]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 3.1.1
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.1/.config.inet linux-3.1-vs2.3.1-rc2/.config.inet
2 --- linux-3.1/.config.inet      1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.1-vs2.3.1-rc2/.config.inet  2011-10-24 18:53:33.000000000 +0200
4 @@ -0,0 +1,1620 @@
5 +#
6 +# Automatically generated make config: don't edit
7 +# Linux/x86_64 3.0.0-rc2-vs2.3.x Kernel Configuration
8 +#
9 +CONFIG_64BIT=y
10 +# CONFIG_X86_32 is not set
11 +CONFIG_X86_64=y
12 +CONFIG_X86=y
13 +CONFIG_INSTRUCTION_DECODER=y
14 +CONFIG_OUTPUT_FORMAT="elf64-x86-64"
15 +CONFIG_ARCH_DEFCONFIG="arch/x86/configs/x86_64_defconfig"
16 +CONFIG_GENERIC_CMOS_UPDATE=y
17 +CONFIG_CLOCKSOURCE_WATCHDOG=y
18 +CONFIG_GENERIC_CLOCKEVENTS=y
19 +CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
20 +CONFIG_LOCKDEP_SUPPORT=y
21 +CONFIG_STACKTRACE_SUPPORT=y
22 +CONFIG_HAVE_LATENCYTOP_SUPPORT=y
23 +CONFIG_MMU=y
24 +CONFIG_ZONE_DMA=y
25 +CONFIG_NEED_DMA_MAP_STATE=y
26 +CONFIG_NEED_SG_DMA_LENGTH=y
27 +CONFIG_GENERIC_ISA_DMA=y
28 +CONFIG_GENERIC_IOMAP=y
29 +CONFIG_GENERIC_BUG=y
30 +CONFIG_GENERIC_BUG_RELATIVE_POINTERS=y
31 +CONFIG_GENERIC_HWEIGHT=y
32 +CONFIG_ARCH_MAY_HAVE_PC_FDC=y
33 +# CONFIG_RWSEM_GENERIC_SPINLOCK is not set
34 +CONFIG_RWSEM_XCHGADD_ALGORITHM=y
35 +CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
36 +CONFIG_GENERIC_CALIBRATE_DELAY=y
37 +CONFIG_GENERIC_TIME_VSYSCALL=y
38 +CONFIG_ARCH_HAS_CPU_RELAX=y
39 +CONFIG_ARCH_HAS_DEFAULT_IDLE=y
40 +CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
41 +CONFIG_HAVE_SETUP_PER_CPU_AREA=y
42 +CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK=y
43 +CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK=y
44 +CONFIG_HAVE_CPUMASK_OF_CPU_MAP=y
45 +CONFIG_ARCH_HIBERNATION_POSSIBLE=y
46 +CONFIG_ARCH_SUSPEND_POSSIBLE=y
47 +CONFIG_ZONE_DMA32=y
48 +CONFIG_ARCH_POPULATES_NODE_MAP=y
49 +CONFIG_AUDIT_ARCH=y
50 +CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING=y
51 +CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
52 +CONFIG_X86_64_SMP=y
53 +CONFIG_X86_HT=y
54 +CONFIG_ARCH_HWEIGHT_CFLAGS="-fcall-saved-rdi -fcall-saved-rsi -fcall-saved-rdx -fcall-saved-rcx -fcall-saved-r8 -fcall-saved-r9 -fcall-saved-r10 -fcall-saved-r11"
55 +# CONFIG_KTIME_SCALAR is not set
56 +CONFIG_ARCH_CPU_PROBE_RELEASE=y
57 +CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
58 +CONFIG_CONSTRUCTORS=y
59 +CONFIG_HAVE_IRQ_WORK=y
60 +CONFIG_IRQ_WORK=y
61 +
62 +#
63 +# General setup
64 +#
65 +CONFIG_EXPERIMENTAL=y
66 +CONFIG_INIT_ENV_ARG_LIMIT=32
67 +CONFIG_CROSS_COMPILE=""
68 +CONFIG_LOCALVERSION=""
69 +# CONFIG_LOCALVERSION_AUTO is not set
70 +CONFIG_HAVE_KERNEL_GZIP=y
71 +CONFIG_HAVE_KERNEL_BZIP2=y
72 +CONFIG_HAVE_KERNEL_LZMA=y
73 +CONFIG_HAVE_KERNEL_XZ=y
74 +CONFIG_HAVE_KERNEL_LZO=y
75 +# CONFIG_KERNEL_GZIP is not set
76 +# CONFIG_KERNEL_BZIP2 is not set
77 +CONFIG_KERNEL_LZMA=y
78 +# CONFIG_KERNEL_XZ is not set
79 +# CONFIG_KERNEL_LZO is not set
80 +CONFIG_SWAP=y
81 +CONFIG_SYSVIPC=y
82 +CONFIG_SYSVIPC_SYSCTL=y
83 +CONFIG_POSIX_MQUEUE=y
84 +CONFIG_POSIX_MQUEUE_SYSCTL=y
85 +CONFIG_BSD_PROCESS_ACCT=y
86 +# CONFIG_BSD_PROCESS_ACCT_V3 is not set
87 +# CONFIG_FHANDLE is not set
88 +CONFIG_TASKSTATS=y
89 +CONFIG_TASK_DELAY_ACCT=y
90 +CONFIG_TASK_XACCT=y
91 +CONFIG_TASK_IO_ACCOUNTING=y
92 +# CONFIG_AUDIT is not set
93 +CONFIG_HAVE_GENERIC_HARDIRQS=y
94 +
95 +#
96 +# IRQ subsystem
97 +#
98 +CONFIG_GENERIC_HARDIRQS=y
99 +CONFIG_HAVE_SPARSE_IRQ=y
100 +CONFIG_GENERIC_IRQ_PROBE=y
101 +CONFIG_GENERIC_IRQ_SHOW=y
102 +CONFIG_GENERIC_PENDING_IRQ=y
103 +CONFIG_IRQ_FORCED_THREADING=y
104 +# CONFIG_SPARSE_IRQ is not set
105 +
106 +#
107 +# RCU Subsystem
108 +#
109 +CONFIG_TREE_RCU=y
110 +# CONFIG_PREEMPT_RCU is not set
111 +# CONFIG_RCU_TRACE is not set
112 +CONFIG_RCU_FANOUT=64
113 +# CONFIG_RCU_FANOUT_EXACT is not set
114 +# CONFIG_TREE_RCU_TRACE is not set
115 +CONFIG_IKCONFIG=y
116 +CONFIG_IKCONFIG_PROC=y
117 +CONFIG_LOG_BUF_SHIFT=18
118 +CONFIG_HAVE_UNSTABLE_SCHED_CLOCK=y
119 +CONFIG_CGROUPS=y
120 +# CONFIG_CGROUP_DEBUG is not set
121 +# CONFIG_CGROUP_FREEZER is not set
122 +# CONFIG_CGROUP_DEVICE is not set
123 +# CONFIG_CPUSETS is not set
124 +# CONFIG_CGROUP_CPUACCT is not set
125 +CONFIG_RESOURCE_COUNTERS=y
126 +CONFIG_CGROUP_MEM_RES_CTLR=y
127 +CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y
128 +CONFIG_CGROUP_MEM_RES_CTLR_SWAP_ENABLED=y
129 +# CONFIG_CGROUP_PERF is not set
130 +CONFIG_CGROUP_SCHED=y
131 +CONFIG_FAIR_GROUP_SCHED=y
132 +# CONFIG_RT_GROUP_SCHED is not set
133 +# CONFIG_BLK_CGROUP is not set
134 +CONFIG_NAMESPACES=y
135 +CONFIG_UTS_NS=y
136 +CONFIG_IPC_NS=y
137 +CONFIG_USER_NS=y
138 +# CONFIG_PID_NS is not set
139 +# CONFIG_NET_NS is not set
140 +CONFIG_SCHED_AUTOGROUP=y
141 +CONFIG_MM_OWNER=y
142 +# CONFIG_SYSFS_DEPRECATED is not set
143 +# CONFIG_RELAY is not set
144 +# CONFIG_BLK_DEV_INITRD is not set
145 +CONFIG_CC_OPTIMIZE_FOR_SIZE=y
146 +CONFIG_SYSCTL=y
147 +CONFIG_ANON_INODES=y
148 +CONFIG_EXPERT=y
149 +CONFIG_UID16=y
150 +CONFIG_SYSCTL_SYSCALL=y
151 +CONFIG_KALLSYMS=y
152 +CONFIG_KALLSYMS_ALL=y
153 +CONFIG_HOTPLUG=y
154 +CONFIG_PRINTK=y
155 +CONFIG_BUG=y
156 +CONFIG_ELF_CORE=y
157 +CONFIG_PCSPKR_PLATFORM=y
158 +CONFIG_BASE_FULL=y
159 +CONFIG_FUTEX=y
160 +CONFIG_EPOLL=y
161 +CONFIG_SIGNALFD=y
162 +CONFIG_TIMERFD=y
163 +CONFIG_EVENTFD=y
164 +CONFIG_SHMEM=y
165 +CONFIG_AIO=y
166 +# CONFIG_EMBEDDED is not set
167 +CONFIG_HAVE_PERF_EVENTS=y
168 +
169 +#
170 +# Kernel Performance Events And Counters
171 +#
172 +CONFIG_PERF_EVENTS=y
173 +# CONFIG_PERF_COUNTERS is not set
174 +# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
175 +CONFIG_VM_EVENT_COUNTERS=y
176 +CONFIG_PCI_QUIRKS=y
177 +CONFIG_SLUB_DEBUG=y
178 +# CONFIG_COMPAT_BRK is not set
179 +# CONFIG_SLAB is not set
180 +CONFIG_SLUB=y
181 +# CONFIG_SLOB is not set
182 +# CONFIG_PROFILING is not set
183 +CONFIG_HAVE_OPROFILE=y
184 +# CONFIG_JUMP_LABEL is not set
185 +CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y
186 +CONFIG_HAVE_IOREMAP_PROT=y
187 +CONFIG_HAVE_KPROBES=y
188 +CONFIG_HAVE_KRETPROBES=y
189 +CONFIG_HAVE_OPTPROBES=y
190 +CONFIG_HAVE_ARCH_TRACEHOOK=y
191 +CONFIG_HAVE_DMA_ATTRS=y
192 +CONFIG_USE_GENERIC_SMP_HELPERS=y
193 +CONFIG_HAVE_REGS_AND_STACK_ACCESS_API=y
194 +CONFIG_HAVE_DMA_API_DEBUG=y
195 +CONFIG_HAVE_HW_BREAKPOINT=y
196 +CONFIG_HAVE_MIXED_BREAKPOINTS_REGS=y
197 +CONFIG_HAVE_USER_RETURN_NOTIFIER=y
198 +CONFIG_HAVE_PERF_EVENTS_NMI=y
199 +CONFIG_HAVE_ARCH_JUMP_LABEL=y
200 +
201 +#
202 +# GCOV-based kernel profiling
203 +#
204 +# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
205 +CONFIG_SLABINFO=y
206 +CONFIG_RT_MUTEXES=y
207 +CONFIG_BASE_SMALL=0
208 +# CONFIG_MODULES is not set
209 +CONFIG_STOP_MACHINE=y
210 +CONFIG_BLOCK=y
211 +# CONFIG_BLK_DEV_BSG is not set
212 +# CONFIG_BLK_DEV_INTEGRITY is not set
213 +CONFIG_BLOCK_COMPAT=y
214 +
215 +#
216 +# IO Schedulers
217 +#
218 +CONFIG_IOSCHED_NOOP=y
219 +# CONFIG_IOSCHED_DEADLINE is not set
220 +CONFIG_IOSCHED_CFQ=y
221 +CONFIG_DEFAULT_CFQ=y
222 +# CONFIG_DEFAULT_NOOP is not set
223 +CONFIG_DEFAULT_IOSCHED="cfq"
224 +# CONFIG_INLINE_SPIN_TRYLOCK is not set
225 +# CONFIG_INLINE_SPIN_TRYLOCK_BH is not set
226 +# CONFIG_INLINE_SPIN_LOCK is not set
227 +# CONFIG_INLINE_SPIN_LOCK_BH is not set
228 +# CONFIG_INLINE_SPIN_LOCK_IRQ is not set
229 +# CONFIG_INLINE_SPIN_LOCK_IRQSAVE is not set
230 +CONFIG_INLINE_SPIN_UNLOCK=y
231 +# CONFIG_INLINE_SPIN_UNLOCK_BH is not set
232 +CONFIG_INLINE_SPIN_UNLOCK_IRQ=y
233 +# CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE is not set
234 +# CONFIG_INLINE_READ_TRYLOCK is not set
235 +# CONFIG_INLINE_READ_LOCK is not set
236 +# CONFIG_INLINE_READ_LOCK_BH is not set
237 +# CONFIG_INLINE_READ_LOCK_IRQ is not set
238 +# CONFIG_INLINE_READ_LOCK_IRQSAVE is not set
239 +CONFIG_INLINE_READ_UNLOCK=y
240 +# CONFIG_INLINE_READ_UNLOCK_BH is not set
241 +CONFIG_INLINE_READ_UNLOCK_IRQ=y
242 +# CONFIG_INLINE_READ_UNLOCK_IRQRESTORE is not set
243 +# CONFIG_INLINE_WRITE_TRYLOCK is not set
244 +# CONFIG_INLINE_WRITE_LOCK is not set
245 +# CONFIG_INLINE_WRITE_LOCK_BH is not set
246 +# CONFIG_INLINE_WRITE_LOCK_IRQ is not set
247 +# CONFIG_INLINE_WRITE_LOCK_IRQSAVE is not set
248 +CONFIG_INLINE_WRITE_UNLOCK=y
249 +# CONFIG_INLINE_WRITE_UNLOCK_BH is not set
250 +CONFIG_INLINE_WRITE_UNLOCK_IRQ=y
251 +# CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE is not set
252 +CONFIG_MUTEX_SPIN_ON_OWNER=y
253 +CONFIG_FREEZER=y
254 +
255 +#
256 +# Processor type and features
257 +#
258 +CONFIG_TICK_ONESHOT=y
259 +# CONFIG_NO_HZ is not set
260 +CONFIG_HIGH_RES_TIMERS=y
261 +CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
262 +CONFIG_SMP=y
263 +CONFIG_X86_MPPARSE=y
264 +# CONFIG_X86_EXTENDED_PLATFORM is not set
265 +CONFIG_X86_SUPPORTS_MEMORY_FAILURE=y
266 +CONFIG_SCHED_OMIT_FRAME_POINTER=y
267 +# CONFIG_PARAVIRT_GUEST is not set
268 +CONFIG_NO_BOOTMEM=y
269 +# CONFIG_MEMTEST is not set
270 +# CONFIG_MK8 is not set
271 +# CONFIG_MPSC is not set
272 +CONFIG_MCORE2=y
273 +# CONFIG_MATOM is not set
274 +# CONFIG_GENERIC_CPU is not set
275 +CONFIG_X86_INTERNODE_CACHE_SHIFT=6
276 +CONFIG_X86_CMPXCHG=y
277 +CONFIG_CMPXCHG_LOCAL=y
278 +CONFIG_X86_L1_CACHE_SHIFT=6
279 +CONFIG_X86_XADD=y
280 +CONFIG_X86_WP_WORKS_OK=y
281 +CONFIG_X86_INTEL_USERCOPY=y
282 +CONFIG_X86_USE_PPRO_CHECKSUM=y
283 +CONFIG_X86_P6_NOP=y
284 +CONFIG_X86_TSC=y
285 +CONFIG_X86_CMPXCHG64=y
286 +CONFIG_X86_CMOV=y
287 +CONFIG_X86_MINIMUM_CPU_FAMILY=64
288 +CONFIG_X86_DEBUGCTLMSR=y
289 +# CONFIG_PROCESSOR_SELECT is not set
290 +CONFIG_CPU_SUP_INTEL=y
291 +CONFIG_CPU_SUP_AMD=y
292 +CONFIG_CPU_SUP_CENTAUR=y
293 +CONFIG_HPET_TIMER=y
294 +CONFIG_HPET_EMULATE_RTC=y
295 +CONFIG_DMI=y
296 +CONFIG_GART_IOMMU=y
297 +# CONFIG_CALGARY_IOMMU is not set
298 +# CONFIG_AMD_IOMMU is not set
299 +CONFIG_SWIOTLB=y
300 +CONFIG_IOMMU_HELPER=y
301 +# CONFIG_IOMMU_API is not set
302 +# CONFIG_MAXSMP is not set
303 +CONFIG_NR_CPUS=32
304 +CONFIG_SCHED_SMT=y
305 +CONFIG_SCHED_MC=y
306 +# CONFIG_IRQ_TIME_ACCOUNTING is not set
307 +CONFIG_PREEMPT_NONE=y
308 +# CONFIG_PREEMPT_VOLUNTARY is not set
309 +# CONFIG_PREEMPT is not set
310 +CONFIG_X86_LOCAL_APIC=y
311 +CONFIG_X86_IO_APIC=y
312 +# CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS is not set
313 +CONFIG_X86_MCE=y
314 +CONFIG_X86_MCE_INTEL=y
315 +CONFIG_X86_MCE_AMD=y
316 +CONFIG_X86_MCE_THRESHOLD=y
317 +# CONFIG_X86_MCE_INJECT is not set
318 +CONFIG_X86_THERMAL_VECTOR=y
319 +# CONFIG_I8K is not set
320 +# CONFIG_MICROCODE is not set
321 +CONFIG_X86_MSR=y
322 +CONFIG_X86_CPUID=y
323 +CONFIG_ARCH_PHYS_ADDR_T_64BIT=y
324 +CONFIG_ARCH_DMA_ADDR_T_64BIT=y
325 +CONFIG_DIRECT_GBPAGES=y
326 +# CONFIG_NUMA is not set
327 +CONFIG_ARCH_SPARSEMEM_ENABLE=y
328 +CONFIG_ARCH_SPARSEMEM_DEFAULT=y
329 +CONFIG_ARCH_SELECT_MEMORY_MODEL=y
330 +CONFIG_ILLEGAL_POINTER_VALUE=0xdead000000000000
331 +CONFIG_SELECT_MEMORY_MODEL=y
332 +CONFIG_SPARSEMEM_MANUAL=y
333 +CONFIG_SPARSEMEM=y
334 +CONFIG_HAVE_MEMORY_PRESENT=y
335 +CONFIG_SPARSEMEM_EXTREME=y
336 +CONFIG_SPARSEMEM_VMEMMAP_ENABLE=y
337 +CONFIG_SPARSEMEM_ALLOC_MEM_MAP_TOGETHER=y
338 +CONFIG_SPARSEMEM_VMEMMAP=y
339 +CONFIG_HAVE_MEMBLOCK=y
340 +# CONFIG_MEMORY_HOTPLUG is not set
341 +CONFIG_PAGEFLAGS_EXTENDED=y
342 +CONFIG_SPLIT_PTLOCK_CPUS=4
343 +CONFIG_COMPACTION=y
344 +CONFIG_MIGRATION=y
345 +CONFIG_PHYS_ADDR_T_64BIT=y
346 +CONFIG_ZONE_DMA_FLAG=1
347 +CONFIG_BOUNCE=y
348 +CONFIG_VIRT_TO_BUS=y
349 +# CONFIG_KSM is not set
350 +CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
351 +CONFIG_ARCH_SUPPORTS_MEMORY_FAILURE=y
352 +# CONFIG_MEMORY_FAILURE is not set
353 +CONFIG_TRANSPARENT_HUGEPAGE=y
354 +CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y
355 +# CONFIG_TRANSPARENT_HUGEPAGE_MADVISE is not set
356 +CONFIG_CLEANCACHE=y
357 +# CONFIG_X86_CHECK_BIOS_CORRUPTION is not set
358 +CONFIG_X86_RESERVE_LOW=4
359 +CONFIG_MTRR=y
360 +CONFIG_MTRR_SANITIZER=y
361 +CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT=0
362 +CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT=1
363 +CONFIG_X86_PAT=y
364 +CONFIG_ARCH_USES_PG_UNCACHED=y
365 +# CONFIG_EFI is not set
366 +CONFIG_SECCOMP=y
367 +# CONFIG_CC_STACKPROTECTOR is not set
368 +CONFIG_HZ_100=y
369 +# CONFIG_HZ_250 is not set
370 +# CONFIG_HZ_300 is not set
371 +# CONFIG_HZ_1000 is not set
372 +CONFIG_HZ=100
373 +CONFIG_SCHED_HRTICK=y
374 +# CONFIG_KEXEC is not set
375 +# CONFIG_CRASH_DUMP is not set
376 +CONFIG_PHYSICAL_START=0x1000000
377 +# CONFIG_RELOCATABLE is not set
378 +CONFIG_PHYSICAL_ALIGN=0x1000000
379 +CONFIG_HOTPLUG_CPU=y
380 +# CONFIG_COMPAT_VDSO is not set
381 +# CONFIG_CMDLINE_BOOL is not set
382 +CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
383 +
384 +#
385 +# Power management and ACPI options
386 +#
387 +CONFIG_SUSPEND=y
388 +CONFIG_SUSPEND_FREEZER=y
389 +# CONFIG_HIBERNATION is not set
390 +CONFIG_PM_SLEEP=y
391 +CONFIG_PM_SLEEP_SMP=y
392 +# CONFIG_PM_RUNTIME is not set
393 +CONFIG_PM=y
394 +# CONFIG_PM_DEBUG is not set
395 +CONFIG_ACPI=y
396 +CONFIG_ACPI_SLEEP=y
397 +# CONFIG_ACPI_PROCFS is not set
398 +# CONFIG_ACPI_PROCFS_POWER is not set
399 +# CONFIG_ACPI_EC_DEBUGFS is not set
400 +CONFIG_ACPI_PROC_EVENT=y
401 +CONFIG_ACPI_AC=y
402 +CONFIG_ACPI_BATTERY=y
403 +CONFIG_ACPI_BUTTON=y
404 +CONFIG_ACPI_FAN=y
405 +# CONFIG_ACPI_DOCK is not set
406 +CONFIG_ACPI_PROCESSOR=y
407 +CONFIG_ACPI_HOTPLUG_CPU=y
408 +# CONFIG_ACPI_PROCESSOR_AGGREGATOR is not set
409 +CONFIG_ACPI_THERMAL=y
410 +# CONFIG_ACPI_CUSTOM_DSDT is not set
411 +CONFIG_ACPI_BLACKLIST_YEAR=0
412 +# CONFIG_ACPI_DEBUG is not set
413 +# CONFIG_ACPI_PCI_SLOT is not set
414 +CONFIG_X86_PM_TIMER=y
415 +CONFIG_ACPI_CONTAINER=y
416 +# CONFIG_ACPI_SBS is not set
417 +# CONFIG_ACPI_HED is not set
418 +# CONFIG_ACPI_APEI is not set
419 +# CONFIG_SFI is not set
420 +
421 +#
422 +# CPU Frequency scaling
423 +#
424 +# CONFIG_CPU_FREQ is not set
425 +CONFIG_CPU_IDLE=y
426 +CONFIG_CPU_IDLE_GOV_LADDER=y
427 +# CONFIG_INTEL_IDLE is not set
428 +
429 +#
430 +# Memory power savings
431 +#
432 +# CONFIG_I7300_IDLE is not set
433 +
434 +#
435 +# Bus options (PCI etc.)
436 +#
437 +CONFIG_PCI=y
438 +CONFIG_PCI_DIRECT=y
439 +# CONFIG_PCI_MMCONFIG is not set
440 +CONFIG_PCI_DOMAINS=y
441 +# CONFIG_PCI_CNB20LE_QUIRK is not set
442 +CONFIG_PCIEPORTBUS=y
443 +# CONFIG_PCIEAER is not set
444 +CONFIG_PCIEASPM=y
445 +# CONFIG_PCIEASPM_DEBUG is not set
446 +CONFIG_ARCH_SUPPORTS_MSI=y
447 +# CONFIG_PCI_MSI is not set
448 +# CONFIG_PCI_DEBUG is not set
449 +# CONFIG_PCI_STUB is not set
450 +CONFIG_HT_IRQ=y
451 +# CONFIG_PCI_IOV is not set
452 +CONFIG_PCI_IOAPIC=y
453 +CONFIG_PCI_LABEL=y
454 +CONFIG_ISA_DMA_API=y
455 +CONFIG_AMD_NB=y
456 +# CONFIG_PCCARD is not set
457 +# CONFIG_HOTPLUG_PCI is not set
458 +# CONFIG_RAPIDIO is not set
459 +
460 +#
461 +# Executable file formats / Emulations
462 +#
463 +CONFIG_BINFMT_ELF=y
464 +CONFIG_COMPAT_BINFMT_ELF=y
465 +# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
466 +# CONFIG_HAVE_AOUT is not set
467 +# CONFIG_BINFMT_MISC is not set
468 +CONFIG_IA32_EMULATION=y
469 +# CONFIG_IA32_AOUT is not set
470 +CONFIG_COMPAT=y
471 +CONFIG_COMPAT_FOR_U64_ALIGNMENT=y
472 +CONFIG_SYSVIPC_COMPAT=y
473 +CONFIG_HAVE_TEXT_POKE_SMP=y
474 +CONFIG_NET=y
475 +
476 +#
477 +# Networking options
478 +#
479 +CONFIG_PACKET=y
480 +CONFIG_UNIX=y
481 +CONFIG_XFRM=y
482 +CONFIG_XFRM_USER=y
483 +# CONFIG_XFRM_SUB_POLICY is not set
484 +# CONFIG_XFRM_MIGRATE is not set
485 +# CONFIG_XFRM_STATISTICS is not set
486 +CONFIG_XFRM_IPCOMP=y
487 +# CONFIG_NET_KEY is not set
488 +CONFIG_IP_MULTICAST=y
489 +# CONFIG_IP_ADVANCED_ROUTER is not set
490 +# CONFIG_IP_PNP is not set
491 +# CONFIG_NET_IPIP is not set
492 +# CONFIG_NET_IPGRE_DEMUX is not set
493 +# CONFIG_IP_MROUTE is not set
494 +# CONFIG_ARPD is not set
495 +CONFIG_SYN_COOKIES=y
496 +# CONFIG_INET_AH is not set
497 +# CONFIG_INET_ESP is not set
498 +# CONFIG_INET_IPCOMP is not set
499 +# CONFIG_INET_XFRM_TUNNEL is not set
500 +CONFIG_INET_TUNNEL=y
501 +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
502 +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
503 +# CONFIG_INET_XFRM_MODE_BEET is not set
504 +CONFIG_INET_LRO=y
505 +CONFIG_INET_DIAG=y
506 +CONFIG_INET_TCP_DIAG=y
507 +# CONFIG_TCP_CONG_ADVANCED is not set
508 +CONFIG_TCP_CONG_CUBIC=y
509 +CONFIG_DEFAULT_TCP_CONG="cubic"
510 +# CONFIG_TCP_MD5SIG is not set
511 +CONFIG_IPV6=y
512 +# CONFIG_IPV6_PRIVACY is not set
513 +# CONFIG_IPV6_ROUTER_PREF is not set
514 +# CONFIG_IPV6_OPTIMISTIC_DAD is not set
515 +CONFIG_INET6_AH=y
516 +CONFIG_INET6_ESP=y
517 +CONFIG_INET6_IPCOMP=y
518 +# CONFIG_IPV6_MIP6 is not set
519 +CONFIG_INET6_XFRM_TUNNEL=y
520 +CONFIG_INET6_TUNNEL=y
521 +CONFIG_INET6_XFRM_MODE_TRANSPORT=y
522 +CONFIG_INET6_XFRM_MODE_TUNNEL=y
523 +CONFIG_INET6_XFRM_MODE_BEET=y
524 +# CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set
525 +CONFIG_IPV6_SIT=y
526 +# CONFIG_IPV6_SIT_6RD is not set
527 +CONFIG_IPV6_NDISC_NODETYPE=y
528 +# CONFIG_IPV6_TUNNEL is not set
529 +# CONFIG_IPV6_MULTIPLE_TABLES is not set
530 +# CONFIG_IPV6_MROUTE is not set
531 +# CONFIG_NETWORK_SECMARK is not set
532 +# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
533 +CONFIG_NETFILTER=y
534 +# CONFIG_NETFILTER_DEBUG is not set
535 +# CONFIG_NETFILTER_ADVANCED is not set
536 +
537 +#
538 +# Core Netfilter Configuration
539 +#
540 +CONFIG_NETFILTER_NETLINK=y
541 +CONFIG_NETFILTER_NETLINK_LOG=y
542 +CONFIG_NF_CONNTRACK=y
543 +CONFIG_NF_CONNTRACK_FTP=y
544 +CONFIG_NF_CONNTRACK_IRC=y
545 +CONFIG_NF_CONNTRACK_SIP=y
546 +CONFIG_NF_CT_NETLINK=y
547 +CONFIG_NETFILTER_XTABLES=y
548 +
549 +#
550 +# Xtables combined modules
551 +#
552 +CONFIG_NETFILTER_XT_MARK=y
553 +
554 +#
555 +# Xtables targets
556 +#
557 +CONFIG_NETFILTER_XT_TARGET_NFLOG=y
558 +CONFIG_NETFILTER_XT_TARGET_TCPMSS=y
559 +
560 +#
561 +# Xtables matches
562 +#
563 +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
564 +CONFIG_NETFILTER_XT_MATCH_POLICY=y
565 +CONFIG_NETFILTER_XT_MATCH_STATE=y
566 +# CONFIG_IP_SET is not set
567 +CONFIG_IP_VS=y
568 +CONFIG_IP_VS_IPV6=y
569 +# CONFIG_IP_VS_DEBUG is not set
570 +CONFIG_IP_VS_TAB_BITS=12
571 +
572 +#
573 +# IPVS transport protocol load balancing support
574 +#
575 +# CONFIG_IP_VS_PROTO_TCP is not set
576 +# CONFIG_IP_VS_PROTO_UDP is not set
577 +# CONFIG_IP_VS_PROTO_AH_ESP is not set
578 +# CONFIG_IP_VS_PROTO_ESP is not set
579 +# CONFIG_IP_VS_PROTO_AH is not set
580 +# CONFIG_IP_VS_PROTO_SCTP is not set
581 +
582 +#
583 +# IPVS scheduler
584 +#
585 +# CONFIG_IP_VS_RR is not set
586 +# CONFIG_IP_VS_WRR is not set
587 +# CONFIG_IP_VS_LC is not set
588 +# CONFIG_IP_VS_WLC is not set
589 +# CONFIG_IP_VS_LBLC is not set
590 +# CONFIG_IP_VS_LBLCR is not set
591 +# CONFIG_IP_VS_DH is not set
592 +# CONFIG_IP_VS_SH is not set
593 +# CONFIG_IP_VS_SED is not set
594 +# CONFIG_IP_VS_NQ is not set
595 +
596 +#
597 +# IPVS application helper
598 +#
599 +# CONFIG_IP_VS_NFCT is not set
600 +
601 +#
602 +# IP: Netfilter Configuration
603 +#
604 +CONFIG_NF_DEFRAG_IPV4=y
605 +CONFIG_NF_CONNTRACK_IPV4=y
606 +# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set
607 +CONFIG_IP_NF_IPTABLES=y
608 +CONFIG_IP_NF_FILTER=y
609 +CONFIG_IP_NF_TARGET_REJECT=y
610 +CONFIG_IP_NF_TARGET_LOG=y
611 +CONFIG_IP_NF_TARGET_ULOG=y
612 +CONFIG_NF_NAT=y
613 +CONFIG_NF_NAT_NEEDED=y
614 +CONFIG_IP_NF_TARGET_MASQUERADE=y
615 +CONFIG_NF_NAT_FTP=y
616 +CONFIG_NF_NAT_IRC=y
617 +# CONFIG_NF_NAT_TFTP is not set
618 +# CONFIG_NF_NAT_AMANDA is not set
619 +# CONFIG_NF_NAT_PPTP is not set
620 +# CONFIG_NF_NAT_H323 is not set
621 +CONFIG_NF_NAT_SIP=y
622 +CONFIG_IP_NF_MANGLE=y
623 +
624 +#
625 +# IPv6: Netfilter Configuration
626 +#
627 +# CONFIG_NF_DEFRAG_IPV6 is not set
628 +# CONFIG_NF_CONNTRACK_IPV6 is not set
629 +CONFIG_IP6_NF_IPTABLES=y
630 +CONFIG_IP6_NF_MATCH_IPV6HEADER=y
631 +CONFIG_IP6_NF_TARGET_LOG=y
632 +CONFIG_IP6_NF_FILTER=y
633 +CONFIG_IP6_NF_TARGET_REJECT=y
634 +CONFIG_IP6_NF_MANGLE=y
635 +# CONFIG_IP_DCCP is not set
636 +CONFIG_IP_SCTP=y
637 +# CONFIG_SCTP_DBG_MSG is not set
638 +# CONFIG_SCTP_DBG_OBJCNT is not set
639 +# CONFIG_SCTP_HMAC_NONE is not set
640 +# CONFIG_SCTP_HMAC_SHA1 is not set
641 +CONFIG_SCTP_HMAC_MD5=y
642 +# CONFIG_RDS is not set
643 +# CONFIG_TIPC is not set
644 +# CONFIG_ATM is not set
645 +# CONFIG_L2TP is not set
646 +# CONFIG_BRIDGE is not set
647 +# CONFIG_NET_DSA is not set
648 +# CONFIG_VLAN_8021Q is not set
649 +# CONFIG_DECNET is not set
650 +# CONFIG_LLC2 is not set
651 +# CONFIG_IPX is not set
652 +# CONFIG_ATALK is not set
653 +CONFIG_X25=y
654 +# CONFIG_LAPB is not set
655 +# CONFIG_ECONET is not set
656 +# CONFIG_WAN_ROUTER is not set
657 +# CONFIG_PHONET is not set
658 +# CONFIG_IEEE802154 is not set
659 +# CONFIG_NET_SCHED is not set
660 +# CONFIG_DCB is not set
661 +# CONFIG_BATMAN_ADV is not set
662 +CONFIG_RPS=y
663 +CONFIG_RFS_ACCEL=y
664 +CONFIG_XPS=y
665 +CONFIG_HAVE_BPF_JIT=y
666 +
667 +#
668 +# Network testing
669 +#
670 +# CONFIG_NET_PKTGEN is not set
671 +# CONFIG_HAMRADIO is not set
672 +# CONFIG_CAN is not set
673 +# CONFIG_IRDA is not set
674 +# CONFIG_BT is not set
675 +# CONFIG_AF_RXRPC is not set
676 +# CONFIG_WIRELESS is not set
677 +# CONFIG_WIMAX is not set
678 +# CONFIG_RFKILL is not set
679 +# CONFIG_NET_9P is not set
680 +# CONFIG_CAIF is not set
681 +# CONFIG_CEPH_LIB is not set
682 +
683 +#
684 +# Device Drivers
685 +#
686 +
687 +#
688 +# Generic Driver Options
689 +#
690 +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
691 +CONFIG_DEVTMPFS=y
692 +# CONFIG_DEVTMPFS_MOUNT is not set
693 +CONFIG_STANDALONE=y
694 +CONFIG_PREVENT_FIRMWARE_BUILD=y
695 +CONFIG_FW_LOADER=y
696 +CONFIG_FIRMWARE_IN_KERNEL=y
697 +CONFIG_EXTRA_FIRMWARE=""
698 +# CONFIG_DEBUG_DRIVER is not set
699 +# CONFIG_DEBUG_DEVRES is not set
700 +# CONFIG_SYS_HYPERVISOR is not set
701 +# CONFIG_CONNECTOR is not set
702 +# CONFIG_MTD is not set
703 +# CONFIG_PARPORT is not set
704 +CONFIG_PNP=y
705 +CONFIG_PNP_DEBUG_MESSAGES=y
706 +
707 +#
708 +# Protocols
709 +#
710 +CONFIG_PNPACPI=y
711 +CONFIG_BLK_DEV=y
712 +# CONFIG_BLK_DEV_FD is not set
713 +# CONFIG_BLK_CPQ_DA is not set
714 +# CONFIG_BLK_CPQ_CISS_DA is not set
715 +# CONFIG_BLK_DEV_DAC960 is not set
716 +# CONFIG_BLK_DEV_UMEM is not set
717 +# CONFIG_BLK_DEV_COW_COMMON is not set
718 +CONFIG_BLK_DEV_LOOP=y
719 +# CONFIG_BLK_DEV_CRYPTOLOOP is not set
720 +
721 +#
722 +# DRBD disabled because PROC_FS, INET or CONNECTOR not selected
723 +#
724 +CONFIG_BLK_DEV_VROOT=y
725 +# CONFIG_BLK_DEV_NBD is not set
726 +# CONFIG_BLK_DEV_SX8 is not set
727 +# CONFIG_BLK_DEV_RAM is not set
728 +# CONFIG_CDROM_PKTCDVD is not set
729 +# CONFIG_ATA_OVER_ETH is not set
730 +# CONFIG_BLK_DEV_HD is not set
731 +# CONFIG_BLK_DEV_RBD is not set
732 +# CONFIG_SENSORS_LIS3LV02D is not set
733 +# CONFIG_MISC_DEVICES is not set
734 +CONFIG_HAVE_IDE=y
735 +CONFIG_IDE=y
736 +
737 +#
738 +# Please see Documentation/ide/ide.txt for help/info on IDE drives
739 +#
740 +CONFIG_IDE_XFER_MODE=y
741 +# CONFIG_BLK_DEV_IDE_SATA is not set
742 +CONFIG_IDE_GD=y
743 +CONFIG_IDE_GD_ATA=y
744 +# CONFIG_IDE_GD_ATAPI is not set
745 +# CONFIG_BLK_DEV_IDECD is not set
746 +# CONFIG_BLK_DEV_IDETAPE is not set
747 +# CONFIG_BLK_DEV_IDEACPI is not set
748 +CONFIG_IDE_TASK_IOCTL=y
749 +CONFIG_IDE_PROC_FS=y
750 +
751 +#
752 +# IDE chipset support/bugfixes
753 +#
754 +CONFIG_IDE_GENERIC=y
755 +CONFIG_BLK_DEV_PLATFORM=y
756 +# CONFIG_BLK_DEV_CMD640 is not set
757 +# CONFIG_BLK_DEV_IDEPNP is not set
758 +CONFIG_BLK_DEV_IDEDMA_SFF=y
759 +
760 +#
761 +# PCI IDE chipsets support
762 +#
763 +CONFIG_BLK_DEV_IDEPCI=y
764 +CONFIG_IDEPCI_PCIBUS_ORDER=y
765 +# CONFIG_BLK_DEV_OFFBOARD is not set
766 +CONFIG_BLK_DEV_GENERIC=y
767 +# CONFIG_BLK_DEV_OPTI621 is not set
768 +# CONFIG_BLK_DEV_RZ1000 is not set
769 +CONFIG_BLK_DEV_IDEDMA_PCI=y
770 +# CONFIG_BLK_DEV_AEC62XX is not set
771 +# CONFIG_BLK_DEV_ALI15X3 is not set
772 +# CONFIG_BLK_DEV_AMD74XX is not set
773 +# CONFIG_BLK_DEV_ATIIXP is not set
774 +# CONFIG_BLK_DEV_CMD64X is not set
775 +# CONFIG_BLK_DEV_TRIFLEX is not set
776 +# CONFIG_BLK_DEV_CS5520 is not set
777 +# CONFIG_BLK_DEV_CS5530 is not set
778 +# CONFIG_BLK_DEV_HPT366 is not set
779 +# CONFIG_BLK_DEV_JMICRON is not set
780 +# CONFIG_BLK_DEV_SC1200 is not set
781 +CONFIG_BLK_DEV_PIIX=y
782 +# CONFIG_BLK_DEV_IT8172 is not set
783 +# CONFIG_BLK_DEV_IT8213 is not set
784 +# CONFIG_BLK_DEV_IT821X is not set
785 +# CONFIG_BLK_DEV_NS87415 is not set
786 +# CONFIG_BLK_DEV_PDC202XX_OLD is not set
787 +# CONFIG_BLK_DEV_PDC202XX_NEW is not set
788 +# CONFIG_BLK_DEV_SVWKS is not set
789 +# CONFIG_BLK_DEV_SIIMAGE is not set
790 +# CONFIG_BLK_DEV_SIS5513 is not set
791 +# CONFIG_BLK_DEV_SLC90E66 is not set
792 +# CONFIG_BLK_DEV_TRM290 is not set
793 +# CONFIG_BLK_DEV_VIA82CXXX is not set
794 +# CONFIG_BLK_DEV_TC86C001 is not set
795 +CONFIG_BLK_DEV_IDEDMA=y
796 +
797 +#
798 +# SCSI device support
799 +#
800 +CONFIG_SCSI_MOD=y
801 +# CONFIG_RAID_ATTRS is not set
802 +CONFIG_SCSI=y
803 +CONFIG_SCSI_DMA=y
804 +# CONFIG_SCSI_TGT is not set
805 +# CONFIG_SCSI_NETLINK is not set
806 +# CONFIG_SCSI_PROC_FS is not set
807 +
808 +#
809 +# SCSI support type (disk, tape, CD-ROM)
810 +#
811 +CONFIG_BLK_DEV_SD=y
812 +# CONFIG_CHR_DEV_ST is not set
813 +# CONFIG_CHR_DEV_OSST is not set
814 +# CONFIG_BLK_DEV_SR is not set
815 +# CONFIG_CHR_DEV_SG is not set
816 +# CONFIG_CHR_DEV_SCH is not set
817 +# CONFIG_SCSI_MULTI_LUN is not set
818 +# CONFIG_SCSI_CONSTANTS is not set
819 +# CONFIG_SCSI_LOGGING is not set
820 +# CONFIG_SCSI_SCAN_ASYNC is not set
821 +
822 +#
823 +# SCSI Transports
824 +#
825 +# CONFIG_SCSI_SPI_ATTRS is not set
826 +# CONFIG_SCSI_FC_ATTRS is not set
827 +# CONFIG_SCSI_ISCSI_ATTRS is not set
828 +# CONFIG_SCSI_SAS_ATTRS is not set
829 +# CONFIG_SCSI_SAS_LIBSAS is not set
830 +# CONFIG_SCSI_SRP_ATTRS is not set
831 +# CONFIG_SCSI_LOWLEVEL is not set
832 +# CONFIG_SCSI_DH is not set
833 +# CONFIG_SCSI_OSD_INITIATOR is not set
834 +CONFIG_ATA=y
835 +# CONFIG_ATA_NONSTANDARD is not set
836 +CONFIG_ATA_VERBOSE_ERROR=y
837 +CONFIG_ATA_ACPI=y
838 +CONFIG_SATA_PMP=y
839 +
840 +#
841 +# Controllers with non-SFF native interface
842 +#
843 +CONFIG_SATA_AHCI=y
844 +# CONFIG_SATA_AHCI_PLATFORM is not set
845 +# CONFIG_SATA_INIC162X is not set
846 +# CONFIG_SATA_ACARD_AHCI is not set
847 +# CONFIG_SATA_SIL24 is not set
848 +# CONFIG_ATA_SFF is not set
849 +CONFIG_MD=y
850 +CONFIG_BLK_DEV_MD=y
851 +CONFIG_MD_AUTODETECT=y
852 +# CONFIG_MD_LINEAR is not set
853 +CONFIG_MD_RAID0=y
854 +CONFIG_MD_RAID1=y
855 +CONFIG_MD_RAID10=y
856 +CONFIG_MD_RAID456=y
857 +# CONFIG_MULTICORE_RAID456 is not set
858 +# CONFIG_MD_MULTIPATH is not set
859 +# CONFIG_MD_FAULTY is not set
860 +CONFIG_BLK_DEV_DM=y
861 +# CONFIG_DM_DEBUG is not set
862 +# CONFIG_DM_CRYPT is not set
863 +CONFIG_DM_SNAPSHOT=y
864 +CONFIG_DM_MIRROR=y
865 +CONFIG_DM_RAID=y
866 +# CONFIG_DM_LOG_USERSPACE is not set
867 +# CONFIG_DM_ZERO is not set
868 +# CONFIG_DM_MULTIPATH is not set
869 +# CONFIG_DM_DELAY is not set
870 +# CONFIG_DM_UEVENT is not set
871 +# CONFIG_DM_FLAKEY is not set
872 +# CONFIG_TARGET_CORE is not set
873 +# CONFIG_FUSION is not set
874 +
875 +#
876 +# IEEE 1394 (FireWire) support
877 +#
878 +# CONFIG_FIREWIRE is not set
879 +# CONFIG_FIREWIRE_NOSY is not set
880 +# CONFIG_I2O is not set
881 +# CONFIG_MACINTOSH_DRIVERS is not set
882 +CONFIG_NETDEVICES=y
883 +# CONFIG_DUMMY is not set
884 +# CONFIG_BONDING is not set
885 +# CONFIG_MACVLAN is not set
886 +# CONFIG_EQUALIZER is not set
887 +CONFIG_TUN=y
888 +# CONFIG_VETH is not set
889 +# CONFIG_NET_SB1000 is not set
890 +# CONFIG_ARCNET is not set
891 +CONFIG_MII=y
892 +# CONFIG_PHYLIB is not set
893 +# CONFIG_NET_ETHERNET is not set
894 +CONFIG_NETDEV_1000=y
895 +# CONFIG_ACENIC is not set
896 +# CONFIG_DL2K is not set
897 +# CONFIG_E1000 is not set
898 +# CONFIG_E1000E is not set
899 +# CONFIG_IP1000 is not set
900 +# CONFIG_IGB is not set
901 +# CONFIG_IGBVF is not set
902 +# CONFIG_NS83820 is not set
903 +# CONFIG_HAMACHI is not set
904 +# CONFIG_YELLOWFIN is not set
905 +CONFIG_R8169=y
906 +# CONFIG_SIS190 is not set
907 +# CONFIG_SKGE is not set
908 +# CONFIG_SKY2 is not set
909 +# CONFIG_VIA_VELOCITY is not set
910 +# CONFIG_TIGON3 is not set
911 +# CONFIG_BNX2 is not set
912 +# CONFIG_CNIC is not set
913 +# CONFIG_QLA3XXX is not set
914 +# CONFIG_ATL1 is not set
915 +# CONFIG_ATL1E is not set
916 +# CONFIG_ATL1C is not set
917 +# CONFIG_JME is not set
918 +# CONFIG_STMMAC_ETH is not set
919 +# CONFIG_PCH_GBE is not set
920 +# CONFIG_NETDEV_10000 is not set
921 +# CONFIG_TR is not set
922 +# CONFIG_WLAN is not set
923 +
924 +#
925 +# Enable WiMAX (Networking options) to see the WiMAX drivers
926 +#
927 +# CONFIG_WAN is not set
928 +
929 +#
930 +# CAIF transport drivers
931 +#
932 +# CONFIG_FDDI is not set
933 +# CONFIG_HIPPI is not set
934 +# CONFIG_PPP is not set
935 +# CONFIG_SLIP is not set
936 +# CONFIG_NET_FC is not set
937 +# CONFIG_NETCONSOLE is not set
938 +# CONFIG_NETPOLL is not set
939 +# CONFIG_NET_POLL_CONTROLLER is not set
940 +# CONFIG_VMXNET3 is not set
941 +# CONFIG_ISDN is not set
942 +# CONFIG_PHONE is not set
943 +
944 +#
945 +# Input device support
946 +#
947 +CONFIG_INPUT=y
948 +# CONFIG_INPUT_FF_MEMLESS is not set
949 +# CONFIG_INPUT_POLLDEV is not set
950 +# CONFIG_INPUT_SPARSEKMAP is not set
951 +
952 +#
953 +# Userland interfaces
954 +#
955 +CONFIG_INPUT_MOUSEDEV=y
956 +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
957 +CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
958 +CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
959 +# CONFIG_INPUT_JOYDEV is not set
960 +# CONFIG_INPUT_EVDEV is not set
961 +# CONFIG_INPUT_EVBUG is not set
962 +
963 +#
964 +# Input Device Drivers
965 +#
966 +CONFIG_INPUT_KEYBOARD=y
967 +CONFIG_KEYBOARD_ATKBD=y
968 +# CONFIG_KEYBOARD_LKKBD is not set
969 +# CONFIG_KEYBOARD_NEWTON is not set
970 +# CONFIG_KEYBOARD_OPENCORES is not set
971 +# CONFIG_KEYBOARD_STOWAWAY is not set
972 +# CONFIG_KEYBOARD_SUNKBD is not set
973 +# CONFIG_KEYBOARD_XTKBD is not set
974 +# CONFIG_INPUT_MOUSE is not set
975 +# CONFIG_INPUT_JOYSTICK is not set
976 +# CONFIG_INPUT_TABLET is not set
977 +# CONFIG_INPUT_TOUCHSCREEN is not set
978 +# CONFIG_INPUT_MISC is not set
979 +
980 +#
981 +# Hardware I/O ports
982 +#
983 +CONFIG_SERIO=y
984 +CONFIG_SERIO_I8042=y
985 +# CONFIG_SERIO_SERPORT is not set
986 +# CONFIG_SERIO_CT82C710 is not set
987 +# CONFIG_SERIO_PCIPS2 is not set
988 +CONFIG_SERIO_LIBPS2=y
989 +# CONFIG_SERIO_RAW is not set
990 +# CONFIG_SERIO_ALTERA_PS2 is not set
991 +# CONFIG_SERIO_PS2MULT is not set
992 +# CONFIG_GAMEPORT is not set
993 +
994 +#
995 +# Character devices
996 +#
997 +CONFIG_VT=y
998 +CONFIG_CONSOLE_TRANSLATIONS=y
999 +CONFIG_VT_CONSOLE=y
1000 +CONFIG_HW_CONSOLE=y
1001 +# CONFIG_VT_HW_CONSOLE_BINDING is not set
1002 +CONFIG_UNIX98_PTYS=y
1003 +CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
1004 +CONFIG_LEGACY_PTYS=y
1005 +CONFIG_LEGACY_PTY_COUNT=0
1006 +# CONFIG_SERIAL_NONSTANDARD is not set
1007 +# CONFIG_NOZOMI is not set
1008 +# CONFIG_N_GSM is not set
1009 +# CONFIG_TRACE_SINK is not set
1010 +# CONFIG_DEVKMEM is not set
1011 +
1012 +#
1013 +# Serial drivers
1014 +#
1015 +CONFIG_SERIAL_8250=y
1016 +CONFIG_SERIAL_8250_CONSOLE=y
1017 +CONFIG_FIX_EARLYCON_MEM=y
1018 +CONFIG_SERIAL_8250_PCI=y
1019 +CONFIG_SERIAL_8250_PNP=y
1020 +CONFIG_SERIAL_8250_NR_UARTS=4
1021 +CONFIG_SERIAL_8250_RUNTIME_UARTS=4
1022 +# CONFIG_SERIAL_8250_EXTENDED is not set
1023 +
1024 +#
1025 +# Non-8250 serial port support
1026 +#
1027 +# CONFIG_SERIAL_MFD_HSU is not set
1028 +CONFIG_SERIAL_CORE=y
1029 +CONFIG_SERIAL_CORE_CONSOLE=y
1030 +# CONFIG_SERIAL_JSM is not set
1031 +# CONFIG_SERIAL_TIMBERDALE is not set
1032 +# CONFIG_SERIAL_ALTERA_JTAGUART is not set
1033 +# CONFIG_SERIAL_ALTERA_UART is not set
1034 +# CONFIG_SERIAL_PCH_UART is not set
1035 +# CONFIG_SERIAL_XILINX_PS_UART is not set
1036 +CONFIG_TTY_PRINTK=y
1037 +# CONFIG_IPMI_HANDLER is not set
1038 +# CONFIG_HW_RANDOM is not set
1039 +# CONFIG_NVRAM is not set
1040 +CONFIG_RTC=y
1041 +# CONFIG_R3964 is not set
1042 +# CONFIG_APPLICOM is not set
1043 +# CONFIG_MWAVE is not set
1044 +# CONFIG_RAW_DRIVER is not set
1045 +# CONFIG_HPET is not set
1046 +# CONFIG_HANGCHECK_TIMER is not set
1047 +# CONFIG_TCG_TPM is not set
1048 +# CONFIG_TELCLOCK is not set
1049 +CONFIG_DEVPORT=y
1050 +CONFIG_RAMOOPS=y
1051 +# CONFIG_I2C is not set
1052 +# CONFIG_SPI is not set
1053 +
1054 +#
1055 +# PPS support
1056 +#
1057 +# CONFIG_PPS is not set
1058 +
1059 +#
1060 +# PPS generators support
1061 +#
1062 +
1063 +#
1064 +# PTP clock support
1065 +#
1066 +
1067 +#
1068 +# Enable Device Drivers -> PPS to see the PTP clock options.
1069 +#
1070 +CONFIG_ARCH_WANT_OPTIONAL_GPIOLIB=y
1071 +# CONFIG_GPIOLIB is not set
1072 +# CONFIG_W1 is not set
1073 +CONFIG_POWER_SUPPLY=y
1074 +# CONFIG_POWER_SUPPLY_DEBUG is not set
1075 +# CONFIG_PDA_POWER is not set
1076 +# CONFIG_TEST_POWER is not set
1077 +# CONFIG_BATTERY_DS2780 is not set
1078 +# CONFIG_BATTERY_BQ27x00 is not set
1079 +# CONFIG_CHARGER_MAX8903 is not set
1080 +# CONFIG_HWMON is not set
1081 +CONFIG_THERMAL=y
1082 +# CONFIG_WATCHDOG is not set
1083 +CONFIG_SSB_POSSIBLE=y
1084 +
1085 +#
1086 +# Sonics Silicon Backplane
1087 +#
1088 +# CONFIG_SSB is not set
1089 +CONFIG_BCMA_POSSIBLE=y
1090 +
1091 +#
1092 +# Broadcom specific AMBA
1093 +#
1094 +# CONFIG_BCMA is not set
1095 +# CONFIG_MFD_SUPPORT is not set
1096 +# CONFIG_REGULATOR is not set
1097 +# CONFIG_MEDIA_SUPPORT is not set
1098 +
1099 +#
1100 +# Graphics support
1101 +#
1102 +# CONFIG_AGP is not set
1103 +CONFIG_VGA_ARB=y
1104 +CONFIG_VGA_ARB_MAX_GPUS=2
1105 +# CONFIG_VGA_SWITCHEROO is not set
1106 +# CONFIG_DRM is not set
1107 +# CONFIG_STUB_POULSBO is not set
1108 +# CONFIG_VGASTATE is not set
1109 +# CONFIG_VIDEO_OUTPUT_CONTROL is not set
1110 +# CONFIG_FB is not set
1111 +# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
1112 +
1113 +#
1114 +# Display device support
1115 +#
1116 +# CONFIG_DISPLAY_SUPPORT is not set
1117 +
1118 +#
1119 +# Console display driver support
1120 +#
1121 +CONFIG_VGA_CONSOLE=y
1122 +# CONFIG_VGACON_SOFT_SCROLLBACK is not set
1123 +CONFIG_DUMMY_CONSOLE=y
1124 +# CONFIG_SOUND is not set
1125 +# CONFIG_HID_SUPPORT is not set
1126 +# CONFIG_USB_SUPPORT is not set
1127 +# CONFIG_UWB is not set
1128 +# CONFIG_MMC is not set
1129 +# CONFIG_MEMSTICK is not set
1130 +# CONFIG_NEW_LEDS is not set
1131 +# CONFIG_NFC_DEVICES is not set
1132 +# CONFIG_ACCESSIBILITY is not set
1133 +# CONFIG_INFINIBAND is not set
1134 +# CONFIG_EDAC is not set
1135 +# CONFIG_RTC_CLASS is not set
1136 +# CONFIG_DMADEVICES is not set
1137 +# CONFIG_AUXDISPLAY is not set
1138 +# CONFIG_UIO is not set
1139 +# CONFIG_STAGING is not set
1140 +# CONFIG_X86_PLATFORM_DEVICES is not set
1141 +
1142 +#
1143 +# Firmware Drivers
1144 +#
1145 +# CONFIG_EDD is not set
1146 +CONFIG_FIRMWARE_MEMMAP=y
1147 +# CONFIG_DELL_RBU is not set
1148 +# CONFIG_DCDBAS is not set
1149 +# CONFIG_DMIID is not set
1150 +# CONFIG_DMI_SYSFS is not set
1151 +# CONFIG_ISCSI_IBFT_FIND is not set
1152 +# CONFIG_GOOGLE_FIRMWARE is not set
1153 +
1154 +#
1155 +# File systems
1156 +#
1157 +CONFIG_EXT2_FS=y
1158 +CONFIG_EXT2_FS_XATTR=y
1159 +CONFIG_EXT2_FS_POSIX_ACL=y
1160 +CONFIG_EXT2_FS_SECURITY=y
1161 +CONFIG_EXT2_FS_XIP=y
1162 +CONFIG_EXT3_FS=y
1163 +CONFIG_EXT3_DEFAULTS_TO_ORDERED=y
1164 +CONFIG_EXT3_FS_XATTR=y
1165 +CONFIG_EXT3_FS_POSIX_ACL=y
1166 +CONFIG_EXT3_FS_SECURITY=y
1167 +CONFIG_EXT4_FS=y
1168 +CONFIG_EXT4_FS_XATTR=y
1169 +CONFIG_EXT4_FS_POSIX_ACL=y
1170 +CONFIG_EXT4_FS_SECURITY=y
1171 +# CONFIG_EXT4_DEBUG is not set
1172 +CONFIG_FS_XIP=y
1173 +CONFIG_JBD=y
1174 +CONFIG_JBD2=y
1175 +CONFIG_FS_MBCACHE=y
1176 +CONFIG_REISERFS_FS=y
1177 +CONFIG_REISERFS_CHECK=y
1178 +CONFIG_REISERFS_PROC_INFO=y
1179 +CONFIG_REISERFS_FS_XATTR=y
1180 +CONFIG_REISERFS_FS_POSIX_ACL=y
1181 +CONFIG_REISERFS_FS_SECURITY=y
1182 +CONFIG_JFS_FS=y
1183 +CONFIG_JFS_POSIX_ACL=y
1184 +CONFIG_JFS_SECURITY=y
1185 +CONFIG_JFS_DEBUG=y
1186 +CONFIG_JFS_STATISTICS=y
1187 +CONFIG_XFS_FS=y
1188 +CONFIG_XFS_QUOTA=y
1189 +CONFIG_XFS_POSIX_ACL=y
1190 +CONFIG_XFS_RT=y
1191 +# CONFIG_XFS_DEBUG is not set
1192 +CONFIG_GFS2_FS=y
1193 +CONFIG_GFS2_FS_LOCKING_DLM=y
1194 +CONFIG_OCFS2_FS=y
1195 +CONFIG_OCFS2_FS_O2CB=y
1196 +CONFIG_OCFS2_FS_USERSPACE_CLUSTER=y
1197 +CONFIG_OCFS2_DEBUG_MASKLOG=y
1198 +CONFIG_OCFS2_DEBUG_FS=y
1199 +CONFIG_BTRFS_FS=y
1200 +CONFIG_BTRFS_FS_POSIX_ACL=y
1201 +# CONFIG_NILFS2_FS is not set
1202 +CONFIG_FS_POSIX_ACL=y
1203 +CONFIG_EXPORTFS=y
1204 +CONFIG_FILE_LOCKING=y
1205 +CONFIG_FSNOTIFY=y
1206 +CONFIG_DNOTIFY=y
1207 +CONFIG_INOTIFY_USER=y
1208 +CONFIG_FANOTIFY=y
1209 +CONFIG_QUOTA=y
1210 +CONFIG_QUOTA_NETLINK_INTERFACE=y
1211 +CONFIG_PRINT_QUOTA_WARNING=y
1212 +# CONFIG_QUOTA_DEBUG is not set
1213 +CONFIG_QUOTA_TREE=y
1214 +CONFIG_QFMT_V1=y
1215 +CONFIG_QFMT_V2=y
1216 +CONFIG_QUOTACTL=y
1217 +CONFIG_QUOTACTL_COMPAT=y
1218 +# CONFIG_AUTOFS4_FS is not set
1219 +# CONFIG_FUSE_FS is not set
1220 +CONFIG_GENERIC_ACL=y
1221 +
1222 +#
1223 +# Caches
1224 +#
1225 +# CONFIG_FSCACHE is not set
1226 +
1227 +#
1228 +# CD-ROM/DVD Filesystems
1229 +#
1230 +# CONFIG_ISO9660_FS is not set
1231 +# CONFIG_UDF_FS is not set
1232 +
1233 +#
1234 +# DOS/FAT/NT Filesystems
1235 +#
1236 +# CONFIG_MSDOS_FS is not set
1237 +# CONFIG_VFAT_FS is not set
1238 +# CONFIG_NTFS_FS is not set
1239 +
1240 +#
1241 +# Pseudo filesystems
1242 +#
1243 +CONFIG_PROC_FS=y
1244 +# CONFIG_PROC_KCORE is not set
1245 +CONFIG_PROC_SYSCTL=y
1246 +CONFIG_PROC_PAGE_MONITOR=y
1247 +CONFIG_SYSFS=y
1248 +CONFIG_TMPFS=y
1249 +CONFIG_TMPFS_POSIX_ACL=y
1250 +CONFIG_TMPFS_XATTR=y
1251 +# CONFIG_HUGETLBFS is not set
1252 +# CONFIG_HUGETLB_PAGE is not set
1253 +CONFIG_CONFIGFS_FS=y
1254 +# CONFIG_MISC_FILESYSTEMS is not set
1255 +CONFIG_NETWORK_FILESYSTEMS=y
1256 +CONFIG_NFS_FS=y
1257 +CONFIG_NFS_V3=y
1258 +# CONFIG_NFS_V3_ACL is not set
1259 +# CONFIG_NFS_V4 is not set
1260 +CONFIG_NFSD=y
1261 +CONFIG_NFSD_DEPRECATED=y
1262 +CONFIG_NFSD_V3=y
1263 +# CONFIG_NFSD_V3_ACL is not set
1264 +# CONFIG_NFSD_V4 is not set
1265 +CONFIG_LOCKD=y
1266 +CONFIG_LOCKD_V4=y
1267 +CONFIG_NFS_COMMON=y
1268 +CONFIG_SUNRPC=y
1269 +# CONFIG_CEPH_FS is not set
1270 +# CONFIG_CIFS is not set
1271 +# CONFIG_NCP_FS is not set
1272 +# CONFIG_CODA_FS is not set
1273 +# CONFIG_AFS_FS is not set
1274 +
1275 +#
1276 +# Partition Types
1277 +#
1278 +# CONFIG_PARTITION_ADVANCED is not set
1279 +CONFIG_MSDOS_PARTITION=y
1280 +CONFIG_NLS=y
1281 +CONFIG_NLS_DEFAULT="iso8859-1"
1282 +# CONFIG_NLS_CODEPAGE_437 is not set
1283 +# CONFIG_NLS_CODEPAGE_737 is not set
1284 +# CONFIG_NLS_CODEPAGE_775 is not set
1285 +# CONFIG_NLS_CODEPAGE_850 is not set
1286 +# CONFIG_NLS_CODEPAGE_852 is not set
1287 +# CONFIG_NLS_CODEPAGE_855 is not set
1288 +# CONFIG_NLS_CODEPAGE_857 is not set
1289 +# CONFIG_NLS_CODEPAGE_860 is not set
1290 +# CONFIG_NLS_CODEPAGE_861 is not set
1291 +# CONFIG_NLS_CODEPAGE_862 is not set
1292 +# CONFIG_NLS_CODEPAGE_863 is not set
1293 +# CONFIG_NLS_CODEPAGE_864 is not set
1294 +# CONFIG_NLS_CODEPAGE_865 is not set
1295 +# CONFIG_NLS_CODEPAGE_866 is not set
1296 +# CONFIG_NLS_CODEPAGE_869 is not set
1297 +# CONFIG_NLS_CODEPAGE_936 is not set
1298 +# CONFIG_NLS_CODEPAGE_950 is not set
1299 +# CONFIG_NLS_CODEPAGE_932 is not set
1300 +# CONFIG_NLS_CODEPAGE_949 is not set
1301 +# CONFIG_NLS_CODEPAGE_874 is not set
1302 +# CONFIG_NLS_ISO8859_8 is not set
1303 +# CONFIG_NLS_CODEPAGE_1250 is not set
1304 +# CONFIG_NLS_CODEPAGE_1251 is not set
1305 +# CONFIG_NLS_ASCII is not set
1306 +# CONFIG_NLS_ISO8859_1 is not set
1307 +# CONFIG_NLS_ISO8859_2 is not set
1308 +# CONFIG_NLS_ISO8859_3 is not set
1309 +# CONFIG_NLS_ISO8859_4 is not set
1310 +# CONFIG_NLS_ISO8859_5 is not set
1311 +# CONFIG_NLS_ISO8859_6 is not set
1312 +# CONFIG_NLS_ISO8859_7 is not set
1313 +# CONFIG_NLS_ISO8859_9 is not set
1314 +# CONFIG_NLS_ISO8859_13 is not set
1315 +# CONFIG_NLS_ISO8859_14 is not set
1316 +# CONFIG_NLS_ISO8859_15 is not set
1317 +# CONFIG_NLS_KOI8_R is not set
1318 +# CONFIG_NLS_KOI8_U is not set
1319 +# CONFIG_NLS_UTF8 is not set
1320 +CONFIG_DLM=y
1321 +# CONFIG_DLM_DEBUG is not set
1322 +
1323 +#
1324 +# Kernel hacking
1325 +#
1326 +CONFIG_TRACE_IRQFLAGS_SUPPORT=y
1327 +CONFIG_PRINTK_TIME=y
1328 +CONFIG_DEFAULT_MESSAGE_LOGLEVEL=4
1329 +# CONFIG_ENABLE_WARN_DEPRECATED is not set
1330 +# CONFIG_ENABLE_MUST_CHECK is not set
1331 +CONFIG_FRAME_WARN=2048
1332 +CONFIG_MAGIC_SYSRQ=y
1333 +# CONFIG_STRIP_ASM_SYMS is not set
1334 +# CONFIG_UNUSED_SYMBOLS is not set
1335 +# CONFIG_DEBUG_FS is not set
1336 +# CONFIG_HEADERS_CHECK is not set
1337 +# CONFIG_DEBUG_SECTION_MISMATCH is not set
1338 +CONFIG_DEBUG_KERNEL=y
1339 +# CONFIG_DEBUG_SHIRQ is not set
1340 +# CONFIG_LOCKUP_DETECTOR is not set
1341 +# CONFIG_HARDLOCKUP_DETECTOR is not set
1342 +CONFIG_DETECT_HUNG_TASK=y
1343 +CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=120
1344 +# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
1345 +CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
1346 +# CONFIG_SCHED_DEBUG is not set
1347 +# CONFIG_SCHEDSTATS is not set
1348 +# CONFIG_TIMER_STATS is not set
1349 +# CONFIG_DEBUG_OBJECTS is not set
1350 +# CONFIG_SLUB_DEBUG_ON is not set
1351 +# CONFIG_SLUB_STATS is not set
1352 +# CONFIG_DEBUG_KMEMLEAK is not set
1353 +# CONFIG_DEBUG_RT_MUTEXES is not set
1354 +# CONFIG_RT_MUTEX_TESTER is not set
1355 +# CONFIG_DEBUG_SPINLOCK is not set
1356 +# CONFIG_DEBUG_MUTEXES is not set
1357 +# CONFIG_DEBUG_LOCK_ALLOC is not set
1358 +# CONFIG_PROVE_LOCKING is not set
1359 +# CONFIG_SPARSE_RCU_POINTER is not set
1360 +# CONFIG_LOCK_STAT is not set
1361 +# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1362 +# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1363 +# CONFIG_DEBUG_STACK_USAGE is not set
1364 +# CONFIG_DEBUG_KOBJECT is not set
1365 +CONFIG_DEBUG_BUGVERBOSE=y
1366 +CONFIG_DEBUG_INFO=y
1367 +# CONFIG_DEBUG_INFO_REDUCED is not set
1368 +# CONFIG_DEBUG_VM is not set
1369 +# CONFIG_DEBUG_VIRTUAL is not set
1370 +# CONFIG_DEBUG_WRITECOUNT is not set
1371 +CONFIG_DEBUG_MEMORY_INIT=y
1372 +# CONFIG_DEBUG_LIST is not set
1373 +# CONFIG_TEST_LIST_SORT is not set
1374 +# CONFIG_DEBUG_SG is not set
1375 +# CONFIG_DEBUG_NOTIFIERS is not set
1376 +# CONFIG_DEBUG_CREDENTIALS is not set
1377 +CONFIG_ARCH_WANT_FRAME_POINTERS=y
1378 +# CONFIG_FRAME_POINTER is not set
1379 +# CONFIG_BOOT_PRINTK_DELAY is not set
1380 +# CONFIG_RCU_TORTURE_TEST is not set
1381 +CONFIG_RCU_CPU_STALL_TIMEOUT=60
1382 +# CONFIG_BACKTRACE_SELF_TEST is not set
1383 +# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
1384 +# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
1385 +# CONFIG_DEBUG_PER_CPU_MAPS is not set
1386 +# CONFIG_CPU_NOTIFIER_ERROR_INJECT is not set
1387 +# CONFIG_FAULT_INJECTION is not set
1388 +# CONFIG_LATENCYTOP is not set
1389 +# CONFIG_SYSCTL_SYSCALL_CHECK is not set
1390 +# CONFIG_DEBUG_PAGEALLOC is not set
1391 +CONFIG_USER_STACKTRACE_SUPPORT=y
1392 +CONFIG_HAVE_FUNCTION_TRACER=y
1393 +CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
1394 +CONFIG_HAVE_FUNCTION_GRAPH_FP_TEST=y
1395 +CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
1396 +CONFIG_HAVE_DYNAMIC_FTRACE=y
1397 +CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1398 +CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
1399 +CONFIG_HAVE_C_RECORDMCOUNT=y
1400 +CONFIG_TRACING_SUPPORT=y
1401 +# CONFIG_FTRACE is not set
1402 +# CONFIG_PROVIDE_OHCI1394_DMA_INIT is not set
1403 +# CONFIG_DMA_API_DEBUG is not set
1404 +CONFIG_ATOMIC64_SELFTEST=y
1405 +# CONFIG_ASYNC_RAID6_TEST is not set
1406 +# CONFIG_SAMPLES is not set
1407 +CONFIG_HAVE_ARCH_KGDB=y
1408 +# CONFIG_KGDB is not set
1409 +CONFIG_HAVE_ARCH_KMEMCHECK=y
1410 +# CONFIG_TEST_KSTRTOX is not set
1411 +# CONFIG_STRICT_DEVMEM is not set
1412 +# CONFIG_X86_VERBOSE_BOOTUP is not set
1413 +CONFIG_EARLY_PRINTK=y
1414 +# CONFIG_EARLY_PRINTK_DBGP is not set
1415 +# CONFIG_DEBUG_STACKOVERFLOW is not set
1416 +# CONFIG_X86_PTDUMP is not set
1417 +CONFIG_DEBUG_RODATA=y
1418 +CONFIG_DEBUG_RODATA_TEST=y
1419 +# CONFIG_IOMMU_DEBUG is not set
1420 +# CONFIG_IOMMU_STRESS is not set
1421 +CONFIG_HAVE_MMIOTRACE_SUPPORT=y
1422 +CONFIG_IO_DELAY_TYPE_0X80=0
1423 +CONFIG_IO_DELAY_TYPE_0XED=1
1424 +CONFIG_IO_DELAY_TYPE_UDELAY=2
1425 +CONFIG_IO_DELAY_TYPE_NONE=3
1426 +CONFIG_IO_DELAY_0X80=y
1427 +# CONFIG_IO_DELAY_0XED is not set
1428 +# CONFIG_IO_DELAY_UDELAY is not set
1429 +# CONFIG_IO_DELAY_NONE is not set
1430 +CONFIG_DEFAULT_IO_DELAY_TYPE=0
1431 +# CONFIG_CPA_DEBUG is not set
1432 +# CONFIG_OPTIMIZE_INLINING is not set
1433 +# CONFIG_DEBUG_STRICT_USER_COPY_CHECKS is not set
1434 +
1435 +#
1436 +# Linux VServer
1437 +#
1438 +CONFIG_VSERVER_AUTO_LBACK=y
1439 +# CONFIG_VSERVER_AUTO_SINGLE is not set
1440 +CONFIG_VSERVER_COWBL=y
1441 +CONFIG_VSERVER_VTIME=y
1442 +# CONFIG_VSERVER_DEVICE is not set
1443 +CONFIG_VSERVER_PROC_SECURE=y
1444 +# CONFIG_TAGGING_NONE is not set
1445 +# CONFIG_TAGGING_UID16 is not set
1446 +# CONFIG_TAGGING_GID16 is not set
1447 +CONFIG_TAGGING_ID24=y
1448 +# CONFIG_TAGGING_INTERN is not set
1449 +# CONFIG_TAG_NFSD is not set
1450 +# CONFIG_VSERVER_PRIVACY is not set
1451 +CONFIG_VSERVER_CONTEXTS=768
1452 +CONFIG_VSERVER_WARN=y
1453 +CONFIG_VSERVER_WARN_DEVPTS=y
1454 +CONFIG_VSERVER_DEBUG=y
1455 +CONFIG_VSERVER_HISTORY=y
1456 +CONFIG_VSERVER_HISTORY_SIZE=64
1457 +CONFIG_VSERVER_LEGACY_MEM=y
1458 +# CONFIG_QUOTES_ISO8859 is not set
1459 +# CONFIG_QUOTES_UTF8 is not set
1460 +CONFIG_QUOTES_ASCII=y
1461 +CONFIG_VSERVER=y
1462 +
1463 +#
1464 +# Security options
1465 +#
1466 +# CONFIG_KEYS is not set
1467 +CONFIG_SECURITY_DMESG_RESTRICT=y
1468 +# CONFIG_SECURITY is not set
1469 +# CONFIG_SECURITYFS is not set
1470 +CONFIG_DEFAULT_SECURITY_DAC=y
1471 +CONFIG_DEFAULT_SECURITY=""
1472 +CONFIG_XOR_BLOCKS=y
1473 +CONFIG_ASYNC_CORE=y
1474 +CONFIG_ASYNC_MEMCPY=y
1475 +CONFIG_ASYNC_XOR=y
1476 +CONFIG_ASYNC_PQ=y
1477 +CONFIG_ASYNC_RAID6_RECOV=y
1478 +CONFIG_CRYPTO=y
1479 +
1480 +#
1481 +# Crypto core or helper
1482 +#
1483 +CONFIG_CRYPTO_ALGAPI=y
1484 +CONFIG_CRYPTO_ALGAPI2=y
1485 +CONFIG_CRYPTO_AEAD=y
1486 +CONFIG_CRYPTO_AEAD2=y
1487 +CONFIG_CRYPTO_BLKCIPHER=y
1488 +CONFIG_CRYPTO_BLKCIPHER2=y
1489 +CONFIG_CRYPTO_HASH=y
1490 +CONFIG_CRYPTO_HASH2=y
1491 +CONFIG_CRYPTO_RNG=y
1492 +CONFIG_CRYPTO_RNG2=y
1493 +CONFIG_CRYPTO_PCOMP2=y
1494 +CONFIG_CRYPTO_MANAGER=y
1495 +CONFIG_CRYPTO_MANAGER2=y
1496 +CONFIG_CRYPTO_MANAGER_DISABLE_TESTS=y
1497 +# CONFIG_CRYPTO_GF128MUL is not set
1498 +# CONFIG_CRYPTO_NULL is not set
1499 +# CONFIG_CRYPTO_PCRYPT is not set
1500 +CONFIG_CRYPTO_WORKQUEUE=y
1501 +# CONFIG_CRYPTO_CRYPTD is not set
1502 +CONFIG_CRYPTO_AUTHENC=y
1503 +
1504 +#
1505 +# Authenticated Encryption with Associated Data
1506 +#
1507 +# CONFIG_CRYPTO_CCM is not set
1508 +# CONFIG_CRYPTO_GCM is not set
1509 +# CONFIG_CRYPTO_SEQIV is not set
1510 +
1511 +#
1512 +# Block modes
1513 +#
1514 +CONFIG_CRYPTO_CBC=y
1515 +# CONFIG_CRYPTO_CTR is not set
1516 +# CONFIG_CRYPTO_CTS is not set
1517 +# CONFIG_CRYPTO_ECB is not set
1518 +# CONFIG_CRYPTO_LRW is not set
1519 +# CONFIG_CRYPTO_PCBC is not set
1520 +# CONFIG_CRYPTO_XTS is not set
1521 +
1522 +#
1523 +# Hash modes
1524 +#
1525 +CONFIG_CRYPTO_HMAC=y
1526 +# CONFIG_CRYPTO_XCBC is not set
1527 +# CONFIG_CRYPTO_VMAC is not set
1528 +
1529 +#
1530 +# Digest
1531 +#
1532 +CONFIG_CRYPTO_CRC32C=y
1533 +# CONFIG_CRYPTO_CRC32C_INTEL is not set
1534 +# CONFIG_CRYPTO_GHASH is not set
1535 +# CONFIG_CRYPTO_MD4 is not set
1536 +CONFIG_CRYPTO_MD5=y
1537 +# CONFIG_CRYPTO_MICHAEL_MIC is not set
1538 +# CONFIG_CRYPTO_RMD128 is not set
1539 +# CONFIG_CRYPTO_RMD160 is not set
1540 +# CONFIG_CRYPTO_RMD256 is not set
1541 +# CONFIG_CRYPTO_RMD320 is not set
1542 +CONFIG_CRYPTO_SHA1=y
1543 +# CONFIG_CRYPTO_SHA256 is not set
1544 +# CONFIG_CRYPTO_SHA512 is not set
1545 +# CONFIG_CRYPTO_TGR192 is not set
1546 +# CONFIG_CRYPTO_WP512 is not set
1547 +# CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL is not set
1548 +
1549 +#
1550 +# Ciphers
1551 +#
1552 +CONFIG_CRYPTO_AES=y
1553 +# CONFIG_CRYPTO_AES_X86_64 is not set
1554 +# CONFIG_CRYPTO_AES_NI_INTEL is not set
1555 +# CONFIG_CRYPTO_ANUBIS is not set
1556 +# CONFIG_CRYPTO_ARC4 is not set
1557 +# CONFIG_CRYPTO_BLOWFISH is not set
1558 +# CONFIG_CRYPTO_CAMELLIA is not set
1559 +# CONFIG_CRYPTO_CAST5 is not set
1560 +# CONFIG_CRYPTO_CAST6 is not set
1561 +CONFIG_CRYPTO_DES=y
1562 +# CONFIG_CRYPTO_FCRYPT is not set
1563 +# CONFIG_CRYPTO_KHAZAD is not set
1564 +# CONFIG_CRYPTO_SALSA20 is not set
1565 +# CONFIG_CRYPTO_SALSA20_X86_64 is not set
1566 +# CONFIG_CRYPTO_SEED is not set
1567 +# CONFIG_CRYPTO_SERPENT is not set
1568 +# CONFIG_CRYPTO_TEA is not set
1569 +# CONFIG_CRYPTO_TWOFISH is not set
1570 +# CONFIG_CRYPTO_TWOFISH_X86_64 is not set
1571 +
1572 +#
1573 +# Compression
1574 +#
1575 +CONFIG_CRYPTO_DEFLATE=y
1576 +# CONFIG_CRYPTO_ZLIB is not set
1577 +# CONFIG_CRYPTO_LZO is not set
1578 +
1579 +#
1580 +# Random Number Generation
1581 +#
1582 +CONFIG_CRYPTO_ANSI_CPRNG=y
1583 +CONFIG_CRYPTO_USER_API=y
1584 +CONFIG_CRYPTO_USER_API_HASH=y
1585 +CONFIG_CRYPTO_USER_API_SKCIPHER=y
1586 +CONFIG_CRYPTO_HW=y
1587 +# CONFIG_CRYPTO_DEV_PADLOCK is not set
1588 +# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1589 +CONFIG_HAVE_KVM=y
1590 +# CONFIG_VIRTUALIZATION is not set
1591 +# CONFIG_BINARY_PRINTF is not set
1592 +
1593 +#
1594 +# Library routines
1595 +#
1596 +CONFIG_RAID6_PQ=y
1597 +CONFIG_BITREVERSE=y
1598 +CONFIG_GENERIC_FIND_FIRST_BIT=y
1599 +# CONFIG_CRC_CCITT is not set
1600 +CONFIG_CRC16=y
1601 +# CONFIG_CRC_T10DIF is not set
1602 +# CONFIG_CRC_ITU_T is not set
1603 +CONFIG_CRC32=y
1604 +# CONFIG_CRC7 is not set
1605 +CONFIG_LIBCRC32C=y
1606 +CONFIG_ZLIB_INFLATE=y
1607 +CONFIG_ZLIB_DEFLATE=y
1608 +CONFIG_LZO_COMPRESS=y
1609 +CONFIG_LZO_DECOMPRESS=y
1610 +CONFIG_XZ_DEC=y
1611 +CONFIG_XZ_DEC_X86=y
1612 +# CONFIG_XZ_DEC_POWERPC is not set
1613 +# CONFIG_XZ_DEC_IA64 is not set
1614 +# CONFIG_XZ_DEC_ARM is not set
1615 +# CONFIG_XZ_DEC_ARMTHUMB is not set
1616 +# CONFIG_XZ_DEC_SPARC is not set
1617 +CONFIG_XZ_DEC_BCJ=y
1618 +# CONFIG_XZ_DEC_TEST is not set
1619 +CONFIG_HAS_IOMEM=y
1620 +CONFIG_HAS_IOPORT=y
1621 +CONFIG_HAS_DMA=y
1622 +CONFIG_CPU_RMAP=y
1623 +CONFIG_NLATTR=y
1624 +# CONFIG_AVERAGE is not set
1625 diff -NurpP --minimal linux-3.1/Documentation/vserver/debug.txt linux-3.1-vs2.3.1-rc2/Documentation/vserver/debug.txt
1626 --- linux-3.1/Documentation/vserver/debug.txt   1970-01-01 01:00:00.000000000 +0100
1627 +++ linux-3.1-vs2.3.1-rc2/Documentation/vserver/debug.txt       2011-10-24 18:53:33.000000000 +0200
1628 @@ -0,0 +1,154 @@
1629 +
1630 +debug_cvirt:
1631 +
1632 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1633 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1634 +
1635 +debug_dlim:
1636 +
1637 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1638 +       "FREE  (%p,#%d)%c inode"
1639 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1640 +       "FREE  (%p,#%d)%c %lld bytes"
1641 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1642 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1643 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1644 +       "rcu_free_dl_info(%p)"
1645 + 4  10 "alloc_dl_info(%p,%d) = %p"
1646 +       "dealloc_dl_info(%p)"
1647 +       "get_dl_info(%p[#%d.%d])"
1648 +       "put_dl_info(%p[#%d.%d])"
1649 + 5  20 "alloc_dl_info(%p,%d)*"
1650 + 6  40 "__hash_dl_info: %p[#%d]"
1651 +       "__unhash_dl_info: %p[#%d]"
1652 + 7  80 "locate_dl_info(%p,#%d) = %p"
1653 +
1654 +debug_misc:
1655 +
1656 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1657 +       "new_dqhash: %p [#0x%08x]"
1658 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1659 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1660 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1661 +       "vroot_get_real_bdev not set"
1662 + 1   2 "cow_break_link(»%s«)"
1663 +       "temp copy Â»%s«"
1664 + 2   4 "dentry_open(new): %p"
1665 +       "dentry_open(old): %p"
1666 +       "lookup_create(new): %p"
1667 +       "old path Â»%s«"
1668 +       "path_lookup(old): %d"
1669 +       "vfs_create(new): %d"
1670 +       "vfs_rename: %d"
1671 +       "vfs_sendfile: %d"
1672 + 3   8 "fput(new_file=%p[#%d])"
1673 +       "fput(old_file=%p[#%d])"
1674 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1675 +       "vx_info_kill(%p[#%d],%d,%d)*"
1676 + 5  20 "vs_reboot(%p[#%d],%d)"
1677 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1678 +
1679 +debug_net:
1680 +
1681 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1682 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1683 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
1684 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
1685 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
1686 + 6  40 "sk,egf: %p [#%d] (from %d)"
1687 +       "sk,egn: %p [#%d] (from %d)"
1688 +       "sk,req: %p [#%d] (from %d)"
1689 +       "sk: %p [#%d] (from %d)"
1690 +       "tw: %p [#%d] (from %d)"
1691 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
1692 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
1693 +
1694 +debug_nid:
1695 +
1696 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
1697 +       "alloc_nx_info(%d) = %p"
1698 +       "create_nx_info(%d) (dynamic rejected)"
1699 +       "create_nx_info(%d) = %p (already there)"
1700 +       "create_nx_info(%d) = %p (new)"
1701 +       "dealloc_nx_info(%p)"
1702 + 1   2 "alloc_nx_info(%d)*"
1703 +       "create_nx_info(%d)*"
1704 + 2   4 "get_nx_info(%p[#%d.%d])"
1705 +       "put_nx_info(%p[#%d.%d])"
1706 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1707 +       "clr_nx_info(%p[#%d.%d])"
1708 +       "init_nx_info(%p[#%d.%d])"
1709 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1710 +       "set_nx_info(%p[#%d.%d])"
1711 + 4  10 "__hash_nx_info: %p[#%d]"
1712 +       "__nx_dynamic_id: [#%d]"
1713 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1714 + 5  20 "moved task %p into nxi:%p[#%d]"
1715 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1716 +       "task_get_nx_info(%p)"
1717 + 6  40 "nx_clear_persistent(%p[#%d])"
1718 +
1719 +debug_quota:
1720 +
1721 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1722 + 1   2 "quota_sync_dqh(%p,%d)"
1723 +       "sync_dquots(%p,%d)"
1724 +       "sync_dquots_dqh(%p,%d)"
1725 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1726 +
1727 +debug_switch:
1728 +
1729 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1730 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1731 + 4  10 "%s: (%s %s) returned %s with %d"
1732 +
1733 +debug_tag:
1734 +
1735 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1736 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1737 +
1738 +debug_xid:
1739 +
1740 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1741 +       "alloc_vx_info(%d) = %p"
1742 +       "alloc_vx_info(%d)*"
1743 +       "create_vx_info(%d) (dynamic rejected)"
1744 +       "create_vx_info(%d) = %p (already there)"
1745 +       "create_vx_info(%d) = %p (new)"
1746 +       "dealloc_vx_info(%p)"
1747 +       "loc_vx_info(%d) = %p (found)"
1748 +       "loc_vx_info(%d) = %p (new)"
1749 +       "loc_vx_info(%d) = %p (not available)"
1750 + 1   2 "create_vx_info(%d)*"
1751 +       "loc_vx_info(%d)*"
1752 + 2   4 "get_vx_info(%p[#%d.%d])"
1753 +       "put_vx_info(%p[#%d.%d])"
1754 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1755 +       "clr_vx_info(%p[#%d.%d])"
1756 +       "init_vx_info(%p[#%d.%d])"
1757 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1758 +       "set_vx_info(%p[#%d.%d])"
1759 + 4  10 "__hash_vx_info: %p[#%d]"
1760 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1761 +       "__vx_dynamic_id: [#%d]"
1762 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1763 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1764 +       "moved task %p into vxi:%p[#%d]"
1765 +       "task_get_vx_info(%p)"
1766 +       "vx_migrate_task(%p,%p[#%d.%d])"
1767 + 6  40 "vx_clear_persistent(%p[#%d])"
1768 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1769 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1770 +       "vx_set_persistent(%p[#%d])"
1771 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1772 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1773 +
1774 +
1775 +debug_limit:
1776 +
1777 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1778 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1779 +
1780 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1781 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1782 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1783 diff -NurpP --minimal linux-3.1/arch/alpha/Kconfig linux-3.1-vs2.3.1-rc2/arch/alpha/Kconfig
1784 --- linux-3.1/arch/alpha/Kconfig        2011-10-24 18:44:54.000000000 +0200
1785 +++ linux-3.1-vs2.3.1-rc2/arch/alpha/Kconfig    2011-10-24 18:53:33.000000000 +0200
1786 @@ -670,6 +670,8 @@ config DUMMY_CONSOLE
1787         depends on VGA_HOSE
1788         default y
1789  
1790 +source "kernel/vserver/Kconfig"
1791 +
1792  source "security/Kconfig"
1793  
1794  source "crypto/Kconfig"
1795 diff -NurpP --minimal linux-3.1/arch/alpha/kernel/entry.S linux-3.1-vs2.3.1-rc2/arch/alpha/kernel/entry.S
1796 --- linux-3.1/arch/alpha/kernel/entry.S 2010-10-21 13:06:45.000000000 +0200
1797 +++ linux-3.1-vs2.3.1-rc2/arch/alpha/kernel/entry.S     2011-10-24 18:53:33.000000000 +0200
1798 @@ -860,24 +860,15 @@ sys_getxgid:
1799         .globl  sys_getxpid
1800         .ent    sys_getxpid
1801  sys_getxpid:
1802 +       lda     $sp, -16($sp)
1803 +       stq     $26, 0($sp)
1804         .prologue 0
1805 -       ldq     $2, TI_TASK($8)
1806  
1807 -       /* See linux/kernel/timer.c sys_getppid for discussion
1808 -          about this loop.  */
1809 -       ldq     $3, TASK_GROUP_LEADER($2)
1810 -       ldq     $4, TASK_REAL_PARENT($3)
1811 -       ldl     $0, TASK_TGID($2)
1812 -1:     ldl     $1, TASK_TGID($4)
1813 -#ifdef CONFIG_SMP
1814 -       mov     $4, $5
1815 -       mb
1816 -       ldq     $3, TASK_GROUP_LEADER($2)
1817 -       ldq     $4, TASK_REAL_PARENT($3)
1818 -       cmpeq   $4, $5, $5
1819 -       beq     $5, 1b
1820 -#endif
1821 -       stq     $1, 80($sp)
1822 +       lda     $16, 96($sp)
1823 +       jsr     $26, do_getxpid
1824 +       ldq     $26, 0($sp)
1825 +
1826 +       lda     $sp, 16($sp)
1827         ret
1828  .end sys_getxpid
1829  
1830 diff -NurpP --minimal linux-3.1/arch/alpha/kernel/ptrace.c linux-3.1-vs2.3.1-rc2/arch/alpha/kernel/ptrace.c
1831 --- linux-3.1/arch/alpha/kernel/ptrace.c        2011-01-05 21:48:40.000000000 +0100
1832 +++ linux-3.1-vs2.3.1-rc2/arch/alpha/kernel/ptrace.c    2011-10-24 18:53:33.000000000 +0200
1833 @@ -13,6 +13,7 @@
1834  #include <linux/user.h>
1835  #include <linux/security.h>
1836  #include <linux/signal.h>
1837 +#include <linux/vs_base.h>
1838  
1839  #include <asm/uaccess.h>
1840  #include <asm/pgtable.h>
1841 diff -NurpP --minimal linux-3.1/arch/alpha/kernel/systbls.S linux-3.1-vs2.3.1-rc2/arch/alpha/kernel/systbls.S
1842 --- linux-3.1/arch/alpha/kernel/systbls.S       2011-10-24 18:44:54.000000000 +0200
1843 +++ linux-3.1-vs2.3.1-rc2/arch/alpha/kernel/systbls.S   2011-10-24 18:53:33.000000000 +0200
1844 @@ -446,7 +446,7 @@ sys_call_table:
1845         .quad sys_stat64                        /* 425 */
1846         .quad sys_lstat64
1847         .quad sys_fstat64
1848 -       .quad sys_ni_syscall                    /* sys_vserver */
1849 +       .quad sys_vserver                       /* sys_vserver */
1850         .quad sys_ni_syscall                    /* sys_mbind */
1851         .quad sys_ni_syscall                    /* sys_get_mempolicy */
1852         .quad sys_ni_syscall                    /* sys_set_mempolicy */
1853 diff -NurpP --minimal linux-3.1/arch/alpha/kernel/traps.c linux-3.1-vs2.3.1-rc2/arch/alpha/kernel/traps.c
1854 --- linux-3.1/arch/alpha/kernel/traps.c 2010-10-21 13:06:46.000000000 +0200
1855 +++ linux-3.1-vs2.3.1-rc2/arch/alpha/kernel/traps.c     2011-10-24 18:53:33.000000000 +0200
1856 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
1857  #ifdef CONFIG_SMP
1858         printk("CPU %d ", hard_smp_processor_id());
1859  #endif
1860 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
1861 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
1862 +               task_pid_nr(current), current->xid, str, err);
1863         dik_show_regs(regs, r9_15);
1864         add_taint(TAINT_DIE);
1865         dik_show_trace((unsigned long *)(regs+1));
1866 diff -NurpP --minimal linux-3.1/arch/arm/Kconfig linux-3.1-vs2.3.1-rc2/arch/arm/Kconfig
1867 --- linux-3.1/arch/arm/Kconfig  2011-10-24 18:44:54.000000000 +0200
1868 +++ linux-3.1-vs2.3.1-rc2/arch/arm/Kconfig      2011-10-24 18:53:33.000000000 +0200
1869 @@ -2111,6 +2111,8 @@ source "fs/Kconfig"
1870  
1871  source "arch/arm/Kconfig.debug"
1872  
1873 +source "kernel/vserver/Kconfig"
1874 +
1875  source "security/Kconfig"
1876  
1877  source "crypto/Kconfig"
1878 diff -NurpP --minimal linux-3.1/arch/arm/kernel/calls.S linux-3.1-vs2.3.1-rc2/arch/arm/kernel/calls.S
1879 --- linux-3.1/arch/arm/kernel/calls.S   2011-10-24 18:44:54.000000000 +0200
1880 +++ linux-3.1-vs2.3.1-rc2/arch/arm/kernel/calls.S       2011-10-24 18:53:33.000000000 +0200
1881 @@ -322,7 +322,7 @@
1882  /* 310 */      CALL(sys_request_key)
1883                 CALL(sys_keyctl)
1884                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
1885 -/* vserver */  CALL(sys_ni_syscall)
1886 +               CALL(sys_vserver)
1887                 CALL(sys_ioprio_set)
1888  /* 315 */      CALL(sys_ioprio_get)
1889                 CALL(sys_inotify_init)
1890 diff -NurpP --minimal linux-3.1/arch/arm/kernel/process.c linux-3.1-vs2.3.1-rc2/arch/arm/kernel/process.c
1891 --- linux-3.1/arch/arm/kernel/process.c 2011-10-24 18:44:54.000000000 +0200
1892 +++ linux-3.1-vs2.3.1-rc2/arch/arm/kernel/process.c     2011-10-24 18:53:33.000000000 +0200
1893 @@ -317,7 +317,8 @@ void __show_regs(struct pt_regs *regs)
1894  void show_regs(struct pt_regs * regs)
1895  {
1896         printk("\n");
1897 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
1898 +       printk("Pid: %d[#%u], comm: %20s\n",
1899 +               task_pid_nr(current), current->xid, current->comm);
1900         __show_regs(regs);
1901         __backtrace();
1902  }
1903 diff -NurpP --minimal linux-3.1/arch/arm/kernel/traps.c linux-3.1-vs2.3.1-rc2/arch/arm/kernel/traps.c
1904 --- linux-3.1/arch/arm/kernel/traps.c   2011-10-24 18:44:54.000000000 +0200
1905 +++ linux-3.1-vs2.3.1-rc2/arch/arm/kernel/traps.c       2011-10-24 18:53:33.000000000 +0200
1906 @@ -242,8 +242,8 @@ static int __die(const char *str, int er
1907  
1908         print_modules();
1909         __show_regs(regs);
1910 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
1911 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
1912 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
1913 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
1914  
1915         if (!user_mode(regs) || in_interrupt()) {
1916                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
1917 diff -NurpP --minimal linux-3.1/arch/cris/Kconfig linux-3.1-vs2.3.1-rc2/arch/cris/Kconfig
1918 --- linux-3.1/arch/cris/Kconfig 2011-07-22 11:17:35.000000000 +0200
1919 +++ linux-3.1-vs2.3.1-rc2/arch/cris/Kconfig     2011-10-24 18:53:33.000000000 +0200
1920 @@ -678,6 +678,8 @@ source "drivers/staging/Kconfig"
1921  
1922  source "arch/cris/Kconfig.debug"
1923  
1924 +source "kernel/vserver/Kconfig"
1925 +
1926  source "security/Kconfig"
1927  
1928  source "crypto/Kconfig"
1929 diff -NurpP --minimal linux-3.1/arch/frv/kernel/kernel_thread.S linux-3.1-vs2.3.1-rc2/arch/frv/kernel/kernel_thread.S
1930 --- linux-3.1/arch/frv/kernel/kernel_thread.S   2008-12-25 00:26:37.000000000 +0100
1931 +++ linux-3.1-vs2.3.1-rc2/arch/frv/kernel/kernel_thread.S       2011-10-24 18:53:33.000000000 +0200
1932 @@ -37,7 +37,7 @@ kernel_thread:
1933  
1934         # start by forking the current process, but with shared VM
1935         setlos.p        #__NR_clone,gr7         ; syscall number
1936 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
1937 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
1938         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
1939         setlo           #0xe4e4,gr9
1940         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
1941 diff -NurpP --minimal linux-3.1/arch/h8300/Kconfig linux-3.1-vs2.3.1-rc2/arch/h8300/Kconfig
1942 --- linux-3.1/arch/h8300/Kconfig        2011-07-22 11:17:35.000000000 +0200
1943 +++ linux-3.1-vs2.3.1-rc2/arch/h8300/Kconfig    2011-10-24 18:53:33.000000000 +0200
1944 @@ -213,6 +213,8 @@ source "fs/Kconfig"
1945  
1946  source "arch/h8300/Kconfig.debug"
1947  
1948 +source "kernel/vserver/Kconfig"
1949 +
1950  source "security/Kconfig"
1951  
1952  source "crypto/Kconfig"
1953 diff -NurpP --minimal linux-3.1/arch/ia64/Kconfig linux-3.1-vs2.3.1-rc2/arch/ia64/Kconfig
1954 --- linux-3.1/arch/ia64/Kconfig 2011-10-24 18:44:58.000000000 +0200
1955 +++ linux-3.1-vs2.3.1-rc2/arch/ia64/Kconfig     2011-10-24 18:53:33.000000000 +0200
1956 @@ -657,6 +657,8 @@ source "fs/Kconfig"
1957  
1958  source "arch/ia64/Kconfig.debug"
1959  
1960 +source "kernel/vserver/Kconfig"
1961 +
1962  source "security/Kconfig"
1963  
1964  source "crypto/Kconfig"
1965 diff -NurpP --minimal linux-3.1/arch/ia64/include/asm/tlb.h linux-3.1-vs2.3.1-rc2/arch/ia64/include/asm/tlb.h
1966 --- linux-3.1/arch/ia64/include/asm/tlb.h       2011-07-22 11:17:35.000000000 +0200
1967 +++ linux-3.1-vs2.3.1-rc2/arch/ia64/include/asm/tlb.h   2011-10-24 18:53:33.000000000 +0200
1968 @@ -40,6 +40,7 @@
1969  #include <linux/mm.h>
1970  #include <linux/pagemap.h>
1971  #include <linux/swap.h>
1972 +#include <linux/vs_memory.h>
1973  
1974  #include <asm/pgalloc.h>
1975  #include <asm/processor.h>
1976 diff -NurpP --minimal linux-3.1/arch/ia64/kernel/entry.S linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/entry.S
1977 --- linux-3.1/arch/ia64/kernel/entry.S  2011-10-24 18:44:58.000000000 +0200
1978 +++ linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/entry.S      2011-10-24 18:53:33.000000000 +0200
1979 @@ -1714,7 +1714,7 @@ sys_call_table:
1980         data8 sys_mq_notify
1981         data8 sys_mq_getsetattr
1982         data8 sys_kexec_load
1983 -       data8 sys_ni_syscall                    // reserved for vserver
1984 +       data8 sys_vserver
1985         data8 sys_waitid                        // 1270
1986         data8 sys_add_key
1987         data8 sys_request_key
1988 diff -NurpP --minimal linux-3.1/arch/ia64/kernel/perfmon.c linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/perfmon.c
1989 --- linux-3.1/arch/ia64/kernel/perfmon.c        2011-03-15 18:06:39.000000000 +0100
1990 +++ linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/perfmon.c    2011-10-24 18:53:33.000000000 +0200
1991 @@ -42,6 +42,7 @@
1992  #include <linux/completion.h>
1993  #include <linux/tracehook.h>
1994  #include <linux/slab.h>
1995 +#include <linux/vs_memory.h>
1996  
1997  #include <asm/errno.h>
1998  #include <asm/intrinsics.h>
1999 diff -NurpP --minimal linux-3.1/arch/ia64/kernel/process.c linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/process.c
2000 --- linux-3.1/arch/ia64/kernel/process.c        2011-03-15 18:06:39.000000000 +0100
2001 +++ linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/process.c    2011-10-24 18:53:33.000000000 +0200
2002 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
2003         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
2004  
2005         print_modules();
2006 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
2007 -                       smp_processor_id(), current->comm);
2008 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
2009 +                       current->xid, smp_processor_id(), current->comm);
2010         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
2011                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
2012                init_utsname()->release);
2013 diff -NurpP --minimal linux-3.1/arch/ia64/kernel/ptrace.c linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/ptrace.c
2014 --- linux-3.1/arch/ia64/kernel/ptrace.c 2011-01-05 21:48:59.000000000 +0100
2015 +++ linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/ptrace.c     2011-10-24 18:53:33.000000000 +0200
2016 @@ -21,6 +21,7 @@
2017  #include <linux/regset.h>
2018  #include <linux/elf.h>
2019  #include <linux/tracehook.h>
2020 +#include <linux/vs_base.h>
2021  
2022  #include <asm/pgtable.h>
2023  #include <asm/processor.h>
2024 diff -NurpP --minimal linux-3.1/arch/ia64/kernel/traps.c linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/traps.c
2025 --- linux-3.1/arch/ia64/kernel/traps.c  2010-07-07 18:31:01.000000000 +0200
2026 +++ linux-3.1-vs2.3.1-rc2/arch/ia64/kernel/traps.c      2011-10-24 18:53:33.000000000 +0200
2027 @@ -59,8 +59,9 @@ die (const char *str, struct pt_regs *re
2028         put_cpu();
2029  
2030         if (++die.lock_owner_depth < 3) {
2031 -               printk("%s[%d]: %s %ld [%d]\n",
2032 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
2033 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
2034 +                       current->comm, task_pid_nr(current), current->xid,
2035 +                       str, err, ++die_counter);
2036                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
2037                     != NOTIFY_STOP)
2038                         show_regs(regs);
2039 @@ -323,8 +324,9 @@ handle_fpu_swa (int fp_fault, struct pt_
2040                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
2041                                 last.time = current_jiffies + 5 * HZ;
2042                                 printk(KERN_WARNING
2043 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
2044 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
2045 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
2046 +                                       current->comm, task_pid_nr(current), current->xid,
2047 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
2048                         }
2049                 }
2050         }
2051 diff -NurpP --minimal linux-3.1/arch/ia64/mm/fault.c linux-3.1-vs2.3.1-rc2/arch/ia64/mm/fault.c
2052 --- linux-3.1/arch/ia64/mm/fault.c      2011-07-22 11:17:35.000000000 +0200
2053 +++ linux-3.1-vs2.3.1-rc2/arch/ia64/mm/fault.c  2011-10-24 18:53:33.000000000 +0200
2054 @@ -11,6 +11,7 @@
2055  #include <linux/kprobes.h>
2056  #include <linux/kdebug.h>
2057  #include <linux/prefetch.h>
2058 +#include <linux/vs_memory.h>
2059  
2060  #include <asm/pgtable.h>
2061  #include <asm/processor.h>
2062 diff -NurpP --minimal linux-3.1/arch/m32r/kernel/traps.c linux-3.1-vs2.3.1-rc2/arch/m32r/kernel/traps.c
2063 --- linux-3.1/arch/m32r/kernel/traps.c  2011-10-24 18:44:58.000000000 +0200
2064 +++ linux-3.1-vs2.3.1-rc2/arch/m32r/kernel/traps.c      2011-10-24 18:53:33.000000000 +0200
2065 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
2066         } else {
2067                 printk("SPI: %08lx\n", sp);
2068         }
2069 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
2070 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
2071 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
2072 +               current->comm, task_pid_nr(current), current->xid,
2073 +               0xffff & i, 4096+(unsigned long)current);
2074  
2075         /*
2076          * When in-kernel, we also print out the stack and code at the
2077 diff -NurpP --minimal linux-3.1/arch/m68k/Kconfig linux-3.1-vs2.3.1-rc2/arch/m68k/Kconfig
2078 --- linux-3.1/arch/m68k/Kconfig 2011-10-24 18:44:58.000000000 +0200
2079 +++ linux-3.1-vs2.3.1-rc2/arch/m68k/Kconfig     2011-10-24 18:53:33.000000000 +0200
2080 @@ -246,6 +246,8 @@ source "fs/Kconfig"
2081  
2082  source "arch/m68k/Kconfig.debug"
2083  
2084 +source "kernel/vserver/Kconfig"
2085 +
2086  source "security/Kconfig"
2087  
2088  source "crypto/Kconfig"
2089 diff -NurpP --minimal linux-3.1/arch/mips/Kconfig linux-3.1-vs2.3.1-rc2/arch/mips/Kconfig
2090 --- linux-3.1/arch/mips/Kconfig 2011-10-24 18:44:59.000000000 +0200
2091 +++ linux-3.1-vs2.3.1-rc2/arch/mips/Kconfig     2011-10-24 18:53:33.000000000 +0200
2092 @@ -2495,6 +2495,8 @@ source "fs/Kconfig"
2093  
2094  source "arch/mips/Kconfig.debug"
2095  
2096 +source "kernel/vserver/Kconfig"
2097 +
2098  source "security/Kconfig"
2099  
2100  source "crypto/Kconfig"
2101 diff -NurpP --minimal linux-3.1/arch/mips/kernel/ptrace.c linux-3.1-vs2.3.1-rc2/arch/mips/kernel/ptrace.c
2102 --- linux-3.1/arch/mips/kernel/ptrace.c 2011-07-22 11:17:36.000000000 +0200
2103 +++ linux-3.1-vs2.3.1-rc2/arch/mips/kernel/ptrace.c     2011-10-24 18:53:33.000000000 +0200
2104 @@ -25,6 +25,7 @@
2105  #include <linux/security.h>
2106  #include <linux/audit.h>
2107  #include <linux/seccomp.h>
2108 +#include <linux/vs_base.h>
2109  
2110  #include <asm/byteorder.h>
2111  #include <asm/cpu.h>
2112 @@ -263,6 +264,9 @@ long arch_ptrace(struct task_struct *chi
2113         void __user *datavp = (void __user *) data;
2114         unsigned long __user *datalp = (void __user *) data;
2115  
2116 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
2117 +               goto out;
2118 +
2119         switch (request) {
2120         /* when I and D space are separate, these will need to be fixed. */
2121         case PTRACE_PEEKTEXT: /* read word at location addr. */
2122 diff -NurpP --minimal linux-3.1/arch/mips/kernel/scall32-o32.S linux-3.1-vs2.3.1-rc2/arch/mips/kernel/scall32-o32.S
2123 --- linux-3.1/arch/mips/kernel/scall32-o32.S    2011-10-24 18:44:59.000000000 +0200
2124 +++ linux-3.1-vs2.3.1-rc2/arch/mips/kernel/scall32-o32.S        2011-10-24 18:53:33.000000000 +0200
2125 @@ -523,7 +523,7 @@ einval:     li      v0, -ENOSYS
2126         sys     sys_mq_timedreceive     5
2127         sys     sys_mq_notify           2       /* 4275 */
2128         sys     sys_mq_getsetattr       3
2129 -       sys     sys_ni_syscall          0       /* sys_vserver */
2130 +       sys     sys_vserver             3
2131         sys     sys_waitid              5
2132         sys     sys_ni_syscall          0       /* available, was setaltroot */
2133         sys     sys_add_key             5       /* 4280 */
2134 diff -NurpP --minimal linux-3.1/arch/mips/kernel/scall64-64.S linux-3.1-vs2.3.1-rc2/arch/mips/kernel/scall64-64.S
2135 --- linux-3.1/arch/mips/kernel/scall64-64.S     2011-10-24 18:44:59.000000000 +0200
2136 +++ linux-3.1-vs2.3.1-rc2/arch/mips/kernel/scall64-64.S 2011-10-24 18:53:33.000000000 +0200
2137 @@ -362,7 +362,7 @@ sys_call_table:
2138         PTR     sys_mq_timedreceive
2139         PTR     sys_mq_notify
2140         PTR     sys_mq_getsetattr               /* 5235 */
2141 -       PTR     sys_ni_syscall                  /* sys_vserver */
2142 +       PTR     sys_vserver
2143         PTR     sys_waitid
2144         PTR     sys_ni_syscall                  /* available, was setaltroot */
2145         PTR     sys_add_key
2146 diff -NurpP --minimal linux-3.1/arch/mips/kernel/scall64-n32.S linux-3.1-vs2.3.1-rc2/arch/mips/kernel/scall64-n32.S
2147 --- linux-3.1/arch/mips/kernel/scall64-n32.S    2011-10-24 18:44:59.000000000 +0200
2148 +++ linux-3.1-vs2.3.1-rc2/arch/mips/kernel/scall64-n32.S        2011-10-24 18:53:33.000000000 +0200
2149 @@ -361,7 +361,7 @@ EXPORT(sysn32_call_table)
2150         PTR     compat_sys_mq_timedreceive
2151         PTR     compat_sys_mq_notify
2152         PTR     compat_sys_mq_getsetattr
2153 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
2154 +       PTR     sys32_vserver                   /* 6240 */
2155         PTR     compat_sys_waitid
2156         PTR     sys_ni_syscall                  /* available, was setaltroot */
2157         PTR     sys_add_key
2158 diff -NurpP --minimal linux-3.1/arch/mips/kernel/scall64-o32.S linux-3.1-vs2.3.1-rc2/arch/mips/kernel/scall64-o32.S
2159 --- linux-3.1/arch/mips/kernel/scall64-o32.S    2011-10-24 18:44:59.000000000 +0200
2160 +++ linux-3.1-vs2.3.1-rc2/arch/mips/kernel/scall64-o32.S        2011-10-24 18:53:33.000000000 +0200
2161 @@ -480,7 +480,7 @@ sys_call_table:
2162         PTR     compat_sys_mq_timedreceive
2163         PTR     compat_sys_mq_notify            /* 4275 */
2164         PTR     compat_sys_mq_getsetattr
2165 -       PTR     sys_ni_syscall                  /* sys_vserver */
2166 +       PTR     sys32_vserver
2167         PTR     sys_32_waitid
2168         PTR     sys_ni_syscall                  /* available, was setaltroot */
2169         PTR     sys_add_key                     /* 4280 */
2170 diff -NurpP --minimal linux-3.1/arch/mips/kernel/traps.c linux-3.1-vs2.3.1-rc2/arch/mips/kernel/traps.c
2171 --- linux-3.1/arch/mips/kernel/traps.c  2011-10-24 18:44:59.000000000 +0200
2172 +++ linux-3.1-vs2.3.1-rc2/arch/mips/kernel/traps.c      2011-10-24 18:53:33.000000000 +0200
2173 @@ -344,9 +344,10 @@ void show_registers(struct pt_regs *regs
2174  
2175         __show_regs(regs);
2176         print_modules();
2177 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
2178 -              current->comm, current->pid, current_thread_info(), current,
2179 -             field, current_thread_info()->tp_value);
2180 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
2181 +               current->comm, task_pid_nr(current), current->xid,
2182 +               current_thread_info(), current,
2183 +               field, current_thread_info()->tp_value);
2184         if (cpu_has_userlocal) {
2185                 unsigned long tls;
2186  
2187 diff -NurpP --minimal linux-3.1/arch/parisc/Kconfig linux-3.1-vs2.3.1-rc2/arch/parisc/Kconfig
2188 --- linux-3.1/arch/parisc/Kconfig       2011-10-24 18:44:59.000000000 +0200
2189 +++ linux-3.1-vs2.3.1-rc2/arch/parisc/Kconfig   2011-10-24 18:53:33.000000000 +0200
2190 @@ -280,6 +280,8 @@ source "fs/Kconfig"
2191  
2192  source "arch/parisc/Kconfig.debug"
2193  
2194 +source "kernel/vserver/Kconfig"
2195 +
2196  source "security/Kconfig"
2197  
2198  source "crypto/Kconfig"
2199 diff -NurpP --minimal linux-3.1/arch/parisc/kernel/syscall_table.S linux-3.1-vs2.3.1-rc2/arch/parisc/kernel/syscall_table.S
2200 --- linux-3.1/arch/parisc/kernel/syscall_table.S        2011-10-24 18:45:00.000000000 +0200
2201 +++ linux-3.1-vs2.3.1-rc2/arch/parisc/kernel/syscall_table.S    2011-10-24 18:53:33.000000000 +0200
2202 @@ -361,7 +361,7 @@
2203         ENTRY_COMP(mbind)               /* 260 */
2204         ENTRY_COMP(get_mempolicy)
2205         ENTRY_COMP(set_mempolicy)
2206 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
2207 +       ENTRY_DIFF(vserver)
2208         ENTRY_SAME(add_key)
2209         ENTRY_SAME(request_key)         /* 265 */
2210         ENTRY_SAME(keyctl)
2211 diff -NurpP --minimal linux-3.1/arch/parisc/kernel/traps.c linux-3.1-vs2.3.1-rc2/arch/parisc/kernel/traps.c
2212 --- linux-3.1/arch/parisc/kernel/traps.c        2011-10-24 18:45:00.000000000 +0200
2213 +++ linux-3.1-vs2.3.1-rc2/arch/parisc/kernel/traps.c    2011-10-24 18:53:33.000000000 +0200
2214 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
2215                 if (err == 0)
2216                         return; /* STFU */
2217  
2218 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
2219 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
2220 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
2221 +                       current->comm, task_pid_nr(current), current->xid,
2222 +                       str, err, regs->iaoq[0]);
2223  #ifdef PRINT_USER_FAULTS
2224                 /* XXX for debugging only */
2225                 show_regs(regs);
2226 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
2227                 pdc_console_restart();
2228         
2229         if (err)
2230 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
2231 -                       current->comm, task_pid_nr(current), str, err);
2232 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
2233 +                       current->comm, task_pid_nr(current), current->xid, str, err);
2234  
2235         /* Wot's wrong wif bein' racy? */
2236         if (current->thread.flags & PARISC_KERNEL_DEATH) {
2237 diff -NurpP --minimal linux-3.1/arch/parisc/mm/fault.c linux-3.1-vs2.3.1-rc2/arch/parisc/mm/fault.c
2238 --- linux-3.1/arch/parisc/mm/fault.c    2010-08-02 16:52:06.000000000 +0200
2239 +++ linux-3.1-vs2.3.1-rc2/arch/parisc/mm/fault.c        2011-10-24 18:53:33.000000000 +0200
2240 @@ -237,8 +237,9 @@ bad_area:
2241  
2242  #ifdef PRINT_USER_FAULTS
2243                 printk(KERN_DEBUG "\n");
2244 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
2245 -                   task_pid_nr(tsk), tsk->comm, code, address);
2246 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
2247 +                   "command='%s' type=%lu address=0x%08lx\n",
2248 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
2249                 if (vma) {
2250                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
2251                                         vma->vm_start, vma->vm_end);
2252 diff -NurpP --minimal linux-3.1/arch/powerpc/Kconfig linux-3.1-vs2.3.1-rc2/arch/powerpc/Kconfig
2253 --- linux-3.1/arch/powerpc/Kconfig      2011-10-24 18:45:00.000000000 +0200
2254 +++ linux-3.1-vs2.3.1-rc2/arch/powerpc/Kconfig  2011-10-24 18:53:33.000000000 +0200
2255 @@ -981,6 +981,8 @@ source "lib/Kconfig"
2256  
2257  source "arch/powerpc/Kconfig.debug"
2258  
2259 +source "kernel/vserver/Kconfig"
2260 +
2261  source "security/Kconfig"
2262  
2263  config KEYS_COMPAT
2264 diff -NurpP --minimal linux-3.1/arch/powerpc/include/asm/unistd.h linux-3.1-vs2.3.1-rc2/arch/powerpc/include/asm/unistd.h
2265 --- linux-3.1/arch/powerpc/include/asm/unistd.h 2011-07-22 11:17:40.000000000 +0200
2266 +++ linux-3.1-vs2.3.1-rc2/arch/powerpc/include/asm/unistd.h     2011-10-24 18:53:33.000000000 +0200
2267 @@ -275,7 +275,7 @@
2268  #endif
2269  #define __NR_rtas              255
2270  #define __NR_sys_debug_setcontext 256
2271 -/* Number 257 is reserved for vserver */
2272 +#define __NR_vserver           257
2273  #define __NR_migrate_pages     258
2274  #define __NR_mbind             259
2275  #define __NR_get_mempolicy     260
2276 diff -NurpP --minimal linux-3.1/arch/powerpc/kernel/process.c linux-3.1-vs2.3.1-rc2/arch/powerpc/kernel/process.c
2277 --- linux-3.1/arch/powerpc/kernel/process.c     2011-10-24 18:45:00.000000000 +0200
2278 +++ linux-3.1-vs2.3.1-rc2/arch/powerpc/kernel/process.c 2011-10-24 18:53:33.000000000 +0200
2279 @@ -662,8 +662,9 @@ void show_regs(struct pt_regs * regs)
2280  #else
2281                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
2282  #endif
2283 -       printk("TASK = %p[%d] '%s' THREAD: %p",
2284 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
2285 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
2286 +              current, task_pid_nr(current), current->xid,
2287 +              current->comm, task_thread_info(current));
2288  
2289  #ifdef CONFIG_SMP
2290         printk(" CPU: %d", raw_smp_processor_id());
2291 diff -NurpP --minimal linux-3.1/arch/powerpc/kernel/traps.c linux-3.1-vs2.3.1-rc2/arch/powerpc/kernel/traps.c
2292 --- linux-3.1/arch/powerpc/kernel/traps.c       2011-10-24 18:45:00.000000000 +0200
2293 +++ linux-3.1-vs2.3.1-rc2/arch/powerpc/kernel/traps.c   2011-10-24 18:53:33.000000000 +0200
2294 @@ -1075,8 +1075,9 @@ void nonrecoverable_exception(struct pt_
2295  
2296  void trace_syscall(struct pt_regs *regs)
2297  {
2298 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
2299 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
2300 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
2301 +              current, task_pid_nr(current), current->xid,
2302 +              regs->nip, regs->link, regs->gpr[0],
2303                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
2304  }
2305  
2306 diff -NurpP --minimal linux-3.1/arch/powerpc/kernel/vdso.c linux-3.1-vs2.3.1-rc2/arch/powerpc/kernel/vdso.c
2307 --- linux-3.1/arch/powerpc/kernel/vdso.c        2011-05-22 16:17:02.000000000 +0200
2308 +++ linux-3.1-vs2.3.1-rc2/arch/powerpc/kernel/vdso.c    2011-10-24 18:53:33.000000000 +0200
2309 @@ -23,6 +23,7 @@
2310  #include <linux/security.h>
2311  #include <linux/bootmem.h>
2312  #include <linux/memblock.h>
2313 +#include <linux/vs_memory.h>
2314  
2315  #include <asm/pgtable.h>
2316  #include <asm/system.h>
2317 diff -NurpP --minimal linux-3.1/arch/s390/Kconfig linux-3.1-vs2.3.1-rc2/arch/s390/Kconfig
2318 --- linux-3.1/arch/s390/Kconfig 2011-10-24 18:45:01.000000000 +0200
2319 +++ linux-3.1-vs2.3.1-rc2/arch/s390/Kconfig     2011-10-24 18:53:33.000000000 +0200
2320 @@ -629,6 +629,8 @@ source "fs/Kconfig"
2321  
2322  source "arch/s390/Kconfig.debug"
2323  
2324 +source "kernel/vserver/Kconfig"
2325 +
2326  source "security/Kconfig"
2327  
2328  source "crypto/Kconfig"
2329 diff -NurpP --minimal linux-3.1/arch/s390/include/asm/tlb.h linux-3.1-vs2.3.1-rc2/arch/s390/include/asm/tlb.h
2330 --- linux-3.1/arch/s390/include/asm/tlb.h       2011-07-22 11:17:41.000000000 +0200
2331 +++ linux-3.1-vs2.3.1-rc2/arch/s390/include/asm/tlb.h   2011-10-24 18:53:33.000000000 +0200
2332 @@ -24,6 +24,8 @@
2333  #include <linux/mm.h>
2334  #include <linux/pagemap.h>
2335  #include <linux/swap.h>
2336 +#include <linux/vs_memory.h>
2337 +
2338  #include <asm/processor.h>
2339  #include <asm/pgalloc.h>
2340  #include <asm/tlbflush.h>
2341 diff -NurpP --minimal linux-3.1/arch/s390/include/asm/unistd.h linux-3.1-vs2.3.1-rc2/arch/s390/include/asm/unistd.h
2342 --- linux-3.1/arch/s390/include/asm/unistd.h    2011-07-22 11:17:41.000000000 +0200
2343 +++ linux-3.1-vs2.3.1-rc2/arch/s390/include/asm/unistd.h        2011-10-24 18:53:33.000000000 +0200
2344 @@ -202,7 +202,7 @@
2345  #define __NR_clock_gettime     (__NR_timer_create+6)
2346  #define __NR_clock_getres      (__NR_timer_create+7)
2347  #define __NR_clock_nanosleep   (__NR_timer_create+8)
2348 -/* Number 263 is reserved for vserver */
2349 +#define __NR_vserver           263
2350  #define __NR_statfs64          265
2351  #define __NR_fstatfs64         266
2352  #define __NR_remap_file_pages  267
2353 diff -NurpP --minimal linux-3.1/arch/s390/kernel/ptrace.c linux-3.1-vs2.3.1-rc2/arch/s390/kernel/ptrace.c
2354 --- linux-3.1/arch/s390/kernel/ptrace.c 2011-03-15 18:06:45.000000000 +0100
2355 +++ linux-3.1-vs2.3.1-rc2/arch/s390/kernel/ptrace.c     2011-10-24 18:53:33.000000000 +0200
2356 @@ -20,6 +20,7 @@
2357  #include <linux/regset.h>
2358  #include <linux/tracehook.h>
2359  #include <linux/seccomp.h>
2360 +#include <linux/vs_base.h>
2361  #include <trace/syscall.h>
2362  #include <asm/compat.h>
2363  #include <asm/segment.h>
2364 diff -NurpP --minimal linux-3.1/arch/s390/kernel/syscalls.S linux-3.1-vs2.3.1-rc2/arch/s390/kernel/syscalls.S
2365 --- linux-3.1/arch/s390/kernel/syscalls.S       2011-10-24 18:45:01.000000000 +0200
2366 +++ linux-3.1-vs2.3.1-rc2/arch/s390/kernel/syscalls.S   2011-10-24 18:53:33.000000000 +0200
2367 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
2368  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
2369  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
2370  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
2371 -NI_SYSCALL                                                     /* reserved for vserver */
2372 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
2373  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
2374  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
2375  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
2376 diff -NurpP --minimal linux-3.1/arch/sh/Kconfig linux-3.1-vs2.3.1-rc2/arch/sh/Kconfig
2377 --- linux-3.1/arch/sh/Kconfig   2011-10-24 18:45:01.000000000 +0200
2378 +++ linux-3.1-vs2.3.1-rc2/arch/sh/Kconfig       2011-10-24 18:53:33.000000000 +0200
2379 @@ -894,6 +894,8 @@ source "fs/Kconfig"
2380  
2381  source "arch/sh/Kconfig.debug"
2382  
2383 +source "kernel/vserver/Kconfig"
2384 +
2385  source "security/Kconfig"
2386  
2387  source "crypto/Kconfig"
2388 diff -NurpP --minimal linux-3.1/arch/sh/kernel/irq.c linux-3.1-vs2.3.1-rc2/arch/sh/kernel/irq.c
2389 --- linux-3.1/arch/sh/kernel/irq.c      2011-07-22 11:17:41.000000000 +0200
2390 +++ linux-3.1-vs2.3.1-rc2/arch/sh/kernel/irq.c  2011-10-24 18:53:33.000000000 +0200
2391 @@ -14,6 +14,7 @@
2392  #include <linux/ftrace.h>
2393  #include <linux/delay.h>
2394  #include <linux/ratelimit.h>
2395 +// #include <linux/vs_context.h>
2396  #include <asm/processor.h>
2397  #include <asm/machvec.h>
2398  #include <asm/uaccess.h>
2399 diff -NurpP --minimal linux-3.1/arch/sh/kernel/vsyscall/vsyscall.c linux-3.1-vs2.3.1-rc2/arch/sh/kernel/vsyscall/vsyscall.c
2400 --- linux-3.1/arch/sh/kernel/vsyscall/vsyscall.c        2011-05-22 16:17:07.000000000 +0200
2401 +++ linux-3.1-vs2.3.1-rc2/arch/sh/kernel/vsyscall/vsyscall.c    2011-10-24 18:53:33.000000000 +0200
2402 @@ -18,6 +18,7 @@
2403  #include <linux/elf.h>
2404  #include <linux/sched.h>
2405  #include <linux/err.h>
2406 +#include <linux/vs_memory.h>
2407  
2408  /*
2409   * Should the kernel map a VDSO page into processes and pass its
2410 diff -NurpP --minimal linux-3.1/arch/sparc/Kconfig linux-3.1-vs2.3.1-rc2/arch/sparc/Kconfig
2411 --- linux-3.1/arch/sparc/Kconfig        2011-10-24 18:45:02.000000000 +0200
2412 +++ linux-3.1-vs2.3.1-rc2/arch/sparc/Kconfig    2011-10-24 18:53:33.000000000 +0200
2413 @@ -600,6 +600,8 @@ source "fs/Kconfig"
2414  
2415  source "arch/sparc/Kconfig.debug"
2416  
2417 +source "kernel/vserver/Kconfig"
2418 +
2419  source "security/Kconfig"
2420  
2421  source "crypto/Kconfig"
2422 diff -NurpP --minimal linux-3.1/arch/sparc/include/asm/tlb_64.h linux-3.1-vs2.3.1-rc2/arch/sparc/include/asm/tlb_64.h
2423 --- linux-3.1/arch/sparc/include/asm/tlb_64.h   2011-07-22 11:17:42.000000000 +0200
2424 +++ linux-3.1-vs2.3.1-rc2/arch/sparc/include/asm/tlb_64.h       2011-10-24 18:53:33.000000000 +0200
2425 @@ -3,6 +3,7 @@
2426  
2427  #include <linux/swap.h>
2428  #include <linux/pagemap.h>
2429 +#include <linux/vs_memory.h>
2430  #include <asm/pgalloc.h>
2431  #include <asm/tlbflush.h>
2432  #include <asm/mmu_context.h>
2433 diff -NurpP --minimal linux-3.1/arch/sparc/include/asm/unistd.h linux-3.1-vs2.3.1-rc2/arch/sparc/include/asm/unistd.h
2434 --- linux-3.1/arch/sparc/include/asm/unistd.h   2011-07-22 11:17:42.000000000 +0200
2435 +++ linux-3.1-vs2.3.1-rc2/arch/sparc/include/asm/unistd.h       2011-10-24 18:53:33.000000000 +0200
2436 @@ -335,7 +335,7 @@
2437  #define __NR_timer_getoverrun  264
2438  #define __NR_timer_delete      265
2439  #define __NR_timer_create      266
2440 -/* #define __NR_vserver                267 Reserved for VSERVER */
2441 +#define __NR_vserver           267
2442  #define __NR_io_setup          268
2443  #define __NR_io_destroy                269
2444  #define __NR_io_submit         270
2445 diff -NurpP --minimal linux-3.1/arch/sparc/kernel/systbls_32.S linux-3.1-vs2.3.1-rc2/arch/sparc/kernel/systbls_32.S
2446 --- linux-3.1/arch/sparc/kernel/systbls_32.S    2011-10-24 18:45:02.000000000 +0200
2447 +++ linux-3.1-vs2.3.1-rc2/arch/sparc/kernel/systbls_32.S        2011-10-24 18:53:33.000000000 +0200
2448 @@ -70,7 +70,7 @@ sys_call_table:
2449  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
2450  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
2451  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
2452 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
2453 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
2454  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
2455  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
2456  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
2457 diff -NurpP --minimal linux-3.1/arch/sparc/kernel/systbls_64.S linux-3.1-vs2.3.1-rc2/arch/sparc/kernel/systbls_64.S
2458 --- linux-3.1/arch/sparc/kernel/systbls_64.S    2011-10-24 18:45:02.000000000 +0200
2459 +++ linux-3.1-vs2.3.1-rc2/arch/sparc/kernel/systbls_64.S        2011-10-24 18:53:33.000000000 +0200
2460 @@ -71,7 +71,7 @@ sys_call_table32:
2461  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys_nis_syscall
2462         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
2463  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
2464 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
2465 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
2466  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
2467         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
2468  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
2469 @@ -148,7 +148,7 @@ sys_call_table:
2470  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
2471         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
2472  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
2473 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
2474 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
2475  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
2476         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
2477  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
2478 diff -NurpP --minimal linux-3.1/arch/um/Kconfig.rest linux-3.1-vs2.3.1-rc2/arch/um/Kconfig.rest
2479 --- linux-3.1/arch/um/Kconfig.rest      2009-06-11 17:12:19.000000000 +0200
2480 +++ linux-3.1-vs2.3.1-rc2/arch/um/Kconfig.rest  2011-10-24 18:53:33.000000000 +0200
2481 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
2482  
2483  source "fs/Kconfig"
2484  
2485 +source "kernel/vserver/Kconfig"
2486 +
2487  source "security/Kconfig"
2488  
2489  source "crypto/Kconfig"
2490 diff -NurpP --minimal linux-3.1/arch/um/include/asm/tlb.h linux-3.1-vs2.3.1-rc2/arch/um/include/asm/tlb.h
2491 --- linux-3.1/arch/um/include/asm/tlb.h 2011-07-22 11:17:42.000000000 +0200
2492 +++ linux-3.1-vs2.3.1-rc2/arch/um/include/asm/tlb.h     2011-10-24 18:53:33.000000000 +0200
2493 @@ -3,6 +3,7 @@
2494  
2495  #include <linux/pagemap.h>
2496  #include <linux/swap.h>
2497 +#include <linux/vs_memory.h>
2498  #include <asm/percpu.h>
2499  #include <asm/pgalloc.h>
2500  #include <asm/tlbflush.h>
2501 diff -NurpP --minimal linux-3.1/arch/um/include/shared/kern_constants.h linux-3.1-vs2.3.1-rc2/arch/um/include/shared/kern_constants.h
2502 --- linux-3.1/arch/um/include/shared/kern_constants.h   1970-01-01 01:00:00.000000000 +0100
2503 +++ linux-3.1-vs2.3.1-rc2/arch/um/include/shared/kern_constants.h       2011-10-24 18:53:33.000000000 +0200
2504 @@ -0,0 +1 @@
2505 +#include "../../../../include/generated/asm-offsets.h"
2506 diff -NurpP --minimal linux-3.1/arch/um/include/shared/user_constants.h linux-3.1-vs2.3.1-rc2/arch/um/include/shared/user_constants.h
2507 --- linux-3.1/arch/um/include/shared/user_constants.h   1970-01-01 01:00:00.000000000 +0100
2508 +++ linux-3.1-vs2.3.1-rc2/arch/um/include/shared/user_constants.h       2011-10-24 18:53:33.000000000 +0200
2509 @@ -0,0 +1,40 @@
2510 +/*
2511 + * DO NOT MODIFY.
2512 + *
2513 + * This file was generated by arch/um/Makefile
2514 + *
2515 + */
2516 +
2517 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
2518 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
2519 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
2520 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
2521 +#define HOST_RBX 5 /* RBX      # */
2522 +#define HOST_RCX 11 /* RCX     # */
2523 +#define HOST_RDI 14 /* RDI     # */
2524 +#define HOST_RSI 13 /* RSI     # */
2525 +#define HOST_RDX 12 /* RDX     # */
2526 +#define HOST_RBP 4 /* RBP      # */
2527 +#define HOST_RAX 10 /* RAX     # */
2528 +#define HOST_R8 9 /* R8        # */
2529 +#define HOST_R9 8 /* R9        # */
2530 +#define HOST_R10 7 /* R10      # */
2531 +#define HOST_R11 6 /* R11      # */
2532 +#define HOST_R12 3 /* R12      # */
2533 +#define HOST_R13 2 /* R13      # */
2534 +#define HOST_R14 1 /* R14      # */
2535 +#define HOST_R15 0 /* R15      # */
2536 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
2537 +#define HOST_CS 17 /* CS       # */
2538 +#define HOST_SS 20 /* SS       # */
2539 +#define HOST_EFLAGS 18 /* EFLAGS       # */
2540 +#define HOST_IP 16 /* RIP      # */
2541 +#define HOST_SP 19 /* RSP      # */
2542 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
2543 +#define UM_POLLIN 1 /* POLLIN  # */
2544 +#define UM_POLLPRI 2 /* POLLPRI        # */
2545 +#define UM_POLLOUT 4 /* POLLOUT        # */
2546 +#define UM_PROT_READ 1 /* PROT_READ    # */
2547 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
2548 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
2549 +
2550 diff -NurpP --minimal linux-3.1/arch/x86/Kconfig linux-3.1-vs2.3.1-rc2/arch/x86/Kconfig
2551 --- linux-3.1/arch/x86/Kconfig  2011-10-24 18:45:06.000000000 +0200
2552 +++ linux-3.1-vs2.3.1-rc2/arch/x86/Kconfig      2011-10-24 18:53:33.000000000 +0200
2553 @@ -2144,6 +2144,8 @@ source "fs/Kconfig"
2554  
2555  source "arch/x86/Kconfig.debug"
2556  
2557 +source "kernel/vserver/Kconfig"
2558 +
2559  source "security/Kconfig"
2560  
2561  source "crypto/Kconfig"
2562 diff -NurpP --minimal linux-3.1/arch/x86/ia32/ia32entry.S linux-3.1-vs2.3.1-rc2/arch/x86/ia32/ia32entry.S
2563 --- linux-3.1/arch/x86/ia32/ia32entry.S 2011-10-24 18:45:06.000000000 +0200
2564 +++ linux-3.1-vs2.3.1-rc2/arch/x86/ia32/ia32entry.S     2011-10-24 18:53:33.000000000 +0200
2565 @@ -776,7 +776,7 @@ ia32_sys_call_table:
2566         .quad sys_tgkill                /* 270 */
2567         .quad compat_sys_utimes
2568         .quad sys32_fadvise64_64
2569 -       .quad quiet_ni_syscall  /* sys_vserver */
2570 +       .quad sys32_vserver
2571         .quad sys_mbind
2572         .quad compat_sys_get_mempolicy  /* 275 */
2573         .quad sys_set_mempolicy
2574 diff -NurpP --minimal linux-3.1/arch/x86/include/asm/unistd_64.h linux-3.1-vs2.3.1-rc2/arch/x86/include/asm/unistd_64.h
2575 --- linux-3.1/arch/x86/include/asm/unistd_64.h  2011-10-24 18:45:07.000000000 +0200
2576 +++ linux-3.1-vs2.3.1-rc2/arch/x86/include/asm/unistd_64.h      2011-10-24 18:53:33.000000000 +0200
2577 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
2578  #define __NR_utimes                            235
2579  __SYSCALL(__NR_utimes, sys_utimes)
2580  #define __NR_vserver                           236
2581 -__SYSCALL(__NR_vserver, sys_ni_syscall)
2582 +__SYSCALL(__NR_vserver, sys_vserver)
2583  #define __NR_mbind                             237
2584  __SYSCALL(__NR_mbind, sys_mbind)
2585  #define __NR_set_mempolicy                     238
2586 diff -NurpP --minimal linux-3.1/arch/x86/kernel/syscall_table_32.S linux-3.1-vs2.3.1-rc2/arch/x86/kernel/syscall_table_32.S
2587 --- linux-3.1/arch/x86/kernel/syscall_table_32.S        2011-10-24 18:45:07.000000000 +0200
2588 +++ linux-3.1-vs2.3.1-rc2/arch/x86/kernel/syscall_table_32.S    2011-10-24 18:53:33.000000000 +0200
2589 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
2590         .long sys_tgkill        /* 270 */
2591         .long sys_utimes
2592         .long sys_fadvise64_64
2593 -       .long sys_ni_syscall    /* sys_vserver */
2594 +       .long sys_vserver
2595         .long sys_mbind
2596         .long sys_get_mempolicy
2597         .long sys_set_mempolicy
2598 diff -NurpP --minimal linux-3.1/drivers/block/Kconfig linux-3.1-vs2.3.1-rc2/drivers/block/Kconfig
2599 --- linux-3.1/drivers/block/Kconfig     2011-10-24 18:45:08.000000000 +0200
2600 +++ linux-3.1-vs2.3.1-rc2/drivers/block/Kconfig 2011-10-24 18:53:33.000000000 +0200
2601 @@ -288,6 +288,13 @@ config BLK_DEV_CRYPTOLOOP
2602  
2603  source "drivers/block/drbd/Kconfig"
2604  
2605 +config BLK_DEV_VROOT
2606 +       tristate "Virtual Root device support"
2607 +       depends on QUOTACTL
2608 +       ---help---
2609 +         Saying Y here will allow you to use quota/fs ioctls on a shared
2610 +         partition within a virtual server without compromising security.
2611 +
2612  config BLK_DEV_NBD
2613         tristate "Network block device support"
2614         depends on NET
2615 diff -NurpP --minimal linux-3.1/drivers/block/Makefile linux-3.1-vs2.3.1-rc2/drivers/block/Makefile
2616 --- linux-3.1/drivers/block/Makefile    2011-07-22 11:17:44.000000000 +0200
2617 +++ linux-3.1-vs2.3.1-rc2/drivers/block/Makefile        2011-10-24 18:53:33.000000000 +0200
2618 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
2619  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
2620  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
2621  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
2622 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
2623  
2624  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
2625  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
2626 diff -NurpP --minimal linux-3.1/drivers/block/loop.c linux-3.1-vs2.3.1-rc2/drivers/block/loop.c
2627 --- linux-3.1/drivers/block/loop.c      2011-10-24 18:45:08.000000000 +0200
2628 +++ linux-3.1-vs2.3.1-rc2/drivers/block/loop.c  2011-10-24 18:53:33.000000000 +0200
2629 @@ -76,6 +76,7 @@
2630  #include <linux/splice.h>
2631  #include <linux/sysfs.h>
2632  #include <linux/miscdevice.h>
2633 +#include <linux/vs_context.h>
2634  #include <asm/uaccess.h>
2635  
2636  static DEFINE_IDR(loop_index_idr);
2637 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
2638         lo->lo_blocksize = lo_blocksize;
2639         lo->lo_device = bdev;
2640         lo->lo_flags = lo_flags;
2641 +       lo->lo_xid = vx_current_xid();
2642         lo->lo_backing_file = file;
2643         lo->transfer = transfer_none;
2644         lo->ioctl = NULL;
2645 @@ -1014,6 +1016,7 @@ static int loop_clr_fd(struct loop_devic
2646         lo->lo_encrypt_key_size = 0;
2647         lo->lo_flags = 0;
2648         lo->lo_thread = NULL;
2649 +       lo->lo_xid = 0;
2650         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
2651         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
2652         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
2653 @@ -1052,7 +1055,7 @@ loop_set_status(struct loop_device *lo, 
2654  
2655         if (lo->lo_encrypt_key_size &&
2656             lo->lo_key_owner != uid &&
2657 -           !capable(CAP_SYS_ADMIN))
2658 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
2659                 return -EPERM;
2660         if (lo->lo_state != Lo_bound)
2661                 return -ENXIO;
2662 @@ -1136,7 +1139,8 @@ loop_get_status(struct loop_device *lo, 
2663         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
2664         info->lo_encrypt_type =
2665                 lo->lo_encryption ? lo->lo_encryption->number : 0;
2666 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
2667 +       if (lo->lo_encrypt_key_size &&
2668 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
2669                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
2670                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
2671                        lo->lo_encrypt_key_size);
2672 @@ -1490,6 +1494,9 @@ static int lo_open(struct block_device *
2673                 goto out;
2674         }
2675  
2676 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
2677 +               return -EACCES;
2678 +
2679         mutex_lock(&lo->lo_ctl_mutex);
2680         lo->lo_refcnt++;
2681         mutex_unlock(&lo->lo_ctl_mutex);
2682 diff -NurpP --minimal linux-3.1/drivers/block/vroot.c linux-3.1-vs2.3.1-rc2/drivers/block/vroot.c
2683 --- linux-3.1/drivers/block/vroot.c     1970-01-01 01:00:00.000000000 +0100
2684 +++ linux-3.1-vs2.3.1-rc2/drivers/block/vroot.c 2011-10-24 18:53:33.000000000 +0200
2685 @@ -0,0 +1,292 @@
2686 +/*
2687 + *  linux/drivers/block/vroot.c
2688 + *
2689 + *  written by Herbert Pötzl, 9/11/2002
2690 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
2691 + *
2692 + *  based on the loop.c code by Theodore Ts'o.
2693 + *
2694 + * Copyright (C) 2002-2007 by Herbert Pötzl.
2695 + * Redistribution of this file is permitted under the
2696 + * GNU General Public License.
2697 + *
2698 + */
2699 +
2700 +#include <linux/module.h>
2701 +#include <linux/moduleparam.h>
2702 +#include <linux/file.h>
2703 +#include <linux/major.h>
2704 +#include <linux/blkdev.h>
2705 +#include <linux/slab.h>
2706 +
2707 +#include <linux/vroot.h>
2708 +#include <linux/vs_context.h>
2709 +
2710 +
2711 +static int max_vroot = 8;
2712 +
2713 +static struct vroot_device *vroot_dev;
2714 +static struct gendisk **disks;
2715 +
2716 +
2717 +static int vroot_set_dev(
2718 +       struct vroot_device *vr,
2719 +       struct block_device *bdev,
2720 +       unsigned int arg)
2721 +{
2722 +       struct block_device *real_bdev;
2723 +       struct file *file;
2724 +       struct inode *inode;
2725 +       int error;
2726 +
2727 +       error = -EBUSY;
2728 +       if (vr->vr_state != Vr_unbound)
2729 +               goto out;
2730 +
2731 +       error = -EBADF;
2732 +       file = fget(arg);
2733 +       if (!file)
2734 +               goto out;
2735 +
2736 +       error = -EINVAL;
2737 +       inode = file->f_dentry->d_inode;
2738 +
2739 +
2740 +       if (S_ISBLK(inode->i_mode)) {
2741 +               real_bdev = inode->i_bdev;
2742 +               vr->vr_device = real_bdev;
2743 +               __iget(real_bdev->bd_inode);
2744 +       } else
2745 +               goto out_fput;
2746 +
2747 +       vxdprintk(VXD_CBIT(misc, 0),
2748 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
2749 +               vr->vr_number, VXD_DEV(real_bdev));
2750 +
2751 +       vr->vr_state = Vr_bound;
2752 +       error = 0;
2753 +
2754 + out_fput:
2755 +       fput(file);
2756 + out:
2757 +       return error;
2758 +}
2759 +
2760 +static int vroot_clr_dev(
2761 +       struct vroot_device *vr,
2762 +       struct block_device *bdev)
2763 +{
2764 +       struct block_device *real_bdev;
2765 +
2766 +       if (vr->vr_state != Vr_bound)
2767 +               return -ENXIO;
2768 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
2769 +               return -EBUSY;
2770 +
2771 +       real_bdev = vr->vr_device;
2772 +
2773 +       vxdprintk(VXD_CBIT(misc, 0),
2774 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
2775 +               vr->vr_number, VXD_DEV(real_bdev));
2776 +
2777 +       bdput(real_bdev);
2778 +       vr->vr_state = Vr_unbound;
2779 +       vr->vr_device = NULL;
2780 +       return 0;
2781 +}
2782 +
2783 +
2784 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
2785 +       unsigned int cmd, unsigned long arg)
2786 +{
2787 +       struct vroot_device *vr = bdev->bd_disk->private_data;
2788 +       int err;
2789 +
2790 +       down(&vr->vr_ctl_mutex);
2791 +       switch (cmd) {
2792 +       case VROOT_SET_DEV:
2793 +               err = vroot_set_dev(vr, bdev, arg);
2794 +               break;
2795 +       case VROOT_CLR_DEV:
2796 +               err = vroot_clr_dev(vr, bdev);
2797 +               break;
2798 +       default:
2799 +               err = -EINVAL;
2800 +               break;
2801 +       }
2802 +       up(&vr->vr_ctl_mutex);
2803 +       return err;
2804 +}
2805 +
2806 +static int vr_open(struct block_device *bdev, fmode_t mode)
2807 +{
2808 +       struct vroot_device *vr = bdev->bd_disk->private_data;
2809 +
2810 +       down(&vr->vr_ctl_mutex);
2811 +       vr->vr_refcnt++;
2812 +       up(&vr->vr_ctl_mutex);
2813 +       return 0;
2814 +}
2815 +
2816 +static int vr_release(struct gendisk *disk, fmode_t mode)
2817 +{
2818 +       struct vroot_device *vr = disk->private_data;
2819 +
2820 +       down(&vr->vr_ctl_mutex);
2821 +       --vr->vr_refcnt;
2822 +       up(&vr->vr_ctl_mutex);
2823 +       return 0;
2824 +}
2825 +
2826 +static struct block_device_operations vr_fops = {
2827 +       .owner =        THIS_MODULE,
2828 +       .open =         vr_open,
2829 +       .release =      vr_release,
2830 +       .ioctl =        vr_ioctl,
2831 +};
2832 +
2833 +static int vroot_make_request(struct request_queue *q, struct bio *bio)
2834 +{
2835 +       printk("vroot_make_request %p, %p\n", q, bio);
2836 +       bio_io_error(bio);
2837 +       return 0;
2838 +}
2839 +
2840 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
2841 +{
2842 +       struct inode *inode = bdev->bd_inode;
2843 +       struct vroot_device *vr;
2844 +       struct block_device *real_bdev;
2845 +       int minor = iminor(inode);
2846 +
2847 +       vr = &vroot_dev[minor];
2848 +       real_bdev = vr->vr_device;
2849 +
2850 +       vxdprintk(VXD_CBIT(misc, 0),
2851 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
2852 +               vr->vr_number, VXD_DEV(real_bdev));
2853 +
2854 +       if (vr->vr_state != Vr_bound)
2855 +               return ERR_PTR(-ENXIO);
2856 +
2857 +       __iget(real_bdev->bd_inode);
2858 +       return real_bdev;
2859 +}
2860 +
2861 +
2862 +
2863 +/*
2864 + * And now the modules code and kernel interface.
2865 + */
2866 +
2867 +module_param(max_vroot, int, 0);
2868 +
2869 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
2870 +MODULE_LICENSE("GPL");
2871 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
2872 +
2873 +MODULE_AUTHOR ("Herbert Pötzl");
2874 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
2875 +
2876 +
2877 +int __init vroot_init(void)
2878 +{
2879 +       int err, i;
2880 +
2881 +       if (max_vroot < 1 || max_vroot > 256) {
2882 +               max_vroot = MAX_VROOT_DEFAULT;
2883 +               printk(KERN_WARNING "vroot: invalid max_vroot "
2884 +                       "(must be between 1 and 256), "
2885 +                       "using default (%d)\n", max_vroot);
2886 +       }
2887 +
2888 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
2889 +               return -EIO;
2890 +
2891 +       err = -ENOMEM;
2892 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
2893 +       if (!vroot_dev)
2894 +               goto out_mem1;
2895 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
2896 +
2897 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
2898 +       if (!disks)
2899 +               goto out_mem2;
2900 +
2901 +       for (i = 0; i < max_vroot; i++) {
2902 +               disks[i] = alloc_disk(1);
2903 +               if (!disks[i])
2904 +                       goto out_mem3;
2905 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
2906 +               if (!disks[i]->queue)
2907 +                       goto out_mem3;
2908 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
2909 +       }
2910 +
2911 +       for (i = 0; i < max_vroot; i++) {
2912 +               struct vroot_device *vr = &vroot_dev[i];
2913 +               struct gendisk *disk = disks[i];
2914 +
2915 +               memset(vr, 0, sizeof(*vr));
2916 +               sema_init(&vr->vr_ctl_mutex, 1);
2917 +               vr->vr_number = i;
2918 +               disk->major = VROOT_MAJOR;
2919 +               disk->first_minor = i;
2920 +               disk->fops = &vr_fops;
2921 +               sprintf(disk->disk_name, "vroot%d", i);
2922 +               disk->private_data = vr;
2923 +       }
2924 +
2925 +       err = register_vroot_grb(&__vroot_get_real_bdev);
2926 +       if (err)
2927 +               goto out_mem3;
2928 +
2929 +       for (i = 0; i < max_vroot; i++)
2930 +               add_disk(disks[i]);
2931 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
2932 +       return 0;
2933 +
2934 +out_mem3:
2935 +       while (i--)
2936 +               put_disk(disks[i]);
2937 +       kfree(disks);
2938 +out_mem2:
2939 +       kfree(vroot_dev);
2940 +out_mem1:
2941 +       unregister_blkdev(VROOT_MAJOR, "vroot");
2942 +       printk(KERN_ERR "vroot: ran out of memory\n");
2943 +       return err;
2944 +}
2945 +
2946 +void vroot_exit(void)
2947 +{
2948 +       int i;
2949 +
2950 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
2951 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
2952 +
2953 +       for (i = 0; i < max_vroot; i++) {
2954 +               del_gendisk(disks[i]);
2955 +               put_disk(disks[i]);
2956 +       }
2957 +       unregister_blkdev(VROOT_MAJOR, "vroot");
2958 +
2959 +       kfree(disks);
2960 +       kfree(vroot_dev);
2961 +}
2962 +
2963 +module_init(vroot_init);
2964 +module_exit(vroot_exit);
2965 +
2966 +#ifndef MODULE
2967 +
2968 +static int __init max_vroot_setup(char *str)
2969 +{
2970 +       max_vroot = simple_strtol(str, NULL, 0);
2971 +       return 1;
2972 +}
2973 +
2974 +__setup("max_vroot=", max_vroot_setup);
2975 +
2976 +#endif
2977 +
2978 diff -NurpP --minimal linux-3.1/drivers/infiniband/core/addr.c linux-3.1-vs2.3.1-rc2/drivers/infiniband/core/addr.c
2979 --- linux-3.1/drivers/infiniband/core/addr.c    2011-10-24 18:45:09.000000000 +0200
2980 +++ linux-3.1-vs2.3.1-rc2/drivers/infiniband/core/addr.c        2011-10-24 18:53:33.000000000 +0200
2981 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
2982  
2983         if (ipv6_addr_any(&fl6.saddr)) {
2984                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
2985 -                                        &fl6.daddr, 0, &fl6.saddr);
2986 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
2987                 if (ret)
2988                         goto put;
2989  
2990 diff -NurpP --minimal linux-3.1/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-3.1-vs2.3.1-rc2/drivers/infiniband/hw/ipath/ipath_user_pages.c
2991 --- linux-3.1/drivers/infiniband/hw/ipath/ipath_user_pages.c    2011-05-22 16:17:16.000000000 +0200
2992 +++ linux-3.1-vs2.3.1-rc2/drivers/infiniband/hw/ipath/ipath_user_pages.c        2011-10-24 18:53:33.000000000 +0200
2993 @@ -35,6 +35,7 @@
2994  #include <linux/device.h>
2995  #include <linux/slab.h>
2996  #include <linux/sched.h>
2997 +#include <linux/vs_memory.h>
2998  
2999  #include "ipath_kernel.h"
3000  
3001 diff -NurpP --minimal linux-3.1/drivers/md/dm-ioctl.c linux-3.1-vs2.3.1-rc2/drivers/md/dm-ioctl.c
3002 --- linux-3.1/drivers/md/dm-ioctl.c     2011-10-24 18:45:10.000000000 +0200
3003 +++ linux-3.1-vs2.3.1-rc2/drivers/md/dm-ioctl.c 2011-10-24 18:53:33.000000000 +0200
3004 @@ -16,6 +16,7 @@
3005  #include <linux/dm-ioctl.h>
3006  #include <linux/hdreg.h>
3007  #include <linux/compat.h>
3008 +#include <linux/vs_context.h>
3009  
3010  #include <asm/uaccess.h>
3011  
3012 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
3013         unsigned int h = hash_str(str);
3014  
3015         list_for_each_entry (hc, _name_buckets + h, name_list)
3016 -               if (!strcmp(hc->name, str)) {
3017 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
3018 +                       !strcmp(hc->name, str)) {
3019                         dm_get(hc->md);
3020                         return hc;
3021                 }
3022 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
3023         unsigned int h = hash_str(str);
3024  
3025         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
3026 -               if (!strcmp(hc->uuid, str)) {
3027 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
3028 +                       !strcmp(hc->uuid, str)) {
3029                         dm_get(hc->md);
3030                         return hc;
3031                 }
3032 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
3033  static struct hash_cell *__get_dev_cell(uint64_t dev)
3034  {
3035         struct mapped_device *md;
3036 -       struct hash_cell *hc;
3037 +       struct hash_cell *hc = NULL;
3038  
3039         md = dm_get_md(huge_decode_dev(dev));
3040         if (!md)
3041                 return NULL;
3042  
3043 -       hc = dm_get_mdptr(md);
3044 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
3045 +               hc = dm_get_mdptr(md);
3046 +
3047         if (!hc) {
3048                 dm_put(md);
3049                 return NULL;
3050 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
3051  
3052  static int remove_all(struct dm_ioctl *param, size_t param_size)
3053  {
3054 +       if (!vx_check(0, VS_ADMIN))
3055 +               return -EPERM;
3056 +
3057         dm_hash_remove_all(1);
3058         param->data_size = 0;
3059         return 0;
3060 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl 
3061          */
3062         for (i = 0; i < NUM_BUCKETS; i++) {
3063                 list_for_each_entry (hc, _name_buckets + i, name_list) {
3064 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
3065 +                               continue;
3066                         needed += sizeof(struct dm_name_list);
3067                         needed += strlen(hc->name) + 1;
3068                         needed += ALIGN_MASK;
3069 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl 
3070          */
3071         for (i = 0; i < NUM_BUCKETS; i++) {
3072                 list_for_each_entry (hc, _name_buckets + i, name_list) {
3073 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
3074 +                               continue;
3075                         if (old_nl)
3076                                 old_nl->next = (uint32_t) ((void *) nl -
3077                                                            (void *) old_nl);
3078 @@ -1604,8 +1616,8 @@ static int ctl_ioctl(uint command, struc
3079         ioctl_fn fn = NULL;
3080         size_t input_param_size;
3081  
3082 -       /* only root can play with this */
3083 -       if (!capable(CAP_SYS_ADMIN))
3084 +       /* only root and certain contexts can play with this */
3085 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
3086                 return -EACCES;
3087  
3088         if (_IOC_TYPE(command) != DM_IOCTL)
3089 diff -NurpP --minimal linux-3.1/drivers/md/dm.c linux-3.1-vs2.3.1-rc2/drivers/md/dm.c
3090 --- linux-3.1/drivers/md/dm.c   2011-10-24 18:45:10.000000000 +0200
3091 +++ linux-3.1-vs2.3.1-rc2/drivers/md/dm.c       2011-10-24 18:53:33.000000000 +0200
3092 @@ -20,6 +20,7 @@
3093  #include <linux/idr.h>
3094  #include <linux/hdreg.h>
3095  #include <linux/delay.h>
3096 +#include <linux/vs_base.h>
3097  
3098  #include <trace/events/block.h>
3099  
3100 @@ -122,6 +123,7 @@ struct mapped_device {
3101         rwlock_t map_lock;
3102         atomic_t holders;
3103         atomic_t open_count;
3104 +       xid_t xid;
3105  
3106         unsigned long flags;
3107  
3108 @@ -335,6 +337,7 @@ int dm_deleting_md(struct mapped_device 
3109  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
3110  {
3111         struct mapped_device *md;
3112 +       int ret = -ENXIO;
3113  
3114         spin_lock(&_minor_lock);
3115  
3116 @@ -343,18 +346,19 @@ static int dm_blk_open(struct block_devi
3117                 goto out;
3118  
3119         if (test_bit(DMF_FREEING, &md->flags) ||
3120 -           dm_deleting_md(md)) {
3121 -               md = NULL;
3122 +           dm_deleting_md(md))
3123 +               goto out;
3124 +
3125 +       ret = -EACCES;
3126 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
3127                 goto out;
3128 -       }
3129  
3130         dm_get(md);
3131         atomic_inc(&md->open_count);
3132 -
3133 +       ret = 0;
3134  out:
3135         spin_unlock(&_minor_lock);
3136 -
3137 -       return md ? 0 : -ENXIO;
3138 +       return ret;
3139  }
3140  
3141  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
3142 @@ -575,6 +579,14 @@ int dm_set_geometry(struct mapped_device
3143         return 0;
3144  }
3145  
3146 +/*
3147 + * Get the xid associated with a dm device
3148 + */
3149 +xid_t dm_get_xid(struct mapped_device *md)
3150 +{
3151 +       return md->xid;
3152 +}
3153 +
3154  /*-----------------------------------------------------------------
3155   * CRUD START:
3156   *   A more elegant soln is in the works that uses the queue
3157 @@ -1848,6 +1860,7 @@ static struct mapped_device *alloc_dev(i
3158         INIT_LIST_HEAD(&md->uevent_list);
3159         spin_lock_init(&md->uevent_lock);
3160  
3161 +       md->xid = vx_current_xid();
3162         md->queue = blk_alloc_queue(GFP_KERNEL);
3163         if (!md->queue)
3164                 goto bad_queue;
3165 diff -NurpP --minimal linux-3.1/drivers/md/dm.h linux-3.1-vs2.3.1-rc2/drivers/md/dm.h
3166 --- linux-3.1/drivers/md/dm.h   2011-10-24 18:45:10.000000000 +0200
3167 +++ linux-3.1-vs2.3.1-rc2/drivers/md/dm.h       2011-10-24 18:53:33.000000000 +0200
3168 @@ -41,6 +41,8 @@ struct dm_dev_internal {
3169  struct dm_table;
3170  struct dm_md_mempools;
3171  
3172 +xid_t dm_get_xid(struct mapped_device *md);
3173 +
3174  /*-----------------------------------------------------------------
3175   * Internal table functions.
3176   *---------------------------------------------------------------*/
3177 diff -NurpP --minimal linux-3.1/drivers/net/tun.c linux-3.1-vs2.3.1-rc2/drivers/net/tun.c
3178 --- linux-3.1/drivers/net/tun.c 2011-10-24 18:45:17.000000000 +0200
3179 +++ linux-3.1-vs2.3.1-rc2/drivers/net/tun.c     2011-10-24 18:53:33.000000000 +0200
3180 @@ -64,6 +64,7 @@
3181  #include <linux/nsproxy.h>
3182  #include <linux/virtio_net.h>
3183  #include <linux/rcupdate.h>
3184 +#include <linux/vs_network.h>
3185  #include <net/net_namespace.h>
3186  #include <net/netns/generic.h>
3187  #include <net/rtnetlink.h>
3188 @@ -121,6 +122,7 @@ struct tun_struct {
3189         unsigned int            flags;
3190         uid_t                   owner;
3191         gid_t                   group;
3192 +       nid_t                   nid;
3193  
3194         struct net_device       *dev;
3195         u32                     set_features;
3196 @@ -909,6 +911,7 @@ static void tun_setup(struct net_device 
3197  
3198         tun->owner = -1;
3199         tun->group = -1;
3200 +       tun->nid = current->nid;
3201  
3202         dev->ethtool_ops = &tun_ethtool_ops;
3203         dev->destructor = tun_free_netdev;
3204 @@ -1059,7 +1062,7 @@ static int tun_set_iff(struct net *net, 
3205  
3206                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
3207                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
3208 -                   !capable(CAP_NET_ADMIN))
3209 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
3210                         return -EPERM;
3211                 err = security_tun_dev_attach(tun->socket.sk);
3212                 if (err < 0)
3213 @@ -1073,7 +1076,7 @@ static int tun_set_iff(struct net *net, 
3214                 char *name;
3215                 unsigned long flags = 0;
3216  
3217 -               if (!capable(CAP_NET_ADMIN))
3218 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
3219                         return -EPERM;
3220                 err = security_tun_dev_create();
3221                 if (err < 0)
3222 @@ -1141,6 +1144,9 @@ static int tun_set_iff(struct net *net, 
3223  
3224                 sk->sk_destruct = tun_sock_destruct;
3225  
3226 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
3227 +                       return -EPERM;
3228 +
3229                 err = tun_attach(tun, file);
3230                 if (err < 0)
3231                         goto failed;
3232 @@ -1322,6 +1328,16 @@ static long __tun_chr_ioctl(struct file 
3233                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
3234                 break;
3235  
3236 +       case TUNSETNID:
3237 +               if (!capable(CAP_CONTEXT))
3238 +                       return -EPERM;
3239 +
3240 +               /* Set nid owner of the device */
3241 +               tun->nid = (nid_t) arg;
3242 +
3243 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
3244 +               break;
3245 +
3246         case TUNSETLINK:
3247                 /* Only allow setting the type when the interface is down */
3248                 if (tun->dev->flags & IFF_UP) {
3249 diff -NurpP --minimal linux-3.1/drivers/tty/sysrq.c linux-3.1-vs2.3.1-rc2/drivers/tty/sysrq.c
3250 --- linux-3.1/drivers/tty/sysrq.c       2011-05-22 16:17:44.000000000 +0200
3251 +++ linux-3.1-vs2.3.1-rc2/drivers/tty/sysrq.c   2011-10-24 18:53:33.000000000 +0200
3252 @@ -41,6 +41,7 @@
3253  #include <linux/oom.h>
3254  #include <linux/slab.h>
3255  #include <linux/input.h>
3256 +#include <linux/vserver/debug.h>
3257  
3258  #include <asm/ptrace.h>
3259  #include <asm/irq_regs.h>
3260 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
3261         .enable_mask    = SYSRQ_ENABLE_RTNICE,
3262  };
3263  
3264 +
3265 +#ifdef CONFIG_VSERVER_DEBUG
3266 +static void sysrq_handle_vxinfo(int key)
3267 +{
3268 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
3269 +}
3270 +
3271 +static struct sysrq_key_op sysrq_showvxinfo_op = {
3272 +       .handler        = sysrq_handle_vxinfo,
3273 +       .help_msg       = "conteXt",
3274 +       .action_msg     = "Show Context Info",
3275 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
3276 +};
3277 +#endif
3278 +
3279  /* Key Operations table and lock */
3280  static DEFINE_SPINLOCK(sysrq_key_table_lock);
3281  
3282 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
3283         NULL,                           /* v */
3284         &sysrq_showstate_blocked_op,    /* w */
3285         /* x: May be registered on ppc/powerpc for xmon */
3286 +#ifdef CONFIG_VSERVER_DEBUG
3287 +       &sysrq_showvxinfo_op,           /* x */
3288 +#else
3289         NULL,                           /* x */
3290 +#endif
3291         /* y: May be registered on sparc64 for global register dump */
3292         NULL,                           /* y */
3293         &sysrq_ftrace_dump_op,          /* z */
3294 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
3295                 retval = key - '0';
3296         else if ((key >= 'a') && (key <= 'z'))
3297                 retval = key + 10 - 'a';
3298 +       else if ((key >= 'A') && (key <= 'Z'))
3299 +               retval = key + 10 - 'A';
3300         else
3301                 retval = -1;
3302         return retval;
3303 diff -NurpP --minimal linux-3.1/drivers/tty/tty_io.c linux-3.1-vs2.3.1-rc2/drivers/tty/tty_io.c
3304 --- linux-3.1/drivers/tty/tty_io.c      2011-10-24 18:45:24.000000000 +0200
3305 +++ linux-3.1-vs2.3.1-rc2/drivers/tty/tty_io.c  2011-10-24 18:53:33.000000000 +0200
3306 @@ -105,6 +105,7 @@
3307  
3308  #include <linux/kmod.h>
3309  #include <linux/nsproxy.h>
3310 +#include <linux/vs_pid.h>
3311  
3312  #undef TTY_DEBUG_HANGUP
3313  
3314 @@ -2056,7 +2057,8 @@ static int tiocsti(struct tty_struct *tt
3315         char ch, mbz = 0;
3316         struct tty_ldisc *ld;
3317  
3318 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
3319 +       if (((current->signal->tty != tty) &&
3320 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
3321                 return -EPERM;
3322         if (get_user(ch, p))
3323                 return -EFAULT;
3324 @@ -2344,6 +2346,7 @@ static int tiocspgrp(struct tty_struct *
3325                 return -ENOTTY;
3326         if (get_user(pgrp_nr, p))
3327                 return -EFAULT;
3328 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
3329         if (pgrp_nr < 0)
3330                 return -EINVAL;
3331         rcu_read_lock();
3332 diff -NurpP --minimal linux-3.1/fs/attr.c linux-3.1-vs2.3.1-rc2/fs/attr.c
3333 --- linux-3.1/fs/attr.c 2011-10-24 18:45:26.000000000 +0200
3334 +++ linux-3.1-vs2.3.1-rc2/fs/attr.c     2011-10-24 18:53:33.000000000 +0200
3335 @@ -13,6 +13,9 @@
3336  #include <linux/fsnotify.h>
3337  #include <linux/fcntl.h>
3338  #include <linux/security.h>
3339 +#include <linux/proc_fs.h>
3340 +#include <linux/devpts_fs.h>
3341 +#include <linux/vs_tag.h>
3342  
3343  /**
3344   * inode_change_ok - check if attribute changes to an inode are allowed
3345 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
3346                         return -EPERM;
3347         }
3348  
3349 +       /* check for inode tag permission */
3350 +       if (dx_permission(inode, MAY_WRITE))
3351 +               return -EACCES;
3352 +
3353         return 0;
3354  }
3355  EXPORT_SYMBOL(inode_change_ok);
3356 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
3357                 inode->i_uid = attr->ia_uid;
3358         if (ia_valid & ATTR_GID)
3359                 inode->i_gid = attr->ia_gid;
3360 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3361 +               inode->i_tag = attr->ia_tag;
3362         if (ia_valid & ATTR_ATIME)
3363                 inode->i_atime = timespec_trunc(attr->ia_atime,
3364                                                 inode->i_sb->s_time_gran);
3365 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
3366         struct timespec now;
3367         unsigned int ia_valid = attr->ia_valid;
3368  
3369 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
3370 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
3371 +               ATTR_TAG | ATTR_TIMES_SET)) {
3372                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
3373                         return -EPERM;
3374         }
3375 diff -NurpP --minimal linux-3.1/fs/binfmt_aout.c linux-3.1-vs2.3.1-rc2/fs/binfmt_aout.c
3376 --- linux-3.1/fs/binfmt_aout.c  2010-10-21 13:07:47.000000000 +0200
3377 +++ linux-3.1-vs2.3.1-rc2/fs/binfmt_aout.c      2011-10-24 18:53:33.000000000 +0200
3378 @@ -25,6 +25,7 @@
3379  #include <linux/init.h>
3380  #include <linux/coredump.h>
3381  #include <linux/slab.h>
3382 +#include <linux/vs_memory.h>
3383  
3384  #include <asm/system.h>
3385  #include <asm/uaccess.h>
3386 diff -NurpP --minimal linux-3.1/fs/binfmt_elf.c linux-3.1-vs2.3.1-rc2/fs/binfmt_elf.c
3387 --- linux-3.1/fs/binfmt_elf.c   2011-10-24 18:45:26.000000000 +0200
3388 +++ linux-3.1-vs2.3.1-rc2/fs/binfmt_elf.c       2011-10-24 18:53:33.000000000 +0200
3389 @@ -32,6 +32,7 @@
3390  #include <linux/elf.h>
3391  #include <linux/utsname.h>
3392  #include <linux/coredump.h>
3393 +#include <linux/vs_memory.h>
3394  #include <asm/uaccess.h>
3395  #include <asm/param.h>
3396  #include <asm/page.h>
3397 diff -NurpP --minimal linux-3.1/fs/binfmt_flat.c linux-3.1-vs2.3.1-rc2/fs/binfmt_flat.c
3398 --- linux-3.1/fs/binfmt_flat.c  2011-07-22 11:18:05.000000000 +0200
3399 +++ linux-3.1-vs2.3.1-rc2/fs/binfmt_flat.c      2011-10-24 18:53:33.000000000 +0200
3400 @@ -35,6 +35,7 @@
3401  #include <linux/init.h>
3402  #include <linux/flat.h>
3403  #include <linux/syscalls.h>
3404 +#include <linux/vs_memory.h>
3405  
3406  #include <asm/byteorder.h>
3407  #include <asm/system.h>
3408 diff -NurpP --minimal linux-3.1/fs/binfmt_som.c linux-3.1-vs2.3.1-rc2/fs/binfmt_som.c
3409 --- linux-3.1/fs/binfmt_som.c   2010-02-25 11:52:04.000000000 +0100
3410 +++ linux-3.1-vs2.3.1-rc2/fs/binfmt_som.c       2011-10-24 18:53:33.000000000 +0200
3411 @@ -28,6 +28,7 @@
3412  #include <linux/shm.h>
3413  #include <linux/personality.h>
3414  #include <linux/init.h>
3415 +#include <linux/vs_memory.h>
3416  
3417  #include <asm/uaccess.h>
3418  #include <asm/pgtable.h>
3419 diff -NurpP --minimal linux-3.1/fs/block_dev.c linux-3.1-vs2.3.1-rc2/fs/block_dev.c
3420 --- linux-3.1/fs/block_dev.c    2011-10-24 18:45:26.000000000 +0200
3421 +++ linux-3.1-vs2.3.1-rc2/fs/block_dev.c        2011-10-24 18:53:33.000000000 +0200
3422 @@ -25,6 +25,7 @@
3423  #include <linux/namei.h>
3424  #include <linux/log2.h>
3425  #include <linux/kmemleak.h>
3426 +#include <linux/vs_device.h>
3427  #include <asm/uaccess.h>
3428  #include "internal.h"
3429  
3430 @@ -563,6 +564,7 @@ struct block_device *bdget(dev_t dev)
3431                 bdev->bd_invalidated = 0;
3432                 inode->i_mode = S_IFBLK;
3433                 inode->i_rdev = dev;
3434 +               inode->i_mdev = dev;
3435                 inode->i_bdev = bdev;
3436                 inode->i_data.a_ops = &def_blk_aops;
3437                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
3438 @@ -609,6 +611,11 @@ EXPORT_SYMBOL(bdput);
3439  static struct block_device *bd_acquire(struct inode *inode)
3440  {
3441         struct block_device *bdev;
3442 +       dev_t mdev;
3443 +
3444 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
3445 +               return NULL;
3446 +       inode->i_mdev = mdev;
3447  
3448         spin_lock(&bdev_lock);
3449         bdev = inode->i_bdev;
3450 @@ -619,7 +626,7 @@ static struct block_device *bd_acquire(s
3451         }
3452         spin_unlock(&bdev_lock);
3453  
3454 -       bdev = bdget(inode->i_rdev);
3455 +       bdev = bdget(mdev);
3456         if (bdev) {
3457                 spin_lock(&bdev_lock);
3458                 if (!inode->i_bdev) {
3459 diff -NurpP --minimal linux-3.1/fs/btrfs/ctree.h linux-3.1-vs2.3.1-rc2/fs/btrfs/ctree.h
3460 --- linux-3.1/fs/btrfs/ctree.h  2011-10-24 18:45:26.000000000 +0200
3461 +++ linux-3.1-vs2.3.1-rc2/fs/btrfs/ctree.h      2011-10-24 18:53:33.000000000 +0200
3462 @@ -600,11 +600,14 @@ struct btrfs_inode_item {
3463         /* modification sequence number for NFS */
3464         __le64 sequence;
3465  
3466 +       __le16 tag;
3467         /*
3468          * a little future expansion, for more than this we can
3469          * just grow the inode item and version it
3470          */
3471 -       __le64 reserved[4];
3472 +       __le16 reserved16;
3473 +       __le32 reserved32;
3474 +       __le64 reserved[3];
3475         struct btrfs_timespec atime;
3476         struct btrfs_timespec ctime;
3477         struct btrfs_timespec mtime;
3478 @@ -1364,6 +1367,8 @@ struct btrfs_ioctl_defrag_range_args {
3479  #define BTRFS_MOUNT_AUTO_DEFRAG                (1 << 16)
3480  #define BTRFS_MOUNT_INODE_MAP_CACHE    (1 << 17)
3481  
3482 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
3483 +
3484  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
3485  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
3486  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
3487 @@ -1571,6 +1576,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
3488  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
3489  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
3490  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
3491 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
3492  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
3493  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
3494  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
3495 @@ -1624,6 +1630,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
3496  
3497  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
3498  
3499 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
3500 +#define BTRFS_INODE_BARRIER            (1 << 25)
3501 +#define BTRFS_INODE_COW                        (1 << 26)
3502 +
3503  
3504  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
3505  
3506 @@ -2603,6 +2613,7 @@ extern const struct dentry_operations bt
3507  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
3508  void btrfs_update_iflags(struct inode *inode);
3509  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
3510 +int btrfs_sync_flags(struct inode *inode, int, int);
3511  int btrfs_defrag_file(struct inode *inode, struct file *file,
3512                       struct btrfs_ioctl_defrag_range_args *range,
3513                       u64 newer_than, unsigned long max_pages);
3514 diff -NurpP --minimal linux-3.1/fs/btrfs/disk-io.c linux-3.1-vs2.3.1-rc2/fs/btrfs/disk-io.c
3515 --- linux-3.1/fs/btrfs/disk-io.c        2011-10-24 18:45:26.000000000 +0200
3516 +++ linux-3.1-vs2.3.1-rc2/fs/btrfs/disk-io.c    2011-10-24 18:53:33.000000000 +0200
3517 @@ -1794,6 +1794,9 @@ struct btrfs_root *open_ctree(struct sup
3518                 goto fail_alloc;
3519         }
3520  
3521 +       if (btrfs_test_opt(tree_root, TAGGED))
3522 +               sb->s_flags |= MS_TAGGED;
3523 +
3524         features = btrfs_super_incompat_flags(disk_super) &
3525                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
3526         if (features) {
3527 diff -NurpP --minimal linux-3.1/fs/btrfs/inode.c linux-3.1-vs2.3.1-rc2/fs/btrfs/inode.c
3528 --- linux-3.1/fs/btrfs/inode.c  2011-10-24 18:45:26.000000000 +0200
3529 +++ linux-3.1-vs2.3.1-rc2/fs/btrfs/inode.c      2011-10-24 18:53:33.000000000 +0200
3530 @@ -38,6 +38,7 @@
3531  #include <linux/falloc.h>
3532  #include <linux/slab.h>
3533  #include <linux/ratelimit.h>
3534 +#include <linux/vs_tag.h>
3535  #include "compat.h"
3536  #include "ctree.h"
3537  #include "disk-io.h"
3538 @@ -2508,6 +2509,8 @@ static void btrfs_read_locked_inode(stru
3539         struct btrfs_key location;
3540         int maybe_acls;
3541         u32 rdev;
3542 +       uid_t uid;
3543 +       gid_t gid;
3544         int ret;
3545         bool filled = false;
3546  
3547 @@ -2535,8 +2538,13 @@ static void btrfs_read_locked_inode(stru
3548                                     struct btrfs_inode_item);
3549         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
3550         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
3551 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
3552 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
3553 +
3554 +       uid = btrfs_inode_uid(leaf, inode_item);
3555 +       gid = btrfs_inode_gid(leaf, inode_item);
3556 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3557 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3558 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3559 +               btrfs_inode_tag(leaf, inode_item));
3560         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
3561  
3562         tspec = btrfs_inode_atime(inode_item);
3563 @@ -2614,8 +2622,14 @@ static void fill_inode_item(struct btrfs
3564                             struct btrfs_inode_item *item,
3565                             struct inode *inode)
3566  {
3567 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
3568 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
3569 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3570 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3571 +
3572 +       btrfs_set_inode_uid(leaf, item, uid);
3573 +       btrfs_set_inode_gid(leaf, item, gid);
3574 +#ifdef CONFIG_TAGGING_INTERN
3575 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
3576 +#endif
3577         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
3578         btrfs_set_inode_mode(leaf, item, inode->i_mode);
3579         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
3580 @@ -7393,11 +7407,13 @@ static const struct inode_operations btr
3581         .listxattr      = btrfs_listxattr,
3582         .removexattr    = btrfs_removexattr,
3583         .permission     = btrfs_permission,
3584 +       .sync_flags     = btrfs_sync_flags,
3585         .get_acl        = btrfs_get_acl,
3586  };
3587  static const struct inode_operations btrfs_dir_ro_inode_operations = {
3588         .lookup         = btrfs_lookup,
3589         .permission     = btrfs_permission,
3590 +       .sync_flags     = btrfs_sync_flags,
3591         .get_acl        = btrfs_get_acl,
3592  };
3593  
3594 diff -NurpP --minimal linux-3.1/fs/btrfs/ioctl.c linux-3.1-vs2.3.1-rc2/fs/btrfs/ioctl.c
3595 --- linux-3.1/fs/btrfs/ioctl.c  2011-10-24 18:45:26.000000000 +0200
3596 +++ linux-3.1-vs2.3.1-rc2/fs/btrfs/ioctl.c      2011-10-24 18:53:33.000000000 +0200
3597 @@ -70,10 +70,13 @@ static unsigned int btrfs_flags_to_ioctl
3598  {
3599         unsigned int iflags = 0;
3600  
3601 -       if (flags & BTRFS_INODE_SYNC)
3602 -               iflags |= FS_SYNC_FL;
3603         if (flags & BTRFS_INODE_IMMUTABLE)
3604                 iflags |= FS_IMMUTABLE_FL;
3605 +       if (flags & BTRFS_INODE_IXUNLINK)
3606 +               iflags |= FS_IXUNLINK_FL;
3607 +
3608 +       if (flags & BTRFS_INODE_SYNC)
3609 +               iflags |= FS_SYNC_FL;
3610         if (flags & BTRFS_INODE_APPEND)
3611                 iflags |= FS_APPEND_FL;
3612         if (flags & BTRFS_INODE_NODUMP)
3613 @@ -90,28 +93,78 @@ static unsigned int btrfs_flags_to_ioctl
3614         else if (flags & BTRFS_INODE_NOCOMPRESS)
3615                 iflags |= FS_NOCOMP_FL;
3616  
3617 +       if (flags & BTRFS_INODE_BARRIER)
3618 +               iflags |= FS_BARRIER_FL;
3619 +       if (flags & BTRFS_INODE_COW)
3620 +               iflags |= FS_COW_FL;
3621         return iflags;
3622  }
3623  
3624  /*
3625 - * Update inode->i_flags based on the btrfs internal flags.
3626 + * Update inode->i_(v)flags based on the btrfs internal flags.
3627   */
3628  void btrfs_update_iflags(struct inode *inode)
3629  {
3630         struct btrfs_inode *ip = BTRFS_I(inode);
3631  
3632 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3633 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3634 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3635  
3636 -       if (ip->flags & BTRFS_INODE_SYNC)
3637 -               inode->i_flags |= S_SYNC;
3638         if (ip->flags & BTRFS_INODE_IMMUTABLE)
3639                 inode->i_flags |= S_IMMUTABLE;
3640 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
3641 +               inode->i_flags |= S_IXUNLINK;
3642 +
3643 +       if (ip->flags & BTRFS_INODE_SYNC)
3644 +               inode->i_flags |= S_SYNC;
3645         if (ip->flags & BTRFS_INODE_APPEND)
3646                 inode->i_flags |= S_APPEND;
3647         if (ip->flags & BTRFS_INODE_NOATIME)
3648                 inode->i_flags |= S_NOATIME;
3649         if (ip->flags & BTRFS_INODE_DIRSYNC)
3650                 inode->i_flags |= S_DIRSYNC;
3651 +
3652 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3653 +
3654 +       if (ip->flags & BTRFS_INODE_BARRIER)
3655 +               inode->i_vflags |= V_BARRIER;
3656 +       if (ip->flags & BTRFS_INODE_COW)
3657 +               inode->i_vflags |= V_COW;
3658 +}
3659 +
3660 +/*
3661 + * Update btrfs internal flags from inode->i_(v)flags.
3662 + */
3663 +void btrfs_update_flags(struct inode *inode)
3664 +{
3665 +       struct btrfs_inode *ip = BTRFS_I(inode);
3666 +
3667 +       unsigned int flags = inode->i_flags;
3668 +       unsigned int vflags = inode->i_vflags;
3669 +
3670 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
3671 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
3672 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
3673 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
3674 +
3675 +       if (flags & S_IMMUTABLE)
3676 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
3677 +       if (flags & S_IXUNLINK)
3678 +               ip->flags |= BTRFS_INODE_IXUNLINK;
3679 +
3680 +       if (flags & S_SYNC)
3681 +               ip->flags |= BTRFS_INODE_SYNC;
3682 +       if (flags & S_APPEND)
3683 +               ip->flags |= BTRFS_INODE_APPEND;
3684 +       if (flags & S_NOATIME)
3685 +               ip->flags |= BTRFS_INODE_NOATIME;
3686 +       if (flags & S_DIRSYNC)
3687 +               ip->flags |= BTRFS_INODE_DIRSYNC;
3688 +
3689 +       if (vflags & V_BARRIER)
3690 +               ip->flags |= BTRFS_INODE_BARRIER;
3691 +       if (vflags & V_COW)
3692 +               ip->flags |= BTRFS_INODE_COW;
3693  }
3694  
3695  /*
3696 @@ -129,7 +182,7 @@ void btrfs_inherit_iflags(struct inode *
3697         flags = BTRFS_I(dir)->flags;
3698  
3699         if (S_ISREG(inode->i_mode))
3700 -               flags &= ~BTRFS_INODE_DIRSYNC;
3701 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
3702         else if (!S_ISDIR(inode->i_mode))
3703                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
3704  
3705 @@ -137,6 +190,30 @@ void btrfs_inherit_iflags(struct inode *
3706         btrfs_update_iflags(inode);
3707  }
3708  
3709 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
3710 +{
3711 +       struct btrfs_inode *ip = BTRFS_I(inode);
3712 +       struct btrfs_root *root = ip->root;
3713 +       struct btrfs_trans_handle *trans;
3714 +       int ret;
3715 +
3716 +       trans = btrfs_join_transaction(root);
3717 +       BUG_ON(!trans);
3718 +
3719 +       inode->i_flags = flags;
3720 +       inode->i_vflags = vflags;
3721 +       btrfs_update_flags(inode);
3722 +
3723 +       ret = btrfs_update_inode(trans, root, inode);
3724 +       BUG_ON(ret);
3725 +
3726 +       btrfs_update_iflags(inode);
3727 +       inode->i_ctime = CURRENT_TIME;
3728 +       btrfs_end_transaction(trans, root);
3729 +
3730 +       return 0;
3731 +}
3732 +
3733  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
3734  {
3735         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
3736 @@ -188,7 +265,8 @@ static int btrfs_ioctl_setflags(struct f
3737  
3738         flags = btrfs_mask_flags(inode->i_mode, flags);
3739         oldflags = btrfs_flags_to_ioctl(ip->flags);
3740 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
3741 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
3742 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
3743                 if (!capable(CAP_LINUX_IMMUTABLE)) {
3744                         ret = -EPERM;
3745                         goto out_unlock;
3746 @@ -199,14 +277,19 @@ static int btrfs_ioctl_setflags(struct f
3747         if (ret)
3748                 goto out_unlock;
3749  
3750 -       if (flags & FS_SYNC_FL)
3751 -               ip->flags |= BTRFS_INODE_SYNC;
3752 -       else
3753 -               ip->flags &= ~BTRFS_INODE_SYNC;
3754         if (flags & FS_IMMUTABLE_FL)
3755                 ip->flags |= BTRFS_INODE_IMMUTABLE;
3756         else
3757                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
3758 +       if (flags & FS_IXUNLINK_FL)
3759 +               ip->flags |= BTRFS_INODE_IXUNLINK;
3760 +       else
3761 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
3762 +
3763 +       if (flags & FS_SYNC_FL)
3764 +               ip->flags |= BTRFS_INODE_SYNC;
3765 +       else
3766 +               ip->flags &= ~BTRFS_INODE_SYNC;
3767         if (flags & FS_APPEND_FL)
3768                 ip->flags |= BTRFS_INODE_APPEND;
3769         else
3770 diff -NurpP --minimal linux-3.1/fs/btrfs/super.c linux-3.1-vs2.3.1-rc2/fs/btrfs/super.c
3771 --- linux-3.1/fs/btrfs/super.c  2011-07-22 11:18:05.000000000 +0200
3772 +++ linux-3.1-vs2.3.1-rc2/fs/btrfs/super.c      2011-10-24 18:53:33.000000000 +0200
3773 @@ -162,7 +162,7 @@ enum {
3774         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
3775         Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
3776         Opt_enospc_debug, Opt_subvolrootid, Opt_defrag,
3777 -       Opt_inode_cache, Opt_err,
3778 +       Opt_inode_cache, Opt_tag, Opt_notag, Opt_tagid, Opt_err,
3779  };
3780  
3781  static match_table_t tokens = {
3782 @@ -195,6 +195,9 @@ static match_table_t tokens = {
3783         {Opt_subvolrootid, "subvolrootid=%d"},
3784         {Opt_defrag, "autodefrag"},
3785         {Opt_inode_cache, "inode_cache"},
3786 +       {Opt_tag, "tag"},
3787 +       {Opt_notag, "notag"},
3788 +       {Opt_tagid, "tagid=%u"},
3789         {Opt_err, NULL},
3790  };
3791  
3792 @@ -381,6 +384,22 @@ int btrfs_parse_options(struct btrfs_roo
3793                         printk(KERN_INFO "btrfs: enabling auto defrag");
3794                         btrfs_set_opt(info->mount_opt, AUTO_DEFRAG);
3795                         break;
3796 +#ifndef CONFIG_TAGGING_NONE
3797 +               case Opt_tag:
3798 +                       printk(KERN_INFO "btrfs: use tagging\n");
3799 +                       btrfs_set_opt(info->mount_opt, TAGGED);
3800 +                       break;
3801 +               case Opt_notag:
3802 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
3803 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
3804 +                       break;
3805 +#endif
3806 +#ifdef CONFIG_PROPAGATE
3807 +               case Opt_tagid:
3808 +                       /* use args[0] */
3809 +                       btrfs_set_opt(info->mount_opt, TAGGED);
3810 +                       break;
3811 +#endif
3812                 case Opt_err:
3813                         printk(KERN_INFO "btrfs: unrecognized mount option "
3814                                "'%s'\n", p);
3815 @@ -907,6 +926,12 @@ static int btrfs_remount(struct super_bl
3816         if (ret)
3817                 return -EINVAL;
3818  
3819 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3820 +               printk("btrfs: %s: tagging not permitted on remount.\n",
3821 +                       sb->s_id);
3822 +               return -EINVAL;
3823 +       }
3824 +
3825         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
3826                 return 0;
3827  
3828 diff -NurpP --minimal linux-3.1/fs/char_dev.c linux-3.1-vs2.3.1-rc2/fs/char_dev.c
3829 --- linux-3.1/fs/char_dev.c     2011-03-15 18:07:31.000000000 +0100
3830 +++ linux-3.1-vs2.3.1-rc2/fs/char_dev.c 2011-10-24 18:53:33.000000000 +0200
3831 @@ -21,6 +21,8 @@
3832  #include <linux/mutex.h>
3833  #include <linux/backing-dev.h>
3834  #include <linux/tty.h>
3835 +#include <linux/vs_context.h>
3836 +#include <linux/vs_device.h>
3837  
3838  #include "internal.h"
3839  
3840 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
3841         struct cdev *p;
3842         struct cdev *new = NULL;
3843         int ret = 0;
3844 +       dev_t mdev;
3845 +
3846 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
3847 +               return -EPERM;
3848 +       inode->i_mdev = mdev;
3849  
3850         spin_lock(&cdev_lock);
3851         p = inode->i_cdev;
3852         if (!p) {
3853                 struct kobject *kobj;
3854                 int idx;
3855 +
3856                 spin_unlock(&cdev_lock);
3857 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
3858 +
3859 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
3860                 if (!kobj)
3861                         return -ENXIO;
3862                 new = container_of(kobj, struct cdev, kobj);
3863 diff -NurpP --minimal linux-3.1/fs/dcache.c linux-3.1-vs2.3.1-rc2/fs/dcache.c
3864 --- linux-3.1/fs/dcache.c       2011-10-24 18:45:26.000000000 +0200
3865 +++ linux-3.1-vs2.3.1-rc2/fs/dcache.c   2011-10-24 18:53:33.000000000 +0200
3866 @@ -36,6 +36,7 @@
3867  #include <linux/bit_spinlock.h>
3868  #include <linux/rculist_bl.h>
3869  #include <linux/prefetch.h>
3870 +#include <linux/vs_limit.h>
3871  #include "internal.h"
3872  
3873  /*
3874 @@ -513,6 +514,8 @@ int d_invalidate(struct dentry * dentry)
3875                 spin_lock(&dentry->d_lock);
3876         }
3877  
3878 +       vx_dentry_dec(dentry);
3879 +
3880         /*
3881          * Somebody else still using it?
3882          *
3883 @@ -540,6 +543,7 @@ EXPORT_SYMBOL(d_invalidate);
3884  static inline void __dget_dlock(struct dentry *dentry)
3885  {
3886         dentry->d_count++;
3887 +       vx_dentry_inc(dentry);
3888  }
3889  
3890  static inline void __dget(struct dentry *dentry)
3891 @@ -1175,6 +1179,9 @@ struct dentry *__d_alloc(struct super_bl
3892         struct dentry *dentry;
3893         char *dname;
3894  
3895 +       if (!vx_dentry_avail(1))
3896 +               return NULL;
3897 +
3898         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
3899         if (!dentry)
3900                 return NULL;
3901 @@ -1197,6 +1204,7 @@ struct dentry *__d_alloc(struct super_bl
3902  
3903         dentry->d_count = 1;
3904         dentry->d_flags = 0;
3905 +       vx_dentry_inc(dentry);
3906         spin_lock_init(&dentry->d_lock);
3907         seqcount_init(&dentry->d_seq);
3908         dentry->d_inode = NULL;
3909 @@ -1853,6 +1861,7 @@ struct dentry *__d_lookup(struct dentry 
3910                 }
3911  
3912                 dentry->d_count++;
3913 +               vx_dentry_inc(dentry);
3914                 found = dentry;
3915                 spin_unlock(&dentry->d_lock);
3916                 break;
3917 diff -NurpP --minimal linux-3.1/fs/devpts/inode.c linux-3.1-vs2.3.1-rc2/fs/devpts/inode.c
3918 --- linux-3.1/fs/devpts/inode.c 2011-05-22 16:17:50.000000000 +0200
3919 +++ linux-3.1-vs2.3.1-rc2/fs/devpts/inode.c     2011-10-24 18:53:33.000000000 +0200
3920 @@ -25,6 +25,7 @@
3921  #include <linux/parser.h>
3922  #include <linux/fsnotify.h>
3923  #include <linux/seq_file.h>
3924 +#include <linux/vs_base.h>
3925  
3926  #define DEVPTS_DEFAULT_MODE 0600
3927  /*
3928 @@ -36,6 +37,20 @@
3929  #define DEVPTS_DEFAULT_PTMX_MODE 0000
3930  #define PTMX_MINOR     2
3931  
3932 +static int devpts_permission(struct inode *inode, int mask)
3933 +{
3934 +       int ret = -EACCES;
3935 +
3936 +       /* devpts is xid tagged */
3937 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
3938 +               ret = generic_permission(inode, mask);
3939 +       return ret;
3940 +}
3941 +
3942 +static struct inode_operations devpts_file_inode_operations = {
3943 +       .permission     = devpts_permission,
3944 +};
3945 +
3946  extern int pty_limit;                  /* Config limit on Unix98 ptys */
3947  static DEFINE_MUTEX(allocated_ptys_lock);
3948  
3949 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
3950         return 0;
3951  }
3952  
3953 +static int devpts_filter(struct dentry *de)
3954 +{
3955 +       xid_t xid = 0;
3956 +
3957 +       /* devpts is xid tagged */
3958 +       if (de && de->d_inode)
3959 +               xid = (xid_t)de->d_inode->i_tag;
3960 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
3961 +       else
3962 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
3963 +                       de->d_name.len, de->d_name.name);
3964 +#endif
3965 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
3966 +}
3967 +
3968 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
3969 +{
3970 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
3971 +}
3972 +
3973 +static struct file_operations devpts_dir_operations = {
3974 +       .open           = dcache_dir_open,
3975 +       .release        = dcache_dir_close,
3976 +       .llseek         = dcache_dir_lseek,
3977 +       .read           = generic_read_dir,
3978 +       .readdir        = devpts_readdir,
3979 +};
3980 +
3981  static const struct super_operations devpts_sops = {
3982         .statfs         = simple_statfs,
3983         .remount_fs     = devpts_remount,
3984 @@ -302,12 +345,15 @@ devpts_fill_super(struct super_block *s,
3985         inode = new_inode(s);
3986         if (!inode)
3987                 goto free_fsi;
3988 +
3989         inode->i_ino = 1;
3990         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
3991         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
3992         inode->i_op = &simple_dir_inode_operations;
3993 -       inode->i_fop = &simple_dir_operations;
3994 +       inode->i_fop = &devpts_dir_operations;
3995         inode->i_nlink = 2;
3996 +       /* devpts is xid tagged */
3997 +       inode->i_tag = (tag_t)vx_current_xid();
3998  
3999         s->s_root = d_alloc_root(inode);
4000         if (s->s_root)
4001 @@ -494,6 +540,9 @@ int devpts_pty_new(struct inode *ptmx_in
4002         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
4003         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
4004         init_special_inode(inode, S_IFCHR|opts->mode, device);
4005 +       /* devpts is xid tagged */
4006 +       inode->i_tag = (tag_t)vx_current_xid();
4007 +       inode->i_op = &devpts_file_inode_operations;
4008         inode->i_private = tty;
4009         tty->driver_data = inode;
4010  
4011 diff -NurpP --minimal linux-3.1/fs/ext2/balloc.c linux-3.1-vs2.3.1-rc2/fs/ext2/balloc.c
4012 --- linux-3.1/fs/ext2/balloc.c  2011-05-22 16:17:51.000000000 +0200
4013 +++ linux-3.1-vs2.3.1-rc2/fs/ext2/balloc.c      2011-10-24 18:53:33.000000000 +0200
4014 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
4015                         start = 0;
4016                 end = EXT2_BLOCKS_PER_GROUP(sb);
4017         }
4018 -
4019         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
4020  
4021  repeat:
4022 diff -NurpP --minimal linux-3.1/fs/ext2/ext2.h linux-3.1-vs2.3.1-rc2/fs/ext2/ext2.h
4023 --- linux-3.1/fs/ext2/ext2.h    2011-10-24 18:45:27.000000000 +0200
4024 +++ linux-3.1-vs2.3.1-rc2/fs/ext2/ext2.h        2011-10-24 18:53:33.000000000 +0200
4025 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
4026  extern void ext2_get_inode_flags(struct ext2_inode_info *);
4027  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4028                        u64 start, u64 len);
4029 +extern int ext2_sync_flags(struct inode *, int, int);
4030  
4031  /* ioctl.c */
4032  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
4033 diff -NurpP --minimal linux-3.1/fs/ext2/file.c linux-3.1-vs2.3.1-rc2/fs/ext2/file.c
4034 --- linux-3.1/fs/ext2/file.c    2011-10-24 18:45:27.000000000 +0200
4035 +++ linux-3.1-vs2.3.1-rc2/fs/ext2/file.c        2011-10-24 18:53:33.000000000 +0200
4036 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
4037         .setattr        = ext2_setattr,
4038         .get_acl        = ext2_get_acl,
4039         .fiemap         = ext2_fiemap,
4040 +       .sync_flags     = ext2_sync_flags,
4041  };
4042 diff -NurpP --minimal linux-3.1/fs/ext2/ialloc.c linux-3.1-vs2.3.1-rc2/fs/ext2/ialloc.c
4043 --- linux-3.1/fs/ext2/ialloc.c  2011-05-22 16:17:51.000000000 +0200
4044 +++ linux-3.1-vs2.3.1-rc2/fs/ext2/ialloc.c      2011-10-24 18:53:33.000000000 +0200
4045 @@ -17,6 +17,7 @@
4046  #include <linux/backing-dev.h>
4047  #include <linux/buffer_head.h>
4048  #include <linux/random.h>
4049 +#include <linux/vs_tag.h>
4050  #include "ext2.h"
4051  #include "xattr.h"
4052  #include "acl.h"
4053 @@ -549,6 +550,7 @@ got:
4054                 inode->i_mode = mode;
4055                 inode->i_uid = current_fsuid();
4056                 inode->i_gid = dir->i_gid;
4057 +               inode->i_tag = dx_current_fstag(sb);
4058         } else
4059                 inode_init_owner(inode, dir, mode);
4060  
4061 diff -NurpP --minimal linux-3.1/fs/ext2/inode.c linux-3.1-vs2.3.1-rc2/fs/ext2/inode.c
4062 --- linux-3.1/fs/ext2/inode.c   2011-10-24 18:45:27.000000000 +0200
4063 +++ linux-3.1-vs2.3.1-rc2/fs/ext2/inode.c       2011-10-24 18:53:33.000000000 +0200
4064 @@ -32,6 +32,7 @@
4065  #include <linux/mpage.h>
4066  #include <linux/fiemap.h>
4067  #include <linux/namei.h>
4068 +#include <linux/vs_tag.h>
4069  #include "ext2.h"
4070  #include "acl.h"
4071  #include "xip.h"
4072 @@ -1167,7 +1168,7 @@ static void ext2_truncate_blocks(struct 
4073                 return;
4074         if (ext2_inode_is_fast_symlink(inode))
4075                 return;
4076 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4077 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4078                 return;
4079         __ext2_truncate_blocks(inode, offset);
4080  }
4081 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
4082  {
4083         unsigned int flags = EXT2_I(inode)->i_flags;
4084  
4085 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4086 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4087 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4088 +
4089 +
4090 +       if (flags & EXT2_IMMUTABLE_FL)
4091 +               inode->i_flags |= S_IMMUTABLE;
4092 +       if (flags & EXT2_IXUNLINK_FL)
4093 +               inode->i_flags |= S_IXUNLINK;
4094 +
4095         if (flags & EXT2_SYNC_FL)
4096                 inode->i_flags |= S_SYNC;
4097         if (flags & EXT2_APPEND_FL)
4098                 inode->i_flags |= S_APPEND;
4099 -       if (flags & EXT2_IMMUTABLE_FL)
4100 -               inode->i_flags |= S_IMMUTABLE;
4101         if (flags & EXT2_NOATIME_FL)
4102                 inode->i_flags |= S_NOATIME;
4103         if (flags & EXT2_DIRSYNC_FL)
4104                 inode->i_flags |= S_DIRSYNC;
4105 +
4106 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4107 +
4108 +       if (flags & EXT2_BARRIER_FL)
4109 +               inode->i_vflags |= V_BARRIER;
4110 +       if (flags & EXT2_COW_FL)
4111 +               inode->i_vflags |= V_COW;
4112  }
4113  
4114  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
4115  void ext2_get_inode_flags(struct ext2_inode_info *ei)
4116  {
4117         unsigned int flags = ei->vfs_inode.i_flags;
4118 +       unsigned int vflags = ei->vfs_inode.i_vflags;
4119 +
4120 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
4121 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
4122 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
4123 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
4124 +
4125 +       if (flags & S_IMMUTABLE)
4126 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
4127 +       if (flags & S_IXUNLINK)
4128 +               ei->i_flags |= EXT2_IXUNLINK_FL;
4129  
4130 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
4131 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
4132         if (flags & S_SYNC)
4133                 ei->i_flags |= EXT2_SYNC_FL;
4134         if (flags & S_APPEND)
4135                 ei->i_flags |= EXT2_APPEND_FL;
4136 -       if (flags & S_IMMUTABLE)
4137 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
4138         if (flags & S_NOATIME)
4139                 ei->i_flags |= EXT2_NOATIME_FL;
4140         if (flags & S_DIRSYNC)
4141                 ei->i_flags |= EXT2_DIRSYNC_FL;
4142 +
4143 +       if (vflags & V_BARRIER)
4144 +               ei->i_flags |= EXT2_BARRIER_FL;
4145 +       if (vflags & V_COW)
4146 +               ei->i_flags |= EXT2_COW_FL;
4147  }
4148  
4149  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
4150 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
4151         struct ext2_inode *raw_inode;
4152         struct inode *inode;
4153         long ret = -EIO;
4154 +       uid_t uid;
4155 +       gid_t gid;
4156         int n;
4157  
4158         inode = iget_locked(sb, ino);
4159 @@ -1315,12 +1343,17 @@ struct inode *ext2_iget (struct super_bl
4160         }
4161  
4162         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4163 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4164 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4165 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4166 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4167         if (!(test_opt (inode->i_sb, NO_UID32))) {
4168 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4169 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4170 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4171 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4172         }
4173 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4174 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4175 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4176 +               le16_to_cpu(raw_inode->i_raw_tag));
4177 +
4178         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4179         inode->i_size = le32_to_cpu(raw_inode->i_size);
4180         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
4181 @@ -1418,8 +1451,8 @@ static int __ext2_write_inode(struct ino
4182         struct ext2_inode_info *ei = EXT2_I(inode);
4183         struct super_block *sb = inode->i_sb;
4184         ino_t ino = inode->i_ino;
4185 -       uid_t uid = inode->i_uid;
4186 -       gid_t gid = inode->i_gid;
4187 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4188 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4189         struct buffer_head * bh;
4190         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
4191         int n;
4192 @@ -1455,6 +1488,9 @@ static int __ext2_write_inode(struct ino
4193                 raw_inode->i_uid_high = 0;
4194                 raw_inode->i_gid_high = 0;
4195         }
4196 +#ifdef CONFIG_TAGGING_INTERN
4197 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4198 +#endif
4199         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4200         raw_inode->i_size = cpu_to_le32(inode->i_size);
4201         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4202 @@ -1535,7 +1571,8 @@ int ext2_setattr(struct dentry *dentry, 
4203         if (is_quota_modification(inode, iattr))
4204                 dquot_initialize(inode);
4205         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4206 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4207 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4208 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4209                 error = dquot_transfer(inode, iattr);
4210                 if (error)
4211                         return error;
4212 diff -NurpP --minimal linux-3.1/fs/ext2/ioctl.c linux-3.1-vs2.3.1-rc2/fs/ext2/ioctl.c
4213 --- linux-3.1/fs/ext2/ioctl.c   2011-05-22 16:17:51.000000000 +0200
4214 +++ linux-3.1-vs2.3.1-rc2/fs/ext2/ioctl.c       2011-10-24 18:53:33.000000000 +0200
4215 @@ -17,6 +17,16 @@
4216  #include <asm/uaccess.h>
4217  
4218  
4219 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
4220 +{
4221 +       inode->i_flags = flags;
4222 +       inode->i_vflags = vflags;
4223 +       ext2_get_inode_flags(EXT2_I(inode));
4224 +       inode->i_ctime = CURRENT_TIME_SEC;
4225 +       mark_inode_dirty(inode);
4226 +       return 0;
4227 +}
4228 +
4229  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4230  {
4231         struct inode *inode = filp->f_dentry->d_inode;
4232 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
4233  
4234                 flags = ext2_mask_flags(inode->i_mode, flags);
4235  
4236 +               if (IS_BARRIER(inode)) {
4237 +                       vxwprintk_task(1, "messing with the barrier.");
4238 +                       return -EACCES;
4239 +               }
4240 +
4241                 mutex_lock(&inode->i_mutex);
4242                 /* Is it quota file? Do not allow user to mess with it */
4243                 if (IS_NOQUOTA(inode)) {
4244 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
4245                  *
4246                  * This test looks nicer. Thanks to Pauline Middelink
4247                  */
4248 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
4249 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
4250 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
4251 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
4252                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4253                                 mutex_unlock(&inode->i_mutex);
4254                                 ret = -EPERM;
4255 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
4256                         }
4257                 }
4258  
4259 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
4260 +               flags &= EXT2_FL_USER_MODIFIABLE;
4261                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
4262                 ei->i_flags = flags;
4263                 mutex_unlock(&inode->i_mutex);
4264 diff -NurpP --minimal linux-3.1/fs/ext2/namei.c linux-3.1-vs2.3.1-rc2/fs/ext2/namei.c
4265 --- linux-3.1/fs/ext2/namei.c   2011-10-24 18:45:27.000000000 +0200
4266 +++ linux-3.1-vs2.3.1-rc2/fs/ext2/namei.c       2011-10-24 18:53:33.000000000 +0200
4267 @@ -32,6 +32,7 @@
4268  
4269  #include <linux/pagemap.h>
4270  #include <linux/quotaops.h>
4271 +#include <linux/vs_tag.h>
4272  #include "ext2.h"
4273  #include "xattr.h"
4274  #include "acl.h"
4275 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
4276                                         (unsigned long) ino);
4277                         return ERR_PTR(-EIO);
4278                 }
4279 +               dx_propagate_tag(nd, inode);
4280         }
4281         return d_splice_alias(inode, dentry);
4282  }
4283 @@ -408,6 +410,7 @@ const struct inode_operations ext2_dir_i
4284         .removexattr    = generic_removexattr,
4285  #endif
4286         .setattr        = ext2_setattr,
4287 +       .sync_flags     = ext2_sync_flags,
4288         .get_acl        = ext2_get_acl,
4289  };
4290  
4291 diff -NurpP --minimal linux-3.1/fs/ext2/super.c linux-3.1-vs2.3.1-rc2/fs/ext2/super.c
4292 --- linux-3.1/fs/ext2/super.c   2011-07-22 11:18:05.000000000 +0200
4293 +++ linux-3.1-vs2.3.1-rc2/fs/ext2/super.c       2011-10-24 18:53:33.000000000 +0200
4294 @@ -394,7 +394,8 @@ enum {
4295         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
4296         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
4297         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
4298 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
4299 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
4300 +       Opt_tag, Opt_notag, Opt_tagid
4301  };
4302  
4303  static const match_table_t tokens = {
4304 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
4305         {Opt_acl, "acl"},
4306         {Opt_noacl, "noacl"},
4307         {Opt_xip, "xip"},
4308 +       {Opt_tag, "tag"},
4309 +       {Opt_notag, "notag"},
4310 +       {Opt_tagid, "tagid=%u"},
4311         {Opt_grpquota, "grpquota"},
4312         {Opt_ignore, "noquota"},
4313         {Opt_quota, "quota"},
4314 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
4315                 case Opt_nouid32:
4316                         set_opt (sbi->s_mount_opt, NO_UID32);
4317                         break;
4318 +#ifndef CONFIG_TAGGING_NONE
4319 +               case Opt_tag:
4320 +                       set_opt (sbi->s_mount_opt, TAGGED);
4321 +                       break;
4322 +               case Opt_notag:
4323 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4324 +                       break;
4325 +#endif
4326 +#ifdef CONFIG_PROPAGATE
4327 +               case Opt_tagid:
4328 +                       /* use args[0] */
4329 +                       set_opt (sbi->s_mount_opt, TAGGED);
4330 +                       break;
4331 +#endif
4332                 case Opt_nocheck:
4333                         clear_opt (sbi->s_mount_opt, CHECK);
4334                         break;
4335 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
4336         if (!parse_options((char *) data, sb))
4337                 goto failed_mount;
4338  
4339 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
4340 +               sb->s_flags |= MS_TAGGED;
4341         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4342                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
4343                  MS_POSIXACL : 0);
4344 @@ -1224,6 +1244,14 @@ static int ext2_remount (struct super_bl
4345                 goto restore_opts;
4346         }
4347  
4348 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
4349 +               !(sb->s_flags & MS_TAGGED)) {
4350 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
4351 +                      sb->s_id);
4352 +               err = -EINVAL;
4353 +               goto restore_opts;
4354 +       }
4355 +
4356         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4357                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4358  
4359 diff -NurpP --minimal linux-3.1/fs/ext3/file.c linux-3.1-vs2.3.1-rc2/fs/ext3/file.c
4360 --- linux-3.1/fs/ext3/file.c    2011-10-24 18:45:27.000000000 +0200
4361 +++ linux-3.1-vs2.3.1-rc2/fs/ext3/file.c        2011-10-24 18:53:33.000000000 +0200
4362 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
4363  #endif
4364         .get_acl        = ext3_get_acl,
4365         .fiemap         = ext3_fiemap,
4366 +       .sync_flags     = ext3_sync_flags,
4367  };
4368  
4369 diff -NurpP --minimal linux-3.1/fs/ext3/ialloc.c linux-3.1-vs2.3.1-rc2/fs/ext3/ialloc.c
4370 --- linux-3.1/fs/ext3/ialloc.c  2011-10-24 18:45:27.000000000 +0200
4371 +++ linux-3.1-vs2.3.1-rc2/fs/ext3/ialloc.c      2011-10-24 18:53:33.000000000 +0200
4372 @@ -23,6 +23,7 @@
4373  #include <linux/buffer_head.h>
4374  #include <linux/random.h>
4375  #include <linux/bitops.h>
4376 +#include <linux/vs_tag.h>
4377  #include <trace/events/ext3.h>
4378  
4379  #include <asm/byteorder.h>
4380 @@ -535,6 +536,7 @@ got:
4381                 inode->i_mode = mode;
4382                 inode->i_uid = current_fsuid();
4383                 inode->i_gid = dir->i_gid;
4384 +               inode->i_tag = dx_current_fstag(sb);
4385         } else
4386                 inode_init_owner(inode, dir, mode);
4387  
4388 diff -NurpP --minimal linux-3.1/fs/ext3/inode.c linux-3.1-vs2.3.1-rc2/fs/ext3/inode.c
4389 --- linux-3.1/fs/ext3/inode.c   2011-10-24 18:45:27.000000000 +0200
4390 +++ linux-3.1-vs2.3.1-rc2/fs/ext3/inode.c       2011-10-24 18:53:33.000000000 +0200
4391 @@ -38,6 +38,7 @@
4392  #include <linux/bio.h>
4393  #include <linux/fiemap.h>
4394  #include <linux/namei.h>
4395 +#include <linux/vs_tag.h>
4396  #include <trace/events/ext3.h>
4397  #include "xattr.h"
4398  #include "acl.h"
4399 @@ -2834,36 +2835,60 @@ void ext3_set_inode_flags(struct inode *
4400  {
4401         unsigned int flags = EXT3_I(inode)->i_flags;
4402  
4403 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4404 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4405 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4406 +
4407 +       if (flags & EXT3_IMMUTABLE_FL)
4408 +               inode->i_flags |= S_IMMUTABLE;
4409 +       if (flags & EXT3_IXUNLINK_FL)
4410 +               inode->i_flags |= S_IXUNLINK;
4411 +
4412         if (flags & EXT3_SYNC_FL)
4413                 inode->i_flags |= S_SYNC;
4414         if (flags & EXT3_APPEND_FL)
4415                 inode->i_flags |= S_APPEND;
4416 -       if (flags & EXT3_IMMUTABLE_FL)
4417 -               inode->i_flags |= S_IMMUTABLE;
4418         if (flags & EXT3_NOATIME_FL)
4419                 inode->i_flags |= S_NOATIME;
4420         if (flags & EXT3_DIRSYNC_FL)
4421                 inode->i_flags |= S_DIRSYNC;
4422 +
4423 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4424 +
4425 +       if (flags & EXT3_BARRIER_FL)
4426 +               inode->i_vflags |= V_BARRIER;
4427 +       if (flags & EXT3_COW_FL)
4428 +               inode->i_vflags |= V_COW;
4429  }
4430  
4431  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
4432  void ext3_get_inode_flags(struct ext3_inode_info *ei)
4433  {
4434         unsigned int flags = ei->vfs_inode.i_flags;
4435 +       unsigned int vflags = ei->vfs_inode.i_vflags;
4436 +
4437 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
4438 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
4439 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
4440 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
4441 +
4442 +       if (flags & S_IMMUTABLE)
4443 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
4444 +       if (flags & S_IXUNLINK)
4445 +               ei->i_flags |= EXT3_IXUNLINK_FL;
4446  
4447 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
4448 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
4449         if (flags & S_SYNC)
4450                 ei->i_flags |= EXT3_SYNC_FL;
4451         if (flags & S_APPEND)
4452                 ei->i_flags |= EXT3_APPEND_FL;
4453 -       if (flags & S_IMMUTABLE)
4454 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
4455         if (flags & S_NOATIME)
4456                 ei->i_flags |= EXT3_NOATIME_FL;
4457         if (flags & S_DIRSYNC)
4458                 ei->i_flags |= EXT3_DIRSYNC_FL;
4459 +
4460 +       if (vflags & V_BARRIER)
4461 +               ei->i_flags |= EXT3_BARRIER_FL;
4462 +       if (vflags & V_COW)
4463 +               ei->i_flags |= EXT3_COW_FL;
4464  }
4465  
4466  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
4467 @@ -2877,6 +2902,8 @@ struct inode *ext3_iget(struct super_blo
4468         transaction_t *transaction;
4469         long ret;
4470         int block;
4471 +       uid_t uid;
4472 +       gid_t gid;
4473  
4474         inode = iget_locked(sb, ino);
4475         if (!inode)
4476 @@ -2893,12 +2920,17 @@ struct inode *ext3_iget(struct super_blo
4477         bh = iloc.bh;
4478         raw_inode = ext3_raw_inode(&iloc);
4479         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4480 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4481 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4482 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4483 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4484         if(!(test_opt (inode->i_sb, NO_UID32))) {
4485 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4486 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4487 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4488 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4489         }
4490 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4491 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4492 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4493 +               le16_to_cpu(raw_inode->i_raw_tag));
4494 +
4495         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4496         inode->i_size = le32_to_cpu(raw_inode->i_size);
4497         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
4498 @@ -3053,6 +3085,8 @@ static int ext3_do_update_inode(handle_t
4499         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
4500         struct ext3_inode_info *ei = EXT3_I(inode);
4501         struct buffer_head *bh = iloc->bh;
4502 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4503 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4504         int err = 0, rc, block;
4505  
4506  again:
4507 @@ -3067,29 +3101,32 @@ again:
4508         ext3_get_inode_flags(ei);
4509         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
4510         if(!(test_opt(inode->i_sb, NO_UID32))) {
4511 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
4512 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
4513 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
4514 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
4515  /*
4516   * Fix up interoperability with old kernels. Otherwise, old inodes get
4517   * re-used with the upper 16 bits of the uid/gid intact
4518   */
4519                 if(!ei->i_dtime) {
4520                         raw_inode->i_uid_high =
4521 -                               cpu_to_le16(high_16_bits(inode->i_uid));
4522 +                               cpu_to_le16(high_16_bits(uid));
4523                         raw_inode->i_gid_high =
4524 -                               cpu_to_le16(high_16_bits(inode->i_gid));
4525 +                               cpu_to_le16(high_16_bits(gid));
4526                 } else {
4527                         raw_inode->i_uid_high = 0;
4528                         raw_inode->i_gid_high = 0;
4529                 }
4530         } else {
4531                 raw_inode->i_uid_low =
4532 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
4533 +                       cpu_to_le16(fs_high2lowuid(uid));
4534                 raw_inode->i_gid_low =
4535 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4536 +                       cpu_to_le16(fs_high2lowgid(gid));
4537                 raw_inode->i_uid_high = 0;
4538                 raw_inode->i_gid_high = 0;
4539         }
4540 +#ifdef CONFIG_TAGGING_INTERN
4541 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4542 +#endif
4543         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4544         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
4545         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4546 @@ -3249,7 +3286,8 @@ int ext3_setattr(struct dentry *dentry, 
4547         if (is_quota_modification(inode, attr))
4548                 dquot_initialize(inode);
4549         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4550 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4551 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4552 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4553                 handle_t *handle;
4554  
4555                 /* (user+group)*(old+new) structure, inode write (sb,
4556 @@ -3271,6 +3309,8 @@ int ext3_setattr(struct dentry *dentry, 
4557                         inode->i_uid = attr->ia_uid;
4558                 if (attr->ia_valid & ATTR_GID)
4559                         inode->i_gid = attr->ia_gid;
4560 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4561 +                       inode->i_tag = attr->ia_tag;
4562                 error = ext3_mark_inode_dirty(handle, inode);
4563                 ext3_journal_stop(handle);
4564         }
4565 diff -NurpP --minimal linux-3.1/fs/ext3/ioctl.c linux-3.1-vs2.3.1-rc2/fs/ext3/ioctl.c
4566 --- linux-3.1/fs/ext3/ioctl.c   2011-10-24 18:45:27.000000000 +0200
4567 +++ linux-3.1-vs2.3.1-rc2/fs/ext3/ioctl.c       2011-10-24 18:53:33.000000000 +0200
4568 @@ -8,6 +8,7 @@
4569   */
4570  
4571  #include <linux/fs.h>
4572 +#include <linux/mount.h>
4573  #include <linux/jbd.h>
4574  #include <linux/capability.h>
4575  #include <linux/ext3_fs.h>
4576 @@ -17,6 +18,34 @@
4577  #include <linux/compat.h>
4578  #include <asm/uaccess.h>
4579  
4580 +
4581 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
4582 +{
4583 +       handle_t *handle = NULL;
4584 +       struct ext3_iloc iloc;
4585 +       int err;
4586 +
4587 +       handle = ext3_journal_start(inode, 1);
4588 +       if (IS_ERR(handle))
4589 +               return PTR_ERR(handle);
4590 +
4591 +       if (IS_SYNC(inode))
4592 +               handle->h_sync = 1;
4593 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
4594 +       if (err)
4595 +               goto flags_err;
4596 +
4597 +       inode->i_flags = flags;
4598 +       inode->i_vflags = vflags;
4599 +       ext3_get_inode_flags(EXT3_I(inode));
4600 +       inode->i_ctime = CURRENT_TIME_SEC;
4601 +
4602 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
4603 +flags_err:
4604 +       ext3_journal_stop(handle);
4605 +       return err;
4606 +}
4607 +
4608  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4609  {
4610         struct inode *inode = filp->f_dentry->d_inode;
4611 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
4612  
4613                 flags = ext3_mask_flags(inode->i_mode, flags);
4614  
4615 +               if (IS_BARRIER(inode)) {
4616 +                       vxwprintk_task(1, "messing with the barrier.");
4617 +                       return -EACCES;
4618 +               }
4619 +
4620                 mutex_lock(&inode->i_mutex);
4621  
4622                 /* Is it quota file? Do not allow user to mess with it */
4623 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
4624                  *
4625                  * This test looks nicer. Thanks to Pauline Middelink
4626                  */
4627 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
4628 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
4629 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
4630 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
4631                         if (!capable(CAP_LINUX_IMMUTABLE))
4632                                 goto flags_out;
4633                 }
4634 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
4635                 if (err)
4636                         goto flags_err;
4637  
4638 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
4639 +               flags &= EXT3_FL_USER_MODIFIABLE;
4640                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
4641                 ei->i_flags = flags;
4642  
4643 diff -NurpP --minimal linux-3.1/fs/ext3/namei.c linux-3.1-vs2.3.1-rc2/fs/ext3/namei.c
4644 --- linux-3.1/fs/ext3/namei.c   2011-10-24 18:45:27.000000000 +0200
4645 +++ linux-3.1-vs2.3.1-rc2/fs/ext3/namei.c       2011-10-24 18:53:33.000000000 +0200
4646 @@ -36,6 +36,7 @@
4647  #include <linux/quotaops.h>
4648  #include <linux/buffer_head.h>
4649  #include <linux/bio.h>
4650 +#include <linux/vs_tag.h>
4651  #include <trace/events/ext3.h>
4652  
4653  #include "namei.h"
4654 @@ -925,6 +926,7 @@ restart:
4655                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
4656                                                     1, &bh);
4657                         }
4658 +               dx_propagate_tag(nd, inode);
4659                 }
4660                 if ((bh = bh_use[ra_ptr++]) == NULL)
4661                         goto next;
4662 @@ -2535,6 +2537,7 @@ const struct inode_operations ext3_dir_i
4663         .listxattr      = ext3_listxattr,
4664         .removexattr    = generic_removexattr,
4665  #endif
4666 +       .sync_flags     = ext3_sync_flags,
4667         .get_acl        = ext3_get_acl,
4668  };
4669  
4670 diff -NurpP --minimal linux-3.1/fs/ext3/super.c linux-3.1-vs2.3.1-rc2/fs/ext3/super.c
4671 --- linux-3.1/fs/ext3/super.c   2011-10-24 18:45:27.000000000 +0200
4672 +++ linux-3.1-vs2.3.1-rc2/fs/ext3/super.c       2011-10-24 18:53:33.000000000 +0200
4673 @@ -833,7 +833,8 @@ enum {
4674         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
4675         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
4676         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
4677 -       Opt_resize, Opt_usrquota, Opt_grpquota
4678 +       Opt_resize, Opt_usrquota, Opt_grpquota,
4679 +       Opt_tag, Opt_notag, Opt_tagid
4680  };
4681  
4682  static const match_table_t tokens = {
4683 @@ -890,6 +891,9 @@ static const match_table_t tokens = {
4684         {Opt_barrier, "barrier"},
4685         {Opt_nobarrier, "nobarrier"},
4686         {Opt_resize, "resize"},
4687 +       {Opt_tag, "tag"},
4688 +       {Opt_notag, "notag"},
4689 +       {Opt_tagid, "tagid=%u"},
4690         {Opt_err, NULL},
4691  };
4692  
4693 @@ -1042,6 +1046,20 @@ static int parse_options (char *options,
4694                 case Opt_nouid32:
4695                         set_opt (sbi->s_mount_opt, NO_UID32);
4696                         break;
4697 +#ifndef CONFIG_TAGGING_NONE
4698 +               case Opt_tag:
4699 +                       set_opt (sbi->s_mount_opt, TAGGED);
4700 +                       break;
4701 +               case Opt_notag:
4702 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4703 +                       break;
4704 +#endif
4705 +#ifdef CONFIG_PROPAGATE
4706 +               case Opt_tagid:
4707 +                       /* use args[0] */
4708 +                       set_opt (sbi->s_mount_opt, TAGGED);
4709 +                       break;
4710 +#endif
4711                 case Opt_nocheck:
4712                         clear_opt (sbi->s_mount_opt, CHECK);
4713                         break;
4714 @@ -1738,6 +1756,9 @@ static int ext3_fill_super (struct super
4715                             NULL, 0))
4716                 goto failed_mount;
4717  
4718 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
4719 +               sb->s_flags |= MS_TAGGED;
4720 +
4721         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4722                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
4723  
4724 @@ -2619,6 +2640,14 @@ static int ext3_remount (struct super_bl
4725         if (test_opt(sb, ABORT))
4726                 ext3_abort(sb, __func__, "Abort forced by user");
4727  
4728 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
4729 +               !(sb->s_flags & MS_TAGGED)) {
4730 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
4731 +                       sb->s_id);
4732 +               err = -EINVAL;
4733 +               goto restore_opts;
4734 +       }
4735 +
4736         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4737                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
4738  
4739 diff -NurpP --minimal linux-3.1/fs/ext4/ext4.h linux-3.1-vs2.3.1-rc2/fs/ext4/ext4.h
4740 --- linux-3.1/fs/ext4/ext4.h    2011-10-24 18:45:27.000000000 +0200
4741 +++ linux-3.1-vs2.3.1-rc2/fs/ext4/ext4.h        2011-10-24 18:53:33.000000000 +0200
4742 @@ -351,8 +351,12 @@ struct flex_groups {
4743  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
4744  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
4745  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
4746 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
4747  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
4748  
4749 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
4750 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
4751 +
4752  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
4753  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
4754  
4755 @@ -610,7 +614,8 @@ struct ext4_inode {
4756                         __le16  l_i_file_acl_high;
4757                         __le16  l_i_uid_high;   /* these 2 fields */
4758                         __le16  l_i_gid_high;   /* were reserved2[0] */
4759 -                       __u32   l_i_reserved2;
4760 +                       __le16  l_i_tag;        /* Context Tag */
4761 +                       __u16   l_i_reserved2;
4762                 } linux2;
4763                 struct {
4764                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
4765 @@ -728,6 +733,7 @@ do {                                                                               \
4766  #define i_gid_low      i_gid
4767  #define i_uid_high     osd2.linux2.l_i_uid_high
4768  #define i_gid_high     osd2.linux2.l_i_gid_high
4769 +#define i_raw_tag      osd2.linux2.l_i_tag
4770  #define i_reserved2    osd2.linux2.l_i_reserved2
4771  
4772  #elif defined(__GNU__)
4773 @@ -904,6 +910,7 @@ struct ext4_inode_info {
4774  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
4775  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
4776  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
4777 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
4778  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
4779  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
4780  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
4781 @@ -2218,6 +2225,7 @@ extern int ext4_map_blocks(handle_t *han
4782                            struct ext4_map_blocks *map, int flags);
4783  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4784                         __u64 start, __u64 len);
4785 +extern int ext4_sync_flags(struct inode *, int, int);
4786  /* move_extent.c */
4787  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
4788                              __u64 start_orig, __u64 start_donor,
4789 diff -NurpP --minimal linux-3.1/fs/ext4/file.c linux-3.1-vs2.3.1-rc2/fs/ext4/file.c
4790 --- linux-3.1/fs/ext4/file.c    2011-10-24 18:45:27.000000000 +0200
4791 +++ linux-3.1-vs2.3.1-rc2/fs/ext4/file.c        2011-10-24 18:53:33.000000000 +0200
4792 @@ -303,5 +303,6 @@ const struct inode_operations ext4_file_
4793  #endif
4794         .get_acl        = ext4_get_acl,
4795         .fiemap         = ext4_fiemap,
4796 +       .sync_flags     = ext4_sync_flags,
4797  };
4798  
4799 diff -NurpP --minimal linux-3.1/fs/ext4/ialloc.c linux-3.1-vs2.3.1-rc2/fs/ext4/ialloc.c
4800 --- linux-3.1/fs/ext4/ialloc.c  2011-10-24 18:45:27.000000000 +0200
4801 +++ linux-3.1-vs2.3.1-rc2/fs/ext4/ialloc.c      2011-10-24 18:53:33.000000000 +0200
4802 @@ -22,6 +22,7 @@
4803  #include <linux/random.h>
4804  #include <linux/bitops.h>
4805  #include <linux/blkdev.h>
4806 +#include <linux/vs_tag.h>
4807  #include <asm/byteorder.h>
4808  
4809  #include "ext4.h"
4810 @@ -992,6 +993,7 @@ got:
4811                 inode->i_mode = mode;
4812                 inode->i_uid = current_fsuid();
4813                 inode->i_gid = dir->i_gid;
4814 +               inode->i_tag = dx_current_fstag(sb);
4815         } else
4816                 inode_init_owner(inode, dir, mode);
4817  
4818 diff -NurpP --minimal linux-3.1/fs/ext4/inode.c linux-3.1-vs2.3.1-rc2/fs/ext4/inode.c
4819 --- linux-3.1/fs/ext4/inode.c   2011-10-24 18:45:27.000000000 +0200
4820 +++ linux-3.1-vs2.3.1-rc2/fs/ext4/inode.c       2011-10-24 18:53:33.000000000 +0200
4821 @@ -38,6 +38,7 @@
4822  #include <linux/printk.h>
4823  #include <linux/slab.h>
4824  #include <linux/ratelimit.h>
4825 +#include <linux/vs_tag.h>
4826  
4827  #include "ext4_jbd2.h"
4828  #include "xattr.h"
4829 @@ -3323,41 +3324,64 @@ void ext4_set_inode_flags(struct inode *
4830  {
4831         unsigned int flags = EXT4_I(inode)->i_flags;
4832  
4833 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4834 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4835 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4836 +
4837 +       if (flags & EXT4_IMMUTABLE_FL)
4838 +               inode->i_flags |= S_IMMUTABLE;
4839 +       if (flags & EXT4_IXUNLINK_FL)
4840 +               inode->i_flags |= S_IXUNLINK;
4841 +
4842         if (flags & EXT4_SYNC_FL)
4843                 inode->i_flags |= S_SYNC;
4844         if (flags & EXT4_APPEND_FL)
4845                 inode->i_flags |= S_APPEND;
4846 -       if (flags & EXT4_IMMUTABLE_FL)
4847 -               inode->i_flags |= S_IMMUTABLE;
4848         if (flags & EXT4_NOATIME_FL)
4849                 inode->i_flags |= S_NOATIME;
4850         if (flags & EXT4_DIRSYNC_FL)
4851                 inode->i_flags |= S_DIRSYNC;
4852 +
4853 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4854 +
4855 +       if (flags & EXT4_BARRIER_FL)
4856 +               inode->i_vflags |= V_BARRIER;
4857 +       if (flags & EXT4_COW_FL)
4858 +               inode->i_vflags |= V_COW;
4859  }
4860  
4861  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
4862  void ext4_get_inode_flags(struct ext4_inode_info *ei)
4863  {
4864 -       unsigned int vfs_fl;
4865 +       unsigned int vfs_fl, vfs_vf;
4866         unsigned long old_fl, new_fl;
4867  
4868         do {
4869                 vfs_fl = ei->vfs_inode.i_flags;
4870 +               vfs_vf = ei->vfs_inode.i_vflags;
4871                 old_fl = ei->i_flags;
4872                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
4873                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
4874 -                               EXT4_DIRSYNC_FL);
4875 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
4876 +                               EXT4_COW_FL);
4877 +
4878 +               if (vfs_fl & S_IMMUTABLE)
4879 +                       new_fl |= EXT4_IMMUTABLE_FL;
4880 +               if (vfs_fl & S_IXUNLINK)
4881 +                       new_fl |= EXT4_IXUNLINK_FL;
4882 +
4883                 if (vfs_fl & S_SYNC)
4884                         new_fl |= EXT4_SYNC_FL;
4885                 if (vfs_fl & S_APPEND)
4886                         new_fl |= EXT4_APPEND_FL;
4887 -               if (vfs_fl & S_IMMUTABLE)
4888 -                       new_fl |= EXT4_IMMUTABLE_FL;
4889                 if (vfs_fl & S_NOATIME)
4890                         new_fl |= EXT4_NOATIME_FL;
4891                 if (vfs_fl & S_DIRSYNC)
4892                         new_fl |= EXT4_DIRSYNC_FL;
4893 +
4894 +               if (vfs_vf & V_BARRIER)
4895 +                       new_fl |= EXT4_BARRIER_FL;
4896 +               if (vfs_vf & V_COW)
4897 +                       new_fl |= EXT4_COW_FL;
4898         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
4899  }
4900  
4901 @@ -3393,6 +3417,8 @@ struct inode *ext4_iget(struct super_blo
4902         journal_t *journal = EXT4_SB(sb)->s_journal;
4903         long ret;
4904         int block;
4905 +       uid_t uid;
4906 +       gid_t gid;
4907  
4908         inode = iget_locked(sb, ino);
4909         if (!inode)
4910 @@ -3408,12 +3434,16 @@ struct inode *ext4_iget(struct super_blo
4911                 goto bad_inode;
4912         raw_inode = ext4_raw_inode(&iloc);
4913         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4914 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4915 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4916 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4917 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4918         if (!(test_opt(inode->i_sb, NO_UID32))) {
4919 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4920 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4921 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4922 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4923         }
4924 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4925 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4926 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4927 +               le16_to_cpu(raw_inode->i_raw_tag));
4928         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4929  
4930         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
4931 @@ -3632,6 +3662,8 @@ static int ext4_do_update_inode(handle_t
4932         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
4933         struct ext4_inode_info *ei = EXT4_I(inode);
4934         struct buffer_head *bh = iloc->bh;
4935 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4936 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4937         int err = 0, rc, block;
4938  
4939         /* For fields not not tracking in the in-memory inode,
4940 @@ -3642,29 +3674,32 @@ static int ext4_do_update_inode(handle_t
4941         ext4_get_inode_flags(ei);
4942         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
4943         if (!(test_opt(inode->i_sb, NO_UID32))) {
4944 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
4945 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
4946 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
4947 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
4948  /*
4949   * Fix up interoperability with old kernels. Otherwise, old inodes get
4950   * re-used with the upper 16 bits of the uid/gid intact
4951   */
4952                 if (!ei->i_dtime) {
4953                         raw_inode->i_uid_high =
4954 -                               cpu_to_le16(high_16_bits(inode->i_uid));
4955 +                               cpu_to_le16(high_16_bits(uid));
4956                         raw_inode->i_gid_high =
4957 -                               cpu_to_le16(high_16_bits(inode->i_gid));
4958 +                               cpu_to_le16(high_16_bits(gid));
4959                 } else {
4960                         raw_inode->i_uid_high = 0;
4961                         raw_inode->i_gid_high = 0;
4962                 }
4963         } else {
4964                 raw_inode->i_uid_low =
4965 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
4966 +                       cpu_to_le16(fs_high2lowuid(uid));
4967                 raw_inode->i_gid_low =
4968 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4969 +                       cpu_to_le16(fs_high2lowgid(gid));
4970                 raw_inode->i_uid_high = 0;
4971                 raw_inode->i_gid_high = 0;
4972         }
4973 +#ifdef CONFIG_TAGGING_INTERN
4974 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4975 +#endif
4976         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4977  
4978         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
4979 @@ -3850,7 +3885,8 @@ int ext4_setattr(struct dentry *dentry, 
4980         if (is_quota_modification(inode, attr))
4981                 dquot_initialize(inode);
4982         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4983 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4984 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4985 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4986                 handle_t *handle;
4987  
4988                 /* (user+group)*(old+new) structure, inode write (sb,
4989 @@ -3872,6 +3908,8 @@ int ext4_setattr(struct dentry *dentry, 
4990                         inode->i_uid = attr->ia_uid;
4991                 if (attr->ia_valid & ATTR_GID)
4992                         inode->i_gid = attr->ia_gid;
4993 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4994 +                       inode->i_tag = attr->ia_tag;
4995                 error = ext4_mark_inode_dirty(handle, inode);
4996                 ext4_journal_stop(handle);
4997         }
4998 diff -NurpP --minimal linux-3.1/fs/ext4/ioctl.c linux-3.1-vs2.3.1-rc2/fs/ext4/ioctl.c
4999 --- linux-3.1/fs/ext4/ioctl.c   2011-10-24 18:45:27.000000000 +0200
5000 +++ linux-3.1-vs2.3.1-rc2/fs/ext4/ioctl.c       2011-10-24 18:53:33.000000000 +0200
5001 @@ -14,10 +14,39 @@
5002  #include <linux/compat.h>
5003  #include <linux/mount.h>
5004  #include <linux/file.h>
5005 +#include <linux/vs_tag.h>
5006  #include <asm/uaccess.h>
5007  #include "ext4_jbd2.h"
5008  #include "ext4.h"
5009  
5010 +
5011 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
5012 +{
5013 +       handle_t *handle = NULL;
5014 +       struct ext4_iloc iloc;
5015 +       int err;
5016 +
5017 +       handle = ext4_journal_start(inode, 1);
5018 +       if (IS_ERR(handle))
5019 +               return PTR_ERR(handle);
5020 +
5021 +       if (IS_SYNC(inode))
5022 +               ext4_handle_sync(handle);
5023 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
5024 +       if (err)
5025 +               goto flags_err;
5026 +
5027 +       inode->i_flags = flags;
5028 +       inode->i_vflags = vflags;
5029 +       ext4_get_inode_flags(EXT4_I(inode));
5030 +       inode->i_ctime = ext4_current_time(inode);
5031 +
5032 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
5033 +flags_err:
5034 +       ext4_journal_stop(handle);
5035 +       return err;
5036 +}
5037 +
5038  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5039  {
5040         struct inode *inode = filp->f_dentry->d_inode;
5041 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
5042  
5043                 flags = ext4_mask_flags(inode->i_mode, flags);
5044  
5045 +               if (IS_BARRIER(inode)) {
5046 +                       vxwprintk_task(1, "messing with the barrier.");
5047 +                       return -EACCES;
5048 +               }
5049 +
5050                 err = -EPERM;
5051                 mutex_lock(&inode->i_mutex);
5052                 /* Is it quota file? Do not allow user to mess with it */
5053 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
5054                  *
5055                  * This test looks nicer. Thanks to Pauline Middelink
5056                  */
5057 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
5058 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
5059 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
5060 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
5061                         if (!capable(CAP_LINUX_IMMUTABLE))
5062                                 goto flags_out;
5063                 }
5064 diff -NurpP --minimal linux-3.1/fs/ext4/namei.c linux-3.1-vs2.3.1-rc2/fs/ext4/namei.c
5065 --- linux-3.1/fs/ext4/namei.c   2011-10-24 18:45:27.000000000 +0200
5066 +++ linux-3.1-vs2.3.1-rc2/fs/ext4/namei.c       2011-10-24 18:53:33.000000000 +0200
5067 @@ -34,6 +34,7 @@
5068  #include <linux/quotaops.h>
5069  #include <linux/buffer_head.h>
5070  #include <linux/bio.h>
5071 +#include <linux/vs_tag.h>
5072  #include "ext4.h"
5073  #include "ext4_jbd2.h"
5074  
5075 @@ -925,6 +926,7 @@ restart:
5076                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
5077                                                     1, &bh);
5078                         }
5079 +               dx_propagate_tag(nd, inode);
5080                 }
5081                 if ((bh = bh_use[ra_ptr++]) == NULL)
5082                         goto next;
5083 @@ -2588,6 +2590,7 @@ const struct inode_operations ext4_dir_i
5084  #endif
5085         .get_acl        = ext4_get_acl,
5086         .fiemap         = ext4_fiemap,
5087 +       .sync_flags     = ext4_sync_flags,
5088  };
5089  
5090  const struct inode_operations ext4_special_inode_operations = {
5091 diff -NurpP --minimal linux-3.1/fs/ext4/super.c linux-3.1-vs2.3.1-rc2/fs/ext4/super.c
5092 --- linux-3.1/fs/ext4/super.c   2011-10-24 18:45:27.000000000 +0200
5093 +++ linux-3.1-vs2.3.1-rc2/fs/ext4/super.c       2011-10-24 18:53:33.000000000 +0200
5094 @@ -1320,6 +1320,7 @@ enum {
5095         Opt_dioread_nolock, Opt_dioread_lock,
5096         Opt_discard, Opt_nodiscard,
5097         Opt_init_inode_table, Opt_noinit_inode_table,
5098 +       Opt_tag, Opt_notag, Opt_tagid
5099  };
5100  
5101  static const match_table_t tokens = {
5102 @@ -1395,6 +1396,9 @@ static const match_table_t tokens = {
5103         {Opt_init_inode_table, "init_itable=%u"},
5104         {Opt_init_inode_table, "init_itable"},
5105         {Opt_noinit_inode_table, "noinit_itable"},
5106 +       {Opt_tag, "tag"},
5107 +       {Opt_notag, "notag"},
5108 +       {Opt_tagid, "tagid=%u"},
5109         {Opt_err, NULL},
5110  };
5111  
5112 @@ -1563,6 +1567,20 @@ static int parse_options(char *options, 
5113                 case Opt_nouid32:
5114                         set_opt(sb, NO_UID32);
5115                         break;
5116 +#ifndef CONFIG_TAGGING_NONE
5117 +               case Opt_tag:
5118 +                       set_opt(sb, TAGGED);
5119 +                       break;
5120 +               case Opt_notag:
5121 +                       clear_opt(sb, TAGGED);
5122 +                       break;
5123 +#endif
5124 +#ifdef CONFIG_PROPAGATE
5125 +               case Opt_tagid:
5126 +                       /* use args[0] */
5127 +                       set_opt(sb, TAGGED);
5128 +                       break;
5129 +#endif
5130                 case Opt_debug:
5131                         set_opt(sb, DEBUG);
5132                         break;
5133 @@ -3224,6 +3242,9 @@ static int ext4_fill_super(struct super_
5134                            &journal_ioprio, NULL, 0))
5135                 goto failed_mount;
5136  
5137 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
5138 +               sb->s_flags |= MS_TAGGED;
5139 +
5140         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
5141                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
5142  
5143 @@ -4351,6 +4372,14 @@ static int ext4_remount(struct super_blo
5144         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
5145                 ext4_abort(sb, "Abort forced by user");
5146  
5147 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
5148 +               !(sb->s_flags & MS_TAGGED)) {
5149 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
5150 +                       sb->s_id);
5151 +               err = -EINVAL;
5152 +               goto restore_opts;
5153 +       }
5154 +
5155         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
5156                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
5157  
5158 diff -NurpP --minimal linux-3.1/fs/fcntl.c linux-3.1-vs2.3.1-rc2/fs/fcntl.c
5159 --- linux-3.1/fs/fcntl.c        2011-05-22 16:17:52.000000000 +0200
5160 +++ linux-3.1-vs2.3.1-rc2/fs/fcntl.c    2011-10-24 18:53:33.000000000 +0200
5161 @@ -20,6 +20,7 @@
5162  #include <linux/signal.h>
5163  #include <linux/rcupdate.h>
5164  #include <linux/pid_namespace.h>
5165 +#include <linux/vs_limit.h>
5166  
5167  #include <asm/poll.h>
5168  #include <asm/siginfo.h>
5169 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
5170  
5171         if (tofree)
5172                 filp_close(tofree, files);
5173 +       else
5174 +               vx_openfd_inc(newfd);   /* fd was unused */
5175  
5176         return newfd;
5177  
5178 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
5179         filp = fget_raw(fd);
5180         if (!filp)
5181                 goto out;
5182 +       if (!vx_files_avail(1))
5183 +               goto out;
5184  
5185         if (unlikely(filp->f_mode & FMODE_PATH)) {
5186                 if (!check_fcntl_cmd(cmd)) {
5187 diff -NurpP --minimal linux-3.1/fs/file.c linux-3.1-vs2.3.1-rc2/fs/file.c
5188 --- linux-3.1/fs/file.c 2011-05-22 16:17:52.000000000 +0200
5189 +++ linux-3.1-vs2.3.1-rc2/fs/file.c     2011-10-24 18:53:33.000000000 +0200
5190 @@ -21,6 +21,7 @@
5191  #include <linux/spinlock.h>
5192  #include <linux/rcupdate.h>
5193  #include <linux/workqueue.h>
5194 +#include <linux/vs_limit.h>
5195  
5196  struct fdtable_defer {
5197         spinlock_t lock;
5198 @@ -359,6 +360,8 @@ struct files_struct *dup_fd(struct files
5199                 struct file *f = *old_fds++;
5200                 if (f) {
5201                         get_file(f);
5202 +                       /* TODO: sum it first for check and performance */
5203 +                       vx_openfd_inc(open_files - i);
5204                 } else {
5205                         /*
5206                          * The fd may be claimed in the fd bitmap but not yet
5207 @@ -466,6 +469,7 @@ repeat:
5208         else
5209                 FD_CLR(fd, fdt->close_on_exec);
5210         error = fd;
5211 +       vx_openfd_inc(fd);
5212  #if 1
5213         /* Sanity check */
5214         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
5215 diff -NurpP --minimal linux-3.1/fs/file_table.c linux-3.1-vs2.3.1-rc2/fs/file_table.c
5216 --- linux-3.1/fs/file_table.c   2011-10-24 18:45:27.000000000 +0200
5217 +++ linux-3.1-vs2.3.1-rc2/fs/file_table.c       2011-10-24 18:53:33.000000000 +0200
5218 @@ -24,6 +24,8 @@
5219  #include <linux/percpu_counter.h>
5220  #include <linux/percpu.h>
5221  #include <linux/ima.h>
5222 +#include <linux/vs_limit.h>
5223 +#include <linux/vs_context.h>
5224  
5225  #include <linux/atomic.h>
5226  
5227 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
5228         spin_lock_init(&f->f_lock);
5229         eventpoll_init_file(f);
5230         /* f->f_version: 0 */
5231 +       f->f_xid = vx_current_xid();
5232 +       vx_files_inc(f);
5233         return f;
5234  
5235  over:
5236 @@ -253,6 +257,8 @@ static void __fput(struct file *file)
5237         }
5238         fops_put(file->f_op);
5239         put_pid(file->f_owner.pid);
5240 +       vx_files_dec(file);
5241 +       file->f_xid = 0;
5242         file_sb_list_del(file);
5243         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
5244                 i_readcount_dec(inode);
5245 @@ -383,6 +389,8 @@ void put_filp(struct file *file)
5246  {
5247         if (atomic_long_dec_and_test(&file->f_count)) {
5248                 security_file_free(file);
5249 +               vx_files_dec(file);
5250 +               file->f_xid = 0;
5251                 file_sb_list_del(file);
5252                 file_free(file);
5253         }
5254 diff -NurpP --minimal linux-3.1/fs/fs_struct.c linux-3.1-vs2.3.1-rc2/fs/fs_struct.c
5255 --- linux-3.1/fs/fs_struct.c    2011-03-15 18:07:31.000000000 +0100
5256 +++ linux-3.1-vs2.3.1-rc2/fs/fs_struct.c        2011-10-24 18:53:33.000000000 +0200
5257 @@ -4,6 +4,7 @@
5258  #include <linux/path.h>
5259  #include <linux/slab.h>
5260  #include <linux/fs_struct.h>
5261 +#include <linux/vserver/global.h>
5262  #include "internal.h"
5263  
5264  static inline void path_get_longterm(struct path *path)
5265 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
5266  {
5267         path_put_longterm(&fs->root);
5268         path_put_longterm(&fs->pwd);
5269 +       atomic_dec(&vs_global_fs);
5270         kmem_cache_free(fs_cachep, fs);
5271  }
5272  
5273 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
5274                 fs->pwd = old->pwd;
5275                 path_get_longterm(&fs->pwd);
5276                 spin_unlock(&old->lock);
5277 +               atomic_inc(&vs_global_fs);
5278         }
5279         return fs;
5280  }
5281 diff -NurpP --minimal linux-3.1/fs/gfs2/file.c linux-3.1-vs2.3.1-rc2/fs/gfs2/file.c
5282 --- linux-3.1/fs/gfs2/file.c    2011-10-24 18:45:27.000000000 +0200
5283 +++ linux-3.1-vs2.3.1-rc2/fs/gfs2/file.c        2011-10-24 18:53:33.000000000 +0200
5284 @@ -134,6 +134,9 @@ static const u32 fsflags_to_gfs2[32] = {
5285         [7] = GFS2_DIF_NOATIME,
5286         [12] = GFS2_DIF_EXHASH,
5287         [14] = GFS2_DIF_INHERIT_JDATA,
5288 +       [27] = GFS2_DIF_IXUNLINK,
5289 +       [26] = GFS2_DIF_BARRIER,
5290 +       [29] = GFS2_DIF_COW,
5291  };
5292  
5293  static const u32 gfs2_to_fsflags[32] = {
5294 @@ -143,6 +146,9 @@ static const u32 gfs2_to_fsflags[32] = {
5295         [gfs2fl_NoAtime] = FS_NOATIME_FL,
5296         [gfs2fl_ExHash] = FS_INDEX_FL,
5297         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
5298 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
5299 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
5300 +       [gfs2fl_Cow] = FS_COW_FL,
5301  };
5302  
5303  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
5304 @@ -173,12 +179,18 @@ void gfs2_set_inode_flags(struct inode *
5305  {
5306         struct gfs2_inode *ip = GFS2_I(inode);
5307         unsigned int flags = inode->i_flags;
5308 +       unsigned int vflags = inode->i_vflags;
5309 +
5310 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5311 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
5312  
5313 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
5314         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
5315                 inode->i_flags |= S_NOSEC;
5316         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
5317                 flags |= S_IMMUTABLE;
5318 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
5319 +               flags |= S_IXUNLINK;
5320 +
5321         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
5322                 flags |= S_APPEND;
5323         if (ip->i_diskflags & GFS2_DIF_NOATIME)
5324 @@ -186,6 +198,43 @@ void gfs2_set_inode_flags(struct inode *
5325         if (ip->i_diskflags & GFS2_DIF_SYNC)
5326                 flags |= S_SYNC;
5327         inode->i_flags = flags;
5328 +
5329 +       vflags &= ~(V_BARRIER | V_COW);
5330 +
5331 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
5332 +               vflags |= V_BARRIER;
5333 +       if (ip->i_diskflags & GFS2_DIF_COW)
5334 +               vflags |= V_COW;
5335 +       inode->i_vflags = vflags;
5336 +}
5337 +
5338 +void gfs2_get_inode_flags(struct inode *inode)
5339 +{
5340 +       struct gfs2_inode *ip = GFS2_I(inode);
5341 +       unsigned int flags = inode->i_flags;
5342 +       unsigned int vflags = inode->i_vflags;
5343 +
5344 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
5345 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
5346 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
5347 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
5348 +
5349 +       if (flags & S_IMMUTABLE)
5350 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
5351 +       if (flags & S_IXUNLINK)
5352 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
5353 +
5354 +       if (flags & S_APPEND)
5355 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
5356 +       if (flags & S_NOATIME)
5357 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
5358 +       if (flags & S_SYNC)
5359 +               ip->i_diskflags |= GFS2_DIF_SYNC;
5360 +
5361 +       if (vflags & V_BARRIER)
5362 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
5363 +       if (vflags & V_COW)
5364 +               ip->i_diskflags |= GFS2_DIF_COW;
5365  }
5366  
5367  /* Flags that can be set by user space */
5368 @@ -297,6 +346,37 @@ static int gfs2_set_flags(struct file *f
5369         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
5370  }
5371  
5372 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
5373 +{
5374 +       struct gfs2_inode *ip = GFS2_I(inode);
5375 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
5376 +       struct buffer_head *bh;
5377 +       struct gfs2_holder gh;
5378 +       int error;
5379 +
5380 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
5381 +       if (error)
5382 +               return error;
5383 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
5384 +       if (error)
5385 +               goto out;
5386 +       error = gfs2_meta_inode_buffer(ip, &bh);
5387 +       if (error)
5388 +               goto out_trans_end;
5389 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
5390 +       inode->i_flags = flags;
5391 +       inode->i_vflags = vflags;
5392 +       gfs2_get_inode_flags(inode);
5393 +       gfs2_dinode_out(ip, bh->b_data);
5394 +       brelse(bh);
5395 +       gfs2_set_aops(inode);
5396 +out_trans_end:
5397 +       gfs2_trans_end(sdp);
5398 +out:
5399 +       gfs2_glock_dq_uninit(&gh);
5400 +       return error;
5401 +}
5402 +
5403  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5404  {
5405         switch(cmd) {
5406 diff -NurpP --minimal linux-3.1/fs/gfs2/inode.h linux-3.1-vs2.3.1-rc2/fs/gfs2/inode.h
5407 --- linux-3.1/fs/gfs2/inode.h   2011-10-24 18:45:27.000000000 +0200
5408 +++ linux-3.1-vs2.3.1-rc2/fs/gfs2/inode.h       2011-10-24 18:53:33.000000000 +0200
5409 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
5410  extern const struct file_operations gfs2_dir_fops_nolock;
5411  
5412  extern void gfs2_set_inode_flags(struct inode *inode);
5413 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
5414   
5415  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
5416  extern const struct file_operations gfs2_file_fops;
5417 diff -NurpP --minimal linux-3.1/fs/inode.c linux-3.1-vs2.3.1-rc2/fs/inode.c
5418 --- linux-3.1/fs/inode.c        2011-10-24 18:45:27.000000000 +0200
5419 +++ linux-3.1-vs2.3.1-rc2/fs/inode.c    2011-10-24 18:53:33.000000000 +0200
5420 @@ -26,6 +26,7 @@
5421  #include <linux/ima.h>
5422  #include <linux/cred.h>
5423  #include <linux/buffer_head.h> /* for inode_has_buffers */
5424 +#include <linux/vs_tag.h>
5425  #include "internal.h"
5426  
5427  /*
5428 @@ -137,6 +138,9 @@ int inode_init_always(struct super_block
5429         struct address_space *const mapping = &inode->i_data;
5430  
5431         inode->i_sb = sb;
5432 +
5433 +       /* essential because of inode slab reuse */
5434 +       inode->i_tag = 0;
5435         inode->i_blkbits = sb->s_blocksize_bits;
5436         inode->i_flags = 0;
5437         atomic_set(&inode->i_count, 1);
5438 @@ -158,6 +162,7 @@ int inode_init_always(struct super_block
5439         inode->i_bdev = NULL;
5440         inode->i_cdev = NULL;
5441         inode->i_rdev = 0;
5442 +       inode->i_mdev = 0;
5443         inode->dirtied_when = 0;
5444  
5445         if (security_inode_alloc(inode))
5446 @@ -399,6 +404,8 @@ void __insert_inode_hash(struct inode *i
5447  }
5448  EXPORT_SYMBOL(__insert_inode_hash);
5449  
5450 +EXPORT_SYMBOL_GPL(__iget);
5451 +
5452  /**
5453   *     __remove_inode_hash - remove an inode from the hash
5454   *     @inode: inode to unhash
5455 @@ -1626,9 +1633,11 @@ void init_special_inode(struct inode *in
5456         if (S_ISCHR(mode)) {
5457                 inode->i_fop = &def_chr_fops;
5458                 inode->i_rdev = rdev;
5459 +               inode->i_mdev = rdev;
5460         } else if (S_ISBLK(mode)) {
5461                 inode->i_fop = &def_blk_fops;
5462                 inode->i_rdev = rdev;
5463 +               inode->i_mdev = rdev;
5464         } else if (S_ISFIFO(mode))
5465                 inode->i_fop = &def_fifo_fops;
5466         else if (S_ISSOCK(mode))
5467 @@ -1657,6 +1666,7 @@ void inode_init_owner(struct inode *inod
5468         } else
5469                 inode->i_gid = current_fsgid();
5470         inode->i_mode = mode;
5471 +       inode->i_tag = dx_current_fstag(inode->i_sb);
5472  }
5473  EXPORT_SYMBOL(inode_init_owner);
5474  
5475 diff -NurpP --minimal linux-3.1/fs/ioctl.c linux-3.1-vs2.3.1-rc2/fs/ioctl.c
5476 --- linux-3.1/fs/ioctl.c        2011-05-22 16:17:52.000000000 +0200
5477 +++ linux-3.1-vs2.3.1-rc2/fs/ioctl.c    2011-10-24 18:53:33.000000000 +0200
5478 @@ -15,6 +15,9 @@
5479  #include <linux/writeback.h>
5480  #include <linux/buffer_head.h>
5481  #include <linux/falloc.h>
5482 +#include <linux/proc_fs.h>
5483 +#include <linux/vserver/inode.h>
5484 +#include <linux/vs_tag.h>
5485  
5486  #include <asm/ioctls.h>
5487  
5488 diff -NurpP --minimal linux-3.1/fs/ioprio.c linux-3.1-vs2.3.1-rc2/fs/ioprio.c
5489 --- linux-3.1/fs/ioprio.c       2011-01-05 21:50:24.000000000 +0100
5490 +++ linux-3.1-vs2.3.1-rc2/fs/ioprio.c   2011-10-24 18:53:33.000000000 +0200
5491 @@ -27,6 +27,7 @@
5492  #include <linux/syscalls.h>
5493  #include <linux/security.h>
5494  #include <linux/pid_namespace.h>
5495 +#include <linux/vs_base.h>
5496  
5497  int set_task_ioprio(struct task_struct *task, int ioprio)
5498  {
5499 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
5500                         else
5501                                 pgrp = find_vpid(who);
5502                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
5503 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5504 +                                       continue;
5505                                 ret = set_task_ioprio(p, ioprio);
5506                                 if (ret)
5507                                         break;
5508 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
5509                         else
5510                                 pgrp = find_vpid(who);
5511                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
5512 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5513 +                                       continue;
5514                                 tmpio = get_task_ioprio(p);
5515                                 if (tmpio < 0)
5516                                         continue;
5517 diff -NurpP --minimal linux-3.1/fs/jfs/file.c linux-3.1-vs2.3.1-rc2/fs/jfs/file.c
5518 --- linux-3.1/fs/jfs/file.c     2011-10-24 18:45:27.000000000 +0200
5519 +++ linux-3.1-vs2.3.1-rc2/fs/jfs/file.c 2011-10-24 18:53:33.000000000 +0200
5520 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
5521         if (is_quota_modification(inode, iattr))
5522                 dquot_initialize(inode);
5523         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
5524 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
5525 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
5526 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
5527                 rc = dquot_transfer(inode, iattr);
5528                 if (rc)
5529                         return rc;
5530 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
5531  #ifdef CONFIG_JFS_POSIX_ACL
5532         .get_acl        = jfs_get_acl,
5533  #endif
5534 +       .sync_flags     = jfs_sync_flags,
5535  };
5536  
5537  const struct file_operations jfs_file_operations = {
5538 diff -NurpP --minimal linux-3.1/fs/jfs/ioctl.c linux-3.1-vs2.3.1-rc2/fs/jfs/ioctl.c
5539 --- linux-3.1/fs/jfs/ioctl.c    2011-05-22 16:17:52.000000000 +0200
5540 +++ linux-3.1-vs2.3.1-rc2/fs/jfs/ioctl.c        2011-10-24 18:53:33.000000000 +0200
5541 @@ -11,6 +11,7 @@
5542  #include <linux/mount.h>
5543  #include <linux/time.h>
5544  #include <linux/sched.h>
5545 +#include <linux/mount.h>
5546  #include <asm/current.h>
5547  #include <asm/uaccess.h>
5548  
5549 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
5550  }
5551  
5552  
5553 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
5554 +{
5555 +       inode->i_flags = flags;
5556 +       inode->i_vflags = vflags;
5557 +       jfs_get_inode_flags(JFS_IP(inode));
5558 +       inode->i_ctime = CURRENT_TIME_SEC;
5559 +       mark_inode_dirty(inode);
5560 +       return 0;
5561 +}
5562 +
5563  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5564  {
5565         struct inode *inode = filp->f_dentry->d_inode;
5566 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
5567                 if (!S_ISDIR(inode->i_mode))
5568                         flags &= ~JFS_DIRSYNC_FL;
5569  
5570 +               if (IS_BARRIER(inode)) {
5571 +                       vxwprintk_task(1, "messing with the barrier.");
5572 +                       return -EACCES;
5573 +               }
5574 +
5575                 /* Is it quota file? Do not allow user to mess with it */
5576                 if (IS_NOQUOTA(inode)) {
5577                         err = -EPERM;
5578 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
5579                  * the relevant capability.
5580                  */
5581                 if ((oldflags & JFS_IMMUTABLE_FL) ||
5582 -                       ((flags ^ oldflags) &
5583 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
5584 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
5585 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
5586                         if (!capable(CAP_LINUX_IMMUTABLE)) {
5587                                 mutex_unlock(&inode->i_mutex);
5588                                 err = -EPERM;
5589 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
5590                         }
5591                 }
5592  
5593 -               flags = flags & JFS_FL_USER_MODIFIABLE;
5594 +               flags &= JFS_FL_USER_MODIFIABLE;
5595                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
5596                 jfs_inode->mode2 = flags;
5597  
5598 diff -NurpP --minimal linux-3.1/fs/jfs/jfs_dinode.h linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_dinode.h
5599 --- linux-3.1/fs/jfs/jfs_dinode.h       2008-12-25 00:26:37.000000000 +0100
5600 +++ linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_dinode.h   2011-10-24 18:53:33.000000000 +0200
5601 @@ -161,9 +161,13 @@ struct dinode {
5602  
5603  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
5604  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
5605 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
5606  
5607 -#define JFS_FL_USER_VISIBLE    0x03F80000
5608 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
5609 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
5610 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
5611 +
5612 +#define JFS_FL_USER_VISIBLE    0x07F80000
5613 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
5614  #define JFS_FL_INHERIT         0x03C80000
5615  
5616  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
5617 diff -NurpP --minimal linux-3.1/fs/jfs/jfs_filsys.h linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_filsys.h
5618 --- linux-3.1/fs/jfs/jfs_filsys.h       2008-12-25 00:26:37.000000000 +0100
5619 +++ linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_filsys.h   2011-10-24 18:53:33.000000000 +0200
5620 @@ -263,6 +263,7 @@
5621  #define JFS_NAME_MAX   255
5622  #define JFS_PATH_MAX   BPSIZE
5623  
5624 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
5625  
5626  /*
5627   *     file system state (superblock state)
5628 diff -NurpP --minimal linux-3.1/fs/jfs/jfs_imap.c linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_imap.c
5629 --- linux-3.1/fs/jfs/jfs_imap.c 2011-07-22 11:18:05.000000000 +0200
5630 +++ linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_imap.c     2011-10-24 18:53:33.000000000 +0200
5631 @@ -46,6 +46,7 @@
5632  #include <linux/pagemap.h>
5633  #include <linux/quotaops.h>
5634  #include <linux/slab.h>
5635 +#include <linux/vs_tag.h>
5636  
5637  #include "jfs_incore.h"
5638  #include "jfs_inode.h"
5639 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
5640  {
5641         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
5642         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
5643 +       uid_t uid;
5644 +       gid_t gid;
5645  
5646         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
5647         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
5648 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
5649         }
5650         ip->i_nlink = le32_to_cpu(dip->di_nlink);
5651  
5652 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
5653 +       uid = le32_to_cpu(dip->di_uid);
5654 +       gid = le32_to_cpu(dip->di_gid);
5655 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
5656 +
5657 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
5658         if (sbi->uid == -1)
5659                 ip->i_uid = jfs_ip->saved_uid;
5660         else {
5661                 ip->i_uid = sbi->uid;
5662         }
5663  
5664 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
5665 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
5666         if (sbi->gid == -1)
5667                 ip->i_gid = jfs_ip->saved_gid;
5668         else {
5669 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
5670         dip->di_size = cpu_to_le64(ip->i_size);
5671         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
5672         dip->di_nlink = cpu_to_le32(ip->i_nlink);
5673 -       if (sbi->uid == -1)
5674 -               dip->di_uid = cpu_to_le32(ip->i_uid);
5675 -       else
5676 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
5677 -       if (sbi->gid == -1)
5678 -               dip->di_gid = cpu_to_le32(ip->i_gid);
5679 -       else
5680 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
5681 +
5682 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
5683 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
5684 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
5685 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
5686 +
5687         jfs_get_inode_flags(jfs_ip);
5688         /*
5689          * mode2 is only needed for storing the higher order bits.
5690 diff -NurpP --minimal linux-3.1/fs/jfs/jfs_inode.c linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_inode.c
5691 --- linux-3.1/fs/jfs/jfs_inode.c        2010-08-02 16:52:49.000000000 +0200
5692 +++ linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_inode.c    2011-10-24 18:53:33.000000000 +0200
5693 @@ -18,6 +18,7 @@
5694  
5695  #include <linux/fs.h>
5696  #include <linux/quotaops.h>
5697 +#include <linux/vs_tag.h>
5698  #include "jfs_incore.h"
5699  #include "jfs_inode.h"
5700  #include "jfs_filsys.h"
5701 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
5702  {
5703         unsigned int flags = JFS_IP(inode)->mode2;
5704  
5705 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
5706 -               S_NOATIME | S_DIRSYNC | S_SYNC);
5707 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5708 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5709  
5710         if (flags & JFS_IMMUTABLE_FL)
5711                 inode->i_flags |= S_IMMUTABLE;
5712 +       if (flags & JFS_IXUNLINK_FL)
5713 +               inode->i_flags |= S_IXUNLINK;
5714 +
5715 +       if (flags & JFS_SYNC_FL)
5716 +               inode->i_flags |= S_SYNC;
5717         if (flags & JFS_APPEND_FL)
5718                 inode->i_flags |= S_APPEND;
5719         if (flags & JFS_NOATIME_FL)
5720                 inode->i_flags |= S_NOATIME;
5721         if (flags & JFS_DIRSYNC_FL)
5722                 inode->i_flags |= S_DIRSYNC;
5723 -       if (flags & JFS_SYNC_FL)
5724 -               inode->i_flags |= S_SYNC;
5725 +
5726 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5727 +
5728 +       if (flags & JFS_BARRIER_FL)
5729 +               inode->i_vflags |= V_BARRIER;
5730 +       if (flags & JFS_COW_FL)
5731 +               inode->i_vflags |= V_COW;
5732  }
5733  
5734  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
5735  {
5736         unsigned int flags = jfs_ip->vfs_inode.i_flags;
5737 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
5738 +
5739 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
5740 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
5741 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
5742 +                          JFS_BARRIER_FL | JFS_COW_FL);
5743  
5744 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
5745 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
5746         if (flags & S_IMMUTABLE)
5747                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
5748 +       if (flags & S_IXUNLINK)
5749 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
5750 +
5751         if (flags & S_APPEND)
5752                 jfs_ip->mode2 |= JFS_APPEND_FL;
5753         if (flags & S_NOATIME)
5754 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
5755                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
5756         if (flags & S_SYNC)
5757                 jfs_ip->mode2 |= JFS_SYNC_FL;
5758 +
5759 +       if (vflags & V_BARRIER)
5760 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
5761 +       if (vflags & V_COW)
5762 +               jfs_ip->mode2 |= JFS_COW_FL;
5763  }
5764  
5765  /*
5766 diff -NurpP --minimal linux-3.1/fs/jfs/jfs_inode.h linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_inode.h
5767 --- linux-3.1/fs/jfs/jfs_inode.h        2011-10-24 18:45:27.000000000 +0200
5768 +++ linux-3.1-vs2.3.1-rc2/fs/jfs/jfs_inode.h    2011-10-24 18:53:33.000000000 +0200
5769 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
5770  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
5771         int fh_len, int fh_type);
5772  extern void jfs_set_inode_flags(struct inode *);
5773 +extern int jfs_sync_flags(struct inode *, int, int);
5774  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
5775  extern int jfs_setattr(struct dentry *, struct iattr *);
5776  
5777 diff -NurpP --minimal linux-3.1/fs/jfs/namei.c linux-3.1-vs2.3.1-rc2/fs/jfs/namei.c
5778 --- linux-3.1/fs/jfs/namei.c    2011-10-24 18:45:27.000000000 +0200
5779 +++ linux-3.1-vs2.3.1-rc2/fs/jfs/namei.c        2011-10-24 18:53:33.000000000 +0200
5780 @@ -22,6 +22,7 @@
5781  #include <linux/ctype.h>
5782  #include <linux/quotaops.h>
5783  #include <linux/exportfs.h>
5784 +#include <linux/vs_tag.h>
5785  #include "jfs_incore.h"
5786  #include "jfs_superblock.h"
5787  #include "jfs_inode.h"
5788 @@ -1474,6 +1475,7 @@ static struct dentry *jfs_lookup(struct 
5789                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
5790         }
5791  
5792 +       dx_propagate_tag(nd, ip);
5793         return d_splice_alias(ip, dentry);
5794  }
5795  
5796 @@ -1538,6 +1540,7 @@ const struct inode_operations jfs_dir_in
5797  #ifdef CONFIG_JFS_POSIX_ACL
5798         .get_acl        = jfs_get_acl,
5799  #endif
5800 +       .sync_flags     = jfs_sync_flags,
5801  };
5802  
5803  const struct file_operations jfs_dir_operations = {
5804 diff -NurpP --minimal linux-3.1/fs/jfs/super.c linux-3.1-vs2.3.1-rc2/fs/jfs/super.c
5805 --- linux-3.1/fs/jfs/super.c    2011-05-22 16:17:53.000000000 +0200
5806 +++ linux-3.1-vs2.3.1-rc2/fs/jfs/super.c        2011-10-24 18:53:33.000000000 +0200
5807 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
5808  enum {
5809         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
5810         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
5811 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
5812 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
5813 +       Opt_tag, Opt_notag, Opt_tagid
5814  };
5815  
5816  static const match_table_t tokens = {
5817 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
5818         {Opt_resize, "resize=%u"},
5819         {Opt_resize_nosize, "resize"},
5820         {Opt_errors, "errors=%s"},
5821 +       {Opt_tag, "tag"},
5822 +       {Opt_notag, "notag"},
5823 +       {Opt_tagid, "tagid=%u"},
5824 +       {Opt_tag, "tagxid"},
5825         {Opt_ignore, "noquota"},
5826         {Opt_ignore, "quota"},
5827         {Opt_usrquota, "usrquota"},
5828 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
5829                         }
5830                         break;
5831                 }
5832 +#ifndef CONFIG_TAGGING_NONE
5833 +               case Opt_tag:
5834 +                       *flag |= JFS_TAGGED;
5835 +                       break;
5836 +               case Opt_notag:
5837 +                       *flag &= JFS_TAGGED;
5838 +                       break;
5839 +#endif
5840 +#ifdef CONFIG_PROPAGATE
5841 +               case Opt_tagid:
5842 +                       /* use args[0] */
5843 +                       *flag |= JFS_TAGGED;
5844 +                       break;
5845 +#endif
5846                 default:
5847                         printk("jfs: Unrecognized mount option \"%s\" "
5848                                         " or missing value\n", p);
5849 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
5850                 return -EINVAL;
5851         }
5852  
5853 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
5854 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
5855 +                       sb->s_id);
5856 +               return -EINVAL;
5857 +       }
5858 +
5859         if (newLVSize) {
5860                 if (sb->s_flags & MS_RDONLY) {
5861                         printk(KERN_ERR
5862 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
5863  #ifdef CONFIG_JFS_POSIX_ACL
5864         sb->s_flags |= MS_POSIXACL;
5865  #endif
5866 +       /* map mount option tagxid */
5867 +       if (sbi->flag & JFS_TAGGED)
5868 +               sb->s_flags |= MS_TAGGED;
5869  
5870         if (newLVSize) {
5871                 printk(KERN_ERR "resize option for remount only\n");
5872 diff -NurpP --minimal linux-3.1/fs/libfs.c linux-3.1-vs2.3.1-rc2/fs/libfs.c
5873 --- linux-3.1/fs/libfs.c        2011-10-24 18:45:27.000000000 +0200
5874 +++ linux-3.1-vs2.3.1-rc2/fs/libfs.c    2011-10-24 18:53:33.000000000 +0200
5875 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
5876   * both impossible due to the lock on directory.
5877   */
5878  
5879 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
5880 +static inline int do_dcache_readdir_filter(struct file *filp,
5881 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
5882  {
5883         struct dentry *dentry = filp->f_path.dentry;
5884         struct dentry *cursor = filp->private_data;
5885 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
5886                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
5887                                 struct dentry *next;
5888                                 next = list_entry(p, struct dentry, d_u.d_child);
5889 +                               if (filter && !filter(next))
5890 +                                       continue;
5891                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
5892                                 if (!simple_positive(next)) {
5893                                         spin_unlock(&next->d_lock);
5894 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
5895         return 0;
5896  }
5897  
5898 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
5899 +{
5900 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
5901 +}
5902 +
5903 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
5904 +       int (*filter)(struct dentry *))
5905 +{
5906 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
5907 +}
5908 +
5909  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
5910  {
5911         return -EISDIR;
5912 @@ -975,6 +989,7 @@ EXPORT_SYMBOL(dcache_dir_close);
5913  EXPORT_SYMBOL(dcache_dir_lseek);
5914  EXPORT_SYMBOL(dcache_dir_open);
5915  EXPORT_SYMBOL(dcache_readdir);
5916 +EXPORT_SYMBOL(dcache_readdir_filter);
5917  EXPORT_SYMBOL(generic_read_dir);
5918  EXPORT_SYMBOL(mount_pseudo);
5919  EXPORT_SYMBOL(simple_write_begin);
5920 diff -NurpP --minimal linux-3.1/fs/locks.c linux-3.1-vs2.3.1-rc2/fs/locks.c
5921 --- linux-3.1/fs/locks.c        2011-10-24 18:45:27.000000000 +0200
5922 +++ linux-3.1-vs2.3.1-rc2/fs/locks.c    2011-10-24 18:53:33.000000000 +0200
5923 @@ -126,6 +126,8 @@
5924  #include <linux/time.h>
5925  #include <linux/rcupdate.h>
5926  #include <linux/pid_namespace.h>
5927 +#include <linux/vs_base.h>
5928 +#include <linux/vs_limit.h>
5929  
5930  #include <asm/uaccess.h>
5931  
5932 @@ -170,11 +172,17 @@ static void locks_init_lock_heads(struct
5933  /* Allocate an empty lock structure. */
5934  struct file_lock *locks_alloc_lock(void)
5935  {
5936 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
5937 +       struct file_lock *fl;
5938  
5939 -       if (fl)
5940 -               locks_init_lock_heads(fl);
5941 +       if (!vx_locks_avail(1))
5942 +               return NULL;
5943  
5944 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
5945 +
5946 +       if (fl) {
5947 +               locks_init_lock_heads(fl);
5948 +               fl->fl_xid = -1;
5949 +       }
5950         return fl;
5951  }
5952  EXPORT_SYMBOL_GPL(locks_alloc_lock);
5953 @@ -202,6 +210,7 @@ void locks_free_lock(struct file_lock *f
5954         BUG_ON(!list_empty(&fl->fl_block));
5955         BUG_ON(!list_empty(&fl->fl_link));
5956  
5957 +       vx_locks_dec(fl);
5958         locks_release_private(fl);
5959         kmem_cache_free(filelock_cache, fl);
5960  }
5961 @@ -211,6 +220,7 @@ void locks_init_lock(struct file_lock *f
5962  {
5963         memset(fl, 0, sizeof(struct file_lock));
5964         locks_init_lock_heads(fl);
5965 +       fl->fl_xid = -1;
5966  }
5967  
5968  EXPORT_SYMBOL(locks_init_lock);
5969 @@ -251,6 +261,7 @@ void locks_copy_lock(struct file_lock *n
5970         new->fl_file = fl->fl_file;
5971         new->fl_ops = fl->fl_ops;
5972         new->fl_lmops = fl->fl_lmops;
5973 +       new->fl_xid = fl->fl_xid;
5974  
5975         locks_copy_private(new, fl);
5976  }
5977 @@ -289,6 +300,11 @@ static int flock_make_lock(struct file *
5978         fl->fl_flags = FL_FLOCK;
5979         fl->fl_type = type;
5980         fl->fl_end = OFFSET_MAX;
5981 +
5982 +       vxd_assert(filp->f_xid == vx_current_xid(),
5983 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5984 +       fl->fl_xid = filp->f_xid;
5985 +       vx_locks_inc(fl);
5986         
5987         *lock = fl;
5988         return 0;
5989 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
5990  
5991         fl->fl_owner = current->files;
5992         fl->fl_pid = current->tgid;
5993 +       fl->fl_xid = vx_current_xid();
5994  
5995         fl->fl_file = filp;
5996         fl->fl_flags = FL_LEASE;
5997 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
5998         if (fl == NULL)
5999                 return ERR_PTR(error);
6000  
6001 +       fl->fl_xid = vx_current_xid();
6002 +       if (filp)
6003 +               vxd_assert(filp->f_xid == fl->fl_xid,
6004 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
6005 +       vx_locks_inc(fl);
6006         error = lease_init(filp, type, fl);
6007         if (error) {
6008                 locks_free_lock(fl);
6009 @@ -758,6 +780,7 @@ static int flock_lock_file(struct file *
6010                 lock_flocks();
6011         }
6012  
6013 +       new_fl->fl_xid = -1;
6014  find_conflict:
6015         for_each_lock(inode, before) {
6016                 struct file_lock *fl = *before;
6017 @@ -778,6 +801,7 @@ find_conflict:
6018                 goto out;
6019         locks_copy_lock(new_fl, request);
6020         locks_insert_lock(before, new_fl);
6021 +       vx_locks_inc(new_fl);
6022         new_fl = NULL;
6023         error = 0;
6024  
6025 @@ -788,7 +812,8 @@ out:
6026         return error;
6027  }
6028  
6029 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
6030 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
6031 +       struct file_lock *conflock, xid_t xid)
6032  {
6033         struct file_lock *fl;
6034         struct file_lock *new_fl = NULL;
6035 @@ -798,6 +823,8 @@ static int __posix_lock_file(struct inod
6036         struct file_lock **before;
6037         int error, added = 0;
6038  
6039 +       vxd_assert(xid == vx_current_xid(),
6040 +               "xid(%d) == current(%d)", xid, vx_current_xid());
6041         /*
6042          * We may need two file_lock structures for this operation,
6043          * so we get them in advance to avoid races.
6044 @@ -808,7 +835,11 @@ static int __posix_lock_file(struct inod
6045             (request->fl_type != F_UNLCK ||
6046              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
6047                 new_fl = locks_alloc_lock();
6048 +               new_fl->fl_xid = xid;
6049 +               vx_locks_inc(new_fl);
6050                 new_fl2 = locks_alloc_lock();
6051 +               new_fl2->fl_xid = xid;
6052 +               vx_locks_inc(new_fl2);
6053         }
6054  
6055         lock_flocks();
6056 @@ -1007,7 +1038,8 @@ static int __posix_lock_file(struct inod
6057  int posix_lock_file(struct file *filp, struct file_lock *fl,
6058                         struct file_lock *conflock)
6059  {
6060 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
6061 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
6062 +               fl, conflock, filp->f_xid);
6063  }
6064  EXPORT_SYMBOL(posix_lock_file);
6065  
6066 @@ -1097,7 +1129,7 @@ int locks_mandatory_area(int read_write,
6067         fl.fl_end = offset + count - 1;
6068  
6069         for (;;) {
6070 -               error = __posix_lock_file(inode, &fl, NULL);
6071 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
6072                 if (error != FILE_LOCK_DEFERRED)
6073                         break;
6074                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
6075 @@ -1410,6 +1442,7 @@ int generic_setlease(struct file *filp, 
6076                 goto out;
6077  
6078         locks_insert_lock(before, lease);
6079 +       vx_locks_inc(lease);
6080         return 0;
6081  
6082  out:
6083 @@ -1794,6 +1827,11 @@ int fcntl_setlk(unsigned int fd, struct 
6084         if (file_lock == NULL)
6085                 return -ENOLCK;
6086  
6087 +       vxd_assert(filp->f_xid == vx_current_xid(),
6088 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6089 +       file_lock->fl_xid = filp->f_xid;
6090 +       vx_locks_inc(file_lock);
6091 +
6092         /*
6093          * This might block, so we do it before checking the inode.
6094          */
6095 @@ -1912,6 +1950,11 @@ int fcntl_setlk64(unsigned int fd, struc
6096         if (file_lock == NULL)
6097                 return -ENOLCK;
6098  
6099 +       vxd_assert(filp->f_xid == vx_current_xid(),
6100 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6101 +       file_lock->fl_xid = filp->f_xid;
6102 +       vx_locks_inc(file_lock);
6103 +
6104         /*
6105          * This might block, so we do it before checking the inode.
6106          */
6107 @@ -2177,8 +2220,11 @@ static int locks_show(struct seq_file *f
6108  
6109         lock_get_status(f, fl, *((loff_t *)f->private), "");
6110  
6111 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
6112 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
6113 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
6114 +                       continue;
6115                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
6116 +       }
6117  
6118         return 0;
6119  }
6120 diff -NurpP --minimal linux-3.1/fs/namei.c linux-3.1-vs2.3.1-rc2/fs/namei.c
6121 --- linux-3.1/fs/namei.c        2011-10-24 18:45:27.000000000 +0200
6122 +++ linux-3.1-vs2.3.1-rc2/fs/namei.c    2011-10-30 02:53:05.000000000 +0200
6123 @@ -33,6 +33,14 @@
6124  #include <linux/device_cgroup.h>
6125  #include <linux/fs_struct.h>
6126  #include <linux/posix_acl.h>
6127 +#include <linux/proc_fs.h>
6128 +#include <linux/vserver/inode.h>
6129 +#include <linux/vs_base.h>
6130 +#include <linux/vs_tag.h>
6131 +#include <linux/vs_cowbl.h>
6132 +#include <linux/vs_device.h>
6133 +#include <linux/vs_context.h>
6134 +#include <linux/pid_namespace.h>
6135  #include <asm/uaccess.h>
6136  
6137  #include "internal.h"
6138 @@ -220,6 +228,84 @@ static int check_acl(struct inode *inode
6139         return -EAGAIN;
6140  }
6141  
6142 +static inline int dx_barrier(const struct inode *inode)
6143 +{
6144 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
6145 +               vxwprintk_task(1, "did hit the barrier.");
6146 +               return 1;
6147 +       }
6148 +       return 0;
6149 +}
6150 +
6151 +static int __dx_permission(const struct inode *inode, int mask)
6152 +{
6153 +       if (dx_barrier(inode))
6154 +               return -EACCES;
6155 +
6156 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
6157 +               /* devpts is xid tagged */
6158 +               if (S_ISDIR(inode->i_mode) ||
6159 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
6160 +                       return 0;
6161 +
6162 +               /* just pretend we didn't find anything */
6163 +               return -ENOENT;
6164 +       }
6165 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
6166 +               struct proc_dir_entry *de = PDE(inode);
6167 +
6168 +               if (de && !vx_hide_check(0, de->vx_flags))
6169 +                       goto out;
6170 +
6171 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
6172 +                       struct pid *pid;
6173 +                       struct task_struct *tsk;
6174 +
6175 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
6176 +                           vx_flags(VXF_STATE_SETUP, 0))
6177 +                               return 0;
6178 +
6179 +                       pid = PROC_I(inode)->pid;
6180 +                       if (!pid)
6181 +                               goto out;
6182 +
6183 +                       tsk = pid_task(pid, PIDTYPE_PID);
6184 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
6185 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
6186 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
6187 +                               return 0;
6188 +               }
6189 +               else {
6190 +                       /* FIXME: Should we block some entries here? */
6191 +                       return 0;
6192 +               }
6193 +       }
6194 +       else {
6195 +               if (dx_notagcheck(inode->i_sb) ||
6196 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
6197 +                            DX_IDENT))
6198 +                       return 0;
6199 +       }
6200 +
6201 +out:
6202 +       return -EACCES;
6203 +}
6204 +
6205 +int dx_permission(const struct inode *inode, int mask)
6206 +{
6207 +       int ret = __dx_permission(inode, mask);
6208 +       if (unlikely(ret)) {
6209 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
6210 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
6211 +#endif
6212 +                   vxwprintk_task(1,
6213 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
6214 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
6215 +                       inode->i_ino);
6216 +       }
6217 +       return ret;
6218 +}
6219 +
6220  /*
6221   * This does basic POSIX ACL permission checking
6222   */
6223 @@ -355,10 +441,14 @@ int inode_permission(struct inode *inode
6224                 /*
6225                  * Nobody gets write access to an immutable file.
6226                  */
6227 -               if (IS_IMMUTABLE(inode))
6228 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
6229                         return -EACCES;
6230         }
6231  
6232 +       retval = dx_permission(inode, mask);
6233 +       if (retval)
6234 +               return retval;
6235 +
6236         retval = do_inode_permission(inode, mask);
6237         if (retval)
6238                 return retval;
6239 @@ -1034,7 +1124,8 @@ static void follow_dotdot(struct nameida
6240  
6241                 if (nd->path.dentry == nd->root.dentry &&
6242                     nd->path.mnt == nd->root.mnt) {
6243 -                       break;
6244 +                       /* for sane '/' avoid follow_mount() */
6245 +                       return;
6246                 }
6247                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
6248                         /* rare case of legitimate dget_parent()... */
6249 @@ -1143,6 +1234,9 @@ static int do_lookup(struct nameidata *n
6250                 }
6251                 if (unlikely(d_need_lookup(dentry)))
6252                         goto unlazy;
6253 +
6254 +               /* FIXME: check dx permission */
6255 +
6256                 path->mnt = mnt;
6257                 path->dentry = dentry;
6258                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
6259 @@ -1204,6 +1298,8 @@ retry:
6260                 }
6261         }
6262  
6263 +       /* FIXME: check dx permission */
6264 +
6265         path->mnt = mnt;
6266         path->dentry = dentry;
6267         err = follow_managed(path, nd->flags);
6268 @@ -1890,7 +1986,7 @@ static int may_delete(struct inode *dir,
6269         if (IS_APPEND(dir))
6270                 return -EPERM;
6271         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
6272 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
6273 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
6274                 return -EPERM;
6275         if (isdir) {
6276                 if (!S_ISDIR(victim->d_inode->i_mode))
6277 @@ -1970,19 +2066,25 @@ int vfs_create(struct inode *dir, struct
6278  {
6279         int error = may_create(dir, dentry);
6280  
6281 -       if (error)
6282 +       if (error) {
6283 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
6284                 return error;
6285 +       }
6286  
6287         if (!dir->i_op->create)
6288                 return -EACCES; /* shouldn't it be ENOSYS? */
6289         mode &= S_IALLUGO;
6290         mode |= S_IFREG;
6291         error = security_inode_create(dir, dentry, mode);
6292 -       if (error)
6293 +       if (error) {
6294 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
6295                 return error;
6296 +       }
6297         error = dir->i_op->create(dir, dentry, mode, nd);
6298         if (!error)
6299                 fsnotify_create(dir, dentry);
6300 +       else
6301 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
6302         return error;
6303  }
6304  
6305 @@ -2017,6 +2119,15 @@ static int may_open(struct path *path, i
6306                 break;
6307         }
6308  
6309 +#ifdef CONFIG_VSERVER_COWBL
6310 +       if (IS_COW(inode) &&
6311 +               ((flag & O_ACCMODE) != O_RDONLY)) {
6312 +               if (IS_COW_LINK(inode))
6313 +                       return -EMLINK;
6314 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
6315 +               mark_inode_dirty(inode);
6316 +       }
6317 +#endif
6318         error = inode_permission(inode, acc_mode);
6319         if (error)
6320                 return error;
6321 @@ -2233,6 +2344,16 @@ ok:
6322         }
6323  common:
6324         error = may_open(&nd->path, acc_mode, open_flag);
6325 +#ifdef CONFIG_VSERVER_COWBL
6326 +       if (error == -EMLINK) {
6327 +               struct dentry *dentry;
6328 +               dentry = cow_break_link(pathname);
6329 +               if (IS_ERR(dentry))
6330 +                       error = PTR_ERR(dentry);
6331 +               else
6332 +                       dput(dentry);
6333 +       }
6334 +#endif
6335         if (error)
6336                 goto exit;
6337         filp = nameidata_to_filp(nd);
6338 @@ -2275,6 +2396,7 @@ static struct file *path_openat(int dfd,
6339         struct path path;
6340         int error;
6341  
6342 +restart:
6343         filp = get_empty_filp();
6344         if (!filp)
6345                 return ERR_PTR(-ENFILE);
6346 @@ -2312,6 +2434,17 @@ static struct file *path_openat(int dfd,
6347                         filp = do_last(nd, &path, op, pathname);
6348                 put_link(nd, &link, cookie);
6349         }
6350 +
6351 +#ifdef CONFIG_VSERVER_COWBL
6352 +       if (filp == ERR_PTR(-EMLINK)) {
6353 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
6354 +                       path_put(&nd->root);
6355 +               if (base)
6356 +                       fput(base);
6357 +               release_open_intent(nd);
6358 +               goto restart;
6359 +       }
6360 +#endif
6361  out:
6362         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
6363                 path_put(&nd->root);
6364 @@ -2401,6 +2534,11 @@ struct dentry *kern_path_create(int dfd,
6365                 goto fail;
6366         }
6367         *path = nd.path;
6368 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
6369 +               path->dentry, path->dentry->d_name.len,
6370 +               path->dentry->d_name.name, dentry,
6371 +               dentry->d_name.len, dentry->d_name.name,
6372 +               path->dentry->d_inode);
6373         return dentry;
6374  eexist:
6375         dput(dentry);
6376 @@ -2882,7 +3020,7 @@ int vfs_link(struct dentry *old_dentry, 
6377         /*
6378          * A link to an append-only or immutable file cannot be created.
6379          */
6380 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
6381 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
6382                 return -EPERM;
6383         if (!dir->i_op->link)
6384                 return -EPERM;
6385 @@ -3263,6 +3401,227 @@ int vfs_follow_link(struct nameidata *nd
6386         return __vfs_follow_link(nd, link);
6387  }
6388  
6389 +
6390 +#ifdef CONFIG_VSERVER_COWBL
6391 +
6392 +static inline
6393 +long do_cow_splice(struct file *in, struct file *out, size_t len)
6394 +{
6395 +       loff_t ppos = 0;
6396 +
6397 +       return do_splice_direct(in, &ppos, out, len, 0);
6398 +}
6399 +
6400 +struct dentry *cow_break_link(const char *pathname)
6401 +{
6402 +       int ret, mode, pathlen, redo = 0;
6403 +       struct nameidata old_nd, dir_nd;
6404 +       struct path old_path, dir_path;
6405 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
6406 +       struct file *old_file;
6407 +       struct file *new_file;
6408 +       char *to, *path, pad='\251';
6409 +       loff_t size;
6410 +
6411 +       vxdprintk(VXD_CBIT(misc, 1),
6412 +               "cow_break_link(" VS_Q("%s") ")", pathname);
6413 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
6414 +       ret = -ENOMEM;
6415 +       if (!path)
6416 +               goto out;
6417 +
6418 +       /* old_nd will have refs to dentry and mnt */
6419 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
6420 +       vxdprintk(VXD_CBIT(misc, 2),
6421 +               "do_path_lookup(old): %d (%d mnt refs)",
6422 +               ret, mnt_get_count(old_nd.path.mnt));
6423 +       if (ret < 0)
6424 +               goto out_free_path;
6425 +
6426 +       old_path = old_nd.path;
6427 +       old_dentry = old_path.dentry;
6428 +       mode = old_dentry->d_inode->i_mode;
6429 +
6430 +       to = d_path(&old_path, path, PATH_MAX-2);
6431 +       pathlen = strlen(to);
6432 +       vxdprintk(VXD_CBIT(misc, 2),
6433 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
6434 +               old_dentry,
6435 +               old_dentry->d_name.len, old_dentry->d_name.name,
6436 +               old_dentry->d_name.len);
6437 +
6438 +       to[pathlen + 1] = 0;
6439 +retry:
6440 +       new_dentry = NULL;
6441 +       to[pathlen] = pad--;
6442 +       ret = -ELOOP;
6443 +       if (pad <= '\240')
6444 +               goto out_rel_old;
6445 +
6446 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
6447 +       /* dir_nd will have refs to dentry and mnt */
6448 +       ret = do_path_lookup(AT_FDCWD, to,
6449 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
6450 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
6451 +       if (ret < 0)
6452 +               goto retry;
6453 +
6454 +       /* this puppy downs the dir inode mutex if successful */
6455 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
6456 +       if (!new_dentry || IS_ERR(new_dentry)) {
6457 +               path_put(&dir_nd.path);
6458 +               vxdprintk(VXD_CBIT(misc, 2),
6459 +                       "kern_path_create(new) failed with %ld",
6460 +                       PTR_ERR(new_dentry));
6461 +               goto retry;
6462 +       }
6463 +       path_put(&dir_path);
6464 +       vxdprintk(VXD_CBIT(misc, 2),
6465 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
6466 +               new_dentry,
6467 +               new_dentry->d_name.len, new_dentry->d_name.name,
6468 +               new_dentry->d_name.len);
6469 +
6470 +       dir = dir_nd.path.dentry;
6471 +
6472 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
6473 +       vxdprintk(VXD_CBIT(misc, 2),
6474 +               "vfs_create(new): %d", ret);
6475 +       if (ret == -EEXIST) {
6476 +               mutex_unlock(&dir->d_inode->i_mutex);
6477 +               path_put(&dir_nd.path);
6478 +               dput(new_dentry);
6479 +               goto retry;
6480 +       }
6481 +       else if (ret < 0)
6482 +               goto out_unlock_new;
6483 +
6484 +       /* drop out early, ret passes ENOENT */
6485 +       ret = -ENOENT;
6486 +       if ((redo = d_unhashed(old_dentry)))
6487 +               goto out_unlock_new;
6488 +
6489 +       path_get(&old_path);
6490 +       /* this one cleans up the dentry/mnt in case of failure */
6491 +       old_file = dentry_open(old_dentry, old_path.mnt,
6492 +               O_RDONLY, current_cred());
6493 +       vxdprintk(VXD_CBIT(misc, 2),
6494 +               "dentry_open(old): %p", old_file);
6495 +       if (IS_ERR(old_file)) {
6496 +               ret = PTR_ERR(old_file);
6497 +               goto out_unlock_new;
6498 +       }
6499 +
6500 +       dget(new_dentry);
6501 +       mntget(old_path.mnt);
6502 +       /* this one cleans up the dentry/mnt in case of failure */
6503 +       new_file = dentry_open(new_dentry, old_path.mnt,
6504 +               O_WRONLY, current_cred());
6505 +       vxdprintk(VXD_CBIT(misc, 2),
6506 +               "dentry_open(new): %p", new_file);
6507 +       if (IS_ERR(new_file)) {
6508 +               ret = PTR_ERR(new_file);
6509 +               goto out_fput_old;
6510 +       }
6511 +
6512 +       size = i_size_read(old_file->f_dentry->d_inode);
6513 +       ret = do_cow_splice(old_file, new_file, size);
6514 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
6515 +       if (ret < 0) {
6516 +               goto out_fput_both;
6517 +       } else if (ret < size) {
6518 +               ret = -ENOSPC;
6519 +               goto out_fput_both;
6520 +       } else {
6521 +               struct inode *old_inode = old_dentry->d_inode;
6522 +               struct inode *new_inode = new_dentry->d_inode;
6523 +               struct iattr attr = {
6524 +                       .ia_uid = old_inode->i_uid,
6525 +                       .ia_gid = old_inode->i_gid,
6526 +                       .ia_valid = ATTR_UID | ATTR_GID
6527 +                       };
6528 +
6529 +               setattr_copy(new_inode, &attr);
6530 +               mark_inode_dirty(new_inode);
6531 +       }
6532 +
6533 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
6534 +
6535 +       /* drop out late */
6536 +       ret = -ENOENT;
6537 +       if ((redo = d_unhashed(old_dentry)))
6538 +               goto out_unlock;
6539 +
6540 +       vxdprintk(VXD_CBIT(misc, 2),
6541 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
6542 +               new_dentry->d_name.len, new_dentry->d_name.name,
6543 +               new_dentry->d_name.len,
6544 +               old_dentry->d_name.len, old_dentry->d_name.name,
6545 +               old_dentry->d_name.len);
6546 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
6547 +               old_dentry->d_parent->d_inode, old_dentry);
6548 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
6549 +
6550 +out_unlock:
6551 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
6552 +
6553 +out_fput_both:
6554 +       vxdprintk(VXD_CBIT(misc, 3),
6555 +               "fput(new_file=%p[#%ld])", new_file,
6556 +               atomic_long_read(&new_file->f_count));
6557 +       fput(new_file);
6558 +
6559 +out_fput_old:
6560 +       vxdprintk(VXD_CBIT(misc, 3),
6561 +               "fput(old_file=%p[#%ld])", old_file,
6562 +               atomic_long_read(&old_file->f_count));
6563 +       fput(old_file);
6564 +
6565 +out_unlock_new:
6566 +       mutex_unlock(&dir->d_inode->i_mutex);
6567 +       if (!ret)
6568 +               goto out_redo;
6569 +
6570 +       /* error path cleanup */
6571 +       vfs_unlink(dir->d_inode, new_dentry);
6572 +
6573 +out_redo:
6574 +       if (!redo)
6575 +               goto out_rel_both;
6576 +       /* lookup dentry once again */
6577 +       /* old_nd.path is freed as old_path in out_rel_old */
6578 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
6579 +       if (ret)
6580 +               goto out_rel_both;
6581 +
6582 +       dput(new_dentry);
6583 +       new_dentry = old_nd.path.dentry;
6584 +       vxdprintk(VXD_CBIT(misc, 2),
6585 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
6586 +               new_dentry,
6587 +               new_dentry->d_name.len, new_dentry->d_name.name,
6588 +               new_dentry->d_name.len);
6589 +       dget(new_dentry);
6590 +
6591 +out_rel_both:
6592 +       path_put(&dir_nd.path);
6593 +out_rel_old:
6594 +       path_put(&old_path);
6595 +out_free_path:
6596 +       kfree(path);
6597 +out:
6598 +       if (ret) {
6599 +               dput(new_dentry);
6600 +               new_dentry = ERR_PTR(ret);
6601 +       }
6602 +       vxdprintk(VXD_CBIT(misc, 3),
6603 +               "cow_break_link returning with %p (%d mount refs)",
6604 +               new_dentry, mnt_get_count(old_nd.path.mnt));
6605 +       return new_dentry;
6606 +}
6607 +
6608 +#endif
6609 +
6610  /* get the link contents into pagecache */
6611  static char *page_getlink(struct dentry * dentry, struct page **ppage)
6612  {
6613 diff -NurpP --minimal linux-3.1/fs/namespace.c linux-3.1-vs2.3.1-rc2/fs/namespace.c
6614 --- linux-3.1/fs/namespace.c    2011-10-24 18:45:27.000000000 +0200
6615 +++ linux-3.1-vs2.3.1-rc2/fs/namespace.c        2011-10-24 18:53:33.000000000 +0200
6616 @@ -31,6 +31,11 @@
6617  #include <linux/idr.h>
6618  #include <linux/fs_struct.h>
6619  #include <linux/fsnotify.h>
6620 +#include <linux/vs_base.h>
6621 +#include <linux/vs_context.h>
6622 +#include <linux/vs_tag.h>
6623 +#include <linux/vserver/space.h>
6624 +#include <linux/vserver/global.h>
6625  #include <asm/uaccess.h>
6626  #include <asm/unistd.h>
6627  #include "pnode.h"
6628 @@ -679,6 +684,10 @@ vfs_kern_mount(struct file_system_type *
6629         if (!type)
6630                 return ERR_PTR(-ENODEV);
6631  
6632 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
6633 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
6634 +               return ERR_PTR(-EPERM);
6635 +
6636         mnt = alloc_vfsmnt(name);
6637         if (!mnt)
6638                 return ERR_PTR(-ENOMEM);
6639 @@ -724,6 +733,7 @@ static struct vfsmount *clone_mnt(struct
6640                 mnt->mnt_root = dget(root);
6641                 mnt->mnt_mountpoint = mnt->mnt_root;
6642                 mnt->mnt_parent = mnt;
6643 +               mnt->mnt_tag = old->mnt_tag;
6644  
6645                 if (flag & CL_SLAVE) {
6646                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
6647 @@ -852,6 +862,31 @@ static inline void mangle(struct seq_fil
6648         seq_escape(m, s, " \t\n\\");
6649  }
6650  
6651 +static int mnt_is_reachable(struct vfsmount *mnt)
6652 +{
6653 +       struct path root;
6654 +       struct dentry *point;
6655 +       int ret;
6656 +
6657 +       if (mnt == mnt->mnt_ns->root)
6658 +               return 1;
6659 +
6660 +       br_read_lock(vfsmount_lock);
6661 +       root = current->fs->root;
6662 +       point = root.dentry;
6663 +
6664 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
6665 +               point = mnt->mnt_mountpoint;
6666 +               mnt = mnt->mnt_parent;
6667 +       }
6668 +
6669 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
6670 +
6671 +       br_read_unlock(vfsmount_lock);
6672 +
6673 +       return ret;
6674 +}
6675 +
6676  /*
6677   * Simple .show_options callback for filesystems which don't want to
6678   * implement more complex mount option showing.
6679 @@ -954,6 +989,8 @@ static int show_sb_opts(struct seq_file 
6680                 { MS_SYNCHRONOUS, ",sync" },
6681                 { MS_DIRSYNC, ",dirsync" },
6682                 { MS_MANDLOCK, ",mand" },
6683 +               { MS_TAGGED, ",tag" },
6684 +               { MS_NOTAGCHECK, ",notagcheck" },
6685                 { 0, NULL }
6686         };
6687         const struct proc_fs_info *fs_infop;
6688 @@ -1000,16 +1037,26 @@ static int show_vfsmnt(struct seq_file *
6689         int err = 0;
6690         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6691  
6692 -       if (mnt->mnt_sb->s_op->show_devname) {
6693 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6694 -               if (err)
6695 -                       goto out;
6696 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6697 +               return SEQ_SKIP;
6698 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6699 +               return SEQ_SKIP;
6700 +
6701 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6702 +               mnt == current->fs->root.mnt) {
6703 +               seq_puts(m, "/dev/root / ");
6704         } else {
6705 -               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6706 +               if (mnt->mnt_sb->s_op->show_devname) {
6707 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6708 +                       if (err)
6709 +                               goto out;
6710 +               } else {
6711 +                       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6712 +               }
6713 +               seq_putc(m, ' ');
6714 +               seq_path(m, &mnt_path, " \t\n\\");
6715 +               seq_putc(m, ' ');
6716         }
6717 -       seq_putc(m, ' ');
6718 -       seq_path(m, &mnt_path, " \t\n\\");
6719 -       seq_putc(m, ' ');
6720         show_type(m, mnt->mnt_sb);
6721         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6722         err = show_sb_opts(m, mnt->mnt_sb);
6723 @@ -1039,6 +1086,11 @@ static int show_mountinfo(struct seq_fil
6724         struct path root = p->root;
6725         int err = 0;
6726  
6727 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6728 +               return SEQ_SKIP;
6729 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6730 +               return SEQ_SKIP;
6731 +
6732         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
6733                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6734         if (sb->s_op->show_path)
6735 @@ -1107,22 +1159,32 @@ static int show_vfsstat(struct seq_file 
6736         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6737         int err = 0;
6738  
6739 -       /* device */
6740 -       if (mnt->mnt_sb->s_op->show_devname) {
6741 -               seq_puts(m, "device ");
6742 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6743 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6744 +               return SEQ_SKIP;
6745 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6746 +               return SEQ_SKIP;
6747 +
6748 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6749 +               mnt == current->fs->root.mnt) {
6750 +               seq_puts(m, "device /dev/root mounted on / ");
6751         } else {
6752 -               if (mnt->mnt_devname) {
6753 -                       seq_puts(m, "device ");
6754 -                       mangle(m, mnt->mnt_devname);
6755 -               } else
6756 -                       seq_puts(m, "no device");
6757 -       }
6758 +               /* device */
6759 +               if (mnt->mnt_sb->s_op->show_devname) {
6760 +                       seq_puts(m, "device ");
6761 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6762 +               } else {
6763 +                       if (mnt->mnt_devname) {
6764 +                               seq_puts(m, "device ");
6765 +                               mangle(m, mnt->mnt_devname);
6766 +                       } else
6767 +                               seq_puts(m, "no device");
6768 +               }
6769  
6770 -       /* mount point */
6771 -       seq_puts(m, " mounted on ");
6772 -       seq_path(m, &mnt_path, " \t\n\\");
6773 -       seq_putc(m, ' ');
6774 +               /* mount point */
6775 +               seq_puts(m, " mounted on ");
6776 +               seq_path(m, &mnt_path, " \t\n\\");
6777 +               seq_putc(m, ' ');
6778 +       }
6779  
6780         /* file system type */
6781         seq_puts(m, "with fstype ");
6782 @@ -1380,7 +1442,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
6783                 goto dput_and_out;
6784  
6785         retval = -EPERM;
6786 -       if (!capable(CAP_SYS_ADMIN))
6787 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6788                 goto dput_and_out;
6789  
6790         retval = do_umount(path.mnt, flags);
6791 @@ -1406,7 +1468,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
6792  
6793  static int mount_is_safe(struct path *path)
6794  {
6795 -       if (capable(CAP_SYS_ADMIN))
6796 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6797                 return 0;
6798         return -EPERM;
6799  #ifdef notyet
6800 @@ -1716,7 +1778,7 @@ static int do_change_type(struct path *p
6801         int type;
6802         int err = 0;
6803  
6804 -       if (!capable(CAP_SYS_ADMIN))
6805 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
6806                 return -EPERM;
6807  
6808         if (path->dentry != path->mnt->mnt_root)
6809 @@ -1732,6 +1794,7 @@ static int do_change_type(struct path *p
6810                 if (err)
6811                         goto out_unlock;
6812         }
6813 +       // mnt->mnt_flags = mnt_flags;
6814  
6815         br_write_lock(vfsmount_lock);
6816         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
6817 @@ -1747,12 +1810,14 @@ static int do_change_type(struct path *p
6818   * do loopback mount.
6819   */
6820  static int do_loopback(struct path *path, char *old_name,
6821 -                               int recurse)
6822 +       tag_t tag, unsigned long flags, int mnt_flags)
6823  {
6824         LIST_HEAD(umount_list);
6825         struct path old_path;
6826         struct vfsmount *mnt = NULL;
6827         int err = mount_is_safe(path);
6828 +       int recurse = flags & MS_REC;
6829 +
6830         if (err)
6831                 return err;
6832         if (!old_name || !*old_name)
6833 @@ -1818,12 +1883,12 @@ static int change_mount_flags(struct vfs
6834   * on it - tough luck.
6835   */
6836  static int do_remount(struct path *path, int flags, int mnt_flags,
6837 -                     void *data)
6838 +       void *data, xid_t xid)
6839  {
6840         int err;
6841         struct super_block *sb = path->mnt->mnt_sb;
6842  
6843 -       if (!capable(CAP_SYS_ADMIN))
6844 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
6845                 return -EPERM;
6846  
6847         if (!check_mnt(path->mnt))
6848 @@ -1871,7 +1936,7 @@ static int do_move_mount(struct path *pa
6849         struct path old_path, parent_path;
6850         struct vfsmount *p;
6851         int err = 0;
6852 -       if (!capable(CAP_SYS_ADMIN))
6853 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6854                 return -EPERM;
6855         if (!old_name || !*old_name)
6856                 return -EINVAL;
6857 @@ -2022,7 +2087,7 @@ static int do_new_mount(struct path *pat
6858                 return -EINVAL;
6859  
6860         /* we need capabilities... */
6861 -       if (!capable(CAP_SYS_ADMIN))
6862 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6863                 return -EPERM;
6864  
6865         mnt = do_kern_mount(type, flags, name, data);
6866 @@ -2291,6 +2356,7 @@ long do_mount(char *dev_name, char *dir_
6867         struct path path;
6868         int retval = 0;
6869         int mnt_flags = 0;
6870 +       tag_t tag = 0;
6871  
6872         /* Discard magic */
6873         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
6874 @@ -2318,6 +2384,12 @@ long do_mount(char *dev_name, char *dir_
6875         if (!(flags & MS_NOATIME))
6876                 mnt_flags |= MNT_RELATIME;
6877  
6878 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
6879 +               /* FIXME: bind and re-mounts get the tag flag? */
6880 +               if (flags & (MS_BIND|MS_REMOUNT))
6881 +                       flags |= MS_TAGID;
6882 +       }
6883 +
6884         /* Separate the per-mountpoint flags */
6885         if (flags & MS_NOSUID)
6886                 mnt_flags |= MNT_NOSUID;
6887 @@ -2334,15 +2406,17 @@ long do_mount(char *dev_name, char *dir_
6888         if (flags & MS_RDONLY)
6889                 mnt_flags |= MNT_READONLY;
6890  
6891 +       if (!capable(CAP_SYS_ADMIN))
6892 +               mnt_flags |= MNT_NODEV;
6893         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
6894                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
6895                    MS_STRICTATIME);
6896  
6897         if (flags & MS_REMOUNT)
6898                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
6899 -                                   data_page);
6900 +                                   data_page, tag);
6901         else if (flags & MS_BIND)
6902 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
6903 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
6904         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
6905                 retval = do_change_type(&path, flags);
6906         else if (flags & MS_MOVE)
6907 @@ -2442,6 +2516,7 @@ static struct mnt_namespace *dup_mnt_ns(
6908                 q = next_mnt(q, new_ns->root);
6909         }
6910         up_write(&namespace_sem);
6911 +       atomic_inc(&vs_global_mnt_ns);
6912  
6913         if (rootmnt)
6914                 mntput(rootmnt);
6915 @@ -2581,9 +2656,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
6916                 goto out3;
6917  
6918         error = -EINVAL;
6919 -       if (IS_MNT_SHARED(old.mnt) ||
6920 +       if ((IS_MNT_SHARED(old.mnt) ||
6921                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
6922 -               IS_MNT_SHARED(root.mnt->mnt_parent))
6923 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
6924 +               !vx_flags(VXF_STATE_SETUP, 0))
6925                 goto out4;
6926         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
6927                 goto out4;
6928 @@ -2715,6 +2791,7 @@ void put_mnt_ns(struct mnt_namespace *ns
6929         br_write_unlock(vfsmount_lock);
6930         up_write(&namespace_sem);
6931         release_mounts(&umount_list);
6932 +       atomic_dec(&vs_global_mnt_ns);
6933         kfree(ns);
6934  }
6935  EXPORT_SYMBOL(put_mnt_ns);
6936 diff -NurpP --minimal linux-3.1/fs/nfs/client.c linux-3.1-vs2.3.1-rc2/fs/nfs/client.c
6937 --- linux-3.1/fs/nfs/client.c   2011-10-24 18:45:27.000000000 +0200
6938 +++ linux-3.1-vs2.3.1-rc2/fs/nfs/client.c       2011-10-24 18:53:33.000000000 +0200
6939 @@ -778,6 +778,9 @@ static int nfs_init_server_rpcclient(str
6940         if (server->flags & NFS_MOUNT_SOFT)
6941                 server->client->cl_softrtry = 1;
6942  
6943 +       server->client->cl_tag = 0;
6944 +       if (server->flags & NFS_MOUNT_TAGGED)
6945 +               server->client->cl_tag = 1;
6946         return 0;
6947  }
6948  
6949 @@ -952,6 +955,10 @@ static void nfs_server_set_fsinfo(struct
6950                 server->acdirmin = server->acdirmax = 0;
6951         }
6952  
6953 +       /* FIXME: needs fsinfo
6954 +       if (server->flags & NFS_MOUNT_TAGGED)
6955 +               sb->s_flags |= MS_TAGGED;       */
6956 +
6957         server->maxfilesize = fsinfo->maxfilesize;
6958  
6959         server->time_delta = fsinfo->time_delta;
6960 diff -NurpP --minimal linux-3.1/fs/nfs/dir.c linux-3.1-vs2.3.1-rc2/fs/nfs/dir.c
6961 --- linux-3.1/fs/nfs/dir.c      2011-10-24 18:45:27.000000000 +0200
6962 +++ linux-3.1-vs2.3.1-rc2/fs/nfs/dir.c  2011-10-24 18:53:33.000000000 +0200
6963 @@ -35,6 +35,7 @@
6964  #include <linux/sched.h>
6965  #include <linux/kmemleak.h>
6966  #include <linux/xattr.h>
6967 +#include <linux/vs_tag.h>
6968  
6969  #include "delegation.h"
6970  #include "iostat.h"
6971 @@ -1311,6 +1312,7 @@ static struct dentry *nfs_lookup(struct 
6972         if (IS_ERR(res))
6973                 goto out_unblock_sillyrename;
6974  
6975 +       dx_propagate_tag(nd, inode);
6976  no_entry:
6977         res = d_materialise_unique(dentry, inode);
6978         if (res != NULL) {
6979 diff -NurpP --minimal linux-3.1/fs/nfs/inode.c linux-3.1-vs2.3.1-rc2/fs/nfs/inode.c
6980 --- linux-3.1/fs/nfs/inode.c    2011-10-24 18:45:27.000000000 +0200
6981 +++ linux-3.1-vs2.3.1-rc2/fs/nfs/inode.c        2011-10-24 18:53:33.000000000 +0200
6982 @@ -38,6 +38,7 @@
6983  #include <linux/nfs_xdr.h>
6984  #include <linux/slab.h>
6985  #include <linux/compat.h>
6986 +#include <linux/vs_tag.h>
6987  
6988  #include <asm/system.h>
6989  #include <asm/uaccess.h>
6990 @@ -273,6 +274,8 @@ nfs_fhget(struct super_block *sb, struct
6991         if (inode->i_state & I_NEW) {
6992                 struct nfs_inode *nfsi = NFS_I(inode);
6993                 unsigned long now = jiffies;
6994 +               uid_t uid;
6995 +               gid_t gid;
6996  
6997                 /* We set i_ino for the few things that still rely on it,
6998                  * such as stat(2) */
6999 @@ -321,8 +324,8 @@ nfs_fhget(struct super_block *sb, struct
7000                 nfsi->change_attr = 0;
7001                 inode->i_size = 0;
7002                 inode->i_nlink = 0;
7003 -               inode->i_uid = -2;
7004 -               inode->i_gid = -2;
7005 +               uid = -2;
7006 +               gid = -2;
7007                 inode->i_blocks = 0;
7008                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
7009  
7010 @@ -359,13 +362,13 @@ nfs_fhget(struct super_block *sb, struct
7011                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
7012                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
7013                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
7014 -                       inode->i_uid = fattr->uid;
7015 +                       uid = fattr->uid;
7016                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
7017                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
7018                                 | NFS_INO_INVALID_ACCESS
7019                                 | NFS_INO_INVALID_ACL;
7020                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
7021 -                       inode->i_gid = fattr->gid;
7022 +                       gid = fattr->gid;
7023                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
7024                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
7025                                 | NFS_INO_INVALID_ACCESS
7026 @@ -378,6 +381,11 @@ nfs_fhget(struct super_block *sb, struct
7027                          */
7028                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
7029                 }
7030 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7031 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7032 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7033 +                               /* maybe fattr->xid someday */
7034 +
7035                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
7036                 nfsi->attrtimeo_timestamp = now;
7037                 nfsi->access_cache = RB_ROOT;
7038 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
7039                         inode->i_uid = attr->ia_uid;
7040                 if ((attr->ia_valid & ATTR_GID) != 0)
7041                         inode->i_gid = attr->ia_gid;
7042 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
7043 +                       inode->i_tag = attr->ia_tag;
7044                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7045                 spin_unlock(&inode->i_lock);
7046         }
7047 @@ -943,6 +953,9 @@ static int nfs_check_inode_attributes(st
7048         struct nfs_inode *nfsi = NFS_I(inode);
7049         loff_t cur_size, new_isize;
7050         unsigned long invalid = 0;
7051 +       uid_t uid;
7052 +       gid_t gid;
7053 +       tag_t tag;
7054  
7055  
7056         /* Has the inode gone and changed behind our back? */
7057 @@ -966,13 +979,18 @@ static int nfs_check_inode_attributes(st
7058                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
7059         }
7060  
7061 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7062 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7063 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7064 +
7065         /* Have any file permissions changed? */
7066         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
7067                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7068 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
7069 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
7070                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7071 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
7072 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
7073                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7074 +               /* maybe check for tag too? */
7075  
7076         /* Has the link count changed? */
7077         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
7078 @@ -1207,6 +1225,9 @@ static int nfs_update_inode(struct inode
7079         unsigned long invalid = 0;
7080         unsigned long now = jiffies;
7081         unsigned long save_cache_validity;
7082 +       uid_t uid;
7083 +       gid_t gid;
7084 +       tag_t tag;
7085  
7086         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
7087                         __func__, inode->i_sb->s_id, inode->i_ino,
7088 @@ -1314,6 +1335,9 @@ static int nfs_update_inode(struct inode
7089                                 | NFS_INO_REVAL_PAGECACHE
7090                                 | NFS_INO_REVAL_FORCED);
7091  
7092 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7093 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7094 +       tag = inode->i_tag;
7095  
7096         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
7097                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
7098 @@ -1335,9 +1359,9 @@ static int nfs_update_inode(struct inode
7099                                 | NFS_INO_REVAL_FORCED);
7100  
7101         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
7102 -               if (inode->i_uid != fattr->uid) {
7103 +               if (uid != fattr->uid) {
7104                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7105 -                       inode->i_uid = fattr->uid;
7106 +                       uid = fattr->uid;
7107                 }
7108         } else if (server->caps & NFS_CAP_OWNER)
7109                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
7110 @@ -1346,9 +1370,9 @@ static int nfs_update_inode(struct inode
7111                                 | NFS_INO_REVAL_FORCED);
7112  
7113         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
7114 -               if (inode->i_gid != fattr->gid) {
7115 +               if (gid != fattr->gid) {
7116                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7117 -                       inode->i_gid = fattr->gid;
7118 +                       gid = fattr->gid;
7119                 }
7120         } else if (server->caps & NFS_CAP_OWNER_GROUP)
7121                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
7122 @@ -1356,6 +1380,10 @@ static int nfs_update_inode(struct inode
7123                                 | NFS_INO_INVALID_ACL
7124                                 | NFS_INO_REVAL_FORCED);
7125  
7126 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7127 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7128 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
7129 +
7130         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
7131                 if (inode->i_nlink != fattr->nlink) {
7132                         invalid |= NFS_INO_INVALID_ATTR;
7133 diff -NurpP --minimal linux-3.1/fs/nfs/nfs3xdr.c linux-3.1-vs2.3.1-rc2/fs/nfs/nfs3xdr.c
7134 --- linux-3.1/fs/nfs/nfs3xdr.c  2011-03-15 18:07:32.000000000 +0100
7135 +++ linux-3.1-vs2.3.1-rc2/fs/nfs/nfs3xdr.c      2011-10-24 18:53:33.000000000 +0200
7136 @@ -20,6 +20,7 @@
7137  #include <linux/nfs3.h>
7138  #include <linux/nfs_fs.h>
7139  #include <linux/nfsacl.h>
7140 +#include <linux/vs_tag.h>
7141  #include "internal.h"
7142  
7143  #define NFSDBG_FACILITY                NFSDBG_XDR
7144 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
7145   *             set_mtime       mtime;
7146   *     };
7147   */
7148 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
7149 +static void encode_sattr3(struct xdr_stream *xdr,
7150 +       const struct iattr *attr, int tag)
7151  {
7152         u32 nbytes;
7153         __be32 *p;
7154 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
7155         } else
7156                 *p++ = xdr_zero;
7157  
7158 -       if (attr->ia_valid & ATTR_UID) {
7159 +       if (attr->ia_valid & ATTR_UID ||
7160 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7161                 *p++ = xdr_one;
7162 -               *p++ = cpu_to_be32(attr->ia_uid);
7163 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
7164 +                       attr->ia_uid, attr->ia_tag));
7165         } else
7166                 *p++ = xdr_zero;
7167  
7168 -       if (attr->ia_valid & ATTR_GID) {
7169 +       if (attr->ia_valid & ATTR_GID ||
7170 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7171                 *p++ = xdr_one;
7172 -               *p++ = cpu_to_be32(attr->ia_gid);
7173 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
7174 +                       attr->ia_gid, attr->ia_tag));
7175         } else
7176                 *p++ = xdr_zero;
7177  
7178 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
7179                                       const struct nfs3_sattrargs *args)
7180  {
7181         encode_nfs_fh3(xdr, args->fh);
7182 -       encode_sattr3(xdr, args->sattr);
7183 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
7184         encode_sattrguard3(xdr, args);
7185  }
7186  
7187 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
7188   *     };
7189   */
7190  static void encode_createhow3(struct xdr_stream *xdr,
7191 -                             const struct nfs3_createargs *args)
7192 +       const struct nfs3_createargs *args, int tag)
7193  {
7194         encode_uint32(xdr, args->createmode);
7195         switch (args->createmode) {
7196         case NFS3_CREATE_UNCHECKED:
7197         case NFS3_CREATE_GUARDED:
7198 -               encode_sattr3(xdr, args->sattr);
7199 +               encode_sattr3(xdr, args->sattr, tag);
7200                 break;
7201         case NFS3_CREATE_EXCLUSIVE:
7202                 encode_createverf3(xdr, args->verifier);
7203 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
7204                                      const struct nfs3_createargs *args)
7205  {
7206         encode_diropargs3(xdr, args->fh, args->name, args->len);
7207 -       encode_createhow3(xdr, args);
7208 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
7209  }
7210  
7211  /*
7212 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
7213                                     const struct nfs3_mkdirargs *args)
7214  {
7215         encode_diropargs3(xdr, args->fh, args->name, args->len);
7216 -       encode_sattr3(xdr, args->sattr);
7217 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
7218  }
7219  
7220  /*
7221 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
7222   *     };
7223   */
7224  static void encode_symlinkdata3(struct xdr_stream *xdr,
7225 -                               const struct nfs3_symlinkargs *args)
7226 +       const struct nfs3_symlinkargs *args, int tag)
7227  {
7228 -       encode_sattr3(xdr, args->sattr);
7229 +       encode_sattr3(xdr, args->sattr, tag);
7230         encode_nfspath3(xdr, args->pages, args->pathlen);
7231  }
7232  
7233 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
7234                                       const struct nfs3_symlinkargs *args)
7235  {
7236         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
7237 -       encode_symlinkdata3(xdr, args);
7238 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
7239  }
7240  
7241  /*
7242 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
7243   *     };
7244   */
7245  static void encode_devicedata3(struct xdr_stream *xdr,
7246 -                              const struct nfs3_mknodargs *args)
7247 +       const struct nfs3_mknodargs *args, int tag)
7248  {
7249 -       encode_sattr3(xdr, args->sattr);
7250 +       encode_sattr3(xdr, args->sattr, tag);
7251         encode_specdata3(xdr, args->rdev);
7252  }
7253  
7254  static void encode_mknoddata3(struct xdr_stream *xdr,
7255 -                             const struct nfs3_mknodargs *args)
7256 +       const struct nfs3_mknodargs *args, int tag)
7257  {
7258         encode_ftype3(xdr, args->type);
7259         switch (args->type) {
7260         case NF3CHR:
7261         case NF3BLK:
7262 -               encode_devicedata3(xdr, args);
7263 +               encode_devicedata3(xdr, args, tag);
7264                 break;
7265         case NF3SOCK:
7266         case NF3FIFO:
7267 -               encode_sattr3(xdr, args->sattr);
7268 +               encode_sattr3(xdr, args->sattr, tag);
7269                 break;
7270         case NF3REG:
7271         case NF3DIR:
7272 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
7273                                     const struct nfs3_mknodargs *args)
7274  {
7275         encode_diropargs3(xdr, args->fh, args->name, args->len);
7276 -       encode_mknoddata3(xdr, args);
7277 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
7278  }
7279  
7280  /*
7281 diff -NurpP --minimal linux-3.1/fs/nfs/super.c linux-3.1-vs2.3.1-rc2/fs/nfs/super.c
7282 --- linux-3.1/fs/nfs/super.c    2011-10-24 18:45:27.000000000 +0200
7283 +++ linux-3.1-vs2.3.1-rc2/fs/nfs/super.c        2011-10-24 18:53:33.000000000 +0200
7284 @@ -53,6 +53,7 @@
7285  #include <linux/nfs_xdr.h>
7286  #include <linux/magic.h>
7287  #include <linux/parser.h>
7288 +#include <linux/vs_tag.h>
7289  
7290  #include <asm/system.h>
7291  #include <asm/uaccess.h>
7292 @@ -87,6 +88,7 @@ enum {
7293         Opt_sharecache, Opt_nosharecache,
7294         Opt_resvport, Opt_noresvport,
7295         Opt_fscache, Opt_nofscache,
7296 +       Opt_tag, Opt_notag,
7297  
7298         /* Mount options that take integer arguments */
7299         Opt_port,
7300 @@ -100,6 +102,7 @@ enum {
7301         Opt_mountvers,
7302         Opt_nfsvers,
7303         Opt_minorversion,
7304 +       Opt_tagid,
7305  
7306         /* Mount options that take string arguments */
7307         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
7308 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
7309         { Opt_fscache_uniq, "fsc=%s" },
7310         { Opt_local_lock, "local_lock=%s" },
7311  
7312 +       { Opt_tag, "tag" },
7313 +       { Opt_notag, "notag" },
7314 +       { Opt_tagid, "tagid=%u" },
7315 +
7316         { Opt_err, NULL }
7317  };
7318  
7319 @@ -650,6 +657,7 @@ static void nfs_show_mount_options(struc
7320                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
7321                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
7322                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
7323 +               { NFS_MOUNT_TAGGED, ",tag", "" },
7324                 { 0, NULL, NULL }
7325         };
7326         const struct proc_nfs_info *nfs_infop;
7327 @@ -1198,6 +1206,14 @@ static int nfs_parse_mount_options(char 
7328                         kfree(mnt->fscache_uniq);
7329                         mnt->fscache_uniq = NULL;
7330                         break;
7331 +#ifndef CONFIG_TAGGING_NONE
7332 +               case Opt_tag:
7333 +                       mnt->flags |= NFS_MOUNT_TAGGED;
7334 +                       break;
7335 +               case Opt_notag:
7336 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
7337 +                       break;
7338 +#endif
7339  
7340                 /*
7341                  * options that take numeric values
7342 @@ -1304,6 +1320,12 @@ static int nfs_parse_mount_options(char 
7343                                 goto out_invalid_value;
7344                         mnt->minorversion = option;
7345                         break;
7346 +#ifdef CONFIG_PROPAGATE
7347 +               case Opt_tagid:
7348 +                       /* use args[0] */
7349 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
7350 +                       break;
7351 +#endif
7352  
7353                 /*
7354                  * options that take text values
7355 diff -NurpP --minimal linux-3.1/fs/nfsd/auth.c linux-3.1-vs2.3.1-rc2/fs/nfsd/auth.c
7356 --- linux-3.1/fs/nfsd/auth.c    2010-02-25 11:52:05.000000000 +0100
7357 +++ linux-3.1-vs2.3.1-rc2/fs/nfsd/auth.c        2011-10-24 18:53:33.000000000 +0200
7358 @@ -1,6 +1,7 @@
7359  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
7360  
7361  #include <linux/sched.h>
7362 +#include <linux/vs_tag.h>
7363  #include "nfsd.h"
7364  #include "auth.h"
7365  
7366 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
7367  
7368         new->fsuid = rqstp->rq_cred.cr_uid;
7369         new->fsgid = rqstp->rq_cred.cr_gid;
7370 +       /* FIXME: this desperately needs a tag :)
7371 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
7372 +                       */
7373  
7374         rqgi = rqstp->rq_cred.cr_group_info;
7375  
7376 diff -NurpP --minimal linux-3.1/fs/nfsd/nfs3xdr.c linux-3.1-vs2.3.1-rc2/fs/nfsd/nfs3xdr.c
7377 --- linux-3.1/fs/nfsd/nfs3xdr.c 2011-07-22 11:18:05.000000000 +0200
7378 +++ linux-3.1-vs2.3.1-rc2/fs/nfsd/nfs3xdr.c     2011-10-24 18:53:33.000000000 +0200
7379 @@ -7,6 +7,7 @@
7380   */
7381  
7382  #include <linux/namei.h>
7383 +#include <linux/vs_tag.h>
7384  #include "xdr3.h"
7385  #include "auth.h"
7386  
7387 @@ -95,6 +96,8 @@ static __be32 *
7388  decode_sattr3(__be32 *p, struct iattr *iap)
7389  {
7390         u32     tmp;
7391 +       uid_t   uid = 0;
7392 +       gid_t   gid = 0;
7393  
7394         iap->ia_valid = 0;
7395  
7396 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
7397         }
7398         if (*p++) {
7399                 iap->ia_valid |= ATTR_UID;
7400 -               iap->ia_uid = ntohl(*p++);
7401 +               uid = ntohl(*p++);
7402         }
7403         if (*p++) {
7404                 iap->ia_valid |= ATTR_GID;
7405 -               iap->ia_gid = ntohl(*p++);
7406 +               gid = ntohl(*p++);
7407         }
7408 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7409 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7410 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7411         if (*p++) {
7412                 u64     newsize;
7413  
7414 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
7415         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
7416         *p++ = htonl((u32) stat->mode);
7417         *p++ = htonl((u32) stat->nlink);
7418 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7419 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7420 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7421 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
7422 +               stat->uid, stat->tag)));
7423 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7424 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
7425 +               stat->gid, stat->tag)));
7426         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
7427                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
7428         } else {
7429 diff -NurpP --minimal linux-3.1/fs/nfsd/nfs4xdr.c linux-3.1-vs2.3.1-rc2/fs/nfsd/nfs4xdr.c
7430 --- linux-3.1/fs/nfsd/nfs4xdr.c 2011-10-24 18:45:27.000000000 +0200
7431 +++ linux-3.1-vs2.3.1-rc2/fs/nfsd/nfs4xdr.c     2011-10-24 18:53:33.000000000 +0200
7432 @@ -46,6 +46,7 @@
7433  #include <linux/utsname.h>
7434  #include <linux/pagemap.h>
7435  #include <linux/sunrpc/svcauth_gss.h>
7436 +#include <linux/vs_tag.h>
7437  
7438  #include "idmap.h"
7439  #include "acl.h"
7440 @@ -2165,14 +2166,18 @@ out_acl:
7441                 WRITE32(stat.nlink);
7442         }
7443         if (bmval1 & FATTR4_WORD1_OWNER) {
7444 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
7445 +               status = nfsd4_encode_user(rqstp,
7446 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
7447 +                       stat.uid, stat.tag), &p, &buflen);
7448                 if (status == nfserr_resource)
7449                         goto out_resource;
7450                 if (status)
7451                         goto out;
7452         }
7453         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
7454 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
7455 +               status = nfsd4_encode_group(rqstp,
7456 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
7457 +                       stat.gid, stat.tag), &p, &buflen);
7458                 if (status == nfserr_resource)
7459                         goto out_resource;
7460                 if (status)
7461 diff -NurpP --minimal linux-3.1/fs/nfsd/nfsxdr.c linux-3.1-vs2.3.1-rc2/fs/nfsd/nfsxdr.c
7462 --- linux-3.1/fs/nfsd/nfsxdr.c  2011-05-22 16:17:53.000000000 +0200
7463 +++ linux-3.1-vs2.3.1-rc2/fs/nfsd/nfsxdr.c      2011-10-24 18:53:33.000000000 +0200
7464 @@ -6,6 +6,7 @@
7465  
7466  #include "xdr.h"
7467  #include "auth.h"
7468 +#include <linux/vs_tag.h>
7469  
7470  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7471  
7472 @@ -88,6 +89,8 @@ static __be32 *
7473  decode_sattr(__be32 *p, struct iattr *iap)
7474  {
7475         u32     tmp, tmp1;
7476 +       uid_t   uid = 0;
7477 +       gid_t   gid = 0;
7478  
7479         iap->ia_valid = 0;
7480  
7481 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
7482         }
7483         if ((tmp = ntohl(*p++)) != (u32)-1) {
7484                 iap->ia_valid |= ATTR_UID;
7485 -               iap->ia_uid = tmp;
7486 +               uid = tmp;
7487         }
7488         if ((tmp = ntohl(*p++)) != (u32)-1) {
7489                 iap->ia_valid |= ATTR_GID;
7490 -               iap->ia_gid = tmp;
7491 +               gid = tmp;
7492         }
7493 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7494 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7495 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7496         if ((tmp = ntohl(*p++)) != (u32)-1) {
7497                 iap->ia_valid |= ATTR_SIZE;
7498                 iap->ia_size = tmp;
7499 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
7500         *p++ = htonl(nfs_ftypes[type >> 12]);
7501         *p++ = htonl((u32) stat->mode);
7502         *p++ = htonl((u32) stat->nlink);
7503 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7504 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7505 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7506 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7507 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7508 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7509  
7510         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
7511                 *p++ = htonl(NFS_MAXPATHLEN);
7512 diff -NurpP --minimal linux-3.1/fs/ocfs2/dlmglue.c linux-3.1-vs2.3.1-rc2/fs/ocfs2/dlmglue.c
7513 --- linux-3.1/fs/ocfs2/dlmglue.c        2011-05-22 16:17:53.000000000 +0200
7514 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/dlmglue.c    2011-10-24 18:53:33.000000000 +0200
7515 @@ -2041,6 +2041,7 @@ static void __ocfs2_stuff_meta_lvb(struc
7516         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
7517         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
7518         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
7519 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
7520         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
7521         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
7522         lvb->lvb_iatime_packed  =
7523 @@ -2091,6 +2092,7 @@ static void ocfs2_refresh_inode_from_lvb
7524  
7525         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
7526         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
7527 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
7528         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
7529         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
7530         ocfs2_unpack_timespec(&inode->i_atime,
7531 diff -NurpP --minimal linux-3.1/fs/ocfs2/dlmglue.h linux-3.1-vs2.3.1-rc2/fs/ocfs2/dlmglue.h
7532 --- linux-3.1/fs/ocfs2/dlmglue.h        2010-10-21 13:07:50.000000000 +0200
7533 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/dlmglue.h    2011-10-24 18:53:33.000000000 +0200
7534 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
7535         __be16       lvb_inlink;
7536         __be32       lvb_iattr;
7537         __be32       lvb_igeneration;
7538 -       __be32       lvb_reserved2;
7539 +       __be16       lvb_itag;
7540 +       __be16       lvb_reserved2;
7541  };
7542  
7543  #define OCFS2_QINFO_LVB_VERSION 1
7544 diff -NurpP --minimal linux-3.1/fs/ocfs2/file.c linux-3.1-vs2.3.1-rc2/fs/ocfs2/file.c
7545 --- linux-3.1/fs/ocfs2/file.c   2011-10-24 18:45:27.000000000 +0200
7546 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/file.c       2011-10-24 18:53:33.000000000 +0200
7547 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
7548                 attr->ia_valid &= ~ATTR_SIZE;
7549  
7550  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
7551 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
7552 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
7553         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
7554                 return 0;
7555  
7556 diff -NurpP --minimal linux-3.1/fs/ocfs2/inode.c linux-3.1-vs2.3.1-rc2/fs/ocfs2/inode.c
7557 --- linux-3.1/fs/ocfs2/inode.c  2011-05-22 16:17:53.000000000 +0200
7558 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/inode.c      2011-10-24 18:53:33.000000000 +0200
7559 @@ -28,6 +28,7 @@
7560  #include <linux/highmem.h>
7561  #include <linux/pagemap.h>
7562  #include <linux/quotaops.h>
7563 +#include <linux/vs_tag.h>
7564  
7565  #include <asm/byteorder.h>
7566  
7567 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
7568  {
7569         unsigned int flags = OCFS2_I(inode)->ip_attr;
7570  
7571 -       inode->i_flags &= ~(S_IMMUTABLE |
7572 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
7573                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
7574  
7575         if (flags & OCFS2_IMMUTABLE_FL)
7576                 inode->i_flags |= S_IMMUTABLE;
7577 +       if (flags & OCFS2_IXUNLINK_FL)
7578 +               inode->i_flags |= S_IXUNLINK;
7579  
7580         if (flags & OCFS2_SYNC_FL)
7581                 inode->i_flags |= S_SYNC;
7582 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
7583                 inode->i_flags |= S_NOATIME;
7584         if (flags & OCFS2_DIRSYNC_FL)
7585                 inode->i_flags |= S_DIRSYNC;
7586 +
7587 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
7588 +
7589 +       if (flags & OCFS2_BARRIER_FL)
7590 +               inode->i_vflags |= V_BARRIER;
7591 +       if (flags & OCFS2_COW_FL)
7592 +               inode->i_vflags |= V_COW;
7593  }
7594  
7595  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
7596  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
7597  {
7598         unsigned int flags = oi->vfs_inode.i_flags;
7599 +       unsigned int vflags = oi->vfs_inode.i_vflags;
7600 +
7601 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
7602 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
7603 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
7604 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
7605 +
7606 +       if (flags & S_IMMUTABLE)
7607 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
7608 +       if (flags & S_IXUNLINK)
7609 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
7610  
7611 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
7612 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
7613         if (flags & S_SYNC)
7614                 oi->ip_attr |= OCFS2_SYNC_FL;
7615         if (flags & S_APPEND)
7616                 oi->ip_attr |= OCFS2_APPEND_FL;
7617 -       if (flags & S_IMMUTABLE)
7618 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
7619         if (flags & S_NOATIME)
7620                 oi->ip_attr |= OCFS2_NOATIME_FL;
7621         if (flags & S_DIRSYNC)
7622                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
7623 +
7624 +       if (vflags & V_BARRIER)
7625 +               oi->ip_attr |= OCFS2_BARRIER_FL;
7626 +       if (vflags & V_COW)
7627 +               oi->ip_attr |= OCFS2_COW_FL;
7628  }
7629  
7630  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
7631 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
7632         struct super_block *sb;
7633         struct ocfs2_super *osb;
7634         int use_plocks = 1;
7635 +       uid_t uid;
7636 +       gid_t gid;
7637  
7638         sb = inode->i_sb;
7639         osb = OCFS2_SB(sb);
7640 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
7641         inode->i_generation = le32_to_cpu(fe->i_generation);
7642         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
7643         inode->i_mode = le16_to_cpu(fe->i_mode);
7644 -       inode->i_uid = le32_to_cpu(fe->i_uid);
7645 -       inode->i_gid = le32_to_cpu(fe->i_gid);
7646 +       uid = le32_to_cpu(fe->i_uid);
7647 +       gid = le32_to_cpu(fe->i_gid);
7648 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7649 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7650 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
7651 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
7652  
7653         /* Fast symlinks will have i_size but no allocated clusters. */
7654         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
7655 diff -NurpP --minimal linux-3.1/fs/ocfs2/inode.h linux-3.1-vs2.3.1-rc2/fs/ocfs2/inode.h
7656 --- linux-3.1/fs/ocfs2/inode.h  2011-01-05 21:50:26.000000000 +0100
7657 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/inode.h      2011-10-24 18:53:33.000000000 +0200
7658 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
7659  
7660  void ocfs2_set_inode_flags(struct inode *inode);
7661  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
7662 +int ocfs2_sync_flags(struct inode *inode, int, int);
7663  
7664  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
7665  {
7666 diff -NurpP --minimal linux-3.1/fs/ocfs2/ioctl.c linux-3.1-vs2.3.1-rc2/fs/ocfs2/ioctl.c
7667 --- linux-3.1/fs/ocfs2/ioctl.c  2011-07-22 11:18:06.000000000 +0200
7668 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/ioctl.c      2011-10-24 18:53:33.000000000 +0200
7669 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
7670         return status;
7671  }
7672  
7673 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7674 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
7675 +{
7676 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
7677 +       struct buffer_head *bh = NULL;
7678 +       handle_t *handle = NULL;
7679 +       int status;
7680 +
7681 +       status = ocfs2_inode_lock(inode, &bh, 1);
7682 +       if (status < 0) {
7683 +               mlog_errno(status);
7684 +               return status;
7685 +       }
7686 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
7687 +       if (IS_ERR(handle)) {
7688 +               status = PTR_ERR(handle);
7689 +               mlog_errno(status);
7690 +               goto bail_unlock;
7691 +       }
7692 +
7693 +       inode->i_flags = flags;
7694 +       inode->i_vflags = vflags;
7695 +       ocfs2_get_inode_flags(OCFS2_I(inode));
7696 +
7697 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
7698 +       if (status < 0)
7699 +               mlog_errno(status);
7700 +
7701 +       ocfs2_commit_trans(osb, handle);
7702 +bail_unlock:
7703 +       ocfs2_inode_unlock(inode, 1);
7704 +       brelse(bh);
7705 +       return status;
7706 +}
7707 +
7708 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7709                                 unsigned mask)
7710  {
7711         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
7712 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
7713         if (!S_ISDIR(inode->i_mode))
7714                 flags &= ~OCFS2_DIRSYNC_FL;
7715  
7716 +       if (IS_BARRIER(inode)) {
7717 +               vxwprintk_task(1, "messing with the barrier.");
7718 +               goto bail_unlock;
7719 +       }
7720 +
7721         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
7722         if (IS_ERR(handle)) {
7723                 status = PTR_ERR(handle);
7724 @@ -880,6 +919,7 @@ bail:
7725         return status;
7726  }
7727  
7728 +
7729  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7730  {
7731         struct inode *inode = filp->f_path.dentry->d_inode;
7732 diff -NurpP --minimal linux-3.1/fs/ocfs2/namei.c linux-3.1-vs2.3.1-rc2/fs/ocfs2/namei.c
7733 --- linux-3.1/fs/ocfs2/namei.c  2011-10-24 18:45:27.000000000 +0200
7734 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/namei.c      2011-10-24 18:53:33.000000000 +0200
7735 @@ -41,6 +41,7 @@
7736  #include <linux/slab.h>
7737  #include <linux/highmem.h>
7738  #include <linux/quotaops.h>
7739 +#include <linux/vs_tag.h>
7740  
7741  #include <cluster/masklog.h>
7742  
7743 @@ -477,6 +478,7 @@ static int __ocfs2_mknod_locked(struct i
7744         struct ocfs2_dinode *fe = NULL;
7745         struct ocfs2_extent_list *fel;
7746         u16 feat;
7747 +       tag_t tag;
7748  
7749         *new_fe_bh = NULL;
7750  
7751 @@ -514,8 +516,11 @@ static int __ocfs2_mknod_locked(struct i
7752         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
7753         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
7754         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
7755 -       fe->i_uid = cpu_to_le32(inode->i_uid);
7756 -       fe->i_gid = cpu_to_le32(inode->i_gid);
7757 +
7758 +       tag = dx_current_fstag(osb->sb);
7759 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
7760 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
7761 +       inode->i_tag = tag;
7762         fe->i_mode = cpu_to_le16(inode->i_mode);
7763         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
7764                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
7765 diff -NurpP --minimal linux-3.1/fs/ocfs2/ocfs2.h linux-3.1-vs2.3.1-rc2/fs/ocfs2/ocfs2.h
7766 --- linux-3.1/fs/ocfs2/ocfs2.h  2011-05-22 16:17:53.000000000 +0200
7767 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/ocfs2.h      2011-10-24 18:53:33.000000000 +0200
7768 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
7769                                                      writes */
7770         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
7771         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
7772 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
7773  };
7774  
7775  #define OCFS2_OSB_SOFT_RO                      0x0001
7776 diff -NurpP --minimal linux-3.1/fs/ocfs2/ocfs2_fs.h linux-3.1-vs2.3.1-rc2/fs/ocfs2/ocfs2_fs.h
7777 --- linux-3.1/fs/ocfs2/ocfs2_fs.h       2011-05-22 16:17:53.000000000 +0200
7778 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/ocfs2_fs.h   2011-10-24 18:53:33.000000000 +0200
7779 @@ -266,6 +266,11 @@
7780  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
7781  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
7782  
7783 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
7784 +
7785 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
7786 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
7787 +
7788  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
7789  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
7790  
7791 diff -NurpP --minimal linux-3.1/fs/ocfs2/super.c linux-3.1-vs2.3.1-rc2/fs/ocfs2/super.c
7792 --- linux-3.1/fs/ocfs2/super.c  2011-07-22 11:18:06.000000000 +0200
7793 +++ linux-3.1-vs2.3.1-rc2/fs/ocfs2/super.c      2011-10-24 18:53:33.000000000 +0200
7794 @@ -184,6 +184,7 @@ enum {
7795         Opt_coherency_full,
7796         Opt_resv_level,
7797         Opt_dir_resv_level,
7798 +       Opt_tag, Opt_notag, Opt_tagid,
7799         Opt_err,
7800  };
7801  
7802 @@ -215,6 +216,9 @@ static const match_table_t tokens = {
7803         {Opt_coherency_full, "coherency=full"},
7804         {Opt_resv_level, "resv_level=%u"},
7805         {Opt_dir_resv_level, "dir_resv_level=%u"},
7806 +       {Opt_tag, "tag"},
7807 +       {Opt_notag, "notag"},
7808 +       {Opt_tagid, "tagid=%u"},
7809         {Opt_err, NULL}
7810  };
7811  
7812 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
7813                 goto out;
7814         }
7815  
7816 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
7817 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
7818 +               ret = -EINVAL;
7819 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
7820 +               goto out;
7821 +       }
7822 +
7823         /* We're going to/from readonly mode. */
7824         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
7825                 /* Disable quota accounting before remounting RO */
7826 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
7827  
7828         ocfs2_complete_mount_recovery(osb);
7829  
7830 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
7831 +               sb->s_flags |= MS_TAGGED;
7832 +
7833         if (ocfs2_mount_local(osb))
7834                 snprintf(nodestr, sizeof(nodestr), "local");
7835         else
7836 @@ -1506,6 +1520,20 @@ static int ocfs2_parse_options(struct su
7837                             option < OCFS2_MAX_RESV_LEVEL)
7838                                 mopt->dir_resv_level = option;
7839                         break;
7840 +#ifndef CONFIG_TAGGING_NONE
7841 +               case Opt_tag:
7842 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
7843 +                       break;
7844 +               case Opt_notag:
7845 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
7846 +                       break;
7847 +#endif
7848 +#ifdef CONFIG_PROPAGATE
7849 +               case Opt_tagid:
7850 +                       /* use args[0] */
7851 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
7852 +                       break;
7853 +#endif
7854                 default:
7855                         mlog(ML_ERROR,
7856                              "Unrecognized mount option \"%s\" "
7857 diff -NurpP --minimal linux-3.1/fs/open.c linux-3.1-vs2.3.1-rc2/fs/open.c
7858 --- linux-3.1/fs/open.c 2011-10-24 18:45:27.000000000 +0200
7859 +++ linux-3.1-vs2.3.1-rc2/fs/open.c     2011-10-30 02:06:37.000000000 +0100
7860 @@ -30,6 +30,11 @@
7861  #include <linux/fs_struct.h>
7862  #include <linux/ima.h>
7863  #include <linux/dnotify.h>
7864 +#include <linux/vs_base.h>
7865 +#include <linux/vs_limit.h>
7866 +#include <linux/vs_tag.h>
7867 +#include <linux/vs_cowbl.h>
7868 +#include <linux/vserver/dlimit.h>
7869  
7870  #include "internal.h"
7871  
7872 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
7873         error = user_path(pathname, &path);
7874         if (error)
7875                 goto out;
7876 +
7877 +#ifdef CONFIG_VSERVER_COWBL
7878 +       error = cow_check_and_break(&path);
7879 +       if (error)
7880 +               goto dput_and_out;
7881 +#endif
7882         inode = path.dentry->d_inode;
7883  
7884         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
7885 @@ -489,6 +500,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
7886  
7887         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
7888         if (!error) {
7889 +#ifdef CONFIG_VSERVER_COWBL
7890 +               error = cow_check_and_break(&path);
7891 +               if (!error)
7892 +#endif
7893                 error = chmod_common(&path, mode);
7894                 path_put(&path);
7895         }
7896 @@ -509,11 +524,11 @@ static int chown_common(struct path *pat
7897         newattrs.ia_valid =  ATTR_CTIME;
7898         if (user != (uid_t) -1) {
7899                 newattrs.ia_valid |= ATTR_UID;
7900 -               newattrs.ia_uid = user;
7901 +               newattrs.ia_uid = dx_map_uid(user);
7902         }
7903         if (group != (gid_t) -1) {
7904                 newattrs.ia_valid |= ATTR_GID;
7905 -               newattrs.ia_gid = group;
7906 +               newattrs.ia_gid = dx_map_gid(group);
7907         }
7908         if (!S_ISDIR(inode->i_mode))
7909                 newattrs.ia_valid |=
7910 @@ -538,6 +553,10 @@ SYSCALL_DEFINE3(chown, const char __user
7911         error = mnt_want_write(path.mnt);
7912         if (error)
7913                 goto out_release;
7914 +#ifdef CONFIG_VSERVER_COWBL
7915 +       error = cow_check_and_break(&path);
7916 +       if (!error)
7917 +#endif
7918         error = chown_common(&path, user, group);
7919         mnt_drop_write(path.mnt);
7920  out_release:
7921 @@ -565,6 +584,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
7922         error = mnt_want_write(path.mnt);
7923         if (error)
7924                 goto out_release;
7925 +#ifdef CONFIG_VSERVER_COWBL
7926 +       error = cow_check_and_break(&path);
7927 +       if (!error)
7928 +#endif
7929         error = chown_common(&path, user, group);
7930         mnt_drop_write(path.mnt);
7931  out_release:
7932 @@ -584,6 +607,10 @@ SYSCALL_DEFINE3(lchown, const char __use
7933         error = mnt_want_write(path.mnt);
7934         if (error)
7935                 goto out_release;
7936 +#ifdef CONFIG_VSERVER_COWBL
7937 +       error = cow_check_and_break(&path);
7938 +       if (!error)
7939 +#endif
7940         error = chown_common(&path, user, group);
7941         mnt_drop_write(path.mnt);
7942  out_release:
7943 @@ -835,6 +862,7 @@ static void __put_unused_fd(struct files
7944         __FD_CLR(fd, fdt->open_fds);
7945         if (fd < files->next_fd)
7946                 files->next_fd = fd;
7947 +       vx_openfd_dec(fd);
7948  }
7949  
7950  void put_unused_fd(unsigned int fd)
7951 diff -NurpP --minimal linux-3.1/fs/proc/array.c linux-3.1-vs2.3.1-rc2/fs/proc/array.c
7952 --- linux-3.1/fs/proc/array.c   2011-10-24 18:45:27.000000000 +0200
7953 +++ linux-3.1-vs2.3.1-rc2/fs/proc/array.c       2011-10-24 18:53:33.000000000 +0200
7954 @@ -81,6 +81,8 @@
7955  #include <linux/pid_namespace.h>
7956  #include <linux/ptrace.h>
7957  #include <linux/tracehook.h>
7958 +#include <linux/vs_context.h>
7959 +#include <linux/vs_network.h>
7960  
7961  #include <asm/pgtable.h>
7962  #include <asm/processor.h>
7963 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
7964         rcu_read_lock();
7965         ppid = pid_alive(p) ?
7966                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
7967 +       if (unlikely(vx_current_initpid(p->pid)))
7968 +               ppid = 0;
7969 +
7970         tpid = 0;
7971         if (pid_alive(p)) {
7972                 struct task_struct *tracer = ptrace_parent(p);
7973 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
7974  }
7975  
7976  static void render_cap_t(struct seq_file *m, const char *header,
7977 -                       kernel_cap_t *a)
7978 +                       struct vx_info *vxi, kernel_cap_t *a)
7979  {
7980         unsigned __capi;
7981  
7982 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
7983         cap_bset        = cred->cap_bset;
7984         rcu_read_unlock();
7985  
7986 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
7987 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
7988 -       render_cap_t(m, "CapEff:\t", &cap_effective);
7989 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
7990 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
7991 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
7992 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
7993 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
7994 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
7995  }
7996  
7997  static inline void task_context_switch_counts(struct seq_file *m,
7998 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
7999         seq_putc(m, '\n');
8000  }
8001  
8002 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
8003 +                       struct pid *pid, struct task_struct *task)
8004 +{
8005 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
8006 +                       "Count:\t%u\n"
8007 +                       "uts:\t%p(%c)\n"
8008 +                       "ipc:\t%p(%c)\n"
8009 +                       "mnt:\t%p(%c)\n"
8010 +                       "pid:\t%p(%c)\n"
8011 +                       "net:\t%p(%c)\n",
8012 +                       task->nsproxy,
8013 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
8014 +                       atomic_read(&task->nsproxy->count),
8015 +                       task->nsproxy->uts_ns,
8016 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
8017 +                       task->nsproxy->ipc_ns,
8018 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
8019 +                       task->nsproxy->mnt_ns,
8020 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
8021 +                       task->nsproxy->pid_ns,
8022 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
8023 +                       task->nsproxy->net_ns,
8024 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
8025 +       return 0;
8026 +}
8027 +
8028 +void task_vs_id(struct seq_file *m, struct task_struct *task)
8029 +{
8030 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
8031 +               return;
8032 +
8033 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
8034 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
8035 +}
8036 +
8037 +
8038  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
8039                         struct pid *pid, struct task_struct *task)
8040  {
8041 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
8042         task_cap(m, task);
8043         task_cpus_allowed(m, task);
8044         cpuset_task_status_allowed(m, task);
8045 +       task_vs_id(m, task);
8046         task_context_switch_counts(m, task);
8047         return 0;
8048  }
8049 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
8050         /* convert nsec -> ticks */
8051         start_time = nsec_to_clock_t(start_time);
8052  
8053 +       /* fixup start time for virt uptime */
8054 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
8055 +               unsigned long long bias =
8056 +                       current->vx_info->cvirt.bias_clock;
8057 +
8058 +               if (start_time > bias)
8059 +                       start_time -= bias;
8060 +               else
8061 +                       start_time = 0;
8062 +       }
8063 +
8064         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
8065  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
8066  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
8067 diff -NurpP --minimal linux-3.1/fs/proc/base.c linux-3.1-vs2.3.1-rc2/fs/proc/base.c
8068 --- linux-3.1/fs/proc/base.c    2011-10-24 18:45:27.000000000 +0200
8069 +++ linux-3.1-vs2.3.1-rc2/fs/proc/base.c        2011-10-24 18:53:33.000000000 +0200
8070 @@ -83,6 +83,8 @@
8071  #include <linux/pid_namespace.h>
8072  #include <linux/fs_struct.h>
8073  #include <linux/slab.h>
8074 +#include <linux/vs_context.h>
8075 +#include <linux/vs_network.h>
8076  #ifdef CONFIG_HARDWALL
8077  #include <asm/hardwall.h>
8078  #endif
8079 @@ -1102,11 +1104,16 @@ static ssize_t oom_adjust_write(struct f
8080                 goto err_task_lock;
8081         }
8082  
8083 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
8084 +       if (oom_adjust < task->signal->oom_adj &&
8085 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
8086                 err = -EACCES;
8087                 goto err_sighand;
8088         }
8089  
8090 +       /* prevent guest processes from circumventing the oom killer */
8091 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
8092 +               oom_adjust = OOM_ADJUST_MIN;
8093 +
8094         if (oom_adjust != task->signal->oom_adj) {
8095                 if (oom_adjust == OOM_DISABLE)
8096                         atomic_inc(&task->mm->oom_disable_count);
8097 @@ -1274,7 +1281,7 @@ static ssize_t proc_loginuid_write(struc
8098         ssize_t length;
8099         uid_t loginuid;
8100  
8101 -       if (!capable(CAP_AUDIT_CONTROL))
8102 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
8103                 return -EPERM;
8104  
8105         rcu_read_lock();
8106 @@ -1721,6 +1728,8 @@ struct inode *proc_pid_make_inode(struct
8107                 inode->i_gid = cred->egid;
8108                 rcu_read_unlock();
8109         }
8110 +       /* procfs is xid tagged */
8111 +       inode->i_tag = (tag_t)vx_task_xid(task);
8112         security_task_to_inode(task, inode);
8113  
8114  out:
8115 @@ -1757,6 +1766,8 @@ int pid_getattr(struct vfsmount *mnt, st
8116  
8117  /* dentry stuff */
8118  
8119 +static unsigned name_to_int(struct dentry *dentry);
8120 +
8121  /*
8122   *     Exceptional case: normally we are not allowed to unhash a busy
8123   * directory. In this case, however, we can do it - no aliasing problems
8124 @@ -1785,6 +1796,12 @@ int pid_revalidate(struct dentry *dentry
8125         task = get_proc_task(inode);
8126  
8127         if (task) {
8128 +               unsigned pid = name_to_int(dentry);
8129 +
8130 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
8131 +                       put_task_struct(task);
8132 +                       goto drop;
8133 +               }
8134                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
8135                     task_dumpable(task)) {
8136                         rcu_read_lock();
8137 @@ -1801,6 +1818,7 @@ int pid_revalidate(struct dentry *dentry
8138                 put_task_struct(task);
8139                 return 1;
8140         }
8141 +drop:
8142         d_drop(dentry);
8143         return 0;
8144  }
8145 @@ -2290,6 +2308,13 @@ static struct dentry *proc_pident_lookup
8146         if (!task)
8147                 goto out_no_task;
8148  
8149 +       /* TODO: maybe we can come up with a generic approach? */
8150 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
8151 +               (dentry->d_name.len == 5) &&
8152 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
8153 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
8154 +               goto out;
8155 +
8156         /*
8157          * Yes, it does not scale. And it should not. Don't add
8158          * new entries into /proc/<tgid>/ without very good reasons.
8159 @@ -2675,7 +2700,7 @@ out_iput:
8160  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
8161  {
8162         struct dentry *error;
8163 -       struct task_struct *task = get_proc_task(dir);
8164 +       struct task_struct *task = get_proc_task_real(dir);
8165         const struct pid_entry *p, *last;
8166  
8167         error = ERR_PTR(-ENOENT);
8168 @@ -2782,6 +2807,9 @@ static int proc_pid_personality(struct s
8169  static const struct file_operations proc_task_operations;
8170  static const struct inode_operations proc_task_inode_operations;
8171  
8172 +extern int proc_pid_vx_info(struct task_struct *, char *);
8173 +extern int proc_pid_nx_info(struct task_struct *, char *);
8174 +
8175  static const struct pid_entry tgid_base_stuff[] = {
8176         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
8177         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
8178 @@ -2845,6 +2873,8 @@ static const struct pid_entry tgid_base_
8179  #ifdef CONFIG_CGROUPS
8180         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
8181  #endif
8182 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
8183 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
8184         INF("oom_score",  S_IRUGO, proc_oom_score),
8185         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
8186         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
8187 @@ -2864,6 +2894,7 @@ static const struct pid_entry tgid_base_
8188  #ifdef CONFIG_HARDWALL
8189         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
8190  #endif
8191 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
8192  };
8193  
8194  static int proc_tgid_base_readdir(struct file * filp,
8195 @@ -3056,7 +3087,7 @@ retry:
8196         iter.task = NULL;
8197         pid = find_ge_pid(iter.tgid, ns);
8198         if (pid) {
8199 -               iter.tgid = pid_nr_ns(pid, ns);
8200 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
8201                 iter.task = pid_task(pid, PIDTYPE_PID);
8202                 /* What we to know is if the pid we have find is the
8203                  * pid of a thread_group_leader.  Testing for task
8204 @@ -3086,7 +3117,7 @@ static int proc_pid_fill_cache(struct fi
8205         struct tgid_iter iter)
8206  {
8207         char name[PROC_NUMBUF];
8208 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
8209 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
8210         return proc_fill_cache(filp, dirent, filldir, name, len,
8211                                 proc_pid_instantiate, iter.task, NULL);
8212  }
8213 @@ -3103,7 +3134,7 @@ int proc_pid_readdir(struct file * filp,
8214                 goto out_no_task;
8215         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
8216  
8217 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
8218 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
8219         if (!reaper)
8220                 goto out_no_task;
8221  
8222 @@ -3120,6 +3151,8 @@ int proc_pid_readdir(struct file * filp,
8223              iter.task;
8224              iter.tgid += 1, iter = next_tgid(ns, iter)) {
8225                 filp->f_pos = iter.tgid + TGID_OFFSET;
8226 +               if (!vx_proc_task_visible(iter.task))
8227 +                       continue;
8228                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
8229                         put_task_struct(iter.task);
8230                         goto out;
8231 @@ -3273,6 +3306,8 @@ static struct dentry *proc_task_lookup(s
8232         tid = name_to_int(dentry);
8233         if (tid == ~0U)
8234                 goto out;
8235 +       if (vx_current_initpid(tid))
8236 +               goto out;
8237  
8238         ns = dentry->d_sb->s_fs_info;
8239         rcu_read_lock();
8240 diff -NurpP --minimal linux-3.1/fs/proc/generic.c linux-3.1-vs2.3.1-rc2/fs/proc/generic.c
8241 --- linux-3.1/fs/proc/generic.c 2011-10-24 18:45:27.000000000 +0200
8242 +++ linux-3.1-vs2.3.1-rc2/fs/proc/generic.c     2011-10-24 18:53:33.000000000 +0200
8243 @@ -22,6 +22,7 @@
8244  #include <linux/bitops.h>
8245  #include <linux/spinlock.h>
8246  #include <linux/completion.h>
8247 +#include <linux/vserver/inode.h>
8248  #include <asm/uaccess.h>
8249  
8250  #include "internal.h"
8251 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
8252         for (de = de->subdir; de ; de = de->next) {
8253                 if (de->namelen != dentry->d_name.len)
8254                         continue;
8255 +               if (!vx_hide_check(0, de->vx_flags))
8256 +                       continue;
8257                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
8258                         pde_get(de);
8259                         spin_unlock(&proc_subdir_lock);
8260                         error = -EINVAL;
8261                         inode = proc_get_inode(dir->i_sb, de);
8262 +                       /* generic proc entries belong to the host */
8263 +                       inode->i_tag = 0;
8264                         goto out_unlock;
8265                 }
8266         }
8267 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
8268  
8269                                 /* filldir passes info to user space */
8270                                 pde_get(de);
8271 +                               if (!vx_hide_check(0, de->vx_flags))
8272 +                                       goto skip;
8273                                 spin_unlock(&proc_subdir_lock);
8274                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
8275                                             de->low_ino, de->mode >> 12) < 0) {
8276 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
8277                                         goto out;
8278                                 }
8279                                 spin_lock(&proc_subdir_lock);
8280 +                       skip:
8281                                 filp->f_pos++;
8282                                 next = de->next;
8283                                 pde_put(de);
8284 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
8285         ent->nlink = nlink;
8286         atomic_set(&ent->count, 1);
8287         ent->pde_users = 0;
8288 +       ent->vx_flags = IATTR_PROC_DEFAULT;
8289         spin_lock_init(&ent->pde_unload_lock);
8290         ent->pde_unload_completion = NULL;
8291         INIT_LIST_HEAD(&ent->pde_openers);
8292 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
8293                                 kfree(ent->data);
8294                                 kfree(ent);
8295                                 ent = NULL;
8296 -                       }
8297 +                       } else
8298 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
8299                 } else {
8300                         kfree(ent);
8301                         ent = NULL;
8302 diff -NurpP --minimal linux-3.1/fs/proc/inode.c linux-3.1-vs2.3.1-rc2/fs/proc/inode.c
8303 --- linux-3.1/fs/proc/inode.c   2011-10-24 18:45:27.000000000 +0200
8304 +++ linux-3.1-vs2.3.1-rc2/fs/proc/inode.c       2011-10-24 18:53:33.000000000 +0200
8305 @@ -442,6 +442,8 @@ struct inode *proc_get_inode(struct supe
8306                         inode->i_uid = de->uid;
8307                         inode->i_gid = de->gid;
8308                 }
8309 +               if (de->vx_flags)
8310 +                       PROC_I(inode)->vx_flags = de->vx_flags;
8311                 if (de->size)
8312                         inode->i_size = de->size;
8313                 if (de->nlink)
8314 diff -NurpP --minimal linux-3.1/fs/proc/internal.h linux-3.1-vs2.3.1-rc2/fs/proc/internal.h
8315 --- linux-3.1/fs/proc/internal.h        2011-07-22 11:18:06.000000000 +0200
8316 +++ linux-3.1-vs2.3.1-rc2/fs/proc/internal.h    2011-10-24 18:53:33.000000000 +0200
8317 @@ -10,6 +10,7 @@
8318   */
8319  
8320  #include <linux/proc_fs.h>
8321 +#include <linux/vs_pid.h>
8322  
8323  extern struct proc_dir_entry proc_root;
8324  #ifdef CONFIG_PROC_SYSCTL
8325 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
8326                                 struct pid *pid, struct task_struct *task);
8327  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
8328                                 struct pid *pid, struct task_struct *task);
8329 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
8330 +                               struct pid *pid, struct task_struct *task);
8331 +
8332  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
8333  
8334  extern const struct file_operations proc_maps_operations;
8335 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
8336         return PROC_I(inode)->pid;
8337  }
8338  
8339 -static inline struct task_struct *get_proc_task(struct inode *inode)
8340 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
8341  {
8342         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
8343  }
8344  
8345 +static inline struct task_struct *get_proc_task(struct inode *inode)
8346 +{
8347 +       return vx_get_proc_task(inode, proc_pid(inode));
8348 +}
8349 +
8350  static inline int proc_fd(struct inode *inode)
8351  {
8352         return PROC_I(inode)->fd;
8353 diff -NurpP --minimal linux-3.1/fs/proc/loadavg.c linux-3.1-vs2.3.1-rc2/fs/proc/loadavg.c
8354 --- linux-3.1/fs/proc/loadavg.c 2009-09-10 15:26:23.000000000 +0200
8355 +++ linux-3.1-vs2.3.1-rc2/fs/proc/loadavg.c     2011-10-24 18:53:33.000000000 +0200
8356 @@ -12,15 +12,27 @@
8357  
8358  static int loadavg_proc_show(struct seq_file *m, void *v)
8359  {
8360 +       unsigned long running;
8361 +       unsigned int threads;
8362         unsigned long avnrun[3];
8363  
8364         get_avenrun(avnrun, FIXED_1/200, 0);
8365  
8366 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
8367 +               struct vx_info *vxi = current_vx_info();
8368 +
8369 +               running = atomic_read(&vxi->cvirt.nr_running);
8370 +               threads = atomic_read(&vxi->cvirt.nr_threads);
8371 +       } else {
8372 +               running = nr_running();
8373 +               threads = nr_threads;
8374 +       }
8375 +
8376         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
8377                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
8378                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
8379                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
8380 -               nr_running(), nr_threads,
8381 +               running, threads,
8382                 task_active_pid_ns(current)->last_pid);
8383         return 0;
8384  }
8385 diff -NurpP --minimal linux-3.1/fs/proc/meminfo.c linux-3.1-vs2.3.1-rc2/fs/proc/meminfo.c
8386 --- linux-3.1/fs/proc/meminfo.c 2011-10-24 18:45:27.000000000 +0200
8387 +++ linux-3.1-vs2.3.1-rc2/fs/proc/meminfo.c     2011-10-24 18:53:33.000000000 +0200
8388 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
8389         allowed = ((totalram_pages - hugetlb_total_pages())
8390                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
8391  
8392 -       cached = global_page_state(NR_FILE_PAGES) -
8393 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
8394 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
8395                         total_swapcache_pages - i.bufferram;
8396         if (cached < 0)
8397                 cached = 0;
8398 diff -NurpP --minimal linux-3.1/fs/proc/root.c linux-3.1-vs2.3.1-rc2/fs/proc/root.c
8399 --- linux-3.1/fs/proc/root.c    2011-10-24 18:45:27.000000000 +0200
8400 +++ linux-3.1-vs2.3.1-rc2/fs/proc/root.c        2011-10-24 18:53:33.000000000 +0200
8401 @@ -18,9 +18,14 @@
8402  #include <linux/bitops.h>
8403  #include <linux/mount.h>
8404  #include <linux/pid_namespace.h>
8405 +#include <linux/vserver/inode.h>
8406  
8407  #include "internal.h"
8408  
8409 +struct proc_dir_entry *proc_virtual;
8410 +
8411 +extern void proc_vx_init(void);
8412 +
8413  static int proc_test_super(struct super_block *sb, void *data)
8414  {
8415         return sb->s_fs_info == data;
8416 @@ -125,6 +130,7 @@ void __init proc_root_init(void)
8417  #endif
8418         proc_mkdir("bus", NULL);
8419         proc_sys_init();
8420 +       proc_vx_init();
8421  }
8422  
8423  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
8424 @@ -192,6 +198,7 @@ struct proc_dir_entry proc_root = {
8425         .proc_iops      = &proc_root_inode_operations, 
8426         .proc_fops      = &proc_root_operations,
8427         .parent         = &proc_root,
8428 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
8429         .name           = "/proc",
8430  };
8431  
8432 diff -NurpP --minimal linux-3.1/fs/proc/uptime.c linux-3.1-vs2.3.1-rc2/fs/proc/uptime.c
8433 --- linux-3.1/fs/proc/uptime.c  2009-12-03 20:02:53.000000000 +0100
8434 +++ linux-3.1-vs2.3.1-rc2/fs/proc/uptime.c      2011-10-24 18:53:33.000000000 +0200
8435 @@ -4,22 +4,22 @@
8436  #include <linux/sched.h>
8437  #include <linux/seq_file.h>
8438  #include <linux/time.h>
8439 -#include <linux/kernel_stat.h>
8440 +#include <linux/vserver/cvirt.h>
8441  #include <asm/cputime.h>
8442  
8443  static int uptime_proc_show(struct seq_file *m, void *v)
8444  {
8445         struct timespec uptime;
8446         struct timespec idle;
8447 -       int i;
8448 -       cputime_t idletime = cputime_zero;
8449 -
8450 -       for_each_possible_cpu(i)
8451 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
8452 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
8453  
8454         do_posix_clock_monotonic_gettime(&uptime);
8455         monotonic_to_bootbased(&uptime);
8456         cputime_to_timespec(idletime, &idle);
8457 +
8458 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
8459 +               vx_vsi_uptime(&uptime, &idle);
8460 +
8461         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
8462                         (unsigned long) uptime.tv_sec,
8463                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
8464 diff -NurpP --minimal linux-3.1/fs/quota/dquot.c linux-3.1-vs2.3.1-rc2/fs/quota/dquot.c
8465 --- linux-3.1/fs/quota/dquot.c  2011-07-22 11:18:06.000000000 +0200
8466 +++ linux-3.1-vs2.3.1-rc2/fs/quota/dquot.c      2011-10-24 18:53:33.000000000 +0200
8467 @@ -1548,6 +1548,9 @@ int __dquot_alloc_space(struct inode *in
8468         int reserve = flags & DQUOT_SPACE_RESERVE;
8469         int nofail = flags & DQUOT_SPACE_NOFAIL;
8470  
8471 +       if ((ret = dl_alloc_space(inode, number)))
8472 +               return ret;
8473 +
8474         /*
8475          * First test before acquiring mutex - solves deadlocks when we
8476          * re-enter the quota code and are already holding the mutex
8477 @@ -1602,6 +1605,9 @@ int dquot_alloc_inode(const struct inode
8478         int cnt, ret = 0;
8479         char warntype[MAXQUOTAS];
8480  
8481 +       if ((ret = dl_alloc_inode(inode)))
8482 +               return ret;
8483 +
8484         /* First test before acquiring mutex - solves deadlocks when we
8485           * re-enter the quota code and are already holding the mutex */
8486         if (!dquot_active(inode))
8487 @@ -1672,6 +1678,8 @@ void __dquot_free_space(struct inode *in
8488         char warntype[MAXQUOTAS];
8489         int reserve = flags & DQUOT_SPACE_RESERVE;
8490  
8491 +       dl_free_space(inode, number);
8492 +
8493         /* First test before acquiring mutex - solves deadlocks when we
8494           * re-enter the quota code and are already holding the mutex */
8495         if (!dquot_active(inode)) {
8496 @@ -1710,6 +1718,8 @@ void dquot_free_inode(const struct inode
8497         unsigned int cnt;
8498         char warntype[MAXQUOTAS];
8499  
8500 +       dl_free_inode(inode);
8501 +
8502         /* First test before acquiring mutex - solves deadlocks when we
8503           * re-enter the quota code and are already holding the mutex */
8504         if (!dquot_active(inode))
8505 diff -NurpP --minimal linux-3.1/fs/quota/quota.c linux-3.1-vs2.3.1-rc2/fs/quota/quota.c
8506 --- linux-3.1/fs/quota/quota.c  2011-10-24 18:45:27.000000000 +0200
8507 +++ linux-3.1-vs2.3.1-rc2/fs/quota/quota.c      2011-10-24 18:53:33.000000000 +0200
8508 @@ -8,6 +8,7 @@
8509  #include <linux/fs.h>
8510  #include <linux/namei.h>
8511  #include <linux/slab.h>
8512 +#include <linux/vs_context.h>
8513  #include <asm/current.h>
8514  #include <asm/uaccess.h>
8515  #include <linux/kernel.h>
8516 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
8517                         break;
8518                 /*FALLTHROUGH*/
8519         default:
8520 -               if (!capable(CAP_SYS_ADMIN))
8521 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8522                         return -EPERM;
8523         }
8524  
8525 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
8526         }
8527  }
8528  
8529 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8530 +
8531 +#include <linux/vroot.h>
8532 +#include <linux/major.h>
8533 +#include <linux/module.h>
8534 +#include <linux/kallsyms.h>
8535 +#include <linux/vserver/debug.h>
8536 +
8537 +static vroot_grb_func *vroot_get_real_bdev = NULL;
8538 +
8539 +static DEFINE_SPINLOCK(vroot_grb_lock);
8540 +
8541 +int register_vroot_grb(vroot_grb_func *func) {
8542 +       int ret = -EBUSY;
8543 +
8544 +       spin_lock(&vroot_grb_lock);
8545 +       if (!vroot_get_real_bdev) {
8546 +               vroot_get_real_bdev = func;
8547 +               ret = 0;
8548 +       }
8549 +       spin_unlock(&vroot_grb_lock);
8550 +       return ret;
8551 +}
8552 +EXPORT_SYMBOL(register_vroot_grb);
8553 +
8554 +int unregister_vroot_grb(vroot_grb_func *func) {
8555 +       int ret = -EINVAL;
8556 +
8557 +       spin_lock(&vroot_grb_lock);
8558 +       if (vroot_get_real_bdev) {
8559 +               vroot_get_real_bdev = NULL;
8560 +               ret = 0;
8561 +       }
8562 +       spin_unlock(&vroot_grb_lock);
8563 +       return ret;
8564 +}
8565 +EXPORT_SYMBOL(unregister_vroot_grb);
8566 +
8567 +#endif
8568 +
8569  /*
8570   * look up a superblock on which quota ops will be performed
8571   * - use the name of a block device to find the superblock thereon
8572 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
8573         putname(tmp);
8574         if (IS_ERR(bdev))
8575                 return ERR_CAST(bdev);
8576 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8577 +       if (bdev && bdev->bd_inode &&
8578 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
8579 +               struct block_device *bdnew = (void *)-EINVAL;
8580 +
8581 +               if (vroot_get_real_bdev)
8582 +                       bdnew = vroot_get_real_bdev(bdev);
8583 +               else
8584 +                       vxdprintk(VXD_CBIT(misc, 0),
8585 +                                       "vroot_get_real_bdev not set");
8586 +               bdput(bdev);
8587 +               if (IS_ERR(bdnew))
8588 +                       return ERR_PTR(PTR_ERR(bdnew));
8589 +               bdev = bdnew;
8590 +       }
8591 +#endif
8592         sb = get_super(bdev);
8593         bdput(bdev);
8594         if (!sb)
8595 diff -NurpP --minimal linux-3.1/fs/reiserfs/file.c linux-3.1-vs2.3.1-rc2/fs/reiserfs/file.c
8596 --- linux-3.1/fs/reiserfs/file.c        2011-10-24 18:45:27.000000000 +0200
8597 +++ linux-3.1-vs2.3.1-rc2/fs/reiserfs/file.c    2011-10-24 18:53:33.000000000 +0200
8598 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
8599         .listxattr = reiserfs_listxattr,
8600         .removexattr = reiserfs_removexattr,
8601         .permission = reiserfs_permission,
8602 +       .sync_flags = reiserfs_sync_flags,
8603         .get_acl = reiserfs_get_acl,
8604  };
8605 diff -NurpP --minimal linux-3.1/fs/reiserfs/inode.c linux-3.1-vs2.3.1-rc2/fs/reiserfs/inode.c
8606 --- linux-3.1/fs/reiserfs/inode.c       2011-10-24 18:45:27.000000000 +0200
8607 +++ linux-3.1-vs2.3.1-rc2/fs/reiserfs/inode.c   2011-10-24 18:53:33.000000000 +0200
8608 @@ -18,6 +18,7 @@
8609  #include <linux/writeback.h>
8610  #include <linux/quotaops.h>
8611  #include <linux/swap.h>
8612 +#include <linux/vs_tag.h>
8613  
8614  int reiserfs_commit_write(struct file *f, struct page *page,
8615                           unsigned from, unsigned to);
8616 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
8617         struct buffer_head *bh;
8618         struct item_head *ih;
8619         __u32 rdev;
8620 +       uid_t uid;
8621 +       gid_t gid;
8622         //int version = ITEM_VERSION_1;
8623  
8624         bh = PATH_PLAST_BUFFER(path);
8625 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
8626                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
8627                 unsigned long blocks;
8628  
8629 +               uid = sd_v1_uid(sd);
8630 +               gid = sd_v1_gid(sd);
8631 +
8632                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
8633                 set_inode_sd_version(inode, STAT_DATA_V1);
8634                 inode->i_mode = sd_v1_mode(sd);
8635                 inode->i_nlink = sd_v1_nlink(sd);
8636 -               inode->i_uid = sd_v1_uid(sd);
8637 -               inode->i_gid = sd_v1_gid(sd);
8638                 inode->i_size = sd_v1_size(sd);
8639                 inode->i_atime.tv_sec = sd_v1_atime(sd);
8640                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
8641 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
8642                 // (directories and symlinks)
8643                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
8644  
8645 +               uid    = sd_v2_uid(sd);
8646 +               gid    = sd_v2_gid(sd);
8647 +
8648                 inode->i_mode = sd_v2_mode(sd);
8649                 inode->i_nlink = sd_v2_nlink(sd);
8650 -               inode->i_uid = sd_v2_uid(sd);
8651                 inode->i_size = sd_v2_size(sd);
8652 -               inode->i_gid = sd_v2_gid(sd);
8653                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
8654                 inode->i_atime.tv_sec = sd_v2_atime(sd);
8655                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
8656 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
8657                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
8658         }
8659  
8660 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8661 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8662 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
8663 +
8664         pathrelse(path);
8665         if (S_ISREG(inode->i_mode)) {
8666                 inode->i_op = &reiserfs_file_inode_operations;
8667 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
8668  static void inode2sd(void *sd, struct inode *inode, loff_t size)
8669  {
8670         struct stat_data *sd_v2 = (struct stat_data *)sd;
8671 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
8672 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
8673         __u16 flags;
8674  
8675 +       set_sd_v2_uid(sd_v2, uid);
8676 +       set_sd_v2_gid(sd_v2, gid);
8677         set_sd_v2_mode(sd_v2, inode->i_mode);
8678         set_sd_v2_nlink(sd_v2, inode->i_nlink);
8679 -       set_sd_v2_uid(sd_v2, inode->i_uid);
8680         set_sd_v2_size(sd_v2, size);
8681 -       set_sd_v2_gid(sd_v2, inode->i_gid);
8682         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
8683         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
8684         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
8685 @@ -2868,14 +2879,19 @@ int reiserfs_commit_write(struct file *f
8686  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
8687  {
8688         if (reiserfs_attrs(inode->i_sb)) {
8689 -               if (sd_attrs & REISERFS_SYNC_FL)
8690 -                       inode->i_flags |= S_SYNC;
8691 -               else
8692 -                       inode->i_flags &= ~S_SYNC;
8693                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
8694                         inode->i_flags |= S_IMMUTABLE;
8695                 else
8696                         inode->i_flags &= ~S_IMMUTABLE;
8697 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
8698 +                       inode->i_flags |= S_IXUNLINK;
8699 +               else
8700 +                       inode->i_flags &= ~S_IXUNLINK;
8701 +
8702 +               if (sd_attrs & REISERFS_SYNC_FL)
8703 +                       inode->i_flags |= S_SYNC;
8704 +               else
8705 +                       inode->i_flags &= ~S_SYNC;
8706                 if (sd_attrs & REISERFS_APPEND_FL)
8707                         inode->i_flags |= S_APPEND;
8708                 else
8709 @@ -2888,6 +2904,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
8710                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
8711                 else
8712                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
8713 +
8714 +               if (sd_attrs & REISERFS_BARRIER_FL)
8715 +                       inode->i_vflags |= V_BARRIER;
8716 +               else
8717 +                       inode->i_vflags &= ~V_BARRIER;
8718 +               if (sd_attrs & REISERFS_COW_FL)
8719 +                       inode->i_vflags |= V_COW;
8720 +               else
8721 +                       inode->i_vflags &= ~V_COW;
8722         }
8723  }
8724  
8725 @@ -2898,6 +2923,11 @@ void i_attrs_to_sd_attrs(struct inode *i
8726                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
8727                 else
8728                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
8729 +               if (inode->i_flags & S_IXUNLINK)
8730 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
8731 +               else
8732 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
8733 +
8734                 if (inode->i_flags & S_SYNC)
8735                         *sd_attrs |= REISERFS_SYNC_FL;
8736                 else
8737 @@ -2910,6 +2940,15 @@ void i_attrs_to_sd_attrs(struct inode *i
8738                         *sd_attrs |= REISERFS_NOTAIL_FL;
8739                 else
8740                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
8741 +
8742 +               if (inode->i_vflags & V_BARRIER)
8743 +                       *sd_attrs |= REISERFS_BARRIER_FL;
8744 +               else
8745 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
8746 +               if (inode->i_vflags & V_COW)
8747 +                       *sd_attrs |= REISERFS_COW_FL;
8748 +               else
8749 +                       *sd_attrs &= ~REISERFS_COW_FL;
8750         }
8751  }
8752  
8753 @@ -3155,7 +3194,8 @@ int reiserfs_setattr(struct dentry *dent
8754         }
8755  
8756         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
8757 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
8758 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
8759 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
8760                 struct reiserfs_transaction_handle th;
8761                 int jbegin_count =
8762                     2 *
8763 @@ -3184,6 +3224,9 @@ int reiserfs_setattr(struct dentry *dent
8764                         inode->i_uid = attr->ia_uid;
8765                 if (attr->ia_valid & ATTR_GID)
8766                         inode->i_gid = attr->ia_gid;
8767 +                               if ((attr->ia_valid & ATTR_TAG) &&
8768 +                                       IS_TAGGED(inode))
8769 +                                       inode->i_tag = attr->ia_tag;
8770                 mark_inode_dirty(inode);
8771                 error = journal_end(&th, inode->i_sb, jbegin_count);
8772                 if (error)
8773 diff -NurpP --minimal linux-3.1/fs/reiserfs/ioctl.c linux-3.1-vs2.3.1-rc2/fs/reiserfs/ioctl.c
8774 --- linux-3.1/fs/reiserfs/ioctl.c       2011-05-22 16:17:53.000000000 +0200
8775 +++ linux-3.1-vs2.3.1-rc2/fs/reiserfs/ioctl.c   2011-10-24 18:53:33.000000000 +0200
8776 @@ -11,6 +11,21 @@
8777  #include <linux/pagemap.h>
8778  #include <linux/compat.h>
8779  
8780 +
8781 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
8782 +{
8783 +       __u16 sd_attrs = 0;
8784 +
8785 +       inode->i_flags = flags;
8786 +       inode->i_vflags = vflags;
8787 +
8788 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
8789 +       REISERFS_I(inode)->i_attrs = sd_attrs;
8790 +       inode->i_ctime = CURRENT_TIME_SEC;
8791 +       mark_inode_dirty(inode);
8792 +       return 0;
8793 +}
8794 +
8795  /*
8796   * reiserfs_ioctl - handler for ioctl for inode
8797   * supported commands:
8798 @@ -22,7 +37,7 @@
8799  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
8800  {
8801         struct inode *inode = filp->f_path.dentry->d_inode;
8802 -       unsigned int flags;
8803 +       unsigned int flags, oldflags;
8804         int err = 0;
8805  
8806         reiserfs_write_lock(inode->i_sb);
8807 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
8808  
8809                 flags = REISERFS_I(inode)->i_attrs;
8810                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
8811 +               flags &= REISERFS_FL_USER_VISIBLE;
8812                 err = put_user(flags, (int __user *)arg);
8813                 break;
8814         case REISERFS_IOC_SETFLAGS:{
8815 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
8816                                 err = -EFAULT;
8817                                 goto setflags_out;
8818                         }
8819 +                       if (IS_BARRIER(inode)) {
8820 +                               vxwprintk_task(1, "messing with the barrier.");
8821 +                               return -EACCES;
8822 +                       }
8823                         /*
8824                          * Is it quota file? Do not allow user to mess with it
8825                          */
8826 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
8827                                         goto setflags_out;
8828                                 }
8829                         }
8830 +
8831 +                       oldflags = REISERFS_I(inode)->i_attrs;
8832 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
8833 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
8834                         sd_attrs_to_i_attrs(flags, inode);
8835                         REISERFS_I(inode)->i_attrs = flags;
8836                         inode->i_ctime = CURRENT_TIME_SEC;
8837 diff -NurpP --minimal linux-3.1/fs/reiserfs/namei.c linux-3.1-vs2.3.1-rc2/fs/reiserfs/namei.c
8838 --- linux-3.1/fs/reiserfs/namei.c       2011-10-24 18:45:27.000000000 +0200
8839 +++ linux-3.1-vs2.3.1-rc2/fs/reiserfs/namei.c   2011-10-24 18:53:33.000000000 +0200
8840 @@ -18,6 +18,7 @@
8841  #include <linux/reiserfs_acl.h>
8842  #include <linux/reiserfs_xattr.h>
8843  #include <linux/quotaops.h>
8844 +#include <linux/vs_tag.h>
8845  
8846  #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) i->i_nlink=1; }
8847  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
8848 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
8849         if (retval == IO_ERROR) {
8850                 return ERR_PTR(-EIO);
8851         }
8852 +               dx_propagate_tag(nd, inode);
8853  
8854         return d_splice_alias(inode, dentry);
8855  }
8856 diff -NurpP --minimal linux-3.1/fs/reiserfs/super.c linux-3.1-vs2.3.1-rc2/fs/reiserfs/super.c
8857 --- linux-3.1/fs/reiserfs/super.c       2011-10-24 18:45:27.000000000 +0200
8858 +++ linux-3.1-vs2.3.1-rc2/fs/reiserfs/super.c   2011-10-24 18:53:33.000000000 +0200
8859 @@ -899,6 +899,14 @@ static int reiserfs_parse_options(struct
8860                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
8861                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
8862  #endif
8863 +#ifndef CONFIG_TAGGING_NONE
8864 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
8865 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
8866 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
8867 +#endif
8868 +#ifdef CONFIG_PROPAGATE
8869 +               {"tag",.arg_required = 'T',.values = NULL},
8870 +#endif
8871  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
8872                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
8873                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
8874 @@ -1208,6 +1216,14 @@ static int reiserfs_remount(struct super
8875         handle_quota_files(s, qf_names, &qfmt);
8876  #endif
8877  
8878 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
8879 +               !(s->s_flags & MS_TAGGED)) {
8880 +               reiserfs_warning(s, "super-vs01",
8881 +                       "reiserfs: tagging not permitted on remount.");
8882 +               err = -EINVAL;
8883 +               goto out_err;
8884 +       }
8885 +
8886         handle_attrs(s);
8887  
8888         /* Add options that are safe here */
8889 @@ -1691,6 +1707,10 @@ static int reiserfs_fill_super(struct su
8890                 goto error;
8891         }
8892  
8893 +       /* map mount option tagxid */
8894 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
8895 +               s->s_flags |= MS_TAGGED;
8896 +
8897         rs = SB_DISK_SUPER_BLOCK(s);
8898         /* Let's do basic sanity check to verify that underlying device is not
8899            smaller than the filesystem. If the check fails then abort and scream,
8900 diff -NurpP --minimal linux-3.1/fs/reiserfs/xattr.c linux-3.1-vs2.3.1-rc2/fs/reiserfs/xattr.c
8901 --- linux-3.1/fs/reiserfs/xattr.c       2011-10-24 18:45:27.000000000 +0200
8902 +++ linux-3.1-vs2.3.1-rc2/fs/reiserfs/xattr.c   2011-10-24 18:53:33.000000000 +0200
8903 @@ -40,6 +40,7 @@
8904  #include <linux/errno.h>
8905  #include <linux/gfp.h>
8906  #include <linux/fs.h>
8907 +#include <linux/mount.h>
8908  #include <linux/file.h>
8909  #include <linux/pagemap.h>
8910  #include <linux/xattr.h>
8911 diff -NurpP --minimal linux-3.1/fs/stat.c linux-3.1-vs2.3.1-rc2/fs/stat.c
8912 --- linux-3.1/fs/stat.c 2011-10-24 18:45:27.000000000 +0200
8913 +++ linux-3.1-vs2.3.1-rc2/fs/stat.c     2011-10-24 18:53:33.000000000 +0200
8914 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
8915         stat->nlink = inode->i_nlink;
8916         stat->uid = inode->i_uid;
8917         stat->gid = inode->i_gid;
8918 +       stat->tag = inode->i_tag;
8919         stat->rdev = inode->i_rdev;
8920         stat->size = i_size_read(inode);
8921         stat->atime = inode->i_atime;
8922 diff -NurpP --minimal linux-3.1/fs/statfs.c linux-3.1-vs2.3.1-rc2/fs/statfs.c
8923 --- linux-3.1/fs/statfs.c       2011-05-22 16:17:54.000000000 +0200
8924 +++ linux-3.1-vs2.3.1-rc2/fs/statfs.c   2011-10-24 18:53:33.000000000 +0200
8925 @@ -7,6 +7,8 @@
8926  #include <linux/statfs.h>
8927  #include <linux/security.h>
8928  #include <linux/uaccess.h>
8929 +#include <linux/vs_base.h>
8930 +#include <linux/vs_dlimit.h>
8931  
8932  static int flags_by_mnt(int mnt_flags)
8933  {
8934 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
8935         retval = dentry->d_sb->s_op->statfs(dentry, buf);
8936         if (retval == 0 && buf->f_frsize == 0)
8937                 buf->f_frsize = buf->f_bsize;
8938 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
8939 +               vx_vsi_statfs(dentry->d_sb, buf);
8940         return retval;
8941  }
8942  
8943 diff -NurpP --minimal linux-3.1/fs/super.c linux-3.1-vs2.3.1-rc2/fs/super.c
8944 --- linux-3.1/fs/super.c        2011-10-24 18:45:27.000000000 +0200
8945 +++ linux-3.1-vs2.3.1-rc2/fs/super.c    2011-10-24 18:53:33.000000000 +0200
8946 @@ -32,6 +32,9 @@
8947  #include <linux/backing-dev.h>
8948  #include <linux/rculist_bl.h>
8949  #include <linux/cleancache.h>
8950 +#include <linux/devpts_fs.h>
8951 +#include <linux/proc_fs.h>
8952 +#include <linux/vs_context.h>
8953  #include "internal.h"
8954  
8955  
8956 @@ -1095,6 +1098,13 @@ mount_fs(struct file_system_type *type, 
8957         WARN_ON(sb->s_bdi == &default_backing_dev_info);
8958         sb->s_flags |= MS_BORN;
8959  
8960 +       error = -EPERM;
8961 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
8962 +               !sb->s_bdev &&
8963 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
8964 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
8965 +               goto out_sb;
8966 +
8967         error = security_sb_kern_mount(sb, flags, secdata);
8968         if (error)
8969                 goto out_sb;
8970 diff -NurpP --minimal linux-3.1/fs/sysfs/mount.c linux-3.1-vs2.3.1-rc2/fs/sysfs/mount.c
8971 --- linux-3.1/fs/sysfs/mount.c  2011-07-22 11:18:06.000000000 +0200
8972 +++ linux-3.1-vs2.3.1-rc2/fs/sysfs/mount.c      2011-10-24 18:53:33.000000000 +0200
8973 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
8974  
8975         sb->s_blocksize = PAGE_CACHE_SIZE;
8976         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
8977 -       sb->s_magic = SYSFS_MAGIC;
8978 +       sb->s_magic = SYSFS_SUPER_MAGIC;
8979         sb->s_op = &sysfs_ops;
8980         sb->s_time_gran = 1;
8981  
8982 diff -NurpP --minimal linux-3.1/fs/utimes.c linux-3.1-vs2.3.1-rc2/fs/utimes.c
8983 --- linux-3.1/fs/utimes.c       2011-05-22 16:17:54.000000000 +0200
8984 +++ linux-3.1-vs2.3.1-rc2/fs/utimes.c   2011-10-24 18:53:33.000000000 +0200
8985 @@ -8,6 +8,8 @@
8986  #include <linux/stat.h>
8987  #include <linux/utime.h>
8988  #include <linux/syscalls.h>
8989 +#include <linux/mount.h>
8990 +#include <linux/vs_cowbl.h>
8991  #include <asm/uaccess.h>
8992  #include <asm/unistd.h>
8993  
8994 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
8995  {
8996         int error;
8997         struct iattr newattrs;
8998 -       struct inode *inode = path->dentry->d_inode;
8999 +       struct inode *inode;
9000  
9001         error = mnt_want_write(path->mnt);
9002         if (error)
9003                 goto out;
9004  
9005 +       error = cow_check_and_break(path);
9006 +       if (error)
9007 +               goto mnt_drop_write_and_out;
9008 +
9009 +       inode = path->dentry->d_inode;
9010 +
9011         if (times && times[0].tv_nsec == UTIME_NOW &&
9012                      times[1].tv_nsec == UTIME_NOW)
9013                 times = NULL;
9014 diff -NurpP --minimal linux-3.1/fs/xattr.c linux-3.1-vs2.3.1-rc2/fs/xattr.c
9015 --- linux-3.1/fs/xattr.c        2011-07-22 11:18:09.000000000 +0200
9016 +++ linux-3.1-vs2.3.1-rc2/fs/xattr.c    2011-10-24 18:53:33.000000000 +0200
9017 @@ -18,6 +18,7 @@
9018  #include <linux/module.h>
9019  #include <linux/fsnotify.h>
9020  #include <linux/audit.h>
9021 +#include <linux/mount.h>
9022  #include <asm/uaccess.h>
9023  
9024  
9025 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
9026          * The trusted.* namespace can only be accessed by privileged users.
9027          */
9028         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
9029 -               if (!capable(CAP_SYS_ADMIN))
9030 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
9031                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
9032                 return 0;
9033         }
9034 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_dinode.h linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_dinode.h
9035 --- linux-3.1/fs/xfs/xfs_dinode.h       2011-10-24 18:45:31.000000000 +0200
9036 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_dinode.h   2011-10-24 18:53:33.000000000 +0200
9037 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
9038         __be32          di_nlink;       /* number of links to file */
9039         __be16          di_projid_lo;   /* lower part of owner's project id */
9040         __be16          di_projid_hi;   /* higher part owner's project id */
9041 -       __u8            di_pad[6];      /* unused, zeroed space */
9042 +       __u8            di_pad[2];      /* unused, zeroed space */
9043 +       __be16          di_tag;         /* context tagging */
9044 +       __be16          di_vflags;      /* vserver specific flags */
9045         __be16          di_flushiter;   /* incremented on flush */
9046         xfs_timestamp_t di_atime;       /* time last accessed */
9047         xfs_timestamp_t di_mtime;       /* time last modified */
9048 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
9049  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
9050  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
9051  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
9052 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
9053 +
9054  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
9055  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
9056  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
9057 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
9058  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
9059  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
9060  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
9061 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
9062  
9063  #ifdef CONFIG_XFS_RT
9064  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
9065 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
9066          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
9067          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
9068          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
9069 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
9070 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
9071 +        XFS_DIFLAG_IXUNLINK)
9072 +
9073 +#define XFS_DIVFLAG_BARRIER    0x01
9074 +#define XFS_DIVFLAG_COW                0x02
9075  
9076  #endif /* __XFS_DINODE_H__ */
9077 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_fs.h linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_fs.h
9078 --- linux-3.1/fs/xfs/xfs_fs.h   2011-10-24 18:45:31.000000000 +0200
9079 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_fs.h       2011-10-24 18:53:33.000000000 +0200
9080 @@ -67,6 +67,9 @@ struct fsxattr {
9081  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
9082  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
9083  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
9084 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
9085 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
9086 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
9087  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
9088  
9089  /*
9090 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
9091  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
9092         __u16           bs_forkoff;     /* inode fork offset in bytes   */
9093         __u16           bs_projid_hi;   /* higher part of project id    */
9094 -       unsigned char   bs_pad[10];     /* pad space, unused            */
9095 +       unsigned char   bs_pad[8];      /* pad space, unused            */
9096 +       __u16           bs_tag;         /* context tagging              */
9097         __u32           bs_dmevmask;    /* DMIG event mask              */
9098         __u16           bs_dmstate;     /* DMIG state info              */
9099         __u16           bs_aextents;    /* attribute number of extents  */
9100 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_ialloc.c linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_ialloc.c
9101 --- linux-3.1/fs/xfs/xfs_ialloc.c       2011-10-24 18:45:31.000000000 +0200
9102 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_ialloc.c   2011-10-24 18:53:33.000000000 +0200
9103 @@ -37,7 +37,6 @@
9104  #include "xfs_error.h"
9105  #include "xfs_bmap.h"
9106  
9107 -
9108  /*
9109   * Allocation group level functions.
9110   */
9111 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_inode.c linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_inode.c
9112 --- linux-3.1/fs/xfs/xfs_inode.c        2011-10-24 18:45:31.000000000 +0200
9113 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_inode.c    2011-10-24 18:53:33.000000000 +0200
9114 @@ -242,6 +242,7 @@ xfs_inotobp(
9115         return 0;
9116  }
9117  
9118 +#include <linux/vs_tag.h>
9119  
9120  /*
9121   * This routine is called to map an inode to the buffer containing
9122 @@ -640,15 +641,25 @@ xfs_iformat_btree(
9123  STATIC void
9124  xfs_dinode_from_disk(
9125         xfs_icdinode_t          *to,
9126 -       xfs_dinode_t            *from)
9127 +       xfs_dinode_t            *from,
9128 +       int tagged)
9129  {
9130 +       uint32_t uid, gid, tag;
9131 +
9132         to->di_magic = be16_to_cpu(from->di_magic);
9133         to->di_mode = be16_to_cpu(from->di_mode);
9134         to->di_version = from ->di_version;
9135         to->di_format = from->di_format;
9136         to->di_onlink = be16_to_cpu(from->di_onlink);
9137 -       to->di_uid = be32_to_cpu(from->di_uid);
9138 -       to->di_gid = be32_to_cpu(from->di_gid);
9139 +
9140 +       uid = be32_to_cpu(from->di_uid);
9141 +       gid = be32_to_cpu(from->di_gid);
9142 +       tag = be16_to_cpu(from->di_tag);
9143 +
9144 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
9145 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
9146 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
9147 +
9148         to->di_nlink = be32_to_cpu(from->di_nlink);
9149         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
9150         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
9151 @@ -670,21 +681,26 @@ xfs_dinode_from_disk(
9152         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
9153         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
9154         to->di_flags    = be16_to_cpu(from->di_flags);
9155 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
9156         to->di_gen      = be32_to_cpu(from->di_gen);
9157  }
9158  
9159  void
9160  xfs_dinode_to_disk(
9161         xfs_dinode_t            *to,
9162 -       xfs_icdinode_t          *from)
9163 +       xfs_icdinode_t          *from,
9164 +       int tagged)
9165  {
9166         to->di_magic = cpu_to_be16(from->di_magic);
9167         to->di_mode = cpu_to_be16(from->di_mode);
9168         to->di_version = from ->di_version;
9169         to->di_format = from->di_format;
9170         to->di_onlink = cpu_to_be16(from->di_onlink);
9171 -       to->di_uid = cpu_to_be32(from->di_uid);
9172 -       to->di_gid = cpu_to_be32(from->di_gid);
9173 +
9174 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
9175 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
9176 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
9177 +
9178         to->di_nlink = cpu_to_be32(from->di_nlink);
9179         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
9180         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
9181 @@ -706,12 +722,14 @@ xfs_dinode_to_disk(
9182         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
9183         to->di_dmstate = cpu_to_be16(from->di_dmstate);
9184         to->di_flags = cpu_to_be16(from->di_flags);
9185 +       to->di_vflags = cpu_to_be16(from->di_vflags);
9186         to->di_gen = cpu_to_be32(from->di_gen);
9187  }
9188  
9189  STATIC uint
9190  _xfs_dic2xflags(
9191 -       __uint16_t              di_flags)
9192 +       __uint16_t              di_flags,
9193 +       __uint16_t              di_vflags)
9194  {
9195         uint                    flags = 0;
9196  
9197 @@ -722,6 +740,8 @@ _xfs_dic2xflags(
9198                         flags |= XFS_XFLAG_PREALLOC;
9199                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
9200                         flags |= XFS_XFLAG_IMMUTABLE;
9201 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
9202 +                       flags |= XFS_XFLAG_IXUNLINK;
9203                 if (di_flags & XFS_DIFLAG_APPEND)
9204                         flags |= XFS_XFLAG_APPEND;
9205                 if (di_flags & XFS_DIFLAG_SYNC)
9206 @@ -746,6 +766,10 @@ _xfs_dic2xflags(
9207                         flags |= XFS_XFLAG_FILESTREAM;
9208         }
9209  
9210 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
9211 +               flags |= FS_BARRIER_FL;
9212 +       if (di_vflags & XFS_DIVFLAG_COW)
9213 +               flags |= FS_COW_FL;
9214         return flags;
9215  }
9216  
9217 @@ -755,7 +779,7 @@ xfs_ip2xflags(
9218  {
9219         xfs_icdinode_t          *dic = &ip->i_d;
9220  
9221 -       return _xfs_dic2xflags(dic->di_flags) |
9222 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
9223                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
9224  }
9225  
9226 @@ -763,7 +787,8 @@ uint
9227  xfs_dic2xflags(
9228         xfs_dinode_t            *dip)
9229  {
9230 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
9231 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
9232 +                               be16_to_cpu(dip->di_vflags)) |
9233                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
9234  }
9235  
9236 @@ -796,7 +821,6 @@ xfs_iread(
9237         if (error)
9238                 return error;
9239         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
9240 -
9241         /*
9242          * If we got something that isn't an inode it means someone
9243          * (nfs or dmi) has a stale handle.
9244 @@ -819,7 +843,8 @@ xfs_iread(
9245          * Otherwise, just get the truly permanent information.
9246          */
9247         if (dip->di_mode) {
9248 -               xfs_dinode_from_disk(&ip->i_d, dip);
9249 +               xfs_dinode_from_disk(&ip->i_d, dip,
9250 +                       mp->m_flags & XFS_MOUNT_TAGGED);
9251                 error = xfs_iformat(ip, dip);
9252                 if (error)  {
9253  #ifdef DEBUG
9254 @@ -1014,6 +1039,7 @@ xfs_ialloc(
9255         ASSERT(ip->i_d.di_nlink == nlink);
9256         ip->i_d.di_uid = current_fsuid();
9257         ip->i_d.di_gid = current_fsgid();
9258 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
9259         xfs_set_projid(ip, prid);
9260         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
9261  
9262 @@ -1074,6 +1100,7 @@ xfs_ialloc(
9263         ip->i_d.di_dmevmask = 0;
9264         ip->i_d.di_dmstate = 0;
9265         ip->i_d.di_flags = 0;
9266 +       ip->i_d.di_vflags = 0;
9267         flags = XFS_ILOG_CORE;
9268         switch (mode & S_IFMT) {
9269         case S_IFIFO:
9270 @@ -1845,6 +1872,7 @@ xfs_ifree(
9271         }
9272         ip->i_d.di_mode = 0;            /* mark incore inode as free */
9273         ip->i_d.di_flags = 0;
9274 +       ip->i_d.di_vflags = 0;
9275         ip->i_d.di_dmevmask = 0;
9276         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
9277         ip->i_df.if_ext_max =
9278 @@ -2724,7 +2752,8 @@ xfs_iflush_int(
9279          * because if the inode is dirty at all the core must
9280          * be.
9281          */
9282 -       xfs_dinode_to_disk(dip, &ip->i_d);
9283 +       xfs_dinode_to_disk(dip, &ip->i_d,
9284 +               mp->m_flags & XFS_MOUNT_TAGGED);
9285  
9286         /* Wrap, we never let the log put out DI_MAX_FLUSH */
9287         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
9288 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_inode.h linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_inode.h
9289 --- linux-3.1/fs/xfs/xfs_inode.h        2011-10-24 18:45:31.000000000 +0200
9290 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_inode.h    2011-10-24 18:53:33.000000000 +0200
9291 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
9292         __uint32_t      di_nlink;       /* number of links to file */
9293         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
9294         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
9295 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
9296 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
9297 +       __uint16_t      di_tag;         /* context tagging */
9298 +       __uint16_t      di_vflags;      /* vserver specific flags */
9299         __uint16_t      di_flushiter;   /* incremented on flush */
9300         xfs_ictimestamp_t di_atime;     /* time last accessed */
9301         xfs_ictimestamp_t di_mtime;     /* time last modified */
9302 @@ -536,7 +538,7 @@ int         xfs_itobp(struct xfs_mount *, struc
9303  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
9304                           struct xfs_inode *, uint);
9305  void           xfs_dinode_to_disk(struct xfs_dinode *,
9306 -                                  struct xfs_icdinode *);
9307 +                                  struct xfs_icdinode *, int);
9308  void           xfs_idestroy_fork(struct xfs_inode *, int);
9309  void           xfs_idata_realloc(struct xfs_inode *, int, int);
9310  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
9311 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_ioctl.c linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_ioctl.c
9312 --- linux-3.1/fs/xfs/xfs_ioctl.c        2011-10-24 18:45:31.000000000 +0200
9313 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_ioctl.c    2011-10-24 18:53:33.000000000 +0200
9314 @@ -28,7 +28,7 @@
9315  #include "xfs_bmap_btree.h"
9316  #include "xfs_dinode.h"
9317  #include "xfs_inode.h"
9318 -#include "xfs_ioctl.h"
9319 +// #include "xfs_ioctl.h"
9320  #include "xfs_rtalloc.h"
9321  #include "xfs_itable.h"
9322  #include "xfs_error.h"
9323 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
9324                 xflags |= XFS_XFLAG_IMMUTABLE;
9325         else
9326                 xflags &= ~XFS_XFLAG_IMMUTABLE;
9327 +       if (flags & FS_IXUNLINK_FL)
9328 +               xflags |= XFS_XFLAG_IXUNLINK;
9329 +       else
9330 +               xflags &= ~XFS_XFLAG_IXUNLINK;
9331         if (flags & FS_APPEND_FL)
9332                 xflags |= XFS_XFLAG_APPEND;
9333         else
9334 @@ -776,6 +780,8 @@ xfs_di2lxflags(
9335  
9336         if (di_flags & XFS_DIFLAG_IMMUTABLE)
9337                 flags |= FS_IMMUTABLE_FL;
9338 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
9339 +               flags |= FS_IXUNLINK_FL;
9340         if (di_flags & XFS_DIFLAG_APPEND)
9341                 flags |= FS_APPEND_FL;
9342         if (di_flags & XFS_DIFLAG_SYNC)
9343 @@ -836,6 +842,8 @@ xfs_set_diflags(
9344         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
9345         if (xflags & XFS_XFLAG_IMMUTABLE)
9346                 di_flags |= XFS_DIFLAG_IMMUTABLE;
9347 +       if (xflags & XFS_XFLAG_IXUNLINK)
9348 +               di_flags |= XFS_DIFLAG_IXUNLINK;
9349         if (xflags & XFS_XFLAG_APPEND)
9350                 di_flags |= XFS_DIFLAG_APPEND;
9351         if (xflags & XFS_XFLAG_SYNC)
9352 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
9353                 inode->i_flags |= S_IMMUTABLE;
9354         else
9355                 inode->i_flags &= ~S_IMMUTABLE;
9356 +       if (xflags & XFS_XFLAG_IXUNLINK)
9357 +               inode->i_flags |= S_IXUNLINK;
9358 +       else
9359 +               inode->i_flags &= ~S_IXUNLINK;
9360         if (xflags & XFS_XFLAG_APPEND)
9361                 inode->i_flags |= S_APPEND;
9362         else
9363 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
9364         case XFS_IOC_FSGETXATTRA:
9365                 return xfs_ioc_fsgetxattr(ip, 1, arg);
9366         case XFS_IOC_FSSETXATTR:
9367 +               if (IS_BARRIER(inode)) {
9368 +                       vxwprintk_task(1, "messing with the barrier.");
9369 +                       return -XFS_ERROR(EACCES);
9370 +               }
9371                 return xfs_ioc_fssetxattr(ip, filp, arg);
9372         case XFS_IOC_GETXFLAGS:
9373                 return xfs_ioc_getxflags(ip, arg);
9374         case XFS_IOC_SETXFLAGS:
9375 +               if (IS_BARRIER(inode)) {
9376 +                       vxwprintk_task(1, "messing with the barrier.");
9377 +                       return -XFS_ERROR(EACCES);
9378 +               }
9379                 return xfs_ioc_setxflags(ip, filp, arg);
9380  
9381         case XFS_IOC_FSSETDM: {
9382 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_ioctl.h linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_ioctl.h
9383 --- linux-3.1/fs/xfs/xfs_ioctl.h        2011-10-24 18:45:31.000000000 +0200
9384 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_ioctl.h    2011-10-24 18:53:33.000000000 +0200
9385 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
9386         void __user             *uhandle,
9387         u32                     hlen);
9388  
9389 +extern int
9390 +xfs_sync_flags(
9391 +       struct inode            *inode,
9392 +       int                     flags,
9393 +       int                     vflags);
9394 +
9395  extern long
9396  xfs_file_ioctl(
9397         struct file             *filp,
9398 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_iops.c linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_iops.c
9399 --- linux-3.1/fs/xfs/xfs_iops.c 2011-10-24 18:45:31.000000000 +0200
9400 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_iops.c     2011-10-24 18:53:33.000000000 +0200
9401 @@ -30,6 +30,7 @@
9402  #include "xfs_bmap_btree.h"
9403  #include "xfs_dinode.h"
9404  #include "xfs_inode.h"
9405 +#include "xfs_ioctl.h"
9406  #include "xfs_bmap.h"
9407  #include "xfs_rtalloc.h"
9408  #include "xfs_error.h"
9409 @@ -49,6 +50,7 @@
9410  #include <linux/security.h>
9411  #include <linux/fiemap.h>
9412  #include <linux/slab.h>
9413 +#include <linux/vs_tag.h>
9414  
9415  /*
9416   * Bring the timestamps in the XFS inode uptodate.
9417 @@ -473,6 +475,7 @@ xfs_vn_getattr(
9418         stat->nlink = ip->i_d.di_nlink;
9419         stat->uid = ip->i_d.di_uid;
9420         stat->gid = ip->i_d.di_gid;
9421 +       stat->tag = ip->i_d.di_tag;
9422         stat->ino = ip->i_ino;
9423         stat->atime = inode->i_atime;
9424         stat->mtime = inode->i_mtime;
9425 @@ -1038,6 +1041,7 @@ static const struct inode_operations xfs
9426         .removexattr            = generic_removexattr,
9427         .listxattr              = xfs_vn_listxattr,
9428         .fiemap                 = xfs_vn_fiemap,
9429 +       .sync_flags             = xfs_sync_flags,
9430  };
9431  
9432  static const struct inode_operations xfs_dir_inode_operations = {
9433 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
9434         .getxattr               = generic_getxattr,
9435         .removexattr            = generic_removexattr,
9436         .listxattr              = xfs_vn_listxattr,
9437 +       .sync_flags             = xfs_sync_flags,
9438  };
9439  
9440  static const struct inode_operations xfs_dir_ci_inode_operations = {
9441 @@ -1112,6 +1117,10 @@ xfs_diflags_to_iflags(
9442                 inode->i_flags |= S_IMMUTABLE;
9443         else
9444                 inode->i_flags &= ~S_IMMUTABLE;
9445 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
9446 +               inode->i_flags |= S_IXUNLINK;
9447 +       else
9448 +               inode->i_flags &= ~S_IXUNLINK;
9449         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
9450                 inode->i_flags |= S_APPEND;
9451         else
9452 @@ -1124,6 +1133,15 @@ xfs_diflags_to_iflags(
9453                 inode->i_flags |= S_NOATIME;
9454         else
9455                 inode->i_flags &= ~S_NOATIME;
9456 +
9457 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
9458 +               inode->i_vflags |= V_BARRIER;
9459 +       else
9460 +               inode->i_vflags &= ~V_BARRIER;
9461 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
9462 +               inode->i_vflags |= V_COW;
9463 +       else
9464 +               inode->i_vflags &= ~V_COW;
9465  }
9466  
9467  /*
9468 @@ -1155,6 +1173,7 @@ xfs_setup_inode(
9469         inode->i_nlink  = ip->i_d.di_nlink;
9470         inode->i_uid    = ip->i_d.di_uid;
9471         inode->i_gid    = ip->i_d.di_gid;
9472 +       inode->i_tag    = ip->i_d.di_tag;
9473  
9474         switch (inode->i_mode & S_IFMT) {
9475         case S_IFBLK:
9476 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_itable.c linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_itable.c
9477 --- linux-3.1/fs/xfs/xfs_itable.c       2011-05-22 16:17:54.000000000 +0200
9478 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_itable.c   2011-10-24 18:53:33.000000000 +0200
9479 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
9480         buf->bs_mode = dic->di_mode;
9481         buf->bs_uid = dic->di_uid;
9482         buf->bs_gid = dic->di_gid;
9483 +       buf->bs_tag = dic->di_tag;
9484         buf->bs_size = dic->di_size;
9485  
9486         /*
9487 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_linux.h linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_linux.h
9488 --- linux-3.1/fs/xfs/xfs_linux.h        2011-10-24 18:45:31.000000000 +0200
9489 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_linux.h    2011-10-24 18:53:33.000000000 +0200
9490 @@ -121,6 +121,7 @@
9491  
9492  #define current_cpu()          (raw_smp_processor_id())
9493  #define current_pid()          (current->pid)
9494 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
9495  #define current_test_flags(f)  (current->flags & (f))
9496  #define current_set_flags_nested(sp, f)                \
9497                 (*(sp) = current->flags, current->flags |= (f))
9498 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_log_recover.c linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_log_recover.c
9499 --- linux-3.1/fs/xfs/xfs_log_recover.c  2011-10-24 18:45:31.000000000 +0200
9500 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_log_recover.c      2011-10-24 18:53:33.000000000 +0200
9501 @@ -2347,7 +2347,8 @@ xlog_recover_inode_pass2(
9502         }
9503  
9504         /* The core is in in-core format */
9505 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
9506 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
9507 +               mp->m_flags & XFS_MOUNT_TAGGED);
9508  
9509         /* the rest is in on-disk format */
9510         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
9511 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_mount.h linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_mount.h
9512 --- linux-3.1/fs/xfs/xfs_mount.h        2011-10-24 18:45:31.000000000 +0200
9513 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_mount.h    2011-10-24 18:53:33.000000000 +0200
9514 @@ -249,6 +249,7 @@ typedef struct xfs_mount {
9515                                                    allocator */
9516  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
9517  
9518 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
9519  
9520  /*
9521   * Default minimum read and write sizes.
9522 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_super.c linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_super.c
9523 --- linux-3.1/fs/xfs/xfs_super.c        2011-10-24 18:45:31.000000000 +0200
9524 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_super.c    2011-10-24 18:53:33.000000000 +0200
9525 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
9526  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
9527  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
9528  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
9529 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
9530 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
9531 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
9532  
9533  /*
9534   * Table driven mount option parser.
9535 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
9536   * in the future, too.
9537   */
9538  enum {
9539 +       Opt_tag, Opt_notag,
9540         Opt_barrier, Opt_nobarrier, Opt_err
9541  };
9542  
9543  static const match_table_t tokens = {
9544 +       {Opt_tag, "tagxid"},
9545 +       {Opt_tag, "tag"},
9546 +       {Opt_notag, "notag"},
9547         {Opt_barrier, "barrier"},
9548         {Opt_nobarrier, "nobarrier"},
9549         {Opt_err, NULL}
9550 @@ -374,6 +381,19 @@ xfs_parseargs(
9551                 } else if (!strcmp(this_char, "irixsgid")) {
9552                         xfs_warn(mp,
9553         "irixsgid is now a sysctl(2) variable, option is deprecated.");
9554 +#ifndef CONFIG_TAGGING_NONE
9555 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9556 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
9557 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
9558 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
9559 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
9560 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
9561 +#endif
9562 +#ifdef CONFIG_PROPAGATE
9563 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9564 +                       /* use value */
9565 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
9566 +#endif
9567                 } else {
9568                         xfs_warn(mp, "unknown mount option [%s].", this_char);
9569                         return EINVAL;
9570 @@ -1162,6 +1182,16 @@ xfs_fs_remount(
9571                 case Opt_nobarrier:
9572                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
9573                         break;
9574 +               case Opt_tag:
9575 +                       if (!(sb->s_flags & MS_TAGGED)) {
9576 +                               printk(KERN_INFO
9577 +                                       "XFS: %s: tagging not permitted on remount.\n",
9578 +                                       sb->s_id);
9579 +                               return -EINVAL;
9580 +                       }
9581 +                       break;
9582 +               case Opt_notag:
9583 +                       break;
9584                 default:
9585                         /*
9586                          * Logically we would return an error here to prevent
9587 @@ -1377,6 +1407,9 @@ xfs_fs_fill_super(
9588         if (error)
9589                 goto out_free_sb;
9590  
9591 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
9592 +               sb->s_flags |= MS_TAGGED;
9593 +
9594         /*
9595          * we must configure the block size in the superblock before we run the
9596          * full mount process as the mount process can lookup and cache inodes.
9597 diff -NurpP --minimal linux-3.1/fs/xfs/xfs_vnodeops.c linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_vnodeops.c
9598 --- linux-3.1/fs/xfs/xfs_vnodeops.c     2011-10-24 18:45:31.000000000 +0200
9599 +++ linux-3.1-vs2.3.1-rc2/fs/xfs/xfs_vnodeops.c 2011-10-24 18:53:33.000000000 +0200
9600 @@ -107,6 +107,78 @@ xfs_readlink_bmap(
9601         return error;
9602  }
9603  
9604 +
9605 +STATIC void
9606 +xfs_get_inode_flags(
9607 +       xfs_inode_t     *ip)
9608 +{
9609 +       struct inode    *inode = VFS_I(ip);
9610 +       unsigned int    flags = inode->i_flags;
9611 +       unsigned int    vflags = inode->i_vflags;
9612 +
9613 +       if (flags & S_IMMUTABLE)
9614 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
9615 +       else
9616 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
9617 +       if (flags & S_IXUNLINK)
9618 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
9619 +       else
9620 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
9621 +
9622 +       if (vflags & V_BARRIER)
9623 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
9624 +       else
9625 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
9626 +       if (vflags & V_COW)
9627 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
9628 +       else
9629 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
9630 +}
9631 +
9632 +int
9633 +xfs_sync_flags(
9634 +       struct inode            *inode,
9635 +       int                     flags,
9636 +       int                     vflags)
9637 +{
9638 +       struct xfs_inode        *ip = XFS_I(inode);
9639 +       struct xfs_mount        *mp = ip->i_mount;
9640 +       struct xfs_trans        *tp;
9641 +       unsigned int            lock_flags = 0;
9642 +       int                     code;
9643 +
9644 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
9645 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
9646 +       if (code)
9647 +               goto error_out;
9648 +
9649 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
9650 +
9651 +       xfs_trans_ijoin(tp, ip);
9652 +
9653 +       inode->i_flags = flags;
9654 +       inode->i_vflags = vflags;
9655 +       xfs_get_inode_flags(ip);
9656 +
9657 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
9658 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
9659 +
9660 +       XFS_STATS_INC(xs_ig_attrchg);
9661 +
9662 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
9663 +               xfs_trans_set_sync(tp);
9664 +       code = xfs_trans_commit(tp, 0);
9665 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
9666 +       return code;
9667 +
9668 +error_out:
9669 +       xfs_trans_cancel(tp, 0);
9670 +       if (lock_flags)
9671 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
9672 +       return code;
9673 +}
9674 +
9675 +
9676  int
9677  xfs_readlink(
9678         xfs_inode_t     *ip,
9679 diff -NurpP --minimal linux-3.1/include/asm-generic/tlb.h linux-3.1-vs2.3.1-rc2/include/asm-generic/tlb.h
9680 --- linux-3.1/include/asm-generic/tlb.h 2011-07-22 11:18:10.000000000 +0200
9681 +++ linux-3.1-vs2.3.1-rc2/include/asm-generic/tlb.h     2011-10-24 18:53:33.000000000 +0200
9682 @@ -16,6 +16,7 @@
9683  #define _ASM_GENERIC__TLB_H
9684  
9685  #include <linux/swap.h>
9686 +#include <linux/vs_memory.h>
9687  #include <asm/pgalloc.h>
9688  #include <asm/tlbflush.h>
9689  
9690 diff -NurpP --minimal linux-3.1/include/linux/Kbuild linux-3.1-vs2.3.1-rc2/include/linux/Kbuild
9691 --- linux-3.1/include/linux/Kbuild      2011-10-24 18:45:31.000000000 +0200
9692 +++ linux-3.1-vs2.3.1-rc2/include/linux/Kbuild  2011-10-24 18:53:33.000000000 +0200
9693 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
9694  header-y += netfilter_ipv4/
9695  header-y += netfilter_ipv6/
9696  header-y += usb/
9697 +header-y += vserver/
9698  header-y += wimax/
9699  
9700  objhdr-y += version.h
9701 diff -NurpP --minimal linux-3.1/include/linux/capability.h linux-3.1-vs2.3.1-rc2/include/linux/capability.h
9702 --- linux-3.1/include/linux/capability.h        2011-07-22 11:18:10.000000000 +0200
9703 +++ linux-3.1-vs2.3.1-rc2/include/linux/capability.h    2011-10-24 18:53:33.000000000 +0200
9704 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
9705     arbitrary SCSI commands */
9706  /* Allow setting encryption key on loopback filesystem */
9707  /* Allow setting zone reclaim policy */
9708 +/* Allow the selection of a security context */
9709  
9710  #define CAP_SYS_ADMIN        21
9711  
9712 @@ -362,7 +363,12 @@ struct cpu_vfs_cap_data {
9713  
9714  #define CAP_LAST_CAP         CAP_WAKE_ALARM
9715  
9716 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
9717 +/* Allow context manipulations */
9718 +/* Allow changing context info on files */
9719 +
9720 +#define CAP_CONTEXT         63
9721 +
9722 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
9723  
9724  /*
9725   * Bit location of each capability (used by user-space library and kernel)
9726 diff -NurpP --minimal linux-3.1/include/linux/cred.h linux-3.1-vs2.3.1-rc2/include/linux/cred.h
9727 --- linux-3.1/include/linux/cred.h      2011-10-24 18:45:31.000000000 +0200
9728 +++ linux-3.1-vs2.3.1-rc2/include/linux/cred.h  2011-10-24 18:53:33.000000000 +0200
9729 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
9730  extern int copy_creds(struct task_struct *, unsigned long);
9731  extern const struct cred *get_task_cred(struct task_struct *);
9732  extern struct cred *cred_alloc_blank(void);
9733 +extern struct cred *__prepare_creds(const struct cred *);
9734  extern struct cred *prepare_creds(void);
9735  extern struct cred *prepare_exec_creds(void);
9736  extern int commit_creds(struct cred *);
9737 @@ -209,6 +210,31 @@ static inline void validate_process_cred
9738  }
9739  #endif
9740  
9741 +static inline void set_cred_subscribers(struct cred *cred, int n)
9742 +{
9743 +#ifdef CONFIG_DEBUG_CREDENTIALS
9744 +       atomic_set(&cred->subscribers, n);
9745 +#endif
9746 +}
9747 +
9748 +static inline int read_cred_subscribers(const struct cred *cred)
9749 +{
9750 +#ifdef CONFIG_DEBUG_CREDENTIALS
9751 +       return atomic_read(&cred->subscribers);
9752 +#else
9753 +       return 0;
9754 +#endif
9755 +}
9756 +
9757 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
9758 +{
9759 +#ifdef CONFIG_DEBUG_CREDENTIALS
9760 +       struct cred *cred = (struct cred *) _cred;
9761 +
9762 +       atomic_add(n, &cred->subscribers);
9763 +#endif
9764 +}
9765 +
9766  /**
9767   * get_new_cred - Get a reference on a new set of credentials
9768   * @cred: The new credentials to reference
9769 diff -NurpP --minimal linux-3.1/include/linux/devpts_fs.h linux-3.1-vs2.3.1-rc2/include/linux/devpts_fs.h
9770 --- linux-3.1/include/linux/devpts_fs.h 2008-12-25 00:26:37.000000000 +0100
9771 +++ linux-3.1-vs2.3.1-rc2/include/linux/devpts_fs.h     2011-10-24 18:53:33.000000000 +0200
9772 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
9773  
9774  #endif
9775  
9776 -
9777  #endif /* _LINUX_DEVPTS_FS_H */
9778 diff -NurpP --minimal linux-3.1/include/linux/ext2_fs.h linux-3.1-vs2.3.1-rc2/include/linux/ext2_fs.h
9779 --- linux-3.1/include/linux/ext2_fs.h   2011-10-24 18:45:32.000000000 +0200
9780 +++ linux-3.1-vs2.3.1-rc2/include/linux/ext2_fs.h       2011-10-24 18:53:33.000000000 +0200
9781 @@ -190,8 +190,12 @@ struct ext2_group_desc
9782  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
9783  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
9784  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
9785 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
9786  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
9787  
9788 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
9789 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
9790 +
9791  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
9792  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
9793  
9794 @@ -275,7 +279,8 @@ struct ext2_inode {
9795                         __u16   i_pad1;
9796                         __le16  l_i_uid_high;   /* these 2 fields    */
9797                         __le16  l_i_gid_high;   /* were reserved2[0] */
9798 -                       __u32   l_i_reserved2;
9799 +                       __le16  l_i_tag;        /* Context Tag */
9800 +                       __u16   l_i_reserved2;
9801                 } linux2;
9802                 struct {
9803                         __u8    h_i_frag;       /* Fragment number */
9804 @@ -304,6 +309,7 @@ struct ext2_inode {
9805  #define i_gid_low      i_gid
9806  #define i_uid_high     osd2.linux2.l_i_uid_high
9807  #define i_gid_high     osd2.linux2.l_i_gid_high
9808 +#define i_raw_tag      osd2.linux2.l_i_tag
9809  #define i_reserved2    osd2.linux2.l_i_reserved2
9810  #endif
9811  
9812 @@ -348,6 +354,7 @@ struct ext2_inode {
9813  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
9814  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
9815  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
9816 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
9817  
9818  
9819  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
9820 diff -NurpP --minimal linux-3.1/include/linux/ext3_fs.h linux-3.1-vs2.3.1-rc2/include/linux/ext3_fs.h
9821 --- linux-3.1/include/linux/ext3_fs.h   2011-10-24 18:45:32.000000000 +0200
9822 +++ linux-3.1-vs2.3.1-rc2/include/linux/ext3_fs.h       2011-10-24 18:53:33.000000000 +0200
9823 @@ -173,10 +173,14 @@ struct ext3_group_desc
9824  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
9825  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
9826  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
9827 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
9828  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
9829  
9830 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
9831 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
9832 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
9833 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
9834 +
9835 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
9836 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
9837  
9838  /* Flags that should be inherited by new inodes from their parent. */
9839  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
9840 @@ -312,7 +316,8 @@ struct ext3_inode {
9841                         __u16   i_pad1;
9842                         __le16  l_i_uid_high;   /* these 2 fields    */
9843                         __le16  l_i_gid_high;   /* were reserved2[0] */
9844 -                       __u32   l_i_reserved2;
9845 +                       __le16  l_i_tag;        /* Context Tag */
9846 +                       __u16   l_i_reserved2;
9847                 } linux2;
9848                 struct {
9849                         __u8    h_i_frag;       /* Fragment number */
9850 @@ -343,6 +348,7 @@ struct ext3_inode {
9851  #define i_gid_low      i_gid
9852  #define i_uid_high     osd2.linux2.l_i_uid_high
9853  #define i_gid_high     osd2.linux2.l_i_gid_high
9854 +#define i_raw_tag      osd2.linux2.l_i_tag
9855  #define i_reserved2    osd2.linux2.l_i_reserved2
9856  
9857  #elif defined(__GNU__)
9858 @@ -405,6 +411,7 @@ struct ext3_inode {
9859  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
9860  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
9861                                                   * error in ordered mode */
9862 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
9863  
9864  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
9865  #ifndef _LINUX_EXT2_FS_H
9866 @@ -918,6 +925,7 @@ extern void ext3_get_inode_flags(struct 
9867  extern void ext3_set_aops(struct inode *inode);
9868  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
9869                        u64 start, u64 len);
9870 +extern int ext3_sync_flags(struct inode *, int, int);
9871  
9872  /* ioctl.c */
9873  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
9874 diff -NurpP --minimal linux-3.1/include/linux/fs.h linux-3.1-vs2.3.1-rc2/include/linux/fs.h
9875 --- linux-3.1/include/linux/fs.h        2011-10-24 18:45:32.000000000 +0200
9876 +++ linux-3.1-vs2.3.1-rc2/include/linux/fs.h    2011-10-24 18:53:33.000000000 +0200
9877 @@ -209,6 +209,9 @@ struct inodes_stat_t {
9878  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
9879  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
9880  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
9881 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
9882 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
9883 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
9884  #define MS_NOSEC       (1<<28)
9885  #define MS_BORN                (1<<29)
9886  #define MS_ACTIVE      (1<<30)
9887 @@ -240,6 +243,14 @@ struct inodes_stat_t {
9888  #define S_IMA          1024    /* Inode has an associated IMA struct */
9889  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
9890  #define S_NOSEC                4096    /* no suid or xattr security attributes */
9891 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
9892 +
9893 +/* Linux-VServer related Inode flags */
9894 +
9895 +#define V_VALID                1
9896 +#define V_XATTR                2
9897 +#define V_BARRIER      4       /* Barrier for chroot() */
9898 +#define V_COW          8       /* Copy on Write */
9899  
9900  /*
9901   * Note that nosuid etc flags are inode-specific: setting some file-system
9902 @@ -262,12 +273,15 @@ struct inodes_stat_t {
9903  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
9904                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
9905  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
9906 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9907 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
9908 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9909 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
9910 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
9911  
9912  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
9913  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
9914  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
9915 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
9916 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
9917  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
9918  
9919  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
9920 @@ -278,6 +292,16 @@ struct inodes_stat_t {
9921  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
9922  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
9923  
9924 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
9925 +
9926 +#ifdef CONFIG_VSERVER_COWBL
9927 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
9928 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
9929 +#else
9930 +#  define IS_COW(inode)                (0)
9931 +#  define IS_COW_LINK(inode)   (0)
9932 +#endif
9933 +
9934  /* the read-only stuff doesn't really belong here, but any other place is
9935     probably as bad and I don't want to create yet another include file. */
9936  
9937 @@ -363,11 +387,14 @@ struct inodes_stat_t {
9938  #define FS_EXTENT_FL                   0x00080000 /* Extents */
9939  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
9940  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
9941 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
9942  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
9943  
9944 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
9945 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
9946 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
9947 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
9948  
9949 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
9950 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
9951  
9952  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
9953  #define SYNC_FILE_RANGE_WRITE          2
9954 @@ -448,6 +475,7 @@ typedef void (dio_iodone_t)(struct kiocb
9955  #define ATTR_KILL_PRIV (1 << 14)
9956  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
9957  #define ATTR_TIMES_SET (1 << 16)
9958 +#define ATTR_TAG       (1 << 17)
9959  
9960  /*
9961   * This is the Inode Attributes structure, used for notify_change().  It
9962 @@ -463,6 +491,7 @@ struct iattr {
9963         umode_t         ia_mode;
9964         uid_t           ia_uid;
9965         gid_t           ia_gid;
9966 +       tag_t           ia_tag;
9967         loff_t          ia_size;
9968         struct timespec ia_atime;
9969         struct timespec ia_mtime;
9970 @@ -476,6 +505,9 @@ struct iattr {
9971         struct file     *ia_file;
9972  };
9973  
9974 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
9975 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
9976 +
9977  /*
9978   * Includes for diskquotas.
9979   */
9980 @@ -750,7 +782,9 @@ struct inode {
9981         unsigned short          i_opflags;
9982         uid_t                   i_uid;
9983         gid_t                   i_gid;
9984 -       unsigned int            i_flags;
9985 +       tag_t                   i_tag;
9986 +       unsigned short          i_flags;
9987 +       unsigned short          i_vflags;
9988  
9989  #ifdef CONFIG_FS_POSIX_ACL
9990         struct posix_acl        *i_acl;
9991 @@ -769,6 +803,7 @@ struct inode {
9992         unsigned long           i_ino;
9993         unsigned int            i_nlink;
9994         dev_t                   i_rdev;
9995 +       dev_t                   i_mdev;
9996         loff_t                  i_size;
9997         struct timespec         i_atime;
9998         struct timespec         i_mtime;
9999 @@ -906,12 +941,12 @@ static inline void i_size_write(struct i
10000  
10001  static inline unsigned iminor(const struct inode *inode)
10002  {
10003 -       return MINOR(inode->i_rdev);
10004 +       return MINOR(inode->i_mdev);
10005  }
10006  
10007  static inline unsigned imajor(const struct inode *inode)
10008  {
10009 -       return MAJOR(inode->i_rdev);
10010 +       return MAJOR(inode->i_mdev);
10011  }
10012  
10013  extern struct block_device *I_BDEV(struct inode *inode);
10014 @@ -973,6 +1008,7 @@ struct file {
10015         loff_t                  f_pos;
10016         struct fown_struct      f_owner;
10017         const struct cred       *f_cred;
10018 +       xid_t                   f_xid;
10019         struct file_ra_state    f_ra;
10020  
10021         u64                     f_version;
10022 @@ -1117,6 +1153,7 @@ struct file_lock {
10023         struct file *fl_file;
10024         loff_t fl_start;
10025         loff_t fl_end;
10026 +       xid_t fl_xid;
10027  
10028         struct fasync_struct *  fl_fasync; /* for lease break notifications */
10029         unsigned long fl_break_time;    /* for nonblocking lease breaks */
10030 @@ -1615,6 +1652,7 @@ struct inode_operations {
10031         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
10032         ssize_t (*listxattr) (struct dentry *, char *, size_t);
10033         int (*removexattr) (struct dentry *, const char *);
10034 +       int (*sync_flags) (struct inode *, int, int);
10035         void (*truncate_range)(struct inode *, loff_t, loff_t);
10036         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
10037                       u64 len);
10038 @@ -1633,6 +1671,7 @@ extern ssize_t vfs_readv(struct file *, 
10039                 unsigned long, loff_t *);
10040  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
10041                 unsigned long, loff_t *);
10042 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
10043  
10044  struct super_operations {
10045         struct inode *(*alloc_inode)(struct super_block *sb);
10046 @@ -2505,6 +2544,7 @@ extern int dcache_dir_open(struct inode 
10047  extern int dcache_dir_close(struct inode *, struct file *);
10048  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
10049  extern int dcache_readdir(struct file *, void *, filldir_t);
10050 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
10051  extern int simple_setattr(struct dentry *, struct iattr *);
10052  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
10053  extern int simple_statfs(struct dentry *, struct kstatfs *);
10054 diff -NurpP --minimal linux-3.1/include/linux/gfs2_ondisk.h linux-3.1-vs2.3.1-rc2/include/linux/gfs2_ondisk.h
10055 --- linux-3.1/include/linux/gfs2_ondisk.h       2010-07-07 18:31:55.000000000 +0200
10056 +++ linux-3.1-vs2.3.1-rc2/include/linux/gfs2_ondisk.h   2011-10-24 18:53:33.000000000 +0200
10057 @@ -211,6 +211,9 @@ enum {
10058         gfs2fl_NoAtime          = 7,
10059         gfs2fl_Sync             = 8,
10060         gfs2fl_System           = 9,
10061 +       gfs2fl_IXUnlink         = 16,
10062 +       gfs2fl_Barrier          = 17,
10063 +       gfs2fl_Cow              = 18,
10064         gfs2fl_TruncInProg      = 29,
10065         gfs2fl_InheritDirectio  = 30,
10066         gfs2fl_InheritJdata     = 31,
10067 @@ -227,6 +230,9 @@ enum {
10068  #define GFS2_DIF_NOATIME               0x00000080
10069  #define GFS2_DIF_SYNC                  0x00000100
10070  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
10071 +#define GFS2_DIF_IXUNLINK              0x00010000
10072 +#define GFS2_DIF_BARRIER               0x00020000
10073 +#define GFS2_DIF_COW                   0x00040000
10074  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
10075  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
10076  #define GFS2_DIF_INHERIT_JDATA         0x80000000
10077 diff -NurpP --minimal linux-3.1/include/linux/if_tun.h linux-3.1-vs2.3.1-rc2/include/linux/if_tun.h
10078 --- linux-3.1/include/linux/if_tun.h    2010-08-02 16:52:54.000000000 +0200
10079 +++ linux-3.1-vs2.3.1-rc2/include/linux/if_tun.h        2011-10-24 18:53:33.000000000 +0200
10080 @@ -53,6 +53,7 @@
10081  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
10082  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
10083  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
10084 +#define TUNSETNID     _IOW('T', 217, int)
10085  
10086  /* TUNSETIFF ifr flags */
10087  #define IFF_TUN                0x0001
10088 diff -NurpP --minimal linux-3.1/include/linux/init_task.h linux-3.1-vs2.3.1-rc2/include/linux/init_task.h
10089 --- linux-3.1/include/linux/init_task.h 2011-10-24 18:45:32.000000000 +0200
10090 +++ linux-3.1-vs2.3.1-rc2/include/linux/init_task.h     2011-10-24 18:53:33.000000000 +0200
10091 @@ -192,6 +192,10 @@ extern struct cred init_cred;
10092         INIT_FTRACE_GRAPH                                               \
10093         INIT_TRACE_RECURSION                                            \
10094         INIT_TASK_RCU_PREEMPT(tsk)                                      \
10095 +       .xid            = 0,                                            \
10096 +       .vx_info        = NULL,                                         \
10097 +       .nid            = 0,                                            \
10098 +       .nx_info        = NULL,                                         \
10099  }
10100  
10101  
10102 diff -NurpP --minimal linux-3.1/include/linux/ipc.h linux-3.1-vs2.3.1-rc2/include/linux/ipc.h
10103 --- linux-3.1/include/linux/ipc.h       2009-12-03 20:02:55.000000000 +0100
10104 +++ linux-3.1-vs2.3.1-rc2/include/linux/ipc.h   2011-10-24 18:53:33.000000000 +0200
10105 @@ -91,6 +91,7 @@ struct kern_ipc_perm
10106         key_t           key;
10107         uid_t           uid;
10108         gid_t           gid;
10109 +       xid_t           xid;
10110         uid_t           cuid;
10111         gid_t           cgid;
10112         mode_t          mode; 
10113 diff -NurpP --minimal linux-3.1/include/linux/ipc_namespace.h linux-3.1-vs2.3.1-rc2/include/linux/ipc_namespace.h
10114 --- linux-3.1/include/linux/ipc_namespace.h     2011-10-24 18:45:32.000000000 +0200
10115 +++ linux-3.1-vs2.3.1-rc2/include/linux/ipc_namespace.h 2011-10-24 18:53:33.000000000 +0200
10116 @@ -101,7 +101,8 @@ static inline int mq_init_ns(struct ipc_
10117  
10118  #if defined(CONFIG_IPC_NS)
10119  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
10120 -                                      struct task_struct *tsk);
10121 +                                      struct ipc_namespace *old_ns,
10122 +                                      struct user_namespace *user_ns);
10123  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
10124  {
10125         if (ns)
10126 @@ -112,12 +113,13 @@ static inline struct ipc_namespace *get_
10127  extern void put_ipc_ns(struct ipc_namespace *ns);
10128  #else
10129  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
10130 -                                             struct task_struct *tsk)
10131 +                                             struct ipc_namespace *old_ns,
10132 +                                             struct user_namespace *user_ns)
10133  {
10134         if (flags & CLONE_NEWIPC)
10135                 return ERR_PTR(-EINVAL);
10136  
10137 -       return tsk->nsproxy->ipc_ns;
10138 +       return old_ns;
10139  }
10140  
10141  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
10142 diff -NurpP --minimal linux-3.1/include/linux/loop.h linux-3.1-vs2.3.1-rc2/include/linux/loop.h
10143 --- linux-3.1/include/linux/loop.h      2011-10-24 18:45:32.000000000 +0200
10144 +++ linux-3.1-vs2.3.1-rc2/include/linux/loop.h  2011-10-24 18:53:33.000000000 +0200
10145 @@ -45,6 +45,7 @@ struct loop_device {
10146         struct loop_func_table *lo_encryption;
10147         __u32           lo_init[2];
10148         uid_t           lo_key_owner;   /* Who set the key */
10149 +       xid_t           lo_xid;
10150         int             (*ioctl)(struct loop_device *, int cmd, 
10151                                  unsigned long arg); 
10152  
10153 diff -NurpP --minimal linux-3.1/include/linux/magic.h linux-3.1-vs2.3.1-rc2/include/linux/magic.h
10154 --- linux-3.1/include/linux/magic.h     2011-05-22 16:17:55.000000000 +0200
10155 +++ linux-3.1-vs2.3.1-rc2/include/linux/magic.h 2011-10-24 18:53:33.000000000 +0200
10156 @@ -3,7 +3,7 @@
10157  
10158  #define ADFS_SUPER_MAGIC       0xadf5
10159  #define AFFS_SUPER_MAGIC       0xadff
10160 -#define AFS_SUPER_MAGIC                0x5346414F
10161 +#define AFS_SUPER_MAGIC                0x5346414F
10162  #define AUTOFS_SUPER_MAGIC     0x0187
10163  #define CODA_SUPER_MAGIC       0x73757245
10164  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
10165 @@ -41,6 +41,7 @@
10166  #define NFS_SUPER_MAGIC                0x6969
10167  #define OPENPROM_SUPER_MAGIC   0x9fa1
10168  #define PROC_SUPER_MAGIC       0x9fa0
10169 +#define DEVPTS_SUPER_MAGIC     0x1cd1
10170  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
10171  
10172  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
10173 diff -NurpP --minimal linux-3.1/include/linux/major.h linux-3.1-vs2.3.1-rc2/include/linux/major.h
10174 --- linux-3.1/include/linux/major.h     2009-09-10 15:26:25.000000000 +0200
10175 +++ linux-3.1-vs2.3.1-rc2/include/linux/major.h 2011-10-24 18:53:33.000000000 +0200
10176 @@ -15,6 +15,7 @@
10177  #define HD_MAJOR               IDE0_MAJOR
10178  #define PTY_SLAVE_MAJOR                3
10179  #define TTY_MAJOR              4
10180 +#define VROOT_MAJOR            4
10181  #define TTYAUX_MAJOR           5
10182  #define LP_MAJOR               6
10183  #define VCS_MAJOR              7
10184 diff -NurpP --minimal linux-3.1/include/linux/memcontrol.h linux-3.1-vs2.3.1-rc2/include/linux/memcontrol.h
10185 --- linux-3.1/include/linux/memcontrol.h        2011-10-24 18:45:32.000000000 +0200
10186 +++ linux-3.1-vs2.3.1-rc2/include/linux/memcontrol.h    2011-10-24 18:53:33.000000000 +0200
10187 @@ -84,6 +84,13 @@ extern struct mem_cgroup *try_get_mem_cg
10188  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
10189  extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
10190  
10191 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
10192 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
10193 +
10194 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
10195 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
10196 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
10197 +
10198  static inline
10199  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
10200  {
10201 diff -NurpP --minimal linux-3.1/include/linux/mm_types.h linux-3.1-vs2.3.1-rc2/include/linux/mm_types.h
10202 --- linux-3.1/include/linux/mm_types.h  2011-10-24 18:45:32.000000000 +0200
10203 +++ linux-3.1-vs2.3.1-rc2/include/linux/mm_types.h      2011-10-24 18:53:33.000000000 +0200
10204 @@ -301,6 +301,7 @@ struct mm_struct {
10205  
10206         /* Architecture-specific MM context */
10207         mm_context_t context;
10208 +       struct vx_info *mm_vx_info;
10209  
10210         /* Swap token stuff */
10211         /*
10212 diff -NurpP --minimal linux-3.1/include/linux/mmzone.h linux-3.1-vs2.3.1-rc2/include/linux/mmzone.h
10213 --- linux-3.1/include/linux/mmzone.h    2011-10-24 18:45:32.000000000 +0200
10214 +++ linux-3.1-vs2.3.1-rc2/include/linux/mmzone.h        2011-10-24 18:53:33.000000000 +0200
10215 @@ -660,6 +660,13 @@ typedef struct pglist_data {
10216         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
10217  })
10218  
10219 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
10220 +
10221 +#define node_end_pfn(nid) ({\
10222 +       pg_data_t *__pgdat = NODE_DATA(nid);\
10223 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
10224 +})
10225 +
10226  #include <linux/memory_hotplug.h>
10227  
10228  extern struct mutex zonelists_mutex;
10229 diff -NurpP --minimal linux-3.1/include/linux/mount.h linux-3.1-vs2.3.1-rc2/include/linux/mount.h
10230 --- linux-3.1/include/linux/mount.h     2011-10-24 18:45:32.000000000 +0200
10231 +++ linux-3.1-vs2.3.1-rc2/include/linux/mount.h 2011-10-24 18:53:33.000000000 +0200
10232 @@ -52,6 +52,9 @@ struct mnt_pcp {
10233         int mnt_writers;
10234  };
10235  
10236 +#define MNT_TAGID      0x10000
10237 +#define MNT_NOTAG      0x20000
10238 +
10239  struct vfsmount {
10240         struct list_head mnt_hash;
10241         struct vfsmount *mnt_parent;    /* fs we are mounted on */
10242 @@ -86,6 +89,7 @@ struct vfsmount {
10243         int mnt_expiry_mark;            /* true if marked for expiry */
10244         int mnt_pinned;
10245         int mnt_ghosts;
10246 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
10247  };
10248  
10249  struct file; /* forward dec */
10250 diff -NurpP --minimal linux-3.1/include/linux/net.h linux-3.1-vs2.3.1-rc2/include/linux/net.h
10251 --- linux-3.1/include/linux/net.h       2011-07-22 11:18:11.000000000 +0200
10252 +++ linux-3.1-vs2.3.1-rc2/include/linux/net.h   2011-10-24 18:53:33.000000000 +0200
10253 @@ -72,6 +72,7 @@ struct net;
10254  #define SOCK_NOSPACE           2
10255  #define SOCK_PASSCRED          3
10256  #define SOCK_PASSSEC           4
10257 +#define SOCK_USER_SOCKET       5
10258  
10259  #ifndef ARCH_HAS_SOCKET_TYPES
10260  /**
10261 diff -NurpP --minimal linux-3.1/include/linux/netdevice.h linux-3.1-vs2.3.1-rc2/include/linux/netdevice.h
10262 --- linux-3.1/include/linux/netdevice.h 2011-10-24 18:45:32.000000000 +0200
10263 +++ linux-3.1-vs2.3.1-rc2/include/linux/netdevice.h     2011-10-24 18:53:33.000000000 +0200
10264 @@ -1641,6 +1641,7 @@ extern void               netdev_resync_ops(struct ne
10265  
10266  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
10267  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
10268 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
10269  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
10270  extern int             dev_restart(struct net_device *dev);
10271  #ifdef CONFIG_NETPOLL_TRAP
10272 diff -NurpP --minimal linux-3.1/include/linux/nfs_mount.h linux-3.1-vs2.3.1-rc2/include/linux/nfs_mount.h
10273 --- linux-3.1/include/linux/nfs_mount.h 2011-01-05 21:50:31.000000000 +0100
10274 +++ linux-3.1-vs2.3.1-rc2/include/linux/nfs_mount.h     2011-10-24 18:53:33.000000000 +0200
10275 @@ -63,7 +63,8 @@ struct nfs_mount_data {
10276  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
10277  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
10278  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
10279 -#define NFS_MOUNT_FLAGMASK     0xFFFF
10280 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
10281 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
10282  
10283  /* The following are for internal use only */
10284  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
10285 diff -NurpP --minimal linux-3.1/include/linux/nsproxy.h linux-3.1-vs2.3.1-rc2/include/linux/nsproxy.h
10286 --- linux-3.1/include/linux/nsproxy.h   2011-10-24 18:45:32.000000000 +0200
10287 +++ linux-3.1-vs2.3.1-rc2/include/linux/nsproxy.h       2011-10-24 18:53:33.000000000 +0200
10288 @@ -3,6 +3,7 @@
10289  
10290  #include <linux/spinlock.h>
10291  #include <linux/sched.h>
10292 +#include <linux/vserver/debug.h>
10293  
10294  struct mnt_namespace;
10295  struct uts_namespace;
10296 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
10297  }
10298  
10299  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
10300 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
10301  void exit_task_namespaces(struct task_struct *tsk);
10302  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
10303  void free_nsproxy(struct nsproxy *ns);
10304 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
10305         struct fs_struct *);
10306  int __init nsproxy_cache_init(void);
10307  
10308 -static inline void put_nsproxy(struct nsproxy *ns)
10309 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
10310 +
10311 +static inline void __get_nsproxy(struct nsproxy *ns,
10312 +       const char *_file, int _line)
10313  {
10314 -       if (atomic_dec_and_test(&ns->count)) {
10315 -               free_nsproxy(ns);
10316 -       }
10317 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
10318 +               ns, atomic_read(&ns->count), _file, _line);
10319 +       atomic_inc(&ns->count);
10320  }
10321  
10322 -static inline void get_nsproxy(struct nsproxy *ns)
10323 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
10324 +
10325 +static inline void __put_nsproxy(struct nsproxy *ns,
10326 +       const char *_file, int _line)
10327  {
10328 -       atomic_inc(&ns->count);
10329 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
10330 +               ns, atomic_read(&ns->count), _file, _line);
10331 +       if (atomic_dec_and_test(&ns->count)) {
10332 +               free_nsproxy(ns);
10333 +       }
10334  }
10335  
10336  #endif
10337 diff -NurpP --minimal linux-3.1/include/linux/pid.h linux-3.1-vs2.3.1-rc2/include/linux/pid.h
10338 --- linux-3.1/include/linux/pid.h       2011-07-22 11:18:11.000000000 +0200
10339 +++ linux-3.1-vs2.3.1-rc2/include/linux/pid.h   2011-10-24 18:53:33.000000000 +0200
10340 @@ -8,7 +8,8 @@ enum pid_type
10341         PIDTYPE_PID,
10342         PIDTYPE_PGID,
10343         PIDTYPE_SID,
10344 -       PIDTYPE_MAX
10345 +       PIDTYPE_MAX,
10346 +       PIDTYPE_REALPID
10347  };
10348  
10349  /*
10350 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
10351  }
10352  
10353  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
10354 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
10355  pid_t pid_vnr(struct pid *pid);
10356  
10357  #define do_each_pid_task(pid, type, task)                              \
10358 diff -NurpP --minimal linux-3.1/include/linux/proc_fs.h linux-3.1-vs2.3.1-rc2/include/linux/proc_fs.h
10359 --- linux-3.1/include/linux/proc_fs.h   2011-10-24 18:45:32.000000000 +0200
10360 +++ linux-3.1-vs2.3.1-rc2/include/linux/proc_fs.h       2011-10-24 18:53:33.000000000 +0200
10361 @@ -54,6 +54,7 @@ struct proc_dir_entry {
10362         nlink_t nlink;
10363         uid_t uid;
10364         gid_t gid;
10365 +       int vx_flags;
10366         loff_t size;
10367         const struct inode_operations *proc_iops;
10368         /*
10369 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
10370  extern const struct proc_ns_operations utsns_operations;
10371  extern const struct proc_ns_operations ipcns_operations;
10372  
10373 +struct vx_info;
10374 +struct nx_info;
10375 +
10376  union proc_op {
10377         int (*proc_get_link)(struct inode *, struct path *);
10378         int (*proc_read)(struct task_struct *task, char *page);
10379         int (*proc_show)(struct seq_file *m,
10380                 struct pid_namespace *ns, struct pid *pid,
10381                 struct task_struct *task);
10382 +       int (*proc_vs_read)(char *page);
10383 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
10384 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
10385  };
10386  
10387  struct ctl_table_header;
10388 @@ -265,6 +272,7 @@ struct ctl_table;
10389  
10390  struct proc_inode {
10391         struct pid *pid;
10392 +       int vx_flags;
10393         int fd;
10394         union proc_op op;
10395         struct proc_dir_entry *pde;
10396 diff -NurpP --minimal linux-3.1/include/linux/quotaops.h linux-3.1-vs2.3.1-rc2/include/linux/quotaops.h
10397 --- linux-3.1/include/linux/quotaops.h  2011-05-22 16:17:57.000000000 +0200
10398 +++ linux-3.1-vs2.3.1-rc2/include/linux/quotaops.h      2011-10-24 18:53:33.000000000 +0200
10399 @@ -8,6 +8,7 @@
10400  #define _LINUX_QUOTAOPS_
10401  
10402  #include <linux/fs.h>
10403 +#include <linux/vs_dlimit.h>
10404  
10405  #define DQUOT_SPACE_WARN       0x1
10406  #define DQUOT_SPACE_RESERVE    0x2
10407 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
10408  
10409  static inline int dquot_alloc_inode(const struct inode *inode)
10410  {
10411 -       return 0;
10412 +       return dl_alloc_inode(inode);
10413  }
10414  
10415  static inline void dquot_free_inode(const struct inode *inode)
10416  {
10417 +       dl_free_inode(inode);
10418  }
10419  
10420  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
10421 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
10422  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
10423                 int flags)
10424  {
10425 +       int ret = 0;
10426 +
10427 +       if ((ret = dl_alloc_space(inode, number)))
10428 +               return ret;
10429         if (!(flags & DQUOT_SPACE_RESERVE))
10430                 inode_add_bytes(inode, number);
10431         return 0;
10432 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
10433  {
10434         if (!(flags & DQUOT_SPACE_RESERVE))
10435                 inode_sub_bytes(inode, number);
10436 +       dl_free_space(inode, number);
10437  }
10438  
10439  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
10440 diff -NurpP --minimal linux-3.1/include/linux/reboot.h linux-3.1-vs2.3.1-rc2/include/linux/reboot.h
10441 --- linux-3.1/include/linux/reboot.h    2011-10-24 18:45:32.000000000 +0200
10442 +++ linux-3.1-vs2.3.1-rc2/include/linux/reboot.h        2011-10-24 18:53:33.000000000 +0200
10443 @@ -33,6 +33,7 @@
10444  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
10445  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
10446  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
10447 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
10448  
10449  
10450  #ifdef __KERNEL__
10451 diff -NurpP --minimal linux-3.1/include/linux/reiserfs_fs.h linux-3.1-vs2.3.1-rc2/include/linux/reiserfs_fs.h
10452 --- linux-3.1/include/linux/reiserfs_fs.h       2011-10-24 18:45:32.000000000 +0200
10453 +++ linux-3.1-vs2.3.1-rc2/include/linux/reiserfs_fs.h   2011-10-24 18:53:33.000000000 +0200
10454 @@ -976,6 +976,11 @@ struct stat_data_v1 {
10455  #define REISERFS_COMPR_FL     FS_COMPR_FL
10456  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
10457  
10458 +/* unfortunately reiserfs sdattr is only 16 bit */
10459 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
10460 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
10461 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
10462 +
10463  /* persistent flags that file inherits from the parent directory */
10464  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
10465                                 REISERFS_SYNC_FL |      \
10466 @@ -985,6 +990,9 @@ struct stat_data_v1 {
10467                                 REISERFS_COMPR_FL |     \
10468                                 REISERFS_NOTAIL_FL )
10469  
10470 +#define REISERFS_FL_USER_VISIBLE       0x80FF
10471 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
10472 +
10473  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
10474     address blocks) */
10475  struct stat_data {
10476 @@ -2073,6 +2081,7 @@ static inline void reiserfs_update_sd(st
10477  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
10478  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
10479  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
10480 +int reiserfs_sync_flags(struct inode *inode, int, int);
10481  
10482  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
10483  
10484 diff -NurpP --minimal linux-3.1/include/linux/reiserfs_fs_sb.h linux-3.1-vs2.3.1-rc2/include/linux/reiserfs_fs_sb.h
10485 --- linux-3.1/include/linux/reiserfs_fs_sb.h    2010-02-25 11:52:07.000000000 +0100
10486 +++ linux-3.1-vs2.3.1-rc2/include/linux/reiserfs_fs_sb.h        2011-10-24 18:53:33.000000000 +0200
10487 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
10488         REISERFS_EXPOSE_PRIVROOT,
10489         REISERFS_BARRIER_NONE,
10490         REISERFS_BARRIER_FLUSH,
10491 +       REISERFS_TAGGED,
10492  
10493         /* Actions on error */
10494         REISERFS_ERROR_PANIC,
10495 diff -NurpP --minimal linux-3.1/include/linux/sched.h linux-3.1-vs2.3.1-rc2/include/linux/sched.h
10496 --- linux-3.1/include/linux/sched.h     2011-10-24 18:45:32.000000000 +0200
10497 +++ linux-3.1-vs2.3.1-rc2/include/linux/sched.h 2011-10-24 18:53:33.000000000 +0200
10498 @@ -1406,6 +1406,14 @@ struct task_struct {
10499  #endif
10500         seccomp_t seccomp;
10501  
10502 +/* vserver context data */
10503 +       struct vx_info *vx_info;
10504 +       struct nx_info *nx_info;
10505 +
10506 +       xid_t xid;
10507 +       nid_t nid;
10508 +       tag_t tag;
10509 +
10510  /* Thread group tracking */
10511         u32 parent_exec_id;
10512         u32 self_exec_id;
10513 @@ -1648,6 +1656,11 @@ struct pid_namespace;
10514  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
10515                         struct pid_namespace *ns);
10516  
10517 +#include <linux/vserver/base.h>
10518 +#include <linux/vserver/context.h>
10519 +#include <linux/vserver/debug.h>
10520 +#include <linux/vserver/pid.h>
10521 +
10522  static inline pid_t task_pid_nr(struct task_struct *tsk)
10523  {
10524         return tsk->pid;
10525 @@ -1661,7 +1674,8 @@ static inline pid_t task_pid_nr_ns(struc
10526  
10527  static inline pid_t task_pid_vnr(struct task_struct *tsk)
10528  {
10529 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
10530 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
10531 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
10532  }
10533  
10534  
10535 @@ -1674,7 +1688,7 @@ pid_t task_tgid_nr_ns(struct task_struct
10536  
10537  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
10538  {
10539 -       return pid_vnr(task_tgid(tsk));
10540 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
10541  }
10542  
10543  
10544 diff -NurpP --minimal linux-3.1/include/linux/shmem_fs.h linux-3.1-vs2.3.1-rc2/include/linux/shmem_fs.h
10545 --- linux-3.1/include/linux/shmem_fs.h  2011-10-24 18:45:32.000000000 +0200
10546 +++ linux-3.1-vs2.3.1-rc2/include/linux/shmem_fs.h      2011-10-24 18:53:33.000000000 +0200
10547 @@ -8,6 +8,9 @@
10548  
10549  /* inode in-kernel data */
10550  
10551 +#define TMPFS_SUPER_MAGIC      0x01021994
10552 +
10553 +
10554  struct shmem_inode_info {
10555         spinlock_t              lock;
10556         unsigned long           flags;
10557 diff -NurpP --minimal linux-3.1/include/linux/stat.h linux-3.1-vs2.3.1-rc2/include/linux/stat.h
10558 --- linux-3.1/include/linux/stat.h      2008-12-25 00:26:37.000000000 +0100
10559 +++ linux-3.1-vs2.3.1-rc2/include/linux/stat.h  2011-10-24 18:53:33.000000000 +0200
10560 @@ -66,6 +66,7 @@ struct kstat {
10561         unsigned int    nlink;
10562         uid_t           uid;
10563         gid_t           gid;
10564 +       tag_t           tag;
10565         dev_t           rdev;
10566         loff_t          size;
10567         struct timespec  atime;
10568 diff -NurpP --minimal linux-3.1/include/linux/sunrpc/auth.h linux-3.1-vs2.3.1-rc2/include/linux/sunrpc/auth.h
10569 --- linux-3.1/include/linux/sunrpc/auth.h       2011-10-24 18:45:32.000000000 +0200
10570 +++ linux-3.1-vs2.3.1-rc2/include/linux/sunrpc/auth.h   2011-10-24 18:53:33.000000000 +0200
10571 @@ -25,6 +25,7 @@
10572  struct auth_cred {
10573         uid_t   uid;
10574         gid_t   gid;
10575 +       tag_t   tag;
10576         struct group_info *group_info;
10577         unsigned char machine_cred : 1;
10578  };
10579 diff -NurpP --minimal linux-3.1/include/linux/sunrpc/clnt.h linux-3.1-vs2.3.1-rc2/include/linux/sunrpc/clnt.h
10580 --- linux-3.1/include/linux/sunrpc/clnt.h       2011-05-22 16:17:58.000000000 +0200
10581 +++ linux-3.1-vs2.3.1-rc2/include/linux/sunrpc/clnt.h   2011-10-24 18:53:33.000000000 +0200
10582 @@ -49,7 +49,8 @@ struct rpc_clnt {
10583         unsigned int            cl_softrtry : 1,/* soft timeouts */
10584                                 cl_discrtry : 1,/* disconnect before retry */
10585                                 cl_autobind : 1,/* use getport() */
10586 -                               cl_chatty   : 1;/* be verbose */
10587 +                               cl_chatty   : 1,/* be verbose */
10588 +                               cl_tag      : 1;/* context tagging */
10589  
10590         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
10591         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
10592 diff -NurpP --minimal linux-3.1/include/linux/syscalls.h linux-3.1-vs2.3.1-rc2/include/linux/syscalls.h
10593 --- linux-3.1/include/linux/syscalls.h  2011-10-24 18:45:32.000000000 +0200
10594 +++ linux-3.1-vs2.3.1-rc2/include/linux/syscalls.h      2011-10-24 18:53:33.000000000 +0200
10595 @@ -483,6 +483,8 @@ asmlinkage long sys_symlink(const char _
10596  asmlinkage long sys_unlink(const char __user *pathname);
10597  asmlinkage long sys_rename(const char __user *oldname,
10598                                 const char __user *newname);
10599 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
10600 +                               umode_t mode);
10601  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
10602  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
10603  
10604 diff -NurpP --minimal linux-3.1/include/linux/sysctl.h linux-3.1-vs2.3.1-rc2/include/linux/sysctl.h
10605 --- linux-3.1/include/linux/sysctl.h    2011-03-15 18:07:40.000000000 +0100
10606 +++ linux-3.1-vs2.3.1-rc2/include/linux/sysctl.h        2011-10-24 18:53:33.000000000 +0200
10607 @@ -60,6 +60,7 @@ enum
10608         CTL_ABI=9,              /* Binary emulation */
10609         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
10610         CTL_ARLAN=254,          /* arlan wireless driver */
10611 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
10612         CTL_S390DBF=5677,       /* s390 debug */
10613         CTL_SUNRPC=7249,        /* sunrpc debug */
10614         CTL_PM=9899,            /* frv power management */
10615 @@ -94,6 +95,7 @@ enum
10616  
10617         KERN_PANIC=15,          /* int: panic timeout */
10618         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
10619 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
10620  
10621         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
10622         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
10623 diff -NurpP --minimal linux-3.1/include/linux/sysfs.h linux-3.1-vs2.3.1-rc2/include/linux/sysfs.h
10624 --- linux-3.1/include/linux/sysfs.h     2011-10-24 18:45:32.000000000 +0200
10625 +++ linux-3.1-vs2.3.1-rc2/include/linux/sysfs.h 2011-10-24 18:53:33.000000000 +0200
10626 @@ -19,6 +19,8 @@
10627  #include <linux/kobject_ns.h>
10628  #include <linux/atomic.h>
10629  
10630 +#define SYSFS_SUPER_MAGIC      0x62656572
10631 +
10632  struct kobject;
10633  struct module;
10634  enum kobj_ns_type;
10635 diff -NurpP --minimal linux-3.1/include/linux/time.h linux-3.1-vs2.3.1-rc2/include/linux/time.h
10636 --- linux-3.1/include/linux/time.h      2011-07-22 11:18:11.000000000 +0200
10637 +++ linux-3.1-vs2.3.1-rc2/include/linux/time.h  2011-10-24 18:53:33.000000000 +0200
10638 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
10639         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
10640         a->tv_nsec = ns;
10641  }
10642 +
10643 +#include <linux/vs_time.h>
10644 +
10645  #endif /* __KERNEL__ */
10646  
10647  #define NFDBITS                        __NFDBITS
10648 diff -NurpP --minimal linux-3.1/include/linux/types.h linux-3.1-vs2.3.1-rc2/include/linux/types.h
10649 --- linux-3.1/include/linux/types.h     2011-05-22 16:17:58.000000000 +0200
10650 +++ linux-3.1-vs2.3.1-rc2/include/linux/types.h 2011-10-24 18:53:33.000000000 +0200
10651 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
10652  typedef __kernel_gid32_t       gid_t;
10653  typedef __kernel_uid16_t        uid16_t;
10654  typedef __kernel_gid16_t        gid16_t;
10655 +typedef unsigned int           xid_t;
10656 +typedef unsigned int           nid_t;
10657 +typedef unsigned int           tag_t;
10658  
10659  typedef unsigned long          uintptr_t;
10660  
10661 diff -NurpP --minimal linux-3.1/include/linux/utsname.h linux-3.1-vs2.3.1-rc2/include/linux/utsname.h
10662 --- linux-3.1/include/linux/utsname.h   2011-05-22 16:17:58.000000000 +0200
10663 +++ linux-3.1-vs2.3.1-rc2/include/linux/utsname.h       2011-10-24 18:53:33.000000000 +0200
10664 @@ -54,7 +54,8 @@ static inline void get_uts_ns(struct uts
10665  }
10666  
10667  extern struct uts_namespace *copy_utsname(unsigned long flags,
10668 -                                         struct task_struct *tsk);
10669 +                                         struct uts_namespace *old_ns,
10670 +                                         struct user_namespace *user_ns);
10671  extern void free_uts_ns(struct kref *kref);
10672  
10673  static inline void put_uts_ns(struct uts_namespace *ns)
10674 @@ -71,12 +72,13 @@ static inline void put_uts_ns(struct uts
10675  }
10676  
10677  static inline struct uts_namespace *copy_utsname(unsigned long flags,
10678 -                                                struct task_struct *tsk)
10679 +                                                struct uts_namespace *old_ns,
10680 +                                                struct user_namespace *user_ns)
10681  {
10682         if (flags & CLONE_NEWUTS)
10683                 return ERR_PTR(-EINVAL);
10684  
10685 -       return tsk->nsproxy->uts_ns;
10686 +       return old_ns;
10687  }
10688  #endif
10689  
10690 diff -NurpP --minimal linux-3.1/include/linux/vroot.h linux-3.1-vs2.3.1-rc2/include/linux/vroot.h
10691 --- linux-3.1/include/linux/vroot.h     1970-01-01 01:00:00.000000000 +0100
10692 +++ linux-3.1-vs2.3.1-rc2/include/linux/vroot.h 2011-10-24 18:53:33.000000000 +0200
10693 @@ -0,0 +1,51 @@
10694 +
10695 +/*
10696 + * include/linux/vroot.h
10697 + *
10698 + * written by Herbert Pötzl, 9/11/2002
10699 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
10700 + *
10701 + * Copyright (C) 2002-2007 by Herbert Pötzl.
10702 + * Redistribution of this file is permitted under the
10703 + * GNU General Public License.
10704 + */
10705 +
10706 +#ifndef _LINUX_VROOT_H
10707 +#define _LINUX_VROOT_H
10708 +
10709 +
10710 +#ifdef __KERNEL__
10711 +
10712 +/* Possible states of device */
10713 +enum {
10714 +       Vr_unbound,
10715 +       Vr_bound,
10716 +};
10717 +
10718 +struct vroot_device {
10719 +       int             vr_number;
10720 +       int             vr_refcnt;
10721 +
10722 +       struct semaphore        vr_ctl_mutex;
10723 +       struct block_device    *vr_device;
10724 +       int                     vr_state;
10725 +};
10726 +
10727 +
10728 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
10729 +
10730 +extern int register_vroot_grb(vroot_grb_func *);
10731 +extern int unregister_vroot_grb(vroot_grb_func *);
10732 +
10733 +#endif /* __KERNEL__ */
10734 +
10735 +#define MAX_VROOT_DEFAULT      8
10736 +
10737 +/*
10738 + * IOCTL commands --- we will commandeer 0x56 ('V')
10739 + */
10740 +
10741 +#define VROOT_SET_DEV          0x5600
10742 +#define VROOT_CLR_DEV          0x5601
10743 +
10744 +#endif /* _LINUX_VROOT_H */
10745 diff -NurpP --minimal linux-3.1/include/linux/vs_base.h linux-3.1-vs2.3.1-rc2/include/linux/vs_base.h
10746 --- linux-3.1/include/linux/vs_base.h   1970-01-01 01:00:00.000000000 +0100
10747 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_base.h       2011-10-24 18:53:33.000000000 +0200
10748 @@ -0,0 +1,10 @@
10749 +#ifndef _VS_BASE_H
10750 +#define _VS_BASE_H
10751 +
10752 +#include "vserver/base.h"
10753 +#include "vserver/check.h"
10754 +#include "vserver/debug.h"
10755 +
10756 +#else
10757 +#warning duplicate inclusion
10758 +#endif
10759 diff -NurpP --minimal linux-3.1/include/linux/vs_context.h linux-3.1-vs2.3.1-rc2/include/linux/vs_context.h
10760 --- linux-3.1/include/linux/vs_context.h        1970-01-01 01:00:00.000000000 +0100
10761 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_context.h    2011-10-24 18:53:33.000000000 +0200
10762 @@ -0,0 +1,242 @@
10763 +#ifndef _VS_CONTEXT_H
10764 +#define _VS_CONTEXT_H
10765 +
10766 +#include "vserver/base.h"
10767 +#include "vserver/check.h"
10768 +#include "vserver/context.h"
10769 +#include "vserver/history.h"
10770 +#include "vserver/debug.h"
10771 +
10772 +#include <linux/sched.h>
10773 +
10774 +
10775 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
10776 +
10777 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
10778 +       const char *_file, int _line, void *_here)
10779 +{
10780 +       if (!vxi)
10781 +               return NULL;
10782 +
10783 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
10784 +               vxi, vxi ? vxi->vx_id : 0,
10785 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10786 +               _file, _line);
10787 +       __vxh_get_vx_info(vxi, _here);
10788 +
10789 +       atomic_inc(&vxi->vx_usecnt);
10790 +       return vxi;
10791 +}
10792 +
10793 +
10794 +extern void free_vx_info(struct vx_info *);
10795 +
10796 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
10797 +
10798 +static inline void __put_vx_info(struct vx_info *vxi,
10799 +       const char *_file, int _line, void *_here)
10800 +{
10801 +       if (!vxi)
10802 +               return;
10803 +
10804 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
10805 +               vxi, vxi ? vxi->vx_id : 0,
10806 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10807 +               _file, _line);
10808 +       __vxh_put_vx_info(vxi, _here);
10809 +
10810 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
10811 +               free_vx_info(vxi);
10812 +}
10813 +
10814 +
10815 +#define init_vx_info(p, i) \
10816 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
10817 +
10818 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
10819 +       const char *_file, int _line, void *_here)
10820 +{
10821 +       if (vxi) {
10822 +               vxlprintk(VXD_CBIT(xid, 3),
10823 +                       "init_vx_info(%p[#%d.%d])",
10824 +                       vxi, vxi ? vxi->vx_id : 0,
10825 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10826 +                       _file, _line);
10827 +               __vxh_init_vx_info(vxi, vxp, _here);
10828 +
10829 +               atomic_inc(&vxi->vx_usecnt);
10830 +       }
10831 +       *vxp = vxi;
10832 +}
10833 +
10834 +
10835 +#define set_vx_info(p, i) \
10836 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
10837 +
10838 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
10839 +       const char *_file, int _line, void *_here)
10840 +{
10841 +       struct vx_info *vxo;
10842 +
10843 +       if (!vxi)
10844 +               return;
10845 +
10846 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
10847 +               vxi, vxi ? vxi->vx_id : 0,
10848 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10849 +               _file, _line);
10850 +       __vxh_set_vx_info(vxi, vxp, _here);
10851 +
10852 +       atomic_inc(&vxi->vx_usecnt);
10853 +       vxo = xchg(vxp, vxi);
10854 +       BUG_ON(vxo);
10855 +}
10856 +
10857 +
10858 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
10859 +
10860 +static inline void __clr_vx_info(struct vx_info **vxp,
10861 +       const char *_file, int _line, void *_here)
10862 +{
10863 +       struct vx_info *vxo;
10864 +
10865 +       vxo = xchg(vxp, NULL);
10866 +       if (!vxo)
10867 +               return;
10868 +
10869 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
10870 +               vxo, vxo ? vxo->vx_id : 0,
10871 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
10872 +               _file, _line);
10873 +       __vxh_clr_vx_info(vxo, vxp, _here);
10874 +
10875 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
10876 +               free_vx_info(vxo);
10877 +}
10878 +
10879 +
10880 +#define claim_vx_info(v, p) \
10881 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
10882 +
10883 +static inline void __claim_vx_info(struct vx_info *vxi,
10884 +       struct task_struct *task,
10885 +       const char *_file, int _line, void *_here)
10886 +{
10887 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
10888 +               vxi, vxi ? vxi->vx_id : 0,
10889 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10890 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
10891 +               task, _file, _line);
10892 +       __vxh_claim_vx_info(vxi, task, _here);
10893 +
10894 +       atomic_inc(&vxi->vx_tasks);
10895 +}
10896 +
10897 +
10898 +extern void unhash_vx_info(struct vx_info *);
10899 +
10900 +#define release_vx_info(v, p) \
10901 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
10902 +
10903 +static inline void __release_vx_info(struct vx_info *vxi,
10904 +       struct task_struct *task,
10905 +       const char *_file, int _line, void *_here)
10906 +{
10907 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
10908 +               vxi, vxi ? vxi->vx_id : 0,
10909 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
10910 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
10911 +               task, _file, _line);
10912 +       __vxh_release_vx_info(vxi, task, _here);
10913 +
10914 +       might_sleep();
10915 +
10916 +       if (atomic_dec_and_test(&vxi->vx_tasks))
10917 +               unhash_vx_info(vxi);
10918 +}
10919 +
10920 +
10921 +#define task_get_vx_info(p) \
10922 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
10923 +
10924 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
10925 +       const char *_file, int _line, void *_here)
10926 +{
10927 +       struct vx_info *vxi;
10928 +
10929 +       task_lock(p);
10930 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
10931 +               p, _file, _line);
10932 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
10933 +       task_unlock(p);
10934 +       return vxi;
10935 +}
10936 +
10937 +
10938 +static inline void __wakeup_vx_info(struct vx_info *vxi)
10939 +{
10940 +       if (waitqueue_active(&vxi->vx_wait))
10941 +               wake_up_interruptible(&vxi->vx_wait);
10942 +}
10943 +
10944 +
10945 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
10946 +
10947 +static inline void __enter_vx_info(struct vx_info *vxi,
10948 +       struct vx_info_save *vxis, const char *_file, int _line)
10949 +{
10950 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
10951 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
10952 +               current->xid, current->vx_info, _file, _line);
10953 +       vxis->vxi = xchg(&current->vx_info, vxi);
10954 +       vxis->xid = current->xid;
10955 +       current->xid = vxi ? vxi->vx_id : 0;
10956 +}
10957 +
10958 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
10959 +
10960 +static inline void __leave_vx_info(struct vx_info_save *vxis,
10961 +       const char *_file, int _line)
10962 +{
10963 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
10964 +               vxis, vxis->xid, vxis->vxi, current,
10965 +               current->xid, current->vx_info, _file, _line);
10966 +       (void)xchg(&current->vx_info, vxis->vxi);
10967 +       current->xid = vxis->xid;
10968 +}
10969 +
10970 +
10971 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
10972 +{
10973 +       vxis->vxi = xchg(&current->vx_info, NULL);
10974 +       vxis->xid = xchg(&current->xid, (xid_t)0);
10975 +}
10976 +
10977 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
10978 +{
10979 +       (void)xchg(&current->xid, vxis->xid);
10980 +       (void)xchg(&current->vx_info, vxis->vxi);
10981 +}
10982 +
10983 +#define task_is_init(p) \
10984 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
10985 +
10986 +static inline int __task_is_init(struct task_struct *p,
10987 +       const char *_file, int _line, void *_here)
10988 +{
10989 +       int is_init = is_global_init(p);
10990 +
10991 +       task_lock(p);
10992 +       if (p->vx_info)
10993 +               is_init = p->vx_info->vx_initpid == p->pid;
10994 +       task_unlock(p);
10995 +       return is_init;
10996 +}
10997 +
10998 +extern void exit_vx_info(struct task_struct *, int);
10999 +extern void exit_vx_info_early(struct task_struct *, int);
11000 +
11001 +
11002 +#else
11003 +#warning duplicate inclusion
11004 +#endif
11005 diff -NurpP --minimal linux-3.1/include/linux/vs_cowbl.h linux-3.1-vs2.3.1-rc2/include/linux/vs_cowbl.h
11006 --- linux-3.1/include/linux/vs_cowbl.h  1970-01-01 01:00:00.000000000 +0100
11007 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_cowbl.h      2011-10-24 18:53:33.000000000 +0200
11008 @@ -0,0 +1,48 @@
11009 +#ifndef _VS_COWBL_H
11010 +#define _VS_COWBL_H
11011 +
11012 +#include <linux/fs.h>
11013 +#include <linux/dcache.h>
11014 +#include <linux/namei.h>
11015 +#include <linux/slab.h>
11016 +
11017 +extern struct dentry *cow_break_link(const char *pathname);
11018 +
11019 +static inline int cow_check_and_break(struct path *path)
11020 +{
11021 +       struct inode *inode = path->dentry->d_inode;
11022 +       int error = 0;
11023 +
11024 +       /* do we need this check? */
11025 +       if (IS_RDONLY(inode))
11026 +               return -EROFS;
11027 +
11028 +       if (IS_COW(inode)) {
11029 +               if (IS_COW_LINK(inode)) {
11030 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
11031 +                       char *pp, *buf;
11032 +
11033 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
11034 +                       if (!buf) {
11035 +                               return -ENOMEM;
11036 +                       }
11037 +                       pp = d_path(path, buf, PATH_MAX);
11038 +                       new_dentry = cow_break_link(pp);
11039 +                       kfree(buf);
11040 +                       if (!IS_ERR(new_dentry)) {
11041 +                               path->dentry = new_dentry;
11042 +                               dput(old_dentry);
11043 +                       } else
11044 +                               error = PTR_ERR(new_dentry);
11045 +               } else {
11046 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
11047 +                       inode->i_ctime = CURRENT_TIME;
11048 +                       mark_inode_dirty(inode);
11049 +               }
11050 +       }
11051 +       return error;
11052 +}
11053 +
11054 +#else
11055 +#warning duplicate inclusion
11056 +#endif
11057 diff -NurpP --minimal linux-3.1/include/linux/vs_cvirt.h linux-3.1-vs2.3.1-rc2/include/linux/vs_cvirt.h
11058 --- linux-3.1/include/linux/vs_cvirt.h  1970-01-01 01:00:00.000000000 +0100
11059 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_cvirt.h      2011-10-24 18:53:33.000000000 +0200
11060 @@ -0,0 +1,50 @@
11061 +#ifndef _VS_CVIRT_H
11062 +#define _VS_CVIRT_H
11063 +
11064 +#include "vserver/cvirt.h"
11065 +#include "vserver/context.h"
11066 +#include "vserver/base.h"
11067 +#include "vserver/check.h"
11068 +#include "vserver/debug.h"
11069 +
11070 +
11071 +static inline void vx_activate_task(struct task_struct *p)
11072 +{
11073 +       struct vx_info *vxi;
11074 +
11075 +       if ((vxi = p->vx_info)) {
11076 +               vx_update_load(vxi);
11077 +               atomic_inc(&vxi->cvirt.nr_running);
11078 +       }
11079 +}
11080 +
11081 +static inline void vx_deactivate_task(struct task_struct *p)
11082 +{
11083 +       struct vx_info *vxi;
11084 +
11085 +       if ((vxi = p->vx_info)) {
11086 +               vx_update_load(vxi);
11087 +               atomic_dec(&vxi->cvirt.nr_running);
11088 +       }
11089 +}
11090 +
11091 +static inline void vx_uninterruptible_inc(struct task_struct *p)
11092 +{
11093 +       struct vx_info *vxi;
11094 +
11095 +       if ((vxi = p->vx_info))
11096 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
11097 +}
11098 +
11099 +static inline void vx_uninterruptible_dec(struct task_struct *p)
11100 +{
11101 +       struct vx_info *vxi;
11102 +
11103 +       if ((vxi = p->vx_info))
11104 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
11105 +}
11106 +
11107 +
11108 +#else
11109 +#warning duplicate inclusion
11110 +#endif
11111 diff -NurpP --minimal linux-3.1/include/linux/vs_device.h linux-3.1-vs2.3.1-rc2/include/linux/vs_device.h
11112 --- linux-3.1/include/linux/vs_device.h 1970-01-01 01:00:00.000000000 +0100
11113 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_device.h     2011-10-24 18:53:33.000000000 +0200
11114 @@ -0,0 +1,45 @@
11115 +#ifndef _VS_DEVICE_H
11116 +#define _VS_DEVICE_H
11117 +
11118 +#include "vserver/base.h"
11119 +#include "vserver/device.h"
11120 +#include "vserver/debug.h"
11121 +
11122 +
11123 +#ifdef CONFIG_VSERVER_DEVICE
11124 +
11125 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
11126 +
11127 +#define vs_device_perm(v, d, m, p) \
11128 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
11129 +
11130 +#else
11131 +
11132 +static inline
11133 +int vs_map_device(struct vx_info *vxi,
11134 +       dev_t device, dev_t *target, umode_t mode)
11135 +{
11136 +       if (target)
11137 +               *target = device;
11138 +       return ~0;
11139 +}
11140 +
11141 +#define vs_device_perm(v, d, m, p) ((p) == (p))
11142 +
11143 +#endif
11144 +
11145 +
11146 +#define vs_map_chrdev(d, t, p) \
11147 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
11148 +#define vs_map_blkdev(d, t, p) \
11149 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
11150 +
11151 +#define vs_chrdev_perm(d, p) \
11152 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
11153 +#define vs_blkdev_perm(d, p) \
11154 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
11155 +
11156 +
11157 +#else
11158 +#warning duplicate inclusion
11159 +#endif
11160 diff -NurpP --minimal linux-3.1/include/linux/vs_dlimit.h linux-3.1-vs2.3.1-rc2/include/linux/vs_dlimit.h
11161 --- linux-3.1/include/linux/vs_dlimit.h 1970-01-01 01:00:00.000000000 +0100
11162 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_dlimit.h     2011-10-24 18:53:33.000000000 +0200
11163 @@ -0,0 +1,215 @@
11164 +#ifndef _VS_DLIMIT_H
11165 +#define _VS_DLIMIT_H
11166 +
11167 +#include <linux/fs.h>
11168 +
11169 +#include "vserver/dlimit.h"
11170 +#include "vserver/base.h"
11171 +#include "vserver/debug.h"
11172 +
11173 +
11174 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
11175 +
11176 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
11177 +       const char *_file, int _line)
11178 +{
11179 +       if (!dli)
11180 +               return NULL;
11181 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
11182 +               dli, dli ? dli->dl_tag : 0,
11183 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11184 +               _file, _line);
11185 +       atomic_inc(&dli->dl_usecnt);
11186 +       return dli;
11187 +}
11188 +
11189 +
11190 +#define free_dl_info(i) \
11191 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
11192 +
11193 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
11194 +
11195 +static inline void __put_dl_info(struct dl_info *dli,
11196 +       const char *_file, int _line)
11197 +{
11198 +       if (!dli)
11199 +               return;
11200 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
11201 +               dli, dli ? dli->dl_tag : 0,
11202 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11203 +               _file, _line);
11204 +       if (atomic_dec_and_test(&dli->dl_usecnt))
11205 +               free_dl_info(dli);
11206 +}
11207 +
11208 +
11209 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
11210 +
11211 +static inline int __dl_alloc_space(struct super_block *sb,
11212 +       tag_t tag, dlsize_t nr, const char *file, int line)
11213 +{
11214 +       struct dl_info *dli = NULL;
11215 +       int ret = 0;
11216 +
11217 +       if (nr == 0)
11218 +               goto out;
11219 +       dli = locate_dl_info(sb, tag);
11220 +       if (!dli)
11221 +               goto out;
11222 +
11223 +       spin_lock(&dli->dl_lock);
11224 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
11225 +       if (!ret)
11226 +               dli->dl_space_used += nr;
11227 +       spin_unlock(&dli->dl_lock);
11228 +       put_dl_info(dli);
11229 +out:
11230 +       vxlprintk(VXD_CBIT(dlim, 1),
11231 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
11232 +               sb, tag, __dlimit_char(dli), (long long)nr,
11233 +               ret, file, line);
11234 +       return ret ? -ENOSPC : 0;
11235 +}
11236 +
11237 +static inline void __dl_free_space(struct super_block *sb,
11238 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
11239 +{
11240 +       struct dl_info *dli = NULL;
11241 +
11242 +       if (nr == 0)
11243 +               goto out;
11244 +       dli = locate_dl_info(sb, tag);
11245 +       if (!dli)
11246 +               goto out;
11247 +
11248 +       spin_lock(&dli->dl_lock);
11249 +       if (dli->dl_space_used > nr)
11250 +               dli->dl_space_used -= nr;
11251 +       else
11252 +               dli->dl_space_used = 0;
11253 +       spin_unlock(&dli->dl_lock);
11254 +       put_dl_info(dli);
11255 +out:
11256 +       vxlprintk(VXD_CBIT(dlim, 1),
11257 +               "FREE  (%p,#%d)%c %lld bytes",
11258 +               sb, tag, __dlimit_char(dli), (long long)nr,
11259 +               _file, _line);
11260 +}
11261 +
11262 +static inline int __dl_alloc_inode(struct super_block *sb,
11263 +       tag_t tag, const char *_file, int _line)
11264 +{
11265 +       struct dl_info *dli;
11266 +       int ret = 0;
11267 +
11268 +       dli = locate_dl_info(sb, tag);
11269 +       if (!dli)
11270 +               goto out;
11271 +
11272 +       spin_lock(&dli->dl_lock);
11273 +       dli->dl_inodes_used++;
11274 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
11275 +       spin_unlock(&dli->dl_lock);
11276 +       put_dl_info(dli);
11277 +out:
11278 +       vxlprintk(VXD_CBIT(dlim, 0),
11279 +               "ALLOC (%p,#%d)%c inode (%d)",
11280 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
11281 +       return ret ? -ENOSPC : 0;
11282 +}
11283 +
11284 +static inline void __dl_free_inode(struct super_block *sb,
11285 +       tag_t tag, const char *_file, int _line)
11286 +{
11287 +       struct dl_info *dli;
11288 +
11289 +       dli = locate_dl_info(sb, tag);
11290 +       if (!dli)
11291 +               goto out;
11292 +
11293 +       spin_lock(&dli->dl_lock);
11294 +       if (dli->dl_inodes_used > 1)
11295 +               dli->dl_inodes_used--;
11296 +       else
11297 +               dli->dl_inodes_used = 0;
11298 +       spin_unlock(&dli->dl_lock);
11299 +       put_dl_info(dli);
11300 +out:
11301 +       vxlprintk(VXD_CBIT(dlim, 0),
11302 +               "FREE  (%p,#%d)%c inode",
11303 +               sb, tag, __dlimit_char(dli), _file, _line);
11304 +}
11305 +
11306 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
11307 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
11308 +       const char *_file, int _line)
11309 +{
11310 +       struct dl_info *dli;
11311 +       uint64_t broot, bfree;
11312 +
11313 +       dli = locate_dl_info(sb, tag);
11314 +       if (!dli)
11315 +               return;
11316 +
11317 +       spin_lock(&dli->dl_lock);
11318 +       broot = (dli->dl_space_total -
11319 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
11320 +               >> sb->s_blocksize_bits;
11321 +       bfree = (dli->dl_space_total - dli->dl_space_used)
11322 +                       >> sb->s_blocksize_bits;
11323 +       spin_unlock(&dli->dl_lock);
11324 +
11325 +       vxlprintk(VXD_CBIT(dlim, 2),
11326 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
11327 +               (long long)bfree, (long long)broot,
11328 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
11329 +               _file, _line);
11330 +       if (free_blocks) {
11331 +               if (*free_blocks > bfree)
11332 +                       *free_blocks = bfree;
11333 +       }
11334 +       if (root_blocks) {
11335 +               if (*root_blocks > broot)
11336 +                       *root_blocks = broot;
11337 +       }
11338 +       put_dl_info(dli);
11339 +}
11340 +
11341 +#define dl_prealloc_space(in, bytes) \
11342 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11343 +               __FILE__, __LINE__ )
11344 +
11345 +#define dl_alloc_space(in, bytes) \
11346 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11347 +               __FILE__, __LINE__ )
11348 +
11349 +#define dl_reserve_space(in, bytes) \
11350 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11351 +               __FILE__, __LINE__ )
11352 +
11353 +#define dl_claim_space(in, bytes) (0)
11354 +
11355 +#define dl_release_space(in, bytes) \
11356 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11357 +               __FILE__, __LINE__ )
11358 +
11359 +#define dl_free_space(in, bytes) \
11360 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11361 +               __FILE__, __LINE__ )
11362 +
11363 +
11364 +
11365 +#define dl_alloc_inode(in) \
11366 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11367 +
11368 +#define dl_free_inode(in) \
11369 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11370 +
11371 +
11372 +#define dl_adjust_block(sb, tag, fb, rb) \
11373 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
11374 +
11375 +
11376 +#else
11377 +#warning duplicate inclusion
11378 +#endif
11379 diff -NurpP --minimal linux-3.1/include/linux/vs_inet.h linux-3.1-vs2.3.1-rc2/include/linux/vs_inet.h
11380 --- linux-3.1/include/linux/vs_inet.h   1970-01-01 01:00:00.000000000 +0100
11381 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_inet.h       2011-10-24 18:53:33.000000000 +0200
11382 @@ -0,0 +1,353 @@
11383 +#ifndef _VS_INET_H
11384 +#define _VS_INET_H
11385 +
11386 +#include "vserver/base.h"
11387 +#include "vserver/network.h"
11388 +#include "vserver/debug.h"
11389 +
11390 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
11391 +
11392 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
11393 +                       NIPQUAD((a)->mask), (a)->type
11394 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
11395 +
11396 +#define NIPQUAD(addr) \
11397 +       ((unsigned char *)&addr)[0], \
11398 +       ((unsigned char *)&addr)[1], \
11399 +       ((unsigned char *)&addr)[2], \
11400 +       ((unsigned char *)&addr)[3]
11401 +
11402 +#define NIPQUAD_FMT "%u.%u.%u.%u"
11403 +
11404 +
11405 +static inline
11406 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
11407 +{
11408 +       __be32 ip = nxa->ip[0].s_addr;
11409 +       __be32 mask = nxa->mask.s_addr;
11410 +       __be32 bcast = ip | ~mask;
11411 +       int ret = 0;
11412 +
11413 +       switch (nxa->type & tmask) {
11414 +       case NXA_TYPE_MASK:
11415 +               ret = (ip == (addr & mask));
11416 +               break;
11417 +       case NXA_TYPE_ADDR:
11418 +               ret = 3;
11419 +               if (addr == ip)
11420 +                       break;
11421 +               /* fall through to broadcast */
11422 +       case NXA_MOD_BCAST:
11423 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
11424 +               break;
11425 +       case NXA_TYPE_RANGE:
11426 +               ret = ((nxa->ip[0].s_addr <= addr) &&
11427 +                       (nxa->ip[1].s_addr > addr));
11428 +               break;
11429 +       case NXA_TYPE_ANY:
11430 +               ret = 2;
11431 +               break;
11432 +       }
11433 +
11434 +       vxdprintk(VXD_CBIT(net, 0),
11435 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
11436 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
11437 +       return ret;
11438 +}
11439 +
11440 +static inline
11441 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
11442 +{
11443 +       struct nx_addr_v4 *nxa;
11444 +       int ret = 1;
11445 +
11446 +       if (!nxi)
11447 +               goto out;
11448 +
11449 +       ret = 2;
11450 +       /* allow 127.0.0.1 when remapping lback */
11451 +       if ((tmask & NXA_LOOPBACK) &&
11452 +               (addr == IPI_LOOPBACK) &&
11453 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
11454 +               goto out;
11455 +       ret = 3;
11456 +       /* check for lback address */
11457 +       if ((tmask & NXA_MOD_LBACK) &&
11458 +               (nxi->v4_lback.s_addr == addr))
11459 +               goto out;
11460 +       ret = 4;
11461 +       /* check for broadcast address */
11462 +       if ((tmask & NXA_MOD_BCAST) &&
11463 +               (nxi->v4_bcast.s_addr == addr))
11464 +               goto out;
11465 +       ret = 5;
11466 +       /* check for v4 addresses */
11467 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
11468 +               if (v4_addr_match(nxa, addr, tmask))
11469 +                       goto out;
11470 +       ret = 0;
11471 +out:
11472 +       vxdprintk(VXD_CBIT(net, 0),
11473 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
11474 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
11475 +       return ret;
11476 +}
11477 +
11478 +static inline
11479 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
11480 +{
11481 +       /* FIXME: needs full range checks */
11482 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
11483 +}
11484 +
11485 +static inline
11486 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
11487 +{
11488 +       struct nx_addr_v4 *ptr;
11489 +
11490 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
11491 +               if (v4_nx_addr_match(ptr, nxa, mask))
11492 +                       return 1;
11493 +       return 0;
11494 +}
11495 +
11496 +#include <net/inet_sock.h>
11497 +
11498 +/*
11499 + *     Check if a given address matches for a socket
11500 + *
11501 + *     nxi:            the socket's nx_info if any
11502 + *     addr:           to be verified address
11503 + */
11504 +static inline
11505 +int v4_sock_addr_match (
11506 +       struct nx_info *nxi,
11507 +       struct inet_sock *inet,
11508 +       __be32 addr)
11509 +{
11510 +       __be32 saddr = inet->inet_rcv_saddr;
11511 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
11512 +
11513 +       if (addr && (saddr == addr || bcast == addr))
11514 +               return 1;
11515 +       if (!saddr)
11516 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
11517 +       return 0;
11518 +}
11519 +
11520 +
11521 +/* inet related checks and helpers */
11522 +
11523 +
11524 +struct in_ifaddr;
11525 +struct net_device;
11526 +struct sock;
11527 +
11528 +#ifdef CONFIG_INET
11529 +
11530 +#include <linux/netdevice.h>
11531 +#include <linux/inetdevice.h>
11532 +#include <net/inet_sock.h>
11533 +#include <net/inet_timewait_sock.h>
11534 +
11535 +
11536 +int dev_in_nx_info(struct net_device *, struct nx_info *);
11537 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
11538 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
11539 +
11540 +
11541 +/*
11542 + *     check if address is covered by socket
11543 + *
11544 + *     sk:     the socket to check against
11545 + *     addr:   the address in question (must be != 0)
11546 + */
11547 +
11548 +static inline
11549 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
11550 +{
11551 +       struct nx_info *nxi = sk->sk_nx_info;
11552 +       __be32 saddr = sk_rcv_saddr(sk);
11553 +
11554 +       vxdprintk(VXD_CBIT(net, 5),
11555 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
11556 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
11557 +               (sk->sk_socket?sk->sk_socket->flags:0));
11558 +
11559 +       if (saddr) {            /* direct address match */
11560 +               return v4_addr_match(nxa, saddr, -1);
11561 +       } else if (nxi) {       /* match against nx_info */
11562 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
11563 +       } else {                /* unrestricted any socket */
11564 +               return 1;
11565 +       }
11566 +}
11567 +
11568 +
11569 +
11570 +static inline
11571 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
11572 +{
11573 +       vxdprintk(VXD_CBIT(net, 1),
11574 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
11575 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
11576 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
11577 +
11578 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
11579 +               return 1;
11580 +       if (dev_in_nx_info(dev, nxi))
11581 +               return 1;
11582 +       return 0;
11583 +}
11584 +
11585 +
11586 +static inline
11587 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
11588 +{
11589 +       if (!nxi)
11590 +               return 1;
11591 +       if (!ifa)
11592 +               return 0;
11593 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
11594 +}
11595 +
11596 +static inline
11597 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
11598 +{
11599 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
11600 +               nxi, nxi ? nxi->nx_id : 0, ifa,
11601 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
11602 +
11603 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
11604 +               return 1;
11605 +       if (v4_ifa_in_nx_info(ifa, nxi))
11606 +               return 1;
11607 +       return 0;
11608 +}
11609 +
11610 +
11611 +struct nx_v4_sock_addr {
11612 +       __be32 saddr;   /* Address used for validation */
11613 +       __be32 baddr;   /* Address used for socket bind */
11614 +};
11615 +
11616 +static inline
11617 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
11618 +       struct nx_v4_sock_addr *nsa)
11619 +{
11620 +       struct sock *sk = &inet->sk;
11621 +       struct nx_info *nxi = sk->sk_nx_info;
11622 +       __be32 saddr = addr->sin_addr.s_addr;
11623 +       __be32 baddr = saddr;
11624 +
11625 +       vxdprintk(VXD_CBIT(net, 3),
11626 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
11627 +               sk, sk->sk_nx_info, sk->sk_socket,
11628 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
11629 +               NIPQUAD(saddr));
11630 +
11631 +       if (nxi) {
11632 +               if (saddr == INADDR_ANY) {
11633 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
11634 +                               baddr = nxi->v4.ip[0].s_addr;
11635 +               } else if (saddr == IPI_LOOPBACK) {
11636 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
11637 +                               baddr = nxi->v4_lback.s_addr;
11638 +               } else if (!ipv4_is_multicast(saddr) ||
11639 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
11640 +                       /* normal address bind */
11641 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
11642 +                               return -EADDRNOTAVAIL;
11643 +               }
11644 +       }
11645 +
11646 +       vxdprintk(VXD_CBIT(net, 3),
11647 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
11648 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
11649 +
11650 +       nsa->saddr = saddr;
11651 +       nsa->baddr = baddr;
11652 +       return 0;
11653 +}
11654 +
11655 +static inline
11656 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
11657 +{
11658 +       inet->inet_saddr = nsa->baddr;
11659 +       inet->inet_rcv_saddr = nsa->baddr;
11660 +}
11661 +
11662 +
11663 +/*
11664 + *      helper to simplify inet_lookup_listener
11665 + *
11666 + *      nxi:   the socket's nx_info if any
11667 + *      addr:  to be verified address
11668 + *      saddr: socket address
11669 + */
11670 +static inline int v4_inet_addr_match (
11671 +       struct nx_info *nxi,
11672 +       __be32 addr,
11673 +       __be32 saddr)
11674 +{
11675 +       if (addr && (saddr == addr))
11676 +               return 1;
11677 +       if (!saddr)
11678 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
11679 +       return 0;
11680 +}
11681 +
11682 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
11683 +{
11684 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
11685 +               (addr == nxi->v4_lback.s_addr))
11686 +               return IPI_LOOPBACK;
11687 +       return addr;
11688 +}
11689 +
11690 +static inline
11691 +int nx_info_has_v4(struct nx_info *nxi)
11692 +{
11693 +       if (!nxi)
11694 +               return 1;
11695 +       if (NX_IPV4(nxi))
11696 +               return 1;
11697 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
11698 +               return 1;
11699 +       return 0;
11700 +}
11701 +
11702 +#else /* CONFIG_INET */
11703 +
11704 +static inline
11705 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
11706 +{
11707 +       return 1;
11708 +}
11709 +
11710 +static inline
11711 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
11712 +{
11713 +       return 1;
11714 +}
11715 +
11716 +static inline
11717 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
11718 +{
11719 +       return 1;
11720 +}
11721 +
11722 +static inline
11723 +int nx_info_has_v4(struct nx_info *nxi)
11724 +{
11725 +       return 0;
11726 +}
11727 +
11728 +#endif /* CONFIG_INET */
11729 +
11730 +#define current_nx_info_has_v4() \
11731 +       nx_info_has_v4(current_nx_info())
11732 +
11733 +#else
11734 +// #warning duplicate inclusion
11735 +#endif
11736 diff -NurpP --minimal linux-3.1/include/linux/vs_inet6.h linux-3.1-vs2.3.1-rc2/include/linux/vs_inet6.h
11737 --- linux-3.1/include/linux/vs_inet6.h  1970-01-01 01:00:00.000000000 +0100
11738 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_inet6.h      2011-10-24 18:53:33.000000000 +0200
11739 @@ -0,0 +1,246 @@
11740 +#ifndef _VS_INET6_H
11741 +#define _VS_INET6_H
11742 +
11743 +#include "vserver/base.h"
11744 +#include "vserver/network.h"
11745 +#include "vserver/debug.h"
11746 +
11747 +#include <net/ipv6.h>
11748 +
11749 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
11750 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
11751 +
11752 +
11753 +#ifdef CONFIG_IPV6
11754 +
11755 +static inline
11756 +int v6_addr_match(struct nx_addr_v6 *nxa,
11757 +       const struct in6_addr *addr, uint16_t mask)
11758 +{
11759 +       int ret = 0;
11760 +
11761 +       switch (nxa->type & mask) {
11762 +       case NXA_TYPE_MASK:
11763 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
11764 +               break;
11765 +       case NXA_TYPE_ADDR:
11766 +               ret = ipv6_addr_equal(&nxa->ip, addr);
11767 +               break;
11768 +       case NXA_TYPE_ANY:
11769 +               ret = 1;
11770 +               break;
11771 +       }
11772 +       vxdprintk(VXD_CBIT(net, 0),
11773 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
11774 +               nxa, NXAV6(nxa), addr, mask, ret);
11775 +       return ret;
11776 +}
11777 +
11778 +static inline
11779 +int v6_addr_in_nx_info(struct nx_info *nxi,
11780 +       const struct in6_addr *addr, uint16_t mask)
11781 +{
11782 +       struct nx_addr_v6 *nxa;
11783 +       int ret = 1;
11784 +
11785 +       if (!nxi)
11786 +               goto out;
11787 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
11788 +               if (v6_addr_match(nxa, addr, mask))
11789 +                       goto out;
11790 +       ret = 0;
11791 +out:
11792 +       vxdprintk(VXD_CBIT(net, 0),
11793 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
11794 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
11795 +       return ret;
11796 +}
11797 +
11798 +static inline
11799 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
11800 +{
11801 +       /* FIXME: needs full range checks */
11802 +       return v6_addr_match(nxa, &addr->ip, mask);
11803 +}
11804 +
11805 +static inline
11806 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
11807 +{
11808 +       struct nx_addr_v6 *ptr;
11809 +
11810 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
11811 +               if (v6_nx_addr_match(ptr, nxa, mask))
11812 +                       return 1;
11813 +       return 0;
11814 +}
11815 +
11816 +
11817 +/*
11818 + *     Check if a given address matches for a socket
11819 + *
11820 + *     nxi:            the socket's nx_info if any
11821 + *     addr:           to be verified address
11822 + */
11823 +static inline
11824 +int v6_sock_addr_match (
11825 +       struct nx_info *nxi,
11826 +       struct inet_sock *inet,
11827 +       struct in6_addr *addr)
11828 +{
11829 +       struct sock *sk = &inet->sk;
11830 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
11831 +
11832 +       if (!ipv6_addr_any(addr) &&
11833 +               ipv6_addr_equal(saddr, addr))
11834 +               return 1;
11835 +       if (ipv6_addr_any(saddr))
11836 +               return v6_addr_in_nx_info(nxi, addr, -1);
11837 +       return 0;
11838 +}
11839 +
11840 +/*
11841 + *     check if address is covered by socket
11842 + *
11843 + *     sk:     the socket to check against
11844 + *     addr:   the address in question (must be != 0)
11845 + */
11846 +
11847 +static inline
11848 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
11849 +{
11850 +       struct nx_info *nxi = sk->sk_nx_info;
11851 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
11852 +
11853 +       vxdprintk(VXD_CBIT(net, 5),
11854 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
11855 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
11856 +               (sk->sk_socket?sk->sk_socket->flags:0));
11857 +
11858 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
11859 +               return v6_addr_match(nxa, saddr, -1);
11860 +       } else if (nxi) {               /* match against nx_info */
11861 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
11862 +       } else {                        /* unrestricted any socket */
11863 +               return 1;
11864 +       }
11865 +}
11866 +
11867 +
11868 +/* inet related checks and helpers */
11869 +
11870 +
11871 +struct in_ifaddr;
11872 +struct net_device;
11873 +struct sock;
11874 +
11875 +
11876 +#include <linux/netdevice.h>
11877 +#include <linux/inetdevice.h>
11878 +#include <net/inet_timewait_sock.h>
11879 +
11880 +
11881 +int dev_in_nx_info(struct net_device *, struct nx_info *);
11882 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
11883 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
11884 +
11885 +
11886 +
11887 +static inline
11888 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
11889 +{
11890 +       if (!nxi)
11891 +               return 1;
11892 +       if (!ifa)
11893 +               return 0;
11894 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
11895 +}
11896 +
11897 +static inline
11898 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
11899 +{
11900 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
11901 +               nxi, nxi ? nxi->nx_id : 0, ifa,
11902 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
11903 +
11904 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
11905 +               return 1;
11906 +       if (v6_ifa_in_nx_info(ifa, nxi))
11907 +               return 1;
11908 +       return 0;
11909 +}
11910 +
11911 +
11912 +struct nx_v6_sock_addr {
11913 +       struct in6_addr saddr;  /* Address used for validation */
11914 +       struct in6_addr baddr;  /* Address used for socket bind */
11915 +};
11916 +
11917 +static inline
11918 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
11919 +       struct nx_v6_sock_addr *nsa)
11920 +{
11921 +       // struct sock *sk = &inet->sk;
11922 +       // struct nx_info *nxi = sk->sk_nx_info;
11923 +       struct in6_addr saddr = addr->sin6_addr;
11924 +       struct in6_addr baddr = saddr;
11925 +
11926 +       nsa->saddr = saddr;
11927 +       nsa->baddr = baddr;
11928 +       return 0;
11929 +}
11930 +
11931 +static inline
11932 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
11933 +{
11934 +       // struct sock *sk = &inet->sk;
11935 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
11936 +
11937 +       // *saddr = nsa->baddr;
11938 +       // inet->inet_saddr = nsa->baddr;
11939 +}
11940 +
11941 +static inline
11942 +int nx_info_has_v6(struct nx_info *nxi)
11943 +{
11944 +       if (!nxi)
11945 +               return 1;
11946 +       if (NX_IPV6(nxi))
11947 +               return 1;
11948 +       return 0;
11949 +}
11950 +
11951 +#else /* CONFIG_IPV6 */
11952 +
11953 +static inline
11954 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
11955 +{
11956 +       return 1;
11957 +}
11958 +
11959 +
11960 +static inline
11961 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
11962 +{
11963 +       return 1;
11964 +}
11965 +
11966 +static inline
11967 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
11968 +{
11969 +       return 1;
11970 +}
11971 +
11972 +static inline
11973 +int nx_info_has_v6(struct nx_info *nxi)
11974 +{
11975 +       return 0;
11976 +}
11977 +
11978 +#endif /* CONFIG_IPV6 */
11979 +
11980 +#define current_nx_info_has_v6() \
11981 +       nx_info_has_v6(current_nx_info())
11982 +
11983 +#else
11984 +#warning duplicate inclusion
11985 +#endif
11986 diff -NurpP --minimal linux-3.1/include/linux/vs_limit.h linux-3.1-vs2.3.1-rc2/include/linux/vs_limit.h
11987 --- linux-3.1/include/linux/vs_limit.h  1970-01-01 01:00:00.000000000 +0100
11988 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_limit.h      2011-10-24 18:53:33.000000000 +0200
11989 @@ -0,0 +1,140 @@
11990 +#ifndef _VS_LIMIT_H
11991 +#define _VS_LIMIT_H
11992 +
11993 +#include "vserver/limit.h"
11994 +#include "vserver/base.h"
11995 +#include "vserver/context.h"
11996 +#include "vserver/debug.h"
11997 +#include "vserver/context.h"
11998 +#include "vserver/limit_int.h"
11999 +
12000 +
12001 +#define vx_acc_cres(v, d, p, r) \
12002 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
12003 +
12004 +#define vx_acc_cres_cond(x, d, p, r) \
12005 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
12006 +       r, d, p, __FILE__, __LINE__)
12007 +
12008 +
12009 +#define vx_add_cres(v, a, p, r) \
12010 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
12011 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
12012 +
12013 +#define vx_add_cres_cond(x, a, p, r) \
12014 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
12015 +       r, a, p, __FILE__, __LINE__)
12016 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
12017 +
12018 +
12019 +/* process and file limits */
12020 +
12021 +#define vx_nproc_inc(p) \
12022 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
12023 +
12024 +#define vx_nproc_dec(p) \
12025 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
12026 +
12027 +#define vx_files_inc(f) \
12028 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
12029 +
12030 +#define vx_files_dec(f) \
12031 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
12032 +
12033 +#define vx_locks_inc(l) \
12034 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
12035 +
12036 +#define vx_locks_dec(l) \
12037 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
12038 +
12039 +#define vx_openfd_inc(f) \
12040 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
12041 +
12042 +#define vx_openfd_dec(f) \
12043 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
12044 +
12045 +
12046 +#define vx_cres_avail(v, n, r) \
12047 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
12048 +
12049 +
12050 +#define vx_nproc_avail(n) \
12051 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
12052 +
12053 +#define vx_files_avail(n) \
12054 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
12055 +
12056 +#define vx_locks_avail(n) \
12057 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
12058 +
12059 +#define vx_openfd_avail(n) \
12060 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
12061 +
12062 +
12063 +/* dentry limits */
12064 +
12065 +#define vx_dentry_inc(d) do {                                          \
12066 +       if ((d)->d_count == 1)                                          \
12067 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
12068 +       } while (0)
12069 +
12070 +#define vx_dentry_dec(d) do {                                          \
12071 +       if ((d)->d_count == 0)                                          \
12072 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
12073 +       } while (0)
12074 +
12075 +#define vx_dentry_avail(n) \
12076 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
12077 +
12078 +
12079 +/* socket limits */
12080 +
12081 +#define vx_sock_inc(s) \
12082 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
12083 +
12084 +#define vx_sock_dec(s) \
12085 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
12086 +
12087 +#define vx_sock_avail(n) \
12088 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
12089 +
12090 +
12091 +/* ipc resource limits */
12092 +
12093 +#define vx_ipcmsg_add(v, u, a) \
12094 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
12095 +
12096 +#define vx_ipcmsg_sub(v, u, a) \
12097 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
12098 +
12099 +#define vx_ipcmsg_avail(v, a) \
12100 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
12101 +
12102 +
12103 +#define vx_ipcshm_add(v, k, a) \
12104 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
12105 +
12106 +#define vx_ipcshm_sub(v, k, a) \
12107 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
12108 +
12109 +#define vx_ipcshm_avail(v, a) \
12110 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
12111 +
12112 +
12113 +#define vx_semary_inc(a) \
12114 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
12115 +
12116 +#define vx_semary_dec(a) \
12117 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
12118 +
12119 +
12120 +#define vx_nsems_add(a,n) \
12121 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
12122 +
12123 +#define vx_nsems_sub(a,n) \
12124 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
12125 +
12126 +
12127 +#else
12128 +#warning duplicate inclusion
12129 +#endif
12130 diff -NurpP --minimal linux-3.1/include/linux/vs_memory.h linux-3.1-vs2.3.1-rc2/include/linux/vs_memory.h
12131 --- linux-3.1/include/linux/vs_memory.h 1970-01-01 01:00:00.000000000 +0100
12132 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_memory.h     2011-10-24 18:53:33.000000000 +0200
12133 @@ -0,0 +1,58 @@
12134 +#ifndef _VS_MEMORY_H
12135 +#define _VS_MEMORY_H
12136 +
12137 +#include "vserver/limit.h"
12138 +#include "vserver/base.h"
12139 +#include "vserver/context.h"
12140 +#include "vserver/debug.h"
12141 +#include "vserver/context.h"
12142 +#include "vserver/limit_int.h"
12143 +
12144 +enum {
12145 +       VXPT_UNKNOWN = 0,
12146 +       VXPT_ANON,
12147 +       VXPT_NONE,
12148 +       VXPT_FILE,
12149 +       VXPT_SWAP,
12150 +       VXPT_WRITE
12151 +};
12152 +
12153 +#if 0
12154 +#define        vx_page_fault(mm, vma, type, ret)
12155 +#else
12156 +
12157 +static inline
12158 +void __vx_page_fault(struct mm_struct *mm,
12159 +       struct vm_area_struct *vma, int type, int ret)
12160 +{
12161 +       struct vx_info *vxi = mm->mm_vx_info;
12162 +       int what;
12163 +/*
12164 +       static char *page_type[6] =
12165 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
12166 +       static char *page_what[4] =
12167 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
12168 +*/
12169 +
12170 +       if (!vxi)
12171 +               return;
12172 +
12173 +       what = (ret & 0x3);
12174 +
12175 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
12176 +               type, what, ret, page_type[type], page_what[what]);
12177 +*/
12178 +       if (ret & VM_FAULT_WRITE)
12179 +               what |= 0x4;
12180 +       atomic_inc(&vxi->cacct.page[type][what]);
12181 +}
12182 +
12183 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
12184 +#endif
12185 +
12186 +
12187 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
12188 +
12189 +#else
12190 +#warning duplicate inclusion
12191 +#endif
12192 diff -NurpP --minimal linux-3.1/include/linux/vs_network.h linux-3.1-vs2.3.1-rc2/include/linux/vs_network.h
12193 --- linux-3.1/include/linux/vs_network.h        1970-01-01 01:00:00.000000000 +0100
12194 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_network.h    2011-10-24 18:53:33.000000000 +0200
12195 @@ -0,0 +1,169 @@
12196 +#ifndef _NX_VS_NETWORK_H
12197 +#define _NX_VS_NETWORK_H
12198 +
12199 +#include "vserver/context.h"
12200 +#include "vserver/network.h"
12201 +#include "vserver/base.h"
12202 +#include "vserver/check.h"
12203 +#include "vserver/debug.h"
12204 +
12205 +#include <linux/sched.h>
12206 +
12207 +
12208 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
12209 +
12210 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
12211 +       const char *_file, int _line)
12212 +{
12213 +       if (!nxi)
12214 +               return NULL;
12215 +
12216 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
12217 +               nxi, nxi ? nxi->nx_id : 0,
12218 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12219 +               _file, _line);
12220 +
12221 +       atomic_inc(&nxi->nx_usecnt);
12222 +       return nxi;
12223 +}
12224 +
12225 +
12226 +extern void free_nx_info(struct nx_info *);
12227 +
12228 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
12229 +
12230 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
12231 +{
12232 +       if (!nxi)
12233 +               return;
12234 +
12235 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
12236 +               nxi, nxi ? nxi->nx_id : 0,
12237 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12238 +               _file, _line);
12239 +
12240 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
12241 +               free_nx_info(nxi);
12242 +}
12243 +
12244 +
12245 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
12246 +
12247 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
12248 +               const char *_file, int _line)
12249 +{
12250 +       if (nxi) {
12251 +               vxlprintk(VXD_CBIT(nid, 3),
12252 +                       "init_nx_info(%p[#%d.%d])",
12253 +                       nxi, nxi ? nxi->nx_id : 0,
12254 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12255 +                       _file, _line);
12256 +
12257 +               atomic_inc(&nxi->nx_usecnt);
12258 +       }
12259 +       *nxp = nxi;
12260 +}
12261 +
12262 +
12263 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
12264 +
12265 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
12266 +       const char *_file, int _line)
12267 +{
12268 +       struct nx_info *nxo;
12269 +
12270 +       if (!nxi)
12271 +               return;
12272 +
12273 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
12274 +               nxi, nxi ? nxi->nx_id : 0,
12275 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12276 +               _file, _line);
12277 +
12278 +       atomic_inc(&nxi->nx_usecnt);
12279 +       nxo = xchg(nxp, nxi);
12280 +       BUG_ON(nxo);
12281 +}
12282 +
12283 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
12284 +
12285 +static inline void __clr_nx_info(struct nx_info **nxp,
12286 +       const char *_file, int _line)
12287 +{
12288 +       struct nx_info *nxo;
12289 +
12290 +       nxo = xchg(nxp, NULL);
12291 +       if (!nxo)
12292 +               return;
12293 +
12294 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
12295 +               nxo, nxo ? nxo->nx_id : 0,
12296 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
12297 +               _file, _line);
12298 +
12299 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
12300 +               free_nx_info(nxo);
12301 +}
12302 +
12303 +
12304 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
12305 +
12306 +static inline void __claim_nx_info(struct nx_info *nxi,
12307 +       struct task_struct *task, const char *_file, int _line)
12308 +{
12309 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
12310 +               nxi, nxi ? nxi->nx_id : 0,
12311 +               nxi?atomic_read(&nxi->nx_usecnt):0,
12312 +               nxi?atomic_read(&nxi->nx_tasks):0,
12313 +               task, _file, _line);
12314 +
12315 +       atomic_inc(&nxi->nx_tasks);
12316 +}
12317 +
12318 +
12319 +extern void unhash_nx_info(struct nx_info *);
12320 +
12321 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
12322 +
12323 +static inline void __release_nx_info(struct nx_info *nxi,
12324 +       struct task_struct *task, const char *_file, int _line)
12325 +{
12326 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
12327 +               nxi, nxi ? nxi->nx_id : 0,
12328 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12329 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
12330 +               task, _file, _line);
12331 +
12332 +       might_sleep();
12333 +
12334 +       if (atomic_dec_and_test(&nxi->nx_tasks))
12335 +               unhash_nx_info(nxi);
12336 +}
12337 +
12338 +
12339 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
12340 +
12341 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
12342 +       const char *_file, int _line)
12343 +{
12344 +       struct nx_info *nxi;
12345 +
12346 +       task_lock(p);
12347 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
12348 +               p, _file, _line);
12349 +       nxi = __get_nx_info(p->nx_info, _file, _line);
12350 +       task_unlock(p);
12351 +       return nxi;
12352 +}
12353 +
12354 +
12355 +static inline void exit_nx_info(struct task_struct *p)
12356 +{
12357 +       if (p->nx_info)
12358 +               release_nx_info(p->nx_info, p);
12359 +}
12360 +
12361 +
12362 +#else
12363 +#warning duplicate inclusion
12364 +#endif
12365 diff -NurpP --minimal linux-3.1/include/linux/vs_pid.h linux-3.1-vs2.3.1-rc2/include/linux/vs_pid.h
12366 --- linux-3.1/include/linux/vs_pid.h    1970-01-01 01:00:00.000000000 +0100
12367 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_pid.h        2011-10-24 18:53:33.000000000 +0200
12368 @@ -0,0 +1,50 @@
12369 +#ifndef _VS_PID_H
12370 +#define _VS_PID_H
12371 +
12372 +#include "vserver/base.h"
12373 +#include "vserver/check.h"
12374 +#include "vserver/context.h"
12375 +#include "vserver/debug.h"
12376 +#include "vserver/pid.h"
12377 +#include <linux/pid_namespace.h>
12378 +
12379 +
12380 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
12381 +
12382 +static inline
12383 +int vx_proc_task_visible(struct task_struct *task)
12384 +{
12385 +       if ((task->pid == 1) &&
12386 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
12387 +               /* show a blend through init */
12388 +               goto visible;
12389 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
12390 +               goto visible;
12391 +       return 0;
12392 +visible:
12393 +       return 1;
12394 +}
12395 +
12396 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
12397 +
12398 +
12399 +static inline
12400 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
12401 +{
12402 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
12403 +
12404 +       if (task && !vx_proc_task_visible(task)) {
12405 +               vxdprintk(VXD_CBIT(misc, 6),
12406 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
12407 +                       task, task->xid, task->pid,
12408 +                       current, current->xid, current->pid);
12409 +               put_task_struct(task);
12410 +               task = NULL;
12411 +       }
12412 +       return task;
12413 +}
12414 +
12415 +
12416 +#else
12417 +#warning duplicate inclusion
12418 +#endif
12419 diff -NurpP --minimal linux-3.1/include/linux/vs_sched.h linux-3.1-vs2.3.1-rc2/include/linux/vs_sched.h
12420 --- linux-3.1/include/linux/vs_sched.h  1970-01-01 01:00:00.000000000 +0100
12421 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_sched.h      2011-10-24 18:53:33.000000000 +0200
12422 @@ -0,0 +1,40 @@
12423 +#ifndef _VS_SCHED_H
12424 +#define _VS_SCHED_H
12425 +
12426 +#include "vserver/base.h"
12427 +#include "vserver/context.h"
12428 +#include "vserver/sched.h"
12429 +
12430 +
12431 +#define MAX_PRIO_BIAS           20
12432 +#define MIN_PRIO_BIAS          -20
12433 +
12434 +static inline
12435 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
12436 +{
12437 +       struct vx_info *vxi = p->vx_info;
12438 +
12439 +       if (vxi)
12440 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
12441 +       return prio;
12442 +}
12443 +
12444 +static inline void vx_account_user(struct vx_info *vxi,
12445 +       cputime_t cputime, int nice)
12446 +{
12447 +       if (!vxi)
12448 +               return;
12449 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
12450 +}
12451 +
12452 +static inline void vx_account_system(struct vx_info *vxi,
12453 +       cputime_t cputime, int idle)
12454 +{
12455 +       if (!vxi)
12456 +               return;
12457 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
12458 +}
12459 +
12460 +#else
12461 +#warning duplicate inclusion
12462 +#endif
12463 diff -NurpP --minimal linux-3.1/include/linux/vs_socket.h linux-3.1-vs2.3.1-rc2/include/linux/vs_socket.h
12464 --- linux-3.1/include/linux/vs_socket.h 1970-01-01 01:00:00.000000000 +0100
12465 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_socket.h     2011-10-24 18:53:33.000000000 +0200
12466 @@ -0,0 +1,67 @@
12467 +#ifndef _VS_SOCKET_H
12468 +#define _VS_SOCKET_H
12469 +
12470 +#include "vserver/debug.h"
12471 +#include "vserver/base.h"
12472 +#include "vserver/cacct.h"
12473 +#include "vserver/context.h"
12474 +#include "vserver/tag.h"
12475 +
12476 +
12477 +/* socket accounting */
12478 +
12479 +#include <linux/socket.h>
12480 +
12481 +static inline int vx_sock_type(int family)
12482 +{
12483 +       switch (family) {
12484 +       case PF_UNSPEC:
12485 +               return VXA_SOCK_UNSPEC;
12486 +       case PF_UNIX:
12487 +               return VXA_SOCK_UNIX;
12488 +       case PF_INET:
12489 +               return VXA_SOCK_INET;
12490 +       case PF_INET6:
12491 +               return VXA_SOCK_INET6;
12492 +       case PF_PACKET:
12493 +               return VXA_SOCK_PACKET;
12494 +       default:
12495 +               return VXA_SOCK_OTHER;
12496 +       }
12497 +}
12498 +
12499 +#define vx_acc_sock(v, f, p, s) \
12500 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
12501 +
12502 +static inline void __vx_acc_sock(struct vx_info *vxi,
12503 +       int family, int pos, int size, char *file, int line)
12504 +{
12505 +       if (vxi) {
12506 +               int type = vx_sock_type(family);
12507 +
12508 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
12509 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
12510 +       }
12511 +}
12512 +
12513 +#define vx_sock_recv(sk, s) \
12514 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
12515 +#define vx_sock_send(sk, s) \
12516 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
12517 +#define vx_sock_fail(sk, s) \
12518 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
12519 +
12520 +
12521 +#define sock_vx_init(s) do {           \
12522 +       (s)->sk_xid = 0;                \
12523 +       (s)->sk_vx_info = NULL;         \
12524 +       } while (0)
12525 +
12526 +#define sock_nx_init(s) do {           \
12527 +       (s)->sk_nid = 0;                \
12528 +       (s)->sk_nx_info = NULL;         \
12529 +       } while (0)
12530 +
12531 +#else
12532 +#warning duplicate inclusion
12533 +#endif
12534 diff -NurpP --minimal linux-3.1/include/linux/vs_tag.h linux-3.1-vs2.3.1-rc2/include/linux/vs_tag.h
12535 --- linux-3.1/include/linux/vs_tag.h    1970-01-01 01:00:00.000000000 +0100
12536 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_tag.h        2011-10-24 18:53:33.000000000 +0200
12537 @@ -0,0 +1,47 @@
12538 +#ifndef _VS_TAG_H
12539 +#define _VS_TAG_H
12540 +
12541 +#include <linux/vserver/tag.h>
12542 +
12543 +/* check conditions */
12544 +
12545 +#define DX_ADMIN       0x0001
12546 +#define DX_WATCH       0x0002
12547 +#define DX_HOSTID      0x0008
12548 +
12549 +#define DX_IDENT       0x0010
12550 +
12551 +#define DX_ARG_MASK    0x0010
12552 +
12553 +
12554 +#define dx_task_tag(t) ((t)->tag)
12555 +
12556 +#define dx_current_tag() dx_task_tag(current)
12557 +
12558 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
12559 +
12560 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
12561 +
12562 +
12563 +/*
12564 + * check current context for ADMIN/WATCH and
12565 + * optionally against supplied argument
12566 + */
12567 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
12568 +{
12569 +       if (mode & DX_ARG_MASK) {
12570 +               if ((mode & DX_IDENT) && (id == cid))
12571 +                       return 1;
12572 +       }
12573 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
12574 +               ((mode & DX_WATCH) && (cid == 1)) ||
12575 +               ((mode & DX_HOSTID) && (id == 0)));
12576 +}
12577 +
12578 +struct inode;
12579 +int dx_permission(const struct inode *inode, int mask);
12580 +
12581 +
12582 +#else
12583 +#warning duplicate inclusion
12584 +#endif
12585 diff -NurpP --minimal linux-3.1/include/linux/vs_time.h linux-3.1-vs2.3.1-rc2/include/linux/vs_time.h
12586 --- linux-3.1/include/linux/vs_time.h   1970-01-01 01:00:00.000000000 +0100
12587 +++ linux-3.1-vs2.3.1-rc2/include/linux/vs_time.h       2011-10-24 18:53:33.000000000 +0200
12588 @@ -0,0 +1,19 @@
12589 +#ifndef _VS_TIME_H
12590 +#define _VS_TIME_H
12591 +
12592 +
12593 +/* time faking stuff */
12594 +
12595 +#ifdef CONFIG_VSERVER_VTIME
12596 +
12597 +extern void vx_adjust_timespec(struct timespec *ts);
12598 +extern int vx_settimeofday(const struct timespec *ts);
12599 +
12600 +#else
12601 +#define        vx_adjust_timespec(t)   do { } while (0)
12602 +#define        vx_settimeofday(t)      do_settimeofday(t)
12603 +#endif
12604 +
12605 +#else
12606 +#warning duplicate inclusion
12607 +#endif
12608 diff -NurpP --minimal linux-3.1/include/linux/vserver/Kbuild linux-3.1-vs2.3.1-rc2/include/linux/vserver/Kbuild
12609 --- linux-3.1/include/linux/vserver/Kbuild      1970-01-01 01:00:00.000000000 +0100
12610 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/Kbuild  2011-10-24 18:53:33.000000000 +0200
12611 @@ -0,0 +1,8 @@
12612 +
12613 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12614 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12615 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12616 +       debug_cmd.h device_cmd.h
12617 +
12618 +header-y += switch.h network.h monitor.h inode.h device.h
12619 +
12620 diff -NurpP --minimal linux-3.1/include/linux/vserver/base.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/base.h
12621 --- linux-3.1/include/linux/vserver/base.h      1970-01-01 01:00:00.000000000 +0100
12622 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/base.h  2011-10-24 18:53:33.000000000 +0200
12623 @@ -0,0 +1,178 @@
12624 +#ifndef _VX_BASE_H
12625 +#define _VX_BASE_H
12626 +
12627 +
12628 +/* context state changes */
12629 +
12630 +enum {
12631 +       VSC_STARTUP = 1,
12632 +       VSC_SHUTDOWN,
12633 +
12634 +       VSC_NETUP,
12635 +       VSC_NETDOWN,
12636 +};
12637 +
12638 +
12639 +
12640 +#define vx_task_xid(t) ((t)->xid)
12641 +
12642 +#define vx_current_xid() vx_task_xid(current)
12643 +
12644 +#define current_vx_info() (current->vx_info)
12645 +
12646 +
12647 +#define nx_task_nid(t) ((t)->nid)
12648 +
12649 +#define nx_current_nid() nx_task_nid(current)
12650 +
12651 +#define current_nx_info() (current->nx_info)
12652 +
12653 +
12654 +/* generic flag merging */
12655 +
12656 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
12657 +
12658 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
12659 +
12660 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
12661 +
12662 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
12663 +
12664 +
12665 +/* context flags */
12666 +
12667 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
12668 +
12669 +#define vx_current_flags()     __vx_flags(current_vx_info())
12670 +
12671 +#define vx_info_flags(v, m, f) \
12672 +       vs_check_flags(__vx_flags(v), m, f)
12673 +
12674 +#define task_vx_flags(t, m, f) \
12675 +       ((t) && vx_info_flags((t)->vx_info, m, f))
12676 +
12677 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
12678 +
12679 +
12680 +/* context caps */
12681 +
12682 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
12683 +
12684 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
12685 +
12686 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
12687 +
12688 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
12689 +
12690 +
12691 +
12692 +/* network flags */
12693 +
12694 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
12695 +
12696 +#define nx_current_flags()     __nx_flags(current_nx_info())
12697 +
12698 +#define nx_info_flags(n, m, f) \
12699 +       vs_check_flags(__nx_flags(n), m, f)
12700 +
12701 +#define task_nx_flags(t, m, f) \
12702 +       ((t) && nx_info_flags((t)->nx_info, m, f))
12703 +
12704 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
12705 +
12706 +
12707 +/* network caps */
12708 +
12709 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
12710 +
12711 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
12712 +
12713 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
12714 +
12715 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
12716 +
12717 +
12718 +/* context mask capabilities */
12719 +
12720 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
12721 +
12722 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
12723 +
12724 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
12725 +
12726 +
12727 +/* context bcap mask */
12728 +
12729 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
12730 +
12731 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
12732 +
12733 +
12734 +/* mask given bcaps */
12735 +
12736 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
12737 +
12738 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
12739 +
12740 +
12741 +/* masked cap_bset */
12742 +
12743 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
12744 +
12745 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
12746 +
12747 +#if 0
12748 +#define vx_info_mbcap(v, b) \
12749 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
12750 +       vx_info_bcaps(v, b) : (b))
12751 +
12752 +#define task_vx_mbcap(t, b) \
12753 +       vx_info_mbcap((t)->vx_info, (t)->b)
12754 +
12755 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
12756 +#endif
12757 +
12758 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
12759 +
12760 +#define vx_capable(b, c) (capable(b) || \
12761 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
12762 +
12763 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
12764 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
12765 +
12766 +#define nx_capable(b, c) (capable(b) || \
12767 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
12768 +
12769 +#define vx_task_initpid(t, n) \
12770 +       ((t)->vx_info && \
12771 +       ((t)->vx_info->vx_initpid == (n)))
12772 +
12773 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
12774 +
12775 +
12776 +/* context unshare mask */
12777 +
12778 +#define __vx_umask(v)          ((v)->vx_umask)
12779 +
12780 +#define vx_current_umask()     __vx_umask(current_vx_info())
12781 +
12782 +#define vx_can_unshare(b, f) (capable(b) || \
12783 +       (cap_raised(current_cap(), b) && \
12784 +       !((f) & ~vx_current_umask())))
12785 +
12786 +
12787 +#define __vx_wmask(v)          ((v)->vx_wmask)
12788 +
12789 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
12790 +
12791 +
12792 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
12793 +
12794 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
12795 +
12796 +
12797 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
12798 +
12799 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
12800 +
12801 +#endif
12802 diff -NurpP --minimal linux-3.1/include/linux/vserver/cacct.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/cacct.h
12803 --- linux-3.1/include/linux/vserver/cacct.h     1970-01-01 01:00:00.000000000 +0100
12804 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/cacct.h 2011-10-24 18:53:33.000000000 +0200
12805 @@ -0,0 +1,15 @@
12806 +#ifndef _VX_CACCT_H
12807 +#define _VX_CACCT_H
12808 +
12809 +
12810 +enum sock_acc_field {
12811 +       VXA_SOCK_UNSPEC = 0,
12812 +       VXA_SOCK_UNIX,
12813 +       VXA_SOCK_INET,
12814 +       VXA_SOCK_INET6,
12815 +       VXA_SOCK_PACKET,
12816 +       VXA_SOCK_OTHER,
12817 +       VXA_SOCK_SIZE   /* array size */
12818 +};
12819 +
12820 +#endif /* _VX_CACCT_H */
12821 diff -NurpP --minimal linux-3.1/include/linux/vserver/cacct_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/cacct_cmd.h
12822 --- linux-3.1/include/linux/vserver/cacct_cmd.h 1970-01-01 01:00:00.000000000 +0100
12823 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/cacct_cmd.h     2011-10-24 18:53:33.000000000 +0200
12824 @@ -0,0 +1,23 @@
12825 +#ifndef _VX_CACCT_CMD_H
12826 +#define _VX_CACCT_CMD_H
12827 +
12828 +
12829 +/* virtual host info name commands */
12830 +
12831 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12832 +
12833 +struct vcmd_sock_stat_v0 {
12834 +       uint32_t field;
12835 +       uint32_t count[3];
12836 +       uint64_t total[3];
12837 +};
12838 +
12839 +
12840 +#ifdef __KERNEL__
12841 +
12842 +#include <linux/compiler.h>
12843 +
12844 +extern int vc_sock_stat(struct vx_info *, void __user *);
12845 +
12846 +#endif /* __KERNEL__ */
12847 +#endif /* _VX_CACCT_CMD_H */
12848 diff -NurpP --minimal linux-3.1/include/linux/vserver/cacct_def.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/cacct_def.h
12849 --- linux-3.1/include/linux/vserver/cacct_def.h 1970-01-01 01:00:00.000000000 +0100
12850 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/cacct_def.h     2011-10-24 18:53:33.000000000 +0200
12851 @@ -0,0 +1,43 @@
12852 +#ifndef _VX_CACCT_DEF_H
12853 +#define _VX_CACCT_DEF_H
12854 +
12855 +#include <asm/atomic.h>
12856 +#include <linux/vserver/cacct.h>
12857 +
12858 +
12859 +struct _vx_sock_acc {
12860 +       atomic_long_t count;
12861 +       atomic_long_t total;
12862 +};
12863 +
12864 +/* context sub struct */
12865 +
12866 +struct _vx_cacct {
12867 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
12868 +       atomic_t slab[8];
12869 +       atomic_t page[6][8];
12870 +};
12871 +
12872 +#ifdef CONFIG_VSERVER_DEBUG
12873 +
12874 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
12875 +{
12876 +       int i, j;
12877 +
12878 +       printk("\t_vx_cacct:");
12879 +       for (i = 0; i < 6; i++) {
12880 +               struct _vx_sock_acc *ptr = cacct->sock[i];
12881 +
12882 +               printk("\t [%d] =", i);
12883 +               for (j = 0; j < 3; j++) {
12884 +                       printk(" [%d] = %8lu, %8lu", j,
12885 +                               atomic_long_read(&ptr[j].count),
12886 +                               atomic_long_read(&ptr[j].total));
12887 +               }
12888 +               printk("\n");
12889 +       }
12890 +}
12891 +
12892 +#endif
12893 +
12894 +#endif /* _VX_CACCT_DEF_H */
12895 diff -NurpP --minimal linux-3.1/include/linux/vserver/cacct_int.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/cacct_int.h
12896 --- linux-3.1/include/linux/vserver/cacct_int.h 1970-01-01 01:00:00.000000000 +0100
12897 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/cacct_int.h     2011-10-24 18:53:33.000000000 +0200
12898 @@ -0,0 +1,21 @@
12899 +#ifndef _VX_CACCT_INT_H
12900 +#define _VX_CACCT_INT_H
12901 +
12902 +
12903 +#ifdef __KERNEL__
12904 +
12905 +static inline
12906 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
12907 +{
12908 +       return atomic_long_read(&cacct->sock[type][pos].count);
12909 +}
12910 +
12911 +
12912 +static inline
12913 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
12914 +{
12915 +       return atomic_long_read(&cacct->sock[type][pos].total);
12916 +}
12917 +
12918 +#endif /* __KERNEL__ */
12919 +#endif /* _VX_CACCT_INT_H */
12920 diff -NurpP --minimal linux-3.1/include/linux/vserver/check.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/check.h
12921 --- linux-3.1/include/linux/vserver/check.h     1970-01-01 01:00:00.000000000 +0100
12922 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/check.h 2011-10-24 18:53:33.000000000 +0200
12923 @@ -0,0 +1,89 @@
12924 +#ifndef _VS_CHECK_H
12925 +#define _VS_CHECK_H
12926 +
12927 +
12928 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
12929 +
12930 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
12931 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
12932 +#else
12933 +#define MIN_D_CONTEXT  65536
12934 +#endif
12935 +
12936 +/* check conditions */
12937 +
12938 +#define VS_ADMIN       0x0001
12939 +#define VS_WATCH       0x0002
12940 +#define VS_HIDE                0x0004
12941 +#define VS_HOSTID      0x0008
12942 +
12943 +#define VS_IDENT       0x0010
12944 +#define VS_EQUIV       0x0020
12945 +#define VS_PARENT      0x0040
12946 +#define VS_CHILD       0x0080
12947 +
12948 +#define VS_ARG_MASK    0x00F0
12949 +
12950 +#define VS_DYNAMIC     0x0100
12951 +#define VS_STATIC      0x0200
12952 +
12953 +#define VS_ATR_MASK    0x0F00
12954 +
12955 +#ifdef CONFIG_VSERVER_PRIVACY
12956 +#define VS_ADMIN_P     (0)
12957 +#define VS_WATCH_P     (0)
12958 +#else
12959 +#define VS_ADMIN_P     VS_ADMIN
12960 +#define VS_WATCH_P     VS_WATCH
12961 +#endif
12962 +
12963 +#define VS_HARDIRQ     0x1000
12964 +#define VS_SOFTIRQ     0x2000
12965 +#define VS_IRQ         0x4000
12966 +
12967 +#define VS_IRQ_MASK    0xF000
12968 +
12969 +#include <linux/hardirq.h>
12970 +
12971 +/*
12972 + * check current context for ADMIN/WATCH and
12973 + * optionally against supplied argument
12974 + */
12975 +static inline int __vs_check(int cid, int id, unsigned int mode)
12976 +{
12977 +       if (mode & VS_ARG_MASK) {
12978 +               if ((mode & VS_IDENT) && (id == cid))
12979 +                       return 1;
12980 +       }
12981 +       if (mode & VS_ATR_MASK) {
12982 +               if ((mode & VS_DYNAMIC) &&
12983 +                       (id >= MIN_D_CONTEXT) &&
12984 +                       (id <= MAX_S_CONTEXT))
12985 +                       return 1;
12986 +               if ((mode & VS_STATIC) &&
12987 +                       (id > 1) && (id < MIN_D_CONTEXT))
12988 +                       return 1;
12989 +       }
12990 +       if (mode & VS_IRQ_MASK) {
12991 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
12992 +                       return 1;
12993 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
12994 +                       return 1;
12995 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
12996 +                       return 1;
12997 +       }
12998 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
12999 +               ((mode & VS_WATCH) && (cid == 1)) ||
13000 +               ((mode & VS_HOSTID) && (id == 0)));
13001 +}
13002 +
13003 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
13004 +
13005 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
13006 +
13007 +
13008 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
13009 +
13010 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
13011 +
13012 +#endif
13013 diff -NurpP --minimal linux-3.1/include/linux/vserver/context.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/context.h
13014 --- linux-3.1/include/linux/vserver/context.h   1970-01-01 01:00:00.000000000 +0100
13015 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/context.h       2011-10-24 18:53:33.000000000 +0200
13016 @@ -0,0 +1,190 @@
13017 +#ifndef _VX_CONTEXT_H
13018 +#define _VX_CONTEXT_H
13019 +
13020 +#include <linux/types.h>
13021 +#include <linux/capability.h>
13022 +
13023 +
13024 +/* context flags */
13025 +
13026 +#define VXF_INFO_SCHED         0x00000002
13027 +#define VXF_INFO_NPROC         0x00000004
13028 +#define VXF_INFO_PRIVATE       0x00000008
13029 +
13030 +#define VXF_INFO_INIT          0x00000010
13031 +#define VXF_INFO_HIDE          0x00000020
13032 +#define VXF_INFO_ULIMIT                0x00000040
13033 +#define VXF_INFO_NSPACE                0x00000080
13034 +
13035 +#define VXF_SCHED_HARD         0x00000100
13036 +#define VXF_SCHED_PRIO         0x00000200
13037 +#define VXF_SCHED_PAUSE                0x00000400
13038 +
13039 +#define VXF_VIRT_MEM           0x00010000
13040 +#define VXF_VIRT_UPTIME                0x00020000
13041 +#define VXF_VIRT_CPU           0x00040000
13042 +#define VXF_VIRT_LOAD          0x00080000
13043 +#define VXF_VIRT_TIME          0x00100000
13044 +
13045 +#define VXF_HIDE_MOUNT         0x01000000
13046 +/* was VXF_HIDE_NETIF          0x02000000 */
13047 +#define VXF_HIDE_VINFO         0x04000000
13048 +
13049 +#define VXF_STATE_SETUP                (1ULL << 32)
13050 +#define VXF_STATE_INIT         (1ULL << 33)
13051 +#define VXF_STATE_ADMIN                (1ULL << 34)
13052 +
13053 +#define VXF_SC_HELPER          (1ULL << 36)
13054 +#define VXF_REBOOT_KILL                (1ULL << 37)
13055 +#define VXF_PERSISTENT         (1ULL << 38)
13056 +
13057 +#define VXF_FORK_RSS           (1ULL << 48)
13058 +#define VXF_PROLIFIC           (1ULL << 49)
13059 +
13060 +#define VXF_IGNEG_NICE         (1ULL << 52)
13061 +
13062 +#define VXF_ONE_TIME           (0x0007ULL << 32)
13063 +
13064 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
13065 +
13066 +
13067 +/* context migration */
13068 +
13069 +#define VXM_SET_INIT           0x00000001
13070 +#define VXM_SET_REAPER         0x00000002
13071 +
13072 +/* context caps */
13073 +
13074 +#define VXC_CAP_MASK           0x00000000
13075 +
13076 +#define VXC_SET_UTSNAME                0x00000001
13077 +#define VXC_SET_RLIMIT         0x00000002
13078 +#define VXC_FS_SECURITY                0x00000004
13079 +#define VXC_FS_TRUSTED         0x00000008
13080 +#define VXC_TIOCSTI            0x00000010
13081 +
13082 +/* was VXC_RAW_ICMP            0x00000100 */
13083 +#define VXC_SYSLOG             0x00001000
13084 +#define VXC_OOM_ADJUST         0x00002000
13085 +#define VXC_AUDIT_CONTROL      0x00004000
13086 +
13087 +#define VXC_SECURE_MOUNT       0x00010000
13088 +#define VXC_SECURE_REMOUNT     0x00020000
13089 +#define VXC_BINARY_MOUNT       0x00040000
13090 +
13091 +#define VXC_QUOTA_CTL          0x00100000
13092 +#define VXC_ADMIN_MAPPER       0x00200000
13093 +#define VXC_ADMIN_CLOOP                0x00400000
13094 +
13095 +#define VXC_KTHREAD            0x01000000
13096 +#define VXC_NAMESPACE          0x02000000
13097 +
13098 +
13099 +#ifdef __KERNEL__
13100 +
13101 +#include <linux/list.h>
13102 +#include <linux/spinlock.h>
13103 +#include <linux/rcupdate.h>
13104 +
13105 +#include "limit_def.h"
13106 +#include "sched_def.h"
13107 +#include "cvirt_def.h"
13108 +#include "cacct_def.h"
13109 +#include "device_def.h"
13110 +
13111 +#define VX_SPACES      2
13112 +
13113 +struct _vx_info_pc {
13114 +       struct _vx_sched_pc sched_pc;
13115 +       struct _vx_cvirt_pc cvirt_pc;
13116 +};
13117 +
13118 +struct _vx_space {
13119 +       unsigned long vx_nsmask;                /* assignment mask */
13120 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
13121 +       struct fs_struct *vx_fs;                /* private namespace fs */
13122 +       const struct cred *vx_cred;             /* task credentials */
13123 +};
13124 +
13125 +struct vx_info {
13126 +       struct hlist_node vx_hlist;             /* linked list of contexts */
13127 +       xid_t vx_id;                            /* context id */
13128 +       atomic_t vx_usecnt;                     /* usage count */
13129 +       atomic_t vx_tasks;                      /* tasks count */
13130 +       struct vx_info *vx_parent;              /* parent context */
13131 +       int vx_state;                           /* context state */
13132 +
13133 +       struct _vx_space space[VX_SPACES];      /* namespace store */
13134 +
13135 +       uint64_t vx_flags;                      /* context flags */
13136 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
13137 +       uint64_t vx_umask;                      /* unshare mask (guest) */
13138 +       uint64_t vx_wmask;                      /* warn mask (guest) */
13139 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
13140 +
13141 +       struct task_struct *vx_reaper;          /* guest reaper process */
13142 +       pid_t vx_initpid;                       /* PID of guest init */
13143 +       int64_t vx_badness_bias;                /* OOM points bias */
13144 +
13145 +       struct _vx_limit limit;                 /* vserver limits */
13146 +       struct _vx_sched sched;                 /* vserver scheduler */
13147 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
13148 +       struct _vx_cacct cacct;                 /* context accounting */
13149 +
13150 +       struct _vx_device dmap;                 /* default device map targets */
13151 +
13152 +#ifndef CONFIG_SMP
13153 +       struct _vx_info_pc info_pc;             /* per cpu data */
13154 +#else
13155 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
13156 +#endif
13157 +
13158 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
13159 +       int reboot_cmd;                         /* last sys_reboot() cmd */
13160 +       int exit_code;                          /* last process exit code */
13161 +
13162 +       char vx_name[65];                       /* vserver name */
13163 +};
13164 +
13165 +#ifndef CONFIG_SMP
13166 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
13167 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
13168 +#else
13169 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
13170 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
13171 +#endif
13172 +
13173 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
13174 +
13175 +
13176 +struct vx_info_save {
13177 +       struct vx_info *vxi;
13178 +       xid_t xid;
13179 +};
13180 +
13181 +
13182 +/* status flags */
13183 +
13184 +#define VXS_HASHED     0x0001
13185 +#define VXS_PAUSED     0x0010
13186 +#define VXS_SHUTDOWN   0x0100
13187 +#define VXS_HELPER     0x1000
13188 +#define VXS_RELEASED   0x8000
13189 +
13190 +
13191 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
13192 +extern void release_vx_info(struct vx_info *, struct task_struct *);
13193 +
13194 +extern struct vx_info *lookup_vx_info(int);
13195 +extern struct vx_info *lookup_or_create_vx_info(int);
13196 +
13197 +extern int get_xid_list(int, unsigned int *, int);
13198 +extern int xid_is_hashed(xid_t);
13199 +
13200 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
13201 +
13202 +extern long vs_state_change(struct vx_info *, unsigned int);
13203 +
13204 +
13205 +#endif /* __KERNEL__ */
13206 +#endif /* _VX_CONTEXT_H */
13207 diff -NurpP --minimal linux-3.1/include/linux/vserver/context_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/context_cmd.h
13208 --- linux-3.1/include/linux/vserver/context_cmd.h       1970-01-01 01:00:00.000000000 +0100
13209 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/context_cmd.h   2011-10-24 18:53:33.000000000 +0200
13210 @@ -0,0 +1,162 @@
13211 +#ifndef _VX_CONTEXT_CMD_H
13212 +#define _VX_CONTEXT_CMD_H
13213 +
13214 +
13215 +/* vinfo commands */
13216 +
13217 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
13218 +
13219 +#ifdef __KERNEL__
13220 +extern int vc_task_xid(uint32_t);
13221 +
13222 +#endif /* __KERNEL__ */
13223 +
13224 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
13225 +
13226 +struct vcmd_vx_info_v0 {
13227 +       uint32_t xid;
13228 +       uint32_t initpid;
13229 +       /* more to come */
13230 +};
13231 +
13232 +#ifdef __KERNEL__
13233 +extern int vc_vx_info(struct vx_info *, void __user *);
13234 +
13235 +#endif /* __KERNEL__ */
13236 +
13237 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
13238 +
13239 +struct vcmd_ctx_stat_v0 {
13240 +       uint32_t usecnt;
13241 +       uint32_t tasks;
13242 +       /* more to come */
13243 +};
13244 +
13245 +#ifdef __KERNEL__
13246 +extern int vc_ctx_stat(struct vx_info *, void __user *);
13247 +
13248 +#endif /* __KERNEL__ */
13249 +
13250 +/* context commands */
13251 +
13252 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
13253 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
13254 +
13255 +struct vcmd_ctx_create {
13256 +       uint64_t flagword;
13257 +};
13258 +
13259 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
13260 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
13261 +
13262 +struct vcmd_ctx_migrate {
13263 +       uint64_t flagword;
13264 +};
13265 +
13266 +#ifdef __KERNEL__
13267 +extern int vc_ctx_create(uint32_t, void __user *);
13268 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
13269 +
13270 +#endif /* __KERNEL__ */
13271 +
13272 +
13273 +/* flag commands */
13274 +
13275 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
13276 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
13277 +
13278 +struct vcmd_ctx_flags_v0 {
13279 +       uint64_t flagword;
13280 +       uint64_t mask;
13281 +};
13282 +
13283 +#ifdef __KERNEL__
13284 +extern int vc_get_cflags(struct vx_info *, void __user *);
13285 +extern int vc_set_cflags(struct vx_info *, void __user *);
13286 +
13287 +#endif /* __KERNEL__ */
13288 +
13289 +
13290 +/* context caps commands */
13291 +
13292 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
13293 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
13294 +
13295 +struct vcmd_ctx_caps_v1 {
13296 +       uint64_t ccaps;
13297 +       uint64_t cmask;
13298 +};
13299 +
13300 +#ifdef __KERNEL__
13301 +extern int vc_get_ccaps(struct vx_info *, void __user *);
13302 +extern int vc_set_ccaps(struct vx_info *, void __user *);
13303 +
13304 +#endif /* __KERNEL__ */
13305 +
13306 +
13307 +/* bcaps commands */
13308 +
13309 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
13310 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
13311 +
13312 +struct vcmd_bcaps {
13313 +       uint64_t bcaps;
13314 +       uint64_t bmask;
13315 +};
13316 +
13317 +#ifdef __KERNEL__
13318 +extern int vc_get_bcaps(struct vx_info *, void __user *);
13319 +extern int vc_set_bcaps(struct vx_info *, void __user *);
13320 +
13321 +#endif /* __KERNEL__ */
13322 +
13323 +
13324 +/* umask commands */
13325 +
13326 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
13327 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
13328 +
13329 +struct vcmd_umask {
13330 +       uint64_t umask;
13331 +       uint64_t mask;
13332 +};
13333 +
13334 +#ifdef __KERNEL__
13335 +extern int vc_get_umask(struct vx_info *, void __user *);
13336 +extern int vc_set_umask(struct vx_info *, void __user *);
13337 +
13338 +#endif /* __KERNEL__ */
13339 +
13340 +
13341 +/* wmask commands */
13342 +
13343 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
13344 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
13345 +
13346 +struct vcmd_wmask {
13347 +       uint64_t wmask;
13348 +       uint64_t mask;
13349 +};
13350 +
13351 +#ifdef __KERNEL__
13352 +extern int vc_get_wmask(struct vx_info *, void __user *);
13353 +extern int vc_set_wmask(struct vx_info *, void __user *);
13354 +
13355 +#endif /* __KERNEL__ */
13356 +
13357 +
13358 +/* OOM badness */
13359 +
13360 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
13361 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
13362 +
13363 +struct vcmd_badness_v0 {
13364 +       int64_t bias;
13365 +};
13366 +
13367 +#ifdef __KERNEL__
13368 +extern int vc_get_badness(struct vx_info *, void __user *);
13369 +extern int vc_set_badness(struct vx_info *, void __user *);
13370 +
13371 +#endif /* __KERNEL__ */
13372 +#endif /* _VX_CONTEXT_CMD_H */
13373 diff -NurpP --minimal linux-3.1/include/linux/vserver/cvirt.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/cvirt.h
13374 --- linux-3.1/include/linux/vserver/cvirt.h     1970-01-01 01:00:00.000000000 +0100
13375 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/cvirt.h 2011-10-24 18:53:33.000000000 +0200
13376 @@ -0,0 +1,20 @@
13377 +#ifndef _VX_CVIRT_H
13378 +#define _VX_CVIRT_H
13379 +
13380 +
13381 +#ifdef __KERNEL__
13382 +
13383 +struct timespec;
13384 +
13385 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13386 +
13387 +
13388 +struct vx_info;
13389 +
13390 +void vx_update_load(struct vx_info *);
13391 +
13392 +
13393 +int vx_do_syslog(int, char __user *, int);
13394 +
13395 +#endif /* __KERNEL__ */
13396 +#endif /* _VX_CVIRT_H */
13397 diff -NurpP --minimal linux-3.1/include/linux/vserver/cvirt_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/cvirt_cmd.h
13398 --- linux-3.1/include/linux/vserver/cvirt_cmd.h 1970-01-01 01:00:00.000000000 +0100
13399 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/cvirt_cmd.h     2011-10-24 18:53:33.000000000 +0200
13400 @@ -0,0 +1,53 @@
13401 +#ifndef _VX_CVIRT_CMD_H
13402 +#define _VX_CVIRT_CMD_H
13403 +
13404 +
13405 +/* virtual host info name commands */
13406 +
13407 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
13408 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
13409 +
13410 +struct vcmd_vhi_name_v0 {
13411 +       uint32_t field;
13412 +       char name[65];
13413 +};
13414 +
13415 +
13416 +enum vhi_name_field {
13417 +       VHIN_CONTEXT = 0,
13418 +       VHIN_SYSNAME,
13419 +       VHIN_NODENAME,
13420 +       VHIN_RELEASE,
13421 +       VHIN_VERSION,
13422 +       VHIN_MACHINE,
13423 +       VHIN_DOMAINNAME,
13424 +};
13425 +
13426 +
13427 +#ifdef __KERNEL__
13428 +
13429 +#include <linux/compiler.h>
13430 +
13431 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
13432 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
13433 +
13434 +#endif /* __KERNEL__ */
13435 +
13436 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
13437 +
13438 +struct vcmd_virt_stat_v0 {
13439 +       uint64_t offset;
13440 +       uint64_t uptime;
13441 +       uint32_t nr_threads;
13442 +       uint32_t nr_running;
13443 +       uint32_t nr_uninterruptible;
13444 +       uint32_t nr_onhold;
13445 +       uint32_t nr_forks;
13446 +       uint32_t load[3];
13447 +};
13448 +
13449 +#ifdef __KERNEL__
13450 +extern int vc_virt_stat(struct vx_info *, void __user *);
13451 +
13452 +#endif /* __KERNEL__ */
13453 +#endif /* _VX_CVIRT_CMD_H */
13454 diff -NurpP --minimal linux-3.1/include/linux/vserver/cvirt_def.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/cvirt_def.h
13455 --- linux-3.1/include/linux/vserver/cvirt_def.h 1970-01-01 01:00:00.000000000 +0100
13456 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/cvirt_def.h     2011-10-24 18:53:33.000000000 +0200
13457 @@ -0,0 +1,80 @@
13458 +#ifndef _VX_CVIRT_DEF_H
13459 +#define _VX_CVIRT_DEF_H
13460 +
13461 +#include <linux/jiffies.h>
13462 +#include <linux/spinlock.h>
13463 +#include <linux/wait.h>
13464 +#include <linux/time.h>
13465 +#include <asm/atomic.h>
13466 +
13467 +
13468 +struct _vx_usage_stat {
13469 +       uint64_t user;
13470 +       uint64_t nice;
13471 +       uint64_t system;
13472 +       uint64_t softirq;
13473 +       uint64_t irq;
13474 +       uint64_t idle;
13475 +       uint64_t iowait;
13476 +};
13477 +
13478 +struct _vx_syslog {
13479 +       wait_queue_head_t log_wait;
13480 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
13481 +
13482 +       unsigned long log_start;        /* next char to be read by syslog() */
13483 +       unsigned long con_start;        /* next char to be sent to consoles */
13484 +       unsigned long log_end;  /* most-recently-written-char + 1 */
13485 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
13486 +
13487 +       char log_buf[1024];
13488 +};
13489 +
13490 +
13491 +/* context sub struct */
13492 +
13493 +struct _vx_cvirt {
13494 +       atomic_t nr_threads;            /* number of current threads */
13495 +       atomic_t nr_running;            /* number of running threads */
13496 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
13497 +
13498 +       atomic_t nr_onhold;             /* processes on hold */
13499 +       uint32_t onhold_last;           /* jiffies when put on hold */
13500 +
13501 +       struct timespec bias_ts;        /* time offset to the host */
13502 +       struct timespec bias_idle;
13503 +       struct timespec bias_uptime;    /* context creation point */
13504 +       uint64_t bias_clock;            /* offset in clock_t */
13505 +
13506 +       spinlock_t load_lock;           /* lock for the load averages */
13507 +       atomic_t load_updates;          /* nr of load updates done so far */
13508 +       uint32_t load_last;             /* last time load was calculated */
13509 +       uint32_t load[3];               /* load averages 1,5,15 */
13510 +
13511 +       atomic_t total_forks;           /* number of forks so far */
13512 +
13513 +       struct _vx_syslog syslog;
13514 +};
13515 +
13516 +struct _vx_cvirt_pc {
13517 +       struct _vx_usage_stat cpustat;
13518 +};
13519 +
13520 +
13521 +#ifdef CONFIG_VSERVER_DEBUG
13522 +
13523 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
13524 +{
13525 +       printk("\t_vx_cvirt:\n");
13526 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
13527 +               atomic_read(&cvirt->nr_threads),
13528 +               atomic_read(&cvirt->nr_running),
13529 +               atomic_read(&cvirt->nr_uninterruptible),
13530 +               atomic_read(&cvirt->nr_onhold));
13531 +       /* add rest here */
13532 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
13533 +}
13534 +
13535 +#endif
13536 +
13537 +#endif /* _VX_CVIRT_DEF_H */
13538 diff -NurpP --minimal linux-3.1/include/linux/vserver/debug.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/debug.h
13539 --- linux-3.1/include/linux/vserver/debug.h     1970-01-01 01:00:00.000000000 +0100
13540 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/debug.h 2011-10-24 18:53:33.000000000 +0200
13541 @@ -0,0 +1,140 @@
13542 +#ifndef _VX_DEBUG_H
13543 +#define _VX_DEBUG_H
13544 +
13545 +
13546 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
13547 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
13548 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
13549 +
13550 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
13551 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
13552 +#define VXF_DEV                "%p[%lu,%d:%d]"
13553 +
13554 +#if    defined(CONFIG_QUOTES_UTF8)
13555 +#define        VS_Q_LQM        "\xc2\xbb"
13556 +#define        VS_Q_RQM        "\xc2\xab"
13557 +#elif  defined(CONFIG_QUOTES_ASCII)
13558 +#define        VS_Q_LQM        "\x27"
13559 +#define        VS_Q_RQM        "\x27"
13560 +#else
13561 +#define        VS_Q_LQM        "\xbb"
13562 +#define        VS_Q_RQM        "\xab"
13563 +#endif
13564 +
13565 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
13566 +
13567 +
13568 +#define vxd_path(p)                                            \
13569 +       ({ static char _buffer[PATH_MAX];                       \
13570 +          d_path(p, _buffer, sizeof(_buffer)); })
13571 +
13572 +#define vxd_cond_path(n)                                       \
13573 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
13574 +
13575 +
13576 +#ifdef CONFIG_VSERVER_DEBUG
13577 +
13578 +extern unsigned int vx_debug_switch;
13579 +extern unsigned int vx_debug_xid;
13580 +extern unsigned int vx_debug_nid;
13581 +extern unsigned int vx_debug_tag;
13582 +extern unsigned int vx_debug_net;
13583 +extern unsigned int vx_debug_limit;
13584 +extern unsigned int vx_debug_cres;
13585 +extern unsigned int vx_debug_dlim;
13586 +extern unsigned int vx_debug_quota;
13587 +extern unsigned int vx_debug_cvirt;
13588 +extern unsigned int vx_debug_space;
13589 +extern unsigned int vx_debug_misc;
13590 +
13591 +
13592 +#define VX_LOGLEVEL    "vxD: "
13593 +#define VX_PROC_FMT    "%p: "
13594 +#define VX_PROCESS     current
13595 +
13596 +#define vxdprintk(c, f, x...)                                  \
13597 +       do {                                                    \
13598 +               if (c)                                          \
13599 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
13600 +                               VX_PROCESS , ##x);              \
13601 +       } while (0)
13602 +
13603 +#define vxlprintk(c, f, x...)                                  \
13604 +       do {                                                    \
13605 +               if (c)                                          \
13606 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
13607 +       } while (0)
13608 +
13609 +#define vxfprintk(c, f, x...)                                  \
13610 +       do {                                                    \
13611 +               if (c)                                          \
13612 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
13613 +       } while (0)
13614 +
13615 +
13616 +struct vx_info;
13617 +
13618 +void dump_vx_info(struct vx_info *, int);
13619 +void dump_vx_info_inactive(int);
13620 +
13621 +#else  /* CONFIG_VSERVER_DEBUG */
13622 +
13623 +#define vx_debug_switch 0
13624 +#define vx_debug_xid   0
13625 +#define vx_debug_nid   0
13626 +#define vx_debug_tag   0
13627 +#define vx_debug_net   0
13628 +#define vx_debug_limit 0
13629 +#define vx_debug_cres  0
13630 +#define vx_debug_dlim  0
13631 +#define vx_debug_cvirt 0
13632 +
13633 +#define vxdprintk(x...) do { } while (0)
13634 +#define vxlprintk(x...) do { } while (0)
13635 +#define vxfprintk(x...) do { } while (0)
13636 +
13637 +#endif /* CONFIG_VSERVER_DEBUG */
13638 +
13639 +
13640 +#ifdef CONFIG_VSERVER_WARN
13641 +
13642 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
13643 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
13644 +#define VX_WARN_XID    "[xid #%u] "
13645 +#define VX_WARN_NID    "[nid #%u] "
13646 +#define VX_WARN_TAG    "[tag #%u] "
13647 +
13648 +#define vxwprintk(c, f, x...)                                  \
13649 +       do {                                                    \
13650 +               if (c)                                          \
13651 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
13652 +       } while (0)
13653 +
13654 +#else  /* CONFIG_VSERVER_WARN */
13655 +
13656 +#define vxwprintk(x...) do { } while (0)
13657 +
13658 +#endif /* CONFIG_VSERVER_WARN */
13659 +
13660 +#define vxwprintk_task(c, f, x...)                             \
13661 +       vxwprintk(c, VX_WARN_TASK f,                            \
13662 +               current->comm, current->pid,                    \
13663 +               current->xid, current->nid, current->tag, ##x)
13664 +#define vxwprintk_xid(c, f, x...)                              \
13665 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
13666 +#define vxwprintk_nid(c, f, x...)                              \
13667 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
13668 +#define vxwprintk_tag(c, f, x...)                              \
13669 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
13670 +
13671 +#ifdef CONFIG_VSERVER_DEBUG
13672 +#define vxd_assert_lock(l)     assert_spin_locked(l)
13673 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
13674 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
13675 +#else
13676 +#define vxd_assert_lock(l)     do { } while (0)
13677 +#define vxd_assert(c, f, x...) do { } while (0)
13678 +#endif
13679 +
13680 +
13681 +#endif /* _VX_DEBUG_H */
13682 diff -NurpP --minimal linux-3.1/include/linux/vserver/debug_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/debug_cmd.h
13683 --- linux-3.1/include/linux/vserver/debug_cmd.h 1970-01-01 01:00:00.000000000 +0100
13684 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/debug_cmd.h     2011-10-24 18:53:33.000000000 +0200
13685 @@ -0,0 +1,58 @@
13686 +#ifndef _VX_DEBUG_CMD_H
13687 +#define _VX_DEBUG_CMD_H
13688 +
13689 +
13690 +/* debug commands */
13691 +
13692 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
13693 +
13694 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
13695 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
13696 +
13697 +struct  vcmd_read_history_v0 {
13698 +       uint32_t index;
13699 +       uint32_t count;
13700 +       char __user *data;
13701 +};
13702 +
13703 +struct  vcmd_read_monitor_v0 {
13704 +       uint32_t index;
13705 +       uint32_t count;
13706 +       char __user *data;
13707 +};
13708 +
13709 +
13710 +#ifdef __KERNEL__
13711 +
13712 +#ifdef CONFIG_COMPAT
13713 +
13714 +#include <asm/compat.h>
13715 +
13716 +struct vcmd_read_history_v0_x32 {
13717 +       uint32_t index;
13718 +       uint32_t count;
13719 +       compat_uptr_t data_ptr;
13720 +};
13721 +
13722 +struct vcmd_read_monitor_v0_x32 {
13723 +       uint32_t index;
13724 +       uint32_t count;
13725 +       compat_uptr_t data_ptr;
13726 +};
13727 +
13728 +#endif  /* CONFIG_COMPAT */
13729 +
13730 +extern int vc_dump_history(uint32_t);
13731 +
13732 +extern int vc_read_history(uint32_t, void __user *);
13733 +extern int vc_read_monitor(uint32_t, void __user *);
13734 +
13735 +#ifdef CONFIG_COMPAT
13736 +
13737 +extern int vc_read_history_x32(uint32_t, void __user *);
13738 +extern int vc_read_monitor_x32(uint32_t, void __user *);
13739 +
13740 +#endif  /* CONFIG_COMPAT */
13741 +
13742 +#endif /* __KERNEL__ */
13743 +#endif /* _VX_DEBUG_CMD_H */
13744 diff -NurpP --minimal linux-3.1/include/linux/vserver/device.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/device.h
13745 --- linux-3.1/include/linux/vserver/device.h    1970-01-01 01:00:00.000000000 +0100
13746 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/device.h        2011-10-24 18:53:33.000000000 +0200
13747 @@ -0,0 +1,15 @@
13748 +#ifndef _VX_DEVICE_H
13749 +#define _VX_DEVICE_H
13750 +
13751 +
13752 +#define DATTR_CREATE   0x00000001
13753 +#define DATTR_OPEN     0x00000002
13754 +
13755 +#define DATTR_REMAP    0x00000010
13756 +
13757 +#define DATTR_MASK     0x00000013
13758 +
13759 +
13760 +#else  /* _VX_DEVICE_H */
13761 +#warning duplicate inclusion
13762 +#endif /* _VX_DEVICE_H */
13763 diff -NurpP --minimal linux-3.1/include/linux/vserver/device_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/device_cmd.h
13764 --- linux-3.1/include/linux/vserver/device_cmd.h        1970-01-01 01:00:00.000000000 +0100
13765 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/device_cmd.h    2011-10-24 18:53:33.000000000 +0200
13766 @@ -0,0 +1,44 @@
13767 +#ifndef _VX_DEVICE_CMD_H
13768 +#define _VX_DEVICE_CMD_H
13769 +
13770 +
13771 +/*  device vserver commands */
13772 +
13773 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
13774 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
13775 +
13776 +struct vcmd_set_mapping_v0 {
13777 +       const char __user *device;
13778 +       const char __user *target;
13779 +       uint32_t flags;
13780 +};
13781 +
13782 +
13783 +#ifdef __KERNEL__
13784 +
13785 +#ifdef CONFIG_COMPAT
13786 +
13787 +#include <asm/compat.h>
13788 +
13789 +struct vcmd_set_mapping_v0_x32 {
13790 +       compat_uptr_t device_ptr;
13791 +       compat_uptr_t target_ptr;
13792 +       uint32_t flags;
13793 +};
13794 +
13795 +#endif /* CONFIG_COMPAT */
13796 +
13797 +#include <linux/compiler.h>
13798 +
13799 +extern int vc_set_mapping(struct vx_info *, void __user *);
13800 +extern int vc_unset_mapping(struct vx_info *, void __user *);
13801 +
13802 +#ifdef CONFIG_COMPAT
13803 +
13804 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
13805 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
13806 +
13807 +#endif /* CONFIG_COMPAT */
13808 +
13809 +#endif /* __KERNEL__ */
13810 +#endif /* _VX_DEVICE_CMD_H */
13811 diff -NurpP --minimal linux-3.1/include/linux/vserver/device_def.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/device_def.h
13812 --- linux-3.1/include/linux/vserver/device_def.h        1970-01-01 01:00:00.000000000 +0100
13813 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/device_def.h    2011-10-24 18:53:33.000000000 +0200
13814 @@ -0,0 +1,17 @@
13815 +#ifndef _VX_DEVICE_DEF_H
13816 +#define _VX_DEVICE_DEF_H
13817 +
13818 +#include <linux/types.h>
13819 +
13820 +struct vx_dmap_target {
13821 +       dev_t target;
13822 +       uint32_t flags;
13823 +};
13824 +
13825 +struct _vx_device {
13826 +#ifdef CONFIG_VSERVER_DEVICE
13827 +       struct vx_dmap_target targets[2];
13828 +#endif
13829 +};
13830 +
13831 +#endif /* _VX_DEVICE_DEF_H */
13832 diff -NurpP --minimal linux-3.1/include/linux/vserver/dlimit.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/dlimit.h
13833 --- linux-3.1/include/linux/vserver/dlimit.h    1970-01-01 01:00:00.000000000 +0100
13834 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/dlimit.h        2011-10-24 18:53:33.000000000 +0200
13835 @@ -0,0 +1,54 @@
13836 +#ifndef _VX_DLIMIT_H
13837 +#define _VX_DLIMIT_H
13838 +
13839 +#include "switch.h"
13840 +
13841 +
13842 +#ifdef __KERNEL__
13843 +
13844 +/*      keep in sync with CDLIM_INFINITY       */
13845 +
13846 +#define DLIM_INFINITY          (~0ULL)
13847 +
13848 +#include <linux/spinlock.h>
13849 +#include <linux/rcupdate.h>
13850 +
13851 +struct super_block;
13852 +
13853 +struct dl_info {
13854 +       struct hlist_node dl_hlist;             /* linked list of contexts */
13855 +       struct rcu_head dl_rcu;                 /* the rcu head */
13856 +       tag_t dl_tag;                           /* context tag */
13857 +       atomic_t dl_usecnt;                     /* usage count */
13858 +       atomic_t dl_refcnt;                     /* reference count */
13859 +
13860 +       struct super_block *dl_sb;              /* associated superblock */
13861 +
13862 +       spinlock_t dl_lock;                     /* protect the values */
13863 +
13864 +       unsigned long long dl_space_used;       /* used space in bytes */
13865 +       unsigned long long dl_space_total;      /* maximum space in bytes */
13866 +       unsigned long dl_inodes_used;           /* used inodes */
13867 +       unsigned long dl_inodes_total;          /* maximum inodes */
13868 +
13869 +       unsigned int dl_nrlmult;                /* non root limit mult */
13870 +};
13871 +
13872 +struct rcu_head;
13873 +
13874 +extern void rcu_free_dl_info(struct rcu_head *);
13875 +extern void unhash_dl_info(struct dl_info *);
13876 +
13877 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
13878 +
13879 +
13880 +struct kstatfs;
13881 +
13882 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
13883 +
13884 +typedef uint64_t dlsize_t;
13885 +
13886 +#endif /* __KERNEL__ */
13887 +#else  /* _VX_DLIMIT_H */
13888 +#warning duplicate inclusion
13889 +#endif /* _VX_DLIMIT_H */
13890 diff -NurpP --minimal linux-3.1/include/linux/vserver/dlimit_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/dlimit_cmd.h
13891 --- linux-3.1/include/linux/vserver/dlimit_cmd.h        1970-01-01 01:00:00.000000000 +0100
13892 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/dlimit_cmd.h    2011-10-24 18:53:33.000000000 +0200
13893 @@ -0,0 +1,109 @@
13894 +#ifndef _VX_DLIMIT_CMD_H
13895 +#define _VX_DLIMIT_CMD_H
13896 +
13897 +
13898 +/*  dlimit vserver commands */
13899 +
13900 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13901 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13902 +
13903 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13904 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13905 +
13906 +struct vcmd_ctx_dlimit_base_v0 {
13907 +       const char __user *name;
13908 +       uint32_t flags;
13909 +};
13910 +
13911 +struct vcmd_ctx_dlimit_v0 {
13912 +       const char __user *name;
13913 +       uint32_t space_used;                    /* used space in kbytes */
13914 +       uint32_t space_total;                   /* maximum space in kbytes */
13915 +       uint32_t inodes_used;                   /* used inodes */
13916 +       uint32_t inodes_total;                  /* maximum inodes */
13917 +       uint32_t reserved;                      /* reserved for root in % */
13918 +       uint32_t flags;
13919 +};
13920 +
13921 +#define CDLIM_UNSET            ((uint32_t)0UL)
13922 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13923 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13924 +
13925 +#define DLIME_UNIT     0
13926 +#define DLIME_KILO     1
13927 +#define DLIME_MEGA     2
13928 +#define DLIME_GIGA     3
13929 +
13930 +#define DLIMF_SHIFT    0x10
13931 +
13932 +#define DLIMS_USED     0
13933 +#define DLIMS_TOTAL    2
13934 +
13935 +static inline
13936 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13937 +{
13938 +       int exp = (flags & DLIMF_SHIFT) ?
13939 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13940 +       return ((uint64_t)val) << (10 * exp);
13941 +}
13942 +
13943 +static inline
13944 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13945 +{
13946 +       int exp = 0;
13947 +
13948 +       if (*flags & DLIMF_SHIFT) {
13949 +               while (val > (1LL << 32) && (exp < 3)) {
13950 +                       val >>= 10;
13951 +                       exp++;
13952 +               }
13953 +               *flags &= ~(DLIME_GIGA << shift);
13954 +               *flags |= exp << shift;
13955 +       } else
13956 +               val >>= 10;
13957 +       return val;
13958 +}
13959 +
13960 +#ifdef __KERNEL__
13961 +
13962 +#ifdef CONFIG_COMPAT
13963 +
13964 +#include <asm/compat.h>
13965 +
13966 +struct vcmd_ctx_dlimit_base_v0_x32 {
13967 +       compat_uptr_t name_ptr;
13968 +       uint32_t flags;
13969 +};
13970 +
13971 +struct vcmd_ctx_dlimit_v0_x32 {
13972 +       compat_uptr_t name_ptr;
13973 +       uint32_t space_used;                    /* used space in kbytes */
13974 +       uint32_t space_total;                   /* maximum space in kbytes */
13975 +       uint32_t inodes_used;                   /* used inodes */
13976 +       uint32_t inodes_total;                  /* maximum inodes */
13977 +       uint32_t reserved;                      /* reserved for root in % */
13978 +       uint32_t flags;
13979 +};
13980 +
13981 +#endif /* CONFIG_COMPAT */
13982 +
13983 +#include <linux/compiler.h>
13984 +
13985 +extern int vc_add_dlimit(uint32_t, void __user *);
13986 +extern int vc_rem_dlimit(uint32_t, void __user *);
13987 +
13988 +extern int vc_set_dlimit(uint32_t, void __user *);
13989 +extern int vc_get_dlimit(uint32_t, void __user *);
13990 +
13991 +#ifdef CONFIG_COMPAT
13992 +
13993 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
13994 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
13995 +
13996 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
13997 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
13998 +
13999 +#endif /* CONFIG_COMPAT */
14000 +
14001 +#endif /* __KERNEL__ */
14002 +#endif /* _VX_DLIMIT_CMD_H */
14003 diff -NurpP --minimal linux-3.1/include/linux/vserver/global.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/global.h
14004 --- linux-3.1/include/linux/vserver/global.h    1970-01-01 01:00:00.000000000 +0100
14005 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/global.h        2011-10-24 18:53:33.000000000 +0200
14006 @@ -0,0 +1,19 @@
14007 +#ifndef _VX_GLOBAL_H
14008 +#define _VX_GLOBAL_H
14009 +
14010 +
14011 +extern atomic_t vx_global_ctotal;
14012 +extern atomic_t vx_global_cactive;
14013 +
14014 +extern atomic_t nx_global_ctotal;
14015 +extern atomic_t nx_global_cactive;
14016 +
14017 +extern atomic_t vs_global_nsproxy;
14018 +extern atomic_t vs_global_fs;
14019 +extern atomic_t vs_global_mnt_ns;
14020 +extern atomic_t vs_global_uts_ns;
14021 +extern atomic_t vs_global_user_ns;
14022 +extern atomic_t vs_global_pid_ns;
14023 +
14024 +
14025 +#endif /* _VX_GLOBAL_H */
14026 diff -NurpP --minimal linux-3.1/include/linux/vserver/history.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/history.h
14027 --- linux-3.1/include/linux/vserver/history.h   1970-01-01 01:00:00.000000000 +0100
14028 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/history.h       2011-10-24 18:53:33.000000000 +0200
14029 @@ -0,0 +1,197 @@
14030 +#ifndef _VX_HISTORY_H
14031 +#define _VX_HISTORY_H
14032 +
14033 +
14034 +enum {
14035 +       VXH_UNUSED = 0,
14036 +       VXH_THROW_OOPS = 1,
14037 +
14038 +       VXH_GET_VX_INFO,
14039 +       VXH_PUT_VX_INFO,
14040 +       VXH_INIT_VX_INFO,
14041 +       VXH_SET_VX_INFO,
14042 +       VXH_CLR_VX_INFO,
14043 +       VXH_CLAIM_VX_INFO,
14044 +       VXH_RELEASE_VX_INFO,
14045 +       VXH_ALLOC_VX_INFO,
14046 +       VXH_DEALLOC_VX_INFO,
14047 +       VXH_HASH_VX_INFO,
14048 +       VXH_UNHASH_VX_INFO,
14049 +       VXH_LOC_VX_INFO,
14050 +       VXH_LOOKUP_VX_INFO,
14051 +       VXH_CREATE_VX_INFO,
14052 +};
14053 +
14054 +struct _vxhe_vxi {
14055 +       struct vx_info *ptr;
14056 +       unsigned xid;
14057 +       unsigned usecnt;
14058 +       unsigned tasks;
14059 +};
14060 +
14061 +struct _vxhe_set_clr {
14062 +       void *data;
14063 +};
14064 +
14065 +struct _vxhe_loc_lookup {
14066 +       unsigned arg;
14067 +};
14068 +
14069 +struct _vx_hist_entry {
14070 +       void *loc;
14071 +       unsigned short seq;
14072 +       unsigned short type;
14073 +       struct _vxhe_vxi vxi;
14074 +       union {
14075 +               struct _vxhe_set_clr sc;
14076 +               struct _vxhe_loc_lookup ll;
14077 +       };
14078 +};
14079 +
14080 +#ifdef CONFIG_VSERVER_HISTORY
14081 +
14082 +extern unsigned volatile int vxh_active;
14083 +
14084 +struct _vx_hist_entry *vxh_advance(void *loc);
14085 +
14086 +
14087 +static inline
14088 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
14089 +{
14090 +       entry->vxi.ptr = vxi;
14091 +       if (vxi) {
14092 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
14093 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
14094 +               entry->vxi.xid = vxi->vx_id;
14095 +       }
14096 +}
14097 +
14098 +
14099 +#define        __HERE__ current_text_addr()
14100 +
14101 +#define __VXH_BODY(__type, __data, __here)     \
14102 +       struct _vx_hist_entry *entry;           \
14103 +                                               \
14104 +       preempt_disable();                      \
14105 +       entry = vxh_advance(__here);            \
14106 +       __data;                                 \
14107 +       entry->type = __type;                   \
14108 +       preempt_enable();
14109 +
14110 +
14111 +       /* pass vxi only */
14112 +
14113 +#define __VXH_SMPL                             \
14114 +       __vxh_copy_vxi(entry, vxi)
14115 +
14116 +static inline
14117 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
14118 +{
14119 +       __VXH_BODY(__type, __VXH_SMPL, __here)
14120 +}
14121 +
14122 +       /* pass vxi and data (void *) */
14123 +
14124 +#define __VXH_DATA                             \
14125 +       __vxh_copy_vxi(entry, vxi);             \
14126 +       entry->sc.data = data
14127 +
14128 +static inline
14129 +void   __vxh_data(struct vx_info *vxi, void *data,
14130 +                       int __type, void *__here)
14131 +{
14132 +       __VXH_BODY(__type, __VXH_DATA, __here)
14133 +}
14134 +
14135 +       /* pass vxi and arg (long) */
14136 +
14137 +#define __VXH_LONG                             \
14138 +       __vxh_copy_vxi(entry, vxi);             \
14139 +       entry->ll.arg = arg
14140 +
14141 +static inline
14142 +void   __vxh_long(struct vx_info *vxi, long arg,
14143 +                       int __type, void *__here)
14144 +{
14145 +       __VXH_BODY(__type, __VXH_LONG, __here)
14146 +}
14147 +
14148 +
14149 +static inline
14150 +void   __vxh_throw_oops(void *__here)
14151 +{
14152 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
14153 +       /* prevent further acquisition */
14154 +       vxh_active = 0;
14155 +}
14156 +
14157 +
14158 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
14159 +
14160 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
14161 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
14162 +
14163 +#define __vxh_init_vx_info(v, d, h) \
14164 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
14165 +#define __vxh_set_vx_info(v, d, h) \
14166 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
14167 +#define __vxh_clr_vx_info(v, d, h) \
14168 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
14169 +
14170 +#define __vxh_claim_vx_info(v, d, h) \
14171 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
14172 +#define __vxh_release_vx_info(v, d, h) \
14173 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
14174 +
14175 +#define vxh_alloc_vx_info(v) \
14176 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
14177 +#define vxh_dealloc_vx_info(v) \
14178 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
14179 +
14180 +#define vxh_hash_vx_info(v) \
14181 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
14182 +#define vxh_unhash_vx_info(v) \
14183 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
14184 +
14185 +#define vxh_loc_vx_info(v, l) \
14186 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
14187 +#define vxh_lookup_vx_info(v, l) \
14188 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
14189 +#define vxh_create_vx_info(v, l) \
14190 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
14191 +
14192 +extern void vxh_dump_history(void);
14193 +
14194 +
14195 +#else  /* CONFIG_VSERVER_HISTORY */
14196 +
14197 +#define        __HERE__        0
14198 +
14199 +#define vxh_throw_oops()               do { } while (0)
14200 +
14201 +#define __vxh_get_vx_info(v, h)                do { } while (0)
14202 +#define __vxh_put_vx_info(v, h)                do { } while (0)
14203 +
14204 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
14205 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
14206 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
14207 +
14208 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
14209 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
14210 +
14211 +#define vxh_alloc_vx_info(v)           do { } while (0)
14212 +#define vxh_dealloc_vx_info(v)         do { } while (0)
14213 +
14214 +#define vxh_hash_vx_info(v)            do { } while (0)
14215 +#define vxh_unhash_vx_info(v)          do { } while (0)
14216 +
14217 +#define vxh_loc_vx_info(v, l)          do { } while (0)
14218 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
14219 +#define vxh_create_vx_info(v, l)       do { } while (0)
14220 +
14221 +#define vxh_dump_history()             do { } while (0)
14222 +
14223 +
14224 +#endif /* CONFIG_VSERVER_HISTORY */
14225 +
14226 +#endif /* _VX_HISTORY_H */
14227 diff -NurpP --minimal linux-3.1/include/linux/vserver/inode.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/inode.h
14228 --- linux-3.1/include/linux/vserver/inode.h     1970-01-01 01:00:00.000000000 +0100
14229 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/inode.h 2011-10-24 18:53:33.000000000 +0200
14230 @@ -0,0 +1,39 @@
14231 +#ifndef _VX_INODE_H
14232 +#define _VX_INODE_H
14233 +
14234 +
14235 +#define IATTR_TAG      0x01000000
14236 +
14237 +#define IATTR_ADMIN    0x00000001
14238 +#define IATTR_WATCH    0x00000002
14239 +#define IATTR_HIDE     0x00000004
14240 +#define IATTR_FLAGS    0x00000007
14241 +
14242 +#define IATTR_BARRIER  0x00010000
14243 +#define IATTR_IXUNLINK 0x00020000
14244 +#define IATTR_IMMUTABLE 0x00040000
14245 +#define IATTR_COW      0x00080000
14246 +
14247 +#ifdef __KERNEL__
14248 +
14249 +
14250 +#ifdef CONFIG_VSERVER_PROC_SECURE
14251 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
14252 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14253 +#else
14254 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
14255 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14256 +#endif
14257 +
14258 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
14259 +
14260 +#endif /* __KERNEL__ */
14261 +
14262 +/* inode ioctls */
14263 +
14264 +#define FIOC_GETXFLG   _IOR('x', 5, long)
14265 +#define FIOC_SETXFLG   _IOW('x', 6, long)
14266 +
14267 +#else  /* _VX_INODE_H */
14268 +#warning duplicate inclusion
14269 +#endif /* _VX_INODE_H */
14270 diff -NurpP --minimal linux-3.1/include/linux/vserver/inode_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/inode_cmd.h
14271 --- linux-3.1/include/linux/vserver/inode_cmd.h 1970-01-01 01:00:00.000000000 +0100
14272 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/inode_cmd.h     2011-10-24 18:53:33.000000000 +0200
14273 @@ -0,0 +1,59 @@
14274 +#ifndef _VX_INODE_CMD_H
14275 +#define _VX_INODE_CMD_H
14276 +
14277 +
14278 +/*  inode vserver commands */
14279 +
14280 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
14281 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
14282 +
14283 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
14284 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
14285 +
14286 +struct vcmd_ctx_iattr_v1 {
14287 +       const char __user *name;
14288 +       uint32_t tag;
14289 +       uint32_t flags;
14290 +       uint32_t mask;
14291 +};
14292 +
14293 +struct vcmd_ctx_fiattr_v0 {
14294 +       uint32_t tag;
14295 +       uint32_t flags;
14296 +       uint32_t mask;
14297 +};
14298 +
14299 +
14300 +#ifdef __KERNEL__
14301 +
14302 +
14303 +#ifdef CONFIG_COMPAT
14304 +
14305 +#include <asm/compat.h>
14306 +
14307 +struct vcmd_ctx_iattr_v1_x32 {
14308 +       compat_uptr_t name_ptr;
14309 +       uint32_t tag;
14310 +       uint32_t flags;
14311 +       uint32_t mask;
14312 +};
14313 +
14314 +#endif /* CONFIG_COMPAT */
14315 +
14316 +#include <linux/compiler.h>
14317 +
14318 +extern int vc_get_iattr(void __user *);
14319 +extern int vc_set_iattr(void __user *);
14320 +
14321 +extern int vc_fget_iattr(uint32_t, void __user *);
14322 +extern int vc_fset_iattr(uint32_t, void __user *);
14323 +
14324 +#ifdef CONFIG_COMPAT
14325 +
14326 +extern int vc_get_iattr_x32(void __user *);
14327 +extern int vc_set_iattr_x32(void __user *);
14328 +
14329 +#endif /* CONFIG_COMPAT */
14330 +
14331 +#endif /* __KERNEL__ */
14332 +#endif /* _VX_INODE_CMD_H */
14333 diff -NurpP --minimal linux-3.1/include/linux/vserver/limit.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/limit.h
14334 --- linux-3.1/include/linux/vserver/limit.h     1970-01-01 01:00:00.000000000 +0100
14335 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/limit.h 2011-10-24 18:53:33.000000000 +0200
14336 @@ -0,0 +1,71 @@
14337 +#ifndef _VX_LIMIT_H
14338 +#define _VX_LIMIT_H
14339 +
14340 +#define VLIMIT_NSOCK   16
14341 +#define VLIMIT_OPENFD  17
14342 +#define VLIMIT_ANON    18
14343 +#define VLIMIT_SHMEM   19
14344 +#define VLIMIT_SEMARY  20
14345 +#define VLIMIT_NSEMS   21
14346 +#define VLIMIT_DENTRY  22
14347 +#define VLIMIT_MAPPED  23
14348 +
14349 +
14350 +#ifdef __KERNEL__
14351 +
14352 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
14353 +
14354 +/*     keep in sync with CRLIM_INFINITY */
14355 +
14356 +#define        VLIM_INFINITY   (~0ULL)
14357 +
14358 +#include <asm/atomic.h>
14359 +#include <asm/resource.h>
14360 +
14361 +#ifndef RLIM_INFINITY
14362 +#warning RLIM_INFINITY is undefined
14363 +#endif
14364 +
14365 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
14366 +
14367 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
14368 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
14369 +
14370 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
14371 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
14372 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
14373 +
14374 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
14375 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
14376 +
14377 +typedef atomic_long_t rlim_atomic_t;
14378 +typedef unsigned long rlim_t;
14379 +
14380 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
14381 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
14382 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
14383 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
14384 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
14385 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
14386 +
14387 +
14388 +#if    (RLIM_INFINITY == VLIM_INFINITY)
14389 +#define        VX_VLIM(r) ((long long)(long)(r))
14390 +#define        VX_RLIM(v) ((rlim_t)(v))
14391 +#else
14392 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
14393 +               ? VLIM_INFINITY : (long long)(r))
14394 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
14395 +               ? RLIM_INFINITY : (rlim_t)(v))
14396 +#endif
14397 +
14398 +struct sysinfo;
14399 +
14400 +void vx_vsi_meminfo(struct sysinfo *);
14401 +void vx_vsi_swapinfo(struct sysinfo *);
14402 +long vx_vsi_cached(struct sysinfo *);
14403 +
14404 +#define NUM_LIMITS     24
14405 +
14406 +#endif /* __KERNEL__ */
14407 +#endif /* _VX_LIMIT_H */
14408 diff -NurpP --minimal linux-3.1/include/linux/vserver/limit_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/limit_cmd.h
14409 --- linux-3.1/include/linux/vserver/limit_cmd.h 1970-01-01 01:00:00.000000000 +0100
14410 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/limit_cmd.h     2011-10-24 18:53:33.000000000 +0200
14411 @@ -0,0 +1,71 @@
14412 +#ifndef _VX_LIMIT_CMD_H
14413 +#define _VX_LIMIT_CMD_H
14414 +
14415 +
14416 +/*  rlimit vserver commands */
14417 +
14418 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
14419 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
14420 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
14421 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
14422 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
14423 +
14424 +struct vcmd_ctx_rlimit_v0 {
14425 +       uint32_t id;
14426 +       uint64_t minimum;
14427 +       uint64_t softlimit;
14428 +       uint64_t maximum;
14429 +};
14430 +
14431 +struct vcmd_ctx_rlimit_mask_v0 {
14432 +       uint32_t minimum;
14433 +       uint32_t softlimit;
14434 +       uint32_t maximum;
14435 +};
14436 +
14437 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
14438 +
14439 +struct vcmd_rlimit_stat_v0 {
14440 +       uint32_t id;
14441 +       uint32_t hits;
14442 +       uint64_t value;
14443 +       uint64_t minimum;
14444 +       uint64_t maximum;
14445 +};
14446 +
14447 +#define CRLIM_UNSET            (0ULL)
14448 +#define CRLIM_INFINITY         (~0ULL)
14449 +#define CRLIM_KEEP             (~1ULL)
14450 +
14451 +#ifdef __KERNEL__
14452 +
14453 +#ifdef CONFIG_IA32_EMULATION
14454 +
14455 +struct vcmd_ctx_rlimit_v0_x32 {
14456 +       uint32_t id;
14457 +       uint64_t minimum;
14458 +       uint64_t softlimit;
14459 +       uint64_t maximum;
14460 +} __attribute__ ((packed));
14461 +
14462 +#endif /* CONFIG_IA32_EMULATION */
14463 +
14464 +#include <linux/compiler.h>
14465 +
14466 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
14467 +extern int vc_get_rlimit(struct vx_info *, void __user *);
14468 +extern int vc_set_rlimit(struct vx_info *, void __user *);
14469 +extern int vc_reset_hits(struct vx_info *, void __user *);
14470 +extern int vc_reset_minmax(struct vx_info *, void __user *);
14471 +
14472 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
14473 +
14474 +#ifdef CONFIG_IA32_EMULATION
14475 +
14476 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
14477 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
14478 +
14479 +#endif /* CONFIG_IA32_EMULATION */
14480 +
14481 +#endif /* __KERNEL__ */
14482 +#endif /* _VX_LIMIT_CMD_H */
14483 diff -NurpP --minimal linux-3.1/include/linux/vserver/limit_def.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/limit_def.h
14484 --- linux-3.1/include/linux/vserver/limit_def.h 1970-01-01 01:00:00.000000000 +0100
14485 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/limit_def.h     2011-10-24 18:53:33.000000000 +0200
14486 @@ -0,0 +1,47 @@
14487 +#ifndef _VX_LIMIT_DEF_H
14488 +#define _VX_LIMIT_DEF_H
14489 +
14490 +#include <asm/atomic.h>
14491 +#include <asm/resource.h>
14492 +
14493 +#include "limit.h"
14494 +
14495 +
14496 +struct _vx_res_limit {
14497 +       rlim_t soft;            /* Context soft limit */
14498 +       rlim_t hard;            /* Context hard limit */
14499 +
14500 +       rlim_atomic_t rcur;     /* Current value */
14501 +       rlim_t rmin;            /* Context minimum */
14502 +       rlim_t rmax;            /* Context maximum */
14503 +
14504 +       atomic_t lhit;          /* Limit hits */
14505 +};
14506 +
14507 +/* context sub struct */
14508 +
14509 +struct _vx_limit {
14510 +       struct _vx_res_limit res[NUM_LIMITS];
14511 +};
14512 +
14513 +#ifdef CONFIG_VSERVER_DEBUG
14514 +
14515 +static inline void __dump_vx_limit(struct _vx_limit *limit)
14516 +{
14517 +       int i;
14518 +
14519 +       printk("\t_vx_limit:");
14520 +       for (i = 0; i < NUM_LIMITS; i++) {
14521 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
14522 +                       i, (unsigned long)__rlim_get(limit, i),
14523 +                       (unsigned long)__rlim_rmin(limit, i),
14524 +                       (unsigned long)__rlim_rmax(limit, i),
14525 +                       (long)__rlim_soft(limit, i),
14526 +                       (long)__rlim_hard(limit, i),
14527 +                       atomic_read(&__rlim_lhit(limit, i)));
14528 +       }
14529 +}
14530 +
14531 +#endif
14532 +
14533 +#endif /* _VX_LIMIT_DEF_H */
14534 diff -NurpP --minimal linux-3.1/include/linux/vserver/limit_int.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/limit_int.h
14535 --- linux-3.1/include/linux/vserver/limit_int.h 1970-01-01 01:00:00.000000000 +0100
14536 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/limit_int.h     2011-10-24 18:53:33.000000000 +0200
14537 @@ -0,0 +1,198 @@
14538 +#ifndef _VX_LIMIT_INT_H
14539 +#define _VX_LIMIT_INT_H
14540 +
14541 +#include "context.h"
14542 +
14543 +#ifdef __KERNEL__
14544 +
14545 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
14546 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
14547 +
14548 +extern const char *vlimit_name[NUM_LIMITS];
14549 +
14550 +static inline void __vx_acc_cres(struct vx_info *vxi,
14551 +       int res, int dir, void *_data, char *_file, int _line)
14552 +{
14553 +       if (VXD_RCRES_COND(res))
14554 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
14555 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14556 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14557 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
14558 +       if (!vxi)
14559 +               return;
14560 +
14561 +       if (dir > 0)
14562 +               __rlim_inc(&vxi->limit, res);
14563 +       else
14564 +               __rlim_dec(&vxi->limit, res);
14565 +}
14566 +
14567 +static inline void __vx_add_cres(struct vx_info *vxi,
14568 +       int res, int amount, void *_data, char *_file, int _line)
14569 +{
14570 +       if (VXD_RCRES_COND(res))
14571 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
14572 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14573 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14574 +                       amount, _data, _file, _line);
14575 +       if (amount == 0)
14576 +               return;
14577 +       if (!vxi)
14578 +               return;
14579 +       __rlim_add(&vxi->limit, res, amount);
14580 +}
14581 +
14582 +static inline
14583 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
14584 +{
14585 +       int cond = (value > __rlim_rmax(limit, res));
14586 +
14587 +       if (cond)
14588 +               __rlim_rmax(limit, res) = value;
14589 +       return cond;
14590 +}
14591 +
14592 +static inline
14593 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
14594 +{
14595 +       int cond = (value < __rlim_rmin(limit, res));
14596 +
14597 +       if (cond)
14598 +               __rlim_rmin(limit, res) = value;
14599 +       return cond;
14600 +}
14601 +
14602 +static inline
14603 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
14604 +{
14605 +       if (!__vx_cres_adjust_max(limit, res, value))
14606 +               __vx_cres_adjust_min(limit, res, value);
14607 +}
14608 +
14609 +
14610 +/*     return values:
14611 +        +1 ... no limit hit
14612 +        -1 ... over soft limit
14613 +         0 ... over hard limit         */
14614 +
14615 +static inline int __vx_cres_avail(struct vx_info *vxi,
14616 +       int res, int num, char *_file, int _line)
14617 +{
14618 +       struct _vx_limit *limit;
14619 +       rlim_t value;
14620 +
14621 +       if (VXD_RLIMIT_COND(res))
14622 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
14623 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14624 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
14625 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
14626 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14627 +                       num, _file, _line);
14628 +       if (!vxi)
14629 +               return 1;
14630 +
14631 +       limit = &vxi->limit;
14632 +       value = __rlim_get(limit, res);
14633 +
14634 +       if (!__vx_cres_adjust_max(limit, res, value))
14635 +               __vx_cres_adjust_min(limit, res, value);
14636 +
14637 +       if (num == 0)
14638 +               return 1;
14639 +
14640 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
14641 +               return -1;
14642 +       if (value + num <= __rlim_soft(limit, res))
14643 +               return -1;
14644 +
14645 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
14646 +               return 1;
14647 +       if (value + num <= __rlim_hard(limit, res))
14648 +               return 1;
14649 +
14650 +       __rlim_hit(limit, res);
14651 +       return 0;
14652 +}
14653 +
14654 +
14655 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
14656 +
14657 +static inline
14658 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
14659 +{
14660 +       rlim_t value, sum = 0;
14661 +       int res;
14662 +
14663 +       while ((res = *array++)) {
14664 +               value = __rlim_get(limit, res);
14665 +               __vx_cres_fixup(limit, res, value);
14666 +               sum += value;
14667 +       }
14668 +       return sum;
14669 +}
14670 +
14671 +static inline
14672 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
14673 +{
14674 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
14675 +       int res = *array;
14676 +
14677 +       if (value == __rlim_get(limit, res))
14678 +               return value;
14679 +
14680 +       __rlim_set(limit, res, value);
14681 +       /* now adjust min/max */
14682 +       if (!__vx_cres_adjust_max(limit, res, value))
14683 +               __vx_cres_adjust_min(limit, res, value);
14684 +
14685 +       return value;
14686 +}
14687 +
14688 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
14689 +       const int *array, int num, char *_file, int _line)
14690 +{
14691 +       struct _vx_limit *limit;
14692 +       rlim_t value = 0;
14693 +       int res;
14694 +
14695 +       if (num == 0)
14696 +               return 1;
14697 +       if (!vxi)
14698 +               return 1;
14699 +
14700 +       limit = &vxi->limit;
14701 +       res = *array;
14702 +       value = __vx_cres_array_sum(limit, array + 1);
14703 +
14704 +       __rlim_set(limit, res, value);
14705 +       __vx_cres_fixup(limit, res, value);
14706 +
14707 +       return __vx_cres_avail(vxi, res, num, _file, _line);
14708 +}
14709 +
14710 +
14711 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
14712 +{
14713 +       rlim_t value;
14714 +       int res;
14715 +
14716 +       /* complex resources first */
14717 +       if ((id < 0) || (id == RLIMIT_RSS))
14718 +               __vx_cres_array_fixup(limit, VLA_RSS);
14719 +
14720 +       for (res = 0; res < NUM_LIMITS; res++) {
14721 +               if ((id > 0) && (res != id))
14722 +                       continue;
14723 +
14724 +               value = __rlim_get(limit, res);
14725 +               __vx_cres_fixup(limit, res, value);
14726 +
14727 +               /* not supposed to happen, maybe warn? */
14728 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
14729 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
14730 +       }
14731 +}
14732 +
14733 +
14734 +#endif /* __KERNEL__ */
14735 +#endif /* _VX_LIMIT_INT_H */
14736 diff -NurpP --minimal linux-3.1/include/linux/vserver/monitor.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/monitor.h
14737 --- linux-3.1/include/linux/vserver/monitor.h   1970-01-01 01:00:00.000000000 +0100
14738 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/monitor.h       2011-10-24 18:53:33.000000000 +0200
14739 @@ -0,0 +1,96 @@
14740 +#ifndef _VX_MONITOR_H
14741 +#define _VX_MONITOR_H
14742 +
14743 +#include <linux/types.h>
14744 +
14745 +enum {
14746 +       VXM_UNUSED = 0,
14747 +
14748 +       VXM_SYNC = 0x10,
14749 +
14750 +       VXM_UPDATE = 0x20,
14751 +       VXM_UPDATE_1,
14752 +       VXM_UPDATE_2,
14753 +
14754 +       VXM_RQINFO_1 = 0x24,
14755 +       VXM_RQINFO_2,
14756 +
14757 +       VXM_ACTIVATE = 0x40,
14758 +       VXM_DEACTIVATE,
14759 +       VXM_IDLE,
14760 +
14761 +       VXM_HOLD = 0x44,
14762 +       VXM_UNHOLD,
14763 +
14764 +       VXM_MIGRATE = 0x48,
14765 +       VXM_RESCHED,
14766 +
14767 +       /* all other bits are flags */
14768 +       VXM_SCHED = 0x80,
14769 +};
14770 +
14771 +struct _vxm_update_1 {
14772 +       uint32_t tokens_max;
14773 +       uint32_t fill_rate;
14774 +       uint32_t interval;
14775 +};
14776 +
14777 +struct _vxm_update_2 {
14778 +       uint32_t tokens_min;
14779 +       uint32_t fill_rate;
14780 +       uint32_t interval;
14781 +};
14782 +
14783 +struct _vxm_rqinfo_1 {
14784 +       uint16_t running;
14785 +       uint16_t onhold;
14786 +       uint16_t iowait;
14787 +       uint16_t uintr;
14788 +       uint32_t idle_tokens;
14789 +};
14790 +
14791 +struct _vxm_rqinfo_2 {
14792 +       uint32_t norm_time;
14793 +       uint32_t idle_time;
14794 +       uint32_t idle_skip;
14795 +};
14796 +
14797 +struct _vxm_sched {
14798 +       uint32_t tokens;
14799 +       uint32_t norm_time;
14800 +       uint32_t idle_time;
14801 +};
14802 +
14803 +struct _vxm_task {
14804 +       uint16_t pid;
14805 +       uint16_t state;
14806 +};
14807 +
14808 +struct _vxm_event {
14809 +       uint32_t jif;
14810 +       union {
14811 +               uint32_t seq;
14812 +               uint32_t sec;
14813 +       };
14814 +       union {
14815 +               uint32_t tokens;
14816 +               uint32_t nsec;
14817 +               struct _vxm_task tsk;
14818 +       };
14819 +};
14820 +
14821 +struct _vx_mon_entry {
14822 +       uint16_t type;
14823 +       uint16_t xid;
14824 +       union {
14825 +               struct _vxm_event ev;
14826 +               struct _vxm_sched sd;
14827 +               struct _vxm_update_1 u1;
14828 +               struct _vxm_update_2 u2;
14829 +               struct _vxm_rqinfo_1 q1;
14830 +               struct _vxm_rqinfo_2 q2;
14831 +       };
14832 +};
14833 +
14834 +
14835 +#endif /* _VX_MONITOR_H */
14836 diff -NurpP --minimal linux-3.1/include/linux/vserver/network.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/network.h
14837 --- linux-3.1/include/linux/vserver/network.h   1970-01-01 01:00:00.000000000 +0100
14838 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/network.h       2011-10-24 18:53:33.000000000 +0200
14839 @@ -0,0 +1,148 @@
14840 +#ifndef _VX_NETWORK_H
14841 +#define _VX_NETWORK_H
14842 +
14843 +#include <linux/types.h>
14844 +
14845 +
14846 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
14847 +
14848 +
14849 +/* network flags */
14850 +
14851 +#define NXF_INFO_PRIVATE       0x00000008
14852 +
14853 +#define NXF_SINGLE_IP          0x00000100
14854 +#define NXF_LBACK_REMAP                0x00000200
14855 +#define NXF_LBACK_ALLOW                0x00000400
14856 +
14857 +#define NXF_HIDE_NETIF         0x02000000
14858 +#define NXF_HIDE_LBACK         0x04000000
14859 +
14860 +#define NXF_STATE_SETUP                (1ULL << 32)
14861 +#define NXF_STATE_ADMIN                (1ULL << 34)
14862 +
14863 +#define NXF_SC_HELPER          (1ULL << 36)
14864 +#define NXF_PERSISTENT         (1ULL << 38)
14865 +
14866 +#define NXF_ONE_TIME           (0x0005ULL << 32)
14867 +
14868 +
14869 +#define        NXF_INIT_SET            (__nxf_init_set())
14870 +
14871 +static inline uint64_t __nxf_init_set(void) {
14872 +       return    NXF_STATE_ADMIN
14873 +#ifdef CONFIG_VSERVER_AUTO_LBACK
14874 +               | NXF_LBACK_REMAP
14875 +               | NXF_HIDE_LBACK
14876 +#endif
14877 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
14878 +               | NXF_SINGLE_IP
14879 +#endif
14880 +               | NXF_HIDE_NETIF;
14881 +}
14882 +
14883 +
14884 +/* network caps */
14885 +
14886 +#define NXC_TUN_CREATE         0x00000001
14887 +
14888 +#define NXC_RAW_ICMP           0x00000100
14889 +
14890 +#define NXC_MULTICAST          0x00001000
14891 +
14892 +
14893 +/* address types */
14894 +
14895 +#define NXA_TYPE_IPV4          0x0001
14896 +#define NXA_TYPE_IPV6          0x0002
14897 +
14898 +#define NXA_TYPE_NONE          0x0000
14899 +#define NXA_TYPE_ANY           0x00FF
14900 +
14901 +#define NXA_TYPE_ADDR          0x0010
14902 +#define NXA_TYPE_MASK          0x0020
14903 +#define NXA_TYPE_RANGE         0x0040
14904 +
14905 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
14906 +
14907 +#define NXA_MOD_BCAST          0x0100
14908 +#define NXA_MOD_LBACK          0x0200
14909 +
14910 +#define NXA_LOOPBACK           0x1000
14911 +
14912 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
14913 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
14914 +
14915 +#ifdef __KERNEL__
14916 +
14917 +#include <linux/list.h>
14918 +#include <linux/spinlock.h>
14919 +#include <linux/rcupdate.h>
14920 +#include <linux/in.h>
14921 +#include <linux/in6.h>
14922 +#include <asm/atomic.h>
14923 +
14924 +struct nx_addr_v4 {
14925 +       struct nx_addr_v4 *next;
14926 +       struct in_addr ip[2];
14927 +       struct in_addr mask;
14928 +       uint16_t type;
14929 +       uint16_t flags;
14930 +};
14931 +
14932 +struct nx_addr_v6 {
14933 +       struct nx_addr_v6 *next;
14934 +       struct in6_addr ip;
14935 +       struct in6_addr mask;
14936 +       uint32_t prefix;
14937 +       uint16_t type;
14938 +       uint16_t flags;
14939 +};
14940 +
14941 +struct nx_info {
14942 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
14943 +       nid_t nx_id;                    /* vnet id */
14944 +       atomic_t nx_usecnt;             /* usage count */
14945 +       atomic_t nx_tasks;              /* tasks count */
14946 +       int nx_state;                   /* context state */
14947 +
14948 +       uint64_t nx_flags;              /* network flag word */
14949 +       uint64_t nx_ncaps;              /* network capabilities */
14950 +
14951 +       struct in_addr v4_lback;        /* Loopback address */
14952 +       struct in_addr v4_bcast;        /* Broadcast address */
14953 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
14954 +#ifdef CONFIG_IPV6
14955 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
14956 +#endif
14957 +       char nx_name[65];               /* network context name */
14958 +};
14959 +
14960 +
14961 +/* status flags */
14962 +
14963 +#define NXS_HASHED      0x0001
14964 +#define NXS_SHUTDOWN    0x0100
14965 +#define NXS_RELEASED    0x8000
14966 +
14967 +extern struct nx_info *lookup_nx_info(int);
14968 +
14969 +extern int get_nid_list(int, unsigned int *, int);
14970 +extern int nid_is_hashed(nid_t);
14971 +
14972 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
14973 +
14974 +extern long vs_net_change(struct nx_info *, unsigned int);
14975 +
14976 +struct sock;
14977 +
14978 +
14979 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
14980 +#ifdef  CONFIG_IPV6
14981 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
14982 +#else
14983 +#define NX_IPV6(n)     (0)
14984 +#endif
14985 +
14986 +#endif /* __KERNEL__ */
14987 +#endif /* _VX_NETWORK_H */
14988 diff -NurpP --minimal linux-3.1/include/linux/vserver/network_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/network_cmd.h
14989 --- linux-3.1/include/linux/vserver/network_cmd.h       1970-01-01 01:00:00.000000000 +0100
14990 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/network_cmd.h   2011-10-24 18:53:33.000000000 +0200
14991 @@ -0,0 +1,164 @@
14992 +#ifndef _VX_NETWORK_CMD_H
14993 +#define _VX_NETWORK_CMD_H
14994 +
14995 +
14996 +/* vinfo commands */
14997 +
14998 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
14999 +
15000 +#ifdef __KERNEL__
15001 +extern int vc_task_nid(uint32_t);
15002 +
15003 +#endif /* __KERNEL__ */
15004 +
15005 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
15006 +
15007 +struct vcmd_nx_info_v0 {
15008 +       uint32_t nid;
15009 +       /* more to come */
15010 +};
15011 +
15012 +#ifdef __KERNEL__
15013 +extern int vc_nx_info(struct nx_info *, void __user *);
15014 +
15015 +#endif /* __KERNEL__ */
15016 +
15017 +#include <linux/in.h>
15018 +#include <linux/in6.h>
15019 +
15020 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
15021 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
15022 +
15023 +struct  vcmd_net_create {
15024 +       uint64_t flagword;
15025 +};
15026 +
15027 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
15028 +
15029 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
15030 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
15031 +
15032 +struct vcmd_net_addr_v0 {
15033 +       uint16_t type;
15034 +       uint16_t count;
15035 +       struct in_addr ip[4];
15036 +       struct in_addr mask[4];
15037 +};
15038 +
15039 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
15040 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
15041 +
15042 +struct vcmd_net_addr_ipv4_v1 {
15043 +       uint16_t type;
15044 +       uint16_t flags;
15045 +       struct in_addr ip;
15046 +       struct in_addr mask;
15047 +};
15048 +
15049 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
15050 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
15051 +
15052 +struct vcmd_net_addr_ipv4_v2 {
15053 +       uint16_t type;
15054 +       uint16_t flags;
15055 +       struct in_addr ip;
15056 +       struct in_addr ip2;
15057 +       struct in_addr mask;
15058 +};
15059 +
15060 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
15061 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
15062 +
15063 +struct vcmd_net_addr_ipv6_v1 {
15064 +       uint16_t type;
15065 +       uint16_t flags;
15066 +       uint32_t prefix;
15067 +       struct in6_addr ip;
15068 +       struct in6_addr mask;
15069 +};
15070 +
15071 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
15072 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
15073 +
15074 +struct vcmd_match_ipv4_v0 {
15075 +       uint16_t type;
15076 +       uint16_t flags;
15077 +       uint16_t parent;
15078 +       uint16_t prefix;
15079 +       struct in_addr ip;
15080 +       struct in_addr ip2;
15081 +       struct in_addr mask;
15082 +};
15083 +
15084 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
15085 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
15086 +
15087 +struct vcmd_match_ipv6_v0 {
15088 +       uint16_t type;
15089 +       uint16_t flags;
15090 +       uint16_t parent;
15091 +       uint16_t prefix;
15092 +       struct in6_addr ip;
15093 +       struct in6_addr ip2;
15094 +       struct in6_addr mask;
15095 +};
15096 +
15097 +
15098 +#ifdef __KERNEL__
15099 +extern int vc_net_create(uint32_t, void __user *);
15100 +extern int vc_net_migrate(struct nx_info *, void __user *);
15101 +
15102 +extern int vc_net_add(struct nx_info *, void __user *);
15103 +extern int vc_net_remove(struct nx_info *, void __user *);
15104 +
15105 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
15106 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
15107 +
15108 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
15109 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
15110 +
15111 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
15112 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
15113 +
15114 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
15115 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
15116 +
15117 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
15118 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
15119 +
15120 +#endif /* __KERNEL__ */
15121 +
15122 +
15123 +/* flag commands */
15124 +
15125 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
15126 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
15127 +
15128 +struct vcmd_net_flags_v0 {
15129 +       uint64_t flagword;
15130 +       uint64_t mask;
15131 +};
15132 +
15133 +#ifdef __KERNEL__
15134 +extern int vc_get_nflags(struct nx_info *, void __user *);
15135 +extern int vc_set_nflags(struct nx_info *, void __user *);
15136 +
15137 +#endif /* __KERNEL__ */
15138 +
15139 +
15140 +/* network caps commands */
15141 +
15142 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
15143 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
15144 +
15145 +struct vcmd_net_caps_v0 {
15146 +       uint64_t ncaps;
15147 +       uint64_t cmask;
15148 +};
15149 +
15150 +#ifdef __KERNEL__
15151 +extern int vc_get_ncaps(struct nx_info *, void __user *);
15152 +extern int vc_set_ncaps(struct nx_info *, void __user *);
15153 +
15154 +#endif /* __KERNEL__ */
15155 +#endif /* _VX_CONTEXT_CMD_H */
15156 diff -NurpP --minimal linux-3.1/include/linux/vserver/percpu.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/percpu.h
15157 --- linux-3.1/include/linux/vserver/percpu.h    1970-01-01 01:00:00.000000000 +0100
15158 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/percpu.h        2011-10-24 18:53:33.000000000 +0200
15159 @@ -0,0 +1,14 @@
15160 +#ifndef _VX_PERCPU_H
15161 +#define _VX_PERCPU_H
15162 +
15163 +#include "cvirt_def.h"
15164 +#include "sched_def.h"
15165 +
15166 +struct _vx_percpu {
15167 +       struct _vx_cvirt_pc cvirt;
15168 +       struct _vx_sched_pc sched;
15169 +};
15170 +
15171 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
15172 +
15173 +#endif /* _VX_PERCPU_H */
15174 diff -NurpP --minimal linux-3.1/include/linux/vserver/pid.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/pid.h
15175 --- linux-3.1/include/linux/vserver/pid.h       1970-01-01 01:00:00.000000000 +0100
15176 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/pid.h   2011-10-24 18:53:33.000000000 +0200
15177 @@ -0,0 +1,51 @@
15178 +#ifndef _VSERVER_PID_H
15179 +#define _VSERVER_PID_H
15180 +
15181 +/* pid faking stuff */
15182 +
15183 +#define vx_info_map_pid(v, p) \
15184 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
15185 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
15186 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
15187 +#define vx_map_tgid(p) vx_map_pid(p)
15188 +
15189 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
15190 +       const char *func, const char *file, int line)
15191 +{
15192 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
15193 +               vxfprintk(VXD_CBIT(cvirt, 2),
15194 +                       "vx_map_tgid: %p/%llx: %d -> %d",
15195 +                       vxi, (long long)vxi->vx_flags, pid,
15196 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
15197 +                       func, file, line);
15198 +               if (pid == 0)
15199 +                       return 0;
15200 +               if (pid == vxi->vx_initpid)
15201 +                       return 1;
15202 +       }
15203 +       return pid;
15204 +}
15205 +
15206 +#define vx_info_rmap_pid(v, p) \
15207 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
15208 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
15209 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
15210 +
15211 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
15212 +       const char *func, const char *file, int line)
15213 +{
15214 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
15215 +               vxfprintk(VXD_CBIT(cvirt, 2),
15216 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
15217 +                       vxi, (long long)vxi->vx_flags, pid,
15218 +                       (pid == 1) ? vxi->vx_initpid : pid,
15219 +                       func, file, line);
15220 +               if ((pid == 1) && vxi->vx_initpid)
15221 +                       return vxi->vx_initpid;
15222 +               if (pid == vxi->vx_initpid)
15223 +                       return ~0U;
15224 +       }
15225 +       return pid;
15226 +}
15227 +
15228 +#endif
15229 diff -NurpP --minimal linux-3.1/include/linux/vserver/sched.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/sched.h
15230 --- linux-3.1/include/linux/vserver/sched.h     1970-01-01 01:00:00.000000000 +0100
15231 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/sched.h 2011-10-24 18:53:33.000000000 +0200
15232 @@ -0,0 +1,23 @@
15233 +#ifndef _VX_SCHED_H
15234 +#define _VX_SCHED_H
15235 +
15236 +
15237 +#ifdef __KERNEL__
15238 +
15239 +struct timespec;
15240 +
15241 +void vx_vsi_uptime(struct timespec *, struct timespec *);
15242 +
15243 +
15244 +struct vx_info;
15245 +
15246 +void vx_update_load(struct vx_info *);
15247 +
15248 +
15249 +void vx_update_sched_param(struct _vx_sched *sched,
15250 +       struct _vx_sched_pc *sched_pc);
15251 +
15252 +#endif /* __KERNEL__ */
15253 +#else  /* _VX_SCHED_H */
15254 +#warning duplicate inclusion
15255 +#endif /* _VX_SCHED_H */
15256 diff -NurpP --minimal linux-3.1/include/linux/vserver/sched_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/sched_cmd.h
15257 --- linux-3.1/include/linux/vserver/sched_cmd.h 1970-01-01 01:00:00.000000000 +0100
15258 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/sched_cmd.h     2011-10-24 18:53:33.000000000 +0200
15259 @@ -0,0 +1,21 @@
15260 +#ifndef _VX_SCHED_CMD_H
15261 +#define _VX_SCHED_CMD_H
15262 +
15263 +
15264 +struct vcmd_prio_bias {
15265 +       int32_t cpu_id;
15266 +       int32_t prio_bias;
15267 +};
15268 +
15269 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
15270 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
15271 +
15272 +#ifdef __KERNEL__
15273 +
15274 +#include <linux/compiler.h>
15275 +
15276 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
15277 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
15278 +
15279 +#endif /* __KERNEL__ */
15280 +#endif /* _VX_SCHED_CMD_H */
15281 diff -NurpP --minimal linux-3.1/include/linux/vserver/sched_def.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/sched_def.h
15282 --- linux-3.1/include/linux/vserver/sched_def.h 1970-01-01 01:00:00.000000000 +0100
15283 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/sched_def.h     2011-10-24 18:53:33.000000000 +0200
15284 @@ -0,0 +1,38 @@
15285 +#ifndef _VX_SCHED_DEF_H
15286 +#define _VX_SCHED_DEF_H
15287 +
15288 +#include <linux/spinlock.h>
15289 +#include <linux/jiffies.h>
15290 +#include <linux/cpumask.h>
15291 +#include <asm/atomic.h>
15292 +#include <asm/param.h>
15293 +
15294 +
15295 +/* context sub struct */
15296 +
15297 +struct _vx_sched {
15298 +       int prio_bias;                  /* bias offset for priority */
15299 +
15300 +       cpumask_t update;               /* CPUs which should update */
15301 +};
15302 +
15303 +struct _vx_sched_pc {
15304 +       int prio_bias;                  /* bias offset for priority */
15305 +
15306 +       uint64_t user_ticks;            /* token tick events */
15307 +       uint64_t sys_ticks;             /* token tick events */
15308 +       uint64_t hold_ticks;            /* token ticks paused */
15309 +};
15310 +
15311 +
15312 +#ifdef CONFIG_VSERVER_DEBUG
15313 +
15314 +static inline void __dump_vx_sched(struct _vx_sched *sched)
15315 +{
15316 +       printk("\t_vx_sched:\n");
15317 +       printk("\t priority = %4d\n", sched->prio_bias);
15318 +}
15319 +
15320 +#endif
15321 +
15322 +#endif /* _VX_SCHED_DEF_H */
15323 diff -NurpP --minimal linux-3.1/include/linux/vserver/signal.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/signal.h
15324 --- linux-3.1/include/linux/vserver/signal.h    1970-01-01 01:00:00.000000000 +0100
15325 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/signal.h        2011-10-24 18:53:33.000000000 +0200
15326 @@ -0,0 +1,14 @@
15327 +#ifndef _VX_SIGNAL_H
15328 +#define _VX_SIGNAL_H
15329 +
15330 +
15331 +#ifdef __KERNEL__
15332 +
15333 +struct vx_info;
15334 +
15335 +int vx_info_kill(struct vx_info *, int, int);
15336 +
15337 +#endif /* __KERNEL__ */
15338 +#else  /* _VX_SIGNAL_H */
15339 +#warning duplicate inclusion
15340 +#endif /* _VX_SIGNAL_H */
15341 diff -NurpP --minimal linux-3.1/include/linux/vserver/signal_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/signal_cmd.h
15342 --- linux-3.1/include/linux/vserver/signal_cmd.h        1970-01-01 01:00:00.000000000 +0100
15343 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/signal_cmd.h    2011-10-24 18:53:33.000000000 +0200
15344 @@ -0,0 +1,43 @@
15345 +#ifndef _VX_SIGNAL_CMD_H
15346 +#define _VX_SIGNAL_CMD_H
15347 +
15348 +
15349 +/*  signalling vserver commands */
15350 +
15351 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
15352 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
15353 +
15354 +struct vcmd_ctx_kill_v0 {
15355 +       int32_t pid;
15356 +       int32_t sig;
15357 +};
15358 +
15359 +struct vcmd_wait_exit_v0 {
15360 +       int32_t reboot_cmd;
15361 +       int32_t exit_code;
15362 +};
15363 +
15364 +#ifdef __KERNEL__
15365 +
15366 +extern int vc_ctx_kill(struct vx_info *, void __user *);
15367 +extern int vc_wait_exit(struct vx_info *, void __user *);
15368 +
15369 +#endif /* __KERNEL__ */
15370 +
15371 +/*  process alteration commands */
15372 +
15373 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
15374 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
15375 +
15376 +struct vcmd_pflags_v0 {
15377 +       uint32_t flagword;
15378 +       uint32_t mask;
15379 +};
15380 +
15381 +#ifdef __KERNEL__
15382 +
15383 +extern int vc_get_pflags(uint32_t pid, void __user *);
15384 +extern int vc_set_pflags(uint32_t pid, void __user *);
15385 +
15386 +#endif /* __KERNEL__ */
15387 +#endif /* _VX_SIGNAL_CMD_H */
15388 diff -NurpP --minimal linux-3.1/include/linux/vserver/space.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/space.h
15389 --- linux-3.1/include/linux/vserver/space.h     1970-01-01 01:00:00.000000000 +0100
15390 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/space.h 2011-10-24 18:53:33.000000000 +0200
15391 @@ -0,0 +1,12 @@
15392 +#ifndef _VX_SPACE_H
15393 +#define _VX_SPACE_H
15394 +
15395 +#include <linux/types.h>
15396 +
15397 +struct vx_info;
15398 +
15399 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
15400 +
15401 +#else  /* _VX_SPACE_H */
15402 +#warning duplicate inclusion
15403 +#endif /* _VX_SPACE_H */
15404 diff -NurpP --minimal linux-3.1/include/linux/vserver/space_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/space_cmd.h
15405 --- linux-3.1/include/linux/vserver/space_cmd.h 1970-01-01 01:00:00.000000000 +0100
15406 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/space_cmd.h     2011-10-24 18:53:33.000000000 +0200
15407 @@ -0,0 +1,38 @@
15408 +#ifndef _VX_SPACE_CMD_H
15409 +#define _VX_SPACE_CMD_H
15410 +
15411 +
15412 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
15413 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
15414 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
15415 +
15416 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
15417 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
15418 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
15419 +
15420 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
15421 +
15422 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
15423 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
15424 +
15425 +
15426 +struct vcmd_space_mask_v1 {
15427 +       uint64_t mask;
15428 +};
15429 +
15430 +struct vcmd_space_mask_v2 {
15431 +       uint64_t mask;
15432 +       uint32_t index;
15433 +};
15434 +
15435 +
15436 +#ifdef __KERNEL__
15437 +
15438 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
15439 +extern int vc_set_space_v1(struct vx_info *, void __user *);
15440 +extern int vc_enter_space(struct vx_info *, void __user *);
15441 +extern int vc_set_space(struct vx_info *, void __user *);
15442 +extern int vc_get_space_mask(void __user *, int);
15443 +
15444 +#endif /* __KERNEL__ */
15445 +#endif /* _VX_SPACE_CMD_H */
15446 diff -NurpP --minimal linux-3.1/include/linux/vserver/switch.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/switch.h
15447 --- linux-3.1/include/linux/vserver/switch.h    1970-01-01 01:00:00.000000000 +0100
15448 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/switch.h        2011-10-24 18:53:33.000000000 +0200
15449 @@ -0,0 +1,98 @@
15450 +#ifndef _VX_SWITCH_H
15451 +#define _VX_SWITCH_H
15452 +
15453 +#include <linux/types.h>
15454 +
15455 +
15456 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
15457 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
15458 +#define VC_VERSION(c)          ((c) & 0xFFF)
15459 +
15460 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
15461 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
15462 +
15463 +/*
15464 +
15465 +  Syscall Matrix V2.8
15466 +
15467 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
15468 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
15469 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
15470 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15471 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
15472 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
15473 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15474 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
15475 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
15476 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15477 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
15478 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
15479 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15480 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
15481 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
15482 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15483 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
15484 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
15485 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15486 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
15487 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
15488 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
15489 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
15490 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
15491 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15492 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
15493 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
15494 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15495 +
15496 +*/
15497 +
15498 +#define VC_CAT_VERSION         0
15499 +
15500 +#define VC_CAT_VSETUP          1
15501 +#define VC_CAT_VHOST           2
15502 +
15503 +#define VC_CAT_DEVICE          6
15504 +
15505 +#define VC_CAT_VPROC           9
15506 +#define VC_CAT_PROCALT         10
15507 +#define VC_CAT_PROCMIG         11
15508 +#define VC_CAT_PROCTRL         12
15509 +
15510 +#define VC_CAT_SCHED           14
15511 +#define VC_CAT_MEMCTRL         20
15512 +
15513 +#define VC_CAT_VNET            25
15514 +#define VC_CAT_NETALT          26
15515 +#define VC_CAT_NETMIG          27
15516 +#define VC_CAT_NETCTRL         28
15517 +
15518 +#define VC_CAT_TAGMIG          35
15519 +#define VC_CAT_DLIMIT          36
15520 +#define VC_CAT_INODE           38
15521 +
15522 +#define VC_CAT_VSTAT           40
15523 +#define VC_CAT_VINFO           46
15524 +#define VC_CAT_EVENT           48
15525 +
15526 +#define VC_CAT_FLAGS           52
15527 +#define VC_CAT_VSPACE          54
15528 +#define VC_CAT_DEBUG           56
15529 +#define VC_CAT_RLIMIT          60
15530 +
15531 +#define VC_CAT_SYSTEST         61
15532 +#define VC_CAT_COMPAT          63
15533 +
15534 +/*  query version */
15535 +
15536 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
15537 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
15538 +
15539 +
15540 +#ifdef __KERNEL__
15541 +
15542 +#include <linux/errno.h>
15543 +
15544 +#endif /* __KERNEL__ */
15545 +
15546 +#endif /* _VX_SWITCH_H */
15547 +
15548 diff -NurpP --minimal linux-3.1/include/linux/vserver/tag.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/tag.h
15549 --- linux-3.1/include/linux/vserver/tag.h       1970-01-01 01:00:00.000000000 +0100
15550 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/tag.h   2011-10-24 18:53:33.000000000 +0200
15551 @@ -0,0 +1,143 @@
15552 +#ifndef _DX_TAG_H
15553 +#define _DX_TAG_H
15554 +
15555 +#include <linux/types.h>
15556 +
15557 +
15558 +#define DX_TAG(in)     (IS_TAGGED(in))
15559 +
15560 +
15561 +#ifdef CONFIG_TAG_NFSD
15562 +#define DX_TAG_NFSD    1
15563 +#else
15564 +#define DX_TAG_NFSD    0
15565 +#endif
15566 +
15567 +
15568 +#ifdef CONFIG_TAGGING_NONE
15569 +
15570 +#define MAX_UID                0xFFFFFFFF
15571 +#define MAX_GID                0xFFFFFFFF
15572 +
15573 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
15574 +
15575 +#define TAGINO_UID(cond, uid, tag)     (uid)
15576 +#define TAGINO_GID(cond, gid, tag)     (gid)
15577 +
15578 +#endif
15579 +
15580 +
15581 +#ifdef CONFIG_TAGGING_GID16
15582 +
15583 +#define MAX_UID                0xFFFFFFFF
15584 +#define MAX_GID                0x0000FFFF
15585 +
15586 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15587 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
15588 +
15589 +#define TAGINO_UID(cond, uid, tag)     (uid)
15590 +#define TAGINO_GID(cond, gid, tag)     \
15591 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
15592 +
15593 +#endif
15594 +
15595 +
15596 +#ifdef CONFIG_TAGGING_ID24
15597 +
15598 +#define MAX_UID                0x00FFFFFF
15599 +#define MAX_GID                0x00FFFFFF
15600 +
15601 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15602 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
15603 +
15604 +#define TAGINO_UID(cond, uid, tag)     \
15605 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
15606 +#define TAGINO_GID(cond, gid, tag)     \
15607 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
15608 +
15609 +#endif
15610 +
15611 +
15612 +#ifdef CONFIG_TAGGING_UID16
15613 +
15614 +#define MAX_UID                0x0000FFFF
15615 +#define MAX_GID                0xFFFFFFFF
15616 +
15617 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15618 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
15619 +
15620 +#define TAGINO_UID(cond, uid, tag)     \
15621 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
15622 +#define TAGINO_GID(cond, gid, tag)     (gid)
15623 +
15624 +#endif
15625 +
15626 +
15627 +#ifdef CONFIG_TAGGING_INTERN
15628 +
15629 +#define MAX_UID                0xFFFFFFFF
15630 +#define MAX_GID                0xFFFFFFFF
15631 +
15632 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15633 +       ((cond) ? (tag) : 0)
15634 +
15635 +#define TAGINO_UID(cond, uid, tag)     (uid)
15636 +#define TAGINO_GID(cond, gid, tag)     (gid)
15637 +
15638 +#endif
15639 +
15640 +
15641 +#ifndef CONFIG_TAGGING_NONE
15642 +#define dx_current_fstag(sb)   \
15643 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
15644 +#else
15645 +#define dx_current_fstag(sb)   (0)
15646 +#endif
15647 +
15648 +#ifndef CONFIG_TAGGING_INTERN
15649 +#define TAGINO_TAG(cond, tag)  (0)
15650 +#else
15651 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
15652 +#endif
15653 +
15654 +#define INOTAG_UID(cond, uid, gid)     \
15655 +       ((cond) ? ((uid) & MAX_UID) : (uid))
15656 +#define INOTAG_GID(cond, uid, gid)     \
15657 +       ((cond) ? ((gid) & MAX_GID) : (gid))
15658 +
15659 +
15660 +static inline uid_t dx_map_uid(uid_t uid)
15661 +{
15662 +       if ((uid > MAX_UID) && (uid != -1))
15663 +               uid = -2;
15664 +       return (uid & MAX_UID);
15665 +}
15666 +
15667 +static inline gid_t dx_map_gid(gid_t gid)
15668 +{
15669 +       if ((gid > MAX_GID) && (gid != -1))
15670 +               gid = -2;
15671 +       return (gid & MAX_GID);
15672 +}
15673 +
15674 +struct peer_tag {
15675 +       int32_t xid;
15676 +       int32_t nid;
15677 +};
15678 +
15679 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
15680 +
15681 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
15682 +                unsigned long *flags);
15683 +
15684 +#ifdef CONFIG_PROPAGATE
15685 +
15686 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
15687 +
15688 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
15689 +
15690 +#else
15691 +#define dx_propagate_tag(n, i) do { } while (0)
15692 +#endif
15693 +
15694 +#endif /* _DX_TAG_H */
15695 diff -NurpP --minimal linux-3.1/include/linux/vserver/tag_cmd.h linux-3.1-vs2.3.1-rc2/include/linux/vserver/tag_cmd.h
15696 --- linux-3.1/include/linux/vserver/tag_cmd.h   1970-01-01 01:00:00.000000000 +0100
15697 +++ linux-3.1-vs2.3.1-rc2/include/linux/vserver/tag_cmd.h       2011-10-24 18:53:33.000000000 +0200
15698 @@ -0,0 +1,22 @@
15699 +#ifndef _VX_TAG_CMD_H
15700 +#define _VX_TAG_CMD_H
15701 +
15702 +
15703 +/* vinfo commands */
15704 +
15705 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
15706 +
15707 +#ifdef __KERNEL__
15708 +extern int vc_task_tag(uint32_t);
15709 +
15710 +#endif /* __KERNEL__ */
15711 +
15712 +/* context commands */
15713 +
15714 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
15715 +
15716 +#ifdef __KERNEL__
15717 +extern int vc_tag_migrate(uint32_t);
15718 +
15719 +#endif /* __KERNEL__ */
15720 +#endif /* _VX_TAG_CMD_H */
15721 diff -NurpP --minimal linux-3.1/include/net/addrconf.h linux-3.1-vs2.3.1-rc2/include/net/addrconf.h
15722 --- linux-3.1/include/net/addrconf.h    2011-07-22 11:18:11.000000000 +0200
15723 +++ linux-3.1-vs2.3.1-rc2/include/net/addrconf.h        2011-10-24 18:53:33.000000000 +0200
15724 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
15725                                                struct net_device *dev,
15726                                                const struct in6_addr *daddr,
15727                                                unsigned int srcprefs,
15728 -                                              struct in6_addr *saddr);
15729 +                                              struct in6_addr *saddr,
15730 +                                              struct nx_info *nxi);
15731  extern int                     ipv6_get_lladdr(struct net_device *dev,
15732                                                 struct in6_addr *addr,
15733                                                 unsigned char banned_flags);
15734 diff -NurpP --minimal linux-3.1/include/net/af_unix.h linux-3.1-vs2.3.1-rc2/include/net/af_unix.h
15735 --- linux-3.1/include/net/af_unix.h     2011-07-22 11:18:11.000000000 +0200
15736 +++ linux-3.1-vs2.3.1-rc2/include/net/af_unix.h 2011-10-24 18:53:33.000000000 +0200
15737 @@ -4,6 +4,7 @@
15738  #include <linux/socket.h>
15739  #include <linux/un.h>
15740  #include <linux/mutex.h>
15741 +#include <linux/vs_base.h>
15742  #include <net/sock.h>
15743  
15744  extern void unix_inflight(struct file *fp);
15745 diff -NurpP --minimal linux-3.1/include/net/inet_timewait_sock.h linux-3.1-vs2.3.1-rc2/include/net/inet_timewait_sock.h
15746 --- linux-3.1/include/net/inet_timewait_sock.h  2011-10-24 18:45:32.000000000 +0200
15747 +++ linux-3.1-vs2.3.1-rc2/include/net/inet_timewait_sock.h      2011-10-24 18:53:33.000000000 +0200
15748 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
15749  #define tw_net                 __tw_common.skc_net
15750  #define tw_daddr               __tw_common.skc_daddr
15751  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
15752 +#define tw_xid                 __tw_common.skc_xid
15753 +#define tw_vx_info             __tw_common.skc_vx_info
15754 +#define tw_nid                 __tw_common.skc_nid
15755 +#define tw_nx_info             __tw_common.skc_nx_info
15756         int                     tw_timeout;
15757         volatile unsigned char  tw_substate;
15758         unsigned char           tw_rcv_wscale;
15759 diff -NurpP --minimal linux-3.1/include/net/ip6_route.h linux-3.1-vs2.3.1-rc2/include/net/ip6_route.h
15760 --- linux-3.1/include/net/ip6_route.h   2011-07-22 11:18:11.000000000 +0200
15761 +++ linux-3.1-vs2.3.1-rc2/include/net/ip6_route.h       2011-10-24 18:53:33.000000000 +0200
15762 @@ -86,7 +86,8 @@ extern int                    ip6_route_get_saddr(struct 
15763                                                     struct rt6_info *rt,
15764                                                     const struct in6_addr *daddr,
15765                                                     unsigned int prefs,
15766 -                                                   struct in6_addr *saddr);
15767 +                                                   struct in6_addr *saddr,
15768 +                                                   struct nx_info *nxi);
15769  
15770  extern struct rt6_info         *rt6_lookup(struct net *net,
15771                                             const struct in6_addr *daddr,
15772 diff -NurpP --minimal linux-3.1/include/net/route.h linux-3.1-vs2.3.1-rc2/include/net/route.h
15773 --- linux-3.1/include/net/route.h       2011-07-22 11:18:11.000000000 +0200
15774 +++ linux-3.1-vs2.3.1-rc2/include/net/route.h   2011-10-24 18:53:33.000000000 +0200
15775 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
15776                 dst_release(&rt->dst);
15777  }
15778  
15779 +#include <linux/vs_base.h>
15780 +#include <linux/vs_inet.h>
15781 +
15782  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
15783  
15784  extern const __u8 ip_tos2prio[16];
15785 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
15786                            protocol, flow_flags, dst, src, dport, sport);
15787  }
15788  
15789 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
15790 +       struct flowi4 *);
15791 +
15792  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
15793                                               __be32 dst, __be32 src, u32 tos,
15794                                               int oif, u8 protocol,
15795 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
15796  {
15797         struct net *net = sock_net(sk);
15798         struct rtable *rt;
15799 +       struct nx_info *nx_info = current_nx_info();
15800  
15801         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
15802                               sport, dport, sk, can_sleep);
15803  
15804 -       if (!dst || !src) {
15805 +       if (sk)
15806 +               nx_info = sk->sk_nx_info;
15807 +
15808 +       vxdprintk(VXD_CBIT(net, 4),
15809 +               "ip_route_connect(%p) %p,%p;%lx",
15810 +               sk, nx_info, sk->sk_socket,
15811 +               (sk->sk_socket?sk->sk_socket->flags:0));
15812 +
15813 +       rt = ip_v4_find_src(net, nx_info, fl4);
15814 +       if (IS_ERR(rt))
15815 +               return rt;
15816 +       ip_rt_put(rt);
15817 +
15818 +       if (!fl4->daddr || !fl4->saddr) {
15819                 rt = __ip_route_output_key(net, fl4);
15820                 if (IS_ERR(rt))
15821                         return rt;
15822 diff -NurpP --minimal linux-3.1/include/net/sock.h linux-3.1-vs2.3.1-rc2/include/net/sock.h
15823 --- linux-3.1/include/net/sock.h        2011-10-24 18:45:32.000000000 +0200
15824 +++ linux-3.1-vs2.3.1-rc2/include/net/sock.h    2011-10-24 18:53:33.000000000 +0200
15825 @@ -150,6 +150,10 @@ struct sock_common {
15826  #ifdef CONFIG_NET_NS
15827         struct net              *skc_net;
15828  #endif
15829 +       xid_t                   skc_xid;
15830 +       struct vx_info          *skc_vx_info;
15831 +       nid_t                   skc_nid;
15832 +       struct nx_info          *skc_nx_info;
15833         /*
15834          * fields between dontcopy_begin/dontcopy_end
15835          * are not copied in sock_copy()
15836 @@ -257,6 +261,10 @@ struct sock {
15837  #define sk_bind_node           __sk_common.skc_bind_node
15838  #define sk_prot                        __sk_common.skc_prot
15839  #define sk_net                 __sk_common.skc_net
15840 +#define sk_xid                 __sk_common.skc_xid
15841 +#define sk_vx_info             __sk_common.skc_vx_info
15842 +#define sk_nid                 __sk_common.skc_nid
15843 +#define sk_nx_info             __sk_common.skc_nx_info
15844         socket_lock_t           sk_lock;
15845         struct sk_buff_head     sk_receive_queue;
15846         /*
15847 diff -NurpP --minimal linux-3.1/init/Kconfig linux-3.1-vs2.3.1-rc2/init/Kconfig
15848 --- linux-3.1/init/Kconfig      2011-10-24 18:45:33.000000000 +0200
15849 +++ linux-3.1-vs2.3.1-rc2/init/Kconfig  2011-10-24 18:53:33.000000000 +0200
15850 @@ -574,6 +574,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
15851  menuconfig CGROUPS
15852         boolean "Control Group support"
15853         depends on EVENTFD
15854 +       default y
15855         help
15856           This option adds support for grouping sets of processes together, for
15857           use with process control subsystems such as Cpusets, CFS, memory
15858 @@ -790,6 +791,7 @@ config IPC_NS
15859  config USER_NS
15860         bool "User namespace (EXPERIMENTAL)"
15861         depends on EXPERIMENTAL
15862 +       depends on VSERVER_DISABLED
15863         default y
15864         help
15865           This allows containers, i.e. vservers, to use user namespaces
15866 diff -NurpP --minimal linux-3.1/init/main.c linux-3.1-vs2.3.1-rc2/init/main.c
15867 --- linux-3.1/init/main.c       2011-10-24 18:45:33.000000000 +0200
15868 +++ linux-3.1-vs2.3.1-rc2/init/main.c   2011-10-24 18:53:33.000000000 +0200
15869 @@ -68,6 +68,7 @@
15870  #include <linux/shmem_fs.h>
15871  #include <linux/slab.h>
15872  #include <linux/perf_event.h>
15873 +#include <linux/vserver/percpu.h>
15874  
15875  #include <asm/io.h>
15876  #include <asm/bugs.h>
15877 diff -NurpP --minimal linux-3.1/ipc/mqueue.c linux-3.1-vs2.3.1-rc2/ipc/mqueue.c
15878 --- linux-3.1/ipc/mqueue.c      2011-10-24 18:45:33.000000000 +0200
15879 +++ linux-3.1-vs2.3.1-rc2/ipc/mqueue.c  2011-10-24 18:53:33.000000000 +0200
15880 @@ -33,6 +33,8 @@
15881  #include <linux/pid.h>
15882  #include <linux/ipc_namespace.h>
15883  #include <linux/slab.h>
15884 +#include <linux/vs_context.h>
15885 +#include <linux/vs_limit.h>
15886  
15887  #include <net/sock.h>
15888  #include "util.h"
15889 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
15890         struct sigevent notify;
15891         struct pid* notify_owner;
15892         struct user_struct *user;       /* user who created, for accounting */
15893 +       struct vx_info *vxi;
15894         struct sock *notify_sock;
15895         struct sk_buff *notify_cookie;
15896  
15897 @@ -128,6 +131,7 @@ static struct inode *mqueue_get_inode(st
15898         if (S_ISREG(mode)) {
15899                 struct mqueue_inode_info *info;
15900                 struct task_struct *p = current;
15901 +               struct vx_info *vxi = p->vx_info;
15902                 unsigned long mq_bytes, mq_msg_tblsz;
15903  
15904                 inode->i_fop = &mqueue_file_operations;
15905 @@ -141,6 +145,7 @@ static struct inode *mqueue_get_inode(st
15906                 info->notify_owner = NULL;
15907                 info->qsize = 0;
15908                 info->user = NULL;      /* set when all is ok */
15909 +               info->vxi = NULL;
15910                 memset(&info->attr, 0, sizeof(info->attr));
15911                 info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
15912                 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
15913 @@ -158,17 +163,20 @@ static struct inode *mqueue_get_inode(st
15914  
15915                 spin_lock(&mq_lock);
15916                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
15917 -                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
15918 +                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE) ||
15919 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
15920                         spin_unlock(&mq_lock);
15921                         /* mqueue_evict_inode() releases info->messages */
15922                         ret = -EMFILE;
15923                         goto out_inode;
15924                 }
15925                 u->mq_bytes += mq_bytes;
15926 +               vx_ipcmsg_add(vxi, u, mq_bytes);
15927                 spin_unlock(&mq_lock);
15928  
15929                 /* all is ok */
15930                 info->user = get_uid(u);
15931 +               info->vxi = get_vx_info(vxi);
15932         } else if (S_ISDIR(mode)) {
15933                 inc_nlink(inode);
15934                 /* Some things misbehave if size == 0 on a directory */
15935 @@ -278,8 +286,11 @@ static void mqueue_evict_inode(struct in
15936             + info->attr.mq_msgsize);
15937         user = info->user;
15938         if (user) {
15939 +               struct vx_info *vxi = info->vxi;
15940 +
15941                 spin_lock(&mq_lock);
15942                 user->mq_bytes -= mq_bytes;
15943 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15944                 /*
15945                  * get_ns_from_inode() ensures that the
15946                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
15947 @@ -289,6 +300,7 @@ static void mqueue_evict_inode(struct in
15948                 if (ipc_ns)
15949                         ipc_ns->mq_queues_count--;
15950                 spin_unlock(&mq_lock);
15951 +               put_vx_info(vxi);
15952                 free_uid(user);
15953         }
15954         if (ipc_ns)
15955 diff -NurpP --minimal linux-3.1/ipc/msg.c linux-3.1-vs2.3.1-rc2/ipc/msg.c
15956 --- linux-3.1/ipc/msg.c 2011-05-22 16:17:59.000000000 +0200
15957 +++ linux-3.1-vs2.3.1-rc2/ipc/msg.c     2011-10-24 18:53:33.000000000 +0200
15958 @@ -37,6 +37,7 @@
15959  #include <linux/rwsem.h>
15960  #include <linux/nsproxy.h>
15961  #include <linux/ipc_namespace.h>
15962 +#include <linux/vs_base.h>
15963  
15964  #include <asm/current.h>
15965  #include <asm/uaccess.h>
15966 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
15967  
15968         msq->q_perm.mode = msgflg & S_IRWXUGO;
15969         msq->q_perm.key = key;
15970 +       msq->q_perm.xid = vx_current_xid();
15971  
15972         msq->q_perm.security = NULL;
15973         retval = security_msg_queue_alloc(msq);
15974 diff -NurpP --minimal linux-3.1/ipc/namespace.c linux-3.1-vs2.3.1-rc2/ipc/namespace.c
15975 --- linux-3.1/ipc/namespace.c   2011-07-22 11:18:12.000000000 +0200
15976 +++ linux-3.1-vs2.3.1-rc2/ipc/namespace.c       2011-10-24 18:53:33.000000000 +0200
15977 @@ -13,11 +13,12 @@
15978  #include <linux/mount.h>
15979  #include <linux/user_namespace.h>
15980  #include <linux/proc_fs.h>
15981 +#include <linux/vs_base.h>
15982 +#include <linux/vserver/global.h>
15983  
15984  #include "util.h"
15985  
15986 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
15987 -                                          struct ipc_namespace *old_ns)
15988 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
15989  {
15990         struct ipc_namespace *ns;
15991         int err;
15992 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
15993         ipcns_notify(IPCNS_CREATED);
15994         register_ipcns_notifier(ns);
15995  
15996 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15997 +       ns->user_ns = get_user_ns(user_ns);
15998  
15999         return ns;
16000  }
16001  
16002  struct ipc_namespace *copy_ipcs(unsigned long flags,
16003 -                               struct task_struct *tsk)
16004 +                               struct ipc_namespace *old_ns,
16005 +                               struct user_namespace *user_ns)
16006  {
16007 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
16008 -
16009         if (!(flags & CLONE_NEWIPC))
16010 -               return get_ipc_ns(ns);
16011 -       return create_ipc_ns(tsk, ns);
16012 +               return get_ipc_ns(old_ns);
16013 +       return create_ipc_ns(user_ns);
16014  }
16015  
16016  /*
16017 diff -NurpP --minimal linux-3.1/ipc/sem.c linux-3.1-vs2.3.1-rc2/ipc/sem.c
16018 --- linux-3.1/ipc/sem.c 2011-10-24 18:45:33.000000000 +0200
16019 +++ linux-3.1-vs2.3.1-rc2/ipc/sem.c     2011-10-24 18:53:33.000000000 +0200
16020 @@ -86,6 +86,8 @@
16021  #include <linux/rwsem.h>
16022  #include <linux/nsproxy.h>
16023  #include <linux/ipc_namespace.h>
16024 +#include <linux/vs_base.h>
16025 +#include <linux/vs_limit.h>
16026  
16027  #include <asm/uaccess.h>
16028  #include "util.h"
16029 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
16030  
16031         sma->sem_perm.mode = (semflg & S_IRWXUGO);
16032         sma->sem_perm.key = key;
16033 +       sma->sem_perm.xid = vx_current_xid();
16034  
16035         sma->sem_perm.security = NULL;
16036         retval = security_sem_alloc(sma);
16037 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
16038                 return id;
16039         }
16040         ns->used_sems += nsems;
16041 +       /* FIXME: obsoleted? */
16042 +       vx_semary_inc(sma);
16043 +       vx_nsems_add(sma, nsems);
16044  
16045         sma->sem_base = (struct sem *) &sma[1];
16046  
16047 @@ -724,6 +730,9 @@ static void freeary(struct ipc_namespace
16048  
16049         wake_up_sem_queue_do(&tasks);
16050         ns->used_sems -= sma->sem_nsems;
16051 +       /* FIXME: obsoleted? */
16052 +       vx_nsems_sub(sma, sma->sem_nsems);
16053 +       vx_semary_dec(sma);
16054         security_sem_free(sma);
16055         ipc_rcu_putref(sma);
16056  }
16057 diff -NurpP --minimal linux-3.1/ipc/shm.c linux-3.1-vs2.3.1-rc2/ipc/shm.c
16058 --- linux-3.1/ipc/shm.c 2011-10-24 18:45:33.000000000 +0200
16059 +++ linux-3.1-vs2.3.1-rc2/ipc/shm.c     2011-10-24 18:53:33.000000000 +0200
16060 @@ -39,6 +39,8 @@
16061  #include <linux/nsproxy.h>
16062  #include <linux/mount.h>
16063  #include <linux/ipc_namespace.h>
16064 +#include <linux/vs_context.h>
16065 +#include <linux/vs_limit.h>
16066  
16067  #include <asm/uaccess.h>
16068  
16069 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
16070   */
16071  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
16072  {
16073 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
16074 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
16075 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
16076 +
16077 +       vx_ipcshm_sub(vxi, shp, numpages);
16078 +       ns->shm_tot -= numpages;
16079 +
16080         shm_rmid(ns, shp);
16081         shm_unlock(shp);
16082         if (!is_file_hugepages(shp->shm_file))
16083 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
16084                                                 shp->mlock_user);
16085         fput (shp->shm_file);
16086         security_shm_free(shp);
16087 +       put_vx_info(vxi);
16088         ipc_rcu_putref(shp);
16089  }
16090  
16091 @@ -462,11 +470,15 @@ static int newseg(struct ipc_namespace *
16092         if (ns->shm_tot + numpages > ns->shm_ctlall)
16093                 return -ENOSPC;
16094  
16095 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
16096 +               return -ENOSPC;
16097 +
16098         shp = ipc_rcu_alloc(sizeof(*shp));
16099         if (!shp)
16100                 return -ENOMEM;
16101  
16102         shp->shm_perm.key = key;
16103 +       shp->shm_perm.xid = vx_current_xid();
16104         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
16105         shp->mlock_user = NULL;
16106  
16107 @@ -521,6 +533,7 @@ static int newseg(struct ipc_namespace *
16108         ns->shm_tot += numpages;
16109         error = shp->shm_perm.id;
16110         shm_unlock(shp);
16111 +       vx_ipcshm_add(current_vx_info(), key, numpages);
16112         return error;
16113  
16114  no_id:
16115 diff -NurpP --minimal linux-3.1/kernel/Makefile linux-3.1-vs2.3.1-rc2/kernel/Makefile
16116 --- linux-3.1/kernel/Makefile   2011-10-24 18:45:33.000000000 +0200
16117 +++ linux-3.1-vs2.3.1-rc2/kernel/Makefile       2011-10-24 18:53:33.000000000 +0200
16118 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
16119  CFLAGS_REMOVE_irq_work.o = -pg
16120  endif
16121  
16122 +obj-y += vserver/
16123  obj-$(CONFIG_FREEZER) += freezer.o
16124  obj-$(CONFIG_PROFILING) += profile.o
16125  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
16126 diff -NurpP --minimal linux-3.1/kernel/capability.c linux-3.1-vs2.3.1-rc2/kernel/capability.c
16127 --- linux-3.1/kernel/capability.c       2011-07-22 11:18:12.000000000 +0200
16128 +++ linux-3.1-vs2.3.1-rc2/kernel/capability.c   2011-10-24 18:53:33.000000000 +0200
16129 @@ -15,6 +15,7 @@
16130  #include <linux/syscalls.h>
16131  #include <linux/pid_namespace.h>
16132  #include <linux/user_namespace.h>
16133 +#include <linux/vs_context.h>
16134  #include <asm/uaccess.h>
16135  
16136  /*
16137 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
16138         return 0;
16139  }
16140  
16141 +
16142  /*
16143   * The only thing that can change the capabilities of the current
16144   * process is the current process. As such, we can't be in this code
16145 @@ -340,6 +342,8 @@ bool has_capability_noaudit(struct task_
16146         return (ret == 0);
16147  }
16148  
16149 +#include <linux/vserver/base.h>
16150 +
16151  /**
16152   * capable - Determine if the current task has a superior capability in effect
16153   * @cap: The capability to be tested for
16154 @@ -374,6 +378,9 @@ bool ns_capable(struct user_namespace *n
16155                 BUG();
16156         }
16157  
16158 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
16159 +               return true;
16160 +
16161         if (security_capable(ns, current_cred(), cap) == 0) {
16162                 current->flags |= PF_SUPERPRIV;
16163                 return true;
16164 diff -NurpP --minimal linux-3.1/kernel/compat.c linux-3.1-vs2.3.1-rc2/kernel/compat.c
16165 --- linux-3.1/kernel/compat.c   2011-10-24 18:45:33.000000000 +0200
16166 +++ linux-3.1-vs2.3.1-rc2/kernel/compat.c       2011-10-24 18:53:33.000000000 +0200
16167 @@ -972,7 +972,7 @@ asmlinkage long compat_sys_stime(compat_
16168         if (err)
16169                 return err;
16170  
16171 -       do_settimeofday(&tv);
16172 +       vx_settimeofday(&tv);
16173         return 0;
16174  }
16175  
16176 diff -NurpP --minimal linux-3.1/kernel/cred.c linux-3.1-vs2.3.1-rc2/kernel/cred.c
16177 --- linux-3.1/kernel/cred.c     2011-10-24 18:45:33.000000000 +0200
16178 +++ linux-3.1-vs2.3.1-rc2/kernel/cred.c 2011-10-24 18:53:33.000000000 +0200
16179 @@ -61,31 +61,6 @@ struct cred init_cred = {
16180  #endif
16181  };
16182  
16183 -static inline void set_cred_subscribers(struct cred *cred, int n)
16184 -{
16185 -#ifdef CONFIG_DEBUG_CREDENTIALS
16186 -       atomic_set(&cred->subscribers, n);
16187 -#endif
16188 -}
16189 -
16190 -static inline int read_cred_subscribers(const struct cred *cred)
16191 -{
16192 -#ifdef CONFIG_DEBUG_CREDENTIALS
16193 -       return atomic_read(&cred->subscribers);
16194 -#else
16195 -       return 0;
16196 -#endif
16197 -}
16198 -
16199 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
16200 -{
16201 -#ifdef CONFIG_DEBUG_CREDENTIALS
16202 -       struct cred *cred = (struct cred *) _cred;
16203 -
16204 -       atomic_add(n, &cred->subscribers);
16205 -#endif
16206 -}
16207 -
16208  /*
16209   * Dispose of the shared task group credentials
16210   */
16211 @@ -281,21 +256,16 @@ error:
16212   *
16213   * Call commit_creds() or abort_creds() to clean up.
16214   */
16215 -struct cred *prepare_creds(void)
16216 +struct cred *__prepare_creds(const struct cred *old)
16217  {
16218 -       struct task_struct *task = current;
16219 -       const struct cred *old;
16220         struct cred *new;
16221  
16222 -       validate_process_creds();
16223 -
16224         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
16225         if (!new)
16226                 return NULL;
16227  
16228         kdebug("prepare_creds() alloc %p", new);
16229  
16230 -       old = task->cred;
16231         memcpy(new, old, sizeof(struct cred));
16232  
16233         atomic_set(&new->usage, 1);
16234 @@ -322,6 +292,13 @@ error:
16235         abort_creds(new);
16236         return NULL;
16237  }
16238 +
16239 +struct cred *prepare_creds(void)
16240 +{
16241 +       validate_process_creds();
16242 +
16243 +       return __prepare_creds(current->cred);
16244 +}
16245  EXPORT_SYMBOL(prepare_creds);
16246  
16247  /*
16248 diff -NurpP --minimal linux-3.1/kernel/exit.c linux-3.1-vs2.3.1-rc2/kernel/exit.c
16249 --- linux-3.1/kernel/exit.c     2011-10-24 18:45:33.000000000 +0200
16250 +++ linux-3.1-vs2.3.1-rc2/kernel/exit.c 2011-10-24 18:53:33.000000000 +0200
16251 @@ -48,6 +48,10 @@
16252  #include <linux/fs_struct.h>
16253  #include <linux/init_task.h>
16254  #include <linux/perf_event.h>
16255 +#include <linux/vs_limit.h>
16256 +#include <linux/vs_context.h>
16257 +#include <linux/vs_network.h>
16258 +#include <linux/vs_pid.h>
16259  #include <trace/events/sched.h>
16260  #include <linux/hw_breakpoint.h>
16261  #include <linux/oom.h>
16262 @@ -480,9 +484,11 @@ static void close_files(struct files_str
16263                                         filp_close(file, files);
16264                                         cond_resched();
16265                                 }
16266 +                               vx_openfd_dec(i);
16267                         }
16268                         i++;
16269                         set >>= 1;
16270 +                       cond_resched();
16271                 }
16272         }
16273  }
16274 @@ -1038,11 +1044,16 @@ NORET_TYPE void do_exit(long code)
16275  
16276         validate_creds_for_do_exit(tsk);
16277  
16278 +       /* needs to stay after exit_notify() */
16279 +       exit_vx_info(tsk, code);
16280 +       exit_nx_info(tsk);
16281 +
16282         preempt_disable();
16283         exit_rcu();
16284         /* causes final put_task_struct in finish_task_switch(). */
16285         tsk->state = TASK_DEAD;
16286         schedule();
16287 +       printk("bad task: %p [%lx]\n", current, current->state);
16288         BUG();
16289         /* Avoid "noreturn function does return".  */
16290         for (;;)
16291 diff -NurpP --minimal linux-3.1/kernel/fork.c linux-3.1-vs2.3.1-rc2/kernel/fork.c
16292 --- linux-3.1/kernel/fork.c     2011-10-24 18:45:33.000000000 +0200
16293 +++ linux-3.1-vs2.3.1-rc2/kernel/fork.c 2011-10-24 18:53:33.000000000 +0200
16294 @@ -66,6 +66,10 @@
16295  #include <linux/user-return-notifier.h>
16296  #include <linux/oom.h>
16297  #include <linux/khugepaged.h>
16298 +#include <linux/vs_context.h>
16299 +#include <linux/vs_network.h>
16300 +#include <linux/vs_limit.h>
16301 +#include <linux/vs_memory.h>
16302  
16303  #include <asm/pgtable.h>
16304  #include <asm/pgalloc.h>
16305 @@ -166,6 +170,8 @@ void free_task(struct task_struct *tsk)
16306         account_kernel_stack(tsk->stack, -1);
16307         free_thread_info(tsk->stack);
16308         rt_mutex_debug_task_free(tsk);
16309 +       clr_vx_info(&tsk->vx_info);
16310 +       clr_nx_info(&tsk->nx_info);
16311         ftrace_graph_exit_task(tsk);
16312         free_task_struct(tsk);
16313  }
16314 @@ -506,6 +512,7 @@ static struct mm_struct *mm_init(struct 
16315         if (likely(!mm_alloc_pgd(mm))) {
16316                 mm->def_flags = 0;
16317                 mmu_notifier_mm_init(mm);
16318 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
16319                 return mm;
16320         }
16321  
16322 @@ -543,6 +550,7 @@ void __mmdrop(struct mm_struct *mm)
16323  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
16324         VM_BUG_ON(mm->pmd_huge_pte);
16325  #endif
16326 +       clr_vx_info(&mm->mm_vx_info);
16327         free_mm(mm);
16328  }
16329  EXPORT_SYMBOL_GPL(__mmdrop);
16330 @@ -730,6 +738,7 @@ struct mm_struct *dup_mm(struct task_str
16331                 goto fail_nomem;
16332  
16333         memcpy(mm, oldmm, sizeof(*mm));
16334 +       mm->mm_vx_info = NULL;
16335         mm_init_cpumask(mm);
16336  
16337         /* Initializing for Swap token stuff */
16338 @@ -773,6 +782,7 @@ fail_nocontext:
16339          * If init_new_context() failed, we cannot use mmput() to free the mm
16340          * because it calls destroy_context()
16341          */
16342 +       clr_vx_info(&mm->mm_vx_info);
16343         mm_free_pgd(mm);
16344         free_mm(mm);
16345         return NULL;
16346 @@ -1058,6 +1068,8 @@ static struct task_struct *copy_process(
16347         int retval;
16348         struct task_struct *p;
16349         int cgroup_callbacks_done = 0;
16350 +       struct vx_info *vxi;
16351 +       struct nx_info *nxi;
16352  
16353         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
16354                 return ERR_PTR(-EINVAL);
16355 @@ -1104,7 +1116,12 @@ static struct task_struct *copy_process(
16356         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
16357         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
16358  #endif
16359 +       init_vx_info(&p->vx_info, current_vx_info());
16360 +       init_nx_info(&p->nx_info, current_nx_info());
16361 +
16362         retval = -EAGAIN;
16363 +       if (!vx_nproc_avail(1))
16364 +               goto bad_fork_free;
16365         if (atomic_read(&p->real_cred->user->processes) >=
16366                         task_rlimit(p, RLIMIT_NPROC)) {
16367                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
16368 @@ -1374,6 +1391,18 @@ static struct task_struct *copy_process(
16369  
16370         total_forks++;
16371         spin_unlock(&current->sighand->siglock);
16372 +
16373 +       /* p is copy of current */
16374 +       vxi = p->vx_info;
16375 +       if (vxi) {
16376 +               claim_vx_info(vxi, p);
16377 +               atomic_inc(&vxi->cvirt.nr_threads);
16378 +               atomic_inc(&vxi->cvirt.total_forks);
16379 +               vx_nproc_inc(p);
16380 +       }
16381 +       nxi = p->nx_info;
16382 +       if (nxi)
16383 +               claim_nx_info(nxi, p);
16384         write_unlock_irq(&tasklist_lock);
16385         proc_fork_connector(p);
16386         cgroup_post_fork(p);
16387 diff -NurpP --minimal linux-3.1/kernel/kthread.c linux-3.1-vs2.3.1-rc2/kernel/kthread.c
16388 --- linux-3.1/kernel/kthread.c  2011-07-22 11:18:12.000000000 +0200
16389 +++ linux-3.1-vs2.3.1-rc2/kernel/kthread.c      2011-10-24 18:53:33.000000000 +0200
16390 @@ -16,6 +16,7 @@
16391  #include <linux/mutex.h>
16392  #include <linux/slab.h>
16393  #include <linux/freezer.h>
16394 +#include <linux/vs_pid.h>
16395  #include <trace/events/sched.h>
16396  
16397  static DEFINE_SPINLOCK(kthread_create_lock);
16398 diff -NurpP --minimal linux-3.1/kernel/nsproxy.c linux-3.1-vs2.3.1-rc2/kernel/nsproxy.c
16399 --- linux-3.1/kernel/nsproxy.c  2011-10-24 18:45:33.000000000 +0200
16400 +++ linux-3.1-vs2.3.1-rc2/kernel/nsproxy.c      2011-10-24 18:53:33.000000000 +0200
16401 @@ -20,6 +20,8 @@
16402  #include <linux/mnt_namespace.h>
16403  #include <linux/utsname.h>
16404  #include <linux/pid_namespace.h>
16405 +#include <linux/vserver/global.h>
16406 +#include <linux/vserver/debug.h>
16407  #include <net/net_namespace.h>
16408  #include <linux/ipc_namespace.h>
16409  #include <linux/proc_fs.h>
16410 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
16411         struct nsproxy *nsproxy;
16412  
16413         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
16414 -       if (nsproxy)
16415 +       if (nsproxy) {
16416                 atomic_set(&nsproxy->count, 1);
16417 +               atomic_inc(&vs_global_nsproxy);
16418 +       }
16419 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
16420         return nsproxy;
16421  }
16422  
16423 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
16424   * Return the newly created nsproxy.  Do not attach this to the task,
16425   * leave it to the caller to do proper locking and attach it to task.
16426   */
16427 -static struct nsproxy *create_new_namespaces(unsigned long flags,
16428 -                       struct task_struct *tsk, struct fs_struct *new_fs)
16429 +static struct nsproxy *unshare_namespaces(unsigned long flags,
16430 +                       struct nsproxy *orig,
16431 +                       struct fs_struct *new_fs,
16432 +                       struct user_namespace *new_user,
16433 +                       struct pid_namespace *new_pid)
16434  {
16435         struct nsproxy *new_nsp;
16436         int err;
16437 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
16438         if (!new_nsp)
16439                 return ERR_PTR(-ENOMEM);
16440  
16441 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
16442 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
16443         if (IS_ERR(new_nsp->mnt_ns)) {
16444                 err = PTR_ERR(new_nsp->mnt_ns);
16445                 goto out_ns;
16446         }
16447  
16448 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
16449 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
16450         if (IS_ERR(new_nsp->uts_ns)) {
16451                 err = PTR_ERR(new_nsp->uts_ns);
16452                 goto out_uts;
16453         }
16454  
16455 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
16456 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
16457         if (IS_ERR(new_nsp->ipc_ns)) {
16458                 err = PTR_ERR(new_nsp->ipc_ns);
16459                 goto out_ipc;
16460         }
16461  
16462 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
16463 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
16464         if (IS_ERR(new_nsp->pid_ns)) {
16465                 err = PTR_ERR(new_nsp->pid_ns);
16466                 goto out_pid;
16467         }
16468  
16469 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
16470 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
16471         if (IS_ERR(new_nsp->net_ns)) {
16472                 err = PTR_ERR(new_nsp->net_ns);
16473                 goto out_net;
16474 @@ -115,6 +123,40 @@ out_ns:
16475         return ERR_PTR(err);
16476  }
16477  
16478 +static struct nsproxy *create_new_namespaces(unsigned long flags,
16479 +                       struct task_struct *tsk, struct fs_struct *new_fs)
16480 +{
16481 +       return unshare_namespaces(flags, tsk->nsproxy,
16482 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
16483 +               task_active_pid_ns(tsk));
16484 +}
16485 +
16486 +/*
16487 + * copies the nsproxy, setting refcount to 1, and grabbing a
16488 + * reference to all contained namespaces.
16489 + */
16490 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
16491 +{
16492 +       struct nsproxy *ns = create_nsproxy();
16493 +
16494 +       if (ns) {
16495 +               memcpy(ns, orig, sizeof(struct nsproxy));
16496 +               atomic_set(&ns->count, 1);
16497 +
16498 +               if (ns->mnt_ns)
16499 +                       get_mnt_ns(ns->mnt_ns);
16500 +               if (ns->uts_ns)
16501 +                       get_uts_ns(ns->uts_ns);
16502 +               if (ns->ipc_ns)
16503 +                       get_ipc_ns(ns->ipc_ns);
16504 +               if (ns->pid_ns)
16505 +                       get_pid_ns(ns->pid_ns);
16506 +               if (ns->net_ns)
16507 +                       get_net(ns->net_ns);
16508 +       }
16509 +       return ns;
16510 +}
16511 +
16512  /*
16513   * called from clone.  This now handles copy for nsproxy and all
16514   * namespaces therein.
16515 @@ -122,9 +164,12 @@ out_ns:
16516  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
16517  {
16518         struct nsproxy *old_ns = tsk->nsproxy;
16519 -       struct nsproxy *new_ns;
16520 +       struct nsproxy *new_ns = NULL;
16521         int err = 0;
16522  
16523 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
16524 +               flags, tsk, old_ns);
16525 +
16526         if (!old_ns)
16527                 return 0;
16528  
16529 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
16530                                 CLONE_NEWPID | CLONE_NEWNET)))
16531                 return 0;
16532  
16533 -       if (!capable(CAP_SYS_ADMIN)) {
16534 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
16535                 err = -EPERM;
16536                 goto out;
16537         }
16538 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
16539  
16540  out:
16541         put_nsproxy(old_ns);
16542 +       vxdprintk(VXD_CBIT(space, 3),
16543 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
16544 +               flags, tsk, old_ns, err, new_ns);
16545         return err;
16546  }
16547  
16548 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
16549                 put_ipc_ns(ns->ipc_ns);
16550         if (ns->pid_ns)
16551                 put_pid_ns(ns->pid_ns);
16552 -       put_net(ns->net_ns);
16553 +       if (ns->net_ns)
16554 +               put_net(ns->net_ns);
16555 +       atomic_dec(&vs_global_nsproxy);
16556         kmem_cache_free(nsproxy_cachep, ns);
16557  }
16558  
16559 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
16560  {
16561         int err = 0;
16562  
16563 +       vxdprintk(VXD_CBIT(space, 4),
16564 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
16565 +               unshare_flags, current->nsproxy);
16566 +
16567         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
16568                                CLONE_NEWNET)))
16569                 return 0;
16570  
16571 -       if (!capable(CAP_SYS_ADMIN))
16572 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
16573                 return -EPERM;
16574  
16575         *new_nsp = create_new_namespaces(unshare_flags, current,
16576 diff -NurpP --minimal linux-3.1/kernel/pid.c linux-3.1-vs2.3.1-rc2/kernel/pid.c
16577 --- linux-3.1/kernel/pid.c      2011-10-24 18:45:33.000000000 +0200
16578 +++ linux-3.1-vs2.3.1-rc2/kernel/pid.c  2011-10-24 18:53:33.000000000 +0200
16579 @@ -36,6 +36,7 @@
16580  #include <linux/pid_namespace.h>
16581  #include <linux/init_task.h>
16582  #include <linux/syscalls.h>
16583 +#include <linux/vs_pid.h>
16584  
16585  #define pid_hashfn(nr, ns)     \
16586         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
16587 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
16588  
16589  struct pid *find_vpid(int nr)
16590  {
16591 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
16592 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
16593  }
16594  EXPORT_SYMBOL_GPL(find_vpid);
16595  
16596 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
16597  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
16598  {
16599         struct task_struct *result = NULL;
16600 +
16601 +       if (type == PIDTYPE_REALPID)
16602 +               type = PIDTYPE_PID;
16603         if (pid) {
16604                 struct hlist_node *first;
16605                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
16606 @@ -419,7 +423,7 @@ EXPORT_SYMBOL(pid_task);
16607  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
16608  {
16609         rcu_lockdep_assert(rcu_read_lock_held());
16610 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
16611 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
16612  }
16613  
16614  struct task_struct *find_task_by_vpid(pid_t vnr)
16615 @@ -463,7 +467,7 @@ struct pid *find_get_pid(pid_t nr)
16616  }
16617  EXPORT_SYMBOL_GPL(find_get_pid);
16618  
16619 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
16620 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
16621  {
16622         struct upid *upid;
16623         pid_t nr = 0;
16624 @@ -476,6 +480,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
16625         return nr;
16626  }
16627  
16628 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
16629 +{
16630 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
16631 +}
16632 +
16633  pid_t pid_vnr(struct pid *pid)
16634  {
16635         return pid_nr_ns(pid, current->nsproxy->pid_ns);
16636 diff -NurpP --minimal linux-3.1/kernel/pid_namespace.c linux-3.1-vs2.3.1-rc2/kernel/pid_namespace.c
16637 --- linux-3.1/kernel/pid_namespace.c    2011-05-22 16:17:59.000000000 +0200
16638 +++ linux-3.1-vs2.3.1-rc2/kernel/pid_namespace.c        2011-10-24 18:53:33.000000000 +0200
16639 @@ -15,6 +15,7 @@
16640  #include <linux/acct.h>
16641  #include <linux/slab.h>
16642  #include <linux/proc_fs.h>
16643 +#include <linux/vserver/global.h>
16644  
16645  #define BITS_PER_PAGE          (PAGE_SIZE*8)
16646  
16647 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
16648                 goto out_free_map;
16649  
16650         kref_init(&ns->kref);
16651 +       atomic_inc(&vs_global_pid_ns);
16652         ns->level = level;
16653         ns->parent = get_pid_ns(parent_pid_ns);
16654  
16655 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
16656  
16657         for (i = 0; i < PIDMAP_ENTRIES; i++)
16658                 kfree(ns->pidmap[i].page);
16659 +       atomic_dec(&vs_global_pid_ns);
16660         kmem_cache_free(pid_ns_cachep, ns);
16661  }
16662  
16663 diff -NurpP --minimal linux-3.1/kernel/posix-timers.c linux-3.1-vs2.3.1-rc2/kernel/posix-timers.c
16664 --- linux-3.1/kernel/posix-timers.c     2011-07-22 11:18:12.000000000 +0200
16665 +++ linux-3.1-vs2.3.1-rc2/kernel/posix-timers.c 2011-10-24 18:53:33.000000000 +0200
16666 @@ -47,6 +47,7 @@
16667  #include <linux/wait.h>
16668  #include <linux/workqueue.h>
16669  #include <linux/module.h>
16670 +#include <linux/vs_context.h>
16671  
16672  /*
16673   * Management arrays for POSIX timers.  Timers are kept in slab memory
16674 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
16675  {
16676         struct task_struct *task;
16677         int shared, ret = -1;
16678 +
16679         /*
16680          * FIXME: if ->sigq is queued we can race with
16681          * dequeue_signal()->do_schedule_next_timer().
16682 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
16683         rcu_read_lock();
16684         task = pid_task(timr->it_pid, PIDTYPE_PID);
16685         if (task) {
16686 +               struct vx_info_save vxis;
16687 +               struct vx_info *vxi;
16688 +
16689 +               vxi = get_vx_info(task->vx_info);
16690 +               enter_vx_info(vxi, &vxis);
16691                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
16692                 ret = send_sigqueue(timr->sigq, task, shared);
16693 +               leave_vx_info(&vxis);
16694 +               put_vx_info(vxi);
16695         }
16696         rcu_read_unlock();
16697 +
16698         /* If we failed to send the signal the timer stops. */
16699         return ret > 0;
16700  }
16701 diff -NurpP --minimal linux-3.1/kernel/printk.c linux-3.1-vs2.3.1-rc2/kernel/printk.c
16702 --- linux-3.1/kernel/printk.c   2011-10-24 18:45:33.000000000 +0200
16703 +++ linux-3.1-vs2.3.1-rc2/kernel/printk.c       2011-10-24 18:53:33.000000000 +0200
16704 @@ -41,6 +41,7 @@
16705  #include <linux/cpu.h>
16706  #include <linux/notifier.h>
16707  #include <linux/rculist.h>
16708 +#include <linux/vs_cvirt.h>
16709  
16710  #include <asm/uaccess.h>
16711  
16712 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
16713                 return 0;
16714  
16715         if (syslog_action_restricted(type)) {
16716 -               if (capable(CAP_SYSLOG))
16717 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
16718                         return 0;
16719                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
16720                 if (capable(CAP_SYS_ADMIN)) {
16721 @@ -344,12 +345,9 @@ int do_syslog(int type, char __user *buf
16722         if (error)
16723                 return error;
16724  
16725 -       switch (type) {
16726 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
16727 -               break;
16728 -       case SYSLOG_ACTION_OPEN:        /* Open log */
16729 -               break;
16730 -       case SYSLOG_ACTION_READ:        /* Read from log */
16731 +       if ((type == SYSLOG_ACTION_READ) ||
16732 +           (type == SYSLOG_ACTION_READ_ALL) ||
16733 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
16734                 error = -EINVAL;
16735                 if (!buf || len < 0)
16736                         goto out;
16737 @@ -360,6 +358,16 @@ int do_syslog(int type, char __user *buf
16738                         error = -EFAULT;
16739                         goto out;
16740                 }
16741 +       }
16742 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16743 +               return vx_do_syslog(type, buf, len);
16744 +
16745 +       switch (type) {
16746 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
16747 +               break;
16748 +       case SYSLOG_ACTION_OPEN:        /* Open log */
16749 +               break;
16750 +       case SYSLOG_ACTION_READ:        /* Read from log */
16751                 error = wait_event_interruptible(log_wait,
16752                                                         (log_start - log_end));
16753                 if (error)
16754 @@ -386,16 +394,6 @@ int do_syslog(int type, char __user *buf
16755                 /* FALL THRU */
16756         /* Read last kernel messages */
16757         case SYSLOG_ACTION_READ_ALL:
16758 -               error = -EINVAL;
16759 -               if (!buf || len < 0)
16760 -                       goto out;
16761 -               error = 0;
16762 -               if (!len)
16763 -                       goto out;
16764 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16765 -                       error = -EFAULT;
16766 -                       goto out;
16767 -               }
16768                 count = len;
16769                 if (count > log_buf_len)
16770                         count = log_buf_len;
16771 diff -NurpP --minimal linux-3.1/kernel/ptrace.c linux-3.1-vs2.3.1-rc2/kernel/ptrace.c
16772 --- linux-3.1/kernel/ptrace.c   2011-10-24 18:45:33.000000000 +0200
16773 +++ linux-3.1-vs2.3.1-rc2/kernel/ptrace.c       2011-10-24 18:53:33.000000000 +0200
16774 @@ -22,6 +22,7 @@
16775  #include <linux/syscalls.h>
16776  #include <linux/uaccess.h>
16777  #include <linux/regset.h>
16778 +#include <linux/vs_context.h>
16779  #include <linux/hw_breakpoint.h>
16780  #include <linux/cn_proc.h>
16781  
16782 @@ -198,6 +199,11 @@ ok:
16783                 dumpable = get_dumpable(task->mm);
16784         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
16785                 return -EPERM;
16786 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
16787 +               return -EPERM;
16788 +       if (!vx_check(task->xid, VS_IDENT) &&
16789 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
16790 +               return -EACCES;
16791  
16792         return security_ptrace_access_check(task, mode);
16793  }
16794 diff -NurpP --minimal linux-3.1/kernel/sched.c linux-3.1-vs2.3.1-rc2/kernel/sched.c
16795 --- linux-3.1/kernel/sched.c    2011-10-24 18:45:33.000000000 +0200
16796 +++ linux-3.1-vs2.3.1-rc2/kernel/sched.c        2011-10-24 18:53:33.000000000 +0200
16797 @@ -71,6 +71,8 @@
16798  #include <linux/ctype.h>
16799  #include <linux/ftrace.h>
16800  #include <linux/slab.h>
16801 +#include <linux/vs_sched.h>
16802 +#include <linux/vs_cvirt.h>
16803  
16804  #include <asm/tlb.h>
16805  #include <asm/irq_regs.h>
16806 @@ -3473,9 +3475,17 @@ static void calc_global_nohz(unsigned lo
16807   */
16808  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
16809  {
16810 -       loads[0] = (avenrun[0] + offset) << shift;
16811 -       loads[1] = (avenrun[1] + offset) << shift;
16812 -       loads[2] = (avenrun[2] + offset) << shift;
16813 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
16814 +               struct vx_info *vxi = current_vx_info();
16815 +
16816 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
16817 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
16818 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
16819 +       } else {
16820 +               loads[0] = (avenrun[0] + offset) << shift;
16821 +               loads[1] = (avenrun[1] + offset) << shift;
16822 +               loads[2] = (avenrun[2] + offset) << shift;
16823 +       }
16824  }
16825  
16826  /*
16827 @@ -3734,16 +3744,19 @@ void account_user_time(struct task_struc
16828                        cputime_t cputime_scaled)
16829  {
16830         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16831 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16832         cputime64_t tmp;
16833 +       int nice = (TASK_NICE(p) > 0);
16834  
16835         /* Add user time to process. */
16836         p->utime = cputime_add(p->utime, cputime);
16837         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
16838 +       vx_account_user(vxi, cputime, nice);
16839         account_group_user_time(p, cputime);
16840  
16841         /* Add user time to cpustat. */
16842         tmp = cputime_to_cputime64(cputime);
16843 -       if (TASK_NICE(p) > 0)
16844 +       if (nice)
16845                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16846         else
16847                 cpustat->user = cputime64_add(cpustat->user, tmp);
16848 @@ -3795,10 +3808,12 @@ void __account_system_time(struct task_s
16849                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
16850  {
16851         cputime64_t tmp = cputime_to_cputime64(cputime);
16852 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16853  
16854         /* Add system time to process. */
16855         p->stime = cputime_add(p->stime, cputime);
16856         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
16857 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
16858         account_group_system_time(p, cputime);
16859  
16860         /* Add system time to cpustat. */
16861 @@ -4984,7 +4999,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16862                 nice = 19;
16863  
16864         if (increment < 0 && !can_nice(current, nice))
16865 -               return -EPERM;
16866 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16867  
16868         retval = security_task_setnice(current, nice);
16869         if (retval)
16870 diff -NurpP --minimal linux-3.1/kernel/sched_fair.c linux-3.1-vs2.3.1-rc2/kernel/sched_fair.c
16871 --- linux-3.1/kernel/sched_fair.c       2011-10-24 18:45:33.000000000 +0200
16872 +++ linux-3.1-vs2.3.1-rc2/kernel/sched_fair.c   2011-10-24 18:53:33.000000000 +0200
16873 @@ -979,6 +979,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16874                 __enqueue_entity(cfs_rq, se);
16875         se->on_rq = 1;
16876  
16877 +       if (entity_is_task(se))
16878 +               vx_activate_task(task_of(se));
16879         if (cfs_rq->nr_running == 1)
16880                 list_add_leaf_cfs_rq(cfs_rq);
16881  }
16882 @@ -1055,6 +1057,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16883         if (se != cfs_rq->curr)
16884                 __dequeue_entity(cfs_rq, se);
16885         se->on_rq = 0;
16886 +       if (entity_is_task(se))
16887 +               vx_deactivate_task(task_of(se));
16888         update_cfs_load(cfs_rq, 0);
16889         account_entity_dequeue(cfs_rq, se);
16890  
16891 diff -NurpP --minimal linux-3.1/kernel/signal.c linux-3.1-vs2.3.1-rc2/kernel/signal.c
16892 --- linux-3.1/kernel/signal.c   2011-10-24 18:45:33.000000000 +0200
16893 +++ linux-3.1-vs2.3.1-rc2/kernel/signal.c       2011-10-24 18:53:33.000000000 +0200
16894 @@ -28,6 +28,8 @@
16895  #include <linux/freezer.h>
16896  #include <linux/pid_namespace.h>
16897  #include <linux/nsproxy.h>
16898 +#include <linux/vs_context.h>
16899 +#include <linux/vs_pid.h>
16900  #define CREATE_TRACE_POINTS
16901  #include <trace/events/signal.h>
16902  
16903 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
16904         struct pid *sid;
16905         int error;
16906  
16907 +       vxdprintk(VXD_CBIT(misc, 7),
16908 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16909 +               sig, info, t, vx_task_xid(t), t->pid);
16910 +
16911         if (!valid_signal(sig))
16912                 return -EINVAL;
16913  
16914 +/*     FIXME: needed? if so, why?
16915 +       if ((info != SEND_SIG_NOINFO) &&
16916 +               (is_si_special(info) || !si_fromuser(info)))
16917 +               goto skip;      */
16918 +
16919         if (!si_fromuser(info))
16920                 return 0;
16921  
16922 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
16923                 }
16924         }
16925  
16926 +       error = -EPERM;
16927 +       if (t->pid == 1 && current->xid)
16928 +               return error;
16929 +
16930 +       error = -ESRCH;
16931 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
16932 +                 loops, maybe ENOENT or EACCES? */
16933 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16934 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16935 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16936 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16937 +               return error;
16938 +       }
16939 +/* skip: */
16940         return security_task_kill(t, info, sig, 0);
16941  }
16942  
16943 @@ -1319,7 +1344,7 @@ int kill_pid_info(int sig, struct siginf
16944         rcu_read_lock();
16945  retry:
16946         p = pid_task(pid, PIDTYPE_PID);
16947 -       if (p) {
16948 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
16949                 error = group_send_sig_info(sig, info, p);
16950                 if (unlikely(error == -ESRCH))
16951                         /*
16952 @@ -1358,7 +1383,7 @@ int kill_pid_info_as_uid(int sig, struct
16953  
16954         rcu_read_lock();
16955         p = pid_task(pid, PIDTYPE_PID);
16956 -       if (!p) {
16957 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16958                 ret = -ESRCH;
16959                 goto out_unlock;
16960         }
16961 @@ -1413,8 +1438,10 @@ static int kill_something_info(int sig, 
16962                 struct task_struct * p;
16963  
16964                 for_each_process(p) {
16965 -                       if (task_pid_vnr(p) > 1 &&
16966 -                                       !same_thread_group(p, current)) {
16967 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16968 +                               task_pid_vnr(p) > 1 &&
16969 +                               !same_thread_group(p, current) &&
16970 +                               !vx_current_initpid(p->pid)) {
16971                                 int err = group_send_sig_info(sig, info, p);
16972                                 ++count;
16973                                 if (err != -EPERM)
16974 @@ -2249,6 +2276,11 @@ relock:
16975                                 !sig_kernel_only(signr))
16976                         continue;
16977  
16978 +               /* virtual init is protected against user signals */
16979 +               if ((info->si_code == SI_USER) &&
16980 +                       vx_current_initpid(current->pid))
16981 +                       continue;
16982 +
16983                 if (sig_kernel_stop(signr)) {
16984                         /*
16985                          * The default action is to stop all threads in
16986 diff -NurpP --minimal linux-3.1/kernel/softirq.c linux-3.1-vs2.3.1-rc2/kernel/softirq.c
16987 --- linux-3.1/kernel/softirq.c  2011-07-22 11:18:12.000000000 +0200
16988 +++ linux-3.1-vs2.3.1-rc2/kernel/softirq.c      2011-10-24 18:53:33.000000000 +0200
16989 @@ -24,6 +24,7 @@
16990  #include <linux/ftrace.h>
16991  #include <linux/smp.h>
16992  #include <linux/tick.h>
16993 +#include <linux/vs_context.h>
16994  
16995  #define CREATE_TRACE_POINTS
16996  #include <trace/events/irq.h>
16997 diff -NurpP --minimal linux-3.1/kernel/sys.c linux-3.1-vs2.3.1-rc2/kernel/sys.c
16998 --- linux-3.1/kernel/sys.c      2011-10-24 18:45:33.000000000 +0200
16999 +++ linux-3.1-vs2.3.1-rc2/kernel/sys.c  2011-10-24 18:53:33.000000000 +0200
17000 @@ -44,6 +44,7 @@
17001  #include <linux/syscalls.h>
17002  #include <linux/kprobes.h>
17003  #include <linux/user_namespace.h>
17004 +#include <linux/vs_pid.h>
17005  
17006  #include <linux/kmsg_dump.h>
17007  /* Move somewhere else to avoid recompiling? */
17008 @@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
17009                 goto out;
17010         }
17011         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17012 -               error = -EACCES;
17013 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17014 +                       error = 0;
17015 +               else
17016 +                       error = -EACCES;
17017                 goto out;
17018         }
17019         no_nice = security_task_setnice(p, niceval);
17020 @@ -204,6 +208,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
17021                         else
17022                                 pgrp = task_pgrp(current);
17023                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17024 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17025 +                                       continue;
17026                                 error = set_one_prio(p, niceval, error);
17027                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
17028                         break;
17029 @@ -267,6 +273,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
17030                         else
17031                                 pgrp = task_pgrp(current);
17032                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17033 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17034 +                                       continue;
17035                                 niceval = 20 - task_nice(p);
17036                                 if (niceval > retval)
17037                                         retval = niceval;
17038 @@ -417,6 +425,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
17039  
17040  static DEFINE_MUTEX(reboot_mutex);
17041  
17042 +long vs_reboot(unsigned int, void __user *);
17043 +
17044  /*
17045   * Reboot system call: for obvious reasons only root may call it,
17046   * and even root needs to set up some magic numbers in the registers
17047 @@ -449,6 +459,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
17048         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17049                 cmd = LINUX_REBOOT_CMD_HALT;
17050  
17051 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17052 +               return vs_reboot(cmd, arg);
17053 +
17054         mutex_lock(&reboot_mutex);
17055         switch (cmd) {
17056         case LINUX_REBOOT_CMD_RESTART:
17057 @@ -1272,7 +1285,8 @@ SYSCALL_DEFINE2(sethostname, char __user
17058         int errno;
17059         char tmp[__NEW_UTS_LEN];
17060  
17061 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
17062 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
17063 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17064                 return -EPERM;
17065  
17066         if (len < 0 || len > __NEW_UTS_LEN)
17067 @@ -1322,7 +1336,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
17068         int errno;
17069         char tmp[__NEW_UTS_LEN];
17070  
17071 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
17072 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
17073 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17074                 return -EPERM;
17075         if (len < 0 || len > __NEW_UTS_LEN)
17076                 return -EINVAL;
17077 @@ -1440,7 +1455,7 @@ int do_prlimit(struct task_struct *tsk, 
17078                 /* Keep the capable check against init_user_ns until
17079                    cgroups can contain all limits */
17080                 if (new_rlim->rlim_max > rlim->rlim_max &&
17081 -                               !capable(CAP_SYS_RESOURCE))
17082 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17083                         retval = -EPERM;
17084                 if (!retval)
17085                         retval = security_task_setrlimit(tsk->group_leader,
17086 @@ -1494,7 +1509,8 @@ static int check_prlimit_permission(stru
17087              cred->gid == tcred->sgid &&
17088              cred->gid == tcred->gid))
17089                 return 0;
17090 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
17091 +       if (vx_ns_capable(tcred->user->user_ns,
17092 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17093                 return 0;
17094  
17095         return -EPERM;
17096 diff -NurpP --minimal linux-3.1/kernel/sysctl.c linux-3.1-vs2.3.1-rc2/kernel/sysctl.c
17097 --- linux-3.1/kernel/sysctl.c   2011-10-24 18:45:33.000000000 +0200
17098 +++ linux-3.1-vs2.3.1-rc2/kernel/sysctl.c       2011-10-24 18:53:33.000000000 +0200
17099 @@ -75,6 +75,7 @@
17100  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
17101  #include <linux/lockdep.h>
17102  #endif
17103 +extern char vshelper_path[];
17104  #ifdef CONFIG_CHR_DEV_SG
17105  #include <scsi/sg.h>
17106  #endif
17107 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
17108                 .proc_handler   = proc_dostring,
17109         },
17110  #endif
17111 +       {
17112 +               .procname       = "vshelper",
17113 +               .data           = &vshelper_path,
17114 +               .maxlen         = 256,
17115 +               .mode           = 0644,
17116 +               .proc_handler   = &proc_dostring,
17117 +       },
17118  #ifdef CONFIG_CHR_DEV_SG
17119         {
17120                 .procname       = "sg-big-buff",
17121 diff -NurpP --minimal linux-3.1/kernel/sysctl_binary.c linux-3.1-vs2.3.1-rc2/kernel/sysctl_binary.c
17122 --- linux-3.1/kernel/sysctl_binary.c    2011-10-24 18:45:33.000000000 +0200
17123 +++ linux-3.1-vs2.3.1-rc2/kernel/sysctl_binary.c        2011-10-24 18:53:33.000000000 +0200
17124 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
17125  
17126         { CTL_INT,      KERN_PANIC,                     "panic" },
17127         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
17128 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
17129  
17130         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
17131         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
17132 diff -NurpP --minimal linux-3.1/kernel/time/timekeeping.c linux-3.1-vs2.3.1-rc2/kernel/time/timekeeping.c
17133 --- linux-3.1/kernel/time/timekeeping.c 2011-10-24 18:45:33.000000000 +0200
17134 +++ linux-3.1-vs2.3.1-rc2/kernel/time/timekeeping.c     2011-10-24 18:53:33.000000000 +0200
17135 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
17136         } while (read_seqretry(&xtime_lock, seq));
17137  
17138         timespec_add_ns(ts, nsecs);
17139 +       vx_adjust_timespec(ts);
17140  }
17141  
17142  EXPORT_SYMBOL(getnstimeofday);
17143 diff -NurpP --minimal linux-3.1/kernel/time.c linux-3.1-vs2.3.1-rc2/kernel/time.c
17144 --- linux-3.1/kernel/time.c     2011-05-22 16:17:59.000000000 +0200
17145 +++ linux-3.1-vs2.3.1-rc2/kernel/time.c 2011-10-24 18:53:33.000000000 +0200
17146 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17147         if (err)
17148                 return err;
17149  
17150 -       do_settimeofday(&tv);
17151 +       vx_settimeofday(&tv);
17152         return 0;
17153  }
17154  
17155 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
17156                 /* SMP safe, again the code in arch/foo/time.c should
17157                  * globally block out interrupts when it runs.
17158                  */
17159 -               return do_settimeofday(tv);
17160 +               return vx_settimeofday(tv);
17161         }
17162         return 0;
17163  }
17164 diff -NurpP --minimal linux-3.1/kernel/timer.c linux-3.1-vs2.3.1-rc2/kernel/timer.c
17165 --- linux-3.1/kernel/timer.c    2011-07-22 11:18:12.000000000 +0200
17166 +++ linux-3.1-vs2.3.1-rc2/kernel/timer.c        2011-10-24 18:53:33.000000000 +0200
17167 @@ -40,6 +40,10 @@
17168  #include <linux/irq_work.h>
17169  #include <linux/sched.h>
17170  #include <linux/slab.h>
17171 +#include <linux/vs_base.h>
17172 +#include <linux/vs_cvirt.h>
17173 +#include <linux/vs_pid.h>
17174 +#include <linux/vserver/sched.h>
17175  
17176  #include <asm/uaccess.h>
17177  #include <asm/unistd.h>
17178 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17179  
17180  #endif
17181  
17182 -#ifndef __alpha__
17183 -
17184 -/*
17185 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17186 - * should be moved into arch/i386 instead?
17187 - */
17188  
17189  /**
17190   * sys_getpid - return the thread group id of the current process
17191 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
17192         rcu_read_lock();
17193         pid = task_tgid_vnr(current->real_parent);
17194         rcu_read_unlock();
17195 +       return vx_map_pid(pid);
17196 +}
17197  
17198 -       return pid;
17199 +#ifdef __alpha__
17200 +
17201 +/*
17202 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17203 + */
17204 +
17205 +asmlinkage long do_getxpid(long *ppid)
17206 +{
17207 +       *ppid = sys_getppid();
17208 +       return sys_getpid();
17209  }
17210  
17211 +#else /* _alpha_ */
17212 +
17213  SYSCALL_DEFINE0(getuid)
17214  {
17215         /* Only we change this so SMP safe */
17216 diff -NurpP --minimal linux-3.1/kernel/user_namespace.c linux-3.1-vs2.3.1-rc2/kernel/user_namespace.c
17217 --- linux-3.1/kernel/user_namespace.c   2011-03-15 18:07:42.000000000 +0100
17218 +++ linux-3.1-vs2.3.1-rc2/kernel/user_namespace.c       2011-10-24 18:53:33.000000000 +0200
17219 @@ -11,6 +11,7 @@
17220  #include <linux/user_namespace.h>
17221  #include <linux/highuid.h>
17222  #include <linux/cred.h>
17223 +#include <linux/vserver/global.h>
17224  
17225  static struct kmem_cache *user_ns_cachep __read_mostly;
17226  
17227 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
17228                 return -ENOMEM;
17229  
17230         kref_init(&ns->kref);
17231 +       atomic_inc(&vs_global_user_ns);
17232  
17233         for (n = 0; n < UIDHASH_SZ; ++n)
17234                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17235 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
17236         struct user_namespace *ns =
17237                 container_of(kref, struct user_namespace, kref);
17238  
17239 +       /* FIXME: maybe move into destroyer? */
17240 +       atomic_dec(&vs_global_user_ns);
17241         INIT_WORK(&ns->destroyer, free_user_ns_work);
17242         schedule_work(&ns->destroyer);
17243  }
17244 diff -NurpP --minimal linux-3.1/kernel/utsname.c linux-3.1-vs2.3.1-rc2/kernel/utsname.c
17245 --- linux-3.1/kernel/utsname.c  2011-07-22 11:18:12.000000000 +0200
17246 +++ linux-3.1-vs2.3.1-rc2/kernel/utsname.c      2011-10-24 18:53:33.000000000 +0200
17247 @@ -16,14 +16,17 @@
17248  #include <linux/slab.h>
17249  #include <linux/user_namespace.h>
17250  #include <linux/proc_fs.h>
17251 +#include <linux/vserver/global.h>
17252  
17253  static struct uts_namespace *create_uts_ns(void)
17254  {
17255         struct uts_namespace *uts_ns;
17256  
17257         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
17258 -       if (uts_ns)
17259 +       if (uts_ns) {
17260                 kref_init(&uts_ns->kref);
17261 +               atomic_inc(&vs_global_uts_ns);
17262 +       }
17263         return uts_ns;
17264  }
17265  
17266 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
17267   * @old_ns: namespace to clone
17268   * Return NULL on error (failure to kmalloc), new ns otherwise
17269   */
17270 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
17271 -                                         struct uts_namespace *old_ns)
17272 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
17273 +                                         struct user_namespace *old_user)
17274  {
17275         struct uts_namespace *ns;
17276  
17277 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
17278  
17279         down_read(&uts_sem);
17280         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17281 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
17282 +       ns->user_ns = get_user_ns(old_user);
17283         up_read(&uts_sem);
17284         return ns;
17285  }
17286 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
17287   * versa.
17288   */
17289  struct uts_namespace *copy_utsname(unsigned long flags,
17290 -                                  struct task_struct *tsk)
17291 +                                  struct uts_namespace *old_ns,
17292 +                                  struct user_namespace *user_ns)
17293  {
17294 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
17295         struct uts_namespace *new_ns;
17296  
17297         BUG_ON(!old_ns);
17298 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
17299         if (!(flags & CLONE_NEWUTS))
17300                 return old_ns;
17301  
17302 -       new_ns = clone_uts_ns(tsk, old_ns);
17303 +       new_ns = clone_uts_ns(old_ns, user_ns);
17304  
17305         put_uts_ns(old_ns);
17306         return new_ns;
17307 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
17308  
17309         ns = container_of(kref, struct uts_namespace, kref);
17310         put_user_ns(ns->user_ns);
17311 +       atomic_dec(&vs_global_uts_ns);
17312         kfree(ns);
17313  }
17314  
17315 diff -NurpP --minimal linux-3.1/kernel/vserver/Kconfig linux-3.1-vs2.3.1-rc2/kernel/vserver/Kconfig
17316 --- linux-3.1/kernel/vserver/Kconfig    1970-01-01 01:00:00.000000000 +0100
17317 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/Kconfig        2011-10-24 18:53:33.000000000 +0200
17318 @@ -0,0 +1,232 @@
17319 +#
17320 +# Linux VServer configuration
17321 +#
17322 +
17323 +menu "Linux VServer"
17324 +
17325 +config VSERVER_AUTO_LBACK
17326 +       bool    "Automatically Assign Loopback IP"
17327 +       default y
17328 +       help
17329 +         Automatically assign a guest specific loopback
17330 +         IP and add it to the kernel network stack on
17331 +         startup.
17332 +
17333 +config VSERVER_AUTO_SINGLE
17334 +       bool    "Automatic Single IP Special Casing"
17335 +       depends on EXPERIMENTAL
17336 +       default y
17337 +       help
17338 +         This allows network contexts with a single IP to
17339 +         automatically remap 0.0.0.0 bindings to that IP,
17340 +         avoiding further network checks and improving
17341 +         performance.
17342 +
17343 +         (note: such guests do not allow to change the ip
17344 +          on the fly and do not show loopback addresses)
17345 +
17346 +config VSERVER_COWBL
17347 +       bool    "Enable COW Immutable Link Breaking"
17348 +       default y
17349 +       help
17350 +         This enables the COW (Copy-On-Write) link break code.
17351 +         It allows you to treat unified files like normal files
17352 +         when writing to them (which will implicitely break the
17353 +         link and create a copy of the unified file)
17354 +
17355 +config VSERVER_VTIME
17356 +       bool    "Enable Virtualized Guest Time"
17357 +       depends on EXPERIMENTAL
17358 +       default n
17359 +       help
17360 +         This enables per guest time offsets to allow for
17361 +         adjusting the system clock individually per guest.
17362 +         this adds some overhead to the time functions and
17363 +         therefore should not be enabled without good reason.
17364 +
17365 +config VSERVER_DEVICE
17366 +       bool    "Enable Guest Device Mapping"
17367 +       depends on EXPERIMENTAL
17368 +       default n
17369 +       help
17370 +         This enables generic device remapping.
17371 +
17372 +config VSERVER_PROC_SECURE
17373 +       bool    "Enable Proc Security"
17374 +       depends on PROC_FS
17375 +       default y
17376 +       help
17377 +         This configures ProcFS security to initially hide
17378 +         non-process entries for all contexts except the main and
17379 +         spectator context (i.e. for all guests), which is a secure
17380 +         default.
17381 +
17382 +         (note: on 1.2x the entries were visible by default)
17383 +
17384 +choice
17385 +       prompt  "Persistent Inode Tagging"
17386 +       default TAGGING_ID24
17387 +       help
17388 +         This adds persistent context information to filesystems
17389 +         mounted with the tagxid option. Tagging is a requirement
17390 +         for per-context disk limits and per-context quota.
17391 +
17392 +
17393 +config TAGGING_NONE
17394 +       bool    "Disabled"
17395 +       help
17396 +         do not store per-context information in inodes.
17397 +
17398 +config TAGGING_UID16
17399 +       bool    "UID16/GID32"
17400 +       help
17401 +         reduces UID to 16 bit, but leaves GID at 32 bit.
17402 +
17403 +config TAGGING_GID16
17404 +       bool    "UID32/GID16"
17405 +       help
17406 +         reduces GID to 16 bit, but leaves UID at 32 bit.
17407 +
17408 +config TAGGING_ID24
17409 +       bool    "UID24/GID24"
17410 +       help
17411 +         uses the upper 8bit from UID and GID for XID tagging
17412 +         which leaves 24bit for UID/GID each, which should be
17413 +         more than sufficient for normal use.
17414 +
17415 +config TAGGING_INTERN
17416 +       bool    "UID32/GID32"
17417 +       help
17418 +         this uses otherwise reserved inode fields in the on
17419 +         disk representation, which limits the use to a few
17420 +         filesystems (currently ext2 and ext3)
17421 +
17422 +endchoice
17423 +
17424 +config TAG_NFSD
17425 +       bool    "Tag NFSD User Auth and Files"
17426 +       default n
17427 +       help
17428 +         Enable this if you do want the in-kernel NFS
17429 +         Server to use the tagging specified above.
17430 +         (will require patched clients too)
17431 +
17432 +config VSERVER_PRIVACY
17433 +       bool    "Honor Privacy Aspects of Guests"
17434 +       default n
17435 +       help
17436 +         When enabled, most context checks will disallow
17437 +         access to structures assigned to a specific context,
17438 +         like ptys or loop devices.
17439 +
17440 +config VSERVER_CONTEXTS
17441 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
17442 +       range 1 65533
17443 +       default "768"   if 64BIT
17444 +       default "256"
17445 +       help
17446 +         This setting will optimize certain data structures
17447 +         and memory allocations according to the expected
17448 +         maximum.
17449 +
17450 +         note: this is not a strict upper limit.
17451 +
17452 +config VSERVER_WARN
17453 +       bool    "VServer Warnings"
17454 +       default y
17455 +       help
17456 +         This enables various runtime warnings, which will
17457 +         notify about potential manipulation attempts or
17458 +         resource shortage. It is generally considered to
17459 +         be a good idea to have that enabled.
17460 +
17461 +config VSERVER_WARN_DEVPTS
17462 +       bool    "VServer DevPTS Warnings"
17463 +       depends on VSERVER_WARN
17464 +       default y
17465 +       help
17466 +         This enables DevPTS related warnings, issued when a
17467 +         process inside a context tries to lookup or access
17468 +         a dynamic pts from the host or a different context.
17469 +
17470 +config VSERVER_DEBUG
17471 +       bool    "VServer Debugging Code"
17472 +       default n
17473 +       help
17474 +         Set this to yes if you want to be able to activate
17475 +         debugging output at runtime. It adds a very small
17476 +         overhead to all vserver related functions and
17477 +         increases the kernel size by about 20k.
17478 +
17479 +config VSERVER_HISTORY
17480 +       bool    "VServer History Tracing"
17481 +       depends on VSERVER_DEBUG
17482 +       default n
17483 +       help
17484 +         Set this to yes if you want to record the history of
17485 +         linux-vserver activities, so they can be replayed in
17486 +         the event of a kernel panic or oops.
17487 +
17488 +config VSERVER_HISTORY_SIZE
17489 +       int     "Per-CPU History Size (32-65536)"
17490 +       depends on VSERVER_HISTORY
17491 +       range 32 65536
17492 +       default 64
17493 +       help
17494 +         This allows you to specify the number of entries in
17495 +         the per-CPU history buffer.
17496 +
17497 +config VSERVER_LEGACY_MEM
17498 +       bool    "Legacy Memory Limits"
17499 +       default n
17500 +       help
17501 +         This provides fake memory limits to keep
17502 +         older tools happy in the face of memory
17503 +         cgroups
17504 +
17505 +choice
17506 +       prompt  "Quotes used in debug and warn messages"
17507 +       default QUOTES_ISO8859
17508 +
17509 +config QUOTES_ISO8859
17510 +       bool    "Extended ASCII (ISO 8859) angle quotes"
17511 +       help
17512 +         This uses the extended ASCII characters \xbb
17513 +         and \xab for quoting file and process names.
17514 +
17515 +config QUOTES_UTF8
17516 +       bool    "UTF-8 angle quotes"
17517 +       help
17518 +         This uses the the UTF-8 sequences for angle
17519 +         quotes to quote file and process names.
17520 +
17521 +config QUOTES_ASCII
17522 +       bool    "ASCII single quotes"
17523 +       help
17524 +         This uses the ASCII single quote character
17525 +         (\x27) to quote file and process names.
17526 +
17527 +endchoice
17528 +
17529 +endmenu
17530 +
17531 +
17532 +config VSERVER
17533 +       bool
17534 +       default y
17535 +       select NAMESPACES
17536 +       select UTS_NS
17537 +       select IPC_NS
17538 +#      select USER_NS
17539 +       select SYSVIPC
17540 +
17541 +config VSERVER_SECURITY
17542 +       bool
17543 +       depends on SECURITY
17544 +       default y
17545 +       select SECURITY_CAPABILITIES
17546 +
17547 +config VSERVER_DISABLED
17548 +       bool
17549 +       default n
17550 +
17551 diff -NurpP --minimal linux-3.1/kernel/vserver/Makefile linux-3.1-vs2.3.1-rc2/kernel/vserver/Makefile
17552 --- linux-3.1/kernel/vserver/Makefile   1970-01-01 01:00:00.000000000 +0100
17553 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/Makefile       2011-10-24 18:53:33.000000000 +0200
17554 @@ -0,0 +1,18 @@
17555 +#
17556 +# Makefile for the Linux vserver routines.
17557 +#
17558 +
17559 +
17560 +obj-y          += vserver.o
17561 +
17562 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
17563 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
17564 +                  dlimit.o tag.o
17565 +
17566 +vserver-$(CONFIG_INET) += inet.o
17567 +vserver-$(CONFIG_PROC_FS) += proc.o
17568 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
17569 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
17570 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
17571 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
17572 +
17573 diff -NurpP --minimal linux-3.1/kernel/vserver/cacct.c linux-3.1-vs2.3.1-rc2/kernel/vserver/cacct.c
17574 --- linux-3.1/kernel/vserver/cacct.c    1970-01-01 01:00:00.000000000 +0100
17575 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/cacct.c        2011-10-24 18:53:33.000000000 +0200
17576 @@ -0,0 +1,42 @@
17577 +/*
17578 + *  linux/kernel/vserver/cacct.c
17579 + *
17580 + *  Virtual Server: Context Accounting
17581 + *
17582 + *  Copyright (C) 2006-2007 Herbert Pötzl
17583 + *
17584 + *  V0.01  added accounting stats
17585 + *
17586 + */
17587 +
17588 +#include <linux/types.h>
17589 +#include <linux/vs_context.h>
17590 +#include <linux/vserver/cacct_cmd.h>
17591 +#include <linux/vserver/cacct_int.h>
17592 +
17593 +#include <asm/errno.h>
17594 +#include <asm/uaccess.h>
17595 +
17596 +
17597 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17598 +{
17599 +       struct vcmd_sock_stat_v0 vc_data;
17600 +       int j, field;
17601 +
17602 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17603 +               return -EFAULT;
17604 +
17605 +       field = vc_data.field;
17606 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17607 +               return -EINVAL;
17608 +
17609 +       for (j = 0; j < 3; j++) {
17610 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17611 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17612 +       }
17613 +
17614 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17615 +               return -EFAULT;
17616 +       return 0;
17617 +}
17618 +
17619 diff -NurpP --minimal linux-3.1/kernel/vserver/cacct_init.h linux-3.1-vs2.3.1-rc2/kernel/vserver/cacct_init.h
17620 --- linux-3.1/kernel/vserver/cacct_init.h       1970-01-01 01:00:00.000000000 +0100
17621 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/cacct_init.h   2011-10-24 18:53:33.000000000 +0200
17622 @@ -0,0 +1,25 @@
17623 +
17624 +
17625 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17626 +{
17627 +       int i, j;
17628 +
17629 +
17630 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17631 +               for (j = 0; j < 3; j++) {
17632 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
17633 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
17634 +               }
17635 +       }
17636 +       for (i = 0; i < 8; i++)
17637 +               atomic_set(&cacct->slab[i], 0);
17638 +       for (i = 0; i < 5; i++)
17639 +               for (j = 0; j < 4; j++)
17640 +                       atomic_set(&cacct->page[i][j], 0);
17641 +}
17642 +
17643 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17644 +{
17645 +       return;
17646 +}
17647 +
17648 diff -NurpP --minimal linux-3.1/kernel/vserver/cacct_proc.h linux-3.1-vs2.3.1-rc2/kernel/vserver/cacct_proc.h
17649 --- linux-3.1/kernel/vserver/cacct_proc.h       1970-01-01 01:00:00.000000000 +0100
17650 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/cacct_proc.h   2011-10-24 18:53:33.000000000 +0200
17651 @@ -0,0 +1,53 @@
17652 +#ifndef _VX_CACCT_PROC_H
17653 +#define _VX_CACCT_PROC_H
17654 +
17655 +#include <linux/vserver/cacct_int.h>
17656 +
17657 +
17658 +#define VX_SOCKA_TOP   \
17659 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17660 +
17661 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17662 +{
17663 +       int i, j, length = 0;
17664 +       static char *type[VXA_SOCK_SIZE] = {
17665 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17666 +       };
17667 +
17668 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17669 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17670 +               length += sprintf(buffer + length, "%s:", type[i]);
17671 +               for (j = 0; j < 3; j++) {
17672 +                       length += sprintf(buffer + length,
17673 +                               "\t%10lu/%-10lu",
17674 +                               vx_sock_count(cacct, i, j),
17675 +                               vx_sock_total(cacct, i, j));
17676 +               }
17677 +               buffer[length++] = '\n';
17678 +       }
17679 +
17680 +       length += sprintf(buffer + length, "\n");
17681 +       length += sprintf(buffer + length,
17682 +               "slab:\t %8u %8u %8u %8u\n",
17683 +               atomic_read(&cacct->slab[1]),
17684 +               atomic_read(&cacct->slab[4]),
17685 +               atomic_read(&cacct->slab[0]),
17686 +               atomic_read(&cacct->slab[2]));
17687 +
17688 +       length += sprintf(buffer + length, "\n");
17689 +       for (i = 0; i < 5; i++) {
17690 +               length += sprintf(buffer + length,
17691 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17692 +                       atomic_read(&cacct->page[i][0]),
17693 +                       atomic_read(&cacct->page[i][1]),
17694 +                       atomic_read(&cacct->page[i][2]),
17695 +                       atomic_read(&cacct->page[i][3]),
17696 +                       atomic_read(&cacct->page[i][4]),
17697 +                       atomic_read(&cacct->page[i][5]),
17698 +                       atomic_read(&cacct->page[i][6]),
17699 +                       atomic_read(&cacct->page[i][7]));
17700 +       }
17701 +       return length;
17702 +}
17703 +
17704 +#endif /* _VX_CACCT_PROC_H */
17705 diff -NurpP --minimal linux-3.1/kernel/vserver/context.c linux-3.1-vs2.3.1-rc2/kernel/vserver/context.c
17706 --- linux-3.1/kernel/vserver/context.c  1970-01-01 01:00:00.000000000 +0100
17707 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/context.c      2011-10-24 18:53:33.000000000 +0200
17708 @@ -0,0 +1,1107 @@
17709 +/*
17710 + *  linux/kernel/vserver/context.c
17711 + *
17712 + *  Virtual Server: Context Support
17713 + *
17714 + *  Copyright (C) 2003-2011  Herbert Pötzl
17715 + *
17716 + *  V0.01  context helper
17717 + *  V0.02  vx_ctx_kill syscall command
17718 + *  V0.03  replaced context_info calls
17719 + *  V0.04  redesign of struct (de)alloc
17720 + *  V0.05  rlimit basic implementation
17721 + *  V0.06  task_xid and info commands
17722 + *  V0.07  context flags and caps
17723 + *  V0.08  switch to RCU based hash
17724 + *  V0.09  revert to non RCU for now
17725 + *  V0.10  and back to working RCU hash
17726 + *  V0.11  and back to locking again
17727 + *  V0.12  referenced context store
17728 + *  V0.13  separate per cpu data
17729 + *  V0.14  changed vcmds to vxi arg
17730 + *  V0.15  added context stat
17731 + *  V0.16  have __create claim() the vxi
17732 + *  V0.17  removed older and legacy stuff
17733 + *  V0.18  added user credentials
17734 + *  V0.19  added warn mask
17735 + *
17736 + */
17737 +
17738 +#include <linux/slab.h>
17739 +#include <linux/types.h>
17740 +#include <linux/security.h>
17741 +#include <linux/pid_namespace.h>
17742 +#include <linux/capability.h>
17743 +
17744 +#include <linux/vserver/context.h>
17745 +#include <linux/vserver/network.h>
17746 +#include <linux/vserver/debug.h>
17747 +#include <linux/vserver/limit.h>
17748 +#include <linux/vserver/limit_int.h>
17749 +#include <linux/vserver/space.h>
17750 +#include <linux/init_task.h>
17751 +#include <linux/fs_struct.h>
17752 +#include <linux/cred.h>
17753 +
17754 +#include <linux/vs_context.h>
17755 +#include <linux/vs_limit.h>
17756 +#include <linux/vs_pid.h>
17757 +#include <linux/vserver/context_cmd.h>
17758 +
17759 +#include "cvirt_init.h"
17760 +#include "cacct_init.h"
17761 +#include "limit_init.h"
17762 +#include "sched_init.h"
17763 +
17764 +
17765 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17766 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17767 +
17768 +
17769 +/*     now inactive context structures */
17770 +
17771 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17772 +
17773 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
17774 +
17775 +
17776 +/*     __alloc_vx_info()
17777 +
17778 +       * allocate an initialized vx_info struct
17779 +       * doesn't make it visible (hash)                        */
17780 +
17781 +static struct vx_info *__alloc_vx_info(xid_t xid)
17782 +{
17783 +       struct vx_info *new = NULL;
17784 +       int cpu, index;
17785 +
17786 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17787 +
17788 +       /* would this benefit from a slab cache? */
17789 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17790 +       if (!new)
17791 +               return 0;
17792 +
17793 +       memset(new, 0, sizeof(struct vx_info));
17794 +#ifdef CONFIG_SMP
17795 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17796 +       if (!new->ptr_pc)
17797 +               goto error;
17798 +#endif
17799 +       new->vx_id = xid;
17800 +       INIT_HLIST_NODE(&new->vx_hlist);
17801 +       atomic_set(&new->vx_usecnt, 0);
17802 +       atomic_set(&new->vx_tasks, 0);
17803 +       new->vx_parent = NULL;
17804 +       new->vx_state = 0;
17805 +       init_waitqueue_head(&new->vx_wait);
17806 +
17807 +       /* prepare reaper */
17808 +       get_task_struct(init_pid_ns.child_reaper);
17809 +       new->vx_reaper = init_pid_ns.child_reaper;
17810 +       new->vx_badness_bias = 0;
17811 +
17812 +       /* rest of init goes here */
17813 +       vx_info_init_limit(&new->limit);
17814 +       vx_info_init_sched(&new->sched);
17815 +       vx_info_init_cvirt(&new->cvirt);
17816 +       vx_info_init_cacct(&new->cacct);
17817 +
17818 +       /* per cpu data structures */
17819 +       for_each_possible_cpu(cpu) {
17820 +               vx_info_init_sched_pc(
17821 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17822 +               vx_info_init_cvirt_pc(
17823 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17824 +       }
17825 +
17826 +       new->vx_flags = VXF_INIT_SET;
17827 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
17828 +       new->vx_ccaps = 0;
17829 +       new->vx_umask = 0;
17830 +       new->vx_wmask = 0;
17831 +
17832 +       new->reboot_cmd = 0;
17833 +       new->exit_code = 0;
17834 +
17835 +       // preconfig spaces
17836 +       for (index = 0; index < VX_SPACES; index++) {
17837 +               struct _vx_space *space = &new->space[index];
17838 +
17839 +               // filesystem
17840 +               spin_lock(&init_fs.lock);
17841 +               init_fs.users++;
17842 +               spin_unlock(&init_fs.lock);
17843 +               space->vx_fs = &init_fs;
17844 +
17845 +               /* FIXME: do we want defaults? */
17846 +               // space->vx_real_cred = 0;
17847 +               // space->vx_cred = 0;
17848 +       }
17849 +
17850 +
17851 +       vxdprintk(VXD_CBIT(xid, 0),
17852 +               "alloc_vx_info(%d) = %p", xid, new);
17853 +       vxh_alloc_vx_info(new);
17854 +       atomic_inc(&vx_global_ctotal);
17855 +       return new;
17856 +#ifdef CONFIG_SMP
17857 +error:
17858 +       kfree(new);
17859 +       return 0;
17860 +#endif
17861 +}
17862 +
17863 +/*     __dealloc_vx_info()
17864 +
17865 +       * final disposal of vx_info                             */
17866 +
17867 +static void __dealloc_vx_info(struct vx_info *vxi)
17868 +{
17869 +#ifdef CONFIG_VSERVER_WARN
17870 +       struct vx_info_save vxis;
17871 +       int cpu;
17872 +#endif
17873 +       vxdprintk(VXD_CBIT(xid, 0),
17874 +               "dealloc_vx_info(%p)", vxi);
17875 +       vxh_dealloc_vx_info(vxi);
17876 +
17877 +#ifdef CONFIG_VSERVER_WARN
17878 +       enter_vx_info(vxi, &vxis);
17879 +       vx_info_exit_limit(&vxi->limit);
17880 +       vx_info_exit_sched(&vxi->sched);
17881 +       vx_info_exit_cvirt(&vxi->cvirt);
17882 +       vx_info_exit_cacct(&vxi->cacct);
17883 +
17884 +       for_each_possible_cpu(cpu) {
17885 +               vx_info_exit_sched_pc(
17886 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17887 +               vx_info_exit_cvirt_pc(
17888 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17889 +       }
17890 +       leave_vx_info(&vxis);
17891 +#endif
17892 +
17893 +       vxi->vx_id = -1;
17894 +       vxi->vx_state |= VXS_RELEASED;
17895 +
17896 +#ifdef CONFIG_SMP
17897 +       free_percpu(vxi->ptr_pc);
17898 +#endif
17899 +       kfree(vxi);
17900 +       atomic_dec(&vx_global_ctotal);
17901 +}
17902 +
17903 +static void __shutdown_vx_info(struct vx_info *vxi)
17904 +{
17905 +       struct nsproxy *nsproxy;
17906 +       struct fs_struct *fs;
17907 +       struct cred *cred;
17908 +       int index, kill;
17909 +
17910 +       might_sleep();
17911 +
17912 +       vxi->vx_state |= VXS_SHUTDOWN;
17913 +       vs_state_change(vxi, VSC_SHUTDOWN);
17914 +
17915 +       for (index = 0; index < VX_SPACES; index++) {
17916 +               struct _vx_space *space = &vxi->space[index];
17917 +
17918 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
17919 +               if (nsproxy)
17920 +                       put_nsproxy(nsproxy);
17921 +
17922 +               fs = xchg(&space->vx_fs, NULL);
17923 +               spin_lock(&fs->lock);
17924 +               kill = !--fs->users;
17925 +               spin_unlock(&fs->lock);
17926 +               if (kill)
17927 +                       free_fs_struct(fs);
17928 +
17929 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
17930 +               if (cred)
17931 +                       abort_creds(cred);
17932 +       }
17933 +}
17934 +
17935 +/* exported stuff */
17936 +
17937 +void free_vx_info(struct vx_info *vxi)
17938 +{
17939 +       unsigned long flags;
17940 +       unsigned index;
17941 +
17942 +       /* check for reference counts first */
17943 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17944 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17945 +
17946 +       /* context must not be hashed */
17947 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17948 +
17949 +       /* context shutdown is mandatory */
17950 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17951 +
17952 +       /* spaces check */
17953 +       for (index = 0; index < VX_SPACES; index++) {
17954 +               struct _vx_space *space = &vxi->space[index];
17955 +
17956 +               BUG_ON(space->vx_nsproxy);
17957 +               BUG_ON(space->vx_fs);
17958 +               // BUG_ON(space->vx_real_cred);
17959 +               // BUG_ON(space->vx_cred);
17960 +       }
17961 +
17962 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17963 +       hlist_del(&vxi->vx_hlist);
17964 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17965 +
17966 +       __dealloc_vx_info(vxi);
17967 +}
17968 +
17969 +
17970 +/*     hash table for vx_info hash */
17971 +
17972 +#define VX_HASH_SIZE   13
17973 +
17974 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17975 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17976 +
17977 +static DEFINE_SPINLOCK(vx_info_hash_lock);
17978 +
17979 +
17980 +static inline unsigned int __hashval(xid_t xid)
17981 +{
17982 +       return (xid % VX_HASH_SIZE);
17983 +}
17984 +
17985 +
17986 +
17987 +/*     __hash_vx_info()
17988 +
17989 +       * add the vxi to the global hash table
17990 +       * requires the hash_lock to be held                     */
17991 +
17992 +static inline void __hash_vx_info(struct vx_info *vxi)
17993 +{
17994 +       struct hlist_head *head;
17995 +
17996 +       vxd_assert_lock(&vx_info_hash_lock);
17997 +       vxdprintk(VXD_CBIT(xid, 4),
17998 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17999 +       vxh_hash_vx_info(vxi);
18000 +
18001 +       /* context must not be hashed */
18002 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18003 +
18004 +       vxi->vx_state |= VXS_HASHED;
18005 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
18006 +       hlist_add_head(&vxi->vx_hlist, head);
18007 +       atomic_inc(&vx_global_cactive);
18008 +}
18009 +
18010 +/*     __unhash_vx_info()
18011 +
18012 +       * remove the vxi from the global hash table
18013 +       * requires the hash_lock to be held                     */
18014 +
18015 +static inline void __unhash_vx_info(struct vx_info *vxi)
18016 +{
18017 +       unsigned long flags;
18018 +
18019 +       vxd_assert_lock(&vx_info_hash_lock);
18020 +       vxdprintk(VXD_CBIT(xid, 4),
18021 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
18022 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
18023 +       vxh_unhash_vx_info(vxi);
18024 +
18025 +       /* context must be hashed */
18026 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
18027 +       /* but without tasks */
18028 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18029 +
18030 +       vxi->vx_state &= ~VXS_HASHED;
18031 +       hlist_del_init(&vxi->vx_hlist);
18032 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18033 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
18034 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18035 +       atomic_dec(&vx_global_cactive);
18036 +}
18037 +
18038 +
18039 +/*     __lookup_vx_info()
18040 +
18041 +       * requires the hash_lock to be held
18042 +       * doesn't increment the vx_refcnt                       */
18043 +
18044 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
18045 +{
18046 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
18047 +       struct hlist_node *pos;
18048 +       struct vx_info *vxi;
18049 +
18050 +       vxd_assert_lock(&vx_info_hash_lock);
18051 +       hlist_for_each(pos, head) {
18052 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18053 +
18054 +               if (vxi->vx_id == xid)
18055 +                       goto found;
18056 +       }
18057 +       vxi = NULL;
18058 +found:
18059 +       vxdprintk(VXD_CBIT(xid, 0),
18060 +               "__lookup_vx_info(#%u): %p[#%u]",
18061 +               xid, vxi, vxi ? vxi->vx_id : 0);
18062 +       vxh_lookup_vx_info(vxi, xid);
18063 +       return vxi;
18064 +}
18065 +
18066 +
18067 +/*     __create_vx_info()
18068 +
18069 +       * create the requested context
18070 +       * get(), claim() and hash it                            */
18071 +
18072 +static struct vx_info *__create_vx_info(int id)
18073 +{
18074 +       struct vx_info *new, *vxi = NULL;
18075 +
18076 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
18077 +
18078 +       if (!(new = __alloc_vx_info(id)))
18079 +               return ERR_PTR(-ENOMEM);
18080 +
18081 +       /* required to make dynamic xids unique */
18082 +       spin_lock(&vx_info_hash_lock);
18083 +
18084 +       /* static context requested */
18085 +       if ((vxi = __lookup_vx_info(id))) {
18086 +               vxdprintk(VXD_CBIT(xid, 0),
18087 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18088 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18089 +                       vxi = ERR_PTR(-EBUSY);
18090 +               else
18091 +                       vxi = ERR_PTR(-EEXIST);
18092 +               goto out_unlock;
18093 +       }
18094 +       /* new context */
18095 +       vxdprintk(VXD_CBIT(xid, 0),
18096 +               "create_vx_info(%d) = %p (new)", id, new);
18097 +       claim_vx_info(new, NULL);
18098 +       __hash_vx_info(get_vx_info(new));
18099 +       vxi = new, new = NULL;
18100 +
18101 +out_unlock:
18102 +       spin_unlock(&vx_info_hash_lock);
18103 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18104 +       if (new)
18105 +               __dealloc_vx_info(new);
18106 +       return vxi;
18107 +}
18108 +
18109 +
18110 +/*     exported stuff                                          */
18111 +
18112 +
18113 +void unhash_vx_info(struct vx_info *vxi)
18114 +{
18115 +       spin_lock(&vx_info_hash_lock);
18116 +       __unhash_vx_info(vxi);
18117 +       spin_unlock(&vx_info_hash_lock);
18118 +       __shutdown_vx_info(vxi);
18119 +       __wakeup_vx_info(vxi);
18120 +}
18121 +
18122 +
18123 +/*     lookup_vx_info()
18124 +
18125 +       * search for a vx_info and get() it
18126 +       * negative id means current                             */
18127 +
18128 +struct vx_info *lookup_vx_info(int id)
18129 +{
18130 +       struct vx_info *vxi = NULL;
18131 +
18132 +       if (id < 0) {
18133 +               vxi = get_vx_info(current_vx_info());
18134 +       } else if (id > 1) {
18135 +               spin_lock(&vx_info_hash_lock);
18136 +               vxi = get_vx_info(__lookup_vx_info(id));
18137 +               spin_unlock(&vx_info_hash_lock);
18138 +       }
18139 +       return vxi;
18140 +}
18141 +
18142 +/*     xid_is_hashed()
18143 +
18144 +       * verify that xid is still hashed                       */
18145 +
18146 +int xid_is_hashed(xid_t xid)
18147 +{
18148 +       int hashed;
18149 +
18150 +       spin_lock(&vx_info_hash_lock);
18151 +       hashed = (__lookup_vx_info(xid) != NULL);
18152 +       spin_unlock(&vx_info_hash_lock);
18153 +       return hashed;
18154 +}
18155 +
18156 +#ifdef CONFIG_PROC_FS
18157 +
18158 +/*     get_xid_list()
18159 +
18160 +       * get a subset of hashed xids for proc
18161 +       * assumes size is at least one                          */
18162 +
18163 +int get_xid_list(int index, unsigned int *xids, int size)
18164 +{
18165 +       int hindex, nr_xids = 0;
18166 +
18167 +       /* only show current and children */
18168 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18169 +               if (index > 0)
18170 +                       return 0;
18171 +               xids[nr_xids] = vx_current_xid();
18172 +               return 1;
18173 +       }
18174 +
18175 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18176 +               struct hlist_head *head = &vx_info_hash[hindex];
18177 +               struct hlist_node *pos;
18178 +
18179 +               spin_lock(&vx_info_hash_lock);
18180 +               hlist_for_each(pos, head) {
18181 +                       struct vx_info *vxi;
18182 +
18183 +                       if (--index > 0)
18184 +                               continue;
18185 +
18186 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18187 +                       xids[nr_xids] = vxi->vx_id;
18188 +                       if (++nr_xids >= size) {
18189 +                               spin_unlock(&vx_info_hash_lock);
18190 +                               goto out;
18191 +                       }
18192 +               }
18193 +               /* keep the lock time short */
18194 +               spin_unlock(&vx_info_hash_lock);
18195 +       }
18196 +out:
18197 +       return nr_xids;
18198 +}
18199 +#endif
18200 +
18201 +#ifdef CONFIG_VSERVER_DEBUG
18202 +
18203 +void   dump_vx_info_inactive(int level)
18204 +{
18205 +       struct hlist_node *entry, *next;
18206 +
18207 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18208 +               struct vx_info *vxi =
18209 +                       list_entry(entry, struct vx_info, vx_hlist);
18210 +
18211 +               dump_vx_info(vxi, level);
18212 +       }
18213 +}
18214 +
18215 +#endif
18216 +
18217 +#if 0
18218 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18219 +{
18220 +       struct user_struct *new_user, *old_user;
18221 +
18222 +       if (!p || !vxi)
18223 +               BUG();
18224 +
18225 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18226 +               return -EACCES;
18227 +
18228 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18229 +       if (!new_user)
18230 +               return -ENOMEM;
18231 +
18232 +       old_user = p->user;
18233 +       if (new_user != old_user) {
18234 +               atomic_inc(&new_user->processes);
18235 +               atomic_dec(&old_user->processes);
18236 +               p->user = new_user;
18237 +       }
18238 +       free_uid(old_user);
18239 +       return 0;
18240 +}
18241 +#endif
18242 +
18243 +#if 0
18244 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18245 +{
18246 +       // p->cap_effective &= vxi->vx_cap_bset;
18247 +       p->cap_effective =
18248 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18249 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18250 +       p->cap_inheritable =
18251 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18252 +       // p->cap_permitted &= vxi->vx_cap_bset;
18253 +       p->cap_permitted =
18254 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18255 +}
18256 +#endif
18257 +
18258 +
18259 +#include <linux/file.h>
18260 +#include <linux/fdtable.h>
18261 +
18262 +static int vx_openfd_task(struct task_struct *tsk)
18263 +{
18264 +       struct files_struct *files = tsk->files;
18265 +       struct fdtable *fdt;
18266 +       const unsigned long *bptr;
18267 +       int count, total;
18268 +
18269 +       /* no rcu_read_lock() because of spin_lock() */
18270 +       spin_lock(&files->file_lock);
18271 +       fdt = files_fdtable(files);
18272 +       bptr = fdt->open_fds->fds_bits;
18273 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18274 +       for (total = 0; count > 0; count--) {
18275 +               if (*bptr)
18276 +                       total += hweight_long(*bptr);
18277 +               bptr++;
18278 +       }
18279 +       spin_unlock(&files->file_lock);
18280 +       return total;
18281 +}
18282 +
18283 +
18284 +/*     for *space compatibility */
18285 +
18286 +asmlinkage long sys_unshare(unsigned long);
18287 +
18288 +/*
18289 + *     migrate task to new context
18290 + *     gets vxi, puts old_vxi on change
18291 + *     optionally unshares namespaces (hack)
18292 + */
18293 +
18294 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18295 +{
18296 +       struct vx_info *old_vxi;
18297 +       int ret = 0;
18298 +
18299 +       if (!p || !vxi)
18300 +               BUG();
18301 +
18302 +       vxdprintk(VXD_CBIT(xid, 5),
18303 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18304 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18305 +
18306 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18307 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18308 +               return -EACCES;
18309 +
18310 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18311 +               return -EFAULT;
18312 +
18313 +       old_vxi = task_get_vx_info(p);
18314 +       if (old_vxi == vxi)
18315 +               goto out;
18316 +
18317 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18318 +       {
18319 +               int openfd;
18320 +
18321 +               task_lock(p);
18322 +               openfd = vx_openfd_task(p);
18323 +
18324 +               if (old_vxi) {
18325 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18326 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18327 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18328 +                       /* FIXME: what about the struct files here? */
18329 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18330 +                       /* account for the executable */
18331 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18332 +               }
18333 +               atomic_inc(&vxi->cvirt.nr_threads);
18334 +               atomic_inc(&vxi->cvirt.nr_running);
18335 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18336 +               /* FIXME: what about the struct files here? */
18337 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18338 +               /* account for the executable */
18339 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18340 +
18341 +               if (old_vxi) {
18342 +                       release_vx_info(old_vxi, p);
18343 +                       clr_vx_info(&p->vx_info);
18344 +               }
18345 +               claim_vx_info(vxi, p);
18346 +               set_vx_info(&p->vx_info, vxi);
18347 +               p->xid = vxi->vx_id;
18348 +
18349 +               vxdprintk(VXD_CBIT(xid, 5),
18350 +                       "moved task %p into vxi:%p[#%d]",
18351 +                       p, vxi, vxi->vx_id);
18352 +
18353 +               // vx_mask_cap_bset(vxi, p);
18354 +               task_unlock(p);
18355 +
18356 +               /* hack for *spaces to provide compatibility */
18357 +               if (unshare) {
18358 +                       struct nsproxy *old_nsp, *new_nsp;
18359 +
18360 +                       ret = unshare_nsproxy_namespaces(
18361 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18362 +                               &new_nsp, NULL);
18363 +                       if (ret)
18364 +                               goto out;
18365 +
18366 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18367 +                       vx_set_space(vxi,
18368 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18369 +                       put_nsproxy(old_nsp);
18370 +               }
18371 +       }
18372 +out:
18373 +       put_vx_info(old_vxi);
18374 +       return ret;
18375 +}
18376 +
18377 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18378 +{
18379 +       struct task_struct *old_reaper;
18380 +
18381 +       if (!vxi)
18382 +               return -EINVAL;
18383 +
18384 +       vxdprintk(VXD_CBIT(xid, 6),
18385 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18386 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18387 +
18388 +       old_reaper = vxi->vx_reaper;
18389 +       if (old_reaper == p)
18390 +               return 0;
18391 +
18392 +       /* set new child reaper */
18393 +       get_task_struct(p);
18394 +       vxi->vx_reaper = p;
18395 +       put_task_struct(old_reaper);
18396 +       return 0;
18397 +}
18398 +
18399 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18400 +{
18401 +       if (!vxi)
18402 +               return -EINVAL;
18403 +
18404 +       vxdprintk(VXD_CBIT(xid, 6),
18405 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18406 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18407 +
18408 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18409 +       // vxi->vx_initpid = p->tgid;
18410 +       vxi->vx_initpid = p->pid;
18411 +       return 0;
18412 +}
18413 +
18414 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18415 +{
18416 +       vxdprintk(VXD_CBIT(xid, 6),
18417 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18418 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18419 +
18420 +       vxi->exit_code = code;
18421 +       vxi->vx_initpid = 0;
18422 +}
18423 +
18424 +
18425 +void vx_set_persistent(struct vx_info *vxi)
18426 +{
18427 +       vxdprintk(VXD_CBIT(xid, 6),
18428 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18429 +
18430 +       get_vx_info(vxi);
18431 +       claim_vx_info(vxi, NULL);
18432 +}
18433 +
18434 +void vx_clear_persistent(struct vx_info *vxi)
18435 +{
18436 +       vxdprintk(VXD_CBIT(xid, 6),
18437 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18438 +
18439 +       release_vx_info(vxi, NULL);
18440 +       put_vx_info(vxi);
18441 +}
18442 +
18443 +void vx_update_persistent(struct vx_info *vxi)
18444 +{
18445 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18446 +               vx_set_persistent(vxi);
18447 +       else
18448 +               vx_clear_persistent(vxi);
18449 +}
18450 +
18451 +
18452 +/*     task must be current or locked          */
18453 +
18454 +void   exit_vx_info(struct task_struct *p, int code)
18455 +{
18456 +       struct vx_info *vxi = p->vx_info;
18457 +
18458 +       if (vxi) {
18459 +               atomic_dec(&vxi->cvirt.nr_threads);
18460 +               vx_nproc_dec(p);
18461 +
18462 +               vxi->exit_code = code;
18463 +               release_vx_info(vxi, p);
18464 +       }
18465 +}
18466 +
18467 +void   exit_vx_info_early(struct task_struct *p, int code)
18468 +{
18469 +       struct vx_info *vxi = p->vx_info;
18470 +
18471 +       if (vxi) {
18472 +               if (vxi->vx_initpid == p->pid)
18473 +                       vx_exit_init(vxi, p, code);
18474 +               if (vxi->vx_reaper == p)
18475 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18476 +       }
18477 +}
18478 +
18479 +
18480 +/* vserver syscall commands below here */
18481 +
18482 +/* taks xid and vx_info functions */
18483 +
18484 +#include <asm/uaccess.h>
18485 +
18486 +
18487 +int vc_task_xid(uint32_t id)
18488 +{
18489 +       xid_t xid;
18490 +
18491 +       if (id) {
18492 +               struct task_struct *tsk;
18493 +
18494 +               rcu_read_lock();
18495 +               tsk = find_task_by_real_pid(id);
18496 +               xid = (tsk) ? tsk->xid : -ESRCH;
18497 +               rcu_read_unlock();
18498 +       } else
18499 +               xid = vx_current_xid();
18500 +       return xid;
18501 +}
18502 +
18503 +
18504 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18505 +{
18506 +       struct vcmd_vx_info_v0 vc_data;
18507 +
18508 +       vc_data.xid = vxi->vx_id;
18509 +       vc_data.initpid = vxi->vx_initpid;
18510 +
18511 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18512 +               return -EFAULT;
18513 +       return 0;
18514 +}
18515 +
18516 +
18517 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18518 +{
18519 +       struct vcmd_ctx_stat_v0 vc_data;
18520 +
18521 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18522 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18523 +
18524 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18525 +               return -EFAULT;
18526 +       return 0;
18527 +}
18528 +
18529 +
18530 +/* context functions */
18531 +
18532 +int vc_ctx_create(uint32_t xid, void __user *data)
18533 +{
18534 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18535 +       struct vx_info *new_vxi;
18536 +       int ret;
18537 +
18538 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18539 +               return -EFAULT;
18540 +
18541 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18542 +               return -EINVAL;
18543 +
18544 +       new_vxi = __create_vx_info(xid);
18545 +       if (IS_ERR(new_vxi))
18546 +               return PTR_ERR(new_vxi);
18547 +
18548 +       /* initial flags */
18549 +       new_vxi->vx_flags = vc_data.flagword;
18550 +
18551 +       ret = -ENOEXEC;
18552 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18553 +               goto out;
18554 +
18555 +       ret = vx_migrate_task(current, new_vxi, (!data));
18556 +       if (ret)
18557 +               goto out;
18558 +
18559 +       /* return context id on success */
18560 +       ret = new_vxi->vx_id;
18561 +
18562 +       /* get a reference for persistent contexts */
18563 +       if ((vc_data.flagword & VXF_PERSISTENT))
18564 +               vx_set_persistent(new_vxi);
18565 +out:
18566 +       release_vx_info(new_vxi, NULL);
18567 +       put_vx_info(new_vxi);
18568 +       return ret;
18569 +}
18570 +
18571 +
18572 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18573 +{
18574 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18575 +       int ret;
18576 +
18577 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18578 +               return -EFAULT;
18579 +
18580 +       ret = vx_migrate_task(current, vxi, 0);
18581 +       if (ret)
18582 +               return ret;
18583 +       if (vc_data.flagword & VXM_SET_INIT)
18584 +               ret = vx_set_init(vxi, current);
18585 +       if (ret)
18586 +               return ret;
18587 +       if (vc_data.flagword & VXM_SET_REAPER)
18588 +               ret = vx_set_reaper(vxi, current);
18589 +       return ret;
18590 +}
18591 +
18592 +
18593 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18594 +{
18595 +       struct vcmd_ctx_flags_v0 vc_data;
18596 +
18597 +       vc_data.flagword = vxi->vx_flags;
18598 +
18599 +       /* special STATE flag handling */
18600 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18601 +
18602 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18603 +               return -EFAULT;
18604 +       return 0;
18605 +}
18606 +
18607 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18608 +{
18609 +       struct vcmd_ctx_flags_v0 vc_data;
18610 +       uint64_t mask, trigger;
18611 +
18612 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18613 +               return -EFAULT;
18614 +
18615 +       /* special STATE flag handling */
18616 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18617 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18618 +
18619 +       if (vxi == current_vx_info()) {
18620 +               /* if (trigger & VXF_STATE_SETUP)
18621 +                       vx_mask_cap_bset(vxi, current); */
18622 +               if (trigger & VXF_STATE_INIT) {
18623 +                       int ret;
18624 +
18625 +                       ret = vx_set_init(vxi, current);
18626 +                       if (ret)
18627 +                               return ret;
18628 +                       ret = vx_set_reaper(vxi, current);
18629 +                       if (ret)
18630 +                               return ret;
18631 +               }
18632 +       }
18633 +
18634 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18635 +               vc_data.flagword, mask);
18636 +       if (trigger & VXF_PERSISTENT)
18637 +               vx_update_persistent(vxi);
18638 +
18639 +       return 0;
18640 +}
18641 +
18642 +
18643 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18644 +{
18645 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18646 +
18647 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18648 +       return v;
18649 +}
18650 +
18651 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18652 +{
18653 +       kernel_cap_t c = __cap_empty_set;
18654 +
18655 +       c.cap[0] = v & 0xFFFFFFFF;
18656 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18657 +
18658 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18659 +       return c;
18660 +}
18661 +
18662 +
18663 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18664 +{
18665 +       if (bcaps)
18666 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18667 +       if (ccaps)
18668 +               *ccaps = vxi->vx_ccaps;
18669 +
18670 +       return 0;
18671 +}
18672 +
18673 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18674 +{
18675 +       struct vcmd_ctx_caps_v1 vc_data;
18676 +       int ret;
18677 +
18678 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18679 +       if (ret)
18680 +               return ret;
18681 +       vc_data.cmask = ~0ULL;
18682 +
18683 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18684 +               return -EFAULT;
18685 +       return 0;
18686 +}
18687 +
18688 +static int do_set_caps(struct vx_info *vxi,
18689 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18690 +{
18691 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18692 +
18693 +#if 0
18694 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18695 +               bcaps, bmask, ccaps, cmask);
18696 +#endif
18697 +       vxi->vx_bcaps = cap_t_from_caps(
18698 +               vs_mask_flags(bcold, bcaps, bmask));
18699 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18700 +
18701 +       return 0;
18702 +}
18703 +
18704 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18705 +{
18706 +       struct vcmd_ctx_caps_v1 vc_data;
18707 +
18708 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18709 +               return -EFAULT;
18710 +
18711 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18712 +}
18713 +
18714 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18715 +{
18716 +       struct vcmd_bcaps vc_data;
18717 +       int ret;
18718 +
18719 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18720 +       if (ret)
18721 +               return ret;
18722 +       vc_data.bmask = ~0ULL;
18723 +
18724 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18725 +               return -EFAULT;
18726 +       return 0;
18727 +}
18728 +
18729 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18730 +{
18731 +       struct vcmd_bcaps vc_data;
18732 +
18733 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18734 +               return -EFAULT;
18735 +
18736 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18737 +}
18738 +
18739 +
18740 +int vc_get_umask(struct vx_info *vxi, void __user *data)
18741 +{
18742 +       struct vcmd_umask vc_data;
18743 +
18744 +       vc_data.umask = vxi->vx_umask;
18745 +       vc_data.mask = ~0ULL;
18746 +
18747 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18748 +               return -EFAULT;
18749 +       return 0;
18750 +}
18751 +
18752 +int vc_set_umask(struct vx_info *vxi, void __user *data)
18753 +{
18754 +       struct vcmd_umask vc_data;
18755 +
18756 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18757 +               return -EFAULT;
18758 +
18759 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
18760 +               vc_data.umask, vc_data.mask);
18761 +       return 0;
18762 +}
18763 +
18764 +
18765 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
18766 +{
18767 +       struct vcmd_wmask vc_data;
18768 +
18769 +       vc_data.wmask = vxi->vx_wmask;
18770 +       vc_data.mask = ~0ULL;
18771 +
18772 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18773 +               return -EFAULT;
18774 +       return 0;
18775 +}
18776 +
18777 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
18778 +{
18779 +       struct vcmd_wmask vc_data;
18780 +
18781 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18782 +               return -EFAULT;
18783 +
18784 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
18785 +               vc_data.wmask, vc_data.mask);
18786 +       return 0;
18787 +}
18788 +
18789 +
18790 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18791 +{
18792 +       struct vcmd_badness_v0 vc_data;
18793 +
18794 +       vc_data.bias = vxi->vx_badness_bias;
18795 +
18796 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18797 +               return -EFAULT;
18798 +       return 0;
18799 +}
18800 +
18801 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18802 +{
18803 +       struct vcmd_badness_v0 vc_data;
18804 +
18805 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18806 +               return -EFAULT;
18807 +
18808 +       vxi->vx_badness_bias = vc_data.bias;
18809 +       return 0;
18810 +}
18811 +
18812 +#include <linux/module.h>
18813 +
18814 +EXPORT_SYMBOL_GPL(free_vx_info);
18815 +
18816 diff -NurpP --minimal linux-3.1/kernel/vserver/cvirt.c linux-3.1-vs2.3.1-rc2/kernel/vserver/cvirt.c
18817 --- linux-3.1/kernel/vserver/cvirt.c    1970-01-01 01:00:00.000000000 +0100
18818 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/cvirt.c        2011-10-24 18:53:33.000000000 +0200
18819 @@ -0,0 +1,303 @@
18820 +/*
18821 + *  linux/kernel/vserver/cvirt.c
18822 + *
18823 + *  Virtual Server: Context Virtualization
18824 + *
18825 + *  Copyright (C) 2004-2007  Herbert Pötzl
18826 + *
18827 + *  V0.01  broken out from limit.c
18828 + *  V0.02  added utsname stuff
18829 + *  V0.03  changed vcmds to vxi arg
18830 + *
18831 + */
18832 +
18833 +#include <linux/types.h>
18834 +#include <linux/utsname.h>
18835 +#include <linux/vs_cvirt.h>
18836 +#include <linux/vserver/switch.h>
18837 +#include <linux/vserver/cvirt_cmd.h>
18838 +
18839 +#include <asm/uaccess.h>
18840 +
18841 +
18842 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18843 +{
18844 +       struct vx_info *vxi = current_vx_info();
18845 +
18846 +       set_normalized_timespec(uptime,
18847 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18848 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18849 +       if (!idle)
18850 +               return;
18851 +       set_normalized_timespec(idle,
18852 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18853 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18854 +       return;
18855 +}
18856 +
18857 +uint64_t vx_idle_jiffies(void)
18858 +{
18859 +       return init_task.utime + init_task.stime;
18860 +}
18861 +
18862 +
18863 +
18864 +static inline uint32_t __update_loadavg(uint32_t load,
18865 +       int wsize, int delta, int n)
18866 +{
18867 +       unsigned long long calc, prev;
18868 +
18869 +       /* just set it to n */
18870 +       if (unlikely(delta >= wsize))
18871 +               return (n << FSHIFT);
18872 +
18873 +       calc = delta * n;
18874 +       calc <<= FSHIFT;
18875 +       prev = (wsize - delta);
18876 +       prev *= load;
18877 +       calc += prev;
18878 +       do_div(calc, wsize);
18879 +       return calc;
18880 +}
18881 +
18882 +
18883 +void vx_update_load(struct vx_info *vxi)
18884 +{
18885 +       uint32_t now, last, delta;
18886 +       unsigned int nr_running, nr_uninterruptible;
18887 +       unsigned int total;
18888 +       unsigned long flags;
18889 +
18890 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18891 +
18892 +       now = jiffies;
18893 +       last = vxi->cvirt.load_last;
18894 +       delta = now - last;
18895 +
18896 +       if (delta < 5*HZ)
18897 +               goto out;
18898 +
18899 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18900 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18901 +       total = nr_running + nr_uninterruptible;
18902 +
18903 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18904 +               60*HZ, delta, total);
18905 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18906 +               5*60*HZ, delta, total);
18907 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18908 +               15*60*HZ, delta, total);
18909 +
18910 +       vxi->cvirt.load_last = now;
18911 +out:
18912 +       atomic_inc(&vxi->cvirt.load_updates);
18913 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18914 +}
18915 +
18916 +
18917 +/*
18918 + * Commands to do_syslog:
18919 + *
18920 + *      0 -- Close the log.  Currently a NOP.
18921 + *      1 -- Open the log. Currently a NOP.
18922 + *      2 -- Read from the log.
18923 + *      3 -- Read all messages remaining in the ring buffer.
18924 + *      4 -- Read and clear all messages remaining in the ring buffer
18925 + *      5 -- Clear ring buffer.
18926 + *      6 -- Disable printk's to console
18927 + *      7 -- Enable printk's to console
18928 + *      8 -- Set level of messages printed to console
18929 + *      9 -- Return number of unread characters in the log buffer
18930 + *     10 -- Return size of the log buffer
18931 + */
18932 +int vx_do_syslog(int type, char __user *buf, int len)
18933 +{
18934 +       int error = 0;
18935 +       int do_clear = 0;
18936 +       struct vx_info *vxi = current_vx_info();
18937 +       struct _vx_syslog *log;
18938 +
18939 +       if (!vxi)
18940 +               return -EINVAL;
18941 +       log = &vxi->cvirt.syslog;
18942 +
18943 +       switch (type) {
18944 +       case 0:         /* Close log */
18945 +       case 1:         /* Open log */
18946 +               break;
18947 +       case 2:         /* Read from log */
18948 +               error = wait_event_interruptible(log->log_wait,
18949 +                       (log->log_start - log->log_end));
18950 +               if (error)
18951 +                       break;
18952 +               spin_lock_irq(&log->logbuf_lock);
18953 +               spin_unlock_irq(&log->logbuf_lock);
18954 +               break;
18955 +       case 4:         /* Read/clear last kernel messages */
18956 +               do_clear = 1;
18957 +               /* fall through */
18958 +       case 3:         /* Read last kernel messages */
18959 +               return 0;
18960 +
18961 +       case 5:         /* Clear ring buffer */
18962 +               return 0;
18963 +
18964 +       case 6:         /* Disable logging to console */
18965 +       case 7:         /* Enable logging to console */
18966 +       case 8:         /* Set level of messages printed to console */
18967 +               break;
18968 +
18969 +       case 9:         /* Number of chars in the log buffer */
18970 +               return 0;
18971 +       case 10:        /* Size of the log buffer */
18972 +               return 0;
18973 +       default:
18974 +               error = -EINVAL;
18975 +               break;
18976 +       }
18977 +       return error;
18978 +}
18979 +
18980 +
18981 +/* virtual host info names */
18982 +
18983 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18984 +{
18985 +       struct nsproxy *nsproxy;
18986 +       struct uts_namespace *uts;
18987 +
18988 +       if (id == VHIN_CONTEXT)
18989 +               return vxi->vx_name;
18990 +
18991 +       nsproxy = vxi->space[0].vx_nsproxy;
18992 +       if (!nsproxy)
18993 +               return NULL;
18994 +
18995 +       uts = nsproxy->uts_ns;
18996 +       if (!uts)
18997 +               return NULL;
18998 +
18999 +       switch (id) {
19000 +       case VHIN_SYSNAME:
19001 +               return uts->name.sysname;
19002 +       case VHIN_NODENAME:
19003 +               return uts->name.nodename;
19004 +       case VHIN_RELEASE:
19005 +               return uts->name.release;
19006 +       case VHIN_VERSION:
19007 +               return uts->name.version;
19008 +       case VHIN_MACHINE:
19009 +               return uts->name.machine;
19010 +       case VHIN_DOMAINNAME:
19011 +               return uts->name.domainname;
19012 +       default:
19013 +               return NULL;
19014 +       }
19015 +       return NULL;
19016 +}
19017 +
19018 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
19019 +{
19020 +       struct vcmd_vhi_name_v0 vc_data;
19021 +       char *name;
19022 +
19023 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19024 +               return -EFAULT;
19025 +
19026 +       name = vx_vhi_name(vxi, vc_data.field);
19027 +       if (!name)
19028 +               return -EINVAL;
19029 +
19030 +       memcpy(name, vc_data.name, 65);
19031 +       return 0;
19032 +}
19033 +
19034 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
19035 +{
19036 +       struct vcmd_vhi_name_v0 vc_data;
19037 +       char *name;
19038 +
19039 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19040 +               return -EFAULT;
19041 +
19042 +       name = vx_vhi_name(vxi, vc_data.field);
19043 +       if (!name)
19044 +               return -EINVAL;
19045 +
19046 +       memcpy(vc_data.name, name, 65);
19047 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19048 +               return -EFAULT;
19049 +       return 0;
19050 +}
19051 +
19052 +
19053 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
19054 +{
19055 +       struct vcmd_virt_stat_v0 vc_data;
19056 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
19057 +       struct timespec uptime;
19058 +
19059 +       do_posix_clock_monotonic_gettime(&uptime);
19060 +       set_normalized_timespec(&uptime,
19061 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
19062 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
19063 +
19064 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
19065 +       vc_data.uptime = timespec_to_ns(&uptime);
19066 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
19067 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
19068 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
19069 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
19070 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
19071 +       vc_data.load[0] = cvirt->load[0];
19072 +       vc_data.load[1] = cvirt->load[1];
19073 +       vc_data.load[2] = cvirt->load[2];
19074 +
19075 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19076 +               return -EFAULT;
19077 +       return 0;
19078 +}
19079 +
19080 +
19081 +#ifdef CONFIG_VSERVER_VTIME
19082 +
19083 +/* virtualized time base */
19084 +
19085 +void vx_adjust_timespec(struct timespec *ts)
19086 +{
19087 +       struct vx_info *vxi;
19088 +
19089 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19090 +               return;
19091 +
19092 +       vxi = current_vx_info();
19093 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
19094 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
19095 +
19096 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
19097 +               ts->tv_sec++;
19098 +               ts->tv_nsec -= NSEC_PER_SEC;
19099 +       } else if (ts->tv_nsec < 0) {
19100 +               ts->tv_sec--;
19101 +               ts->tv_nsec += NSEC_PER_SEC;
19102 +       }
19103 +}
19104 +
19105 +int vx_settimeofday(const struct timespec *ts)
19106 +{
19107 +       struct timespec ats, delta;
19108 +       struct vx_info *vxi;
19109 +
19110 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19111 +               return do_settimeofday(ts);
19112 +
19113 +       getnstimeofday(&ats);
19114 +       delta = timespec_sub(*ts, ats);
19115 +
19116 +       vxi = current_vx_info();
19117 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
19118 +       return 0;
19119 +}
19120 +
19121 +#endif
19122 +
19123 diff -NurpP --minimal linux-3.1/kernel/vserver/cvirt_init.h linux-3.1-vs2.3.1-rc2/kernel/vserver/cvirt_init.h
19124 --- linux-3.1/kernel/vserver/cvirt_init.h       1970-01-01 01:00:00.000000000 +0100
19125 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/cvirt_init.h   2011-10-24 18:53:33.000000000 +0200
19126 @@ -0,0 +1,70 @@
19127 +
19128 +
19129 +extern uint64_t vx_idle_jiffies(void);
19130 +
19131 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19132 +{
19133 +       uint64_t idle_jiffies = vx_idle_jiffies();
19134 +       uint64_t nsuptime;
19135 +
19136 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19137 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19138 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19139 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19140 +       cvirt->bias_ts.tv_sec = 0;
19141 +       cvirt->bias_ts.tv_nsec = 0;
19142 +
19143 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19144 +       atomic_set(&cvirt->nr_threads, 0);
19145 +       atomic_set(&cvirt->nr_running, 0);
19146 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19147 +       atomic_set(&cvirt->nr_onhold, 0);
19148 +
19149 +       spin_lock_init(&cvirt->load_lock);
19150 +       cvirt->load_last = jiffies;
19151 +       atomic_set(&cvirt->load_updates, 0);
19152 +       cvirt->load[0] = 0;
19153 +       cvirt->load[1] = 0;
19154 +       cvirt->load[2] = 0;
19155 +       atomic_set(&cvirt->total_forks, 0);
19156 +
19157 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19158 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19159 +       cvirt->syslog.log_start = 0;
19160 +       cvirt->syslog.log_end = 0;
19161 +       cvirt->syslog.con_start = 0;
19162 +       cvirt->syslog.logged_chars = 0;
19163 +}
19164 +
19165 +static inline
19166 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19167 +{
19168 +       // cvirt_pc->cpustat = { 0 };
19169 +}
19170 +
19171 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19172 +{
19173 +#ifdef CONFIG_VSERVER_WARN
19174 +       int value;
19175 +#endif
19176 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19177 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19178 +               cvirt, value);
19179 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19180 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19181 +               cvirt, value);
19182 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19183 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19184 +               cvirt, value);
19185 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19186 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19187 +               cvirt, value);
19188 +       return;
19189 +}
19190 +
19191 +static inline
19192 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19193 +{
19194 +       return;
19195 +}
19196 +
19197 diff -NurpP --minimal linux-3.1/kernel/vserver/cvirt_proc.h linux-3.1-vs2.3.1-rc2/kernel/vserver/cvirt_proc.h
19198 --- linux-3.1/kernel/vserver/cvirt_proc.h       1970-01-01 01:00:00.000000000 +0100
19199 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/cvirt_proc.h   2011-10-24 18:53:33.000000000 +0200
19200 @@ -0,0 +1,135 @@
19201 +#ifndef _VX_CVIRT_PROC_H
19202 +#define _VX_CVIRT_PROC_H
19203 +
19204 +#include <linux/nsproxy.h>
19205 +#include <linux/mnt_namespace.h>
19206 +#include <linux/ipc_namespace.h>
19207 +#include <linux/utsname.h>
19208 +#include <linux/ipc.h>
19209 +
19210 +
19211 +static inline
19212 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19213 +{
19214 +       struct mnt_namespace *ns;
19215 +       struct uts_namespace *uts;
19216 +       struct ipc_namespace *ipc;
19217 +       struct path path;
19218 +       char *pstr, *root;
19219 +       int length = 0;
19220 +
19221 +       if (!nsproxy)
19222 +               goto out;
19223 +
19224 +       length += sprintf(buffer + length,
19225 +               "NSProxy:\t%p [%p,%p,%p]\n",
19226 +               nsproxy, nsproxy->mnt_ns,
19227 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19228 +
19229 +       ns = nsproxy->mnt_ns;
19230 +       if (!ns)
19231 +               goto skip_ns;
19232 +
19233 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19234 +       if (!pstr)
19235 +               goto skip_ns;
19236 +
19237 +       path.mnt = ns->root;
19238 +       path.dentry = ns->root->mnt_root;
19239 +       root = d_path(&path, pstr, PATH_MAX - 2);
19240 +       length += sprintf(buffer + length,
19241 +               "Namespace:\t%p [#%u]\n"
19242 +               "RootPath:\t%s\n",
19243 +               ns, atomic_read(&ns->count),
19244 +               root);
19245 +       kfree(pstr);
19246 +skip_ns:
19247 +
19248 +       uts = nsproxy->uts_ns;
19249 +       if (!uts)
19250 +               goto skip_uts;
19251 +
19252 +       length += sprintf(buffer + length,
19253 +               "SysName:\t%.*s\n"
19254 +               "NodeName:\t%.*s\n"
19255 +               "Release:\t%.*s\n"
19256 +               "Version:\t%.*s\n"
19257 +               "Machine:\t%.*s\n"
19258 +               "DomainName:\t%.*s\n",
19259 +               __NEW_UTS_LEN, uts->name.sysname,
19260 +               __NEW_UTS_LEN, uts->name.nodename,
19261 +               __NEW_UTS_LEN, uts->name.release,
19262 +               __NEW_UTS_LEN, uts->name.version,
19263 +               __NEW_UTS_LEN, uts->name.machine,
19264 +               __NEW_UTS_LEN, uts->name.domainname);
19265 +skip_uts:
19266 +
19267 +       ipc = nsproxy->ipc_ns;
19268 +       if (!ipc)
19269 +               goto skip_ipc;
19270 +
19271 +       length += sprintf(buffer + length,
19272 +               "SEMS:\t\t%d %d %d %d  %d\n"
19273 +               "MSG:\t\t%d %d %d\n"
19274 +               "SHM:\t\t%lu %lu  %d %d\n",
19275 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19276 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19277 +               ipc->used_sems,
19278 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19279 +               (unsigned long)ipc->shm_ctlmax,
19280 +               (unsigned long)ipc->shm_ctlall,
19281 +               ipc->shm_ctlmni, ipc->shm_tot);
19282 +skip_ipc:
19283 +out:
19284 +       return length;
19285 +}
19286 +
19287 +
19288 +#include <linux/sched.h>
19289 +
19290 +#define LOAD_INT(x) ((x) >> FSHIFT)
19291 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19292 +
19293 +static inline
19294 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19295 +{
19296 +       int length = 0;
19297 +       int a, b, c;
19298 +
19299 +       length += sprintf(buffer + length,
19300 +               "BiasUptime:\t%lu.%02lu\n",
19301 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19302 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19303 +
19304 +       a = cvirt->load[0] + (FIXED_1 / 200);
19305 +       b = cvirt->load[1] + (FIXED_1 / 200);
19306 +       c = cvirt->load[2] + (FIXED_1 / 200);
19307 +       length += sprintf(buffer + length,
19308 +               "nr_threads:\t%d\n"
19309 +               "nr_running:\t%d\n"
19310 +               "nr_unintr:\t%d\n"
19311 +               "nr_onhold:\t%d\n"
19312 +               "load_updates:\t%d\n"
19313 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19314 +               "total_forks:\t%d\n",
19315 +               atomic_read(&cvirt->nr_threads),
19316 +               atomic_read(&cvirt->nr_running),
19317 +               atomic_read(&cvirt->nr_uninterruptible),
19318 +               atomic_read(&cvirt->nr_onhold),
19319 +               atomic_read(&cvirt->load_updates),
19320 +               LOAD_INT(a), LOAD_FRAC(a),
19321 +               LOAD_INT(b), LOAD_FRAC(b),
19322 +               LOAD_INT(c), LOAD_FRAC(c),
19323 +               atomic_read(&cvirt->total_forks));
19324 +       return length;
19325 +}
19326 +
19327 +static inline
19328 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19329 +       char *buffer, int cpu)
19330 +{
19331 +       int length = 0;
19332 +       return length;
19333 +}
19334 +
19335 +#endif /* _VX_CVIRT_PROC_H */
19336 diff -NurpP --minimal linux-3.1/kernel/vserver/debug.c linux-3.1-vs2.3.1-rc2/kernel/vserver/debug.c
19337 --- linux-3.1/kernel/vserver/debug.c    1970-01-01 01:00:00.000000000 +0100
19338 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/debug.c        2011-10-24 18:53:33.000000000 +0200
19339 @@ -0,0 +1,32 @@
19340 +/*
19341 + *  kernel/vserver/debug.c
19342 + *
19343 + *  Copyright (C) 2005-2007 Herbert Pötzl
19344 + *
19345 + *  V0.01  vx_info dump support
19346 + *
19347 + */
19348 +
19349 +#include <linux/module.h>
19350 +
19351 +#include <linux/vserver/context.h>
19352 +
19353 +
19354 +void   dump_vx_info(struct vx_info *vxi, int level)
19355 +{
19356 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19357 +               atomic_read(&vxi->vx_usecnt),
19358 +               atomic_read(&vxi->vx_tasks),
19359 +               vxi->vx_state);
19360 +       if (level > 0) {
19361 +               __dump_vx_limit(&vxi->limit);
19362 +               __dump_vx_sched(&vxi->sched);
19363 +               __dump_vx_cvirt(&vxi->cvirt);
19364 +               __dump_vx_cacct(&vxi->cacct);
19365 +       }
19366 +       printk("---\n");
19367 +}
19368 +
19369 +
19370 +EXPORT_SYMBOL_GPL(dump_vx_info);
19371 +
19372 diff -NurpP --minimal linux-3.1/kernel/vserver/device.c linux-3.1-vs2.3.1-rc2/kernel/vserver/device.c
19373 --- linux-3.1/kernel/vserver/device.c   1970-01-01 01:00:00.000000000 +0100
19374 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/device.c       2011-10-24 18:53:33.000000000 +0200
19375 @@ -0,0 +1,443 @@
19376 +/*
19377 + *  linux/kernel/vserver/device.c
19378 + *
19379 + *  Linux-VServer: Device Support
19380 + *
19381 + *  Copyright (C) 2006  Herbert Pötzl
19382 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19383 + *
19384 + *  V0.01  device mapping basics
19385 + *  V0.02  added defaults
19386 + *
19387 + */
19388 +
19389 +#include <linux/slab.h>
19390 +#include <linux/rcupdate.h>
19391 +#include <linux/fs.h>
19392 +#include <linux/namei.h>
19393 +#include <linux/hash.h>
19394 +
19395 +#include <asm/errno.h>
19396 +#include <asm/uaccess.h>
19397 +#include <linux/vserver/base.h>
19398 +#include <linux/vserver/debug.h>
19399 +#include <linux/vserver/context.h>
19400 +#include <linux/vserver/device.h>
19401 +#include <linux/vserver/device_cmd.h>
19402 +
19403 +
19404 +#define DMAP_HASH_BITS 4
19405 +
19406 +
19407 +struct vs_mapping {
19408 +       union {
19409 +               struct hlist_node hlist;
19410 +               struct list_head list;
19411 +       } u;
19412 +#define dm_hlist       u.hlist
19413 +#define dm_list                u.list
19414 +       xid_t xid;
19415 +       dev_t device;
19416 +       struct vx_dmap_target target;
19417 +};
19418 +
19419 +
19420 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19421 +
19422 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
19423 +
19424 +static struct vx_dmap_target dmap_defaults[2] = {
19425 +       { .flags = DATTR_OPEN },
19426 +       { .flags = DATTR_OPEN },
19427 +};
19428 +
19429 +
19430 +struct kmem_cache *dmap_cachep __read_mostly;
19431 +
19432 +int __init dmap_cache_init(void)
19433 +{
19434 +       dmap_cachep = kmem_cache_create("dmap_cache",
19435 +               sizeof(struct vs_mapping), 0,
19436 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19437 +       return 0;
19438 +}
19439 +
19440 +__initcall(dmap_cache_init);
19441 +
19442 +
19443 +static inline unsigned int __hashval(dev_t dev, int bits)
19444 +{
19445 +       return hash_long((unsigned long)dev, bits);
19446 +}
19447 +
19448 +
19449 +/*     __hash_mapping()
19450 + *     add the mapping to the hash table
19451 + */
19452 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19453 +{
19454 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19455 +       struct hlist_head *head, *hash = dmap_main_hash;
19456 +       int device = vdm->device;
19457 +
19458 +       spin_lock(hash_lock);
19459 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19460 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19461 +
19462 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19463 +       hlist_add_head(&vdm->dm_hlist, head);
19464 +       spin_unlock(hash_lock);
19465 +}
19466 +
19467 +
19468 +static inline int __mode_to_default(umode_t mode)
19469 +{
19470 +       switch (mode) {
19471 +       case S_IFBLK:
19472 +               return 0;
19473 +       case S_IFCHR:
19474 +               return 1;
19475 +       default:
19476 +               BUG();
19477 +       }
19478 +}
19479 +
19480 +
19481 +/*     __set_default()
19482 + *     set a default
19483 + */
19484 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19485 +       struct vx_dmap_target *vdmt)
19486 +{
19487 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19488 +       spin_lock(hash_lock);
19489 +
19490 +       if (vxi)
19491 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19492 +       else
19493 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19494 +
19495 +
19496 +       spin_unlock(hash_lock);
19497 +
19498 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19499 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19500 +}
19501 +
19502 +
19503 +/*     __remove_default()
19504 + *     remove a default
19505 + */
19506 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19507 +{
19508 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19509 +       spin_lock(hash_lock);
19510 +
19511 +       if (vxi)
19512 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19513 +       else    /* remove == reset */
19514 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19515 +
19516 +       spin_unlock(hash_lock);
19517 +       return 0;
19518 +}
19519 +
19520 +
19521 +/*     __find_mapping()
19522 + *     find a mapping in the hash table
19523 + *
19524 + *     caller must hold hash_lock
19525 + */
19526 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19527 +       struct vs_mapping **local, struct vs_mapping **global)
19528 +{
19529 +       struct hlist_head *hash = dmap_main_hash;
19530 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19531 +       struct hlist_node *pos;
19532 +       struct vs_mapping *vdm;
19533 +
19534 +       *local = NULL;
19535 +       if (global)
19536 +               *global = NULL;
19537 +
19538 +       hlist_for_each(pos, head) {
19539 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19540 +
19541 +               if ((vdm->device == device) &&
19542 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19543 +                       if (vdm->xid == xid) {
19544 +                               *local = vdm;
19545 +                               return 1;
19546 +                       } else if (global && vdm->xid == 0)
19547 +                               *global = vdm;
19548 +               }
19549 +       }
19550 +
19551 +       if (global && *global)
19552 +               return 0;
19553 +       else
19554 +               return -ENOENT;
19555 +}
19556 +
19557 +
19558 +/*     __lookup_mapping()
19559 + *     find a mapping and store the result in target and flags
19560 + */
19561 +static inline int __lookup_mapping(struct vx_info *vxi,
19562 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19563 +{
19564 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19565 +       struct vs_mapping *vdm, *global;
19566 +       struct vx_dmap_target *vdmt;
19567 +       int ret = 0;
19568 +       xid_t xid = vxi->vx_id;
19569 +       int index;
19570 +
19571 +       spin_lock(hash_lock);
19572 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19573 +               ret = 1;
19574 +               vdmt = &vdm->target;
19575 +               goto found;
19576 +       }
19577 +
19578 +       index = __mode_to_default(mode);
19579 +       if (vxi && vxi->dmap.targets[index].flags) {
19580 +               ret = 2;
19581 +               vdmt = &vxi->dmap.targets[index];
19582 +       } else if (global) {
19583 +               ret = 3;
19584 +               vdmt = &global->target;
19585 +               goto found;
19586 +       } else {
19587 +               ret = 4;
19588 +               vdmt = &dmap_defaults[index];
19589 +       }
19590 +
19591 +found:
19592 +       if (target && (vdmt->flags & DATTR_REMAP))
19593 +               *target = vdmt->target;
19594 +       else if (target)
19595 +               *target = device;
19596 +       if (flags)
19597 +               *flags = vdmt->flags;
19598 +
19599 +       spin_unlock(hash_lock);
19600 +
19601 +       return ret;
19602 +}
19603 +
19604 +
19605 +/*     __remove_mapping()
19606 + *     remove a mapping from the hash table
19607 + */
19608 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19609 +       umode_t mode)
19610 +{
19611 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19612 +       struct vs_mapping *vdm = NULL;
19613 +       int ret = 0;
19614 +
19615 +       spin_lock(hash_lock);
19616 +
19617 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19618 +               NULL);
19619 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19620 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19621 +       if (ret < 0)
19622 +               goto out;
19623 +       hlist_del(&vdm->dm_hlist);
19624 +
19625 +out:
19626 +       spin_unlock(hash_lock);
19627 +       if (vdm)
19628 +               kmem_cache_free(dmap_cachep, vdm);
19629 +       return ret;
19630 +}
19631 +
19632 +
19633 +
19634 +int vs_map_device(struct vx_info *vxi,
19635 +       dev_t device, dev_t *target, umode_t mode)
19636 +{
19637 +       int ret, flags = DATTR_MASK;
19638 +
19639 +       if (!vxi) {
19640 +               if (target)
19641 +                       *target = device;
19642 +               goto out;
19643 +       }
19644 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19645 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19646 +               device, target ? *target : 0, flags, mode, ret);
19647 +out:
19648 +       return (flags & DATTR_MASK);
19649 +}
19650 +
19651 +
19652 +
19653 +static int do_set_mapping(struct vx_info *vxi,
19654 +       dev_t device, dev_t target, int flags, umode_t mode)
19655 +{
19656 +       if (device) {
19657 +               struct vs_mapping *new;
19658 +
19659 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19660 +               if (!new)
19661 +                       return -ENOMEM;
19662 +
19663 +               INIT_HLIST_NODE(&new->dm_hlist);
19664 +               new->device = device;
19665 +               new->target.target = target;
19666 +               new->target.flags = flags | mode;
19667 +               new->xid = (vxi ? vxi->vx_id : 0);
19668 +
19669 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19670 +               __hash_mapping(vxi, new);
19671 +       } else {
19672 +               struct vx_dmap_target new = {
19673 +                       .target = target,
19674 +                       .flags = flags | mode,
19675 +               };
19676 +               __set_default(vxi, mode, &new);
19677 +       }
19678 +       return 0;
19679 +}
19680 +
19681 +
19682 +static int do_unset_mapping(struct vx_info *vxi,
19683 +       dev_t device, dev_t target, int flags, umode_t mode)
19684 +{
19685 +       int ret = -EINVAL;
19686 +
19687 +       if (device) {
19688 +               ret = __remove_mapping(vxi, device, mode);
19689 +               if (ret < 0)
19690 +                       goto out;
19691 +       } else {
19692 +               ret = __remove_default(vxi, mode);
19693 +               if (ret < 0)
19694 +                       goto out;
19695 +       }
19696 +
19697 +out:
19698 +       return ret;
19699 +}
19700 +
19701 +
19702 +static inline int __user_device(const char __user *name, dev_t *dev,
19703 +       umode_t *mode)
19704 +{
19705 +       struct nameidata nd;
19706 +       int ret;
19707 +
19708 +       if (!name) {
19709 +               *dev = 0;
19710 +               return 0;
19711 +       }
19712 +       ret = user_lpath(name, &nd.path);
19713 +       if (ret)
19714 +               return ret;
19715 +       if (nd.path.dentry->d_inode) {
19716 +               *dev = nd.path.dentry->d_inode->i_rdev;
19717 +               *mode = nd.path.dentry->d_inode->i_mode;
19718 +       }
19719 +       path_put(&nd.path);
19720 +       return 0;
19721 +}
19722 +
19723 +static inline int __mapping_mode(dev_t device, dev_t target,
19724 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19725 +{
19726 +       if (device)
19727 +               *mode = device_mode & S_IFMT;
19728 +       else if (target)
19729 +               *mode = target_mode & S_IFMT;
19730 +       else
19731 +               return -EINVAL;
19732 +
19733 +       /* if both given, device and target mode have to match */
19734 +       if (device && target &&
19735 +               ((device_mode ^ target_mode) & S_IFMT))
19736 +               return -EINVAL;
19737 +       return 0;
19738 +}
19739 +
19740 +
19741 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19742 +       const char __user *target_path, int flags, int set)
19743 +{
19744 +       dev_t device = ~0, target = ~0;
19745 +       umode_t device_mode = 0, target_mode = 0, mode;
19746 +       int ret;
19747 +
19748 +       ret = __user_device(device_path, &device, &device_mode);
19749 +       if (ret)
19750 +               return ret;
19751 +       ret = __user_device(target_path, &target, &target_mode);
19752 +       if (ret)
19753 +               return ret;
19754 +
19755 +       ret = __mapping_mode(device, target,
19756 +               device_mode, target_mode, &mode);
19757 +       if (ret)
19758 +               return ret;
19759 +
19760 +       if (set)
19761 +               return do_set_mapping(vxi, device, target,
19762 +                       flags, mode);
19763 +       else
19764 +               return do_unset_mapping(vxi, device, target,
19765 +                       flags, mode);
19766 +}
19767 +
19768 +
19769 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19770 +{
19771 +       struct vcmd_set_mapping_v0 vc_data;
19772 +
19773 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19774 +               return -EFAULT;
19775 +
19776 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19777 +               vc_data.flags, 1);
19778 +}
19779 +
19780 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19781 +{
19782 +       struct vcmd_set_mapping_v0 vc_data;
19783 +
19784 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19785 +               return -EFAULT;
19786 +
19787 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19788 +               vc_data.flags, 0);
19789 +}
19790 +
19791 +
19792 +#ifdef CONFIG_COMPAT
19793 +
19794 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19795 +{
19796 +       struct vcmd_set_mapping_v0_x32 vc_data;
19797 +
19798 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19799 +               return -EFAULT;
19800 +
19801 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19802 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19803 +}
19804 +
19805 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19806 +{
19807 +       struct vcmd_set_mapping_v0_x32 vc_data;
19808 +
19809 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19810 +               return -EFAULT;
19811 +
19812 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19813 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19814 +}
19815 +
19816 +#endif /* CONFIG_COMPAT */
19817 +
19818 +
19819 diff -NurpP --minimal linux-3.1/kernel/vserver/dlimit.c linux-3.1-vs2.3.1-rc2/kernel/vserver/dlimit.c
19820 --- linux-3.1/kernel/vserver/dlimit.c   1970-01-01 01:00:00.000000000 +0100
19821 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/dlimit.c       2011-10-24 18:53:33.000000000 +0200
19822 @@ -0,0 +1,531 @@
19823 +/*
19824 + *  linux/kernel/vserver/dlimit.c
19825 + *
19826 + *  Virtual Server: Context Disk Limits
19827 + *
19828 + *  Copyright (C) 2004-2009  Herbert Pötzl
19829 + *
19830 + *  V0.01  initial version
19831 + *  V0.02  compat32 splitup
19832 + *  V0.03  extended interface
19833 + *
19834 + */
19835 +
19836 +#include <linux/statfs.h>
19837 +#include <linux/sched.h>
19838 +#include <linux/namei.h>
19839 +#include <linux/vs_tag.h>
19840 +#include <linux/vs_dlimit.h>
19841 +#include <linux/vserver/dlimit_cmd.h>
19842 +#include <linux/slab.h>
19843 +// #include <linux/gfp.h>
19844 +
19845 +#include <asm/uaccess.h>
19846 +
19847 +/*     __alloc_dl_info()
19848 +
19849 +       * allocate an initialized dl_info struct
19850 +       * doesn't make it visible (hash)                        */
19851 +
19852 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19853 +{
19854 +       struct dl_info *new = NULL;
19855 +
19856 +       vxdprintk(VXD_CBIT(dlim, 5),
19857 +               "alloc_dl_info(%p,%d)*", sb, tag);
19858 +
19859 +       /* would this benefit from a slab cache? */
19860 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19861 +       if (!new)
19862 +               return 0;
19863 +
19864 +       memset(new, 0, sizeof(struct dl_info));
19865 +       new->dl_tag = tag;
19866 +       new->dl_sb = sb;
19867 +       // INIT_RCU_HEAD(&new->dl_rcu);
19868 +       INIT_HLIST_NODE(&new->dl_hlist);
19869 +       spin_lock_init(&new->dl_lock);
19870 +       atomic_set(&new->dl_refcnt, 0);
19871 +       atomic_set(&new->dl_usecnt, 0);
19872 +
19873 +       /* rest of init goes here */
19874 +
19875 +       vxdprintk(VXD_CBIT(dlim, 4),
19876 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19877 +       return new;
19878 +}
19879 +
19880 +/*     __dealloc_dl_info()
19881 +
19882 +       * final disposal of dl_info                             */
19883 +
19884 +static void __dealloc_dl_info(struct dl_info *dli)
19885 +{
19886 +       vxdprintk(VXD_CBIT(dlim, 4),
19887 +               "dealloc_dl_info(%p)", dli);
19888 +
19889 +       dli->dl_hlist.next = LIST_POISON1;
19890 +       dli->dl_tag = -1;
19891 +       dli->dl_sb = 0;
19892 +
19893 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19894 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19895 +
19896 +       kfree(dli);
19897 +}
19898 +
19899 +
19900 +/*     hash table for dl_info hash */
19901 +
19902 +#define DL_HASH_SIZE   13
19903 +
19904 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19905 +
19906 +static DEFINE_SPINLOCK(dl_info_hash_lock);
19907 +
19908 +
19909 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19910 +{
19911 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19912 +}
19913 +
19914 +
19915 +
19916 +/*     __hash_dl_info()
19917 +
19918 +       * add the dli to the global hash table
19919 +       * requires the hash_lock to be held                     */
19920 +
19921 +static inline void __hash_dl_info(struct dl_info *dli)
19922 +{
19923 +       struct hlist_head *head;
19924 +
19925 +       vxdprintk(VXD_CBIT(dlim, 6),
19926 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19927 +       get_dl_info(dli);
19928 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19929 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19930 +}
19931 +
19932 +/*     __unhash_dl_info()
19933 +
19934 +       * remove the dli from the global hash table
19935 +       * requires the hash_lock to be held                     */
19936 +
19937 +static inline void __unhash_dl_info(struct dl_info *dli)
19938 +{
19939 +       vxdprintk(VXD_CBIT(dlim, 6),
19940 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19941 +       hlist_del_rcu(&dli->dl_hlist);
19942 +       put_dl_info(dli);
19943 +}
19944 +
19945 +
19946 +/*     __lookup_dl_info()
19947 +
19948 +       * requires the rcu_read_lock()
19949 +       * doesn't increment the dl_refcnt                       */
19950 +
19951 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19952 +{
19953 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19954 +       struct hlist_node *pos;
19955 +       struct dl_info *dli;
19956 +
19957 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19958 +
19959 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19960 +                       return dli;
19961 +               }
19962 +       }
19963 +       return NULL;
19964 +}
19965 +
19966 +
19967 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19968 +{
19969 +       struct dl_info *dli;
19970 +
19971 +       rcu_read_lock();
19972 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19973 +       vxdprintk(VXD_CBIT(dlim, 7),
19974 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19975 +       rcu_read_unlock();
19976 +       return dli;
19977 +}
19978 +
19979 +void rcu_free_dl_info(struct rcu_head *head)
19980 +{
19981 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19982 +       int usecnt, refcnt;
19983 +
19984 +       BUG_ON(!dli || !head);
19985 +
19986 +       usecnt = atomic_read(&dli->dl_usecnt);
19987 +       BUG_ON(usecnt < 0);
19988 +
19989 +       refcnt = atomic_read(&dli->dl_refcnt);
19990 +       BUG_ON(refcnt < 0);
19991 +
19992 +       vxdprintk(VXD_CBIT(dlim, 3),
19993 +               "rcu_free_dl_info(%p)", dli);
19994 +       if (!usecnt)
19995 +               __dealloc_dl_info(dli);
19996 +       else
19997 +               printk("!!! rcu didn't free\n");
19998 +}
19999 +
20000 +
20001 +
20002 +
20003 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
20004 +       uint32_t flags, int add)
20005 +{
20006 +       struct path path;
20007 +       int ret;
20008 +
20009 +       ret = user_lpath(name, &path);
20010 +       if (!ret) {
20011 +               struct super_block *sb;
20012 +               struct dl_info *dli;
20013 +
20014 +               ret = -EINVAL;
20015 +               if (!path.dentry->d_inode)
20016 +                       goto out_release;
20017 +               if (!(sb = path.dentry->d_inode->i_sb))
20018 +                       goto out_release;
20019 +
20020 +               if (add) {
20021 +                       dli = __alloc_dl_info(sb, id);
20022 +                       spin_lock(&dl_info_hash_lock);
20023 +
20024 +                       ret = -EEXIST;
20025 +                       if (__lookup_dl_info(sb, id))
20026 +                               goto out_unlock;
20027 +                       __hash_dl_info(dli);
20028 +                       dli = NULL;
20029 +               } else {
20030 +                       spin_lock(&dl_info_hash_lock);
20031 +                       dli = __lookup_dl_info(sb, id);
20032 +
20033 +                       ret = -ESRCH;
20034 +                       if (!dli)
20035 +                               goto out_unlock;
20036 +                       __unhash_dl_info(dli);
20037 +               }
20038 +               ret = 0;
20039 +       out_unlock:
20040 +               spin_unlock(&dl_info_hash_lock);
20041 +               if (add && dli)
20042 +                       __dealloc_dl_info(dli);
20043 +       out_release:
20044 +               path_put(&path);
20045 +       }
20046 +       return ret;
20047 +}
20048 +
20049 +int vc_add_dlimit(uint32_t id, void __user *data)
20050 +{
20051 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20052 +
20053 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20054 +               return -EFAULT;
20055 +
20056 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
20057 +}
20058 +
20059 +int vc_rem_dlimit(uint32_t id, void __user *data)
20060 +{
20061 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20062 +
20063 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20064 +               return -EFAULT;
20065 +
20066 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
20067 +}
20068 +
20069 +#ifdef CONFIG_COMPAT
20070 +
20071 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
20072 +{
20073 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20074 +
20075 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20076 +               return -EFAULT;
20077 +
20078 +       return do_addrem_dlimit(id,
20079 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
20080 +}
20081 +
20082 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
20083 +{
20084 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20085 +
20086 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20087 +               return -EFAULT;
20088 +
20089 +       return do_addrem_dlimit(id,
20090 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
20091 +}
20092 +
20093 +#endif /* CONFIG_COMPAT */
20094 +
20095 +
20096 +static inline
20097 +int do_set_dlimit(uint32_t id, const char __user *name,
20098 +       uint32_t space_used, uint32_t space_total,
20099 +       uint32_t inodes_used, uint32_t inodes_total,
20100 +       uint32_t reserved, uint32_t flags)
20101 +{
20102 +       struct path path;
20103 +       int ret;
20104 +
20105 +       ret = user_lpath(name, &path);
20106 +       if (!ret) {
20107 +               struct super_block *sb;
20108 +               struct dl_info *dli;
20109 +
20110 +               ret = -EINVAL;
20111 +               if (!path.dentry->d_inode)
20112 +                       goto out_release;
20113 +               if (!(sb = path.dentry->d_inode->i_sb))
20114 +                       goto out_release;
20115 +
20116 +               /* sanity checks */
20117 +               if ((reserved != CDLIM_KEEP &&
20118 +                       reserved > 100) ||
20119 +                       (inodes_used != CDLIM_KEEP &&
20120 +                       inodes_used > inodes_total) ||
20121 +                       (space_used != CDLIM_KEEP &&
20122 +                       space_used > space_total))
20123 +                       goto out_release;
20124 +
20125 +               ret = -ESRCH;
20126 +               dli = locate_dl_info(sb, id);
20127 +               if (!dli)
20128 +                       goto out_release;
20129 +
20130 +               spin_lock(&dli->dl_lock);
20131 +
20132 +               if (inodes_used != CDLIM_KEEP)
20133 +                       dli->dl_inodes_used = inodes_used;
20134 +               if (inodes_total != CDLIM_KEEP)
20135 +                       dli->dl_inodes_total = inodes_total;
20136 +               if (space_used != CDLIM_KEEP)
20137 +                       dli->dl_space_used = dlimit_space_32to64(
20138 +                               space_used, flags, DLIMS_USED);
20139 +
20140 +               if (space_total == CDLIM_INFINITY)
20141 +                       dli->dl_space_total = DLIM_INFINITY;
20142 +               else if (space_total != CDLIM_KEEP)
20143 +                       dli->dl_space_total = dlimit_space_32to64(
20144 +                               space_total, flags, DLIMS_TOTAL);
20145 +
20146 +               if (reserved != CDLIM_KEEP)
20147 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
20148 +
20149 +               spin_unlock(&dli->dl_lock);
20150 +
20151 +               put_dl_info(dli);
20152 +               ret = 0;
20153 +
20154 +       out_release:
20155 +               path_put(&path);
20156 +       }
20157 +       return ret;
20158 +}
20159 +
20160 +int vc_set_dlimit(uint32_t id, void __user *data)
20161 +{
20162 +       struct vcmd_ctx_dlimit_v0 vc_data;
20163 +
20164 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20165 +               return -EFAULT;
20166 +
20167 +       return do_set_dlimit(id, vc_data.name,
20168 +               vc_data.space_used, vc_data.space_total,
20169 +               vc_data.inodes_used, vc_data.inodes_total,
20170 +               vc_data.reserved, vc_data.flags);
20171 +}
20172 +
20173 +#ifdef CONFIG_COMPAT
20174 +
20175 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20176 +{
20177 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20178 +
20179 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20180 +               return -EFAULT;
20181 +
20182 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20183 +               vc_data.space_used, vc_data.space_total,
20184 +               vc_data.inodes_used, vc_data.inodes_total,
20185 +               vc_data.reserved, vc_data.flags);
20186 +}
20187 +
20188 +#endif /* CONFIG_COMPAT */
20189 +
20190 +
20191 +static inline
20192 +int do_get_dlimit(uint32_t id, const char __user *name,
20193 +       uint32_t *space_used, uint32_t *space_total,
20194 +       uint32_t *inodes_used, uint32_t *inodes_total,
20195 +       uint32_t *reserved, uint32_t *flags)
20196 +{
20197 +       struct path path;
20198 +       int ret;
20199 +
20200 +       ret = user_lpath(name, &path);
20201 +       if (!ret) {
20202 +               struct super_block *sb;
20203 +               struct dl_info *dli;
20204 +
20205 +               ret = -EINVAL;
20206 +               if (!path.dentry->d_inode)
20207 +                       goto out_release;
20208 +               if (!(sb = path.dentry->d_inode->i_sb))
20209 +                       goto out_release;
20210 +
20211 +               ret = -ESRCH;
20212 +               dli = locate_dl_info(sb, id);
20213 +               if (!dli)
20214 +                       goto out_release;
20215 +
20216 +               spin_lock(&dli->dl_lock);
20217 +               *inodes_used = dli->dl_inodes_used;
20218 +               *inodes_total = dli->dl_inodes_total;
20219 +
20220 +               *space_used = dlimit_space_64to32(
20221 +                       dli->dl_space_used, flags, DLIMS_USED);
20222 +
20223 +               if (dli->dl_space_total == DLIM_INFINITY)
20224 +                       *space_total = CDLIM_INFINITY;
20225 +               else
20226 +                       *space_total = dlimit_space_64to32(
20227 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
20228 +
20229 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20230 +               spin_unlock(&dli->dl_lock);
20231 +
20232 +               put_dl_info(dli);
20233 +               ret = -EFAULT;
20234 +
20235 +               ret = 0;
20236 +       out_release:
20237 +               path_put(&path);
20238 +       }
20239 +       return ret;
20240 +}
20241 +
20242 +
20243 +int vc_get_dlimit(uint32_t id, void __user *data)
20244 +{
20245 +       struct vcmd_ctx_dlimit_v0 vc_data;
20246 +       int ret;
20247 +
20248 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20249 +               return -EFAULT;
20250 +
20251 +       ret = do_get_dlimit(id, vc_data.name,
20252 +               &vc_data.space_used, &vc_data.space_total,
20253 +               &vc_data.inodes_used, &vc_data.inodes_total,
20254 +               &vc_data.reserved, &vc_data.flags);
20255 +       if (ret)
20256 +               return ret;
20257 +
20258 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20259 +               return -EFAULT;
20260 +       return 0;
20261 +}
20262 +
20263 +#ifdef CONFIG_COMPAT
20264 +
20265 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20266 +{
20267 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20268 +       int ret;
20269 +
20270 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20271 +               return -EFAULT;
20272 +
20273 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20274 +               &vc_data.space_used, &vc_data.space_total,
20275 +               &vc_data.inodes_used, &vc_data.inodes_total,
20276 +               &vc_data.reserved, &vc_data.flags);
20277 +       if (ret)
20278 +               return ret;
20279 +
20280 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20281 +               return -EFAULT;
20282 +       return 0;
20283 +}
20284 +
20285 +#endif /* CONFIG_COMPAT */
20286 +
20287 +
20288 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20289 +{
20290 +       struct dl_info *dli;
20291 +       __u64 blimit, bfree, bavail;
20292 +       __u32 ifree;
20293 +
20294 +       dli = locate_dl_info(sb, dx_current_tag());
20295 +       if (!dli)
20296 +               return;
20297 +
20298 +       spin_lock(&dli->dl_lock);
20299 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20300 +               goto no_ilim;
20301 +
20302 +       /* reduce max inodes available to limit */
20303 +       if (buf->f_files > dli->dl_inodes_total)
20304 +               buf->f_files = dli->dl_inodes_total;
20305 +
20306 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20307 +       /* reduce free inodes to min */
20308 +       if (ifree < buf->f_ffree)
20309 +               buf->f_ffree = ifree;
20310 +
20311 +no_ilim:
20312 +       if (dli->dl_space_total == DLIM_INFINITY)
20313 +               goto no_blim;
20314 +
20315 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20316 +
20317 +       if (dli->dl_space_total < dli->dl_space_used)
20318 +               bfree = 0;
20319 +       else
20320 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20321 +                       >> sb->s_blocksize_bits;
20322 +
20323 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20324 +       if (bavail < dli->dl_space_used)
20325 +               bavail = 0;
20326 +       else
20327 +               bavail = (bavail - dli->dl_space_used)
20328 +                       >> sb->s_blocksize_bits;
20329 +
20330 +       /* reduce max space available to limit */
20331 +       if (buf->f_blocks > blimit)
20332 +               buf->f_blocks = blimit;
20333 +
20334 +       /* reduce free space to min */
20335 +       if (bfree < buf->f_bfree)
20336 +               buf->f_bfree = bfree;
20337 +
20338 +       /* reduce avail space to min */
20339 +       if (bavail < buf->f_bavail)
20340 +               buf->f_bavail = bavail;
20341 +
20342 +no_blim:
20343 +       spin_unlock(&dli->dl_lock);
20344 +       put_dl_info(dli);
20345 +
20346 +       return;
20347 +}
20348 +
20349 +#include <linux/module.h>
20350 +
20351 +EXPORT_SYMBOL_GPL(locate_dl_info);
20352 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20353 +
20354 diff -NurpP --minimal linux-3.1/kernel/vserver/helper.c linux-3.1-vs2.3.1-rc2/kernel/vserver/helper.c
20355 --- linux-3.1/kernel/vserver/helper.c   1970-01-01 01:00:00.000000000 +0100
20356 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/helper.c       2011-10-24 18:53:33.000000000 +0200
20357 @@ -0,0 +1,223 @@
20358 +/*
20359 + *  linux/kernel/vserver/helper.c
20360 + *
20361 + *  Virtual Context Support
20362 + *
20363 + *  Copyright (C) 2004-2007  Herbert Pötzl
20364 + *
20365 + *  V0.01  basic helper
20366 + *
20367 + */
20368 +
20369 +#include <linux/kmod.h>
20370 +#include <linux/reboot.h>
20371 +#include <linux/vs_context.h>
20372 +#include <linux/vs_network.h>
20373 +#include <linux/vserver/signal.h>
20374 +
20375 +
20376 +char vshelper_path[255] = "/sbin/vshelper";
20377 +
20378 +
20379 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20380 +{
20381 +       int ret;
20382 +
20383 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20384 +               printk( KERN_WARNING
20385 +                       "%s: (%s %s) returned %s with %d\n",
20386 +                       name, argv[1], argv[2],
20387 +                       sync ? "sync" : "async", ret);
20388 +       }
20389 +       vxdprintk(VXD_CBIT(switch, 4),
20390 +               "%s: (%s %s) returned %s with %d",
20391 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20392 +       return ret;
20393 +}
20394 +
20395 +/*
20396 + *      vshelper path is set via /proc/sys
20397 + *      invoked by vserver sys_reboot(), with
20398 + *      the following arguments
20399 + *
20400 + *      argv [0] = vshelper_path;
20401 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20402 + *      argv [2] = context identifier
20403 + *
20404 + *      envp [*] = type-specific parameters
20405 + */
20406 +
20407 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20408 +{
20409 +       char id_buf[8], cmd_buf[16];
20410 +       char uid_buf[16], pid_buf[16];
20411 +       int ret;
20412 +
20413 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20414 +       char *envp[] = {"HOME=/", "TERM=linux",
20415 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20416 +                       uid_buf, pid_buf, cmd_buf, 0};
20417 +
20418 +       if (vx_info_state(vxi, VXS_HELPER))
20419 +               return -EAGAIN;
20420 +       vxi->vx_state |= VXS_HELPER;
20421 +
20422 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20423 +
20424 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20425 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
20426 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20427 +
20428 +       switch (cmd) {
20429 +       case LINUX_REBOOT_CMD_RESTART:
20430 +               argv[1] = "restart";
20431 +               break;
20432 +
20433 +       case LINUX_REBOOT_CMD_HALT:
20434 +               argv[1] = "halt";
20435 +               break;
20436 +
20437 +       case LINUX_REBOOT_CMD_POWER_OFF:
20438 +               argv[1] = "poweroff";
20439 +               break;
20440 +
20441 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20442 +               argv[1] = "swsusp";
20443 +               break;
20444 +
20445 +       case LINUX_REBOOT_CMD_OOM:
20446 +               argv[1] = "oom";
20447 +               break;
20448 +
20449 +       default:
20450 +               vxi->vx_state &= ~VXS_HELPER;
20451 +               return 0;
20452 +       }
20453 +
20454 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20455 +       vxi->vx_state &= ~VXS_HELPER;
20456 +       __wakeup_vx_info(vxi);
20457 +       return (ret) ? -EPERM : 0;
20458 +}
20459 +
20460 +
20461 +long vs_reboot(unsigned int cmd, void __user *arg)
20462 +{
20463 +       struct vx_info *vxi = current_vx_info();
20464 +       long ret = 0;
20465 +
20466 +       vxdprintk(VXD_CBIT(misc, 5),
20467 +               "vs_reboot(%p[#%d],%u)",
20468 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20469 +
20470 +       ret = vs_reboot_helper(vxi, cmd, arg);
20471 +       if (ret)
20472 +               return ret;
20473 +
20474 +       vxi->reboot_cmd = cmd;
20475 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20476 +               switch (cmd) {
20477 +               case LINUX_REBOOT_CMD_RESTART:
20478 +               case LINUX_REBOOT_CMD_HALT:
20479 +               case LINUX_REBOOT_CMD_POWER_OFF:
20480 +                       vx_info_kill(vxi, 0, SIGKILL);
20481 +                       vx_info_kill(vxi, 1, SIGKILL);
20482 +               default:
20483 +                       break;
20484 +               }
20485 +       }
20486 +       return 0;
20487 +}
20488 +
20489 +long vs_oom_action(unsigned int cmd)
20490 +{
20491 +       struct vx_info *vxi = current_vx_info();
20492 +       long ret = 0;
20493 +
20494 +       vxdprintk(VXD_CBIT(misc, 5),
20495 +               "vs_oom_action(%p[#%d],%u)",
20496 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20497 +
20498 +       ret = vs_reboot_helper(vxi, cmd, NULL);
20499 +       if (ret)
20500 +               return ret;
20501 +
20502 +       vxi->reboot_cmd = cmd;
20503 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20504 +               vx_info_kill(vxi, 0, SIGKILL);
20505 +               vx_info_kill(vxi, 1, SIGKILL);
20506 +       }
20507 +       return 0;
20508 +}
20509 +
20510 +/*
20511 + *      argv [0] = vshelper_path;
20512 + *      argv [1] = action: "startup", "shutdown"
20513 + *      argv [2] = context identifier
20514 + *
20515 + *      envp [*] = type-specific parameters
20516 + */
20517 +
20518 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20519 +{
20520 +       char id_buf[8], cmd_buf[16];
20521 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20522 +       char *envp[] = {"HOME=/", "TERM=linux",
20523 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20524 +
20525 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20526 +               return 0;
20527 +
20528 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20529 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20530 +
20531 +       switch (cmd) {
20532 +       case VSC_STARTUP:
20533 +               argv[1] = "startup";
20534 +               break;
20535 +       case VSC_SHUTDOWN:
20536 +               argv[1] = "shutdown";
20537 +               break;
20538 +       default:
20539 +               return 0;
20540 +       }
20541 +
20542 +       return do_vshelper(vshelper_path, argv, envp, 1);
20543 +}
20544 +
20545 +
20546 +/*
20547 + *      argv [0] = vshelper_path;
20548 + *      argv [1] = action: "netup", "netdown"
20549 + *      argv [2] = context identifier
20550 + *
20551 + *      envp [*] = type-specific parameters
20552 + */
20553 +
20554 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20555 +{
20556 +       char id_buf[8], cmd_buf[16];
20557 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20558 +       char *envp[] = {"HOME=/", "TERM=linux",
20559 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20560 +
20561 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20562 +               return 0;
20563 +
20564 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20565 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20566 +
20567 +       switch (cmd) {
20568 +       case VSC_NETUP:
20569 +               argv[1] = "netup";
20570 +               break;
20571 +       case VSC_NETDOWN:
20572 +               argv[1] = "netdown";
20573 +               break;
20574 +       default:
20575 +               return 0;
20576 +       }
20577 +
20578 +       return do_vshelper(vshelper_path, argv, envp, 1);
20579 +}
20580 +
20581 diff -NurpP --minimal linux-3.1/kernel/vserver/history.c linux-3.1-vs2.3.1-rc2/kernel/vserver/history.c
20582 --- linux-3.1/kernel/vserver/history.c  1970-01-01 01:00:00.000000000 +0100
20583 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/history.c      2011-10-24 18:53:33.000000000 +0200
20584 @@ -0,0 +1,258 @@
20585 +/*
20586 + *  kernel/vserver/history.c
20587 + *
20588 + *  Virtual Context History Backtrace
20589 + *
20590 + *  Copyright (C) 2004-2007  Herbert Pötzl
20591 + *
20592 + *  V0.01  basic structure
20593 + *  V0.02  hash/unhash and trace
20594 + *  V0.03  preemption fixes
20595 + *
20596 + */
20597 +
20598 +#include <linux/module.h>
20599 +#include <asm/uaccess.h>
20600 +
20601 +#include <linux/vserver/context.h>
20602 +#include <linux/vserver/debug.h>
20603 +#include <linux/vserver/debug_cmd.h>
20604 +#include <linux/vserver/history.h>
20605 +
20606 +
20607 +#ifdef CONFIG_VSERVER_HISTORY
20608 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20609 +#else
20610 +#define VXH_SIZE       64
20611 +#endif
20612 +
20613 +struct _vx_history {
20614 +       unsigned int counter;
20615 +
20616 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20617 +};
20618 +
20619 +
20620 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20621 +
20622 +unsigned volatile int vxh_active = 1;
20623 +
20624 +static atomic_t sequence = ATOMIC_INIT(0);
20625 +
20626 +
20627 +/*     vxh_advance()
20628 +
20629 +       * requires disabled preemption                          */
20630 +
20631 +struct _vx_hist_entry *vxh_advance(void *loc)
20632 +{
20633 +       unsigned int cpu = smp_processor_id();
20634 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20635 +       struct _vx_hist_entry *entry;
20636 +       unsigned int index;
20637 +
20638 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20639 +       entry = &hist->entry[index];
20640 +
20641 +       entry->seq = atomic_inc_return(&sequence);
20642 +       entry->loc = loc;
20643 +       return entry;
20644 +}
20645 +
20646 +EXPORT_SYMBOL_GPL(vxh_advance);
20647 +
20648 +
20649 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20650 +
20651 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20652 +
20653 +
20654 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20655 +
20656 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20657 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20658 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20659 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20660 +
20661 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20662 +{
20663 +       switch (e->type) {
20664 +       case VXH_THROW_OOPS:
20665 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20666 +               break;
20667 +
20668 +       case VXH_GET_VX_INFO:
20669 +       case VXH_PUT_VX_INFO:
20670 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20671 +                       VXH_LOC_ARGS(e),
20672 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20673 +                       VXH_VXI_ARGS(e));
20674 +               break;
20675 +
20676 +       case VXH_INIT_VX_INFO:
20677 +       case VXH_SET_VX_INFO:
20678 +       case VXH_CLR_VX_INFO:
20679 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20680 +                       VXH_LOC_ARGS(e),
20681 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20682 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20683 +                       VXH_VXI_ARGS(e), e->sc.data);
20684 +               break;
20685 +
20686 +       case VXH_CLAIM_VX_INFO:
20687 +       case VXH_RELEASE_VX_INFO:
20688 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20689 +                       VXH_LOC_ARGS(e),
20690 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20691 +                       VXH_VXI_ARGS(e), e->sc.data);
20692 +               break;
20693 +
20694 +       case VXH_ALLOC_VX_INFO:
20695 +       case VXH_DEALLOC_VX_INFO:
20696 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20697 +                       VXH_LOC_ARGS(e),
20698 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20699 +                       VXH_VXI_ARGS(e));
20700 +               break;
20701 +
20702 +       case VXH_HASH_VX_INFO:
20703 +       case VXH_UNHASH_VX_INFO:
20704 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20705 +                       VXH_LOC_ARGS(e),
20706 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20707 +                       VXH_VXI_ARGS(e));
20708 +               break;
20709 +
20710 +       case VXH_LOC_VX_INFO:
20711 +       case VXH_LOOKUP_VX_INFO:
20712 +       case VXH_CREATE_VX_INFO:
20713 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20714 +                       VXH_LOC_ARGS(e),
20715 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20716 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20717 +                       e->ll.arg, VXH_VXI_ARGS(e));
20718 +               break;
20719 +       }
20720 +}
20721 +
20722 +static void __vxh_dump_history(void)
20723 +{
20724 +       unsigned int i, cpu;
20725 +
20726 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20727 +               atomic_read(&sequence), NR_CPUS);
20728 +
20729 +       for (i = 0; i < VXH_SIZE; i++) {
20730 +               for_each_online_cpu(cpu) {
20731 +                       struct _vx_history *hist =
20732 +                               &per_cpu(vx_history_buffer, cpu);
20733 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20734 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20735 +
20736 +                       vxh_dump_entry(entry, cpu);
20737 +               }
20738 +       }
20739 +}
20740 +
20741 +void   vxh_dump_history(void)
20742 +{
20743 +       vxh_active = 0;
20744 +#ifdef CONFIG_SMP
20745 +       local_irq_enable();
20746 +       smp_send_stop();
20747 +       local_irq_disable();
20748 +#endif
20749 +       __vxh_dump_history();
20750 +}
20751 +
20752 +
20753 +/* vserver syscall commands below here */
20754 +
20755 +
20756 +int vc_dump_history(uint32_t id)
20757 +{
20758 +       vxh_active = 0;
20759 +       __vxh_dump_history();
20760 +       vxh_active = 1;
20761 +
20762 +       return 0;
20763 +}
20764 +
20765 +
20766 +int do_read_history(struct __user _vx_hist_entry *data,
20767 +       int cpu, uint32_t *index, uint32_t *count)
20768 +{
20769 +       int pos, ret = 0;
20770 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20771 +       int end = hist->counter;
20772 +       int start = end - VXH_SIZE + 2;
20773 +       int idx = *index;
20774 +
20775 +       /* special case: get current pos */
20776 +       if (!*count) {
20777 +               *index = end;
20778 +               return 0;
20779 +       }
20780 +
20781 +       /* have we lost some data? */
20782 +       if (idx < start)
20783 +               idx = start;
20784 +
20785 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20786 +               struct _vx_hist_entry *entry =
20787 +                       &hist->entry[idx % VXH_SIZE];
20788 +
20789 +               /* send entry to userspace */
20790 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20791 +               if (ret)
20792 +                       break;
20793 +       }
20794 +       /* save new index and count */
20795 +       *index = idx;
20796 +       *count = pos;
20797 +       return ret ? ret : (*index < end);
20798 +}
20799 +
20800 +int vc_read_history(uint32_t id, void __user *data)
20801 +{
20802 +       struct vcmd_read_history_v0 vc_data;
20803 +       int ret;
20804 +
20805 +       if (id >= NR_CPUS)
20806 +               return -EINVAL;
20807 +
20808 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20809 +               return -EFAULT;
20810 +
20811 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20812 +               id, &vc_data.index, &vc_data.count);
20813 +
20814 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20815 +               return -EFAULT;
20816 +       return ret;
20817 +}
20818 +
20819 +#ifdef CONFIG_COMPAT
20820 +
20821 +int vc_read_history_x32(uint32_t id, void __user *data)
20822 +{
20823 +       struct vcmd_read_history_v0_x32 vc_data;
20824 +       int ret;
20825 +
20826 +       if (id >= NR_CPUS)
20827 +               return -EINVAL;
20828 +
20829 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20830 +               return -EFAULT;
20831 +
20832 +       ret = do_read_history((struct __user _vx_hist_entry *)
20833 +               compat_ptr(vc_data.data_ptr),
20834 +               id, &vc_data.index, &vc_data.count);
20835 +
20836 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20837 +               return -EFAULT;
20838 +       return ret;
20839 +}
20840 +
20841 +#endif /* CONFIG_COMPAT */
20842 +
20843 diff -NurpP --minimal linux-3.1/kernel/vserver/inet.c linux-3.1-vs2.3.1-rc2/kernel/vserver/inet.c
20844 --- linux-3.1/kernel/vserver/inet.c     1970-01-01 01:00:00.000000000 +0100
20845 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/inet.c 2011-10-24 18:53:33.000000000 +0200
20846 @@ -0,0 +1,225 @@
20847 +
20848 +#include <linux/in.h>
20849 +#include <linux/inetdevice.h>
20850 +#include <linux/vs_inet.h>
20851 +#include <linux/vs_inet6.h>
20852 +#include <linux/vserver/debug.h>
20853 +#include <net/route.h>
20854 +#include <net/addrconf.h>
20855 +
20856 +
20857 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20858 +{
20859 +       int ret = 0;
20860 +
20861 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20862 +               ret = 1;
20863 +       else {
20864 +               struct nx_addr_v4 *ptr;
20865 +
20866 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20867 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20868 +                               ret = 1;
20869 +                               break;
20870 +                       }
20871 +               }
20872 +       }
20873 +
20874 +       vxdprintk(VXD_CBIT(net, 2),
20875 +               "nx_v4_addr_conflict(%p,%p): %d",
20876 +               nxi1, nxi2, ret);
20877 +
20878 +       return ret;
20879 +}
20880 +
20881 +
20882 +#ifdef CONFIG_IPV6
20883 +
20884 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20885 +{
20886 +       int ret = 0;
20887 +
20888 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20889 +               ret = 1;
20890 +       else {
20891 +               struct nx_addr_v6 *ptr;
20892 +
20893 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20894 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20895 +                               ret = 1;
20896 +                               break;
20897 +                       }
20898 +               }
20899 +       }
20900 +
20901 +       vxdprintk(VXD_CBIT(net, 2),
20902 +               "nx_v6_addr_conflict(%p,%p): %d",
20903 +               nxi1, nxi2, ret);
20904 +
20905 +       return ret;
20906 +}
20907 +
20908 +#endif
20909 +
20910 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20911 +{
20912 +       struct in_device *in_dev;
20913 +       struct in_ifaddr **ifap;
20914 +       struct in_ifaddr *ifa;
20915 +       int ret = 0;
20916 +
20917 +       if (!dev)
20918 +               goto out;
20919 +       in_dev = in_dev_get(dev);
20920 +       if (!in_dev)
20921 +               goto out;
20922 +
20923 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20924 +               ifap = &ifa->ifa_next) {
20925 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20926 +                       ret = 1;
20927 +                       break;
20928 +               }
20929 +       }
20930 +       in_dev_put(in_dev);
20931 +out:
20932 +       return ret;
20933 +}
20934 +
20935 +
20936 +#ifdef CONFIG_IPV6
20937 +
20938 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20939 +{
20940 +       struct inet6_dev *in_dev;
20941 +       struct inet6_ifaddr *ifa;
20942 +       int ret = 0;
20943 +
20944 +       if (!dev)
20945 +               goto out;
20946 +       in_dev = in6_dev_get(dev);
20947 +       if (!in_dev)
20948 +               goto out;
20949 +
20950 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20951 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
20952 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20953 +                       ret = 1;
20954 +                       break;
20955 +               }
20956 +       }
20957 +       in6_dev_put(in_dev);
20958 +out:
20959 +       return ret;
20960 +}
20961 +
20962 +#endif
20963 +
20964 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20965 +{
20966 +       int ret = 1;
20967 +
20968 +       if (!nxi)
20969 +               goto out;
20970 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20971 +               goto out;
20972 +#ifdef CONFIG_IPV6
20973 +       ret = 2;
20974 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20975 +               goto out;
20976 +#endif
20977 +       ret = 0;
20978 +out:
20979 +       vxdprintk(VXD_CBIT(net, 3),
20980 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20981 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20982 +       return ret;
20983 +}
20984 +
20985 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
20986 +       struct flowi4 *fl4)
20987 +{
20988 +       struct rtable *rt;
20989 +
20990 +       if (!nxi)
20991 +               return NULL;
20992 +
20993 +       /* FIXME: handle lback only case */
20994 +       if (!NX_IPV4(nxi))
20995 +               return ERR_PTR(-EPERM);
20996 +
20997 +       vxdprintk(VXD_CBIT(net, 4),
20998 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20999 +               nxi, nxi ? nxi->nx_id : 0,
21000 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
21001 +
21002 +       /* single IP is unconditional */
21003 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
21004 +               (fl4->saddr == INADDR_ANY))
21005 +               fl4->saddr = nxi->v4.ip[0].s_addr;
21006 +
21007 +       if (fl4->saddr == INADDR_ANY) {
21008 +               struct nx_addr_v4 *ptr;
21009 +               __be32 found = 0;
21010 +
21011 +               rt = __ip_route_output_key(net, fl4);
21012 +               if (!IS_ERR(rt)) {
21013 +                       found = fl4->saddr;
21014 +                       ip_rt_put(rt);
21015 +                       vxdprintk(VXD_CBIT(net, 4),
21016 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21017 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
21018 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
21019 +                               goto found;
21020 +               }
21021 +
21022 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
21023 +                       __be32 primary = ptr->ip[0].s_addr;
21024 +                       __be32 mask = ptr->mask.s_addr;
21025 +                       __be32 neta = primary & mask;
21026 +
21027 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
21028 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
21029 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
21030 +                               NIPQUAD(mask), NIPQUAD(neta));
21031 +                       if ((found & mask) != neta)
21032 +                               continue;
21033 +
21034 +                       fl4->saddr = primary;
21035 +                       rt = __ip_route_output_key(net, fl4);
21036 +                       vxdprintk(VXD_CBIT(net, 4),
21037 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21038 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
21039 +                       if (!IS_ERR(rt)) {
21040 +                               found = fl4->saddr;
21041 +                               ip_rt_put(rt);
21042 +                               if (found == primary)
21043 +                                       goto found;
21044 +                       }
21045 +               }
21046 +               /* still no source ip? */
21047 +               found = ipv4_is_loopback(fl4->daddr)
21048 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
21049 +       found:
21050 +               /* assign src ip to flow */
21051 +               fl4->saddr = found;
21052 +
21053 +       } else {
21054 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
21055 +                       return ERR_PTR(-EPERM);
21056 +       }
21057 +
21058 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
21059 +               if (ipv4_is_loopback(fl4->daddr))
21060 +                       fl4->daddr = nxi->v4_lback.s_addr;
21061 +               if (ipv4_is_loopback(fl4->saddr))
21062 +                       fl4->saddr = nxi->v4_lback.s_addr;
21063 +       } else if (ipv4_is_loopback(fl4->daddr) &&
21064 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
21065 +               return ERR_PTR(-EPERM);
21066 +
21067 +       return NULL;
21068 +}
21069 +
21070 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
21071 +
21072 diff -NurpP --minimal linux-3.1/kernel/vserver/init.c linux-3.1-vs2.3.1-rc2/kernel/vserver/init.c
21073 --- linux-3.1/kernel/vserver/init.c     1970-01-01 01:00:00.000000000 +0100
21074 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/init.c 2011-10-24 18:53:33.000000000 +0200
21075 @@ -0,0 +1,45 @@
21076 +/*
21077 + *  linux/kernel/init.c
21078 + *
21079 + *  Virtual Server Init
21080 + *
21081 + *  Copyright (C) 2004-2007  Herbert Pötzl
21082 + *
21083 + *  V0.01  basic structure
21084 + *
21085 + */
21086 +
21087 +#include <linux/init.h>
21088 +
21089 +int    vserver_register_sysctl(void);
21090 +void   vserver_unregister_sysctl(void);
21091 +
21092 +
21093 +static int __init init_vserver(void)
21094 +{
21095 +       int ret = 0;
21096 +
21097 +#ifdef CONFIG_VSERVER_DEBUG
21098 +       vserver_register_sysctl();
21099 +#endif
21100 +       return ret;
21101 +}
21102 +
21103 +
21104 +static void __exit exit_vserver(void)
21105 +{
21106 +
21107 +#ifdef CONFIG_VSERVER_DEBUG
21108 +       vserver_unregister_sysctl();
21109 +#endif
21110 +       return;
21111 +}
21112 +
21113 +/* FIXME: GFP_ZONETYPES gone
21114 +long vx_slab[GFP_ZONETYPES]; */
21115 +long vx_area;
21116 +
21117 +
21118 +module_init(init_vserver);
21119 +module_exit(exit_vserver);
21120 +
21121 diff -NurpP --minimal linux-3.1/kernel/vserver/inode.c linux-3.1-vs2.3.1-rc2/kernel/vserver/inode.c
21122 --- linux-3.1/kernel/vserver/inode.c    1970-01-01 01:00:00.000000000 +0100
21123 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/inode.c        2011-10-24 18:53:33.000000000 +0200
21124 @@ -0,0 +1,437 @@
21125 +/*
21126 + *  linux/kernel/vserver/inode.c
21127 + *
21128 + *  Virtual Server: File System Support
21129 + *
21130 + *  Copyright (C) 2004-2007  Herbert Pötzl
21131 + *
21132 + *  V0.01  separated from vcontext V0.05
21133 + *  V0.02  moved to tag (instead of xid)
21134 + *
21135 + */
21136 +
21137 +#include <linux/tty.h>
21138 +#include <linux/proc_fs.h>
21139 +#include <linux/devpts_fs.h>
21140 +#include <linux/fs.h>
21141 +#include <linux/file.h>
21142 +#include <linux/mount.h>
21143 +#include <linux/parser.h>
21144 +#include <linux/namei.h>
21145 +#include <linux/vserver/inode.h>
21146 +#include <linux/vserver/inode_cmd.h>
21147 +#include <linux/vs_base.h>
21148 +#include <linux/vs_tag.h>
21149 +
21150 +#include <asm/uaccess.h>
21151 +
21152 +
21153 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21154 +{
21155 +       struct proc_dir_entry *entry;
21156 +
21157 +       if (!in || !in->i_sb)
21158 +               return -ESRCH;
21159 +
21160 +       *flags = IATTR_TAG
21161 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
21162 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
21163 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
21164 +               | (IS_COW(in) ? IATTR_COW : 0);
21165 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
21166 +
21167 +       if (S_ISDIR(in->i_mode))
21168 +               *mask |= IATTR_BARRIER;
21169 +
21170 +       if (IS_TAGGED(in)) {
21171 +               *tag = in->i_tag;
21172 +               *mask |= IATTR_TAG;
21173 +       }
21174 +
21175 +       switch (in->i_sb->s_magic) {
21176 +       case PROC_SUPER_MAGIC:
21177 +               entry = PROC_I(in)->pde;
21178 +
21179 +               /* check for specific inodes? */
21180 +               if (entry)
21181 +                       *mask |= IATTR_FLAGS;
21182 +               if (entry)
21183 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21184 +               else
21185 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21186 +               break;
21187 +
21188 +       case DEVPTS_SUPER_MAGIC:
21189 +               *tag = in->i_tag;
21190 +               *mask |= IATTR_TAG;
21191 +               break;
21192 +
21193 +       default:
21194 +               break;
21195 +       }
21196 +       return 0;
21197 +}
21198 +
21199 +int vc_get_iattr(void __user *data)
21200 +{
21201 +       struct path path;
21202 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21203 +       int ret;
21204 +
21205 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21206 +               return -EFAULT;
21207 +
21208 +       ret = user_lpath(vc_data.name, &path);
21209 +       if (!ret) {
21210 +               ret = __vc_get_iattr(path.dentry->d_inode,
21211 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21212 +               path_put(&path);
21213 +       }
21214 +       if (ret)
21215 +               return ret;
21216 +
21217 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21218 +               ret = -EFAULT;
21219 +       return ret;
21220 +}
21221 +
21222 +#ifdef CONFIG_COMPAT
21223 +
21224 +int vc_get_iattr_x32(void __user *data)
21225 +{
21226 +       struct path path;
21227 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21228 +       int ret;
21229 +
21230 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21231 +               return -EFAULT;
21232 +
21233 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21234 +       if (!ret) {
21235 +               ret = __vc_get_iattr(path.dentry->d_inode,
21236 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21237 +               path_put(&path);
21238 +       }
21239 +       if (ret)
21240 +               return ret;
21241 +
21242 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21243 +               ret = -EFAULT;
21244 +       return ret;
21245 +}
21246 +
21247 +#endif /* CONFIG_COMPAT */
21248 +
21249 +
21250 +int vc_fget_iattr(uint32_t fd, void __user *data)
21251 +{
21252 +       struct file *filp;
21253 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21254 +       int ret;
21255 +
21256 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21257 +               return -EFAULT;
21258 +
21259 +       filp = fget(fd);
21260 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21261 +               return -EBADF;
21262 +
21263 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21264 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21265 +
21266 +       fput(filp);
21267 +
21268 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21269 +               ret = -EFAULT;
21270 +       return ret;
21271 +}
21272 +
21273 +
21274 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21275 +{
21276 +       struct inode *in = de->d_inode;
21277 +       int error = 0, is_proc = 0, has_tag = 0;
21278 +       struct iattr attr = { 0 };
21279 +
21280 +       if (!in || !in->i_sb)
21281 +               return -ESRCH;
21282 +
21283 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21284 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21285 +               return -EINVAL;
21286 +
21287 +       has_tag = IS_TAGGED(in) ||
21288 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21289 +       if ((*mask & IATTR_TAG) && !has_tag)
21290 +               return -EINVAL;
21291 +
21292 +       mutex_lock(&in->i_mutex);
21293 +       if (*mask & IATTR_TAG) {
21294 +               attr.ia_tag = *tag;
21295 +               attr.ia_valid |= ATTR_TAG;
21296 +       }
21297 +
21298 +       if (*mask & IATTR_FLAGS) {
21299 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21300 +               unsigned int iflags = PROC_I(in)->vx_flags;
21301 +
21302 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21303 +                       | (*flags & IATTR_FLAGS);
21304 +               PROC_I(in)->vx_flags = iflags;
21305 +               if (entry)
21306 +                       entry->vx_flags = iflags;
21307 +       }
21308 +
21309 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
21310 +               IATTR_BARRIER | IATTR_COW)) {
21311 +               int iflags = in->i_flags;
21312 +               int vflags = in->i_vflags;
21313 +
21314 +               if (*mask & IATTR_IMMUTABLE) {
21315 +                       if (*flags & IATTR_IMMUTABLE)
21316 +                               iflags |= S_IMMUTABLE;
21317 +                       else
21318 +                               iflags &= ~S_IMMUTABLE;
21319 +               }
21320 +               if (*mask & IATTR_IXUNLINK) {
21321 +                       if (*flags & IATTR_IXUNLINK)
21322 +                               iflags |= S_IXUNLINK;
21323 +                       else
21324 +                               iflags &= ~S_IXUNLINK;
21325 +               }
21326 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21327 +                       if (*flags & IATTR_BARRIER)
21328 +                               vflags |= V_BARRIER;
21329 +                       else
21330 +                               vflags &= ~V_BARRIER;
21331 +               }
21332 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
21333 +                       if (*flags & IATTR_COW)
21334 +                               vflags |= V_COW;
21335 +                       else
21336 +                               vflags &= ~V_COW;
21337 +               }
21338 +               if (in->i_op && in->i_op->sync_flags) {
21339 +                       error = in->i_op->sync_flags(in, iflags, vflags);
21340 +                       if (error)
21341 +                               goto out;
21342 +               }
21343 +       }
21344 +
21345 +       if (attr.ia_valid) {
21346 +               if (in->i_op && in->i_op->setattr)
21347 +                       error = in->i_op->setattr(de, &attr);
21348 +               else {
21349 +                       error = inode_change_ok(in, &attr);
21350 +                       if (!error) {
21351 +                               setattr_copy(in, &attr);
21352 +                               mark_inode_dirty(in);
21353 +                       }
21354 +               }
21355 +       }
21356 +
21357 +out:
21358 +       mutex_unlock(&in->i_mutex);
21359 +       return error;
21360 +}
21361 +
21362 +int vc_set_iattr(void __user *data)
21363 +{
21364 +       struct path path;
21365 +       struct vcmd_ctx_iattr_v1 vc_data;
21366 +       int ret;
21367 +
21368 +       if (!capable(CAP_LINUX_IMMUTABLE))
21369 +               return -EPERM;
21370 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21371 +               return -EFAULT;
21372 +
21373 +       ret = user_lpath(vc_data.name, &path);
21374 +       if (!ret) {
21375 +               ret = __vc_set_iattr(path.dentry,
21376 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21377 +               path_put(&path);
21378 +       }
21379 +
21380 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21381 +               ret = -EFAULT;
21382 +       return ret;
21383 +}
21384 +
21385 +#ifdef CONFIG_COMPAT
21386 +
21387 +int vc_set_iattr_x32(void __user *data)
21388 +{
21389 +       struct path path;
21390 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21391 +       int ret;
21392 +
21393 +       if (!capable(CAP_LINUX_IMMUTABLE))
21394 +               return -EPERM;
21395 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21396 +               return -EFAULT;
21397 +
21398 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21399 +       if (!ret) {
21400 +               ret = __vc_set_iattr(path.dentry,
21401 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21402 +               path_put(&path);
21403 +       }
21404 +
21405 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21406 +               ret = -EFAULT;
21407 +       return ret;
21408 +}
21409 +
21410 +#endif /* CONFIG_COMPAT */
21411 +
21412 +int vc_fset_iattr(uint32_t fd, void __user *data)
21413 +{
21414 +       struct file *filp;
21415 +       struct vcmd_ctx_fiattr_v0 vc_data;
21416 +       int ret;
21417 +
21418 +       if (!capable(CAP_LINUX_IMMUTABLE))
21419 +               return -EPERM;
21420 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21421 +               return -EFAULT;
21422 +
21423 +       filp = fget(fd);
21424 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21425 +               return -EBADF;
21426 +
21427 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21428 +               &vc_data.flags, &vc_data.mask);
21429 +
21430 +       fput(filp);
21431 +
21432 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21433 +               return -EFAULT;
21434 +       return ret;
21435 +}
21436 +
21437 +
21438 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21439 +
21440 +static match_table_t tokens = {
21441 +       {Opt_notagcheck, "notagcheck"},
21442 +#ifdef CONFIG_PROPAGATE
21443 +       {Opt_notag, "notag"},
21444 +       {Opt_tag, "tag"},
21445 +       {Opt_tagid, "tagid=%u"},
21446 +#endif
21447 +       {Opt_err, NULL}
21448 +};
21449 +
21450 +
21451 +static void __dx_parse_remove(char *string, char *opt)
21452 +{
21453 +       char *p = strstr(string, opt);
21454 +       char *q = p;
21455 +
21456 +       if (p) {
21457 +               while (*q != '\0' && *q != ',')
21458 +                       q++;
21459 +               while (*q)
21460 +                       *p++ = *q++;
21461 +               while (*p)
21462 +                       *p++ = '\0';
21463 +       }
21464 +}
21465 +
21466 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21467 +                unsigned long *flags)
21468 +{
21469 +       int set = 0;
21470 +       substring_t args[MAX_OPT_ARGS];
21471 +       int token;
21472 +       char *s, *p, *opts;
21473 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_WARN)
21474 +       int option = 0;
21475 +#endif
21476 +
21477 +       if (!string)
21478 +               return 0;
21479 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21480 +       if (!s)
21481 +               return 0;
21482 +
21483 +       opts = s;
21484 +       while ((p = strsep(&opts, ",")) != NULL) {
21485 +               token = match_token(p, tokens, args);
21486 +
21487 +               switch (token) {
21488 +#ifdef CONFIG_PROPAGATE
21489 +               case Opt_tag:
21490 +                       if (tag)
21491 +                               *tag = 0;
21492 +                       if (remove)
21493 +                               __dx_parse_remove(s, "tag");
21494 +                       *mnt_flags |= MNT_TAGID;
21495 +                       set |= MNT_TAGID;
21496 +                       break;
21497 +               case Opt_notag:
21498 +                       if (remove)
21499 +                               __dx_parse_remove(s, "notag");
21500 +                       *mnt_flags |= MNT_NOTAG;
21501 +                       set |= MNT_NOTAG;
21502 +                       break;
21503 +               case Opt_tagid:
21504 +                       if (tag && !match_int(args, &option))
21505 +                               *tag = option;
21506 +                       if (remove)
21507 +                               __dx_parse_remove(s, "tagid");
21508 +                       *mnt_flags |= MNT_TAGID;
21509 +                       set |= MNT_TAGID;
21510 +                       break;
21511 +#endif
21512 +               case Opt_notagcheck:
21513 +                       if (remove)
21514 +                               __dx_parse_remove(s, "notagcheck");
21515 +                       *flags |= MS_NOTAGCHECK;
21516 +                       set |= MS_NOTAGCHECK;
21517 +                       break;
21518 +               }
21519 +               vxdprintk(VXD_CBIT(tag, 7),
21520 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
21521 +                       p, token, option);
21522 +       }
21523 +       if (set)
21524 +               strcpy(string, s);
21525 +       kfree(s);
21526 +       return set;
21527 +}
21528 +
21529 +#ifdef CONFIG_PROPAGATE
21530 +
21531 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21532 +{
21533 +       tag_t new_tag = 0;
21534 +       struct vfsmount *mnt;
21535 +       int propagate;
21536 +
21537 +       if (!nd)
21538 +               return;
21539 +       mnt = nd->path.mnt;
21540 +       if (!mnt)
21541 +               return;
21542 +
21543 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21544 +       if (propagate)
21545 +               new_tag = mnt->mnt_tag;
21546 +
21547 +       vxdprintk(VXD_CBIT(tag, 7),
21548 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21549 +               inode, inode->i_ino, inode->i_tag,
21550 +               new_tag, (propagate) ? 1 : 0);
21551 +
21552 +       if (propagate)
21553 +               inode->i_tag = new_tag;
21554 +}
21555 +
21556 +#include <linux/module.h>
21557 +
21558 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21559 +
21560 +#endif /* CONFIG_PROPAGATE */
21561 +
21562 diff -NurpP --minimal linux-3.1/kernel/vserver/limit.c linux-3.1-vs2.3.1-rc2/kernel/vserver/limit.c
21563 --- linux-3.1/kernel/vserver/limit.c    1970-01-01 01:00:00.000000000 +0100
21564 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/limit.c        2011-10-24 18:53:33.000000000 +0200
21565 @@ -0,0 +1,360 @@
21566 +/*
21567 + *  linux/kernel/vserver/limit.c
21568 + *
21569 + *  Virtual Server: Context Limits
21570 + *
21571 + *  Copyright (C) 2004-2010  Herbert Pötzl
21572 + *
21573 + *  V0.01  broken out from vcontext V0.05
21574 + *  V0.02  changed vcmds to vxi arg
21575 + *  V0.03  added memory cgroup support
21576 + *
21577 + */
21578 +
21579 +#include <linux/sched.h>
21580 +#include <linux/module.h>
21581 +#include <linux/memcontrol.h>
21582 +#include <linux/res_counter.h>
21583 +#include <linux/vs_limit.h>
21584 +#include <linux/vserver/limit.h>
21585 +#include <linux/vserver/limit_cmd.h>
21586 +
21587 +#include <asm/uaccess.h>
21588 +
21589 +
21590 +const char *vlimit_name[NUM_LIMITS] = {
21591 +#ifdef CONFIG_VSERVER_LEGACY_MEM
21592 +       [RLIMIT_RSS]            = "RSS",
21593 +       [RLIMIT_AS]             = "VM",
21594 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
21595 +       [RLIMIT_CPU]            = "CPU",
21596 +       [RLIMIT_NPROC]          = "NPROC",
21597 +       [RLIMIT_NOFILE]         = "NOFILE",
21598 +       [RLIMIT_LOCKS]          = "LOCKS",
21599 +       [RLIMIT_SIGPENDING]     = "SIGP",
21600 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21601 +
21602 +       [VLIMIT_NSOCK]          = "NSOCK",
21603 +       [VLIMIT_OPENFD]         = "OPENFD",
21604 +       [VLIMIT_SHMEM]          = "SHMEM",
21605 +       [VLIMIT_DENTRY]         = "DENTRY",
21606 +};
21607 +
21608 +EXPORT_SYMBOL_GPL(vlimit_name);
21609 +
21610 +#define MASK_ENTRY(x)  (1 << (x))
21611 +
21612 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21613 +               /* minimum */
21614 +       0
21615 +       ,       /* softlimit */
21616 +#ifdef CONFIG_VSERVER_LEGACY_MEM
21617 +       MASK_ENTRY( RLIMIT_RSS          ) |
21618 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
21619 +       0
21620 +       ,       /* maximum */
21621 +#ifdef CONFIG_VSERVER_LEGACY_MEM
21622 +       MASK_ENTRY( RLIMIT_RSS          ) |
21623 +       MASK_ENTRY( RLIMIT_AS           ) |
21624 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
21625 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21626 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21627 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21628 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21629 +
21630 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21631 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21632 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21633 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21634 +       0
21635 +};
21636 +               /* accounting only */
21637 +uint32_t account_mask =
21638 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21639 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21640 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21641 +       0;
21642 +
21643 +
21644 +static int is_valid_vlimit(int id)
21645 +{
21646 +       uint32_t mask = vlimit_mask.minimum |
21647 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21648 +       return mask & (1 << id);
21649 +}
21650 +
21651 +static int is_accounted_vlimit(int id)
21652 +{
21653 +       if (is_valid_vlimit(id))
21654 +               return 1;
21655 +       return account_mask & (1 << id);
21656 +}
21657 +
21658 +
21659 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21660 +{
21661 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21662 +       return VX_VLIM(limit);
21663 +}
21664 +
21665 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21666 +{
21667 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21668 +       return VX_VLIM(limit);
21669 +}
21670 +
21671 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21672 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21673 +{
21674 +       if (!is_valid_vlimit(id))
21675 +               return -EINVAL;
21676 +
21677 +       if (minimum)
21678 +               *minimum = CRLIM_UNSET;
21679 +       if (softlimit)
21680 +               *softlimit = vc_get_soft(vxi, id);
21681 +       if (maximum)
21682 +               *maximum = vc_get_hard(vxi, id);
21683 +       return 0;
21684 +}
21685 +
21686 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21687 +{
21688 +       struct vcmd_ctx_rlimit_v0 vc_data;
21689 +       int ret;
21690 +
21691 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21692 +               return -EFAULT;
21693 +
21694 +       ret = do_get_rlimit(vxi, vc_data.id,
21695 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21696 +       if (ret)
21697 +               return ret;
21698 +
21699 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21700 +               return -EFAULT;
21701 +       return 0;
21702 +}
21703 +
21704 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21705 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21706 +{
21707 +       if (!is_valid_vlimit(id))
21708 +               return -EINVAL;
21709 +
21710 +       if (maximum != CRLIM_KEEP)
21711 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21712 +       if (softlimit != CRLIM_KEEP)
21713 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21714 +
21715 +       /* clamp soft limit */
21716 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21717 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21718 +
21719 +       return 0;
21720 +}
21721 +
21722 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21723 +{
21724 +       struct vcmd_ctx_rlimit_v0 vc_data;
21725 +
21726 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21727 +               return -EFAULT;
21728 +
21729 +       return do_set_rlimit(vxi, vc_data.id,
21730 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21731 +}
21732 +
21733 +#ifdef CONFIG_IA32_EMULATION
21734 +
21735 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21736 +{
21737 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21738 +
21739 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21740 +               return -EFAULT;
21741 +
21742 +       return do_set_rlimit(vxi, vc_data.id,
21743 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21744 +}
21745 +
21746 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21747 +{
21748 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21749 +       int ret;
21750 +
21751 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21752 +               return -EFAULT;
21753 +
21754 +       ret = do_get_rlimit(vxi, vc_data.id,
21755 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21756 +       if (ret)
21757 +               return ret;
21758 +
21759 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21760 +               return -EFAULT;
21761 +       return 0;
21762 +}
21763 +
21764 +#endif /* CONFIG_IA32_EMULATION */
21765 +
21766 +
21767 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21768 +{
21769 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21770 +               return -EFAULT;
21771 +       return 0;
21772 +}
21773 +
21774 +
21775 +static inline void vx_reset_hits(struct _vx_limit *limit)
21776 +{
21777 +       int lim;
21778 +
21779 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21780 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21781 +       }
21782 +}
21783 +
21784 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
21785 +{
21786 +       vx_reset_hits(&vxi->limit);
21787 +       return 0;
21788 +}
21789 +
21790 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21791 +{
21792 +       rlim_t value;
21793 +       int lim;
21794 +
21795 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21796 +               value = __rlim_get(limit, lim);
21797 +               __rlim_rmax(limit, lim) = value;
21798 +               __rlim_rmin(limit, lim) = value;
21799 +       }
21800 +}
21801 +
21802 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21803 +{
21804 +       vx_reset_minmax(&vxi->limit);
21805 +       return 0;
21806 +}
21807 +
21808 +
21809 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21810 +{
21811 +       struct vcmd_rlimit_stat_v0 vc_data;
21812 +       struct _vx_limit *limit = &vxi->limit;
21813 +       int id;
21814 +
21815 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21816 +               return -EFAULT;
21817 +
21818 +       id = vc_data.id;
21819 +       if (!is_accounted_vlimit(id))
21820 +               return -EINVAL;
21821 +
21822 +       vx_limit_fixup(limit, id);
21823 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21824 +       vc_data.value = __rlim_get(limit, id);
21825 +       vc_data.minimum = __rlim_rmin(limit, id);
21826 +       vc_data.maximum = __rlim_rmax(limit, id);
21827 +
21828 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21829 +               return -EFAULT;
21830 +       return 0;
21831 +}
21832 +
21833 +
21834 +void vx_vsi_meminfo(struct sysinfo *val)
21835 +{
21836 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
21837 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
21838 +       u64 res_limit, res_usage;
21839 +
21840 +       if (!mcg)
21841 +               return;
21842 +
21843 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
21844 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
21845 +
21846 +       if (res_limit != RESOURCE_MAX)
21847 +               val->totalram = (res_limit >> PAGE_SHIFT);
21848 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
21849 +       val->bufferram = 0;
21850 +       val->totalhigh = 0;
21851 +       val->freehigh = 0;
21852 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
21853 +       return;
21854 +}
21855 +
21856 +void vx_vsi_swapinfo(struct sysinfo *val)
21857 +{
21858 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
21859 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
21860 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
21861 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
21862 +       s64 swap_limit, swap_usage;
21863 +
21864 +       if (!mcg)
21865 +               return;
21866 +
21867 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
21868 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
21869 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
21870 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
21871 +
21872 +       /* memory unlimited */
21873 +       if (res_limit == RESOURCE_MAX)
21874 +               return;
21875 +
21876 +       swap_limit = memsw_limit - res_limit;
21877 +       /* we have a swap limit? */
21878 +       if (memsw_limit != RESOURCE_MAX)
21879 +               val->totalswap = swap_limit >> PAGE_SHIFT;
21880 +
21881 +       /* calculate swap part */
21882 +       swap_usage = (memsw_usage > res_usage) ?
21883 +               memsw_usage - res_usage : 0;
21884 +
21885 +       /* total shown minus usage gives free swap */
21886 +       val->freeswap = (swap_usage < swap_limit) ?
21887 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
21888 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
21889 +       val->totalswap = 0;
21890 +       val->freeswap = 0;
21891 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
21892 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
21893 +       return;
21894 +}
21895 +
21896 +long vx_vsi_cached(struct sysinfo *val)
21897 +{
21898 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
21899 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
21900 +
21901 +       return mem_cgroup_stat_read_cache(mcg);
21902 +#else
21903 +       return 0;
21904 +#endif
21905 +}
21906 +
21907 +
21908 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21909 +{
21910 +       struct vx_info *vxi = mm->mm_vx_info;
21911 +       unsigned long points;
21912 +       rlim_t v, w;
21913 +
21914 +       if (!vxi)
21915 +               return 0;
21916 +
21917 +       points = vxi->vx_badness_bias;
21918 +
21919 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21920 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21921 +       points += (v > w) ? (v - w) : 0;
21922 +
21923 +       return points;
21924 +}
21925 +
21926 diff -NurpP --minimal linux-3.1/kernel/vserver/limit_init.h linux-3.1-vs2.3.1-rc2/kernel/vserver/limit_init.h
21927 --- linux-3.1/kernel/vserver/limit_init.h       1970-01-01 01:00:00.000000000 +0100
21928 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/limit_init.h   2011-10-24 18:53:33.000000000 +0200
21929 @@ -0,0 +1,31 @@
21930 +
21931 +
21932 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21933 +{
21934 +       int lim;
21935 +
21936 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21937 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21938 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21939 +               __rlim_set(limit, lim, 0);
21940 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21941 +               __rlim_rmin(limit, lim) = 0;
21942 +               __rlim_rmax(limit, lim) = 0;
21943 +       }
21944 +}
21945 +
21946 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21947 +{
21948 +       rlim_t value;
21949 +       int lim;
21950 +
21951 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21952 +               if ((1 << lim) & VLIM_NOCHECK)
21953 +                       continue;
21954 +               value = __rlim_get(limit, lim);
21955 +               vxwprintk_xid(value,
21956 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21957 +                       limit, vlimit_name[lim], lim, (long)value);
21958 +       }
21959 +}
21960 +
21961 diff -NurpP --minimal linux-3.1/kernel/vserver/limit_proc.h linux-3.1-vs2.3.1-rc2/kernel/vserver/limit_proc.h
21962 --- linux-3.1/kernel/vserver/limit_proc.h       1970-01-01 01:00:00.000000000 +0100
21963 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/limit_proc.h   2011-10-24 18:53:33.000000000 +0200
21964 @@ -0,0 +1,57 @@
21965 +#ifndef _VX_LIMIT_PROC_H
21966 +#define _VX_LIMIT_PROC_H
21967 +
21968 +#include <linux/vserver/limit_int.h>
21969 +
21970 +
21971 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21972 +#define VX_LIMIT_TOP   \
21973 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21974 +
21975 +#define VX_LIMIT_ARG(r)                                \
21976 +       (unsigned long)__rlim_get(limit, r),    \
21977 +       (unsigned long)__rlim_rmin(limit, r),   \
21978 +       (unsigned long)__rlim_rmax(limit, r),   \
21979 +       VX_VLIM(__rlim_soft(limit, r)),         \
21980 +       VX_VLIM(__rlim_hard(limit, r)),         \
21981 +       atomic_read(&__rlim_lhit(limit, r))
21982 +
21983 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21984 +{
21985 +       vx_limit_fixup(limit, -1);
21986 +       return sprintf(buffer, VX_LIMIT_TOP
21987 +               "PROC"  VX_LIMIT_FMT
21988 +               "VM"    VX_LIMIT_FMT
21989 +               "VML"   VX_LIMIT_FMT
21990 +               "RSS"   VX_LIMIT_FMT
21991 +               "ANON"  VX_LIMIT_FMT
21992 +               "RMAP"  VX_LIMIT_FMT
21993 +               "FILES" VX_LIMIT_FMT
21994 +               "OFD"   VX_LIMIT_FMT
21995 +               "LOCKS" VX_LIMIT_FMT
21996 +               "SOCK"  VX_LIMIT_FMT
21997 +               "MSGQ"  VX_LIMIT_FMT
21998 +               "SHM"   VX_LIMIT_FMT
21999 +               "SEMA"  VX_LIMIT_FMT
22000 +               "SEMS"  VX_LIMIT_FMT
22001 +               "DENT"  VX_LIMIT_FMT,
22002 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22003 +               VX_LIMIT_ARG(RLIMIT_AS),
22004 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22005 +               VX_LIMIT_ARG(RLIMIT_RSS),
22006 +               VX_LIMIT_ARG(VLIMIT_ANON),
22007 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22008 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22009 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22010 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22011 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22012 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22013 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22014 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22015 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22016 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22017 +}
22018 +
22019 +#endif /* _VX_LIMIT_PROC_H */
22020 +
22021 +
22022 diff -NurpP --minimal linux-3.1/kernel/vserver/network.c linux-3.1-vs2.3.1-rc2/kernel/vserver/network.c
22023 --- linux-3.1/kernel/vserver/network.c  1970-01-01 01:00:00.000000000 +0100
22024 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/network.c      2011-10-24 18:53:33.000000000 +0200
22025 @@ -0,0 +1,912 @@
22026 +/*
22027 + *  linux/kernel/vserver/network.c
22028 + *
22029 + *  Virtual Server: Network Support
22030 + *
22031 + *  Copyright (C) 2003-2007  Herbert Pötzl
22032 + *
22033 + *  V0.01  broken out from vcontext V0.05
22034 + *  V0.02  cleaned up implementation
22035 + *  V0.03  added equiv nx commands
22036 + *  V0.04  switch to RCU based hash
22037 + *  V0.05  and back to locking again
22038 + *  V0.06  changed vcmds to nxi arg
22039 + *  V0.07  have __create claim() the nxi
22040 + *
22041 + */
22042 +
22043 +#include <linux/err.h>
22044 +#include <linux/slab.h>
22045 +#include <linux/rcupdate.h>
22046 +
22047 +#include <linux/vs_network.h>
22048 +#include <linux/vs_pid.h>
22049 +#include <linux/vserver/network_cmd.h>
22050 +
22051 +
22052 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22053 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22054 +
22055 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22056 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22057 +
22058 +
22059 +static int __init init_network(void)
22060 +{
22061 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22062 +               sizeof(struct nx_addr_v4), 0,
22063 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22064 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22065 +               sizeof(struct nx_addr_v6), 0,
22066 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22067 +       return 0;
22068 +}
22069 +
22070 +
22071 +/*     __alloc_nx_addr_v4()                                    */
22072 +
22073 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22074 +{
22075 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22076 +               nx_addr_v4_cachep, GFP_KERNEL);
22077 +
22078 +       if (!IS_ERR(nxa))
22079 +               memset(nxa, 0, sizeof(*nxa));
22080 +       return nxa;
22081 +}
22082 +
22083 +/*     __dealloc_nx_addr_v4()                                  */
22084 +
22085 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22086 +{
22087 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22088 +}
22089 +
22090 +/*     __dealloc_nx_addr_v4_all()                              */
22091 +
22092 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22093 +{
22094 +       while (nxa) {
22095 +               struct nx_addr_v4 *next = nxa->next;
22096 +
22097 +               __dealloc_nx_addr_v4(nxa);
22098 +               nxa = next;
22099 +       }
22100 +}
22101 +
22102 +
22103 +#ifdef CONFIG_IPV6
22104 +
22105 +/*     __alloc_nx_addr_v6()                                    */
22106 +
22107 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22108 +{
22109 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22110 +               nx_addr_v6_cachep, GFP_KERNEL);
22111 +
22112 +       if (!IS_ERR(nxa))
22113 +               memset(nxa, 0, sizeof(*nxa));
22114 +       return nxa;
22115 +}
22116 +
22117 +/*     __dealloc_nx_addr_v6()                                  */
22118 +
22119 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22120 +{
22121 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22122 +}
22123 +
22124 +/*     __dealloc_nx_addr_v6_all()                              */
22125 +
22126 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22127 +{
22128 +       while (nxa) {
22129 +               struct nx_addr_v6 *next = nxa->next;
22130 +
22131 +               __dealloc_nx_addr_v6(nxa);
22132 +               nxa = next;
22133 +       }
22134 +}
22135 +
22136 +#endif /* CONFIG_IPV6 */
22137 +
22138 +/*     __alloc_nx_info()
22139 +
22140 +       * allocate an initialized nx_info struct
22141 +       * doesn't make it visible (hash)                        */
22142 +
22143 +static struct nx_info *__alloc_nx_info(nid_t nid)
22144 +{
22145 +       struct nx_info *new = NULL;
22146 +
22147 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22148 +
22149 +       /* would this benefit from a slab cache? */
22150 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22151 +       if (!new)
22152 +               return 0;
22153 +
22154 +       memset(new, 0, sizeof(struct nx_info));
22155 +       new->nx_id = nid;
22156 +       INIT_HLIST_NODE(&new->nx_hlist);
22157 +       atomic_set(&new->nx_usecnt, 0);
22158 +       atomic_set(&new->nx_tasks, 0);
22159 +       new->nx_state = 0;
22160 +
22161 +       new->nx_flags = NXF_INIT_SET;
22162 +
22163 +       /* rest of init goes here */
22164 +
22165 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22166 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22167 +
22168 +       vxdprintk(VXD_CBIT(nid, 0),
22169 +               "alloc_nx_info(%d) = %p", nid, new);
22170 +       atomic_inc(&nx_global_ctotal);
22171 +       return new;
22172 +}
22173 +
22174 +/*     __dealloc_nx_info()
22175 +
22176 +       * final disposal of nx_info                             */
22177 +
22178 +static void __dealloc_nx_info(struct nx_info *nxi)
22179 +{
22180 +       vxdprintk(VXD_CBIT(nid, 0),
22181 +               "dealloc_nx_info(%p)", nxi);
22182 +
22183 +       nxi->nx_hlist.next = LIST_POISON1;
22184 +       nxi->nx_id = -1;
22185 +
22186 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22187 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22188 +
22189 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22190 +
22191 +       nxi->nx_state |= NXS_RELEASED;
22192 +       kfree(nxi);
22193 +       atomic_dec(&nx_global_ctotal);
22194 +}
22195 +
22196 +static void __shutdown_nx_info(struct nx_info *nxi)
22197 +{
22198 +       nxi->nx_state |= NXS_SHUTDOWN;
22199 +       vs_net_change(nxi, VSC_NETDOWN);
22200 +}
22201 +
22202 +/*     exported stuff                                          */
22203 +
22204 +void free_nx_info(struct nx_info *nxi)
22205 +{
22206 +       /* context shutdown is mandatory */
22207 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22208 +
22209 +       /* context must not be hashed */
22210 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22211 +
22212 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22213 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22214 +
22215 +       __dealloc_nx_info(nxi);
22216 +}
22217 +
22218 +
22219 +void __nx_set_lback(struct nx_info *nxi)
22220 +{
22221 +       int nid = nxi->nx_id;
22222 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22223 +
22224 +       nxi->v4_lback.s_addr = lback;
22225 +}
22226 +
22227 +extern int __nx_inet_add_lback(__be32 addr);
22228 +extern int __nx_inet_del_lback(__be32 addr);
22229 +
22230 +
22231 +/*     hash table for nx_info hash */
22232 +
22233 +#define NX_HASH_SIZE   13
22234 +
22235 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22236 +
22237 +static DEFINE_SPINLOCK(nx_info_hash_lock);
22238 +
22239 +
22240 +static inline unsigned int __hashval(nid_t nid)
22241 +{
22242 +       return (nid % NX_HASH_SIZE);
22243 +}
22244 +
22245 +
22246 +
22247 +/*     __hash_nx_info()
22248 +
22249 +       * add the nxi to the global hash table
22250 +       * requires the hash_lock to be held                     */
22251 +
22252 +static inline void __hash_nx_info(struct nx_info *nxi)
22253 +{
22254 +       struct hlist_head *head;
22255 +
22256 +       vxd_assert_lock(&nx_info_hash_lock);
22257 +       vxdprintk(VXD_CBIT(nid, 4),
22258 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22259 +
22260 +       /* context must not be hashed */
22261 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22262 +
22263 +       nxi->nx_state |= NXS_HASHED;
22264 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22265 +       hlist_add_head(&nxi->nx_hlist, head);
22266 +       atomic_inc(&nx_global_cactive);
22267 +}
22268 +
22269 +/*     __unhash_nx_info()
22270 +
22271 +       * remove the nxi from the global hash table
22272 +       * requires the hash_lock to be held                     */
22273 +
22274 +static inline void __unhash_nx_info(struct nx_info *nxi)
22275 +{
22276 +       vxd_assert_lock(&nx_info_hash_lock);
22277 +       vxdprintk(VXD_CBIT(nid, 4),
22278 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22279 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22280 +
22281 +       /* context must be hashed */
22282 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22283 +       /* but without tasks */
22284 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22285 +
22286 +       nxi->nx_state &= ~NXS_HASHED;
22287 +       hlist_del(&nxi->nx_hlist);
22288 +       atomic_dec(&nx_global_cactive);
22289 +}
22290 +
22291 +
22292 +/*     __lookup_nx_info()
22293 +
22294 +       * requires the hash_lock to be held
22295 +       * doesn't increment the nx_refcnt                       */
22296 +
22297 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22298 +{
22299 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22300 +       struct hlist_node *pos;
22301 +       struct nx_info *nxi;
22302 +
22303 +       vxd_assert_lock(&nx_info_hash_lock);
22304 +       hlist_for_each(pos, head) {
22305 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22306 +
22307 +               if (nxi->nx_id == nid)
22308 +                       goto found;
22309 +       }
22310 +       nxi = NULL;
22311 +found:
22312 +       vxdprintk(VXD_CBIT(nid, 0),
22313 +               "__lookup_nx_info(#%u): %p[#%u]",
22314 +               nid, nxi, nxi ? nxi->nx_id : 0);
22315 +       return nxi;
22316 +}
22317 +
22318 +
22319 +/*     __create_nx_info()
22320 +
22321 +       * create the requested context
22322 +       * get(), claim() and hash it                            */
22323 +
22324 +static struct nx_info *__create_nx_info(int id)
22325 +{
22326 +       struct nx_info *new, *nxi = NULL;
22327 +
22328 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22329 +
22330 +       if (!(new = __alloc_nx_info(id)))
22331 +               return ERR_PTR(-ENOMEM);
22332 +
22333 +       /* required to make dynamic xids unique */
22334 +       spin_lock(&nx_info_hash_lock);
22335 +
22336 +       /* static context requested */
22337 +       if ((nxi = __lookup_nx_info(id))) {
22338 +               vxdprintk(VXD_CBIT(nid, 0),
22339 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22340 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22341 +                       nxi = ERR_PTR(-EBUSY);
22342 +               else
22343 +                       nxi = ERR_PTR(-EEXIST);
22344 +               goto out_unlock;
22345 +       }
22346 +       /* new context */
22347 +       vxdprintk(VXD_CBIT(nid, 0),
22348 +               "create_nx_info(%d) = %p (new)", id, new);
22349 +       claim_nx_info(new, NULL);
22350 +       __nx_set_lback(new);
22351 +       __hash_nx_info(get_nx_info(new));
22352 +       nxi = new, new = NULL;
22353 +
22354 +out_unlock:
22355 +       spin_unlock(&nx_info_hash_lock);
22356 +       if (new)
22357 +               __dealloc_nx_info(new);
22358 +       return nxi;
22359 +}
22360 +
22361 +
22362 +
22363 +/*     exported stuff                                          */
22364 +
22365 +
22366 +void unhash_nx_info(struct nx_info *nxi)
22367 +{
22368 +       __shutdown_nx_info(nxi);
22369 +       spin_lock(&nx_info_hash_lock);
22370 +       __unhash_nx_info(nxi);
22371 +       spin_unlock(&nx_info_hash_lock);
22372 +}
22373 +
22374 +/*     lookup_nx_info()
22375 +
22376 +       * search for a nx_info and get() it
22377 +       * negative id means current                             */
22378 +
22379 +struct nx_info *lookup_nx_info(int id)
22380 +{
22381 +       struct nx_info *nxi = NULL;
22382 +
22383 +       if (id < 0) {
22384 +               nxi = get_nx_info(current_nx_info());
22385 +       } else if (id > 1) {
22386 +               spin_lock(&nx_info_hash_lock);
22387 +               nxi = get_nx_info(__lookup_nx_info(id));
22388 +               spin_unlock(&nx_info_hash_lock);
22389 +       }
22390 +       return nxi;
22391 +}
22392 +
22393 +/*     nid_is_hashed()
22394 +
22395 +       * verify that nid is still hashed                       */
22396 +
22397 +int nid_is_hashed(nid_t nid)
22398 +{
22399 +       int hashed;
22400 +
22401 +       spin_lock(&nx_info_hash_lock);
22402 +       hashed = (__lookup_nx_info(nid) != NULL);
22403 +       spin_unlock(&nx_info_hash_lock);
22404 +       return hashed;
22405 +}
22406 +
22407 +
22408 +#ifdef CONFIG_PROC_FS
22409 +
22410 +/*     get_nid_list()
22411 +
22412 +       * get a subset of hashed nids for proc
22413 +       * assumes size is at least one                          */
22414 +
22415 +int get_nid_list(int index, unsigned int *nids, int size)
22416 +{
22417 +       int hindex, nr_nids = 0;
22418 +
22419 +       /* only show current and children */
22420 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22421 +               if (index > 0)
22422 +                       return 0;
22423 +               nids[nr_nids] = nx_current_nid();
22424 +               return 1;
22425 +       }
22426 +
22427 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22428 +               struct hlist_head *head = &nx_info_hash[hindex];
22429 +               struct hlist_node *pos;
22430 +
22431 +               spin_lock(&nx_info_hash_lock);
22432 +               hlist_for_each(pos, head) {
22433 +                       struct nx_info *nxi;
22434 +
22435 +                       if (--index > 0)
22436 +                               continue;
22437 +
22438 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22439 +                       nids[nr_nids] = nxi->nx_id;
22440 +                       if (++nr_nids >= size) {
22441 +                               spin_unlock(&nx_info_hash_lock);
22442 +                               goto out;
22443 +                       }
22444 +               }
22445 +               /* keep the lock time short */
22446 +               spin_unlock(&nx_info_hash_lock);
22447 +       }
22448 +out:
22449 +       return nr_nids;
22450 +}
22451 +#endif
22452 +
22453 +
22454 +/*
22455 + *     migrate task to new network
22456 + *     gets nxi, puts old_nxi on change
22457 + */
22458 +
22459 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22460 +{
22461 +       struct nx_info *old_nxi;
22462 +       int ret = 0;
22463 +
22464 +       if (!p || !nxi)
22465 +               BUG();
22466 +
22467 +       vxdprintk(VXD_CBIT(nid, 5),
22468 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22469 +               p, nxi, nxi->nx_id,
22470 +               atomic_read(&nxi->nx_usecnt),
22471 +               atomic_read(&nxi->nx_tasks));
22472 +
22473 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22474 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22475 +               return -EACCES;
22476 +
22477 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22478 +               return -EFAULT;
22479 +
22480 +       /* maybe disallow this completely? */
22481 +       old_nxi = task_get_nx_info(p);
22482 +       if (old_nxi == nxi)
22483 +               goto out;
22484 +
22485 +       task_lock(p);
22486 +       if (old_nxi)
22487 +               clr_nx_info(&p->nx_info);
22488 +       claim_nx_info(nxi, p);
22489 +       set_nx_info(&p->nx_info, nxi);
22490 +       p->nid = nxi->nx_id;
22491 +       task_unlock(p);
22492 +
22493 +       vxdprintk(VXD_CBIT(nid, 5),
22494 +               "moved task %p into nxi:%p[#%d]",
22495 +               p, nxi, nxi->nx_id);
22496 +
22497 +       if (old_nxi)
22498 +               release_nx_info(old_nxi, p);
22499 +       ret = 0;
22500 +out:
22501 +       put_nx_info(old_nxi);
22502 +       return ret;
22503 +}
22504 +
22505 +
22506 +void nx_set_persistent(struct nx_info *nxi)
22507 +{
22508 +       vxdprintk(VXD_CBIT(nid, 6),
22509 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22510 +
22511 +       get_nx_info(nxi);
22512 +       claim_nx_info(nxi, NULL);
22513 +}
22514 +
22515 +void nx_clear_persistent(struct nx_info *nxi)
22516 +{
22517 +       vxdprintk(VXD_CBIT(nid, 6),
22518 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22519 +
22520 +       release_nx_info(nxi, NULL);
22521 +       put_nx_info(nxi);
22522 +}
22523 +
22524 +void nx_update_persistent(struct nx_info *nxi)
22525 +{
22526 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22527 +               nx_set_persistent(nxi);
22528 +       else
22529 +               nx_clear_persistent(nxi);
22530 +}
22531 +
22532 +/* vserver syscall commands below here */
22533 +
22534 +/* taks nid and nx_info functions */
22535 +
22536 +#include <asm/uaccess.h>
22537 +
22538 +
22539 +int vc_task_nid(uint32_t id)
22540 +{
22541 +       nid_t nid;
22542 +
22543 +       if (id) {
22544 +               struct task_struct *tsk;
22545 +
22546 +               rcu_read_lock();
22547 +               tsk = find_task_by_real_pid(id);
22548 +               nid = (tsk) ? tsk->nid : -ESRCH;
22549 +               rcu_read_unlock();
22550 +       } else
22551 +               nid = nx_current_nid();
22552 +       return nid;
22553 +}
22554 +
22555 +
22556 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22557 +{
22558 +       struct vcmd_nx_info_v0 vc_data;
22559 +
22560 +       vc_data.nid = nxi->nx_id;
22561 +
22562 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22563 +               return -EFAULT;
22564 +       return 0;
22565 +}
22566 +
22567 +
22568 +/* network functions */
22569 +
22570 +int vc_net_create(uint32_t nid, void __user *data)
22571 +{
22572 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22573 +       struct nx_info *new_nxi;
22574 +       int ret;
22575 +
22576 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22577 +               return -EFAULT;
22578 +
22579 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22580 +               return -EINVAL;
22581 +
22582 +       new_nxi = __create_nx_info(nid);
22583 +       if (IS_ERR(new_nxi))
22584 +               return PTR_ERR(new_nxi);
22585 +
22586 +       /* initial flags */
22587 +       new_nxi->nx_flags = vc_data.flagword;
22588 +
22589 +       ret = -ENOEXEC;
22590 +       if (vs_net_change(new_nxi, VSC_NETUP))
22591 +               goto out;
22592 +
22593 +       ret = nx_migrate_task(current, new_nxi);
22594 +       if (ret)
22595 +               goto out;
22596 +
22597 +       /* return context id on success */
22598 +       ret = new_nxi->nx_id;
22599 +
22600 +       /* get a reference for persistent contexts */
22601 +       if ((vc_data.flagword & NXF_PERSISTENT))
22602 +               nx_set_persistent(new_nxi);
22603 +out:
22604 +       release_nx_info(new_nxi, NULL);
22605 +       put_nx_info(new_nxi);
22606 +       return ret;
22607 +}
22608 +
22609 +
22610 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22611 +{
22612 +       return nx_migrate_task(current, nxi);
22613 +}
22614 +
22615 +
22616 +
22617 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22618 +       uint16_t type, uint16_t flags)
22619 +{
22620 +       struct nx_addr_v4 *nxa = &nxi->v4;
22621 +
22622 +       if (NX_IPV4(nxi)) {
22623 +               /* locate last entry */
22624 +               for (; nxa->next; nxa = nxa->next);
22625 +               nxa->next = __alloc_nx_addr_v4();
22626 +               nxa = nxa->next;
22627 +
22628 +               if (IS_ERR(nxa))
22629 +                       return PTR_ERR(nxa);
22630 +       }
22631 +
22632 +       if (nxi->v4.next)
22633 +               /* remove single ip for ip list */
22634 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22635 +
22636 +       nxa->ip[0].s_addr = ip;
22637 +       nxa->ip[1].s_addr = ip2;
22638 +       nxa->mask.s_addr = mask;
22639 +       nxa->type = type;
22640 +       nxa->flags = flags;
22641 +       return 0;
22642 +}
22643 +
22644 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22645 +       uint16_t type, uint16_t flags)
22646 +{
22647 +       struct nx_addr_v4 *nxa = &nxi->v4;
22648 +
22649 +       switch (type) {
22650 +/*     case NXA_TYPE_ADDR:
22651 +               break;          */
22652 +
22653 +       case NXA_TYPE_ANY:
22654 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
22655 +               memset(nxa, 0, sizeof(*nxa));
22656 +               break;
22657 +
22658 +       default:
22659 +               return -EINVAL;
22660 +       }
22661 +       return 0;
22662 +}
22663 +
22664 +
22665 +int vc_net_add(struct nx_info *nxi, void __user *data)
22666 +{
22667 +       struct vcmd_net_addr_v0 vc_data;
22668 +       int index, ret = 0;
22669 +
22670 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22671 +               return -EFAULT;
22672 +
22673 +       switch (vc_data.type) {
22674 +       case NXA_TYPE_IPV4:
22675 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22676 +                       return -EINVAL;
22677 +
22678 +               index = 0;
22679 +               while (index < vc_data.count) {
22680 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22681 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22682 +                       if (ret)
22683 +                               return ret;
22684 +                       index++;
22685 +               }
22686 +               ret = index;
22687 +               break;
22688 +
22689 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22690 +               nxi->v4_bcast = vc_data.ip[0];
22691 +               ret = 1;
22692 +               break;
22693 +
22694 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22695 +               nxi->v4_lback = vc_data.ip[0];
22696 +               ret = 1;
22697 +               break;
22698 +
22699 +       default:
22700 +               ret = -EINVAL;
22701 +               break;
22702 +       }
22703 +       return ret;
22704 +}
22705 +
22706 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22707 +{
22708 +       struct vcmd_net_addr_v0 vc_data;
22709 +
22710 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22711 +               return -EFAULT;
22712 +
22713 +       switch (vc_data.type) {
22714 +       case NXA_TYPE_ANY:
22715 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22716 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22717 +               break;
22718 +
22719 +       default:
22720 +               return -EINVAL;
22721 +       }
22722 +       return 0;
22723 +}
22724 +
22725 +
22726 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
22727 +{
22728 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22729 +
22730 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22731 +               return -EFAULT;
22732 +
22733 +       switch (vc_data.type) {
22734 +       case NXA_TYPE_ADDR:
22735 +       case NXA_TYPE_MASK:
22736 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22737 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22738 +
22739 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22740 +               nxi->v4_bcast = vc_data.ip;
22741 +               break;
22742 +
22743 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22744 +               nxi->v4_lback = vc_data.ip;
22745 +               break;
22746 +
22747 +       default:
22748 +               return -EINVAL;
22749 +       }
22750 +       return 0;
22751 +}
22752 +
22753 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22754 +{
22755 +       struct vcmd_net_addr_ipv4_v2 vc_data;
22756 +
22757 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22758 +               return -EFAULT;
22759 +
22760 +       switch (vc_data.type) {
22761 +       case NXA_TYPE_ADDR:
22762 +       case NXA_TYPE_MASK:
22763 +       case NXA_TYPE_RANGE:
22764 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
22765 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22766 +
22767 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22768 +               nxi->v4_bcast = vc_data.ip;
22769 +               break;
22770 +
22771 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22772 +               nxi->v4_lback = vc_data.ip;
22773 +               break;
22774 +
22775 +       default:
22776 +               return -EINVAL;
22777 +       }
22778 +       return 0;
22779 +}
22780 +
22781 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
22782 +{
22783 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22784 +
22785 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22786 +               return -EFAULT;
22787 +
22788 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
22789 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22790 +}
22791 +
22792 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
22793 +{
22794 +       struct vcmd_net_addr_ipv4_v2 vc_data;
22795 +
22796 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22797 +               return -EFAULT;
22798 +
22799 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
22800 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22801 +}
22802 +
22803 +#ifdef CONFIG_IPV6
22804 +
22805 +int do_add_v6_addr(struct nx_info *nxi,
22806 +       struct in6_addr *ip, struct in6_addr *mask,
22807 +       uint32_t prefix, uint16_t type, uint16_t flags)
22808 +{
22809 +       struct nx_addr_v6 *nxa = &nxi->v6;
22810 +
22811 +       if (NX_IPV6(nxi)) {
22812 +               /* locate last entry */
22813 +               for (; nxa->next; nxa = nxa->next);
22814 +               nxa->next = __alloc_nx_addr_v6();
22815 +               nxa = nxa->next;
22816 +
22817 +               if (IS_ERR(nxa))
22818 +                       return PTR_ERR(nxa);
22819 +       }
22820 +
22821 +       nxa->ip = *ip;
22822 +       nxa->mask = *mask;
22823 +       nxa->prefix = prefix;
22824 +       nxa->type = type;
22825 +       nxa->flags = flags;
22826 +       return 0;
22827 +}
22828 +
22829 +
22830 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22831 +{
22832 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22833 +
22834 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22835 +               return -EFAULT;
22836 +
22837 +       switch (vc_data.type) {
22838 +       case NXA_TYPE_ADDR:
22839 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
22840 +               /* fallthrough */
22841 +       case NXA_TYPE_MASK:
22842 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22843 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22844 +       default:
22845 +               return -EINVAL;
22846 +       }
22847 +       return 0;
22848 +}
22849 +
22850 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
22851 +{
22852 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22853 +
22854 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22855 +               return -EFAULT;
22856 +
22857 +       switch (vc_data.type) {
22858 +       case NXA_TYPE_ANY:
22859 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
22860 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
22861 +               break;
22862 +
22863 +       default:
22864 +               return -EINVAL;
22865 +       }
22866 +       return 0;
22867 +}
22868 +
22869 +#endif /* CONFIG_IPV6 */
22870 +
22871 +
22872 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22873 +{
22874 +       struct vcmd_net_flags_v0 vc_data;
22875 +
22876 +       vc_data.flagword = nxi->nx_flags;
22877 +
22878 +       /* special STATE flag handling */
22879 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22880 +
22881 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22882 +               return -EFAULT;
22883 +       return 0;
22884 +}
22885 +
22886 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22887 +{
22888 +       struct vcmd_net_flags_v0 vc_data;
22889 +       uint64_t mask, trigger;
22890 +
22891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22892 +               return -EFAULT;
22893 +
22894 +       /* special STATE flag handling */
22895 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22896 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22897 +
22898 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22899 +               vc_data.flagword, mask);
22900 +       if (trigger & NXF_PERSISTENT)
22901 +               nx_update_persistent(nxi);
22902 +
22903 +       return 0;
22904 +}
22905 +
22906 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22907 +{
22908 +       struct vcmd_net_caps_v0 vc_data;
22909 +
22910 +       vc_data.ncaps = nxi->nx_ncaps;
22911 +       vc_data.cmask = ~0ULL;
22912 +
22913 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22914 +               return -EFAULT;
22915 +       return 0;
22916 +}
22917 +
22918 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22919 +{
22920 +       struct vcmd_net_caps_v0 vc_data;
22921 +
22922 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22923 +               return -EFAULT;
22924 +
22925 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22926 +               vc_data.ncaps, vc_data.cmask);
22927 +       return 0;
22928 +}
22929 +
22930 +
22931 +#include <linux/module.h>
22932 +
22933 +module_init(init_network);
22934 +
22935 +EXPORT_SYMBOL_GPL(free_nx_info);
22936 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22937 +
22938 diff -NurpP --minimal linux-3.1/kernel/vserver/proc.c linux-3.1-vs2.3.1-rc2/kernel/vserver/proc.c
22939 --- linux-3.1/kernel/vserver/proc.c     1970-01-01 01:00:00.000000000 +0100
22940 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/proc.c 2011-10-24 18:53:33.000000000 +0200
22941 @@ -0,0 +1,1103 @@
22942 +/*
22943 + *  linux/kernel/vserver/proc.c
22944 + *
22945 + *  Virtual Context Support
22946 + *
22947 + *  Copyright (C) 2003-2011  Herbert Pötzl
22948 + *
22949 + *  V0.01  basic structure
22950 + *  V0.02  adaptation vs1.3.0
22951 + *  V0.03  proc permissions
22952 + *  V0.04  locking/generic
22953 + *  V0.05  next generation procfs
22954 + *  V0.06  inode validation
22955 + *  V0.07  generic rewrite vid
22956 + *  V0.08  remove inode type
22957 + *  V0.09  added u/wmask info
22958 + *
22959 + */
22960 +
22961 +#include <linux/proc_fs.h>
22962 +#include <linux/fs_struct.h>
22963 +#include <linux/mount.h>
22964 +#include <asm/unistd.h>
22965 +
22966 +#include <linux/vs_context.h>
22967 +#include <linux/vs_network.h>
22968 +#include <linux/vs_cvirt.h>
22969 +
22970 +#include <linux/in.h>
22971 +#include <linux/inetdevice.h>
22972 +#include <linux/vs_inet.h>
22973 +#include <linux/vs_inet6.h>
22974 +
22975 +#include <linux/vserver/global.h>
22976 +
22977 +#include "cvirt_proc.h"
22978 +#include "cacct_proc.h"
22979 +#include "limit_proc.h"
22980 +#include "sched_proc.h"
22981 +#include "vci_config.h"
22982 +
22983 +
22984 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22985 +{
22986 +       unsigned __capi;
22987 +
22988 +       CAP_FOR_EACH_U32(__capi) {
22989 +               buffer += sprintf(buffer, "%08x",
22990 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22991 +       }
22992 +       return buffer;
22993 +}
22994 +
22995 +
22996 +static struct proc_dir_entry *proc_virtual;
22997 +
22998 +static struct proc_dir_entry *proc_virtnet;
22999 +
23000 +
23001 +/* first the actual feeds */
23002 +
23003 +
23004 +static int proc_vci(char *buffer)
23005 +{
23006 +       return sprintf(buffer,
23007 +               "VCIVersion:\t%04x:%04x\n"
23008 +               "VCISyscall:\t%d\n"
23009 +               "VCIKernel:\t%08x\n",
23010 +               VCI_VERSION >> 16,
23011 +               VCI_VERSION & 0xFFFF,
23012 +               __NR_vserver,
23013 +               vci_kernel_config());
23014 +}
23015 +
23016 +static int proc_virtual_info(char *buffer)
23017 +{
23018 +       return proc_vci(buffer);
23019 +}
23020 +
23021 +static int proc_virtual_status(char *buffer)
23022 +{
23023 +       return sprintf(buffer,
23024 +               "#CTotal:\t%d\n"
23025 +               "#CActive:\t%d\n"
23026 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
23027 +               "#InitTask:\t%d\t%d %d\n",
23028 +               atomic_read(&vx_global_ctotal),
23029 +               atomic_read(&vx_global_cactive),
23030 +               atomic_read(&vs_global_nsproxy),
23031 +               atomic_read(&vs_global_fs),
23032 +               atomic_read(&vs_global_mnt_ns),
23033 +               atomic_read(&vs_global_uts_ns),
23034 +               atomic_read(&nr_ipc_ns),
23035 +               atomic_read(&vs_global_user_ns),
23036 +               atomic_read(&vs_global_pid_ns),
23037 +               atomic_read(&init_task.usage),
23038 +               atomic_read(&init_task.nsproxy->count),
23039 +               init_task.fs->users);
23040 +}
23041 +
23042 +
23043 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23044 +{
23045 +       int length;
23046 +
23047 +       length = sprintf(buffer,
23048 +               "ID:\t%d\n"
23049 +               "Info:\t%p\n"
23050 +               "Init:\t%d\n"
23051 +               "OOM:\t%lld\n",
23052 +               vxi->vx_id,
23053 +               vxi,
23054 +               vxi->vx_initpid,
23055 +               vxi->vx_badness_bias);
23056 +       return length;
23057 +}
23058 +
23059 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23060 +{
23061 +       char *orig = buffer;
23062 +
23063 +       buffer += sprintf(buffer,
23064 +               "UseCnt:\t%d\n"
23065 +               "Tasks:\t%d\n"
23066 +               "Flags:\t%016llx\n",
23067 +               atomic_read(&vxi->vx_usecnt),
23068 +               atomic_read(&vxi->vx_tasks),
23069 +               (unsigned long long)vxi->vx_flags);
23070 +
23071 +       buffer += sprintf(buffer, "BCaps:\t");
23072 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23073 +       buffer += sprintf(buffer, "\n");
23074 +
23075 +       buffer += sprintf(buffer,
23076 +               "CCaps:\t%016llx\n"
23077 +               "Umask:\t%16llx\n"
23078 +               "Wmask:\t%16llx\n"
23079 +               "Spaces:\t%08lx %08lx\n",
23080 +               (unsigned long long)vxi->vx_ccaps,
23081 +               (unsigned long long)vxi->vx_umask,
23082 +               (unsigned long long)vxi->vx_wmask,
23083 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
23084 +       return buffer - orig;
23085 +}
23086 +
23087 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23088 +{
23089 +       return vx_info_proc_limit(&vxi->limit, buffer);
23090 +}
23091 +
23092 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23093 +{
23094 +       int cpu, length;
23095 +
23096 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23097 +       for_each_online_cpu(cpu) {
23098 +               length += vx_info_proc_sched_pc(
23099 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23100 +                       buffer + length, cpu);
23101 +       }
23102 +       return length;
23103 +}
23104 +
23105 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23106 +{
23107 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
23108 +}
23109 +
23110 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23111 +{
23112 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
23113 +}
23114 +
23115 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23116 +{
23117 +       int cpu, length;
23118 +
23119 +       vx_update_load(vxi);
23120 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23121 +       for_each_online_cpu(cpu) {
23122 +               length += vx_info_proc_cvirt_pc(
23123 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23124 +                       buffer + length, cpu);
23125 +       }
23126 +       return length;
23127 +}
23128 +
23129 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23130 +{
23131 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23132 +}
23133 +
23134 +
23135 +static int proc_virtnet_info(char *buffer)
23136 +{
23137 +       return proc_vci(buffer);
23138 +}
23139 +
23140 +static int proc_virtnet_status(char *buffer)
23141 +{
23142 +       return sprintf(buffer,
23143 +               "#CTotal:\t%d\n"
23144 +               "#CActive:\t%d\n",
23145 +               atomic_read(&nx_global_ctotal),
23146 +               atomic_read(&nx_global_cactive));
23147 +}
23148 +
23149 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23150 +{
23151 +       struct nx_addr_v4 *v4a;
23152 +#ifdef CONFIG_IPV6
23153 +       struct nx_addr_v6 *v6a;
23154 +#endif
23155 +       int length, i;
23156 +
23157 +       length = sprintf(buffer,
23158 +               "ID:\t%d\n"
23159 +               "Info:\t%p\n"
23160 +               "Bcast:\t" NIPQUAD_FMT "\n"
23161 +               "Lback:\t" NIPQUAD_FMT "\n",
23162 +               nxi->nx_id,
23163 +               nxi,
23164 +               NIPQUAD(nxi->v4_bcast.s_addr),
23165 +               NIPQUAD(nxi->v4_lback.s_addr));
23166 +
23167 +       if (!NX_IPV4(nxi))
23168 +               goto skip_v4;
23169 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23170 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23171 +                       i, NXAV4(v4a));
23172 +skip_v4:
23173 +#ifdef CONFIG_IPV6
23174 +       if (!NX_IPV6(nxi))
23175 +               goto skip_v6;
23176 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23177 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23178 +                       i, NXAV6(v6a));
23179 +skip_v6:
23180 +#endif
23181 +       return length;
23182 +}
23183 +
23184 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23185 +{
23186 +       int length;
23187 +
23188 +       length = sprintf(buffer,
23189 +               "UseCnt:\t%d\n"
23190 +               "Tasks:\t%d\n"
23191 +               "Flags:\t%016llx\n"
23192 +               "NCaps:\t%016llx\n",
23193 +               atomic_read(&nxi->nx_usecnt),
23194 +               atomic_read(&nxi->nx_tasks),
23195 +               (unsigned long long)nxi->nx_flags,
23196 +               (unsigned long long)nxi->nx_ncaps);
23197 +       return length;
23198 +}
23199 +
23200 +
23201 +
23202 +/* here the inode helpers */
23203 +
23204 +struct vs_entry {
23205 +       int len;
23206 +       char *name;
23207 +       mode_t mode;
23208 +       struct inode_operations *iop;
23209 +       struct file_operations *fop;
23210 +       union proc_op op;
23211 +};
23212 +
23213 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23214 +{
23215 +       struct inode *inode = new_inode(sb);
23216 +
23217 +       if (!inode)
23218 +               goto out;
23219 +
23220 +       inode->i_mode = p->mode;
23221 +       if (p->iop)
23222 +               inode->i_op = p->iop;
23223 +       if (p->fop)
23224 +               inode->i_fop = p->fop;
23225 +
23226 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23227 +       inode->i_flags |= S_IMMUTABLE;
23228 +
23229 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23230 +
23231 +       inode->i_uid = 0;
23232 +       inode->i_gid = 0;
23233 +       inode->i_tag = 0;
23234 +out:
23235 +       return inode;
23236 +}
23237 +
23238 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23239 +       struct dentry *dentry, int id, void *ptr)
23240 +{
23241 +       struct vs_entry *p = ptr;
23242 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23243 +       struct dentry *error = ERR_PTR(-EINVAL);
23244 +
23245 +       if (!inode)
23246 +               goto out;
23247 +
23248 +       PROC_I(inode)->op = p->op;
23249 +       PROC_I(inode)->fd = id;
23250 +       d_add(dentry, inode);
23251 +       error = NULL;
23252 +out:
23253 +       return error;
23254 +}
23255 +
23256 +/* Lookups */
23257 +
23258 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23259 +
23260 +/*
23261 + * Fill a directory entry.
23262 + *
23263 + * If possible create the dcache entry and derive our inode number and
23264 + * file type from dcache entry.
23265 + *
23266 + * Since all of the proc inode numbers are dynamically generated, the inode
23267 + * numbers do not exist until the inode is cache.  This means creating the
23268 + * the dcache entry in readdir is necessary to keep the inode numbers
23269 + * reported by readdir in sync with the inode numbers reported
23270 + * by stat.
23271 + */
23272 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23273 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23274 +{
23275 +       struct dentry *child, *dir = filp->f_dentry;
23276 +       struct inode *inode;
23277 +       struct qstr qname;
23278 +       ino_t ino = 0;
23279 +       unsigned type = DT_UNKNOWN;
23280 +
23281 +       qname.name = name;
23282 +       qname.len  = len;
23283 +       qname.hash = full_name_hash(name, len);
23284 +
23285 +       child = d_lookup(dir, &qname);
23286 +       if (!child) {
23287 +               struct dentry *new;
23288 +               new = d_alloc(dir, &qname);
23289 +               if (new) {
23290 +                       child = instantiate(dir->d_inode, new, id, ptr);
23291 +                       if (child)
23292 +                               dput(new);
23293 +                       else
23294 +                               child = new;
23295 +               }
23296 +       }
23297 +       if (!child || IS_ERR(child) || !child->d_inode)
23298 +               goto end_instantiate;
23299 +       inode = child->d_inode;
23300 +       if (inode) {
23301 +               ino = inode->i_ino;
23302 +               type = inode->i_mode >> 12;
23303 +       }
23304 +       dput(child);
23305 +end_instantiate:
23306 +       if (!ino)
23307 +               ino = find_inode_number(dir, &qname);
23308 +       if (!ino)
23309 +               ino = 1;
23310 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23311 +}
23312 +
23313 +
23314 +
23315 +/* get and revalidate vx_info/xid */
23316 +
23317 +static inline
23318 +struct vx_info *get_proc_vx_info(struct inode *inode)
23319 +{
23320 +       return lookup_vx_info(PROC_I(inode)->fd);
23321 +}
23322 +
23323 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23324 +{
23325 +       struct inode *inode = dentry->d_inode;
23326 +       xid_t xid = PROC_I(inode)->fd;
23327 +
23328 +       if (!xid || xid_is_hashed(xid))
23329 +               return 1;
23330 +       d_drop(dentry);
23331 +       return 0;
23332 +}
23333 +
23334 +
23335 +/* get and revalidate nx_info/nid */
23336 +
23337 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23338 +{
23339 +       struct inode *inode = dentry->d_inode;
23340 +       nid_t nid = PROC_I(inode)->fd;
23341 +
23342 +       if (!nid || nid_is_hashed(nid))
23343 +               return 1;
23344 +       d_drop(dentry);
23345 +       return 0;
23346 +}
23347 +
23348 +
23349 +
23350 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23351 +
23352 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23353 +                         size_t count, loff_t *ppos)
23354 +{
23355 +       struct inode *inode = file->f_dentry->d_inode;
23356 +       unsigned long page;
23357 +       ssize_t length = 0;
23358 +
23359 +       if (count > PROC_BLOCK_SIZE)
23360 +               count = PROC_BLOCK_SIZE;
23361 +
23362 +       /* fade that out as soon as stable */
23363 +       WARN_ON(PROC_I(inode)->fd);
23364 +
23365 +       if (!(page = __get_free_page(GFP_KERNEL)))
23366 +               return -ENOMEM;
23367 +
23368 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23369 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23370 +
23371 +       if (length >= 0)
23372 +               length = simple_read_from_buffer(buf, count, ppos,
23373 +                       (char *)page, length);
23374 +
23375 +       free_page(page);
23376 +       return length;
23377 +}
23378 +
23379 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23380 +                         size_t count, loff_t *ppos)
23381 +{
23382 +       struct inode *inode = file->f_dentry->d_inode;
23383 +       struct vx_info *vxi = NULL;
23384 +       xid_t xid = PROC_I(inode)->fd;
23385 +       unsigned long page;
23386 +       ssize_t length = 0;
23387 +
23388 +       if (count > PROC_BLOCK_SIZE)
23389 +               count = PROC_BLOCK_SIZE;
23390 +
23391 +       /* fade that out as soon as stable */
23392 +       WARN_ON(!xid);
23393 +       vxi = lookup_vx_info(xid);
23394 +       if (!vxi)
23395 +               goto out;
23396 +
23397 +       length = -ENOMEM;
23398 +       if (!(page = __get_free_page(GFP_KERNEL)))
23399 +               goto out_put;
23400 +
23401 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23402 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23403 +
23404 +       if (length >= 0)
23405 +               length = simple_read_from_buffer(buf, count, ppos,
23406 +                       (char *)page, length);
23407 +
23408 +       free_page(page);
23409 +out_put:
23410 +       put_vx_info(vxi);
23411 +out:
23412 +       return length;
23413 +}
23414 +
23415 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23416 +                         size_t count, loff_t *ppos)
23417 +{
23418 +       struct inode *inode = file->f_dentry->d_inode;
23419 +       struct nx_info *nxi = NULL;
23420 +       nid_t nid = PROC_I(inode)->fd;
23421 +       unsigned long page;
23422 +       ssize_t length = 0;
23423 +
23424 +       if (count > PROC_BLOCK_SIZE)
23425 +               count = PROC_BLOCK_SIZE;
23426 +
23427 +       /* fade that out as soon as stable */
23428 +       WARN_ON(!nid);
23429 +       nxi = lookup_nx_info(nid);
23430 +       if (!nxi)
23431 +               goto out;
23432 +
23433 +       length = -ENOMEM;
23434 +       if (!(page = __get_free_page(GFP_KERNEL)))
23435 +               goto out_put;
23436 +
23437 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23438 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23439 +
23440 +       if (length >= 0)
23441 +               length = simple_read_from_buffer(buf, count, ppos,
23442 +                       (char *)page, length);
23443 +
23444 +       free_page(page);
23445 +out_put:
23446 +       put_nx_info(nxi);
23447 +out:
23448 +       return length;
23449 +}
23450 +
23451 +
23452 +
23453 +/* here comes the lower level */
23454 +
23455 +
23456 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23457 +       .len  = sizeof(NAME) - 1,       \
23458 +       .name = (NAME),                 \
23459 +       .mode = MODE,                   \
23460 +       .iop  = IOP,                    \
23461 +       .fop  = FOP,                    \
23462 +       .op   = OP,                     \
23463 +}
23464 +
23465 +
23466 +#define DIR(NAME, MODE, OTYPE)                         \
23467 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23468 +               &proc_ ## OTYPE ## _inode_operations,   \
23469 +               &proc_ ## OTYPE ## _file_operations, { } )
23470 +
23471 +#define INF(NAME, MODE, OTYPE)                         \
23472 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23473 +               &proc_vs_info_file_operations,          \
23474 +               { .proc_vs_read = &proc_##OTYPE } )
23475 +
23476 +#define VINF(NAME, MODE, OTYPE)                                \
23477 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23478 +               &proc_vx_info_file_operations,          \
23479 +               { .proc_vxi_read = &proc_##OTYPE } )
23480 +
23481 +#define NINF(NAME, MODE, OTYPE)                                \
23482 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23483 +               &proc_nx_info_file_operations,          \
23484 +               { .proc_nxi_read = &proc_##OTYPE } )
23485 +
23486 +
23487 +static struct file_operations proc_vs_info_file_operations = {
23488 +       .read =         proc_vs_info_read,
23489 +};
23490 +
23491 +static struct file_operations proc_vx_info_file_operations = {
23492 +       .read =         proc_vx_info_read,
23493 +};
23494 +
23495 +static struct dentry_operations proc_xid_dentry_operations = {
23496 +       .d_revalidate = proc_xid_revalidate,
23497 +};
23498 +
23499 +static struct vs_entry vx_base_stuff[] = {
23500 +       VINF("info",    S_IRUGO, vxi_info),
23501 +       VINF("status",  S_IRUGO, vxi_status),
23502 +       VINF("limit",   S_IRUGO, vxi_limit),
23503 +       VINF("sched",   S_IRUGO, vxi_sched),
23504 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23505 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23506 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23507 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23508 +       {}
23509 +};
23510 +
23511 +
23512 +
23513 +
23514 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23515 +       struct dentry *dentry, int id, void *ptr)
23516 +{
23517 +       dentry->d_op = &proc_xid_dentry_operations;
23518 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23519 +}
23520 +
23521 +static struct dentry *proc_xid_lookup(struct inode *dir,
23522 +       struct dentry *dentry, struct nameidata *nd)
23523 +{
23524 +       struct vs_entry *p = vx_base_stuff;
23525 +       struct dentry *error = ERR_PTR(-ENOENT);
23526 +
23527 +       for (; p->name; p++) {
23528 +               if (p->len != dentry->d_name.len)
23529 +                       continue;
23530 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23531 +                       break;
23532 +       }
23533 +       if (!p->name)
23534 +               goto out;
23535 +
23536 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23537 +out:
23538 +       return error;
23539 +}
23540 +
23541 +static int proc_xid_readdir(struct file *filp,
23542 +       void *dirent, filldir_t filldir)
23543 +{
23544 +       struct dentry *dentry = filp->f_dentry;
23545 +       struct inode *inode = dentry->d_inode;
23546 +       struct vs_entry *p = vx_base_stuff;
23547 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23548 +       int pos, index;
23549 +       u64 ino;
23550 +
23551 +       pos = filp->f_pos;
23552 +       switch (pos) {
23553 +       case 0:
23554 +               ino = inode->i_ino;
23555 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23556 +                       goto out;
23557 +               pos++;
23558 +               /* fall through */
23559 +       case 1:
23560 +               ino = parent_ino(dentry);
23561 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23562 +                       goto out;
23563 +               pos++;
23564 +               /* fall through */
23565 +       default:
23566 +               index = pos - 2;
23567 +               if (index >= size)
23568 +                       goto out;
23569 +               for (p += index; p->name; p++) {
23570 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23571 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23572 +                               goto out;
23573 +                       pos++;
23574 +               }
23575 +       }
23576 +out:
23577 +       filp->f_pos = pos;
23578 +       return 1;
23579 +}
23580 +
23581 +
23582 +
23583 +static struct file_operations proc_nx_info_file_operations = {
23584 +       .read =         proc_nx_info_read,
23585 +};
23586 +
23587 +static struct dentry_operations proc_nid_dentry_operations = {
23588 +       .d_revalidate = proc_nid_revalidate,
23589 +};
23590 +
23591 +static struct vs_entry nx_base_stuff[] = {
23592 +       NINF("info",    S_IRUGO, nxi_info),
23593 +       NINF("status",  S_IRUGO, nxi_status),
23594 +       {}
23595 +};
23596 +
23597 +
23598 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23599 +       struct dentry *dentry, int id, void *ptr)
23600 +{
23601 +       dentry->d_op = &proc_nid_dentry_operations;
23602 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23603 +}
23604 +
23605 +static struct dentry *proc_nid_lookup(struct inode *dir,
23606 +       struct dentry *dentry, struct nameidata *nd)
23607 +{
23608 +       struct vs_entry *p = nx_base_stuff;
23609 +       struct dentry *error = ERR_PTR(-ENOENT);
23610 +
23611 +       for (; p->name; p++) {
23612 +               if (p->len != dentry->d_name.len)
23613 +                       continue;
23614 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23615 +                       break;
23616 +       }
23617 +       if (!p->name)
23618 +               goto out;
23619 +
23620 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23621 +out:
23622 +       return error;
23623 +}
23624 +
23625 +static int proc_nid_readdir(struct file *filp,
23626 +       void *dirent, filldir_t filldir)
23627 +{
23628 +       struct dentry *dentry = filp->f_dentry;
23629 +       struct inode *inode = dentry->d_inode;
23630 +       struct vs_entry *p = nx_base_stuff;
23631 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23632 +       int pos, index;
23633 +       u64 ino;
23634 +
23635 +       pos = filp->f_pos;
23636 +       switch (pos) {
23637 +       case 0:
23638 +               ino = inode->i_ino;
23639 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23640 +                       goto out;
23641 +               pos++;
23642 +               /* fall through */
23643 +       case 1:
23644 +               ino = parent_ino(dentry);
23645 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23646 +                       goto out;
23647 +               pos++;
23648 +               /* fall through */
23649 +       default:
23650 +               index = pos - 2;
23651 +               if (index >= size)
23652 +                       goto out;
23653 +               for (p += index; p->name; p++) {
23654 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23655 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23656 +                               goto out;
23657 +                       pos++;
23658 +               }
23659 +       }
23660 +out:
23661 +       filp->f_pos = pos;
23662 +       return 1;
23663 +}
23664 +
23665 +
23666 +#define MAX_MULBY10    ((~0U - 9) / 10)
23667 +
23668 +static inline int atovid(const char *str, int len)
23669 +{
23670 +       int vid, c;
23671 +
23672 +       vid = 0;
23673 +       while (len-- > 0) {
23674 +               c = *str - '0';
23675 +               str++;
23676 +               if (c > 9)
23677 +                       return -1;
23678 +               if (vid >= MAX_MULBY10)
23679 +                       return -1;
23680 +               vid *= 10;
23681 +               vid += c;
23682 +               if (!vid)
23683 +                       return -1;
23684 +       }
23685 +       return vid;
23686 +}
23687 +
23688 +/* now the upper level (virtual) */
23689 +
23690 +
23691 +static struct file_operations proc_xid_file_operations = {
23692 +       .read =         generic_read_dir,
23693 +       .readdir =      proc_xid_readdir,
23694 +};
23695 +
23696 +static struct inode_operations proc_xid_inode_operations = {
23697 +       .lookup =       proc_xid_lookup,
23698 +};
23699 +
23700 +static struct vs_entry vx_virtual_stuff[] = {
23701 +       INF("info",     S_IRUGO, virtual_info),
23702 +       INF("status",   S_IRUGO, virtual_status),
23703 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23704 +};
23705 +
23706 +
23707 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23708 +       struct dentry *dentry, struct nameidata *nd)
23709 +{
23710 +       struct vs_entry *p = vx_virtual_stuff;
23711 +       struct dentry *error = ERR_PTR(-ENOENT);
23712 +       int id = 0;
23713 +
23714 +       for (; p->name; p++) {
23715 +               if (p->len != dentry->d_name.len)
23716 +                       continue;
23717 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23718 +                       break;
23719 +       }
23720 +       if (p->name)
23721 +               goto instantiate;
23722 +
23723 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23724 +       if ((id < 0) || !xid_is_hashed(id))
23725 +               goto out;
23726 +
23727 +instantiate:
23728 +       error = proc_xid_instantiate(dir, dentry, id, p);
23729 +out:
23730 +       return error;
23731 +}
23732 +
23733 +static struct file_operations proc_nid_file_operations = {
23734 +       .read =         generic_read_dir,
23735 +       .readdir =      proc_nid_readdir,
23736 +};
23737 +
23738 +static struct inode_operations proc_nid_inode_operations = {
23739 +       .lookup =       proc_nid_lookup,
23740 +};
23741 +
23742 +static struct vs_entry nx_virtnet_stuff[] = {
23743 +       INF("info",     S_IRUGO, virtnet_info),
23744 +       INF("status",   S_IRUGO, virtnet_status),
23745 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23746 +};
23747 +
23748 +
23749 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23750 +       struct dentry *dentry, struct nameidata *nd)
23751 +{
23752 +       struct vs_entry *p = nx_virtnet_stuff;
23753 +       struct dentry *error = ERR_PTR(-ENOENT);
23754 +       int id = 0;
23755 +
23756 +       for (; p->name; p++) {
23757 +               if (p->len != dentry->d_name.len)
23758 +                       continue;
23759 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23760 +                       break;
23761 +       }
23762 +       if (p->name)
23763 +               goto instantiate;
23764 +
23765 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23766 +       if ((id < 0) || !nid_is_hashed(id))
23767 +               goto out;
23768 +
23769 +instantiate:
23770 +       error = proc_nid_instantiate(dir, dentry, id, p);
23771 +out:
23772 +       return error;
23773 +}
23774 +
23775 +
23776 +#define PROC_MAXVIDS 32
23777 +
23778 +int proc_virtual_readdir(struct file *filp,
23779 +       void *dirent, filldir_t filldir)
23780 +{
23781 +       struct dentry *dentry = filp->f_dentry;
23782 +       struct inode *inode = dentry->d_inode;
23783 +       struct vs_entry *p = vx_virtual_stuff;
23784 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23785 +       int pos, index;
23786 +       unsigned int xid_array[PROC_MAXVIDS];
23787 +       char buf[PROC_NUMBUF];
23788 +       unsigned int nr_xids, i;
23789 +       u64 ino;
23790 +
23791 +       pos = filp->f_pos;
23792 +       switch (pos) {
23793 +       case 0:
23794 +               ino = inode->i_ino;
23795 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23796 +                       goto out;
23797 +               pos++;
23798 +               /* fall through */
23799 +       case 1:
23800 +               ino = parent_ino(dentry);
23801 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23802 +                       goto out;
23803 +               pos++;
23804 +               /* fall through */
23805 +       default:
23806 +               index = pos - 2;
23807 +               if (index >= size)
23808 +                       goto entries;
23809 +               for (p += index; p->name; p++) {
23810 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23811 +                               vs_proc_instantiate, 0, p))
23812 +                               goto out;
23813 +                       pos++;
23814 +               }
23815 +       entries:
23816 +               index = pos - size;
23817 +               p = &vx_virtual_stuff[size - 1];
23818 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23819 +               for (i = 0; i < nr_xids; i++) {
23820 +                       int n, xid = xid_array[i];
23821 +                       unsigned int j = PROC_NUMBUF;
23822 +
23823 +                       n = xid;
23824 +                       do
23825 +                               buf[--j] = '0' + (n % 10);
23826 +                       while (n /= 10);
23827 +
23828 +                       if (proc_fill_cache(filp, dirent, filldir,
23829 +                               buf + j, PROC_NUMBUF - j,
23830 +                               vs_proc_instantiate, xid, p))
23831 +                               goto out;
23832 +                       pos++;
23833 +               }
23834 +       }
23835 +out:
23836 +       filp->f_pos = pos;
23837 +       return 0;
23838 +}
23839 +
23840 +static int proc_virtual_getattr(struct vfsmount *mnt,
23841 +       struct dentry *dentry, struct kstat *stat)
23842 +{
23843 +       struct inode *inode = dentry->d_inode;
23844 +
23845 +       generic_fillattr(inode, stat);
23846 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23847 +       return 0;
23848 +}
23849 +
23850 +static struct file_operations proc_virtual_dir_operations = {
23851 +       .read =         generic_read_dir,
23852 +       .readdir =      proc_virtual_readdir,
23853 +};
23854 +
23855 +static struct inode_operations proc_virtual_dir_inode_operations = {
23856 +       .getattr =      proc_virtual_getattr,
23857 +       .lookup =       proc_virtual_lookup,
23858 +};
23859 +
23860 +
23861 +
23862 +
23863 +
23864 +int proc_virtnet_readdir(struct file *filp,
23865 +       void *dirent, filldir_t filldir)
23866 +{
23867 +       struct dentry *dentry = filp->f_dentry;
23868 +       struct inode *inode = dentry->d_inode;
23869 +       struct vs_entry *p = nx_virtnet_stuff;
23870 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23871 +       int pos, index;
23872 +       unsigned int nid_array[PROC_MAXVIDS];
23873 +       char buf[PROC_NUMBUF];
23874 +       unsigned int nr_nids, i;
23875 +       u64 ino;
23876 +
23877 +       pos = filp->f_pos;
23878 +       switch (pos) {
23879 +       case 0:
23880 +               ino = inode->i_ino;
23881 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23882 +                       goto out;
23883 +               pos++;
23884 +               /* fall through */
23885 +       case 1:
23886 +               ino = parent_ino(dentry);
23887 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23888 +                       goto out;
23889 +               pos++;
23890 +               /* fall through */
23891 +       default:
23892 +               index = pos - 2;
23893 +               if (index >= size)
23894 +                       goto entries;
23895 +               for (p += index; p->name; p++) {
23896 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23897 +                               vs_proc_instantiate, 0, p))
23898 +                               goto out;
23899 +                       pos++;
23900 +               }
23901 +       entries:
23902 +               index = pos - size;
23903 +               p = &nx_virtnet_stuff[size - 1];
23904 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23905 +               for (i = 0; i < nr_nids; i++) {
23906 +                       int n, nid = nid_array[i];
23907 +                       unsigned int j = PROC_NUMBUF;
23908 +
23909 +                       n = nid;
23910 +                       do
23911 +                               buf[--j] = '0' + (n % 10);
23912 +                       while (n /= 10);
23913 +
23914 +                       if (proc_fill_cache(filp, dirent, filldir,
23915 +                               buf + j, PROC_NUMBUF - j,
23916 +                               vs_proc_instantiate, nid, p))
23917 +                               goto out;
23918 +                       pos++;
23919 +               }
23920 +       }
23921 +out:
23922 +       filp->f_pos = pos;
23923 +       return 0;
23924 +}
23925 +
23926 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23927 +       struct dentry *dentry, struct kstat *stat)
23928 +{
23929 +       struct inode *inode = dentry->d_inode;
23930 +
23931 +       generic_fillattr(inode, stat);
23932 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23933 +       return 0;
23934 +}
23935 +
23936 +static struct file_operations proc_virtnet_dir_operations = {
23937 +       .read =         generic_read_dir,
23938 +       .readdir =      proc_virtnet_readdir,
23939 +};
23940 +
23941 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23942 +       .getattr =      proc_virtnet_getattr,
23943 +       .lookup =       proc_virtnet_lookup,
23944 +};
23945 +
23946 +
23947 +
23948 +void proc_vx_init(void)
23949 +{
23950 +       struct proc_dir_entry *ent;
23951 +
23952 +       ent = proc_mkdir("virtual", 0);
23953 +       if (ent) {
23954 +               ent->proc_fops = &proc_virtual_dir_operations;
23955 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23956 +       }
23957 +       proc_virtual = ent;
23958 +
23959 +       ent = proc_mkdir("virtnet", 0);
23960 +       if (ent) {
23961 +               ent->proc_fops = &proc_virtnet_dir_operations;
23962 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23963 +       }
23964 +       proc_virtnet = ent;
23965 +}
23966 +
23967 +
23968 +
23969 +
23970 +/* per pid info */
23971 +
23972 +
23973 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23974 +{
23975 +       struct vx_info *vxi;
23976 +       char *orig = buffer;
23977 +
23978 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23979 +
23980 +       vxi = task_get_vx_info(p);
23981 +       if (!vxi)
23982 +               goto out;
23983 +
23984 +       buffer += sprintf(buffer, "BCaps:\t");
23985 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23986 +       buffer += sprintf(buffer, "\n");
23987 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23988 +               (unsigned long long)vxi->vx_ccaps);
23989 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23990 +               (unsigned long long)vxi->vx_flags);
23991 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23992 +
23993 +       put_vx_info(vxi);
23994 +out:
23995 +       return buffer - orig;
23996 +}
23997 +
23998 +
23999 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24000 +{
24001 +       struct nx_info *nxi;
24002 +       struct nx_addr_v4 *v4a;
24003 +#ifdef CONFIG_IPV6
24004 +       struct nx_addr_v6 *v6a;
24005 +#endif
24006 +       char *orig = buffer;
24007 +       int i;
24008 +
24009 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24010 +
24011 +       nxi = task_get_nx_info(p);
24012 +       if (!nxi)
24013 +               goto out;
24014 +
24015 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24016 +               (unsigned long long)nxi->nx_ncaps);
24017 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24018 +               (unsigned long long)nxi->nx_flags);
24019 +
24020 +       buffer += sprintf(buffer,
24021 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24022 +               NIPQUAD(nxi->v4_bcast.s_addr));
24023 +       buffer += sprintf (buffer,
24024 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24025 +               NIPQUAD(nxi->v4_lback.s_addr));
24026 +       if (!NX_IPV4(nxi))
24027 +               goto skip_v4;
24028 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24029 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24030 +                       i, NXAV4(v4a));
24031 +skip_v4:
24032 +#ifdef CONFIG_IPV6
24033 +       if (!NX_IPV6(nxi))
24034 +               goto skip_v6;
24035 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24036 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24037 +                       i, NXAV6(v6a));
24038 +skip_v6:
24039 +#endif
24040 +       put_nx_info(nxi);
24041 +out:
24042 +       return buffer - orig;
24043 +}
24044 +
24045 diff -NurpP --minimal linux-3.1/kernel/vserver/sched.c linux-3.1-vs2.3.1-rc2/kernel/vserver/sched.c
24046 --- linux-3.1/kernel/vserver/sched.c    1970-01-01 01:00:00.000000000 +0100
24047 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/sched.c        2011-10-24 18:53:33.000000000 +0200
24048 @@ -0,0 +1,82 @@
24049 +/*
24050 + *  linux/kernel/vserver/sched.c
24051 + *
24052 + *  Virtual Server: Scheduler Support
24053 + *
24054 + *  Copyright (C) 2004-2010  Herbert Pötzl
24055 + *
24056 + *  V0.01  adapted Sam Vilains version to 2.6.3
24057 + *  V0.02  removed legacy interface
24058 + *  V0.03  changed vcmds to vxi arg
24059 + *  V0.04  removed older and legacy interfaces
24060 + *  V0.05  removed scheduler code/commands
24061 + *
24062 + */
24063 +
24064 +#include <linux/vs_context.h>
24065 +#include <linux/vs_sched.h>
24066 +#include <linux/vserver/sched_cmd.h>
24067 +
24068 +#include <asm/uaccess.h>
24069 +
24070 +
24071 +void vx_update_sched_param(struct _vx_sched *sched,
24072 +       struct _vx_sched_pc *sched_pc)
24073 +{
24074 +       sched_pc->prio_bias = sched->prio_bias;
24075 +}
24076 +
24077 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
24078 +{
24079 +       int cpu;
24080 +
24081 +       if (data->prio_bias > MAX_PRIO_BIAS)
24082 +               data->prio_bias = MAX_PRIO_BIAS;
24083 +       if (data->prio_bias < MIN_PRIO_BIAS)
24084 +               data->prio_bias = MIN_PRIO_BIAS;
24085 +
24086 +       if (data->cpu_id != ~0) {
24087 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24088 +               cpus_and(vxi->sched.update, cpu_online_map,
24089 +                       vxi->sched.update);
24090 +       } else
24091 +               vxi->sched.update = cpu_online_map;
24092 +
24093 +       for_each_cpu_mask(cpu, vxi->sched.update)
24094 +               vx_update_sched_param(&vxi->sched,
24095 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24096 +       return 0;
24097 +}
24098 +
24099 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
24100 +{
24101 +       struct vcmd_prio_bias vc_data;
24102 +
24103 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24104 +               return -EFAULT;
24105 +
24106 +       return do_set_prio_bias(vxi, &vc_data);
24107 +}
24108 +
24109 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
24110 +{
24111 +       struct vcmd_prio_bias vc_data;
24112 +       struct _vx_sched_pc *pcd;
24113 +       int cpu;
24114 +
24115 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24116 +               return -EFAULT;
24117 +
24118 +       cpu = vc_data.cpu_id;
24119 +
24120 +       if (!cpu_possible(cpu))
24121 +               return -EINVAL;
24122 +
24123 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
24124 +       vc_data.prio_bias = pcd->prio_bias;
24125 +
24126 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24127 +               return -EFAULT;
24128 +       return 0;
24129 +}
24130 +
24131 diff -NurpP --minimal linux-3.1/kernel/vserver/sched_init.h linux-3.1-vs2.3.1-rc2/kernel/vserver/sched_init.h
24132 --- linux-3.1/kernel/vserver/sched_init.h       1970-01-01 01:00:00.000000000 +0100
24133 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/sched_init.h   2011-10-24 18:53:33.000000000 +0200
24134 @@ -0,0 +1,27 @@
24135 +
24136 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24137 +{
24138 +       /* scheduling; hard code starting values as constants */
24139 +       sched->prio_bias = 0;
24140 +}
24141 +
24142 +static inline
24143 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24144 +{
24145 +       sched_pc->prio_bias = 0;
24146 +
24147 +       sched_pc->user_ticks = 0;
24148 +       sched_pc->sys_ticks = 0;
24149 +       sched_pc->hold_ticks = 0;
24150 +}
24151 +
24152 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24153 +{
24154 +       return;
24155 +}
24156 +
24157 +static inline
24158 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24159 +{
24160 +       return;
24161 +}
24162 diff -NurpP --minimal linux-3.1/kernel/vserver/sched_proc.h linux-3.1-vs2.3.1-rc2/kernel/vserver/sched_proc.h
24163 --- linux-3.1/kernel/vserver/sched_proc.h       1970-01-01 01:00:00.000000000 +0100
24164 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/sched_proc.h   2011-10-24 18:53:33.000000000 +0200
24165 @@ -0,0 +1,32 @@
24166 +#ifndef _VX_SCHED_PROC_H
24167 +#define _VX_SCHED_PROC_H
24168 +
24169 +
24170 +static inline
24171 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24172 +{
24173 +       int length = 0;
24174 +
24175 +       length += sprintf(buffer,
24176 +               "PrioBias:\t%8d\n",
24177 +               sched->prio_bias);
24178 +       return length;
24179 +}
24180 +
24181 +static inline
24182 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24183 +       char *buffer, int cpu)
24184 +{
24185 +       int length = 0;
24186 +
24187 +       length += sprintf(buffer + length,
24188 +               "cpu %d: %lld %lld %lld", cpu,
24189 +               (unsigned long long)sched_pc->user_ticks,
24190 +               (unsigned long long)sched_pc->sys_ticks,
24191 +               (unsigned long long)sched_pc->hold_ticks);
24192 +       length += sprintf(buffer + length,
24193 +               " %d\n", sched_pc->prio_bias);
24194 +       return length;
24195 +}
24196 +
24197 +#endif /* _VX_SCHED_PROC_H */
24198 diff -NurpP --minimal linux-3.1/kernel/vserver/signal.c linux-3.1-vs2.3.1-rc2/kernel/vserver/signal.c
24199 --- linux-3.1/kernel/vserver/signal.c   1970-01-01 01:00:00.000000000 +0100
24200 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/signal.c       2011-10-24 18:53:33.000000000 +0200
24201 @@ -0,0 +1,134 @@
24202 +/*
24203 + *  linux/kernel/vserver/signal.c
24204 + *
24205 + *  Virtual Server: Signal Support
24206 + *
24207 + *  Copyright (C) 2003-2007  Herbert Pötzl
24208 + *
24209 + *  V0.01  broken out from vcontext V0.05
24210 + *  V0.02  changed vcmds to vxi arg
24211 + *  V0.03  adjusted siginfo for kill
24212 + *
24213 + */
24214 +
24215 +#include <asm/uaccess.h>
24216 +
24217 +#include <linux/vs_context.h>
24218 +#include <linux/vs_pid.h>
24219 +#include <linux/vserver/signal_cmd.h>
24220 +
24221 +
24222 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24223 +{
24224 +       int retval, count = 0;
24225 +       struct task_struct *p;
24226 +       struct siginfo *sip = SEND_SIG_PRIV;
24227 +
24228 +       retval = -ESRCH;
24229 +       vxdprintk(VXD_CBIT(misc, 4),
24230 +               "vx_info_kill(%p[#%d],%d,%d)*",
24231 +               vxi, vxi->vx_id, pid, sig);
24232 +       read_lock(&tasklist_lock);
24233 +       switch (pid) {
24234 +       case  0:
24235 +       case -1:
24236 +               for_each_process(p) {
24237 +                       int err = 0;
24238 +
24239 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24240 +                               (pid && vxi->vx_initpid == p->pid))
24241 +                               continue;
24242 +
24243 +                       err = group_send_sig_info(sig, sip, p);
24244 +                       ++count;
24245 +                       if (err != -EPERM)
24246 +                               retval = err;
24247 +               }
24248 +               break;
24249 +
24250 +       case 1:
24251 +               if (vxi->vx_initpid) {
24252 +                       pid = vxi->vx_initpid;
24253 +                       /* for now, only SIGINT to private init ... */
24254 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24255 +                               /* ... as long as there are tasks left */
24256 +                               (atomic_read(&vxi->vx_tasks) > 1))
24257 +                               sig = SIGINT;
24258 +               }
24259 +               /* fallthrough */
24260 +       default:
24261 +               rcu_read_lock();
24262 +               p = find_task_by_real_pid(pid);
24263 +               rcu_read_unlock();
24264 +               if (p) {
24265 +                       if (vx_task_xid(p) == vxi->vx_id)
24266 +                               retval = group_send_sig_info(sig, sip, p);
24267 +               }
24268 +               break;
24269 +       }
24270 +       read_unlock(&tasklist_lock);
24271 +       vxdprintk(VXD_CBIT(misc, 4),
24272 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24273 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24274 +       return retval;
24275 +}
24276 +
24277 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24278 +{
24279 +       struct vcmd_ctx_kill_v0 vc_data;
24280 +
24281 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24282 +               return -EFAULT;
24283 +
24284 +       /* special check to allow guest shutdown */
24285 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24286 +               /* forbid killall pid=0 when init is present */
24287 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24288 +               (vc_data.pid > 1)))
24289 +               return -EACCES;
24290 +
24291 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24292 +}
24293 +
24294 +
24295 +static int __wait_exit(struct vx_info *vxi)
24296 +{
24297 +       DECLARE_WAITQUEUE(wait, current);
24298 +       int ret = 0;
24299 +
24300 +       add_wait_queue(&vxi->vx_wait, &wait);
24301 +       set_current_state(TASK_INTERRUPTIBLE);
24302 +
24303 +wait:
24304 +       if (vx_info_state(vxi,
24305 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24306 +               goto out;
24307 +       if (signal_pending(current)) {
24308 +               ret = -ERESTARTSYS;
24309 +               goto out;
24310 +       }
24311 +       schedule();
24312 +       goto wait;
24313 +
24314 +out:
24315 +       set_current_state(TASK_RUNNING);
24316 +       remove_wait_queue(&vxi->vx_wait, &wait);
24317 +       return ret;
24318 +}
24319 +
24320 +
24321 +
24322 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24323 +{
24324 +       struct vcmd_wait_exit_v0 vc_data;
24325 +       int ret;
24326 +
24327 +       ret = __wait_exit(vxi);
24328 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24329 +       vc_data.exit_code = vxi->exit_code;
24330 +
24331 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24332 +               ret = -EFAULT;
24333 +       return ret;
24334 +}
24335 +
24336 diff -NurpP --minimal linux-3.1/kernel/vserver/space.c linux-3.1-vs2.3.1-rc2/kernel/vserver/space.c
24337 --- linux-3.1/kernel/vserver/space.c    1970-01-01 01:00:00.000000000 +0100
24338 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/space.c        2011-10-24 18:53:33.000000000 +0200
24339 @@ -0,0 +1,435 @@
24340 +/*
24341 + *  linux/kernel/vserver/space.c
24342 + *
24343 + *  Virtual Server: Context Space Support
24344 + *
24345 + *  Copyright (C) 2003-2010  Herbert Pötzl
24346 + *
24347 + *  V0.01  broken out from context.c 0.07
24348 + *  V0.02  added task locking for namespace
24349 + *  V0.03  broken out vx_enter_namespace
24350 + *  V0.04  added *space support and commands
24351 + *  V0.05  added credential support
24352 + *
24353 + */
24354 +
24355 +#include <linux/utsname.h>
24356 +#include <linux/nsproxy.h>
24357 +#include <linux/err.h>
24358 +#include <linux/fs_struct.h>
24359 +#include <linux/cred.h>
24360 +#include <asm/uaccess.h>
24361 +
24362 +#include <linux/vs_context.h>
24363 +#include <linux/vserver/space.h>
24364 +#include <linux/vserver/space_cmd.h>
24365 +
24366 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24367 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24368 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24369 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24370 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24371 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24372 +
24373 +
24374 +/* namespace functions */
24375 +
24376 +#include <linux/mnt_namespace.h>
24377 +#include <linux/user_namespace.h>
24378 +#include <linux/pid_namespace.h>
24379 +#include <linux/ipc_namespace.h>
24380 +#include <net/net_namespace.h>
24381 +
24382 +
24383 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24384 +       .mask = CLONE_FS |
24385 +               CLONE_NEWNS |
24386 +#ifdef CONFIG_UTS_NS
24387 +               CLONE_NEWUTS |
24388 +#endif
24389 +#ifdef CONFIG_IPC_NS
24390 +               CLONE_NEWIPC |
24391 +#endif
24392 +#ifdef CONFIG_USER_NS
24393 +               CLONE_NEWUSER |
24394 +#endif
24395 +               0
24396 +};
24397 +
24398 +static const struct vcmd_space_mask_v1 space_mask = {
24399 +       .mask = CLONE_FS |
24400 +               CLONE_NEWNS |
24401 +#ifdef CONFIG_UTS_NS
24402 +               CLONE_NEWUTS |
24403 +#endif
24404 +#ifdef CONFIG_IPC_NS
24405 +               CLONE_NEWIPC |
24406 +#endif
24407 +#ifdef CONFIG_USER_NS
24408 +               CLONE_NEWUSER |
24409 +#endif
24410 +#ifdef CONFIG_PID_NS
24411 +               CLONE_NEWPID |
24412 +#endif
24413 +#ifdef CONFIG_NET_NS
24414 +               CLONE_NEWNET |
24415 +#endif
24416 +               0
24417 +};
24418 +
24419 +static const struct vcmd_space_mask_v1 default_space_mask = {
24420 +       .mask = CLONE_FS |
24421 +               CLONE_NEWNS |
24422 +#ifdef CONFIG_UTS_NS
24423 +               CLONE_NEWUTS |
24424 +#endif
24425 +#ifdef CONFIG_IPC_NS
24426 +               CLONE_NEWIPC |
24427 +#endif
24428 +#ifdef CONFIG_USER_NS
24429 +               CLONE_NEWUSER |
24430 +#endif
24431 +#ifdef CONFIG_PID_NS
24432 +//             CLONE_NEWPID |
24433 +#endif
24434 +               0
24435 +};
24436 +
24437 +/*
24438 + *     build a new nsproxy mix
24439 + *      assumes that both proxies are 'const'
24440 + *     does not touch nsproxy refcounts
24441 + *     will hold a reference on the result.
24442 + */
24443 +
24444 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24445 +       struct nsproxy *new_nsproxy, unsigned long mask)
24446 +{
24447 +       struct mnt_namespace *old_ns;
24448 +       struct uts_namespace *old_uts;
24449 +       struct ipc_namespace *old_ipc;
24450 +#ifdef CONFIG_PID_NS
24451 +       struct pid_namespace *old_pid;
24452 +#endif
24453 +#ifdef CONFIG_NET_NS
24454 +       struct net *old_net;
24455 +#endif
24456 +       struct nsproxy *nsproxy;
24457 +
24458 +       nsproxy = copy_nsproxy(old_nsproxy);
24459 +       if (!nsproxy)
24460 +               goto out;
24461 +
24462 +       if (mask & CLONE_NEWNS) {
24463 +               old_ns = nsproxy->mnt_ns;
24464 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24465 +               if (nsproxy->mnt_ns)
24466 +                       get_mnt_ns(nsproxy->mnt_ns);
24467 +       } else
24468 +               old_ns = NULL;
24469 +
24470 +       if (mask & CLONE_NEWUTS) {
24471 +               old_uts = nsproxy->uts_ns;
24472 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24473 +               if (nsproxy->uts_ns)
24474 +                       get_uts_ns(nsproxy->uts_ns);
24475 +       } else
24476 +               old_uts = NULL;
24477 +
24478 +       if (mask & CLONE_NEWIPC) {
24479 +               old_ipc = nsproxy->ipc_ns;
24480 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24481 +               if (nsproxy->ipc_ns)
24482 +                       get_ipc_ns(nsproxy->ipc_ns);
24483 +       } else
24484 +               old_ipc = NULL;
24485 +
24486 +#ifdef CONFIG_PID_NS
24487 +       if (mask & CLONE_NEWPID) {
24488 +               old_pid = nsproxy->pid_ns;
24489 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24490 +               if (nsproxy->pid_ns)
24491 +                       get_pid_ns(nsproxy->pid_ns);
24492 +       } else
24493 +               old_pid = NULL;
24494 +#endif
24495 +#ifdef CONFIG_NET_NS
24496 +       if (mask & CLONE_NEWNET) {
24497 +               old_net = nsproxy->net_ns;
24498 +               nsproxy->net_ns = new_nsproxy->net_ns;
24499 +               if (nsproxy->net_ns)
24500 +                       get_net(nsproxy->net_ns);
24501 +       } else
24502 +               old_net = NULL;
24503 +#endif
24504 +       if (old_ns)
24505 +               put_mnt_ns(old_ns);
24506 +       if (old_uts)
24507 +               put_uts_ns(old_uts);
24508 +       if (old_ipc)
24509 +               put_ipc_ns(old_ipc);
24510 +#ifdef CONFIG_PID_NS
24511 +       if (old_pid)
24512 +               put_pid_ns(old_pid);
24513 +#endif
24514 +#ifdef CONFIG_NET_NS
24515 +       if (old_net)
24516 +               put_net(old_net);
24517 +#endif
24518 +out:
24519 +       return nsproxy;
24520 +}
24521 +
24522 +
24523 +/*
24524 + *     merge two nsproxy structs into a new one.
24525 + *     will hold a reference on the result.
24526 + */
24527 +
24528 +static inline
24529 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24530 +       struct nsproxy *proxy, unsigned long mask)
24531 +{
24532 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24533 +
24534 +       if (!proxy)
24535 +               return NULL;
24536 +
24537 +       if (mask) {
24538 +               /* vs_mix_nsproxy returns with reference */
24539 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24540 +                       proxy, mask);
24541 +       }
24542 +       get_nsproxy(proxy);
24543 +       return proxy;
24544 +}
24545 +
24546 +
24547 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24548 +{
24549 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24550 +       struct fs_struct *fs_cur, *fs = NULL;
24551 +       struct _vx_space *space;
24552 +       int ret, kill = 0;
24553 +
24554 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24555 +               vxi, vxi->vx_id, mask, index);
24556 +
24557 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24558 +               return -EACCES;
24559 +
24560 +       if (index >= VX_SPACES)
24561 +               return -EINVAL;
24562 +
24563 +       space = &vxi->space[index];
24564 +
24565 +       if (!mask)
24566 +               mask = space->vx_nsmask;
24567 +
24568 +       if ((mask & space->vx_nsmask) != mask)
24569 +               return -EINVAL;
24570 +
24571 +       if (mask & CLONE_FS) {
24572 +               fs = copy_fs_struct(space->vx_fs);
24573 +               if (!fs)
24574 +                       return -ENOMEM;
24575 +       }
24576 +       proxy = space->vx_nsproxy;
24577 +
24578 +       vxdprintk(VXD_CBIT(space, 9),
24579 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
24580 +               vxi, vxi->vx_id, mask, index, proxy, fs);
24581 +
24582 +       task_lock(current);
24583 +       fs_cur = current->fs;
24584 +
24585 +       if (mask & CLONE_FS) {
24586 +               spin_lock(&fs_cur->lock);
24587 +               current->fs = fs;
24588 +               kill = !--fs_cur->users;
24589 +               spin_unlock(&fs_cur->lock);
24590 +       }
24591 +
24592 +       proxy_cur = current->nsproxy;
24593 +       get_nsproxy(proxy_cur);
24594 +       task_unlock(current);
24595 +
24596 +       if (kill)
24597 +               free_fs_struct(fs_cur);
24598 +
24599 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24600 +       if (IS_ERR(proxy_new)) {
24601 +               ret = PTR_ERR(proxy_new);
24602 +               goto out_put;
24603 +       }
24604 +
24605 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24606 +
24607 +       if (mask & CLONE_NEWUSER) {
24608 +               struct cred *cred;
24609 +
24610 +               vxdprintk(VXD_CBIT(space, 10),
24611 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
24612 +                       vxi, vxi->vx_id, space->vx_cred,
24613 +                       current->real_cred, current->cred);
24614 +
24615 +               if (space->vx_cred) {
24616 +                       cred = __prepare_creds(space->vx_cred);
24617 +                       if (cred)
24618 +                               commit_creds(cred);
24619 +               }
24620 +       }
24621 +
24622 +       ret = 0;
24623 +
24624 +       if (proxy_new)
24625 +               put_nsproxy(proxy_new);
24626 +out_put:
24627 +       if (proxy_cur)
24628 +               put_nsproxy(proxy_cur);
24629 +       return ret;
24630 +}
24631 +
24632 +
24633 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24634 +{
24635 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24636 +       struct fs_struct *fs_vxi, *fs;
24637 +       struct _vx_space *space;
24638 +       int ret, kill = 0;
24639 +
24640 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24641 +               vxi, vxi->vx_id, mask, index);
24642 +
24643 +       if ((mask & space_mask.mask) != mask)
24644 +               return -EINVAL;
24645 +
24646 +       if (index >= VX_SPACES)
24647 +               return -EINVAL;
24648 +
24649 +       space = &vxi->space[index];
24650 +
24651 +       proxy_vxi = space->vx_nsproxy;
24652 +       fs_vxi = space->vx_fs;
24653 +
24654 +       if (mask & CLONE_FS) {
24655 +               fs = copy_fs_struct(current->fs);
24656 +               if (!fs)
24657 +                       return -ENOMEM;
24658 +       }
24659 +
24660 +       task_lock(current);
24661 +
24662 +       if (mask & CLONE_FS) {
24663 +               spin_lock(&fs_vxi->lock);
24664 +               space->vx_fs = fs;
24665 +               kill = !--fs_vxi->users;
24666 +               spin_unlock(&fs_vxi->lock);
24667 +       }
24668 +
24669 +       proxy_cur = current->nsproxy;
24670 +       get_nsproxy(proxy_cur);
24671 +       task_unlock(current);
24672 +
24673 +       if (kill)
24674 +               free_fs_struct(fs_vxi);
24675 +
24676 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24677 +       if (IS_ERR(proxy_new)) {
24678 +               ret = PTR_ERR(proxy_new);
24679 +               goto out_put;
24680 +       }
24681 +
24682 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
24683 +       space->vx_nsmask |= mask;
24684 +
24685 +       if (mask & CLONE_NEWUSER) {
24686 +               struct cred *cred;
24687 +
24688 +               vxdprintk(VXD_CBIT(space, 10),
24689 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
24690 +                       vxi, vxi->vx_id, space->vx_cred,
24691 +                       current->real_cred, current->cred);
24692 +
24693 +               cred = prepare_creds();
24694 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
24695 +               if (cred)
24696 +                       abort_creds(cred);
24697 +       }
24698 +
24699 +       ret = 0;
24700 +
24701 +       if (proxy_new)
24702 +               put_nsproxy(proxy_new);
24703 +out_put:
24704 +       if (proxy_cur)
24705 +               put_nsproxy(proxy_cur);
24706 +       return ret;
24707 +}
24708 +
24709 +
24710 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24711 +{
24712 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24713 +
24714 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24715 +               return -EFAULT;
24716 +
24717 +       return vx_enter_space(vxi, vc_data.mask, 0);
24718 +}
24719 +
24720 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24721 +{
24722 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24723 +
24724 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24725 +               return -EFAULT;
24726 +
24727 +       if (vc_data.index >= VX_SPACES)
24728 +               return -EINVAL;
24729 +
24730 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24731 +}
24732 +
24733 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24734 +{
24735 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24736 +
24737 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24738 +               return -EFAULT;
24739 +
24740 +       return vx_set_space(vxi, vc_data.mask, 0);
24741 +}
24742 +
24743 +int vc_set_space(struct vx_info *vxi, void __user *data)
24744 +{
24745 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24746 +
24747 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24748 +               return -EFAULT;
24749 +
24750 +       if (vc_data.index >= VX_SPACES)
24751 +               return -EINVAL;
24752 +
24753 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24754 +}
24755 +
24756 +int vc_get_space_mask(void __user *data, int type)
24757 +{
24758 +       const struct vcmd_space_mask_v1 *mask;
24759 +
24760 +       if (type == 0)
24761 +               mask = &space_mask_v0;
24762 +       else if (type == 1)
24763 +               mask = &space_mask;
24764 +       else
24765 +               mask = &default_space_mask;
24766 +
24767 +       vxdprintk(VXD_CBIT(space, 10),
24768 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24769 +
24770 +       if (copy_to_user(data, mask, sizeof(*mask)))
24771 +               return -EFAULT;
24772 +       return 0;
24773 +}
24774 +
24775 diff -NurpP --minimal linux-3.1/kernel/vserver/switch.c linux-3.1-vs2.3.1-rc2/kernel/vserver/switch.c
24776 --- linux-3.1/kernel/vserver/switch.c   1970-01-01 01:00:00.000000000 +0100
24777 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/switch.c       2011-10-24 18:53:33.000000000 +0200
24778 @@ -0,0 +1,556 @@
24779 +/*
24780 + *  linux/kernel/vserver/switch.c
24781 + *
24782 + *  Virtual Server: Syscall Switch
24783 + *
24784 + *  Copyright (C) 2003-2011  Herbert Pötzl
24785 + *
24786 + *  V0.01  syscall switch
24787 + *  V0.02  added signal to context
24788 + *  V0.03  added rlimit functions
24789 + *  V0.04  added iattr, task/xid functions
24790 + *  V0.05  added debug/history stuff
24791 + *  V0.06  added compat32 layer
24792 + *  V0.07  vcmd args and perms
24793 + *  V0.08  added status commands
24794 + *  V0.09  added tag commands
24795 + *  V0.10  added oom bias
24796 + *  V0.11  added device commands
24797 + *  V0.12  added warn mask
24798 + *
24799 + */
24800 +
24801 +#include <linux/vs_context.h>
24802 +#include <linux/vs_network.h>
24803 +#include <linux/vserver/switch.h>
24804 +
24805 +#include "vci_config.h"
24806 +
24807 +
24808 +static inline
24809 +int vc_get_version(uint32_t id)
24810 +{
24811 +       return VCI_VERSION;
24812 +}
24813 +
24814 +static inline
24815 +int vc_get_vci(uint32_t id)
24816 +{
24817 +       return vci_kernel_config();
24818 +}
24819 +
24820 +#include <linux/vserver/context_cmd.h>
24821 +#include <linux/vserver/cvirt_cmd.h>
24822 +#include <linux/vserver/cacct_cmd.h>
24823 +#include <linux/vserver/limit_cmd.h>
24824 +#include <linux/vserver/network_cmd.h>
24825 +#include <linux/vserver/sched_cmd.h>
24826 +#include <linux/vserver/debug_cmd.h>
24827 +#include <linux/vserver/inode_cmd.h>
24828 +#include <linux/vserver/dlimit_cmd.h>
24829 +#include <linux/vserver/signal_cmd.h>
24830 +#include <linux/vserver/space_cmd.h>
24831 +#include <linux/vserver/tag_cmd.h>
24832 +#include <linux/vserver/device_cmd.h>
24833 +
24834 +#include <linux/vserver/inode.h>
24835 +#include <linux/vserver/dlimit.h>
24836 +
24837 +
24838 +#ifdef CONFIG_COMPAT
24839 +#define __COMPAT(name, id, data, compat)       \
24840 +       (compat) ? name ## _x32(id, data) : name(id, data)
24841 +#define __COMPAT_NO_ID(name, data, compat)     \
24842 +       (compat) ? name ## _x32(data) : name(data)
24843 +#else
24844 +#define __COMPAT(name, id, data, compat)       \
24845 +       name(id, data)
24846 +#define __COMPAT_NO_ID(name, data, compat)     \
24847 +       name(data)
24848 +#endif
24849 +
24850 +
24851 +static inline
24852 +long do_vcmd(uint32_t cmd, uint32_t id,
24853 +       struct vx_info *vxi, struct nx_info *nxi,
24854 +       void __user *data, int compat)
24855 +{
24856 +       switch (cmd) {
24857 +
24858 +       case VCMD_get_version:
24859 +               return vc_get_version(id);
24860 +       case VCMD_get_vci:
24861 +               return vc_get_vci(id);
24862 +
24863 +       case VCMD_task_xid:
24864 +               return vc_task_xid(id);
24865 +       case VCMD_vx_info:
24866 +               return vc_vx_info(vxi, data);
24867 +
24868 +       case VCMD_task_nid:
24869 +               return vc_task_nid(id);
24870 +       case VCMD_nx_info:
24871 +               return vc_nx_info(nxi, data);
24872 +
24873 +       case VCMD_task_tag:
24874 +               return vc_task_tag(id);
24875 +
24876 +       case VCMD_set_space_v1:
24877 +               return vc_set_space_v1(vxi, data);
24878 +       /* this is version 2 */
24879 +       case VCMD_set_space:
24880 +               return vc_set_space(vxi, data);
24881 +
24882 +       case VCMD_get_space_mask_v0:
24883 +               return vc_get_space_mask(data, 0);
24884 +       /* this is version 1 */
24885 +       case VCMD_get_space_mask:
24886 +               return vc_get_space_mask(data, 1);
24887 +
24888 +       case VCMD_get_space_default:
24889 +               return vc_get_space_mask(data, -1);
24890 +
24891 +       case VCMD_set_umask:
24892 +               return vc_set_umask(vxi, data);
24893 +
24894 +       case VCMD_get_umask:
24895 +               return vc_get_umask(vxi, data);
24896 +
24897 +       case VCMD_set_wmask:
24898 +               return vc_set_wmask(vxi, data);
24899 +
24900 +       case VCMD_get_wmask:
24901 +               return vc_get_wmask(vxi, data);
24902 +#ifdef CONFIG_IA32_EMULATION
24903 +       case VCMD_get_rlimit:
24904 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
24905 +       case VCMD_set_rlimit:
24906 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
24907 +#else
24908 +       case VCMD_get_rlimit:
24909 +               return vc_get_rlimit(vxi, data);
24910 +       case VCMD_set_rlimit:
24911 +               return vc_set_rlimit(vxi, data);
24912 +#endif
24913 +       case VCMD_get_rlimit_mask:
24914 +               return vc_get_rlimit_mask(id, data);
24915 +       case VCMD_reset_hits:
24916 +               return vc_reset_hits(vxi, data);
24917 +       case VCMD_reset_minmax:
24918 +               return vc_reset_minmax(vxi, data);
24919 +
24920 +       case VCMD_get_vhi_name:
24921 +               return vc_get_vhi_name(vxi, data);
24922 +       case VCMD_set_vhi_name:
24923 +               return vc_set_vhi_name(vxi, data);
24924 +
24925 +       case VCMD_ctx_stat:
24926 +               return vc_ctx_stat(vxi, data);
24927 +       case VCMD_virt_stat:
24928 +               return vc_virt_stat(vxi, data);
24929 +       case VCMD_sock_stat:
24930 +               return vc_sock_stat(vxi, data);
24931 +       case VCMD_rlimit_stat:
24932 +               return vc_rlimit_stat(vxi, data);
24933 +
24934 +       case VCMD_set_cflags:
24935 +               return vc_set_cflags(vxi, data);
24936 +       case VCMD_get_cflags:
24937 +               return vc_get_cflags(vxi, data);
24938 +
24939 +       /* this is version 1 */
24940 +       case VCMD_set_ccaps:
24941 +               return vc_set_ccaps(vxi, data);
24942 +       /* this is version 1 */
24943 +       case VCMD_get_ccaps:
24944 +               return vc_get_ccaps(vxi, data);
24945 +       case VCMD_set_bcaps:
24946 +               return vc_set_bcaps(vxi, data);
24947 +       case VCMD_get_bcaps:
24948 +               return vc_get_bcaps(vxi, data);
24949 +
24950 +       case VCMD_set_badness:
24951 +               return vc_set_badness(vxi, data);
24952 +       case VCMD_get_badness:
24953 +               return vc_get_badness(vxi, data);
24954 +
24955 +       case VCMD_set_nflags:
24956 +               return vc_set_nflags(nxi, data);
24957 +       case VCMD_get_nflags:
24958 +               return vc_get_nflags(nxi, data);
24959 +
24960 +       case VCMD_set_ncaps:
24961 +               return vc_set_ncaps(nxi, data);
24962 +       case VCMD_get_ncaps:
24963 +               return vc_get_ncaps(nxi, data);
24964 +
24965 +       case VCMD_set_prio_bias:
24966 +               return vc_set_prio_bias(vxi, data);
24967 +       case VCMD_get_prio_bias:
24968 +               return vc_get_prio_bias(vxi, data);
24969 +       case VCMD_add_dlimit:
24970 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24971 +       case VCMD_rem_dlimit:
24972 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24973 +       case VCMD_set_dlimit:
24974 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24975 +       case VCMD_get_dlimit:
24976 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24977 +
24978 +       case VCMD_ctx_kill:
24979 +               return vc_ctx_kill(vxi, data);
24980 +
24981 +       case VCMD_wait_exit:
24982 +               return vc_wait_exit(vxi, data);
24983 +
24984 +       case VCMD_get_iattr:
24985 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24986 +       case VCMD_set_iattr:
24987 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24988 +
24989 +       case VCMD_fget_iattr:
24990 +               return vc_fget_iattr(id, data);
24991 +       case VCMD_fset_iattr:
24992 +               return vc_fset_iattr(id, data);
24993 +
24994 +       case VCMD_enter_space_v0:
24995 +               return vc_enter_space_v1(vxi, NULL);
24996 +       case VCMD_enter_space_v1:
24997 +               return vc_enter_space_v1(vxi, data);
24998 +       /* this is version 2 */
24999 +       case VCMD_enter_space:
25000 +               return vc_enter_space(vxi, data);
25001 +
25002 +       case VCMD_ctx_create_v0:
25003 +               return vc_ctx_create(id, NULL);
25004 +       case VCMD_ctx_create:
25005 +               return vc_ctx_create(id, data);
25006 +       case VCMD_ctx_migrate_v0:
25007 +               return vc_ctx_migrate(vxi, NULL);
25008 +       case VCMD_ctx_migrate:
25009 +               return vc_ctx_migrate(vxi, data);
25010 +
25011 +       case VCMD_net_create_v0:
25012 +               return vc_net_create(id, NULL);
25013 +       case VCMD_net_create:
25014 +               return vc_net_create(id, data);
25015 +       case VCMD_net_migrate:
25016 +               return vc_net_migrate(nxi, data);
25017 +
25018 +       case VCMD_tag_migrate:
25019 +               return vc_tag_migrate(id);
25020 +
25021 +       case VCMD_net_add:
25022 +               return vc_net_add(nxi, data);
25023 +       case VCMD_net_remove:
25024 +               return vc_net_remove(nxi, data);
25025 +
25026 +       case VCMD_net_add_ipv4_v1:
25027 +               return vc_net_add_ipv4_v1(nxi, data);
25028 +       /* this is version 2 */
25029 +       case VCMD_net_add_ipv4:
25030 +               return vc_net_add_ipv4(nxi, data);
25031 +
25032 +       case VCMD_net_rem_ipv4_v1:
25033 +               return vc_net_rem_ipv4_v1(nxi, data);
25034 +       /* this is version 2 */
25035 +       case VCMD_net_rem_ipv4:
25036 +               return vc_net_rem_ipv4(nxi, data);
25037 +#ifdef CONFIG_IPV6
25038 +       case VCMD_net_add_ipv6:
25039 +               return vc_net_add_ipv6(nxi, data);
25040 +       case VCMD_net_remove_ipv6:
25041 +               return vc_net_remove_ipv6(nxi, data);
25042 +#endif
25043 +/*     case VCMD_add_match_ipv4:
25044 +               return vc_add_match_ipv4(nxi, data);
25045 +       case VCMD_get_match_ipv4:
25046 +               return vc_get_match_ipv4(nxi, data);
25047 +#ifdef CONFIG_IPV6
25048 +       case VCMD_add_match_ipv6:
25049 +               return vc_add_match_ipv6(nxi, data);
25050 +       case VCMD_get_match_ipv6:
25051 +               return vc_get_match_ipv6(nxi, data);
25052 +#endif */
25053 +
25054 +#ifdef CONFIG_VSERVER_DEVICE
25055 +       case VCMD_set_mapping:
25056 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25057 +       case VCMD_unset_mapping:
25058 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25059 +#endif
25060 +#ifdef CONFIG_VSERVER_HISTORY
25061 +       case VCMD_dump_history:
25062 +               return vc_dump_history(id);
25063 +       case VCMD_read_history:
25064 +               return __COMPAT(vc_read_history, id, data, compat);
25065 +#endif
25066 +       default:
25067 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25068 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25069 +       }
25070 +       return -ENOSYS;
25071 +}
25072 +
25073 +
25074 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25075 +       case VCMD_ ## vcmd: perm = _perm;               \
25076 +               args = _args; flags = _flags; break
25077 +
25078 +
25079 +#define VCA_NONE       0x00
25080 +#define VCA_VXI                0x01
25081 +#define VCA_NXI                0x02
25082 +
25083 +#define VCF_NONE       0x00
25084 +#define VCF_INFO       0x01
25085 +#define VCF_ADMIN      0x02
25086 +#define VCF_ARES       0x06    /* includes admin */
25087 +#define VCF_SETUP      0x08
25088 +
25089 +#define VCF_ZIDOK      0x10    /* zero id okay */
25090 +
25091 +
25092 +static inline
25093 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25094 +{
25095 +       long ret;
25096 +       int permit = -1, state = 0;
25097 +       int perm = -1, args = 0, flags = 0;
25098 +       struct vx_info *vxi = NULL;
25099 +       struct nx_info *nxi = NULL;
25100 +
25101 +       switch (cmd) {
25102 +       /* unpriviledged commands */
25103 +       __VCMD(get_version,      0, VCA_NONE,   0);
25104 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25105 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25106 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25107 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25108 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25109 +
25110 +       /* info commands */
25111 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25112 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
25113 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25114 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25115 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25116 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25117 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25118 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
25119 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
25120 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25121 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25122 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25123 +
25124 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25125 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25126 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25127 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25128 +
25129 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25130 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25131 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25132 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25133 +
25134 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25135 +
25136 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25137 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25138 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25139 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
25140 +
25141 +       /* lower admin commands */
25142 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25143 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25144 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25145 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25146 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25147 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25148 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25149 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25150 +
25151 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25152 +       __VCMD(net_create,       5, VCA_NONE,   0);
25153 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25154 +
25155 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25156 +
25157 +       /* higher admin commands */
25158 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25159 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25160 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25161 +
25162 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25163 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25164 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25165 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25166 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25167 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25168 +
25169 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25170 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25171 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25172 +
25173 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25174 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25175 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25176 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25177 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25178 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25179 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25180 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25181 +#ifdef CONFIG_IPV6
25182 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25183 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25184 +#endif
25185 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25186 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25187 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25188 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25189 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25190 +
25191 +#ifdef CONFIG_VSERVER_DEVICE
25192 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25193 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25194 +#endif
25195 +       /* debug level admin commands */
25196 +#ifdef CONFIG_VSERVER_HISTORY
25197 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25198 +       __VCMD(read_history,     9, VCA_NONE,   0);
25199 +#endif
25200 +
25201 +       default:
25202 +               perm = -1;
25203 +       }
25204 +
25205 +       vxdprintk(VXD_CBIT(switch, 0),
25206 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25207 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25208 +               VC_VERSION(cmd), id, data, compat,
25209 +               perm, args, flags);
25210 +
25211 +       ret = -ENOSYS;
25212 +       if (perm < 0)
25213 +               goto out;
25214 +
25215 +       state = 1;
25216 +       if (!capable(CAP_CONTEXT))
25217 +               goto out;
25218 +
25219 +       state = 2;
25220 +       /* moved here from the individual commands */
25221 +       ret = -EPERM;
25222 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25223 +               goto out;
25224 +
25225 +       state = 3;
25226 +       /* vcmd involves resource management  */
25227 +       ret = -EPERM;
25228 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25229 +               goto out;
25230 +
25231 +       state = 4;
25232 +       /* various legacy exceptions */
25233 +       switch (cmd) {
25234 +       /* will go away when spectator is a cap */
25235 +       case VCMD_ctx_migrate_v0:
25236 +       case VCMD_ctx_migrate:
25237 +               if (id == 1) {
25238 +                       current->xid = 1;
25239 +                       ret = 1;
25240 +                       goto out;
25241 +               }
25242 +               break;
25243 +
25244 +       /* will go away when spectator is a cap */
25245 +       case VCMD_net_migrate:
25246 +               if (id == 1) {
25247 +                       current->nid = 1;
25248 +                       ret = 1;
25249 +                       goto out;
25250 +               }
25251 +               break;
25252 +       }
25253 +
25254 +       /* vcmds are fine by default */
25255 +       permit = 1;
25256 +
25257 +       /* admin type vcmds require admin ... */
25258 +       if (flags & VCF_ADMIN)
25259 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25260 +
25261 +       /* ... but setup type vcmds override that */
25262 +       if (!permit && (flags & VCF_SETUP))
25263 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25264 +
25265 +       state = 5;
25266 +       ret = -EPERM;
25267 +       if (!permit)
25268 +               goto out;
25269 +
25270 +       state = 6;
25271 +       if (!id && (flags & VCF_ZIDOK))
25272 +               goto skip_id;
25273 +
25274 +       ret = -ESRCH;
25275 +       if (args & VCA_VXI) {
25276 +               vxi = lookup_vx_info(id);
25277 +               if (!vxi)
25278 +                       goto out;
25279 +
25280 +               if ((flags & VCF_ADMIN) &&
25281 +                       /* special case kill for shutdown */
25282 +                       (cmd != VCMD_ctx_kill) &&
25283 +                       /* can context be administrated? */
25284 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25285 +                       ret = -EACCES;
25286 +                       goto out_vxi;
25287 +               }
25288 +       }
25289 +       state = 7;
25290 +       if (args & VCA_NXI) {
25291 +               nxi = lookup_nx_info(id);
25292 +               if (!nxi)
25293 +                       goto out_vxi;
25294 +
25295 +               if ((flags & VCF_ADMIN) &&
25296 +                       /* can context be administrated? */
25297 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25298 +                       ret = -EACCES;
25299 +                       goto out_nxi;
25300 +               }
25301 +       }
25302 +skip_id:
25303 +       state = 8;
25304 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25305 +
25306 +out_nxi:
25307 +       if ((args & VCA_NXI) && nxi)
25308 +               put_nx_info(nxi);
25309 +out_vxi:
25310 +       if ((args & VCA_VXI) && vxi)
25311 +               put_vx_info(vxi);
25312 +out:
25313 +       vxdprintk(VXD_CBIT(switch, 1),
25314 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25315 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25316 +               VC_VERSION(cmd), ret, ret, state, permit);
25317 +       return ret;
25318 +}
25319 +
25320 +asmlinkage long
25321 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25322 +{
25323 +       return do_vserver(cmd, id, data, 0);
25324 +}
25325 +
25326 +#ifdef CONFIG_COMPAT
25327 +
25328 +asmlinkage long
25329 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25330 +{
25331 +       return do_vserver(cmd, id, data, 1);
25332 +}
25333 +
25334 +#endif /* CONFIG_COMPAT */
25335 diff -NurpP --minimal linux-3.1/kernel/vserver/sysctl.c linux-3.1-vs2.3.1-rc2/kernel/vserver/sysctl.c
25336 --- linux-3.1/kernel/vserver/sysctl.c   1970-01-01 01:00:00.000000000 +0100
25337 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/sysctl.c       2011-10-24 18:53:33.000000000 +0200
25338 @@ -0,0 +1,241 @@
25339 +/*
25340 + *  kernel/vserver/sysctl.c
25341 + *
25342 + *  Virtual Context Support
25343 + *
25344 + *  Copyright (C) 2004-2007  Herbert Pötzl
25345 + *
25346 + *  V0.01  basic structure
25347 + *
25348 + */
25349 +
25350 +#include <linux/module.h>
25351 +#include <linux/ctype.h>
25352 +#include <linux/sysctl.h>
25353 +#include <linux/parser.h>
25354 +#include <asm/uaccess.h>
25355 +
25356 +enum {
25357 +       CTL_DEBUG_ERROR         = 0,
25358 +       CTL_DEBUG_SWITCH        = 1,
25359 +       CTL_DEBUG_XID,
25360 +       CTL_DEBUG_NID,
25361 +       CTL_DEBUG_TAG,
25362 +       CTL_DEBUG_NET,
25363 +       CTL_DEBUG_LIMIT,
25364 +       CTL_DEBUG_CRES,
25365 +       CTL_DEBUG_DLIM,
25366 +       CTL_DEBUG_QUOTA,
25367 +       CTL_DEBUG_CVIRT,
25368 +       CTL_DEBUG_SPACE,
25369 +       CTL_DEBUG_MISC,
25370 +};
25371 +
25372 +
25373 +unsigned int vx_debug_switch   = 0;
25374 +unsigned int vx_debug_xid      = 0;
25375 +unsigned int vx_debug_nid      = 0;
25376 +unsigned int vx_debug_tag      = 0;
25377 +unsigned int vx_debug_net      = 0;
25378 +unsigned int vx_debug_limit    = 0;
25379 +unsigned int vx_debug_cres     = 0;
25380 +unsigned int vx_debug_dlim     = 0;
25381 +unsigned int vx_debug_quota    = 0;
25382 +unsigned int vx_debug_cvirt    = 0;
25383 +unsigned int vx_debug_space    = 0;
25384 +unsigned int vx_debug_misc     = 0;
25385 +
25386 +
25387 +static struct ctl_table_header *vserver_table_header;
25388 +static ctl_table vserver_root_table[];
25389 +
25390 +
25391 +void vserver_register_sysctl(void)
25392 +{
25393 +       if (!vserver_table_header) {
25394 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25395 +       }
25396 +
25397 +}
25398 +
25399 +void vserver_unregister_sysctl(void)
25400 +{
25401 +       if (vserver_table_header) {
25402 +               unregister_sysctl_table(vserver_table_header);
25403 +               vserver_table_header = NULL;
25404 +       }
25405 +}
25406 +
25407 +
25408 +static int proc_dodebug(ctl_table *table, int write,
25409 +       void __user *buffer, size_t *lenp, loff_t *ppos)
25410 +{
25411 +       char            tmpbuf[20], *p, c;
25412 +       unsigned int    value;
25413 +       size_t          left, len;
25414 +
25415 +       if ((*ppos && !write) || !*lenp) {
25416 +               *lenp = 0;
25417 +               return 0;
25418 +       }
25419 +
25420 +       left = *lenp;
25421 +
25422 +       if (write) {
25423 +               if (!access_ok(VERIFY_READ, buffer, left))
25424 +                       return -EFAULT;
25425 +               p = (char *)buffer;
25426 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25427 +                       left--, p++;
25428 +               if (!left)
25429 +                       goto done;
25430 +
25431 +               if (left > sizeof(tmpbuf) - 1)
25432 +                       return -EINVAL;
25433 +               if (copy_from_user(tmpbuf, p, left))
25434 +                       return -EFAULT;
25435 +               tmpbuf[left] = '\0';
25436 +
25437 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25438 +                       value = 10 * value + (*p - '0');
25439 +               if (*p && !isspace(*p))
25440 +                       return -EINVAL;
25441 +               while (left && isspace(*p))
25442 +                       left--, p++;
25443 +               *(unsigned int *)table->data = value;
25444 +       } else {
25445 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25446 +                       return -EFAULT;
25447 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25448 +               if (len > left)
25449 +                       len = left;
25450 +               if (__copy_to_user(buffer, tmpbuf, len))
25451 +                       return -EFAULT;
25452 +               if ((left -= len) > 0) {
25453 +                       if (put_user('\n', (char *)buffer + len))
25454 +                               return -EFAULT;
25455 +                       left--;
25456 +               }
25457 +       }
25458 +
25459 +done:
25460 +       *lenp -= left;
25461 +       *ppos += *lenp;
25462 +       return 0;
25463 +}
25464 +
25465 +static int zero;
25466 +
25467 +#define        CTL_ENTRY(ctl, name)                            \
25468 +       {                                               \
25469 +               .procname       = #name,                \
25470 +               .data           = &vx_ ## name,         \
25471 +               .maxlen         = sizeof(int),          \
25472 +               .mode           = 0644,                 \
25473 +               .proc_handler   = &proc_dodebug,        \
25474 +               .extra1         = &zero,                \
25475 +               .extra2         = &zero,                \
25476 +       }
25477 +
25478 +static ctl_table vserver_debug_table[] = {
25479 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25480 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25481 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25482 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25483 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25484 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25485 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25486 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25487 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25488 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25489 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25490 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25491 +       { 0 }
25492 +};
25493 +
25494 +static ctl_table vserver_root_table[] = {
25495 +       {
25496 +               .procname       = "vserver",
25497 +               .mode           = 0555,
25498 +               .child          = vserver_debug_table
25499 +       },
25500 +       { 0 }
25501 +};
25502 +
25503 +
25504 +static match_table_t tokens = {
25505 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25506 +       { CTL_DEBUG_XID,        "xid=%x"        },
25507 +       { CTL_DEBUG_NID,        "nid=%x"        },
25508 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25509 +       { CTL_DEBUG_NET,        "net=%x"        },
25510 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25511 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25512 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25513 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25514 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25515 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25516 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25517 +       { CTL_DEBUG_ERROR,      NULL            }
25518 +};
25519 +
25520 +#define        HANDLE_CASE(id, name, val)                              \
25521 +       case CTL_DEBUG_ ## id:                                  \
25522 +               vx_debug_ ## name = val;                        \
25523 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25524 +               break
25525 +
25526 +
25527 +static int __init vs_debug_setup(char *str)
25528 +{
25529 +       char *p;
25530 +       int token;
25531 +
25532 +       printk("vs_debug_setup(%s)\n", str);
25533 +       while ((p = strsep(&str, ",")) != NULL) {
25534 +               substring_t args[MAX_OPT_ARGS];
25535 +               unsigned int value;
25536 +
25537 +               if (!*p)
25538 +                       continue;
25539 +
25540 +               token = match_token(p, tokens, args);
25541 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25542 +
25543 +               switch (token) {
25544 +               HANDLE_CASE(SWITCH, switch, value);
25545 +               HANDLE_CASE(XID,    xid,    value);
25546 +               HANDLE_CASE(NID,    nid,    value);
25547 +               HANDLE_CASE(TAG,    tag,    value);
25548 +               HANDLE_CASE(NET,    net,    value);
25549 +               HANDLE_CASE(LIMIT,  limit,  value);
25550 +               HANDLE_CASE(CRES,   cres,   value);
25551 +               HANDLE_CASE(DLIM,   dlim,   value);
25552 +               HANDLE_CASE(QUOTA,  quota,  value);
25553 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25554 +               HANDLE_CASE(SPACE,  space,  value);
25555 +               HANDLE_CASE(MISC,   misc,   value);
25556 +               default:
25557 +                       return -EINVAL;
25558 +                       break;
25559 +               }
25560 +       }
25561 +       return 1;
25562 +}
25563 +
25564 +__setup("vsdebug=", vs_debug_setup);
25565 +
25566 +
25567 +
25568 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25569 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25570 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25571 +EXPORT_SYMBOL_GPL(vx_debug_net);
25572 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25573 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25574 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25575 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25576 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25577 +EXPORT_SYMBOL_GPL(vx_debug_space);
25578 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25579 +
25580 diff -NurpP --minimal linux-3.1/kernel/vserver/tag.c linux-3.1-vs2.3.1-rc2/kernel/vserver/tag.c
25581 --- linux-3.1/kernel/vserver/tag.c      1970-01-01 01:00:00.000000000 +0100
25582 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/tag.c  2011-10-24 18:53:33.000000000 +0200
25583 @@ -0,0 +1,63 @@
25584 +/*
25585 + *  linux/kernel/vserver/tag.c
25586 + *
25587 + *  Virtual Server: Shallow Tag Space
25588 + *
25589 + *  Copyright (C) 2007  Herbert Pötzl
25590 + *
25591 + *  V0.01  basic implementation
25592 + *
25593 + */
25594 +
25595 +#include <linux/sched.h>
25596 +#include <linux/vserver/debug.h>
25597 +#include <linux/vs_pid.h>
25598 +#include <linux/vs_tag.h>
25599 +
25600 +#include <linux/vserver/tag_cmd.h>
25601 +
25602 +
25603 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25604 +{
25605 +       if (!p)
25606 +               BUG();
25607 +
25608 +       vxdprintk(VXD_CBIT(tag, 5),
25609 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25610 +
25611 +       task_lock(p);
25612 +       p->tag = tag;
25613 +       task_unlock(p);
25614 +
25615 +       vxdprintk(VXD_CBIT(tag, 5),
25616 +               "moved task %p into [#%d]", p, tag);
25617 +       return 0;
25618 +}
25619 +
25620 +/* vserver syscall commands below here */
25621 +
25622 +/* taks xid and vx_info functions */
25623 +
25624 +
25625 +int vc_task_tag(uint32_t id)
25626 +{
25627 +       tag_t tag;
25628 +
25629 +       if (id) {
25630 +               struct task_struct *tsk;
25631 +               rcu_read_lock();
25632 +               tsk = find_task_by_real_pid(id);
25633 +               tag = (tsk) ? tsk->tag : -ESRCH;
25634 +               rcu_read_unlock();
25635 +       } else
25636 +               tag = dx_current_tag();
25637 +       return tag;
25638 +}
25639 +
25640 +
25641 +int vc_tag_migrate(uint32_t tag)
25642 +{
25643 +       return dx_migrate_task(current, tag & 0xFFFF);
25644 +}
25645 +
25646 +
25647 diff -NurpP --minimal linux-3.1/kernel/vserver/vci_config.h linux-3.1-vs2.3.1-rc2/kernel/vserver/vci_config.h
25648 --- linux-3.1/kernel/vserver/vci_config.h       1970-01-01 01:00:00.000000000 +0100
25649 +++ linux-3.1-vs2.3.1-rc2/kernel/vserver/vci_config.h   2011-10-24 18:53:33.000000000 +0200
25650 @@ -0,0 +1,76 @@
25651 +
25652 +/*  interface version */
25653 +
25654 +#define VCI_VERSION            0x00020308
25655 +
25656 +
25657 +enum {
25658 +       VCI_KCBIT_NO_DYNAMIC = 0,
25659 +
25660 +       VCI_KCBIT_PROC_SECURE = 4,
25661 +       /* VCI_KCBIT_HARDCPU = 5, */
25662 +       /* VCI_KCBIT_IDLELIMIT = 6, */
25663 +       /* VCI_KCBIT_IDLETIME = 7, */
25664 +
25665 +       VCI_KCBIT_COWBL = 8,
25666 +       VCI_KCBIT_FULLCOWBL = 9,
25667 +       VCI_KCBIT_SPACES = 10,
25668 +       VCI_KCBIT_NETV2 = 11,
25669 +       VCI_KCBIT_MEMCG = 12,
25670 +
25671 +       VCI_KCBIT_DEBUG = 16,
25672 +       VCI_KCBIT_HISTORY = 20,
25673 +       VCI_KCBIT_TAGGED = 24,
25674 +       VCI_KCBIT_PPTAG = 28,
25675 +
25676 +       VCI_KCBIT_MORE = 31,
25677 +};
25678 +
25679 +
25680 +static inline uint32_t vci_kernel_config(void)
25681 +{
25682 +       return
25683 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25684 +
25685 +       /* configured features */
25686 +#ifdef CONFIG_VSERVER_PROC_SECURE
25687 +       (1 << VCI_KCBIT_PROC_SECURE) |
25688 +#endif
25689 +#ifdef CONFIG_VSERVER_COWBL
25690 +       (1 << VCI_KCBIT_COWBL) |
25691 +       (1 << VCI_KCBIT_FULLCOWBL) |
25692 +#endif
25693 +       (1 << VCI_KCBIT_SPACES) |
25694 +       (1 << VCI_KCBIT_NETV2) |
25695 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
25696 +       (1 << VCI_KCBIT_MEMCG) |
25697 +#endif
25698 +
25699 +       /* debug options */
25700 +#ifdef CONFIG_VSERVER_DEBUG
25701 +       (1 << VCI_KCBIT_DEBUG) |
25702 +#endif
25703 +#ifdef CONFIG_VSERVER_HISTORY
25704 +       (1 << VCI_KCBIT_HISTORY) |
25705 +#endif
25706 +
25707 +       /* inode context tagging */
25708 +#if    defined(CONFIG_TAGGING_NONE)
25709 +       (0 << VCI_KCBIT_TAGGED) |
25710 +#elif  defined(CONFIG_TAGGING_UID16)
25711 +       (1 << VCI_KCBIT_TAGGED) |
25712 +#elif  defined(CONFIG_TAGGING_GID16)
25713 +       (2 << VCI_KCBIT_TAGGED) |
25714 +#elif  defined(CONFIG_TAGGING_ID24)
25715 +       (3 << VCI_KCBIT_TAGGED) |
25716 +#elif  defined(CONFIG_TAGGING_INTERN)
25717 +       (4 << VCI_KCBIT_TAGGED) |
25718 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25719 +       (5 << VCI_KCBIT_TAGGED) |
25720 +#else
25721 +       (7 << VCI_KCBIT_TAGGED) |
25722 +#endif
25723 +       (1 << VCI_KCBIT_PPTAG) |
25724 +       0;
25725 +}
25726 +
25727 diff -NurpP --minimal linux-3.1/mm/filemap_xip.c linux-3.1-vs2.3.1-rc2/mm/filemap_xip.c
25728 --- linux-3.1/mm/filemap_xip.c  2011-07-22 11:18:12.000000000 +0200
25729 +++ linux-3.1-vs2.3.1-rc2/mm/filemap_xip.c      2011-10-24 18:53:33.000000000 +0200
25730 @@ -18,6 +18,7 @@
25731  #include <linux/seqlock.h>
25732  #include <linux/mutex.h>
25733  #include <linux/gfp.h>
25734 +#include <linux/vs_memory.h>
25735  #include <asm/tlbflush.h>
25736  #include <asm/io.h>
25737  
25738 diff -NurpP --minimal linux-3.1/mm/fremap.c linux-3.1-vs2.3.1-rc2/mm/fremap.c
25739 --- linux-3.1/mm/fremap.c       2011-07-22 11:18:12.000000000 +0200
25740 +++ linux-3.1-vs2.3.1-rc2/mm/fremap.c   2011-10-24 18:53:33.000000000 +0200
25741 @@ -16,6 +16,7 @@
25742  #include <linux/module.h>
25743  #include <linux/syscalls.h>
25744  #include <linux/mmu_notifier.h>
25745 +#include <linux/vs_memory.h>
25746  
25747  #include <asm/mmu_context.h>
25748  #include <asm/cacheflush.h>
25749 diff -NurpP --minimal linux-3.1/mm/hugetlb.c linux-3.1-vs2.3.1-rc2/mm/hugetlb.c
25750 --- linux-3.1/mm/hugetlb.c      2011-10-24 18:45:33.000000000 +0200
25751 +++ linux-3.1-vs2.3.1-rc2/mm/hugetlb.c  2011-10-24 18:53:33.000000000 +0200
25752 @@ -28,6 +28,7 @@
25753  
25754  #include <linux/hugetlb.h>
25755  #include <linux/node.h>
25756 +#include <linux/vs_memory.h>
25757  #include "internal.h"
25758  
25759  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25760 diff -NurpP --minimal linux-3.1/mm/memcontrol.c linux-3.1-vs2.3.1-rc2/mm/memcontrol.c
25761 --- linux-3.1/mm/memcontrol.c   2011-10-24 18:45:33.000000000 +0200
25762 +++ linux-3.1-vs2.3.1-rc2/mm/memcontrol.c       2011-10-24 18:53:33.000000000 +0200
25763 @@ -760,6 +760,31 @@ struct mem_cgroup *mem_cgroup_from_task(
25764                                 struct mem_cgroup, css);
25765  }
25766  
25767 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
25768 +{
25769 +       return res_counter_read_u64(&mem->res, member);
25770 +}
25771 +
25772 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
25773 +{
25774 +       return res_counter_read_u64(&mem->memsw, member);
25775 +}
25776 +
25777 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
25778 +{
25779 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
25780 +}
25781 +
25782 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
25783 +{
25784 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
25785 +}
25786 +
25787 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
25788 +{
25789 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
25790 +}
25791 +
25792  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
25793  {
25794         struct mem_cgroup *mem = NULL;
25795 diff -NurpP --minimal linux-3.1/mm/memory.c linux-3.1-vs2.3.1-rc2/mm/memory.c
25796 --- linux-3.1/mm/memory.c       2011-10-24 18:45:33.000000000 +0200
25797 +++ linux-3.1-vs2.3.1-rc2/mm/memory.c   2011-10-24 18:53:33.000000000 +0200
25798 @@ -3389,6 +3389,7 @@ int handle_pte_fault(struct mm_struct *m
25799  {
25800         pte_t entry;
25801         spinlock_t *ptl;
25802 +       int ret = 0, type = VXPT_UNKNOWN;
25803  
25804         entry = *pte;
25805         if (!pte_present(entry)) {
25806 @@ -3413,9 +3414,12 @@ int handle_pte_fault(struct mm_struct *m
25807         if (unlikely(!pte_same(*pte, entry)))
25808                 goto unlock;
25809         if (flags & FAULT_FLAG_WRITE) {
25810 -               if (!pte_write(entry))
25811 -                       return do_wp_page(mm, vma, address,
25812 +               if (!pte_write(entry)) {
25813 +                       ret = do_wp_page(mm, vma, address,
25814                                         pte, pmd, ptl, entry);
25815 +                       type = VXPT_WRITE;
25816 +                       goto out;
25817 +               }
25818                 entry = pte_mkdirty(entry);
25819         }
25820         entry = pte_mkyoung(entry);
25821 @@ -3433,7 +3437,10 @@ int handle_pte_fault(struct mm_struct *m
25822         }
25823  unlock:
25824         pte_unmap_unlock(pte, ptl);
25825 -       return 0;
25826 +       ret = 0;
25827 +out:
25828 +       vx_page_fault(mm, vma, type, ret);
25829 +       return ret;
25830  }
25831  
25832  /*
25833 diff -NurpP --minimal linux-3.1/mm/mremap.c linux-3.1-vs2.3.1-rc2/mm/mremap.c
25834 --- linux-3.1/mm/mremap.c       2011-07-22 11:18:12.000000000 +0200
25835 +++ linux-3.1-vs2.3.1-rc2/mm/mremap.c   2011-10-24 18:53:33.000000000 +0200
25836 @@ -19,6 +19,7 @@
25837  #include <linux/security.h>
25838  #include <linux/syscalls.h>
25839  #include <linux/mmu_notifier.h>
25840 +#include <linux/vs_memory.h>
25841  
25842  #include <asm/uaccess.h>
25843  #include <asm/cacheflush.h>
25844 diff -NurpP --minimal linux-3.1/mm/oom_kill.c linux-3.1-vs2.3.1-rc2/mm/oom_kill.c
25845 --- linux-3.1/mm/oom_kill.c     2011-10-24 18:45:33.000000000 +0200
25846 +++ linux-3.1-vs2.3.1-rc2/mm/oom_kill.c 2011-10-24 18:53:33.000000000 +0200
25847 @@ -32,6 +32,9 @@
25848  #include <linux/mempolicy.h>
25849  #include <linux/security.h>
25850  #include <linux/ptrace.h>
25851 +#include <linux/reboot.h>
25852 +#include <linux/vs_memory.h>
25853 +#include <linux/vs_context.h>
25854  
25855  int sysctl_panic_on_oom;
25856  int sysctl_oom_kill_allocating_task;
25857 @@ -134,11 +137,18 @@ struct task_struct *find_lock_task_mm(st
25858  static bool oom_unkillable_task(struct task_struct *p,
25859                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
25860  {
25861 -       if (is_global_init(p))
25862 +       unsigned xid = vx_current_xid();
25863 +
25864 +       /* skip the init task, global and per guest */
25865 +       if (task_is_init(p))
25866                 return true;
25867         if (p->flags & PF_KTHREAD)
25868                 return true;
25869  
25870 +       /* skip other guest and host processes if oom in guest */
25871 +       if (xid && vx_task_xid(p) != xid)
25872 +               return true;
25873 +
25874         /* When mem_cgroup_out_of_memory() and p is not member of the group */
25875         if (mem && !task_in_mem_cgroup(p, mem))
25876                 return true;
25877 @@ -214,6 +224,18 @@ unsigned int oom_badness(struct task_str
25878         points += p->signal->oom_score_adj;
25879  
25880         /*
25881 +        * add points for context badness and
25882 +        * reduce badness for processes belonging to
25883 +        * a different context
25884 +        */
25885 +
25886 +       points += vx_badness(p, p->mm);
25887 +
25888 +       if ((vx_current_xid() > 1) &&
25889 +               vx_current_xid() != vx_task_xid(p))
25890 +               points /= 16;
25891 +
25892 +       /*
25893          * Never return 0 for an eligible task that may be killed since it's
25894          * possible that no single user task uses more than 0.1% of memory and
25895          * no single admin tasks uses more than 3.0%.
25896 @@ -428,8 +450,8 @@ static int oom_kill_task(struct task_str
25897         /* mm cannot be safely dereferenced after task_unlock(p) */
25898         mm = p->mm;
25899  
25900 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
25901 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
25902 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
25903 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
25904                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
25905                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
25906         task_unlock(p);
25907 @@ -483,8 +505,8 @@ static int oom_kill_process(struct task_
25908         }
25909  
25910         task_lock(p);
25911 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
25912 -               message, task_pid_nr(p), p->comm, points);
25913 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
25914 +               message, task_pid_nr(p), p->xid, p->comm, points);
25915         task_unlock(p);
25916  
25917         /*
25918 @@ -585,6 +607,8 @@ int unregister_oom_notifier(struct notif
25919  }
25920  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
25921  
25922 +long vs_oom_action(unsigned int);
25923 +
25924  /*
25925   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
25926   * if a parallel OOM killing is already taking place that includes a zone in
25927 @@ -743,7 +767,12 @@ retry:
25928         if (!p) {
25929                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
25930                 read_unlock(&tasklist_lock);
25931 -               panic("Out of memory and no killable processes...\n");
25932 +
25933 +               /* avoid panic for guest OOM */
25934 +               if (current->xid)
25935 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
25936 +               else
25937 +                       panic("Out of memory and no killable processes...\n");
25938         }
25939  
25940         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
25941 diff -NurpP --minimal linux-3.1/mm/page_alloc.c linux-3.1-vs2.3.1-rc2/mm/page_alloc.c
25942 --- linux-3.1/mm/page_alloc.c   2011-10-24 18:45:33.000000000 +0200
25943 +++ linux-3.1-vs2.3.1-rc2/mm/page_alloc.c       2011-10-24 18:53:33.000000000 +0200
25944 @@ -57,6 +57,8 @@
25945  #include <linux/ftrace_event.h>
25946  #include <linux/memcontrol.h>
25947  #include <linux/prefetch.h>
25948 +#include <linux/vs_base.h>
25949 +#include <linux/vs_limit.h>
25950  
25951  #include <asm/tlbflush.h>
25952  #include <asm/div64.h>
25953 @@ -2484,6 +2486,9 @@ void si_meminfo(struct sysinfo *val)
25954         val->totalhigh = totalhigh_pages;
25955         val->freehigh = nr_free_highpages();
25956         val->mem_unit = PAGE_SIZE;
25957 +
25958 +       if (vx_flags(VXF_VIRT_MEM, 0))
25959 +               vx_vsi_meminfo(val);
25960  }
25961  
25962  EXPORT_SYMBOL(si_meminfo);
25963 @@ -2504,6 +2509,9 @@ void si_meminfo_node(struct sysinfo *val
25964         val->freehigh = 0;
25965  #endif
25966         val->mem_unit = PAGE_SIZE;
25967 +
25968 +       if (vx_flags(VXF_VIRT_MEM, 0))
25969 +               vx_vsi_meminfo(val);
25970  }
25971  #endif
25972  
25973 diff -NurpP --minimal linux-3.1/mm/pgtable-generic.c linux-3.1-vs2.3.1-rc2/mm/pgtable-generic.c
25974 --- linux-3.1/mm/pgtable-generic.c      2011-03-15 18:07:42.000000000 +0100
25975 +++ linux-3.1-vs2.3.1-rc2/mm/pgtable-generic.c  2011-10-24 18:53:33.000000000 +0200
25976 @@ -6,6 +6,8 @@
25977   *  Copyright (C) 2010  Linus Torvalds
25978   */
25979  
25980 +#include <linux/mm.h>
25981 +
25982  #include <linux/pagemap.h>
25983  #include <asm/tlb.h>
25984  #include <asm-generic/pgtable.h>
25985 diff -NurpP --minimal linux-3.1/mm/rmap.c linux-3.1-vs2.3.1-rc2/mm/rmap.c
25986 --- linux-3.1/mm/rmap.c 2011-10-24 18:45:33.000000000 +0200
25987 +++ linux-3.1-vs2.3.1-rc2/mm/rmap.c     2011-10-24 18:53:33.000000000 +0200
25988 @@ -56,6 +56,7 @@
25989  #include <linux/mmu_notifier.h>
25990  #include <linux/migrate.h>
25991  #include <linux/hugetlb.h>
25992 +#include <linux/vs_memory.h>
25993  
25994  #include <asm/tlbflush.h>
25995  
25996 diff -NurpP --minimal linux-3.1/mm/shmem.c linux-3.1-vs2.3.1-rc2/mm/shmem.c
25997 --- linux-3.1/mm/shmem.c        2011-10-24 18:45:33.000000000 +0200
25998 +++ linux-3.1-vs2.3.1-rc2/mm/shmem.c    2011-10-24 18:53:33.000000000 +0200
25999 @@ -1429,7 +1429,7 @@ static int shmem_statfs(struct dentry *d
26000  {
26001         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26002  
26003 -       buf->f_type = TMPFS_MAGIC;
26004 +       buf->f_type = TMPFS_SUPER_MAGIC;
26005         buf->f_bsize = PAGE_CACHE_SIZE;
26006         buf->f_namelen = NAME_MAX;
26007         if (sbinfo->max_blocks) {
26008 @@ -2186,7 +2186,7 @@ int shmem_fill_super(struct super_block 
26009         sb->s_maxbytes = MAX_LFS_FILESIZE;
26010         sb->s_blocksize = PAGE_CACHE_SIZE;
26011         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26012 -       sb->s_magic = TMPFS_MAGIC;
26013 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26014         sb->s_op = &shmem_ops;
26015         sb->s_time_gran = 1;
26016  #ifdef CONFIG_TMPFS_XATTR
26017 diff -NurpP --minimal linux-3.1/mm/slab.c linux-3.1-vs2.3.1-rc2/mm/slab.c
26018 --- linux-3.1/mm/slab.c 2011-10-24 18:45:33.000000000 +0200
26019 +++ linux-3.1-vs2.3.1-rc2/mm/slab.c     2011-10-24 18:53:33.000000000 +0200
26020 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
26021  #define STATS_INC_FREEMISS(x)  do { } while (0)
26022  #endif
26023  
26024 +#include "slab_vs.h"
26025 +
26026  #if DEBUG
26027  
26028  /*
26029 @@ -3399,6 +3401,7 @@ retry:
26030  
26031         obj = slab_get_obj(cachep, slabp, nodeid);
26032         check_slabp(cachep, slabp);
26033 +       vx_slab_alloc(cachep, flags);
26034         l3->free_objects--;
26035         /* move slabp to correct slabp list: */
26036         list_del(&slabp->list);
26037 @@ -3476,6 +3479,7 @@ __cache_alloc_node(struct kmem_cache *ca
26038         /* ___cache_alloc_node can fall back to other nodes */
26039         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26040    out:
26041 +       vx_slab_alloc(cachep, flags);
26042         local_irq_restore(save_flags);
26043         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26044         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
26045 @@ -3663,6 +3667,7 @@ static inline void __cache_free(struct k
26046         check_irq_off();
26047         kmemleak_free_recursive(objp, cachep->flags);
26048         objp = cache_free_debugcheck(cachep, objp, caller);
26049 +       vx_slab_free(cachep);
26050  
26051         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
26052  
26053 diff -NurpP --minimal linux-3.1/mm/slab_vs.h linux-3.1-vs2.3.1-rc2/mm/slab_vs.h
26054 --- linux-3.1/mm/slab_vs.h      1970-01-01 01:00:00.000000000 +0100
26055 +++ linux-3.1-vs2.3.1-rc2/mm/slab_vs.h  2011-10-24 18:53:33.000000000 +0200
26056 @@ -0,0 +1,29 @@
26057 +
26058 +#include <linux/vserver/context.h>
26059 +
26060 +#include <linux/vs_context.h>
26061 +
26062 +static inline
26063 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26064 +{
26065 +       int what = gfp_zone(cachep->gfpflags);
26066 +       struct vx_info *vxi = current_vx_info();
26067 +
26068 +       if (!vxi)
26069 +               return;
26070 +
26071 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
26072 +}
26073 +
26074 +static inline
26075 +void vx_slab_free(struct kmem_cache *cachep)
26076 +{
26077 +       int what = gfp_zone(cachep->gfpflags);
26078 +       struct vx_info *vxi = current_vx_info();
26079 +
26080 +       if (!vxi)
26081 +               return;
26082 +
26083 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
26084 +}
26085 +
26086 diff -NurpP --minimal linux-3.1/mm/swapfile.c linux-3.1-vs2.3.1-rc2/mm/swapfile.c
26087 --- linux-3.1/mm/swapfile.c     2011-10-24 18:45:33.000000000 +0200
26088 +++ linux-3.1-vs2.3.1-rc2/mm/swapfile.c 2011-10-24 18:53:33.000000000 +0200
26089 @@ -37,6 +37,8 @@
26090  #include <asm/tlbflush.h>
26091  #include <linux/swapops.h>
26092  #include <linux/page_cgroup.h>
26093 +#include <linux/vs_base.h>
26094 +#include <linux/vs_memory.h>
26095  
26096  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
26097                                  unsigned char);
26098 @@ -1754,6 +1756,16 @@ static int swap_show(struct seq_file *sw
26099  
26100         if (si == SEQ_START_TOKEN) {
26101                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
26102 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
26103 +                       struct sysinfo si;
26104 +
26105 +                       vx_vsi_swapinfo(&si);
26106 +                       if (si.totalswap < (1 << 10))
26107 +                               return 0;
26108 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
26109 +                               "hdv0", "partition", si.totalswap >> 10,
26110 +                               (si.totalswap - si.freeswap) >> 10, -1);
26111 +               }
26112                 return 0;
26113         }
26114  
26115 @@ -2177,6 +2189,8 @@ void si_swapinfo(struct sysinfo *val)
26116         val->freeswap = nr_swap_pages + nr_to_be_unused;
26117         val->totalswap = total_swap_pages + nr_to_be_unused;
26118         spin_unlock(&swap_lock);
26119 +       if (vx_flags(VXF_VIRT_MEM, 0))
26120 +               vx_vsi_swapinfo(val);
26121  }
26122  
26123  /*
26124 diff -NurpP --minimal linux-3.1/net/bridge/br_multicast.c linux-3.1-vs2.3.1-rc2/net/bridge/br_multicast.c
26125 --- linux-3.1/net/bridge/br_multicast.c 2011-10-24 18:45:34.000000000 +0200
26126 +++ linux-3.1-vs2.3.1-rc2/net/bridge/br_multicast.c     2011-10-24 18:53:33.000000000 +0200
26127 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
26128         ip6h->hop_limit = 1;
26129         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
26130         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
26131 -                          &ip6h->saddr);
26132 +                          &ip6h->saddr, NULL);
26133         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
26134  
26135         hopopt = (u8 *)(ip6h + 1);
26136 diff -NurpP --minimal linux-3.1/net/core/dev.c linux-3.1-vs2.3.1-rc2/net/core/dev.c
26137 --- linux-3.1/net/core/dev.c    2011-10-24 18:45:34.000000000 +0200
26138 +++ linux-3.1-vs2.3.1-rc2/net/core/dev.c        2011-10-24 18:53:33.000000000 +0200
26139 @@ -127,6 +127,7 @@
26140  #include <linux/in.h>
26141  #include <linux/jhash.h>
26142  #include <linux/random.h>
26143 +#include <linux/vs_inet.h>
26144  #include <trace/events/napi.h>
26145  #include <trace/events/net.h>
26146  #include <trace/events/skb.h>
26147 @@ -619,7 +620,8 @@ struct net_device *__dev_get_by_name(str
26148         struct hlist_head *head = dev_name_hash(net, name);
26149  
26150         hlist_for_each_entry(dev, p, head, name_hlist)
26151 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26152 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26153 +                   nx_dev_visible(current_nx_info(), dev))
26154                         return dev;
26155  
26156         return NULL;
26157 @@ -645,7 +647,8 @@ struct net_device *dev_get_by_name_rcu(s
26158         struct hlist_head *head = dev_name_hash(net, name);
26159  
26160         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
26161 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26162 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26163 +                   nx_dev_visible(current_nx_info(), dev))
26164                         return dev;
26165  
26166         return NULL;
26167 @@ -696,7 +699,8 @@ struct net_device *__dev_get_by_index(st
26168         struct hlist_head *head = dev_index_hash(net, ifindex);
26169  
26170         hlist_for_each_entry(dev, p, head, index_hlist)
26171 -               if (dev->ifindex == ifindex)
26172 +               if ((dev->ifindex == ifindex) &&
26173 +                   nx_dev_visible(current_nx_info(), dev))
26174                         return dev;
26175  
26176         return NULL;
26177 @@ -714,7 +718,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
26178   *     about locking. The caller must hold RCU lock.
26179   */
26180  
26181 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
26182 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
26183  {
26184         struct hlist_node *p;
26185         struct net_device *dev;
26186 @@ -726,6 +730,16 @@ struct net_device *dev_get_by_index_rcu(
26187  
26188         return NULL;
26189  }
26190 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
26191 +
26192 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
26193 +{
26194 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
26195 +
26196 +       if (nx_dev_visible(current_nx_info(), dev))
26197 +               return dev;
26198 +       return NULL;
26199 +}
26200  EXPORT_SYMBOL(dev_get_by_index_rcu);
26201  
26202  
26203 @@ -774,7 +788,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
26204  
26205         for_each_netdev_rcu(net, dev)
26206                 if (dev->type == type &&
26207 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
26208 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
26209 +                   nx_dev_visible(current_nx_info(), dev))
26210                         return dev;
26211  
26212         return NULL;
26213 @@ -786,9 +801,11 @@ struct net_device *__dev_getfirstbyhwtyp
26214         struct net_device *dev;
26215  
26216         ASSERT_RTNL();
26217 -       for_each_netdev(net, dev)
26218 -               if (dev->type == type)
26219 +       for_each_netdev(net, dev) {
26220 +               if ((dev->type == type) &&
26221 +                   nx_dev_visible(current_nx_info(), dev))
26222                         return dev;
26223 +       }
26224  
26225         return NULL;
26226  }
26227 @@ -906,6 +923,8 @@ static int __dev_alloc_name(struct net *
26228                                 continue;
26229                         if (i < 0 || i >= max_netdevices)
26230                                 continue;
26231 +                       if (!nx_dev_visible(current_nx_info(), d))
26232 +                               continue;
26233  
26234                         /*  avoid cases where sscanf is not exact inverse of printf */
26235                         snprintf(buf, IFNAMSIZ, name, i);
26236 @@ -3955,6 +3974,8 @@ static int dev_ifconf(struct net *net, c
26237  
26238         total = 0;
26239         for_each_netdev(net, dev) {
26240 +               if (!nx_dev_visible(current_nx_info(), dev))
26241 +                       continue;
26242                 for (i = 0; i < NPROTO; i++) {
26243                         if (gifconf_list[i]) {
26244                                 int done;
26245 @@ -4029,6 +4050,10 @@ static void dev_seq_printf_stats(struct 
26246         struct rtnl_link_stats64 temp;
26247         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
26248  
26249 +       /* device visible inside network context? */
26250 +       if (!nx_dev_visible(current_nx_info(), dev))
26251 +               return;
26252 +
26253         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
26254                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
26255                    dev->name, stats->rx_bytes, stats->rx_packets,
26256 diff -NurpP --minimal linux-3.1/net/core/rtnetlink.c linux-3.1-vs2.3.1-rc2/net/core/rtnetlink.c
26257 --- linux-3.1/net/core/rtnetlink.c      2011-10-24 18:45:34.000000000 +0200
26258 +++ linux-3.1-vs2.3.1-rc2/net/core/rtnetlink.c  2011-10-24 18:53:33.000000000 +0200
26259 @@ -1040,6 +1040,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26260                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
26261                         if (idx < s_idx)
26262                                 goto cont;
26263 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26264 +                               continue;
26265                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26266                                              NETLINK_CB(cb->skb).pid,
26267                                              cb->nlh->nlmsg_seq, 0,
26268 @@ -1881,6 +1883,9 @@ void rtmsg_ifinfo(int type, struct net_d
26269         int err = -ENOBUFS;
26270         size_t if_info_size;
26271  
26272 +       if (!nx_dev_visible(current_nx_info(), dev))
26273 +               return;
26274 +
26275         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev)), GFP_KERNEL);
26276         if (skb == NULL)
26277                 goto errout;
26278 diff -NurpP --minimal linux-3.1/net/core/sock.c linux-3.1-vs2.3.1-rc2/net/core/sock.c
26279 --- linux-3.1/net/core/sock.c   2011-10-24 18:45:34.000000000 +0200
26280 +++ linux-3.1-vs2.3.1-rc2/net/core/sock.c       2011-10-24 18:53:33.000000000 +0200
26281 @@ -127,6 +127,10 @@
26282  #include <net/cls_cgroup.h>
26283  
26284  #include <linux/filter.h>
26285 +#include <linux/vs_socket.h>
26286 +#include <linux/vs_limit.h>
26287 +#include <linux/vs_context.h>
26288 +#include <linux/vs_network.h>
26289  
26290  #include <trace/events/sock.h>
26291  
26292 @@ -1073,6 +1077,8 @@ static struct sock *sk_prot_alloc(struct
26293                         goto out_free_sec;
26294                 sk_tx_queue_clear(sk);
26295         }
26296 +               sock_vx_init(sk);
26297 +               sock_nx_init(sk);
26298  
26299         return sk;
26300  
26301 @@ -1172,6 +1178,11 @@ static void __sk_free(struct sock *sk)
26302                 put_cred(sk->sk_peer_cred);
26303         put_pid(sk->sk_peer_pid);
26304         put_net(sock_net(sk));
26305 +       vx_sock_dec(sk);
26306 +       clr_vx_info(&sk->sk_vx_info);
26307 +       sk->sk_xid = -1;
26308 +       clr_nx_info(&sk->sk_nx_info);
26309 +       sk->sk_nid = -1;
26310         sk_prot_free(sk->sk_prot_creator, sk);
26311  }
26312  
26313 @@ -1219,6 +1230,8 @@ struct sock *sk_clone(const struct sock 
26314  
26315                 /* SANITY */
26316                 get_net(sock_net(newsk));
26317 +               sock_vx_init(newsk);
26318 +               sock_nx_init(newsk);
26319                 sk_node_init(&newsk->sk_node);
26320                 sock_lock_init(newsk);
26321                 bh_lock_sock(newsk);
26322 @@ -1274,6 +1287,12 @@ struct sock *sk_clone(const struct sock 
26323                 smp_wmb();
26324                 atomic_set(&newsk->sk_refcnt, 2);
26325  
26326 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26327 +               newsk->sk_xid = sk->sk_xid;
26328 +               vx_sock_inc(newsk);
26329 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26330 +               newsk->sk_nid = sk->sk_nid;
26331 +
26332                 /*
26333                  * Increment the counter in the same struct proto as the master
26334                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26335 @@ -2022,6 +2041,12 @@ void sock_init_data(struct socket *sock,
26336  
26337         sk->sk_stamp = ktime_set(-1L, 0);
26338  
26339 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
26340 +       sk->sk_xid = vx_current_xid();
26341 +       vx_sock_inc(sk);
26342 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
26343 +       sk->sk_nid = nx_current_nid();
26344 +
26345         /*
26346          * Before updating sk_refcnt, we must commit prior changes to memory
26347          * (Documentation/RCU/rculist_nulls.txt for details)
26348 diff -NurpP --minimal linux-3.1/net/ipv4/af_inet.c linux-3.1-vs2.3.1-rc2/net/ipv4/af_inet.c
26349 --- linux-3.1/net/ipv4/af_inet.c        2011-10-24 18:45:34.000000000 +0200
26350 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/af_inet.c    2011-10-24 18:53:33.000000000 +0200
26351 @@ -117,6 +117,7 @@
26352  #ifdef CONFIG_IP_MROUTE
26353  #include <linux/mroute.h>
26354  #endif
26355 +#include <linux/vs_limit.h>
26356  
26357  
26358  /* The inetsw table contains everything that inet_create needs to
26359 @@ -326,9 +327,13 @@ lookup_protocol:
26360         }
26361  
26362         err = -EPERM;
26363 +       if ((protocol == IPPROTO_ICMP) &&
26364 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
26365 +               goto override;
26366 +
26367         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
26368                 goto out_rcu_unlock;
26369 -
26370 +override:
26371         err = -EAFNOSUPPORT;
26372         if (!inet_netns_ok(net, protocol))
26373                 goto out_rcu_unlock;
26374 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
26375         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26376         struct sock *sk = sock->sk;
26377         struct inet_sock *inet = inet_sk(sk);
26378 +       struct nx_v4_sock_addr nsa;
26379         unsigned short snum;
26380         int chk_addr_ret;
26381         int err;
26382 @@ -475,7 +481,11 @@ int inet_bind(struct socket *sock, struc
26383                         goto out;
26384         }
26385  
26386 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26387 +       err = v4_map_sock_addr(inet, addr, &nsa);
26388 +       if (err)
26389 +               goto out;
26390 +
26391 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26392  
26393         /* Not specified by any standard per-se, however it breaks too
26394          * many applications when removed.  It is unfortunate since
26395 @@ -487,7 +497,7 @@ int inet_bind(struct socket *sock, struc
26396         err = -EADDRNOTAVAIL;
26397         if (!sysctl_ip_nonlocal_bind &&
26398             !(inet->freebind || inet->transparent) &&
26399 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26400 +           nsa.saddr != htonl(INADDR_ANY) &&
26401             chk_addr_ret != RTN_LOCAL &&
26402             chk_addr_ret != RTN_MULTICAST &&
26403             chk_addr_ret != RTN_BROADCAST)
26404 @@ -512,7 +522,7 @@ int inet_bind(struct socket *sock, struc
26405         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
26406                 goto out_release_sock;
26407  
26408 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
26409 +       v4_set_sock_addr(inet, &nsa);
26410         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26411                 inet->inet_saddr = 0;  /* Use device */
26412  
26413 @@ -715,11 +725,13 @@ int inet_getname(struct socket *sock, st
26414                      peer == 1))
26415                         return -ENOTCONN;
26416                 sin->sin_port = inet->inet_dport;
26417 -               sin->sin_addr.s_addr = inet->inet_daddr;
26418 +               sin->sin_addr.s_addr =
26419 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
26420         } else {
26421                 __be32 addr = inet->inet_rcv_saddr;
26422                 if (!addr)
26423                         addr = inet->inet_saddr;
26424 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26425                 sin->sin_port = inet->inet_sport;
26426                 sin->sin_addr.s_addr = addr;
26427         }
26428 diff -NurpP --minimal linux-3.1/net/ipv4/arp.c linux-3.1-vs2.3.1-rc2/net/ipv4/arp.c
26429 --- linux-3.1/net/ipv4/arp.c    2011-10-24 18:45:34.000000000 +0200
26430 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/arp.c        2011-10-24 18:53:33.000000000 +0200
26431 @@ -1332,6 +1332,7 @@ static void arp_format_neigh_entry(struc
26432         struct net_device *dev = n->dev;
26433         int hatype = dev->type;
26434  
26435 +       /* FIXME: check for network context */
26436         read_lock(&n->lock);
26437         /* Convert hardware address to XX:XX:XX:XX ... form. */
26438  #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
26439 @@ -1363,6 +1364,7 @@ static void arp_format_pneigh_entry(stru
26440         int hatype = dev ? dev->type : 0;
26441         char tbuf[16];
26442  
26443 +       /* FIXME: check for network context */
26444         sprintf(tbuf, "%pI4", n->key);
26445         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
26446                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
26447 diff -NurpP --minimal linux-3.1/net/ipv4/devinet.c linux-3.1-vs2.3.1-rc2/net/ipv4/devinet.c
26448 --- linux-3.1/net/ipv4/devinet.c        2011-10-24 18:45:34.000000000 +0200
26449 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/devinet.c    2011-10-24 18:53:33.000000000 +0200
26450 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
26451  }
26452  EXPORT_SYMBOL(inetdev_by_index);
26453  
26454 +
26455  /* Called only from RTNL semaphored context. No locks. */
26456  
26457  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26458 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
26459  
26460         in_dev = __in_dev_get_rtnl(dev);
26461         if (in_dev) {
26462 +               struct nx_info *nxi = current_nx_info();
26463 +
26464                 if (tryaddrmatch) {
26465                         /* Matthias Andree */
26466                         /* compare label and address (4.4BSD style) */
26467 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
26468                            This is checked above. */
26469                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26470                              ifap = &ifa->ifa_next) {
26471 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26472 +                                       continue;
26473                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26474                                     sin_orig.sin_addr.s_addr ==
26475                                                         ifa->ifa_local) {
26476 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
26477                    comparing just the label */
26478                 if (!ifa) {
26479                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26480 -                            ifap = &ifa->ifa_next)
26481 +                            ifap = &ifa->ifa_next) {
26482 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26483 +                                       continue;
26484                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26485                                         break;
26486 +                       }
26487                 }
26488         }
26489  
26490 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
26491                 goto out;
26492  
26493         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
26494 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
26495 +                       continue;
26496                 if (!buf) {
26497                         done += sizeof(ifr);
26498                         continue;
26499 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
26500         struct net_device *dev;
26501         struct in_device *in_dev;
26502         struct in_ifaddr *ifa;
26503 +       struct sock *sk = skb->sk;
26504         struct hlist_head *head;
26505         struct hlist_node *node;
26506  
26507 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
26508  
26509                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26510                              ifa = ifa->ifa_next, ip_idx++) {
26511 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26512 +                               continue;
26513                                 if (ip_idx < s_ip_idx)
26514                                         continue;
26515                                 if (inet_fill_ifaddr(skb, ifa,
26516 diff -NurpP --minimal linux-3.1/net/ipv4/fib_trie.c linux-3.1-vs2.3.1-rc2/net/ipv4/fib_trie.c
26517 --- linux-3.1/net/ipv4/fib_trie.c       2011-10-24 18:45:34.000000000 +0200
26518 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/fib_trie.c   2011-10-24 18:53:33.000000000 +0200
26519 @@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
26520                             || fa->fa_type == RTN_MULTICAST)
26521                                 continue;
26522  
26523 +                       /* FIXME: check for network context? */
26524                         if (fi)
26525                                 seq_printf(seq,
26526                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
26527 diff -NurpP --minimal linux-3.1/net/ipv4/inet_connection_sock.c linux-3.1-vs2.3.1-rc2/net/ipv4/inet_connection_sock.c
26528 --- linux-3.1/net/ipv4/inet_connection_sock.c   2011-07-22 11:18:13.000000000 +0200
26529 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/inet_connection_sock.c       2011-10-24 18:53:33.000000000 +0200
26530 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
26531  }
26532  EXPORT_SYMBOL(inet_get_local_port_range);
26533  
26534 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26535 +{
26536 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
26537 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
26538 +
26539 +       if (inet_v6_ipv6only(sk2))
26540 +               return 0;
26541 +
26542 +       if (sk1_rcv_saddr &&
26543 +           sk2_rcv_saddr &&
26544 +           sk1_rcv_saddr == sk2_rcv_saddr)
26545 +               return 1;
26546 +
26547 +       if (sk1_rcv_saddr &&
26548 +           !sk2_rcv_saddr &&
26549 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26550 +               return 1;
26551 +
26552 +       if (sk2_rcv_saddr &&
26553 +           !sk1_rcv_saddr &&
26554 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26555 +               return 1;
26556 +
26557 +       if (!sk1_rcv_saddr &&
26558 +           !sk2_rcv_saddr &&
26559 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26560 +               return 1;
26561 +
26562 +       return 0;
26563 +}
26564 +
26565  int inet_csk_bind_conflict(const struct sock *sk,
26566                            const struct inet_bind_bucket *tb)
26567  {
26568 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
26569                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26570                         if (!reuse || !sk2->sk_reuse ||
26571                             sk2->sk_state == TCP_LISTEN) {
26572 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
26573 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
26574 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
26575 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26576                                         break;
26577                         }
26578                 }
26579 diff -NurpP --minimal linux-3.1/net/ipv4/inet_diag.c linux-3.1-vs2.3.1-rc2/net/ipv4/inet_diag.c
26580 --- linux-3.1/net/ipv4/inet_diag.c      2011-10-24 18:45:34.000000000 +0200
26581 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/inet_diag.c  2011-10-24 18:53:33.000000000 +0200
26582 @@ -33,6 +33,8 @@
26583  #include <linux/stddef.h>
26584  
26585  #include <linux/inet_diag.h>
26586 +#include <linux/vs_network.h>
26587 +#include <linux/vs_inet.h>
26588  
26589  static const struct inet_diag_handler **inet_diag_table;
26590  
26591 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
26592  
26593         r->id.idiag_sport = inet->inet_sport;
26594         r->id.idiag_dport = inet->inet_dport;
26595 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
26596 -       r->id.idiag_dst[0] = inet->inet_daddr;
26597 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
26598 +               inet->inet_rcv_saddr);
26599 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
26600 +               inet->inet_daddr);
26601  
26602  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26603         if (r->idiag_family == AF_INET6) {
26604 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
26605         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26606         r->id.idiag_sport     = tw->tw_sport;
26607         r->id.idiag_dport     = tw->tw_dport;
26608 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26609 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26610 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26611 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26612         r->idiag_state        = tw->tw_substate;
26613         r->idiag_timer        = 3;
26614         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26615 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
26616         err = -EINVAL;
26617  
26618         if (req->idiag_family == AF_INET) {
26619 +               /* TODO: lback */
26620                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26621                                  req->id.idiag_dport, req->id.idiag_src[0],
26622                                  req->id.idiag_sport, req->id.idiag_if);
26623 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
26624                 } else
26625  #endif
26626                 {
26627 +                       /* TODO: lback */
26628                         entry.saddr = &inet->inet_rcv_saddr;
26629                         entry.daddr = &inet->inet_daddr;
26630                 }
26631 @@ -543,6 +549,7 @@ static int inet_twsk_diag_dump(struct in
26632                 } else
26633  #endif
26634                 {
26635 +                       /* TODO: lback */
26636                         entry.saddr = &tw->tw_rcv_saddr;
26637                         entry.daddr = &tw->tw_daddr;
26638                 }
26639 @@ -589,8 +596,8 @@ static int inet_diag_fill_req(struct sk_
26640  
26641         r->id.idiag_sport = inet->inet_sport;
26642         r->id.idiag_dport = ireq->rmt_port;
26643 -       r->id.idiag_src[0] = ireq->loc_addr;
26644 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26645 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26646 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26647         r->idiag_expires = jiffies_to_msecs(tmo);
26648         r->idiag_rqueue = 0;
26649         r->idiag_wqueue = 0;
26650 @@ -661,6 +668,7 @@ static int inet_diag_dump_reqs(struct sk
26651                                 continue;
26652  
26653                         if (bc) {
26654 +                               /* TODO: lback */
26655                                 entry.saddr =
26656  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26657                                         (entry.family == AF_INET6) ?
26658 @@ -731,6 +739,8 @@ static int inet_diag_dump(struct sk_buff
26659                         sk_nulls_for_each(sk, node, &ilb->head) {
26660                                 struct inet_sock *inet = inet_sk(sk);
26661  
26662 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26663 +                                       continue;
26664                                 if (num < s_num) {
26665                                         num++;
26666                                         continue;
26667 @@ -797,6 +807,8 @@ skip_listen_ht:
26668                 sk_nulls_for_each(sk, node, &head->chain) {
26669                         struct inet_sock *inet = inet_sk(sk);
26670  
26671 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26672 +                               continue;
26673                         if (num < s_num)
26674                                 goto next_normal;
26675                         if (!(r->idiag_states & (1 << sk->sk_state)))
26676 @@ -821,6 +833,8 @@ next_normal:
26677                         inet_twsk_for_each(tw, node,
26678                                     &head->twchain) {
26679  
26680 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26681 +                                       continue;
26682                                 if (num < s_num)
26683                                         goto next_dying;
26684                                 if (r->id.idiag_sport != tw->tw_sport &&
26685 diff -NurpP --minimal linux-3.1/net/ipv4/inet_hashtables.c linux-3.1-vs2.3.1-rc2/net/ipv4/inet_hashtables.c
26686 --- linux-3.1/net/ipv4/inet_hashtables.c        2011-10-24 18:45:34.000000000 +0200
26687 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/inet_hashtables.c    2011-10-24 18:53:33.000000000 +0200
26688 @@ -22,6 +22,7 @@
26689  #include <net/inet_connection_sock.h>
26690  #include <net/inet_hashtables.h>
26691  #include <net/secure_seq.h>
26692 +#include <net/route.h>
26693  #include <net/ip.h>
26694  
26695  /*
26696 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
26697                         if (rcv_saddr != daddr)
26698                                 return -1;
26699                         score += 2;
26700 +               } else {
26701 +                       /* block non nx_info ips */
26702 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
26703 +                               daddr, NXA_MASK_BIND))
26704 +                               return -1;
26705                 }
26706                 if (sk->sk_bound_dev_if) {
26707                         if (sk->sk_bound_dev_if != dif)
26708 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
26709   * wildcarded during the search since they can never be otherwise.
26710   */
26711  
26712 -
26713  struct sock *__inet_lookup_listener(struct net *net,
26714                                     struct inet_hashinfo *hashinfo,
26715                                     const __be32 daddr, const unsigned short hnum,
26716 @@ -196,6 +201,7 @@ begin:
26717                         hiscore = score;
26718                 }
26719         }
26720 +
26721         /*
26722          * if the nulls value we got at the end of this lookup is
26723          * not the expected one, we must restart lookup.
26724 diff -NurpP --minimal linux-3.1/net/ipv4/netfilter/nf_nat_helper.c linux-3.1-vs2.3.1-rc2/net/ipv4/netfilter/nf_nat_helper.c
26725 --- linux-3.1/net/ipv4/netfilter/nf_nat_helper.c        2011-07-22 11:18:13.000000000 +0200
26726 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/netfilter/nf_nat_helper.c    2011-10-24 18:53:33.000000000 +0200
26727 @@ -20,6 +20,7 @@
26728  #include <net/route.h>
26729  
26730  #include <linux/netfilter_ipv4.h>
26731 +#include <net/route.h>
26732  #include <net/netfilter/nf_conntrack.h>
26733  #include <net/netfilter/nf_conntrack_helper.h>
26734  #include <net/netfilter/nf_conntrack_ecache.h>
26735 diff -NurpP --minimal linux-3.1/net/ipv4/netfilter.c linux-3.1-vs2.3.1-rc2/net/ipv4/netfilter.c
26736 --- linux-3.1/net/ipv4/netfilter.c      2011-10-24 18:45:34.000000000 +0200
26737 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/netfilter.c  2011-10-24 18:53:33.000000000 +0200
26738 @@ -5,7 +5,7 @@
26739  #include <linux/ip.h>
26740  #include <linux/skbuff.h>
26741  #include <linux/gfp.h>
26742 -#include <net/route.h>
26743 +// #include <net/route.h>
26744  #include <net/xfrm.h>
26745  #include <net/ip.h>
26746  #include <net/netfilter/nf_queue.h>
26747 diff -NurpP --minimal linux-3.1/net/ipv4/raw.c linux-3.1-vs2.3.1-rc2/net/ipv4/raw.c
26748 --- linux-3.1/net/ipv4/raw.c    2011-10-24 18:45:34.000000000 +0200
26749 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/raw.c        2011-10-24 18:53:33.000000000 +0200
26750 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
26751  
26752                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
26753                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
26754 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
26755 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
26756                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
26757                         goto found; /* gotcha */
26758         }
26759 @@ -385,6 +385,12 @@ static int raw_send_hdrinc(struct sock *
26760                 icmp_out_count(net, ((struct icmphdr *)
26761                         skb_transport_header(skb))->type);
26762  
26763 +       err = -EPERM;
26764 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
26765 +               sk->sk_nx_info &&
26766 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
26767 +               goto error_free;
26768 +
26769         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
26770                       rt->dst.dev, dst_output);
26771         if (err > 0)
26772 @@ -572,6 +578,16 @@ static int raw_sendmsg(struct kiocb *ioc
26773                         goto done;
26774         }
26775  
26776 +       if (sk->sk_nx_info) {
26777 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
26778 +               if (IS_ERR(rt)) {
26779 +                       err = PTR_ERR(rt);
26780 +                       rt = NULL;
26781 +                       goto done;
26782 +               }
26783 +               ip_rt_put(rt);
26784 +       }
26785 +
26786         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
26787         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
26788         if (IS_ERR(rt)) {
26789 @@ -648,17 +664,19 @@ static int raw_bind(struct sock *sk, str
26790  {
26791         struct inet_sock *inet = inet_sk(sk);
26792         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
26793 +       struct nx_v4_sock_addr nsa = { 0 };
26794         int ret = -EINVAL;
26795         int chk_addr_ret;
26796  
26797         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
26798                 goto out;
26799 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26800 +       v4_map_sock_addr(inet, addr, &nsa);
26801 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26802         ret = -EADDRNOTAVAIL;
26803 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
26804 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
26805             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
26806                 goto out;
26807 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
26808 +       v4_set_sock_addr(inet, &nsa);
26809         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26810                 inet->inet_saddr = 0;  /* Use device */
26811         sk_dst_reset(sk);
26812 @@ -710,7 +728,8 @@ static int raw_recvmsg(struct kiocb *ioc
26813         /* Copy the address. */
26814         if (sin) {
26815                 sin->sin_family = AF_INET;
26816 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26817 +               sin->sin_addr.s_addr =
26818 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
26819                 sin->sin_port = 0;
26820                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
26821         }
26822 @@ -906,7 +925,8 @@ static struct sock *raw_get_first(struct
26823                 struct hlist_node *node;
26824  
26825                 sk_for_each(sk, node, &state->h->ht[state->bucket])
26826 -                       if (sock_net(sk) == seq_file_net(seq))
26827 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
26828 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26829                                 goto found;
26830         }
26831         sk = NULL;
26832 @@ -922,7 +942,8 @@ static struct sock *raw_get_next(struct 
26833                 sk = sk_next(sk);
26834  try_again:
26835                 ;
26836 -       } while (sk && sock_net(sk) != seq_file_net(seq));
26837 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
26838 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26839  
26840         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
26841                 sk = sk_head(&state->h->ht[state->bucket]);
26842 diff -NurpP --minimal linux-3.1/net/ipv4/route.c linux-3.1-vs2.3.1-rc2/net/ipv4/route.c
26843 --- linux-3.1/net/ipv4/route.c  2011-10-24 18:45:34.000000000 +0200
26844 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/route.c      2011-10-24 18:53:33.000000000 +0200
26845 @@ -2562,7 +2562,7 @@ static struct rtable *ip_route_output_sl
26846  
26847  
26848         if (fl4->flowi4_oif) {
26849 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
26850 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
26851                 rth = ERR_PTR(-ENODEV);
26852                 if (dev_out == NULL)
26853                         goto out;
26854 diff -NurpP --minimal linux-3.1/net/ipv4/tcp.c linux-3.1-vs2.3.1-rc2/net/ipv4/tcp.c
26855 --- linux-3.1/net/ipv4/tcp.c    2011-07-22 11:18:13.000000000 +0200
26856 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/tcp.c        2011-10-24 18:53:33.000000000 +0200
26857 @@ -266,6 +266,7 @@
26858  #include <linux/crypto.h>
26859  #include <linux/time.h>
26860  #include <linux/slab.h>
26861 +#include <linux/in.h>
26862  
26863  #include <net/icmp.h>
26864  #include <net/tcp.h>
26865 diff -NurpP --minimal linux-3.1/net/ipv4/tcp_ipv4.c linux-3.1-vs2.3.1-rc2/net/ipv4/tcp_ipv4.c
26866 --- linux-3.1/net/ipv4/tcp_ipv4.c       2011-10-24 18:45:34.000000000 +0200
26867 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/tcp_ipv4.c   2011-10-24 18:53:33.000000000 +0200
26868 @@ -2018,6 +2018,12 @@ static void *listening_get_next(struct s
26869                 req = req->dl_next;
26870                 while (1) {
26871                         while (req) {
26872 +                               vxdprintk(VXD_CBIT(net, 6),
26873 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
26874 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
26875 +                               if (req->sk &&
26876 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
26877 +                                       continue;
26878                                 if (req->rsk_ops->family == st->family) {
26879                                         cur = req;
26880                                         goto out;
26881 @@ -2042,6 +2048,10 @@ get_req:
26882         }
26883  get_sk:
26884         sk_nulls_for_each_from(sk, node) {
26885 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
26886 +                       sk, sk->sk_nid, nx_current_nid());
26887 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26888 +                       continue;
26889                 if (!net_eq(sock_net(sk), net))
26890                         continue;
26891                 if (sk->sk_family == st->family) {
26892 @@ -2118,6 +2128,11 @@ static void *established_get_first(struc
26893  
26894                 spin_lock_bh(lock);
26895                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
26896 +                       vxdprintk(VXD_CBIT(net, 6),
26897 +                               "sk,egf: %p [#%d] (from %d)",
26898 +                               sk, sk->sk_nid, nx_current_nid());
26899 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26900 +                               continue;
26901                         if (sk->sk_family != st->family ||
26902                             !net_eq(sock_net(sk), net)) {
26903                                 continue;
26904 @@ -2128,6 +2143,11 @@ static void *established_get_first(struc
26905                 st->state = TCP_SEQ_STATE_TIME_WAIT;
26906                 inet_twsk_for_each(tw, node,
26907                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
26908 +                       vxdprintk(VXD_CBIT(net, 6),
26909 +                               "tw: %p [#%d] (from %d)",
26910 +                               tw, tw->tw_nid, nx_current_nid());
26911 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26912 +                               continue;
26913                         if (tw->tw_family != st->family ||
26914                             !net_eq(twsk_net(tw), net)) {
26915                                 continue;
26916 @@ -2157,7 +2177,9 @@ static void *established_get_next(struct
26917                 tw = cur;
26918                 tw = tw_next(tw);
26919  get_tw:
26920 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
26921 +               while (tw && (tw->tw_family != st->family ||
26922 +                       !net_eq(twsk_net(tw), net) ||
26923 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
26924                         tw = tw_next(tw);
26925                 }
26926                 if (tw) {
26927 @@ -2181,6 +2203,11 @@ get_tw:
26928                 sk = sk_nulls_next(sk);
26929  
26930         sk_nulls_for_each_from(sk, node) {
26931 +               vxdprintk(VXD_CBIT(net, 6),
26932 +                       "sk,egn: %p [#%d] (from %d)",
26933 +                       sk, sk->sk_nid, nx_current_nid());
26934 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26935 +                       continue;
26936                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
26937                         goto found;
26938         }
26939 @@ -2390,9 +2417,9 @@ static void get_openreq4(struct sock *sk
26940         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26941                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
26942                 i,
26943 -               ireq->loc_addr,
26944 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
26945                 ntohs(inet_sk(sk)->inet_sport),
26946 -               ireq->rmt_addr,
26947 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
26948                 ntohs(ireq->rmt_port),
26949                 TCP_SYN_RECV,
26950                 0, 0, /* could print option size, but that is af dependent. */
26951 @@ -2414,8 +2441,8 @@ static void get_tcp4_sock(struct sock *s
26952         struct tcp_sock *tp = tcp_sk(sk);
26953         const struct inet_connection_sock *icsk = inet_csk(sk);
26954         struct inet_sock *inet = inet_sk(sk);
26955 -       __be32 dest = inet->inet_daddr;
26956 -       __be32 src = inet->inet_rcv_saddr;
26957 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
26958 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
26959         __u16 destp = ntohs(inet->inet_dport);
26960         __u16 srcp = ntohs(inet->inet_sport);
26961         int rx_queue;
26962 @@ -2472,8 +2499,8 @@ static void get_timewait4_sock(struct in
26963         if (ttd < 0)
26964                 ttd = 0;
26965  
26966 -       dest  = tw->tw_daddr;
26967 -       src   = tw->tw_rcv_saddr;
26968 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
26969 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
26970         destp = ntohs(tw->tw_dport);
26971         srcp  = ntohs(tw->tw_sport);
26972  
26973 diff -NurpP --minimal linux-3.1/net/ipv4/tcp_minisocks.c linux-3.1-vs2.3.1-rc2/net/ipv4/tcp_minisocks.c
26974 --- linux-3.1/net/ipv4/tcp_minisocks.c  2011-10-24 18:45:34.000000000 +0200
26975 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/tcp_minisocks.c      2011-10-24 18:53:33.000000000 +0200
26976 @@ -23,6 +23,9 @@
26977  #include <linux/slab.h>
26978  #include <linux/sysctl.h>
26979  #include <linux/workqueue.h>
26980 +#include <linux/vs_limit.h>
26981 +#include <linux/vs_socket.h>
26982 +#include <linux/vs_context.h>
26983  #include <net/tcp.h>
26984  #include <net/inet_common.h>
26985  #include <net/xfrm.h>
26986 @@ -336,6 +339,11 @@ void tcp_time_wait(struct sock *sk, int 
26987                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
26988                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
26989  
26990 +               tw->tw_xid              = sk->sk_xid;
26991 +               tw->tw_vx_info          = NULL;
26992 +               tw->tw_nid              = sk->sk_nid;
26993 +               tw->tw_nx_info          = NULL;
26994 +
26995  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
26996                 if (tw->tw_family == PF_INET6) {
26997                         struct ipv6_pinfo *np = inet6_sk(sk);
26998 diff -NurpP --minimal linux-3.1/net/ipv4/udp.c linux-3.1-vs2.3.1-rc2/net/ipv4/udp.c
26999 --- linux-3.1/net/ipv4/udp.c    2011-10-24 18:45:34.000000000 +0200
27000 +++ linux-3.1-vs2.3.1-rc2/net/ipv4/udp.c        2011-10-24 18:53:33.000000000 +0200
27001 @@ -297,14 +297,7 @@ fail:
27002  }
27003  EXPORT_SYMBOL(udp_lib_get_port);
27004  
27005 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27006 -{
27007 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27008 -
27009 -       return  (!ipv6_only_sock(sk2)  &&
27010 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
27011 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
27012 -}
27013 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27014  
27015  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
27016                                        unsigned int port)
27017 @@ -339,6 +332,11 @@ static inline int compute_score(struct s
27018                         if (inet->inet_rcv_saddr != daddr)
27019                                 return -1;
27020                         score += 2;
27021 +               } else {
27022 +                       /* block non nx_info ips */
27023 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27024 +                               daddr, NXA_MASK_BIND))
27025 +                               return -1;
27026                 }
27027                 if (inet->inet_daddr) {
27028                         if (inet->inet_daddr != saddr)
27029 @@ -442,6 +440,7 @@ exact_match:
27030         return result;
27031  }
27032  
27033 +
27034  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27035   * harder than this. -DaveM
27036   */
27037 @@ -487,6 +486,11 @@ begin:
27038         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27039                 score = compute_score(sk, net, saddr, hnum, sport,
27040                                       daddr, dport, dif);
27041 +               /* FIXME: disabled?
27042 +               if (score == 9) {
27043 +                       result = sk;
27044 +                       break;
27045 +               } else */
27046                 if (score > badness) {
27047                         result = sk;
27048                         badness = score;
27049 @@ -500,6 +504,7 @@ begin:
27050         if (get_nulls_value(node) != slot)
27051                 goto begin;
27052  
27053 +
27054         if (result) {
27055                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
27056                         result = NULL;
27057 @@ -509,6 +514,7 @@ begin:
27058                         goto begin;
27059                 }
27060         }
27061 +
27062         rcu_read_unlock();
27063         return result;
27064  }
27065 @@ -551,8 +557,7 @@ static inline struct sock *udp_v4_mcast_
27066                     udp_sk(s)->udp_port_hash != hnum ||
27067                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
27068                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
27069 -                   (inet->inet_rcv_saddr &&
27070 -                    inet->inet_rcv_saddr != loc_addr) ||
27071 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27072                     ipv6_only_sock(s) ||
27073                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27074                         continue;
27075 @@ -930,6 +935,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
27076                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
27077                                    faddr, saddr, dport, inet->inet_sport);
27078  
27079 +               if (sk->sk_nx_info) {
27080 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
27081 +                       if (IS_ERR(rt)) {
27082 +                               err = PTR_ERR(rt);
27083 +                               rt = NULL;
27084 +                               goto out;
27085 +                       }
27086 +                       ip_rt_put(rt);
27087 +               }
27088 +
27089                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
27090                 rt = ip_route_output_flow(net, fl4, sk);
27091                 if (IS_ERR(rt)) {
27092 @@ -1227,7 +1242,8 @@ try_again:
27093         if (sin) {
27094                 sin->sin_family = AF_INET;
27095                 sin->sin_port = udp_hdr(skb)->source;
27096 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27097 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27098 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27099                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27100         }
27101         if (inet->cmsg_flags)
27102 @@ -1972,6 +1988,8 @@ static struct sock *udp_get_first(struct
27103                 sk_nulls_for_each(sk, node, &hslot->head) {
27104                         if (!net_eq(sock_net(sk), net))
27105                                 continue;
27106 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27107 +                               continue;
27108                         if (sk->sk_family == state->family)
27109                                 goto found;
27110                 }
27111 @@ -1989,7 +2007,9 @@ static struct sock *udp_get_next(struct 
27112  
27113         do {
27114                 sk = sk_nulls_next(sk);
27115 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27116 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27117 +               sk->sk_family != state->family ||
27118 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27119  
27120         if (!sk) {
27121                 if (state->bucket <= state->udp_table->mask)
27122 diff -NurpP --minimal linux-3.1/net/ipv6/Kconfig linux-3.1-vs2.3.1-rc2/net/ipv6/Kconfig
27123 --- linux-3.1/net/ipv6/Kconfig  2010-08-02 16:52:59.000000000 +0200
27124 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/Kconfig      2011-10-24 18:53:33.000000000 +0200
27125 @@ -4,8 +4,8 @@
27126  
27127  #   IPv6 as module will cause a CRASH if you try to unload it
27128  menuconfig IPV6
27129 -       tristate "The IPv6 protocol"
27130 -       default m
27131 +       bool "The IPv6 protocol"
27132 +       default n
27133         ---help---
27134           This is complemental support for the IP version 6.
27135           You will still be able to do traditional IPv4 networking as well.
27136 diff -NurpP --minimal linux-3.1/net/ipv6/addrconf.c linux-3.1-vs2.3.1-rc2/net/ipv6/addrconf.c
27137 --- linux-3.1/net/ipv6/addrconf.c       2011-10-24 18:45:34.000000000 +0200
27138 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/addrconf.c   2011-10-24 18:53:33.000000000 +0200
27139 @@ -87,6 +87,8 @@
27140  
27141  #include <linux/proc_fs.h>
27142  #include <linux/seq_file.h>
27143 +#include <linux/vs_network.h>
27144 +#include <linux/vs_inet6.h>
27145  
27146  /* Set to 3 to get tracing... */
27147  #define ACONF_DEBUG 2
27148 @@ -1108,7 +1110,7 @@ out:
27149  
27150  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27151                        const struct in6_addr *daddr, unsigned int prefs,
27152 -                      struct in6_addr *saddr)
27153 +                      struct in6_addr *saddr, struct nx_info *nxi)
27154  {
27155         struct ipv6_saddr_score scores[2],
27156                                 *score = &scores[0], *hiscore = &scores[1];
27157 @@ -1180,6 +1182,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27158                                                dev->name);
27159                                 continue;
27160                         }
27161 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27162 +                               continue;
27163  
27164                         score->rule = -1;
27165                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27166 @@ -3087,7 +3091,10 @@ static void if6_seq_stop(struct seq_file
27167  static int if6_seq_show(struct seq_file *seq, void *v)
27168  {
27169         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27170 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27171 +
27172 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27173 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27174 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27175                    &ifp->addr,
27176                    ifp->idev->dev->ifindex,
27177                    ifp->prefix_len,
27178 @@ -3593,6 +3600,11 @@ static int in6_dump_addrs(struct inet6_d
27179         struct ifacaddr6 *ifaca;
27180         int err = 1;
27181         int ip_idx = *p_ip_idx;
27182 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27183 +
27184 +       /* disable ipv6 on non v6 guests */
27185 +       if (nxi && !nx_info_has_v6(nxi))
27186 +               return skb->len;
27187  
27188         read_lock_bh(&idev->lock);
27189         switch (type) {
27190 @@ -3603,6 +3615,8 @@ static int in6_dump_addrs(struct inet6_d
27191                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
27192                         if (++ip_idx < s_ip_idx)
27193                                 continue;
27194 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27195 +                                       continue;
27196                         err = inet6_fill_ifaddr(skb, ifa,
27197                                                 NETLINK_CB(cb->skb).pid,
27198                                                 cb->nlh->nlmsg_seq,
27199 @@ -3619,6 +3633,8 @@ static int in6_dump_addrs(struct inet6_d
27200                      ifmca = ifmca->next, ip_idx++) {
27201                         if (ip_idx < s_ip_idx)
27202                                 continue;
27203 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27204 +                                       continue;
27205                         err = inet6_fill_ifmcaddr(skb, ifmca,
27206                                                   NETLINK_CB(cb->skb).pid,
27207                                                   cb->nlh->nlmsg_seq,
27208 @@ -3634,6 +3650,8 @@ static int in6_dump_addrs(struct inet6_d
27209                      ifaca = ifaca->aca_next, ip_idx++) {
27210                         if (ip_idx < s_ip_idx)
27211                                 continue;
27212 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27213 +                                       continue;
27214                         err = inet6_fill_ifacaddr(skb, ifaca,
27215                                                   NETLINK_CB(cb->skb).pid,
27216                                                   cb->nlh->nlmsg_seq,
27217 @@ -4019,6 +4037,11 @@ static int inet6_dump_ifinfo(struct sk_b
27218         struct inet6_dev *idev;
27219         struct hlist_head *head;
27220         struct hlist_node *node;
27221 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27222 +
27223 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27224 +       if (skb->sk && skb->sk->sk_vx_info)
27225 +               return skb->len; */
27226  
27227         s_h = cb->args[0];
27228         s_idx = cb->args[1];
27229 @@ -4030,6 +4053,8 @@ static int inet6_dump_ifinfo(struct sk_b
27230                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
27231                         if (idx < s_idx)
27232                                 goto cont;
27233 +                       if (!v6_dev_in_nx_info(dev, nxi))
27234 +                               goto cont;
27235                         idev = __in6_dev_get(dev);
27236                         if (!idev)
27237                                 goto cont;
27238 diff -NurpP --minimal linux-3.1/net/ipv6/af_inet6.c linux-3.1-vs2.3.1-rc2/net/ipv6/af_inet6.c
27239 --- linux-3.1/net/ipv6/af_inet6.c       2011-10-24 18:45:34.000000000 +0200
27240 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/af_inet6.c   2011-10-24 18:53:33.000000000 +0200
27241 @@ -42,6 +42,8 @@
27242  #include <linux/netdevice.h>
27243  #include <linux/icmpv6.h>
27244  #include <linux/netfilter_ipv6.h>
27245 +#include <linux/vs_inet.h>
27246 +#include <linux/vs_inet6.h>
27247  
27248  #include <net/ip.h>
27249  #include <net/ipv6.h>
27250 @@ -160,9 +162,12 @@ lookup_protocol:
27251         }
27252  
27253         err = -EPERM;
27254 +       if ((protocol == IPPROTO_ICMPV6) &&
27255 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
27256 +               goto override;
27257         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
27258                 goto out_rcu_unlock;
27259 -
27260 +override:
27261         sock->ops = answer->ops;
27262         answer_prot = answer->prot;
27263         answer_no_check = answer->no_check;
27264 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
27265         struct inet_sock *inet = inet_sk(sk);
27266         struct ipv6_pinfo *np = inet6_sk(sk);
27267         struct net *net = sock_net(sk);
27268 +       struct nx_v6_sock_addr nsa;
27269         __be32 v4addr = 0;
27270         unsigned short snum;
27271         int addr_type = 0;
27272 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
27273         if (addr->sin6_family != AF_INET6)
27274                 return -EAFNOSUPPORT;
27275  
27276 +       err = v6_map_sock_addr(inet, addr, &nsa);
27277 +       if (err)
27278 +               return err;
27279 +
27280         addr_type = ipv6_addr_type(&addr->sin6_addr);
27281         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27282                 return -EINVAL;
27283 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
27284                 /* Reproduce AF_INET checks to make the bindings consistent */
27285                 v4addr = addr->sin6_addr.s6_addr32[3];
27286                 chk_addr_ret = inet_addr_type(net, v4addr);
27287 +
27288                 if (!sysctl_ip_nonlocal_bind &&
27289                     !(inet->freebind || inet->transparent) &&
27290                     v4addr != htonl(INADDR_ANY) &&
27291 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
27292                         err = -EADDRNOTAVAIL;
27293                         goto out;
27294                 }
27295 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27296 +                       err = -EADDRNOTAVAIL;
27297 +                       goto out;
27298 +               }
27299         } else {
27300                 if (addr_type != IPV6_ADDR_ANY) {
27301                         struct net_device *dev = NULL;
27302 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
27303                                 }
27304                         }
27305  
27306 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27307 +                               err = -EADDRNOTAVAIL;
27308 +                               goto out;
27309 +                       }
27310 +
27311                         /* ipv4 addr of the socket is invalid.  Only the
27312                          * unspecified and mapped address have a v4 equivalent.
27313                          */
27314 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
27315                 }
27316         }
27317  
27318 +       /* what's that for? */
27319 +       v6_set_sock_addr(inet, &nsa);
27320 +
27321         inet->inet_rcv_saddr = v4addr;
27322         inet->inet_saddr = v4addr;
27323  
27324 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
27325                         return -ENOTCONN;
27326                 sin->sin6_port = inet->inet_dport;
27327                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27328 +               /* FIXME: remap lback? */
27329                 if (np->sndflow)
27330                         sin->sin6_flowinfo = np->flow_label;
27331         } else {
27332 +               /* FIXME: remap lback? */
27333                 if (ipv6_addr_any(&np->rcv_saddr))
27334                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27335                 else
27336 diff -NurpP --minimal linux-3.1/net/ipv6/datagram.c linux-3.1-vs2.3.1-rc2/net/ipv6/datagram.c
27337 --- linux-3.1/net/ipv6/datagram.c       2011-10-24 18:45:34.000000000 +0200
27338 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/datagram.c   2011-10-24 18:53:33.000000000 +0200
27339 @@ -646,7 +646,7 @@ int datagram_send_ctl(struct net *net, s
27340  
27341                         rcu_read_lock();
27342                         if (fl6->flowi6_oif) {
27343 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
27344 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
27345                                 if (!dev) {
27346                                         rcu_read_unlock();
27347                                         return -ENODEV;
27348 diff -NurpP --minimal linux-3.1/net/ipv6/fib6_rules.c linux-3.1-vs2.3.1-rc2/net/ipv6/fib6_rules.c
27349 --- linux-3.1/net/ipv6/fib6_rules.c     2011-05-22 16:18:00.000000000 +0200
27350 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/fib6_rules.c 2011-10-24 18:53:33.000000000 +0200
27351 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
27352                                                ip6_dst_idev(&rt->dst)->dev,
27353                                                &flp6->daddr,
27354                                                rt6_flags2srcprefs(flags),
27355 -                                              &saddr))
27356 +                                              &saddr, NULL))
27357                                 goto again;
27358                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27359                                                r->src.plen))
27360 diff -NurpP --minimal linux-3.1/net/ipv6/inet6_hashtables.c linux-3.1-vs2.3.1-rc2/net/ipv6/inet6_hashtables.c
27361 --- linux-3.1/net/ipv6/inet6_hashtables.c       2011-10-24 18:45:34.000000000 +0200
27362 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/inet6_hashtables.c   2011-10-24 18:53:33.000000000 +0200
27363 @@ -16,6 +16,7 @@
27364  
27365  #include <linux/module.h>
27366  #include <linux/random.h>
27367 +#include <linux/vs_inet6.h>
27368  
27369  #include <net/inet_connection_sock.h>
27370  #include <net/inet_hashtables.h>
27371 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
27372         unsigned int slot = hash & hashinfo->ehash_mask;
27373         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
27374  
27375 -
27376         rcu_read_lock();
27377  begin:
27378         sk_nulls_for_each_rcu(sk, node, &head->chain) {
27379 @@ -95,7 +95,7 @@ begin:
27380                                 sock_put(sk);
27381                                 goto begin;
27382                         }
27383 -               goto out;
27384 +                       goto out;
27385                 }
27386         }
27387         if (get_nulls_value(node) != slot)
27388 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
27389                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27390                                 return -1;
27391                         score++;
27392 +               } else {
27393 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27394 +                               return -1;
27395                 }
27396                 if (sk->sk_bound_dev_if) {
27397                         if (sk->sk_bound_dev_if != dif)
27398 diff -NurpP --minimal linux-3.1/net/ipv6/ip6_output.c linux-3.1-vs2.3.1-rc2/net/ipv6/ip6_output.c
27399 --- linux-3.1/net/ipv6/ip6_output.c     2011-10-24 18:45:34.000000000 +0200
27400 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/ip6_output.c 2011-10-24 18:53:33.000000000 +0200
27401 @@ -966,7 +966,8 @@ static int ip6_dst_lookup_tail(struct so
27402                 struct rt6_info *rt = (struct rt6_info *) *dst;
27403                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
27404                                           sk ? inet6_sk(sk)->srcprefs : 0,
27405 -                                         &fl6->saddr);
27406 +                                         &fl6->saddr,
27407 +                                         sk ? sk->sk_nx_info : NULL);
27408                 if (err)
27409                         goto out_err_release;
27410         }
27411 diff -NurpP --minimal linux-3.1/net/ipv6/ndisc.c linux-3.1-vs2.3.1-rc2/net/ipv6/ndisc.c
27412 --- linux-3.1/net/ipv6/ndisc.c  2011-10-24 18:45:34.000000000 +0200
27413 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/ndisc.c      2011-10-24 18:53:33.000000000 +0200
27414 @@ -591,7 +591,7 @@ static void ndisc_send_na(struct net_dev
27415         } else {
27416                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27417                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27418 -                                      &tmpaddr))
27419 +                                      &tmpaddr, NULL))
27420                         return;
27421                 src_addr = &tmpaddr;
27422         }
27423 diff -NurpP --minimal linux-3.1/net/ipv6/raw.c linux-3.1-vs2.3.1-rc2/net/ipv6/raw.c
27424 --- linux-3.1/net/ipv6/raw.c    2011-10-24 18:45:34.000000000 +0200
27425 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/raw.c        2011-10-24 18:53:33.000000000 +0200
27426 @@ -30,6 +30,7 @@
27427  #include <linux/icmpv6.h>
27428  #include <linux/netfilter.h>
27429  #include <linux/netfilter_ipv6.h>
27430 +#include <linux/vs_inet6.h>
27431  #include <linux/skbuff.h>
27432  #include <linux/compat.h>
27433  #include <asm/uaccess.h>
27434 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
27435                                 goto out_unlock;
27436                 }
27437  
27438 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27439 +                       err = -EADDRNOTAVAIL;
27440 +                       if (dev)
27441 +                               dev_put(dev);
27442 +                       goto out;
27443 +               }
27444 +
27445                 /* ipv4 addr of the socket is invalid.  Only the
27446                  * unspecified and mapped address have a v4 equivalent.
27447                  */
27448 diff -NurpP --minimal linux-3.1/net/ipv6/route.c linux-3.1-vs2.3.1-rc2/net/ipv6/route.c
27449 --- linux-3.1/net/ipv6/route.c  2011-10-24 18:45:34.000000000 +0200
27450 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/route.c      2011-10-24 18:53:33.000000000 +0200
27451 @@ -54,6 +54,7 @@
27452  #include <net/xfrm.h>
27453  #include <net/netevent.h>
27454  #include <net/netlink.h>
27455 +#include <linux/vs_inet6.h>
27456  
27457  #include <asm/uaccess.h>
27458  
27459 @@ -2086,15 +2087,17 @@ int ip6_route_get_saddr(struct net *net,
27460                         struct rt6_info *rt,
27461                         const struct in6_addr *daddr,
27462                         unsigned int prefs,
27463 -                       struct in6_addr *saddr)
27464 +                       struct in6_addr *saddr,
27465 +                       struct nx_info *nxi)
27466  {
27467         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
27468         int err = 0;
27469 -       if (rt->rt6i_prefsrc.plen)
27470 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
27471 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
27472                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
27473         else
27474                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27475 -                                        daddr, prefs, saddr);
27476 +                                        daddr, prefs, saddr, nxi);
27477         return err;
27478  }
27479  
27480 @@ -2424,7 +2427,8 @@ static int rt6_fill_node(struct net *net
27481                         NLA_PUT_U32(skb, RTA_IIF, iif);
27482         } else if (dst) {
27483                 struct in6_addr saddr_buf;
27484 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
27485 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
27486 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27487                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27488         }
27489  
27490 @@ -2627,6 +2631,7 @@ static int rt6_info_route(struct rt6_inf
27491         struct seq_file *m = p_arg;
27492         struct neighbour *n;
27493  
27494 +       /* FIXME: check for network context? */
27495         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
27496  
27497  #ifdef CONFIG_IPV6_SUBTREES
27498 diff -NurpP --minimal linux-3.1/net/ipv6/tcp_ipv6.c linux-3.1-vs2.3.1-rc2/net/ipv6/tcp_ipv6.c
27499 --- linux-3.1/net/ipv6/tcp_ipv6.c       2011-10-24 18:45:34.000000000 +0200
27500 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/tcp_ipv6.c   2011-10-24 18:53:33.000000000 +0200
27501 @@ -70,6 +70,7 @@
27502  
27503  #include <linux/crypto.h>
27504  #include <linux/scatterlist.h>
27505 +#include <linux/vs_inet6.h>
27506  
27507  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27508  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27509 @@ -162,8 +163,15 @@ static int tcp_v6_connect(struct sock *s
27510          *      connect() to INADDR_ANY means loopback (BSD'ism).
27511          */
27512  
27513 -       if(ipv6_addr_any(&usin->sin6_addr))
27514 -               usin->sin6_addr.s6_addr[15] = 0x1;
27515 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27516 +               struct nx_info *nxi =  sk->sk_nx_info;
27517 +
27518 +               if (nxi && nx_info_has_v6(nxi))
27519 +                       /* FIXME: remap lback? */
27520 +                       usin->sin6_addr = nxi->v6.ip;
27521 +               else
27522 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27523 +       }
27524  
27525         addr_type = ipv6_addr_type(&usin->sin6_addr);
27526  
27527 diff -NurpP --minimal linux-3.1/net/ipv6/udp.c linux-3.1-vs2.3.1-rc2/net/ipv6/udp.c
27528 --- linux-3.1/net/ipv6/udp.c    2011-10-24 18:45:34.000000000 +0200
27529 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/udp.c        2011-10-24 18:53:33.000000000 +0200
27530 @@ -45,41 +45,67 @@
27531  #include <net/tcp_states.h>
27532  #include <net/ip6_checksum.h>
27533  #include <net/xfrm.h>
27534 +#include <linux/vs_inet6.h>
27535  
27536  #include <linux/proc_fs.h>
27537  #include <linux/seq_file.h>
27538  #include "udp_impl.h"
27539  
27540 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27541 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27542  {
27543 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27544 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
27545         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27546 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
27547 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
27548         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
27549 -       int sk_ipv6only = ipv6_only_sock(sk);
27550 +       int sk1_ipv6only = ipv6_only_sock(sk1);
27551         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27552 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27553 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
27554         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27555  
27556         /* if both are mapped, treat as IPv4 */
27557 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
27558 -               return (!sk2_ipv6only &&
27559 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
27560 +               if (!sk2_ipv6only &&
27561                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
27562 -                         sk1_rcv_saddr == sk2_rcv_saddr));
27563 +                         sk1_rcv_saddr == sk2_rcv_saddr))
27564 +                       goto vs_v4;
27565 +               else
27566 +                       return 0;
27567 +       }
27568  
27569         if (addr_type2 == IPV6_ADDR_ANY &&
27570             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27571 -               return 1;
27572 +               goto vs;
27573  
27574         if (addr_type == IPV6_ADDR_ANY &&
27575 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27576 -               return 1;
27577 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27578 +               goto vs;
27579  
27580         if (sk2_rcv_saddr6 &&
27581 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27582 -               return 1;
27583 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
27584 +               goto vs;
27585  
27586         return 0;
27587 +
27588 +vs_v4:
27589 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
27590 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
27591 +       if (!sk2_rcv_saddr)
27592 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
27593 +       if (!sk1_rcv_saddr)
27594 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
27595 +       return 1;
27596 +vs:
27597 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
27598 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
27599 +       else if (addr_type2 == IPV6_ADDR_ANY)
27600 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
27601 +       else if (addr_type == IPV6_ADDR_ANY) {
27602 +               if (addr_type2 == IPV6_ADDR_MAPPED)
27603 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
27604 +               else
27605 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
27606 +       }
27607 +       return 1;
27608  }
27609  
27610  static unsigned int udp6_portaddr_hash(struct net *net,
27611 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
27612                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27613                                 return -1;
27614                         score++;
27615 +               } else {
27616 +                       /* block non nx_info ips */
27617 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27618 +                               return -1;
27619                 }
27620                 if (!ipv6_addr_any(&np->daddr)) {
27621                         if (!ipv6_addr_equal(&np->daddr, saddr))
27622 diff -NurpP --minimal linux-3.1/net/ipv6/xfrm6_policy.c linux-3.1-vs2.3.1-rc2/net/ipv6/xfrm6_policy.c
27623 --- linux-3.1/net/ipv6/xfrm6_policy.c   2011-07-22 11:18:13.000000000 +0200
27624 +++ linux-3.1-vs2.3.1-rc2/net/ipv6/xfrm6_policy.c       2011-10-24 18:53:33.000000000 +0200
27625 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
27626         dev = ip6_dst_idev(dst)->dev;
27627         ipv6_dev_get_saddr(dev_net(dev), dev,
27628                            (struct in6_addr *)&daddr->a6, 0,
27629 -                          (struct in6_addr *)&saddr->a6);
27630 +                          (struct in6_addr *)&saddr->a6, NULL);
27631         dst_release(dst);
27632         return 0;
27633  }
27634 diff -NurpP --minimal linux-3.1/net/netfilter/ipvs/ip_vs_xmit.c linux-3.1-vs2.3.1-rc2/net/netfilter/ipvs/ip_vs_xmit.c
27635 --- linux-3.1/net/netfilter/ipvs/ip_vs_xmit.c   2011-07-22 11:18:13.000000000 +0200
27636 +++ linux-3.1-vs2.3.1-rc2/net/netfilter/ipvs/ip_vs_xmit.c       2011-10-24 18:53:33.000000000 +0200
27637 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
27638                 return dst;
27639         if (ipv6_addr_any(&fl6.saddr) &&
27640             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
27641 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
27642 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
27643                 goto out_err;
27644         if (do_xfrm) {
27645                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
27646 diff -NurpP --minimal linux-3.1/net/netlink/af_netlink.c linux-3.1-vs2.3.1-rc2/net/netlink/af_netlink.c
27647 --- linux-3.1/net/netlink/af_netlink.c  2011-10-24 18:45:34.000000000 +0200
27648 +++ linux-3.1-vs2.3.1-rc2/net/netlink/af_netlink.c      2011-10-24 18:53:33.000000000 +0200
27649 @@ -55,6 +55,9 @@
27650  #include <linux/types.h>
27651  #include <linux/audit.h>
27652  #include <linux/mutex.h>
27653 +#include <linux/vs_context.h>
27654 +#include <linux/vs_network.h>
27655 +#include <linux/vs_limit.h>
27656  
27657  #include <net/net_namespace.h>
27658  #include <net/sock.h>
27659 @@ -1913,6 +1916,8 @@ static struct sock *netlink_seq_socket_i
27660                         sk_for_each(s, node, &hash->table[j]) {
27661                                 if (sock_net(s) != seq_file_net(seq))
27662                                         continue;
27663 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27664 +                                       continue;
27665                                 if (off == pos) {
27666                                         iter->link = i;
27667                                         iter->hash_idx = j;
27668 @@ -1947,7 +1952,8 @@ static void *netlink_seq_next(struct seq
27669         s = v;
27670         do {
27671                 s = sk_next(s);
27672 -       } while (s && sock_net(s) != seq_file_net(seq));
27673 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27674 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27675         if (s)
27676                 return s;
27677  
27678 @@ -1959,7 +1965,8 @@ static void *netlink_seq_next(struct seq
27679  
27680                 for (; j <= hash->mask; j++) {
27681                         s = sk_head(&hash->table[j]);
27682 -                       while (s && sock_net(s) != seq_file_net(seq))
27683 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27684 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27685                                 s = sk_next(s);
27686                         if (s) {
27687                                 iter->link = i;
27688 diff -NurpP --minimal linux-3.1/net/socket.c linux-3.1-vs2.3.1-rc2/net/socket.c
27689 --- linux-3.1/net/socket.c      2011-10-24 18:45:34.000000000 +0200
27690 +++ linux-3.1-vs2.3.1-rc2/net/socket.c  2011-10-24 18:53:33.000000000 +0200
27691 @@ -98,6 +98,10 @@
27692  
27693  #include <net/sock.h>
27694  #include <linux/netfilter.h>
27695 +#include <linux/vs_base.h>
27696 +#include <linux/vs_socket.h>
27697 +#include <linux/vs_inet.h>
27698 +#include <linux/vs_inet6.h>
27699  
27700  #include <linux/if_tun.h>
27701  #include <linux/ipv6_route.h>
27702 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
27703                                        struct msghdr *msg, size_t size)
27704  {
27705         struct sock_iocb *si = kiocb_to_siocb(iocb);
27706 +       size_t len;
27707  
27708         sock_update_classid(sock->sk);
27709  
27710 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
27711         si->msg = msg;
27712         si->size = size;
27713  
27714 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27715 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27716 +       if (sock->sk) {
27717 +               if (len == size)
27718 +                       vx_sock_send(sock->sk, size);
27719 +               else
27720 +                       vx_sock_fail(sock->sk, size);
27721 +       }
27722 +       vxdprintk(VXD_CBIT(net, 7),
27723 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
27724 +               sock, sock->sk,
27725 +               (sock->sk)?sock->sk->sk_nx_info:0,
27726 +               (sock->sk)?sock->sk->sk_vx_info:0,
27727 +               (sock->sk)?sock->sk->sk_xid:0,
27728 +               (sock->sk)?sock->sk->sk_nid:0,
27729 +               (unsigned int)size, len);
27730 +       return len;
27731  }
27732  
27733  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
27734 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
27735                                        struct msghdr *msg, size_t size, int flags)
27736  {
27737         struct sock_iocb *si = kiocb_to_siocb(iocb);
27738 +       int len;
27739  
27740         sock_update_classid(sock->sk);
27741  
27742 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
27743         si->size = size;
27744         si->flags = flags;
27745  
27746 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27747 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27748 +       if ((len >= 0) && sock->sk)
27749 +               vx_sock_recv(sock->sk, len);
27750 +       vxdprintk(VXD_CBIT(net, 7),
27751 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27752 +               sock, sock->sk,
27753 +               (sock->sk)?sock->sk->sk_nx_info:0,
27754 +               (sock->sk)?sock->sk->sk_vx_info:0,
27755 +               (sock->sk)?sock->sk->sk_xid:0,
27756 +               (sock->sk)?sock->sk->sk_nid:0,
27757 +               (unsigned int)size, len);
27758 +       return len;
27759  }
27760  
27761  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27762 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
27763         if (type < 0 || type >= SOCK_MAX)
27764                 return -EINVAL;
27765  
27766 +       if (!nx_check(0, VS_ADMIN)) {
27767 +               if (family == PF_INET && !current_nx_info_has_v4())
27768 +                       return -EAFNOSUPPORT;
27769 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27770 +                       return -EAFNOSUPPORT;
27771 +       }
27772 +
27773         /* Compatibility.
27774  
27775            This uglymoron is moved from INET layer to here to avoid
27776 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
27777         if (retval < 0)
27778                 goto out;
27779  
27780 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27781         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27782         if (retval < 0)
27783                 goto out_release;
27784 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
27785         err = sock_create(family, type, protocol, &sock1);
27786         if (err < 0)
27787                 goto out;
27788 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27789  
27790         err = sock_create(family, type, protocol, &sock2);
27791         if (err < 0)
27792                 goto out_release_1;
27793 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27794  
27795         err = sock1->ops->socketpair(sock1, sock2);
27796         if (err < 0)
27797 diff -NurpP --minimal linux-3.1/net/sunrpc/auth.c linux-3.1-vs2.3.1-rc2/net/sunrpc/auth.c
27798 --- linux-3.1/net/sunrpc/auth.c 2011-10-24 18:45:34.000000000 +0200
27799 +++ linux-3.1-vs2.3.1-rc2/net/sunrpc/auth.c     2011-10-24 18:53:33.000000000 +0200
27800 @@ -14,6 +14,7 @@
27801  #include <linux/hash.h>
27802  #include <linux/sunrpc/clnt.h>
27803  #include <linux/spinlock.h>
27804 +#include <linux/vs_tag.h>
27805  
27806  #ifdef RPC_DEBUG
27807  # define RPCDBG_FACILITY       RPCDBG_AUTH
27808 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27809         memset(&acred, 0, sizeof(acred));
27810         acred.uid = cred->fsuid;
27811         acred.gid = cred->fsgid;
27812 +       acred.tag = dx_current_tag();
27813         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
27814  
27815         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
27816 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
27817         struct auth_cred acred = {
27818                 .uid = 0,
27819                 .gid = 0,
27820 +               .tag = dx_current_tag(),
27821         };
27822  
27823         dprintk("RPC: %5u looking up %s cred\n",
27824 diff -NurpP --minimal linux-3.1/net/sunrpc/auth_unix.c linux-3.1-vs2.3.1-rc2/net/sunrpc/auth_unix.c
27825 --- linux-3.1/net/sunrpc/auth_unix.c    2010-10-21 13:08:01.000000000 +0200
27826 +++ linux-3.1-vs2.3.1-rc2/net/sunrpc/auth_unix.c        2011-10-24 18:53:33.000000000 +0200
27827 @@ -12,12 +12,14 @@
27828  #include <linux/module.h>
27829  #include <linux/sunrpc/clnt.h>
27830  #include <linux/sunrpc/auth.h>
27831 +#include <linux/vs_tag.h>
27832  
27833  #define NFS_NGROUPS    16
27834  
27835  struct unx_cred {
27836         struct rpc_cred         uc_base;
27837         gid_t                   uc_gid;
27838 +       tag_t                   uc_tag;
27839         gid_t                   uc_gids[NFS_NGROUPS];
27840  };
27841  #define uc_uid                 uc_base.cr_uid
27842 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
27843                 groups = NFS_NGROUPS;
27844  
27845         cred->uc_gid = acred->gid;
27846 +       cred->uc_tag = acred->tag;
27847         for (i = 0; i < groups; i++)
27848                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
27849         if (i < NFS_NGROUPS)
27850 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
27851         unsigned int i;
27852  
27853  
27854 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
27855 +       if (cred->uc_uid != acred->uid ||
27856 +               cred->uc_gid != acred->gid ||
27857 +               cred->uc_tag != acred->tag)
27858                 return 0;
27859  
27860         if (acred->group_info != NULL)
27861 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
27862         struct rpc_clnt *clnt = task->tk_client;
27863         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
27864         __be32          *base, *hold;
27865 -       int             i;
27866 +       int             i, tag;
27867  
27868         *p++ = htonl(RPC_AUTH_UNIX);
27869         base = p++;
27870 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
27871          * Copy the UTS nodename captured when the client was created.
27872          */
27873         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
27874 +       tag = task->tk_client->cl_tag;
27875  
27876 -       *p++ = htonl((u32) cred->uc_uid);
27877 -       *p++ = htonl((u32) cred->uc_gid);
27878 +       *p++ = htonl((u32) TAGINO_UID(tag,
27879 +               cred->uc_uid, cred->uc_tag));
27880 +       *p++ = htonl((u32) TAGINO_GID(tag,
27881 +               cred->uc_gid, cred->uc_tag));
27882         hold = p++;
27883         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27884                 *p++ = htonl((u32) cred->uc_gids[i]);
27885 diff -NurpP --minimal linux-3.1/net/sunrpc/clnt.c linux-3.1-vs2.3.1-rc2/net/sunrpc/clnt.c
27886 --- linux-3.1/net/sunrpc/clnt.c 2011-10-24 18:45:34.000000000 +0200
27887 +++ linux-3.1-vs2.3.1-rc2/net/sunrpc/clnt.c     2011-10-24 18:53:33.000000000 +0200
27888 @@ -31,6 +31,7 @@
27889  #include <linux/in.h>
27890  #include <linux/in6.h>
27891  #include <linux/un.h>
27892 +#include <linux/vs_cvirt.h>
27893  
27894  #include <linux/sunrpc/clnt.h>
27895  #include <linux/sunrpc/rpc_pipe_fs.h>
27896 @@ -361,6 +362,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27897         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
27898                 clnt->cl_chatty = 1;
27899  
27900 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27901 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27902 +               clnt->cl_tag = 1; */
27903         return clnt;
27904  }
27905  EXPORT_SYMBOL_GPL(rpc_create);
27906 diff -NurpP --minimal linux-3.1/net/unix/af_unix.c linux-3.1-vs2.3.1-rc2/net/unix/af_unix.c
27907 --- linux-3.1/net/unix/af_unix.c        2011-10-24 18:45:34.000000000 +0200
27908 +++ linux-3.1-vs2.3.1-rc2/net/unix/af_unix.c    2011-10-24 18:53:33.000000000 +0200
27909 @@ -114,6 +114,8 @@
27910  #include <linux/mount.h>
27911  #include <net/checksum.h>
27912  #include <linux/security.h>
27913 +#include <linux/vs_context.h>
27914 +#include <linux/vs_limit.h>
27915  
27916  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
27917  static DEFINE_SPINLOCK(unix_table_lock);
27918 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
27919                 if (!net_eq(sock_net(s), net))
27920                         continue;
27921  
27922 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27923 +                       continue;
27924                 if (u->addr->len == len &&
27925                     !memcmp(u->addr->name, sunname, len))
27926                         goto found;
27927 @@ -2204,6 +2208,8 @@ static struct sock *unix_seq_idx(struct 
27928         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
27929                 if (sock_net(s) != seq_file_net(seq))
27930                         continue;
27931 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27932 +                       continue;
27933                 if (off == pos)
27934                         return s;
27935                 ++off;
27936 @@ -2228,7 +2234,8 @@ static void *unix_seq_next(struct seq_fi
27937                 sk = first_unix_socket(&iter->i);
27938         else
27939                 sk = next_unix_socket(&iter->i, sk);
27940 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
27941 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
27942 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
27943                 sk = next_unix_socket(&iter->i, sk);
27944         return sk;
27945  }
27946 diff -NurpP --minimal linux-3.1/scripts/checksyscalls.sh linux-3.1-vs2.3.1-rc2/scripts/checksyscalls.sh
27947 --- linux-3.1/scripts/checksyscalls.sh  2011-03-15 18:07:46.000000000 +0100
27948 +++ linux-3.1-vs2.3.1-rc2/scripts/checksyscalls.sh      2011-10-24 18:53:33.000000000 +0200
27949 @@ -193,7 +193,6 @@ cat << EOF
27950  #define __IGNORE_afs_syscall
27951  #define __IGNORE_getpmsg
27952  #define __IGNORE_putpmsg
27953 -#define __IGNORE_vserver
27954  EOF
27955  }
27956  
27957 diff -NurpP --minimal linux-3.1/security/commoncap.c linux-3.1-vs2.3.1-rc2/security/commoncap.c
27958 --- linux-3.1/security/commoncap.c      2011-07-22 11:18:14.000000000 +0200
27959 +++ linux-3.1-vs2.3.1-rc2/security/commoncap.c  2011-10-24 18:53:33.000000000 +0200
27960 @@ -62,6 +62,7 @@ int cap_netlink_recv(struct sk_buff *skb
27961                 return -EPERM;
27962         return 0;
27963  }
27964 +
27965  EXPORT_SYMBOL(cap_netlink_recv);
27966  
27967  /**
27968 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
27969  int cap_capable(struct task_struct *tsk, const struct cred *cred,
27970                 struct user_namespace *targ_ns, int cap, int audit)
27971  {
27972 +       struct vx_info *vxi = tsk->vx_info;
27973 +
27974         for (;;) {
27975                 /* The creator of the user namespace has all caps. */
27976                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
27977                         return 0;
27978  
27979                 /* Do we have the necessary capabilities? */
27980 -               if (targ_ns == cred->user->user_ns)
27981 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
27982 +               if (targ_ns == cred->user->user_ns) {
27983 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
27984 +                           cap_raised(cred->cap_effective, cap))
27985 +                               return 0;
27986 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
27987 +               }
27988  
27989                 /* Have we tried all of the parent namespaces? */
27990                 if (targ_ns == &init_user_ns)
27991 @@ -611,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
27992  
27993         if (!strncmp(name, XATTR_SECURITY_PREFIX,
27994                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
27995 -           !capable(CAP_SYS_ADMIN))
27996 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
27997                 return -EPERM;
27998         return 0;
27999  }
28000 @@ -637,7 +644,7 @@ int cap_inode_removexattr(struct dentry 
28001  
28002         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28003                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
28004 -           !capable(CAP_SYS_ADMIN))
28005 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28006                 return -EPERM;
28007         return 0;
28008  }
28009 diff -NurpP --minimal linux-3.1/security/selinux/hooks.c linux-3.1-vs2.3.1-rc2/security/selinux/hooks.c
28010 --- linux-3.1/security/selinux/hooks.c  2011-10-24 18:45:35.000000000 +0200
28011 +++ linux-3.1-vs2.3.1-rc2/security/selinux/hooks.c      2011-10-24 18:53:33.000000000 +0200
28012 @@ -67,7 +67,6 @@
28013  #include <linux/dccp.h>
28014  #include <linux/quota.h>
28015  #include <linux/un.h>          /* for Unix socket types */
28016 -#include <net/af_unix.h>       /* for Unix socket types */
28017  #include <linux/parser.h>
28018  #include <linux/nfs_mount.h>
28019  #include <net/ipv6.h>
This page took 2.967572 seconds and 4 git commands to generate.