]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
9bf1d63a627816e046fad04dd7620142d48dd8be
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.7/Documentation/vserver/debug.txt linux-3.7-vs2.3.5.1/Documentation/vserver/debug.txt
2 --- linux-3.7/Documentation/vserver/debug.txt   1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.7-vs2.3.5.1/Documentation/vserver/debug.txt 2012-12-11 15:56:32.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/arch/alpha/Kconfig linux-3.7-vs2.3.5.1/arch/alpha/Kconfig
160 --- linux-3.7/arch/alpha/Kconfig        2012-12-11 15:45:43.000000000 +0000
161 +++ linux-3.7-vs2.3.5.1/arch/alpha/Kconfig      2012-12-11 15:56:32.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/arch/alpha/kernel/systbls.S linux-3.7-vs2.3.5.1/arch/alpha/kernel/systbls.S
172 --- linux-3.7/arch/alpha/kernel/systbls.S       2012-10-04 13:26:43.000000000 +0000
173 +++ linux-3.7-vs2.3.5.1/arch/alpha/kernel/systbls.S     2012-12-11 15:56:32.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/arch/alpha/kernel/traps.c linux-3.7-vs2.3.5.1/arch/alpha/kernel/traps.c
184 --- linux-3.7/arch/alpha/kernel/traps.c 2012-12-11 15:45:44.000000000 +0000
185 +++ linux-3.7-vs2.3.5.1/arch/alpha/kernel/traps.c       2012-12-11 15:56:32.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/arch/arm/Kconfig linux-3.7-vs2.3.5.1/arch/arm/Kconfig
197 --- linux-3.7/arch/arm/Kconfig  2012-12-11 15:45:44.000000000 +0000
198 +++ linux-3.7-vs2.3.5.1/arch/arm/Kconfig        2012-12-11 15:56:32.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/arch/arm/kernel/calls.S linux-3.7-vs2.3.5.1/arch/arm/kernel/calls.S
209 --- linux-3.7/arch/arm/kernel/calls.S   2012-12-11 15:45:45.000000000 +0000
210 +++ linux-3.7-vs2.3.5.1/arch/arm/kernel/calls.S 2012-12-11 15:56:32.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/arch/arm/kernel/process.c linux-3.7-vs2.3.5.1/arch/arm/kernel/process.c
221 --- linux-3.7/arch/arm/kernel/process.c 2012-12-11 15:45:45.000000000 +0000
222 +++ linux-3.7-vs2.3.5.1/arch/arm/kernel/process.c       2012-12-11 15:56:32.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/arch/arm/kernel/traps.c linux-3.7-vs2.3.5.1/arch/arm/kernel/traps.c
234 --- linux-3.7/arch/arm/kernel/traps.c   2012-10-04 13:26:44.000000000 +0000
235 +++ linux-3.7-vs2.3.5.1/arch/arm/kernel/traps.c 2012-12-11 15:56:32.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/arch/cris/Kconfig linux-3.7-vs2.3.5.1/arch/cris/Kconfig
248 --- linux-3.7/arch/cris/Kconfig 2012-12-11 15:46:01.000000000 +0000
249 +++ linux-3.7-vs2.3.5.1/arch/cris/Kconfig       2012-12-11 15:56:32.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/arch/h8300/Kconfig linux-3.7-vs2.3.5.1/arch/h8300/Kconfig
260 --- linux-3.7/arch/h8300/Kconfig        2012-12-11 15:46:02.000000000 +0000
261 +++ linux-3.7-vs2.3.5.1/arch/h8300/Kconfig      2012-12-11 15:56:32.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/arch/ia64/Kconfig linux-3.7-vs2.3.5.1/arch/ia64/Kconfig
272 --- linux-3.7/arch/ia64/Kconfig 2012-12-11 15:46:03.000000000 +0000
273 +++ linux-3.7-vs2.3.5.1/arch/ia64/Kconfig       2012-12-11 15:56:32.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/arch/ia64/kernel/entry.S linux-3.7-vs2.3.5.1/arch/ia64/kernel/entry.S
284 --- linux-3.7/arch/ia64/kernel/entry.S  2012-03-19 18:46:40.000000000 +0000
285 +++ linux-3.7-vs2.3.5.1/arch/ia64/kernel/entry.S        2012-12-11 15:56:32.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/arch/ia64/kernel/process.c linux-3.7-vs2.3.5.1/arch/ia64/kernel/process.c
296 --- linux-3.7/arch/ia64/kernel/process.c        2012-12-11 15:46:03.000000000 +0000
297 +++ linux-3.7-vs2.3.5.1/arch/ia64/kernel/process.c      2012-12-11 15:56:32.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/arch/ia64/kernel/ptrace.c linux-3.7-vs2.3.5.1/arch/ia64/kernel/ptrace.c
310 --- linux-3.7/arch/ia64/kernel/ptrace.c 2012-05-21 16:06:26.000000000 +0000
311 +++ linux-3.7-vs2.3.5.1/arch/ia64/kernel/ptrace.c       2012-12-11 15:56:32.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/arch/ia64/kernel/traps.c linux-3.7-vs2.3.5.1/arch/ia64/kernel/traps.c
321 --- linux-3.7/arch/ia64/kernel/traps.c  2012-05-21 16:06:26.000000000 +0000
322 +++ linux-3.7-vs2.3.5.1/arch/ia64/kernel/traps.c        2012-12-11 15:56:32.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/arch/m32r/kernel/traps.c linux-3.7-vs2.3.5.1/arch/m32r/kernel/traps.c
348 --- linux-3.7/arch/m32r/kernel/traps.c  2012-05-21 16:06:26.000000000 +0000
349 +++ linux-3.7-vs2.3.5.1/arch/m32r/kernel/traps.c        2012-12-11 15:56:32.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/arch/m68k/Kconfig linux-3.7-vs2.3.5.1/arch/m68k/Kconfig
363 --- linux-3.7/arch/m68k/Kconfig 2012-12-11 15:46:03.000000000 +0000
364 +++ linux-3.7-vs2.3.5.1/arch/m68k/Kconfig       2012-12-11 15:56:32.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/arch/mips/Kconfig linux-3.7-vs2.3.5.1/arch/mips/Kconfig
375 --- linux-3.7/arch/mips/Kconfig 2012-12-11 15:46:05.000000000 +0000
376 +++ linux-3.7-vs2.3.5.1/arch/mips/Kconfig       2012-12-11 15:56:32.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/arch/mips/kernel/ptrace.c linux-3.7-vs2.3.5.1/arch/mips/kernel/ptrace.c
387 --- linux-3.7/arch/mips/kernel/ptrace.c 2012-07-22 21:38:52.000000000 +0000
388 +++ linux-3.7-vs2.3.5.1/arch/mips/kernel/ptrace.c       2012-12-11 15:56:32.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/arch/mips/kernel/scall32-o32.S linux-3.7-vs2.3.5.1/arch/mips/kernel/scall32-o32.S
408 --- linux-3.7/arch/mips/kernel/scall32-o32.S    2012-12-11 15:46:07.000000000 +0000
409 +++ linux-3.7-vs2.3.5.1/arch/mips/kernel/scall32-o32.S  2012-12-11 15:56:32.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/arch/mips/kernel/scall64-64.S linux-3.7-vs2.3.5.1/arch/mips/kernel/scall64-64.S
420 --- linux-3.7/arch/mips/kernel/scall64-64.S     2012-12-11 15:46:07.000000000 +0000
421 +++ linux-3.7-vs2.3.5.1/arch/mips/kernel/scall64-64.S   2012-12-11 15:56:32.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/arch/mips/kernel/scall64-n32.S linux-3.7-vs2.3.5.1/arch/mips/kernel/scall64-n32.S
432 --- linux-3.7/arch/mips/kernel/scall64-n32.S    2012-12-11 15:46:07.000000000 +0000
433 +++ linux-3.7-vs2.3.5.1/arch/mips/kernel/scall64-n32.S  2012-12-11 15:56:32.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/arch/mips/kernel/scall64-o32.S linux-3.7-vs2.3.5.1/arch/mips/kernel/scall64-o32.S
444 --- linux-3.7/arch/mips/kernel/scall64-o32.S    2012-12-11 15:46:07.000000000 +0000
445 +++ linux-3.7-vs2.3.5.1/arch/mips/kernel/scall64-o32.S  2012-12-11 15:56:32.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/arch/mips/kernel/traps.c linux-3.7-vs2.3.5.1/arch/mips/kernel/traps.c
456 --- linux-3.7/arch/mips/kernel/traps.c  2012-10-04 13:26:53.000000000 +0000
457 +++ linux-3.7-vs2.3.5.1/arch/mips/kernel/traps.c        2012-12-11 15:56:32.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/arch/parisc/Kconfig linux-3.7-vs2.3.5.1/arch/parisc/Kconfig
473 --- linux-3.7/arch/parisc/Kconfig       2012-12-11 15:46:08.000000000 +0000
474 +++ linux-3.7-vs2.3.5.1/arch/parisc/Kconfig     2012-12-11 15:56:32.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/arch/parisc/kernel/syscall_table.S linux-3.7-vs2.3.5.1/arch/parisc/kernel/syscall_table.S
485 --- linux-3.7/arch/parisc/kernel/syscall_table.S        2012-12-11 15:46:09.000000000 +0000
486 +++ linux-3.7-vs2.3.5.1/arch/parisc/kernel/syscall_table.S      2012-12-11 15:56:32.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/arch/parisc/kernel/traps.c linux-3.7-vs2.3.5.1/arch/parisc/kernel/traps.c
497 --- linux-3.7/arch/parisc/kernel/traps.c        2012-05-21 16:06:28.000000000 +0000
498 +++ linux-3.7-vs2.3.5.1/arch/parisc/kernel/traps.c      2012-12-11 15:56:32.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/arch/parisc/mm/fault.c linux-3.7-vs2.3.5.1/arch/parisc/mm/fault.c
523 --- linux-3.7/arch/parisc/mm/fault.c    2010-08-02 14:52:06.000000000 +0000
524 +++ linux-3.7-vs2.3.5.1/arch/parisc/mm/fault.c  2012-12-11 15:56:32.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/arch/powerpc/Kconfig linux-3.7-vs2.3.5.1/arch/powerpc/Kconfig
538 --- linux-3.7/arch/powerpc/Kconfig      2012-12-11 15:46:09.000000000 +0000
539 +++ linux-3.7-vs2.3.5.1/arch/powerpc/Kconfig    2012-12-11 15:56:32.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/arch/powerpc/include/uapi/asm/unistd.h linux-3.7-vs2.3.5.1/arch/powerpc/include/uapi/asm/unistd.h
550 --- linux-3.7/arch/powerpc/include/uapi/asm/unistd.h    2012-12-11 15:46:10.000000000 +0000
551 +++ linux-3.7-vs2.3.5.1/arch/powerpc/include/uapi/asm/unistd.h  2012-12-11 16:48:48.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/arch/powerpc/kernel/process.c linux-3.7-vs2.3.5.1/arch/powerpc/kernel/process.c
562 --- linux-3.7/arch/powerpc/kernel/process.c     2012-12-11 15:46:10.000000000 +0000
563 +++ linux-3.7-vs2.3.5.1/arch/powerpc/kernel/process.c   2012-12-11 15:56:32.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/arch/powerpc/kernel/traps.c linux-3.7-vs2.3.5.1/arch/powerpc/kernel/traps.c
577 --- linux-3.7/arch/powerpc/kernel/traps.c       2012-12-11 15:46:10.000000000 +0000
578 +++ linux-3.7-vs2.3.5.1/arch/powerpc/kernel/traps.c     2012-12-11 15:56:32.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/arch/s390/Kconfig linux-3.7-vs2.3.5.1/arch/s390/Kconfig
592 --- linux-3.7/arch/s390/Kconfig 2012-12-11 15:46:14.000000000 +0000
593 +++ linux-3.7-vs2.3.5.1/arch/s390/Kconfig       2012-12-11 15:56:32.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/arch/s390/include/asm/tlb.h linux-3.7-vs2.3.5.1/arch/s390/include/asm/tlb.h
604 --- linux-3.7/arch/s390/include/asm/tlb.h       2012-12-11 15:46:14.000000000 +0000
605 +++ linux-3.7-vs2.3.5.1/arch/s390/include/asm/tlb.h     2012-12-11 15:56:32.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/arch/s390/include/uapi/asm/unistd.h linux-3.7-vs2.3.5.1/arch/s390/include/uapi/asm/unistd.h
615 --- linux-3.7/arch/s390/include/uapi/asm/unistd.h       2012-12-11 15:46:14.000000000 +0000
616 +++ linux-3.7-vs2.3.5.1/arch/s390/include/uapi/asm/unistd.h     2012-12-11 16:47:45.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/arch/s390/kernel/ptrace.c linux-3.7-vs2.3.5.1/arch/s390/kernel/ptrace.c
627 --- linux-3.7/arch/s390/kernel/ptrace.c 2012-12-11 15:46:15.000000000 +0000
628 +++ linux-3.7-vs2.3.5.1/arch/s390/kernel/ptrace.c       2012-12-11 15:56:32.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/arch/s390/kernel/syscalls.S linux-3.7-vs2.3.5.1/arch/s390/kernel/syscalls.S
638 --- linux-3.7/arch/s390/kernel/syscalls.S       2012-12-11 15:46:15.000000000 +0000
639 +++ linux-3.7-vs2.3.5.1/arch/s390/kernel/syscalls.S     2012-12-11 15:56:32.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/arch/sh/Kconfig linux-3.7-vs2.3.5.1/arch/sh/Kconfig
650 --- linux-3.7/arch/sh/Kconfig   2012-12-11 15:46:15.000000000 +0000
651 +++ linux-3.7-vs2.3.5.1/arch/sh/Kconfig 2012-12-11 15:56:32.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/arch/sh/kernel/irq.c linux-3.7-vs2.3.5.1/arch/sh/kernel/irq.c
662 --- linux-3.7/arch/sh/kernel/irq.c      2012-10-04 13:26:56.000000000 +0000
663 +++ linux-3.7-vs2.3.5.1/arch/sh/kernel/irq.c    2012-12-11 15:56:32.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/arch/sparc/Kconfig linux-3.7-vs2.3.5.1/arch/sparc/Kconfig
673 --- linux-3.7/arch/sparc/Kconfig        2012-12-11 15:46:15.000000000 +0000
674 +++ linux-3.7-vs2.3.5.1/arch/sparc/Kconfig      2012-12-11 15:56:32.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/arch/sparc/include/uapi/asm/unistd.h linux-3.7-vs2.3.5.1/arch/sparc/include/uapi/asm/unistd.h
685 --- linux-3.7/arch/sparc/include/uapi/asm/unistd.h      2012-12-11 15:46:16.000000000 +0000
686 +++ linux-3.7-vs2.3.5.1/arch/sparc/include/uapi/asm/unistd.h    2012-12-11 16:43:01.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/arch/sparc/kernel/systbls_32.S linux-3.7-vs2.3.5.1/arch/sparc/kernel/systbls_32.S
697 --- linux-3.7/arch/sparc/kernel/systbls_32.S    2012-12-11 15:46:17.000000000 +0000
698 +++ linux-3.7-vs2.3.5.1/arch/sparc/kernel/systbls_32.S  2012-12-11 15:56:32.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/arch/sparc/kernel/systbls_64.S linux-3.7-vs2.3.5.1/arch/sparc/kernel/systbls_64.S
709 --- linux-3.7/arch/sparc/kernel/systbls_64.S    2012-12-11 15:46:17.000000000 +0000
710 +++ linux-3.7-vs2.3.5.1/arch/sparc/kernel/systbls_64.S  2012-12-11 15:56:32.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/arch/um/Kconfig.rest linux-3.7-vs2.3.5.1/arch/um/Kconfig.rest
730 --- linux-3.7/arch/um/Kconfig.rest      2012-01-09 15:14:09.000000000 +0000
731 +++ linux-3.7-vs2.3.5.1/arch/um/Kconfig.rest    2012-12-11 15:56:32.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/arch/um/include/shared/kern_constants.h linux-3.7-vs2.3.5.1/arch/um/include/shared/kern_constants.h
742 --- linux-3.7/arch/um/include/shared/kern_constants.h   1970-01-01 00:00:00.000000000 +0000
743 +++ linux-3.7-vs2.3.5.1/arch/um/include/shared/kern_constants.h 2012-12-11 15:56:32.000000000 +0000
744 @@ -0,0 +1 @@
745 +#include "../../../../include/generated/asm-offsets.h"
746 diff -NurpP --minimal linux-3.7/arch/um/include/shared/user_constants.h linux-3.7-vs2.3.5.1/arch/um/include/shared/user_constants.h
747 --- linux-3.7/arch/um/include/shared/user_constants.h   1970-01-01 00:00:00.000000000 +0000
748 +++ linux-3.7-vs2.3.5.1/arch/um/include/shared/user_constants.h 2012-12-11 15:56:32.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/arch/x86/Kconfig linux-3.7-vs2.3.5.1/arch/x86/Kconfig
791 --- linux-3.7/arch/x86/Kconfig  2012-12-11 15:46:18.000000000 +0000
792 +++ linux-3.7-vs2.3.5.1/arch/x86/Kconfig        2012-12-11 15:56:32.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/arch/x86/syscalls/syscall_32.tbl linux-3.7-vs2.3.5.1/arch/x86/syscalls/syscall_32.tbl
803 --- linux-3.7/arch/x86/syscalls/syscall_32.tbl  2012-12-11 15:46:21.000000000 +0000
804 +++ linux-3.7-vs2.3.5.1/arch/x86/syscalls/syscall_32.tbl        2012-12-11 15:56:32.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/arch/x86/syscalls/syscall_64.tbl linux-3.7-vs2.3.5.1/arch/x86/syscalls/syscall_64.tbl
815 --- linux-3.7/arch/x86/syscalls/syscall_64.tbl  2012-10-04 13:27:01.000000000 +0000
816 +++ linux-3.7-vs2.3.5.1/arch/x86/syscalls/syscall_64.tbl        2012-12-11 15:56:32.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/drivers/block/Kconfig linux-3.7-vs2.3.5.1/drivers/block/Kconfig
827 --- linux-3.7/drivers/block/Kconfig     2012-12-11 15:46:23.000000000 +0000
828 +++ linux-3.7-vs2.3.5.1/drivers/block/Kconfig   2012-12-11 15:56:32.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/drivers/block/Makefile linux-3.7-vs2.3.5.1/drivers/block/Makefile
844 --- linux-3.7/drivers/block/Makefile    2012-12-11 15:46:23.000000000 +0000
845 +++ linux-3.7-vs2.3.5.1/drivers/block/Makefile  2012-12-11 15:56:32.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/drivers/block/loop.c linux-3.7-vs2.3.5.1/drivers/block/loop.c
855 --- linux-3.7/drivers/block/loop.c      2012-12-11 15:46:24.000000000 +0000
856 +++ linux-3.7-vs2.3.5.1/drivers/block/loop.c    2012-12-11 16:49:59.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/drivers/block/vroot.c linux-3.7-vs2.3.5.1/drivers/block/vroot.c
913 --- linux-3.7/drivers/block/vroot.c     1970-01-01 00:00:00.000000000 +0000
914 +++ linux-3.7-vs2.3.5.1/drivers/block/vroot.c   2012-12-11 15:56:32.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/drivers/infiniband/Kconfig linux-3.7-vs2.3.5.1/drivers/infiniband/Kconfig
1208 --- linux-3.7/drivers/infiniband/Kconfig        2012-07-22 21:39:06.000000000 +0000
1209 +++ linux-3.7-vs2.3.5.1/drivers/infiniband/Kconfig      2012-12-11 15:56:32.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/drivers/infiniband/core/addr.c linux-3.7-vs2.3.5.1/drivers/infiniband/core/addr.c
1220 --- linux-3.7/drivers/infiniband/core/addr.c    2012-12-11 15:46:34.000000000 +0000
1221 +++ linux-3.7-vs2.3.5.1/drivers/infiniband/core/addr.c  2012-12-11 15:56:32.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/drivers/md/dm-ioctl.c linux-3.7-vs2.3.5.1/drivers/md/dm-ioctl.c
1232 --- linux-3.7/drivers/md/dm-ioctl.c     2012-10-04 13:27:11.000000000 +0000
1233 +++ linux-3.7-vs2.3.5.1/drivers/md/dm-ioctl.c   2012-12-11 15:56:32.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/drivers/md/dm.c linux-3.7-vs2.3.5.1/drivers/md/dm.c
1320 --- linux-3.7/drivers/md/dm.c   2012-12-11 15:46:38.000000000 +0000
1321 +++ linux-3.7-vs2.3.5.1/drivers/md/dm.c 2012-12-11 15:56:32.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/drivers/md/dm.h linux-3.7-vs2.3.5.1/drivers/md/dm.h
1396 --- linux-3.7/drivers/md/dm.h   2012-10-04 13:27:11.000000000 +0000
1397 +++ linux-3.7-vs2.3.5.1/drivers/md/dm.h 2012-12-11 15:56:32.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/drivers/net/tun.c linux-3.7-vs2.3.5.1/drivers/net/tun.c
1408 --- linux-3.7/drivers/net/tun.c 2012-12-11 15:47:01.000000000 +0000
1409 +++ linux-3.7-vs2.3.5.1/drivers/net/tun.c       2012-12-12 00:07:34.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/drivers/staging/csr/csr_wifi_hip_xbv.c linux-3.7-vs2.3.5.1/drivers/staging/csr/csr_wifi_hip_xbv.c
1480 --- linux-3.7/drivers/staging/csr/csr_wifi_hip_xbv.c    2012-10-04 13:27:30.000000000 +0000
1481 +++ linux-3.7-vs2.3.5.1/drivers/staging/csr/csr_wifi_hip_xbv.c  2012-12-11 15:56:32.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/drivers/tty/sysrq.c linux-3.7-vs2.3.5.1/drivers/tty/sysrq.c
1519 --- linux-3.7/drivers/tty/sysrq.c       2012-12-11 15:47:24.000000000 +0000
1520 +++ linux-3.7-vs2.3.5.1/drivers/tty/sysrq.c     2012-12-11 16:52:41.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 -       NULL,                           /* x */
1556 +#ifdef CONFIG_VSERVER_DEBUG
1557 +       &sysrq_showvxinfo_op,           /* x */
1558 +#else
1559 +       NULL,                           /* x */
1560 +#endif
1561         /* y: May be registered on sparc64 for global register dump */
1562         NULL,                           /* y */
1563         &sysrq_ftrace_dump_op,          /* z */
1564 @@ -468,6 +488,8 @@ static int sysrq_key_table_key2index(int
1565                 retval = key - '0';
1566         else if ((key >= 'a') && (key <= 'z'))
1567                 retval = key + 10 - 'a';
1568 +       else if ((key >= 'A') && (key <= 'Z'))
1569 +               retval = key + 10 - 'A';
1570         else
1571                 retval = -1;
1572         return retval;
1573 diff -NurpP --minimal linux-3.7/drivers/tty/tty_io.c linux-3.7-vs2.3.5.1/drivers/tty/tty_io.c
1574 --- linux-3.7/drivers/tty/tty_io.c      2012-12-11 15:47:24.000000000 +0000
1575 +++ linux-3.7-vs2.3.5.1/drivers/tty/tty_io.c    2012-12-11 15:56:32.000000000 +0000
1576 @@ -104,6 +104,7 @@
1577  
1578  #include <linux/kmod.h>
1579  #include <linux/nsproxy.h>
1580 +#include <linux/vs_pid.h>
1581  
1582  #undef TTY_DEBUG_HANGUP
1583  
1584 @@ -2139,7 +2140,8 @@ static int tiocsti(struct tty_struct *tt
1585         char ch, mbz = 0;
1586         struct tty_ldisc *ld;
1587  
1588 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1589 +       if (((current->signal->tty != tty) &&
1590 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1591                 return -EPERM;
1592         if (get_user(ch, p))
1593                 return -EFAULT;
1594 @@ -2426,6 +2428,7 @@ static int tiocspgrp(struct tty_struct *
1595                 return -ENOTTY;
1596         if (get_user(pgrp_nr, p))
1597                 return -EFAULT;
1598 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1599         if (pgrp_nr < 0)
1600                 return -EINVAL;
1601         rcu_read_lock();
1602 diff -NurpP --minimal linux-3.7/fs/attr.c linux-3.7-vs2.3.5.1/fs/attr.c
1603 --- linux-3.7/fs/attr.c 2012-12-11 15:47:31.000000000 +0000
1604 +++ linux-3.7-vs2.3.5.1/fs/attr.c       2012-12-11 19:10:54.000000000 +0000
1605 @@ -15,6 +15,9 @@
1606  #include <linux/security.h>
1607  #include <linux/evm.h>
1608  #include <linux/ima.h>
1609 +#include <linux/proc_fs.h>
1610 +#include <linux/devpts_fs.h>
1611 +#include <linux/vs_tag.h>
1612  
1613  /**
1614   * inode_change_ok - check if attribute changes to an inode are allowed
1615 @@ -75,6 +78,10 @@ int inode_change_ok(const struct inode *
1616                         return -EPERM;
1617         }
1618  
1619 +       /* check for inode tag permission */
1620 +       if (dx_permission(inode, MAY_WRITE))
1621 +               return -EACCES;
1622 +
1623         return 0;
1624  }
1625  EXPORT_SYMBOL(inode_change_ok);
1626 @@ -145,6 +152,8 @@ void setattr_copy(struct inode *inode, c
1627                 inode->i_uid = attr->ia_uid;
1628         if (ia_valid & ATTR_GID)
1629                 inode->i_gid = attr->ia_gid;
1630 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1631 +               inode->i_tag = attr->ia_tag;
1632         if (ia_valid & ATTR_ATIME)
1633                 inode->i_atime = timespec_trunc(attr->ia_atime,
1634                                                 inode->i_sb->s_time_gran);
1635 @@ -174,7 +183,8 @@ int notify_change(struct dentry * dentry
1636  
1637         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1638  
1639 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1640 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1641 +               ATTR_TAG | ATTR_TIMES_SET)) {
1642                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1643                         return -EPERM;
1644         }
1645 diff -NurpP --minimal linux-3.7/fs/block_dev.c linux-3.7-vs2.3.5.1/fs/block_dev.c
1646 --- linux-3.7/fs/block_dev.c    2012-12-11 15:47:31.000000000 +0000
1647 +++ linux-3.7-vs2.3.5.1/fs/block_dev.c  2012-12-11 15:56:32.000000000 +0000
1648 @@ -27,6 +27,7 @@
1649  #include <linux/namei.h>
1650  #include <linux/log2.h>
1651  #include <linux/cleancache.h>
1652 +#include <linux/vs_device.h>
1653  #include <asm/uaccess.h>
1654  #include "internal.h"
1655  
1656 @@ -528,6 +529,7 @@ struct block_device *bdget(dev_t dev)
1657                 bdev->bd_invalidated = 0;
1658                 inode->i_mode = S_IFBLK;
1659                 inode->i_rdev = dev;
1660 +               inode->i_mdev = dev;
1661                 inode->i_bdev = bdev;
1662                 inode->i_data.a_ops = &def_blk_aops;
1663                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1664 @@ -574,6 +576,11 @@ EXPORT_SYMBOL(bdput);
1665  static struct block_device *bd_acquire(struct inode *inode)
1666  {
1667         struct block_device *bdev;
1668 +       dev_t mdev;
1669 +
1670 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1671 +               return NULL;
1672 +       inode->i_mdev = mdev;
1673  
1674         spin_lock(&bdev_lock);
1675         bdev = inode->i_bdev;
1676 @@ -584,7 +591,7 @@ static struct block_device *bd_acquire(s
1677         }
1678         spin_unlock(&bdev_lock);
1679  
1680 -       bdev = bdget(inode->i_rdev);
1681 +       bdev = bdget(mdev);
1682         if (bdev) {
1683                 spin_lock(&bdev_lock);
1684                 if (!inode->i_bdev) {
1685 diff -NurpP --minimal linux-3.7/fs/btrfs/ctree.h linux-3.7-vs2.3.5.1/fs/btrfs/ctree.h
1686 --- linux-3.7/fs/btrfs/ctree.h  2012-12-11 15:47:31.000000000 +0000
1687 +++ linux-3.7-vs2.3.5.1/fs/btrfs/ctree.h        2012-12-11 15:56:32.000000000 +0000
1688 @@ -692,11 +692,14 @@ struct btrfs_inode_item {
1689         /* modification sequence number for NFS */
1690         __le64 sequence;
1691  
1692 +       __le16 tag;
1693         /*
1694          * a little future expansion, for more than this we can
1695          * just grow the inode item and version it
1696          */
1697 -       __le64 reserved[4];
1698 +       __le16 reserved16;
1699 +       __le32 reserved32;
1700 +       __le64 reserved[3];
1701         struct btrfs_timespec atime;
1702         struct btrfs_timespec ctime;
1703         struct btrfs_timespec mtime;
1704 @@ -1757,6 +1760,8 @@ struct btrfs_ioctl_defrag_range_args {
1705  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1706  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1707  
1708 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1709 +
1710  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1711  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1712  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1713 @@ -2025,6 +2030,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1714  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1715  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1716  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1717 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1718  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1719  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1720  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1721 @@ -2078,6 +2084,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1722  
1723  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1724  
1725 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1726 +#define BTRFS_INODE_BARRIER            (1 << 25)
1727 +#define BTRFS_INODE_COW                        (1 << 26)
1728 +
1729  
1730  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1731  
1732 @@ -3363,6 +3373,7 @@ extern const struct dentry_operations bt
1733  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1734  void btrfs_update_iflags(struct inode *inode);
1735  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1736 +int btrfs_sync_flags(struct inode *inode, int, int);
1737  int btrfs_defrag_file(struct inode *inode, struct file *file,
1738                       struct btrfs_ioctl_defrag_range_args *range,
1739                       u64 newer_than, unsigned long max_pages);
1740 diff -NurpP --minimal linux-3.7/fs/btrfs/disk-io.c linux-3.7-vs2.3.5.1/fs/btrfs/disk-io.c
1741 --- linux-3.7/fs/btrfs/disk-io.c        2012-12-11 15:47:31.000000000 +0000
1742 +++ linux-3.7-vs2.3.5.1/fs/btrfs/disk-io.c      2012-12-11 15:56:32.000000000 +0000
1743 @@ -2197,6 +2197,9 @@ int open_ctree(struct super_block *sb,
1744                 goto fail_alloc;
1745         }
1746  
1747 +       if (btrfs_test_opt(tree_root, TAGGED))
1748 +               sb->s_flags |= MS_TAGGED;
1749 +
1750         features = btrfs_super_incompat_flags(disk_super) &
1751                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1752         if (features) {
1753 diff -NurpP --minimal linux-3.7/fs/btrfs/inode.c linux-3.7-vs2.3.5.1/fs/btrfs/inode.c
1754 --- linux-3.7/fs/btrfs/inode.c  2012-12-11 15:47:31.000000000 +0000
1755 +++ linux-3.7-vs2.3.5.1/fs/btrfs/inode.c        2012-12-11 21:52:49.000000000 +0000
1756 @@ -39,6 +39,7 @@
1757  #include <linux/slab.h>
1758  #include <linux/ratelimit.h>
1759  #include <linux/mount.h>
1760 +#include <linux/vs_tag.h>
1761  #include "compat.h"
1762  #include "ctree.h"
1763  #include "disk-io.h"
1764 @@ -2530,6 +2531,8 @@ static void btrfs_read_locked_inode(stru
1765         struct btrfs_key location;
1766         int maybe_acls;
1767         u32 rdev;
1768 +       uid_t uid;
1769 +       gid_t gid;
1770         int ret;
1771         bool filled = false;
1772  
1773 @@ -2557,8 +2560,13 @@ static void btrfs_read_locked_inode(stru
1774                                     struct btrfs_inode_item);
1775         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1776         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1777 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1778 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1779 +
1780 +       uid = btrfs_inode_uid(leaf, inode_item);
1781 +       gid = btrfs_inode_gid(leaf, inode_item);
1782 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
1783 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
1784 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
1785 +               btrfs_inode_tag(leaf, inode_item)));
1786         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1787  
1788         tspec = btrfs_inode_atime(inode_item);
1789 @@ -2648,8 +2656,16 @@ static void fill_inode_item(struct btrfs
1790                             struct btrfs_inode_item *item,
1791                             struct inode *inode)
1792  {
1793 -       btrfs_set_inode_uid(leaf, item, i_uid_read(inode));
1794 -       btrfs_set_inode_gid(leaf, item, i_gid_read(inode));
1795 +       uid_t uid = TAGINO_UID(DX_TAG(inode),
1796 +               i_uid_read(inode), i_tag_read(inode));
1797 +       gid_t gid = TAGINO_GID(DX_TAG(inode),
1798 +               i_gid_read(inode), i_tag_read(inode));
1799 +
1800 +       btrfs_set_inode_uid(leaf, item, uid);
1801 +       btrfs_set_inode_gid(leaf, item, gid);
1802 +#ifdef CONFIG_TAGGING_INTERN
1803 +       btrfs_set_inode_tag(leaf, item, i_tag_read(inode));
1804 +#endif
1805         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1806         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1807         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1808 @@ -7786,11 +7802,13 @@ static const struct inode_operations btr
1809         .listxattr      = btrfs_listxattr,
1810         .removexattr    = btrfs_removexattr,
1811         .permission     = btrfs_permission,
1812 +       .sync_flags     = btrfs_sync_flags,
1813         .get_acl        = btrfs_get_acl,
1814  };
1815  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1816         .lookup         = btrfs_lookup,
1817         .permission     = btrfs_permission,
1818 +       .sync_flags     = btrfs_sync_flags,
1819         .get_acl        = btrfs_get_acl,
1820  };
1821  
1822 diff -NurpP --minimal linux-3.7/fs/btrfs/ioctl.c linux-3.7-vs2.3.5.1/fs/btrfs/ioctl.c
1823 --- linux-3.7/fs/btrfs/ioctl.c  2012-12-11 15:47:31.000000000 +0000
1824 +++ linux-3.7-vs2.3.5.1/fs/btrfs/ioctl.c        2012-12-11 15:56:32.000000000 +0000
1825 @@ -74,10 +74,13 @@ static unsigned int btrfs_flags_to_ioctl
1826  {
1827         unsigned int iflags = 0;
1828  
1829 -       if (flags & BTRFS_INODE_SYNC)
1830 -               iflags |= FS_SYNC_FL;
1831         if (flags & BTRFS_INODE_IMMUTABLE)
1832                 iflags |= FS_IMMUTABLE_FL;
1833 +       if (flags & BTRFS_INODE_IXUNLINK)
1834 +               iflags |= FS_IXUNLINK_FL;
1835 +
1836 +       if (flags & BTRFS_INODE_SYNC)
1837 +               iflags |= FS_SYNC_FL;
1838         if (flags & BTRFS_INODE_APPEND)
1839                 iflags |= FS_APPEND_FL;
1840         if (flags & BTRFS_INODE_NODUMP)
1841 @@ -94,28 +97,78 @@ static unsigned int btrfs_flags_to_ioctl
1842         else if (flags & BTRFS_INODE_NOCOMPRESS)
1843                 iflags |= FS_NOCOMP_FL;
1844  
1845 +       if (flags & BTRFS_INODE_BARRIER)
1846 +               iflags |= FS_BARRIER_FL;
1847 +       if (flags & BTRFS_INODE_COW)
1848 +               iflags |= FS_COW_FL;
1849         return iflags;
1850  }
1851  
1852  /*
1853 - * Update inode->i_flags based on the btrfs internal flags.
1854 + * Update inode->i_(v)flags based on the btrfs internal flags.
1855   */
1856  void btrfs_update_iflags(struct inode *inode)
1857  {
1858         struct btrfs_inode *ip = BTRFS_I(inode);
1859  
1860 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1861 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1862 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1863  
1864 -       if (ip->flags & BTRFS_INODE_SYNC)
1865 -               inode->i_flags |= S_SYNC;
1866         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1867                 inode->i_flags |= S_IMMUTABLE;
1868 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1869 +               inode->i_flags |= S_IXUNLINK;
1870 +
1871 +       if (ip->flags & BTRFS_INODE_SYNC)
1872 +               inode->i_flags |= S_SYNC;
1873         if (ip->flags & BTRFS_INODE_APPEND)
1874                 inode->i_flags |= S_APPEND;
1875         if (ip->flags & BTRFS_INODE_NOATIME)
1876                 inode->i_flags |= S_NOATIME;
1877         if (ip->flags & BTRFS_INODE_DIRSYNC)
1878                 inode->i_flags |= S_DIRSYNC;
1879 +
1880 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1881 +
1882 +       if (ip->flags & BTRFS_INODE_BARRIER)
1883 +               inode->i_vflags |= V_BARRIER;
1884 +       if (ip->flags & BTRFS_INODE_COW)
1885 +               inode->i_vflags |= V_COW;
1886 +}
1887 +
1888 +/*
1889 + * Update btrfs internal flags from inode->i_(v)flags.
1890 + */
1891 +void btrfs_update_flags(struct inode *inode)
1892 +{
1893 +       struct btrfs_inode *ip = BTRFS_I(inode);
1894 +
1895 +       unsigned int flags = inode->i_flags;
1896 +       unsigned int vflags = inode->i_vflags;
1897 +
1898 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1899 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1900 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1901 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1902 +
1903 +       if (flags & S_IMMUTABLE)
1904 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1905 +       if (flags & S_IXUNLINK)
1906 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1907 +
1908 +       if (flags & S_SYNC)
1909 +               ip->flags |= BTRFS_INODE_SYNC;
1910 +       if (flags & S_APPEND)
1911 +               ip->flags |= BTRFS_INODE_APPEND;
1912 +       if (flags & S_NOATIME)
1913 +               ip->flags |= BTRFS_INODE_NOATIME;
1914 +       if (flags & S_DIRSYNC)
1915 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1916 +
1917 +       if (vflags & V_BARRIER)
1918 +               ip->flags |= BTRFS_INODE_BARRIER;
1919 +       if (vflags & V_COW)
1920 +               ip->flags |= BTRFS_INODE_COW;
1921  }
1922  
1923  /*
1924 @@ -131,6 +184,7 @@ void btrfs_inherit_iflags(struct inode *
1925                 return;
1926  
1927         flags = BTRFS_I(dir)->flags;
1928 +       flags &= ~BTRFS_INODE_BARRIER;
1929  
1930         if (flags & BTRFS_INODE_NOCOMPRESS) {
1931                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1932 @@ -146,6 +200,30 @@ void btrfs_inherit_iflags(struct inode *
1933         btrfs_update_iflags(inode);
1934  }
1935  
1936 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1937 +{
1938 +       struct btrfs_inode *ip = BTRFS_I(inode);
1939 +       struct btrfs_root *root = ip->root;
1940 +       struct btrfs_trans_handle *trans;
1941 +       int ret;
1942 +
1943 +       trans = btrfs_join_transaction(root);
1944 +       BUG_ON(!trans);
1945 +
1946 +       inode->i_flags = flags;
1947 +       inode->i_vflags = vflags;
1948 +       btrfs_update_flags(inode);
1949 +
1950 +       ret = btrfs_update_inode(trans, root, inode);
1951 +       BUG_ON(ret);
1952 +
1953 +       btrfs_update_iflags(inode);
1954 +       inode->i_ctime = CURRENT_TIME;
1955 +       btrfs_end_transaction(trans, root);
1956 +
1957 +       return 0;
1958 +}
1959 +
1960  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1961  {
1962         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
1963 @@ -208,21 +286,27 @@ static int btrfs_ioctl_setflags(struct f
1964  
1965         flags = btrfs_mask_flags(inode->i_mode, flags);
1966         oldflags = btrfs_flags_to_ioctl(ip->flags);
1967 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1968 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1969 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1970                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1971                         ret = -EPERM;
1972                         goto out_unlock;
1973                 }
1974         }
1975  
1976 -       if (flags & FS_SYNC_FL)
1977 -               ip->flags |= BTRFS_INODE_SYNC;
1978 -       else
1979 -               ip->flags &= ~BTRFS_INODE_SYNC;
1980         if (flags & FS_IMMUTABLE_FL)
1981                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1982         else
1983                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1984 +       if (flags & FS_IXUNLINK_FL)
1985 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1986 +       else
1987 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1988 +
1989 +       if (flags & FS_SYNC_FL)
1990 +               ip->flags |= BTRFS_INODE_SYNC;
1991 +       else
1992 +               ip->flags &= ~BTRFS_INODE_SYNC;
1993         if (flags & FS_APPEND_FL)
1994                 ip->flags |= BTRFS_INODE_APPEND;
1995         else
1996 diff -NurpP --minimal linux-3.7/fs/btrfs/super.c linux-3.7-vs2.3.5.1/fs/btrfs/super.c
1997 --- linux-3.7/fs/btrfs/super.c  2012-12-11 15:47:31.000000000 +0000
1998 +++ linux-3.7-vs2.3.5.1/fs/btrfs/super.c        2012-12-11 15:56:32.000000000 +0000
1999 @@ -312,7 +312,7 @@ enum {
2000         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
2001         Opt_check_integrity, Opt_check_integrity_including_extent_data,
2002         Opt_check_integrity_print_mask, Opt_fatal_errors,
2003 -       Opt_err,
2004 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2005  };
2006  
2007  static match_table_t tokens = {
2008 @@ -352,6 +352,9 @@ static match_table_t tokens = {
2009         {Opt_check_integrity_including_extent_data, "check_int_data"},
2010         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
2011         {Opt_fatal_errors, "fatal_errors=%s"},
2012 +       {Opt_tag, "tag"},
2013 +       {Opt_notag, "notag"},
2014 +       {Opt_tagid, "tagid=%u"},
2015         {Opt_err, NULL},
2016  };
2017  
2018 @@ -614,6 +617,22 @@ int btrfs_parse_options(struct btrfs_roo
2019                                 goto out;
2020                         }
2021                         break;
2022 +#ifndef CONFIG_TAGGING_NONE
2023 +               case Opt_tag:
2024 +                       printk(KERN_INFO "btrfs: use tagging\n");
2025 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2026 +                       break;
2027 +               case Opt_notag:
2028 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2029 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2030 +                       break;
2031 +#endif
2032 +#ifdef CONFIG_PROPAGATE
2033 +               case Opt_tagid:
2034 +                       /* use args[0] */
2035 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2036 +                       break;
2037 +#endif
2038                 case Opt_err:
2039                         printk(KERN_INFO "btrfs: unrecognized mount option "
2040                                "'%s'\n", p);
2041 @@ -1211,6 +1230,12 @@ static int btrfs_remount(struct super_bl
2042         btrfs_resize_thread_pool(fs_info,
2043                 fs_info->thread_pool_size, old_thread_pool_size);
2044  
2045 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2046 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2047 +                       sb->s_id);
2048 +               return -EINVAL;
2049 +       }
2050 +
2051         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2052                 return 0;
2053  
2054 diff -NurpP --minimal linux-3.7/fs/char_dev.c linux-3.7-vs2.3.5.1/fs/char_dev.c
2055 --- linux-3.7/fs/char_dev.c     2012-12-11 15:47:32.000000000 +0000
2056 +++ linux-3.7-vs2.3.5.1/fs/char_dev.c   2012-12-11 15:56:32.000000000 +0000
2057 @@ -21,6 +21,8 @@
2058  #include <linux/mutex.h>
2059  #include <linux/backing-dev.h>
2060  #include <linux/tty.h>
2061 +#include <linux/vs_context.h>
2062 +#include <linux/vs_device.h>
2063  
2064  #include "internal.h"
2065  
2066 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2067         struct cdev *p;
2068         struct cdev *new = NULL;
2069         int ret = 0;
2070 +       dev_t mdev;
2071 +
2072 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2073 +               return -EPERM;
2074 +       inode->i_mdev = mdev;
2075  
2076         spin_lock(&cdev_lock);
2077         p = inode->i_cdev;
2078         if (!p) {
2079                 struct kobject *kobj;
2080                 int idx;
2081 +
2082                 spin_unlock(&cdev_lock);
2083 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2084 +
2085 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2086                 if (!kobj)
2087                         return -ENXIO;
2088                 new = container_of(kobj, struct cdev, kobj);
2089 diff -NurpP --minimal linux-3.7/fs/dcache.c linux-3.7-vs2.3.5.1/fs/dcache.c
2090 --- linux-3.7/fs/dcache.c       2012-12-11 15:47:32.000000000 +0000
2091 +++ linux-3.7-vs2.3.5.1/fs/dcache.c     2012-12-11 15:56:32.000000000 +0000
2092 @@ -37,6 +37,7 @@
2093  #include <linux/rculist_bl.h>
2094  #include <linux/prefetch.h>
2095  #include <linux/ratelimit.h>
2096 +#include <linux/vs_limit.h>
2097  #include "internal.h"
2098  #include "mount.h"
2099  
2100 @@ -617,6 +618,8 @@ int d_invalidate(struct dentry * dentry)
2101                 spin_lock(&dentry->d_lock);
2102         }
2103  
2104 +       vx_dentry_dec(dentry);
2105 +
2106         /*
2107          * Somebody else still using it?
2108          *
2109 @@ -646,6 +649,7 @@ EXPORT_SYMBOL(d_invalidate);
2110  static inline void __dget_dlock(struct dentry *dentry)
2111  {
2112         dentry->d_count++;
2113 +       vx_dentry_inc(dentry);
2114  }
2115  
2116  static inline void __dget(struct dentry *dentry)
2117 @@ -1276,6 +1280,9 @@ struct dentry *__d_alloc(struct super_bl
2118         struct dentry *dentry;
2119         char *dname;
2120  
2121 +       if (!vx_dentry_avail(1))
2122 +               return NULL;
2123 +
2124         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2125         if (!dentry)
2126                 return NULL;
2127 @@ -1308,6 +1315,7 @@ struct dentry *__d_alloc(struct super_bl
2128  
2129         dentry->d_count = 1;
2130         dentry->d_flags = 0;
2131 +       vx_dentry_inc(dentry);
2132         spin_lock_init(&dentry->d_lock);
2133         seqcount_init(&dentry->d_seq);
2134         dentry->d_inode = NULL;
2135 @@ -2012,6 +2020,7 @@ struct dentry *__d_lookup(struct dentry
2136                 }
2137  
2138                 dentry->d_count++;
2139 +               vx_dentry_inc(dentry);
2140                 found = dentry;
2141                 spin_unlock(&dentry->d_lock);
2142                 break;
2143 diff -NurpP --minimal linux-3.7/fs/devpts/inode.c linux-3.7-vs2.3.5.1/fs/devpts/inode.c
2144 --- linux-3.7/fs/devpts/inode.c 2012-10-04 13:27:39.000000000 +0000
2145 +++ linux-3.7-vs2.3.5.1/fs/devpts/inode.c       2012-12-11 19:18:53.000000000 +0000
2146 @@ -25,6 +25,7 @@
2147  #include <linux/parser.h>
2148  #include <linux/fsnotify.h>
2149  #include <linux/seq_file.h>
2150 +#include <linux/vs_base.h>
2151  
2152  #define DEVPTS_DEFAULT_MODE 0600
2153  /*
2154 @@ -36,6 +37,21 @@
2155  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2156  #define PTMX_MINOR     2
2157  
2158 +static int devpts_permission(struct inode *inode, int mask)
2159 +{
2160 +       int ret = -EACCES;
2161 +
2162 +       /* devpts is xid tagged */
2163 +       if (vx_check((xid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2164 +               ret = generic_permission(inode, mask);
2165 +       return ret;
2166 +}
2167 +
2168 +static struct inode_operations devpts_file_inode_operations = {
2169 +       .permission     = devpts_permission,
2170 +};
2171 +
2172 +
2173  /*
2174   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2175   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2176 @@ -336,6 +352,34 @@ static int devpts_show_options(struct se
2177         return 0;
2178  }
2179  
2180 +static int devpts_filter(struct dentry *de)
2181 +{
2182 +       xid_t xid = 0;
2183 +
2184 +       /* devpts is xid tagged */
2185 +       if (de && de->d_inode)
2186 +               xid = (xid_t)i_tag_read(de->d_inode);
2187 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2188 +       else
2189 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2190 +                       de->d_name.len, de->d_name.name);
2191 +#endif
2192 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2193 +}
2194 +
2195 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2196 +{
2197 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2198 +}
2199 +
2200 +static struct file_operations devpts_dir_operations = {
2201 +       .open           = dcache_dir_open,
2202 +       .release        = dcache_dir_close,
2203 +       .llseek         = dcache_dir_lseek,
2204 +       .read           = generic_read_dir,
2205 +       .readdir        = devpts_readdir,
2206 +};
2207 +
2208  static const struct super_operations devpts_sops = {
2209         .statfs         = simple_statfs,
2210         .remount_fs     = devpts_remount,
2211 @@ -379,8 +423,10 @@ devpts_fill_super(struct super_block *s,
2212         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2213         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2214         inode->i_op = &simple_dir_inode_operations;
2215 -       inode->i_fop = &simple_dir_operations;
2216 +       inode->i_fop = &devpts_dir_operations;
2217         set_nlink(inode, 2);
2218 +       /* devpts is xid tagged */
2219 +       i_tag_write(inode, (tag_t)vx_current_xid());
2220  
2221         s->s_root = d_make_root(inode);
2222         if (s->s_root)
2223 @@ -572,6 +618,9 @@ int devpts_pty_new(struct inode *ptmx_in
2224         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2225         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2226         init_special_inode(inode, S_IFCHR|opts->mode, device);
2227 +       /* devpts is xid tagged */
2228 +       i_tag_write(inode, (tag_t)vx_current_xid());
2229 +       inode->i_op = &devpts_file_inode_operations;
2230         inode->i_private = tty;
2231         tty->driver_data = inode;
2232  
2233 diff -NurpP --minimal linux-3.7/fs/ext2/balloc.c linux-3.7-vs2.3.5.1/fs/ext2/balloc.c
2234 --- linux-3.7/fs/ext2/balloc.c  2012-12-11 15:47:32.000000000 +0000
2235 +++ linux-3.7-vs2.3.5.1/fs/ext2/balloc.c        2012-12-11 15:56:32.000000000 +0000
2236 @@ -699,7 +699,6 @@ ext2_try_to_allocate(struct super_block
2237                         start = 0;
2238                 end = EXT2_BLOCKS_PER_GROUP(sb);
2239         }
2240 -
2241         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2242  
2243  repeat:
2244 diff -NurpP --minimal linux-3.7/fs/ext2/ext2.h linux-3.7-vs2.3.5.1/fs/ext2/ext2.h
2245 --- linux-3.7/fs/ext2/ext2.h    2012-07-22 21:39:39.000000000 +0000
2246 +++ linux-3.7-vs2.3.5.1/fs/ext2/ext2.h  2012-12-11 15:56:32.000000000 +0000
2247 @@ -244,8 +244,12 @@ struct ext2_group_desc
2248  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2249  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2250  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2251 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2252  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2253  
2254 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2255 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2256 +
2257  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2258  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2259  
2260 @@ -329,7 +333,8 @@ struct ext2_inode {
2261                         __u16   i_pad1;
2262                         __le16  l_i_uid_high;   /* these 2 fields    */
2263                         __le16  l_i_gid_high;   /* were reserved2[0] */
2264 -                       __u32   l_i_reserved2;
2265 +                       __le16  l_i_tag;        /* Context Tag */
2266 +                       __u16   l_i_reserved2;
2267                 } linux2;
2268                 struct {
2269                         __u8    h_i_frag;       /* Fragment number */
2270 @@ -357,6 +362,7 @@ struct ext2_inode {
2271  #define i_gid_low      i_gid
2272  #define i_uid_high     osd2.linux2.l_i_uid_high
2273  #define i_gid_high     osd2.linux2.l_i_gid_high
2274 +#define i_raw_tag      osd2.linux2.l_i_tag
2275  #define i_reserved2    osd2.linux2.l_i_reserved2
2276  
2277  /*
2278 @@ -384,6 +390,7 @@ struct ext2_inode {
2279  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2280  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2281  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2282 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2283  
2284  
2285  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2286 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2287  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2288  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2289                        u64 start, u64 len);
2290 +extern int ext2_sync_flags(struct inode *, int, int);
2291  
2292  /* ioctl.c */
2293  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2294 diff -NurpP --minimal linux-3.7/fs/ext2/file.c linux-3.7-vs2.3.5.1/fs/ext2/file.c
2295 --- linux-3.7/fs/ext2/file.c    2011-10-24 16:45:27.000000000 +0000
2296 +++ linux-3.7-vs2.3.5.1/fs/ext2/file.c  2012-12-11 15:56:32.000000000 +0000
2297 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2298         .setattr        = ext2_setattr,
2299         .get_acl        = ext2_get_acl,
2300         .fiemap         = ext2_fiemap,
2301 +       .sync_flags     = ext2_sync_flags,
2302  };
2303 diff -NurpP --minimal linux-3.7/fs/ext2/ialloc.c linux-3.7-vs2.3.5.1/fs/ext2/ialloc.c
2304 --- linux-3.7/fs/ext2/ialloc.c  2012-10-04 13:27:39.000000000 +0000
2305 +++ linux-3.7-vs2.3.5.1/fs/ext2/ialloc.c        2012-12-11 15:56:32.000000000 +0000
2306 @@ -17,6 +17,7 @@
2307  #include <linux/backing-dev.h>
2308  #include <linux/buffer_head.h>
2309  #include <linux/random.h>
2310 +#include <linux/vs_tag.h>
2311  #include "ext2.h"
2312  #include "xattr.h"
2313  #include "acl.h"
2314 @@ -547,6 +548,7 @@ got:
2315                 inode->i_mode = mode;
2316                 inode->i_uid = current_fsuid();
2317                 inode->i_gid = dir->i_gid;
2318 +               inode->i_tag = dx_current_fstag(sb);
2319         } else
2320                 inode_init_owner(inode, dir, mode);
2321  
2322 diff -NurpP --minimal linux-3.7/fs/ext2/inode.c linux-3.7-vs2.3.5.1/fs/ext2/inode.c
2323 --- linux-3.7/fs/ext2/inode.c   2012-10-04 13:27:39.000000000 +0000
2324 +++ linux-3.7-vs2.3.5.1/fs/ext2/inode.c 2012-12-11 19:22:08.000000000 +0000
2325 @@ -31,6 +31,7 @@
2326  #include <linux/mpage.h>
2327  #include <linux/fiemap.h>
2328  #include <linux/namei.h>
2329 +#include <linux/vs_tag.h>
2330  #include "ext2.h"
2331  #include "acl.h"
2332  #include "xip.h"
2333 @@ -1165,7 +1166,7 @@ static void ext2_truncate_blocks(struct
2334                 return;
2335         if (ext2_inode_is_fast_symlink(inode))
2336                 return;
2337 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2338 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2339                 return;
2340         __ext2_truncate_blocks(inode, offset);
2341  }
2342 @@ -1256,36 +1257,61 @@ void ext2_set_inode_flags(struct inode *
2343  {
2344         unsigned int flags = EXT2_I(inode)->i_flags;
2345  
2346 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2347 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2348 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2349 +
2350 +
2351 +       if (flags & EXT2_IMMUTABLE_FL)
2352 +               inode->i_flags |= S_IMMUTABLE;
2353 +       if (flags & EXT2_IXUNLINK_FL)
2354 +               inode->i_flags |= S_IXUNLINK;
2355 +
2356         if (flags & EXT2_SYNC_FL)
2357                 inode->i_flags |= S_SYNC;
2358         if (flags & EXT2_APPEND_FL)
2359                 inode->i_flags |= S_APPEND;
2360 -       if (flags & EXT2_IMMUTABLE_FL)
2361 -               inode->i_flags |= S_IMMUTABLE;
2362         if (flags & EXT2_NOATIME_FL)
2363                 inode->i_flags |= S_NOATIME;
2364         if (flags & EXT2_DIRSYNC_FL)
2365                 inode->i_flags |= S_DIRSYNC;
2366 +
2367 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2368 +
2369 +       if (flags & EXT2_BARRIER_FL)
2370 +               inode->i_vflags |= V_BARRIER;
2371 +       if (flags & EXT2_COW_FL)
2372 +               inode->i_vflags |= V_COW;
2373  }
2374  
2375  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2376  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2377  {
2378         unsigned int flags = ei->vfs_inode.i_flags;
2379 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2380 +
2381 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2382 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2383 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2384 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2385 +
2386 +       if (flags & S_IMMUTABLE)
2387 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2388 +       if (flags & S_IXUNLINK)
2389 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2390  
2391 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2392 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2393         if (flags & S_SYNC)
2394                 ei->i_flags |= EXT2_SYNC_FL;
2395         if (flags & S_APPEND)
2396                 ei->i_flags |= EXT2_APPEND_FL;
2397 -       if (flags & S_IMMUTABLE)
2398 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2399         if (flags & S_NOATIME)
2400                 ei->i_flags |= EXT2_NOATIME_FL;
2401         if (flags & S_DIRSYNC)
2402                 ei->i_flags |= EXT2_DIRSYNC_FL;
2403 +
2404 +       if (vflags & V_BARRIER)
2405 +               ei->i_flags |= EXT2_BARRIER_FL;
2406 +       if (vflags & V_COW)
2407 +               ei->i_flags |= EXT2_COW_FL;
2408  }
2409  
2410  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2411 @@ -1321,8 +1347,10 @@ struct inode *ext2_iget (struct super_bl
2412                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2413                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2414         }
2415 -       i_uid_write(inode, i_uid);
2416 -       i_gid_write(inode, i_gid);
2417 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2418 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2419 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2420 +               le16_to_cpu(raw_inode->i_raw_tag)));
2421         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2422         inode->i_size = le32_to_cpu(raw_inode->i_size);
2423         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2424 @@ -1420,8 +1448,10 @@ static int __ext2_write_inode(struct ino
2425         struct ext2_inode_info *ei = EXT2_I(inode);
2426         struct super_block *sb = inode->i_sb;
2427         ino_t ino = inode->i_ino;
2428 -       uid_t uid = i_uid_read(inode);
2429 -       gid_t gid = i_gid_read(inode);
2430 +       uid_t uid = TAGINO_UID(DX_TAG(inode),
2431 +               i_uid_read(inode), i_tag_read(inode));
2432 +       gid_t gid = TAGINO_GID(DX_TAG(inode),
2433 +               i_gid_read(inode), i_tag_read(inode));
2434         struct buffer_head * bh;
2435         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2436         int n;
2437 @@ -1457,6 +1487,9 @@ static int __ext2_write_inode(struct ino
2438                 raw_inode->i_uid_high = 0;
2439                 raw_inode->i_gid_high = 0;
2440         }
2441 +#ifdef CONFIG_TAGGING_INTERN
2442 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2443 +#endif
2444         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2445         raw_inode->i_size = cpu_to_le32(inode->i_size);
2446         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2447 @@ -1537,7 +1570,8 @@ int ext2_setattr(struct dentry *dentry,
2448         if (is_quota_modification(inode, iattr))
2449                 dquot_initialize(inode);
2450         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2451 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2452 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2453 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2454                 error = dquot_transfer(inode, iattr);
2455                 if (error)
2456                         return error;
2457 diff -NurpP --minimal linux-3.7/fs/ext2/ioctl.c linux-3.7-vs2.3.5.1/fs/ext2/ioctl.c
2458 --- linux-3.7/fs/ext2/ioctl.c   2012-03-19 18:47:25.000000000 +0000
2459 +++ linux-3.7-vs2.3.5.1/fs/ext2/ioctl.c 2012-12-11 15:56:32.000000000 +0000
2460 @@ -17,6 +17,16 @@
2461  #include <asm/uaccess.h>
2462  
2463  
2464 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2465 +{
2466 +       inode->i_flags = flags;
2467 +       inode->i_vflags = vflags;
2468 +       ext2_get_inode_flags(EXT2_I(inode));
2469 +       inode->i_ctime = CURRENT_TIME_SEC;
2470 +       mark_inode_dirty(inode);
2471 +       return 0;
2472 +}
2473 +
2474  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2475  {
2476         struct inode *inode = filp->f_dentry->d_inode;
2477 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2478  
2479                 flags = ext2_mask_flags(inode->i_mode, flags);
2480  
2481 +               if (IS_BARRIER(inode)) {
2482 +                       vxwprintk_task(1, "messing with the barrier.");
2483 +                       return -EACCES;
2484 +               }
2485 +
2486                 mutex_lock(&inode->i_mutex);
2487                 /* Is it quota file? Do not allow user to mess with it */
2488                 if (IS_NOQUOTA(inode)) {
2489 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2490                  *
2491                  * This test looks nicer. Thanks to Pauline Middelink
2492                  */
2493 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2494 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2495 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2496 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2497                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2498                                 mutex_unlock(&inode->i_mutex);
2499                                 ret = -EPERM;
2500 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2501                         }
2502                 }
2503  
2504 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2505 +               flags &= EXT2_FL_USER_MODIFIABLE;
2506                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2507                 ei->i_flags = flags;
2508  
2509 diff -NurpP --minimal linux-3.7/fs/ext2/namei.c linux-3.7-vs2.3.5.1/fs/ext2/namei.c
2510 --- linux-3.7/fs/ext2/namei.c   2012-10-04 13:27:39.000000000 +0000
2511 +++ linux-3.7-vs2.3.5.1/fs/ext2/namei.c 2012-12-11 15:56:32.000000000 +0000
2512 @@ -32,6 +32,7 @@
2513  
2514  #include <linux/pagemap.h>
2515  #include <linux/quotaops.h>
2516 +#include <linux/vs_tag.h>
2517  #include "ext2.h"
2518  #include "xattr.h"
2519  #include "acl.h"
2520 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2521                                         (unsigned long) ino);
2522                         return ERR_PTR(-EIO);
2523                 }
2524 +               dx_propagate_tag(nd, inode);
2525         }
2526         return d_splice_alias(inode, dentry);
2527  }
2528 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2529         .removexattr    = generic_removexattr,
2530  #endif
2531         .setattr        = ext2_setattr,
2532 +       .sync_flags     = ext2_sync_flags,
2533         .get_acl        = ext2_get_acl,
2534  };
2535  
2536 diff -NurpP --minimal linux-3.7/fs/ext2/super.c linux-3.7-vs2.3.5.1/fs/ext2/super.c
2537 --- linux-3.7/fs/ext2/super.c   2012-12-11 15:47:33.000000000 +0000
2538 +++ linux-3.7-vs2.3.5.1/fs/ext2/super.c 2012-12-11 15:56:32.000000000 +0000
2539 @@ -395,7 +395,8 @@ enum {
2540         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2541         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2542         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2543 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2544 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2545 +       Opt_tag, Opt_notag, Opt_tagid
2546  };
2547  
2548  static const match_table_t tokens = {
2549 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2550         {Opt_acl, "acl"},
2551         {Opt_noacl, "noacl"},
2552         {Opt_xip, "xip"},
2553 +       {Opt_tag, "tag"},
2554 +       {Opt_notag, "notag"},
2555 +       {Opt_tagid, "tagid=%u"},
2556         {Opt_grpquota, "grpquota"},
2557         {Opt_ignore, "noquota"},
2558         {Opt_quota, "quota"},
2559 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2560                 case Opt_nouid32:
2561                         set_opt (sbi->s_mount_opt, NO_UID32);
2562                         break;
2563 +#ifndef CONFIG_TAGGING_NONE
2564 +               case Opt_tag:
2565 +                       set_opt (sbi->s_mount_opt, TAGGED);
2566 +                       break;
2567 +               case Opt_notag:
2568 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2569 +                       break;
2570 +#endif
2571 +#ifdef CONFIG_PROPAGATE
2572 +               case Opt_tagid:
2573 +                       /* use args[0] */
2574 +                       set_opt (sbi->s_mount_opt, TAGGED);
2575 +                       break;
2576 +#endif
2577                 case Opt_nocheck:
2578                         clear_opt (sbi->s_mount_opt, CHECK);
2579                         break;
2580 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2581         if (!parse_options((char *) data, sb))
2582                 goto failed_mount;
2583  
2584 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2585 +               sb->s_flags |= MS_TAGGED;
2586         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2587                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2588                  MS_POSIXACL : 0);
2589 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2590                 err = -EINVAL;
2591                 goto restore_opts;
2592         }
2593 +
2594 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2595 +               !(sb->s_flags & MS_TAGGED)) {
2596 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2597 +                      sb->s_id);
2598 +               err = -EINVAL;
2599 +               goto restore_opts;
2600 +       }
2601  
2602         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2603                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2604 diff -NurpP --minimal linux-3.7/fs/ext3/ext3.h linux-3.7-vs2.3.5.1/fs/ext3/ext3.h
2605 --- linux-3.7/fs/ext3/ext3.h    2012-07-22 21:39:39.000000000 +0000
2606 +++ linux-3.7-vs2.3.5.1/fs/ext3/ext3.h  2012-12-11 15:56:32.000000000 +0000
2607 @@ -151,10 +151,14 @@ struct ext3_group_desc
2608  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2609  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2610  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2611 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2612  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2613  
2614 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2615 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2616 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2617 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2618 +
2619 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2620 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2621  
2622  /* Flags that should be inherited by new inodes from their parent. */
2623  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2624 @@ -290,7 +294,8 @@ struct ext3_inode {
2625                         __u16   i_pad1;
2626                         __le16  l_i_uid_high;   /* these 2 fields    */
2627                         __le16  l_i_gid_high;   /* were reserved2[0] */
2628 -                       __u32   l_i_reserved2;
2629 +                       __le16  l_i_tag;        /* Context Tag */
2630 +                       __u16   l_i_reserved2;
2631                 } linux2;
2632                 struct {
2633                         __u8    h_i_frag;       /* Fragment number */
2634 @@ -320,6 +325,7 @@ struct ext3_inode {
2635  #define i_gid_low      i_gid
2636  #define i_uid_high     osd2.linux2.l_i_uid_high
2637  #define i_gid_high     osd2.linux2.l_i_gid_high
2638 +#define i_raw_tag      osd2.linux2.l_i_tag
2639  #define i_reserved2    osd2.linux2.l_i_reserved2
2640  
2641  /*
2642 @@ -364,6 +370,7 @@ struct ext3_inode {
2643  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2644  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2645                                                   * error in ordered mode */
2646 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2647  
2648  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2649  #ifndef _LINUX_EXT2_FS_H
2650 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2651  extern void ext3_set_aops(struct inode *inode);
2652  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2653                        u64 start, u64 len);
2654 +extern int ext3_sync_flags(struct inode *, int, int);
2655  
2656  /* ioctl.c */
2657  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2658 diff -NurpP --minimal linux-3.7/fs/ext3/file.c linux-3.7-vs2.3.5.1/fs/ext3/file.c
2659 --- linux-3.7/fs/ext3/file.c    2012-05-21 16:07:20.000000000 +0000
2660 +++ linux-3.7-vs2.3.5.1/fs/ext3/file.c  2012-12-11 15:56:32.000000000 +0000
2661 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2662  #endif
2663         .get_acl        = ext3_get_acl,
2664         .fiemap         = ext3_fiemap,
2665 +       .sync_flags     = ext3_sync_flags,
2666  };
2667  
2668 diff -NurpP --minimal linux-3.7/fs/ext3/ialloc.c linux-3.7-vs2.3.5.1/fs/ext3/ialloc.c
2669 --- linux-3.7/fs/ext3/ialloc.c  2012-07-22 21:39:39.000000000 +0000
2670 +++ linux-3.7-vs2.3.5.1/fs/ext3/ialloc.c        2012-12-11 15:56:32.000000000 +0000
2671 @@ -14,6 +14,7 @@
2672  
2673  #include <linux/quotaops.h>
2674  #include <linux/random.h>
2675 +#include <linux/vs_tag.h>
2676  
2677  #include "ext3.h"
2678  #include "xattr.h"
2679 @@ -469,6 +470,7 @@ got:
2680                 inode->i_mode = mode;
2681                 inode->i_uid = current_fsuid();
2682                 inode->i_gid = dir->i_gid;
2683 +               inode->i_tag = dx_current_fstag(sb);
2684         } else
2685                 inode_init_owner(inode, dir, mode);
2686  
2687 diff -NurpP --minimal linux-3.7/fs/ext3/inode.c linux-3.7-vs2.3.5.1/fs/ext3/inode.c
2688 --- linux-3.7/fs/ext3/inode.c   2012-12-11 15:47:33.000000000 +0000
2689 +++ linux-3.7-vs2.3.5.1/fs/ext3/inode.c 2012-12-11 19:24:12.000000000 +0000
2690 @@ -27,6 +27,8 @@
2691  #include <linux/writeback.h>
2692  #include <linux/mpage.h>
2693  #include <linux/namei.h>
2694 +#include <linux/vs_tag.h>
2695 +
2696  #include "ext3.h"
2697  #include "xattr.h"
2698  #include "acl.h"
2699 @@ -2848,36 +2850,60 @@ void ext3_set_inode_flags(struct inode *
2700  {
2701         unsigned int flags = EXT3_I(inode)->i_flags;
2702  
2703 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2704 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2705 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2706 +
2707 +       if (flags & EXT3_IMMUTABLE_FL)
2708 +               inode->i_flags |= S_IMMUTABLE;
2709 +       if (flags & EXT3_IXUNLINK_FL)
2710 +               inode->i_flags |= S_IXUNLINK;
2711 +
2712         if (flags & EXT3_SYNC_FL)
2713                 inode->i_flags |= S_SYNC;
2714         if (flags & EXT3_APPEND_FL)
2715                 inode->i_flags |= S_APPEND;
2716 -       if (flags & EXT3_IMMUTABLE_FL)
2717 -               inode->i_flags |= S_IMMUTABLE;
2718         if (flags & EXT3_NOATIME_FL)
2719                 inode->i_flags |= S_NOATIME;
2720         if (flags & EXT3_DIRSYNC_FL)
2721                 inode->i_flags |= S_DIRSYNC;
2722 +
2723 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2724 +
2725 +       if (flags & EXT3_BARRIER_FL)
2726 +               inode->i_vflags |= V_BARRIER;
2727 +       if (flags & EXT3_COW_FL)
2728 +               inode->i_vflags |= V_COW;
2729  }
2730  
2731  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2732  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2733  {
2734         unsigned int flags = ei->vfs_inode.i_flags;
2735 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2736 +
2737 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2738 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2739 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2740 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2741 +
2742 +       if (flags & S_IMMUTABLE)
2743 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2744 +       if (flags & S_IXUNLINK)
2745 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2746  
2747 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2748 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2749         if (flags & S_SYNC)
2750                 ei->i_flags |= EXT3_SYNC_FL;
2751         if (flags & S_APPEND)
2752                 ei->i_flags |= EXT3_APPEND_FL;
2753 -       if (flags & S_IMMUTABLE)
2754 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2755         if (flags & S_NOATIME)
2756                 ei->i_flags |= EXT3_NOATIME_FL;
2757         if (flags & S_DIRSYNC)
2758                 ei->i_flags |= EXT3_DIRSYNC_FL;
2759 +
2760 +       if (vflags & V_BARRIER)
2761 +               ei->i_flags |= EXT3_BARRIER_FL;
2762 +       if (vflags & V_COW)
2763 +               ei->i_flags |= EXT3_COW_FL;
2764  }
2765  
2766  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2767 @@ -2915,8 +2941,10 @@ struct inode *ext3_iget(struct super_blo
2768                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2769                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2770         }
2771 -       i_uid_write(inode, i_uid);
2772 -       i_gid_write(inode, i_gid);
2773 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2774 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2775 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2776 +               le16_to_cpu(raw_inode->i_raw_tag)));
2777         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2778         inode->i_size = le32_to_cpu(raw_inode->i_size);
2779         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2780 @@ -3088,8 +3116,10 @@ again:
2781  
2782         ext3_get_inode_flags(ei);
2783         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2784 -       i_uid = i_uid_read(inode);
2785 -       i_gid = i_gid_read(inode);
2786 +       i_uid = TAGINO_UID(DX_TAG(inode),
2787 +               i_uid_read(inode), i_tag_read(inode));
2788 +       i_gid = TAGINO_GID(DX_TAG(inode),
2789 +               i_gid_read(inode), i_tag_read(inode));
2790         if(!(test_opt(inode->i_sb, NO_UID32))) {
2791                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2792                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2793 @@ -3114,6 +3144,9 @@ again:
2794                 raw_inode->i_uid_high = 0;
2795                 raw_inode->i_gid_high = 0;
2796         }
2797 +#ifdef CONFIG_TAGGING_INTERN
2798 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2799 +#endif
2800         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2801         disksize = cpu_to_le32(ei->i_disksize);
2802         if (disksize != raw_inode->i_size) {
2803 @@ -3282,7 +3315,8 @@ int ext3_setattr(struct dentry *dentry,
2804         if (is_quota_modification(inode, attr))
2805                 dquot_initialize(inode);
2806         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2807 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2808 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2809 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2810                 handle_t *handle;
2811  
2812                 /* (user+group)*(old+new) structure, inode write (sb,
2813 @@ -3304,6 +3338,8 @@ int ext3_setattr(struct dentry *dentry,
2814                         inode->i_uid = attr->ia_uid;
2815                 if (attr->ia_valid & ATTR_GID)
2816                         inode->i_gid = attr->ia_gid;
2817 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2818 +                       inode->i_tag = attr->ia_tag;
2819                 error = ext3_mark_inode_dirty(handle, inode);
2820                 ext3_journal_stop(handle);
2821         }
2822 diff -NurpP --minimal linux-3.7/fs/ext3/ioctl.c linux-3.7-vs2.3.5.1/fs/ext3/ioctl.c
2823 --- linux-3.7/fs/ext3/ioctl.c   2012-05-21 16:07:20.000000000 +0000
2824 +++ linux-3.7-vs2.3.5.1/fs/ext3/ioctl.c 2012-12-11 15:56:32.000000000 +0000
2825 @@ -12,6 +12,34 @@
2826  #include <asm/uaccess.h>
2827  #include "ext3.h"
2828  
2829 +
2830 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2831 +{
2832 +       handle_t *handle = NULL;
2833 +       struct ext3_iloc iloc;
2834 +       int err;
2835 +
2836 +       handle = ext3_journal_start(inode, 1);
2837 +       if (IS_ERR(handle))
2838 +               return PTR_ERR(handle);
2839 +
2840 +       if (IS_SYNC(inode))
2841 +               handle->h_sync = 1;
2842 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2843 +       if (err)
2844 +               goto flags_err;
2845 +
2846 +       inode->i_flags = flags;
2847 +       inode->i_vflags = vflags;
2848 +       ext3_get_inode_flags(EXT3_I(inode));
2849 +       inode->i_ctime = CURRENT_TIME_SEC;
2850 +
2851 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2852 +flags_err:
2853 +       ext3_journal_stop(handle);
2854 +       return err;
2855 +}
2856 +
2857  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2858  {
2859         struct inode *inode = filp->f_dentry->d_inode;
2860 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2861  
2862                 flags = ext3_mask_flags(inode->i_mode, flags);
2863  
2864 +               if (IS_BARRIER(inode)) {
2865 +                       vxwprintk_task(1, "messing with the barrier.");
2866 +                       return -EACCES;
2867 +               }
2868 +
2869                 mutex_lock(&inode->i_mutex);
2870  
2871                 /* Is it quota file? Do not allow user to mess with it */
2872 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2873                  *
2874                  * This test looks nicer. Thanks to Pauline Middelink
2875                  */
2876 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2877 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2878 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2879 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2880                         if (!capable(CAP_LINUX_IMMUTABLE))
2881                                 goto flags_out;
2882                 }
2883 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2884                 if (err)
2885                         goto flags_err;
2886  
2887 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2888 +               flags &= EXT3_FL_USER_MODIFIABLE;
2889                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2890                 ei->i_flags = flags;
2891  
2892 diff -NurpP --minimal linux-3.7/fs/ext3/namei.c linux-3.7-vs2.3.5.1/fs/ext3/namei.c
2893 --- linux-3.7/fs/ext3/namei.c   2012-12-11 15:47:33.000000000 +0000
2894 +++ linux-3.7-vs2.3.5.1/fs/ext3/namei.c 2012-12-11 15:56:32.000000000 +0000
2895 @@ -25,6 +25,8 @@
2896   */
2897  
2898  #include <linux/quotaops.h>
2899 +#include <linux/vs_tag.h>
2900 +
2901  #include "ext3.h"
2902  #include "namei.h"
2903  #include "xattr.h"
2904 @@ -919,6 +921,7 @@ restart:
2905                                         submit_bh(READ | REQ_META | REQ_PRIO,
2906                                                   bh);
2907                                 }
2908 +               dx_propagate_tag(nd, inode);
2909                         }
2910                 }
2911                 if ((bh = bh_use[ra_ptr++]) == NULL)
2912 @@ -2528,6 +2531,7 @@ const struct inode_operations ext3_dir_i
2913         .listxattr      = ext3_listxattr,
2914         .removexattr    = generic_removexattr,
2915  #endif
2916 +       .sync_flags     = ext3_sync_flags,
2917         .get_acl        = ext3_get_acl,
2918  };
2919  
2920 diff -NurpP --minimal linux-3.7/fs/ext3/super.c linux-3.7-vs2.3.5.1/fs/ext3/super.c
2921 --- linux-3.7/fs/ext3/super.c   2012-12-11 15:47:33.000000000 +0000
2922 +++ linux-3.7-vs2.3.5.1/fs/ext3/super.c 2012-12-11 15:56:32.000000000 +0000
2923 @@ -816,7 +816,8 @@ enum {
2924         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2925         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2926         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2927 -       Opt_resize, Opt_usrquota, Opt_grpquota
2928 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2929 +       Opt_tag, Opt_notag, Opt_tagid
2930  };
2931  
2932  static const match_table_t tokens = {
2933 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2934         {Opt_barrier, "barrier"},
2935         {Opt_nobarrier, "nobarrier"},
2936         {Opt_resize, "resize"},
2937 +       {Opt_tag, "tag"},
2938 +       {Opt_notag, "notag"},
2939 +       {Opt_tagid, "tagid=%u"},
2940         {Opt_err, NULL},
2941  };
2942  
2943 @@ -1038,6 +1042,20 @@ static int parse_options (char *options,
2944                 case Opt_nouid32:
2945                         set_opt (sbi->s_mount_opt, NO_UID32);
2946                         break;
2947 +#ifndef CONFIG_TAGGING_NONE
2948 +               case Opt_tag:
2949 +                       set_opt (sbi->s_mount_opt, TAGGED);
2950 +                       break;
2951 +               case Opt_notag:
2952 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2953 +                       break;
2954 +#endif
2955 +#ifdef CONFIG_PROPAGATE
2956 +               case Opt_tagid:
2957 +                       /* use args[0] */
2958 +                       set_opt (sbi->s_mount_opt, TAGGED);
2959 +                       break;
2960 +#endif
2961                 case Opt_nocheck:
2962                         clear_opt (sbi->s_mount_opt, CHECK);
2963                         break;
2964 @@ -1738,6 +1756,9 @@ static int ext3_fill_super (struct super
2965                             NULL, 0))
2966                 goto failed_mount;
2967  
2968 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2969 +               sb->s_flags |= MS_TAGGED;
2970 +
2971         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2972                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2973  
2974 @@ -2622,6 +2643,14 @@ static int ext3_remount (struct super_bl
2975         if (test_opt(sb, ABORT))
2976                 ext3_abort(sb, __func__, "Abort forced by user");
2977  
2978 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2979 +               !(sb->s_flags & MS_TAGGED)) {
2980 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2981 +                       sb->s_id);
2982 +               err = -EINVAL;
2983 +               goto restore_opts;
2984 +       }
2985 +
2986         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2987                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2988  
2989 diff -NurpP --minimal linux-3.7/fs/ext4/ext4.h linux-3.7-vs2.3.5.1/fs/ext4/ext4.h
2990 --- linux-3.7/fs/ext4/ext4.h    2012-12-11 15:47:33.000000000 +0000
2991 +++ linux-3.7-vs2.3.5.1/fs/ext4/ext4.h  2012-12-11 15:56:32.000000000 +0000
2992 @@ -392,8 +392,12 @@ struct flex_groups {
2993  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2994  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2995  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2996 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2997  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2998  
2999 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3000 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3001 +
3002  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3003  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3004  
3005 @@ -665,7 +669,7 @@ struct ext4_inode {
3006                         __le16  l_i_uid_high;   /* these 2 fields */
3007                         __le16  l_i_gid_high;   /* were reserved2[0] */
3008                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
3009 -                       __le16  l_i_reserved;
3010 +                       __le16  l_i_tag;        /* Context Tag */
3011                 } linux2;
3012                 struct {
3013                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3014 @@ -783,6 +787,7 @@ do {                                                                               \
3015  #define i_gid_low      i_gid
3016  #define i_uid_high     osd2.linux2.l_i_uid_high
3017  #define i_gid_high     osd2.linux2.l_i_gid_high
3018 +#define i_raw_tag      osd2.linux2.l_i_tag
3019  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
3020  
3021  #elif defined(__GNU__)
3022 @@ -961,6 +966,7 @@ struct ext4_inode_info {
3023  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3024  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3025  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3026 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3027  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3028  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3029  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3030 @@ -2412,6 +2418,7 @@ extern int ext4_map_blocks(handle_t *han
3031                            struct ext4_map_blocks *map, int flags);
3032  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3033                         __u64 start, __u64 len);
3034 +extern int ext4_sync_flags(struct inode *, int, int);
3035  /* move_extent.c */
3036  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3037                              __u64 start_orig, __u64 start_donor,
3038 diff -NurpP --minimal linux-3.7/fs/ext4/file.c linux-3.7-vs2.3.5.1/fs/ext4/file.c
3039 --- linux-3.7/fs/ext4/file.c    2012-12-11 15:47:33.000000000 +0000
3040 +++ linux-3.7-vs2.3.5.1/fs/ext4/file.c  2012-12-11 15:56:32.000000000 +0000
3041 @@ -334,5 +334,6 @@ const struct inode_operations ext4_file_
3042  #endif
3043         .get_acl        = ext4_get_acl,
3044         .fiemap         = ext4_fiemap,
3045 +       .sync_flags     = ext4_sync_flags,
3046  };
3047  
3048 diff -NurpP --minimal linux-3.7/fs/ext4/ialloc.c linux-3.7-vs2.3.5.1/fs/ext4/ialloc.c
3049 --- linux-3.7/fs/ext4/ialloc.c  2012-12-11 15:47:33.000000000 +0000
3050 +++ linux-3.7-vs2.3.5.1/fs/ext4/ialloc.c        2012-12-11 15:56:32.000000000 +0000
3051 @@ -22,6 +22,7 @@
3052  #include <linux/random.h>
3053  #include <linux/bitops.h>
3054  #include <linux/blkdev.h>
3055 +#include <linux/vs_tag.h>
3056  #include <asm/byteorder.h>
3057  
3058  #include "ext4.h"
3059 @@ -848,6 +849,7 @@ got:
3060                 inode->i_mode = mode;
3061                 inode->i_uid = current_fsuid();
3062                 inode->i_gid = dir->i_gid;
3063 +               inode->i_tag = dx_current_fstag(sb);
3064         } else
3065                 inode_init_owner(inode, dir, mode);
3066  
3067 diff -NurpP --minimal linux-3.7/fs/ext4/inode.c linux-3.7-vs2.3.5.1/fs/ext4/inode.c
3068 --- linux-3.7/fs/ext4/inode.c   2012-12-11 15:47:33.000000000 +0000
3069 +++ linux-3.7-vs2.3.5.1/fs/ext4/inode.c 2012-12-11 19:25:58.000000000 +0000
3070 @@ -37,6 +37,7 @@
3071  #include <linux/printk.h>
3072  #include <linux/slab.h>
3073  #include <linux/ratelimit.h>
3074 +#include <linux/vs_tag.h>
3075  
3076  #include "ext4_jbd2.h"
3077  #include "xattr.h"
3078 @@ -3695,41 +3696,64 @@ void ext4_set_inode_flags(struct inode *
3079  {
3080         unsigned int flags = EXT4_I(inode)->i_flags;
3081  
3082 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3083 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3084 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3085 +
3086 +       if (flags & EXT4_IMMUTABLE_FL)
3087 +               inode->i_flags |= S_IMMUTABLE;
3088 +       if (flags & EXT4_IXUNLINK_FL)
3089 +               inode->i_flags |= S_IXUNLINK;
3090 +
3091         if (flags & EXT4_SYNC_FL)
3092                 inode->i_flags |= S_SYNC;
3093         if (flags & EXT4_APPEND_FL)
3094                 inode->i_flags |= S_APPEND;
3095 -       if (flags & EXT4_IMMUTABLE_FL)
3096 -               inode->i_flags |= S_IMMUTABLE;
3097         if (flags & EXT4_NOATIME_FL)
3098                 inode->i_flags |= S_NOATIME;
3099         if (flags & EXT4_DIRSYNC_FL)
3100                 inode->i_flags |= S_DIRSYNC;
3101 +
3102 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3103 +
3104 +       if (flags & EXT4_BARRIER_FL)
3105 +               inode->i_vflags |= V_BARRIER;
3106 +       if (flags & EXT4_COW_FL)
3107 +               inode->i_vflags |= V_COW;
3108  }
3109  
3110  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3111  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3112  {
3113 -       unsigned int vfs_fl;
3114 +       unsigned int vfs_fl, vfs_vf;
3115         unsigned long old_fl, new_fl;
3116  
3117         do {
3118                 vfs_fl = ei->vfs_inode.i_flags;
3119 +               vfs_vf = ei->vfs_inode.i_vflags;
3120                 old_fl = ei->i_flags;
3121                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3122                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3123 -                               EXT4_DIRSYNC_FL);
3124 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3125 +                               EXT4_COW_FL);
3126 +
3127 +               if (vfs_fl & S_IMMUTABLE)
3128 +                       new_fl |= EXT4_IMMUTABLE_FL;
3129 +               if (vfs_fl & S_IXUNLINK)
3130 +                       new_fl |= EXT4_IXUNLINK_FL;
3131 +
3132                 if (vfs_fl & S_SYNC)
3133                         new_fl |= EXT4_SYNC_FL;
3134                 if (vfs_fl & S_APPEND)
3135                         new_fl |= EXT4_APPEND_FL;
3136 -               if (vfs_fl & S_IMMUTABLE)
3137 -                       new_fl |= EXT4_IMMUTABLE_FL;
3138                 if (vfs_fl & S_NOATIME)
3139                         new_fl |= EXT4_NOATIME_FL;
3140                 if (vfs_fl & S_DIRSYNC)
3141                         new_fl |= EXT4_DIRSYNC_FL;
3142 +
3143 +               if (vfs_vf & V_BARRIER)
3144 +                       new_fl |= EXT4_BARRIER_FL;
3145 +               if (vfs_vf & V_COW)
3146 +                       new_fl |= EXT4_COW_FL;
3147         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3148  }
3149  
3150 @@ -3821,8 +3845,10 @@ struct inode *ext4_iget(struct super_blo
3151                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3152                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3153         }
3154 -       i_uid_write(inode, i_uid);
3155 -       i_gid_write(inode, i_gid);
3156 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3157 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3158 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3159 +               le16_to_cpu(raw_inode->i_raw_tag)));
3160         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3161  
3162         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3163 @@ -4046,8 +4072,10 @@ static int ext4_do_update_inode(handle_t
3164  
3165         ext4_get_inode_flags(ei);
3166         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3167 -       i_uid = i_uid_read(inode);
3168 -       i_gid = i_gid_read(inode);
3169 +       i_uid = TAGINO_UID(DX_TAG(inode),
3170 +               i_uid_read(inode), i_tag_read(inode));
3171 +       i_gid = TAGINO_GID(DX_TAG(inode),
3172 +               i_gid_read(inode), i_tag_read(inode));
3173         if (!(test_opt(inode->i_sb, NO_UID32))) {
3174                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3175                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3176 @@ -4070,6 +4098,9 @@ static int ext4_do_update_inode(handle_t
3177                 raw_inode->i_uid_high = 0;
3178                 raw_inode->i_gid_high = 0;
3179         }
3180 +#ifdef CONFIG_TAGGING_INTERN
3181 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3182 +#endif
3183         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3184  
3185         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3186 @@ -4258,7 +4289,8 @@ int ext4_setattr(struct dentry *dentry,
3187         if (is_quota_modification(inode, attr))
3188                 dquot_initialize(inode);
3189         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3190 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3191 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3192 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3193                 handle_t *handle;
3194  
3195                 /* (user+group)*(old+new) structure, inode write (sb,
3196 @@ -4280,6 +4312,8 @@ int ext4_setattr(struct dentry *dentry,
3197                         inode->i_uid = attr->ia_uid;
3198                 if (attr->ia_valid & ATTR_GID)
3199                         inode->i_gid = attr->ia_gid;
3200 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3201 +                       inode->i_tag = attr->ia_tag;
3202                 error = ext4_mark_inode_dirty(handle, inode);
3203                 ext4_journal_stop(handle);
3204         }
3205 diff -NurpP --minimal linux-3.7/fs/ext4/ioctl.c linux-3.7-vs2.3.5.1/fs/ext4/ioctl.c
3206 --- linux-3.7/fs/ext4/ioctl.c   2012-12-11 15:47:33.000000000 +0000
3207 +++ linux-3.7-vs2.3.5.1/fs/ext4/ioctl.c 2012-12-11 15:56:32.000000000 +0000
3208 @@ -14,12 +14,40 @@
3209  #include <linux/compat.h>
3210  #include <linux/mount.h>
3211  #include <linux/file.h>
3212 +#include <linux/vs_tag.h>
3213  #include <asm/uaccess.h>
3214  #include "ext4_jbd2.h"
3215  #include "ext4.h"
3216  
3217  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3218  
3219 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3220 +{
3221 +       handle_t *handle = NULL;
3222 +       struct ext4_iloc iloc;
3223 +       int err;
3224 +
3225 +       handle = ext4_journal_start(inode, 1);
3226 +       if (IS_ERR(handle))
3227 +               return PTR_ERR(handle);
3228 +
3229 +       if (IS_SYNC(inode))
3230 +               ext4_handle_sync(handle);
3231 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3232 +       if (err)
3233 +               goto flags_err;
3234 +
3235 +       inode->i_flags = flags;
3236 +       inode->i_vflags = vflags;
3237 +       ext4_get_inode_flags(EXT4_I(inode));
3238 +       inode->i_ctime = ext4_current_time(inode);
3239 +
3240 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3241 +flags_err:
3242 +       ext4_journal_stop(handle);
3243 +       return err;
3244 +}
3245 +
3246  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3247  {
3248         struct inode *inode = filp->f_dentry->d_inode;
3249 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3250  
3251                 flags = ext4_mask_flags(inode->i_mode, flags);
3252  
3253 +               if (IS_BARRIER(inode)) {
3254 +                       vxwprintk_task(1, "messing with the barrier.");
3255 +                       return -EACCES;
3256 +               }
3257 +
3258                 err = -EPERM;
3259                 mutex_lock(&inode->i_mutex);
3260                 /* Is it quota file? Do not allow user to mess with it */
3261 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3262                  *
3263                  * This test looks nicer. Thanks to Pauline Middelink
3264                  */
3265 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3266 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3267 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3268 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3269                         if (!capable(CAP_LINUX_IMMUTABLE))
3270                                 goto flags_out;
3271                 }
3272 diff -NurpP --minimal linux-3.7/fs/ext4/namei.c linux-3.7-vs2.3.5.1/fs/ext4/namei.c
3273 --- linux-3.7/fs/ext4/namei.c   2012-12-11 15:47:33.000000000 +0000
3274 +++ linux-3.7-vs2.3.5.1/fs/ext4/namei.c 2012-12-11 15:56:32.000000000 +0000
3275 @@ -34,6 +34,7 @@
3276  #include <linux/quotaops.h>
3277  #include <linux/buffer_head.h>
3278  #include <linux/bio.h>
3279 +#include <linux/vs_tag.h>
3280  #include "ext4.h"
3281  #include "ext4_jbd2.h"
3282  
3283 @@ -1232,6 +1233,7 @@ restart:
3284                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3285                                                     1, &bh);
3286                         }
3287 +               dx_propagate_tag(nd, inode);
3288                 }
3289                 if ((bh = bh_use[ra_ptr++]) == NULL)
3290                         goto next;
3291 @@ -3051,6 +3053,7 @@ const struct inode_operations ext4_dir_i
3292  #endif
3293         .get_acl        = ext4_get_acl,
3294         .fiemap         = ext4_fiemap,
3295 +       .sync_flags     = ext4_sync_flags,
3296  };
3297  
3298  const struct inode_operations ext4_special_inode_operations = {
3299 diff -NurpP --minimal linux-3.7/fs/ext4/super.c linux-3.7-vs2.3.5.1/fs/ext4/super.c
3300 --- linux-3.7/fs/ext4/super.c   2012-12-11 15:47:33.000000000 +0000
3301 +++ linux-3.7-vs2.3.5.1/fs/ext4/super.c 2012-12-11 19:16:16.000000000 +0000
3302 @@ -1222,7 +1222,7 @@ enum {
3303         Opt_inode_readahead_blks, Opt_journal_ioprio,
3304         Opt_dioread_nolock, Opt_dioread_lock,
3305         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3306 -       Opt_max_dir_size_kb,
3307 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3308  };
3309  
3310  static const match_table_t tokens = {
3311 @@ -1302,6 +1302,9 @@ static const match_table_t tokens = {
3312         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3313         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3314         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3315 +       {Opt_tag, "tag"},
3316 +       {Opt_notag, "notag"},
3317 +       {Opt_tagid, "tagid=%u"},
3318         {Opt_err, NULL},
3319  };
3320  
3321 @@ -1549,6 +1552,20 @@ static int handle_mount_opt(struct super
3322                         return -1;
3323                 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
3324                 return 1;
3325 +#ifndef CONFIG_TAGGING_NONE
3326 +       case Opt_tag:
3327 +               set_opt(sb, TAGGED);
3328 +               return 1;
3329 +       case Opt_notag:
3330 +               clear_opt(sb, TAGGED);
3331 +               return 1;
3332 +#endif
3333 +#ifdef CONFIG_PROPAGATE
3334 +       case Opt_tagid:
3335 +               /* use args[0] */
3336 +               set_opt(sb, TAGGED);
3337 +               return 1;
3338 +#endif
3339         }
3340  
3341         for (m = ext4_mount_opts; m->token != Opt_err; m++) {
3342 @@ -3455,6 +3472,9 @@ static int ext4_fill_super(struct super_
3343                 }
3344         }
3345  
3346 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3347 +               sb->s_flags |= MS_TAGGED;
3348 +
3349         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3350                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3351  
3352 @@ -4618,6 +4638,14 @@ static int ext4_remount(struct super_blo
3353         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3354                 ext4_abort(sb, "Abort forced by user");
3355  
3356 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3357 +               !(sb->s_flags & MS_TAGGED)) {
3358 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3359 +                       sb->s_id);
3360 +               err = -EINVAL;
3361 +               goto restore_opts;
3362 +       }
3363 +
3364         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3365                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3366  
3367 diff -NurpP --minimal linux-3.7/fs/fcntl.c linux-3.7-vs2.3.5.1/fs/fcntl.c
3368 --- linux-3.7/fs/fcntl.c        2012-12-11 15:47:33.000000000 +0000
3369 +++ linux-3.7-vs2.3.5.1/fs/fcntl.c      2012-12-11 15:56:32.000000000 +0000
3370 @@ -21,6 +21,7 @@
3371  #include <linux/rcupdate.h>
3372  #include <linux/pid_namespace.h>
3373  #include <linux/user_namespace.h>
3374 +#include <linux/vs_limit.h>
3375  
3376  #include <asm/poll.h>
3377  #include <asm/siginfo.h>
3378 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3379  
3380         if (!f.file)
3381                 goto out;
3382 +       if (!vx_files_avail(1))
3383 +               goto out;
3384  
3385         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3386                 if (!check_fcntl_cmd(cmd))
3387 diff -NurpP --minimal linux-3.7/fs/file.c linux-3.7-vs2.3.5.1/fs/file.c
3388 --- linux-3.7/fs/file.c 2012-12-11 15:47:33.000000000 +0000
3389 +++ linux-3.7-vs2.3.5.1/fs/file.c       2012-12-11 21:51:51.000000000 +0000
3390 @@ -22,6 +22,7 @@
3391  #include <linux/spinlock.h>
3392  #include <linux/rcupdate.h>
3393  #include <linux/workqueue.h>
3394 +#include <linux/vs_limit.h>
3395  
3396  struct fdtable_defer {
3397         spinlock_t lock;
3398 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3399                 struct file *f = *old_fds++;
3400                 if (f) {
3401                         get_file(f);
3402 +                       /* TODO: sum it first for check and performance */
3403 +                       vx_openfd_inc(open_files - i);
3404                 } else {
3405                         /*
3406                          * The fd may be claimed in the fd bitmap but not yet
3407 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3408                                         filp_close(file, files);
3409                                         cond_resched();
3410                                 }
3411 +                               vx_openfd_dec(i);
3412                         }
3413                         i++;
3414                         set >>= 1;
3415 +                       cond_resched();
3416                 }
3417         }
3418  }
3419 @@ -573,6 +578,7 @@ repeat:
3420         else
3421                 __clear_close_on_exec(fd, fdt);
3422         error = fd;
3423 +       vx_openfd_inc(fd);
3424  #if 1
3425         /* Sanity check */
3426         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3427 @@ -603,6 +609,7 @@ static void __put_unused_fd(struct files
3428         __clear_open_fd(fd, fdt);
3429         if (fd < files->next_fd)
3430                 files->next_fd = fd;
3431 +       vx_openfd_dec(fd);
3432  }
3433  
3434  void put_unused_fd(unsigned int fd)
3435 @@ -882,6 +889,8 @@ static int do_dup2(struct files_struct *
3436  
3437         if (tofree)
3438                 filp_close(tofree, files);
3439 +       else
3440 +               vx_openfd_inc(fd);      /* fd was unused */
3441  
3442         return fd;
3443  
3444 diff -NurpP --minimal linux-3.7/fs/file_table.c linux-3.7-vs2.3.5.1/fs/file_table.c
3445 --- linux-3.7/fs/file_table.c   2012-12-11 15:47:33.000000000 +0000
3446 +++ linux-3.7-vs2.3.5.1/fs/file_table.c 2012-12-11 15:56:32.000000000 +0000
3447 @@ -26,6 +26,8 @@
3448  #include <linux/hardirq.h>
3449  #include <linux/task_work.h>
3450  #include <linux/ima.h>
3451 +#include <linux/vs_limit.h>
3452 +#include <linux/vs_context.h>
3453  
3454  #include <linux/atomic.h>
3455  
3456 @@ -136,6 +138,8 @@ struct file *get_empty_filp(void)
3457         spin_lock_init(&f->f_lock);
3458         eventpoll_init_file(f);
3459         /* f->f_version: 0 */
3460 +       f->f_xid = vx_current_xid();
3461 +       vx_files_inc(f);
3462         return f;
3463  
3464  over:
3465 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3466                 i_readcount_dec(inode);
3467         if (file->f_mode & FMODE_WRITE)
3468                 drop_file_write_access(file);
3469 +       vx_files_dec(file);
3470 +       file->f_xid = 0;
3471         file->f_path.dentry = NULL;
3472         file->f_path.mnt = NULL;
3473         file_free(file);
3474 @@ -343,6 +349,8 @@ void put_filp(struct file *file)
3475  {
3476         if (atomic_long_dec_and_test(&file->f_count)) {
3477                 security_file_free(file);
3478 +               vx_files_dec(file);
3479 +               file->f_xid = 0;
3480                 file_sb_list_del(file);
3481                 file_free(file);
3482         }
3483 diff -NurpP --minimal linux-3.7/fs/fs_struct.c linux-3.7-vs2.3.5.1/fs/fs_struct.c
3484 --- linux-3.7/fs/fs_struct.c    2012-10-04 13:27:39.000000000 +0000
3485 +++ linux-3.7-vs2.3.5.1/fs/fs_struct.c  2012-12-11 15:56:32.000000000 +0000
3486 @@ -4,6 +4,7 @@
3487  #include <linux/path.h>
3488  #include <linux/slab.h>
3489  #include <linux/fs_struct.h>
3490 +#include <linux/vserver/global.h>
3491  #include "internal.h"
3492  
3493  /*
3494 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3495  {
3496         path_put(&fs->root);
3497         path_put(&fs->pwd);
3498 +       atomic_dec(&vs_global_fs);
3499         kmem_cache_free(fs_cachep, fs);
3500  }
3501  
3502 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3503                 fs->pwd = old->pwd;
3504                 path_get(&fs->pwd);
3505                 spin_unlock(&old->lock);
3506 +               atomic_inc(&vs_global_fs);
3507         }
3508         return fs;
3509  }
3510 diff -NurpP --minimal linux-3.7/fs/gfs2/file.c linux-3.7-vs2.3.5.1/fs/gfs2/file.c
3511 --- linux-3.7/fs/gfs2/file.c    2012-12-11 15:47:34.000000000 +0000
3512 +++ linux-3.7-vs2.3.5.1/fs/gfs2/file.c  2012-12-11 15:56:32.000000000 +0000
3513 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3514         [12] = GFS2_DIF_EXHASH,
3515         [14] = GFS2_DIF_INHERIT_JDATA,
3516         [17] = GFS2_DIF_TOPDIR,
3517 +       [27] = GFS2_DIF_IXUNLINK,
3518 +       [26] = GFS2_DIF_BARRIER,
3519 +       [29] = GFS2_DIF_COW,
3520  };
3521  
3522  static const u32 gfs2_to_fsflags[32] = {
3523 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3524         [gfs2fl_ExHash] = FS_INDEX_FL,
3525         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3526         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3527 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3528 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3529 +       [gfs2fl_Cow] = FS_COW_FL,
3530  };
3531  
3532  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3533 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3534  {
3535         struct gfs2_inode *ip = GFS2_I(inode);
3536         unsigned int flags = inode->i_flags;
3537 +       unsigned int vflags = inode->i_vflags;
3538 +
3539 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3540 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3541  
3542 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3543         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3544                 inode->i_flags |= S_NOSEC;
3545         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3546                 flags |= S_IMMUTABLE;
3547 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3548 +               flags |= S_IXUNLINK;
3549 +
3550         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3551                 flags |= S_APPEND;
3552         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3553 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3554         if (ip->i_diskflags & GFS2_DIF_SYNC)
3555                 flags |= S_SYNC;
3556         inode->i_flags = flags;
3557 +
3558 +       vflags &= ~(V_BARRIER | V_COW);
3559 +
3560 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3561 +               vflags |= V_BARRIER;
3562 +       if (ip->i_diskflags & GFS2_DIF_COW)
3563 +               vflags |= V_COW;
3564 +       inode->i_vflags = vflags;
3565 +}
3566 +
3567 +void gfs2_get_inode_flags(struct inode *inode)
3568 +{
3569 +       struct gfs2_inode *ip = GFS2_I(inode);
3570 +       unsigned int flags = inode->i_flags;
3571 +       unsigned int vflags = inode->i_vflags;
3572 +
3573 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3574 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3575 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3576 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3577 +
3578 +       if (flags & S_IMMUTABLE)
3579 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3580 +       if (flags & S_IXUNLINK)
3581 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3582 +
3583 +       if (flags & S_APPEND)
3584 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3585 +       if (flags & S_NOATIME)
3586 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3587 +       if (flags & S_SYNC)
3588 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3589 +
3590 +       if (vflags & V_BARRIER)
3591 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3592 +       if (vflags & V_COW)
3593 +               ip->i_diskflags |= GFS2_DIF_COW;
3594  }
3595  
3596  /* Flags that can be set by user space */
3597 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3598         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3599  }
3600  
3601 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3602 +{
3603 +       struct gfs2_inode *ip = GFS2_I(inode);
3604 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3605 +       struct buffer_head *bh;
3606 +       struct gfs2_holder gh;
3607 +       int error;
3608 +
3609 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3610 +       if (error)
3611 +               return error;
3612 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3613 +       if (error)
3614 +               goto out;
3615 +       error = gfs2_meta_inode_buffer(ip, &bh);
3616 +       if (error)
3617 +               goto out_trans_end;
3618 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3619 +       inode->i_flags = flags;
3620 +       inode->i_vflags = vflags;
3621 +       gfs2_get_inode_flags(inode);
3622 +       gfs2_dinode_out(ip, bh->b_data);
3623 +       brelse(bh);
3624 +       gfs2_set_aops(inode);
3625 +out_trans_end:
3626 +       gfs2_trans_end(sdp);
3627 +out:
3628 +       gfs2_glock_dq_uninit(&gh);
3629 +       return error;
3630 +}
3631 +
3632  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3633  {
3634         switch(cmd) {
3635 diff -NurpP --minimal linux-3.7/fs/gfs2/inode.h linux-3.7-vs2.3.5.1/fs/gfs2/inode.h
3636 --- linux-3.7/fs/gfs2/inode.h   2012-07-22 21:39:40.000000000 +0000
3637 +++ linux-3.7-vs2.3.5.1/fs/gfs2/inode.h 2012-12-11 15:56:32.000000000 +0000
3638 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3639  extern const struct file_operations gfs2_dir_fops_nolock;
3640  
3641  extern void gfs2_set_inode_flags(struct inode *inode);
3642 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3643   
3644  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3645  extern const struct file_operations gfs2_file_fops;
3646 diff -NurpP --minimal linux-3.7/fs/hostfs/hostfs.h linux-3.7-vs2.3.5.1/fs/hostfs/hostfs.h
3647 --- linux-3.7/fs/hostfs/hostfs.h        2012-12-11 15:47:34.000000000 +0000
3648 +++ linux-3.7-vs2.3.5.1/fs/hostfs/hostfs.h      2012-12-11 16:35:58.000000000 +0000
3649 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3650         unsigned short  ia_mode;
3651         uid_t           ia_uid;
3652         gid_t           ia_gid;
3653 +       tag_t           ia_tag;
3654         loff_t          ia_size;
3655         struct timespec ia_atime;
3656         struct timespec ia_mtime;
3657 diff -NurpP --minimal linux-3.7/fs/inode.c linux-3.7-vs2.3.5.1/fs/inode.c
3658 --- linux-3.7/fs/inode.c        2012-12-11 15:47:34.000000000 +0000
3659 +++ linux-3.7-vs2.3.5.1/fs/inode.c      2012-12-11 19:26:31.000000000 +0000
3660 @@ -17,6 +17,7 @@
3661  #include <linux/prefetch.h>
3662  #include <linux/buffer_head.h> /* for inode_has_buffers */
3663  #include <linux/ratelimit.h>
3664 +#include <linux/vs_tag.h>
3665  #include "internal.h"
3666  
3667  /*
3668 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3669         struct address_space *const mapping = &inode->i_data;
3670  
3671         inode->i_sb = sb;
3672 +
3673 +       /* essential because of inode slab reuse */
3674         inode->i_blkbits = sb->s_blocksize_bits;
3675         inode->i_flags = 0;
3676         atomic_set(&inode->i_count, 1);
3677 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3678         inode->i_opflags = 0;
3679         i_uid_write(inode, 0);
3680         i_gid_write(inode, 0);
3681 +       i_tag_write(inode, 0);
3682         atomic_set(&inode->i_writecount, 0);
3683         inode->i_size = 0;
3684         inode->i_blocks = 0;
3685 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3686         inode->i_bdev = NULL;
3687         inode->i_cdev = NULL;
3688         inode->i_rdev = 0;
3689 +       inode->i_mdev = 0;
3690         inode->dirtied_when = 0;
3691  
3692         if (security_inode_alloc(inode))
3693 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3694  }
3695  EXPORT_SYMBOL(__insert_inode_hash);
3696  
3697 +EXPORT_SYMBOL_GPL(__iget);
3698 +
3699  /**
3700   *     __remove_inode_hash - remove an inode from the hash
3701   *     @inode: inode to unhash
3702 @@ -1804,9 +1811,11 @@ void init_special_inode(struct inode *in
3703         if (S_ISCHR(mode)) {
3704                 inode->i_fop = &def_chr_fops;
3705                 inode->i_rdev = rdev;
3706 +               inode->i_mdev = rdev;
3707         } else if (S_ISBLK(mode)) {
3708                 inode->i_fop = &def_blk_fops;
3709                 inode->i_rdev = rdev;
3710 +               inode->i_mdev = rdev;
3711         } else if (S_ISFIFO(mode))
3712                 inode->i_fop = &def_fifo_fops;
3713         else if (S_ISSOCK(mode))
3714 @@ -1835,6 +1844,7 @@ void inode_init_owner(struct inode *inod
3715         } else
3716                 inode->i_gid = current_fsgid();
3717         inode->i_mode = mode;
3718 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3719  }
3720  EXPORT_SYMBOL(inode_init_owner);
3721  
3722 diff -NurpP --minimal linux-3.7/fs/ioctl.c linux-3.7-vs2.3.5.1/fs/ioctl.c
3723 --- linux-3.7/fs/ioctl.c        2012-12-11 15:47:34.000000000 +0000
3724 +++ linux-3.7-vs2.3.5.1/fs/ioctl.c      2012-12-11 15:56:32.000000000 +0000
3725 @@ -15,6 +15,9 @@
3726  #include <linux/writeback.h>
3727  #include <linux/buffer_head.h>
3728  #include <linux/falloc.h>
3729 +#include <linux/proc_fs.h>
3730 +#include <linux/vserver/inode.h>
3731 +#include <linux/vs_tag.h>
3732  
3733  #include <asm/ioctls.h>
3734  
3735 diff -NurpP --minimal linux-3.7/fs/ioprio.c linux-3.7-vs2.3.5.1/fs/ioprio.c
3736 --- linux-3.7/fs/ioprio.c       2012-07-22 21:39:40.000000000 +0000
3737 +++ linux-3.7-vs2.3.5.1/fs/ioprio.c     2012-12-11 15:56:32.000000000 +0000
3738 @@ -28,6 +28,7 @@
3739  #include <linux/syscalls.h>
3740  #include <linux/security.h>
3741  #include <linux/pid_namespace.h>
3742 +#include <linux/vs_base.h>
3743  
3744  int set_task_ioprio(struct task_struct *task, int ioprio)
3745  {
3746 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3747                         else
3748                                 pgrp = find_vpid(who);
3749                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3750 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3751 +                                       continue;
3752                                 ret = set_task_ioprio(p, ioprio);
3753                                 if (ret)
3754                                         break;
3755 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3756                         else
3757                                 pgrp = find_vpid(who);
3758                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3759 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3760 +                                       continue;
3761                                 tmpio = get_task_ioprio(p);
3762                                 if (tmpio < 0)
3763                                         continue;
3764 diff -NurpP --minimal linux-3.7/fs/jfs/file.c linux-3.7-vs2.3.5.1/fs/jfs/file.c
3765 --- linux-3.7/fs/jfs/file.c     2012-12-11 15:47:34.000000000 +0000
3766 +++ linux-3.7-vs2.3.5.1/fs/jfs/file.c   2012-12-11 17:20:13.000000000 +0000
3767 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3768         if (is_quota_modification(inode, iattr))
3769                 dquot_initialize(inode);
3770         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3771 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3772 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3773 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3774                 rc = dquot_transfer(inode, iattr);
3775                 if (rc)
3776                         return rc;
3777 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3778  #ifdef CONFIG_JFS_POSIX_ACL
3779         .get_acl        = jfs_get_acl,
3780  #endif
3781 +       .sync_flags     = jfs_sync_flags,
3782  };
3783  
3784  const struct file_operations jfs_file_operations = {
3785 diff -NurpP --minimal linux-3.7/fs/jfs/ioctl.c linux-3.7-vs2.3.5.1/fs/jfs/ioctl.c
3786 --- linux-3.7/fs/jfs/ioctl.c    2012-12-11 15:47:34.000000000 +0000
3787 +++ linux-3.7-vs2.3.5.1/fs/jfs/ioctl.c  2012-12-11 17:34:44.000000000 +0000
3788 @@ -12,6 +12,7 @@
3789  #include <linux/time.h>
3790  #include <linux/sched.h>
3791  #include <linux/blkdev.h>
3792 +#include <linux/mount.h>
3793  #include <asm/current.h>
3794  #include <asm/uaccess.h>
3795  
3796 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3797  }
3798  
3799  
3800 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3801 +{
3802 +       inode->i_flags = flags;
3803 +       inode->i_vflags = vflags;
3804 +       jfs_get_inode_flags(JFS_IP(inode));
3805 +       inode->i_ctime = CURRENT_TIME_SEC;
3806 +       mark_inode_dirty(inode);
3807 +       return 0;
3808 +}
3809 +
3810  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3811  {
3812         struct inode *inode = filp->f_dentry->d_inode;
3813 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3814                 if (!S_ISDIR(inode->i_mode))
3815                         flags &= ~JFS_DIRSYNC_FL;
3816  
3817 +               if (IS_BARRIER(inode)) {
3818 +                       vxwprintk_task(1, "messing with the barrier.");
3819 +                       return -EACCES;
3820 +               }
3821 +
3822                 /* Is it quota file? Do not allow user to mess with it */
3823                 if (IS_NOQUOTA(inode)) {
3824                         err = -EPERM;
3825 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3826                  * the relevant capability.
3827                  */
3828                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3829 -                       ((flags ^ oldflags) &
3830 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3831 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3832 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3833                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3834                                 mutex_unlock(&inode->i_mutex);
3835                                 err = -EPERM;
3836 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3837                         }
3838                 }
3839  
3840 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3841 +               flags &= JFS_FL_USER_MODIFIABLE;
3842                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3843                 jfs_inode->mode2 = flags;
3844  
3845 diff -NurpP --minimal linux-3.7/fs/jfs/jfs_dinode.h linux-3.7-vs2.3.5.1/fs/jfs/jfs_dinode.h
3846 --- linux-3.7/fs/jfs/jfs_dinode.h       2008-12-24 23:26:37.000000000 +0000
3847 +++ linux-3.7-vs2.3.5.1/fs/jfs/jfs_dinode.h     2012-12-11 15:56:32.000000000 +0000
3848 @@ -161,9 +161,13 @@ struct dinode {
3849  
3850  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3851  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3852 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3853  
3854 -#define JFS_FL_USER_VISIBLE    0x03F80000
3855 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3856 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3857 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3858 +
3859 +#define JFS_FL_USER_VISIBLE    0x07F80000
3860 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3861  #define JFS_FL_INHERIT         0x03C80000
3862  
3863  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3864 diff -NurpP --minimal linux-3.7/fs/jfs/jfs_filsys.h linux-3.7-vs2.3.5.1/fs/jfs/jfs_filsys.h
3865 --- linux-3.7/fs/jfs/jfs_filsys.h       2012-12-11 15:47:34.000000000 +0000
3866 +++ linux-3.7-vs2.3.5.1/fs/jfs/jfs_filsys.h     2012-12-11 15:56:32.000000000 +0000
3867 @@ -266,6 +266,7 @@
3868  #define JFS_NAME_MAX   255
3869  #define JFS_PATH_MAX   BPSIZE
3870  
3871 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3872  
3873  /*
3874   *     file system state (superblock state)
3875 diff -NurpP --minimal linux-3.7/fs/jfs/jfs_imap.c linux-3.7-vs2.3.5.1/fs/jfs/jfs_imap.c
3876 --- linux-3.7/fs/jfs/jfs_imap.c 2012-12-11 15:47:34.000000000 +0000
3877 +++ linux-3.7-vs2.3.5.1/fs/jfs/jfs_imap.c       2012-12-11 22:02:05.000000000 +0000
3878 @@ -46,6 +46,7 @@
3879  #include <linux/pagemap.h>
3880  #include <linux/quotaops.h>
3881  #include <linux/slab.h>
3882 +#include <linux/vs_tag.h>
3883  
3884  #include "jfs_incore.h"
3885  #include "jfs_inode.h"
3886 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3887  {
3888         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3889         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3890 +       kuid_t uid;
3891 +       kgid_t gid;
3892  
3893         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3894         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3895 @@ -3078,14 +3081,19 @@ static int copy_from_dinode(struct dinod
3896         }
3897         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3898  
3899 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3900 +       uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3901 +       gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3902 +       ip->i_tag = make_ktag(&init_user_ns,
3903 +               INOTAG_TAG(DX_TAG(ip), uid, gid, 0));
3904 +
3905 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3906         if (!uid_valid(sbi->uid))
3907                 ip->i_uid = jfs_ip->saved_uid;
3908         else {
3909                 ip->i_uid = sbi->uid;
3910         }
3911  
3912 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3913 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3914         if (!gid_valid(sbi->gid))
3915                 ip->i_gid = jfs_ip->saved_gid;
3916         else {
3917 @@ -3150,16 +3158,14 @@ static void copy_to_dinode(struct dinode
3918         dip->di_size = cpu_to_le64(ip->i_size);
3919         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3920         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3921 -       if (!uid_valid(sbi->uid))
3922 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3923 -       else
3924 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3925 -                                                  jfs_ip->saved_uid));
3926 -       if (!gid_valid(sbi->gid))
3927 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3928 -       else
3929 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3930 -                                                   jfs_ip->saved_gid));
3931 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3932 +               TAGINO_UID(DX_TAG(ip),
3933 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3934 +               ip->i_tag)));
3935 +       dip->di_gid = cpu_to_le32(from_kuid(&init_user_ns,
3936 +               TAGINO_GID(DX_TAG(ip),
3937 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3938 +               ip->i_tag)));
3939         jfs_get_inode_flags(jfs_ip);
3940         /*
3941          * mode2 is only needed for storing the higher order bits.
3942 diff -NurpP --minimal linux-3.7/fs/jfs/jfs_inode.c linux-3.7-vs2.3.5.1/fs/jfs/jfs_inode.c
3943 --- linux-3.7/fs/jfs/jfs_inode.c        2012-01-09 15:14:54.000000000 +0000
3944 +++ linux-3.7-vs2.3.5.1/fs/jfs/jfs_inode.c      2012-12-11 15:56:32.000000000 +0000
3945 @@ -18,6 +18,7 @@
3946  
3947  #include <linux/fs.h>
3948  #include <linux/quotaops.h>
3949 +#include <linux/vs_tag.h>
3950  #include "jfs_incore.h"
3951  #include "jfs_inode.h"
3952  #include "jfs_filsys.h"
3953 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3954  {
3955         unsigned int flags = JFS_IP(inode)->mode2;
3956  
3957 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3958 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3959 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3960 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3961  
3962         if (flags & JFS_IMMUTABLE_FL)
3963                 inode->i_flags |= S_IMMUTABLE;
3964 +       if (flags & JFS_IXUNLINK_FL)
3965 +               inode->i_flags |= S_IXUNLINK;
3966 +
3967 +       if (flags & JFS_SYNC_FL)
3968 +               inode->i_flags |= S_SYNC;
3969         if (flags & JFS_APPEND_FL)
3970                 inode->i_flags |= S_APPEND;
3971         if (flags & JFS_NOATIME_FL)
3972                 inode->i_flags |= S_NOATIME;
3973         if (flags & JFS_DIRSYNC_FL)
3974                 inode->i_flags |= S_DIRSYNC;
3975 -       if (flags & JFS_SYNC_FL)
3976 -               inode->i_flags |= S_SYNC;
3977 +
3978 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3979 +
3980 +       if (flags & JFS_BARRIER_FL)
3981 +               inode->i_vflags |= V_BARRIER;
3982 +       if (flags & JFS_COW_FL)
3983 +               inode->i_vflags |= V_COW;
3984  }
3985  
3986  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3987  {
3988         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3989 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3990 +
3991 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3992 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3993 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3994 +                          JFS_BARRIER_FL | JFS_COW_FL);
3995  
3996 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3997 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3998         if (flags & S_IMMUTABLE)
3999                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4000 +       if (flags & S_IXUNLINK)
4001 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4002 +
4003         if (flags & S_APPEND)
4004                 jfs_ip->mode2 |= JFS_APPEND_FL;
4005         if (flags & S_NOATIME)
4006 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4007                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4008         if (flags & S_SYNC)
4009                 jfs_ip->mode2 |= JFS_SYNC_FL;
4010 +
4011 +       if (vflags & V_BARRIER)
4012 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4013 +       if (vflags & V_COW)
4014 +               jfs_ip->mode2 |= JFS_COW_FL;
4015  }
4016  
4017  /*
4018 diff -NurpP --minimal linux-3.7/fs/jfs/jfs_inode.h linux-3.7-vs2.3.5.1/fs/jfs/jfs_inode.h
4019 --- linux-3.7/fs/jfs/jfs_inode.h        2011-10-24 16:45:27.000000000 +0000
4020 +++ linux-3.7-vs2.3.5.1/fs/jfs/jfs_inode.h      2012-12-11 15:56:32.000000000 +0000
4021 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4022  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4023         int fh_len, int fh_type);
4024  extern void jfs_set_inode_flags(struct inode *);
4025 +extern int jfs_sync_flags(struct inode *, int, int);
4026  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4027  extern int jfs_setattr(struct dentry *, struct iattr *);
4028  
4029 diff -NurpP --minimal linux-3.7/fs/jfs/namei.c linux-3.7-vs2.3.5.1/fs/jfs/namei.c
4030 --- linux-3.7/fs/jfs/namei.c    2012-10-04 13:27:40.000000000 +0000
4031 +++ linux-3.7-vs2.3.5.1/fs/jfs/namei.c  2012-12-11 15:56:32.000000000 +0000
4032 @@ -22,6 +22,7 @@
4033  #include <linux/ctype.h>
4034  #include <linux/quotaops.h>
4035  #include <linux/exportfs.h>
4036 +#include <linux/vs_tag.h>
4037  #include "jfs_incore.h"
4038  #include "jfs_superblock.h"
4039  #include "jfs_inode.h"
4040 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
4041                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4042         }
4043  
4044 +       dx_propagate_tag(nd, ip);
4045         return d_splice_alias(ip, dentry);
4046  }
4047  
4048 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4049  #ifdef CONFIG_JFS_POSIX_ACL
4050         .get_acl        = jfs_get_acl,
4051  #endif
4052 +       .sync_flags     = jfs_sync_flags,
4053  };
4054  
4055  const struct file_operations jfs_dir_operations = {
4056 diff -NurpP --minimal linux-3.7/fs/jfs/super.c linux-3.7-vs2.3.5.1/fs/jfs/super.c
4057 --- linux-3.7/fs/jfs/super.c    2012-12-11 15:47:34.000000000 +0000
4058 +++ linux-3.7-vs2.3.5.1/fs/jfs/super.c  2012-12-11 17:36:00.000000000 +0000
4059 @@ -199,7 +199,8 @@ enum {
4060         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4061         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4062         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4063 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
4064 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4065 +       Opt_tag, Opt_notag, Opt_tagid
4066  };
4067  
4068  static const match_table_t tokens = {
4069 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4070         {Opt_resize, "resize=%u"},
4071         {Opt_resize_nosize, "resize"},
4072         {Opt_errors, "errors=%s"},
4073 +       {Opt_tag, "tag"},
4074 +       {Opt_notag, "notag"},
4075 +       {Opt_tagid, "tagid=%u"},
4076 +       {Opt_tag, "tagxid"},
4077         {Opt_ignore, "noquota"},
4078         {Opt_ignore, "quota"},
4079         {Opt_usrquota, "usrquota"},
4080 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4081                         }
4082                         break;
4083                 }
4084 -
4085 +#ifndef CONFIG_TAGGING_NONE
4086 +               case Opt_tag:
4087 +                       *flag |= JFS_TAGGED;
4088 +                       break;
4089 +               case Opt_notag:
4090 +                       *flag &= JFS_TAGGED;
4091 +                       break;
4092 +#endif
4093 +#ifdef CONFIG_PROPAGATE
4094 +               case Opt_tagid:
4095 +                       /* use args[0] */
4096 +                       *flag |= JFS_TAGGED;
4097 +                       break;
4098 +#endif
4099                 default:
4100                         printk("jfs: Unrecognized mount option \"%s\" "
4101                                         " or missing value\n", p);
4102 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4103                 return -EINVAL;
4104         }
4105  
4106 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4107 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4108 +                       sb->s_id);
4109 +               return -EINVAL;
4110 +       }
4111 +
4112         if (newLVSize) {
4113                 if (sb->s_flags & MS_RDONLY) {
4114                         pr_err("JFS: resize requires volume" \
4115 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4116  #ifdef CONFIG_JFS_POSIX_ACL
4117         sb->s_flags |= MS_POSIXACL;
4118  #endif
4119 +       /* map mount option tagxid */
4120 +       if (sbi->flag & JFS_TAGGED)
4121 +               sb->s_flags |= MS_TAGGED;
4122  
4123         if (newLVSize) {
4124                 pr_err("resize option for remount only\n");
4125 diff -NurpP --minimal linux-3.7/fs/libfs.c linux-3.7-vs2.3.5.1/fs/libfs.c
4126 --- linux-3.7/fs/libfs.c        2012-12-11 15:47:34.000000000 +0000
4127 +++ linux-3.7-vs2.3.5.1/fs/libfs.c      2012-12-11 15:56:32.000000000 +0000
4128 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4129   * both impossible due to the lock on directory.
4130   */
4131  
4132 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4133 +static inline int do_dcache_readdir_filter(struct file *filp,
4134 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4135  {
4136         struct dentry *dentry = filp->f_path.dentry;
4137         struct dentry *cursor = filp->private_data;
4138 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4139                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4140                                 struct dentry *next;
4141                                 next = list_entry(p, struct dentry, d_u.d_child);
4142 +                               if (filter && !filter(next))
4143 +                                       continue;
4144                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4145                                 if (!simple_positive(next)) {
4146                                         spin_unlock(&next->d_lock);
4147 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4148         return 0;
4149  }
4150  
4151 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4152 +{
4153 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4154 +}
4155 +
4156 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4157 +       int (*filter)(struct dentry *))
4158 +{
4159 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4160 +}
4161 +
4162  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4163  {
4164         return -EISDIR;
4165 @@ -983,6 +997,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4166  EXPORT_SYMBOL(dcache_dir_lseek);
4167  EXPORT_SYMBOL(dcache_dir_open);
4168  EXPORT_SYMBOL(dcache_readdir);
4169 +EXPORT_SYMBOL(dcache_readdir_filter);
4170  EXPORT_SYMBOL(generic_read_dir);
4171  EXPORT_SYMBOL(mount_pseudo);
4172  EXPORT_SYMBOL(simple_write_begin);
4173 diff -NurpP --minimal linux-3.7/fs/locks.c linux-3.7-vs2.3.5.1/fs/locks.c
4174 --- linux-3.7/fs/locks.c        2012-12-11 15:47:34.000000000 +0000
4175 +++ linux-3.7-vs2.3.5.1/fs/locks.c      2012-12-11 15:56:32.000000000 +0000
4176 @@ -126,6 +126,8 @@
4177  #include <linux/time.h>
4178  #include <linux/rcupdate.h>
4179  #include <linux/pid_namespace.h>
4180 +#include <linux/vs_base.h>
4181 +#include <linux/vs_limit.h>
4182  
4183  #include <asm/uaccess.h>
4184  
4185 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4186  /* Allocate an empty lock structure. */
4187  struct file_lock *locks_alloc_lock(void)
4188  {
4189 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4190 +       struct file_lock *fl;
4191  
4192 -       if (fl)
4193 -               locks_init_lock_heads(fl);
4194 +       if (!vx_locks_avail(1))
4195 +               return NULL;
4196  
4197 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4198 +
4199 +       if (fl) {
4200 +               locks_init_lock_heads(fl);
4201 +               fl->fl_xid = -1;
4202 +       }
4203         return fl;
4204  }
4205  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4206 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4207         BUG_ON(!list_empty(&fl->fl_block));
4208         BUG_ON(!list_empty(&fl->fl_link));
4209  
4210 +       vx_locks_dec(fl);
4211         locks_release_private(fl);
4212         kmem_cache_free(filelock_cache, fl);
4213  }
4214 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4215  {
4216         memset(fl, 0, sizeof(struct file_lock));
4217         locks_init_lock_heads(fl);
4218 +       fl->fl_xid = -1;
4219  }
4220  
4221  EXPORT_SYMBOL(locks_init_lock);
4222 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4223         new->fl_file = fl->fl_file;
4224         new->fl_ops = fl->fl_ops;
4225         new->fl_lmops = fl->fl_lmops;
4226 +       new->fl_xid = fl->fl_xid;
4227  
4228         locks_copy_private(new, fl);
4229  }
4230 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4231         fl->fl_flags = FL_FLOCK;
4232         fl->fl_type = type;
4233         fl->fl_end = OFFSET_MAX;
4234 +
4235 +       vxd_assert(filp->f_xid == vx_current_xid(),
4236 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4237 +       fl->fl_xid = filp->f_xid;
4238 +       vx_locks_inc(fl);
4239         
4240         *lock = fl;
4241         return 0;
4242 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4243  
4244         fl->fl_owner = current->files;
4245         fl->fl_pid = current->tgid;
4246 +       fl->fl_xid = vx_current_xid();
4247  
4248         fl->fl_file = filp;
4249         fl->fl_flags = FL_LEASE;
4250 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4251         if (fl == NULL)
4252                 return ERR_PTR(error);
4253  
4254 +       fl->fl_xid = vx_current_xid();
4255 +       if (filp)
4256 +               vxd_assert(filp->f_xid == fl->fl_xid,
4257 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4258 +       vx_locks_inc(fl);
4259         error = lease_init(filp, type, fl);
4260         if (error) {
4261                 locks_free_lock(fl);
4262 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4263                 lock_flocks();
4264         }
4265  
4266 +       new_fl->fl_xid = -1;
4267  find_conflict:
4268         for_each_lock(inode, before) {
4269                 struct file_lock *fl = *before;
4270 @@ -773,6 +796,7 @@ find_conflict:
4271                 goto out;
4272         locks_copy_lock(new_fl, request);
4273         locks_insert_lock(before, new_fl);
4274 +       vx_locks_inc(new_fl);
4275         new_fl = NULL;
4276         error = 0;
4277  
4278 @@ -783,7 +807,8 @@ out:
4279         return error;
4280  }
4281  
4282 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4283 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4284 +       struct file_lock *conflock, xid_t xid)
4285  {
4286         struct file_lock *fl;
4287         struct file_lock *new_fl = NULL;
4288 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4289         struct file_lock **before;
4290         int error, added = 0;
4291  
4292 +       vxd_assert(xid == vx_current_xid(),
4293 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4294         /*
4295          * We may need two file_lock structures for this operation,
4296          * so we get them in advance to avoid races.
4297 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4298             (request->fl_type != F_UNLCK ||
4299              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4300                 new_fl = locks_alloc_lock();
4301 +               new_fl->fl_xid = xid;
4302 +               vx_locks_inc(new_fl);
4303                 new_fl2 = locks_alloc_lock();
4304 +               new_fl2->fl_xid = xid;
4305 +               vx_locks_inc(new_fl2);
4306         }
4307  
4308         lock_flocks();
4309 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4310  int posix_lock_file(struct file *filp, struct file_lock *fl,
4311                         struct file_lock *conflock)
4312  {
4313 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4314 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4315 +               fl, conflock, filp->f_xid);
4316  }
4317  EXPORT_SYMBOL(posix_lock_file);
4318  
4319 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4320         fl.fl_end = offset + count - 1;
4321  
4322         for (;;) {
4323 -               error = __posix_lock_file(inode, &fl, NULL);
4324 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4325                 if (error != FILE_LOCK_DEFERRED)
4326                         break;
4327                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4328 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4329                 goto out;
4330  
4331         locks_insert_lock(before, lease);
4332 +       vx_locks_inc(lease);
4333         return 0;
4334  
4335  out:
4336 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4337         if (file_lock == NULL)
4338                 return -ENOLCK;
4339  
4340 +       vxd_assert(filp->f_xid == vx_current_xid(),
4341 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4342 +       file_lock->fl_xid = filp->f_xid;
4343 +       vx_locks_inc(file_lock);
4344 +
4345         /*
4346          * This might block, so we do it before checking the inode.
4347          */
4348 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4349         if (file_lock == NULL)
4350                 return -ENOLCK;
4351  
4352 +       vxd_assert(filp->f_xid == vx_current_xid(),
4353 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4354 +       file_lock->fl_xid = filp->f_xid;
4355 +       vx_locks_inc(file_lock);
4356 +
4357         /*
4358          * This might block, so we do it before checking the inode.
4359          */
4360 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4361  
4362         lock_get_status(f, fl, *((loff_t *)f->private), "");
4363  
4364 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4365 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4366 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4367 +                       continue;
4368                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4369 +       }
4370  
4371         return 0;
4372  }
4373 diff -NurpP --minimal linux-3.7/fs/mount.h linux-3.7-vs2.3.5.1/fs/mount.h
4374 --- linux-3.7/fs/mount.h        2012-10-04 13:27:40.000000000 +0000
4375 +++ linux-3.7-vs2.3.5.1/fs/mount.h      2012-12-11 15:56:32.000000000 +0000
4376 @@ -46,6 +46,7 @@ struct mount {
4377         int mnt_expiry_mark;            /* true if marked for expiry */
4378         int mnt_pinned;
4379         int mnt_ghosts;
4380 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4381  };
4382  
4383  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4384 diff -NurpP --minimal linux-3.7/fs/namei.c linux-3.7-vs2.3.5.1/fs/namei.c
4385 --- linux-3.7/fs/namei.c        2012-12-11 15:47:35.000000000 +0000
4386 +++ linux-3.7-vs2.3.5.1/fs/namei.c      2012-12-11 21:44:51.000000000 +0000
4387 @@ -34,6 +34,14 @@
4388  #include <linux/device_cgroup.h>
4389  #include <linux/fs_struct.h>
4390  #include <linux/posix_acl.h>
4391 +#include <linux/proc_fs.h>
4392 +#include <linux/vserver/inode.h>
4393 +#include <linux/vs_base.h>
4394 +#include <linux/vs_tag.h>
4395 +#include <linux/vs_cowbl.h>
4396 +#include <linux/vs_device.h>
4397 +#include <linux/vs_context.h>
4398 +#include <linux/pid_namespace.h>
4399  #include <asm/uaccess.h>
4400  
4401  #include "internal.h"
4402 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4403         return -EAGAIN;
4404  }
4405  
4406 +static inline int dx_barrier(const struct inode *inode)
4407 +{
4408 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4409 +               vxwprintk_task(1, "did hit the barrier.");
4410 +               return 1;
4411 +       }
4412 +       return 0;
4413 +}
4414 +
4415 +static int __dx_permission(const struct inode *inode, int mask)
4416 +{
4417 +       if (dx_barrier(inode))
4418 +               return -EACCES;
4419 +
4420 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4421 +               /* devpts is xid tagged */
4422 +               if (S_ISDIR(inode->i_mode) ||
4423 +                   vx_check((xid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4424 +                       return 0;
4425 +
4426 +               /* just pretend we didn't find anything */
4427 +               return -ENOENT;
4428 +       }
4429 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4430 +               struct proc_dir_entry *de = PDE(inode);
4431 +
4432 +               if (de && !vx_hide_check(0, de->vx_flags))
4433 +                       goto out;
4434 +
4435 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4436 +                       struct pid *pid;
4437 +                       struct task_struct *tsk;
4438 +
4439 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4440 +                           vx_flags(VXF_STATE_SETUP, 0))
4441 +                               return 0;
4442 +
4443 +                       pid = PROC_I(inode)->pid;
4444 +                       if (!pid)
4445 +                               goto out;
4446 +
4447 +                       rcu_read_lock();
4448 +                       tsk = pid_task(pid, PIDTYPE_PID);
4449 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4450 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4451 +                       if (tsk &&
4452 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4453 +                               rcu_read_unlock();
4454 +                               return 0;
4455 +                       }
4456 +                       rcu_read_unlock();
4457 +               }
4458 +               else {
4459 +                       /* FIXME: Should we block some entries here? */
4460 +                       return 0;
4461 +               }
4462 +       }
4463 +       else {
4464 +               if (dx_notagcheck(inode->i_sb) ||
4465 +                   dx_check((xid_t)i_tag_read(inode),
4466 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4467 +                       return 0;
4468 +       }
4469 +
4470 +out:
4471 +       return -EACCES;
4472 +}
4473 +
4474 +int dx_permission(const struct inode *inode, int mask)
4475 +{
4476 +       int ret = __dx_permission(inode, mask);
4477 +       if (unlikely(ret)) {
4478 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4479 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4480 +#endif
4481 +                   vxwprintk_task(1,
4482 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4483 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4484 +                       inode->i_ino);
4485 +       }
4486 +       return ret;
4487 +}
4488 +
4489  /*
4490   * This does the basic permission checking
4491   */
4492 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4493                 /*
4494                  * Nobody gets write access to an immutable file.
4495                  */
4496 -               if (IS_IMMUTABLE(inode))
4497 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4498                         return -EACCES;
4499         }
4500  
4501 +       retval = dx_permission(inode, mask);
4502 +       if (retval)
4503 +               return retval;
4504 +
4505         retval = do_inode_permission(inode, mask);
4506         if (retval)
4507                 return retval;
4508 @@ -1244,7 +1339,8 @@ static void follow_dotdot(struct nameida
4509  
4510                 if (nd->path.dentry == nd->root.dentry &&
4511                     nd->path.mnt == nd->root.mnt) {
4512 -                       break;
4513 +                       /* for sane '/' avoid follow_mount() */
4514 +                       return;
4515                 }
4516                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4517                         /* rare case of legitimate dget_parent()... */
4518 @@ -1393,6 +1489,9 @@ static int lookup_fast(struct nameidata
4519                                 goto unlazy;
4520                         }
4521                 }
4522 +
4523 +               /* FIXME: check dx permission */
4524 +
4525                 path->mnt = mnt;
4526                 path->dentry = dentry;
4527                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4528 @@ -1428,6 +1527,8 @@ unlazy:
4529                 }
4530         }
4531  
4532 +       /* FIXME: check dx permission */
4533 +
4534         path->mnt = mnt;
4535         path->dentry = dentry;
4536         err = follow_managed(path, nd->flags);
4537 @@ -2258,7 +2359,7 @@ static int may_delete(struct inode *dir,
4538         if (IS_APPEND(dir))
4539                 return -EPERM;
4540         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4541 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4542 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4543                 return -EPERM;
4544         if (isdir) {
4545                 if (!S_ISDIR(victim->d_inode->i_mode))
4546 @@ -2337,19 +2438,25 @@ int vfs_create(struct inode *dir, struct
4547                 bool want_excl)
4548  {
4549         int error = may_create(dir, dentry);
4550 -       if (error)
4551 +       if (error) {
4552 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4553                 return error;
4554 +       }
4555  
4556         if (!dir->i_op->create)
4557                 return -EACCES; /* shouldn't it be ENOSYS? */
4558         mode &= S_IALLUGO;
4559         mode |= S_IFREG;
4560         error = security_inode_create(dir, dentry, mode);
4561 -       if (error)
4562 +       if (error) {
4563 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4564                 return error;
4565 +       }
4566         error = dir->i_op->create(dir, dentry, mode, want_excl);
4567         if (!error)
4568                 fsnotify_create(dir, dentry);
4569 +       else
4570 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4571         return error;
4572  }
4573  
4574 @@ -2384,6 +2491,15 @@ static int may_open(struct path *path, i
4575                 break;
4576         }
4577  
4578 +#ifdef CONFIG_VSERVER_COWBL
4579 +       if (IS_COW(inode) &&
4580 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4581 +               if (IS_COW_LINK(inode))
4582 +                       return -EMLINK;
4583 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4584 +               mark_inode_dirty(inode);
4585 +       }
4586 +#endif
4587         error = inode_permission(inode, acc_mode);
4588         if (error)
4589                 return error;
4590 @@ -2886,6 +3002,16 @@ finish_open:
4591         }
4592  finish_open_created:
4593         error = may_open(&nd->path, acc_mode, open_flag);
4594 +#ifdef CONFIG_VSERVER_COWBL
4595 +       if (error == -EMLINK) {
4596 +               struct dentry *dentry;
4597 +               dentry = cow_break_link(name->name);
4598 +               if (IS_ERR(dentry))
4599 +                       error = PTR_ERR(dentry);
4600 +               else
4601 +                       dput(dentry);
4602 +       }
4603 +#endif
4604         if (error)
4605                 goto out;
4606         file->f_path.mnt = nd->path.mnt;
4607 @@ -2950,6 +3076,7 @@ static struct file *path_openat(int dfd,
4608         int opened = 0;
4609         int error;
4610  
4611 +restart:
4612         file = get_empty_filp();
4613         if (!file)
4614                 return ERR_PTR(-ENFILE);
4615 @@ -2986,6 +3113,16 @@ static struct file *path_openat(int dfd,
4616                 error = do_last(nd, &path, file, op, &opened, pathname);
4617                 put_link(nd, &link, cookie);
4618         }
4619 +
4620 +#ifdef CONFIG_VSERVER_COWBL
4621 +       if (error == -EMLINK) {
4622 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4623 +                       path_put(&nd->root);
4624 +               if (base)
4625 +                       fput(base);
4626 +               goto restart;
4627 +       }
4628 +#endif
4629  out:
4630         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4631                 path_put(&nd->root);
4632 @@ -3090,6 +3227,11 @@ struct dentry *kern_path_create(int dfd,
4633                 goto fail;
4634         }
4635         *path = nd.path;
4636 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4637 +               path->dentry, path->dentry->d_name.len,
4638 +               path->dentry->d_name.name, dentry,
4639 +               dentry->d_name.len, dentry->d_name.name,
4640 +               path->dentry->d_inode);
4641         return dentry;
4642  fail:
4643         dput(dentry);
4644 @@ -3556,7 +3698,7 @@ int vfs_link(struct dentry *old_dentry,
4645         /*
4646          * A link to an append-only or immutable file cannot be created.
4647          */
4648 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4649 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4650                 return -EPERM;
4651         if (!dir->i_op->link)
4652                 return -EPERM;
4653 @@ -3945,6 +4087,275 @@ int vfs_follow_link(struct nameidata *nd
4654         return __vfs_follow_link(nd, link);
4655  }
4656  
4657 +
4658 +#ifdef CONFIG_VSERVER_COWBL
4659 +
4660 +static inline
4661 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4662 +{
4663 +       loff_t ppos = 0;
4664 +
4665 +       return do_splice_direct(in, &ppos, out, len, 0);
4666 +}
4667 +
4668 +struct dentry *cow_break_link(const char *pathname)
4669 +{
4670 +       int ret, mode, pathlen, redo = 0;
4671 +       struct nameidata old_nd, dir_nd;
4672 +       struct path dir_path, *old_path, *new_path;
4673 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4674 +       struct file *old_file;
4675 +       struct file *new_file;
4676 +       char *to, *path, pad='\251';
4677 +       loff_t size;
4678 +
4679 +       vxdprintk(VXD_CBIT(misc, 1),
4680 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4681 +
4682 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4683 +       ret = -ENOMEM;
4684 +       if (!path)
4685 +               goto out;
4686 +
4687 +       /* old_nd.path will have refs to dentry and mnt */
4688 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4689 +       vxdprintk(VXD_CBIT(misc, 2),
4690 +               "do_path_lookup(old): %d", ret);
4691 +       if (ret < 0)
4692 +               goto out_free_path;
4693 +
4694 +       /* dentry/mnt refs handed over to old_path */
4695 +       old_path = &old_nd.path;
4696 +       /* no explicit reference for old_dentry here */
4697 +       old_dentry = old_path->dentry;
4698 +
4699 +       mode = old_dentry->d_inode->i_mode;
4700 +       to = d_path(old_path, path, PATH_MAX-2);
4701 +       pathlen = strlen(to);
4702 +       vxdprintk(VXD_CBIT(misc, 2),
4703 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4704 +               old_dentry,
4705 +               old_dentry->d_name.len, old_dentry->d_name.name,
4706 +               old_dentry->d_name.len);
4707 +
4708 +       to[pathlen + 1] = 0;
4709 +retry:
4710 +       new_dentry = NULL;
4711 +       to[pathlen] = pad--;
4712 +       ret = -ELOOP;
4713 +       if (pad <= '\240')
4714 +               goto out_rel_old;
4715 +
4716 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4717 +
4718 +       /* dir_nd.path will have refs to dentry and mnt */
4719 +       ret = do_path_lookup(AT_FDCWD, to,
4720 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4721 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4722 +       if (ret < 0)
4723 +               goto retry;
4724 +
4725 +       /* this puppy downs the dir inode mutex if successful.
4726 +          dir_path will hold refs to dentry and mnt and
4727 +          we'll have get write access to the mnt */
4728 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4729 +       if (!new_dentry || IS_ERR(new_dentry)) {
4730 +               path_put(&dir_nd.path);
4731 +               vxdprintk(VXD_CBIT(misc, 2),
4732 +                       "kern_path_create(new) failed with %ld",
4733 +                       PTR_ERR(new_dentry));
4734 +               goto retry;
4735 +       }
4736 +       vxdprintk(VXD_CBIT(misc, 2),
4737 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4738 +               new_dentry,
4739 +               new_dentry->d_name.len, new_dentry->d_name.name,
4740 +               new_dentry->d_name.len);
4741 +
4742 +       /* take a reference on new_dentry */
4743 +       dget(new_dentry);
4744 +
4745 +       /* dentry/mnt refs handed over to new_path */
4746 +       new_path = &dir_path;
4747 +
4748 +       /* dentry for old/new dir */
4749 +       dir = dir_nd.path.dentry;
4750 +
4751 +       /* give up reference on dir */
4752 +       dput(new_path->dentry);
4753 +
4754 +       /* new_dentry already has a reference */
4755 +       new_path->dentry = new_dentry;
4756 +
4757 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4758 +       vxdprintk(VXD_CBIT(misc, 2),
4759 +               "vfs_create(new): %d", ret);
4760 +       if (ret == -EEXIST) {
4761 +               mutex_unlock(&dir->d_inode->i_mutex);
4762 +               path_put(&dir_nd.path);
4763 +               mnt_drop_write(new_path->mnt);
4764 +               path_put(new_path);
4765 +               new_dentry = NULL;
4766 +               goto retry;
4767 +       }
4768 +       else if (ret < 0)
4769 +               goto out_unlock_new;
4770 +
4771 +       /* drop out early, ret passes ENOENT */
4772 +       ret = -ENOENT;
4773 +       if ((redo = d_unhashed(old_dentry)))
4774 +               goto out_unlock_new;
4775 +
4776 +       /* doesn't change refs for old_path */
4777 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4778 +       vxdprintk(VXD_CBIT(misc, 2),
4779 +               "dentry_open(old): %p", old_file);
4780 +       if (IS_ERR(old_file)) {
4781 +               ret = PTR_ERR(old_file);
4782 +               goto out_unlock_new;
4783 +       }
4784 +
4785 +       /* doesn't change refs for new_path */
4786 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4787 +       vxdprintk(VXD_CBIT(misc, 2),
4788 +               "dentry_open(new): %p", new_file);
4789 +       if (IS_ERR(new_file)) {
4790 +               ret = PTR_ERR(new_file);
4791 +               goto out_fput_old;
4792 +       }
4793 +
4794 +       size = i_size_read(old_file->f_dentry->d_inode);
4795 +       ret = do_cow_splice(old_file, new_file, size);
4796 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4797 +       if (ret < 0) {
4798 +               goto out_fput_both;
4799 +       } else if (ret < size) {
4800 +               ret = -ENOSPC;
4801 +               goto out_fput_both;
4802 +       } else {
4803 +               struct inode *old_inode = old_dentry->d_inode;
4804 +               struct inode *new_inode = new_dentry->d_inode;
4805 +               struct iattr attr = {
4806 +                       .ia_uid = old_inode->i_uid,
4807 +                       .ia_gid = old_inode->i_gid,
4808 +                       .ia_valid = ATTR_UID | ATTR_GID
4809 +                       };
4810 +
4811 +               setattr_copy(new_inode, &attr);
4812 +               mark_inode_dirty(new_inode);
4813 +       }
4814 +
4815 +       /* lock rename mutex */
4816 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4817 +
4818 +       /* drop out late */
4819 +       ret = -ENOENT;
4820 +       if ((redo = d_unhashed(old_dentry)))
4821 +               goto out_unlock;
4822 +
4823 +       vxdprintk(VXD_CBIT(misc, 2),
4824 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4825 +               new_dentry->d_name.len, new_dentry->d_name.name,
4826 +               new_dentry->d_name.len,
4827 +               old_dentry->d_name.len, old_dentry->d_name.name,
4828 +               old_dentry->d_name.len);
4829 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4830 +               old_dentry->d_parent->d_inode, old_dentry);
4831 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4832 +
4833 +out_unlock:
4834 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4835 +
4836 +out_fput_both:
4837 +       vxdprintk(VXD_CBIT(misc, 3),
4838 +               "fput(new_file=%p[#%ld])", new_file,
4839 +               atomic_long_read(&new_file->f_count));
4840 +       fput(new_file);
4841 +
4842 +out_fput_old:
4843 +       vxdprintk(VXD_CBIT(misc, 3),
4844 +               "fput(old_file=%p[#%ld])", old_file,
4845 +               atomic_long_read(&old_file->f_count));
4846 +       fput(old_file);
4847 +
4848 +out_unlock_new:
4849 +       /* drop references from dir_nd.path */
4850 +       path_put(&dir_nd.path);
4851 +
4852 +       /* drop write access to mnt */
4853 +       mnt_drop_write(new_path->mnt);
4854 +
4855 +       /* unlock the inode mutex from kern_path_create() */
4856 +       mutex_unlock(&dir->d_inode->i_mutex);
4857 +       if (!ret)
4858 +               goto out_redo;
4859 +
4860 +       /* error path cleanup */
4861 +       vfs_unlink(dir->d_inode, new_dentry);
4862 +
4863 +out_redo:
4864 +       if (!redo)
4865 +               goto out_rel_both;
4866 +
4867 +       /* lookup dentry once again
4868 +          old_nd.path will be freed as old_path in out_rel_old */
4869 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4870 +       if (ret)
4871 +               goto out_rel_both;
4872 +
4873 +       /* drop reference on new_dentry */
4874 +       dput(new_dentry);
4875 +       new_dentry = old_path->dentry;
4876 +       dget(new_dentry);
4877 +       vxdprintk(VXD_CBIT(misc, 2),
4878 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4879 +               new_dentry,
4880 +               new_dentry->d_name.len, new_dentry->d_name.name,
4881 +               new_dentry->d_name.len);
4882 +
4883 +out_rel_both:
4884 +       if (new_path)
4885 +               path_put(new_path);
4886 +out_rel_old:
4887 +       path_put(old_path);
4888 +out_free_path:
4889 +       kfree(path);
4890 +out:
4891 +       if (ret) {
4892 +               dput(new_dentry);
4893 +               new_dentry = ERR_PTR(ret);
4894 +       }
4895 +       vxdprintk(VXD_CBIT(misc, 3),
4896 +               "cow_break_link returning with %p", new_dentry);
4897 +       return new_dentry;
4898 +}
4899 +
4900 +#endif
4901 +
4902 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4903 +{
4904 +       struct path path;
4905 +       struct vfsmount *vmnt;
4906 +       char *pstr, *root;
4907 +       int length = 0;
4908 +
4909 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4910 +       if (!pstr)
4911 +               return 0;
4912 +
4913 +       vmnt = &ns->root->mnt;
4914 +       path.mnt = vmnt;
4915 +       path.dentry = vmnt->mnt_root;
4916 +       root = d_path(&path, pstr, PATH_MAX - 2);
4917 +       length = sprintf(buffer + length,
4918 +               "Namespace:\t%p [#%u]\n"
4919 +               "RootPath:\t%s\n",
4920 +               ns, atomic_read(&ns->count),
4921 +               root);
4922 +       kfree(pstr);
4923 +       return length;
4924 +}
4925 +
4926  /* get the link contents into pagecache */
4927  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4928  {
4929 @@ -4068,3 +4479,4 @@ EXPORT_SYMBOL(vfs_symlink);
4930  EXPORT_SYMBOL(vfs_unlink);
4931  EXPORT_SYMBOL(dentry_unhash);
4932  EXPORT_SYMBOL(generic_readlink);
4933 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4934 diff -NurpP --minimal linux-3.7/fs/namespace.c linux-3.7-vs2.3.5.1/fs/namespace.c
4935 --- linux-3.7/fs/namespace.c    2012-12-11 15:47:35.000000000 +0000
4936 +++ linux-3.7-vs2.3.5.1/fs/namespace.c  2012-12-11 17:17:30.000000000 +0000
4937 @@ -20,6 +20,11 @@
4938  #include <linux/fs_struct.h>   /* get_fs_root et.al. */
4939  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4940  #include <linux/uaccess.h>
4941 +#include <linux/vs_base.h>
4942 +#include <linux/vs_context.h>
4943 +#include <linux/vs_tag.h>
4944 +#include <linux/vserver/space.h>
4945 +#include <linux/vserver/global.h>
4946  #include "pnode.h"
4947  #include "internal.h"
4948  
4949 @@ -749,6 +754,10 @@ vfs_kern_mount(struct file_system_type *
4950         if (!type)
4951                 return ERR_PTR(-ENODEV);
4952  
4953 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4954 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4955 +               return ERR_PTR(-EPERM);
4956 +
4957         mnt = alloc_vfsmnt(name);
4958         if (!mnt)
4959                 return ERR_PTR(-ENOMEM);
4960 @@ -801,6 +810,7 @@ static struct mount *clone_mnt(struct mo
4961         mnt->mnt.mnt_root = dget(root);
4962         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4963         mnt->mnt_parent = mnt;
4964 +               mnt->mnt_tag = old->mnt_tag;
4965         br_write_lock(&vfsmount_lock);
4966         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4967         br_write_unlock(&vfsmount_lock);
4968 @@ -1266,7 +1276,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
4969                 goto dput_and_out;
4970  
4971         retval = -EPERM;
4972 -       if (!capable(CAP_SYS_ADMIN))
4973 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4974                 goto dput_and_out;
4975  
4976         retval = do_umount(mnt, flags);
4977 @@ -1292,7 +1302,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
4978  
4979  static int mount_is_safe(struct path *path)
4980  {
4981 -       if (capable(CAP_SYS_ADMIN))
4982 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4983                 return 0;
4984         return -EPERM;
4985  #ifdef notyet
4986 @@ -1610,7 +1620,7 @@ static int do_change_type(struct path *p
4987         int type;
4988         int err = 0;
4989  
4990 -       if (!capable(CAP_SYS_ADMIN))
4991 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
4992                 return -EPERM;
4993  
4994         if (path->dentry != path->mnt->mnt_root)
4995 @@ -1626,6 +1636,7 @@ static int do_change_type(struct path *p
4996                 if (err)
4997                         goto out_unlock;
4998         }
4999 +       // mnt->mnt_flags = mnt_flags;
5000  
5001         br_write_lock(&vfsmount_lock);
5002         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5003 @@ -1641,12 +1652,14 @@ static int do_change_type(struct path *p
5004   * do loopback mount.
5005   */
5006  static int do_loopback(struct path *path, const char *old_name,
5007 -                               int recurse)
5008 +       tag_t tag, unsigned long flags, int mnt_flags)
5009  {
5010         LIST_HEAD(umount_list);
5011         struct path old_path;
5012         struct mount *mnt = NULL, *old;
5013         int err = mount_is_safe(path);
5014 +       int recurse = flags & MS_REC;
5015 +
5016         if (err)
5017                 return err;
5018         if (!old_name || !*old_name)
5019 @@ -1715,13 +1728,13 @@ static int change_mount_flags(struct vfs
5020   * on it - tough luck.
5021   */
5022  static int do_remount(struct path *path, int flags, int mnt_flags,
5023 -                     void *data)
5024 +       void *data, xid_t xid)
5025  {
5026         int err;
5027         struct super_block *sb = path->mnt->mnt_sb;
5028         struct mount *mnt = real_mount(path->mnt);
5029  
5030 -       if (!capable(CAP_SYS_ADMIN))
5031 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5032                 return -EPERM;
5033  
5034         if (!check_mnt(mnt))
5035 @@ -1770,7 +1783,7 @@ static int do_move_mount(struct path *pa
5036         struct mount *p;
5037         struct mount *old;
5038         int err = 0;
5039 -       if (!capable(CAP_SYS_ADMIN))
5040 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5041                 return -EPERM;
5042         if (!old_name || !*old_name)
5043                 return -EINVAL;
5044 @@ -1927,7 +1940,7 @@ static int do_new_mount(struct path *pat
5045                 return -EINVAL;
5046  
5047         /* we need capabilities... */
5048 -       if (!capable(CAP_SYS_ADMIN))
5049 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5050                 return -EPERM;
5051  
5052         mnt = do_kern_mount(type, flags, name, data);
5053 @@ -2197,6 +2210,7 @@ long do_mount(const char *dev_name, cons
5054         struct path path;
5055         int retval = 0;
5056         int mnt_flags = 0;
5057 +       tag_t tag = 0;
5058  
5059         /* Discard magic */
5060         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5061 @@ -2224,6 +2238,12 @@ long do_mount(const char *dev_name, cons
5062         if (!(flags & MS_NOATIME))
5063                 mnt_flags |= MNT_RELATIME;
5064  
5065 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5066 +               /* FIXME: bind and re-mounts get the tag flag? */
5067 +               if (flags & (MS_BIND|MS_REMOUNT))
5068 +                       flags |= MS_TAGID;
5069 +       }
5070 +
5071         /* Separate the per-mountpoint flags */
5072         if (flags & MS_NOSUID)
5073                 mnt_flags |= MNT_NOSUID;
5074 @@ -2240,15 +2260,17 @@ long do_mount(const char *dev_name, cons
5075         if (flags & MS_RDONLY)
5076                 mnt_flags |= MNT_READONLY;
5077  
5078 +       if (!capable(CAP_SYS_ADMIN))
5079 +               mnt_flags |= MNT_NODEV;
5080         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5081                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5082                    MS_STRICTATIME);
5083  
5084         if (flags & MS_REMOUNT)
5085                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5086 -                                   data_page);
5087 +                                   data_page, tag);
5088         else if (flags & MS_BIND)
5089 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5090 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5091         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5092                 retval = do_change_type(&path, flags);
5093         else if (flags & MS_MOVE)
5094 @@ -2329,6 +2351,7 @@ static struct mnt_namespace *dup_mnt_ns(
5095                 q = next_mnt(q, new);
5096         }
5097         up_write(&namespace_sem);
5098 +       atomic_inc(&vs_global_mnt_ns);
5099  
5100         if (rootmnt)
5101                 mntput(rootmnt);
5102 @@ -2524,9 +2547,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5103         error = -EINVAL;
5104         new_mnt = real_mount(new.mnt);
5105         root_mnt = real_mount(root.mnt);
5106 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5107 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5108                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5109 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5110 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5111 +               !vx_flags(VXF_STATE_SETUP, 0))
5112                 goto out4;
5113         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5114                 goto out4;
5115 @@ -2647,6 +2671,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5116         br_write_unlock(&vfsmount_lock);
5117         up_write(&namespace_sem);
5118         release_mounts(&umount_list);
5119 +       atomic_dec(&vs_global_mnt_ns);
5120         kfree(ns);
5121  }
5122  
5123 diff -NurpP --minimal linux-3.7/fs/nfs/client.c linux-3.7-vs2.3.5.1/fs/nfs/client.c
5124 --- linux-3.7/fs/nfs/client.c   2012-12-11 15:47:35.000000000 +0000
5125 +++ linux-3.7-vs2.3.5.1/fs/nfs/client.c 2012-12-11 15:56:32.000000000 +0000
5126 @@ -684,6 +684,9 @@ int nfs_init_server_rpcclient(struct nfs
5127         if (server->flags & NFS_MOUNT_SOFT)
5128                 server->client->cl_softrtry = 1;
5129  
5130 +       server->client->cl_tag = 0;
5131 +       if (server->flags & NFS_MOUNT_TAGGED)
5132 +               server->client->cl_tag = 1;
5133         return 0;
5134  }
5135  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5136 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
5137                 server->acdirmin = server->acdirmax = 0;
5138         }
5139  
5140 +       /* FIXME: needs fsinfo
5141 +       if (server->flags & NFS_MOUNT_TAGGED)
5142 +               sb->s_flags |= MS_TAGGED;       */
5143 +
5144         server->maxfilesize = fsinfo->maxfilesize;
5145  
5146         server->time_delta = fsinfo->time_delta;
5147 diff -NurpP --minimal linux-3.7/fs/nfs/dir.c linux-3.7-vs2.3.5.1/fs/nfs/dir.c
5148 --- linux-3.7/fs/nfs/dir.c      2012-12-11 15:47:35.000000000 +0000
5149 +++ linux-3.7-vs2.3.5.1/fs/nfs/dir.c    2012-12-11 15:56:32.000000000 +0000
5150 @@ -36,6 +36,7 @@
5151  #include <linux/sched.h>
5152  #include <linux/kmemleak.h>
5153  #include <linux/xattr.h>
5154 +#include <linux/vs_tag.h>
5155  
5156  #include "delegation.h"
5157  #include "iostat.h"
5158 @@ -1252,6 +1253,7 @@ struct dentry *nfs_lookup(struct inode *
5159         /* Success: notify readdir to use READDIRPLUS */
5160         nfs_advise_use_readdirplus(dir);
5161  
5162 +       dx_propagate_tag(nd, inode);
5163  no_entry:
5164         res = d_materialise_unique(dentry, inode);
5165         if (res != NULL) {
5166 diff -NurpP --minimal linux-3.7/fs/nfs/inode.c linux-3.7-vs2.3.5.1/fs/nfs/inode.c
5167 --- linux-3.7/fs/nfs/inode.c    2012-12-11 15:47:35.000000000 +0000
5168 +++ linux-3.7-vs2.3.5.1/fs/nfs/inode.c  2012-12-11 15:56:32.000000000 +0000
5169 @@ -39,6 +39,7 @@
5170  #include <linux/compat.h>
5171  #include <linux/freezer.h>
5172  #include <linux/crc32.h>
5173 +#include <linux/vs_tag.h>
5174  
5175  #include <asm/uaccess.h>
5176  
5177 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5178         if (inode->i_state & I_NEW) {
5179                 struct nfs_inode *nfsi = NFS_I(inode);
5180                 unsigned long now = jiffies;
5181 +               uid_t uid;
5182 +               gid_t gid;
5183  
5184                 /* We set i_ino for the few things that still rely on it,
5185                  * such as stat(2) */
5186 @@ -323,8 +326,8 @@ nfs_fhget(struct super_block *sb, struct
5187                 inode->i_version = 0;
5188                 inode->i_size = 0;
5189                 clear_nlink(inode);
5190 -               inode->i_uid = -2;
5191 -               inode->i_gid = -2;
5192 +               uid = -2;
5193 +               gid = -2;
5194                 inode->i_blocks = 0;
5195                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5196                 nfsi->write_io = 0;
5197 @@ -358,11 +361,11 @@ nfs_fhget(struct super_block *sb, struct
5198                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5199                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5200                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5201 -                       inode->i_uid = fattr->uid;
5202 +                       uid = fattr->uid;
5203                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5204                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5205                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5206 -                       inode->i_gid = fattr->gid;
5207 +                       gid = fattr->gid;
5208                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5209                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5210                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5211 @@ -373,6 +376,11 @@ nfs_fhget(struct super_block *sb, struct
5212                          */
5213                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5214                 }
5215 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5216 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5217 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5218 +                               /* maybe fattr->xid someday */
5219 +
5220                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5221                 nfsi->attrtimeo_timestamp = now;
5222                 nfsi->access_cache = RB_ROOT;
5223 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5224                         inode->i_uid = attr->ia_uid;
5225                 if ((attr->ia_valid & ATTR_GID) != 0)
5226                         inode->i_gid = attr->ia_gid;
5227 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5228 +                       inode->i_tag = attr->ia_tag;
5229                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5230                 spin_unlock(&inode->i_lock);
5231         }
5232 @@ -968,6 +978,9 @@ static int nfs_check_inode_attributes(st
5233         struct nfs_inode *nfsi = NFS_I(inode);
5234         loff_t cur_size, new_isize;
5235         unsigned long invalid = 0;
5236 +       uid_t uid;
5237 +       gid_t gid;
5238 +       tag_t tag;
5239  
5240  
5241         if (nfs_have_delegated_attributes(inode))
5242 @@ -993,13 +1006,18 @@ static int nfs_check_inode_attributes(st
5243                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5244         }
5245  
5246 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5247 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5248 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5249 +
5250         /* Have any file permissions changed? */
5251         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5252                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5253 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5254 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5255                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5256 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5257 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5258                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5259 +               /* maybe check for tag too? */
5260  
5261         /* Has the link count changed? */
5262         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5263 @@ -1303,6 +1321,9 @@ static int nfs_update_inode(struct inode
5264         unsigned long invalid = 0;
5265         unsigned long now = jiffies;
5266         unsigned long save_cache_validity;
5267 +       uid_t uid;
5268 +       gid_t gid;
5269 +       tag_t tag;
5270  
5271         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5272                         __func__, inode->i_sb->s_id, inode->i_ino,
5273 @@ -1404,6 +1425,9 @@ static int nfs_update_inode(struct inode
5274                                 | NFS_INO_REVAL_PAGECACHE
5275                                 | NFS_INO_REVAL_FORCED);
5276  
5277 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5278 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5279 +       tag = inode->i_tag;
5280  
5281         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5282                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5283 @@ -1425,9 +1449,9 @@ static int nfs_update_inode(struct inode
5284                                 | NFS_INO_REVAL_FORCED);
5285  
5286         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5287 -               if (inode->i_uid != fattr->uid) {
5288 +               if (uid != fattr->uid) {
5289                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5290 -                       inode->i_uid = fattr->uid;
5291 +                       uid = fattr->uid;
5292                 }
5293         } else if (server->caps & NFS_CAP_OWNER)
5294                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5295 @@ -1436,9 +1460,9 @@ static int nfs_update_inode(struct inode
5296                                 | NFS_INO_REVAL_FORCED);
5297  
5298         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5299 -               if (inode->i_gid != fattr->gid) {
5300 +               if (gid != fattr->gid) {
5301                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5302 -                       inode->i_gid = fattr->gid;
5303 +                       gid = fattr->gid;
5304                 }
5305         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5306                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5307 @@ -1446,6 +1470,10 @@ static int nfs_update_inode(struct inode
5308                                 | NFS_INO_INVALID_ACL
5309                                 | NFS_INO_REVAL_FORCED);
5310  
5311 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5312 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5313 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5314 +
5315         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5316                 if (inode->i_nlink != fattr->nlink) {
5317                         invalid |= NFS_INO_INVALID_ATTR;
5318 diff -NurpP --minimal linux-3.7/fs/nfs/nfs3xdr.c linux-3.7-vs2.3.5.1/fs/nfs/nfs3xdr.c
5319 --- linux-3.7/fs/nfs/nfs3xdr.c  2012-10-04 13:27:40.000000000 +0000
5320 +++ linux-3.7-vs2.3.5.1/fs/nfs/nfs3xdr.c        2012-12-11 15:56:32.000000000 +0000
5321 @@ -20,6 +20,7 @@
5322  #include <linux/nfs3.h>
5323  #include <linux/nfs_fs.h>
5324  #include <linux/nfsacl.h>
5325 +#include <linux/vs_tag.h>
5326  #include "internal.h"
5327  
5328  #define NFSDBG_FACILITY                NFSDBG_XDR
5329 @@ -560,7 +561,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5330   *             set_mtime       mtime;
5331   *     };
5332   */
5333 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5334 +static void encode_sattr3(struct xdr_stream *xdr,
5335 +       const struct iattr *attr, int tag)
5336  {
5337         u32 nbytes;
5338         __be32 *p;
5339 @@ -592,15 +594,19 @@ static void encode_sattr3(struct xdr_str
5340         } else
5341                 *p++ = xdr_zero;
5342  
5343 -       if (attr->ia_valid & ATTR_UID) {
5344 +       if (attr->ia_valid & ATTR_UID ||
5345 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5346                 *p++ = xdr_one;
5347 -               *p++ = cpu_to_be32(attr->ia_uid);
5348 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5349 +                       attr->ia_uid, attr->ia_tag));
5350         } else
5351                 *p++ = xdr_zero;
5352  
5353 -       if (attr->ia_valid & ATTR_GID) {
5354 +       if (attr->ia_valid & ATTR_GID ||
5355 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5356                 *p++ = xdr_one;
5357 -               *p++ = cpu_to_be32(attr->ia_gid);
5358 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5359 +                       attr->ia_gid, attr->ia_tag));
5360         } else
5361                 *p++ = xdr_zero;
5362  
5363 @@ -879,7 +885,7 @@ static void nfs3_xdr_enc_setattr3args(st
5364                                       const struct nfs3_sattrargs *args)
5365  {
5366         encode_nfs_fh3(xdr, args->fh);
5367 -       encode_sattr3(xdr, args->sattr);
5368 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5369         encode_sattrguard3(xdr, args);
5370  }
5371  
5372 @@ -1029,13 +1035,13 @@ static void nfs3_xdr_enc_write3args(stru
5373   *     };
5374   */
5375  static void encode_createhow3(struct xdr_stream *xdr,
5376 -                             const struct nfs3_createargs *args)
5377 +       const struct nfs3_createargs *args, int tag)
5378  {
5379         encode_uint32(xdr, args->createmode);
5380         switch (args->createmode) {
5381         case NFS3_CREATE_UNCHECKED:
5382         case NFS3_CREATE_GUARDED:
5383 -               encode_sattr3(xdr, args->sattr);
5384 +               encode_sattr3(xdr, args->sattr, tag);
5385                 break;
5386         case NFS3_CREATE_EXCLUSIVE:
5387                 encode_createverf3(xdr, args->verifier);
5388 @@ -1050,7 +1056,7 @@ static void nfs3_xdr_enc_create3args(str
5389                                      const struct nfs3_createargs *args)
5390  {
5391         encode_diropargs3(xdr, args->fh, args->name, args->len);
5392 -       encode_createhow3(xdr, args);
5393 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5394  }
5395  
5396  /*
5397 @@ -1066,7 +1072,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5398                                     const struct nfs3_mkdirargs *args)
5399  {
5400         encode_diropargs3(xdr, args->fh, args->name, args->len);
5401 -       encode_sattr3(xdr, args->sattr);
5402 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5403  }
5404  
5405  /*
5406 @@ -1083,9 +1089,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5407   *     };
5408   */
5409  static void encode_symlinkdata3(struct xdr_stream *xdr,
5410 -                               const struct nfs3_symlinkargs *args)
5411 +       const struct nfs3_symlinkargs *args, int tag)
5412  {
5413 -       encode_sattr3(xdr, args->sattr);
5414 +       encode_sattr3(xdr, args->sattr, tag);
5415         encode_nfspath3(xdr, args->pages, args->pathlen);
5416  }
5417  
5418 @@ -1094,7 +1100,7 @@ static void nfs3_xdr_enc_symlink3args(st
5419                                       const struct nfs3_symlinkargs *args)
5420  {
5421         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5422 -       encode_symlinkdata3(xdr, args);
5423 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5424  }
5425  
5426  /*
5427 @@ -1122,24 +1128,24 @@ static void nfs3_xdr_enc_symlink3args(st
5428   *     };
5429   */
5430  static void encode_devicedata3(struct xdr_stream *xdr,
5431 -                              const struct nfs3_mknodargs *args)
5432 +       const struct nfs3_mknodargs *args, int tag)
5433  {
5434 -       encode_sattr3(xdr, args->sattr);
5435 +       encode_sattr3(xdr, args->sattr, tag);
5436         encode_specdata3(xdr, args->rdev);
5437  }
5438  
5439  static void encode_mknoddata3(struct xdr_stream *xdr,
5440 -                             const struct nfs3_mknodargs *args)
5441 +       const struct nfs3_mknodargs *args, int tag)
5442  {
5443         encode_ftype3(xdr, args->type);
5444         switch (args->type) {
5445         case NF3CHR:
5446         case NF3BLK:
5447 -               encode_devicedata3(xdr, args);
5448 +               encode_devicedata3(xdr, args, tag);
5449                 break;
5450         case NF3SOCK:
5451         case NF3FIFO:
5452 -               encode_sattr3(xdr, args->sattr);
5453 +               encode_sattr3(xdr, args->sattr, tag);
5454                 break;
5455         case NF3REG:
5456         case NF3DIR:
5457 @@ -1154,7 +1160,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5458                                     const struct nfs3_mknodargs *args)
5459  {
5460         encode_diropargs3(xdr, args->fh, args->name, args->len);
5461 -       encode_mknoddata3(xdr, args);
5462 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5463  }
5464  
5465  /*
5466 diff -NurpP --minimal linux-3.7/fs/nfs/super.c linux-3.7-vs2.3.5.1/fs/nfs/super.c
5467 --- linux-3.7/fs/nfs/super.c    2012-12-11 15:47:35.000000000 +0000
5468 +++ linux-3.7-vs2.3.5.1/fs/nfs/super.c  2012-12-11 17:09:13.000000000 +0000
5469 @@ -55,6 +55,7 @@
5470  #include <linux/nsproxy.h>
5471  #include <linux/rcupdate.h>
5472  #include <linux/kthread.h>
5473 +#include <linux/vs_tag.h>
5474  
5475  #include <asm/uaccess.h>
5476  
5477 @@ -102,6 +103,7 @@ enum {
5478         Opt_mountport,
5479         Opt_mountvers,
5480         Opt_minorversion,
5481 +       Opt_tagid,
5482  
5483         /* Mount options that take string arguments */
5484         Opt_nfsvers,
5485 @@ -114,6 +116,9 @@ enum {
5486         /* Special mount options */
5487         Opt_userspace, Opt_deprecated, Opt_sloppy,
5488  
5489 +       /* Linux-VServer tagging options */
5490 +       Opt_tag, Opt_notag,
5491 +
5492         Opt_err
5493  };
5494  
5495 @@ -183,6 +188,10 @@ static const match_table_t nfs_mount_opt
5496         { Opt_fscache_uniq, "fsc=%s" },
5497         { Opt_local_lock, "local_lock=%s" },
5498  
5499 +       { Opt_tag, "tag" },
5500 +       { Opt_notag, "notag" },
5501 +       { Opt_tagid, "tagid=%u" },
5502 +
5503         /* The following needs to be listed after all other options */
5504         { Opt_nfsvers, "v%s" },
5505  
5506 @@ -678,6 +687,7 @@ static void nfs_show_mount_options(struc
5507                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5508                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5509                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5510 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5511                 { 0, NULL, NULL }
5512         };
5513         const struct proc_nfs_info *nfs_infop;
5514 @@ -1304,6 +1314,14 @@ static int nfs_parse_mount_options(char
5515                 case Opt_nomigration:
5516                         mnt->options &= NFS_OPTION_MIGRATION;
5517                         break;
5518 +#ifndef CONFIG_TAGGING_NONE
5519 +               case Opt_tag:
5520 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5521 +                       break;
5522 +               case Opt_notag:
5523 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5524 +                       break;
5525 +#endif
5526  
5527                 /*
5528                  * options that take numeric values
5529 @@ -1390,6 +1408,12 @@ static int nfs_parse_mount_options(char
5530                                 goto out_invalid_value;
5531                         mnt->minorversion = option;
5532                         break;
5533 +#ifdef CONFIG_PROPAGATE
5534 +               case Opt_tagid:
5535 +                       /* use args[0] */
5536 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5537 +                       break;
5538 +#endif
5539  
5540                 /*
5541                  * options that take text values
5542 diff -NurpP --minimal linux-3.7/fs/nfsd/auth.c linux-3.7-vs2.3.5.1/fs/nfsd/auth.c
5543 --- linux-3.7/fs/nfsd/auth.c    2012-07-22 21:39:41.000000000 +0000
5544 +++ linux-3.7-vs2.3.5.1/fs/nfsd/auth.c  2012-12-11 15:56:32.000000000 +0000
5545 @@ -2,6 +2,7 @@
5546  
5547  #include <linux/sched.h>
5548  #include <linux/user_namespace.h>
5549 +#include <linux/vs_tag.h>
5550  #include "nfsd.h"
5551  #include "auth.h"
5552  
5553 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5554  
5555         new->fsuid = rqstp->rq_cred.cr_uid;
5556         new->fsgid = rqstp->rq_cred.cr_gid;
5557 +       /* FIXME: this desperately needs a tag :)
5558 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5559 +                       */
5560  
5561         rqgi = rqstp->rq_cred.cr_group_info;
5562  
5563 diff -NurpP --minimal linux-3.7/fs/nfsd/nfs3xdr.c linux-3.7-vs2.3.5.1/fs/nfsd/nfs3xdr.c
5564 --- linux-3.7/fs/nfsd/nfs3xdr.c 2012-05-21 16:07:26.000000000 +0000
5565 +++ linux-3.7-vs2.3.5.1/fs/nfsd/nfs3xdr.c       2012-12-11 15:56:32.000000000 +0000
5566 @@ -7,6 +7,7 @@
5567   */
5568  
5569  #include <linux/namei.h>
5570 +#include <linux/vs_tag.h>
5571  #include "xdr3.h"
5572  #include "auth.h"
5573  
5574 @@ -95,6 +96,8 @@ static __be32 *
5575  decode_sattr3(__be32 *p, struct iattr *iap)
5576  {
5577         u32     tmp;
5578 +       uid_t   uid = 0;
5579 +       gid_t   gid = 0;
5580  
5581         iap->ia_valid = 0;
5582  
5583 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5584         }
5585         if (*p++) {
5586                 iap->ia_valid |= ATTR_UID;
5587 -               iap->ia_uid = ntohl(*p++);
5588 +               uid = ntohl(*p++);
5589         }
5590         if (*p++) {
5591                 iap->ia_valid |= ATTR_GID;
5592 -               iap->ia_gid = ntohl(*p++);
5593 +               gid = ntohl(*p++);
5594         }
5595 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5596 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5597 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5598         if (*p++) {
5599                 u64     newsize;
5600  
5601 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5602         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5603         *p++ = htonl((u32) stat->mode);
5604         *p++ = htonl((u32) stat->nlink);
5605 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5606 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5607 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5608 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5609 +               stat->uid, stat->tag)));
5610 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5611 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5612 +               stat->gid, stat->tag)));
5613         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5614                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5615         } else {
5616 diff -NurpP --minimal linux-3.7/fs/nfsd/nfs4xdr.c linux-3.7-vs2.3.5.1/fs/nfsd/nfs4xdr.c
5617 --- linux-3.7/fs/nfsd/nfs4xdr.c 2012-12-11 15:47:35.000000000 +0000
5618 +++ linux-3.7-vs2.3.5.1/fs/nfsd/nfs4xdr.c       2012-12-11 15:56:32.000000000 +0000
5619 @@ -46,6 +46,7 @@
5620  #include <linux/utsname.h>
5621  #include <linux/pagemap.h>
5622  #include <linux/sunrpc/svcauth_gss.h>
5623 +#include <linux/vs_tag.h>
5624  
5625  #include "idmap.h"
5626  #include "acl.h"
5627 @@ -2351,14 +2352,18 @@ out_acl:
5628                 WRITE32(stat.nlink);
5629         }
5630         if (bmval1 & FATTR4_WORD1_OWNER) {
5631 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5632 +               status = nfsd4_encode_user(rqstp,
5633 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5634 +                       stat.uid, stat.tag), &p, &buflen);
5635                 if (status == nfserr_resource)
5636                         goto out_resource;
5637                 if (status)
5638                         goto out;
5639         }
5640         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5641 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5642 +               status = nfsd4_encode_group(rqstp,
5643 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5644 +                       stat.gid, stat.tag), &p, &buflen);
5645                 if (status == nfserr_resource)
5646                         goto out_resource;
5647                 if (status)
5648 diff -NurpP --minimal linux-3.7/fs/nfsd/nfsxdr.c linux-3.7-vs2.3.5.1/fs/nfsd/nfsxdr.c
5649 --- linux-3.7/fs/nfsd/nfsxdr.c  2011-05-22 14:17:53.000000000 +0000
5650 +++ linux-3.7-vs2.3.5.1/fs/nfsd/nfsxdr.c        2012-12-11 15:56:32.000000000 +0000
5651 @@ -6,6 +6,7 @@
5652  
5653  #include "xdr.h"
5654  #include "auth.h"
5655 +#include <linux/vs_tag.h>
5656  
5657  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5658  
5659 @@ -88,6 +89,8 @@ static __be32 *
5660  decode_sattr(__be32 *p, struct iattr *iap)
5661  {
5662         u32     tmp, tmp1;
5663 +       uid_t   uid = 0;
5664 +       gid_t   gid = 0;
5665  
5666         iap->ia_valid = 0;
5667  
5668 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5669         }
5670         if ((tmp = ntohl(*p++)) != (u32)-1) {
5671                 iap->ia_valid |= ATTR_UID;
5672 -               iap->ia_uid = tmp;
5673 +               uid = tmp;
5674         }
5675         if ((tmp = ntohl(*p++)) != (u32)-1) {
5676                 iap->ia_valid |= ATTR_GID;
5677 -               iap->ia_gid = tmp;
5678 +               gid = tmp;
5679         }
5680 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5681 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5682 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5683         if ((tmp = ntohl(*p++)) != (u32)-1) {
5684                 iap->ia_valid |= ATTR_SIZE;
5685                 iap->ia_size = tmp;
5686 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5687         *p++ = htonl(nfs_ftypes[type >> 12]);
5688         *p++ = htonl((u32) stat->mode);
5689         *p++ = htonl((u32) stat->nlink);
5690 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5691 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5692 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5693 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5694 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5695 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5696  
5697         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5698                 *p++ = htonl(NFS_MAXPATHLEN);
5699 diff -NurpP --minimal linux-3.7/fs/ocfs2/dlmglue.c linux-3.7-vs2.3.5.1/fs/ocfs2/dlmglue.c
5700 --- linux-3.7/fs/ocfs2/dlmglue.c        2012-07-22 21:39:41.000000000 +0000
5701 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/dlmglue.c      2012-12-11 15:56:32.000000000 +0000
5702 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5703         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5704         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5705         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5706 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5707         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5708         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5709         lvb->lvb_iatime_packed  =
5710 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5711  
5712         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5713         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5714 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5715         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5716         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5717         ocfs2_unpack_timespec(&inode->i_atime,
5718 diff -NurpP --minimal linux-3.7/fs/ocfs2/dlmglue.h linux-3.7-vs2.3.5.1/fs/ocfs2/dlmglue.h
5719 --- linux-3.7/fs/ocfs2/dlmglue.h        2010-10-21 11:07:50.000000000 +0000
5720 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/dlmglue.h      2012-12-11 15:56:32.000000000 +0000
5721 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5722         __be16       lvb_inlink;
5723         __be32       lvb_iattr;
5724         __be32       lvb_igeneration;
5725 -       __be32       lvb_reserved2;
5726 +       __be16       lvb_itag;
5727 +       __be16       lvb_reserved2;
5728  };
5729  
5730  #define OCFS2_QINFO_LVB_VERSION 1
5731 diff -NurpP --minimal linux-3.7/fs/ocfs2/file.c linux-3.7-vs2.3.5.1/fs/ocfs2/file.c
5732 --- linux-3.7/fs/ocfs2/file.c   2012-12-11 15:47:35.000000000 +0000
5733 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/file.c 2012-12-11 15:56:32.000000000 +0000
5734 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5735                 attr->ia_valid &= ~ATTR_SIZE;
5736  
5737  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5738 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5739 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5740         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5741                 return 0;
5742  
5743 diff -NurpP --minimal linux-3.7/fs/ocfs2/inode.c linux-3.7-vs2.3.5.1/fs/ocfs2/inode.c
5744 --- linux-3.7/fs/ocfs2/inode.c  2012-07-22 21:39:41.000000000 +0000
5745 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/inode.c        2012-12-11 15:56:32.000000000 +0000
5746 @@ -28,6 +28,7 @@
5747  #include <linux/highmem.h>
5748  #include <linux/pagemap.h>
5749  #include <linux/quotaops.h>
5750 +#include <linux/vs_tag.h>
5751  
5752  #include <asm/byteorder.h>
5753  
5754 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5755  {
5756         unsigned int flags = OCFS2_I(inode)->ip_attr;
5757  
5758 -       inode->i_flags &= ~(S_IMMUTABLE |
5759 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5760                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5761  
5762         if (flags & OCFS2_IMMUTABLE_FL)
5763                 inode->i_flags |= S_IMMUTABLE;
5764 +       if (flags & OCFS2_IXUNLINK_FL)
5765 +               inode->i_flags |= S_IXUNLINK;
5766  
5767         if (flags & OCFS2_SYNC_FL)
5768                 inode->i_flags |= S_SYNC;
5769 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5770                 inode->i_flags |= S_NOATIME;
5771         if (flags & OCFS2_DIRSYNC_FL)
5772                 inode->i_flags |= S_DIRSYNC;
5773 +
5774 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5775 +
5776 +       if (flags & OCFS2_BARRIER_FL)
5777 +               inode->i_vflags |= V_BARRIER;
5778 +       if (flags & OCFS2_COW_FL)
5779 +               inode->i_vflags |= V_COW;
5780  }
5781  
5782  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5783  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5784  {
5785         unsigned int flags = oi->vfs_inode.i_flags;
5786 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5787 +
5788 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5789 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5790 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5791 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5792 +
5793 +       if (flags & S_IMMUTABLE)
5794 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5795 +       if (flags & S_IXUNLINK)
5796 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5797  
5798 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5799 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5800         if (flags & S_SYNC)
5801                 oi->ip_attr |= OCFS2_SYNC_FL;
5802         if (flags & S_APPEND)
5803                 oi->ip_attr |= OCFS2_APPEND_FL;
5804 -       if (flags & S_IMMUTABLE)
5805 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5806         if (flags & S_NOATIME)
5807                 oi->ip_attr |= OCFS2_NOATIME_FL;
5808         if (flags & S_DIRSYNC)
5809                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5810 +
5811 +       if (vflags & V_BARRIER)
5812 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5813 +       if (vflags & V_COW)
5814 +               oi->ip_attr |= OCFS2_COW_FL;
5815  }
5816  
5817  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5818 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5819         struct super_block *sb;
5820         struct ocfs2_super *osb;
5821         int use_plocks = 1;
5822 +       uid_t uid;
5823 +       gid_t gid;
5824  
5825         sb = inode->i_sb;
5826         osb = OCFS2_SB(sb);
5827 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5828         inode->i_generation = le32_to_cpu(fe->i_generation);
5829         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5830         inode->i_mode = le16_to_cpu(fe->i_mode);
5831 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5832 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5833 +       uid = le32_to_cpu(fe->i_uid);
5834 +       gid = le32_to_cpu(fe->i_gid);
5835 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5836 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5837 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5838 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5839  
5840         /* Fast symlinks will have i_size but no allocated clusters. */
5841         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5842 diff -NurpP --minimal linux-3.7/fs/ocfs2/inode.h linux-3.7-vs2.3.5.1/fs/ocfs2/inode.h
5843 --- linux-3.7/fs/ocfs2/inode.h  2012-01-09 15:14:55.000000000 +0000
5844 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/inode.h        2012-12-11 15:56:32.000000000 +0000
5845 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5846  
5847  void ocfs2_set_inode_flags(struct inode *inode);
5848  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5849 +int ocfs2_sync_flags(struct inode *inode, int, int);
5850  
5851  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5852  {
5853 diff -NurpP --minimal linux-3.7/fs/ocfs2/ioctl.c linux-3.7-vs2.3.5.1/fs/ocfs2/ioctl.c
5854 --- linux-3.7/fs/ocfs2/ioctl.c  2012-10-04 13:27:41.000000000 +0000
5855 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/ioctl.c        2012-12-11 15:56:32.000000000 +0000
5856 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5857         return status;
5858  }
5859  
5860 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5861 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5862 +{
5863 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5864 +       struct buffer_head *bh = NULL;
5865 +       handle_t *handle = NULL;
5866 +       int status;
5867 +
5868 +       status = ocfs2_inode_lock(inode, &bh, 1);
5869 +       if (status < 0) {
5870 +               mlog_errno(status);
5871 +               return status;
5872 +       }
5873 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5874 +       if (IS_ERR(handle)) {
5875 +               status = PTR_ERR(handle);
5876 +               mlog_errno(status);
5877 +               goto bail_unlock;
5878 +       }
5879 +
5880 +       inode->i_flags = flags;
5881 +       inode->i_vflags = vflags;
5882 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5883 +
5884 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5885 +       if (status < 0)
5886 +               mlog_errno(status);
5887 +
5888 +       ocfs2_commit_trans(osb, handle);
5889 +bail_unlock:
5890 +       ocfs2_inode_unlock(inode, 1);
5891 +       brelse(bh);
5892 +       return status;
5893 +}
5894 +
5895 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5896                                 unsigned mask)
5897  {
5898         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5899 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5900         if (!S_ISDIR(inode->i_mode))
5901                 flags &= ~OCFS2_DIRSYNC_FL;
5902  
5903 +       if (IS_BARRIER(inode)) {
5904 +               vxwprintk_task(1, "messing with the barrier.");
5905 +               goto bail_unlock;
5906 +       }
5907 +
5908         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5909         if (IS_ERR(handle)) {
5910                 status = PTR_ERR(handle);
5911 @@ -879,6 +918,7 @@ bail:
5912         return status;
5913  }
5914  
5915 +
5916  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5917  {
5918         struct inode *inode = filp->f_path.dentry->d_inode;
5919 diff -NurpP --minimal linux-3.7/fs/ocfs2/namei.c linux-3.7-vs2.3.5.1/fs/ocfs2/namei.c
5920 --- linux-3.7/fs/ocfs2/namei.c  2012-10-04 13:27:41.000000000 +0000
5921 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/namei.c        2012-12-11 15:56:32.000000000 +0000
5922 @@ -41,6 +41,7 @@
5923  #include <linux/slab.h>
5924  #include <linux/highmem.h>
5925  #include <linux/quotaops.h>
5926 +#include <linux/vs_tag.h>
5927  
5928  #include <cluster/masklog.h>
5929  
5930 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5931         struct ocfs2_dinode *fe = NULL;
5932         struct ocfs2_extent_list *fel;
5933         u16 feat;
5934 +       tag_t tag;
5935  
5936         *new_fe_bh = NULL;
5937  
5938 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5939         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5940         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5941         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5942 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5943 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5944 +
5945 +       tag = dx_current_fstag(osb->sb);
5946 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5947 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
5948 +       inode->i_tag = tag;
5949         fe->i_mode = cpu_to_le16(inode->i_mode);
5950         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5951                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5952 diff -NurpP --minimal linux-3.7/fs/ocfs2/ocfs2.h linux-3.7-vs2.3.5.1/fs/ocfs2/ocfs2.h
5953 --- linux-3.7/fs/ocfs2/ocfs2.h  2012-01-09 15:14:55.000000000 +0000
5954 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/ocfs2.h        2012-12-11 15:56:32.000000000 +0000
5955 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5956                                                      writes */
5957         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5958         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5959 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5960  };
5961  
5962  #define OCFS2_OSB_SOFT_RO                      0x0001
5963 diff -NurpP --minimal linux-3.7/fs/ocfs2/ocfs2_fs.h linux-3.7-vs2.3.5.1/fs/ocfs2/ocfs2_fs.h
5964 --- linux-3.7/fs/ocfs2/ocfs2_fs.h       2011-05-22 14:17:53.000000000 +0000
5965 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/ocfs2_fs.h     2012-12-11 15:56:32.000000000 +0000
5966 @@ -266,6 +266,11 @@
5967  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5968  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5969  
5970 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5971 +
5972 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5973 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5974 +
5975  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5976  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5977  
5978 diff -NurpP --minimal linux-3.7/fs/ocfs2/super.c linux-3.7-vs2.3.5.1/fs/ocfs2/super.c
5979 --- linux-3.7/fs/ocfs2/super.c  2012-12-11 15:47:36.000000000 +0000
5980 +++ linux-3.7-vs2.3.5.1/fs/ocfs2/super.c        2012-12-11 15:56:32.000000000 +0000
5981 @@ -185,6 +185,7 @@ enum {
5982         Opt_coherency_full,
5983         Opt_resv_level,
5984         Opt_dir_resv_level,
5985 +       Opt_tag, Opt_notag, Opt_tagid,
5986         Opt_err,
5987  };
5988  
5989 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5990         {Opt_coherency_full, "coherency=full"},
5991         {Opt_resv_level, "resv_level=%u"},
5992         {Opt_dir_resv_level, "dir_resv_level=%u"},
5993 +       {Opt_tag, "tag"},
5994 +       {Opt_notag, "notag"},
5995 +       {Opt_tagid, "tagid=%u"},
5996         {Opt_err, NULL}
5997  };
5998  
5999 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
6000                 goto out;
6001         }
6002  
6003 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6004 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6005 +               ret = -EINVAL;
6006 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6007 +               goto out;
6008 +       }
6009 +
6010         /* We're going to/from readonly mode. */
6011         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6012                 /* Disable quota accounting before remounting RO */
6013 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
6014  
6015         ocfs2_complete_mount_recovery(osb);
6016  
6017 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6018 +               sb->s_flags |= MS_TAGGED;
6019 +
6020         if (ocfs2_mount_local(osb))
6021                 snprintf(nodestr, sizeof(nodestr), "local");
6022         else
6023 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
6024                             option < OCFS2_MAX_RESV_LEVEL)
6025                                 mopt->dir_resv_level = option;
6026                         break;
6027 +#ifndef CONFIG_TAGGING_NONE
6028 +               case Opt_tag:
6029 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6030 +                       break;
6031 +               case Opt_notag:
6032 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6033 +                       break;
6034 +#endif
6035 +#ifdef CONFIG_PROPAGATE
6036 +               case Opt_tagid:
6037 +                       /* use args[0] */
6038 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6039 +                       break;
6040 +#endif
6041                 default:
6042                         mlog(ML_ERROR,
6043                              "Unrecognized mount option \"%s\" "
6044 diff -NurpP --minimal linux-3.7/fs/open.c linux-3.7-vs2.3.5.1/fs/open.c
6045 --- linux-3.7/fs/open.c 2012-12-11 15:47:36.000000000 +0000
6046 +++ linux-3.7-vs2.3.5.1/fs/open.c       2012-12-11 15:56:32.000000000 +0000
6047 @@ -30,6 +30,11 @@
6048  #include <linux/fs_struct.h>
6049  #include <linux/ima.h>
6050  #include <linux/dnotify.h>
6051 +#include <linux/vs_base.h>
6052 +#include <linux/vs_limit.h>
6053 +#include <linux/vs_tag.h>
6054 +#include <linux/vs_cowbl.h>
6055 +#include <linux/vserver/dlimit.h>
6056  
6057  #include "internal.h"
6058  
6059 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6060         error = user_path(pathname, &path);
6061         if (error)
6062                 goto out;
6063 +
6064 +#ifdef CONFIG_VSERVER_COWBL
6065 +       error = cow_check_and_break(&path);
6066 +       if (error)
6067 +               goto dput_and_out;
6068 +#endif
6069         inode = path.dentry->d_inode;
6070  
6071         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6072 @@ -492,6 +503,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6073  
6074         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6075         if (!error) {
6076 +#ifdef CONFIG_VSERVER_COWBL
6077 +               error = cow_check_and_break(&path);
6078 +               if (!error)
6079 +#endif
6080                 error = chmod_common(&path, mode);
6081                 path_put(&path);
6082         }
6083 @@ -519,13 +534,13 @@ static int chown_common(struct path *pat
6084                 if (!uid_valid(uid))
6085                         return -EINVAL;
6086                 newattrs.ia_valid |= ATTR_UID;
6087 -               newattrs.ia_uid = uid;
6088 +               newattrs.ia_uid = dx_map_uid(user);
6089         }
6090         if (group != (gid_t) -1) {
6091                 if (!gid_valid(gid))
6092                         return -EINVAL;
6093                 newattrs.ia_valid |= ATTR_GID;
6094 -               newattrs.ia_gid = gid;
6095 +               newattrs.ia_gid = dx_map_gid(group);
6096         }
6097         if (!S_ISDIR(inode->i_mode))
6098                 newattrs.ia_valid |=
6099 @@ -558,6 +573,18 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6100         error = mnt_want_write(path.mnt);
6101         if (error)
6102                 goto out_release;
6103 +#ifdef CONFIG_VSERVER_COWBL
6104 +       error = cow_check_and_break(&path);
6105 +       if (!error)
6106 +#endif
6107 +#ifdef CONFIG_VSERVER_COWBL
6108 +       error = cow_check_and_break(&path);
6109 +       if (!error)
6110 +#endif
6111 +#ifdef CONFIG_VSERVER_COWBL
6112 +       error = cow_check_and_break(&path);
6113 +       if (!error)
6114 +#endif
6115         error = chown_common(&path, user, group);
6116         mnt_drop_write(path.mnt);
6117  out_release:
6118 diff -NurpP --minimal linux-3.7/fs/proc/array.c linux-3.7-vs2.3.5.1/fs/proc/array.c
6119 --- linux-3.7/fs/proc/array.c   2012-07-22 21:39:42.000000000 +0000
6120 +++ linux-3.7-vs2.3.5.1/fs/proc/array.c 2012-12-11 15:56:32.000000000 +0000
6121 @@ -82,6 +82,8 @@
6122  #include <linux/ptrace.h>
6123  #include <linux/tracehook.h>
6124  #include <linux/user_namespace.h>
6125 +#include <linux/vs_context.h>
6126 +#include <linux/vs_network.h>
6127  
6128  #include <asm/pgtable.h>
6129  #include <asm/processor.h>
6130 @@ -172,6 +174,9 @@ static inline void task_state(struct seq
6131         rcu_read_lock();
6132         ppid = pid_alive(p) ?
6133                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6134 +       if (unlikely(vx_current_initpid(p->pid)))
6135 +               ppid = 0;
6136 +
6137         tpid = 0;
6138         if (pid_alive(p)) {
6139                 struct task_struct *tracer = ptrace_parent(p);
6140 @@ -296,7 +301,7 @@ static inline void task_sig(struct seq_f
6141  }
6142  
6143  static void render_cap_t(struct seq_file *m, const char *header,
6144 -                       kernel_cap_t *a)
6145 +                       struct vx_info *vxi, kernel_cap_t *a)
6146  {
6147         unsigned __capi;
6148  
6149 @@ -321,10 +326,11 @@ static inline void task_cap(struct seq_f
6150         cap_bset        = cred->cap_bset;
6151         rcu_read_unlock();
6152  
6153 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6154 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6155 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6156 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6157 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6158 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6159 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6160 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6161 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6162  }
6163  
6164  static inline void task_context_switch_counts(struct seq_file *m,
6165 @@ -346,6 +352,42 @@ static void task_cpus_allowed(struct seq
6166         seq_putc(m, '\n');
6167  }
6168  
6169 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6170 +                       struct pid *pid, struct task_struct *task)
6171 +{
6172 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6173 +                       "Count:\t%u\n"
6174 +                       "uts:\t%p(%c)\n"
6175 +                       "ipc:\t%p(%c)\n"
6176 +                       "mnt:\t%p(%c)\n"
6177 +                       "pid:\t%p(%c)\n"
6178 +                       "net:\t%p(%c)\n",
6179 +                       task->nsproxy,
6180 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6181 +                       atomic_read(&task->nsproxy->count),
6182 +                       task->nsproxy->uts_ns,
6183 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6184 +                       task->nsproxy->ipc_ns,
6185 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6186 +                       task->nsproxy->mnt_ns,
6187 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6188 +                       task->nsproxy->pid_ns,
6189 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6190 +                       task->nsproxy->net_ns,
6191 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6192 +       return 0;
6193 +}
6194 +
6195 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6196 +{
6197 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6198 +               return;
6199 +
6200 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6201 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6202 +}
6203 +
6204 +
6205  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6206                         struct pid *pid, struct task_struct *task)
6207  {
6208 @@ -362,6 +404,7 @@ int proc_pid_status(struct seq_file *m,
6209         task_cap(m, task);
6210         task_cpus_allowed(m, task);
6211         cpuset_task_status_allowed(m, task);
6212 +       task_vs_id(m, task);
6213         task_context_switch_counts(m, task);
6214         return 0;
6215  }
6216 @@ -471,6 +514,17 @@ static int do_task_stat(struct seq_file
6217         /* convert nsec -> ticks */
6218         start_time = nsec_to_clock_t(start_time);
6219  
6220 +       /* fixup start time for virt uptime */
6221 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6222 +               unsigned long long bias =
6223 +                       current->vx_info->cvirt.bias_clock;
6224 +
6225 +               if (start_time > bias)
6226 +                       start_time -= bias;
6227 +               else
6228 +                       start_time = 0;
6229 +       }
6230 +
6231         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6232         seq_put_decimal_ll(m, ' ', ppid);
6233         seq_put_decimal_ll(m, ' ', pgid);
6234 diff -NurpP --minimal linux-3.7/fs/proc/base.c linux-3.7-vs2.3.5.1/fs/proc/base.c
6235 --- linux-3.7/fs/proc/base.c    2012-12-11 15:47:36.000000000 +0000
6236 +++ linux-3.7-vs2.3.5.1/fs/proc/base.c  2012-12-11 19:34:49.000000000 +0000
6237 @@ -85,6 +85,8 @@
6238  #include <linux/fs_struct.h>
6239  #include <linux/slab.h>
6240  #include <linux/flex_array.h>
6241 +#include <linux/vs_context.h>
6242 +#include <linux/vs_network.h>
6243  #ifdef CONFIG_HARDWALL
6244  #include <asm/hardwall.h>
6245  #endif
6246 @@ -950,11 +952,15 @@ static ssize_t oom_adj_write(struct file
6247                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6248  
6249         if (oom_adj < task->signal->oom_score_adj &&
6250 -           !capable(CAP_SYS_RESOURCE)) {
6251 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6252                 err = -EACCES;
6253                 goto err_sighand;
6254         }
6255  
6256 +       /* prevent guest processes from circumventing the oom killer */
6257 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6258 +               oom_adj = OOM_ADJUST_MIN;
6259 +
6260         /*
6261          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6262          * /proc/pid/oom_score_adj instead.
6263 @@ -1534,6 +1540,8 @@ struct inode *proc_pid_make_inode(struct
6264                 inode->i_gid = cred->egid;
6265                 rcu_read_unlock();
6266         }
6267 +       /* procfs is xid tagged */
6268 +       i_tag_write(inode, (tag_t)vx_task_xid(task));
6269         security_task_to_inode(task, inode);
6270  
6271  out:
6272 @@ -1579,6 +1587,8 @@ int pid_getattr(struct vfsmount *mnt, st
6273  
6274  /* dentry stuff */
6275  
6276 +static unsigned name_to_int(struct dentry *dentry);
6277 +
6278  /*
6279   *     Exceptional case: normally we are not allowed to unhash a busy
6280   * directory. In this case, however, we can do it - no aliasing problems
6281 @@ -1607,6 +1617,12 @@ int pid_revalidate(struct dentry *dentry
6282         task = get_proc_task(inode);
6283  
6284         if (task) {
6285 +               unsigned pid = name_to_int(dentry);
6286 +
6287 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6288 +                       put_task_struct(task);
6289 +                       goto drop;
6290 +               }
6291                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6292                     task_dumpable(task)) {
6293                         rcu_read_lock();
6294 @@ -1623,6 +1639,7 @@ int pid_revalidate(struct dentry *dentry
6295                 put_task_struct(task);
6296                 return 1;
6297         }
6298 +drop:
6299         d_drop(dentry);
6300         return 0;
6301  }
6302 @@ -2065,6 +2082,13 @@ static struct dentry *proc_pident_lookup
6303         if (!task)
6304                 goto out_no_task;
6305  
6306 +       /* TODO: maybe we can come up with a generic approach? */
6307 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6308 +               (dentry->d_name.len == 5) &&
6309 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6310 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6311 +               goto out;
6312 +
6313         /*
6314          * Yes, it does not scale. And it should not. Don't add
6315          * new entries into /proc/<tgid>/ without very good reasons.
6316 @@ -2451,7 +2475,7 @@ out_iput:
6317  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6318  {
6319         struct dentry *error;
6320 -       struct task_struct *task = get_proc_task(dir);
6321 +       struct task_struct *task = get_proc_task_real(dir);
6322         const struct pid_entry *p, *last;
6323  
6324         error = ERR_PTR(-ENOENT);
6325 @@ -2639,6 +2663,9 @@ static int proc_pid_personality(struct s
6326  static const struct file_operations proc_task_operations;
6327  static const struct inode_operations proc_task_inode_operations;
6328  
6329 +extern int proc_pid_vx_info(struct task_struct *, char *);
6330 +extern int proc_pid_nx_info(struct task_struct *, char *);
6331 +
6332  static const struct pid_entry tgid_base_stuff[] = {
6333         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6334         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6335 @@ -2705,6 +2732,8 @@ static const struct pid_entry tgid_base_
6336  #ifdef CONFIG_CGROUPS
6337         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6338  #endif
6339 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6340 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6341         INF("oom_score",  S_IRUGO, proc_oom_score),
6342         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6343         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6344 @@ -2729,6 +2758,7 @@ static const struct pid_entry tgid_base_
6345         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6346         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6347  #endif
6348 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6349  };
6350  
6351  static int proc_tgid_base_readdir(struct file * filp,
6352 @@ -2923,7 +2953,7 @@ retry:
6353         iter.task = NULL;
6354         pid = find_ge_pid(iter.tgid, ns);
6355         if (pid) {
6356 -               iter.tgid = pid_nr_ns(pid, ns);
6357 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6358                 iter.task = pid_task(pid, PIDTYPE_PID);
6359                 /* What we to know is if the pid we have find is the
6360                  * pid of a thread_group_leader.  Testing for task
6361 @@ -2953,7 +2983,7 @@ static int proc_pid_fill_cache(struct fi
6362         struct tgid_iter iter)
6363  {
6364         char name[PROC_NUMBUF];
6365 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6366 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6367         return proc_fill_cache(filp, dirent, filldir, name, len,
6368                                 proc_pid_instantiate, iter.task, NULL);
6369  }
6370 @@ -2977,7 +3007,7 @@ int proc_pid_readdir(struct file * filp,
6371                 goto out_no_task;
6372         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6373  
6374 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6375 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6376         if (!reaper)
6377                 goto out_no_task;
6378  
6379 @@ -2999,6 +3029,8 @@ int proc_pid_readdir(struct file * filp,
6380                         __filldir = fake_filldir;
6381  
6382                 filp->f_pos = iter.tgid + TGID_OFFSET;
6383 +               if (!vx_proc_task_visible(iter.task))
6384 +                       continue;
6385                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6386                         put_task_struct(iter.task);
6387                         goto out;
6388 @@ -3161,6 +3193,8 @@ static struct dentry *proc_task_lookup(s
6389         tid = name_to_int(dentry);
6390         if (tid == ~0U)
6391                 goto out;
6392 +       if (vx_current_initpid(tid))
6393 +               goto out;
6394  
6395         ns = dentry->d_sb->s_fs_info;
6396         rcu_read_lock();
6397 diff -NurpP --minimal linux-3.7/fs/proc/generic.c linux-3.7-vs2.3.5.1/fs/proc/generic.c
6398 --- linux-3.7/fs/proc/generic.c 2012-12-11 15:47:36.000000000 +0000
6399 +++ linux-3.7-vs2.3.5.1/fs/proc/generic.c       2012-12-11 19:15:21.000000000 +0000
6400 @@ -22,6 +22,7 @@
6401  #include <linux/bitops.h>
6402  #include <linux/spinlock.h>
6403  #include <linux/completion.h>
6404 +#include <linux/vserver/inode.h>
6405  #include <asm/uaccess.h>
6406  
6407  #include "internal.h"
6408 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6409         for (de = de->subdir; de ; de = de->next) {
6410                 if (de->namelen != dentry->d_name.len)
6411                         continue;
6412 +               if (!vx_hide_check(0, de->vx_flags))
6413 +                       continue;
6414                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6415                         pde_get(de);
6416                         spin_unlock(&proc_subdir_lock);
6417                         error = -ENOMEM;
6418                         inode = proc_get_inode(dir->i_sb, de);
6419 +                       /* generic proc entries belong to the host */
6420 +                       i_tag_write(inode, 0);
6421                         goto out_unlock;
6422                 }
6423         }
6424 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6425  
6426                                 /* filldir passes info to user space */
6427                                 pde_get(de);
6428 +                               if (!vx_hide_check(0, de->vx_flags))
6429 +                                       goto skip;
6430                                 spin_unlock(&proc_subdir_lock);
6431                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6432                                             de->low_ino, de->mode >> 12) < 0) {
6433 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6434                                         goto out;
6435                                 }
6436                                 spin_lock(&proc_subdir_lock);
6437 +                       skip:
6438                                 filp->f_pos++;
6439                                 next = de->next;
6440                                 pde_put(de);
6441 @@ -625,6 +633,7 @@ static struct proc_dir_entry *__proc_cre
6442         ent->namelen = len;
6443         ent->mode = mode;
6444         ent->nlink = nlink;
6445 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6446         atomic_set(&ent->count, 1);
6447         spin_lock_init(&ent->pde_unload_lock);
6448         INIT_LIST_HEAD(&ent->pde_openers);
6449 @@ -648,7 +657,8 @@ struct proc_dir_entry *proc_symlink(cons
6450                                 kfree(ent->data);
6451                                 kfree(ent);
6452                                 ent = NULL;
6453 -                       }
6454 +                       } else
6455 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6456                 } else {
6457                         kfree(ent);
6458                         ent = NULL;
6459 diff -NurpP --minimal linux-3.7/fs/proc/inode.c linux-3.7-vs2.3.5.1/fs/proc/inode.c
6460 --- linux-3.7/fs/proc/inode.c   2012-12-11 15:47:36.000000000 +0000
6461 +++ linux-3.7-vs2.3.5.1/fs/proc/inode.c 2012-12-11 15:56:32.000000000 +0000
6462 @@ -457,6 +457,8 @@ struct inode *proc_get_inode(struct supe
6463                         inode->i_uid = de->uid;
6464                         inode->i_gid = de->gid;
6465                 }
6466 +               if (de->vx_flags)
6467 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6468                 if (de->size)
6469                         inode->i_size = de->size;
6470                 if (de->nlink)
6471 diff -NurpP --minimal linux-3.7/fs/proc/internal.h linux-3.7-vs2.3.5.1/fs/proc/internal.h
6472 --- linux-3.7/fs/proc/internal.h        2012-12-11 15:47:36.000000000 +0000
6473 +++ linux-3.7-vs2.3.5.1/fs/proc/internal.h      2012-12-11 15:56:32.000000000 +0000
6474 @@ -11,6 +11,8 @@
6475  
6476  #include <linux/sched.h>
6477  #include <linux/proc_fs.h>
6478 +#include <linux/vs_pid.h>
6479 +
6480  struct  ctl_table_header;
6481  struct  mempolicy;
6482  
6483 @@ -54,6 +56,9 @@ extern int proc_pid_status(struct seq_fi
6484                                 struct pid *pid, struct task_struct *task);
6485  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6486                                 struct pid *pid, struct task_struct *task);
6487 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6488 +                               struct pid *pid, struct task_struct *task);
6489 +
6490  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6491  
6492  extern const struct file_operations proc_tid_children_operations;
6493 @@ -87,11 +92,16 @@ static inline struct pid *proc_pid(struc
6494         return PROC_I(inode)->pid;
6495  }
6496  
6497 -static inline struct task_struct *get_proc_task(struct inode *inode)
6498 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6499  {
6500         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6501  }
6502  
6503 +static inline struct task_struct *get_proc_task(struct inode *inode)
6504 +{
6505 +       return vx_get_proc_task(inode, proc_pid(inode));
6506 +}
6507 +
6508  static inline int proc_fd(struct inode *inode)
6509  {
6510         return PROC_I(inode)->fd;
6511 diff -NurpP --minimal linux-3.7/fs/proc/loadavg.c linux-3.7-vs2.3.5.1/fs/proc/loadavg.c
6512 --- linux-3.7/fs/proc/loadavg.c 2009-09-10 13:26:23.000000000 +0000
6513 +++ linux-3.7-vs2.3.5.1/fs/proc/loadavg.c       2012-12-11 15:56:32.000000000 +0000
6514 @@ -12,15 +12,27 @@
6515  
6516  static int loadavg_proc_show(struct seq_file *m, void *v)
6517  {
6518 +       unsigned long running;
6519 +       unsigned int threads;
6520         unsigned long avnrun[3];
6521  
6522         get_avenrun(avnrun, FIXED_1/200, 0);
6523  
6524 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6525 +               struct vx_info *vxi = current_vx_info();
6526 +
6527 +               running = atomic_read(&vxi->cvirt.nr_running);
6528 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6529 +       } else {
6530 +               running = nr_running();
6531 +               threads = nr_threads;
6532 +       }
6533 +
6534         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6535                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6536                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6537                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6538 -               nr_running(), nr_threads,
6539 +               running, threads,
6540                 task_active_pid_ns(current)->last_pid);
6541         return 0;
6542  }
6543 diff -NurpP --minimal linux-3.7/fs/proc/meminfo.c linux-3.7-vs2.3.5.1/fs/proc/meminfo.c
6544 --- linux-3.7/fs/proc/meminfo.c 2012-01-09 15:14:55.000000000 +0000
6545 +++ linux-3.7-vs2.3.5.1/fs/proc/meminfo.c       2012-12-11 15:56:32.000000000 +0000
6546 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6547         allowed = ((totalram_pages - hugetlb_total_pages())
6548                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6549  
6550 -       cached = global_page_state(NR_FILE_PAGES) -
6551 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6552 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6553                         total_swapcache_pages - i.bufferram;
6554         if (cached < 0)
6555                 cached = 0;
6556 diff -NurpP --minimal linux-3.7/fs/proc/root.c linux-3.7-vs2.3.5.1/fs/proc/root.c
6557 --- linux-3.7/fs/proc/root.c    2012-12-11 15:47:36.000000000 +0000
6558 +++ linux-3.7-vs2.3.5.1/fs/proc/root.c  2012-12-11 15:56:32.000000000 +0000
6559 @@ -19,9 +19,14 @@
6560  #include <linux/mount.h>
6561  #include <linux/pid_namespace.h>
6562  #include <linux/parser.h>
6563 +#include <linux/vserver/inode.h>
6564  
6565  #include "internal.h"
6566  
6567 +struct proc_dir_entry *proc_virtual;
6568 +
6569 +extern void proc_vx_init(void);
6570 +
6571  static int proc_test_super(struct super_block *sb, void *data)
6572  {
6573         return sb->s_fs_info == data;
6574 @@ -189,6 +194,7 @@ void __init proc_root_init(void)
6575  #endif
6576         proc_mkdir("bus", NULL);
6577         proc_sys_init();
6578 +       proc_vx_init();
6579  }
6580  
6581  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6582 @@ -255,6 +261,7 @@ struct proc_dir_entry proc_root = {
6583         .proc_iops      = &proc_root_inode_operations, 
6584         .proc_fops      = &proc_root_operations,
6585         .parent         = &proc_root,
6586 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6587         .name           = "/proc",
6588  };
6589  
6590 diff -NurpP --minimal linux-3.7/fs/proc/stat.c linux-3.7-vs2.3.5.1/fs/proc/stat.c
6591 --- linux-3.7/fs/proc/stat.c    2012-12-11 15:47:36.000000000 +0000
6592 +++ linux-3.7-vs2.3.5.1/fs/proc/stat.c  2012-12-12 13:54:26.000000000 +0000
6593 @@ -9,8 +9,10 @@
6594  #include <linux/slab.h>
6595  #include <linux/time.h>
6596  #include <linux/irqnr.h>
6597 +#include <linux/vserver/cvirt.h>
6598  #include <asm/cputime.h>
6599  #include <linux/tick.h>
6600 +#include <linux/cpuset.h>
6601  
6602  #ifndef arch_irq_stat_cpu
6603  #define arch_irq_stat_cpu(cpu) 0
6604 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6605         u64 sum_softirq = 0;
6606         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6607         struct timespec boottime;
6608 +       cpumask_var_t cpus_allowed;
6609 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6610  
6611         user = nice = system = idle = iowait =
6612                 irq = softirq = steal = 0;
6613         guest = guest_nice = 0;
6614         getboottime(&boottime);
6615 +
6616 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6617 +               vx_vsi_boottime(&boottime);
6618 +
6619 +       if (virt_cpu)
6620 +               cpuset_cpus_allowed(current, cpus_allowed);
6621 +
6622         jif = boottime.tv_sec;
6623  
6624         for_each_possible_cpu(i) {
6625 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6626 +                       continue;
6627 +
6628                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6629                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6630                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6631 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6632         seq_putc(p, '\n');
6633  
6634         for_each_online_cpu(i) {
6635 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6636 +                       continue;
6637 +
6638                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6639                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6640                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6641 diff -NurpP --minimal linux-3.7/fs/proc/uptime.c linux-3.7-vs2.3.5.1/fs/proc/uptime.c
6642 --- linux-3.7/fs/proc/uptime.c  2012-03-19 18:47:26.000000000 +0000
6643 +++ linux-3.7-vs2.3.5.1/fs/proc/uptime.c        2012-12-11 15:56:32.000000000 +0000
6644 @@ -5,6 +5,7 @@
6645  #include <linux/seq_file.h>
6646  #include <linux/time.h>
6647  #include <linux/kernel_stat.h>
6648 +#include <linux/vserver/cvirt.h>
6649  #include <asm/cputime.h>
6650  
6651  static int uptime_proc_show(struct seq_file *m, void *v)
6652 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6653         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6654         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6655         idle.tv_nsec = rem;
6656 +
6657 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6658 +               vx_vsi_uptime(&uptime, &idle);
6659 +
6660         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6661                         (unsigned long) uptime.tv_sec,
6662                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6663 diff -NurpP --minimal linux-3.7/fs/proc_namespace.c linux-3.7-vs2.3.5.1/fs/proc_namespace.c
6664 --- linux-3.7/fs/proc_namespace.c       2012-10-04 13:27:41.000000000 +0000
6665 +++ linux-3.7-vs2.3.5.1/fs/proc_namespace.c     2012-12-11 15:56:32.000000000 +0000
6666 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6667                 { MS_SYNCHRONOUS, ",sync" },
6668                 { MS_DIRSYNC, ",dirsync" },
6669                 { MS_MANDLOCK, ",mand" },
6670 +               { MS_TAGGED, ",tag" },
6671 +               { MS_NOTAGCHECK, ",notagcheck" },
6672                 { 0, NULL }
6673         };
6674         const struct proc_fs_info *fs_infop;
6675 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6676         seq_escape(m, s, " \t\n\\");
6677  }
6678  
6679 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6680 +
6681 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6682 +{
6683 +       struct path root;
6684 +       struct dentry *point;
6685 +       struct mount *mnt = real_mount(vfsmnt);
6686 +       struct mount *root_mnt;
6687 +       int ret;
6688 +
6689 +       if (mnt == mnt->mnt_ns->root)
6690 +               return 1;
6691 +
6692 +       br_read_lock(&vfsmount_lock);
6693 +       root = current->fs->root;
6694 +       root_mnt = real_mount(root.mnt);
6695 +       point = root.dentry;
6696 +
6697 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6698 +               point = mnt->mnt_mountpoint;
6699 +               mnt = mnt->mnt_parent;
6700 +       }
6701 +
6702 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6703 +
6704 +       br_read_unlock(&vfsmount_lock);
6705 +
6706 +       return ret;
6707 +}
6708 +
6709 +#else
6710 +#define        mnt_is_reachable(v)     (1)
6711 +#endif
6712 +
6713  static void show_type(struct seq_file *m, struct super_block *sb)
6714  {
6715         mangle(m, sb->s_type->name);
6716 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6717         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6718         struct super_block *sb = mnt_path.dentry->d_sb;
6719  
6720 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6721 +               return SEQ_SKIP;
6722 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6723 +               return SEQ_SKIP;
6724 +
6725 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6726 +               mnt == current->fs->root.mnt) {
6727 +               seq_puts(m, "/dev/root / ");
6728 +               goto type;
6729 +       }
6730 +
6731         if (sb->s_op->show_devname) {
6732                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6733                 if (err)
6734 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6735         seq_putc(m, ' ');
6736         seq_path(m, &mnt_path, " \t\n\\");
6737         seq_putc(m, ' ');
6738 +type:
6739         show_type(m, sb);
6740         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6741         err = show_sb_opts(m, sb);
6742 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6743         struct path root = p->root;
6744         int err = 0;
6745  
6746 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6747 +               return SEQ_SKIP;
6748 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6749 +               return SEQ_SKIP;
6750 +
6751         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6752                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6753         if (sb->s_op->show_path)
6754 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6755         struct super_block *sb = mnt_path.dentry->d_sb;
6756         int err = 0;
6757  
6758 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6759 +               return SEQ_SKIP;
6760 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6761 +               return SEQ_SKIP;
6762 +
6763 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6764 +               mnt == current->fs->root.mnt) {
6765 +               seq_puts(m, "device /dev/root mounted on / ");
6766 +               goto type;
6767 +       }
6768 +
6769         /* device */
6770         if (sb->s_op->show_devname) {
6771                 seq_puts(m, "device ");
6772 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6773         seq_puts(m, " mounted on ");
6774         seq_path(m, &mnt_path, " \t\n\\");
6775         seq_putc(m, ' ');
6776 -
6777 +type:
6778         /* file system type */
6779         seq_puts(m, "with fstype ");
6780         show_type(m, sb);
6781 diff -NurpP --minimal linux-3.7/fs/quota/dquot.c linux-3.7-vs2.3.5.1/fs/quota/dquot.c
6782 --- linux-3.7/fs/quota/dquot.c  2012-12-11 15:47:36.000000000 +0000
6783 +++ linux-3.7-vs2.3.5.1/fs/quota/dquot.c        2012-12-11 15:56:32.000000000 +0000
6784 @@ -1582,6 +1582,9 @@ int __dquot_alloc_space(struct inode *in
6785         struct dquot **dquots = inode->i_dquot;
6786         int reserve = flags & DQUOT_SPACE_RESERVE;
6787  
6788 +       if ((ret = dl_alloc_space(inode, number)))
6789 +               return ret;
6790 +
6791         /*
6792          * First test before acquiring mutex - solves deadlocks when we
6793          * re-enter the quota code and are already holding the mutex
6794 @@ -1637,6 +1640,9 @@ int dquot_alloc_inode(const struct inode
6795         struct dquot_warn warn[MAXQUOTAS];
6796         struct dquot * const *dquots = inode->i_dquot;
6797  
6798 +       if ((ret = dl_alloc_inode(inode)))
6799 +               return ret;
6800 +
6801         /* First test before acquiring mutex - solves deadlocks when we
6802           * re-enter the quota code and are already holding the mutex */
6803         if (!dquot_active(inode))
6804 @@ -1708,6 +1714,8 @@ void __dquot_free_space(struct inode *in
6805         struct dquot **dquots = inode->i_dquot;
6806         int reserve = flags & DQUOT_SPACE_RESERVE;
6807  
6808 +       dl_free_space(inode, number);
6809 +
6810         /* First test before acquiring mutex - solves deadlocks when we
6811           * re-enter the quota code and are already holding the mutex */
6812         if (!dquot_active(inode)) {
6813 @@ -1752,6 +1760,8 @@ void dquot_free_inode(const struct inode
6814         struct dquot_warn warn[MAXQUOTAS];
6815         struct dquot * const *dquots = inode->i_dquot;
6816  
6817 +       dl_free_inode(inode);
6818 +
6819         /* First test before acquiring mutex - solves deadlocks when we
6820           * re-enter the quota code and are already holding the mutex */
6821         if (!dquot_active(inode))
6822 diff -NurpP --minimal linux-3.7/fs/quota/quota.c linux-3.7-vs2.3.5.1/fs/quota/quota.c
6823 --- linux-3.7/fs/quota/quota.c  2012-12-11 15:47:36.000000000 +0000
6824 +++ linux-3.7-vs2.3.5.1/fs/quota/quota.c        2012-12-11 22:07:44.000000000 +0000
6825 @@ -8,6 +8,7 @@
6826  #include <linux/fs.h>
6827  #include <linux/namei.h>
6828  #include <linux/slab.h>
6829 +#include <linux/vs_context.h>
6830  #include <asm/current.h>
6831  #include <linux/uaccess.h>
6832  #include <linux/kernel.h>
6833 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6834                         break;
6835                 /*FALLTHROUGH*/
6836         default:
6837 -               if (!capable(CAP_SYS_ADMIN))
6838 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6839                         return -EPERM;
6840         }
6841  
6842 @@ -307,6 +308,46 @@ static int do_quotactl(struct super_bloc
6843         }
6844  }
6845  
6846 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6847 +
6848 +#include <linux/vroot.h>
6849 +#include <linux/major.h>
6850 +#include <linux/module.h>
6851 +#include <linux/kallsyms.h>
6852 +#include <linux/vserver/debug.h>
6853 +
6854 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6855 +
6856 +static DEFINE_SPINLOCK(vroot_grb_lock);
6857 +
6858 +int register_vroot_grb(vroot_grb_func *func) {
6859 +       int ret = -EBUSY;
6860 +
6861 +       spin_lock(&vroot_grb_lock);
6862 +       if (!vroot_get_real_bdev) {
6863 +               vroot_get_real_bdev = func;
6864 +               ret = 0;
6865 +       }
6866 +       spin_unlock(&vroot_grb_lock);
6867 +       return ret;
6868 +}
6869 +EXPORT_SYMBOL(register_vroot_grb);
6870 +
6871 +int unregister_vroot_grb(vroot_grb_func *func) {
6872 +       int ret = -EINVAL;
6873 +
6874 +       spin_lock(&vroot_grb_lock);
6875 +       if (vroot_get_real_bdev) {
6876 +               vroot_get_real_bdev = NULL;
6877 +               ret = 0;
6878 +       }
6879 +       spin_unlock(&vroot_grb_lock);
6880 +       return ret;
6881 +}
6882 +EXPORT_SYMBOL(unregister_vroot_grb);
6883 +
6884 +#endif
6885 +
6886  /* Return 1 if 'cmd' will block on frozen filesystem */
6887  static int quotactl_cmd_write(int cmd)
6888  {
6889 @@ -339,6 +380,22 @@ static struct super_block *quotactl_bloc
6890         putname(tmp);
6891         if (IS_ERR(bdev))
6892                 return ERR_CAST(bdev);
6893 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6894 +       if (bdev && bdev->bd_inode &&
6895 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6896 +               struct block_device *bdnew = (void *)-EINVAL;
6897 +
6898 +               if (vroot_get_real_bdev)
6899 +                       bdnew = vroot_get_real_bdev(bdev);
6900 +               else
6901 +                       vxdprintk(VXD_CBIT(misc, 0),
6902 +                                       "vroot_get_real_bdev not set");
6903 +               bdput(bdev);
6904 +               if (IS_ERR(bdnew))
6905 +                       return ERR_PTR(PTR_ERR(bdnew));
6906 +               bdev = bdnew;
6907 +       }
6908 +#endif
6909         if (quotactl_cmd_write(cmd))
6910                 sb = get_super_thawed(bdev);
6911         else
6912 diff -NurpP --minimal linux-3.7/fs/stat.c linux-3.7-vs2.3.5.1/fs/stat.c
6913 --- linux-3.7/fs/stat.c 2012-12-11 15:47:36.000000000 +0000
6914 +++ linux-3.7-vs2.3.5.1/fs/stat.c       2012-12-11 15:56:32.000000000 +0000
6915 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6916         stat->nlink = inode->i_nlink;
6917         stat->uid = inode->i_uid;
6918         stat->gid = inode->i_gid;
6919 +       stat->tag = inode->i_tag;
6920         stat->rdev = inode->i_rdev;
6921         stat->size = i_size_read(inode);
6922         stat->atime = inode->i_atime;
6923 diff -NurpP --minimal linux-3.7/fs/statfs.c linux-3.7-vs2.3.5.1/fs/statfs.c
6924 --- linux-3.7/fs/statfs.c       2012-12-11 15:47:36.000000000 +0000
6925 +++ linux-3.7-vs2.3.5.1/fs/statfs.c     2012-12-11 15:56:32.000000000 +0000
6926 @@ -7,6 +7,8 @@
6927  #include <linux/statfs.h>
6928  #include <linux/security.h>
6929  #include <linux/uaccess.h>
6930 +#include <linux/vs_base.h>
6931 +#include <linux/vs_dlimit.h>
6932  #include "internal.h"
6933  
6934  static int flags_by_mnt(int mnt_flags)
6935 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6936         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6937         if (retval == 0 && buf->f_frsize == 0)
6938                 buf->f_frsize = buf->f_bsize;
6939 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6940 +               vx_vsi_statfs(dentry->d_sb, buf);
6941         return retval;
6942  }
6943  
6944 diff -NurpP --minimal linux-3.7/fs/super.c linux-3.7-vs2.3.5.1/fs/super.c
6945 --- linux-3.7/fs/super.c        2012-12-11 15:47:36.000000000 +0000
6946 +++ linux-3.7-vs2.3.5.1/fs/super.c      2012-12-11 15:56:32.000000000 +0000
6947 @@ -34,6 +34,8 @@
6948  #include <linux/cleancache.h>
6949  #include <linux/fsnotify.h>
6950  #include <linux/lockdep.h>
6951 +#include <linux/magic.h>
6952 +#include <linux/vs_context.h>
6953  #include "internal.h"
6954  
6955  
6956 @@ -1119,6 +1121,13 @@ mount_fs(struct file_system_type *type,
6957         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6958         sb->s_flags |= MS_BORN;
6959  
6960 +       error = -EPERM;
6961 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6962 +               !sb->s_bdev &&
6963 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6964 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6965 +               goto out_sb;
6966 +
6967         error = security_sb_kern_mount(sb, flags, secdata);
6968         if (error)
6969                 goto out_sb;
6970 diff -NurpP --minimal linux-3.7/fs/sysfs/mount.c linux-3.7-vs2.3.5.1/fs/sysfs/mount.c
6971 --- linux-3.7/fs/sysfs/mount.c  2012-10-04 13:27:41.000000000 +0000
6972 +++ linux-3.7-vs2.3.5.1/fs/sysfs/mount.c        2012-12-11 15:56:32.000000000 +0000
6973 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
6974  
6975         sb->s_blocksize = PAGE_CACHE_SIZE;
6976         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6977 -       sb->s_magic = SYSFS_MAGIC;
6978 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6979         sb->s_op = &sysfs_ops;
6980         sb->s_time_gran = 1;
6981  
6982 diff -NurpP --minimal linux-3.7/fs/utimes.c linux-3.7-vs2.3.5.1/fs/utimes.c
6983 --- linux-3.7/fs/utimes.c       2012-12-11 15:47:37.000000000 +0000
6984 +++ linux-3.7-vs2.3.5.1/fs/utimes.c     2012-12-11 15:56:32.000000000 +0000
6985 @@ -8,6 +8,8 @@
6986  #include <linux/stat.h>
6987  #include <linux/utime.h>
6988  #include <linux/syscalls.h>
6989 +#include <linux/mount.h>
6990 +#include <linux/vs_cowbl.h>
6991  #include <asm/uaccess.h>
6992  #include <asm/unistd.h>
6993  
6994 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6995  {
6996         int error;
6997         struct iattr newattrs;
6998 -       struct inode *inode = path->dentry->d_inode;
6999 +       struct inode *inode;
7000  
7001         error = mnt_want_write(path->mnt);
7002         if (error)
7003                 goto out;
7004  
7005 +       error = cow_check_and_break(path);
7006 +       if (error)
7007 +               goto mnt_drop_write_and_out;
7008 +
7009 +       inode = path->dentry->d_inode;
7010 +
7011         if (times && times[0].tv_nsec == UTIME_NOW &&
7012                      times[1].tv_nsec == UTIME_NOW)
7013                 times = NULL;
7014 diff -NurpP --minimal linux-3.7/fs/xattr.c linux-3.7-vs2.3.5.1/fs/xattr.c
7015 --- linux-3.7/fs/xattr.c        2012-12-11 15:47:37.000000000 +0000
7016 +++ linux-3.7-vs2.3.5.1/fs/xattr.c      2012-12-11 17:16:31.000000000 +0000
7017 @@ -21,6 +21,7 @@
7018  #include <linux/audit.h>
7019  #include <linux/vmalloc.h>
7020  #include <linux/posix_acl_xattr.h>
7021 +#include <linux/mount.h>
7022  
7023  #include <asm/uaccess.h>
7024  
7025 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
7026          * The trusted.* namespace can only be accessed by privileged users.
7027          */
7028         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7029 -               if (!capable(CAP_SYS_ADMIN))
7030 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7031                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7032                 return 0;
7033         }
7034 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_dinode.h linux-3.7-vs2.3.5.1/fs/xfs/xfs_dinode.h
7035 --- linux-3.7/fs/xfs/xfs_dinode.h       2012-10-04 13:27:44.000000000 +0000
7036 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_dinode.h     2012-12-11 15:56:32.000000000 +0000
7037 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7038         __be32          di_nlink;       /* number of links to file */
7039         __be16          di_projid_lo;   /* lower part of owner's project id */
7040         __be16          di_projid_hi;   /* higher part owner's project id */
7041 -       __u8            di_pad[6];      /* unused, zeroed space */
7042 +       __u8            di_pad[2];      /* unused, zeroed space */
7043 +       __be16          di_tag;         /* context tagging */
7044 +       __be16          di_vflags;      /* vserver specific flags */
7045         __be16          di_flushiter;   /* incremented on flush */
7046         xfs_timestamp_t di_atime;       /* time last accessed */
7047         xfs_timestamp_t di_mtime;       /* time last modified */
7048 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7049  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7050  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7051  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7052 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7053 +
7054  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7055  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7056  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7057 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7058  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7059  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7060  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7061 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7062  
7063  #ifdef CONFIG_XFS_RT
7064  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7065 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7066          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7067          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7068          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7069 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7070 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7071 +        XFS_DIFLAG_IXUNLINK)
7072 +
7073 +#define XFS_DIVFLAG_BARRIER    0x01
7074 +#define XFS_DIVFLAG_COW                0x02
7075  
7076  #endif /* __XFS_DINODE_H__ */
7077 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_fs.h linux-3.7-vs2.3.5.1/fs/xfs/xfs_fs.h
7078 --- linux-3.7/fs/xfs/xfs_fs.h   2011-10-24 16:45:31.000000000 +0000
7079 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_fs.h 2012-12-11 15:56:32.000000000 +0000
7080 @@ -67,6 +67,9 @@ struct fsxattr {
7081  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7082  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7083  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7084 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7085 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7086 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7087  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7088  
7089  /*
7090 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7091  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7092         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7093         __u16           bs_projid_hi;   /* higher part of project id    */
7094 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7095 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7096 +       __u16           bs_tag;         /* context tagging              */
7097         __u32           bs_dmevmask;    /* DMIG event mask              */
7098         __u16           bs_dmstate;     /* DMIG state info              */
7099         __u16           bs_aextents;    /* attribute number of extents  */
7100 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_ialloc.c linux-3.7-vs2.3.5.1/fs/xfs/xfs_ialloc.c
7101 --- linux-3.7/fs/xfs/xfs_ialloc.c       2012-12-11 15:47:37.000000000 +0000
7102 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_ialloc.c     2012-12-11 15:56:32.000000000 +0000
7103 @@ -37,7 +37,6 @@
7104  #include "xfs_error.h"
7105  #include "xfs_bmap.h"
7106  
7107 -
7108  /*
7109   * Allocation group level functions.
7110   */
7111 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_inode.c linux-3.7-vs2.3.5.1/fs/xfs/xfs_inode.c
7112 --- linux-3.7/fs/xfs/xfs_inode.c        2012-12-11 15:47:37.000000000 +0000
7113 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_inode.c      2012-12-11 22:20:23.000000000 +0000
7114 @@ -16,6 +16,7 @@
7115   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7116   */
7117  #include <linux/log2.h>
7118 +#include <linux/vs_tag.h>
7119  
7120  #include "xfs.h"
7121  #include "xfs_fs.h"
7122 @@ -563,15 +564,25 @@ xfs_iformat_btree(
7123  STATIC void
7124  xfs_dinode_from_disk(
7125         xfs_icdinode_t          *to,
7126 -       xfs_dinode_t            *from)
7127 +       xfs_dinode_t            *from,
7128 +       int                     tagged)
7129  {
7130 +       uint32_t uid, gid, tag;
7131 +
7132         to->di_magic = be16_to_cpu(from->di_magic);
7133         to->di_mode = be16_to_cpu(from->di_mode);
7134         to->di_version = from ->di_version;
7135         to->di_format = from->di_format;
7136         to->di_onlink = be16_to_cpu(from->di_onlink);
7137 -       to->di_uid = be32_to_cpu(from->di_uid);
7138 -       to->di_gid = be32_to_cpu(from->di_gid);
7139 +
7140 +       uid = be32_to_cpu(from->di_uid);
7141 +       gid = be32_to_cpu(from->di_gid);
7142 +       tag = be16_to_cpu(from->di_tag);
7143 +
7144 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7145 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7146 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7147 +
7148         to->di_nlink = be32_to_cpu(from->di_nlink);
7149         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7150         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7151 @@ -593,21 +604,26 @@ xfs_dinode_from_disk(
7152         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7153         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7154         to->di_flags    = be16_to_cpu(from->di_flags);
7155 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7156         to->di_gen      = be32_to_cpu(from->di_gen);
7157  }
7158  
7159  void
7160  xfs_dinode_to_disk(
7161         xfs_dinode_t            *to,
7162 -       xfs_icdinode_t          *from)
7163 +       xfs_icdinode_t          *from,
7164 +       int                     tagged)
7165  {
7166         to->di_magic = cpu_to_be16(from->di_magic);
7167         to->di_mode = cpu_to_be16(from->di_mode);
7168         to->di_version = from ->di_version;
7169         to->di_format = from->di_format;
7170         to->di_onlink = cpu_to_be16(from->di_onlink);
7171 -       to->di_uid = cpu_to_be32(from->di_uid);
7172 -       to->di_gid = cpu_to_be32(from->di_gid);
7173 +
7174 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7175 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7176 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7177 +
7178         to->di_nlink = cpu_to_be32(from->di_nlink);
7179         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7180         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7181 @@ -629,12 +645,14 @@ xfs_dinode_to_disk(
7182         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7183         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7184         to->di_flags = cpu_to_be16(from->di_flags);
7185 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7186         to->di_gen = cpu_to_be32(from->di_gen);
7187  }
7188  
7189  STATIC uint
7190  _xfs_dic2xflags(
7191 -       __uint16_t              di_flags)
7192 +       __uint16_t              di_flags,
7193 +       __uint16_t              di_vflags)
7194  {
7195         uint                    flags = 0;
7196  
7197 @@ -645,6 +663,8 @@ _xfs_dic2xflags(
7198                         flags |= XFS_XFLAG_PREALLOC;
7199                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7200                         flags |= XFS_XFLAG_IMMUTABLE;
7201 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7202 +                       flags |= XFS_XFLAG_IXUNLINK;
7203                 if (di_flags & XFS_DIFLAG_APPEND)
7204                         flags |= XFS_XFLAG_APPEND;
7205                 if (di_flags & XFS_DIFLAG_SYNC)
7206 @@ -669,6 +689,10 @@ _xfs_dic2xflags(
7207                         flags |= XFS_XFLAG_FILESTREAM;
7208         }
7209  
7210 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7211 +               flags |= FS_BARRIER_FL;
7212 +       if (di_vflags & XFS_DIVFLAG_COW)
7213 +               flags |= FS_COW_FL;
7214         return flags;
7215  }
7216  
7217 @@ -678,7 +702,7 @@ xfs_ip2xflags(
7218  {
7219         xfs_icdinode_t          *dic = &ip->i_d;
7220  
7221 -       return _xfs_dic2xflags(dic->di_flags) |
7222 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7223                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7224  }
7225  
7226 @@ -686,7 +710,8 @@ uint
7227  xfs_dic2xflags(
7228         xfs_dinode_t            *dip)
7229  {
7230 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7231 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7232 +                               be16_to_cpu(dip->di_vflags)) |
7233                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7234  }
7235  
7236 @@ -740,7 +765,8 @@ xfs_iread(
7237          * Otherwise, just get the truly permanent information.
7238          */
7239         if (dip->di_mode) {
7240 -               xfs_dinode_from_disk(&ip->i_d, dip);
7241 +               xfs_dinode_from_disk(&ip->i_d, dip,
7242 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7243                 error = xfs_iformat(ip, dip);
7244                 if (error)  {
7245  #ifdef DEBUG
7246 @@ -927,6 +953,7 @@ xfs_ialloc(
7247         ASSERT(ip->i_d.di_nlink == nlink);
7248         ip->i_d.di_uid = current_fsuid();
7249         ip->i_d.di_gid = current_fsgid();
7250 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7251         xfs_set_projid(ip, prid);
7252         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7253  
7254 @@ -986,6 +1013,7 @@ xfs_ialloc(
7255         ip->i_d.di_dmevmask = 0;
7256         ip->i_d.di_dmstate = 0;
7257         ip->i_d.di_flags = 0;
7258 +       ip->i_d.di_vflags = 0;
7259         flags = XFS_ILOG_CORE;
7260         switch (mode & S_IFMT) {
7261         case S_IFIFO:
7262 @@ -1668,6 +1696,7 @@ xfs_ifree(
7263         }
7264         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7265         ip->i_d.di_flags = 0;
7266 +       ip->i_d.di_vflags = 0;
7267         ip->i_d.di_dmevmask = 0;
7268         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7269         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7270 @@ -1834,7 +1863,6 @@ xfs_iroot_realloc(
7271         return;
7272  }
7273  
7274 -
7275  /*
7276   * This is called when the amount of space needed for if_data
7277   * is increased or decreased.  The change in size is indicated by
7278 @@ -2522,7 +2550,8 @@ xfs_iflush_int(
7279          * because if the inode is dirty at all the core must
7280          * be.
7281          */
7282 -       xfs_dinode_to_disk(dip, &ip->i_d);
7283 +       xfs_dinode_to_disk(dip, &ip->i_d,
7284 +               mp->m_flags & XFS_MOUNT_TAGGED);
7285  
7286         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7287         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7288 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_inode.h linux-3.7-vs2.3.5.1/fs/xfs/xfs_inode.h
7289 --- linux-3.7/fs/xfs/xfs_inode.h        2012-10-04 13:27:44.000000000 +0000
7290 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_inode.h      2012-12-11 15:56:32.000000000 +0000
7291 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7292         __uint32_t      di_nlink;       /* number of links to file */
7293         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7294         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7295 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7296 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7297 +       __uint16_t      di_tag;         /* context tagging */
7298 +       __uint16_t      di_vflags;      /* vserver specific flags */
7299         __uint16_t      di_flushiter;   /* incremented on flush */
7300         xfs_ictimestamp_t di_atime;     /* time last accessed */
7301         xfs_ictimestamp_t di_mtime;     /* time last modified */
7302 @@ -561,7 +563,7 @@ int         xfs_imap_to_bp(struct xfs_mount *,
7303  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7304                           struct xfs_inode *, uint);
7305  void           xfs_dinode_to_disk(struct xfs_dinode *,
7306 -                                  struct xfs_icdinode *);
7307 +                                  struct xfs_icdinode *, int);
7308  void           xfs_idestroy_fork(struct xfs_inode *, int);
7309  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7310  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7311 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_ioctl.c linux-3.7-vs2.3.5.1/fs/xfs/xfs_ioctl.c
7312 --- linux-3.7/fs/xfs/xfs_ioctl.c        2012-12-11 15:47:37.000000000 +0000
7313 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_ioctl.c      2012-12-11 15:56:32.000000000 +0000
7314 @@ -26,7 +26,7 @@
7315  #include "xfs_bmap_btree.h"
7316  #include "xfs_dinode.h"
7317  #include "xfs_inode.h"
7318 -#include "xfs_ioctl.h"
7319 +// #include "xfs_ioctl.h"
7320  #include "xfs_rtalloc.h"
7321  #include "xfs_itable.h"
7322  #include "xfs_error.h"
7323 @@ -762,6 +762,10 @@ xfs_merge_ioc_xflags(
7324                 xflags |= XFS_XFLAG_IMMUTABLE;
7325         else
7326                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7327 +       if (flags & FS_IXUNLINK_FL)
7328 +               xflags |= XFS_XFLAG_IXUNLINK;
7329 +       else
7330 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7331         if (flags & FS_APPEND_FL)
7332                 xflags |= XFS_XFLAG_APPEND;
7333         else
7334 @@ -790,6 +794,8 @@ xfs_di2lxflags(
7335  
7336         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7337                 flags |= FS_IMMUTABLE_FL;
7338 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7339 +               flags |= FS_IXUNLINK_FL;
7340         if (di_flags & XFS_DIFLAG_APPEND)
7341                 flags |= FS_APPEND_FL;
7342         if (di_flags & XFS_DIFLAG_SYNC)
7343 @@ -850,6 +856,8 @@ xfs_set_diflags(
7344         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7345         if (xflags & XFS_XFLAG_IMMUTABLE)
7346                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7347 +       if (xflags & XFS_XFLAG_IXUNLINK)
7348 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7349         if (xflags & XFS_XFLAG_APPEND)
7350                 di_flags |= XFS_DIFLAG_APPEND;
7351         if (xflags & XFS_XFLAG_SYNC)
7352 @@ -892,6 +900,10 @@ xfs_diflags_to_linux(
7353                 inode->i_flags |= S_IMMUTABLE;
7354         else
7355                 inode->i_flags &= ~S_IMMUTABLE;
7356 +       if (xflags & XFS_XFLAG_IXUNLINK)
7357 +               inode->i_flags |= S_IXUNLINK;
7358 +       else
7359 +               inode->i_flags &= ~S_IXUNLINK;
7360         if (xflags & XFS_XFLAG_APPEND)
7361                 inode->i_flags |= S_APPEND;
7362         else
7363 @@ -1396,10 +1408,18 @@ xfs_file_ioctl(
7364         case XFS_IOC_FSGETXATTRA:
7365                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7366         case XFS_IOC_FSSETXATTR:
7367 +               if (IS_BARRIER(inode)) {
7368 +                       vxwprintk_task(1, "messing with the barrier.");
7369 +                       return -XFS_ERROR(EACCES);
7370 +               }
7371                 return xfs_ioc_fssetxattr(ip, filp, arg);
7372         case XFS_IOC_GETXFLAGS:
7373                 return xfs_ioc_getxflags(ip, arg);
7374         case XFS_IOC_SETXFLAGS:
7375 +               if (IS_BARRIER(inode)) {
7376 +                       vxwprintk_task(1, "messing with the barrier.");
7377 +                       return -XFS_ERROR(EACCES);
7378 +               }
7379                 return xfs_ioc_setxflags(ip, filp, arg);
7380  
7381         case XFS_IOC_FSSETDM: {
7382 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_ioctl.h linux-3.7-vs2.3.5.1/fs/xfs/xfs_ioctl.h
7383 --- linux-3.7/fs/xfs/xfs_ioctl.h        2011-10-24 16:45:31.000000000 +0000
7384 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_ioctl.h      2012-12-11 15:56:32.000000000 +0000
7385 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7386         void __user             *uhandle,
7387         u32                     hlen);
7388  
7389 +extern int
7390 +xfs_sync_flags(
7391 +       struct inode            *inode,
7392 +       int                     flags,
7393 +       int                     vflags);
7394 +
7395  extern long
7396  xfs_file_ioctl(
7397         struct file             *filp,
7398 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_iops.c linux-3.7-vs2.3.5.1/fs/xfs/xfs_iops.c
7399 --- linux-3.7/fs/xfs/xfs_iops.c 2012-10-04 13:27:44.000000000 +0000
7400 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_iops.c       2012-12-11 15:56:32.000000000 +0000
7401 @@ -28,6 +28,7 @@
7402  #include "xfs_bmap_btree.h"
7403  #include "xfs_dinode.h"
7404  #include "xfs_inode.h"
7405 +#include "xfs_ioctl.h"
7406  #include "xfs_bmap.h"
7407  #include "xfs_rtalloc.h"
7408  #include "xfs_error.h"
7409 @@ -46,6 +47,7 @@
7410  #include <linux/security.h>
7411  #include <linux/fiemap.h>
7412  #include <linux/slab.h>
7413 +#include <linux/vs_tag.h>
7414  
7415  static int
7416  xfs_initxattrs(
7417 @@ -421,6 +423,7 @@ xfs_vn_getattr(
7418         stat->nlink = ip->i_d.di_nlink;
7419         stat->uid = ip->i_d.di_uid;
7420         stat->gid = ip->i_d.di_gid;
7421 +       stat->tag = ip->i_d.di_tag;
7422         stat->ino = ip->i_ino;
7423         stat->atime = inode->i_atime;
7424         stat->mtime = inode->i_mtime;
7425 @@ -1033,6 +1036,7 @@ static const struct inode_operations xfs
7426         .listxattr              = xfs_vn_listxattr,
7427         .fiemap                 = xfs_vn_fiemap,
7428         .update_time            = xfs_vn_update_time,
7429 +       .sync_flags             = xfs_sync_flags,
7430  };
7431  
7432  static const struct inode_operations xfs_dir_inode_operations = {
7433 @@ -1059,6 +1063,7 @@ static const struct inode_operations xfs
7434         .removexattr            = generic_removexattr,
7435         .listxattr              = xfs_vn_listxattr,
7436         .update_time            = xfs_vn_update_time,
7437 +       .sync_flags             = xfs_sync_flags,
7438  };
7439  
7440  static const struct inode_operations xfs_dir_ci_inode_operations = {
7441 @@ -1110,6 +1115,10 @@ xfs_diflags_to_iflags(
7442                 inode->i_flags |= S_IMMUTABLE;
7443         else
7444                 inode->i_flags &= ~S_IMMUTABLE;
7445 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7446 +               inode->i_flags |= S_IXUNLINK;
7447 +       else
7448 +               inode->i_flags &= ~S_IXUNLINK;
7449         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7450                 inode->i_flags |= S_APPEND;
7451         else
7452 @@ -1122,6 +1131,15 @@ xfs_diflags_to_iflags(
7453                 inode->i_flags |= S_NOATIME;
7454         else
7455                 inode->i_flags &= ~S_NOATIME;
7456 +
7457 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7458 +               inode->i_vflags |= V_BARRIER;
7459 +       else
7460 +               inode->i_vflags &= ~V_BARRIER;
7461 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7462 +               inode->i_vflags |= V_COW;
7463 +       else
7464 +               inode->i_vflags &= ~V_COW;
7465  }
7466  
7467  /*
7468 @@ -1153,6 +1171,7 @@ xfs_setup_inode(
7469         set_nlink(inode, ip->i_d.di_nlink);
7470         inode->i_uid    = ip->i_d.di_uid;
7471         inode->i_gid    = ip->i_d.di_gid;
7472 +       inode->i_tag    = ip->i_d.di_tag;
7473  
7474         switch (inode->i_mode & S_IFMT) {
7475         case S_IFBLK:
7476 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_itable.c linux-3.7-vs2.3.5.1/fs/xfs/xfs_itable.c
7477 --- linux-3.7/fs/xfs/xfs_itable.c       2012-10-04 13:27:44.000000000 +0000
7478 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_itable.c     2012-12-11 15:56:32.000000000 +0000
7479 @@ -96,6 +96,7 @@ xfs_bulkstat_one_int(
7480         buf->bs_mode = dic->di_mode;
7481         buf->bs_uid = dic->di_uid;
7482         buf->bs_gid = dic->di_gid;
7483 +       buf->bs_tag = dic->di_tag;
7484         buf->bs_size = dic->di_size;
7485         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7486         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7487 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_linux.h linux-3.7-vs2.3.5.1/fs/xfs/xfs_linux.h
7488 --- linux-3.7/fs/xfs/xfs_linux.h        2011-10-24 16:45:31.000000000 +0000
7489 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_linux.h      2012-12-11 15:56:32.000000000 +0000
7490 @@ -121,6 +121,7 @@
7491  
7492  #define current_cpu()          (raw_smp_processor_id())
7493  #define current_pid()          (current->pid)
7494 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7495  #define current_test_flags(f)  (current->flags & (f))
7496  #define current_set_flags_nested(sp, f)                \
7497                 (*(sp) = current->flags, current->flags |= (f))
7498 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_log_recover.c linux-3.7-vs2.3.5.1/fs/xfs/xfs_log_recover.c
7499 --- linux-3.7/fs/xfs/xfs_log_recover.c  2012-12-11 15:47:37.000000000 +0000
7500 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_log_recover.c        2012-12-11 15:56:32.000000000 +0000
7501 @@ -2359,7 +2359,8 @@ xlog_recover_inode_pass2(
7502         }
7503  
7504         /* The core is in in-core format */
7505 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7506 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7507 +               mp->m_flags & XFS_MOUNT_TAGGED);
7508  
7509         /* the rest is in on-disk format */
7510         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7511 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_mount.h linux-3.7-vs2.3.5.1/fs/xfs/xfs_mount.h
7512 --- linux-3.7/fs/xfs/xfs_mount.h        2012-12-11 15:47:37.000000000 +0000
7513 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_mount.h      2012-12-11 15:56:32.000000000 +0000
7514 @@ -246,6 +246,7 @@ typedef struct xfs_mount {
7515                                                    allocator */
7516  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7517  
7518 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7519  
7520  /*
7521   * Default minimum read and write sizes.
7522 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_super.c linux-3.7-vs2.3.5.1/fs/xfs/xfs_super.c
7523 --- linux-3.7/fs/xfs/xfs_super.c        2012-12-11 15:47:37.000000000 +0000
7524 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_super.c      2012-12-11 17:36:47.000000000 +0000
7525 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7526  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7527  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7528  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7529 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7530 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7531 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7532  
7533  /*
7534   * Table driven mount option parser.
7535 @@ -126,6 +129,8 @@ enum {
7536         Opt_nobarrier,
7537         Opt_inode64,
7538         Opt_inode32,
7539 +       Opt_tag,
7540 +       Opt_notag,
7541         Opt_err
7542  };
7543  
7544 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7545         {Opt_nobarrier, "nobarrier"},
7546         {Opt_inode64, "inode64"},
7547         {Opt_inode32, "inode32"},
7548 +       {Opt_tag, "tagxid"},
7549 +       {Opt_tag, "tag"},
7550 +       {Opt_notag, "notag"},
7551         {Opt_err, NULL}
7552  };
7553  
7554 @@ -383,6 +391,19 @@ xfs_parseargs(
7555                 } else if (!strcmp(this_char, "irixsgid")) {
7556                         xfs_warn(mp,
7557         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7558 +#ifndef CONFIG_TAGGING_NONE
7559 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7560 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7561 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7562 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7563 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7564 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7565 +#endif
7566 +#ifdef CONFIG_PROPAGATE
7567 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7568 +                       /* use value */
7569 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7570 +#endif
7571                 } else {
7572                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7573                         return EINVAL;
7574 @@ -1149,6 +1170,16 @@ xfs_fs_remount(
7575                 case Opt_inode32:
7576                         mp->m_maxagi = xfs_set_inode32(mp);
7577                         break;
7578 +               case Opt_tag:
7579 +                       if (!(sb->s_flags & MS_TAGGED)) {
7580 +                               printk(KERN_INFO
7581 +                                       "XFS: %s: tagging not permitted on remount.\n",
7582 +                                       sb->s_id);
7583 +                               return -EINVAL;
7584 +                       }
7585 +                       break;
7586 +               case Opt_notag:
7587 +                       break;
7588                 default:
7589                         /*
7590                          * Logically we would return an error here to prevent
7591 @@ -1368,6 +1399,9 @@ xfs_fs_fill_super(
7592         if (error)
7593                 goto out_free_sb;
7594  
7595 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7596 +               sb->s_flags |= MS_TAGGED;
7597 +
7598         /*
7599          * we must configure the block size in the superblock before we run the
7600          * full mount process as the mount process can lookup and cache inodes.
7601 diff -NurpP --minimal linux-3.7/fs/xfs/xfs_vnodeops.c linux-3.7-vs2.3.5.1/fs/xfs/xfs_vnodeops.c
7602 --- linux-3.7/fs/xfs/xfs_vnodeops.c     2012-10-04 13:27:44.000000000 +0000
7603 +++ linux-3.7-vs2.3.5.1/fs/xfs/xfs_vnodeops.c   2012-12-11 15:56:32.000000000 +0000
7604 @@ -103,6 +103,77 @@ xfs_readlink_bmap(
7605         return error;
7606  }
7607  
7608 +
7609 +STATIC void
7610 +xfs_get_inode_flags(
7611 +       xfs_inode_t     *ip)
7612 +{
7613 +       struct inode    *inode = VFS_I(ip);
7614 +       unsigned int    flags = inode->i_flags;
7615 +       unsigned int    vflags = inode->i_vflags;
7616 +
7617 +       if (flags & S_IMMUTABLE)
7618 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7619 +       else
7620 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7621 +       if (flags & S_IXUNLINK)
7622 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7623 +       else
7624 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7625 +
7626 +       if (vflags & V_BARRIER)
7627 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7628 +       else
7629 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7630 +       if (vflags & V_COW)
7631 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7632 +       else
7633 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7634 +}
7635 +
7636 +int
7637 +xfs_sync_flags(
7638 +       struct inode            *inode,
7639 +       int                     flags,
7640 +       int                     vflags)
7641 +{
7642 +       struct xfs_inode        *ip = XFS_I(inode);
7643 +       struct xfs_mount        *mp = ip->i_mount;
7644 +       struct xfs_trans        *tp;
7645 +       unsigned int            lock_flags = 0;
7646 +       int                     code;
7647 +
7648 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7649 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7650 +       if (code)
7651 +               goto error_out;
7652 +
7653 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7654 +       xfs_trans_ijoin(tp, ip, 0);
7655 +
7656 +       inode->i_flags = flags;
7657 +       inode->i_vflags = vflags;
7658 +       xfs_get_inode_flags(ip);
7659 +
7660 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7661 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7662 +
7663 +       XFS_STATS_INC(xs_ig_attrchg);
7664 +
7665 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7666 +               xfs_trans_set_sync(tp);
7667 +       code = xfs_trans_commit(tp, 0);
7668 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7669 +       return code;
7670 +
7671 +error_out:
7672 +       xfs_trans_cancel(tp, 0);
7673 +       if (lock_flags)
7674 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7675 +       return code;
7676 +}
7677 +
7678 +
7679  int
7680  xfs_readlink(
7681         xfs_inode_t     *ip,
7682 diff -NurpP --minimal linux-3.7/include/linux/Kbuild linux-3.7-vs2.3.5.1/include/linux/Kbuild
7683 --- linux-3.7/include/linux/Kbuild      2012-12-11 15:47:38.000000000 +0000
7684 +++ linux-3.7-vs2.3.5.1/include/linux/Kbuild    2012-12-11 16:09:38.000000000 +0000
7685 @@ -3,3 +3,4 @@ header-y += hdlc/
7686  header-y += hsi/
7687  header-y += raid/
7688  header-y += usb/
7689 +header-y += vserver/
7690 diff -NurpP --minimal linux-3.7/include/linux/cred.h linux-3.7-vs2.3.5.1/include/linux/cred.h
7691 --- linux-3.7/include/linux/cred.h      2012-07-22 21:39:43.000000000 +0000
7692 +++ linux-3.7-vs2.3.5.1/include/linux/cred.h    2012-12-11 15:56:32.000000000 +0000
7693 @@ -157,6 +157,7 @@ extern void exit_creds(struct task_struc
7694  extern int copy_creds(struct task_struct *, unsigned long);
7695  extern const struct cred *get_task_cred(struct task_struct *);
7696  extern struct cred *cred_alloc_blank(void);
7697 +extern struct cred *__prepare_creds(const struct cred *);
7698  extern struct cred *prepare_creds(void);
7699  extern struct cred *prepare_exec_creds(void);
7700  extern int commit_creds(struct cred *);
7701 @@ -210,6 +211,31 @@ static inline void validate_process_cred
7702  }
7703  #endif
7704  
7705 +static inline void set_cred_subscribers(struct cred *cred, int n)
7706 +{
7707 +#ifdef CONFIG_DEBUG_CREDENTIALS
7708 +       atomic_set(&cred->subscribers, n);
7709 +#endif
7710 +}
7711 +
7712 +static inline int read_cred_subscribers(const struct cred *cred)
7713 +{
7714 +#ifdef CONFIG_DEBUG_CREDENTIALS
7715 +       return atomic_read(&cred->subscribers);
7716 +#else
7717 +       return 0;
7718 +#endif
7719 +}
7720 +
7721 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7722 +{
7723 +#ifdef CONFIG_DEBUG_CREDENTIALS
7724 +       struct cred *cred = (struct cred *) _cred;
7725 +
7726 +       atomic_add(n, &cred->subscribers);
7727 +#endif
7728 +}
7729 +
7730  /**
7731   * get_new_cred - Get a reference on a new set of credentials
7732   * @cred: The new credentials to reference
7733 diff -NurpP --minimal linux-3.7/include/linux/devpts_fs.h linux-3.7-vs2.3.5.1/include/linux/devpts_fs.h
7734 --- linux-3.7/include/linux/devpts_fs.h 2008-12-24 23:26:37.000000000 +0000
7735 +++ linux-3.7-vs2.3.5.1/include/linux/devpts_fs.h       2012-12-11 15:56:32.000000000 +0000
7736 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7737  
7738  #endif
7739  
7740 -
7741  #endif /* _LINUX_DEVPTS_FS_H */
7742 diff -NurpP --minimal linux-3.7/include/linux/fs.h linux-3.7-vs2.3.5.1/include/linux/fs.h
7743 --- linux-3.7/include/linux/fs.h        2012-12-11 15:47:41.000000000 +0000
7744 +++ linux-3.7-vs2.3.5.1/include/linux/fs.h      2012-12-11 21:23:03.000000000 +0000
7745 @@ -210,6 +210,7 @@ typedef void (dio_iodone_t)(struct kiocb
7746  #define ATTR_KILL_PRIV (1 << 14)
7747  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7748  #define ATTR_TIMES_SET (1 << 16)
7749 +#define ATTR_TAG       (1 << 17)
7750  
7751  /*
7752   * This is the Inode Attributes structure, used for notify_change().  It
7753 @@ -225,6 +226,7 @@ struct iattr {
7754         umode_t         ia_mode;
7755         kuid_t          ia_uid;
7756         kgid_t          ia_gid;
7757 +       ktag_t          ia_tag;
7758         loff_t          ia_size;
7759         struct timespec ia_atime;
7760         struct timespec ia_mtime;
7761 @@ -522,7 +524,9 @@ struct inode {
7762         unsigned short          i_opflags;
7763         kuid_t                  i_uid;
7764         kgid_t                  i_gid;
7765 -       unsigned int            i_flags;
7766 +       ktag_t                  i_tag;
7767 +       unsigned short          i_flags;
7768 +       unsigned short          i_vflags;
7769  
7770  #ifdef CONFIG_FS_POSIX_ACL
7771         struct posix_acl        *i_acl;
7772 @@ -551,6 +555,7 @@ struct inode {
7773                 unsigned int __i_nlink;
7774         };
7775         dev_t                   i_rdev;
7776 +       dev_t                   i_mdev;
7777         loff_t                  i_size;
7778         struct timespec         i_atime;
7779         struct timespec         i_mtime;
7780 @@ -701,6 +706,11 @@ static inline gid_t i_gid_read(const str
7781         return from_kgid(&init_user_ns, inode->i_gid);
7782  }
7783  
7784 +static inline tag_t i_tag_read(const struct inode *inode)
7785 +{
7786 +       return from_ktag(&init_user_ns, inode->i_tag);
7787 +}
7788 +
7789  static inline void i_uid_write(struct inode *inode, uid_t uid)
7790  {
7791         inode->i_uid = make_kuid(&init_user_ns, uid);
7792 @@ -711,14 +721,19 @@ static inline void i_gid_write(struct in
7793         inode->i_gid = make_kgid(&init_user_ns, gid);
7794  }
7795  
7796 +static inline void i_tag_write(struct inode *inode, tag_t tag)
7797 +{
7798 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7799 +}
7800 +
7801  static inline unsigned iminor(const struct inode *inode)
7802  {
7803 -       return MINOR(inode->i_rdev);
7804 +       return MINOR(inode->i_mdev);
7805  }
7806  
7807  static inline unsigned imajor(const struct inode *inode)
7808  {
7809 -       return MAJOR(inode->i_rdev);
7810 +       return MAJOR(inode->i_mdev);
7811  }
7812  
7813  extern struct block_device *I_BDEV(struct inode *inode);
7814 @@ -785,6 +800,7 @@ struct file {
7815         loff_t                  f_pos;
7816         struct fown_struct      f_owner;
7817         const struct cred       *f_cred;
7818 +       xid_t                   f_xid;
7819         struct file_ra_state    f_ra;
7820  
7821         u64                     f_version;
7822 @@ -936,6 +952,7 @@ struct file_lock {
7823         struct file *fl_file;
7824         loff_t fl_start;
7825         loff_t fl_end;
7826 +       xid_t fl_xid;
7827  
7828         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7829         /* for lease breaks: */
7830 @@ -1570,6 +1587,7 @@ struct inode_operations {
7831         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7832         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7833         int (*removexattr) (struct dentry *, const char *);
7834 +       int (*sync_flags) (struct inode *, int, int);
7835         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7836                       u64 len);
7837         int (*update_time)(struct inode *, struct timespec *, int);
7838 @@ -1584,6 +1602,7 @@ ssize_t rw_copy_check_uvector(int type,
7839                               unsigned long nr_segs, unsigned long fast_segs,
7840                               struct iovec *fast_pointer,
7841                               struct iovec **ret_pointer);
7842 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7843  
7844  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7845  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7846 @@ -1637,6 +1656,14 @@ struct super_operations {
7847  #define S_IMA          1024    /* Inode has an associated IMA struct */
7848  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7849  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7850 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7851 +
7852 +/* Linux-VServer related Inode flags */
7853 +
7854 +#define V_VALID                1
7855 +#define V_XATTR                2
7856 +#define V_BARRIER      4       /* Barrier for chroot() */
7857 +#define V_COW          8       /* Copy on Write */
7858  
7859  /*
7860   * Note that nosuid etc flags are inode-specific: setting some file-system
7861 @@ -1661,10 +1688,13 @@ struct super_operations {
7862  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7863  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7864  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7865 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7866  
7867  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7868  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7869  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7870 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7871 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7872  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7873  
7874  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7875 @@ -1675,6 +1705,16 @@ struct super_operations {
7876  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7877  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7878  
7879 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7880 +
7881 +#ifdef CONFIG_VSERVER_COWBL
7882 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7883 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7884 +#else
7885 +#  define IS_COW(inode)                (0)
7886 +#  define IS_COW_LINK(inode)   (0)
7887 +#endif
7888 +
7889  /*
7890   * Inode state bits.  Protected by inode->i_lock
7891   *
7892 @@ -1900,6 +1940,9 @@ extern int rw_verify_area(int, struct fi
7893  extern int locks_mandatory_locked(struct inode *);
7894  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7895  
7896 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7897 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7898 +
7899  /*
7900   * Candidates for mandatory locking have the setgid bit set
7901   * but no group execute bit -  an otherwise meaningless combination.
7902 @@ -2504,6 +2547,7 @@ extern int dcache_dir_open(struct inode
7903  extern int dcache_dir_close(struct inode *, struct file *);
7904  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7905  extern int dcache_readdir(struct file *, void *, filldir_t);
7906 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7907  extern int simple_setattr(struct dentry *, struct iattr *);
7908  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7909  extern int simple_statfs(struct dentry *, struct kstatfs *);
7910 diff -NurpP --minimal linux-3.7/include/linux/init_task.h linux-3.7-vs2.3.5.1/include/linux/init_task.h
7911 --- linux-3.7/include/linux/init_task.h 2012-12-11 15:47:42.000000000 +0000
7912 +++ linux-3.7-vs2.3.5.1/include/linux/init_task.h       2012-12-11 15:56:32.000000000 +0000
7913 @@ -210,6 +210,10 @@ extern struct task_group root_task_group
7914         INIT_TRACE_RECURSION                                            \
7915         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7916         INIT_CPUSET_SEQ                                                 \
7917 +       .xid            = 0,                                            \
7918 +       .vx_info        = NULL,                                         \
7919 +       .nid            = 0,                                            \
7920 +       .nx_info        = NULL,                                         \
7921  }
7922  
7923  
7924 diff -NurpP --minimal linux-3.7/include/linux/ipc.h linux-3.7-vs2.3.5.1/include/linux/ipc.h
7925 --- linux-3.7/include/linux/ipc.h       2012-12-11 15:47:42.000000000 +0000
7926 +++ linux-3.7-vs2.3.5.1/include/linux/ipc.h     2012-12-11 22:24:37.000000000 +0000
7927 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7928         key_t           key;
7929         kuid_t          uid;
7930         kgid_t          gid;
7931 +       xid_t           xid;
7932         kuid_t          cuid;
7933         kgid_t          cgid;
7934         umode_t         mode; 
7935 diff -NurpP --minimal linux-3.7/include/linux/ipc_namespace.h linux-3.7-vs2.3.5.1/include/linux/ipc_namespace.h
7936 --- linux-3.7/include/linux/ipc_namespace.h     2012-07-22 21:39:43.000000000 +0000
7937 +++ linux-3.7-vs2.3.5.1/include/linux/ipc_namespace.h   2012-12-11 15:56:32.000000000 +0000
7938 @@ -133,7 +133,8 @@ static inline int mq_init_ns(struct ipc_
7939  
7940  #if defined(CONFIG_IPC_NS)
7941  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
7942 -                                      struct task_struct *tsk);
7943 +                                      struct ipc_namespace *old_ns,
7944 +                                      struct user_namespace *user_ns);
7945  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
7946  {
7947         if (ns)
7948 @@ -144,12 +145,13 @@ static inline struct ipc_namespace *get_
7949  extern void put_ipc_ns(struct ipc_namespace *ns);
7950  #else
7951  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
7952 -                                             struct task_struct *tsk)
7953 +                                             struct ipc_namespace *old_ns,
7954 +                                             struct user_namespace *user_ns)
7955  {
7956         if (flags & CLONE_NEWIPC)
7957                 return ERR_PTR(-EINVAL);
7958  
7959 -       return tsk->nsproxy->ipc_ns;
7960 +       return old_ns;
7961  }
7962  
7963  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
7964 diff -NurpP --minimal linux-3.7/include/linux/loop.h linux-3.7-vs2.3.5.1/include/linux/loop.h
7965 --- linux-3.7/include/linux/loop.h      2012-12-11 15:47:42.000000000 +0000
7966 +++ linux-3.7-vs2.3.5.1/include/linux/loop.h    2012-12-11 22:34:03.000000000 +0000
7967 @@ -41,6 +41,7 @@ struct loop_device {
7968         struct loop_func_table *lo_encryption;
7969         __u32           lo_init[2];
7970         kuid_t          lo_key_owner;   /* Who set the key */
7971 +       xid_t           lo_xid;
7972         int             (*ioctl)(struct loop_device *, int cmd, 
7973                                  unsigned long arg); 
7974  
7975 diff -NurpP --minimal linux-3.7/include/linux/memcontrol.h linux-3.7-vs2.3.5.1/include/linux/memcontrol.h
7976 --- linux-3.7/include/linux/memcontrol.h        2012-12-11 15:47:42.000000000 +0000
7977 +++ linux-3.7-vs2.3.5.1/include/linux/memcontrol.h      2012-12-11 15:56:32.000000000 +0000
7978 @@ -83,6 +83,13 @@ extern struct mem_cgroup *try_get_mem_cg
7979  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7980  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7981  
7982 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7983 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7984 +
7985 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7986 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7987 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7988 +
7989  static inline
7990  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7991  {
7992 diff -NurpP --minimal linux-3.7/include/linux/mm_types.h linux-3.7-vs2.3.5.1/include/linux/mm_types.h
7993 --- linux-3.7/include/linux/mm_types.h  2012-12-11 15:47:43.000000000 +0000
7994 +++ linux-3.7-vs2.3.5.1/include/linux/mm_types.h        2012-12-11 15:56:32.000000000 +0000
7995 @@ -365,6 +365,7 @@ struct mm_struct {
7996  
7997         /* Architecture-specific MM context */
7998         mm_context_t context;
7999 +       struct vx_info *mm_vx_info;
8000  
8001         unsigned long flags; /* Must use atomic bitops to access the bits */
8002  
8003 diff -NurpP --minimal linux-3.7/include/linux/mmzone.h linux-3.7-vs2.3.5.1/include/linux/mmzone.h
8004 --- linux-3.7/include/linux/mmzone.h    2012-12-11 15:47:43.000000000 +0000
8005 +++ linux-3.7-vs2.3.5.1/include/linux/mmzone.h  2012-12-11 15:56:32.000000000 +0000
8006 @@ -735,6 +735,13 @@ typedef struct pglist_data {
8007         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8008  })
8009  
8010 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8011 +
8012 +#define node_end_pfn(nid) ({\
8013 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8014 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8015 +})
8016 +
8017  #include <linux/memory_hotplug.h>
8018  
8019  extern struct mutex zonelists_mutex;
8020 diff -NurpP --minimal linux-3.7/include/linux/mount.h linux-3.7-vs2.3.5.1/include/linux/mount.h
8021 --- linux-3.7/include/linux/mount.h     2012-03-19 18:47:28.000000000 +0000
8022 +++ linux-3.7-vs2.3.5.1/include/linux/mount.h   2012-12-11 15:56:32.000000000 +0000
8023 @@ -47,6 +47,9 @@ struct mnt_namespace;
8024  
8025  #define MNT_INTERNAL   0x4000
8026  
8027 +#define MNT_TAGID      0x10000
8028 +#define MNT_NOTAG      0x20000
8029 +
8030  struct vfsmount {
8031         struct dentry *mnt_root;        /* root of the mounted tree */
8032         struct super_block *mnt_sb;     /* pointer to superblock */
8033 diff -NurpP --minimal linux-3.7/include/linux/net.h linux-3.7-vs2.3.5.1/include/linux/net.h
8034 --- linux-3.7/include/linux/net.h       2012-12-11 15:47:43.000000000 +0000
8035 +++ linux-3.7-vs2.3.5.1/include/linux/net.h     2012-12-11 15:56:32.000000000 +0000
8036 @@ -38,6 +38,7 @@ struct net;
8037  #define SOCK_PASSCRED          3
8038  #define SOCK_PASSSEC           4
8039  #define SOCK_EXTERNALLY_ALLOCATED 5
8040 +#define SOCK_USER_SOCKET       6
8041  
8042  #ifndef ARCH_HAS_SOCKET_TYPES
8043  /**
8044 diff -NurpP --minimal linux-3.7/include/linux/netdevice.h linux-3.7-vs2.3.5.1/include/linux/netdevice.h
8045 --- linux-3.7/include/linux/netdevice.h 2012-12-11 15:47:43.000000000 +0000
8046 +++ linux-3.7-vs2.3.5.1/include/linux/netdevice.h       2012-12-11 15:56:32.000000000 +0000
8047 @@ -1637,6 +1637,7 @@ extern void               netdev_resync_ops(struct ne
8048  
8049  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8050  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8051 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8052  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8053  extern int             dev_restart(struct net_device *dev);
8054  #ifdef CONFIG_NETPOLL_TRAP
8055 diff -NurpP --minimal linux-3.7/include/linux/nsproxy.h linux-3.7-vs2.3.5.1/include/linux/nsproxy.h
8056 --- linux-3.7/include/linux/nsproxy.h   2011-10-24 16:45:32.000000000 +0000
8057 +++ linux-3.7-vs2.3.5.1/include/linux/nsproxy.h 2012-12-11 15:56:32.000000000 +0000
8058 @@ -3,6 +3,7 @@
8059  
8060  #include <linux/spinlock.h>
8061  #include <linux/sched.h>
8062 +#include <linux/vserver/debug.h>
8063  
8064  struct mnt_namespace;
8065  struct uts_namespace;
8066 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8067  }
8068  
8069  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8070 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8071  void exit_task_namespaces(struct task_struct *tsk);
8072  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8073  void free_nsproxy(struct nsproxy *ns);
8074 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
8075         struct fs_struct *);
8076  int __init nsproxy_cache_init(void);
8077  
8078 -static inline void put_nsproxy(struct nsproxy *ns)
8079 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8080 +
8081 +static inline void __get_nsproxy(struct nsproxy *ns,
8082 +       const char *_file, int _line)
8083  {
8084 -       if (atomic_dec_and_test(&ns->count)) {
8085 -               free_nsproxy(ns);
8086 -       }
8087 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8088 +               ns, atomic_read(&ns->count), _file, _line);
8089 +       atomic_inc(&ns->count);
8090  }
8091  
8092 -static inline void get_nsproxy(struct nsproxy *ns)
8093 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8094 +
8095 +static inline void __put_nsproxy(struct nsproxy *ns,
8096 +       const char *_file, int _line)
8097  {
8098 -       atomic_inc(&ns->count);
8099 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8100 +               ns, atomic_read(&ns->count), _file, _line);
8101 +       if (atomic_dec_and_test(&ns->count)) {
8102 +               free_nsproxy(ns);
8103 +       }
8104  }
8105  
8106  #endif
8107 diff -NurpP --minimal linux-3.7/include/linux/pid.h linux-3.7-vs2.3.5.1/include/linux/pid.h
8108 --- linux-3.7/include/linux/pid.h       2011-07-22 09:18:11.000000000 +0000
8109 +++ linux-3.7-vs2.3.5.1/include/linux/pid.h     2012-12-11 15:56:32.000000000 +0000
8110 @@ -8,7 +8,8 @@ enum pid_type
8111         PIDTYPE_PID,
8112         PIDTYPE_PGID,
8113         PIDTYPE_SID,
8114 -       PIDTYPE_MAX
8115 +       PIDTYPE_MAX,
8116 +       PIDTYPE_REALPID
8117  };
8118  
8119  /*
8120 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8121  }
8122  
8123  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8124 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8125  pid_t pid_vnr(struct pid *pid);
8126  
8127  #define do_each_pid_task(pid, type, task)                              \
8128 diff -NurpP --minimal linux-3.7/include/linux/proc_fs.h linux-3.7-vs2.3.5.1/include/linux/proc_fs.h
8129 --- linux-3.7/include/linux/proc_fs.h   2012-07-22 21:39:44.000000000 +0000
8130 +++ linux-3.7-vs2.3.5.1/include/linux/proc_fs.h 2012-12-11 15:56:32.000000000 +0000
8131 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8132         nlink_t nlink;
8133         kuid_t uid;
8134         kgid_t gid;
8135 +       int vx_flags;
8136         loff_t size;
8137         const struct inode_operations *proc_iops;
8138         /*
8139 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8140  extern const struct proc_ns_operations utsns_operations;
8141  extern const struct proc_ns_operations ipcns_operations;
8142  
8143 +struct vx_info;
8144 +struct nx_info;
8145 +
8146  union proc_op {
8147         int (*proc_get_link)(struct dentry *, struct path *);
8148         int (*proc_read)(struct task_struct *task, char *page);
8149         int (*proc_show)(struct seq_file *m,
8150                 struct pid_namespace *ns, struct pid *pid,
8151                 struct task_struct *task);
8152 +       int (*proc_vs_read)(char *page);
8153 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8154 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8155  };
8156  
8157  struct ctl_table_header;
8158 @@ -265,6 +272,7 @@ struct ctl_table;
8159  
8160  struct proc_inode {
8161         struct pid *pid;
8162 +       int vx_flags;
8163         int fd;
8164         union proc_op op;
8165         struct proc_dir_entry *pde;
8166 diff -NurpP --minimal linux-3.7/include/linux/quotaops.h linux-3.7-vs2.3.5.1/include/linux/quotaops.h
8167 --- linux-3.7/include/linux/quotaops.h  2012-12-11 15:47:44.000000000 +0000
8168 +++ linux-3.7-vs2.3.5.1/include/linux/quotaops.h        2012-12-11 15:56:32.000000000 +0000
8169 @@ -8,6 +8,7 @@
8170  #define _LINUX_QUOTAOPS_
8171  
8172  #include <linux/fs.h>
8173 +#include <linux/vs_dlimit.h>
8174  
8175  #define DQUOT_SPACE_WARN       0x1
8176  #define DQUOT_SPACE_RESERVE    0x2
8177 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8178  
8179  static inline int dquot_alloc_inode(const struct inode *inode)
8180  {
8181 -       return 0;
8182 +       return dl_alloc_inode(inode);
8183  }
8184  
8185  static inline void dquot_free_inode(const struct inode *inode)
8186  {
8187 +       dl_free_inode(inode);
8188  }
8189  
8190  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8191 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8192  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8193                 int flags)
8194  {
8195 +       int ret = 0;
8196 +
8197 +       if ((ret = dl_alloc_space(inode, number)))
8198 +               return ret;
8199         if (!(flags & DQUOT_SPACE_RESERVE))
8200                 inode_add_bytes(inode, number);
8201         return 0;
8202 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8203  {
8204         if (!(flags & DQUOT_SPACE_RESERVE))
8205                 inode_sub_bytes(inode, number);
8206 +       dl_free_space(inode, number);
8207  }
8208  
8209  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8210 diff -NurpP --minimal linux-3.7/include/linux/sched.h linux-3.7-vs2.3.5.1/include/linux/sched.h
8211 --- linux-3.7/include/linux/sched.h     2012-12-11 15:47:44.000000000 +0000
8212 +++ linux-3.7-vs2.3.5.1/include/linux/sched.h   2012-12-11 15:56:32.000000000 +0000
8213 @@ -1378,6 +1378,14 @@ struct task_struct {
8214  #endif
8215         struct seccomp seccomp;
8216  
8217 +/* vserver context data */
8218 +       struct vx_info *vx_info;
8219 +       struct nx_info *nx_info;
8220 +
8221 +       xid_t xid;
8222 +       nid_t nid;
8223 +       tag_t tag;
8224 +
8225  /* Thread group tracking */
8226         u32 parent_exec_id;
8227         u32 self_exec_id;
8228 @@ -1627,6 +1635,11 @@ struct pid_namespace;
8229  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8230                         struct pid_namespace *ns);
8231  
8232 +#include <linux/vserver/base.h>
8233 +#include <linux/vserver/context.h>
8234 +#include <linux/vserver/debug.h>
8235 +#include <linux/vserver/pid.h>
8236 +
8237  static inline pid_t task_pid_nr(struct task_struct *tsk)
8238  {
8239         return tsk->pid;
8240 @@ -1640,7 +1653,8 @@ static inline pid_t task_pid_nr_ns(struc
8241  
8242  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8243  {
8244 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8245 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8246 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8247  }
8248  
8249  
8250 @@ -1653,7 +1667,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8251  
8252  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8253  {
8254 -       return pid_vnr(task_tgid(tsk));
8255 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8256  }
8257  
8258  
8259 diff -NurpP --minimal linux-3.7/include/linux/shmem_fs.h linux-3.7-vs2.3.5.1/include/linux/shmem_fs.h
8260 --- linux-3.7/include/linux/shmem_fs.h  2012-12-11 15:47:44.000000000 +0000
8261 +++ linux-3.7-vs2.3.5.1/include/linux/shmem_fs.h        2012-12-11 15:56:32.000000000 +0000
8262 @@ -9,6 +9,9 @@
8263  
8264  /* inode in-kernel data */
8265  
8266 +#define TMPFS_SUPER_MAGIC      0x01021994
8267 +
8268 +
8269  struct shmem_inode_info {
8270         spinlock_t              lock;
8271         unsigned long           flags;
8272 diff -NurpP --minimal linux-3.7/include/linux/stat.h linux-3.7-vs2.3.5.1/include/linux/stat.h
8273 --- linux-3.7/include/linux/stat.h      2012-12-11 15:47:45.000000000 +0000
8274 +++ linux-3.7-vs2.3.5.1/include/linux/stat.h    2012-12-11 15:56:32.000000000 +0000
8275 @@ -25,6 +25,7 @@ struct kstat {
8276         unsigned int    nlink;
8277         kuid_t          uid;
8278         kgid_t          gid;
8279 +       tag_t           tag;
8280         dev_t           rdev;
8281         loff_t          size;
8282         struct timespec  atime;
8283 diff -NurpP --minimal linux-3.7/include/linux/sunrpc/auth.h linux-3.7-vs2.3.5.1/include/linux/sunrpc/auth.h
8284 --- linux-3.7/include/linux/sunrpc/auth.h       2012-10-04 13:27:46.000000000 +0000
8285 +++ linux-3.7-vs2.3.5.1/include/linux/sunrpc/auth.h     2012-12-11 15:56:32.000000000 +0000
8286 @@ -25,6 +25,7 @@
8287  struct auth_cred {
8288         uid_t   uid;
8289         gid_t   gid;
8290 +       tag_t   tag;
8291         struct group_info *group_info;
8292         const char *principal;
8293         unsigned char machine_cred : 1;
8294 diff -NurpP --minimal linux-3.7/include/linux/sunrpc/clnt.h linux-3.7-vs2.3.5.1/include/linux/sunrpc/clnt.h
8295 --- linux-3.7/include/linux/sunrpc/clnt.h       2012-12-11 15:47:45.000000000 +0000
8296 +++ linux-3.7-vs2.3.5.1/include/linux/sunrpc/clnt.h     2012-12-11 15:56:32.000000000 +0000
8297 @@ -49,7 +49,8 @@ struct rpc_clnt {
8298         unsigned int            cl_softrtry : 1,/* soft timeouts */
8299                                 cl_discrtry : 1,/* disconnect before retry */
8300                                 cl_autobind : 1,/* use getport() */
8301 -                               cl_chatty   : 1;/* be verbose */
8302 +                               cl_chatty   : 1,/* be verbose */
8303 +                               cl_tag      : 1;/* context tagging */
8304  
8305         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8306         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8307 diff -NurpP --minimal linux-3.7/include/linux/sysfs.h linux-3.7-vs2.3.5.1/include/linux/sysfs.h
8308 --- linux-3.7/include/linux/sysfs.h     2012-07-22 21:39:44.000000000 +0000
8309 +++ linux-3.7-vs2.3.5.1/include/linux/sysfs.h   2012-12-11 15:56:32.000000000 +0000
8310 @@ -19,6 +19,8 @@
8311  #include <linux/kobject_ns.h>
8312  #include <linux/atomic.h>
8313  
8314 +#define SYSFS_SUPER_MAGIC      0x62656572
8315 +
8316  struct kobject;
8317  struct module;
8318  enum kobj_ns_type;
8319 diff -NurpP --minimal linux-3.7/include/linux/types.h linux-3.7-vs2.3.5.1/include/linux/types.h
8320 --- linux-3.7/include/linux/types.h     2012-12-11 15:47:45.000000000 +0000
8321 +++ linux-3.7-vs2.3.5.1/include/linux/types.h   2012-12-11 15:56:32.000000000 +0000
8322 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8323  typedef __kernel_gid32_t       gid_t;
8324  typedef __kernel_uid16_t        uid16_t;
8325  typedef __kernel_gid16_t        gid16_t;
8326 +typedef unsigned int           xid_t;
8327 +typedef unsigned int           nid_t;
8328 +typedef unsigned int           tag_t;
8329  
8330  typedef unsigned long          uintptr_t;
8331  
8332 diff -NurpP --minimal linux-3.7/include/linux/uidgid.h linux-3.7-vs2.3.5.1/include/linux/uidgid.h
8333 --- linux-3.7/include/linux/uidgid.h    2012-07-22 21:39:45.000000000 +0000
8334 +++ linux-3.7-vs2.3.5.1/include/linux/uidgid.h  2012-12-11 19:45:37.000000000 +0000
8335 @@ -23,13 +23,17 @@ typedef struct {
8336         uid_t val;
8337  } kuid_t;
8338  
8339 -
8340  typedef struct {
8341         gid_t val;
8342  } kgid_t;
8343  
8344 +typedef struct {
8345 +       tag_t val;
8346 +} ktag_t;
8347 +
8348  #define KUIDT_INIT(value) (kuid_t){ value }
8349  #define KGIDT_INIT(value) (kgid_t){ value }
8350 +#define KTAGT_INIT(value) (ktag_t){ value }
8351  
8352  static inline uid_t __kuid_val(kuid_t uid)
8353  {
8354 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8355         return gid.val;
8356  }
8357  
8358 +static inline tag_t __ktag_val(ktag_t tag)
8359 +{
8360 +       return tag.val;
8361 +}
8362 +
8363  #else
8364  
8365  typedef uid_t kuid_t;
8366  typedef gid_t kgid_t;
8367 +typedef tag_t ktag_t;
8368  
8369  static inline uid_t __kuid_val(kuid_t uid)
8370  {
8371 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8372         return gid;
8373  }
8374  
8375 +static inline tag_t __ktag_val(ktag_t tag)
8376 +{
8377 +       return tag;
8378 +}
8379 +
8380  #define KUIDT_INIT(value) ((kuid_t) value )
8381  #define KGIDT_INIT(value) ((kgid_t) value )
8382 +#define KTAGT_INIT(value) ((ktag_t) value )
8383  
8384  #endif
8385  
8386  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8387  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8388 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8389  
8390  #define INVALID_UID KUIDT_INIT(-1)
8391  #define INVALID_GID KGIDT_INIT(-1)
8392 +#define INVALID_TAG KTAGT_INIT(-1)
8393  
8394  static inline bool uid_eq(kuid_t left, kuid_t right)
8395  {
8396 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8397         return __kgid_val(left) == __kgid_val(right);
8398  }
8399  
8400 +static inline bool tag_eq(ktag_t left, ktag_t right)
8401 +{
8402 +       return __ktag_val(left) == __ktag_val(right);
8403 +}
8404 +
8405  static inline bool uid_gt(kuid_t left, kuid_t right)
8406  {
8407         return __kuid_val(left) > __kuid_val(right);
8408 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8409         return !gid_eq(gid, INVALID_GID);
8410  }
8411  
8412 +static inline bool tag_valid(ktag_t tag)
8413 +{
8414 +       return !tag_eq(tag, INVALID_TAG);
8415 +}
8416 +
8417  #ifdef CONFIG_USER_NS
8418  
8419  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8420  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8421 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8422  
8423  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8424  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8425 +extern tag_t from_ktag(struct user_namespace *to, ktag_t tag);
8426 +
8427  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8428  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8429  
8430 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8431         return KGIDT_INIT(gid);
8432  }
8433  
8434 +static inline ktag_t make_ktag(struct user_namespace *from, tag_t tag)
8435 +{
8436 +       return KTAGT_INIT(tag);
8437 +}
8438 +
8439  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8440  {
8441         return __kuid_val(kuid);
8442 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8443         return __kgid_val(kgid);
8444  }
8445  
8446 +static inline tag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8447 +{
8448 +       return __ktag_val(ktag);
8449 +}
8450 +
8451  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8452  {
8453         uid_t uid = from_kuid(to, kuid);
8454 diff -NurpP --minimal linux-3.7/include/linux/utsname.h linux-3.7-vs2.3.5.1/include/linux/utsname.h
8455 --- linux-3.7/include/linux/utsname.h   2012-12-11 15:47:45.000000000 +0000
8456 +++ linux-3.7-vs2.3.5.1/include/linux/utsname.h 2012-12-11 15:56:32.000000000 +0000
8457 @@ -33,7 +33,8 @@ static inline void get_uts_ns(struct uts
8458  }
8459  
8460  extern struct uts_namespace *copy_utsname(unsigned long flags,
8461 -                                         struct task_struct *tsk);
8462 +                                         struct uts_namespace *old_ns,
8463 +                                         struct user_namespace *user_ns);
8464  extern void free_uts_ns(struct kref *kref);
8465  
8466  static inline void put_uts_ns(struct uts_namespace *ns)
8467 @@ -50,12 +51,13 @@ static inline void put_uts_ns(struct uts
8468  }
8469  
8470  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8471 -                                                struct task_struct *tsk)
8472 +                                                struct uts_namespace *old_ns,
8473 +                                                struct user_namespace *user_ns)
8474  {
8475         if (flags & CLONE_NEWUTS)
8476                 return ERR_PTR(-EINVAL);
8477  
8478 -       return tsk->nsproxy->uts_ns;
8479 +       return old_ns;
8480  }
8481  #endif
8482  
8483 diff -NurpP --minimal linux-3.7/include/linux/vroot.h linux-3.7-vs2.3.5.1/include/linux/vroot.h
8484 --- linux-3.7/include/linux/vroot.h     1970-01-01 00:00:00.000000000 +0000
8485 +++ linux-3.7-vs2.3.5.1/include/linux/vroot.h   2012-12-11 15:56:32.000000000 +0000
8486 @@ -0,0 +1,51 @@
8487 +
8488 +/*
8489 + * include/linux/vroot.h
8490 + *
8491 + * written by Herbert Pötzl, 9/11/2002
8492 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8493 + *
8494 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8495 + * Redistribution of this file is permitted under the
8496 + * GNU General Public License.
8497 + */
8498 +
8499 +#ifndef _LINUX_VROOT_H
8500 +#define _LINUX_VROOT_H
8501 +
8502 +
8503 +#ifdef __KERNEL__
8504 +
8505 +/* Possible states of device */
8506 +enum {
8507 +       Vr_unbound,
8508 +       Vr_bound,
8509 +};
8510 +
8511 +struct vroot_device {
8512 +       int             vr_number;
8513 +       int             vr_refcnt;
8514 +
8515 +       struct semaphore        vr_ctl_mutex;
8516 +       struct block_device    *vr_device;
8517 +       int                     vr_state;
8518 +};
8519 +
8520 +
8521 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8522 +
8523 +extern int register_vroot_grb(vroot_grb_func *);
8524 +extern int unregister_vroot_grb(vroot_grb_func *);
8525 +
8526 +#endif /* __KERNEL__ */
8527 +
8528 +#define MAX_VROOT_DEFAULT      8
8529 +
8530 +/*
8531 + * IOCTL commands --- we will commandeer 0x56 ('V')
8532 + */
8533 +
8534 +#define VROOT_SET_DEV          0x5600
8535 +#define VROOT_CLR_DEV          0x5601
8536 +
8537 +#endif /* _LINUX_VROOT_H */
8538 diff -NurpP --minimal linux-3.7/include/linux/vs_base.h linux-3.7-vs2.3.5.1/include/linux/vs_base.h
8539 --- linux-3.7/include/linux/vs_base.h   1970-01-01 00:00:00.000000000 +0000
8540 +++ linux-3.7-vs2.3.5.1/include/linux/vs_base.h 2012-12-11 15:56:32.000000000 +0000
8541 @@ -0,0 +1,10 @@
8542 +#ifndef _VS_BASE_H
8543 +#define _VS_BASE_H
8544 +
8545 +#include "vserver/base.h"
8546 +#include "vserver/check.h"
8547 +#include "vserver/debug.h"
8548 +
8549 +#else
8550 +#warning duplicate inclusion
8551 +#endif
8552 diff -NurpP --minimal linux-3.7/include/linux/vs_context.h linux-3.7-vs2.3.5.1/include/linux/vs_context.h
8553 --- linux-3.7/include/linux/vs_context.h        1970-01-01 00:00:00.000000000 +0000
8554 +++ linux-3.7-vs2.3.5.1/include/linux/vs_context.h      2012-12-11 15:56:32.000000000 +0000
8555 @@ -0,0 +1,242 @@
8556 +#ifndef _VS_CONTEXT_H
8557 +#define _VS_CONTEXT_H
8558 +
8559 +#include "vserver/base.h"
8560 +#include "vserver/check.h"
8561 +#include "vserver/context.h"
8562 +#include "vserver/history.h"
8563 +#include "vserver/debug.h"
8564 +
8565 +#include <linux/sched.h>
8566 +
8567 +
8568 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8569 +
8570 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8571 +       const char *_file, int _line, void *_here)
8572 +{
8573 +       if (!vxi)
8574 +               return NULL;
8575 +
8576 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8577 +               vxi, vxi ? vxi->vx_id : 0,
8578 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8579 +               _file, _line);
8580 +       __vxh_get_vx_info(vxi, _here);
8581 +
8582 +       atomic_inc(&vxi->vx_usecnt);
8583 +       return vxi;
8584 +}
8585 +
8586 +
8587 +extern void free_vx_info(struct vx_info *);
8588 +
8589 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8590 +
8591 +static inline void __put_vx_info(struct vx_info *vxi,
8592 +       const char *_file, int _line, void *_here)
8593 +{
8594 +       if (!vxi)
8595 +               return;
8596 +
8597 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8598 +               vxi, vxi ? vxi->vx_id : 0,
8599 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8600 +               _file, _line);
8601 +       __vxh_put_vx_info(vxi, _here);
8602 +
8603 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8604 +               free_vx_info(vxi);
8605 +}
8606 +
8607 +
8608 +#define init_vx_info(p, i) \
8609 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8610 +
8611 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8612 +       const char *_file, int _line, void *_here)
8613 +{
8614 +       if (vxi) {
8615 +               vxlprintk(VXD_CBIT(xid, 3),
8616 +                       "init_vx_info(%p[#%d.%d])",
8617 +                       vxi, vxi ? vxi->vx_id : 0,
8618 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8619 +                       _file, _line);
8620 +               __vxh_init_vx_info(vxi, vxp, _here);
8621 +
8622 +               atomic_inc(&vxi->vx_usecnt);
8623 +       }
8624 +       *vxp = vxi;
8625 +}
8626 +
8627 +
8628 +#define set_vx_info(p, i) \
8629 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8630 +
8631 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8632 +       const char *_file, int _line, void *_here)
8633 +{
8634 +       struct vx_info *vxo;
8635 +
8636 +       if (!vxi)
8637 +               return;
8638 +
8639 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8640 +               vxi, vxi ? vxi->vx_id : 0,
8641 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8642 +               _file, _line);
8643 +       __vxh_set_vx_info(vxi, vxp, _here);
8644 +
8645 +       atomic_inc(&vxi->vx_usecnt);
8646 +       vxo = xchg(vxp, vxi);
8647 +       BUG_ON(vxo);
8648 +}
8649 +
8650 +
8651 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8652 +
8653 +static inline void __clr_vx_info(struct vx_info **vxp,
8654 +       const char *_file, int _line, void *_here)
8655 +{
8656 +       struct vx_info *vxo;
8657 +
8658 +       vxo = xchg(vxp, NULL);
8659 +       if (!vxo)
8660 +               return;
8661 +
8662 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8663 +               vxo, vxo ? vxo->vx_id : 0,
8664 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8665 +               _file, _line);
8666 +       __vxh_clr_vx_info(vxo, vxp, _here);
8667 +
8668 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8669 +               free_vx_info(vxo);
8670 +}
8671 +
8672 +
8673 +#define claim_vx_info(v, p) \
8674 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8675 +
8676 +static inline void __claim_vx_info(struct vx_info *vxi,
8677 +       struct task_struct *task,
8678 +       const char *_file, int _line, void *_here)
8679 +{
8680 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8681 +               vxi, vxi ? vxi->vx_id : 0,
8682 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8683 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8684 +               task, _file, _line);
8685 +       __vxh_claim_vx_info(vxi, task, _here);
8686 +
8687 +       atomic_inc(&vxi->vx_tasks);
8688 +}
8689 +
8690 +
8691 +extern void unhash_vx_info(struct vx_info *);
8692 +
8693 +#define release_vx_info(v, p) \
8694 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8695 +
8696 +static inline void __release_vx_info(struct vx_info *vxi,
8697 +       struct task_struct *task,
8698 +       const char *_file, int _line, void *_here)
8699 +{
8700 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8701 +               vxi, vxi ? vxi->vx_id : 0,
8702 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8703 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8704 +               task, _file, _line);
8705 +       __vxh_release_vx_info(vxi, task, _here);
8706 +
8707 +       might_sleep();
8708 +
8709 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8710 +               unhash_vx_info(vxi);
8711 +}
8712 +
8713 +
8714 +#define task_get_vx_info(p) \
8715 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8716 +
8717 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8718 +       const char *_file, int _line, void *_here)
8719 +{
8720 +       struct vx_info *vxi;
8721 +
8722 +       task_lock(p);
8723 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8724 +               p, _file, _line);
8725 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8726 +       task_unlock(p);
8727 +       return vxi;
8728 +}
8729 +
8730 +
8731 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8732 +{
8733 +       if (waitqueue_active(&vxi->vx_wait))
8734 +               wake_up_interruptible(&vxi->vx_wait);
8735 +}
8736 +
8737 +
8738 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8739 +
8740 +static inline void __enter_vx_info(struct vx_info *vxi,
8741 +       struct vx_info_save *vxis, const char *_file, int _line)
8742 +{
8743 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8744 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8745 +               current->xid, current->vx_info, _file, _line);
8746 +       vxis->vxi = xchg(&current->vx_info, vxi);
8747 +       vxis->xid = current->xid;
8748 +       current->xid = vxi ? vxi->vx_id : 0;
8749 +}
8750 +
8751 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8752 +
8753 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8754 +       const char *_file, int _line)
8755 +{
8756 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8757 +               vxis, vxis->xid, vxis->vxi, current,
8758 +               current->xid, current->vx_info, _file, _line);
8759 +       (void)xchg(&current->vx_info, vxis->vxi);
8760 +       current->xid = vxis->xid;
8761 +}
8762 +
8763 +
8764 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8765 +{
8766 +       vxis->vxi = xchg(&current->vx_info, NULL);
8767 +       vxis->xid = xchg(&current->xid, (xid_t)0);
8768 +}
8769 +
8770 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8771 +{
8772 +       (void)xchg(&current->xid, vxis->xid);
8773 +       (void)xchg(&current->vx_info, vxis->vxi);
8774 +}
8775 +
8776 +#define task_is_init(p) \
8777 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8778 +
8779 +static inline int __task_is_init(struct task_struct *p,
8780 +       const char *_file, int _line, void *_here)
8781 +{
8782 +       int is_init = is_global_init(p);
8783 +
8784 +       task_lock(p);
8785 +       if (p->vx_info)
8786 +               is_init = p->vx_info->vx_initpid == p->pid;
8787 +       task_unlock(p);
8788 +       return is_init;
8789 +}
8790 +
8791 +extern void exit_vx_info(struct task_struct *, int);
8792 +extern void exit_vx_info_early(struct task_struct *, int);
8793 +
8794 +
8795 +#else
8796 +#warning duplicate inclusion
8797 +#endif
8798 diff -NurpP --minimal linux-3.7/include/linux/vs_cowbl.h linux-3.7-vs2.3.5.1/include/linux/vs_cowbl.h
8799 --- linux-3.7/include/linux/vs_cowbl.h  1970-01-01 00:00:00.000000000 +0000
8800 +++ linux-3.7-vs2.3.5.1/include/linux/vs_cowbl.h        2012-12-11 15:56:32.000000000 +0000
8801 @@ -0,0 +1,48 @@
8802 +#ifndef _VS_COWBL_H
8803 +#define _VS_COWBL_H
8804 +
8805 +#include <linux/fs.h>
8806 +#include <linux/dcache.h>
8807 +#include <linux/namei.h>
8808 +#include <linux/slab.h>
8809 +
8810 +extern struct dentry *cow_break_link(const char *pathname);
8811 +
8812 +static inline int cow_check_and_break(struct path *path)
8813 +{
8814 +       struct inode *inode = path->dentry->d_inode;
8815 +       int error = 0;
8816 +
8817 +       /* do we need this check? */
8818 +       if (IS_RDONLY(inode))
8819 +               return -EROFS;
8820 +
8821 +       if (IS_COW(inode)) {
8822 +               if (IS_COW_LINK(inode)) {
8823 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8824 +                       char *pp, *buf;
8825 +
8826 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8827 +                       if (!buf) {
8828 +                               return -ENOMEM;
8829 +                       }
8830 +                       pp = d_path(path, buf, PATH_MAX);
8831 +                       new_dentry = cow_break_link(pp);
8832 +                       kfree(buf);
8833 +                       if (!IS_ERR(new_dentry)) {
8834 +                               path->dentry = new_dentry;
8835 +                               dput(old_dentry);
8836 +                       } else
8837 +                               error = PTR_ERR(new_dentry);
8838 +               } else {
8839 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8840 +                       inode->i_ctime = CURRENT_TIME;
8841 +                       mark_inode_dirty(inode);
8842 +               }
8843 +       }
8844 +       return error;
8845 +}
8846 +
8847 +#else
8848 +#warning duplicate inclusion
8849 +#endif
8850 diff -NurpP --minimal linux-3.7/include/linux/vs_cvirt.h linux-3.7-vs2.3.5.1/include/linux/vs_cvirt.h
8851 --- linux-3.7/include/linux/vs_cvirt.h  1970-01-01 00:00:00.000000000 +0000
8852 +++ linux-3.7-vs2.3.5.1/include/linux/vs_cvirt.h        2012-12-11 15:56:32.000000000 +0000
8853 @@ -0,0 +1,50 @@
8854 +#ifndef _VS_CVIRT_H
8855 +#define _VS_CVIRT_H
8856 +
8857 +#include "vserver/cvirt.h"
8858 +#include "vserver/context.h"
8859 +#include "vserver/base.h"
8860 +#include "vserver/check.h"
8861 +#include "vserver/debug.h"
8862 +
8863 +
8864 +static inline void vx_activate_task(struct task_struct *p)
8865 +{
8866 +       struct vx_info *vxi;
8867 +
8868 +       if ((vxi = p->vx_info)) {
8869 +               vx_update_load(vxi);
8870 +               atomic_inc(&vxi->cvirt.nr_running);
8871 +       }
8872 +}
8873 +
8874 +static inline void vx_deactivate_task(struct task_struct *p)
8875 +{
8876 +       struct vx_info *vxi;
8877 +
8878 +       if ((vxi = p->vx_info)) {
8879 +               vx_update_load(vxi);
8880 +               atomic_dec(&vxi->cvirt.nr_running);
8881 +       }
8882 +}
8883 +
8884 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8885 +{
8886 +       struct vx_info *vxi;
8887 +
8888 +       if ((vxi = p->vx_info))
8889 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8890 +}
8891 +
8892 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8893 +{
8894 +       struct vx_info *vxi;
8895 +
8896 +       if ((vxi = p->vx_info))
8897 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8898 +}
8899 +
8900 +
8901 +#else
8902 +#warning duplicate inclusion
8903 +#endif
8904 diff -NurpP --minimal linux-3.7/include/linux/vs_device.h linux-3.7-vs2.3.5.1/include/linux/vs_device.h
8905 --- linux-3.7/include/linux/vs_device.h 1970-01-01 00:00:00.000000000 +0000
8906 +++ linux-3.7-vs2.3.5.1/include/linux/vs_device.h       2012-12-11 15:56:32.000000000 +0000
8907 @@ -0,0 +1,45 @@
8908 +#ifndef _VS_DEVICE_H
8909 +#define _VS_DEVICE_H
8910 +
8911 +#include "vserver/base.h"
8912 +#include "vserver/device.h"
8913 +#include "vserver/debug.h"
8914 +
8915 +
8916 +#ifdef CONFIG_VSERVER_DEVICE
8917 +
8918 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8919 +
8920 +#define vs_device_perm(v, d, m, p) \
8921 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8922 +
8923 +#else
8924 +
8925 +static inline
8926 +int vs_map_device(struct vx_info *vxi,
8927 +       dev_t device, dev_t *target, umode_t mode)
8928 +{
8929 +       if (target)
8930 +               *target = device;
8931 +       return ~0;
8932 +}
8933 +
8934 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8935 +
8936 +#endif
8937 +
8938 +
8939 +#define vs_map_chrdev(d, t, p) \
8940 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8941 +#define vs_map_blkdev(d, t, p) \
8942 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8943 +
8944 +#define vs_chrdev_perm(d, p) \
8945 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8946 +#define vs_blkdev_perm(d, p) \
8947 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8948 +
8949 +
8950 +#else
8951 +#warning duplicate inclusion
8952 +#endif
8953 diff -NurpP --minimal linux-3.7/include/linux/vs_dlimit.h linux-3.7-vs2.3.5.1/include/linux/vs_dlimit.h
8954 --- linux-3.7/include/linux/vs_dlimit.h 1970-01-01 00:00:00.000000000 +0000
8955 +++ linux-3.7-vs2.3.5.1/include/linux/vs_dlimit.h       2012-12-11 19:37:05.000000000 +0000
8956 @@ -0,0 +1,215 @@
8957 +#ifndef _VS_DLIMIT_H
8958 +#define _VS_DLIMIT_H
8959 +
8960 +#include <linux/fs.h>
8961 +
8962 +#include "vserver/dlimit.h"
8963 +#include "vserver/base.h"
8964 +#include "vserver/debug.h"
8965 +
8966 +
8967 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8968 +
8969 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8970 +       const char *_file, int _line)
8971 +{
8972 +       if (!dli)
8973 +               return NULL;
8974 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8975 +               dli, dli ? dli->dl_tag : 0,
8976 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8977 +               _file, _line);
8978 +       atomic_inc(&dli->dl_usecnt);
8979 +       return dli;
8980 +}
8981 +
8982 +
8983 +#define free_dl_info(i) \
8984 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8985 +
8986 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8987 +
8988 +static inline void __put_dl_info(struct dl_info *dli,
8989 +       const char *_file, int _line)
8990 +{
8991 +       if (!dli)
8992 +               return;
8993 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8994 +               dli, dli ? dli->dl_tag : 0,
8995 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8996 +               _file, _line);
8997 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8998 +               free_dl_info(dli);
8999 +}
9000 +
9001 +
9002 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9003 +
9004 +static inline int __dl_alloc_space(struct super_block *sb,
9005 +       tag_t tag, dlsize_t nr, const char *file, int line)
9006 +{
9007 +       struct dl_info *dli = NULL;
9008 +       int ret = 0;
9009 +
9010 +       if (nr == 0)
9011 +               goto out;
9012 +       dli = locate_dl_info(sb, tag);
9013 +       if (!dli)
9014 +               goto out;
9015 +
9016 +       spin_lock(&dli->dl_lock);
9017 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9018 +       if (!ret)
9019 +               dli->dl_space_used += nr;
9020 +       spin_unlock(&dli->dl_lock);
9021 +       put_dl_info(dli);
9022 +out:
9023 +       vxlprintk(VXD_CBIT(dlim, 1),
9024 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9025 +               sb, tag, __dlimit_char(dli), (long long)nr,
9026 +               ret, file, line);
9027 +       return ret ? -ENOSPC : 0;
9028 +}
9029 +
9030 +static inline void __dl_free_space(struct super_block *sb,
9031 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9032 +{
9033 +       struct dl_info *dli = NULL;
9034 +
9035 +       if (nr == 0)
9036 +               goto out;
9037 +       dli = locate_dl_info(sb, tag);
9038 +       if (!dli)
9039 +               goto out;
9040 +
9041 +       spin_lock(&dli->dl_lock);
9042 +       if (dli->dl_space_used > nr)
9043 +               dli->dl_space_used -= nr;
9044 +       else
9045 +               dli->dl_space_used = 0;
9046 +       spin_unlock(&dli->dl_lock);
9047 +       put_dl_info(dli);
9048 +out:
9049 +       vxlprintk(VXD_CBIT(dlim, 1),
9050 +               "FREE  (%p,#%d)%c %lld bytes",
9051 +               sb, tag, __dlimit_char(dli), (long long)nr,
9052 +               _file, _line);
9053 +}
9054 +
9055 +static inline int __dl_alloc_inode(struct super_block *sb,
9056 +       tag_t tag, const char *_file, int _line)
9057 +{
9058 +       struct dl_info *dli;
9059 +       int ret = 0;
9060 +
9061 +       dli = locate_dl_info(sb, tag);
9062 +       if (!dli)
9063 +               goto out;
9064 +
9065 +       spin_lock(&dli->dl_lock);
9066 +       dli->dl_inodes_used++;
9067 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9068 +       spin_unlock(&dli->dl_lock);
9069 +       put_dl_info(dli);
9070 +out:
9071 +       vxlprintk(VXD_CBIT(dlim, 0),
9072 +               "ALLOC (%p,#%d)%c inode (%d)",
9073 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9074 +       return ret ? -ENOSPC : 0;
9075 +}
9076 +
9077 +static inline void __dl_free_inode(struct super_block *sb,
9078 +       tag_t tag, const char *_file, int _line)
9079 +{
9080 +       struct dl_info *dli;
9081 +
9082 +       dli = locate_dl_info(sb, tag);
9083 +       if (!dli)
9084 +               goto out;
9085 +
9086 +       spin_lock(&dli->dl_lock);
9087 +       if (dli->dl_inodes_used > 1)
9088 +               dli->dl_inodes_used--;
9089 +       else
9090 +               dli->dl_inodes_used = 0;
9091 +       spin_unlock(&dli->dl_lock);
9092 +       put_dl_info(dli);
9093 +out:
9094 +       vxlprintk(VXD_CBIT(dlim, 0),
9095 +               "FREE  (%p,#%d)%c inode",
9096 +               sb, tag, __dlimit_char(dli), _file, _line);
9097 +}
9098 +
9099 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9100 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9101 +       const char *_file, int _line)
9102 +{
9103 +       struct dl_info *dli;
9104 +       uint64_t broot, bfree;
9105 +
9106 +       dli = locate_dl_info(sb, tag);
9107 +       if (!dli)
9108 +               return;
9109 +
9110 +       spin_lock(&dli->dl_lock);
9111 +       broot = (dli->dl_space_total -
9112 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9113 +               >> sb->s_blocksize_bits;
9114 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9115 +                       >> sb->s_blocksize_bits;
9116 +       spin_unlock(&dli->dl_lock);
9117 +
9118 +       vxlprintk(VXD_CBIT(dlim, 2),
9119 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9120 +               (long long)bfree, (long long)broot,
9121 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9122 +               _file, _line);
9123 +       if (free_blocks) {
9124 +               if (*free_blocks > bfree)
9125 +                       *free_blocks = bfree;
9126 +       }
9127 +       if (root_blocks) {
9128 +               if (*root_blocks > broot)
9129 +                       *root_blocks = broot;
9130 +       }
9131 +       put_dl_info(dli);
9132 +}
9133 +
9134 +#define dl_prealloc_space(in, bytes) \
9135 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9136 +               __FILE__, __LINE__ )
9137 +
9138 +#define dl_alloc_space(in, bytes) \
9139 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9140 +               __FILE__, __LINE__ )
9141 +
9142 +#define dl_reserve_space(in, bytes) \
9143 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9144 +               __FILE__, __LINE__ )
9145 +
9146 +#define dl_claim_space(in, bytes) (0)
9147 +
9148 +#define dl_release_space(in, bytes) \
9149 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9150 +               __FILE__, __LINE__ )
9151 +
9152 +#define dl_free_space(in, bytes) \
9153 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9154 +               __FILE__, __LINE__ )
9155 +
9156 +
9157 +
9158 +#define dl_alloc_inode(in) \
9159 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9160 +
9161 +#define dl_free_inode(in) \
9162 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9163 +
9164 +
9165 +#define dl_adjust_block(sb, tag, fb, rb) \
9166 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9167 +
9168 +
9169 +#else
9170 +#warning duplicate inclusion
9171 +#endif
9172 diff -NurpP --minimal linux-3.7/include/linux/vs_inet.h linux-3.7-vs2.3.5.1/include/linux/vs_inet.h
9173 --- linux-3.7/include/linux/vs_inet.h   1970-01-01 00:00:00.000000000 +0000
9174 +++ linux-3.7-vs2.3.5.1/include/linux/vs_inet.h 2012-12-11 15:56:32.000000000 +0000
9175 @@ -0,0 +1,353 @@
9176 +#ifndef _VS_INET_H
9177 +#define _VS_INET_H
9178 +
9179 +#include "vserver/base.h"
9180 +#include "vserver/network.h"
9181 +#include "vserver/debug.h"
9182 +
9183 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9184 +
9185 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9186 +                       NIPQUAD((a)->mask), (a)->type
9187 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9188 +
9189 +#define NIPQUAD(addr) \
9190 +       ((unsigned char *)&addr)[0], \
9191 +       ((unsigned char *)&addr)[1], \
9192 +       ((unsigned char *)&addr)[2], \
9193 +       ((unsigned char *)&addr)[3]
9194 +
9195 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9196 +
9197 +
9198 +static inline
9199 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9200 +{
9201 +       __be32 ip = nxa->ip[0].s_addr;
9202 +       __be32 mask = nxa->mask.s_addr;
9203 +       __be32 bcast = ip | ~mask;
9204 +       int ret = 0;
9205 +
9206 +       switch (nxa->type & tmask) {
9207 +       case NXA_TYPE_MASK:
9208 +               ret = (ip == (addr & mask));
9209 +               break;
9210 +       case NXA_TYPE_ADDR:
9211 +               ret = 3;
9212 +               if (addr == ip)
9213 +                       break;
9214 +               /* fall through to broadcast */
9215 +       case NXA_MOD_BCAST:
9216 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9217 +               break;
9218 +       case NXA_TYPE_RANGE:
9219 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9220 +                       (nxa->ip[1].s_addr > addr));
9221 +               break;
9222 +       case NXA_TYPE_ANY:
9223 +               ret = 2;
9224 +               break;
9225 +       }
9226 +
9227 +       vxdprintk(VXD_CBIT(net, 0),
9228 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9229 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9230 +       return ret;
9231 +}
9232 +
9233 +static inline
9234 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9235 +{
9236 +       struct nx_addr_v4 *nxa;
9237 +       int ret = 1;
9238 +
9239 +       if (!nxi)
9240 +               goto out;
9241 +
9242 +       ret = 2;
9243 +       /* allow 127.0.0.1 when remapping lback */
9244 +       if ((tmask & NXA_LOOPBACK) &&
9245 +               (addr == IPI_LOOPBACK) &&
9246 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9247 +               goto out;
9248 +       ret = 3;
9249 +       /* check for lback address */
9250 +       if ((tmask & NXA_MOD_LBACK) &&
9251 +               (nxi->v4_lback.s_addr == addr))
9252 +               goto out;
9253 +       ret = 4;
9254 +       /* check for broadcast address */
9255 +       if ((tmask & NXA_MOD_BCAST) &&
9256 +               (nxi->v4_bcast.s_addr == addr))
9257 +               goto out;
9258 +       ret = 5;
9259 +       /* check for v4 addresses */
9260 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9261 +               if (v4_addr_match(nxa, addr, tmask))
9262 +                       goto out;
9263 +       ret = 0;
9264 +out:
9265 +       vxdprintk(VXD_CBIT(net, 0),
9266 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9267 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9268 +       return ret;
9269 +}
9270 +
9271 +static inline
9272 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9273 +{
9274 +       /* FIXME: needs full range checks */
9275 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9276 +}
9277 +
9278 +static inline
9279 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9280 +{
9281 +       struct nx_addr_v4 *ptr;
9282 +
9283 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9284 +               if (v4_nx_addr_match(ptr, nxa, mask))
9285 +                       return 1;
9286 +       return 0;
9287 +}
9288 +
9289 +#include <net/inet_sock.h>
9290 +
9291 +/*
9292 + *     Check if a given address matches for a socket
9293 + *
9294 + *     nxi:            the socket's nx_info if any
9295 + *     addr:           to be verified address
9296 + */
9297 +static inline
9298 +int v4_sock_addr_match (
9299 +       struct nx_info *nxi,
9300 +       struct inet_sock *inet,
9301 +       __be32 addr)
9302 +{
9303 +       __be32 saddr = inet->inet_rcv_saddr;
9304 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9305 +
9306 +       if (addr && (saddr == addr || bcast == addr))
9307 +               return 1;
9308 +       if (!saddr)
9309 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9310 +       return 0;
9311 +}
9312 +
9313 +
9314 +/* inet related checks and helpers */
9315 +
9316 +
9317 +struct in_ifaddr;
9318 +struct net_device;
9319 +struct sock;
9320 +
9321 +#ifdef CONFIG_INET
9322 +
9323 +#include <linux/netdevice.h>
9324 +#include <linux/inetdevice.h>
9325 +#include <net/inet_sock.h>
9326 +#include <net/inet_timewait_sock.h>
9327 +
9328 +
9329 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9330 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9331 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9332 +
9333 +
9334 +/*
9335 + *     check if address is covered by socket
9336 + *
9337 + *     sk:     the socket to check against
9338 + *     addr:   the address in question (must be != 0)
9339 + */
9340 +
9341 +static inline
9342 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9343 +{
9344 +       struct nx_info *nxi = sk->sk_nx_info;
9345 +       __be32 saddr = sk_rcv_saddr(sk);
9346 +
9347 +       vxdprintk(VXD_CBIT(net, 5),
9348 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9349 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9350 +               (sk->sk_socket?sk->sk_socket->flags:0));
9351 +
9352 +       if (saddr) {            /* direct address match */
9353 +               return v4_addr_match(nxa, saddr, -1);
9354 +       } else if (nxi) {       /* match against nx_info */
9355 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9356 +       } else {                /* unrestricted any socket */
9357 +               return 1;
9358 +       }
9359 +}
9360 +
9361 +
9362 +
9363 +static inline
9364 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9365 +{
9366 +       vxdprintk(VXD_CBIT(net, 1),
9367 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9368 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9369 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9370 +
9371 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9372 +               return 1;
9373 +       if (dev_in_nx_info(dev, nxi))
9374 +               return 1;
9375 +       return 0;
9376 +}
9377 +
9378 +
9379 +static inline
9380 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9381 +{
9382 +       if (!nxi)
9383 +               return 1;
9384 +       if (!ifa)
9385 +               return 0;
9386 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9387 +}
9388 +
9389 +static inline
9390 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9391 +{
9392 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9393 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9394 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9395 +
9396 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9397 +               return 1;
9398 +       if (v4_ifa_in_nx_info(ifa, nxi))
9399 +               return 1;
9400 +       return 0;
9401 +}
9402 +
9403 +
9404 +struct nx_v4_sock_addr {
9405 +       __be32 saddr;   /* Address used for validation */
9406 +       __be32 baddr;   /* Address used for socket bind */
9407 +};
9408 +
9409 +static inline
9410 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9411 +       struct nx_v4_sock_addr *nsa)
9412 +{
9413 +       struct sock *sk = &inet->sk;
9414 +       struct nx_info *nxi = sk->sk_nx_info;
9415 +       __be32 saddr = addr->sin_addr.s_addr;
9416 +       __be32 baddr = saddr;
9417 +
9418 +       vxdprintk(VXD_CBIT(net, 3),
9419 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9420 +               sk, sk->sk_nx_info, sk->sk_socket,
9421 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9422 +               NIPQUAD(saddr));
9423 +
9424 +       if (nxi) {
9425 +               if (saddr == INADDR_ANY) {
9426 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9427 +                               baddr = nxi->v4.ip[0].s_addr;
9428 +               } else if (saddr == IPI_LOOPBACK) {
9429 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9430 +                               baddr = nxi->v4_lback.s_addr;
9431 +               } else if (!ipv4_is_multicast(saddr) ||
9432 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9433 +                       /* normal address bind */
9434 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9435 +                               return -EADDRNOTAVAIL;
9436 +               }
9437 +       }
9438 +
9439 +       vxdprintk(VXD_CBIT(net, 3),
9440 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9441 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9442 +
9443 +       nsa->saddr = saddr;
9444 +       nsa->baddr = baddr;
9445 +       return 0;
9446 +}
9447 +
9448 +static inline
9449 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9450 +{
9451 +       inet->inet_saddr = nsa->baddr;
9452 +       inet->inet_rcv_saddr = nsa->baddr;
9453 +}
9454 +
9455 +
9456 +/*
9457 + *      helper to simplify inet_lookup_listener
9458 + *
9459 + *      nxi:   the socket's nx_info if any
9460 + *      addr:  to be verified address
9461 + *      saddr: socket address
9462 + */
9463 +static inline int v4_inet_addr_match (
9464 +       struct nx_info *nxi,
9465 +       __be32 addr,
9466 +       __be32 saddr)
9467 +{
9468 +       if (addr && (saddr == addr))
9469 +               return 1;
9470 +       if (!saddr)
9471 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9472 +       return 0;
9473 +}
9474 +
9475 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9476 +{
9477 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9478 +               (addr == nxi->v4_lback.s_addr))
9479 +               return IPI_LOOPBACK;
9480 +       return addr;
9481 +}
9482 +
9483 +static inline
9484 +int nx_info_has_v4(struct nx_info *nxi)
9485 +{
9486 +       if (!nxi)
9487 +               return 1;
9488 +       if (NX_IPV4(nxi))
9489 +               return 1;
9490 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9491 +               return 1;
9492 +       return 0;
9493 +}
9494 +
9495 +#else /* CONFIG_INET */
9496 +
9497 +static inline
9498 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9499 +{
9500 +       return 1;
9501 +}
9502 +
9503 +static inline
9504 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9505 +{
9506 +       return 1;
9507 +}
9508 +
9509 +static inline
9510 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9511 +{
9512 +       return 1;
9513 +}
9514 +
9515 +static inline
9516 +int nx_info_has_v4(struct nx_info *nxi)
9517 +{
9518 +       return 0;
9519 +}
9520 +
9521 +#endif /* CONFIG_INET */
9522 +
9523 +#define current_nx_info_has_v4() \
9524 +       nx_info_has_v4(current_nx_info())
9525 +
9526 +#else
9527 +// #warning duplicate inclusion
9528 +#endif
9529 diff -NurpP --minimal linux-3.7/include/linux/vs_inet6.h linux-3.7-vs2.3.5.1/include/linux/vs_inet6.h
9530 --- linux-3.7/include/linux/vs_inet6.h  1970-01-01 00:00:00.000000000 +0000
9531 +++ linux-3.7-vs2.3.5.1/include/linux/vs_inet6.h        2012-12-11 15:56:32.000000000 +0000
9532 @@ -0,0 +1,246 @@
9533 +#ifndef _VS_INET6_H
9534 +#define _VS_INET6_H
9535 +
9536 +#include "vserver/base.h"
9537 +#include "vserver/network.h"
9538 +#include "vserver/debug.h"
9539 +
9540 +#include <net/ipv6.h>
9541 +
9542 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9543 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9544 +
9545 +
9546 +#ifdef CONFIG_IPV6
9547 +
9548 +static inline
9549 +int v6_addr_match(struct nx_addr_v6 *nxa,
9550 +       const struct in6_addr *addr, uint16_t mask)
9551 +{
9552 +       int ret = 0;
9553 +
9554 +       switch (nxa->type & mask) {
9555 +       case NXA_TYPE_MASK:
9556 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9557 +               break;
9558 +       case NXA_TYPE_ADDR:
9559 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9560 +               break;
9561 +       case NXA_TYPE_ANY:
9562 +               ret = 1;
9563 +               break;
9564 +       }
9565 +       vxdprintk(VXD_CBIT(net, 0),
9566 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9567 +               nxa, NXAV6(nxa), addr, mask, ret);
9568 +       return ret;
9569 +}
9570 +
9571 +static inline
9572 +int v6_addr_in_nx_info(struct nx_info *nxi,
9573 +       const struct in6_addr *addr, uint16_t mask)
9574 +{
9575 +       struct nx_addr_v6 *nxa;
9576 +       int ret = 1;
9577 +
9578 +       if (!nxi)
9579 +               goto out;
9580 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9581 +               if (v6_addr_match(nxa, addr, mask))
9582 +                       goto out;
9583 +       ret = 0;
9584 +out:
9585 +       vxdprintk(VXD_CBIT(net, 0),
9586 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9587 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9588 +       return ret;
9589 +}
9590 +
9591 +static inline
9592 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9593 +{
9594 +       /* FIXME: needs full range checks */
9595 +       return v6_addr_match(nxa, &addr->ip, mask);
9596 +}
9597 +
9598 +static inline
9599 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9600 +{
9601 +       struct nx_addr_v6 *ptr;
9602 +
9603 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9604 +               if (v6_nx_addr_match(ptr, nxa, mask))
9605 +                       return 1;
9606 +       return 0;
9607 +}
9608 +
9609 +
9610 +/*
9611 + *     Check if a given address matches for a socket
9612 + *
9613 + *     nxi:            the socket's nx_info if any
9614 + *     addr:           to be verified address
9615 + */
9616 +static inline
9617 +int v6_sock_addr_match (
9618 +       struct nx_info *nxi,
9619 +       struct inet_sock *inet,
9620 +       struct in6_addr *addr)
9621 +{
9622 +       struct sock *sk = &inet->sk;
9623 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9624 +
9625 +       if (!ipv6_addr_any(addr) &&
9626 +               ipv6_addr_equal(saddr, addr))
9627 +               return 1;
9628 +       if (ipv6_addr_any(saddr))
9629 +               return v6_addr_in_nx_info(nxi, addr, -1);
9630 +       return 0;
9631 +}
9632 +
9633 +/*
9634 + *     check if address is covered by socket
9635 + *
9636 + *     sk:     the socket to check against
9637 + *     addr:   the address in question (must be != 0)
9638 + */
9639 +
9640 +static inline
9641 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9642 +{
9643 +       struct nx_info *nxi = sk->sk_nx_info;
9644 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9645 +
9646 +       vxdprintk(VXD_CBIT(net, 5),
9647 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9648 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9649 +               (sk->sk_socket?sk->sk_socket->flags:0));
9650 +
9651 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9652 +               return v6_addr_match(nxa, saddr, -1);
9653 +       } else if (nxi) {               /* match against nx_info */
9654 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9655 +       } else {                        /* unrestricted any socket */
9656 +               return 1;
9657 +       }
9658 +}
9659 +
9660 +
9661 +/* inet related checks and helpers */
9662 +
9663 +
9664 +struct in_ifaddr;
9665 +struct net_device;
9666 +struct sock;
9667 +
9668 +
9669 +#include <linux/netdevice.h>
9670 +#include <linux/inetdevice.h>
9671 +#include <net/inet_timewait_sock.h>
9672 +
9673 +
9674 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9675 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9676 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9677 +
9678 +
9679 +
9680 +static inline
9681 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9682 +{
9683 +       if (!nxi)
9684 +               return 1;
9685 +       if (!ifa)
9686 +               return 0;
9687 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9688 +}
9689 +
9690 +static inline
9691 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9692 +{
9693 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9694 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9695 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9696 +
9697 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9698 +               return 1;
9699 +       if (v6_ifa_in_nx_info(ifa, nxi))
9700 +               return 1;
9701 +       return 0;
9702 +}
9703 +
9704 +
9705 +struct nx_v6_sock_addr {
9706 +       struct in6_addr saddr;  /* Address used for validation */
9707 +       struct in6_addr baddr;  /* Address used for socket bind */
9708 +};
9709 +
9710 +static inline
9711 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9712 +       struct nx_v6_sock_addr *nsa)
9713 +{
9714 +       // struct sock *sk = &inet->sk;
9715 +       // struct nx_info *nxi = sk->sk_nx_info;
9716 +       struct in6_addr saddr = addr->sin6_addr;
9717 +       struct in6_addr baddr = saddr;
9718 +
9719 +       nsa->saddr = saddr;
9720 +       nsa->baddr = baddr;
9721 +       return 0;
9722 +}
9723 +
9724 +static inline
9725 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9726 +{
9727 +       // struct sock *sk = &inet->sk;
9728 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9729 +
9730 +       // *saddr = nsa->baddr;
9731 +       // inet->inet_saddr = nsa->baddr;
9732 +}
9733 +
9734 +static inline
9735 +int nx_info_has_v6(struct nx_info *nxi)
9736 +{
9737 +       if (!nxi)
9738 +               return 1;
9739 +       if (NX_IPV6(nxi))
9740 +               return 1;
9741 +       return 0;
9742 +}
9743 +
9744 +#else /* CONFIG_IPV6 */
9745 +
9746 +static inline
9747 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9748 +{
9749 +       return 1;
9750 +}
9751 +
9752 +
9753 +static inline
9754 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9755 +{
9756 +       return 1;
9757 +}
9758 +
9759 +static inline
9760 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9761 +{
9762 +       return 1;
9763 +}
9764 +
9765 +static inline
9766 +int nx_info_has_v6(struct nx_info *nxi)
9767 +{
9768 +       return 0;
9769 +}
9770 +
9771 +#endif /* CONFIG_IPV6 */
9772 +
9773 +#define current_nx_info_has_v6() \
9774 +       nx_info_has_v6(current_nx_info())
9775 +
9776 +#else
9777 +#warning duplicate inclusion
9778 +#endif
9779 diff -NurpP --minimal linux-3.7/include/linux/vs_limit.h linux-3.7-vs2.3.5.1/include/linux/vs_limit.h
9780 --- linux-3.7/include/linux/vs_limit.h  1970-01-01 00:00:00.000000000 +0000
9781 +++ linux-3.7-vs2.3.5.1/include/linux/vs_limit.h        2012-12-11 15:56:32.000000000 +0000
9782 @@ -0,0 +1,140 @@
9783 +#ifndef _VS_LIMIT_H
9784 +#define _VS_LIMIT_H
9785 +
9786 +#include "vserver/limit.h"
9787 +#include "vserver/base.h"
9788 +#include "vserver/context.h"
9789 +#include "vserver/debug.h"
9790 +#include "vserver/context.h"
9791 +#include "vserver/limit_int.h"
9792 +
9793 +
9794 +#define vx_acc_cres(v, d, p, r) \
9795 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9796 +
9797 +#define vx_acc_cres_cond(x, d, p, r) \
9798 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9799 +       r, d, p, __FILE__, __LINE__)
9800 +
9801 +
9802 +#define vx_add_cres(v, a, p, r) \
9803 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9804 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9805 +
9806 +#define vx_add_cres_cond(x, a, p, r) \
9807 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9808 +       r, a, p, __FILE__, __LINE__)
9809 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9810 +
9811 +
9812 +/* process and file limits */
9813 +
9814 +#define vx_nproc_inc(p) \
9815 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9816 +
9817 +#define vx_nproc_dec(p) \
9818 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9819 +
9820 +#define vx_files_inc(f) \
9821 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9822 +
9823 +#define vx_files_dec(f) \
9824 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9825 +
9826 +#define vx_locks_inc(l) \
9827 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9828 +
9829 +#define vx_locks_dec(l) \
9830 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9831 +
9832 +#define vx_openfd_inc(f) \
9833 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9834 +
9835 +#define vx_openfd_dec(f) \
9836 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9837 +
9838 +
9839 +#define vx_cres_avail(v, n, r) \
9840 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9841 +
9842 +
9843 +#define vx_nproc_avail(n) \
9844 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9845 +
9846 +#define vx_files_avail(n) \
9847 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9848 +
9849 +#define vx_locks_avail(n) \
9850 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9851 +
9852 +#define vx_openfd_avail(n) \
9853 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9854 +
9855 +
9856 +/* dentry limits */
9857 +
9858 +#define vx_dentry_inc(d) do {                                          \
9859 +       if ((d)->d_count == 1)                                          \
9860 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9861 +       } while (0)
9862 +
9863 +#define vx_dentry_dec(d) do {                                          \
9864 +       if ((d)->d_count == 0)                                          \
9865 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9866 +       } while (0)
9867 +
9868 +#define vx_dentry_avail(n) \
9869 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9870 +
9871 +
9872 +/* socket limits */
9873 +
9874 +#define vx_sock_inc(s) \
9875 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9876 +
9877 +#define vx_sock_dec(s) \
9878 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9879 +
9880 +#define vx_sock_avail(n) \
9881 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9882 +
9883 +
9884 +/* ipc resource limits */
9885 +
9886 +#define vx_ipcmsg_add(v, u, a) \
9887 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9888 +
9889 +#define vx_ipcmsg_sub(v, u, a) \
9890 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9891 +
9892 +#define vx_ipcmsg_avail(v, a) \
9893 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9894 +
9895 +
9896 +#define vx_ipcshm_add(v, k, a) \
9897 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9898 +
9899 +#define vx_ipcshm_sub(v, k, a) \
9900 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9901 +
9902 +#define vx_ipcshm_avail(v, a) \
9903 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9904 +
9905 +
9906 +#define vx_semary_inc(a) \
9907 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9908 +
9909 +#define vx_semary_dec(a) \
9910 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9911 +
9912 +
9913 +#define vx_nsems_add(a,n) \
9914 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9915 +
9916 +#define vx_nsems_sub(a,n) \
9917 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9918 +
9919 +
9920 +#else
9921 +#warning duplicate inclusion
9922 +#endif
9923 diff -NurpP --minimal linux-3.7/include/linux/vs_network.h linux-3.7-vs2.3.5.1/include/linux/vs_network.h
9924 --- linux-3.7/include/linux/vs_network.h        1970-01-01 00:00:00.000000000 +0000
9925 +++ linux-3.7-vs2.3.5.1/include/linux/vs_network.h      2012-12-11 15:56:32.000000000 +0000
9926 @@ -0,0 +1,169 @@
9927 +#ifndef _NX_VS_NETWORK_H
9928 +#define _NX_VS_NETWORK_H
9929 +
9930 +#include "vserver/context.h"
9931 +#include "vserver/network.h"
9932 +#include "vserver/base.h"
9933 +#include "vserver/check.h"
9934 +#include "vserver/debug.h"
9935 +
9936 +#include <linux/sched.h>
9937 +
9938 +
9939 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9940 +
9941 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9942 +       const char *_file, int _line)
9943 +{
9944 +       if (!nxi)
9945 +               return NULL;
9946 +
9947 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9948 +               nxi, nxi ? nxi->nx_id : 0,
9949 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9950 +               _file, _line);
9951 +
9952 +       atomic_inc(&nxi->nx_usecnt);
9953 +       return nxi;
9954 +}
9955 +
9956 +
9957 +extern void free_nx_info(struct nx_info *);
9958 +
9959 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9960 +
9961 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9962 +{
9963 +       if (!nxi)
9964 +               return;
9965 +
9966 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9967 +               nxi, nxi ? nxi->nx_id : 0,
9968 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9969 +               _file, _line);
9970 +
9971 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9972 +               free_nx_info(nxi);
9973 +}
9974 +
9975 +
9976 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9977 +
9978 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9979 +               const char *_file, int _line)
9980 +{
9981 +       if (nxi) {
9982 +               vxlprintk(VXD_CBIT(nid, 3),
9983 +                       "init_nx_info(%p[#%d.%d])",
9984 +                       nxi, nxi ? nxi->nx_id : 0,
9985 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9986 +                       _file, _line);
9987 +
9988 +               atomic_inc(&nxi->nx_usecnt);
9989 +       }
9990 +       *nxp = nxi;
9991 +}
9992 +
9993 +
9994 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9995 +
9996 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9997 +       const char *_file, int _line)
9998 +{
9999 +       struct nx_info *nxo;
10000 +
10001 +       if (!nxi)
10002 +               return;
10003 +
10004 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10005 +               nxi, nxi ? nxi->nx_id : 0,
10006 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10007 +               _file, _line);
10008 +
10009 +       atomic_inc(&nxi->nx_usecnt);
10010 +       nxo = xchg(nxp, nxi);
10011 +       BUG_ON(nxo);
10012 +}
10013 +
10014 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10015 +
10016 +static inline void __clr_nx_info(struct nx_info **nxp,
10017 +       const char *_file, int _line)
10018 +{
10019 +       struct nx_info *nxo;
10020 +
10021 +       nxo = xchg(nxp, NULL);
10022 +       if (!nxo)
10023 +               return;
10024 +
10025 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10026 +               nxo, nxo ? nxo->nx_id : 0,
10027 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10028 +               _file, _line);
10029 +
10030 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10031 +               free_nx_info(nxo);
10032 +}
10033 +
10034 +
10035 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10036 +
10037 +static inline void __claim_nx_info(struct nx_info *nxi,
10038 +       struct task_struct *task, const char *_file, int _line)
10039 +{
10040 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10041 +               nxi, nxi ? nxi->nx_id : 0,
10042 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10043 +               nxi?atomic_read(&nxi->nx_tasks):0,
10044 +               task, _file, _line);
10045 +
10046 +       atomic_inc(&nxi->nx_tasks);
10047 +}
10048 +
10049 +
10050 +extern void unhash_nx_info(struct nx_info *);
10051 +
10052 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10053 +
10054 +static inline void __release_nx_info(struct nx_info *nxi,
10055 +       struct task_struct *task, const char *_file, int _line)
10056 +{
10057 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10058 +               nxi, nxi ? nxi->nx_id : 0,
10059 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10060 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10061 +               task, _file, _line);
10062 +
10063 +       might_sleep();
10064 +
10065 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10066 +               unhash_nx_info(nxi);
10067 +}
10068 +
10069 +
10070 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10071 +
10072 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10073 +       const char *_file, int _line)
10074 +{
10075 +       struct nx_info *nxi;
10076 +
10077 +       task_lock(p);
10078 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10079 +               p, _file, _line);
10080 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10081 +       task_unlock(p);
10082 +       return nxi;
10083 +}
10084 +
10085 +
10086 +static inline void exit_nx_info(struct task_struct *p)
10087 +{
10088 +       if (p->nx_info)
10089 +               release_nx_info(p->nx_info, p);
10090 +}
10091 +
10092 +
10093 +#else
10094 +#warning duplicate inclusion
10095 +#endif
10096 diff -NurpP --minimal linux-3.7/include/linux/vs_pid.h linux-3.7-vs2.3.5.1/include/linux/vs_pid.h
10097 --- linux-3.7/include/linux/vs_pid.h    1970-01-01 00:00:00.000000000 +0000
10098 +++ linux-3.7-vs2.3.5.1/include/linux/vs_pid.h  2012-12-11 15:56:32.000000000 +0000
10099 @@ -0,0 +1,50 @@
10100 +#ifndef _VS_PID_H
10101 +#define _VS_PID_H
10102 +
10103 +#include "vserver/base.h"
10104 +#include "vserver/check.h"
10105 +#include "vserver/context.h"
10106 +#include "vserver/debug.h"
10107 +#include "vserver/pid.h"
10108 +#include <linux/pid_namespace.h>
10109 +
10110 +
10111 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10112 +
10113 +static inline
10114 +int vx_proc_task_visible(struct task_struct *task)
10115 +{
10116 +       if ((task->pid == 1) &&
10117 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10118 +               /* show a blend through init */
10119 +               goto visible;
10120 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10121 +               goto visible;
10122 +       return 0;
10123 +visible:
10124 +       return 1;
10125 +}
10126 +
10127 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10128 +
10129 +
10130 +static inline
10131 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10132 +{
10133 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10134 +
10135 +       if (task && !vx_proc_task_visible(task)) {
10136 +               vxdprintk(VXD_CBIT(misc, 6),
10137 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10138 +                       task, task->xid, task->pid,
10139 +                       current, current->xid, current->pid);
10140 +               put_task_struct(task);
10141 +               task = NULL;
10142 +       }
10143 +       return task;
10144 +}
10145 +
10146 +
10147 +#else
10148 +#warning duplicate inclusion
10149 +#endif
10150 diff -NurpP --minimal linux-3.7/include/linux/vs_sched.h linux-3.7-vs2.3.5.1/include/linux/vs_sched.h
10151 --- linux-3.7/include/linux/vs_sched.h  1970-01-01 00:00:00.000000000 +0000
10152 +++ linux-3.7-vs2.3.5.1/include/linux/vs_sched.h        2012-12-11 15:56:32.000000000 +0000
10153 @@ -0,0 +1,40 @@
10154 +#ifndef _VS_SCHED_H
10155 +#define _VS_SCHED_H
10156 +
10157 +#include "vserver/base.h"
10158 +#include "vserver/context.h"
10159 +#include "vserver/sched.h"
10160 +
10161 +
10162 +#define MAX_PRIO_BIAS           20
10163 +#define MIN_PRIO_BIAS          -20
10164 +
10165 +static inline
10166 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10167 +{
10168 +       struct vx_info *vxi = p->vx_info;
10169 +
10170 +       if (vxi)
10171 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10172 +       return prio;
10173 +}
10174 +
10175 +static inline void vx_account_user(struct vx_info *vxi,
10176 +       cputime_t cputime, int nice)
10177 +{
10178 +       if (!vxi)
10179 +               return;
10180 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10181 +}
10182 +
10183 +static inline void vx_account_system(struct vx_info *vxi,
10184 +       cputime_t cputime, int idle)
10185 +{
10186 +       if (!vxi)
10187 +               return;
10188 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10189 +}
10190 +
10191 +#else
10192 +#warning duplicate inclusion
10193 +#endif
10194 diff -NurpP --minimal linux-3.7/include/linux/vs_socket.h linux-3.7-vs2.3.5.1/include/linux/vs_socket.h
10195 --- linux-3.7/include/linux/vs_socket.h 1970-01-01 00:00:00.000000000 +0000
10196 +++ linux-3.7-vs2.3.5.1/include/linux/vs_socket.h       2012-12-11 15:56:32.000000000 +0000
10197 @@ -0,0 +1,67 @@
10198 +#ifndef _VS_SOCKET_H
10199 +#define _VS_SOCKET_H
10200 +
10201 +#include "vserver/debug.h"
10202 +#include "vserver/base.h"
10203 +#include "vserver/cacct.h"
10204 +#include "vserver/context.h"
10205 +#include "vserver/tag.h"
10206 +
10207 +
10208 +/* socket accounting */
10209 +
10210 +#include <linux/socket.h>
10211 +
10212 +static inline int vx_sock_type(int family)
10213 +{
10214 +       switch (family) {
10215 +       case PF_UNSPEC:
10216 +               return VXA_SOCK_UNSPEC;
10217 +       case PF_UNIX:
10218 +               return VXA_SOCK_UNIX;
10219 +       case PF_INET:
10220 +               return VXA_SOCK_INET;
10221 +       case PF_INET6:
10222 +               return VXA_SOCK_INET6;
10223 +       case PF_PACKET:
10224 +               return VXA_SOCK_PACKET;
10225 +       default:
10226 +               return VXA_SOCK_OTHER;
10227 +       }
10228 +}
10229 +
10230 +#define vx_acc_sock(v, f, p, s) \
10231 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10232 +
10233 +static inline void __vx_acc_sock(struct vx_info *vxi,
10234 +       int family, int pos, int size, char *file, int line)
10235 +{
10236 +       if (vxi) {
10237 +               int type = vx_sock_type(family);
10238 +
10239 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10240 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10241 +       }
10242 +}
10243 +
10244 +#define vx_sock_recv(sk, s) \
10245 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10246 +#define vx_sock_send(sk, s) \
10247 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10248 +#define vx_sock_fail(sk, s) \
10249 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10250 +
10251 +
10252 +#define sock_vx_init(s) do {           \
10253 +       (s)->sk_xid = 0;                \
10254 +       (s)->sk_vx_info = NULL;         \
10255 +       } while (0)
10256 +
10257 +#define sock_nx_init(s) do {           \
10258 +       (s)->sk_nid = 0;                \
10259 +       (s)->sk_nx_info = NULL;         \
10260 +       } while (0)
10261 +
10262 +#else
10263 +#warning duplicate inclusion
10264 +#endif
10265 diff -NurpP --minimal linux-3.7/include/linux/vs_tag.h linux-3.7-vs2.3.5.1/include/linux/vs_tag.h
10266 --- linux-3.7/include/linux/vs_tag.h    1970-01-01 00:00:00.000000000 +0000
10267 +++ linux-3.7-vs2.3.5.1/include/linux/vs_tag.h  2012-12-11 15:56:32.000000000 +0000
10268 @@ -0,0 +1,47 @@
10269 +#ifndef _VS_TAG_H
10270 +#define _VS_TAG_H
10271 +
10272 +#include <linux/vserver/tag.h>
10273 +
10274 +/* check conditions */
10275 +
10276 +#define DX_ADMIN       0x0001
10277 +#define DX_WATCH       0x0002
10278 +#define DX_HOSTID      0x0008
10279 +
10280 +#define DX_IDENT       0x0010
10281 +
10282 +#define DX_ARG_MASK    0x0010
10283 +
10284 +
10285 +#define dx_task_tag(t) ((t)->tag)
10286 +
10287 +#define dx_current_tag() dx_task_tag(current)
10288 +
10289 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10290 +
10291 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10292 +
10293 +
10294 +/*
10295 + * check current context for ADMIN/WATCH and
10296 + * optionally against supplied argument
10297 + */
10298 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10299 +{
10300 +       if (mode & DX_ARG_MASK) {
10301 +               if ((mode & DX_IDENT) && (id == cid))
10302 +                       return 1;
10303 +       }
10304 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10305 +               ((mode & DX_WATCH) && (cid == 1)) ||
10306 +               ((mode & DX_HOSTID) && (id == 0)));
10307 +}
10308 +
10309 +struct inode;
10310 +int dx_permission(const struct inode *inode, int mask);
10311 +
10312 +
10313 +#else
10314 +#warning duplicate inclusion
10315 +#endif
10316 diff -NurpP --minimal linux-3.7/include/linux/vs_time.h linux-3.7-vs2.3.5.1/include/linux/vs_time.h
10317 --- linux-3.7/include/linux/vs_time.h   1970-01-01 00:00:00.000000000 +0000
10318 +++ linux-3.7-vs2.3.5.1/include/linux/vs_time.h 2012-12-11 15:56:32.000000000 +0000
10319 @@ -0,0 +1,19 @@
10320 +#ifndef _VS_TIME_H
10321 +#define _VS_TIME_H
10322 +
10323 +
10324 +/* time faking stuff */
10325 +
10326 +#ifdef CONFIG_VSERVER_VTIME
10327 +
10328 +extern void vx_adjust_timespec(struct timespec *ts);
10329 +extern int vx_settimeofday(const struct timespec *ts);
10330 +
10331 +#else
10332 +#define        vx_adjust_timespec(t)   do { } while (0)
10333 +#define        vx_settimeofday(t)      do_settimeofday(t)
10334 +#endif
10335 +
10336 +#else
10337 +#warning duplicate inclusion
10338 +#endif
10339 diff -NurpP --minimal linux-3.7/include/linux/vserver/Kbuild linux-3.7-vs2.3.5.1/include/linux/vserver/Kbuild
10340 --- linux-3.7/include/linux/vserver/Kbuild      1970-01-01 00:00:00.000000000 +0000
10341 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/Kbuild    2012-12-11 15:56:32.000000000 +0000
10342 @@ -0,0 +1,8 @@
10343 +
10344 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10345 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10346 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10347 +       debug_cmd.h device_cmd.h
10348 +
10349 +header-y += switch.h network.h monitor.h inode.h device.h
10350 +
10351 diff -NurpP --minimal linux-3.7/include/linux/vserver/base.h linux-3.7-vs2.3.5.1/include/linux/vserver/base.h
10352 --- linux-3.7/include/linux/vserver/base.h      1970-01-01 00:00:00.000000000 +0000
10353 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/base.h    2012-12-11 15:56:32.000000000 +0000
10354 @@ -0,0 +1,178 @@
10355 +#ifndef _VX_BASE_H
10356 +#define _VX_BASE_H
10357 +
10358 +
10359 +/* context state changes */
10360 +
10361 +enum {
10362 +       VSC_STARTUP = 1,
10363 +       VSC_SHUTDOWN,
10364 +
10365 +       VSC_NETUP,
10366 +       VSC_NETDOWN,
10367 +};
10368 +
10369 +
10370 +
10371 +#define vx_task_xid(t) ((t)->xid)
10372 +
10373 +#define vx_current_xid() vx_task_xid(current)
10374 +
10375 +#define current_vx_info() (current->vx_info)
10376 +
10377 +
10378 +#define nx_task_nid(t) ((t)->nid)
10379 +
10380 +#define nx_current_nid() nx_task_nid(current)
10381 +
10382 +#define current_nx_info() (current->nx_info)
10383 +
10384 +
10385 +/* generic flag merging */
10386 +
10387 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10388 +
10389 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10390 +
10391 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10392 +
10393 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10394 +
10395 +
10396 +/* context flags */
10397 +
10398 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10399 +
10400 +#define vx_current_flags()     __vx_flags(current_vx_info())
10401 +
10402 +#define vx_info_flags(v, m, f) \
10403 +       vs_check_flags(__vx_flags(v), m, f)
10404 +
10405 +#define task_vx_flags(t, m, f) \
10406 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10407 +
10408 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10409 +
10410 +
10411 +/* context caps */
10412 +
10413 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10414 +
10415 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10416 +
10417 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10418 +
10419 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10420 +
10421 +
10422 +
10423 +/* network flags */
10424 +
10425 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10426 +
10427 +#define nx_current_flags()     __nx_flags(current_nx_info())
10428 +
10429 +#define nx_info_flags(n, m, f) \
10430 +       vs_check_flags(__nx_flags(n), m, f)
10431 +
10432 +#define task_nx_flags(t, m, f) \
10433 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10434 +
10435 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10436 +
10437 +
10438 +/* network caps */
10439 +
10440 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10441 +
10442 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10443 +
10444 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10445 +
10446 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10447 +
10448 +
10449 +/* context mask capabilities */
10450 +
10451 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10452 +
10453 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10454 +
10455 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10456 +
10457 +
10458 +/* context bcap mask */
10459 +
10460 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10461 +
10462 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10463 +
10464 +
10465 +/* mask given bcaps */
10466 +
10467 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10468 +
10469 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10470 +
10471 +
10472 +/* masked cap_bset */
10473 +
10474 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10475 +
10476 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10477 +
10478 +#if 0
10479 +#define vx_info_mbcap(v, b) \
10480 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10481 +       vx_info_bcaps(v, b) : (b))
10482 +
10483 +#define task_vx_mbcap(t, b) \
10484 +       vx_info_mbcap((t)->vx_info, (t)->b)
10485 +
10486 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10487 +#endif
10488 +
10489 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10490 +
10491 +#define vx_capable(b, c) (capable(b) || \
10492 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10493 +
10494 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10495 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10496 +
10497 +#define nx_capable(b, c) (capable(b) || \
10498 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10499 +
10500 +#define vx_task_initpid(t, n) \
10501 +       ((t)->vx_info && \
10502 +       ((t)->vx_info->vx_initpid == (n)))
10503 +
10504 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10505 +
10506 +
10507 +/* context unshare mask */
10508 +
10509 +#define __vx_umask(v)          ((v)->vx_umask)
10510 +
10511 +#define vx_current_umask()     __vx_umask(current_vx_info())
10512 +
10513 +#define vx_can_unshare(b, f) (capable(b) || \
10514 +       (cap_raised(current_cap(), b) && \
10515 +       !((f) & ~vx_current_umask())))
10516 +
10517 +
10518 +#define __vx_wmask(v)          ((v)->vx_wmask)
10519 +
10520 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10521 +
10522 +
10523 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10524 +
10525 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10526 +
10527 +
10528 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10529 +
10530 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10531 +
10532 +#endif
10533 diff -NurpP --minimal linux-3.7/include/linux/vserver/cacct.h linux-3.7-vs2.3.5.1/include/linux/vserver/cacct.h
10534 --- linux-3.7/include/linux/vserver/cacct.h     1970-01-01 00:00:00.000000000 +0000
10535 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/cacct.h   2012-12-11 15:56:32.000000000 +0000
10536 @@ -0,0 +1,15 @@
10537 +#ifndef _VX_CACCT_H
10538 +#define _VX_CACCT_H
10539 +
10540 +
10541 +enum sock_acc_field {
10542 +       VXA_SOCK_UNSPEC = 0,
10543 +       VXA_SOCK_UNIX,
10544 +       VXA_SOCK_INET,
10545 +       VXA_SOCK_INET6,
10546 +       VXA_SOCK_PACKET,
10547 +       VXA_SOCK_OTHER,
10548 +       VXA_SOCK_SIZE   /* array size */
10549 +};
10550 +
10551 +#endif /* _VX_CACCT_H */
10552 diff -NurpP --minimal linux-3.7/include/linux/vserver/cacct_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/cacct_cmd.h
10553 --- linux-3.7/include/linux/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
10554 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/cacct_cmd.h       2012-12-11 15:56:32.000000000 +0000
10555 @@ -0,0 +1,23 @@
10556 +#ifndef _VX_CACCT_CMD_H
10557 +#define _VX_CACCT_CMD_H
10558 +
10559 +
10560 +/* virtual host info name commands */
10561 +
10562 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10563 +
10564 +struct vcmd_sock_stat_v0 {
10565 +       uint32_t field;
10566 +       uint32_t count[3];
10567 +       uint64_t total[3];
10568 +};
10569 +
10570 +
10571 +#ifdef __KERNEL__
10572 +
10573 +#include <linux/compiler.h>
10574 +
10575 +extern int vc_sock_stat(struct vx_info *, void __user *);
10576 +
10577 +#endif /* __KERNEL__ */
10578 +#endif /* _VX_CACCT_CMD_H */
10579 diff -NurpP --minimal linux-3.7/include/linux/vserver/cacct_def.h linux-3.7-vs2.3.5.1/include/linux/vserver/cacct_def.h
10580 --- linux-3.7/include/linux/vserver/cacct_def.h 1970-01-01 00:00:00.000000000 +0000
10581 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/cacct_def.h       2012-12-11 15:56:32.000000000 +0000
10582 @@ -0,0 +1,43 @@
10583 +#ifndef _VX_CACCT_DEF_H
10584 +#define _VX_CACCT_DEF_H
10585 +
10586 +#include <asm/atomic.h>
10587 +#include <linux/vserver/cacct.h>
10588 +
10589 +
10590 +struct _vx_sock_acc {
10591 +       atomic_long_t count;
10592 +       atomic_long_t total;
10593 +};
10594 +
10595 +/* context sub struct */
10596 +
10597 +struct _vx_cacct {
10598 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10599 +       atomic_t slab[8];
10600 +       atomic_t page[6][8];
10601 +};
10602 +
10603 +#ifdef CONFIG_VSERVER_DEBUG
10604 +
10605 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10606 +{
10607 +       int i, j;
10608 +
10609 +       printk("\t_vx_cacct:");
10610 +       for (i = 0; i < 6; i++) {
10611 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10612 +
10613 +               printk("\t [%d] =", i);
10614 +               for (j = 0; j < 3; j++) {
10615 +                       printk(" [%d] = %8lu, %8lu", j,
10616 +                               atomic_long_read(&ptr[j].count),
10617 +                               atomic_long_read(&ptr[j].total));
10618 +               }
10619 +               printk("\n");
10620 +       }
10621 +}
10622 +
10623 +#endif
10624 +
10625 +#endif /* _VX_CACCT_DEF_H */
10626 diff -NurpP --minimal linux-3.7/include/linux/vserver/cacct_int.h linux-3.7-vs2.3.5.1/include/linux/vserver/cacct_int.h
10627 --- linux-3.7/include/linux/vserver/cacct_int.h 1970-01-01 00:00:00.000000000 +0000
10628 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/cacct_int.h       2012-12-11 15:56:32.000000000 +0000
10629 @@ -0,0 +1,21 @@
10630 +#ifndef _VX_CACCT_INT_H
10631 +#define _VX_CACCT_INT_H
10632 +
10633 +
10634 +#ifdef __KERNEL__
10635 +
10636 +static inline
10637 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10638 +{
10639 +       return atomic_long_read(&cacct->sock[type][pos].count);
10640 +}
10641 +
10642 +
10643 +static inline
10644 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10645 +{
10646 +       return atomic_long_read(&cacct->sock[type][pos].total);
10647 +}
10648 +
10649 +#endif /* __KERNEL__ */
10650 +#endif /* _VX_CACCT_INT_H */
10651 diff -NurpP --minimal linux-3.7/include/linux/vserver/check.h linux-3.7-vs2.3.5.1/include/linux/vserver/check.h
10652 --- linux-3.7/include/linux/vserver/check.h     1970-01-01 00:00:00.000000000 +0000
10653 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/check.h   2012-12-11 15:56:32.000000000 +0000
10654 @@ -0,0 +1,89 @@
10655 +#ifndef _VS_CHECK_H
10656 +#define _VS_CHECK_H
10657 +
10658 +
10659 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10660 +
10661 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10662 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10663 +#else
10664 +#define MIN_D_CONTEXT  65536
10665 +#endif
10666 +
10667 +/* check conditions */
10668 +
10669 +#define VS_ADMIN       0x0001
10670 +#define VS_WATCH       0x0002
10671 +#define VS_HIDE                0x0004
10672 +#define VS_HOSTID      0x0008
10673 +
10674 +#define VS_IDENT       0x0010
10675 +#define VS_EQUIV       0x0020
10676 +#define VS_PARENT      0x0040
10677 +#define VS_CHILD       0x0080
10678 +
10679 +#define VS_ARG_MASK    0x00F0
10680 +
10681 +#define VS_DYNAMIC     0x0100
10682 +#define VS_STATIC      0x0200
10683 +
10684 +#define VS_ATR_MASK    0x0F00
10685 +
10686 +#ifdef CONFIG_VSERVER_PRIVACY
10687 +#define VS_ADMIN_P     (0)
10688 +#define VS_WATCH_P     (0)
10689 +#else
10690 +#define VS_ADMIN_P     VS_ADMIN
10691 +#define VS_WATCH_P     VS_WATCH
10692 +#endif
10693 +
10694 +#define VS_HARDIRQ     0x1000
10695 +#define VS_SOFTIRQ     0x2000
10696 +#define VS_IRQ         0x4000
10697 +
10698 +#define VS_IRQ_MASK    0xF000
10699 +
10700 +#include <linux/hardirq.h>
10701 +
10702 +/*
10703 + * check current context for ADMIN/WATCH and
10704 + * optionally against supplied argument
10705 + */
10706 +static inline int __vs_check(int cid, int id, unsigned int mode)
10707 +{
10708 +       if (mode & VS_ARG_MASK) {
10709 +               if ((mode & VS_IDENT) && (id == cid))
10710 +                       return 1;
10711 +       }
10712 +       if (mode & VS_ATR_MASK) {
10713 +               if ((mode & VS_DYNAMIC) &&
10714 +                       (id >= MIN_D_CONTEXT) &&
10715 +                       (id <= MAX_S_CONTEXT))
10716 +                       return 1;
10717 +               if ((mode & VS_STATIC) &&
10718 +                       (id > 1) && (id < MIN_D_CONTEXT))
10719 +                       return 1;
10720 +       }
10721 +       if (mode & VS_IRQ_MASK) {
10722 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10723 +                       return 1;
10724 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10725 +                       return 1;
10726 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10727 +                       return 1;
10728 +       }
10729 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10730 +               ((mode & VS_WATCH) && (cid == 1)) ||
10731 +               ((mode & VS_HOSTID) && (id == 0)));
10732 +}
10733 +
10734 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10735 +
10736 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10737 +
10738 +
10739 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10740 +
10741 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10742 +
10743 +#endif
10744 diff -NurpP --minimal linux-3.7/include/linux/vserver/context.h linux-3.7-vs2.3.5.1/include/linux/vserver/context.h
10745 --- linux-3.7/include/linux/vserver/context.h   1970-01-01 00:00:00.000000000 +0000
10746 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/context.h 2012-12-11 15:56:32.000000000 +0000
10747 @@ -0,0 +1,188 @@
10748 +#ifndef _VX_CONTEXT_H
10749 +#define _VX_CONTEXT_H
10750 +
10751 +#include <linux/types.h>
10752 +#include <linux/capability.h>
10753 +
10754 +
10755 +/* context flags */
10756 +
10757 +#define VXF_INFO_SCHED         0x00000002
10758 +#define VXF_INFO_NPROC         0x00000004
10759 +#define VXF_INFO_PRIVATE       0x00000008
10760 +
10761 +#define VXF_INFO_INIT          0x00000010
10762 +#define VXF_INFO_HIDE          0x00000020
10763 +#define VXF_INFO_ULIMIT                0x00000040
10764 +#define VXF_INFO_NSPACE                0x00000080
10765 +
10766 +#define VXF_SCHED_HARD         0x00000100
10767 +#define VXF_SCHED_PRIO         0x00000200
10768 +#define VXF_SCHED_PAUSE                0x00000400
10769 +
10770 +#define VXF_VIRT_MEM           0x00010000
10771 +#define VXF_VIRT_UPTIME                0x00020000
10772 +#define VXF_VIRT_CPU           0x00040000
10773 +#define VXF_VIRT_LOAD          0x00080000
10774 +#define VXF_VIRT_TIME          0x00100000
10775 +
10776 +#define VXF_HIDE_MOUNT         0x01000000
10777 +/* was VXF_HIDE_NETIF          0x02000000 */
10778 +#define VXF_HIDE_VINFO         0x04000000
10779 +
10780 +#define VXF_STATE_SETUP                (1ULL << 32)
10781 +#define VXF_STATE_INIT         (1ULL << 33)
10782 +#define VXF_STATE_ADMIN                (1ULL << 34)
10783 +
10784 +#define VXF_SC_HELPER          (1ULL << 36)
10785 +#define VXF_REBOOT_KILL                (1ULL << 37)
10786 +#define VXF_PERSISTENT         (1ULL << 38)
10787 +
10788 +#define VXF_FORK_RSS           (1ULL << 48)
10789 +#define VXF_PROLIFIC           (1ULL << 49)
10790 +
10791 +#define VXF_IGNEG_NICE         (1ULL << 52)
10792 +
10793 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10794 +
10795 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10796 +
10797 +
10798 +/* context migration */
10799 +
10800 +#define VXM_SET_INIT           0x00000001
10801 +#define VXM_SET_REAPER         0x00000002
10802 +
10803 +/* context caps */
10804 +
10805 +#define VXC_SET_UTSNAME                0x00000001
10806 +#define VXC_SET_RLIMIT         0x00000002
10807 +#define VXC_FS_SECURITY                0x00000004
10808 +#define VXC_FS_TRUSTED         0x00000008
10809 +#define VXC_TIOCSTI            0x00000010
10810 +
10811 +/* was VXC_RAW_ICMP            0x00000100 */
10812 +#define VXC_SYSLOG             0x00001000
10813 +#define VXC_OOM_ADJUST         0x00002000
10814 +#define VXC_AUDIT_CONTROL      0x00004000
10815 +
10816 +#define VXC_SECURE_MOUNT       0x00010000
10817 +#define VXC_SECURE_REMOUNT     0x00020000
10818 +#define VXC_BINARY_MOUNT       0x00040000
10819 +
10820 +#define VXC_QUOTA_CTL          0x00100000
10821 +#define VXC_ADMIN_MAPPER       0x00200000
10822 +#define VXC_ADMIN_CLOOP                0x00400000
10823 +
10824 +#define VXC_KTHREAD            0x01000000
10825 +#define VXC_NAMESPACE          0x02000000
10826 +
10827 +
10828 +#ifdef __KERNEL__
10829 +
10830 +#include <linux/list.h>
10831 +#include <linux/spinlock.h>
10832 +#include <linux/rcupdate.h>
10833 +
10834 +#include "limit_def.h"
10835 +#include "sched_def.h"
10836 +#include "cvirt_def.h"
10837 +#include "cacct_def.h"
10838 +#include "device_def.h"
10839 +
10840 +#define VX_SPACES      2
10841 +
10842 +struct _vx_info_pc {
10843 +       struct _vx_sched_pc sched_pc;
10844 +       struct _vx_cvirt_pc cvirt_pc;
10845 +};
10846 +
10847 +struct _vx_space {
10848 +       unsigned long vx_nsmask;                /* assignment mask */
10849 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10850 +       struct fs_struct *vx_fs;                /* private namespace fs */
10851 +       const struct cred *vx_cred;             /* task credentials */
10852 +};
10853 +
10854 +struct vx_info {
10855 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10856 +       xid_t vx_id;                            /* context id */
10857 +       atomic_t vx_usecnt;                     /* usage count */
10858 +       atomic_t vx_tasks;                      /* tasks count */
10859 +       struct vx_info *vx_parent;              /* parent context */
10860 +       int vx_state;                           /* context state */
10861 +
10862 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10863 +
10864 +       uint64_t vx_flags;                      /* context flags */
10865 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10866 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10867 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10868 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10869 +
10870 +       struct task_struct *vx_reaper;          /* guest reaper process */
10871 +       pid_t vx_initpid;                       /* PID of guest init */
10872 +       int64_t vx_badness_bias;                /* OOM points bias */
10873 +
10874 +       struct _vx_limit limit;                 /* vserver limits */
10875 +       struct _vx_sched sched;                 /* vserver scheduler */
10876 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10877 +       struct _vx_cacct cacct;                 /* context accounting */
10878 +
10879 +       struct _vx_device dmap;                 /* default device map targets */
10880 +
10881 +#ifndef CONFIG_SMP
10882 +       struct _vx_info_pc info_pc;             /* per cpu data */
10883 +#else
10884 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10885 +#endif
10886 +
10887 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10888 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10889 +       int exit_code;                          /* last process exit code */
10890 +
10891 +       char vx_name[65];                       /* vserver name */
10892 +};
10893 +
10894 +#ifndef CONFIG_SMP
10895 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10896 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10897 +#else
10898 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10899 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10900 +#endif
10901 +
10902 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10903 +
10904 +
10905 +struct vx_info_save {
10906 +       struct vx_info *vxi;
10907 +       xid_t xid;
10908 +};
10909 +
10910 +
10911 +/* status flags */
10912 +
10913 +#define VXS_HASHED     0x0001
10914 +#define VXS_PAUSED     0x0010
10915 +#define VXS_SHUTDOWN   0x0100
10916 +#define VXS_HELPER     0x1000
10917 +#define VXS_RELEASED   0x8000
10918 +
10919 +
10920 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10921 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10922 +
10923 +extern struct vx_info *lookup_vx_info(int);
10924 +extern struct vx_info *lookup_or_create_vx_info(int);
10925 +
10926 +extern int get_xid_list(int, unsigned int *, int);
10927 +extern int xid_is_hashed(xid_t);
10928 +
10929 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10930 +
10931 +extern long vs_state_change(struct vx_info *, unsigned int);
10932 +
10933 +
10934 +#endif /* __KERNEL__ */
10935 +#endif /* _VX_CONTEXT_H */
10936 diff -NurpP --minimal linux-3.7/include/linux/vserver/context_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/context_cmd.h
10937 --- linux-3.7/include/linux/vserver/context_cmd.h       1970-01-01 00:00:00.000000000 +0000
10938 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/context_cmd.h     2012-12-11 15:56:32.000000000 +0000
10939 @@ -0,0 +1,162 @@
10940 +#ifndef _VX_CONTEXT_CMD_H
10941 +#define _VX_CONTEXT_CMD_H
10942 +
10943 +
10944 +/* vinfo commands */
10945 +
10946 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10947 +
10948 +#ifdef __KERNEL__
10949 +extern int vc_task_xid(uint32_t);
10950 +
10951 +#endif /* __KERNEL__ */
10952 +
10953 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10954 +
10955 +struct vcmd_vx_info_v0 {
10956 +       uint32_t xid;
10957 +       uint32_t initpid;
10958 +       /* more to come */
10959 +};
10960 +
10961 +#ifdef __KERNEL__
10962 +extern int vc_vx_info(struct vx_info *, void __user *);
10963 +
10964 +#endif /* __KERNEL__ */
10965 +
10966 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10967 +
10968 +struct vcmd_ctx_stat_v0 {
10969 +       uint32_t usecnt;
10970 +       uint32_t tasks;
10971 +       /* more to come */
10972 +};
10973 +
10974 +#ifdef __KERNEL__
10975 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10976 +
10977 +#endif /* __KERNEL__ */
10978 +
10979 +/* context commands */
10980 +
10981 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10982 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10983 +
10984 +struct vcmd_ctx_create {
10985 +       uint64_t flagword;
10986 +};
10987 +
10988 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10989 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10990 +
10991 +struct vcmd_ctx_migrate {
10992 +       uint64_t flagword;
10993 +};
10994 +
10995 +#ifdef __KERNEL__
10996 +extern int vc_ctx_create(uint32_t, void __user *);
10997 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10998 +
10999 +#endif /* __KERNEL__ */
11000 +
11001 +
11002 +/* flag commands */
11003 +
11004 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11005 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11006 +
11007 +struct vcmd_ctx_flags_v0 {
11008 +       uint64_t flagword;
11009 +       uint64_t mask;
11010 +};
11011 +
11012 +#ifdef __KERNEL__
11013 +extern int vc_get_cflags(struct vx_info *, void __user *);
11014 +extern int vc_set_cflags(struct vx_info *, void __user *);
11015 +
11016 +#endif /* __KERNEL__ */
11017 +
11018 +
11019 +/* context caps commands */
11020 +
11021 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11022 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11023 +
11024 +struct vcmd_ctx_caps_v1 {
11025 +       uint64_t ccaps;
11026 +       uint64_t cmask;
11027 +};
11028 +
11029 +#ifdef __KERNEL__
11030 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11031 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11032 +
11033 +#endif /* __KERNEL__ */
11034 +
11035 +
11036 +/* bcaps commands */
11037 +
11038 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11039 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11040 +
11041 +struct vcmd_bcaps {
11042 +       uint64_t bcaps;
11043 +       uint64_t bmask;
11044 +};
11045 +
11046 +#ifdef __KERNEL__
11047 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11048 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11049 +
11050 +#endif /* __KERNEL__ */
11051 +
11052 +
11053 +/* umask commands */
11054 +
11055 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11056 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11057 +
11058 +struct vcmd_umask {
11059 +       uint64_t umask;
11060 +       uint64_t mask;
11061 +};
11062 +
11063 +#ifdef __KERNEL__
11064 +extern int vc_get_umask(struct vx_info *, void __user *);
11065 +extern int vc_set_umask(struct vx_info *, void __user *);
11066 +
11067 +#endif /* __KERNEL__ */
11068 +
11069 +
11070 +/* wmask commands */
11071 +
11072 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11073 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11074 +
11075 +struct vcmd_wmask {
11076 +       uint64_t wmask;
11077 +       uint64_t mask;
11078 +};
11079 +
11080 +#ifdef __KERNEL__
11081 +extern int vc_get_wmask(struct vx_info *, void __user *);
11082 +extern int vc_set_wmask(struct vx_info *, void __user *);
11083 +
11084 +#endif /* __KERNEL__ */
11085 +
11086 +
11087 +/* OOM badness */
11088 +
11089 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11090 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11091 +
11092 +struct vcmd_badness_v0 {
11093 +       int64_t bias;
11094 +};
11095 +
11096 +#ifdef __KERNEL__
11097 +extern int vc_get_badness(struct vx_info *, void __user *);
11098 +extern int vc_set_badness(struct vx_info *, void __user *);
11099 +
11100 +#endif /* __KERNEL__ */
11101 +#endif /* _VX_CONTEXT_CMD_H */
11102 diff -NurpP --minimal linux-3.7/include/linux/vserver/cvirt.h linux-3.7-vs2.3.5.1/include/linux/vserver/cvirt.h
11103 --- linux-3.7/include/linux/vserver/cvirt.h     1970-01-01 00:00:00.000000000 +0000
11104 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/cvirt.h   2012-12-11 15:56:32.000000000 +0000
11105 @@ -0,0 +1,22 @@
11106 +#ifndef _VX_CVIRT_H
11107 +#define _VX_CVIRT_H
11108 +
11109 +
11110 +#ifdef __KERNEL__
11111 +
11112 +struct timespec;
11113 +
11114 +void vx_vsi_boottime(struct timespec *);
11115 +
11116 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11117 +
11118 +
11119 +struct vx_info;
11120 +
11121 +void vx_update_load(struct vx_info *);
11122 +
11123 +
11124 +int vx_do_syslog(int, char __user *, int);
11125 +
11126 +#endif /* __KERNEL__ */
11127 +#endif /* _VX_CVIRT_H */
11128 diff -NurpP --minimal linux-3.7/include/linux/vserver/cvirt_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/cvirt_cmd.h
11129 --- linux-3.7/include/linux/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
11130 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/cvirt_cmd.h       2012-12-11 15:56:32.000000000 +0000
11131 @@ -0,0 +1,53 @@
11132 +#ifndef _VX_CVIRT_CMD_H
11133 +#define _VX_CVIRT_CMD_H
11134 +
11135 +
11136 +/* virtual host info name commands */
11137 +
11138 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11139 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11140 +
11141 +struct vcmd_vhi_name_v0 {
11142 +       uint32_t field;
11143 +       char name[65];
11144 +};
11145 +
11146 +
11147 +enum vhi_name_field {
11148 +       VHIN_CONTEXT = 0,
11149 +       VHIN_SYSNAME,
11150 +       VHIN_NODENAME,
11151 +       VHIN_RELEASE,
11152 +       VHIN_VERSION,
11153 +       VHIN_MACHINE,
11154 +       VHIN_DOMAINNAME,
11155 +};
11156 +
11157 +
11158 +#ifdef __KERNEL__
11159 +
11160 +#include <linux/compiler.h>
11161 +
11162 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11163 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11164 +
11165 +#endif /* __KERNEL__ */
11166 +
11167 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11168 +
11169 +struct vcmd_virt_stat_v0 {
11170 +       uint64_t offset;
11171 +       uint64_t uptime;
11172 +       uint32_t nr_threads;
11173 +       uint32_t nr_running;
11174 +       uint32_t nr_uninterruptible;
11175 +       uint32_t nr_onhold;
11176 +       uint32_t nr_forks;
11177 +       uint32_t load[3];
11178 +};
11179 +
11180 +#ifdef __KERNEL__
11181 +extern int vc_virt_stat(struct vx_info *, void __user *);
11182 +
11183 +#endif /* __KERNEL__ */
11184 +#endif /* _VX_CVIRT_CMD_H */
11185 diff -NurpP --minimal linux-3.7/include/linux/vserver/cvirt_def.h linux-3.7-vs2.3.5.1/include/linux/vserver/cvirt_def.h
11186 --- linux-3.7/include/linux/vserver/cvirt_def.h 1970-01-01 00:00:00.000000000 +0000
11187 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/cvirt_def.h       2012-12-11 15:56:32.000000000 +0000
11188 @@ -0,0 +1,80 @@
11189 +#ifndef _VX_CVIRT_DEF_H
11190 +#define _VX_CVIRT_DEF_H
11191 +
11192 +#include <linux/jiffies.h>
11193 +#include <linux/spinlock.h>
11194 +#include <linux/wait.h>
11195 +#include <linux/time.h>
11196 +#include <asm/atomic.h>
11197 +
11198 +
11199 +struct _vx_usage_stat {
11200 +       uint64_t user;
11201 +       uint64_t nice;
11202 +       uint64_t system;
11203 +       uint64_t softirq;
11204 +       uint64_t irq;
11205 +       uint64_t idle;
11206 +       uint64_t iowait;
11207 +};
11208 +
11209 +struct _vx_syslog {
11210 +       wait_queue_head_t log_wait;
11211 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11212 +
11213 +       unsigned long log_start;        /* next char to be read by syslog() */
11214 +       unsigned long con_start;        /* next char to be sent to consoles */
11215 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11216 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11217 +
11218 +       char log_buf[1024];
11219 +};
11220 +
11221 +
11222 +/* context sub struct */
11223 +
11224 +struct _vx_cvirt {
11225 +       atomic_t nr_threads;            /* number of current threads */
11226 +       atomic_t nr_running;            /* number of running threads */
11227 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11228 +
11229 +       atomic_t nr_onhold;             /* processes on hold */
11230 +       uint32_t onhold_last;           /* jiffies when put on hold */
11231 +
11232 +       struct timespec bias_ts;        /* time offset to the host */
11233 +       struct timespec bias_idle;
11234 +       struct timespec bias_uptime;    /* context creation point */
11235 +       uint64_t bias_clock;            /* offset in clock_t */
11236 +
11237 +       spinlock_t load_lock;           /* lock for the load averages */
11238 +       atomic_t load_updates;          /* nr of load updates done so far */
11239 +       uint32_t load_last;             /* last time load was calculated */
11240 +       uint32_t load[3];               /* load averages 1,5,15 */
11241 +
11242 +       atomic_t total_forks;           /* number of forks so far */
11243 +
11244 +       struct _vx_syslog syslog;
11245 +};
11246 +
11247 +struct _vx_cvirt_pc {
11248 +       struct _vx_usage_stat cpustat;
11249 +};
11250 +
11251 +
11252 +#ifdef CONFIG_VSERVER_DEBUG
11253 +
11254 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11255 +{
11256 +       printk("\t_vx_cvirt:\n");
11257 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11258 +               atomic_read(&cvirt->nr_threads),
11259 +               atomic_read(&cvirt->nr_running),
11260 +               atomic_read(&cvirt->nr_uninterruptible),
11261 +               atomic_read(&cvirt->nr_onhold));
11262 +       /* add rest here */
11263 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11264 +}
11265 +
11266 +#endif
11267 +
11268 +#endif /* _VX_CVIRT_DEF_H */
11269 diff -NurpP --minimal linux-3.7/include/linux/vserver/debug.h linux-3.7-vs2.3.5.1/include/linux/vserver/debug.h
11270 --- linux-3.7/include/linux/vserver/debug.h     1970-01-01 00:00:00.000000000 +0000
11271 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/debug.h   2012-12-11 15:56:32.000000000 +0000
11272 @@ -0,0 +1,145 @@
11273 +#ifndef _VX_DEBUG_H
11274 +#define _VX_DEBUG_H
11275 +
11276 +
11277 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11278 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11279 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11280 +
11281 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11282 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11283 +#define VXF_DEV                "%p[%lu,%d:%d]"
11284 +
11285 +#if    defined(CONFIG_QUOTES_UTF8)
11286 +#define        VS_Q_LQM        "\xc2\xbb"
11287 +#define        VS_Q_RQM        "\xc2\xab"
11288 +#elif  defined(CONFIG_QUOTES_ASCII)
11289 +#define        VS_Q_LQM        "\x27"
11290 +#define        VS_Q_RQM        "\x27"
11291 +#else
11292 +#define        VS_Q_LQM        "\xbb"
11293 +#define        VS_Q_RQM        "\xab"
11294 +#endif
11295 +
11296 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11297 +
11298 +
11299 +#define vxd_path(p)                                            \
11300 +       ({ static char _buffer[PATH_MAX];                       \
11301 +          d_path(p, _buffer, sizeof(_buffer)); })
11302 +
11303 +#define vxd_cond_path(n)                                       \
11304 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11305 +
11306 +
11307 +#ifdef CONFIG_VSERVER_DEBUG
11308 +
11309 +extern unsigned int vs_debug_switch;
11310 +extern unsigned int vs_debug_xid;
11311 +extern unsigned int vs_debug_nid;
11312 +extern unsigned int vs_debug_tag;
11313 +extern unsigned int vs_debug_net;
11314 +extern unsigned int vs_debug_limit;
11315 +extern unsigned int vs_debug_cres;
11316 +extern unsigned int vs_debug_dlim;
11317 +extern unsigned int vs_debug_quota;
11318 +extern unsigned int vs_debug_cvirt;
11319 +extern unsigned int vs_debug_space;
11320 +extern unsigned int vs_debug_perm;
11321 +extern unsigned int vs_debug_misc;
11322 +
11323 +
11324 +#define VX_LOGLEVEL    "vxD: "
11325 +#define VX_PROC_FMT    "%p: "
11326 +#define VX_PROCESS     current
11327 +
11328 +#define vxdprintk(c, f, x...)                                  \
11329 +       do {                                                    \
11330 +               if (c)                                          \
11331 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11332 +                               VX_PROCESS , ##x);              \
11333 +       } while (0)
11334 +
11335 +#define vxlprintk(c, f, x...)                                  \
11336 +       do {                                                    \
11337 +               if (c)                                          \
11338 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11339 +       } while (0)
11340 +
11341 +#define vxfprintk(c, f, x...)                                  \
11342 +       do {                                                    \
11343 +               if (c)                                          \
11344 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11345 +       } while (0)
11346 +
11347 +
11348 +struct vx_info;
11349 +
11350 +void dump_vx_info(struct vx_info *, int);
11351 +void dump_vx_info_inactive(int);
11352 +
11353 +#else  /* CONFIG_VSERVER_DEBUG */
11354 +
11355 +#define vs_debug_switch        0
11356 +#define vs_debug_xid   0
11357 +#define vs_debug_nid   0
11358 +#define vs_debug_tag   0
11359 +#define vs_debug_net   0
11360 +#define vs_debug_limit 0
11361 +#define vs_debug_cres  0
11362 +#define vs_debug_dlim  0
11363 +#define vs_debug_quota 0
11364 +#define vs_debug_cvirt 0
11365 +#define vs_debug_space 0
11366 +#define vs_debug_perm  0
11367 +#define vs_debug_misc  0
11368 +
11369 +#define vxdprintk(x...) do { } while (0)
11370 +#define vxlprintk(x...) do { } while (0)
11371 +#define vxfprintk(x...) do { } while (0)
11372 +
11373 +#endif /* CONFIG_VSERVER_DEBUG */
11374 +
11375 +
11376 +#ifdef CONFIG_VSERVER_WARN
11377 +
11378 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11379 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11380 +#define VX_WARN_XID    "[xid #%u] "
11381 +#define VX_WARN_NID    "[nid #%u] "
11382 +#define VX_WARN_TAG    "[tag #%u] "
11383 +
11384 +#define vxwprintk(c, f, x...)                                  \
11385 +       do {                                                    \
11386 +               if (c)                                          \
11387 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11388 +       } while (0)
11389 +
11390 +#else  /* CONFIG_VSERVER_WARN */
11391 +
11392 +#define vxwprintk(x...) do { } while (0)
11393 +
11394 +#endif /* CONFIG_VSERVER_WARN */
11395 +
11396 +#define vxwprintk_task(c, f, x...)                             \
11397 +       vxwprintk(c, VX_WARN_TASK f,                            \
11398 +               current->comm, current->pid,                    \
11399 +               current->xid, current->nid, current->tag, ##x)
11400 +#define vxwprintk_xid(c, f, x...)                              \
11401 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11402 +#define vxwprintk_nid(c, f, x...)                              \
11403 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11404 +#define vxwprintk_tag(c, f, x...)                              \
11405 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11406 +
11407 +#ifdef CONFIG_VSERVER_DEBUG
11408 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11409 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11410 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11411 +#else
11412 +#define vxd_assert_lock(l)     do { } while (0)
11413 +#define vxd_assert(c, f, x...) do { } while (0)
11414 +#endif
11415 +
11416 +
11417 +#endif /* _VX_DEBUG_H */
11418 diff -NurpP --minimal linux-3.7/include/linux/vserver/debug_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/debug_cmd.h
11419 --- linux-3.7/include/linux/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
11420 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/debug_cmd.h       2012-12-11 15:56:32.000000000 +0000
11421 @@ -0,0 +1,58 @@
11422 +#ifndef _VX_DEBUG_CMD_H
11423 +#define _VX_DEBUG_CMD_H
11424 +
11425 +
11426 +/* debug commands */
11427 +
11428 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11429 +
11430 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11431 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11432 +
11433 +struct  vcmd_read_history_v0 {
11434 +       uint32_t index;
11435 +       uint32_t count;
11436 +       char __user *data;
11437 +};
11438 +
11439 +struct  vcmd_read_monitor_v0 {
11440 +       uint32_t index;
11441 +       uint32_t count;
11442 +       char __user *data;
11443 +};
11444 +
11445 +
11446 +#ifdef __KERNEL__
11447 +
11448 +#ifdef CONFIG_COMPAT
11449 +
11450 +#include <asm/compat.h>
11451 +
11452 +struct vcmd_read_history_v0_x32 {
11453 +       uint32_t index;
11454 +       uint32_t count;
11455 +       compat_uptr_t data_ptr;
11456 +};
11457 +
11458 +struct vcmd_read_monitor_v0_x32 {
11459 +       uint32_t index;
11460 +       uint32_t count;
11461 +       compat_uptr_t data_ptr;
11462 +};
11463 +
11464 +#endif  /* CONFIG_COMPAT */
11465 +
11466 +extern int vc_dump_history(uint32_t);
11467 +
11468 +extern int vc_read_history(uint32_t, void __user *);
11469 +extern int vc_read_monitor(uint32_t, void __user *);
11470 +
11471 +#ifdef CONFIG_COMPAT
11472 +
11473 +extern int vc_read_history_x32(uint32_t, void __user *);
11474 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11475 +
11476 +#endif  /* CONFIG_COMPAT */
11477 +
11478 +#endif /* __KERNEL__ */
11479 +#endif /* _VX_DEBUG_CMD_H */
11480 diff -NurpP --minimal linux-3.7/include/linux/vserver/device.h linux-3.7-vs2.3.5.1/include/linux/vserver/device.h
11481 --- linux-3.7/include/linux/vserver/device.h    1970-01-01 00:00:00.000000000 +0000
11482 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/device.h  2012-12-11 15:56:32.000000000 +0000
11483 @@ -0,0 +1,15 @@
11484 +#ifndef _VX_DEVICE_H
11485 +#define _VX_DEVICE_H
11486 +
11487 +
11488 +#define DATTR_CREATE   0x00000001
11489 +#define DATTR_OPEN     0x00000002
11490 +
11491 +#define DATTR_REMAP    0x00000010
11492 +
11493 +#define DATTR_MASK     0x00000013
11494 +
11495 +
11496 +#else  /* _VX_DEVICE_H */
11497 +#warning duplicate inclusion
11498 +#endif /* _VX_DEVICE_H */
11499 diff -NurpP --minimal linux-3.7/include/linux/vserver/device_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/device_cmd.h
11500 --- linux-3.7/include/linux/vserver/device_cmd.h        1970-01-01 00:00:00.000000000 +0000
11501 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/device_cmd.h      2012-12-11 15:56:32.000000000 +0000
11502 @@ -0,0 +1,44 @@
11503 +#ifndef _VX_DEVICE_CMD_H
11504 +#define _VX_DEVICE_CMD_H
11505 +
11506 +
11507 +/*  device vserver commands */
11508 +
11509 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11510 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11511 +
11512 +struct vcmd_set_mapping_v0 {
11513 +       const char __user *device;
11514 +       const char __user *target;
11515 +       uint32_t flags;
11516 +};
11517 +
11518 +
11519 +#ifdef __KERNEL__
11520 +
11521 +#ifdef CONFIG_COMPAT
11522 +
11523 +#include <asm/compat.h>
11524 +
11525 +struct vcmd_set_mapping_v0_x32 {
11526 +       compat_uptr_t device_ptr;
11527 +       compat_uptr_t target_ptr;
11528 +       uint32_t flags;
11529 +};
11530 +
11531 +#endif /* CONFIG_COMPAT */
11532 +
11533 +#include <linux/compiler.h>
11534 +
11535 +extern int vc_set_mapping(struct vx_info *, void __user *);
11536 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11537 +
11538 +#ifdef CONFIG_COMPAT
11539 +
11540 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11541 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11542 +
11543 +#endif /* CONFIG_COMPAT */
11544 +
11545 +#endif /* __KERNEL__ */
11546 +#endif /* _VX_DEVICE_CMD_H */
11547 diff -NurpP --minimal linux-3.7/include/linux/vserver/device_def.h linux-3.7-vs2.3.5.1/include/linux/vserver/device_def.h
11548 --- linux-3.7/include/linux/vserver/device_def.h        1970-01-01 00:00:00.000000000 +0000
11549 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/device_def.h      2012-12-11 15:56:32.000000000 +0000
11550 @@ -0,0 +1,17 @@
11551 +#ifndef _VX_DEVICE_DEF_H
11552 +#define _VX_DEVICE_DEF_H
11553 +
11554 +#include <linux/types.h>
11555 +
11556 +struct vx_dmap_target {
11557 +       dev_t target;
11558 +       uint32_t flags;
11559 +};
11560 +
11561 +struct _vx_device {
11562 +#ifdef CONFIG_VSERVER_DEVICE
11563 +       struct vx_dmap_target targets[2];
11564 +#endif
11565 +};
11566 +
11567 +#endif /* _VX_DEVICE_DEF_H */
11568 diff -NurpP --minimal linux-3.7/include/linux/vserver/dlimit.h linux-3.7-vs2.3.5.1/include/linux/vserver/dlimit.h
11569 --- linux-3.7/include/linux/vserver/dlimit.h    1970-01-01 00:00:00.000000000 +0000
11570 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/dlimit.h  2012-12-11 15:56:32.000000000 +0000
11571 @@ -0,0 +1,54 @@
11572 +#ifndef _VX_DLIMIT_H
11573 +#define _VX_DLIMIT_H
11574 +
11575 +#include "switch.h"
11576 +
11577 +
11578 +#ifdef __KERNEL__
11579 +
11580 +/*      keep in sync with CDLIM_INFINITY       */
11581 +
11582 +#define DLIM_INFINITY          (~0ULL)
11583 +
11584 +#include <linux/spinlock.h>
11585 +#include <linux/rcupdate.h>
11586 +
11587 +struct super_block;
11588 +
11589 +struct dl_info {
11590 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11591 +       struct rcu_head dl_rcu;                 /* the rcu head */
11592 +       tag_t dl_tag;                           /* context tag */
11593 +       atomic_t dl_usecnt;                     /* usage count */
11594 +       atomic_t dl_refcnt;                     /* reference count */
11595 +
11596 +       struct super_block *dl_sb;              /* associated superblock */
11597 +
11598 +       spinlock_t dl_lock;                     /* protect the values */
11599 +
11600 +       unsigned long long dl_space_used;       /* used space in bytes */
11601 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11602 +       unsigned long dl_inodes_used;           /* used inodes */
11603 +       unsigned long dl_inodes_total;          /* maximum inodes */
11604 +
11605 +       unsigned int dl_nrlmult;                /* non root limit mult */
11606 +};
11607 +
11608 +struct rcu_head;
11609 +
11610 +extern void rcu_free_dl_info(struct rcu_head *);
11611 +extern void unhash_dl_info(struct dl_info *);
11612 +
11613 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11614 +
11615 +
11616 +struct kstatfs;
11617 +
11618 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11619 +
11620 +typedef uint64_t dlsize_t;
11621 +
11622 +#endif /* __KERNEL__ */
11623 +#else  /* _VX_DLIMIT_H */
11624 +#warning duplicate inclusion
11625 +#endif /* _VX_DLIMIT_H */
11626 diff -NurpP --minimal linux-3.7/include/linux/vserver/dlimit_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/dlimit_cmd.h
11627 --- linux-3.7/include/linux/vserver/dlimit_cmd.h        1970-01-01 00:00:00.000000000 +0000
11628 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/dlimit_cmd.h      2012-12-11 15:56:32.000000000 +0000
11629 @@ -0,0 +1,109 @@
11630 +#ifndef _VX_DLIMIT_CMD_H
11631 +#define _VX_DLIMIT_CMD_H
11632 +
11633 +
11634 +/*  dlimit vserver commands */
11635 +
11636 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11637 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11638 +
11639 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11640 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11641 +
11642 +struct vcmd_ctx_dlimit_base_v0 {
11643 +       const char __user *name;
11644 +       uint32_t flags;
11645 +};
11646 +
11647 +struct vcmd_ctx_dlimit_v0 {
11648 +       const char __user *name;
11649 +       uint32_t space_used;                    /* used space in kbytes */
11650 +       uint32_t space_total;                   /* maximum space in kbytes */
11651 +       uint32_t inodes_used;                   /* used inodes */
11652 +       uint32_t inodes_total;                  /* maximum inodes */
11653 +       uint32_t reserved;                      /* reserved for root in % */
11654 +       uint32_t flags;
11655 +};
11656 +
11657 +#define CDLIM_UNSET            ((uint32_t)0UL)
11658 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11659 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11660 +
11661 +#define DLIME_UNIT     0
11662 +#define DLIME_KILO     1
11663 +#define DLIME_MEGA     2
11664 +#define DLIME_GIGA     3
11665 +
11666 +#define DLIMF_SHIFT    0x10
11667 +
11668 +#define DLIMS_USED     0
11669 +#define DLIMS_TOTAL    2
11670 +
11671 +static inline
11672 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11673 +{
11674 +       int exp = (flags & DLIMF_SHIFT) ?
11675 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11676 +       return ((uint64_t)val) << (10 * exp);
11677 +}
11678 +
11679 +static inline
11680 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11681 +{
11682 +       int exp = 0;
11683 +
11684 +       if (*flags & DLIMF_SHIFT) {
11685 +               while (val > (1LL << 32) && (exp < 3)) {
11686 +                       val >>= 10;
11687 +                       exp++;
11688 +               }
11689 +               *flags &= ~(DLIME_GIGA << shift);
11690 +               *flags |= exp << shift;
11691 +       } else
11692 +               val >>= 10;
11693 +       return val;
11694 +}
11695 +
11696 +#ifdef __KERNEL__
11697 +
11698 +#ifdef CONFIG_COMPAT
11699 +
11700 +#include <asm/compat.h>
11701 +
11702 +struct vcmd_ctx_dlimit_base_v0_x32 {
11703 +       compat_uptr_t name_ptr;
11704 +       uint32_t flags;
11705 +};
11706 +
11707 +struct vcmd_ctx_dlimit_v0_x32 {
11708 +       compat_uptr_t name_ptr;
11709 +       uint32_t space_used;                    /* used space in kbytes */
11710 +       uint32_t space_total;                   /* maximum space in kbytes */
11711 +       uint32_t inodes_used;                   /* used inodes */
11712 +       uint32_t inodes_total;                  /* maximum inodes */
11713 +       uint32_t reserved;                      /* reserved for root in % */
11714 +       uint32_t flags;
11715 +};
11716 +
11717 +#endif /* CONFIG_COMPAT */
11718 +
11719 +#include <linux/compiler.h>
11720 +
11721 +extern int vc_add_dlimit(uint32_t, void __user *);
11722 +extern int vc_rem_dlimit(uint32_t, void __user *);
11723 +
11724 +extern int vc_set_dlimit(uint32_t, void __user *);
11725 +extern int vc_get_dlimit(uint32_t, void __user *);
11726 +
11727 +#ifdef CONFIG_COMPAT
11728 +
11729 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11730 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11731 +
11732 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11733 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11734 +
11735 +#endif /* CONFIG_COMPAT */
11736 +
11737 +#endif /* __KERNEL__ */
11738 +#endif /* _VX_DLIMIT_CMD_H */
11739 diff -NurpP --minimal linux-3.7/include/linux/vserver/global.h linux-3.7-vs2.3.5.1/include/linux/vserver/global.h
11740 --- linux-3.7/include/linux/vserver/global.h    1970-01-01 00:00:00.000000000 +0000
11741 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/global.h  2012-12-11 15:56:32.000000000 +0000
11742 @@ -0,0 +1,19 @@
11743 +#ifndef _VX_GLOBAL_H
11744 +#define _VX_GLOBAL_H
11745 +
11746 +
11747 +extern atomic_t vx_global_ctotal;
11748 +extern atomic_t vx_global_cactive;
11749 +
11750 +extern atomic_t nx_global_ctotal;
11751 +extern atomic_t nx_global_cactive;
11752 +
11753 +extern atomic_t vs_global_nsproxy;
11754 +extern atomic_t vs_global_fs;
11755 +extern atomic_t vs_global_mnt_ns;
11756 +extern atomic_t vs_global_uts_ns;
11757 +extern atomic_t vs_global_user_ns;
11758 +extern atomic_t vs_global_pid_ns;
11759 +
11760 +
11761 +#endif /* _VX_GLOBAL_H */
11762 diff -NurpP --minimal linux-3.7/include/linux/vserver/history.h linux-3.7-vs2.3.5.1/include/linux/vserver/history.h
11763 --- linux-3.7/include/linux/vserver/history.h   1970-01-01 00:00:00.000000000 +0000
11764 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/history.h 2012-12-11 15:56:32.000000000 +0000
11765 @@ -0,0 +1,197 @@
11766 +#ifndef _VX_HISTORY_H
11767 +#define _VX_HISTORY_H
11768 +
11769 +
11770 +enum {
11771 +       VXH_UNUSED = 0,
11772 +       VXH_THROW_OOPS = 1,
11773 +
11774 +       VXH_GET_VX_INFO,
11775 +       VXH_PUT_VX_INFO,
11776 +       VXH_INIT_VX_INFO,
11777 +       VXH_SET_VX_INFO,
11778 +       VXH_CLR_VX_INFO,
11779 +       VXH_CLAIM_VX_INFO,
11780 +       VXH_RELEASE_VX_INFO,
11781 +       VXH_ALLOC_VX_INFO,
11782 +       VXH_DEALLOC_VX_INFO,
11783 +       VXH_HASH_VX_INFO,
11784 +       VXH_UNHASH_VX_INFO,
11785 +       VXH_LOC_VX_INFO,
11786 +       VXH_LOOKUP_VX_INFO,
11787 +       VXH_CREATE_VX_INFO,
11788 +};
11789 +
11790 +struct _vxhe_vxi {
11791 +       struct vx_info *ptr;
11792 +       unsigned xid;
11793 +       unsigned usecnt;
11794 +       unsigned tasks;
11795 +};
11796 +
11797 +struct _vxhe_set_clr {
11798 +       void *data;
11799 +};
11800 +
11801 +struct _vxhe_loc_lookup {
11802 +       unsigned arg;
11803 +};
11804 +
11805 +struct _vx_hist_entry {
11806 +       void *loc;
11807 +       unsigned short seq;
11808 +       unsigned short type;
11809 +       struct _vxhe_vxi vxi;
11810 +       union {
11811 +               struct _vxhe_set_clr sc;
11812 +               struct _vxhe_loc_lookup ll;
11813 +       };
11814 +};
11815 +
11816 +#ifdef CONFIG_VSERVER_HISTORY
11817 +
11818 +extern unsigned volatile int vxh_active;
11819 +
11820 +struct _vx_hist_entry *vxh_advance(void *loc);
11821 +
11822 +
11823 +static inline
11824 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11825 +{
11826 +       entry->vxi.ptr = vxi;
11827 +       if (vxi) {
11828 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11829 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11830 +               entry->vxi.xid = vxi->vx_id;
11831 +       }
11832 +}
11833 +
11834 +
11835 +#define        __HERE__ current_text_addr()
11836 +
11837 +#define __VXH_BODY(__type, __data, __here)     \
11838 +       struct _vx_hist_entry *entry;           \
11839 +                                               \
11840 +       preempt_disable();                      \
11841 +       entry = vxh_advance(__here);            \
11842 +       __data;                                 \
11843 +       entry->type = __type;                   \
11844 +       preempt_enable();
11845 +
11846 +
11847 +       /* pass vxi only */
11848 +
11849 +#define __VXH_SMPL                             \
11850 +       __vxh_copy_vxi(entry, vxi)
11851 +
11852 +static inline
11853 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11854 +{
11855 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11856 +}
11857 +
11858 +       /* pass vxi and data (void *) */
11859 +
11860 +#define __VXH_DATA                             \
11861 +       __vxh_copy_vxi(entry, vxi);             \
11862 +       entry->sc.data = data
11863 +
11864 +static inline
11865 +void   __vxh_data(struct vx_info *vxi, void *data,
11866 +                       int __type, void *__here)
11867 +{
11868 +       __VXH_BODY(__type, __VXH_DATA, __here)
11869 +}
11870 +
11871 +       /* pass vxi and arg (long) */
11872 +
11873 +#define __VXH_LONG                             \
11874 +       __vxh_copy_vxi(entry, vxi);             \
11875 +       entry->ll.arg = arg
11876 +
11877 +static inline
11878 +void   __vxh_long(struct vx_info *vxi, long arg,
11879 +                       int __type, void *__here)
11880 +{
11881 +       __VXH_BODY(__type, __VXH_LONG, __here)
11882 +}
11883 +
11884 +
11885 +static inline
11886 +void   __vxh_throw_oops(void *__here)
11887 +{
11888 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11889 +       /* prevent further acquisition */
11890 +       vxh_active = 0;
11891 +}
11892 +
11893 +
11894 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11895 +
11896 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11897 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11898 +
11899 +#define __vxh_init_vx_info(v, d, h) \
11900 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11901 +#define __vxh_set_vx_info(v, d, h) \
11902 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11903 +#define __vxh_clr_vx_info(v, d, h) \
11904 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11905 +
11906 +#define __vxh_claim_vx_info(v, d, h) \
11907 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11908 +#define __vxh_release_vx_info(v, d, h) \
11909 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11910 +
11911 +#define vxh_alloc_vx_info(v) \
11912 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11913 +#define vxh_dealloc_vx_info(v) \
11914 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11915 +
11916 +#define vxh_hash_vx_info(v) \
11917 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11918 +#define vxh_unhash_vx_info(v) \
11919 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11920 +
11921 +#define vxh_loc_vx_info(v, l) \
11922 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11923 +#define vxh_lookup_vx_info(v, l) \
11924 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11925 +#define vxh_create_vx_info(v, l) \
11926 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11927 +
11928 +extern void vxh_dump_history(void);
11929 +
11930 +
11931 +#else  /* CONFIG_VSERVER_HISTORY */
11932 +
11933 +#define        __HERE__        0
11934 +
11935 +#define vxh_throw_oops()               do { } while (0)
11936 +
11937 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11938 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11939 +
11940 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11941 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11942 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11943 +
11944 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11945 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11946 +
11947 +#define vxh_alloc_vx_info(v)           do { } while (0)
11948 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11949 +
11950 +#define vxh_hash_vx_info(v)            do { } while (0)
11951 +#define vxh_unhash_vx_info(v)          do { } while (0)
11952 +
11953 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11954 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11955 +#define vxh_create_vx_info(v, l)       do { } while (0)
11956 +
11957 +#define vxh_dump_history()             do { } while (0)
11958 +
11959 +
11960 +#endif /* CONFIG_VSERVER_HISTORY */
11961 +
11962 +#endif /* _VX_HISTORY_H */
11963 diff -NurpP --minimal linux-3.7/include/linux/vserver/inode.h linux-3.7-vs2.3.5.1/include/linux/vserver/inode.h
11964 --- linux-3.7/include/linux/vserver/inode.h     1970-01-01 00:00:00.000000000 +0000
11965 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/inode.h   2012-12-11 15:56:32.000000000 +0000
11966 @@ -0,0 +1,39 @@
11967 +#ifndef _VX_INODE_H
11968 +#define _VX_INODE_H
11969 +
11970 +
11971 +#define IATTR_TAG      0x01000000
11972 +
11973 +#define IATTR_ADMIN    0x00000001
11974 +#define IATTR_WATCH    0x00000002
11975 +#define IATTR_HIDE     0x00000004
11976 +#define IATTR_FLAGS    0x00000007
11977 +
11978 +#define IATTR_BARRIER  0x00010000
11979 +#define IATTR_IXUNLINK 0x00020000
11980 +#define IATTR_IMMUTABLE 0x00040000
11981 +#define IATTR_COW      0x00080000
11982 +
11983 +#ifdef __KERNEL__
11984 +
11985 +
11986 +#ifdef CONFIG_VSERVER_PROC_SECURE
11987 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11988 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11989 +#else
11990 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11991 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11992 +#endif
11993 +
11994 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11995 +
11996 +#endif /* __KERNEL__ */
11997 +
11998 +/* inode ioctls */
11999 +
12000 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12001 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12002 +
12003 +#else  /* _VX_INODE_H */
12004 +#warning duplicate inclusion
12005 +#endif /* _VX_INODE_H */
12006 diff -NurpP --minimal linux-3.7/include/linux/vserver/inode_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/inode_cmd.h
12007 --- linux-3.7/include/linux/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
12008 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/inode_cmd.h       2012-12-11 15:56:32.000000000 +0000
12009 @@ -0,0 +1,59 @@
12010 +#ifndef _VX_INODE_CMD_H
12011 +#define _VX_INODE_CMD_H
12012 +
12013 +
12014 +/*  inode vserver commands */
12015 +
12016 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12017 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12018 +
12019 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12020 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12021 +
12022 +struct vcmd_ctx_iattr_v1 {
12023 +       const char __user *name;
12024 +       uint32_t tag;
12025 +       uint32_t flags;
12026 +       uint32_t mask;
12027 +};
12028 +
12029 +struct vcmd_ctx_fiattr_v0 {
12030 +       uint32_t tag;
12031 +       uint32_t flags;
12032 +       uint32_t mask;
12033 +};
12034 +
12035 +
12036 +#ifdef __KERNEL__
12037 +
12038 +
12039 +#ifdef CONFIG_COMPAT
12040 +
12041 +#include <asm/compat.h>
12042 +
12043 +struct vcmd_ctx_iattr_v1_x32 {
12044 +       compat_uptr_t name_ptr;
12045 +       uint32_t tag;
12046 +       uint32_t flags;
12047 +       uint32_t mask;
12048 +};
12049 +
12050 +#endif /* CONFIG_COMPAT */
12051 +
12052 +#include <linux/compiler.h>
12053 +
12054 +extern int vc_get_iattr(void __user *);
12055 +extern int vc_set_iattr(void __user *);
12056 +
12057 +extern int vc_fget_iattr(uint32_t, void __user *);
12058 +extern int vc_fset_iattr(uint32_t, void __user *);
12059 +
12060 +#ifdef CONFIG_COMPAT
12061 +
12062 +extern int vc_get_iattr_x32(void __user *);
12063 +extern int vc_set_iattr_x32(void __user *);
12064 +
12065 +#endif /* CONFIG_COMPAT */
12066 +
12067 +#endif /* __KERNEL__ */
12068 +#endif /* _VX_INODE_CMD_H */
12069 diff -NurpP --minimal linux-3.7/include/linux/vserver/limit.h linux-3.7-vs2.3.5.1/include/linux/vserver/limit.h
12070 --- linux-3.7/include/linux/vserver/limit.h     1970-01-01 00:00:00.000000000 +0000
12071 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/limit.h   2012-12-11 15:56:32.000000000 +0000
12072 @@ -0,0 +1,71 @@
12073 +#ifndef _VX_LIMIT_H
12074 +#define _VX_LIMIT_H
12075 +
12076 +#define VLIMIT_NSOCK   16
12077 +#define VLIMIT_OPENFD  17
12078 +#define VLIMIT_ANON    18
12079 +#define VLIMIT_SHMEM   19
12080 +#define VLIMIT_SEMARY  20
12081 +#define VLIMIT_NSEMS   21
12082 +#define VLIMIT_DENTRY  22
12083 +#define VLIMIT_MAPPED  23
12084 +
12085 +
12086 +#ifdef __KERNEL__
12087 +
12088 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12089 +
12090 +/*     keep in sync with CRLIM_INFINITY */
12091 +
12092 +#define        VLIM_INFINITY   (~0ULL)
12093 +
12094 +#include <asm/atomic.h>
12095 +#include <asm/resource.h>
12096 +
12097 +#ifndef RLIM_INFINITY
12098 +#warning RLIM_INFINITY is undefined
12099 +#endif
12100 +
12101 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12102 +
12103 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12104 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12105 +
12106 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12107 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12108 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12109 +
12110 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12111 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12112 +
12113 +typedef atomic_long_t rlim_atomic_t;
12114 +typedef unsigned long rlim_t;
12115 +
12116 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12117 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12118 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12119 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12120 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12121 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12122 +
12123 +
12124 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12125 +#define        VX_VLIM(r) ((long long)(long)(r))
12126 +#define        VX_RLIM(v) ((rlim_t)(v))
12127 +#else
12128 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12129 +               ? VLIM_INFINITY : (long long)(r))
12130 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12131 +               ? RLIM_INFINITY : (rlim_t)(v))
12132 +#endif
12133 +
12134 +struct sysinfo;
12135 +
12136 +void vx_vsi_meminfo(struct sysinfo *);
12137 +void vx_vsi_swapinfo(struct sysinfo *);
12138 +long vx_vsi_cached(struct sysinfo *);
12139 +
12140 +#define NUM_LIMITS     24
12141 +
12142 +#endif /* __KERNEL__ */
12143 +#endif /* _VX_LIMIT_H */
12144 diff -NurpP --minimal linux-3.7/include/linux/vserver/limit_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/limit_cmd.h
12145 --- linux-3.7/include/linux/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
12146 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/limit_cmd.h       2012-12-11 15:56:32.000000000 +0000
12147 @@ -0,0 +1,71 @@
12148 +#ifndef _VX_LIMIT_CMD_H
12149 +#define _VX_LIMIT_CMD_H
12150 +
12151 +
12152 +/*  rlimit vserver commands */
12153 +
12154 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12155 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12156 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12157 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12158 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12159 +
12160 +struct vcmd_ctx_rlimit_v0 {
12161 +       uint32_t id;
12162 +       uint64_t minimum;
12163 +       uint64_t softlimit;
12164 +       uint64_t maximum;
12165 +};
12166 +
12167 +struct vcmd_ctx_rlimit_mask_v0 {
12168 +       uint32_t minimum;
12169 +       uint32_t softlimit;
12170 +       uint32_t maximum;
12171 +};
12172 +
12173 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12174 +
12175 +struct vcmd_rlimit_stat_v0 {
12176 +       uint32_t id;
12177 +       uint32_t hits;
12178 +       uint64_t value;
12179 +       uint64_t minimum;
12180 +       uint64_t maximum;
12181 +};
12182 +
12183 +#define CRLIM_UNSET            (0ULL)
12184 +#define CRLIM_INFINITY         (~0ULL)
12185 +#define CRLIM_KEEP             (~1ULL)
12186 +
12187 +#ifdef __KERNEL__
12188 +
12189 +#ifdef CONFIG_IA32_EMULATION
12190 +
12191 +struct vcmd_ctx_rlimit_v0_x32 {
12192 +       uint32_t id;
12193 +       uint64_t minimum;
12194 +       uint64_t softlimit;
12195 +       uint64_t maximum;
12196 +} __attribute__ ((packed));
12197 +
12198 +#endif /* CONFIG_IA32_EMULATION */
12199 +
12200 +#include <linux/compiler.h>
12201 +
12202 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12203 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12204 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12205 +extern int vc_reset_hits(struct vx_info *, void __user *);
12206 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12207 +
12208 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12209 +
12210 +#ifdef CONFIG_IA32_EMULATION
12211 +
12212 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12213 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12214 +
12215 +#endif /* CONFIG_IA32_EMULATION */
12216 +
12217 +#endif /* __KERNEL__ */
12218 +#endif /* _VX_LIMIT_CMD_H */
12219 diff -NurpP --minimal linux-3.7/include/linux/vserver/limit_def.h linux-3.7-vs2.3.5.1/include/linux/vserver/limit_def.h
12220 --- linux-3.7/include/linux/vserver/limit_def.h 1970-01-01 00:00:00.000000000 +0000
12221 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/limit_def.h       2012-12-11 15:56:32.000000000 +0000
12222 @@ -0,0 +1,47 @@
12223 +#ifndef _VX_LIMIT_DEF_H
12224 +#define _VX_LIMIT_DEF_H
12225 +
12226 +#include <asm/atomic.h>
12227 +#include <asm/resource.h>
12228 +
12229 +#include "limit.h"
12230 +
12231 +
12232 +struct _vx_res_limit {
12233 +       rlim_t soft;            /* Context soft limit */
12234 +       rlim_t hard;            /* Context hard limit */
12235 +
12236 +       rlim_atomic_t rcur;     /* Current value */
12237 +       rlim_t rmin;            /* Context minimum */
12238 +       rlim_t rmax;            /* Context maximum */
12239 +
12240 +       atomic_t lhit;          /* Limit hits */
12241 +};
12242 +
12243 +/* context sub struct */
12244 +
12245 +struct _vx_limit {
12246 +       struct _vx_res_limit res[NUM_LIMITS];
12247 +};
12248 +
12249 +#ifdef CONFIG_VSERVER_DEBUG
12250 +
12251 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12252 +{
12253 +       int i;
12254 +
12255 +       printk("\t_vx_limit:");
12256 +       for (i = 0; i < NUM_LIMITS; i++) {
12257 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12258 +                       i, (unsigned long)__rlim_get(limit, i),
12259 +                       (unsigned long)__rlim_rmin(limit, i),
12260 +                       (unsigned long)__rlim_rmax(limit, i),
12261 +                       (long)__rlim_soft(limit, i),
12262 +                       (long)__rlim_hard(limit, i),
12263 +                       atomic_read(&__rlim_lhit(limit, i)));
12264 +       }
12265 +}
12266 +
12267 +#endif
12268 +
12269 +#endif /* _VX_LIMIT_DEF_H */
12270 diff -NurpP --minimal linux-3.7/include/linux/vserver/limit_int.h linux-3.7-vs2.3.5.1/include/linux/vserver/limit_int.h
12271 --- linux-3.7/include/linux/vserver/limit_int.h 1970-01-01 00:00:00.000000000 +0000
12272 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/limit_int.h       2012-12-11 15:56:32.000000000 +0000
12273 @@ -0,0 +1,198 @@
12274 +#ifndef _VX_LIMIT_INT_H
12275 +#define _VX_LIMIT_INT_H
12276 +
12277 +#include "context.h"
12278 +
12279 +#ifdef __KERNEL__
12280 +
12281 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12282 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12283 +
12284 +extern const char *vlimit_name[NUM_LIMITS];
12285 +
12286 +static inline void __vx_acc_cres(struct vx_info *vxi,
12287 +       int res, int dir, void *_data, char *_file, int _line)
12288 +{
12289 +       if (VXD_RCRES_COND(res))
12290 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12291 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12292 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12293 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12294 +       if (!vxi)
12295 +               return;
12296 +
12297 +       if (dir > 0)
12298 +               __rlim_inc(&vxi->limit, res);
12299 +       else
12300 +               __rlim_dec(&vxi->limit, res);
12301 +}
12302 +
12303 +static inline void __vx_add_cres(struct vx_info *vxi,
12304 +       int res, int amount, void *_data, char *_file, int _line)
12305 +{
12306 +       if (VXD_RCRES_COND(res))
12307 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12308 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12309 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12310 +                       amount, _data, _file, _line);
12311 +       if (amount == 0)
12312 +               return;
12313 +       if (!vxi)
12314 +               return;
12315 +       __rlim_add(&vxi->limit, res, amount);
12316 +}
12317 +
12318 +static inline
12319 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12320 +{
12321 +       int cond = (value > __rlim_rmax(limit, res));
12322 +
12323 +       if (cond)
12324 +               __rlim_rmax(limit, res) = value;
12325 +       return cond;
12326 +}
12327 +
12328 +static inline
12329 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12330 +{
12331 +       int cond = (value < __rlim_rmin(limit, res));
12332 +
12333 +       if (cond)
12334 +               __rlim_rmin(limit, res) = value;
12335 +       return cond;
12336 +}
12337 +
12338 +static inline
12339 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12340 +{
12341 +       if (!__vx_cres_adjust_max(limit, res, value))
12342 +               __vx_cres_adjust_min(limit, res, value);
12343 +}
12344 +
12345 +
12346 +/*     return values:
12347 +        +1 ... no limit hit
12348 +        -1 ... over soft limit
12349 +         0 ... over hard limit         */
12350 +
12351 +static inline int __vx_cres_avail(struct vx_info *vxi,
12352 +       int res, int num, char *_file, int _line)
12353 +{
12354 +       struct _vx_limit *limit;
12355 +       rlim_t value;
12356 +
12357 +       if (VXD_RLIMIT_COND(res))
12358 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12359 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12360 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12361 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12362 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12363 +                       num, _file, _line);
12364 +       if (!vxi)
12365 +               return 1;
12366 +
12367 +       limit = &vxi->limit;
12368 +       value = __rlim_get(limit, res);
12369 +
12370 +       if (!__vx_cres_adjust_max(limit, res, value))
12371 +               __vx_cres_adjust_min(limit, res, value);
12372 +
12373 +       if (num == 0)
12374 +               return 1;
12375 +
12376 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12377 +               return -1;
12378 +       if (value + num <= __rlim_soft(limit, res))
12379 +               return -1;
12380 +
12381 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12382 +               return 1;
12383 +       if (value + num <= __rlim_hard(limit, res))
12384 +               return 1;
12385 +
12386 +       __rlim_hit(limit, res);
12387 +       return 0;
12388 +}
12389 +
12390 +
12391 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12392 +
12393 +static inline
12394 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12395 +{
12396 +       rlim_t value, sum = 0;
12397 +       int res;
12398 +
12399 +       while ((res = *array++)) {
12400 +               value = __rlim_get(limit, res);
12401 +               __vx_cres_fixup(limit, res, value);
12402 +               sum += value;
12403 +       }
12404 +       return sum;
12405 +}
12406 +
12407 +static inline
12408 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12409 +{
12410 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12411 +       int res = *array;
12412 +
12413 +       if (value == __rlim_get(limit, res))
12414 +               return value;
12415 +
12416 +       __rlim_set(limit, res, value);
12417 +       /* now adjust min/max */
12418 +       if (!__vx_cres_adjust_max(limit, res, value))
12419 +               __vx_cres_adjust_min(limit, res, value);
12420 +
12421 +       return value;
12422 +}
12423 +
12424 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12425 +       const int *array, int num, char *_file, int _line)
12426 +{
12427 +       struct _vx_limit *limit;
12428 +       rlim_t value = 0;
12429 +       int res;
12430 +
12431 +       if (num == 0)
12432 +               return 1;
12433 +       if (!vxi)
12434 +               return 1;
12435 +
12436 +       limit = &vxi->limit;
12437 +       res = *array;
12438 +       value = __vx_cres_array_sum(limit, array + 1);
12439 +
12440 +       __rlim_set(limit, res, value);
12441 +       __vx_cres_fixup(limit, res, value);
12442 +
12443 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12444 +}
12445 +
12446 +
12447 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12448 +{
12449 +       rlim_t value;
12450 +       int res;
12451 +
12452 +       /* complex resources first */
12453 +       if ((id < 0) || (id == RLIMIT_RSS))
12454 +               __vx_cres_array_fixup(limit, VLA_RSS);
12455 +
12456 +       for (res = 0; res < NUM_LIMITS; res++) {
12457 +               if ((id > 0) && (res != id))
12458 +                       continue;
12459 +
12460 +               value = __rlim_get(limit, res);
12461 +               __vx_cres_fixup(limit, res, value);
12462 +
12463 +               /* not supposed to happen, maybe warn? */
12464 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12465 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12466 +       }
12467 +}
12468 +
12469 +
12470 +#endif /* __KERNEL__ */
12471 +#endif /* _VX_LIMIT_INT_H */
12472 diff -NurpP --minimal linux-3.7/include/linux/vserver/monitor.h linux-3.7-vs2.3.5.1/include/linux/vserver/monitor.h
12473 --- linux-3.7/include/linux/vserver/monitor.h   1970-01-01 00:00:00.000000000 +0000
12474 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/monitor.h 2012-12-11 15:56:32.000000000 +0000
12475 @@ -0,0 +1,96 @@
12476 +#ifndef _VX_MONITOR_H
12477 +#define _VX_MONITOR_H
12478 +
12479 +#include <linux/types.h>
12480 +
12481 +enum {
12482 +       VXM_UNUSED = 0,
12483 +
12484 +       VXM_SYNC = 0x10,
12485 +
12486 +       VXM_UPDATE = 0x20,
12487 +       VXM_UPDATE_1,
12488 +       VXM_UPDATE_2,
12489 +
12490 +       VXM_RQINFO_1 = 0x24,
12491 +       VXM_RQINFO_2,
12492 +
12493 +       VXM_ACTIVATE = 0x40,
12494 +       VXM_DEACTIVATE,
12495 +       VXM_IDLE,
12496 +
12497 +       VXM_HOLD = 0x44,
12498 +       VXM_UNHOLD,
12499 +
12500 +       VXM_MIGRATE = 0x48,
12501 +       VXM_RESCHED,
12502 +
12503 +       /* all other bits are flags */
12504 +       VXM_SCHED = 0x80,
12505 +};
12506 +
12507 +struct _vxm_update_1 {
12508 +       uint32_t tokens_max;
12509 +       uint32_t fill_rate;
12510 +       uint32_t interval;
12511 +};
12512 +
12513 +struct _vxm_update_2 {
12514 +       uint32_t tokens_min;
12515 +       uint32_t fill_rate;
12516 +       uint32_t interval;
12517 +};
12518 +
12519 +struct _vxm_rqinfo_1 {
12520 +       uint16_t running;
12521 +       uint16_t onhold;
12522 +       uint16_t iowait;
12523 +       uint16_t uintr;
12524 +       uint32_t idle_tokens;
12525 +};
12526 +
12527 +struct _vxm_rqinfo_2 {
12528 +       uint32_t norm_time;
12529 +       uint32_t idle_time;
12530 +       uint32_t idle_skip;
12531 +};
12532 +
12533 +struct _vxm_sched {
12534 +       uint32_t tokens;
12535 +       uint32_t norm_time;
12536 +       uint32_t idle_time;
12537 +};
12538 +
12539 +struct _vxm_task {
12540 +       uint16_t pid;
12541 +       uint16_t state;
12542 +};
12543 +
12544 +struct _vxm_event {
12545 +       uint32_t jif;
12546 +       union {
12547 +               uint32_t seq;
12548 +               uint32_t sec;
12549 +       };
12550 +       union {
12551 +               uint32_t tokens;
12552 +               uint32_t nsec;
12553 +               struct _vxm_task tsk;
12554 +       };
12555 +};
12556 +
12557 +struct _vx_mon_entry {
12558 +       uint16_t type;
12559 +       uint16_t xid;
12560 +       union {
12561 +               struct _vxm_event ev;
12562 +               struct _vxm_sched sd;
12563 +               struct _vxm_update_1 u1;
12564 +               struct _vxm_update_2 u2;
12565 +               struct _vxm_rqinfo_1 q1;
12566 +               struct _vxm_rqinfo_2 q2;
12567 +       };
12568 +};
12569 +
12570 +
12571 +#endif /* _VX_MONITOR_H */
12572 diff -NurpP --minimal linux-3.7/include/linux/vserver/network.h linux-3.7-vs2.3.5.1/include/linux/vserver/network.h
12573 --- linux-3.7/include/linux/vserver/network.h   1970-01-01 00:00:00.000000000 +0000
12574 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/network.h 2012-12-11 15:56:32.000000000 +0000
12575 @@ -0,0 +1,148 @@
12576 +#ifndef _VX_NETWORK_H
12577 +#define _VX_NETWORK_H
12578 +
12579 +#include <linux/types.h>
12580 +
12581 +
12582 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12583 +
12584 +
12585 +/* network flags */
12586 +
12587 +#define NXF_INFO_PRIVATE       0x00000008
12588 +
12589 +#define NXF_SINGLE_IP          0x00000100
12590 +#define NXF_LBACK_REMAP                0x00000200
12591 +#define NXF_LBACK_ALLOW                0x00000400
12592 +
12593 +#define NXF_HIDE_NETIF         0x02000000
12594 +#define NXF_HIDE_LBACK         0x04000000
12595 +
12596 +#define NXF_STATE_SETUP                (1ULL << 32)
12597 +#define NXF_STATE_ADMIN                (1ULL << 34)
12598 +
12599 +#define NXF_SC_HELPER          (1ULL << 36)
12600 +#define NXF_PERSISTENT         (1ULL << 38)
12601 +
12602 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12603 +
12604 +
12605 +#define        NXF_INIT_SET            (__nxf_init_set())
12606 +
12607 +static inline uint64_t __nxf_init_set(void) {
12608 +       return    NXF_STATE_ADMIN
12609 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12610 +               | NXF_LBACK_REMAP
12611 +               | NXF_HIDE_LBACK
12612 +#endif
12613 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12614 +               | NXF_SINGLE_IP
12615 +#endif
12616 +               | NXF_HIDE_NETIF;
12617 +}
12618 +
12619 +
12620 +/* network caps */
12621 +
12622 +#define NXC_TUN_CREATE         0x00000001
12623 +
12624 +#define NXC_RAW_ICMP           0x00000100
12625 +
12626 +#define NXC_MULTICAST          0x00001000
12627 +
12628 +
12629 +/* address types */
12630 +
12631 +#define NXA_TYPE_IPV4          0x0001
12632 +#define NXA_TYPE_IPV6          0x0002
12633 +
12634 +#define NXA_TYPE_NONE          0x0000
12635 +#define NXA_TYPE_ANY           0x00FF
12636 +
12637 +#define NXA_TYPE_ADDR          0x0010
12638 +#define NXA_TYPE_MASK          0x0020
12639 +#define NXA_TYPE_RANGE         0x0040
12640 +
12641 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12642 +
12643 +#define NXA_MOD_BCAST          0x0100
12644 +#define NXA_MOD_LBACK          0x0200
12645 +
12646 +#define NXA_LOOPBACK           0x1000
12647 +
12648 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12649 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12650 +
12651 +#ifdef __KERNEL__
12652 +
12653 +#include <linux/list.h>
12654 +#include <linux/spinlock.h>
12655 +#include <linux/rcupdate.h>
12656 +#include <linux/in.h>
12657 +#include <linux/in6.h>
12658 +#include <asm/atomic.h>
12659 +
12660 +struct nx_addr_v4 {
12661 +       struct nx_addr_v4 *next;
12662 +       struct in_addr ip[2];
12663 +       struct in_addr mask;
12664 +       uint16_t type;
12665 +       uint16_t flags;
12666 +};
12667 +
12668 +struct nx_addr_v6 {
12669 +       struct nx_addr_v6 *next;
12670 +       struct in6_addr ip;
12671 +       struct in6_addr mask;
12672 +       uint32_t prefix;
12673 +       uint16_t type;
12674 +       uint16_t flags;
12675 +};
12676 +
12677 +struct nx_info {
12678 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12679 +       nid_t nx_id;                    /* vnet id */
12680 +       atomic_t nx_usecnt;             /* usage count */
12681 +       atomic_t nx_tasks;              /* tasks count */
12682 +       int nx_state;                   /* context state */
12683 +
12684 +       uint64_t nx_flags;              /* network flag word */
12685 +       uint64_t nx_ncaps;              /* network capabilities */
12686 +
12687 +       struct in_addr v4_lback;        /* Loopback address */
12688 +       struct in_addr v4_bcast;        /* Broadcast address */
12689 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12690 +#ifdef CONFIG_IPV6
12691 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12692 +#endif
12693 +       char nx_name[65];               /* network context name */
12694 +};
12695 +
12696 +
12697 +/* status flags */
12698 +
12699 +#define NXS_HASHED      0x0001
12700 +#define NXS_SHUTDOWN    0x0100
12701 +#define NXS_RELEASED    0x8000
12702 +
12703 +extern struct nx_info *lookup_nx_info(int);
12704 +
12705 +extern int get_nid_list(int, unsigned int *, int);
12706 +extern int nid_is_hashed(nid_t);
12707 +
12708 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12709 +
12710 +extern long vs_net_change(struct nx_info *, unsigned int);
12711 +
12712 +struct sock;
12713 +
12714 +
12715 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12716 +#ifdef  CONFIG_IPV6
12717 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12718 +#else
12719 +#define NX_IPV6(n)     (0)
12720 +#endif
12721 +
12722 +#endif /* __KERNEL__ */
12723 +#endif /* _VX_NETWORK_H */
12724 diff -NurpP --minimal linux-3.7/include/linux/vserver/network_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/network_cmd.h
12725 --- linux-3.7/include/linux/vserver/network_cmd.h       1970-01-01 00:00:00.000000000 +0000
12726 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/network_cmd.h     2012-12-11 15:56:32.000000000 +0000
12727 @@ -0,0 +1,164 @@
12728 +#ifndef _VX_NETWORK_CMD_H
12729 +#define _VX_NETWORK_CMD_H
12730 +
12731 +
12732 +/* vinfo commands */
12733 +
12734 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12735 +
12736 +#ifdef __KERNEL__
12737 +extern int vc_task_nid(uint32_t);
12738 +
12739 +#endif /* __KERNEL__ */
12740 +
12741 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12742 +
12743 +struct vcmd_nx_info_v0 {
12744 +       uint32_t nid;
12745 +       /* more to come */
12746 +};
12747 +
12748 +#ifdef __KERNEL__
12749 +extern int vc_nx_info(struct nx_info *, void __user *);
12750 +
12751 +#endif /* __KERNEL__ */
12752 +
12753 +#include <linux/in.h>
12754 +#include <linux/in6.h>
12755 +
12756 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12757 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12758 +
12759 +struct  vcmd_net_create {
12760 +       uint64_t flagword;
12761 +};
12762 +
12763 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12764 +
12765 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12766 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12767 +
12768 +struct vcmd_net_addr_v0 {
12769 +       uint16_t type;
12770 +       uint16_t count;
12771 +       struct in_addr ip[4];
12772 +       struct in_addr mask[4];
12773 +};
12774 +
12775 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12776 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12777 +
12778 +struct vcmd_net_addr_ipv4_v1 {
12779 +       uint16_t type;
12780 +       uint16_t flags;
12781 +       struct in_addr ip;
12782 +       struct in_addr mask;
12783 +};
12784 +
12785 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12786 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12787 +
12788 +struct vcmd_net_addr_ipv4_v2 {
12789 +       uint16_t type;
12790 +       uint16_t flags;
12791 +       struct in_addr ip;
12792 +       struct in_addr ip2;
12793 +       struct in_addr mask;
12794 +};
12795 +
12796 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12797 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12798 +
12799 +struct vcmd_net_addr_ipv6_v1 {
12800 +       uint16_t type;
12801 +       uint16_t flags;
12802 +       uint32_t prefix;
12803 +       struct in6_addr ip;
12804 +       struct in6_addr mask;
12805 +};
12806 +
12807 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12808 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12809 +
12810 +struct vcmd_match_ipv4_v0 {
12811 +       uint16_t type;
12812 +       uint16_t flags;
12813 +       uint16_t parent;
12814 +       uint16_t prefix;
12815 +       struct in_addr ip;
12816 +       struct in_addr ip2;
12817 +       struct in_addr mask;
12818 +};
12819 +
12820 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12821 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12822 +
12823 +struct vcmd_match_ipv6_v0 {
12824 +       uint16_t type;
12825 +       uint16_t flags;
12826 +       uint16_t parent;
12827 +       uint16_t prefix;
12828 +       struct in6_addr ip;
12829 +       struct in6_addr ip2;
12830 +       struct in6_addr mask;
12831 +};
12832 +
12833 +
12834 +#ifdef __KERNEL__
12835 +extern int vc_net_create(uint32_t, void __user *);
12836 +extern int vc_net_migrate(struct nx_info *, void __user *);
12837 +
12838 +extern int vc_net_add(struct nx_info *, void __user *);
12839 +extern int vc_net_remove(struct nx_info *, void __user *);
12840 +
12841 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
12842 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12843 +
12844 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
12845 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
12846 +
12847 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12848 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12849 +
12850 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12851 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12852 +
12853 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12854 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12855 +
12856 +#endif /* __KERNEL__ */
12857 +
12858 +
12859 +/* flag commands */
12860 +
12861 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12862 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12863 +
12864 +struct vcmd_net_flags_v0 {
12865 +       uint64_t flagword;
12866 +       uint64_t mask;
12867 +};
12868 +
12869 +#ifdef __KERNEL__
12870 +extern int vc_get_nflags(struct nx_info *, void __user *);
12871 +extern int vc_set_nflags(struct nx_info *, void __user *);
12872 +
12873 +#endif /* __KERNEL__ */
12874 +
12875 +
12876 +/* network caps commands */
12877 +
12878 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12879 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12880 +
12881 +struct vcmd_net_caps_v0 {
12882 +       uint64_t ncaps;
12883 +       uint64_t cmask;
12884 +};
12885 +
12886 +#ifdef __KERNEL__
12887 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12888 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12889 +
12890 +#endif /* __KERNEL__ */
12891 +#endif /* _VX_CONTEXT_CMD_H */
12892 diff -NurpP --minimal linux-3.7/include/linux/vserver/percpu.h linux-3.7-vs2.3.5.1/include/linux/vserver/percpu.h
12893 --- linux-3.7/include/linux/vserver/percpu.h    1970-01-01 00:00:00.000000000 +0000
12894 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/percpu.h  2012-12-11 15:56:32.000000000 +0000
12895 @@ -0,0 +1,14 @@
12896 +#ifndef _VX_PERCPU_H
12897 +#define _VX_PERCPU_H
12898 +
12899 +#include "cvirt_def.h"
12900 +#include "sched_def.h"
12901 +
12902 +struct _vx_percpu {
12903 +       struct _vx_cvirt_pc cvirt;
12904 +       struct _vx_sched_pc sched;
12905 +};
12906 +
12907 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12908 +
12909 +#endif /* _VX_PERCPU_H */
12910 diff -NurpP --minimal linux-3.7/include/linux/vserver/pid.h linux-3.7-vs2.3.5.1/include/linux/vserver/pid.h
12911 --- linux-3.7/include/linux/vserver/pid.h       1970-01-01 00:00:00.000000000 +0000
12912 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/pid.h     2012-12-11 15:56:32.000000000 +0000
12913 @@ -0,0 +1,51 @@
12914 +#ifndef _VSERVER_PID_H
12915 +#define _VSERVER_PID_H
12916 +
12917 +/* pid faking stuff */
12918 +
12919 +#define vx_info_map_pid(v, p) \
12920 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12921 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12922 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12923 +#define vx_map_tgid(p) vx_map_pid(p)
12924 +
12925 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12926 +       const char *func, const char *file, int line)
12927 +{
12928 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12929 +               vxfprintk(VXD_CBIT(cvirt, 2),
12930 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12931 +                       vxi, (long long)vxi->vx_flags, pid,
12932 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12933 +                       func, file, line);
12934 +               if (pid == 0)
12935 +                       return 0;
12936 +               if (pid == vxi->vx_initpid)
12937 +                       return 1;
12938 +       }
12939 +       return pid;
12940 +}
12941 +
12942 +#define vx_info_rmap_pid(v, p) \
12943 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12944 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12945 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12946 +
12947 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12948 +       const char *func, const char *file, int line)
12949 +{
12950 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12951 +               vxfprintk(VXD_CBIT(cvirt, 2),
12952 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12953 +                       vxi, (long long)vxi->vx_flags, pid,
12954 +                       (pid == 1) ? vxi->vx_initpid : pid,
12955 +                       func, file, line);
12956 +               if ((pid == 1) && vxi->vx_initpid)
12957 +                       return vxi->vx_initpid;
12958 +               if (pid == vxi->vx_initpid)
12959 +                       return ~0U;
12960 +       }
12961 +       return pid;
12962 +}
12963 +
12964 +#endif
12965 diff -NurpP --minimal linux-3.7/include/linux/vserver/sched.h linux-3.7-vs2.3.5.1/include/linux/vserver/sched.h
12966 --- linux-3.7/include/linux/vserver/sched.h     1970-01-01 00:00:00.000000000 +0000
12967 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/sched.h   2012-12-11 15:56:32.000000000 +0000
12968 @@ -0,0 +1,23 @@
12969 +#ifndef _VX_SCHED_H
12970 +#define _VX_SCHED_H
12971 +
12972 +
12973 +#ifdef __KERNEL__
12974 +
12975 +struct timespec;
12976 +
12977 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12978 +
12979 +
12980 +struct vx_info;
12981 +
12982 +void vx_update_load(struct vx_info *);
12983 +
12984 +
12985 +void vx_update_sched_param(struct _vx_sched *sched,
12986 +       struct _vx_sched_pc *sched_pc);
12987 +
12988 +#endif /* __KERNEL__ */
12989 +#else  /* _VX_SCHED_H */
12990 +#warning duplicate inclusion
12991 +#endif /* _VX_SCHED_H */
12992 diff -NurpP --minimal linux-3.7/include/linux/vserver/sched_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/sched_cmd.h
12993 --- linux-3.7/include/linux/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
12994 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/sched_cmd.h       2012-12-11 15:56:32.000000000 +0000
12995 @@ -0,0 +1,21 @@
12996 +#ifndef _VX_SCHED_CMD_H
12997 +#define _VX_SCHED_CMD_H
12998 +
12999 +
13000 +struct vcmd_prio_bias {
13001 +       int32_t cpu_id;
13002 +       int32_t prio_bias;
13003 +};
13004 +
13005 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13006 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13007 +
13008 +#ifdef __KERNEL__
13009 +
13010 +#include <linux/compiler.h>
13011 +
13012 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13013 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13014 +
13015 +#endif /* __KERNEL__ */
13016 +#endif /* _VX_SCHED_CMD_H */
13017 diff -NurpP --minimal linux-3.7/include/linux/vserver/sched_def.h linux-3.7-vs2.3.5.1/include/linux/vserver/sched_def.h
13018 --- linux-3.7/include/linux/vserver/sched_def.h 1970-01-01 00:00:00.000000000 +0000
13019 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/sched_def.h       2012-12-11 15:56:32.000000000 +0000
13020 @@ -0,0 +1,38 @@
13021 +#ifndef _VX_SCHED_DEF_H
13022 +#define _VX_SCHED_DEF_H
13023 +
13024 +#include <linux/spinlock.h>
13025 +#include <linux/jiffies.h>
13026 +#include <linux/cpumask.h>
13027 +#include <asm/atomic.h>
13028 +#include <asm/param.h>
13029 +
13030 +
13031 +/* context sub struct */
13032 +
13033 +struct _vx_sched {
13034 +       int prio_bias;                  /* bias offset for priority */
13035 +
13036 +       cpumask_t update;               /* CPUs which should update */
13037 +};
13038 +
13039 +struct _vx_sched_pc {
13040 +       int prio_bias;                  /* bias offset for priority */
13041 +
13042 +       uint64_t user_ticks;            /* token tick events */
13043 +       uint64_t sys_ticks;             /* token tick events */
13044 +       uint64_t hold_ticks;            /* token ticks paused */
13045 +};
13046 +
13047 +
13048 +#ifdef CONFIG_VSERVER_DEBUG
13049 +
13050 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13051 +{
13052 +       printk("\t_vx_sched:\n");
13053 +       printk("\t priority = %4d\n", sched->prio_bias);
13054 +}
13055 +
13056 +#endif
13057 +
13058 +#endif /* _VX_SCHED_DEF_H */
13059 diff -NurpP --minimal linux-3.7/include/linux/vserver/signal.h linux-3.7-vs2.3.5.1/include/linux/vserver/signal.h
13060 --- linux-3.7/include/linux/vserver/signal.h    1970-01-01 00:00:00.000000000 +0000
13061 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/signal.h  2012-12-11 15:56:32.000000000 +0000
13062 @@ -0,0 +1,14 @@
13063 +#ifndef _VX_SIGNAL_H
13064 +#define _VX_SIGNAL_H
13065 +
13066 +
13067 +#ifdef __KERNEL__
13068 +
13069 +struct vx_info;
13070 +
13071 +int vx_info_kill(struct vx_info *, int, int);
13072 +
13073 +#endif /* __KERNEL__ */
13074 +#else  /* _VX_SIGNAL_H */
13075 +#warning duplicate inclusion
13076 +#endif /* _VX_SIGNAL_H */
13077 diff -NurpP --minimal linux-3.7/include/linux/vserver/signal_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/signal_cmd.h
13078 --- linux-3.7/include/linux/vserver/signal_cmd.h        1970-01-01 00:00:00.000000000 +0000
13079 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/signal_cmd.h      2012-12-11 15:56:32.000000000 +0000
13080 @@ -0,0 +1,43 @@
13081 +#ifndef _VX_SIGNAL_CMD_H
13082 +#define _VX_SIGNAL_CMD_H
13083 +
13084 +
13085 +/*  signalling vserver commands */
13086 +
13087 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13088 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13089 +
13090 +struct vcmd_ctx_kill_v0 {
13091 +       int32_t pid;
13092 +       int32_t sig;
13093 +};
13094 +
13095 +struct vcmd_wait_exit_v0 {
13096 +       int32_t reboot_cmd;
13097 +       int32_t exit_code;
13098 +};
13099 +
13100 +#ifdef __KERNEL__
13101 +
13102 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13103 +extern int vc_wait_exit(struct vx_info *, void __user *);
13104 +
13105 +#endif /* __KERNEL__ */
13106 +
13107 +/*  process alteration commands */
13108 +
13109 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13110 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13111 +
13112 +struct vcmd_pflags_v0 {
13113 +       uint32_t flagword;
13114 +       uint32_t mask;
13115 +};
13116 +
13117 +#ifdef __KERNEL__
13118 +
13119 +extern int vc_get_pflags(uint32_t pid, void __user *);
13120 +extern int vc_set_pflags(uint32_t pid, void __user *);
13121 +
13122 +#endif /* __KERNEL__ */
13123 +#endif /* _VX_SIGNAL_CMD_H */
13124 diff -NurpP --minimal linux-3.7/include/linux/vserver/space.h linux-3.7-vs2.3.5.1/include/linux/vserver/space.h
13125 --- linux-3.7/include/linux/vserver/space.h     1970-01-01 00:00:00.000000000 +0000
13126 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/space.h   2012-12-11 15:56:32.000000000 +0000
13127 @@ -0,0 +1,12 @@
13128 +#ifndef _VX_SPACE_H
13129 +#define _VX_SPACE_H
13130 +
13131 +#include <linux/types.h>
13132 +
13133 +struct vx_info;
13134 +
13135 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13136 +
13137 +#else  /* _VX_SPACE_H */
13138 +#warning duplicate inclusion
13139 +#endif /* _VX_SPACE_H */
13140 diff -NurpP --minimal linux-3.7/include/linux/vserver/space_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/space_cmd.h
13141 --- linux-3.7/include/linux/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
13142 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/space_cmd.h       2012-12-11 15:56:32.000000000 +0000
13143 @@ -0,0 +1,38 @@
13144 +#ifndef _VX_SPACE_CMD_H
13145 +#define _VX_SPACE_CMD_H
13146 +
13147 +
13148 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13149 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13150 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13151 +
13152 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13153 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13154 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13155 +
13156 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13157 +
13158 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13159 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13160 +
13161 +
13162 +struct vcmd_space_mask_v1 {
13163 +       uint64_t mask;
13164 +};
13165 +
13166 +struct vcmd_space_mask_v2 {
13167 +       uint64_t mask;
13168 +       uint32_t index;
13169 +};
13170 +
13171 +
13172 +#ifdef __KERNEL__
13173 +
13174 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13175 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13176 +extern int vc_enter_space(struct vx_info *, void __user *);
13177 +extern int vc_set_space(struct vx_info *, void __user *);
13178 +extern int vc_get_space_mask(void __user *, int);
13179 +
13180 +#endif /* __KERNEL__ */
13181 +#endif /* _VX_SPACE_CMD_H */
13182 diff -NurpP --minimal linux-3.7/include/linux/vserver/switch.h linux-3.7-vs2.3.5.1/include/linux/vserver/switch.h
13183 --- linux-3.7/include/linux/vserver/switch.h    1970-01-01 00:00:00.000000000 +0000
13184 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/switch.h  2012-12-11 15:56:32.000000000 +0000
13185 @@ -0,0 +1,98 @@
13186 +#ifndef _VX_SWITCH_H
13187 +#define _VX_SWITCH_H
13188 +
13189 +#include <linux/types.h>
13190 +
13191 +
13192 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13193 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13194 +#define VC_VERSION(c)          ((c) & 0xFFF)
13195 +
13196 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13197 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13198 +
13199 +/*
13200 +
13201 +  Syscall Matrix V2.8
13202 +
13203 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13204 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13205 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13206 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13207 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13208 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13209 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13210 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13211 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13212 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13213 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13214 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13215 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13216 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13217 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13218 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13219 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13220 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13221 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13222 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13223 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13224 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13225 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13226 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13227 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13228 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13229 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13230 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13231 +
13232 +*/
13233 +
13234 +#define VC_CAT_VERSION         0
13235 +
13236 +#define VC_CAT_VSETUP          1
13237 +#define VC_CAT_VHOST           2
13238 +
13239 +#define VC_CAT_DEVICE          6
13240 +
13241 +#define VC_CAT_VPROC           9
13242 +#define VC_CAT_PROCALT         10
13243 +#define VC_CAT_PROCMIG         11
13244 +#define VC_CAT_PROCTRL         12
13245 +
13246 +#define VC_CAT_SCHED           14
13247 +#define VC_CAT_MEMCTRL         20
13248 +
13249 +#define VC_CAT_VNET            25
13250 +#define VC_CAT_NETALT          26
13251 +#define VC_CAT_NETMIG          27
13252 +#define VC_CAT_NETCTRL         28
13253 +
13254 +#define VC_CAT_TAGMIG          35
13255 +#define VC_CAT_DLIMIT          36
13256 +#define VC_CAT_INODE           38
13257 +
13258 +#define VC_CAT_VSTAT           40
13259 +#define VC_CAT_VINFO           46
13260 +#define VC_CAT_EVENT           48
13261 +
13262 +#define VC_CAT_FLAGS           52
13263 +#define VC_CAT_VSPACE          54
13264 +#define VC_CAT_DEBUG           56
13265 +#define VC_CAT_RLIMIT          60
13266 +
13267 +#define VC_CAT_SYSTEST         61
13268 +#define VC_CAT_COMPAT          63
13269 +
13270 +/*  query version */
13271 +
13272 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13273 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13274 +
13275 +
13276 +#ifdef __KERNEL__
13277 +
13278 +#include <linux/errno.h>
13279 +
13280 +#endif /* __KERNEL__ */
13281 +
13282 +#endif /* _VX_SWITCH_H */
13283 +
13284 diff -NurpP --minimal linux-3.7/include/linux/vserver/tag.h linux-3.7-vs2.3.5.1/include/linux/vserver/tag.h
13285 --- linux-3.7/include/linux/vserver/tag.h       1970-01-01 00:00:00.000000000 +0000
13286 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/tag.h     2012-12-11 15:56:32.000000000 +0000
13287 @@ -0,0 +1,143 @@
13288 +#ifndef _DX_TAG_H
13289 +#define _DX_TAG_H
13290 +
13291 +#include <linux/types.h>
13292 +
13293 +
13294 +#define DX_TAG(in)     (IS_TAGGED(in))
13295 +
13296 +
13297 +#ifdef CONFIG_TAG_NFSD
13298 +#define DX_TAG_NFSD    1
13299 +#else
13300 +#define DX_TAG_NFSD    0
13301 +#endif
13302 +
13303 +
13304 +#ifdef CONFIG_TAGGING_NONE
13305 +
13306 +#define MAX_UID                0xFFFFFFFF
13307 +#define MAX_GID                0xFFFFFFFF
13308 +
13309 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13310 +
13311 +#define TAGINO_UID(cond, uid, tag)     (uid)
13312 +#define TAGINO_GID(cond, gid, tag)     (gid)
13313 +
13314 +#endif
13315 +
13316 +
13317 +#ifdef CONFIG_TAGGING_GID16
13318 +
13319 +#define MAX_UID                0xFFFFFFFF
13320 +#define MAX_GID                0x0000FFFF
13321 +
13322 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13323 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13324 +
13325 +#define TAGINO_UID(cond, uid, tag)     (uid)
13326 +#define TAGINO_GID(cond, gid, tag)     \
13327 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13328 +
13329 +#endif
13330 +
13331 +
13332 +#ifdef CONFIG_TAGGING_ID24
13333 +
13334 +#define MAX_UID                0x00FFFFFF
13335 +#define MAX_GID                0x00FFFFFF
13336 +
13337 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13338 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13339 +
13340 +#define TAGINO_UID(cond, uid, tag)     \
13341 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13342 +#define TAGINO_GID(cond, gid, tag)     \
13343 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13344 +
13345 +#endif
13346 +
13347 +
13348 +#ifdef CONFIG_TAGGING_UID16
13349 +
13350 +#define MAX_UID                0x0000FFFF
13351 +#define MAX_GID                0xFFFFFFFF
13352 +
13353 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13354 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13355 +
13356 +#define TAGINO_UID(cond, uid, tag)     \
13357 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13358 +#define TAGINO_GID(cond, gid, tag)     (gid)
13359 +
13360 +#endif
13361 +
13362 +
13363 +#ifdef CONFIG_TAGGING_INTERN
13364 +
13365 +#define MAX_UID                0xFFFFFFFF
13366 +#define MAX_GID                0xFFFFFFFF
13367 +
13368 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13369 +       ((cond) ? (tag) : 0)
13370 +
13371 +#define TAGINO_UID(cond, uid, tag)     (uid)
13372 +#define TAGINO_GID(cond, gid, tag)     (gid)
13373 +
13374 +#endif
13375 +
13376 +
13377 +#ifndef CONFIG_TAGGING_NONE
13378 +#define dx_current_fstag(sb)   \
13379 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13380 +#else
13381 +#define dx_current_fstag(sb)   (0)
13382 +#endif
13383 +
13384 +#ifndef CONFIG_TAGGING_INTERN
13385 +#define TAGINO_TAG(cond, tag)  (0)
13386 +#else
13387 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13388 +#endif
13389 +
13390 +#define INOTAG_UID(cond, uid, gid)     \
13391 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13392 +#define INOTAG_GID(cond, uid, gid)     \
13393 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13394 +
13395 +
13396 +static inline uid_t dx_map_uid(uid_t uid)
13397 +{
13398 +       if ((uid > MAX_UID) && (uid != -1))
13399 +               uid = -2;
13400 +       return (uid & MAX_UID);
13401 +}
13402 +
13403 +static inline gid_t dx_map_gid(gid_t gid)
13404 +{
13405 +       if ((gid > MAX_GID) && (gid != -1))
13406 +               gid = -2;
13407 +       return (gid & MAX_GID);
13408 +}
13409 +
13410 +struct peer_tag {
13411 +       int32_t xid;
13412 +       int32_t nid;
13413 +};
13414 +
13415 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13416 +
13417 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13418 +                unsigned long *flags);
13419 +
13420 +#ifdef CONFIG_PROPAGATE
13421 +
13422 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13423 +
13424 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13425 +
13426 +#else
13427 +#define dx_propagate_tag(n, i) do { } while (0)
13428 +#endif
13429 +
13430 +#endif /* _DX_TAG_H */
13431 diff -NurpP --minimal linux-3.7/include/linux/vserver/tag_cmd.h linux-3.7-vs2.3.5.1/include/linux/vserver/tag_cmd.h
13432 --- linux-3.7/include/linux/vserver/tag_cmd.h   1970-01-01 00:00:00.000000000 +0000
13433 +++ linux-3.7-vs2.3.5.1/include/linux/vserver/tag_cmd.h 2012-12-11 15:56:32.000000000 +0000
13434 @@ -0,0 +1,22 @@
13435 +#ifndef _VX_TAG_CMD_H
13436 +#define _VX_TAG_CMD_H
13437 +
13438 +
13439 +/* vinfo commands */
13440 +
13441 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13442 +
13443 +#ifdef __KERNEL__
13444 +extern int vc_task_tag(uint32_t);
13445 +
13446 +#endif /* __KERNEL__ */
13447 +
13448 +/* context commands */
13449 +
13450 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13451 +
13452 +#ifdef __KERNEL__
13453 +extern int vc_tag_migrate(uint32_t);
13454 +
13455 +#endif /* __KERNEL__ */
13456 +#endif /* _VX_TAG_CMD_H */
13457 diff -NurpP --minimal linux-3.7/include/net/addrconf.h linux-3.7-vs2.3.5.1/include/net/addrconf.h
13458 --- linux-3.7/include/net/addrconf.h    2012-12-11 15:47:46.000000000 +0000
13459 +++ linux-3.7-vs2.3.5.1/include/net/addrconf.h  2012-12-11 15:56:32.000000000 +0000
13460 @@ -81,7 +81,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13461                                                const struct net_device *dev,
13462                                                const struct in6_addr *daddr,
13463                                                unsigned int srcprefs,
13464 -                                              struct in6_addr *saddr);
13465 +                                              struct in6_addr *saddr,
13466 +                                              struct nx_info *nxi);
13467  extern int                     ipv6_get_lladdr(struct net_device *dev,
13468                                                 struct in6_addr *addr,
13469                                                 unsigned char banned_flags);
13470 diff -NurpP --minimal linux-3.7/include/net/af_unix.h linux-3.7-vs2.3.5.1/include/net/af_unix.h
13471 --- linux-3.7/include/net/af_unix.h     2012-10-04 13:27:47.000000000 +0000
13472 +++ linux-3.7-vs2.3.5.1/include/net/af_unix.h   2012-12-11 15:56:32.000000000 +0000
13473 @@ -4,6 +4,7 @@
13474  #include <linux/socket.h>
13475  #include <linux/un.h>
13476  #include <linux/mutex.h>
13477 +#include <linux/vs_base.h>
13478  #include <net/sock.h>
13479  
13480  extern void unix_inflight(struct file *fp);
13481 diff -NurpP --minimal linux-3.7/include/net/inet_timewait_sock.h linux-3.7-vs2.3.5.1/include/net/inet_timewait_sock.h
13482 --- linux-3.7/include/net/inet_timewait_sock.h  2012-03-19 18:47:29.000000000 +0000
13483 +++ linux-3.7-vs2.3.5.1/include/net/inet_timewait_sock.h        2012-12-11 15:56:32.000000000 +0000
13484 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13485  #define tw_net                 __tw_common.skc_net
13486  #define tw_daddr               __tw_common.skc_daddr
13487  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13488 +#define tw_xid                 __tw_common.skc_xid
13489 +#define tw_vx_info             __tw_common.skc_vx_info
13490 +#define tw_nid                 __tw_common.skc_nid
13491 +#define tw_nx_info             __tw_common.skc_nx_info
13492         int                     tw_timeout;
13493         volatile unsigned char  tw_substate;
13494         unsigned char           tw_rcv_wscale;
13495 diff -NurpP --minimal linux-3.7/include/net/ip6_route.h linux-3.7-vs2.3.5.1/include/net/ip6_route.h
13496 --- linux-3.7/include/net/ip6_route.h   2012-10-04 13:27:47.000000000 +0000
13497 +++ linux-3.7-vs2.3.5.1/include/net/ip6_route.h 2012-12-11 15:56:32.000000000 +0000
13498 @@ -97,7 +97,8 @@ extern int                    ip6_route_get_saddr(struct
13499                                                     struct rt6_info *rt,
13500                                                     const struct in6_addr *daddr,
13501                                                     unsigned int prefs,
13502 -                                                   struct in6_addr *saddr);
13503 +                                                   struct in6_addr *saddr,
13504 +                                                   struct nx_info *nxi);
13505  
13506  extern struct rt6_info         *rt6_lookup(struct net *net,
13507                                             const struct in6_addr *daddr,
13508 diff -NurpP --minimal linux-3.7/include/net/route.h linux-3.7-vs2.3.5.1/include/net/route.h
13509 --- linux-3.7/include/net/route.h       2012-12-11 15:47:46.000000000 +0000
13510 +++ linux-3.7-vs2.3.5.1/include/net/route.h     2012-12-11 15:56:32.000000000 +0000
13511 @@ -204,6 +204,9 @@ static inline void ip_rt_put(struct rtab
13512                 dst_release(&rt->dst);
13513  }
13514  
13515 +#include <linux/vs_base.h>
13516 +#include <linux/vs_inet.h>
13517 +
13518  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13519  
13520  extern const __u8 ip_tos2prio[16];
13521 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13522                            protocol, flow_flags, dst, src, dport, sport);
13523  }
13524  
13525 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13526 +       struct flowi4 *);
13527 +
13528  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13529                                               __be32 dst, __be32 src, u32 tos,
13530                                               int oif, u8 protocol,
13531 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13532  {
13533         struct net *net = sock_net(sk);
13534         struct rtable *rt;
13535 +       struct nx_info *nx_info = current_nx_info();
13536  
13537         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13538                               sport, dport, sk, can_sleep);
13539  
13540 -       if (!dst || !src) {
13541 +       if (sk)
13542 +               nx_info = sk->sk_nx_info;
13543 +
13544 +       vxdprintk(VXD_CBIT(net, 4),
13545 +               "ip_route_connect(%p) %p,%p;%lx",
13546 +               sk, nx_info, sk->sk_socket,
13547 +               (sk->sk_socket?sk->sk_socket->flags:0));
13548 +
13549 +       rt = ip_v4_find_src(net, nx_info, fl4);
13550 +       if (IS_ERR(rt))
13551 +               return rt;
13552 +       ip_rt_put(rt);
13553 +
13554 +       if (!fl4->daddr || !fl4->saddr) {
13555                 rt = __ip_route_output_key(net, fl4);
13556                 if (IS_ERR(rt))
13557                         return rt;
13558 diff -NurpP --minimal linux-3.7/include/net/sock.h linux-3.7-vs2.3.5.1/include/net/sock.h
13559 --- linux-3.7/include/net/sock.h        2012-12-11 15:47:46.000000000 +0000
13560 +++ linux-3.7-vs2.3.5.1/include/net/sock.h      2012-12-11 15:56:32.000000000 +0000
13561 @@ -171,6 +171,10 @@ struct sock_common {
13562  #ifdef CONFIG_NET_NS
13563         struct net              *skc_net;
13564  #endif
13565 +       xid_t                   skc_xid;
13566 +       struct vx_info          *skc_vx_info;
13567 +       nid_t                   skc_nid;
13568 +       struct nx_info          *skc_nx_info;
13569         /*
13570          * fields between dontcopy_begin/dontcopy_end
13571          * are not copied in sock_copy()
13572 @@ -283,6 +287,10 @@ struct sock {
13573  #define sk_bind_node           __sk_common.skc_bind_node
13574  #define sk_prot                        __sk_common.skc_prot
13575  #define sk_net                 __sk_common.skc_net
13576 +#define sk_xid                 __sk_common.skc_xid
13577 +#define sk_vx_info             __sk_common.skc_vx_info
13578 +#define sk_nid                 __sk_common.skc_nid
13579 +#define sk_nx_info             __sk_common.skc_nx_info
13580         socket_lock_t           sk_lock;
13581         struct sk_buff_head     sk_receive_queue;
13582         /*
13583 diff -NurpP --minimal linux-3.7/include/uapi/linux/capability.h linux-3.7-vs2.3.5.1/include/uapi/linux/capability.h
13584 --- linux-3.7/include/uapi/linux/capability.h   2012-12-11 15:47:47.000000000 +0000
13585 +++ linux-3.7-vs2.3.5.1/include/uapi/linux/capability.h 2012-12-11 16:08:57.000000000 +0000
13586 @@ -259,6 +259,7 @@ struct vfs_cap_data {
13587     arbitrary SCSI commands */
13588  /* Allow setting encryption key on loopback filesystem */
13589  /* Allow setting zone reclaim policy */
13590 +/* Allow the selection of a security context */
13591  
13592  #define CAP_SYS_ADMIN        21
13593  
13594 @@ -345,7 +346,12 @@ struct vfs_cap_data {
13595  
13596  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
13597  
13598 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
13599 +/* Allow context manipulations */
13600 +/* Allow changing context info on files */
13601 +
13602 +#define CAP_CONTEXT         63
13603 +
13604 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
13605  
13606  /*
13607   * Bit location of each capability (used by user-space library and kernel)
13608 diff -NurpP --minimal linux-3.7/include/uapi/linux/fs.h linux-3.7-vs2.3.5.1/include/uapi/linux/fs.h
13609 --- linux-3.7/include/uapi/linux/fs.h   2012-12-11 15:47:47.000000000 +0000
13610 +++ linux-3.7-vs2.3.5.1/include/uapi/linux/fs.h 2012-12-11 16:35:06.000000000 +0000
13611 @@ -86,6 +86,9 @@ struct inodes_stat_t {
13612  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
13613  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
13614  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
13615 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
13616 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
13617 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
13618  #define MS_NOSEC       (1<<28)
13619  #define MS_BORN                (1<<29)
13620  #define MS_ACTIVE      (1<<30)
13621 @@ -189,11 +192,14 @@ struct inodes_stat_t {
13622  #define FS_EXTENT_FL                   0x00080000 /* Extents */
13623  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
13624  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
13625 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
13626  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
13627  
13628 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
13629 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
13630 -
13631 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
13632 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
13633 +
13634 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
13635 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
13636  
13637  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
13638  #define SYNC_FILE_RANGE_WRITE          2
13639 diff -NurpP --minimal linux-3.7/include/uapi/linux/gfs2_ondisk.h linux-3.7-vs2.3.5.1/include/uapi/linux/gfs2_ondisk.h
13640 --- linux-3.7/include/uapi/linux/gfs2_ondisk.h  2012-12-11 15:47:47.000000000 +0000
13641 +++ linux-3.7-vs2.3.5.1/include/uapi/linux/gfs2_ondisk.h        2012-12-11 21:58:36.000000000 +0000
13642 @@ -225,6 +225,9 @@ enum {
13643         gfs2fl_Sync             = 8,
13644         gfs2fl_System           = 9,
13645         gfs2fl_TopLevel         = 10,
13646 +       gfs2fl_IXUnlink         = 16,
13647 +       gfs2fl_Barrier          = 17,
13648 +       gfs2fl_Cow              = 18,
13649         gfs2fl_TruncInProg      = 29,
13650         gfs2fl_InheritDirectio  = 30,
13651         gfs2fl_InheritJdata     = 31,
13652 @@ -242,6 +245,9 @@ enum {
13653  #define GFS2_DIF_SYNC                  0x00000100
13654  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
13655  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
13656 +#define GFS2_DIF_IXUNLINK               0x00010000
13657 +#define GFS2_DIF_BARRIER                0x00020000
13658 +#define GFS2_DIF_COW                    0x00040000
13659  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
13660  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
13661  #define GFS2_DIF_INHERIT_JDATA         0x80000000
13662 diff -NurpP --minimal linux-3.7/include/uapi/linux/if_tun.h linux-3.7-vs2.3.5.1/include/uapi/linux/if_tun.h
13663 --- linux-3.7/include/uapi/linux/if_tun.h       2012-12-11 15:47:47.000000000 +0000
13664 +++ linux-3.7-vs2.3.5.1/include/uapi/linux/if_tun.h     2012-12-11 16:11:03.000000000 +0000
13665 @@ -53,6 +53,7 @@
13666  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
13667  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
13668  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
13669 +#define TUNSETNID     _IOW('T', 217, int)
13670  
13671  /* TUNSETIFF ifr flags */
13672  #define IFF_TUN                0x0001
13673 diff -NurpP --minimal linux-3.7/include/uapi/linux/major.h linux-3.7-vs2.3.5.1/include/uapi/linux/major.h
13674 --- linux-3.7/include/uapi/linux/major.h        2012-12-11 15:47:47.000000000 +0000
13675 +++ linux-3.7-vs2.3.5.1/include/uapi/linux/major.h      2012-12-11 22:10:37.000000000 +0000
13676 @@ -15,6 +15,7 @@
13677  #define HD_MAJOR               IDE0_MAJOR
13678  #define PTY_SLAVE_MAJOR                3
13679  #define TTY_MAJOR              4
13680 +#define VROOT_MAJOR            4
13681  #define TTYAUX_MAJOR           5
13682  #define LP_MAJOR               6
13683  #define VCS_MAJOR              7
13684 diff -NurpP --minimal linux-3.7/include/uapi/linux/nfs_mount.h linux-3.7-vs2.3.5.1/include/uapi/linux/nfs_mount.h
13685 --- linux-3.7/include/uapi/linux/nfs_mount.h    2012-12-11 15:47:47.000000000 +0000
13686 +++ linux-3.7-vs2.3.5.1/include/uapi/linux/nfs_mount.h  2012-12-11 22:05:39.000000000 +0000
13687 @@ -63,7 +63,8 @@ struct nfs_mount_data {
13688  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
13689  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
13690  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
13691 -#define NFS_MOUNT_FLAGMASK     0xFFFF
13692 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
13693 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
13694  
13695  /* The following are for internal use only */
13696  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
13697 diff -NurpP --minimal linux-3.7/include/uapi/linux/reboot.h linux-3.7-vs2.3.5.1/include/uapi/linux/reboot.h
13698 --- linux-3.7/include/uapi/linux/reboot.h       2012-12-11 15:47:47.000000000 +0000
13699 +++ linux-3.7-vs2.3.5.1/include/uapi/linux/reboot.h     2012-12-11 16:29:23.000000000 +0000
13700 @@ -33,7 +33,7 @@
13701  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
13702  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
13703  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
13704 -
13705 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
13706  
13707  
13708  #endif /* _UAPI_LINUX_REBOOT_H */
13709 diff -NurpP --minimal linux-3.7/include/uapi/linux/sysctl.h linux-3.7-vs2.3.5.1/include/uapi/linux/sysctl.h
13710 --- linux-3.7/include/uapi/linux/sysctl.h       2012-12-11 15:47:47.000000000 +0000
13711 +++ linux-3.7-vs2.3.5.1/include/uapi/linux/sysctl.h     2012-12-11 16:42:05.000000000 +0000
13712 @@ -60,6 +60,7 @@ enum
13713         CTL_ABI=9,              /* Binary emulation */
13714         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
13715         CTL_ARLAN=254,          /* arlan wireless driver */
13716 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
13717         CTL_S390DBF=5677,       /* s390 debug */
13718         CTL_SUNRPC=7249,        /* sunrpc debug */
13719         CTL_PM=9899,            /* frv power management */
13720 @@ -94,6 +95,7 @@ enum
13721  
13722         KERN_PANIC=15,          /* int: panic timeout */
13723         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
13724 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
13725  
13726         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
13727         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
13728 diff -NurpP --minimal linux-3.7/init/Kconfig linux-3.7-vs2.3.5.1/init/Kconfig
13729 --- linux-3.7/init/Kconfig      2012-12-11 15:47:47.000000000 +0000
13730 +++ linux-3.7-vs2.3.5.1/init/Kconfig    2012-12-11 23:14:38.000000000 +0000
13731 @@ -699,6 +699,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
13732  menuconfig CGROUPS
13733         boolean "Control Group support"
13734         depends on EVENTFD
13735 +       default y
13736         help
13737           This option adds support for grouping sets of processes together, for
13738           use with process control subsystems such as Cpusets, CFS, memory
13739 @@ -964,6 +965,7 @@ config USER_NS
13740         bool "User namespace (EXPERIMENTAL)"
13741         depends on EXPERIMENTAL
13742         depends on UIDGID_CONVERTED
13743 +       depends on VSERVER_DISABLED
13744         select UIDGID_STRICT_TYPE_CHECKS
13745  
13746         default n
13747 diff -NurpP --minimal linux-3.7/init/main.c linux-3.7-vs2.3.5.1/init/main.c
13748 --- linux-3.7/init/main.c       2012-12-11 15:47:48.000000000 +0000
13749 +++ linux-3.7-vs2.3.5.1/init/main.c     2012-12-11 16:56:16.000000000 +0000
13750 @@ -70,6 +70,7 @@
13751  #include <linux/perf_event.h>
13752  #include <linux/file.h>
13753  #include <linux/ptrace.h>
13754 +#include <linux/vserver/percpu.h>
13755  
13756  #include <asm/io.h>
13757  #include <asm/bugs.h>
13758 diff -NurpP --minimal linux-3.7/ipc/mqueue.c linux-3.7-vs2.3.5.1/ipc/mqueue.c
13759 --- linux-3.7/ipc/mqueue.c      2012-12-11 15:47:48.000000000 +0000
13760 +++ linux-3.7-vs2.3.5.1/ipc/mqueue.c    2012-12-11 15:56:32.000000000 +0000
13761 @@ -35,6 +35,8 @@
13762  #include <linux/ipc_namespace.h>
13763  #include <linux/user_namespace.h>
13764  #include <linux/slab.h>
13765 +#include <linux/vs_context.h>
13766 +#include <linux/vs_limit.h>
13767  
13768  #include <net/sock.h>
13769  #include "util.h"
13770 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13771         struct pid* notify_owner;
13772         struct user_namespace *notify_user_ns;
13773         struct user_struct *user;       /* user who created, for accounting */
13774 +       struct vx_info *vxi;
13775         struct sock *notify_sock;
13776         struct sk_buff *notify_cookie;
13777  
13778 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13779         if (S_ISREG(mode)) {
13780                 struct mqueue_inode_info *info;
13781                 unsigned long mq_bytes, mq_treesize;
13782 +               struct vx_info *vxi = current_vx_info();
13783  
13784                 inode->i_fop = &mqueue_file_operations;
13785                 inode->i_size = FILENT_SIZE;
13786 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13787                 info->notify_user_ns = NULL;
13788                 info->qsize = 0;
13789                 info->user = NULL;      /* set when all is ok */
13790 +               info->vxi = NULL;
13791                 info->msg_tree = RB_ROOT;
13792                 info->node_cache = NULL;
13793                 memset(&info->attr, 0, sizeof(info->attr));
13794 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13795  
13796                 spin_lock(&mq_lock);
13797                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13798 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13799 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13800 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13801                         spin_unlock(&mq_lock);
13802                         /* mqueue_evict_inode() releases info->messages */
13803                         ret = -EMFILE;
13804                         goto out_inode;
13805                 }
13806                 u->mq_bytes += mq_bytes;
13807 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13808                 spin_unlock(&mq_lock);
13809  
13810                 /* all is ok */
13811                 info->user = get_uid(u);
13812 +               info->vxi = get_vx_info(vxi);
13813         } else if (S_ISDIR(mode)) {
13814                 inc_nlink(inode);
13815                 /* Some things misbehave if size == 0 on a directory */
13816 @@ -394,8 +402,11 @@ static void mqueue_evict_inode(struct in
13817  
13818         user = info->user;
13819         if (user) {
13820 +               struct vx_info *vxi = info->vxi;
13821 +
13822                 spin_lock(&mq_lock);
13823                 user->mq_bytes -= mq_bytes;
13824 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13825                 /*
13826                  * get_ns_from_inode() ensures that the
13827                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13828 @@ -405,6 +416,7 @@ static void mqueue_evict_inode(struct in
13829                 if (ipc_ns)
13830                         ipc_ns->mq_queues_count--;
13831                 spin_unlock(&mq_lock);
13832 +               put_vx_info(vxi);
13833                 free_uid(user);
13834         }
13835         if (ipc_ns)
13836 diff -NurpP --minimal linux-3.7/ipc/msg.c linux-3.7-vs2.3.5.1/ipc/msg.c
13837 --- linux-3.7/ipc/msg.c 2012-12-11 15:47:48.000000000 +0000
13838 +++ linux-3.7-vs2.3.5.1/ipc/msg.c       2012-12-11 15:56:32.000000000 +0000
13839 @@ -37,6 +37,7 @@
13840  #include <linux/rwsem.h>
13841  #include <linux/nsproxy.h>
13842  #include <linux/ipc_namespace.h>
13843 +#include <linux/vs_base.h>
13844  
13845  #include <asm/current.h>
13846  #include <asm/uaccess.h>
13847 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13848  
13849         msq->q_perm.mode = msgflg & S_IRWXUGO;
13850         msq->q_perm.key = key;
13851 +       msq->q_perm.xid = vx_current_xid();
13852  
13853         msq->q_perm.security = NULL;
13854         retval = security_msg_queue_alloc(msq);
13855 diff -NurpP --minimal linux-3.7/ipc/namespace.c linux-3.7-vs2.3.5.1/ipc/namespace.c
13856 --- linux-3.7/ipc/namespace.c   2012-07-22 21:39:46.000000000 +0000
13857 +++ linux-3.7-vs2.3.5.1/ipc/namespace.c 2012-12-11 15:56:32.000000000 +0000
13858 @@ -13,11 +13,12 @@
13859  #include <linux/mount.h>
13860  #include <linux/user_namespace.h>
13861  #include <linux/proc_fs.h>
13862 +#include <linux/vs_base.h>
13863 +#include <linux/vserver/global.h>
13864  
13865  #include "util.h"
13866  
13867 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
13868 -                                          struct ipc_namespace *old_ns)
13869 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
13870  {
13871         struct ipc_namespace *ns;
13872         int err;
13873 @@ -46,19 +47,19 @@ static struct ipc_namespace *create_ipc_
13874         ipcns_notify(IPCNS_CREATED);
13875         register_ipcns_notifier(ns);
13876  
13877 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
13878 +       // ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
13879 +       ns->user_ns = get_user_ns(user_ns);
13880  
13881         return ns;
13882  }
13883  
13884  struct ipc_namespace *copy_ipcs(unsigned long flags,
13885 -                               struct task_struct *tsk)
13886 +                               struct ipc_namespace *old_ns,
13887 +                               struct user_namespace *user_ns)
13888  {
13889 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
13890 -
13891         if (!(flags & CLONE_NEWIPC))
13892 -               return get_ipc_ns(ns);
13893 -       return create_ipc_ns(tsk, ns);
13894 +               return get_ipc_ns(old_ns);
13895 +       return create_ipc_ns(user_ns);
13896  }
13897  
13898  /*
13899 diff -NurpP --minimal linux-3.7/ipc/sem.c linux-3.7-vs2.3.5.1/ipc/sem.c
13900 --- linux-3.7/ipc/sem.c 2012-12-11 15:47:48.000000000 +0000
13901 +++ linux-3.7-vs2.3.5.1/ipc/sem.c       2012-12-11 15:56:32.000000000 +0000
13902 @@ -86,6 +86,8 @@
13903  #include <linux/rwsem.h>
13904  #include <linux/nsproxy.h>
13905  #include <linux/ipc_namespace.h>
13906 +#include <linux/vs_base.h>
13907 +#include <linux/vs_limit.h>
13908  
13909  #include <asm/uaccess.h>
13910  #include "util.h"
13911 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13912  
13913         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13914         sma->sem_perm.key = key;
13915 +       sma->sem_perm.xid = vx_current_xid();
13916  
13917         sma->sem_perm.security = NULL;
13918         retval = security_sem_alloc(sma);
13919 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13920                 return id;
13921         }
13922         ns->used_sems += nsems;
13923 +       /* FIXME: obsoleted? */
13924 +       vx_semary_inc(sma);
13925 +       vx_nsems_add(sma, nsems);
13926  
13927         sma->sem_base = (struct sem *) &sma[1];
13928  
13929 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13930  
13931         wake_up_sem_queue_do(&tasks);
13932         ns->used_sems -= sma->sem_nsems;
13933 +       /* FIXME: obsoleted? */
13934 +       vx_nsems_sub(sma, sma->sem_nsems);
13935 +       vx_semary_dec(sma);
13936         security_sem_free(sma);
13937         ipc_rcu_putref(sma);
13938  }
13939 diff -NurpP --minimal linux-3.7/ipc/shm.c linux-3.7-vs2.3.5.1/ipc/shm.c
13940 --- linux-3.7/ipc/shm.c 2012-12-11 15:47:48.000000000 +0000
13941 +++ linux-3.7-vs2.3.5.1/ipc/shm.c       2012-12-11 15:56:32.000000000 +0000
13942 @@ -39,6 +39,8 @@
13943  #include <linux/nsproxy.h>
13944  #include <linux/mount.h>
13945  #include <linux/ipc_namespace.h>
13946 +#include <linux/vs_context.h>
13947 +#include <linux/vs_limit.h>
13948  
13949  #include <asm/uaccess.h>
13950  
13951 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13952   */
13953  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13954  {
13955 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13956 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13957 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13958 +
13959 +       vx_ipcshm_sub(vxi, shp, numpages);
13960 +       ns->shm_tot -= numpages;
13961 +
13962         shm_rmid(ns, shp);
13963         shm_unlock(shp);
13964         if (!is_file_hugepages(shp->shm_file))
13965 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13966                                                 shp->mlock_user);
13967         fput (shp->shm_file);
13968         security_shm_free(shp);
13969 +       put_vx_info(vxi);
13970         ipc_rcu_putref(shp);
13971  }
13972  
13973 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13974         if (ns->shm_tot + numpages > ns->shm_ctlall)
13975                 return -ENOSPC;
13976  
13977 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13978 +               return -ENOSPC;
13979 +
13980         shp = ipc_rcu_alloc(sizeof(*shp));
13981         if (!shp)
13982                 return -ENOMEM;
13983  
13984         shp->shm_perm.key = key;
13985 +       shp->shm_perm.xid = vx_current_xid();
13986         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13987         shp->mlock_user = NULL;
13988  
13989 @@ -533,6 +545,7 @@ static int newseg(struct ipc_namespace *
13990         ns->shm_tot += numpages;
13991         error = shp->shm_perm.id;
13992         shm_unlock(shp);
13993 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13994         return error;
13995  
13996  no_id:
13997 diff -NurpP --minimal linux-3.7/kernel/Makefile linux-3.7-vs2.3.5.1/kernel/Makefile
13998 --- linux-3.7/kernel/Makefile   2012-12-11 15:47:48.000000000 +0000
13999 +++ linux-3.7-vs2.3.5.1/kernel/Makefile 2012-12-11 15:56:32.000000000 +0000
14000 @@ -24,6 +24,7 @@ endif
14001  
14002  obj-y += sched/
14003  obj-y += power/
14004 +obj-y += vserver/
14005  
14006  ifeq ($(CONFIG_CHECKPOINT_RESTORE),y)
14007  obj-$(CONFIG_X86) += kcmp.o
14008 diff -NurpP --minimal linux-3.7/kernel/auditsc.c linux-3.7-vs2.3.5.1/kernel/auditsc.c
14009 --- linux-3.7/kernel/auditsc.c  2012-12-11 15:47:48.000000000 +0000
14010 +++ linux-3.7-vs2.3.5.1/kernel/auditsc.c        2012-12-11 15:56:32.000000000 +0000
14011 @@ -2372,7 +2372,7 @@ int audit_set_loginuid(kuid_t loginuid)
14012         if (uid_valid(task->loginuid))
14013                 return -EPERM;
14014  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14015 -       if (!capable(CAP_AUDIT_CONTROL))
14016 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
14017                 return -EPERM;
14018  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14019  
14020 diff -NurpP --minimal linux-3.7/kernel/capability.c linux-3.7-vs2.3.5.1/kernel/capability.c
14021 --- linux-3.7/kernel/capability.c       2012-07-22 21:39:46.000000000 +0000
14022 +++ linux-3.7-vs2.3.5.1/kernel/capability.c     2012-12-11 15:56:32.000000000 +0000
14023 @@ -15,6 +15,7 @@
14024  #include <linux/syscalls.h>
14025  #include <linux/pid_namespace.h>
14026  #include <linux/user_namespace.h>
14027 +#include <linux/vs_context.h>
14028  #include <asm/uaccess.h>
14029  
14030  /*
14031 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14032         return 0;
14033  }
14034  
14035 +
14036  /*
14037   * The only thing that can change the capabilities of the current
14038   * process is the current process. As such, we can't be in this code
14039 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14040         return (ret == 0);
14041  }
14042  
14043 +#include <linux/vserver/base.h>
14044 +
14045  /**
14046   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14047   * initial user ns
14048 diff -NurpP --minimal linux-3.7/kernel/compat.c linux-3.7-vs2.3.5.1/kernel/compat.c
14049 --- linux-3.7/kernel/compat.c   2012-07-22 21:39:46.000000000 +0000
14050 +++ linux-3.7-vs2.3.5.1/kernel/compat.c 2012-12-11 21:24:51.000000000 +0000
14051 @@ -27,6 +27,7 @@
14052  #include <linux/times.h>
14053  #include <linux/ptrace.h>
14054  #include <linux/gfp.h>
14055 +#include <linux/vs_time.h>
14056  
14057  #include <asm/uaccess.h>
14058  
14059 @@ -1054,7 +1055,7 @@ asmlinkage long compat_sys_stime(compat_
14060         if (err)
14061                 return err;
14062  
14063 -       do_settimeofday(&tv);
14064 +       vx_settimeofday(&tv);
14065         return 0;
14066  }
14067  
14068 diff -NurpP --minimal linux-3.7/kernel/cred.c linux-3.7-vs2.3.5.1/kernel/cred.c
14069 --- linux-3.7/kernel/cred.c     2012-12-11 15:47:48.000000000 +0000
14070 +++ linux-3.7-vs2.3.5.1/kernel/cred.c   2012-12-11 15:56:32.000000000 +0000
14071 @@ -70,31 +70,6 @@ struct cred init_cred = {
14072  #endif
14073  };
14074  
14075 -static inline void set_cred_subscribers(struct cred *cred, int n)
14076 -{
14077 -#ifdef CONFIG_DEBUG_CREDENTIALS
14078 -       atomic_set(&cred->subscribers, n);
14079 -#endif
14080 -}
14081 -
14082 -static inline int read_cred_subscribers(const struct cred *cred)
14083 -{
14084 -#ifdef CONFIG_DEBUG_CREDENTIALS
14085 -       return atomic_read(&cred->subscribers);
14086 -#else
14087 -       return 0;
14088 -#endif
14089 -}
14090 -
14091 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14092 -{
14093 -#ifdef CONFIG_DEBUG_CREDENTIALS
14094 -       struct cred *cred = (struct cred *) _cred;
14095 -
14096 -       atomic_add(n, &cred->subscribers);
14097 -#endif
14098 -}
14099 -
14100  /*
14101   * Dispose of the shared task group credentials
14102   */
14103 @@ -284,21 +259,16 @@ error:
14104   *
14105   * Call commit_creds() or abort_creds() to clean up.
14106   */
14107 -struct cred *prepare_creds(void)
14108 +struct cred *__prepare_creds(const struct cred *old)
14109  {
14110 -       struct task_struct *task = current;
14111 -       const struct cred *old;
14112         struct cred *new;
14113  
14114 -       validate_process_creds();
14115 -
14116         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14117         if (!new)
14118                 return NULL;
14119  
14120         kdebug("prepare_creds() alloc %p", new);
14121  
14122 -       old = task->cred;
14123         memcpy(new, old, sizeof(struct cred));
14124  
14125         atomic_set(&new->usage, 1);
14126 @@ -326,6 +296,13 @@ error:
14127         abort_creds(new);
14128         return NULL;
14129  }
14130 +
14131 +struct cred *prepare_creds(void)
14132 +{
14133 +       validate_process_creds();
14134 +
14135 +       return __prepare_creds(current->cred);
14136 +}
14137  EXPORT_SYMBOL(prepare_creds);
14138  
14139  /*
14140 diff -NurpP --minimal linux-3.7/kernel/exit.c linux-3.7-vs2.3.5.1/kernel/exit.c
14141 --- linux-3.7/kernel/exit.c     2012-12-11 15:47:48.000000000 +0000
14142 +++ linux-3.7-vs2.3.5.1/kernel/exit.c   2012-12-11 15:56:32.000000000 +0000
14143 @@ -48,6 +48,10 @@
14144  #include <linux/fs_struct.h>
14145  #include <linux/init_task.h>
14146  #include <linux/perf_event.h>
14147 +#include <linux/vs_limit.h>
14148 +#include <linux/vs_context.h>
14149 +#include <linux/vs_network.h>
14150 +#include <linux/vs_pid.h>
14151  #include <trace/events/sched.h>
14152  #include <linux/hw_breakpoint.h>
14153  #include <linux/oom.h>
14154 @@ -616,15 +620,25 @@ static struct task_struct *find_new_reap
14155         __acquires(&tasklist_lock)
14156  {
14157         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14158 -       struct task_struct *thread;
14159 +       struct vx_info *vxi = task_get_vx_info(father);
14160 +       struct task_struct *thread = father;
14161 +       struct task_struct *reaper;
14162  
14163 -       thread = father;
14164         while_each_thread(father, thread) {
14165                 if (thread->flags & PF_EXITING)
14166                         continue;
14167                 if (unlikely(pid_ns->child_reaper == father))
14168                         pid_ns->child_reaper = thread;
14169 -               return thread;
14170 +               reaper = thread;
14171 +               goto out_put;
14172 +       }
14173 +
14174 +       reaper = pid_ns->child_reaper;
14175 +       if (vxi) {
14176 +               BUG_ON(!vxi->vx_reaper);
14177 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14178 +                   vxi->vx_reaper != father)
14179 +                       reaper = vxi->vx_reaper;
14180         }
14181  
14182         if (unlikely(pid_ns->child_reaper == father)) {
14183 @@ -662,7 +676,9 @@ static struct task_struct *find_new_reap
14184                 }
14185         }
14186  
14187 -       return pid_ns->child_reaper;
14188 +out_put:
14189 +       put_vx_info(vxi);
14190 +       return reaper;
14191  }
14192  
14193  /*
14194 @@ -713,10 +729,15 @@ static void forget_original_parent(struc
14195         list_for_each_entry_safe(p, n, &father->children, sibling) {
14196                 struct task_struct *t = p;
14197                 do {
14198 -                       t->real_parent = reaper;
14199 +                       struct task_struct *new_parent = reaper;
14200 +
14201 +                       if (unlikely(p == reaper))
14202 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14203 +
14204 +                       t->real_parent = new_parent;
14205                         if (t->parent == father) {
14206                                 BUG_ON(t->ptrace);
14207 -                               t->parent = t->real_parent;
14208 +                               t->parent = new_parent;
14209                         }
14210                         if (t->pdeath_signal)
14211                                 group_send_sig_info(t->pdeath_signal,
14212 @@ -923,6 +944,9 @@ void do_exit(long code)
14213          */
14214         ptrace_put_breakpoints(tsk);
14215  
14216 +       /* needs to stay before exit_notify() */
14217 +       exit_vx_info_early(tsk, code);
14218 +
14219         exit_notify(tsk, group_dead);
14220  #ifdef CONFIG_NUMA
14221         task_lock(tsk);
14222 @@ -976,10 +1000,15 @@ void do_exit(long code)
14223         smp_mb();
14224         raw_spin_unlock_wait(&tsk->pi_lock);
14225  
14226 +       /* needs to stay after exit_notify() */
14227 +       exit_vx_info(tsk, code);
14228 +       exit_nx_info(tsk);
14229 +
14230         /* causes final put_task_struct in finish_task_switch(). */
14231         tsk->state = TASK_DEAD;
14232         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14233         schedule();
14234 +       printk("bad task: %p [%lx]\n", current, current->state);
14235         BUG();
14236         /* Avoid "noreturn function does return".  */
14237         for (;;)
14238 diff -NurpP --minimal linux-3.7/kernel/fork.c linux-3.7-vs2.3.5.1/kernel/fork.c
14239 --- linux-3.7/kernel/fork.c     2012-12-11 15:47:48.000000000 +0000
14240 +++ linux-3.7-vs2.3.5.1/kernel/fork.c   2012-12-11 15:56:32.000000000 +0000
14241 @@ -70,6 +70,9 @@
14242  #include <linux/khugepaged.h>
14243  #include <linux/signalfd.h>
14244  #include <linux/uprobes.h>
14245 +#include <linux/vs_context.h>
14246 +#include <linux/vs_network.h>
14247 +#include <linux/vs_limit.h>
14248  
14249  #include <asm/pgtable.h>
14250  #include <asm/pgalloc.h>
14251 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14252         arch_release_thread_info(tsk->stack);
14253         free_thread_info(tsk->stack);
14254         rt_mutex_debug_task_free(tsk);
14255 +       clr_vx_info(&tsk->vx_info);
14256 +       clr_nx_info(&tsk->nx_info);
14257         ftrace_graph_exit_task(tsk);
14258         put_seccomp_filter(tsk);
14259         arch_release_task_struct(tsk);
14260 @@ -545,6 +550,7 @@ static struct mm_struct *mm_init(struct
14261         if (likely(!mm_alloc_pgd(mm))) {
14262                 mm->def_flags = 0;
14263                 mmu_notifier_mm_init(mm);
14264 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14265                 return mm;
14266         }
14267  
14268 @@ -597,6 +603,7 @@ void __mmdrop(struct mm_struct *mm)
14269         destroy_context(mm);
14270         mmu_notifier_mm_destroy(mm);
14271         check_mm(mm);
14272 +       clr_vx_info(&mm->mm_vx_info);
14273         free_mm(mm);
14274  }
14275  EXPORT_SYMBOL_GPL(__mmdrop);
14276 @@ -816,6 +823,7 @@ struct mm_struct *dup_mm(struct task_str
14277                 goto fail_nomem;
14278  
14279         memcpy(mm, oldmm, sizeof(*mm));
14280 +       mm->mm_vx_info = NULL;
14281         mm_init_cpumask(mm);
14282  
14283  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14284 @@ -854,6 +862,7 @@ fail_nocontext:
14285          * If init_new_context() failed, we cannot use mmput() to free the mm
14286          * because it calls destroy_context()
14287          */
14288 +       clr_vx_info(&mm->mm_vx_info);
14289         mm_free_pgd(mm);
14290         free_mm(mm);
14291         return NULL;
14292 @@ -1136,6 +1145,8 @@ static struct task_struct *copy_process(
14293         int retval;
14294         struct task_struct *p;
14295         int cgroup_callbacks_done = 0;
14296 +       struct vx_info *vxi;
14297 +       struct nx_info *nxi;
14298  
14299         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14300                 return ERR_PTR(-EINVAL);
14301 @@ -1183,7 +1194,12 @@ static struct task_struct *copy_process(
14302         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14303         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14304  #endif
14305 +       init_vx_info(&p->vx_info, current_vx_info());
14306 +       init_nx_info(&p->nx_info, current_nx_info());
14307 +
14308         retval = -EAGAIN;
14309 +       if (!vx_nproc_avail(1))
14310 +               goto bad_fork_free;
14311         if (atomic_read(&p->real_cred->user->processes) >=
14312                         task_rlimit(p, RLIMIT_NPROC)) {
14313                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14314 @@ -1458,6 +1474,18 @@ static struct task_struct *copy_process(
14315  
14316         total_forks++;
14317         spin_unlock(&current->sighand->siglock);
14318 +
14319 +       /* p is copy of current */
14320 +       vxi = p->vx_info;
14321 +       if (vxi) {
14322 +               claim_vx_info(vxi, p);
14323 +               atomic_inc(&vxi->cvirt.nr_threads);
14324 +               atomic_inc(&vxi->cvirt.total_forks);
14325 +               vx_nproc_inc(p);
14326 +       }
14327 +       nxi = p->nx_info;
14328 +       if (nxi)
14329 +               claim_nx_info(nxi, p);
14330         write_unlock_irq(&tasklist_lock);
14331         proc_fork_connector(p);
14332         cgroup_post_fork(p);
14333 diff -NurpP --minimal linux-3.7/kernel/kthread.c linux-3.7-vs2.3.5.1/kernel/kthread.c
14334 --- linux-3.7/kernel/kthread.c  2012-12-11 15:47:48.000000000 +0000
14335 +++ linux-3.7-vs2.3.5.1/kernel/kthread.c        2012-12-11 17:04:03.000000000 +0000
14336 @@ -17,6 +17,7 @@
14337  #include <linux/slab.h>
14338  #include <linux/freezer.h>
14339  #include <linux/ptrace.h>
14340 +#include <linux/vs_pid.h>
14341  #include <trace/events/sched.h>
14342  
14343  static DEFINE_SPINLOCK(kthread_create_lock);
14344 diff -NurpP --minimal linux-3.7/kernel/nsproxy.c linux-3.7-vs2.3.5.1/kernel/nsproxy.c
14345 --- linux-3.7/kernel/nsproxy.c  2012-01-09 15:15:00.000000000 +0000
14346 +++ linux-3.7-vs2.3.5.1/kernel/nsproxy.c        2012-12-11 15:56:32.000000000 +0000
14347 @@ -20,11 +20,14 @@
14348  #include <linux/mnt_namespace.h>
14349  #include <linux/utsname.h>
14350  #include <linux/pid_namespace.h>
14351 +#include <linux/vserver/global.h>
14352 +#include <linux/vserver/debug.h>
14353  #include <net/net_namespace.h>
14354  #include <linux/ipc_namespace.h>
14355  #include <linux/proc_fs.h>
14356  #include <linux/file.h>
14357  #include <linux/syscalls.h>
14358 +#include "../fs/mount.h"
14359  
14360  static struct kmem_cache *nsproxy_cachep;
14361  
14362 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14363         struct nsproxy *nsproxy;
14364  
14365         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14366 -       if (nsproxy)
14367 +       if (nsproxy) {
14368                 atomic_set(&nsproxy->count, 1);
14369 +               atomic_inc(&vs_global_nsproxy);
14370 +       }
14371 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14372         return nsproxy;
14373  }
14374  
14375 @@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14376   * Return the newly created nsproxy.  Do not attach this to the task,
14377   * leave it to the caller to do proper locking and attach it to task.
14378   */
14379 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14380 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14381 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14382 +                       struct nsproxy *orig,
14383 +                       struct fs_struct *new_fs,
14384 +                       struct user_namespace *new_user,
14385 +                       struct pid_namespace *new_pid)
14386  {
14387         struct nsproxy *new_nsp;
14388         int err;
14389 @@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14390         if (!new_nsp)
14391                 return ERR_PTR(-ENOMEM);
14392  
14393 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14394 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14395         if (IS_ERR(new_nsp->mnt_ns)) {
14396                 err = PTR_ERR(new_nsp->mnt_ns);
14397                 goto out_ns;
14398         }
14399  
14400 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14401 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14402         if (IS_ERR(new_nsp->uts_ns)) {
14403                 err = PTR_ERR(new_nsp->uts_ns);
14404                 goto out_uts;
14405         }
14406  
14407 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14408 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14409         if (IS_ERR(new_nsp->ipc_ns)) {
14410                 err = PTR_ERR(new_nsp->ipc_ns);
14411                 goto out_ipc;
14412         }
14413  
14414 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14415 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14416         if (IS_ERR(new_nsp->pid_ns)) {
14417                 err = PTR_ERR(new_nsp->pid_ns);
14418                 goto out_pid;
14419         }
14420  
14421 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14422 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14423         if (IS_ERR(new_nsp->net_ns)) {
14424                 err = PTR_ERR(new_nsp->net_ns);
14425                 goto out_net;
14426 @@ -115,6 +124,40 @@ out_ns:
14427         return ERR_PTR(err);
14428  }
14429  
14430 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14431 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14432 +{
14433 +       return unshare_namespaces(flags, tsk->nsproxy,
14434 +               new_fs, task_cred_xxx(tsk, user_ns),
14435 +               task_active_pid_ns(tsk));
14436 +}
14437 +
14438 +/*
14439 + * copies the nsproxy, setting refcount to 1, and grabbing a
14440 + * reference to all contained namespaces.
14441 + */
14442 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14443 +{
14444 +       struct nsproxy *ns = create_nsproxy();
14445 +
14446 +       if (ns) {
14447 +               memcpy(ns, orig, sizeof(struct nsproxy));
14448 +               atomic_set(&ns->count, 1);
14449 +
14450 +               if (ns->mnt_ns)
14451 +                       get_mnt_ns(ns->mnt_ns);
14452 +               if (ns->uts_ns)
14453 +                       get_uts_ns(ns->uts_ns);
14454 +               if (ns->ipc_ns)
14455 +                       get_ipc_ns(ns->ipc_ns);
14456 +               if (ns->pid_ns)
14457 +                       get_pid_ns(ns->pid_ns);
14458 +               if (ns->net_ns)
14459 +                       get_net(ns->net_ns);
14460 +       }
14461 +       return ns;
14462 +}
14463 +
14464  /*
14465   * called from clone.  This now handles copy for nsproxy and all
14466   * namespaces therein.
14467 @@ -122,9 +165,12 @@ out_ns:
14468  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14469  {
14470         struct nsproxy *old_ns = tsk->nsproxy;
14471 -       struct nsproxy *new_ns;
14472 +       struct nsproxy *new_ns = NULL;
14473         int err = 0;
14474  
14475 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14476 +               flags, tsk, old_ns);
14477 +
14478         if (!old_ns)
14479                 return 0;
14480  
14481 @@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14482                                 CLONE_NEWPID | CLONE_NEWNET)))
14483                 return 0;
14484  
14485 -       if (!capable(CAP_SYS_ADMIN)) {
14486 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14487                 err = -EPERM;
14488                 goto out;
14489         }
14490 @@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14491  
14492  out:
14493         put_nsproxy(old_ns);
14494 +       vxdprintk(VXD_CBIT(space, 3),
14495 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14496 +               flags, tsk, old_ns, err, new_ns);
14497         return err;
14498  }
14499  
14500 @@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14501                 put_ipc_ns(ns->ipc_ns);
14502         if (ns->pid_ns)
14503                 put_pid_ns(ns->pid_ns);
14504 -       put_net(ns->net_ns);
14505 +       if (ns->net_ns)
14506 +               put_net(ns->net_ns);
14507 +       atomic_dec(&vs_global_nsproxy);
14508         kmem_cache_free(nsproxy_cachep, ns);
14509  }
14510  
14511 @@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned
14512  {
14513         int err = 0;
14514  
14515 +       vxdprintk(VXD_CBIT(space, 4),
14516 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14517 +               unshare_flags, current->nsproxy);
14518 +
14519         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14520                                CLONE_NEWNET)))
14521                 return 0;
14522  
14523 -       if (!capable(CAP_SYS_ADMIN))
14524 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14525                 return -EPERM;
14526  
14527         *new_nsp = create_new_namespaces(unshare_flags, current,
14528 diff -NurpP --minimal linux-3.7/kernel/pid.c linux-3.7-vs2.3.5.1/kernel/pid.c
14529 --- linux-3.7/kernel/pid.c      2012-12-11 15:47:48.000000000 +0000
14530 +++ linux-3.7-vs2.3.5.1/kernel/pid.c    2012-12-11 15:56:32.000000000 +0000
14531 @@ -36,6 +36,7 @@
14532  #include <linux/pid_namespace.h>
14533  #include <linux/init_task.h>
14534  #include <linux/syscalls.h>
14535 +#include <linux/vs_pid.h>
14536  
14537  #define pid_hashfn(nr, ns)     \
14538         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14539 @@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14540  
14541  struct pid *find_vpid(int nr)
14542  {
14543 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14544 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14545  }
14546  EXPORT_SYMBOL_GPL(find_vpid);
14547  
14548 @@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14549  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14550  {
14551         struct task_struct *result = NULL;
14552 +
14553 +       if (type == PIDTYPE_REALPID)
14554 +               type = PIDTYPE_PID;
14555         if (pid) {
14556                 struct hlist_node *first;
14557                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14558 @@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14559         rcu_lockdep_assert(rcu_read_lock_held(),
14560                            "find_task_by_pid_ns() needs rcu_read_lock()"
14561                            " protection");
14562 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14563 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14564  }
14565  
14566  struct task_struct *find_task_by_vpid(pid_t vnr)
14567 @@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14568  }
14569  EXPORT_SYMBOL_GPL(find_get_pid);
14570  
14571 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14572 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14573  {
14574         struct upid *upid;
14575         pid_t nr = 0;
14576 @@ -481,6 +485,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14577  }
14578  EXPORT_SYMBOL_GPL(pid_nr_ns);
14579  
14580 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14581 +{
14582 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14583 +}
14584 +
14585  pid_t pid_vnr(struct pid *pid)
14586  {
14587         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14588 diff -NurpP --minimal linux-3.7/kernel/pid_namespace.c linux-3.7-vs2.3.5.1/kernel/pid_namespace.c
14589 --- linux-3.7/kernel/pid_namespace.c    2012-12-11 15:47:48.000000000 +0000
14590 +++ linux-3.7-vs2.3.5.1/kernel/pid_namespace.c  2012-12-11 17:04:24.000000000 +0000
14591 @@ -17,6 +17,7 @@
14592  #include <linux/proc_fs.h>
14593  #include <linux/reboot.h>
14594  #include <linux/export.h>
14595 +#include <linux/vserver/global.h>
14596  
14597  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14598  
14599 @@ -100,6 +101,7 @@ static struct pid_namespace *create_pid_
14600                 goto out_free_map;
14601  
14602         kref_init(&ns->kref);
14603 +       atomic_inc(&vs_global_pid_ns);
14604         ns->level = level;
14605         ns->parent = get_pid_ns(parent_pid_ns);
14606  
14607 @@ -131,6 +133,7 @@ static void destroy_pid_namespace(struct
14608  
14609         for (i = 0; i < PIDMAP_ENTRIES; i++)
14610                 kfree(ns->pidmap[i].page);
14611 +       atomic_dec(&vs_global_pid_ns);
14612         kmem_cache_free(pid_ns_cachep, ns);
14613  }
14614  
14615 diff -NurpP --minimal linux-3.7/kernel/posix-timers.c linux-3.7-vs2.3.5.1/kernel/posix-timers.c
14616 --- linux-3.7/kernel/posix-timers.c     2012-01-09 15:15:00.000000000 +0000
14617 +++ linux-3.7-vs2.3.5.1/kernel/posix-timers.c   2012-12-11 15:56:32.000000000 +0000
14618 @@ -47,6 +47,7 @@
14619  #include <linux/wait.h>
14620  #include <linux/workqueue.h>
14621  #include <linux/export.h>
14622 +#include <linux/vs_context.h>
14623  
14624  /*
14625   * Management arrays for POSIX timers.  Timers are kept in slab memory
14626 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14627  {
14628         struct task_struct *task;
14629         int shared, ret = -1;
14630 +
14631         /*
14632          * FIXME: if ->sigq is queued we can race with
14633          * dequeue_signal()->do_schedule_next_timer().
14634 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14635         rcu_read_lock();
14636         task = pid_task(timr->it_pid, PIDTYPE_PID);
14637         if (task) {
14638 +               struct vx_info_save vxis;
14639 +               struct vx_info *vxi;
14640 +
14641 +               vxi = get_vx_info(task->vx_info);
14642 +               enter_vx_info(vxi, &vxis);
14643                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14644                 ret = send_sigqueue(timr->sigq, task, shared);
14645 +               leave_vx_info(&vxis);
14646 +               put_vx_info(vxi);
14647         }
14648         rcu_read_unlock();
14649 +
14650         /* If we failed to send the signal the timer stops. */
14651         return ret > 0;
14652  }
14653 diff -NurpP --minimal linux-3.7/kernel/printk.c linux-3.7-vs2.3.5.1/kernel/printk.c
14654 --- linux-3.7/kernel/printk.c   2012-12-11 15:47:48.000000000 +0000
14655 +++ linux-3.7-vs2.3.5.1/kernel/printk.c 2012-12-11 15:56:32.000000000 +0000
14656 @@ -42,6 +42,7 @@
14657  #include <linux/notifier.h>
14658  #include <linux/rculist.h>
14659  #include <linux/poll.h>
14660 +#include <linux/vs_cvirt.h>
14661  
14662  #include <asm/uaccess.h>
14663  
14664 @@ -818,7 +819,7 @@ static int check_syslog_permissions(int
14665                 return 0;
14666  
14667         if (syslog_action_restricted(type)) {
14668 -               if (capable(CAP_SYSLOG))
14669 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14670                         return 0;
14671                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14672                 if (capable(CAP_SYS_ADMIN)) {
14673 @@ -1111,12 +1112,9 @@ int do_syslog(int type, char __user *buf
14674         if (error)
14675                 return error;
14676  
14677 -       switch (type) {
14678 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14679 -               break;
14680 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14681 -               break;
14682 -       case SYSLOG_ACTION_READ:        /* Read from log */
14683 +       if ((type == SYSLOG_ACTION_READ) ||
14684 +           (type == SYSLOG_ACTION_READ_ALL) ||
14685 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14686                 error = -EINVAL;
14687                 if (!buf || len < 0)
14688                         goto out;
14689 @@ -1127,6 +1125,16 @@ int do_syslog(int type, char __user *buf
14690                         error = -EFAULT;
14691                         goto out;
14692                 }
14693 +       }
14694 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14695 +               return vx_do_syslog(type, buf, len);
14696 +
14697 +       switch (type) {
14698 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14699 +               break;
14700 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14701 +               break;
14702 +       case SYSLOG_ACTION_READ:        /* Read from log */
14703                 error = wait_event_interruptible(log_wait,
14704                                                  syslog_seq != log_next_seq);
14705                 if (error)
14706 @@ -1139,16 +1147,6 @@ int do_syslog(int type, char __user *buf
14707                 /* FALL THRU */
14708         /* Read last kernel messages */
14709         case SYSLOG_ACTION_READ_ALL:
14710 -               error = -EINVAL;
14711 -               if (!buf || len < 0)
14712 -                       goto out;
14713 -               error = 0;
14714 -               if (!len)
14715 -                       goto out;
14716 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14717 -                       error = -EFAULT;
14718 -                       goto out;
14719 -               }
14720                 error = syslog_print_all(buf, len, clear);
14721                 break;
14722         /* Clear ring buffer */
14723 diff -NurpP --minimal linux-3.7/kernel/ptrace.c linux-3.7-vs2.3.5.1/kernel/ptrace.c
14724 --- linux-3.7/kernel/ptrace.c   2012-12-11 15:47:48.000000000 +0000
14725 +++ linux-3.7-vs2.3.5.1/kernel/ptrace.c 2012-12-11 15:56:32.000000000 +0000
14726 @@ -22,6 +22,7 @@
14727  #include <linux/syscalls.h>
14728  #include <linux/uaccess.h>
14729  #include <linux/regset.h>
14730 +#include <linux/vs_context.h>
14731  #include <linux/hw_breakpoint.h>
14732  #include <linux/cn_proc.h>
14733  
14734 @@ -217,6 +218,11 @@ ok:
14735                 dumpable = get_dumpable(task->mm);
14736         if (!dumpable  && !ptrace_has_cap(task_user_ns(task), mode))
14737                 return -EPERM;
14738 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14739 +               return -EPERM;
14740 +       if (!vx_check(task->xid, VS_IDENT) &&
14741 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14742 +               return -EACCES;
14743  
14744         return security_ptrace_access_check(task, mode);
14745  }
14746 diff -NurpP --minimal linux-3.7/kernel/sched/core.c linux-3.7-vs2.3.5.1/kernel/sched/core.c
14747 --- linux-3.7/kernel/sched/core.c       2012-12-11 15:47:48.000000000 +0000
14748 +++ linux-3.7-vs2.3.5.1/kernel/sched/core.c     2012-12-11 15:56:32.000000000 +0000
14749 @@ -72,6 +72,8 @@
14750  #include <linux/slab.h>
14751  #include <linux/init_task.h>
14752  #include <linux/binfmts.h>
14753 +#include <linux/vs_sched.h>
14754 +#include <linux/vs_cvirt.h>
14755  
14756  #include <asm/switch_to.h>
14757  #include <asm/tlb.h>
14758 @@ -2030,9 +2032,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14759   */
14760  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14761  {
14762 -       loads[0] = (avenrun[0] + offset) << shift;
14763 -       loads[1] = (avenrun[1] + offset) << shift;
14764 -       loads[2] = (avenrun[2] + offset) << shift;
14765 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14766 +               struct vx_info *vxi = current_vx_info();
14767 +
14768 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14769 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14770 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14771 +       } else {
14772 +               loads[0] = (avenrun[0] + offset) << shift;
14773 +               loads[1] = (avenrun[1] + offset) << shift;
14774 +               loads[2] = (avenrun[2] + offset) << shift;
14775 +       }
14776  }
14777  
14778  static long calc_load_fold_active(struct rq *this_rq)
14779 @@ -3596,7 +3606,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14780                 nice = 19;
14781  
14782         if (increment < 0 && !can_nice(current, nice))
14783 -               return -EPERM;
14784 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14785  
14786         retval = security_task_setnice(current, nice);
14787         if (retval)
14788 diff -NurpP --minimal linux-3.7/kernel/sched/cputime.c linux-3.7-vs2.3.5.1/kernel/sched/cputime.c
14789 --- linux-3.7/kernel/sched/cputime.c    2012-12-11 15:47:48.000000000 +0000
14790 +++ linux-3.7-vs2.3.5.1/kernel/sched/cputime.c  2012-12-11 21:13:27.000000000 +0000
14791 @@ -3,6 +3,7 @@
14792  #include <linux/tsacct_kern.h>
14793  #include <linux/kernel_stat.h>
14794  #include <linux/static_key.h>
14795 +#include <linux/vs_sched.h>
14796  #include "sched.h"
14797  
14798  
14799 @@ -150,14 +151,17 @@ static inline void task_group_account_fi
14800  void account_user_time(struct task_struct *p, cputime_t cputime,
14801                        cputime_t cputime_scaled)
14802  {
14803 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14804 +       int nice = (TASK_NICE(p) > 0);
14805         int index;
14806  
14807         /* Add user time to process. */
14808         p->utime += cputime;
14809         p->utimescaled += cputime_scaled;
14810 +       vx_account_user(vxi, cputime, nice);
14811         account_group_user_time(p, cputime);
14812  
14813 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14814 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14815  
14816         /* Add user time to cpustat. */
14817         task_group_account_field(p, index, (__force u64) cputime);
14818 @@ -204,9 +208,12 @@ static inline
14819  void __account_system_time(struct task_struct *p, cputime_t cputime,
14820                         cputime_t cputime_scaled, int index)
14821  {
14822 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14823 +
14824         /* Add system time to process. */
14825         p->stime += cputime;
14826         p->stimescaled += cputime_scaled;
14827 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14828         account_group_system_time(p, cputime);
14829  
14830         /* Add system time to cpustat. */
14831 diff -NurpP --minimal linux-3.7/kernel/sched/fair.c linux-3.7-vs2.3.5.1/kernel/sched/fair.c
14832 --- linux-3.7/kernel/sched/fair.c       2012-12-11 15:47:48.000000000 +0000
14833 +++ linux-3.7-vs2.3.5.1/kernel/sched/fair.c     2012-12-11 15:56:33.000000000 +0000
14834 @@ -26,6 +26,7 @@
14835  #include <linux/slab.h>
14836  #include <linux/profile.h>
14837  #include <linux/interrupt.h>
14838 +#include <linux/vs_cvirt.h>
14839  
14840  #include <trace/events/sched.h>
14841  
14842 @@ -1111,6 +1112,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14843                 __enqueue_entity(cfs_rq, se);
14844         se->on_rq = 1;
14845  
14846 +       if (entity_is_task(se))
14847 +               vx_activate_task(task_of(se));
14848         if (cfs_rq->nr_running == 1) {
14849                 list_add_leaf_cfs_rq(cfs_rq);
14850                 check_enqueue_throttle(cfs_rq);
14851 @@ -1191,6 +1194,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14852         if (se != cfs_rq->curr)
14853                 __dequeue_entity(cfs_rq, se);
14854         se->on_rq = 0;
14855 +       if (entity_is_task(se))
14856 +               vx_deactivate_task(task_of(se));
14857         update_cfs_load(cfs_rq, 0);
14858         account_entity_dequeue(cfs_rq, se);
14859  
14860 diff -NurpP --minimal linux-3.7/kernel/signal.c linux-3.7-vs2.3.5.1/kernel/signal.c
14861 --- linux-3.7/kernel/signal.c   2012-12-11 15:47:48.000000000 +0000
14862 +++ linux-3.7-vs2.3.5.1/kernel/signal.c 2012-12-11 15:56:33.000000000 +0000
14863 @@ -31,6 +31,8 @@
14864  #include <linux/nsproxy.h>
14865  #include <linux/user_namespace.h>
14866  #include <linux/uprobes.h>
14867 +#include <linux/vs_context.h>
14868 +#include <linux/vs_pid.h>
14869  #define CREATE_TRACE_POINTS
14870  #include <trace/events/signal.h>
14871  
14872 @@ -791,9 +793,18 @@ static int check_kill_permission(int sig
14873         struct pid *sid;
14874         int error;
14875  
14876 +       vxdprintk(VXD_CBIT(misc, 7),
14877 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14878 +               sig, info, t, vx_task_xid(t), t->pid);
14879 +
14880         if (!valid_signal(sig))
14881                 return -EINVAL;
14882  
14883 +/*     FIXME: needed? if so, why?
14884 +       if ((info != SEND_SIG_NOINFO) &&
14885 +               (is_si_special(info) || !si_fromuser(info)))
14886 +               goto skip;      */
14887 +
14888         if (!si_fromuser(info))
14889                 return 0;
14890  
14891 @@ -817,6 +828,20 @@ static int check_kill_permission(int sig
14892                 }
14893         }
14894  
14895 +       error = -EPERM;
14896 +       if (t->pid == 1 && current->xid)
14897 +               return error;
14898 +
14899 +       error = -ESRCH;
14900 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14901 +                 loops, maybe ENOENT or EACCES? */
14902 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14903 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14904 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14905 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14906 +               return error;
14907 +       }
14908 +/* skip: */
14909         return security_task_kill(t, info, sig, 0);
14910  }
14911  
14912 @@ -1352,7 +1377,7 @@ int kill_pid_info(int sig, struct siginf
14913         rcu_read_lock();
14914  retry:
14915         p = pid_task(pid, PIDTYPE_PID);
14916 -       if (p) {
14917 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14918                 error = group_send_sig_info(sig, info, p);
14919                 if (unlikely(error == -ESRCH))
14920                         /*
14921 @@ -1400,7 +1425,7 @@ int kill_pid_info_as_cred(int sig, struc
14922  
14923         rcu_read_lock();
14924         p = pid_task(pid, PIDTYPE_PID);
14925 -       if (!p) {
14926 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14927                 ret = -ESRCH;
14928                 goto out_unlock;
14929         }
14930 @@ -1452,8 +1477,10 @@ static int kill_something_info(int sig,
14931                 struct task_struct * p;
14932  
14933                 for_each_process(p) {
14934 -                       if (task_pid_vnr(p) > 1 &&
14935 -                                       !same_thread_group(p, current)) {
14936 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14937 +                               task_pid_vnr(p) > 1 &&
14938 +                               !same_thread_group(p, current) &&
14939 +                               !vx_current_initpid(p->pid)) {
14940                                 int err = group_send_sig_info(sig, info, p);
14941                                 ++count;
14942                                 if (err != -EPERM)
14943 @@ -2308,6 +2335,11 @@ relock:
14944                                 !sig_kernel_only(signr))
14945                         continue;
14946  
14947 +               /* virtual init is protected against user signals */
14948 +               if ((info->si_code == SI_USER) &&
14949 +                       vx_current_initpid(current->pid))
14950 +                       continue;
14951 +
14952                 if (sig_kernel_stop(signr)) {
14953                         /*
14954                          * The default action is to stop all threads in
14955 diff -NurpP --minimal linux-3.7/kernel/softirq.c linux-3.7-vs2.3.5.1/kernel/softirq.c
14956 --- linux-3.7/kernel/softirq.c  2012-12-11 15:47:48.000000000 +0000
14957 +++ linux-3.7-vs2.3.5.1/kernel/softirq.c        2012-12-11 15:56:33.000000000 +0000
14958 @@ -25,6 +25,7 @@
14959  #include <linux/smp.h>
14960  #include <linux/smpboot.h>
14961  #include <linux/tick.h>
14962 +#include <linux/vs_context.h>
14963  
14964  #define CREATE_TRACE_POINTS
14965  #include <trace/events/irq.h>
14966 diff -NurpP --minimal linux-3.7/kernel/sys.c linux-3.7-vs2.3.5.1/kernel/sys.c
14967 --- linux-3.7/kernel/sys.c      2012-12-11 15:47:48.000000000 +0000
14968 +++ linux-3.7-vs2.3.5.1/kernel/sys.c    2012-12-11 15:56:33.000000000 +0000
14969 @@ -47,6 +47,7 @@
14970  #include <linux/syscalls.h>
14971  #include <linux/kprobes.h>
14972  #include <linux/user_namespace.h>
14973 +#include <linux/vs_pid.h>
14974  
14975  #include <linux/kmsg_dump.h>
14976  /* Move somewhere else to avoid recompiling? */
14977 @@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
14978                 goto out;
14979         }
14980         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14981 -               error = -EACCES;
14982 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14983 +                       error = 0;
14984 +               else
14985 +                       error = -EACCES;
14986                 goto out;
14987         }
14988         no_nice = security_task_setnice(p, niceval);
14989 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14990                         else
14991                                 pgrp = task_pgrp(current);
14992                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14993 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14994 +                                       continue;
14995                                 error = set_one_prio(p, niceval, error);
14996                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14997                         break;
14998 @@ -270,6 +276,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14999                         else
15000                                 pgrp = task_pgrp(current);
15001                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15002 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15003 +                                       continue;
15004                                 niceval = 20 - task_nice(p);
15005                                 if (niceval > retval)
15006                                         retval = niceval;
15007 @@ -422,6 +430,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15008  
15009  static DEFINE_MUTEX(reboot_mutex);
15010  
15011 +long vs_reboot(unsigned int, void __user *);
15012 +
15013  /*
15014   * Reboot system call: for obvious reasons only root may call it,
15015   * and even root needs to set up some magic numbers in the registers
15016 @@ -463,6 +473,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15017         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15018                 cmd = LINUX_REBOOT_CMD_HALT;
15019  
15020 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15021 +               return vs_reboot(cmd, arg);
15022 +
15023         mutex_lock(&reboot_mutex);
15024         switch (cmd) {
15025         case LINUX_REBOOT_CMD_RESTART:
15026 @@ -1370,7 +1383,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15027         int errno;
15028         char tmp[__NEW_UTS_LEN];
15029  
15030 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15031 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15032 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15033                 return -EPERM;
15034  
15035         if (len < 0 || len > __NEW_UTS_LEN)
15036 @@ -1421,7 +1435,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15037         int errno;
15038         char tmp[__NEW_UTS_LEN];
15039  
15040 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15041 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15042 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15043                 return -EPERM;
15044         if (len < 0 || len > __NEW_UTS_LEN)
15045                 return -EINVAL;
15046 @@ -1540,7 +1555,7 @@ int do_prlimit(struct task_struct *tsk,
15047                 /* Keep the capable check against init_user_ns until
15048                    cgroups can contain all limits */
15049                 if (new_rlim->rlim_max > rlim->rlim_max &&
15050 -                               !capable(CAP_SYS_RESOURCE))
15051 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15052                         retval = -EPERM;
15053                 if (!retval)
15054                         retval = security_task_setrlimit(tsk->group_leader,
15055 @@ -1593,7 +1608,8 @@ static int check_prlimit_permission(stru
15056             gid_eq(cred->gid, tcred->sgid) &&
15057             gid_eq(cred->gid, tcred->gid))
15058                 return 0;
15059 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15060 +       if (vx_ns_capable(tcred->user_ns,
15061 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15062                 return 0;
15063  
15064         return -EPERM;
15065 diff -NurpP --minimal linux-3.7/kernel/sysctl.c linux-3.7-vs2.3.5.1/kernel/sysctl.c
15066 --- linux-3.7/kernel/sysctl.c   2012-12-11 15:47:48.000000000 +0000
15067 +++ linux-3.7-vs2.3.5.1/kernel/sysctl.c 2012-12-11 15:56:33.000000000 +0000
15068 @@ -82,6 +82,7 @@
15069  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15070  #include <linux/lockdep.h>
15071  #endif
15072 +extern char vshelper_path[];
15073  #ifdef CONFIG_CHR_DEV_SG
15074  #include <scsi/sg.h>
15075  #endif
15076 @@ -574,6 +575,13 @@ static struct ctl_table kern_table[] = {
15077                 .proc_handler   = proc_dostring,
15078         },
15079  #endif
15080 +       {
15081 +               .procname       = "vshelper",
15082 +               .data           = &vshelper_path,
15083 +               .maxlen         = 256,
15084 +               .mode           = 0644,
15085 +               .proc_handler   = &proc_dostring,
15086 +       },
15087  #ifdef CONFIG_CHR_DEV_SG
15088         {
15089                 .procname       = "sg-big-buff",
15090 diff -NurpP --minimal linux-3.7/kernel/sysctl_binary.c linux-3.7-vs2.3.5.1/kernel/sysctl_binary.c
15091 --- linux-3.7/kernel/sysctl_binary.c    2012-10-04 13:27:48.000000000 +0000
15092 +++ linux-3.7-vs2.3.5.1/kernel/sysctl_binary.c  2012-12-11 15:56:33.000000000 +0000
15093 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15094  
15095         { CTL_INT,      KERN_PANIC,                     "panic" },
15096         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15097 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15098  
15099         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15100         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15101 diff -NurpP --minimal linux-3.7/kernel/time/timekeeping.c linux-3.7-vs2.3.5.1/kernel/time/timekeeping.c
15102 --- linux-3.7/kernel/time/timekeeping.c 2012-12-11 15:47:49.000000000 +0000
15103 +++ linux-3.7-vs2.3.5.1/kernel/time/timekeeping.c       2012-12-11 21:13:56.000000000 +0000
15104 @@ -21,6 +21,7 @@
15105  #include <linux/time.h>
15106  #include <linux/tick.h>
15107  #include <linux/stop_machine.h>
15108 +#include <linux/vs_time.h>
15109  
15110  
15111  static struct timekeeper timekeeper;
15112 @@ -243,6 +244,7 @@ void getnstimeofday(struct timespec *ts)
15113  
15114         ts->tv_nsec = 0;
15115         timespec_add_ns(ts, nsecs);
15116 +       vx_adjust_timespec(ts);
15117  }
15118  EXPORT_SYMBOL(getnstimeofday);
15119  
15120 diff -NurpP --minimal linux-3.7/kernel/time.c linux-3.7-vs2.3.5.1/kernel/time.c
15121 --- linux-3.7/kernel/time.c     2012-12-11 15:47:49.000000000 +0000
15122 +++ linux-3.7-vs2.3.5.1/kernel/time.c   2012-12-11 21:12:29.000000000 +0000
15123 @@ -37,6 +37,7 @@
15124  #include <linux/fs.h>
15125  #include <linux/math64.h>
15126  #include <linux/ptrace.h>
15127 +#include <linux/vs_time.h>
15128  
15129  #include <asm/uaccess.h>
15130  #include <asm/unistd.h>
15131 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15132         if (err)
15133                 return err;
15134  
15135 -       do_settimeofday(&tv);
15136 +       vx_settimeofday(&tv);
15137         return 0;
15138  }
15139  
15140 @@ -172,7 +173,7 @@ int do_sys_settimeofday(const struct tim
15141                 }
15142         }
15143         if (tv)
15144 -               return do_settimeofday(tv);
15145 +               return vx_settimeofday(tv);
15146         return 0;
15147  }
15148  
15149 diff -NurpP --minimal linux-3.7/kernel/timer.c linux-3.7-vs2.3.5.1/kernel/timer.c
15150 --- linux-3.7/kernel/timer.c    2012-12-11 15:47:49.000000000 +0000
15151 +++ linux-3.7-vs2.3.5.1/kernel/timer.c  2012-12-11 15:56:33.000000000 +0000
15152 @@ -40,6 +40,10 @@
15153  #include <linux/irq_work.h>
15154  #include <linux/sched.h>
15155  #include <linux/slab.h>
15156 +#include <linux/vs_base.h>
15157 +#include <linux/vs_cvirt.h>
15158 +#include <linux/vs_pid.h>
15159 +#include <linux/vserver/sched.h>
15160  
15161  #include <asm/uaccess.h>
15162  #include <asm/unistd.h>
15163 diff -NurpP --minimal linux-3.7/kernel/user_namespace.c linux-3.7-vs2.3.5.1/kernel/user_namespace.c
15164 --- linux-3.7/kernel/user_namespace.c   2012-12-11 15:47:49.000000000 +0000
15165 +++ linux-3.7-vs2.3.5.1/kernel/user_namespace.c 2012-12-11 16:58:02.000000000 +0000
15166 @@ -20,6 +20,7 @@
15167  #include <linux/uaccess.h>
15168  #include <linux/ctype.h>
15169  #include <linux/projid.h>
15170 +#include <linux/vserver/global.h>
15171  
15172  static struct kmem_cache *user_ns_cachep __read_mostly;
15173  
15174 @@ -53,6 +54,7 @@ int create_user_ns(struct cred *new)
15175                 return -ENOMEM;
15176  
15177         kref_init(&ns->kref);
15178 +       atomic_inc(&vs_global_user_ns);
15179         ns->parent = parent_ns;
15180         ns->owner = owner;
15181         ns->group = group;
15182 @@ -85,6 +87,9 @@ void free_user_ns(struct kref *kref)
15183  
15184         parent = ns->parent;
15185         kmem_cache_free(user_ns_cachep, ns);
15186 +
15187 +       /* FIXME: maybe move into destroyer? */
15188 +       atomic_dec(&vs_global_user_ns);
15189         put_user_ns(parent);
15190  }
15191  EXPORT_SYMBOL(free_user_ns);
15192 diff -NurpP --minimal linux-3.7/kernel/utsname.c linux-3.7-vs2.3.5.1/kernel/utsname.c
15193 --- linux-3.7/kernel/utsname.c  2012-07-22 21:39:47.000000000 +0000
15194 +++ linux-3.7-vs2.3.5.1/kernel/utsname.c        2012-12-11 15:56:33.000000000 +0000
15195 @@ -16,14 +16,17 @@
15196  #include <linux/slab.h>
15197  #include <linux/user_namespace.h>
15198  #include <linux/proc_fs.h>
15199 +#include <linux/vserver/global.h>
15200  
15201  static struct uts_namespace *create_uts_ns(void)
15202  {
15203         struct uts_namespace *uts_ns;
15204  
15205         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15206 -       if (uts_ns)
15207 +       if (uts_ns) {
15208                 kref_init(&uts_ns->kref);
15209 +               atomic_inc(&vs_global_uts_ns);
15210 +       }
15211         return uts_ns;
15212  }
15213  
15214 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15215   * @old_ns: namespace to clone
15216   * Return NULL on error (failure to kmalloc), new ns otherwise
15217   */
15218 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15219 -                                         struct uts_namespace *old_ns)
15220 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15221 +                                         struct user_namespace *old_user)
15222  {
15223         struct uts_namespace *ns;
15224  
15225 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15226  
15227         down_read(&uts_sem);
15228         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15229 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
15230 +       ns->user_ns = get_user_ns(old_user);
15231         up_read(&uts_sem);
15232         return ns;
15233  }
15234 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15235   * versa.
15236   */
15237  struct uts_namespace *copy_utsname(unsigned long flags,
15238 -                                  struct task_struct *tsk)
15239 +                                  struct uts_namespace *old_ns,
15240 +                                  struct user_namespace *user_ns)
15241  {
15242 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15243         struct uts_namespace *new_ns;
15244  
15245         BUG_ON(!old_ns);
15246 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15247         if (!(flags & CLONE_NEWUTS))
15248                 return old_ns;
15249  
15250 -       new_ns = clone_uts_ns(tsk, old_ns);
15251 +       new_ns = clone_uts_ns(old_ns, user_ns);
15252  
15253         put_uts_ns(old_ns);
15254         return new_ns;
15255 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15256  
15257         ns = container_of(kref, struct uts_namespace, kref);
15258         put_user_ns(ns->user_ns);
15259 +       atomic_dec(&vs_global_uts_ns);
15260         kfree(ns);
15261  }
15262  
15263 diff -NurpP --minimal linux-3.7/kernel/vserver/Kconfig linux-3.7-vs2.3.5.1/kernel/vserver/Kconfig
15264 --- linux-3.7/kernel/vserver/Kconfig    1970-01-01 00:00:00.000000000 +0000
15265 +++ linux-3.7-vs2.3.5.1/kernel/vserver/Kconfig  2012-12-11 15:56:33.000000000 +0000
15266 @@ -0,0 +1,233 @@
15267 +#
15268 +# Linux VServer configuration
15269 +#
15270 +
15271 +menu "Linux VServer"
15272 +
15273 +config VSERVER_AUTO_LBACK
15274 +       bool    "Automatically Assign Loopback IP"
15275 +       default y
15276 +       help
15277 +         Automatically assign a guest specific loopback
15278 +         IP and add it to the kernel network stack on
15279 +         startup.
15280 +
15281 +config VSERVER_AUTO_SINGLE
15282 +       bool    "Automatic Single IP Special Casing"
15283 +       depends on EXPERIMENTAL
15284 +       default y
15285 +       help
15286 +         This allows network contexts with a single IP to
15287 +         automatically remap 0.0.0.0 bindings to that IP,
15288 +         avoiding further network checks and improving
15289 +         performance.
15290 +
15291 +         (note: such guests do not allow to change the ip
15292 +          on the fly and do not show loopback addresses)
15293 +
15294 +config VSERVER_COWBL
15295 +       bool    "Enable COW Immutable Link Breaking"
15296 +       default y
15297 +       help
15298 +         This enables the COW (Copy-On-Write) link break code.
15299 +         It allows you to treat unified files like normal files
15300 +         when writing to them (which will implicitely break the
15301 +         link and create a copy of the unified file)
15302 +
15303 +config VSERVER_VTIME
15304 +       bool    "Enable Virtualized Guest Time"
15305 +       depends on EXPERIMENTAL
15306 +       default n
15307 +       help
15308 +         This enables per guest time offsets to allow for
15309 +         adjusting the system clock individually per guest.
15310 +         this adds some overhead to the time functions and
15311 +         therefore should not be enabled without good reason.
15312 +
15313 +config VSERVER_DEVICE
15314 +       bool    "Enable Guest Device Mapping"
15315 +       depends on EXPERIMENTAL
15316 +       default n
15317 +       help
15318 +         This enables generic device remapping.
15319 +
15320 +config VSERVER_PROC_SECURE
15321 +       bool    "Enable Proc Security"
15322 +       depends on PROC_FS
15323 +       default y
15324 +       help
15325 +         This configures ProcFS security to initially hide
15326 +         non-process entries for all contexts except the main and
15327 +         spectator context (i.e. for all guests), which is a secure
15328 +         default.
15329 +
15330 +         (note: on 1.2x the entries were visible by default)
15331 +
15332 +choice
15333 +       prompt  "Persistent Inode Tagging"
15334 +       default TAGGING_ID24
15335 +       help
15336 +         This adds persistent context information to filesystems
15337 +         mounted with the tagxid option. Tagging is a requirement
15338 +         for per-context disk limits and per-context quota.
15339 +
15340 +
15341 +config TAGGING_NONE
15342 +       bool    "Disabled"
15343 +       help
15344 +         do not store per-context information in inodes.
15345 +
15346 +config TAGGING_UID16
15347 +       bool    "UID16/GID32"
15348 +       help
15349 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15350 +
15351 +config TAGGING_GID16
15352 +       bool    "UID32/GID16"
15353 +       help
15354 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15355 +
15356 +config TAGGING_ID24
15357 +       bool    "UID24/GID24"
15358 +       help
15359 +         uses the upper 8bit from UID and GID for XID tagging
15360 +         which leaves 24bit for UID/GID each, which should be
15361 +         more than sufficient for normal use.
15362 +
15363 +config TAGGING_INTERN
15364 +       bool    "UID32/GID32"
15365 +       help
15366 +         this uses otherwise reserved inode fields in the on
15367 +         disk representation, which limits the use to a few
15368 +         filesystems (currently ext2 and ext3)
15369 +
15370 +endchoice
15371 +
15372 +config TAG_NFSD
15373 +       bool    "Tag NFSD User Auth and Files"
15374 +       default n
15375 +       help
15376 +         Enable this if you do want the in-kernel NFS
15377 +         Server to use the tagging specified above.
15378 +         (will require patched clients too)
15379 +
15380 +config VSERVER_PRIVACY
15381 +       bool    "Honor Privacy Aspects of Guests"
15382 +       default n
15383 +       help
15384 +         When enabled, most context checks will disallow
15385 +         access to structures assigned to a specific context,
15386 +         like ptys or loop devices.
15387 +
15388 +config VSERVER_CONTEXTS
15389 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15390 +       range 1 65533
15391 +       default "768"   if 64BIT
15392 +       default "256"
15393 +       help
15394 +         This setting will optimize certain data structures
15395 +         and memory allocations according to the expected
15396 +         maximum.
15397 +
15398 +         note: this is not a strict upper limit.
15399 +
15400 +config VSERVER_WARN
15401 +       bool    "VServer Warnings"
15402 +       default y
15403 +       help
15404 +         This enables various runtime warnings, which will
15405 +         notify about potential manipulation attempts or
15406 +         resource shortage. It is generally considered to
15407 +         be a good idea to have that enabled.
15408 +
15409 +config VSERVER_WARN_DEVPTS
15410 +       bool    "VServer DevPTS Warnings"
15411 +       depends on VSERVER_WARN
15412 +       default y
15413 +       help
15414 +         This enables DevPTS related warnings, issued when a
15415 +         process inside a context tries to lookup or access
15416 +         a dynamic pts from the host or a different context.
15417 +
15418 +config VSERVER_DEBUG
15419 +       bool    "VServer Debugging Code"
15420 +       default n
15421 +       help
15422 +         Set this to yes if you want to be able to activate
15423 +         debugging output at runtime. It adds a very small
15424 +         overhead to all vserver related functions and
15425 +         increases the kernel size by about 20k.
15426 +
15427 +config VSERVER_HISTORY
15428 +       bool    "VServer History Tracing"
15429 +       depends on VSERVER_DEBUG
15430 +       default n
15431 +       help
15432 +         Set this to yes if you want to record the history of
15433 +         linux-vserver activities, so they can be replayed in
15434 +         the event of a kernel panic or oops.
15435 +
15436 +config VSERVER_HISTORY_SIZE
15437 +       int     "Per-CPU History Size (32-65536)"
15438 +       depends on VSERVER_HISTORY
15439 +       range 32 65536
15440 +       default 64
15441 +       help
15442 +         This allows you to specify the number of entries in
15443 +         the per-CPU history buffer.
15444 +
15445 +config VSERVER_EXTRA_MNT_CHECK
15446 +       bool    "Extra Checks for Reachability"
15447 +       default n
15448 +       help
15449 +         Set this to yes if you want to do extra checks for
15450 +         vfsmount reachability in the proc filesystem code.
15451 +         This shouldn't be required on any setup utilizing
15452 +         mnt namespaces.
15453 +
15454 +choice
15455 +       prompt  "Quotes used in debug and warn messages"
15456 +       default QUOTES_ISO8859
15457 +
15458 +config QUOTES_ISO8859
15459 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15460 +       help
15461 +         This uses the extended ASCII characters \xbb
15462 +         and \xab for quoting file and process names.
15463 +
15464 +config QUOTES_UTF8
15465 +       bool    "UTF-8 angle quotes"
15466 +       help
15467 +         This uses the the UTF-8 sequences for angle
15468 +         quotes to quote file and process names.
15469 +
15470 +config QUOTES_ASCII
15471 +       bool    "ASCII single quotes"
15472 +       help
15473 +         This uses the ASCII single quote character
15474 +         (\x27) to quote file and process names.
15475 +
15476 +endchoice
15477 +
15478 +endmenu
15479 +
15480 +
15481 +config VSERVER
15482 +       bool
15483 +       default y
15484 +       select NAMESPACES
15485 +       select UTS_NS
15486 +       select IPC_NS
15487 +#      select USER_NS
15488 +       select SYSVIPC
15489 +
15490 +config VSERVER_SECURITY
15491 +       bool
15492 +       depends on SECURITY
15493 +       default y
15494 +       select SECURITY_CAPABILITIES
15495 +
15496 +config VSERVER_DISABLED
15497 +       bool
15498 +       default n
15499 +
15500 diff -NurpP --minimal linux-3.7/kernel/vserver/Makefile linux-3.7-vs2.3.5.1/kernel/vserver/Makefile
15501 --- linux-3.7/kernel/vserver/Makefile   1970-01-01 00:00:00.000000000 +0000
15502 +++ linux-3.7-vs2.3.5.1/kernel/vserver/Makefile 2012-12-11 15:56:33.000000000 +0000
15503 @@ -0,0 +1,18 @@
15504 +#
15505 +# Makefile for the Linux vserver routines.
15506 +#
15507 +
15508 +
15509 +obj-y          += vserver.o
15510 +
15511 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15512 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15513 +                  dlimit.o tag.o
15514 +
15515 +vserver-$(CONFIG_INET) += inet.o
15516 +vserver-$(CONFIG_PROC_FS) += proc.o
15517 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15518 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15519 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15520 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15521 +
15522 diff -NurpP --minimal linux-3.7/kernel/vserver/cacct.c linux-3.7-vs2.3.5.1/kernel/vserver/cacct.c
15523 --- linux-3.7/kernel/vserver/cacct.c    1970-01-01 00:00:00.000000000 +0000
15524 +++ linux-3.7-vs2.3.5.1/kernel/vserver/cacct.c  2012-12-11 15:56:33.000000000 +0000
15525 @@ -0,0 +1,42 @@
15526 +/*
15527 + *  linux/kernel/vserver/cacct.c
15528 + *
15529 + *  Virtual Server: Context Accounting
15530 + *
15531 + *  Copyright (C) 2006-2007 Herbert Pötzl
15532 + *
15533 + *  V0.01  added accounting stats
15534 + *
15535 + */
15536 +
15537 +#include <linux/types.h>
15538 +#include <linux/vs_context.h>
15539 +#include <linux/vserver/cacct_cmd.h>
15540 +#include <linux/vserver/cacct_int.h>
15541 +
15542 +#include <asm/errno.h>
15543 +#include <asm/uaccess.h>
15544 +
15545 +
15546 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15547 +{
15548 +       struct vcmd_sock_stat_v0 vc_data;
15549 +       int j, field;
15550 +
15551 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15552 +               return -EFAULT;
15553 +
15554 +       field = vc_data.field;
15555 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15556 +               return -EINVAL;
15557 +
15558 +       for (j = 0; j < 3; j++) {
15559 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15560 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15561 +       }
15562 +
15563 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15564 +               return -EFAULT;
15565 +       return 0;
15566 +}
15567 +
15568 diff -NurpP --minimal linux-3.7/kernel/vserver/cacct_init.h linux-3.7-vs2.3.5.1/kernel/vserver/cacct_init.h
15569 --- linux-3.7/kernel/vserver/cacct_init.h       1970-01-01 00:00:00.000000000 +0000
15570 +++ linux-3.7-vs2.3.5.1/kernel/vserver/cacct_init.h     2012-12-11 15:56:33.000000000 +0000
15571 @@ -0,0 +1,25 @@
15572 +
15573 +
15574 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15575 +{
15576 +       int i, j;
15577 +
15578 +
15579 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15580 +               for (j = 0; j < 3; j++) {
15581 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15582 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15583 +               }
15584 +       }
15585 +       for (i = 0; i < 8; i++)
15586 +               atomic_set(&cacct->slab[i], 0);
15587 +       for (i = 0; i < 5; i++)
15588 +               for (j = 0; j < 4; j++)
15589 +                       atomic_set(&cacct->page[i][j], 0);
15590 +}
15591 +
15592 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15593 +{
15594 +       return;
15595 +}
15596 +
15597 diff -NurpP --minimal linux-3.7/kernel/vserver/cacct_proc.h linux-3.7-vs2.3.5.1/kernel/vserver/cacct_proc.h
15598 --- linux-3.7/kernel/vserver/cacct_proc.h       1970-01-01 00:00:00.000000000 +0000
15599 +++ linux-3.7-vs2.3.5.1/kernel/vserver/cacct_proc.h     2012-12-11 15:56:33.000000000 +0000
15600 @@ -0,0 +1,53 @@
15601 +#ifndef _VX_CACCT_PROC_H
15602 +#define _VX_CACCT_PROC_H
15603 +
15604 +#include <linux/vserver/cacct_int.h>
15605 +
15606 +
15607 +#define VX_SOCKA_TOP   \
15608 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15609 +
15610 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15611 +{
15612 +       int i, j, length = 0;
15613 +       static char *type[VXA_SOCK_SIZE] = {
15614 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15615 +       };
15616 +
15617 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15618 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15619 +               length += sprintf(buffer + length, "%s:", type[i]);
15620 +               for (j = 0; j < 3; j++) {
15621 +                       length += sprintf(buffer + length,
15622 +                               "\t%10lu/%-10lu",
15623 +                               vx_sock_count(cacct, i, j),
15624 +                               vx_sock_total(cacct, i, j));
15625 +               }
15626 +               buffer[length++] = '\n';
15627 +       }
15628 +
15629 +       length += sprintf(buffer + length, "\n");
15630 +       length += sprintf(buffer + length,
15631 +               "slab:\t %8u %8u %8u %8u\n",
15632 +               atomic_read(&cacct->slab[1]),
15633 +               atomic_read(&cacct->slab[4]),
15634 +               atomic_read(&cacct->slab[0]),
15635 +               atomic_read(&cacct->slab[2]));
15636 +
15637 +       length += sprintf(buffer + length, "\n");
15638 +       for (i = 0; i < 5; i++) {
15639 +               length += sprintf(buffer + length,
15640 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15641 +                       atomic_read(&cacct->page[i][0]),
15642 +                       atomic_read(&cacct->page[i][1]),
15643 +                       atomic_read(&cacct->page[i][2]),
15644 +                       atomic_read(&cacct->page[i][3]),
15645 +                       atomic_read(&cacct->page[i][4]),
15646 +                       atomic_read(&cacct->page[i][5]),
15647 +                       atomic_read(&cacct->page[i][6]),
15648 +                       atomic_read(&cacct->page[i][7]));
15649 +       }
15650 +       return length;
15651 +}
15652 +
15653 +#endif /* _VX_CACCT_PROC_H */
15654 diff -NurpP --minimal linux-3.7/kernel/vserver/context.c linux-3.7-vs2.3.5.1/kernel/vserver/context.c
15655 --- linux-3.7/kernel/vserver/context.c  1970-01-01 00:00:00.000000000 +0000
15656 +++ linux-3.7-vs2.3.5.1/kernel/vserver/context.c        2012-12-11 15:56:33.000000000 +0000
15657 @@ -0,0 +1,1119 @@
15658 +/*
15659 + *  linux/kernel/vserver/context.c
15660 + *
15661 + *  Virtual Server: Context Support
15662 + *
15663 + *  Copyright (C) 2003-2011  Herbert Pötzl
15664 + *
15665 + *  V0.01  context helper
15666 + *  V0.02  vx_ctx_kill syscall command
15667 + *  V0.03  replaced context_info calls
15668 + *  V0.04  redesign of struct (de)alloc
15669 + *  V0.05  rlimit basic implementation
15670 + *  V0.06  task_xid and info commands
15671 + *  V0.07  context flags and caps
15672 + *  V0.08  switch to RCU based hash
15673 + *  V0.09  revert to non RCU for now
15674 + *  V0.10  and back to working RCU hash
15675 + *  V0.11  and back to locking again
15676 + *  V0.12  referenced context store
15677 + *  V0.13  separate per cpu data
15678 + *  V0.14  changed vcmds to vxi arg
15679 + *  V0.15  added context stat
15680 + *  V0.16  have __create claim() the vxi
15681 + *  V0.17  removed older and legacy stuff
15682 + *  V0.18  added user credentials
15683 + *  V0.19  added warn mask
15684 + *
15685 + */
15686 +
15687 +#include <linux/slab.h>
15688 +#include <linux/types.h>
15689 +#include <linux/security.h>
15690 +#include <linux/pid_namespace.h>
15691 +#include <linux/capability.h>
15692 +
15693 +#include <linux/vserver/context.h>
15694 +#include <linux/vserver/network.h>
15695 +#include <linux/vserver/debug.h>
15696 +#include <linux/vserver/limit.h>
15697 +#include <linux/vserver/limit_int.h>
15698 +#include <linux/vserver/space.h>
15699 +#include <linux/init_task.h>
15700 +#include <linux/fs_struct.h>
15701 +#include <linux/cred.h>
15702 +
15703 +#include <linux/vs_context.h>
15704 +#include <linux/vs_limit.h>
15705 +#include <linux/vs_pid.h>
15706 +#include <linux/vserver/context_cmd.h>
15707 +
15708 +#include "cvirt_init.h"
15709 +#include "cacct_init.h"
15710 +#include "limit_init.h"
15711 +#include "sched_init.h"
15712 +
15713 +
15714 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15715 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15716 +
15717 +
15718 +/*     now inactive context structures */
15719 +
15720 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15721 +
15722 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15723 +
15724 +
15725 +/*     __alloc_vx_info()
15726 +
15727 +       * allocate an initialized vx_info struct
15728 +       * doesn't make it visible (hash)                        */
15729 +
15730 +static struct vx_info *__alloc_vx_info(xid_t xid)
15731 +{
15732 +       struct vx_info *new = NULL;
15733 +       int cpu, index;
15734 +
15735 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15736 +
15737 +       /* would this benefit from a slab cache? */
15738 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15739 +       if (!new)
15740 +               return 0;
15741 +
15742 +       memset(new, 0, sizeof(struct vx_info));
15743 +#ifdef CONFIG_SMP
15744 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15745 +       if (!new->ptr_pc)
15746 +               goto error;
15747 +#endif
15748 +       new->vx_id = xid;
15749 +       INIT_HLIST_NODE(&new->vx_hlist);
15750 +       atomic_set(&new->vx_usecnt, 0);
15751 +       atomic_set(&new->vx_tasks, 0);
15752 +       new->vx_parent = NULL;
15753 +       new->vx_state = 0;
15754 +       init_waitqueue_head(&new->vx_wait);
15755 +
15756 +       /* prepare reaper */
15757 +       get_task_struct(init_pid_ns.child_reaper);
15758 +       new->vx_reaper = init_pid_ns.child_reaper;
15759 +       new->vx_badness_bias = 0;
15760 +
15761 +       /* rest of init goes here */
15762 +       vx_info_init_limit(&new->limit);
15763 +       vx_info_init_sched(&new->sched);
15764 +       vx_info_init_cvirt(&new->cvirt);
15765 +       vx_info_init_cacct(&new->cacct);
15766 +
15767 +       /* per cpu data structures */
15768 +       for_each_possible_cpu(cpu) {
15769 +               vx_info_init_sched_pc(
15770 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15771 +               vx_info_init_cvirt_pc(
15772 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15773 +       }
15774 +
15775 +       new->vx_flags = VXF_INIT_SET;
15776 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15777 +       new->vx_ccaps = 0;
15778 +       new->vx_umask = 0;
15779 +       new->vx_wmask = 0;
15780 +
15781 +       new->reboot_cmd = 0;
15782 +       new->exit_code = 0;
15783 +
15784 +       // preconfig spaces
15785 +       for (index = 0; index < VX_SPACES; index++) {
15786 +               struct _vx_space *space = &new->space[index];
15787 +
15788 +               // filesystem
15789 +               spin_lock(&init_fs.lock);
15790 +               init_fs.users++;
15791 +               spin_unlock(&init_fs.lock);
15792 +               space->vx_fs = &init_fs;
15793 +
15794 +               /* FIXME: do we want defaults? */
15795 +               // space->vx_real_cred = 0;
15796 +               // space->vx_cred = 0;
15797 +       }
15798 +
15799 +
15800 +       vxdprintk(VXD_CBIT(xid, 0),
15801 +               "alloc_vx_info(%d) = %p", xid, new);
15802 +       vxh_alloc_vx_info(new);
15803 +       atomic_inc(&vx_global_ctotal);
15804 +       return new;
15805 +#ifdef CONFIG_SMP
15806 +error:
15807 +       kfree(new);
15808 +       return 0;
15809 +#endif
15810 +}
15811 +
15812 +/*     __dealloc_vx_info()
15813 +
15814 +       * final disposal of vx_info                             */
15815 +
15816 +static void __dealloc_vx_info(struct vx_info *vxi)
15817 +{
15818 +#ifdef CONFIG_VSERVER_WARN
15819 +       struct vx_info_save vxis;
15820 +       int cpu;
15821 +#endif
15822 +       vxdprintk(VXD_CBIT(xid, 0),
15823 +               "dealloc_vx_info(%p)", vxi);
15824 +       vxh_dealloc_vx_info(vxi);
15825 +
15826 +#ifdef CONFIG_VSERVER_WARN
15827 +       enter_vx_info(vxi, &vxis);
15828 +       vx_info_exit_limit(&vxi->limit);
15829 +       vx_info_exit_sched(&vxi->sched);
15830 +       vx_info_exit_cvirt(&vxi->cvirt);
15831 +       vx_info_exit_cacct(&vxi->cacct);
15832 +
15833 +       for_each_possible_cpu(cpu) {
15834 +               vx_info_exit_sched_pc(
15835 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15836 +               vx_info_exit_cvirt_pc(
15837 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15838 +       }
15839 +       leave_vx_info(&vxis);
15840 +#endif
15841 +
15842 +       vxi->vx_id = -1;
15843 +       vxi->vx_state |= VXS_RELEASED;
15844 +
15845 +#ifdef CONFIG_SMP
15846 +       free_percpu(vxi->ptr_pc);
15847 +#endif
15848 +       kfree(vxi);
15849 +       atomic_dec(&vx_global_ctotal);
15850 +}
15851 +
15852 +static void __shutdown_vx_info(struct vx_info *vxi)
15853 +{
15854 +       struct nsproxy *nsproxy;
15855 +       struct fs_struct *fs;
15856 +       struct cred *cred;
15857 +       int index, kill;
15858 +
15859 +       might_sleep();
15860 +
15861 +       vxi->vx_state |= VXS_SHUTDOWN;
15862 +       vs_state_change(vxi, VSC_SHUTDOWN);
15863 +
15864 +       for (index = 0; index < VX_SPACES; index++) {
15865 +               struct _vx_space *space = &vxi->space[index];
15866 +
15867 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15868 +               if (nsproxy)
15869 +                       put_nsproxy(nsproxy);
15870 +
15871 +               fs = xchg(&space->vx_fs, NULL);
15872 +               spin_lock(&fs->lock);
15873 +               kill = !--fs->users;
15874 +               spin_unlock(&fs->lock);
15875 +               if (kill)
15876 +                       free_fs_struct(fs);
15877 +
15878 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15879 +               if (cred)
15880 +                       abort_creds(cred);
15881 +       }
15882 +}
15883 +
15884 +/* exported stuff */
15885 +
15886 +void free_vx_info(struct vx_info *vxi)
15887 +{
15888 +       unsigned long flags;
15889 +       unsigned index;
15890 +
15891 +       /* check for reference counts first */
15892 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15893 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15894 +
15895 +       /* context must not be hashed */
15896 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15897 +
15898 +       /* context shutdown is mandatory */
15899 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15900 +
15901 +       /* spaces check */
15902 +       for (index = 0; index < VX_SPACES; index++) {
15903 +               struct _vx_space *space = &vxi->space[index];
15904 +
15905 +               BUG_ON(space->vx_nsproxy);
15906 +               BUG_ON(space->vx_fs);
15907 +               // BUG_ON(space->vx_real_cred);
15908 +               // BUG_ON(space->vx_cred);
15909 +       }
15910 +
15911 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15912 +       hlist_del(&vxi->vx_hlist);
15913 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15914 +
15915 +       __dealloc_vx_info(vxi);
15916 +}
15917 +
15918 +
15919 +/*     hash table for vx_info hash */
15920 +
15921 +#define VX_HASH_SIZE   13
15922 +
15923 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15924 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15925 +
15926 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15927 +
15928 +
15929 +static inline unsigned int __hashval(xid_t xid)
15930 +{
15931 +       return (xid % VX_HASH_SIZE);
15932 +}
15933 +
15934 +
15935 +
15936 +/*     __hash_vx_info()
15937 +
15938 +       * add the vxi to the global hash table
15939 +       * requires the hash_lock to be held                     */
15940 +
15941 +static inline void __hash_vx_info(struct vx_info *vxi)
15942 +{
15943 +       struct hlist_head *head;
15944 +
15945 +       vxd_assert_lock(&vx_info_hash_lock);
15946 +       vxdprintk(VXD_CBIT(xid, 4),
15947 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15948 +       vxh_hash_vx_info(vxi);
15949 +
15950 +       /* context must not be hashed */
15951 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15952 +
15953 +       vxi->vx_state |= VXS_HASHED;
15954 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15955 +       hlist_add_head(&vxi->vx_hlist, head);
15956 +       atomic_inc(&vx_global_cactive);
15957 +}
15958 +
15959 +/*     __unhash_vx_info()
15960 +
15961 +       * remove the vxi from the global hash table
15962 +       * requires the hash_lock to be held                     */
15963 +
15964 +static inline void __unhash_vx_info(struct vx_info *vxi)
15965 +{
15966 +       unsigned long flags;
15967 +
15968 +       vxd_assert_lock(&vx_info_hash_lock);
15969 +       vxdprintk(VXD_CBIT(xid, 4),
15970 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15971 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15972 +       vxh_unhash_vx_info(vxi);
15973 +
15974 +       /* context must be hashed */
15975 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15976 +       /* but without tasks */
15977 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15978 +
15979 +       vxi->vx_state &= ~VXS_HASHED;
15980 +       hlist_del_init(&vxi->vx_hlist);
15981 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15982 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15983 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15984 +       atomic_dec(&vx_global_cactive);
15985 +}
15986 +
15987 +
15988 +/*     __lookup_vx_info()
15989 +
15990 +       * requires the hash_lock to be held
15991 +       * doesn't increment the vx_refcnt                       */
15992 +
15993 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
15994 +{
15995 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15996 +       struct hlist_node *pos;
15997 +       struct vx_info *vxi;
15998 +
15999 +       vxd_assert_lock(&vx_info_hash_lock);
16000 +       hlist_for_each(pos, head) {
16001 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16002 +
16003 +               if (vxi->vx_id == xid)
16004 +                       goto found;
16005 +       }
16006 +       vxi = NULL;
16007 +found:
16008 +       vxdprintk(VXD_CBIT(xid, 0),
16009 +               "__lookup_vx_info(#%u): %p[#%u]",
16010 +               xid, vxi, vxi ? vxi->vx_id : 0);
16011 +       vxh_lookup_vx_info(vxi, xid);
16012 +       return vxi;
16013 +}
16014 +
16015 +
16016 +/*     __create_vx_info()
16017 +
16018 +       * create the requested context
16019 +       * get(), claim() and hash it                            */
16020 +
16021 +static struct vx_info *__create_vx_info(int id)
16022 +{
16023 +       struct vx_info *new, *vxi = NULL;
16024 +
16025 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16026 +
16027 +       if (!(new = __alloc_vx_info(id)))
16028 +               return ERR_PTR(-ENOMEM);
16029 +
16030 +       /* required to make dynamic xids unique */
16031 +       spin_lock(&vx_info_hash_lock);
16032 +
16033 +       /* static context requested */
16034 +       if ((vxi = __lookup_vx_info(id))) {
16035 +               vxdprintk(VXD_CBIT(xid, 0),
16036 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16037 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16038 +                       vxi = ERR_PTR(-EBUSY);
16039 +               else
16040 +                       vxi = ERR_PTR(-EEXIST);
16041 +               goto out_unlock;
16042 +       }
16043 +       /* new context */
16044 +       vxdprintk(VXD_CBIT(xid, 0),
16045 +               "create_vx_info(%d) = %p (new)", id, new);
16046 +       claim_vx_info(new, NULL);
16047 +       __hash_vx_info(get_vx_info(new));
16048 +       vxi = new, new = NULL;
16049 +
16050 +out_unlock:
16051 +       spin_unlock(&vx_info_hash_lock);
16052 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16053 +       if (new)
16054 +               __dealloc_vx_info(new);
16055 +       return vxi;
16056 +}
16057 +
16058 +
16059 +/*     exported stuff                                          */
16060 +
16061 +
16062 +void unhash_vx_info(struct vx_info *vxi)
16063 +{
16064 +       spin_lock(&vx_info_hash_lock);
16065 +       __unhash_vx_info(vxi);
16066 +       spin_unlock(&vx_info_hash_lock);
16067 +       __shutdown_vx_info(vxi);
16068 +       __wakeup_vx_info(vxi);
16069 +}
16070 +
16071 +
16072 +/*     lookup_vx_info()
16073 +
16074 +       * search for a vx_info and get() it
16075 +       * negative id means current                             */
16076 +
16077 +struct vx_info *lookup_vx_info(int id)
16078 +{
16079 +       struct vx_info *vxi = NULL;
16080 +
16081 +       if (id < 0) {
16082 +               vxi = get_vx_info(current_vx_info());
16083 +       } else if (id > 1) {
16084 +               spin_lock(&vx_info_hash_lock);
16085 +               vxi = get_vx_info(__lookup_vx_info(id));
16086 +               spin_unlock(&vx_info_hash_lock);
16087 +       }
16088 +       return vxi;
16089 +}
16090 +
16091 +/*     xid_is_hashed()
16092 +
16093 +       * verify that xid is still hashed                       */
16094 +
16095 +int xid_is_hashed(xid_t xid)
16096 +{
16097 +       int hashed;
16098 +
16099 +       spin_lock(&vx_info_hash_lock);
16100 +       hashed = (__lookup_vx_info(xid) != NULL);
16101 +       spin_unlock(&vx_info_hash_lock);
16102 +       return hashed;
16103 +}
16104 +
16105 +#ifdef CONFIG_PROC_FS
16106 +
16107 +/*     get_xid_list()
16108 +
16109 +       * get a subset of hashed xids for proc
16110 +       * assumes size is at least one                          */
16111 +
16112 +int get_xid_list(int index, unsigned int *xids, int size)
16113 +{
16114 +       int hindex, nr_xids = 0;
16115 +
16116 +       /* only show current and children */
16117 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16118 +               if (index > 0)
16119 +                       return 0;
16120 +               xids[nr_xids] = vx_current_xid();
16121 +               return 1;
16122 +       }
16123 +
16124 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16125 +               struct hlist_head *head = &vx_info_hash[hindex];
16126 +               struct hlist_node *pos;
16127 +
16128 +               spin_lock(&vx_info_hash_lock);
16129 +               hlist_for_each(pos, head) {
16130 +                       struct vx_info *vxi;
16131 +
16132 +                       if (--index > 0)
16133 +                               continue;
16134 +
16135 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16136 +                       xids[nr_xids] = vxi->vx_id;
16137 +                       if (++nr_xids >= size) {
16138 +                               spin_unlock(&vx_info_hash_lock);
16139 +                               goto out;
16140 +                       }
16141 +               }
16142 +               /* keep the lock time short */
16143 +               spin_unlock(&vx_info_hash_lock);
16144 +       }
16145 +out:
16146 +       return nr_xids;
16147 +}
16148 +#endif
16149 +
16150 +#ifdef CONFIG_VSERVER_DEBUG
16151 +
16152 +void   dump_vx_info_inactive(int level)
16153 +{
16154 +       struct hlist_node *entry, *next;
16155 +
16156 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16157 +               struct vx_info *vxi =
16158 +                       list_entry(entry, struct vx_info, vx_hlist);
16159 +
16160 +               dump_vx_info(vxi, level);
16161 +       }
16162 +}
16163 +
16164 +#endif
16165 +
16166 +#if 0
16167 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16168 +{
16169 +       struct user_struct *new_user, *old_user;
16170 +
16171 +       if (!p || !vxi)
16172 +               BUG();
16173 +
16174 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16175 +               return -EACCES;
16176 +
16177 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16178 +       if (!new_user)
16179 +               return -ENOMEM;
16180 +
16181 +       old_user = p->user;
16182 +       if (new_user != old_user) {
16183 +               atomic_inc(&new_user->processes);
16184 +               atomic_dec(&old_user->processes);
16185 +               p->user = new_user;
16186 +       }
16187 +       free_uid(old_user);
16188 +       return 0;
16189 +}
16190 +#endif
16191 +
16192 +#if 0
16193 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16194 +{
16195 +       // p->cap_effective &= vxi->vx_cap_bset;
16196 +       p->cap_effective =
16197 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16198 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16199 +       p->cap_inheritable =
16200 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16201 +       // p->cap_permitted &= vxi->vx_cap_bset;
16202 +       p->cap_permitted =
16203 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16204 +}
16205 +#endif
16206 +
16207 +
16208 +#include <linux/file.h>
16209 +#include <linux/fdtable.h>
16210 +
16211 +static int vx_openfd_task(struct task_struct *tsk)
16212 +{
16213 +       struct files_struct *files = tsk->files;
16214 +       struct fdtable *fdt;
16215 +       const unsigned long *bptr;
16216 +       int count, total;
16217 +
16218 +       /* no rcu_read_lock() because of spin_lock() */
16219 +       spin_lock(&files->file_lock);
16220 +       fdt = files_fdtable(files);
16221 +       bptr = fdt->open_fds;
16222 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16223 +       for (total = 0; count > 0; count--) {
16224 +               if (*bptr)
16225 +                       total += hweight_long(*bptr);
16226 +               bptr++;
16227 +       }
16228 +       spin_unlock(&files->file_lock);
16229 +       return total;
16230 +}
16231 +
16232 +
16233 +/*     for *space compatibility */
16234 +
16235 +asmlinkage long sys_unshare(unsigned long);
16236 +
16237 +/*
16238 + *     migrate task to new context
16239 + *     gets vxi, puts old_vxi on change
16240 + *     optionally unshares namespaces (hack)
16241 + */
16242 +
16243 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16244 +{
16245 +       struct vx_info *old_vxi;
16246 +       int ret = 0;
16247 +
16248 +       if (!p || !vxi)
16249 +               BUG();
16250 +
16251 +       vxdprintk(VXD_CBIT(xid, 5),
16252 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16253 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16254 +
16255 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16256 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16257 +               return -EACCES;
16258 +
16259 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16260 +               return -EFAULT;
16261 +
16262 +       old_vxi = task_get_vx_info(p);
16263 +       if (old_vxi == vxi)
16264 +               goto out;
16265 +
16266 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16267 +       {
16268 +               int openfd;
16269 +
16270 +               task_lock(p);
16271 +               openfd = vx_openfd_task(p);
16272 +
16273 +               if (old_vxi) {
16274 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16275 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16276 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16277 +                       /* FIXME: what about the struct files here? */
16278 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16279 +                       /* account for the executable */
16280 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16281 +               }
16282 +               atomic_inc(&vxi->cvirt.nr_threads);
16283 +               atomic_inc(&vxi->cvirt.nr_running);
16284 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16285 +               /* FIXME: what about the struct files here? */
16286 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16287 +               /* account for the executable */
16288 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16289 +
16290 +               if (old_vxi) {
16291 +                       release_vx_info(old_vxi, p);
16292 +                       clr_vx_info(&p->vx_info);
16293 +               }
16294 +               claim_vx_info(vxi, p);
16295 +               set_vx_info(&p->vx_info, vxi);
16296 +               p->xid = vxi->vx_id;
16297 +
16298 +               vxdprintk(VXD_CBIT(xid, 5),
16299 +                       "moved task %p into vxi:%p[#%d]",
16300 +                       p, vxi, vxi->vx_id);
16301 +
16302 +               // vx_mask_cap_bset(vxi, p);
16303 +               task_unlock(p);
16304 +
16305 +               /* hack for *spaces to provide compatibility */
16306 +               if (unshare) {
16307 +                       struct nsproxy *old_nsp, *new_nsp;
16308 +
16309 +                       ret = unshare_nsproxy_namespaces(
16310 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16311 +                               &new_nsp, NULL);
16312 +                       if (ret)
16313 +                               goto out;
16314 +
16315 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16316 +                       vx_set_space(vxi,
16317 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16318 +                       put_nsproxy(old_nsp);
16319 +               }
16320 +       }
16321 +out:
16322 +       put_vx_info(old_vxi);
16323 +       return ret;
16324 +}
16325 +
16326 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16327 +{
16328 +       struct task_struct *old_reaper;
16329 +       struct vx_info *reaper_vxi;
16330 +
16331 +       if (!vxi)
16332 +               return -EINVAL;
16333 +
16334 +       vxdprintk(VXD_CBIT(xid, 6),
16335 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16336 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16337 +
16338 +       old_reaper = vxi->vx_reaper;
16339 +       if (old_reaper == p)
16340 +               return 0;
16341 +
16342 +       reaper_vxi = task_get_vx_info(p);
16343 +       if (reaper_vxi && reaper_vxi != vxi) {
16344 +               vxwprintk(1,
16345 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16346 +                       "for [xid #%u]",
16347 +                       p->comm, p->pid, p->xid, vx_current_xid());
16348 +               goto out;
16349 +       }
16350 +
16351 +       /* set new child reaper */
16352 +       get_task_struct(p);
16353 +       vxi->vx_reaper = p;
16354 +       put_task_struct(old_reaper);
16355 +out:
16356 +       put_vx_info(reaper_vxi);
16357 +       return 0;
16358 +}
16359 +
16360 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16361 +{
16362 +       if (!vxi)
16363 +               return -EINVAL;
16364 +
16365 +       vxdprintk(VXD_CBIT(xid, 6),
16366 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16367 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16368 +
16369 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16370 +       // vxi->vx_initpid = p->tgid;
16371 +       vxi->vx_initpid = p->pid;
16372 +       return 0;
16373 +}
16374 +
16375 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16376 +{
16377 +       vxdprintk(VXD_CBIT(xid, 6),
16378 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16379 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16380 +
16381 +       vxi->exit_code = code;
16382 +       vxi->vx_initpid = 0;
16383 +}
16384 +
16385 +
16386 +void vx_set_persistent(struct vx_info *vxi)
16387 +{
16388 +       vxdprintk(VXD_CBIT(xid, 6),
16389 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16390 +
16391 +       get_vx_info(vxi);
16392 +       claim_vx_info(vxi, NULL);
16393 +}
16394 +
16395 +void vx_clear_persistent(struct vx_info *vxi)
16396 +{
16397 +       vxdprintk(VXD_CBIT(xid, 6),
16398 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16399 +
16400 +       release_vx_info(vxi, NULL);
16401 +       put_vx_info(vxi);
16402 +}
16403 +
16404 +void vx_update_persistent(struct vx_info *vxi)
16405 +{
16406 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16407 +               vx_set_persistent(vxi);
16408 +       else
16409 +               vx_clear_persistent(vxi);
16410 +}
16411 +
16412 +
16413 +/*     task must be current or locked          */
16414 +
16415 +void   exit_vx_info(struct task_struct *p, int code)
16416 +{
16417 +       struct vx_info *vxi = p->vx_info;
16418 +
16419 +       if (vxi) {
16420 +               atomic_dec(&vxi->cvirt.nr_threads);
16421 +               vx_nproc_dec(p);
16422 +
16423 +               vxi->exit_code = code;
16424 +               release_vx_info(vxi, p);
16425 +       }
16426 +}
16427 +
16428 +void   exit_vx_info_early(struct task_struct *p, int code)
16429 +{
16430 +       struct vx_info *vxi = p->vx_info;
16431 +
16432 +       if (vxi) {
16433 +               if (vxi->vx_initpid == p->pid)
16434 +                       vx_exit_init(vxi, p, code);
16435 +               if (vxi->vx_reaper == p)
16436 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16437 +       }
16438 +}
16439 +
16440 +
16441 +/* vserver syscall commands below here */
16442 +
16443 +/* taks xid and vx_info functions */
16444 +
16445 +#include <asm/uaccess.h>
16446 +
16447 +
16448 +int vc_task_xid(uint32_t id)
16449 +{
16450 +       xid_t xid;
16451 +
16452 +       if (id) {
16453 +               struct task_struct *tsk;
16454 +
16455 +               rcu_read_lock();
16456 +               tsk = find_task_by_real_pid(id);
16457 +               xid = (tsk) ? tsk->xid : -ESRCH;
16458 +               rcu_read_unlock();
16459 +       } else
16460 +               xid = vx_current_xid();
16461 +       return xid;
16462 +}
16463 +
16464 +
16465 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16466 +{
16467 +       struct vcmd_vx_info_v0 vc_data;
16468 +
16469 +       vc_data.xid = vxi->vx_id;
16470 +       vc_data.initpid = vxi->vx_initpid;
16471 +
16472 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16473 +               return -EFAULT;
16474 +       return 0;
16475 +}
16476 +
16477 +
16478 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16479 +{
16480 +       struct vcmd_ctx_stat_v0 vc_data;
16481 +
16482 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16483 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16484 +
16485 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16486 +               return -EFAULT;
16487 +       return 0;
16488 +}
16489 +
16490 +
16491 +/* context functions */
16492 +
16493 +int vc_ctx_create(uint32_t xid, void __user *data)
16494 +{
16495 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16496 +       struct vx_info *new_vxi;
16497 +       int ret;
16498 +
16499 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16500 +               return -EFAULT;
16501 +
16502 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16503 +               return -EINVAL;
16504 +
16505 +       new_vxi = __create_vx_info(xid);
16506 +       if (IS_ERR(new_vxi))
16507 +               return PTR_ERR(new_vxi);
16508 +
16509 +       /* initial flags */
16510 +       new_vxi->vx_flags = vc_data.flagword;
16511 +
16512 +       ret = -ENOEXEC;
16513 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16514 +               goto out;
16515 +
16516 +       ret = vx_migrate_task(current, new_vxi, (!data));
16517 +       if (ret)
16518 +               goto out;
16519 +
16520 +       /* return context id on success */
16521 +       ret = new_vxi->vx_id;
16522 +
16523 +       /* get a reference for persistent contexts */
16524 +       if ((vc_data.flagword & VXF_PERSISTENT))
16525 +               vx_set_persistent(new_vxi);
16526 +out:
16527 +       release_vx_info(new_vxi, NULL);
16528 +       put_vx_info(new_vxi);
16529 +       return ret;
16530 +}
16531 +
16532 +
16533 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16534 +{
16535 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16536 +       int ret;
16537 +
16538 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16539 +               return -EFAULT;
16540 +
16541 +       ret = vx_migrate_task(current, vxi, 0);
16542 +       if (ret)
16543 +               return ret;
16544 +       if (vc_data.flagword & VXM_SET_INIT)
16545 +               ret = vx_set_init(vxi, current);
16546 +       if (ret)
16547 +               return ret;
16548 +       if (vc_data.flagword & VXM_SET_REAPER)
16549 +               ret = vx_set_reaper(vxi, current);
16550 +       return ret;
16551 +}
16552 +
16553 +
16554 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16555 +{
16556 +       struct vcmd_ctx_flags_v0 vc_data;
16557 +
16558 +       vc_data.flagword = vxi->vx_flags;
16559 +
16560 +       /* special STATE flag handling */
16561 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16562 +
16563 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16564 +               return -EFAULT;
16565 +       return 0;
16566 +}
16567 +
16568 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16569 +{
16570 +       struct vcmd_ctx_flags_v0 vc_data;
16571 +       uint64_t mask, trigger;
16572 +
16573 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16574 +               return -EFAULT;
16575 +
16576 +       /* special STATE flag handling */
16577 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16578 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16579 +
16580 +       if (vxi == current_vx_info()) {
16581 +               /* if (trigger & VXF_STATE_SETUP)
16582 +                       vx_mask_cap_bset(vxi, current); */
16583 +               if (trigger & VXF_STATE_INIT) {
16584 +                       int ret;
16585 +
16586 +                       ret = vx_set_init(vxi, current);
16587 +                       if (ret)
16588 +                               return ret;
16589 +                       ret = vx_set_reaper(vxi, current);
16590 +                       if (ret)
16591 +                               return ret;
16592 +               }
16593 +       }
16594 +
16595 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16596 +               vc_data.flagword, mask);
16597 +       if (trigger & VXF_PERSISTENT)
16598 +               vx_update_persistent(vxi);
16599 +
16600 +       return 0;
16601 +}
16602 +
16603 +
16604 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16605 +{
16606 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16607 +
16608 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16609 +       return v;
16610 +}
16611 +
16612 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16613 +{
16614 +       kernel_cap_t c = __cap_empty_set;
16615 +
16616 +       c.cap[0] = v & 0xFFFFFFFF;
16617 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16618 +
16619 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16620 +       return c;
16621 +}
16622 +
16623 +
16624 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16625 +{
16626 +       if (bcaps)
16627 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16628 +       if (ccaps)
16629 +               *ccaps = vxi->vx_ccaps;
16630 +
16631 +       return 0;
16632 +}
16633 +
16634 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16635 +{
16636 +       struct vcmd_ctx_caps_v1 vc_data;
16637 +       int ret;
16638 +
16639 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16640 +       if (ret)
16641 +               return ret;
16642 +       vc_data.cmask = ~0ULL;
16643 +
16644 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16645 +               return -EFAULT;
16646 +       return 0;
16647 +}
16648 +
16649 +static int do_set_caps(struct vx_info *vxi,
16650 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16651 +{
16652 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16653 +
16654 +#if 0
16655 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16656 +               bcaps, bmask, ccaps, cmask);
16657 +#endif
16658 +       vxi->vx_bcaps = cap_t_from_caps(
16659 +               vs_mask_flags(bcold, bcaps, bmask));
16660 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16661 +
16662 +       return 0;
16663 +}
16664 +
16665 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16666 +{
16667 +       struct vcmd_ctx_caps_v1 vc_data;
16668 +
16669 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16670 +               return -EFAULT;
16671 +
16672 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16673 +}
16674 +
16675 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16676 +{
16677 +       struct vcmd_bcaps vc_data;
16678 +       int ret;
16679 +
16680 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16681 +       if (ret)
16682 +               return ret;
16683 +       vc_data.bmask = ~0ULL;
16684 +
16685 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16686 +               return -EFAULT;
16687 +       return 0;
16688 +}
16689 +
16690 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16691 +{
16692 +       struct vcmd_bcaps vc_data;
16693 +
16694 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16695 +               return -EFAULT;
16696 +
16697 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16698 +}
16699 +
16700 +
16701 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16702 +{
16703 +       struct vcmd_umask vc_data;
16704 +
16705 +       vc_data.umask = vxi->vx_umask;
16706 +       vc_data.mask = ~0ULL;
16707 +
16708 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16709 +               return -EFAULT;
16710 +       return 0;
16711 +}
16712 +
16713 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16714 +{
16715 +       struct vcmd_umask vc_data;
16716 +
16717 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16718 +               return -EFAULT;
16719 +
16720 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16721 +               vc_data.umask, vc_data.mask);
16722 +       return 0;
16723 +}
16724 +
16725 +
16726 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16727 +{
16728 +       struct vcmd_wmask vc_data;
16729 +
16730 +       vc_data.wmask = vxi->vx_wmask;
16731 +       vc_data.mask = ~0ULL;
16732 +
16733 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16734 +               return -EFAULT;
16735 +       return 0;
16736 +}
16737 +
16738 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16739 +{
16740 +       struct vcmd_wmask vc_data;
16741 +
16742 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16743 +               return -EFAULT;
16744 +
16745 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16746 +               vc_data.wmask, vc_data.mask);
16747 +       return 0;
16748 +}
16749 +
16750 +
16751 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16752 +{
16753 +       struct vcmd_badness_v0 vc_data;
16754 +
16755 +       vc_data.bias = vxi->vx_badness_bias;
16756 +
16757 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16758 +               return -EFAULT;
16759 +       return 0;
16760 +}
16761 +
16762 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16763 +{
16764 +       struct vcmd_badness_v0 vc_data;
16765 +
16766 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16767 +               return -EFAULT;
16768 +
16769 +       vxi->vx_badness_bias = vc_data.bias;
16770 +       return 0;
16771 +}
16772 +
16773 +#include <linux/module.h>
16774 +
16775 +EXPORT_SYMBOL_GPL(free_vx_info);
16776 +
16777 diff -NurpP --minimal linux-3.7/kernel/vserver/cvirt.c linux-3.7-vs2.3.5.1/kernel/vserver/cvirt.c
16778 --- linux-3.7/kernel/vserver/cvirt.c    1970-01-01 00:00:00.000000000 +0000
16779 +++ linux-3.7-vs2.3.5.1/kernel/vserver/cvirt.c  2012-12-11 15:56:33.000000000 +0000
16780 @@ -0,0 +1,313 @@
16781 +/*
16782 + *  linux/kernel/vserver/cvirt.c
16783 + *
16784 + *  Virtual Server: Context Virtualization
16785 + *
16786 + *  Copyright (C) 2004-2007  Herbert Pötzl
16787 + *
16788 + *  V0.01  broken out from limit.c
16789 + *  V0.02  added utsname stuff
16790 + *  V0.03  changed vcmds to vxi arg
16791 + *
16792 + */
16793 +
16794 +#include <linux/types.h>
16795 +#include <linux/utsname.h>
16796 +#include <linux/vs_cvirt.h>
16797 +#include <linux/vserver/switch.h>
16798 +#include <linux/vserver/cvirt_cmd.h>
16799 +
16800 +#include <asm/uaccess.h>
16801 +
16802 +
16803 +void vx_vsi_boottime(struct timespec *boottime)
16804 +{
16805 +       struct vx_info *vxi = current_vx_info();
16806 +
16807 +       set_normalized_timespec(boottime,
16808 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16809 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16810 +       return;
16811 +}
16812 +
16813 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16814 +{
16815 +       struct vx_info *vxi = current_vx_info();
16816 +
16817 +       set_normalized_timespec(uptime,
16818 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16819 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16820 +       if (!idle)
16821 +               return;
16822 +       set_normalized_timespec(idle,
16823 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16824 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16825 +       return;
16826 +}
16827 +
16828 +uint64_t vx_idle_jiffies(void)
16829 +{
16830 +       return init_task.utime + init_task.stime;
16831 +}
16832 +
16833 +
16834 +
16835 +static inline uint32_t __update_loadavg(uint32_t load,
16836 +       int wsize, int delta, int n)
16837 +{
16838 +       unsigned long long calc, prev;
16839 +
16840 +       /* just set it to n */
16841 +       if (unlikely(delta >= wsize))
16842 +               return (n << FSHIFT);
16843 +
16844 +       calc = delta * n;
16845 +       calc <<= FSHIFT;
16846 +       prev = (wsize - delta);
16847 +       prev *= load;
16848 +       calc += prev;
16849 +       do_div(calc, wsize);
16850 +       return calc;
16851 +}
16852 +
16853 +
16854 +void vx_update_load(struct vx_info *vxi)
16855 +{
16856 +       uint32_t now, last, delta;
16857 +       unsigned int nr_running, nr_uninterruptible;
16858 +       unsigned int total;
16859 +       unsigned long flags;
16860 +
16861 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16862 +
16863 +       now = jiffies;
16864 +       last = vxi->cvirt.load_last;
16865 +       delta = now - last;
16866 +
16867 +       if (delta < 5*HZ)
16868 +               goto out;
16869 +
16870 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16871 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16872 +       total = nr_running + nr_uninterruptible;
16873 +
16874 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16875 +               60*HZ, delta, total);
16876 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16877 +               5*60*HZ, delta, total);
16878 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16879 +               15*60*HZ, delta, total);
16880 +
16881 +       vxi->cvirt.load_last = now;
16882 +out:
16883 +       atomic_inc(&vxi->cvirt.load_updates);
16884 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16885 +}
16886 +
16887 +
16888 +/*
16889 + * Commands to do_syslog:
16890 + *
16891 + *      0 -- Close the log.  Currently a NOP.
16892 + *      1 -- Open the log. Currently a NOP.
16893 + *      2 -- Read from the log.
16894 + *      3 -- Read all messages remaining in the ring buffer.
16895 + *      4 -- Read and clear all messages remaining in the ring buffer
16896 + *      5 -- Clear ring buffer.
16897 + *      6 -- Disable printk's to console
16898 + *      7 -- Enable printk's to console
16899 + *      8 -- Set level of messages printed to console
16900 + *      9 -- Return number of unread characters in the log buffer
16901 + *     10 -- Return size of the log buffer
16902 + */
16903 +int vx_do_syslog(int type, char __user *buf, int len)
16904 +{
16905 +       int error = 0;
16906 +       int do_clear = 0;
16907 +       struct vx_info *vxi = current_vx_info();
16908 +       struct _vx_syslog *log;
16909 +
16910 +       if (!vxi)
16911 +               return -EINVAL;
16912 +       log = &vxi->cvirt.syslog;
16913 +
16914 +       switch (type) {
16915 +       case 0:         /* Close log */
16916 +       case 1:         /* Open log */
16917 +               break;
16918 +       case 2:         /* Read from log */
16919 +               error = wait_event_interruptible(log->log_wait,
16920 +                       (log->log_start - log->log_end));
16921 +               if (error)
16922 +                       break;
16923 +               spin_lock_irq(&log->logbuf_lock);
16924 +               spin_unlock_irq(&log->logbuf_lock);
16925 +               break;
16926 +       case 4:         /* Read/clear last kernel messages */
16927 +               do_clear = 1;
16928 +               /* fall through */
16929 +       case 3:         /* Read last kernel messages */
16930 +               return 0;
16931 +
16932 +       case 5:         /* Clear ring buffer */
16933 +               return 0;
16934 +
16935 +       case 6:         /* Disable logging to console */
16936 +       case 7:         /* Enable logging to console */
16937 +       case 8:         /* Set level of messages printed to console */
16938 +               break;
16939 +
16940 +       case 9:         /* Number of chars in the log buffer */
16941 +               return 0;
16942 +       case 10:        /* Size of the log buffer */
16943 +               return 0;
16944 +       default:
16945 +               error = -EINVAL;
16946 +               break;
16947 +       }
16948 +       return error;
16949 +}
16950 +
16951 +
16952 +/* virtual host info names */
16953 +
16954 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16955 +{
16956 +       struct nsproxy *nsproxy;
16957 +       struct uts_namespace *uts;
16958 +
16959 +       if (id == VHIN_CONTEXT)
16960 +               return vxi->vx_name;
16961 +
16962 +       nsproxy = vxi->space[0].vx_nsproxy;
16963 +       if (!nsproxy)
16964 +               return NULL;
16965 +
16966 +       uts = nsproxy->uts_ns;
16967 +       if (!uts)
16968 +               return NULL;
16969 +
16970 +       switch (id) {
16971 +       case VHIN_SYSNAME:
16972 +               return uts->name.sysname;
16973 +       case VHIN_NODENAME:
16974 +               return uts->name.nodename;
16975 +       case VHIN_RELEASE:
16976 +               return uts->name.release;
16977 +       case VHIN_VERSION:
16978 +               return uts->name.version;
16979 +       case VHIN_MACHINE:
16980 +               return uts->name.machine;
16981 +       case VHIN_DOMAINNAME:
16982 +               return uts->name.domainname;
16983 +       default:
16984 +               return NULL;
16985 +       }
16986 +       return NULL;
16987 +}
16988 +
16989 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16990 +{
16991 +       struct vcmd_vhi_name_v0 vc_data;
16992 +       char *name;
16993 +
16994 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16995 +               return -EFAULT;
16996 +
16997 +       name = vx_vhi_name(vxi, vc_data.field);
16998 +       if (!name)
16999 +               return -EINVAL;
17000 +
17001 +       memcpy(name, vc_data.name, 65);
17002 +       return 0;
17003 +}
17004 +
17005 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17006 +{
17007 +       struct vcmd_vhi_name_v0 vc_data;
17008 +       char *name;
17009 +
17010 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17011 +               return -EFAULT;
17012 +
17013 +       name = vx_vhi_name(vxi, vc_data.field);
17014 +       if (!name)
17015 +               return -EINVAL;
17016 +
17017 +       memcpy(vc_data.name, name, 65);
17018 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17019 +               return -EFAULT;
17020 +       return 0;
17021 +}
17022 +
17023 +
17024 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17025 +{
17026 +       struct vcmd_virt_stat_v0 vc_data;
17027 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17028 +       struct timespec uptime;
17029 +
17030 +       do_posix_clock_monotonic_gettime(&uptime);
17031 +       set_normalized_timespec(&uptime,
17032 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17033 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17034 +
17035 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17036 +       vc_data.uptime = timespec_to_ns(&uptime);
17037 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17038 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17039 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17040 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17041 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17042 +       vc_data.load[0] = cvirt->load[0];
17043 +       vc_data.load[1] = cvirt->load[1];
17044 +       vc_data.load[2] = cvirt->load[2];
17045 +
17046 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17047 +               return -EFAULT;
17048 +       return 0;
17049 +}
17050 +
17051 +
17052 +#ifdef CONFIG_VSERVER_VTIME
17053 +
17054 +/* virtualized time base */
17055 +
17056 +void vx_adjust_timespec(struct timespec *ts)
17057 +{
17058 +       struct vx_info *vxi;
17059 +
17060 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17061 +               return;
17062 +
17063 +       vxi = current_vx_info();
17064 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17065 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17066 +
17067 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17068 +               ts->tv_sec++;
17069 +               ts->tv_nsec -= NSEC_PER_SEC;
17070 +       } else if (ts->tv_nsec < 0) {
17071 +               ts->tv_sec--;
17072 +               ts->tv_nsec += NSEC_PER_SEC;
17073 +       }
17074 +}
17075 +
17076 +int vx_settimeofday(const struct timespec *ts)
17077 +{
17078 +       struct timespec ats, delta;
17079 +       struct vx_info *vxi;
17080 +
17081 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17082 +               return do_settimeofday(ts);
17083 +
17084 +       getnstimeofday(&ats);
17085 +       delta = timespec_sub(*ts, ats);
17086 +
17087 +       vxi = current_vx_info();
17088 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17089 +       return 0;
17090 +}
17091 +
17092 +#endif
17093 +
17094 diff -NurpP --minimal linux-3.7/kernel/vserver/cvirt_init.h linux-3.7-vs2.3.5.1/kernel/vserver/cvirt_init.h
17095 --- linux-3.7/kernel/vserver/cvirt_init.h       1970-01-01 00:00:00.000000000 +0000
17096 +++ linux-3.7-vs2.3.5.1/kernel/vserver/cvirt_init.h     2012-12-11 15:56:33.000000000 +0000
17097 @@ -0,0 +1,70 @@
17098 +
17099 +
17100 +extern uint64_t vx_idle_jiffies(void);
17101 +
17102 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17103 +{
17104 +       uint64_t idle_jiffies = vx_idle_jiffies();
17105 +       uint64_t nsuptime;
17106 +
17107 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17108 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17109 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17110 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17111 +       cvirt->bias_ts.tv_sec = 0;
17112 +       cvirt->bias_ts.tv_nsec = 0;
17113 +
17114 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17115 +       atomic_set(&cvirt->nr_threads, 0);
17116 +       atomic_set(&cvirt->nr_running, 0);
17117 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17118 +       atomic_set(&cvirt->nr_onhold, 0);
17119 +
17120 +       spin_lock_init(&cvirt->load_lock);
17121 +       cvirt->load_last = jiffies;
17122 +       atomic_set(&cvirt->load_updates, 0);
17123 +       cvirt->load[0] = 0;
17124 +       cvirt->load[1] = 0;
17125 +       cvirt->load[2] = 0;
17126 +       atomic_set(&cvirt->total_forks, 0);
17127 +
17128 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17129 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17130 +       cvirt->syslog.log_start = 0;
17131 +       cvirt->syslog.log_end = 0;
17132 +       cvirt->syslog.con_start = 0;
17133 +       cvirt->syslog.logged_chars = 0;
17134 +}
17135 +
17136 +static inline
17137 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17138 +{
17139 +       // cvirt_pc->cpustat = { 0 };
17140 +}
17141 +
17142 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17143 +{
17144 +#ifdef CONFIG_VSERVER_WARN
17145 +       int value;
17146 +#endif
17147 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17148 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17149 +               cvirt, value);
17150 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17151 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17152 +               cvirt, value);
17153 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17154 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17155 +               cvirt, value);
17156 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17157 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17158 +               cvirt, value);
17159 +       return;
17160 +}
17161 +
17162 +static inline
17163 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17164 +{
17165 +       return;
17166 +}
17167 +
17168 diff -NurpP --minimal linux-3.7/kernel/vserver/cvirt_proc.h linux-3.7-vs2.3.5.1/kernel/vserver/cvirt_proc.h
17169 --- linux-3.7/kernel/vserver/cvirt_proc.h       1970-01-01 00:00:00.000000000 +0000
17170 +++ linux-3.7-vs2.3.5.1/kernel/vserver/cvirt_proc.h     2012-12-11 15:56:33.000000000 +0000
17171 @@ -0,0 +1,123 @@
17172 +#ifndef _VX_CVIRT_PROC_H
17173 +#define _VX_CVIRT_PROC_H
17174 +
17175 +#include <linux/nsproxy.h>
17176 +#include <linux/mnt_namespace.h>
17177 +#include <linux/ipc_namespace.h>
17178 +#include <linux/utsname.h>
17179 +#include <linux/ipc.h>
17180 +
17181 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17182 +
17183 +static inline
17184 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17185 +{
17186 +       struct mnt_namespace *ns;
17187 +       struct uts_namespace *uts;
17188 +       struct ipc_namespace *ipc;
17189 +       int length = 0;
17190 +
17191 +       if (!nsproxy)
17192 +               goto out;
17193 +
17194 +       length += sprintf(buffer + length,
17195 +               "NSProxy:\t%p [%p,%p,%p]\n",
17196 +               nsproxy, nsproxy->mnt_ns,
17197 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17198 +
17199 +       ns = nsproxy->mnt_ns;
17200 +       if (!ns)
17201 +               goto skip_ns;
17202 +
17203 +       length += vx_info_mnt_namespace(ns, buffer + length);
17204 +
17205 +skip_ns:
17206 +
17207 +       uts = nsproxy->uts_ns;
17208 +       if (!uts)
17209 +               goto skip_uts;
17210 +
17211 +       length += sprintf(buffer + length,
17212 +               "SysName:\t%.*s\n"
17213 +               "NodeName:\t%.*s\n"
17214 +               "Release:\t%.*s\n"
17215 +               "Version:\t%.*s\n"
17216 +               "Machine:\t%.*s\n"
17217 +               "DomainName:\t%.*s\n",
17218 +               __NEW_UTS_LEN, uts->name.sysname,
17219 +               __NEW_UTS_LEN, uts->name.nodename,
17220 +               __NEW_UTS_LEN, uts->name.release,
17221 +               __NEW_UTS_LEN, uts->name.version,
17222 +               __NEW_UTS_LEN, uts->name.machine,
17223 +               __NEW_UTS_LEN, uts->name.domainname);
17224 +skip_uts:
17225 +
17226 +       ipc = nsproxy->ipc_ns;
17227 +       if (!ipc)
17228 +               goto skip_ipc;
17229 +
17230 +       length += sprintf(buffer + length,
17231 +               "SEMS:\t\t%d %d %d %d  %d\n"
17232 +               "MSG:\t\t%d %d %d\n"
17233 +               "SHM:\t\t%lu %lu  %d %d\n",
17234 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17235 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17236 +               ipc->used_sems,
17237 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17238 +               (unsigned long)ipc->shm_ctlmax,
17239 +               (unsigned long)ipc->shm_ctlall,
17240 +               ipc->shm_ctlmni, ipc->shm_tot);
17241 +skip_ipc:
17242 +out:
17243 +       return length;
17244 +}
17245 +
17246 +
17247 +#include <linux/sched.h>
17248 +
17249 +#define LOAD_INT(x) ((x) >> FSHIFT)
17250 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17251 +
17252 +static inline
17253 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17254 +{
17255 +       int length = 0;
17256 +       int a, b, c;
17257 +
17258 +       length += sprintf(buffer + length,
17259 +               "BiasUptime:\t%lu.%02lu\n",
17260 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17261 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17262 +
17263 +       a = cvirt->load[0] + (FIXED_1 / 200);
17264 +       b = cvirt->load[1] + (FIXED_1 / 200);
17265 +       c = cvirt->load[2] + (FIXED_1 / 200);
17266 +       length += sprintf(buffer + length,
17267 +               "nr_threads:\t%d\n"
17268 +               "nr_running:\t%d\n"
17269 +               "nr_unintr:\t%d\n"
17270 +               "nr_onhold:\t%d\n"
17271 +               "load_updates:\t%d\n"
17272 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17273 +               "total_forks:\t%d\n",
17274 +               atomic_read(&cvirt->nr_threads),
17275 +               atomic_read(&cvirt->nr_running),
17276 +               atomic_read(&cvirt->nr_uninterruptible),
17277 +               atomic_read(&cvirt->nr_onhold),
17278 +               atomic_read(&cvirt->load_updates),
17279 +               LOAD_INT(a), LOAD_FRAC(a),
17280 +               LOAD_INT(b), LOAD_FRAC(b),
17281 +               LOAD_INT(c), LOAD_FRAC(c),
17282 +               atomic_read(&cvirt->total_forks));
17283 +       return length;
17284 +}
17285 +
17286 +static inline
17287 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17288 +       char *buffer, int cpu)
17289 +{
17290 +       int length = 0;
17291 +       return length;
17292 +}
17293 +
17294 +#endif /* _VX_CVIRT_PROC_H */
17295 diff -NurpP --minimal linux-3.7/kernel/vserver/debug.c linux-3.7-vs2.3.5.1/kernel/vserver/debug.c
17296 --- linux-3.7/kernel/vserver/debug.c    1970-01-01 00:00:00.000000000 +0000
17297 +++ linux-3.7-vs2.3.5.1/kernel/vserver/debug.c  2012-12-11 15:56:33.000000000 +0000
17298 @@ -0,0 +1,32 @@
17299 +/*
17300 + *  kernel/vserver/debug.c
17301 + *
17302 + *  Copyright (C) 2005-2007 Herbert Pötzl
17303 + *
17304 + *  V0.01  vx_info dump support
17305 + *
17306 + */
17307 +
17308 +#include <linux/module.h>
17309 +
17310 +#include <linux/vserver/context.h>
17311 +
17312 +
17313 +void   dump_vx_info(struct vx_info *vxi, int level)
17314 +{
17315 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17316 +               atomic_read(&vxi->vx_usecnt),
17317 +               atomic_read(&vxi->vx_tasks),
17318 +               vxi->vx_state);
17319 +       if (level > 0) {
17320 +               __dump_vx_limit(&vxi->limit);
17321 +               __dump_vx_sched(&vxi->sched);
17322 +               __dump_vx_cvirt(&vxi->cvirt);
17323 +               __dump_vx_cacct(&vxi->cacct);
17324 +       }
17325 +       printk("---\n");
17326 +}
17327 +
17328 +
17329 +EXPORT_SYMBOL_GPL(dump_vx_info);
17330 +
17331 diff -NurpP --minimal linux-3.7/kernel/vserver/device.c linux-3.7-vs2.3.5.1/kernel/vserver/device.c
17332 --- linux-3.7/kernel/vserver/device.c   1970-01-01 00:00:00.000000000 +0000
17333 +++ linux-3.7-vs2.3.5.1/kernel/vserver/device.c 2012-12-11 15:56:33.000000000 +0000
17334 @@ -0,0 +1,443 @@
17335 +/*
17336 + *  linux/kernel/vserver/device.c
17337 + *
17338 + *  Linux-VServer: Device Support
17339 + *
17340 + *  Copyright (C) 2006  Herbert Pötzl
17341 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17342 + *
17343 + *  V0.01  device mapping basics
17344 + *  V0.02  added defaults
17345 + *
17346 + */
17347 +
17348 +#include <linux/slab.h>
17349 +#include <linux/rcupdate.h>
17350 +#include <linux/fs.h>
17351 +#include <linux/namei.h>
17352 +#include <linux/hash.h>
17353 +
17354 +#include <asm/errno.h>
17355 +#include <asm/uaccess.h>
17356 +#include <linux/vserver/base.h>
17357 +#include <linux/vserver/debug.h>
17358 +#include <linux/vserver/context.h>
17359 +#include <linux/vserver/device.h>
17360 +#include <linux/vserver/device_cmd.h>
17361 +
17362 +
17363 +#define DMAP_HASH_BITS 4
17364 +
17365 +
17366 +struct vs_mapping {
17367 +       union {
17368 +               struct hlist_node hlist;
17369 +               struct list_head list;
17370 +       } u;
17371 +#define dm_hlist       u.hlist
17372 +#define dm_list                u.list
17373 +       xid_t xid;
17374 +       dev_t device;
17375 +       struct vx_dmap_target target;
17376 +};
17377 +
17378 +
17379 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17380 +
17381 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17382 +
17383 +static struct vx_dmap_target dmap_defaults[2] = {
17384 +       { .flags = DATTR_OPEN },
17385 +       { .flags = DATTR_OPEN },
17386 +};
17387 +
17388 +
17389 +struct kmem_cache *dmap_cachep __read_mostly;
17390 +
17391 +int __init dmap_cache_init(void)
17392 +{
17393 +       dmap_cachep = kmem_cache_create("dmap_cache",
17394 +               sizeof(struct vs_mapping), 0,
17395 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17396 +       return 0;
17397 +}
17398 +
17399 +__initcall(dmap_cache_init);
17400 +
17401 +
17402 +static inline unsigned int __hashval(dev_t dev, int bits)
17403 +{
17404 +       return hash_long((unsigned long)dev, bits);
17405 +}
17406 +
17407 +
17408 +/*     __hash_mapping()
17409 + *     add the mapping to the hash table
17410 + */
17411 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17412 +{
17413 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17414 +       struct hlist_head *head, *hash = dmap_main_hash;
17415 +       int device = vdm->device;
17416 +
17417 +       spin_lock(hash_lock);
17418 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17419 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17420 +
17421 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17422 +       hlist_add_head(&vdm->dm_hlist, head);
17423 +       spin_unlock(hash_lock);
17424 +}
17425 +
17426 +
17427 +static inline int __mode_to_default(umode_t mode)
17428 +{
17429 +       switch (mode) {
17430 +       case S_IFBLK:
17431 +               return 0;
17432 +       case S_IFCHR:
17433 +               return 1;
17434 +       default:
17435 +               BUG();
17436 +       }
17437 +}
17438 +
17439 +
17440 +/*     __set_default()
17441 + *     set a default
17442 + */
17443 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17444 +       struct vx_dmap_target *vdmt)
17445 +{
17446 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17447 +       spin_lock(hash_lock);
17448 +
17449 +       if (vxi)
17450 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17451 +       else
17452 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17453 +
17454 +
17455 +       spin_unlock(hash_lock);
17456 +
17457 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17458 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17459 +}
17460 +
17461 +
17462 +/*     __remove_default()
17463 + *     remove a default
17464 + */
17465 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17466 +{
17467 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17468 +       spin_lock(hash_lock);
17469 +
17470 +       if (vxi)
17471 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17472 +       else    /* remove == reset */
17473 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17474 +
17475 +       spin_unlock(hash_lock);
17476 +       return 0;
17477 +}
17478 +
17479 +
17480 +/*     __find_mapping()
17481 + *     find a mapping in the hash table
17482 + *
17483 + *     caller must hold hash_lock
17484 + */
17485 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17486 +       struct vs_mapping **local, struct vs_mapping **global)
17487 +{
17488 +       struct hlist_head *hash = dmap_main_hash;
17489 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17490 +       struct hlist_node *pos;
17491 +       struct vs_mapping *vdm;
17492 +
17493 +       *local = NULL;
17494 +       if (global)
17495 +               *global = NULL;
17496 +
17497 +       hlist_for_each(pos, head) {
17498 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17499 +
17500 +               if ((vdm->device == device) &&
17501 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17502 +                       if (vdm->xid == xid) {
17503 +                               *local = vdm;
17504 +                               return 1;
17505 +                       } else if (global && vdm->xid == 0)
17506 +                               *global = vdm;
17507 +               }
17508 +       }
17509 +
17510 +       if (global && *global)
17511 +               return 0;
17512 +       else
17513 +               return -ENOENT;
17514 +}
17515 +
17516 +
17517 +/*     __lookup_mapping()
17518 + *     find a mapping and store the result in target and flags
17519 + */
17520 +static inline int __lookup_mapping(struct vx_info *vxi,
17521 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17522 +{
17523 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17524 +       struct vs_mapping *vdm, *global;
17525 +       struct vx_dmap_target *vdmt;
17526 +       int ret = 0;
17527 +       xid_t xid = vxi->vx_id;
17528 +       int index;
17529 +
17530 +       spin_lock(hash_lock);
17531 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17532 +               ret = 1;
17533 +               vdmt = &vdm->target;
17534 +               goto found;
17535 +       }
17536 +
17537 +       index = __mode_to_default(mode);
17538 +       if (vxi && vxi->dmap.targets[index].flags) {
17539 +               ret = 2;
17540 +               vdmt = &vxi->dmap.targets[index];
17541 +       } else if (global) {
17542 +               ret = 3;
17543 +               vdmt = &global->target;
17544 +               goto found;
17545 +       } else {
17546 +               ret = 4;
17547 +               vdmt = &dmap_defaults[index];
17548 +       }
17549 +
17550 +found:
17551 +       if (target && (vdmt->flags & DATTR_REMAP))
17552 +               *target = vdmt->target;
17553 +       else if (target)
17554 +               *target = device;
17555 +       if (flags)
17556 +               *flags = vdmt->flags;
17557 +
17558 +       spin_unlock(hash_lock);
17559 +
17560 +       return ret;
17561 +}
17562 +
17563 +
17564 +/*     __remove_mapping()
17565 + *     remove a mapping from the hash table
17566 + */
17567 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17568 +       umode_t mode)
17569 +{
17570 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17571 +       struct vs_mapping *vdm = NULL;
17572 +       int ret = 0;
17573 +
17574 +       spin_lock(hash_lock);
17575 +
17576 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17577 +               NULL);
17578 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17579 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17580 +       if (ret < 0)
17581 +               goto out;
17582 +       hlist_del(&vdm->dm_hlist);
17583 +
17584 +out:
17585 +       spin_unlock(hash_lock);
17586 +       if (vdm)
17587 +               kmem_cache_free(dmap_cachep, vdm);
17588 +       return ret;
17589 +}
17590 +
17591 +
17592 +
17593 +int vs_map_device(struct vx_info *vxi,
17594 +       dev_t device, dev_t *target, umode_t mode)
17595 +{
17596 +       int ret, flags = DATTR_MASK;
17597 +
17598 +       if (!vxi) {
17599 +               if (target)
17600 +                       *target = device;
17601 +               goto out;
17602 +       }
17603 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17604 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17605 +               device, target ? *target : 0, flags, mode, ret);
17606 +out:
17607 +       return (flags & DATTR_MASK);
17608 +}
17609 +
17610 +
17611 +
17612 +static int do_set_mapping(struct vx_info *vxi,
17613 +       dev_t device, dev_t target, int flags, umode_t mode)
17614 +{
17615 +       if (device) {
17616 +               struct vs_mapping *new;
17617 +
17618 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17619 +               if (!new)
17620 +                       return -ENOMEM;
17621 +
17622 +               INIT_HLIST_NODE(&new->dm_hlist);
17623 +               new->device = device;
17624 +               new->target.target = target;
17625 +               new->target.flags = flags | mode;
17626 +               new->xid = (vxi ? vxi->vx_id : 0);
17627 +
17628 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17629 +               __hash_mapping(vxi, new);
17630 +       } else {
17631 +               struct vx_dmap_target new = {
17632 +                       .target = target,
17633 +                       .flags = flags | mode,
17634 +               };
17635 +               __set_default(vxi, mode, &new);
17636 +       }
17637 +       return 0;
17638 +}
17639 +
17640 +
17641 +static int do_unset_mapping(struct vx_info *vxi,
17642 +       dev_t device, dev_t target, int flags, umode_t mode)
17643 +{
17644 +       int ret = -EINVAL;
17645 +
17646 +       if (device) {
17647 +               ret = __remove_mapping(vxi, device, mode);
17648 +               if (ret < 0)
17649 +                       goto out;
17650 +       } else {
17651 +               ret = __remove_default(vxi, mode);
17652 +               if (ret < 0)
17653 +                       goto out;
17654 +       }
17655 +
17656 +out:
17657 +       return ret;
17658 +}
17659 +
17660 +
17661 +static inline int __user_device(const char __user *name, dev_t *dev,
17662 +       umode_t *mode)
17663 +{
17664 +       struct nameidata nd;
17665 +       int ret;
17666 +
17667 +       if (!name) {
17668 +               *dev = 0;
17669 +               return 0;
17670 +       }
17671 +       ret = user_lpath(name, &nd.path);
17672 +       if (ret)
17673 +               return ret;
17674 +       if (nd.path.dentry->d_inode) {
17675 +               *dev = nd.path.dentry->d_inode->i_rdev;
17676 +               *mode = nd.path.dentry->d_inode->i_mode;
17677 +       }
17678 +       path_put(&nd.path);
17679 +       return 0;
17680 +}
17681 +
17682 +static inline int __mapping_mode(dev_t device, dev_t target,
17683 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17684 +{
17685 +       if (device)
17686 +               *mode = device_mode & S_IFMT;
17687 +       else if (target)
17688 +               *mode = target_mode & S_IFMT;
17689 +       else
17690 +               return -EINVAL;
17691 +
17692 +       /* if both given, device and target mode have to match */
17693 +       if (device && target &&
17694 +               ((device_mode ^ target_mode) & S_IFMT))
17695 +               return -EINVAL;
17696 +       return 0;
17697 +}
17698 +
17699 +
17700 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17701 +       const char __user *target_path, int flags, int set)
17702 +{
17703 +       dev_t device = ~0, target = ~0;
17704 +       umode_t device_mode = 0, target_mode = 0, mode;
17705 +       int ret;
17706 +
17707 +       ret = __user_device(device_path, &device, &device_mode);
17708 +       if (ret)
17709 +               return ret;
17710 +       ret = __user_device(target_path, &target, &target_mode);
17711 +       if (ret)
17712 +               return ret;
17713 +
17714 +       ret = __mapping_mode(device, target,
17715 +               device_mode, target_mode, &mode);
17716 +       if (ret)
17717 +               return ret;
17718 +
17719 +       if (set)
17720 +               return do_set_mapping(vxi, device, target,
17721 +                       flags, mode);
17722 +       else
17723 +               return do_unset_mapping(vxi, device, target,
17724 +                       flags, mode);
17725 +}
17726 +
17727 +
17728 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17729 +{
17730 +       struct vcmd_set_mapping_v0 vc_data;
17731 +
17732 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17733 +               return -EFAULT;
17734 +
17735 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17736 +               vc_data.flags, 1);
17737 +}
17738 +
17739 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17740 +{
17741 +       struct vcmd_set_mapping_v0 vc_data;
17742 +
17743 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17744 +               return -EFAULT;
17745 +
17746 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17747 +               vc_data.flags, 0);
17748 +}
17749 +
17750 +
17751 +#ifdef CONFIG_COMPAT
17752 +
17753 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17754 +{
17755 +       struct vcmd_set_mapping_v0_x32 vc_data;
17756 +
17757 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17758 +               return -EFAULT;
17759 +
17760 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17761 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17762 +}
17763 +
17764 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17765 +{
17766 +       struct vcmd_set_mapping_v0_x32 vc_data;
17767 +
17768 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17769 +               return -EFAULT;
17770 +
17771 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17772 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17773 +}
17774 +
17775 +#endif /* CONFIG_COMPAT */
17776 +
17777 +
17778 diff -NurpP --minimal linux-3.7/kernel/vserver/dlimit.c linux-3.7-vs2.3.5.1/kernel/vserver/dlimit.c
17779 --- linux-3.7/kernel/vserver/dlimit.c   1970-01-01 00:00:00.000000000 +0000
17780 +++ linux-3.7-vs2.3.5.1/kernel/vserver/dlimit.c 2012-12-11 15:56:33.000000000 +0000
17781 @@ -0,0 +1,531 @@
17782 +/*
17783 + *  linux/kernel/vserver/dlimit.c
17784 + *
17785 + *  Virtual Server: Context Disk Limits
17786 + *
17787 + *  Copyright (C) 2004-2009  Herbert Pötzl
17788 + *
17789 + *  V0.01  initial version
17790 + *  V0.02  compat32 splitup
17791 + *  V0.03  extended interface
17792 + *
17793 + */
17794 +
17795 +#include <linux/statfs.h>
17796 +#include <linux/sched.h>
17797 +#include <linux/namei.h>
17798 +#include <linux/vs_tag.h>
17799 +#include <linux/vs_dlimit.h>
17800 +#include <linux/vserver/dlimit_cmd.h>
17801 +#include <linux/slab.h>
17802 +// #include <linux/gfp.h>
17803 +
17804 +#include <asm/uaccess.h>
17805 +
17806 +/*     __alloc_dl_info()
17807 +
17808 +       * allocate an initialized dl_info struct
17809 +       * doesn't make it visible (hash)                        */
17810 +
17811 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17812 +{
17813 +       struct dl_info *new = NULL;
17814 +
17815 +       vxdprintk(VXD_CBIT(dlim, 5),
17816 +               "alloc_dl_info(%p,%d)*", sb, tag);
17817 +
17818 +       /* would this benefit from a slab cache? */
17819 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17820 +       if (!new)
17821 +               return 0;
17822 +
17823 +       memset(new, 0, sizeof(struct dl_info));
17824 +       new->dl_tag = tag;
17825 +       new->dl_sb = sb;
17826 +       // INIT_RCU_HEAD(&new->dl_rcu);
17827 +       INIT_HLIST_NODE(&new->dl_hlist);
17828 +       spin_lock_init(&new->dl_lock);
17829 +       atomic_set(&new->dl_refcnt, 0);
17830 +       atomic_set(&new->dl_usecnt, 0);
17831 +
17832 +       /* rest of init goes here */
17833 +
17834 +       vxdprintk(VXD_CBIT(dlim, 4),
17835 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17836 +       return new;
17837 +}
17838 +
17839 +/*     __dealloc_dl_info()
17840 +
17841 +       * final disposal of dl_info                             */
17842 +
17843 +static void __dealloc_dl_info(struct dl_info *dli)
17844 +{
17845 +       vxdprintk(VXD_CBIT(dlim, 4),
17846 +               "dealloc_dl_info(%p)", dli);
17847 +
17848 +       dli->dl_hlist.next = LIST_POISON1;
17849 +       dli->dl_tag = -1;
17850 +       dli->dl_sb = 0;
17851 +
17852 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17853 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17854 +
17855 +       kfree(dli);
17856 +}
17857 +
17858 +
17859 +/*     hash table for dl_info hash */
17860 +
17861 +#define DL_HASH_SIZE   13
17862 +
17863 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17864 +
17865 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17866 +
17867 +
17868 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17869 +{
17870 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17871 +}
17872 +
17873 +
17874 +
17875 +/*     __hash_dl_info()
17876 +
17877 +       * add the dli to the global hash table
17878 +       * requires the hash_lock to be held                     */
17879 +
17880 +static inline void __hash_dl_info(struct dl_info *dli)
17881 +{
17882 +       struct hlist_head *head;
17883 +
17884 +       vxdprintk(VXD_CBIT(dlim, 6),
17885 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17886 +       get_dl_info(dli);
17887 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17888 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17889 +}
17890 +
17891 +/*     __unhash_dl_info()
17892 +
17893 +       * remove the dli from the global hash table
17894 +       * requires the hash_lock to be held                     */
17895 +
17896 +static inline void __unhash_dl_info(struct dl_info *dli)
17897 +{
17898 +       vxdprintk(VXD_CBIT(dlim, 6),
17899 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17900 +       hlist_del_rcu(&dli->dl_hlist);
17901 +       put_dl_info(dli);
17902 +}
17903 +
17904 +
17905 +/*     __lookup_dl_info()
17906 +
17907 +       * requires the rcu_read_lock()
17908 +       * doesn't increment the dl_refcnt                       */
17909 +
17910 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17911 +{
17912 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17913 +       struct hlist_node *pos;
17914 +       struct dl_info *dli;
17915 +
17916 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
17917 +
17918 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
17919 +                       return dli;
17920 +               }
17921 +       }
17922 +       return NULL;
17923 +}
17924 +
17925 +
17926 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17927 +{
17928 +       struct dl_info *dli;
17929 +
17930 +       rcu_read_lock();
17931 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17932 +       vxdprintk(VXD_CBIT(dlim, 7),
17933 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17934 +       rcu_read_unlock();
17935 +       return dli;
17936 +}
17937 +
17938 +void rcu_free_dl_info(struct rcu_head *head)
17939 +{
17940 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17941 +       int usecnt, refcnt;
17942 +
17943 +       BUG_ON(!dli || !head);
17944 +
17945 +       usecnt = atomic_read(&dli->dl_usecnt);
17946 +       BUG_ON(usecnt < 0);
17947 +
17948 +       refcnt = atomic_read(&dli->dl_refcnt);
17949 +       BUG_ON(refcnt < 0);
17950 +
17951 +       vxdprintk(VXD_CBIT(dlim, 3),
17952 +               "rcu_free_dl_info(%p)", dli);
17953 +       if (!usecnt)
17954 +               __dealloc_dl_info(dli);
17955 +       else
17956 +               printk("!!! rcu didn't free\n");
17957 +}
17958 +
17959 +
17960 +
17961 +
17962 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17963 +       uint32_t flags, int add)
17964 +{
17965 +       struct path path;
17966 +       int ret;
17967 +
17968 +       ret = user_lpath(name, &path);
17969 +       if (!ret) {
17970 +               struct super_block *sb;
17971 +               struct dl_info *dli;
17972 +
17973 +               ret = -EINVAL;
17974 +               if (!path.dentry->d_inode)
17975 +                       goto out_release;
17976 +               if (!(sb = path.dentry->d_inode->i_sb))
17977 +                       goto out_release;
17978 +
17979 +               if (add) {
17980 +                       dli = __alloc_dl_info(sb, id);
17981 +                       spin_lock(&dl_info_hash_lock);
17982 +
17983 +                       ret = -EEXIST;
17984 +                       if (__lookup_dl_info(sb, id))
17985 +                               goto out_unlock;
17986 +                       __hash_dl_info(dli);
17987 +                       dli = NULL;
17988 +               } else {
17989 +                       spin_lock(&dl_info_hash_lock);
17990 +                       dli = __lookup_dl_info(sb, id);
17991 +
17992 +                       ret = -ESRCH;
17993 +                       if (!dli)
17994 +                               goto out_unlock;
17995 +                       __unhash_dl_info(dli);
17996 +               }
17997 +               ret = 0;
17998 +       out_unlock:
17999 +               spin_unlock(&dl_info_hash_lock);
18000 +               if (add && dli)
18001 +                       __dealloc_dl_info(dli);
18002 +       out_release:
18003 +               path_put(&path);
18004 +       }
18005 +       return ret;
18006 +}
18007 +
18008 +int vc_add_dlimit(uint32_t id, void __user *data)
18009 +{
18010 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18011 +
18012 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18013 +               return -EFAULT;
18014 +
18015 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18016 +}
18017 +
18018 +int vc_rem_dlimit(uint32_t id, void __user *data)
18019 +{
18020 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18021 +
18022 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18023 +               return -EFAULT;
18024 +
18025 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18026 +}
18027 +
18028 +#ifdef CONFIG_COMPAT
18029 +
18030 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18031 +{
18032 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18033 +
18034 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18035 +               return -EFAULT;
18036 +
18037 +       return do_addrem_dlimit(id,
18038 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18039 +}
18040 +
18041 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18042 +{
18043 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18044 +
18045 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18046 +               return -EFAULT;
18047 +
18048 +       return do_addrem_dlimit(id,
18049 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18050 +}
18051 +
18052 +#endif /* CONFIG_COMPAT */
18053 +
18054 +
18055 +static inline
18056 +int do_set_dlimit(uint32_t id, const char __user *name,
18057 +       uint32_t space_used, uint32_t space_total,
18058 +       uint32_t inodes_used, uint32_t inodes_total,
18059 +       uint32_t reserved, uint32_t flags)
18060 +{
18061 +       struct path path;
18062 +       int ret;
18063 +
18064 +       ret = user_lpath(name, &path);
18065 +       if (!ret) {
18066 +               struct super_block *sb;
18067 +               struct dl_info *dli;
18068 +
18069 +               ret = -EINVAL;
18070 +               if (!path.dentry->d_inode)
18071 +                       goto out_release;
18072 +               if (!(sb = path.dentry->d_inode->i_sb))
18073 +                       goto out_release;
18074 +
18075 +               /* sanity checks */
18076 +               if ((reserved != CDLIM_KEEP &&
18077 +                       reserved > 100) ||
18078 +                       (inodes_used != CDLIM_KEEP &&
18079 +                       inodes_used > inodes_total) ||
18080 +                       (space_used != CDLIM_KEEP &&
18081 +                       space_used > space_total))
18082 +                       goto out_release;
18083 +
18084 +               ret = -ESRCH;
18085 +               dli = locate_dl_info(sb, id);
18086 +               if (!dli)
18087 +                       goto out_release;
18088 +
18089 +               spin_lock(&dli->dl_lock);
18090 +
18091 +               if (inodes_used != CDLIM_KEEP)
18092 +                       dli->dl_inodes_used = inodes_used;
18093 +               if (inodes_total != CDLIM_KEEP)
18094 +                       dli->dl_inodes_total = inodes_total;
18095 +               if (space_used != CDLIM_KEEP)
18096 +                       dli->dl_space_used = dlimit_space_32to64(
18097 +                               space_used, flags, DLIMS_USED);
18098 +
18099 +               if (space_total == CDLIM_INFINITY)
18100 +                       dli->dl_space_total = DLIM_INFINITY;
18101 +               else if (space_total != CDLIM_KEEP)
18102 +                       dli->dl_space_total = dlimit_space_32to64(
18103 +                               space_total, flags, DLIMS_TOTAL);
18104 +
18105 +               if (reserved != CDLIM_KEEP)
18106 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18107 +
18108 +               spin_unlock(&dli->dl_lock);
18109 +
18110 +               put_dl_info(dli);
18111 +               ret = 0;
18112 +
18113 +       out_release:
18114 +               path_put(&path);
18115 +       }
18116 +       return ret;
18117 +}
18118 +
18119 +int vc_set_dlimit(uint32_t id, void __user *data)
18120 +{
18121 +       struct vcmd_ctx_dlimit_v0 vc_data;
18122 +
18123 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18124 +               return -EFAULT;
18125 +
18126 +       return do_set_dlimit(id, vc_data.name,
18127 +               vc_data.space_used, vc_data.space_total,
18128 +               vc_data.inodes_used, vc_data.inodes_total,
18129 +               vc_data.reserved, vc_data.flags);
18130 +}
18131 +
18132 +#ifdef CONFIG_COMPAT
18133 +
18134 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18135 +{
18136 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18137 +
18138 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18139 +               return -EFAULT;
18140 +
18141 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18142 +               vc_data.space_used, vc_data.space_total,
18143 +               vc_data.inodes_used, vc_data.inodes_total,
18144 +               vc_data.reserved, vc_data.flags);
18145 +}
18146 +
18147 +#endif /* CONFIG_COMPAT */
18148 +
18149 +
18150 +static inline
18151 +int do_get_dlimit(uint32_t id, const char __user *name,
18152 +       uint32_t *space_used, uint32_t *space_total,
18153 +       uint32_t *inodes_used, uint32_t *inodes_total,
18154 +       uint32_t *reserved, uint32_t *flags)
18155 +{
18156 +       struct path path;
18157 +       int ret;
18158 +
18159 +       ret = user_lpath(name, &path);
18160 +       if (!ret) {
18161 +               struct super_block *sb;
18162 +               struct dl_info *dli;
18163 +
18164 +               ret = -EINVAL;
18165 +               if (!path.dentry->d_inode)
18166 +                       goto out_release;
18167 +               if (!(sb = path.dentry->d_inode->i_sb))
18168 +                       goto out_release;
18169 +
18170 +               ret = -ESRCH;
18171 +               dli = locate_dl_info(sb, id);
18172 +               if (!dli)
18173 +                       goto out_release;
18174 +
18175 +               spin_lock(&dli->dl_lock);
18176 +               *inodes_used = dli->dl_inodes_used;
18177 +               *inodes_total = dli->dl_inodes_total;
18178 +
18179 +               *space_used = dlimit_space_64to32(
18180 +                       dli->dl_space_used, flags, DLIMS_USED);
18181 +
18182 +               if (dli->dl_space_total == DLIM_INFINITY)
18183 +                       *space_total = CDLIM_INFINITY;
18184 +               else
18185 +                       *space_total = dlimit_space_64to32(
18186 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18187 +
18188 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18189 +               spin_unlock(&dli->dl_lock);
18190 +
18191 +               put_dl_info(dli);
18192 +               ret = -EFAULT;
18193 +
18194 +               ret = 0;
18195 +       out_release:
18196 +               path_put(&path);
18197 +       }
18198 +       return ret;
18199 +}
18200 +
18201 +
18202 +int vc_get_dlimit(uint32_t id, void __user *data)
18203 +{
18204 +       struct vcmd_ctx_dlimit_v0 vc_data;
18205 +       int ret;
18206 +
18207 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18208 +               return -EFAULT;
18209 +
18210 +       ret = do_get_dlimit(id, vc_data.name,
18211 +               &vc_data.space_used, &vc_data.space_total,
18212 +               &vc_data.inodes_used, &vc_data.inodes_total,
18213 +               &vc_data.reserved, &vc_data.flags);
18214 +       if (ret)
18215 +               return ret;
18216 +
18217 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18218 +               return -EFAULT;
18219 +       return 0;
18220 +}
18221 +
18222 +#ifdef CONFIG_COMPAT
18223 +
18224 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18225 +{
18226 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18227 +       int ret;
18228 +
18229 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18230 +               return -EFAULT;
18231 +
18232 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18233 +               &vc_data.space_used, &vc_data.space_total,
18234 +               &vc_data.inodes_used, &vc_data.inodes_total,
18235 +               &vc_data.reserved, &vc_data.flags);
18236 +       if (ret)
18237 +               return ret;
18238 +
18239 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18240 +               return -EFAULT;
18241 +       return 0;
18242 +}
18243 +
18244 +#endif /* CONFIG_COMPAT */
18245 +
18246 +
18247 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18248 +{
18249 +       struct dl_info *dli;
18250 +       __u64 blimit, bfree, bavail;
18251 +       __u32 ifree;
18252 +
18253 +       dli = locate_dl_info(sb, dx_current_tag());
18254 +       if (!dli)
18255 +               return;
18256 +
18257 +       spin_lock(&dli->dl_lock);
18258 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18259 +               goto no_ilim;
18260 +
18261 +       /* reduce max inodes available to limit */
18262 +       if (buf->f_files > dli->dl_inodes_total)
18263 +               buf->f_files = dli->dl_inodes_total;
18264 +
18265 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18266 +       /* reduce free inodes to min */
18267 +       if (ifree < buf->f_ffree)
18268 +               buf->f_ffree = ifree;
18269 +
18270 +no_ilim:
18271 +       if (dli->dl_space_total == DLIM_INFINITY)
18272 +               goto no_blim;
18273 +
18274 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18275 +
18276 +       if (dli->dl_space_total < dli->dl_space_used)
18277 +               bfree = 0;
18278 +       else
18279 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18280 +                       >> sb->s_blocksize_bits;
18281 +
18282 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18283 +       if (bavail < dli->dl_space_used)
18284 +               bavail = 0;
18285 +       else
18286 +               bavail = (bavail - dli->dl_space_used)
18287 +                       >> sb->s_blocksize_bits;
18288 +
18289 +       /* reduce max space available to limit */
18290 +       if (buf->f_blocks > blimit)
18291 +               buf->f_blocks = blimit;
18292 +
18293 +       /* reduce free space to min */
18294 +       if (bfree < buf->f_bfree)
18295 +               buf->f_bfree = bfree;
18296 +
18297 +       /* reduce avail space to min */
18298 +       if (bavail < buf->f_bavail)
18299 +               buf->f_bavail = bavail;
18300 +
18301 +no_blim:
18302 +       spin_unlock(&dli->dl_lock);
18303 +       put_dl_info(dli);
18304 +
18305 +       return;
18306 +}
18307 +
18308 +#include <linux/module.h>
18309 +
18310 +EXPORT_SYMBOL_GPL(locate_dl_info);
18311 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18312 +
18313 diff -NurpP --minimal linux-3.7/kernel/vserver/helper.c linux-3.7-vs2.3.5.1/kernel/vserver/helper.c
18314 --- linux-3.7/kernel/vserver/helper.c   1970-01-01 00:00:00.000000000 +0000
18315 +++ linux-3.7-vs2.3.5.1/kernel/vserver/helper.c 2012-12-11 15:56:33.000000000 +0000
18316 @@ -0,0 +1,229 @@
18317 +/*
18318 + *  linux/kernel/vserver/helper.c
18319 + *
18320 + *  Virtual Context Support
18321 + *
18322 + *  Copyright (C) 2004-2007  Herbert Pötzl
18323 + *
18324 + *  V0.01  basic helper
18325 + *
18326 + */
18327 +
18328 +#include <linux/kmod.h>
18329 +#include <linux/reboot.h>
18330 +#include <linux/vs_context.h>
18331 +#include <linux/vs_network.h>
18332 +#include <linux/vserver/signal.h>
18333 +
18334 +
18335 +char vshelper_path[255] = "/sbin/vshelper";
18336 +
18337 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18338 +{
18339 +       current->flags &= ~PF_THREAD_BOUND;
18340 +       return 0;
18341 +}
18342 +
18343 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18344 +{
18345 +       int ret;
18346 +
18347 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18348 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18349 +               vshelper_init, NULL, NULL))) {
18350 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18351 +                       name, argv[1], argv[2],
18352 +                       sync ? "sync" : "async", ret);
18353 +       }
18354 +       vxdprintk(VXD_CBIT(switch, 4),
18355 +               "%s: (%s %s) returned %s with %d",
18356 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18357 +       return ret;
18358 +}
18359 +
18360 +/*
18361 + *      vshelper path is set via /proc/sys
18362 + *      invoked by vserver sys_reboot(), with
18363 + *      the following arguments
18364 + *
18365 + *      argv [0] = vshelper_path;
18366 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18367 + *      argv [2] = context identifier
18368 + *
18369 + *      envp [*] = type-specific parameters
18370 + */
18371 +
18372 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18373 +{
18374 +       char id_buf[8], cmd_buf[16];
18375 +       char uid_buf[16], pid_buf[16];
18376 +       int ret;
18377 +
18378 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18379 +       char *envp[] = {"HOME=/", "TERM=linux",
18380 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18381 +                       uid_buf, pid_buf, cmd_buf, 0};
18382 +
18383 +       if (vx_info_state(vxi, VXS_HELPER))
18384 +               return -EAGAIN;
18385 +       vxi->vx_state |= VXS_HELPER;
18386 +
18387 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18388 +
18389 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18390 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18391 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18392 +
18393 +       switch (cmd) {
18394 +       case LINUX_REBOOT_CMD_RESTART:
18395 +               argv[1] = "restart";
18396 +               break;
18397 +
18398 +       case LINUX_REBOOT_CMD_HALT:
18399 +               argv[1] = "halt";
18400 +               break;
18401 +
18402 +       case LINUX_REBOOT_CMD_POWER_OFF:
18403 +               argv[1] = "poweroff";
18404 +               break;
18405 +
18406 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18407 +               argv[1] = "swsusp";
18408 +               break;
18409 +
18410 +       case LINUX_REBOOT_CMD_OOM:
18411 +               argv[1] = "oom";
18412 +               break;
18413 +
18414 +       default:
18415 +               vxi->vx_state &= ~VXS_HELPER;
18416 +               return 0;
18417 +       }
18418 +
18419 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18420 +       vxi->vx_state &= ~VXS_HELPER;
18421 +       __wakeup_vx_info(vxi);
18422 +       return (ret) ? -EPERM : 0;
18423 +}
18424 +
18425 +
18426 +long vs_reboot(unsigned int cmd, void __user *arg)
18427 +{
18428 +       struct vx_info *vxi = current_vx_info();
18429 +       long ret = 0;
18430 +
18431 +       vxdprintk(VXD_CBIT(misc, 5),
18432 +               "vs_reboot(%p[#%d],%u)",
18433 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18434 +
18435 +       ret = vs_reboot_helper(vxi, cmd, arg);
18436 +       if (ret)
18437 +               return ret;
18438 +
18439 +       vxi->reboot_cmd = cmd;
18440 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18441 +               switch (cmd) {
18442 +               case LINUX_REBOOT_CMD_RESTART:
18443 +               case LINUX_REBOOT_CMD_HALT:
18444 +               case LINUX_REBOOT_CMD_POWER_OFF:
18445 +                       vx_info_kill(vxi, 0, SIGKILL);
18446 +                       vx_info_kill(vxi, 1, SIGKILL);
18447 +               default:
18448 +                       break;
18449 +               }
18450 +       }
18451 +       return 0;
18452 +}
18453 +
18454 +long vs_oom_action(unsigned int cmd)
18455 +{
18456 +       struct vx_info *vxi = current_vx_info();
18457 +       long ret = 0;
18458 +
18459 +       vxdprintk(VXD_CBIT(misc, 5),
18460 +               "vs_oom_action(%p[#%d],%u)",
18461 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18462 +
18463 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18464 +       if (ret)
18465 +               return ret;
18466 +
18467 +       vxi->reboot_cmd = cmd;
18468 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18469 +               vx_info_kill(vxi, 0, SIGKILL);
18470 +               vx_info_kill(vxi, 1, SIGKILL);
18471 +       }
18472 +       return 0;
18473 +}
18474 +
18475 +/*
18476 + *      argv [0] = vshelper_path;
18477 + *      argv [1] = action: "startup", "shutdown"
18478 + *      argv [2] = context identifier
18479 + *
18480 + *      envp [*] = type-specific parameters
18481 + */
18482 +
18483 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18484 +{
18485 +       char id_buf[8], cmd_buf[16];
18486 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18487 +       char *envp[] = {"HOME=/", "TERM=linux",
18488 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18489 +
18490 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18491 +               return 0;
18492 +
18493 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18494 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18495 +
18496 +       switch (cmd) {
18497 +       case VSC_STARTUP:
18498 +               argv[1] = "startup";
18499 +               break;
18500 +       case VSC_SHUTDOWN:
18501 +               argv[1] = "shutdown";
18502 +               break;
18503 +       default:
18504 +               return 0;
18505 +       }
18506 +
18507 +       return do_vshelper(vshelper_path, argv, envp, 1);
18508 +}
18509 +
18510 +
18511 +/*
18512 + *      argv [0] = vshelper_path;
18513 + *      argv [1] = action: "netup", "netdown"
18514 + *      argv [2] = context identifier
18515 + *
18516 + *      envp [*] = type-specific parameters
18517 + */
18518 +
18519 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18520 +{
18521 +       char id_buf[8], cmd_buf[16];
18522 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18523 +       char *envp[] = {"HOME=/", "TERM=linux",
18524 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18525 +
18526 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18527 +               return 0;
18528 +
18529 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18530 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18531 +
18532 +       switch (cmd) {
18533 +       case VSC_NETUP:
18534 +               argv[1] = "netup";
18535 +               break;
18536 +       case VSC_NETDOWN:
18537 +               argv[1] = "netdown";
18538 +               break;
18539 +       default:
18540 +               return 0;
18541 +       }
18542 +
18543 +       return do_vshelper(vshelper_path, argv, envp, 1);
18544 +}
18545 +
18546 diff -NurpP --minimal linux-3.7/kernel/vserver/history.c linux-3.7-vs2.3.5.1/kernel/vserver/history.c
18547 --- linux-3.7/kernel/vserver/history.c  1970-01-01 00:00:00.000000000 +0000
18548 +++ linux-3.7-vs2.3.5.1/kernel/vserver/history.c        2012-12-11 15:56:33.000000000 +0000
18549 @@ -0,0 +1,258 @@
18550 +/*
18551 + *  kernel/vserver/history.c
18552 + *
18553 + *  Virtual Context History Backtrace
18554 + *
18555 + *  Copyright (C) 2004-2007  Herbert Pötzl
18556 + *
18557 + *  V0.01  basic structure
18558 + *  V0.02  hash/unhash and trace
18559 + *  V0.03  preemption fixes
18560 + *
18561 + */
18562 +
18563 +#include <linux/module.h>
18564 +#include <asm/uaccess.h>
18565 +
18566 +#include <linux/vserver/context.h>
18567 +#include <linux/vserver/debug.h>
18568 +#include <linux/vserver/debug_cmd.h>
18569 +#include <linux/vserver/history.h>
18570 +
18571 +
18572 +#ifdef CONFIG_VSERVER_HISTORY
18573 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18574 +#else
18575 +#define VXH_SIZE       64
18576 +#endif
18577 +
18578 +struct _vx_history {
18579 +       unsigned int counter;
18580 +
18581 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18582 +};
18583 +
18584 +
18585 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18586 +
18587 +unsigned volatile int vxh_active = 1;
18588 +
18589 +static atomic_t sequence = ATOMIC_INIT(0);
18590 +
18591 +
18592 +/*     vxh_advance()
18593 +
18594 +       * requires disabled preemption                          */
18595 +
18596 +struct _vx_hist_entry *vxh_advance(void *loc)
18597 +{
18598 +       unsigned int cpu = smp_processor_id();
18599 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18600 +       struct _vx_hist_entry *entry;
18601 +       unsigned int index;
18602 +
18603 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18604 +       entry = &hist->entry[index];
18605 +
18606 +       entry->seq = atomic_inc_return(&sequence);
18607 +       entry->loc = loc;
18608 +       return entry;
18609 +}
18610 +
18611 +EXPORT_SYMBOL_GPL(vxh_advance);
18612 +
18613 +
18614 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18615 +
18616 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18617 +
18618 +
18619 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18620 +
18621 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18622 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18623 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18624 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18625 +
18626 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18627 +{
18628 +       switch (e->type) {
18629 +       case VXH_THROW_OOPS:
18630 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18631 +               break;
18632 +
18633 +       case VXH_GET_VX_INFO:
18634 +       case VXH_PUT_VX_INFO:
18635 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18636 +                       VXH_LOC_ARGS(e),
18637 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18638 +                       VXH_VXI_ARGS(e));
18639 +               break;
18640 +
18641 +       case VXH_INIT_VX_INFO:
18642 +       case VXH_SET_VX_INFO:
18643 +       case VXH_CLR_VX_INFO:
18644 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18645 +                       VXH_LOC_ARGS(e),
18646 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18647 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18648 +                       VXH_VXI_ARGS(e), e->sc.data);
18649 +               break;
18650 +
18651 +       case VXH_CLAIM_VX_INFO:
18652 +       case VXH_RELEASE_VX_INFO:
18653 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18654 +                       VXH_LOC_ARGS(e),
18655 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18656 +                       VXH_VXI_ARGS(e), e->sc.data);
18657 +               break;
18658 +
18659 +       case VXH_ALLOC_VX_INFO:
18660 +       case VXH_DEALLOC_VX_INFO:
18661 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18662 +                       VXH_LOC_ARGS(e),
18663 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18664 +                       VXH_VXI_ARGS(e));
18665 +               break;
18666 +
18667 +       case VXH_HASH_VX_INFO:
18668 +       case VXH_UNHASH_VX_INFO:
18669 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18670 +                       VXH_LOC_ARGS(e),
18671 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18672 +                       VXH_VXI_ARGS(e));
18673 +               break;
18674 +
18675 +       case VXH_LOC_VX_INFO:
18676 +       case VXH_LOOKUP_VX_INFO:
18677 +       case VXH_CREATE_VX_INFO:
18678 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18679 +                       VXH_LOC_ARGS(e),
18680 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18681 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18682 +                       e->ll.arg, VXH_VXI_ARGS(e));
18683 +               break;
18684 +       }
18685 +}
18686 +
18687 +static void __vxh_dump_history(void)
18688 +{
18689 +       unsigned int i, cpu;
18690 +
18691 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18692 +               atomic_read(&sequence), NR_CPUS);
18693 +
18694 +       for (i = 0; i < VXH_SIZE; i++) {
18695 +               for_each_online_cpu(cpu) {
18696 +                       struct _vx_history *hist =
18697 +                               &per_cpu(vx_history_buffer, cpu);
18698 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18699 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18700 +
18701 +                       vxh_dump_entry(entry, cpu);
18702 +               }
18703 +       }
18704 +}
18705 +
18706 +void   vxh_dump_history(void)
18707 +{
18708 +       vxh_active = 0;
18709 +#ifdef CONFIG_SMP
18710 +       local_irq_enable();
18711 +       smp_send_stop();
18712 +       local_irq_disable();
18713 +#endif
18714 +       __vxh_dump_history();
18715 +}
18716 +
18717 +
18718 +/* vserver syscall commands below here */
18719 +
18720 +
18721 +int vc_dump_history(uint32_t id)
18722 +{
18723 +       vxh_active = 0;
18724 +       __vxh_dump_history();
18725 +       vxh_active = 1;
18726 +
18727 +       return 0;
18728 +}
18729 +
18730 +
18731 +int do_read_history(struct __user _vx_hist_entry *data,
18732 +       int cpu, uint32_t *index, uint32_t *count)
18733 +{
18734 +       int pos, ret = 0;
18735 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18736 +       int end = hist->counter;
18737 +       int start = end - VXH_SIZE + 2;
18738 +       int idx = *index;
18739 +
18740 +       /* special case: get current pos */
18741 +       if (!*count) {
18742 +               *index = end;
18743 +               return 0;
18744 +       }
18745 +
18746 +       /* have we lost some data? */
18747 +       if (idx < start)
18748 +               idx = start;
18749 +
18750 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18751 +               struct _vx_hist_entry *entry =
18752 +                       &hist->entry[idx % VXH_SIZE];
18753 +
18754 +               /* send entry to userspace */
18755 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18756 +               if (ret)
18757 +                       break;
18758 +       }
18759 +       /* save new index and count */
18760 +       *index = idx;
18761 +       *count = pos;
18762 +       return ret ? ret : (*index < end);
18763 +}
18764 +
18765 +int vc_read_history(uint32_t id, void __user *data)
18766 +{
18767 +       struct vcmd_read_history_v0 vc_data;
18768 +       int ret;
18769 +
18770 +       if (id >= NR_CPUS)
18771 +               return -EINVAL;
18772 +
18773 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18774 +               return -EFAULT;
18775 +
18776 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18777 +               id, &vc_data.index, &vc_data.count);
18778 +
18779 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18780 +               return -EFAULT;
18781 +       return ret;
18782 +}
18783 +
18784 +#ifdef CONFIG_COMPAT
18785 +
18786 +int vc_read_history_x32(uint32_t id, void __user *data)
18787 +{
18788 +       struct vcmd_read_history_v0_x32 vc_data;
18789 +       int ret;
18790 +
18791 +       if (id >= NR_CPUS)
18792 +               return -EINVAL;
18793 +
18794 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18795 +               return -EFAULT;
18796 +
18797 +       ret = do_read_history((struct __user _vx_hist_entry *)
18798 +               compat_ptr(vc_data.data_ptr),
18799 +               id, &vc_data.index, &vc_data.count);
18800 +
18801 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18802 +               return -EFAULT;
18803 +       return ret;
18804 +}
18805 +
18806 +#endif /* CONFIG_COMPAT */
18807 +
18808 diff -NurpP --minimal linux-3.7/kernel/vserver/inet.c linux-3.7-vs2.3.5.1/kernel/vserver/inet.c
18809 --- linux-3.7/kernel/vserver/inet.c     1970-01-01 00:00:00.000000000 +0000
18810 +++ linux-3.7-vs2.3.5.1/kernel/vserver/inet.c   2012-12-11 15:56:33.000000000 +0000
18811 @@ -0,0 +1,226 @@
18812 +
18813 +#include <linux/in.h>
18814 +#include <linux/inetdevice.h>
18815 +#include <linux/export.h>
18816 +#include <linux/vs_inet.h>
18817 +#include <linux/vs_inet6.h>
18818 +#include <linux/vserver/debug.h>
18819 +#include <net/route.h>
18820 +#include <net/addrconf.h>
18821 +
18822 +
18823 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18824 +{
18825 +       int ret = 0;
18826 +
18827 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18828 +               ret = 1;
18829 +       else {
18830 +               struct nx_addr_v4 *ptr;
18831 +
18832 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18833 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18834 +                               ret = 1;
18835 +                               break;
18836 +                       }
18837 +               }
18838 +       }
18839 +
18840 +       vxdprintk(VXD_CBIT(net, 2),
18841 +               "nx_v4_addr_conflict(%p,%p): %d",
18842 +               nxi1, nxi2, ret);
18843 +
18844 +       return ret;
18845 +}
18846 +
18847 +
18848 +#ifdef CONFIG_IPV6
18849 +
18850 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18851 +{
18852 +       int ret = 0;
18853 +
18854 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18855 +               ret = 1;
18856 +       else {
18857 +               struct nx_addr_v6 *ptr;
18858 +
18859 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18860 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18861 +                               ret = 1;
18862 +                               break;
18863 +                       }
18864 +               }
18865 +       }
18866 +
18867 +       vxdprintk(VXD_CBIT(net, 2),
18868 +               "nx_v6_addr_conflict(%p,%p): %d",
18869 +               nxi1, nxi2, ret);
18870 +
18871 +       return ret;
18872 +}
18873 +
18874 +#endif
18875 +
18876 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18877 +{
18878 +       struct in_device *in_dev;
18879 +       struct in_ifaddr **ifap;
18880 +       struct in_ifaddr *ifa;
18881 +       int ret = 0;
18882 +
18883 +       if (!dev)
18884 +               goto out;
18885 +       in_dev = in_dev_get(dev);
18886 +       if (!in_dev)
18887 +               goto out;
18888 +
18889 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18890 +               ifap = &ifa->ifa_next) {
18891 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18892 +                       ret = 1;
18893 +                       break;
18894 +               }
18895 +       }
18896 +       in_dev_put(in_dev);
18897 +out:
18898 +       return ret;
18899 +}
18900 +
18901 +
18902 +#ifdef CONFIG_IPV6
18903 +
18904 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18905 +{
18906 +       struct inet6_dev *in_dev;
18907 +       struct inet6_ifaddr *ifa;
18908 +       int ret = 0;
18909 +
18910 +       if (!dev)
18911 +               goto out;
18912 +       in_dev = in6_dev_get(dev);
18913 +       if (!in_dev)
18914 +               goto out;
18915 +
18916 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18917 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18918 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18919 +                       ret = 1;
18920 +                       break;
18921 +               }
18922 +       }
18923 +       in6_dev_put(in_dev);
18924 +out:
18925 +       return ret;
18926 +}
18927 +
18928 +#endif
18929 +
18930 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18931 +{
18932 +       int ret = 1;
18933 +
18934 +       if (!nxi)
18935 +               goto out;
18936 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18937 +               goto out;
18938 +#ifdef CONFIG_IPV6
18939 +       ret = 2;
18940 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18941 +               goto out;
18942 +#endif
18943 +       ret = 0;
18944 +out:
18945 +       vxdprintk(VXD_CBIT(net, 3),
18946 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18947 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18948 +       return ret;
18949 +}
18950 +
18951 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18952 +       struct flowi4 *fl4)
18953 +{
18954 +       struct rtable *rt;
18955 +
18956 +       if (!nxi)
18957 +               return NULL;
18958 +
18959 +       /* FIXME: handle lback only case */
18960 +       if (!NX_IPV4(nxi))
18961 +               return ERR_PTR(-EPERM);
18962 +
18963 +       vxdprintk(VXD_CBIT(net, 4),
18964 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18965 +               nxi, nxi ? nxi->nx_id : 0,
18966 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18967 +
18968 +       /* single IP is unconditional */
18969 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18970 +               (fl4->saddr == INADDR_ANY))
18971 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18972 +
18973 +       if (fl4->saddr == INADDR_ANY) {
18974 +               struct nx_addr_v4 *ptr;
18975 +               __be32 found = 0;
18976 +
18977 +               rt = __ip_route_output_key(net, fl4);
18978 +               if (!IS_ERR(rt)) {
18979 +                       found = fl4->saddr;
18980 +                       ip_rt_put(rt);
18981 +                       vxdprintk(VXD_CBIT(net, 4),
18982 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18983 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18984 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18985 +                               goto found;
18986 +               }
18987 +
18988 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18989 +                       __be32 primary = ptr->ip[0].s_addr;
18990 +                       __be32 mask = ptr->mask.s_addr;
18991 +                       __be32 neta = primary & mask;
18992 +
18993 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18994 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18995 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18996 +                               NIPQUAD(mask), NIPQUAD(neta));
18997 +                       if ((found & mask) != neta)
18998 +                               continue;
18999 +
19000 +                       fl4->saddr = primary;
19001 +                       rt = __ip_route_output_key(net, fl4);
19002 +                       vxdprintk(VXD_CBIT(net, 4),
19003 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19004 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19005 +                       if (!IS_ERR(rt)) {
19006 +                               found = fl4->saddr;
19007 +                               ip_rt_put(rt);
19008 +                               if (found == primary)
19009 +                                       goto found;
19010 +                       }
19011 +               }
19012 +               /* still no source ip? */
19013 +               found = ipv4_is_loopback(fl4->daddr)
19014 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19015 +       found:
19016 +               /* assign src ip to flow */
19017 +               fl4->saddr = found;
19018 +
19019 +       } else {
19020 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19021 +                       return ERR_PTR(-EPERM);
19022 +       }
19023 +
19024 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19025 +               if (ipv4_is_loopback(fl4->daddr))
19026 +                       fl4->daddr = nxi->v4_lback.s_addr;
19027 +               if (ipv4_is_loopback(fl4->saddr))
19028 +                       fl4->saddr = nxi->v4_lback.s_addr;
19029 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19030 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19031 +               return ERR_PTR(-EPERM);
19032 +
19033 +       return NULL;
19034 +}
19035 +
19036 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19037 +
19038 diff -NurpP --minimal linux-3.7/kernel/vserver/init.c linux-3.7-vs2.3.5.1/kernel/vserver/init.c
19039 --- linux-3.7/kernel/vserver/init.c     1970-01-01 00:00:00.000000000 +0000
19040 +++ linux-3.7-vs2.3.5.1/kernel/vserver/init.c   2012-12-11 15:56:33.000000000 +0000
19041 @@ -0,0 +1,45 @@
19042 +/*
19043 + *  linux/kernel/init.c
19044 + *
19045 + *  Virtual Server Init
19046 + *
19047 + *  Copyright (C) 2004-2007  Herbert Pötzl
19048 + *
19049 + *  V0.01  basic structure
19050 + *
19051 + */
19052 +
19053 +#include <linux/init.h>
19054 +
19055 +int    vserver_register_sysctl(void);
19056 +void   vserver_unregister_sysctl(void);
19057 +
19058 +
19059 +static int __init init_vserver(void)
19060 +{
19061 +       int ret = 0;
19062 +
19063 +#ifdef CONFIG_VSERVER_DEBUG
19064 +       vserver_register_sysctl();
19065 +#endif
19066 +       return ret;
19067 +}
19068 +
19069 +
19070 +static void __exit exit_vserver(void)
19071 +{
19072 +
19073 +#ifdef CONFIG_VSERVER_DEBUG
19074 +       vserver_unregister_sysctl();
19075 +#endif
19076 +       return;
19077 +}
19078 +
19079 +/* FIXME: GFP_ZONETYPES gone
19080 +long vx_slab[GFP_ZONETYPES]; */
19081 +long vx_area;
19082 +
19083 +
19084 +module_init(init_vserver);
19085 +module_exit(exit_vserver);
19086 +
19087 diff -NurpP --minimal linux-3.7/kernel/vserver/inode.c linux-3.7-vs2.3.5.1/kernel/vserver/inode.c
19088 --- linux-3.7/kernel/vserver/inode.c    1970-01-01 00:00:00.000000000 +0000
19089 +++ linux-3.7-vs2.3.5.1/kernel/vserver/inode.c  2012-12-11 19:38:12.000000000 +0000
19090 @@ -0,0 +1,437 @@
19091 +/*
19092 + *  linux/kernel/vserver/inode.c
19093 + *
19094 + *  Virtual Server: File System Support
19095 + *
19096 + *  Copyright (C) 2004-2007  Herbert Pötzl
19097 + *
19098 + *  V0.01  separated from vcontext V0.05
19099 + *  V0.02  moved to tag (instead of xid)
19100 + *
19101 + */
19102 +
19103 +#include <linux/tty.h>
19104 +#include <linux/proc_fs.h>
19105 +#include <linux/devpts_fs.h>
19106 +#include <linux/fs.h>
19107 +#include <linux/file.h>
19108 +#include <linux/mount.h>
19109 +#include <linux/parser.h>
19110 +#include <linux/namei.h>
19111 +#include <linux/vserver/inode.h>
19112 +#include <linux/vserver/inode_cmd.h>
19113 +#include <linux/vs_base.h>
19114 +#include <linux/vs_tag.h>
19115 +
19116 +#include <asm/uaccess.h>
19117 +
19118 +
19119 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19120 +{
19121 +       struct proc_dir_entry *entry;
19122 +
19123 +       if (!in || !in->i_sb)
19124 +               return -ESRCH;
19125 +
19126 +       *flags = IATTR_TAG
19127 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19128 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19129 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19130 +               | (IS_COW(in) ? IATTR_COW : 0);
19131 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19132 +
19133 +       if (S_ISDIR(in->i_mode))
19134 +               *mask |= IATTR_BARRIER;
19135 +
19136 +       if (IS_TAGGED(in)) {
19137 +               *tag = i_tag_read(in);
19138 +               *mask |= IATTR_TAG;
19139 +       }
19140 +
19141 +       switch (in->i_sb->s_magic) {
19142 +       case PROC_SUPER_MAGIC:
19143 +               entry = PROC_I(in)->pde;
19144 +
19145 +               /* check for specific inodes? */
19146 +               if (entry)
19147 +                       *mask |= IATTR_FLAGS;
19148 +               if (entry)
19149 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19150 +               else
19151 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19152 +               break;
19153 +
19154 +       case DEVPTS_SUPER_MAGIC:
19155 +               *tag = i_tag_read(in);
19156 +               *mask |= IATTR_TAG;
19157 +               break;
19158 +
19159 +       default:
19160 +               break;
19161 +       }
19162 +       return 0;
19163 +}
19164 +
19165 +int vc_get_iattr(void __user *data)
19166 +{
19167 +       struct path path;
19168 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19169 +       int ret;
19170 +
19171 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19172 +               return -EFAULT;
19173 +
19174 +       ret = user_lpath(vc_data.name, &path);
19175 +       if (!ret) {
19176 +               ret = __vc_get_iattr(path.dentry->d_inode,
19177 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19178 +               path_put(&path);
19179 +       }
19180 +       if (ret)
19181 +               return ret;
19182 +
19183 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19184 +               ret = -EFAULT;
19185 +       return ret;
19186 +}
19187 +
19188 +#ifdef CONFIG_COMPAT
19189 +
19190 +int vc_get_iattr_x32(void __user *data)
19191 +{
19192 +       struct path path;
19193 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19194 +       int ret;
19195 +
19196 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19197 +               return -EFAULT;
19198 +
19199 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19200 +       if (!ret) {
19201 +               ret = __vc_get_iattr(path.dentry->d_inode,
19202 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19203 +               path_put(&path);
19204 +       }
19205 +       if (ret)
19206 +               return ret;
19207 +
19208 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19209 +               ret = -EFAULT;
19210 +       return ret;
19211 +}
19212 +
19213 +#endif /* CONFIG_COMPAT */
19214 +
19215 +
19216 +int vc_fget_iattr(uint32_t fd, void __user *data)
19217 +{
19218 +       struct file *filp;
19219 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19220 +       int ret;
19221 +
19222 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19223 +               return -EFAULT;
19224 +
19225 +       filp = fget(fd);
19226 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19227 +               return -EBADF;
19228 +
19229 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19230 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19231 +
19232 +       fput(filp);
19233 +
19234 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19235 +               ret = -EFAULT;
19236 +       return ret;
19237 +}
19238 +
19239 +
19240 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19241 +{
19242 +       struct inode *in = de->d_inode;
19243 +       int error = 0, is_proc = 0, has_tag = 0;
19244 +       struct iattr attr = { 0 };
19245 +
19246 +       if (!in || !in->i_sb)
19247 +               return -ESRCH;
19248 +
19249 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19250 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19251 +               return -EINVAL;
19252 +
19253 +       has_tag = IS_TAGGED(in) ||
19254 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19255 +       if ((*mask & IATTR_TAG) && !has_tag)
19256 +               return -EINVAL;
19257 +
19258 +       mutex_lock(&in->i_mutex);
19259 +       if (*mask & IATTR_TAG) {
19260 +               attr.ia_tag = *tag;
19261 +               attr.ia_valid |= ATTR_TAG;
19262 +       }
19263 +
19264 +       if (*mask & IATTR_FLAGS) {
19265 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19266 +               unsigned int iflags = PROC_I(in)->vx_flags;
19267 +
19268 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19269 +                       | (*flags & IATTR_FLAGS);
19270 +               PROC_I(in)->vx_flags = iflags;
19271 +               if (entry)
19272 +                       entry->vx_flags = iflags;
19273 +       }
19274 +
19275 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19276 +               IATTR_BARRIER | IATTR_COW)) {
19277 +               int iflags = in->i_flags;
19278 +               int vflags = in->i_vflags;
19279 +
19280 +               if (*mask & IATTR_IMMUTABLE) {
19281 +                       if (*flags & IATTR_IMMUTABLE)
19282 +                               iflags |= S_IMMUTABLE;
19283 +                       else
19284 +                               iflags &= ~S_IMMUTABLE;
19285 +               }
19286 +               if (*mask & IATTR_IXUNLINK) {
19287 +                       if (*flags & IATTR_IXUNLINK)
19288 +                               iflags |= S_IXUNLINK;
19289 +                       else
19290 +                               iflags &= ~S_IXUNLINK;
19291 +               }
19292 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19293 +                       if (*flags & IATTR_BARRIER)
19294 +                               vflags |= V_BARRIER;
19295 +                       else
19296 +                               vflags &= ~V_BARRIER;
19297 +               }
19298 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19299 +                       if (*flags & IATTR_COW)
19300 +                               vflags |= V_COW;
19301 +                       else
19302 +                               vflags &= ~V_COW;
19303 +               }
19304 +               if (in->i_op && in->i_op->sync_flags) {
19305 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19306 +                       if (error)
19307 +                               goto out;
19308 +               }
19309 +       }
19310 +
19311 +       if (attr.ia_valid) {
19312 +               if (in->i_op && in->i_op->setattr)
19313 +                       error = in->i_op->setattr(de, &attr);
19314 +               else {
19315 +                       error = inode_change_ok(in, &attr);
19316 +                       if (!error) {
19317 +                               setattr_copy(in, &attr);
19318 +                               mark_inode_dirty(in);
19319 +                       }
19320 +               }
19321 +       }
19322 +
19323 +out:
19324 +       mutex_unlock(&in->i_mutex);
19325 +       return error;
19326 +}
19327 +
19328 +int vc_set_iattr(void __user *data)
19329 +{
19330 +       struct path path;
19331 +       struct vcmd_ctx_iattr_v1 vc_data;
19332 +       int ret;
19333 +
19334 +       if (!capable(CAP_LINUX_IMMUTABLE))
19335 +               return -EPERM;
19336 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19337 +               return -EFAULT;
19338 +
19339 +       ret = user_lpath(vc_data.name, &path);
19340 +       if (!ret) {
19341 +               ret = __vc_set_iattr(path.dentry,
19342 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19343 +               path_put(&path);
19344 +       }
19345 +
19346 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19347 +               ret = -EFAULT;
19348 +       return ret;
19349 +}
19350 +
19351 +#ifdef CONFIG_COMPAT
19352 +
19353 +int vc_set_iattr_x32(void __user *data)
19354 +{
19355 +       struct path path;
19356 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19357 +       int ret;
19358 +
19359 +       if (!capable(CAP_LINUX_IMMUTABLE))
19360 +               return -EPERM;
19361 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19362 +               return -EFAULT;
19363 +
19364 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19365 +       if (!ret) {
19366 +               ret = __vc_set_iattr(path.dentry,
19367 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19368 +               path_put(&path);
19369 +       }
19370 +
19371 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19372 +               ret = -EFAULT;
19373 +       return ret;
19374 +}
19375 +
19376 +#endif /* CONFIG_COMPAT */
19377 +
19378 +int vc_fset_iattr(uint32_t fd, void __user *data)
19379 +{
19380 +       struct file *filp;
19381 +       struct vcmd_ctx_fiattr_v0 vc_data;
19382 +       int ret;
19383 +
19384 +       if (!capable(CAP_LINUX_IMMUTABLE))
19385 +               return -EPERM;
19386 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19387 +               return -EFAULT;
19388 +
19389 +       filp = fget(fd);
19390 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19391 +               return -EBADF;
19392 +
19393 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19394 +               &vc_data.flags, &vc_data.mask);
19395 +
19396 +       fput(filp);
19397 +
19398 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19399 +               return -EFAULT;
19400 +       return ret;
19401 +}
19402 +
19403 +
19404 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19405 +
19406 +static match_table_t tokens = {
19407 +       {Opt_notagcheck, "notagcheck"},
19408 +#ifdef CONFIG_PROPAGATE
19409 +       {Opt_notag, "notag"},
19410 +       {Opt_tag, "tag"},
19411 +       {Opt_tagid, "tagid=%u"},
19412 +#endif
19413 +       {Opt_err, NULL}
19414 +};
19415 +
19416 +
19417 +static void __dx_parse_remove(char *string, char *opt)
19418 +{
19419 +       char *p = strstr(string, opt);
19420 +       char *q = p;
19421 +
19422 +       if (p) {
19423 +               while (*q != '\0' && *q != ',')
19424 +                       q++;
19425 +               while (*q)
19426 +                       *p++ = *q++;
19427 +               while (*p)
19428 +                       *p++ = '\0';
19429 +       }
19430 +}
19431 +
19432 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19433 +                unsigned long *flags)
19434 +{
19435 +       int set = 0;
19436 +       substring_t args[MAX_OPT_ARGS];
19437 +       int token;
19438 +       char *s, *p, *opts;
19439 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19440 +       int option = 0;
19441 +#endif
19442 +
19443 +       if (!string)
19444 +               return 0;
19445 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19446 +       if (!s)
19447 +               return 0;
19448 +
19449 +       opts = s;
19450 +       while ((p = strsep(&opts, ",")) != NULL) {
19451 +               token = match_token(p, tokens, args);
19452 +
19453 +               switch (token) {
19454 +#ifdef CONFIG_PROPAGATE
19455 +               case Opt_tag:
19456 +                       if (tag)
19457 +                               *tag = 0;
19458 +                       if (remove)
19459 +                               __dx_parse_remove(s, "tag");
19460 +                       *mnt_flags |= MNT_TAGID;
19461 +                       set |= MNT_TAGID;
19462 +                       break;
19463 +               case Opt_notag:
19464 +                       if (remove)
19465 +                               __dx_parse_remove(s, "notag");
19466 +                       *mnt_flags |= MNT_NOTAG;
19467 +                       set |= MNT_NOTAG;
19468 +                       break;
19469 +               case Opt_tagid:
19470 +                       if (tag && !match_int(args, &option))
19471 +                               *tag = option;
19472 +                       if (remove)
19473 +                               __dx_parse_remove(s, "tagid");
19474 +                       *mnt_flags |= MNT_TAGID;
19475 +                       set |= MNT_TAGID;
19476 +                       break;
19477 +#endif /* CONFIG_PROPAGATE */
19478 +               case Opt_notagcheck:
19479 +                       if (remove)
19480 +                               __dx_parse_remove(s, "notagcheck");
19481 +                       *flags |= MS_NOTAGCHECK;
19482 +                       set |= MS_NOTAGCHECK;
19483 +                       break;
19484 +               }
19485 +               vxdprintk(VXD_CBIT(tag, 7),
19486 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19487 +                       p, token, option);
19488 +       }
19489 +       if (set)
19490 +               strcpy(string, s);
19491 +       kfree(s);
19492 +       return set;
19493 +}
19494 +
19495 +#ifdef CONFIG_PROPAGATE
19496 +
19497 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19498 +{
19499 +       tag_t new_tag = 0;
19500 +       struct vfsmount *mnt;
19501 +       int propagate;
19502 +
19503 +       if (!nd)
19504 +               return;
19505 +       mnt = nd->path.mnt;
19506 +       if (!mnt)
19507 +               return;
19508 +
19509 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19510 +       if (propagate)
19511 +               new_tag = mnt->mnt_tag;
19512 +
19513 +       vxdprintk(VXD_CBIT(tag, 7),
19514 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19515 +               inode, inode->i_ino, inode->i_tag,
19516 +               new_tag, (propagate) ? 1 : 0);
19517 +
19518 +       if (propagate)
19519 +               i_tag_write(inode, new_tag);
19520 +}
19521 +
19522 +#include <linux/module.h>
19523 +
19524 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19525 +
19526 +#endif /* CONFIG_PROPAGATE */
19527 +
19528 diff -NurpP --minimal linux-3.7/kernel/vserver/limit.c linux-3.7-vs2.3.5.1/kernel/vserver/limit.c
19529 --- linux-3.7/kernel/vserver/limit.c    1970-01-01 00:00:00.000000000 +0000
19530 +++ linux-3.7-vs2.3.5.1/kernel/vserver/limit.c  2012-12-12 13:08:45.000000000 +0000
19531 @@ -0,0 +1,345 @@
19532 +/*
19533 + *  linux/kernel/vserver/limit.c
19534 + *
19535 + *  Virtual Server: Context Limits
19536 + *
19537 + *  Copyright (C) 2004-2010  Herbert Pötzl
19538 + *
19539 + *  V0.01  broken out from vcontext V0.05
19540 + *  V0.02  changed vcmds to vxi arg
19541 + *  V0.03  added memory cgroup support
19542 + *
19543 + */
19544 +
19545 +#include <linux/sched.h>
19546 +#include <linux/module.h>
19547 +#include <linux/memcontrol.h>
19548 +#include <linux/res_counter.h>
19549 +#include <linux/vs_limit.h>
19550 +#include <linux/vserver/limit.h>
19551 +#include <linux/vserver/limit_cmd.h>
19552 +
19553 +#include <asm/uaccess.h>
19554 +
19555 +
19556 +const char *vlimit_name[NUM_LIMITS] = {
19557 +       [RLIMIT_CPU]            = "CPU",
19558 +       [RLIMIT_NPROC]          = "NPROC",
19559 +       [RLIMIT_NOFILE]         = "NOFILE",
19560 +       [RLIMIT_LOCKS]          = "LOCKS",
19561 +       [RLIMIT_SIGPENDING]     = "SIGP",
19562 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19563 +
19564 +       [VLIMIT_NSOCK]          = "NSOCK",
19565 +       [VLIMIT_OPENFD]         = "OPENFD",
19566 +       [VLIMIT_SHMEM]          = "SHMEM",
19567 +       [VLIMIT_DENTRY]         = "DENTRY",
19568 +};
19569 +
19570 +EXPORT_SYMBOL_GPL(vlimit_name);
19571 +
19572 +#define MASK_ENTRY(x)  (1 << (x))
19573 +
19574 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19575 +               /* minimum */
19576 +       0
19577 +       ,       /* softlimit */
19578 +       0
19579 +       ,       /* maximum */
19580 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19581 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19582 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19583 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19584 +
19585 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19586 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19587 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19588 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19589 +       0
19590 +};
19591 +               /* accounting only */
19592 +uint32_t account_mask =
19593 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19594 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19595 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19596 +       0;
19597 +
19598 +
19599 +static int is_valid_vlimit(int id)
19600 +{
19601 +       uint32_t mask = vlimit_mask.minimum |
19602 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19603 +       return mask & (1 << id);
19604 +}
19605 +
19606 +static int is_accounted_vlimit(int id)
19607 +{
19608 +       if (is_valid_vlimit(id))
19609 +               return 1;
19610 +       return account_mask & (1 << id);
19611 +}
19612 +
19613 +
19614 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19615 +{
19616 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19617 +       return VX_VLIM(limit);
19618 +}
19619 +
19620 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19621 +{
19622 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19623 +       return VX_VLIM(limit);
19624 +}
19625 +
19626 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19627 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19628 +{
19629 +       if (!is_valid_vlimit(id))
19630 +               return -EINVAL;
19631 +
19632 +       if (minimum)
19633 +               *minimum = CRLIM_UNSET;
19634 +       if (softlimit)
19635 +               *softlimit = vc_get_soft(vxi, id);
19636 +       if (maximum)
19637 +               *maximum = vc_get_hard(vxi, id);
19638 +       return 0;
19639 +}
19640 +
19641 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19642 +{
19643 +       struct vcmd_ctx_rlimit_v0 vc_data;
19644 +       int ret;
19645 +
19646 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19647 +               return -EFAULT;
19648 +
19649 +       ret = do_get_rlimit(vxi, vc_data.id,
19650 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19651 +       if (ret)
19652 +               return ret;
19653 +
19654 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19655 +               return -EFAULT;
19656 +       return 0;
19657 +}
19658 +
19659 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19660 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19661 +{
19662 +       if (!is_valid_vlimit(id))
19663 +               return -EINVAL;
19664 +
19665 +       if (maximum != CRLIM_KEEP)
19666 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19667 +       if (softlimit != CRLIM_KEEP)
19668 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19669 +
19670 +       /* clamp soft limit */
19671 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19672 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19673 +
19674 +       return 0;
19675 +}
19676 +
19677 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19678 +{
19679 +       struct vcmd_ctx_rlimit_v0 vc_data;
19680 +
19681 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19682 +               return -EFAULT;
19683 +
19684 +       return do_set_rlimit(vxi, vc_data.id,
19685 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19686 +}
19687 +
19688 +#ifdef CONFIG_IA32_EMULATION
19689 +
19690 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19691 +{
19692 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19693 +
19694 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19695 +               return -EFAULT;
19696 +
19697 +       return do_set_rlimit(vxi, vc_data.id,
19698 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19699 +}
19700 +
19701 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19702 +{
19703 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19704 +       int ret;
19705 +
19706 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19707 +               return -EFAULT;
19708 +
19709 +       ret = do_get_rlimit(vxi, vc_data.id,
19710 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19711 +       if (ret)
19712 +               return ret;
19713 +
19714 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19715 +               return -EFAULT;
19716 +       return 0;
19717 +}
19718 +
19719 +#endif /* CONFIG_IA32_EMULATION */
19720 +
19721 +
19722 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19723 +{
19724 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19725 +               return -EFAULT;
19726 +       return 0;
19727 +}
19728 +
19729 +
19730 +static inline void vx_reset_hits(struct _vx_limit *limit)
19731 +{
19732 +       int lim;
19733 +
19734 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19735 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19736 +       }
19737 +}
19738 +
19739 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19740 +{
19741 +       vx_reset_hits(&vxi->limit);
19742 +       return 0;
19743 +}
19744 +
19745 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19746 +{
19747 +       rlim_t value;
19748 +       int lim;
19749 +
19750 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19751 +               value = __rlim_get(limit, lim);
19752 +               __rlim_rmax(limit, lim) = value;
19753 +               __rlim_rmin(limit, lim) = value;
19754 +       }
19755 +}
19756 +
19757 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19758 +{
19759 +       vx_reset_minmax(&vxi->limit);
19760 +       return 0;
19761 +}
19762 +
19763 +
19764 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19765 +{
19766 +       struct vcmd_rlimit_stat_v0 vc_data;
19767 +       struct _vx_limit *limit = &vxi->limit;
19768 +       int id;
19769 +
19770 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19771 +               return -EFAULT;
19772 +
19773 +       id = vc_data.id;
19774 +       if (!is_accounted_vlimit(id))
19775 +               return -EINVAL;
19776 +
19777 +       vx_limit_fixup(limit, id);
19778 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19779 +       vc_data.value = __rlim_get(limit, id);
19780 +       vc_data.minimum = __rlim_rmin(limit, id);
19781 +       vc_data.maximum = __rlim_rmax(limit, id);
19782 +
19783 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19784 +               return -EFAULT;
19785 +       return 0;
19786 +}
19787 +
19788 +
19789 +void vx_vsi_meminfo(struct sysinfo *val)
19790 +{
19791 +#ifdef CONFIG_MEMCG
19792 +       struct mem_cgroup *mcg;
19793 +       u64 res_limit, res_usage;
19794 +
19795 +       rcu_read_lock();
19796 +       mcg = mem_cgroup_from_task(current);
19797 +       rcu_read_unlock();
19798 +       if (!mcg)
19799 +               goto out;
19800 +
19801 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19802 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19803 +
19804 +       if (res_limit != RESOURCE_MAX)
19805 +               val->totalram = (res_limit >> PAGE_SHIFT);
19806 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19807 +       val->bufferram = 0;
19808 +       val->totalhigh = 0;
19809 +       val->freehigh = 0;
19810 +out:
19811 +#endif /* CONFIG_MEMCG */
19812 +       return;
19813 +}
19814 +
19815 +void vx_vsi_swapinfo(struct sysinfo *val)
19816 +{
19817 +#ifdef CONFIG_MEMCG
19818 +#ifdef CONFIG_MEMCG_SWAP
19819 +       struct mem_cgroup *mcg;
19820 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19821 +       s64 swap_limit, swap_usage;
19822 +
19823 +       rcu_read_lock();
19824 +       mcg = mem_cgroup_from_task(current);
19825 +       rcu_read_unlock();
19826 +       if (!mcg)
19827 +               goto out;
19828 +
19829 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19830 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19831 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19832 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19833 +
19834 +       /* memory unlimited */
19835 +       if (res_limit == RESOURCE_MAX)
19836 +               goto out;
19837 +
19838 +       swap_limit = memsw_limit - res_limit;
19839 +       /* we have a swap limit? */
19840 +       if (memsw_limit != RESOURCE_MAX)
19841 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19842 +
19843 +       /* calculate swap part */
19844 +       swap_usage = (memsw_usage > res_usage) ?
19845 +               memsw_usage - res_usage : 0;
19846 +
19847 +       /* total shown minus usage gives free swap */
19848 +       val->freeswap = (swap_usage < swap_limit) ?
19849 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19850 +out:
19851 +#else  /* !CONFIG_MEMCG_SWAP */
19852 +       val->totalswap = 0;
19853 +       val->freeswap = 0;
19854 +#endif /* !CONFIG_MEMCG_SWAP */
19855 +#endif /* CONFIG_MEMCG */
19856 +       return;
19857 +}
19858 +
19859 +long vx_vsi_cached(struct sysinfo *val)
19860 +{
19861 +       long cache = 0;
19862 +#ifdef CONFIG_MEMCG
19863 +       struct mem_cgroup *mcg;
19864 +
19865 +       rcu_read_lock();
19866 +       mcg = mem_cgroup_from_task(current);
19867 +       rcu_read_unlock();
19868 +       if (!mcg)
19869 +               goto out;
19870 +
19871 +       cache = mem_cgroup_stat_read_cache(mcg);
19872 +out:
19873 +#endif
19874 +       return cache;
19875 +}
19876 +
19877 diff -NurpP --minimal linux-3.7/kernel/vserver/limit_init.h linux-3.7-vs2.3.5.1/kernel/vserver/limit_init.h
19878 --- linux-3.7/kernel/vserver/limit_init.h       1970-01-01 00:00:00.000000000 +0000
19879 +++ linux-3.7-vs2.3.5.1/kernel/vserver/limit_init.h     2012-12-11 15:56:33.000000000 +0000
19880 @@ -0,0 +1,31 @@
19881 +
19882 +
19883 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19884 +{
19885 +       int lim;
19886 +
19887 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19888 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19889 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19890 +               __rlim_set(limit, lim, 0);
19891 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19892 +               __rlim_rmin(limit, lim) = 0;
19893 +               __rlim_rmax(limit, lim) = 0;
19894 +       }
19895 +}
19896 +
19897 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19898 +{
19899 +       rlim_t value;
19900 +       int lim;
19901 +
19902 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19903 +               if ((1 << lim) & VLIM_NOCHECK)
19904 +                       continue;
19905 +               value = __rlim_get(limit, lim);
19906 +               vxwprintk_xid(value,
19907 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19908 +                       limit, vlimit_name[lim], lim, (long)value);
19909 +       }
19910 +}
19911 +
19912 diff -NurpP --minimal linux-3.7/kernel/vserver/limit_proc.h linux-3.7-vs2.3.5.1/kernel/vserver/limit_proc.h
19913 --- linux-3.7/kernel/vserver/limit_proc.h       1970-01-01 00:00:00.000000000 +0000
19914 +++ linux-3.7-vs2.3.5.1/kernel/vserver/limit_proc.h     2012-12-11 15:56:33.000000000 +0000
19915 @@ -0,0 +1,57 @@
19916 +#ifndef _VX_LIMIT_PROC_H
19917 +#define _VX_LIMIT_PROC_H
19918 +
19919 +#include <linux/vserver/limit_int.h>
19920 +
19921 +
19922 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19923 +#define VX_LIMIT_TOP   \
19924 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19925 +
19926 +#define VX_LIMIT_ARG(r)                                \
19927 +       (unsigned long)__rlim_get(limit, r),    \
19928 +       (unsigned long)__rlim_rmin(limit, r),   \
19929 +       (unsigned long)__rlim_rmax(limit, r),   \
19930 +       VX_VLIM(__rlim_soft(limit, r)),         \
19931 +       VX_VLIM(__rlim_hard(limit, r)),         \
19932 +       atomic_read(&__rlim_lhit(limit, r))
19933 +
19934 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19935 +{
19936 +       vx_limit_fixup(limit, -1);
19937 +       return sprintf(buffer, VX_LIMIT_TOP
19938 +               "PROC"  VX_LIMIT_FMT
19939 +               "VM"    VX_LIMIT_FMT
19940 +               "VML"   VX_LIMIT_FMT
19941 +               "RSS"   VX_LIMIT_FMT
19942 +               "ANON"  VX_LIMIT_FMT
19943 +               "RMAP"  VX_LIMIT_FMT
19944 +               "FILES" VX_LIMIT_FMT
19945 +               "OFD"   VX_LIMIT_FMT
19946 +               "LOCKS" VX_LIMIT_FMT
19947 +               "SOCK"  VX_LIMIT_FMT
19948 +               "MSGQ"  VX_LIMIT_FMT
19949 +               "SHM"   VX_LIMIT_FMT
19950 +               "SEMA"  VX_LIMIT_FMT
19951 +               "SEMS"  VX_LIMIT_FMT
19952 +               "DENT"  VX_LIMIT_FMT,
19953 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19954 +               VX_LIMIT_ARG(RLIMIT_AS),
19955 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19956 +               VX_LIMIT_ARG(RLIMIT_RSS),
19957 +               VX_LIMIT_ARG(VLIMIT_ANON),
19958 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19959 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19960 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19961 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19962 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19963 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19964 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19965 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19966 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19967 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19968 +}
19969 +
19970 +#endif /* _VX_LIMIT_PROC_H */
19971 +
19972 +
19973 diff -NurpP --minimal linux-3.7/kernel/vserver/network.c linux-3.7-vs2.3.5.1/kernel/vserver/network.c
19974 --- linux-3.7/kernel/vserver/network.c  1970-01-01 00:00:00.000000000 +0000
19975 +++ linux-3.7-vs2.3.5.1/kernel/vserver/network.c        2012-12-11 15:56:33.000000000 +0000
19976 @@ -0,0 +1,912 @@
19977 +/*
19978 + *  linux/kernel/vserver/network.c
19979 + *
19980 + *  Virtual Server: Network Support
19981 + *
19982 + *  Copyright (C) 2003-2007  Herbert Pötzl
19983 + *
19984 + *  V0.01  broken out from vcontext V0.05
19985 + *  V0.02  cleaned up implementation
19986 + *  V0.03  added equiv nx commands
19987 + *  V0.04  switch to RCU based hash
19988 + *  V0.05  and back to locking again
19989 + *  V0.06  changed vcmds to nxi arg
19990 + *  V0.07  have __create claim() the nxi
19991 + *
19992 + */
19993 +
19994 +#include <linux/err.h>
19995 +#include <linux/slab.h>
19996 +#include <linux/rcupdate.h>
19997 +
19998 +#include <linux/vs_network.h>
19999 +#include <linux/vs_pid.h>
20000 +#include <linux/vserver/network_cmd.h>
20001 +
20002 +
20003 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20004 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20005 +
20006 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20007 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20008 +
20009 +
20010 +static int __init init_network(void)
20011 +{
20012 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20013 +               sizeof(struct nx_addr_v4), 0,
20014 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20015 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20016 +               sizeof(struct nx_addr_v6), 0,
20017 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20018 +       return 0;
20019 +}
20020 +
20021 +
20022 +/*     __alloc_nx_addr_v4()                                    */
20023 +
20024 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20025 +{
20026 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20027 +               nx_addr_v4_cachep, GFP_KERNEL);
20028 +
20029 +       if (!IS_ERR(nxa))
20030 +               memset(nxa, 0, sizeof(*nxa));
20031 +       return nxa;
20032 +}
20033 +
20034 +/*     __dealloc_nx_addr_v4()                                  */
20035 +
20036 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20037 +{
20038 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20039 +}
20040 +
20041 +/*     __dealloc_nx_addr_v4_all()                              */
20042 +
20043 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20044 +{
20045 +       while (nxa) {
20046 +               struct nx_addr_v4 *next = nxa->next;
20047 +
20048 +               __dealloc_nx_addr_v4(nxa);
20049 +               nxa = next;
20050 +       }
20051 +}
20052 +
20053 +
20054 +#ifdef CONFIG_IPV6
20055 +
20056 +/*     __alloc_nx_addr_v6()                                    */
20057 +
20058 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20059 +{
20060 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20061 +               nx_addr_v6_cachep, GFP_KERNEL);
20062 +
20063 +       if (!IS_ERR(nxa))
20064 +               memset(nxa, 0, sizeof(*nxa));
20065 +       return nxa;
20066 +}
20067 +
20068 +/*     __dealloc_nx_addr_v6()                                  */
20069 +
20070 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20071 +{
20072 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20073 +}
20074 +
20075 +/*     __dealloc_nx_addr_v6_all()                              */
20076 +
20077 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20078 +{
20079 +       while (nxa) {
20080 +               struct nx_addr_v6 *next = nxa->next;
20081 +
20082 +               __dealloc_nx_addr_v6(nxa);
20083 +               nxa = next;
20084 +       }
20085 +}
20086 +
20087 +#endif /* CONFIG_IPV6 */
20088 +
20089 +/*     __alloc_nx_info()
20090 +
20091 +       * allocate an initialized nx_info struct
20092 +       * doesn't make it visible (hash)                        */
20093 +
20094 +static struct nx_info *__alloc_nx_info(nid_t nid)
20095 +{
20096 +       struct nx_info *new = NULL;
20097 +
20098 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20099 +
20100 +       /* would this benefit from a slab cache? */
20101 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20102 +       if (!new)
20103 +               return 0;
20104 +
20105 +       memset(new, 0, sizeof(struct nx_info));
20106 +       new->nx_id = nid;
20107 +       INIT_HLIST_NODE(&new->nx_hlist);
20108 +       atomic_set(&new->nx_usecnt, 0);
20109 +       atomic_set(&new->nx_tasks, 0);
20110 +       new->nx_state = 0;
20111 +
20112 +       new->nx_flags = NXF_INIT_SET;
20113 +
20114 +       /* rest of init goes here */
20115 +
20116 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20117 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20118 +
20119 +       vxdprintk(VXD_CBIT(nid, 0),
20120 +               "alloc_nx_info(%d) = %p", nid, new);
20121 +       atomic_inc(&nx_global_ctotal);
20122 +       return new;
20123 +}
20124 +
20125 +/*     __dealloc_nx_info()
20126 +
20127 +       * final disposal of nx_info                             */
20128 +
20129 +static void __dealloc_nx_info(struct nx_info *nxi)
20130 +{
20131 +       vxdprintk(VXD_CBIT(nid, 0),
20132 +               "dealloc_nx_info(%p)", nxi);
20133 +
20134 +       nxi->nx_hlist.next = LIST_POISON1;
20135 +       nxi->nx_id = -1;
20136 +
20137 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20138 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20139 +
20140 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20141 +
20142 +       nxi->nx_state |= NXS_RELEASED;
20143 +       kfree(nxi);
20144 +       atomic_dec(&nx_global_ctotal);
20145 +}
20146 +
20147 +static void __shutdown_nx_info(struct nx_info *nxi)
20148 +{
20149 +       nxi->nx_state |= NXS_SHUTDOWN;
20150 +       vs_net_change(nxi, VSC_NETDOWN);
20151 +}
20152 +
20153 +/*     exported stuff                                          */
20154 +
20155 +void free_nx_info(struct nx_info *nxi)
20156 +{
20157 +       /* context shutdown is mandatory */
20158 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20159 +
20160 +       /* context must not be hashed */
20161 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20162 +
20163 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20164 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20165 +
20166 +       __dealloc_nx_info(nxi);
20167 +}
20168 +
20169 +
20170 +void __nx_set_lback(struct nx_info *nxi)
20171 +{
20172 +       int nid = nxi->nx_id;
20173 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20174 +
20175 +       nxi->v4_lback.s_addr = lback;
20176 +}
20177 +
20178 +extern int __nx_inet_add_lback(__be32 addr);
20179 +extern int __nx_inet_del_lback(__be32 addr);
20180 +
20181 +
20182 +/*     hash table for nx_info hash */
20183 +
20184 +#define NX_HASH_SIZE   13
20185 +
20186 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20187 +
20188 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20189 +
20190 +
20191 +static inline unsigned int __hashval(nid_t nid)
20192 +{
20193 +       return (nid % NX_HASH_SIZE);
20194 +}
20195 +
20196 +
20197 +
20198 +/*     __hash_nx_info()
20199 +
20200 +       * add the nxi to the global hash table
20201 +       * requires the hash_lock to be held                     */
20202 +
20203 +static inline void __hash_nx_info(struct nx_info *nxi)
20204 +{
20205 +       struct hlist_head *head;
20206 +
20207 +       vxd_assert_lock(&nx_info_hash_lock);
20208 +       vxdprintk(VXD_CBIT(nid, 4),
20209 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20210 +
20211 +       /* context must not be hashed */
20212 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20213 +
20214 +       nxi->nx_state |= NXS_HASHED;
20215 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20216 +       hlist_add_head(&nxi->nx_hlist, head);
20217 +       atomic_inc(&nx_global_cactive);
20218 +}
20219 +
20220 +/*     __unhash_nx_info()
20221 +
20222 +       * remove the nxi from the global hash table
20223 +       * requires the hash_lock to be held                     */
20224 +
20225 +static inline void __unhash_nx_info(struct nx_info *nxi)
20226 +{
20227 +       vxd_assert_lock(&nx_info_hash_lock);
20228 +       vxdprintk(VXD_CBIT(nid, 4),
20229 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20230 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20231 +
20232 +       /* context must be hashed */
20233 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20234 +       /* but without tasks */
20235 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20236 +
20237 +       nxi->nx_state &= ~NXS_HASHED;
20238 +       hlist_del(&nxi->nx_hlist);
20239 +       atomic_dec(&nx_global_cactive);
20240 +}
20241 +
20242 +
20243 +/*     __lookup_nx_info()
20244 +
20245 +       * requires the hash_lock to be held
20246 +       * doesn't increment the nx_refcnt                       */
20247 +
20248 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20249 +{
20250 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20251 +       struct hlist_node *pos;
20252 +       struct nx_info *nxi;
20253 +
20254 +       vxd_assert_lock(&nx_info_hash_lock);
20255 +       hlist_for_each(pos, head) {
20256 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20257 +
20258 +               if (nxi->nx_id == nid)
20259 +                       goto found;
20260 +       }
20261 +       nxi = NULL;
20262 +found:
20263 +       vxdprintk(VXD_CBIT(nid, 0),
20264 +               "__lookup_nx_info(#%u): %p[#%u]",
20265 +               nid, nxi, nxi ? nxi->nx_id : 0);
20266 +       return nxi;
20267 +}
20268 +
20269 +
20270 +/*     __create_nx_info()
20271 +
20272 +       * create the requested context
20273 +       * get(), claim() and hash it                            */
20274 +
20275 +static struct nx_info *__create_nx_info(int id)
20276 +{
20277 +       struct nx_info *new, *nxi = NULL;
20278 +
20279 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20280 +
20281 +       if (!(new = __alloc_nx_info(id)))
20282 +               return ERR_PTR(-ENOMEM);
20283 +
20284 +       /* required to make dynamic xids unique */
20285 +       spin_lock(&nx_info_hash_lock);
20286 +
20287 +       /* static context requested */
20288 +       if ((nxi = __lookup_nx_info(id))) {
20289 +               vxdprintk(VXD_CBIT(nid, 0),
20290 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20291 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20292 +                       nxi = ERR_PTR(-EBUSY);
20293 +               else
20294 +                       nxi = ERR_PTR(-EEXIST);
20295 +               goto out_unlock;
20296 +       }
20297 +       /* new context */
20298 +       vxdprintk(VXD_CBIT(nid, 0),
20299 +               "create_nx_info(%d) = %p (new)", id, new);
20300 +       claim_nx_info(new, NULL);
20301 +       __nx_set_lback(new);
20302 +       __hash_nx_info(get_nx_info(new));
20303 +       nxi = new, new = NULL;
20304 +
20305 +out_unlock:
20306 +       spin_unlock(&nx_info_hash_lock);
20307 +       if (new)
20308 +               __dealloc_nx_info(new);
20309 +       return nxi;
20310 +}
20311 +
20312 +
20313 +
20314 +/*     exported stuff                                          */
20315 +
20316 +
20317 +void unhash_nx_info(struct nx_info *nxi)
20318 +{
20319 +       __shutdown_nx_info(nxi);
20320 +       spin_lock(&nx_info_hash_lock);
20321 +       __unhash_nx_info(nxi);
20322 +       spin_unlock(&nx_info_hash_lock);
20323 +}
20324 +
20325 +/*     lookup_nx_info()
20326 +
20327 +       * search for a nx_info and get() it
20328 +       * negative id means current                             */
20329 +
20330 +struct nx_info *lookup_nx_info(int id)
20331 +{
20332 +       struct nx_info *nxi = NULL;
20333 +
20334 +       if (id < 0) {
20335 +               nxi = get_nx_info(current_nx_info());
20336 +       } else if (id > 1) {
20337 +               spin_lock(&nx_info_hash_lock);
20338 +               nxi = get_nx_info(__lookup_nx_info(id));
20339 +               spin_unlock(&nx_info_hash_lock);
20340 +       }
20341 +       return nxi;
20342 +}
20343 +
20344 +/*     nid_is_hashed()
20345 +
20346 +       * verify that nid is still hashed                       */
20347 +
20348 +int nid_is_hashed(nid_t nid)
20349 +{
20350 +       int hashed;
20351 +
20352 +       spin_lock(&nx_info_hash_lock);
20353 +       hashed = (__lookup_nx_info(nid) != NULL);
20354 +       spin_unlock(&nx_info_hash_lock);
20355 +       return hashed;
20356 +}
20357 +
20358 +
20359 +#ifdef CONFIG_PROC_FS
20360 +
20361 +/*     get_nid_list()
20362 +
20363 +       * get a subset of hashed nids for proc
20364 +       * assumes size is at least one                          */
20365 +
20366 +int get_nid_list(int index, unsigned int *nids, int size)
20367 +{
20368 +       int hindex, nr_nids = 0;
20369 +
20370 +       /* only show current and children */
20371 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20372 +               if (index > 0)
20373 +                       return 0;
20374 +               nids[nr_nids] = nx_current_nid();
20375 +               return 1;
20376 +       }
20377 +
20378 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20379 +               struct hlist_head *head = &nx_info_hash[hindex];
20380 +               struct hlist_node *pos;
20381 +
20382 +               spin_lock(&nx_info_hash_lock);
20383 +               hlist_for_each(pos, head) {
20384 +                       struct nx_info *nxi;
20385 +
20386 +                       if (--index > 0)
20387 +                               continue;
20388 +
20389 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20390 +                       nids[nr_nids] = nxi->nx_id;
20391 +                       if (++nr_nids >= size) {
20392 +                               spin_unlock(&nx_info_hash_lock);
20393 +                               goto out;
20394 +                       }
20395 +               }
20396 +               /* keep the lock time short */
20397 +               spin_unlock(&nx_info_hash_lock);
20398 +       }
20399 +out:
20400 +       return nr_nids;
20401 +}
20402 +#endif
20403 +
20404 +
20405 +/*
20406 + *     migrate task to new network
20407 + *     gets nxi, puts old_nxi on change
20408 + */
20409 +
20410 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20411 +{
20412 +       struct nx_info *old_nxi;
20413 +       int ret = 0;
20414 +
20415 +       if (!p || !nxi)
20416 +               BUG();
20417 +
20418 +       vxdprintk(VXD_CBIT(nid, 5),
20419 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20420 +               p, nxi, nxi->nx_id,
20421 +               atomic_read(&nxi->nx_usecnt),
20422 +               atomic_read(&nxi->nx_tasks));
20423 +
20424 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20425 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20426 +               return -EACCES;
20427 +
20428 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20429 +               return -EFAULT;
20430 +
20431 +       /* maybe disallow this completely? */
20432 +       old_nxi = task_get_nx_info(p);
20433 +       if (old_nxi == nxi)
20434 +               goto out;
20435 +
20436 +       task_lock(p);
20437 +       if (old_nxi)
20438 +               clr_nx_info(&p->nx_info);
20439 +       claim_nx_info(nxi, p);
20440 +       set_nx_info(&p->nx_info, nxi);
20441 +       p->nid = nxi->nx_id;
20442 +       task_unlock(p);
20443 +
20444 +       vxdprintk(VXD_CBIT(nid, 5),
20445 +               "moved task %p into nxi:%p[#%d]",
20446 +               p, nxi, nxi->nx_id);
20447 +
20448 +       if (old_nxi)
20449 +               release_nx_info(old_nxi, p);
20450 +       ret = 0;
20451 +out:
20452 +       put_nx_info(old_nxi);
20453 +       return ret;
20454 +}
20455 +
20456 +
20457 +void nx_set_persistent(struct nx_info *nxi)
20458 +{
20459 +       vxdprintk(VXD_CBIT(nid, 6),
20460 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20461 +
20462 +       get_nx_info(nxi);
20463 +       claim_nx_info(nxi, NULL);
20464 +}
20465 +
20466 +void nx_clear_persistent(struct nx_info *nxi)
20467 +{
20468 +       vxdprintk(VXD_CBIT(nid, 6),
20469 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20470 +
20471 +       release_nx_info(nxi, NULL);
20472 +       put_nx_info(nxi);
20473 +}
20474 +
20475 +void nx_update_persistent(struct nx_info *nxi)
20476 +{
20477 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20478 +               nx_set_persistent(nxi);
20479 +       else
20480 +               nx_clear_persistent(nxi);
20481 +}
20482 +
20483 +/* vserver syscall commands below here */
20484 +
20485 +/* taks nid and nx_info functions */
20486 +
20487 +#include <asm/uaccess.h>
20488 +
20489 +
20490 +int vc_task_nid(uint32_t id)
20491 +{
20492 +       nid_t nid;
20493 +
20494 +       if (id) {
20495 +               struct task_struct *tsk;
20496 +
20497 +               rcu_read_lock();
20498 +               tsk = find_task_by_real_pid(id);
20499 +               nid = (tsk) ? tsk->nid : -ESRCH;
20500 +               rcu_read_unlock();
20501 +       } else
20502 +               nid = nx_current_nid();
20503 +       return nid;
20504 +}
20505 +
20506 +
20507 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20508 +{
20509 +       struct vcmd_nx_info_v0 vc_data;
20510 +
20511 +       vc_data.nid = nxi->nx_id;
20512 +
20513 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20514 +               return -EFAULT;
20515 +       return 0;
20516 +}
20517 +
20518 +
20519 +/* network functions */
20520 +
20521 +int vc_net_create(uint32_t nid, void __user *data)
20522 +{
20523 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20524 +       struct nx_info *new_nxi;
20525 +       int ret;
20526 +
20527 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20528 +               return -EFAULT;
20529 +
20530 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20531 +               return -EINVAL;
20532 +
20533 +       new_nxi = __create_nx_info(nid);
20534 +       if (IS_ERR(new_nxi))
20535 +               return PTR_ERR(new_nxi);
20536 +
20537 +       /* initial flags */
20538 +       new_nxi->nx_flags = vc_data.flagword;
20539 +
20540 +       ret = -ENOEXEC;
20541 +       if (vs_net_change(new_nxi, VSC_NETUP))
20542 +               goto out;
20543 +
20544 +       ret = nx_migrate_task(current, new_nxi);
20545 +       if (ret)
20546 +               goto out;
20547 +
20548 +       /* return context id on success */
20549 +       ret = new_nxi->nx_id;
20550 +
20551 +       /* get a reference for persistent contexts */
20552 +       if ((vc_data.flagword & NXF_PERSISTENT))
20553 +               nx_set_persistent(new_nxi);
20554 +out:
20555 +       release_nx_info(new_nxi, NULL);
20556 +       put_nx_info(new_nxi);
20557 +       return ret;
20558 +}
20559 +
20560 +
20561 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20562 +{
20563 +       return nx_migrate_task(current, nxi);
20564 +}
20565 +
20566 +
20567 +
20568 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20569 +       uint16_t type, uint16_t flags)
20570 +{
20571 +       struct nx_addr_v4 *nxa = &nxi->v4;
20572 +
20573 +       if (NX_IPV4(nxi)) {
20574 +               /* locate last entry */
20575 +               for (; nxa->next; nxa = nxa->next);
20576 +               nxa->next = __alloc_nx_addr_v4();
20577 +               nxa = nxa->next;
20578 +
20579 +               if (IS_ERR(nxa))
20580 +                       return PTR_ERR(nxa);
20581 +       }
20582 +
20583 +       if (nxi->v4.next)
20584 +               /* remove single ip for ip list */
20585 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20586 +
20587 +       nxa->ip[0].s_addr = ip;
20588 +       nxa->ip[1].s_addr = ip2;
20589 +       nxa->mask.s_addr = mask;
20590 +       nxa->type = type;
20591 +       nxa->flags = flags;
20592 +       return 0;
20593 +}
20594 +
20595 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20596 +       uint16_t type, uint16_t flags)
20597 +{
20598 +       struct nx_addr_v4 *nxa = &nxi->v4;
20599 +
20600 +       switch (type) {
20601 +/*     case NXA_TYPE_ADDR:
20602 +               break;          */
20603 +
20604 +       case NXA_TYPE_ANY:
20605 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20606 +               memset(nxa, 0, sizeof(*nxa));
20607 +               break;
20608 +
20609 +       default:
20610 +               return -EINVAL;
20611 +       }
20612 +       return 0;
20613 +}
20614 +
20615 +
20616 +int vc_net_add(struct nx_info *nxi, void __user *data)
20617 +{
20618 +       struct vcmd_net_addr_v0 vc_data;
20619 +       int index, ret = 0;
20620 +
20621 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20622 +               return -EFAULT;
20623 +
20624 +       switch (vc_data.type) {
20625 +       case NXA_TYPE_IPV4:
20626 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20627 +                       return -EINVAL;
20628 +
20629 +               index = 0;
20630 +               while (index < vc_data.count) {
20631 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20632 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20633 +                       if (ret)
20634 +                               return ret;
20635 +                       index++;
20636 +               }
20637 +               ret = index;
20638 +               break;
20639 +
20640 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20641 +               nxi->v4_bcast = vc_data.ip[0];
20642 +               ret = 1;
20643 +               break;
20644 +
20645 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20646 +               nxi->v4_lback = vc_data.ip[0];
20647 +               ret = 1;
20648 +               break;
20649 +
20650 +       default:
20651 +               ret = -EINVAL;
20652 +               break;
20653 +       }
20654 +       return ret;
20655 +}
20656 +
20657 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20658 +{
20659 +       struct vcmd_net_addr_v0 vc_data;
20660 +
20661 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20662 +               return -EFAULT;
20663 +
20664 +       switch (vc_data.type) {
20665 +       case NXA_TYPE_ANY:
20666 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20667 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20668 +               break;
20669 +
20670 +       default:
20671 +               return -EINVAL;
20672 +       }
20673 +       return 0;
20674 +}
20675 +
20676 +
20677 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20678 +{
20679 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20680 +
20681 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20682 +               return -EFAULT;
20683 +
20684 +       switch (vc_data.type) {
20685 +       case NXA_TYPE_ADDR:
20686 +       case NXA_TYPE_MASK:
20687 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20688 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20689 +
20690 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20691 +               nxi->v4_bcast = vc_data.ip;
20692 +               break;
20693 +
20694 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20695 +               nxi->v4_lback = vc_data.ip;
20696 +               break;
20697 +
20698 +       default:
20699 +               return -EINVAL;
20700 +       }
20701 +       return 0;
20702 +}
20703 +
20704 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20705 +{
20706 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20707 +
20708 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20709 +               return -EFAULT;
20710 +
20711 +       switch (vc_data.type) {
20712 +       case NXA_TYPE_ADDR:
20713 +       case NXA_TYPE_MASK:
20714 +       case NXA_TYPE_RANGE:
20715 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20716 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20717 +
20718 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20719 +               nxi->v4_bcast = vc_data.ip;
20720 +               break;
20721 +
20722 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20723 +               nxi->v4_lback = vc_data.ip;
20724 +               break;
20725 +
20726 +       default:
20727 +               return -EINVAL;
20728 +       }
20729 +       return 0;
20730 +}
20731 +
20732 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20733 +{
20734 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20735 +
20736 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20737 +               return -EFAULT;
20738 +
20739 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20740 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20741 +}
20742 +
20743 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20744 +{
20745 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20746 +
20747 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20748 +               return -EFAULT;
20749 +
20750 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20751 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20752 +}
20753 +
20754 +#ifdef CONFIG_IPV6
20755 +
20756 +int do_add_v6_addr(struct nx_info *nxi,
20757 +       struct in6_addr *ip, struct in6_addr *mask,
20758 +       uint32_t prefix, uint16_t type, uint16_t flags)
20759 +{
20760 +       struct nx_addr_v6 *nxa = &nxi->v6;
20761 +
20762 +       if (NX_IPV6(nxi)) {
20763 +               /* locate last entry */
20764 +               for (; nxa->next; nxa = nxa->next);
20765 +               nxa->next = __alloc_nx_addr_v6();
20766 +               nxa = nxa->next;
20767 +
20768 +               if (IS_ERR(nxa))
20769 +                       return PTR_ERR(nxa);
20770 +       }
20771 +
20772 +       nxa->ip = *ip;
20773 +       nxa->mask = *mask;
20774 +       nxa->prefix = prefix;
20775 +       nxa->type = type;
20776 +       nxa->flags = flags;
20777 +       return 0;
20778 +}
20779 +
20780 +
20781 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20782 +{
20783 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20784 +
20785 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20786 +               return -EFAULT;
20787 +
20788 +       switch (vc_data.type) {
20789 +       case NXA_TYPE_ADDR:
20790 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20791 +               /* fallthrough */
20792 +       case NXA_TYPE_MASK:
20793 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20794 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20795 +       default:
20796 +               return -EINVAL;
20797 +       }
20798 +       return 0;
20799 +}
20800 +
20801 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20802 +{
20803 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20804 +
20805 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20806 +               return -EFAULT;
20807 +
20808 +       switch (vc_data.type) {
20809 +       case NXA_TYPE_ANY:
20810 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20811 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
20812 +               break;
20813 +
20814 +       default:
20815 +               return -EINVAL;
20816 +       }
20817 +       return 0;
20818 +}
20819 +
20820 +#endif /* CONFIG_IPV6 */
20821 +
20822 +
20823 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20824 +{
20825 +       struct vcmd_net_flags_v0 vc_data;
20826 +
20827 +       vc_data.flagword = nxi->nx_flags;
20828 +
20829 +       /* special STATE flag handling */
20830 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20831 +
20832 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20833 +               return -EFAULT;
20834 +       return 0;
20835 +}
20836 +
20837 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20838 +{
20839 +       struct vcmd_net_flags_v0 vc_data;
20840 +       uint64_t mask, trigger;
20841 +
20842 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20843 +               return -EFAULT;
20844 +
20845 +       /* special STATE flag handling */
20846 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20847 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20848 +
20849 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20850 +               vc_data.flagword, mask);
20851 +       if (trigger & NXF_PERSISTENT)
20852 +               nx_update_persistent(nxi);
20853 +
20854 +       return 0;
20855 +}
20856 +
20857 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20858 +{
20859 +       struct vcmd_net_caps_v0 vc_data;
20860 +
20861 +       vc_data.ncaps = nxi->nx_ncaps;
20862 +       vc_data.cmask = ~0ULL;
20863 +
20864 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20865 +               return -EFAULT;
20866 +       return 0;
20867 +}
20868 +
20869 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20870 +{
20871 +       struct vcmd_net_caps_v0 vc_data;
20872 +
20873 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20874 +               return -EFAULT;
20875 +
20876 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20877 +               vc_data.ncaps, vc_data.cmask);
20878 +       return 0;
20879 +}
20880 +
20881 +
20882 +#include <linux/module.h>
20883 +
20884 +module_init(init_network);
20885 +
20886 +EXPORT_SYMBOL_GPL(free_nx_info);
20887 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20888 +
20889 diff -NurpP --minimal linux-3.7/kernel/vserver/proc.c linux-3.7-vs2.3.5.1/kernel/vserver/proc.c
20890 --- linux-3.7/kernel/vserver/proc.c     1970-01-01 00:00:00.000000000 +0000
20891 +++ linux-3.7-vs2.3.5.1/kernel/vserver/proc.c   2012-12-11 15:56:33.000000000 +0000
20892 @@ -0,0 +1,1110 @@
20893 +/*
20894 + *  linux/kernel/vserver/proc.c
20895 + *
20896 + *  Virtual Context Support
20897 + *
20898 + *  Copyright (C) 2003-2011  Herbert Pötzl
20899 + *
20900 + *  V0.01  basic structure
20901 + *  V0.02  adaptation vs1.3.0
20902 + *  V0.03  proc permissions
20903 + *  V0.04  locking/generic
20904 + *  V0.05  next generation procfs
20905 + *  V0.06  inode validation
20906 + *  V0.07  generic rewrite vid
20907 + *  V0.08  remove inode type
20908 + *  V0.09  added u/wmask info
20909 + *
20910 + */
20911 +
20912 +#include <linux/proc_fs.h>
20913 +#include <linux/fs_struct.h>
20914 +#include <linux/mount.h>
20915 +#include <linux/namei.h>
20916 +#include <asm/unistd.h>
20917 +
20918 +#include <linux/vs_context.h>
20919 +#include <linux/vs_network.h>
20920 +#include <linux/vs_cvirt.h>
20921 +
20922 +#include <linux/in.h>
20923 +#include <linux/inetdevice.h>
20924 +#include <linux/vs_inet.h>
20925 +#include <linux/vs_inet6.h>
20926 +
20927 +#include <linux/vserver/global.h>
20928 +
20929 +#include "cvirt_proc.h"
20930 +#include "cacct_proc.h"
20931 +#include "limit_proc.h"
20932 +#include "sched_proc.h"
20933 +#include "vci_config.h"
20934 +
20935 +
20936 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20937 +{
20938 +       unsigned __capi;
20939 +
20940 +       CAP_FOR_EACH_U32(__capi) {
20941 +               buffer += sprintf(buffer, "%08x",
20942 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20943 +       }
20944 +       return buffer;
20945 +}
20946 +
20947 +
20948 +static struct proc_dir_entry *proc_virtual;
20949 +
20950 +static struct proc_dir_entry *proc_virtnet;
20951 +
20952 +
20953 +/* first the actual feeds */
20954 +
20955 +
20956 +static int proc_vci(char *buffer)
20957 +{
20958 +       return sprintf(buffer,
20959 +               "VCIVersion:\t%04x:%04x\n"
20960 +               "VCISyscall:\t%d\n"
20961 +               "VCIKernel:\t%08x\n",
20962 +               VCI_VERSION >> 16,
20963 +               VCI_VERSION & 0xFFFF,
20964 +               __NR_vserver,
20965 +               vci_kernel_config());
20966 +}
20967 +
20968 +static int proc_virtual_info(char *buffer)
20969 +{
20970 +       return proc_vci(buffer);
20971 +}
20972 +
20973 +static int proc_virtual_status(char *buffer)
20974 +{
20975 +       return sprintf(buffer,
20976 +               "#CTotal:\t%d\n"
20977 +               "#CActive:\t%d\n"
20978 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20979 +               "#InitTask:\t%d\t%d %d\n",
20980 +               atomic_read(&vx_global_ctotal),
20981 +               atomic_read(&vx_global_cactive),
20982 +               atomic_read(&vs_global_nsproxy),
20983 +               atomic_read(&vs_global_fs),
20984 +               atomic_read(&vs_global_mnt_ns),
20985 +               atomic_read(&vs_global_uts_ns),
20986 +               atomic_read(&nr_ipc_ns),
20987 +               atomic_read(&vs_global_user_ns),
20988 +               atomic_read(&vs_global_pid_ns),
20989 +               atomic_read(&init_task.usage),
20990 +               atomic_read(&init_task.nsproxy->count),
20991 +               init_task.fs->users);
20992 +}
20993 +
20994 +
20995 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20996 +{
20997 +       int length;
20998 +
20999 +       length = sprintf(buffer,
21000 +               "ID:\t%d\n"
21001 +               "Info:\t%p\n"
21002 +               "Init:\t%d\n"
21003 +               "OOM:\t%lld\n",
21004 +               vxi->vx_id,
21005 +               vxi,
21006 +               vxi->vx_initpid,
21007 +               vxi->vx_badness_bias);
21008 +       return length;
21009 +}
21010 +
21011 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21012 +{
21013 +       char *orig = buffer;
21014 +
21015 +       buffer += sprintf(buffer,
21016 +               "UseCnt:\t%d\n"
21017 +               "Tasks:\t%d\n"
21018 +               "Flags:\t%016llx\n",
21019 +               atomic_read(&vxi->vx_usecnt),
21020 +               atomic_read(&vxi->vx_tasks),
21021 +               (unsigned long long)vxi->vx_flags);
21022 +
21023 +       buffer += sprintf(buffer, "BCaps:\t");
21024 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21025 +       buffer += sprintf(buffer, "\n");
21026 +
21027 +       buffer += sprintf(buffer,
21028 +               "CCaps:\t%016llx\n"
21029 +               "Umask:\t%16llx\n"
21030 +               "Wmask:\t%16llx\n"
21031 +               "Spaces:\t%08lx %08lx\n",
21032 +               (unsigned long long)vxi->vx_ccaps,
21033 +               (unsigned long long)vxi->vx_umask,
21034 +               (unsigned long long)vxi->vx_wmask,
21035 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21036 +       return buffer - orig;
21037 +}
21038 +
21039 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21040 +{
21041 +       return vx_info_proc_limit(&vxi->limit, buffer);
21042 +}
21043 +
21044 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21045 +{
21046 +       int cpu, length;
21047 +
21048 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21049 +       for_each_online_cpu(cpu) {
21050 +               length += vx_info_proc_sched_pc(
21051 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21052 +                       buffer + length, cpu);
21053 +       }
21054 +       return length;
21055 +}
21056 +
21057 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21058 +{
21059 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21060 +}
21061 +
21062 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21063 +{
21064 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21065 +}
21066 +
21067 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21068 +{
21069 +       int cpu, length;
21070 +
21071 +       vx_update_load(vxi);
21072 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21073 +       for_each_online_cpu(cpu) {
21074 +               length += vx_info_proc_cvirt_pc(
21075 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21076 +                       buffer + length, cpu);
21077 +       }
21078 +       return length;
21079 +}
21080 +
21081 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21082 +{
21083 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21084 +}
21085 +
21086 +
21087 +static int proc_virtnet_info(char *buffer)
21088 +{
21089 +       return proc_vci(buffer);
21090 +}
21091 +
21092 +static int proc_virtnet_status(char *buffer)
21093 +{
21094 +       return sprintf(buffer,
21095 +               "#CTotal:\t%d\n"
21096 +               "#CActive:\t%d\n",
21097 +               atomic_read(&nx_global_ctotal),
21098 +               atomic_read(&nx_global_cactive));
21099 +}
21100 +
21101 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21102 +{
21103 +       struct nx_addr_v4 *v4a;
21104 +#ifdef CONFIG_IPV6
21105 +       struct nx_addr_v6 *v6a;
21106 +#endif
21107 +       int length, i;
21108 +
21109 +       length = sprintf(buffer,
21110 +               "ID:\t%d\n"
21111 +               "Info:\t%p\n"
21112 +               "Bcast:\t" NIPQUAD_FMT "\n"
21113 +               "Lback:\t" NIPQUAD_FMT "\n",
21114 +               nxi->nx_id,
21115 +               nxi,
21116 +               NIPQUAD(nxi->v4_bcast.s_addr),
21117 +               NIPQUAD(nxi->v4_lback.s_addr));
21118 +
21119 +       if (!NX_IPV4(nxi))
21120 +               goto skip_v4;
21121 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21122 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21123 +                       i, NXAV4(v4a));
21124 +skip_v4:
21125 +#ifdef CONFIG_IPV6
21126 +       if (!NX_IPV6(nxi))
21127 +               goto skip_v6;
21128 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21129 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21130 +                       i, NXAV6(v6a));
21131 +skip_v6:
21132 +#endif
21133 +       return length;
21134 +}
21135 +
21136 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21137 +{
21138 +       int length;
21139 +
21140 +       length = sprintf(buffer,
21141 +               "UseCnt:\t%d\n"
21142 +               "Tasks:\t%d\n"
21143 +               "Flags:\t%016llx\n"
21144 +               "NCaps:\t%016llx\n",
21145 +               atomic_read(&nxi->nx_usecnt),
21146 +               atomic_read(&nxi->nx_tasks),
21147 +               (unsigned long long)nxi->nx_flags,
21148 +               (unsigned long long)nxi->nx_ncaps);
21149 +       return length;
21150 +}
21151 +
21152 +
21153 +
21154 +/* here the inode helpers */
21155 +
21156 +struct vs_entry {
21157 +       int len;
21158 +       char *name;
21159 +       mode_t mode;
21160 +       struct inode_operations *iop;
21161 +       struct file_operations *fop;
21162 +       union proc_op op;
21163 +};
21164 +
21165 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21166 +{
21167 +       struct inode *inode = new_inode(sb);
21168 +
21169 +       if (!inode)
21170 +               goto out;
21171 +
21172 +       inode->i_mode = p->mode;
21173 +       if (p->iop)
21174 +               inode->i_op = p->iop;
21175 +       if (p->fop)
21176 +               inode->i_fop = p->fop;
21177 +
21178 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21179 +       inode->i_flags |= S_IMMUTABLE;
21180 +
21181 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21182 +
21183 +       inode->i_uid = 0;
21184 +       inode->i_gid = 0;
21185 +       inode->i_tag = 0;
21186 +out:
21187 +       return inode;
21188 +}
21189 +
21190 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21191 +       struct dentry *dentry, int id, void *ptr)
21192 +{
21193 +       struct vs_entry *p = ptr;
21194 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21195 +       struct dentry *error = ERR_PTR(-EINVAL);
21196 +
21197 +       if (!inode)
21198 +               goto out;
21199 +
21200 +       PROC_I(inode)->op = p->op;
21201 +       PROC_I(inode)->fd = id;
21202 +       d_add(dentry, inode);
21203 +       error = NULL;
21204 +out:
21205 +       return error;
21206 +}
21207 +
21208 +/* Lookups */
21209 +
21210 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21211 +
21212 +/*
21213 + * Fill a directory entry.
21214 + *
21215 + * If possible create the dcache entry and derive our inode number and
21216 + * file type from dcache entry.
21217 + *
21218 + * Since all of the proc inode numbers are dynamically generated, the inode
21219 + * numbers do not exist until the inode is cache.  This means creating the
21220 + * the dcache entry in readdir is necessary to keep the inode numbers
21221 + * reported by readdir in sync with the inode numbers reported
21222 + * by stat.
21223 + */
21224 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21225 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21226 +{
21227 +       struct dentry *child, *dir = filp->f_dentry;
21228 +       struct inode *inode;
21229 +       struct qstr qname;
21230 +       ino_t ino = 0;
21231 +       unsigned type = DT_UNKNOWN;
21232 +
21233 +       qname.name = name;
21234 +       qname.len  = len;
21235 +       qname.hash = full_name_hash(name, len);
21236 +
21237 +       child = d_lookup(dir, &qname);
21238 +       if (!child) {
21239 +               struct dentry *new;
21240 +               new = d_alloc(dir, &qname);
21241 +               if (new) {
21242 +                       child = instantiate(dir->d_inode, new, id, ptr);
21243 +                       if (child)
21244 +                               dput(new);
21245 +                       else
21246 +                               child = new;
21247 +               }
21248 +       }
21249 +       if (!child || IS_ERR(child) || !child->d_inode)
21250 +               goto end_instantiate;
21251 +       inode = child->d_inode;
21252 +       if (inode) {
21253 +               ino = inode->i_ino;
21254 +               type = inode->i_mode >> 12;
21255 +       }
21256 +       dput(child);
21257 +end_instantiate:
21258 +       if (!ino)
21259 +               ino = find_inode_number(dir, &qname);
21260 +       if (!ino)
21261 +               ino = 1;
21262 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21263 +}
21264 +
21265 +
21266 +
21267 +/* get and revalidate vx_info/xid */
21268 +
21269 +static inline
21270 +struct vx_info *get_proc_vx_info(struct inode *inode)
21271 +{
21272 +       return lookup_vx_info(PROC_I(inode)->fd);
21273 +}
21274 +
21275 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21276 +{
21277 +       struct inode *inode = dentry->d_inode;
21278 +       xid_t xid = PROC_I(inode)->fd;
21279 +
21280 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21281 +               return -ECHILD;
21282 +
21283 +       if (!xid || xid_is_hashed(xid))
21284 +               return 1;
21285 +       d_drop(dentry);
21286 +       return 0;
21287 +}
21288 +
21289 +
21290 +/* get and revalidate nx_info/nid */
21291 +
21292 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21293 +{
21294 +       struct inode *inode = dentry->d_inode;
21295 +       nid_t nid = PROC_I(inode)->fd;
21296 +
21297 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21298 +               return -ECHILD;
21299 +
21300 +       if (!nid || nid_is_hashed(nid))
21301 +               return 1;
21302 +       d_drop(dentry);
21303 +       return 0;
21304 +}
21305 +
21306 +
21307 +
21308 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21309 +
21310 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21311 +                         size_t count, loff_t *ppos)
21312 +{
21313 +       struct inode *inode = file->f_dentry->d_inode;
21314 +       unsigned long page;
21315 +       ssize_t length = 0;
21316 +
21317 +       if (count > PROC_BLOCK_SIZE)
21318 +               count = PROC_BLOCK_SIZE;
21319 +
21320 +       /* fade that out as soon as stable */
21321 +       WARN_ON(PROC_I(inode)->fd);
21322 +
21323 +       if (!(page = __get_free_page(GFP_KERNEL)))
21324 +               return -ENOMEM;
21325 +
21326 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21327 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21328 +
21329 +       if (length >= 0)
21330 +               length = simple_read_from_buffer(buf, count, ppos,
21331 +                       (char *)page, length);
21332 +
21333 +       free_page(page);
21334 +       return length;
21335 +}
21336 +
21337 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21338 +                         size_t count, loff_t *ppos)
21339 +{
21340 +       struct inode *inode = file->f_dentry->d_inode;
21341 +       struct vx_info *vxi = NULL;
21342 +       xid_t xid = PROC_I(inode)->fd;
21343 +       unsigned long page;
21344 +       ssize_t length = 0;
21345 +
21346 +       if (count > PROC_BLOCK_SIZE)
21347 +               count = PROC_BLOCK_SIZE;
21348 +
21349 +       /* fade that out as soon as stable */
21350 +       WARN_ON(!xid);
21351 +       vxi = lookup_vx_info(xid);
21352 +       if (!vxi)
21353 +               goto out;
21354 +
21355 +       length = -ENOMEM;
21356 +       if (!(page = __get_free_page(GFP_KERNEL)))
21357 +               goto out_put;
21358 +
21359 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21360 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21361 +
21362 +       if (length >= 0)
21363 +               length = simple_read_from_buffer(buf, count, ppos,
21364 +                       (char *)page, length);
21365 +
21366 +       free_page(page);
21367 +out_put:
21368 +       put_vx_info(vxi);
21369 +out:
21370 +       return length;
21371 +}
21372 +
21373 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21374 +                         size_t count, loff_t *ppos)
21375 +{
21376 +       struct inode *inode = file->f_dentry->d_inode;
21377 +       struct nx_info *nxi = NULL;
21378 +       nid_t nid = PROC_I(inode)->fd;
21379 +       unsigned long page;
21380 +       ssize_t length = 0;
21381 +
21382 +       if (count > PROC_BLOCK_SIZE)
21383 +               count = PROC_BLOCK_SIZE;
21384 +
21385 +       /* fade that out as soon as stable */
21386 +       WARN_ON(!nid);
21387 +       nxi = lookup_nx_info(nid);
21388 +       if (!nxi)
21389 +               goto out;
21390 +
21391 +       length = -ENOMEM;
21392 +       if (!(page = __get_free_page(GFP_KERNEL)))
21393 +               goto out_put;
21394 +
21395 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21396 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21397 +
21398 +       if (length >= 0)
21399 +               length = simple_read_from_buffer(buf, count, ppos,
21400 +                       (char *)page, length);
21401 +
21402 +       free_page(page);
21403 +out_put:
21404 +       put_nx_info(nxi);
21405 +out:
21406 +       return length;
21407 +}
21408 +
21409 +
21410 +
21411 +/* here comes the lower level */
21412 +
21413 +
21414 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21415 +       .len  = sizeof(NAME) - 1,       \
21416 +       .name = (NAME),                 \
21417 +       .mode = MODE,                   \
21418 +       .iop  = IOP,                    \
21419 +       .fop  = FOP,                    \
21420 +       .op   = OP,                     \
21421 +}
21422 +
21423 +
21424 +#define DIR(NAME, MODE, OTYPE)                         \
21425 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21426 +               &proc_ ## OTYPE ## _inode_operations,   \
21427 +               &proc_ ## OTYPE ## _file_operations, { } )
21428 +
21429 +#define INF(NAME, MODE, OTYPE)                         \
21430 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21431 +               &proc_vs_info_file_operations,          \
21432 +               { .proc_vs_read = &proc_##OTYPE } )
21433 +
21434 +#define VINF(NAME, MODE, OTYPE)                                \
21435 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21436 +               &proc_vx_info_file_operations,          \
21437 +               { .proc_vxi_read = &proc_##OTYPE } )
21438 +
21439 +#define NINF(NAME, MODE, OTYPE)                                \
21440 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21441 +               &proc_nx_info_file_operations,          \
21442 +               { .proc_nxi_read = &proc_##OTYPE } )
21443 +
21444 +
21445 +static struct file_operations proc_vs_info_file_operations = {
21446 +       .read =         proc_vs_info_read,
21447 +};
21448 +
21449 +static struct file_operations proc_vx_info_file_operations = {
21450 +       .read =         proc_vx_info_read,
21451 +};
21452 +
21453 +static struct dentry_operations proc_xid_dentry_operations = {
21454 +       .d_revalidate = proc_xid_revalidate,
21455 +};
21456 +
21457 +static struct vs_entry vx_base_stuff[] = {
21458 +       VINF("info",    S_IRUGO, vxi_info),
21459 +       VINF("status",  S_IRUGO, vxi_status),
21460 +       VINF("limit",   S_IRUGO, vxi_limit),
21461 +       VINF("sched",   S_IRUGO, vxi_sched),
21462 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21463 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21464 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21465 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21466 +       {}
21467 +};
21468 +
21469 +
21470 +
21471 +
21472 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21473 +       struct dentry *dentry, int id, void *ptr)
21474 +{
21475 +       dentry->d_op = &proc_xid_dentry_operations;
21476 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21477 +}
21478 +
21479 +static struct dentry *proc_xid_lookup(struct inode *dir,
21480 +       struct dentry *dentry, unsigned int flags)
21481 +{
21482 +       struct vs_entry *p = vx_base_stuff;
21483 +       struct dentry *error = ERR_PTR(-ENOENT);
21484 +
21485 +       for (; p->name; p++) {
21486 +               if (p->len != dentry->d_name.len)
21487 +                       continue;
21488 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21489 +                       break;
21490 +       }
21491 +       if (!p->name)
21492 +               goto out;
21493 +
21494 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21495 +out:
21496 +       return error;
21497 +}
21498 +
21499 +static int proc_xid_readdir(struct file *filp,
21500 +       void *dirent, filldir_t filldir)
21501 +{
21502 +       struct dentry *dentry = filp->f_dentry;
21503 +       struct inode *inode = dentry->d_inode;
21504 +       struct vs_entry *p = vx_base_stuff;
21505 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21506 +       int pos, index;
21507 +       u64 ino;
21508 +
21509 +       pos = filp->f_pos;
21510 +       switch (pos) {
21511 +       case 0:
21512 +               ino = inode->i_ino;
21513 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21514 +                       goto out;
21515 +               pos++;
21516 +               /* fall through */
21517 +       case 1:
21518 +               ino = parent_ino(dentry);
21519 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21520 +                       goto out;
21521 +               pos++;
21522 +               /* fall through */
21523 +       default:
21524 +               index = pos - 2;
21525 +               if (index >= size)
21526 +                       goto out;
21527 +               for (p += index; p->name; p++) {
21528 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21529 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21530 +                               goto out;
21531 +                       pos++;
21532 +               }
21533 +       }
21534 +out:
21535 +       filp->f_pos = pos;
21536 +       return 1;
21537 +}
21538 +
21539 +
21540 +
21541 +static struct file_operations proc_nx_info_file_operations = {
21542 +       .read =         proc_nx_info_read,
21543 +};
21544 +
21545 +static struct dentry_operations proc_nid_dentry_operations = {
21546 +       .d_revalidate = proc_nid_revalidate,
21547 +};
21548 +
21549 +static struct vs_entry nx_base_stuff[] = {
21550 +       NINF("info",    S_IRUGO, nxi_info),
21551 +       NINF("status",  S_IRUGO, nxi_status),
21552 +       {}
21553 +};
21554 +
21555 +
21556 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21557 +       struct dentry *dentry, int id, void *ptr)
21558 +{
21559 +       dentry->d_op = &proc_nid_dentry_operations;
21560 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21561 +}
21562 +
21563 +static struct dentry *proc_nid_lookup(struct inode *dir,
21564 +       struct dentry *dentry, unsigned int flags)
21565 +{
21566 +       struct vs_entry *p = nx_base_stuff;
21567 +       struct dentry *error = ERR_PTR(-ENOENT);
21568 +
21569 +       for (; p->name; p++) {
21570 +               if (p->len != dentry->d_name.len)
21571 +                       continue;
21572 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21573 +                       break;
21574 +       }
21575 +       if (!p->name)
21576 +               goto out;
21577 +
21578 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21579 +out:
21580 +       return error;
21581 +}
21582 +
21583 +static int proc_nid_readdir(struct file *filp,
21584 +       void *dirent, filldir_t filldir)
21585 +{
21586 +       struct dentry *dentry = filp->f_dentry;
21587 +       struct inode *inode = dentry->d_inode;
21588 +       struct vs_entry *p = nx_base_stuff;
21589 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21590 +       int pos, index;
21591 +       u64 ino;
21592 +
21593 +       pos = filp->f_pos;
21594 +       switch (pos) {
21595 +       case 0:
21596 +               ino = inode->i_ino;
21597 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21598 +                       goto out;
21599 +               pos++;
21600 +               /* fall through */
21601 +       case 1:
21602 +               ino = parent_ino(dentry);
21603 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21604 +                       goto out;
21605 +               pos++;
21606 +               /* fall through */
21607 +       default:
21608 +               index = pos - 2;
21609 +               if (index >= size)
21610 +                       goto out;
21611 +               for (p += index; p->name; p++) {
21612 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21613 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21614 +                               goto out;
21615 +                       pos++;
21616 +               }
21617 +       }
21618 +out:
21619 +       filp->f_pos = pos;
21620 +       return 1;
21621 +}
21622 +
21623 +
21624 +#define MAX_MULBY10    ((~0U - 9) / 10)
21625 +
21626 +static inline int atovid(const char *str, int len)
21627 +{
21628 +       int vid, c;
21629 +
21630 +       vid = 0;
21631 +       while (len-- > 0) {
21632 +               c = *str - '0';
21633 +               str++;
21634 +               if (c > 9)
21635 +                       return -1;
21636 +               if (vid >= MAX_MULBY10)
21637 +                       return -1;
21638 +               vid *= 10;
21639 +               vid += c;
21640 +               if (!vid)
21641 +                       return -1;
21642 +       }
21643 +       return vid;
21644 +}
21645 +
21646 +/* now the upper level (virtual) */
21647 +
21648 +
21649 +static struct file_operations proc_xid_file_operations = {
21650 +       .read =         generic_read_dir,
21651 +       .readdir =      proc_xid_readdir,
21652 +};
21653 +
21654 +static struct inode_operations proc_xid_inode_operations = {
21655 +       .lookup =       proc_xid_lookup,
21656 +};
21657 +
21658 +static struct vs_entry vx_virtual_stuff[] = {
21659 +       INF("info",     S_IRUGO, virtual_info),
21660 +       INF("status",   S_IRUGO, virtual_status),
21661 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21662 +};
21663 +
21664 +
21665 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21666 +       struct dentry *dentry, unsigned int flags)
21667 +{
21668 +       struct vs_entry *p = vx_virtual_stuff;
21669 +       struct dentry *error = ERR_PTR(-ENOENT);
21670 +       int id = 0;
21671 +
21672 +       for (; p->name; p++) {
21673 +               if (p->len != dentry->d_name.len)
21674 +                       continue;
21675 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21676 +                       break;
21677 +       }
21678 +       if (p->name)
21679 +               goto instantiate;
21680 +
21681 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21682 +       if ((id < 0) || !xid_is_hashed(id))
21683 +               goto out;
21684 +
21685 +instantiate:
21686 +       error = proc_xid_instantiate(dir, dentry, id, p);
21687 +out:
21688 +       return error;
21689 +}
21690 +
21691 +static struct file_operations proc_nid_file_operations = {
21692 +       .read =         generic_read_dir,
21693 +       .readdir =      proc_nid_readdir,
21694 +};
21695 +
21696 +static struct inode_operations proc_nid_inode_operations = {
21697 +       .lookup =       proc_nid_lookup,
21698 +};
21699 +
21700 +static struct vs_entry nx_virtnet_stuff[] = {
21701 +       INF("info",     S_IRUGO, virtnet_info),
21702 +       INF("status",   S_IRUGO, virtnet_status),
21703 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21704 +};
21705 +
21706 +
21707 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21708 +       struct dentry *dentry, unsigned int flags)
21709 +{
21710 +       struct vs_entry *p = nx_virtnet_stuff;
21711 +       struct dentry *error = ERR_PTR(-ENOENT);
21712 +       int id = 0;
21713 +
21714 +       for (; p->name; p++) {
21715 +               if (p->len != dentry->d_name.len)
21716 +                       continue;
21717 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21718 +                       break;
21719 +       }
21720 +       if (p->name)
21721 +               goto instantiate;
21722 +
21723 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21724 +       if ((id < 0) || !nid_is_hashed(id))
21725 +               goto out;
21726 +
21727 +instantiate:
21728 +       error = proc_nid_instantiate(dir, dentry, id, p);
21729 +out:
21730 +       return error;
21731 +}
21732 +
21733 +
21734 +#define PROC_MAXVIDS 32
21735 +
21736 +int proc_virtual_readdir(struct file *filp,
21737 +       void *dirent, filldir_t filldir)
21738 +{
21739 +       struct dentry *dentry = filp->f_dentry;
21740 +       struct inode *inode = dentry->d_inode;
21741 +       struct vs_entry *p = vx_virtual_stuff;
21742 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21743 +       int pos, index;
21744 +       unsigned int xid_array[PROC_MAXVIDS];
21745 +       char buf[PROC_NUMBUF];
21746 +       unsigned int nr_xids, i;
21747 +       u64 ino;
21748 +
21749 +       pos = filp->f_pos;
21750 +       switch (pos) {
21751 +       case 0:
21752 +               ino = inode->i_ino;
21753 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21754 +                       goto out;
21755 +               pos++;
21756 +               /* fall through */
21757 +       case 1:
21758 +               ino = parent_ino(dentry);
21759 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21760 +                       goto out;
21761 +               pos++;
21762 +               /* fall through */
21763 +       default:
21764 +               index = pos - 2;
21765 +               if (index >= size)
21766 +                       goto entries;
21767 +               for (p += index; p->name; p++) {
21768 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21769 +                               vs_proc_instantiate, 0, p))
21770 +                               goto out;
21771 +                       pos++;
21772 +               }
21773 +       entries:
21774 +               index = pos - size;
21775 +               p = &vx_virtual_stuff[size - 1];
21776 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21777 +               for (i = 0; i < nr_xids; i++) {
21778 +                       int n, xid = xid_array[i];
21779 +                       unsigned int j = PROC_NUMBUF;
21780 +
21781 +                       n = xid;
21782 +                       do
21783 +                               buf[--j] = '0' + (n % 10);
21784 +                       while (n /= 10);
21785 +
21786 +                       if (proc_fill_cache(filp, dirent, filldir,
21787 +                               buf + j, PROC_NUMBUF - j,
21788 +                               vs_proc_instantiate, xid, p))
21789 +                               goto out;
21790 +                       pos++;
21791 +               }
21792 +       }
21793 +out:
21794 +       filp->f_pos = pos;
21795 +       return 0;
21796 +}
21797 +
21798 +static int proc_virtual_getattr(struct vfsmount *mnt,
21799 +       struct dentry *dentry, struct kstat *stat)
21800 +{
21801 +       struct inode *inode = dentry->d_inode;
21802 +
21803 +       generic_fillattr(inode, stat);
21804 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21805 +       return 0;
21806 +}
21807 +
21808 +static struct file_operations proc_virtual_dir_operations = {
21809 +       .read =         generic_read_dir,
21810 +       .readdir =      proc_virtual_readdir,
21811 +};
21812 +
21813 +static struct inode_operations proc_virtual_dir_inode_operations = {
21814 +       .getattr =      proc_virtual_getattr,
21815 +       .lookup =       proc_virtual_lookup,
21816 +};
21817 +
21818 +
21819 +
21820 +
21821 +
21822 +int proc_virtnet_readdir(struct file *filp,
21823 +       void *dirent, filldir_t filldir)
21824 +{
21825 +       struct dentry *dentry = filp->f_dentry;
21826 +       struct inode *inode = dentry->d_inode;
21827 +       struct vs_entry *p = nx_virtnet_stuff;
21828 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21829 +       int pos, index;
21830 +       unsigned int nid_array[PROC_MAXVIDS];
21831 +       char buf[PROC_NUMBUF];
21832 +       unsigned int nr_nids, i;
21833 +       u64 ino;
21834 +
21835 +       pos = filp->f_pos;
21836 +       switch (pos) {
21837 +       case 0:
21838 +               ino = inode->i_ino;
21839 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21840 +                       goto out;
21841 +               pos++;
21842 +               /* fall through */
21843 +       case 1:
21844 +               ino = parent_ino(dentry);
21845 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21846 +                       goto out;
21847 +               pos++;
21848 +               /* fall through */
21849 +       default:
21850 +               index = pos - 2;
21851 +               if (index >= size)
21852 +                       goto entries;
21853 +               for (p += index; p->name; p++) {
21854 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21855 +                               vs_proc_instantiate, 0, p))
21856 +                               goto out;
21857 +                       pos++;
21858 +               }
21859 +       entries:
21860 +               index = pos - size;
21861 +               p = &nx_virtnet_stuff[size - 1];
21862 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21863 +               for (i = 0; i < nr_nids; i++) {
21864 +                       int n, nid = nid_array[i];
21865 +                       unsigned int j = PROC_NUMBUF;
21866 +
21867 +                       n = nid;
21868 +                       do
21869 +                               buf[--j] = '0' + (n % 10);
21870 +                       while (n /= 10);
21871 +
21872 +                       if (proc_fill_cache(filp, dirent, filldir,
21873 +                               buf + j, PROC_NUMBUF - j,
21874 +                               vs_proc_instantiate, nid, p))
21875 +                               goto out;
21876 +                       pos++;
21877 +               }
21878 +       }
21879 +out:
21880 +       filp->f_pos = pos;
21881 +       return 0;
21882 +}
21883 +
21884 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21885 +       struct dentry *dentry, struct kstat *stat)
21886 +{
21887 +       struct inode *inode = dentry->d_inode;
21888 +
21889 +       generic_fillattr(inode, stat);
21890 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21891 +       return 0;
21892 +}
21893 +
21894 +static struct file_operations proc_virtnet_dir_operations = {
21895 +       .read =         generic_read_dir,
21896 +       .readdir =      proc_virtnet_readdir,
21897 +};
21898 +
21899 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21900 +       .getattr =      proc_virtnet_getattr,
21901 +       .lookup =       proc_virtnet_lookup,
21902 +};
21903 +
21904 +
21905 +
21906 +void proc_vx_init(void)
21907 +{
21908 +       struct proc_dir_entry *ent;
21909 +
21910 +       ent = proc_mkdir("virtual", 0);
21911 +       if (ent) {
21912 +               ent->proc_fops = &proc_virtual_dir_operations;
21913 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21914 +       }
21915 +       proc_virtual = ent;
21916 +
21917 +       ent = proc_mkdir("virtnet", 0);
21918 +       if (ent) {
21919 +               ent->proc_fops = &proc_virtnet_dir_operations;
21920 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21921 +       }
21922 +       proc_virtnet = ent;
21923 +}
21924 +
21925 +
21926 +
21927 +
21928 +/* per pid info */
21929 +
21930 +
21931 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21932 +{
21933 +       struct vx_info *vxi;
21934 +       char *orig = buffer;
21935 +
21936 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21937 +
21938 +       vxi = task_get_vx_info(p);
21939 +       if (!vxi)
21940 +               goto out;
21941 +
21942 +       buffer += sprintf(buffer, "BCaps:\t");
21943 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21944 +       buffer += sprintf(buffer, "\n");
21945 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21946 +               (unsigned long long)vxi->vx_ccaps);
21947 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21948 +               (unsigned long long)vxi->vx_flags);
21949 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21950 +
21951 +       put_vx_info(vxi);
21952 +out:
21953 +       return buffer - orig;
21954 +}
21955 +
21956 +
21957 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21958 +{
21959 +       struct nx_info *nxi;
21960 +       struct nx_addr_v4 *v4a;
21961 +#ifdef CONFIG_IPV6
21962 +       struct nx_addr_v6 *v6a;
21963 +#endif
21964 +       char *orig = buffer;
21965 +       int i;
21966 +
21967 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21968 +
21969 +       nxi = task_get_nx_info(p);
21970 +       if (!nxi)
21971 +               goto out;
21972 +
21973 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21974 +               (unsigned long long)nxi->nx_ncaps);
21975 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21976 +               (unsigned long long)nxi->nx_flags);
21977 +
21978 +       buffer += sprintf(buffer,
21979 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21980 +               NIPQUAD(nxi->v4_bcast.s_addr));
21981 +       buffer += sprintf (buffer,
21982 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21983 +               NIPQUAD(nxi->v4_lback.s_addr));
21984 +       if (!NX_IPV4(nxi))
21985 +               goto skip_v4;
21986 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21987 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21988 +                       i, NXAV4(v4a));
21989 +skip_v4:
21990 +#ifdef CONFIG_IPV6
21991 +       if (!NX_IPV6(nxi))
21992 +               goto skip_v6;
21993 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21994 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21995 +                       i, NXAV6(v6a));
21996 +skip_v6:
21997 +#endif
21998 +       put_nx_info(nxi);
21999 +out:
22000 +       return buffer - orig;
22001 +}
22002 +
22003 diff -NurpP --minimal linux-3.7/kernel/vserver/sched.c linux-3.7-vs2.3.5.1/kernel/vserver/sched.c
22004 --- linux-3.7/kernel/vserver/sched.c    1970-01-01 00:00:00.000000000 +0000
22005 +++ linux-3.7-vs2.3.5.1/kernel/vserver/sched.c  2012-12-11 15:56:33.000000000 +0000
22006 @@ -0,0 +1,83 @@
22007 +/*
22008 + *  linux/kernel/vserver/sched.c
22009 + *
22010 + *  Virtual Server: Scheduler Support
22011 + *
22012 + *  Copyright (C) 2004-2010  Herbert Pötzl
22013 + *
22014 + *  V0.01  adapted Sam Vilains version to 2.6.3
22015 + *  V0.02  removed legacy interface
22016 + *  V0.03  changed vcmds to vxi arg
22017 + *  V0.04  removed older and legacy interfaces
22018 + *  V0.05  removed scheduler code/commands
22019 + *
22020 + */
22021 +
22022 +#include <linux/vs_context.h>
22023 +#include <linux/vs_sched.h>
22024 +#include <linux/cpumask.h>
22025 +#include <linux/vserver/sched_cmd.h>
22026 +
22027 +#include <asm/uaccess.h>
22028 +
22029 +
22030 +void vx_update_sched_param(struct _vx_sched *sched,
22031 +       struct _vx_sched_pc *sched_pc)
22032 +{
22033 +       sched_pc->prio_bias = sched->prio_bias;
22034 +}
22035 +
22036 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22037 +{
22038 +       int cpu;
22039 +
22040 +       if (data->prio_bias > MAX_PRIO_BIAS)
22041 +               data->prio_bias = MAX_PRIO_BIAS;
22042 +       if (data->prio_bias < MIN_PRIO_BIAS)
22043 +               data->prio_bias = MIN_PRIO_BIAS;
22044 +
22045 +       if (data->cpu_id != ~0) {
22046 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22047 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22048 +                       cpu_online_mask);
22049 +       } else
22050 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22051 +
22052 +       for_each_cpu_mask(cpu, vxi->sched.update)
22053 +               vx_update_sched_param(&vxi->sched,
22054 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22055 +       return 0;
22056 +}
22057 +
22058 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22059 +{
22060 +       struct vcmd_prio_bias vc_data;
22061 +
22062 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22063 +               return -EFAULT;
22064 +
22065 +       return do_set_prio_bias(vxi, &vc_data);
22066 +}
22067 +
22068 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22069 +{
22070 +       struct vcmd_prio_bias vc_data;
22071 +       struct _vx_sched_pc *pcd;
22072 +       int cpu;
22073 +
22074 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22075 +               return -EFAULT;
22076 +
22077 +       cpu = vc_data.cpu_id;
22078 +
22079 +       if (!cpu_possible(cpu))
22080 +               return -EINVAL;
22081 +
22082 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22083 +       vc_data.prio_bias = pcd->prio_bias;
22084 +
22085 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22086 +               return -EFAULT;
22087 +       return 0;
22088 +}
22089 +
22090 diff -NurpP --minimal linux-3.7/kernel/vserver/sched_init.h linux-3.7-vs2.3.5.1/kernel/vserver/sched_init.h
22091 --- linux-3.7/kernel/vserver/sched_init.h       1970-01-01 00:00:00.000000000 +0000
22092 +++ linux-3.7-vs2.3.5.1/kernel/vserver/sched_init.h     2012-12-11 15:56:33.000000000 +0000
22093 @@ -0,0 +1,27 @@
22094 +
22095 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22096 +{
22097 +       /* scheduling; hard code starting values as constants */
22098 +       sched->prio_bias = 0;
22099 +}
22100 +
22101 +static inline
22102 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22103 +{
22104 +       sched_pc->prio_bias = 0;
22105 +
22106 +       sched_pc->user_ticks = 0;
22107 +       sched_pc->sys_ticks = 0;
22108 +       sched_pc->hold_ticks = 0;
22109 +}
22110 +
22111 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22112 +{
22113 +       return;
22114 +}
22115 +
22116 +static inline
22117 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22118 +{
22119 +       return;
22120 +}
22121 diff -NurpP --minimal linux-3.7/kernel/vserver/sched_proc.h linux-3.7-vs2.3.5.1/kernel/vserver/sched_proc.h
22122 --- linux-3.7/kernel/vserver/sched_proc.h       1970-01-01 00:00:00.000000000 +0000
22123 +++ linux-3.7-vs2.3.5.1/kernel/vserver/sched_proc.h     2012-12-11 15:56:33.000000000 +0000
22124 @@ -0,0 +1,32 @@
22125 +#ifndef _VX_SCHED_PROC_H
22126 +#define _VX_SCHED_PROC_H
22127 +
22128 +
22129 +static inline
22130 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22131 +{
22132 +       int length = 0;
22133 +
22134 +       length += sprintf(buffer,
22135 +               "PrioBias:\t%8d\n",
22136 +               sched->prio_bias);
22137 +       return length;
22138 +}
22139 +
22140 +static inline
22141 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22142 +       char *buffer, int cpu)
22143 +{
22144 +       int length = 0;
22145 +
22146 +       length += sprintf(buffer + length,
22147 +               "cpu %d: %lld %lld %lld", cpu,
22148 +               (unsigned long long)sched_pc->user_ticks,
22149 +               (unsigned long long)sched_pc->sys_ticks,
22150 +               (unsigned long long)sched_pc->hold_ticks);
22151 +       length += sprintf(buffer + length,
22152 +               " %d\n", sched_pc->prio_bias);
22153 +       return length;
22154 +}
22155 +
22156 +#endif /* _VX_SCHED_PROC_H */
22157 diff -NurpP --minimal linux-3.7/kernel/vserver/signal.c linux-3.7-vs2.3.5.1/kernel/vserver/signal.c
22158 --- linux-3.7/kernel/vserver/signal.c   1970-01-01 00:00:00.000000000 +0000
22159 +++ linux-3.7-vs2.3.5.1/kernel/vserver/signal.c 2012-12-11 15:56:33.000000000 +0000
22160 @@ -0,0 +1,134 @@
22161 +/*
22162 + *  linux/kernel/vserver/signal.c
22163 + *
22164 + *  Virtual Server: Signal Support
22165 + *
22166 + *  Copyright (C) 2003-2007  Herbert Pötzl
22167 + *
22168 + *  V0.01  broken out from vcontext V0.05
22169 + *  V0.02  changed vcmds to vxi arg
22170 + *  V0.03  adjusted siginfo for kill
22171 + *
22172 + */
22173 +
22174 +#include <asm/uaccess.h>
22175 +
22176 +#include <linux/vs_context.h>
22177 +#include <linux/vs_pid.h>
22178 +#include <linux/vserver/signal_cmd.h>
22179 +
22180 +
22181 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22182 +{
22183 +       int retval, count = 0;
22184 +       struct task_struct *p;
22185 +       struct siginfo *sip = SEND_SIG_PRIV;
22186 +
22187 +       retval = -ESRCH;
22188 +       vxdprintk(VXD_CBIT(misc, 4),
22189 +               "vx_info_kill(%p[#%d],%d,%d)*",
22190 +               vxi, vxi->vx_id, pid, sig);
22191 +       read_lock(&tasklist_lock);
22192 +       switch (pid) {
22193 +       case  0:
22194 +       case -1:
22195 +               for_each_process(p) {
22196 +                       int err = 0;
22197 +
22198 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22199 +                               (pid && vxi->vx_initpid == p->pid))
22200 +                               continue;
22201 +
22202 +                       err = group_send_sig_info(sig, sip, p);
22203 +                       ++count;
22204 +                       if (err != -EPERM)
22205 +                               retval = err;
22206 +               }
22207 +               break;
22208 +
22209 +       case 1:
22210 +               if (vxi->vx_initpid) {
22211 +                       pid = vxi->vx_initpid;
22212 +                       /* for now, only SIGINT to private init ... */
22213 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22214 +                               /* ... as long as there are tasks left */
22215 +                               (atomic_read(&vxi->vx_tasks) > 1))
22216 +                               sig = SIGINT;
22217 +               }
22218 +               /* fallthrough */
22219 +       default:
22220 +               rcu_read_lock();
22221 +               p = find_task_by_real_pid(pid);
22222 +               rcu_read_unlock();
22223 +               if (p) {
22224 +                       if (vx_task_xid(p) == vxi->vx_id)
22225 +                               retval = group_send_sig_info(sig, sip, p);
22226 +               }
22227 +               break;
22228 +       }
22229 +       read_unlock(&tasklist_lock);
22230 +       vxdprintk(VXD_CBIT(misc, 4),
22231 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22232 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22233 +       return retval;
22234 +}
22235 +
22236 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22237 +{
22238 +       struct vcmd_ctx_kill_v0 vc_data;
22239 +
22240 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22241 +               return -EFAULT;
22242 +
22243 +       /* special check to allow guest shutdown */
22244 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22245 +               /* forbid killall pid=0 when init is present */
22246 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22247 +               (vc_data.pid > 1)))
22248 +               return -EACCES;
22249 +
22250 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22251 +}
22252 +
22253 +
22254 +static int __wait_exit(struct vx_info *vxi)
22255 +{
22256 +       DECLARE_WAITQUEUE(wait, current);
22257 +       int ret = 0;
22258 +
22259 +       add_wait_queue(&vxi->vx_wait, &wait);
22260 +       set_current_state(TASK_INTERRUPTIBLE);
22261 +
22262 +wait:
22263 +       if (vx_info_state(vxi,
22264 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22265 +               goto out;
22266 +       if (signal_pending(current)) {
22267 +               ret = -ERESTARTSYS;
22268 +               goto out;
22269 +       }
22270 +       schedule();
22271 +       goto wait;
22272 +
22273 +out:
22274 +       set_current_state(TASK_RUNNING);
22275 +       remove_wait_queue(&vxi->vx_wait, &wait);
22276 +       return ret;
22277 +}
22278 +
22279 +
22280 +
22281 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22282 +{
22283 +       struct vcmd_wait_exit_v0 vc_data;
22284 +       int ret;
22285 +
22286 +       ret = __wait_exit(vxi);
22287 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22288 +       vc_data.exit_code = vxi->exit_code;
22289 +
22290 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22291 +               ret = -EFAULT;
22292 +       return ret;
22293 +}
22294 +
22295 diff -NurpP --minimal linux-3.7/kernel/vserver/space.c linux-3.7-vs2.3.5.1/kernel/vserver/space.c
22296 --- linux-3.7/kernel/vserver/space.c    1970-01-01 00:00:00.000000000 +0000
22297 +++ linux-3.7-vs2.3.5.1/kernel/vserver/space.c  2012-12-11 21:15:48.000000000 +0000
22298 @@ -0,0 +1,436 @@
22299 +/*
22300 + *  linux/kernel/vserver/space.c
22301 + *
22302 + *  Virtual Server: Context Space Support
22303 + *
22304 + *  Copyright (C) 2003-2010  Herbert Pötzl
22305 + *
22306 + *  V0.01  broken out from context.c 0.07
22307 + *  V0.02  added task locking for namespace
22308 + *  V0.03  broken out vx_enter_namespace
22309 + *  V0.04  added *space support and commands
22310 + *  V0.05  added credential support
22311 + *
22312 + */
22313 +
22314 +#include <linux/utsname.h>
22315 +#include <linux/nsproxy.h>
22316 +#include <linux/err.h>
22317 +#include <linux/fs_struct.h>
22318 +#include <linux/cred.h>
22319 +#include <asm/uaccess.h>
22320 +
22321 +#include <linux/vs_context.h>
22322 +#include <linux/vserver/space.h>
22323 +#include <linux/vserver/space_cmd.h>
22324 +
22325 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22326 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22327 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22328 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22329 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22330 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22331 +
22332 +
22333 +/* namespace functions */
22334 +
22335 +#include <linux/mnt_namespace.h>
22336 +#include <linux/user_namespace.h>
22337 +#include <linux/pid_namespace.h>
22338 +#include <linux/ipc_namespace.h>
22339 +#include <net/net_namespace.h>
22340 +#include "../fs/mount.h"
22341 +
22342 +
22343 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22344 +       .mask = CLONE_FS |
22345 +               CLONE_NEWNS |
22346 +#ifdef CONFIG_UTS_NS
22347 +               CLONE_NEWUTS |
22348 +#endif
22349 +#ifdef CONFIG_IPC_NS
22350 +               CLONE_NEWIPC |
22351 +#endif
22352 +#ifdef CONFIG_USER_NS
22353 +               CLONE_NEWUSER |
22354 +#endif
22355 +               0
22356 +};
22357 +
22358 +static const struct vcmd_space_mask_v1 space_mask = {
22359 +       .mask = CLONE_FS |
22360 +               CLONE_NEWNS |
22361 +#ifdef CONFIG_UTS_NS
22362 +               CLONE_NEWUTS |
22363 +#endif
22364 +#ifdef CONFIG_IPC_NS
22365 +               CLONE_NEWIPC |
22366 +#endif
22367 +#ifdef CONFIG_USER_NS
22368 +               CLONE_NEWUSER |
22369 +#endif
22370 +#ifdef CONFIG_PID_NS
22371 +               CLONE_NEWPID |
22372 +#endif
22373 +#ifdef CONFIG_NET_NS
22374 +               CLONE_NEWNET |
22375 +#endif
22376 +               0
22377 +};
22378 +
22379 +static const struct vcmd_space_mask_v1 default_space_mask = {
22380 +       .mask = CLONE_FS |
22381 +               CLONE_NEWNS |
22382 +#ifdef CONFIG_UTS_NS
22383 +               CLONE_NEWUTS |
22384 +#endif
22385 +#ifdef CONFIG_IPC_NS
22386 +               CLONE_NEWIPC |
22387 +#endif
22388 +#ifdef CONFIG_USER_NS
22389 +               CLONE_NEWUSER |
22390 +#endif
22391 +#ifdef CONFIG_PID_NS
22392 +//             CLONE_NEWPID |
22393 +#endif
22394 +               0
22395 +};
22396 +
22397 +/*
22398 + *     build a new nsproxy mix
22399 + *      assumes that both proxies are 'const'
22400 + *     does not touch nsproxy refcounts
22401 + *     will hold a reference on the result.
22402 + */
22403 +
22404 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22405 +       struct nsproxy *new_nsproxy, unsigned long mask)
22406 +{
22407 +       struct mnt_namespace *old_ns;
22408 +       struct uts_namespace *old_uts;
22409 +       struct ipc_namespace *old_ipc;
22410 +#ifdef CONFIG_PID_NS
22411 +       struct pid_namespace *old_pid;
22412 +#endif
22413 +#ifdef CONFIG_NET_NS
22414 +       struct net *old_net;
22415 +#endif
22416 +       struct nsproxy *nsproxy;
22417 +
22418 +       nsproxy = copy_nsproxy(old_nsproxy);
22419 +       if (!nsproxy)
22420 +               goto out;
22421 +
22422 +       if (mask & CLONE_NEWNS) {
22423 +               old_ns = nsproxy->mnt_ns;
22424 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22425 +               if (nsproxy->mnt_ns)
22426 +                       get_mnt_ns(nsproxy->mnt_ns);
22427 +       } else
22428 +               old_ns = NULL;
22429 +
22430 +       if (mask & CLONE_NEWUTS) {
22431 +               old_uts = nsproxy->uts_ns;
22432 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22433 +               if (nsproxy->uts_ns)
22434 +                       get_uts_ns(nsproxy->uts_ns);
22435 +       } else
22436 +               old_uts = NULL;
22437 +
22438 +       if (mask & CLONE_NEWIPC) {
22439 +               old_ipc = nsproxy->ipc_ns;
22440 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22441 +               if (nsproxy->ipc_ns)
22442 +                       get_ipc_ns(nsproxy->ipc_ns);
22443 +       } else
22444 +               old_ipc = NULL;
22445 +
22446 +#ifdef CONFIG_PID_NS
22447 +       if (mask & CLONE_NEWPID) {
22448 +               old_pid = nsproxy->pid_ns;
22449 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22450 +               if (nsproxy->pid_ns)
22451 +                       get_pid_ns(nsproxy->pid_ns);
22452 +       } else
22453 +               old_pid = NULL;
22454 +#endif
22455 +#ifdef CONFIG_NET_NS
22456 +       if (mask & CLONE_NEWNET) {
22457 +               old_net = nsproxy->net_ns;
22458 +               nsproxy->net_ns = new_nsproxy->net_ns;
22459 +               if (nsproxy->net_ns)
22460 +                       get_net(nsproxy->net_ns);
22461 +       } else
22462 +               old_net = NULL;
22463 +#endif
22464 +       if (old_ns)
22465 +               put_mnt_ns(old_ns);
22466 +       if (old_uts)
22467 +               put_uts_ns(old_uts);
22468 +       if (old_ipc)
22469 +               put_ipc_ns(old_ipc);
22470 +#ifdef CONFIG_PID_NS
22471 +       if (old_pid)
22472 +               put_pid_ns(old_pid);
22473 +#endif
22474 +#ifdef CONFIG_NET_NS
22475 +       if (old_net)
22476 +               put_net(old_net);
22477 +#endif
22478 +out:
22479 +       return nsproxy;
22480 +}
22481 +
22482 +
22483 +/*
22484 + *     merge two nsproxy structs into a new one.
22485 + *     will hold a reference on the result.
22486 + */
22487 +
22488 +static inline
22489 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22490 +       struct nsproxy *proxy, unsigned long mask)
22491 +{
22492 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22493 +
22494 +       if (!proxy)
22495 +               return NULL;
22496 +
22497 +       if (mask) {
22498 +               /* vs_mix_nsproxy returns with reference */
22499 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22500 +                       proxy, mask);
22501 +       }
22502 +       get_nsproxy(proxy);
22503 +       return proxy;
22504 +}
22505 +
22506 +
22507 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22508 +{
22509 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22510 +       struct fs_struct *fs_cur, *fs = NULL;
22511 +       struct _vx_space *space;
22512 +       int ret, kill = 0;
22513 +
22514 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22515 +               vxi, vxi->vx_id, mask, index);
22516 +
22517 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22518 +               return -EACCES;
22519 +
22520 +       if (index >= VX_SPACES)
22521 +               return -EINVAL;
22522 +
22523 +       space = &vxi->space[index];
22524 +
22525 +       if (!mask)
22526 +               mask = space->vx_nsmask;
22527 +
22528 +       if ((mask & space->vx_nsmask) != mask)
22529 +               return -EINVAL;
22530 +
22531 +       if (mask & CLONE_FS) {
22532 +               fs = copy_fs_struct(space->vx_fs);
22533 +               if (!fs)
22534 +                       return -ENOMEM;
22535 +       }
22536 +       proxy = space->vx_nsproxy;
22537 +
22538 +       vxdprintk(VXD_CBIT(space, 9),
22539 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22540 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22541 +
22542 +       task_lock(current);
22543 +       fs_cur = current->fs;
22544 +
22545 +       if (mask & CLONE_FS) {
22546 +               spin_lock(&fs_cur->lock);
22547 +               current->fs = fs;
22548 +               kill = !--fs_cur->users;
22549 +               spin_unlock(&fs_cur->lock);
22550 +       }
22551 +
22552 +       proxy_cur = current->nsproxy;
22553 +       get_nsproxy(proxy_cur);
22554 +       task_unlock(current);
22555 +
22556 +       if (kill)
22557 +               free_fs_struct(fs_cur);
22558 +
22559 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22560 +       if (IS_ERR(proxy_new)) {
22561 +               ret = PTR_ERR(proxy_new);
22562 +               goto out_put;
22563 +       }
22564 +
22565 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22566 +
22567 +       if (mask & CLONE_NEWUSER) {
22568 +               struct cred *cred;
22569 +
22570 +               vxdprintk(VXD_CBIT(space, 10),
22571 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22572 +                       vxi, vxi->vx_id, space->vx_cred,
22573 +                       current->real_cred, current->cred);
22574 +
22575 +               if (space->vx_cred) {
22576 +                       cred = __prepare_creds(space->vx_cred);
22577 +                       if (cred)
22578 +                               commit_creds(cred);
22579 +               }
22580 +       }
22581 +
22582 +       ret = 0;
22583 +
22584 +       if (proxy_new)
22585 +               put_nsproxy(proxy_new);
22586 +out_put:
22587 +       if (proxy_cur)
22588 +               put_nsproxy(proxy_cur);
22589 +       return ret;
22590 +}
22591 +
22592 +
22593 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22594 +{
22595 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22596 +       struct fs_struct *fs_vxi, *fs = NULL;
22597 +       struct _vx_space *space;
22598 +       int ret, kill = 0;
22599 +
22600 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22601 +               vxi, vxi->vx_id, mask, index);
22602 +
22603 +       if ((mask & space_mask.mask) != mask)
22604 +               return -EINVAL;
22605 +
22606 +       if (index >= VX_SPACES)
22607 +               return -EINVAL;
22608 +
22609 +       space = &vxi->space[index];
22610 +
22611 +       proxy_vxi = space->vx_nsproxy;
22612 +       fs_vxi = space->vx_fs;
22613 +
22614 +       if (mask & CLONE_FS) {
22615 +               fs = copy_fs_struct(current->fs);
22616 +               if (!fs)
22617 +                       return -ENOMEM;
22618 +       }
22619 +
22620 +       task_lock(current);
22621 +
22622 +       if (mask & CLONE_FS) {
22623 +               spin_lock(&fs_vxi->lock);
22624 +               space->vx_fs = fs;
22625 +               kill = !--fs_vxi->users;
22626 +               spin_unlock(&fs_vxi->lock);
22627 +       }
22628 +
22629 +       proxy_cur = current->nsproxy;
22630 +       get_nsproxy(proxy_cur);
22631 +       task_unlock(current);
22632 +
22633 +       if (kill)
22634 +               free_fs_struct(fs_vxi);
22635 +
22636 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22637 +       if (IS_ERR(proxy_new)) {
22638 +               ret = PTR_ERR(proxy_new);
22639 +               goto out_put;
22640 +       }
22641 +
22642 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22643 +       space->vx_nsmask |= mask;
22644 +
22645 +       if (mask & CLONE_NEWUSER) {
22646 +               struct cred *cred;
22647 +
22648 +               vxdprintk(VXD_CBIT(space, 10),
22649 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22650 +                       vxi, vxi->vx_id, space->vx_cred,
22651 +                       current->real_cred, current->cred);
22652 +
22653 +               cred = prepare_creds();
22654 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22655 +               if (cred)
22656 +                       abort_creds(cred);
22657 +       }
22658 +
22659 +       ret = 0;
22660 +
22661 +       if (proxy_new)
22662 +               put_nsproxy(proxy_new);
22663 +out_put:
22664 +       if (proxy_cur)
22665 +               put_nsproxy(proxy_cur);
22666 +       return ret;
22667 +}
22668 +
22669 +
22670 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22671 +{
22672 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22673 +
22674 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22675 +               return -EFAULT;
22676 +
22677 +       return vx_enter_space(vxi, vc_data.mask, 0);
22678 +}
22679 +
22680 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22681 +{
22682 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22683 +
22684 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22685 +               return -EFAULT;
22686 +
22687 +       if (vc_data.index >= VX_SPACES)
22688 +               return -EINVAL;
22689 +
22690 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22691 +}
22692 +
22693 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22694 +{
22695 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22696 +
22697 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22698 +               return -EFAULT;
22699 +
22700 +       return vx_set_space(vxi, vc_data.mask, 0);
22701 +}
22702 +
22703 +int vc_set_space(struct vx_info *vxi, void __user *data)
22704 +{
22705 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22706 +
22707 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22708 +               return -EFAULT;
22709 +
22710 +       if (vc_data.index >= VX_SPACES)
22711 +               return -EINVAL;
22712 +
22713 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22714 +}
22715 +
22716 +int vc_get_space_mask(void __user *data, int type)
22717 +{
22718 +       const struct vcmd_space_mask_v1 *mask;
22719 +
22720 +       if (type == 0)
22721 +               mask = &space_mask_v0;
22722 +       else if (type == 1)
22723 +               mask = &space_mask;
22724 +       else
22725 +               mask = &default_space_mask;
22726 +
22727 +       vxdprintk(VXD_CBIT(space, 10),
22728 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22729 +
22730 +       if (copy_to_user(data, mask, sizeof(*mask)))
22731 +               return -EFAULT;
22732 +       return 0;
22733 +}
22734 +
22735 diff -NurpP --minimal linux-3.7/kernel/vserver/switch.c linux-3.7-vs2.3.5.1/kernel/vserver/switch.c
22736 --- linux-3.7/kernel/vserver/switch.c   1970-01-01 00:00:00.000000000 +0000
22737 +++ linux-3.7-vs2.3.5.1/kernel/vserver/switch.c 2012-12-11 15:56:33.000000000 +0000
22738 @@ -0,0 +1,556 @@
22739 +/*
22740 + *  linux/kernel/vserver/switch.c
22741 + *
22742 + *  Virtual Server: Syscall Switch
22743 + *
22744 + *  Copyright (C) 2003-2011  Herbert Pötzl
22745 + *
22746 + *  V0.01  syscall switch
22747 + *  V0.02  added signal to context
22748 + *  V0.03  added rlimit functions
22749 + *  V0.04  added iattr, task/xid functions
22750 + *  V0.05  added debug/history stuff
22751 + *  V0.06  added compat32 layer
22752 + *  V0.07  vcmd args and perms
22753 + *  V0.08  added status commands
22754 + *  V0.09  added tag commands
22755 + *  V0.10  added oom bias
22756 + *  V0.11  added device commands
22757 + *  V0.12  added warn mask
22758 + *
22759 + */
22760 +
22761 +#include <linux/vs_context.h>
22762 +#include <linux/vs_network.h>
22763 +#include <linux/vserver/switch.h>
22764 +
22765 +#include "vci_config.h"
22766 +
22767 +
22768 +static inline
22769 +int vc_get_version(uint32_t id)
22770 +{
22771 +       return VCI_VERSION;
22772 +}
22773 +
22774 +static inline
22775 +int vc_get_vci(uint32_t id)
22776 +{
22777 +       return vci_kernel_config();
22778 +}
22779 +
22780 +#include <linux/vserver/context_cmd.h>
22781 +#include <linux/vserver/cvirt_cmd.h>
22782 +#include <linux/vserver/cacct_cmd.h>
22783 +#include <linux/vserver/limit_cmd.h>
22784 +#include <linux/vserver/network_cmd.h>
22785 +#include <linux/vserver/sched_cmd.h>
22786 +#include <linux/vserver/debug_cmd.h>
22787 +#include <linux/vserver/inode_cmd.h>
22788 +#include <linux/vserver/dlimit_cmd.h>
22789 +#include <linux/vserver/signal_cmd.h>
22790 +#include <linux/vserver/space_cmd.h>
22791 +#include <linux/vserver/tag_cmd.h>
22792 +#include <linux/vserver/device_cmd.h>
22793 +
22794 +#include <linux/vserver/inode.h>
22795 +#include <linux/vserver/dlimit.h>
22796 +
22797 +
22798 +#ifdef CONFIG_COMPAT
22799 +#define __COMPAT(name, id, data, compat)       \
22800 +       (compat) ? name ## _x32(id, data) : name(id, data)
22801 +#define __COMPAT_NO_ID(name, data, compat)     \
22802 +       (compat) ? name ## _x32(data) : name(data)
22803 +#else
22804 +#define __COMPAT(name, id, data, compat)       \
22805 +       name(id, data)
22806 +#define __COMPAT_NO_ID(name, data, compat)     \
22807 +       name(data)
22808 +#endif
22809 +
22810 +
22811 +static inline
22812 +long do_vcmd(uint32_t cmd, uint32_t id,
22813 +       struct vx_info *vxi, struct nx_info *nxi,
22814 +       void __user *data, int compat)
22815 +{
22816 +       switch (cmd) {
22817 +
22818 +       case VCMD_get_version:
22819 +               return vc_get_version(id);
22820 +       case VCMD_get_vci:
22821 +               return vc_get_vci(id);
22822 +
22823 +       case VCMD_task_xid:
22824 +               return vc_task_xid(id);
22825 +       case VCMD_vx_info:
22826 +               return vc_vx_info(vxi, data);
22827 +
22828 +       case VCMD_task_nid:
22829 +               return vc_task_nid(id);
22830 +       case VCMD_nx_info:
22831 +               return vc_nx_info(nxi, data);
22832 +
22833 +       case VCMD_task_tag:
22834 +               return vc_task_tag(id);
22835 +
22836 +       case VCMD_set_space_v1:
22837 +               return vc_set_space_v1(vxi, data);
22838 +       /* this is version 2 */
22839 +       case VCMD_set_space:
22840 +               return vc_set_space(vxi, data);
22841 +
22842 +       case VCMD_get_space_mask_v0:
22843 +               return vc_get_space_mask(data, 0);
22844 +       /* this is version 1 */
22845 +       case VCMD_get_space_mask:
22846 +               return vc_get_space_mask(data, 1);
22847 +
22848 +       case VCMD_get_space_default:
22849 +               return vc_get_space_mask(data, -1);
22850 +
22851 +       case VCMD_set_umask:
22852 +               return vc_set_umask(vxi, data);
22853 +
22854 +       case VCMD_get_umask:
22855 +               return vc_get_umask(vxi, data);
22856 +
22857 +       case VCMD_set_wmask:
22858 +               return vc_set_wmask(vxi, data);
22859 +
22860 +       case VCMD_get_wmask:
22861 +               return vc_get_wmask(vxi, data);
22862 +#ifdef CONFIG_IA32_EMULATION
22863 +       case VCMD_get_rlimit:
22864 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22865 +       case VCMD_set_rlimit:
22866 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22867 +#else
22868 +       case VCMD_get_rlimit:
22869 +               return vc_get_rlimit(vxi, data);
22870 +       case VCMD_set_rlimit:
22871 +               return vc_set_rlimit(vxi, data);
22872 +#endif
22873 +       case VCMD_get_rlimit_mask:
22874 +               return vc_get_rlimit_mask(id, data);
22875 +       case VCMD_reset_hits:
22876 +               return vc_reset_hits(vxi, data);
22877 +       case VCMD_reset_minmax:
22878 +               return vc_reset_minmax(vxi, data);
22879 +
22880 +       case VCMD_get_vhi_name:
22881 +               return vc_get_vhi_name(vxi, data);
22882 +       case VCMD_set_vhi_name:
22883 +               return vc_set_vhi_name(vxi, data);
22884 +
22885 +       case VCMD_ctx_stat:
22886 +               return vc_ctx_stat(vxi, data);
22887 +       case VCMD_virt_stat:
22888 +               return vc_virt_stat(vxi, data);
22889 +       case VCMD_sock_stat:
22890 +               return vc_sock_stat(vxi, data);
22891 +       case VCMD_rlimit_stat:
22892 +               return vc_rlimit_stat(vxi, data);
22893 +
22894 +       case VCMD_set_cflags:
22895 +               return vc_set_cflags(vxi, data);
22896 +       case VCMD_get_cflags:
22897 +               return vc_get_cflags(vxi, data);
22898 +
22899 +       /* this is version 1 */
22900 +       case VCMD_set_ccaps:
22901 +               return vc_set_ccaps(vxi, data);
22902 +       /* this is version 1 */
22903 +       case VCMD_get_ccaps:
22904 +               return vc_get_ccaps(vxi, data);
22905 +       case VCMD_set_bcaps:
22906 +               return vc_set_bcaps(vxi, data);
22907 +       case VCMD_get_bcaps:
22908 +               return vc_get_bcaps(vxi, data);
22909 +
22910 +       case VCMD_set_badness:
22911 +               return vc_set_badness(vxi, data);
22912 +       case VCMD_get_badness:
22913 +               return vc_get_badness(vxi, data);
22914 +
22915 +       case VCMD_set_nflags:
22916 +               return vc_set_nflags(nxi, data);
22917 +       case VCMD_get_nflags:
22918 +               return vc_get_nflags(nxi, data);
22919 +
22920 +       case VCMD_set_ncaps:
22921 +               return vc_set_ncaps(nxi, data);
22922 +       case VCMD_get_ncaps:
22923 +               return vc_get_ncaps(nxi, data);
22924 +
22925 +       case VCMD_set_prio_bias:
22926 +               return vc_set_prio_bias(vxi, data);
22927 +       case VCMD_get_prio_bias:
22928 +               return vc_get_prio_bias(vxi, data);
22929 +       case VCMD_add_dlimit:
22930 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22931 +       case VCMD_rem_dlimit:
22932 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22933 +       case VCMD_set_dlimit:
22934 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22935 +       case VCMD_get_dlimit:
22936 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22937 +
22938 +       case VCMD_ctx_kill:
22939 +               return vc_ctx_kill(vxi, data);
22940 +
22941 +       case VCMD_wait_exit:
22942 +               return vc_wait_exit(vxi, data);
22943 +
22944 +       case VCMD_get_iattr:
22945 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22946 +       case VCMD_set_iattr:
22947 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22948 +
22949 +       case VCMD_fget_iattr:
22950 +               return vc_fget_iattr(id, data);
22951 +       case VCMD_fset_iattr:
22952 +               return vc_fset_iattr(id, data);
22953 +
22954 +       case VCMD_enter_space_v0:
22955 +               return vc_enter_space_v1(vxi, NULL);
22956 +       case VCMD_enter_space_v1:
22957 +               return vc_enter_space_v1(vxi, data);
22958 +       /* this is version 2 */
22959 +       case VCMD_enter_space:
22960 +               return vc_enter_space(vxi, data);
22961 +
22962 +       case VCMD_ctx_create_v0:
22963 +               return vc_ctx_create(id, NULL);
22964 +       case VCMD_ctx_create:
22965 +               return vc_ctx_create(id, data);
22966 +       case VCMD_ctx_migrate_v0:
22967 +               return vc_ctx_migrate(vxi, NULL);
22968 +       case VCMD_ctx_migrate:
22969 +               return vc_ctx_migrate(vxi, data);
22970 +
22971 +       case VCMD_net_create_v0:
22972 +               return vc_net_create(id, NULL);
22973 +       case VCMD_net_create:
22974 +               return vc_net_create(id, data);
22975 +       case VCMD_net_migrate:
22976 +               return vc_net_migrate(nxi, data);
22977 +
22978 +       case VCMD_tag_migrate:
22979 +               return vc_tag_migrate(id);
22980 +
22981 +       case VCMD_net_add:
22982 +               return vc_net_add(nxi, data);
22983 +       case VCMD_net_remove:
22984 +               return vc_net_remove(nxi, data);
22985 +
22986 +       case VCMD_net_add_ipv4_v1:
22987 +               return vc_net_add_ipv4_v1(nxi, data);
22988 +       /* this is version 2 */
22989 +       case VCMD_net_add_ipv4:
22990 +               return vc_net_add_ipv4(nxi, data);
22991 +
22992 +       case VCMD_net_rem_ipv4_v1:
22993 +               return vc_net_rem_ipv4_v1(nxi, data);
22994 +       /* this is version 2 */
22995 +       case VCMD_net_rem_ipv4:
22996 +               return vc_net_rem_ipv4(nxi, data);
22997 +#ifdef CONFIG_IPV6
22998 +       case VCMD_net_add_ipv6:
22999 +               return vc_net_add_ipv6(nxi, data);
23000 +       case VCMD_net_remove_ipv6:
23001 +               return vc_net_remove_ipv6(nxi, data);
23002 +#endif
23003 +/*     case VCMD_add_match_ipv4:
23004 +               return vc_add_match_ipv4(nxi, data);
23005 +       case VCMD_get_match_ipv4:
23006 +               return vc_get_match_ipv4(nxi, data);
23007 +#ifdef CONFIG_IPV6
23008 +       case VCMD_add_match_ipv6:
23009 +               return vc_add_match_ipv6(nxi, data);
23010 +       case VCMD_get_match_ipv6:
23011 +               return vc_get_match_ipv6(nxi, data);
23012 +#endif */
23013 +
23014 +#ifdef CONFIG_VSERVER_DEVICE
23015 +       case VCMD_set_mapping:
23016 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23017 +       case VCMD_unset_mapping:
23018 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23019 +#endif
23020 +#ifdef CONFIG_VSERVER_HISTORY
23021 +       case VCMD_dump_history:
23022 +               return vc_dump_history(id);
23023 +       case VCMD_read_history:
23024 +               return __COMPAT(vc_read_history, id, data, compat);
23025 +#endif
23026 +       default:
23027 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23028 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23029 +       }
23030 +       return -ENOSYS;
23031 +}
23032 +
23033 +
23034 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23035 +       case VCMD_ ## vcmd: perm = _perm;               \
23036 +               args = _args; flags = _flags; break
23037 +
23038 +
23039 +#define VCA_NONE       0x00
23040 +#define VCA_VXI                0x01
23041 +#define VCA_NXI                0x02
23042 +
23043 +#define VCF_NONE       0x00
23044 +#define VCF_INFO       0x01
23045 +#define VCF_ADMIN      0x02
23046 +#define VCF_ARES       0x06    /* includes admin */
23047 +#define VCF_SETUP      0x08
23048 +
23049 +#define VCF_ZIDOK      0x10    /* zero id okay */
23050 +
23051 +
23052 +static inline
23053 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23054 +{
23055 +       long ret;
23056 +       int permit = -1, state = 0;
23057 +       int perm = -1, args = 0, flags = 0;
23058 +       struct vx_info *vxi = NULL;
23059 +       struct nx_info *nxi = NULL;
23060 +
23061 +       switch (cmd) {
23062 +       /* unpriviledged commands */
23063 +       __VCMD(get_version,      0, VCA_NONE,   0);
23064 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23065 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23066 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23067 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23068 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23069 +
23070 +       /* info commands */
23071 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23072 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23073 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23074 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23075 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23076 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23077 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23078 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23079 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23080 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23081 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23082 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23083 +
23084 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23085 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23086 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23087 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23088 +
23089 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23090 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23091 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23092 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23093 +
23094 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23095 +
23096 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23097 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23098 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23099 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23100 +
23101 +       /* lower admin commands */
23102 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23103 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23104 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23105 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23106 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23107 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23108 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23109 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23110 +
23111 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23112 +       __VCMD(net_create,       5, VCA_NONE,   0);
23113 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23114 +
23115 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23116 +
23117 +       /* higher admin commands */
23118 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23119 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23120 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23121 +
23122 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23123 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23124 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23125 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23126 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23127 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23128 +
23129 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23130 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23131 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23132 +
23133 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23134 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23135 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23136 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23137 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23138 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23139 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23140 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23141 +#ifdef CONFIG_IPV6
23142 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23143 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23144 +#endif
23145 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23146 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23147 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23148 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23149 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23150 +
23151 +#ifdef CONFIG_VSERVER_DEVICE
23152 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23153 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23154 +#endif
23155 +       /* debug level admin commands */
23156 +#ifdef CONFIG_VSERVER_HISTORY
23157 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23158 +       __VCMD(read_history,     9, VCA_NONE,   0);
23159 +#endif
23160 +
23161 +       default:
23162 +               perm = -1;
23163 +       }
23164 +
23165 +       vxdprintk(VXD_CBIT(switch, 0),
23166 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23167 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23168 +               VC_VERSION(cmd), id, data, compat,
23169 +               perm, args, flags);
23170 +
23171 +       ret = -ENOSYS;
23172 +       if (perm < 0)
23173 +               goto out;
23174 +
23175 +       state = 1;
23176 +       if (!capable(CAP_CONTEXT))
23177 +               goto out;
23178 +
23179 +       state = 2;
23180 +       /* moved here from the individual commands */
23181 +       ret = -EPERM;
23182 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23183 +               goto out;
23184 +
23185 +       state = 3;
23186 +       /* vcmd involves resource management  */
23187 +       ret = -EPERM;
23188 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23189 +               goto out;
23190 +
23191 +       state = 4;
23192 +       /* various legacy exceptions */
23193 +       switch (cmd) {
23194 +       /* will go away when spectator is a cap */
23195 +       case VCMD_ctx_migrate_v0:
23196 +       case VCMD_ctx_migrate:
23197 +               if (id == 1) {
23198 +                       current->xid = 1;
23199 +                       ret = 1;
23200 +                       goto out;
23201 +               }
23202 +               break;
23203 +
23204 +       /* will go away when spectator is a cap */
23205 +       case VCMD_net_migrate:
23206 +               if (id == 1) {
23207 +                       current->nid = 1;
23208 +                       ret = 1;
23209 +                       goto out;
23210 +               }
23211 +               break;
23212 +       }
23213 +
23214 +       /* vcmds are fine by default */
23215 +       permit = 1;
23216 +
23217 +       /* admin type vcmds require admin ... */
23218 +       if (flags & VCF_ADMIN)
23219 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23220 +
23221 +       /* ... but setup type vcmds override that */
23222 +       if (!permit && (flags & VCF_SETUP))
23223 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23224 +
23225 +       state = 5;
23226 +       ret = -EPERM;
23227 +       if (!permit)
23228 +               goto out;
23229 +
23230 +       state = 6;
23231 +       if (!id && (flags & VCF_ZIDOK))
23232 +               goto skip_id;
23233 +
23234 +       ret = -ESRCH;
23235 +       if (args & VCA_VXI) {
23236 +               vxi = lookup_vx_info(id);
23237 +               if (!vxi)
23238 +                       goto out;
23239 +
23240 +               if ((flags & VCF_ADMIN) &&
23241 +                       /* special case kill for shutdown */
23242 +                       (cmd != VCMD_ctx_kill) &&
23243 +                       /* can context be administrated? */
23244 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23245 +                       ret = -EACCES;
23246 +                       goto out_vxi;
23247 +               }
23248 +       }
23249 +       state = 7;
23250 +       if (args & VCA_NXI) {
23251 +               nxi = lookup_nx_info(id);
23252 +               if (!nxi)
23253 +                       goto out_vxi;
23254 +
23255 +               if ((flags & VCF_ADMIN) &&
23256 +                       /* can context be administrated? */
23257 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23258 +                       ret = -EACCES;
23259 +                       goto out_nxi;
23260 +               }
23261 +       }
23262 +skip_id:
23263 +       state = 8;
23264 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23265 +
23266 +out_nxi:
23267 +       if ((args & VCA_NXI) && nxi)
23268 +               put_nx_info(nxi);
23269 +out_vxi:
23270 +       if ((args & VCA_VXI) && vxi)
23271 +               put_vx_info(vxi);
23272 +out:
23273 +       vxdprintk(VXD_CBIT(switch, 1),
23274 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23275 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23276 +               VC_VERSION(cmd), ret, ret, state, permit);
23277 +       return ret;
23278 +}
23279 +
23280 +asmlinkage long
23281 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23282 +{
23283 +       return do_vserver(cmd, id, data, 0);
23284 +}
23285 +
23286 +#ifdef CONFIG_COMPAT
23287 +
23288 +asmlinkage long
23289 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23290 +{
23291 +       return do_vserver(cmd, id, data, 1);
23292 +}
23293 +
23294 +#endif /* CONFIG_COMPAT */
23295 diff -NurpP --minimal linux-3.7/kernel/vserver/sysctl.c linux-3.7-vs2.3.5.1/kernel/vserver/sysctl.c
23296 --- linux-3.7/kernel/vserver/sysctl.c   1970-01-01 00:00:00.000000000 +0000
23297 +++ linux-3.7-vs2.3.5.1/kernel/vserver/sysctl.c 2012-12-11 15:56:33.000000000 +0000
23298 @@ -0,0 +1,247 @@
23299 +/*
23300 + *  kernel/vserver/sysctl.c
23301 + *
23302 + *  Virtual Context Support
23303 + *
23304 + *  Copyright (C) 2004-2007  Herbert Pötzl
23305 + *
23306 + *  V0.01  basic structure
23307 + *
23308 + */
23309 +
23310 +#include <linux/module.h>
23311 +#include <linux/ctype.h>
23312 +#include <linux/sysctl.h>
23313 +#include <linux/parser.h>
23314 +#include <asm/uaccess.h>
23315 +
23316 +enum {
23317 +       CTL_DEBUG_ERROR         = 0,
23318 +       CTL_DEBUG_SWITCH        = 1,
23319 +       CTL_DEBUG_XID,
23320 +       CTL_DEBUG_NID,
23321 +       CTL_DEBUG_TAG,
23322 +       CTL_DEBUG_NET,
23323 +       CTL_DEBUG_LIMIT,
23324 +       CTL_DEBUG_CRES,
23325 +       CTL_DEBUG_DLIM,
23326 +       CTL_DEBUG_QUOTA,
23327 +       CTL_DEBUG_CVIRT,
23328 +       CTL_DEBUG_SPACE,
23329 +       CTL_DEBUG_PERM,
23330 +       CTL_DEBUG_MISC,
23331 +};
23332 +
23333 +
23334 +unsigned int vs_debug_switch   = 0;
23335 +unsigned int vs_debug_xid      = 0;
23336 +unsigned int vs_debug_nid      = 0;
23337 +unsigned int vs_debug_tag      = 0;
23338 +unsigned int vs_debug_net      = 0;
23339 +unsigned int vs_debug_limit    = 0;
23340 +unsigned int vs_debug_cres     = 0;
23341 +unsigned int vs_debug_dlim     = 0;
23342 +unsigned int vs_debug_quota    = 0;
23343 +unsigned int vs_debug_cvirt    = 0;
23344 +unsigned int vs_debug_space    = 0;
23345 +unsigned int vs_debug_perm     = 0;
23346 +unsigned int vs_debug_misc     = 0;
23347 +
23348 +
23349 +static struct ctl_table_header *vserver_table_header;
23350 +static ctl_table vserver_root_table[];
23351 +
23352 +
23353 +void vserver_register_sysctl(void)
23354 +{
23355 +       if (!vserver_table_header) {
23356 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23357 +       }
23358 +
23359 +}
23360 +
23361 +void vserver_unregister_sysctl(void)
23362 +{
23363 +       if (vserver_table_header) {
23364 +               unregister_sysctl_table(vserver_table_header);
23365 +               vserver_table_header = NULL;
23366 +       }
23367 +}
23368 +
23369 +
23370 +static int proc_dodebug(ctl_table *table, int write,
23371 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23372 +{
23373 +       char            tmpbuf[20], *p, c;
23374 +       unsigned int    value;
23375 +       size_t          left, len;
23376 +
23377 +       if ((*ppos && !write) || !*lenp) {
23378 +               *lenp = 0;
23379 +               return 0;
23380 +       }
23381 +
23382 +       left = *lenp;
23383 +
23384 +       if (write) {
23385 +               if (!access_ok(VERIFY_READ, buffer, left))
23386 +                       return -EFAULT;
23387 +               p = (char *)buffer;
23388 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23389 +                       left--, p++;
23390 +               if (!left)
23391 +                       goto done;
23392 +
23393 +               if (left > sizeof(tmpbuf) - 1)
23394 +                       return -EINVAL;
23395 +               if (copy_from_user(tmpbuf, p, left))
23396 +                       return -EFAULT;
23397 +               tmpbuf[left] = '\0';
23398 +
23399 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23400 +                       value = 10 * value + (*p - '0');
23401 +               if (*p && !isspace(*p))
23402 +                       return -EINVAL;
23403 +               while (left && isspace(*p))
23404 +                       left--, p++;
23405 +               *(unsigned int *)table->data = value;
23406 +       } else {
23407 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23408 +                       return -EFAULT;
23409 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23410 +               if (len > left)
23411 +                       len = left;
23412 +               if (__copy_to_user(buffer, tmpbuf, len))
23413 +                       return -EFAULT;
23414 +               if ((left -= len) > 0) {
23415 +                       if (put_user('\n', (char *)buffer + len))
23416 +                               return -EFAULT;
23417 +                       left--;
23418 +               }
23419 +       }
23420 +
23421 +done:
23422 +       *lenp -= left;
23423 +       *ppos += *lenp;
23424 +       return 0;
23425 +}
23426 +
23427 +static int zero;
23428 +
23429 +#define        CTL_ENTRY(ctl, name)                            \
23430 +       {                                               \
23431 +               .procname       = #name,                \
23432 +               .data           = &vs_ ## name,         \
23433 +               .maxlen         = sizeof(int),          \
23434 +               .mode           = 0644,                 \
23435 +               .proc_handler   = &proc_dodebug,        \
23436 +               .extra1         = &zero,                \
23437 +               .extra2         = &zero,                \
23438 +       }
23439 +
23440 +static ctl_table vserver_debug_table[] = {
23441 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23442 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23443 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23444 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23445 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23446 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23447 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23448 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23449 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23450 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23451 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23452 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23453 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23454 +       { 0 }
23455 +};
23456 +
23457 +static ctl_table vserver_root_table[] = {
23458 +       {
23459 +               .procname       = "vserver",
23460 +               .mode           = 0555,
23461 +               .child          = vserver_debug_table
23462 +       },
23463 +       { 0 }
23464 +};
23465 +
23466 +
23467 +static match_table_t tokens = {
23468 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23469 +       { CTL_DEBUG_XID,        "xid=%x"        },
23470 +       { CTL_DEBUG_NID,        "nid=%x"        },
23471 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23472 +       { CTL_DEBUG_NET,        "net=%x"        },
23473 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23474 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23475 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23476 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23477 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23478 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23479 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23480 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23481 +       { CTL_DEBUG_ERROR,      NULL            }
23482 +};
23483 +
23484 +#define        HANDLE_CASE(id, name, val)                              \
23485 +       case CTL_DEBUG_ ## id:                                  \
23486 +               vs_debug_ ## name = val;                        \
23487 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23488 +               break
23489 +
23490 +
23491 +static int __init vs_debug_setup(char *str)
23492 +{
23493 +       char *p;
23494 +       int token;
23495 +
23496 +       printk("vs_debug_setup(%s)\n", str);
23497 +       while ((p = strsep(&str, ",")) != NULL) {
23498 +               substring_t args[MAX_OPT_ARGS];
23499 +               unsigned int value;
23500 +
23501 +               if (!*p)
23502 +                       continue;
23503 +
23504 +               token = match_token(p, tokens, args);
23505 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23506 +
23507 +               switch (token) {
23508 +               HANDLE_CASE(SWITCH, switch, value);
23509 +               HANDLE_CASE(XID,    xid,    value);
23510 +               HANDLE_CASE(NID,    nid,    value);
23511 +               HANDLE_CASE(TAG,    tag,    value);
23512 +               HANDLE_CASE(NET,    net,    value);
23513 +               HANDLE_CASE(LIMIT,  limit,  value);
23514 +               HANDLE_CASE(CRES,   cres,   value);
23515 +               HANDLE_CASE(DLIM,   dlim,   value);
23516 +               HANDLE_CASE(QUOTA,  quota,  value);
23517 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23518 +               HANDLE_CASE(SPACE,  space,  value);
23519 +               HANDLE_CASE(PERM,   perm,   value);
23520 +               HANDLE_CASE(MISC,   misc,   value);
23521 +               default:
23522 +                       return -EINVAL;
23523 +                       break;
23524 +               }
23525 +       }
23526 +       return 1;
23527 +}
23528 +
23529 +__setup("vsdebug=", vs_debug_setup);
23530 +
23531 +
23532 +
23533 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23534 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23535 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23536 +EXPORT_SYMBOL_GPL(vs_debug_net);
23537 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23538 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23539 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23540 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23541 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23542 +EXPORT_SYMBOL_GPL(vs_debug_space);
23543 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23544 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23545 +
23546 diff -NurpP --minimal linux-3.7/kernel/vserver/tag.c linux-3.7-vs2.3.5.1/kernel/vserver/tag.c
23547 --- linux-3.7/kernel/vserver/tag.c      1970-01-01 00:00:00.000000000 +0000
23548 +++ linux-3.7-vs2.3.5.1/kernel/vserver/tag.c    2012-12-11 15:56:33.000000000 +0000
23549 @@ -0,0 +1,63 @@
23550 +/*
23551 + *  linux/kernel/vserver/tag.c
23552 + *
23553 + *  Virtual Server: Shallow Tag Space
23554 + *
23555 + *  Copyright (C) 2007  Herbert Pötzl
23556 + *
23557 + *  V0.01  basic implementation
23558 + *
23559 + */
23560 +
23561 +#include <linux/sched.h>
23562 +#include <linux/vserver/debug.h>
23563 +#include <linux/vs_pid.h>
23564 +#include <linux/vs_tag.h>
23565 +
23566 +#include <linux/vserver/tag_cmd.h>
23567 +
23568 +
23569 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23570 +{
23571 +       if (!p)
23572 +               BUG();
23573 +
23574 +       vxdprintk(VXD_CBIT(tag, 5),
23575 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23576 +
23577 +       task_lock(p);
23578 +       p->tag = tag;
23579 +       task_unlock(p);
23580 +
23581 +       vxdprintk(VXD_CBIT(tag, 5),
23582 +               "moved task %p into [#%d]", p, tag);
23583 +       return 0;
23584 +}
23585 +
23586 +/* vserver syscall commands below here */
23587 +
23588 +/* taks xid and vx_info functions */
23589 +
23590 +
23591 +int vc_task_tag(uint32_t id)
23592 +{
23593 +       tag_t tag;
23594 +
23595 +       if (id) {
23596 +               struct task_struct *tsk;
23597 +               rcu_read_lock();
23598 +               tsk = find_task_by_real_pid(id);
23599 +               tag = (tsk) ? tsk->tag : -ESRCH;
23600 +               rcu_read_unlock();
23601 +       } else
23602 +               tag = dx_current_tag();
23603 +       return tag;
23604 +}
23605 +
23606 +
23607 +int vc_tag_migrate(uint32_t tag)
23608 +{
23609 +       return dx_migrate_task(current, tag & 0xFFFF);
23610 +}
23611 +
23612 +
23613 diff -NurpP --minimal linux-3.7/kernel/vserver/vci_config.h linux-3.7-vs2.3.5.1/kernel/vserver/vci_config.h
23614 --- linux-3.7/kernel/vserver/vci_config.h       1970-01-01 00:00:00.000000000 +0000
23615 +++ linux-3.7-vs2.3.5.1/kernel/vserver/vci_config.h     2012-12-12 13:08:45.000000000 +0000
23616 @@ -0,0 +1,80 @@
23617 +
23618 +/*  interface version */
23619 +
23620 +#define VCI_VERSION            0x00020308
23621 +
23622 +
23623 +enum {
23624 +       VCI_KCBIT_NO_DYNAMIC = 0,
23625 +
23626 +       VCI_KCBIT_PROC_SECURE = 4,
23627 +       /* VCI_KCBIT_HARDCPU = 5, */
23628 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23629 +       /* VCI_KCBIT_IDLETIME = 7, */
23630 +
23631 +       VCI_KCBIT_COWBL = 8,
23632 +       VCI_KCBIT_FULLCOWBL = 9,
23633 +       VCI_KCBIT_SPACES = 10,
23634 +       VCI_KCBIT_NETV2 = 11,
23635 +       VCI_KCBIT_MEMCG = 12,
23636 +       VCI_KCBIT_MEMCG_SWAP = 13,
23637 +
23638 +       VCI_KCBIT_DEBUG = 16,
23639 +       VCI_KCBIT_HISTORY = 20,
23640 +       VCI_KCBIT_TAGGED = 24,
23641 +       VCI_KCBIT_PPTAG = 28,
23642 +
23643 +       VCI_KCBIT_MORE = 31,
23644 +};
23645 +
23646 +
23647 +static inline uint32_t vci_kernel_config(void)
23648 +{
23649 +       return
23650 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23651 +
23652 +       /* configured features */
23653 +#ifdef CONFIG_VSERVER_PROC_SECURE
23654 +       (1 << VCI_KCBIT_PROC_SECURE) |
23655 +#endif
23656 +#ifdef CONFIG_VSERVER_COWBL
23657 +       (1 << VCI_KCBIT_COWBL) |
23658 +       (1 << VCI_KCBIT_FULLCOWBL) |
23659 +#endif
23660 +       (1 << VCI_KCBIT_SPACES) |
23661 +       (1 << VCI_KCBIT_NETV2) |
23662 +#ifdef CONFIG_MEMCG
23663 +       (1 << VCI_KCBIT_MEMCG) |
23664 +#endif
23665 +#ifdef CONFIG_MEMCG_SWAP
23666 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23667 +#endif
23668 +
23669 +       /* debug options */
23670 +#ifdef CONFIG_VSERVER_DEBUG
23671 +       (1 << VCI_KCBIT_DEBUG) |
23672 +#endif
23673 +#ifdef CONFIG_VSERVER_HISTORY
23674 +       (1 << VCI_KCBIT_HISTORY) |
23675 +#endif
23676 +
23677 +       /* inode context tagging */
23678 +#if    defined(CONFIG_TAGGING_NONE)
23679 +       (0 << VCI_KCBIT_TAGGED) |
23680 +#elif  defined(CONFIG_TAGGING_UID16)
23681 +       (1 << VCI_KCBIT_TAGGED) |
23682 +#elif  defined(CONFIG_TAGGING_GID16)
23683 +       (2 << VCI_KCBIT_TAGGED) |
23684 +#elif  defined(CONFIG_TAGGING_ID24)
23685 +       (3 << VCI_KCBIT_TAGGED) |
23686 +#elif  defined(CONFIG_TAGGING_INTERN)
23687 +       (4 << VCI_KCBIT_TAGGED) |
23688 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23689 +       (5 << VCI_KCBIT_TAGGED) |
23690 +#else
23691 +       (7 << VCI_KCBIT_TAGGED) |
23692 +#endif
23693 +       (1 << VCI_KCBIT_PPTAG) |
23694 +       0;
23695 +}
23696 +
23697 diff -NurpP --minimal linux-3.7/mm/memcontrol.c linux-3.7-vs2.3.5.1/mm/memcontrol.c
23698 --- linux-3.7/mm/memcontrol.c   2012-12-11 15:47:52.000000000 +0000
23699 +++ linux-3.7-vs2.3.5.1/mm/memcontrol.c 2012-12-11 15:56:33.000000000 +0000
23700 @@ -884,6 +884,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23701         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23702  }
23703  
23704 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23705 +{
23706 +       return res_counter_read_u64(&mem->res, member);
23707 +}
23708 +
23709 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23710 +{
23711 +       return res_counter_read_u64(&mem->memsw, member);
23712 +}
23713 +
23714 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23715 +{
23716 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23717 +}
23718 +
23719 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23720 +{
23721 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23722 +}
23723 +
23724 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23725 +{
23726 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23727 +}
23728 +
23729  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23730  {
23731         struct mem_cgroup *memcg = NULL;
23732 diff -NurpP --minimal linux-3.7/mm/oom_kill.c linux-3.7-vs2.3.5.1/mm/oom_kill.c
23733 --- linux-3.7/mm/oom_kill.c     2012-12-11 15:47:52.000000000 +0000
23734 +++ linux-3.7-vs2.3.5.1/mm/oom_kill.c   2012-12-12 00:10:01.000000000 +0000
23735 @@ -35,6 +35,8 @@
23736  #include <linux/freezer.h>
23737  #include <linux/ftrace.h>
23738  #include <linux/ratelimit.h>
23739 +#include <linux/reboot.h>
23740 +#include <linux/vs_context.h>
23741  
23742  #define CREATE_TRACE_POINTS
23743  #include <trace/events/oom.h>
23744 @@ -155,11 +157,18 @@ struct task_struct *find_lock_task_mm(st
23745  static bool oom_unkillable_task(struct task_struct *p,
23746                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23747  {
23748 -       if (is_global_init(p))
23749 +       unsigned xid = vx_current_xid();
23750 +
23751 +       /* skip the init task, global and per guest */
23752 +       if (task_is_init(p))
23753                 return true;
23754         if (p->flags & PF_KTHREAD)
23755                 return true;
23756  
23757 +       /* skip other guest and host processes if oom in guest */
23758 +       if (xid && vx_task_xid(p) != xid)
23759 +               return true;
23760 +
23761         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23762         if (memcg && !task_in_mem_cgroup(p, memcg))
23763                 return true;
23764 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23765                 dump_header(p, gfp_mask, order, memcg, nodemask);
23766  
23767         task_lock(p);
23768 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23769 -               message, task_pid_nr(p), p->comm, points);
23770 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23771 +               message, task_pid_nr(p), p->xid, p->comm, points);
23772         task_unlock(p);
23773  
23774         /*
23775 @@ -518,8 +527,8 @@ void oom_kill_process(struct task_struct
23776  
23777         /* mm cannot safely be dereferenced after task_unlock(victim) */
23778         mm = victim->mm;
23779 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23780 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23781 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23782 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23783                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23784                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23785         task_unlock(victim);
23786 @@ -589,6 +598,8 @@ int unregister_oom_notifier(struct notif
23787  }
23788  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23789  
23790 +long vs_oom_action(unsigned int);
23791 +
23792  /*
23793   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23794   * if a parallel OOM killing is already taking place that includes a zone in
23795 @@ -738,7 +749,12 @@ void out_of_memory(struct zonelist *zone
23796         /* Found nothing?!?! Either we hang forever, or we panic. */
23797         if (!p) {
23798                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23799 -               panic("Out of memory and no killable processes...\n");
23800 +
23801 +               /* avoid panic for guest OOM */
23802 +               if (vx_current_xid())
23803 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23804 +               else
23805 +                       panic("Out of memory and no killable processes...\n");
23806         }
23807         if (PTR_ERR(p) != -1UL) {
23808                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23809 diff -NurpP --minimal linux-3.7/mm/page_alloc.c linux-3.7-vs2.3.5.1/mm/page_alloc.c
23810 --- linux-3.7/mm/page_alloc.c   2012-12-11 15:47:52.000000000 +0000
23811 +++ linux-3.7-vs2.3.5.1/mm/page_alloc.c 2012-12-11 15:56:33.000000000 +0000
23812 @@ -58,6 +58,8 @@
23813  #include <linux/prefetch.h>
23814  #include <linux/migrate.h>
23815  #include <linux/page-debug-flags.h>
23816 +#include <linux/vs_base.h>
23817 +#include <linux/vs_limit.h>
23818  
23819  #include <asm/tlbflush.h>
23820  #include <asm/div64.h>
23821 @@ -2832,6 +2834,9 @@ void si_meminfo(struct sysinfo *val)
23822         val->totalhigh = totalhigh_pages;
23823         val->freehigh = nr_free_highpages();
23824         val->mem_unit = PAGE_SIZE;
23825 +
23826 +       if (vx_flags(VXF_VIRT_MEM, 0))
23827 +               vx_vsi_meminfo(val);
23828  }
23829  
23830  EXPORT_SYMBOL(si_meminfo);
23831 @@ -2852,6 +2857,9 @@ void si_meminfo_node(struct sysinfo *val
23832         val->freehigh = 0;
23833  #endif
23834         val->mem_unit = PAGE_SIZE;
23835 +
23836 +       if (vx_flags(VXF_VIRT_MEM, 0))
23837 +               vx_vsi_meminfo(val);
23838  }
23839  #endif
23840  
23841 diff -NurpP --minimal linux-3.7/mm/pgtable-generic.c linux-3.7-vs2.3.5.1/mm/pgtable-generic.c
23842 --- linux-3.7/mm/pgtable-generic.c      2012-12-11 15:47:52.000000000 +0000
23843 +++ linux-3.7-vs2.3.5.1/mm/pgtable-generic.c    2012-12-11 15:56:33.000000000 +0000
23844 @@ -6,6 +6,8 @@
23845   *  Copyright (C) 2010  Linus Torvalds
23846   */
23847  
23848 +#include <linux/mm.h>
23849 +
23850  #include <linux/pagemap.h>
23851  #include <asm/tlb.h>
23852  #include <asm-generic/pgtable.h>
23853 diff -NurpP --minimal linux-3.7/mm/shmem.c linux-3.7-vs2.3.5.1/mm/shmem.c
23854 --- linux-3.7/mm/shmem.c        2012-12-11 15:47:52.000000000 +0000
23855 +++ linux-3.7-vs2.3.5.1/mm/shmem.c      2012-12-11 15:56:33.000000000 +0000
23856 @@ -1820,7 +1820,7 @@ static int shmem_statfs(struct dentry *d
23857  {
23858         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23859  
23860 -       buf->f_type = TMPFS_MAGIC;
23861 +       buf->f_type = TMPFS_SUPER_MAGIC;
23862         buf->f_bsize = PAGE_CACHE_SIZE;
23863         buf->f_namelen = NAME_MAX;
23864         if (sbinfo->max_blocks) {
23865 @@ -2504,7 +2504,7 @@ int shmem_fill_super(struct super_block
23866         sb->s_maxbytes = MAX_LFS_FILESIZE;
23867         sb->s_blocksize = PAGE_CACHE_SIZE;
23868         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23869 -       sb->s_magic = TMPFS_MAGIC;
23870 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23871         sb->s_op = &shmem_ops;
23872         sb->s_time_gran = 1;
23873  #ifdef CONFIG_TMPFS_XATTR
23874 diff -NurpP --minimal linux-3.7/mm/slab.c linux-3.7-vs2.3.5.1/mm/slab.c
23875 --- linux-3.7/mm/slab.c 2012-12-11 15:47:52.000000000 +0000
23876 +++ linux-3.7-vs2.3.5.1/mm/slab.c       2012-12-11 15:56:33.000000000 +0000
23877 @@ -445,6 +445,8 @@ static void kmem_list3_init(struct kmem_
23878  #define STATS_INC_FREEMISS(x)  do { } while (0)
23879  #endif
23880  
23881 +#include "slab_vs.h"
23882 +
23883  #if DEBUG
23884  
23885  /*
23886 @@ -3479,6 +3481,7 @@ retry:
23887  
23888         obj = slab_get_obj(cachep, slabp, nodeid);
23889         check_slabp(cachep, slabp);
23890 +       vx_slab_alloc(cachep, flags);
23891         l3->free_objects--;
23892         /* move slabp to correct slabp list: */
23893         list_del(&slabp->list);
23894 @@ -3556,6 +3559,7 @@ slab_alloc_node(struct kmem_cache *cache
23895         /* ___cache_alloc_node can fall back to other nodes */
23896         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23897    out:
23898 +       vx_slab_alloc(cachep, flags);
23899         local_irq_restore(save_flags);
23900         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23901         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23902 @@ -3746,6 +3750,7 @@ static inline void __cache_free(struct k
23903         check_irq_off();
23904         kmemleak_free_recursive(objp, cachep->flags);
23905         objp = cache_free_debugcheck(cachep, objp, caller);
23906 +       vx_slab_free(cachep);
23907  
23908         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23909  
23910 diff -NurpP --minimal linux-3.7/mm/slab_vs.h linux-3.7-vs2.3.5.1/mm/slab_vs.h
23911 --- linux-3.7/mm/slab_vs.h      1970-01-01 00:00:00.000000000 +0000
23912 +++ linux-3.7-vs2.3.5.1/mm/slab_vs.h    2012-12-11 15:56:33.000000000 +0000
23913 @@ -0,0 +1,29 @@
23914 +
23915 +#include <linux/vserver/context.h>
23916 +
23917 +#include <linux/vs_context.h>
23918 +
23919 +static inline
23920 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23921 +{
23922 +       int what = gfp_zone(cachep->allocflags);
23923 +       struct vx_info *vxi = current_vx_info();
23924 +
23925 +       if (!vxi)
23926 +               return;
23927 +
23928 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23929 +}
23930 +
23931 +static inline
23932 +void vx_slab_free(struct kmem_cache *cachep)
23933 +{
23934 +       int what = gfp_zone(cachep->allocflags);
23935 +       struct vx_info *vxi = current_vx_info();
23936 +
23937 +       if (!vxi)
23938 +               return;
23939 +
23940 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23941 +}
23942 +
23943 diff -NurpP --minimal linux-3.7/mm/swapfile.c linux-3.7-vs2.3.5.1/mm/swapfile.c
23944 --- linux-3.7/mm/swapfile.c     2012-12-11 15:47:52.000000000 +0000
23945 +++ linux-3.7-vs2.3.5.1/mm/swapfile.c   2012-12-11 15:56:33.000000000 +0000
23946 @@ -39,6 +39,7 @@
23947  #include <asm/tlbflush.h>
23948  #include <linux/swapops.h>
23949  #include <linux/page_cgroup.h>
23950 +#include <linux/vs_base.h>
23951  
23952  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23953                                  unsigned char);
23954 @@ -1685,6 +1686,16 @@ static int swap_show(struct seq_file *sw
23955  
23956         if (si == SEQ_START_TOKEN) {
23957                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23958 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23959 +                       struct sysinfo si;
23960 +
23961 +                       vx_vsi_swapinfo(&si);
23962 +                       if (si.totalswap < (1 << 10))
23963 +                               return 0;
23964 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23965 +                               "hdv0", "partition", si.totalswap >> 10,
23966 +                               (si.totalswap - si.freeswap) >> 10, -1);
23967 +               }
23968                 return 0;
23969         }
23970  
23971 @@ -2112,6 +2123,8 @@ void si_swapinfo(struct sysinfo *val)
23972         val->freeswap = nr_swap_pages + nr_to_be_unused;
23973         val->totalswap = total_swap_pages + nr_to_be_unused;
23974         spin_unlock(&swap_lock);
23975 +       if (vx_flags(VXF_VIRT_MEM, 0))
23976 +               vx_vsi_swapinfo(val);
23977  }
23978  
23979  /*
23980 diff -NurpP --minimal linux-3.7/net/bridge/br_multicast.c linux-3.7-vs2.3.5.1/net/bridge/br_multicast.c
23981 --- linux-3.7/net/bridge/br_multicast.c 2012-10-04 13:27:49.000000000 +0000
23982 +++ linux-3.7-vs2.3.5.1/net/bridge/br_multicast.c       2012-12-11 15:56:33.000000000 +0000
23983 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23984         ip6h->hop_limit = 1;
23985         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23986         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23987 -                              &ip6h->saddr)) {
23988 +                              &ip6h->saddr, NULL)) {
23989                 kfree_skb(skb);
23990                 return NULL;
23991         }
23992 diff -NurpP --minimal linux-3.7/net/core/dev.c linux-3.7-vs2.3.5.1/net/core/dev.c
23993 --- linux-3.7/net/core/dev.c    2012-12-11 15:47:53.000000000 +0000
23994 +++ linux-3.7-vs2.3.5.1/net/core/dev.c  2012-12-11 15:56:33.000000000 +0000
23995 @@ -126,6 +126,7 @@
23996  #include <linux/in.h>
23997  #include <linux/jhash.h>
23998  #include <linux/random.h>
23999 +#include <linux/vs_inet.h>
24000  #include <trace/events/napi.h>
24001  #include <trace/events/net.h>
24002  #include <trace/events/skb.h>
24003 @@ -620,7 +621,8 @@ struct net_device *__dev_get_by_name(str
24004         struct hlist_head *head = dev_name_hash(net, name);
24005  
24006         hlist_for_each_entry(dev, p, head, name_hlist)
24007 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24008 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24009 +                   nx_dev_visible(current_nx_info(), dev))
24010                         return dev;
24011  
24012         return NULL;
24013 @@ -646,7 +648,8 @@ struct net_device *dev_get_by_name_rcu(s
24014         struct hlist_head *head = dev_name_hash(net, name);
24015  
24016         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24017 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24018 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24019 +                   nx_dev_visible(current_nx_info(), dev))
24020                         return dev;
24021  
24022         return NULL;
24023 @@ -697,7 +700,8 @@ struct net_device *__dev_get_by_index(st
24024         struct hlist_head *head = dev_index_hash(net, ifindex);
24025  
24026         hlist_for_each_entry(dev, p, head, index_hlist)
24027 -               if (dev->ifindex == ifindex)
24028 +               if ((dev->ifindex == ifindex) &&
24029 +                   nx_dev_visible(current_nx_info(), dev))
24030                         return dev;
24031  
24032         return NULL;
24033 @@ -715,7 +719,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24034   *     about locking. The caller must hold RCU lock.
24035   */
24036  
24037 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24038 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24039  {
24040         struct hlist_node *p;
24041         struct net_device *dev;
24042 @@ -727,6 +731,16 @@ struct net_device *dev_get_by_index_rcu(
24043  
24044         return NULL;
24045  }
24046 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24047 +
24048 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24049 +{
24050 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24051 +
24052 +       if (nx_dev_visible(current_nx_info(), dev))
24053 +               return dev;
24054 +       return NULL;
24055 +}
24056  EXPORT_SYMBOL(dev_get_by_index_rcu);
24057  
24058  
24059 @@ -775,7 +789,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24060  
24061         for_each_netdev_rcu(net, dev)
24062                 if (dev->type == type &&
24063 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24064 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24065 +                   nx_dev_visible(current_nx_info(), dev))
24066                         return dev;
24067  
24068         return NULL;
24069 @@ -787,9 +802,11 @@ struct net_device *__dev_getfirstbyhwtyp
24070         struct net_device *dev;
24071  
24072         ASSERT_RTNL();
24073 -       for_each_netdev(net, dev)
24074 -               if (dev->type == type)
24075 +       for_each_netdev(net, dev) {
24076 +               if ((dev->type == type) &&
24077 +                   nx_dev_visible(current_nx_info(), dev))
24078                         return dev;
24079 +       }
24080  
24081         return NULL;
24082  }
24083 @@ -907,6 +924,8 @@ static int __dev_alloc_name(struct net *
24084                                 continue;
24085                         if (i < 0 || i >= max_netdevices)
24086                                 continue;
24087 +                       if (!nx_dev_visible(current_nx_info(), d))
24088 +                               continue;
24089  
24090                         /*  avoid cases where sscanf is not exact inverse of printf */
24091                         snprintf(buf, IFNAMSIZ, name, i);
24092 @@ -4129,6 +4148,8 @@ static int dev_ifconf(struct net *net, c
24093  
24094         total = 0;
24095         for_each_netdev(net, dev) {
24096 +               if (!nx_dev_visible(current_nx_info(), dev))
24097 +                       continue;
24098                 for (i = 0; i < NPROTO; i++) {
24099                         if (gifconf_list[i]) {
24100                                 int done;
24101 @@ -4231,6 +4252,10 @@ static void dev_seq_printf_stats(struct
24102         struct rtnl_link_stats64 temp;
24103         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24104  
24105 +       /* device visible inside network context? */
24106 +       if (!nx_dev_visible(current_nx_info(), dev))
24107 +               return;
24108 +
24109         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24110                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24111                    dev->name, stats->rx_bytes, stats->rx_packets,
24112 diff -NurpP --minimal linux-3.7/net/core/rtnetlink.c linux-3.7-vs2.3.5.1/net/core/rtnetlink.c
24113 --- linux-3.7/net/core/rtnetlink.c      2012-12-11 15:47:53.000000000 +0000
24114 +++ linux-3.7-vs2.3.5.1/net/core/rtnetlink.c    2012-12-11 15:56:33.000000000 +0000
24115 @@ -1080,6 +1080,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24116                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24117                         if (idx < s_idx)
24118                                 goto cont;
24119 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24120 +                               continue;
24121                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24122                                              NETLINK_CB(cb->skb).portid,
24123                                              cb->nlh->nlmsg_seq, 0,
24124 @@ -1971,6 +1973,9 @@ void rtmsg_ifinfo(int type, struct net_d
24125         int err = -ENOBUFS;
24126         size_t if_info_size;
24127  
24128 +       if (!nx_dev_visible(current_nx_info(), dev))
24129 +               return;
24130 +
24131         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24132         if (skb == NULL)
24133                 goto errout;
24134 diff -NurpP --minimal linux-3.7/net/core/sock.c linux-3.7-vs2.3.5.1/net/core/sock.c
24135 --- linux-3.7/net/core/sock.c   2012-12-11 15:47:53.000000000 +0000
24136 +++ linux-3.7-vs2.3.5.1/net/core/sock.c 2012-12-11 15:56:33.000000000 +0000
24137 @@ -132,6 +132,10 @@
24138  #include <net/netprio_cgroup.h>
24139  
24140  #include <linux/filter.h>
24141 +#include <linux/vs_socket.h>
24142 +#include <linux/vs_limit.h>
24143 +#include <linux/vs_context.h>
24144 +#include <linux/vs_network.h>
24145  
24146  #include <trace/events/sock.h>
24147  
24148 @@ -1183,6 +1187,8 @@ static struct sock *sk_prot_alloc(struct
24149                         goto out_free_sec;
24150                 sk_tx_queue_clear(sk);
24151         }
24152 +               sock_vx_init(sk);
24153 +               sock_nx_init(sk);
24154  
24155         return sk;
24156  
24157 @@ -1295,6 +1301,11 @@ static void __sk_free(struct sock *sk)
24158                 put_cred(sk->sk_peer_cred);
24159         put_pid(sk->sk_peer_pid);
24160         put_net(sock_net(sk));
24161 +       vx_sock_dec(sk);
24162 +       clr_vx_info(&sk->sk_vx_info);
24163 +       sk->sk_xid = -1;
24164 +       clr_nx_info(&sk->sk_nx_info);
24165 +       sk->sk_nid = -1;
24166         sk_prot_free(sk->sk_prot_creator, sk);
24167  }
24168  
24169 @@ -1355,6 +1366,8 @@ struct sock *sk_clone_lock(const struct
24170  
24171                 /* SANITY */
24172                 get_net(sock_net(newsk));
24173 +               sock_vx_init(newsk);
24174 +               sock_nx_init(newsk);
24175                 sk_node_init(&newsk->sk_node);
24176                 sock_lock_init(newsk);
24177                 bh_lock_sock(newsk);
24178 @@ -1411,6 +1424,12 @@ struct sock *sk_clone_lock(const struct
24179                 smp_wmb();
24180                 atomic_set(&newsk->sk_refcnt, 2);
24181  
24182 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24183 +               newsk->sk_xid = sk->sk_xid;
24184 +               vx_sock_inc(newsk);
24185 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24186 +               newsk->sk_nid = sk->sk_nid;
24187 +
24188                 /*
24189                  * Increment the counter in the same struct proto as the master
24190                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24191 @@ -2206,6 +2225,12 @@ void sock_init_data(struct socket *sock,
24192  
24193         sk->sk_stamp = ktime_set(-1L, 0);
24194  
24195 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24196 +       sk->sk_xid = vx_current_xid();
24197 +       vx_sock_inc(sk);
24198 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24199 +       sk->sk_nid = nx_current_nid();
24200 +
24201         /*
24202          * Before updating sk_refcnt, we must commit prior changes to memory
24203          * (Documentation/RCU/rculist_nulls.txt for details)
24204 diff -NurpP --minimal linux-3.7/net/ipv4/af_inet.c linux-3.7-vs2.3.5.1/net/ipv4/af_inet.c
24205 --- linux-3.7/net/ipv4/af_inet.c        2012-12-11 15:47:54.000000000 +0000
24206 +++ linux-3.7-vs2.3.5.1/net/ipv4/af_inet.c      2012-12-11 15:56:33.000000000 +0000
24207 @@ -118,6 +118,7 @@
24208  #ifdef CONFIG_IP_MROUTE
24209  #include <linux/mroute.h>
24210  #endif
24211 +#include <linux/vs_limit.h>
24212  
24213  
24214  /* The inetsw table contains everything that inet_create needs to
24215 @@ -346,9 +347,13 @@ lookup_protocol:
24216         }
24217  
24218         err = -EPERM;
24219 +       if ((protocol == IPPROTO_ICMP) &&
24220 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24221 +               goto override;
24222 +
24223         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24224                 goto out_rcu_unlock;
24225 -
24226 +override:
24227         err = -EAFNOSUPPORT;
24228         if (!inet_netns_ok(net, protocol))
24229                 goto out_rcu_unlock;
24230 @@ -473,6 +478,7 @@ int inet_bind(struct socket *sock, struc
24231         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24232         struct sock *sk = sock->sk;
24233         struct inet_sock *inet = inet_sk(sk);
24234 +       struct nx_v4_sock_addr nsa;
24235         unsigned short snum;
24236         int chk_addr_ret;
24237         int err;
24238 @@ -496,7 +502,11 @@ int inet_bind(struct socket *sock, struc
24239                         goto out;
24240         }
24241  
24242 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24243 +       err = v4_map_sock_addr(inet, addr, &nsa);
24244 +       if (err)
24245 +               goto out;
24246 +
24247 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24248  
24249         /* Not specified by any standard per-se, however it breaks too
24250          * many applications when removed.  It is unfortunate since
24251 @@ -508,7 +518,7 @@ int inet_bind(struct socket *sock, struc
24252         err = -EADDRNOTAVAIL;
24253         if (!sysctl_ip_nonlocal_bind &&
24254             !(inet->freebind || inet->transparent) &&
24255 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24256 +           nsa.saddr != htonl(INADDR_ANY) &&
24257             chk_addr_ret != RTN_LOCAL &&
24258             chk_addr_ret != RTN_MULTICAST &&
24259             chk_addr_ret != RTN_BROADCAST)
24260 @@ -533,7 +543,7 @@ int inet_bind(struct socket *sock, struc
24261         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24262                 goto out_release_sock;
24263  
24264 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24265 +       v4_set_sock_addr(inet, &nsa);
24266         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24267                 inet->inet_saddr = 0;  /* Use device */
24268  
24269 @@ -752,11 +762,13 @@ int inet_getname(struct socket *sock, st
24270                      peer == 1))
24271                         return -ENOTCONN;
24272                 sin->sin_port = inet->inet_dport;
24273 -               sin->sin_addr.s_addr = inet->inet_daddr;
24274 +               sin->sin_addr.s_addr =
24275 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24276         } else {
24277                 __be32 addr = inet->inet_rcv_saddr;
24278                 if (!addr)
24279                         addr = inet->inet_saddr;
24280 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24281                 sin->sin_port = inet->inet_sport;
24282                 sin->sin_addr.s_addr = addr;
24283         }
24284 diff -NurpP --minimal linux-3.7/net/ipv4/arp.c linux-3.7-vs2.3.5.1/net/ipv4/arp.c
24285 --- linux-3.7/net/ipv4/arp.c    2012-10-04 13:27:49.000000000 +0000
24286 +++ linux-3.7-vs2.3.5.1/net/ipv4/arp.c  2012-12-11 15:56:33.000000000 +0000
24287 @@ -1318,6 +1318,7 @@ static void arp_format_neigh_entry(struc
24288         struct net_device *dev = n->dev;
24289         int hatype = dev->type;
24290  
24291 +       /* FIXME: check for network context */
24292         read_lock(&n->lock);
24293         /* Convert hardware address to XX:XX:XX:XX ... form. */
24294  #if IS_ENABLED(CONFIG_AX25)
24295 @@ -1349,6 +1350,7 @@ static void arp_format_pneigh_entry(stru
24296         int hatype = dev ? dev->type : 0;
24297         char tbuf[16];
24298  
24299 +       /* FIXME: check for network context */
24300         sprintf(tbuf, "%pI4", n->key);
24301         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24302                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24303 diff -NurpP --minimal linux-3.7/net/ipv4/devinet.c linux-3.7-vs2.3.5.1/net/ipv4/devinet.c
24304 --- linux-3.7/net/ipv4/devinet.c        2012-12-11 15:47:54.000000000 +0000
24305 +++ linux-3.7-vs2.3.5.1/net/ipv4/devinet.c      2012-12-11 15:56:33.000000000 +0000
24306 @@ -513,6 +513,7 @@ struct in_device *inetdev_by_index(struc
24307  }
24308  EXPORT_SYMBOL(inetdev_by_index);
24309  
24310 +
24311  /* Called only from RTNL semaphored context. No locks. */
24312  
24313  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24314 @@ -754,6 +755,8 @@ int devinet_ioctl(struct net *net, unsig
24315  
24316         in_dev = __in_dev_get_rtnl(dev);
24317         if (in_dev) {
24318 +               struct nx_info *nxi = current_nx_info();
24319 +
24320                 if (tryaddrmatch) {
24321                         /* Matthias Andree */
24322                         /* compare label and address (4.4BSD style) */
24323 @@ -762,6 +765,8 @@ int devinet_ioctl(struct net *net, unsig
24324                            This is checked above. */
24325                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24326                              ifap = &ifa->ifa_next) {
24327 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24328 +                                       continue;
24329                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24330                                     sin_orig.sin_addr.s_addr ==
24331                                                         ifa->ifa_local) {
24332 @@ -774,9 +779,12 @@ int devinet_ioctl(struct net *net, unsig
24333                    comparing just the label */
24334                 if (!ifa) {
24335                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24336 -                            ifap = &ifa->ifa_next)
24337 +                            ifap = &ifa->ifa_next) {
24338 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24339 +                                       continue;
24340                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24341                                         break;
24342 +                       }
24343                 }
24344         }
24345  
24346 @@ -929,6 +937,8 @@ static int inet_gifconf(struct net_devic
24347                 goto out;
24348  
24349         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24350 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24351 +                       continue;
24352                 if (!buf) {
24353                         done += sizeof(ifr);
24354                         continue;
24355 @@ -1288,6 +1298,7 @@ static int inet_dump_ifaddr(struct sk_bu
24356         struct net_device *dev;
24357         struct in_device *in_dev;
24358         struct in_ifaddr *ifa;
24359 +       struct sock *sk = skb->sk;
24360         struct hlist_head *head;
24361         struct hlist_node *node;
24362  
24363 @@ -1310,6 +1321,8 @@ static int inet_dump_ifaddr(struct sk_bu
24364  
24365                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24366                              ifa = ifa->ifa_next, ip_idx++) {
24367 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24368 +                               continue;
24369                                 if (ip_idx < s_ip_idx)
24370                                         continue;
24371                                 if (inet_fill_ifaddr(skb, ifa,
24372 diff -NurpP --minimal linux-3.7/net/ipv4/fib_trie.c linux-3.7-vs2.3.5.1/net/ipv4/fib_trie.c
24373 --- linux-3.7/net/ipv4/fib_trie.c       2012-12-11 15:47:54.000000000 +0000
24374 +++ linux-3.7-vs2.3.5.1/net/ipv4/fib_trie.c     2012-12-11 15:56:33.000000000 +0000
24375 @@ -2557,6 +2557,7 @@ static int fib_route_seq_show(struct seq
24376                             || fa->fa_type == RTN_MULTICAST)
24377                                 continue;
24378  
24379 +                       /* FIXME: check for network context? */
24380                         if (fi)
24381                                 seq_printf(seq,
24382                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24383 diff -NurpP --minimal linux-3.7/net/ipv4/inet_connection_sock.c linux-3.7-vs2.3.5.1/net/ipv4/inet_connection_sock.c
24384 --- linux-3.7/net/ipv4/inet_connection_sock.c   2012-12-11 15:47:54.000000000 +0000
24385 +++ linux-3.7-vs2.3.5.1/net/ipv4/inet_connection_sock.c 2012-12-11 15:56:33.000000000 +0000
24386 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24387  }
24388  EXPORT_SYMBOL(inet_get_local_port_range);
24389  
24390 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24391 +{
24392 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24393 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24394 +
24395 +       if (inet_v6_ipv6only(sk2))
24396 +               return 0;
24397 +
24398 +       if (sk1_rcv_saddr &&
24399 +           sk2_rcv_saddr &&
24400 +           sk1_rcv_saddr == sk2_rcv_saddr)
24401 +               return 1;
24402 +
24403 +       if (sk1_rcv_saddr &&
24404 +           !sk2_rcv_saddr &&
24405 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24406 +               return 1;
24407 +
24408 +       if (sk2_rcv_saddr &&
24409 +           !sk1_rcv_saddr &&
24410 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24411 +               return 1;
24412 +
24413 +       if (!sk1_rcv_saddr &&
24414 +           !sk2_rcv_saddr &&
24415 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24416 +               return 1;
24417 +
24418 +       return 0;
24419 +}
24420 +
24421  int inet_csk_bind_conflict(const struct sock *sk,
24422                            const struct inet_bind_bucket *tb, bool relax)
24423  {
24424 @@ -75,9 +106,7 @@ int inet_csk_bind_conflict(const struct
24425                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24426                         if (!reuse || !sk2->sk_reuse ||
24427                             sk2->sk_state == TCP_LISTEN) {
24428 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24429 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24430 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24431 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24432                                         break;
24433                         }
24434                         if (!relax && reuse && sk2->sk_reuse &&
24435 diff -NurpP --minimal linux-3.7/net/ipv4/inet_diag.c linux-3.7-vs2.3.5.1/net/ipv4/inet_diag.c
24436 --- linux-3.7/net/ipv4/inet_diag.c      2012-12-11 15:47:54.000000000 +0000
24437 +++ linux-3.7-vs2.3.5.1/net/ipv4/inet_diag.c    2012-12-11 17:05:58.000000000 +0000
24438 @@ -31,6 +31,8 @@
24439  
24440  #include <linux/inet.h>
24441  #include <linux/stddef.h>
24442 +#include <linux/vs_network.h>
24443 +#include <linux/vs_inet.h>
24444  
24445  #include <linux/inet_diag.h>
24446  #include <linux/sock_diag.h>
24447 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24448  
24449         r->id.idiag_sport = inet->inet_sport;
24450         r->id.idiag_dport = inet->inet_dport;
24451 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24452 -       r->id.idiag_dst[0] = inet->inet_daddr;
24453 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24454 +               inet->inet_rcv_saddr);
24455 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24456 +               inet->inet_daddr);
24457  
24458         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24459          * hence this needs to be included regardless of socket family.
24460 @@ -239,8 +243,8 @@ static int inet_twsk_diag_fill(struct in
24461         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24462         r->id.idiag_sport     = tw->tw_sport;
24463         r->id.idiag_dport     = tw->tw_dport;
24464 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24465 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24466 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24467 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24468         r->idiag_state        = tw->tw_substate;
24469         r->idiag_timer        = 3;
24470         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24471 @@ -284,12 +288,14 @@ int inet_diag_dump_one_icsk(struct inet_
24472  
24473         err = -EINVAL;
24474         if (req->sdiag_family == AF_INET) {
24475 +               /* TODO: lback */
24476                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24477                                  req->id.idiag_dport, req->id.idiag_src[0],
24478                                  req->id.idiag_sport, req->id.idiag_if);
24479         }
24480  #if IS_ENABLED(CONFIG_IPV6)
24481         else if (req->sdiag_family == AF_INET6) {
24482 +               /* TODO: lback */
24483                 sk = inet6_lookup(net, hashinfo,
24484                                   (struct in6_addr *)req->id.idiag_dst,
24485                                   req->id.idiag_dport,
24486 @@ -491,6 +497,7 @@ int inet_diag_bc_sk(const struct nlattr
24487         } else
24488  #endif
24489         {
24490 +                       /* TODO: lback */
24491                 entry.saddr = &inet->inet_rcv_saddr;
24492                 entry.daddr = &inet->inet_daddr;
24493         }
24494 @@ -649,6 +656,7 @@ static int inet_twsk_diag_dump(struct in
24495                 } else
24496  #endif
24497                 {
24498 +                       /* TODO: lback */
24499                         entry.saddr = &tw->tw_rcv_saddr;
24500                         entry.daddr = &tw->tw_daddr;
24501                 }
24502 @@ -727,8 +735,8 @@ static int inet_diag_fill_req(struct sk_
24503  
24504         r->id.idiag_sport = inet->inet_sport;
24505         r->id.idiag_dport = ireq->rmt_port;
24506 -       r->id.idiag_src[0] = ireq->loc_addr;
24507 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24508 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24509 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24510         r->idiag_expires = jiffies_to_msecs(tmo);
24511         r->idiag_rqueue = 0;
24512         r->idiag_wqueue = 0;
24513 @@ -791,6 +799,7 @@ static int inet_diag_dump_reqs(struct sk
24514                             r->id.idiag_dport)
24515                                 continue;
24516  
24517 +                       /* TODO: lback */
24518                         if (bc) {
24519                                 inet_diag_req_addrs(sk, req, &entry);
24520                                 entry.dport = ntohs(ireq->rmt_port);
24521 @@ -847,6 +856,8 @@ void inet_diag_dump_icsk(struct inet_has
24522                                 if (!net_eq(sock_net(sk), net))
24523                                         continue;
24524  
24525 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24526 +                                       continue;
24527                                 if (num < s_num) {
24528                                         num++;
24529                                         continue;
24530 @@ -919,6 +930,8 @@ skip_listen_ht:
24531  
24532                         if (!net_eq(sock_net(sk), net))
24533                                 continue;
24534 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24535 +                               continue;
24536                         if (num < s_num)
24537                                 goto next_normal;
24538                         if (!(r->idiag_states & (1 << sk->sk_state)))
24539 @@ -947,7 +960,8 @@ next_normal:
24540                                     &head->twchain) {
24541                                 if (!net_eq(twsk_net(tw), net))
24542                                         continue;
24543 -
24544 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24545 +                                       continue;
24546                                 if (num < s_num)
24547                                         goto next_dying;
24548                                 if (r->sdiag_family != AF_UNSPEC &&
24549 diff -NurpP --minimal linux-3.7/net/ipv4/inet_hashtables.c linux-3.7-vs2.3.5.1/net/ipv4/inet_hashtables.c
24550 --- linux-3.7/net/ipv4/inet_hashtables.c        2012-07-22 21:39:48.000000000 +0000
24551 +++ linux-3.7-vs2.3.5.1/net/ipv4/inet_hashtables.c      2012-12-11 15:56:33.000000000 +0000
24552 @@ -22,6 +22,7 @@
24553  #include <net/inet_connection_sock.h>
24554  #include <net/inet_hashtables.h>
24555  #include <net/secure_seq.h>
24556 +#include <net/route.h>
24557  #include <net/ip.h>
24558  
24559  /*
24560 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24561                         if (rcv_saddr != daddr)
24562                                 return -1;
24563                         score += 2;
24564 +               } else {
24565 +                       /* block non nx_info ips */
24566 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24567 +                               daddr, NXA_MASK_BIND))
24568 +                               return -1;
24569                 }
24570                 if (sk->sk_bound_dev_if) {
24571                         if (sk->sk_bound_dev_if != dif)
24572 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24573   * wildcarded during the search since they can never be otherwise.
24574   */
24575  
24576 -
24577  struct sock *__inet_lookup_listener(struct net *net,
24578                                     struct inet_hashinfo *hashinfo,
24579                                     const __be32 daddr, const unsigned short hnum,
24580 @@ -196,6 +201,7 @@ begin:
24581                         hiscore = score;
24582                 }
24583         }
24584 +
24585         /*
24586          * if the nulls value we got at the end of this lookup is
24587          * not the expected one, we must restart lookup.
24588 diff -NurpP --minimal linux-3.7/net/ipv4/netfilter.c linux-3.7-vs2.3.5.1/net/ipv4/netfilter.c
24589 --- linux-3.7/net/ipv4/netfilter.c      2012-12-11 15:47:54.000000000 +0000
24590 +++ linux-3.7-vs2.3.5.1/net/ipv4/netfilter.c    2012-12-11 15:56:33.000000000 +0000
24591 @@ -6,7 +6,7 @@
24592  #include <linux/skbuff.h>
24593  #include <linux/gfp.h>
24594  #include <linux/export.h>
24595 -#include <net/route.h>
24596 +// #include <net/route.h>
24597  #include <net/xfrm.h>
24598  #include <net/ip.h>
24599  #include <net/netfilter/nf_queue.h>
24600 diff -NurpP --minimal linux-3.7/net/ipv4/raw.c linux-3.7-vs2.3.5.1/net/ipv4/raw.c
24601 --- linux-3.7/net/ipv4/raw.c    2012-12-11 15:47:54.000000000 +0000
24602 +++ linux-3.7-vs2.3.5.1/net/ipv4/raw.c  2012-12-11 15:56:33.000000000 +0000
24603 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24604  
24605                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24606                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24607 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24608 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24609                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24610                         goto found; /* gotcha */
24611         }
24612 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
24613                 icmp_out_count(net, ((struct icmphdr *)
24614                         skb_transport_header(skb))->type);
24615  
24616 +       err = -EPERM;
24617 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24618 +               sk->sk_nx_info &&
24619 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24620 +               goto error_free;
24621 +
24622         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24623                       rt->dst.dev, dst_output);
24624         if (err > 0)
24625 @@ -582,6 +588,16 @@ static int raw_sendmsg(struct kiocb *ioc
24626                         goto done;
24627         }
24628  
24629 +       if (sk->sk_nx_info) {
24630 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24631 +               if (IS_ERR(rt)) {
24632 +                       err = PTR_ERR(rt);
24633 +                       rt = NULL;
24634 +                       goto done;
24635 +               }
24636 +               ip_rt_put(rt);
24637 +       }
24638 +
24639         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24640         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24641         if (IS_ERR(rt)) {
24642 @@ -658,17 +674,19 @@ static int raw_bind(struct sock *sk, str
24643  {
24644         struct inet_sock *inet = inet_sk(sk);
24645         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24646 +       struct nx_v4_sock_addr nsa = { 0 };
24647         int ret = -EINVAL;
24648         int chk_addr_ret;
24649  
24650         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24651                 goto out;
24652 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24653 +       v4_map_sock_addr(inet, addr, &nsa);
24654 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24655         ret = -EADDRNOTAVAIL;
24656 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24657 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24658             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24659                 goto out;
24660 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24661 +       v4_set_sock_addr(inet, &nsa);
24662         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24663                 inet->inet_saddr = 0;  /* Use device */
24664         sk_dst_reset(sk);
24665 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
24666         /* Copy the address. */
24667         if (sin) {
24668                 sin->sin_family = AF_INET;
24669 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24670 +               sin->sin_addr.s_addr =
24671 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24672                 sin->sin_port = 0;
24673                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24674         }
24675 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
24676                 struct hlist_node *node;
24677  
24678                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24679 -                       if (sock_net(sk) == seq_file_net(seq))
24680 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24681 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24682                                 goto found;
24683         }
24684         sk = NULL;
24685 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
24686                 sk = sk_next(sk);
24687  try_again:
24688                 ;
24689 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24690 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24691 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24692  
24693         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24694                 sk = sk_head(&state->h->ht[state->bucket]);
24695 diff -NurpP --minimal linux-3.7/net/ipv4/route.c linux-3.7-vs2.3.5.1/net/ipv4/route.c
24696 --- linux-3.7/net/ipv4/route.c  2012-12-11 15:47:54.000000000 +0000
24697 +++ linux-3.7-vs2.3.5.1/net/ipv4/route.c        2012-12-11 15:56:33.000000000 +0000
24698 @@ -1952,7 +1952,7 @@ struct rtable *__ip_route_output_key(str
24699  
24700  
24701         if (fl4->flowi4_oif) {
24702 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24703 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24704                 rth = ERR_PTR(-ENODEV);
24705                 if (dev_out == NULL)
24706                         goto out;
24707 diff -NurpP --minimal linux-3.7/net/ipv4/tcp.c linux-3.7-vs2.3.5.1/net/ipv4/tcp.c
24708 --- linux-3.7/net/ipv4/tcp.c    2012-12-11 15:47:54.000000000 +0000
24709 +++ linux-3.7-vs2.3.5.1/net/ipv4/tcp.c  2012-12-11 15:56:33.000000000 +0000
24710 @@ -268,6 +268,7 @@
24711  #include <linux/crypto.h>
24712  #include <linux/time.h>
24713  #include <linux/slab.h>
24714 +#include <linux/in.h>
24715  
24716  #include <net/icmp.h>
24717  #include <net/inet_common.h>
24718 diff -NurpP --minimal linux-3.7/net/ipv4/tcp_ipv4.c linux-3.7-vs2.3.5.1/net/ipv4/tcp_ipv4.c
24719 --- linux-3.7/net/ipv4/tcp_ipv4.c       2012-12-11 15:47:54.000000000 +0000
24720 +++ linux-3.7-vs2.3.5.1/net/ipv4/tcp_ipv4.c     2012-12-11 17:07:07.000000000 +0000
24721 @@ -2264,6 +2264,12 @@ static void *listening_get_next(struct s
24722                 req = req->dl_next;
24723                 while (1) {
24724                         while (req) {
24725 +                               vxdprintk(VXD_CBIT(net, 6),
24726 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24727 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24728 +                               if (req->sk &&
24729 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24730 +                                       continue;
24731                                 if (req->rsk_ops->family == st->family) {
24732                                         cur = req;
24733                                         goto out;
24734 @@ -2288,6 +2294,10 @@ get_req:
24735         }
24736  get_sk:
24737         sk_nulls_for_each_from(sk, node) {
24738 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24739 +                       sk, sk->sk_nid, nx_current_nid());
24740 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24741 +                       continue;
24742                 if (!net_eq(sock_net(sk), net))
24743                         continue;
24744                 if (sk->sk_family == st->family) {
24745 @@ -2364,6 +2374,11 @@ static void *established_get_first(struc
24746  
24747                 spin_lock_bh(lock);
24748                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24749 +                       vxdprintk(VXD_CBIT(net, 6),
24750 +                               "sk,egf: %p [#%d] (from %d)",
24751 +                               sk, sk->sk_nid, nx_current_nid());
24752 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24753 +                               continue;
24754                         if (sk->sk_family != st->family ||
24755                             !net_eq(sock_net(sk), net)) {
24756                                 continue;
24757 @@ -2374,6 +2389,11 @@ static void *established_get_first(struc
24758                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24759                 inet_twsk_for_each(tw, node,
24760                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24761 +                       vxdprintk(VXD_CBIT(net, 6),
24762 +                               "tw: %p [#%d] (from %d)",
24763 +                               tw, tw->tw_nid, nx_current_nid());
24764 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24765 +                               continue;
24766                         if (tw->tw_family != st->family ||
24767                             !net_eq(twsk_net(tw), net)) {
24768                                 continue;
24769 @@ -2403,7 +2423,9 @@ static void *established_get_next(struct
24770                 tw = cur;
24771                 tw = tw_next(tw);
24772  get_tw:
24773 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24774 +               while (tw && (tw->tw_family != st->family ||
24775 +                       !net_eq(twsk_net(tw), net) ||
24776 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24777                         tw = tw_next(tw);
24778                 }
24779                 if (tw) {
24780 @@ -2427,6 +2449,11 @@ get_tw:
24781                 sk = sk_nulls_next(sk);
24782  
24783         sk_nulls_for_each_from(sk, node) {
24784 +               vxdprintk(VXD_CBIT(net, 6),
24785 +                       "sk,egn: %p [#%d] (from %d)",
24786 +                       sk, sk->sk_nid, nx_current_nid());
24787 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24788 +                       continue;
24789                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24790                         goto found;
24791         }
24792 @@ -2632,9 +2659,9 @@ static void get_openreq4(const struct so
24793         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24794                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24795                 i,
24796 -               ireq->loc_addr,
24797 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24798                 ntohs(inet_sk(sk)->inet_sport),
24799 -               ireq->rmt_addr,
24800 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24801                 ntohs(ireq->rmt_port),
24802                 TCP_SYN_RECV,
24803                 0, 0, /* could print option size, but that is af dependent. */
24804 @@ -2657,8 +2684,8 @@ static void get_tcp4_sock(struct sock *s
24805         const struct inet_connection_sock *icsk = inet_csk(sk);
24806         const struct inet_sock *inet = inet_sk(sk);
24807         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24808 -       __be32 dest = inet->inet_daddr;
24809 -       __be32 src = inet->inet_rcv_saddr;
24810 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24811 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24812         __u16 destp = ntohs(inet->inet_dport);
24813         __u16 srcp = ntohs(inet->inet_sport);
24814         int rx_queue;
24815 @@ -2714,8 +2741,8 @@ static void get_timewait4_sock(const str
24816         __u16 destp, srcp;
24817         long delta = tw->tw_ttd - jiffies;
24818  
24819 -       dest  = tw->tw_daddr;
24820 -       src   = tw->tw_rcv_saddr;
24821 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24822 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24823         destp = ntohs(tw->tw_dport);
24824         srcp  = ntohs(tw->tw_sport);
24825  
24826 diff -NurpP --minimal linux-3.7/net/ipv4/tcp_minisocks.c linux-3.7-vs2.3.5.1/net/ipv4/tcp_minisocks.c
24827 --- linux-3.7/net/ipv4/tcp_minisocks.c  2012-12-11 15:47:54.000000000 +0000
24828 +++ linux-3.7-vs2.3.5.1/net/ipv4/tcp_minisocks.c        2012-12-11 15:56:33.000000000 +0000
24829 @@ -23,6 +23,9 @@
24830  #include <linux/slab.h>
24831  #include <linux/sysctl.h>
24832  #include <linux/workqueue.h>
24833 +#include <linux/vs_limit.h>
24834 +#include <linux/vs_socket.h>
24835 +#include <linux/vs_context.h>
24836  #include <net/tcp.h>
24837  #include <net/inet_common.h>
24838  #include <net/xfrm.h>
24839 @@ -289,6 +292,11 @@ void tcp_time_wait(struct sock *sk, int
24840                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
24841                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24842  
24843 +               tw->tw_xid              = sk->sk_xid;
24844 +               tw->tw_vx_info          = NULL;
24845 +               tw->tw_nid              = sk->sk_nid;
24846 +               tw->tw_nx_info          = NULL;
24847 +
24848  #if IS_ENABLED(CONFIG_IPV6)
24849                 if (tw->tw_family == PF_INET6) {
24850                         struct ipv6_pinfo *np = inet6_sk(sk);
24851 diff -NurpP --minimal linux-3.7/net/ipv4/udp.c linux-3.7-vs2.3.5.1/net/ipv4/udp.c
24852 --- linux-3.7/net/ipv4/udp.c    2012-12-11 15:47:54.000000000 +0000
24853 +++ linux-3.7-vs2.3.5.1/net/ipv4/udp.c  2012-12-11 15:56:33.000000000 +0000
24854 @@ -300,14 +300,7 @@ fail:
24855  }
24856  EXPORT_SYMBOL(udp_lib_get_port);
24857  
24858 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24859 -{
24860 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24861 -
24862 -       return  (!ipv6_only_sock(sk2)  &&
24863 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24864 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24865 -}
24866 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24867  
24868  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24869                                        unsigned int port)
24870 @@ -342,6 +335,11 @@ static inline int compute_score(struct s
24871                         if (inet->inet_rcv_saddr != daddr)
24872                                 return -1;
24873                         score += 2;
24874 +               } else {
24875 +                       /* block non nx_info ips */
24876 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24877 +                               daddr, NXA_MASK_BIND))
24878 +                               return -1;
24879                 }
24880                 if (inet->inet_daddr) {
24881                         if (inet->inet_daddr != saddr)
24882 @@ -445,6 +443,7 @@ exact_match:
24883         return result;
24884  }
24885  
24886 +
24887  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24888   * harder than this. -DaveM
24889   */
24890 @@ -490,6 +489,11 @@ begin:
24891         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24892                 score = compute_score(sk, net, saddr, hnum, sport,
24893                                       daddr, dport, dif);
24894 +               /* FIXME: disabled?
24895 +               if (score == 9) {
24896 +                       result = sk;
24897 +                       break;
24898 +               } else */
24899                 if (score > badness) {
24900                         result = sk;
24901                         badness = score;
24902 @@ -503,6 +507,7 @@ begin:
24903         if (get_nulls_value(node) != slot)
24904                 goto begin;
24905  
24906 +
24907         if (result) {
24908                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24909                         result = NULL;
24910 @@ -512,6 +517,7 @@ begin:
24911                         goto begin;
24912                 }
24913         }
24914 +
24915         rcu_read_unlock();
24916         return result;
24917  }
24918 @@ -555,8 +561,7 @@ static inline struct sock *udp_v4_mcast_
24919                     udp_sk(s)->udp_port_hash != hnum ||
24920                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24921                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
24922 -                   (inet->inet_rcv_saddr &&
24923 -                    inet->inet_rcv_saddr != loc_addr) ||
24924 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24925                     ipv6_only_sock(s) ||
24926                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24927                         continue;
24928 @@ -939,6 +944,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24929                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24930                                    faddr, saddr, dport, inet->inet_sport);
24931  
24932 +               if (sk->sk_nx_info) {
24933 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24934 +                       if (IS_ERR(rt)) {
24935 +                               err = PTR_ERR(rt);
24936 +                               rt = NULL;
24937 +                               goto out;
24938 +                       }
24939 +                       ip_rt_put(rt);
24940 +               }
24941 +
24942                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24943                 rt = ip_route_output_flow(net, fl4, sk);
24944                 if (IS_ERR(rt)) {
24945 @@ -1244,7 +1259,8 @@ try_again:
24946         if (sin) {
24947                 sin->sin_family = AF_INET;
24948                 sin->sin_port = udp_hdr(skb)->source;
24949 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24950 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24951 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24952                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24953         }
24954         if (inet->cmsg_flags)
24955 @@ -1992,6 +2008,8 @@ static struct sock *udp_get_first(struct
24956                 sk_nulls_for_each(sk, node, &hslot->head) {
24957                         if (!net_eq(sock_net(sk), net))
24958                                 continue;
24959 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24960 +                               continue;
24961                         if (sk->sk_family == state->family)
24962                                 goto found;
24963                 }
24964 @@ -2009,7 +2027,9 @@ static struct sock *udp_get_next(struct
24965  
24966         do {
24967                 sk = sk_nulls_next(sk);
24968 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24969 +       } while (sk && (!net_eq(sock_net(sk), net) ||
24970 +               sk->sk_family != state->family ||
24971 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24972  
24973         if (!sk) {
24974                 if (state->bucket <= state->udp_table->mask)
24975 @@ -2105,8 +2125,8 @@ static void udp4_format_sock(struct sock
24976                 int bucket, int *len)
24977  {
24978         struct inet_sock *inet = inet_sk(sp);
24979 -       __be32 dest = inet->inet_daddr;
24980 -       __be32 src  = inet->inet_rcv_saddr;
24981 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24982 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24983         __u16 destp       = ntohs(inet->inet_dport);
24984         __u16 srcp        = ntohs(inet->inet_sport);
24985  
24986 diff -NurpP --minimal linux-3.7/net/ipv6/Kconfig linux-3.7-vs2.3.5.1/net/ipv6/Kconfig
24987 --- linux-3.7/net/ipv6/Kconfig  2012-12-11 15:47:54.000000000 +0000
24988 +++ linux-3.7-vs2.3.5.1/net/ipv6/Kconfig        2012-12-11 15:56:33.000000000 +0000
24989 @@ -4,8 +4,8 @@
24990  
24991  #   IPv6 as module will cause a CRASH if you try to unload it
24992  menuconfig IPV6
24993 -       tristate "The IPv6 protocol"
24994 -       default m
24995 +       bool "The IPv6 protocol"
24996 +       default n
24997         ---help---
24998           This is complemental support for the IP version 6.
24999           You will still be able to do traditional IPv4 networking as well.
25000 diff -NurpP --minimal linux-3.7/net/ipv6/addrconf.c linux-3.7-vs2.3.5.1/net/ipv6/addrconf.c
25001 --- linux-3.7/net/ipv6/addrconf.c       2012-12-11 15:47:54.000000000 +0000
25002 +++ linux-3.7-vs2.3.5.1/net/ipv6/addrconf.c     2012-12-11 15:56:33.000000000 +0000
25003 @@ -92,6 +92,8 @@
25004  #include <linux/proc_fs.h>
25005  #include <linux/seq_file.h>
25006  #include <linux/export.h>
25007 +#include <linux/vs_network.h>
25008 +#include <linux/vs_inet6.h>
25009  
25010  /* Set to 3 to get tracing... */
25011  #define ACONF_DEBUG 2
25012 @@ -1094,7 +1096,7 @@ out:
25013  
25014  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25015                        const struct in6_addr *daddr, unsigned int prefs,
25016 -                      struct in6_addr *saddr)
25017 +                      struct in6_addr *saddr, struct nx_info *nxi)
25018  {
25019         struct ipv6_saddr_score scores[2],
25020                                 *score = &scores[0], *hiscore = &scores[1];
25021 @@ -1166,6 +1168,8 @@ int ipv6_dev_get_saddr(struct net *net,
25022                                                dev->name);
25023                                 continue;
25024                         }
25025 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25026 +                               continue;
25027  
25028                         score->rule = -1;
25029                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25030 @@ -3135,7 +3139,10 @@ static void if6_seq_stop(struct seq_file
25031  static int if6_seq_show(struct seq_file *seq, void *v)
25032  {
25033         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25034 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25035 +
25036 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25037 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25038 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25039                    &ifp->addr,
25040                    ifp->idev->dev->ifindex,
25041                    ifp->prefix_len,
25042 @@ -3641,6 +3648,11 @@ static int in6_dump_addrs(struct inet6_d
25043         struct ifacaddr6 *ifaca;
25044         int err = 1;
25045         int ip_idx = *p_ip_idx;
25046 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25047 +
25048 +       /* disable ipv6 on non v6 guests */
25049 +       if (nxi && !nx_info_has_v6(nxi))
25050 +               return skb->len;
25051  
25052         read_lock_bh(&idev->lock);
25053         switch (type) {
25054 @@ -3651,6 +3663,8 @@ static int in6_dump_addrs(struct inet6_d
25055                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25056                         if (++ip_idx < s_ip_idx)
25057                                 continue;
25058 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25059 +                                       continue;
25060                         err = inet6_fill_ifaddr(skb, ifa,
25061                                                 NETLINK_CB(cb->skb).portid,
25062                                                 cb->nlh->nlmsg_seq,
25063 @@ -3667,6 +3681,8 @@ static int in6_dump_addrs(struct inet6_d
25064                      ifmca = ifmca->next, ip_idx++) {
25065                         if (ip_idx < s_ip_idx)
25066                                 continue;
25067 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25068 +                                       continue;
25069                         err = inet6_fill_ifmcaddr(skb, ifmca,
25070                                                   NETLINK_CB(cb->skb).portid,
25071                                                   cb->nlh->nlmsg_seq,
25072 @@ -3682,6 +3698,8 @@ static int in6_dump_addrs(struct inet6_d
25073                      ifaca = ifaca->aca_next, ip_idx++) {
25074                         if (ip_idx < s_ip_idx)
25075                                 continue;
25076 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25077 +                                       continue;
25078                         err = inet6_fill_ifacaddr(skb, ifaca,
25079                                                   NETLINK_CB(cb->skb).portid,
25080                                                   cb->nlh->nlmsg_seq,
25081 @@ -4065,6 +4083,11 @@ static int inet6_dump_ifinfo(struct sk_b
25082         struct inet6_dev *idev;
25083         struct hlist_head *head;
25084         struct hlist_node *node;
25085 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25086 +
25087 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25088 +       if (skb->sk && skb->sk->sk_vx_info)
25089 +               return skb->len; */
25090  
25091         s_h = cb->args[0];
25092         s_idx = cb->args[1];
25093 @@ -4076,6 +4099,8 @@ static int inet6_dump_ifinfo(struct sk_b
25094                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25095                         if (idx < s_idx)
25096                                 goto cont;
25097 +                       if (!v6_dev_in_nx_info(dev, nxi))
25098 +                               goto cont;
25099                         idev = __in6_dev_get(dev);
25100                         if (!idev)
25101                                 goto cont;
25102 diff -NurpP --minimal linux-3.7/net/ipv6/af_inet6.c linux-3.7-vs2.3.5.1/net/ipv6/af_inet6.c
25103 --- linux-3.7/net/ipv6/af_inet6.c       2012-12-11 15:47:54.000000000 +0000
25104 +++ linux-3.7-vs2.3.5.1/net/ipv6/af_inet6.c     2012-12-11 15:56:33.000000000 +0000
25105 @@ -43,6 +43,8 @@
25106  #include <linux/netdevice.h>
25107  #include <linux/icmpv6.h>
25108  #include <linux/netfilter_ipv6.h>
25109 +#include <linux/vs_inet.h>
25110 +#include <linux/vs_inet6.h>
25111  
25112  #include <net/ip.h>
25113  #include <net/ipv6.h>
25114 @@ -160,9 +162,12 @@ lookup_protocol:
25115         }
25116  
25117         err = -EPERM;
25118 +       if ((protocol == IPPROTO_ICMPV6) &&
25119 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25120 +               goto override;
25121         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25122                 goto out_rcu_unlock;
25123 -
25124 +override:
25125         sock->ops = answer->ops;
25126         answer_prot = answer->prot;
25127         answer_no_check = answer->no_check;
25128 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25129         struct inet_sock *inet = inet_sk(sk);
25130         struct ipv6_pinfo *np = inet6_sk(sk);
25131         struct net *net = sock_net(sk);
25132 +       struct nx_v6_sock_addr nsa;
25133         __be32 v4addr = 0;
25134         unsigned short snum;
25135         int addr_type = 0;
25136 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25137         if (addr->sin6_family != AF_INET6)
25138                 return -EAFNOSUPPORT;
25139  
25140 +       err = v6_map_sock_addr(inet, addr, &nsa);
25141 +       if (err)
25142 +               return err;
25143 +
25144         addr_type = ipv6_addr_type(&addr->sin6_addr);
25145         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25146                 return -EINVAL;
25147 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25148                 /* Reproduce AF_INET checks to make the bindings consistent */
25149                 v4addr = addr->sin6_addr.s6_addr32[3];
25150                 chk_addr_ret = inet_addr_type(net, v4addr);
25151 +
25152                 if (!sysctl_ip_nonlocal_bind &&
25153                     !(inet->freebind || inet->transparent) &&
25154                     v4addr != htonl(INADDR_ANY) &&
25155 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25156                         err = -EADDRNOTAVAIL;
25157                         goto out;
25158                 }
25159 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25160 +                       err = -EADDRNOTAVAIL;
25161 +                       goto out;
25162 +               }
25163         } else {
25164                 if (addr_type != IPV6_ADDR_ANY) {
25165                         struct net_device *dev = NULL;
25166 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25167                                 }
25168                         }
25169  
25170 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25171 +                               err = -EADDRNOTAVAIL;
25172 +                               goto out_unlock;
25173 +                       }
25174 +
25175                         /* ipv4 addr of the socket is invalid.  Only the
25176                          * unspecified and mapped address have a v4 equivalent.
25177                          */
25178 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25179                 }
25180         }
25181  
25182 +       /* what's that for? */
25183 +       v6_set_sock_addr(inet, &nsa);
25184 +
25185         inet->inet_rcv_saddr = v4addr;
25186         inet->inet_saddr = v4addr;
25187  
25188 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25189                         return -ENOTCONN;
25190                 sin->sin6_port = inet->inet_dport;
25191                 sin->sin6_addr = np->daddr;
25192 +               /* FIXME: remap lback? */
25193                 if (np->sndflow)
25194                         sin->sin6_flowinfo = np->flow_label;
25195         } else {
25196 +               /* FIXME: remap lback? */
25197                 if (ipv6_addr_any(&np->rcv_saddr))
25198                         sin->sin6_addr = np->saddr;
25199                 else
25200 diff -NurpP --minimal linux-3.7/net/ipv6/datagram.c linux-3.7-vs2.3.5.1/net/ipv6/datagram.c
25201 --- linux-3.7/net/ipv6/datagram.c       2012-07-22 21:39:48.000000000 +0000
25202 +++ linux-3.7-vs2.3.5.1/net/ipv6/datagram.c     2012-12-11 15:56:33.000000000 +0000
25203 @@ -645,7 +645,7 @@ int datagram_send_ctl(struct net *net, s
25204  
25205                         rcu_read_lock();
25206                         if (fl6->flowi6_oif) {
25207 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25208 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25209                                 if (!dev) {
25210                                         rcu_read_unlock();
25211                                         return -ENODEV;
25212 diff -NurpP --minimal linux-3.7/net/ipv6/fib6_rules.c linux-3.7-vs2.3.5.1/net/ipv6/fib6_rules.c
25213 --- linux-3.7/net/ipv6/fib6_rules.c     2012-12-11 15:47:54.000000000 +0000
25214 +++ linux-3.7-vs2.3.5.1/net/ipv6/fib6_rules.c   2012-12-11 15:56:33.000000000 +0000
25215 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25216                                                ip6_dst_idev(&rt->dst)->dev,
25217                                                &flp6->daddr,
25218                                                rt6_flags2srcprefs(flags),
25219 -                                              &saddr))
25220 +                                              &saddr, NULL))
25221                                 goto again;
25222                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25223                                                r->src.plen))
25224 diff -NurpP --minimal linux-3.7/net/ipv6/inet6_hashtables.c linux-3.7-vs2.3.5.1/net/ipv6/inet6_hashtables.c
25225 --- linux-3.7/net/ipv6/inet6_hashtables.c       2011-10-24 16:45:34.000000000 +0000
25226 +++ linux-3.7-vs2.3.5.1/net/ipv6/inet6_hashtables.c     2012-12-11 15:56:33.000000000 +0000
25227 @@ -16,6 +16,7 @@
25228  
25229  #include <linux/module.h>
25230  #include <linux/random.h>
25231 +#include <linux/vs_inet6.h>
25232  
25233  #include <net/inet_connection_sock.h>
25234  #include <net/inet_hashtables.h>
25235 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25236         unsigned int slot = hash & hashinfo->ehash_mask;
25237         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25238  
25239 -
25240         rcu_read_lock();
25241  begin:
25242         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25243 @@ -95,7 +95,7 @@ begin:
25244                                 sock_put(sk);
25245                                 goto begin;
25246                         }
25247 -               goto out;
25248 +                       goto out;
25249                 }
25250         }
25251         if (get_nulls_value(node) != slot)
25252 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25253                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25254                                 return -1;
25255                         score++;
25256 +               } else {
25257 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25258 +                               return -1;
25259                 }
25260                 if (sk->sk_bound_dev_if) {
25261                         if (sk->sk_bound_dev_if != dif)
25262 diff -NurpP --minimal linux-3.7/net/ipv6/ip6_output.c linux-3.7-vs2.3.5.1/net/ipv6/ip6_output.c
25263 --- linux-3.7/net/ipv6/ip6_output.c     2012-12-11 15:47:54.000000000 +0000
25264 +++ linux-3.7-vs2.3.5.1/net/ipv6/ip6_output.c   2012-12-11 15:56:33.000000000 +0000
25265 @@ -964,7 +964,8 @@ static int ip6_dst_lookup_tail(struct so
25266                 struct rt6_info *rt = (struct rt6_info *) *dst;
25267                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25268                                           sk ? inet6_sk(sk)->srcprefs : 0,
25269 -                                         &fl6->saddr);
25270 +                                         &fl6->saddr,
25271 +                                         sk ? sk->sk_nx_info : NULL);
25272                 if (err)
25273                         goto out_err_release;
25274         }
25275 diff -NurpP --minimal linux-3.7/net/ipv6/ndisc.c linux-3.7-vs2.3.5.1/net/ipv6/ndisc.c
25276 --- linux-3.7/net/ipv6/ndisc.c  2012-12-11 15:47:54.000000000 +0000
25277 +++ linux-3.7-vs2.3.5.1/net/ipv6/ndisc.c        2012-12-11 15:56:33.000000000 +0000
25278 @@ -517,7 +517,7 @@ static void ndisc_send_na(struct net_dev
25279         } else {
25280                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25281                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25282 -                                      &tmpaddr))
25283 +                                      &tmpaddr, NULL))
25284                         return;
25285                 src_addr = &tmpaddr;
25286         }
25287 diff -NurpP --minimal linux-3.7/net/ipv6/raw.c linux-3.7-vs2.3.5.1/net/ipv6/raw.c
25288 --- linux-3.7/net/ipv6/raw.c    2012-12-11 15:47:54.000000000 +0000
25289 +++ linux-3.7-vs2.3.5.1/net/ipv6/raw.c  2012-12-11 15:56:33.000000000 +0000
25290 @@ -30,6 +30,7 @@
25291  #include <linux/icmpv6.h>
25292  #include <linux/netfilter.h>
25293  #include <linux/netfilter_ipv6.h>
25294 +#include <linux/vs_inet6.h>
25295  #include <linux/skbuff.h>
25296  #include <linux/compat.h>
25297  #include <asm/uaccess.h>
25298 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25299                                 goto out_unlock;
25300                 }
25301  
25302 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25303 +                       err = -EADDRNOTAVAIL;
25304 +                       if (dev)
25305 +                               dev_put(dev);
25306 +                       goto out;
25307 +               }
25308 +
25309                 /* ipv4 addr of the socket is invalid.  Only the
25310                  * unspecified and mapped address have a v4 equivalent.
25311                  */
25312 diff -NurpP --minimal linux-3.7/net/ipv6/route.c linux-3.7-vs2.3.5.1/net/ipv6/route.c
25313 --- linux-3.7/net/ipv6/route.c  2012-12-11 15:47:55.000000000 +0000
25314 +++ linux-3.7-vs2.3.5.1/net/ipv6/route.c        2012-12-11 15:56:33.000000000 +0000
25315 @@ -57,6 +57,7 @@
25316  #include <net/xfrm.h>
25317  #include <net/netevent.h>
25318  #include <net/netlink.h>
25319 +#include <linux/vs_inet6.h>
25320  
25321  #include <asm/uaccess.h>
25322  
25323 @@ -2116,15 +2117,17 @@ int ip6_route_get_saddr(struct net *net,
25324                         struct rt6_info *rt,
25325                         const struct in6_addr *daddr,
25326                         unsigned int prefs,
25327 -                       struct in6_addr *saddr)
25328 +                       struct in6_addr *saddr,
25329 +                       struct nx_info *nxi)
25330  {
25331         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25332         int err = 0;
25333 -       if (rt->rt6i_prefsrc.plen)
25334 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25335 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25336                 *saddr = rt->rt6i_prefsrc.addr;
25337         else
25338                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25339 -                                        daddr, prefs, saddr);
25340 +                                        daddr, prefs, saddr, nxi);
25341         return err;
25342  }
25343  
25344 @@ -2478,7 +2481,8 @@ static int rt6_fill_node(struct net *net
25345                                 goto nla_put_failure;
25346         } else if (dst) {
25347                 struct in6_addr saddr_buf;
25348 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25349 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25350 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25351                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25352                         goto nla_put_failure;
25353         }
25354 @@ -2692,6 +2696,7 @@ static int rt6_info_route(struct rt6_inf
25355         struct seq_file *m = p_arg;
25356         struct neighbour *n;
25357  
25358 +       /* FIXME: check for network context? */
25359         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25360  
25361  #ifdef CONFIG_IPV6_SUBTREES
25362 diff -NurpP --minimal linux-3.7/net/ipv6/tcp_ipv6.c linux-3.7-vs2.3.5.1/net/ipv6/tcp_ipv6.c
25363 --- linux-3.7/net/ipv6/tcp_ipv6.c       2012-12-11 15:47:55.000000000 +0000
25364 +++ linux-3.7-vs2.3.5.1/net/ipv6/tcp_ipv6.c     2012-12-11 15:56:33.000000000 +0000
25365 @@ -71,6 +71,7 @@
25366  
25367  #include <linux/crypto.h>
25368  #include <linux/scatterlist.h>
25369 +#include <linux/vs_inet6.h>
25370  
25371  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25372  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25373 @@ -175,8 +176,15 @@ static int tcp_v6_connect(struct sock *s
25374          *      connect() to INADDR_ANY means loopback (BSD'ism).
25375          */
25376  
25377 -       if(ipv6_addr_any(&usin->sin6_addr))
25378 -               usin->sin6_addr.s6_addr[15] = 0x1;
25379 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25380 +               struct nx_info *nxi =  sk->sk_nx_info;
25381 +
25382 +               if (nxi && nx_info_has_v6(nxi))
25383 +                       /* FIXME: remap lback? */
25384 +                       usin->sin6_addr = nxi->v6.ip;
25385 +               else
25386 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25387 +       }
25388  
25389         addr_type = ipv6_addr_type(&usin->sin6_addr);
25390  
25391 diff -NurpP --minimal linux-3.7/net/ipv6/udp.c linux-3.7-vs2.3.5.1/net/ipv6/udp.c
25392 --- linux-3.7/net/ipv6/udp.c    2012-12-11 15:47:55.000000000 +0000
25393 +++ linux-3.7-vs2.3.5.1/net/ipv6/udp.c  2012-12-11 15:56:33.000000000 +0000
25394 @@ -45,42 +45,68 @@
25395  #include <net/tcp_states.h>
25396  #include <net/ip6_checksum.h>
25397  #include <net/xfrm.h>
25398 +#include <linux/vs_inet6.h>
25399  
25400  #include <linux/proc_fs.h>
25401  #include <linux/seq_file.h>
25402  #include <trace/events/skb.h>
25403  #include "udp_impl.h"
25404  
25405 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25406 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25407  {
25408 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25409 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25410         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25411 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25412 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25413         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25414 -       int sk_ipv6only = ipv6_only_sock(sk);
25415 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25416         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25417 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25418 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25419         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25420  
25421         /* if both are mapped, treat as IPv4 */
25422 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25423 -               return (!sk2_ipv6only &&
25424 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25425 +               if (!sk2_ipv6only &&
25426                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25427 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25428 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25429 +                       goto vs_v4;
25430 +               else
25431 +                       return 0;
25432 +       }
25433  
25434         if (addr_type2 == IPV6_ADDR_ANY &&
25435             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25436 -               return 1;
25437 +               goto vs;
25438  
25439         if (addr_type == IPV6_ADDR_ANY &&
25440 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25441 -               return 1;
25442 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25443 +               goto vs;
25444  
25445         if (sk2_rcv_saddr6 &&
25446 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25447 -               return 1;
25448 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25449 +               goto vs;
25450  
25451         return 0;
25452 +
25453 +vs_v4:
25454 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25455 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25456 +       if (!sk2_rcv_saddr)
25457 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25458 +       if (!sk1_rcv_saddr)
25459 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25460 +       return 1;
25461 +vs:
25462 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25463 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25464 +       else if (addr_type2 == IPV6_ADDR_ANY)
25465 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25466 +       else if (addr_type == IPV6_ADDR_ANY) {
25467 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25468 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25469 +               else
25470 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25471 +       }
25472 +       return 1;
25473  }
25474  
25475  static unsigned int udp6_portaddr_hash(struct net *net,
25476 @@ -144,6 +170,10 @@ static inline int compute_score(struct s
25477                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25478                                 return -1;
25479                         score++;
25480 +               } else {
25481 +                       /* block non nx_info ips */
25482 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25483 +                               return -1;
25484                 }
25485                 if (!ipv6_addr_any(&np->daddr)) {
25486                         if (!ipv6_addr_equal(&np->daddr, saddr))
25487 diff -NurpP --minimal linux-3.7/net/ipv6/xfrm6_policy.c linux-3.7-vs2.3.5.1/net/ipv6/xfrm6_policy.c
25488 --- linux-3.7/net/ipv6/xfrm6_policy.c   2012-10-04 13:27:50.000000000 +0000
25489 +++ linux-3.7-vs2.3.5.1/net/ipv6/xfrm6_policy.c 2012-12-11 15:56:33.000000000 +0000
25490 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25491         dev = ip6_dst_idev(dst)->dev;
25492         ipv6_dev_get_saddr(dev_net(dev), dev,
25493                            (struct in6_addr *)&daddr->a6, 0,
25494 -                          (struct in6_addr *)&saddr->a6);
25495 +                          (struct in6_addr *)&saddr->a6, NULL);
25496         dst_release(dst);
25497         return 0;
25498  }
25499 diff -NurpP --minimal linux-3.7/net/netfilter/ipvs/ip_vs_xmit.c linux-3.7-vs2.3.5.1/net/netfilter/ipvs/ip_vs_xmit.c
25500 --- linux-3.7/net/netfilter/ipvs/ip_vs_xmit.c   2012-12-11 15:47:55.000000000 +0000
25501 +++ linux-3.7-vs2.3.5.1/net/netfilter/ipvs/ip_vs_xmit.c 2012-12-11 15:56:33.000000000 +0000
25502 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25503                 return dst;
25504         if (ipv6_addr_any(&fl6.saddr) &&
25505             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25506 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25507 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25508                 goto out_err;
25509         if (do_xfrm) {
25510                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25511 diff -NurpP --minimal linux-3.7/net/netlink/af_netlink.c linux-3.7-vs2.3.5.1/net/netlink/af_netlink.c
25512 --- linux-3.7/net/netlink/af_netlink.c  2012-12-11 15:47:56.000000000 +0000
25513 +++ linux-3.7-vs2.3.5.1/net/netlink/af_netlink.c        2012-12-11 15:56:33.000000000 +0000
25514 @@ -55,6 +55,9 @@
25515  #include <linux/types.h>
25516  #include <linux/audit.h>
25517  #include <linux/mutex.h>
25518 +#include <linux/vs_context.h>
25519 +#include <linux/vs_network.h>
25520 +#include <linux/vs_limit.h>
25521  
25522  #include <net/net_namespace.h>
25523  #include <net/sock.h>
25524 @@ -1981,6 +1984,8 @@ static struct sock *netlink_seq_socket_i
25525                         sk_for_each(s, node, &hash->table[j]) {
25526                                 if (sock_net(s) != seq_file_net(seq))
25527                                         continue;
25528 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25529 +                                       continue;
25530                                 if (off == pos) {
25531                                         iter->link = i;
25532                                         iter->hash_idx = j;
25533 @@ -2015,7 +2020,8 @@ static void *netlink_seq_next(struct seq
25534         s = v;
25535         do {
25536                 s = sk_next(s);
25537 -       } while (s && sock_net(s) != seq_file_net(seq));
25538 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25539 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25540         if (s)
25541                 return s;
25542  
25543 @@ -2027,7 +2033,8 @@ static void *netlink_seq_next(struct seq
25544  
25545                 for (; j <= hash->mask; j++) {
25546                         s = sk_head(&hash->table[j]);
25547 -                       while (s && sock_net(s) != seq_file_net(seq))
25548 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25549 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25550                                 s = sk_next(s);
25551                         if (s) {
25552                                 iter->link = i;
25553 diff -NurpP --minimal linux-3.7/net/socket.c linux-3.7-vs2.3.5.1/net/socket.c
25554 --- linux-3.7/net/socket.c      2012-12-11 15:47:57.000000000 +0000
25555 +++ linux-3.7-vs2.3.5.1/net/socket.c    2012-12-11 15:56:33.000000000 +0000
25556 @@ -99,6 +99,10 @@
25557  
25558  #include <net/sock.h>
25559  #include <linux/netfilter.h>
25560 +#include <linux/vs_base.h>
25561 +#include <linux/vs_socket.h>
25562 +#include <linux/vs_inet.h>
25563 +#include <linux/vs_inet6.h>
25564  
25565  #include <linux/if_tun.h>
25566  #include <linux/ipv6_route.h>
25567 @@ -619,6 +623,7 @@ static inline int __sock_sendmsg_nosec(s
25568                                        struct msghdr *msg, size_t size)
25569  {
25570         struct sock_iocb *si = kiocb_to_siocb(iocb);
25571 +       size_t len;
25572  
25573         sock_update_classid(sock->sk);
25574  
25575 @@ -627,7 +632,22 @@ static inline int __sock_sendmsg_nosec(s
25576         si->msg = msg;
25577         si->size = size;
25578  
25579 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25580 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25581 +       if (sock->sk) {
25582 +               if (len == size)
25583 +                       vx_sock_send(sock->sk, size);
25584 +               else
25585 +                       vx_sock_fail(sock->sk, size);
25586 +       }
25587 +       vxdprintk(VXD_CBIT(net, 7),
25588 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25589 +               sock, sock->sk,
25590 +               (sock->sk)?sock->sk->sk_nx_info:0,
25591 +               (sock->sk)?sock->sk->sk_vx_info:0,
25592 +               (sock->sk)?sock->sk->sk_xid:0,
25593 +               (sock->sk)?sock->sk->sk_nid:0,
25594 +               (unsigned int)size, len);
25595 +       return len;
25596  }
25597  
25598  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25599 @@ -783,6 +803,7 @@ static inline int __sock_recvmsg_nosec(s
25600                                        struct msghdr *msg, size_t size, int flags)
25601  {
25602         struct sock_iocb *si = kiocb_to_siocb(iocb);
25603 +       int len;
25604  
25605         sock_update_classid(sock->sk);
25606  
25607 @@ -792,7 +813,18 @@ static inline int __sock_recvmsg_nosec(s
25608         si->size = size;
25609         si->flags = flags;
25610  
25611 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25612 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25613 +       if ((len >= 0) && sock->sk)
25614 +               vx_sock_recv(sock->sk, len);
25615 +       vxdprintk(VXD_CBIT(net, 7),
25616 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25617 +               sock, sock->sk,
25618 +               (sock->sk)?sock->sk->sk_nx_info:0,
25619 +               (sock->sk)?sock->sk->sk_vx_info:0,
25620 +               (sock->sk)?sock->sk->sk_xid:0,
25621 +               (sock->sk)?sock->sk->sk_nid:0,
25622 +               (unsigned int)size, len);
25623 +       return len;
25624  }
25625  
25626  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25627 @@ -1277,6 +1309,13 @@ int __sock_create(struct net *net, int f
25628         if (type < 0 || type >= SOCK_MAX)
25629                 return -EINVAL;
25630  
25631 +       if (!nx_check(0, VS_ADMIN)) {
25632 +               if (family == PF_INET && !current_nx_info_has_v4())
25633 +                       return -EAFNOSUPPORT;
25634 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25635 +                       return -EAFNOSUPPORT;
25636 +       }
25637 +
25638         /* Compatibility.
25639  
25640            This uglymoron is moved from INET layer to here to avoid
25641 @@ -1411,6 +1450,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25642         if (retval < 0)
25643                 goto out;
25644  
25645 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25646         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25647         if (retval < 0)
25648                 goto out_release;
25649 @@ -1452,10 +1492,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25650         err = sock_create(family, type, protocol, &sock1);
25651         if (err < 0)
25652                 goto out;
25653 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25654  
25655         err = sock_create(family, type, protocol, &sock2);
25656         if (err < 0)
25657                 goto out_release_1;
25658 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25659  
25660         err = sock1->ops->socketpair(sock1, sock2);
25661         if (err < 0)
25662 diff -NurpP --minimal linux-3.7/net/sunrpc/auth.c linux-3.7-vs2.3.5.1/net/sunrpc/auth.c
25663 --- linux-3.7/net/sunrpc/auth.c 2012-10-04 13:27:51.000000000 +0000
25664 +++ linux-3.7-vs2.3.5.1/net/sunrpc/auth.c       2012-12-11 15:56:33.000000000 +0000
25665 @@ -15,6 +15,7 @@
25666  #include <linux/sunrpc/clnt.h>
25667  #include <linux/sunrpc/gss_api.h>
25668  #include <linux/spinlock.h>
25669 +#include <linux/vs_tag.h>
25670  
25671  #ifdef RPC_DEBUG
25672  # define RPCDBG_FACILITY       RPCDBG_AUTH
25673 @@ -481,6 +482,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25674         memset(&acred, 0, sizeof(acred));
25675         acred.uid = cred->fsuid;
25676         acred.gid = cred->fsgid;
25677 +       acred.tag = dx_current_tag();
25678         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25679  
25680         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25681 @@ -521,6 +523,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25682         struct auth_cred acred = {
25683                 .uid = 0,
25684                 .gid = 0,
25685 +               .tag = dx_current_tag(),
25686         };
25687  
25688         dprintk("RPC: %5u looking up %s cred\n",
25689 diff -NurpP --minimal linux-3.7/net/sunrpc/auth_unix.c linux-3.7-vs2.3.5.1/net/sunrpc/auth_unix.c
25690 --- linux-3.7/net/sunrpc/auth_unix.c    2012-07-22 21:39:49.000000000 +0000
25691 +++ linux-3.7-vs2.3.5.1/net/sunrpc/auth_unix.c  2012-12-11 15:56:33.000000000 +0000
25692 @@ -13,11 +13,13 @@
25693  #include <linux/sunrpc/clnt.h>
25694  #include <linux/sunrpc/auth.h>
25695  #include <linux/user_namespace.h>
25696 +#include <linux/vs_tag.h>
25697  
25698  #define NFS_NGROUPS    16
25699  
25700  struct unx_cred {
25701         struct rpc_cred         uc_base;
25702 +       tag_t                   uc_tag;
25703         gid_t                   uc_gid;
25704         gid_t                   uc_gids[NFS_NGROUPS];
25705  };
25706 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
25707                 groups = NFS_NGROUPS;
25708  
25709         cred->uc_gid = acred->gid;
25710 +       cred->uc_tag = acred->tag;
25711         for (i = 0; i < groups; i++) {
25712                 gid_t gid;
25713                 gid = from_kgid(&init_user_ns, GROUP_AT(acred->group_info, i));
25714 @@ -123,7 +126,9 @@ unx_match(struct auth_cred *acred, struc
25715         unsigned int i;
25716  
25717  
25718 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25719 +       if (cred->uc_uid != acred->uid ||
25720 +               cred->uc_gid != acred->gid ||
25721 +               cred->uc_tag != acred->tag)
25722                 return 0;
25723  
25724         if (acred->group_info != NULL)
25725 @@ -152,7 +157,7 @@ unx_marshal(struct rpc_task *task, __be3
25726         struct rpc_clnt *clnt = task->tk_client;
25727         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25728         __be32          *base, *hold;
25729 -       int             i;
25730 +       int             i, tag;
25731  
25732         *p++ = htonl(RPC_AUTH_UNIX);
25733         base = p++;
25734 @@ -162,9 +167,12 @@ unx_marshal(struct rpc_task *task, __be3
25735          * Copy the UTS nodename captured when the client was created.
25736          */
25737         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25738 +       tag = task->tk_client->cl_tag;
25739  
25740 -       *p++ = htonl((u32) cred->uc_uid);
25741 -       *p++ = htonl((u32) cred->uc_gid);
25742 +       *p++ = htonl((u32) TAGINO_UID(tag,
25743 +               cred->uc_uid, cred->uc_tag));
25744 +       *p++ = htonl((u32) TAGINO_GID(tag,
25745 +               cred->uc_gid, cred->uc_tag));
25746         hold = p++;
25747         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25748                 *p++ = htonl((u32) cred->uc_gids[i]);
25749 diff -NurpP --minimal linux-3.7/net/sunrpc/clnt.c linux-3.7-vs2.3.5.1/net/sunrpc/clnt.c
25750 --- linux-3.7/net/sunrpc/clnt.c 2012-12-11 15:47:57.000000000 +0000
25751 +++ linux-3.7-vs2.3.5.1/net/sunrpc/clnt.c       2012-12-11 15:56:33.000000000 +0000
25752 @@ -31,6 +31,7 @@
25753  #include <linux/in6.h>
25754  #include <linux/un.h>
25755  #include <linux/rcupdate.h>
25756 +#include <linux/vs_cvirt.h>
25757  
25758  #include <linux/sunrpc/clnt.h>
25759  #include <linux/sunrpc/rpc_pipe_fs.h>
25760 @@ -481,6 +482,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25761         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25762                 clnt->cl_chatty = 1;
25763  
25764 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25765 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25766 +               clnt->cl_tag = 1; */
25767         return clnt;
25768  }
25769  EXPORT_SYMBOL_GPL(rpc_create);
25770 diff -NurpP --minimal linux-3.7/net/unix/af_unix.c linux-3.7-vs2.3.5.1/net/unix/af_unix.c
25771 --- linux-3.7/net/unix/af_unix.c        2012-12-11 15:47:57.000000000 +0000
25772 +++ linux-3.7-vs2.3.5.1/net/unix/af_unix.c      2012-12-11 15:56:33.000000000 +0000
25773 @@ -114,6 +114,8 @@
25774  #include <linux/mount.h>
25775  #include <net/checksum.h>
25776  #include <linux/security.h>
25777 +#include <linux/vs_context.h>
25778 +#include <linux/vs_limit.h>
25779  
25780  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25781  EXPORT_SYMBOL_GPL(unix_socket_table);
25782 @@ -271,6 +273,8 @@ static struct sock *__unix_find_socket_b
25783                 if (!net_eq(sock_net(s), net))
25784                         continue;
25785  
25786 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25787 +                       continue;
25788                 if (u->addr->len == len &&
25789                     !memcmp(u->addr->name, sunname, len))
25790                         goto found;
25791 @@ -2259,6 +2263,8 @@ static struct sock *unix_from_bucket(str
25792         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25793                 if (sock_net(sk) != seq_file_net(seq))
25794                         continue;
25795 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25796 +                       continue;
25797                 if (++count == offset)
25798                         break;
25799         }
25800 @@ -2276,6 +2282,8 @@ static struct sock *unix_next_socket(str
25801                 sk = sk_next(sk);
25802                 if (!sk)
25803                         goto next_bucket;
25804 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25805 +                       continue;
25806                 if (sock_net(sk) == seq_file_net(seq))
25807                         return sk;
25808         }
25809 diff -NurpP --minimal linux-3.7/scripts/checksyscalls.sh linux-3.7-vs2.3.5.1/scripts/checksyscalls.sh
25810 --- linux-3.7/scripts/checksyscalls.sh  2012-10-04 13:27:51.000000000 +0000
25811 +++ linux-3.7-vs2.3.5.1/scripts/checksyscalls.sh        2012-12-11 15:56:33.000000000 +0000
25812 @@ -193,7 +193,6 @@ cat << EOF
25813  #define __IGNORE_afs_syscall
25814  #define __IGNORE_getpmsg
25815  #define __IGNORE_putpmsg
25816 -#define __IGNORE_vserver
25817  EOF
25818  }
25819  
25820 diff -NurpP --minimal linux-3.7/security/commoncap.c linux-3.7-vs2.3.5.1/security/commoncap.c
25821 --- linux-3.7/security/commoncap.c      2012-07-22 21:39:51.000000000 +0000
25822 +++ linux-3.7-vs2.3.5.1/security/commoncap.c    2012-12-11 15:56:33.000000000 +0000
25823 @@ -76,14 +76,20 @@ int cap_netlink_send(struct sock *sk, st
25824  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25825                 int cap, int audit)
25826  {
25827 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25828 +
25829         for (;;) {
25830                 /* The owner of the user namespace has all caps. */
25831                 if (targ_ns != &init_user_ns && uid_eq(targ_ns->owner, cred->euid))
25832                         return 0;
25833  
25834                 /* Do we have the necessary capabilities? */
25835 -               if (targ_ns == cred->user_ns)
25836 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25837 +               if (targ_ns == cred->user_ns) {
25838 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25839 +                           cap_raised(cred->cap_effective, cap))
25840 +                               return 0;
25841 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25842 +               }
25843  
25844                 /* Have we tried all of the parent namespaces? */
25845                 if (targ_ns == &init_user_ns)
25846 @@ -619,7 +625,7 @@ int cap_inode_setxattr(struct dentry *de
25847  
25848         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25849                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25850 -           !capable(CAP_SYS_ADMIN))
25851 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25852                 return -EPERM;
25853         return 0;
25854  }
25855 @@ -645,7 +651,7 @@ int cap_inode_removexattr(struct dentry
25856  
25857         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25858                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25859 -           !capable(CAP_SYS_ADMIN))
25860 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25861                 return -EPERM;
25862         return 0;
25863  }
25864 diff -NurpP --minimal linux-3.7/security/selinux/hooks.c linux-3.7-vs2.3.5.1/security/selinux/hooks.c
25865 --- linux-3.7/security/selinux/hooks.c  2012-12-11 15:48:01.000000000 +0000
25866 +++ linux-3.7-vs2.3.5.1/security/selinux/hooks.c        2012-12-11 15:56:33.000000000 +0000
25867 @@ -66,7 +66,6 @@
25868  #include <linux/dccp.h>
25869  #include <linux/quota.h>
25870  #include <linux/un.h>          /* for Unix socket types */
25871 -#include <net/af_unix.h>       /* for Unix socket types */
25872  #include <linux/parser.h>
25873  #include <linux/nfs_mount.h>
25874  #include <net/ipv6.h>
25875 diff -NurpP linux-3.7-vs2.3.5.1/kernel/vserver/network.c linux-3.7-vs2.3.5.1.1/kernel/vserver/network.c
25876 --- linux-3.7-vs2.3.5.1/kernel/vserver/network.c        2012-12-11 15:56:33.000000000 +0000
25877 +++ linux-3.7-vs2.3.5.1.1/kernel/vserver/network.c      2012-12-13 13:48:35.000000000 +0000
25878 @@ -162,6 +163,9 @@ static void __dealloc_nx_info(struct nx_
25879         BUG_ON(atomic_read(&nxi->nx_tasks));
25880  
25881         __dealloc_nx_addr_v4_all(nxi->v4.next);
25882 +#ifdef CONFIG_IPV6
25883 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
25884 +#endif
25885  
25886         nxi->nx_state |= NXS_RELEASED;
25887         kfree(nxi);
25888 diff -NurpP linux-3.7-vs2.3.5.1/include/linux/vs_inet.h linux-3.7-vs2.3.5.1.1/include/linux/vs_inet.h
25889 --- linux-3.7-vs2.3.5.1/include/linux/vs_inet.h 2012-12-11 15:56:32.000000000 +0000
25890 +++ linux-3.7-vs2.3.5.1.1/include/linux/vs_inet.h       2012-12-13 12:52:33.000000000 +0000
25891 @@ -81,12 +81,15 @@ int v4_addr_in_nx_info(struct nx_info *n
25892                 (nxi->v4_bcast.s_addr == addr))
25893                 goto out;
25894         ret = 5;
25895 +
25896         /* check for v4 addresses */
25897 +       spin_lock(&nxi->addr_lock);
25898         for (nxa = &nxi->v4; nxa; nxa = nxa->next)
25899                 if (v4_addr_match(nxa, addr, tmask))
25900                         goto out;
25901         ret = 0;
25902  out:
25903 +       spin_unlock(&nxi->addr_lock);
25904         vxdprintk(VXD_CBIT(net, 0),
25905                 "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
25906                 nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
25907 @@ -104,11 +107,16 @@ static inline
25908  int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
25909  {
25910         struct nx_addr_v4 *ptr;
25911 +       int ret = 1;
25912  
25913 +       spin_lock(&nxi->addr_lock);
25914         for (ptr = &nxi->v4; ptr; ptr = ptr->next)
25915                 if (v4_nx_addr_match(ptr, nxa, mask))
25916 -                       return 1;
25917 -       return 0;
25918 +                       goto out;
25919 +       ret = 0;
25920 +out:
25921 +       spin_unlock(&nxi->addr_lock);
25922 +       return ret;
25923  }
25924  
25925  #include <net/inet_sock.h>
25926 diff -NurpP linux-3.7-vs2.3.5.1/include/linux/vs_inet6.h linux-3.7-vs2.3.5.1.1/include/linux/vs_inet6.h
25927 --- linux-3.7-vs2.3.5.1/include/linux/vs_inet6.h        2012-12-11 15:56:32.000000000 +0000
25928 +++ linux-3.7-vs2.3.5.1.1/include/linux/vs_inet6.h      2012-12-13 12:52:39.000000000 +0000
25929 @@ -45,11 +45,14 @@ int v6_addr_in_nx_info(struct nx_info *n
25930  
25931         if (!nxi)
25932                 goto out;
25933 +
25934 +       spin_lock(&nxi->addr_lock);
25935         for (nxa = &nxi->v6; nxa; nxa = nxa->next)
25936                 if (v6_addr_match(nxa, addr, mask))
25937                         goto out;
25938         ret = 0;
25939  out:
25940 +       spin_unlock(&nxi->addr_lock);
25941         vxdprintk(VXD_CBIT(net, 0),
25942                 "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
25943                 nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
25944 @@ -67,11 +70,16 @@ static inline
25945  int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
25946  {
25947         struct nx_addr_v6 *ptr;
25948 +       int ret = 1;
25949  
25950 +       spin_lock(&nxi->addr_lock);
25951         for (ptr = &nxi->v6; ptr; ptr = ptr->next)
25952                 if (v6_nx_addr_match(ptr, nxa, mask))
25953 -                       return 1;
25954 -       return 0;
25955 +                       goto out;
25956 +       ret = 0;
25957 +out:
25958 +       spin_unlock(&nxi->addr_lock);
25959 +       return ret;
25960  }
25961  
25962  
25963 diff -NurpP linux-3.7-vs2.3.5.1/include/linux/vserver/network.h linux-3.7-vs2.3.5.1.1/include/linux/vserver/network.h
25964 --- linux-3.7-vs2.3.5.1/include/linux/vserver/network.h 2012-12-11 15:56:32.000000000 +0000
25965 +++ linux-3.7-vs2.3.5.1.1/include/linux/vserver/network.h       2012-12-13 13:40:52.000000000 +0000
25966 @@ -109,6 +109,7 @@ struct nx_info {
25967         uint64_t nx_flags;              /* network flag word */
25968         uint64_t nx_ncaps;              /* network capabilities */
25969  
25970 +       spinlock_t addr_lock;           /* protect address changes */
25971         struct in_addr v4_lback;        /* Loopback address */
25972         struct in_addr v4_bcast;        /* Broadcast address */
25973         struct nx_addr_v4 v4;           /* First/Single ipv4 address */
25974 diff -NurpP linux-3.7-vs2.3.5.1/kernel/vserver/network.c linux-3.7-vs2.3.5.1.1/kernel/vserver/network.c
25975 --- linux-3.7-vs2.3.5.1/kernel/vserver/network.c        2012-12-11 15:56:33.000000000 +0000
25976 +++ linux-3.7-vs2.3.5.1.1/kernel/vserver/network.c      2012-12-13 13:48:35.000000000 +0000
25977 @@ -131,6 +131,7 @@ static struct nx_info *__alloc_nx_info(n
25978         INIT_HLIST_NODE(&new->nx_hlist);
25979         atomic_set(&new->nx_usecnt, 0);
25980         atomic_set(&new->nx_tasks, 0);
25981 +       spin_lock_init(&new->addr_lock);
25982         new->nx_state = 0;
25983  
25984         new->nx_flags = NXF_INIT_SET;
25985 @@ -593,26 +597,31 @@ int do_add_v4_addr(struct nx_info *nxi,
25986         uint16_t type, uint16_t flags)
25987  {
25988         struct nx_addr_v4 *nxa = &nxi->v4;
25989 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
25990 +
25991 +       if (IS_ERR(new))
25992 +               return PTR_ERR(new);
25993  
25994 +       spin_lock(&nxi->addr_lock);
25995         if (NX_IPV4(nxi)) {
25996                 /* locate last entry */
25997                 for (; nxa->next; nxa = nxa->next);
25998 -               nxa->next = __alloc_nx_addr_v4();
25999 -               nxa = nxa->next;
26000 -
26001 -               if (IS_ERR(nxa))
26002 -                       return PTR_ERR(nxa);
26003 -       }
26004 +               nxa->next = new;
26005 +               nxa = new;
26006 +               new = NULL;
26007  
26008 -       if (nxi->v4.next)
26009                 /* remove single ip for ip list */
26010                 nxi->nx_flags &= ~NXF_SINGLE_IP;
26011 +       }
26012  
26013         nxa->ip[0].s_addr = ip;
26014         nxa->ip[1].s_addr = ip2;
26015         nxa->mask.s_addr = mask;
26016         nxa->type = type;
26017         nxa->flags = flags;
26018 +       spin_unlock(&nxi->addr_lock);
26019 +       if (new)
26020 +               __dealloc_nx_addr_v4(new);
26021         return 0;
26022  }
26023  
26024 @@ -620,20 +629,25 @@ int do_remove_v4_addr(struct nx_info *nx
26025         uint16_t type, uint16_t flags)
26026  {
26027         struct nx_addr_v4 *nxa = &nxi->v4;
26028 +       struct nx_addr_v4 *old = NULL;
26029 +       int ret = 0;
26030  
26031 +       spin_lock(&nxi->addr_lock);
26032         switch (type) {
26033  /*     case NXA_TYPE_ADDR:
26034                 break;          */
26035  
26036         case NXA_TYPE_ANY:
26037 -               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
26038 +               old = xchg(&nxa->next, NULL);
26039                 memset(nxa, 0, sizeof(*nxa));
26040                 break;
26041  
26042         default:
26043 -               return -EINVAL;
26044 +               ret = -EINVAL;
26045         }
26046 -       return 0;
26047 +       spin_unlock(&nxi->addr_lock);
26048 +       __dealloc_nx_addr_v4_all(old);
26049 +       return ret;
26050  }
26051  
26052  
26053 @@ -687,10 +701,7 @@ int vc_net_remove(struct nx_info *nxi, v
26054  
26055         switch (vc_data.type) {
26056         case NXA_TYPE_ANY:
26057 -               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
26058 -               memset(&nxi->v4, 0, sizeof(nxi->v4));
26059 -               break;
26060 -
26061 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
26062         default:
26063                 return -EINVAL;
26064         }
26065 @@ -782,15 +793,18 @@ int do_add_v6_addr(struct nx_info *nxi,
26066         uint32_t prefix, uint16_t type, uint16_t flags)
26067  {
26068         struct nx_addr_v6 *nxa = &nxi->v6;
26069 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
26070  
26071 +       if (IS_ERR(new))
26072 +               return PTR_ERR(new);
26073 +
26074 +       spin_lock(&nxi->addr_lock);
26075         if (NX_IPV6(nxi)) {
26076                 /* locate last entry */
26077                 for (; nxa->next; nxa = nxa->next);
26078 -               nxa->next = __alloc_nx_addr_v6();
26079 -               nxa = nxa->next;
26080 -
26081 -               if (IS_ERR(nxa))
26082 -                       return PTR_ERR(nxa);
26083 +               nxa->next = new;
26084 +               nxa = new;
26085 +               new = NULL;
26086         }
26087  
26088         nxa->ip = *ip;
26089 @@ -798,6 +812,9 @@ int do_add_v6_addr(struct nx_info *nxi,
26090         nxa->prefix = prefix;
26091         nxa->type = type;
26092         nxa->flags = flags;
26093 +       spin_unlock(&nxi->addr_lock);
26094 +       if (new)
26095 +               __dealloc_nx_addr_v6(new);
26096         return 0;
26097  }
26098  
26099 diff -NurpP linux-3.7-vs2.3.5.1/kernel/vserver/network.c linux-3.7-vs2.3.5.1.1/kernel/vserver/network.c
26100 --- linux-3.7-vs2.3.5.1/kernel/vserver/network.c        2012-12-11 15:56:33.000000000 +0000
26101 +++ linux-3.7-vs2.3.5.1.1/kernel/vserver/network.c      2012-12-13 13:48:35.000000000 +0000
26102 @@ -804,6 +818,31 @@ int do_add_v6_addr(struct nx_info *nxi,
26103         return 0;
26104  }
26105  
26106 +int do_remove_v6_addr(struct nx_info *nxi,
26107 +       struct in6_addr *ip, struct in6_addr *mask, 
26108 +       uint32_t prefix, uint16_t type, uint16_t flags)
26109 +{
26110 +       struct nx_addr_v6 *nxa = &nxi->v6;
26111 +       struct nx_addr_v6 *old = NULL;
26112 +       int ret = 0;
26113 +
26114 +       spin_lock(&nxi->addr_lock);
26115 +       switch (type) {
26116 +/*     case NXA_TYPE_ADDR:
26117 +               break;          */
26118 +
26119 +       case NXA_TYPE_ANY:
26120 +               old = xchg(&nxa->next, NULL);
26121 +               memset(nxa, 0, sizeof(*nxa));
26122 +               break;
26123 +
26124 +       default:
26125 +               ret = -EINVAL;
26126 +       }
26127 +       spin_unlock(&nxi->addr_lock);
26128 +       __dealloc_nx_addr_v6_all(old);
26129 +       return ret;
26130 +}
26131  
26132  int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
26133  {
26134 @@ -831,10 +873,8 @@ int vc_net_remove_ipv6(struct nx_info *n
26135  
26136         switch (vc_data.type) {
26137         case NXA_TYPE_ANY:
26138 -               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
26139 -               memset(&nxi->v6, 0, sizeof(nxi->v6));
26140 +               do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
26141                 break;
26142 -
26143         default:
26144                 return -EINVAL;
26145         }
26146 --- linux-3.7/net/ipv6/netfilter/ip6t_MASQUERADE.c~     2012-12-11 04:30:57.000000000 +0100
26147 +++ linux-3.7/net/ipv6/netfilter/ip6t_MASQUERADE.c      2012-12-13 21:09:30.741602424 +0100
26148 @@ -34,7 +34,7 @@
26149                             ctinfo == IP_CT_RELATED_REPLY));
26150  
26151         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
26152 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
26153 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
26154                 return NF_DROP;
26155  
26156         nfct_nat(ct)->masq_index = par->out->ifindex;
This page took 2.124271 seconds and 3 git commands to generate.