]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 3.0.6
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.0.4/.config.inet linux-3.0.4-vs2.3.1-pre10.1/.config.inet
2 --- linux-3.0.4/.config.inet    1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.0.4-vs2.3.1-pre10.1/.config.inet    2011-06-13 14:55:18.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.0.4/Documentation/vserver/debug.txt linux-3.0.4-vs2.3.1-pre10.1/Documentation/vserver/debug.txt
1626 --- linux-3.0.4/Documentation/vserver/debug.txt 1970-01-01 01:00:00.000000000 +0100
1627 +++ linux-3.0.4-vs2.3.1-pre10.1/Documentation/vserver/debug.txt 2011-06-10 22:11:24.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.0.4/arch/alpha/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/Kconfig
1784 --- linux-3.0.4/arch/alpha/Kconfig      2011-07-22 11:17:32.000000000 +0200
1785 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/Kconfig      2011-06-10 22:11:24.000000000 +0200
1786 @@ -668,6 +668,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.0.4/arch/alpha/kernel/entry.S linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/kernel/entry.S
1796 --- linux-3.0.4/arch/alpha/kernel/entry.S       2010-10-21 13:06:45.000000000 +0200
1797 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/kernel/entry.S       2011-06-10 22:11:24.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.0.4/arch/alpha/kernel/ptrace.c linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/kernel/ptrace.c
1831 --- linux-3.0.4/arch/alpha/kernel/ptrace.c      2011-01-05 21:48:40.000000000 +0100
1832 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/kernel/ptrace.c      2011-06-10 22:11:24.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.0.4/arch/alpha/kernel/systbls.S linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/kernel/systbls.S
1842 --- linux-3.0.4/arch/alpha/kernel/systbls.S     2011-07-22 11:17:32.000000000 +0200
1843 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/kernel/systbls.S     2011-06-10 22:11:24.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.0.4/arch/alpha/kernel/traps.c linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/kernel/traps.c
1854 --- linux-3.0.4/arch/alpha/kernel/traps.c       2010-10-21 13:06:46.000000000 +0200
1855 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/alpha/kernel/traps.c       2011-06-10 22:11:24.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.0.4/arch/arm/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/arm/Kconfig
1867 --- linux-3.0.4/arch/arm/Kconfig        2011-07-22 11:17:32.000000000 +0200
1868 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/arm/Kconfig        2011-06-10 22:11:24.000000000 +0200
1869 @@ -2035,6 +2035,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.0.4/arch/arm/kernel/calls.S linux-3.0.4-vs2.3.1-pre10.1/arch/arm/kernel/calls.S
1879 --- linux-3.0.4/arch/arm/kernel/calls.S 2011-07-22 11:17:32.000000000 +0200
1880 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/arm/kernel/calls.S 2011-06-10 22:11:24.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.0.4/arch/arm/kernel/process.c linux-3.0.4-vs2.3.1-pre10.1/arch/arm/kernel/process.c
1891 --- linux-3.0.4/arch/arm/kernel/process.c       2011-05-22 16:16:47.000000000 +0200
1892 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/arm/kernel/process.c       2011-06-10 22:11:24.000000000 +0200
1893 @@ -315,7 +315,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.0.4/arch/arm/kernel/traps.c linux-3.0.4-vs2.3.1-pre10.1/arch/arm/kernel/traps.c
1904 --- linux-3.0.4/arch/arm/kernel/traps.c 2011-07-22 11:17:32.000000000 +0200
1905 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/arm/kernel/traps.c 2011-06-22 12:39:12.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.0.4/arch/cris/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/cris/Kconfig
1918 --- linux-3.0.4/arch/cris/Kconfig       2011-07-22 11:17:35.000000000 +0200
1919 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/cris/Kconfig       2011-06-10 22:11:24.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.0.4/arch/frv/kernel/kernel_thread.S linux-3.0.4-vs2.3.1-pre10.1/arch/frv/kernel/kernel_thread.S
1930 --- linux-3.0.4/arch/frv/kernel/kernel_thread.S 2008-12-25 00:26:37.000000000 +0100
1931 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/frv/kernel/kernel_thread.S 2011-06-10 22:11:24.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.0.4/arch/h8300/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/h8300/Kconfig
1942 --- linux-3.0.4/arch/h8300/Kconfig      2011-07-22 11:17:35.000000000 +0200
1943 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/h8300/Kconfig      2011-06-10 22:11:24.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.0.4/arch/ia64/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/Kconfig
1954 --- linux-3.0.4/arch/ia64/Kconfig       2011-07-22 11:17:35.000000000 +0200
1955 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/Kconfig       2011-06-10 22:11:24.000000000 +0200
1956 @@ -671,6 +671,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.0.4/arch/ia64/include/asm/tlb.h linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/include/asm/tlb.h
1966 --- linux-3.0.4/arch/ia64/include/asm/tlb.h     2011-07-22 11:17:35.000000000 +0200
1967 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/include/asm/tlb.h     2011-06-10 22:11:24.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.0.4/arch/ia64/kernel/entry.S linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/entry.S
1977 --- linux-3.0.4/arch/ia64/kernel/entry.S        2011-07-22 11:17:35.000000000 +0200
1978 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/entry.S        2011-06-10 22:11:24.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.0.4/arch/ia64/kernel/perfmon.c linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/perfmon.c
1989 --- linux-3.0.4/arch/ia64/kernel/perfmon.c      2011-03-15 18:06:39.000000000 +0100
1990 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/perfmon.c      2011-06-10 22:11:24.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.0.4/arch/ia64/kernel/process.c linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/process.c
2000 --- linux-3.0.4/arch/ia64/kernel/process.c      2011-03-15 18:06:39.000000000 +0100
2001 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/process.c      2011-06-10 22:11:24.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.0.4/arch/ia64/kernel/ptrace.c linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/ptrace.c
2014 --- linux-3.0.4/arch/ia64/kernel/ptrace.c       2011-01-05 21:48:59.000000000 +0100
2015 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/ptrace.c       2011-06-10 22:11:24.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.0.4/arch/ia64/kernel/traps.c linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/traps.c
2025 --- linux-3.0.4/arch/ia64/kernel/traps.c        2010-07-07 18:31:01.000000000 +0200
2026 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/kernel/traps.c        2011-06-10 22:11:24.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.0.4/arch/ia64/mm/fault.c linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/mm/fault.c
2052 --- linux-3.0.4/arch/ia64/mm/fault.c    2011-07-22 11:17:35.000000000 +0200
2053 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/ia64/mm/fault.c    2011-06-10 22:28:23.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.0.4/arch/m32r/kernel/traps.c linux-3.0.4-vs2.3.1-pre10.1/arch/m32r/kernel/traps.c
2063 --- linux-3.0.4/arch/m32r/kernel/traps.c        2009-12-03 20:01:57.000000000 +0100
2064 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/m32r/kernel/traps.c        2011-06-10 22:11:24.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.0.4/arch/m68k/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/m68k/Kconfig
2078 --- linux-3.0.4/arch/m68k/Kconfig       2011-07-22 11:17:35.000000000 +0200
2079 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/m68k/Kconfig       2011-06-10 22:11:24.000000000 +0200
2080 @@ -241,6 +241,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.0.4/arch/mips/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/mips/Kconfig
2090 --- linux-3.0.4/arch/mips/Kconfig       2011-07-22 11:17:35.000000000 +0200
2091 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/mips/Kconfig       2011-06-10 22:11:24.000000000 +0200
2092 @@ -2485,6 +2485,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.0.4/arch/mips/kernel/ptrace.c linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/ptrace.c
2102 --- linux-3.0.4/arch/mips/kernel/ptrace.c       2011-07-22 11:17:36.000000000 +0200
2103 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/ptrace.c       2011-06-10 22:11:24.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.0.4/arch/mips/kernel/scall32-o32.S linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/scall32-o32.S
2123 --- linux-3.0.4/arch/mips/kernel/scall32-o32.S  2011-07-22 11:17:36.000000000 +0200
2124 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/scall32-o32.S  2011-06-10 22:11:24.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.0.4/arch/mips/kernel/scall64-64.S linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/scall64-64.S
2135 --- linux-3.0.4/arch/mips/kernel/scall64-64.S   2011-07-22 11:17:36.000000000 +0200
2136 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/scall64-64.S   2011-06-10 22:11:24.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.0.4/arch/mips/kernel/scall64-n32.S linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/scall64-n32.S
2147 --- linux-3.0.4/arch/mips/kernel/scall64-n32.S  2011-07-22 11:17:36.000000000 +0200
2148 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/scall64-n32.S  2011-06-10 22:11:24.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.0.4/arch/mips/kernel/scall64-o32.S linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/scall64-o32.S
2159 --- linux-3.0.4/arch/mips/kernel/scall64-o32.S  2011-07-22 11:17:36.000000000 +0200
2160 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/scall64-o32.S  2011-06-10 22:11:24.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.0.4/arch/mips/kernel/traps.c linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/traps.c
2171 --- linux-3.0.4/arch/mips/kernel/traps.c        2011-05-22 16:17:00.000000000 +0200
2172 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/mips/kernel/traps.c        2011-06-10 22:11:24.000000000 +0200
2173 @@ -343,9 +343,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.0.4/arch/parisc/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/parisc/Kconfig
2188 --- linux-3.0.4/arch/parisc/Kconfig     2011-07-22 11:17:36.000000000 +0200
2189 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/parisc/Kconfig     2011-06-10 22:11:24.000000000 +0200
2190 @@ -279,6 +279,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.0.4/arch/parisc/kernel/syscall_table.S linux-3.0.4-vs2.3.1-pre10.1/arch/parisc/kernel/syscall_table.S
2200 --- linux-3.0.4/arch/parisc/kernel/syscall_table.S      2011-08-31 18:56:40.000000000 +0200
2201 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/parisc/kernel/syscall_table.S      2011-08-29 03:45:07.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.0.4/arch/parisc/kernel/traps.c linux-3.0.4-vs2.3.1-pre10.1/arch/parisc/kernel/traps.c
2212 --- linux-3.0.4/arch/parisc/kernel/traps.c      2009-09-10 15:25:40.000000000 +0200
2213 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/parisc/kernel/traps.c      2011-06-10 22:11:24.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.0.4/arch/parisc/mm/fault.c linux-3.0.4-vs2.3.1-pre10.1/arch/parisc/mm/fault.c
2238 --- linux-3.0.4/arch/parisc/mm/fault.c  2010-08-02 16:52:06.000000000 +0200
2239 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/parisc/mm/fault.c  2011-06-10 22:11:24.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.0.4/arch/powerpc/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/Kconfig
2253 --- linux-3.0.4/arch/powerpc/Kconfig    2011-07-22 11:17:36.000000000 +0200
2254 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/Kconfig    2011-06-10 22:11:24.000000000 +0200
2255 @@ -978,6 +978,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.0.4/arch/powerpc/include/asm/unistd.h linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/include/asm/unistd.h
2265 --- linux-3.0.4/arch/powerpc/include/asm/unistd.h       2011-07-22 11:17:40.000000000 +0200
2266 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/include/asm/unistd.h       2011-06-10 22:11:24.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.0.4/arch/powerpc/kernel/process.c linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/kernel/process.c
2277 --- linux-3.0.4/arch/powerpc/kernel/process.c   2011-07-22 11:17:40.000000000 +0200
2278 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/kernel/process.c   2011-06-10 22:11:24.000000000 +0200
2279 @@ -656,8 +656,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.0.4/arch/powerpc/kernel/traps.c linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/kernel/traps.c
2292 --- linux-3.0.4/arch/powerpc/kernel/traps.c     2011-07-22 11:17:40.000000000 +0200
2293 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/kernel/traps.c     2011-07-19 00:44:39.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.0.4/arch/powerpc/kernel/vdso.c linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/kernel/vdso.c
2307 --- linux-3.0.4/arch/powerpc/kernel/vdso.c      2011-05-22 16:17:02.000000000 +0200
2308 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/powerpc/kernel/vdso.c      2011-06-10 22:11:24.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.0.4/arch/s390/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/s390/Kconfig
2318 --- linux-3.0.4/arch/s390/Kconfig       2011-07-22 11:17:41.000000000 +0200
2319 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/s390/Kconfig       2011-07-01 11:35:34.000000000 +0200
2320 @@ -628,6 +628,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.0.4/arch/s390/include/asm/tlb.h linux-3.0.4-vs2.3.1-pre10.1/arch/s390/include/asm/tlb.h
2330 --- linux-3.0.4/arch/s390/include/asm/tlb.h     2011-07-22 11:17:41.000000000 +0200
2331 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/s390/include/asm/tlb.h     2011-06-15 02:40:14.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.0.4/arch/s390/include/asm/unistd.h linux-3.0.4-vs2.3.1-pre10.1/arch/s390/include/asm/unistd.h
2342 --- linux-3.0.4/arch/s390/include/asm/unistd.h  2011-07-22 11:17:41.000000000 +0200
2343 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/s390/include/asm/unistd.h  2011-06-10 22:11:24.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.0.4/arch/s390/kernel/ptrace.c linux-3.0.4-vs2.3.1-pre10.1/arch/s390/kernel/ptrace.c
2354 --- linux-3.0.4/arch/s390/kernel/ptrace.c       2011-03-15 18:06:45.000000000 +0100
2355 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/s390/kernel/ptrace.c       2011-06-10 22:11:24.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.0.4/arch/s390/kernel/syscalls.S linux-3.0.4-vs2.3.1-pre10.1/arch/s390/kernel/syscalls.S
2365 --- linux-3.0.4/arch/s390/kernel/syscalls.S     2011-07-22 11:17:41.000000000 +0200
2366 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/s390/kernel/syscalls.S     2011-06-10 22:11:24.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.0.4/arch/sh/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/sh/Kconfig
2377 --- linux-3.0.4/arch/sh/Kconfig 2011-07-22 11:17:41.000000000 +0200
2378 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/sh/Kconfig 2011-07-19 00:44:39.000000000 +0200
2379 @@ -893,6 +893,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.0.4/arch/sh/kernel/irq.c linux-3.0.4-vs2.3.1-pre10.1/arch/sh/kernel/irq.c
2389 --- linux-3.0.4/arch/sh/kernel/irq.c    2011-07-22 11:17:41.000000000 +0200
2390 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/sh/kernel/irq.c    2011-07-19 00:45:06.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.0.4/arch/sh/kernel/vsyscall/vsyscall.c linux-3.0.4-vs2.3.1-pre10.1/arch/sh/kernel/vsyscall/vsyscall.c
2400 --- linux-3.0.4/arch/sh/kernel/vsyscall/vsyscall.c      2011-05-22 16:17:07.000000000 +0200
2401 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/sh/kernel/vsyscall/vsyscall.c      2011-06-10 22:11:24.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.0.4/arch/sparc/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/Kconfig
2411 --- linux-3.0.4/arch/sparc/Kconfig      2011-07-22 11:17:41.000000000 +0200
2412 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/Kconfig      2011-06-15 02:40:14.000000000 +0200
2413 @@ -601,6 +601,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.0.4/arch/sparc/include/asm/tlb_64.h linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/include/asm/tlb_64.h
2423 --- linux-3.0.4/arch/sparc/include/asm/tlb_64.h 2011-07-22 11:17:42.000000000 +0200
2424 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/include/asm/tlb_64.h 2011-06-10 22:11:24.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.0.4/arch/sparc/include/asm/unistd.h linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/include/asm/unistd.h
2434 --- linux-3.0.4/arch/sparc/include/asm/unistd.h 2011-07-22 11:17:42.000000000 +0200
2435 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/include/asm/unistd.h 2011-06-10 22:11:24.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.0.4/arch/sparc/kernel/systbls_32.S linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/kernel/systbls_32.S
2446 --- linux-3.0.4/arch/sparc/kernel/systbls_32.S  2011-07-22 11:17:42.000000000 +0200
2447 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/kernel/systbls_32.S  2011-06-10 22:11:24.000000000 +0200
2448 @@ -70,7 +70,7 @@ sys_call_table:
2449  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
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.0.4/arch/sparc/kernel/systbls_64.S linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/kernel/systbls_64.S
2458 --- linux-3.0.4/arch/sparc/kernel/systbls_64.S  2011-07-22 11:17:42.000000000 +0200
2459 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/sparc/kernel/systbls_64.S  2011-06-10 22:11:24.000000000 +0200
2460 @@ -71,7 +71,7 @@ sys_call_table32:
2461  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
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_nfsservctl
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.0.4/arch/um/Kconfig.rest linux-3.0.4-vs2.3.1-pre10.1/arch/um/Kconfig.rest
2479 --- linux-3.0.4/arch/um/Kconfig.rest    2009-06-11 17:12:19.000000000 +0200
2480 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/um/Kconfig.rest    2011-06-10 22:11:24.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.0.4/arch/um/include/asm/tlb.h linux-3.0.4-vs2.3.1-pre10.1/arch/um/include/asm/tlb.h
2491 --- linux-3.0.4/arch/um/include/asm/tlb.h       2011-07-22 11:17:42.000000000 +0200
2492 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/um/include/asm/tlb.h       2011-06-10 22:11:24.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.0.4/arch/um/include/shared/kern_constants.h linux-3.0.4-vs2.3.1-pre10.1/arch/um/include/shared/kern_constants.h
2502 --- linux-3.0.4/arch/um/include/shared/kern_constants.h 1970-01-01 01:00:00.000000000 +0100
2503 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/um/include/shared/kern_constants.h 2011-06-10 22:11:24.000000000 +0200
2504 @@ -0,0 +1 @@
2505 +#include "../../../../include/generated/asm-offsets.h"
2506 diff -NurpP --minimal linux-3.0.4/arch/um/include/shared/user_constants.h linux-3.0.4-vs2.3.1-pre10.1/arch/um/include/shared/user_constants.h
2507 --- linux-3.0.4/arch/um/include/shared/user_constants.h 1970-01-01 01:00:00.000000000 +0100
2508 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/um/include/shared/user_constants.h 2011-06-10 22:11:24.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.0.4/arch/x86/Kconfig linux-3.0.4-vs2.3.1-pre10.1/arch/x86/Kconfig
2551 --- linux-3.0.4/arch/x86/Kconfig        2011-07-22 11:17:42.000000000 +0200
2552 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/x86/Kconfig        2011-07-22 11:20:39.000000000 +0200
2553 @@ -2159,6 +2159,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.0.4/arch/x86/ia32/ia32entry.S linux-3.0.4-vs2.3.1-pre10.1/arch/x86/ia32/ia32entry.S
2563 --- linux-3.0.4/arch/x86/ia32/ia32entry.S       2011-07-22 11:17:42.000000000 +0200
2564 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/x86/ia32/ia32entry.S       2011-06-10 22:11:24.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.0.4/arch/x86/include/asm/unistd_64.h linux-3.0.4-vs2.3.1-pre10.1/arch/x86/include/asm/unistd_64.h
2575 --- linux-3.0.4/arch/x86/include/asm/unistd_64.h        2011-07-22 11:17:43.000000000 +0200
2576 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/x86/include/asm/unistd_64.h        2011-06-10 22:11:24.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.0.4/arch/x86/kernel/syscall_table_32.S linux-3.0.4-vs2.3.1-pre10.1/arch/x86/kernel/syscall_table_32.S
2587 --- linux-3.0.4/arch/x86/kernel/syscall_table_32.S      2011-07-22 11:17:43.000000000 +0200
2588 +++ linux-3.0.4-vs2.3.1-pre10.1/arch/x86/kernel/syscall_table_32.S      2011-06-10 22:11:24.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.0.4/block/genhd.c linux-3.0.4-vs2.3.1-pre10.1/block/genhd.c
2599 --- linux-3.0.4/block/genhd.c   2011-07-22 11:17:43.000000000 +0200
2600 +++ linux-3.0.4-vs2.3.1-pre10.1/block/genhd.c   2011-07-01 11:35:34.000000000 +0200
2601 @@ -1154,17 +1154,17 @@ static int diskstats_show(struct seq_fil
2602                 cpu = part_stat_lock();
2603                 part_round_stats(cpu, hd);
2604                 part_stat_unlock();
2605 -               seq_printf(seqf, "%4d %7d %s %lu %lu %llu "
2606 -                          "%u %lu %lu %llu %u %u %u %u\n",
2607 +               seq_printf(seqf, "%4d %7d %s %lu %lu %lu "
2608 +                          "%u %lu %lu %lu %u %u %u %u\n",
2609                            MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
2610                            disk_name(gp, hd->partno, buf),
2611                            part_stat_read(hd, ios[READ]),
2612                            part_stat_read(hd, merges[READ]),
2613 -                          (unsigned long long)part_stat_read(hd, sectors[READ]),
2614 +                          part_stat_read(hd, sectors[READ]),
2615                            jiffies_to_msecs(part_stat_read(hd, ticks[READ])),
2616                            part_stat_read(hd, ios[WRITE]),
2617                            part_stat_read(hd, merges[WRITE]),
2618 -                          (unsigned long long)part_stat_read(hd, sectors[WRITE]),
2619 +                          part_stat_read(hd, sectors[WRITE]),
2620                            jiffies_to_msecs(part_stat_read(hd, ticks[WRITE])),
2621                            part_in_flight(hd),
2622                            jiffies_to_msecs(part_stat_read(hd, io_ticks)),
2623 diff -NurpP --minimal linux-3.0.4/drivers/block/Kconfig linux-3.0.4-vs2.3.1-pre10.1/drivers/block/Kconfig
2624 --- linux-3.0.4/drivers/block/Kconfig   2011-07-22 11:17:44.000000000 +0200
2625 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/block/Kconfig   2011-06-10 22:11:24.000000000 +0200
2626 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
2627  
2628  source "drivers/block/drbd/Kconfig"
2629  
2630 +config BLK_DEV_VROOT
2631 +       tristate "Virtual Root device support"
2632 +       depends on QUOTACTL
2633 +       ---help---
2634 +         Saying Y here will allow you to use quota/fs ioctls on a shared
2635 +         partition within a virtual server without compromising security.
2636 +
2637  config BLK_DEV_NBD
2638         tristate "Network block device support"
2639         depends on NET
2640 diff -NurpP --minimal linux-3.0.4/drivers/block/Makefile linux-3.0.4-vs2.3.1-pre10.1/drivers/block/Makefile
2641 --- linux-3.0.4/drivers/block/Makefile  2011-07-22 11:17:44.000000000 +0200
2642 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/block/Makefile  2011-06-10 22:11:24.000000000 +0200
2643 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
2644  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
2645  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
2646  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
2647 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
2648  
2649  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
2650  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
2651 diff -NurpP --minimal linux-3.0.4/drivers/block/loop.c linux-3.0.4-vs2.3.1-pre10.1/drivers/block/loop.c
2652 --- linux-3.0.4/drivers/block/loop.c    2011-08-31 18:56:40.000000000 +0200
2653 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/block/loop.c    2011-08-31 19:37:44.000000000 +0200
2654 @@ -75,6 +75,7 @@
2655  #include <linux/kthread.h>
2656  #include <linux/splice.h>
2657  #include <linux/sysfs.h>
2658 +#include <linux/vs_context.h>
2659  
2660  #include <asm/uaccess.h>
2661  
2662 @@ -891,6 +892,7 @@ static int loop_set_fd(struct loop_devic
2663         lo->lo_blocksize = lo_blocksize;
2664         lo->lo_device = bdev;
2665         lo->lo_flags = lo_flags;
2666 +       lo->lo_xid = vx_current_xid();
2667         lo->lo_backing_file = file;
2668         lo->transfer = transfer_none;
2669         lo->ioctl = NULL;
2670 @@ -1021,6 +1023,7 @@ static int loop_clr_fd(struct loop_devic
2671         lo->lo_encrypt_key_size = 0;
2672         lo->lo_flags = 0;
2673         lo->lo_thread = NULL;
2674 +       lo->lo_xid = 0;
2675         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
2676         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
2677         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
2678 @@ -1059,7 +1062,7 @@ loop_set_status(struct loop_device *lo, 
2679  
2680         if (lo->lo_encrypt_key_size &&
2681             lo->lo_key_owner != uid &&
2682 -           !capable(CAP_SYS_ADMIN))
2683 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
2684                 return -EPERM;
2685         if (lo->lo_state != Lo_bound)
2686                 return -ENXIO;
2687 @@ -1143,7 +1146,8 @@ loop_get_status(struct loop_device *lo, 
2688         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
2689         info->lo_encrypt_type =
2690                 lo->lo_encryption ? lo->lo_encryption->number : 0;
2691 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
2692 +       if (lo->lo_encrypt_key_size &&
2693 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
2694                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
2695                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
2696                        lo->lo_encrypt_key_size);
2697 @@ -1489,6 +1493,9 @@ static int lo_open(struct block_device *
2698  {
2699         struct loop_device *lo = bdev->bd_disk->private_data;
2700  
2701 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
2702 +               return -EACCES;
2703 +
2704         mutex_lock(&lo->lo_ctl_mutex);
2705         lo->lo_refcnt++;
2706         mutex_unlock(&lo->lo_ctl_mutex);
2707 diff -NurpP --minimal linux-3.0.4/drivers/block/vroot.c linux-3.0.4-vs2.3.1-pre10.1/drivers/block/vroot.c
2708 --- linux-3.0.4/drivers/block/vroot.c   1970-01-01 01:00:00.000000000 +0100
2709 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/block/vroot.c   2011-06-10 22:11:24.000000000 +0200
2710 @@ -0,0 +1,292 @@
2711 +/*
2712 + *  linux/drivers/block/vroot.c
2713 + *
2714 + *  written by Herbert Pötzl, 9/11/2002
2715 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
2716 + *
2717 + *  based on the loop.c code by Theodore Ts'o.
2718 + *
2719 + * Copyright (C) 2002-2007 by Herbert Pötzl.
2720 + * Redistribution of this file is permitted under the
2721 + * GNU General Public License.
2722 + *
2723 + */
2724 +
2725 +#include <linux/module.h>
2726 +#include <linux/moduleparam.h>
2727 +#include <linux/file.h>
2728 +#include <linux/major.h>
2729 +#include <linux/blkdev.h>
2730 +#include <linux/slab.h>
2731 +
2732 +#include <linux/vroot.h>
2733 +#include <linux/vs_context.h>
2734 +
2735 +
2736 +static int max_vroot = 8;
2737 +
2738 +static struct vroot_device *vroot_dev;
2739 +static struct gendisk **disks;
2740 +
2741 +
2742 +static int vroot_set_dev(
2743 +       struct vroot_device *vr,
2744 +       struct block_device *bdev,
2745 +       unsigned int arg)
2746 +{
2747 +       struct block_device *real_bdev;
2748 +       struct file *file;
2749 +       struct inode *inode;
2750 +       int error;
2751 +
2752 +       error = -EBUSY;
2753 +       if (vr->vr_state != Vr_unbound)
2754 +               goto out;
2755 +
2756 +       error = -EBADF;
2757 +       file = fget(arg);
2758 +       if (!file)
2759 +               goto out;
2760 +
2761 +       error = -EINVAL;
2762 +       inode = file->f_dentry->d_inode;
2763 +
2764 +
2765 +       if (S_ISBLK(inode->i_mode)) {
2766 +               real_bdev = inode->i_bdev;
2767 +               vr->vr_device = real_bdev;
2768 +               __iget(real_bdev->bd_inode);
2769 +       } else
2770 +               goto out_fput;
2771 +
2772 +       vxdprintk(VXD_CBIT(misc, 0),
2773 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
2774 +               vr->vr_number, VXD_DEV(real_bdev));
2775 +
2776 +       vr->vr_state = Vr_bound;
2777 +       error = 0;
2778 +
2779 + out_fput:
2780 +       fput(file);
2781 + out:
2782 +       return error;
2783 +}
2784 +
2785 +static int vroot_clr_dev(
2786 +       struct vroot_device *vr,
2787 +       struct block_device *bdev)
2788 +{
2789 +       struct block_device *real_bdev;
2790 +
2791 +       if (vr->vr_state != Vr_bound)
2792 +               return -ENXIO;
2793 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
2794 +               return -EBUSY;
2795 +
2796 +       real_bdev = vr->vr_device;
2797 +
2798 +       vxdprintk(VXD_CBIT(misc, 0),
2799 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
2800 +               vr->vr_number, VXD_DEV(real_bdev));
2801 +
2802 +       bdput(real_bdev);
2803 +       vr->vr_state = Vr_unbound;
2804 +       vr->vr_device = NULL;
2805 +       return 0;
2806 +}
2807 +
2808 +
2809 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
2810 +       unsigned int cmd, unsigned long arg)
2811 +{
2812 +       struct vroot_device *vr = bdev->bd_disk->private_data;
2813 +       int err;
2814 +
2815 +       down(&vr->vr_ctl_mutex);
2816 +       switch (cmd) {
2817 +       case VROOT_SET_DEV:
2818 +               err = vroot_set_dev(vr, bdev, arg);
2819 +               break;
2820 +       case VROOT_CLR_DEV:
2821 +               err = vroot_clr_dev(vr, bdev);
2822 +               break;
2823 +       default:
2824 +               err = -EINVAL;
2825 +               break;
2826 +       }
2827 +       up(&vr->vr_ctl_mutex);
2828 +       return err;
2829 +}
2830 +
2831 +static int vr_open(struct block_device *bdev, fmode_t mode)
2832 +{
2833 +       struct vroot_device *vr = bdev->bd_disk->private_data;
2834 +
2835 +       down(&vr->vr_ctl_mutex);
2836 +       vr->vr_refcnt++;
2837 +       up(&vr->vr_ctl_mutex);
2838 +       return 0;
2839 +}
2840 +
2841 +static int vr_release(struct gendisk *disk, fmode_t mode)
2842 +{
2843 +       struct vroot_device *vr = disk->private_data;
2844 +
2845 +       down(&vr->vr_ctl_mutex);
2846 +       --vr->vr_refcnt;
2847 +       up(&vr->vr_ctl_mutex);
2848 +       return 0;
2849 +}
2850 +
2851 +static struct block_device_operations vr_fops = {
2852 +       .owner =        THIS_MODULE,
2853 +       .open =         vr_open,
2854 +       .release =      vr_release,
2855 +       .ioctl =        vr_ioctl,
2856 +};
2857 +
2858 +static int vroot_make_request(struct request_queue *q, struct bio *bio)
2859 +{
2860 +       printk("vroot_make_request %p, %p\n", q, bio);
2861 +       bio_io_error(bio);
2862 +       return 0;
2863 +}
2864 +
2865 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
2866 +{
2867 +       struct inode *inode = bdev->bd_inode;
2868 +       struct vroot_device *vr;
2869 +       struct block_device *real_bdev;
2870 +       int minor = iminor(inode);
2871 +
2872 +       vr = &vroot_dev[minor];
2873 +       real_bdev = vr->vr_device;
2874 +
2875 +       vxdprintk(VXD_CBIT(misc, 0),
2876 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
2877 +               vr->vr_number, VXD_DEV(real_bdev));
2878 +
2879 +       if (vr->vr_state != Vr_bound)
2880 +               return ERR_PTR(-ENXIO);
2881 +
2882 +       __iget(real_bdev->bd_inode);
2883 +       return real_bdev;
2884 +}
2885 +
2886 +
2887 +
2888 +/*
2889 + * And now the modules code and kernel interface.
2890 + */
2891 +
2892 +module_param(max_vroot, int, 0);
2893 +
2894 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
2895 +MODULE_LICENSE("GPL");
2896 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
2897 +
2898 +MODULE_AUTHOR ("Herbert Pötzl");
2899 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
2900 +
2901 +
2902 +int __init vroot_init(void)
2903 +{
2904 +       int err, i;
2905 +
2906 +       if (max_vroot < 1 || max_vroot > 256) {
2907 +               max_vroot = MAX_VROOT_DEFAULT;
2908 +               printk(KERN_WARNING "vroot: invalid max_vroot "
2909 +                       "(must be between 1 and 256), "
2910 +                       "using default (%d)\n", max_vroot);
2911 +       }
2912 +
2913 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
2914 +               return -EIO;
2915 +
2916 +       err = -ENOMEM;
2917 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
2918 +       if (!vroot_dev)
2919 +               goto out_mem1;
2920 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
2921 +
2922 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
2923 +       if (!disks)
2924 +               goto out_mem2;
2925 +
2926 +       for (i = 0; i < max_vroot; i++) {
2927 +               disks[i] = alloc_disk(1);
2928 +               if (!disks[i])
2929 +                       goto out_mem3;
2930 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
2931 +               if (!disks[i]->queue)
2932 +                       goto out_mem3;
2933 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
2934 +       }
2935 +
2936 +       for (i = 0; i < max_vroot; i++) {
2937 +               struct vroot_device *vr = &vroot_dev[i];
2938 +               struct gendisk *disk = disks[i];
2939 +
2940 +               memset(vr, 0, sizeof(*vr));
2941 +               sema_init(&vr->vr_ctl_mutex, 1);
2942 +               vr->vr_number = i;
2943 +               disk->major = VROOT_MAJOR;
2944 +               disk->first_minor = i;
2945 +               disk->fops = &vr_fops;
2946 +               sprintf(disk->disk_name, "vroot%d", i);
2947 +               disk->private_data = vr;
2948 +       }
2949 +
2950 +       err = register_vroot_grb(&__vroot_get_real_bdev);
2951 +       if (err)
2952 +               goto out_mem3;
2953 +
2954 +       for (i = 0; i < max_vroot; i++)
2955 +               add_disk(disks[i]);
2956 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
2957 +       return 0;
2958 +
2959 +out_mem3:
2960 +       while (i--)
2961 +               put_disk(disks[i]);
2962 +       kfree(disks);
2963 +out_mem2:
2964 +       kfree(vroot_dev);
2965 +out_mem1:
2966 +       unregister_blkdev(VROOT_MAJOR, "vroot");
2967 +       printk(KERN_ERR "vroot: ran out of memory\n");
2968 +       return err;
2969 +}
2970 +
2971 +void vroot_exit(void)
2972 +{
2973 +       int i;
2974 +
2975 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
2976 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
2977 +
2978 +       for (i = 0; i < max_vroot; i++) {
2979 +               del_gendisk(disks[i]);
2980 +               put_disk(disks[i]);
2981 +       }
2982 +       unregister_blkdev(VROOT_MAJOR, "vroot");
2983 +
2984 +       kfree(disks);
2985 +       kfree(vroot_dev);
2986 +}
2987 +
2988 +module_init(vroot_init);
2989 +module_exit(vroot_exit);
2990 +
2991 +#ifndef MODULE
2992 +
2993 +static int __init max_vroot_setup(char *str)
2994 +{
2995 +       max_vroot = simple_strtol(str, NULL, 0);
2996 +       return 1;
2997 +}
2998 +
2999 +__setup("max_vroot=", max_vroot_setup);
3000 +
3001 +#endif
3002 +
3003 diff -NurpP --minimal linux-3.0.4/drivers/gpu/drm/radeon/r100_reg_safe.h linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/r100_reg_safe.h
3004 --- linux-3.0.4/drivers/gpu/drm/radeon/r100_reg_safe.h  1970-01-01 01:00:00.000000000 +0100
3005 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/r100_reg_safe.h  2011-06-10 22:11:24.000000000 +0200
3006 @@ -0,0 +1,28 @@
3007 +static const unsigned r100_reg_safe_bm[102] = {
3008 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3009 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3010 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3011 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3012 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3013 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3014 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3015 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3016 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3017 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3018 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
3019 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
3020 +       0xFFFFFFCF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3021 +       0xFFFFFF9F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3022 +       0x38E7FE1F, 0xFFC3FF8E, 0x7FF8FFFF, 0xFFFF803C,
3023 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3024 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFFFF, 0xFFFFFFFF,
3025 +       0x00000000, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF,
3026 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3027 +       0xFFFFFFFF, 0xFFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3028 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3029 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3030 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3031 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3032 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3033 +       0xFFFFFFFF, 0xFFFFFFEF,
3034 +};
3035 diff -NurpP --minimal linux-3.0.4/drivers/gpu/drm/radeon/r200_reg_safe.h linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/r200_reg_safe.h
3036 --- linux-3.0.4/drivers/gpu/drm/radeon/r200_reg_safe.h  1970-01-01 01:00:00.000000000 +0100
3037 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/r200_reg_safe.h  2011-06-10 22:11:24.000000000 +0200
3038 @@ -0,0 +1,28 @@
3039 +static const unsigned r200_reg_safe_bm[102] = {
3040 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3041 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3042 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3043 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3044 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3045 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3046 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3047 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3048 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3049 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3050 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
3051 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
3052 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3053 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3054 +       0xFFE7FE1F, 0xF003FFFF, 0x7EFFFFFF, 0xFFFF803C,
3055 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3056 +       0xFFFFFFFF, 0xFFFFEFCE, 0xFFFEFFFF, 0xFFFFFFFE,
3057 +       0x020E0FF0, 0xFFCC83FD, 0xFFFFFFFF, 0xFFFFFFFF,
3058 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3059 +       0xFFFBFFFF, 0xEFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3060 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3061 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3062 +       0xDFDFDFDF, 0x3FFDDFDF, 0xFFFFFFFF, 0xFFFFFF7F,
3063 +       0xFFFFFFFF, 0x00FFFFFF, 0x00000000, 0x00000000,
3064 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3065 +       0xFFFFFE3F, 0xFFFFFFEF,
3066 +};
3067 diff -NurpP --minimal linux-3.0.4/drivers/gpu/drm/radeon/r300_reg_safe.h linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/r300_reg_safe.h
3068 --- linux-3.0.4/drivers/gpu/drm/radeon/r300_reg_safe.h  1970-01-01 01:00:00.000000000 +0100
3069 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/r300_reg_safe.h  2011-06-10 22:11:24.000000000 +0200
3070 @@ -0,0 +1,42 @@
3071 +static const unsigned r300_reg_safe_bm[159] = {
3072 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3073 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3074 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3075 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3076 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3077 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3078 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3079 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3080 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3081 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3082 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
3083 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
3084 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3085 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3086 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
3087 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3088 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
3089 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
3090 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3091 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3092 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3093 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3094 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3095 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3096 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3097 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3098 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3099 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3100 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3101 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3102 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3103 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3104 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
3105 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
3106 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
3107 +       0x00000000, 0x0000C100, 0x00000000, 0x00000000,
3108 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
3109 +       0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFF80FFFF,
3110 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
3111 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
3112 +};
3113 diff -NurpP --minimal linux-3.0.4/drivers/gpu/drm/radeon/r420_reg_safe.h linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/r420_reg_safe.h
3114 --- linux-3.0.4/drivers/gpu/drm/radeon/r420_reg_safe.h  1970-01-01 01:00:00.000000000 +0100
3115 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/r420_reg_safe.h  2011-06-10 22:11:24.000000000 +0200
3116 @@ -0,0 +1,42 @@
3117 +static const unsigned r420_reg_safe_bm[159] = {
3118 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3119 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3120 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3121 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3122 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3123 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3124 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3125 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3126 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3127 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3128 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
3129 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
3130 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3131 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3132 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
3133 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3134 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
3135 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
3136 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3137 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3138 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3139 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3140 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3141 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3142 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3143 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3144 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3145 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3146 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3147 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3148 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3149 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3150 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
3151 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
3152 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
3153 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
3154 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
3155 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
3156 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
3157 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
3158 +};
3159 diff -NurpP --minimal linux-3.0.4/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/rn50_reg_safe.h
3160 --- linux-3.0.4/drivers/gpu/drm/radeon/rn50_reg_safe.h  1970-01-01 01:00:00.000000000 +0100
3161 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/rn50_reg_safe.h  2011-06-10 22:11:24.000000000 +0200
3162 @@ -0,0 +1,28 @@
3163 +static const unsigned rn50_reg_safe_bm[102] = {
3164 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3165 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3166 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3167 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3168 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3169 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3170 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3171 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3172 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3173 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3174 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
3175 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
3176 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3177 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3178 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3179 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3180 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3181 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3182 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3183 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3184 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3185 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3186 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3187 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3188 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3189 +       0xFFFFFFFF, 0xFFFFFFFF,
3190 +};
3191 diff -NurpP --minimal linux-3.0.4/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/rs600_reg_safe.h
3192 --- linux-3.0.4/drivers/gpu/drm/radeon/rs600_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
3193 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/rs600_reg_safe.h 2011-06-10 22:11:24.000000000 +0200
3194 @@ -0,0 +1,57 @@
3195 +static const unsigned rs600_reg_safe_bm[219] = {
3196 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3197 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3198 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3199 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3200 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3201 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3202 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3203 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3204 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3205 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3206 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
3207 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
3208 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3209 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3210 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
3211 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3212 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
3213 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
3214 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3215 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3216 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3217 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3218 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3219 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3220 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3221 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3222 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3223 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3224 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3225 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3226 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3227 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3228 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
3229 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
3230 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
3231 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
3232 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
3233 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
3234 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
3235 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19, 0xFFFFFFFF,
3236 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3237 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3238 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3239 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3240 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3241 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3242 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3243 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3244 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3245 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3246 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3247 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3248 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3249 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3250 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3251 +};
3252 diff -NurpP --minimal linux-3.0.4/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/rv515_reg_safe.h
3253 --- linux-3.0.4/drivers/gpu/drm/radeon/rv515_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
3254 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/gpu/drm/radeon/rv515_reg_safe.h 2011-06-10 22:11:24.000000000 +0200
3255 @@ -0,0 +1,57 @@
3256 +static const unsigned rv515_reg_safe_bm[219] = {
3257 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3258 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3259 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3260 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3261 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3262 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3263 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3264 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3265 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3266 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3267 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
3268 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
3269 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3270 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3271 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
3272 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3273 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
3274 +       0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
3275 +       0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
3276 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3277 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3278 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3279 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3280 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3281 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3282 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3283 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3284 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3285 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3286 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3287 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3288 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3289 +       0x1FFFF878, 0xFFFFE000, 0xFFFFFE1E, 0xFFFFFFFF,
3290 +       0x388F8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
3291 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
3292 +       0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
3293 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3294 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
3295 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
3296 +       0x0003FC01, 0x3FFFFCF8, 0xFF800B19, 0xFFDFFFFF,
3297 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3298 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3299 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3300 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3301 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3302 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3303 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3304 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3305 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3306 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3307 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3308 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3309 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3310 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3311 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3312 +};
3313 diff -NurpP --minimal linux-3.0.4/drivers/infiniband/core/addr.c linux-3.0.4-vs2.3.1-pre10.1/drivers/infiniband/core/addr.c
3314 --- linux-3.0.4/drivers/infiniband/core/addr.c  2011-07-22 11:17:45.000000000 +0200
3315 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/infiniband/core/addr.c  2011-06-16 14:16:51.000000000 +0200
3316 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
3317  
3318         if (ipv6_addr_any(&fl6.saddr)) {
3319                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
3320 -                                        &fl6.daddr, 0, &fl6.saddr);
3321 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
3322                 if (ret)
3323                         goto put;
3324  
3325 diff -NurpP --minimal linux-3.0.4/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-3.0.4-vs2.3.1-pre10.1/drivers/infiniband/hw/ipath/ipath_user_pages.c
3326 --- linux-3.0.4/drivers/infiniband/hw/ipath/ipath_user_pages.c  2011-05-22 16:17:16.000000000 +0200
3327 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/infiniband/hw/ipath/ipath_user_pages.c  2011-06-10 22:11:24.000000000 +0200
3328 @@ -35,6 +35,7 @@
3329  #include <linux/device.h>
3330  #include <linux/slab.h>
3331  #include <linux/sched.h>
3332 +#include <linux/vs_memory.h>
3333  
3334  #include "ipath_kernel.h"
3335  
3336 diff -NurpP --minimal linux-3.0.4/drivers/md/dm-ioctl.c linux-3.0.4-vs2.3.1-pre10.1/drivers/md/dm-ioctl.c
3337 --- linux-3.0.4/drivers/md/dm-ioctl.c   2011-05-22 16:17:18.000000000 +0200
3338 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/md/dm-ioctl.c   2011-06-10 22:11:24.000000000 +0200
3339 @@ -16,6 +16,7 @@
3340  #include <linux/dm-ioctl.h>
3341  #include <linux/hdreg.h>
3342  #include <linux/compat.h>
3343 +#include <linux/vs_context.h>
3344  
3345  #include <asm/uaccess.h>
3346  
3347 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
3348         unsigned int h = hash_str(str);
3349  
3350         list_for_each_entry (hc, _name_buckets + h, name_list)
3351 -               if (!strcmp(hc->name, str)) {
3352 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
3353 +                       !strcmp(hc->name, str)) {
3354                         dm_get(hc->md);
3355                         return hc;
3356                 }
3357 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
3358         unsigned int h = hash_str(str);
3359  
3360         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
3361 -               if (!strcmp(hc->uuid, str)) {
3362 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
3363 +                       !strcmp(hc->uuid, str)) {
3364                         dm_get(hc->md);
3365                         return hc;
3366                 }
3367 @@ -427,6 +430,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
3368  
3369  static int remove_all(struct dm_ioctl *param, size_t param_size)
3370  {
3371 +       if (!vx_check(0, VS_ADMIN))
3372 +               return -EPERM;
3373 +
3374         dm_hash_remove_all(1);
3375         param->data_size = 0;
3376         return 0;
3377 @@ -474,6 +480,8 @@ static int list_devices(struct dm_ioctl 
3378          */
3379         for (i = 0; i < NUM_BUCKETS; i++) {
3380                 list_for_each_entry (hc, _name_buckets + i, name_list) {
3381 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
3382 +                               continue;
3383                         needed += sizeof(struct dm_name_list);
3384                         needed += strlen(hc->name) + 1;
3385                         needed += ALIGN_MASK;
3386 @@ -497,6 +505,8 @@ static int list_devices(struct dm_ioctl 
3387          */
3388         for (i = 0; i < NUM_BUCKETS; i++) {
3389                 list_for_each_entry (hc, _name_buckets + i, name_list) {
3390 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
3391 +                               continue;
3392                         if (old_nl)
3393                                 old_nl->next = (uint32_t) ((void *) nl -
3394                                                            (void *) old_nl);
3395 @@ -731,10 +741,11 @@ static struct hash_cell *__find_device_h
3396         if (!md)
3397                 goto out;
3398  
3399 -       mdptr = dm_get_mdptr(md);
3400 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
3401 +               mdptr = dm_get_mdptr(md);
3402 +
3403         if (!mdptr)
3404                 dm_put(md);
3405 -
3406  out:
3407         return mdptr;
3408  }
3409 @@ -1577,8 +1588,8 @@ static int ctl_ioctl(uint command, struc
3410         ioctl_fn fn = NULL;
3411         size_t input_param_size;
3412  
3413 -       /* only root can play with this */
3414 -       if (!capable(CAP_SYS_ADMIN))
3415 +       /* only root and certain contexts can play with this */
3416 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
3417                 return -EACCES;
3418  
3419         if (_IOC_TYPE(command) != DM_IOCTL)
3420 diff -NurpP --minimal linux-3.0.4/drivers/md/dm.c linux-3.0.4-vs2.3.1-pre10.1/drivers/md/dm.c
3421 --- linux-3.0.4/drivers/md/dm.c 2011-08-31 18:56:41.000000000 +0200
3422 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/md/dm.c 2011-08-08 23:04:47.000000000 +0200
3423 @@ -20,6 +20,7 @@
3424  #include <linux/idr.h>
3425  #include <linux/hdreg.h>
3426  #include <linux/delay.h>
3427 +#include <linux/vs_base.h>
3428  
3429  #include <trace/events/block.h>
3430  
3431 @@ -121,6 +122,7 @@ struct mapped_device {
3432         rwlock_t map_lock;
3433         atomic_t holders;
3434         atomic_t open_count;
3435 +       xid_t xid;
3436  
3437         unsigned long flags;
3438  
3439 @@ -334,6 +336,7 @@ int dm_deleting_md(struct mapped_device 
3440  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
3441  {
3442         struct mapped_device *md;
3443 +       int ret = -ENXIO;
3444  
3445         spin_lock(&_minor_lock);
3446  
3447 @@ -342,18 +345,19 @@ static int dm_blk_open(struct block_devi
3448                 goto out;
3449  
3450         if (test_bit(DMF_FREEING, &md->flags) ||
3451 -           dm_deleting_md(md)) {
3452 -               md = NULL;
3453 +           dm_deleting_md(md))
3454 +               goto out;
3455 +
3456 +       ret = -EACCES;
3457 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
3458                 goto out;
3459 -       }
3460  
3461         dm_get(md);
3462         atomic_inc(&md->open_count);
3463 -
3464 +       ret = 0;
3465  out:
3466         spin_unlock(&_minor_lock);
3467 -
3468 -       return md ? 0 : -ENXIO;
3469 +       return ret;
3470  }
3471  
3472  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
3473 @@ -574,6 +578,14 @@ int dm_set_geometry(struct mapped_device
3474         return 0;
3475  }
3476  
3477 +/*
3478 + * Get the xid associated with a dm device
3479 + */
3480 +xid_t dm_get_xid(struct mapped_device *md)
3481 +{
3482 +       return md->xid;
3483 +}
3484 +
3485  /*-----------------------------------------------------------------
3486   * CRUD START:
3487   *   A more elegant soln is in the works that uses the queue
3488 @@ -1847,6 +1859,7 @@ static struct mapped_device *alloc_dev(i
3489         INIT_LIST_HEAD(&md->uevent_list);
3490         spin_lock_init(&md->uevent_lock);
3491  
3492 +       md->xid = vx_current_xid();
3493         md->queue = blk_alloc_queue(GFP_KERNEL);
3494         if (!md->queue)
3495                 goto bad_queue;
3496 diff -NurpP --minimal linux-3.0.4/drivers/md/dm.h linux-3.0.4-vs2.3.1-pre10.1/drivers/md/dm.h
3497 --- linux-3.0.4/drivers/md/dm.h 2011-05-22 16:17:18.000000000 +0200
3498 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/md/dm.h 2011-06-10 22:11:24.000000000 +0200
3499 @@ -41,6 +41,8 @@ struct dm_dev_internal {
3500  struct dm_table;
3501  struct dm_md_mempools;
3502  
3503 +xid_t dm_get_xid(struct mapped_device *md);
3504 +
3505  /*-----------------------------------------------------------------
3506   * Internal table functions.
3507   *---------------------------------------------------------------*/
3508 diff -NurpP --minimal linux-3.0.4/drivers/net/tun.c linux-3.0.4-vs2.3.1-pre10.1/drivers/net/tun.c
3509 --- linux-3.0.4/drivers/net/tun.c       2011-08-31 18:56:41.000000000 +0200
3510 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/net/tun.c       2011-08-29 03:45:08.000000000 +0200
3511 @@ -64,6 +64,7 @@
3512  #include <linux/nsproxy.h>
3513  #include <linux/virtio_net.h>
3514  #include <linux/rcupdate.h>
3515 +#include <linux/vs_network.h>
3516  #include <net/net_namespace.h>
3517  #include <net/netns/generic.h>
3518  #include <net/rtnetlink.h>
3519 @@ -121,6 +122,7 @@ struct tun_struct {
3520         unsigned int            flags;
3521         uid_t                   owner;
3522         gid_t                   group;
3523 +       nid_t                   nid;
3524  
3525         struct net_device       *dev;
3526         u32                     set_features;
3527 @@ -905,6 +907,7 @@ static void tun_setup(struct net_device 
3528  
3529         tun->owner = -1;
3530         tun->group = -1;
3531 +       tun->nid = current->nid;
3532  
3533         dev->ethtool_ops = &tun_ethtool_ops;
3534         dev->destructor = tun_free_netdev;
3535 @@ -1055,7 +1058,7 @@ static int tun_set_iff(struct net *net, 
3536  
3537                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
3538                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
3539 -                   !capable(CAP_NET_ADMIN))
3540 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
3541                         return -EPERM;
3542                 err = security_tun_dev_attach(tun->socket.sk);
3543                 if (err < 0)
3544 @@ -1069,7 +1072,7 @@ static int tun_set_iff(struct net *net, 
3545                 char *name;
3546                 unsigned long flags = 0;
3547  
3548 -               if (!capable(CAP_NET_ADMIN))
3549 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
3550                         return -EPERM;
3551                 err = security_tun_dev_create();
3552                 if (err < 0)
3553 @@ -1137,6 +1140,9 @@ static int tun_set_iff(struct net *net, 
3554  
3555                 sk->sk_destruct = tun_sock_destruct;
3556  
3557 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
3558 +                       return -EPERM;
3559 +
3560                 err = tun_attach(tun, file);
3561                 if (err < 0)
3562                         goto failed;
3563 @@ -1318,6 +1324,16 @@ static long __tun_chr_ioctl(struct file 
3564                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
3565                 break;
3566  
3567 +       case TUNSETNID:
3568 +               if (!capable(CAP_CONTEXT))
3569 +                       return -EPERM;
3570 +
3571 +               /* Set nid owner of the device */
3572 +               tun->nid = (nid_t) arg;
3573 +
3574 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
3575 +               break;
3576 +
3577         case TUNSETLINK:
3578                 /* Only allow setting the type when the interface is down */
3579                 if (tun->dev->flags & IFF_UP) {
3580 diff -NurpP --minimal linux-3.0.4/drivers/tty/sysrq.c linux-3.0.4-vs2.3.1-pre10.1/drivers/tty/sysrq.c
3581 --- linux-3.0.4/drivers/tty/sysrq.c     2011-05-22 16:17:44.000000000 +0200
3582 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/tty/sysrq.c     2011-06-10 22:11:24.000000000 +0200
3583 @@ -41,6 +41,7 @@
3584  #include <linux/oom.h>
3585  #include <linux/slab.h>
3586  #include <linux/input.h>
3587 +#include <linux/vserver/debug.h>
3588  
3589  #include <asm/ptrace.h>
3590  #include <asm/irq_regs.h>
3591 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
3592         .enable_mask    = SYSRQ_ENABLE_RTNICE,
3593  };
3594  
3595 +
3596 +#ifdef CONFIG_VSERVER_DEBUG
3597 +static void sysrq_handle_vxinfo(int key)
3598 +{
3599 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
3600 +}
3601 +
3602 +static struct sysrq_key_op sysrq_showvxinfo_op = {
3603 +       .handler        = sysrq_handle_vxinfo,
3604 +       .help_msg       = "conteXt",
3605 +       .action_msg     = "Show Context Info",
3606 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
3607 +};
3608 +#endif
3609 +
3610  /* Key Operations table and lock */
3611  static DEFINE_SPINLOCK(sysrq_key_table_lock);
3612  
3613 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
3614         NULL,                           /* v */
3615         &sysrq_showstate_blocked_op,    /* w */
3616         /* x: May be registered on ppc/powerpc for xmon */
3617 +#ifdef CONFIG_VSERVER_DEBUG
3618 +       &sysrq_showvxinfo_op,           /* x */
3619 +#else
3620         NULL,                           /* x */
3621 +#endif
3622         /* y: May be registered on sparc64 for global register dump */
3623         NULL,                           /* y */
3624         &sysrq_ftrace_dump_op,          /* z */
3625 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
3626                 retval = key - '0';
3627         else if ((key >= 'a') && (key <= 'z'))
3628                 retval = key + 10 - 'a';
3629 +       else if ((key >= 'A') && (key <= 'Z'))
3630 +               retval = key + 10 - 'A';
3631         else
3632                 retval = -1;
3633         return retval;
3634 diff -NurpP --minimal linux-3.0.4/drivers/tty/tty_io.c linux-3.0.4-vs2.3.1-pre10.1/drivers/tty/tty_io.c
3635 --- linux-3.0.4/drivers/tty/tty_io.c    2011-07-22 11:18:03.000000000 +0200
3636 +++ linux-3.0.4-vs2.3.1-pre10.1/drivers/tty/tty_io.c    2011-06-10 22:11:24.000000000 +0200
3637 @@ -104,6 +104,7 @@
3638  
3639  #include <linux/kmod.h>
3640  #include <linux/nsproxy.h>
3641 +#include <linux/vs_pid.h>
3642  
3643  #undef TTY_DEBUG_HANGUP
3644  
3645 @@ -2057,7 +2058,8 @@ static int tiocsti(struct tty_struct *tt
3646         char ch, mbz = 0;
3647         struct tty_ldisc *ld;
3648  
3649 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
3650 +       if (((current->signal->tty != tty) &&
3651 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
3652                 return -EPERM;
3653         if (get_user(ch, p))
3654                 return -EFAULT;
3655 @@ -2345,6 +2347,7 @@ static int tiocspgrp(struct tty_struct *
3656                 return -ENOTTY;
3657         if (get_user(pgrp_nr, p))
3658                 return -EFAULT;
3659 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
3660         if (pgrp_nr < 0)
3661                 return -EINVAL;
3662         rcu_read_lock();
3663 diff -NurpP --minimal linux-3.0.4/fs/attr.c linux-3.0.4-vs2.3.1-pre10.1/fs/attr.c
3664 --- linux-3.0.4/fs/attr.c       2011-07-22 11:18:05.000000000 +0200
3665 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/attr.c       2011-06-10 22:11:24.000000000 +0200
3666 @@ -13,6 +13,9 @@
3667  #include <linux/fsnotify.h>
3668  #include <linux/fcntl.h>
3669  #include <linux/security.h>
3670 +#include <linux/proc_fs.h>
3671 +#include <linux/devpts_fs.h>
3672 +#include <linux/vs_tag.h>
3673  
3674  /**
3675   * inode_change_ok - check if attribute changes to an inode are allowed
3676 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
3677                         return -EPERM;
3678         }
3679  
3680 +       /* check for inode tag permission */
3681 +       if (dx_permission(inode, MAY_WRITE))
3682 +               return -EACCES;
3683 +
3684         return 0;
3685  }
3686  EXPORT_SYMBOL(inode_change_ok);
3687 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
3688                 inode->i_uid = attr->ia_uid;
3689         if (ia_valid & ATTR_GID)
3690                 inode->i_gid = attr->ia_gid;
3691 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3692 +               inode->i_tag = attr->ia_tag;
3693         if (ia_valid & ATTR_ATIME)
3694                 inode->i_atime = timespec_trunc(attr->ia_atime,
3695                                                 inode->i_sb->s_time_gran);
3696 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
3697         struct timespec now;
3698         unsigned int ia_valid = attr->ia_valid;
3699  
3700 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
3701 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
3702 +               ATTR_TAG | ATTR_TIMES_SET)) {
3703                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
3704                         return -EPERM;
3705         }
3706 diff -NurpP --minimal linux-3.0.4/fs/binfmt_aout.c linux-3.0.4-vs2.3.1-pre10.1/fs/binfmt_aout.c
3707 --- linux-3.0.4/fs/binfmt_aout.c        2010-10-21 13:07:47.000000000 +0200
3708 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/binfmt_aout.c        2011-06-10 22:11:24.000000000 +0200
3709 @@ -25,6 +25,7 @@
3710  #include <linux/init.h>
3711  #include <linux/coredump.h>
3712  #include <linux/slab.h>
3713 +#include <linux/vs_memory.h>
3714  
3715  #include <asm/system.h>
3716  #include <asm/uaccess.h>
3717 diff -NurpP --minimal linux-3.0.4/fs/binfmt_elf.c linux-3.0.4-vs2.3.1-pre10.1/fs/binfmt_elf.c
3718 --- linux-3.0.4/fs/binfmt_elf.c 2011-05-22 16:17:48.000000000 +0200
3719 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/binfmt_elf.c 2011-06-10 22:11:24.000000000 +0200
3720 @@ -32,6 +32,7 @@
3721  #include <linux/elf.h>
3722  #include <linux/utsname.h>
3723  #include <linux/coredump.h>
3724 +#include <linux/vs_memory.h>
3725  #include <asm/uaccess.h>
3726  #include <asm/param.h>
3727  #include <asm/page.h>
3728 diff -NurpP --minimal linux-3.0.4/fs/binfmt_flat.c linux-3.0.4-vs2.3.1-pre10.1/fs/binfmt_flat.c
3729 --- linux-3.0.4/fs/binfmt_flat.c        2011-07-22 11:18:05.000000000 +0200
3730 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/binfmt_flat.c        2011-06-10 22:11:24.000000000 +0200
3731 @@ -35,6 +35,7 @@
3732  #include <linux/init.h>
3733  #include <linux/flat.h>
3734  #include <linux/syscalls.h>
3735 +#include <linux/vs_memory.h>
3736  
3737  #include <asm/byteorder.h>
3738  #include <asm/system.h>
3739 diff -NurpP --minimal linux-3.0.4/fs/binfmt_som.c linux-3.0.4-vs2.3.1-pre10.1/fs/binfmt_som.c
3740 --- linux-3.0.4/fs/binfmt_som.c 2010-02-25 11:52:04.000000000 +0100
3741 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/binfmt_som.c 2011-06-10 22:11:24.000000000 +0200
3742 @@ -28,6 +28,7 @@
3743  #include <linux/shm.h>
3744  #include <linux/personality.h>
3745  #include <linux/init.h>
3746 +#include <linux/vs_memory.h>
3747  
3748  #include <asm/uaccess.h>
3749  #include <asm/pgtable.h>
3750 diff -NurpP --minimal linux-3.0.4/fs/block_dev.c linux-3.0.4-vs2.3.1-pre10.1/fs/block_dev.c
3751 --- linux-3.0.4/fs/block_dev.c  2011-07-22 11:18:05.000000000 +0200
3752 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/block_dev.c  2011-07-01 11:35:34.000000000 +0200
3753 @@ -25,6 +25,7 @@
3754  #include <linux/namei.h>
3755  #include <linux/log2.h>
3756  #include <linux/kmemleak.h>
3757 +#include <linux/vs_device.h>
3758  #include <asm/uaccess.h>
3759  #include "internal.h"
3760  
3761 @@ -553,6 +554,7 @@ struct block_device *bdget(dev_t dev)
3762                 bdev->bd_invalidated = 0;
3763                 inode->i_mode = S_IFBLK;
3764                 inode->i_rdev = dev;
3765 +               inode->i_mdev = dev;
3766                 inode->i_bdev = bdev;
3767                 inode->i_data.a_ops = &def_blk_aops;
3768                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
3769 @@ -599,6 +601,11 @@ EXPORT_SYMBOL(bdput);
3770  static struct block_device *bd_acquire(struct inode *inode)
3771  {
3772         struct block_device *bdev;
3773 +       dev_t mdev;
3774 +
3775 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
3776 +               return NULL;
3777 +       inode->i_mdev = mdev;
3778  
3779         spin_lock(&bdev_lock);
3780         bdev = inode->i_bdev;
3781 @@ -609,7 +616,7 @@ static struct block_device *bd_acquire(s
3782         }
3783         spin_unlock(&bdev_lock);
3784  
3785 -       bdev = bdget(inode->i_rdev);
3786 +       bdev = bdget(mdev);
3787         if (bdev) {
3788                 spin_lock(&bdev_lock);
3789                 if (!inode->i_bdev) {
3790 diff -NurpP --minimal linux-3.0.4/fs/btrfs/ctree.h linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/ctree.h
3791 --- linux-3.0.4/fs/btrfs/ctree.h        2011-07-22 11:18:05.000000000 +0200
3792 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/ctree.h        2011-07-19 00:44:39.000000000 +0200
3793 @@ -600,11 +600,14 @@ struct btrfs_inode_item {
3794         /* modification sequence number for NFS */
3795         __le64 sequence;
3796  
3797 +       __le16 tag;
3798         /*
3799          * a little future expansion, for more than this we can
3800          * just grow the inode item and version it
3801          */
3802 -       __le64 reserved[4];
3803 +       __le16 reserved16;
3804 +       __le32 reserved32;
3805 +       __le64 reserved[3];
3806         struct btrfs_timespec atime;
3807         struct btrfs_timespec ctime;
3808         struct btrfs_timespec mtime;
3809 @@ -1359,6 +1362,8 @@ struct btrfs_ioctl_defrag_range_args {
3810  #define BTRFS_MOUNT_AUTO_DEFRAG                (1 << 16)
3811  #define BTRFS_MOUNT_INODE_MAP_CACHE    (1 << 17)
3812  
3813 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
3814 +
3815  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
3816  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
3817  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
3818 @@ -1568,6 +1573,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
3819  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
3820  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
3821  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
3822 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
3823  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
3824  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
3825  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
3826 @@ -1621,6 +1627,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
3827  
3828  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
3829  
3830 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
3831 +#define BTRFS_INODE_BARRIER            (1 << 25)
3832 +#define BTRFS_INODE_COW                        (1 << 26)
3833 +
3834  
3835  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
3836  
3837 @@ -2595,6 +2605,7 @@ extern const struct dentry_operations bt
3838  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
3839  void btrfs_update_iflags(struct inode *inode);
3840  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
3841 +int btrfs_sync_flags(struct inode *inode, int, int);
3842  int btrfs_defrag_file(struct inode *inode, struct file *file,
3843                       struct btrfs_ioctl_defrag_range_args *range,
3844                       u64 newer_than, unsigned long max_pages);
3845 diff -NurpP --minimal linux-3.0.4/fs/btrfs/disk-io.c linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/disk-io.c
3846 --- linux-3.0.4/fs/btrfs/disk-io.c      2011-07-22 11:18:05.000000000 +0200
3847 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/disk-io.c      2011-06-22 12:39:15.000000000 +0200
3848 @@ -1765,6 +1765,9 @@ struct btrfs_root *open_ctree(struct sup
3849                 goto fail_alloc;
3850         }
3851  
3852 +       if (btrfs_test_opt(tree_root, TAGGED))
3853 +               sb->s_flags |= MS_TAGGED;
3854 +
3855         features = btrfs_super_incompat_flags(disk_super) &
3856                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
3857         if (features) {
3858 diff -NurpP --minimal linux-3.0.4/fs/btrfs/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/inode.c
3859 --- linux-3.0.4/fs/btrfs/inode.c        2011-07-22 11:18:05.000000000 +0200
3860 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/inode.c        2011-07-19 00:44:39.000000000 +0200
3861 @@ -38,6 +38,7 @@
3862  #include <linux/falloc.h>
3863  #include <linux/slab.h>
3864  #include <linux/ratelimit.h>
3865 +#include <linux/vs_tag.h>
3866  #include "compat.h"
3867  #include "ctree.h"
3868  #include "disk-io.h"
3869 @@ -2508,6 +2509,8 @@ static void btrfs_read_locked_inode(stru
3870         struct btrfs_key location;
3871         int maybe_acls;
3872         u32 rdev;
3873 +       uid_t uid;
3874 +       gid_t gid;
3875         int ret;
3876         bool filled = false;
3877  
3878 @@ -2540,8 +2543,13 @@ static void btrfs_read_locked_inode(stru
3879  
3880         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
3881         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
3882 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
3883 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
3884 +
3885 +       uid = btrfs_inode_uid(leaf, inode_item);
3886 +       gid = btrfs_inode_gid(leaf, inode_item);
3887 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3888 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3889 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3890 +               btrfs_inode_tag(leaf, inode_item));
3891         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
3892  
3893         tspec = btrfs_inode_atime(inode_item);
3894 @@ -2624,6 +2632,9 @@ static void fill_inode_item(struct btrfs
3895                             struct btrfs_inode_item *item,
3896                             struct inode *inode)
3897  {
3898 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3899 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3900 +
3901         if (!leaf->map_token)
3902                 map_private_extent_buffer(leaf, (unsigned long)item,
3903                                           sizeof(struct btrfs_inode_item),
3904 @@ -2631,8 +2642,11 @@ static void fill_inode_item(struct btrfs
3905                                           &leaf->map_start, &leaf->map_len,
3906                                           KM_USER1);
3907  
3908 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
3909 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
3910 +       btrfs_set_inode_uid(leaf, item, uid);
3911 +       btrfs_set_inode_gid(leaf, item, gid);
3912 +#ifdef CONFIG_TAGGING_INTERN
3913 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
3914 +#endif
3915         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
3916         btrfs_set_inode_mode(leaf, item, inode->i_mode);
3917         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
3918 @@ -7359,6 +7373,7 @@ static const struct inode_operations btr
3919         .listxattr      = btrfs_listxattr,
3920         .removexattr    = btrfs_removexattr,
3921         .permission     = btrfs_permission,
3922 +       .sync_flags     = btrfs_sync_flags,
3923  };
3924  static const struct inode_operations btrfs_dir_ro_inode_operations = {
3925         .lookup         = btrfs_lookup,
3926 @@ -7431,6 +7446,7 @@ static const struct inode_operations btr
3927         .removexattr    = btrfs_removexattr,
3928         .permission     = btrfs_permission,
3929         .fiemap         = btrfs_fiemap,
3930 +       .sync_flags     = btrfs_sync_flags,
3931  };
3932  static const struct inode_operations btrfs_special_inode_operations = {
3933         .getattr        = btrfs_getattr,
3934 diff -NurpP --minimal linux-3.0.4/fs/btrfs/ioctl.c linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/ioctl.c
3935 --- linux-3.0.4/fs/btrfs/ioctl.c        2011-07-22 11:18:05.000000000 +0200
3936 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/ioctl.c        2011-06-22 12:39:15.000000000 +0200
3937 @@ -70,10 +70,13 @@ static unsigned int btrfs_flags_to_ioctl
3938  {
3939         unsigned int iflags = 0;
3940  
3941 -       if (flags & BTRFS_INODE_SYNC)
3942 -               iflags |= FS_SYNC_FL;
3943         if (flags & BTRFS_INODE_IMMUTABLE)
3944                 iflags |= FS_IMMUTABLE_FL;
3945 +       if (flags & BTRFS_INODE_IXUNLINK)
3946 +               iflags |= FS_IXUNLINK_FL;
3947 +
3948 +       if (flags & BTRFS_INODE_SYNC)
3949 +               iflags |= FS_SYNC_FL;
3950         if (flags & BTRFS_INODE_APPEND)
3951                 iflags |= FS_APPEND_FL;
3952         if (flags & BTRFS_INODE_NODUMP)
3953 @@ -90,28 +93,78 @@ static unsigned int btrfs_flags_to_ioctl
3954         else if (flags & BTRFS_INODE_NOCOMPRESS)
3955                 iflags |= FS_NOCOMP_FL;
3956  
3957 +       if (flags & BTRFS_INODE_BARRIER)
3958 +               iflags |= FS_BARRIER_FL;
3959 +       if (flags & BTRFS_INODE_COW)
3960 +               iflags |= FS_COW_FL;
3961         return iflags;
3962  }
3963  
3964  /*
3965 - * Update inode->i_flags based on the btrfs internal flags.
3966 + * Update inode->i_(v)flags based on the btrfs internal flags.
3967   */
3968  void btrfs_update_iflags(struct inode *inode)
3969  {
3970         struct btrfs_inode *ip = BTRFS_I(inode);
3971  
3972 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3973 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3974 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3975  
3976 -       if (ip->flags & BTRFS_INODE_SYNC)
3977 -               inode->i_flags |= S_SYNC;
3978         if (ip->flags & BTRFS_INODE_IMMUTABLE)
3979                 inode->i_flags |= S_IMMUTABLE;
3980 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
3981 +               inode->i_flags |= S_IXUNLINK;
3982 +
3983 +       if (ip->flags & BTRFS_INODE_SYNC)
3984 +               inode->i_flags |= S_SYNC;
3985         if (ip->flags & BTRFS_INODE_APPEND)
3986                 inode->i_flags |= S_APPEND;
3987         if (ip->flags & BTRFS_INODE_NOATIME)
3988                 inode->i_flags |= S_NOATIME;
3989         if (ip->flags & BTRFS_INODE_DIRSYNC)
3990                 inode->i_flags |= S_DIRSYNC;
3991 +
3992 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3993 +
3994 +       if (ip->flags & BTRFS_INODE_BARRIER)
3995 +               inode->i_vflags |= V_BARRIER;
3996 +       if (ip->flags & BTRFS_INODE_COW)
3997 +               inode->i_vflags |= V_COW;
3998 +}
3999 +
4000 +/*
4001 + * Update btrfs internal flags from inode->i_(v)flags.
4002 + */
4003 +void btrfs_update_flags(struct inode *inode)
4004 +{
4005 +       struct btrfs_inode *ip = BTRFS_I(inode);
4006 +
4007 +       unsigned int flags = inode->i_flags;
4008 +       unsigned int vflags = inode->i_vflags;
4009 +
4010 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
4011 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
4012 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
4013 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
4014 +
4015 +       if (flags & S_IMMUTABLE)
4016 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
4017 +       if (flags & S_IXUNLINK)
4018 +               ip->flags |= BTRFS_INODE_IXUNLINK;
4019 +
4020 +       if (flags & S_SYNC)
4021 +               ip->flags |= BTRFS_INODE_SYNC;
4022 +       if (flags & S_APPEND)
4023 +               ip->flags |= BTRFS_INODE_APPEND;
4024 +       if (flags & S_NOATIME)
4025 +               ip->flags |= BTRFS_INODE_NOATIME;
4026 +       if (flags & S_DIRSYNC)
4027 +               ip->flags |= BTRFS_INODE_DIRSYNC;
4028 +
4029 +       if (vflags & V_BARRIER)
4030 +               ip->flags |= BTRFS_INODE_BARRIER;
4031 +       if (vflags & V_COW)
4032 +               ip->flags |= BTRFS_INODE_COW;
4033  }
4034  
4035  /*
4036 @@ -129,7 +182,7 @@ void btrfs_inherit_iflags(struct inode *
4037         flags = BTRFS_I(dir)->flags;
4038  
4039         if (S_ISREG(inode->i_mode))
4040 -               flags &= ~BTRFS_INODE_DIRSYNC;
4041 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
4042         else if (!S_ISDIR(inode->i_mode))
4043                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
4044  
4045 @@ -137,6 +190,30 @@ void btrfs_inherit_iflags(struct inode *
4046         btrfs_update_iflags(inode);
4047  }
4048  
4049 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
4050 +{
4051 +       struct btrfs_inode *ip = BTRFS_I(inode);
4052 +       struct btrfs_root *root = ip->root;
4053 +       struct btrfs_trans_handle *trans;
4054 +       int ret;
4055 +
4056 +       trans = btrfs_join_transaction(root);
4057 +       BUG_ON(!trans);
4058 +
4059 +       inode->i_flags = flags;
4060 +       inode->i_vflags = vflags;
4061 +       btrfs_update_flags(inode);
4062 +
4063 +       ret = btrfs_update_inode(trans, root, inode);
4064 +       BUG_ON(ret);
4065 +
4066 +       btrfs_update_iflags(inode);
4067 +       inode->i_ctime = CURRENT_TIME;
4068 +       btrfs_end_transaction(trans, root);
4069 +
4070 +       return 0;
4071 +}
4072 +
4073  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
4074  {
4075         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
4076 @@ -188,7 +265,8 @@ static int btrfs_ioctl_setflags(struct f
4077  
4078         flags = btrfs_mask_flags(inode->i_mode, flags);
4079         oldflags = btrfs_flags_to_ioctl(ip->flags);
4080 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
4081 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
4082 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
4083                 if (!capable(CAP_LINUX_IMMUTABLE)) {
4084                         ret = -EPERM;
4085                         goto out_unlock;
4086 @@ -199,14 +277,19 @@ static int btrfs_ioctl_setflags(struct f
4087         if (ret)
4088                 goto out_unlock;
4089  
4090 -       if (flags & FS_SYNC_FL)
4091 -               ip->flags |= BTRFS_INODE_SYNC;
4092 -       else
4093 -               ip->flags &= ~BTRFS_INODE_SYNC;
4094         if (flags & FS_IMMUTABLE_FL)
4095                 ip->flags |= BTRFS_INODE_IMMUTABLE;
4096         else
4097                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
4098 +       if (flags & FS_IXUNLINK_FL)
4099 +               ip->flags |= BTRFS_INODE_IXUNLINK;
4100 +       else
4101 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
4102 +
4103 +       if (flags & FS_SYNC_FL)
4104 +               ip->flags |= BTRFS_INODE_SYNC;
4105 +       else
4106 +               ip->flags &= ~BTRFS_INODE_SYNC;
4107         if (flags & FS_APPEND_FL)
4108                 ip->flags |= BTRFS_INODE_APPEND;
4109         else
4110 diff -NurpP --minimal linux-3.0.4/fs/btrfs/super.c linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/super.c
4111 --- linux-3.0.4/fs/btrfs/super.c        2011-07-22 11:18:05.000000000 +0200
4112 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/btrfs/super.c        2011-07-19 00:44:39.000000000 +0200
4113 @@ -162,7 +162,7 @@ enum {
4114         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
4115         Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
4116         Opt_enospc_debug, Opt_subvolrootid, Opt_defrag,
4117 -       Opt_inode_cache, Opt_err,
4118 +       Opt_inode_cache, Opt_tag, Opt_notag, Opt_tagid, Opt_err,
4119  };
4120  
4121  static match_table_t tokens = {
4122 @@ -195,6 +195,9 @@ static match_table_t tokens = {
4123         {Opt_subvolrootid, "subvolrootid=%d"},
4124         {Opt_defrag, "autodefrag"},
4125         {Opt_inode_cache, "inode_cache"},
4126 +       {Opt_tag, "tag"},
4127 +       {Opt_notag, "notag"},
4128 +       {Opt_tagid, "tagid=%u"},
4129         {Opt_err, NULL},
4130  };
4131  
4132 @@ -381,6 +384,22 @@ int btrfs_parse_options(struct btrfs_roo
4133                         printk(KERN_INFO "btrfs: enabling auto defrag");
4134                         btrfs_set_opt(info->mount_opt, AUTO_DEFRAG);
4135                         break;
4136 +#ifndef CONFIG_TAGGING_NONE
4137 +               case Opt_tag:
4138 +                       printk(KERN_INFO "btrfs: use tagging\n");
4139 +                       btrfs_set_opt(info->mount_opt, TAGGED);
4140 +                       break;
4141 +               case Opt_notag:
4142 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
4143 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
4144 +                       break;
4145 +#endif
4146 +#ifdef CONFIG_PROPAGATE
4147 +               case Opt_tagid:
4148 +                       /* use args[0] */
4149 +                       btrfs_set_opt(info->mount_opt, TAGGED);
4150 +                       break;
4151 +#endif
4152                 case Opt_err:
4153                         printk(KERN_INFO "btrfs: unrecognized mount option "
4154                                "'%s'\n", p);
4155 @@ -907,6 +926,12 @@ static int btrfs_remount(struct super_bl
4156         if (ret)
4157                 return -EINVAL;
4158  
4159 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4160 +               printk("btrfs: %s: tagging not permitted on remount.\n",
4161 +                       sb->s_id);
4162 +               return -EINVAL;
4163 +       }
4164 +
4165         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
4166                 return 0;
4167  
4168 diff -NurpP --minimal linux-3.0.4/fs/char_dev.c linux-3.0.4-vs2.3.1-pre10.1/fs/char_dev.c
4169 --- linux-3.0.4/fs/char_dev.c   2011-03-15 18:07:31.000000000 +0100
4170 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/char_dev.c   2011-06-10 22:11:24.000000000 +0200
4171 @@ -21,6 +21,8 @@
4172  #include <linux/mutex.h>
4173  #include <linux/backing-dev.h>
4174  #include <linux/tty.h>
4175 +#include <linux/vs_context.h>
4176 +#include <linux/vs_device.h>
4177  
4178  #include "internal.h"
4179  
4180 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
4181         struct cdev *p;
4182         struct cdev *new = NULL;
4183         int ret = 0;
4184 +       dev_t mdev;
4185 +
4186 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
4187 +               return -EPERM;
4188 +       inode->i_mdev = mdev;
4189  
4190         spin_lock(&cdev_lock);
4191         p = inode->i_cdev;
4192         if (!p) {
4193                 struct kobject *kobj;
4194                 int idx;
4195 +
4196                 spin_unlock(&cdev_lock);
4197 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
4198 +
4199 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
4200                 if (!kobj)
4201                         return -ENXIO;
4202                 new = container_of(kobj, struct cdev, kobj);
4203 diff -NurpP --minimal linux-3.0.4/fs/dcache.c linux-3.0.4-vs2.3.1-pre10.1/fs/dcache.c
4204 --- linux-3.0.4/fs/dcache.c     2011-07-22 11:18:05.000000000 +0200
4205 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/dcache.c     2011-07-22 11:20:39.000000000 +0200
4206 @@ -36,6 +36,7 @@
4207  #include <linux/bit_spinlock.h>
4208  #include <linux/rculist_bl.h>
4209  #include <linux/prefetch.h>
4210 +#include <linux/vs_limit.h>
4211  #include "internal.h"
4212  
4213  /*
4214 @@ -479,6 +480,8 @@ int d_invalidate(struct dentry * dentry)
4215                 spin_lock(&dentry->d_lock);
4216         }
4217  
4218 +       vx_dentry_dec(dentry);
4219 +
4220         /*
4221          * Somebody else still using it?
4222          *
4223 @@ -506,6 +509,7 @@ EXPORT_SYMBOL(d_invalidate);
4224  static inline void __dget_dlock(struct dentry *dentry)
4225  {
4226         dentry->d_count++;
4227 +       vx_dentry_inc(dentry);
4228  }
4229  
4230  static inline void __dget(struct dentry *dentry)
4231 @@ -1266,6 +1270,9 @@ struct dentry *d_alloc(struct dentry * p
4232         struct dentry *dentry;
4233         char *dname;
4234  
4235 +       if (!vx_dentry_avail(1))
4236 +               return NULL;
4237 +
4238         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
4239         if (!dentry)
4240                 return NULL;
4241 @@ -1288,6 +1295,7 @@ struct dentry *d_alloc(struct dentry * p
4242  
4243         dentry->d_count = 1;
4244         dentry->d_flags = 0;
4245 +       vx_dentry_inc(dentry);
4246         spin_lock_init(&dentry->d_lock);
4247         seqcount_init(&dentry->d_seq);
4248         dentry->d_inode = NULL;
4249 @@ -1945,6 +1953,7 @@ struct dentry *__d_lookup(struct dentry 
4250                 }
4251  
4252                 dentry->d_count++;
4253 +               vx_dentry_inc(dentry);
4254                 found = dentry;
4255                 spin_unlock(&dentry->d_lock);
4256                 break;
4257 diff -NurpP --minimal linux-3.0.4/fs/devpts/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/devpts/inode.c
4258 --- linux-3.0.4/fs/devpts/inode.c       2011-05-22 16:17:50.000000000 +0200
4259 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/devpts/inode.c       2011-06-10 22:11:24.000000000 +0200
4260 @@ -25,6 +25,7 @@
4261  #include <linux/parser.h>
4262  #include <linux/fsnotify.h>
4263  #include <linux/seq_file.h>
4264 +#include <linux/vs_base.h>
4265  
4266  #define DEVPTS_DEFAULT_MODE 0600
4267  /*
4268 @@ -36,6 +37,20 @@
4269  #define DEVPTS_DEFAULT_PTMX_MODE 0000
4270  #define PTMX_MINOR     2
4271  
4272 +static int devpts_permission(struct inode *inode, int mask, unsigned int flags)
4273 +{
4274 +       int ret = -EACCES;
4275 +
4276 +       /* devpts is xid tagged */
4277 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
4278 +               ret = generic_permission(inode, mask, flags, NULL);
4279 +       return ret;
4280 +}
4281 +
4282 +static struct inode_operations devpts_file_inode_operations = {
4283 +       .permission     = devpts_permission,
4284 +};
4285 +
4286  extern int pty_limit;                  /* Config limit on Unix98 ptys */
4287  static DEFINE_MUTEX(allocated_ptys_lock);
4288  
4289 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
4290         return 0;
4291  }
4292  
4293 +static int devpts_filter(struct dentry *de)
4294 +{
4295 +       xid_t xid = 0;
4296 +
4297 +       /* devpts is xid tagged */
4298 +       if (de && de->d_inode)
4299 +               xid = (xid_t)de->d_inode->i_tag;
4300 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
4301 +       else
4302 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
4303 +                       de->d_name.len, de->d_name.name);
4304 +#endif
4305 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
4306 +}
4307 +
4308 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
4309 +{
4310 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
4311 +}
4312 +
4313 +static struct file_operations devpts_dir_operations = {
4314 +       .open           = dcache_dir_open,
4315 +       .release        = dcache_dir_close,
4316 +       .llseek         = dcache_dir_lseek,
4317 +       .read           = generic_read_dir,
4318 +       .readdir        = devpts_readdir,
4319 +};
4320 +
4321  static const struct super_operations devpts_sops = {
4322         .statfs         = simple_statfs,
4323         .remount_fs     = devpts_remount,
4324 @@ -302,12 +345,15 @@ devpts_fill_super(struct super_block *s,
4325         inode = new_inode(s);
4326         if (!inode)
4327                 goto free_fsi;
4328 +
4329         inode->i_ino = 1;
4330         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
4331         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
4332         inode->i_op = &simple_dir_inode_operations;
4333 -       inode->i_fop = &simple_dir_operations;
4334 +       inode->i_fop = &devpts_dir_operations;
4335         inode->i_nlink = 2;
4336 +       /* devpts is xid tagged */
4337 +       inode->i_tag = (tag_t)vx_current_xid();
4338  
4339         s->s_root = d_alloc_root(inode);
4340         if (s->s_root)
4341 @@ -494,6 +540,9 @@ int devpts_pty_new(struct inode *ptmx_in
4342         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
4343         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
4344         init_special_inode(inode, S_IFCHR|opts->mode, device);
4345 +       /* devpts is xid tagged */
4346 +       inode->i_tag = (tag_t)vx_current_xid();
4347 +       inode->i_op = &devpts_file_inode_operations;
4348         inode->i_private = tty;
4349         tty->driver_data = inode;
4350  
4351 diff -NurpP --minimal linux-3.0.4/fs/ext2/balloc.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/balloc.c
4352 --- linux-3.0.4/fs/ext2/balloc.c        2011-05-22 16:17:51.000000000 +0200
4353 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/balloc.c        2011-06-10 22:11:24.000000000 +0200
4354 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
4355                         start = 0;
4356                 end = EXT2_BLOCKS_PER_GROUP(sb);
4357         }
4358 -
4359         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
4360  
4361  repeat:
4362 diff -NurpP --minimal linux-3.0.4/fs/ext2/ext2.h linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/ext2.h
4363 --- linux-3.0.4/fs/ext2/ext2.h  2011-05-22 16:17:51.000000000 +0200
4364 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/ext2.h  2011-06-10 22:11:24.000000000 +0200
4365 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
4366  extern void ext2_get_inode_flags(struct ext2_inode_info *);
4367  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4368                        u64 start, u64 len);
4369 +extern int ext2_sync_flags(struct inode *, int, int);
4370  
4371  /* ioctl.c */
4372  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
4373 diff -NurpP --minimal linux-3.0.4/fs/ext2/file.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/file.c
4374 --- linux-3.0.4/fs/ext2/file.c  2010-08-02 16:52:48.000000000 +0200
4375 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/file.c  2011-06-10 22:11:24.000000000 +0200
4376 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
4377         .setattr        = ext2_setattr,
4378         .check_acl      = ext2_check_acl,
4379         .fiemap         = ext2_fiemap,
4380 +       .sync_flags     = ext2_sync_flags,
4381  };
4382 diff -NurpP --minimal linux-3.0.4/fs/ext2/ialloc.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/ialloc.c
4383 --- linux-3.0.4/fs/ext2/ialloc.c        2011-05-22 16:17:51.000000000 +0200
4384 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/ialloc.c        2011-06-10 22:11:24.000000000 +0200
4385 @@ -17,6 +17,7 @@
4386  #include <linux/backing-dev.h>
4387  #include <linux/buffer_head.h>
4388  #include <linux/random.h>
4389 +#include <linux/vs_tag.h>
4390  #include "ext2.h"
4391  #include "xattr.h"
4392  #include "acl.h"
4393 @@ -549,6 +550,7 @@ got:
4394                 inode->i_mode = mode;
4395                 inode->i_uid = current_fsuid();
4396                 inode->i_gid = dir->i_gid;
4397 +               inode->i_tag = dx_current_fstag(sb);
4398         } else
4399                 inode_init_owner(inode, dir, mode);
4400  
4401 diff -NurpP --minimal linux-3.0.4/fs/ext2/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/inode.c
4402 --- linux-3.0.4/fs/ext2/inode.c 2011-05-22 16:17:51.000000000 +0200
4403 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/inode.c 2011-06-10 22:11:24.000000000 +0200
4404 @@ -32,6 +32,7 @@
4405  #include <linux/mpage.h>
4406  #include <linux/fiemap.h>
4407  #include <linux/namei.h>
4408 +#include <linux/vs_tag.h>
4409  #include "ext2.h"
4410  #include "acl.h"
4411  #include "xip.h"
4412 @@ -1167,7 +1168,7 @@ static void ext2_truncate_blocks(struct 
4413                 return;
4414         if (ext2_inode_is_fast_symlink(inode))
4415                 return;
4416 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4417 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4418                 return;
4419         __ext2_truncate_blocks(inode, offset);
4420  }
4421 @@ -1256,36 +1257,61 @@ void ext2_set_inode_flags(struct inode *
4422  {
4423         unsigned int flags = EXT2_I(inode)->i_flags;
4424  
4425 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4426 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4427 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4428 +
4429 +
4430 +       if (flags & EXT2_IMMUTABLE_FL)
4431 +               inode->i_flags |= S_IMMUTABLE;
4432 +       if (flags & EXT2_IXUNLINK_FL)
4433 +               inode->i_flags |= S_IXUNLINK;
4434 +
4435         if (flags & EXT2_SYNC_FL)
4436                 inode->i_flags |= S_SYNC;
4437         if (flags & EXT2_APPEND_FL)
4438                 inode->i_flags |= S_APPEND;
4439 -       if (flags & EXT2_IMMUTABLE_FL)
4440 -               inode->i_flags |= S_IMMUTABLE;
4441         if (flags & EXT2_NOATIME_FL)
4442                 inode->i_flags |= S_NOATIME;
4443         if (flags & EXT2_DIRSYNC_FL)
4444                 inode->i_flags |= S_DIRSYNC;
4445 +
4446 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4447 +
4448 +       if (flags & EXT2_BARRIER_FL)
4449 +               inode->i_vflags |= V_BARRIER;
4450 +       if (flags & EXT2_COW_FL)
4451 +               inode->i_vflags |= V_COW;
4452  }
4453  
4454  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
4455  void ext2_get_inode_flags(struct ext2_inode_info *ei)
4456  {
4457         unsigned int flags = ei->vfs_inode.i_flags;
4458 +       unsigned int vflags = ei->vfs_inode.i_vflags;
4459 +
4460 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
4461 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
4462 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
4463 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
4464 +
4465 +       if (flags & S_IMMUTABLE)
4466 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
4467 +       if (flags & S_IXUNLINK)
4468 +               ei->i_flags |= EXT2_IXUNLINK_FL;
4469  
4470 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
4471 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
4472         if (flags & S_SYNC)
4473                 ei->i_flags |= EXT2_SYNC_FL;
4474         if (flags & S_APPEND)
4475                 ei->i_flags |= EXT2_APPEND_FL;
4476 -       if (flags & S_IMMUTABLE)
4477 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
4478         if (flags & S_NOATIME)
4479                 ei->i_flags |= EXT2_NOATIME_FL;
4480         if (flags & S_DIRSYNC)
4481                 ei->i_flags |= EXT2_DIRSYNC_FL;
4482 +
4483 +       if (vflags & V_BARRIER)
4484 +               ei->i_flags |= EXT2_BARRIER_FL;
4485 +       if (vflags & V_COW)
4486 +               ei->i_flags |= EXT2_COW_FL;
4487  }
4488  
4489  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
4490 @@ -1295,6 +1321,8 @@ struct inode *ext2_iget (struct super_bl
4491         struct ext2_inode *raw_inode;
4492         struct inode *inode;
4493         long ret = -EIO;
4494 +       uid_t uid;
4495 +       gid_t gid;
4496         int n;
4497  
4498         inode = iget_locked(sb, ino);
4499 @@ -1313,12 +1341,17 @@ struct inode *ext2_iget (struct super_bl
4500         }
4501  
4502         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4503 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4504 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4505 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4506 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4507         if (!(test_opt (inode->i_sb, NO_UID32))) {
4508 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4509 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4510 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4511 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4512         }
4513 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4514 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4515 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4516 +               le16_to_cpu(raw_inode->i_raw_tag));
4517 +
4518         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4519         inode->i_size = le32_to_cpu(raw_inode->i_size);
4520         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
4521 @@ -1416,8 +1449,8 @@ static int __ext2_write_inode(struct ino
4522         struct ext2_inode_info *ei = EXT2_I(inode);
4523         struct super_block *sb = inode->i_sb;
4524         ino_t ino = inode->i_ino;
4525 -       uid_t uid = inode->i_uid;
4526 -       gid_t gid = inode->i_gid;
4527 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4528 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4529         struct buffer_head * bh;
4530         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
4531         int n;
4532 @@ -1453,6 +1486,9 @@ static int __ext2_write_inode(struct ino
4533                 raw_inode->i_uid_high = 0;
4534                 raw_inode->i_gid_high = 0;
4535         }
4536 +#ifdef CONFIG_TAGGING_INTERN
4537 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4538 +#endif
4539         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4540         raw_inode->i_size = cpu_to_le32(inode->i_size);
4541         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4542 @@ -1533,7 +1569,8 @@ int ext2_setattr(struct dentry *dentry, 
4543         if (is_quota_modification(inode, iattr))
4544                 dquot_initialize(inode);
4545         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4546 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4547 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4548 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4549                 error = dquot_transfer(inode, iattr);
4550                 if (error)
4551                         return error;
4552 diff -NurpP --minimal linux-3.0.4/fs/ext2/ioctl.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/ioctl.c
4553 --- linux-3.0.4/fs/ext2/ioctl.c 2011-05-22 16:17:51.000000000 +0200
4554 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/ioctl.c 2011-06-10 22:11:24.000000000 +0200
4555 @@ -17,6 +17,16 @@
4556  #include <asm/uaccess.h>
4557  
4558  
4559 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
4560 +{
4561 +       inode->i_flags = flags;
4562 +       inode->i_vflags = vflags;
4563 +       ext2_get_inode_flags(EXT2_I(inode));
4564 +       inode->i_ctime = CURRENT_TIME_SEC;
4565 +       mark_inode_dirty(inode);
4566 +       return 0;
4567 +}
4568 +
4569  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4570  {
4571         struct inode *inode = filp->f_dentry->d_inode;
4572 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
4573  
4574                 flags = ext2_mask_flags(inode->i_mode, flags);
4575  
4576 +               if (IS_BARRIER(inode)) {
4577 +                       vxwprintk_task(1, "messing with the barrier.");
4578 +                       return -EACCES;
4579 +               }
4580 +
4581                 mutex_lock(&inode->i_mutex);
4582                 /* Is it quota file? Do not allow user to mess with it */
4583                 if (IS_NOQUOTA(inode)) {
4584 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
4585                  *
4586                  * This test looks nicer. Thanks to Pauline Middelink
4587                  */
4588 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
4589 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
4590 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
4591 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
4592                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4593                                 mutex_unlock(&inode->i_mutex);
4594                                 ret = -EPERM;
4595 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
4596                         }
4597                 }
4598  
4599 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
4600 +               flags &= EXT2_FL_USER_MODIFIABLE;
4601                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
4602                 ei->i_flags = flags;
4603                 mutex_unlock(&inode->i_mutex);
4604 diff -NurpP --minimal linux-3.0.4/fs/ext2/namei.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/namei.c
4605 --- linux-3.0.4/fs/ext2/namei.c 2011-05-22 16:17:51.000000000 +0200
4606 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/namei.c 2011-06-10 22:11:24.000000000 +0200
4607 @@ -32,6 +32,7 @@
4608  
4609  #include <linux/pagemap.h>
4610  #include <linux/quotaops.h>
4611 +#include <linux/vs_tag.h>
4612  #include "ext2.h"
4613  #include "xattr.h"
4614  #include "acl.h"
4615 @@ -75,6 +76,7 @@ static struct dentry *ext2_lookup(struct
4616                                 return ERR_PTR(-EIO);
4617                         } else {
4618                                 return ERR_CAST(inode);
4619 +               dx_propagate_tag(nd, inode);
4620                         }
4621                 }
4622         }
4623 @@ -413,6 +415,7 @@ const struct inode_operations ext2_dir_i
4624  #endif
4625         .setattr        = ext2_setattr,
4626         .check_acl      = ext2_check_acl,
4627 +       .sync_flags     = ext2_sync_flags,
4628  };
4629  
4630  const struct inode_operations ext2_special_inode_operations = {
4631 diff -NurpP --minimal linux-3.0.4/fs/ext2/super.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/super.c
4632 --- linux-3.0.4/fs/ext2/super.c 2011-07-22 11:18:05.000000000 +0200
4633 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext2/super.c 2011-06-10 22:11:24.000000000 +0200
4634 @@ -394,7 +394,8 @@ enum {
4635         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
4636         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
4637         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
4638 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
4639 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
4640 +       Opt_tag, Opt_notag, Opt_tagid
4641  };
4642  
4643  static const match_table_t tokens = {
4644 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
4645         {Opt_acl, "acl"},
4646         {Opt_noacl, "noacl"},
4647         {Opt_xip, "xip"},
4648 +       {Opt_tag, "tag"},
4649 +       {Opt_notag, "notag"},
4650 +       {Opt_tagid, "tagid=%u"},
4651         {Opt_grpquota, "grpquota"},
4652         {Opt_ignore, "noquota"},
4653         {Opt_quota, "quota"},
4654 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
4655                 case Opt_nouid32:
4656                         set_opt (sbi->s_mount_opt, NO_UID32);
4657                         break;
4658 +#ifndef CONFIG_TAGGING_NONE
4659 +               case Opt_tag:
4660 +                       set_opt (sbi->s_mount_opt, TAGGED);
4661 +                       break;
4662 +               case Opt_notag:
4663 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4664 +                       break;
4665 +#endif
4666 +#ifdef CONFIG_PROPAGATE
4667 +               case Opt_tagid:
4668 +                       /* use args[0] */
4669 +                       set_opt (sbi->s_mount_opt, TAGGED);
4670 +                       break;
4671 +#endif
4672                 case Opt_nocheck:
4673                         clear_opt (sbi->s_mount_opt, CHECK);
4674                         break;
4675 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
4676         if (!parse_options((char *) data, sb))
4677                 goto failed_mount;
4678  
4679 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
4680 +               sb->s_flags |= MS_TAGGED;
4681         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4682                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
4683                  MS_POSIXACL : 0);
4684 @@ -1224,6 +1244,14 @@ static int ext2_remount (struct super_bl
4685                 goto restore_opts;
4686         }
4687  
4688 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
4689 +               !(sb->s_flags & MS_TAGGED)) {
4690 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
4691 +                      sb->s_id);
4692 +               err = -EINVAL;
4693 +               goto restore_opts;
4694 +       }
4695 +
4696         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4697                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4698  
4699 diff -NurpP --minimal linux-3.0.4/fs/ext3/file.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/file.c
4700 --- linux-3.0.4/fs/ext3/file.c  2010-07-07 18:31:51.000000000 +0200
4701 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/file.c  2011-06-10 22:11:24.000000000 +0200
4702 @@ -81,5 +81,6 @@ const struct inode_operations ext3_file_
4703  #endif
4704         .check_acl      = ext3_check_acl,
4705         .fiemap         = ext3_fiemap,
4706 +       .sync_flags     = ext3_sync_flags,
4707  };
4708  
4709 diff -NurpP --minimal linux-3.0.4/fs/ext3/ialloc.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/ialloc.c
4710 --- linux-3.0.4/fs/ext3/ialloc.c        2011-05-22 16:17:52.000000000 +0200
4711 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/ialloc.c        2011-06-10 22:11:24.000000000 +0200
4712 @@ -23,6 +23,7 @@
4713  #include <linux/buffer_head.h>
4714  #include <linux/random.h>
4715  #include <linux/bitops.h>
4716 +#include <linux/vs_tag.h>
4717  
4718  #include <asm/byteorder.h>
4719  
4720 @@ -532,6 +533,7 @@ got:
4721                 inode->i_mode = mode;
4722                 inode->i_uid = current_fsuid();
4723                 inode->i_gid = dir->i_gid;
4724 +               inode->i_tag = dx_current_fstag(sb);
4725         } else
4726                 inode_init_owner(inode, dir, mode);
4727  
4728 diff -NurpP --minimal linux-3.0.4/fs/ext3/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/inode.c
4729 --- linux-3.0.4/fs/ext3/inode.c 2011-07-22 11:18:05.000000000 +0200
4730 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/inode.c 2011-06-10 22:11:24.000000000 +0200
4731 @@ -38,6 +38,7 @@
4732  #include <linux/bio.h>
4733  #include <linux/fiemap.h>
4734  #include <linux/namei.h>
4735 +#include <linux/vs_tag.h>
4736  #include "xattr.h"
4737  #include "acl.h"
4738  
4739 @@ -2391,7 +2392,7 @@ static void ext3_free_branches(handle_t 
4740  
4741  int ext3_can_truncate(struct inode *inode)
4742  {
4743 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4744 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4745                 return 0;
4746         if (S_ISREG(inode->i_mode))
4747                 return 1;
4748 @@ -2775,36 +2776,60 @@ void ext3_set_inode_flags(struct inode *
4749  {
4750         unsigned int flags = EXT3_I(inode)->i_flags;
4751  
4752 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4753 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4754 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4755 +
4756 +       if (flags & EXT3_IMMUTABLE_FL)
4757 +               inode->i_flags |= S_IMMUTABLE;
4758 +       if (flags & EXT3_IXUNLINK_FL)
4759 +               inode->i_flags |= S_IXUNLINK;
4760 +
4761         if (flags & EXT3_SYNC_FL)
4762                 inode->i_flags |= S_SYNC;
4763         if (flags & EXT3_APPEND_FL)
4764                 inode->i_flags |= S_APPEND;
4765 -       if (flags & EXT3_IMMUTABLE_FL)
4766 -               inode->i_flags |= S_IMMUTABLE;
4767         if (flags & EXT3_NOATIME_FL)
4768                 inode->i_flags |= S_NOATIME;
4769         if (flags & EXT3_DIRSYNC_FL)
4770                 inode->i_flags |= S_DIRSYNC;
4771 +
4772 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4773 +
4774 +       if (flags & EXT3_BARRIER_FL)
4775 +               inode->i_vflags |= V_BARRIER;
4776 +       if (flags & EXT3_COW_FL)
4777 +               inode->i_vflags |= V_COW;
4778  }
4779  
4780  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
4781  void ext3_get_inode_flags(struct ext3_inode_info *ei)
4782  {
4783         unsigned int flags = ei->vfs_inode.i_flags;
4784 +       unsigned int vflags = ei->vfs_inode.i_vflags;
4785 +
4786 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
4787 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
4788 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
4789 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
4790 +
4791 +       if (flags & S_IMMUTABLE)
4792 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
4793 +       if (flags & S_IXUNLINK)
4794 +               ei->i_flags |= EXT3_IXUNLINK_FL;
4795  
4796 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
4797 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
4798         if (flags & S_SYNC)
4799                 ei->i_flags |= EXT3_SYNC_FL;
4800         if (flags & S_APPEND)
4801                 ei->i_flags |= EXT3_APPEND_FL;
4802 -       if (flags & S_IMMUTABLE)
4803 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
4804         if (flags & S_NOATIME)
4805                 ei->i_flags |= EXT3_NOATIME_FL;
4806         if (flags & S_DIRSYNC)
4807                 ei->i_flags |= EXT3_DIRSYNC_FL;
4808 +
4809 +       if (vflags & V_BARRIER)
4810 +               ei->i_flags |= EXT3_BARRIER_FL;
4811 +       if (vflags & V_COW)
4812 +               ei->i_flags |= EXT3_COW_FL;
4813  }
4814  
4815  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
4816 @@ -2818,6 +2843,8 @@ struct inode *ext3_iget(struct super_blo
4817         transaction_t *transaction;
4818         long ret;
4819         int block;
4820 +       uid_t uid;
4821 +       gid_t gid;
4822  
4823         inode = iget_locked(sb, ino);
4824         if (!inode)
4825 @@ -2834,12 +2861,17 @@ struct inode *ext3_iget(struct super_blo
4826         bh = iloc.bh;
4827         raw_inode = ext3_raw_inode(&iloc);
4828         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4829 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4830 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4831 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4832 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4833         if(!(test_opt (inode->i_sb, NO_UID32))) {
4834 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4835 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4836 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4837 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4838         }
4839 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4840 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4841 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4842 +               le16_to_cpu(raw_inode->i_raw_tag));
4843 +
4844         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4845         inode->i_size = le32_to_cpu(raw_inode->i_size);
4846         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
4847 @@ -2994,6 +3026,8 @@ static int ext3_do_update_inode(handle_t
4848         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
4849         struct ext3_inode_info *ei = EXT3_I(inode);
4850         struct buffer_head *bh = iloc->bh;
4851 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4852 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4853         int err = 0, rc, block;
4854  
4855  again:
4856 @@ -3008,29 +3042,32 @@ again:
4857         ext3_get_inode_flags(ei);
4858         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
4859         if(!(test_opt(inode->i_sb, NO_UID32))) {
4860 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
4861 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
4862 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
4863 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
4864  /*
4865   * Fix up interoperability with old kernels. Otherwise, old inodes get
4866   * re-used with the upper 16 bits of the uid/gid intact
4867   */
4868                 if(!ei->i_dtime) {
4869                         raw_inode->i_uid_high =
4870 -                               cpu_to_le16(high_16_bits(inode->i_uid));
4871 +                               cpu_to_le16(high_16_bits(uid));
4872                         raw_inode->i_gid_high =
4873 -                               cpu_to_le16(high_16_bits(inode->i_gid));
4874 +                               cpu_to_le16(high_16_bits(gid));
4875                 } else {
4876                         raw_inode->i_uid_high = 0;
4877                         raw_inode->i_gid_high = 0;
4878                 }
4879         } else {
4880                 raw_inode->i_uid_low =
4881 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
4882 +                       cpu_to_le16(fs_high2lowuid(uid));
4883                 raw_inode->i_gid_low =
4884 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4885 +                       cpu_to_le16(fs_high2lowgid(gid));
4886                 raw_inode->i_uid_high = 0;
4887                 raw_inode->i_gid_high = 0;
4888         }
4889 +#ifdef CONFIG_TAGGING_INTERN
4890 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4891 +#endif
4892         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4893         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
4894         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4895 @@ -3190,7 +3227,8 @@ int ext3_setattr(struct dentry *dentry, 
4896         if (is_quota_modification(inode, attr))
4897                 dquot_initialize(inode);
4898         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4899 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4900 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4901 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4902                 handle_t *handle;
4903  
4904                 /* (user+group)*(old+new) structure, inode write (sb,
4905 @@ -3212,6 +3250,8 @@ int ext3_setattr(struct dentry *dentry, 
4906                         inode->i_uid = attr->ia_uid;
4907                 if (attr->ia_valid & ATTR_GID)
4908                         inode->i_gid = attr->ia_gid;
4909 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4910 +                       inode->i_tag = attr->ia_tag;
4911                 error = ext3_mark_inode_dirty(handle, inode);
4912                 ext3_journal_stop(handle);
4913         }
4914 diff -NurpP --minimal linux-3.0.4/fs/ext3/ioctl.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/ioctl.c
4915 --- linux-3.0.4/fs/ext3/ioctl.c 2011-05-22 16:17:52.000000000 +0200
4916 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/ioctl.c 2011-06-10 22:11:24.000000000 +0200
4917 @@ -8,6 +8,7 @@
4918   */
4919  
4920  #include <linux/fs.h>
4921 +#include <linux/mount.h>
4922  #include <linux/jbd.h>
4923  #include <linux/capability.h>
4924  #include <linux/ext3_fs.h>
4925 @@ -17,6 +18,34 @@
4926  #include <linux/compat.h>
4927  #include <asm/uaccess.h>
4928  
4929 +
4930 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
4931 +{
4932 +       handle_t *handle = NULL;
4933 +       struct ext3_iloc iloc;
4934 +       int err;
4935 +
4936 +       handle = ext3_journal_start(inode, 1);
4937 +       if (IS_ERR(handle))
4938 +               return PTR_ERR(handle);
4939 +
4940 +       if (IS_SYNC(inode))
4941 +               handle->h_sync = 1;
4942 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
4943 +       if (err)
4944 +               goto flags_err;
4945 +
4946 +       inode->i_flags = flags;
4947 +       inode->i_vflags = vflags;
4948 +       ext3_get_inode_flags(EXT3_I(inode));
4949 +       inode->i_ctime = CURRENT_TIME_SEC;
4950 +
4951 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
4952 +flags_err:
4953 +       ext3_journal_stop(handle);
4954 +       return err;
4955 +}
4956 +
4957  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4958  {
4959         struct inode *inode = filp->f_dentry->d_inode;
4960 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
4961  
4962                 flags = ext3_mask_flags(inode->i_mode, flags);
4963  
4964 +               if (IS_BARRIER(inode)) {
4965 +                       vxwprintk_task(1, "messing with the barrier.");
4966 +                       return -EACCES;
4967 +               }
4968 +
4969                 mutex_lock(&inode->i_mutex);
4970  
4971                 /* Is it quota file? Do not allow user to mess with it */
4972 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
4973                  *
4974                  * This test looks nicer. Thanks to Pauline Middelink
4975                  */
4976 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
4977 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
4978 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
4979 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
4980                         if (!capable(CAP_LINUX_IMMUTABLE))
4981                                 goto flags_out;
4982                 }
4983 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
4984                 if (err)
4985                         goto flags_err;
4986  
4987 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
4988 +               flags &= EXT3_FL_USER_MODIFIABLE;
4989                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
4990                 ei->i_flags = flags;
4991  
4992 diff -NurpP --minimal linux-3.0.4/fs/ext3/namei.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/namei.c
4993 --- linux-3.0.4/fs/ext3/namei.c 2011-08-31 18:56:42.000000000 +0200
4994 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/namei.c 2011-08-29 03:45:09.000000000 +0200
4995 @@ -36,6 +36,7 @@
4996  #include <linux/quotaops.h>
4997  #include <linux/buffer_head.h>
4998  #include <linux/bio.h>
4999 +#include <linux/vs_tag.h>
5000  
5001  #include "namei.h"
5002  #include "xattr.h"
5003 @@ -923,6 +924,7 @@ restart:
5004                                 if (bh)
5005                                         ll_rw_block(READ_META, 1, &bh);
5006                         }
5007 +               dx_propagate_tag(nd, inode);
5008                 }
5009                 if ((bh = bh_use[ra_ptr++]) == NULL)
5010                         goto next;
5011 @@ -2536,6 +2538,7 @@ const struct inode_operations ext3_dir_i
5012         .removexattr    = generic_removexattr,
5013  #endif
5014         .check_acl      = ext3_check_acl,
5015 +       .sync_flags     = ext3_sync_flags,
5016  };
5017  
5018  const struct inode_operations ext3_special_inode_operations = {
5019 diff -NurpP --minimal linux-3.0.4/fs/ext3/super.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/super.c
5020 --- linux-3.0.4/fs/ext3/super.c 2011-07-22 11:18:05.000000000 +0200
5021 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext3/super.c 2011-06-10 22:11:24.000000000 +0200
5022 @@ -821,7 +821,8 @@ enum {
5023         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
5024         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
5025         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
5026 -       Opt_resize, Opt_usrquota, Opt_grpquota
5027 +       Opt_resize, Opt_usrquota, Opt_grpquota,
5028 +       Opt_tag, Opt_notag, Opt_tagid
5029  };
5030  
5031  static const match_table_t tokens = {
5032 @@ -878,6 +879,9 @@ static const match_table_t tokens = {
5033         {Opt_barrier, "barrier"},
5034         {Opt_nobarrier, "nobarrier"},
5035         {Opt_resize, "resize"},
5036 +       {Opt_tag, "tag"},
5037 +       {Opt_notag, "notag"},
5038 +       {Opt_tagid, "tagid=%u"},
5039         {Opt_err, NULL},
5040  };
5041  
5042 @@ -1030,6 +1034,20 @@ static int parse_options (char *options,
5043                 case Opt_nouid32:
5044                         set_opt (sbi->s_mount_opt, NO_UID32);
5045                         break;
5046 +#ifndef CONFIG_TAGGING_NONE
5047 +               case Opt_tag:
5048 +                       set_opt (sbi->s_mount_opt, TAGGED);
5049 +                       break;
5050 +               case Opt_notag:
5051 +                       clear_opt (sbi->s_mount_opt, TAGGED);
5052 +                       break;
5053 +#endif
5054 +#ifdef CONFIG_PROPAGATE
5055 +               case Opt_tagid:
5056 +                       /* use args[0] */
5057 +                       set_opt (sbi->s_mount_opt, TAGGED);
5058 +                       break;
5059 +#endif
5060                 case Opt_nocheck:
5061                         clear_opt (sbi->s_mount_opt, CHECK);
5062                         break;
5063 @@ -1724,6 +1742,9 @@ static int ext3_fill_super (struct super
5064                             NULL, 0))
5065                 goto failed_mount;
5066  
5067 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
5068 +               sb->s_flags |= MS_TAGGED;
5069 +
5070         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
5071                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
5072  
5073 @@ -2604,6 +2625,14 @@ static int ext3_remount (struct super_bl
5074         if (test_opt(sb, ABORT))
5075                 ext3_abort(sb, __func__, "Abort forced by user");
5076  
5077 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
5078 +               !(sb->s_flags & MS_TAGGED)) {
5079 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
5080 +                       sb->s_id);
5081 +               err = -EINVAL;
5082 +               goto restore_opts;
5083 +       }
5084 +
5085         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
5086                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
5087  
5088 diff -NurpP --minimal linux-3.0.4/fs/ext4/ext4.h linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/ext4.h
5089 --- linux-3.0.4/fs/ext4/ext4.h  2011-08-31 18:56:42.000000000 +0200
5090 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/ext4.h  2011-08-08 23:04:47.000000000 +0200
5091 @@ -350,8 +350,12 @@ struct flex_groups {
5092  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
5093  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
5094  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
5095 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
5096  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
5097  
5098 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
5099 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
5100 +
5101  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
5102  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
5103  
5104 @@ -609,7 +613,8 @@ struct ext4_inode {
5105                         __le16  l_i_file_acl_high;
5106                         __le16  l_i_uid_high;   /* these 2 fields */
5107                         __le16  l_i_gid_high;   /* were reserved2[0] */
5108 -                       __u32   l_i_reserved2;
5109 +                       __le16  l_i_tag;        /* Context Tag */
5110 +                       __u16   l_i_reserved2;
5111                 } linux2;
5112                 struct {
5113                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
5114 @@ -727,6 +732,7 @@ do {                                                                               \
5115  #define i_gid_low      i_gid
5116  #define i_uid_high     osd2.linux2.l_i_uid_high
5117  #define i_gid_high     osd2.linux2.l_i_gid_high
5118 +#define i_raw_tag      osd2.linux2.l_i_tag
5119  #define i_reserved2    osd2.linux2.l_i_reserved2
5120  
5121  #elif defined(__GNU__)
5122 @@ -903,6 +909,7 @@ struct ext4_inode_info {
5123  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
5124  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
5125  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
5126 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
5127  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
5128  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
5129  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
5130 @@ -2173,6 +2180,7 @@ extern int ext4_map_blocks(handle_t *han
5131                            struct ext4_map_blocks *map, int flags);
5132  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
5133                         __u64 start, __u64 len);
5134 +extern int ext4_sync_flags(struct inode *, int, int);
5135  /* move_extent.c */
5136  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
5137                              __u64 start_orig, __u64 start_donor,
5138 diff -NurpP --minimal linux-3.0.4/fs/ext4/file.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/file.c
5139 --- linux-3.0.4/fs/ext4/file.c  2011-07-22 11:18:05.000000000 +0200
5140 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/file.c  2011-06-10 22:11:24.000000000 +0200
5141 @@ -282,5 +282,6 @@ const struct inode_operations ext4_file_
5142  #endif
5143         .check_acl      = ext4_check_acl,
5144         .fiemap         = ext4_fiemap,
5145 +       .sync_flags     = ext4_sync_flags,
5146  };
5147  
5148 diff -NurpP --minimal linux-3.0.4/fs/ext4/ialloc.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/ialloc.c
5149 --- linux-3.0.4/fs/ext4/ialloc.c        2011-05-22 16:17:52.000000000 +0200
5150 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/ialloc.c        2011-06-10 22:11:24.000000000 +0200
5151 @@ -22,6 +22,7 @@
5152  #include <linux/random.h>
5153  #include <linux/bitops.h>
5154  #include <linux/blkdev.h>
5155 +#include <linux/vs_tag.h>
5156  #include <asm/byteorder.h>
5157  
5158  #include "ext4.h"
5159 @@ -992,6 +993,7 @@ got:
5160                 inode->i_mode = mode;
5161                 inode->i_uid = current_fsuid();
5162                 inode->i_gid = dir->i_gid;
5163 +               inode->i_tag = dx_current_fstag(sb);
5164         } else
5165                 inode_init_owner(inode, dir, mode);
5166  
5167 diff -NurpP --minimal linux-3.0.4/fs/ext4/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/inode.c
5168 --- linux-3.0.4/fs/ext4/inode.c 2011-08-31 18:56:42.000000000 +0200
5169 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/inode.c 2011-08-31 19:37:44.000000000 +0200
5170 @@ -42,6 +42,7 @@
5171  #include <linux/printk.h>
5172  #include <linux/slab.h>
5173  #include <linux/ratelimit.h>
5174 +#include <linux/vs_tag.h>
5175  
5176  #include "ext4_jbd2.h"
5177  #include "xattr.h"
5178 @@ -4819,41 +4820,64 @@ void ext4_set_inode_flags(struct inode *
5179  {
5180         unsigned int flags = EXT4_I(inode)->i_flags;
5181  
5182 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
5183 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5184 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5185 +
5186 +       if (flags & EXT4_IMMUTABLE_FL)
5187 +               inode->i_flags |= S_IMMUTABLE;
5188 +       if (flags & EXT4_IXUNLINK_FL)
5189 +               inode->i_flags |= S_IXUNLINK;
5190 +
5191         if (flags & EXT4_SYNC_FL)
5192                 inode->i_flags |= S_SYNC;
5193         if (flags & EXT4_APPEND_FL)
5194                 inode->i_flags |= S_APPEND;
5195 -       if (flags & EXT4_IMMUTABLE_FL)
5196 -               inode->i_flags |= S_IMMUTABLE;
5197         if (flags & EXT4_NOATIME_FL)
5198                 inode->i_flags |= S_NOATIME;
5199         if (flags & EXT4_DIRSYNC_FL)
5200                 inode->i_flags |= S_DIRSYNC;
5201 +
5202 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5203 +
5204 +       if (flags & EXT4_BARRIER_FL)
5205 +               inode->i_vflags |= V_BARRIER;
5206 +       if (flags & EXT4_COW_FL)
5207 +               inode->i_vflags |= V_COW;
5208  }
5209  
5210  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
5211  void ext4_get_inode_flags(struct ext4_inode_info *ei)
5212  {
5213 -       unsigned int vfs_fl;
5214 +       unsigned int vfs_fl, vfs_vf;
5215         unsigned long old_fl, new_fl;
5216  
5217         do {
5218                 vfs_fl = ei->vfs_inode.i_flags;
5219 +               vfs_vf = ei->vfs_inode.i_vflags;
5220                 old_fl = ei->i_flags;
5221                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
5222                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
5223 -                               EXT4_DIRSYNC_FL);
5224 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
5225 +                               EXT4_COW_FL);
5226 +
5227 +               if (vfs_fl & S_IMMUTABLE)
5228 +                       new_fl |= EXT4_IMMUTABLE_FL;
5229 +               if (vfs_fl & S_IXUNLINK)
5230 +                       new_fl |= EXT4_IXUNLINK_FL;
5231 +
5232                 if (vfs_fl & S_SYNC)
5233                         new_fl |= EXT4_SYNC_FL;
5234                 if (vfs_fl & S_APPEND)
5235                         new_fl |= EXT4_APPEND_FL;
5236 -               if (vfs_fl & S_IMMUTABLE)
5237 -                       new_fl |= EXT4_IMMUTABLE_FL;
5238                 if (vfs_fl & S_NOATIME)
5239                         new_fl |= EXT4_NOATIME_FL;
5240                 if (vfs_fl & S_DIRSYNC)
5241                         new_fl |= EXT4_DIRSYNC_FL;
5242 +
5243 +               if (vfs_vf & V_BARRIER)
5244 +                       new_fl |= EXT4_BARRIER_FL;
5245 +               if (vfs_vf & V_COW)
5246 +                       new_fl |= EXT4_COW_FL;
5247         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
5248  }
5249  
5250 @@ -4889,6 +4913,8 @@ struct inode *ext4_iget(struct super_blo
5251         journal_t *journal = EXT4_SB(sb)->s_journal;
5252         long ret;
5253         int block;
5254 +       uid_t uid;
5255 +       gid_t gid;
5256  
5257         inode = iget_locked(sb, ino);
5258         if (!inode)
5259 @@ -4904,12 +4930,16 @@ struct inode *ext4_iget(struct super_blo
5260                 goto bad_inode;
5261         raw_inode = ext4_raw_inode(&iloc);
5262         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
5263 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
5264 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
5265 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
5266 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
5267         if (!(test_opt(inode->i_sb, NO_UID32))) {
5268 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
5269 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
5270 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
5271 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
5272         }
5273 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5274 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5275 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5276 +               le16_to_cpu(raw_inode->i_raw_tag));
5277         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
5278  
5279         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
5280 @@ -5128,6 +5158,8 @@ static int ext4_do_update_inode(handle_t
5281         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
5282         struct ext4_inode_info *ei = EXT4_I(inode);
5283         struct buffer_head *bh = iloc->bh;
5284 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5285 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5286         int err = 0, rc, block;
5287  
5288         /* For fields not not tracking in the in-memory inode,
5289 @@ -5138,29 +5170,32 @@ static int ext4_do_update_inode(handle_t
5290         ext4_get_inode_flags(ei);
5291         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
5292         if (!(test_opt(inode->i_sb, NO_UID32))) {
5293 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
5294 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
5295 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
5296 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
5297  /*
5298   * Fix up interoperability with old kernels. Otherwise, old inodes get
5299   * re-used with the upper 16 bits of the uid/gid intact
5300   */
5301                 if (!ei->i_dtime) {
5302                         raw_inode->i_uid_high =
5303 -                               cpu_to_le16(high_16_bits(inode->i_uid));
5304 +                               cpu_to_le16(high_16_bits(uid));
5305                         raw_inode->i_gid_high =
5306 -                               cpu_to_le16(high_16_bits(inode->i_gid));
5307 +                               cpu_to_le16(high_16_bits(gid));
5308                 } else {
5309                         raw_inode->i_uid_high = 0;
5310                         raw_inode->i_gid_high = 0;
5311                 }
5312         } else {
5313                 raw_inode->i_uid_low =
5314 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
5315 +                       cpu_to_le16(fs_high2lowuid(uid));
5316                 raw_inode->i_gid_low =
5317 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
5318 +                       cpu_to_le16(fs_high2lowgid(gid));
5319                 raw_inode->i_uid_high = 0;
5320                 raw_inode->i_gid_high = 0;
5321         }
5322 +#ifdef CONFIG_TAGGING_INTERN
5323 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
5324 +#endif
5325         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
5326  
5327         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
5328 @@ -5346,7 +5381,8 @@ int ext4_setattr(struct dentry *dentry, 
5329         if (is_quota_modification(inode, attr))
5330                 dquot_initialize(inode);
5331         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
5332 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
5333 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
5334 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
5335                 handle_t *handle;
5336  
5337                 /* (user+group)*(old+new) structure, inode write (sb,
5338 @@ -5368,6 +5404,8 @@ int ext4_setattr(struct dentry *dentry, 
5339                         inode->i_uid = attr->ia_uid;
5340                 if (attr->ia_valid & ATTR_GID)
5341                         inode->i_gid = attr->ia_gid;
5342 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5343 +                       inode->i_tag = attr->ia_tag;
5344                 error = ext4_mark_inode_dirty(handle, inode);
5345                 ext4_journal_stop(handle);
5346         }
5347 diff -NurpP --minimal linux-3.0.4/fs/ext4/ioctl.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/ioctl.c
5348 --- linux-3.0.4/fs/ext4/ioctl.c 2011-05-22 16:17:52.000000000 +0200
5349 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/ioctl.c 2011-06-10 22:11:24.000000000 +0200
5350 @@ -14,10 +14,39 @@
5351  #include <linux/compat.h>
5352  #include <linux/mount.h>
5353  #include <linux/file.h>
5354 +#include <linux/vs_tag.h>
5355  #include <asm/uaccess.h>
5356  #include "ext4_jbd2.h"
5357  #include "ext4.h"
5358  
5359 +
5360 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
5361 +{
5362 +       handle_t *handle = NULL;
5363 +       struct ext4_iloc iloc;
5364 +       int err;
5365 +
5366 +       handle = ext4_journal_start(inode, 1);
5367 +       if (IS_ERR(handle))
5368 +               return PTR_ERR(handle);
5369 +
5370 +       if (IS_SYNC(inode))
5371 +               ext4_handle_sync(handle);
5372 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
5373 +       if (err)
5374 +               goto flags_err;
5375 +
5376 +       inode->i_flags = flags;
5377 +       inode->i_vflags = vflags;
5378 +       ext4_get_inode_flags(EXT4_I(inode));
5379 +       inode->i_ctime = ext4_current_time(inode);
5380 +
5381 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
5382 +flags_err:
5383 +       ext4_journal_stop(handle);
5384 +       return err;
5385 +}
5386 +
5387  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5388  {
5389         struct inode *inode = filp->f_dentry->d_inode;
5390 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
5391  
5392                 flags = ext4_mask_flags(inode->i_mode, flags);
5393  
5394 +               if (IS_BARRIER(inode)) {
5395 +                       vxwprintk_task(1, "messing with the barrier.");
5396 +                       return -EACCES;
5397 +               }
5398 +
5399                 err = -EPERM;
5400                 mutex_lock(&inode->i_mutex);
5401                 /* Is it quota file? Do not allow user to mess with it */
5402 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
5403                  *
5404                  * This test looks nicer. Thanks to Pauline Middelink
5405                  */
5406 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
5407 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
5408 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
5409 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
5410                         if (!capable(CAP_LINUX_IMMUTABLE))
5411                                 goto flags_out;
5412                 }
5413 diff -NurpP --minimal linux-3.0.4/fs/ext4/namei.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/namei.c
5414 --- linux-3.0.4/fs/ext4/namei.c 2011-08-31 18:56:42.000000000 +0200
5415 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/namei.c 2011-08-29 03:45:09.000000000 +0200
5416 @@ -34,6 +34,7 @@
5417  #include <linux/quotaops.h>
5418  #include <linux/buffer_head.h>
5419  #include <linux/bio.h>
5420 +#include <linux/vs_tag.h>
5421  #include "ext4.h"
5422  #include "ext4_jbd2.h"
5423  
5424 @@ -924,6 +925,7 @@ restart:
5425                                 if (bh)
5426                                         ll_rw_block(READ_META, 1, &bh);
5427                         }
5428 +               dx_propagate_tag(nd, inode);
5429                 }
5430                 if ((bh = bh_use[ra_ptr++]) == NULL)
5431                         goto next;
5432 @@ -2598,6 +2600,7 @@ const struct inode_operations ext4_dir_i
5433  #endif
5434         .check_acl      = ext4_check_acl,
5435         .fiemap         = ext4_fiemap,
5436 +       .sync_flags     = ext4_sync_flags,
5437  };
5438  
5439  const struct inode_operations ext4_special_inode_operations = {
5440 diff -NurpP --minimal linux-3.0.4/fs/ext4/super.c linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/super.c
5441 --- linux-3.0.4/fs/ext4/super.c 2011-08-31 18:56:42.000000000 +0200
5442 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ext4/super.c 2011-08-31 19:37:44.000000000 +0200
5443 @@ -1293,6 +1293,7 @@ enum {
5444         Opt_dioread_nolock, Opt_dioread_lock,
5445         Opt_discard, Opt_nodiscard,
5446         Opt_init_inode_table, Opt_noinit_inode_table,
5447 +       Opt_tag, Opt_notag, Opt_tagid
5448  };
5449  
5450  static const match_table_t tokens = {
5451 @@ -1368,6 +1369,9 @@ static const match_table_t tokens = {
5452         {Opt_init_inode_table, "init_itable=%u"},
5453         {Opt_init_inode_table, "init_itable"},
5454         {Opt_noinit_inode_table, "noinit_itable"},
5455 +       {Opt_tag, "tag"},
5456 +       {Opt_notag, "notag"},
5457 +       {Opt_tagid, "tagid=%u"},
5458         {Opt_err, NULL},
5459  };
5460  
5461 @@ -1536,6 +1540,20 @@ static int parse_options(char *options, 
5462                 case Opt_nouid32:
5463                         set_opt(sb, NO_UID32);
5464                         break;
5465 +#ifndef CONFIG_TAGGING_NONE
5466 +               case Opt_tag:
5467 +                       set_opt(sb, TAGGED);
5468 +                       break;
5469 +               case Opt_notag:
5470 +                       clear_opt(sb, TAGGED);
5471 +                       break;
5472 +#endif
5473 +#ifdef CONFIG_PROPAGATE
5474 +               case Opt_tagid:
5475 +                       /* use args[0] */
5476 +                       set_opt(sb, TAGGED);
5477 +                       break;
5478 +#endif
5479                 case Opt_debug:
5480                         set_opt(sb, DEBUG);
5481                         break;
5482 @@ -3193,6 +3211,9 @@ static int ext4_fill_super(struct super_
5483                            &journal_ioprio, NULL, 0))
5484                 goto failed_mount;
5485  
5486 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
5487 +               sb->s_flags |= MS_TAGGED;
5488 +
5489         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
5490                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
5491  
5492 @@ -4323,6 +4344,14 @@ static int ext4_remount(struct super_blo
5493         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
5494                 ext4_abort(sb, "Abort forced by user");
5495  
5496 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
5497 +               !(sb->s_flags & MS_TAGGED)) {
5498 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
5499 +                       sb->s_id);
5500 +               err = -EINVAL;
5501 +               goto restore_opts;
5502 +       }
5503 +
5504         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
5505                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
5506  
5507 diff -NurpP --minimal linux-3.0.4/fs/fcntl.c linux-3.0.4-vs2.3.1-pre10.1/fs/fcntl.c
5508 --- linux-3.0.4/fs/fcntl.c      2011-05-22 16:17:52.000000000 +0200
5509 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/fcntl.c      2011-06-10 22:11:24.000000000 +0200
5510 @@ -20,6 +20,7 @@
5511  #include <linux/signal.h>
5512  #include <linux/rcupdate.h>
5513  #include <linux/pid_namespace.h>
5514 +#include <linux/vs_limit.h>
5515  
5516  #include <asm/poll.h>
5517  #include <asm/siginfo.h>
5518 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
5519  
5520         if (tofree)
5521                 filp_close(tofree, files);
5522 +       else
5523 +               vx_openfd_inc(newfd);   /* fd was unused */
5524  
5525         return newfd;
5526  
5527 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
5528         filp = fget_raw(fd);
5529         if (!filp)
5530                 goto out;
5531 +       if (!vx_files_avail(1))
5532 +               goto out;
5533  
5534         if (unlikely(filp->f_mode & FMODE_PATH)) {
5535                 if (!check_fcntl_cmd(cmd)) {
5536 diff -NurpP --minimal linux-3.0.4/fs/file.c linux-3.0.4-vs2.3.1-pre10.1/fs/file.c
5537 --- linux-3.0.4/fs/file.c       2011-05-22 16:17:52.000000000 +0200
5538 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/file.c       2011-06-10 22:11:24.000000000 +0200
5539 @@ -21,6 +21,7 @@
5540  #include <linux/spinlock.h>
5541  #include <linux/rcupdate.h>
5542  #include <linux/workqueue.h>
5543 +#include <linux/vs_limit.h>
5544  
5545  struct fdtable_defer {
5546         spinlock_t lock;
5547 @@ -359,6 +360,8 @@ struct files_struct *dup_fd(struct files
5548                 struct file *f = *old_fds++;
5549                 if (f) {
5550                         get_file(f);
5551 +                       /* TODO: sum it first for check and performance */
5552 +                       vx_openfd_inc(open_files - i);
5553                 } else {
5554                         /*
5555                          * The fd may be claimed in the fd bitmap but not yet
5556 @@ -466,6 +469,7 @@ repeat:
5557         else
5558                 FD_CLR(fd, fdt->close_on_exec);
5559         error = fd;
5560 +       vx_openfd_inc(fd);
5561  #if 1
5562         /* Sanity check */
5563         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
5564 diff -NurpP --minimal linux-3.0.4/fs/file_table.c linux-3.0.4-vs2.3.1-pre10.1/fs/file_table.c
5565 --- linux-3.0.4/fs/file_table.c 2011-05-22 16:17:52.000000000 +0200
5566 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/file_table.c 2011-06-10 22:11:24.000000000 +0200
5567 @@ -24,6 +24,8 @@
5568  #include <linux/percpu_counter.h>
5569  #include <linux/percpu.h>
5570  #include <linux/ima.h>
5571 +#include <linux/vs_limit.h>
5572 +#include <linux/vs_context.h>
5573  
5574  #include <asm/atomic.h>
5575  
5576 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
5577         spin_lock_init(&f->f_lock);
5578         eventpoll_init_file(f);
5579         /* f->f_version: 0 */
5580 +       f->f_xid = vx_current_xid();
5581 +       vx_files_inc(f);
5582         return f;
5583  
5584  over:
5585 @@ -253,6 +257,8 @@ static void __fput(struct file *file)
5586         }
5587         fops_put(file->f_op);
5588         put_pid(file->f_owner.pid);
5589 +       vx_files_dec(file);
5590 +       file->f_xid = 0;
5591         file_sb_list_del(file);
5592         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
5593                 i_readcount_dec(inode);
5594 @@ -383,6 +389,8 @@ void put_filp(struct file *file)
5595  {
5596         if (atomic_long_dec_and_test(&file->f_count)) {
5597                 security_file_free(file);
5598 +               vx_files_dec(file);
5599 +               file->f_xid = 0;
5600                 file_sb_list_del(file);
5601                 file_free(file);
5602         }
5603 diff -NurpP --minimal linux-3.0.4/fs/fs_struct.c linux-3.0.4-vs2.3.1-pre10.1/fs/fs_struct.c
5604 --- linux-3.0.4/fs/fs_struct.c  2011-03-15 18:07:31.000000000 +0100
5605 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/fs_struct.c  2011-06-10 22:11:24.000000000 +0200
5606 @@ -4,6 +4,7 @@
5607  #include <linux/path.h>
5608  #include <linux/slab.h>
5609  #include <linux/fs_struct.h>
5610 +#include <linux/vserver/global.h>
5611  #include "internal.h"
5612  
5613  static inline void path_get_longterm(struct path *path)
5614 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
5615  {
5616         path_put_longterm(&fs->root);
5617         path_put_longterm(&fs->pwd);
5618 +       atomic_dec(&vs_global_fs);
5619         kmem_cache_free(fs_cachep, fs);
5620  }
5621  
5622 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
5623                 fs->pwd = old->pwd;
5624                 path_get_longterm(&fs->pwd);
5625                 spin_unlock(&old->lock);
5626 +               atomic_inc(&vs_global_fs);
5627         }
5628         return fs;
5629  }
5630 diff -NurpP --minimal linux-3.0.4/fs/gfs2/file.c linux-3.0.4-vs2.3.1-pre10.1/fs/gfs2/file.c
5631 --- linux-3.0.4/fs/gfs2/file.c  2011-07-22 11:18:05.000000000 +0200
5632 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/gfs2/file.c  2011-06-10 22:11:24.000000000 +0200
5633 @@ -134,6 +134,9 @@ static const u32 fsflags_to_gfs2[32] = {
5634         [7] = GFS2_DIF_NOATIME,
5635         [12] = GFS2_DIF_EXHASH,
5636         [14] = GFS2_DIF_INHERIT_JDATA,
5637 +       [27] = GFS2_DIF_IXUNLINK,
5638 +       [26] = GFS2_DIF_BARRIER,
5639 +       [29] = GFS2_DIF_COW,
5640  };
5641  
5642  static const u32 gfs2_to_fsflags[32] = {
5643 @@ -143,6 +146,9 @@ static const u32 gfs2_to_fsflags[32] = {
5644         [gfs2fl_NoAtime] = FS_NOATIME_FL,
5645         [gfs2fl_ExHash] = FS_INDEX_FL,
5646         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
5647 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
5648 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
5649 +       [gfs2fl_Cow] = FS_COW_FL,
5650  };
5651  
5652  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
5653 @@ -173,10 +179,16 @@ void gfs2_set_inode_flags(struct inode *
5654  {
5655         struct gfs2_inode *ip = GFS2_I(inode);
5656         unsigned int flags = inode->i_flags;
5657 +       unsigned int vflags = inode->i_vflags;
5658 +
5659 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5660 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5661  
5662 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
5663         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
5664                 flags |= S_IMMUTABLE;
5665 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
5666 +               flags |= S_IXUNLINK;
5667 +
5668         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
5669                 flags |= S_APPEND;
5670         if (ip->i_diskflags & GFS2_DIF_NOATIME)
5671 @@ -184,6 +196,43 @@ void gfs2_set_inode_flags(struct inode *
5672         if (ip->i_diskflags & GFS2_DIF_SYNC)
5673                 flags |= S_SYNC;
5674         inode->i_flags = flags;
5675 +
5676 +       vflags &= ~(V_BARRIER | V_COW);
5677 +
5678 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
5679 +               vflags |= V_BARRIER;
5680 +       if (ip->i_diskflags & GFS2_DIF_COW)
5681 +               vflags |= V_COW;
5682 +       inode->i_vflags = vflags;
5683 +}
5684 +
5685 +void gfs2_get_inode_flags(struct inode *inode)
5686 +{
5687 +       struct gfs2_inode *ip = GFS2_I(inode);
5688 +       unsigned int flags = inode->i_flags;
5689 +       unsigned int vflags = inode->i_vflags;
5690 +
5691 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
5692 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
5693 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
5694 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
5695 +
5696 +       if (flags & S_IMMUTABLE)
5697 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
5698 +       if (flags & S_IXUNLINK)
5699 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
5700 +
5701 +       if (flags & S_APPEND)
5702 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
5703 +       if (flags & S_NOATIME)
5704 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
5705 +       if (flags & S_SYNC)
5706 +               ip->i_diskflags |= GFS2_DIF_SYNC;
5707 +
5708 +       if (vflags & V_BARRIER)
5709 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
5710 +       if (vflags & V_COW)
5711 +               ip->i_diskflags |= GFS2_DIF_COW;
5712  }
5713  
5714  /* Flags that can be set by user space */
5715 @@ -295,6 +344,37 @@ static int gfs2_set_flags(struct file *f
5716         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
5717  }
5718  
5719 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
5720 +{
5721 +       struct gfs2_inode *ip = GFS2_I(inode);
5722 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
5723 +       struct buffer_head *bh;
5724 +       struct gfs2_holder gh;
5725 +       int error;
5726 +
5727 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
5728 +       if (error)
5729 +               return error;
5730 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
5731 +       if (error)
5732 +               goto out;
5733 +       error = gfs2_meta_inode_buffer(ip, &bh);
5734 +       if (error)
5735 +               goto out_trans_end;
5736 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
5737 +       inode->i_flags = flags;
5738 +       inode->i_vflags = vflags;
5739 +       gfs2_get_inode_flags(inode);
5740 +       gfs2_dinode_out(ip, bh->b_data);
5741 +       brelse(bh);
5742 +       gfs2_set_aops(inode);
5743 +out_trans_end:
5744 +       gfs2_trans_end(sdp);
5745 +out:
5746 +       gfs2_glock_dq_uninit(&gh);
5747 +       return error;
5748 +}
5749 +
5750  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5751  {
5752         switch(cmd) {
5753 diff -NurpP --minimal linux-3.0.4/fs/gfs2/inode.h linux-3.0.4-vs2.3.1-pre10.1/fs/gfs2/inode.h
5754 --- linux-3.0.4/fs/gfs2/inode.h 2011-07-22 11:18:05.000000000 +0200
5755 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/gfs2/inode.h 2011-06-10 22:11:24.000000000 +0200
5756 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
5757  extern const struct file_operations gfs2_dir_fops_nolock;
5758  
5759  extern void gfs2_set_inode_flags(struct inode *inode);
5760 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
5761   
5762  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
5763  extern const struct file_operations gfs2_file_fops;
5764 diff -NurpP --minimal linux-3.0.4/fs/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/inode.c
5765 --- linux-3.0.4/fs/inode.c      2011-07-22 11:18:05.000000000 +0200
5766 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/inode.c      2011-07-01 11:35:34.000000000 +0200
5767 @@ -26,6 +26,7 @@
5768  #include <linux/ima.h>
5769  #include <linux/cred.h>
5770  #include <linux/buffer_head.h> /* for inode_has_buffers */
5771 +#include <linux/vs_tag.h>
5772  #include "internal.h"
5773  
5774  /*
5775 @@ -146,6 +147,9 @@ int inode_init_always(struct super_block
5776         struct address_space *const mapping = &inode->i_data;
5777  
5778         inode->i_sb = sb;
5779 +
5780 +       /* essential because of inode slab reuse */
5781 +       inode->i_tag = 0;
5782         inode->i_blkbits = sb->s_blocksize_bits;
5783         inode->i_flags = 0;
5784         atomic_set(&inode->i_count, 1);
5785 @@ -166,6 +170,7 @@ int inode_init_always(struct super_block
5786         inode->i_bdev = NULL;
5787         inode->i_cdev = NULL;
5788         inode->i_rdev = 0;
5789 +       inode->i_mdev = 0;
5790         inode->dirtied_when = 0;
5791  
5792         if (security_inode_alloc(inode))
5793 @@ -404,6 +409,8 @@ void __insert_inode_hash(struct inode *i
5794  }
5795  EXPORT_SYMBOL(__insert_inode_hash);
5796  
5797 +EXPORT_SYMBOL_GPL(__iget);
5798 +
5799  /**
5800   *     remove_inode_hash - remove an inode from the hash
5801   *     @inode: inode to unhash
5802 @@ -1643,9 +1650,11 @@ void init_special_inode(struct inode *in
5803         if (S_ISCHR(mode)) {
5804                 inode->i_fop = &def_chr_fops;
5805                 inode->i_rdev = rdev;
5806 +               inode->i_mdev = rdev;
5807         } else if (S_ISBLK(mode)) {
5808                 inode->i_fop = &def_blk_fops;
5809                 inode->i_rdev = rdev;
5810 +               inode->i_mdev = rdev;
5811         } else if (S_ISFIFO(mode))
5812                 inode->i_fop = &def_fifo_fops;
5813         else if (S_ISSOCK(mode))
5814 @@ -1674,6 +1683,7 @@ void inode_init_owner(struct inode *inod
5815         } else
5816                 inode->i_gid = current_fsgid();
5817         inode->i_mode = mode;
5818 +       inode->i_tag = dx_current_fstag(inode->i_sb);
5819  }
5820  EXPORT_SYMBOL(inode_init_owner);
5821  
5822 diff -NurpP --minimal linux-3.0.4/fs/ioctl.c linux-3.0.4-vs2.3.1-pre10.1/fs/ioctl.c
5823 --- linux-3.0.4/fs/ioctl.c      2011-05-22 16:17:52.000000000 +0200
5824 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ioctl.c      2011-06-10 22:11:24.000000000 +0200
5825 @@ -15,6 +15,9 @@
5826  #include <linux/writeback.h>
5827  #include <linux/buffer_head.h>
5828  #include <linux/falloc.h>
5829 +#include <linux/proc_fs.h>
5830 +#include <linux/vserver/inode.h>
5831 +#include <linux/vs_tag.h>
5832  
5833  #include <asm/ioctls.h>
5834  
5835 diff -NurpP --minimal linux-3.0.4/fs/ioprio.c linux-3.0.4-vs2.3.1-pre10.1/fs/ioprio.c
5836 --- linux-3.0.4/fs/ioprio.c     2011-01-05 21:50:24.000000000 +0100
5837 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ioprio.c     2011-06-10 22:11:24.000000000 +0200
5838 @@ -27,6 +27,7 @@
5839  #include <linux/syscalls.h>
5840  #include <linux/security.h>
5841  #include <linux/pid_namespace.h>
5842 +#include <linux/vs_base.h>
5843  
5844  int set_task_ioprio(struct task_struct *task, int ioprio)
5845  {
5846 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
5847                         else
5848                                 pgrp = find_vpid(who);
5849                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
5850 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5851 +                                       continue;
5852                                 ret = set_task_ioprio(p, ioprio);
5853                                 if (ret)
5854                                         break;
5855 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
5856                         else
5857                                 pgrp = find_vpid(who);
5858                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
5859 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5860 +                                       continue;
5861                                 tmpio = get_task_ioprio(p);
5862                                 if (tmpio < 0)
5863                                         continue;
5864 diff -NurpP --minimal linux-3.0.4/fs/jfs/file.c linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/file.c
5865 --- linux-3.0.4/fs/jfs/file.c   2011-07-22 11:18:05.000000000 +0200
5866 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/file.c   2011-07-01 11:35:34.000000000 +0200
5867 @@ -102,7 +102,8 @@ int jfs_setattr(struct dentry *dentry, s
5868         if (is_quota_modification(inode, iattr))
5869                 dquot_initialize(inode);
5870         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
5871 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
5872 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
5873 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
5874                 rc = dquot_transfer(inode, iattr);
5875                 if (rc)
5876                         return rc;
5877 @@ -133,6 +134,7 @@ const struct inode_operations jfs_file_i
5878  #ifdef CONFIG_JFS_POSIX_ACL
5879         .check_acl      = jfs_check_acl,
5880  #endif
5881 +       .sync_flags     = jfs_sync_flags,
5882  };
5883  
5884  const struct file_operations jfs_file_operations = {
5885 diff -NurpP --minimal linux-3.0.4/fs/jfs/ioctl.c linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/ioctl.c
5886 --- linux-3.0.4/fs/jfs/ioctl.c  2011-05-22 16:17:52.000000000 +0200
5887 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/ioctl.c  2011-06-10 22:11:24.000000000 +0200
5888 @@ -11,6 +11,7 @@
5889  #include <linux/mount.h>
5890  #include <linux/time.h>
5891  #include <linux/sched.h>
5892 +#include <linux/mount.h>
5893  #include <asm/current.h>
5894  #include <asm/uaccess.h>
5895  
5896 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
5897  }
5898  
5899  
5900 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
5901 +{
5902 +       inode->i_flags = flags;
5903 +       inode->i_vflags = vflags;
5904 +       jfs_get_inode_flags(JFS_IP(inode));
5905 +       inode->i_ctime = CURRENT_TIME_SEC;
5906 +       mark_inode_dirty(inode);
5907 +       return 0;
5908 +}
5909 +
5910  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5911  {
5912         struct inode *inode = filp->f_dentry->d_inode;
5913 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
5914                 if (!S_ISDIR(inode->i_mode))
5915                         flags &= ~JFS_DIRSYNC_FL;
5916  
5917 +               if (IS_BARRIER(inode)) {
5918 +                       vxwprintk_task(1, "messing with the barrier.");
5919 +                       return -EACCES;
5920 +               }
5921 +
5922                 /* Is it quota file? Do not allow user to mess with it */
5923                 if (IS_NOQUOTA(inode)) {
5924                         err = -EPERM;
5925 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
5926                  * the relevant capability.
5927                  */
5928                 if ((oldflags & JFS_IMMUTABLE_FL) ||
5929 -                       ((flags ^ oldflags) &
5930 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
5931 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
5932 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
5933                         if (!capable(CAP_LINUX_IMMUTABLE)) {
5934                                 mutex_unlock(&inode->i_mutex);
5935                                 err = -EPERM;
5936 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
5937                         }
5938                 }
5939  
5940 -               flags = flags & JFS_FL_USER_MODIFIABLE;
5941 +               flags &= JFS_FL_USER_MODIFIABLE;
5942                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
5943                 jfs_inode->mode2 = flags;
5944  
5945 diff -NurpP --minimal linux-3.0.4/fs/jfs/jfs_dinode.h linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_dinode.h
5946 --- linux-3.0.4/fs/jfs/jfs_dinode.h     2008-12-25 00:26:37.000000000 +0100
5947 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_dinode.h     2011-06-10 22:11:24.000000000 +0200
5948 @@ -161,9 +161,13 @@ struct dinode {
5949  
5950  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
5951  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
5952 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
5953  
5954 -#define JFS_FL_USER_VISIBLE    0x03F80000
5955 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
5956 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
5957 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
5958 +
5959 +#define JFS_FL_USER_VISIBLE    0x07F80000
5960 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
5961  #define JFS_FL_INHERIT         0x03C80000
5962  
5963  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
5964 diff -NurpP --minimal linux-3.0.4/fs/jfs/jfs_filsys.h linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_filsys.h
5965 --- linux-3.0.4/fs/jfs/jfs_filsys.h     2008-12-25 00:26:37.000000000 +0100
5966 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_filsys.h     2011-06-10 22:11:24.000000000 +0200
5967 @@ -263,6 +263,7 @@
5968  #define JFS_NAME_MAX   255
5969  #define JFS_PATH_MAX   BPSIZE
5970  
5971 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
5972  
5973  /*
5974   *     file system state (superblock state)
5975 diff -NurpP --minimal linux-3.0.4/fs/jfs/jfs_imap.c linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_imap.c
5976 --- linux-3.0.4/fs/jfs/jfs_imap.c       2011-07-22 11:18:05.000000000 +0200
5977 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_imap.c       2011-07-01 11:35:34.000000000 +0200
5978 @@ -46,6 +46,7 @@
5979  #include <linux/pagemap.h>
5980  #include <linux/quotaops.h>
5981  #include <linux/slab.h>
5982 +#include <linux/vs_tag.h>
5983  
5984  #include "jfs_incore.h"
5985  #include "jfs_inode.h"
5986 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
5987  {
5988         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
5989         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
5990 +       uid_t uid;
5991 +       gid_t gid;
5992  
5993         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
5994         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
5995 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
5996         }
5997         ip->i_nlink = le32_to_cpu(dip->di_nlink);
5998  
5999 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
6000 +       uid = le32_to_cpu(dip->di_uid);
6001 +       gid = le32_to_cpu(dip->di_gid);
6002 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
6003 +
6004 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
6005         if (sbi->uid == -1)
6006                 ip->i_uid = jfs_ip->saved_uid;
6007         else {
6008                 ip->i_uid = sbi->uid;
6009         }
6010  
6011 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
6012 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
6013         if (sbi->gid == -1)
6014                 ip->i_gid = jfs_ip->saved_gid;
6015         else {
6016 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
6017         dip->di_size = cpu_to_le64(ip->i_size);
6018         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
6019         dip->di_nlink = cpu_to_le32(ip->i_nlink);
6020 -       if (sbi->uid == -1)
6021 -               dip->di_uid = cpu_to_le32(ip->i_uid);
6022 -       else
6023 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
6024 -       if (sbi->gid == -1)
6025 -               dip->di_gid = cpu_to_le32(ip->i_gid);
6026 -       else
6027 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
6028 +
6029 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
6030 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
6031 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
6032 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
6033 +
6034         jfs_get_inode_flags(jfs_ip);
6035         /*
6036          * mode2 is only needed for storing the higher order bits.
6037 diff -NurpP --minimal linux-3.0.4/fs/jfs/jfs_inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_inode.c
6038 --- linux-3.0.4/fs/jfs/jfs_inode.c      2010-08-02 16:52:49.000000000 +0200
6039 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_inode.c      2011-06-10 22:11:24.000000000 +0200
6040 @@ -18,6 +18,7 @@
6041  
6042  #include <linux/fs.h>
6043  #include <linux/quotaops.h>
6044 +#include <linux/vs_tag.h>
6045  #include "jfs_incore.h"
6046  #include "jfs_inode.h"
6047  #include "jfs_filsys.h"
6048 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
6049  {
6050         unsigned int flags = JFS_IP(inode)->mode2;
6051  
6052 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
6053 -               S_NOATIME | S_DIRSYNC | S_SYNC);
6054 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6055 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6056  
6057         if (flags & JFS_IMMUTABLE_FL)
6058                 inode->i_flags |= S_IMMUTABLE;
6059 +       if (flags & JFS_IXUNLINK_FL)
6060 +               inode->i_flags |= S_IXUNLINK;
6061 +
6062 +       if (flags & JFS_SYNC_FL)
6063 +               inode->i_flags |= S_SYNC;
6064         if (flags & JFS_APPEND_FL)
6065                 inode->i_flags |= S_APPEND;
6066         if (flags & JFS_NOATIME_FL)
6067                 inode->i_flags |= S_NOATIME;
6068         if (flags & JFS_DIRSYNC_FL)
6069                 inode->i_flags |= S_DIRSYNC;
6070 -       if (flags & JFS_SYNC_FL)
6071 -               inode->i_flags |= S_SYNC;
6072 +
6073 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6074 +
6075 +       if (flags & JFS_BARRIER_FL)
6076 +               inode->i_vflags |= V_BARRIER;
6077 +       if (flags & JFS_COW_FL)
6078 +               inode->i_vflags |= V_COW;
6079  }
6080  
6081  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
6082  {
6083         unsigned int flags = jfs_ip->vfs_inode.i_flags;
6084 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
6085 +
6086 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
6087 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
6088 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
6089 +                          JFS_BARRIER_FL | JFS_COW_FL);
6090  
6091 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
6092 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
6093         if (flags & S_IMMUTABLE)
6094                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
6095 +       if (flags & S_IXUNLINK)
6096 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
6097 +
6098         if (flags & S_APPEND)
6099                 jfs_ip->mode2 |= JFS_APPEND_FL;
6100         if (flags & S_NOATIME)
6101 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
6102                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
6103         if (flags & S_SYNC)
6104                 jfs_ip->mode2 |= JFS_SYNC_FL;
6105 +
6106 +       if (vflags & V_BARRIER)
6107 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
6108 +       if (vflags & V_COW)
6109 +               jfs_ip->mode2 |= JFS_COW_FL;
6110  }
6111  
6112  /*
6113 diff -NurpP --minimal linux-3.0.4/fs/jfs/jfs_inode.h linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_inode.h
6114 --- linux-3.0.4/fs/jfs/jfs_inode.h      2011-07-22 11:18:05.000000000 +0200
6115 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/jfs_inode.h      2011-06-10 22:11:24.000000000 +0200
6116 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
6117  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
6118         int fh_len, int fh_type);
6119  extern void jfs_set_inode_flags(struct inode *);
6120 +extern int jfs_sync_flags(struct inode *, int, int);
6121  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
6122  extern int jfs_setattr(struct dentry *, struct iattr *);
6123  
6124 diff -NurpP --minimal linux-3.0.4/fs/jfs/namei.c linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/namei.c
6125 --- linux-3.0.4/fs/jfs/namei.c  2011-05-22 16:17:53.000000000 +0200
6126 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/namei.c  2011-06-10 22:11:24.000000000 +0200
6127 @@ -22,6 +22,7 @@
6128  #include <linux/ctype.h>
6129  #include <linux/quotaops.h>
6130  #include <linux/exportfs.h>
6131 +#include <linux/vs_tag.h>
6132  #include "jfs_incore.h"
6133  #include "jfs_superblock.h"
6134  #include "jfs_inode.h"
6135 @@ -1486,6 +1487,7 @@ static struct dentry *jfs_lookup(struct 
6136                 return ERR_CAST(ip);
6137         }
6138  
6139 +       dx_propagate_tag(nd, ip);
6140         return d_splice_alias(ip, dentry);
6141  }
6142  
6143 @@ -1550,6 +1552,7 @@ const struct inode_operations jfs_dir_in
6144  #ifdef CONFIG_JFS_POSIX_ACL
6145         .check_acl      = jfs_check_acl,
6146  #endif
6147 +       .sync_flags     = jfs_sync_flags,
6148  };
6149  
6150  const struct file_operations jfs_dir_operations = {
6151 diff -NurpP --minimal linux-3.0.4/fs/jfs/super.c linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/super.c
6152 --- linux-3.0.4/fs/jfs/super.c  2011-05-22 16:17:53.000000000 +0200
6153 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/jfs/super.c  2011-06-10 22:11:24.000000000 +0200
6154 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
6155  enum {
6156         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
6157         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
6158 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
6159 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
6160 +       Opt_tag, Opt_notag, Opt_tagid
6161  };
6162  
6163  static const match_table_t tokens = {
6164 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
6165         {Opt_resize, "resize=%u"},
6166         {Opt_resize_nosize, "resize"},
6167         {Opt_errors, "errors=%s"},
6168 +       {Opt_tag, "tag"},
6169 +       {Opt_notag, "notag"},
6170 +       {Opt_tagid, "tagid=%u"},
6171 +       {Opt_tag, "tagxid"},
6172         {Opt_ignore, "noquota"},
6173         {Opt_ignore, "quota"},
6174         {Opt_usrquota, "usrquota"},
6175 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
6176                         }
6177                         break;
6178                 }
6179 +#ifndef CONFIG_TAGGING_NONE
6180 +               case Opt_tag:
6181 +                       *flag |= JFS_TAGGED;
6182 +                       break;
6183 +               case Opt_notag:
6184 +                       *flag &= JFS_TAGGED;
6185 +                       break;
6186 +#endif
6187 +#ifdef CONFIG_PROPAGATE
6188 +               case Opt_tagid:
6189 +                       /* use args[0] */
6190 +                       *flag |= JFS_TAGGED;
6191 +                       break;
6192 +#endif
6193                 default:
6194                         printk("jfs: Unrecognized mount option \"%s\" "
6195                                         " or missing value\n", p);
6196 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
6197                 return -EINVAL;
6198         }
6199  
6200 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
6201 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
6202 +                       sb->s_id);
6203 +               return -EINVAL;
6204 +       }
6205 +
6206         if (newLVSize) {
6207                 if (sb->s_flags & MS_RDONLY) {
6208                         printk(KERN_ERR
6209 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
6210  #ifdef CONFIG_JFS_POSIX_ACL
6211         sb->s_flags |= MS_POSIXACL;
6212  #endif
6213 +       /* map mount option tagxid */
6214 +       if (sbi->flag & JFS_TAGGED)
6215 +               sb->s_flags |= MS_TAGGED;
6216  
6217         if (newLVSize) {
6218                 printk(KERN_ERR "resize option for remount only\n");
6219 diff -NurpP --minimal linux-3.0.4/fs/libfs.c linux-3.0.4-vs2.3.1-pre10.1/fs/libfs.c
6220 --- linux-3.0.4/fs/libfs.c      2011-07-22 11:18:05.000000000 +0200
6221 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/libfs.c      2011-07-22 11:20:39.000000000 +0200
6222 @@ -133,7 +133,8 @@ static inline unsigned char dt_type(stru
6223   * both impossible due to the lock on directory.
6224   */
6225  
6226 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
6227 +static inline int do_dcache_readdir_filter(struct file *filp,
6228 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
6229  {
6230         struct dentry *dentry = filp->f_path.dentry;
6231         struct dentry *cursor = filp->private_data;
6232 @@ -164,6 +165,8 @@ int dcache_readdir(struct file * filp, v
6233                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
6234                                 struct dentry *next;
6235                                 next = list_entry(p, struct dentry, d_u.d_child);
6236 +                               if (filter && !filter(next))
6237 +                                       continue;
6238                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
6239                                 if (!simple_positive(next)) {
6240                                         spin_unlock(&next->d_lock);
6241 @@ -190,6 +193,17 @@ int dcache_readdir(struct file * filp, v
6242         return 0;
6243  }
6244  
6245 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
6246 +{
6247 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
6248 +}
6249 +
6250 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
6251 +       int (*filter)(struct dentry *))
6252 +{
6253 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
6254 +}
6255 +
6256  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
6257  {
6258         return -EISDIR;
6259 @@ -965,6 +979,7 @@ EXPORT_SYMBOL(dcache_dir_close);
6260  EXPORT_SYMBOL(dcache_dir_lseek);
6261  EXPORT_SYMBOL(dcache_dir_open);
6262  EXPORT_SYMBOL(dcache_readdir);
6263 +EXPORT_SYMBOL(dcache_readdir_filter);
6264  EXPORT_SYMBOL(generic_read_dir);
6265  EXPORT_SYMBOL(mount_pseudo);
6266  EXPORT_SYMBOL(simple_write_begin);
6267 diff -NurpP --minimal linux-3.0.4/fs/locks.c linux-3.0.4-vs2.3.1-pre10.1/fs/locks.c
6268 --- linux-3.0.4/fs/locks.c      2011-07-22 11:18:05.000000000 +0200
6269 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/locks.c      2011-07-19 00:51:58.000000000 +0200
6270 @@ -126,6 +126,8 @@
6271  #include <linux/time.h>
6272  #include <linux/rcupdate.h>
6273  #include <linux/pid_namespace.h>
6274 +#include <linux/vs_base.h>
6275 +#include <linux/vs_limit.h>
6276  
6277  #include <asm/uaccess.h>
6278  
6279 @@ -171,13 +173,19 @@ static void locks_init_lock_always(struc
6280         fl->fl_flags = 0;
6281         fl->fl_type = 0;
6282         fl->fl_start = fl->fl_end = 0;
6283 +       fl->fl_xid = -1;
6284  }
6285  
6286 +
6287  /* Allocate an empty lock structure. */
6288  struct file_lock *locks_alloc_lock(void)
6289  {
6290 -       struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
6291 +       struct file_lock *fl;
6292 +
6293 +       if (!vx_locks_avail(1))
6294 +               return NULL;
6295  
6296 +       fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
6297         if (fl)
6298                 locks_init_lock_always(fl);
6299  
6300 @@ -208,6 +216,7 @@ void locks_free_lock(struct file_lock *f
6301         BUG_ON(!list_empty(&fl->fl_block));
6302         BUG_ON(!list_empty(&fl->fl_link));
6303  
6304 +       vx_locks_dec(fl);
6305         locks_release_private(fl);
6306         kmem_cache_free(filelock_cache, fl);
6307  }
6308 @@ -272,6 +281,7 @@ void locks_copy_lock(struct file_lock *n
6309         new->fl_file = fl->fl_file;
6310         new->fl_ops = fl->fl_ops;
6311         new->fl_lmops = fl->fl_lmops;
6312 +       new->fl_xid = fl->fl_xid;
6313  
6314         locks_copy_private(new, fl);
6315  }
6316 @@ -310,6 +320,11 @@ static int flock_make_lock(struct file *
6317         fl->fl_flags = FL_FLOCK;
6318         fl->fl_type = type;
6319         fl->fl_end = OFFSET_MAX;
6320 +
6321 +       vxd_assert(filp->f_xid == vx_current_xid(),
6322 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6323 +       fl->fl_xid = filp->f_xid;
6324 +       vx_locks_inc(fl);
6325         
6326         *lock = fl;
6327         return 0;
6328 @@ -459,6 +474,7 @@ static int lease_init(struct file *filp,
6329  
6330         fl->fl_owner = current->files;
6331         fl->fl_pid = current->tgid;
6332 +       fl->fl_xid = vx_current_xid();
6333  
6334         fl->fl_file = filp;
6335         fl->fl_flags = FL_LEASE;
6336 @@ -478,6 +494,11 @@ static struct file_lock *lease_alloc(str
6337         if (fl == NULL)
6338                 return ERR_PTR(error);
6339  
6340 +       fl->fl_xid = vx_current_xid();
6341 +       if (filp)
6342 +               vxd_assert(filp->f_xid == fl->fl_xid,
6343 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
6344 +       vx_locks_inc(fl);
6345         error = lease_init(filp, type, fl);
6346         if (error) {
6347                 locks_free_lock(fl);
6348 @@ -779,6 +800,7 @@ static int flock_lock_file(struct file *
6349                 lock_flocks();
6350         }
6351  
6352 +       new_fl->fl_xid = -1;
6353  find_conflict:
6354         for_each_lock(inode, before) {
6355                 struct file_lock *fl = *before;
6356 @@ -799,6 +821,7 @@ find_conflict:
6357                 goto out;
6358         locks_copy_lock(new_fl, request);
6359         locks_insert_lock(before, new_fl);
6360 +       vx_locks_inc(new_fl);
6361         new_fl = NULL;
6362         error = 0;
6363  
6364 @@ -809,7 +832,8 @@ out:
6365         return error;
6366  }
6367  
6368 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
6369 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
6370 +       struct file_lock *conflock, xid_t xid)
6371  {
6372         struct file_lock *fl;
6373         struct file_lock *new_fl = NULL;
6374 @@ -819,6 +843,8 @@ static int __posix_lock_file(struct inod
6375         struct file_lock **before;
6376         int error, added = 0;
6377  
6378 +       vxd_assert(xid == vx_current_xid(),
6379 +               "xid(%d) == current(%d)", xid, vx_current_xid());
6380         /*
6381          * We may need two file_lock structures for this operation,
6382          * so we get them in advance to avoid races.
6383 @@ -829,7 +855,11 @@ static int __posix_lock_file(struct inod
6384             (request->fl_type != F_UNLCK ||
6385              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
6386                 new_fl = locks_alloc_lock();
6387 +               new_fl->fl_xid = xid;
6388 +               vx_locks_inc(new_fl);
6389                 new_fl2 = locks_alloc_lock();
6390 +               new_fl2->fl_xid = xid;
6391 +               vx_locks_inc(new_fl2);
6392         }
6393  
6394         lock_flocks();
6395 @@ -1028,7 +1058,8 @@ static int __posix_lock_file(struct inod
6396  int posix_lock_file(struct file *filp, struct file_lock *fl,
6397                         struct file_lock *conflock)
6398  {
6399 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
6400 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
6401 +               fl, conflock, filp->f_xid);
6402  }
6403  EXPORT_SYMBOL(posix_lock_file);
6404  
6405 @@ -1118,7 +1149,7 @@ int locks_mandatory_area(int read_write,
6406         fl.fl_end = offset + count - 1;
6407  
6408         for (;;) {
6409 -               error = __posix_lock_file(inode, &fl, NULL);
6410 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
6411                 if (error != FILE_LOCK_DEFERRED)
6412                         break;
6413                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
6414 @@ -1431,6 +1462,7 @@ int generic_setlease(struct file *filp, 
6415                 goto out;
6416  
6417         locks_insert_lock(before, lease);
6418 +       vx_locks_inc(lease);
6419         return 0;
6420  
6421  out:
6422 @@ -1815,6 +1847,11 @@ int fcntl_setlk(unsigned int fd, struct 
6423         if (file_lock == NULL)
6424                 return -ENOLCK;
6425  
6426 +       vxd_assert(filp->f_xid == vx_current_xid(),
6427 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6428 +       file_lock->fl_xid = filp->f_xid;
6429 +       vx_locks_inc(file_lock);
6430 +
6431         /*
6432          * This might block, so we do it before checking the inode.
6433          */
6434 @@ -1933,6 +1970,11 @@ int fcntl_setlk64(unsigned int fd, struc
6435         if (file_lock == NULL)
6436                 return -ENOLCK;
6437  
6438 +       vxd_assert(filp->f_xid == vx_current_xid(),
6439 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6440 +       file_lock->fl_xid = filp->f_xid;
6441 +       vx_locks_inc(file_lock);
6442 +
6443         /*
6444          * This might block, so we do it before checking the inode.
6445          */
6446 @@ -2198,8 +2240,11 @@ static int locks_show(struct seq_file *f
6447  
6448         lock_get_status(f, fl, *((loff_t *)f->private), "");
6449  
6450 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
6451 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
6452 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
6453 +                       continue;
6454                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
6455 +       }
6456  
6457         return 0;
6458  }
6459 diff -NurpP --minimal linux-3.0.4/fs/namei.c linux-3.0.4-vs2.3.1-pre10.1/fs/namei.c
6460 --- linux-3.0.4/fs/namei.c      2011-07-22 11:18:05.000000000 +0200
6461 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/namei.c      2011-08-01 18:18:05.000000000 +0200
6462 @@ -32,6 +32,14 @@
6463  #include <linux/fcntl.h>
6464  #include <linux/device_cgroup.h>
6465  #include <linux/fs_struct.h>
6466 +#include <linux/proc_fs.h>
6467 +#include <linux/vserver/inode.h>
6468 +#include <linux/vs_base.h>
6469 +#include <linux/vs_tag.h>
6470 +#include <linux/vs_cowbl.h>
6471 +#include <linux/vs_device.h>
6472 +#include <linux/vs_context.h>
6473 +#include <linux/pid_namespace.h>
6474  #include <asm/uaccess.h>
6475  
6476  #include "internal.h"
6477 @@ -173,6 +181,84 @@ void putname(const char *name)
6478  EXPORT_SYMBOL(putname);
6479  #endif
6480  
6481 +static inline int dx_barrier(const struct inode *inode)
6482 +{
6483 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
6484 +               vxwprintk_task(1, "did hit the barrier.");
6485 +               return 1;
6486 +       }
6487 +       return 0;
6488 +}
6489 +
6490 +static int __dx_permission(const struct inode *inode, int mask)
6491 +{
6492 +       if (dx_barrier(inode))
6493 +               return -EACCES;
6494 +
6495 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
6496 +               /* devpts is xid tagged */
6497 +               if (S_ISDIR(inode->i_mode) ||
6498 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
6499 +                       return 0;
6500 +
6501 +               /* just pretend we didn't find anything */
6502 +               return -ENOENT;
6503 +       }
6504 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
6505 +               struct proc_dir_entry *de = PDE(inode);
6506 +
6507 +               if (de && !vx_hide_check(0, de->vx_flags))
6508 +                       goto out;
6509 +
6510 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
6511 +                       struct pid *pid;
6512 +                       struct task_struct *tsk;
6513 +
6514 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
6515 +                           vx_flags(VXF_STATE_SETUP, 0))
6516 +                               return 0;
6517 +
6518 +                       pid = PROC_I(inode)->pid;
6519 +                       if (!pid)
6520 +                               goto out;
6521 +
6522 +                       tsk = pid_task(pid, PIDTYPE_PID);
6523 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
6524 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
6525 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
6526 +                               return 0;
6527 +               }
6528 +               else {
6529 +                       /* FIXME: Should we block some entries here? */
6530 +                       return 0;
6531 +               }
6532 +       }
6533 +       else {
6534 +               if (dx_notagcheck(inode->i_sb) ||
6535 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
6536 +                            DX_IDENT))
6537 +                       return 0;
6538 +       }
6539 +
6540 +out:
6541 +       return -EACCES;
6542 +}
6543 +
6544 +int dx_permission(const struct inode *inode, int mask)
6545 +{
6546 +       int ret = __dx_permission(inode, mask);
6547 +       if (unlikely(ret)) {
6548 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
6549 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
6550 +#endif
6551 +                   vxwprintk_task(1,
6552 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
6553 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
6554 +                       inode->i_ino);
6555 +       }
6556 +       return ret;
6557 +}
6558 +
6559  /*
6560   * This does basic POSIX ACL permission checking
6561   */
6562 @@ -283,10 +369,14 @@ int inode_permission(struct inode *inode
6563                 /*
6564                  * Nobody gets write access to an immutable file.
6565                  */
6566 -               if (IS_IMMUTABLE(inode))
6567 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
6568                         return -EACCES;
6569         }
6570  
6571 +       retval = dx_permission(inode, mask);
6572 +       if (retval)
6573 +               return retval;
6574 +
6575         if (inode->i_op->permission)
6576                 retval = inode->i_op->permission(inode, mask, 0);
6577         else
6578 @@ -582,6 +672,9 @@ static inline int exec_permission(struct
6579         int ret;
6580         struct user_namespace *ns = inode_userns(inode);
6581  
6582 +       if (dx_barrier(inode))
6583 +               return -EACCES;
6584 +
6585         if (inode->i_op->permission) {
6586                 ret = inode->i_op->permission(inode, MAY_EXEC, flags);
6587         } else {
6588 @@ -1089,7 +1182,8 @@ static void follow_dotdot(struct nameida
6589  
6590                 if (nd->path.dentry == nd->root.dentry &&
6591                     nd->path.mnt == nd->root.mnt) {
6592 -                       break;
6593 +                       /* for sane '/' avoid follow_mount() */
6594 +                       return;
6595                 }
6596                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
6597                         /* rare case of legitimate dget_parent()... */
6598 @@ -1172,6 +1266,9 @@ static int do_lookup(struct nameidata *n
6599                                 goto unlazy;
6600                         }
6601                 }
6602 +
6603 +               /* FIXME: check dx permission */
6604 +
6605                 path->mnt = mnt;
6606                 path->dentry = dentry;
6607                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
6608 @@ -1220,6 +1317,8 @@ retry:
6609                 }
6610         }
6611  
6612 +       /* FIXME: check dx permission */
6613 +
6614         path->mnt = mnt;
6615         path->dentry = dentry;
6616         err = follow_managed(path, nd->flags);
6617 @@ -1839,7 +1938,7 @@ static int may_delete(struct inode *dir,
6618         if (IS_APPEND(dir))
6619                 return -EPERM;
6620         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
6621 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
6622 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
6623                 return -EPERM;
6624         if (isdir) {
6625                 if (!S_ISDIR(victim->d_inode->i_mode))
6626 @@ -1966,6 +2065,15 @@ static int may_open(struct path *path, i
6627                 break;
6628         }
6629  
6630 +#ifdef CONFIG_VSERVER_COWBL
6631 +       if (IS_COW(inode) &&
6632 +               ((flag & O_ACCMODE) != O_RDONLY)) {
6633 +               if (IS_COW_LINK(inode))
6634 +                       return -EMLINK;
6635 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
6636 +               mark_inode_dirty(inode);
6637 +       }
6638 +#endif
6639         error = inode_permission(inode, acc_mode);
6640         if (error)
6641                 return error;
6642 @@ -2859,7 +2967,7 @@ int vfs_link(struct dentry *old_dentry, 
6643         /*
6644          * A link to an append-only or immutable file cannot be created.
6645          */
6646 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
6647 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
6648                 return -EPERM;
6649         if (!dir->i_op->link)
6650                 return -EPERM;
6651 @@ -3245,6 +3353,222 @@ int vfs_follow_link(struct nameidata *nd
6652         return __vfs_follow_link(nd, link);
6653  }
6654  
6655 +
6656 +#ifdef CONFIG_VSERVER_COWBL
6657 +
6658 +#include <linux/file.h>
6659 +
6660 +static inline
6661 +long do_cow_splice(struct file *in, struct file *out, size_t len)
6662 +{
6663 +       loff_t ppos = 0;
6664 +
6665 +       return do_splice_direct(in, &ppos, out, len, 0);
6666 +}
6667 +
6668 +struct dentry *cow_break_link(const char *pathname)
6669 +{
6670 +       int ret, mode, pathlen, redo = 0;
6671 +       struct nameidata old_nd, dir_nd;
6672 +       struct path old_path, new_path;
6673 +       struct dentry *dir, *res = NULL;
6674 +       struct file *old_file;
6675 +       struct file *new_file;
6676 +       char *to, *path, pad='\251';
6677 +       loff_t size;
6678 +
6679 +       vxdprintk(VXD_CBIT(misc, 1),
6680 +               "cow_break_link(" VS_Q("%s") ")", pathname);
6681 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
6682 +       ret = -ENOMEM;
6683 +       if (!path)
6684 +               goto out;
6685 +
6686 +       /* old_nd will have refs to dentry and mnt */
6687 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
6688 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(old): %d", ret);
6689 +       if (ret < 0)
6690 +               goto out_free_path;
6691 +
6692 +       old_path = old_nd.path;
6693 +       mode = old_path.dentry->d_inode->i_mode;
6694 +
6695 +       to = d_path(&old_path, path, PATH_MAX-2);
6696 +       pathlen = strlen(to);
6697 +       vxdprintk(VXD_CBIT(misc, 2),
6698 +               "old path " VS_Q("%s") " [" VS_Q("%.*s") ":%d]", to,
6699 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
6700 +               old_path.dentry->d_name.len);
6701 +
6702 +       to[pathlen + 1] = 0;
6703 +retry:
6704 +       to[pathlen] = pad--;
6705 +       ret = -EMLINK;
6706 +       if (pad <= '\240')
6707 +               goto out_rel_old;
6708 +
6709 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
6710 +       /* dir_nd will have refs to dentry and mnt */
6711 +       ret = do_path_lookup(AT_FDCWD, to,
6712 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
6713 +       vxdprintk(VXD_CBIT(misc, 2),
6714 +               "do_path_lookup(new): %d", ret);
6715 +       if (ret < 0)
6716 +               goto retry;
6717 +
6718 +       /* this puppy downs the inode mutex */
6719 +       new_path.dentry = lookup_create(&dir_nd, 0);
6720 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
6721 +               vxdprintk(VXD_CBIT(misc, 2),
6722 +                       "lookup_create(new): %p", new_path.dentry);
6723 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
6724 +               path_put(&dir_nd.path);
6725 +               goto retry;
6726 +       }
6727 +       vxdprintk(VXD_CBIT(misc, 2),
6728 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
6729 +               new_path.dentry,
6730 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
6731 +               new_path.dentry->d_name.len);
6732 +       dir = dir_nd.path.dentry;
6733 +
6734 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
6735 +       vxdprintk(VXD_CBIT(misc, 2),
6736 +               "vfs_create(new): %d", ret);
6737 +       if (ret == -EEXIST) {
6738 +               mutex_unlock(&dir->d_inode->i_mutex);
6739 +               dput(new_path.dentry);
6740 +               path_put(&dir_nd.path);
6741 +               goto retry;
6742 +       }
6743 +       else if (ret < 0)
6744 +               goto out_unlock_new;
6745 +
6746 +       /* drop out early, ret passes ENOENT */
6747 +       ret = -ENOENT;
6748 +       if ((redo = d_unhashed(old_path.dentry)))
6749 +               goto out_unlock_new;
6750 +
6751 +       new_path.mnt = dir_nd.path.mnt;
6752 +       dget(old_path.dentry);
6753 +       mntget(old_path.mnt);
6754 +       /* this one cleans up the dentry/mnt in case of failure */
6755 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
6756 +               O_RDONLY, current_cred());
6757 +       vxdprintk(VXD_CBIT(misc, 2),
6758 +               "dentry_open(old): %p", old_file);
6759 +       if (!old_file || IS_ERR(old_file)) {
6760 +               res = IS_ERR(old_file) ? (void *) old_file : res;
6761 +               goto out_unlock_new;
6762 +       }
6763 +
6764 +       dget(new_path.dentry);
6765 +       mntget(new_path.mnt);
6766 +       /* this one cleans up the dentry/mnt in case of failure */
6767 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
6768 +               O_WRONLY, current_cred());
6769 +       vxdprintk(VXD_CBIT(misc, 2),
6770 +               "dentry_open(new): %p", new_file);
6771 +
6772 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
6773 +       if (!new_file || IS_ERR(new_file))
6774 +               goto out_fput_old;
6775 +
6776 +       size = i_size_read(old_file->f_dentry->d_inode);
6777 +       ret = do_cow_splice(old_file, new_file, size);
6778 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
6779 +       if (ret < 0) {
6780 +               goto out_fput_both;
6781 +       } else if (ret < size) {
6782 +               ret = -ENOSPC;
6783 +               goto out_fput_both;
6784 +       } else {
6785 +               struct inode *old_inode = old_path.dentry->d_inode;
6786 +               struct inode *new_inode = new_path.dentry->d_inode;
6787 +               struct iattr attr = {
6788 +                       .ia_uid = old_inode->i_uid,
6789 +                       .ia_gid = old_inode->i_gid,
6790 +                       .ia_valid = ATTR_UID | ATTR_GID
6791 +                       };
6792 +
6793 +               setattr_copy(new_inode, &attr);
6794 +               mark_inode_dirty(new_inode);
6795 +       }
6796 +
6797 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
6798 +
6799 +       /* drop out late */
6800 +       ret = -ENOENT;
6801 +       if ((redo = d_unhashed(old_path.dentry)))
6802 +               goto out_unlock;
6803 +
6804 +       vxdprintk(VXD_CBIT(misc, 2),
6805 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
6806 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
6807 +               new_path.dentry->d_name.len,
6808 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
6809 +               old_path.dentry->d_name.len);
6810 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
6811 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
6812 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
6813 +       res = new_path.dentry;
6814 +
6815 +out_unlock:
6816 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
6817 +
6818 +out_fput_both:
6819 +       vxdprintk(VXD_CBIT(misc, 3),
6820 +               "fput(new_file=%p[#%ld])", new_file,
6821 +               atomic_long_read(&new_file->f_count));
6822 +       fput(new_file);
6823 +
6824 +out_fput_old:
6825 +       vxdprintk(VXD_CBIT(misc, 3),
6826 +               "fput(old_file=%p[#%ld])", old_file,
6827 +               atomic_long_read(&old_file->f_count));
6828 +       fput(old_file);
6829 +
6830 +out_unlock_new:
6831 +       mutex_unlock(&dir->d_inode->i_mutex);
6832 +       if (!ret)
6833 +               goto out_redo;
6834 +
6835 +       /* error path cleanup */
6836 +       vfs_unlink(dir->d_inode, new_path.dentry);
6837 +       dput(new_path.dentry);
6838 +
6839 +out_redo:
6840 +       if (!redo)
6841 +               goto out_rel_both;
6842 +       /* lookup dentry once again */
6843 +       path_put(&old_nd.path);
6844 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
6845 +       if (ret)
6846 +               goto out_rel_both;
6847 +
6848 +       new_path.dentry = old_nd.path.dentry;
6849 +       vxdprintk(VXD_CBIT(misc, 2),
6850 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
6851 +               new_path.dentry,
6852 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
6853 +               new_path.dentry->d_name.len);
6854 +       dget(new_path.dentry);
6855 +       res = new_path.dentry;
6856 +
6857 +out_rel_both:
6858 +       path_put(&dir_nd.path);
6859 +out_rel_old:
6860 +       path_put(&old_nd.path);
6861 +out_free_path:
6862 +       kfree(path);
6863 +out:
6864 +       if (ret)
6865 +               res = ERR_PTR(ret);
6866 +       return res;
6867 +}
6868 +
6869 +#endif
6870 +
6871  /* get the link contents into pagecache */
6872  static char *page_getlink(struct dentry * dentry, struct page **ppage)
6873  {
6874 diff -NurpP --minimal linux-3.0.4/fs/namespace.c linux-3.0.4-vs2.3.1-pre10.1/fs/namespace.c
6875 --- linux-3.0.4/fs/namespace.c  2011-07-22 11:18:05.000000000 +0200
6876 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/namespace.c  2011-07-23 16:43:31.000000000 +0200
6877 @@ -31,6 +31,11 @@
6878  #include <linux/idr.h>
6879  #include <linux/fs_struct.h>
6880  #include <linux/fsnotify.h>
6881 +#include <linux/vs_base.h>
6882 +#include <linux/vs_context.h>
6883 +#include <linux/vs_tag.h>
6884 +#include <linux/vserver/space.h>
6885 +#include <linux/vserver/global.h>
6886  #include <asm/uaccess.h>
6887  #include <asm/unistd.h>
6888  #include "pnode.h"
6889 @@ -679,6 +684,10 @@ vfs_kern_mount(struct file_system_type *
6890         if (!type)
6891                 return ERR_PTR(-ENODEV);
6892  
6893 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
6894 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
6895 +               return ERR_PTR(-EPERM);
6896 +
6897         mnt = alloc_vfsmnt(name);
6898         if (!mnt)
6899                 return ERR_PTR(-ENOMEM);
6900 @@ -724,6 +733,7 @@ static struct vfsmount *clone_mnt(struct
6901                 mnt->mnt_root = dget(root);
6902                 mnt->mnt_mountpoint = mnt->mnt_root;
6903                 mnt->mnt_parent = mnt;
6904 +               mnt->mnt_tag = old->mnt_tag;
6905  
6906                 if (flag & CL_SLAVE) {
6907                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
6908 @@ -852,6 +862,31 @@ static inline void mangle(struct seq_fil
6909         seq_escape(m, s, " \t\n\\");
6910  }
6911  
6912 +static int mnt_is_reachable(struct vfsmount *mnt)
6913 +{
6914 +       struct path root;
6915 +       struct dentry *point;
6916 +       int ret;
6917 +
6918 +       if (mnt == mnt->mnt_ns->root)
6919 +               return 1;
6920 +
6921 +       br_read_lock(vfsmount_lock);
6922 +       root = current->fs->root;
6923 +       point = root.dentry;
6924 +
6925 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
6926 +               point = mnt->mnt_mountpoint;
6927 +               mnt = mnt->mnt_parent;
6928 +       }
6929 +
6930 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
6931 +
6932 +       br_read_unlock(vfsmount_lock);
6933 +
6934 +       return ret;
6935 +}
6936 +
6937  /*
6938   * Simple .show_options callback for filesystems which don't want to
6939   * implement more complex mount option showing.
6940 @@ -954,6 +989,8 @@ static int show_sb_opts(struct seq_file 
6941                 { MS_SYNCHRONOUS, ",sync" },
6942                 { MS_DIRSYNC, ",dirsync" },
6943                 { MS_MANDLOCK, ",mand" },
6944 +               { MS_TAGGED, ",tag" },
6945 +               { MS_NOTAGCHECK, ",notagcheck" },
6946                 { 0, NULL }
6947         };
6948         const struct proc_fs_info *fs_infop;
6949 @@ -1000,16 +1037,26 @@ static int show_vfsmnt(struct seq_file *
6950         int err = 0;
6951         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6952  
6953 -       if (mnt->mnt_sb->s_op->show_devname) {
6954 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6955 -               if (err)
6956 -                       goto out;
6957 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6958 +               return SEQ_SKIP;
6959 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6960 +               return SEQ_SKIP;
6961 +
6962 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6963 +               mnt == current->fs->root.mnt) {
6964 +               seq_puts(m, "/dev/root / ");
6965         } else {
6966 -               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6967 +               if (mnt->mnt_sb->s_op->show_devname) {
6968 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6969 +                       if (err)
6970 +                               goto out;
6971 +               } else {
6972 +                       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6973 +               }
6974 +               seq_putc(m, ' ');
6975 +               seq_path(m, &mnt_path, " \t\n\\");
6976 +               seq_putc(m, ' ');
6977         }
6978 -       seq_putc(m, ' ');
6979 -       seq_path(m, &mnt_path, " \t\n\\");
6980 -       seq_putc(m, ' ');
6981         show_type(m, mnt->mnt_sb);
6982         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6983         err = show_sb_opts(m, mnt->mnt_sb);
6984 @@ -1039,6 +1086,11 @@ static int show_mountinfo(struct seq_fil
6985         struct path root = p->root;
6986         int err = 0;
6987  
6988 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6989 +               return SEQ_SKIP;
6990 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6991 +               return SEQ_SKIP;
6992 +
6993         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
6994                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6995         if (sb->s_op->show_path)
6996 @@ -1107,21 +1159,31 @@ static int show_vfsstat(struct seq_file 
6997         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6998         int err = 0;
6999  
7000 -       /* device */
7001 -       if (mnt->mnt_sb->s_op->show_devname) {
7002 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
7003 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
7004 +               return SEQ_SKIP;
7005 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
7006 +               return SEQ_SKIP;
7007 +
7008 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
7009 +               mnt == current->fs->root.mnt) {
7010 +               seq_puts(m, "device /dev/root mounted on / ");
7011         } else {
7012 -               if (mnt->mnt_devname) {
7013 -                       seq_puts(m, "device ");
7014 -                       mangle(m, mnt->mnt_devname);
7015 -               } else
7016 -                       seq_puts(m, "no device");
7017 -       }
7018 +               /* device */
7019 +               if (mnt->mnt_sb->s_op->show_devname) {
7020 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
7021 +               } else {
7022 +                       if (mnt->mnt_devname) {
7023 +                               seq_puts(m, "device ");
7024 +                               mangle(m, mnt->mnt_devname);
7025 +                       } else
7026 +                               seq_puts(m, "no device");
7027 +               }
7028  
7029 -       /* mount point */
7030 -       seq_puts(m, " mounted on ");
7031 -       seq_path(m, &mnt_path, " \t\n\\");
7032 -       seq_putc(m, ' ');
7033 +               /* mount point */
7034 +               seq_puts(m, " mounted on ");
7035 +               seq_path(m, &mnt_path, " \t\n\\");
7036 +               seq_putc(m, ' ');
7037 +       }
7038  
7039         /* file system type */
7040         seq_puts(m, "with fstype ");
7041 @@ -1380,7 +1442,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
7042                 goto dput_and_out;
7043  
7044         retval = -EPERM;
7045 -       if (!capable(CAP_SYS_ADMIN))
7046 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7047                 goto dput_and_out;
7048  
7049         retval = do_umount(path.mnt, flags);
7050 @@ -1406,7 +1468,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
7051  
7052  static int mount_is_safe(struct path *path)
7053  {
7054 -       if (capable(CAP_SYS_ADMIN))
7055 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7056                 return 0;
7057         return -EPERM;
7058  #ifdef notyet
7059 @@ -1716,7 +1778,7 @@ static int do_change_type(struct path *p
7060         int type;
7061         int err = 0;
7062  
7063 -       if (!capable(CAP_SYS_ADMIN))
7064 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
7065                 return -EPERM;
7066  
7067         if (path->dentry != path->mnt->mnt_root)
7068 @@ -1732,6 +1794,7 @@ static int do_change_type(struct path *p
7069                 if (err)
7070                         goto out_unlock;
7071         }
7072 +       // mnt->mnt_flags = mnt_flags;
7073  
7074         br_write_lock(vfsmount_lock);
7075         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
7076 @@ -1747,12 +1810,14 @@ static int do_change_type(struct path *p
7077   * do loopback mount.
7078   */
7079  static int do_loopback(struct path *path, char *old_name,
7080 -                               int recurse)
7081 +       tag_t tag, unsigned long flags, int mnt_flags)
7082  {
7083         LIST_HEAD(umount_list);
7084         struct path old_path;
7085         struct vfsmount *mnt = NULL;
7086         int err = mount_is_safe(path);
7087 +       int recurse = flags & MS_REC;
7088 +
7089         if (err)
7090                 return err;
7091         if (!old_name || !*old_name)
7092 @@ -1818,12 +1883,12 @@ static int change_mount_flags(struct vfs
7093   * on it - tough luck.
7094   */
7095  static int do_remount(struct path *path, int flags, int mnt_flags,
7096 -                     void *data)
7097 +       void *data, xid_t xid)
7098  {
7099         int err;
7100         struct super_block *sb = path->mnt->mnt_sb;
7101  
7102 -       if (!capable(CAP_SYS_ADMIN))
7103 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
7104                 return -EPERM;
7105  
7106         if (!check_mnt(path->mnt))
7107 @@ -1871,7 +1936,7 @@ static int do_move_mount(struct path *pa
7108         struct path old_path, parent_path;
7109         struct vfsmount *p;
7110         int err = 0;
7111 -       if (!capable(CAP_SYS_ADMIN))
7112 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7113                 return -EPERM;
7114         if (!old_name || !*old_name)
7115                 return -EINVAL;
7116 @@ -2022,7 +2087,7 @@ static int do_new_mount(struct path *pat
7117                 return -EINVAL;
7118  
7119         /* we need capabilities... */
7120 -       if (!capable(CAP_SYS_ADMIN))
7121 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7122                 return -EPERM;
7123  
7124         mnt = do_kern_mount(type, flags, name, data);
7125 @@ -2291,6 +2356,7 @@ long do_mount(char *dev_name, char *dir_
7126         struct path path;
7127         int retval = 0;
7128         int mnt_flags = 0;
7129 +       tag_t tag = 0;
7130  
7131         /* Discard magic */
7132         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
7133 @@ -2318,6 +2384,12 @@ long do_mount(char *dev_name, char *dir_
7134         if (!(flags & MS_NOATIME))
7135                 mnt_flags |= MNT_RELATIME;
7136  
7137 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
7138 +               /* FIXME: bind and re-mounts get the tag flag? */
7139 +               if (flags & (MS_BIND|MS_REMOUNT))
7140 +                       flags |= MS_TAGID;
7141 +       }
7142 +
7143         /* Separate the per-mountpoint flags */
7144         if (flags & MS_NOSUID)
7145                 mnt_flags |= MNT_NOSUID;
7146 @@ -2334,15 +2406,17 @@ long do_mount(char *dev_name, char *dir_
7147         if (flags & MS_RDONLY)
7148                 mnt_flags |= MNT_READONLY;
7149  
7150 +       if (!capable(CAP_SYS_ADMIN))
7151 +               mnt_flags |= MNT_NODEV;
7152         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
7153                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
7154                    MS_STRICTATIME);
7155  
7156         if (flags & MS_REMOUNT)
7157                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
7158 -                                   data_page);
7159 +                                   data_page, tag);
7160         else if (flags & MS_BIND)
7161 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
7162 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
7163         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
7164                 retval = do_change_type(&path, flags);
7165         else if (flags & MS_MOVE)
7166 @@ -2442,6 +2516,7 @@ static struct mnt_namespace *dup_mnt_ns(
7167                 q = next_mnt(q, new_ns->root);
7168         }
7169         up_write(&namespace_sem);
7170 +       atomic_inc(&vs_global_mnt_ns);
7171  
7172         if (rootmnt)
7173                 mntput(rootmnt);
7174 @@ -2581,9 +2656,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
7175                 goto out3;
7176  
7177         error = -EINVAL;
7178 -       if (IS_MNT_SHARED(old.mnt) ||
7179 -               IS_MNT_SHARED(new.mnt->mnt_parent) ||
7180 -               IS_MNT_SHARED(root.mnt->mnt_parent))
7181 +       if ((IS_MNT_SHARED(old.mnt) ||
7182 +               IS_MNT_SHARED(new.mnt->mnt_parent) ||
7183 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
7184 +               !vx_flags(VXF_STATE_SETUP, 0))
7185                 goto out4;
7186         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
7187                 goto out4;
7188 @@ -2715,6 +2791,7 @@ void put_mnt_ns(struct mnt_namespace *ns
7189         br_write_unlock(vfsmount_lock);
7190         up_write(&namespace_sem);
7191         release_mounts(&umount_list);
7192 +       atomic_dec(&vs_global_mnt_ns);
7193         kfree(ns);
7194  }
7195  EXPORT_SYMBOL(put_mnt_ns);
7196 diff -NurpP --minimal linux-3.0.4/fs/nfs/client.c linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/client.c
7197 --- linux-3.0.4/fs/nfs/client.c 2011-07-22 11:18:05.000000000 +0200
7198 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/client.c 2011-06-10 22:11:24.000000000 +0200
7199 @@ -780,6 +780,9 @@ static int nfs_init_server_rpcclient(str
7200         if (server->flags & NFS_MOUNT_SOFT)
7201                 server->client->cl_softrtry = 1;
7202  
7203 +       server->client->cl_tag = 0;
7204 +       if (server->flags & NFS_MOUNT_TAGGED)
7205 +               server->client->cl_tag = 1;
7206         return 0;
7207  }
7208  
7209 @@ -951,6 +954,10 @@ static void nfs_server_set_fsinfo(struct
7210                 server->acdirmin = server->acdirmax = 0;
7211         }
7212  
7213 +       /* FIXME: needs fsinfo
7214 +       if (server->flags & NFS_MOUNT_TAGGED)
7215 +               sb->s_flags |= MS_TAGGED;       */
7216 +
7217         server->maxfilesize = fsinfo->maxfilesize;
7218  
7219         server->time_delta = fsinfo->time_delta;
7220 diff -NurpP --minimal linux-3.0.4/fs/nfs/dir.c linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/dir.c
7221 --- linux-3.0.4/fs/nfs/dir.c    2011-08-31 18:56:42.000000000 +0200
7222 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/dir.c    2011-08-08 23:04:47.000000000 +0200
7223 @@ -35,6 +35,7 @@
7224  #include <linux/sched.h>
7225  #include <linux/kmemleak.h>
7226  #include <linux/xattr.h>
7227 +#include <linux/vs_tag.h>
7228  
7229  #include "delegation.h"
7230  #include "iostat.h"
7231 @@ -1308,6 +1309,7 @@ static struct dentry *nfs_lookup(struct 
7232         if (IS_ERR(res))
7233                 goto out_unblock_sillyrename;
7234  
7235 +       dx_propagate_tag(nd, inode);
7236  no_entry:
7237         res = d_materialise_unique(dentry, inode);
7238         if (res != NULL) {
7239 diff -NurpP --minimal linux-3.0.4/fs/nfs/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/inode.c
7240 --- linux-3.0.4/fs/nfs/inode.c  2011-07-22 11:18:05.000000000 +0200
7241 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/inode.c  2011-07-01 11:35:34.000000000 +0200
7242 @@ -38,6 +38,7 @@
7243  #include <linux/nfs_xdr.h>
7244  #include <linux/slab.h>
7245  #include <linux/compat.h>
7246 +#include <linux/vs_tag.h>
7247  
7248  #include <asm/system.h>
7249  #include <asm/uaccess.h>
7250 @@ -273,6 +274,8 @@ nfs_fhget(struct super_block *sb, struct
7251         if (inode->i_state & I_NEW) {
7252                 struct nfs_inode *nfsi = NFS_I(inode);
7253                 unsigned long now = jiffies;
7254 +               uid_t uid;
7255 +               gid_t gid;
7256  
7257                 /* We set i_ino for the few things that still rely on it,
7258                  * such as stat(2) */
7259 @@ -321,8 +324,8 @@ nfs_fhget(struct super_block *sb, struct
7260                 nfsi->change_attr = 0;
7261                 inode->i_size = 0;
7262                 inode->i_nlink = 0;
7263 -               inode->i_uid = -2;
7264 -               inode->i_gid = -2;
7265 +               uid = -2;
7266 +               gid = -2;
7267                 inode->i_blocks = 0;
7268                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
7269  
7270 @@ -359,13 +362,13 @@ nfs_fhget(struct super_block *sb, struct
7271                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
7272                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
7273                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
7274 -                       inode->i_uid = fattr->uid;
7275 +                       uid = fattr->uid;
7276                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
7277                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
7278                                 | NFS_INO_INVALID_ACCESS
7279                                 | NFS_INO_INVALID_ACL;
7280                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
7281 -                       inode->i_gid = fattr->gid;
7282 +                       gid = fattr->gid;
7283                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
7284                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
7285                                 | NFS_INO_INVALID_ACCESS
7286 @@ -378,6 +381,11 @@ nfs_fhget(struct super_block *sb, struct
7287                          */
7288                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
7289                 }
7290 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7291 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7292 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7293 +                               /* maybe fattr->xid someday */
7294 +
7295                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
7296                 nfsi->attrtimeo_timestamp = now;
7297                 nfsi->access_cache = RB_ROOT;
7298 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
7299                         inode->i_uid = attr->ia_uid;
7300                 if ((attr->ia_valid & ATTR_GID) != 0)
7301                         inode->i_gid = attr->ia_gid;
7302 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
7303 +                       inode->i_tag = attr->ia_tag;
7304                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7305                 spin_unlock(&inode->i_lock);
7306         }
7307 @@ -941,6 +951,9 @@ static int nfs_check_inode_attributes(st
7308         struct nfs_inode *nfsi = NFS_I(inode);
7309         loff_t cur_size, new_isize;
7310         unsigned long invalid = 0;
7311 +       uid_t uid;
7312 +       gid_t gid;
7313 +       tag_t tag;
7314  
7315  
7316         /* Has the inode gone and changed behind our back? */
7317 @@ -964,13 +977,18 @@ static int nfs_check_inode_attributes(st
7318                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
7319         }
7320  
7321 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7322 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7323 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7324 +
7325         /* Have any file permissions changed? */
7326         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
7327                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7328 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
7329 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
7330                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7331 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
7332 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
7333                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7334 +               /* maybe check for tag too? */
7335  
7336         /* Has the link count changed? */
7337         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
7338 @@ -1205,6 +1223,9 @@ static int nfs_update_inode(struct inode
7339         unsigned long invalid = 0;
7340         unsigned long now = jiffies;
7341         unsigned long save_cache_validity;
7342 +       uid_t uid;
7343 +       gid_t gid;
7344 +       tag_t tag;
7345  
7346         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
7347                         __func__, inode->i_sb->s_id, inode->i_ino,
7348 @@ -1312,6 +1333,9 @@ static int nfs_update_inode(struct inode
7349                                 | NFS_INO_REVAL_PAGECACHE
7350                                 | NFS_INO_REVAL_FORCED);
7351  
7352 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7353 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7354 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7355  
7356         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
7357                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
7358 @@ -1333,9 +1357,9 @@ static int nfs_update_inode(struct inode
7359                                 | NFS_INO_REVAL_FORCED);
7360  
7361         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
7362 -               if (inode->i_uid != fattr->uid) {
7363 +               if (uid != fattr->uid) {
7364                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7365 -                       inode->i_uid = fattr->uid;
7366 +                       uid = fattr->uid;
7367                 }
7368         } else if (server->caps & NFS_CAP_OWNER)
7369                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
7370 @@ -1344,9 +1368,9 @@ static int nfs_update_inode(struct inode
7371                                 | NFS_INO_REVAL_FORCED);
7372  
7373         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
7374 -               if (inode->i_gid != fattr->gid) {
7375 +               if (gid != fattr->gid) {
7376                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7377 -                       inode->i_gid = fattr->gid;
7378 +                       gid = fattr->gid;
7379                 }
7380         } else if (server->caps & NFS_CAP_OWNER_GROUP)
7381                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
7382 @@ -1354,6 +1378,10 @@ static int nfs_update_inode(struct inode
7383                                 | NFS_INO_INVALID_ACL
7384                                 | NFS_INO_REVAL_FORCED);
7385  
7386 +       inode->i_uid = uid;
7387 +       inode->i_gid = gid;
7388 +       inode->i_tag = tag;
7389 +
7390         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
7391                 if (inode->i_nlink != fattr->nlink) {
7392                         invalid |= NFS_INO_INVALID_ATTR;
7393 diff -NurpP --minimal linux-3.0.4/fs/nfs/nfs3xdr.c linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/nfs3xdr.c
7394 --- linux-3.0.4/fs/nfs/nfs3xdr.c        2011-03-15 18:07:32.000000000 +0100
7395 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/nfs3xdr.c        2011-06-10 22:11:24.000000000 +0200
7396 @@ -20,6 +20,7 @@
7397  #include <linux/nfs3.h>
7398  #include <linux/nfs_fs.h>
7399  #include <linux/nfsacl.h>
7400 +#include <linux/vs_tag.h>
7401  #include "internal.h"
7402  
7403  #define NFSDBG_FACILITY                NFSDBG_XDR
7404 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
7405   *             set_mtime       mtime;
7406   *     };
7407   */
7408 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
7409 +static void encode_sattr3(struct xdr_stream *xdr,
7410 +       const struct iattr *attr, int tag)
7411  {
7412         u32 nbytes;
7413         __be32 *p;
7414 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
7415         } else
7416                 *p++ = xdr_zero;
7417  
7418 -       if (attr->ia_valid & ATTR_UID) {
7419 +       if (attr->ia_valid & ATTR_UID ||
7420 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7421                 *p++ = xdr_one;
7422 -               *p++ = cpu_to_be32(attr->ia_uid);
7423 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
7424 +                       attr->ia_uid, attr->ia_tag));
7425         } else
7426                 *p++ = xdr_zero;
7427  
7428 -       if (attr->ia_valid & ATTR_GID) {
7429 +       if (attr->ia_valid & ATTR_GID ||
7430 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7431                 *p++ = xdr_one;
7432 -               *p++ = cpu_to_be32(attr->ia_gid);
7433 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
7434 +                       attr->ia_gid, attr->ia_tag));
7435         } else
7436                 *p++ = xdr_zero;
7437  
7438 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
7439                                       const struct nfs3_sattrargs *args)
7440  {
7441         encode_nfs_fh3(xdr, args->fh);
7442 -       encode_sattr3(xdr, args->sattr);
7443 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
7444         encode_sattrguard3(xdr, args);
7445  }
7446  
7447 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
7448   *     };
7449   */
7450  static void encode_createhow3(struct xdr_stream *xdr,
7451 -                             const struct nfs3_createargs *args)
7452 +       const struct nfs3_createargs *args, int tag)
7453  {
7454         encode_uint32(xdr, args->createmode);
7455         switch (args->createmode) {
7456         case NFS3_CREATE_UNCHECKED:
7457         case NFS3_CREATE_GUARDED:
7458 -               encode_sattr3(xdr, args->sattr);
7459 +               encode_sattr3(xdr, args->sattr, tag);
7460                 break;
7461         case NFS3_CREATE_EXCLUSIVE:
7462                 encode_createverf3(xdr, args->verifier);
7463 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
7464                                      const struct nfs3_createargs *args)
7465  {
7466         encode_diropargs3(xdr, args->fh, args->name, args->len);
7467 -       encode_createhow3(xdr, args);
7468 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
7469  }
7470  
7471  /*
7472 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
7473                                     const struct nfs3_mkdirargs *args)
7474  {
7475         encode_diropargs3(xdr, args->fh, args->name, args->len);
7476 -       encode_sattr3(xdr, args->sattr);
7477 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
7478  }
7479  
7480  /*
7481 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
7482   *     };
7483   */
7484  static void encode_symlinkdata3(struct xdr_stream *xdr,
7485 -                               const struct nfs3_symlinkargs *args)
7486 +       const struct nfs3_symlinkargs *args, int tag)
7487  {
7488 -       encode_sattr3(xdr, args->sattr);
7489 +       encode_sattr3(xdr, args->sattr, tag);
7490         encode_nfspath3(xdr, args->pages, args->pathlen);
7491  }
7492  
7493 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
7494                                       const struct nfs3_symlinkargs *args)
7495  {
7496         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
7497 -       encode_symlinkdata3(xdr, args);
7498 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
7499  }
7500  
7501  /*
7502 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
7503   *     };
7504   */
7505  static void encode_devicedata3(struct xdr_stream *xdr,
7506 -                              const struct nfs3_mknodargs *args)
7507 +       const struct nfs3_mknodargs *args, int tag)
7508  {
7509 -       encode_sattr3(xdr, args->sattr);
7510 +       encode_sattr3(xdr, args->sattr, tag);
7511         encode_specdata3(xdr, args->rdev);
7512  }
7513  
7514  static void encode_mknoddata3(struct xdr_stream *xdr,
7515 -                             const struct nfs3_mknodargs *args)
7516 +       const struct nfs3_mknodargs *args, int tag)
7517  {
7518         encode_ftype3(xdr, args->type);
7519         switch (args->type) {
7520         case NF3CHR:
7521         case NF3BLK:
7522 -               encode_devicedata3(xdr, args);
7523 +               encode_devicedata3(xdr, args, tag);
7524                 break;
7525         case NF3SOCK:
7526         case NF3FIFO:
7527 -               encode_sattr3(xdr, args->sattr);
7528 +               encode_sattr3(xdr, args->sattr, tag);
7529                 break;
7530         case NF3REG:
7531         case NF3DIR:
7532 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
7533                                     const struct nfs3_mknodargs *args)
7534  {
7535         encode_diropargs3(xdr, args->fh, args->name, args->len);
7536 -       encode_mknoddata3(xdr, args);
7537 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
7538  }
7539  
7540  /*
7541 diff -NurpP --minimal linux-3.0.4/fs/nfs/super.c linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/super.c
7542 --- linux-3.0.4/fs/nfs/super.c  2011-07-22 11:18:05.000000000 +0200
7543 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/nfs/super.c  2011-06-10 22:11:24.000000000 +0200
7544 @@ -53,6 +53,7 @@
7545  #include <linux/nfs_xdr.h>
7546  #include <linux/magic.h>
7547  #include <linux/parser.h>
7548 +#include <linux/vs_tag.h>
7549  
7550  #include <asm/system.h>
7551  #include <asm/uaccess.h>
7552 @@ -87,6 +88,7 @@ enum {
7553         Opt_sharecache, Opt_nosharecache,
7554         Opt_resvport, Opt_noresvport,
7555         Opt_fscache, Opt_nofscache,
7556 +       Opt_tag, Opt_notag,
7557  
7558         /* Mount options that take integer arguments */
7559         Opt_port,
7560 @@ -100,6 +102,7 @@ enum {
7561         Opt_mountvers,
7562         Opt_nfsvers,
7563         Opt_minorversion,
7564 +       Opt_tagid,
7565  
7566         /* Mount options that take string arguments */
7567         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
7568 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
7569         { Opt_fscache_uniq, "fsc=%s" },
7570         { Opt_local_lock, "local_lock=%s" },
7571  
7572 +       { Opt_tag, "tag" },
7573 +       { Opt_notag, "notag" },
7574 +       { Opt_tagid, "tagid=%u" },
7575 +
7576         { Opt_err, NULL }
7577  };
7578  
7579 @@ -650,6 +657,7 @@ static void nfs_show_mount_options(struc
7580                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
7581                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
7582                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
7583 +               { NFS_MOUNT_TAGGED, ",tag", "" },
7584                 { 0, NULL, NULL }
7585         };
7586         const struct proc_nfs_info *nfs_infop;
7587 @@ -1198,6 +1206,14 @@ static int nfs_parse_mount_options(char 
7588                         kfree(mnt->fscache_uniq);
7589                         mnt->fscache_uniq = NULL;
7590                         break;
7591 +#ifndef CONFIG_TAGGING_NONE
7592 +               case Opt_tag:
7593 +                       mnt->flags |= NFS_MOUNT_TAGGED;
7594 +                       break;
7595 +               case Opt_notag:
7596 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
7597 +                       break;
7598 +#endif
7599  
7600                 /*
7601                  * options that take numeric values
7602 @@ -1304,6 +1320,12 @@ static int nfs_parse_mount_options(char 
7603                                 goto out_invalid_value;
7604                         mnt->minorversion = option;
7605                         break;
7606 +#ifdef CONFIG_PROPAGATE
7607 +               case Opt_tagid:
7608 +                       /* use args[0] */
7609 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
7610 +                       break;
7611 +#endif
7612  
7613                 /*
7614                  * options that take text values
7615 diff -NurpP --minimal linux-3.0.4/fs/nfsd/auth.c linux-3.0.4-vs2.3.1-pre10.1/fs/nfsd/auth.c
7616 --- linux-3.0.4/fs/nfsd/auth.c  2010-02-25 11:52:05.000000000 +0100
7617 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/nfsd/auth.c  2011-06-10 22:11:24.000000000 +0200
7618 @@ -1,6 +1,7 @@
7619  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
7620  
7621  #include <linux/sched.h>
7622 +#include <linux/vs_tag.h>
7623  #include "nfsd.h"
7624  #include "auth.h"
7625  
7626 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
7627  
7628         new->fsuid = rqstp->rq_cred.cr_uid;
7629         new->fsgid = rqstp->rq_cred.cr_gid;
7630 +       /* FIXME: this desperately needs a tag :)
7631 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
7632 +                       */
7633  
7634         rqgi = rqstp->rq_cred.cr_group_info;
7635  
7636 diff -NurpP --minimal linux-3.0.4/fs/nfsd/nfs3xdr.c linux-3.0.4-vs2.3.1-pre10.1/fs/nfsd/nfs3xdr.c
7637 --- linux-3.0.4/fs/nfsd/nfs3xdr.c       2011-07-22 11:18:05.000000000 +0200
7638 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/nfsd/nfs3xdr.c       2011-06-10 22:11:24.000000000 +0200
7639 @@ -7,6 +7,7 @@
7640   */
7641  
7642  #include <linux/namei.h>
7643 +#include <linux/vs_tag.h>
7644  #include "xdr3.h"
7645  #include "auth.h"
7646  
7647 @@ -95,6 +96,8 @@ static __be32 *
7648  decode_sattr3(__be32 *p, struct iattr *iap)
7649  {
7650         u32     tmp;
7651 +       uid_t   uid = 0;
7652 +       gid_t   gid = 0;
7653  
7654         iap->ia_valid = 0;
7655  
7656 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
7657         }
7658         if (*p++) {
7659                 iap->ia_valid |= ATTR_UID;
7660 -               iap->ia_uid = ntohl(*p++);
7661 +               uid = ntohl(*p++);
7662         }
7663         if (*p++) {
7664                 iap->ia_valid |= ATTR_GID;
7665 -               iap->ia_gid = ntohl(*p++);
7666 +               gid = ntohl(*p++);
7667         }
7668 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7669 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7670 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7671         if (*p++) {
7672                 u64     newsize;
7673  
7674 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
7675         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
7676         *p++ = htonl((u32) stat->mode);
7677         *p++ = htonl((u32) stat->nlink);
7678 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7679 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7680 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7681 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
7682 +               stat->uid, stat->tag)));
7683 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7684 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
7685 +               stat->gid, stat->tag)));
7686         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
7687                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
7688         } else {
7689 diff -NurpP --minimal linux-3.0.4/fs/nfsd/nfs4xdr.c linux-3.0.4-vs2.3.1-pre10.1/fs/nfsd/nfs4xdr.c
7690 --- linux-3.0.4/fs/nfsd/nfs4xdr.c       2011-07-22 11:18:05.000000000 +0200
7691 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/nfsd/nfs4xdr.c       2011-06-10 22:11:24.000000000 +0200
7692 @@ -45,6 +45,7 @@
7693  #include <linux/statfs.h>
7694  #include <linux/utsname.h>
7695  #include <linux/sunrpc/svcauth_gss.h>
7696 +#include <linux/vs_tag.h>
7697  
7698  #include "idmap.h"
7699  #include "acl.h"
7700 @@ -2090,14 +2091,18 @@ out_acl:
7701                 WRITE32(stat.nlink);
7702         }
7703         if (bmval1 & FATTR4_WORD1_OWNER) {
7704 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
7705 +               status = nfsd4_encode_user(rqstp,
7706 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
7707 +                       stat.uid, stat.tag), &p, &buflen);
7708                 if (status == nfserr_resource)
7709                         goto out_resource;
7710                 if (status)
7711                         goto out;
7712         }
7713         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
7714 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
7715 +               status = nfsd4_encode_group(rqstp,
7716 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
7717 +                       stat.gid, stat.tag), &p, &buflen);
7718                 if (status == nfserr_resource)
7719                         goto out_resource;
7720                 if (status)
7721 diff -NurpP --minimal linux-3.0.4/fs/nfsd/nfsxdr.c linux-3.0.4-vs2.3.1-pre10.1/fs/nfsd/nfsxdr.c
7722 --- linux-3.0.4/fs/nfsd/nfsxdr.c        2011-05-22 16:17:53.000000000 +0200
7723 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/nfsd/nfsxdr.c        2011-06-10 22:11:24.000000000 +0200
7724 @@ -6,6 +6,7 @@
7725  
7726  #include "xdr.h"
7727  #include "auth.h"
7728 +#include <linux/vs_tag.h>
7729  
7730  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7731  
7732 @@ -88,6 +89,8 @@ static __be32 *
7733  decode_sattr(__be32 *p, struct iattr *iap)
7734  {
7735         u32     tmp, tmp1;
7736 +       uid_t   uid = 0;
7737 +       gid_t   gid = 0;
7738  
7739         iap->ia_valid = 0;
7740  
7741 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
7742         }
7743         if ((tmp = ntohl(*p++)) != (u32)-1) {
7744                 iap->ia_valid |= ATTR_UID;
7745 -               iap->ia_uid = tmp;
7746 +               uid = tmp;
7747         }
7748         if ((tmp = ntohl(*p++)) != (u32)-1) {
7749                 iap->ia_valid |= ATTR_GID;
7750 -               iap->ia_gid = tmp;
7751 +               gid = tmp;
7752         }
7753 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7754 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7755 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7756         if ((tmp = ntohl(*p++)) != (u32)-1) {
7757                 iap->ia_valid |= ATTR_SIZE;
7758                 iap->ia_size = tmp;
7759 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
7760         *p++ = htonl(nfs_ftypes[type >> 12]);
7761         *p++ = htonl((u32) stat->mode);
7762         *p++ = htonl((u32) stat->nlink);
7763 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7764 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7765 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7766 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7767 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7768 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7769  
7770         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
7771                 *p++ = htonl(NFS_MAXPATHLEN);
7772 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/dlmglue.c linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/dlmglue.c
7773 --- linux-3.0.4/fs/ocfs2/dlmglue.c      2011-05-22 16:17:53.000000000 +0200
7774 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/dlmglue.c      2011-06-10 22:11:24.000000000 +0200
7775 @@ -2041,6 +2041,7 @@ static void __ocfs2_stuff_meta_lvb(struc
7776         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
7777         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
7778         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
7779 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
7780         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
7781         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
7782         lvb->lvb_iatime_packed  =
7783 @@ -2091,6 +2092,7 @@ static void ocfs2_refresh_inode_from_lvb
7784  
7785         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
7786         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
7787 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
7788         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
7789         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
7790         ocfs2_unpack_timespec(&inode->i_atime,
7791 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/dlmglue.h linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/dlmglue.h
7792 --- linux-3.0.4/fs/ocfs2/dlmglue.h      2010-10-21 13:07:50.000000000 +0200
7793 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/dlmglue.h      2011-06-10 22:11:24.000000000 +0200
7794 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
7795         __be16       lvb_inlink;
7796         __be32       lvb_iattr;
7797         __be32       lvb_igeneration;
7798 -       __be32       lvb_reserved2;
7799 +       __be16       lvb_itag;
7800 +       __be16       lvb_reserved2;
7801  };
7802  
7803  #define OCFS2_QINFO_LVB_VERSION 1
7804 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/file.c linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/file.c
7805 --- linux-3.0.4/fs/ocfs2/file.c 2011-07-22 11:18:06.000000000 +0200
7806 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/file.c 2011-06-10 22:43:33.000000000 +0200
7807 @@ -1111,7 +1111,7 @@ int ocfs2_setattr(struct dentry *dentry,
7808                 attr->ia_valid &= ~ATTR_SIZE;
7809  
7810  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
7811 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
7812 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
7813         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
7814                 return 0;
7815  
7816 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/inode.c
7817 --- linux-3.0.4/fs/ocfs2/inode.c        2011-05-22 16:17:53.000000000 +0200
7818 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/inode.c        2011-06-10 22:11:24.000000000 +0200
7819 @@ -28,6 +28,7 @@
7820  #include <linux/highmem.h>
7821  #include <linux/pagemap.h>
7822  #include <linux/quotaops.h>
7823 +#include <linux/vs_tag.h>
7824  
7825  #include <asm/byteorder.h>
7826  
7827 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
7828  {
7829         unsigned int flags = OCFS2_I(inode)->ip_attr;
7830  
7831 -       inode->i_flags &= ~(S_IMMUTABLE |
7832 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
7833                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
7834  
7835         if (flags & OCFS2_IMMUTABLE_FL)
7836                 inode->i_flags |= S_IMMUTABLE;
7837 +       if (flags & OCFS2_IXUNLINK_FL)
7838 +               inode->i_flags |= S_IXUNLINK;
7839  
7840         if (flags & OCFS2_SYNC_FL)
7841                 inode->i_flags |= S_SYNC;
7842 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
7843                 inode->i_flags |= S_NOATIME;
7844         if (flags & OCFS2_DIRSYNC_FL)
7845                 inode->i_flags |= S_DIRSYNC;
7846 +
7847 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
7848 +
7849 +       if (flags & OCFS2_BARRIER_FL)
7850 +               inode->i_vflags |= V_BARRIER;
7851 +       if (flags & OCFS2_COW_FL)
7852 +               inode->i_vflags |= V_COW;
7853  }
7854  
7855  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
7856  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
7857  {
7858         unsigned int flags = oi->vfs_inode.i_flags;
7859 +       unsigned int vflags = oi->vfs_inode.i_vflags;
7860 +
7861 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
7862 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
7863 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
7864 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
7865 +
7866 +       if (flags & S_IMMUTABLE)
7867 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
7868 +       if (flags & S_IXUNLINK)
7869 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
7870  
7871 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
7872 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
7873         if (flags & S_SYNC)
7874                 oi->ip_attr |= OCFS2_SYNC_FL;
7875         if (flags & S_APPEND)
7876                 oi->ip_attr |= OCFS2_APPEND_FL;
7877 -       if (flags & S_IMMUTABLE)
7878 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
7879         if (flags & S_NOATIME)
7880                 oi->ip_attr |= OCFS2_NOATIME_FL;
7881         if (flags & S_DIRSYNC)
7882                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
7883 +
7884 +       if (vflags & V_BARRIER)
7885 +               oi->ip_attr |= OCFS2_BARRIER_FL;
7886 +       if (vflags & V_COW)
7887 +               oi->ip_attr |= OCFS2_COW_FL;
7888  }
7889  
7890  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
7891 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
7892         struct super_block *sb;
7893         struct ocfs2_super *osb;
7894         int use_plocks = 1;
7895 +       uid_t uid;
7896 +       gid_t gid;
7897  
7898         sb = inode->i_sb;
7899         osb = OCFS2_SB(sb);
7900 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
7901         inode->i_generation = le32_to_cpu(fe->i_generation);
7902         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
7903         inode->i_mode = le16_to_cpu(fe->i_mode);
7904 -       inode->i_uid = le32_to_cpu(fe->i_uid);
7905 -       inode->i_gid = le32_to_cpu(fe->i_gid);
7906 +       uid = le32_to_cpu(fe->i_uid);
7907 +       gid = le32_to_cpu(fe->i_gid);
7908 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7909 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7910 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
7911 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
7912  
7913         /* Fast symlinks will have i_size but no allocated clusters. */
7914         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
7915 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/inode.h linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/inode.h
7916 --- linux-3.0.4/fs/ocfs2/inode.h        2011-01-05 21:50:26.000000000 +0100
7917 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/inode.h        2011-06-10 22:11:24.000000000 +0200
7918 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
7919  
7920  void ocfs2_set_inode_flags(struct inode *inode);
7921  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
7922 +int ocfs2_sync_flags(struct inode *inode, int, int);
7923  
7924  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
7925  {
7926 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/ioctl.c linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/ioctl.c
7927 --- linux-3.0.4/fs/ocfs2/ioctl.c        2011-07-22 11:18:06.000000000 +0200
7928 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/ioctl.c        2011-06-10 22:11:24.000000000 +0200
7929 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
7930         return status;
7931  }
7932  
7933 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7934 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
7935 +{
7936 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
7937 +       struct buffer_head *bh = NULL;
7938 +       handle_t *handle = NULL;
7939 +       int status;
7940 +
7941 +       status = ocfs2_inode_lock(inode, &bh, 1);
7942 +       if (status < 0) {
7943 +               mlog_errno(status);
7944 +               return status;
7945 +       }
7946 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
7947 +       if (IS_ERR(handle)) {
7948 +               status = PTR_ERR(handle);
7949 +               mlog_errno(status);
7950 +               goto bail_unlock;
7951 +       }
7952 +
7953 +       inode->i_flags = flags;
7954 +       inode->i_vflags = vflags;
7955 +       ocfs2_get_inode_flags(OCFS2_I(inode));
7956 +
7957 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
7958 +       if (status < 0)
7959 +               mlog_errno(status);
7960 +
7961 +       ocfs2_commit_trans(osb, handle);
7962 +bail_unlock:
7963 +       ocfs2_inode_unlock(inode, 1);
7964 +       brelse(bh);
7965 +       return status;
7966 +}
7967 +
7968 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7969                                 unsigned mask)
7970  {
7971         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
7972 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
7973         if (!S_ISDIR(inode->i_mode))
7974                 flags &= ~OCFS2_DIRSYNC_FL;
7975  
7976 +       if (IS_BARRIER(inode)) {
7977 +               vxwprintk_task(1, "messing with the barrier.");
7978 +               goto bail_unlock;
7979 +       }
7980 +
7981         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
7982         if (IS_ERR(handle)) {
7983                 status = PTR_ERR(handle);
7984 @@ -880,6 +919,7 @@ bail:
7985         return status;
7986  }
7987  
7988 +
7989  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7990  {
7991         struct inode *inode = filp->f_path.dentry->d_inode;
7992 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/namei.c linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/namei.c
7993 --- linux-3.0.4/fs/ocfs2/namei.c        2011-05-22 16:17:53.000000000 +0200
7994 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/namei.c        2011-06-10 22:11:24.000000000 +0200
7995 @@ -41,6 +41,7 @@
7996  #include <linux/slab.h>
7997  #include <linux/highmem.h>
7998  #include <linux/quotaops.h>
7999 +#include <linux/vs_tag.h>
8000  
8001  #include <cluster/masklog.h>
8002  
8003 @@ -477,6 +478,7 @@ static int __ocfs2_mknod_locked(struct i
8004         struct ocfs2_dinode *fe = NULL;
8005         struct ocfs2_extent_list *fel;
8006         u16 feat;
8007 +       tag_t tag;
8008  
8009         *new_fe_bh = NULL;
8010  
8011 @@ -514,8 +516,11 @@ static int __ocfs2_mknod_locked(struct i
8012         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
8013         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
8014         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
8015 -       fe->i_uid = cpu_to_le32(inode->i_uid);
8016 -       fe->i_gid = cpu_to_le32(inode->i_gid);
8017 +
8018 +       tag = dx_current_fstag(osb->sb);
8019 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
8020 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
8021 +       inode->i_tag = tag;
8022         fe->i_mode = cpu_to_le16(inode->i_mode);
8023         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
8024                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
8025 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/ocfs2.h linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/ocfs2.h
8026 --- linux-3.0.4/fs/ocfs2/ocfs2.h        2011-05-22 16:17:53.000000000 +0200
8027 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/ocfs2.h        2011-06-10 22:11:24.000000000 +0200
8028 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
8029                                                      writes */
8030         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
8031         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
8032 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
8033  };
8034  
8035  #define OCFS2_OSB_SOFT_RO                      0x0001
8036 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/ocfs2_fs.h linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/ocfs2_fs.h
8037 --- linux-3.0.4/fs/ocfs2/ocfs2_fs.h     2011-05-22 16:17:53.000000000 +0200
8038 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/ocfs2_fs.h     2011-06-10 22:11:24.000000000 +0200
8039 @@ -266,6 +266,11 @@
8040  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
8041  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
8042  
8043 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
8044 +
8045 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
8046 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
8047 +
8048  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
8049  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8050  
8051 diff -NurpP --minimal linux-3.0.4/fs/ocfs2/super.c linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/super.c
8052 --- linux-3.0.4/fs/ocfs2/super.c        2011-07-22 11:18:06.000000000 +0200
8053 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/ocfs2/super.c        2011-06-15 02:40:14.000000000 +0200
8054 @@ -184,6 +184,7 @@ enum {
8055         Opt_coherency_full,
8056         Opt_resv_level,
8057         Opt_dir_resv_level,
8058 +       Opt_tag, Opt_notag, Opt_tagid,
8059         Opt_err,
8060  };
8061  
8062 @@ -215,6 +216,9 @@ static const match_table_t tokens = {
8063         {Opt_coherency_full, "coherency=full"},
8064         {Opt_resv_level, "resv_level=%u"},
8065         {Opt_dir_resv_level, "dir_resv_level=%u"},
8066 +       {Opt_tag, "tag"},
8067 +       {Opt_notag, "notag"},
8068 +       {Opt_tagid, "tagid=%u"},
8069         {Opt_err, NULL}
8070  };
8071  
8072 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
8073                 goto out;
8074         }
8075  
8076 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
8077 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
8078 +               ret = -EINVAL;
8079 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
8080 +               goto out;
8081 +       }
8082 +
8083         /* We're going to/from readonly mode. */
8084         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
8085                 /* Disable quota accounting before remounting RO */
8086 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
8087  
8088         ocfs2_complete_mount_recovery(osb);
8089  
8090 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
8091 +               sb->s_flags |= MS_TAGGED;
8092 +
8093         if (ocfs2_mount_local(osb))
8094                 snprintf(nodestr, sizeof(nodestr), "local");
8095         else
8096 @@ -1506,6 +1520,20 @@ static int ocfs2_parse_options(struct su
8097                             option < OCFS2_MAX_RESV_LEVEL)
8098                                 mopt->dir_resv_level = option;
8099                         break;
8100 +#ifndef CONFIG_TAGGING_NONE
8101 +               case Opt_tag:
8102 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
8103 +                       break;
8104 +               case Opt_notag:
8105 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
8106 +                       break;
8107 +#endif
8108 +#ifdef CONFIG_PROPAGATE
8109 +               case Opt_tagid:
8110 +                       /* use args[0] */
8111 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
8112 +                       break;
8113 +#endif
8114                 default:
8115                         mlog(ML_ERROR,
8116                              "Unrecognized mount option \"%s\" "
8117 diff -NurpP --minimal linux-3.0.4/fs/open.c linux-3.0.4-vs2.3.1-pre10.1/fs/open.c
8118 --- linux-3.0.4/fs/open.c       2011-05-22 16:17:53.000000000 +0200
8119 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/open.c       2011-06-10 22:11:24.000000000 +0200
8120 @@ -30,6 +30,11 @@
8121  #include <linux/fs_struct.h>
8122  #include <linux/ima.h>
8123  #include <linux/dnotify.h>
8124 +#include <linux/vs_base.h>
8125 +#include <linux/vs_limit.h>
8126 +#include <linux/vs_tag.h>
8127 +#include <linux/vs_cowbl.h>
8128 +#include <linux/vserver/dlimit.h>
8129  
8130  #include "internal.h"
8131  
8132 @@ -494,6 +499,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
8133         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
8134         if (error)
8135                 goto out;
8136 +
8137 +#ifdef CONFIG_VSERVER_COWBL
8138 +       error = cow_check_and_break(&path);
8139 +       if (error)
8140 +               goto dput_and_out;
8141 +#endif
8142         inode = path.dentry->d_inode;
8143  
8144         error = mnt_want_write(path.mnt);
8145 @@ -531,11 +542,11 @@ static int chown_common(struct path *pat
8146         newattrs.ia_valid =  ATTR_CTIME;
8147         if (user != (uid_t) -1) {
8148                 newattrs.ia_valid |= ATTR_UID;
8149 -               newattrs.ia_uid = user;
8150 +               newattrs.ia_uid = dx_map_uid(user);
8151         }
8152         if (group != (gid_t) -1) {
8153                 newattrs.ia_valid |= ATTR_GID;
8154 -               newattrs.ia_gid = group;
8155 +               newattrs.ia_gid = dx_map_gid(group);
8156         }
8157         if (!S_ISDIR(inode->i_mode))
8158                 newattrs.ia_valid |=
8159 @@ -560,6 +571,10 @@ SYSCALL_DEFINE3(chown, const char __user
8160         error = mnt_want_write(path.mnt);
8161         if (error)
8162                 goto out_release;
8163 +#ifdef CONFIG_VSERVER_COWBL
8164 +       error = cow_check_and_break(&path);
8165 +       if (!error)
8166 +#endif
8167         error = chown_common(&path, user, group);
8168         mnt_drop_write(path.mnt);
8169  out_release:
8170 @@ -587,6 +602,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
8171         error = mnt_want_write(path.mnt);
8172         if (error)
8173                 goto out_release;
8174 +#ifdef CONFIG_VSERVER_COWBL
8175 +       error = cow_check_and_break(&path);
8176 +       if (!error)
8177 +#endif
8178         error = chown_common(&path, user, group);
8179         mnt_drop_write(path.mnt);
8180  out_release:
8181 @@ -606,6 +625,10 @@ SYSCALL_DEFINE3(lchown, const char __use
8182         error = mnt_want_write(path.mnt);
8183         if (error)
8184                 goto out_release;
8185 +#ifdef CONFIG_VSERVER_COWBL
8186 +       error = cow_check_and_break(&path);
8187 +       if (!error)
8188 +#endif
8189         error = chown_common(&path, user, group);
8190         mnt_drop_write(path.mnt);
8191  out_release:
8192 @@ -857,6 +880,7 @@ static void __put_unused_fd(struct files
8193         __FD_CLR(fd, fdt->open_fds);
8194         if (fd < files->next_fd)
8195                 files->next_fd = fd;
8196 +       vx_openfd_dec(fd);
8197  }
8198  
8199  void put_unused_fd(unsigned int fd)
8200 diff -NurpP --minimal linux-3.0.4/fs/proc/array.c linux-3.0.4-vs2.3.1-pre10.1/fs/proc/array.c
8201 --- linux-3.0.4/fs/proc/array.c 2011-07-22 11:18:06.000000000 +0200
8202 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/proc/array.c 2011-06-10 22:11:24.000000000 +0200
8203 @@ -81,6 +81,8 @@
8204  #include <linux/pid_namespace.h>
8205  #include <linux/ptrace.h>
8206  #include <linux/tracehook.h>
8207 +#include <linux/vs_context.h>
8208 +#include <linux/vs_network.h>
8209  
8210  #include <asm/pgtable.h>
8211  #include <asm/processor.h>
8212 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
8213         rcu_read_lock();
8214         ppid = pid_alive(p) ?
8215                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
8216 +       if (unlikely(vx_current_initpid(p->pid)))
8217 +               ppid = 0;
8218 +
8219         tpid = 0;
8220         if (pid_alive(p)) {
8221                 struct task_struct *tracer = tracehook_tracer_task(p);
8222 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
8223  }
8224  
8225  static void render_cap_t(struct seq_file *m, const char *header,
8226 -                       kernel_cap_t *a)
8227 +                       struct vx_info *vxi, kernel_cap_t *a)
8228  {
8229         unsigned __capi;
8230  
8231 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
8232         cap_bset        = cred->cap_bset;
8233         rcu_read_unlock();
8234  
8235 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
8236 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
8237 -       render_cap_t(m, "CapEff:\t", &cap_effective);
8238 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
8239 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
8240 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
8241 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
8242 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
8243 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
8244  }
8245  
8246  static inline void task_context_switch_counts(struct seq_file *m,
8247 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
8248         seq_putc(m, '\n');
8249  }
8250  
8251 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
8252 +                       struct pid *pid, struct task_struct *task)
8253 +{
8254 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
8255 +                       "Count:\t%u\n"
8256 +                       "uts:\t%p(%c)\n"
8257 +                       "ipc:\t%p(%c)\n"
8258 +                       "mnt:\t%p(%c)\n"
8259 +                       "pid:\t%p(%c)\n"
8260 +                       "net:\t%p(%c)\n",
8261 +                       task->nsproxy,
8262 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
8263 +                       atomic_read(&task->nsproxy->count),
8264 +                       task->nsproxy->uts_ns,
8265 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
8266 +                       task->nsproxy->ipc_ns,
8267 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
8268 +                       task->nsproxy->mnt_ns,
8269 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
8270 +                       task->nsproxy->pid_ns,
8271 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
8272 +                       task->nsproxy->net_ns,
8273 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
8274 +       return 0;
8275 +}
8276 +
8277 +void task_vs_id(struct seq_file *m, struct task_struct *task)
8278 +{
8279 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
8280 +               return;
8281 +
8282 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
8283 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
8284 +}
8285 +
8286 +
8287  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
8288                         struct pid *pid, struct task_struct *task)
8289  {
8290 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
8291         task_cap(m, task);
8292         task_cpus_allowed(m, task);
8293         cpuset_task_status_allowed(m, task);
8294 +       task_vs_id(m, task);
8295         task_context_switch_counts(m, task);
8296         return 0;
8297  }
8298 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
8299         /* convert nsec -> ticks */
8300         start_time = nsec_to_clock_t(start_time);
8301  
8302 +       /* fixup start time for virt uptime */
8303 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
8304 +               unsigned long long bias =
8305 +                       current->vx_info->cvirt.bias_clock;
8306 +
8307 +               if (start_time > bias)
8308 +                       start_time -= bias;
8309 +               else
8310 +                       start_time = 0;
8311 +       }
8312 +
8313         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
8314  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
8315  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
8316 diff -NurpP --minimal linux-3.0.4/fs/proc/base.c linux-3.0.4-vs2.3.1-pre10.1/fs/proc/base.c
8317 --- linux-3.0.4/fs/proc/base.c  2011-08-31 18:56:42.000000000 +0200
8318 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/proc/base.c  2011-08-08 23:04:47.000000000 +0200
8319 @@ -83,6 +83,8 @@
8320  #include <linux/pid_namespace.h>
8321  #include <linux/fs_struct.h>
8322  #include <linux/slab.h>
8323 +#include <linux/vs_context.h>
8324 +#include <linux/vs_network.h>
8325  #ifdef CONFIG_HARDWALL
8326  #include <asm/hardwall.h>
8327  #endif
8328 @@ -1102,11 +1104,16 @@ static ssize_t oom_adjust_write(struct f
8329                 goto err_task_lock;
8330         }
8331  
8332 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
8333 +       if (oom_adjust < task->signal->oom_adj &&
8334 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
8335                 err = -EACCES;
8336                 goto err_sighand;
8337         }
8338  
8339 +       /* prevent guest processes from circumventing the oom killer */
8340 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
8341 +               oom_adjust = OOM_ADJUST_MIN;
8342 +
8343         if (oom_adjust != task->signal->oom_adj) {
8344                 if (oom_adjust == OOM_DISABLE)
8345                         atomic_inc(&task->mm->oom_disable_count);
8346 @@ -1275,7 +1282,7 @@ static ssize_t proc_loginuid_write(struc
8347         ssize_t length;
8348         uid_t loginuid;
8349  
8350 -       if (!capable(CAP_AUDIT_CONTROL))
8351 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
8352                 return -EPERM;
8353  
8354         rcu_read_lock();
8355 @@ -1722,6 +1729,8 @@ struct inode *proc_pid_make_inode(struct
8356                 inode->i_gid = cred->egid;
8357                 rcu_read_unlock();
8358         }
8359 +       /* procfs is xid tagged */
8360 +       inode->i_tag = (tag_t)vx_task_xid(task);
8361         security_task_to_inode(task, inode);
8362  
8363  out:
8364 @@ -1758,6 +1767,8 @@ int pid_getattr(struct vfsmount *mnt, st
8365  
8366  /* dentry stuff */
8367  
8368 +static unsigned name_to_int(struct dentry *dentry);
8369 +
8370  /*
8371   *     Exceptional case: normally we are not allowed to unhash a busy
8372   * directory. In this case, however, we can do it - no aliasing problems
8373 @@ -1786,6 +1797,12 @@ int pid_revalidate(struct dentry *dentry
8374         task = get_proc_task(inode);
8375  
8376         if (task) {
8377 +               unsigned pid = name_to_int(dentry);
8378 +
8379 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
8380 +                       put_task_struct(task);
8381 +                       goto drop;
8382 +               }
8383                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
8384                     task_dumpable(task)) {
8385                         rcu_read_lock();
8386 @@ -1802,6 +1819,7 @@ int pid_revalidate(struct dentry *dentry
8387                 put_task_struct(task);
8388                 return 1;
8389         }
8390 +drop:
8391         d_drop(dentry);
8392         return 0;
8393  }
8394 @@ -2283,6 +2301,13 @@ static struct dentry *proc_pident_lookup
8395         if (!task)
8396                 goto out_no_task;
8397  
8398 +       /* TODO: maybe we can come up with a generic approach? */
8399 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
8400 +               (dentry->d_name.len == 5) &&
8401 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
8402 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
8403 +               goto out;
8404 +
8405         /*
8406          * Yes, it does not scale. And it should not. Don't add
8407          * new entries into /proc/<tgid>/ without very good reasons.
8408 @@ -2668,7 +2693,7 @@ out_iput:
8409  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
8410  {
8411         struct dentry *error;
8412 -       struct task_struct *task = get_proc_task(dir);
8413 +       struct task_struct *task = get_proc_task_real(dir);
8414         const struct pid_entry *p, *last;
8415  
8416         error = ERR_PTR(-ENOENT);
8417 @@ -2775,6 +2800,9 @@ static int proc_pid_personality(struct s
8418  static const struct file_operations proc_task_operations;
8419  static const struct inode_operations proc_task_inode_operations;
8420  
8421 +extern int proc_pid_vx_info(struct task_struct *, char *);
8422 +extern int proc_pid_nx_info(struct task_struct *, char *);
8423 +
8424  static const struct pid_entry tgid_base_stuff[] = {
8425         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
8426         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
8427 @@ -2838,6 +2866,8 @@ static const struct pid_entry tgid_base_
8428  #ifdef CONFIG_CGROUPS
8429         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
8430  #endif
8431 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
8432 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
8433         INF("oom_score",  S_IRUGO, proc_oom_score),
8434         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
8435         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
8436 @@ -2857,6 +2887,7 @@ static const struct pid_entry tgid_base_
8437  #ifdef CONFIG_HARDWALL
8438         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
8439  #endif
8440 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
8441  };
8442  
8443  static int proc_tgid_base_readdir(struct file * filp,
8444 @@ -3049,7 +3080,7 @@ retry:
8445         iter.task = NULL;
8446         pid = find_ge_pid(iter.tgid, ns);
8447         if (pid) {
8448 -               iter.tgid = pid_nr_ns(pid, ns);
8449 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
8450                 iter.task = pid_task(pid, PIDTYPE_PID);
8451                 /* What we to know is if the pid we have find is the
8452                  * pid of a thread_group_leader.  Testing for task
8453 @@ -3079,7 +3110,7 @@ static int proc_pid_fill_cache(struct fi
8454         struct tgid_iter iter)
8455  {
8456         char name[PROC_NUMBUF];
8457 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
8458 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
8459         return proc_fill_cache(filp, dirent, filldir, name, len,
8460                                 proc_pid_instantiate, iter.task, NULL);
8461  }
8462 @@ -3096,7 +3127,7 @@ int proc_pid_readdir(struct file * filp,
8463                 goto out_no_task;
8464         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
8465  
8466 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
8467 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
8468         if (!reaper)
8469                 goto out_no_task;
8470  
8471 @@ -3113,6 +3144,8 @@ int proc_pid_readdir(struct file * filp,
8472              iter.task;
8473              iter.tgid += 1, iter = next_tgid(ns, iter)) {
8474                 filp->f_pos = iter.tgid + TGID_OFFSET;
8475 +               if (!vx_proc_task_visible(iter.task))
8476 +                       continue;
8477                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
8478                         put_task_struct(iter.task);
8479                         goto out;
8480 @@ -3266,6 +3299,8 @@ static struct dentry *proc_task_lookup(s
8481         tid = name_to_int(dentry);
8482         if (tid == ~0U)
8483                 goto out;
8484 +       if (vx_current_initpid(tid))
8485 +               goto out;
8486  
8487         ns = dentry->d_sb->s_fs_info;
8488         rcu_read_lock();
8489 diff -NurpP --minimal linux-3.0.4/fs/proc/generic.c linux-3.0.4-vs2.3.1-pre10.1/fs/proc/generic.c
8490 --- linux-3.0.4/fs/proc/generic.c       2011-07-22 11:18:06.000000000 +0200
8491 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/proc/generic.c       2011-06-10 22:11:24.000000000 +0200
8492 @@ -22,6 +22,7 @@
8493  #include <linux/bitops.h>
8494  #include <linux/spinlock.h>
8495  #include <linux/completion.h>
8496 +#include <linux/vserver/inode.h>
8497  #include <asm/uaccess.h>
8498  
8499  #include "internal.h"
8500 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
8501         for (de = de->subdir; de ; de = de->next) {
8502                 if (de->namelen != dentry->d_name.len)
8503                         continue;
8504 +               if (!vx_hide_check(0, de->vx_flags))
8505 +                       continue;
8506                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
8507                         pde_get(de);
8508                         spin_unlock(&proc_subdir_lock);
8509                         error = -EINVAL;
8510                         inode = proc_get_inode(dir->i_sb, de);
8511 +                       /* generic proc entries belong to the host */
8512 +                       inode->i_tag = 0;
8513                         goto out_unlock;
8514                 }
8515         }
8516 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
8517  
8518                                 /* filldir passes info to user space */
8519                                 pde_get(de);
8520 +                               if (!vx_hide_check(0, de->vx_flags))
8521 +                                       goto skip;
8522                                 spin_unlock(&proc_subdir_lock);
8523                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
8524                                             de->low_ino, de->mode >> 12) < 0) {
8525 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
8526                                         goto out;
8527                                 }
8528                                 spin_lock(&proc_subdir_lock);
8529 +                       skip:
8530                                 filp->f_pos++;
8531                                 next = de->next;
8532                                 pde_put(de);
8533 @@ -627,6 +635,7 @@ static struct proc_dir_entry *__proc_cre
8534         ent->nlink = nlink;
8535         atomic_set(&ent->count, 1);
8536         ent->pde_users = 0;
8537 +       ent->vx_flags = IATTR_PROC_DEFAULT;
8538         spin_lock_init(&ent->pde_unload_lock);
8539         ent->pde_unload_completion = NULL;
8540         INIT_LIST_HEAD(&ent->pde_openers);
8541 @@ -650,7 +659,8 @@ struct proc_dir_entry *proc_symlink(cons
8542                                 kfree(ent->data);
8543                                 kfree(ent);
8544                                 ent = NULL;
8545 -                       }
8546 +                       } else
8547 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
8548                 } else {
8549                         kfree(ent);
8550                         ent = NULL;
8551 diff -NurpP --minimal linux-3.0.4/fs/proc/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/proc/inode.c
8552 --- linux-3.0.4/fs/proc/inode.c 2011-07-22 11:18:06.000000000 +0200
8553 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/proc/inode.c 2011-06-10 22:11:24.000000000 +0200
8554 @@ -442,6 +442,8 @@ struct inode *proc_get_inode(struct supe
8555                         inode->i_uid = de->uid;
8556                         inode->i_gid = de->gid;
8557                 }
8558 +               if (de->vx_flags)
8559 +                       PROC_I(inode)->vx_flags = de->vx_flags;
8560                 if (de->size)
8561                         inode->i_size = de->size;
8562                 if (de->nlink)
8563 diff -NurpP --minimal linux-3.0.4/fs/proc/internal.h linux-3.0.4-vs2.3.1-pre10.1/fs/proc/internal.h
8564 --- linux-3.0.4/fs/proc/internal.h      2011-07-22 11:18:06.000000000 +0200
8565 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/proc/internal.h      2011-06-10 22:11:24.000000000 +0200
8566 @@ -10,6 +10,7 @@
8567   */
8568  
8569  #include <linux/proc_fs.h>
8570 +#include <linux/vs_pid.h>
8571  
8572  extern struct proc_dir_entry proc_root;
8573  #ifdef CONFIG_PROC_SYSCTL
8574 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
8575                                 struct pid *pid, struct task_struct *task);
8576  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
8577                                 struct pid *pid, struct task_struct *task);
8578 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
8579 +                               struct pid *pid, struct task_struct *task);
8580 +
8581  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
8582  
8583  extern const struct file_operations proc_maps_operations;
8584 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
8585         return PROC_I(inode)->pid;
8586  }
8587  
8588 -static inline struct task_struct *get_proc_task(struct inode *inode)
8589 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
8590  {
8591         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
8592  }
8593  
8594 +static inline struct task_struct *get_proc_task(struct inode *inode)
8595 +{
8596 +       return vx_get_proc_task(inode, proc_pid(inode));
8597 +}
8598 +
8599  static inline int proc_fd(struct inode *inode)
8600  {
8601         return PROC_I(inode)->fd;
8602 diff -NurpP --minimal linux-3.0.4/fs/proc/loadavg.c linux-3.0.4-vs2.3.1-pre10.1/fs/proc/loadavg.c
8603 --- linux-3.0.4/fs/proc/loadavg.c       2009-09-10 15:26:23.000000000 +0200
8604 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/proc/loadavg.c       2011-06-10 22:11:24.000000000 +0200
8605 @@ -12,15 +12,27 @@
8606  
8607  static int loadavg_proc_show(struct seq_file *m, void *v)
8608  {
8609 +       unsigned long running;
8610 +       unsigned int threads;
8611         unsigned long avnrun[3];
8612  
8613         get_avenrun(avnrun, FIXED_1/200, 0);
8614  
8615 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
8616 +               struct vx_info *vxi = current_vx_info();
8617 +
8618 +               running = atomic_read(&vxi->cvirt.nr_running);
8619 +               threads = atomic_read(&vxi->cvirt.nr_threads);
8620 +       } else {
8621 +               running = nr_running();
8622 +               threads = nr_threads;
8623 +       }
8624 +
8625         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
8626                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
8627                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
8628                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
8629 -               nr_running(), nr_threads,
8630 +               running, threads,
8631                 task_active_pid_ns(current)->last_pid);
8632         return 0;
8633  }
8634 diff -NurpP --minimal linux-3.0.4/fs/proc/meminfo.c linux-3.0.4-vs2.3.1-pre10.1/fs/proc/meminfo.c
8635 --- linux-3.0.4/fs/proc/meminfo.c       2011-03-15 18:07:33.000000000 +0100
8636 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/proc/meminfo.c       2011-06-10 22:11:24.000000000 +0200
8637 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
8638         allowed = ((totalram_pages - hugetlb_total_pages())
8639                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
8640  
8641 -       cached = global_page_state(NR_FILE_PAGES) -
8642 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
8643 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
8644                         total_swapcache_pages - i.bufferram;
8645         if (cached < 0)
8646                 cached = 0;
8647 diff -NurpP --minimal linux-3.0.4/fs/proc/root.c linux-3.0.4-vs2.3.1-pre10.1/fs/proc/root.c
8648 --- linux-3.0.4/fs/proc/root.c  2011-07-22 11:18:06.000000000 +0200
8649 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/proc/root.c  2011-06-22 12:39:15.000000000 +0200
8650 @@ -18,9 +18,14 @@
8651  #include <linux/bitops.h>
8652  #include <linux/mount.h>
8653  #include <linux/pid_namespace.h>
8654 +#include <linux/vserver/inode.h>
8655  
8656  #include "internal.h"
8657  
8658 +struct proc_dir_entry *proc_virtual;
8659 +
8660 +extern void proc_vx_init(void);
8661 +
8662  static int proc_test_super(struct super_block *sb, void *data)
8663  {
8664         return sb->s_fs_info == data;
8665 @@ -125,6 +130,7 @@ void __init proc_root_init(void)
8666  #endif
8667         proc_mkdir("bus", NULL);
8668         proc_sys_init();
8669 +       proc_vx_init();
8670  }
8671  
8672  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
8673 @@ -193,6 +199,7 @@ struct proc_dir_entry proc_root = {
8674         .proc_iops      = &proc_root_inode_operations, 
8675         .proc_fops      = &proc_root_operations,
8676         .parent         = &proc_root,
8677 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
8678  };
8679  
8680  int pid_ns_prepare_proc(struct pid_namespace *ns)
8681 diff -NurpP --minimal linux-3.0.4/fs/proc/uptime.c linux-3.0.4-vs2.3.1-pre10.1/fs/proc/uptime.c
8682 --- linux-3.0.4/fs/proc/uptime.c        2009-12-03 20:02:53.000000000 +0100
8683 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/proc/uptime.c        2011-06-10 22:11:24.000000000 +0200
8684 @@ -4,22 +4,22 @@
8685  #include <linux/sched.h>
8686  #include <linux/seq_file.h>
8687  #include <linux/time.h>
8688 -#include <linux/kernel_stat.h>
8689 +#include <linux/vserver/cvirt.h>
8690  #include <asm/cputime.h>
8691  
8692  static int uptime_proc_show(struct seq_file *m, void *v)
8693  {
8694         struct timespec uptime;
8695         struct timespec idle;
8696 -       int i;
8697 -       cputime_t idletime = cputime_zero;
8698 -
8699 -       for_each_possible_cpu(i)
8700 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
8701 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
8702  
8703         do_posix_clock_monotonic_gettime(&uptime);
8704         monotonic_to_bootbased(&uptime);
8705         cputime_to_timespec(idletime, &idle);
8706 +
8707 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
8708 +               vx_vsi_uptime(&uptime, &idle);
8709 +
8710         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
8711                         (unsigned long) uptime.tv_sec,
8712                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
8713 diff -NurpP --minimal linux-3.0.4/fs/quota/dquot.c linux-3.0.4-vs2.3.1-pre10.1/fs/quota/dquot.c
8714 --- linux-3.0.4/fs/quota/dquot.c        2011-07-22 11:18:06.000000000 +0200
8715 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/quota/dquot.c        2011-06-10 22:11:24.000000000 +0200
8716 @@ -1548,6 +1548,9 @@ int __dquot_alloc_space(struct inode *in
8717         int reserve = flags & DQUOT_SPACE_RESERVE;
8718         int nofail = flags & DQUOT_SPACE_NOFAIL;
8719  
8720 +       if ((ret = dl_alloc_space(inode, number)))
8721 +               return ret;
8722 +
8723         /*
8724          * First test before acquiring mutex - solves deadlocks when we
8725          * re-enter the quota code and are already holding the mutex
8726 @@ -1602,6 +1605,9 @@ int dquot_alloc_inode(const struct inode
8727         int cnt, ret = 0;
8728         char warntype[MAXQUOTAS];
8729  
8730 +       if ((ret = dl_alloc_inode(inode)))
8731 +               return ret;
8732 +
8733         /* First test before acquiring mutex - solves deadlocks when we
8734           * re-enter the quota code and are already holding the mutex */
8735         if (!dquot_active(inode))
8736 @@ -1672,6 +1678,8 @@ void __dquot_free_space(struct inode *in
8737         char warntype[MAXQUOTAS];
8738         int reserve = flags & DQUOT_SPACE_RESERVE;
8739  
8740 +       dl_free_space(inode, number);
8741 +
8742         /* First test before acquiring mutex - solves deadlocks when we
8743           * re-enter the quota code and are already holding the mutex */
8744         if (!dquot_active(inode)) {
8745 @@ -1710,6 +1718,8 @@ void dquot_free_inode(const struct inode
8746         unsigned int cnt;
8747         char warntype[MAXQUOTAS];
8748  
8749 +       dl_free_inode(inode);
8750 +
8751         /* First test before acquiring mutex - solves deadlocks when we
8752           * re-enter the quota code and are already holding the mutex */
8753         if (!dquot_active(inode))
8754 diff -NurpP --minimal linux-3.0.4/fs/quota/quota.c linux-3.0.4-vs2.3.1-pre10.1/fs/quota/quota.c
8755 --- linux-3.0.4/fs/quota/quota.c        2011-03-15 18:07:34.000000000 +0100
8756 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/quota/quota.c        2011-06-13 18:19:47.000000000 +0200
8757 @@ -8,6 +8,7 @@
8758  #include <linux/fs.h>
8759  #include <linux/namei.h>
8760  #include <linux/slab.h>
8761 +#include <linux/vs_context.h>
8762  #include <asm/current.h>
8763  #include <asm/uaccess.h>
8764  #include <linux/kernel.h>
8765 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
8766                         break;
8767                 /*FALLTHROUGH*/
8768         default:
8769 -               if (!capable(CAP_SYS_ADMIN))
8770 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8771                         return -EPERM;
8772         }
8773  
8774 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
8775         }
8776  }
8777  
8778 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8779 +
8780 +#include <linux/vroot.h>
8781 +#include <linux/major.h>
8782 +#include <linux/module.h>
8783 +#include <linux/kallsyms.h>
8784 +#include <linux/vserver/debug.h>
8785 +
8786 +static vroot_grb_func *vroot_get_real_bdev = NULL;
8787 +
8788 +static DEFINE_SPINLOCK(vroot_grb_lock);
8789 +
8790 +int register_vroot_grb(vroot_grb_func *func) {
8791 +       int ret = -EBUSY;
8792 +
8793 +       spin_lock(&vroot_grb_lock);
8794 +       if (!vroot_get_real_bdev) {
8795 +               vroot_get_real_bdev = func;
8796 +               ret = 0;
8797 +       }
8798 +       spin_unlock(&vroot_grb_lock);
8799 +       return ret;
8800 +}
8801 +EXPORT_SYMBOL(register_vroot_grb);
8802 +
8803 +int unregister_vroot_grb(vroot_grb_func *func) {
8804 +       int ret = -EINVAL;
8805 +
8806 +       spin_lock(&vroot_grb_lock);
8807 +       if (vroot_get_real_bdev) {
8808 +               vroot_get_real_bdev = NULL;
8809 +               ret = 0;
8810 +       }
8811 +       spin_unlock(&vroot_grb_lock);
8812 +       return ret;
8813 +}
8814 +EXPORT_SYMBOL(unregister_vroot_grb);
8815 +
8816 +#endif
8817 +
8818  /*
8819   * look up a superblock on which quota ops will be performed
8820   * - use the name of a block device to find the superblock thereon
8821 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
8822         putname(tmp);
8823         if (IS_ERR(bdev))
8824                 return ERR_CAST(bdev);
8825 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8826 +       if (bdev && bdev->bd_inode &&
8827 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
8828 +               struct block_device *bdnew = (void *)-EINVAL;
8829 +
8830 +               if (vroot_get_real_bdev)
8831 +                       bdnew = vroot_get_real_bdev(bdev);
8832 +               else
8833 +                       vxdprintk(VXD_CBIT(misc, 0),
8834 +                                       "vroot_get_real_bdev not set");
8835 +               bdput(bdev);
8836 +               if (IS_ERR(bdnew))
8837 +                       return ERR_PTR(PTR_ERR(bdnew));
8838 +               bdev = bdnew;
8839 +       }
8840 +#endif
8841         sb = get_super(bdev);
8842         bdput(bdev);
8843         if (!sb)
8844 diff -NurpP --minimal linux-3.0.4/fs/reiserfs/file.c linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/file.c
8845 --- linux-3.0.4/fs/reiserfs/file.c      2011-01-05 21:50:26.000000000 +0100
8846 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/file.c      2011-06-10 22:11:24.000000000 +0200
8847 @@ -312,4 +312,5 @@ const struct inode_operations reiserfs_f
8848         .listxattr = reiserfs_listxattr,
8849         .removexattr = reiserfs_removexattr,
8850         .permission = reiserfs_permission,
8851 +       .sync_flags = reiserfs_sync_flags,
8852  };
8853 diff -NurpP --minimal linux-3.0.4/fs/reiserfs/inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/inode.c
8854 --- linux-3.0.4/fs/reiserfs/inode.c     2011-05-22 16:17:53.000000000 +0200
8855 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/inode.c     2011-06-10 22:11:24.000000000 +0200
8856 @@ -18,6 +18,7 @@
8857  #include <linux/writeback.h>
8858  #include <linux/quotaops.h>
8859  #include <linux/swap.h>
8860 +#include <linux/vs_tag.h>
8861  
8862  int reiserfs_commit_write(struct file *f, struct page *page,
8863                           unsigned from, unsigned to);
8864 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
8865         struct buffer_head *bh;
8866         struct item_head *ih;
8867         __u32 rdev;
8868 +       uid_t uid;
8869 +       gid_t gid;
8870         //int version = ITEM_VERSION_1;
8871  
8872         bh = PATH_PLAST_BUFFER(path);
8873 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
8874                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
8875                 unsigned long blocks;
8876  
8877 +               uid = sd_v1_uid(sd);
8878 +               gid = sd_v1_gid(sd);
8879 +
8880                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
8881                 set_inode_sd_version(inode, STAT_DATA_V1);
8882                 inode->i_mode = sd_v1_mode(sd);
8883                 inode->i_nlink = sd_v1_nlink(sd);
8884 -               inode->i_uid = sd_v1_uid(sd);
8885 -               inode->i_gid = sd_v1_gid(sd);
8886                 inode->i_size = sd_v1_size(sd);
8887                 inode->i_atime.tv_sec = sd_v1_atime(sd);
8888                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
8889 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
8890                 // (directories and symlinks)
8891                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
8892  
8893 +               uid    = sd_v2_uid(sd);
8894 +               gid    = sd_v2_gid(sd);
8895 +
8896                 inode->i_mode = sd_v2_mode(sd);
8897                 inode->i_nlink = sd_v2_nlink(sd);
8898 -               inode->i_uid = sd_v2_uid(sd);
8899                 inode->i_size = sd_v2_size(sd);
8900 -               inode->i_gid = sd_v2_gid(sd);
8901                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
8902                 inode->i_atime.tv_sec = sd_v2_atime(sd);
8903                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
8904 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
8905                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
8906         }
8907  
8908 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8909 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8910 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
8911 +
8912         pathrelse(path);
8913         if (S_ISREG(inode->i_mode)) {
8914                 inode->i_op = &reiserfs_file_inode_operations;
8915 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
8916  static void inode2sd(void *sd, struct inode *inode, loff_t size)
8917  {
8918         struct stat_data *sd_v2 = (struct stat_data *)sd;
8919 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
8920 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
8921         __u16 flags;
8922  
8923 +       set_sd_v2_uid(sd_v2, uid);
8924 +       set_sd_v2_gid(sd_v2, gid);
8925         set_sd_v2_mode(sd_v2, inode->i_mode);
8926         set_sd_v2_nlink(sd_v2, inode->i_nlink);
8927 -       set_sd_v2_uid(sd_v2, inode->i_uid);
8928         set_sd_v2_size(sd_v2, size);
8929 -       set_sd_v2_gid(sd_v2, inode->i_gid);
8930         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
8931         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
8932         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
8933 @@ -2863,14 +2874,19 @@ int reiserfs_commit_write(struct file *f
8934  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
8935  {
8936         if (reiserfs_attrs(inode->i_sb)) {
8937 -               if (sd_attrs & REISERFS_SYNC_FL)
8938 -                       inode->i_flags |= S_SYNC;
8939 -               else
8940 -                       inode->i_flags &= ~S_SYNC;
8941                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
8942                         inode->i_flags |= S_IMMUTABLE;
8943                 else
8944                         inode->i_flags &= ~S_IMMUTABLE;
8945 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
8946 +                       inode->i_flags |= S_IXUNLINK;
8947 +               else
8948 +                       inode->i_flags &= ~S_IXUNLINK;
8949 +
8950 +               if (sd_attrs & REISERFS_SYNC_FL)
8951 +                       inode->i_flags |= S_SYNC;
8952 +               else
8953 +                       inode->i_flags &= ~S_SYNC;
8954                 if (sd_attrs & REISERFS_APPEND_FL)
8955                         inode->i_flags |= S_APPEND;
8956                 else
8957 @@ -2883,6 +2899,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
8958                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
8959                 else
8960                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
8961 +
8962 +               if (sd_attrs & REISERFS_BARRIER_FL)
8963 +                       inode->i_vflags |= V_BARRIER;
8964 +               else
8965 +                       inode->i_vflags &= ~V_BARRIER;
8966 +               if (sd_attrs & REISERFS_COW_FL)
8967 +                       inode->i_vflags |= V_COW;
8968 +               else
8969 +                       inode->i_vflags &= ~V_COW;
8970         }
8971  }
8972  
8973 @@ -2893,6 +2918,11 @@ void i_attrs_to_sd_attrs(struct inode *i
8974                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
8975                 else
8976                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
8977 +               if (inode->i_flags & S_IXUNLINK)
8978 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
8979 +               else
8980 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
8981 +
8982                 if (inode->i_flags & S_SYNC)
8983                         *sd_attrs |= REISERFS_SYNC_FL;
8984                 else
8985 @@ -2905,6 +2935,15 @@ void i_attrs_to_sd_attrs(struct inode *i
8986                         *sd_attrs |= REISERFS_NOTAIL_FL;
8987                 else
8988                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
8989 +
8990 +               if (inode->i_vflags & V_BARRIER)
8991 +                       *sd_attrs |= REISERFS_BARRIER_FL;
8992 +               else
8993 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
8994 +               if (inode->i_vflags & V_COW)
8995 +                       *sd_attrs |= REISERFS_COW_FL;
8996 +               else
8997 +                       *sd_attrs &= ~REISERFS_COW_FL;
8998         }
8999  }
9000  
9001 @@ -3148,7 +3187,8 @@ int reiserfs_setattr(struct dentry *dent
9002         }
9003  
9004         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
9005 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
9006 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
9007 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
9008                 struct reiserfs_transaction_handle th;
9009                 int jbegin_count =
9010                     2 *
9011 @@ -3177,6 +3217,9 @@ int reiserfs_setattr(struct dentry *dent
9012                         inode->i_uid = attr->ia_uid;
9013                 if (attr->ia_valid & ATTR_GID)
9014                         inode->i_gid = attr->ia_gid;
9015 +                               if ((attr->ia_valid & ATTR_TAG) &&
9016 +                                       IS_TAGGED(inode))
9017 +                                       inode->i_tag = attr->ia_tag;
9018                 mark_inode_dirty(inode);
9019                 error = journal_end(&th, inode->i_sb, jbegin_count);
9020                 if (error)
9021 diff -NurpP --minimal linux-3.0.4/fs/reiserfs/ioctl.c linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/ioctl.c
9022 --- linux-3.0.4/fs/reiserfs/ioctl.c     2011-05-22 16:17:53.000000000 +0200
9023 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/ioctl.c     2011-06-10 22:11:24.000000000 +0200
9024 @@ -11,6 +11,21 @@
9025  #include <linux/pagemap.h>
9026  #include <linux/compat.h>
9027  
9028 +
9029 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
9030 +{
9031 +       __u16 sd_attrs = 0;
9032 +
9033 +       inode->i_flags = flags;
9034 +       inode->i_vflags = vflags;
9035 +
9036 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
9037 +       REISERFS_I(inode)->i_attrs = sd_attrs;
9038 +       inode->i_ctime = CURRENT_TIME_SEC;
9039 +       mark_inode_dirty(inode);
9040 +       return 0;
9041 +}
9042 +
9043  /*
9044   * reiserfs_ioctl - handler for ioctl for inode
9045   * supported commands:
9046 @@ -22,7 +37,7 @@
9047  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
9048  {
9049         struct inode *inode = filp->f_path.dentry->d_inode;
9050 -       unsigned int flags;
9051 +       unsigned int flags, oldflags;
9052         int err = 0;
9053  
9054         reiserfs_write_lock(inode->i_sb);
9055 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
9056  
9057                 flags = REISERFS_I(inode)->i_attrs;
9058                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
9059 +               flags &= REISERFS_FL_USER_VISIBLE;
9060                 err = put_user(flags, (int __user *)arg);
9061                 break;
9062         case REISERFS_IOC_SETFLAGS:{
9063 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
9064                                 err = -EFAULT;
9065                                 goto setflags_out;
9066                         }
9067 +                       if (IS_BARRIER(inode)) {
9068 +                               vxwprintk_task(1, "messing with the barrier.");
9069 +                               return -EACCES;
9070 +                       }
9071                         /*
9072                          * Is it quota file? Do not allow user to mess with it
9073                          */
9074 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
9075                                         goto setflags_out;
9076                                 }
9077                         }
9078 +
9079 +                       oldflags = REISERFS_I(inode)->i_attrs;
9080 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
9081 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
9082                         sd_attrs_to_i_attrs(flags, inode);
9083                         REISERFS_I(inode)->i_attrs = flags;
9084                         inode->i_ctime = CURRENT_TIME_SEC;
9085 diff -NurpP --minimal linux-3.0.4/fs/reiserfs/namei.c linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/namei.c
9086 --- linux-3.0.4/fs/reiserfs/namei.c     2011-05-22 16:17:53.000000000 +0200
9087 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/namei.c     2011-06-10 22:11:24.000000000 +0200
9088 @@ -18,6 +18,7 @@
9089  #include <linux/reiserfs_acl.h>
9090  #include <linux/reiserfs_xattr.h>
9091  #include <linux/quotaops.h>
9092 +#include <linux/vs_tag.h>
9093  
9094  #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; }
9095  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
9096 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
9097         if (retval == IO_ERROR) {
9098                 return ERR_PTR(-EIO);
9099         }
9100 +               dx_propagate_tag(nd, inode);
9101  
9102         return d_splice_alias(inode, dentry);
9103  }
9104 @@ -1529,6 +1531,7 @@ const struct inode_operations reiserfs_d
9105         .listxattr = reiserfs_listxattr,
9106         .removexattr = reiserfs_removexattr,
9107         .permission = reiserfs_permission,
9108 +       .sync_flags = reiserfs_sync_flags,
9109  };
9110  
9111  /*
9112 diff -NurpP --minimal linux-3.0.4/fs/reiserfs/super.c linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/super.c
9113 --- linux-3.0.4/fs/reiserfs/super.c     2011-07-22 11:18:06.000000000 +0200
9114 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/super.c     2011-06-10 22:11:24.000000000 +0200
9115 @@ -899,6 +899,14 @@ static int reiserfs_parse_options(struct
9116                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
9117                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
9118  #endif
9119 +#ifndef CONFIG_TAGGING_NONE
9120 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
9121 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
9122 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
9123 +#endif
9124 +#ifdef CONFIG_PROPAGATE
9125 +               {"tag",.arg_required = 'T',.values = NULL},
9126 +#endif
9127  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
9128                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
9129                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
9130 @@ -1208,6 +1216,14 @@ static int reiserfs_remount(struct super
9131         handle_quota_files(s, qf_names, &qfmt);
9132  #endif
9133  
9134 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
9135 +               !(s->s_flags & MS_TAGGED)) {
9136 +               reiserfs_warning(s, "super-vs01",
9137 +                       "reiserfs: tagging not permitted on remount.");
9138 +               err = -EINVAL;
9139 +               goto out_err;
9140 +       }
9141 +
9142         handle_attrs(s);
9143  
9144         /* Add options that are safe here */
9145 @@ -1690,6 +1706,10 @@ static int reiserfs_fill_super(struct su
9146                 goto error;
9147         }
9148  
9149 +       /* map mount option tagxid */
9150 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
9151 +               s->s_flags |= MS_TAGGED;
9152 +
9153         rs = SB_DISK_SUPER_BLOCK(s);
9154         /* Let's do basic sanity check to verify that underlying device is not
9155            smaller than the filesystem. If the check fails then abort and scream,
9156 diff -NurpP --minimal linux-3.0.4/fs/reiserfs/xattr.c linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/xattr.c
9157 --- linux-3.0.4/fs/reiserfs/xattr.c     2011-07-22 11:18:06.000000000 +0200
9158 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/reiserfs/xattr.c     2011-06-22 12:39:15.000000000 +0200
9159 @@ -40,6 +40,7 @@
9160  #include <linux/errno.h>
9161  #include <linux/gfp.h>
9162  #include <linux/fs.h>
9163 +#include <linux/mount.h>
9164  #include <linux/file.h>
9165  #include <linux/pagemap.h>
9166  #include <linux/xattr.h>
9167 diff -NurpP --minimal linux-3.0.4/fs/stat.c linux-3.0.4-vs2.3.1-pre10.1/fs/stat.c
9168 --- linux-3.0.4/fs/stat.c       2011-05-22 16:17:54.000000000 +0200
9169 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/stat.c       2011-06-10 22:11:24.000000000 +0200
9170 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
9171         stat->nlink = inode->i_nlink;
9172         stat->uid = inode->i_uid;
9173         stat->gid = inode->i_gid;
9174 +       stat->tag = inode->i_tag;
9175         stat->rdev = inode->i_rdev;
9176         stat->atime = inode->i_atime;
9177         stat->mtime = inode->i_mtime;
9178 diff -NurpP --minimal linux-3.0.4/fs/statfs.c linux-3.0.4-vs2.3.1-pre10.1/fs/statfs.c
9179 --- linux-3.0.4/fs/statfs.c     2011-05-22 16:17:54.000000000 +0200
9180 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/statfs.c     2011-06-10 22:11:24.000000000 +0200
9181 @@ -7,6 +7,8 @@
9182  #include <linux/statfs.h>
9183  #include <linux/security.h>
9184  #include <linux/uaccess.h>
9185 +#include <linux/vs_base.h>
9186 +#include <linux/vs_dlimit.h>
9187  
9188  static int flags_by_mnt(int mnt_flags)
9189  {
9190 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
9191         retval = dentry->d_sb->s_op->statfs(dentry, buf);
9192         if (retval == 0 && buf->f_frsize == 0)
9193                 buf->f_frsize = buf->f_bsize;
9194 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
9195 +               vx_vsi_statfs(dentry->d_sb, buf);
9196         return retval;
9197  }
9198  
9199 diff -NurpP --minimal linux-3.0.4/fs/super.c linux-3.0.4-vs2.3.1-pre10.1/fs/super.c
9200 --- linux-3.0.4/fs/super.c      2011-07-22 11:18:06.000000000 +0200
9201 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/super.c      2011-07-23 16:49:09.000000000 +0200
9202 @@ -32,6 +32,9 @@
9203  #include <linux/backing-dev.h>
9204  #include <linux/rculist_bl.h>
9205  #include <linux/cleancache.h>
9206 +#include <linux/devpts_fs.h>
9207 +#include <linux/proc_fs.h>
9208 +#include <linux/vs_context.h>
9209  #include "internal.h"
9210  
9211  
9212 @@ -943,6 +946,13 @@ mount_fs(struct file_system_type *type, 
9213         WARN_ON(sb->s_bdi == &default_backing_dev_info);
9214         sb->s_flags |= MS_BORN;
9215  
9216 +       error = -EPERM;
9217 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
9218 +               !sb->s_bdev &&
9219 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
9220 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
9221 +               goto out_sb;
9222 +
9223         error = security_sb_kern_mount(sb, flags, secdata);
9224         if (error)
9225                 goto out_sb;
9226 diff -NurpP --minimal linux-3.0.4/fs/sysfs/mount.c linux-3.0.4-vs2.3.1-pre10.1/fs/sysfs/mount.c
9227 --- linux-3.0.4/fs/sysfs/mount.c        2011-07-22 11:18:06.000000000 +0200
9228 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/sysfs/mount.c        2011-06-22 12:39:15.000000000 +0200
9229 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
9230  
9231         sb->s_blocksize = PAGE_CACHE_SIZE;
9232         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
9233 -       sb->s_magic = SYSFS_MAGIC;
9234 +       sb->s_magic = SYSFS_SUPER_MAGIC;
9235         sb->s_op = &sysfs_ops;
9236         sb->s_time_gran = 1;
9237  
9238 diff -NurpP --minimal linux-3.0.4/fs/utimes.c linux-3.0.4-vs2.3.1-pre10.1/fs/utimes.c
9239 --- linux-3.0.4/fs/utimes.c     2011-05-22 16:17:54.000000000 +0200
9240 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/utimes.c     2011-06-10 22:11:24.000000000 +0200
9241 @@ -8,6 +8,8 @@
9242  #include <linux/stat.h>
9243  #include <linux/utime.h>
9244  #include <linux/syscalls.h>
9245 +#include <linux/mount.h>
9246 +#include <linux/vs_cowbl.h>
9247  #include <asm/uaccess.h>
9248  #include <asm/unistd.h>
9249  
9250 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
9251  {
9252         int error;
9253         struct iattr newattrs;
9254 -       struct inode *inode = path->dentry->d_inode;
9255 +       struct inode *inode;
9256  
9257         error = mnt_want_write(path->mnt);
9258         if (error)
9259                 goto out;
9260  
9261 +       error = cow_check_and_break(path);
9262 +       if (error)
9263 +               goto mnt_drop_write_and_out;
9264 +
9265 +       inode = path->dentry->d_inode;
9266 +
9267         if (times && times[0].tv_nsec == UTIME_NOW &&
9268                      times[1].tv_nsec == UTIME_NOW)
9269                 times = NULL;
9270 diff -NurpP --minimal linux-3.0.4/fs/xattr.c linux-3.0.4-vs2.3.1-pre10.1/fs/xattr.c
9271 --- linux-3.0.4/fs/xattr.c      2011-07-22 11:18:09.000000000 +0200
9272 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xattr.c      2011-06-10 23:10:19.000000000 +0200
9273 @@ -18,6 +18,7 @@
9274  #include <linux/module.h>
9275  #include <linux/fsnotify.h>
9276  #include <linux/audit.h>
9277 +#include <linux/mount.h>
9278  #include <asm/uaccess.h>
9279  
9280  
9281 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
9282          * The trusted.* namespace can only be accessed by privileged users.
9283          */
9284         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
9285 -               if (!capable(CAP_SYS_ADMIN))
9286 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
9287                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
9288                 return 0;
9289         }
9290 diff -NurpP --minimal linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_ioctl.c
9291 --- linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.c    2011-05-22 16:17:54.000000000 +0200
9292 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_ioctl.c    2011-06-10 22:11:24.000000000 +0200
9293 @@ -28,7 +28,7 @@
9294  #include "xfs_bmap_btree.h"
9295  #include "xfs_dinode.h"
9296  #include "xfs_inode.h"
9297 -#include "xfs_ioctl.h"
9298 +// #include "xfs_ioctl.h"
9299  #include "xfs_rtalloc.h"
9300  #include "xfs_itable.h"
9301  #include "xfs_error.h"
9302 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
9303                 xflags |= XFS_XFLAG_IMMUTABLE;
9304         else
9305                 xflags &= ~XFS_XFLAG_IMMUTABLE;
9306 +       if (flags & FS_IXUNLINK_FL)
9307 +               xflags |= XFS_XFLAG_IXUNLINK;
9308 +       else
9309 +               xflags &= ~XFS_XFLAG_IXUNLINK;
9310         if (flags & FS_APPEND_FL)
9311                 xflags |= XFS_XFLAG_APPEND;
9312         else
9313 @@ -776,6 +780,8 @@ xfs_di2lxflags(
9314  
9315         if (di_flags & XFS_DIFLAG_IMMUTABLE)
9316                 flags |= FS_IMMUTABLE_FL;
9317 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
9318 +               flags |= FS_IXUNLINK_FL;
9319         if (di_flags & XFS_DIFLAG_APPEND)
9320                 flags |= FS_APPEND_FL;
9321         if (di_flags & XFS_DIFLAG_SYNC)
9322 @@ -836,6 +842,8 @@ xfs_set_diflags(
9323         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
9324         if (xflags & XFS_XFLAG_IMMUTABLE)
9325                 di_flags |= XFS_DIFLAG_IMMUTABLE;
9326 +       if (xflags & XFS_XFLAG_IXUNLINK)
9327 +               di_flags |= XFS_DIFLAG_IXUNLINK;
9328         if (xflags & XFS_XFLAG_APPEND)
9329                 di_flags |= XFS_DIFLAG_APPEND;
9330         if (xflags & XFS_XFLAG_SYNC)
9331 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
9332                 inode->i_flags |= S_IMMUTABLE;
9333         else
9334                 inode->i_flags &= ~S_IMMUTABLE;
9335 +       if (xflags & XFS_XFLAG_IXUNLINK)
9336 +               inode->i_flags |= S_IXUNLINK;
9337 +       else
9338 +               inode->i_flags &= ~S_IXUNLINK;
9339         if (xflags & XFS_XFLAG_APPEND)
9340                 inode->i_flags |= S_APPEND;
9341         else
9342 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
9343         case XFS_IOC_FSGETXATTRA:
9344                 return xfs_ioc_fsgetxattr(ip, 1, arg);
9345         case XFS_IOC_FSSETXATTR:
9346 +               if (IS_BARRIER(inode)) {
9347 +                       vxwprintk_task(1, "messing with the barrier.");
9348 +                       return -XFS_ERROR(EACCES);
9349 +               }
9350                 return xfs_ioc_fssetxattr(ip, filp, arg);
9351         case XFS_IOC_GETXFLAGS:
9352                 return xfs_ioc_getxflags(ip, arg);
9353         case XFS_IOC_SETXFLAGS:
9354 +               if (IS_BARRIER(inode)) {
9355 +                       vxwprintk_task(1, "messing with the barrier.");
9356 +                       return -XFS_ERROR(EACCES);
9357 +               }
9358                 return xfs_ioc_setxflags(ip, filp, arg);
9359  
9360         case XFS_IOC_FSSETDM: {
9361 diff -NurpP --minimal linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.h linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_ioctl.h
9362 --- linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.h    2010-07-07 18:31:54.000000000 +0200
9363 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_ioctl.h    2011-06-10 22:11:24.000000000 +0200
9364 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
9365         void __user             *uhandle,
9366         u32                     hlen);
9367  
9368 +extern int
9369 +xfs_sync_flags(
9370 +       struct inode            *inode,
9371 +       int                     flags,
9372 +       int                     vflags);
9373 +
9374  extern long
9375  xfs_file_ioctl(
9376         struct file             *filp,
9377 diff -NurpP --minimal linux-3.0.4/fs/xfs/linux-2.6/xfs_iops.c linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_iops.c
9378 --- linux-3.0.4/fs/xfs/linux-2.6/xfs_iops.c     2011-07-22 11:18:09.000000000 +0200
9379 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_iops.c     2011-06-22 12:39:15.000000000 +0200
9380 @@ -30,6 +30,7 @@
9381  #include "xfs_bmap_btree.h"
9382  #include "xfs_dinode.h"
9383  #include "xfs_inode.h"
9384 +#include "xfs_ioctl.h"
9385  #include "xfs_bmap.h"
9386  #include "xfs_rtalloc.h"
9387  #include "xfs_error.h"
9388 @@ -48,6 +49,7 @@
9389  #include <linux/security.h>
9390  #include <linux/fiemap.h>
9391  #include <linux/slab.h>
9392 +#include <linux/vs_tag.h>
9393  
9394  /*
9395   * Bring the timestamps in the XFS inode uptodate.
9396 @@ -464,6 +466,7 @@ xfs_vn_getattr(
9397         stat->nlink = ip->i_d.di_nlink;
9398         stat->uid = ip->i_d.di_uid;
9399         stat->gid = ip->i_d.di_gid;
9400 +       stat->tag = ip->i_d.di_tag;
9401         stat->ino = ip->i_ino;
9402         stat->atime = inode->i_atime;
9403         stat->mtime = inode->i_mtime;
9404 @@ -599,6 +602,7 @@ static const struct inode_operations xfs
9405         .removexattr            = generic_removexattr,
9406         .listxattr              = xfs_vn_listxattr,
9407         .fiemap                 = xfs_vn_fiemap,
9408 +       .sync_flags             = xfs_sync_flags,
9409  };
9410  
9411  static const struct inode_operations xfs_dir_inode_operations = {
9412 @@ -624,6 +628,7 @@ static const struct inode_operations xfs
9413         .getxattr               = generic_getxattr,
9414         .removexattr            = generic_removexattr,
9415         .listxattr              = xfs_vn_listxattr,
9416 +       .sync_flags             = xfs_sync_flags,
9417  };
9418  
9419  static const struct inode_operations xfs_dir_ci_inode_operations = {
9420 @@ -673,6 +678,10 @@ xfs_diflags_to_iflags(
9421                 inode->i_flags |= S_IMMUTABLE;
9422         else
9423                 inode->i_flags &= ~S_IMMUTABLE;
9424 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
9425 +               inode->i_flags |= S_IXUNLINK;
9426 +       else
9427 +               inode->i_flags &= ~S_IXUNLINK;
9428         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
9429                 inode->i_flags |= S_APPEND;
9430         else
9431 @@ -685,6 +694,15 @@ xfs_diflags_to_iflags(
9432                 inode->i_flags |= S_NOATIME;
9433         else
9434                 inode->i_flags &= ~S_NOATIME;
9435 +
9436 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
9437 +               inode->i_vflags |= V_BARRIER;
9438 +       else
9439 +               inode->i_vflags &= ~V_BARRIER;
9440 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
9441 +               inode->i_vflags |= V_COW;
9442 +       else
9443 +               inode->i_vflags &= ~V_COW;
9444  }
9445  
9446  /*
9447 @@ -716,6 +734,7 @@ xfs_setup_inode(
9448         inode->i_nlink  = ip->i_d.di_nlink;
9449         inode->i_uid    = ip->i_d.di_uid;
9450         inode->i_gid    = ip->i_d.di_gid;
9451 +       inode->i_tag    = ip->i_d.di_tag;
9452  
9453         switch (inode->i_mode & S_IFMT) {
9454         case S_IFBLK:
9455 diff -NurpP --minimal linux-3.0.4/fs/xfs/linux-2.6/xfs_linux.h linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_linux.h
9456 --- linux-3.0.4/fs/xfs/linux-2.6/xfs_linux.h    2011-07-22 11:18:09.000000000 +0200
9457 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_linux.h    2011-06-10 22:11:24.000000000 +0200
9458 @@ -115,6 +115,7 @@
9459  
9460  #define current_cpu()          (raw_smp_processor_id())
9461  #define current_pid()          (current->pid)
9462 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
9463  #define current_test_flags(f)  (current->flags & (f))
9464  #define current_set_flags_nested(sp, f)                \
9465                 (*(sp) = current->flags, current->flags |= (f))
9466 diff -NurpP --minimal linux-3.0.4/fs/xfs/linux-2.6/xfs_super.c linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_super.c
9467 --- linux-3.0.4/fs/xfs/linux-2.6/xfs_super.c    2011-07-22 11:18:09.000000000 +0200
9468 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/linux-2.6/xfs_super.c    2011-06-22 12:39:15.000000000 +0200
9469 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
9470  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
9471  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
9472  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
9473 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
9474 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
9475 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
9476  
9477  /*
9478   * Table driven mount option parser.
9479 @@ -122,10 +125,14 @@ mempool_t *xfs_ioend_pool;
9480   * in the future, too.
9481   */
9482  enum {
9483 +       Opt_tag, Opt_notag,
9484         Opt_barrier, Opt_nobarrier, Opt_err
9485  };
9486  
9487  static const match_table_t tokens = {
9488 +       {Opt_tag, "tagxid"},
9489 +       {Opt_tag, "tag"},
9490 +       {Opt_notag, "notag"},
9491         {Opt_barrier, "barrier"},
9492         {Opt_nobarrier, "nobarrier"},
9493         {Opt_err, NULL}
9494 @@ -373,6 +380,19 @@ xfs_parseargs(
9495                 } else if (!strcmp(this_char, "irixsgid")) {
9496                         xfs_warn(mp,
9497         "irixsgid is now a sysctl(2) variable, option is deprecated.");
9498 +#ifndef CONFIG_TAGGING_NONE
9499 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9500 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
9501 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
9502 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
9503 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
9504 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
9505 +#endif
9506 +#ifdef CONFIG_PROPAGATE
9507 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9508 +                       /* use value */
9509 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
9510 +#endif
9511                 } else {
9512                         xfs_warn(mp, "unknown mount option [%s].", this_char);
9513                         return EINVAL;
9514 @@ -1182,6 +1202,16 @@ xfs_fs_remount(
9515                 case Opt_nobarrier:
9516                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
9517                         break;
9518 +               case Opt_tag:
9519 +                       if (!(sb->s_flags & MS_TAGGED)) {
9520 +                               printk(KERN_INFO
9521 +                                       "XFS: %s: tagging not permitted on remount.\n",
9522 +                                       sb->s_id);
9523 +                               return -EINVAL;
9524 +                       }
9525 +                       break;
9526 +               case Opt_notag:
9527 +                       break;
9528                 default:
9529                         /*
9530                          * Logically we would return an error here to prevent
9531 @@ -1397,6 +1427,9 @@ xfs_fs_fill_super(
9532         if (error)
9533                 goto out_free_sb;
9534  
9535 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
9536 +               sb->s_flags |= MS_TAGGED;
9537 +
9538         /*
9539          * we must configure the block size in the superblock before we run the
9540          * full mount process as the mount process can lookup and cache inodes.
9541 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_dinode.h linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_dinode.h
9542 --- linux-3.0.4/fs/xfs/xfs_dinode.h     2011-01-05 21:50:28.000000000 +0100
9543 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_dinode.h     2011-06-10 22:11:24.000000000 +0200
9544 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
9545         __be32          di_nlink;       /* number of links to file */
9546         __be16          di_projid_lo;   /* lower part of owner's project id */
9547         __be16          di_projid_hi;   /* higher part owner's project id */
9548 -       __u8            di_pad[6];      /* unused, zeroed space */
9549 +       __u8            di_pad[2];      /* unused, zeroed space */
9550 +       __be16          di_tag;         /* context tagging */
9551 +       __be16          di_vflags;      /* vserver specific flags */
9552         __be16          di_flushiter;   /* incremented on flush */
9553         xfs_timestamp_t di_atime;       /* time last accessed */
9554         xfs_timestamp_t di_mtime;       /* time last modified */
9555 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
9556  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
9557  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
9558  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
9559 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
9560 +
9561  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
9562  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
9563  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
9564 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
9565  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
9566  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
9567  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
9568 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
9569  
9570  #ifdef CONFIG_XFS_RT
9571  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
9572 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
9573          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
9574          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
9575          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
9576 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
9577 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
9578 +        XFS_DIFLAG_IXUNLINK)
9579 +
9580 +#define XFS_DIVFLAG_BARRIER    0x01
9581 +#define XFS_DIVFLAG_COW                0x02
9582  
9583  #endif /* __XFS_DINODE_H__ */
9584 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_fs.h linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_fs.h
9585 --- linux-3.0.4/fs/xfs/xfs_fs.h 2011-01-05 21:50:28.000000000 +0100
9586 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_fs.h 2011-06-10 22:11:24.000000000 +0200
9587 @@ -67,6 +67,9 @@ struct fsxattr {
9588  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
9589  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
9590  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
9591 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
9592 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
9593 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
9594  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
9595  
9596  /*
9597 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
9598  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
9599         __u16           bs_forkoff;     /* inode fork offset in bytes   */
9600         __u16           bs_projid_hi;   /* higher part of project id    */
9601 -       unsigned char   bs_pad[10];     /* pad space, unused            */
9602 +       unsigned char   bs_pad[8];      /* pad space, unused            */
9603 +       __u16           bs_tag;         /* context tagging              */
9604         __u32           bs_dmevmask;    /* DMIG event mask              */
9605         __u16           bs_dmstate;     /* DMIG state info              */
9606         __u16           bs_aextents;    /* attribute number of extents  */
9607 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_ialloc.c linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_ialloc.c
9608 --- linux-3.0.4/fs/xfs/xfs_ialloc.c     2011-05-22 16:17:54.000000000 +0200
9609 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_ialloc.c     2011-06-10 22:11:24.000000000 +0200
9610 @@ -37,7 +37,6 @@
9611  #include "xfs_error.h"
9612  #include "xfs_bmap.h"
9613  
9614 -
9615  /*
9616   * Allocation group level functions.
9617   */
9618 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_inode.c linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_inode.c
9619 --- linux-3.0.4/fs/xfs/xfs_inode.c      2011-07-22 11:18:10.000000000 +0200
9620 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_inode.c      2011-06-10 22:11:24.000000000 +0200
9621 @@ -243,6 +243,7 @@ xfs_inotobp(
9622         return 0;
9623  }
9624  
9625 +#include <linux/vs_tag.h>
9626  
9627  /*
9628   * This routine is called to map an inode to the buffer containing
9629 @@ -641,15 +642,25 @@ xfs_iformat_btree(
9630  STATIC void
9631  xfs_dinode_from_disk(
9632         xfs_icdinode_t          *to,
9633 -       xfs_dinode_t            *from)
9634 +       xfs_dinode_t            *from,
9635 +       int tagged)
9636  {
9637 +       uint32_t uid, gid, tag;
9638 +
9639         to->di_magic = be16_to_cpu(from->di_magic);
9640         to->di_mode = be16_to_cpu(from->di_mode);
9641         to->di_version = from ->di_version;
9642         to->di_format = from->di_format;
9643         to->di_onlink = be16_to_cpu(from->di_onlink);
9644 -       to->di_uid = be32_to_cpu(from->di_uid);
9645 -       to->di_gid = be32_to_cpu(from->di_gid);
9646 +
9647 +       uid = be32_to_cpu(from->di_uid);
9648 +       gid = be32_to_cpu(from->di_gid);
9649 +       tag = be16_to_cpu(from->di_tag);
9650 +
9651 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
9652 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
9653 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
9654 +
9655         to->di_nlink = be32_to_cpu(from->di_nlink);
9656         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
9657         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
9658 @@ -671,21 +682,26 @@ xfs_dinode_from_disk(
9659         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
9660         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
9661         to->di_flags    = be16_to_cpu(from->di_flags);
9662 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
9663         to->di_gen      = be32_to_cpu(from->di_gen);
9664  }
9665  
9666  void
9667  xfs_dinode_to_disk(
9668         xfs_dinode_t            *to,
9669 -       xfs_icdinode_t          *from)
9670 +       xfs_icdinode_t          *from,
9671 +       int tagged)
9672  {
9673         to->di_magic = cpu_to_be16(from->di_magic);
9674         to->di_mode = cpu_to_be16(from->di_mode);
9675         to->di_version = from ->di_version;
9676         to->di_format = from->di_format;
9677         to->di_onlink = cpu_to_be16(from->di_onlink);
9678 -       to->di_uid = cpu_to_be32(from->di_uid);
9679 -       to->di_gid = cpu_to_be32(from->di_gid);
9680 +
9681 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
9682 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
9683 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
9684 +
9685         to->di_nlink = cpu_to_be32(from->di_nlink);
9686         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
9687         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
9688 @@ -707,12 +723,14 @@ xfs_dinode_to_disk(
9689         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
9690         to->di_dmstate = cpu_to_be16(from->di_dmstate);
9691         to->di_flags = cpu_to_be16(from->di_flags);
9692 +       to->di_vflags = cpu_to_be16(from->di_vflags);
9693         to->di_gen = cpu_to_be32(from->di_gen);
9694  }
9695  
9696  STATIC uint
9697  _xfs_dic2xflags(
9698 -       __uint16_t              di_flags)
9699 +       __uint16_t              di_flags,
9700 +       __uint16_t              di_vflags)
9701  {
9702         uint                    flags = 0;
9703  
9704 @@ -723,6 +741,8 @@ _xfs_dic2xflags(
9705                         flags |= XFS_XFLAG_PREALLOC;
9706                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
9707                         flags |= XFS_XFLAG_IMMUTABLE;
9708 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
9709 +                       flags |= XFS_XFLAG_IXUNLINK;
9710                 if (di_flags & XFS_DIFLAG_APPEND)
9711                         flags |= XFS_XFLAG_APPEND;
9712                 if (di_flags & XFS_DIFLAG_SYNC)
9713 @@ -747,6 +767,10 @@ _xfs_dic2xflags(
9714                         flags |= XFS_XFLAG_FILESTREAM;
9715         }
9716  
9717 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
9718 +               flags |= FS_BARRIER_FL;
9719 +       if (di_vflags & XFS_DIVFLAG_COW)
9720 +               flags |= FS_COW_FL;
9721         return flags;
9722  }
9723  
9724 @@ -756,7 +780,7 @@ xfs_ip2xflags(
9725  {
9726         xfs_icdinode_t          *dic = &ip->i_d;
9727  
9728 -       return _xfs_dic2xflags(dic->di_flags) |
9729 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
9730                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
9731  }
9732  
9733 @@ -764,7 +788,8 @@ uint
9734  xfs_dic2xflags(
9735         xfs_dinode_t            *dip)
9736  {
9737 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
9738 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
9739 +                               be16_to_cpu(dip->di_vflags)) |
9740                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
9741  }
9742  
9743 @@ -797,7 +822,6 @@ xfs_iread(
9744         if (error)
9745                 return error;
9746         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
9747 -
9748         /*
9749          * If we got something that isn't an inode it means someone
9750          * (nfs or dmi) has a stale handle.
9751 @@ -820,7 +844,8 @@ xfs_iread(
9752          * Otherwise, just get the truly permanent information.
9753          */
9754         if (dip->di_mode) {
9755 -               xfs_dinode_from_disk(&ip->i_d, dip);
9756 +               xfs_dinode_from_disk(&ip->i_d, dip,
9757 +                       mp->m_flags & XFS_MOUNT_TAGGED);
9758                 error = xfs_iformat(ip, dip);
9759                 if (error)  {
9760  #ifdef DEBUG
9761 @@ -1015,6 +1040,7 @@ xfs_ialloc(
9762         ASSERT(ip->i_d.di_nlink == nlink);
9763         ip->i_d.di_uid = current_fsuid();
9764         ip->i_d.di_gid = current_fsgid();
9765 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
9766         xfs_set_projid(ip, prid);
9767         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
9768  
9769 @@ -1075,6 +1101,7 @@ xfs_ialloc(
9770         ip->i_d.di_dmevmask = 0;
9771         ip->i_d.di_dmstate = 0;
9772         ip->i_d.di_flags = 0;
9773 +       ip->i_d.di_vflags = 0;
9774         flags = XFS_ILOG_CORE;
9775         switch (mode & S_IFMT) {
9776         case S_IFIFO:
9777 @@ -2108,6 +2135,7 @@ xfs_ifree(
9778         }
9779         ip->i_d.di_mode = 0;            /* mark incore inode as free */
9780         ip->i_d.di_flags = 0;
9781 +       ip->i_d.di_vflags = 0;
9782         ip->i_d.di_dmevmask = 0;
9783         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
9784         ip->i_df.if_ext_max =
9785 @@ -2987,7 +3015,8 @@ xfs_iflush_int(
9786          * because if the inode is dirty at all the core must
9787          * be.
9788          */
9789 -       xfs_dinode_to_disk(dip, &ip->i_d);
9790 +       xfs_dinode_to_disk(dip, &ip->i_d,
9791 +               mp->m_flags & XFS_MOUNT_TAGGED);
9792  
9793         /* Wrap, we never let the log put out DI_MAX_FLUSH */
9794         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
9795 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_inode.h linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_inode.h
9796 --- linux-3.0.4/fs/xfs/xfs_inode.h      2011-07-22 11:18:10.000000000 +0200
9797 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_inode.h      2011-07-01 11:35:35.000000000 +0200
9798 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
9799         __uint32_t      di_nlink;       /* number of links to file */
9800         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
9801         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
9802 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
9803 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
9804 +       __uint16_t      di_tag;         /* context tagging */
9805 +       __uint16_t      di_vflags;      /* vserver specific flags */
9806         __uint16_t      di_flushiter;   /* incremented on flush */
9807         xfs_ictimestamp_t di_atime;     /* time last accessed */
9808         xfs_ictimestamp_t di_mtime;     /* time last modified */
9809 @@ -546,7 +548,7 @@ int         xfs_itobp(struct xfs_mount *, struc
9810  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
9811                           struct xfs_inode *, uint);
9812  void           xfs_dinode_to_disk(struct xfs_dinode *,
9813 -                                  struct xfs_icdinode *);
9814 +                                  struct xfs_icdinode *, int);
9815  void           xfs_idestroy_fork(struct xfs_inode *, int);
9816  void           xfs_idata_realloc(struct xfs_inode *, int, int);
9817  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
9818 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_itable.c linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_itable.c
9819 --- linux-3.0.4/fs/xfs/xfs_itable.c     2011-05-22 16:17:54.000000000 +0200
9820 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_itable.c     2011-06-10 22:11:24.000000000 +0200
9821 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
9822         buf->bs_mode = dic->di_mode;
9823         buf->bs_uid = dic->di_uid;
9824         buf->bs_gid = dic->di_gid;
9825 +       buf->bs_tag = dic->di_tag;
9826         buf->bs_size = dic->di_size;
9827  
9828         /*
9829 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_log_recover.c linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_log_recover.c
9830 --- linux-3.0.4/fs/xfs/xfs_log_recover.c        2011-07-22 11:18:10.000000000 +0200
9831 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_log_recover.c        2011-06-10 22:11:24.000000000 +0200
9832 @@ -2343,7 +2343,8 @@ xlog_recover_inode_pass2(
9833         }
9834  
9835         /* The core is in in-core format */
9836 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
9837 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
9838 +               mp->m_flags & XFS_MOUNT_TAGGED);
9839  
9840         /* the rest is in on-disk format */
9841         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
9842 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_mount.h linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_mount.h
9843 --- linux-3.0.4/fs/xfs/xfs_mount.h      2011-07-22 11:18:10.000000000 +0200
9844 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_mount.h      2011-06-10 22:11:24.000000000 +0200
9845 @@ -249,6 +249,7 @@ typedef struct xfs_mount {
9846                                                    allocator */
9847  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
9848  
9849 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
9850  
9851  /*
9852   * Default minimum read and write sizes.
9853 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_vnodeops.c linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_vnodeops.c
9854 --- linux-3.0.4/fs/xfs/xfs_vnodeops.c   2011-07-22 11:18:10.000000000 +0200
9855 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_vnodeops.c   2011-07-01 11:35:35.000000000 +0200
9856 @@ -50,6 +50,78 @@
9857  #include "xfs_vnodeops.h"
9858  #include "xfs_trace.h"
9859  
9860 +
9861 +STATIC void
9862 +xfs_get_inode_flags(
9863 +       xfs_inode_t     *ip)
9864 +{
9865 +       struct inode    *inode = VFS_I(ip);
9866 +       unsigned int    flags = inode->i_flags;
9867 +       unsigned int    vflags = inode->i_vflags;
9868 +
9869 +       if (flags & S_IMMUTABLE)
9870 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
9871 +       else
9872 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
9873 +       if (flags & S_IXUNLINK)
9874 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
9875 +       else
9876 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
9877 +
9878 +       if (vflags & V_BARRIER)
9879 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
9880 +       else
9881 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
9882 +       if (vflags & V_COW)
9883 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
9884 +       else
9885 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
9886 +}
9887 +
9888 +int
9889 +xfs_sync_flags(
9890 +       struct inode            *inode,
9891 +       int                     flags,
9892 +       int                     vflags)
9893 +{
9894 +       struct xfs_inode        *ip = XFS_I(inode);
9895 +       struct xfs_mount        *mp = ip->i_mount;
9896 +       struct xfs_trans        *tp;
9897 +       unsigned int            lock_flags = 0;
9898 +       int                     code;
9899 +
9900 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
9901 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
9902 +       if (code)
9903 +               goto error_out;
9904 +
9905 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
9906 +
9907 +       xfs_trans_ijoin(tp, ip);
9908 +
9909 +       inode->i_flags = flags;
9910 +       inode->i_vflags = vflags;
9911 +       xfs_get_inode_flags(ip);
9912 +
9913 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
9914 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
9915 +
9916 +       XFS_STATS_INC(xs_ig_attrchg);
9917 +
9918 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
9919 +               xfs_trans_set_sync(tp);
9920 +       code = xfs_trans_commit(tp, 0);
9921 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
9922 +       return code;
9923 +
9924 +error_out:
9925 +       xfs_trans_cancel(tp, 0);
9926 +       if (lock_flags)
9927 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
9928 +       return code;
9929 +}
9930 +
9931 +
9932  int
9933  xfs_setattr(
9934         struct xfs_inode        *ip,
9935 @@ -65,6 +137,7 @@ xfs_setattr(
9936         uint                    commit_flags=0;
9937         uid_t                   uid=0, iuid=0;
9938         gid_t                   gid=0, igid=0;
9939 +       tag_t                   tag=0, itag=0;
9940         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
9941         int                     need_iolock = 1;
9942  
9943 @@ -147,7 +220,7 @@ xfs_setattr(
9944         /*
9945          * Change file ownership.  Must be the owner or privileged.
9946          */
9947 -       if (mask & (ATTR_UID|ATTR_GID)) {
9948 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
9949                 /*
9950                  * These IDs could have changed since we last looked at them.
9951                  * But, we're assured that if the ownership did change
9952 @@ -156,8 +229,10 @@ xfs_setattr(
9953                  */
9954                 iuid = ip->i_d.di_uid;
9955                 igid = ip->i_d.di_gid;
9956 +               itag = ip->i_d.di_tag;
9957                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
9958                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
9959 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
9960  
9961                 /*
9962                  * Do a quota reservation only if uid/gid is actually
9963 @@ -165,7 +240,8 @@ xfs_setattr(
9964                  */
9965                 if (XFS_IS_QUOTA_RUNNING(mp) &&
9966                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
9967 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
9968 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
9969 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
9970                         ASSERT(tp);
9971                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
9972                                                 capable(CAP_FOWNER) ?
9973 @@ -329,7 +405,7 @@ xfs_setattr(
9974         /*
9975          * Change file ownership.  Must be the owner or privileged.
9976          */
9977 -       if (mask & (ATTR_UID|ATTR_GID)) {
9978 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
9979                 /*
9980                  * CAP_FSETID overrides the following restrictions:
9981                  *
9982 @@ -345,6 +421,10 @@ xfs_setattr(
9983                  * Change the ownerships and register quota modifications
9984                  * in the transaction.
9985                  */
9986 +               if (itag != tag) {
9987 +                       ip->i_d.di_tag = tag;
9988 +                       inode->i_tag = tag;
9989 +               }
9990                 if (iuid != uid) {
9991                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
9992                                 ASSERT(mask & ATTR_UID);
9993 diff -NurpP --minimal linux-3.0.4/fs/xfs/xfs_vnodeops.h linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_vnodeops.h
9994 --- linux-3.0.4/fs/xfs/xfs_vnodeops.h   2011-05-22 16:17:54.000000000 +0200
9995 +++ linux-3.0.4-vs2.3.1-pre10.1/fs/xfs/xfs_vnodeops.h   2011-06-10 22:11:24.000000000 +0200
9996 @@ -13,6 +13,7 @@ struct xfs_inode;
9997  struct xfs_iomap;
9998  
9999  
10000 +int xfs_sync_xflags(struct xfs_inode *ip);
10001  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
10002  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
10003  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
10004 diff -NurpP --minimal linux-3.0.4/include/asm-generic/tlb.h linux-3.0.4-vs2.3.1-pre10.1/include/asm-generic/tlb.h
10005 --- linux-3.0.4/include/asm-generic/tlb.h       2011-07-22 11:18:10.000000000 +0200
10006 +++ linux-3.0.4-vs2.3.1-pre10.1/include/asm-generic/tlb.h       2011-06-10 22:11:24.000000000 +0200
10007 @@ -16,6 +16,7 @@
10008  #define _ASM_GENERIC__TLB_H
10009  
10010  #include <linux/swap.h>
10011 +#include <linux/vs_memory.h>
10012  #include <asm/pgalloc.h>
10013  #include <asm/tlbflush.h>
10014  
10015 diff -NurpP --minimal linux-3.0.4/include/linux/Kbuild linux-3.0.4-vs2.3.1-pre10.1/include/linux/Kbuild
10016 --- linux-3.0.4/include/linux/Kbuild    2011-07-22 11:18:10.000000000 +0200
10017 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/Kbuild    2011-06-10 22:11:24.000000000 +0200
10018 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
10019  header-y += netfilter_ipv4/
10020  header-y += netfilter_ipv6/
10021  header-y += usb/
10022 +header-y += vserver/
10023  header-y += wimax/
10024  
10025  objhdr-y += version.h
10026 diff -NurpP --minimal linux-3.0.4/include/linux/capability.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/capability.h
10027 --- linux-3.0.4/include/linux/capability.h      2011-07-22 11:18:10.000000000 +0200
10028 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/capability.h      2011-06-10 22:11:24.000000000 +0200
10029 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
10030     arbitrary SCSI commands */
10031  /* Allow setting encryption key on loopback filesystem */
10032  /* Allow setting zone reclaim policy */
10033 +/* Allow the selection of a security context */
10034  
10035  #define CAP_SYS_ADMIN        21
10036  
10037 @@ -362,7 +363,12 @@ struct cpu_vfs_cap_data {
10038  
10039  #define CAP_LAST_CAP         CAP_WAKE_ALARM
10040  
10041 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
10042 +/* Allow context manipulations */
10043 +/* Allow changing context info on files */
10044 +
10045 +#define CAP_CONTEXT         63
10046 +
10047 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
10048  
10049  /*
10050   * Bit location of each capability (used by user-space library and kernel)
10051 diff -NurpP --minimal linux-3.0.4/include/linux/cred.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/cred.h
10052 --- linux-3.0.4/include/linux/cred.h    2011-07-22 11:18:10.000000000 +0200
10053 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/cred.h    2011-06-10 22:11:24.000000000 +0200
10054 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
10055  extern int copy_creds(struct task_struct *, unsigned long);
10056  extern const struct cred *get_task_cred(struct task_struct *);
10057  extern struct cred *cred_alloc_blank(void);
10058 +extern struct cred *__prepare_creds(const struct cred *);
10059  extern struct cred *prepare_creds(void);
10060  extern struct cred *prepare_exec_creds(void);
10061  extern int commit_creds(struct cred *);
10062 @@ -209,6 +210,31 @@ static inline void validate_process_cred
10063  }
10064  #endif
10065  
10066 +static inline void set_cred_subscribers(struct cred *cred, int n)
10067 +{
10068 +#ifdef CONFIG_DEBUG_CREDENTIALS
10069 +       atomic_set(&cred->subscribers, n);
10070 +#endif
10071 +}
10072 +
10073 +static inline int read_cred_subscribers(const struct cred *cred)
10074 +{
10075 +#ifdef CONFIG_DEBUG_CREDENTIALS
10076 +       return atomic_read(&cred->subscribers);
10077 +#else
10078 +       return 0;
10079 +#endif
10080 +}
10081 +
10082 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
10083 +{
10084 +#ifdef CONFIG_DEBUG_CREDENTIALS
10085 +       struct cred *cred = (struct cred *) _cred;
10086 +
10087 +       atomic_add(n, &cred->subscribers);
10088 +#endif
10089 +}
10090 +
10091  /**
10092   * get_new_cred - Get a reference on a new set of credentials
10093   * @cred: The new credentials to reference
10094 diff -NurpP --minimal linux-3.0.4/include/linux/devpts_fs.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/devpts_fs.h
10095 --- linux-3.0.4/include/linux/devpts_fs.h       2008-12-25 00:26:37.000000000 +0100
10096 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/devpts_fs.h       2011-06-10 22:11:24.000000000 +0200
10097 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
10098  
10099  #endif
10100  
10101 -
10102  #endif /* _LINUX_DEVPTS_FS_H */
10103 diff -NurpP --minimal linux-3.0.4/include/linux/ext2_fs.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/ext2_fs.h
10104 --- linux-3.0.4/include/linux/ext2_fs.h 2010-02-25 11:52:07.000000000 +0100
10105 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/ext2_fs.h 2011-06-10 22:11:24.000000000 +0200
10106 @@ -189,8 +189,12 @@ struct ext2_group_desc
10107  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
10108  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
10109  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
10110 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
10111  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
10112  
10113 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
10114 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
10115 +
10116  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
10117  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
10118  
10119 @@ -274,7 +278,8 @@ struct ext2_inode {
10120                         __u16   i_pad1;
10121                         __le16  l_i_uid_high;   /* these 2 fields    */
10122                         __le16  l_i_gid_high;   /* were reserved2[0] */
10123 -                       __u32   l_i_reserved2;
10124 +                       __le16  l_i_tag;        /* Context Tag */
10125 +                       __u16   l_i_reserved2;
10126                 } linux2;
10127                 struct {
10128                         __u8    h_i_frag;       /* Fragment number */
10129 @@ -303,6 +308,7 @@ struct ext2_inode {
10130  #define i_gid_low      i_gid
10131  #define i_uid_high     osd2.linux2.l_i_uid_high
10132  #define i_gid_high     osd2.linux2.l_i_gid_high
10133 +#define i_raw_tag      osd2.linux2.l_i_tag
10134  #define i_reserved2    osd2.linux2.l_i_reserved2
10135  #endif
10136  
10137 @@ -347,6 +353,7 @@ struct ext2_inode {
10138  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
10139  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
10140  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
10141 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
10142  
10143  
10144  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
10145 diff -NurpP --minimal linux-3.0.4/include/linux/ext3_fs.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/ext3_fs.h
10146 --- linux-3.0.4/include/linux/ext3_fs.h 2011-07-22 11:18:10.000000000 +0200
10147 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/ext3_fs.h 2011-06-10 22:11:24.000000000 +0200
10148 @@ -173,10 +173,14 @@ struct ext3_group_desc
10149  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
10150  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
10151  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
10152 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
10153  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
10154  
10155 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
10156 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
10157 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
10158 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
10159 +
10160 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
10161 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
10162  
10163  /* Flags that should be inherited by new inodes from their parent. */
10164  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
10165 @@ -312,7 +316,8 @@ struct ext3_inode {
10166                         __u16   i_pad1;
10167                         __le16  l_i_uid_high;   /* these 2 fields    */
10168                         __le16  l_i_gid_high;   /* were reserved2[0] */
10169 -                       __u32   l_i_reserved2;
10170 +                       __le16  l_i_tag;        /* Context Tag */
10171 +                       __u16   l_i_reserved2;
10172                 } linux2;
10173                 struct {
10174                         __u8    h_i_frag;       /* Fragment number */
10175 @@ -343,6 +348,7 @@ struct ext3_inode {
10176  #define i_gid_low      i_gid
10177  #define i_uid_high     osd2.linux2.l_i_uid_high
10178  #define i_gid_high     osd2.linux2.l_i_gid_high
10179 +#define i_raw_tag      osd2.linux2.l_i_tag
10180  #define i_reserved2    osd2.linux2.l_i_reserved2
10181  
10182  #elif defined(__GNU__)
10183 @@ -405,6 +411,7 @@ struct ext3_inode {
10184  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
10185  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
10186                                                   * error in ordered mode */
10187 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
10188  
10189  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
10190  #ifndef _LINUX_EXT2_FS_H
10191 @@ -919,6 +926,7 @@ extern void ext3_get_inode_flags(struct 
10192  extern void ext3_set_aops(struct inode *inode);
10193  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
10194                        u64 start, u64 len);
10195 +extern int ext3_sync_flags(struct inode *, int, int);
10196  
10197  /* ioctl.c */
10198  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
10199 diff -NurpP --minimal linux-3.0.4/include/linux/fs.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/fs.h
10200 --- linux-3.0.4/include/linux/fs.h      2011-07-22 11:18:10.000000000 +0200
10201 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/fs.h      2011-07-01 11:35:35.000000000 +0200
10202 @@ -208,6 +208,9 @@ struct inodes_stat_t {
10203  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
10204  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
10205  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
10206 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
10207 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
10208 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
10209  #define MS_NOSEC       (1<<28)
10210  #define MS_BORN                (1<<29)
10211  #define MS_ACTIVE      (1<<30)
10212 @@ -239,6 +242,14 @@ struct inodes_stat_t {
10213  #define S_IMA          1024    /* Inode has an associated IMA struct */
10214  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
10215  #define S_NOSEC                4096    /* no suid or xattr security attributes */
10216 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
10217 +
10218 +/* Linux-VServer related Inode flags */
10219 +
10220 +#define V_VALID                1
10221 +#define V_XATTR                2
10222 +#define V_BARRIER      4       /* Barrier for chroot() */
10223 +#define V_COW          8       /* Copy on Write */
10224  
10225  /*
10226   * Note that nosuid etc flags are inode-specific: setting some file-system
10227 @@ -261,12 +272,15 @@ struct inodes_stat_t {
10228  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
10229                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
10230  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
10231 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
10232 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
10233 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
10234 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
10235 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
10236  
10237  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
10238  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
10239  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
10240 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
10241 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
10242  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
10243  
10244  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
10245 @@ -277,6 +291,16 @@ struct inodes_stat_t {
10246  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
10247  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
10248  
10249 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
10250 +
10251 +#ifdef CONFIG_VSERVER_COWBL
10252 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
10253 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
10254 +#else
10255 +#  define IS_COW(inode)                (0)
10256 +#  define IS_COW_LINK(inode)   (0)
10257 +#endif
10258 +
10259  /* the read-only stuff doesn't really belong here, but any other place is
10260     probably as bad and I don't want to create yet another include file. */
10261  
10262 @@ -362,11 +386,14 @@ struct inodes_stat_t {
10263  #define FS_EXTENT_FL                   0x00080000 /* Extents */
10264  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
10265  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
10266 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
10267  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
10268  
10269 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
10270 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
10271 -
10272 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
10273 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
10274 +
10275 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
10276 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
10277  
10278  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
10279  #define SYNC_FILE_RANGE_WRITE          2
10280 @@ -447,6 +474,7 @@ typedef void (dio_iodone_t)(struct kiocb
10281  #define ATTR_KILL_PRIV (1 << 14)
10282  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
10283  #define ATTR_TIMES_SET (1 << 16)
10284 +#define ATTR_TAG       (1 << 17)
10285  
10286  /*
10287   * This is the Inode Attributes structure, used for notify_change().  It
10288 @@ -462,6 +490,7 @@ struct iattr {
10289         umode_t         ia_mode;
10290         uid_t           ia_uid;
10291         gid_t           ia_gid;
10292 +       tag_t           ia_tag;
10293         loff_t          ia_size;
10294         struct timespec ia_atime;
10295         struct timespec ia_mtime;
10296 @@ -475,6 +504,9 @@ struct iattr {
10297         struct file     *ia_file;
10298  };
10299  
10300 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
10301 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
10302 +
10303  /*
10304   * Includes for diskquotas.
10305   */
10306 @@ -740,11 +772,13 @@ struct inode {
10307         umode_t                 i_mode;
10308         uid_t                   i_uid;
10309         gid_t                   i_gid;
10310 +       tag_t                   i_tag;
10311         const struct inode_operations   *i_op;
10312         struct super_block      *i_sb;
10313  
10314         spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
10315 -       unsigned int            i_flags;
10316 +       unsigned short          i_flags;
10317 +       unsigned short          i_vflags;
10318         unsigned long           i_state;
10319  #ifdef CONFIG_SECURITY
10320         void                    *i_security;
10321 @@ -766,6 +800,7 @@ struct inode {
10322         atomic_t                i_count;
10323         unsigned int            i_nlink;
10324         dev_t                   i_rdev;
10325 +       dev_t                   i_mdev;
10326         unsigned int            i_blkbits;
10327         u64                     i_version;
10328         loff_t                  i_size;
10329 @@ -890,12 +925,12 @@ static inline void i_size_write(struct i
10330  
10331  static inline unsigned iminor(const struct inode *inode)
10332  {
10333 -       return MINOR(inode->i_rdev);
10334 +       return MINOR(inode->i_mdev);
10335  }
10336  
10337  static inline unsigned imajor(const struct inode *inode)
10338  {
10339 -       return MAJOR(inode->i_rdev);
10340 +       return MAJOR(inode->i_mdev);
10341  }
10342  
10343  extern struct block_device *I_BDEV(struct inode *inode);
10344 @@ -957,6 +992,7 @@ struct file {
10345         loff_t                  f_pos;
10346         struct fown_struct      f_owner;
10347         const struct cred       *f_cred;
10348 +       xid_t                   f_xid;
10349         struct file_ra_state    f_ra;
10350  
10351         u64                     f_version;
10352 @@ -1101,6 +1137,7 @@ struct file_lock {
10353         struct file *fl_file;
10354         loff_t fl_start;
10355         loff_t fl_end;
10356 +       xid_t fl_xid;
10357  
10358         struct fasync_struct *  fl_fasync; /* for lease break notifications */
10359         unsigned long fl_break_time;    /* for nonblocking lease breaks */
10360 @@ -1600,6 +1637,7 @@ struct inode_operations {
10361         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
10362         ssize_t (*listxattr) (struct dentry *, char *, size_t);
10363         int (*removexattr) (struct dentry *, const char *);
10364 +       int (*sync_flags) (struct inode *, int, int);
10365         void (*truncate_range)(struct inode *, loff_t, loff_t);
10366         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
10367                       u64 len);
10368 @@ -1618,6 +1656,7 @@ extern ssize_t vfs_readv(struct file *, 
10369                 unsigned long, loff_t *);
10370  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
10371                 unsigned long, loff_t *);
10372 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
10373  
10374  struct super_operations {
10375         struct inode *(*alloc_inode)(struct super_block *sb);
10376 @@ -2437,6 +2476,7 @@ extern int dcache_dir_open(struct inode 
10377  extern int dcache_dir_close(struct inode *, struct file *);
10378  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
10379  extern int dcache_readdir(struct file *, void *, filldir_t);
10380 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
10381  extern int simple_setattr(struct dentry *, struct iattr *);
10382  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
10383  extern int simple_statfs(struct dentry *, struct kstatfs *);
10384 diff -NurpP --minimal linux-3.0.4/include/linux/gfs2_ondisk.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/gfs2_ondisk.h
10385 --- linux-3.0.4/include/linux/gfs2_ondisk.h     2010-07-07 18:31:55.000000000 +0200
10386 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/gfs2_ondisk.h     2011-06-10 22:11:24.000000000 +0200
10387 @@ -211,6 +211,9 @@ enum {
10388         gfs2fl_NoAtime          = 7,
10389         gfs2fl_Sync             = 8,
10390         gfs2fl_System           = 9,
10391 +       gfs2fl_IXUnlink         = 16,
10392 +       gfs2fl_Barrier          = 17,
10393 +       gfs2fl_Cow              = 18,
10394         gfs2fl_TruncInProg      = 29,
10395         gfs2fl_InheritDirectio  = 30,
10396         gfs2fl_InheritJdata     = 31,
10397 @@ -227,6 +230,9 @@ enum {
10398  #define GFS2_DIF_NOATIME               0x00000080
10399  #define GFS2_DIF_SYNC                  0x00000100
10400  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
10401 +#define GFS2_DIF_IXUNLINK              0x00010000
10402 +#define GFS2_DIF_BARRIER               0x00020000
10403 +#define GFS2_DIF_COW                   0x00040000
10404  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
10405  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
10406  #define GFS2_DIF_INHERIT_JDATA         0x80000000
10407 diff -NurpP --minimal linux-3.0.4/include/linux/if_tun.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/if_tun.h
10408 --- linux-3.0.4/include/linux/if_tun.h  2010-08-02 16:52:54.000000000 +0200
10409 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/if_tun.h  2011-06-10 22:11:24.000000000 +0200
10410 @@ -53,6 +53,7 @@
10411  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
10412  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
10413  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
10414 +#define TUNSETNID     _IOW('T', 217, int)
10415  
10416  /* TUNSETIFF ifr flags */
10417  #define IFF_TUN                0x0001
10418 diff -NurpP --minimal linux-3.0.4/include/linux/init_task.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/init_task.h
10419 --- linux-3.0.4/include/linux/init_task.h       2011-07-22 11:18:10.000000000 +0200
10420 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/init_task.h       2011-06-10 22:11:24.000000000 +0200
10421 @@ -193,6 +193,10 @@ extern struct cred init_cred;
10422         INIT_FTRACE_GRAPH                                               \
10423         INIT_TRACE_RECURSION                                            \
10424         INIT_TASK_RCU_PREEMPT(tsk)                                      \
10425 +       .xid            = 0,                                            \
10426 +       .vx_info        = NULL,                                         \
10427 +       .nid            = 0,                                            \
10428 +       .nx_info        = NULL,                                         \
10429  }
10430  
10431  
10432 diff -NurpP --minimal linux-3.0.4/include/linux/ipc.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/ipc.h
10433 --- linux-3.0.4/include/linux/ipc.h     2009-12-03 20:02:55.000000000 +0100
10434 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/ipc.h     2011-06-10 22:11:24.000000000 +0200
10435 @@ -91,6 +91,7 @@ struct kern_ipc_perm
10436         key_t           key;
10437         uid_t           uid;
10438         gid_t           gid;
10439 +       xid_t           xid;
10440         uid_t           cuid;
10441         gid_t           cgid;
10442         mode_t          mode; 
10443 diff -NurpP --minimal linux-3.0.4/include/linux/ipc_namespace.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/ipc_namespace.h
10444 --- linux-3.0.4/include/linux/ipc_namespace.h   2011-05-22 16:17:55.000000000 +0200
10445 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/ipc_namespace.h   2011-06-13 14:09:44.000000000 +0200
10446 @@ -94,7 +94,8 @@ static inline int mq_init_ns(struct ipc_
10447  
10448  #if defined(CONFIG_IPC_NS)
10449  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
10450 -                                      struct task_struct *tsk);
10451 +                                      struct ipc_namespace *old_ns,
10452 +                                      struct user_namespace *user_ns);
10453  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
10454  {
10455         if (ns)
10456 @@ -105,12 +106,13 @@ static inline struct ipc_namespace *get_
10457  extern void put_ipc_ns(struct ipc_namespace *ns);
10458  #else
10459  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
10460 -                                             struct task_struct *tsk)
10461 +                                             struct ipc_namespace *old_ns,
10462 +                                             struct user_namespace *user_ns)
10463  {
10464         if (flags & CLONE_NEWIPC)
10465                 return ERR_PTR(-EINVAL);
10466  
10467 -       return tsk->nsproxy->ipc_ns;
10468 +       return old_ns;
10469  }
10470  
10471  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
10472 diff -NurpP --minimal linux-3.0.4/include/linux/loop.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/loop.h
10473 --- linux-3.0.4/include/linux/loop.h    2009-09-10 15:26:25.000000000 +0200
10474 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/loop.h    2011-06-10 22:11:24.000000000 +0200
10475 @@ -45,6 +45,7 @@ struct loop_device {
10476         struct loop_func_table *lo_encryption;
10477         __u32           lo_init[2];
10478         uid_t           lo_key_owner;   /* Who set the key */
10479 +       xid_t           lo_xid;
10480         int             (*ioctl)(struct loop_device *, int cmd, 
10481                                  unsigned long arg); 
10482  
10483 diff -NurpP --minimal linux-3.0.4/include/linux/magic.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/magic.h
10484 --- linux-3.0.4/include/linux/magic.h   2011-05-22 16:17:55.000000000 +0200
10485 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/magic.h   2011-06-10 22:11:24.000000000 +0200
10486 @@ -3,7 +3,7 @@
10487  
10488  #define ADFS_SUPER_MAGIC       0xadf5
10489  #define AFFS_SUPER_MAGIC       0xadff
10490 -#define AFS_SUPER_MAGIC                0x5346414F
10491 +#define AFS_SUPER_MAGIC                0x5346414F
10492  #define AUTOFS_SUPER_MAGIC     0x0187
10493  #define CODA_SUPER_MAGIC       0x73757245
10494  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
10495 @@ -41,6 +41,7 @@
10496  #define NFS_SUPER_MAGIC                0x6969
10497  #define OPENPROM_SUPER_MAGIC   0x9fa1
10498  #define PROC_SUPER_MAGIC       0x9fa0
10499 +#define DEVPTS_SUPER_MAGIC     0x1cd1
10500  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
10501  
10502  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
10503 diff -NurpP --minimal linux-3.0.4/include/linux/major.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/major.h
10504 --- linux-3.0.4/include/linux/major.h   2009-09-10 15:26:25.000000000 +0200
10505 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/major.h   2011-06-10 22:11:24.000000000 +0200
10506 @@ -15,6 +15,7 @@
10507  #define HD_MAJOR               IDE0_MAJOR
10508  #define PTY_SLAVE_MAJOR                3
10509  #define TTY_MAJOR              4
10510 +#define VROOT_MAJOR            4
10511  #define TTYAUX_MAJOR           5
10512  #define LP_MAJOR               6
10513  #define VCS_MAJOR              7
10514 diff -NurpP --minimal linux-3.0.4/include/linux/memcontrol.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/memcontrol.h
10515 --- linux-3.0.4/include/linux/memcontrol.h      2011-07-22 11:18:10.000000000 +0200
10516 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/memcontrol.h      2011-06-22 12:39:15.000000000 +0200
10517 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
10518  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
10519  extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
10520  
10521 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
10522 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
10523 +
10524 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
10525 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
10526 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
10527 +
10528  static inline
10529  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
10530  {
10531 diff -NurpP --minimal linux-3.0.4/include/linux/mm_types.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/mm_types.h
10532 --- linux-3.0.4/include/linux/mm_types.h        2011-07-22 11:18:11.000000000 +0200
10533 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/mm_types.h        2011-06-10 22:11:24.000000000 +0200
10534 @@ -268,6 +268,7 @@ struct mm_struct {
10535  
10536         /* Architecture-specific MM context */
10537         mm_context_t context;
10538 +       struct vx_info *mm_vx_info;
10539  
10540         /* Swap token stuff */
10541         /*
10542 diff -NurpP --minimal linux-3.0.4/include/linux/mmzone.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/mmzone.h
10543 --- linux-3.0.4/include/linux/mmzone.h  2011-07-22 11:18:11.000000000 +0200
10544 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/mmzone.h  2011-07-01 11:35:35.000000000 +0200
10545 @@ -654,6 +654,13 @@ typedef struct pglist_data {
10546         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
10547  })
10548  
10549 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
10550 +
10551 +#define node_end_pfn(nid) ({\
10552 +       pg_data_t *__pgdat = NODE_DATA(nid);\
10553 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
10554 +})
10555 +
10556  #include <linux/memory_hotplug.h>
10557  
10558  extern struct mutex zonelists_mutex;
10559 diff -NurpP --minimal linux-3.0.4/include/linux/mount.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/mount.h
10560 --- linux-3.0.4/include/linux/mount.h   2011-03-15 18:07:39.000000000 +0100
10561 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/mount.h   2011-06-10 22:11:24.000000000 +0200
10562 @@ -52,6 +52,9 @@ struct mnt_pcp {
10563         int mnt_writers;
10564  };
10565  
10566 +#define MNT_TAGID      0x10000
10567 +#define MNT_NOTAG      0x20000
10568 +
10569  struct vfsmount {
10570         struct list_head mnt_hash;
10571         struct vfsmount *mnt_parent;    /* fs we are mounted on */
10572 @@ -86,6 +89,7 @@ struct vfsmount {
10573         int mnt_expiry_mark;            /* true if marked for expiry */
10574         int mnt_pinned;
10575         int mnt_ghosts;
10576 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
10577  };
10578  
10579  struct file; /* forward dec */
10580 diff -NurpP --minimal linux-3.0.4/include/linux/net.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/net.h
10581 --- linux-3.0.4/include/linux/net.h     2011-07-22 11:18:11.000000000 +0200
10582 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/net.h     2011-06-10 22:11:24.000000000 +0200
10583 @@ -72,6 +72,7 @@ struct net;
10584  #define SOCK_NOSPACE           2
10585  #define SOCK_PASSCRED          3
10586  #define SOCK_PASSSEC           4
10587 +#define SOCK_USER_SOCKET       5
10588  
10589  #ifndef ARCH_HAS_SOCKET_TYPES
10590  /**
10591 diff -NurpP --minimal linux-3.0.4/include/linux/nfs_mount.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/nfs_mount.h
10592 --- linux-3.0.4/include/linux/nfs_mount.h       2011-01-05 21:50:31.000000000 +0100
10593 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/nfs_mount.h       2011-06-10 22:11:24.000000000 +0200
10594 @@ -63,7 +63,8 @@ struct nfs_mount_data {
10595  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
10596  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
10597  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
10598 -#define NFS_MOUNT_FLAGMASK     0xFFFF
10599 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
10600 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
10601  
10602  /* The following are for internal use only */
10603  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
10604 diff -NurpP --minimal linux-3.0.4/include/linux/nsproxy.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/nsproxy.h
10605 --- linux-3.0.4/include/linux/nsproxy.h 2011-07-22 11:18:11.000000000 +0200
10606 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/nsproxy.h 2011-06-10 22:11:24.000000000 +0200
10607 @@ -3,6 +3,7 @@
10608  
10609  #include <linux/spinlock.h>
10610  #include <linux/sched.h>
10611 +#include <linux/vserver/debug.h>
10612  
10613  struct mnt_namespace;
10614  struct uts_namespace;
10615 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
10616  }
10617  
10618  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
10619 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
10620  void exit_task_namespaces(struct task_struct *tsk);
10621  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
10622  void free_nsproxy(struct nsproxy *ns);
10623  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
10624         struct fs_struct *);
10625  
10626 -static inline void put_nsproxy(struct nsproxy *ns)
10627 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
10628 +
10629 +static inline void __get_nsproxy(struct nsproxy *ns,
10630 +       const char *_file, int _line)
10631  {
10632 -       if (atomic_dec_and_test(&ns->count)) {
10633 -               free_nsproxy(ns);
10634 -       }
10635 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
10636 +               ns, atomic_read(&ns->count), _file, _line);
10637 +       atomic_inc(&ns->count);
10638  }
10639  
10640 -static inline void get_nsproxy(struct nsproxy *ns)
10641 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
10642 +
10643 +static inline void __put_nsproxy(struct nsproxy *ns,
10644 +       const char *_file, int _line)
10645  {
10646 -       atomic_inc(&ns->count);
10647 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
10648 +               ns, atomic_read(&ns->count), _file, _line);
10649 +       if (atomic_dec_and_test(&ns->count)) {
10650 +               free_nsproxy(ns);
10651 +       }
10652  }
10653  
10654  #endif
10655 diff -NurpP --minimal linux-3.0.4/include/linux/pid.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/pid.h
10656 --- linux-3.0.4/include/linux/pid.h     2011-07-22 11:18:11.000000000 +0200
10657 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/pid.h     2011-06-10 22:11:24.000000000 +0200
10658 @@ -8,7 +8,8 @@ enum pid_type
10659         PIDTYPE_PID,
10660         PIDTYPE_PGID,
10661         PIDTYPE_SID,
10662 -       PIDTYPE_MAX
10663 +       PIDTYPE_MAX,
10664 +       PIDTYPE_REALPID
10665  };
10666  
10667  /*
10668 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
10669  }
10670  
10671  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
10672 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
10673  pid_t pid_vnr(struct pid *pid);
10674  
10675  #define do_each_pid_task(pid, type, task)                              \
10676 diff -NurpP --minimal linux-3.0.4/include/linux/proc_fs.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/proc_fs.h
10677 --- linux-3.0.4/include/linux/proc_fs.h 2011-07-22 11:18:11.000000000 +0200
10678 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/proc_fs.h 2011-06-10 22:11:24.000000000 +0200
10679 @@ -56,6 +56,7 @@ struct proc_dir_entry {
10680         nlink_t nlink;
10681         uid_t uid;
10682         gid_t gid;
10683 +       int vx_flags;
10684         loff_t size;
10685         const struct inode_operations *proc_iops;
10686         /*
10687 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
10688  extern const struct proc_ns_operations utsns_operations;
10689  extern const struct proc_ns_operations ipcns_operations;
10690  
10691 +struct vx_info;
10692 +struct nx_info;
10693 +
10694  union proc_op {
10695         int (*proc_get_link)(struct inode *, struct path *);
10696         int (*proc_read)(struct task_struct *task, char *page);
10697         int (*proc_show)(struct seq_file *m,
10698                 struct pid_namespace *ns, struct pid *pid,
10699                 struct task_struct *task);
10700 +       int (*proc_vs_read)(char *page);
10701 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
10702 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
10703  };
10704  
10705  struct ctl_table_header;
10706 @@ -265,6 +272,7 @@ struct ctl_table;
10707  
10708  struct proc_inode {
10709         struct pid *pid;
10710 +       int vx_flags;
10711         int fd;
10712         union proc_op op;
10713         struct proc_dir_entry *pde;
10714 diff -NurpP --minimal linux-3.0.4/include/linux/quotaops.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/quotaops.h
10715 --- linux-3.0.4/include/linux/quotaops.h        2011-05-22 16:17:57.000000000 +0200
10716 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/quotaops.h        2011-06-10 22:11:24.000000000 +0200
10717 @@ -8,6 +8,7 @@
10718  #define _LINUX_QUOTAOPS_
10719  
10720  #include <linux/fs.h>
10721 +#include <linux/vs_dlimit.h>
10722  
10723  #define DQUOT_SPACE_WARN       0x1
10724  #define DQUOT_SPACE_RESERVE    0x2
10725 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
10726  
10727  static inline int dquot_alloc_inode(const struct inode *inode)
10728  {
10729 -       return 0;
10730 +       return dl_alloc_inode(inode);
10731  }
10732  
10733  static inline void dquot_free_inode(const struct inode *inode)
10734  {
10735 +       dl_free_inode(inode);
10736  }
10737  
10738  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
10739 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
10740  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
10741                 int flags)
10742  {
10743 +       int ret = 0;
10744 +
10745 +       if ((ret = dl_alloc_space(inode, number)))
10746 +               return ret;
10747         if (!(flags & DQUOT_SPACE_RESERVE))
10748                 inode_add_bytes(inode, number);
10749         return 0;
10750 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
10751  {
10752         if (!(flags & DQUOT_SPACE_RESERVE))
10753                 inode_sub_bytes(inode, number);
10754 +       dl_free_space(inode, number);
10755  }
10756  
10757  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
10758 diff -NurpP --minimal linux-3.0.4/include/linux/reboot.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/reboot.h
10759 --- linux-3.0.4/include/linux/reboot.h  2010-07-07 18:31:56.000000000 +0200
10760 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/reboot.h  2011-06-10 22:11:24.000000000 +0200
10761 @@ -33,6 +33,7 @@
10762  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
10763  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
10764  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
10765 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
10766  
10767  
10768  #ifdef __KERNEL__
10769 diff -NurpP --minimal linux-3.0.4/include/linux/reiserfs_fs.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/reiserfs_fs.h
10770 --- linux-3.0.4/include/linux/reiserfs_fs.h     2011-05-22 16:17:58.000000000 +0200
10771 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/reiserfs_fs.h     2011-06-10 22:11:24.000000000 +0200
10772 @@ -976,6 +976,11 @@ struct stat_data_v1 {
10773  #define REISERFS_COMPR_FL     FS_COMPR_FL
10774  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
10775  
10776 +/* unfortunately reiserfs sdattr is only 16 bit */
10777 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
10778 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
10779 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
10780 +
10781  /* persistent flags that file inherits from the parent directory */
10782  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
10783                                 REISERFS_SYNC_FL |      \
10784 @@ -985,6 +990,9 @@ struct stat_data_v1 {
10785                                 REISERFS_COMPR_FL |     \
10786                                 REISERFS_NOTAIL_FL )
10787  
10788 +#define REISERFS_FL_USER_VISIBLE       0x80FF
10789 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
10790 +
10791  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
10792     address blocks) */
10793  struct stat_data {
10794 @@ -2073,6 +2081,7 @@ static inline void reiserfs_update_sd(st
10795  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
10796  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
10797  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
10798 +int reiserfs_sync_flags(struct inode *inode, int, int);
10799  
10800  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
10801  
10802 diff -NurpP --minimal linux-3.0.4/include/linux/reiserfs_fs_sb.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/reiserfs_fs_sb.h
10803 --- linux-3.0.4/include/linux/reiserfs_fs_sb.h  2010-02-25 11:52:07.000000000 +0100
10804 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/reiserfs_fs_sb.h  2011-06-10 22:11:24.000000000 +0200
10805 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
10806         REISERFS_EXPOSE_PRIVROOT,
10807         REISERFS_BARRIER_NONE,
10808         REISERFS_BARRIER_FLUSH,
10809 +       REISERFS_TAGGED,
10810  
10811         /* Actions on error */
10812         REISERFS_ERROR_PANIC,
10813 diff -NurpP --minimal linux-3.0.4/include/linux/sched.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/sched.h
10814 --- linux-3.0.4/include/linux/sched.h   2011-07-22 11:18:11.000000000 +0200
10815 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/sched.h   2011-07-22 11:20:39.000000000 +0200
10816 @@ -1406,6 +1406,14 @@ struct task_struct {
10817  #endif
10818         seccomp_t seccomp;
10819  
10820 +/* vserver context data */
10821 +       struct vx_info *vx_info;
10822 +       struct nx_info *nx_info;
10823 +
10824 +       xid_t xid;
10825 +       nid_t nid;
10826 +       tag_t tag;
10827 +
10828  /* Thread group tracking */
10829         u32 parent_exec_id;
10830         u32 self_exec_id;
10831 @@ -1649,6 +1657,11 @@ struct pid_namespace;
10832  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
10833                         struct pid_namespace *ns);
10834  
10835 +#include <linux/vserver/base.h>
10836 +#include <linux/vserver/context.h>
10837 +#include <linux/vserver/debug.h>
10838 +#include <linux/vserver/pid.h>
10839 +
10840  static inline pid_t task_pid_nr(struct task_struct *tsk)
10841  {
10842         return tsk->pid;
10843 @@ -1662,7 +1675,8 @@ static inline pid_t task_pid_nr_ns(struc
10844  
10845  static inline pid_t task_pid_vnr(struct task_struct *tsk)
10846  {
10847 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
10848 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
10849 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
10850  }
10851  
10852  
10853 @@ -1675,7 +1689,7 @@ pid_t task_tgid_nr_ns(struct task_struct
10854  
10855  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
10856  {
10857 -       return pid_vnr(task_tgid(tsk));
10858 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
10859  }
10860  
10861  
10862 diff -NurpP --minimal linux-3.0.4/include/linux/shmem_fs.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/shmem_fs.h
10863 --- linux-3.0.4/include/linux/shmem_fs.h        2011-07-22 11:18:11.000000000 +0200
10864 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/shmem_fs.h        2011-07-01 11:35:35.000000000 +0200
10865 @@ -12,6 +12,9 @@
10866  
10867  #define SHMEM_SYMLINK_INLINE_LEN (SHMEM_NR_DIRECT * sizeof(swp_entry_t))
10868  
10869 +#define TMPFS_SUPER_MAGIC      0x01021994
10870 +
10871 +
10872  struct shmem_inode_info {
10873         spinlock_t              lock;
10874         unsigned long           flags;
10875 diff -NurpP --minimal linux-3.0.4/include/linux/stat.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/stat.h
10876 --- linux-3.0.4/include/linux/stat.h    2008-12-25 00:26:37.000000000 +0100
10877 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/stat.h    2011-06-10 22:11:24.000000000 +0200
10878 @@ -66,6 +66,7 @@ struct kstat {
10879         unsigned int    nlink;
10880         uid_t           uid;
10881         gid_t           gid;
10882 +       tag_t           tag;
10883         dev_t           rdev;
10884         loff_t          size;
10885         struct timespec  atime;
10886 diff -NurpP --minimal linux-3.0.4/include/linux/sunrpc/auth.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/sunrpc/auth.h
10887 --- linux-3.0.4/include/linux/sunrpc/auth.h     2011-03-15 18:07:39.000000000 +0100
10888 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/sunrpc/auth.h     2011-06-10 22:11:24.000000000 +0200
10889 @@ -25,6 +25,7 @@
10890  struct auth_cred {
10891         uid_t   uid;
10892         gid_t   gid;
10893 +       tag_t   tag;
10894         struct group_info *group_info;
10895         unsigned char machine_cred : 1;
10896  };
10897 diff -NurpP --minimal linux-3.0.4/include/linux/sunrpc/clnt.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/sunrpc/clnt.h
10898 --- linux-3.0.4/include/linux/sunrpc/clnt.h     2011-05-22 16:17:58.000000000 +0200
10899 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/sunrpc/clnt.h     2011-06-10 22:11:24.000000000 +0200
10900 @@ -49,7 +49,8 @@ struct rpc_clnt {
10901         unsigned int            cl_softrtry : 1,/* soft timeouts */
10902                                 cl_discrtry : 1,/* disconnect before retry */
10903                                 cl_autobind : 1,/* use getport() */
10904 -                               cl_chatty   : 1;/* be verbose */
10905 +                               cl_chatty   : 1,/* be verbose */
10906 +                               cl_tag      : 1;/* context tagging */
10907  
10908         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
10909         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
10910 diff -NurpP --minimal linux-3.0.4/include/linux/syscalls.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/syscalls.h
10911 --- linux-3.0.4/include/linux/syscalls.h        2011-07-22 11:18:11.000000000 +0200
10912 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/syscalls.h        2011-06-10 22:11:24.000000000 +0200
10913 @@ -483,6 +483,8 @@ asmlinkage long sys_symlink(const char _
10914  asmlinkage long sys_unlink(const char __user *pathname);
10915  asmlinkage long sys_rename(const char __user *oldname,
10916                                 const char __user *newname);
10917 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
10918 +                               umode_t mode);
10919  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
10920  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
10921  
10922 diff -NurpP --minimal linux-3.0.4/include/linux/sysctl.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/sysctl.h
10923 --- linux-3.0.4/include/linux/sysctl.h  2011-03-15 18:07:40.000000000 +0100
10924 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/sysctl.h  2011-06-10 22:11:24.000000000 +0200
10925 @@ -60,6 +60,7 @@ enum
10926         CTL_ABI=9,              /* Binary emulation */
10927         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
10928         CTL_ARLAN=254,          /* arlan wireless driver */
10929 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
10930         CTL_S390DBF=5677,       /* s390 debug */
10931         CTL_SUNRPC=7249,        /* sunrpc debug */
10932         CTL_PM=9899,            /* frv power management */
10933 @@ -94,6 +95,7 @@ enum
10934  
10935         KERN_PANIC=15,          /* int: panic timeout */
10936         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
10937 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
10938  
10939         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
10940         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
10941 diff -NurpP --minimal linux-3.0.4/include/linux/sysfs.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/sysfs.h
10942 --- linux-3.0.4/include/linux/sysfs.h   2011-07-22 11:18:11.000000000 +0200
10943 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/sysfs.h   2011-06-22 12:39:15.000000000 +0200
10944 @@ -19,6 +19,8 @@
10945  #include <linux/kobject_ns.h>
10946  #include <asm/atomic.h>
10947  
10948 +#define SYSFS_SUPER_MAGIC      0x62656572
10949 +
10950  struct kobject;
10951  struct module;
10952  enum kobj_ns_type;
10953 diff -NurpP --minimal linux-3.0.4/include/linux/time.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/time.h
10954 --- linux-3.0.4/include/linux/time.h    2011-07-22 11:18:11.000000000 +0200
10955 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/time.h    2011-06-10 22:11:24.000000000 +0200
10956 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
10957         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
10958         a->tv_nsec = ns;
10959  }
10960 +
10961 +#include <linux/vs_time.h>
10962 +
10963  #endif /* __KERNEL__ */
10964  
10965  #define NFDBITS                        __NFDBITS
10966 diff -NurpP --minimal linux-3.0.4/include/linux/types.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/types.h
10967 --- linux-3.0.4/include/linux/types.h   2011-05-22 16:17:58.000000000 +0200
10968 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/types.h   2011-06-10 22:11:24.000000000 +0200
10969 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
10970  typedef __kernel_gid32_t       gid_t;
10971  typedef __kernel_uid16_t        uid16_t;
10972  typedef __kernel_gid16_t        gid16_t;
10973 +typedef unsigned int           xid_t;
10974 +typedef unsigned int           nid_t;
10975 +typedef unsigned int           tag_t;
10976  
10977  typedef unsigned long          uintptr_t;
10978  
10979 diff -NurpP --minimal linux-3.0.4/include/linux/utsname.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/utsname.h
10980 --- linux-3.0.4/include/linux/utsname.h 2011-05-22 16:17:58.000000000 +0200
10981 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/utsname.h 2011-06-13 14:36:48.000000000 +0200
10982 @@ -54,7 +54,8 @@ static inline void get_uts_ns(struct uts
10983  }
10984  
10985  extern struct uts_namespace *copy_utsname(unsigned long flags,
10986 -                                         struct task_struct *tsk);
10987 +                                         struct uts_namespace *old_ns,
10988 +                                         struct user_namespace *user_ns);
10989  extern void free_uts_ns(struct kref *kref);
10990  
10991  static inline void put_uts_ns(struct uts_namespace *ns)
10992 @@ -71,12 +72,13 @@ static inline void put_uts_ns(struct uts
10993  }
10994  
10995  static inline struct uts_namespace *copy_utsname(unsigned long flags,
10996 -                                                struct task_struct *tsk)
10997 +                                                struct uts_namespace *old_ns,
10998 +                                                struct user_namespace *user_ns)
10999  {
11000         if (flags & CLONE_NEWUTS)
11001                 return ERR_PTR(-EINVAL);
11002  
11003 -       return tsk->nsproxy->uts_ns;
11004 +       return old_ns;
11005  }
11006  #endif
11007  
11008 diff -NurpP --minimal linux-3.0.4/include/linux/vroot.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vroot.h
11009 --- linux-3.0.4/include/linux/vroot.h   1970-01-01 01:00:00.000000000 +0100
11010 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vroot.h   2011-06-10 22:11:24.000000000 +0200
11011 @@ -0,0 +1,51 @@
11012 +
11013 +/*
11014 + * include/linux/vroot.h
11015 + *
11016 + * written by Herbert Pötzl, 9/11/2002
11017 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
11018 + *
11019 + * Copyright (C) 2002-2007 by Herbert Pötzl.
11020 + * Redistribution of this file is permitted under the
11021 + * GNU General Public License.
11022 + */
11023 +
11024 +#ifndef _LINUX_VROOT_H
11025 +#define _LINUX_VROOT_H
11026 +
11027 +
11028 +#ifdef __KERNEL__
11029 +
11030 +/* Possible states of device */
11031 +enum {
11032 +       Vr_unbound,
11033 +       Vr_bound,
11034 +};
11035 +
11036 +struct vroot_device {
11037 +       int             vr_number;
11038 +       int             vr_refcnt;
11039 +
11040 +       struct semaphore        vr_ctl_mutex;
11041 +       struct block_device    *vr_device;
11042 +       int                     vr_state;
11043 +};
11044 +
11045 +
11046 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
11047 +
11048 +extern int register_vroot_grb(vroot_grb_func *);
11049 +extern int unregister_vroot_grb(vroot_grb_func *);
11050 +
11051 +#endif /* __KERNEL__ */
11052 +
11053 +#define MAX_VROOT_DEFAULT      8
11054 +
11055 +/*
11056 + * IOCTL commands --- we will commandeer 0x56 ('V')
11057 + */
11058 +
11059 +#define VROOT_SET_DEV          0x5600
11060 +#define VROOT_CLR_DEV          0x5601
11061 +
11062 +#endif /* _LINUX_VROOT_H */
11063 diff -NurpP --minimal linux-3.0.4/include/linux/vs_base.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_base.h
11064 --- linux-3.0.4/include/linux/vs_base.h 1970-01-01 01:00:00.000000000 +0100
11065 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_base.h 2011-06-10 22:11:24.000000000 +0200
11066 @@ -0,0 +1,10 @@
11067 +#ifndef _VS_BASE_H
11068 +#define _VS_BASE_H
11069 +
11070 +#include "vserver/base.h"
11071 +#include "vserver/check.h"
11072 +#include "vserver/debug.h"
11073 +
11074 +#else
11075 +#warning duplicate inclusion
11076 +#endif
11077 diff -NurpP --minimal linux-3.0.4/include/linux/vs_context.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_context.h
11078 --- linux-3.0.4/include/linux/vs_context.h      1970-01-01 01:00:00.000000000 +0100
11079 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_context.h      2011-06-10 22:11:24.000000000 +0200
11080 @@ -0,0 +1,242 @@
11081 +#ifndef _VS_CONTEXT_H
11082 +#define _VS_CONTEXT_H
11083 +
11084 +#include "vserver/base.h"
11085 +#include "vserver/check.h"
11086 +#include "vserver/context.h"
11087 +#include "vserver/history.h"
11088 +#include "vserver/debug.h"
11089 +
11090 +#include <linux/sched.h>
11091 +
11092 +
11093 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
11094 +
11095 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
11096 +       const char *_file, int _line, void *_here)
11097 +{
11098 +       if (!vxi)
11099 +               return NULL;
11100 +
11101 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
11102 +               vxi, vxi ? vxi->vx_id : 0,
11103 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11104 +               _file, _line);
11105 +       __vxh_get_vx_info(vxi, _here);
11106 +
11107 +       atomic_inc(&vxi->vx_usecnt);
11108 +       return vxi;
11109 +}
11110 +
11111 +
11112 +extern void free_vx_info(struct vx_info *);
11113 +
11114 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
11115 +
11116 +static inline void __put_vx_info(struct vx_info *vxi,
11117 +       const char *_file, int _line, void *_here)
11118 +{
11119 +       if (!vxi)
11120 +               return;
11121 +
11122 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
11123 +               vxi, vxi ? vxi->vx_id : 0,
11124 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11125 +               _file, _line);
11126 +       __vxh_put_vx_info(vxi, _here);
11127 +
11128 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
11129 +               free_vx_info(vxi);
11130 +}
11131 +
11132 +
11133 +#define init_vx_info(p, i) \
11134 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
11135 +
11136 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
11137 +       const char *_file, int _line, void *_here)
11138 +{
11139 +       if (vxi) {
11140 +               vxlprintk(VXD_CBIT(xid, 3),
11141 +                       "init_vx_info(%p[#%d.%d])",
11142 +                       vxi, vxi ? vxi->vx_id : 0,
11143 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11144 +                       _file, _line);
11145 +               __vxh_init_vx_info(vxi, vxp, _here);
11146 +
11147 +               atomic_inc(&vxi->vx_usecnt);
11148 +       }
11149 +       *vxp = vxi;
11150 +}
11151 +
11152 +
11153 +#define set_vx_info(p, i) \
11154 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
11155 +
11156 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
11157 +       const char *_file, int _line, void *_here)
11158 +{
11159 +       struct vx_info *vxo;
11160 +
11161 +       if (!vxi)
11162 +               return;
11163 +
11164 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
11165 +               vxi, vxi ? vxi->vx_id : 0,
11166 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11167 +               _file, _line);
11168 +       __vxh_set_vx_info(vxi, vxp, _here);
11169 +
11170 +       atomic_inc(&vxi->vx_usecnt);
11171 +       vxo = xchg(vxp, vxi);
11172 +       BUG_ON(vxo);
11173 +}
11174 +
11175 +
11176 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
11177 +
11178 +static inline void __clr_vx_info(struct vx_info **vxp,
11179 +       const char *_file, int _line, void *_here)
11180 +{
11181 +       struct vx_info *vxo;
11182 +
11183 +       vxo = xchg(vxp, NULL);
11184 +       if (!vxo)
11185 +               return;
11186 +
11187 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
11188 +               vxo, vxo ? vxo->vx_id : 0,
11189 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
11190 +               _file, _line);
11191 +       __vxh_clr_vx_info(vxo, vxp, _here);
11192 +
11193 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
11194 +               free_vx_info(vxo);
11195 +}
11196 +
11197 +
11198 +#define claim_vx_info(v, p) \
11199 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
11200 +
11201 +static inline void __claim_vx_info(struct vx_info *vxi,
11202 +       struct task_struct *task,
11203 +       const char *_file, int _line, void *_here)
11204 +{
11205 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
11206 +               vxi, vxi ? vxi->vx_id : 0,
11207 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11208 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
11209 +               task, _file, _line);
11210 +       __vxh_claim_vx_info(vxi, task, _here);
11211 +
11212 +       atomic_inc(&vxi->vx_tasks);
11213 +}
11214 +
11215 +
11216 +extern void unhash_vx_info(struct vx_info *);
11217 +
11218 +#define release_vx_info(v, p) \
11219 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
11220 +
11221 +static inline void __release_vx_info(struct vx_info *vxi,
11222 +       struct task_struct *task,
11223 +       const char *_file, int _line, void *_here)
11224 +{
11225 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
11226 +               vxi, vxi ? vxi->vx_id : 0,
11227 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11228 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
11229 +               task, _file, _line);
11230 +       __vxh_release_vx_info(vxi, task, _here);
11231 +
11232 +       might_sleep();
11233 +
11234 +       if (atomic_dec_and_test(&vxi->vx_tasks))
11235 +               unhash_vx_info(vxi);
11236 +}
11237 +
11238 +
11239 +#define task_get_vx_info(p) \
11240 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
11241 +
11242 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
11243 +       const char *_file, int _line, void *_here)
11244 +{
11245 +       struct vx_info *vxi;
11246 +
11247 +       task_lock(p);
11248 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
11249 +               p, _file, _line);
11250 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
11251 +       task_unlock(p);
11252 +       return vxi;
11253 +}
11254 +
11255 +
11256 +static inline void __wakeup_vx_info(struct vx_info *vxi)
11257 +{
11258 +       if (waitqueue_active(&vxi->vx_wait))
11259 +               wake_up_interruptible(&vxi->vx_wait);
11260 +}
11261 +
11262 +
11263 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
11264 +
11265 +static inline void __enter_vx_info(struct vx_info *vxi,
11266 +       struct vx_info_save *vxis, const char *_file, int _line)
11267 +{
11268 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
11269 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
11270 +               current->xid, current->vx_info, _file, _line);
11271 +       vxis->vxi = xchg(&current->vx_info, vxi);
11272 +       vxis->xid = current->xid;
11273 +       current->xid = vxi ? vxi->vx_id : 0;
11274 +}
11275 +
11276 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
11277 +
11278 +static inline void __leave_vx_info(struct vx_info_save *vxis,
11279 +       const char *_file, int _line)
11280 +{
11281 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
11282 +               vxis, vxis->xid, vxis->vxi, current,
11283 +               current->xid, current->vx_info, _file, _line);
11284 +       (void)xchg(&current->vx_info, vxis->vxi);
11285 +       current->xid = vxis->xid;
11286 +}
11287 +
11288 +
11289 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
11290 +{
11291 +       vxis->vxi = xchg(&current->vx_info, NULL);
11292 +       vxis->xid = xchg(&current->xid, (xid_t)0);
11293 +}
11294 +
11295 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
11296 +{
11297 +       (void)xchg(&current->xid, vxis->xid);
11298 +       (void)xchg(&current->vx_info, vxis->vxi);
11299 +}
11300 +
11301 +#define task_is_init(p) \
11302 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
11303 +
11304 +static inline int __task_is_init(struct task_struct *p,
11305 +       const char *_file, int _line, void *_here)
11306 +{
11307 +       int is_init = is_global_init(p);
11308 +
11309 +       task_lock(p);
11310 +       if (p->vx_info)
11311 +               is_init = p->vx_info->vx_initpid == p->pid;
11312 +       task_unlock(p);
11313 +       return is_init;
11314 +}
11315 +
11316 +extern void exit_vx_info(struct task_struct *, int);
11317 +extern void exit_vx_info_early(struct task_struct *, int);
11318 +
11319 +
11320 +#else
11321 +#warning duplicate inclusion
11322 +#endif
11323 diff -NurpP --minimal linux-3.0.4/include/linux/vs_cowbl.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_cowbl.h
11324 --- linux-3.0.4/include/linux/vs_cowbl.h        1970-01-01 01:00:00.000000000 +0100
11325 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_cowbl.h        2011-06-10 22:11:24.000000000 +0200
11326 @@ -0,0 +1,48 @@
11327 +#ifndef _VS_COWBL_H
11328 +#define _VS_COWBL_H
11329 +
11330 +#include <linux/fs.h>
11331 +#include <linux/dcache.h>
11332 +#include <linux/namei.h>
11333 +#include <linux/slab.h>
11334 +
11335 +extern struct dentry *cow_break_link(const char *pathname);
11336 +
11337 +static inline int cow_check_and_break(struct path *path)
11338 +{
11339 +       struct inode *inode = path->dentry->d_inode;
11340 +       int error = 0;
11341 +
11342 +       /* do we need this check? */
11343 +       if (IS_RDONLY(inode))
11344 +               return -EROFS;
11345 +
11346 +       if (IS_COW(inode)) {
11347 +               if (IS_COW_LINK(inode)) {
11348 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
11349 +                       char *pp, *buf;
11350 +
11351 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
11352 +                       if (!buf) {
11353 +                               return -ENOMEM;
11354 +                       }
11355 +                       pp = d_path(path, buf, PATH_MAX);
11356 +                       new_dentry = cow_break_link(pp);
11357 +                       kfree(buf);
11358 +                       if (!IS_ERR(new_dentry)) {
11359 +                               path->dentry = new_dentry;
11360 +                               dput(old_dentry);
11361 +                       } else
11362 +                               error = PTR_ERR(new_dentry);
11363 +               } else {
11364 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
11365 +                       inode->i_ctime = CURRENT_TIME;
11366 +                       mark_inode_dirty(inode);
11367 +               }
11368 +       }
11369 +       return error;
11370 +}
11371 +
11372 +#else
11373 +#warning duplicate inclusion
11374 +#endif
11375 diff -NurpP --minimal linux-3.0.4/include/linux/vs_cvirt.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_cvirt.h
11376 --- linux-3.0.4/include/linux/vs_cvirt.h        1970-01-01 01:00:00.000000000 +0100
11377 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_cvirt.h        2011-06-10 22:11:24.000000000 +0200
11378 @@ -0,0 +1,50 @@
11379 +#ifndef _VS_CVIRT_H
11380 +#define _VS_CVIRT_H
11381 +
11382 +#include "vserver/cvirt.h"
11383 +#include "vserver/context.h"
11384 +#include "vserver/base.h"
11385 +#include "vserver/check.h"
11386 +#include "vserver/debug.h"
11387 +
11388 +
11389 +static inline void vx_activate_task(struct task_struct *p)
11390 +{
11391 +       struct vx_info *vxi;
11392 +
11393 +       if ((vxi = p->vx_info)) {
11394 +               vx_update_load(vxi);
11395 +               atomic_inc(&vxi->cvirt.nr_running);
11396 +       }
11397 +}
11398 +
11399 +static inline void vx_deactivate_task(struct task_struct *p)
11400 +{
11401 +       struct vx_info *vxi;
11402 +
11403 +       if ((vxi = p->vx_info)) {
11404 +               vx_update_load(vxi);
11405 +               atomic_dec(&vxi->cvirt.nr_running);
11406 +       }
11407 +}
11408 +
11409 +static inline void vx_uninterruptible_inc(struct task_struct *p)
11410 +{
11411 +       struct vx_info *vxi;
11412 +
11413 +       if ((vxi = p->vx_info))
11414 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
11415 +}
11416 +
11417 +static inline void vx_uninterruptible_dec(struct task_struct *p)
11418 +{
11419 +       struct vx_info *vxi;
11420 +
11421 +       if ((vxi = p->vx_info))
11422 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
11423 +}
11424 +
11425 +
11426 +#else
11427 +#warning duplicate inclusion
11428 +#endif
11429 diff -NurpP --minimal linux-3.0.4/include/linux/vs_device.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_device.h
11430 --- linux-3.0.4/include/linux/vs_device.h       1970-01-01 01:00:00.000000000 +0100
11431 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_device.h       2011-06-10 22:11:24.000000000 +0200
11432 @@ -0,0 +1,45 @@
11433 +#ifndef _VS_DEVICE_H
11434 +#define _VS_DEVICE_H
11435 +
11436 +#include "vserver/base.h"
11437 +#include "vserver/device.h"
11438 +#include "vserver/debug.h"
11439 +
11440 +
11441 +#ifdef CONFIG_VSERVER_DEVICE
11442 +
11443 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
11444 +
11445 +#define vs_device_perm(v, d, m, p) \
11446 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
11447 +
11448 +#else
11449 +
11450 +static inline
11451 +int vs_map_device(struct vx_info *vxi,
11452 +       dev_t device, dev_t *target, umode_t mode)
11453 +{
11454 +       if (target)
11455 +               *target = device;
11456 +       return ~0;
11457 +}
11458 +
11459 +#define vs_device_perm(v, d, m, p) ((p) == (p))
11460 +
11461 +#endif
11462 +
11463 +
11464 +#define vs_map_chrdev(d, t, p) \
11465 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
11466 +#define vs_map_blkdev(d, t, p) \
11467 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
11468 +
11469 +#define vs_chrdev_perm(d, p) \
11470 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
11471 +#define vs_blkdev_perm(d, p) \
11472 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
11473 +
11474 +
11475 +#else
11476 +#warning duplicate inclusion
11477 +#endif
11478 diff -NurpP --minimal linux-3.0.4/include/linux/vs_dlimit.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_dlimit.h
11479 --- linux-3.0.4/include/linux/vs_dlimit.h       1970-01-01 01:00:00.000000000 +0100
11480 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_dlimit.h       2011-06-10 22:11:24.000000000 +0200
11481 @@ -0,0 +1,215 @@
11482 +#ifndef _VS_DLIMIT_H
11483 +#define _VS_DLIMIT_H
11484 +
11485 +#include <linux/fs.h>
11486 +
11487 +#include "vserver/dlimit.h"
11488 +#include "vserver/base.h"
11489 +#include "vserver/debug.h"
11490 +
11491 +
11492 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
11493 +
11494 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
11495 +       const char *_file, int _line)
11496 +{
11497 +       if (!dli)
11498 +               return NULL;
11499 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
11500 +               dli, dli ? dli->dl_tag : 0,
11501 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11502 +               _file, _line);
11503 +       atomic_inc(&dli->dl_usecnt);
11504 +       return dli;
11505 +}
11506 +
11507 +
11508 +#define free_dl_info(i) \
11509 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
11510 +
11511 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
11512 +
11513 +static inline void __put_dl_info(struct dl_info *dli,
11514 +       const char *_file, int _line)
11515 +{
11516 +       if (!dli)
11517 +               return;
11518 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
11519 +               dli, dli ? dli->dl_tag : 0,
11520 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11521 +               _file, _line);
11522 +       if (atomic_dec_and_test(&dli->dl_usecnt))
11523 +               free_dl_info(dli);
11524 +}
11525 +
11526 +
11527 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
11528 +
11529 +static inline int __dl_alloc_space(struct super_block *sb,
11530 +       tag_t tag, dlsize_t nr, const char *file, int line)
11531 +{
11532 +       struct dl_info *dli = NULL;
11533 +       int ret = 0;
11534 +
11535 +       if (nr == 0)
11536 +               goto out;
11537 +       dli = locate_dl_info(sb, tag);
11538 +       if (!dli)
11539 +               goto out;
11540 +
11541 +       spin_lock(&dli->dl_lock);
11542 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
11543 +       if (!ret)
11544 +               dli->dl_space_used += nr;
11545 +       spin_unlock(&dli->dl_lock);
11546 +       put_dl_info(dli);
11547 +out:
11548 +       vxlprintk(VXD_CBIT(dlim, 1),
11549 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
11550 +               sb, tag, __dlimit_char(dli), (long long)nr,
11551 +               ret, file, line);
11552 +       return ret ? -ENOSPC : 0;
11553 +}
11554 +
11555 +static inline void __dl_free_space(struct super_block *sb,
11556 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
11557 +{
11558 +       struct dl_info *dli = NULL;
11559 +
11560 +       if (nr == 0)
11561 +               goto out;
11562 +       dli = locate_dl_info(sb, tag);
11563 +       if (!dli)
11564 +               goto out;
11565 +
11566 +       spin_lock(&dli->dl_lock);
11567 +       if (dli->dl_space_used > nr)
11568 +               dli->dl_space_used -= nr;
11569 +       else
11570 +               dli->dl_space_used = 0;
11571 +       spin_unlock(&dli->dl_lock);
11572 +       put_dl_info(dli);
11573 +out:
11574 +       vxlprintk(VXD_CBIT(dlim, 1),
11575 +               "FREE  (%p,#%d)%c %lld bytes",
11576 +               sb, tag, __dlimit_char(dli), (long long)nr,
11577 +               _file, _line);
11578 +}
11579 +
11580 +static inline int __dl_alloc_inode(struct super_block *sb,
11581 +       tag_t tag, const char *_file, int _line)
11582 +{
11583 +       struct dl_info *dli;
11584 +       int ret = 0;
11585 +
11586 +       dli = locate_dl_info(sb, tag);
11587 +       if (!dli)
11588 +               goto out;
11589 +
11590 +       spin_lock(&dli->dl_lock);
11591 +       dli->dl_inodes_used++;
11592 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
11593 +       spin_unlock(&dli->dl_lock);
11594 +       put_dl_info(dli);
11595 +out:
11596 +       vxlprintk(VXD_CBIT(dlim, 0),
11597 +               "ALLOC (%p,#%d)%c inode (%d)",
11598 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
11599 +       return ret ? -ENOSPC : 0;
11600 +}
11601 +
11602 +static inline void __dl_free_inode(struct super_block *sb,
11603 +       tag_t tag, const char *_file, int _line)
11604 +{
11605 +       struct dl_info *dli;
11606 +
11607 +       dli = locate_dl_info(sb, tag);
11608 +       if (!dli)
11609 +               goto out;
11610 +
11611 +       spin_lock(&dli->dl_lock);
11612 +       if (dli->dl_inodes_used > 1)
11613 +               dli->dl_inodes_used--;
11614 +       else
11615 +               dli->dl_inodes_used = 0;
11616 +       spin_unlock(&dli->dl_lock);
11617 +       put_dl_info(dli);
11618 +out:
11619 +       vxlprintk(VXD_CBIT(dlim, 0),
11620 +               "FREE  (%p,#%d)%c inode",
11621 +               sb, tag, __dlimit_char(dli), _file, _line);
11622 +}
11623 +
11624 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
11625 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
11626 +       const char *_file, int _line)
11627 +{
11628 +       struct dl_info *dli;
11629 +       uint64_t broot, bfree;
11630 +
11631 +       dli = locate_dl_info(sb, tag);
11632 +       if (!dli)
11633 +               return;
11634 +
11635 +       spin_lock(&dli->dl_lock);
11636 +       broot = (dli->dl_space_total -
11637 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
11638 +               >> sb->s_blocksize_bits;
11639 +       bfree = (dli->dl_space_total - dli->dl_space_used)
11640 +                       >> sb->s_blocksize_bits;
11641 +       spin_unlock(&dli->dl_lock);
11642 +
11643 +       vxlprintk(VXD_CBIT(dlim, 2),
11644 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
11645 +               (long long)bfree, (long long)broot,
11646 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
11647 +               _file, _line);
11648 +       if (free_blocks) {
11649 +               if (*free_blocks > bfree)
11650 +                       *free_blocks = bfree;
11651 +       }
11652 +       if (root_blocks) {
11653 +               if (*root_blocks > broot)
11654 +                       *root_blocks = broot;
11655 +       }
11656 +       put_dl_info(dli);
11657 +}
11658 +
11659 +#define dl_prealloc_space(in, bytes) \
11660 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11661 +               __FILE__, __LINE__ )
11662 +
11663 +#define dl_alloc_space(in, bytes) \
11664 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11665 +               __FILE__, __LINE__ )
11666 +
11667 +#define dl_reserve_space(in, bytes) \
11668 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11669 +               __FILE__, __LINE__ )
11670 +
11671 +#define dl_claim_space(in, bytes) (0)
11672 +
11673 +#define dl_release_space(in, bytes) \
11674 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11675 +               __FILE__, __LINE__ )
11676 +
11677 +#define dl_free_space(in, bytes) \
11678 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11679 +               __FILE__, __LINE__ )
11680 +
11681 +
11682 +
11683 +#define dl_alloc_inode(in) \
11684 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11685 +
11686 +#define dl_free_inode(in) \
11687 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11688 +
11689 +
11690 +#define dl_adjust_block(sb, tag, fb, rb) \
11691 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
11692 +
11693 +
11694 +#else
11695 +#warning duplicate inclusion
11696 +#endif
11697 diff -NurpP --minimal linux-3.0.4/include/linux/vs_inet.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_inet.h
11698 --- linux-3.0.4/include/linux/vs_inet.h 1970-01-01 01:00:00.000000000 +0100
11699 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_inet.h 2011-08-18 17:01:00.000000000 +0200
11700 @@ -0,0 +1,353 @@
11701 +#ifndef _VS_INET_H
11702 +#define _VS_INET_H
11703 +
11704 +#include "vserver/base.h"
11705 +#include "vserver/network.h"
11706 +#include "vserver/debug.h"
11707 +
11708 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
11709 +
11710 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
11711 +                       NIPQUAD((a)->mask), (a)->type
11712 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
11713 +
11714 +#define NIPQUAD(addr) \
11715 +       ((unsigned char *)&addr)[0], \
11716 +       ((unsigned char *)&addr)[1], \
11717 +       ((unsigned char *)&addr)[2], \
11718 +       ((unsigned char *)&addr)[3]
11719 +
11720 +#define NIPQUAD_FMT "%u.%u.%u.%u"
11721 +
11722 +
11723 +static inline
11724 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
11725 +{
11726 +       __be32 ip = nxa->ip[0].s_addr;
11727 +       __be32 mask = nxa->mask.s_addr;
11728 +       __be32 bcast = ip | ~mask;
11729 +       int ret = 0;
11730 +
11731 +       switch (nxa->type & tmask) {
11732 +       case NXA_TYPE_MASK:
11733 +               ret = (ip == (addr & mask));
11734 +               break;
11735 +       case NXA_TYPE_ADDR:
11736 +               ret = 3;
11737 +               if (addr == ip)
11738 +                       break;
11739 +               /* fall through to broadcast */
11740 +       case NXA_MOD_BCAST:
11741 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
11742 +               break;
11743 +       case NXA_TYPE_RANGE:
11744 +               ret = ((nxa->ip[0].s_addr <= addr) &&
11745 +                       (nxa->ip[1].s_addr > addr));
11746 +               break;
11747 +       case NXA_TYPE_ANY:
11748 +               ret = 2;
11749 +               break;
11750 +       }
11751 +
11752 +       vxdprintk(VXD_CBIT(net, 0),
11753 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
11754 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
11755 +       return ret;
11756 +}
11757 +
11758 +static inline
11759 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
11760 +{
11761 +       struct nx_addr_v4 *nxa;
11762 +       int ret = 1;
11763 +
11764 +       if (!nxi)
11765 +               goto out;
11766 +
11767 +       ret = 2;
11768 +       /* allow 127.0.0.1 when remapping lback */
11769 +       if ((tmask & NXA_LOOPBACK) &&
11770 +               (addr == IPI_LOOPBACK) &&
11771 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
11772 +               goto out;
11773 +       ret = 3;
11774 +       /* check for lback address */
11775 +       if ((tmask & NXA_MOD_LBACK) &&
11776 +               (nxi->v4_lback.s_addr == addr))
11777 +               goto out;
11778 +       ret = 4;
11779 +       /* check for broadcast address */
11780 +       if ((tmask & NXA_MOD_BCAST) &&
11781 +               (nxi->v4_bcast.s_addr == addr))
11782 +               goto out;
11783 +       ret = 5;
11784 +       /* check for v4 addresses */
11785 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
11786 +               if (v4_addr_match(nxa, addr, tmask))
11787 +                       goto out;
11788 +       ret = 0;
11789 +out:
11790 +       vxdprintk(VXD_CBIT(net, 0),
11791 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
11792 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
11793 +       return ret;
11794 +}
11795 +
11796 +static inline
11797 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
11798 +{
11799 +       /* FIXME: needs full range checks */
11800 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
11801 +}
11802 +
11803 +static inline
11804 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
11805 +{
11806 +       struct nx_addr_v4 *ptr;
11807 +
11808 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
11809 +               if (v4_nx_addr_match(ptr, nxa, mask))
11810 +                       return 1;
11811 +       return 0;
11812 +}
11813 +
11814 +#include <net/inet_sock.h>
11815 +
11816 +/*
11817 + *     Check if a given address matches for a socket
11818 + *
11819 + *     nxi:            the socket's nx_info if any
11820 + *     addr:           to be verified address
11821 + */
11822 +static inline
11823 +int v4_sock_addr_match (
11824 +       struct nx_info *nxi,
11825 +       struct inet_sock *inet,
11826 +       __be32 addr)
11827 +{
11828 +       __be32 saddr = inet->inet_rcv_saddr;
11829 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
11830 +
11831 +       if (addr && (saddr == addr || bcast == addr))
11832 +               return 1;
11833 +       if (!saddr)
11834 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
11835 +       return 0;
11836 +}
11837 +
11838 +
11839 +/* inet related checks and helpers */
11840 +
11841 +
11842 +struct in_ifaddr;
11843 +struct net_device;
11844 +struct sock;
11845 +
11846 +#ifdef CONFIG_INET
11847 +
11848 +#include <linux/netdevice.h>
11849 +#include <linux/inetdevice.h>
11850 +#include <net/inet_sock.h>
11851 +#include <net/inet_timewait_sock.h>
11852 +
11853 +
11854 +int dev_in_nx_info(struct net_device *, struct nx_info *);
11855 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
11856 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
11857 +
11858 +
11859 +/*
11860 + *     check if address is covered by socket
11861 + *
11862 + *     sk:     the socket to check against
11863 + *     addr:   the address in question (must be != 0)
11864 + */
11865 +
11866 +static inline
11867 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
11868 +{
11869 +       struct nx_info *nxi = sk->sk_nx_info;
11870 +       __be32 saddr = sk_rcv_saddr(sk);
11871 +
11872 +       vxdprintk(VXD_CBIT(net, 5),
11873 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
11874 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
11875 +               (sk->sk_socket?sk->sk_socket->flags:0));
11876 +
11877 +       if (saddr) {            /* direct address match */
11878 +               return v4_addr_match(nxa, saddr, -1);
11879 +       } else if (nxi) {       /* match against nx_info */
11880 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
11881 +       } else {                /* unrestricted any socket */
11882 +               return 1;
11883 +       }
11884 +}
11885 +
11886 +
11887 +
11888 +static inline
11889 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
11890 +{
11891 +       vxdprintk(VXD_CBIT(net, 1),
11892 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
11893 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
11894 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
11895 +
11896 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
11897 +               return 1;
11898 +       if (dev_in_nx_info(dev, nxi))
11899 +               return 1;
11900 +       return 0;
11901 +}
11902 +
11903 +
11904 +static inline
11905 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
11906 +{
11907 +       if (!nxi)
11908 +               return 1;
11909 +       if (!ifa)
11910 +               return 0;
11911 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
11912 +}
11913 +
11914 +static inline
11915 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
11916 +{
11917 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
11918 +               nxi, nxi ? nxi->nx_id : 0, ifa,
11919 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
11920 +
11921 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
11922 +               return 1;
11923 +       if (v4_ifa_in_nx_info(ifa, nxi))
11924 +               return 1;
11925 +       return 0;
11926 +}
11927 +
11928 +
11929 +struct nx_v4_sock_addr {
11930 +       __be32 saddr;   /* Address used for validation */
11931 +       __be32 baddr;   /* Address used for socket bind */
11932 +};
11933 +
11934 +static inline
11935 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
11936 +       struct nx_v4_sock_addr *nsa)
11937 +{
11938 +       struct sock *sk = &inet->sk;
11939 +       struct nx_info *nxi = sk->sk_nx_info;
11940 +       __be32 saddr = addr->sin_addr.s_addr;
11941 +       __be32 baddr = saddr;
11942 +
11943 +       vxdprintk(VXD_CBIT(net, 3),
11944 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
11945 +               sk, sk->sk_nx_info, sk->sk_socket,
11946 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
11947 +               NIPQUAD(saddr));
11948 +
11949 +       if (nxi) {
11950 +               if (saddr == INADDR_ANY) {
11951 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
11952 +                               baddr = nxi->v4.ip[0].s_addr;
11953 +               } else if (saddr == IPI_LOOPBACK) {
11954 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
11955 +                               baddr = nxi->v4_lback.s_addr;
11956 +               } else if (!ipv4_is_multicast(saddr) ||
11957 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
11958 +                       /* normal address bind */
11959 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
11960 +                               return -EADDRNOTAVAIL;
11961 +               }
11962 +       }
11963 +
11964 +       vxdprintk(VXD_CBIT(net, 3),
11965 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
11966 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
11967 +
11968 +       nsa->saddr = saddr;
11969 +       nsa->baddr = baddr;
11970 +       return 0;
11971 +}
11972 +
11973 +static inline
11974 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
11975 +{
11976 +       inet->inet_saddr = nsa->baddr;
11977 +       inet->inet_rcv_saddr = nsa->baddr;
11978 +}
11979 +
11980 +
11981 +/*
11982 + *      helper to simplify inet_lookup_listener
11983 + *
11984 + *      nxi:   the socket's nx_info if any
11985 + *      addr:  to be verified address
11986 + *      saddr: socket address
11987 + */
11988 +static inline int v4_inet_addr_match (
11989 +       struct nx_info *nxi,
11990 +       __be32 addr,
11991 +       __be32 saddr)
11992 +{
11993 +       if (addr && (saddr == addr))
11994 +               return 1;
11995 +       if (!saddr)
11996 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
11997 +       return 0;
11998 +}
11999 +
12000 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
12001 +{
12002 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
12003 +               (addr == nxi->v4_lback.s_addr))
12004 +               return IPI_LOOPBACK;
12005 +       return addr;
12006 +}
12007 +
12008 +static inline
12009 +int nx_info_has_v4(struct nx_info *nxi)
12010 +{
12011 +       if (!nxi)
12012 +               return 1;
12013 +       if (NX_IPV4(nxi))
12014 +               return 1;
12015 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12016 +               return 1;
12017 +       return 0;
12018 +}
12019 +
12020 +#else /* CONFIG_INET */
12021 +
12022 +static inline
12023 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
12024 +{
12025 +       return 1;
12026 +}
12027 +
12028 +static inline
12029 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
12030 +{
12031 +       return 1;
12032 +}
12033 +
12034 +static inline
12035 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
12036 +{
12037 +       return 1;
12038 +}
12039 +
12040 +static inline
12041 +int nx_info_has_v4(struct nx_info *nxi)
12042 +{
12043 +       return 0;
12044 +}
12045 +
12046 +#endif /* CONFIG_INET */
12047 +
12048 +#define current_nx_info_has_v4() \
12049 +       nx_info_has_v4(current_nx_info())
12050 +
12051 +#else
12052 +// #warning duplicate inclusion
12053 +#endif
12054 diff -NurpP --minimal linux-3.0.4/include/linux/vs_inet6.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_inet6.h
12055 --- linux-3.0.4/include/linux/vs_inet6.h        1970-01-01 01:00:00.000000000 +0100
12056 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_inet6.h        2011-06-10 22:11:24.000000000 +0200
12057 @@ -0,0 +1,246 @@
12058 +#ifndef _VS_INET6_H
12059 +#define _VS_INET6_H
12060 +
12061 +#include "vserver/base.h"
12062 +#include "vserver/network.h"
12063 +#include "vserver/debug.h"
12064 +
12065 +#include <net/ipv6.h>
12066 +
12067 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
12068 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
12069 +
12070 +
12071 +#ifdef CONFIG_IPV6
12072 +
12073 +static inline
12074 +int v6_addr_match(struct nx_addr_v6 *nxa,
12075 +       const struct in6_addr *addr, uint16_t mask)
12076 +{
12077 +       int ret = 0;
12078 +
12079 +       switch (nxa->type & mask) {
12080 +       case NXA_TYPE_MASK:
12081 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
12082 +               break;
12083 +       case NXA_TYPE_ADDR:
12084 +               ret = ipv6_addr_equal(&nxa->ip, addr);
12085 +               break;
12086 +       case NXA_TYPE_ANY:
12087 +               ret = 1;
12088 +               break;
12089 +       }
12090 +       vxdprintk(VXD_CBIT(net, 0),
12091 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
12092 +               nxa, NXAV6(nxa), addr, mask, ret);
12093 +       return ret;
12094 +}
12095 +
12096 +static inline
12097 +int v6_addr_in_nx_info(struct nx_info *nxi,
12098 +       const struct in6_addr *addr, uint16_t mask)
12099 +{
12100 +       struct nx_addr_v6 *nxa;
12101 +       int ret = 1;
12102 +
12103 +       if (!nxi)
12104 +               goto out;
12105 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
12106 +               if (v6_addr_match(nxa, addr, mask))
12107 +                       goto out;
12108 +       ret = 0;
12109 +out:
12110 +       vxdprintk(VXD_CBIT(net, 0),
12111 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
12112 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
12113 +       return ret;
12114 +}
12115 +
12116 +static inline
12117 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
12118 +{
12119 +       /* FIXME: needs full range checks */
12120 +       return v6_addr_match(nxa, &addr->ip, mask);
12121 +}
12122 +
12123 +static inline
12124 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
12125 +{
12126 +       struct nx_addr_v6 *ptr;
12127 +
12128 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
12129 +               if (v6_nx_addr_match(ptr, nxa, mask))
12130 +                       return 1;
12131 +       return 0;
12132 +}
12133 +
12134 +
12135 +/*
12136 + *     Check if a given address matches for a socket
12137 + *
12138 + *     nxi:            the socket's nx_info if any
12139 + *     addr:           to be verified address
12140 + */
12141 +static inline
12142 +int v6_sock_addr_match (
12143 +       struct nx_info *nxi,
12144 +       struct inet_sock *inet,
12145 +       struct in6_addr *addr)
12146 +{
12147 +       struct sock *sk = &inet->sk;
12148 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12149 +
12150 +       if (!ipv6_addr_any(addr) &&
12151 +               ipv6_addr_equal(saddr, addr))
12152 +               return 1;
12153 +       if (ipv6_addr_any(saddr))
12154 +               return v6_addr_in_nx_info(nxi, addr, -1);
12155 +       return 0;
12156 +}
12157 +
12158 +/*
12159 + *     check if address is covered by socket
12160 + *
12161 + *     sk:     the socket to check against
12162 + *     addr:   the address in question (must be != 0)
12163 + */
12164 +
12165 +static inline
12166 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
12167 +{
12168 +       struct nx_info *nxi = sk->sk_nx_info;
12169 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12170 +
12171 +       vxdprintk(VXD_CBIT(net, 5),
12172 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
12173 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
12174 +               (sk->sk_socket?sk->sk_socket->flags:0));
12175 +
12176 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
12177 +               return v6_addr_match(nxa, saddr, -1);
12178 +       } else if (nxi) {               /* match against nx_info */
12179 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
12180 +       } else {                        /* unrestricted any socket */
12181 +               return 1;
12182 +       }
12183 +}
12184 +
12185 +
12186 +/* inet related checks and helpers */
12187 +
12188 +
12189 +struct in_ifaddr;
12190 +struct net_device;
12191 +struct sock;
12192 +
12193 +
12194 +#include <linux/netdevice.h>
12195 +#include <linux/inetdevice.h>
12196 +#include <net/inet_timewait_sock.h>
12197 +
12198 +
12199 +int dev_in_nx_info(struct net_device *, struct nx_info *);
12200 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
12201 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
12202 +
12203 +
12204 +
12205 +static inline
12206 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
12207 +{
12208 +       if (!nxi)
12209 +               return 1;
12210 +       if (!ifa)
12211 +               return 0;
12212 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
12213 +}
12214 +
12215 +static inline
12216 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
12217 +{
12218 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
12219 +               nxi, nxi ? nxi->nx_id : 0, ifa,
12220 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
12221 +
12222 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
12223 +               return 1;
12224 +       if (v6_ifa_in_nx_info(ifa, nxi))
12225 +               return 1;
12226 +       return 0;
12227 +}
12228 +
12229 +
12230 +struct nx_v6_sock_addr {
12231 +       struct in6_addr saddr;  /* Address used for validation */
12232 +       struct in6_addr baddr;  /* Address used for socket bind */
12233 +};
12234 +
12235 +static inline
12236 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
12237 +       struct nx_v6_sock_addr *nsa)
12238 +{
12239 +       // struct sock *sk = &inet->sk;
12240 +       // struct nx_info *nxi = sk->sk_nx_info;
12241 +       struct in6_addr saddr = addr->sin6_addr;
12242 +       struct in6_addr baddr = saddr;
12243 +
12244 +       nsa->saddr = saddr;
12245 +       nsa->baddr = baddr;
12246 +       return 0;
12247 +}
12248 +
12249 +static inline
12250 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
12251 +{
12252 +       // struct sock *sk = &inet->sk;
12253 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
12254 +
12255 +       // *saddr = nsa->baddr;
12256 +       // inet->inet_saddr = nsa->baddr;
12257 +}
12258 +
12259 +static inline
12260 +int nx_info_has_v6(struct nx_info *nxi)
12261 +{
12262 +       if (!nxi)
12263 +               return 1;
12264 +       if (NX_IPV6(nxi))
12265 +               return 1;
12266 +       return 0;
12267 +}
12268 +
12269 +#else /* CONFIG_IPV6 */
12270 +
12271 +static inline
12272 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
12273 +{
12274 +       return 1;
12275 +}
12276 +
12277 +
12278 +static inline
12279 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
12280 +{
12281 +       return 1;
12282 +}
12283 +
12284 +static inline
12285 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
12286 +{
12287 +       return 1;
12288 +}
12289 +
12290 +static inline
12291 +int nx_info_has_v6(struct nx_info *nxi)
12292 +{
12293 +       return 0;
12294 +}
12295 +
12296 +#endif /* CONFIG_IPV6 */
12297 +
12298 +#define current_nx_info_has_v6() \
12299 +       nx_info_has_v6(current_nx_info())
12300 +
12301 +#else
12302 +#warning duplicate inclusion
12303 +#endif
12304 diff -NurpP --minimal linux-3.0.4/include/linux/vs_limit.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_limit.h
12305 --- linux-3.0.4/include/linux/vs_limit.h        1970-01-01 01:00:00.000000000 +0100
12306 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_limit.h        2011-06-10 22:11:24.000000000 +0200
12307 @@ -0,0 +1,140 @@
12308 +#ifndef _VS_LIMIT_H
12309 +#define _VS_LIMIT_H
12310 +
12311 +#include "vserver/limit.h"
12312 +#include "vserver/base.h"
12313 +#include "vserver/context.h"
12314 +#include "vserver/debug.h"
12315 +#include "vserver/context.h"
12316 +#include "vserver/limit_int.h"
12317 +
12318 +
12319 +#define vx_acc_cres(v, d, p, r) \
12320 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
12321 +
12322 +#define vx_acc_cres_cond(x, d, p, r) \
12323 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
12324 +       r, d, p, __FILE__, __LINE__)
12325 +
12326 +
12327 +#define vx_add_cres(v, a, p, r) \
12328 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
12329 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
12330 +
12331 +#define vx_add_cres_cond(x, a, p, r) \
12332 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
12333 +       r, a, p, __FILE__, __LINE__)
12334 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
12335 +
12336 +
12337 +/* process and file limits */
12338 +
12339 +#define vx_nproc_inc(p) \
12340 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
12341 +
12342 +#define vx_nproc_dec(p) \
12343 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
12344 +
12345 +#define vx_files_inc(f) \
12346 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
12347 +
12348 +#define vx_files_dec(f) \
12349 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
12350 +
12351 +#define vx_locks_inc(l) \
12352 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
12353 +
12354 +#define vx_locks_dec(l) \
12355 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
12356 +
12357 +#define vx_openfd_inc(f) \
12358 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
12359 +
12360 +#define vx_openfd_dec(f) \
12361 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
12362 +
12363 +
12364 +#define vx_cres_avail(v, n, r) \
12365 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
12366 +
12367 +
12368 +#define vx_nproc_avail(n) \
12369 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
12370 +
12371 +#define vx_files_avail(n) \
12372 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
12373 +
12374 +#define vx_locks_avail(n) \
12375 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
12376 +
12377 +#define vx_openfd_avail(n) \
12378 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
12379 +
12380 +
12381 +/* dentry limits */
12382 +
12383 +#define vx_dentry_inc(d) do {                                          \
12384 +       if ((d)->d_count == 1)                                          \
12385 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
12386 +       } while (0)
12387 +
12388 +#define vx_dentry_dec(d) do {                                          \
12389 +       if ((d)->d_count == 0)                                          \
12390 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
12391 +       } while (0)
12392 +
12393 +#define vx_dentry_avail(n) \
12394 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
12395 +
12396 +
12397 +/* socket limits */
12398 +
12399 +#define vx_sock_inc(s) \
12400 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
12401 +
12402 +#define vx_sock_dec(s) \
12403 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
12404 +
12405 +#define vx_sock_avail(n) \
12406 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
12407 +
12408 +
12409 +/* ipc resource limits */
12410 +
12411 +#define vx_ipcmsg_add(v, u, a) \
12412 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
12413 +
12414 +#define vx_ipcmsg_sub(v, u, a) \
12415 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
12416 +
12417 +#define vx_ipcmsg_avail(v, a) \
12418 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
12419 +
12420 +
12421 +#define vx_ipcshm_add(v, k, a) \
12422 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
12423 +
12424 +#define vx_ipcshm_sub(v, k, a) \
12425 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
12426 +
12427 +#define vx_ipcshm_avail(v, a) \
12428 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
12429 +
12430 +
12431 +#define vx_semary_inc(a) \
12432 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
12433 +
12434 +#define vx_semary_dec(a) \
12435 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
12436 +
12437 +
12438 +#define vx_nsems_add(a,n) \
12439 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
12440 +
12441 +#define vx_nsems_sub(a,n) \
12442 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
12443 +
12444 +
12445 +#else
12446 +#warning duplicate inclusion
12447 +#endif
12448 diff -NurpP --minimal linux-3.0.4/include/linux/vs_memory.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_memory.h
12449 --- linux-3.0.4/include/linux/vs_memory.h       1970-01-01 01:00:00.000000000 +0100
12450 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_memory.h       2011-06-10 22:11:24.000000000 +0200
12451 @@ -0,0 +1,58 @@
12452 +#ifndef _VS_MEMORY_H
12453 +#define _VS_MEMORY_H
12454 +
12455 +#include "vserver/limit.h"
12456 +#include "vserver/base.h"
12457 +#include "vserver/context.h"
12458 +#include "vserver/debug.h"
12459 +#include "vserver/context.h"
12460 +#include "vserver/limit_int.h"
12461 +
12462 +enum {
12463 +       VXPT_UNKNOWN = 0,
12464 +       VXPT_ANON,
12465 +       VXPT_NONE,
12466 +       VXPT_FILE,
12467 +       VXPT_SWAP,
12468 +       VXPT_WRITE
12469 +};
12470 +
12471 +#if 0
12472 +#define        vx_page_fault(mm, vma, type, ret)
12473 +#else
12474 +
12475 +static inline
12476 +void __vx_page_fault(struct mm_struct *mm,
12477 +       struct vm_area_struct *vma, int type, int ret)
12478 +{
12479 +       struct vx_info *vxi = mm->mm_vx_info;
12480 +       int what;
12481 +/*
12482 +       static char *page_type[6] =
12483 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
12484 +       static char *page_what[4] =
12485 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
12486 +*/
12487 +
12488 +       if (!vxi)
12489 +               return;
12490 +
12491 +       what = (ret & 0x3);
12492 +
12493 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
12494 +               type, what, ret, page_type[type], page_what[what]);
12495 +*/
12496 +       if (ret & VM_FAULT_WRITE)
12497 +               what |= 0x4;
12498 +       atomic_inc(&vxi->cacct.page[type][what]);
12499 +}
12500 +
12501 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
12502 +#endif
12503 +
12504 +
12505 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
12506 +
12507 +#else
12508 +#warning duplicate inclusion
12509 +#endif
12510 diff -NurpP --minimal linux-3.0.4/include/linux/vs_network.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_network.h
12511 --- linux-3.0.4/include/linux/vs_network.h      1970-01-01 01:00:00.000000000 +0100
12512 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_network.h      2011-06-10 22:11:24.000000000 +0200
12513 @@ -0,0 +1,169 @@
12514 +#ifndef _NX_VS_NETWORK_H
12515 +#define _NX_VS_NETWORK_H
12516 +
12517 +#include "vserver/context.h"
12518 +#include "vserver/network.h"
12519 +#include "vserver/base.h"
12520 +#include "vserver/check.h"
12521 +#include "vserver/debug.h"
12522 +
12523 +#include <linux/sched.h>
12524 +
12525 +
12526 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
12527 +
12528 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
12529 +       const char *_file, int _line)
12530 +{
12531 +       if (!nxi)
12532 +               return NULL;
12533 +
12534 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
12535 +               nxi, nxi ? nxi->nx_id : 0,
12536 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12537 +               _file, _line);
12538 +
12539 +       atomic_inc(&nxi->nx_usecnt);
12540 +       return nxi;
12541 +}
12542 +
12543 +
12544 +extern void free_nx_info(struct nx_info *);
12545 +
12546 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
12547 +
12548 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
12549 +{
12550 +       if (!nxi)
12551 +               return;
12552 +
12553 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
12554 +               nxi, nxi ? nxi->nx_id : 0,
12555 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12556 +               _file, _line);
12557 +
12558 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
12559 +               free_nx_info(nxi);
12560 +}
12561 +
12562 +
12563 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
12564 +
12565 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
12566 +               const char *_file, int _line)
12567 +{
12568 +       if (nxi) {
12569 +               vxlprintk(VXD_CBIT(nid, 3),
12570 +                       "init_nx_info(%p[#%d.%d])",
12571 +                       nxi, nxi ? nxi->nx_id : 0,
12572 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12573 +                       _file, _line);
12574 +
12575 +               atomic_inc(&nxi->nx_usecnt);
12576 +       }
12577 +       *nxp = nxi;
12578 +}
12579 +
12580 +
12581 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
12582 +
12583 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
12584 +       const char *_file, int _line)
12585 +{
12586 +       struct nx_info *nxo;
12587 +
12588 +       if (!nxi)
12589 +               return;
12590 +
12591 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
12592 +               nxi, nxi ? nxi->nx_id : 0,
12593 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12594 +               _file, _line);
12595 +
12596 +       atomic_inc(&nxi->nx_usecnt);
12597 +       nxo = xchg(nxp, nxi);
12598 +       BUG_ON(nxo);
12599 +}
12600 +
12601 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
12602 +
12603 +static inline void __clr_nx_info(struct nx_info **nxp,
12604 +       const char *_file, int _line)
12605 +{
12606 +       struct nx_info *nxo;
12607 +
12608 +       nxo = xchg(nxp, NULL);
12609 +       if (!nxo)
12610 +               return;
12611 +
12612 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
12613 +               nxo, nxo ? nxo->nx_id : 0,
12614 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
12615 +               _file, _line);
12616 +
12617 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
12618 +               free_nx_info(nxo);
12619 +}
12620 +
12621 +
12622 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
12623 +
12624 +static inline void __claim_nx_info(struct nx_info *nxi,
12625 +       struct task_struct *task, const char *_file, int _line)
12626 +{
12627 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
12628 +               nxi, nxi ? nxi->nx_id : 0,
12629 +               nxi?atomic_read(&nxi->nx_usecnt):0,
12630 +               nxi?atomic_read(&nxi->nx_tasks):0,
12631 +               task, _file, _line);
12632 +
12633 +       atomic_inc(&nxi->nx_tasks);
12634 +}
12635 +
12636 +
12637 +extern void unhash_nx_info(struct nx_info *);
12638 +
12639 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
12640 +
12641 +static inline void __release_nx_info(struct nx_info *nxi,
12642 +       struct task_struct *task, const char *_file, int _line)
12643 +{
12644 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
12645 +               nxi, nxi ? nxi->nx_id : 0,
12646 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12647 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
12648 +               task, _file, _line);
12649 +
12650 +       might_sleep();
12651 +
12652 +       if (atomic_dec_and_test(&nxi->nx_tasks))
12653 +               unhash_nx_info(nxi);
12654 +}
12655 +
12656 +
12657 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
12658 +
12659 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
12660 +       const char *_file, int _line)
12661 +{
12662 +       struct nx_info *nxi;
12663 +
12664 +       task_lock(p);
12665 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
12666 +               p, _file, _line);
12667 +       nxi = __get_nx_info(p->nx_info, _file, _line);
12668 +       task_unlock(p);
12669 +       return nxi;
12670 +}
12671 +
12672 +
12673 +static inline void exit_nx_info(struct task_struct *p)
12674 +{
12675 +       if (p->nx_info)
12676 +               release_nx_info(p->nx_info, p);
12677 +}
12678 +
12679 +
12680 +#else
12681 +#warning duplicate inclusion
12682 +#endif
12683 diff -NurpP --minimal linux-3.0.4/include/linux/vs_pid.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_pid.h
12684 --- linux-3.0.4/include/linux/vs_pid.h  1970-01-01 01:00:00.000000000 +0100
12685 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_pid.h  2011-06-10 22:11:24.000000000 +0200
12686 @@ -0,0 +1,50 @@
12687 +#ifndef _VS_PID_H
12688 +#define _VS_PID_H
12689 +
12690 +#include "vserver/base.h"
12691 +#include "vserver/check.h"
12692 +#include "vserver/context.h"
12693 +#include "vserver/debug.h"
12694 +#include "vserver/pid.h"
12695 +#include <linux/pid_namespace.h>
12696 +
12697 +
12698 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
12699 +
12700 +static inline
12701 +int vx_proc_task_visible(struct task_struct *task)
12702 +{
12703 +       if ((task->pid == 1) &&
12704 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
12705 +               /* show a blend through init */
12706 +               goto visible;
12707 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
12708 +               goto visible;
12709 +       return 0;
12710 +visible:
12711 +       return 1;
12712 +}
12713 +
12714 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
12715 +
12716 +
12717 +static inline
12718 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
12719 +{
12720 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
12721 +
12722 +       if (task && !vx_proc_task_visible(task)) {
12723 +               vxdprintk(VXD_CBIT(misc, 6),
12724 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
12725 +                       task, task->xid, task->pid,
12726 +                       current, current->xid, current->pid);
12727 +               put_task_struct(task);
12728 +               task = NULL;
12729 +       }
12730 +       return task;
12731 +}
12732 +
12733 +
12734 +#else
12735 +#warning duplicate inclusion
12736 +#endif
12737 diff -NurpP --minimal linux-3.0.4/include/linux/vs_sched.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_sched.h
12738 --- linux-3.0.4/include/linux/vs_sched.h        1970-01-01 01:00:00.000000000 +0100
12739 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_sched.h        2011-06-10 22:11:24.000000000 +0200
12740 @@ -0,0 +1,40 @@
12741 +#ifndef _VS_SCHED_H
12742 +#define _VS_SCHED_H
12743 +
12744 +#include "vserver/base.h"
12745 +#include "vserver/context.h"
12746 +#include "vserver/sched.h"
12747 +
12748 +
12749 +#define MAX_PRIO_BIAS           20
12750 +#define MIN_PRIO_BIAS          -20
12751 +
12752 +static inline
12753 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
12754 +{
12755 +       struct vx_info *vxi = p->vx_info;
12756 +
12757 +       if (vxi)
12758 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
12759 +       return prio;
12760 +}
12761 +
12762 +static inline void vx_account_user(struct vx_info *vxi,
12763 +       cputime_t cputime, int nice)
12764 +{
12765 +       if (!vxi)
12766 +               return;
12767 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
12768 +}
12769 +
12770 +static inline void vx_account_system(struct vx_info *vxi,
12771 +       cputime_t cputime, int idle)
12772 +{
12773 +       if (!vxi)
12774 +               return;
12775 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
12776 +}
12777 +
12778 +#else
12779 +#warning duplicate inclusion
12780 +#endif
12781 diff -NurpP --minimal linux-3.0.4/include/linux/vs_socket.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_socket.h
12782 --- linux-3.0.4/include/linux/vs_socket.h       1970-01-01 01:00:00.000000000 +0100
12783 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_socket.h       2011-06-10 22:11:24.000000000 +0200
12784 @@ -0,0 +1,67 @@
12785 +#ifndef _VS_SOCKET_H
12786 +#define _VS_SOCKET_H
12787 +
12788 +#include "vserver/debug.h"
12789 +#include "vserver/base.h"
12790 +#include "vserver/cacct.h"
12791 +#include "vserver/context.h"
12792 +#include "vserver/tag.h"
12793 +
12794 +
12795 +/* socket accounting */
12796 +
12797 +#include <linux/socket.h>
12798 +
12799 +static inline int vx_sock_type(int family)
12800 +{
12801 +       switch (family) {
12802 +       case PF_UNSPEC:
12803 +               return VXA_SOCK_UNSPEC;
12804 +       case PF_UNIX:
12805 +               return VXA_SOCK_UNIX;
12806 +       case PF_INET:
12807 +               return VXA_SOCK_INET;
12808 +       case PF_INET6:
12809 +               return VXA_SOCK_INET6;
12810 +       case PF_PACKET:
12811 +               return VXA_SOCK_PACKET;
12812 +       default:
12813 +               return VXA_SOCK_OTHER;
12814 +       }
12815 +}
12816 +
12817 +#define vx_acc_sock(v, f, p, s) \
12818 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
12819 +
12820 +static inline void __vx_acc_sock(struct vx_info *vxi,
12821 +       int family, int pos, int size, char *file, int line)
12822 +{
12823 +       if (vxi) {
12824 +               int type = vx_sock_type(family);
12825 +
12826 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
12827 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
12828 +       }
12829 +}
12830 +
12831 +#define vx_sock_recv(sk, s) \
12832 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
12833 +#define vx_sock_send(sk, s) \
12834 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
12835 +#define vx_sock_fail(sk, s) \
12836 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
12837 +
12838 +
12839 +#define sock_vx_init(s) do {           \
12840 +       (s)->sk_xid = 0;                \
12841 +       (s)->sk_vx_info = NULL;         \
12842 +       } while (0)
12843 +
12844 +#define sock_nx_init(s) do {           \
12845 +       (s)->sk_nid = 0;                \
12846 +       (s)->sk_nx_info = NULL;         \
12847 +       } while (0)
12848 +
12849 +#else
12850 +#warning duplicate inclusion
12851 +#endif
12852 diff -NurpP --minimal linux-3.0.4/include/linux/vs_tag.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_tag.h
12853 --- linux-3.0.4/include/linux/vs_tag.h  1970-01-01 01:00:00.000000000 +0100
12854 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_tag.h  2011-06-10 22:11:24.000000000 +0200
12855 @@ -0,0 +1,47 @@
12856 +#ifndef _VS_TAG_H
12857 +#define _VS_TAG_H
12858 +
12859 +#include <linux/vserver/tag.h>
12860 +
12861 +/* check conditions */
12862 +
12863 +#define DX_ADMIN       0x0001
12864 +#define DX_WATCH       0x0002
12865 +#define DX_HOSTID      0x0008
12866 +
12867 +#define DX_IDENT       0x0010
12868 +
12869 +#define DX_ARG_MASK    0x0010
12870 +
12871 +
12872 +#define dx_task_tag(t) ((t)->tag)
12873 +
12874 +#define dx_current_tag() dx_task_tag(current)
12875 +
12876 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
12877 +
12878 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
12879 +
12880 +
12881 +/*
12882 + * check current context for ADMIN/WATCH and
12883 + * optionally against supplied argument
12884 + */
12885 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
12886 +{
12887 +       if (mode & DX_ARG_MASK) {
12888 +               if ((mode & DX_IDENT) && (id == cid))
12889 +                       return 1;
12890 +       }
12891 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
12892 +               ((mode & DX_WATCH) && (cid == 1)) ||
12893 +               ((mode & DX_HOSTID) && (id == 0)));
12894 +}
12895 +
12896 +struct inode;
12897 +int dx_permission(const struct inode *inode, int mask);
12898 +
12899 +
12900 +#else
12901 +#warning duplicate inclusion
12902 +#endif
12903 diff -NurpP --minimal linux-3.0.4/include/linux/vs_time.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_time.h
12904 --- linux-3.0.4/include/linux/vs_time.h 1970-01-01 01:00:00.000000000 +0100
12905 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vs_time.h 2011-06-13 14:57:45.000000000 +0200
12906 @@ -0,0 +1,19 @@
12907 +#ifndef _VS_TIME_H
12908 +#define _VS_TIME_H
12909 +
12910 +
12911 +/* time faking stuff */
12912 +
12913 +#ifdef CONFIG_VSERVER_VTIME
12914 +
12915 +extern void vx_adjust_timespec(struct timespec *ts);
12916 +extern int vx_settimeofday(const struct timespec *ts);
12917 +
12918 +#else
12919 +#define        vx_adjust_timespec(t)   do { } while (0)
12920 +#define        vx_settimeofday(t)      do_settimeofday(t)
12921 +#endif
12922 +
12923 +#else
12924 +#warning duplicate inclusion
12925 +#endif
12926 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/Kbuild linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/Kbuild
12927 --- linux-3.0.4/include/linux/vserver/Kbuild    1970-01-01 01:00:00.000000000 +0100
12928 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/Kbuild    2011-08-08 18:02:46.000000000 +0200
12929 @@ -0,0 +1,8 @@
12930 +
12931 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12932 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12933 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12934 +       debug_cmd.h device_cmd.h
12935 +
12936 +header-y += switch.h network.h monitor.h inode.h device.h
12937 +
12938 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/base.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/base.h
12939 --- linux-3.0.4/include/linux/vserver/base.h    1970-01-01 01:00:00.000000000 +0100
12940 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/base.h    2011-08-01 18:26:07.000000000 +0200
12941 @@ -0,0 +1,178 @@
12942 +#ifndef _VX_BASE_H
12943 +#define _VX_BASE_H
12944 +
12945 +
12946 +/* context state changes */
12947 +
12948 +enum {
12949 +       VSC_STARTUP = 1,
12950 +       VSC_SHUTDOWN,
12951 +
12952 +       VSC_NETUP,
12953 +       VSC_NETDOWN,
12954 +};
12955 +
12956 +
12957 +
12958 +#define vx_task_xid(t) ((t)->xid)
12959 +
12960 +#define vx_current_xid() vx_task_xid(current)
12961 +
12962 +#define current_vx_info() (current->vx_info)
12963 +
12964 +
12965 +#define nx_task_nid(t) ((t)->nid)
12966 +
12967 +#define nx_current_nid() nx_task_nid(current)
12968 +
12969 +#define current_nx_info() (current->nx_info)
12970 +
12971 +
12972 +/* generic flag merging */
12973 +
12974 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
12975 +
12976 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
12977 +
12978 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
12979 +
12980 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
12981 +
12982 +
12983 +/* context flags */
12984 +
12985 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
12986 +
12987 +#define vx_current_flags()     __vx_flags(current_vx_info())
12988 +
12989 +#define vx_info_flags(v, m, f) \
12990 +       vs_check_flags(__vx_flags(v), m, f)
12991 +
12992 +#define task_vx_flags(t, m, f) \
12993 +       ((t) && vx_info_flags((t)->vx_info, m, f))
12994 +
12995 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
12996 +
12997 +
12998 +/* context caps */
12999 +
13000 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
13001 +
13002 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
13003 +
13004 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
13005 +
13006 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
13007 +
13008 +
13009 +
13010 +/* network flags */
13011 +
13012 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
13013 +
13014 +#define nx_current_flags()     __nx_flags(current_nx_info())
13015 +
13016 +#define nx_info_flags(n, m, f) \
13017 +       vs_check_flags(__nx_flags(n), m, f)
13018 +
13019 +#define task_nx_flags(t, m, f) \
13020 +       ((t) && nx_info_flags((t)->nx_info, m, f))
13021 +
13022 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
13023 +
13024 +
13025 +/* network caps */
13026 +
13027 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
13028 +
13029 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
13030 +
13031 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
13032 +
13033 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
13034 +
13035 +
13036 +/* context mask capabilities */
13037 +
13038 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
13039 +
13040 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
13041 +
13042 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
13043 +
13044 +
13045 +/* context bcap mask */
13046 +
13047 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
13048 +
13049 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
13050 +
13051 +
13052 +/* mask given bcaps */
13053 +
13054 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
13055 +
13056 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
13057 +
13058 +
13059 +/* masked cap_bset */
13060 +
13061 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
13062 +
13063 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
13064 +
13065 +#if 0
13066 +#define vx_info_mbcap(v, b) \
13067 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
13068 +       vx_info_bcaps(v, b) : (b))
13069 +
13070 +#define task_vx_mbcap(t, b) \
13071 +       vx_info_mbcap((t)->vx_info, (t)->b)
13072 +
13073 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
13074 +#endif
13075 +
13076 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
13077 +
13078 +#define vx_capable(b, c) (capable(b) || \
13079 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
13080 +
13081 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
13082 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
13083 +
13084 +#define nx_capable(b, c) (capable(b) || \
13085 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
13086 +
13087 +#define vx_task_initpid(t, n) \
13088 +       ((t)->vx_info && \
13089 +       ((t)->vx_info->vx_initpid == (n)))
13090 +
13091 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
13092 +
13093 +
13094 +/* context unshare mask */
13095 +
13096 +#define __vx_umask(v)          ((v)->vx_umask)
13097 +
13098 +#define vx_current_umask()     __vx_umask(current_vx_info())
13099 +
13100 +#define vx_can_unshare(b, f) (capable(b) || \
13101 +       (cap_raised(current_cap(), b) && \
13102 +       !((f) & ~vx_current_umask())))
13103 +
13104 +
13105 +#define __vx_wmask(v)          ((v)->vx_wmask)
13106 +
13107 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
13108 +
13109 +
13110 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
13111 +
13112 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
13113 +
13114 +
13115 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
13116 +
13117 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
13118 +
13119 +#endif
13120 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/cacct.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cacct.h
13121 --- linux-3.0.4/include/linux/vserver/cacct.h   1970-01-01 01:00:00.000000000 +0100
13122 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cacct.h   2011-06-10 22:11:24.000000000 +0200
13123 @@ -0,0 +1,15 @@
13124 +#ifndef _VX_CACCT_H
13125 +#define _VX_CACCT_H
13126 +
13127 +
13128 +enum sock_acc_field {
13129 +       VXA_SOCK_UNSPEC = 0,
13130 +       VXA_SOCK_UNIX,
13131 +       VXA_SOCK_INET,
13132 +       VXA_SOCK_INET6,
13133 +       VXA_SOCK_PACKET,
13134 +       VXA_SOCK_OTHER,
13135 +       VXA_SOCK_SIZE   /* array size */
13136 +};
13137 +
13138 +#endif /* _VX_CACCT_H */
13139 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/cacct_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cacct_cmd.h
13140 --- linux-3.0.4/include/linux/vserver/cacct_cmd.h       1970-01-01 01:00:00.000000000 +0100
13141 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cacct_cmd.h       2011-06-10 22:11:24.000000000 +0200
13142 @@ -0,0 +1,23 @@
13143 +#ifndef _VX_CACCT_CMD_H
13144 +#define _VX_CACCT_CMD_H
13145 +
13146 +
13147 +/* virtual host info name commands */
13148 +
13149 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
13150 +
13151 +struct vcmd_sock_stat_v0 {
13152 +       uint32_t field;
13153 +       uint32_t count[3];
13154 +       uint64_t total[3];
13155 +};
13156 +
13157 +
13158 +#ifdef __KERNEL__
13159 +
13160 +#include <linux/compiler.h>
13161 +
13162 +extern int vc_sock_stat(struct vx_info *, void __user *);
13163 +
13164 +#endif /* __KERNEL__ */
13165 +#endif /* _VX_CACCT_CMD_H */
13166 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/cacct_def.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cacct_def.h
13167 --- linux-3.0.4/include/linux/vserver/cacct_def.h       1970-01-01 01:00:00.000000000 +0100
13168 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cacct_def.h       2011-06-10 22:11:24.000000000 +0200
13169 @@ -0,0 +1,43 @@
13170 +#ifndef _VX_CACCT_DEF_H
13171 +#define _VX_CACCT_DEF_H
13172 +
13173 +#include <asm/atomic.h>
13174 +#include <linux/vserver/cacct.h>
13175 +
13176 +
13177 +struct _vx_sock_acc {
13178 +       atomic_long_t count;
13179 +       atomic_long_t total;
13180 +};
13181 +
13182 +/* context sub struct */
13183 +
13184 +struct _vx_cacct {
13185 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
13186 +       atomic_t slab[8];
13187 +       atomic_t page[6][8];
13188 +};
13189 +
13190 +#ifdef CONFIG_VSERVER_DEBUG
13191 +
13192 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
13193 +{
13194 +       int i, j;
13195 +
13196 +       printk("\t_vx_cacct:");
13197 +       for (i = 0; i < 6; i++) {
13198 +               struct _vx_sock_acc *ptr = cacct->sock[i];
13199 +
13200 +               printk("\t [%d] =", i);
13201 +               for (j = 0; j < 3; j++) {
13202 +                       printk(" [%d] = %8lu, %8lu", j,
13203 +                               atomic_long_read(&ptr[j].count),
13204 +                               atomic_long_read(&ptr[j].total));
13205 +               }
13206 +               printk("\n");
13207 +       }
13208 +}
13209 +
13210 +#endif
13211 +
13212 +#endif /* _VX_CACCT_DEF_H */
13213 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/cacct_int.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cacct_int.h
13214 --- linux-3.0.4/include/linux/vserver/cacct_int.h       1970-01-01 01:00:00.000000000 +0100
13215 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cacct_int.h       2011-06-10 22:11:24.000000000 +0200
13216 @@ -0,0 +1,21 @@
13217 +#ifndef _VX_CACCT_INT_H
13218 +#define _VX_CACCT_INT_H
13219 +
13220 +
13221 +#ifdef __KERNEL__
13222 +
13223 +static inline
13224 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
13225 +{
13226 +       return atomic_long_read(&cacct->sock[type][pos].count);
13227 +}
13228 +
13229 +
13230 +static inline
13231 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
13232 +{
13233 +       return atomic_long_read(&cacct->sock[type][pos].total);
13234 +}
13235 +
13236 +#endif /* __KERNEL__ */
13237 +#endif /* _VX_CACCT_INT_H */
13238 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/check.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/check.h
13239 --- linux-3.0.4/include/linux/vserver/check.h   1970-01-01 01:00:00.000000000 +0100
13240 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/check.h   2011-06-10 22:11:24.000000000 +0200
13241 @@ -0,0 +1,89 @@
13242 +#ifndef _VS_CHECK_H
13243 +#define _VS_CHECK_H
13244 +
13245 +
13246 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
13247 +
13248 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
13249 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
13250 +#else
13251 +#define MIN_D_CONTEXT  65536
13252 +#endif
13253 +
13254 +/* check conditions */
13255 +
13256 +#define VS_ADMIN       0x0001
13257 +#define VS_WATCH       0x0002
13258 +#define VS_HIDE                0x0004
13259 +#define VS_HOSTID      0x0008
13260 +
13261 +#define VS_IDENT       0x0010
13262 +#define VS_EQUIV       0x0020
13263 +#define VS_PARENT      0x0040
13264 +#define VS_CHILD       0x0080
13265 +
13266 +#define VS_ARG_MASK    0x00F0
13267 +
13268 +#define VS_DYNAMIC     0x0100
13269 +#define VS_STATIC      0x0200
13270 +
13271 +#define VS_ATR_MASK    0x0F00
13272 +
13273 +#ifdef CONFIG_VSERVER_PRIVACY
13274 +#define VS_ADMIN_P     (0)
13275 +#define VS_WATCH_P     (0)
13276 +#else
13277 +#define VS_ADMIN_P     VS_ADMIN
13278 +#define VS_WATCH_P     VS_WATCH
13279 +#endif
13280 +
13281 +#define VS_HARDIRQ     0x1000
13282 +#define VS_SOFTIRQ     0x2000
13283 +#define VS_IRQ         0x4000
13284 +
13285 +#define VS_IRQ_MASK    0xF000
13286 +
13287 +#include <linux/hardirq.h>
13288 +
13289 +/*
13290 + * check current context for ADMIN/WATCH and
13291 + * optionally against supplied argument
13292 + */
13293 +static inline int __vs_check(int cid, int id, unsigned int mode)
13294 +{
13295 +       if (mode & VS_ARG_MASK) {
13296 +               if ((mode & VS_IDENT) && (id == cid))
13297 +                       return 1;
13298 +       }
13299 +       if (mode & VS_ATR_MASK) {
13300 +               if ((mode & VS_DYNAMIC) &&
13301 +                       (id >= MIN_D_CONTEXT) &&
13302 +                       (id <= MAX_S_CONTEXT))
13303 +                       return 1;
13304 +               if ((mode & VS_STATIC) &&
13305 +                       (id > 1) && (id < MIN_D_CONTEXT))
13306 +                       return 1;
13307 +       }
13308 +       if (mode & VS_IRQ_MASK) {
13309 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
13310 +                       return 1;
13311 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
13312 +                       return 1;
13313 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
13314 +                       return 1;
13315 +       }
13316 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
13317 +               ((mode & VS_WATCH) && (cid == 1)) ||
13318 +               ((mode & VS_HOSTID) && (id == 0)));
13319 +}
13320 +
13321 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
13322 +
13323 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
13324 +
13325 +
13326 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
13327 +
13328 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
13329 +
13330 +#endif
13331 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/context.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/context.h
13332 --- linux-3.0.4/include/linux/vserver/context.h 1970-01-01 01:00:00.000000000 +0100
13333 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/context.h 2011-08-01 18:23:13.000000000 +0200
13334 @@ -0,0 +1,190 @@
13335 +#ifndef _VX_CONTEXT_H
13336 +#define _VX_CONTEXT_H
13337 +
13338 +#include <linux/types.h>
13339 +#include <linux/capability.h>
13340 +
13341 +
13342 +/* context flags */
13343 +
13344 +#define VXF_INFO_SCHED         0x00000002
13345 +#define VXF_INFO_NPROC         0x00000004
13346 +#define VXF_INFO_PRIVATE       0x00000008
13347 +
13348 +#define VXF_INFO_INIT          0x00000010
13349 +#define VXF_INFO_HIDE          0x00000020
13350 +#define VXF_INFO_ULIMIT                0x00000040
13351 +#define VXF_INFO_NSPACE                0x00000080
13352 +
13353 +#define VXF_SCHED_HARD         0x00000100
13354 +#define VXF_SCHED_PRIO         0x00000200
13355 +#define VXF_SCHED_PAUSE                0x00000400
13356 +
13357 +#define VXF_VIRT_MEM           0x00010000
13358 +#define VXF_VIRT_UPTIME                0x00020000
13359 +#define VXF_VIRT_CPU           0x00040000
13360 +#define VXF_VIRT_LOAD          0x00080000
13361 +#define VXF_VIRT_TIME          0x00100000
13362 +
13363 +#define VXF_HIDE_MOUNT         0x01000000
13364 +/* was VXF_HIDE_NETIF          0x02000000 */
13365 +#define VXF_HIDE_VINFO         0x04000000
13366 +
13367 +#define VXF_STATE_SETUP                (1ULL << 32)
13368 +#define VXF_STATE_INIT         (1ULL << 33)
13369 +#define VXF_STATE_ADMIN                (1ULL << 34)
13370 +
13371 +#define VXF_SC_HELPER          (1ULL << 36)
13372 +#define VXF_REBOOT_KILL                (1ULL << 37)
13373 +#define VXF_PERSISTENT         (1ULL << 38)
13374 +
13375 +#define VXF_FORK_RSS           (1ULL << 48)
13376 +#define VXF_PROLIFIC           (1ULL << 49)
13377 +
13378 +#define VXF_IGNEG_NICE         (1ULL << 52)
13379 +
13380 +#define VXF_ONE_TIME           (0x0007ULL << 32)
13381 +
13382 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
13383 +
13384 +
13385 +/* context migration */
13386 +
13387 +#define VXM_SET_INIT           0x00000001
13388 +#define VXM_SET_REAPER         0x00000002
13389 +
13390 +/* context caps */
13391 +
13392 +#define VXC_CAP_MASK           0x00000000
13393 +
13394 +#define VXC_SET_UTSNAME                0x00000001
13395 +#define VXC_SET_RLIMIT         0x00000002
13396 +#define VXC_FS_SECURITY                0x00000004
13397 +#define VXC_FS_TRUSTED         0x00000008
13398 +#define VXC_TIOCSTI            0x00000010
13399 +
13400 +/* was VXC_RAW_ICMP            0x00000100 */
13401 +#define VXC_SYSLOG             0x00001000
13402 +#define VXC_OOM_ADJUST         0x00002000
13403 +#define VXC_AUDIT_CONTROL      0x00004000
13404 +
13405 +#define VXC_SECURE_MOUNT       0x00010000
13406 +#define VXC_SECURE_REMOUNT     0x00020000
13407 +#define VXC_BINARY_MOUNT       0x00040000
13408 +
13409 +#define VXC_QUOTA_CTL          0x00100000
13410 +#define VXC_ADMIN_MAPPER       0x00200000
13411 +#define VXC_ADMIN_CLOOP                0x00400000
13412 +
13413 +#define VXC_KTHREAD            0x01000000
13414 +#define VXC_NAMESPACE          0x02000000
13415 +
13416 +
13417 +#ifdef __KERNEL__
13418 +
13419 +#include <linux/list.h>
13420 +#include <linux/spinlock.h>
13421 +#include <linux/rcupdate.h>
13422 +
13423 +#include "limit_def.h"
13424 +#include "sched_def.h"
13425 +#include "cvirt_def.h"
13426 +#include "cacct_def.h"
13427 +#include "device_def.h"
13428 +
13429 +#define VX_SPACES      2
13430 +
13431 +struct _vx_info_pc {
13432 +       struct _vx_sched_pc sched_pc;
13433 +       struct _vx_cvirt_pc cvirt_pc;
13434 +};
13435 +
13436 +struct _vx_space {
13437 +       unsigned long vx_nsmask;                /* assignment mask */
13438 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
13439 +       struct fs_struct *vx_fs;                /* private namespace fs */
13440 +       const struct cred *vx_cred;             /* task credentials */
13441 +};
13442 +
13443 +struct vx_info {
13444 +       struct hlist_node vx_hlist;             /* linked list of contexts */
13445 +       xid_t vx_id;                            /* context id */
13446 +       atomic_t vx_usecnt;                     /* usage count */
13447 +       atomic_t vx_tasks;                      /* tasks count */
13448 +       struct vx_info *vx_parent;              /* parent context */
13449 +       int vx_state;                           /* context state */
13450 +
13451 +       struct _vx_space space[VX_SPACES];      /* namespace store */
13452 +
13453 +       uint64_t vx_flags;                      /* context flags */
13454 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
13455 +       uint64_t vx_umask;                      /* unshare mask (guest) */
13456 +       uint64_t vx_wmask;                      /* warn mask (guest) */
13457 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
13458 +
13459 +       struct task_struct *vx_reaper;          /* guest reaper process */
13460 +       pid_t vx_initpid;                       /* PID of guest init */
13461 +       int64_t vx_badness_bias;                /* OOM points bias */
13462 +
13463 +       struct _vx_limit limit;                 /* vserver limits */
13464 +       struct _vx_sched sched;                 /* vserver scheduler */
13465 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
13466 +       struct _vx_cacct cacct;                 /* context accounting */
13467 +
13468 +       struct _vx_device dmap;                 /* default device map targets */
13469 +
13470 +#ifndef CONFIG_SMP
13471 +       struct _vx_info_pc info_pc;             /* per cpu data */
13472 +#else
13473 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
13474 +#endif
13475 +
13476 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
13477 +       int reboot_cmd;                         /* last sys_reboot() cmd */
13478 +       int exit_code;                          /* last process exit code */
13479 +
13480 +       char vx_name[65];                       /* vserver name */
13481 +};
13482 +
13483 +#ifndef CONFIG_SMP
13484 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
13485 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
13486 +#else
13487 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
13488 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
13489 +#endif
13490 +
13491 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
13492 +
13493 +
13494 +struct vx_info_save {
13495 +       struct vx_info *vxi;
13496 +       xid_t xid;
13497 +};
13498 +
13499 +
13500 +/* status flags */
13501 +
13502 +#define VXS_HASHED     0x0001
13503 +#define VXS_PAUSED     0x0010
13504 +#define VXS_SHUTDOWN   0x0100
13505 +#define VXS_HELPER     0x1000
13506 +#define VXS_RELEASED   0x8000
13507 +
13508 +
13509 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
13510 +extern void release_vx_info(struct vx_info *, struct task_struct *);
13511 +
13512 +extern struct vx_info *lookup_vx_info(int);
13513 +extern struct vx_info *lookup_or_create_vx_info(int);
13514 +
13515 +extern int get_xid_list(int, unsigned int *, int);
13516 +extern int xid_is_hashed(xid_t);
13517 +
13518 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
13519 +
13520 +extern long vs_state_change(struct vx_info *, unsigned int);
13521 +
13522 +
13523 +#endif /* __KERNEL__ */
13524 +#endif /* _VX_CONTEXT_H */
13525 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/context_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/context_cmd.h
13526 --- linux-3.0.4/include/linux/vserver/context_cmd.h     1970-01-01 01:00:00.000000000 +0100
13527 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/context_cmd.h     2011-08-01 18:25:07.000000000 +0200
13528 @@ -0,0 +1,162 @@
13529 +#ifndef _VX_CONTEXT_CMD_H
13530 +#define _VX_CONTEXT_CMD_H
13531 +
13532 +
13533 +/* vinfo commands */
13534 +
13535 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
13536 +
13537 +#ifdef __KERNEL__
13538 +extern int vc_task_xid(uint32_t);
13539 +
13540 +#endif /* __KERNEL__ */
13541 +
13542 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
13543 +
13544 +struct vcmd_vx_info_v0 {
13545 +       uint32_t xid;
13546 +       uint32_t initpid;
13547 +       /* more to come */
13548 +};
13549 +
13550 +#ifdef __KERNEL__
13551 +extern int vc_vx_info(struct vx_info *, void __user *);
13552 +
13553 +#endif /* __KERNEL__ */
13554 +
13555 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
13556 +
13557 +struct vcmd_ctx_stat_v0 {
13558 +       uint32_t usecnt;
13559 +       uint32_t tasks;
13560 +       /* more to come */
13561 +};
13562 +
13563 +#ifdef __KERNEL__
13564 +extern int vc_ctx_stat(struct vx_info *, void __user *);
13565 +
13566 +#endif /* __KERNEL__ */
13567 +
13568 +/* context commands */
13569 +
13570 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
13571 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
13572 +
13573 +struct vcmd_ctx_create {
13574 +       uint64_t flagword;
13575 +};
13576 +
13577 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
13578 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
13579 +
13580 +struct vcmd_ctx_migrate {
13581 +       uint64_t flagword;
13582 +};
13583 +
13584 +#ifdef __KERNEL__
13585 +extern int vc_ctx_create(uint32_t, void __user *);
13586 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
13587 +
13588 +#endif /* __KERNEL__ */
13589 +
13590 +
13591 +/* flag commands */
13592 +
13593 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
13594 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
13595 +
13596 +struct vcmd_ctx_flags_v0 {
13597 +       uint64_t flagword;
13598 +       uint64_t mask;
13599 +};
13600 +
13601 +#ifdef __KERNEL__
13602 +extern int vc_get_cflags(struct vx_info *, void __user *);
13603 +extern int vc_set_cflags(struct vx_info *, void __user *);
13604 +
13605 +#endif /* __KERNEL__ */
13606 +
13607 +
13608 +/* context caps commands */
13609 +
13610 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
13611 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
13612 +
13613 +struct vcmd_ctx_caps_v1 {
13614 +       uint64_t ccaps;
13615 +       uint64_t cmask;
13616 +};
13617 +
13618 +#ifdef __KERNEL__
13619 +extern int vc_get_ccaps(struct vx_info *, void __user *);
13620 +extern int vc_set_ccaps(struct vx_info *, void __user *);
13621 +
13622 +#endif /* __KERNEL__ */
13623 +
13624 +
13625 +/* bcaps commands */
13626 +
13627 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
13628 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
13629 +
13630 +struct vcmd_bcaps {
13631 +       uint64_t bcaps;
13632 +       uint64_t bmask;
13633 +};
13634 +
13635 +#ifdef __KERNEL__
13636 +extern int vc_get_bcaps(struct vx_info *, void __user *);
13637 +extern int vc_set_bcaps(struct vx_info *, void __user *);
13638 +
13639 +#endif /* __KERNEL__ */
13640 +
13641 +
13642 +/* umask commands */
13643 +
13644 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
13645 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
13646 +
13647 +struct vcmd_umask {
13648 +       uint64_t umask;
13649 +       uint64_t mask;
13650 +};
13651 +
13652 +#ifdef __KERNEL__
13653 +extern int vc_get_umask(struct vx_info *, void __user *);
13654 +extern int vc_set_umask(struct vx_info *, void __user *);
13655 +
13656 +#endif /* __KERNEL__ */
13657 +
13658 +
13659 +/* wmask commands */
13660 +
13661 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
13662 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
13663 +
13664 +struct vcmd_wmask {
13665 +       uint64_t wmask;
13666 +       uint64_t mask;
13667 +};
13668 +
13669 +#ifdef __KERNEL__
13670 +extern int vc_get_wmask(struct vx_info *, void __user *);
13671 +extern int vc_set_wmask(struct vx_info *, void __user *);
13672 +
13673 +#endif /* __KERNEL__ */
13674 +
13675 +
13676 +/* OOM badness */
13677 +
13678 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
13679 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
13680 +
13681 +struct vcmd_badness_v0 {
13682 +       int64_t bias;
13683 +};
13684 +
13685 +#ifdef __KERNEL__
13686 +extern int vc_get_badness(struct vx_info *, void __user *);
13687 +extern int vc_set_badness(struct vx_info *, void __user *);
13688 +
13689 +#endif /* __KERNEL__ */
13690 +#endif /* _VX_CONTEXT_CMD_H */
13691 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/cvirt.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cvirt.h
13692 --- linux-3.0.4/include/linux/vserver/cvirt.h   1970-01-01 01:00:00.000000000 +0100
13693 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cvirt.h   2011-06-10 22:11:24.000000000 +0200
13694 @@ -0,0 +1,20 @@
13695 +#ifndef _VX_CVIRT_H
13696 +#define _VX_CVIRT_H
13697 +
13698 +
13699 +#ifdef __KERNEL__
13700 +
13701 +struct timespec;
13702 +
13703 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13704 +
13705 +
13706 +struct vx_info;
13707 +
13708 +void vx_update_load(struct vx_info *);
13709 +
13710 +
13711 +int vx_do_syslog(int, char __user *, int);
13712 +
13713 +#endif /* __KERNEL__ */
13714 +#endif /* _VX_CVIRT_H */
13715 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/cvirt_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cvirt_cmd.h
13716 --- linux-3.0.4/include/linux/vserver/cvirt_cmd.h       1970-01-01 01:00:00.000000000 +0100
13717 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cvirt_cmd.h       2011-06-10 22:11:24.000000000 +0200
13718 @@ -0,0 +1,53 @@
13719 +#ifndef _VX_CVIRT_CMD_H
13720 +#define _VX_CVIRT_CMD_H
13721 +
13722 +
13723 +/* virtual host info name commands */
13724 +
13725 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
13726 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
13727 +
13728 +struct vcmd_vhi_name_v0 {
13729 +       uint32_t field;
13730 +       char name[65];
13731 +};
13732 +
13733 +
13734 +enum vhi_name_field {
13735 +       VHIN_CONTEXT = 0,
13736 +       VHIN_SYSNAME,
13737 +       VHIN_NODENAME,
13738 +       VHIN_RELEASE,
13739 +       VHIN_VERSION,
13740 +       VHIN_MACHINE,
13741 +       VHIN_DOMAINNAME,
13742 +};
13743 +
13744 +
13745 +#ifdef __KERNEL__
13746 +
13747 +#include <linux/compiler.h>
13748 +
13749 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
13750 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
13751 +
13752 +#endif /* __KERNEL__ */
13753 +
13754 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
13755 +
13756 +struct vcmd_virt_stat_v0 {
13757 +       uint64_t offset;
13758 +       uint64_t uptime;
13759 +       uint32_t nr_threads;
13760 +       uint32_t nr_running;
13761 +       uint32_t nr_uninterruptible;
13762 +       uint32_t nr_onhold;
13763 +       uint32_t nr_forks;
13764 +       uint32_t load[3];
13765 +};
13766 +
13767 +#ifdef __KERNEL__
13768 +extern int vc_virt_stat(struct vx_info *, void __user *);
13769 +
13770 +#endif /* __KERNEL__ */
13771 +#endif /* _VX_CVIRT_CMD_H */
13772 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/cvirt_def.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cvirt_def.h
13773 --- linux-3.0.4/include/linux/vserver/cvirt_def.h       1970-01-01 01:00:00.000000000 +0100
13774 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/cvirt_def.h       2011-06-10 22:11:24.000000000 +0200
13775 @@ -0,0 +1,80 @@
13776 +#ifndef _VX_CVIRT_DEF_H
13777 +#define _VX_CVIRT_DEF_H
13778 +
13779 +#include <linux/jiffies.h>
13780 +#include <linux/spinlock.h>
13781 +#include <linux/wait.h>
13782 +#include <linux/time.h>
13783 +#include <asm/atomic.h>
13784 +
13785 +
13786 +struct _vx_usage_stat {
13787 +       uint64_t user;
13788 +       uint64_t nice;
13789 +       uint64_t system;
13790 +       uint64_t softirq;
13791 +       uint64_t irq;
13792 +       uint64_t idle;
13793 +       uint64_t iowait;
13794 +};
13795 +
13796 +struct _vx_syslog {
13797 +       wait_queue_head_t log_wait;
13798 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
13799 +
13800 +       unsigned long log_start;        /* next char to be read by syslog() */
13801 +       unsigned long con_start;        /* next char to be sent to consoles */
13802 +       unsigned long log_end;  /* most-recently-written-char + 1 */
13803 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
13804 +
13805 +       char log_buf[1024];
13806 +};
13807 +
13808 +
13809 +/* context sub struct */
13810 +
13811 +struct _vx_cvirt {
13812 +       atomic_t nr_threads;            /* number of current threads */
13813 +       atomic_t nr_running;            /* number of running threads */
13814 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
13815 +
13816 +       atomic_t nr_onhold;             /* processes on hold */
13817 +       uint32_t onhold_last;           /* jiffies when put on hold */
13818 +
13819 +       struct timespec bias_ts;        /* time offset to the host */
13820 +       struct timespec bias_idle;
13821 +       struct timespec bias_uptime;    /* context creation point */
13822 +       uint64_t bias_clock;            /* offset in clock_t */
13823 +
13824 +       spinlock_t load_lock;           /* lock for the load averages */
13825 +       atomic_t load_updates;          /* nr of load updates done so far */
13826 +       uint32_t load_last;             /* last time load was calculated */
13827 +       uint32_t load[3];               /* load averages 1,5,15 */
13828 +
13829 +       atomic_t total_forks;           /* number of forks so far */
13830 +
13831 +       struct _vx_syslog syslog;
13832 +};
13833 +
13834 +struct _vx_cvirt_pc {
13835 +       struct _vx_usage_stat cpustat;
13836 +};
13837 +
13838 +
13839 +#ifdef CONFIG_VSERVER_DEBUG
13840 +
13841 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
13842 +{
13843 +       printk("\t_vx_cvirt:\n");
13844 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
13845 +               atomic_read(&cvirt->nr_threads),
13846 +               atomic_read(&cvirt->nr_running),
13847 +               atomic_read(&cvirt->nr_uninterruptible),
13848 +               atomic_read(&cvirt->nr_onhold));
13849 +       /* add rest here */
13850 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
13851 +}
13852 +
13853 +#endif
13854 +
13855 +#endif /* _VX_CVIRT_DEF_H */
13856 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/debug.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/debug.h
13857 --- linux-3.0.4/include/linux/vserver/debug.h   1970-01-01 01:00:00.000000000 +0100
13858 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/debug.h   2011-06-10 22:11:24.000000000 +0200
13859 @@ -0,0 +1,140 @@
13860 +#ifndef _VX_DEBUG_H
13861 +#define _VX_DEBUG_H
13862 +
13863 +
13864 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
13865 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
13866 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
13867 +
13868 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
13869 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
13870 +#define VXF_DEV                "%p[%lu,%d:%d]"
13871 +
13872 +#if    defined(CONFIG_QUOTES_UTF8)
13873 +#define        VS_Q_LQM        "\xc2\xbb"
13874 +#define        VS_Q_RQM        "\xc2\xab"
13875 +#elif  defined(CONFIG_QUOTES_ASCII)
13876 +#define        VS_Q_LQM        "\x27"
13877 +#define        VS_Q_RQM        "\x27"
13878 +#else
13879 +#define        VS_Q_LQM        "\xbb"
13880 +#define        VS_Q_RQM        "\xab"
13881 +#endif
13882 +
13883 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
13884 +
13885 +
13886 +#define vxd_path(p)                                            \
13887 +       ({ static char _buffer[PATH_MAX];                       \
13888 +          d_path(p, _buffer, sizeof(_buffer)); })
13889 +
13890 +#define vxd_cond_path(n)                                       \
13891 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
13892 +
13893 +
13894 +#ifdef CONFIG_VSERVER_DEBUG
13895 +
13896 +extern unsigned int vx_debug_switch;
13897 +extern unsigned int vx_debug_xid;
13898 +extern unsigned int vx_debug_nid;
13899 +extern unsigned int vx_debug_tag;
13900 +extern unsigned int vx_debug_net;
13901 +extern unsigned int vx_debug_limit;
13902 +extern unsigned int vx_debug_cres;
13903 +extern unsigned int vx_debug_dlim;
13904 +extern unsigned int vx_debug_quota;
13905 +extern unsigned int vx_debug_cvirt;
13906 +extern unsigned int vx_debug_space;
13907 +extern unsigned int vx_debug_misc;
13908 +
13909 +
13910 +#define VX_LOGLEVEL    "vxD: "
13911 +#define VX_PROC_FMT    "%p: "
13912 +#define VX_PROCESS     current
13913 +
13914 +#define vxdprintk(c, f, x...)                                  \
13915 +       do {                                                    \
13916 +               if (c)                                          \
13917 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
13918 +                               VX_PROCESS , ##x);              \
13919 +       } while (0)
13920 +
13921 +#define vxlprintk(c, f, x...)                                  \
13922 +       do {                                                    \
13923 +               if (c)                                          \
13924 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
13925 +       } while (0)
13926 +
13927 +#define vxfprintk(c, f, x...)                                  \
13928 +       do {                                                    \
13929 +               if (c)                                          \
13930 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
13931 +       } while (0)
13932 +
13933 +
13934 +struct vx_info;
13935 +
13936 +void dump_vx_info(struct vx_info *, int);
13937 +void dump_vx_info_inactive(int);
13938 +
13939 +#else  /* CONFIG_VSERVER_DEBUG */
13940 +
13941 +#define vx_debug_switch 0
13942 +#define vx_debug_xid   0
13943 +#define vx_debug_nid   0
13944 +#define vx_debug_tag   0
13945 +#define vx_debug_net   0
13946 +#define vx_debug_limit 0
13947 +#define vx_debug_cres  0
13948 +#define vx_debug_dlim  0
13949 +#define vx_debug_cvirt 0
13950 +
13951 +#define vxdprintk(x...) do { } while (0)
13952 +#define vxlprintk(x...) do { } while (0)
13953 +#define vxfprintk(x...) do { } while (0)
13954 +
13955 +#endif /* CONFIG_VSERVER_DEBUG */
13956 +
13957 +
13958 +#ifdef CONFIG_VSERVER_WARN
13959 +
13960 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
13961 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
13962 +#define VX_WARN_XID    "[xid #%u] "
13963 +#define VX_WARN_NID    "[nid #%u] "
13964 +#define VX_WARN_TAG    "[tag #%u] "
13965 +
13966 +#define vxwprintk(c, f, x...)                                  \
13967 +       do {                                                    \
13968 +               if (c)                                          \
13969 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
13970 +       } while (0)
13971 +
13972 +#else  /* CONFIG_VSERVER_WARN */
13973 +
13974 +#define vxwprintk(x...) do { } while (0)
13975 +
13976 +#endif /* CONFIG_VSERVER_WARN */
13977 +
13978 +#define vxwprintk_task(c, f, x...)                             \
13979 +       vxwprintk(c, VX_WARN_TASK f,                            \
13980 +               current->comm, current->pid,                    \
13981 +               current->xid, current->nid, current->tag, ##x)
13982 +#define vxwprintk_xid(c, f, x...)                              \
13983 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
13984 +#define vxwprintk_nid(c, f, x...)                              \
13985 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
13986 +#define vxwprintk_tag(c, f, x...)                              \
13987 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
13988 +
13989 +#ifdef CONFIG_VSERVER_DEBUG
13990 +#define vxd_assert_lock(l)     assert_spin_locked(l)
13991 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
13992 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
13993 +#else
13994 +#define vxd_assert_lock(l)     do { } while (0)
13995 +#define vxd_assert(c, f, x...) do { } while (0)
13996 +#endif
13997 +
13998 +
13999 +#endif /* _VX_DEBUG_H */
14000 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/debug_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/debug_cmd.h
14001 --- linux-3.0.4/include/linux/vserver/debug_cmd.h       1970-01-01 01:00:00.000000000 +0100
14002 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/debug_cmd.h       2011-06-10 22:11:24.000000000 +0200
14003 @@ -0,0 +1,58 @@
14004 +#ifndef _VX_DEBUG_CMD_H
14005 +#define _VX_DEBUG_CMD_H
14006 +
14007 +
14008 +/* debug commands */
14009 +
14010 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
14011 +
14012 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
14013 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
14014 +
14015 +struct  vcmd_read_history_v0 {
14016 +       uint32_t index;
14017 +       uint32_t count;
14018 +       char __user *data;
14019 +};
14020 +
14021 +struct  vcmd_read_monitor_v0 {
14022 +       uint32_t index;
14023 +       uint32_t count;
14024 +       char __user *data;
14025 +};
14026 +
14027 +
14028 +#ifdef __KERNEL__
14029 +
14030 +#ifdef CONFIG_COMPAT
14031 +
14032 +#include <asm/compat.h>
14033 +
14034 +struct vcmd_read_history_v0_x32 {
14035 +       uint32_t index;
14036 +       uint32_t count;
14037 +       compat_uptr_t data_ptr;
14038 +};
14039 +
14040 +struct vcmd_read_monitor_v0_x32 {
14041 +       uint32_t index;
14042 +       uint32_t count;
14043 +       compat_uptr_t data_ptr;
14044 +};
14045 +
14046 +#endif  /* CONFIG_COMPAT */
14047 +
14048 +extern int vc_dump_history(uint32_t);
14049 +
14050 +extern int vc_read_history(uint32_t, void __user *);
14051 +extern int vc_read_monitor(uint32_t, void __user *);
14052 +
14053 +#ifdef CONFIG_COMPAT
14054 +
14055 +extern int vc_read_history_x32(uint32_t, void __user *);
14056 +extern int vc_read_monitor_x32(uint32_t, void __user *);
14057 +
14058 +#endif  /* CONFIG_COMPAT */
14059 +
14060 +#endif /* __KERNEL__ */
14061 +#endif /* _VX_DEBUG_CMD_H */
14062 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/device.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/device.h
14063 --- linux-3.0.4/include/linux/vserver/device.h  1970-01-01 01:00:00.000000000 +0100
14064 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/device.h  2011-06-10 22:11:24.000000000 +0200
14065 @@ -0,0 +1,15 @@
14066 +#ifndef _VX_DEVICE_H
14067 +#define _VX_DEVICE_H
14068 +
14069 +
14070 +#define DATTR_CREATE   0x00000001
14071 +#define DATTR_OPEN     0x00000002
14072 +
14073 +#define DATTR_REMAP    0x00000010
14074 +
14075 +#define DATTR_MASK     0x00000013
14076 +
14077 +
14078 +#else  /* _VX_DEVICE_H */
14079 +#warning duplicate inclusion
14080 +#endif /* _VX_DEVICE_H */
14081 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/device_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/device_cmd.h
14082 --- linux-3.0.4/include/linux/vserver/device_cmd.h      1970-01-01 01:00:00.000000000 +0100
14083 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/device_cmd.h      2011-06-10 22:11:24.000000000 +0200
14084 @@ -0,0 +1,44 @@
14085 +#ifndef _VX_DEVICE_CMD_H
14086 +#define _VX_DEVICE_CMD_H
14087 +
14088 +
14089 +/*  device vserver commands */
14090 +
14091 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
14092 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
14093 +
14094 +struct vcmd_set_mapping_v0 {
14095 +       const char __user *device;
14096 +       const char __user *target;
14097 +       uint32_t flags;
14098 +};
14099 +
14100 +
14101 +#ifdef __KERNEL__
14102 +
14103 +#ifdef CONFIG_COMPAT
14104 +
14105 +#include <asm/compat.h>
14106 +
14107 +struct vcmd_set_mapping_v0_x32 {
14108 +       compat_uptr_t device_ptr;
14109 +       compat_uptr_t target_ptr;
14110 +       uint32_t flags;
14111 +};
14112 +
14113 +#endif /* CONFIG_COMPAT */
14114 +
14115 +#include <linux/compiler.h>
14116 +
14117 +extern int vc_set_mapping(struct vx_info *, void __user *);
14118 +extern int vc_unset_mapping(struct vx_info *, void __user *);
14119 +
14120 +#ifdef CONFIG_COMPAT
14121 +
14122 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
14123 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
14124 +
14125 +#endif /* CONFIG_COMPAT */
14126 +
14127 +#endif /* __KERNEL__ */
14128 +#endif /* _VX_DEVICE_CMD_H */
14129 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/device_def.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/device_def.h
14130 --- linux-3.0.4/include/linux/vserver/device_def.h      1970-01-01 01:00:00.000000000 +0100
14131 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/device_def.h      2011-06-10 22:11:24.000000000 +0200
14132 @@ -0,0 +1,17 @@
14133 +#ifndef _VX_DEVICE_DEF_H
14134 +#define _VX_DEVICE_DEF_H
14135 +
14136 +#include <linux/types.h>
14137 +
14138 +struct vx_dmap_target {
14139 +       dev_t target;
14140 +       uint32_t flags;
14141 +};
14142 +
14143 +struct _vx_device {
14144 +#ifdef CONFIG_VSERVER_DEVICE
14145 +       struct vx_dmap_target targets[2];
14146 +#endif
14147 +};
14148 +
14149 +#endif /* _VX_DEVICE_DEF_H */
14150 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/dlimit.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/dlimit.h
14151 --- linux-3.0.4/include/linux/vserver/dlimit.h  1970-01-01 01:00:00.000000000 +0100
14152 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/dlimit.h  2011-06-10 22:11:24.000000000 +0200
14153 @@ -0,0 +1,54 @@
14154 +#ifndef _VX_DLIMIT_H
14155 +#define _VX_DLIMIT_H
14156 +
14157 +#include "switch.h"
14158 +
14159 +
14160 +#ifdef __KERNEL__
14161 +
14162 +/*      keep in sync with CDLIM_INFINITY       */
14163 +
14164 +#define DLIM_INFINITY          (~0ULL)
14165 +
14166 +#include <linux/spinlock.h>
14167 +#include <linux/rcupdate.h>
14168 +
14169 +struct super_block;
14170 +
14171 +struct dl_info {
14172 +       struct hlist_node dl_hlist;             /* linked list of contexts */
14173 +       struct rcu_head dl_rcu;                 /* the rcu head */
14174 +       tag_t dl_tag;                           /* context tag */
14175 +       atomic_t dl_usecnt;                     /* usage count */
14176 +       atomic_t dl_refcnt;                     /* reference count */
14177 +
14178 +       struct super_block *dl_sb;              /* associated superblock */
14179 +
14180 +       spinlock_t dl_lock;                     /* protect the values */
14181 +
14182 +       unsigned long long dl_space_used;       /* used space in bytes */
14183 +       unsigned long long dl_space_total;      /* maximum space in bytes */
14184 +       unsigned long dl_inodes_used;           /* used inodes */
14185 +       unsigned long dl_inodes_total;          /* maximum inodes */
14186 +
14187 +       unsigned int dl_nrlmult;                /* non root limit mult */
14188 +};
14189 +
14190 +struct rcu_head;
14191 +
14192 +extern void rcu_free_dl_info(struct rcu_head *);
14193 +extern void unhash_dl_info(struct dl_info *);
14194 +
14195 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
14196 +
14197 +
14198 +struct kstatfs;
14199 +
14200 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
14201 +
14202 +typedef uint64_t dlsize_t;
14203 +
14204 +#endif /* __KERNEL__ */
14205 +#else  /* _VX_DLIMIT_H */
14206 +#warning duplicate inclusion
14207 +#endif /* _VX_DLIMIT_H */
14208 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/dlimit_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/dlimit_cmd.h
14209 --- linux-3.0.4/include/linux/vserver/dlimit_cmd.h      1970-01-01 01:00:00.000000000 +0100
14210 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/dlimit_cmd.h      2011-06-10 22:11:24.000000000 +0200
14211 @@ -0,0 +1,109 @@
14212 +#ifndef _VX_DLIMIT_CMD_H
14213 +#define _VX_DLIMIT_CMD_H
14214 +
14215 +
14216 +/*  dlimit vserver commands */
14217 +
14218 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
14219 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
14220 +
14221 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
14222 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
14223 +
14224 +struct vcmd_ctx_dlimit_base_v0 {
14225 +       const char __user *name;
14226 +       uint32_t flags;
14227 +};
14228 +
14229 +struct vcmd_ctx_dlimit_v0 {
14230 +       const char __user *name;
14231 +       uint32_t space_used;                    /* used space in kbytes */
14232 +       uint32_t space_total;                   /* maximum space in kbytes */
14233 +       uint32_t inodes_used;                   /* used inodes */
14234 +       uint32_t inodes_total;                  /* maximum inodes */
14235 +       uint32_t reserved;                      /* reserved for root in % */
14236 +       uint32_t flags;
14237 +};
14238 +
14239 +#define CDLIM_UNSET            ((uint32_t)0UL)
14240 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
14241 +#define CDLIM_KEEP             ((uint32_t)~1UL)
14242 +
14243 +#define DLIME_UNIT     0
14244 +#define DLIME_KILO     1
14245 +#define DLIME_MEGA     2
14246 +#define DLIME_GIGA     3
14247 +
14248 +#define DLIMF_SHIFT    0x10
14249 +
14250 +#define DLIMS_USED     0
14251 +#define DLIMS_TOTAL    2
14252 +
14253 +static inline
14254 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
14255 +{
14256 +       int exp = (flags & DLIMF_SHIFT) ?
14257 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
14258 +       return ((uint64_t)val) << (10 * exp);
14259 +}
14260 +
14261 +static inline
14262 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
14263 +{
14264 +       int exp = 0;
14265 +
14266 +       if (*flags & DLIMF_SHIFT) {
14267 +               while (val > (1LL << 32) && (exp < 3)) {
14268 +                       val >>= 10;
14269 +                       exp++;
14270 +               }
14271 +               *flags &= ~(DLIME_GIGA << shift);
14272 +               *flags |= exp << shift;
14273 +       } else
14274 +               val >>= 10;
14275 +       return val;
14276 +}
14277 +
14278 +#ifdef __KERNEL__
14279 +
14280 +#ifdef CONFIG_COMPAT
14281 +
14282 +#include <asm/compat.h>
14283 +
14284 +struct vcmd_ctx_dlimit_base_v0_x32 {
14285 +       compat_uptr_t name_ptr;
14286 +       uint32_t flags;
14287 +};
14288 +
14289 +struct vcmd_ctx_dlimit_v0_x32 {
14290 +       compat_uptr_t name_ptr;
14291 +       uint32_t space_used;                    /* used space in kbytes */
14292 +       uint32_t space_total;                   /* maximum space in kbytes */
14293 +       uint32_t inodes_used;                   /* used inodes */
14294 +       uint32_t inodes_total;                  /* maximum inodes */
14295 +       uint32_t reserved;                      /* reserved for root in % */
14296 +       uint32_t flags;
14297 +};
14298 +
14299 +#endif /* CONFIG_COMPAT */
14300 +
14301 +#include <linux/compiler.h>
14302 +
14303 +extern int vc_add_dlimit(uint32_t, void __user *);
14304 +extern int vc_rem_dlimit(uint32_t, void __user *);
14305 +
14306 +extern int vc_set_dlimit(uint32_t, void __user *);
14307 +extern int vc_get_dlimit(uint32_t, void __user *);
14308 +
14309 +#ifdef CONFIG_COMPAT
14310 +
14311 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
14312 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
14313 +
14314 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
14315 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
14316 +
14317 +#endif /* CONFIG_COMPAT */
14318 +
14319 +#endif /* __KERNEL__ */
14320 +#endif /* _VX_DLIMIT_CMD_H */
14321 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/global.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/global.h
14322 --- linux-3.0.4/include/linux/vserver/global.h  1970-01-01 01:00:00.000000000 +0100
14323 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/global.h  2011-06-10 22:11:24.000000000 +0200
14324 @@ -0,0 +1,19 @@
14325 +#ifndef _VX_GLOBAL_H
14326 +#define _VX_GLOBAL_H
14327 +
14328 +
14329 +extern atomic_t vx_global_ctotal;
14330 +extern atomic_t vx_global_cactive;
14331 +
14332 +extern atomic_t nx_global_ctotal;
14333 +extern atomic_t nx_global_cactive;
14334 +
14335 +extern atomic_t vs_global_nsproxy;
14336 +extern atomic_t vs_global_fs;
14337 +extern atomic_t vs_global_mnt_ns;
14338 +extern atomic_t vs_global_uts_ns;
14339 +extern atomic_t vs_global_user_ns;
14340 +extern atomic_t vs_global_pid_ns;
14341 +
14342 +
14343 +#endif /* _VX_GLOBAL_H */
14344 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/history.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/history.h
14345 --- linux-3.0.4/include/linux/vserver/history.h 1970-01-01 01:00:00.000000000 +0100
14346 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/history.h 2011-06-10 22:11:24.000000000 +0200
14347 @@ -0,0 +1,197 @@
14348 +#ifndef _VX_HISTORY_H
14349 +#define _VX_HISTORY_H
14350 +
14351 +
14352 +enum {
14353 +       VXH_UNUSED = 0,
14354 +       VXH_THROW_OOPS = 1,
14355 +
14356 +       VXH_GET_VX_INFO,
14357 +       VXH_PUT_VX_INFO,
14358 +       VXH_INIT_VX_INFO,
14359 +       VXH_SET_VX_INFO,
14360 +       VXH_CLR_VX_INFO,
14361 +       VXH_CLAIM_VX_INFO,
14362 +       VXH_RELEASE_VX_INFO,
14363 +       VXH_ALLOC_VX_INFO,
14364 +       VXH_DEALLOC_VX_INFO,
14365 +       VXH_HASH_VX_INFO,
14366 +       VXH_UNHASH_VX_INFO,
14367 +       VXH_LOC_VX_INFO,
14368 +       VXH_LOOKUP_VX_INFO,
14369 +       VXH_CREATE_VX_INFO,
14370 +};
14371 +
14372 +struct _vxhe_vxi {
14373 +       struct vx_info *ptr;
14374 +       unsigned xid;
14375 +       unsigned usecnt;
14376 +       unsigned tasks;
14377 +};
14378 +
14379 +struct _vxhe_set_clr {
14380 +       void *data;
14381 +};
14382 +
14383 +struct _vxhe_loc_lookup {
14384 +       unsigned arg;
14385 +};
14386 +
14387 +struct _vx_hist_entry {
14388 +       void *loc;
14389 +       unsigned short seq;
14390 +       unsigned short type;
14391 +       struct _vxhe_vxi vxi;
14392 +       union {
14393 +               struct _vxhe_set_clr sc;
14394 +               struct _vxhe_loc_lookup ll;
14395 +       };
14396 +};
14397 +
14398 +#ifdef CONFIG_VSERVER_HISTORY
14399 +
14400 +extern unsigned volatile int vxh_active;
14401 +
14402 +struct _vx_hist_entry *vxh_advance(void *loc);
14403 +
14404 +
14405 +static inline
14406 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
14407 +{
14408 +       entry->vxi.ptr = vxi;
14409 +       if (vxi) {
14410 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
14411 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
14412 +               entry->vxi.xid = vxi->vx_id;
14413 +       }
14414 +}
14415 +
14416 +
14417 +#define        __HERE__ current_text_addr()
14418 +
14419 +#define __VXH_BODY(__type, __data, __here)     \
14420 +       struct _vx_hist_entry *entry;           \
14421 +                                               \
14422 +       preempt_disable();                      \
14423 +       entry = vxh_advance(__here);            \
14424 +       __data;                                 \
14425 +       entry->type = __type;                   \
14426 +       preempt_enable();
14427 +
14428 +
14429 +       /* pass vxi only */
14430 +
14431 +#define __VXH_SMPL                             \
14432 +       __vxh_copy_vxi(entry, vxi)
14433 +
14434 +static inline
14435 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
14436 +{
14437 +       __VXH_BODY(__type, __VXH_SMPL, __here)
14438 +}
14439 +
14440 +       /* pass vxi and data (void *) */
14441 +
14442 +#define __VXH_DATA                             \
14443 +       __vxh_copy_vxi(entry, vxi);             \
14444 +       entry->sc.data = data
14445 +
14446 +static inline
14447 +void   __vxh_data(struct vx_info *vxi, void *data,
14448 +                       int __type, void *__here)
14449 +{
14450 +       __VXH_BODY(__type, __VXH_DATA, __here)
14451 +}
14452 +
14453 +       /* pass vxi and arg (long) */
14454 +
14455 +#define __VXH_LONG                             \
14456 +       __vxh_copy_vxi(entry, vxi);             \
14457 +       entry->ll.arg = arg
14458 +
14459 +static inline
14460 +void   __vxh_long(struct vx_info *vxi, long arg,
14461 +                       int __type, void *__here)
14462 +{
14463 +       __VXH_BODY(__type, __VXH_LONG, __here)
14464 +}
14465 +
14466 +
14467 +static inline
14468 +void   __vxh_throw_oops(void *__here)
14469 +{
14470 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
14471 +       /* prevent further acquisition */
14472 +       vxh_active = 0;
14473 +}
14474 +
14475 +
14476 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
14477 +
14478 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
14479 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
14480 +
14481 +#define __vxh_init_vx_info(v, d, h) \
14482 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
14483 +#define __vxh_set_vx_info(v, d, h) \
14484 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
14485 +#define __vxh_clr_vx_info(v, d, h) \
14486 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
14487 +
14488 +#define __vxh_claim_vx_info(v, d, h) \
14489 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
14490 +#define __vxh_release_vx_info(v, d, h) \
14491 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
14492 +
14493 +#define vxh_alloc_vx_info(v) \
14494 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
14495 +#define vxh_dealloc_vx_info(v) \
14496 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
14497 +
14498 +#define vxh_hash_vx_info(v) \
14499 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
14500 +#define vxh_unhash_vx_info(v) \
14501 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
14502 +
14503 +#define vxh_loc_vx_info(v, l) \
14504 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
14505 +#define vxh_lookup_vx_info(v, l) \
14506 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
14507 +#define vxh_create_vx_info(v, l) \
14508 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
14509 +
14510 +extern void vxh_dump_history(void);
14511 +
14512 +
14513 +#else  /* CONFIG_VSERVER_HISTORY */
14514 +
14515 +#define        __HERE__        0
14516 +
14517 +#define vxh_throw_oops()               do { } while (0)
14518 +
14519 +#define __vxh_get_vx_info(v, h)                do { } while (0)
14520 +#define __vxh_put_vx_info(v, h)                do { } while (0)
14521 +
14522 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
14523 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
14524 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
14525 +
14526 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
14527 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
14528 +
14529 +#define vxh_alloc_vx_info(v)           do { } while (0)
14530 +#define vxh_dealloc_vx_info(v)         do { } while (0)
14531 +
14532 +#define vxh_hash_vx_info(v)            do { } while (0)
14533 +#define vxh_unhash_vx_info(v)          do { } while (0)
14534 +
14535 +#define vxh_loc_vx_info(v, l)          do { } while (0)
14536 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
14537 +#define vxh_create_vx_info(v, l)       do { } while (0)
14538 +
14539 +#define vxh_dump_history()             do { } while (0)
14540 +
14541 +
14542 +#endif /* CONFIG_VSERVER_HISTORY */
14543 +
14544 +#endif /* _VX_HISTORY_H */
14545 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/inode.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/inode.h
14546 --- linux-3.0.4/include/linux/vserver/inode.h   1970-01-01 01:00:00.000000000 +0100
14547 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/inode.h   2011-06-10 22:11:24.000000000 +0200
14548 @@ -0,0 +1,39 @@
14549 +#ifndef _VX_INODE_H
14550 +#define _VX_INODE_H
14551 +
14552 +
14553 +#define IATTR_TAG      0x01000000
14554 +
14555 +#define IATTR_ADMIN    0x00000001
14556 +#define IATTR_WATCH    0x00000002
14557 +#define IATTR_HIDE     0x00000004
14558 +#define IATTR_FLAGS    0x00000007
14559 +
14560 +#define IATTR_BARRIER  0x00010000
14561 +#define IATTR_IXUNLINK 0x00020000
14562 +#define IATTR_IMMUTABLE 0x00040000
14563 +#define IATTR_COW      0x00080000
14564 +
14565 +#ifdef __KERNEL__
14566 +
14567 +
14568 +#ifdef CONFIG_VSERVER_PROC_SECURE
14569 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
14570 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14571 +#else
14572 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
14573 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14574 +#endif
14575 +
14576 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
14577 +
14578 +#endif /* __KERNEL__ */
14579 +
14580 +/* inode ioctls */
14581 +
14582 +#define FIOC_GETXFLG   _IOR('x', 5, long)
14583 +#define FIOC_SETXFLG   _IOW('x', 6, long)
14584 +
14585 +#else  /* _VX_INODE_H */
14586 +#warning duplicate inclusion
14587 +#endif /* _VX_INODE_H */
14588 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/inode_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/inode_cmd.h
14589 --- linux-3.0.4/include/linux/vserver/inode_cmd.h       1970-01-01 01:00:00.000000000 +0100
14590 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/inode_cmd.h       2011-06-10 22:11:24.000000000 +0200
14591 @@ -0,0 +1,59 @@
14592 +#ifndef _VX_INODE_CMD_H
14593 +#define _VX_INODE_CMD_H
14594 +
14595 +
14596 +/*  inode vserver commands */
14597 +
14598 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
14599 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
14600 +
14601 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
14602 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
14603 +
14604 +struct vcmd_ctx_iattr_v1 {
14605 +       const char __user *name;
14606 +       uint32_t tag;
14607 +       uint32_t flags;
14608 +       uint32_t mask;
14609 +};
14610 +
14611 +struct vcmd_ctx_fiattr_v0 {
14612 +       uint32_t tag;
14613 +       uint32_t flags;
14614 +       uint32_t mask;
14615 +};
14616 +
14617 +
14618 +#ifdef __KERNEL__
14619 +
14620 +
14621 +#ifdef CONFIG_COMPAT
14622 +
14623 +#include <asm/compat.h>
14624 +
14625 +struct vcmd_ctx_iattr_v1_x32 {
14626 +       compat_uptr_t name_ptr;
14627 +       uint32_t tag;
14628 +       uint32_t flags;
14629 +       uint32_t mask;
14630 +};
14631 +
14632 +#endif /* CONFIG_COMPAT */
14633 +
14634 +#include <linux/compiler.h>
14635 +
14636 +extern int vc_get_iattr(void __user *);
14637 +extern int vc_set_iattr(void __user *);
14638 +
14639 +extern int vc_fget_iattr(uint32_t, void __user *);
14640 +extern int vc_fset_iattr(uint32_t, void __user *);
14641 +
14642 +#ifdef CONFIG_COMPAT
14643 +
14644 +extern int vc_get_iattr_x32(void __user *);
14645 +extern int vc_set_iattr_x32(void __user *);
14646 +
14647 +#endif /* CONFIG_COMPAT */
14648 +
14649 +#endif /* __KERNEL__ */
14650 +#endif /* _VX_INODE_CMD_H */
14651 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/limit.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/limit.h
14652 --- linux-3.0.4/include/linux/vserver/limit.h   1970-01-01 01:00:00.000000000 +0100
14653 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/limit.h   2011-06-10 22:11:24.000000000 +0200
14654 @@ -0,0 +1,71 @@
14655 +#ifndef _VX_LIMIT_H
14656 +#define _VX_LIMIT_H
14657 +
14658 +#define VLIMIT_NSOCK   16
14659 +#define VLIMIT_OPENFD  17
14660 +#define VLIMIT_ANON    18
14661 +#define VLIMIT_SHMEM   19
14662 +#define VLIMIT_SEMARY  20
14663 +#define VLIMIT_NSEMS   21
14664 +#define VLIMIT_DENTRY  22
14665 +#define VLIMIT_MAPPED  23
14666 +
14667 +
14668 +#ifdef __KERNEL__
14669 +
14670 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
14671 +
14672 +/*     keep in sync with CRLIM_INFINITY */
14673 +
14674 +#define        VLIM_INFINITY   (~0ULL)
14675 +
14676 +#include <asm/atomic.h>
14677 +#include <asm/resource.h>
14678 +
14679 +#ifndef RLIM_INFINITY
14680 +#warning RLIM_INFINITY is undefined
14681 +#endif
14682 +
14683 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
14684 +
14685 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
14686 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
14687 +
14688 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
14689 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
14690 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
14691 +
14692 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
14693 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
14694 +
14695 +typedef atomic_long_t rlim_atomic_t;
14696 +typedef unsigned long rlim_t;
14697 +
14698 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
14699 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
14700 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
14701 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
14702 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
14703 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
14704 +
14705 +
14706 +#if    (RLIM_INFINITY == VLIM_INFINITY)
14707 +#define        VX_VLIM(r) ((long long)(long)(r))
14708 +#define        VX_RLIM(v) ((rlim_t)(v))
14709 +#else
14710 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
14711 +               ? VLIM_INFINITY : (long long)(r))
14712 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
14713 +               ? RLIM_INFINITY : (rlim_t)(v))
14714 +#endif
14715 +
14716 +struct sysinfo;
14717 +
14718 +void vx_vsi_meminfo(struct sysinfo *);
14719 +void vx_vsi_swapinfo(struct sysinfo *);
14720 +long vx_vsi_cached(struct sysinfo *);
14721 +
14722 +#define NUM_LIMITS     24
14723 +
14724 +#endif /* __KERNEL__ */
14725 +#endif /* _VX_LIMIT_H */
14726 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/limit_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/limit_cmd.h
14727 --- linux-3.0.4/include/linux/vserver/limit_cmd.h       1970-01-01 01:00:00.000000000 +0100
14728 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/limit_cmd.h       2011-06-10 22:11:24.000000000 +0200
14729 @@ -0,0 +1,71 @@
14730 +#ifndef _VX_LIMIT_CMD_H
14731 +#define _VX_LIMIT_CMD_H
14732 +
14733 +
14734 +/*  rlimit vserver commands */
14735 +
14736 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
14737 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
14738 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
14739 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
14740 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
14741 +
14742 +struct vcmd_ctx_rlimit_v0 {
14743 +       uint32_t id;
14744 +       uint64_t minimum;
14745 +       uint64_t softlimit;
14746 +       uint64_t maximum;
14747 +};
14748 +
14749 +struct vcmd_ctx_rlimit_mask_v0 {
14750 +       uint32_t minimum;
14751 +       uint32_t softlimit;
14752 +       uint32_t maximum;
14753 +};
14754 +
14755 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
14756 +
14757 +struct vcmd_rlimit_stat_v0 {
14758 +       uint32_t id;
14759 +       uint32_t hits;
14760 +       uint64_t value;
14761 +       uint64_t minimum;
14762 +       uint64_t maximum;
14763 +};
14764 +
14765 +#define CRLIM_UNSET            (0ULL)
14766 +#define CRLIM_INFINITY         (~0ULL)
14767 +#define CRLIM_KEEP             (~1ULL)
14768 +
14769 +#ifdef __KERNEL__
14770 +
14771 +#ifdef CONFIG_IA32_EMULATION
14772 +
14773 +struct vcmd_ctx_rlimit_v0_x32 {
14774 +       uint32_t id;
14775 +       uint64_t minimum;
14776 +       uint64_t softlimit;
14777 +       uint64_t maximum;
14778 +} __attribute__ ((packed));
14779 +
14780 +#endif /* CONFIG_IA32_EMULATION */
14781 +
14782 +#include <linux/compiler.h>
14783 +
14784 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
14785 +extern int vc_get_rlimit(struct vx_info *, void __user *);
14786 +extern int vc_set_rlimit(struct vx_info *, void __user *);
14787 +extern int vc_reset_hits(struct vx_info *, void __user *);
14788 +extern int vc_reset_minmax(struct vx_info *, void __user *);
14789 +
14790 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
14791 +
14792 +#ifdef CONFIG_IA32_EMULATION
14793 +
14794 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
14795 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
14796 +
14797 +#endif /* CONFIG_IA32_EMULATION */
14798 +
14799 +#endif /* __KERNEL__ */
14800 +#endif /* _VX_LIMIT_CMD_H */
14801 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/limit_def.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/limit_def.h
14802 --- linux-3.0.4/include/linux/vserver/limit_def.h       1970-01-01 01:00:00.000000000 +0100
14803 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/limit_def.h       2011-06-10 22:11:24.000000000 +0200
14804 @@ -0,0 +1,47 @@
14805 +#ifndef _VX_LIMIT_DEF_H
14806 +#define _VX_LIMIT_DEF_H
14807 +
14808 +#include <asm/atomic.h>
14809 +#include <asm/resource.h>
14810 +
14811 +#include "limit.h"
14812 +
14813 +
14814 +struct _vx_res_limit {
14815 +       rlim_t soft;            /* Context soft limit */
14816 +       rlim_t hard;            /* Context hard limit */
14817 +
14818 +       rlim_atomic_t rcur;     /* Current value */
14819 +       rlim_t rmin;            /* Context minimum */
14820 +       rlim_t rmax;            /* Context maximum */
14821 +
14822 +       atomic_t lhit;          /* Limit hits */
14823 +};
14824 +
14825 +/* context sub struct */
14826 +
14827 +struct _vx_limit {
14828 +       struct _vx_res_limit res[NUM_LIMITS];
14829 +};
14830 +
14831 +#ifdef CONFIG_VSERVER_DEBUG
14832 +
14833 +static inline void __dump_vx_limit(struct _vx_limit *limit)
14834 +{
14835 +       int i;
14836 +
14837 +       printk("\t_vx_limit:");
14838 +       for (i = 0; i < NUM_LIMITS; i++) {
14839 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
14840 +                       i, (unsigned long)__rlim_get(limit, i),
14841 +                       (unsigned long)__rlim_rmin(limit, i),
14842 +                       (unsigned long)__rlim_rmax(limit, i),
14843 +                       (long)__rlim_soft(limit, i),
14844 +                       (long)__rlim_hard(limit, i),
14845 +                       atomic_read(&__rlim_lhit(limit, i)));
14846 +       }
14847 +}
14848 +
14849 +#endif
14850 +
14851 +#endif /* _VX_LIMIT_DEF_H */
14852 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/limit_int.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/limit_int.h
14853 --- linux-3.0.4/include/linux/vserver/limit_int.h       1970-01-01 01:00:00.000000000 +0100
14854 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/limit_int.h       2011-06-10 22:11:24.000000000 +0200
14855 @@ -0,0 +1,198 @@
14856 +#ifndef _VX_LIMIT_INT_H
14857 +#define _VX_LIMIT_INT_H
14858 +
14859 +#include "context.h"
14860 +
14861 +#ifdef __KERNEL__
14862 +
14863 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
14864 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
14865 +
14866 +extern const char *vlimit_name[NUM_LIMITS];
14867 +
14868 +static inline void __vx_acc_cres(struct vx_info *vxi,
14869 +       int res, int dir, void *_data, char *_file, int _line)
14870 +{
14871 +       if (VXD_RCRES_COND(res))
14872 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
14873 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14874 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14875 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
14876 +       if (!vxi)
14877 +               return;
14878 +
14879 +       if (dir > 0)
14880 +               __rlim_inc(&vxi->limit, res);
14881 +       else
14882 +               __rlim_dec(&vxi->limit, res);
14883 +}
14884 +
14885 +static inline void __vx_add_cres(struct vx_info *vxi,
14886 +       int res, int amount, void *_data, char *_file, int _line)
14887 +{
14888 +       if (VXD_RCRES_COND(res))
14889 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
14890 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14891 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14892 +                       amount, _data, _file, _line);
14893 +       if (amount == 0)
14894 +               return;
14895 +       if (!vxi)
14896 +               return;
14897 +       __rlim_add(&vxi->limit, res, amount);
14898 +}
14899 +
14900 +static inline
14901 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
14902 +{
14903 +       int cond = (value > __rlim_rmax(limit, res));
14904 +
14905 +       if (cond)
14906 +               __rlim_rmax(limit, res) = value;
14907 +       return cond;
14908 +}
14909 +
14910 +static inline
14911 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
14912 +{
14913 +       int cond = (value < __rlim_rmin(limit, res));
14914 +
14915 +       if (cond)
14916 +               __rlim_rmin(limit, res) = value;
14917 +       return cond;
14918 +}
14919 +
14920 +static inline
14921 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
14922 +{
14923 +       if (!__vx_cres_adjust_max(limit, res, value))
14924 +               __vx_cres_adjust_min(limit, res, value);
14925 +}
14926 +
14927 +
14928 +/*     return values:
14929 +        +1 ... no limit hit
14930 +        -1 ... over soft limit
14931 +         0 ... over hard limit         */
14932 +
14933 +static inline int __vx_cres_avail(struct vx_info *vxi,
14934 +       int res, int num, char *_file, int _line)
14935 +{
14936 +       struct _vx_limit *limit;
14937 +       rlim_t value;
14938 +
14939 +       if (VXD_RLIMIT_COND(res))
14940 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
14941 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14942 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
14943 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
14944 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14945 +                       num, _file, _line);
14946 +       if (!vxi)
14947 +               return 1;
14948 +
14949 +       limit = &vxi->limit;
14950 +       value = __rlim_get(limit, res);
14951 +
14952 +       if (!__vx_cres_adjust_max(limit, res, value))
14953 +               __vx_cres_adjust_min(limit, res, value);
14954 +
14955 +       if (num == 0)
14956 +               return 1;
14957 +
14958 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
14959 +               return -1;
14960 +       if (value + num <= __rlim_soft(limit, res))
14961 +               return -1;
14962 +
14963 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
14964 +               return 1;
14965 +       if (value + num <= __rlim_hard(limit, res))
14966 +               return 1;
14967 +
14968 +       __rlim_hit(limit, res);
14969 +       return 0;
14970 +}
14971 +
14972 +
14973 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
14974 +
14975 +static inline
14976 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
14977 +{
14978 +       rlim_t value, sum = 0;
14979 +       int res;
14980 +
14981 +       while ((res = *array++)) {
14982 +               value = __rlim_get(limit, res);
14983 +               __vx_cres_fixup(limit, res, value);
14984 +               sum += value;
14985 +       }
14986 +       return sum;
14987 +}
14988 +
14989 +static inline
14990 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
14991 +{
14992 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
14993 +       int res = *array;
14994 +
14995 +       if (value == __rlim_get(limit, res))
14996 +               return value;
14997 +
14998 +       __rlim_set(limit, res, value);
14999 +       /* now adjust min/max */
15000 +       if (!__vx_cres_adjust_max(limit, res, value))
15001 +               __vx_cres_adjust_min(limit, res, value);
15002 +
15003 +       return value;
15004 +}
15005 +
15006 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
15007 +       const int *array, int num, char *_file, int _line)
15008 +{
15009 +       struct _vx_limit *limit;
15010 +       rlim_t value = 0;
15011 +       int res;
15012 +
15013 +       if (num == 0)
15014 +               return 1;
15015 +       if (!vxi)
15016 +               return 1;
15017 +
15018 +       limit = &vxi->limit;
15019 +       res = *array;
15020 +       value = __vx_cres_array_sum(limit, array + 1);
15021 +
15022 +       __rlim_set(limit, res, value);
15023 +       __vx_cres_fixup(limit, res, value);
15024 +
15025 +       return __vx_cres_avail(vxi, res, num, _file, _line);
15026 +}
15027 +
15028 +
15029 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
15030 +{
15031 +       rlim_t value;
15032 +       int res;
15033 +
15034 +       /* complex resources first */
15035 +       if ((id < 0) || (id == RLIMIT_RSS))
15036 +               __vx_cres_array_fixup(limit, VLA_RSS);
15037 +
15038 +       for (res = 0; res < NUM_LIMITS; res++) {
15039 +               if ((id > 0) && (res != id))
15040 +                       continue;
15041 +
15042 +               value = __rlim_get(limit, res);
15043 +               __vx_cres_fixup(limit, res, value);
15044 +
15045 +               /* not supposed to happen, maybe warn? */
15046 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
15047 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
15048 +       }
15049 +}
15050 +
15051 +
15052 +#endif /* __KERNEL__ */
15053 +#endif /* _VX_LIMIT_INT_H */
15054 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/monitor.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/monitor.h
15055 --- linux-3.0.4/include/linux/vserver/monitor.h 1970-01-01 01:00:00.000000000 +0100
15056 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/monitor.h 2011-06-10 22:11:24.000000000 +0200
15057 @@ -0,0 +1,96 @@
15058 +#ifndef _VX_MONITOR_H
15059 +#define _VX_MONITOR_H
15060 +
15061 +#include <linux/types.h>
15062 +
15063 +enum {
15064 +       VXM_UNUSED = 0,
15065 +
15066 +       VXM_SYNC = 0x10,
15067 +
15068 +       VXM_UPDATE = 0x20,
15069 +       VXM_UPDATE_1,
15070 +       VXM_UPDATE_2,
15071 +
15072 +       VXM_RQINFO_1 = 0x24,
15073 +       VXM_RQINFO_2,
15074 +
15075 +       VXM_ACTIVATE = 0x40,
15076 +       VXM_DEACTIVATE,
15077 +       VXM_IDLE,
15078 +
15079 +       VXM_HOLD = 0x44,
15080 +       VXM_UNHOLD,
15081 +
15082 +       VXM_MIGRATE = 0x48,
15083 +       VXM_RESCHED,
15084 +
15085 +       /* all other bits are flags */
15086 +       VXM_SCHED = 0x80,
15087 +};
15088 +
15089 +struct _vxm_update_1 {
15090 +       uint32_t tokens_max;
15091 +       uint32_t fill_rate;
15092 +       uint32_t interval;
15093 +};
15094 +
15095 +struct _vxm_update_2 {
15096 +       uint32_t tokens_min;
15097 +       uint32_t fill_rate;
15098 +       uint32_t interval;
15099 +};
15100 +
15101 +struct _vxm_rqinfo_1 {
15102 +       uint16_t running;
15103 +       uint16_t onhold;
15104 +       uint16_t iowait;
15105 +       uint16_t uintr;
15106 +       uint32_t idle_tokens;
15107 +};
15108 +
15109 +struct _vxm_rqinfo_2 {
15110 +       uint32_t norm_time;
15111 +       uint32_t idle_time;
15112 +       uint32_t idle_skip;
15113 +};
15114 +
15115 +struct _vxm_sched {
15116 +       uint32_t tokens;
15117 +       uint32_t norm_time;
15118 +       uint32_t idle_time;
15119 +};
15120 +
15121 +struct _vxm_task {
15122 +       uint16_t pid;
15123 +       uint16_t state;
15124 +};
15125 +
15126 +struct _vxm_event {
15127 +       uint32_t jif;
15128 +       union {
15129 +               uint32_t seq;
15130 +               uint32_t sec;
15131 +       };
15132 +       union {
15133 +               uint32_t tokens;
15134 +               uint32_t nsec;
15135 +               struct _vxm_task tsk;
15136 +       };
15137 +};
15138 +
15139 +struct _vx_mon_entry {
15140 +       uint16_t type;
15141 +       uint16_t xid;
15142 +       union {
15143 +               struct _vxm_event ev;
15144 +               struct _vxm_sched sd;
15145 +               struct _vxm_update_1 u1;
15146 +               struct _vxm_update_2 u2;
15147 +               struct _vxm_rqinfo_1 q1;
15148 +               struct _vxm_rqinfo_2 q2;
15149 +       };
15150 +};
15151 +
15152 +
15153 +#endif /* _VX_MONITOR_H */
15154 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/network.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/network.h
15155 --- linux-3.0.4/include/linux/vserver/network.h 1970-01-01 01:00:00.000000000 +0100
15156 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/network.h 2011-08-18 16:30:48.000000000 +0200
15157 @@ -0,0 +1,148 @@
15158 +#ifndef _VX_NETWORK_H
15159 +#define _VX_NETWORK_H
15160 +
15161 +#include <linux/types.h>
15162 +
15163 +
15164 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
15165 +
15166 +
15167 +/* network flags */
15168 +
15169 +#define NXF_INFO_PRIVATE       0x00000008
15170 +
15171 +#define NXF_SINGLE_IP          0x00000100
15172 +#define NXF_LBACK_REMAP                0x00000200
15173 +#define NXF_LBACK_ALLOW                0x00000400
15174 +
15175 +#define NXF_HIDE_NETIF         0x02000000
15176 +#define NXF_HIDE_LBACK         0x04000000
15177 +
15178 +#define NXF_STATE_SETUP                (1ULL << 32)
15179 +#define NXF_STATE_ADMIN                (1ULL << 34)
15180 +
15181 +#define NXF_SC_HELPER          (1ULL << 36)
15182 +#define NXF_PERSISTENT         (1ULL << 38)
15183 +
15184 +#define NXF_ONE_TIME           (0x0005ULL << 32)
15185 +
15186 +
15187 +#define        NXF_INIT_SET            (__nxf_init_set())
15188 +
15189 +static inline uint64_t __nxf_init_set(void) {
15190 +       return    NXF_STATE_ADMIN
15191 +#ifdef CONFIG_VSERVER_AUTO_LBACK
15192 +               | NXF_LBACK_REMAP
15193 +               | NXF_HIDE_LBACK
15194 +#endif
15195 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
15196 +               | NXF_SINGLE_IP
15197 +#endif
15198 +               | NXF_HIDE_NETIF;
15199 +}
15200 +
15201 +
15202 +/* network caps */
15203 +
15204 +#define NXC_TUN_CREATE         0x00000001
15205 +
15206 +#define NXC_RAW_ICMP           0x00000100
15207 +
15208 +#define NXC_MULTICAST          0x00001000
15209 +
15210 +
15211 +/* address types */
15212 +
15213 +#define NXA_TYPE_IPV4          0x0001
15214 +#define NXA_TYPE_IPV6          0x0002
15215 +
15216 +#define NXA_TYPE_NONE          0x0000
15217 +#define NXA_TYPE_ANY           0x00FF
15218 +
15219 +#define NXA_TYPE_ADDR          0x0010
15220 +#define NXA_TYPE_MASK          0x0020
15221 +#define NXA_TYPE_RANGE         0x0040
15222 +
15223 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
15224 +
15225 +#define NXA_MOD_BCAST          0x0100
15226 +#define NXA_MOD_LBACK          0x0200
15227 +
15228 +#define NXA_LOOPBACK           0x1000
15229 +
15230 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
15231 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
15232 +
15233 +#ifdef __KERNEL__
15234 +
15235 +#include <linux/list.h>
15236 +#include <linux/spinlock.h>
15237 +#include <linux/rcupdate.h>
15238 +#include <linux/in.h>
15239 +#include <linux/in6.h>
15240 +#include <asm/atomic.h>
15241 +
15242 +struct nx_addr_v4 {
15243 +       struct nx_addr_v4 *next;
15244 +       struct in_addr ip[2];
15245 +       struct in_addr mask;
15246 +       uint16_t type;
15247 +       uint16_t flags;
15248 +};
15249 +
15250 +struct nx_addr_v6 {
15251 +       struct nx_addr_v6 *next;
15252 +       struct in6_addr ip;
15253 +       struct in6_addr mask;
15254 +       uint32_t prefix;
15255 +       uint16_t type;
15256 +       uint16_t flags;
15257 +};
15258 +
15259 +struct nx_info {
15260 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
15261 +       nid_t nx_id;                    /* vnet id */
15262 +       atomic_t nx_usecnt;             /* usage count */
15263 +       atomic_t nx_tasks;              /* tasks count */
15264 +       int nx_state;                   /* context state */
15265 +
15266 +       uint64_t nx_flags;              /* network flag word */
15267 +       uint64_t nx_ncaps;              /* network capabilities */
15268 +
15269 +       struct in_addr v4_lback;        /* Loopback address */
15270 +       struct in_addr v4_bcast;        /* Broadcast address */
15271 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
15272 +#ifdef CONFIG_IPV6
15273 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
15274 +#endif
15275 +       char nx_name[65];               /* network context name */
15276 +};
15277 +
15278 +
15279 +/* status flags */
15280 +
15281 +#define NXS_HASHED      0x0001
15282 +#define NXS_SHUTDOWN    0x0100
15283 +#define NXS_RELEASED    0x8000
15284 +
15285 +extern struct nx_info *lookup_nx_info(int);
15286 +
15287 +extern int get_nid_list(int, unsigned int *, int);
15288 +extern int nid_is_hashed(nid_t);
15289 +
15290 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
15291 +
15292 +extern long vs_net_change(struct nx_info *, unsigned int);
15293 +
15294 +struct sock;
15295 +
15296 +
15297 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
15298 +#ifdef  CONFIG_IPV6
15299 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
15300 +#else
15301 +#define NX_IPV6(n)     (0)
15302 +#endif
15303 +
15304 +#endif /* __KERNEL__ */
15305 +#endif /* _VX_NETWORK_H */
15306 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/network_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/network_cmd.h
15307 --- linux-3.0.4/include/linux/vserver/network_cmd.h     1970-01-01 01:00:00.000000000 +0100
15308 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/network_cmd.h     2011-06-10 22:11:24.000000000 +0200
15309 @@ -0,0 +1,164 @@
15310 +#ifndef _VX_NETWORK_CMD_H
15311 +#define _VX_NETWORK_CMD_H
15312 +
15313 +
15314 +/* vinfo commands */
15315 +
15316 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
15317 +
15318 +#ifdef __KERNEL__
15319 +extern int vc_task_nid(uint32_t);
15320 +
15321 +#endif /* __KERNEL__ */
15322 +
15323 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
15324 +
15325 +struct vcmd_nx_info_v0 {
15326 +       uint32_t nid;
15327 +       /* more to come */
15328 +};
15329 +
15330 +#ifdef __KERNEL__
15331 +extern int vc_nx_info(struct nx_info *, void __user *);
15332 +
15333 +#endif /* __KERNEL__ */
15334 +
15335 +#include <linux/in.h>
15336 +#include <linux/in6.h>
15337 +
15338 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
15339 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
15340 +
15341 +struct  vcmd_net_create {
15342 +       uint64_t flagword;
15343 +};
15344 +
15345 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
15346 +
15347 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
15348 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
15349 +
15350 +struct vcmd_net_addr_v0 {
15351 +       uint16_t type;
15352 +       uint16_t count;
15353 +       struct in_addr ip[4];
15354 +       struct in_addr mask[4];
15355 +};
15356 +
15357 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
15358 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
15359 +
15360 +struct vcmd_net_addr_ipv4_v1 {
15361 +       uint16_t type;
15362 +       uint16_t flags;
15363 +       struct in_addr ip;
15364 +       struct in_addr mask;
15365 +};
15366 +
15367 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
15368 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
15369 +
15370 +struct vcmd_net_addr_ipv4_v2 {
15371 +       uint16_t type;
15372 +       uint16_t flags;
15373 +       struct in_addr ip;
15374 +       struct in_addr ip2;
15375 +       struct in_addr mask;
15376 +};
15377 +
15378 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
15379 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
15380 +
15381 +struct vcmd_net_addr_ipv6_v1 {
15382 +       uint16_t type;
15383 +       uint16_t flags;
15384 +       uint32_t prefix;
15385 +       struct in6_addr ip;
15386 +       struct in6_addr mask;
15387 +};
15388 +
15389 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
15390 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
15391 +
15392 +struct vcmd_match_ipv4_v0 {
15393 +       uint16_t type;
15394 +       uint16_t flags;
15395 +       uint16_t parent;
15396 +       uint16_t prefix;
15397 +       struct in_addr ip;
15398 +       struct in_addr ip2;
15399 +       struct in_addr mask;
15400 +};
15401 +
15402 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
15403 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
15404 +
15405 +struct vcmd_match_ipv6_v0 {
15406 +       uint16_t type;
15407 +       uint16_t flags;
15408 +       uint16_t parent;
15409 +       uint16_t prefix;
15410 +       struct in6_addr ip;
15411 +       struct in6_addr ip2;
15412 +       struct in6_addr mask;
15413 +};
15414 +
15415 +
15416 +#ifdef __KERNEL__
15417 +extern int vc_net_create(uint32_t, void __user *);
15418 +extern int vc_net_migrate(struct nx_info *, void __user *);
15419 +
15420 +extern int vc_net_add(struct nx_info *, void __user *);
15421 +extern int vc_net_remove(struct nx_info *, void __user *);
15422 +
15423 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
15424 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
15425 +
15426 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
15427 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
15428 +
15429 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
15430 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
15431 +
15432 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
15433 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
15434 +
15435 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
15436 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
15437 +
15438 +#endif /* __KERNEL__ */
15439 +
15440 +
15441 +/* flag commands */
15442 +
15443 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
15444 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
15445 +
15446 +struct vcmd_net_flags_v0 {
15447 +       uint64_t flagword;
15448 +       uint64_t mask;
15449 +};
15450 +
15451 +#ifdef __KERNEL__
15452 +extern int vc_get_nflags(struct nx_info *, void __user *);
15453 +extern int vc_set_nflags(struct nx_info *, void __user *);
15454 +
15455 +#endif /* __KERNEL__ */
15456 +
15457 +
15458 +/* network caps commands */
15459 +
15460 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
15461 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
15462 +
15463 +struct vcmd_net_caps_v0 {
15464 +       uint64_t ncaps;
15465 +       uint64_t cmask;
15466 +};
15467 +
15468 +#ifdef __KERNEL__
15469 +extern int vc_get_ncaps(struct nx_info *, void __user *);
15470 +extern int vc_set_ncaps(struct nx_info *, void __user *);
15471 +
15472 +#endif /* __KERNEL__ */
15473 +#endif /* _VX_CONTEXT_CMD_H */
15474 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/percpu.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/percpu.h
15475 --- linux-3.0.4/include/linux/vserver/percpu.h  1970-01-01 01:00:00.000000000 +0100
15476 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/percpu.h  2011-06-10 22:11:24.000000000 +0200
15477 @@ -0,0 +1,14 @@
15478 +#ifndef _VX_PERCPU_H
15479 +#define _VX_PERCPU_H
15480 +
15481 +#include "cvirt_def.h"
15482 +#include "sched_def.h"
15483 +
15484 +struct _vx_percpu {
15485 +       struct _vx_cvirt_pc cvirt;
15486 +       struct _vx_sched_pc sched;
15487 +};
15488 +
15489 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
15490 +
15491 +#endif /* _VX_PERCPU_H */
15492 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/pid.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/pid.h
15493 --- linux-3.0.4/include/linux/vserver/pid.h     1970-01-01 01:00:00.000000000 +0100
15494 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/pid.h     2011-06-10 22:11:24.000000000 +0200
15495 @@ -0,0 +1,51 @@
15496 +#ifndef _VSERVER_PID_H
15497 +#define _VSERVER_PID_H
15498 +
15499 +/* pid faking stuff */
15500 +
15501 +#define vx_info_map_pid(v, p) \
15502 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
15503 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
15504 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
15505 +#define vx_map_tgid(p) vx_map_pid(p)
15506 +
15507 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
15508 +       const char *func, const char *file, int line)
15509 +{
15510 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
15511 +               vxfprintk(VXD_CBIT(cvirt, 2),
15512 +                       "vx_map_tgid: %p/%llx: %d -> %d",
15513 +                       vxi, (long long)vxi->vx_flags, pid,
15514 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
15515 +                       func, file, line);
15516 +               if (pid == 0)
15517 +                       return 0;
15518 +               if (pid == vxi->vx_initpid)
15519 +                       return 1;
15520 +       }
15521 +       return pid;
15522 +}
15523 +
15524 +#define vx_info_rmap_pid(v, p) \
15525 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
15526 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
15527 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
15528 +
15529 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
15530 +       const char *func, const char *file, int line)
15531 +{
15532 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
15533 +               vxfprintk(VXD_CBIT(cvirt, 2),
15534 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
15535 +                       vxi, (long long)vxi->vx_flags, pid,
15536 +                       (pid == 1) ? vxi->vx_initpid : pid,
15537 +                       func, file, line);
15538 +               if ((pid == 1) && vxi->vx_initpid)
15539 +                       return vxi->vx_initpid;
15540 +               if (pid == vxi->vx_initpid)
15541 +                       return ~0U;
15542 +       }
15543 +       return pid;
15544 +}
15545 +
15546 +#endif
15547 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/sched.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/sched.h
15548 --- linux-3.0.4/include/linux/vserver/sched.h   1970-01-01 01:00:00.000000000 +0100
15549 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/sched.h   2011-06-10 22:11:24.000000000 +0200
15550 @@ -0,0 +1,23 @@
15551 +#ifndef _VX_SCHED_H
15552 +#define _VX_SCHED_H
15553 +
15554 +
15555 +#ifdef __KERNEL__
15556 +
15557 +struct timespec;
15558 +
15559 +void vx_vsi_uptime(struct timespec *, struct timespec *);
15560 +
15561 +
15562 +struct vx_info;
15563 +
15564 +void vx_update_load(struct vx_info *);
15565 +
15566 +
15567 +void vx_update_sched_param(struct _vx_sched *sched,
15568 +       struct _vx_sched_pc *sched_pc);
15569 +
15570 +#endif /* __KERNEL__ */
15571 +#else  /* _VX_SCHED_H */
15572 +#warning duplicate inclusion
15573 +#endif /* _VX_SCHED_H */
15574 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/sched_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/sched_cmd.h
15575 --- linux-3.0.4/include/linux/vserver/sched_cmd.h       1970-01-01 01:00:00.000000000 +0100
15576 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/sched_cmd.h       2011-06-10 22:11:24.000000000 +0200
15577 @@ -0,0 +1,21 @@
15578 +#ifndef _VX_SCHED_CMD_H
15579 +#define _VX_SCHED_CMD_H
15580 +
15581 +
15582 +struct vcmd_prio_bias {
15583 +       int32_t cpu_id;
15584 +       int32_t prio_bias;
15585 +};
15586 +
15587 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
15588 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
15589 +
15590 +#ifdef __KERNEL__
15591 +
15592 +#include <linux/compiler.h>
15593 +
15594 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
15595 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
15596 +
15597 +#endif /* __KERNEL__ */
15598 +#endif /* _VX_SCHED_CMD_H */
15599 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/sched_def.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/sched_def.h
15600 --- linux-3.0.4/include/linux/vserver/sched_def.h       1970-01-01 01:00:00.000000000 +0100
15601 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/sched_def.h       2011-06-10 22:11:24.000000000 +0200
15602 @@ -0,0 +1,38 @@
15603 +#ifndef _VX_SCHED_DEF_H
15604 +#define _VX_SCHED_DEF_H
15605 +
15606 +#include <linux/spinlock.h>
15607 +#include <linux/jiffies.h>
15608 +#include <linux/cpumask.h>
15609 +#include <asm/atomic.h>
15610 +#include <asm/param.h>
15611 +
15612 +
15613 +/* context sub struct */
15614 +
15615 +struct _vx_sched {
15616 +       int prio_bias;                  /* bias offset for priority */
15617 +
15618 +       cpumask_t update;               /* CPUs which should update */
15619 +};
15620 +
15621 +struct _vx_sched_pc {
15622 +       int prio_bias;                  /* bias offset for priority */
15623 +
15624 +       uint64_t user_ticks;            /* token tick events */
15625 +       uint64_t sys_ticks;             /* token tick events */
15626 +       uint64_t hold_ticks;            /* token ticks paused */
15627 +};
15628 +
15629 +
15630 +#ifdef CONFIG_VSERVER_DEBUG
15631 +
15632 +static inline void __dump_vx_sched(struct _vx_sched *sched)
15633 +{
15634 +       printk("\t_vx_sched:\n");
15635 +       printk("\t priority = %4d\n", sched->prio_bias);
15636 +}
15637 +
15638 +#endif
15639 +
15640 +#endif /* _VX_SCHED_DEF_H */
15641 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/signal.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/signal.h
15642 --- linux-3.0.4/include/linux/vserver/signal.h  1970-01-01 01:00:00.000000000 +0100
15643 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/signal.h  2011-06-10 22:11:24.000000000 +0200
15644 @@ -0,0 +1,14 @@
15645 +#ifndef _VX_SIGNAL_H
15646 +#define _VX_SIGNAL_H
15647 +
15648 +
15649 +#ifdef __KERNEL__
15650 +
15651 +struct vx_info;
15652 +
15653 +int vx_info_kill(struct vx_info *, int, int);
15654 +
15655 +#endif /* __KERNEL__ */
15656 +#else  /* _VX_SIGNAL_H */
15657 +#warning duplicate inclusion
15658 +#endif /* _VX_SIGNAL_H */
15659 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/signal_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/signal_cmd.h
15660 --- linux-3.0.4/include/linux/vserver/signal_cmd.h      1970-01-01 01:00:00.000000000 +0100
15661 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/signal_cmd.h      2011-06-10 22:11:24.000000000 +0200
15662 @@ -0,0 +1,43 @@
15663 +#ifndef _VX_SIGNAL_CMD_H
15664 +#define _VX_SIGNAL_CMD_H
15665 +
15666 +
15667 +/*  signalling vserver commands */
15668 +
15669 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
15670 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
15671 +
15672 +struct vcmd_ctx_kill_v0 {
15673 +       int32_t pid;
15674 +       int32_t sig;
15675 +};
15676 +
15677 +struct vcmd_wait_exit_v0 {
15678 +       int32_t reboot_cmd;
15679 +       int32_t exit_code;
15680 +};
15681 +
15682 +#ifdef __KERNEL__
15683 +
15684 +extern int vc_ctx_kill(struct vx_info *, void __user *);
15685 +extern int vc_wait_exit(struct vx_info *, void __user *);
15686 +
15687 +#endif /* __KERNEL__ */
15688 +
15689 +/*  process alteration commands */
15690 +
15691 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
15692 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
15693 +
15694 +struct vcmd_pflags_v0 {
15695 +       uint32_t flagword;
15696 +       uint32_t mask;
15697 +};
15698 +
15699 +#ifdef __KERNEL__
15700 +
15701 +extern int vc_get_pflags(uint32_t pid, void __user *);
15702 +extern int vc_set_pflags(uint32_t pid, void __user *);
15703 +
15704 +#endif /* __KERNEL__ */
15705 +#endif /* _VX_SIGNAL_CMD_H */
15706 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/space.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/space.h
15707 --- linux-3.0.4/include/linux/vserver/space.h   1970-01-01 01:00:00.000000000 +0100
15708 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/space.h   2011-06-10 22:11:24.000000000 +0200
15709 @@ -0,0 +1,12 @@
15710 +#ifndef _VX_SPACE_H
15711 +#define _VX_SPACE_H
15712 +
15713 +#include <linux/types.h>
15714 +
15715 +struct vx_info;
15716 +
15717 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
15718 +
15719 +#else  /* _VX_SPACE_H */
15720 +#warning duplicate inclusion
15721 +#endif /* _VX_SPACE_H */
15722 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/space_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/space_cmd.h
15723 --- linux-3.0.4/include/linux/vserver/space_cmd.h       1970-01-01 01:00:00.000000000 +0100
15724 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/space_cmd.h       2011-06-10 22:11:24.000000000 +0200
15725 @@ -0,0 +1,38 @@
15726 +#ifndef _VX_SPACE_CMD_H
15727 +#define _VX_SPACE_CMD_H
15728 +
15729 +
15730 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
15731 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
15732 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
15733 +
15734 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
15735 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
15736 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
15737 +
15738 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
15739 +
15740 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
15741 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
15742 +
15743 +
15744 +struct vcmd_space_mask_v1 {
15745 +       uint64_t mask;
15746 +};
15747 +
15748 +struct vcmd_space_mask_v2 {
15749 +       uint64_t mask;
15750 +       uint32_t index;
15751 +};
15752 +
15753 +
15754 +#ifdef __KERNEL__
15755 +
15756 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
15757 +extern int vc_set_space_v1(struct vx_info *, void __user *);
15758 +extern int vc_enter_space(struct vx_info *, void __user *);
15759 +extern int vc_set_space(struct vx_info *, void __user *);
15760 +extern int vc_get_space_mask(void __user *, int);
15761 +
15762 +#endif /* __KERNEL__ */
15763 +#endif /* _VX_SPACE_CMD_H */
15764 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/switch.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/switch.h
15765 --- linux-3.0.4/include/linux/vserver/switch.h  1970-01-01 01:00:00.000000000 +0100
15766 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/switch.h  2011-06-10 22:11:24.000000000 +0200
15767 @@ -0,0 +1,98 @@
15768 +#ifndef _VX_SWITCH_H
15769 +#define _VX_SWITCH_H
15770 +
15771 +#include <linux/types.h>
15772 +
15773 +
15774 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
15775 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
15776 +#define VC_VERSION(c)          ((c) & 0xFFF)
15777 +
15778 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
15779 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
15780 +
15781 +/*
15782 +
15783 +  Syscall Matrix V2.8
15784 +
15785 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
15786 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
15787 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
15788 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15789 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
15790 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
15791 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15792 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
15793 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
15794 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15795 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
15796 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
15797 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15798 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
15799 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
15800 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15801 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
15802 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
15803 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15804 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
15805 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
15806 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
15807 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
15808 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
15809 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15810 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
15811 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
15812 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15813 +
15814 +*/
15815 +
15816 +#define VC_CAT_VERSION         0
15817 +
15818 +#define VC_CAT_VSETUP          1
15819 +#define VC_CAT_VHOST           2
15820 +
15821 +#define VC_CAT_DEVICE          6
15822 +
15823 +#define VC_CAT_VPROC           9
15824 +#define VC_CAT_PROCALT         10
15825 +#define VC_CAT_PROCMIG         11
15826 +#define VC_CAT_PROCTRL         12
15827 +
15828 +#define VC_CAT_SCHED           14
15829 +#define VC_CAT_MEMCTRL         20
15830 +
15831 +#define VC_CAT_VNET            25
15832 +#define VC_CAT_NETALT          26
15833 +#define VC_CAT_NETMIG          27
15834 +#define VC_CAT_NETCTRL         28
15835 +
15836 +#define VC_CAT_TAGMIG          35
15837 +#define VC_CAT_DLIMIT          36
15838 +#define VC_CAT_INODE           38
15839 +
15840 +#define VC_CAT_VSTAT           40
15841 +#define VC_CAT_VINFO           46
15842 +#define VC_CAT_EVENT           48
15843 +
15844 +#define VC_CAT_FLAGS           52
15845 +#define VC_CAT_VSPACE          54
15846 +#define VC_CAT_DEBUG           56
15847 +#define VC_CAT_RLIMIT          60
15848 +
15849 +#define VC_CAT_SYSTEST         61
15850 +#define VC_CAT_COMPAT          63
15851 +
15852 +/*  query version */
15853 +
15854 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
15855 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
15856 +
15857 +
15858 +#ifdef __KERNEL__
15859 +
15860 +#include <linux/errno.h>
15861 +
15862 +#endif /* __KERNEL__ */
15863 +
15864 +#endif /* _VX_SWITCH_H */
15865 +
15866 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/tag.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/tag.h
15867 --- linux-3.0.4/include/linux/vserver/tag.h     1970-01-01 01:00:00.000000000 +0100
15868 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/tag.h     2011-06-10 22:11:24.000000000 +0200
15869 @@ -0,0 +1,143 @@
15870 +#ifndef _DX_TAG_H
15871 +#define _DX_TAG_H
15872 +
15873 +#include <linux/types.h>
15874 +
15875 +
15876 +#define DX_TAG(in)     (IS_TAGGED(in))
15877 +
15878 +
15879 +#ifdef CONFIG_TAG_NFSD
15880 +#define DX_TAG_NFSD    1
15881 +#else
15882 +#define DX_TAG_NFSD    0
15883 +#endif
15884 +
15885 +
15886 +#ifdef CONFIG_TAGGING_NONE
15887 +
15888 +#define MAX_UID                0xFFFFFFFF
15889 +#define MAX_GID                0xFFFFFFFF
15890 +
15891 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
15892 +
15893 +#define TAGINO_UID(cond, uid, tag)     (uid)
15894 +#define TAGINO_GID(cond, gid, tag)     (gid)
15895 +
15896 +#endif
15897 +
15898 +
15899 +#ifdef CONFIG_TAGGING_GID16
15900 +
15901 +#define MAX_UID                0xFFFFFFFF
15902 +#define MAX_GID                0x0000FFFF
15903 +
15904 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15905 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
15906 +
15907 +#define TAGINO_UID(cond, uid, tag)     (uid)
15908 +#define TAGINO_GID(cond, gid, tag)     \
15909 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
15910 +
15911 +#endif
15912 +
15913 +
15914 +#ifdef CONFIG_TAGGING_ID24
15915 +
15916 +#define MAX_UID                0x00FFFFFF
15917 +#define MAX_GID                0x00FFFFFF
15918 +
15919 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15920 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
15921 +
15922 +#define TAGINO_UID(cond, uid, tag)     \
15923 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
15924 +#define TAGINO_GID(cond, gid, tag)     \
15925 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
15926 +
15927 +#endif
15928 +
15929 +
15930 +#ifdef CONFIG_TAGGING_UID16
15931 +
15932 +#define MAX_UID                0x0000FFFF
15933 +#define MAX_GID                0xFFFFFFFF
15934 +
15935 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15936 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
15937 +
15938 +#define TAGINO_UID(cond, uid, tag)     \
15939 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
15940 +#define TAGINO_GID(cond, gid, tag)     (gid)
15941 +
15942 +#endif
15943 +
15944 +
15945 +#ifdef CONFIG_TAGGING_INTERN
15946 +
15947 +#define MAX_UID                0xFFFFFFFF
15948 +#define MAX_GID                0xFFFFFFFF
15949 +
15950 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15951 +       ((cond) ? (tag) : 0)
15952 +
15953 +#define TAGINO_UID(cond, uid, tag)     (uid)
15954 +#define TAGINO_GID(cond, gid, tag)     (gid)
15955 +
15956 +#endif
15957 +
15958 +
15959 +#ifndef CONFIG_TAGGING_NONE
15960 +#define dx_current_fstag(sb)   \
15961 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
15962 +#else
15963 +#define dx_current_fstag(sb)   (0)
15964 +#endif
15965 +
15966 +#ifndef CONFIG_TAGGING_INTERN
15967 +#define TAGINO_TAG(cond, tag)  (0)
15968 +#else
15969 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
15970 +#endif
15971 +
15972 +#define INOTAG_UID(cond, uid, gid)     \
15973 +       ((cond) ? ((uid) & MAX_UID) : (uid))
15974 +#define INOTAG_GID(cond, uid, gid)     \
15975 +       ((cond) ? ((gid) & MAX_GID) : (gid))
15976 +
15977 +
15978 +static inline uid_t dx_map_uid(uid_t uid)
15979 +{
15980 +       if ((uid > MAX_UID) && (uid != -1))
15981 +               uid = -2;
15982 +       return (uid & MAX_UID);
15983 +}
15984 +
15985 +static inline gid_t dx_map_gid(gid_t gid)
15986 +{
15987 +       if ((gid > MAX_GID) && (gid != -1))
15988 +               gid = -2;
15989 +       return (gid & MAX_GID);
15990 +}
15991 +
15992 +struct peer_tag {
15993 +       int32_t xid;
15994 +       int32_t nid;
15995 +};
15996 +
15997 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
15998 +
15999 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
16000 +                unsigned long *flags);
16001 +
16002 +#ifdef CONFIG_PROPAGATE
16003 +
16004 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
16005 +
16006 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
16007 +
16008 +#else
16009 +#define dx_propagate_tag(n, i) do { } while (0)
16010 +#endif
16011 +
16012 +#endif /* _DX_TAG_H */
16013 diff -NurpP --minimal linux-3.0.4/include/linux/vserver/tag_cmd.h linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/tag_cmd.h
16014 --- linux-3.0.4/include/linux/vserver/tag_cmd.h 1970-01-01 01:00:00.000000000 +0100
16015 +++ linux-3.0.4-vs2.3.1-pre10.1/include/linux/vserver/tag_cmd.h 2011-06-10 22:11:24.000000000 +0200
16016 @@ -0,0 +1,22 @@
16017 +#ifndef _VX_TAG_CMD_H
16018 +#define _VX_TAG_CMD_H
16019 +
16020 +
16021 +/* vinfo commands */
16022 +
16023 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
16024 +
16025 +#ifdef __KERNEL__
16026 +extern int vc_task_tag(uint32_t);
16027 +
16028 +#endif /* __KERNEL__ */
16029 +
16030 +/* context commands */
16031 +
16032 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
16033 +
16034 +#ifdef __KERNEL__
16035 +extern int vc_tag_migrate(uint32_t);
16036 +
16037 +#endif /* __KERNEL__ */
16038 +#endif /* _VX_TAG_CMD_H */
16039 diff -NurpP --minimal linux-3.0.4/include/net/addrconf.h linux-3.0.4-vs2.3.1-pre10.1/include/net/addrconf.h
16040 --- linux-3.0.4/include/net/addrconf.h  2011-07-22 11:18:11.000000000 +0200
16041 +++ linux-3.0.4-vs2.3.1-pre10.1/include/net/addrconf.h  2011-06-10 22:11:24.000000000 +0200
16042 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
16043                                                struct net_device *dev,
16044                                                const struct in6_addr *daddr,
16045                                                unsigned int srcprefs,
16046 -                                              struct in6_addr *saddr);
16047 +                                              struct in6_addr *saddr,
16048 +                                              struct nx_info *nxi);
16049  extern int                     ipv6_get_lladdr(struct net_device *dev,
16050                                                 struct in6_addr *addr,
16051                                                 unsigned char banned_flags);
16052 diff -NurpP --minimal linux-3.0.4/include/net/af_unix.h linux-3.0.4-vs2.3.1-pre10.1/include/net/af_unix.h
16053 --- linux-3.0.4/include/net/af_unix.h   2011-07-22 11:18:11.000000000 +0200
16054 +++ linux-3.0.4-vs2.3.1-pre10.1/include/net/af_unix.h   2011-06-10 22:11:24.000000000 +0200
16055 @@ -4,6 +4,7 @@
16056  #include <linux/socket.h>
16057  #include <linux/un.h>
16058  #include <linux/mutex.h>
16059 +#include <linux/vs_base.h>
16060  #include <net/sock.h>
16061  
16062  extern void unix_inflight(struct file *fp);
16063 diff -NurpP --minimal linux-3.0.4/include/net/inet_timewait_sock.h linux-3.0.4-vs2.3.1-pre10.1/include/net/inet_timewait_sock.h
16064 --- linux-3.0.4/include/net/inet_timewait_sock.h        2011-03-15 18:07:40.000000000 +0100
16065 +++ linux-3.0.4-vs2.3.1-pre10.1/include/net/inet_timewait_sock.h        2011-06-10 22:11:24.000000000 +0200
16066 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
16067  #define tw_net                 __tw_common.skc_net
16068  #define tw_daddr               __tw_common.skc_daddr
16069  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
16070 +#define tw_xid                 __tw_common.skc_xid
16071 +#define tw_vx_info             __tw_common.skc_vx_info
16072 +#define tw_nid                 __tw_common.skc_nid
16073 +#define tw_nx_info             __tw_common.skc_nx_info
16074         int                     tw_timeout;
16075         volatile unsigned char  tw_substate;
16076         unsigned char           tw_rcv_wscale;
16077 diff -NurpP --minimal linux-3.0.4/include/net/ip6_route.h linux-3.0.4-vs2.3.1-pre10.1/include/net/ip6_route.h
16078 --- linux-3.0.4/include/net/ip6_route.h 2011-07-22 11:18:11.000000000 +0200
16079 +++ linux-3.0.4-vs2.3.1-pre10.1/include/net/ip6_route.h 2011-06-16 14:16:51.000000000 +0200
16080 @@ -86,7 +86,8 @@ extern int                    ip6_route_get_saddr(struct 
16081                                                     struct rt6_info *rt,
16082                                                     const struct in6_addr *daddr,
16083                                                     unsigned int prefs,
16084 -                                                   struct in6_addr *saddr);
16085 +                                                   struct in6_addr *saddr,
16086 +                                                   struct nx_info *nxi);
16087  
16088  extern struct rt6_info         *rt6_lookup(struct net *net,
16089                                             const struct in6_addr *daddr,
16090 diff -NurpP --minimal linux-3.0.4/include/net/route.h linux-3.0.4-vs2.3.1-pre10.1/include/net/route.h
16091 --- linux-3.0.4/include/net/route.h     2011-07-22 11:18:11.000000000 +0200
16092 +++ linux-3.0.4-vs2.3.1-pre10.1/include/net/route.h     2011-07-27 19:42:59.000000000 +0200
16093 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
16094                 dst_release(&rt->dst);
16095  }
16096  
16097 +#include <linux/vs_base.h>
16098 +#include <linux/vs_inet.h>
16099 +
16100  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
16101  
16102  extern const __u8 ip_tos2prio[16];
16103 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
16104                            protocol, flow_flags, dst, src, dport, sport);
16105  }
16106  
16107 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
16108 +       struct flowi4 *);
16109 +
16110  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
16111                                               __be32 dst, __be32 src, u32 tos,
16112                                               int oif, u8 protocol,
16113 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
16114  {
16115         struct net *net = sock_net(sk);
16116         struct rtable *rt;
16117 +       struct nx_info *nx_info = current_nx_info();
16118  
16119         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
16120                               sport, dport, sk, can_sleep);
16121  
16122 -       if (!dst || !src) {
16123 +       if (sk)
16124 +               nx_info = sk->sk_nx_info;
16125 +
16126 +       vxdprintk(VXD_CBIT(net, 4),
16127 +               "ip_route_connect(%p) %p,%p;%lx",
16128 +               sk, nx_info, sk->sk_socket,
16129 +               (sk->sk_socket?sk->sk_socket->flags:0));
16130 +
16131 +       rt = ip_v4_find_src(net, nx_info, fl4);
16132 +       if (IS_ERR(rt))
16133 +               return rt;
16134 +       ip_rt_put(rt);
16135 +
16136 +       if (!fl4->daddr || !fl4->saddr) {
16137                 rt = __ip_route_output_key(net, fl4);
16138                 if (IS_ERR(rt))
16139                         return rt;
16140 diff -NurpP --minimal linux-3.0.4/include/net/sock.h linux-3.0.4-vs2.3.1-pre10.1/include/net/sock.h
16141 --- linux-3.0.4/include/net/sock.h      2011-07-22 11:18:12.000000000 +0200
16142 +++ linux-3.0.4-vs2.3.1-pre10.1/include/net/sock.h      2011-07-01 11:35:35.000000000 +0200
16143 @@ -149,6 +149,10 @@ struct sock_common {
16144  #ifdef CONFIG_NET_NS
16145         struct net              *skc_net;
16146  #endif
16147 +       xid_t                   skc_xid;
16148 +       struct vx_info          *skc_vx_info;
16149 +       nid_t                   skc_nid;
16150 +       struct nx_info          *skc_nx_info;
16151         /*
16152          * fields between dontcopy_begin/dontcopy_end
16153          * are not copied in sock_copy()
16154 @@ -256,6 +260,10 @@ struct sock {
16155  #define sk_bind_node           __sk_common.skc_bind_node
16156  #define sk_prot                        __sk_common.skc_prot
16157  #define sk_net                 __sk_common.skc_net
16158 +#define sk_xid                 __sk_common.skc_xid
16159 +#define sk_vx_info             __sk_common.skc_vx_info
16160 +#define sk_nid                 __sk_common.skc_nid
16161 +#define sk_nx_info             __sk_common.skc_nx_info
16162         socket_lock_t           sk_lock;
16163         struct sk_buff_head     sk_receive_queue;
16164         /*
16165 diff -NurpP --minimal linux-3.0.4/init/Kconfig linux-3.0.4-vs2.3.1-pre10.1/init/Kconfig
16166 --- linux-3.0.4/init/Kconfig    2011-07-22 11:18:12.000000000 +0200
16167 +++ linux-3.0.4-vs2.3.1-pre10.1/init/Kconfig    2011-08-08 18:08:57.000000000 +0200
16168 @@ -574,6 +574,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
16169  menuconfig CGROUPS
16170         boolean "Control Group support"
16171         depends on EVENTFD
16172 +       default y
16173         help
16174           This option adds support for grouping sets of processes together, for
16175           use with process control subsystems such as Cpusets, CFS, memory
16176 @@ -790,6 +791,7 @@ config IPC_NS
16177  config USER_NS
16178         bool "User namespace (EXPERIMENTAL)"
16179         depends on EXPERIMENTAL
16180 +       depends on VSERVER_DISABLED
16181         default y
16182         help
16183           This allows containers, i.e. vservers, to use user namespaces
16184 diff -NurpP --minimal linux-3.0.4/init/main.c linux-3.0.4-vs2.3.1-pre10.1/init/main.c
16185 --- linux-3.0.4/init/main.c     2011-07-22 11:18:12.000000000 +0200
16186 +++ linux-3.0.4-vs2.3.1-pre10.1/init/main.c     2011-06-22 12:39:15.000000000 +0200
16187 @@ -68,6 +68,7 @@
16188  #include <linux/shmem_fs.h>
16189  #include <linux/slab.h>
16190  #include <linux/perf_event.h>
16191 +#include <linux/vserver/percpu.h>
16192  
16193  #include <asm/io.h>
16194  #include <asm/bugs.h>
16195 diff -NurpP --minimal linux-3.0.4/ipc/mqueue.c linux-3.0.4-vs2.3.1-pre10.1/ipc/mqueue.c
16196 --- linux-3.0.4/ipc/mqueue.c    2011-03-15 18:07:41.000000000 +0100
16197 +++ linux-3.0.4-vs2.3.1-pre10.1/ipc/mqueue.c    2011-06-10 22:11:24.000000000 +0200
16198 @@ -33,6 +33,8 @@
16199  #include <linux/pid.h>
16200  #include <linux/ipc_namespace.h>
16201  #include <linux/slab.h>
16202 +#include <linux/vs_context.h>
16203 +#include <linux/vs_limit.h>
16204  
16205  #include <net/sock.h>
16206  #include "util.h"
16207 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
16208         struct sigevent notify;
16209         struct pid* notify_owner;
16210         struct user_struct *user;       /* user who created, for accounting */
16211 +       struct vx_info *vxi;
16212         struct sock *notify_sock;
16213         struct sk_buff *notify_cookie;
16214  
16215 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
16216                 if (S_ISREG(mode)) {
16217                         struct mqueue_inode_info *info;
16218                         struct task_struct *p = current;
16219 +                       struct vx_info *vxi = p->vx_info;
16220                         unsigned long mq_bytes, mq_msg_tblsz;
16221  
16222                         inode->i_fop = &mqueue_file_operations;
16223 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
16224                         info->notify_owner = NULL;
16225                         info->qsize = 0;
16226                         info->user = NULL;      /* set when all is ok */
16227 +                       info->vxi = NULL;
16228                         memset(&info->attr, 0, sizeof(info->attr));
16229                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
16230                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
16231 @@ -157,16 +162,19 @@ static struct inode *mqueue_get_inode(st
16232                         spin_lock(&mq_lock);
16233                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
16234                             u->mq_bytes + mq_bytes >
16235 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
16236 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
16237 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
16238                                 spin_unlock(&mq_lock);
16239                                 /* mqueue_evict_inode() releases info->messages */
16240                                 goto out_inode;
16241                         }
16242                         u->mq_bytes += mq_bytes;
16243 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
16244                         spin_unlock(&mq_lock);
16245  
16246                         /* all is ok */
16247                         info->user = get_uid(u);
16248 +                       info->vxi = get_vx_info(vxi);
16249                 } else if (S_ISDIR(mode)) {
16250                         inc_nlink(inode);
16251                         /* Some things misbehave if size == 0 on a directory */
16252 @@ -275,8 +283,11 @@ static void mqueue_evict_inode(struct in
16253             + info->attr.mq_msgsize);
16254         user = info->user;
16255         if (user) {
16256 +               struct vx_info *vxi = info->vxi;
16257 +
16258                 spin_lock(&mq_lock);
16259                 user->mq_bytes -= mq_bytes;
16260 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
16261                 /*
16262                  * get_ns_from_inode() ensures that the
16263                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
16264 @@ -286,6 +297,7 @@ static void mqueue_evict_inode(struct in
16265                 if (ipc_ns)
16266                         ipc_ns->mq_queues_count--;
16267                 spin_unlock(&mq_lock);
16268 +               put_vx_info(vxi);
16269                 free_uid(user);
16270         }
16271         if (ipc_ns)
16272 diff -NurpP --minimal linux-3.0.4/ipc/msg.c linux-3.0.4-vs2.3.1-pre10.1/ipc/msg.c
16273 --- linux-3.0.4/ipc/msg.c       2011-05-22 16:17:59.000000000 +0200
16274 +++ linux-3.0.4-vs2.3.1-pre10.1/ipc/msg.c       2011-06-10 22:11:24.000000000 +0200
16275 @@ -37,6 +37,7 @@
16276  #include <linux/rwsem.h>
16277  #include <linux/nsproxy.h>
16278  #include <linux/ipc_namespace.h>
16279 +#include <linux/vs_base.h>
16280  
16281  #include <asm/current.h>
16282  #include <asm/uaccess.h>
16283 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
16284  
16285         msq->q_perm.mode = msgflg & S_IRWXUGO;
16286         msq->q_perm.key = key;
16287 +       msq->q_perm.xid = vx_current_xid();
16288  
16289         msq->q_perm.security = NULL;
16290         retval = security_msg_queue_alloc(msq);
16291 diff -NurpP --minimal linux-3.0.4/ipc/namespace.c linux-3.0.4-vs2.3.1-pre10.1/ipc/namespace.c
16292 --- linux-3.0.4/ipc/namespace.c 2011-07-22 11:18:12.000000000 +0200
16293 +++ linux-3.0.4-vs2.3.1-pre10.1/ipc/namespace.c 2011-06-13 14:09:44.000000000 +0200
16294 @@ -13,11 +13,12 @@
16295  #include <linux/mount.h>
16296  #include <linux/user_namespace.h>
16297  #include <linux/proc_fs.h>
16298 +#include <linux/vs_base.h>
16299 +#include <linux/vserver/global.h>
16300  
16301  #include "util.h"
16302  
16303 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
16304 -                                          struct ipc_namespace *old_ns)
16305 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
16306  {
16307         struct ipc_namespace *ns;
16308         int err;
16309 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
16310         ipcns_notify(IPCNS_CREATED);
16311         register_ipcns_notifier(ns);
16312  
16313 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
16314 +       ns->user_ns = get_user_ns(user_ns);
16315  
16316         return ns;
16317  }
16318  
16319  struct ipc_namespace *copy_ipcs(unsigned long flags,
16320 -                               struct task_struct *tsk)
16321 +                               struct ipc_namespace *old_ns,
16322 +                               struct user_namespace *user_ns)
16323  {
16324 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
16325 -
16326         if (!(flags & CLONE_NEWIPC))
16327 -               return get_ipc_ns(ns);
16328 -       return create_ipc_ns(tsk, ns);
16329 +               return get_ipc_ns(old_ns);
16330 +       return create_ipc_ns(user_ns);
16331  }
16332  
16333  /*
16334 diff -NurpP --minimal linux-3.0.4/ipc/sem.c linux-3.0.4-vs2.3.1-pre10.1/ipc/sem.c
16335 --- linux-3.0.4/ipc/sem.c       2011-08-31 18:56:42.000000000 +0200
16336 +++ linux-3.0.4-vs2.3.1-pre10.1/ipc/sem.c       2011-08-08 23:04:47.000000000 +0200
16337 @@ -86,6 +86,8 @@
16338  #include <linux/rwsem.h>
16339  #include <linux/nsproxy.h>
16340  #include <linux/ipc_namespace.h>
16341 +#include <linux/vs_base.h>
16342 +#include <linux/vs_limit.h>
16343  
16344  #include <asm/uaccess.h>
16345  #include "util.h"
16346 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
16347  
16348         sma->sem_perm.mode = (semflg & S_IRWXUGO);
16349         sma->sem_perm.key = key;
16350 +       sma->sem_perm.xid = vx_current_xid();
16351  
16352         sma->sem_perm.security = NULL;
16353         retval = security_sem_alloc(sma);
16354 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
16355                 return id;
16356         }
16357         ns->used_sems += nsems;
16358 +       /* FIXME: obsoleted? */
16359 +       vx_semary_inc(sma);
16360 +       vx_nsems_add(sma, nsems);
16361  
16362         sma->sem_base = (struct sem *) &sma[1];
16363  
16364 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
16365  
16366         wake_up_sem_queue_do(&tasks);
16367         ns->used_sems -= sma->sem_nsems;
16368 +       /* FIXME: obsoleted? */
16369 +       vx_nsems_sub(sma, sma->sem_nsems);
16370 +       vx_semary_dec(sma);
16371         security_sem_free(sma);
16372         ipc_rcu_putref(sma);
16373  }
16374 diff -NurpP --minimal linux-3.0.4/ipc/shm.c linux-3.0.4-vs2.3.1-pre10.1/ipc/shm.c
16375 --- linux-3.0.4/ipc/shm.c       2011-07-22 11:18:12.000000000 +0200
16376 +++ linux-3.0.4-vs2.3.1-pre10.1/ipc/shm.c       2011-06-10 22:11:24.000000000 +0200
16377 @@ -39,6 +39,8 @@
16378  #include <linux/nsproxy.h>
16379  #include <linux/mount.h>
16380  #include <linux/ipc_namespace.h>
16381 +#include <linux/vs_context.h>
16382 +#include <linux/vs_limit.h>
16383  
16384  #include <asm/uaccess.h>
16385  
16386 @@ -173,7 +175,12 @@ static void shm_open(struct vm_area_stru
16387   */
16388  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
16389  {
16390 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
16391 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
16392 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
16393 +
16394 +       vx_ipcshm_sub(vxi, shp, numpages);
16395 +       ns->shm_tot -= numpages;
16396 +
16397         shm_rmid(ns, shp);
16398         shm_unlock(shp);
16399         if (!is_file_hugepages(shp->shm_file))
16400 @@ -183,6 +190,7 @@ static void shm_destroy(struct ipc_names
16401                                                 shp->mlock_user);
16402         fput (shp->shm_file);
16403         security_shm_free(shp);
16404 +       put_vx_info(vxi);
16405         ipc_rcu_putref(shp);
16406  }
16407  
16408 @@ -355,11 +363,15 @@ static int newseg(struct ipc_namespace *
16409         if (ns->shm_tot + numpages > ns->shm_ctlall)
16410                 return -ENOSPC;
16411  
16412 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
16413 +               return -ENOSPC;
16414 +
16415         shp = ipc_rcu_alloc(sizeof(*shp));
16416         if (!shp)
16417                 return -ENOMEM;
16418  
16419         shp->shm_perm.key = key;
16420 +       shp->shm_perm.xid = vx_current_xid();
16421         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
16422         shp->mlock_user = NULL;
16423  
16424 @@ -413,6 +425,7 @@ static int newseg(struct ipc_namespace *
16425         ns->shm_tot += numpages;
16426         error = shp->shm_perm.id;
16427         shm_unlock(shp);
16428 +       vx_ipcshm_add(current_vx_info(), key, numpages);
16429         return error;
16430  
16431  no_id:
16432 diff -NurpP --minimal linux-3.0.4/kernel/Makefile linux-3.0.4-vs2.3.1-pre10.1/kernel/Makefile
16433 --- linux-3.0.4/kernel/Makefile 2011-07-22 11:18:12.000000000 +0200
16434 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/Makefile 2011-06-10 22:11:24.000000000 +0200
16435 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
16436  CFLAGS_REMOVE_irq_work.o = -pg
16437  endif
16438  
16439 +obj-y += vserver/
16440  obj-$(CONFIG_FREEZER) += freezer.o
16441  obj-$(CONFIG_PROFILING) += profile.o
16442  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
16443 diff -NurpP --minimal linux-3.0.4/kernel/capability.c linux-3.0.4-vs2.3.1-pre10.1/kernel/capability.c
16444 --- linux-3.0.4/kernel/capability.c     2011-07-22 11:18:12.000000000 +0200
16445 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/capability.c     2011-07-19 19:27:53.000000000 +0200
16446 @@ -15,6 +15,7 @@
16447  #include <linux/syscalls.h>
16448  #include <linux/pid_namespace.h>
16449  #include <linux/user_namespace.h>
16450 +#include <linux/vs_context.h>
16451  #include <asm/uaccess.h>
16452  
16453  /*
16454 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
16455         return 0;
16456  }
16457  
16458 +
16459  /*
16460   * The only thing that can change the capabilities of the current
16461   * process is the current process. As such, we can't be in this code
16462 @@ -340,6 +342,8 @@ bool has_capability_noaudit(struct task_
16463         return (ret == 0);
16464  }
16465  
16466 +#include <linux/vserver/base.h>
16467 +
16468  /**
16469   * capable - Determine if the current task has a superior capability in effect
16470   * @cap: The capability to be tested for
16471 @@ -374,6 +378,9 @@ bool ns_capable(struct user_namespace *n
16472                 BUG();
16473         }
16474  
16475 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
16476 +               return true;
16477 +
16478         if (security_capable(ns, current_cred(), cap) == 0) {
16479                 current->flags |= PF_SUPERPRIV;
16480                 return true;
16481 diff -NurpP --minimal linux-3.0.4/kernel/compat.c linux-3.0.4-vs2.3.1-pre10.1/kernel/compat.c
16482 --- linux-3.0.4/kernel/compat.c 2011-07-22 11:18:12.000000000 +0200
16483 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/compat.c 2011-06-10 22:11:24.000000000 +0200
16484 @@ -970,7 +970,7 @@ asmlinkage long compat_sys_stime(compat_
16485         if (err)
16486                 return err;
16487  
16488 -       do_settimeofday(&tv);
16489 +       vx_settimeofday(&tv);
16490         return 0;
16491  }
16492  
16493 diff -NurpP --minimal linux-3.0.4/kernel/cred.c linux-3.0.4-vs2.3.1-pre10.1/kernel/cred.c
16494 --- linux-3.0.4/kernel/cred.c   2011-07-22 11:18:12.000000000 +0200
16495 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/cred.c   2011-06-10 22:11:24.000000000 +0200
16496 @@ -61,31 +61,6 @@ struct cred init_cred = {
16497  #endif
16498  };
16499  
16500 -static inline void set_cred_subscribers(struct cred *cred, int n)
16501 -{
16502 -#ifdef CONFIG_DEBUG_CREDENTIALS
16503 -       atomic_set(&cred->subscribers, n);
16504 -#endif
16505 -}
16506 -
16507 -static inline int read_cred_subscribers(const struct cred *cred)
16508 -{
16509 -#ifdef CONFIG_DEBUG_CREDENTIALS
16510 -       return atomic_read(&cred->subscribers);
16511 -#else
16512 -       return 0;
16513 -#endif
16514 -}
16515 -
16516 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
16517 -{
16518 -#ifdef CONFIG_DEBUG_CREDENTIALS
16519 -       struct cred *cred = (struct cred *) _cred;
16520 -
16521 -       atomic_add(n, &cred->subscribers);
16522 -#endif
16523 -}
16524 -
16525  /*
16526   * Dispose of the shared task group credentials
16527   */
16528 @@ -281,21 +256,16 @@ error:
16529   *
16530   * Call commit_creds() or abort_creds() to clean up.
16531   */
16532 -struct cred *prepare_creds(void)
16533 +struct cred *__prepare_creds(const struct cred *old)
16534  {
16535 -       struct task_struct *task = current;
16536 -       const struct cred *old;
16537         struct cred *new;
16538  
16539 -       validate_process_creds();
16540 -
16541         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
16542         if (!new)
16543                 return NULL;
16544  
16545         kdebug("prepare_creds() alloc %p", new);
16546  
16547 -       old = task->cred;
16548         memcpy(new, old, sizeof(struct cred));
16549  
16550         atomic_set(&new->usage, 1);
16551 @@ -322,6 +292,13 @@ error:
16552         abort_creds(new);
16553         return NULL;
16554  }
16555 +
16556 +struct cred *prepare_creds(void)
16557 +{
16558 +       validate_process_creds();
16559 +
16560 +       return __prepare_creds(current->cred);
16561 +}
16562  EXPORT_SYMBOL(prepare_creds);
16563  
16564  /*
16565 diff -NurpP --minimal linux-3.0.4/kernel/exit.c linux-3.0.4-vs2.3.1-pre10.1/kernel/exit.c
16566 --- linux-3.0.4/kernel/exit.c   2011-07-22 11:18:12.000000000 +0200
16567 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/exit.c   2011-06-22 12:39:15.000000000 +0200
16568 @@ -48,6 +48,10 @@
16569  #include <linux/fs_struct.h>
16570  #include <linux/init_task.h>
16571  #include <linux/perf_event.h>
16572 +#include <linux/vs_limit.h>
16573 +#include <linux/vs_context.h>
16574 +#include <linux/vs_network.h>
16575 +#include <linux/vs_pid.h>
16576  #include <trace/events/sched.h>
16577  #include <linux/hw_breakpoint.h>
16578  #include <linux/oom.h>
16579 @@ -494,9 +498,11 @@ static void close_files(struct files_str
16580                                         filp_close(file, files);
16581                                         cond_resched();
16582                                 }
16583 +                               vx_openfd_dec(i);
16584                         }
16585                         i++;
16586                         set >>= 1;
16587 +                       cond_resched();
16588                 }
16589         }
16590  }
16591 @@ -1047,11 +1053,16 @@ NORET_TYPE void do_exit(long code)
16592  
16593         validate_creds_for_do_exit(tsk);
16594  
16595 +       /* needs to stay after exit_notify() */
16596 +       exit_vx_info(tsk, code);
16597 +       exit_nx_info(tsk);
16598 +
16599         preempt_disable();
16600         exit_rcu();
16601         /* causes final put_task_struct in finish_task_switch(). */
16602         tsk->state = TASK_DEAD;
16603         schedule();
16604 +       printk("bad task: %p [%lx]\n", current, current->state);
16605         BUG();
16606         /* Avoid "noreturn function does return".  */
16607         for (;;)
16608 diff -NurpP --minimal linux-3.0.4/kernel/fork.c linux-3.0.4-vs2.3.1-pre10.1/kernel/fork.c
16609 --- linux-3.0.4/kernel/fork.c   2011-07-22 11:18:12.000000000 +0200
16610 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/fork.c   2011-06-10 22:21:02.000000000 +0200
16611 @@ -67,6 +67,10 @@
16612  #include <linux/user-return-notifier.h>
16613  #include <linux/oom.h>
16614  #include <linux/khugepaged.h>
16615 +#include <linux/vs_context.h>
16616 +#include <linux/vs_network.h>
16617 +#include <linux/vs_limit.h>
16618 +#include <linux/vs_memory.h>
16619  
16620  #include <asm/pgtable.h>
16621  #include <asm/pgalloc.h>
16622 @@ -167,6 +171,8 @@ void free_task(struct task_struct *tsk)
16623         account_kernel_stack(tsk->stack, -1);
16624         free_thread_info(tsk->stack);
16625         rt_mutex_debug_task_free(tsk);
16626 +       clr_vx_info(&tsk->vx_info);
16627 +       clr_nx_info(&tsk->nx_info);
16628         ftrace_graph_exit_task(tsk);
16629         free_task_struct(tsk);
16630  }
16631 @@ -505,6 +511,7 @@ static struct mm_struct * mm_init(struct
16632         if (likely(!mm_alloc_pgd(mm))) {
16633                 mm->def_flags = 0;
16634                 mmu_notifier_mm_init(mm);
16635 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
16636                 return mm;
16637         }
16638  
16639 @@ -542,6 +549,7 @@ void __mmdrop(struct mm_struct *mm)
16640  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
16641         VM_BUG_ON(mm->pmd_huge_pte);
16642  #endif
16643 +       clr_vx_info(&mm->mm_vx_info);
16644         free_mm(mm);
16645  }
16646  EXPORT_SYMBOL_GPL(__mmdrop);
16647 @@ -729,6 +737,7 @@ struct mm_struct *dup_mm(struct task_str
16648                 goto fail_nomem;
16649  
16650         memcpy(mm, oldmm, sizeof(*mm));
16651 +       mm->mm_vx_info = NULL;
16652         mm_init_cpumask(mm);
16653  
16654         /* Initializing for Swap token stuff */
16655 @@ -772,6 +781,7 @@ fail_nocontext:
16656          * If init_new_context() failed, we cannot use mmput() to free the mm
16657          * because it calls destroy_context()
16658          */
16659 +       clr_vx_info(&mm->mm_vx_info);
16660         mm_free_pgd(mm);
16661         free_mm(mm);
16662         return NULL;
16663 @@ -1057,6 +1067,8 @@ static struct task_struct *copy_process(
16664         int retval;
16665         struct task_struct *p;
16666         int cgroup_callbacks_done = 0;
16667 +       struct vx_info *vxi;
16668 +       struct nx_info *nxi;
16669  
16670         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
16671                 return ERR_PTR(-EINVAL);
16672 @@ -1103,7 +1115,12 @@ static struct task_struct *copy_process(
16673         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
16674         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
16675  #endif
16676 +       init_vx_info(&p->vx_info, current_vx_info());
16677 +       init_nx_info(&p->nx_info, current_nx_info());
16678 +
16679         retval = -EAGAIN;
16680 +       if (!vx_nproc_avail(1))
16681 +               goto bad_fork_free;
16682         if (atomic_read(&p->real_cred->user->processes) >=
16683                         task_rlimit(p, RLIMIT_NPROC)) {
16684                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
16685 @@ -1360,6 +1377,18 @@ static struct task_struct *copy_process(
16686  
16687         total_forks++;
16688         spin_unlock(&current->sighand->siglock);
16689 +
16690 +       /* p is copy of current */
16691 +       vxi = p->vx_info;
16692 +       if (vxi) {
16693 +               claim_vx_info(vxi, p);
16694 +               atomic_inc(&vxi->cvirt.nr_threads);
16695 +               atomic_inc(&vxi->cvirt.total_forks);
16696 +               vx_nproc_inc(p);
16697 +       }
16698 +       nxi = p->nx_info;
16699 +       if (nxi)
16700 +               claim_nx_info(nxi, p);
16701         write_unlock_irq(&tasklist_lock);
16702         proc_fork_connector(p);
16703         cgroup_post_fork(p);
16704 diff -NurpP --minimal linux-3.0.4/kernel/kthread.c linux-3.0.4-vs2.3.1-pre10.1/kernel/kthread.c
16705 --- linux-3.0.4/kernel/kthread.c        2011-07-22 11:18:12.000000000 +0200
16706 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/kthread.c        2011-06-10 22:11:24.000000000 +0200
16707 @@ -16,6 +16,7 @@
16708  #include <linux/mutex.h>
16709  #include <linux/slab.h>
16710  #include <linux/freezer.h>
16711 +#include <linux/vs_pid.h>
16712  #include <trace/events/sched.h>
16713  
16714  static DEFINE_SPINLOCK(kthread_create_lock);
16715 diff -NurpP --minimal linux-3.0.4/kernel/nsproxy.c linux-3.0.4-vs2.3.1-pre10.1/kernel/nsproxy.c
16716 --- linux-3.0.4/kernel/nsproxy.c        2011-07-22 11:18:12.000000000 +0200
16717 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/nsproxy.c        2011-06-13 14:09:44.000000000 +0200
16718 @@ -20,6 +20,8 @@
16719  #include <linux/mnt_namespace.h>
16720  #include <linux/utsname.h>
16721  #include <linux/pid_namespace.h>
16722 +#include <linux/vserver/global.h>
16723 +#include <linux/vserver/debug.h>
16724  #include <net/net_namespace.h>
16725  #include <linux/ipc_namespace.h>
16726  #include <linux/proc_fs.h>
16727 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
16728         struct nsproxy *nsproxy;
16729  
16730         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
16731 -       if (nsproxy)
16732 +       if (nsproxy) {
16733                 atomic_set(&nsproxy->count, 1);
16734 +               atomic_inc(&vs_global_nsproxy);
16735 +       }
16736 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
16737         return nsproxy;
16738  }
16739  
16740 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
16741   * Return the newly created nsproxy.  Do not attach this to the task,
16742   * leave it to the caller to do proper locking and attach it to task.
16743   */
16744 -static struct nsproxy *create_new_namespaces(unsigned long flags,
16745 -                       struct task_struct *tsk, struct fs_struct *new_fs)
16746 +static struct nsproxy *unshare_namespaces(unsigned long flags,
16747 +                       struct nsproxy *orig,
16748 +                       struct fs_struct *new_fs,
16749 +                       struct user_namespace *new_user,
16750 +                       struct pid_namespace *new_pid)
16751  {
16752         struct nsproxy *new_nsp;
16753         int err;
16754 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
16755         if (!new_nsp)
16756                 return ERR_PTR(-ENOMEM);
16757  
16758 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
16759 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
16760         if (IS_ERR(new_nsp->mnt_ns)) {
16761                 err = PTR_ERR(new_nsp->mnt_ns);
16762                 goto out_ns;
16763         }
16764  
16765 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
16766 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
16767         if (IS_ERR(new_nsp->uts_ns)) {
16768                 err = PTR_ERR(new_nsp->uts_ns);
16769                 goto out_uts;
16770         }
16771  
16772 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
16773 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
16774         if (IS_ERR(new_nsp->ipc_ns)) {
16775                 err = PTR_ERR(new_nsp->ipc_ns);
16776                 goto out_ipc;
16777         }
16778  
16779 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
16780 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
16781         if (IS_ERR(new_nsp->pid_ns)) {
16782                 err = PTR_ERR(new_nsp->pid_ns);
16783                 goto out_pid;
16784         }
16785  
16786 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
16787 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
16788         if (IS_ERR(new_nsp->net_ns)) {
16789                 err = PTR_ERR(new_nsp->net_ns);
16790                 goto out_net;
16791 @@ -115,6 +123,40 @@ out_ns:
16792         return ERR_PTR(err);
16793  }
16794  
16795 +static struct nsproxy *create_new_namespaces(unsigned long flags,
16796 +                       struct task_struct *tsk, struct fs_struct *new_fs)
16797 +{
16798 +       return unshare_namespaces(flags, tsk->nsproxy,
16799 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
16800 +               task_active_pid_ns(tsk));
16801 +}
16802 +
16803 +/*
16804 + * copies the nsproxy, setting refcount to 1, and grabbing a
16805 + * reference to all contained namespaces.
16806 + */
16807 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
16808 +{
16809 +       struct nsproxy *ns = create_nsproxy();
16810 +
16811 +       if (ns) {
16812 +               memcpy(ns, orig, sizeof(struct nsproxy));
16813 +               atomic_set(&ns->count, 1);
16814 +
16815 +               if (ns->mnt_ns)
16816 +                       get_mnt_ns(ns->mnt_ns);
16817 +               if (ns->uts_ns)
16818 +                       get_uts_ns(ns->uts_ns);
16819 +               if (ns->ipc_ns)
16820 +                       get_ipc_ns(ns->ipc_ns);
16821 +               if (ns->pid_ns)
16822 +                       get_pid_ns(ns->pid_ns);
16823 +               if (ns->net_ns)
16824 +                       get_net(ns->net_ns);
16825 +       }
16826 +       return ns;
16827 +}
16828 +
16829  /*
16830   * called from clone.  This now handles copy for nsproxy and all
16831   * namespaces therein.
16832 @@ -122,9 +164,12 @@ out_ns:
16833  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
16834  {
16835         struct nsproxy *old_ns = tsk->nsproxy;
16836 -       struct nsproxy *new_ns;
16837 +       struct nsproxy *new_ns = NULL;
16838         int err = 0;
16839  
16840 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
16841 +               flags, tsk, old_ns);
16842 +
16843         if (!old_ns)
16844                 return 0;
16845  
16846 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
16847                                 CLONE_NEWPID | CLONE_NEWNET)))
16848                 return 0;
16849  
16850 -       if (!capable(CAP_SYS_ADMIN)) {
16851 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
16852                 err = -EPERM;
16853                 goto out;
16854         }
16855 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
16856  
16857  out:
16858         put_nsproxy(old_ns);
16859 +       vxdprintk(VXD_CBIT(space, 3),
16860 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
16861 +               flags, tsk, old_ns, err, new_ns);
16862         return err;
16863  }
16864  
16865 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
16866                 put_ipc_ns(ns->ipc_ns);
16867         if (ns->pid_ns)
16868                 put_pid_ns(ns->pid_ns);
16869 -       put_net(ns->net_ns);
16870 +       if (ns->net_ns)
16871 +               put_net(ns->net_ns);
16872 +       atomic_dec(&vs_global_nsproxy);
16873         kmem_cache_free(nsproxy_cachep, ns);
16874  }
16875  
16876 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
16877  {
16878         int err = 0;
16879  
16880 +       vxdprintk(VXD_CBIT(space, 4),
16881 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
16882 +               unshare_flags, current->nsproxy);
16883 +
16884         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
16885                                CLONE_NEWNET)))
16886                 return 0;
16887  
16888 -       if (!capable(CAP_SYS_ADMIN))
16889 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
16890                 return -EPERM;
16891  
16892         *new_nsp = create_new_namespaces(unshare_flags, current,
16893 diff -NurpP --minimal linux-3.0.4/kernel/pid.c linux-3.0.4-vs2.3.1-pre10.1/kernel/pid.c
16894 --- linux-3.0.4/kernel/pid.c    2011-05-22 16:17:59.000000000 +0200
16895 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/pid.c    2011-06-10 22:11:24.000000000 +0200
16896 @@ -36,6 +36,7 @@
16897  #include <linux/pid_namespace.h>
16898  #include <linux/init_task.h>
16899  #include <linux/syscalls.h>
16900 +#include <linux/vs_pid.h>
16901  
16902  #define pid_hashfn(nr, ns)     \
16903         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
16904 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
16905  
16906  struct pid *find_vpid(int nr)
16907  {
16908 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
16909 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
16910  }
16911  EXPORT_SYMBOL_GPL(find_vpid);
16912  
16913 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
16914  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
16915  {
16916         struct task_struct *result = NULL;
16917 +
16918 +       if (type == PIDTYPE_REALPID)
16919 +               type = PIDTYPE_PID;
16920         if (pid) {
16921                 struct hlist_node *first;
16922                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
16923 @@ -420,7 +424,7 @@ EXPORT_SYMBOL(pid_task);
16924  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
16925  {
16926         rcu_lockdep_assert(rcu_read_lock_held());
16927 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
16928 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
16929  }
16930  
16931  struct task_struct *find_task_by_vpid(pid_t vnr)
16932 @@ -464,7 +468,7 @@ struct pid *find_get_pid(pid_t nr)
16933  }
16934  EXPORT_SYMBOL_GPL(find_get_pid);
16935  
16936 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
16937 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
16938  {
16939         struct upid *upid;
16940         pid_t nr = 0;
16941 @@ -477,6 +481,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
16942         return nr;
16943  }
16944  
16945 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
16946 +{
16947 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
16948 +}
16949 +
16950  pid_t pid_vnr(struct pid *pid)
16951  {
16952         return pid_nr_ns(pid, current->nsproxy->pid_ns);
16953 diff -NurpP --minimal linux-3.0.4/kernel/pid_namespace.c linux-3.0.4-vs2.3.1-pre10.1/kernel/pid_namespace.c
16954 --- linux-3.0.4/kernel/pid_namespace.c  2011-05-22 16:17:59.000000000 +0200
16955 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/pid_namespace.c  2011-06-10 22:17:45.000000000 +0200
16956 @@ -15,6 +15,7 @@
16957  #include <linux/acct.h>
16958  #include <linux/slab.h>
16959  #include <linux/proc_fs.h>
16960 +#include <linux/vserver/global.h>
16961  
16962  #define BITS_PER_PAGE          (PAGE_SIZE*8)
16963  
16964 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
16965                 goto out_free_map;
16966  
16967         kref_init(&ns->kref);
16968 +       atomic_inc(&vs_global_pid_ns);
16969         ns->level = level;
16970         ns->parent = get_pid_ns(parent_pid_ns);
16971  
16972 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
16973  
16974         for (i = 0; i < PIDMAP_ENTRIES; i++)
16975                 kfree(ns->pidmap[i].page);
16976 +       atomic_dec(&vs_global_pid_ns);
16977         kmem_cache_free(pid_ns_cachep, ns);
16978  }
16979  
16980 diff -NurpP --minimal linux-3.0.4/kernel/posix-timers.c linux-3.0.4-vs2.3.1-pre10.1/kernel/posix-timers.c
16981 --- linux-3.0.4/kernel/posix-timers.c   2011-07-22 11:18:12.000000000 +0200
16982 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/posix-timers.c   2011-06-10 22:11:24.000000000 +0200
16983 @@ -47,6 +47,7 @@
16984  #include <linux/wait.h>
16985  #include <linux/workqueue.h>
16986  #include <linux/module.h>
16987 +#include <linux/vs_context.h>
16988  
16989  /*
16990   * Management arrays for POSIX timers.  Timers are kept in slab memory
16991 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
16992  {
16993         struct task_struct *task;
16994         int shared, ret = -1;
16995 +
16996         /*
16997          * FIXME: if ->sigq is queued we can race with
16998          * dequeue_signal()->do_schedule_next_timer().
16999 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
17000         rcu_read_lock();
17001         task = pid_task(timr->it_pid, PIDTYPE_PID);
17002         if (task) {
17003 +               struct vx_info_save vxis;
17004 +               struct vx_info *vxi;
17005 +
17006 +               vxi = get_vx_info(task->vx_info);
17007 +               enter_vx_info(vxi, &vxis);
17008                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
17009                 ret = send_sigqueue(timr->sigq, task, shared);
17010 +               leave_vx_info(&vxis);
17011 +               put_vx_info(vxi);
17012         }
17013         rcu_read_unlock();
17014 +
17015         /* If we failed to send the signal the timer stops. */
17016         return ret > 0;
17017  }
17018 diff -NurpP --minimal linux-3.0.4/kernel/printk.c linux-3.0.4-vs2.3.1-pre10.1/kernel/printk.c
17019 --- linux-3.0.4/kernel/printk.c 2011-07-22 11:18:12.000000000 +0200
17020 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/printk.c 2011-06-10 22:11:24.000000000 +0200
17021 @@ -41,6 +41,7 @@
17022  #include <linux/cpu.h>
17023  #include <linux/notifier.h>
17024  #include <linux/rculist.h>
17025 +#include <linux/vs_cvirt.h>
17026  
17027  #include <asm/uaccess.h>
17028  
17029 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
17030                 return 0;
17031  
17032         if (syslog_action_restricted(type)) {
17033 -               if (capable(CAP_SYSLOG))
17034 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
17035                         return 0;
17036                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
17037                 if (capable(CAP_SYS_ADMIN)) {
17038 @@ -342,12 +343,9 @@ int do_syslog(int type, char __user *buf
17039         if (error)
17040                 return error;
17041  
17042 -       switch (type) {
17043 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
17044 -               break;
17045 -       case SYSLOG_ACTION_OPEN:        /* Open log */
17046 -               break;
17047 -       case SYSLOG_ACTION_READ:        /* Read from log */
17048 +       if ((type == SYSLOG_ACTION_READ) ||
17049 +           (type == SYSLOG_ACTION_READ_ALL) ||
17050 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
17051                 error = -EINVAL;
17052                 if (!buf || len < 0)
17053                         goto out;
17054 @@ -358,6 +356,16 @@ int do_syslog(int type, char __user *buf
17055                         error = -EFAULT;
17056                         goto out;
17057                 }
17058 +       }
17059 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17060 +               return vx_do_syslog(type, buf, len);
17061 +
17062 +       switch (type) {
17063 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
17064 +               break;
17065 +       case SYSLOG_ACTION_OPEN:        /* Open log */
17066 +               break;
17067 +       case SYSLOG_ACTION_READ:        /* Read from log */
17068                 error = wait_event_interruptible(log_wait,
17069                                                         (log_start - log_end));
17070                 if (error)
17071 @@ -384,16 +392,6 @@ int do_syslog(int type, char __user *buf
17072                 /* FALL THRU */
17073         /* Read last kernel messages */
17074         case SYSLOG_ACTION_READ_ALL:
17075 -               error = -EINVAL;
17076 -               if (!buf || len < 0)
17077 -                       goto out;
17078 -               error = 0;
17079 -               if (!len)
17080 -                       goto out;
17081 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
17082 -                       error = -EFAULT;
17083 -                       goto out;
17084 -               }
17085                 count = len;
17086                 if (count > log_buf_len)
17087                         count = log_buf_len;
17088 diff -NurpP --minimal linux-3.0.4/kernel/ptrace.c linux-3.0.4-vs2.3.1-pre10.1/kernel/ptrace.c
17089 --- linux-3.0.4/kernel/ptrace.c 2011-07-22 11:18:12.000000000 +0200
17090 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/ptrace.c 2011-06-10 22:11:24.000000000 +0200
17091 @@ -22,6 +22,7 @@
17092  #include <linux/syscalls.h>
17093  #include <linux/uaccess.h>
17094  #include <linux/regset.h>
17095 +#include <linux/vs_context.h>
17096  #include <linux/hw_breakpoint.h>
17097  
17098  
17099 @@ -169,6 +170,11 @@ ok:
17100                 dumpable = get_dumpable(task->mm);
17101         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
17102                 return -EPERM;
17103 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
17104 +               return -EPERM;
17105 +       if (!vx_check(task->xid, VS_IDENT) &&
17106 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
17107 +               return -EACCES;
17108  
17109         return security_ptrace_access_check(task, mode);
17110  }
17111 diff -NurpP --minimal linux-3.0.4/kernel/sched.c linux-3.0.4-vs2.3.1-pre10.1/kernel/sched.c
17112 --- linux-3.0.4/kernel/sched.c  2011-07-22 11:18:12.000000000 +0200
17113 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/sched.c  2011-07-22 11:20:39.000000000 +0200
17114 @@ -71,6 +71,8 @@
17115  #include <linux/ctype.h>
17116  #include <linux/ftrace.h>
17117  #include <linux/slab.h>
17118 +#include <linux/vs_sched.h>
17119 +#include <linux/vs_cvirt.h>
17120  
17121  #include <asm/tlb.h>
17122  #include <asm/irq_regs.h>
17123 @@ -3461,9 +3463,17 @@ static void calc_global_nohz(unsigned lo
17124   */
17125  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
17126  {
17127 -       loads[0] = (avenrun[0] + offset) << shift;
17128 -       loads[1] = (avenrun[1] + offset) << shift;
17129 -       loads[2] = (avenrun[2] + offset) << shift;
17130 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
17131 +               struct vx_info *vxi = current_vx_info();
17132 +
17133 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
17134 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
17135 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
17136 +       } else {
17137 +               loads[0] = (avenrun[0] + offset) << shift;
17138 +               loads[1] = (avenrun[1] + offset) << shift;
17139 +               loads[2] = (avenrun[2] + offset) << shift;
17140 +       }
17141  }
17142  
17143  /*
17144 @@ -3746,16 +3756,19 @@ void account_user_time(struct task_struc
17145                        cputime_t cputime_scaled)
17146  {
17147         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
17148 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
17149         cputime64_t tmp;
17150 +       int nice = (TASK_NICE(p) > 0);
17151  
17152         /* Add user time to process. */
17153         p->utime = cputime_add(p->utime, cputime);
17154         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
17155 +       vx_account_user(vxi, cputime, nice);
17156         account_group_user_time(p, cputime);
17157  
17158         /* Add user time to cpustat. */
17159         tmp = cputime_to_cputime64(cputime);
17160 -       if (TASK_NICE(p) > 0)
17161 +       if (nice)
17162                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
17163         else
17164                 cpustat->user = cputime64_add(cpustat->user, tmp);
17165 @@ -3807,10 +3820,12 @@ void __account_system_time(struct task_s
17166                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
17167  {
17168         cputime64_t tmp = cputime_to_cputime64(cputime);
17169 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
17170  
17171         /* Add system time to process. */
17172         p->stime = cputime_add(p->stime, cputime);
17173         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
17174 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
17175         account_group_system_time(p, cputime);
17176  
17177         /* Add system time to cpustat. */
17178 @@ -4968,7 +4983,7 @@ SYSCALL_DEFINE1(nice, int, increment)
17179                 nice = 19;
17180  
17181         if (increment < 0 && !can_nice(current, nice))
17182 -               return -EPERM;
17183 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
17184  
17185         retval = security_task_setnice(current, nice);
17186         if (retval)
17187 diff -NurpP --minimal linux-3.0.4/kernel/sched_fair.c linux-3.0.4-vs2.3.1-pre10.1/kernel/sched_fair.c
17188 --- linux-3.0.4/kernel/sched_fair.c     2011-07-22 11:18:12.000000000 +0200
17189 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/sched_fair.c     2011-07-22 11:20:39.000000000 +0200
17190 @@ -998,6 +998,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
17191                 __enqueue_entity(cfs_rq, se);
17192         se->on_rq = 1;
17193  
17194 +       if (entity_is_task(se))
17195 +               vx_activate_task(task_of(se));
17196         if (cfs_rq->nr_running == 1)
17197                 list_add_leaf_cfs_rq(cfs_rq);
17198  }
17199 @@ -1074,6 +1076,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
17200         if (se != cfs_rq->curr)
17201                 __dequeue_entity(cfs_rq, se);
17202         se->on_rq = 0;
17203 +       if (entity_is_task(se))
17204 +               vx_deactivate_task(task_of(se));
17205         update_cfs_load(cfs_rq, 0);
17206         account_entity_dequeue(cfs_rq, se);
17207  
17208 diff -NurpP --minimal linux-3.0.4/kernel/signal.c linux-3.0.4-vs2.3.1-pre10.1/kernel/signal.c
17209 --- linux-3.0.4/kernel/signal.c 2011-07-22 11:18:12.000000000 +0200
17210 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/signal.c 2011-07-22 11:20:39.000000000 +0200
17211 @@ -28,6 +28,8 @@
17212  #include <linux/freezer.h>
17213  #include <linux/pid_namespace.h>
17214  #include <linux/nsproxy.h>
17215 +#include <linux/vs_context.h>
17216 +#include <linux/vs_pid.h>
17217  #define CREATE_TRACE_POINTS
17218  #include <trace/events/signal.h>
17219  
17220 @@ -744,9 +746,18 @@ static int check_kill_permission(int sig
17221         struct pid *sid;
17222         int error;
17223  
17224 +       vxdprintk(VXD_CBIT(misc, 7),
17225 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17226 +               sig, info, t, vx_task_xid(t), t->pid);
17227 +
17228         if (!valid_signal(sig))
17229                 return -EINVAL;
17230  
17231 +/*     FIXME: needed? if so, why?
17232 +       if ((info != SEND_SIG_NOINFO) &&
17233 +               (is_si_special(info) || !si_fromuser(info)))
17234 +               goto skip;      */
17235 +
17236         if (!si_fromuser(info))
17237                 return 0;
17238  
17239 @@ -770,6 +781,20 @@ static int check_kill_permission(int sig
17240                 }
17241         }
17242  
17243 +       error = -EPERM;
17244 +       if (t->pid == 1 && current->xid)
17245 +               return error;
17246 +
17247 +       error = -ESRCH;
17248 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
17249 +                 loops, maybe ENOENT or EACCES? */
17250 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17251 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17252 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17253 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17254 +               return error;
17255 +       }
17256 +/* skip: */
17257         return security_task_kill(t, info, sig, 0);
17258  }
17259  
17260 @@ -1246,7 +1271,7 @@ int kill_pid_info(int sig, struct siginf
17261         rcu_read_lock();
17262  retry:
17263         p = pid_task(pid, PIDTYPE_PID);
17264 -       if (p) {
17265 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
17266                 error = group_send_sig_info(sig, info, p);
17267                 if (unlikely(error == -ESRCH))
17268                         /*
17269 @@ -1285,7 +1310,7 @@ int kill_pid_info_as_uid(int sig, struct
17270  
17271         rcu_read_lock();
17272         p = pid_task(pid, PIDTYPE_PID);
17273 -       if (!p) {
17274 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
17275                 ret = -ESRCH;
17276                 goto out_unlock;
17277         }
17278 @@ -1340,8 +1365,10 @@ static int kill_something_info(int sig, 
17279                 struct task_struct * p;
17280  
17281                 for_each_process(p) {
17282 -                       if (task_pid_vnr(p) > 1 &&
17283 -                                       !same_thread_group(p, current)) {
17284 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
17285 +                               task_pid_vnr(p) > 1 &&
17286 +                               !same_thread_group(p, current) &&
17287 +                               !vx_current_initpid(p->pid)) {
17288                                 int err = group_send_sig_info(sig, info, p);
17289                                 ++count;
17290                                 if (err != -EPERM)
17291 @@ -2140,6 +2167,11 @@ relock:
17292                                 !sig_kernel_only(signr))
17293                         continue;
17294  
17295 +               /* virtual init is protected against user signals */
17296 +               if ((info->si_code == SI_USER) &&
17297 +                       vx_current_initpid(current->pid))
17298 +                       continue;
17299 +
17300                 if (sig_kernel_stop(signr)) {
17301                         /*
17302                          * The default action is to stop all threads in
17303 diff -NurpP --minimal linux-3.0.4/kernel/softirq.c linux-3.0.4-vs2.3.1-pre10.1/kernel/softirq.c
17304 --- linux-3.0.4/kernel/softirq.c        2011-07-22 11:18:12.000000000 +0200
17305 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/softirq.c        2011-07-22 11:20:39.000000000 +0200
17306 @@ -24,6 +24,7 @@
17307  #include <linux/ftrace.h>
17308  #include <linux/smp.h>
17309  #include <linux/tick.h>
17310 +#include <linux/vs_context.h>
17311  
17312  #define CREATE_TRACE_POINTS
17313  #include <trace/events/irq.h>
17314 diff -NurpP --minimal linux-3.0.4/kernel/sys.c linux-3.0.4-vs2.3.1-pre10.1/kernel/sys.c
17315 --- linux-3.0.4/kernel/sys.c    2011-08-31 18:56:42.000000000 +0200
17316 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/sys.c    2011-08-31 19:37:44.000000000 +0200
17317 @@ -45,6 +45,7 @@
17318  #include <linux/syscalls.h>
17319  #include <linux/kprobes.h>
17320  #include <linux/user_namespace.h>
17321 +#include <linux/vs_pid.h>
17322  
17323  #include <linux/kmsg_dump.h>
17324  /* Move somewhere else to avoid recompiling? */
17325 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
17326                 goto out;
17327         }
17328         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17329 -               error = -EACCES;
17330 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17331 +                       error = 0;
17332 +               else
17333 +                       error = -EACCES;
17334                 goto out;
17335         }
17336         no_nice = security_task_setnice(p, niceval);
17337 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
17338                         else
17339                                 pgrp = task_pgrp(current);
17340                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17341 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17342 +                                       continue;
17343                                 error = set_one_prio(p, niceval, error);
17344                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
17345                         break;
17346 @@ -268,6 +274,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
17347                         else
17348                                 pgrp = task_pgrp(current);
17349                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17350 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17351 +                                       continue;
17352                                 niceval = 20 - task_nice(p);
17353                                 if (niceval > retval)
17354                                         retval = niceval;
17355 @@ -387,6 +395,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
17356  
17357  static DEFINE_MUTEX(reboot_mutex);
17358  
17359 +long vs_reboot(unsigned int, void __user *);
17360 +
17361  /*
17362   * Reboot system call: for obvious reasons only root may call it,
17363   * and even root needs to set up some magic numbers in the registers
17364 @@ -419,6 +429,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
17365         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17366                 cmd = LINUX_REBOOT_CMD_HALT;
17367  
17368 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17369 +               return vs_reboot(cmd, arg);
17370 +
17371         mutex_lock(&reboot_mutex);
17372         switch (cmd) {
17373         case LINUX_REBOOT_CMD_RESTART:
17374 @@ -1235,7 +1248,8 @@ SYSCALL_DEFINE2(sethostname, char __user
17375         int errno;
17376         char tmp[__NEW_UTS_LEN];
17377  
17378 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
17379 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
17380 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17381                 return -EPERM;
17382  
17383         if (len < 0 || len > __NEW_UTS_LEN)
17384 @@ -1285,7 +1299,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
17385         int errno;
17386         char tmp[__NEW_UTS_LEN];
17387  
17388 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
17389 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
17390 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17391                 return -EPERM;
17392         if (len < 0 || len > __NEW_UTS_LEN)
17393                 return -EINVAL;
17394 @@ -1403,7 +1418,7 @@ int do_prlimit(struct task_struct *tsk, 
17395                 /* Keep the capable check against init_user_ns until
17396                    cgroups can contain all limits */
17397                 if (new_rlim->rlim_max > rlim->rlim_max &&
17398 -                               !capable(CAP_SYS_RESOURCE))
17399 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17400                         retval = -EPERM;
17401                 if (!retval)
17402                         retval = security_task_setrlimit(tsk->group_leader,
17403 @@ -1457,7 +1472,8 @@ static int check_prlimit_permission(stru
17404              cred->gid == tcred->sgid &&
17405              cred->gid == tcred->gid))
17406                 return 0;
17407 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
17408 +       if (vx_ns_capable(tcred->user->user_ns,
17409 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17410                 return 0;
17411  
17412         return -EPERM;
17413 diff -NurpP --minimal linux-3.0.4/kernel/sysctl.c linux-3.0.4-vs2.3.1-pre10.1/kernel/sysctl.c
17414 --- linux-3.0.4/kernel/sysctl.c 2011-07-22 11:18:12.000000000 +0200
17415 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/sysctl.c 2011-06-15 02:40:14.000000000 +0200
17416 @@ -75,6 +75,7 @@
17417  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
17418  #include <linux/lockdep.h>
17419  #endif
17420 +extern char vshelper_path[];
17421  #ifdef CONFIG_CHR_DEV_SG
17422  #include <scsi/sg.h>
17423  #endif
17424 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
17425                 .proc_handler   = proc_dostring,
17426         },
17427  #endif
17428 +       {
17429 +               .procname       = "vshelper",
17430 +               .data           = &vshelper_path,
17431 +               .maxlen         = 256,
17432 +               .mode           = 0644,
17433 +               .proc_handler   = &proc_dostring,
17434 +       },
17435  #ifdef CONFIG_CHR_DEV_SG
17436         {
17437                 .procname       = "sg-big-buff",
17438 diff -NurpP --minimal linux-3.0.4/kernel/sysctl_binary.c linux-3.0.4-vs2.3.1-pre10.1/kernel/sysctl_binary.c
17439 --- linux-3.0.4/kernel/sysctl_binary.c  2011-05-22 16:17:59.000000000 +0200
17440 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/sysctl_binary.c  2011-06-10 22:11:24.000000000 +0200
17441 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
17442  
17443         { CTL_INT,      KERN_PANIC,                     "panic" },
17444         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
17445 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
17446  
17447         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
17448         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
17449 diff -NurpP --minimal linux-3.0.4/kernel/time/timekeeping.c linux-3.0.4-vs2.3.1-pre10.1/kernel/time/timekeeping.c
17450 --- linux-3.0.4/kernel/time/timekeeping.c       2011-07-22 11:18:12.000000000 +0200
17451 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/time/timekeeping.c       2011-06-10 22:11:24.000000000 +0200
17452 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
17453         } while (read_seqretry(&xtime_lock, seq));
17454  
17455         timespec_add_ns(ts, nsecs);
17456 +       vx_adjust_timespec(ts);
17457  }
17458  
17459  EXPORT_SYMBOL(getnstimeofday);
17460 diff -NurpP --minimal linux-3.0.4/kernel/time.c linux-3.0.4-vs2.3.1-pre10.1/kernel/time.c
17461 --- linux-3.0.4/kernel/time.c   2011-05-22 16:17:59.000000000 +0200
17462 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/time.c   2011-06-10 22:11:24.000000000 +0200
17463 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17464         if (err)
17465                 return err;
17466  
17467 -       do_settimeofday(&tv);
17468 +       vx_settimeofday(&tv);
17469         return 0;
17470  }
17471  
17472 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
17473                 /* SMP safe, again the code in arch/foo/time.c should
17474                  * globally block out interrupts when it runs.
17475                  */
17476 -               return do_settimeofday(tv);
17477 +               return vx_settimeofday(tv);
17478         }
17479         return 0;
17480  }
17481 diff -NurpP --minimal linux-3.0.4/kernel/timer.c linux-3.0.4-vs2.3.1-pre10.1/kernel/timer.c
17482 --- linux-3.0.4/kernel/timer.c  2011-07-22 11:18:12.000000000 +0200
17483 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/timer.c  2011-06-15 02:40:14.000000000 +0200
17484 @@ -40,6 +40,10 @@
17485  #include <linux/irq_work.h>
17486  #include <linux/sched.h>
17487  #include <linux/slab.h>
17488 +#include <linux/vs_base.h>
17489 +#include <linux/vs_cvirt.h>
17490 +#include <linux/vs_pid.h>
17491 +#include <linux/vserver/sched.h>
17492  
17493  #include <asm/uaccess.h>
17494  #include <asm/unistd.h>
17495 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17496  
17497  #endif
17498  
17499 -#ifndef __alpha__
17500 -
17501 -/*
17502 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17503 - * should be moved into arch/i386 instead?
17504 - */
17505  
17506  /**
17507   * sys_getpid - return the thread group id of the current process
17508 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
17509         rcu_read_lock();
17510         pid = task_tgid_vnr(current->real_parent);
17511         rcu_read_unlock();
17512 +       return vx_map_pid(pid);
17513 +}
17514  
17515 -       return pid;
17516 +#ifdef __alpha__
17517 +
17518 +/*
17519 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17520 + */
17521 +
17522 +asmlinkage long do_getxpid(long *ppid)
17523 +{
17524 +       *ppid = sys_getppid();
17525 +       return sys_getpid();
17526  }
17527  
17528 +#else /* _alpha_ */
17529 +
17530  SYSCALL_DEFINE0(getuid)
17531  {
17532         /* Only we change this so SMP safe */
17533 diff -NurpP --minimal linux-3.0.4/kernel/user_namespace.c linux-3.0.4-vs2.3.1-pre10.1/kernel/user_namespace.c
17534 --- linux-3.0.4/kernel/user_namespace.c 2011-03-15 18:07:42.000000000 +0100
17535 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/user_namespace.c 2011-06-10 22:11:24.000000000 +0200
17536 @@ -11,6 +11,7 @@
17537  #include <linux/user_namespace.h>
17538  #include <linux/highuid.h>
17539  #include <linux/cred.h>
17540 +#include <linux/vserver/global.h>
17541  
17542  static struct kmem_cache *user_ns_cachep __read_mostly;
17543  
17544 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
17545                 return -ENOMEM;
17546  
17547         kref_init(&ns->kref);
17548 +       atomic_inc(&vs_global_user_ns);
17549  
17550         for (n = 0; n < UIDHASH_SZ; ++n)
17551                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17552 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
17553         struct user_namespace *ns =
17554                 container_of(kref, struct user_namespace, kref);
17555  
17556 +       /* FIXME: maybe move into destroyer? */
17557 +       atomic_dec(&vs_global_user_ns);
17558         INIT_WORK(&ns->destroyer, free_user_ns_work);
17559         schedule_work(&ns->destroyer);
17560  }
17561 diff -NurpP --minimal linux-3.0.4/kernel/utsname.c linux-3.0.4-vs2.3.1-pre10.1/kernel/utsname.c
17562 --- linux-3.0.4/kernel/utsname.c        2011-07-22 11:18:12.000000000 +0200
17563 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/utsname.c        2011-06-13 14:09:44.000000000 +0200
17564 @@ -16,14 +16,17 @@
17565  #include <linux/slab.h>
17566  #include <linux/user_namespace.h>
17567  #include <linux/proc_fs.h>
17568 +#include <linux/vserver/global.h>
17569  
17570  static struct uts_namespace *create_uts_ns(void)
17571  {
17572         struct uts_namespace *uts_ns;
17573  
17574         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
17575 -       if (uts_ns)
17576 +       if (uts_ns) {
17577                 kref_init(&uts_ns->kref);
17578 +               atomic_inc(&vs_global_uts_ns);
17579 +       }
17580         return uts_ns;
17581  }
17582  
17583 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
17584   * @old_ns: namespace to clone
17585   * Return NULL on error (failure to kmalloc), new ns otherwise
17586   */
17587 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
17588 -                                         struct uts_namespace *old_ns)
17589 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
17590 +                                         struct user_namespace *old_user)
17591  {
17592         struct uts_namespace *ns;
17593  
17594 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
17595  
17596         down_read(&uts_sem);
17597         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17598 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
17599 +       ns->user_ns = get_user_ns(old_user);
17600         up_read(&uts_sem);
17601         return ns;
17602  }
17603 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
17604   * versa.
17605   */
17606  struct uts_namespace *copy_utsname(unsigned long flags,
17607 -                                  struct task_struct *tsk)
17608 +                                  struct uts_namespace *old_ns,
17609 +                                  struct user_namespace *user_ns)
17610  {
17611 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
17612         struct uts_namespace *new_ns;
17613  
17614         BUG_ON(!old_ns);
17615 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
17616         if (!(flags & CLONE_NEWUTS))
17617                 return old_ns;
17618  
17619 -       new_ns = clone_uts_ns(tsk, old_ns);
17620 +       new_ns = clone_uts_ns(old_ns, user_ns);
17621  
17622         put_uts_ns(old_ns);
17623         return new_ns;
17624 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
17625  
17626         ns = container_of(kref, struct uts_namespace, kref);
17627         put_user_ns(ns->user_ns);
17628 +       atomic_dec(&vs_global_uts_ns);
17629         kfree(ns);
17630  }
17631  
17632 diff -NurpP --minimal linux-3.0.4/kernel/vserver/Kconfig linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/Kconfig
17633 --- linux-3.0.4/kernel/vserver/Kconfig  1970-01-01 01:00:00.000000000 +0100
17634 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/Kconfig  2011-08-08 18:06:22.000000000 +0200
17635 @@ -0,0 +1,232 @@
17636 +#
17637 +# Linux VServer configuration
17638 +#
17639 +
17640 +menu "Linux VServer"
17641 +
17642 +config VSERVER_AUTO_LBACK
17643 +       bool    "Automatically Assign Loopback IP"
17644 +       default y
17645 +       help
17646 +         Automatically assign a guest specific loopback
17647 +         IP and add it to the kernel network stack on
17648 +         startup.
17649 +
17650 +config VSERVER_AUTO_SINGLE
17651 +       bool    "Automatic Single IP Special Casing"
17652 +       depends on EXPERIMENTAL
17653 +       default y
17654 +       help
17655 +         This allows network contexts with a single IP to
17656 +         automatically remap 0.0.0.0 bindings to that IP,
17657 +         avoiding further network checks and improving
17658 +         performance.
17659 +
17660 +         (note: such guests do not allow to change the ip
17661 +          on the fly and do not show loopback addresses)
17662 +
17663 +config VSERVER_COWBL
17664 +       bool    "Enable COW Immutable Link Breaking"
17665 +       default y
17666 +       help
17667 +         This enables the COW (Copy-On-Write) link break code.
17668 +         It allows you to treat unified files like normal files
17669 +         when writing to them (which will implicitely break the
17670 +         link and create a copy of the unified file)
17671 +
17672 +config VSERVER_VTIME
17673 +       bool    "Enable Virtualized Guest Time"
17674 +       depends on EXPERIMENTAL
17675 +       default n
17676 +       help
17677 +         This enables per guest time offsets to allow for
17678 +         adjusting the system clock individually per guest.
17679 +         this adds some overhead to the time functions and
17680 +         therefore should not be enabled without good reason.
17681 +
17682 +config VSERVER_DEVICE
17683 +       bool    "Enable Guest Device Mapping"
17684 +       depends on EXPERIMENTAL
17685 +       default n
17686 +       help
17687 +         This enables generic device remapping.
17688 +
17689 +config VSERVER_PROC_SECURE
17690 +       bool    "Enable Proc Security"
17691 +       depends on PROC_FS
17692 +       default y
17693 +       help
17694 +         This configures ProcFS security to initially hide
17695 +         non-process entries for all contexts except the main and
17696 +         spectator context (i.e. for all guests), which is a secure
17697 +         default.
17698 +
17699 +         (note: on 1.2x the entries were visible by default)
17700 +
17701 +choice
17702 +       prompt  "Persistent Inode Tagging"
17703 +       default TAGGING_ID24
17704 +       help
17705 +         This adds persistent context information to filesystems
17706 +         mounted with the tagxid option. Tagging is a requirement
17707 +         for per-context disk limits and per-context quota.
17708 +
17709 +
17710 +config TAGGING_NONE
17711 +       bool    "Disabled"
17712 +       help
17713 +         do not store per-context information in inodes.
17714 +
17715 +config TAGGING_UID16
17716 +       bool    "UID16/GID32"
17717 +       help
17718 +         reduces UID to 16 bit, but leaves GID at 32 bit.
17719 +
17720 +config TAGGING_GID16
17721 +       bool    "UID32/GID16"
17722 +       help
17723 +         reduces GID to 16 bit, but leaves UID at 32 bit.
17724 +
17725 +config TAGGING_ID24
17726 +       bool    "UID24/GID24"
17727 +       help
17728 +         uses the upper 8bit from UID and GID for XID tagging
17729 +         which leaves 24bit for UID/GID each, which should be
17730 +         more than sufficient for normal use.
17731 +
17732 +config TAGGING_INTERN
17733 +       bool    "UID32/GID32"
17734 +       help
17735 +         this uses otherwise reserved inode fields in the on
17736 +         disk representation, which limits the use to a few
17737 +         filesystems (currently ext2 and ext3)
17738 +
17739 +endchoice
17740 +
17741 +config TAG_NFSD
17742 +       bool    "Tag NFSD User Auth and Files"
17743 +       default n
17744 +       help
17745 +         Enable this if you do want the in-kernel NFS
17746 +         Server to use the tagging specified above.
17747 +         (will require patched clients too)
17748 +
17749 +config VSERVER_PRIVACY
17750 +       bool    "Honor Privacy Aspects of Guests"
17751 +       default n
17752 +       help
17753 +         When enabled, most context checks will disallow
17754 +         access to structures assigned to a specific context,
17755 +         like ptys or loop devices.
17756 +
17757 +config VSERVER_CONTEXTS
17758 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
17759 +       range 1 65533
17760 +       default "768"   if 64BIT
17761 +       default "256"
17762 +       help
17763 +         This setting will optimize certain data structures
17764 +         and memory allocations according to the expected
17765 +         maximum.
17766 +
17767 +         note: this is not a strict upper limit.
17768 +
17769 +config VSERVER_WARN
17770 +       bool    "VServer Warnings"
17771 +       default y
17772 +       help
17773 +         This enables various runtime warnings, which will
17774 +         notify about potential manipulation attempts or
17775 +         resource shortage. It is generally considered to
17776 +         be a good idea to have that enabled.
17777 +
17778 +config VSERVER_WARN_DEVPTS
17779 +       bool    "VServer DevPTS Warnings"
17780 +       depends on VSERVER_WARN
17781 +       default y
17782 +       help
17783 +         This enables DevPTS related warnings, issued when a
17784 +         process inside a context tries to lookup or access
17785 +         a dynamic pts from the host or a different context.
17786 +
17787 +config VSERVER_DEBUG
17788 +       bool    "VServer Debugging Code"
17789 +       default n
17790 +       help
17791 +         Set this to yes if you want to be able to activate
17792 +         debugging output at runtime. It adds a very small
17793 +         overhead to all vserver related functions and
17794 +         increases the kernel size by about 20k.
17795 +
17796 +config VSERVER_HISTORY
17797 +       bool    "VServer History Tracing"
17798 +       depends on VSERVER_DEBUG
17799 +       default n
17800 +       help
17801 +         Set this to yes if you want to record the history of
17802 +         linux-vserver activities, so they can be replayed in
17803 +         the event of a kernel panic or oops.
17804 +
17805 +config VSERVER_HISTORY_SIZE
17806 +       int     "Per-CPU History Size (32-65536)"
17807 +       depends on VSERVER_HISTORY
17808 +       range 32 65536
17809 +       default 64
17810 +       help
17811 +         This allows you to specify the number of entries in
17812 +         the per-CPU history buffer.
17813 +
17814 +config VSERVER_LEGACY_MEM
17815 +       bool    "Legacy Memory Limits"
17816 +       default n
17817 +       help
17818 +         This provides fake memory limits to keep
17819 +         older tools happy in the face of memory
17820 +         cgroups
17821 +
17822 +choice
17823 +       prompt  "Quotes used in debug and warn messages"
17824 +       default QUOTES_ISO8859
17825 +
17826 +config QUOTES_ISO8859
17827 +       bool    "Extended ASCII (ISO 8859) angle quotes"
17828 +       help
17829 +         This uses the extended ASCII characters \xbb
17830 +         and \xab for quoting file and process names.
17831 +
17832 +config QUOTES_UTF8
17833 +       bool    "UTF-8 angle quotes"
17834 +       help
17835 +         This uses the the UTF-8 sequences for angle
17836 +         quotes to quote file and process names.
17837 +
17838 +config QUOTES_ASCII
17839 +       bool    "ASCII single quotes"
17840 +       help
17841 +         This uses the ASCII single quote character
17842 +         (\x27) to quote file and process names.
17843 +
17844 +endchoice
17845 +
17846 +endmenu
17847 +
17848 +
17849 +config VSERVER
17850 +       bool
17851 +       default y
17852 +       select NAMESPACES
17853 +       select UTS_NS
17854 +       select IPC_NS
17855 +#      select USER_NS
17856 +       select SYSVIPC
17857 +
17858 +config VSERVER_SECURITY
17859 +       bool
17860 +       depends on SECURITY
17861 +       default y
17862 +       select SECURITY_CAPABILITIES
17863 +
17864 +config VSERVER_DISABLED
17865 +       bool
17866 +       default n
17867 +
17868 diff -NurpP --minimal linux-3.0.4/kernel/vserver/Makefile linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/Makefile
17869 --- linux-3.0.4/kernel/vserver/Makefile 1970-01-01 01:00:00.000000000 +0100
17870 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/Makefile 2011-06-10 22:11:24.000000000 +0200
17871 @@ -0,0 +1,18 @@
17872 +#
17873 +# Makefile for the Linux vserver routines.
17874 +#
17875 +
17876 +
17877 +obj-y          += vserver.o
17878 +
17879 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
17880 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
17881 +                  dlimit.o tag.o
17882 +
17883 +vserver-$(CONFIG_INET) += inet.o
17884 +vserver-$(CONFIG_PROC_FS) += proc.o
17885 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
17886 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
17887 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
17888 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
17889 +
17890 diff -NurpP --minimal linux-3.0.4/kernel/vserver/cacct.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cacct.c
17891 --- linux-3.0.4/kernel/vserver/cacct.c  1970-01-01 01:00:00.000000000 +0100
17892 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cacct.c  2011-06-10 22:11:24.000000000 +0200
17893 @@ -0,0 +1,42 @@
17894 +/*
17895 + *  linux/kernel/vserver/cacct.c
17896 + *
17897 + *  Virtual Server: Context Accounting
17898 + *
17899 + *  Copyright (C) 2006-2007 Herbert Pötzl
17900 + *
17901 + *  V0.01  added accounting stats
17902 + *
17903 + */
17904 +
17905 +#include <linux/types.h>
17906 +#include <linux/vs_context.h>
17907 +#include <linux/vserver/cacct_cmd.h>
17908 +#include <linux/vserver/cacct_int.h>
17909 +
17910 +#include <asm/errno.h>
17911 +#include <asm/uaccess.h>
17912 +
17913 +
17914 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17915 +{
17916 +       struct vcmd_sock_stat_v0 vc_data;
17917 +       int j, field;
17918 +
17919 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17920 +               return -EFAULT;
17921 +
17922 +       field = vc_data.field;
17923 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17924 +               return -EINVAL;
17925 +
17926 +       for (j = 0; j < 3; j++) {
17927 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17928 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17929 +       }
17930 +
17931 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17932 +               return -EFAULT;
17933 +       return 0;
17934 +}
17935 +
17936 diff -NurpP --minimal linux-3.0.4/kernel/vserver/cacct_init.h linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cacct_init.h
17937 --- linux-3.0.4/kernel/vserver/cacct_init.h     1970-01-01 01:00:00.000000000 +0100
17938 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cacct_init.h     2011-06-10 22:11:24.000000000 +0200
17939 @@ -0,0 +1,25 @@
17940 +
17941 +
17942 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17943 +{
17944 +       int i, j;
17945 +
17946 +
17947 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17948 +               for (j = 0; j < 3; j++) {
17949 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
17950 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
17951 +               }
17952 +       }
17953 +       for (i = 0; i < 8; i++)
17954 +               atomic_set(&cacct->slab[i], 0);
17955 +       for (i = 0; i < 5; i++)
17956 +               for (j = 0; j < 4; j++)
17957 +                       atomic_set(&cacct->page[i][j], 0);
17958 +}
17959 +
17960 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17961 +{
17962 +       return;
17963 +}
17964 +
17965 diff -NurpP --minimal linux-3.0.4/kernel/vserver/cacct_proc.h linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cacct_proc.h
17966 --- linux-3.0.4/kernel/vserver/cacct_proc.h     1970-01-01 01:00:00.000000000 +0100
17967 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cacct_proc.h     2011-06-10 22:11:24.000000000 +0200
17968 @@ -0,0 +1,53 @@
17969 +#ifndef _VX_CACCT_PROC_H
17970 +#define _VX_CACCT_PROC_H
17971 +
17972 +#include <linux/vserver/cacct_int.h>
17973 +
17974 +
17975 +#define VX_SOCKA_TOP   \
17976 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17977 +
17978 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17979 +{
17980 +       int i, j, length = 0;
17981 +       static char *type[VXA_SOCK_SIZE] = {
17982 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17983 +       };
17984 +
17985 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17986 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17987 +               length += sprintf(buffer + length, "%s:", type[i]);
17988 +               for (j = 0; j < 3; j++) {
17989 +                       length += sprintf(buffer + length,
17990 +                               "\t%10lu/%-10lu",
17991 +                               vx_sock_count(cacct, i, j),
17992 +                               vx_sock_total(cacct, i, j));
17993 +               }
17994 +               buffer[length++] = '\n';
17995 +       }
17996 +
17997 +       length += sprintf(buffer + length, "\n");
17998 +       length += sprintf(buffer + length,
17999 +               "slab:\t %8u %8u %8u %8u\n",
18000 +               atomic_read(&cacct->slab[1]),
18001 +               atomic_read(&cacct->slab[4]),
18002 +               atomic_read(&cacct->slab[0]),
18003 +               atomic_read(&cacct->slab[2]));
18004 +
18005 +       length += sprintf(buffer + length, "\n");
18006 +       for (i = 0; i < 5; i++) {
18007 +               length += sprintf(buffer + length,
18008 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
18009 +                       atomic_read(&cacct->page[i][0]),
18010 +                       atomic_read(&cacct->page[i][1]),
18011 +                       atomic_read(&cacct->page[i][2]),
18012 +                       atomic_read(&cacct->page[i][3]),
18013 +                       atomic_read(&cacct->page[i][4]),
18014 +                       atomic_read(&cacct->page[i][5]),
18015 +                       atomic_read(&cacct->page[i][6]),
18016 +                       atomic_read(&cacct->page[i][7]));
18017 +       }
18018 +       return length;
18019 +}
18020 +
18021 +#endif /* _VX_CACCT_PROC_H */
18022 diff -NurpP --minimal linux-3.0.4/kernel/vserver/context.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/context.c
18023 --- linux-3.0.4/kernel/vserver/context.c        1970-01-01 01:00:00.000000000 +0100
18024 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/context.c        2011-08-01 18:28:12.000000000 +0200
18025 @@ -0,0 +1,1107 @@
18026 +/*
18027 + *  linux/kernel/vserver/context.c
18028 + *
18029 + *  Virtual Server: Context Support
18030 + *
18031 + *  Copyright (C) 2003-2011  Herbert Pötzl
18032 + *
18033 + *  V0.01  context helper
18034 + *  V0.02  vx_ctx_kill syscall command
18035 + *  V0.03  replaced context_info calls
18036 + *  V0.04  redesign of struct (de)alloc
18037 + *  V0.05  rlimit basic implementation
18038 + *  V0.06  task_xid and info commands
18039 + *  V0.07  context flags and caps
18040 + *  V0.08  switch to RCU based hash
18041 + *  V0.09  revert to non RCU for now
18042 + *  V0.10  and back to working RCU hash
18043 + *  V0.11  and back to locking again
18044 + *  V0.12  referenced context store
18045 + *  V0.13  separate per cpu data
18046 + *  V0.14  changed vcmds to vxi arg
18047 + *  V0.15  added context stat
18048 + *  V0.16  have __create claim() the vxi
18049 + *  V0.17  removed older and legacy stuff
18050 + *  V0.18  added user credentials
18051 + *  V0.19  added warn mask
18052 + *
18053 + */
18054 +
18055 +#include <linux/slab.h>
18056 +#include <linux/types.h>
18057 +#include <linux/security.h>
18058 +#include <linux/pid_namespace.h>
18059 +#include <linux/capability.h>
18060 +
18061 +#include <linux/vserver/context.h>
18062 +#include <linux/vserver/network.h>
18063 +#include <linux/vserver/debug.h>
18064 +#include <linux/vserver/limit.h>
18065 +#include <linux/vserver/limit_int.h>
18066 +#include <linux/vserver/space.h>
18067 +#include <linux/init_task.h>
18068 +#include <linux/fs_struct.h>
18069 +#include <linux/cred.h>
18070 +
18071 +#include <linux/vs_context.h>
18072 +#include <linux/vs_limit.h>
18073 +#include <linux/vs_pid.h>
18074 +#include <linux/vserver/context_cmd.h>
18075 +
18076 +#include "cvirt_init.h"
18077 +#include "cacct_init.h"
18078 +#include "limit_init.h"
18079 +#include "sched_init.h"
18080 +
18081 +
18082 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
18083 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
18084 +
18085 +
18086 +/*     now inactive context structures */
18087 +
18088 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
18089 +
18090 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
18091 +
18092 +
18093 +/*     __alloc_vx_info()
18094 +
18095 +       * allocate an initialized vx_info struct
18096 +       * doesn't make it visible (hash)                        */
18097 +
18098 +static struct vx_info *__alloc_vx_info(xid_t xid)
18099 +{
18100 +       struct vx_info *new = NULL;
18101 +       int cpu, index;
18102 +
18103 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
18104 +
18105 +       /* would this benefit from a slab cache? */
18106 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
18107 +       if (!new)
18108 +               return 0;
18109 +
18110 +       memset(new, 0, sizeof(struct vx_info));
18111 +#ifdef CONFIG_SMP
18112 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
18113 +       if (!new->ptr_pc)
18114 +               goto error;
18115 +#endif
18116 +       new->vx_id = xid;
18117 +       INIT_HLIST_NODE(&new->vx_hlist);
18118 +       atomic_set(&new->vx_usecnt, 0);
18119 +       atomic_set(&new->vx_tasks, 0);
18120 +       new->vx_parent = NULL;
18121 +       new->vx_state = 0;
18122 +       init_waitqueue_head(&new->vx_wait);
18123 +
18124 +       /* prepare reaper */
18125 +       get_task_struct(init_pid_ns.child_reaper);
18126 +       new->vx_reaper = init_pid_ns.child_reaper;
18127 +       new->vx_badness_bias = 0;
18128 +
18129 +       /* rest of init goes here */
18130 +       vx_info_init_limit(&new->limit);
18131 +       vx_info_init_sched(&new->sched);
18132 +       vx_info_init_cvirt(&new->cvirt);
18133 +       vx_info_init_cacct(&new->cacct);
18134 +
18135 +       /* per cpu data structures */
18136 +       for_each_possible_cpu(cpu) {
18137 +               vx_info_init_sched_pc(
18138 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
18139 +               vx_info_init_cvirt_pc(
18140 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
18141 +       }
18142 +
18143 +       new->vx_flags = VXF_INIT_SET;
18144 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
18145 +       new->vx_ccaps = 0;
18146 +       new->vx_umask = 0;
18147 +       new->vx_wmask = 0;
18148 +
18149 +       new->reboot_cmd = 0;
18150 +       new->exit_code = 0;
18151 +
18152 +       // preconfig spaces
18153 +       for (index = 0; index < VX_SPACES; index++) {
18154 +               struct _vx_space *space = &new->space[index];
18155 +
18156 +               // filesystem
18157 +               spin_lock(&init_fs.lock);
18158 +               init_fs.users++;
18159 +               spin_unlock(&init_fs.lock);
18160 +               space->vx_fs = &init_fs;
18161 +
18162 +               /* FIXME: do we want defaults? */
18163 +               // space->vx_real_cred = 0;
18164 +               // space->vx_cred = 0;
18165 +       }
18166 +
18167 +
18168 +       vxdprintk(VXD_CBIT(xid, 0),
18169 +               "alloc_vx_info(%d) = %p", xid, new);
18170 +       vxh_alloc_vx_info(new);
18171 +       atomic_inc(&vx_global_ctotal);
18172 +       return new;
18173 +#ifdef CONFIG_SMP
18174 +error:
18175 +       kfree(new);
18176 +       return 0;
18177 +#endif
18178 +}
18179 +
18180 +/*     __dealloc_vx_info()
18181 +
18182 +       * final disposal of vx_info                             */
18183 +
18184 +static void __dealloc_vx_info(struct vx_info *vxi)
18185 +{
18186 +#ifdef CONFIG_VSERVER_WARN
18187 +       struct vx_info_save vxis;
18188 +       int cpu;
18189 +#endif
18190 +       vxdprintk(VXD_CBIT(xid, 0),
18191 +               "dealloc_vx_info(%p)", vxi);
18192 +       vxh_dealloc_vx_info(vxi);
18193 +
18194 +#ifdef CONFIG_VSERVER_WARN
18195 +       enter_vx_info(vxi, &vxis);
18196 +       vx_info_exit_limit(&vxi->limit);
18197 +       vx_info_exit_sched(&vxi->sched);
18198 +       vx_info_exit_cvirt(&vxi->cvirt);
18199 +       vx_info_exit_cacct(&vxi->cacct);
18200 +
18201 +       for_each_possible_cpu(cpu) {
18202 +               vx_info_exit_sched_pc(
18203 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
18204 +               vx_info_exit_cvirt_pc(
18205 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
18206 +       }
18207 +       leave_vx_info(&vxis);
18208 +#endif
18209 +
18210 +       vxi->vx_id = -1;
18211 +       vxi->vx_state |= VXS_RELEASED;
18212 +
18213 +#ifdef CONFIG_SMP
18214 +       free_percpu(vxi->ptr_pc);
18215 +#endif
18216 +       kfree(vxi);
18217 +       atomic_dec(&vx_global_ctotal);
18218 +}
18219 +
18220 +static void __shutdown_vx_info(struct vx_info *vxi)
18221 +{
18222 +       struct nsproxy *nsproxy;
18223 +       struct fs_struct *fs;
18224 +       struct cred *cred;
18225 +       int index, kill;
18226 +
18227 +       might_sleep();
18228 +
18229 +       vxi->vx_state |= VXS_SHUTDOWN;
18230 +       vs_state_change(vxi, VSC_SHUTDOWN);
18231 +
18232 +       for (index = 0; index < VX_SPACES; index++) {
18233 +               struct _vx_space *space = &vxi->space[index];
18234 +
18235 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
18236 +               if (nsproxy)
18237 +                       put_nsproxy(nsproxy);
18238 +
18239 +               fs = xchg(&space->vx_fs, NULL);
18240 +               spin_lock(&fs->lock);
18241 +               kill = !--fs->users;
18242 +               spin_unlock(&fs->lock);
18243 +               if (kill)
18244 +                       free_fs_struct(fs);
18245 +
18246 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
18247 +               if (cred)
18248 +                       abort_creds(cred);
18249 +       }
18250 +}
18251 +
18252 +/* exported stuff */
18253 +
18254 +void free_vx_info(struct vx_info *vxi)
18255 +{
18256 +       unsigned long flags;
18257 +       unsigned index;
18258 +
18259 +       /* check for reference counts first */
18260 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
18261 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18262 +
18263 +       /* context must not be hashed */
18264 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18265 +
18266 +       /* context shutdown is mandatory */
18267 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
18268 +
18269 +       /* spaces check */
18270 +       for (index = 0; index < VX_SPACES; index++) {
18271 +               struct _vx_space *space = &vxi->space[index];
18272 +
18273 +               BUG_ON(space->vx_nsproxy);
18274 +               BUG_ON(space->vx_fs);
18275 +               // BUG_ON(space->vx_real_cred);
18276 +               // BUG_ON(space->vx_cred);
18277 +       }
18278 +
18279 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18280 +       hlist_del(&vxi->vx_hlist);
18281 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18282 +
18283 +       __dealloc_vx_info(vxi);
18284 +}
18285 +
18286 +
18287 +/*     hash table for vx_info hash */
18288 +
18289 +#define VX_HASH_SIZE   13
18290 +
18291 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
18292 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
18293 +
18294 +static DEFINE_SPINLOCK(vx_info_hash_lock);
18295 +
18296 +
18297 +static inline unsigned int __hashval(xid_t xid)
18298 +{
18299 +       return (xid % VX_HASH_SIZE);
18300 +}
18301 +
18302 +
18303 +
18304 +/*     __hash_vx_info()
18305 +
18306 +       * add the vxi to the global hash table
18307 +       * requires the hash_lock to be held                     */
18308 +
18309 +static inline void __hash_vx_info(struct vx_info *vxi)
18310 +{
18311 +       struct hlist_head *head;
18312 +
18313 +       vxd_assert_lock(&vx_info_hash_lock);
18314 +       vxdprintk(VXD_CBIT(xid, 4),
18315 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
18316 +       vxh_hash_vx_info(vxi);
18317 +
18318 +       /* context must not be hashed */
18319 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18320 +
18321 +       vxi->vx_state |= VXS_HASHED;
18322 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
18323 +       hlist_add_head(&vxi->vx_hlist, head);
18324 +       atomic_inc(&vx_global_cactive);
18325 +}
18326 +
18327 +/*     __unhash_vx_info()
18328 +
18329 +       * remove the vxi from the global hash table
18330 +       * requires the hash_lock to be held                     */
18331 +
18332 +static inline void __unhash_vx_info(struct vx_info *vxi)
18333 +{
18334 +       unsigned long flags;
18335 +
18336 +       vxd_assert_lock(&vx_info_hash_lock);
18337 +       vxdprintk(VXD_CBIT(xid, 4),
18338 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
18339 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
18340 +       vxh_unhash_vx_info(vxi);
18341 +
18342 +       /* context must be hashed */
18343 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
18344 +       /* but without tasks */
18345 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18346 +
18347 +       vxi->vx_state &= ~VXS_HASHED;
18348 +       hlist_del_init(&vxi->vx_hlist);
18349 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18350 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
18351 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18352 +       atomic_dec(&vx_global_cactive);
18353 +}
18354 +
18355 +
18356 +/*     __lookup_vx_info()
18357 +
18358 +       * requires the hash_lock to be held
18359 +       * doesn't increment the vx_refcnt                       */
18360 +
18361 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
18362 +{
18363 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
18364 +       struct hlist_node *pos;
18365 +       struct vx_info *vxi;
18366 +
18367 +       vxd_assert_lock(&vx_info_hash_lock);
18368 +       hlist_for_each(pos, head) {
18369 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18370 +
18371 +               if (vxi->vx_id == xid)
18372 +                       goto found;
18373 +       }
18374 +       vxi = NULL;
18375 +found:
18376 +       vxdprintk(VXD_CBIT(xid, 0),
18377 +               "__lookup_vx_info(#%u): %p[#%u]",
18378 +               xid, vxi, vxi ? vxi->vx_id : 0);
18379 +       vxh_lookup_vx_info(vxi, xid);
18380 +       return vxi;
18381 +}
18382 +
18383 +
18384 +/*     __create_vx_info()
18385 +
18386 +       * create the requested context
18387 +       * get(), claim() and hash it                            */
18388 +
18389 +static struct vx_info *__create_vx_info(int id)
18390 +{
18391 +       struct vx_info *new, *vxi = NULL;
18392 +
18393 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
18394 +
18395 +       if (!(new = __alloc_vx_info(id)))
18396 +               return ERR_PTR(-ENOMEM);
18397 +
18398 +       /* required to make dynamic xids unique */
18399 +       spin_lock(&vx_info_hash_lock);
18400 +
18401 +       /* static context requested */
18402 +       if ((vxi = __lookup_vx_info(id))) {
18403 +               vxdprintk(VXD_CBIT(xid, 0),
18404 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18405 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18406 +                       vxi = ERR_PTR(-EBUSY);
18407 +               else
18408 +                       vxi = ERR_PTR(-EEXIST);
18409 +               goto out_unlock;
18410 +       }
18411 +       /* new context */
18412 +       vxdprintk(VXD_CBIT(xid, 0),
18413 +               "create_vx_info(%d) = %p (new)", id, new);
18414 +       claim_vx_info(new, NULL);
18415 +       __hash_vx_info(get_vx_info(new));
18416 +       vxi = new, new = NULL;
18417 +
18418 +out_unlock:
18419 +       spin_unlock(&vx_info_hash_lock);
18420 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18421 +       if (new)
18422 +               __dealloc_vx_info(new);
18423 +       return vxi;
18424 +}
18425 +
18426 +
18427 +/*     exported stuff                                          */
18428 +
18429 +
18430 +void unhash_vx_info(struct vx_info *vxi)
18431 +{
18432 +       spin_lock(&vx_info_hash_lock);
18433 +       __unhash_vx_info(vxi);
18434 +       spin_unlock(&vx_info_hash_lock);
18435 +       __shutdown_vx_info(vxi);
18436 +       __wakeup_vx_info(vxi);
18437 +}
18438 +
18439 +
18440 +/*     lookup_vx_info()
18441 +
18442 +       * search for a vx_info and get() it
18443 +       * negative id means current                             */
18444 +
18445 +struct vx_info *lookup_vx_info(int id)
18446 +{
18447 +       struct vx_info *vxi = NULL;
18448 +
18449 +       if (id < 0) {
18450 +               vxi = get_vx_info(current_vx_info());
18451 +       } else if (id > 1) {
18452 +               spin_lock(&vx_info_hash_lock);
18453 +               vxi = get_vx_info(__lookup_vx_info(id));
18454 +               spin_unlock(&vx_info_hash_lock);
18455 +       }
18456 +       return vxi;
18457 +}
18458 +
18459 +/*     xid_is_hashed()
18460 +
18461 +       * verify that xid is still hashed                       */
18462 +
18463 +int xid_is_hashed(xid_t xid)
18464 +{
18465 +       int hashed;
18466 +
18467 +       spin_lock(&vx_info_hash_lock);
18468 +       hashed = (__lookup_vx_info(xid) != NULL);
18469 +       spin_unlock(&vx_info_hash_lock);
18470 +       return hashed;
18471 +}
18472 +
18473 +#ifdef CONFIG_PROC_FS
18474 +
18475 +/*     get_xid_list()
18476 +
18477 +       * get a subset of hashed xids for proc
18478 +       * assumes size is at least one                          */
18479 +
18480 +int get_xid_list(int index, unsigned int *xids, int size)
18481 +{
18482 +       int hindex, nr_xids = 0;
18483 +
18484 +       /* only show current and children */
18485 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18486 +               if (index > 0)
18487 +                       return 0;
18488 +               xids[nr_xids] = vx_current_xid();
18489 +               return 1;
18490 +       }
18491 +
18492 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18493 +               struct hlist_head *head = &vx_info_hash[hindex];
18494 +               struct hlist_node *pos;
18495 +
18496 +               spin_lock(&vx_info_hash_lock);
18497 +               hlist_for_each(pos, head) {
18498 +                       struct vx_info *vxi;
18499 +
18500 +                       if (--index > 0)
18501 +                               continue;
18502 +
18503 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18504 +                       xids[nr_xids] = vxi->vx_id;
18505 +                       if (++nr_xids >= size) {
18506 +                               spin_unlock(&vx_info_hash_lock);
18507 +                               goto out;
18508 +                       }
18509 +               }
18510 +               /* keep the lock time short */
18511 +               spin_unlock(&vx_info_hash_lock);
18512 +       }
18513 +out:
18514 +       return nr_xids;
18515 +}
18516 +#endif
18517 +
18518 +#ifdef CONFIG_VSERVER_DEBUG
18519 +
18520 +void   dump_vx_info_inactive(int level)
18521 +{
18522 +       struct hlist_node *entry, *next;
18523 +
18524 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18525 +               struct vx_info *vxi =
18526 +                       list_entry(entry, struct vx_info, vx_hlist);
18527 +
18528 +               dump_vx_info(vxi, level);
18529 +       }
18530 +}
18531 +
18532 +#endif
18533 +
18534 +#if 0
18535 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18536 +{
18537 +       struct user_struct *new_user, *old_user;
18538 +
18539 +       if (!p || !vxi)
18540 +               BUG();
18541 +
18542 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18543 +               return -EACCES;
18544 +
18545 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18546 +       if (!new_user)
18547 +               return -ENOMEM;
18548 +
18549 +       old_user = p->user;
18550 +       if (new_user != old_user) {
18551 +               atomic_inc(&new_user->processes);
18552 +               atomic_dec(&old_user->processes);
18553 +               p->user = new_user;
18554 +       }
18555 +       free_uid(old_user);
18556 +       return 0;
18557 +}
18558 +#endif
18559 +
18560 +#if 0
18561 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18562 +{
18563 +       // p->cap_effective &= vxi->vx_cap_bset;
18564 +       p->cap_effective =
18565 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18566 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18567 +       p->cap_inheritable =
18568 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18569 +       // p->cap_permitted &= vxi->vx_cap_bset;
18570 +       p->cap_permitted =
18571 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18572 +}
18573 +#endif
18574 +
18575 +
18576 +#include <linux/file.h>
18577 +#include <linux/fdtable.h>
18578 +
18579 +static int vx_openfd_task(struct task_struct *tsk)
18580 +{
18581 +       struct files_struct *files = tsk->files;
18582 +       struct fdtable *fdt;
18583 +       const unsigned long *bptr;
18584 +       int count, total;
18585 +
18586 +       /* no rcu_read_lock() because of spin_lock() */
18587 +       spin_lock(&files->file_lock);
18588 +       fdt = files_fdtable(files);
18589 +       bptr = fdt->open_fds->fds_bits;
18590 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18591 +       for (total = 0; count > 0; count--) {
18592 +               if (*bptr)
18593 +                       total += hweight_long(*bptr);
18594 +               bptr++;
18595 +       }
18596 +       spin_unlock(&files->file_lock);
18597 +       return total;
18598 +}
18599 +
18600 +
18601 +/*     for *space compatibility */
18602 +
18603 +asmlinkage long sys_unshare(unsigned long);
18604 +
18605 +/*
18606 + *     migrate task to new context
18607 + *     gets vxi, puts old_vxi on change
18608 + *     optionally unshares namespaces (hack)
18609 + */
18610 +
18611 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18612 +{
18613 +       struct vx_info *old_vxi;
18614 +       int ret = 0;
18615 +
18616 +       if (!p || !vxi)
18617 +               BUG();
18618 +
18619 +       vxdprintk(VXD_CBIT(xid, 5),
18620 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18621 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18622 +
18623 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18624 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18625 +               return -EACCES;
18626 +
18627 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18628 +               return -EFAULT;
18629 +
18630 +       old_vxi = task_get_vx_info(p);
18631 +       if (old_vxi == vxi)
18632 +               goto out;
18633 +
18634 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18635 +       {
18636 +               int openfd;
18637 +
18638 +               task_lock(p);
18639 +               openfd = vx_openfd_task(p);
18640 +
18641 +               if (old_vxi) {
18642 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18643 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18644 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18645 +                       /* FIXME: what about the struct files here? */
18646 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18647 +                       /* account for the executable */
18648 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18649 +               }
18650 +               atomic_inc(&vxi->cvirt.nr_threads);
18651 +               atomic_inc(&vxi->cvirt.nr_running);
18652 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18653 +               /* FIXME: what about the struct files here? */
18654 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18655 +               /* account for the executable */
18656 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18657 +
18658 +               if (old_vxi) {
18659 +                       release_vx_info(old_vxi, p);
18660 +                       clr_vx_info(&p->vx_info);
18661 +               }
18662 +               claim_vx_info(vxi, p);
18663 +               set_vx_info(&p->vx_info, vxi);
18664 +               p->xid = vxi->vx_id;
18665 +
18666 +               vxdprintk(VXD_CBIT(xid, 5),
18667 +                       "moved task %p into vxi:%p[#%d]",
18668 +                       p, vxi, vxi->vx_id);
18669 +
18670 +               // vx_mask_cap_bset(vxi, p);
18671 +               task_unlock(p);
18672 +
18673 +               /* hack for *spaces to provide compatibility */
18674 +               if (unshare) {
18675 +                       struct nsproxy *old_nsp, *new_nsp;
18676 +
18677 +                       ret = unshare_nsproxy_namespaces(
18678 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18679 +                               &new_nsp, NULL);
18680 +                       if (ret)
18681 +                               goto out;
18682 +
18683 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18684 +                       vx_set_space(vxi,
18685 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18686 +                       put_nsproxy(old_nsp);
18687 +               }
18688 +       }
18689 +out:
18690 +       put_vx_info(old_vxi);
18691 +       return ret;
18692 +}
18693 +
18694 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18695 +{
18696 +       struct task_struct *old_reaper;
18697 +
18698 +       if (!vxi)
18699 +               return -EINVAL;
18700 +
18701 +       vxdprintk(VXD_CBIT(xid, 6),
18702 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18703 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18704 +
18705 +       old_reaper = vxi->vx_reaper;
18706 +       if (old_reaper == p)
18707 +               return 0;
18708 +
18709 +       /* set new child reaper */
18710 +       get_task_struct(p);
18711 +       vxi->vx_reaper = p;
18712 +       put_task_struct(old_reaper);
18713 +       return 0;
18714 +}
18715 +
18716 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18717 +{
18718 +       if (!vxi)
18719 +               return -EINVAL;
18720 +
18721 +       vxdprintk(VXD_CBIT(xid, 6),
18722 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18723 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18724 +
18725 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18726 +       // vxi->vx_initpid = p->tgid;
18727 +       vxi->vx_initpid = p->pid;
18728 +       return 0;
18729 +}
18730 +
18731 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18732 +{
18733 +       vxdprintk(VXD_CBIT(xid, 6),
18734 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18735 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18736 +
18737 +       vxi->exit_code = code;
18738 +       vxi->vx_initpid = 0;
18739 +}
18740 +
18741 +
18742 +void vx_set_persistent(struct vx_info *vxi)
18743 +{
18744 +       vxdprintk(VXD_CBIT(xid, 6),
18745 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18746 +
18747 +       get_vx_info(vxi);
18748 +       claim_vx_info(vxi, NULL);
18749 +}
18750 +
18751 +void vx_clear_persistent(struct vx_info *vxi)
18752 +{
18753 +       vxdprintk(VXD_CBIT(xid, 6),
18754 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18755 +
18756 +       release_vx_info(vxi, NULL);
18757 +       put_vx_info(vxi);
18758 +}
18759 +
18760 +void vx_update_persistent(struct vx_info *vxi)
18761 +{
18762 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18763 +               vx_set_persistent(vxi);
18764 +       else
18765 +               vx_clear_persistent(vxi);
18766 +}
18767 +
18768 +
18769 +/*     task must be current or locked          */
18770 +
18771 +void   exit_vx_info(struct task_struct *p, int code)
18772 +{
18773 +       struct vx_info *vxi = p->vx_info;
18774 +
18775 +       if (vxi) {
18776 +               atomic_dec(&vxi->cvirt.nr_threads);
18777 +               vx_nproc_dec(p);
18778 +
18779 +               vxi->exit_code = code;
18780 +               release_vx_info(vxi, p);
18781 +       }
18782 +}
18783 +
18784 +void   exit_vx_info_early(struct task_struct *p, int code)
18785 +{
18786 +       struct vx_info *vxi = p->vx_info;
18787 +
18788 +       if (vxi) {
18789 +               if (vxi->vx_initpid == p->pid)
18790 +                       vx_exit_init(vxi, p, code);
18791 +               if (vxi->vx_reaper == p)
18792 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18793 +       }
18794 +}
18795 +
18796 +
18797 +/* vserver syscall commands below here */
18798 +
18799 +/* taks xid and vx_info functions */
18800 +
18801 +#include <asm/uaccess.h>
18802 +
18803 +
18804 +int vc_task_xid(uint32_t id)
18805 +{
18806 +       xid_t xid;
18807 +
18808 +       if (id) {
18809 +               struct task_struct *tsk;
18810 +
18811 +               rcu_read_lock();
18812 +               tsk = find_task_by_real_pid(id);
18813 +               xid = (tsk) ? tsk->xid : -ESRCH;
18814 +               rcu_read_unlock();
18815 +       } else
18816 +               xid = vx_current_xid();
18817 +       return xid;
18818 +}
18819 +
18820 +
18821 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18822 +{
18823 +       struct vcmd_vx_info_v0 vc_data;
18824 +
18825 +       vc_data.xid = vxi->vx_id;
18826 +       vc_data.initpid = vxi->vx_initpid;
18827 +
18828 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18829 +               return -EFAULT;
18830 +       return 0;
18831 +}
18832 +
18833 +
18834 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18835 +{
18836 +       struct vcmd_ctx_stat_v0 vc_data;
18837 +
18838 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18839 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18840 +
18841 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18842 +               return -EFAULT;
18843 +       return 0;
18844 +}
18845 +
18846 +
18847 +/* context functions */
18848 +
18849 +int vc_ctx_create(uint32_t xid, void __user *data)
18850 +{
18851 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18852 +       struct vx_info *new_vxi;
18853 +       int ret;
18854 +
18855 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18856 +               return -EFAULT;
18857 +
18858 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18859 +               return -EINVAL;
18860 +
18861 +       new_vxi = __create_vx_info(xid);
18862 +       if (IS_ERR(new_vxi))
18863 +               return PTR_ERR(new_vxi);
18864 +
18865 +       /* initial flags */
18866 +       new_vxi->vx_flags = vc_data.flagword;
18867 +
18868 +       ret = -ENOEXEC;
18869 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18870 +               goto out;
18871 +
18872 +       ret = vx_migrate_task(current, new_vxi, (!data));
18873 +       if (ret)
18874 +               goto out;
18875 +
18876 +       /* return context id on success */
18877 +       ret = new_vxi->vx_id;
18878 +
18879 +       /* get a reference for persistent contexts */
18880 +       if ((vc_data.flagword & VXF_PERSISTENT))
18881 +               vx_set_persistent(new_vxi);
18882 +out:
18883 +       release_vx_info(new_vxi, NULL);
18884 +       put_vx_info(new_vxi);
18885 +       return ret;
18886 +}
18887 +
18888 +
18889 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18890 +{
18891 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18892 +       int ret;
18893 +
18894 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18895 +               return -EFAULT;
18896 +
18897 +       ret = vx_migrate_task(current, vxi, 0);
18898 +       if (ret)
18899 +               return ret;
18900 +       if (vc_data.flagword & VXM_SET_INIT)
18901 +               ret = vx_set_init(vxi, current);
18902 +       if (ret)
18903 +               return ret;
18904 +       if (vc_data.flagword & VXM_SET_REAPER)
18905 +               ret = vx_set_reaper(vxi, current);
18906 +       return ret;
18907 +}
18908 +
18909 +
18910 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18911 +{
18912 +       struct vcmd_ctx_flags_v0 vc_data;
18913 +
18914 +       vc_data.flagword = vxi->vx_flags;
18915 +
18916 +       /* special STATE flag handling */
18917 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18918 +
18919 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18920 +               return -EFAULT;
18921 +       return 0;
18922 +}
18923 +
18924 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18925 +{
18926 +       struct vcmd_ctx_flags_v0 vc_data;
18927 +       uint64_t mask, trigger;
18928 +
18929 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18930 +               return -EFAULT;
18931 +
18932 +       /* special STATE flag handling */
18933 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18934 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18935 +
18936 +       if (vxi == current_vx_info()) {
18937 +               /* if (trigger & VXF_STATE_SETUP)
18938 +                       vx_mask_cap_bset(vxi, current); */
18939 +               if (trigger & VXF_STATE_INIT) {
18940 +                       int ret;
18941 +
18942 +                       ret = vx_set_init(vxi, current);
18943 +                       if (ret)
18944 +                               return ret;
18945 +                       ret = vx_set_reaper(vxi, current);
18946 +                       if (ret)
18947 +                               return ret;
18948 +               }
18949 +       }
18950 +
18951 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18952 +               vc_data.flagword, mask);
18953 +       if (trigger & VXF_PERSISTENT)
18954 +               vx_update_persistent(vxi);
18955 +
18956 +       return 0;
18957 +}
18958 +
18959 +
18960 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18961 +{
18962 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18963 +
18964 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18965 +       return v;
18966 +}
18967 +
18968 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18969 +{
18970 +       kernel_cap_t c = __cap_empty_set;
18971 +
18972 +       c.cap[0] = v & 0xFFFFFFFF;
18973 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18974 +
18975 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18976 +       return c;
18977 +}
18978 +
18979 +
18980 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18981 +{
18982 +       if (bcaps)
18983 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18984 +       if (ccaps)
18985 +               *ccaps = vxi->vx_ccaps;
18986 +
18987 +       return 0;
18988 +}
18989 +
18990 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18991 +{
18992 +       struct vcmd_ctx_caps_v1 vc_data;
18993 +       int ret;
18994 +
18995 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18996 +       if (ret)
18997 +               return ret;
18998 +       vc_data.cmask = ~0ULL;
18999 +
19000 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19001 +               return -EFAULT;
19002 +       return 0;
19003 +}
19004 +
19005 +static int do_set_caps(struct vx_info *vxi,
19006 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
19007 +{
19008 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
19009 +
19010 +#if 0
19011 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
19012 +               bcaps, bmask, ccaps, cmask);
19013 +#endif
19014 +       vxi->vx_bcaps = cap_t_from_caps(
19015 +               vs_mask_flags(bcold, bcaps, bmask));
19016 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
19017 +
19018 +       return 0;
19019 +}
19020 +
19021 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
19022 +{
19023 +       struct vcmd_ctx_caps_v1 vc_data;
19024 +
19025 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19026 +               return -EFAULT;
19027 +
19028 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
19029 +}
19030 +
19031 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
19032 +{
19033 +       struct vcmd_bcaps vc_data;
19034 +       int ret;
19035 +
19036 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
19037 +       if (ret)
19038 +               return ret;
19039 +       vc_data.bmask = ~0ULL;
19040 +
19041 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19042 +               return -EFAULT;
19043 +       return 0;
19044 +}
19045 +
19046 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
19047 +{
19048 +       struct vcmd_bcaps vc_data;
19049 +
19050 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19051 +               return -EFAULT;
19052 +
19053 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
19054 +}
19055 +
19056 +
19057 +int vc_get_umask(struct vx_info *vxi, void __user *data)
19058 +{
19059 +       struct vcmd_umask vc_data;
19060 +
19061 +       vc_data.umask = vxi->vx_umask;
19062 +       vc_data.mask = ~0ULL;
19063 +
19064 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19065 +               return -EFAULT;
19066 +       return 0;
19067 +}
19068 +
19069 +int vc_set_umask(struct vx_info *vxi, void __user *data)
19070 +{
19071 +       struct vcmd_umask vc_data;
19072 +
19073 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19074 +               return -EFAULT;
19075 +
19076 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
19077 +               vc_data.umask, vc_data.mask);
19078 +       return 0;
19079 +}
19080 +
19081 +
19082 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
19083 +{
19084 +       struct vcmd_wmask vc_data;
19085 +
19086 +       vc_data.wmask = vxi->vx_wmask;
19087 +       vc_data.mask = ~0ULL;
19088 +
19089 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19090 +               return -EFAULT;
19091 +       return 0;
19092 +}
19093 +
19094 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
19095 +{
19096 +       struct vcmd_wmask vc_data;
19097 +
19098 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19099 +               return -EFAULT;
19100 +
19101 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
19102 +               vc_data.wmask, vc_data.mask);
19103 +       return 0;
19104 +}
19105 +
19106 +
19107 +int vc_get_badness(struct vx_info *vxi, void __user *data)
19108 +{
19109 +       struct vcmd_badness_v0 vc_data;
19110 +
19111 +       vc_data.bias = vxi->vx_badness_bias;
19112 +
19113 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19114 +               return -EFAULT;
19115 +       return 0;
19116 +}
19117 +
19118 +int vc_set_badness(struct vx_info *vxi, void __user *data)
19119 +{
19120 +       struct vcmd_badness_v0 vc_data;
19121 +
19122 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19123 +               return -EFAULT;
19124 +
19125 +       vxi->vx_badness_bias = vc_data.bias;
19126 +       return 0;
19127 +}
19128 +
19129 +#include <linux/module.h>
19130 +
19131 +EXPORT_SYMBOL_GPL(free_vx_info);
19132 +
19133 diff -NurpP --minimal linux-3.0.4/kernel/vserver/cvirt.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cvirt.c
19134 --- linux-3.0.4/kernel/vserver/cvirt.c  1970-01-01 01:00:00.000000000 +0100
19135 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cvirt.c  2011-06-13 14:57:26.000000000 +0200
19136 @@ -0,0 +1,303 @@
19137 +/*
19138 + *  linux/kernel/vserver/cvirt.c
19139 + *
19140 + *  Virtual Server: Context Virtualization
19141 + *
19142 + *  Copyright (C) 2004-2007  Herbert Pötzl
19143 + *
19144 + *  V0.01  broken out from limit.c
19145 + *  V0.02  added utsname stuff
19146 + *  V0.03  changed vcmds to vxi arg
19147 + *
19148 + */
19149 +
19150 +#include <linux/types.h>
19151 +#include <linux/utsname.h>
19152 +#include <linux/vs_cvirt.h>
19153 +#include <linux/vserver/switch.h>
19154 +#include <linux/vserver/cvirt_cmd.h>
19155 +
19156 +#include <asm/uaccess.h>
19157 +
19158 +
19159 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
19160 +{
19161 +       struct vx_info *vxi = current_vx_info();
19162 +
19163 +       set_normalized_timespec(uptime,
19164 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
19165 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
19166 +       if (!idle)
19167 +               return;
19168 +       set_normalized_timespec(idle,
19169 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
19170 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
19171 +       return;
19172 +}
19173 +
19174 +uint64_t vx_idle_jiffies(void)
19175 +{
19176 +       return init_task.utime + init_task.stime;
19177 +}
19178 +
19179 +
19180 +
19181 +static inline uint32_t __update_loadavg(uint32_t load,
19182 +       int wsize, int delta, int n)
19183 +{
19184 +       unsigned long long calc, prev;
19185 +
19186 +       /* just set it to n */
19187 +       if (unlikely(delta >= wsize))
19188 +               return (n << FSHIFT);
19189 +
19190 +       calc = delta * n;
19191 +       calc <<= FSHIFT;
19192 +       prev = (wsize - delta);
19193 +       prev *= load;
19194 +       calc += prev;
19195 +       do_div(calc, wsize);
19196 +       return calc;
19197 +}
19198 +
19199 +
19200 +void vx_update_load(struct vx_info *vxi)
19201 +{
19202 +       uint32_t now, last, delta;
19203 +       unsigned int nr_running, nr_uninterruptible;
19204 +       unsigned int total;
19205 +       unsigned long flags;
19206 +
19207 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
19208 +
19209 +       now = jiffies;
19210 +       last = vxi->cvirt.load_last;
19211 +       delta = now - last;
19212 +
19213 +       if (delta < 5*HZ)
19214 +               goto out;
19215 +
19216 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
19217 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
19218 +       total = nr_running + nr_uninterruptible;
19219 +
19220 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
19221 +               60*HZ, delta, total);
19222 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
19223 +               5*60*HZ, delta, total);
19224 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
19225 +               15*60*HZ, delta, total);
19226 +
19227 +       vxi->cvirt.load_last = now;
19228 +out:
19229 +       atomic_inc(&vxi->cvirt.load_updates);
19230 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
19231 +}
19232 +
19233 +
19234 +/*
19235 + * Commands to do_syslog:
19236 + *
19237 + *      0 -- Close the log.  Currently a NOP.
19238 + *      1 -- Open the log. Currently a NOP.
19239 + *      2 -- Read from the log.
19240 + *      3 -- Read all messages remaining in the ring buffer.
19241 + *      4 -- Read and clear all messages remaining in the ring buffer
19242 + *      5 -- Clear ring buffer.
19243 + *      6 -- Disable printk's to console
19244 + *      7 -- Enable printk's to console
19245 + *      8 -- Set level of messages printed to console
19246 + *      9 -- Return number of unread characters in the log buffer
19247 + *     10 -- Return size of the log buffer
19248 + */
19249 +int vx_do_syslog(int type, char __user *buf, int len)
19250 +{
19251 +       int error = 0;
19252 +       int do_clear = 0;
19253 +       struct vx_info *vxi = current_vx_info();
19254 +       struct _vx_syslog *log;
19255 +
19256 +       if (!vxi)
19257 +               return -EINVAL;
19258 +       log = &vxi->cvirt.syslog;
19259 +
19260 +       switch (type) {
19261 +       case 0:         /* Close log */
19262 +       case 1:         /* Open log */
19263 +               break;
19264 +       case 2:         /* Read from log */
19265 +               error = wait_event_interruptible(log->log_wait,
19266 +                       (log->log_start - log->log_end));
19267 +               if (error)
19268 +                       break;
19269 +               spin_lock_irq(&log->logbuf_lock);
19270 +               spin_unlock_irq(&log->logbuf_lock);
19271 +               break;
19272 +       case 4:         /* Read/clear last kernel messages */
19273 +               do_clear = 1;
19274 +               /* fall through */
19275 +       case 3:         /* Read last kernel messages */
19276 +               return 0;
19277 +
19278 +       case 5:         /* Clear ring buffer */
19279 +               return 0;
19280 +
19281 +       case 6:         /* Disable logging to console */
19282 +       case 7:         /* Enable logging to console */
19283 +       case 8:         /* Set level of messages printed to console */
19284 +               break;
19285 +
19286 +       case 9:         /* Number of chars in the log buffer */
19287 +               return 0;
19288 +       case 10:        /* Size of the log buffer */
19289 +               return 0;
19290 +       default:
19291 +               error = -EINVAL;
19292 +               break;
19293 +       }
19294 +       return error;
19295 +}
19296 +
19297 +
19298 +/* virtual host info names */
19299 +
19300 +static char *vx_vhi_name(struct vx_info *vxi, int id)
19301 +{
19302 +       struct nsproxy *nsproxy;
19303 +       struct uts_namespace *uts;
19304 +
19305 +       if (id == VHIN_CONTEXT)
19306 +               return vxi->vx_name;
19307 +
19308 +       nsproxy = vxi->space[0].vx_nsproxy;
19309 +       if (!nsproxy)
19310 +               return NULL;
19311 +
19312 +       uts = nsproxy->uts_ns;
19313 +       if (!uts)
19314 +               return NULL;
19315 +
19316 +       switch (id) {
19317 +       case VHIN_SYSNAME:
19318 +               return uts->name.sysname;
19319 +       case VHIN_NODENAME:
19320 +               return uts->name.nodename;
19321 +       case VHIN_RELEASE:
19322 +               return uts->name.release;
19323 +       case VHIN_VERSION:
19324 +               return uts->name.version;
19325 +       case VHIN_MACHINE:
19326 +               return uts->name.machine;
19327 +       case VHIN_DOMAINNAME:
19328 +               return uts->name.domainname;
19329 +       default:
19330 +               return NULL;
19331 +       }
19332 +       return NULL;
19333 +}
19334 +
19335 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
19336 +{
19337 +       struct vcmd_vhi_name_v0 vc_data;
19338 +       char *name;
19339 +
19340 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19341 +               return -EFAULT;
19342 +
19343 +       name = vx_vhi_name(vxi, vc_data.field);
19344 +       if (!name)
19345 +               return -EINVAL;
19346 +
19347 +       memcpy(name, vc_data.name, 65);
19348 +       return 0;
19349 +}
19350 +
19351 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
19352 +{
19353 +       struct vcmd_vhi_name_v0 vc_data;
19354 +       char *name;
19355 +
19356 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19357 +               return -EFAULT;
19358 +
19359 +       name = vx_vhi_name(vxi, vc_data.field);
19360 +       if (!name)
19361 +               return -EINVAL;
19362 +
19363 +       memcpy(vc_data.name, name, 65);
19364 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19365 +               return -EFAULT;
19366 +       return 0;
19367 +}
19368 +
19369 +
19370 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
19371 +{
19372 +       struct vcmd_virt_stat_v0 vc_data;
19373 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
19374 +       struct timespec uptime;
19375 +
19376 +       do_posix_clock_monotonic_gettime(&uptime);
19377 +       set_normalized_timespec(&uptime,
19378 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
19379 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
19380 +
19381 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
19382 +       vc_data.uptime = timespec_to_ns(&uptime);
19383 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
19384 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
19385 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
19386 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
19387 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
19388 +       vc_data.load[0] = cvirt->load[0];
19389 +       vc_data.load[1] = cvirt->load[1];
19390 +       vc_data.load[2] = cvirt->load[2];
19391 +
19392 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19393 +               return -EFAULT;
19394 +       return 0;
19395 +}
19396 +
19397 +
19398 +#ifdef CONFIG_VSERVER_VTIME
19399 +
19400 +/* virtualized time base */
19401 +
19402 +void vx_adjust_timespec(struct timespec *ts)
19403 +{
19404 +       struct vx_info *vxi;
19405 +
19406 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19407 +               return;
19408 +
19409 +       vxi = current_vx_info();
19410 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
19411 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
19412 +
19413 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
19414 +               ts->tv_sec++;
19415 +               ts->tv_nsec -= NSEC_PER_SEC;
19416 +       } else if (ts->tv_nsec < 0) {
19417 +               ts->tv_sec--;
19418 +               ts->tv_nsec += NSEC_PER_SEC;
19419 +       }
19420 +}
19421 +
19422 +int vx_settimeofday(const struct timespec *ts)
19423 +{
19424 +       struct timespec ats, delta;
19425 +       struct vx_info *vxi;
19426 +
19427 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19428 +               return do_settimeofday(ts);
19429 +
19430 +       getnstimeofday(&ats);
19431 +       delta = timespec_sub(*ts, ats);
19432 +
19433 +       vxi = current_vx_info();
19434 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
19435 +       return 0;
19436 +}
19437 +
19438 +#endif
19439 +
19440 diff -NurpP --minimal linux-3.0.4/kernel/vserver/cvirt_init.h linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cvirt_init.h
19441 --- linux-3.0.4/kernel/vserver/cvirt_init.h     1970-01-01 01:00:00.000000000 +0100
19442 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cvirt_init.h     2011-06-10 22:11:24.000000000 +0200
19443 @@ -0,0 +1,70 @@
19444 +
19445 +
19446 +extern uint64_t vx_idle_jiffies(void);
19447 +
19448 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19449 +{
19450 +       uint64_t idle_jiffies = vx_idle_jiffies();
19451 +       uint64_t nsuptime;
19452 +
19453 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19454 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19455 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19456 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19457 +       cvirt->bias_ts.tv_sec = 0;
19458 +       cvirt->bias_ts.tv_nsec = 0;
19459 +
19460 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19461 +       atomic_set(&cvirt->nr_threads, 0);
19462 +       atomic_set(&cvirt->nr_running, 0);
19463 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19464 +       atomic_set(&cvirt->nr_onhold, 0);
19465 +
19466 +       spin_lock_init(&cvirt->load_lock);
19467 +       cvirt->load_last = jiffies;
19468 +       atomic_set(&cvirt->load_updates, 0);
19469 +       cvirt->load[0] = 0;
19470 +       cvirt->load[1] = 0;
19471 +       cvirt->load[2] = 0;
19472 +       atomic_set(&cvirt->total_forks, 0);
19473 +
19474 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19475 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19476 +       cvirt->syslog.log_start = 0;
19477 +       cvirt->syslog.log_end = 0;
19478 +       cvirt->syslog.con_start = 0;
19479 +       cvirt->syslog.logged_chars = 0;
19480 +}
19481 +
19482 +static inline
19483 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19484 +{
19485 +       // cvirt_pc->cpustat = { 0 };
19486 +}
19487 +
19488 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19489 +{
19490 +#ifdef CONFIG_VSERVER_WARN
19491 +       int value;
19492 +#endif
19493 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19494 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19495 +               cvirt, value);
19496 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19497 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19498 +               cvirt, value);
19499 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19500 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19501 +               cvirt, value);
19502 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19503 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19504 +               cvirt, value);
19505 +       return;
19506 +}
19507 +
19508 +static inline
19509 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19510 +{
19511 +       return;
19512 +}
19513 +
19514 diff -NurpP --minimal linux-3.0.4/kernel/vserver/cvirt_proc.h linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cvirt_proc.h
19515 --- linux-3.0.4/kernel/vserver/cvirt_proc.h     1970-01-01 01:00:00.000000000 +0100
19516 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/cvirt_proc.h     2011-06-10 22:11:24.000000000 +0200
19517 @@ -0,0 +1,135 @@
19518 +#ifndef _VX_CVIRT_PROC_H
19519 +#define _VX_CVIRT_PROC_H
19520 +
19521 +#include <linux/nsproxy.h>
19522 +#include <linux/mnt_namespace.h>
19523 +#include <linux/ipc_namespace.h>
19524 +#include <linux/utsname.h>
19525 +#include <linux/ipc.h>
19526 +
19527 +
19528 +static inline
19529 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19530 +{
19531 +       struct mnt_namespace *ns;
19532 +       struct uts_namespace *uts;
19533 +       struct ipc_namespace *ipc;
19534 +       struct path path;
19535 +       char *pstr, *root;
19536 +       int length = 0;
19537 +
19538 +       if (!nsproxy)
19539 +               goto out;
19540 +
19541 +       length += sprintf(buffer + length,
19542 +               "NSProxy:\t%p [%p,%p,%p]\n",
19543 +               nsproxy, nsproxy->mnt_ns,
19544 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19545 +
19546 +       ns = nsproxy->mnt_ns;
19547 +       if (!ns)
19548 +               goto skip_ns;
19549 +
19550 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19551 +       if (!pstr)
19552 +               goto skip_ns;
19553 +
19554 +       path.mnt = ns->root;
19555 +       path.dentry = ns->root->mnt_root;
19556 +       root = d_path(&path, pstr, PATH_MAX - 2);
19557 +       length += sprintf(buffer + length,
19558 +               "Namespace:\t%p [#%u]\n"
19559 +               "RootPath:\t%s\n",
19560 +               ns, atomic_read(&ns->count),
19561 +               root);
19562 +       kfree(pstr);
19563 +skip_ns:
19564 +
19565 +       uts = nsproxy->uts_ns;
19566 +       if (!uts)
19567 +               goto skip_uts;
19568 +
19569 +       length += sprintf(buffer + length,
19570 +               "SysName:\t%.*s\n"
19571 +               "NodeName:\t%.*s\n"
19572 +               "Release:\t%.*s\n"
19573 +               "Version:\t%.*s\n"
19574 +               "Machine:\t%.*s\n"
19575 +               "DomainName:\t%.*s\n",
19576 +               __NEW_UTS_LEN, uts->name.sysname,
19577 +               __NEW_UTS_LEN, uts->name.nodename,
19578 +               __NEW_UTS_LEN, uts->name.release,
19579 +               __NEW_UTS_LEN, uts->name.version,
19580 +               __NEW_UTS_LEN, uts->name.machine,
19581 +               __NEW_UTS_LEN, uts->name.domainname);
19582 +skip_uts:
19583 +
19584 +       ipc = nsproxy->ipc_ns;
19585 +       if (!ipc)
19586 +               goto skip_ipc;
19587 +
19588 +       length += sprintf(buffer + length,
19589 +               "SEMS:\t\t%d %d %d %d  %d\n"
19590 +               "MSG:\t\t%d %d %d\n"
19591 +               "SHM:\t\t%lu %lu  %d %d\n",
19592 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19593 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19594 +               ipc->used_sems,
19595 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19596 +               (unsigned long)ipc->shm_ctlmax,
19597 +               (unsigned long)ipc->shm_ctlall,
19598 +               ipc->shm_ctlmni, ipc->shm_tot);
19599 +skip_ipc:
19600 +out:
19601 +       return length;
19602 +}
19603 +
19604 +
19605 +#include <linux/sched.h>
19606 +
19607 +#define LOAD_INT(x) ((x) >> FSHIFT)
19608 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19609 +
19610 +static inline
19611 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19612 +{
19613 +       int length = 0;
19614 +       int a, b, c;
19615 +
19616 +       length += sprintf(buffer + length,
19617 +               "BiasUptime:\t%lu.%02lu\n",
19618 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19619 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19620 +
19621 +       a = cvirt->load[0] + (FIXED_1 / 200);
19622 +       b = cvirt->load[1] + (FIXED_1 / 200);
19623 +       c = cvirt->load[2] + (FIXED_1 / 200);
19624 +       length += sprintf(buffer + length,
19625 +               "nr_threads:\t%d\n"
19626 +               "nr_running:\t%d\n"
19627 +               "nr_unintr:\t%d\n"
19628 +               "nr_onhold:\t%d\n"
19629 +               "load_updates:\t%d\n"
19630 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19631 +               "total_forks:\t%d\n",
19632 +               atomic_read(&cvirt->nr_threads),
19633 +               atomic_read(&cvirt->nr_running),
19634 +               atomic_read(&cvirt->nr_uninterruptible),
19635 +               atomic_read(&cvirt->nr_onhold),
19636 +               atomic_read(&cvirt->load_updates),
19637 +               LOAD_INT(a), LOAD_FRAC(a),
19638 +               LOAD_INT(b), LOAD_FRAC(b),
19639 +               LOAD_INT(c), LOAD_FRAC(c),
19640 +               atomic_read(&cvirt->total_forks));
19641 +       return length;
19642 +}
19643 +
19644 +static inline
19645 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19646 +       char *buffer, int cpu)
19647 +{
19648 +       int length = 0;
19649 +       return length;
19650 +}
19651 +
19652 +#endif /* _VX_CVIRT_PROC_H */
19653 diff -NurpP --minimal linux-3.0.4/kernel/vserver/debug.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/debug.c
19654 --- linux-3.0.4/kernel/vserver/debug.c  1970-01-01 01:00:00.000000000 +0100
19655 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/debug.c  2011-06-10 22:11:24.000000000 +0200
19656 @@ -0,0 +1,32 @@
19657 +/*
19658 + *  kernel/vserver/debug.c
19659 + *
19660 + *  Copyright (C) 2005-2007 Herbert Pötzl
19661 + *
19662 + *  V0.01  vx_info dump support
19663 + *
19664 + */
19665 +
19666 +#include <linux/module.h>
19667 +
19668 +#include <linux/vserver/context.h>
19669 +
19670 +
19671 +void   dump_vx_info(struct vx_info *vxi, int level)
19672 +{
19673 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19674 +               atomic_read(&vxi->vx_usecnt),
19675 +               atomic_read(&vxi->vx_tasks),
19676 +               vxi->vx_state);
19677 +       if (level > 0) {
19678 +               __dump_vx_limit(&vxi->limit);
19679 +               __dump_vx_sched(&vxi->sched);
19680 +               __dump_vx_cvirt(&vxi->cvirt);
19681 +               __dump_vx_cacct(&vxi->cacct);
19682 +       }
19683 +       printk("---\n");
19684 +}
19685 +
19686 +
19687 +EXPORT_SYMBOL_GPL(dump_vx_info);
19688 +
19689 diff -NurpP --minimal linux-3.0.4/kernel/vserver/device.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/device.c
19690 --- linux-3.0.4/kernel/vserver/device.c 1970-01-01 01:00:00.000000000 +0100
19691 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/device.c 2011-06-10 23:20:56.000000000 +0200
19692 @@ -0,0 +1,443 @@
19693 +/*
19694 + *  linux/kernel/vserver/device.c
19695 + *
19696 + *  Linux-VServer: Device Support
19697 + *
19698 + *  Copyright (C) 2006  Herbert Pötzl
19699 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19700 + *
19701 + *  V0.01  device mapping basics
19702 + *  V0.02  added defaults
19703 + *
19704 + */
19705 +
19706 +#include <linux/slab.h>
19707 +#include <linux/rcupdate.h>
19708 +#include <linux/fs.h>
19709 +#include <linux/namei.h>
19710 +#include <linux/hash.h>
19711 +
19712 +#include <asm/errno.h>
19713 +#include <asm/uaccess.h>
19714 +#include <linux/vserver/base.h>
19715 +#include <linux/vserver/debug.h>
19716 +#include <linux/vserver/context.h>
19717 +#include <linux/vserver/device.h>
19718 +#include <linux/vserver/device_cmd.h>
19719 +
19720 +
19721 +#define DMAP_HASH_BITS 4
19722 +
19723 +
19724 +struct vs_mapping {
19725 +       union {
19726 +               struct hlist_node hlist;
19727 +               struct list_head list;
19728 +       } u;
19729 +#define dm_hlist       u.hlist
19730 +#define dm_list                u.list
19731 +       xid_t xid;
19732 +       dev_t device;
19733 +       struct vx_dmap_target target;
19734 +};
19735 +
19736 +
19737 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19738 +
19739 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
19740 +
19741 +static struct vx_dmap_target dmap_defaults[2] = {
19742 +       { .flags = DATTR_OPEN },
19743 +       { .flags = DATTR_OPEN },
19744 +};
19745 +
19746 +
19747 +struct kmem_cache *dmap_cachep __read_mostly;
19748 +
19749 +int __init dmap_cache_init(void)
19750 +{
19751 +       dmap_cachep = kmem_cache_create("dmap_cache",
19752 +               sizeof(struct vs_mapping), 0,
19753 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19754 +       return 0;
19755 +}
19756 +
19757 +__initcall(dmap_cache_init);
19758 +
19759 +
19760 +static inline unsigned int __hashval(dev_t dev, int bits)
19761 +{
19762 +       return hash_long((unsigned long)dev, bits);
19763 +}
19764 +
19765 +
19766 +/*     __hash_mapping()
19767 + *     add the mapping to the hash table
19768 + */
19769 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19770 +{
19771 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19772 +       struct hlist_head *head, *hash = dmap_main_hash;
19773 +       int device = vdm->device;
19774 +
19775 +       spin_lock(hash_lock);
19776 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19777 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19778 +
19779 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19780 +       hlist_add_head(&vdm->dm_hlist, head);
19781 +       spin_unlock(hash_lock);
19782 +}
19783 +
19784 +
19785 +static inline int __mode_to_default(umode_t mode)
19786 +{
19787 +       switch (mode) {
19788 +       case S_IFBLK:
19789 +               return 0;
19790 +       case S_IFCHR:
19791 +               return 1;
19792 +       default:
19793 +               BUG();
19794 +       }
19795 +}
19796 +
19797 +
19798 +/*     __set_default()
19799 + *     set a default
19800 + */
19801 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19802 +       struct vx_dmap_target *vdmt)
19803 +{
19804 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19805 +       spin_lock(hash_lock);
19806 +
19807 +       if (vxi)
19808 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19809 +       else
19810 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19811 +
19812 +
19813 +       spin_unlock(hash_lock);
19814 +
19815 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19816 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19817 +}
19818 +
19819 +
19820 +/*     __remove_default()
19821 + *     remove a default
19822 + */
19823 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19824 +{
19825 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19826 +       spin_lock(hash_lock);
19827 +
19828 +       if (vxi)
19829 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19830 +       else    /* remove == reset */
19831 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19832 +
19833 +       spin_unlock(hash_lock);
19834 +       return 0;
19835 +}
19836 +
19837 +
19838 +/*     __find_mapping()
19839 + *     find a mapping in the hash table
19840 + *
19841 + *     caller must hold hash_lock
19842 + */
19843 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19844 +       struct vs_mapping **local, struct vs_mapping **global)
19845 +{
19846 +       struct hlist_head *hash = dmap_main_hash;
19847 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19848 +       struct hlist_node *pos;
19849 +       struct vs_mapping *vdm;
19850 +
19851 +       *local = NULL;
19852 +       if (global)
19853 +               *global = NULL;
19854 +
19855 +       hlist_for_each(pos, head) {
19856 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19857 +
19858 +               if ((vdm->device == device) &&
19859 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19860 +                       if (vdm->xid == xid) {
19861 +                               *local = vdm;
19862 +                               return 1;
19863 +                       } else if (global && vdm->xid == 0)
19864 +                               *global = vdm;
19865 +               }
19866 +       }
19867 +
19868 +       if (global && *global)
19869 +               return 0;
19870 +       else
19871 +               return -ENOENT;
19872 +}
19873 +
19874 +
19875 +/*     __lookup_mapping()
19876 + *     find a mapping and store the result in target and flags
19877 + */
19878 +static inline int __lookup_mapping(struct vx_info *vxi,
19879 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19880 +{
19881 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19882 +       struct vs_mapping *vdm, *global;
19883 +       struct vx_dmap_target *vdmt;
19884 +       int ret = 0;
19885 +       xid_t xid = vxi->vx_id;
19886 +       int index;
19887 +
19888 +       spin_lock(hash_lock);
19889 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19890 +               ret = 1;
19891 +               vdmt = &vdm->target;
19892 +               goto found;
19893 +       }
19894 +
19895 +       index = __mode_to_default(mode);
19896 +       if (vxi && vxi->dmap.targets[index].flags) {
19897 +               ret = 2;
19898 +               vdmt = &vxi->dmap.targets[index];
19899 +       } else if (global) {
19900 +               ret = 3;
19901 +               vdmt = &global->target;
19902 +               goto found;
19903 +       } else {
19904 +               ret = 4;
19905 +               vdmt = &dmap_defaults[index];
19906 +       }
19907 +
19908 +found:
19909 +       if (target && (vdmt->flags & DATTR_REMAP))
19910 +               *target = vdmt->target;
19911 +       else if (target)
19912 +               *target = device;
19913 +       if (flags)
19914 +               *flags = vdmt->flags;
19915 +
19916 +       spin_unlock(hash_lock);
19917 +
19918 +       return ret;
19919 +}
19920 +
19921 +
19922 +/*     __remove_mapping()
19923 + *     remove a mapping from the hash table
19924 + */
19925 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19926 +       umode_t mode)
19927 +{
19928 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19929 +       struct vs_mapping *vdm = NULL;
19930 +       int ret = 0;
19931 +
19932 +       spin_lock(hash_lock);
19933 +
19934 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19935 +               NULL);
19936 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19937 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19938 +       if (ret < 0)
19939 +               goto out;
19940 +       hlist_del(&vdm->dm_hlist);
19941 +
19942 +out:
19943 +       spin_unlock(hash_lock);
19944 +       if (vdm)
19945 +               kmem_cache_free(dmap_cachep, vdm);
19946 +       return ret;
19947 +}
19948 +
19949 +
19950 +
19951 +int vs_map_device(struct vx_info *vxi,
19952 +       dev_t device, dev_t *target, umode_t mode)
19953 +{
19954 +       int ret, flags = DATTR_MASK;
19955 +
19956 +       if (!vxi) {
19957 +               if (target)
19958 +                       *target = device;
19959 +               goto out;
19960 +       }
19961 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19962 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19963 +               device, target ? *target : 0, flags, mode, ret);
19964 +out:
19965 +       return (flags & DATTR_MASK);
19966 +}
19967 +
19968 +
19969 +
19970 +static int do_set_mapping(struct vx_info *vxi,
19971 +       dev_t device, dev_t target, int flags, umode_t mode)
19972 +{
19973 +       if (device) {
19974 +               struct vs_mapping *new;
19975 +
19976 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19977 +               if (!new)
19978 +                       return -ENOMEM;
19979 +
19980 +               INIT_HLIST_NODE(&new->dm_hlist);
19981 +               new->device = device;
19982 +               new->target.target = target;
19983 +               new->target.flags = flags | mode;
19984 +               new->xid = (vxi ? vxi->vx_id : 0);
19985 +
19986 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19987 +               __hash_mapping(vxi, new);
19988 +       } else {
19989 +               struct vx_dmap_target new = {
19990 +                       .target = target,
19991 +                       .flags = flags | mode,
19992 +               };
19993 +               __set_default(vxi, mode, &new);
19994 +       }
19995 +       return 0;
19996 +}
19997 +
19998 +
19999 +static int do_unset_mapping(struct vx_info *vxi,
20000 +       dev_t device, dev_t target, int flags, umode_t mode)
20001 +{
20002 +       int ret = -EINVAL;
20003 +
20004 +       if (device) {
20005 +               ret = __remove_mapping(vxi, device, mode);
20006 +               if (ret < 0)
20007 +                       goto out;
20008 +       } else {
20009 +               ret = __remove_default(vxi, mode);
20010 +               if (ret < 0)
20011 +                       goto out;
20012 +       }
20013 +
20014 +out:
20015 +       return ret;
20016 +}
20017 +
20018 +
20019 +static inline int __user_device(const char __user *name, dev_t *dev,
20020 +       umode_t *mode)
20021 +{
20022 +       struct nameidata nd;
20023 +       int ret;
20024 +
20025 +       if (!name) {
20026 +               *dev = 0;
20027 +               return 0;
20028 +       }
20029 +       ret = user_lpath(name, &nd.path);
20030 +       if (ret)
20031 +               return ret;
20032 +       if (nd.path.dentry->d_inode) {
20033 +               *dev = nd.path.dentry->d_inode->i_rdev;
20034 +               *mode = nd.path.dentry->d_inode->i_mode;
20035 +       }
20036 +       path_put(&nd.path);
20037 +       return 0;
20038 +}
20039 +
20040 +static inline int __mapping_mode(dev_t device, dev_t target,
20041 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
20042 +{
20043 +       if (device)
20044 +               *mode = device_mode & S_IFMT;
20045 +       else if (target)
20046 +               *mode = target_mode & S_IFMT;
20047 +       else
20048 +               return -EINVAL;
20049 +
20050 +       /* if both given, device and target mode have to match */
20051 +       if (device && target &&
20052 +               ((device_mode ^ target_mode) & S_IFMT))
20053 +               return -EINVAL;
20054 +       return 0;
20055 +}
20056 +
20057 +
20058 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
20059 +       const char __user *target_path, int flags, int set)
20060 +{
20061 +       dev_t device = ~0, target = ~0;
20062 +       umode_t device_mode = 0, target_mode = 0, mode;
20063 +       int ret;
20064 +
20065 +       ret = __user_device(device_path, &device, &device_mode);
20066 +       if (ret)
20067 +               return ret;
20068 +       ret = __user_device(target_path, &target, &target_mode);
20069 +       if (ret)
20070 +               return ret;
20071 +
20072 +       ret = __mapping_mode(device, target,
20073 +               device_mode, target_mode, &mode);
20074 +       if (ret)
20075 +               return ret;
20076 +
20077 +       if (set)
20078 +               return do_set_mapping(vxi, device, target,
20079 +                       flags, mode);
20080 +       else
20081 +               return do_unset_mapping(vxi, device, target,
20082 +                       flags, mode);
20083 +}
20084 +
20085 +
20086 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
20087 +{
20088 +       struct vcmd_set_mapping_v0 vc_data;
20089 +
20090 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20091 +               return -EFAULT;
20092 +
20093 +       return do_mapping(vxi, vc_data.device, vc_data.target,
20094 +               vc_data.flags, 1);
20095 +}
20096 +
20097 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
20098 +{
20099 +       struct vcmd_set_mapping_v0 vc_data;
20100 +
20101 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20102 +               return -EFAULT;
20103 +
20104 +       return do_mapping(vxi, vc_data.device, vc_data.target,
20105 +               vc_data.flags, 0);
20106 +}
20107 +
20108 +
20109 +#ifdef CONFIG_COMPAT
20110 +
20111 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
20112 +{
20113 +       struct vcmd_set_mapping_v0_x32 vc_data;
20114 +
20115 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20116 +               return -EFAULT;
20117 +
20118 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
20119 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
20120 +}
20121 +
20122 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
20123 +{
20124 +       struct vcmd_set_mapping_v0_x32 vc_data;
20125 +
20126 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20127 +               return -EFAULT;
20128 +
20129 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
20130 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
20131 +}
20132 +
20133 +#endif /* CONFIG_COMPAT */
20134 +
20135 +
20136 diff -NurpP --minimal linux-3.0.4/kernel/vserver/dlimit.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/dlimit.c
20137 --- linux-3.0.4/kernel/vserver/dlimit.c 1970-01-01 01:00:00.000000000 +0100
20138 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/dlimit.c 2011-06-10 23:20:56.000000000 +0200
20139 @@ -0,0 +1,531 @@
20140 +/*
20141 + *  linux/kernel/vserver/dlimit.c
20142 + *
20143 + *  Virtual Server: Context Disk Limits
20144 + *
20145 + *  Copyright (C) 2004-2009  Herbert Pötzl
20146 + *
20147 + *  V0.01  initial version
20148 + *  V0.02  compat32 splitup
20149 + *  V0.03  extended interface
20150 + *
20151 + */
20152 +
20153 +#include <linux/statfs.h>
20154 +#include <linux/sched.h>
20155 +#include <linux/namei.h>
20156 +#include <linux/vs_tag.h>
20157 +#include <linux/vs_dlimit.h>
20158 +#include <linux/vserver/dlimit_cmd.h>
20159 +#include <linux/slab.h>
20160 +// #include <linux/gfp.h>
20161 +
20162 +#include <asm/uaccess.h>
20163 +
20164 +/*     __alloc_dl_info()
20165 +
20166 +       * allocate an initialized dl_info struct
20167 +       * doesn't make it visible (hash)                        */
20168 +
20169 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
20170 +{
20171 +       struct dl_info *new = NULL;
20172 +
20173 +       vxdprintk(VXD_CBIT(dlim, 5),
20174 +               "alloc_dl_info(%p,%d)*", sb, tag);
20175 +
20176 +       /* would this benefit from a slab cache? */
20177 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
20178 +       if (!new)
20179 +               return 0;
20180 +
20181 +       memset(new, 0, sizeof(struct dl_info));
20182 +       new->dl_tag = tag;
20183 +       new->dl_sb = sb;
20184 +       // INIT_RCU_HEAD(&new->dl_rcu);
20185 +       INIT_HLIST_NODE(&new->dl_hlist);
20186 +       spin_lock_init(&new->dl_lock);
20187 +       atomic_set(&new->dl_refcnt, 0);
20188 +       atomic_set(&new->dl_usecnt, 0);
20189 +
20190 +       /* rest of init goes here */
20191 +
20192 +       vxdprintk(VXD_CBIT(dlim, 4),
20193 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
20194 +       return new;
20195 +}
20196 +
20197 +/*     __dealloc_dl_info()
20198 +
20199 +       * final disposal of dl_info                             */
20200 +
20201 +static void __dealloc_dl_info(struct dl_info *dli)
20202 +{
20203 +       vxdprintk(VXD_CBIT(dlim, 4),
20204 +               "dealloc_dl_info(%p)", dli);
20205 +
20206 +       dli->dl_hlist.next = LIST_POISON1;
20207 +       dli->dl_tag = -1;
20208 +       dli->dl_sb = 0;
20209 +
20210 +       BUG_ON(atomic_read(&dli->dl_usecnt));
20211 +       BUG_ON(atomic_read(&dli->dl_refcnt));
20212 +
20213 +       kfree(dli);
20214 +}
20215 +
20216 +
20217 +/*     hash table for dl_info hash */
20218 +
20219 +#define DL_HASH_SIZE   13
20220 +
20221 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
20222 +
20223 +static DEFINE_SPINLOCK(dl_info_hash_lock);
20224 +
20225 +
20226 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
20227 +{
20228 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
20229 +}
20230 +
20231 +
20232 +
20233 +/*     __hash_dl_info()
20234 +
20235 +       * add the dli to the global hash table
20236 +       * requires the hash_lock to be held                     */
20237 +
20238 +static inline void __hash_dl_info(struct dl_info *dli)
20239 +{
20240 +       struct hlist_head *head;
20241 +
20242 +       vxdprintk(VXD_CBIT(dlim, 6),
20243 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
20244 +       get_dl_info(dli);
20245 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
20246 +       hlist_add_head_rcu(&dli->dl_hlist, head);
20247 +}
20248 +
20249 +/*     __unhash_dl_info()
20250 +
20251 +       * remove the dli from the global hash table
20252 +       * requires the hash_lock to be held                     */
20253 +
20254 +static inline void __unhash_dl_info(struct dl_info *dli)
20255 +{
20256 +       vxdprintk(VXD_CBIT(dlim, 6),
20257 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
20258 +       hlist_del_rcu(&dli->dl_hlist);
20259 +       put_dl_info(dli);
20260 +}
20261 +
20262 +
20263 +/*     __lookup_dl_info()
20264 +
20265 +       * requires the rcu_read_lock()
20266 +       * doesn't increment the dl_refcnt                       */
20267 +
20268 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
20269 +{
20270 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
20271 +       struct hlist_node *pos;
20272 +       struct dl_info *dli;
20273 +
20274 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
20275 +
20276 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
20277 +                       return dli;
20278 +               }
20279 +       }
20280 +       return NULL;
20281 +}
20282 +
20283 +
20284 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
20285 +{
20286 +       struct dl_info *dli;
20287 +
20288 +       rcu_read_lock();
20289 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
20290 +       vxdprintk(VXD_CBIT(dlim, 7),
20291 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
20292 +       rcu_read_unlock();
20293 +       return dli;
20294 +}
20295 +
20296 +void rcu_free_dl_info(struct rcu_head *head)
20297 +{
20298 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
20299 +       int usecnt, refcnt;
20300 +
20301 +       BUG_ON(!dli || !head);
20302 +
20303 +       usecnt = atomic_read(&dli->dl_usecnt);
20304 +       BUG_ON(usecnt < 0);
20305 +
20306 +       refcnt = atomic_read(&dli->dl_refcnt);
20307 +       BUG_ON(refcnt < 0);
20308 +
20309 +       vxdprintk(VXD_CBIT(dlim, 3),
20310 +               "rcu_free_dl_info(%p)", dli);
20311 +       if (!usecnt)
20312 +               __dealloc_dl_info(dli);
20313 +       else
20314 +               printk("!!! rcu didn't free\n");
20315 +}
20316 +
20317 +
20318 +
20319 +
20320 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
20321 +       uint32_t flags, int add)
20322 +{
20323 +       struct path path;
20324 +       int ret;
20325 +
20326 +       ret = user_lpath(name, &path);
20327 +       if (!ret) {
20328 +               struct super_block *sb;
20329 +               struct dl_info *dli;
20330 +
20331 +               ret = -EINVAL;
20332 +               if (!path.dentry->d_inode)
20333 +                       goto out_release;
20334 +               if (!(sb = path.dentry->d_inode->i_sb))
20335 +                       goto out_release;
20336 +
20337 +               if (add) {
20338 +                       dli = __alloc_dl_info(sb, id);
20339 +                       spin_lock(&dl_info_hash_lock);
20340 +
20341 +                       ret = -EEXIST;
20342 +                       if (__lookup_dl_info(sb, id))
20343 +                               goto out_unlock;
20344 +                       __hash_dl_info(dli);
20345 +                       dli = NULL;
20346 +               } else {
20347 +                       spin_lock(&dl_info_hash_lock);
20348 +                       dli = __lookup_dl_info(sb, id);
20349 +
20350 +                       ret = -ESRCH;
20351 +                       if (!dli)
20352 +                               goto out_unlock;
20353 +                       __unhash_dl_info(dli);
20354 +               }
20355 +               ret = 0;
20356 +       out_unlock:
20357 +               spin_unlock(&dl_info_hash_lock);
20358 +               if (add && dli)
20359 +                       __dealloc_dl_info(dli);
20360 +       out_release:
20361 +               path_put(&path);
20362 +       }
20363 +       return ret;
20364 +}
20365 +
20366 +int vc_add_dlimit(uint32_t id, void __user *data)
20367 +{
20368 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20369 +
20370 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20371 +               return -EFAULT;
20372 +
20373 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
20374 +}
20375 +
20376 +int vc_rem_dlimit(uint32_t id, void __user *data)
20377 +{
20378 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20379 +
20380 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20381 +               return -EFAULT;
20382 +
20383 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
20384 +}
20385 +
20386 +#ifdef CONFIG_COMPAT
20387 +
20388 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
20389 +{
20390 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20391 +
20392 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20393 +               return -EFAULT;
20394 +
20395 +       return do_addrem_dlimit(id,
20396 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
20397 +}
20398 +
20399 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
20400 +{
20401 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20402 +
20403 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20404 +               return -EFAULT;
20405 +
20406 +       return do_addrem_dlimit(id,
20407 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
20408 +}
20409 +
20410 +#endif /* CONFIG_COMPAT */
20411 +
20412 +
20413 +static inline
20414 +int do_set_dlimit(uint32_t id, const char __user *name,
20415 +       uint32_t space_used, uint32_t space_total,
20416 +       uint32_t inodes_used, uint32_t inodes_total,
20417 +       uint32_t reserved, uint32_t flags)
20418 +{
20419 +       struct path path;
20420 +       int ret;
20421 +
20422 +       ret = user_lpath(name, &path);
20423 +       if (!ret) {
20424 +               struct super_block *sb;
20425 +               struct dl_info *dli;
20426 +
20427 +               ret = -EINVAL;
20428 +               if (!path.dentry->d_inode)
20429 +                       goto out_release;
20430 +               if (!(sb = path.dentry->d_inode->i_sb))
20431 +                       goto out_release;
20432 +
20433 +               /* sanity checks */
20434 +               if ((reserved != CDLIM_KEEP &&
20435 +                       reserved > 100) ||
20436 +                       (inodes_used != CDLIM_KEEP &&
20437 +                       inodes_used > inodes_total) ||
20438 +                       (space_used != CDLIM_KEEP &&
20439 +                       space_used > space_total))
20440 +                       goto out_release;
20441 +
20442 +               ret = -ESRCH;
20443 +               dli = locate_dl_info(sb, id);
20444 +               if (!dli)
20445 +                       goto out_release;
20446 +
20447 +               spin_lock(&dli->dl_lock);
20448 +
20449 +               if (inodes_used != CDLIM_KEEP)
20450 +                       dli->dl_inodes_used = inodes_used;
20451 +               if (inodes_total != CDLIM_KEEP)
20452 +                       dli->dl_inodes_total = inodes_total;
20453 +               if (space_used != CDLIM_KEEP)
20454 +                       dli->dl_space_used = dlimit_space_32to64(
20455 +                               space_used, flags, DLIMS_USED);
20456 +
20457 +               if (space_total == CDLIM_INFINITY)
20458 +                       dli->dl_space_total = DLIM_INFINITY;
20459 +               else if (space_total != CDLIM_KEEP)
20460 +                       dli->dl_space_total = dlimit_space_32to64(
20461 +                               space_total, flags, DLIMS_TOTAL);
20462 +
20463 +               if (reserved != CDLIM_KEEP)
20464 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
20465 +
20466 +               spin_unlock(&dli->dl_lock);
20467 +
20468 +               put_dl_info(dli);
20469 +               ret = 0;
20470 +
20471 +       out_release:
20472 +               path_put(&path);
20473 +       }
20474 +       return ret;
20475 +}
20476 +
20477 +int vc_set_dlimit(uint32_t id, void __user *data)
20478 +{
20479 +       struct vcmd_ctx_dlimit_v0 vc_data;
20480 +
20481 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20482 +               return -EFAULT;
20483 +
20484 +       return do_set_dlimit(id, vc_data.name,
20485 +               vc_data.space_used, vc_data.space_total,
20486 +               vc_data.inodes_used, vc_data.inodes_total,
20487 +               vc_data.reserved, vc_data.flags);
20488 +}
20489 +
20490 +#ifdef CONFIG_COMPAT
20491 +
20492 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20493 +{
20494 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20495 +
20496 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20497 +               return -EFAULT;
20498 +
20499 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20500 +               vc_data.space_used, vc_data.space_total,
20501 +               vc_data.inodes_used, vc_data.inodes_total,
20502 +               vc_data.reserved, vc_data.flags);
20503 +}
20504 +
20505 +#endif /* CONFIG_COMPAT */
20506 +
20507 +
20508 +static inline
20509 +int do_get_dlimit(uint32_t id, const char __user *name,
20510 +       uint32_t *space_used, uint32_t *space_total,
20511 +       uint32_t *inodes_used, uint32_t *inodes_total,
20512 +       uint32_t *reserved, uint32_t *flags)
20513 +{
20514 +       struct path path;
20515 +       int ret;
20516 +
20517 +       ret = user_lpath(name, &path);
20518 +       if (!ret) {
20519 +               struct super_block *sb;
20520 +               struct dl_info *dli;
20521 +
20522 +               ret = -EINVAL;
20523 +               if (!path.dentry->d_inode)
20524 +                       goto out_release;
20525 +               if (!(sb = path.dentry->d_inode->i_sb))
20526 +                       goto out_release;
20527 +
20528 +               ret = -ESRCH;
20529 +               dli = locate_dl_info(sb, id);
20530 +               if (!dli)
20531 +                       goto out_release;
20532 +
20533 +               spin_lock(&dli->dl_lock);
20534 +               *inodes_used = dli->dl_inodes_used;
20535 +               *inodes_total = dli->dl_inodes_total;
20536 +
20537 +               *space_used = dlimit_space_64to32(
20538 +                       dli->dl_space_used, flags, DLIMS_USED);
20539 +
20540 +               if (dli->dl_space_total == DLIM_INFINITY)
20541 +                       *space_total = CDLIM_INFINITY;
20542 +               else
20543 +                       *space_total = dlimit_space_64to32(
20544 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
20545 +
20546 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20547 +               spin_unlock(&dli->dl_lock);
20548 +
20549 +               put_dl_info(dli);
20550 +               ret = -EFAULT;
20551 +
20552 +               ret = 0;
20553 +       out_release:
20554 +               path_put(&path);
20555 +       }
20556 +       return ret;
20557 +}
20558 +
20559 +
20560 +int vc_get_dlimit(uint32_t id, void __user *data)
20561 +{
20562 +       struct vcmd_ctx_dlimit_v0 vc_data;
20563 +       int ret;
20564 +
20565 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20566 +               return -EFAULT;
20567 +
20568 +       ret = do_get_dlimit(id, vc_data.name,
20569 +               &vc_data.space_used, &vc_data.space_total,
20570 +               &vc_data.inodes_used, &vc_data.inodes_total,
20571 +               &vc_data.reserved, &vc_data.flags);
20572 +       if (ret)
20573 +               return ret;
20574 +
20575 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20576 +               return -EFAULT;
20577 +       return 0;
20578 +}
20579 +
20580 +#ifdef CONFIG_COMPAT
20581 +
20582 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20583 +{
20584 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20585 +       int ret;
20586 +
20587 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20588 +               return -EFAULT;
20589 +
20590 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20591 +               &vc_data.space_used, &vc_data.space_total,
20592 +               &vc_data.inodes_used, &vc_data.inodes_total,
20593 +               &vc_data.reserved, &vc_data.flags);
20594 +       if (ret)
20595 +               return ret;
20596 +
20597 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20598 +               return -EFAULT;
20599 +       return 0;
20600 +}
20601 +
20602 +#endif /* CONFIG_COMPAT */
20603 +
20604 +
20605 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20606 +{
20607 +       struct dl_info *dli;
20608 +       __u64 blimit, bfree, bavail;
20609 +       __u32 ifree;
20610 +
20611 +       dli = locate_dl_info(sb, dx_current_tag());
20612 +       if (!dli)
20613 +               return;
20614 +
20615 +       spin_lock(&dli->dl_lock);
20616 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20617 +               goto no_ilim;
20618 +
20619 +       /* reduce max inodes available to limit */
20620 +       if (buf->f_files > dli->dl_inodes_total)
20621 +               buf->f_files = dli->dl_inodes_total;
20622 +
20623 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20624 +       /* reduce free inodes to min */
20625 +       if (ifree < buf->f_ffree)
20626 +               buf->f_ffree = ifree;
20627 +
20628 +no_ilim:
20629 +       if (dli->dl_space_total == DLIM_INFINITY)
20630 +               goto no_blim;
20631 +
20632 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20633 +
20634 +       if (dli->dl_space_total < dli->dl_space_used)
20635 +               bfree = 0;
20636 +       else
20637 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20638 +                       >> sb->s_blocksize_bits;
20639 +
20640 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20641 +       if (bavail < dli->dl_space_used)
20642 +               bavail = 0;
20643 +       else
20644 +               bavail = (bavail - dli->dl_space_used)
20645 +                       >> sb->s_blocksize_bits;
20646 +
20647 +       /* reduce max space available to limit */
20648 +       if (buf->f_blocks > blimit)
20649 +               buf->f_blocks = blimit;
20650 +
20651 +       /* reduce free space to min */
20652 +       if (bfree < buf->f_bfree)
20653 +               buf->f_bfree = bfree;
20654 +
20655 +       /* reduce avail space to min */
20656 +       if (bavail < buf->f_bavail)
20657 +               buf->f_bavail = bavail;
20658 +
20659 +no_blim:
20660 +       spin_unlock(&dli->dl_lock);
20661 +       put_dl_info(dli);
20662 +
20663 +       return;
20664 +}
20665 +
20666 +#include <linux/module.h>
20667 +
20668 +EXPORT_SYMBOL_GPL(locate_dl_info);
20669 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20670 +
20671 diff -NurpP --minimal linux-3.0.4/kernel/vserver/helper.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/helper.c
20672 --- linux-3.0.4/kernel/vserver/helper.c 1970-01-01 01:00:00.000000000 +0100
20673 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/helper.c 2011-06-10 22:11:24.000000000 +0200
20674 @@ -0,0 +1,223 @@
20675 +/*
20676 + *  linux/kernel/vserver/helper.c
20677 + *
20678 + *  Virtual Context Support
20679 + *
20680 + *  Copyright (C) 2004-2007  Herbert Pötzl
20681 + *
20682 + *  V0.01  basic helper
20683 + *
20684 + */
20685 +
20686 +#include <linux/kmod.h>
20687 +#include <linux/reboot.h>
20688 +#include <linux/vs_context.h>
20689 +#include <linux/vs_network.h>
20690 +#include <linux/vserver/signal.h>
20691 +
20692 +
20693 +char vshelper_path[255] = "/sbin/vshelper";
20694 +
20695 +
20696 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20697 +{
20698 +       int ret;
20699 +
20700 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20701 +               printk( KERN_WARNING
20702 +                       "%s: (%s %s) returned %s with %d\n",
20703 +                       name, argv[1], argv[2],
20704 +                       sync ? "sync" : "async", ret);
20705 +       }
20706 +       vxdprintk(VXD_CBIT(switch, 4),
20707 +               "%s: (%s %s) returned %s with %d",
20708 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20709 +       return ret;
20710 +}
20711 +
20712 +/*
20713 + *      vshelper path is set via /proc/sys
20714 + *      invoked by vserver sys_reboot(), with
20715 + *      the following arguments
20716 + *
20717 + *      argv [0] = vshelper_path;
20718 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20719 + *      argv [2] = context identifier
20720 + *
20721 + *      envp [*] = type-specific parameters
20722 + */
20723 +
20724 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20725 +{
20726 +       char id_buf[8], cmd_buf[16];
20727 +       char uid_buf[16], pid_buf[16];
20728 +       int ret;
20729 +
20730 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20731 +       char *envp[] = {"HOME=/", "TERM=linux",
20732 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20733 +                       uid_buf, pid_buf, cmd_buf, 0};
20734 +
20735 +       if (vx_info_state(vxi, VXS_HELPER))
20736 +               return -EAGAIN;
20737 +       vxi->vx_state |= VXS_HELPER;
20738 +
20739 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20740 +
20741 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20742 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
20743 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20744 +
20745 +       switch (cmd) {
20746 +       case LINUX_REBOOT_CMD_RESTART:
20747 +               argv[1] = "restart";
20748 +               break;
20749 +
20750 +       case LINUX_REBOOT_CMD_HALT:
20751 +               argv[1] = "halt";
20752 +               break;
20753 +
20754 +       case LINUX_REBOOT_CMD_POWER_OFF:
20755 +               argv[1] = "poweroff";
20756 +               break;
20757 +
20758 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20759 +               argv[1] = "swsusp";
20760 +               break;
20761 +
20762 +       case LINUX_REBOOT_CMD_OOM:
20763 +               argv[1] = "oom";
20764 +               break;
20765 +
20766 +       default:
20767 +               vxi->vx_state &= ~VXS_HELPER;
20768 +               return 0;
20769 +       }
20770 +
20771 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20772 +       vxi->vx_state &= ~VXS_HELPER;
20773 +       __wakeup_vx_info(vxi);
20774 +       return (ret) ? -EPERM : 0;
20775 +}
20776 +
20777 +
20778 +long vs_reboot(unsigned int cmd, void __user *arg)
20779 +{
20780 +       struct vx_info *vxi = current_vx_info();
20781 +       long ret = 0;
20782 +
20783 +       vxdprintk(VXD_CBIT(misc, 5),
20784 +               "vs_reboot(%p[#%d],%u)",
20785 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20786 +
20787 +       ret = vs_reboot_helper(vxi, cmd, arg);
20788 +       if (ret)
20789 +               return ret;
20790 +
20791 +       vxi->reboot_cmd = cmd;
20792 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20793 +               switch (cmd) {
20794 +               case LINUX_REBOOT_CMD_RESTART:
20795 +               case LINUX_REBOOT_CMD_HALT:
20796 +               case LINUX_REBOOT_CMD_POWER_OFF:
20797 +                       vx_info_kill(vxi, 0, SIGKILL);
20798 +                       vx_info_kill(vxi, 1, SIGKILL);
20799 +               default:
20800 +                       break;
20801 +               }
20802 +       }
20803 +       return 0;
20804 +}
20805 +
20806 +long vs_oom_action(unsigned int cmd)
20807 +{
20808 +       struct vx_info *vxi = current_vx_info();
20809 +       long ret = 0;
20810 +
20811 +       vxdprintk(VXD_CBIT(misc, 5),
20812 +               "vs_oom_action(%p[#%d],%u)",
20813 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20814 +
20815 +       ret = vs_reboot_helper(vxi, cmd, NULL);
20816 +       if (ret)
20817 +               return ret;
20818 +
20819 +       vxi->reboot_cmd = cmd;
20820 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20821 +               vx_info_kill(vxi, 0, SIGKILL);
20822 +               vx_info_kill(vxi, 1, SIGKILL);
20823 +       }
20824 +       return 0;
20825 +}
20826 +
20827 +/*
20828 + *      argv [0] = vshelper_path;
20829 + *      argv [1] = action: "startup", "shutdown"
20830 + *      argv [2] = context identifier
20831 + *
20832 + *      envp [*] = type-specific parameters
20833 + */
20834 +
20835 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20836 +{
20837 +       char id_buf[8], cmd_buf[16];
20838 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20839 +       char *envp[] = {"HOME=/", "TERM=linux",
20840 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20841 +
20842 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20843 +               return 0;
20844 +
20845 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20846 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20847 +
20848 +       switch (cmd) {
20849 +       case VSC_STARTUP:
20850 +               argv[1] = "startup";
20851 +               break;
20852 +       case VSC_SHUTDOWN:
20853 +               argv[1] = "shutdown";
20854 +               break;
20855 +       default:
20856 +               return 0;
20857 +       }
20858 +
20859 +       return do_vshelper(vshelper_path, argv, envp, 1);
20860 +}
20861 +
20862 +
20863 +/*
20864 + *      argv [0] = vshelper_path;
20865 + *      argv [1] = action: "netup", "netdown"
20866 + *      argv [2] = context identifier
20867 + *
20868 + *      envp [*] = type-specific parameters
20869 + */
20870 +
20871 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20872 +{
20873 +       char id_buf[8], cmd_buf[16];
20874 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20875 +       char *envp[] = {"HOME=/", "TERM=linux",
20876 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20877 +
20878 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20879 +               return 0;
20880 +
20881 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20882 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20883 +
20884 +       switch (cmd) {
20885 +       case VSC_NETUP:
20886 +               argv[1] = "netup";
20887 +               break;
20888 +       case VSC_NETDOWN:
20889 +               argv[1] = "netdown";
20890 +               break;
20891 +       default:
20892 +               return 0;
20893 +       }
20894 +
20895 +       return do_vshelper(vshelper_path, argv, envp, 1);
20896 +}
20897 +
20898 diff -NurpP --minimal linux-3.0.4/kernel/vserver/history.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/history.c
20899 --- linux-3.0.4/kernel/vserver/history.c        1970-01-01 01:00:00.000000000 +0100
20900 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/history.c        2011-06-10 22:11:24.000000000 +0200
20901 @@ -0,0 +1,258 @@
20902 +/*
20903 + *  kernel/vserver/history.c
20904 + *
20905 + *  Virtual Context History Backtrace
20906 + *
20907 + *  Copyright (C) 2004-2007  Herbert Pötzl
20908 + *
20909 + *  V0.01  basic structure
20910 + *  V0.02  hash/unhash and trace
20911 + *  V0.03  preemption fixes
20912 + *
20913 + */
20914 +
20915 +#include <linux/module.h>
20916 +#include <asm/uaccess.h>
20917 +
20918 +#include <linux/vserver/context.h>
20919 +#include <linux/vserver/debug.h>
20920 +#include <linux/vserver/debug_cmd.h>
20921 +#include <linux/vserver/history.h>
20922 +
20923 +
20924 +#ifdef CONFIG_VSERVER_HISTORY
20925 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20926 +#else
20927 +#define VXH_SIZE       64
20928 +#endif
20929 +
20930 +struct _vx_history {
20931 +       unsigned int counter;
20932 +
20933 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20934 +};
20935 +
20936 +
20937 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20938 +
20939 +unsigned volatile int vxh_active = 1;
20940 +
20941 +static atomic_t sequence = ATOMIC_INIT(0);
20942 +
20943 +
20944 +/*     vxh_advance()
20945 +
20946 +       * requires disabled preemption                          */
20947 +
20948 +struct _vx_hist_entry *vxh_advance(void *loc)
20949 +{
20950 +       unsigned int cpu = smp_processor_id();
20951 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20952 +       struct _vx_hist_entry *entry;
20953 +       unsigned int index;
20954 +
20955 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20956 +       entry = &hist->entry[index];
20957 +
20958 +       entry->seq = atomic_inc_return(&sequence);
20959 +       entry->loc = loc;
20960 +       return entry;
20961 +}
20962 +
20963 +EXPORT_SYMBOL_GPL(vxh_advance);
20964 +
20965 +
20966 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20967 +
20968 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20969 +
20970 +
20971 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20972 +
20973 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20974 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20975 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20976 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20977 +
20978 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20979 +{
20980 +       switch (e->type) {
20981 +       case VXH_THROW_OOPS:
20982 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20983 +               break;
20984 +
20985 +       case VXH_GET_VX_INFO:
20986 +       case VXH_PUT_VX_INFO:
20987 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20988 +                       VXH_LOC_ARGS(e),
20989 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20990 +                       VXH_VXI_ARGS(e));
20991 +               break;
20992 +
20993 +       case VXH_INIT_VX_INFO:
20994 +       case VXH_SET_VX_INFO:
20995 +       case VXH_CLR_VX_INFO:
20996 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20997 +                       VXH_LOC_ARGS(e),
20998 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20999 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
21000 +                       VXH_VXI_ARGS(e), e->sc.data);
21001 +               break;
21002 +
21003 +       case VXH_CLAIM_VX_INFO:
21004 +       case VXH_RELEASE_VX_INFO:
21005 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
21006 +                       VXH_LOC_ARGS(e),
21007 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
21008 +                       VXH_VXI_ARGS(e), e->sc.data);
21009 +               break;
21010 +
21011 +       case VXH_ALLOC_VX_INFO:
21012 +       case VXH_DEALLOC_VX_INFO:
21013 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
21014 +                       VXH_LOC_ARGS(e),
21015 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
21016 +                       VXH_VXI_ARGS(e));
21017 +               break;
21018 +
21019 +       case VXH_HASH_VX_INFO:
21020 +       case VXH_UNHASH_VX_INFO:
21021 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
21022 +                       VXH_LOC_ARGS(e),
21023 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
21024 +                       VXH_VXI_ARGS(e));
21025 +               break;
21026 +
21027 +       case VXH_LOC_VX_INFO:
21028 +       case VXH_LOOKUP_VX_INFO:
21029 +       case VXH_CREATE_VX_INFO:
21030 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
21031 +                       VXH_LOC_ARGS(e),
21032 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
21033 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
21034 +                       e->ll.arg, VXH_VXI_ARGS(e));
21035 +               break;
21036 +       }
21037 +}
21038 +
21039 +static void __vxh_dump_history(void)
21040 +{
21041 +       unsigned int i, cpu;
21042 +
21043 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
21044 +               atomic_read(&sequence), NR_CPUS);
21045 +
21046 +       for (i = 0; i < VXH_SIZE; i++) {
21047 +               for_each_online_cpu(cpu) {
21048 +                       struct _vx_history *hist =
21049 +                               &per_cpu(vx_history_buffer, cpu);
21050 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
21051 +                       struct _vx_hist_entry *entry = &hist->entry[index];
21052 +
21053 +                       vxh_dump_entry(entry, cpu);
21054 +               }
21055 +       }
21056 +}
21057 +
21058 +void   vxh_dump_history(void)
21059 +{
21060 +       vxh_active = 0;
21061 +#ifdef CONFIG_SMP
21062 +       local_irq_enable();
21063 +       smp_send_stop();
21064 +       local_irq_disable();
21065 +#endif
21066 +       __vxh_dump_history();
21067 +}
21068 +
21069 +
21070 +/* vserver syscall commands below here */
21071 +
21072 +
21073 +int vc_dump_history(uint32_t id)
21074 +{
21075 +       vxh_active = 0;
21076 +       __vxh_dump_history();
21077 +       vxh_active = 1;
21078 +
21079 +       return 0;
21080 +}
21081 +
21082 +
21083 +int do_read_history(struct __user _vx_hist_entry *data,
21084 +       int cpu, uint32_t *index, uint32_t *count)
21085 +{
21086 +       int pos, ret = 0;
21087 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
21088 +       int end = hist->counter;
21089 +       int start = end - VXH_SIZE + 2;
21090 +       int idx = *index;
21091 +
21092 +       /* special case: get current pos */
21093 +       if (!*count) {
21094 +               *index = end;
21095 +               return 0;
21096 +       }
21097 +
21098 +       /* have we lost some data? */
21099 +       if (idx < start)
21100 +               idx = start;
21101 +
21102 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21103 +               struct _vx_hist_entry *entry =
21104 +                       &hist->entry[idx % VXH_SIZE];
21105 +
21106 +               /* send entry to userspace */
21107 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21108 +               if (ret)
21109 +                       break;
21110 +       }
21111 +       /* save new index and count */
21112 +       *index = idx;
21113 +       *count = pos;
21114 +       return ret ? ret : (*index < end);
21115 +}
21116 +
21117 +int vc_read_history(uint32_t id, void __user *data)
21118 +{
21119 +       struct vcmd_read_history_v0 vc_data;
21120 +       int ret;
21121 +
21122 +       if (id >= NR_CPUS)
21123 +               return -EINVAL;
21124 +
21125 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21126 +               return -EFAULT;
21127 +
21128 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
21129 +               id, &vc_data.index, &vc_data.count);
21130 +
21131 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21132 +               return -EFAULT;
21133 +       return ret;
21134 +}
21135 +
21136 +#ifdef CONFIG_COMPAT
21137 +
21138 +int vc_read_history_x32(uint32_t id, void __user *data)
21139 +{
21140 +       struct vcmd_read_history_v0_x32 vc_data;
21141 +       int ret;
21142 +
21143 +       if (id >= NR_CPUS)
21144 +               return -EINVAL;
21145 +
21146 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21147 +               return -EFAULT;
21148 +
21149 +       ret = do_read_history((struct __user _vx_hist_entry *)
21150 +               compat_ptr(vc_data.data_ptr),
21151 +               id, &vc_data.index, &vc_data.count);
21152 +
21153 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21154 +               return -EFAULT;
21155 +       return ret;
21156 +}
21157 +
21158 +#endif /* CONFIG_COMPAT */
21159 +
21160 diff -NurpP --minimal linux-3.0.4/kernel/vserver/inet.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/inet.c
21161 --- linux-3.0.4/kernel/vserver/inet.c   1970-01-01 01:00:00.000000000 +0100
21162 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/inet.c   2011-08-30 20:14:33.000000000 +0200
21163 @@ -0,0 +1,225 @@
21164 +
21165 +#include <linux/in.h>
21166 +#include <linux/inetdevice.h>
21167 +#include <linux/vs_inet.h>
21168 +#include <linux/vs_inet6.h>
21169 +#include <linux/vserver/debug.h>
21170 +#include <net/route.h>
21171 +#include <net/addrconf.h>
21172 +
21173 +
21174 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
21175 +{
21176 +       int ret = 0;
21177 +
21178 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
21179 +               ret = 1;
21180 +       else {
21181 +               struct nx_addr_v4 *ptr;
21182 +
21183 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
21184 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
21185 +                               ret = 1;
21186 +                               break;
21187 +                       }
21188 +               }
21189 +       }
21190 +
21191 +       vxdprintk(VXD_CBIT(net, 2),
21192 +               "nx_v4_addr_conflict(%p,%p): %d",
21193 +               nxi1, nxi2, ret);
21194 +
21195 +       return ret;
21196 +}
21197 +
21198 +
21199 +#ifdef CONFIG_IPV6
21200 +
21201 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
21202 +{
21203 +       int ret = 0;
21204 +
21205 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
21206 +               ret = 1;
21207 +       else {
21208 +               struct nx_addr_v6 *ptr;
21209 +
21210 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
21211 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
21212 +                               ret = 1;
21213 +                               break;
21214 +                       }
21215 +               }
21216 +       }
21217 +
21218 +       vxdprintk(VXD_CBIT(net, 2),
21219 +               "nx_v6_addr_conflict(%p,%p): %d",
21220 +               nxi1, nxi2, ret);
21221 +
21222 +       return ret;
21223 +}
21224 +
21225 +#endif
21226 +
21227 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21228 +{
21229 +       struct in_device *in_dev;
21230 +       struct in_ifaddr **ifap;
21231 +       struct in_ifaddr *ifa;
21232 +       int ret = 0;
21233 +
21234 +       if (!dev)
21235 +               goto out;
21236 +       in_dev = in_dev_get(dev);
21237 +       if (!in_dev)
21238 +               goto out;
21239 +
21240 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
21241 +               ifap = &ifa->ifa_next) {
21242 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
21243 +                       ret = 1;
21244 +                       break;
21245 +               }
21246 +       }
21247 +       in_dev_put(in_dev);
21248 +out:
21249 +       return ret;
21250 +}
21251 +
21252 +
21253 +#ifdef CONFIG_IPV6
21254 +
21255 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21256 +{
21257 +       struct inet6_dev *in_dev;
21258 +       struct inet6_ifaddr *ifa;
21259 +       int ret = 0;
21260 +
21261 +       if (!dev)
21262 +               goto out;
21263 +       in_dev = in6_dev_get(dev);
21264 +       if (!in_dev)
21265 +               goto out;
21266 +
21267 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
21268 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
21269 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
21270 +                       ret = 1;
21271 +                       break;
21272 +               }
21273 +       }
21274 +       in6_dev_put(in_dev);
21275 +out:
21276 +       return ret;
21277 +}
21278 +
21279 +#endif
21280 +
21281 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21282 +{
21283 +       int ret = 1;
21284 +
21285 +       if (!nxi)
21286 +               goto out;
21287 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
21288 +               goto out;
21289 +#ifdef CONFIG_IPV6
21290 +       ret = 2;
21291 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
21292 +               goto out;
21293 +#endif
21294 +       ret = 0;
21295 +out:
21296 +       vxdprintk(VXD_CBIT(net, 3),
21297 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
21298 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
21299 +       return ret;
21300 +}
21301 +
21302 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
21303 +       struct flowi4 *fl4)
21304 +{
21305 +       struct rtable *rt;
21306 +
21307 +       if (!nxi)
21308 +               return NULL;
21309 +
21310 +       /* FIXME: handle lback only case */
21311 +       if (!NX_IPV4(nxi))
21312 +               return ERR_PTR(-EPERM);
21313 +
21314 +       vxdprintk(VXD_CBIT(net, 4),
21315 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
21316 +               nxi, nxi ? nxi->nx_id : 0,
21317 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
21318 +
21319 +       /* single IP is unconditional */
21320 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
21321 +               (fl4->saddr == INADDR_ANY))
21322 +               fl4->saddr = nxi->v4.ip[0].s_addr;
21323 +
21324 +       if (fl4->saddr == INADDR_ANY) {
21325 +               struct nx_addr_v4 *ptr;
21326 +               __be32 found = 0;
21327 +
21328 +               rt = __ip_route_output_key(net, fl4);
21329 +               if (!IS_ERR(rt)) {
21330 +                       found = fl4->saddr;
21331 +                       ip_rt_put(rt);
21332 +                       vxdprintk(VXD_CBIT(net, 4),
21333 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21334 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
21335 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
21336 +                               goto found;
21337 +               }
21338 +
21339 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
21340 +                       __be32 primary = ptr->ip[0].s_addr;
21341 +                       __be32 mask = ptr->mask.s_addr;
21342 +                       __be32 neta = primary & mask;
21343 +
21344 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
21345 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
21346 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
21347 +                               NIPQUAD(mask), NIPQUAD(neta));
21348 +                       if ((found & mask) != neta)
21349 +                               continue;
21350 +
21351 +                       fl4->saddr = primary;
21352 +                       rt = __ip_route_output_key(net, fl4);
21353 +                       vxdprintk(VXD_CBIT(net, 4),
21354 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21355 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
21356 +                       if (!IS_ERR(rt)) {
21357 +                               found = fl4->saddr;
21358 +                               ip_rt_put(rt);
21359 +                               if (found == primary)
21360 +                                       goto found;
21361 +                       }
21362 +               }
21363 +               /* still no source ip? */
21364 +               found = ipv4_is_loopback(fl4->daddr)
21365 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
21366 +       found:
21367 +               /* assign src ip to flow */
21368 +               fl4->saddr = found;
21369 +
21370 +       } else {
21371 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
21372 +                       return ERR_PTR(-EPERM);
21373 +       }
21374 +
21375 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
21376 +               if (ipv4_is_loopback(fl4->daddr))
21377 +                       fl4->daddr = nxi->v4_lback.s_addr;
21378 +               if (ipv4_is_loopback(fl4->saddr))
21379 +                       fl4->saddr = nxi->v4_lback.s_addr;
21380 +       } else if (ipv4_is_loopback(fl4->daddr) &&
21381 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
21382 +               return ERR_PTR(-EPERM);
21383 +
21384 +       return NULL;
21385 +}
21386 +
21387 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
21388 +
21389 diff -NurpP --minimal linux-3.0.4/kernel/vserver/init.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/init.c
21390 --- linux-3.0.4/kernel/vserver/init.c   1970-01-01 01:00:00.000000000 +0100
21391 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/init.c   2011-06-10 22:11:24.000000000 +0200
21392 @@ -0,0 +1,45 @@
21393 +/*
21394 + *  linux/kernel/init.c
21395 + *
21396 + *  Virtual Server Init
21397 + *
21398 + *  Copyright (C) 2004-2007  Herbert Pötzl
21399 + *
21400 + *  V0.01  basic structure
21401 + *
21402 + */
21403 +
21404 +#include <linux/init.h>
21405 +
21406 +int    vserver_register_sysctl(void);
21407 +void   vserver_unregister_sysctl(void);
21408 +
21409 +
21410 +static int __init init_vserver(void)
21411 +{
21412 +       int ret = 0;
21413 +
21414 +#ifdef CONFIG_VSERVER_DEBUG
21415 +       vserver_register_sysctl();
21416 +#endif
21417 +       return ret;
21418 +}
21419 +
21420 +
21421 +static void __exit exit_vserver(void)
21422 +{
21423 +
21424 +#ifdef CONFIG_VSERVER_DEBUG
21425 +       vserver_unregister_sysctl();
21426 +#endif
21427 +       return;
21428 +}
21429 +
21430 +/* FIXME: GFP_ZONETYPES gone
21431 +long vx_slab[GFP_ZONETYPES]; */
21432 +long vx_area;
21433 +
21434 +
21435 +module_init(init_vserver);
21436 +module_exit(exit_vserver);
21437 +
21438 diff -NurpP --minimal linux-3.0.4/kernel/vserver/inode.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/inode.c
21439 --- linux-3.0.4/kernel/vserver/inode.c  1970-01-01 01:00:00.000000000 +0100
21440 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/inode.c  2011-06-10 22:11:24.000000000 +0200
21441 @@ -0,0 +1,437 @@
21442 +/*
21443 + *  linux/kernel/vserver/inode.c
21444 + *
21445 + *  Virtual Server: File System Support
21446 + *
21447 + *  Copyright (C) 2004-2007  Herbert Pötzl
21448 + *
21449 + *  V0.01  separated from vcontext V0.05
21450 + *  V0.02  moved to tag (instead of xid)
21451 + *
21452 + */
21453 +
21454 +#include <linux/tty.h>
21455 +#include <linux/proc_fs.h>
21456 +#include <linux/devpts_fs.h>
21457 +#include <linux/fs.h>
21458 +#include <linux/file.h>
21459 +#include <linux/mount.h>
21460 +#include <linux/parser.h>
21461 +#include <linux/namei.h>
21462 +#include <linux/vserver/inode.h>
21463 +#include <linux/vserver/inode_cmd.h>
21464 +#include <linux/vs_base.h>
21465 +#include <linux/vs_tag.h>
21466 +
21467 +#include <asm/uaccess.h>
21468 +
21469 +
21470 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21471 +{
21472 +       struct proc_dir_entry *entry;
21473 +
21474 +       if (!in || !in->i_sb)
21475 +               return -ESRCH;
21476 +
21477 +       *flags = IATTR_TAG
21478 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
21479 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
21480 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
21481 +               | (IS_COW(in) ? IATTR_COW : 0);
21482 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
21483 +
21484 +       if (S_ISDIR(in->i_mode))
21485 +               *mask |= IATTR_BARRIER;
21486 +
21487 +       if (IS_TAGGED(in)) {
21488 +               *tag = in->i_tag;
21489 +               *mask |= IATTR_TAG;
21490 +       }
21491 +
21492 +       switch (in->i_sb->s_magic) {
21493 +       case PROC_SUPER_MAGIC:
21494 +               entry = PROC_I(in)->pde;
21495 +
21496 +               /* check for specific inodes? */
21497 +               if (entry)
21498 +                       *mask |= IATTR_FLAGS;
21499 +               if (entry)
21500 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21501 +               else
21502 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21503 +               break;
21504 +
21505 +       case DEVPTS_SUPER_MAGIC:
21506 +               *tag = in->i_tag;
21507 +               *mask |= IATTR_TAG;
21508 +               break;
21509 +
21510 +       default:
21511 +               break;
21512 +       }
21513 +       return 0;
21514 +}
21515 +
21516 +int vc_get_iattr(void __user *data)
21517 +{
21518 +       struct path path;
21519 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21520 +       int ret;
21521 +
21522 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21523 +               return -EFAULT;
21524 +
21525 +       ret = user_lpath(vc_data.name, &path);
21526 +       if (!ret) {
21527 +               ret = __vc_get_iattr(path.dentry->d_inode,
21528 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21529 +               path_put(&path);
21530 +       }
21531 +       if (ret)
21532 +               return ret;
21533 +
21534 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21535 +               ret = -EFAULT;
21536 +       return ret;
21537 +}
21538 +
21539 +#ifdef CONFIG_COMPAT
21540 +
21541 +int vc_get_iattr_x32(void __user *data)
21542 +{
21543 +       struct path path;
21544 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21545 +       int ret;
21546 +
21547 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21548 +               return -EFAULT;
21549 +
21550 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21551 +       if (!ret) {
21552 +               ret = __vc_get_iattr(path.dentry->d_inode,
21553 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21554 +               path_put(&path);
21555 +       }
21556 +       if (ret)
21557 +               return ret;
21558 +
21559 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21560 +               ret = -EFAULT;
21561 +       return ret;
21562 +}
21563 +
21564 +#endif /* CONFIG_COMPAT */
21565 +
21566 +
21567 +int vc_fget_iattr(uint32_t fd, void __user *data)
21568 +{
21569 +       struct file *filp;
21570 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21571 +       int ret;
21572 +
21573 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21574 +               return -EFAULT;
21575 +
21576 +       filp = fget(fd);
21577 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21578 +               return -EBADF;
21579 +
21580 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21581 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21582 +
21583 +       fput(filp);
21584 +
21585 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21586 +               ret = -EFAULT;
21587 +       return ret;
21588 +}
21589 +
21590 +
21591 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21592 +{
21593 +       struct inode *in = de->d_inode;
21594 +       int error = 0, is_proc = 0, has_tag = 0;
21595 +       struct iattr attr = { 0 };
21596 +
21597 +       if (!in || !in->i_sb)
21598 +               return -ESRCH;
21599 +
21600 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21601 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21602 +               return -EINVAL;
21603 +
21604 +       has_tag = IS_TAGGED(in) ||
21605 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21606 +       if ((*mask & IATTR_TAG) && !has_tag)
21607 +               return -EINVAL;
21608 +
21609 +       mutex_lock(&in->i_mutex);
21610 +       if (*mask & IATTR_TAG) {
21611 +               attr.ia_tag = *tag;
21612 +               attr.ia_valid |= ATTR_TAG;
21613 +       }
21614 +
21615 +       if (*mask & IATTR_FLAGS) {
21616 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21617 +               unsigned int iflags = PROC_I(in)->vx_flags;
21618 +
21619 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21620 +                       | (*flags & IATTR_FLAGS);
21621 +               PROC_I(in)->vx_flags = iflags;
21622 +               if (entry)
21623 +                       entry->vx_flags = iflags;
21624 +       }
21625 +
21626 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
21627 +               IATTR_BARRIER | IATTR_COW)) {
21628 +               int iflags = in->i_flags;
21629 +               int vflags = in->i_vflags;
21630 +
21631 +               if (*mask & IATTR_IMMUTABLE) {
21632 +                       if (*flags & IATTR_IMMUTABLE)
21633 +                               iflags |= S_IMMUTABLE;
21634 +                       else
21635 +                               iflags &= ~S_IMMUTABLE;
21636 +               }
21637 +               if (*mask & IATTR_IXUNLINK) {
21638 +                       if (*flags & IATTR_IXUNLINK)
21639 +                               iflags |= S_IXUNLINK;
21640 +                       else
21641 +                               iflags &= ~S_IXUNLINK;
21642 +               }
21643 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21644 +                       if (*flags & IATTR_BARRIER)
21645 +                               vflags |= V_BARRIER;
21646 +                       else
21647 +                               vflags &= ~V_BARRIER;
21648 +               }
21649 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
21650 +                       if (*flags & IATTR_COW)
21651 +                               vflags |= V_COW;
21652 +                       else
21653 +                               vflags &= ~V_COW;
21654 +               }
21655 +               if (in->i_op && in->i_op->sync_flags) {
21656 +                       error = in->i_op->sync_flags(in, iflags, vflags);
21657 +                       if (error)
21658 +                               goto out;
21659 +               }
21660 +       }
21661 +
21662 +       if (attr.ia_valid) {
21663 +               if (in->i_op && in->i_op->setattr)
21664 +                       error = in->i_op->setattr(de, &attr);
21665 +               else {
21666 +                       error = inode_change_ok(in, &attr);
21667 +                       if (!error) {
21668 +                               setattr_copy(in, &attr);
21669 +                               mark_inode_dirty(in);
21670 +                       }
21671 +               }
21672 +       }
21673 +
21674 +out:
21675 +       mutex_unlock(&in->i_mutex);
21676 +       return error;
21677 +}
21678 +
21679 +int vc_set_iattr(void __user *data)
21680 +{
21681 +       struct path path;
21682 +       struct vcmd_ctx_iattr_v1 vc_data;
21683 +       int ret;
21684 +
21685 +       if (!capable(CAP_LINUX_IMMUTABLE))
21686 +               return -EPERM;
21687 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21688 +               return -EFAULT;
21689 +
21690 +       ret = user_lpath(vc_data.name, &path);
21691 +       if (!ret) {
21692 +               ret = __vc_set_iattr(path.dentry,
21693 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21694 +               path_put(&path);
21695 +       }
21696 +
21697 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21698 +               ret = -EFAULT;
21699 +       return ret;
21700 +}
21701 +
21702 +#ifdef CONFIG_COMPAT
21703 +
21704 +int vc_set_iattr_x32(void __user *data)
21705 +{
21706 +       struct path path;
21707 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21708 +       int ret;
21709 +
21710 +       if (!capable(CAP_LINUX_IMMUTABLE))
21711 +               return -EPERM;
21712 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21713 +               return -EFAULT;
21714 +
21715 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21716 +       if (!ret) {
21717 +               ret = __vc_set_iattr(path.dentry,
21718 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21719 +               path_put(&path);
21720 +       }
21721 +
21722 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21723 +               ret = -EFAULT;
21724 +       return ret;
21725 +}
21726 +
21727 +#endif /* CONFIG_COMPAT */
21728 +
21729 +int vc_fset_iattr(uint32_t fd, void __user *data)
21730 +{
21731 +       struct file *filp;
21732 +       struct vcmd_ctx_fiattr_v0 vc_data;
21733 +       int ret;
21734 +
21735 +       if (!capable(CAP_LINUX_IMMUTABLE))
21736 +               return -EPERM;
21737 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21738 +               return -EFAULT;
21739 +
21740 +       filp = fget(fd);
21741 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21742 +               return -EBADF;
21743 +
21744 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21745 +               &vc_data.flags, &vc_data.mask);
21746 +
21747 +       fput(filp);
21748 +
21749 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21750 +               return -EFAULT;
21751 +       return ret;
21752 +}
21753 +
21754 +
21755 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21756 +
21757 +static match_table_t tokens = {
21758 +       {Opt_notagcheck, "notagcheck"},
21759 +#ifdef CONFIG_PROPAGATE
21760 +       {Opt_notag, "notag"},
21761 +       {Opt_tag, "tag"},
21762 +       {Opt_tagid, "tagid=%u"},
21763 +#endif
21764 +       {Opt_err, NULL}
21765 +};
21766 +
21767 +
21768 +static void __dx_parse_remove(char *string, char *opt)
21769 +{
21770 +       char *p = strstr(string, opt);
21771 +       char *q = p;
21772 +
21773 +       if (p) {
21774 +               while (*q != '\0' && *q != ',')
21775 +                       q++;
21776 +               while (*q)
21777 +                       *p++ = *q++;
21778 +               while (*p)
21779 +                       *p++ = '\0';
21780 +       }
21781 +}
21782 +
21783 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21784 +                unsigned long *flags)
21785 +{
21786 +       int set = 0;
21787 +       substring_t args[MAX_OPT_ARGS];
21788 +       int token;
21789 +       char *s, *p, *opts;
21790 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_WARN)
21791 +       int option = 0;
21792 +#endif
21793 +
21794 +       if (!string)
21795 +               return 0;
21796 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21797 +       if (!s)
21798 +               return 0;
21799 +
21800 +       opts = s;
21801 +       while ((p = strsep(&opts, ",")) != NULL) {
21802 +               token = match_token(p, tokens, args);
21803 +
21804 +               switch (token) {
21805 +#ifdef CONFIG_PROPAGATE
21806 +               case Opt_tag:
21807 +                       if (tag)
21808 +                               *tag = 0;
21809 +                       if (remove)
21810 +                               __dx_parse_remove(s, "tag");
21811 +                       *mnt_flags |= MNT_TAGID;
21812 +                       set |= MNT_TAGID;
21813 +                       break;
21814 +               case Opt_notag:
21815 +                       if (remove)
21816 +                               __dx_parse_remove(s, "notag");
21817 +                       *mnt_flags |= MNT_NOTAG;
21818 +                       set |= MNT_NOTAG;
21819 +                       break;
21820 +               case Opt_tagid:
21821 +                       if (tag && !match_int(args, &option))
21822 +                               *tag = option;
21823 +                       if (remove)
21824 +                               __dx_parse_remove(s, "tagid");
21825 +                       *mnt_flags |= MNT_TAGID;
21826 +                       set |= MNT_TAGID;
21827 +                       break;
21828 +#endif
21829 +               case Opt_notagcheck:
21830 +                       if (remove)
21831 +                               __dx_parse_remove(s, "notagcheck");
21832 +                       *flags |= MS_NOTAGCHECK;
21833 +                       set |= MS_NOTAGCHECK;
21834 +                       break;
21835 +               }
21836 +               vxdprintk(VXD_CBIT(tag, 7),
21837 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
21838 +                       p, token, option);
21839 +       }
21840 +       if (set)
21841 +               strcpy(string, s);
21842 +       kfree(s);
21843 +       return set;
21844 +}
21845 +
21846 +#ifdef CONFIG_PROPAGATE
21847 +
21848 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21849 +{
21850 +       tag_t new_tag = 0;
21851 +       struct vfsmount *mnt;
21852 +       int propagate;
21853 +
21854 +       if (!nd)
21855 +               return;
21856 +       mnt = nd->path.mnt;
21857 +       if (!mnt)
21858 +               return;
21859 +
21860 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21861 +       if (propagate)
21862 +               new_tag = mnt->mnt_tag;
21863 +
21864 +       vxdprintk(VXD_CBIT(tag, 7),
21865 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21866 +               inode, inode->i_ino, inode->i_tag,
21867 +               new_tag, (propagate) ? 1 : 0);
21868 +
21869 +       if (propagate)
21870 +               inode->i_tag = new_tag;
21871 +}
21872 +
21873 +#include <linux/module.h>
21874 +
21875 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21876 +
21877 +#endif /* CONFIG_PROPAGATE */
21878 +
21879 diff -NurpP --minimal linux-3.0.4/kernel/vserver/limit.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/limit.c
21880 --- linux-3.0.4/kernel/vserver/limit.c  1970-01-01 01:00:00.000000000 +0100
21881 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/limit.c  2011-06-10 22:11:24.000000000 +0200
21882 @@ -0,0 +1,354 @@
21883 +/*
21884 + *  linux/kernel/vserver/limit.c
21885 + *
21886 + *  Virtual Server: Context Limits
21887 + *
21888 + *  Copyright (C) 2004-2010  Herbert Pötzl
21889 + *
21890 + *  V0.01  broken out from vcontext V0.05
21891 + *  V0.02  changed vcmds to vxi arg
21892 + *  V0.03  added memory cgroup support
21893 + *
21894 + */
21895 +
21896 +#include <linux/sched.h>
21897 +#include <linux/module.h>
21898 +#include <linux/memcontrol.h>
21899 +#include <linux/res_counter.h>
21900 +#include <linux/vs_limit.h>
21901 +#include <linux/vserver/limit.h>
21902 +#include <linux/vserver/limit_cmd.h>
21903 +
21904 +#include <asm/uaccess.h>
21905 +
21906 +
21907 +const char *vlimit_name[NUM_LIMITS] = {
21908 +#ifdef CONFIG_VSERVER_LEGACY_MEM
21909 +       [RLIMIT_RSS]            = "RSS",
21910 +       [RLIMIT_AS]             = "VM",
21911 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
21912 +       [RLIMIT_CPU]            = "CPU",
21913 +       [RLIMIT_NPROC]          = "NPROC",
21914 +       [RLIMIT_NOFILE]         = "NOFILE",
21915 +       [RLIMIT_LOCKS]          = "LOCKS",
21916 +       [RLIMIT_SIGPENDING]     = "SIGP",
21917 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21918 +
21919 +       [VLIMIT_NSOCK]          = "NSOCK",
21920 +       [VLIMIT_OPENFD]         = "OPENFD",
21921 +       [VLIMIT_SHMEM]          = "SHMEM",
21922 +       [VLIMIT_DENTRY]         = "DENTRY",
21923 +};
21924 +
21925 +EXPORT_SYMBOL_GPL(vlimit_name);
21926 +
21927 +#define MASK_ENTRY(x)  (1 << (x))
21928 +
21929 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21930 +               /* minimum */
21931 +       0
21932 +       ,       /* softlimit */
21933 +#ifdef CONFIG_VSERVER_LEGACY_MEM
21934 +       MASK_ENTRY( RLIMIT_RSS          ) |
21935 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
21936 +       0
21937 +       ,       /* maximum */
21938 +#ifdef CONFIG_VSERVER_LEGACY_MEM
21939 +       MASK_ENTRY( RLIMIT_RSS          ) |
21940 +       MASK_ENTRY( RLIMIT_AS           ) |
21941 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
21942 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21943 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21944 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21945 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21946 +
21947 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21948 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21949 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21950 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21951 +       0
21952 +};
21953 +               /* accounting only */
21954 +uint32_t account_mask =
21955 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21956 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21957 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21958 +       0;
21959 +
21960 +
21961 +static int is_valid_vlimit(int id)
21962 +{
21963 +       uint32_t mask = vlimit_mask.minimum |
21964 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21965 +       return mask & (1 << id);
21966 +}
21967 +
21968 +static int is_accounted_vlimit(int id)
21969 +{
21970 +       if (is_valid_vlimit(id))
21971 +               return 1;
21972 +       return account_mask & (1 << id);
21973 +}
21974 +
21975 +
21976 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21977 +{
21978 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21979 +       return VX_VLIM(limit);
21980 +}
21981 +
21982 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21983 +{
21984 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21985 +       return VX_VLIM(limit);
21986 +}
21987 +
21988 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21989 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21990 +{
21991 +       if (!is_valid_vlimit(id))
21992 +               return -EINVAL;
21993 +
21994 +       if (minimum)
21995 +               *minimum = CRLIM_UNSET;
21996 +       if (softlimit)
21997 +               *softlimit = vc_get_soft(vxi, id);
21998 +       if (maximum)
21999 +               *maximum = vc_get_hard(vxi, id);
22000 +       return 0;
22001 +}
22002 +
22003 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
22004 +{
22005 +       struct vcmd_ctx_rlimit_v0 vc_data;
22006 +       int ret;
22007 +
22008 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22009 +               return -EFAULT;
22010 +
22011 +       ret = do_get_rlimit(vxi, vc_data.id,
22012 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
22013 +       if (ret)
22014 +               return ret;
22015 +
22016 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22017 +               return -EFAULT;
22018 +       return 0;
22019 +}
22020 +
22021 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
22022 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
22023 +{
22024 +       if (!is_valid_vlimit(id))
22025 +               return -EINVAL;
22026 +
22027 +       if (maximum != CRLIM_KEEP)
22028 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
22029 +       if (softlimit != CRLIM_KEEP)
22030 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
22031 +
22032 +       /* clamp soft limit */
22033 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
22034 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
22035 +
22036 +       return 0;
22037 +}
22038 +
22039 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
22040 +{
22041 +       struct vcmd_ctx_rlimit_v0 vc_data;
22042 +
22043 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22044 +               return -EFAULT;
22045 +
22046 +       return do_set_rlimit(vxi, vc_data.id,
22047 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
22048 +}
22049 +
22050 +#ifdef CONFIG_IA32_EMULATION
22051 +
22052 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
22053 +{
22054 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
22055 +
22056 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22057 +               return -EFAULT;
22058 +
22059 +       return do_set_rlimit(vxi, vc_data.id,
22060 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
22061 +}
22062 +
22063 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
22064 +{
22065 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
22066 +       int ret;
22067 +
22068 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22069 +               return -EFAULT;
22070 +
22071 +       ret = do_get_rlimit(vxi, vc_data.id,
22072 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
22073 +       if (ret)
22074 +               return ret;
22075 +
22076 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22077 +               return -EFAULT;
22078 +       return 0;
22079 +}
22080 +
22081 +#endif /* CONFIG_IA32_EMULATION */
22082 +
22083 +
22084 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
22085 +{
22086 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
22087 +               return -EFAULT;
22088 +       return 0;
22089 +}
22090 +
22091 +
22092 +static inline void vx_reset_hits(struct _vx_limit *limit)
22093 +{
22094 +       int lim;
22095 +
22096 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22097 +               atomic_set(&__rlim_lhit(limit, lim), 0);
22098 +       }
22099 +}
22100 +
22101 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
22102 +{
22103 +       vx_reset_hits(&vxi->limit);
22104 +       return 0;
22105 +}
22106 +
22107 +static inline void vx_reset_minmax(struct _vx_limit *limit)
22108 +{
22109 +       rlim_t value;
22110 +       int lim;
22111 +
22112 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22113 +               value = __rlim_get(limit, lim);
22114 +               __rlim_rmax(limit, lim) = value;
22115 +               __rlim_rmin(limit, lim) = value;
22116 +       }
22117 +}
22118 +
22119 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
22120 +{
22121 +       vx_reset_minmax(&vxi->limit);
22122 +       return 0;
22123 +}
22124 +
22125 +
22126 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
22127 +{
22128 +       struct vcmd_rlimit_stat_v0 vc_data;
22129 +       struct _vx_limit *limit = &vxi->limit;
22130 +       int id;
22131 +
22132 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22133 +               return -EFAULT;
22134 +
22135 +       id = vc_data.id;
22136 +       if (!is_accounted_vlimit(id))
22137 +               return -EINVAL;
22138 +
22139 +       vx_limit_fixup(limit, id);
22140 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
22141 +       vc_data.value = __rlim_get(limit, id);
22142 +       vc_data.minimum = __rlim_rmin(limit, id);
22143 +       vc_data.maximum = __rlim_rmax(limit, id);
22144 +
22145 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22146 +               return -EFAULT;
22147 +       return 0;
22148 +}
22149 +
22150 +
22151 +void vx_vsi_meminfo(struct sysinfo *val)
22152 +{
22153 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22154 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22155 +       u64 res_limit, res_usage;
22156 +
22157 +       if (!mcg)
22158 +               return;
22159 +
22160 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
22161 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
22162 +
22163 +       if (res_limit != RESOURCE_MAX)
22164 +               val->totalram = (res_limit >> PAGE_SHIFT);
22165 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
22166 +       val->bufferram = 0;
22167 +       val->totalhigh = 0;
22168 +       val->freehigh = 0;
22169 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
22170 +       return;
22171 +}
22172 +
22173 +void vx_vsi_swapinfo(struct sysinfo *val)
22174 +{
22175 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22176 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
22177 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22178 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
22179 +       s64 swap_limit, swap_usage;
22180 +
22181 +       if (!mcg)
22182 +               return;
22183 +
22184 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
22185 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
22186 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
22187 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
22188 +
22189 +       if (res_limit == RESOURCE_MAX)
22190 +               return;
22191 +
22192 +       swap_limit = memsw_limit - res_limit;
22193 +       if (memsw_limit != RESOURCE_MAX)
22194 +               val->totalswap = swap_limit >> PAGE_SHIFT;
22195 +
22196 +       swap_usage = memsw_usage - res_usage;
22197 +       val->freeswap = (swap_usage < swap_limit) ?
22198 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
22199 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22200 +       val->totalswap = 0;
22201 +       val->freeswap = 0;
22202 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22203 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
22204 +       return;
22205 +}
22206 +
22207 +long vx_vsi_cached(struct sysinfo *val)
22208 +{
22209 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22210 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22211 +
22212 +       return mem_cgroup_stat_read_cache(mcg);
22213 +#else
22214 +       return 0;
22215 +#endif
22216 +}
22217 +
22218 +
22219 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
22220 +{
22221 +       struct vx_info *vxi = mm->mm_vx_info;
22222 +       unsigned long points;
22223 +       rlim_t v, w;
22224 +
22225 +       if (!vxi)
22226 +               return 0;
22227 +
22228 +       points = vxi->vx_badness_bias;
22229 +
22230 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22231 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22232 +       points += (v > w) ? (v - w) : 0;
22233 +
22234 +       return points;
22235 +}
22236 +
22237 diff -NurpP --minimal linux-3.0.4/kernel/vserver/limit_init.h linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/limit_init.h
22238 --- linux-3.0.4/kernel/vserver/limit_init.h     1970-01-01 01:00:00.000000000 +0100
22239 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/limit_init.h     2011-06-10 22:11:24.000000000 +0200
22240 @@ -0,0 +1,31 @@
22241 +
22242 +
22243 +static inline void vx_info_init_limit(struct _vx_limit *limit)
22244 +{
22245 +       int lim;
22246 +
22247 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22248 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
22249 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
22250 +               __rlim_set(limit, lim, 0);
22251 +               atomic_set(&__rlim_lhit(limit, lim), 0);
22252 +               __rlim_rmin(limit, lim) = 0;
22253 +               __rlim_rmax(limit, lim) = 0;
22254 +       }
22255 +}
22256 +
22257 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
22258 +{
22259 +       rlim_t value;
22260 +       int lim;
22261 +
22262 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22263 +               if ((1 << lim) & VLIM_NOCHECK)
22264 +                       continue;
22265 +               value = __rlim_get(limit, lim);
22266 +               vxwprintk_xid(value,
22267 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
22268 +                       limit, vlimit_name[lim], lim, (long)value);
22269 +       }
22270 +}
22271 +
22272 diff -NurpP --minimal linux-3.0.4/kernel/vserver/limit_proc.h linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/limit_proc.h
22273 --- linux-3.0.4/kernel/vserver/limit_proc.h     1970-01-01 01:00:00.000000000 +0100
22274 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/limit_proc.h     2011-06-10 22:11:24.000000000 +0200
22275 @@ -0,0 +1,57 @@
22276 +#ifndef _VX_LIMIT_PROC_H
22277 +#define _VX_LIMIT_PROC_H
22278 +
22279 +#include <linux/vserver/limit_int.h>
22280 +
22281 +
22282 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22283 +#define VX_LIMIT_TOP   \
22284 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22285 +
22286 +#define VX_LIMIT_ARG(r)                                \
22287 +       (unsigned long)__rlim_get(limit, r),    \
22288 +       (unsigned long)__rlim_rmin(limit, r),   \
22289 +       (unsigned long)__rlim_rmax(limit, r),   \
22290 +       VX_VLIM(__rlim_soft(limit, r)),         \
22291 +       VX_VLIM(__rlim_hard(limit, r)),         \
22292 +       atomic_read(&__rlim_lhit(limit, r))
22293 +
22294 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22295 +{
22296 +       vx_limit_fixup(limit, -1);
22297 +       return sprintf(buffer, VX_LIMIT_TOP
22298 +               "PROC"  VX_LIMIT_FMT
22299 +               "VM"    VX_LIMIT_FMT
22300 +               "VML"   VX_LIMIT_FMT
22301 +               "RSS"   VX_LIMIT_FMT
22302 +               "ANON"  VX_LIMIT_FMT
22303 +               "RMAP"  VX_LIMIT_FMT
22304 +               "FILES" VX_LIMIT_FMT
22305 +               "OFD"   VX_LIMIT_FMT
22306 +               "LOCKS" VX_LIMIT_FMT
22307 +               "SOCK"  VX_LIMIT_FMT
22308 +               "MSGQ"  VX_LIMIT_FMT
22309 +               "SHM"   VX_LIMIT_FMT
22310 +               "SEMA"  VX_LIMIT_FMT
22311 +               "SEMS"  VX_LIMIT_FMT
22312 +               "DENT"  VX_LIMIT_FMT,
22313 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22314 +               VX_LIMIT_ARG(RLIMIT_AS),
22315 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22316 +               VX_LIMIT_ARG(RLIMIT_RSS),
22317 +               VX_LIMIT_ARG(VLIMIT_ANON),
22318 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22319 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22320 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22321 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22322 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22323 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22324 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22325 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22326 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22327 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22328 +}
22329 +
22330 +#endif /* _VX_LIMIT_PROC_H */
22331 +
22332 +
22333 diff -NurpP --minimal linux-3.0.4/kernel/vserver/network.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/network.c
22334 --- linux-3.0.4/kernel/vserver/network.c        1970-01-01 01:00:00.000000000 +0100
22335 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/network.c        2011-06-10 23:20:56.000000000 +0200
22336 @@ -0,0 +1,912 @@
22337 +/*
22338 + *  linux/kernel/vserver/network.c
22339 + *
22340 + *  Virtual Server: Network Support
22341 + *
22342 + *  Copyright (C) 2003-2007  Herbert Pötzl
22343 + *
22344 + *  V0.01  broken out from vcontext V0.05
22345 + *  V0.02  cleaned up implementation
22346 + *  V0.03  added equiv nx commands
22347 + *  V0.04  switch to RCU based hash
22348 + *  V0.05  and back to locking again
22349 + *  V0.06  changed vcmds to nxi arg
22350 + *  V0.07  have __create claim() the nxi
22351 + *
22352 + */
22353 +
22354 +#include <linux/err.h>
22355 +#include <linux/slab.h>
22356 +#include <linux/rcupdate.h>
22357 +
22358 +#include <linux/vs_network.h>
22359 +#include <linux/vs_pid.h>
22360 +#include <linux/vserver/network_cmd.h>
22361 +
22362 +
22363 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22364 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22365 +
22366 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22367 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22368 +
22369 +
22370 +static int __init init_network(void)
22371 +{
22372 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22373 +               sizeof(struct nx_addr_v4), 0,
22374 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22375 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22376 +               sizeof(struct nx_addr_v6), 0,
22377 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22378 +       return 0;
22379 +}
22380 +
22381 +
22382 +/*     __alloc_nx_addr_v4()                                    */
22383 +
22384 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22385 +{
22386 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22387 +               nx_addr_v4_cachep, GFP_KERNEL);
22388 +
22389 +       if (!IS_ERR(nxa))
22390 +               memset(nxa, 0, sizeof(*nxa));
22391 +       return nxa;
22392 +}
22393 +
22394 +/*     __dealloc_nx_addr_v4()                                  */
22395 +
22396 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22397 +{
22398 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22399 +}
22400 +
22401 +/*     __dealloc_nx_addr_v4_all()                              */
22402 +
22403 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22404 +{
22405 +       while (nxa) {
22406 +               struct nx_addr_v4 *next = nxa->next;
22407 +
22408 +               __dealloc_nx_addr_v4(nxa);
22409 +               nxa = next;
22410 +       }
22411 +}
22412 +
22413 +
22414 +#ifdef CONFIG_IPV6
22415 +
22416 +/*     __alloc_nx_addr_v6()                                    */
22417 +
22418 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22419 +{
22420 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22421 +               nx_addr_v6_cachep, GFP_KERNEL);
22422 +
22423 +       if (!IS_ERR(nxa))
22424 +               memset(nxa, 0, sizeof(*nxa));
22425 +       return nxa;
22426 +}
22427 +
22428 +/*     __dealloc_nx_addr_v6()                                  */
22429 +
22430 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22431 +{
22432 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22433 +}
22434 +
22435 +/*     __dealloc_nx_addr_v6_all()                              */
22436 +
22437 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22438 +{
22439 +       while (nxa) {
22440 +               struct nx_addr_v6 *next = nxa->next;
22441 +
22442 +               __dealloc_nx_addr_v6(nxa);
22443 +               nxa = next;
22444 +       }
22445 +}
22446 +
22447 +#endif /* CONFIG_IPV6 */
22448 +
22449 +/*     __alloc_nx_info()
22450 +
22451 +       * allocate an initialized nx_info struct
22452 +       * doesn't make it visible (hash)                        */
22453 +
22454 +static struct nx_info *__alloc_nx_info(nid_t nid)
22455 +{
22456 +       struct nx_info *new = NULL;
22457 +
22458 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22459 +
22460 +       /* would this benefit from a slab cache? */
22461 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22462 +       if (!new)
22463 +               return 0;
22464 +
22465 +       memset(new, 0, sizeof(struct nx_info));
22466 +       new->nx_id = nid;
22467 +       INIT_HLIST_NODE(&new->nx_hlist);
22468 +       atomic_set(&new->nx_usecnt, 0);
22469 +       atomic_set(&new->nx_tasks, 0);
22470 +       new->nx_state = 0;
22471 +
22472 +       new->nx_flags = NXF_INIT_SET;
22473 +
22474 +       /* rest of init goes here */
22475 +
22476 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22477 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22478 +
22479 +       vxdprintk(VXD_CBIT(nid, 0),
22480 +               "alloc_nx_info(%d) = %p", nid, new);
22481 +       atomic_inc(&nx_global_ctotal);
22482 +       return new;
22483 +}
22484 +
22485 +/*     __dealloc_nx_info()
22486 +
22487 +       * final disposal of nx_info                             */
22488 +
22489 +static void __dealloc_nx_info(struct nx_info *nxi)
22490 +{
22491 +       vxdprintk(VXD_CBIT(nid, 0),
22492 +               "dealloc_nx_info(%p)", nxi);
22493 +
22494 +       nxi->nx_hlist.next = LIST_POISON1;
22495 +       nxi->nx_id = -1;
22496 +
22497 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22498 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22499 +
22500 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22501 +
22502 +       nxi->nx_state |= NXS_RELEASED;
22503 +       kfree(nxi);
22504 +       atomic_dec(&nx_global_ctotal);
22505 +}
22506 +
22507 +static void __shutdown_nx_info(struct nx_info *nxi)
22508 +{
22509 +       nxi->nx_state |= NXS_SHUTDOWN;
22510 +       vs_net_change(nxi, VSC_NETDOWN);
22511 +}
22512 +
22513 +/*     exported stuff                                          */
22514 +
22515 +void free_nx_info(struct nx_info *nxi)
22516 +{
22517 +       /* context shutdown is mandatory */
22518 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22519 +
22520 +       /* context must not be hashed */
22521 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22522 +
22523 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22524 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22525 +
22526 +       __dealloc_nx_info(nxi);
22527 +}
22528 +
22529 +
22530 +void __nx_set_lback(struct nx_info *nxi)
22531 +{
22532 +       int nid = nxi->nx_id;
22533 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22534 +
22535 +       nxi->v4_lback.s_addr = lback;
22536 +}
22537 +
22538 +extern int __nx_inet_add_lback(__be32 addr);
22539 +extern int __nx_inet_del_lback(__be32 addr);
22540 +
22541 +
22542 +/*     hash table for nx_info hash */
22543 +
22544 +#define NX_HASH_SIZE   13
22545 +
22546 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22547 +
22548 +static DEFINE_SPINLOCK(nx_info_hash_lock);
22549 +
22550 +
22551 +static inline unsigned int __hashval(nid_t nid)
22552 +{
22553 +       return (nid % NX_HASH_SIZE);
22554 +}
22555 +
22556 +
22557 +
22558 +/*     __hash_nx_info()
22559 +
22560 +       * add the nxi to the global hash table
22561 +       * requires the hash_lock to be held                     */
22562 +
22563 +static inline void __hash_nx_info(struct nx_info *nxi)
22564 +{
22565 +       struct hlist_head *head;
22566 +
22567 +       vxd_assert_lock(&nx_info_hash_lock);
22568 +       vxdprintk(VXD_CBIT(nid, 4),
22569 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22570 +
22571 +       /* context must not be hashed */
22572 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22573 +
22574 +       nxi->nx_state |= NXS_HASHED;
22575 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22576 +       hlist_add_head(&nxi->nx_hlist, head);
22577 +       atomic_inc(&nx_global_cactive);
22578 +}
22579 +
22580 +/*     __unhash_nx_info()
22581 +
22582 +       * remove the nxi from the global hash table
22583 +       * requires the hash_lock to be held                     */
22584 +
22585 +static inline void __unhash_nx_info(struct nx_info *nxi)
22586 +{
22587 +       vxd_assert_lock(&nx_info_hash_lock);
22588 +       vxdprintk(VXD_CBIT(nid, 4),
22589 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22590 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22591 +
22592 +       /* context must be hashed */
22593 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22594 +       /* but without tasks */
22595 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22596 +
22597 +       nxi->nx_state &= ~NXS_HASHED;
22598 +       hlist_del(&nxi->nx_hlist);
22599 +       atomic_dec(&nx_global_cactive);
22600 +}
22601 +
22602 +
22603 +/*     __lookup_nx_info()
22604 +
22605 +       * requires the hash_lock to be held
22606 +       * doesn't increment the nx_refcnt                       */
22607 +
22608 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22609 +{
22610 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22611 +       struct hlist_node *pos;
22612 +       struct nx_info *nxi;
22613 +
22614 +       vxd_assert_lock(&nx_info_hash_lock);
22615 +       hlist_for_each(pos, head) {
22616 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22617 +
22618 +               if (nxi->nx_id == nid)
22619 +                       goto found;
22620 +       }
22621 +       nxi = NULL;
22622 +found:
22623 +       vxdprintk(VXD_CBIT(nid, 0),
22624 +               "__lookup_nx_info(#%u): %p[#%u]",
22625 +               nid, nxi, nxi ? nxi->nx_id : 0);
22626 +       return nxi;
22627 +}
22628 +
22629 +
22630 +/*     __create_nx_info()
22631 +
22632 +       * create the requested context
22633 +       * get(), claim() and hash it                            */
22634 +
22635 +static struct nx_info *__create_nx_info(int id)
22636 +{
22637 +       struct nx_info *new, *nxi = NULL;
22638 +
22639 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22640 +
22641 +       if (!(new = __alloc_nx_info(id)))
22642 +               return ERR_PTR(-ENOMEM);
22643 +
22644 +       /* required to make dynamic xids unique */
22645 +       spin_lock(&nx_info_hash_lock);
22646 +
22647 +       /* static context requested */
22648 +       if ((nxi = __lookup_nx_info(id))) {
22649 +               vxdprintk(VXD_CBIT(nid, 0),
22650 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22651 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22652 +                       nxi = ERR_PTR(-EBUSY);
22653 +               else
22654 +                       nxi = ERR_PTR(-EEXIST);
22655 +               goto out_unlock;
22656 +       }
22657 +       /* new context */
22658 +       vxdprintk(VXD_CBIT(nid, 0),
22659 +               "create_nx_info(%d) = %p (new)", id, new);
22660 +       claim_nx_info(new, NULL);
22661 +       __nx_set_lback(new);
22662 +       __hash_nx_info(get_nx_info(new));
22663 +       nxi = new, new = NULL;
22664 +
22665 +out_unlock:
22666 +       spin_unlock(&nx_info_hash_lock);
22667 +       if (new)
22668 +               __dealloc_nx_info(new);
22669 +       return nxi;
22670 +}
22671 +
22672 +
22673 +
22674 +/*     exported stuff                                          */
22675 +
22676 +
22677 +void unhash_nx_info(struct nx_info *nxi)
22678 +{
22679 +       __shutdown_nx_info(nxi);
22680 +       spin_lock(&nx_info_hash_lock);
22681 +       __unhash_nx_info(nxi);
22682 +       spin_unlock(&nx_info_hash_lock);
22683 +}
22684 +
22685 +/*     lookup_nx_info()
22686 +
22687 +       * search for a nx_info and get() it
22688 +       * negative id means current                             */
22689 +
22690 +struct nx_info *lookup_nx_info(int id)
22691 +{
22692 +       struct nx_info *nxi = NULL;
22693 +
22694 +       if (id < 0) {
22695 +               nxi = get_nx_info(current_nx_info());
22696 +       } else if (id > 1) {
22697 +               spin_lock(&nx_info_hash_lock);
22698 +               nxi = get_nx_info(__lookup_nx_info(id));
22699 +               spin_unlock(&nx_info_hash_lock);
22700 +       }
22701 +       return nxi;
22702 +}
22703 +
22704 +/*     nid_is_hashed()
22705 +
22706 +       * verify that nid is still hashed                       */
22707 +
22708 +int nid_is_hashed(nid_t nid)
22709 +{
22710 +       int hashed;
22711 +
22712 +       spin_lock(&nx_info_hash_lock);
22713 +       hashed = (__lookup_nx_info(nid) != NULL);
22714 +       spin_unlock(&nx_info_hash_lock);
22715 +       return hashed;
22716 +}
22717 +
22718 +
22719 +#ifdef CONFIG_PROC_FS
22720 +
22721 +/*     get_nid_list()
22722 +
22723 +       * get a subset of hashed nids for proc
22724 +       * assumes size is at least one                          */
22725 +
22726 +int get_nid_list(int index, unsigned int *nids, int size)
22727 +{
22728 +       int hindex, nr_nids = 0;
22729 +
22730 +       /* only show current and children */
22731 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22732 +               if (index > 0)
22733 +                       return 0;
22734 +               nids[nr_nids] = nx_current_nid();
22735 +               return 1;
22736 +       }
22737 +
22738 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22739 +               struct hlist_head *head = &nx_info_hash[hindex];
22740 +               struct hlist_node *pos;
22741 +
22742 +               spin_lock(&nx_info_hash_lock);
22743 +               hlist_for_each(pos, head) {
22744 +                       struct nx_info *nxi;
22745 +
22746 +                       if (--index > 0)
22747 +                               continue;
22748 +
22749 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22750 +                       nids[nr_nids] = nxi->nx_id;
22751 +                       if (++nr_nids >= size) {
22752 +                               spin_unlock(&nx_info_hash_lock);
22753 +                               goto out;
22754 +                       }
22755 +               }
22756 +               /* keep the lock time short */
22757 +               spin_unlock(&nx_info_hash_lock);
22758 +       }
22759 +out:
22760 +       return nr_nids;
22761 +}
22762 +#endif
22763 +
22764 +
22765 +/*
22766 + *     migrate task to new network
22767 + *     gets nxi, puts old_nxi on change
22768 + */
22769 +
22770 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22771 +{
22772 +       struct nx_info *old_nxi;
22773 +       int ret = 0;
22774 +
22775 +       if (!p || !nxi)
22776 +               BUG();
22777 +
22778 +       vxdprintk(VXD_CBIT(nid, 5),
22779 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22780 +               p, nxi, nxi->nx_id,
22781 +               atomic_read(&nxi->nx_usecnt),
22782 +               atomic_read(&nxi->nx_tasks));
22783 +
22784 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22785 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22786 +               return -EACCES;
22787 +
22788 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22789 +               return -EFAULT;
22790 +
22791 +       /* maybe disallow this completely? */
22792 +       old_nxi = task_get_nx_info(p);
22793 +       if (old_nxi == nxi)
22794 +               goto out;
22795 +
22796 +       task_lock(p);
22797 +       if (old_nxi)
22798 +               clr_nx_info(&p->nx_info);
22799 +       claim_nx_info(nxi, p);
22800 +       set_nx_info(&p->nx_info, nxi);
22801 +       p->nid = nxi->nx_id;
22802 +       task_unlock(p);
22803 +
22804 +       vxdprintk(VXD_CBIT(nid, 5),
22805 +               "moved task %p into nxi:%p[#%d]",
22806 +               p, nxi, nxi->nx_id);
22807 +
22808 +       if (old_nxi)
22809 +               release_nx_info(old_nxi, p);
22810 +       ret = 0;
22811 +out:
22812 +       put_nx_info(old_nxi);
22813 +       return ret;
22814 +}
22815 +
22816 +
22817 +void nx_set_persistent(struct nx_info *nxi)
22818 +{
22819 +       vxdprintk(VXD_CBIT(nid, 6),
22820 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22821 +
22822 +       get_nx_info(nxi);
22823 +       claim_nx_info(nxi, NULL);
22824 +}
22825 +
22826 +void nx_clear_persistent(struct nx_info *nxi)
22827 +{
22828 +       vxdprintk(VXD_CBIT(nid, 6),
22829 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22830 +
22831 +       release_nx_info(nxi, NULL);
22832 +       put_nx_info(nxi);
22833 +}
22834 +
22835 +void nx_update_persistent(struct nx_info *nxi)
22836 +{
22837 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22838 +               nx_set_persistent(nxi);
22839 +       else
22840 +               nx_clear_persistent(nxi);
22841 +}
22842 +
22843 +/* vserver syscall commands below here */
22844 +
22845 +/* taks nid and nx_info functions */
22846 +
22847 +#include <asm/uaccess.h>
22848 +
22849 +
22850 +int vc_task_nid(uint32_t id)
22851 +{
22852 +       nid_t nid;
22853 +
22854 +       if (id) {
22855 +               struct task_struct *tsk;
22856 +
22857 +               rcu_read_lock();
22858 +               tsk = find_task_by_real_pid(id);
22859 +               nid = (tsk) ? tsk->nid : -ESRCH;
22860 +               rcu_read_unlock();
22861 +       } else
22862 +               nid = nx_current_nid();
22863 +       return nid;
22864 +}
22865 +
22866 +
22867 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22868 +{
22869 +       struct vcmd_nx_info_v0 vc_data;
22870 +
22871 +       vc_data.nid = nxi->nx_id;
22872 +
22873 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22874 +               return -EFAULT;
22875 +       return 0;
22876 +}
22877 +
22878 +
22879 +/* network functions */
22880 +
22881 +int vc_net_create(uint32_t nid, void __user *data)
22882 +{
22883 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22884 +       struct nx_info *new_nxi;
22885 +       int ret;
22886 +
22887 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22888 +               return -EFAULT;
22889 +
22890 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22891 +               return -EINVAL;
22892 +
22893 +       new_nxi = __create_nx_info(nid);
22894 +       if (IS_ERR(new_nxi))
22895 +               return PTR_ERR(new_nxi);
22896 +
22897 +       /* initial flags */
22898 +       new_nxi->nx_flags = vc_data.flagword;
22899 +
22900 +       ret = -ENOEXEC;
22901 +       if (vs_net_change(new_nxi, VSC_NETUP))
22902 +               goto out;
22903 +
22904 +       ret = nx_migrate_task(current, new_nxi);
22905 +       if (ret)
22906 +               goto out;
22907 +
22908 +       /* return context id on success */
22909 +       ret = new_nxi->nx_id;
22910 +
22911 +       /* get a reference for persistent contexts */
22912 +       if ((vc_data.flagword & NXF_PERSISTENT))
22913 +               nx_set_persistent(new_nxi);
22914 +out:
22915 +       release_nx_info(new_nxi, NULL);
22916 +       put_nx_info(new_nxi);
22917 +       return ret;
22918 +}
22919 +
22920 +
22921 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22922 +{
22923 +       return nx_migrate_task(current, nxi);
22924 +}
22925 +
22926 +
22927 +
22928 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22929 +       uint16_t type, uint16_t flags)
22930 +{
22931 +       struct nx_addr_v4 *nxa = &nxi->v4;
22932 +
22933 +       if (NX_IPV4(nxi)) {
22934 +               /* locate last entry */
22935 +               for (; nxa->next; nxa = nxa->next);
22936 +               nxa->next = __alloc_nx_addr_v4();
22937 +               nxa = nxa->next;
22938 +
22939 +               if (IS_ERR(nxa))
22940 +                       return PTR_ERR(nxa);
22941 +       }
22942 +
22943 +       if (nxi->v4.next)
22944 +               /* remove single ip for ip list */
22945 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22946 +
22947 +       nxa->ip[0].s_addr = ip;
22948 +       nxa->ip[1].s_addr = ip2;
22949 +       nxa->mask.s_addr = mask;
22950 +       nxa->type = type;
22951 +       nxa->flags = flags;
22952 +       return 0;
22953 +}
22954 +
22955 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22956 +       uint16_t type, uint16_t flags)
22957 +{
22958 +       struct nx_addr_v4 *nxa = &nxi->v4;
22959 +
22960 +       switch (type) {
22961 +/*     case NXA_TYPE_ADDR:
22962 +               break;          */
22963 +
22964 +       case NXA_TYPE_ANY:
22965 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
22966 +               memset(nxa, 0, sizeof(*nxa));
22967 +               break;
22968 +
22969 +       default:
22970 +               return -EINVAL;
22971 +       }
22972 +       return 0;
22973 +}
22974 +
22975 +
22976 +int vc_net_add(struct nx_info *nxi, void __user *data)
22977 +{
22978 +       struct vcmd_net_addr_v0 vc_data;
22979 +       int index, ret = 0;
22980 +
22981 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22982 +               return -EFAULT;
22983 +
22984 +       switch (vc_data.type) {
22985 +       case NXA_TYPE_IPV4:
22986 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22987 +                       return -EINVAL;
22988 +
22989 +               index = 0;
22990 +               while (index < vc_data.count) {
22991 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22992 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22993 +                       if (ret)
22994 +                               return ret;
22995 +                       index++;
22996 +               }
22997 +               ret = index;
22998 +               break;
22999 +
23000 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
23001 +               nxi->v4_bcast = vc_data.ip[0];
23002 +               ret = 1;
23003 +               break;
23004 +
23005 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
23006 +               nxi->v4_lback = vc_data.ip[0];
23007 +               ret = 1;
23008 +               break;
23009 +
23010 +       default:
23011 +               ret = -EINVAL;
23012 +               break;
23013 +       }
23014 +       return ret;
23015 +}
23016 +
23017 +int vc_net_remove(struct nx_info *nxi, void __user *data)
23018 +{
23019 +       struct vcmd_net_addr_v0 vc_data;
23020 +
23021 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23022 +               return -EFAULT;
23023 +
23024 +       switch (vc_data.type) {
23025 +       case NXA_TYPE_ANY:
23026 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
23027 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
23028 +               break;
23029 +
23030 +       default:
23031 +               return -EINVAL;
23032 +       }
23033 +       return 0;
23034 +}
23035 +
23036 +
23037 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
23038 +{
23039 +       struct vcmd_net_addr_ipv4_v1 vc_data;
23040 +
23041 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23042 +               return -EFAULT;
23043 +
23044 +       switch (vc_data.type) {
23045 +       case NXA_TYPE_ADDR:
23046 +       case NXA_TYPE_MASK:
23047 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
23048 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
23049 +
23050 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
23051 +               nxi->v4_bcast = vc_data.ip;
23052 +               break;
23053 +
23054 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
23055 +               nxi->v4_lback = vc_data.ip;
23056 +               break;
23057 +
23058 +       default:
23059 +               return -EINVAL;
23060 +       }
23061 +       return 0;
23062 +}
23063 +
23064 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
23065 +{
23066 +       struct vcmd_net_addr_ipv4_v2 vc_data;
23067 +
23068 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23069 +               return -EFAULT;
23070 +
23071 +       switch (vc_data.type) {
23072 +       case NXA_TYPE_ADDR:
23073 +       case NXA_TYPE_MASK:
23074 +       case NXA_TYPE_RANGE:
23075 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
23076 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
23077 +
23078 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
23079 +               nxi->v4_bcast = vc_data.ip;
23080 +               break;
23081 +
23082 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
23083 +               nxi->v4_lback = vc_data.ip;
23084 +               break;
23085 +
23086 +       default:
23087 +               return -EINVAL;
23088 +       }
23089 +       return 0;
23090 +}
23091 +
23092 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
23093 +{
23094 +       struct vcmd_net_addr_ipv4_v1 vc_data;
23095 +
23096 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23097 +               return -EFAULT;
23098 +
23099 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
23100 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
23101 +}
23102 +
23103 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
23104 +{
23105 +       struct vcmd_net_addr_ipv4_v2 vc_data;
23106 +
23107 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23108 +               return -EFAULT;
23109 +
23110 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
23111 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
23112 +}
23113 +
23114 +#ifdef CONFIG_IPV6
23115 +
23116 +int do_add_v6_addr(struct nx_info *nxi,
23117 +       struct in6_addr *ip, struct in6_addr *mask,
23118 +       uint32_t prefix, uint16_t type, uint16_t flags)
23119 +{
23120 +       struct nx_addr_v6 *nxa = &nxi->v6;
23121 +
23122 +       if (NX_IPV6(nxi)) {
23123 +               /* locate last entry */
23124 +               for (; nxa->next; nxa = nxa->next);
23125 +               nxa->next = __alloc_nx_addr_v6();
23126 +               nxa = nxa->next;
23127 +
23128 +               if (IS_ERR(nxa))
23129 +                       return PTR_ERR(nxa);
23130 +       }
23131 +
23132 +       nxa->ip = *ip;
23133 +       nxa->mask = *mask;
23134 +       nxa->prefix = prefix;
23135 +       nxa->type = type;
23136 +       nxa->flags = flags;
23137 +       return 0;
23138 +}
23139 +
23140 +
23141 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
23142 +{
23143 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23144 +
23145 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23146 +               return -EFAULT;
23147 +
23148 +       switch (vc_data.type) {
23149 +       case NXA_TYPE_ADDR:
23150 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
23151 +               /* fallthrough */
23152 +       case NXA_TYPE_MASK:
23153 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
23154 +                       vc_data.prefix, vc_data.type, vc_data.flags);
23155 +       default:
23156 +               return -EINVAL;
23157 +       }
23158 +       return 0;
23159 +}
23160 +
23161 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
23162 +{
23163 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23164 +
23165 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23166 +               return -EFAULT;
23167 +
23168 +       switch (vc_data.type) {
23169 +       case NXA_TYPE_ANY:
23170 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
23171 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
23172 +               break;
23173 +
23174 +       default:
23175 +               return -EINVAL;
23176 +       }
23177 +       return 0;
23178 +}
23179 +
23180 +#endif /* CONFIG_IPV6 */
23181 +
23182 +
23183 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23184 +{
23185 +       struct vcmd_net_flags_v0 vc_data;
23186 +
23187 +       vc_data.flagword = nxi->nx_flags;
23188 +
23189 +       /* special STATE flag handling */
23190 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23191 +
23192 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23193 +               return -EFAULT;
23194 +       return 0;
23195 +}
23196 +
23197 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23198 +{
23199 +       struct vcmd_net_flags_v0 vc_data;
23200 +       uint64_t mask, trigger;
23201 +
23202 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23203 +               return -EFAULT;
23204 +
23205 +       /* special STATE flag handling */
23206 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23207 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23208 +
23209 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23210 +               vc_data.flagword, mask);
23211 +       if (trigger & NXF_PERSISTENT)
23212 +               nx_update_persistent(nxi);
23213 +
23214 +       return 0;
23215 +}
23216 +
23217 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23218 +{
23219 +       struct vcmd_net_caps_v0 vc_data;
23220 +
23221 +       vc_data.ncaps = nxi->nx_ncaps;
23222 +       vc_data.cmask = ~0ULL;
23223 +
23224 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23225 +               return -EFAULT;
23226 +       return 0;
23227 +}
23228 +
23229 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23230 +{
23231 +       struct vcmd_net_caps_v0 vc_data;
23232 +
23233 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23234 +               return -EFAULT;
23235 +
23236 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23237 +               vc_data.ncaps, vc_data.cmask);
23238 +       return 0;
23239 +}
23240 +
23241 +
23242 +#include <linux/module.h>
23243 +
23244 +module_init(init_network);
23245 +
23246 +EXPORT_SYMBOL_GPL(free_nx_info);
23247 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23248 +
23249 diff -NurpP --minimal linux-3.0.4/kernel/vserver/proc.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/proc.c
23250 --- linux-3.0.4/kernel/vserver/proc.c   1970-01-01 01:00:00.000000000 +0100
23251 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/proc.c   2011-08-01 19:57:21.000000000 +0200
23252 @@ -0,0 +1,1103 @@
23253 +/*
23254 + *  linux/kernel/vserver/proc.c
23255 + *
23256 + *  Virtual Context Support
23257 + *
23258 + *  Copyright (C) 2003-2011  Herbert Pötzl
23259 + *
23260 + *  V0.01  basic structure
23261 + *  V0.02  adaptation vs1.3.0
23262 + *  V0.03  proc permissions
23263 + *  V0.04  locking/generic
23264 + *  V0.05  next generation procfs
23265 + *  V0.06  inode validation
23266 + *  V0.07  generic rewrite vid
23267 + *  V0.08  remove inode type
23268 + *  V0.09  added u/wmask info
23269 + *
23270 + */
23271 +
23272 +#include <linux/proc_fs.h>
23273 +#include <linux/fs_struct.h>
23274 +#include <linux/mount.h>
23275 +#include <asm/unistd.h>
23276 +
23277 +#include <linux/vs_context.h>
23278 +#include <linux/vs_network.h>
23279 +#include <linux/vs_cvirt.h>
23280 +
23281 +#include <linux/in.h>
23282 +#include <linux/inetdevice.h>
23283 +#include <linux/vs_inet.h>
23284 +#include <linux/vs_inet6.h>
23285 +
23286 +#include <linux/vserver/global.h>
23287 +
23288 +#include "cvirt_proc.h"
23289 +#include "cacct_proc.h"
23290 +#include "limit_proc.h"
23291 +#include "sched_proc.h"
23292 +#include "vci_config.h"
23293 +
23294 +
23295 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
23296 +{
23297 +       unsigned __capi;
23298 +
23299 +       CAP_FOR_EACH_U32(__capi) {
23300 +               buffer += sprintf(buffer, "%08x",
23301 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
23302 +       }
23303 +       return buffer;
23304 +}
23305 +
23306 +
23307 +static struct proc_dir_entry *proc_virtual;
23308 +
23309 +static struct proc_dir_entry *proc_virtnet;
23310 +
23311 +
23312 +/* first the actual feeds */
23313 +
23314 +
23315 +static int proc_vci(char *buffer)
23316 +{
23317 +       return sprintf(buffer,
23318 +               "VCIVersion:\t%04x:%04x\n"
23319 +               "VCISyscall:\t%d\n"
23320 +               "VCIKernel:\t%08x\n",
23321 +               VCI_VERSION >> 16,
23322 +               VCI_VERSION & 0xFFFF,
23323 +               __NR_vserver,
23324 +               vci_kernel_config());
23325 +}
23326 +
23327 +static int proc_virtual_info(char *buffer)
23328 +{
23329 +       return proc_vci(buffer);
23330 +}
23331 +
23332 +static int proc_virtual_status(char *buffer)
23333 +{
23334 +       return sprintf(buffer,
23335 +               "#CTotal:\t%d\n"
23336 +               "#CActive:\t%d\n"
23337 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
23338 +               "#InitTask:\t%d\t%d %d\n",
23339 +               atomic_read(&vx_global_ctotal),
23340 +               atomic_read(&vx_global_cactive),
23341 +               atomic_read(&vs_global_nsproxy),
23342 +               atomic_read(&vs_global_fs),
23343 +               atomic_read(&vs_global_mnt_ns),
23344 +               atomic_read(&vs_global_uts_ns),
23345 +               atomic_read(&nr_ipc_ns),
23346 +               atomic_read(&vs_global_user_ns),
23347 +               atomic_read(&vs_global_pid_ns),
23348 +               atomic_read(&init_task.usage),
23349 +               atomic_read(&init_task.nsproxy->count),
23350 +               init_task.fs->users);
23351 +}
23352 +
23353 +
23354 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23355 +{
23356 +       int length;
23357 +
23358 +       length = sprintf(buffer,
23359 +               "ID:\t%d\n"
23360 +               "Info:\t%p\n"
23361 +               "Init:\t%d\n"
23362 +               "OOM:\t%lld\n",
23363 +               vxi->vx_id,
23364 +               vxi,
23365 +               vxi->vx_initpid,
23366 +               vxi->vx_badness_bias);
23367 +       return length;
23368 +}
23369 +
23370 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23371 +{
23372 +       char *orig = buffer;
23373 +
23374 +       buffer += sprintf(buffer,
23375 +               "UseCnt:\t%d\n"
23376 +               "Tasks:\t%d\n"
23377 +               "Flags:\t%016llx\n",
23378 +               atomic_read(&vxi->vx_usecnt),
23379 +               atomic_read(&vxi->vx_tasks),
23380 +               (unsigned long long)vxi->vx_flags);
23381 +
23382 +       buffer += sprintf(buffer, "BCaps:\t");
23383 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23384 +       buffer += sprintf(buffer, "\n");
23385 +
23386 +       buffer += sprintf(buffer,
23387 +               "CCaps:\t%016llx\n"
23388 +               "Umask:\t%16llx\n"
23389 +               "Wmask:\t%16llx\n"
23390 +               "Spaces:\t%08lx %08lx\n",
23391 +               (unsigned long long)vxi->vx_ccaps,
23392 +               (unsigned long long)vxi->vx_umask,
23393 +               (unsigned long long)vxi->vx_wmask,
23394 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
23395 +       return buffer - orig;
23396 +}
23397 +
23398 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23399 +{
23400 +       return vx_info_proc_limit(&vxi->limit, buffer);
23401 +}
23402 +
23403 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23404 +{
23405 +       int cpu, length;
23406 +
23407 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23408 +       for_each_online_cpu(cpu) {
23409 +               length += vx_info_proc_sched_pc(
23410 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23411 +                       buffer + length, cpu);
23412 +       }
23413 +       return length;
23414 +}
23415 +
23416 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23417 +{
23418 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
23419 +}
23420 +
23421 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23422 +{
23423 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
23424 +}
23425 +
23426 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23427 +{
23428 +       int cpu, length;
23429 +
23430 +       vx_update_load(vxi);
23431 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23432 +       for_each_online_cpu(cpu) {
23433 +               length += vx_info_proc_cvirt_pc(
23434 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23435 +                       buffer + length, cpu);
23436 +       }
23437 +       return length;
23438 +}
23439 +
23440 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23441 +{
23442 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23443 +}
23444 +
23445 +
23446 +static int proc_virtnet_info(char *buffer)
23447 +{
23448 +       return proc_vci(buffer);
23449 +}
23450 +
23451 +static int proc_virtnet_status(char *buffer)
23452 +{
23453 +       return sprintf(buffer,
23454 +               "#CTotal:\t%d\n"
23455 +               "#CActive:\t%d\n",
23456 +               atomic_read(&nx_global_ctotal),
23457 +               atomic_read(&nx_global_cactive));
23458 +}
23459 +
23460 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23461 +{
23462 +       struct nx_addr_v4 *v4a;
23463 +#ifdef CONFIG_IPV6
23464 +       struct nx_addr_v6 *v6a;
23465 +#endif
23466 +       int length, i;
23467 +
23468 +       length = sprintf(buffer,
23469 +               "ID:\t%d\n"
23470 +               "Info:\t%p\n"
23471 +               "Bcast:\t" NIPQUAD_FMT "\n"
23472 +               "Lback:\t" NIPQUAD_FMT "\n",
23473 +               nxi->nx_id,
23474 +               nxi,
23475 +               NIPQUAD(nxi->v4_bcast.s_addr),
23476 +               NIPQUAD(nxi->v4_lback.s_addr));
23477 +
23478 +       if (!NX_IPV4(nxi))
23479 +               goto skip_v4;
23480 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23481 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23482 +                       i, NXAV4(v4a));
23483 +skip_v4:
23484 +#ifdef CONFIG_IPV6
23485 +       if (!NX_IPV6(nxi))
23486 +               goto skip_v6;
23487 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23488 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23489 +                       i, NXAV6(v6a));
23490 +skip_v6:
23491 +#endif
23492 +       return length;
23493 +}
23494 +
23495 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23496 +{
23497 +       int length;
23498 +
23499 +       length = sprintf(buffer,
23500 +               "UseCnt:\t%d\n"
23501 +               "Tasks:\t%d\n"
23502 +               "Flags:\t%016llx\n"
23503 +               "NCaps:\t%016llx\n",
23504 +               atomic_read(&nxi->nx_usecnt),
23505 +               atomic_read(&nxi->nx_tasks),
23506 +               (unsigned long long)nxi->nx_flags,
23507 +               (unsigned long long)nxi->nx_ncaps);
23508 +       return length;
23509 +}
23510 +
23511 +
23512 +
23513 +/* here the inode helpers */
23514 +
23515 +struct vs_entry {
23516 +       int len;
23517 +       char *name;
23518 +       mode_t mode;
23519 +       struct inode_operations *iop;
23520 +       struct file_operations *fop;
23521 +       union proc_op op;
23522 +};
23523 +
23524 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23525 +{
23526 +       struct inode *inode = new_inode(sb);
23527 +
23528 +       if (!inode)
23529 +               goto out;
23530 +
23531 +       inode->i_mode = p->mode;
23532 +       if (p->iop)
23533 +               inode->i_op = p->iop;
23534 +       if (p->fop)
23535 +               inode->i_fop = p->fop;
23536 +
23537 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23538 +       inode->i_flags |= S_IMMUTABLE;
23539 +
23540 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23541 +
23542 +       inode->i_uid = 0;
23543 +       inode->i_gid = 0;
23544 +       inode->i_tag = 0;
23545 +out:
23546 +       return inode;
23547 +}
23548 +
23549 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23550 +       struct dentry *dentry, int id, void *ptr)
23551 +{
23552 +       struct vs_entry *p = ptr;
23553 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23554 +       struct dentry *error = ERR_PTR(-EINVAL);
23555 +
23556 +       if (!inode)
23557 +               goto out;
23558 +
23559 +       PROC_I(inode)->op = p->op;
23560 +       PROC_I(inode)->fd = id;
23561 +       d_add(dentry, inode);
23562 +       error = NULL;
23563 +out:
23564 +       return error;
23565 +}
23566 +
23567 +/* Lookups */
23568 +
23569 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23570 +
23571 +/*
23572 + * Fill a directory entry.
23573 + *
23574 + * If possible create the dcache entry and derive our inode number and
23575 + * file type from dcache entry.
23576 + *
23577 + * Since all of the proc inode numbers are dynamically generated, the inode
23578 + * numbers do not exist until the inode is cache.  This means creating the
23579 + * the dcache entry in readdir is necessary to keep the inode numbers
23580 + * reported by readdir in sync with the inode numbers reported
23581 + * by stat.
23582 + */
23583 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23584 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23585 +{
23586 +       struct dentry *child, *dir = filp->f_dentry;
23587 +       struct inode *inode;
23588 +       struct qstr qname;
23589 +       ino_t ino = 0;
23590 +       unsigned type = DT_UNKNOWN;
23591 +
23592 +       qname.name = name;
23593 +       qname.len  = len;
23594 +       qname.hash = full_name_hash(name, len);
23595 +
23596 +       child = d_lookup(dir, &qname);
23597 +       if (!child) {
23598 +               struct dentry *new;
23599 +               new = d_alloc(dir, &qname);
23600 +               if (new) {
23601 +                       child = instantiate(dir->d_inode, new, id, ptr);
23602 +                       if (child)
23603 +                               dput(new);
23604 +                       else
23605 +                               child = new;
23606 +               }
23607 +       }
23608 +       if (!child || IS_ERR(child) || !child->d_inode)
23609 +               goto end_instantiate;
23610 +       inode = child->d_inode;
23611 +       if (inode) {
23612 +               ino = inode->i_ino;
23613 +               type = inode->i_mode >> 12;
23614 +       }
23615 +       dput(child);
23616 +end_instantiate:
23617 +       if (!ino)
23618 +               ino = find_inode_number(dir, &qname);
23619 +       if (!ino)
23620 +               ino = 1;
23621 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23622 +}
23623 +
23624 +
23625 +
23626 +/* get and revalidate vx_info/xid */
23627 +
23628 +static inline
23629 +struct vx_info *get_proc_vx_info(struct inode *inode)
23630 +{
23631 +       return lookup_vx_info(PROC_I(inode)->fd);
23632 +}
23633 +
23634 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23635 +{
23636 +       struct inode *inode = dentry->d_inode;
23637 +       xid_t xid = PROC_I(inode)->fd;
23638 +
23639 +       if (!xid || xid_is_hashed(xid))
23640 +               return 1;
23641 +       d_drop(dentry);
23642 +       return 0;
23643 +}
23644 +
23645 +
23646 +/* get and revalidate nx_info/nid */
23647 +
23648 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23649 +{
23650 +       struct inode *inode = dentry->d_inode;
23651 +       nid_t nid = PROC_I(inode)->fd;
23652 +
23653 +       if (!nid || nid_is_hashed(nid))
23654 +               return 1;
23655 +       d_drop(dentry);
23656 +       return 0;
23657 +}
23658 +
23659 +
23660 +
23661 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23662 +
23663 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23664 +                         size_t count, loff_t *ppos)
23665 +{
23666 +       struct inode *inode = file->f_dentry->d_inode;
23667 +       unsigned long page;
23668 +       ssize_t length = 0;
23669 +
23670 +       if (count > PROC_BLOCK_SIZE)
23671 +               count = PROC_BLOCK_SIZE;
23672 +
23673 +       /* fade that out as soon as stable */
23674 +       WARN_ON(PROC_I(inode)->fd);
23675 +
23676 +       if (!(page = __get_free_page(GFP_KERNEL)))
23677 +               return -ENOMEM;
23678 +
23679 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23680 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23681 +
23682 +       if (length >= 0)
23683 +               length = simple_read_from_buffer(buf, count, ppos,
23684 +                       (char *)page, length);
23685 +
23686 +       free_page(page);
23687 +       return length;
23688 +}
23689 +
23690 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23691 +                         size_t count, loff_t *ppos)
23692 +{
23693 +       struct inode *inode = file->f_dentry->d_inode;
23694 +       struct vx_info *vxi = NULL;
23695 +       xid_t xid = PROC_I(inode)->fd;
23696 +       unsigned long page;
23697 +       ssize_t length = 0;
23698 +
23699 +       if (count > PROC_BLOCK_SIZE)
23700 +               count = PROC_BLOCK_SIZE;
23701 +
23702 +       /* fade that out as soon as stable */
23703 +       WARN_ON(!xid);
23704 +       vxi = lookup_vx_info(xid);
23705 +       if (!vxi)
23706 +               goto out;
23707 +
23708 +       length = -ENOMEM;
23709 +       if (!(page = __get_free_page(GFP_KERNEL)))
23710 +               goto out_put;
23711 +
23712 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23713 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23714 +
23715 +       if (length >= 0)
23716 +               length = simple_read_from_buffer(buf, count, ppos,
23717 +                       (char *)page, length);
23718 +
23719 +       free_page(page);
23720 +out_put:
23721 +       put_vx_info(vxi);
23722 +out:
23723 +       return length;
23724 +}
23725 +
23726 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23727 +                         size_t count, loff_t *ppos)
23728 +{
23729 +       struct inode *inode = file->f_dentry->d_inode;
23730 +       struct nx_info *nxi = NULL;
23731 +       nid_t nid = PROC_I(inode)->fd;
23732 +       unsigned long page;
23733 +       ssize_t length = 0;
23734 +
23735 +       if (count > PROC_BLOCK_SIZE)
23736 +               count = PROC_BLOCK_SIZE;
23737 +
23738 +       /* fade that out as soon as stable */
23739 +       WARN_ON(!nid);
23740 +       nxi = lookup_nx_info(nid);
23741 +       if (!nxi)
23742 +               goto out;
23743 +
23744 +       length = -ENOMEM;
23745 +       if (!(page = __get_free_page(GFP_KERNEL)))
23746 +               goto out_put;
23747 +
23748 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23749 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23750 +
23751 +       if (length >= 0)
23752 +               length = simple_read_from_buffer(buf, count, ppos,
23753 +                       (char *)page, length);
23754 +
23755 +       free_page(page);
23756 +out_put:
23757 +       put_nx_info(nxi);
23758 +out:
23759 +       return length;
23760 +}
23761 +
23762 +
23763 +
23764 +/* here comes the lower level */
23765 +
23766 +
23767 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23768 +       .len  = sizeof(NAME) - 1,       \
23769 +       .name = (NAME),                 \
23770 +       .mode = MODE,                   \
23771 +       .iop  = IOP,                    \
23772 +       .fop  = FOP,                    \
23773 +       .op   = OP,                     \
23774 +}
23775 +
23776 +
23777 +#define DIR(NAME, MODE, OTYPE)                         \
23778 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23779 +               &proc_ ## OTYPE ## _inode_operations,   \
23780 +               &proc_ ## OTYPE ## _file_operations, { } )
23781 +
23782 +#define INF(NAME, MODE, OTYPE)                         \
23783 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23784 +               &proc_vs_info_file_operations,          \
23785 +               { .proc_vs_read = &proc_##OTYPE } )
23786 +
23787 +#define VINF(NAME, MODE, OTYPE)                                \
23788 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23789 +               &proc_vx_info_file_operations,          \
23790 +               { .proc_vxi_read = &proc_##OTYPE } )
23791 +
23792 +#define NINF(NAME, MODE, OTYPE)                                \
23793 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23794 +               &proc_nx_info_file_operations,          \
23795 +               { .proc_nxi_read = &proc_##OTYPE } )
23796 +
23797 +
23798 +static struct file_operations proc_vs_info_file_operations = {
23799 +       .read =         proc_vs_info_read,
23800 +};
23801 +
23802 +static struct file_operations proc_vx_info_file_operations = {
23803 +       .read =         proc_vx_info_read,
23804 +};
23805 +
23806 +static struct dentry_operations proc_xid_dentry_operations = {
23807 +       .d_revalidate = proc_xid_revalidate,
23808 +};
23809 +
23810 +static struct vs_entry vx_base_stuff[] = {
23811 +       VINF("info",    S_IRUGO, vxi_info),
23812 +       VINF("status",  S_IRUGO, vxi_status),
23813 +       VINF("limit",   S_IRUGO, vxi_limit),
23814 +       VINF("sched",   S_IRUGO, vxi_sched),
23815 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23816 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23817 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23818 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23819 +       {}
23820 +};
23821 +
23822 +
23823 +
23824 +
23825 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23826 +       struct dentry *dentry, int id, void *ptr)
23827 +{
23828 +       dentry->d_op = &proc_xid_dentry_operations;
23829 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23830 +}
23831 +
23832 +static struct dentry *proc_xid_lookup(struct inode *dir,
23833 +       struct dentry *dentry, struct nameidata *nd)
23834 +{
23835 +       struct vs_entry *p = vx_base_stuff;
23836 +       struct dentry *error = ERR_PTR(-ENOENT);
23837 +
23838 +       for (; p->name; p++) {
23839 +               if (p->len != dentry->d_name.len)
23840 +                       continue;
23841 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23842 +                       break;
23843 +       }
23844 +       if (!p->name)
23845 +               goto out;
23846 +
23847 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23848 +out:
23849 +       return error;
23850 +}
23851 +
23852 +static int proc_xid_readdir(struct file *filp,
23853 +       void *dirent, filldir_t filldir)
23854 +{
23855 +       struct dentry *dentry = filp->f_dentry;
23856 +       struct inode *inode = dentry->d_inode;
23857 +       struct vs_entry *p = vx_base_stuff;
23858 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23859 +       int pos, index;
23860 +       u64 ino;
23861 +
23862 +       pos = filp->f_pos;
23863 +       switch (pos) {
23864 +       case 0:
23865 +               ino = inode->i_ino;
23866 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23867 +                       goto out;
23868 +               pos++;
23869 +               /* fall through */
23870 +       case 1:
23871 +               ino = parent_ino(dentry);
23872 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23873 +                       goto out;
23874 +               pos++;
23875 +               /* fall through */
23876 +       default:
23877 +               index = pos - 2;
23878 +               if (index >= size)
23879 +                       goto out;
23880 +               for (p += index; p->name; p++) {
23881 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23882 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23883 +                               goto out;
23884 +                       pos++;
23885 +               }
23886 +       }
23887 +out:
23888 +       filp->f_pos = pos;
23889 +       return 1;
23890 +}
23891 +
23892 +
23893 +
23894 +static struct file_operations proc_nx_info_file_operations = {
23895 +       .read =         proc_nx_info_read,
23896 +};
23897 +
23898 +static struct dentry_operations proc_nid_dentry_operations = {
23899 +       .d_revalidate = proc_nid_revalidate,
23900 +};
23901 +
23902 +static struct vs_entry nx_base_stuff[] = {
23903 +       NINF("info",    S_IRUGO, nxi_info),
23904 +       NINF("status",  S_IRUGO, nxi_status),
23905 +       {}
23906 +};
23907 +
23908 +
23909 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23910 +       struct dentry *dentry, int id, void *ptr)
23911 +{
23912 +       dentry->d_op = &proc_nid_dentry_operations;
23913 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23914 +}
23915 +
23916 +static struct dentry *proc_nid_lookup(struct inode *dir,
23917 +       struct dentry *dentry, struct nameidata *nd)
23918 +{
23919 +       struct vs_entry *p = nx_base_stuff;
23920 +       struct dentry *error = ERR_PTR(-ENOENT);
23921 +
23922 +       for (; p->name; p++) {
23923 +               if (p->len != dentry->d_name.len)
23924 +                       continue;
23925 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23926 +                       break;
23927 +       }
23928 +       if (!p->name)
23929 +               goto out;
23930 +
23931 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23932 +out:
23933 +       return error;
23934 +}
23935 +
23936 +static int proc_nid_readdir(struct file *filp,
23937 +       void *dirent, filldir_t filldir)
23938 +{
23939 +       struct dentry *dentry = filp->f_dentry;
23940 +       struct inode *inode = dentry->d_inode;
23941 +       struct vs_entry *p = nx_base_stuff;
23942 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23943 +       int pos, index;
23944 +       u64 ino;
23945 +
23946 +       pos = filp->f_pos;
23947 +       switch (pos) {
23948 +       case 0:
23949 +               ino = inode->i_ino;
23950 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23951 +                       goto out;
23952 +               pos++;
23953 +               /* fall through */
23954 +       case 1:
23955 +               ino = parent_ino(dentry);
23956 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23957 +                       goto out;
23958 +               pos++;
23959 +               /* fall through */
23960 +       default:
23961 +               index = pos - 2;
23962 +               if (index >= size)
23963 +                       goto out;
23964 +               for (p += index; p->name; p++) {
23965 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23966 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23967 +                               goto out;
23968 +                       pos++;
23969 +               }
23970 +       }
23971 +out:
23972 +       filp->f_pos = pos;
23973 +       return 1;
23974 +}
23975 +
23976 +
23977 +#define MAX_MULBY10    ((~0U - 9) / 10)
23978 +
23979 +static inline int atovid(const char *str, int len)
23980 +{
23981 +       int vid, c;
23982 +
23983 +       vid = 0;
23984 +       while (len-- > 0) {
23985 +               c = *str - '0';
23986 +               str++;
23987 +               if (c > 9)
23988 +                       return -1;
23989 +               if (vid >= MAX_MULBY10)
23990 +                       return -1;
23991 +               vid *= 10;
23992 +               vid += c;
23993 +               if (!vid)
23994 +                       return -1;
23995 +       }
23996 +       return vid;
23997 +}
23998 +
23999 +/* now the upper level (virtual) */
24000 +
24001 +
24002 +static struct file_operations proc_xid_file_operations = {
24003 +       .read =         generic_read_dir,
24004 +       .readdir =      proc_xid_readdir,
24005 +};
24006 +
24007 +static struct inode_operations proc_xid_inode_operations = {
24008 +       .lookup =       proc_xid_lookup,
24009 +};
24010 +
24011 +static struct vs_entry vx_virtual_stuff[] = {
24012 +       INF("info",     S_IRUGO, virtual_info),
24013 +       INF("status",   S_IRUGO, virtual_status),
24014 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
24015 +};
24016 +
24017 +
24018 +static struct dentry *proc_virtual_lookup(struct inode *dir,
24019 +       struct dentry *dentry, struct nameidata *nd)
24020 +{
24021 +       struct vs_entry *p = vx_virtual_stuff;
24022 +       struct dentry *error = ERR_PTR(-ENOENT);
24023 +       int id = 0;
24024 +
24025 +       for (; p->name; p++) {
24026 +               if (p->len != dentry->d_name.len)
24027 +                       continue;
24028 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24029 +                       break;
24030 +       }
24031 +       if (p->name)
24032 +               goto instantiate;
24033 +
24034 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24035 +       if ((id < 0) || !xid_is_hashed(id))
24036 +               goto out;
24037 +
24038 +instantiate:
24039 +       error = proc_xid_instantiate(dir, dentry, id, p);
24040 +out:
24041 +       return error;
24042 +}
24043 +
24044 +static struct file_operations proc_nid_file_operations = {
24045 +       .read =         generic_read_dir,
24046 +       .readdir =      proc_nid_readdir,
24047 +};
24048 +
24049 +static struct inode_operations proc_nid_inode_operations = {
24050 +       .lookup =       proc_nid_lookup,
24051 +};
24052 +
24053 +static struct vs_entry nx_virtnet_stuff[] = {
24054 +       INF("info",     S_IRUGO, virtnet_info),
24055 +       INF("status",   S_IRUGO, virtnet_status),
24056 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
24057 +};
24058 +
24059 +
24060 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
24061 +       struct dentry *dentry, struct nameidata *nd)
24062 +{
24063 +       struct vs_entry *p = nx_virtnet_stuff;
24064 +       struct dentry *error = ERR_PTR(-ENOENT);
24065 +       int id = 0;
24066 +
24067 +       for (; p->name; p++) {
24068 +               if (p->len != dentry->d_name.len)
24069 +                       continue;
24070 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24071 +                       break;
24072 +       }
24073 +       if (p->name)
24074 +               goto instantiate;
24075 +
24076 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24077 +       if ((id < 0) || !nid_is_hashed(id))
24078 +               goto out;
24079 +
24080 +instantiate:
24081 +       error = proc_nid_instantiate(dir, dentry, id, p);
24082 +out:
24083 +       return error;
24084 +}
24085 +
24086 +
24087 +#define PROC_MAXVIDS 32
24088 +
24089 +int proc_virtual_readdir(struct file *filp,
24090 +       void *dirent, filldir_t filldir)
24091 +{
24092 +       struct dentry *dentry = filp->f_dentry;
24093 +       struct inode *inode = dentry->d_inode;
24094 +       struct vs_entry *p = vx_virtual_stuff;
24095 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
24096 +       int pos, index;
24097 +       unsigned int xid_array[PROC_MAXVIDS];
24098 +       char buf[PROC_NUMBUF];
24099 +       unsigned int nr_xids, i;
24100 +       u64 ino;
24101 +
24102 +       pos = filp->f_pos;
24103 +       switch (pos) {
24104 +       case 0:
24105 +               ino = inode->i_ino;
24106 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24107 +                       goto out;
24108 +               pos++;
24109 +               /* fall through */
24110 +       case 1:
24111 +               ino = parent_ino(dentry);
24112 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24113 +                       goto out;
24114 +               pos++;
24115 +               /* fall through */
24116 +       default:
24117 +               index = pos - 2;
24118 +               if (index >= size)
24119 +                       goto entries;
24120 +               for (p += index; p->name; p++) {
24121 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24122 +                               vs_proc_instantiate, 0, p))
24123 +                               goto out;
24124 +                       pos++;
24125 +               }
24126 +       entries:
24127 +               index = pos - size;
24128 +               p = &vx_virtual_stuff[size - 1];
24129 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
24130 +               for (i = 0; i < nr_xids; i++) {
24131 +                       int n, xid = xid_array[i];
24132 +                       unsigned int j = PROC_NUMBUF;
24133 +
24134 +                       n = xid;
24135 +                       do
24136 +                               buf[--j] = '0' + (n % 10);
24137 +                       while (n /= 10);
24138 +
24139 +                       if (proc_fill_cache(filp, dirent, filldir,
24140 +                               buf + j, PROC_NUMBUF - j,
24141 +                               vs_proc_instantiate, xid, p))
24142 +                               goto out;
24143 +                       pos++;
24144 +               }
24145 +       }
24146 +out:
24147 +       filp->f_pos = pos;
24148 +       return 0;
24149 +}
24150 +
24151 +static int proc_virtual_getattr(struct vfsmount *mnt,
24152 +       struct dentry *dentry, struct kstat *stat)
24153 +{
24154 +       struct inode *inode = dentry->d_inode;
24155 +
24156 +       generic_fillattr(inode, stat);
24157 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
24158 +       return 0;
24159 +}
24160 +
24161 +static struct file_operations proc_virtual_dir_operations = {
24162 +       .read =         generic_read_dir,
24163 +       .readdir =      proc_virtual_readdir,
24164 +};
24165 +
24166 +static struct inode_operations proc_virtual_dir_inode_operations = {
24167 +       .getattr =      proc_virtual_getattr,
24168 +       .lookup =       proc_virtual_lookup,
24169 +};
24170 +
24171 +
24172 +
24173 +
24174 +
24175 +int proc_virtnet_readdir(struct file *filp,
24176 +       void *dirent, filldir_t filldir)
24177 +{
24178 +       struct dentry *dentry = filp->f_dentry;
24179 +       struct inode *inode = dentry->d_inode;
24180 +       struct vs_entry *p = nx_virtnet_stuff;
24181 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24182 +       int pos, index;
24183 +       unsigned int nid_array[PROC_MAXVIDS];
24184 +       char buf[PROC_NUMBUF];
24185 +       unsigned int nr_nids, i;
24186 +       u64 ino;
24187 +
24188 +       pos = filp->f_pos;
24189 +       switch (pos) {
24190 +       case 0:
24191 +               ino = inode->i_ino;
24192 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24193 +                       goto out;
24194 +               pos++;
24195 +               /* fall through */
24196 +       case 1:
24197 +               ino = parent_ino(dentry);
24198 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24199 +                       goto out;
24200 +               pos++;
24201 +               /* fall through */
24202 +       default:
24203 +               index = pos - 2;
24204 +               if (index >= size)
24205 +                       goto entries;
24206 +               for (p += index; p->name; p++) {
24207 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24208 +                               vs_proc_instantiate, 0, p))
24209 +                               goto out;
24210 +                       pos++;
24211 +               }
24212 +       entries:
24213 +               index = pos - size;
24214 +               p = &nx_virtnet_stuff[size - 1];
24215 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24216 +               for (i = 0; i < nr_nids; i++) {
24217 +                       int n, nid = nid_array[i];
24218 +                       unsigned int j = PROC_NUMBUF;
24219 +
24220 +                       n = nid;
24221 +                       do
24222 +                               buf[--j] = '0' + (n % 10);
24223 +                       while (n /= 10);
24224 +
24225 +                       if (proc_fill_cache(filp, dirent, filldir,
24226 +                               buf + j, PROC_NUMBUF - j,
24227 +                               vs_proc_instantiate, nid, p))
24228 +                               goto out;
24229 +                       pos++;
24230 +               }
24231 +       }
24232 +out:
24233 +       filp->f_pos = pos;
24234 +       return 0;
24235 +}
24236 +
24237 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24238 +       struct dentry *dentry, struct kstat *stat)
24239 +{
24240 +       struct inode *inode = dentry->d_inode;
24241 +
24242 +       generic_fillattr(inode, stat);
24243 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24244 +       return 0;
24245 +}
24246 +
24247 +static struct file_operations proc_virtnet_dir_operations = {
24248 +       .read =         generic_read_dir,
24249 +       .readdir =      proc_virtnet_readdir,
24250 +};
24251 +
24252 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24253 +       .getattr =      proc_virtnet_getattr,
24254 +       .lookup =       proc_virtnet_lookup,
24255 +};
24256 +
24257 +
24258 +
24259 +void proc_vx_init(void)
24260 +{
24261 +       struct proc_dir_entry *ent;
24262 +
24263 +       ent = proc_mkdir("virtual", 0);
24264 +       if (ent) {
24265 +               ent->proc_fops = &proc_virtual_dir_operations;
24266 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24267 +       }
24268 +       proc_virtual = ent;
24269 +
24270 +       ent = proc_mkdir("virtnet", 0);
24271 +       if (ent) {
24272 +               ent->proc_fops = &proc_virtnet_dir_operations;
24273 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24274 +       }
24275 +       proc_virtnet = ent;
24276 +}
24277 +
24278 +
24279 +
24280 +
24281 +/* per pid info */
24282 +
24283 +
24284 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24285 +{
24286 +       struct vx_info *vxi;
24287 +       char *orig = buffer;
24288 +
24289 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24290 +
24291 +       vxi = task_get_vx_info(p);
24292 +       if (!vxi)
24293 +               goto out;
24294 +
24295 +       buffer += sprintf(buffer, "BCaps:\t");
24296 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24297 +       buffer += sprintf(buffer, "\n");
24298 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24299 +               (unsigned long long)vxi->vx_ccaps);
24300 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24301 +               (unsigned long long)vxi->vx_flags);
24302 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24303 +
24304 +       put_vx_info(vxi);
24305 +out:
24306 +       return buffer - orig;
24307 +}
24308 +
24309 +
24310 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24311 +{
24312 +       struct nx_info *nxi;
24313 +       struct nx_addr_v4 *v4a;
24314 +#ifdef CONFIG_IPV6
24315 +       struct nx_addr_v6 *v6a;
24316 +#endif
24317 +       char *orig = buffer;
24318 +       int i;
24319 +
24320 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24321 +
24322 +       nxi = task_get_nx_info(p);
24323 +       if (!nxi)
24324 +               goto out;
24325 +
24326 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24327 +               (unsigned long long)nxi->nx_ncaps);
24328 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24329 +               (unsigned long long)nxi->nx_flags);
24330 +
24331 +       buffer += sprintf(buffer,
24332 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24333 +               NIPQUAD(nxi->v4_bcast.s_addr));
24334 +       buffer += sprintf (buffer,
24335 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24336 +               NIPQUAD(nxi->v4_lback.s_addr));
24337 +       if (!NX_IPV4(nxi))
24338 +               goto skip_v4;
24339 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24340 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24341 +                       i, NXAV4(v4a));
24342 +skip_v4:
24343 +#ifdef CONFIG_IPV6
24344 +       if (!NX_IPV6(nxi))
24345 +               goto skip_v6;
24346 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24347 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24348 +                       i, NXAV6(v6a));
24349 +skip_v6:
24350 +#endif
24351 +       put_nx_info(nxi);
24352 +out:
24353 +       return buffer - orig;
24354 +}
24355 +
24356 diff -NurpP --minimal linux-3.0.4/kernel/vserver/sched.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/sched.c
24357 --- linux-3.0.4/kernel/vserver/sched.c  1970-01-01 01:00:00.000000000 +0100
24358 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/sched.c  2011-06-10 22:11:24.000000000 +0200
24359 @@ -0,0 +1,82 @@
24360 +/*
24361 + *  linux/kernel/vserver/sched.c
24362 + *
24363 + *  Virtual Server: Scheduler Support
24364 + *
24365 + *  Copyright (C) 2004-2010  Herbert Pötzl
24366 + *
24367 + *  V0.01  adapted Sam Vilains version to 2.6.3
24368 + *  V0.02  removed legacy interface
24369 + *  V0.03  changed vcmds to vxi arg
24370 + *  V0.04  removed older and legacy interfaces
24371 + *  V0.05  removed scheduler code/commands
24372 + *
24373 + */
24374 +
24375 +#include <linux/vs_context.h>
24376 +#include <linux/vs_sched.h>
24377 +#include <linux/vserver/sched_cmd.h>
24378 +
24379 +#include <asm/uaccess.h>
24380 +
24381 +
24382 +void vx_update_sched_param(struct _vx_sched *sched,
24383 +       struct _vx_sched_pc *sched_pc)
24384 +{
24385 +       sched_pc->prio_bias = sched->prio_bias;
24386 +}
24387 +
24388 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
24389 +{
24390 +       int cpu;
24391 +
24392 +       if (data->prio_bias > MAX_PRIO_BIAS)
24393 +               data->prio_bias = MAX_PRIO_BIAS;
24394 +       if (data->prio_bias < MIN_PRIO_BIAS)
24395 +               data->prio_bias = MIN_PRIO_BIAS;
24396 +
24397 +       if (data->cpu_id != ~0) {
24398 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24399 +               cpus_and(vxi->sched.update, cpu_online_map,
24400 +                       vxi->sched.update);
24401 +       } else
24402 +               vxi->sched.update = cpu_online_map;
24403 +
24404 +       for_each_cpu_mask(cpu, vxi->sched.update)
24405 +               vx_update_sched_param(&vxi->sched,
24406 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24407 +       return 0;
24408 +}
24409 +
24410 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
24411 +{
24412 +       struct vcmd_prio_bias vc_data;
24413 +
24414 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24415 +               return -EFAULT;
24416 +
24417 +       return do_set_prio_bias(vxi, &vc_data);
24418 +}
24419 +
24420 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
24421 +{
24422 +       struct vcmd_prio_bias vc_data;
24423 +       struct _vx_sched_pc *pcd;
24424 +       int cpu;
24425 +
24426 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24427 +               return -EFAULT;
24428 +
24429 +       cpu = vc_data.cpu_id;
24430 +
24431 +       if (!cpu_possible(cpu))
24432 +               return -EINVAL;
24433 +
24434 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
24435 +       vc_data.prio_bias = pcd->prio_bias;
24436 +
24437 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24438 +               return -EFAULT;
24439 +       return 0;
24440 +}
24441 +
24442 diff -NurpP --minimal linux-3.0.4/kernel/vserver/sched_init.h linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/sched_init.h
24443 --- linux-3.0.4/kernel/vserver/sched_init.h     1970-01-01 01:00:00.000000000 +0100
24444 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/sched_init.h     2011-06-10 22:11:24.000000000 +0200
24445 @@ -0,0 +1,27 @@
24446 +
24447 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24448 +{
24449 +       /* scheduling; hard code starting values as constants */
24450 +       sched->prio_bias = 0;
24451 +}
24452 +
24453 +static inline
24454 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24455 +{
24456 +       sched_pc->prio_bias = 0;
24457 +
24458 +       sched_pc->user_ticks = 0;
24459 +       sched_pc->sys_ticks = 0;
24460 +       sched_pc->hold_ticks = 0;
24461 +}
24462 +
24463 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24464 +{
24465 +       return;
24466 +}
24467 +
24468 +static inline
24469 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24470 +{
24471 +       return;
24472 +}
24473 diff -NurpP --minimal linux-3.0.4/kernel/vserver/sched_proc.h linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/sched_proc.h
24474 --- linux-3.0.4/kernel/vserver/sched_proc.h     1970-01-01 01:00:00.000000000 +0100
24475 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/sched_proc.h     2011-06-10 22:11:24.000000000 +0200
24476 @@ -0,0 +1,32 @@
24477 +#ifndef _VX_SCHED_PROC_H
24478 +#define _VX_SCHED_PROC_H
24479 +
24480 +
24481 +static inline
24482 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24483 +{
24484 +       int length = 0;
24485 +
24486 +       length += sprintf(buffer,
24487 +               "PrioBias:\t%8d\n",
24488 +               sched->prio_bias);
24489 +       return length;
24490 +}
24491 +
24492 +static inline
24493 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24494 +       char *buffer, int cpu)
24495 +{
24496 +       int length = 0;
24497 +
24498 +       length += sprintf(buffer + length,
24499 +               "cpu %d: %lld %lld %lld", cpu,
24500 +               (unsigned long long)sched_pc->user_ticks,
24501 +               (unsigned long long)sched_pc->sys_ticks,
24502 +               (unsigned long long)sched_pc->hold_ticks);
24503 +       length += sprintf(buffer + length,
24504 +               " %d\n", sched_pc->prio_bias);
24505 +       return length;
24506 +}
24507 +
24508 +#endif /* _VX_SCHED_PROC_H */
24509 diff -NurpP --minimal linux-3.0.4/kernel/vserver/signal.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/signal.c
24510 --- linux-3.0.4/kernel/vserver/signal.c 1970-01-01 01:00:00.000000000 +0100
24511 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/signal.c 2011-06-10 22:11:24.000000000 +0200
24512 @@ -0,0 +1,134 @@
24513 +/*
24514 + *  linux/kernel/vserver/signal.c
24515 + *
24516 + *  Virtual Server: Signal Support
24517 + *
24518 + *  Copyright (C) 2003-2007  Herbert Pötzl
24519 + *
24520 + *  V0.01  broken out from vcontext V0.05
24521 + *  V0.02  changed vcmds to vxi arg
24522 + *  V0.03  adjusted siginfo for kill
24523 + *
24524 + */
24525 +
24526 +#include <asm/uaccess.h>
24527 +
24528 +#include <linux/vs_context.h>
24529 +#include <linux/vs_pid.h>
24530 +#include <linux/vserver/signal_cmd.h>
24531 +
24532 +
24533 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24534 +{
24535 +       int retval, count = 0;
24536 +       struct task_struct *p;
24537 +       struct siginfo *sip = SEND_SIG_PRIV;
24538 +
24539 +       retval = -ESRCH;
24540 +       vxdprintk(VXD_CBIT(misc, 4),
24541 +               "vx_info_kill(%p[#%d],%d,%d)*",
24542 +               vxi, vxi->vx_id, pid, sig);
24543 +       read_lock(&tasklist_lock);
24544 +       switch (pid) {
24545 +       case  0:
24546 +       case -1:
24547 +               for_each_process(p) {
24548 +                       int err = 0;
24549 +
24550 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24551 +                               (pid && vxi->vx_initpid == p->pid))
24552 +                               continue;
24553 +
24554 +                       err = group_send_sig_info(sig, sip, p);
24555 +                       ++count;
24556 +                       if (err != -EPERM)
24557 +                               retval = err;
24558 +               }
24559 +               break;
24560 +
24561 +       case 1:
24562 +               if (vxi->vx_initpid) {
24563 +                       pid = vxi->vx_initpid;
24564 +                       /* for now, only SIGINT to private init ... */
24565 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24566 +                               /* ... as long as there are tasks left */
24567 +                               (atomic_read(&vxi->vx_tasks) > 1))
24568 +                               sig = SIGINT;
24569 +               }
24570 +               /* fallthrough */
24571 +       default:
24572 +               rcu_read_lock();
24573 +               p = find_task_by_real_pid(pid);
24574 +               rcu_read_unlock();
24575 +               if (p) {
24576 +                       if (vx_task_xid(p) == vxi->vx_id)
24577 +                               retval = group_send_sig_info(sig, sip, p);
24578 +               }
24579 +               break;
24580 +       }
24581 +       read_unlock(&tasklist_lock);
24582 +       vxdprintk(VXD_CBIT(misc, 4),
24583 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24584 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24585 +       return retval;
24586 +}
24587 +
24588 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24589 +{
24590 +       struct vcmd_ctx_kill_v0 vc_data;
24591 +
24592 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24593 +               return -EFAULT;
24594 +
24595 +       /* special check to allow guest shutdown */
24596 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24597 +               /* forbid killall pid=0 when init is present */
24598 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24599 +               (vc_data.pid > 1)))
24600 +               return -EACCES;
24601 +
24602 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24603 +}
24604 +
24605 +
24606 +static int __wait_exit(struct vx_info *vxi)
24607 +{
24608 +       DECLARE_WAITQUEUE(wait, current);
24609 +       int ret = 0;
24610 +
24611 +       add_wait_queue(&vxi->vx_wait, &wait);
24612 +       set_current_state(TASK_INTERRUPTIBLE);
24613 +
24614 +wait:
24615 +       if (vx_info_state(vxi,
24616 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24617 +               goto out;
24618 +       if (signal_pending(current)) {
24619 +               ret = -ERESTARTSYS;
24620 +               goto out;
24621 +       }
24622 +       schedule();
24623 +       goto wait;
24624 +
24625 +out:
24626 +       set_current_state(TASK_RUNNING);
24627 +       remove_wait_queue(&vxi->vx_wait, &wait);
24628 +       return ret;
24629 +}
24630 +
24631 +
24632 +
24633 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24634 +{
24635 +       struct vcmd_wait_exit_v0 vc_data;
24636 +       int ret;
24637 +
24638 +       ret = __wait_exit(vxi);
24639 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24640 +       vc_data.exit_code = vxi->exit_code;
24641 +
24642 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24643 +               ret = -EFAULT;
24644 +       return ret;
24645 +}
24646 +
24647 diff -NurpP --minimal linux-3.0.4/kernel/vserver/space.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/space.c
24648 --- linux-3.0.4/kernel/vserver/space.c  1970-01-01 01:00:00.000000000 +0100
24649 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/space.c  2011-07-20 02:11:49.000000000 +0200
24650 @@ -0,0 +1,435 @@
24651 +/*
24652 + *  linux/kernel/vserver/space.c
24653 + *
24654 + *  Virtual Server: Context Space Support
24655 + *
24656 + *  Copyright (C) 2003-2010  Herbert Pötzl
24657 + *
24658 + *  V0.01  broken out from context.c 0.07
24659 + *  V0.02  added task locking for namespace
24660 + *  V0.03  broken out vx_enter_namespace
24661 + *  V0.04  added *space support and commands
24662 + *  V0.05  added credential support
24663 + *
24664 + */
24665 +
24666 +#include <linux/utsname.h>
24667 +#include <linux/nsproxy.h>
24668 +#include <linux/err.h>
24669 +#include <linux/fs_struct.h>
24670 +#include <linux/cred.h>
24671 +#include <asm/uaccess.h>
24672 +
24673 +#include <linux/vs_context.h>
24674 +#include <linux/vserver/space.h>
24675 +#include <linux/vserver/space_cmd.h>
24676 +
24677 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24678 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24679 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24680 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24681 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24682 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24683 +
24684 +
24685 +/* namespace functions */
24686 +
24687 +#include <linux/mnt_namespace.h>
24688 +#include <linux/user_namespace.h>
24689 +#include <linux/pid_namespace.h>
24690 +#include <linux/ipc_namespace.h>
24691 +#include <net/net_namespace.h>
24692 +
24693 +
24694 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24695 +       .mask = CLONE_FS |
24696 +               CLONE_NEWNS |
24697 +#ifdef CONFIG_UTS_NS
24698 +               CLONE_NEWUTS |
24699 +#endif
24700 +#ifdef CONFIG_IPC_NS
24701 +               CLONE_NEWIPC |
24702 +#endif
24703 +#ifdef CONFIG_USER_NS
24704 +               CLONE_NEWUSER |
24705 +#endif
24706 +               0
24707 +};
24708 +
24709 +static const struct vcmd_space_mask_v1 space_mask = {
24710 +       .mask = CLONE_FS |
24711 +               CLONE_NEWNS |
24712 +#ifdef CONFIG_UTS_NS
24713 +               CLONE_NEWUTS |
24714 +#endif
24715 +#ifdef CONFIG_IPC_NS
24716 +               CLONE_NEWIPC |
24717 +#endif
24718 +#ifdef CONFIG_USER_NS
24719 +               CLONE_NEWUSER |
24720 +#endif
24721 +#ifdef CONFIG_PID_NS
24722 +               CLONE_NEWPID |
24723 +#endif
24724 +#ifdef CONFIG_NET_NS
24725 +               CLONE_NEWNET |
24726 +#endif
24727 +               0
24728 +};
24729 +
24730 +static const struct vcmd_space_mask_v1 default_space_mask = {
24731 +       .mask = CLONE_FS |
24732 +               CLONE_NEWNS |
24733 +#ifdef CONFIG_UTS_NS
24734 +               CLONE_NEWUTS |
24735 +#endif
24736 +#ifdef CONFIG_IPC_NS
24737 +               CLONE_NEWIPC |
24738 +#endif
24739 +#ifdef CONFIG_USER_NS
24740 +               CLONE_NEWUSER |
24741 +#endif
24742 +#ifdef CONFIG_PID_NS
24743 +//             CLONE_NEWPID |
24744 +#endif
24745 +               0
24746 +};
24747 +
24748 +/*
24749 + *     build a new nsproxy mix
24750 + *      assumes that both proxies are 'const'
24751 + *     does not touch nsproxy refcounts
24752 + *     will hold a reference on the result.
24753 + */
24754 +
24755 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24756 +       struct nsproxy *new_nsproxy, unsigned long mask)
24757 +{
24758 +       struct mnt_namespace *old_ns;
24759 +       struct uts_namespace *old_uts;
24760 +       struct ipc_namespace *old_ipc;
24761 +#ifdef CONFIG_PID_NS
24762 +       struct pid_namespace *old_pid;
24763 +#endif
24764 +#ifdef CONFIG_NET_NS
24765 +       struct net *old_net;
24766 +#endif
24767 +       struct nsproxy *nsproxy;
24768 +
24769 +       nsproxy = copy_nsproxy(old_nsproxy);
24770 +       if (!nsproxy)
24771 +               goto out;
24772 +
24773 +       if (mask & CLONE_NEWNS) {
24774 +               old_ns = nsproxy->mnt_ns;
24775 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24776 +               if (nsproxy->mnt_ns)
24777 +                       get_mnt_ns(nsproxy->mnt_ns);
24778 +       } else
24779 +               old_ns = NULL;
24780 +
24781 +       if (mask & CLONE_NEWUTS) {
24782 +               old_uts = nsproxy->uts_ns;
24783 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24784 +               if (nsproxy->uts_ns)
24785 +                       get_uts_ns(nsproxy->uts_ns);
24786 +       } else
24787 +               old_uts = NULL;
24788 +
24789 +       if (mask & CLONE_NEWIPC) {
24790 +               old_ipc = nsproxy->ipc_ns;
24791 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24792 +               if (nsproxy->ipc_ns)
24793 +                       get_ipc_ns(nsproxy->ipc_ns);
24794 +       } else
24795 +               old_ipc = NULL;
24796 +
24797 +#ifdef CONFIG_PID_NS
24798 +       if (mask & CLONE_NEWPID) {
24799 +               old_pid = nsproxy->pid_ns;
24800 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24801 +               if (nsproxy->pid_ns)
24802 +                       get_pid_ns(nsproxy->pid_ns);
24803 +       } else
24804 +               old_pid = NULL;
24805 +#endif
24806 +#ifdef CONFIG_NET_NS
24807 +       if (mask & CLONE_NEWNET) {
24808 +               old_net = nsproxy->net_ns;
24809 +               nsproxy->net_ns = new_nsproxy->net_ns;
24810 +               if (nsproxy->net_ns)
24811 +                       get_net(nsproxy->net_ns);
24812 +       } else
24813 +               old_net = NULL;
24814 +#endif
24815 +       if (old_ns)
24816 +               put_mnt_ns(old_ns);
24817 +       if (old_uts)
24818 +               put_uts_ns(old_uts);
24819 +       if (old_ipc)
24820 +               put_ipc_ns(old_ipc);
24821 +#ifdef CONFIG_PID_NS
24822 +       if (old_pid)
24823 +               put_pid_ns(old_pid);
24824 +#endif
24825 +#ifdef CONFIG_NET_NS
24826 +       if (old_net)
24827 +               put_net(old_net);
24828 +#endif
24829 +out:
24830 +       return nsproxy;
24831 +}
24832 +
24833 +
24834 +/*
24835 + *     merge two nsproxy structs into a new one.
24836 + *     will hold a reference on the result.
24837 + */
24838 +
24839 +static inline
24840 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24841 +       struct nsproxy *proxy, unsigned long mask)
24842 +{
24843 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24844 +
24845 +       if (!proxy)
24846 +               return NULL;
24847 +
24848 +       if (mask) {
24849 +               /* vs_mix_nsproxy returns with reference */
24850 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24851 +                       proxy, mask);
24852 +       }
24853 +       get_nsproxy(proxy);
24854 +       return proxy;
24855 +}
24856 +
24857 +
24858 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24859 +{
24860 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24861 +       struct fs_struct *fs_cur, *fs = NULL;
24862 +       struct _vx_space *space;
24863 +       int ret, kill = 0;
24864 +
24865 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24866 +               vxi, vxi->vx_id, mask, index);
24867 +
24868 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24869 +               return -EACCES;
24870 +
24871 +       if (index >= VX_SPACES)
24872 +               return -EINVAL;
24873 +
24874 +       space = &vxi->space[index];
24875 +
24876 +       if (!mask)
24877 +               mask = space->vx_nsmask;
24878 +
24879 +       if ((mask & space->vx_nsmask) != mask)
24880 +               return -EINVAL;
24881 +
24882 +       if (mask & CLONE_FS) {
24883 +               fs = copy_fs_struct(space->vx_fs);
24884 +               if (!fs)
24885 +                       return -ENOMEM;
24886 +       }
24887 +       proxy = space->vx_nsproxy;
24888 +
24889 +       vxdprintk(VXD_CBIT(space, 9),
24890 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
24891 +               vxi, vxi->vx_id, mask, index, proxy, fs);
24892 +
24893 +       task_lock(current);
24894 +       fs_cur = current->fs;
24895 +
24896 +       if (mask & CLONE_FS) {
24897 +               spin_lock(&fs_cur->lock);
24898 +               current->fs = fs;
24899 +               kill = !--fs_cur->users;
24900 +               spin_unlock(&fs_cur->lock);
24901 +       }
24902 +
24903 +       proxy_cur = current->nsproxy;
24904 +       get_nsproxy(proxy_cur);
24905 +       task_unlock(current);
24906 +
24907 +       if (kill)
24908 +               free_fs_struct(fs_cur);
24909 +
24910 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24911 +       if (IS_ERR(proxy_new)) {
24912 +               ret = PTR_ERR(proxy_new);
24913 +               goto out_put;
24914 +       }
24915 +
24916 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24917 +
24918 +       if (mask & CLONE_NEWUSER) {
24919 +               struct cred *cred;
24920 +
24921 +               vxdprintk(VXD_CBIT(space, 10),
24922 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
24923 +                       vxi, vxi->vx_id, space->vx_cred,
24924 +                       current->real_cred, current->cred);
24925 +
24926 +               if (space->vx_cred) {
24927 +                       cred = __prepare_creds(space->vx_cred);
24928 +                       if (cred)
24929 +                               commit_creds(cred);
24930 +               }
24931 +       }
24932 +
24933 +       ret = 0;
24934 +
24935 +       if (proxy_new)
24936 +               put_nsproxy(proxy_new);
24937 +out_put:
24938 +       if (proxy_cur)
24939 +               put_nsproxy(proxy_cur);
24940 +       return ret;
24941 +}
24942 +
24943 +
24944 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24945 +{
24946 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24947 +       struct fs_struct *fs_vxi, *fs;
24948 +       struct _vx_space *space;
24949 +       int ret, kill = 0;
24950 +
24951 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24952 +               vxi, vxi->vx_id, mask, index);
24953 +
24954 +       if ((mask & space_mask.mask) != mask)
24955 +               return -EINVAL;
24956 +
24957 +       if (index >= VX_SPACES)
24958 +               return -EINVAL;
24959 +
24960 +       space = &vxi->space[index];
24961 +
24962 +       proxy_vxi = space->vx_nsproxy;
24963 +       fs_vxi = space->vx_fs;
24964 +
24965 +       if (mask & CLONE_FS) {
24966 +               fs = copy_fs_struct(current->fs);
24967 +               if (!fs)
24968 +                       return -ENOMEM;
24969 +       }
24970 +
24971 +       task_lock(current);
24972 +
24973 +       if (mask & CLONE_FS) {
24974 +               spin_lock(&fs_vxi->lock);
24975 +               space->vx_fs = fs;
24976 +               kill = !--fs_vxi->users;
24977 +               spin_unlock(&fs_vxi->lock);
24978 +       }
24979 +
24980 +       proxy_cur = current->nsproxy;
24981 +       get_nsproxy(proxy_cur);
24982 +       task_unlock(current);
24983 +
24984 +       if (kill)
24985 +               free_fs_struct(fs_vxi);
24986 +
24987 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24988 +       if (IS_ERR(proxy_new)) {
24989 +               ret = PTR_ERR(proxy_new);
24990 +               goto out_put;
24991 +       }
24992 +
24993 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
24994 +       space->vx_nsmask |= mask;
24995 +
24996 +       if (mask & CLONE_NEWUSER) {
24997 +               struct cred *cred;
24998 +
24999 +               vxdprintk(VXD_CBIT(space, 10),
25000 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
25001 +                       vxi, vxi->vx_id, space->vx_cred,
25002 +                       current->real_cred, current->cred);
25003 +
25004 +               cred = prepare_creds();
25005 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
25006 +               if (cred)
25007 +                       abort_creds(cred);
25008 +       }
25009 +
25010 +       ret = 0;
25011 +
25012 +       if (proxy_new)
25013 +               put_nsproxy(proxy_new);
25014 +out_put:
25015 +       if (proxy_cur)
25016 +               put_nsproxy(proxy_cur);
25017 +       return ret;
25018 +}
25019 +
25020 +
25021 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
25022 +{
25023 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25024 +
25025 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25026 +               return -EFAULT;
25027 +
25028 +       return vx_enter_space(vxi, vc_data.mask, 0);
25029 +}
25030 +
25031 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25032 +{
25033 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25034 +
25035 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25036 +               return -EFAULT;
25037 +
25038 +       if (vc_data.index >= VX_SPACES)
25039 +               return -EINVAL;
25040 +
25041 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
25042 +}
25043 +
25044 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
25045 +{
25046 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25047 +
25048 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25049 +               return -EFAULT;
25050 +
25051 +       return vx_set_space(vxi, vc_data.mask, 0);
25052 +}
25053 +
25054 +int vc_set_space(struct vx_info *vxi, void __user *data)
25055 +{
25056 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25057 +
25058 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25059 +               return -EFAULT;
25060 +
25061 +       if (vc_data.index >= VX_SPACES)
25062 +               return -EINVAL;
25063 +
25064 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
25065 +}
25066 +
25067 +int vc_get_space_mask(void __user *data, int type)
25068 +{
25069 +       const struct vcmd_space_mask_v1 *mask;
25070 +
25071 +       if (type == 0)
25072 +               mask = &space_mask_v0;
25073 +       else if (type == 1)
25074 +               mask = &space_mask;
25075 +       else
25076 +               mask = &default_space_mask;
25077 +
25078 +       vxdprintk(VXD_CBIT(space, 10),
25079 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
25080 +
25081 +       if (copy_to_user(data, mask, sizeof(*mask)))
25082 +               return -EFAULT;
25083 +       return 0;
25084 +}
25085 +
25086 diff -NurpP --minimal linux-3.0.4/kernel/vserver/switch.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/switch.c
25087 --- linux-3.0.4/kernel/vserver/switch.c 1970-01-01 01:00:00.000000000 +0100
25088 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/switch.c 2011-08-01 18:28:26.000000000 +0200
25089 @@ -0,0 +1,556 @@
25090 +/*
25091 + *  linux/kernel/vserver/switch.c
25092 + *
25093 + *  Virtual Server: Syscall Switch
25094 + *
25095 + *  Copyright (C) 2003-2011  Herbert Pötzl
25096 + *
25097 + *  V0.01  syscall switch
25098 + *  V0.02  added signal to context
25099 + *  V0.03  added rlimit functions
25100 + *  V0.04  added iattr, task/xid functions
25101 + *  V0.05  added debug/history stuff
25102 + *  V0.06  added compat32 layer
25103 + *  V0.07  vcmd args and perms
25104 + *  V0.08  added status commands
25105 + *  V0.09  added tag commands
25106 + *  V0.10  added oom bias
25107 + *  V0.11  added device commands
25108 + *  V0.12  added warn mask
25109 + *
25110 + */
25111 +
25112 +#include <linux/vs_context.h>
25113 +#include <linux/vs_network.h>
25114 +#include <linux/vserver/switch.h>
25115 +
25116 +#include "vci_config.h"
25117 +
25118 +
25119 +static inline
25120 +int vc_get_version(uint32_t id)
25121 +{
25122 +       return VCI_VERSION;
25123 +}
25124 +
25125 +static inline
25126 +int vc_get_vci(uint32_t id)
25127 +{
25128 +       return vci_kernel_config();
25129 +}
25130 +
25131 +#include <linux/vserver/context_cmd.h>
25132 +#include <linux/vserver/cvirt_cmd.h>
25133 +#include <linux/vserver/cacct_cmd.h>
25134 +#include <linux/vserver/limit_cmd.h>
25135 +#include <linux/vserver/network_cmd.h>
25136 +#include <linux/vserver/sched_cmd.h>
25137 +#include <linux/vserver/debug_cmd.h>
25138 +#include <linux/vserver/inode_cmd.h>
25139 +#include <linux/vserver/dlimit_cmd.h>
25140 +#include <linux/vserver/signal_cmd.h>
25141 +#include <linux/vserver/space_cmd.h>
25142 +#include <linux/vserver/tag_cmd.h>
25143 +#include <linux/vserver/device_cmd.h>
25144 +
25145 +#include <linux/vserver/inode.h>
25146 +#include <linux/vserver/dlimit.h>
25147 +
25148 +
25149 +#ifdef CONFIG_COMPAT
25150 +#define __COMPAT(name, id, data, compat)       \
25151 +       (compat) ? name ## _x32(id, data) : name(id, data)
25152 +#define __COMPAT_NO_ID(name, data, compat)     \
25153 +       (compat) ? name ## _x32(data) : name(data)
25154 +#else
25155 +#define __COMPAT(name, id, data, compat)       \
25156 +       name(id, data)
25157 +#define __COMPAT_NO_ID(name, data, compat)     \
25158 +       name(data)
25159 +#endif
25160 +
25161 +
25162 +static inline
25163 +long do_vcmd(uint32_t cmd, uint32_t id,
25164 +       struct vx_info *vxi, struct nx_info *nxi,
25165 +       void __user *data, int compat)
25166 +{
25167 +       switch (cmd) {
25168 +
25169 +       case VCMD_get_version:
25170 +               return vc_get_version(id);
25171 +       case VCMD_get_vci:
25172 +               return vc_get_vci(id);
25173 +
25174 +       case VCMD_task_xid:
25175 +               return vc_task_xid(id);
25176 +       case VCMD_vx_info:
25177 +               return vc_vx_info(vxi, data);
25178 +
25179 +       case VCMD_task_nid:
25180 +               return vc_task_nid(id);
25181 +       case VCMD_nx_info:
25182 +               return vc_nx_info(nxi, data);
25183 +
25184 +       case VCMD_task_tag:
25185 +               return vc_task_tag(id);
25186 +
25187 +       case VCMD_set_space_v1:
25188 +               return vc_set_space_v1(vxi, data);
25189 +       /* this is version 2 */
25190 +       case VCMD_set_space:
25191 +               return vc_set_space(vxi, data);
25192 +
25193 +       case VCMD_get_space_mask_v0:
25194 +               return vc_get_space_mask(data, 0);
25195 +       /* this is version 1 */
25196 +       case VCMD_get_space_mask:
25197 +               return vc_get_space_mask(data, 1);
25198 +
25199 +       case VCMD_get_space_default:
25200 +               return vc_get_space_mask(data, -1);
25201 +
25202 +       case VCMD_set_umask:
25203 +               return vc_set_umask(vxi, data);
25204 +
25205 +       case VCMD_get_umask:
25206 +               return vc_get_umask(vxi, data);
25207 +
25208 +       case VCMD_set_wmask:
25209 +               return vc_set_wmask(vxi, data);
25210 +
25211 +       case VCMD_get_wmask:
25212 +               return vc_get_wmask(vxi, data);
25213 +#ifdef CONFIG_IA32_EMULATION
25214 +       case VCMD_get_rlimit:
25215 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25216 +       case VCMD_set_rlimit:
25217 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25218 +#else
25219 +       case VCMD_get_rlimit:
25220 +               return vc_get_rlimit(vxi, data);
25221 +       case VCMD_set_rlimit:
25222 +               return vc_set_rlimit(vxi, data);
25223 +#endif
25224 +       case VCMD_get_rlimit_mask:
25225 +               return vc_get_rlimit_mask(id, data);
25226 +       case VCMD_reset_hits:
25227 +               return vc_reset_hits(vxi, data);
25228 +       case VCMD_reset_minmax:
25229 +               return vc_reset_minmax(vxi, data);
25230 +
25231 +       case VCMD_get_vhi_name:
25232 +               return vc_get_vhi_name(vxi, data);
25233 +       case VCMD_set_vhi_name:
25234 +               return vc_set_vhi_name(vxi, data);
25235 +
25236 +       case VCMD_ctx_stat:
25237 +               return vc_ctx_stat(vxi, data);
25238 +       case VCMD_virt_stat:
25239 +               return vc_virt_stat(vxi, data);
25240 +       case VCMD_sock_stat:
25241 +               return vc_sock_stat(vxi, data);
25242 +       case VCMD_rlimit_stat:
25243 +               return vc_rlimit_stat(vxi, data);
25244 +
25245 +       case VCMD_set_cflags:
25246 +               return vc_set_cflags(vxi, data);
25247 +       case VCMD_get_cflags:
25248 +               return vc_get_cflags(vxi, data);
25249 +
25250 +       /* this is version 1 */
25251 +       case VCMD_set_ccaps:
25252 +               return vc_set_ccaps(vxi, data);
25253 +       /* this is version 1 */
25254 +       case VCMD_get_ccaps:
25255 +               return vc_get_ccaps(vxi, data);
25256 +       case VCMD_set_bcaps:
25257 +               return vc_set_bcaps(vxi, data);
25258 +       case VCMD_get_bcaps:
25259 +               return vc_get_bcaps(vxi, data);
25260 +
25261 +       case VCMD_set_badness:
25262 +               return vc_set_badness(vxi, data);
25263 +       case VCMD_get_badness:
25264 +               return vc_get_badness(vxi, data);
25265 +
25266 +       case VCMD_set_nflags:
25267 +               return vc_set_nflags(nxi, data);
25268 +       case VCMD_get_nflags:
25269 +               return vc_get_nflags(nxi, data);
25270 +
25271 +       case VCMD_set_ncaps:
25272 +               return vc_set_ncaps(nxi, data);
25273 +       case VCMD_get_ncaps:
25274 +               return vc_get_ncaps(nxi, data);
25275 +
25276 +       case VCMD_set_prio_bias:
25277 +               return vc_set_prio_bias(vxi, data);
25278 +       case VCMD_get_prio_bias:
25279 +               return vc_get_prio_bias(vxi, data);
25280 +       case VCMD_add_dlimit:
25281 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25282 +       case VCMD_rem_dlimit:
25283 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25284 +       case VCMD_set_dlimit:
25285 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25286 +       case VCMD_get_dlimit:
25287 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25288 +
25289 +       case VCMD_ctx_kill:
25290 +               return vc_ctx_kill(vxi, data);
25291 +
25292 +       case VCMD_wait_exit:
25293 +               return vc_wait_exit(vxi, data);
25294 +
25295 +       case VCMD_get_iattr:
25296 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25297 +       case VCMD_set_iattr:
25298 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25299 +
25300 +       case VCMD_fget_iattr:
25301 +               return vc_fget_iattr(id, data);
25302 +       case VCMD_fset_iattr:
25303 +               return vc_fset_iattr(id, data);
25304 +
25305 +       case VCMD_enter_space_v0:
25306 +               return vc_enter_space_v1(vxi, NULL);
25307 +       case VCMD_enter_space_v1:
25308 +               return vc_enter_space_v1(vxi, data);
25309 +       /* this is version 2 */
25310 +       case VCMD_enter_space:
25311 +               return vc_enter_space(vxi, data);
25312 +
25313 +       case VCMD_ctx_create_v0:
25314 +               return vc_ctx_create(id, NULL);
25315 +       case VCMD_ctx_create:
25316 +               return vc_ctx_create(id, data);
25317 +       case VCMD_ctx_migrate_v0:
25318 +               return vc_ctx_migrate(vxi, NULL);
25319 +       case VCMD_ctx_migrate:
25320 +               return vc_ctx_migrate(vxi, data);
25321 +
25322 +       case VCMD_net_create_v0:
25323 +               return vc_net_create(id, NULL);
25324 +       case VCMD_net_create:
25325 +               return vc_net_create(id, data);
25326 +       case VCMD_net_migrate:
25327 +               return vc_net_migrate(nxi, data);
25328 +
25329 +       case VCMD_tag_migrate:
25330 +               return vc_tag_migrate(id);
25331 +
25332 +       case VCMD_net_add:
25333 +               return vc_net_add(nxi, data);
25334 +       case VCMD_net_remove:
25335 +               return vc_net_remove(nxi, data);
25336 +
25337 +       case VCMD_net_add_ipv4_v1:
25338 +               return vc_net_add_ipv4_v1(nxi, data);
25339 +       /* this is version 2 */
25340 +       case VCMD_net_add_ipv4:
25341 +               return vc_net_add_ipv4(nxi, data);
25342 +
25343 +       case VCMD_net_rem_ipv4_v1:
25344 +               return vc_net_rem_ipv4_v1(nxi, data);
25345 +       /* this is version 2 */
25346 +       case VCMD_net_rem_ipv4:
25347 +               return vc_net_rem_ipv4(nxi, data);
25348 +#ifdef CONFIG_IPV6
25349 +       case VCMD_net_add_ipv6:
25350 +               return vc_net_add_ipv6(nxi, data);
25351 +       case VCMD_net_remove_ipv6:
25352 +               return vc_net_remove_ipv6(nxi, data);
25353 +#endif
25354 +/*     case VCMD_add_match_ipv4:
25355 +               return vc_add_match_ipv4(nxi, data);
25356 +       case VCMD_get_match_ipv4:
25357 +               return vc_get_match_ipv4(nxi, data);
25358 +#ifdef CONFIG_IPV6
25359 +       case VCMD_add_match_ipv6:
25360 +               return vc_add_match_ipv6(nxi, data);
25361 +       case VCMD_get_match_ipv6:
25362 +               return vc_get_match_ipv6(nxi, data);
25363 +#endif */
25364 +
25365 +#ifdef CONFIG_VSERVER_DEVICE
25366 +       case VCMD_set_mapping:
25367 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25368 +       case VCMD_unset_mapping:
25369 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25370 +#endif
25371 +#ifdef CONFIG_VSERVER_HISTORY
25372 +       case VCMD_dump_history:
25373 +               return vc_dump_history(id);
25374 +       case VCMD_read_history:
25375 +               return __COMPAT(vc_read_history, id, data, compat);
25376 +#endif
25377 +       default:
25378 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25379 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25380 +       }
25381 +       return -ENOSYS;
25382 +}
25383 +
25384 +
25385 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25386 +       case VCMD_ ## vcmd: perm = _perm;               \
25387 +               args = _args; flags = _flags; break
25388 +
25389 +
25390 +#define VCA_NONE       0x00
25391 +#define VCA_VXI                0x01
25392 +#define VCA_NXI                0x02
25393 +
25394 +#define VCF_NONE       0x00
25395 +#define VCF_INFO       0x01
25396 +#define VCF_ADMIN      0x02
25397 +#define VCF_ARES       0x06    /* includes admin */
25398 +#define VCF_SETUP      0x08
25399 +
25400 +#define VCF_ZIDOK      0x10    /* zero id okay */
25401 +
25402 +
25403 +static inline
25404 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25405 +{
25406 +       long ret;
25407 +       int permit = -1, state = 0;
25408 +       int perm = -1, args = 0, flags = 0;
25409 +       struct vx_info *vxi = NULL;
25410 +       struct nx_info *nxi = NULL;
25411 +
25412 +       switch (cmd) {
25413 +       /* unpriviledged commands */
25414 +       __VCMD(get_version,      0, VCA_NONE,   0);
25415 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25416 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25417 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25418 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25419 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25420 +
25421 +       /* info commands */
25422 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25423 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
25424 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25425 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25426 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25427 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25428 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25429 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
25430 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
25431 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25432 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25433 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25434 +
25435 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25436 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25437 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25438 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25439 +
25440 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25441 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25442 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25443 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25444 +
25445 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25446 +
25447 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25448 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25449 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25450 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
25451 +
25452 +       /* lower admin commands */
25453 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25454 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25455 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25456 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25457 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25458 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25459 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25460 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25461 +
25462 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25463 +       __VCMD(net_create,       5, VCA_NONE,   0);
25464 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25465 +
25466 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25467 +
25468 +       /* higher admin commands */
25469 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25470 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25471 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25472 +
25473 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25474 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25475 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25476 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25477 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25478 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25479 +
25480 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25481 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25482 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25483 +
25484 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25485 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25486 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25487 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25488 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25489 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25490 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25491 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25492 +#ifdef CONFIG_IPV6
25493 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25494 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25495 +#endif
25496 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25497 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25498 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25499 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25500 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25501 +
25502 +#ifdef CONFIG_VSERVER_DEVICE
25503 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25504 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25505 +#endif
25506 +       /* debug level admin commands */
25507 +#ifdef CONFIG_VSERVER_HISTORY
25508 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25509 +       __VCMD(read_history,     9, VCA_NONE,   0);
25510 +#endif
25511 +
25512 +       default:
25513 +               perm = -1;
25514 +       }
25515 +
25516 +       vxdprintk(VXD_CBIT(switch, 0),
25517 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25518 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25519 +               VC_VERSION(cmd), id, data, compat,
25520 +               perm, args, flags);
25521 +
25522 +       ret = -ENOSYS;
25523 +       if (perm < 0)
25524 +               goto out;
25525 +
25526 +       state = 1;
25527 +       if (!capable(CAP_CONTEXT))
25528 +               goto out;
25529 +
25530 +       state = 2;
25531 +       /* moved here from the individual commands */
25532 +       ret = -EPERM;
25533 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25534 +               goto out;
25535 +
25536 +       state = 3;
25537 +       /* vcmd involves resource management  */
25538 +       ret = -EPERM;
25539 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25540 +               goto out;
25541 +
25542 +       state = 4;
25543 +       /* various legacy exceptions */
25544 +       switch (cmd) {
25545 +       /* will go away when spectator is a cap */
25546 +       case VCMD_ctx_migrate_v0:
25547 +       case VCMD_ctx_migrate:
25548 +               if (id == 1) {
25549 +                       current->xid = 1;
25550 +                       ret = 1;
25551 +                       goto out;
25552 +               }
25553 +               break;
25554 +
25555 +       /* will go away when spectator is a cap */
25556 +       case VCMD_net_migrate:
25557 +               if (id == 1) {
25558 +                       current->nid = 1;
25559 +                       ret = 1;
25560 +                       goto out;
25561 +               }
25562 +               break;
25563 +       }
25564 +
25565 +       /* vcmds are fine by default */
25566 +       permit = 1;
25567 +
25568 +       /* admin type vcmds require admin ... */
25569 +       if (flags & VCF_ADMIN)
25570 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25571 +
25572 +       /* ... but setup type vcmds override that */
25573 +       if (!permit && (flags & VCF_SETUP))
25574 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25575 +
25576 +       state = 5;
25577 +       ret = -EPERM;
25578 +       if (!permit)
25579 +               goto out;
25580 +
25581 +       state = 6;
25582 +       if (!id && (flags & VCF_ZIDOK))
25583 +               goto skip_id;
25584 +
25585 +       ret = -ESRCH;
25586 +       if (args & VCA_VXI) {
25587 +               vxi = lookup_vx_info(id);
25588 +               if (!vxi)
25589 +                       goto out;
25590 +
25591 +               if ((flags & VCF_ADMIN) &&
25592 +                       /* special case kill for shutdown */
25593 +                       (cmd != VCMD_ctx_kill) &&
25594 +                       /* can context be administrated? */
25595 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25596 +                       ret = -EACCES;
25597 +                       goto out_vxi;
25598 +               }
25599 +       }
25600 +       state = 7;
25601 +       if (args & VCA_NXI) {
25602 +               nxi = lookup_nx_info(id);
25603 +               if (!nxi)
25604 +                       goto out_vxi;
25605 +
25606 +               if ((flags & VCF_ADMIN) &&
25607 +                       /* can context be administrated? */
25608 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25609 +                       ret = -EACCES;
25610 +                       goto out_nxi;
25611 +               }
25612 +       }
25613 +skip_id:
25614 +       state = 8;
25615 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25616 +
25617 +out_nxi:
25618 +       if ((args & VCA_NXI) && nxi)
25619 +               put_nx_info(nxi);
25620 +out_vxi:
25621 +       if ((args & VCA_VXI) && vxi)
25622 +               put_vx_info(vxi);
25623 +out:
25624 +       vxdprintk(VXD_CBIT(switch, 1),
25625 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25626 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25627 +               VC_VERSION(cmd), ret, ret, state, permit);
25628 +       return ret;
25629 +}
25630 +
25631 +asmlinkage long
25632 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25633 +{
25634 +       return do_vserver(cmd, id, data, 0);
25635 +}
25636 +
25637 +#ifdef CONFIG_COMPAT
25638 +
25639 +asmlinkage long
25640 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25641 +{
25642 +       return do_vserver(cmd, id, data, 1);
25643 +}
25644 +
25645 +#endif /* CONFIG_COMPAT */
25646 diff -NurpP --minimal linux-3.0.4/kernel/vserver/sysctl.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/sysctl.c
25647 --- linux-3.0.4/kernel/vserver/sysctl.c 1970-01-01 01:00:00.000000000 +0100
25648 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/sysctl.c 2011-06-10 22:11:24.000000000 +0200
25649 @@ -0,0 +1,241 @@
25650 +/*
25651 + *  kernel/vserver/sysctl.c
25652 + *
25653 + *  Virtual Context Support
25654 + *
25655 + *  Copyright (C) 2004-2007  Herbert Pötzl
25656 + *
25657 + *  V0.01  basic structure
25658 + *
25659 + */
25660 +
25661 +#include <linux/module.h>
25662 +#include <linux/ctype.h>
25663 +#include <linux/sysctl.h>
25664 +#include <linux/parser.h>
25665 +#include <asm/uaccess.h>
25666 +
25667 +enum {
25668 +       CTL_DEBUG_ERROR         = 0,
25669 +       CTL_DEBUG_SWITCH        = 1,
25670 +       CTL_DEBUG_XID,
25671 +       CTL_DEBUG_NID,
25672 +       CTL_DEBUG_TAG,
25673 +       CTL_DEBUG_NET,
25674 +       CTL_DEBUG_LIMIT,
25675 +       CTL_DEBUG_CRES,
25676 +       CTL_DEBUG_DLIM,
25677 +       CTL_DEBUG_QUOTA,
25678 +       CTL_DEBUG_CVIRT,
25679 +       CTL_DEBUG_SPACE,
25680 +       CTL_DEBUG_MISC,
25681 +};
25682 +
25683 +
25684 +unsigned int vx_debug_switch   = 0;
25685 +unsigned int vx_debug_xid      = 0;
25686 +unsigned int vx_debug_nid      = 0;
25687 +unsigned int vx_debug_tag      = 0;
25688 +unsigned int vx_debug_net      = 0;
25689 +unsigned int vx_debug_limit    = 0;
25690 +unsigned int vx_debug_cres     = 0;
25691 +unsigned int vx_debug_dlim     = 0;
25692 +unsigned int vx_debug_quota    = 0;
25693 +unsigned int vx_debug_cvirt    = 0;
25694 +unsigned int vx_debug_space    = 0;
25695 +unsigned int vx_debug_misc     = 0;
25696 +
25697 +
25698 +static struct ctl_table_header *vserver_table_header;
25699 +static ctl_table vserver_root_table[];
25700 +
25701 +
25702 +void vserver_register_sysctl(void)
25703 +{
25704 +       if (!vserver_table_header) {
25705 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25706 +       }
25707 +
25708 +}
25709 +
25710 +void vserver_unregister_sysctl(void)
25711 +{
25712 +       if (vserver_table_header) {
25713 +               unregister_sysctl_table(vserver_table_header);
25714 +               vserver_table_header = NULL;
25715 +       }
25716 +}
25717 +
25718 +
25719 +static int proc_dodebug(ctl_table *table, int write,
25720 +       void __user *buffer, size_t *lenp, loff_t *ppos)
25721 +{
25722 +       char            tmpbuf[20], *p, c;
25723 +       unsigned int    value;
25724 +       size_t          left, len;
25725 +
25726 +       if ((*ppos && !write) || !*lenp) {
25727 +               *lenp = 0;
25728 +               return 0;
25729 +       }
25730 +
25731 +       left = *lenp;
25732 +
25733 +       if (write) {
25734 +               if (!access_ok(VERIFY_READ, buffer, left))
25735 +                       return -EFAULT;
25736 +               p = (char *)buffer;
25737 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25738 +                       left--, p++;
25739 +               if (!left)
25740 +                       goto done;
25741 +
25742 +               if (left > sizeof(tmpbuf) - 1)
25743 +                       return -EINVAL;
25744 +               if (copy_from_user(tmpbuf, p, left))
25745 +                       return -EFAULT;
25746 +               tmpbuf[left] = '\0';
25747 +
25748 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25749 +                       value = 10 * value + (*p - '0');
25750 +               if (*p && !isspace(*p))
25751 +                       return -EINVAL;
25752 +               while (left && isspace(*p))
25753 +                       left--, p++;
25754 +               *(unsigned int *)table->data = value;
25755 +       } else {
25756 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25757 +                       return -EFAULT;
25758 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25759 +               if (len > left)
25760 +                       len = left;
25761 +               if (__copy_to_user(buffer, tmpbuf, len))
25762 +                       return -EFAULT;
25763 +               if ((left -= len) > 0) {
25764 +                       if (put_user('\n', (char *)buffer + len))
25765 +                               return -EFAULT;
25766 +                       left--;
25767 +               }
25768 +       }
25769 +
25770 +done:
25771 +       *lenp -= left;
25772 +       *ppos += *lenp;
25773 +       return 0;
25774 +}
25775 +
25776 +static int zero;
25777 +
25778 +#define        CTL_ENTRY(ctl, name)                            \
25779 +       {                                               \
25780 +               .procname       = #name,                \
25781 +               .data           = &vx_ ## name,         \
25782 +               .maxlen         = sizeof(int),          \
25783 +               .mode           = 0644,                 \
25784 +               .proc_handler   = &proc_dodebug,        \
25785 +               .extra1         = &zero,                \
25786 +               .extra2         = &zero,                \
25787 +       }
25788 +
25789 +static ctl_table vserver_debug_table[] = {
25790 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25791 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25792 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25793 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25794 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25795 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25796 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25797 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25798 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25799 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25800 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25801 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25802 +       { 0 }
25803 +};
25804 +
25805 +static ctl_table vserver_root_table[] = {
25806 +       {
25807 +               .procname       = "vserver",
25808 +               .mode           = 0555,
25809 +               .child          = vserver_debug_table
25810 +       },
25811 +       { 0 }
25812 +};
25813 +
25814 +
25815 +static match_table_t tokens = {
25816 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25817 +       { CTL_DEBUG_XID,        "xid=%x"        },
25818 +       { CTL_DEBUG_NID,        "nid=%x"        },
25819 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25820 +       { CTL_DEBUG_NET,        "net=%x"        },
25821 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25822 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25823 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25824 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25825 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25826 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25827 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25828 +       { CTL_DEBUG_ERROR,      NULL            }
25829 +};
25830 +
25831 +#define        HANDLE_CASE(id, name, val)                              \
25832 +       case CTL_DEBUG_ ## id:                                  \
25833 +               vx_debug_ ## name = val;                        \
25834 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25835 +               break
25836 +
25837 +
25838 +static int __init vs_debug_setup(char *str)
25839 +{
25840 +       char *p;
25841 +       int token;
25842 +
25843 +       printk("vs_debug_setup(%s)\n", str);
25844 +       while ((p = strsep(&str, ",")) != NULL) {
25845 +               substring_t args[MAX_OPT_ARGS];
25846 +               unsigned int value;
25847 +
25848 +               if (!*p)
25849 +                       continue;
25850 +
25851 +               token = match_token(p, tokens, args);
25852 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25853 +
25854 +               switch (token) {
25855 +               HANDLE_CASE(SWITCH, switch, value);
25856 +               HANDLE_CASE(XID,    xid,    value);
25857 +               HANDLE_CASE(NID,    nid,    value);
25858 +               HANDLE_CASE(TAG,    tag,    value);
25859 +               HANDLE_CASE(NET,    net,    value);
25860 +               HANDLE_CASE(LIMIT,  limit,  value);
25861 +               HANDLE_CASE(CRES,   cres,   value);
25862 +               HANDLE_CASE(DLIM,   dlim,   value);
25863 +               HANDLE_CASE(QUOTA,  quota,  value);
25864 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25865 +               HANDLE_CASE(SPACE,  space,  value);
25866 +               HANDLE_CASE(MISC,   misc,   value);
25867 +               default:
25868 +                       return -EINVAL;
25869 +                       break;
25870 +               }
25871 +       }
25872 +       return 1;
25873 +}
25874 +
25875 +__setup("vsdebug=", vs_debug_setup);
25876 +
25877 +
25878 +
25879 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25880 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25881 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25882 +EXPORT_SYMBOL_GPL(vx_debug_net);
25883 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25884 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25885 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25886 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25887 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25888 +EXPORT_SYMBOL_GPL(vx_debug_space);
25889 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25890 +
25891 diff -NurpP --minimal linux-3.0.4/kernel/vserver/tag.c linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/tag.c
25892 --- linux-3.0.4/kernel/vserver/tag.c    1970-01-01 01:00:00.000000000 +0100
25893 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/tag.c    2011-06-10 22:11:24.000000000 +0200
25894 @@ -0,0 +1,63 @@
25895 +/*
25896 + *  linux/kernel/vserver/tag.c
25897 + *
25898 + *  Virtual Server: Shallow Tag Space
25899 + *
25900 + *  Copyright (C) 2007  Herbert Pötzl
25901 + *
25902 + *  V0.01  basic implementation
25903 + *
25904 + */
25905 +
25906 +#include <linux/sched.h>
25907 +#include <linux/vserver/debug.h>
25908 +#include <linux/vs_pid.h>
25909 +#include <linux/vs_tag.h>
25910 +
25911 +#include <linux/vserver/tag_cmd.h>
25912 +
25913 +
25914 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25915 +{
25916 +       if (!p)
25917 +               BUG();
25918 +
25919 +       vxdprintk(VXD_CBIT(tag, 5),
25920 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25921 +
25922 +       task_lock(p);
25923 +       p->tag = tag;
25924 +       task_unlock(p);
25925 +
25926 +       vxdprintk(VXD_CBIT(tag, 5),
25927 +               "moved task %p into [#%d]", p, tag);
25928 +       return 0;
25929 +}
25930 +
25931 +/* vserver syscall commands below here */
25932 +
25933 +/* taks xid and vx_info functions */
25934 +
25935 +
25936 +int vc_task_tag(uint32_t id)
25937 +{
25938 +       tag_t tag;
25939 +
25940 +       if (id) {
25941 +               struct task_struct *tsk;
25942 +               rcu_read_lock();
25943 +               tsk = find_task_by_real_pid(id);
25944 +               tag = (tsk) ? tsk->tag : -ESRCH;
25945 +               rcu_read_unlock();
25946 +       } else
25947 +               tag = dx_current_tag();
25948 +       return tag;
25949 +}
25950 +
25951 +
25952 +int vc_tag_migrate(uint32_t tag)
25953 +{
25954 +       return dx_migrate_task(current, tag & 0xFFFF);
25955 +}
25956 +
25957 +
25958 diff -NurpP --minimal linux-3.0.4/kernel/vserver/vci_config.h linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/vci_config.h
25959 --- linux-3.0.4/kernel/vserver/vci_config.h     1970-01-01 01:00:00.000000000 +0100
25960 +++ linux-3.0.4-vs2.3.1-pre10.1/kernel/vserver/vci_config.h     2011-06-10 22:11:24.000000000 +0200
25961 @@ -0,0 +1,76 @@
25962 +
25963 +/*  interface version */
25964 +
25965 +#define VCI_VERSION            0x00020308
25966 +
25967 +
25968 +enum {
25969 +       VCI_KCBIT_NO_DYNAMIC = 0,
25970 +
25971 +       VCI_KCBIT_PROC_SECURE = 4,
25972 +       /* VCI_KCBIT_HARDCPU = 5, */
25973 +       /* VCI_KCBIT_IDLELIMIT = 6, */
25974 +       /* VCI_KCBIT_IDLETIME = 7, */
25975 +
25976 +       VCI_KCBIT_COWBL = 8,
25977 +       VCI_KCBIT_FULLCOWBL = 9,
25978 +       VCI_KCBIT_SPACES = 10,
25979 +       VCI_KCBIT_NETV2 = 11,
25980 +       VCI_KCBIT_MEMCG = 12,
25981 +
25982 +       VCI_KCBIT_DEBUG = 16,
25983 +       VCI_KCBIT_HISTORY = 20,
25984 +       VCI_KCBIT_TAGGED = 24,
25985 +       VCI_KCBIT_PPTAG = 28,
25986 +
25987 +       VCI_KCBIT_MORE = 31,
25988 +};
25989 +
25990 +
25991 +static inline uint32_t vci_kernel_config(void)
25992 +{
25993 +       return
25994 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25995 +
25996 +       /* configured features */
25997 +#ifdef CONFIG_VSERVER_PROC_SECURE
25998 +       (1 << VCI_KCBIT_PROC_SECURE) |
25999 +#endif
26000 +#ifdef CONFIG_VSERVER_COWBL
26001 +       (1 << VCI_KCBIT_COWBL) |
26002 +       (1 << VCI_KCBIT_FULLCOWBL) |
26003 +#endif
26004 +       (1 << VCI_KCBIT_SPACES) |
26005 +       (1 << VCI_KCBIT_NETV2) |
26006 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
26007 +       (1 << VCI_KCBIT_MEMCG) |
26008 +#endif
26009 +
26010 +       /* debug options */
26011 +#ifdef CONFIG_VSERVER_DEBUG
26012 +       (1 << VCI_KCBIT_DEBUG) |
26013 +#endif
26014 +#ifdef CONFIG_VSERVER_HISTORY
26015 +       (1 << VCI_KCBIT_HISTORY) |
26016 +#endif
26017 +
26018 +       /* inode context tagging */
26019 +#if    defined(CONFIG_TAGGING_NONE)
26020 +       (0 << VCI_KCBIT_TAGGED) |
26021 +#elif  defined(CONFIG_TAGGING_UID16)
26022 +       (1 << VCI_KCBIT_TAGGED) |
26023 +#elif  defined(CONFIG_TAGGING_GID16)
26024 +       (2 << VCI_KCBIT_TAGGED) |
26025 +#elif  defined(CONFIG_TAGGING_ID24)
26026 +       (3 << VCI_KCBIT_TAGGED) |
26027 +#elif  defined(CONFIG_TAGGING_INTERN)
26028 +       (4 << VCI_KCBIT_TAGGED) |
26029 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26030 +       (5 << VCI_KCBIT_TAGGED) |
26031 +#else
26032 +       (7 << VCI_KCBIT_TAGGED) |
26033 +#endif
26034 +       (1 << VCI_KCBIT_PPTAG) |
26035 +       0;
26036 +}
26037 +
26038 diff -NurpP --minimal linux-3.0.4/mm/filemap_xip.c linux-3.0.4-vs2.3.1-pre10.1/mm/filemap_xip.c
26039 --- linux-3.0.4/mm/filemap_xip.c        2011-07-22 11:18:12.000000000 +0200
26040 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/filemap_xip.c        2011-06-10 22:11:24.000000000 +0200
26041 @@ -18,6 +18,7 @@
26042  #include <linux/seqlock.h>
26043  #include <linux/mutex.h>
26044  #include <linux/gfp.h>
26045 +#include <linux/vs_memory.h>
26046  #include <asm/tlbflush.h>
26047  #include <asm/io.h>
26048  
26049 diff -NurpP --minimal linux-3.0.4/mm/fremap.c linux-3.0.4-vs2.3.1-pre10.1/mm/fremap.c
26050 --- linux-3.0.4/mm/fremap.c     2011-07-22 11:18:12.000000000 +0200
26051 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/fremap.c     2011-06-10 22:11:24.000000000 +0200
26052 @@ -16,6 +16,7 @@
26053  #include <linux/module.h>
26054  #include <linux/syscalls.h>
26055  #include <linux/mmu_notifier.h>
26056 +#include <linux/vs_memory.h>
26057  
26058  #include <asm/mmu_context.h>
26059  #include <asm/cacheflush.h>
26060 diff -NurpP --minimal linux-3.0.4/mm/hugetlb.c linux-3.0.4-vs2.3.1-pre10.1/mm/hugetlb.c
26061 --- linux-3.0.4/mm/hugetlb.c    2011-07-22 11:18:12.000000000 +0200
26062 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/hugetlb.c    2011-06-22 12:39:16.000000000 +0200
26063 @@ -28,6 +28,7 @@
26064  
26065  #include <linux/hugetlb.h>
26066  #include <linux/node.h>
26067 +#include <linux/vs_memory.h>
26068  #include "internal.h"
26069  
26070  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26071 diff -NurpP --minimal linux-3.0.4/mm/memcontrol.c linux-3.0.4-vs2.3.1-pre10.1/mm/memcontrol.c
26072 --- linux-3.0.4/mm/memcontrol.c 2011-08-31 18:56:42.000000000 +0200
26073 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/memcontrol.c 2011-08-08 23:04:47.000000000 +0200
26074 @@ -741,6 +741,31 @@ struct mem_cgroup *mem_cgroup_from_task(
26075                                 struct mem_cgroup, css);
26076  }
26077  
26078 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
26079 +{
26080 +       return res_counter_read_u64(&mem->res, member);
26081 +}
26082 +
26083 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
26084 +{
26085 +       return res_counter_read_u64(&mem->memsw, member);
26086 +}
26087 +
26088 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
26089 +{
26090 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
26091 +}
26092 +
26093 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
26094 +{
26095 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
26096 +}
26097 +
26098 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
26099 +{
26100 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
26101 +}
26102 +
26103  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
26104  {
26105         struct mem_cgroup *mem = NULL;
26106 diff -NurpP --minimal linux-3.0.4/mm/memory.c linux-3.0.4-vs2.3.1-pre10.1/mm/memory.c
26107 --- linux-3.0.4/mm/memory.c     2011-08-31 18:56:42.000000000 +0200
26108 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/memory.c     2011-08-08 23:04:47.000000000 +0200
26109 @@ -3388,6 +3388,7 @@ int handle_pte_fault(struct mm_struct *m
26110  {
26111         pte_t entry;
26112         spinlock_t *ptl;
26113 +       int ret = 0, type = VXPT_UNKNOWN;
26114  
26115         entry = *pte;
26116         if (!pte_present(entry)) {
26117 @@ -3412,9 +3413,12 @@ int handle_pte_fault(struct mm_struct *m
26118         if (unlikely(!pte_same(*pte, entry)))
26119                 goto unlock;
26120         if (flags & FAULT_FLAG_WRITE) {
26121 -               if (!pte_write(entry))
26122 -                       return do_wp_page(mm, vma, address,
26123 +               if (!pte_write(entry)) {
26124 +                       ret = do_wp_page(mm, vma, address,
26125                                         pte, pmd, ptl, entry);
26126 +                       type = VXPT_WRITE;
26127 +                       goto out;
26128 +               }
26129                 entry = pte_mkdirty(entry);
26130         }
26131         entry = pte_mkyoung(entry);
26132 @@ -3432,7 +3436,10 @@ int handle_pte_fault(struct mm_struct *m
26133         }
26134  unlock:
26135         pte_unmap_unlock(pte, ptl);
26136 -       return 0;
26137 +       ret = 0;
26138 +out:
26139 +       vx_page_fault(mm, vma, type, ret);
26140 +       return ret;
26141  }
26142  
26143  /*
26144 diff -NurpP --minimal linux-3.0.4/mm/mremap.c linux-3.0.4-vs2.3.1-pre10.1/mm/mremap.c
26145 --- linux-3.0.4/mm/mremap.c     2011-07-22 11:18:12.000000000 +0200
26146 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/mremap.c     2011-06-10 22:11:24.000000000 +0200
26147 @@ -19,6 +19,7 @@
26148  #include <linux/security.h>
26149  #include <linux/syscalls.h>
26150  #include <linux/mmu_notifier.h>
26151 +#include <linux/vs_memory.h>
26152  
26153  #include <asm/uaccess.h>
26154  #include <asm/cacheflush.h>
26155 diff -NurpP --minimal linux-3.0.4/mm/oom_kill.c linux-3.0.4-vs2.3.1-pre10.1/mm/oom_kill.c
26156 --- linux-3.0.4/mm/oom_kill.c   2011-08-31 18:56:42.000000000 +0200
26157 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/oom_kill.c   2011-08-08 23:04:47.000000000 +0200
26158 @@ -32,6 +32,9 @@
26159  #include <linux/mempolicy.h>
26160  #include <linux/security.h>
26161  #include <linux/ptrace.h>
26162 +#include <linux/reboot.h>
26163 +#include <linux/vs_memory.h>
26164 +#include <linux/vs_context.h>
26165  
26166  int sysctl_panic_on_oom;
26167  int sysctl_oom_kill_allocating_task;
26168 @@ -134,11 +137,18 @@ struct task_struct *find_lock_task_mm(st
26169  static bool oom_unkillable_task(struct task_struct *p,
26170                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
26171  {
26172 -       if (is_global_init(p))
26173 +       unsigned xid = vx_current_xid();
26174 +
26175 +       /* skip the init task, global and per guest */
26176 +       if (task_is_init(p))
26177                 return true;
26178         if (p->flags & PF_KTHREAD)
26179                 return true;
26180  
26181 +       /* skip other guest and host processes if oom in guest */
26182 +       if (xid && vx_task_xid(p) != xid)
26183 +               return true;
26184 +
26185         /* When mem_cgroup_out_of_memory() and p is not member of the group */
26186         if (mem && !task_in_mem_cgroup(p, mem))
26187                 return true;
26188 @@ -214,6 +224,18 @@ unsigned int oom_badness(struct task_str
26189         points += p->signal->oom_score_adj;
26190  
26191         /*
26192 +        * add points for context badness and
26193 +        * reduce badness for processes belonging to
26194 +        * a different context
26195 +        */
26196 +
26197 +       points += vx_badness(p, p->mm);
26198 +
26199 +       if ((vx_current_xid() > 1) &&
26200 +               vx_current_xid() != vx_task_xid(p))
26201 +               points /= 16;
26202 +
26203 +       /*
26204          * Never return 0 for an eligible task that may be killed since it's
26205          * possible that no single user task uses more than 0.1% of memory and
26206          * no single admin tasks uses more than 3.0%.
26207 @@ -429,8 +451,8 @@ static int oom_kill_task(struct task_str
26208         /* mm cannot be safely dereferenced after task_unlock(p) */
26209         mm = p->mm;
26210  
26211 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
26212 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
26213 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
26214 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
26215                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
26216                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
26217         task_unlock(p);
26218 @@ -484,8 +506,8 @@ static int oom_kill_process(struct task_
26219         }
26220  
26221         task_lock(p);
26222 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
26223 -               message, task_pid_nr(p), p->comm, points);
26224 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
26225 +               message, task_pid_nr(p), p->xid, p->comm, points);
26226         task_unlock(p);
26227  
26228         /*
26229 @@ -586,6 +608,8 @@ int unregister_oom_notifier(struct notif
26230  }
26231  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
26232  
26233 +long vs_oom_action(unsigned int);
26234 +
26235  /*
26236   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
26237   * if a parallel OOM killing is already taking place that includes a zone in
26238 @@ -744,7 +768,12 @@ retry:
26239         if (!p) {
26240                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
26241                 read_unlock(&tasklist_lock);
26242 -               panic("Out of memory and no killable processes...\n");
26243 +
26244 +               /* avoid panic for guest OOM */
26245 +               if (current->xid)
26246 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
26247 +               else
26248 +                       panic("Out of memory and no killable processes...\n");
26249         }
26250  
26251         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
26252 diff -NurpP --minimal linux-3.0.4/mm/page_alloc.c linux-3.0.4-vs2.3.1-pre10.1/mm/page_alloc.c
26253 --- linux-3.0.4/mm/page_alloc.c 2011-07-22 11:18:12.000000000 +0200
26254 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/page_alloc.c 2011-06-10 22:24:12.000000000 +0200
26255 @@ -57,6 +57,8 @@
26256  #include <linux/ftrace_event.h>
26257  #include <linux/memcontrol.h>
26258  #include <linux/prefetch.h>
26259 +#include <linux/vs_base.h>
26260 +#include <linux/vs_limit.h>
26261  
26262  #include <asm/tlbflush.h>
26263  #include <asm/div64.h>
26264 @@ -2470,6 +2472,9 @@ void si_meminfo(struct sysinfo *val)
26265         val->totalhigh = totalhigh_pages;
26266         val->freehigh = nr_free_highpages();
26267         val->mem_unit = PAGE_SIZE;
26268 +
26269 +       if (vx_flags(VXF_VIRT_MEM, 0))
26270 +               vx_vsi_meminfo(val);
26271  }
26272  
26273  EXPORT_SYMBOL(si_meminfo);
26274 @@ -2490,6 +2495,9 @@ void si_meminfo_node(struct sysinfo *val
26275         val->freehigh = 0;
26276  #endif
26277         val->mem_unit = PAGE_SIZE;
26278 +
26279 +       if (vx_flags(VXF_VIRT_MEM, 0))
26280 +               vx_vsi_meminfo(val);
26281  }
26282  #endif
26283  
26284 diff -NurpP --minimal linux-3.0.4/mm/pgtable-generic.c linux-3.0.4-vs2.3.1-pre10.1/mm/pgtable-generic.c
26285 --- linux-3.0.4/mm/pgtable-generic.c    2011-03-15 18:07:42.000000000 +0100
26286 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/pgtable-generic.c    2011-06-10 22:11:24.000000000 +0200
26287 @@ -6,6 +6,8 @@
26288   *  Copyright (C) 2010  Linus Torvalds
26289   */
26290  
26291 +#include <linux/mm.h>
26292 +
26293  #include <linux/pagemap.h>
26294  #include <asm/tlb.h>
26295  #include <asm-generic/pgtable.h>
26296 diff -NurpP --minimal linux-3.0.4/mm/rmap.c linux-3.0.4-vs2.3.1-pre10.1/mm/rmap.c
26297 --- linux-3.0.4/mm/rmap.c       2011-07-22 11:18:12.000000000 +0200
26298 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/rmap.c       2011-07-01 11:35:35.000000000 +0200
26299 @@ -57,6 +57,7 @@
26300  #include <linux/mmu_notifier.h>
26301  #include <linux/migrate.h>
26302  #include <linux/hugetlb.h>
26303 +#include <linux/vs_memory.h>
26304  
26305  #include <asm/tlbflush.h>
26306  
26307 diff -NurpP --minimal linux-3.0.4/mm/shmem.c linux-3.0.4-vs2.3.1-pre10.1/mm/shmem.c
26308 --- linux-3.0.4/mm/shmem.c      2011-07-22 11:18:12.000000000 +0200
26309 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/shmem.c      2011-07-01 11:35:35.000000000 +0200
26310 @@ -1850,7 +1850,7 @@ static int shmem_statfs(struct dentry *d
26311  {
26312         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26313  
26314 -       buf->f_type = TMPFS_MAGIC;
26315 +       buf->f_type = TMPFS_SUPER_MAGIC;
26316         buf->f_bsize = PAGE_CACHE_SIZE;
26317         buf->f_namelen = NAME_MAX;
26318         if (sbinfo->max_blocks) {
26319 @@ -2605,7 +2605,7 @@ int shmem_fill_super(struct super_block 
26320         sb->s_maxbytes = SHMEM_MAX_BYTES;
26321         sb->s_blocksize = PAGE_CACHE_SIZE;
26322         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26323 -       sb->s_magic = TMPFS_MAGIC;
26324 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26325         sb->s_op = &shmem_ops;
26326         sb->s_time_gran = 1;
26327  #ifdef CONFIG_TMPFS_XATTR
26328 diff -NurpP --minimal linux-3.0.4/mm/slab.c linux-3.0.4-vs2.3.1-pre10.1/mm/slab.c
26329 --- linux-3.0.4/mm/slab.c       2011-07-22 11:18:12.000000000 +0200
26330 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/slab.c       2011-06-15 02:41:23.000000000 +0200
26331 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
26332  #define STATS_INC_FREEMISS(x)  do { } while (0)
26333  #endif
26334  
26335 +#include "slab_vs.h"
26336 +
26337  #if DEBUG
26338  
26339  /*
26340 @@ -3348,6 +3350,7 @@ retry:
26341  
26342         obj = slab_get_obj(cachep, slabp, nodeid);
26343         check_slabp(cachep, slabp);
26344 +       vx_slab_alloc(cachep, flags);
26345         l3->free_objects--;
26346         /* move slabp to correct slabp list: */
26347         list_del(&slabp->list);
26348 @@ -3425,6 +3428,7 @@ __cache_alloc_node(struct kmem_cache *ca
26349         /* ___cache_alloc_node can fall back to other nodes */
26350         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26351    out:
26352 +       vx_slab_alloc(cachep, flags);
26353         local_irq_restore(save_flags);
26354         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26355         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
26356 @@ -3612,6 +3616,7 @@ static inline void __cache_free(struct k
26357         check_irq_off();
26358         kmemleak_free_recursive(objp, cachep->flags);
26359         objp = cache_free_debugcheck(cachep, objp, caller);
26360 +       vx_slab_free(cachep);
26361  
26362         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
26363  
26364 diff -NurpP --minimal linux-3.0.4/mm/slab_vs.h linux-3.0.4-vs2.3.1-pre10.1/mm/slab_vs.h
26365 --- linux-3.0.4/mm/slab_vs.h    1970-01-01 01:00:00.000000000 +0100
26366 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/slab_vs.h    2011-06-10 22:11:24.000000000 +0200
26367 @@ -0,0 +1,29 @@
26368 +
26369 +#include <linux/vserver/context.h>
26370 +
26371 +#include <linux/vs_context.h>
26372 +
26373 +static inline
26374 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26375 +{
26376 +       int what = gfp_zone(cachep->gfpflags);
26377 +       struct vx_info *vxi = current_vx_info();
26378 +
26379 +       if (!vxi)
26380 +               return;
26381 +
26382 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
26383 +}
26384 +
26385 +static inline
26386 +void vx_slab_free(struct kmem_cache *cachep)
26387 +{
26388 +       int what = gfp_zone(cachep->gfpflags);
26389 +       struct vx_info *vxi = current_vx_info();
26390 +
26391 +       if (!vxi)
26392 +               return;
26393 +
26394 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
26395 +}
26396 +
26397 diff -NurpP --minimal linux-3.0.4/mm/swapfile.c linux-3.0.4-vs2.3.1-pre10.1/mm/swapfile.c
26398 --- linux-3.0.4/mm/swapfile.c   2011-07-22 11:18:12.000000000 +0200
26399 +++ linux-3.0.4-vs2.3.1-pre10.1/mm/swapfile.c   2011-07-01 11:35:35.000000000 +0200
26400 @@ -37,6 +37,8 @@
26401  #include <asm/tlbflush.h>
26402  #include <linux/swapops.h>
26403  #include <linux/page_cgroup.h>
26404 +#include <linux/vs_base.h>
26405 +#include <linux/vs_memory.h>
26406  
26407  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
26408                                  unsigned char);
26409 @@ -1759,6 +1761,16 @@ static int swap_show(struct seq_file *sw
26410  
26411         if (si == SEQ_START_TOKEN) {
26412                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
26413 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
26414 +                       struct sysinfo si;
26415 +
26416 +                       vx_vsi_swapinfo(&si);
26417 +                       if (si.totalswap < (1 << 10))
26418 +                               return 0;
26419 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
26420 +                               "hdv0", "partition", si.totalswap >> 10,
26421 +                               (si.totalswap - si.freeswap) >> 10, -1);
26422 +               }
26423                 return 0;
26424         }
26425  
26426 @@ -2186,6 +2198,8 @@ void si_swapinfo(struct sysinfo *val)
26427         val->freeswap = nr_swap_pages + nr_to_be_unused;
26428         val->totalswap = total_swap_pages + nr_to_be_unused;
26429         spin_unlock(&swap_lock);
26430 +       if (vx_flags(VXF_VIRT_MEM, 0))
26431 +               vx_vsi_swapinfo(val);
26432  }
26433  
26434  /*
26435 diff -NurpP --minimal linux-3.0.4/net/bridge/br_multicast.c linux-3.0.4-vs2.3.1-pre10.1/net/bridge/br_multicast.c
26436 --- linux-3.0.4/net/bridge/br_multicast.c       2011-07-22 11:18:12.000000000 +0200
26437 +++ linux-3.0.4-vs2.3.1-pre10.1/net/bridge/br_multicast.c       2011-07-19 00:44:39.000000000 +0200
26438 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
26439         ip6h->hop_limit = 1;
26440         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
26441         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
26442 -                          &ip6h->saddr);
26443 +                          &ip6h->saddr, NULL);
26444         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
26445  
26446         hopopt = (u8 *)(ip6h + 1);
26447 diff -NurpP --minimal linux-3.0.4/net/core/dev.c linux-3.0.4-vs2.3.1-pre10.1/net/core/dev.c
26448 --- linux-3.0.4/net/core/dev.c  2011-07-22 11:18:13.000000000 +0200
26449 +++ linux-3.0.4-vs2.3.1-pre10.1/net/core/dev.c  2011-06-15 02:40:14.000000000 +0200
26450 @@ -127,6 +127,7 @@
26451  #include <linux/in.h>
26452  #include <linux/jhash.h>
26453  #include <linux/random.h>
26454 +#include <linux/vs_inet.h>
26455  #include <trace/events/napi.h>
26456  #include <trace/events/net.h>
26457  #include <trace/events/skb.h>
26458 @@ -609,7 +610,8 @@ struct net_device *__dev_get_by_name(str
26459         struct hlist_head *head = dev_name_hash(net, name);
26460  
26461         hlist_for_each_entry(dev, p, head, name_hlist)
26462 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26463 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26464 +                   nx_dev_visible(current_nx_info(), dev))
26465                         return dev;
26466  
26467         return NULL;
26468 @@ -635,7 +637,8 @@ struct net_device *dev_get_by_name_rcu(s
26469         struct hlist_head *head = dev_name_hash(net, name);
26470  
26471         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
26472 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26473 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26474 +                   nx_dev_visible(current_nx_info(), dev))
26475                         return dev;
26476  
26477         return NULL;
26478 @@ -686,7 +689,8 @@ struct net_device *__dev_get_by_index(st
26479         struct hlist_head *head = dev_index_hash(net, ifindex);
26480  
26481         hlist_for_each_entry(dev, p, head, index_hlist)
26482 -               if (dev->ifindex == ifindex)
26483 +               if ((dev->ifindex == ifindex) &&
26484 +                   nx_dev_visible(current_nx_info(), dev))
26485                         return dev;
26486  
26487         return NULL;
26488 @@ -711,7 +715,8 @@ struct net_device *dev_get_by_index_rcu(
26489         struct hlist_head *head = dev_index_hash(net, ifindex);
26490  
26491         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
26492 -               if (dev->ifindex == ifindex)
26493 +               if ((dev->ifindex == ifindex) &&
26494 +                   nx_dev_visible(current_nx_info(), dev))
26495                         return dev;
26496  
26497         return NULL;
26498 @@ -764,7 +769,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
26499  
26500         for_each_netdev_rcu(net, dev)
26501                 if (dev->type == type &&
26502 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
26503 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
26504 +                   nx_dev_visible(current_nx_info(), dev))
26505                         return dev;
26506  
26507         return NULL;
26508 @@ -776,9 +782,11 @@ struct net_device *__dev_getfirstbyhwtyp
26509         struct net_device *dev;
26510  
26511         ASSERT_RTNL();
26512 -       for_each_netdev(net, dev)
26513 -               if (dev->type == type)
26514 +       for_each_netdev(net, dev) {
26515 +               if ((dev->type == type) &&
26516 +                   nx_dev_visible(current_nx_info(), dev))
26517                         return dev;
26518 +       }
26519  
26520         return NULL;
26521  }
26522 @@ -896,6 +904,8 @@ static int __dev_alloc_name(struct net *
26523                                 continue;
26524                         if (i < 0 || i >= max_netdevices)
26525                                 continue;
26526 +                       if (!nx_dev_visible(current_nx_info(), d))
26527 +                               continue;
26528  
26529                         /*  avoid cases where sscanf is not exact inverse of printf */
26530                         snprintf(buf, IFNAMSIZ, name, i);
26531 @@ -3937,6 +3947,8 @@ static int dev_ifconf(struct net *net, c
26532  
26533         total = 0;
26534         for_each_netdev(net, dev) {
26535 +               if (!nx_dev_visible(current_nx_info(), dev))
26536 +                       continue;
26537                 for (i = 0; i < NPROTO; i++) {
26538                         if (gifconf_list[i]) {
26539                                 int done;
26540 @@ -4011,6 +4023,10 @@ static void dev_seq_printf_stats(struct 
26541         struct rtnl_link_stats64 temp;
26542         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
26543  
26544 +       /* device visible inside network context? */
26545 +       if (!nx_dev_visible(current_nx_info(), dev))
26546 +               return;
26547 +
26548         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
26549                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
26550                    dev->name, stats->rx_bytes, stats->rx_packets,
26551 diff -NurpP --minimal linux-3.0.4/net/core/rtnetlink.c linux-3.0.4-vs2.3.1-pre10.1/net/core/rtnetlink.c
26552 --- linux-3.0.4/net/core/rtnetlink.c    2011-07-22 11:18:13.000000000 +0200
26553 +++ linux-3.0.4-vs2.3.1-pre10.1/net/core/rtnetlink.c    2011-06-10 22:11:24.000000000 +0200
26554 @@ -1015,6 +1015,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26555                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
26556                         if (idx < s_idx)
26557                                 goto cont;
26558 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26559 +                               continue;
26560                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26561                                              NETLINK_CB(cb->skb).pid,
26562                                              cb->nlh->nlmsg_seq, 0,
26563 @@ -1848,6 +1850,9 @@ void rtmsg_ifinfo(int type, struct net_d
26564         struct sk_buff *skb;
26565         int err = -ENOBUFS;
26566  
26567 +       if (!nx_dev_visible(current_nx_info(), dev))
26568 +               return;
26569 +
26570         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26571         if (skb == NULL)
26572                 goto errout;
26573 diff -NurpP --minimal linux-3.0.4/net/core/sock.c linux-3.0.4-vs2.3.1-pre10.1/net/core/sock.c
26574 --- linux-3.0.4/net/core/sock.c 2011-05-22 16:18:00.000000000 +0200
26575 +++ linux-3.0.4-vs2.3.1-pre10.1/net/core/sock.c 2011-06-10 22:11:24.000000000 +0200
26576 @@ -127,6 +127,10 @@
26577  #include <net/cls_cgroup.h>
26578  
26579  #include <linux/filter.h>
26580 +#include <linux/vs_socket.h>
26581 +#include <linux/vs_limit.h>
26582 +#include <linux/vs_context.h>
26583 +#include <linux/vs_network.h>
26584  
26585  #ifdef CONFIG_INET
26586  #include <net/tcp.h>
26587 @@ -1070,6 +1074,8 @@ static struct sock *sk_prot_alloc(struct
26588                         goto out_free_sec;
26589                 sk_tx_queue_clear(sk);
26590         }
26591 +               sock_vx_init(sk);
26592 +               sock_nx_init(sk);
26593  
26594         return sk;
26595  
26596 @@ -1169,6 +1175,11 @@ static void __sk_free(struct sock *sk)
26597                 put_cred(sk->sk_peer_cred);
26598         put_pid(sk->sk_peer_pid);
26599         put_net(sock_net(sk));
26600 +       vx_sock_dec(sk);
26601 +       clr_vx_info(&sk->sk_vx_info);
26602 +       sk->sk_xid = -1;
26603 +       clr_nx_info(&sk->sk_nx_info);
26604 +       sk->sk_nid = -1;
26605         sk_prot_free(sk->sk_prot_creator, sk);
26606  }
26607  
26608 @@ -1216,6 +1227,8 @@ struct sock *sk_clone(const struct sock 
26609  
26610                 /* SANITY */
26611                 get_net(sock_net(newsk));
26612 +               sock_vx_init(newsk);
26613 +               sock_nx_init(newsk);
26614                 sk_node_init(&newsk->sk_node);
26615                 sock_lock_init(newsk);
26616                 bh_lock_sock(newsk);
26617 @@ -1271,6 +1284,12 @@ struct sock *sk_clone(const struct sock 
26618                 smp_wmb();
26619                 atomic_set(&newsk->sk_refcnt, 2);
26620  
26621 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26622 +               newsk->sk_xid = sk->sk_xid;
26623 +               vx_sock_inc(newsk);
26624 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26625 +               newsk->sk_nid = sk->sk_nid;
26626 +
26627                 /*
26628                  * Increment the counter in the same struct proto as the master
26629                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26630 @@ -2017,6 +2036,12 @@ void sock_init_data(struct socket *sock,
26631  
26632         sk->sk_stamp = ktime_set(-1L, 0);
26633  
26634 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
26635 +       sk->sk_xid = vx_current_xid();
26636 +       vx_sock_inc(sk);
26637 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
26638 +       sk->sk_nid = nx_current_nid();
26639 +
26640         /*
26641          * Before updating sk_refcnt, we must commit prior changes to memory
26642          * (Documentation/RCU/rculist_nulls.txt for details)
26643 diff -NurpP --minimal linux-3.0.4/net/ipv4/af_inet.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/af_inet.c
26644 --- linux-3.0.4/net/ipv4/af_inet.c      2011-07-22 11:18:13.000000000 +0200
26645 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/af_inet.c      2011-07-19 00:44:39.000000000 +0200
26646 @@ -117,6 +117,7 @@
26647  #ifdef CONFIG_IP_MROUTE
26648  #include <linux/mroute.h>
26649  #endif
26650 +#include <linux/vs_limit.h>
26651  
26652  
26653  /* The inetsw table contains everything that inet_create needs to
26654 @@ -326,9 +327,13 @@ lookup_protocol:
26655         }
26656  
26657         err = -EPERM;
26658 +       if ((protocol == IPPROTO_ICMP) &&
26659 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
26660 +               goto override;
26661 +
26662         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
26663                 goto out_rcu_unlock;
26664 -
26665 +override:
26666         err = -EAFNOSUPPORT;
26667         if (!inet_netns_ok(net, protocol))
26668                 goto out_rcu_unlock;
26669 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
26670         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26671         struct sock *sk = sock->sk;
26672         struct inet_sock *inet = inet_sk(sk);
26673 +       struct nx_v4_sock_addr nsa;
26674         unsigned short snum;
26675         int chk_addr_ret;
26676         int err;
26677 @@ -470,7 +476,11 @@ int inet_bind(struct socket *sock, struc
26678                 goto out;
26679         }
26680  
26681 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26682 +       err = v4_map_sock_addr(inet, addr, &nsa);
26683 +       if (err)
26684 +               goto out;
26685 +
26686 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26687  
26688         /* Not specified by any standard per-se, however it breaks too
26689          * many applications when removed.  It is unfortunate since
26690 @@ -482,7 +492,7 @@ int inet_bind(struct socket *sock, struc
26691         err = -EADDRNOTAVAIL;
26692         if (!sysctl_ip_nonlocal_bind &&
26693             !(inet->freebind || inet->transparent) &&
26694 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26695 +           nsa.saddr != htonl(INADDR_ANY) &&
26696             chk_addr_ret != RTN_LOCAL &&
26697             chk_addr_ret != RTN_MULTICAST &&
26698             chk_addr_ret != RTN_BROADCAST)
26699 @@ -507,7 +517,7 @@ int inet_bind(struct socket *sock, struc
26700         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
26701                 goto out_release_sock;
26702  
26703 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
26704 +       v4_set_sock_addr(inet, &nsa);
26705         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26706                 inet->inet_saddr = 0;  /* Use device */
26707  
26708 @@ -710,11 +720,13 @@ int inet_getname(struct socket *sock, st
26709                      peer == 1))
26710                         return -ENOTCONN;
26711                 sin->sin_port = inet->inet_dport;
26712 -               sin->sin_addr.s_addr = inet->inet_daddr;
26713 +               sin->sin_addr.s_addr =
26714 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
26715         } else {
26716                 __be32 addr = inet->inet_rcv_saddr;
26717                 if (!addr)
26718                         addr = inet->inet_saddr;
26719 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26720                 sin->sin_port = inet->inet_sport;
26721                 sin->sin_addr.s_addr = addr;
26722         }
26723 diff -NurpP --minimal linux-3.0.4/net/ipv4/arp.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/arp.c
26724 --- linux-3.0.4/net/ipv4/arp.c  2011-05-22 16:18:00.000000000 +0200
26725 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/arp.c  2011-08-29 05:14:51.000000000 +0200
26726 @@ -1365,6 +1365,7 @@ static void arp_format_neigh_entry(struc
26727         struct net_device *dev = n->dev;
26728         int hatype = dev->type;
26729  
26730 +       /* FIXME: check for network context */
26731         read_lock(&n->lock);
26732         /* Convert hardware address to XX:XX:XX:XX ... form. */
26733  #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
26734 @@ -1396,6 +1397,7 @@ static void arp_format_pneigh_entry(stru
26735         int hatype = dev ? dev->type : 0;
26736         char tbuf[16];
26737  
26738 +       /* FIXME: check for network context */
26739         sprintf(tbuf, "%pI4", n->key);
26740         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
26741                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
26742 diff -NurpP --minimal linux-3.0.4/net/ipv4/devinet.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/devinet.c
26743 --- linux-3.0.4/net/ipv4/devinet.c      2011-08-31 18:56:42.000000000 +0200
26744 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/devinet.c      2011-08-29 03:45:09.000000000 +0200
26745 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
26746  }
26747  EXPORT_SYMBOL(inetdev_by_index);
26748  
26749 +
26750  /* Called only from RTNL semaphored context. No locks. */
26751  
26752  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26753 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
26754  
26755         in_dev = __in_dev_get_rtnl(dev);
26756         if (in_dev) {
26757 +               struct nx_info *nxi = current_nx_info();
26758 +
26759                 if (tryaddrmatch) {
26760                         /* Matthias Andree */
26761                         /* compare label and address (4.4BSD style) */
26762 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
26763                            This is checked above. */
26764                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26765                              ifap = &ifa->ifa_next) {
26766 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26767 +                                       continue;
26768                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26769                                     sin_orig.sin_addr.s_addr ==
26770                                                         ifa->ifa_local) {
26771 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
26772                    comparing just the label */
26773                 if (!ifa) {
26774                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26775 -                            ifap = &ifa->ifa_next)
26776 +                            ifap = &ifa->ifa_next) {
26777 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26778 +                                       continue;
26779                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26780                                         break;
26781 +                       }
26782                 }
26783         }
26784  
26785 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
26786                 goto out;
26787  
26788         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
26789 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
26790 +                       continue;
26791                 if (!buf) {
26792                         done += sizeof(ifr);
26793                         continue;
26794 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
26795         struct net_device *dev;
26796         struct in_device *in_dev;
26797         struct in_ifaddr *ifa;
26798 +       struct sock *sk = skb->sk;
26799         struct hlist_head *head;
26800         struct hlist_node *node;
26801  
26802 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
26803  
26804                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26805                              ifa = ifa->ifa_next, ip_idx++) {
26806 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26807 +                               continue;
26808                                 if (ip_idx < s_ip_idx)
26809                                         continue;
26810                                 if (inet_fill_ifaddr(skb, ifa,
26811 diff -NurpP --minimal linux-3.0.4/net/ipv4/fib_trie.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/fib_trie.c
26812 --- linux-3.0.4/net/ipv4/fib_trie.c     2011-07-22 11:18:13.000000000 +0200
26813 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/fib_trie.c     2011-08-29 04:56:47.000000000 +0200
26814 @@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
26815                             || fa->fa_type == RTN_MULTICAST)
26816                                 continue;
26817  
26818 +                       /* FIXME: check for network context? */
26819                         if (fi)
26820                                 seq_printf(seq,
26821                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
26822 diff -NurpP --minimal linux-3.0.4/net/ipv4/inet_connection_sock.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/inet_connection_sock.c
26823 --- linux-3.0.4/net/ipv4/inet_connection_sock.c 2011-07-22 11:18:13.000000000 +0200
26824 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/inet_connection_sock.c 2011-06-10 22:11:24.000000000 +0200
26825 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
26826  }
26827  EXPORT_SYMBOL(inet_get_local_port_range);
26828  
26829 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26830 +{
26831 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
26832 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
26833 +
26834 +       if (inet_v6_ipv6only(sk2))
26835 +               return 0;
26836 +
26837 +       if (sk1_rcv_saddr &&
26838 +           sk2_rcv_saddr &&
26839 +           sk1_rcv_saddr == sk2_rcv_saddr)
26840 +               return 1;
26841 +
26842 +       if (sk1_rcv_saddr &&
26843 +           !sk2_rcv_saddr &&
26844 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26845 +               return 1;
26846 +
26847 +       if (sk2_rcv_saddr &&
26848 +           !sk1_rcv_saddr &&
26849 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26850 +               return 1;
26851 +
26852 +       if (!sk1_rcv_saddr &&
26853 +           !sk2_rcv_saddr &&
26854 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26855 +               return 1;
26856 +
26857 +       return 0;
26858 +}
26859 +
26860  int inet_csk_bind_conflict(const struct sock *sk,
26861                            const struct inet_bind_bucket *tb)
26862  {
26863 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
26864                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26865                         if (!reuse || !sk2->sk_reuse ||
26866                             sk2->sk_state == TCP_LISTEN) {
26867 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
26868 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
26869 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
26870 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26871                                         break;
26872                         }
26873                 }
26874 diff -NurpP --minimal linux-3.0.4/net/ipv4/inet_diag.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/inet_diag.c
26875 --- linux-3.0.4/net/ipv4/inet_diag.c    2011-07-22 11:18:13.000000000 +0200
26876 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/inet_diag.c    2011-06-22 12:39:16.000000000 +0200
26877 @@ -33,6 +33,8 @@
26878  #include <linux/stddef.h>
26879  
26880  #include <linux/inet_diag.h>
26881 +#include <linux/vs_network.h>
26882 +#include <linux/vs_inet.h>
26883  
26884  static const struct inet_diag_handler **inet_diag_table;
26885  
26886 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
26887  
26888         r->id.idiag_sport = inet->inet_sport;
26889         r->id.idiag_dport = inet->inet_dport;
26890 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
26891 -       r->id.idiag_dst[0] = inet->inet_daddr;
26892 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
26893 +               inet->inet_rcv_saddr);
26894 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
26895 +               inet->inet_daddr);
26896  
26897  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26898         if (r->idiag_family == AF_INET6) {
26899 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
26900         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26901         r->id.idiag_sport     = tw->tw_sport;
26902         r->id.idiag_dport     = tw->tw_dport;
26903 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26904 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26905 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26906 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26907         r->idiag_state        = tw->tw_substate;
26908         r->idiag_timer        = 3;
26909         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26910 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
26911         err = -EINVAL;
26912  
26913         if (req->idiag_family == AF_INET) {
26914 +               /* TODO: lback */
26915                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26916                                  req->id.idiag_dport, req->id.idiag_src[0],
26917                                  req->id.idiag_sport, req->id.idiag_if);
26918 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
26919                 } else
26920  #endif
26921                 {
26922 +                       /* TODO: lback */
26923                         entry.saddr = &inet->inet_rcv_saddr;
26924                         entry.daddr = &inet->inet_daddr;
26925                 }
26926 @@ -543,6 +549,7 @@ static int inet_twsk_diag_dump(struct in
26927                 } else
26928  #endif
26929                 {
26930 +                       /* TODO: lback */
26931                         entry.saddr = &tw->tw_rcv_saddr;
26932                         entry.daddr = &tw->tw_daddr;
26933                 }
26934 @@ -589,8 +596,8 @@ static int inet_diag_fill_req(struct sk_
26935  
26936         r->id.idiag_sport = inet->inet_sport;
26937         r->id.idiag_dport = ireq->rmt_port;
26938 -       r->id.idiag_src[0] = ireq->loc_addr;
26939 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26940 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26941 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26942         r->idiag_expires = jiffies_to_msecs(tmo);
26943         r->idiag_rqueue = 0;
26944         r->idiag_wqueue = 0;
26945 @@ -661,6 +668,7 @@ static int inet_diag_dump_reqs(struct sk
26946                                 continue;
26947  
26948                         if (bc) {
26949 +                               /* TODO: lback */
26950                                 entry.saddr =
26951  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26952                                         (entry.family == AF_INET6) ?
26953 @@ -731,6 +739,8 @@ static int inet_diag_dump(struct sk_buff
26954                         sk_nulls_for_each(sk, node, &ilb->head) {
26955                                 struct inet_sock *inet = inet_sk(sk);
26956  
26957 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26958 +                                       continue;
26959                                 if (num < s_num) {
26960                                         num++;
26961                                         continue;
26962 @@ -797,6 +807,8 @@ skip_listen_ht:
26963                 sk_nulls_for_each(sk, node, &head->chain) {
26964                         struct inet_sock *inet = inet_sk(sk);
26965  
26966 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26967 +                               continue;
26968                         if (num < s_num)
26969                                 goto next_normal;
26970                         if (!(r->idiag_states & (1 << sk->sk_state)))
26971 @@ -821,6 +833,8 @@ next_normal:
26972                         inet_twsk_for_each(tw, node,
26973                                     &head->twchain) {
26974  
26975 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26976 +                                       continue;
26977                                 if (num < s_num)
26978                                         goto next_dying;
26979                                 if (r->id.idiag_sport != tw->tw_sport &&
26980 diff -NurpP --minimal linux-3.0.4/net/ipv4/inet_hashtables.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/inet_hashtables.c
26981 --- linux-3.0.4/net/ipv4/inet_hashtables.c      2011-08-31 18:56:42.000000000 +0200
26982 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/inet_hashtables.c      2011-08-29 03:45:56.000000000 +0200
26983 @@ -22,6 +22,7 @@
26984  
26985  #include <net/inet_connection_sock.h>
26986  #include <net/inet_hashtables.h>
26987 +#include <net/route.h>
26988  #include <net/ip.h>
26989  
26990  /*
26991 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
26992                         if (rcv_saddr != daddr)
26993                                 return -1;
26994                         score += 2;
26995 +               } else {
26996 +                       /* block non nx_info ips */
26997 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
26998 +                               daddr, NXA_MASK_BIND))
26999 +                               return -1;
27000                 }
27001                 if (sk->sk_bound_dev_if) {
27002                         if (sk->sk_bound_dev_if != dif)
27003 diff -NurpP --minimal linux-3.0.4/net/ipv4/netfilter/nf_nat_helper.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/netfilter/nf_nat_helper.c
27004 --- linux-3.0.4/net/ipv4/netfilter/nf_nat_helper.c      2011-07-22 11:18:13.000000000 +0200
27005 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/netfilter/nf_nat_helper.c      2011-06-15 02:40:14.000000000 +0200
27006 @@ -20,6 +20,7 @@
27007  #include <net/route.h>
27008  
27009  #include <linux/netfilter_ipv4.h>
27010 +#include <net/route.h>
27011  #include <net/netfilter/nf_conntrack.h>
27012  #include <net/netfilter/nf_conntrack_helper.h>
27013  #include <net/netfilter/nf_conntrack_ecache.h>
27014 diff -NurpP --minimal linux-3.0.4/net/ipv4/netfilter.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/netfilter.c
27015 --- linux-3.0.4/net/ipv4/netfilter.c    2011-07-22 11:18:13.000000000 +0200
27016 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/netfilter.c    2011-07-19 00:44:39.000000000 +0200
27017 @@ -5,7 +5,7 @@
27018  #include <linux/ip.h>
27019  #include <linux/skbuff.h>
27020  #include <linux/gfp.h>
27021 -#include <net/route.h>
27022 +// #include <net/route.h>
27023  #include <net/xfrm.h>
27024  #include <net/ip.h>
27025  #include <net/netfilter/nf_queue.h>
27026 diff -NurpP --minimal linux-3.0.4/net/ipv4/raw.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/raw.c
27027 --- linux-3.0.4/net/ipv4/raw.c  2011-07-22 11:18:13.000000000 +0200
27028 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/raw.c  2011-07-27 20:26:04.000000000 +0200
27029 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27030  
27031                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
27032                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
27033 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
27034 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27035                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27036                         goto found; /* gotcha */
27037         }
27038 @@ -385,6 +385,12 @@ static int raw_send_hdrinc(struct sock *
27039                 icmp_out_count(net, ((struct icmphdr *)
27040                         skb_transport_header(skb))->type);
27041  
27042 +       err = -EPERM;
27043 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27044 +               sk->sk_nx_info &&
27045 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27046 +               goto error_free;
27047 +
27048         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
27049                       rt->dst.dev, dst_output);
27050         if (err > 0)
27051 @@ -571,6 +577,16 @@ static int raw_sendmsg(struct kiocb *ioc
27052                         goto done;
27053         }
27054  
27055 +       if (sk->sk_nx_info) {
27056 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
27057 +               if (IS_ERR(rt)) {
27058 +                       err = PTR_ERR(rt);
27059 +                       rt = NULL;
27060 +                       goto done;
27061 +               }
27062 +               ip_rt_put(rt);
27063 +       }
27064 +
27065         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
27066         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
27067         if (IS_ERR(rt)) {
27068 @@ -647,17 +663,19 @@ static int raw_bind(struct sock *sk, str
27069  {
27070         struct inet_sock *inet = inet_sk(sk);
27071         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27072 +       struct nx_v4_sock_addr nsa = { 0 };
27073         int ret = -EINVAL;
27074         int chk_addr_ret;
27075  
27076         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27077                 goto out;
27078 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27079 +       v4_map_sock_addr(inet, addr, &nsa);
27080 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27081         ret = -EADDRNOTAVAIL;
27082 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27083 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27084             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27085                 goto out;
27086 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
27087 +       v4_set_sock_addr(inet, &nsa);
27088         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27089                 inet->inet_saddr = 0;  /* Use device */
27090         sk_dst_reset(sk);
27091 @@ -709,7 +727,8 @@ static int raw_recvmsg(struct kiocb *ioc
27092         /* Copy the address. */
27093         if (sin) {
27094                 sin->sin_family = AF_INET;
27095 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27096 +               sin->sin_addr.s_addr =
27097 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27098                 sin->sin_port = 0;
27099                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27100         }
27101 @@ -905,7 +924,8 @@ static struct sock *raw_get_first(struct
27102                 struct hlist_node *node;
27103  
27104                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27105 -                       if (sock_net(sk) == seq_file_net(seq))
27106 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27107 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27108                                 goto found;
27109         }
27110         sk = NULL;
27111 @@ -921,7 +941,8 @@ static struct sock *raw_get_next(struct 
27112                 sk = sk_next(sk);
27113  try_again:
27114                 ;
27115 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27116 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27117 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27118  
27119         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27120                 sk = sk_head(&state->h->ht[state->bucket]);
27121 diff -NurpP --minimal linux-3.0.4/net/ipv4/tcp.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/tcp.c
27122 --- linux-3.0.4/net/ipv4/tcp.c  2011-07-22 11:18:13.000000000 +0200
27123 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/tcp.c  2011-07-19 00:44:39.000000000 +0200
27124 @@ -266,6 +266,7 @@
27125  #include <linux/crypto.h>
27126  #include <linux/time.h>
27127  #include <linux/slab.h>
27128 +#include <linux/in.h>
27129  
27130  #include <net/icmp.h>
27131  #include <net/tcp.h>
27132 diff -NurpP --minimal linux-3.0.4/net/ipv4/tcp_ipv4.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/tcp_ipv4.c
27133 --- linux-3.0.4/net/ipv4/tcp_ipv4.c     2011-08-31 18:56:42.000000000 +0200
27134 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/tcp_ipv4.c     2011-08-29 03:45:10.000000000 +0200
27135 @@ -2003,6 +2003,12 @@ static void *listening_get_next(struct s
27136                 req = req->dl_next;
27137                 while (1) {
27138                         while (req) {
27139 +                               vxdprintk(VXD_CBIT(net, 6),
27140 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27141 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27142 +                               if (req->sk &&
27143 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27144 +                                       continue;
27145                                 if (req->rsk_ops->family == st->family) {
27146                                         cur = req;
27147                                         goto out;
27148 @@ -2027,6 +2033,10 @@ get_req:
27149         }
27150  get_sk:
27151         sk_nulls_for_each_from(sk, node) {
27152 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27153 +                       sk, sk->sk_nid, nx_current_nid());
27154 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27155 +                       continue;
27156                 if (!net_eq(sock_net(sk), net))
27157                         continue;
27158                 if (sk->sk_family == st->family) {
27159 @@ -2103,6 +2113,11 @@ static void *established_get_first(struc
27160  
27161                 spin_lock_bh(lock);
27162                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27163 +                       vxdprintk(VXD_CBIT(net, 6),
27164 +                               "sk,egf: %p [#%d] (from %d)",
27165 +                               sk, sk->sk_nid, nx_current_nid());
27166 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27167 +                               continue;
27168                         if (sk->sk_family != st->family ||
27169                             !net_eq(sock_net(sk), net)) {
27170                                 continue;
27171 @@ -2113,6 +2128,11 @@ static void *established_get_first(struc
27172                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27173                 inet_twsk_for_each(tw, node,
27174                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27175 +                       vxdprintk(VXD_CBIT(net, 6),
27176 +                               "tw: %p [#%d] (from %d)",
27177 +                               tw, tw->tw_nid, nx_current_nid());
27178 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27179 +                               continue;
27180                         if (tw->tw_family != st->family ||
27181                             !net_eq(twsk_net(tw), net)) {
27182                                 continue;
27183 @@ -2142,7 +2162,9 @@ static void *established_get_next(struct
27184                 tw = cur;
27185                 tw = tw_next(tw);
27186  get_tw:
27187 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27188 +               while (tw && (tw->tw_family != st->family ||
27189 +                       !net_eq(twsk_net(tw), net) ||
27190 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27191                         tw = tw_next(tw);
27192                 }
27193                 if (tw) {
27194 @@ -2166,6 +2188,11 @@ get_tw:
27195                 sk = sk_nulls_next(sk);
27196  
27197         sk_nulls_for_each_from(sk, node) {
27198 +               vxdprintk(VXD_CBIT(net, 6),
27199 +                       "sk,egn: %p [#%d] (from %d)",
27200 +                       sk, sk->sk_nid, nx_current_nid());
27201 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27202 +                       continue;
27203                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27204                         goto found;
27205         }
27206 @@ -2375,9 +2402,9 @@ static void get_openreq4(struct sock *sk
27207         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27208                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
27209                 i,
27210 -               ireq->loc_addr,
27211 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27212                 ntohs(inet_sk(sk)->inet_sport),
27213 -               ireq->rmt_addr,
27214 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27215                 ntohs(ireq->rmt_port),
27216                 TCP_SYN_RECV,
27217                 0, 0, /* could print option size, but that is af dependent. */
27218 diff -NurpP --minimal linux-3.0.4/net/ipv4/tcp_minisocks.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/tcp_minisocks.c
27219 --- linux-3.0.4/net/ipv4/tcp_minisocks.c        2011-03-15 18:07:45.000000000 +0100
27220 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/tcp_minisocks.c        2011-06-10 22:11:24.000000000 +0200
27221 @@ -23,6 +23,9 @@
27222  #include <linux/slab.h>
27223  #include <linux/sysctl.h>
27224  #include <linux/workqueue.h>
27225 +#include <linux/vs_limit.h>
27226 +#include <linux/vs_socket.h>
27227 +#include <linux/vs_context.h>
27228  #include <net/tcp.h>
27229  #include <net/inet_common.h>
27230  #include <net/xfrm.h>
27231 @@ -335,6 +338,11 @@ void tcp_time_wait(struct sock *sk, int 
27232                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27233                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27234  
27235 +               tw->tw_xid              = sk->sk_xid;
27236 +               tw->tw_vx_info          = NULL;
27237 +               tw->tw_nid              = sk->sk_nid;
27238 +               tw->tw_nx_info          = NULL;
27239 +
27240  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27241                 if (tw->tw_family == PF_INET6) {
27242                         struct ipv6_pinfo *np = inet6_sk(sk);
27243 diff -NurpP --minimal linux-3.0.4/net/ipv4/udp.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/udp.c
27244 --- linux-3.0.4/net/ipv4/udp.c  2011-07-22 11:18:13.000000000 +0200
27245 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv4/udp.c  2011-07-27 20:26:14.000000000 +0200
27246 @@ -296,14 +296,7 @@ fail:
27247  }
27248  EXPORT_SYMBOL(udp_lib_get_port);
27249  
27250 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27251 -{
27252 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27253 -
27254 -       return  (!ipv6_only_sock(sk2)  &&
27255 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
27256 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
27257 -}
27258 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27259  
27260  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
27261                                        unsigned int port)
27262 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
27263                         if (inet->inet_rcv_saddr != daddr)
27264                                 return -1;
27265                         score += 2;
27266 +               } else {
27267 +                       /* block non nx_info ips */
27268 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27269 +                               daddr, NXA_MASK_BIND))
27270 +                               return -1;
27271                 }
27272                 if (inet->inet_daddr) {
27273                         if (inet->inet_daddr != saddr)
27274 @@ -441,6 +439,7 @@ exact_match:
27275         return result;
27276  }
27277  
27278 +
27279  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27280   * harder than this. -DaveM
27281   */
27282 @@ -486,6 +485,11 @@ begin:
27283         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27284                 score = compute_score(sk, net, saddr, hnum, sport,
27285                                       daddr, dport, dif);
27286 +               /* FIXME: disabled?
27287 +               if (score == 9) {
27288 +                       result = sk;
27289 +                       break;
27290 +               } else */
27291                 if (score > badness) {
27292                         result = sk;
27293                         badness = score;
27294 @@ -499,6 +503,7 @@ begin:
27295         if (get_nulls_value(node) != slot)
27296                 goto begin;
27297  
27298 +
27299         if (result) {
27300                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
27301                         result = NULL;
27302 @@ -508,6 +513,7 @@ begin:
27303                         goto begin;
27304                 }
27305         }
27306 +
27307         rcu_read_unlock();
27308         return result;
27309  }
27310 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
27311                     udp_sk(s)->udp_port_hash != hnum ||
27312                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
27313                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
27314 -                   (inet->inet_rcv_saddr &&
27315 -                    inet->inet_rcv_saddr != loc_addr) ||
27316 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27317                     ipv6_only_sock(s) ||
27318                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27319                         continue;
27320 @@ -929,6 +934,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
27321                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
27322                                    faddr, saddr, dport, inet->inet_sport);
27323  
27324 +               if (sk->sk_nx_info) {
27325 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
27326 +                       if (IS_ERR(rt)) {
27327 +                               err = PTR_ERR(rt);
27328 +                               rt = NULL;
27329 +                               goto out;
27330 +                       }
27331 +                       ip_rt_put(rt);
27332 +               }
27333 +
27334                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
27335                 rt = ip_route_output_flow(net, fl4, sk);
27336                 if (IS_ERR(rt)) {
27337 @@ -1226,7 +1241,8 @@ try_again:
27338         if (sin) {
27339                 sin->sin_family = AF_INET;
27340                 sin->sin_port = udp_hdr(skb)->source;
27341 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27342 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27343 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27344                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27345         }
27346         if (inet->cmsg_flags)
27347 @@ -1970,6 +1986,8 @@ static struct sock *udp_get_first(struct
27348                 sk_nulls_for_each(sk, node, &hslot->head) {
27349                         if (!net_eq(sock_net(sk), net))
27350                                 continue;
27351 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27352 +                               continue;
27353                         if (sk->sk_family == state->family)
27354                                 goto found;
27355                 }
27356 @@ -1987,7 +2005,9 @@ static struct sock *udp_get_next(struct 
27357  
27358         do {
27359                 sk = sk_nulls_next(sk);
27360 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27361 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27362 +               sk->sk_family != state->family ||
27363 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27364  
27365         if (!sk) {
27366                 if (state->bucket <= state->udp_table->mask)
27367 diff -NurpP --minimal linux-3.0.4/net/ipv6/Kconfig linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/Kconfig
27368 --- linux-3.0.4/net/ipv6/Kconfig        2010-08-02 16:52:59.000000000 +0200
27369 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/Kconfig        2011-06-10 22:11:24.000000000 +0200
27370 @@ -4,8 +4,8 @@
27371  
27372  #   IPv6 as module will cause a CRASH if you try to unload it
27373  menuconfig IPV6
27374 -       tristate "The IPv6 protocol"
27375 -       default m
27376 +       bool "The IPv6 protocol"
27377 +       default n
27378         ---help---
27379           This is complemental support for the IP version 6.
27380           You will still be able to do traditional IPv4 networking as well.
27381 diff -NurpP --minimal linux-3.0.4/net/ipv6/addrconf.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/addrconf.c
27382 --- linux-3.0.4/net/ipv6/addrconf.c     2011-07-22 11:18:13.000000000 +0200
27383 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/addrconf.c     2011-06-10 22:11:24.000000000 +0200
27384 @@ -87,6 +87,8 @@
27385  
27386  #include <linux/proc_fs.h>
27387  #include <linux/seq_file.h>
27388 +#include <linux/vs_network.h>
27389 +#include <linux/vs_inet6.h>
27390  
27391  /* Set to 3 to get tracing... */
27392  #define ACONF_DEBUG 2
27393 @@ -1108,7 +1110,7 @@ out:
27394  
27395  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27396                        const struct in6_addr *daddr, unsigned int prefs,
27397 -                      struct in6_addr *saddr)
27398 +                      struct in6_addr *saddr, struct nx_info *nxi)
27399  {
27400         struct ipv6_saddr_score scores[2],
27401                                 *score = &scores[0], *hiscore = &scores[1];
27402 @@ -1180,6 +1182,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27403                                                dev->name);
27404                                 continue;
27405                         }
27406 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27407 +                               continue;
27408  
27409                         score->rule = -1;
27410                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27411 @@ -3048,7 +3052,10 @@ static void if6_seq_stop(struct seq_file
27412  static int if6_seq_show(struct seq_file *seq, void *v)
27413  {
27414         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27415 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27416 +
27417 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27418 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27419 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27420                    &ifp->addr,
27421                    ifp->idev->dev->ifindex,
27422                    ifp->prefix_len,
27423 @@ -3554,6 +3561,11 @@ static int in6_dump_addrs(struct inet6_d
27424         struct ifacaddr6 *ifaca;
27425         int err = 1;
27426         int ip_idx = *p_ip_idx;
27427 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27428 +
27429 +       /* disable ipv6 on non v6 guests */
27430 +       if (nxi && !nx_info_has_v6(nxi))
27431 +               return skb->len;
27432  
27433         read_lock_bh(&idev->lock);
27434         switch (type) {
27435 @@ -3564,6 +3576,8 @@ static int in6_dump_addrs(struct inet6_d
27436                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
27437                         if (++ip_idx < s_ip_idx)
27438                                 continue;
27439 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27440 +                                       continue;
27441                         err = inet6_fill_ifaddr(skb, ifa,
27442                                                 NETLINK_CB(cb->skb).pid,
27443                                                 cb->nlh->nlmsg_seq,
27444 @@ -3580,6 +3594,8 @@ static int in6_dump_addrs(struct inet6_d
27445                      ifmca = ifmca->next, ip_idx++) {
27446                         if (ip_idx < s_ip_idx)
27447                                 continue;
27448 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27449 +                                       continue;
27450                         err = inet6_fill_ifmcaddr(skb, ifmca,
27451                                                   NETLINK_CB(cb->skb).pid,
27452                                                   cb->nlh->nlmsg_seq,
27453 @@ -3595,6 +3611,8 @@ static int in6_dump_addrs(struct inet6_d
27454                      ifaca = ifaca->aca_next, ip_idx++) {
27455                         if (ip_idx < s_ip_idx)
27456                                 continue;
27457 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27458 +                                       continue;
27459                         err = inet6_fill_ifacaddr(skb, ifaca,
27460                                                   NETLINK_CB(cb->skb).pid,
27461                                                   cb->nlh->nlmsg_seq,
27462 @@ -3980,6 +3998,11 @@ static int inet6_dump_ifinfo(struct sk_b
27463         struct inet6_dev *idev;
27464         struct hlist_head *head;
27465         struct hlist_node *node;
27466 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27467 +
27468 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27469 +       if (skb->sk && skb->sk->sk_vx_info)
27470 +               return skb->len; */
27471  
27472         s_h = cb->args[0];
27473         s_idx = cb->args[1];
27474 @@ -3991,6 +4014,8 @@ static int inet6_dump_ifinfo(struct sk_b
27475                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
27476                         if (idx < s_idx)
27477                                 goto cont;
27478 +                       if (!v6_dev_in_nx_info(dev, nxi))
27479 +                               goto cont;
27480                         idev = __in6_dev_get(dev);
27481                         if (!idev)
27482                                 goto cont;
27483 diff -NurpP --minimal linux-3.0.4/net/ipv6/af_inet6.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/af_inet6.c
27484 --- linux-3.0.4/net/ipv6/af_inet6.c     2011-08-31 18:56:42.000000000 +0200
27485 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/af_inet6.c     2011-08-29 03:45:10.000000000 +0200
27486 @@ -42,6 +42,8 @@
27487  #include <linux/netdevice.h>
27488  #include <linux/icmpv6.h>
27489  #include <linux/netfilter_ipv6.h>
27490 +#include <linux/vs_inet.h>
27491 +#include <linux/vs_inet6.h>
27492  
27493  #include <net/ip.h>
27494  #include <net/ipv6.h>
27495 @@ -160,9 +162,12 @@ lookup_protocol:
27496         }
27497  
27498         err = -EPERM;
27499 +       if ((protocol == IPPROTO_ICMPV6) &&
27500 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
27501 +               goto override;
27502         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
27503                 goto out_rcu_unlock;
27504 -
27505 +override:
27506         sock->ops = answer->ops;
27507         answer_prot = answer->prot;
27508         answer_no_check = answer->no_check;
27509 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
27510         struct inet_sock *inet = inet_sk(sk);
27511         struct ipv6_pinfo *np = inet6_sk(sk);
27512         struct net *net = sock_net(sk);
27513 +       struct nx_v6_sock_addr nsa;
27514         __be32 v4addr = 0;
27515         unsigned short snum;
27516         int addr_type = 0;
27517 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
27518         if (addr->sin6_family != AF_INET6)
27519                 return -EAFNOSUPPORT;
27520  
27521 +       err = v6_map_sock_addr(inet, addr, &nsa);
27522 +       if (err)
27523 +               return err;
27524 +
27525         addr_type = ipv6_addr_type(&addr->sin6_addr);
27526         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27527                 return -EINVAL;
27528 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
27529                 /* Reproduce AF_INET checks to make the bindings consistent */
27530                 v4addr = addr->sin6_addr.s6_addr32[3];
27531                 chk_addr_ret = inet_addr_type(net, v4addr);
27532 +
27533                 if (!sysctl_ip_nonlocal_bind &&
27534                     !(inet->freebind || inet->transparent) &&
27535                     v4addr != htonl(INADDR_ANY) &&
27536 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
27537                         err = -EADDRNOTAVAIL;
27538                         goto out;
27539                 }
27540 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27541 +                       err = -EADDRNOTAVAIL;
27542 +                       goto out;
27543 +               }
27544         } else {
27545                 if (addr_type != IPV6_ADDR_ANY) {
27546                         struct net_device *dev = NULL;
27547 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
27548                                 }
27549                         }
27550  
27551 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27552 +                               err = -EADDRNOTAVAIL;
27553 +                               goto out;
27554 +                       }
27555 +
27556                         /* ipv4 addr of the socket is invalid.  Only the
27557                          * unspecified and mapped address have a v4 equivalent.
27558                          */
27559 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
27560                 }
27561         }
27562  
27563 +       /* what's that for? */
27564 +       v6_set_sock_addr(inet, &nsa);
27565 +
27566         inet->inet_rcv_saddr = v4addr;
27567         inet->inet_saddr = v4addr;
27568  
27569 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
27570                         return -ENOTCONN;
27571                 sin->sin6_port = inet->inet_dport;
27572                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27573 +               /* FIXME: remap lback? */
27574                 if (np->sndflow)
27575                         sin->sin6_flowinfo = np->flow_label;
27576         } else {
27577 +               /* FIXME: remap lback? */
27578                 if (ipv6_addr_any(&np->rcv_saddr))
27579                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27580                 else
27581 diff -NurpP --minimal linux-3.0.4/net/ipv6/fib6_rules.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/fib6_rules.c
27582 --- linux-3.0.4/net/ipv6/fib6_rules.c   2011-05-22 16:18:00.000000000 +0200
27583 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/fib6_rules.c   2011-06-10 22:11:24.000000000 +0200
27584 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
27585                                                ip6_dst_idev(&rt->dst)->dev,
27586                                                &flp6->daddr,
27587                                                rt6_flags2srcprefs(flags),
27588 -                                              &saddr))
27589 +                                              &saddr, NULL))
27590                                 goto again;
27591                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27592                                                r->src.plen))
27593 diff -NurpP --minimal linux-3.0.4/net/ipv6/inet6_hashtables.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/inet6_hashtables.c
27594 --- linux-3.0.4/net/ipv6/inet6_hashtables.c     2011-08-31 18:56:42.000000000 +0200
27595 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/inet6_hashtables.c     2011-08-29 03:45:10.000000000 +0200
27596 @@ -16,6 +16,7 @@
27597  
27598  #include <linux/module.h>
27599  #include <linux/random.h>
27600 +#include <linux/vs_inet6.h>
27601  
27602  #include <net/inet_connection_sock.h>
27603  #include <net/inet_hashtables.h>
27604 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
27605         unsigned int slot = hash & hashinfo->ehash_mask;
27606         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
27607  
27608 -
27609         rcu_read_lock();
27610  begin:
27611         sk_nulls_for_each_rcu(sk, node, &head->chain) {
27612 @@ -95,7 +95,7 @@ begin:
27613                                 sock_put(sk);
27614                                 goto begin;
27615                         }
27616 -               goto out;
27617 +                       goto out;
27618                 }
27619         }
27620         if (get_nulls_value(node) != slot)
27621 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
27622                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27623                                 return -1;
27624                         score++;
27625 +               } else {
27626 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27627 +                               return -1;
27628                 }
27629                 if (sk->sk_bound_dev_if) {
27630                         if (sk->sk_bound_dev_if != dif)
27631 diff -NurpP --minimal linux-3.0.4/net/ipv6/ip6_output.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/ip6_output.c
27632 --- linux-3.0.4/net/ipv6/ip6_output.c   2011-08-31 18:56:42.000000000 +0200
27633 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/ip6_output.c   2011-08-29 03:45:10.000000000 +0200
27634 @@ -962,7 +962,8 @@ static int ip6_dst_lookup_tail(struct so
27635                 struct rt6_info *rt = (struct rt6_info *) *dst;
27636                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
27637                                           sk ? inet6_sk(sk)->srcprefs : 0,
27638 -                                         &fl6->saddr);
27639 +                                         &fl6->saddr,
27640 +                                         sk ? sk->sk_nx_info : NULL);
27641                 if (err)
27642                         goto out_err_release;
27643         }
27644 diff -NurpP --minimal linux-3.0.4/net/ipv6/ndisc.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/ndisc.c
27645 --- linux-3.0.4/net/ipv6/ndisc.c        2011-07-22 11:18:13.000000000 +0200
27646 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/ndisc.c        2011-06-10 22:11:24.000000000 +0200
27647 @@ -597,7 +597,7 @@ static void ndisc_send_na(struct net_dev
27648         } else {
27649                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27650                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27651 -                                      &tmpaddr))
27652 +                                      &tmpaddr, NULL))
27653                         return;
27654                 src_addr = &tmpaddr;
27655         }
27656 diff -NurpP --minimal linux-3.0.4/net/ipv6/raw.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/raw.c
27657 --- linux-3.0.4/net/ipv6/raw.c  2011-07-22 11:18:13.000000000 +0200
27658 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/raw.c  2011-06-10 22:11:24.000000000 +0200
27659 @@ -30,6 +30,7 @@
27660  #include <linux/icmpv6.h>
27661  #include <linux/netfilter.h>
27662  #include <linux/netfilter_ipv6.h>
27663 +#include <linux/vs_inet6.h>
27664  #include <linux/skbuff.h>
27665  #include <linux/compat.h>
27666  #include <asm/uaccess.h>
27667 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
27668                                 goto out_unlock;
27669                 }
27670  
27671 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27672 +                       err = -EADDRNOTAVAIL;
27673 +                       if (dev)
27674 +                               dev_put(dev);
27675 +                       goto out;
27676 +               }
27677 +
27678                 /* ipv4 addr of the socket is invalid.  Only the
27679                  * unspecified and mapped address have a v4 equivalent.
27680                  */
27681 diff -NurpP --minimal linux-3.0.4/net/ipv6/route.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/route.c
27682 --- linux-3.0.4/net/ipv6/route.c        2011-07-22 11:18:13.000000000 +0200
27683 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/route.c        2011-08-29 05:05:08.000000000 +0200
27684 @@ -54,6 +54,7 @@
27685  #include <net/xfrm.h>
27686  #include <net/netevent.h>
27687  #include <net/netlink.h>
27688 +#include <linux/vs_inet6.h>
27689  
27690  #include <asm/uaccess.h>
27691  
27692 @@ -2050,15 +2051,17 @@ int ip6_route_get_saddr(struct net *net,
27693                         struct rt6_info *rt,
27694                         const struct in6_addr *daddr,
27695                         unsigned int prefs,
27696 -                       struct in6_addr *saddr)
27697 +                       struct in6_addr *saddr,
27698 +                       struct nx_info *nxi)
27699  {
27700         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
27701         int err = 0;
27702 -       if (rt->rt6i_prefsrc.plen)
27703 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
27704 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
27705                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
27706         else
27707                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27708 -                                        daddr, prefs, saddr);
27709 +                                        daddr, prefs, saddr, nxi);
27710         return err;
27711  }
27712  
27713 @@ -2387,7 +2390,8 @@ static int rt6_fill_node(struct net *net
27714                         NLA_PUT_U32(skb, RTA_IIF, iif);
27715         } else if (dst) {
27716                 struct in6_addr saddr_buf;
27717 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
27718 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
27719 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27720                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27721         }
27722  
27723 @@ -2586,6 +2590,7 @@ static int rt6_info_route(struct rt6_inf
27724  {
27725         struct seq_file *m = p_arg;
27726  
27727 +       /* FIXME: check for network context? */
27728         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
27729  
27730  #ifdef CONFIG_IPV6_SUBTREES
27731 diff -NurpP --minimal linux-3.0.4/net/ipv6/tcp_ipv6.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/tcp_ipv6.c
27732 --- linux-3.0.4/net/ipv6/tcp_ipv6.c     2011-08-31 18:56:42.000000000 +0200
27733 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/tcp_ipv6.c     2011-08-29 03:45:10.000000000 +0200
27734 @@ -70,6 +70,7 @@
27735  
27736  #include <linux/crypto.h>
27737  #include <linux/scatterlist.h>
27738 +#include <linux/vs_inet6.h>
27739  
27740  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27741  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27742 @@ -162,8 +163,15 @@ static int tcp_v6_connect(struct sock *s
27743          *      connect() to INADDR_ANY means loopback (BSD'ism).
27744          */
27745  
27746 -       if(ipv6_addr_any(&usin->sin6_addr))
27747 -               usin->sin6_addr.s6_addr[15] = 0x1;
27748 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27749 +               struct nx_info *nxi =  sk->sk_nx_info;
27750 +
27751 +               if (nxi && nx_info_has_v6(nxi))
27752 +                       /* FIXME: remap lback? */
27753 +                       usin->sin6_addr = nxi->v6.ip;
27754 +               else
27755 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27756 +       }
27757  
27758         addr_type = ipv6_addr_type(&usin->sin6_addr);
27759  
27760 diff -NurpP --minimal linux-3.0.4/net/ipv6/udp.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/udp.c
27761 --- linux-3.0.4/net/ipv6/udp.c  2011-08-31 18:56:42.000000000 +0200
27762 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/udp.c  2011-08-29 03:45:10.000000000 +0200
27763 @@ -45,41 +45,67 @@
27764  #include <net/tcp_states.h>
27765  #include <net/ip6_checksum.h>
27766  #include <net/xfrm.h>
27767 +#include <linux/vs_inet6.h>
27768  
27769  #include <linux/proc_fs.h>
27770  #include <linux/seq_file.h>
27771  #include "udp_impl.h"
27772  
27773 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27774 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27775  {
27776 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27777 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
27778         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27779 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
27780 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
27781         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
27782 -       int sk_ipv6only = ipv6_only_sock(sk);
27783 +       int sk1_ipv6only = ipv6_only_sock(sk1);
27784         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27785 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27786 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
27787         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27788  
27789         /* if both are mapped, treat as IPv4 */
27790 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
27791 -               return (!sk2_ipv6only &&
27792 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
27793 +               if (!sk2_ipv6only &&
27794                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
27795 -                         sk1_rcv_saddr == sk2_rcv_saddr));
27796 +                         sk1_rcv_saddr == sk2_rcv_saddr))
27797 +                       goto vs_v4;
27798 +               else
27799 +                       return 0;
27800 +       }
27801  
27802         if (addr_type2 == IPV6_ADDR_ANY &&
27803             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27804 -               return 1;
27805 +               goto vs;
27806  
27807         if (addr_type == IPV6_ADDR_ANY &&
27808 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27809 -               return 1;
27810 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27811 +               goto vs;
27812  
27813         if (sk2_rcv_saddr6 &&
27814 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27815 -               return 1;
27816 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
27817 +               goto vs;
27818  
27819         return 0;
27820 +
27821 +vs_v4:
27822 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
27823 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
27824 +       if (!sk2_rcv_saddr)
27825 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
27826 +       if (!sk1_rcv_saddr)
27827 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
27828 +       return 1;
27829 +vs:
27830 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
27831 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
27832 +       else if (addr_type2 == IPV6_ADDR_ANY)
27833 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
27834 +       else if (addr_type == IPV6_ADDR_ANY) {
27835 +               if (addr_type2 == IPV6_ADDR_MAPPED)
27836 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
27837 +               else
27838 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
27839 +       }
27840 +       return 1;
27841  }
27842  
27843  static unsigned int udp6_portaddr_hash(struct net *net,
27844 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
27845                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27846                                 return -1;
27847                         score++;
27848 +               } else {
27849 +                       /* block non nx_info ips */
27850 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27851 +                               return -1;
27852                 }
27853                 if (!ipv6_addr_any(&np->daddr)) {
27854                         if (!ipv6_addr_equal(&np->daddr, saddr))
27855 diff -NurpP --minimal linux-3.0.4/net/ipv6/xfrm6_policy.c linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/xfrm6_policy.c
27856 --- linux-3.0.4/net/ipv6/xfrm6_policy.c 2011-07-22 11:18:13.000000000 +0200
27857 +++ linux-3.0.4-vs2.3.1-pre10.1/net/ipv6/xfrm6_policy.c 2011-06-10 22:11:24.000000000 +0200
27858 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
27859         dev = ip6_dst_idev(dst)->dev;
27860         ipv6_dev_get_saddr(dev_net(dev), dev,
27861                            (struct in6_addr *)&daddr->a6, 0,
27862 -                          (struct in6_addr *)&saddr->a6);
27863 +                          (struct in6_addr *)&saddr->a6, NULL);
27864         dst_release(dst);
27865         return 0;
27866  }
27867 diff -NurpP --minimal linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.0.4-vs2.3.1-pre10.1/net/netfilter/ipvs/ip_vs_xmit.c
27868 --- linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c 2011-07-22 11:18:13.000000000 +0200
27869 +++ linux-3.0.4-vs2.3.1-pre10.1/net/netfilter/ipvs/ip_vs_xmit.c 2011-07-22 15:27:52.000000000 +0200
27870 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
27871                 return dst;
27872         if (ipv6_addr_any(&fl6.saddr) &&
27873             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
27874 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
27875 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
27876                 goto out_err;
27877         if (do_xfrm) {
27878                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
27879 diff -NurpP --minimal linux-3.0.4/net/netlink/af_netlink.c linux-3.0.4-vs2.3.1-pre10.1/net/netlink/af_netlink.c
27880 --- linux-3.0.4/net/netlink/af_netlink.c        2011-07-22 11:18:13.000000000 +0200
27881 +++ linux-3.0.4-vs2.3.1-pre10.1/net/netlink/af_netlink.c        2011-06-10 22:11:24.000000000 +0200
27882 @@ -55,6 +55,9 @@
27883  #include <linux/types.h>
27884  #include <linux/audit.h>
27885  #include <linux/mutex.h>
27886 +#include <linux/vs_context.h>
27887 +#include <linux/vs_network.h>
27888 +#include <linux/vs_limit.h>
27889  
27890  #include <net/net_namespace.h>
27891  #include <net/sock.h>
27892 @@ -1907,6 +1910,8 @@ static struct sock *netlink_seq_socket_i
27893                         sk_for_each(s, node, &hash->table[j]) {
27894                                 if (sock_net(s) != seq_file_net(seq))
27895                                         continue;
27896 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27897 +                                       continue;
27898                                 if (off == pos) {
27899                                         iter->link = i;
27900                                         iter->hash_idx = j;
27901 @@ -1941,7 +1946,8 @@ static void *netlink_seq_next(struct seq
27902         s = v;
27903         do {
27904                 s = sk_next(s);
27905 -       } while (s && sock_net(s) != seq_file_net(seq));
27906 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27907 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27908         if (s)
27909                 return s;
27910  
27911 @@ -1953,7 +1959,8 @@ static void *netlink_seq_next(struct seq
27912  
27913                 for (; j <= hash->mask; j++) {
27914                         s = sk_head(&hash->table[j]);
27915 -                       while (s && sock_net(s) != seq_file_net(seq))
27916 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27917 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27918                                 s = sk_next(s);
27919                         if (s) {
27920                                 iter->link = i;
27921 diff -NurpP --minimal linux-3.0.4/net/socket.c linux-3.0.4-vs2.3.1-pre10.1/net/socket.c
27922 --- linux-3.0.4/net/socket.c    2011-08-31 18:56:43.000000000 +0200
27923 +++ linux-3.0.4-vs2.3.1-pre10.1/net/socket.c    2011-08-29 03:45:10.000000000 +0200
27924 @@ -98,6 +98,10 @@
27925  
27926  #include <net/sock.h>
27927  #include <linux/netfilter.h>
27928 +#include <linux/vs_base.h>
27929 +#include <linux/vs_socket.h>
27930 +#include <linux/vs_inet.h>
27931 +#include <linux/vs_inet6.h>
27932  
27933  #include <linux/if_tun.h>
27934  #include <linux/ipv6_route.h>
27935 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
27936                                        struct msghdr *msg, size_t size)
27937  {
27938         struct sock_iocb *si = kiocb_to_siocb(iocb);
27939 +       size_t len;
27940  
27941         sock_update_classid(sock->sk);
27942  
27943 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
27944         si->msg = msg;
27945         si->size = size;
27946  
27947 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27948 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27949 +       if (sock->sk) {
27950 +               if (len == size)
27951 +                       vx_sock_send(sock->sk, size);
27952 +               else
27953 +                       vx_sock_fail(sock->sk, size);
27954 +       }
27955 +       vxdprintk(VXD_CBIT(net, 7),
27956 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
27957 +               sock, sock->sk,
27958 +               (sock->sk)?sock->sk->sk_nx_info:0,
27959 +               (sock->sk)?sock->sk->sk_vx_info:0,
27960 +               (sock->sk)?sock->sk->sk_xid:0,
27961 +               (sock->sk)?sock->sk->sk_nid:0,
27962 +               (unsigned int)size, len);
27963 +       return len;
27964  }
27965  
27966  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
27967 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
27968                                        struct msghdr *msg, size_t size, int flags)
27969  {
27970         struct sock_iocb *si = kiocb_to_siocb(iocb);
27971 +       int len;
27972  
27973         sock_update_classid(sock->sk);
27974  
27975 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
27976         si->size = size;
27977         si->flags = flags;
27978  
27979 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27980 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27981 +       if ((len >= 0) && sock->sk)
27982 +               vx_sock_recv(sock->sk, len);
27983 +       vxdprintk(VXD_CBIT(net, 7),
27984 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27985 +               sock, sock->sk,
27986 +               (sock->sk)?sock->sk->sk_nx_info:0,
27987 +               (sock->sk)?sock->sk->sk_vx_info:0,
27988 +               (sock->sk)?sock->sk->sk_xid:0,
27989 +               (sock->sk)?sock->sk->sk_nid:0,
27990 +               (unsigned int)size, len);
27991 +       return len;
27992  }
27993  
27994  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27995 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
27996         if (type < 0 || type >= SOCK_MAX)
27997                 return -EINVAL;
27998  
27999 +       if (!nx_check(0, VS_ADMIN)) {
28000 +               if (family == PF_INET && !current_nx_info_has_v4())
28001 +                       return -EAFNOSUPPORT;
28002 +               if (family == PF_INET6 && !current_nx_info_has_v6())
28003 +                       return -EAFNOSUPPORT;
28004 +       }
28005 +
28006         /* Compatibility.
28007  
28008            This uglymoron is moved from INET layer to here to avoid
28009 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
28010         if (retval < 0)
28011                 goto out;
28012  
28013 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
28014         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
28015         if (retval < 0)
28016                 goto out_release;
28017 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
28018         err = sock_create(family, type, protocol, &sock1);
28019         if (err < 0)
28020                 goto out;
28021 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
28022  
28023         err = sock_create(family, type, protocol, &sock2);
28024         if (err < 0)
28025                 goto out_release_1;
28026 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
28027  
28028         err = sock1->ops->socketpair(sock1, sock2);
28029         if (err < 0)
28030 diff -NurpP --minimal linux-3.0.4/net/sunrpc/auth.c linux-3.0.4-vs2.3.1-pre10.1/net/sunrpc/auth.c
28031 --- linux-3.0.4/net/sunrpc/auth.c       2011-07-22 11:18:13.000000000 +0200
28032 +++ linux-3.0.4-vs2.3.1-pre10.1/net/sunrpc/auth.c       2011-06-10 22:11:24.000000000 +0200
28033 @@ -14,6 +14,7 @@
28034  #include <linux/hash.h>
28035  #include <linux/sunrpc/clnt.h>
28036  #include <linux/spinlock.h>
28037 +#include <linux/vs_tag.h>
28038  
28039  #ifdef RPC_DEBUG
28040  # define RPCDBG_FACILITY       RPCDBG_AUTH
28041 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28042         memset(&acred, 0, sizeof(acred));
28043         acred.uid = cred->fsuid;
28044         acred.gid = cred->fsgid;
28045 +       acred.tag = dx_current_tag();
28046         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
28047  
28048         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
28049 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
28050         struct auth_cred acred = {
28051                 .uid = 0,
28052                 .gid = 0,
28053 +               .tag = dx_current_tag(),
28054         };
28055  
28056         dprintk("RPC: %5u looking up %s cred\n",
28057 diff -NurpP --minimal linux-3.0.4/net/sunrpc/auth_unix.c linux-3.0.4-vs2.3.1-pre10.1/net/sunrpc/auth_unix.c
28058 --- linux-3.0.4/net/sunrpc/auth_unix.c  2010-10-21 13:08:01.000000000 +0200
28059 +++ linux-3.0.4-vs2.3.1-pre10.1/net/sunrpc/auth_unix.c  2011-06-10 22:11:24.000000000 +0200
28060 @@ -12,12 +12,14 @@
28061  #include <linux/module.h>
28062  #include <linux/sunrpc/clnt.h>
28063  #include <linux/sunrpc/auth.h>
28064 +#include <linux/vs_tag.h>
28065  
28066  #define NFS_NGROUPS    16
28067  
28068  struct unx_cred {
28069         struct rpc_cred         uc_base;
28070         gid_t                   uc_gid;
28071 +       tag_t                   uc_tag;
28072         gid_t                   uc_gids[NFS_NGROUPS];
28073  };
28074  #define uc_uid                 uc_base.cr_uid
28075 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28076                 groups = NFS_NGROUPS;
28077  
28078         cred->uc_gid = acred->gid;
28079 +       cred->uc_tag = acred->tag;
28080         for (i = 0; i < groups; i++)
28081                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28082         if (i < NFS_NGROUPS)
28083 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28084         unsigned int i;
28085  
28086  
28087 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28088 +       if (cred->uc_uid != acred->uid ||
28089 +               cred->uc_gid != acred->gid ||
28090 +               cred->uc_tag != acred->tag)
28091                 return 0;
28092  
28093         if (acred->group_info != NULL)
28094 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
28095         struct rpc_clnt *clnt = task->tk_client;
28096         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
28097         __be32          *base, *hold;
28098 -       int             i;
28099 +       int             i, tag;
28100  
28101         *p++ = htonl(RPC_AUTH_UNIX);
28102         base = p++;
28103 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
28104          * Copy the UTS nodename captured when the client was created.
28105          */
28106         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28107 +       tag = task->tk_client->cl_tag;
28108  
28109 -       *p++ = htonl((u32) cred->uc_uid);
28110 -       *p++ = htonl((u32) cred->uc_gid);
28111 +       *p++ = htonl((u32) TAGINO_UID(tag,
28112 +               cred->uc_uid, cred->uc_tag));
28113 +       *p++ = htonl((u32) TAGINO_GID(tag,
28114 +               cred->uc_gid, cred->uc_tag));
28115         hold = p++;
28116         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28117                 *p++ = htonl((u32) cred->uc_gids[i]);
28118 diff -NurpP --minimal linux-3.0.4/net/sunrpc/clnt.c linux-3.0.4-vs2.3.1-pre10.1/net/sunrpc/clnt.c
28119 --- linux-3.0.4/net/sunrpc/clnt.c       2011-07-22 11:18:13.000000000 +0200
28120 +++ linux-3.0.4-vs2.3.1-pre10.1/net/sunrpc/clnt.c       2011-07-01 11:35:35.000000000 +0200
28121 @@ -31,6 +31,7 @@
28122  #include <linux/in.h>
28123  #include <linux/in6.h>
28124  #include <linux/un.h>
28125 +#include <linux/vs_cvirt.h>
28126  
28127  #include <linux/sunrpc/clnt.h>
28128  #include <linux/sunrpc/rpc_pipe_fs.h>
28129 @@ -362,6 +363,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28130         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28131                 clnt->cl_chatty = 1;
28132  
28133 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28134 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28135 +               clnt->cl_tag = 1; */
28136         return clnt;
28137  }
28138  EXPORT_SYMBOL_GPL(rpc_create);
28139 diff -NurpP --minimal linux-3.0.4/net/unix/af_unix.c linux-3.0.4-vs2.3.1-pre10.1/net/unix/af_unix.c
28140 --- linux-3.0.4/net/unix/af_unix.c      2011-07-22 11:18:13.000000000 +0200
28141 +++ linux-3.0.4-vs2.3.1-pre10.1/net/unix/af_unix.c      2011-06-10 22:11:24.000000000 +0200
28142 @@ -114,6 +114,8 @@
28143  #include <linux/mount.h>
28144  #include <net/checksum.h>
28145  #include <linux/security.h>
28146 +#include <linux/vs_context.h>
28147 +#include <linux/vs_limit.h>
28148  
28149  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28150  static DEFINE_SPINLOCK(unix_table_lock);
28151 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28152                 if (!net_eq(sock_net(s), net))
28153                         continue;
28154  
28155 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28156 +                       continue;
28157                 if (u->addr->len == len &&
28158                     !memcmp(u->addr->name, sunname, len))
28159                         goto found;
28160 @@ -2208,6 +2212,8 @@ static struct sock *unix_seq_idx(struct 
28161         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28162                 if (sock_net(s) != seq_file_net(seq))
28163                         continue;
28164 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28165 +                       continue;
28166                 if (off == pos)
28167                         return s;
28168                 ++off;
28169 @@ -2232,7 +2238,8 @@ static void *unix_seq_next(struct seq_fi
28170                 sk = first_unix_socket(&iter->i);
28171         else
28172                 sk = next_unix_socket(&iter->i, sk);
28173 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28174 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28175 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28176                 sk = next_unix_socket(&iter->i, sk);
28177         return sk;
28178  }
28179 diff -NurpP --minimal linux-3.0.4/scripts/checksyscalls.sh linux-3.0.4-vs2.3.1-pre10.1/scripts/checksyscalls.sh
28180 --- linux-3.0.4/scripts/checksyscalls.sh        2011-03-15 18:07:46.000000000 +0100
28181 +++ linux-3.0.4-vs2.3.1-pre10.1/scripts/checksyscalls.sh        2011-06-10 22:11:24.000000000 +0200
28182 @@ -193,7 +193,6 @@ cat << EOF
28183  #define __IGNORE_afs_syscall
28184  #define __IGNORE_getpmsg
28185  #define __IGNORE_putpmsg
28186 -#define __IGNORE_vserver
28187  EOF
28188  }
28189  
28190 diff -NurpP --minimal linux-3.0.4/security/commoncap.c linux-3.0.4-vs2.3.1-pre10.1/security/commoncap.c
28191 --- linux-3.0.4/security/commoncap.c    2011-07-22 11:18:14.000000000 +0200
28192 +++ linux-3.0.4-vs2.3.1-pre10.1/security/commoncap.c    2011-08-30 15:42:43.000000000 +0200
28193 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
28194  int cap_capable(struct task_struct *tsk, const struct cred *cred,
28195                 struct user_namespace *targ_ns, int cap, int audit)
28196  {
28197 +       struct vx_info *vxi = tsk->vx_info;
28198 +
28199         for (;;) {
28200                 /* The creator of the user namespace has all caps. */
28201                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
28202                         return 0;
28203  
28204                 /* Do we have the necessary capabilities? */
28205 -               if (targ_ns == cred->user->user_ns)
28206 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
28207 +               if (targ_ns == cred->user->user_ns) {
28208 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28209 +                           cap_raised(cred->cap_effective, cap))
28210 +                               return 0;
28211 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
28212 +               }
28213  
28214                 /* Have we tried all of the parent namespaces? */
28215                 if (targ_ns == &init_user_ns)
28216 @@ -611,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
28217  
28218         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28219                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
28220 -           !capable(CAP_SYS_ADMIN))
28221 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28222                 return -EPERM;
28223         return 0;
28224  }
28225 @@ -637,7 +644,7 @@ int cap_inode_removexattr(struct dentry 
28226  
28227         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28228                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
28229 -           !capable(CAP_SYS_ADMIN))
28230 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28231                 return -EPERM;
28232         return 0;
28233  }
28234 diff -NurpP --minimal linux-3.0.4/security/selinux/hooks.c linux-3.0.4-vs2.3.1-pre10.1/security/selinux/hooks.c
28235 --- linux-3.0.4/security/selinux/hooks.c        2011-07-22 11:18:14.000000000 +0200
28236 +++ linux-3.0.4-vs2.3.1-pre10.1/security/selinux/hooks.c        2011-06-15 02:40:14.000000000 +0200
28237 @@ -67,7 +67,6 @@
28238  #include <linux/dccp.h>
28239  #include <linux/quota.h>
28240  #include <linux/un.h>          /* for Unix socket types */
28241 -#include <net/af_unix.h>       /* for Unix socket types */
28242  #include <linux/parser.h>
28243  #include <linux/nfs_mount.h>
28244  #include <net/ipv6.h>
This page took 4.068127 seconds and 4 git commands to generate.