]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- hostname change in guests fixed
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.0/.config.inet linux-3.0-vs2.3.1-pre6/.config.inet
2 --- linux-3.0/.config.inet      1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.0-vs2.3.1-pre6/.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/Documentation/vserver/debug.txt linux-3.0-vs2.3.1-pre6/Documentation/vserver/debug.txt
1626 --- linux-3.0/Documentation/vserver/debug.txt   1970-01-01 01:00:00.000000000 +0100
1627 +++ linux-3.0-vs2.3.1-pre6/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/arch/alpha/Kconfig linux-3.0-vs2.3.1-pre6/arch/alpha/Kconfig
1784 --- linux-3.0/arch/alpha/Kconfig        2011-07-22 11:17:32.000000000 +0200
1785 +++ linux-3.0-vs2.3.1-pre6/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/arch/alpha/kernel/entry.S linux-3.0-vs2.3.1-pre6/arch/alpha/kernel/entry.S
1796 --- linux-3.0/arch/alpha/kernel/entry.S 2010-10-21 13:06:45.000000000 +0200
1797 +++ linux-3.0-vs2.3.1-pre6/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/arch/alpha/kernel/ptrace.c linux-3.0-vs2.3.1-pre6/arch/alpha/kernel/ptrace.c
1831 --- linux-3.0/arch/alpha/kernel/ptrace.c        2011-01-05 21:48:40.000000000 +0100
1832 +++ linux-3.0-vs2.3.1-pre6/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/arch/alpha/kernel/systbls.S linux-3.0-vs2.3.1-pre6/arch/alpha/kernel/systbls.S
1842 --- linux-3.0/arch/alpha/kernel/systbls.S       2011-07-22 11:17:32.000000000 +0200
1843 +++ linux-3.0-vs2.3.1-pre6/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/arch/alpha/kernel/traps.c linux-3.0-vs2.3.1-pre6/arch/alpha/kernel/traps.c
1854 --- linux-3.0/arch/alpha/kernel/traps.c 2010-10-21 13:06:46.000000000 +0200
1855 +++ linux-3.0-vs2.3.1-pre6/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/arch/arm/Kconfig linux-3.0-vs2.3.1-pre6/arch/arm/Kconfig
1867 --- linux-3.0/arch/arm/Kconfig  2011-07-22 11:17:32.000000000 +0200
1868 +++ linux-3.0-vs2.3.1-pre6/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/arch/arm/kernel/calls.S linux-3.0-vs2.3.1-pre6/arch/arm/kernel/calls.S
1879 --- linux-3.0/arch/arm/kernel/calls.S   2011-07-22 11:17:32.000000000 +0200
1880 +++ linux-3.0-vs2.3.1-pre6/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/arch/arm/kernel/process.c linux-3.0-vs2.3.1-pre6/arch/arm/kernel/process.c
1891 --- linux-3.0/arch/arm/kernel/process.c 2011-05-22 16:16:47.000000000 +0200
1892 +++ linux-3.0-vs2.3.1-pre6/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/arch/arm/kernel/traps.c linux-3.0-vs2.3.1-pre6/arch/arm/kernel/traps.c
1904 --- linux-3.0/arch/arm/kernel/traps.c   2011-07-22 11:17:32.000000000 +0200
1905 +++ linux-3.0-vs2.3.1-pre6/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/arch/cris/Kconfig linux-3.0-vs2.3.1-pre6/arch/cris/Kconfig
1918 --- linux-3.0/arch/cris/Kconfig 2011-07-22 11:17:35.000000000 +0200
1919 +++ linux-3.0-vs2.3.1-pre6/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/arch/frv/kernel/kernel_thread.S linux-3.0-vs2.3.1-pre6/arch/frv/kernel/kernel_thread.S
1930 --- linux-3.0/arch/frv/kernel/kernel_thread.S   2008-12-25 00:26:37.000000000 +0100
1931 +++ linux-3.0-vs2.3.1-pre6/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/arch/h8300/Kconfig linux-3.0-vs2.3.1-pre6/arch/h8300/Kconfig
1942 --- linux-3.0/arch/h8300/Kconfig        2011-07-22 11:17:35.000000000 +0200
1943 +++ linux-3.0-vs2.3.1-pre6/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/arch/ia64/Kconfig linux-3.0-vs2.3.1-pre6/arch/ia64/Kconfig
1954 --- linux-3.0/arch/ia64/Kconfig 2011-07-22 11:17:35.000000000 +0200
1955 +++ linux-3.0-vs2.3.1-pre6/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/arch/ia64/include/asm/tlb.h linux-3.0-vs2.3.1-pre6/arch/ia64/include/asm/tlb.h
1966 --- linux-3.0/arch/ia64/include/asm/tlb.h       2011-07-22 11:17:35.000000000 +0200
1967 +++ linux-3.0-vs2.3.1-pre6/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/arch/ia64/kernel/entry.S linux-3.0-vs2.3.1-pre6/arch/ia64/kernel/entry.S
1977 --- linux-3.0/arch/ia64/kernel/entry.S  2011-07-22 11:17:35.000000000 +0200
1978 +++ linux-3.0-vs2.3.1-pre6/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/arch/ia64/kernel/perfmon.c linux-3.0-vs2.3.1-pre6/arch/ia64/kernel/perfmon.c
1989 --- linux-3.0/arch/ia64/kernel/perfmon.c        2011-03-15 18:06:39.000000000 +0100
1990 +++ linux-3.0-vs2.3.1-pre6/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/arch/ia64/kernel/process.c linux-3.0-vs2.3.1-pre6/arch/ia64/kernel/process.c
2000 --- linux-3.0/arch/ia64/kernel/process.c        2011-03-15 18:06:39.000000000 +0100
2001 +++ linux-3.0-vs2.3.1-pre6/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/arch/ia64/kernel/ptrace.c linux-3.0-vs2.3.1-pre6/arch/ia64/kernel/ptrace.c
2014 --- linux-3.0/arch/ia64/kernel/ptrace.c 2011-01-05 21:48:59.000000000 +0100
2015 +++ linux-3.0-vs2.3.1-pre6/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/arch/ia64/kernel/traps.c linux-3.0-vs2.3.1-pre6/arch/ia64/kernel/traps.c
2025 --- linux-3.0/arch/ia64/kernel/traps.c  2010-07-07 18:31:01.000000000 +0200
2026 +++ linux-3.0-vs2.3.1-pre6/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/arch/ia64/mm/fault.c linux-3.0-vs2.3.1-pre6/arch/ia64/mm/fault.c
2052 --- linux-3.0/arch/ia64/mm/fault.c      2011-07-22 11:17:35.000000000 +0200
2053 +++ linux-3.0-vs2.3.1-pre6/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/arch/m32r/kernel/traps.c linux-3.0-vs2.3.1-pre6/arch/m32r/kernel/traps.c
2063 --- linux-3.0/arch/m32r/kernel/traps.c  2009-12-03 20:01:57.000000000 +0100
2064 +++ linux-3.0-vs2.3.1-pre6/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/arch/m68k/Kconfig linux-3.0-vs2.3.1-pre6/arch/m68k/Kconfig
2078 --- linux-3.0/arch/m68k/Kconfig 2011-07-22 11:17:35.000000000 +0200
2079 +++ linux-3.0-vs2.3.1-pre6/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/arch/mips/Kconfig linux-3.0-vs2.3.1-pre6/arch/mips/Kconfig
2090 --- linux-3.0/arch/mips/Kconfig 2011-07-22 11:17:35.000000000 +0200
2091 +++ linux-3.0-vs2.3.1-pre6/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/arch/mips/kernel/ptrace.c linux-3.0-vs2.3.1-pre6/arch/mips/kernel/ptrace.c
2102 --- linux-3.0/arch/mips/kernel/ptrace.c 2011-07-22 11:17:36.000000000 +0200
2103 +++ linux-3.0-vs2.3.1-pre6/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/arch/mips/kernel/scall32-o32.S linux-3.0-vs2.3.1-pre6/arch/mips/kernel/scall32-o32.S
2123 --- linux-3.0/arch/mips/kernel/scall32-o32.S    2011-07-22 11:17:36.000000000 +0200
2124 +++ linux-3.0-vs2.3.1-pre6/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/arch/mips/kernel/scall64-64.S linux-3.0-vs2.3.1-pre6/arch/mips/kernel/scall64-64.S
2135 --- linux-3.0/arch/mips/kernel/scall64-64.S     2011-07-22 11:17:36.000000000 +0200
2136 +++ linux-3.0-vs2.3.1-pre6/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/arch/mips/kernel/scall64-n32.S linux-3.0-vs2.3.1-pre6/arch/mips/kernel/scall64-n32.S
2147 --- linux-3.0/arch/mips/kernel/scall64-n32.S    2011-07-22 11:17:36.000000000 +0200
2148 +++ linux-3.0-vs2.3.1-pre6/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/arch/mips/kernel/scall64-o32.S linux-3.0-vs2.3.1-pre6/arch/mips/kernel/scall64-o32.S
2159 --- linux-3.0/arch/mips/kernel/scall64-o32.S    2011-07-22 11:17:36.000000000 +0200
2160 +++ linux-3.0-vs2.3.1-pre6/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/arch/mips/kernel/traps.c linux-3.0-vs2.3.1-pre6/arch/mips/kernel/traps.c
2171 --- linux-3.0/arch/mips/kernel/traps.c  2011-05-22 16:17:00.000000000 +0200
2172 +++ linux-3.0-vs2.3.1-pre6/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/arch/parisc/Kconfig linux-3.0-vs2.3.1-pre6/arch/parisc/Kconfig
2188 --- linux-3.0/arch/parisc/Kconfig       2011-07-22 11:17:36.000000000 +0200
2189 +++ linux-3.0-vs2.3.1-pre6/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/arch/parisc/kernel/syscall_table.S linux-3.0-vs2.3.1-pre6/arch/parisc/kernel/syscall_table.S
2200 --- linux-3.0/arch/parisc/kernel/syscall_table.S        2011-07-22 11:17:36.000000000 +0200
2201 +++ linux-3.0-vs2.3.1-pre6/arch/parisc/kernel/syscall_table.S   2011-06-10 22:11:24.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/arch/parisc/kernel/traps.c linux-3.0-vs2.3.1-pre6/arch/parisc/kernel/traps.c
2212 --- linux-3.0/arch/parisc/kernel/traps.c        2009-09-10 15:25:40.000000000 +0200
2213 +++ linux-3.0-vs2.3.1-pre6/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/arch/parisc/mm/fault.c linux-3.0-vs2.3.1-pre6/arch/parisc/mm/fault.c
2238 --- linux-3.0/arch/parisc/mm/fault.c    2010-08-02 16:52:06.000000000 +0200
2239 +++ linux-3.0-vs2.3.1-pre6/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/arch/powerpc/Kconfig linux-3.0-vs2.3.1-pre6/arch/powerpc/Kconfig
2253 --- linux-3.0/arch/powerpc/Kconfig      2011-07-22 11:17:36.000000000 +0200
2254 +++ linux-3.0-vs2.3.1-pre6/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/arch/powerpc/include/asm/unistd.h linux-3.0-vs2.3.1-pre6/arch/powerpc/include/asm/unistd.h
2265 --- linux-3.0/arch/powerpc/include/asm/unistd.h 2011-07-22 11:17:40.000000000 +0200
2266 +++ linux-3.0-vs2.3.1-pre6/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/arch/powerpc/kernel/process.c linux-3.0-vs2.3.1-pre6/arch/powerpc/kernel/process.c
2277 --- linux-3.0/arch/powerpc/kernel/process.c     2011-07-22 11:17:40.000000000 +0200
2278 +++ linux-3.0-vs2.3.1-pre6/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/arch/powerpc/kernel/traps.c linux-3.0-vs2.3.1-pre6/arch/powerpc/kernel/traps.c
2292 --- linux-3.0/arch/powerpc/kernel/traps.c       2011-07-22 11:17:40.000000000 +0200
2293 +++ linux-3.0-vs2.3.1-pre6/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/arch/powerpc/kernel/vdso.c linux-3.0-vs2.3.1-pre6/arch/powerpc/kernel/vdso.c
2307 --- linux-3.0/arch/powerpc/kernel/vdso.c        2011-05-22 16:17:02.000000000 +0200
2308 +++ linux-3.0-vs2.3.1-pre6/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/arch/s390/Kconfig linux-3.0-vs2.3.1-pre6/arch/s390/Kconfig
2318 --- linux-3.0/arch/s390/Kconfig 2011-07-22 11:17:41.000000000 +0200
2319 +++ linux-3.0-vs2.3.1-pre6/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/arch/s390/include/asm/tlb.h linux-3.0-vs2.3.1-pre6/arch/s390/include/asm/tlb.h
2330 --- linux-3.0/arch/s390/include/asm/tlb.h       2011-07-22 11:17:41.000000000 +0200
2331 +++ linux-3.0-vs2.3.1-pre6/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/arch/s390/include/asm/unistd.h linux-3.0-vs2.3.1-pre6/arch/s390/include/asm/unistd.h
2342 --- linux-3.0/arch/s390/include/asm/unistd.h    2011-07-22 11:17:41.000000000 +0200
2343 +++ linux-3.0-vs2.3.1-pre6/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/arch/s390/kernel/ptrace.c linux-3.0-vs2.3.1-pre6/arch/s390/kernel/ptrace.c
2354 --- linux-3.0/arch/s390/kernel/ptrace.c 2011-03-15 18:06:45.000000000 +0100
2355 +++ linux-3.0-vs2.3.1-pre6/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/arch/s390/kernel/syscalls.S linux-3.0-vs2.3.1-pre6/arch/s390/kernel/syscalls.S
2365 --- linux-3.0/arch/s390/kernel/syscalls.S       2011-07-22 11:17:41.000000000 +0200
2366 +++ linux-3.0-vs2.3.1-pre6/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/arch/sh/Kconfig linux-3.0-vs2.3.1-pre6/arch/sh/Kconfig
2377 --- linux-3.0/arch/sh/Kconfig   2011-07-22 11:17:41.000000000 +0200
2378 +++ linux-3.0-vs2.3.1-pre6/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/arch/sh/kernel/irq.c linux-3.0-vs2.3.1-pre6/arch/sh/kernel/irq.c
2389 --- linux-3.0/arch/sh/kernel/irq.c      2011-07-22 11:17:41.000000000 +0200
2390 +++ linux-3.0-vs2.3.1-pre6/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/arch/sh/kernel/vsyscall/vsyscall.c linux-3.0-vs2.3.1-pre6/arch/sh/kernel/vsyscall/vsyscall.c
2400 --- linux-3.0/arch/sh/kernel/vsyscall/vsyscall.c        2011-05-22 16:17:07.000000000 +0200
2401 +++ linux-3.0-vs2.3.1-pre6/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/arch/sparc/Kconfig linux-3.0-vs2.3.1-pre6/arch/sparc/Kconfig
2411 --- linux-3.0/arch/sparc/Kconfig        2011-07-22 11:17:41.000000000 +0200
2412 +++ linux-3.0-vs2.3.1-pre6/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/arch/sparc/include/asm/tlb_64.h linux-3.0-vs2.3.1-pre6/arch/sparc/include/asm/tlb_64.h
2423 --- linux-3.0/arch/sparc/include/asm/tlb_64.h   2011-07-22 11:17:42.000000000 +0200
2424 +++ linux-3.0-vs2.3.1-pre6/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/arch/sparc/include/asm/unistd.h linux-3.0-vs2.3.1-pre6/arch/sparc/include/asm/unistd.h
2434 --- linux-3.0/arch/sparc/include/asm/unistd.h   2011-07-22 11:17:42.000000000 +0200
2435 +++ linux-3.0-vs2.3.1-pre6/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/arch/sparc/kernel/systbls_32.S linux-3.0-vs2.3.1-pre6/arch/sparc/kernel/systbls_32.S
2446 --- linux-3.0/arch/sparc/kernel/systbls_32.S    2011-07-22 11:17:42.000000000 +0200
2447 +++ linux-3.0-vs2.3.1-pre6/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/arch/sparc/kernel/systbls_64.S linux-3.0-vs2.3.1-pre6/arch/sparc/kernel/systbls_64.S
2458 --- linux-3.0/arch/sparc/kernel/systbls_64.S    2011-07-22 11:17:42.000000000 +0200
2459 +++ linux-3.0-vs2.3.1-pre6/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/arch/um/Kconfig.rest linux-3.0-vs2.3.1-pre6/arch/um/Kconfig.rest
2479 --- linux-3.0/arch/um/Kconfig.rest      2009-06-11 17:12:19.000000000 +0200
2480 +++ linux-3.0-vs2.3.1-pre6/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/arch/um/include/asm/tlb.h linux-3.0-vs2.3.1-pre6/arch/um/include/asm/tlb.h
2491 --- linux-3.0/arch/um/include/asm/tlb.h 2011-07-22 11:17:42.000000000 +0200
2492 +++ linux-3.0-vs2.3.1-pre6/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/arch/um/include/shared/kern_constants.h linux-3.0-vs2.3.1-pre6/arch/um/include/shared/kern_constants.h
2502 --- linux-3.0/arch/um/include/shared/kern_constants.h   1970-01-01 01:00:00.000000000 +0100
2503 +++ linux-3.0-vs2.3.1-pre6/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/arch/um/include/shared/user_constants.h linux-3.0-vs2.3.1-pre6/arch/um/include/shared/user_constants.h
2507 --- linux-3.0/arch/um/include/shared/user_constants.h   1970-01-01 01:00:00.000000000 +0100
2508 +++ linux-3.0-vs2.3.1-pre6/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/arch/x86/Kconfig linux-3.0-vs2.3.1-pre6/arch/x86/Kconfig
2551 --- linux-3.0/arch/x86/Kconfig  2011-07-22 11:17:42.000000000 +0200
2552 +++ linux-3.0-vs2.3.1-pre6/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/arch/x86/ia32/ia32entry.S linux-3.0-vs2.3.1-pre6/arch/x86/ia32/ia32entry.S
2563 --- linux-3.0/arch/x86/ia32/ia32entry.S 2011-07-22 11:17:42.000000000 +0200
2564 +++ linux-3.0-vs2.3.1-pre6/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/arch/x86/include/asm/unistd_64.h linux-3.0-vs2.3.1-pre6/arch/x86/include/asm/unistd_64.h
2575 --- linux-3.0/arch/x86/include/asm/unistd_64.h  2011-07-22 11:17:43.000000000 +0200
2576 +++ linux-3.0-vs2.3.1-pre6/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/arch/x86/kernel/syscall_table_32.S linux-3.0-vs2.3.1-pre6/arch/x86/kernel/syscall_table_32.S
2587 --- linux-3.0/arch/x86/kernel/syscall_table_32.S        2011-07-22 11:17:43.000000000 +0200
2588 +++ linux-3.0-vs2.3.1-pre6/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/block/genhd.c linux-3.0-vs2.3.1-pre6/block/genhd.c
2599 --- linux-3.0/block/genhd.c     2011-07-22 11:17:43.000000000 +0200
2600 +++ linux-3.0-vs2.3.1-pre6/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/drivers/block/Kconfig linux-3.0-vs2.3.1-pre6/drivers/block/Kconfig
2624 --- linux-3.0/drivers/block/Kconfig     2011-07-22 11:17:44.000000000 +0200
2625 +++ linux-3.0-vs2.3.1-pre6/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/drivers/block/Makefile linux-3.0-vs2.3.1-pre6/drivers/block/Makefile
2641 --- linux-3.0/drivers/block/Makefile    2011-07-22 11:17:44.000000000 +0200
2642 +++ linux-3.0-vs2.3.1-pre6/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/drivers/block/loop.c linux-3.0-vs2.3.1-pre6/drivers/block/loop.c
2652 --- linux-3.0/drivers/block/loop.c      2011-07-22 11:17:44.000000000 +0200
2653 +++ linux-3.0-vs2.3.1-pre6/drivers/block/loop.c 2011-06-10 22:11:24.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 @@ -1019,6 +1021,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 @@ -1057,7 +1060,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 @@ -1141,7 +1144,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 @@ -1487,6 +1491,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/drivers/block/vroot.c linux-3.0-vs2.3.1-pre6/drivers/block/vroot.c
2708 --- linux-3.0/drivers/block/vroot.c     1970-01-01 01:00:00.000000000 +0100
2709 +++ linux-3.0-vs2.3.1-pre6/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/drivers/gpu/drm/radeon/r100_reg_safe.h linux-3.0-vs2.3.1-pre6/drivers/gpu/drm/radeon/r100_reg_safe.h
3004 --- linux-3.0/drivers/gpu/drm/radeon/r100_reg_safe.h    1970-01-01 01:00:00.000000000 +0100
3005 +++ linux-3.0-vs2.3.1-pre6/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/drivers/gpu/drm/radeon/r200_reg_safe.h linux-3.0-vs2.3.1-pre6/drivers/gpu/drm/radeon/r200_reg_safe.h
3036 --- linux-3.0/drivers/gpu/drm/radeon/r200_reg_safe.h    1970-01-01 01:00:00.000000000 +0100
3037 +++ linux-3.0-vs2.3.1-pre6/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/drivers/gpu/drm/radeon/r300_reg_safe.h linux-3.0-vs2.3.1-pre6/drivers/gpu/drm/radeon/r300_reg_safe.h
3068 --- linux-3.0/drivers/gpu/drm/radeon/r300_reg_safe.h    1970-01-01 01:00:00.000000000 +0100
3069 +++ linux-3.0-vs2.3.1-pre6/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/drivers/gpu/drm/radeon/r420_reg_safe.h linux-3.0-vs2.3.1-pre6/drivers/gpu/drm/radeon/r420_reg_safe.h
3114 --- linux-3.0/drivers/gpu/drm/radeon/r420_reg_safe.h    1970-01-01 01:00:00.000000000 +0100
3115 +++ linux-3.0-vs2.3.1-pre6/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/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-3.0-vs2.3.1-pre6/drivers/gpu/drm/radeon/rn50_reg_safe.h
3160 --- linux-3.0/drivers/gpu/drm/radeon/rn50_reg_safe.h    1970-01-01 01:00:00.000000000 +0100
3161 +++ linux-3.0-vs2.3.1-pre6/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/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-3.0-vs2.3.1-pre6/drivers/gpu/drm/radeon/rs600_reg_safe.h
3192 --- linux-3.0/drivers/gpu/drm/radeon/rs600_reg_safe.h   1970-01-01 01:00:00.000000000 +0100
3193 +++ linux-3.0-vs2.3.1-pre6/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/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-3.0-vs2.3.1-pre6/drivers/gpu/drm/radeon/rv515_reg_safe.h
3253 --- linux-3.0/drivers/gpu/drm/radeon/rv515_reg_safe.h   1970-01-01 01:00:00.000000000 +0100
3254 +++ linux-3.0-vs2.3.1-pre6/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/drivers/infiniband/core/addr.c linux-3.0-vs2.3.1-pre6/drivers/infiniband/core/addr.c
3314 --- linux-3.0/drivers/infiniband/core/addr.c    2011-07-22 11:17:45.000000000 +0200
3315 +++ linux-3.0-vs2.3.1-pre6/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/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-3.0-vs2.3.1-pre6/drivers/infiniband/hw/ipath/ipath_user_pages.c
3326 --- linux-3.0/drivers/infiniband/hw/ipath/ipath_user_pages.c    2011-05-22 16:17:16.000000000 +0200
3327 +++ linux-3.0-vs2.3.1-pre6/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/drivers/md/dm-ioctl.c linux-3.0-vs2.3.1-pre6/drivers/md/dm-ioctl.c
3337 --- linux-3.0/drivers/md/dm-ioctl.c     2011-05-22 16:17:18.000000000 +0200
3338 +++ linux-3.0-vs2.3.1-pre6/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/drivers/md/dm.c linux-3.0-vs2.3.1-pre6/drivers/md/dm.c
3421 --- linux-3.0/drivers/md/dm.c   2011-05-22 16:17:18.000000000 +0200
3422 +++ linux-3.0-vs2.3.1-pre6/drivers/md/dm.c      2011-06-10 22:11:24.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 @@ -119,6 +120,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 @@ -326,6 +328,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 @@ -334,18 +337,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 @@ -566,6 +570,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 @@ -1841,6 +1853,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/drivers/md/dm.h linux-3.0-vs2.3.1-pre6/drivers/md/dm.h
3497 --- linux-3.0/drivers/md/dm.h   2011-05-22 16:17:18.000000000 +0200
3498 +++ linux-3.0-vs2.3.1-pre6/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/drivers/net/tun.c linux-3.0-vs2.3.1-pre6/drivers/net/tun.c
3509 --- linux-3.0/drivers/net/tun.c 2011-07-22 11:17:54.000000000 +0200
3510 +++ linux-3.0-vs2.3.1-pre6/drivers/net/tun.c    2011-06-22 12:39:14.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 @@ -904,6 +906,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 @@ -1054,7 +1057,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 @@ -1068,7 +1071,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 @@ -1136,6 +1139,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 @@ -1317,6 +1323,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/drivers/tty/sysrq.c linux-3.0-vs2.3.1-pre6/drivers/tty/sysrq.c
3581 --- linux-3.0/drivers/tty/sysrq.c       2011-05-22 16:17:44.000000000 +0200
3582 +++ linux-3.0-vs2.3.1-pre6/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/drivers/tty/tty_io.c linux-3.0-vs2.3.1-pre6/drivers/tty/tty_io.c
3635 --- linux-3.0/drivers/tty/tty_io.c      2011-07-22 11:18:03.000000000 +0200
3636 +++ linux-3.0-vs2.3.1-pre6/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/fs/attr.c linux-3.0-vs2.3.1-pre6/fs/attr.c
3664 --- linux-3.0/fs/attr.c 2011-07-22 11:18:05.000000000 +0200
3665 +++ linux-3.0-vs2.3.1-pre6/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/fs/binfmt_aout.c linux-3.0-vs2.3.1-pre6/fs/binfmt_aout.c
3707 --- linux-3.0/fs/binfmt_aout.c  2010-10-21 13:07:47.000000000 +0200
3708 +++ linux-3.0-vs2.3.1-pre6/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/fs/binfmt_elf.c linux-3.0-vs2.3.1-pre6/fs/binfmt_elf.c
3718 --- linux-3.0/fs/binfmt_elf.c   2011-05-22 16:17:48.000000000 +0200
3719 +++ linux-3.0-vs2.3.1-pre6/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/fs/binfmt_flat.c linux-3.0-vs2.3.1-pre6/fs/binfmt_flat.c
3729 --- linux-3.0/fs/binfmt_flat.c  2011-07-22 11:18:05.000000000 +0200
3730 +++ linux-3.0-vs2.3.1-pre6/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/fs/binfmt_som.c linux-3.0-vs2.3.1-pre6/fs/binfmt_som.c
3740 --- linux-3.0/fs/binfmt_som.c   2010-02-25 11:52:04.000000000 +0100
3741 +++ linux-3.0-vs2.3.1-pre6/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/fs/block_dev.c linux-3.0-vs2.3.1-pre6/fs/block_dev.c
3751 --- linux-3.0/fs/block_dev.c    2011-07-22 11:18:05.000000000 +0200
3752 +++ linux-3.0-vs2.3.1-pre6/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/fs/btrfs/ctree.h linux-3.0-vs2.3.1-pre6/fs/btrfs/ctree.h
3791 --- linux-3.0/fs/btrfs/ctree.h  2011-07-22 11:18:05.000000000 +0200
3792 +++ linux-3.0-vs2.3.1-pre6/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/fs/btrfs/disk-io.c linux-3.0-vs2.3.1-pre6/fs/btrfs/disk-io.c
3846 --- linux-3.0/fs/btrfs/disk-io.c        2011-07-22 11:18:05.000000000 +0200
3847 +++ linux-3.0-vs2.3.1-pre6/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/fs/btrfs/inode.c linux-3.0-vs2.3.1-pre6/fs/btrfs/inode.c
3859 --- linux-3.0/fs/btrfs/inode.c  2011-07-22 11:18:05.000000000 +0200
3860 +++ linux-3.0-vs2.3.1-pre6/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/fs/btrfs/ioctl.c linux-3.0-vs2.3.1-pre6/fs/btrfs/ioctl.c
3935 --- linux-3.0/fs/btrfs/ioctl.c  2011-07-22 11:18:05.000000000 +0200
3936 +++ linux-3.0-vs2.3.1-pre6/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/fs/btrfs/super.c linux-3.0-vs2.3.1-pre6/fs/btrfs/super.c
4111 --- linux-3.0/fs/btrfs/super.c  2011-07-22 11:18:05.000000000 +0200
4112 +++ linux-3.0-vs2.3.1-pre6/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/fs/char_dev.c linux-3.0-vs2.3.1-pre6/fs/char_dev.c
4169 --- linux-3.0/fs/char_dev.c     2011-03-15 18:07:31.000000000 +0100
4170 +++ linux-3.0-vs2.3.1-pre6/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/fs/dcache.c linux-3.0-vs2.3.1-pre6/fs/dcache.c
4204 --- linux-3.0/fs/dcache.c       2011-07-22 11:18:05.000000000 +0200
4205 +++ linux-3.0-vs2.3.1-pre6/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/fs/devpts/inode.c linux-3.0-vs2.3.1-pre6/fs/devpts/inode.c
4258 --- linux-3.0/fs/devpts/inode.c 2011-05-22 16:17:50.000000000 +0200
4259 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext2/balloc.c linux-3.0-vs2.3.1-pre6/fs/ext2/balloc.c
4352 --- linux-3.0/fs/ext2/balloc.c  2011-05-22 16:17:51.000000000 +0200
4353 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext2/ext2.h linux-3.0-vs2.3.1-pre6/fs/ext2/ext2.h
4363 --- linux-3.0/fs/ext2/ext2.h    2011-05-22 16:17:51.000000000 +0200
4364 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext2/file.c linux-3.0-vs2.3.1-pre6/fs/ext2/file.c
4374 --- linux-3.0/fs/ext2/file.c    2010-08-02 16:52:48.000000000 +0200
4375 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext2/ialloc.c linux-3.0-vs2.3.1-pre6/fs/ext2/ialloc.c
4383 --- linux-3.0/fs/ext2/ialloc.c  2011-05-22 16:17:51.000000000 +0200
4384 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext2/inode.c linux-3.0-vs2.3.1-pre6/fs/ext2/inode.c
4402 --- linux-3.0/fs/ext2/inode.c   2011-05-22 16:17:51.000000000 +0200
4403 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext2/ioctl.c linux-3.0-vs2.3.1-pre6/fs/ext2/ioctl.c
4553 --- linux-3.0/fs/ext2/ioctl.c   2011-05-22 16:17:51.000000000 +0200
4554 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext2/namei.c linux-3.0-vs2.3.1-pre6/fs/ext2/namei.c
4605 --- linux-3.0/fs/ext2/namei.c   2011-05-22 16:17:51.000000000 +0200
4606 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext2/super.c linux-3.0-vs2.3.1-pre6/fs/ext2/super.c
4632 --- linux-3.0/fs/ext2/super.c   2011-07-22 11:18:05.000000000 +0200
4633 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext3/file.c linux-3.0-vs2.3.1-pre6/fs/ext3/file.c
4700 --- linux-3.0/fs/ext3/file.c    2010-07-07 18:31:51.000000000 +0200
4701 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext3/ialloc.c linux-3.0-vs2.3.1-pre6/fs/ext3/ialloc.c
4710 --- linux-3.0/fs/ext3/ialloc.c  2011-05-22 16:17:52.000000000 +0200
4711 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext3/inode.c linux-3.0-vs2.3.1-pre6/fs/ext3/inode.c
4729 --- linux-3.0/fs/ext3/inode.c   2011-07-22 11:18:05.000000000 +0200
4730 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext3/ioctl.c linux-3.0-vs2.3.1-pre6/fs/ext3/ioctl.c
4915 --- linux-3.0/fs/ext3/ioctl.c   2011-05-22 16:17:52.000000000 +0200
4916 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext3/namei.c linux-3.0-vs2.3.1-pre6/fs/ext3/namei.c
4993 --- linux-3.0/fs/ext3/namei.c   2011-07-22 11:18:05.000000000 +0200
4994 +++ linux-3.0-vs2.3.1-pre6/fs/ext3/namei.c      2011-06-10 22:11:24.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 @@ -2534,6 +2536,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/fs/ext3/super.c linux-3.0-vs2.3.1-pre6/fs/ext3/super.c
5020 --- linux-3.0/fs/ext3/super.c   2011-07-22 11:18:05.000000000 +0200
5021 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext4/ext4.h linux-3.0-vs2.3.1-pre6/fs/ext4/ext4.h
5089 --- linux-3.0/fs/ext4/ext4.h    2011-07-22 11:18:05.000000000 +0200
5090 +++ linux-3.0-vs2.3.1-pre6/fs/ext4/ext4.h       2011-06-10 22:11:24.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 @@ -608,7 +612,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 @@ -726,6 +731,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 @@ -902,6 +908,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 @@ -2172,6 +2179,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/fs/ext4/file.c linux-3.0-vs2.3.1-pre6/fs/ext4/file.c
5139 --- linux-3.0/fs/ext4/file.c    2011-07-22 11:18:05.000000000 +0200
5140 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext4/ialloc.c linux-3.0-vs2.3.1-pre6/fs/ext4/ialloc.c
5149 --- linux-3.0/fs/ext4/ialloc.c  2011-05-22 16:17:52.000000000 +0200
5150 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext4/inode.c linux-3.0-vs2.3.1-pre6/fs/ext4/inode.c
5168 --- linux-3.0/fs/ext4/inode.c   2011-07-22 11:18:05.000000000 +0200
5169 +++ linux-3.0-vs2.3.1-pre6/fs/ext4/inode.c      2011-07-01 11:35:34.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 @@ -4797,41 +4798,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 @@ -4867,6 +4891,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 @@ -4882,12 +4908,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 @@ -5106,6 +5136,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 @@ -5116,29 +5148,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 @@ -5324,7 +5359,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 @@ -5346,6 +5382,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/fs/ext4/ioctl.c linux-3.0-vs2.3.1-pre6/fs/ext4/ioctl.c
5348 --- linux-3.0/fs/ext4/ioctl.c   2011-05-22 16:17:52.000000000 +0200
5349 +++ linux-3.0-vs2.3.1-pre6/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/fs/ext4/namei.c linux-3.0-vs2.3.1-pre6/fs/ext4/namei.c
5414 --- linux-3.0/fs/ext4/namei.c   2011-07-22 11:18:05.000000000 +0200
5415 +++ linux-3.0-vs2.3.1-pre6/fs/ext4/namei.c      2011-06-10 22:11:24.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 @@ -2596,6 +2598,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/fs/ext4/super.c linux-3.0-vs2.3.1-pre6/fs/ext4/super.c
5441 --- linux-3.0/fs/ext4/super.c   2011-07-22 11:18:05.000000000 +0200
5442 +++ linux-3.0-vs2.3.1-pre6/fs/ext4/super.c      2011-07-01 11:35:34.000000000 +0200
5443 @@ -1294,6 +1294,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 @@ -1369,6 +1370,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 @@ -1537,6 +1541,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 @@ -3194,6 +3212,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 @@ -4324,6 +4345,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/fs/fcntl.c linux-3.0-vs2.3.1-pre6/fs/fcntl.c
5508 --- linux-3.0/fs/fcntl.c        2011-05-22 16:17:52.000000000 +0200
5509 +++ linux-3.0-vs2.3.1-pre6/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/fs/file.c linux-3.0-vs2.3.1-pre6/fs/file.c
5537 --- linux-3.0/fs/file.c 2011-05-22 16:17:52.000000000 +0200
5538 +++ linux-3.0-vs2.3.1-pre6/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/fs/file_table.c linux-3.0-vs2.3.1-pre6/fs/file_table.c
5565 --- linux-3.0/fs/file_table.c   2011-05-22 16:17:52.000000000 +0200
5566 +++ linux-3.0-vs2.3.1-pre6/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/fs/fs_struct.c linux-3.0-vs2.3.1-pre6/fs/fs_struct.c
5604 --- linux-3.0/fs/fs_struct.c    2011-03-15 18:07:31.000000000 +0100
5605 +++ linux-3.0-vs2.3.1-pre6/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/fs/gfs2/file.c linux-3.0-vs2.3.1-pre6/fs/gfs2/file.c
5631 --- linux-3.0/fs/gfs2/file.c    2011-07-22 11:18:05.000000000 +0200
5632 +++ linux-3.0-vs2.3.1-pre6/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/fs/gfs2/inode.h linux-3.0-vs2.3.1-pre6/fs/gfs2/inode.h
5754 --- linux-3.0/fs/gfs2/inode.h   2011-07-22 11:18:05.000000000 +0200
5755 +++ linux-3.0-vs2.3.1-pre6/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/fs/inode.c linux-3.0-vs2.3.1-pre6/fs/inode.c
5765 --- linux-3.0/fs/inode.c        2011-07-22 11:18:05.000000000 +0200
5766 +++ linux-3.0-vs2.3.1-pre6/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/fs/ioctl.c linux-3.0-vs2.3.1-pre6/fs/ioctl.c
5823 --- linux-3.0/fs/ioctl.c        2011-05-22 16:17:52.000000000 +0200
5824 +++ linux-3.0-vs2.3.1-pre6/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/fs/ioprio.c linux-3.0-vs2.3.1-pre6/fs/ioprio.c
5836 --- linux-3.0/fs/ioprio.c       2011-01-05 21:50:24.000000000 +0100
5837 +++ linux-3.0-vs2.3.1-pre6/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/fs/jfs/file.c linux-3.0-vs2.3.1-pre6/fs/jfs/file.c
5865 --- linux-3.0/fs/jfs/file.c     2011-07-22 11:18:05.000000000 +0200
5866 +++ linux-3.0-vs2.3.1-pre6/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/fs/jfs/ioctl.c linux-3.0-vs2.3.1-pre6/fs/jfs/ioctl.c
5886 --- linux-3.0/fs/jfs/ioctl.c    2011-05-22 16:17:52.000000000 +0200
5887 +++ linux-3.0-vs2.3.1-pre6/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/fs/jfs/jfs_dinode.h linux-3.0-vs2.3.1-pre6/fs/jfs/jfs_dinode.h
5946 --- linux-3.0/fs/jfs/jfs_dinode.h       2008-12-25 00:26:37.000000000 +0100
5947 +++ linux-3.0-vs2.3.1-pre6/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/fs/jfs/jfs_filsys.h linux-3.0-vs2.3.1-pre6/fs/jfs/jfs_filsys.h
5965 --- linux-3.0/fs/jfs/jfs_filsys.h       2008-12-25 00:26:37.000000000 +0100
5966 +++ linux-3.0-vs2.3.1-pre6/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/fs/jfs/jfs_imap.c linux-3.0-vs2.3.1-pre6/fs/jfs/jfs_imap.c
5976 --- linux-3.0/fs/jfs/jfs_imap.c 2011-07-22 11:18:05.000000000 +0200
5977 +++ linux-3.0-vs2.3.1-pre6/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/fs/jfs/jfs_inode.c linux-3.0-vs2.3.1-pre6/fs/jfs/jfs_inode.c
6038 --- linux-3.0/fs/jfs/jfs_inode.c        2010-08-02 16:52:49.000000000 +0200
6039 +++ linux-3.0-vs2.3.1-pre6/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/fs/jfs/jfs_inode.h linux-3.0-vs2.3.1-pre6/fs/jfs/jfs_inode.h
6114 --- linux-3.0/fs/jfs/jfs_inode.h        2011-07-22 11:18:05.000000000 +0200
6115 +++ linux-3.0-vs2.3.1-pre6/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/fs/jfs/namei.c linux-3.0-vs2.3.1-pre6/fs/jfs/namei.c
6125 --- linux-3.0/fs/jfs/namei.c    2011-05-22 16:17:53.000000000 +0200
6126 +++ linux-3.0-vs2.3.1-pre6/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/fs/jfs/super.c linux-3.0-vs2.3.1-pre6/fs/jfs/super.c
6152 --- linux-3.0/fs/jfs/super.c    2011-05-22 16:17:53.000000000 +0200
6153 +++ linux-3.0-vs2.3.1-pre6/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/fs/libfs.c linux-3.0-vs2.3.1-pre6/fs/libfs.c
6220 --- linux-3.0/fs/libfs.c        2011-07-22 11:18:05.000000000 +0200
6221 +++ linux-3.0-vs2.3.1-pre6/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/fs/locks.c linux-3.0-vs2.3.1-pre6/fs/locks.c
6268 --- linux-3.0/fs/locks.c        2011-07-22 11:18:05.000000000 +0200
6269 +++ linux-3.0-vs2.3.1-pre6/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/fs/namei.c linux-3.0-vs2.3.1-pre6/fs/namei.c
6460 --- linux-3.0/fs/namei.c        2011-07-22 11:18:05.000000000 +0200
6461 +++ linux-3.0-vs2.3.1-pre6/fs/namei.c   2011-07-22 11:20:39.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 @@ -1839,7 +1933,7 @@ static int may_delete(struct inode *dir,
6599         if (IS_APPEND(dir))
6600                 return -EPERM;
6601         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
6602 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
6603 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
6604                 return -EPERM;
6605         if (isdir) {
6606                 if (!S_ISDIR(victim->d_inode->i_mode))
6607 @@ -1966,6 +2060,15 @@ static int may_open(struct path *path, i
6608                 break;
6609         }
6610  
6611 +#ifdef CONFIG_VSERVER_COWBL
6612 +       if (IS_COW(inode) &&
6613 +               ((flag & O_ACCMODE) != O_RDONLY)) {
6614 +               if (IS_COW_LINK(inode))
6615 +                       return -EMLINK;
6616 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
6617 +               mark_inode_dirty(inode);
6618 +       }
6619 +#endif
6620         error = inode_permission(inode, acc_mode);
6621         if (error)
6622                 return error;
6623 @@ -2859,7 +2962,7 @@ int vfs_link(struct dentry *old_dentry, 
6624         /*
6625          * A link to an append-only or immutable file cannot be created.
6626          */
6627 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
6628 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
6629                 return -EPERM;
6630         if (!dir->i_op->link)
6631                 return -EPERM;
6632 @@ -3245,6 +3348,222 @@ int vfs_follow_link(struct nameidata *nd
6633         return __vfs_follow_link(nd, link);
6634  }
6635  
6636 +
6637 +#ifdef CONFIG_VSERVER_COWBL
6638 +
6639 +#include <linux/file.h>
6640 +
6641 +static inline
6642 +long do_cow_splice(struct file *in, struct file *out, size_t len)
6643 +{
6644 +       loff_t ppos = 0;
6645 +
6646 +       return do_splice_direct(in, &ppos, out, len, 0);
6647 +}
6648 +
6649 +struct dentry *cow_break_link(const char *pathname)
6650 +{
6651 +       int ret, mode, pathlen, redo = 0;
6652 +       struct nameidata old_nd, dir_nd;
6653 +       struct path old_path, new_path;
6654 +       struct dentry *dir, *res = NULL;
6655 +       struct file *old_file;
6656 +       struct file *new_file;
6657 +       char *to, *path, pad='\251';
6658 +       loff_t size;
6659 +
6660 +       vxdprintk(VXD_CBIT(misc, 1),
6661 +               "cow_break_link(" VS_Q("%s") ")", pathname);
6662 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
6663 +       ret = -ENOMEM;
6664 +       if (!path)
6665 +               goto out;
6666 +
6667 +       /* old_nd will have refs to dentry and mnt */
6668 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
6669 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(old): %d", ret);
6670 +       if (ret < 0)
6671 +               goto out_free_path;
6672 +
6673 +       old_path = old_nd.path;
6674 +       mode = old_path.dentry->d_inode->i_mode;
6675 +
6676 +       to = d_path(&old_path, path, PATH_MAX-2);
6677 +       pathlen = strlen(to);
6678 +       vxdprintk(VXD_CBIT(misc, 2),
6679 +               "old path " VS_Q("%s") " [" VS_Q("%.*s") ":%d]", to,
6680 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
6681 +               old_path.dentry->d_name.len);
6682 +
6683 +       to[pathlen + 1] = 0;
6684 +retry:
6685 +       to[pathlen] = pad--;
6686 +       ret = -EMLINK;
6687 +       if (pad <= '\240')
6688 +               goto out_rel_old;
6689 +
6690 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
6691 +       /* dir_nd will have refs to dentry and mnt */
6692 +       ret = do_path_lookup(AT_FDCWD, to,
6693 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
6694 +       vxdprintk(VXD_CBIT(misc, 2),
6695 +               "do_path_lookup(new): %d", ret);
6696 +       if (ret < 0)
6697 +               goto retry;
6698 +
6699 +       /* this puppy downs the inode mutex */
6700 +       new_path.dentry = lookup_create(&dir_nd, 0);
6701 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
6702 +               vxdprintk(VXD_CBIT(misc, 2),
6703 +                       "lookup_create(new): %p", new_path.dentry);
6704 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
6705 +               path_put(&dir_nd.path);
6706 +               goto retry;
6707 +       }
6708 +       vxdprintk(VXD_CBIT(misc, 2),
6709 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
6710 +               new_path.dentry,
6711 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
6712 +               new_path.dentry->d_name.len);
6713 +       dir = dir_nd.path.dentry;
6714 +
6715 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
6716 +       vxdprintk(VXD_CBIT(misc, 2),
6717 +               "vfs_create(new): %d", ret);
6718 +       if (ret == -EEXIST) {
6719 +               mutex_unlock(&dir->d_inode->i_mutex);
6720 +               dput(new_path.dentry);
6721 +               path_put(&dir_nd.path);
6722 +               goto retry;
6723 +       }
6724 +       else if (ret < 0)
6725 +               goto out_unlock_new;
6726 +
6727 +       /* drop out early, ret passes ENOENT */
6728 +       ret = -ENOENT;
6729 +       if ((redo = d_unhashed(old_path.dentry)))
6730 +               goto out_unlock_new;
6731 +
6732 +       new_path.mnt = dir_nd.path.mnt;
6733 +       dget(old_path.dentry);
6734 +       mntget(old_path.mnt);
6735 +       /* this one cleans up the dentry/mnt in case of failure */
6736 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
6737 +               O_RDONLY, current_cred());
6738 +       vxdprintk(VXD_CBIT(misc, 2),
6739 +               "dentry_open(old): %p", old_file);
6740 +       if (!old_file || IS_ERR(old_file)) {
6741 +               res = IS_ERR(old_file) ? (void *) old_file : res;
6742 +               goto out_unlock_new;
6743 +       }
6744 +
6745 +       dget(new_path.dentry);
6746 +       mntget(new_path.mnt);
6747 +       /* this one cleans up the dentry/mnt in case of failure */
6748 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
6749 +               O_WRONLY, current_cred());
6750 +       vxdprintk(VXD_CBIT(misc, 2),
6751 +               "dentry_open(new): %p", new_file);
6752 +
6753 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
6754 +       if (!new_file || IS_ERR(new_file))
6755 +               goto out_fput_old;
6756 +
6757 +       size = i_size_read(old_file->f_dentry->d_inode);
6758 +       ret = do_cow_splice(old_file, new_file, size);
6759 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
6760 +       if (ret < 0) {
6761 +               goto out_fput_both;
6762 +       } else if (ret < size) {
6763 +               ret = -ENOSPC;
6764 +               goto out_fput_both;
6765 +       } else {
6766 +               struct inode *old_inode = old_path.dentry->d_inode;
6767 +               struct inode *new_inode = new_path.dentry->d_inode;
6768 +               struct iattr attr = {
6769 +                       .ia_uid = old_inode->i_uid,
6770 +                       .ia_gid = old_inode->i_gid,
6771 +                       .ia_valid = ATTR_UID | ATTR_GID
6772 +                       };
6773 +
6774 +               setattr_copy(new_inode, &attr);
6775 +               mark_inode_dirty(new_inode);
6776 +       }
6777 +
6778 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
6779 +
6780 +       /* drop out late */
6781 +       ret = -ENOENT;
6782 +       if ((redo = d_unhashed(old_path.dentry)))
6783 +               goto out_unlock;
6784 +
6785 +       vxdprintk(VXD_CBIT(misc, 2),
6786 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
6787 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
6788 +               new_path.dentry->d_name.len,
6789 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
6790 +               old_path.dentry->d_name.len);
6791 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
6792 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
6793 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
6794 +       res = new_path.dentry;
6795 +
6796 +out_unlock:
6797 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
6798 +
6799 +out_fput_both:
6800 +       vxdprintk(VXD_CBIT(misc, 3),
6801 +               "fput(new_file=%p[#%ld])", new_file,
6802 +               atomic_long_read(&new_file->f_count));
6803 +       fput(new_file);
6804 +
6805 +out_fput_old:
6806 +       vxdprintk(VXD_CBIT(misc, 3),
6807 +               "fput(old_file=%p[#%ld])", old_file,
6808 +               atomic_long_read(&old_file->f_count));
6809 +       fput(old_file);
6810 +
6811 +out_unlock_new:
6812 +       mutex_unlock(&dir->d_inode->i_mutex);
6813 +       if (!ret)
6814 +               goto out_redo;
6815 +
6816 +       /* error path cleanup */
6817 +       vfs_unlink(dir->d_inode, new_path.dentry);
6818 +       dput(new_path.dentry);
6819 +
6820 +out_redo:
6821 +       if (!redo)
6822 +               goto out_rel_both;
6823 +       /* lookup dentry once again */
6824 +       path_put(&old_nd.path);
6825 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
6826 +       if (ret)
6827 +               goto out_rel_both;
6828 +
6829 +       new_path.dentry = old_nd.path.dentry;
6830 +       vxdprintk(VXD_CBIT(misc, 2),
6831 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
6832 +               new_path.dentry,
6833 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
6834 +               new_path.dentry->d_name.len);
6835 +       dget(new_path.dentry);
6836 +       res = new_path.dentry;
6837 +
6838 +out_rel_both:
6839 +       path_put(&dir_nd.path);
6840 +out_rel_old:
6841 +       path_put(&old_nd.path);
6842 +out_free_path:
6843 +       kfree(path);
6844 +out:
6845 +       if (ret)
6846 +               res = ERR_PTR(ret);
6847 +       return res;
6848 +}
6849 +
6850 +#endif
6851 +
6852  /* get the link contents into pagecache */
6853  static char *page_getlink(struct dentry * dentry, struct page **ppage)
6854  {
6855 diff -NurpP --minimal linux-3.0/fs/namespace.c linux-3.0-vs2.3.1-pre6/fs/namespace.c
6856 --- linux-3.0/fs/namespace.c    2011-07-22 11:18:05.000000000 +0200
6857 +++ linux-3.0-vs2.3.1-pre6/fs/namespace.c       2011-06-13 18:26:48.000000000 +0200
6858 @@ -31,6 +31,11 @@
6859  #include <linux/idr.h>
6860  #include <linux/fs_struct.h>
6861  #include <linux/fsnotify.h>
6862 +#include <linux/vs_base.h>
6863 +#include <linux/vs_context.h>
6864 +#include <linux/vs_tag.h>
6865 +#include <linux/vserver/space.h>
6866 +#include <linux/vserver/global.h>
6867  #include <asm/uaccess.h>
6868  #include <asm/unistd.h>
6869  #include "pnode.h"
6870 @@ -724,6 +729,7 @@ static struct vfsmount *clone_mnt(struct
6871                 mnt->mnt_root = dget(root);
6872                 mnt->mnt_mountpoint = mnt->mnt_root;
6873                 mnt->mnt_parent = mnt;
6874 +               mnt->mnt_tag = old->mnt_tag;
6875  
6876                 if (flag & CL_SLAVE) {
6877                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
6878 @@ -852,6 +858,31 @@ static inline void mangle(struct seq_fil
6879         seq_escape(m, s, " \t\n\\");
6880  }
6881  
6882 +static int mnt_is_reachable(struct vfsmount *mnt)
6883 +{
6884 +       struct path root;
6885 +       struct dentry *point;
6886 +       int ret;
6887 +
6888 +       if (mnt == mnt->mnt_ns->root)
6889 +               return 1;
6890 +
6891 +       br_read_lock(vfsmount_lock);
6892 +       root = current->fs->root;
6893 +       point = root.dentry;
6894 +
6895 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
6896 +               point = mnt->mnt_mountpoint;
6897 +               mnt = mnt->mnt_parent;
6898 +       }
6899 +
6900 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
6901 +
6902 +       br_read_unlock(vfsmount_lock);
6903 +
6904 +       return ret;
6905 +}
6906 +
6907  /*
6908   * Simple .show_options callback for filesystems which don't want to
6909   * implement more complex mount option showing.
6910 @@ -954,6 +985,8 @@ static int show_sb_opts(struct seq_file 
6911                 { MS_SYNCHRONOUS, ",sync" },
6912                 { MS_DIRSYNC, ",dirsync" },
6913                 { MS_MANDLOCK, ",mand" },
6914 +               { MS_TAGGED, ",tag" },
6915 +               { MS_NOTAGCHECK, ",notagcheck" },
6916                 { 0, NULL }
6917         };
6918         const struct proc_fs_info *fs_infop;
6919 @@ -1000,16 +1033,26 @@ static int show_vfsmnt(struct seq_file *
6920         int err = 0;
6921         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6922  
6923 -       if (mnt->mnt_sb->s_op->show_devname) {
6924 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6925 -               if (err)
6926 -                       goto out;
6927 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6928 +               return SEQ_SKIP;
6929 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6930 +               return SEQ_SKIP;
6931 +
6932 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6933 +               mnt == current->fs->root.mnt) {
6934 +               seq_puts(m, "/dev/root / ");
6935         } else {
6936 -               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6937 +               if (mnt->mnt_sb->s_op->show_devname) {
6938 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6939 +                       if (err)
6940 +                               goto out;
6941 +               } else {
6942 +                       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6943 +               }
6944 +               seq_putc(m, ' ');
6945 +               seq_path(m, &mnt_path, " \t\n\\");
6946 +               seq_putc(m, ' ');
6947         }
6948 -       seq_putc(m, ' ');
6949 -       seq_path(m, &mnt_path, " \t\n\\");
6950 -       seq_putc(m, ' ');
6951         show_type(m, mnt->mnt_sb);
6952         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6953         err = show_sb_opts(m, mnt->mnt_sb);
6954 @@ -1039,6 +1082,11 @@ static int show_mountinfo(struct seq_fil
6955         struct path root = p->root;
6956         int err = 0;
6957  
6958 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6959 +               return SEQ_SKIP;
6960 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6961 +               return SEQ_SKIP;
6962 +
6963         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
6964                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6965         if (sb->s_op->show_path)
6966 @@ -1107,21 +1155,31 @@ static int show_vfsstat(struct seq_file 
6967         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6968         int err = 0;
6969  
6970 -       /* device */
6971 -       if (mnt->mnt_sb->s_op->show_devname) {
6972 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6973 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6974 +               return SEQ_SKIP;
6975 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6976 +               return SEQ_SKIP;
6977 +
6978 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6979 +               mnt == current->fs->root.mnt) {
6980 +               seq_puts(m, "device /dev/root mounted on / ");
6981         } else {
6982 -               if (mnt->mnt_devname) {
6983 -                       seq_puts(m, "device ");
6984 -                       mangle(m, mnt->mnt_devname);
6985 -               } else
6986 -                       seq_puts(m, "no device");
6987 -       }
6988 +               /* device */
6989 +               if (mnt->mnt_sb->s_op->show_devname) {
6990 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
6991 +               } else {
6992 +                       if (mnt->mnt_devname) {
6993 +                               seq_puts(m, "device ");
6994 +                               mangle(m, mnt->mnt_devname);
6995 +                       } else
6996 +                               seq_puts(m, "no device");
6997 +               }
6998  
6999 -       /* mount point */
7000 -       seq_puts(m, " mounted on ");
7001 -       seq_path(m, &mnt_path, " \t\n\\");
7002 -       seq_putc(m, ' ');
7003 +               /* mount point */
7004 +               seq_puts(m, " mounted on ");
7005 +               seq_path(m, &mnt_path, " \t\n\\");
7006 +               seq_putc(m, ' ');
7007 +       }
7008  
7009         /* file system type */
7010         seq_puts(m, "with fstype ");
7011 @@ -1380,7 +1438,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
7012                 goto dput_and_out;
7013  
7014         retval = -EPERM;
7015 -       if (!capable(CAP_SYS_ADMIN))
7016 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7017                 goto dput_and_out;
7018  
7019         retval = do_umount(path.mnt, flags);
7020 @@ -1406,7 +1464,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
7021  
7022  static int mount_is_safe(struct path *path)
7023  {
7024 -       if (capable(CAP_SYS_ADMIN))
7025 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7026                 return 0;
7027         return -EPERM;
7028  #ifdef notyet
7029 @@ -1716,7 +1774,7 @@ static int do_change_type(struct path *p
7030         int type;
7031         int err = 0;
7032  
7033 -       if (!capable(CAP_SYS_ADMIN))
7034 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
7035                 return -EPERM;
7036  
7037         if (path->dentry != path->mnt->mnt_root)
7038 @@ -1732,6 +1790,7 @@ static int do_change_type(struct path *p
7039                 if (err)
7040                         goto out_unlock;
7041         }
7042 +       // mnt->mnt_flags = mnt_flags;
7043  
7044         br_write_lock(vfsmount_lock);
7045         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
7046 @@ -1747,12 +1806,14 @@ static int do_change_type(struct path *p
7047   * do loopback mount.
7048   */
7049  static int do_loopback(struct path *path, char *old_name,
7050 -                               int recurse)
7051 +       tag_t tag, unsigned long flags, int mnt_flags)
7052  {
7053         LIST_HEAD(umount_list);
7054         struct path old_path;
7055         struct vfsmount *mnt = NULL;
7056         int err = mount_is_safe(path);
7057 +       int recurse = flags & MS_REC;
7058 +
7059         if (err)
7060                 return err;
7061         if (!old_name || !*old_name)
7062 @@ -1818,12 +1879,12 @@ static int change_mount_flags(struct vfs
7063   * on it - tough luck.
7064   */
7065  static int do_remount(struct path *path, int flags, int mnt_flags,
7066 -                     void *data)
7067 +       void *data, xid_t xid)
7068  {
7069         int err;
7070         struct super_block *sb = path->mnt->mnt_sb;
7071  
7072 -       if (!capable(CAP_SYS_ADMIN))
7073 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
7074                 return -EPERM;
7075  
7076         if (!check_mnt(path->mnt))
7077 @@ -1871,7 +1932,7 @@ static int do_move_mount(struct path *pa
7078         struct path old_path, parent_path;
7079         struct vfsmount *p;
7080         int err = 0;
7081 -       if (!capable(CAP_SYS_ADMIN))
7082 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7083                 return -EPERM;
7084         if (!old_name || !*old_name)
7085                 return -EINVAL;
7086 @@ -2022,7 +2083,7 @@ static int do_new_mount(struct path *pat
7087                 return -EINVAL;
7088  
7089         /* we need capabilities... */
7090 -       if (!capable(CAP_SYS_ADMIN))
7091 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7092                 return -EPERM;
7093  
7094         mnt = do_kern_mount(type, flags, name, data);
7095 @@ -2291,6 +2352,7 @@ long do_mount(char *dev_name, char *dir_
7096         struct path path;
7097         int retval = 0;
7098         int mnt_flags = 0;
7099 +       tag_t tag = 0;
7100  
7101         /* Discard magic */
7102         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
7103 @@ -2318,6 +2380,12 @@ long do_mount(char *dev_name, char *dir_
7104         if (!(flags & MS_NOATIME))
7105                 mnt_flags |= MNT_RELATIME;
7106  
7107 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
7108 +               /* FIXME: bind and re-mounts get the tag flag? */
7109 +               if (flags & (MS_BIND|MS_REMOUNT))
7110 +                       flags |= MS_TAGID;
7111 +       }
7112 +
7113         /* Separate the per-mountpoint flags */
7114         if (flags & MS_NOSUID)
7115                 mnt_flags |= MNT_NOSUID;
7116 @@ -2334,15 +2402,17 @@ long do_mount(char *dev_name, char *dir_
7117         if (flags & MS_RDONLY)
7118                 mnt_flags |= MNT_READONLY;
7119  
7120 +       if (!capable(CAP_SYS_ADMIN))
7121 +               mnt_flags |= MNT_NODEV;
7122         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
7123                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
7124                    MS_STRICTATIME);
7125  
7126         if (flags & MS_REMOUNT)
7127                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
7128 -                                   data_page);
7129 +                                   data_page, tag);
7130         else if (flags & MS_BIND)
7131 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
7132 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
7133         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
7134                 retval = do_change_type(&path, flags);
7135         else if (flags & MS_MOVE)
7136 @@ -2442,6 +2512,7 @@ static struct mnt_namespace *dup_mnt_ns(
7137                 q = next_mnt(q, new_ns->root);
7138         }
7139         up_write(&namespace_sem);
7140 +       atomic_inc(&vs_global_mnt_ns);
7141  
7142         if (rootmnt)
7143                 mntput(rootmnt);
7144 @@ -2581,9 +2652,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
7145                 goto out3;
7146  
7147         error = -EINVAL;
7148 -       if (IS_MNT_SHARED(old.mnt) ||
7149 -               IS_MNT_SHARED(new.mnt->mnt_parent) ||
7150 -               IS_MNT_SHARED(root.mnt->mnt_parent))
7151 +       if ((IS_MNT_SHARED(old.mnt) ||
7152 +               IS_MNT_SHARED(new.mnt->mnt_parent) ||
7153 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
7154 +               !vx_flags(VXF_STATE_SETUP, 0))
7155                 goto out4;
7156         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
7157                 goto out4;
7158 @@ -2715,6 +2787,7 @@ void put_mnt_ns(struct mnt_namespace *ns
7159         br_write_unlock(vfsmount_lock);
7160         up_write(&namespace_sem);
7161         release_mounts(&umount_list);
7162 +       atomic_dec(&vs_global_mnt_ns);
7163         kfree(ns);
7164  }
7165  EXPORT_SYMBOL(put_mnt_ns);
7166 diff -NurpP --minimal linux-3.0/fs/nfs/client.c linux-3.0-vs2.3.1-pre6/fs/nfs/client.c
7167 --- linux-3.0/fs/nfs/client.c   2011-07-22 11:18:05.000000000 +0200
7168 +++ linux-3.0-vs2.3.1-pre6/fs/nfs/client.c      2011-06-10 22:11:24.000000000 +0200
7169 @@ -780,6 +780,9 @@ static int nfs_init_server_rpcclient(str
7170         if (server->flags & NFS_MOUNT_SOFT)
7171                 server->client->cl_softrtry = 1;
7172  
7173 +       server->client->cl_tag = 0;
7174 +       if (server->flags & NFS_MOUNT_TAGGED)
7175 +               server->client->cl_tag = 1;
7176         return 0;
7177  }
7178  
7179 @@ -951,6 +954,10 @@ static void nfs_server_set_fsinfo(struct
7180                 server->acdirmin = server->acdirmax = 0;
7181         }
7182  
7183 +       /* FIXME: needs fsinfo
7184 +       if (server->flags & NFS_MOUNT_TAGGED)
7185 +               sb->s_flags |= MS_TAGGED;       */
7186 +
7187         server->maxfilesize = fsinfo->maxfilesize;
7188  
7189         server->time_delta = fsinfo->time_delta;
7190 diff -NurpP --minimal linux-3.0/fs/nfs/dir.c linux-3.0-vs2.3.1-pre6/fs/nfs/dir.c
7191 --- linux-3.0/fs/nfs/dir.c      2011-07-22 11:18:05.000000000 +0200
7192 +++ linux-3.0-vs2.3.1-pre6/fs/nfs/dir.c 2011-06-10 22:11:24.000000000 +0200
7193 @@ -35,6 +35,7 @@
7194  #include <linux/sched.h>
7195  #include <linux/kmemleak.h>
7196  #include <linux/xattr.h>
7197 +#include <linux/vs_tag.h>
7198  
7199  #include "delegation.h"
7200  #include "iostat.h"
7201 @@ -1298,6 +1299,7 @@ static struct dentry *nfs_lookup(struct 
7202         if (IS_ERR(res))
7203                 goto out_unblock_sillyrename;
7204  
7205 +       dx_propagate_tag(nd, inode);
7206  no_entry:
7207         res = d_materialise_unique(dentry, inode);
7208         if (res != NULL) {
7209 diff -NurpP --minimal linux-3.0/fs/nfs/inode.c linux-3.0-vs2.3.1-pre6/fs/nfs/inode.c
7210 --- linux-3.0/fs/nfs/inode.c    2011-07-22 11:18:05.000000000 +0200
7211 +++ linux-3.0-vs2.3.1-pre6/fs/nfs/inode.c       2011-07-01 11:35:34.000000000 +0200
7212 @@ -38,6 +38,7 @@
7213  #include <linux/nfs_xdr.h>
7214  #include <linux/slab.h>
7215  #include <linux/compat.h>
7216 +#include <linux/vs_tag.h>
7217  
7218  #include <asm/system.h>
7219  #include <asm/uaccess.h>
7220 @@ -273,6 +274,8 @@ nfs_fhget(struct super_block *sb, struct
7221         if (inode->i_state & I_NEW) {
7222                 struct nfs_inode *nfsi = NFS_I(inode);
7223                 unsigned long now = jiffies;
7224 +               uid_t uid;
7225 +               gid_t gid;
7226  
7227                 /* We set i_ino for the few things that still rely on it,
7228                  * such as stat(2) */
7229 @@ -321,8 +324,8 @@ nfs_fhget(struct super_block *sb, struct
7230                 nfsi->change_attr = 0;
7231                 inode->i_size = 0;
7232                 inode->i_nlink = 0;
7233 -               inode->i_uid = -2;
7234 -               inode->i_gid = -2;
7235 +               uid = -2;
7236 +               gid = -2;
7237                 inode->i_blocks = 0;
7238                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
7239  
7240 @@ -359,13 +362,13 @@ nfs_fhget(struct super_block *sb, struct
7241                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
7242                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
7243                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
7244 -                       inode->i_uid = fattr->uid;
7245 +                       uid = fattr->uid;
7246                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
7247                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
7248                                 | NFS_INO_INVALID_ACCESS
7249                                 | NFS_INO_INVALID_ACL;
7250                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
7251 -                       inode->i_gid = fattr->gid;
7252 +                       gid = fattr->gid;
7253                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
7254                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
7255                                 | NFS_INO_INVALID_ACCESS
7256 @@ -378,6 +381,11 @@ nfs_fhget(struct super_block *sb, struct
7257                          */
7258                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
7259                 }
7260 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7261 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7262 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7263 +                               /* maybe fattr->xid someday */
7264 +
7265                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
7266                 nfsi->attrtimeo_timestamp = now;
7267                 nfsi->access_cache = RB_ROOT;
7268 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
7269                         inode->i_uid = attr->ia_uid;
7270                 if ((attr->ia_valid & ATTR_GID) != 0)
7271                         inode->i_gid = attr->ia_gid;
7272 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
7273 +                       inode->i_tag = attr->ia_tag;
7274                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7275                 spin_unlock(&inode->i_lock);
7276         }
7277 @@ -941,6 +951,9 @@ static int nfs_check_inode_attributes(st
7278         struct nfs_inode *nfsi = NFS_I(inode);
7279         loff_t cur_size, new_isize;
7280         unsigned long invalid = 0;
7281 +       uid_t uid;
7282 +       gid_t gid;
7283 +       tag_t tag;
7284  
7285  
7286         /* Has the inode gone and changed behind our back? */
7287 @@ -964,13 +977,18 @@ static int nfs_check_inode_attributes(st
7288                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
7289         }
7290  
7291 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7292 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7293 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7294 +
7295         /* Have any file permissions changed? */
7296         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
7297                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7298 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
7299 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
7300                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7301 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
7302 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
7303                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7304 +               /* maybe check for tag too? */
7305  
7306         /* Has the link count changed? */
7307         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
7308 @@ -1205,6 +1223,9 @@ static int nfs_update_inode(struct inode
7309         unsigned long invalid = 0;
7310         unsigned long now = jiffies;
7311         unsigned long save_cache_validity;
7312 +       uid_t uid;
7313 +       gid_t gid;
7314 +       tag_t tag;
7315  
7316         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
7317                         __func__, inode->i_sb->s_id, inode->i_ino,
7318 @@ -1312,6 +1333,9 @@ static int nfs_update_inode(struct inode
7319                                 | NFS_INO_REVAL_PAGECACHE
7320                                 | NFS_INO_REVAL_FORCED);
7321  
7322 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7323 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7324 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7325  
7326         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
7327                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
7328 @@ -1333,9 +1357,9 @@ static int nfs_update_inode(struct inode
7329                                 | NFS_INO_REVAL_FORCED);
7330  
7331         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
7332 -               if (inode->i_uid != fattr->uid) {
7333 +               if (uid != fattr->uid) {
7334                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7335 -                       inode->i_uid = fattr->uid;
7336 +                       uid = fattr->uid;
7337                 }
7338         } else if (server->caps & NFS_CAP_OWNER)
7339                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
7340 @@ -1344,9 +1368,9 @@ static int nfs_update_inode(struct inode
7341                                 | NFS_INO_REVAL_FORCED);
7342  
7343         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
7344 -               if (inode->i_gid != fattr->gid) {
7345 +               if (gid != fattr->gid) {
7346                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7347 -                       inode->i_gid = fattr->gid;
7348 +                       gid = fattr->gid;
7349                 }
7350         } else if (server->caps & NFS_CAP_OWNER_GROUP)
7351                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
7352 @@ -1354,6 +1378,10 @@ static int nfs_update_inode(struct inode
7353                                 | NFS_INO_INVALID_ACL
7354                                 | NFS_INO_REVAL_FORCED);
7355  
7356 +       inode->i_uid = uid;
7357 +       inode->i_gid = gid;
7358 +       inode->i_tag = tag;
7359 +
7360         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
7361                 if (inode->i_nlink != fattr->nlink) {
7362                         invalid |= NFS_INO_INVALID_ATTR;
7363 diff -NurpP --minimal linux-3.0/fs/nfs/nfs3xdr.c linux-3.0-vs2.3.1-pre6/fs/nfs/nfs3xdr.c
7364 --- linux-3.0/fs/nfs/nfs3xdr.c  2011-03-15 18:07:32.000000000 +0100
7365 +++ linux-3.0-vs2.3.1-pre6/fs/nfs/nfs3xdr.c     2011-06-10 22:11:24.000000000 +0200
7366 @@ -20,6 +20,7 @@
7367  #include <linux/nfs3.h>
7368  #include <linux/nfs_fs.h>
7369  #include <linux/nfsacl.h>
7370 +#include <linux/vs_tag.h>
7371  #include "internal.h"
7372  
7373  #define NFSDBG_FACILITY                NFSDBG_XDR
7374 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
7375   *             set_mtime       mtime;
7376   *     };
7377   */
7378 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
7379 +static void encode_sattr3(struct xdr_stream *xdr,
7380 +       const struct iattr *attr, int tag)
7381  {
7382         u32 nbytes;
7383         __be32 *p;
7384 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
7385         } else
7386                 *p++ = xdr_zero;
7387  
7388 -       if (attr->ia_valid & ATTR_UID) {
7389 +       if (attr->ia_valid & ATTR_UID ||
7390 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7391                 *p++ = xdr_one;
7392 -               *p++ = cpu_to_be32(attr->ia_uid);
7393 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
7394 +                       attr->ia_uid, attr->ia_tag));
7395         } else
7396                 *p++ = xdr_zero;
7397  
7398 -       if (attr->ia_valid & ATTR_GID) {
7399 +       if (attr->ia_valid & ATTR_GID ||
7400 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7401                 *p++ = xdr_one;
7402 -               *p++ = cpu_to_be32(attr->ia_gid);
7403 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
7404 +                       attr->ia_gid, attr->ia_tag));
7405         } else
7406                 *p++ = xdr_zero;
7407  
7408 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
7409                                       const struct nfs3_sattrargs *args)
7410  {
7411         encode_nfs_fh3(xdr, args->fh);
7412 -       encode_sattr3(xdr, args->sattr);
7413 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
7414         encode_sattrguard3(xdr, args);
7415  }
7416  
7417 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
7418   *     };
7419   */
7420  static void encode_createhow3(struct xdr_stream *xdr,
7421 -                             const struct nfs3_createargs *args)
7422 +       const struct nfs3_createargs *args, int tag)
7423  {
7424         encode_uint32(xdr, args->createmode);
7425         switch (args->createmode) {
7426         case NFS3_CREATE_UNCHECKED:
7427         case NFS3_CREATE_GUARDED:
7428 -               encode_sattr3(xdr, args->sattr);
7429 +               encode_sattr3(xdr, args->sattr, tag);
7430                 break;
7431         case NFS3_CREATE_EXCLUSIVE:
7432                 encode_createverf3(xdr, args->verifier);
7433 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
7434                                      const struct nfs3_createargs *args)
7435  {
7436         encode_diropargs3(xdr, args->fh, args->name, args->len);
7437 -       encode_createhow3(xdr, args);
7438 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
7439  }
7440  
7441  /*
7442 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
7443                                     const struct nfs3_mkdirargs *args)
7444  {
7445         encode_diropargs3(xdr, args->fh, args->name, args->len);
7446 -       encode_sattr3(xdr, args->sattr);
7447 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
7448  }
7449  
7450  /*
7451 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
7452   *     };
7453   */
7454  static void encode_symlinkdata3(struct xdr_stream *xdr,
7455 -                               const struct nfs3_symlinkargs *args)
7456 +       const struct nfs3_symlinkargs *args, int tag)
7457  {
7458 -       encode_sattr3(xdr, args->sattr);
7459 +       encode_sattr3(xdr, args->sattr, tag);
7460         encode_nfspath3(xdr, args->pages, args->pathlen);
7461  }
7462  
7463 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
7464                                       const struct nfs3_symlinkargs *args)
7465  {
7466         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
7467 -       encode_symlinkdata3(xdr, args);
7468 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
7469  }
7470  
7471  /*
7472 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
7473   *     };
7474   */
7475  static void encode_devicedata3(struct xdr_stream *xdr,
7476 -                              const struct nfs3_mknodargs *args)
7477 +       const struct nfs3_mknodargs *args, int tag)
7478  {
7479 -       encode_sattr3(xdr, args->sattr);
7480 +       encode_sattr3(xdr, args->sattr, tag);
7481         encode_specdata3(xdr, args->rdev);
7482  }
7483  
7484  static void encode_mknoddata3(struct xdr_stream *xdr,
7485 -                             const struct nfs3_mknodargs *args)
7486 +       const struct nfs3_mknodargs *args, int tag)
7487  {
7488         encode_ftype3(xdr, args->type);
7489         switch (args->type) {
7490         case NF3CHR:
7491         case NF3BLK:
7492 -               encode_devicedata3(xdr, args);
7493 +               encode_devicedata3(xdr, args, tag);
7494                 break;
7495         case NF3SOCK:
7496         case NF3FIFO:
7497 -               encode_sattr3(xdr, args->sattr);
7498 +               encode_sattr3(xdr, args->sattr, tag);
7499                 break;
7500         case NF3REG:
7501         case NF3DIR:
7502 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
7503                                     const struct nfs3_mknodargs *args)
7504  {
7505         encode_diropargs3(xdr, args->fh, args->name, args->len);
7506 -       encode_mknoddata3(xdr, args);
7507 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
7508  }
7509  
7510  /*
7511 diff -NurpP --minimal linux-3.0/fs/nfs/super.c linux-3.0-vs2.3.1-pre6/fs/nfs/super.c
7512 --- linux-3.0/fs/nfs/super.c    2011-07-22 11:18:05.000000000 +0200
7513 +++ linux-3.0-vs2.3.1-pre6/fs/nfs/super.c       2011-06-10 22:11:24.000000000 +0200
7514 @@ -53,6 +53,7 @@
7515  #include <linux/nfs_xdr.h>
7516  #include <linux/magic.h>
7517  #include <linux/parser.h>
7518 +#include <linux/vs_tag.h>
7519  
7520  #include <asm/system.h>
7521  #include <asm/uaccess.h>
7522 @@ -87,6 +88,7 @@ enum {
7523         Opt_sharecache, Opt_nosharecache,
7524         Opt_resvport, Opt_noresvport,
7525         Opt_fscache, Opt_nofscache,
7526 +       Opt_tag, Opt_notag,
7527  
7528         /* Mount options that take integer arguments */
7529         Opt_port,
7530 @@ -100,6 +102,7 @@ enum {
7531         Opt_mountvers,
7532         Opt_nfsvers,
7533         Opt_minorversion,
7534 +       Opt_tagid,
7535  
7536         /* Mount options that take string arguments */
7537         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
7538 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
7539         { Opt_fscache_uniq, "fsc=%s" },
7540         { Opt_local_lock, "local_lock=%s" },
7541  
7542 +       { Opt_tag, "tag" },
7543 +       { Opt_notag, "notag" },
7544 +       { Opt_tagid, "tagid=%u" },
7545 +
7546         { Opt_err, NULL }
7547  };
7548  
7549 @@ -650,6 +657,7 @@ static void nfs_show_mount_options(struc
7550                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
7551                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
7552                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
7553 +               { NFS_MOUNT_TAGGED, ",tag", "" },
7554                 { 0, NULL, NULL }
7555         };
7556         const struct proc_nfs_info *nfs_infop;
7557 @@ -1198,6 +1206,14 @@ static int nfs_parse_mount_options(char 
7558                         kfree(mnt->fscache_uniq);
7559                         mnt->fscache_uniq = NULL;
7560                         break;
7561 +#ifndef CONFIG_TAGGING_NONE
7562 +               case Opt_tag:
7563 +                       mnt->flags |= NFS_MOUNT_TAGGED;
7564 +                       break;
7565 +               case Opt_notag:
7566 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
7567 +                       break;
7568 +#endif
7569  
7570                 /*
7571                  * options that take numeric values
7572 @@ -1304,6 +1320,12 @@ static int nfs_parse_mount_options(char 
7573                                 goto out_invalid_value;
7574                         mnt->minorversion = option;
7575                         break;
7576 +#ifdef CONFIG_PROPAGATE
7577 +               case Opt_tagid:
7578 +                       /* use args[0] */
7579 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
7580 +                       break;
7581 +#endif
7582  
7583                 /*
7584                  * options that take text values
7585 diff -NurpP --minimal linux-3.0/fs/nfsd/auth.c linux-3.0-vs2.3.1-pre6/fs/nfsd/auth.c
7586 --- linux-3.0/fs/nfsd/auth.c    2010-02-25 11:52:05.000000000 +0100
7587 +++ linux-3.0-vs2.3.1-pre6/fs/nfsd/auth.c       2011-06-10 22:11:24.000000000 +0200
7588 @@ -1,6 +1,7 @@
7589  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
7590  
7591  #include <linux/sched.h>
7592 +#include <linux/vs_tag.h>
7593  #include "nfsd.h"
7594  #include "auth.h"
7595  
7596 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
7597  
7598         new->fsuid = rqstp->rq_cred.cr_uid;
7599         new->fsgid = rqstp->rq_cred.cr_gid;
7600 +       /* FIXME: this desperately needs a tag :)
7601 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
7602 +                       */
7603  
7604         rqgi = rqstp->rq_cred.cr_group_info;
7605  
7606 diff -NurpP --minimal linux-3.0/fs/nfsd/nfs3xdr.c linux-3.0-vs2.3.1-pre6/fs/nfsd/nfs3xdr.c
7607 --- linux-3.0/fs/nfsd/nfs3xdr.c 2011-07-22 11:18:05.000000000 +0200
7608 +++ linux-3.0-vs2.3.1-pre6/fs/nfsd/nfs3xdr.c    2011-06-10 22:11:24.000000000 +0200
7609 @@ -7,6 +7,7 @@
7610   */
7611  
7612  #include <linux/namei.h>
7613 +#include <linux/vs_tag.h>
7614  #include "xdr3.h"
7615  #include "auth.h"
7616  
7617 @@ -95,6 +96,8 @@ static __be32 *
7618  decode_sattr3(__be32 *p, struct iattr *iap)
7619  {
7620         u32     tmp;
7621 +       uid_t   uid = 0;
7622 +       gid_t   gid = 0;
7623  
7624         iap->ia_valid = 0;
7625  
7626 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
7627         }
7628         if (*p++) {
7629                 iap->ia_valid |= ATTR_UID;
7630 -               iap->ia_uid = ntohl(*p++);
7631 +               uid = ntohl(*p++);
7632         }
7633         if (*p++) {
7634                 iap->ia_valid |= ATTR_GID;
7635 -               iap->ia_gid = ntohl(*p++);
7636 +               gid = ntohl(*p++);
7637         }
7638 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7639 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7640 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7641         if (*p++) {
7642                 u64     newsize;
7643  
7644 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
7645         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
7646         *p++ = htonl((u32) stat->mode);
7647         *p++ = htonl((u32) stat->nlink);
7648 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7649 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7650 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7651 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
7652 +               stat->uid, stat->tag)));
7653 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7654 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
7655 +               stat->gid, stat->tag)));
7656         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
7657                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
7658         } else {
7659 diff -NurpP --minimal linux-3.0/fs/nfsd/nfs4xdr.c linux-3.0-vs2.3.1-pre6/fs/nfsd/nfs4xdr.c
7660 --- linux-3.0/fs/nfsd/nfs4xdr.c 2011-07-22 11:18:05.000000000 +0200
7661 +++ linux-3.0-vs2.3.1-pre6/fs/nfsd/nfs4xdr.c    2011-06-10 22:11:24.000000000 +0200
7662 @@ -45,6 +45,7 @@
7663  #include <linux/statfs.h>
7664  #include <linux/utsname.h>
7665  #include <linux/sunrpc/svcauth_gss.h>
7666 +#include <linux/vs_tag.h>
7667  
7668  #include "idmap.h"
7669  #include "acl.h"
7670 @@ -2090,14 +2091,18 @@ out_acl:
7671                 WRITE32(stat.nlink);
7672         }
7673         if (bmval1 & FATTR4_WORD1_OWNER) {
7674 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
7675 +               status = nfsd4_encode_user(rqstp,
7676 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
7677 +                       stat.uid, stat.tag), &p, &buflen);
7678                 if (status == nfserr_resource)
7679                         goto out_resource;
7680                 if (status)
7681                         goto out;
7682         }
7683         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
7684 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
7685 +               status = nfsd4_encode_group(rqstp,
7686 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
7687 +                       stat.gid, stat.tag), &p, &buflen);
7688                 if (status == nfserr_resource)
7689                         goto out_resource;
7690                 if (status)
7691 diff -NurpP --minimal linux-3.0/fs/nfsd/nfsxdr.c linux-3.0-vs2.3.1-pre6/fs/nfsd/nfsxdr.c
7692 --- linux-3.0/fs/nfsd/nfsxdr.c  2011-05-22 16:17:53.000000000 +0200
7693 +++ linux-3.0-vs2.3.1-pre6/fs/nfsd/nfsxdr.c     2011-06-10 22:11:24.000000000 +0200
7694 @@ -6,6 +6,7 @@
7695  
7696  #include "xdr.h"
7697  #include "auth.h"
7698 +#include <linux/vs_tag.h>
7699  
7700  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7701  
7702 @@ -88,6 +89,8 @@ static __be32 *
7703  decode_sattr(__be32 *p, struct iattr *iap)
7704  {
7705         u32     tmp, tmp1;
7706 +       uid_t   uid = 0;
7707 +       gid_t   gid = 0;
7708  
7709         iap->ia_valid = 0;
7710  
7711 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
7712         }
7713         if ((tmp = ntohl(*p++)) != (u32)-1) {
7714                 iap->ia_valid |= ATTR_UID;
7715 -               iap->ia_uid = tmp;
7716 +               uid = tmp;
7717         }
7718         if ((tmp = ntohl(*p++)) != (u32)-1) {
7719                 iap->ia_valid |= ATTR_GID;
7720 -               iap->ia_gid = tmp;
7721 +               gid = tmp;
7722         }
7723 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7724 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7725 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7726         if ((tmp = ntohl(*p++)) != (u32)-1) {
7727                 iap->ia_valid |= ATTR_SIZE;
7728                 iap->ia_size = tmp;
7729 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
7730         *p++ = htonl(nfs_ftypes[type >> 12]);
7731         *p++ = htonl((u32) stat->mode);
7732         *p++ = htonl((u32) stat->nlink);
7733 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7734 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7735 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7736 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7737 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7738 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7739  
7740         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
7741                 *p++ = htonl(NFS_MAXPATHLEN);
7742 diff -NurpP --minimal linux-3.0/fs/ocfs2/dlmglue.c linux-3.0-vs2.3.1-pre6/fs/ocfs2/dlmglue.c
7743 --- linux-3.0/fs/ocfs2/dlmglue.c        2011-05-22 16:17:53.000000000 +0200
7744 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/dlmglue.c   2011-06-10 22:11:24.000000000 +0200
7745 @@ -2041,6 +2041,7 @@ static void __ocfs2_stuff_meta_lvb(struc
7746         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
7747         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
7748         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
7749 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
7750         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
7751         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
7752         lvb->lvb_iatime_packed  =
7753 @@ -2091,6 +2092,7 @@ static void ocfs2_refresh_inode_from_lvb
7754  
7755         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
7756         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
7757 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
7758         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
7759         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
7760         ocfs2_unpack_timespec(&inode->i_atime,
7761 diff -NurpP --minimal linux-3.0/fs/ocfs2/dlmglue.h linux-3.0-vs2.3.1-pre6/fs/ocfs2/dlmglue.h
7762 --- linux-3.0/fs/ocfs2/dlmglue.h        2010-10-21 13:07:50.000000000 +0200
7763 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/dlmglue.h   2011-06-10 22:11:24.000000000 +0200
7764 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
7765         __be16       lvb_inlink;
7766         __be32       lvb_iattr;
7767         __be32       lvb_igeneration;
7768 -       __be32       lvb_reserved2;
7769 +       __be16       lvb_itag;
7770 +       __be16       lvb_reserved2;
7771  };
7772  
7773  #define OCFS2_QINFO_LVB_VERSION 1
7774 diff -NurpP --minimal linux-3.0/fs/ocfs2/file.c linux-3.0-vs2.3.1-pre6/fs/ocfs2/file.c
7775 --- linux-3.0/fs/ocfs2/file.c   2011-07-22 11:18:06.000000000 +0200
7776 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/file.c      2011-06-10 22:43:33.000000000 +0200
7777 @@ -1111,7 +1111,7 @@ int ocfs2_setattr(struct dentry *dentry,
7778                 attr->ia_valid &= ~ATTR_SIZE;
7779  
7780  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
7781 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
7782 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
7783         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
7784                 return 0;
7785  
7786 diff -NurpP --minimal linux-3.0/fs/ocfs2/inode.c linux-3.0-vs2.3.1-pre6/fs/ocfs2/inode.c
7787 --- linux-3.0/fs/ocfs2/inode.c  2011-05-22 16:17:53.000000000 +0200
7788 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/inode.c     2011-06-10 22:11:24.000000000 +0200
7789 @@ -28,6 +28,7 @@
7790  #include <linux/highmem.h>
7791  #include <linux/pagemap.h>
7792  #include <linux/quotaops.h>
7793 +#include <linux/vs_tag.h>
7794  
7795  #include <asm/byteorder.h>
7796  
7797 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
7798  {
7799         unsigned int flags = OCFS2_I(inode)->ip_attr;
7800  
7801 -       inode->i_flags &= ~(S_IMMUTABLE |
7802 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
7803                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
7804  
7805         if (flags & OCFS2_IMMUTABLE_FL)
7806                 inode->i_flags |= S_IMMUTABLE;
7807 +       if (flags & OCFS2_IXUNLINK_FL)
7808 +               inode->i_flags |= S_IXUNLINK;
7809  
7810         if (flags & OCFS2_SYNC_FL)
7811                 inode->i_flags |= S_SYNC;
7812 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
7813                 inode->i_flags |= S_NOATIME;
7814         if (flags & OCFS2_DIRSYNC_FL)
7815                 inode->i_flags |= S_DIRSYNC;
7816 +
7817 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
7818 +
7819 +       if (flags & OCFS2_BARRIER_FL)
7820 +               inode->i_vflags |= V_BARRIER;
7821 +       if (flags & OCFS2_COW_FL)
7822 +               inode->i_vflags |= V_COW;
7823  }
7824  
7825  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
7826  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
7827  {
7828         unsigned int flags = oi->vfs_inode.i_flags;
7829 +       unsigned int vflags = oi->vfs_inode.i_vflags;
7830 +
7831 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
7832 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
7833 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
7834 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
7835 +
7836 +       if (flags & S_IMMUTABLE)
7837 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
7838 +       if (flags & S_IXUNLINK)
7839 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
7840  
7841 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
7842 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
7843         if (flags & S_SYNC)
7844                 oi->ip_attr |= OCFS2_SYNC_FL;
7845         if (flags & S_APPEND)
7846                 oi->ip_attr |= OCFS2_APPEND_FL;
7847 -       if (flags & S_IMMUTABLE)
7848 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
7849         if (flags & S_NOATIME)
7850                 oi->ip_attr |= OCFS2_NOATIME_FL;
7851         if (flags & S_DIRSYNC)
7852                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
7853 +
7854 +       if (vflags & V_BARRIER)
7855 +               oi->ip_attr |= OCFS2_BARRIER_FL;
7856 +       if (vflags & V_COW)
7857 +               oi->ip_attr |= OCFS2_COW_FL;
7858  }
7859  
7860  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
7861 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
7862         struct super_block *sb;
7863         struct ocfs2_super *osb;
7864         int use_plocks = 1;
7865 +       uid_t uid;
7866 +       gid_t gid;
7867  
7868         sb = inode->i_sb;
7869         osb = OCFS2_SB(sb);
7870 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
7871         inode->i_generation = le32_to_cpu(fe->i_generation);
7872         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
7873         inode->i_mode = le16_to_cpu(fe->i_mode);
7874 -       inode->i_uid = le32_to_cpu(fe->i_uid);
7875 -       inode->i_gid = le32_to_cpu(fe->i_gid);
7876 +       uid = le32_to_cpu(fe->i_uid);
7877 +       gid = le32_to_cpu(fe->i_gid);
7878 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7879 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7880 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
7881 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
7882  
7883         /* Fast symlinks will have i_size but no allocated clusters. */
7884         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
7885 diff -NurpP --minimal linux-3.0/fs/ocfs2/inode.h linux-3.0-vs2.3.1-pre6/fs/ocfs2/inode.h
7886 --- linux-3.0/fs/ocfs2/inode.h  2011-01-05 21:50:26.000000000 +0100
7887 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/inode.h     2011-06-10 22:11:24.000000000 +0200
7888 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
7889  
7890  void ocfs2_set_inode_flags(struct inode *inode);
7891  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
7892 +int ocfs2_sync_flags(struct inode *inode, int, int);
7893  
7894  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
7895  {
7896 diff -NurpP --minimal linux-3.0/fs/ocfs2/ioctl.c linux-3.0-vs2.3.1-pre6/fs/ocfs2/ioctl.c
7897 --- linux-3.0/fs/ocfs2/ioctl.c  2011-07-22 11:18:06.000000000 +0200
7898 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/ioctl.c     2011-06-10 22:11:24.000000000 +0200
7899 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
7900         return status;
7901  }
7902  
7903 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7904 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
7905 +{
7906 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
7907 +       struct buffer_head *bh = NULL;
7908 +       handle_t *handle = NULL;
7909 +       int status;
7910 +
7911 +       status = ocfs2_inode_lock(inode, &bh, 1);
7912 +       if (status < 0) {
7913 +               mlog_errno(status);
7914 +               return status;
7915 +       }
7916 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
7917 +       if (IS_ERR(handle)) {
7918 +               status = PTR_ERR(handle);
7919 +               mlog_errno(status);
7920 +               goto bail_unlock;
7921 +       }
7922 +
7923 +       inode->i_flags = flags;
7924 +       inode->i_vflags = vflags;
7925 +       ocfs2_get_inode_flags(OCFS2_I(inode));
7926 +
7927 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
7928 +       if (status < 0)
7929 +               mlog_errno(status);
7930 +
7931 +       ocfs2_commit_trans(osb, handle);
7932 +bail_unlock:
7933 +       ocfs2_inode_unlock(inode, 1);
7934 +       brelse(bh);
7935 +       return status;
7936 +}
7937 +
7938 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7939                                 unsigned mask)
7940  {
7941         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
7942 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
7943         if (!S_ISDIR(inode->i_mode))
7944                 flags &= ~OCFS2_DIRSYNC_FL;
7945  
7946 +       if (IS_BARRIER(inode)) {
7947 +               vxwprintk_task(1, "messing with the barrier.");
7948 +               goto bail_unlock;
7949 +       }
7950 +
7951         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
7952         if (IS_ERR(handle)) {
7953                 status = PTR_ERR(handle);
7954 @@ -880,6 +919,7 @@ bail:
7955         return status;
7956  }
7957  
7958 +
7959  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7960  {
7961         struct inode *inode = filp->f_path.dentry->d_inode;
7962 diff -NurpP --minimal linux-3.0/fs/ocfs2/namei.c linux-3.0-vs2.3.1-pre6/fs/ocfs2/namei.c
7963 --- linux-3.0/fs/ocfs2/namei.c  2011-05-22 16:17:53.000000000 +0200
7964 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/namei.c     2011-06-10 22:11:24.000000000 +0200
7965 @@ -41,6 +41,7 @@
7966  #include <linux/slab.h>
7967  #include <linux/highmem.h>
7968  #include <linux/quotaops.h>
7969 +#include <linux/vs_tag.h>
7970  
7971  #include <cluster/masklog.h>
7972  
7973 @@ -477,6 +478,7 @@ static int __ocfs2_mknod_locked(struct i
7974         struct ocfs2_dinode *fe = NULL;
7975         struct ocfs2_extent_list *fel;
7976         u16 feat;
7977 +       tag_t tag;
7978  
7979         *new_fe_bh = NULL;
7980  
7981 @@ -514,8 +516,11 @@ static int __ocfs2_mknod_locked(struct i
7982         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
7983         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
7984         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
7985 -       fe->i_uid = cpu_to_le32(inode->i_uid);
7986 -       fe->i_gid = cpu_to_le32(inode->i_gid);
7987 +
7988 +       tag = dx_current_fstag(osb->sb);
7989 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
7990 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
7991 +       inode->i_tag = tag;
7992         fe->i_mode = cpu_to_le16(inode->i_mode);
7993         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
7994                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
7995 diff -NurpP --minimal linux-3.0/fs/ocfs2/ocfs2.h linux-3.0-vs2.3.1-pre6/fs/ocfs2/ocfs2.h
7996 --- linux-3.0/fs/ocfs2/ocfs2.h  2011-05-22 16:17:53.000000000 +0200
7997 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/ocfs2.h     2011-06-10 22:11:24.000000000 +0200
7998 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
7999                                                      writes */
8000         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
8001         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
8002 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
8003  };
8004  
8005  #define OCFS2_OSB_SOFT_RO                      0x0001
8006 diff -NurpP --minimal linux-3.0/fs/ocfs2/ocfs2_fs.h linux-3.0-vs2.3.1-pre6/fs/ocfs2/ocfs2_fs.h
8007 --- linux-3.0/fs/ocfs2/ocfs2_fs.h       2011-05-22 16:17:53.000000000 +0200
8008 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/ocfs2_fs.h  2011-06-10 22:11:24.000000000 +0200
8009 @@ -266,6 +266,11 @@
8010  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
8011  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
8012  
8013 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
8014 +
8015 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
8016 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
8017 +
8018  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
8019  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8020  
8021 diff -NurpP --minimal linux-3.0/fs/ocfs2/super.c linux-3.0-vs2.3.1-pre6/fs/ocfs2/super.c
8022 --- linux-3.0/fs/ocfs2/super.c  2011-07-22 11:18:06.000000000 +0200
8023 +++ linux-3.0-vs2.3.1-pre6/fs/ocfs2/super.c     2011-06-15 02:40:14.000000000 +0200
8024 @@ -184,6 +184,7 @@ enum {
8025         Opt_coherency_full,
8026         Opt_resv_level,
8027         Opt_dir_resv_level,
8028 +       Opt_tag, Opt_notag, Opt_tagid,
8029         Opt_err,
8030  };
8031  
8032 @@ -215,6 +216,9 @@ static const match_table_t tokens = {
8033         {Opt_coherency_full, "coherency=full"},
8034         {Opt_resv_level, "resv_level=%u"},
8035         {Opt_dir_resv_level, "dir_resv_level=%u"},
8036 +       {Opt_tag, "tag"},
8037 +       {Opt_notag, "notag"},
8038 +       {Opt_tagid, "tagid=%u"},
8039         {Opt_err, NULL}
8040  };
8041  
8042 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
8043                 goto out;
8044         }
8045  
8046 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
8047 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
8048 +               ret = -EINVAL;
8049 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
8050 +               goto out;
8051 +       }
8052 +
8053         /* We're going to/from readonly mode. */
8054         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
8055                 /* Disable quota accounting before remounting RO */
8056 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
8057  
8058         ocfs2_complete_mount_recovery(osb);
8059  
8060 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
8061 +               sb->s_flags |= MS_TAGGED;
8062 +
8063         if (ocfs2_mount_local(osb))
8064                 snprintf(nodestr, sizeof(nodestr), "local");
8065         else
8066 @@ -1506,6 +1520,20 @@ static int ocfs2_parse_options(struct su
8067                             option < OCFS2_MAX_RESV_LEVEL)
8068                                 mopt->dir_resv_level = option;
8069                         break;
8070 +#ifndef CONFIG_TAGGING_NONE
8071 +               case Opt_tag:
8072 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
8073 +                       break;
8074 +               case Opt_notag:
8075 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
8076 +                       break;
8077 +#endif
8078 +#ifdef CONFIG_PROPAGATE
8079 +               case Opt_tagid:
8080 +                       /* use args[0] */
8081 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
8082 +                       break;
8083 +#endif
8084                 default:
8085                         mlog(ML_ERROR,
8086                              "Unrecognized mount option \"%s\" "
8087 diff -NurpP --minimal linux-3.0/fs/open.c linux-3.0-vs2.3.1-pre6/fs/open.c
8088 --- linux-3.0/fs/open.c 2011-05-22 16:17:53.000000000 +0200
8089 +++ linux-3.0-vs2.3.1-pre6/fs/open.c    2011-06-10 22:11:24.000000000 +0200
8090 @@ -30,6 +30,11 @@
8091  #include <linux/fs_struct.h>
8092  #include <linux/ima.h>
8093  #include <linux/dnotify.h>
8094 +#include <linux/vs_base.h>
8095 +#include <linux/vs_limit.h>
8096 +#include <linux/vs_tag.h>
8097 +#include <linux/vs_cowbl.h>
8098 +#include <linux/vserver/dlimit.h>
8099  
8100  #include "internal.h"
8101  
8102 @@ -494,6 +499,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
8103         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
8104         if (error)
8105                 goto out;
8106 +
8107 +#ifdef CONFIG_VSERVER_COWBL
8108 +       error = cow_check_and_break(&path);
8109 +       if (error)
8110 +               goto dput_and_out;
8111 +#endif
8112         inode = path.dentry->d_inode;
8113  
8114         error = mnt_want_write(path.mnt);
8115 @@ -531,11 +542,11 @@ static int chown_common(struct path *pat
8116         newattrs.ia_valid =  ATTR_CTIME;
8117         if (user != (uid_t) -1) {
8118                 newattrs.ia_valid |= ATTR_UID;
8119 -               newattrs.ia_uid = user;
8120 +               newattrs.ia_uid = dx_map_uid(user);
8121         }
8122         if (group != (gid_t) -1) {
8123                 newattrs.ia_valid |= ATTR_GID;
8124 -               newattrs.ia_gid = group;
8125 +               newattrs.ia_gid = dx_map_gid(group);
8126         }
8127         if (!S_ISDIR(inode->i_mode))
8128                 newattrs.ia_valid |=
8129 @@ -560,6 +571,10 @@ SYSCALL_DEFINE3(chown, const char __user
8130         error = mnt_want_write(path.mnt);
8131         if (error)
8132                 goto out_release;
8133 +#ifdef CONFIG_VSERVER_COWBL
8134 +       error = cow_check_and_break(&path);
8135 +       if (!error)
8136 +#endif
8137         error = chown_common(&path, user, group);
8138         mnt_drop_write(path.mnt);
8139  out_release:
8140 @@ -587,6 +602,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
8141         error = mnt_want_write(path.mnt);
8142         if (error)
8143                 goto out_release;
8144 +#ifdef CONFIG_VSERVER_COWBL
8145 +       error = cow_check_and_break(&path);
8146 +       if (!error)
8147 +#endif
8148         error = chown_common(&path, user, group);
8149         mnt_drop_write(path.mnt);
8150  out_release:
8151 @@ -606,6 +625,10 @@ SYSCALL_DEFINE3(lchown, const char __use
8152         error = mnt_want_write(path.mnt);
8153         if (error)
8154                 goto out_release;
8155 +#ifdef CONFIG_VSERVER_COWBL
8156 +       error = cow_check_and_break(&path);
8157 +       if (!error)
8158 +#endif
8159         error = chown_common(&path, user, group);
8160         mnt_drop_write(path.mnt);
8161  out_release:
8162 @@ -857,6 +880,7 @@ static void __put_unused_fd(struct files
8163         __FD_CLR(fd, fdt->open_fds);
8164         if (fd < files->next_fd)
8165                 files->next_fd = fd;
8166 +       vx_openfd_dec(fd);
8167  }
8168  
8169  void put_unused_fd(unsigned int fd)
8170 diff -NurpP --minimal linux-3.0/fs/proc/array.c linux-3.0-vs2.3.1-pre6/fs/proc/array.c
8171 --- linux-3.0/fs/proc/array.c   2011-07-22 11:18:06.000000000 +0200
8172 +++ linux-3.0-vs2.3.1-pre6/fs/proc/array.c      2011-06-10 22:11:24.000000000 +0200
8173 @@ -81,6 +81,8 @@
8174  #include <linux/pid_namespace.h>
8175  #include <linux/ptrace.h>
8176  #include <linux/tracehook.h>
8177 +#include <linux/vs_context.h>
8178 +#include <linux/vs_network.h>
8179  
8180  #include <asm/pgtable.h>
8181  #include <asm/processor.h>
8182 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
8183         rcu_read_lock();
8184         ppid = pid_alive(p) ?
8185                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
8186 +       if (unlikely(vx_current_initpid(p->pid)))
8187 +               ppid = 0;
8188 +
8189         tpid = 0;
8190         if (pid_alive(p)) {
8191                 struct task_struct *tracer = tracehook_tracer_task(p);
8192 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
8193  }
8194  
8195  static void render_cap_t(struct seq_file *m, const char *header,
8196 -                       kernel_cap_t *a)
8197 +                       struct vx_info *vxi, kernel_cap_t *a)
8198  {
8199         unsigned __capi;
8200  
8201 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
8202         cap_bset        = cred->cap_bset;
8203         rcu_read_unlock();
8204  
8205 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
8206 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
8207 -       render_cap_t(m, "CapEff:\t", &cap_effective);
8208 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
8209 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
8210 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
8211 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
8212 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
8213 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
8214  }
8215  
8216  static inline void task_context_switch_counts(struct seq_file *m,
8217 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
8218         seq_putc(m, '\n');
8219  }
8220  
8221 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
8222 +                       struct pid *pid, struct task_struct *task)
8223 +{
8224 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
8225 +                       "Count:\t%u\n"
8226 +                       "uts:\t%p(%c)\n"
8227 +                       "ipc:\t%p(%c)\n"
8228 +                       "mnt:\t%p(%c)\n"
8229 +                       "pid:\t%p(%c)\n"
8230 +                       "net:\t%p(%c)\n",
8231 +                       task->nsproxy,
8232 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
8233 +                       atomic_read(&task->nsproxy->count),
8234 +                       task->nsproxy->uts_ns,
8235 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
8236 +                       task->nsproxy->ipc_ns,
8237 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
8238 +                       task->nsproxy->mnt_ns,
8239 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
8240 +                       task->nsproxy->pid_ns,
8241 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
8242 +                       task->nsproxy->net_ns,
8243 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
8244 +       return 0;
8245 +}
8246 +
8247 +void task_vs_id(struct seq_file *m, struct task_struct *task)
8248 +{
8249 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
8250 +               return;
8251 +
8252 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
8253 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
8254 +}
8255 +
8256 +
8257  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
8258                         struct pid *pid, struct task_struct *task)
8259  {
8260 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
8261         task_cap(m, task);
8262         task_cpus_allowed(m, task);
8263         cpuset_task_status_allowed(m, task);
8264 +       task_vs_id(m, task);
8265         task_context_switch_counts(m, task);
8266         return 0;
8267  }
8268 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
8269         /* convert nsec -> ticks */
8270         start_time = nsec_to_clock_t(start_time);
8271  
8272 +       /* fixup start time for virt uptime */
8273 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
8274 +               unsigned long long bias =
8275 +                       current->vx_info->cvirt.bias_clock;
8276 +
8277 +               if (start_time > bias)
8278 +                       start_time -= bias;
8279 +               else
8280 +                       start_time = 0;
8281 +       }
8282 +
8283         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
8284  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
8285  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
8286 diff -NurpP --minimal linux-3.0/fs/proc/base.c linux-3.0-vs2.3.1-pre6/fs/proc/base.c
8287 --- linux-3.0/fs/proc/base.c    2011-07-22 11:18:06.000000000 +0200
8288 +++ linux-3.0-vs2.3.1-pre6/fs/proc/base.c       2011-07-19 00:44:39.000000000 +0200
8289 @@ -83,6 +83,8 @@
8290  #include <linux/pid_namespace.h>
8291  #include <linux/fs_struct.h>
8292  #include <linux/slab.h>
8293 +#include <linux/vs_context.h>
8294 +#include <linux/vs_network.h>
8295  #ifdef CONFIG_HARDWALL
8296  #include <asm/hardwall.h>
8297  #endif
8298 @@ -1102,11 +1104,16 @@ static ssize_t oom_adjust_write(struct f
8299                 goto err_task_lock;
8300         }
8301  
8302 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
8303 +       if (oom_adjust < task->signal->oom_adj &&
8304 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
8305                 err = -EACCES;
8306                 goto err_sighand;
8307         }
8308  
8309 +       /* prevent guest processes from circumventing the oom killer */
8310 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
8311 +               oom_adjust = OOM_ADJUST_MIN;
8312 +
8313         if (oom_adjust != task->signal->oom_adj) {
8314                 if (oom_adjust == OOM_DISABLE)
8315                         atomic_inc(&task->mm->oom_disable_count);
8316 @@ -1275,7 +1282,7 @@ static ssize_t proc_loginuid_write(struc
8317         ssize_t length;
8318         uid_t loginuid;
8319  
8320 -       if (!capable(CAP_AUDIT_CONTROL))
8321 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
8322                 return -EPERM;
8323  
8324         rcu_read_lock();
8325 @@ -1722,6 +1729,8 @@ struct inode *proc_pid_make_inode(struct
8326                 inode->i_gid = cred->egid;
8327                 rcu_read_unlock();
8328         }
8329 +       /* procfs is xid tagged */
8330 +       inode->i_tag = (tag_t)vx_task_xid(task);
8331         security_task_to_inode(task, inode);
8332  
8333  out:
8334 @@ -1758,6 +1767,8 @@ int pid_getattr(struct vfsmount *mnt, st
8335  
8336  /* dentry stuff */
8337  
8338 +static unsigned name_to_int(struct dentry *dentry);
8339 +
8340  /*
8341   *     Exceptional case: normally we are not allowed to unhash a busy
8342   * directory. In this case, however, we can do it - no aliasing problems
8343 @@ -1786,6 +1797,12 @@ int pid_revalidate(struct dentry *dentry
8344         task = get_proc_task(inode);
8345  
8346         if (task) {
8347 +               unsigned pid = name_to_int(dentry);
8348 +
8349 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
8350 +                       put_task_struct(task);
8351 +                       goto drop;
8352 +               }
8353                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
8354                     task_dumpable(task)) {
8355                         rcu_read_lock();
8356 @@ -1802,6 +1819,7 @@ int pid_revalidate(struct dentry *dentry
8357                 put_task_struct(task);
8358                 return 1;
8359         }
8360 +drop:
8361         d_drop(dentry);
8362         return 0;
8363  }
8364 @@ -2283,6 +2301,13 @@ static struct dentry *proc_pident_lookup
8365         if (!task)
8366                 goto out_no_task;
8367  
8368 +       /* TODO: maybe we can come up with a generic approach? */
8369 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
8370 +               (dentry->d_name.len == 5) &&
8371 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
8372 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
8373 +               goto out;
8374 +
8375         /*
8376          * Yes, it does not scale. And it should not. Don't add
8377          * new entries into /proc/<tgid>/ without very good reasons.
8378 @@ -2668,7 +2693,7 @@ out_iput:
8379  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
8380  {
8381         struct dentry *error;
8382 -       struct task_struct *task = get_proc_task(dir);
8383 +       struct task_struct *task = get_proc_task_real(dir);
8384         const struct pid_entry *p, *last;
8385  
8386         error = ERR_PTR(-ENOENT);
8387 @@ -2765,6 +2790,9 @@ static int proc_pid_personality(struct s
8388  static const struct file_operations proc_task_operations;
8389  static const struct inode_operations proc_task_inode_operations;
8390  
8391 +extern int proc_pid_vx_info(struct task_struct *, char *);
8392 +extern int proc_pid_nx_info(struct task_struct *, char *);
8393 +
8394  static const struct pid_entry tgid_base_stuff[] = {
8395         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
8396         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
8397 @@ -2828,6 +2856,8 @@ static const struct pid_entry tgid_base_
8398  #ifdef CONFIG_CGROUPS
8399         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
8400  #endif
8401 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
8402 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
8403         INF("oom_score",  S_IRUGO, proc_oom_score),
8404         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
8405         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
8406 @@ -2847,6 +2877,7 @@ static const struct pid_entry tgid_base_
8407  #ifdef CONFIG_HARDWALL
8408         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
8409  #endif
8410 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
8411  };
8412  
8413  static int proc_tgid_base_readdir(struct file * filp,
8414 @@ -3039,7 +3070,7 @@ retry:
8415         iter.task = NULL;
8416         pid = find_ge_pid(iter.tgid, ns);
8417         if (pid) {
8418 -               iter.tgid = pid_nr_ns(pid, ns);
8419 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
8420                 iter.task = pid_task(pid, PIDTYPE_PID);
8421                 /* What we to know is if the pid we have find is the
8422                  * pid of a thread_group_leader.  Testing for task
8423 @@ -3069,7 +3100,7 @@ static int proc_pid_fill_cache(struct fi
8424         struct tgid_iter iter)
8425  {
8426         char name[PROC_NUMBUF];
8427 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
8428 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
8429         return proc_fill_cache(filp, dirent, filldir, name, len,
8430                                 proc_pid_instantiate, iter.task, NULL);
8431  }
8432 @@ -3086,7 +3117,7 @@ int proc_pid_readdir(struct file * filp,
8433                 goto out_no_task;
8434         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
8435  
8436 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
8437 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
8438         if (!reaper)
8439                 goto out_no_task;
8440  
8441 @@ -3103,6 +3134,8 @@ int proc_pid_readdir(struct file * filp,
8442              iter.task;
8443              iter.tgid += 1, iter = next_tgid(ns, iter)) {
8444                 filp->f_pos = iter.tgid + TGID_OFFSET;
8445 +               if (!vx_proc_task_visible(iter.task))
8446 +                       continue;
8447                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
8448                         put_task_struct(iter.task);
8449                         goto out;
8450 @@ -3256,6 +3289,8 @@ static struct dentry *proc_task_lookup(s
8451         tid = name_to_int(dentry);
8452         if (tid == ~0U)
8453                 goto out;
8454 +       if (vx_current_initpid(tid))
8455 +               goto out;
8456  
8457         ns = dentry->d_sb->s_fs_info;
8458         rcu_read_lock();
8459 diff -NurpP --minimal linux-3.0/fs/proc/generic.c linux-3.0-vs2.3.1-pre6/fs/proc/generic.c
8460 --- linux-3.0/fs/proc/generic.c 2011-07-22 11:18:06.000000000 +0200
8461 +++ linux-3.0-vs2.3.1-pre6/fs/proc/generic.c    2011-06-10 22:11:24.000000000 +0200
8462 @@ -22,6 +22,7 @@
8463  #include <linux/bitops.h>
8464  #include <linux/spinlock.h>
8465  #include <linux/completion.h>
8466 +#include <linux/vserver/inode.h>
8467  #include <asm/uaccess.h>
8468  
8469  #include "internal.h"
8470 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
8471         for (de = de->subdir; de ; de = de->next) {
8472                 if (de->namelen != dentry->d_name.len)
8473                         continue;
8474 +               if (!vx_hide_check(0, de->vx_flags))
8475 +                       continue;
8476                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
8477                         pde_get(de);
8478                         spin_unlock(&proc_subdir_lock);
8479                         error = -EINVAL;
8480                         inode = proc_get_inode(dir->i_sb, de);
8481 +                       /* generic proc entries belong to the host */
8482 +                       inode->i_tag = 0;
8483                         goto out_unlock;
8484                 }
8485         }
8486 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
8487  
8488                                 /* filldir passes info to user space */
8489                                 pde_get(de);
8490 +                               if (!vx_hide_check(0, de->vx_flags))
8491 +                                       goto skip;
8492                                 spin_unlock(&proc_subdir_lock);
8493                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
8494                                             de->low_ino, de->mode >> 12) < 0) {
8495 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
8496                                         goto out;
8497                                 }
8498                                 spin_lock(&proc_subdir_lock);
8499 +                       skip:
8500                                 filp->f_pos++;
8501                                 next = de->next;
8502                                 pde_put(de);
8503 @@ -627,6 +635,7 @@ static struct proc_dir_entry *__proc_cre
8504         ent->nlink = nlink;
8505         atomic_set(&ent->count, 1);
8506         ent->pde_users = 0;
8507 +       ent->vx_flags = IATTR_PROC_DEFAULT;
8508         spin_lock_init(&ent->pde_unload_lock);
8509         ent->pde_unload_completion = NULL;
8510         INIT_LIST_HEAD(&ent->pde_openers);
8511 @@ -650,7 +659,8 @@ struct proc_dir_entry *proc_symlink(cons
8512                                 kfree(ent->data);
8513                                 kfree(ent);
8514                                 ent = NULL;
8515 -                       }
8516 +                       } else
8517 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
8518                 } else {
8519                         kfree(ent);
8520                         ent = NULL;
8521 diff -NurpP --minimal linux-3.0/fs/proc/inode.c linux-3.0-vs2.3.1-pre6/fs/proc/inode.c
8522 --- linux-3.0/fs/proc/inode.c   2011-07-22 11:18:06.000000000 +0200
8523 +++ linux-3.0-vs2.3.1-pre6/fs/proc/inode.c      2011-06-10 22:11:24.000000000 +0200
8524 @@ -442,6 +442,8 @@ struct inode *proc_get_inode(struct supe
8525                         inode->i_uid = de->uid;
8526                         inode->i_gid = de->gid;
8527                 }
8528 +               if (de->vx_flags)
8529 +                       PROC_I(inode)->vx_flags = de->vx_flags;
8530                 if (de->size)
8531                         inode->i_size = de->size;
8532                 if (de->nlink)
8533 diff -NurpP --minimal linux-3.0/fs/proc/internal.h linux-3.0-vs2.3.1-pre6/fs/proc/internal.h
8534 --- linux-3.0/fs/proc/internal.h        2011-07-22 11:18:06.000000000 +0200
8535 +++ linux-3.0-vs2.3.1-pre6/fs/proc/internal.h   2011-06-10 22:11:24.000000000 +0200
8536 @@ -10,6 +10,7 @@
8537   */
8538  
8539  #include <linux/proc_fs.h>
8540 +#include <linux/vs_pid.h>
8541  
8542  extern struct proc_dir_entry proc_root;
8543  #ifdef CONFIG_PROC_SYSCTL
8544 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
8545                                 struct pid *pid, struct task_struct *task);
8546  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
8547                                 struct pid *pid, struct task_struct *task);
8548 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
8549 +                               struct pid *pid, struct task_struct *task);
8550 +
8551  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
8552  
8553  extern const struct file_operations proc_maps_operations;
8554 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
8555         return PROC_I(inode)->pid;
8556  }
8557  
8558 -static inline struct task_struct *get_proc_task(struct inode *inode)
8559 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
8560  {
8561         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
8562  }
8563  
8564 +static inline struct task_struct *get_proc_task(struct inode *inode)
8565 +{
8566 +       return vx_get_proc_task(inode, proc_pid(inode));
8567 +}
8568 +
8569  static inline int proc_fd(struct inode *inode)
8570  {
8571         return PROC_I(inode)->fd;
8572 diff -NurpP --minimal linux-3.0/fs/proc/loadavg.c linux-3.0-vs2.3.1-pre6/fs/proc/loadavg.c
8573 --- linux-3.0/fs/proc/loadavg.c 2009-09-10 15:26:23.000000000 +0200
8574 +++ linux-3.0-vs2.3.1-pre6/fs/proc/loadavg.c    2011-06-10 22:11:24.000000000 +0200
8575 @@ -12,15 +12,27 @@
8576  
8577  static int loadavg_proc_show(struct seq_file *m, void *v)
8578  {
8579 +       unsigned long running;
8580 +       unsigned int threads;
8581         unsigned long avnrun[3];
8582  
8583         get_avenrun(avnrun, FIXED_1/200, 0);
8584  
8585 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
8586 +               struct vx_info *vxi = current_vx_info();
8587 +
8588 +               running = atomic_read(&vxi->cvirt.nr_running);
8589 +               threads = atomic_read(&vxi->cvirt.nr_threads);
8590 +       } else {
8591 +               running = nr_running();
8592 +               threads = nr_threads;
8593 +       }
8594 +
8595         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
8596                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
8597                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
8598                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
8599 -               nr_running(), nr_threads,
8600 +               running, threads,
8601                 task_active_pid_ns(current)->last_pid);
8602         return 0;
8603  }
8604 diff -NurpP --minimal linux-3.0/fs/proc/meminfo.c linux-3.0-vs2.3.1-pre6/fs/proc/meminfo.c
8605 --- linux-3.0/fs/proc/meminfo.c 2011-03-15 18:07:33.000000000 +0100
8606 +++ linux-3.0-vs2.3.1-pre6/fs/proc/meminfo.c    2011-06-10 22:11:24.000000000 +0200
8607 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
8608         allowed = ((totalram_pages - hugetlb_total_pages())
8609                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
8610  
8611 -       cached = global_page_state(NR_FILE_PAGES) -
8612 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
8613 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
8614                         total_swapcache_pages - i.bufferram;
8615         if (cached < 0)
8616                 cached = 0;
8617 diff -NurpP --minimal linux-3.0/fs/proc/root.c linux-3.0-vs2.3.1-pre6/fs/proc/root.c
8618 --- linux-3.0/fs/proc/root.c    2011-07-22 11:18:06.000000000 +0200
8619 +++ linux-3.0-vs2.3.1-pre6/fs/proc/root.c       2011-06-22 12:39:15.000000000 +0200
8620 @@ -18,9 +18,14 @@
8621  #include <linux/bitops.h>
8622  #include <linux/mount.h>
8623  #include <linux/pid_namespace.h>
8624 +#include <linux/vserver/inode.h>
8625  
8626  #include "internal.h"
8627  
8628 +struct proc_dir_entry *proc_virtual;
8629 +
8630 +extern void proc_vx_init(void);
8631 +
8632  static int proc_test_super(struct super_block *sb, void *data)
8633  {
8634         return sb->s_fs_info == data;
8635 @@ -125,6 +130,7 @@ void __init proc_root_init(void)
8636  #endif
8637         proc_mkdir("bus", NULL);
8638         proc_sys_init();
8639 +       proc_vx_init();
8640  }
8641  
8642  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
8643 @@ -193,6 +199,7 @@ struct proc_dir_entry proc_root = {
8644         .proc_iops      = &proc_root_inode_operations, 
8645         .proc_fops      = &proc_root_operations,
8646         .parent         = &proc_root,
8647 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
8648  };
8649  
8650  int pid_ns_prepare_proc(struct pid_namespace *ns)
8651 diff -NurpP --minimal linux-3.0/fs/proc/uptime.c linux-3.0-vs2.3.1-pre6/fs/proc/uptime.c
8652 --- linux-3.0/fs/proc/uptime.c  2009-12-03 20:02:53.000000000 +0100
8653 +++ linux-3.0-vs2.3.1-pre6/fs/proc/uptime.c     2011-06-10 22:11:24.000000000 +0200
8654 @@ -4,22 +4,22 @@
8655  #include <linux/sched.h>
8656  #include <linux/seq_file.h>
8657  #include <linux/time.h>
8658 -#include <linux/kernel_stat.h>
8659 +#include <linux/vserver/cvirt.h>
8660  #include <asm/cputime.h>
8661  
8662  static int uptime_proc_show(struct seq_file *m, void *v)
8663  {
8664         struct timespec uptime;
8665         struct timespec idle;
8666 -       int i;
8667 -       cputime_t idletime = cputime_zero;
8668 -
8669 -       for_each_possible_cpu(i)
8670 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
8671 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
8672  
8673         do_posix_clock_monotonic_gettime(&uptime);
8674         monotonic_to_bootbased(&uptime);
8675         cputime_to_timespec(idletime, &idle);
8676 +
8677 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
8678 +               vx_vsi_uptime(&uptime, &idle);
8679 +
8680         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
8681                         (unsigned long) uptime.tv_sec,
8682                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
8683 diff -NurpP --minimal linux-3.0/fs/quota/dquot.c linux-3.0-vs2.3.1-pre6/fs/quota/dquot.c
8684 --- linux-3.0/fs/quota/dquot.c  2011-07-22 11:18:06.000000000 +0200
8685 +++ linux-3.0-vs2.3.1-pre6/fs/quota/dquot.c     2011-06-10 22:11:24.000000000 +0200
8686 @@ -1548,6 +1548,9 @@ int __dquot_alloc_space(struct inode *in
8687         int reserve = flags & DQUOT_SPACE_RESERVE;
8688         int nofail = flags & DQUOT_SPACE_NOFAIL;
8689  
8690 +       if ((ret = dl_alloc_space(inode, number)))
8691 +               return ret;
8692 +
8693         /*
8694          * First test before acquiring mutex - solves deadlocks when we
8695          * re-enter the quota code and are already holding the mutex
8696 @@ -1602,6 +1605,9 @@ int dquot_alloc_inode(const struct inode
8697         int cnt, ret = 0;
8698         char warntype[MAXQUOTAS];
8699  
8700 +       if ((ret = dl_alloc_inode(inode)))
8701 +               return ret;
8702 +
8703         /* First test before acquiring mutex - solves deadlocks when we
8704           * re-enter the quota code and are already holding the mutex */
8705         if (!dquot_active(inode))
8706 @@ -1672,6 +1678,8 @@ void __dquot_free_space(struct inode *in
8707         char warntype[MAXQUOTAS];
8708         int reserve = flags & DQUOT_SPACE_RESERVE;
8709  
8710 +       dl_free_space(inode, number);
8711 +
8712         /* First test before acquiring mutex - solves deadlocks when we
8713           * re-enter the quota code and are already holding the mutex */
8714         if (!dquot_active(inode)) {
8715 @@ -1710,6 +1718,8 @@ void dquot_free_inode(const struct inode
8716         unsigned int cnt;
8717         char warntype[MAXQUOTAS];
8718  
8719 +       dl_free_inode(inode);
8720 +
8721         /* First test before acquiring mutex - solves deadlocks when we
8722           * re-enter the quota code and are already holding the mutex */
8723         if (!dquot_active(inode))
8724 diff -NurpP --minimal linux-3.0/fs/quota/quota.c linux-3.0-vs2.3.1-pre6/fs/quota/quota.c
8725 --- linux-3.0/fs/quota/quota.c  2011-03-15 18:07:34.000000000 +0100
8726 +++ linux-3.0-vs2.3.1-pre6/fs/quota/quota.c     2011-06-13 18:19:47.000000000 +0200
8727 @@ -8,6 +8,7 @@
8728  #include <linux/fs.h>
8729  #include <linux/namei.h>
8730  #include <linux/slab.h>
8731 +#include <linux/vs_context.h>
8732  #include <asm/current.h>
8733  #include <asm/uaccess.h>
8734  #include <linux/kernel.h>
8735 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
8736                         break;
8737                 /*FALLTHROUGH*/
8738         default:
8739 -               if (!capable(CAP_SYS_ADMIN))
8740 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8741                         return -EPERM;
8742         }
8743  
8744 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
8745         }
8746  }
8747  
8748 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8749 +
8750 +#include <linux/vroot.h>
8751 +#include <linux/major.h>
8752 +#include <linux/module.h>
8753 +#include <linux/kallsyms.h>
8754 +#include <linux/vserver/debug.h>
8755 +
8756 +static vroot_grb_func *vroot_get_real_bdev = NULL;
8757 +
8758 +static DEFINE_SPINLOCK(vroot_grb_lock);
8759 +
8760 +int register_vroot_grb(vroot_grb_func *func) {
8761 +       int ret = -EBUSY;
8762 +
8763 +       spin_lock(&vroot_grb_lock);
8764 +       if (!vroot_get_real_bdev) {
8765 +               vroot_get_real_bdev = func;
8766 +               ret = 0;
8767 +       }
8768 +       spin_unlock(&vroot_grb_lock);
8769 +       return ret;
8770 +}
8771 +EXPORT_SYMBOL(register_vroot_grb);
8772 +
8773 +int unregister_vroot_grb(vroot_grb_func *func) {
8774 +       int ret = -EINVAL;
8775 +
8776 +       spin_lock(&vroot_grb_lock);
8777 +       if (vroot_get_real_bdev) {
8778 +               vroot_get_real_bdev = NULL;
8779 +               ret = 0;
8780 +       }
8781 +       spin_unlock(&vroot_grb_lock);
8782 +       return ret;
8783 +}
8784 +EXPORT_SYMBOL(unregister_vroot_grb);
8785 +
8786 +#endif
8787 +
8788  /*
8789   * look up a superblock on which quota ops will be performed
8790   * - use the name of a block device to find the superblock thereon
8791 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
8792         putname(tmp);
8793         if (IS_ERR(bdev))
8794                 return ERR_CAST(bdev);
8795 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8796 +       if (bdev && bdev->bd_inode &&
8797 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
8798 +               struct block_device *bdnew = (void *)-EINVAL;
8799 +
8800 +               if (vroot_get_real_bdev)
8801 +                       bdnew = vroot_get_real_bdev(bdev);
8802 +               else
8803 +                       vxdprintk(VXD_CBIT(misc, 0),
8804 +                                       "vroot_get_real_bdev not set");
8805 +               bdput(bdev);
8806 +               if (IS_ERR(bdnew))
8807 +                       return ERR_PTR(PTR_ERR(bdnew));
8808 +               bdev = bdnew;
8809 +       }
8810 +#endif
8811         sb = get_super(bdev);
8812         bdput(bdev);
8813         if (!sb)
8814 diff -NurpP --minimal linux-3.0/fs/reiserfs/file.c linux-3.0-vs2.3.1-pre6/fs/reiserfs/file.c
8815 --- linux-3.0/fs/reiserfs/file.c        2011-01-05 21:50:26.000000000 +0100
8816 +++ linux-3.0-vs2.3.1-pre6/fs/reiserfs/file.c   2011-06-10 22:11:24.000000000 +0200
8817 @@ -312,4 +312,5 @@ const struct inode_operations reiserfs_f
8818         .listxattr = reiserfs_listxattr,
8819         .removexattr = reiserfs_removexattr,
8820         .permission = reiserfs_permission,
8821 +       .sync_flags = reiserfs_sync_flags,
8822  };
8823 diff -NurpP --minimal linux-3.0/fs/reiserfs/inode.c linux-3.0-vs2.3.1-pre6/fs/reiserfs/inode.c
8824 --- linux-3.0/fs/reiserfs/inode.c       2011-05-22 16:17:53.000000000 +0200
8825 +++ linux-3.0-vs2.3.1-pre6/fs/reiserfs/inode.c  2011-06-10 22:11:24.000000000 +0200
8826 @@ -18,6 +18,7 @@
8827  #include <linux/writeback.h>
8828  #include <linux/quotaops.h>
8829  #include <linux/swap.h>
8830 +#include <linux/vs_tag.h>
8831  
8832  int reiserfs_commit_write(struct file *f, struct page *page,
8833                           unsigned from, unsigned to);
8834 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
8835         struct buffer_head *bh;
8836         struct item_head *ih;
8837         __u32 rdev;
8838 +       uid_t uid;
8839 +       gid_t gid;
8840         //int version = ITEM_VERSION_1;
8841  
8842         bh = PATH_PLAST_BUFFER(path);
8843 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
8844                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
8845                 unsigned long blocks;
8846  
8847 +               uid = sd_v1_uid(sd);
8848 +               gid = sd_v1_gid(sd);
8849 +
8850                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
8851                 set_inode_sd_version(inode, STAT_DATA_V1);
8852                 inode->i_mode = sd_v1_mode(sd);
8853                 inode->i_nlink = sd_v1_nlink(sd);
8854 -               inode->i_uid = sd_v1_uid(sd);
8855 -               inode->i_gid = sd_v1_gid(sd);
8856                 inode->i_size = sd_v1_size(sd);
8857                 inode->i_atime.tv_sec = sd_v1_atime(sd);
8858                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
8859 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
8860                 // (directories and symlinks)
8861                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
8862  
8863 +               uid    = sd_v2_uid(sd);
8864 +               gid    = sd_v2_gid(sd);
8865 +
8866                 inode->i_mode = sd_v2_mode(sd);
8867                 inode->i_nlink = sd_v2_nlink(sd);
8868 -               inode->i_uid = sd_v2_uid(sd);
8869                 inode->i_size = sd_v2_size(sd);
8870 -               inode->i_gid = sd_v2_gid(sd);
8871                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
8872                 inode->i_atime.tv_sec = sd_v2_atime(sd);
8873                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
8874 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
8875                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
8876         }
8877  
8878 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8879 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8880 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
8881 +
8882         pathrelse(path);
8883         if (S_ISREG(inode->i_mode)) {
8884                 inode->i_op = &reiserfs_file_inode_operations;
8885 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
8886  static void inode2sd(void *sd, struct inode *inode, loff_t size)
8887  {
8888         struct stat_data *sd_v2 = (struct stat_data *)sd;
8889 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
8890 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
8891         __u16 flags;
8892  
8893 +       set_sd_v2_uid(sd_v2, uid);
8894 +       set_sd_v2_gid(sd_v2, gid);
8895         set_sd_v2_mode(sd_v2, inode->i_mode);
8896         set_sd_v2_nlink(sd_v2, inode->i_nlink);
8897 -       set_sd_v2_uid(sd_v2, inode->i_uid);
8898         set_sd_v2_size(sd_v2, size);
8899 -       set_sd_v2_gid(sd_v2, inode->i_gid);
8900         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
8901         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
8902         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
8903 @@ -2863,14 +2874,19 @@ int reiserfs_commit_write(struct file *f
8904  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
8905  {
8906         if (reiserfs_attrs(inode->i_sb)) {
8907 -               if (sd_attrs & REISERFS_SYNC_FL)
8908 -                       inode->i_flags |= S_SYNC;
8909 -               else
8910 -                       inode->i_flags &= ~S_SYNC;
8911                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
8912                         inode->i_flags |= S_IMMUTABLE;
8913                 else
8914                         inode->i_flags &= ~S_IMMUTABLE;
8915 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
8916 +                       inode->i_flags |= S_IXUNLINK;
8917 +               else
8918 +                       inode->i_flags &= ~S_IXUNLINK;
8919 +
8920 +               if (sd_attrs & REISERFS_SYNC_FL)
8921 +                       inode->i_flags |= S_SYNC;
8922 +               else
8923 +                       inode->i_flags &= ~S_SYNC;
8924                 if (sd_attrs & REISERFS_APPEND_FL)
8925                         inode->i_flags |= S_APPEND;
8926                 else
8927 @@ -2883,6 +2899,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
8928                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
8929                 else
8930                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
8931 +
8932 +               if (sd_attrs & REISERFS_BARRIER_FL)
8933 +                       inode->i_vflags |= V_BARRIER;
8934 +               else
8935 +                       inode->i_vflags &= ~V_BARRIER;
8936 +               if (sd_attrs & REISERFS_COW_FL)
8937 +                       inode->i_vflags |= V_COW;
8938 +               else
8939 +                       inode->i_vflags &= ~V_COW;
8940         }
8941  }
8942  
8943 @@ -2893,6 +2918,11 @@ void i_attrs_to_sd_attrs(struct inode *i
8944                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
8945                 else
8946                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
8947 +               if (inode->i_flags & S_IXUNLINK)
8948 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
8949 +               else
8950 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
8951 +
8952                 if (inode->i_flags & S_SYNC)
8953                         *sd_attrs |= REISERFS_SYNC_FL;
8954                 else
8955 @@ -2905,6 +2935,15 @@ void i_attrs_to_sd_attrs(struct inode *i
8956                         *sd_attrs |= REISERFS_NOTAIL_FL;
8957                 else
8958                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
8959 +
8960 +               if (inode->i_vflags & V_BARRIER)
8961 +                       *sd_attrs |= REISERFS_BARRIER_FL;
8962 +               else
8963 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
8964 +               if (inode->i_vflags & V_COW)
8965 +                       *sd_attrs |= REISERFS_COW_FL;
8966 +               else
8967 +                       *sd_attrs &= ~REISERFS_COW_FL;
8968         }
8969  }
8970  
8971 @@ -3148,7 +3187,8 @@ int reiserfs_setattr(struct dentry *dent
8972         }
8973  
8974         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
8975 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
8976 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
8977 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
8978                 struct reiserfs_transaction_handle th;
8979                 int jbegin_count =
8980                     2 *
8981 @@ -3177,6 +3217,9 @@ int reiserfs_setattr(struct dentry *dent
8982                         inode->i_uid = attr->ia_uid;
8983                 if (attr->ia_valid & ATTR_GID)
8984                         inode->i_gid = attr->ia_gid;
8985 +                               if ((attr->ia_valid & ATTR_TAG) &&
8986 +                                       IS_TAGGED(inode))
8987 +                                       inode->i_tag = attr->ia_tag;
8988                 mark_inode_dirty(inode);
8989                 error = journal_end(&th, inode->i_sb, jbegin_count);
8990                 if (error)
8991 diff -NurpP --minimal linux-3.0/fs/reiserfs/ioctl.c linux-3.0-vs2.3.1-pre6/fs/reiserfs/ioctl.c
8992 --- linux-3.0/fs/reiserfs/ioctl.c       2011-05-22 16:17:53.000000000 +0200
8993 +++ linux-3.0-vs2.3.1-pre6/fs/reiserfs/ioctl.c  2011-06-10 22:11:24.000000000 +0200
8994 @@ -11,6 +11,21 @@
8995  #include <linux/pagemap.h>
8996  #include <linux/compat.h>
8997  
8998 +
8999 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
9000 +{
9001 +       __u16 sd_attrs = 0;
9002 +
9003 +       inode->i_flags = flags;
9004 +       inode->i_vflags = vflags;
9005 +
9006 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
9007 +       REISERFS_I(inode)->i_attrs = sd_attrs;
9008 +       inode->i_ctime = CURRENT_TIME_SEC;
9009 +       mark_inode_dirty(inode);
9010 +       return 0;
9011 +}
9012 +
9013  /*
9014   * reiserfs_ioctl - handler for ioctl for inode
9015   * supported commands:
9016 @@ -22,7 +37,7 @@
9017  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
9018  {
9019         struct inode *inode = filp->f_path.dentry->d_inode;
9020 -       unsigned int flags;
9021 +       unsigned int flags, oldflags;
9022         int err = 0;
9023  
9024         reiserfs_write_lock(inode->i_sb);
9025 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
9026  
9027                 flags = REISERFS_I(inode)->i_attrs;
9028                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
9029 +               flags &= REISERFS_FL_USER_VISIBLE;
9030                 err = put_user(flags, (int __user *)arg);
9031                 break;
9032         case REISERFS_IOC_SETFLAGS:{
9033 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
9034                                 err = -EFAULT;
9035                                 goto setflags_out;
9036                         }
9037 +                       if (IS_BARRIER(inode)) {
9038 +                               vxwprintk_task(1, "messing with the barrier.");
9039 +                               return -EACCES;
9040 +                       }
9041                         /*
9042                          * Is it quota file? Do not allow user to mess with it
9043                          */
9044 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
9045                                         goto setflags_out;
9046                                 }
9047                         }
9048 +
9049 +                       oldflags = REISERFS_I(inode)->i_attrs;
9050 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
9051 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
9052                         sd_attrs_to_i_attrs(flags, inode);
9053                         REISERFS_I(inode)->i_attrs = flags;
9054                         inode->i_ctime = CURRENT_TIME_SEC;
9055 diff -NurpP --minimal linux-3.0/fs/reiserfs/namei.c linux-3.0-vs2.3.1-pre6/fs/reiserfs/namei.c
9056 --- linux-3.0/fs/reiserfs/namei.c       2011-05-22 16:17:53.000000000 +0200
9057 +++ linux-3.0-vs2.3.1-pre6/fs/reiserfs/namei.c  2011-06-10 22:11:24.000000000 +0200
9058 @@ -18,6 +18,7 @@
9059  #include <linux/reiserfs_acl.h>
9060  #include <linux/reiserfs_xattr.h>
9061  #include <linux/quotaops.h>
9062 +#include <linux/vs_tag.h>
9063  
9064  #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; }
9065  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
9066 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
9067         if (retval == IO_ERROR) {
9068                 return ERR_PTR(-EIO);
9069         }
9070 +               dx_propagate_tag(nd, inode);
9071  
9072         return d_splice_alias(inode, dentry);
9073  }
9074 @@ -1529,6 +1531,7 @@ const struct inode_operations reiserfs_d
9075         .listxattr = reiserfs_listxattr,
9076         .removexattr = reiserfs_removexattr,
9077         .permission = reiserfs_permission,
9078 +       .sync_flags = reiserfs_sync_flags,
9079  };
9080  
9081  /*
9082 diff -NurpP --minimal linux-3.0/fs/reiserfs/super.c linux-3.0-vs2.3.1-pre6/fs/reiserfs/super.c
9083 --- linux-3.0/fs/reiserfs/super.c       2011-07-22 11:18:06.000000000 +0200
9084 +++ linux-3.0-vs2.3.1-pre6/fs/reiserfs/super.c  2011-06-10 22:11:24.000000000 +0200
9085 @@ -899,6 +899,14 @@ static int reiserfs_parse_options(struct
9086                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
9087                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
9088  #endif
9089 +#ifndef CONFIG_TAGGING_NONE
9090 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
9091 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
9092 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
9093 +#endif
9094 +#ifdef CONFIG_PROPAGATE
9095 +               {"tag",.arg_required = 'T',.values = NULL},
9096 +#endif
9097  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
9098                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
9099                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
9100 @@ -1208,6 +1216,14 @@ static int reiserfs_remount(struct super
9101         handle_quota_files(s, qf_names, &qfmt);
9102  #endif
9103  
9104 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
9105 +               !(s->s_flags & MS_TAGGED)) {
9106 +               reiserfs_warning(s, "super-vs01",
9107 +                       "reiserfs: tagging not permitted on remount.");
9108 +               err = -EINVAL;
9109 +               goto out_err;
9110 +       }
9111 +
9112         handle_attrs(s);
9113  
9114         /* Add options that are safe here */
9115 @@ -1690,6 +1706,10 @@ static int reiserfs_fill_super(struct su
9116                 goto error;
9117         }
9118  
9119 +       /* map mount option tagxid */
9120 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
9121 +               s->s_flags |= MS_TAGGED;
9122 +
9123         rs = SB_DISK_SUPER_BLOCK(s);
9124         /* Let's do basic sanity check to verify that underlying device is not
9125            smaller than the filesystem. If the check fails then abort and scream,
9126 diff -NurpP --minimal linux-3.0/fs/reiserfs/xattr.c linux-3.0-vs2.3.1-pre6/fs/reiserfs/xattr.c
9127 --- linux-3.0/fs/reiserfs/xattr.c       2011-07-22 11:18:06.000000000 +0200
9128 +++ linux-3.0-vs2.3.1-pre6/fs/reiserfs/xattr.c  2011-06-22 12:39:15.000000000 +0200
9129 @@ -40,6 +40,7 @@
9130  #include <linux/errno.h>
9131  #include <linux/gfp.h>
9132  #include <linux/fs.h>
9133 +#include <linux/mount.h>
9134  #include <linux/file.h>
9135  #include <linux/pagemap.h>
9136  #include <linux/xattr.h>
9137 diff -NurpP --minimal linux-3.0/fs/stat.c linux-3.0-vs2.3.1-pre6/fs/stat.c
9138 --- linux-3.0/fs/stat.c 2011-05-22 16:17:54.000000000 +0200
9139 +++ linux-3.0-vs2.3.1-pre6/fs/stat.c    2011-06-10 22:11:24.000000000 +0200
9140 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
9141         stat->nlink = inode->i_nlink;
9142         stat->uid = inode->i_uid;
9143         stat->gid = inode->i_gid;
9144 +       stat->tag = inode->i_tag;
9145         stat->rdev = inode->i_rdev;
9146         stat->atime = inode->i_atime;
9147         stat->mtime = inode->i_mtime;
9148 diff -NurpP --minimal linux-3.0/fs/statfs.c linux-3.0-vs2.3.1-pre6/fs/statfs.c
9149 --- linux-3.0/fs/statfs.c       2011-05-22 16:17:54.000000000 +0200
9150 +++ linux-3.0-vs2.3.1-pre6/fs/statfs.c  2011-06-10 22:11:24.000000000 +0200
9151 @@ -7,6 +7,8 @@
9152  #include <linux/statfs.h>
9153  #include <linux/security.h>
9154  #include <linux/uaccess.h>
9155 +#include <linux/vs_base.h>
9156 +#include <linux/vs_dlimit.h>
9157  
9158  static int flags_by_mnt(int mnt_flags)
9159  {
9160 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
9161         retval = dentry->d_sb->s_op->statfs(dentry, buf);
9162         if (retval == 0 && buf->f_frsize == 0)
9163                 buf->f_frsize = buf->f_bsize;
9164 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
9165 +               vx_vsi_statfs(dentry->d_sb, buf);
9166         return retval;
9167  }
9168  
9169 diff -NurpP --minimal linux-3.0/fs/sysfs/mount.c linux-3.0-vs2.3.1-pre6/fs/sysfs/mount.c
9170 --- linux-3.0/fs/sysfs/mount.c  2011-07-22 11:18:06.000000000 +0200
9171 +++ linux-3.0-vs2.3.1-pre6/fs/sysfs/mount.c     2011-06-22 12:39:15.000000000 +0200
9172 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
9173  
9174         sb->s_blocksize = PAGE_CACHE_SIZE;
9175         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
9176 -       sb->s_magic = SYSFS_MAGIC;
9177 +       sb->s_magic = SYSFS_SUPER_MAGIC;
9178         sb->s_op = &sysfs_ops;
9179         sb->s_time_gran = 1;
9180  
9181 diff -NurpP --minimal linux-3.0/fs/utimes.c linux-3.0-vs2.3.1-pre6/fs/utimes.c
9182 --- linux-3.0/fs/utimes.c       2011-05-22 16:17:54.000000000 +0200
9183 +++ linux-3.0-vs2.3.1-pre6/fs/utimes.c  2011-06-10 22:11:24.000000000 +0200
9184 @@ -8,6 +8,8 @@
9185  #include <linux/stat.h>
9186  #include <linux/utime.h>
9187  #include <linux/syscalls.h>
9188 +#include <linux/mount.h>
9189 +#include <linux/vs_cowbl.h>
9190  #include <asm/uaccess.h>
9191  #include <asm/unistd.h>
9192  
9193 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
9194  {
9195         int error;
9196         struct iattr newattrs;
9197 -       struct inode *inode = path->dentry->d_inode;
9198 +       struct inode *inode;
9199  
9200         error = mnt_want_write(path->mnt);
9201         if (error)
9202                 goto out;
9203  
9204 +       error = cow_check_and_break(path);
9205 +       if (error)
9206 +               goto mnt_drop_write_and_out;
9207 +
9208 +       inode = path->dentry->d_inode;
9209 +
9210         if (times && times[0].tv_nsec == UTIME_NOW &&
9211                      times[1].tv_nsec == UTIME_NOW)
9212                 times = NULL;
9213 diff -NurpP --minimal linux-3.0/fs/xattr.c linux-3.0-vs2.3.1-pre6/fs/xattr.c
9214 --- linux-3.0/fs/xattr.c        2011-07-22 11:18:09.000000000 +0200
9215 +++ linux-3.0-vs2.3.1-pre6/fs/xattr.c   2011-06-10 23:10:19.000000000 +0200
9216 @@ -18,6 +18,7 @@
9217  #include <linux/module.h>
9218  #include <linux/fsnotify.h>
9219  #include <linux/audit.h>
9220 +#include <linux/mount.h>
9221  #include <asm/uaccess.h>
9222  
9223  
9224 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
9225          * The trusted.* namespace can only be accessed by privileged users.
9226          */
9227         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
9228 -               if (!capable(CAP_SYS_ADMIN))
9229 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
9230                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
9231                 return 0;
9232         }
9233 diff -NurpP --minimal linux-3.0/fs/xfs/linux-2.6/xfs_ioctl.c linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_ioctl.c
9234 --- linux-3.0/fs/xfs/linux-2.6/xfs_ioctl.c      2011-05-22 16:17:54.000000000 +0200
9235 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_ioctl.c 2011-06-10 22:11:24.000000000 +0200
9236 @@ -28,7 +28,7 @@
9237  #include "xfs_bmap_btree.h"
9238  #include "xfs_dinode.h"
9239  #include "xfs_inode.h"
9240 -#include "xfs_ioctl.h"
9241 +// #include "xfs_ioctl.h"
9242  #include "xfs_rtalloc.h"
9243  #include "xfs_itable.h"
9244  #include "xfs_error.h"
9245 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
9246                 xflags |= XFS_XFLAG_IMMUTABLE;
9247         else
9248                 xflags &= ~XFS_XFLAG_IMMUTABLE;
9249 +       if (flags & FS_IXUNLINK_FL)
9250 +               xflags |= XFS_XFLAG_IXUNLINK;
9251 +       else
9252 +               xflags &= ~XFS_XFLAG_IXUNLINK;
9253         if (flags & FS_APPEND_FL)
9254                 xflags |= XFS_XFLAG_APPEND;
9255         else
9256 @@ -776,6 +780,8 @@ xfs_di2lxflags(
9257  
9258         if (di_flags & XFS_DIFLAG_IMMUTABLE)
9259                 flags |= FS_IMMUTABLE_FL;
9260 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
9261 +               flags |= FS_IXUNLINK_FL;
9262         if (di_flags & XFS_DIFLAG_APPEND)
9263                 flags |= FS_APPEND_FL;
9264         if (di_flags & XFS_DIFLAG_SYNC)
9265 @@ -836,6 +842,8 @@ xfs_set_diflags(
9266         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
9267         if (xflags & XFS_XFLAG_IMMUTABLE)
9268                 di_flags |= XFS_DIFLAG_IMMUTABLE;
9269 +       if (xflags & XFS_XFLAG_IXUNLINK)
9270 +               di_flags |= XFS_DIFLAG_IXUNLINK;
9271         if (xflags & XFS_XFLAG_APPEND)
9272                 di_flags |= XFS_DIFLAG_APPEND;
9273         if (xflags & XFS_XFLAG_SYNC)
9274 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
9275                 inode->i_flags |= S_IMMUTABLE;
9276         else
9277                 inode->i_flags &= ~S_IMMUTABLE;
9278 +       if (xflags & XFS_XFLAG_IXUNLINK)
9279 +               inode->i_flags |= S_IXUNLINK;
9280 +       else
9281 +               inode->i_flags &= ~S_IXUNLINK;
9282         if (xflags & XFS_XFLAG_APPEND)
9283                 inode->i_flags |= S_APPEND;
9284         else
9285 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
9286         case XFS_IOC_FSGETXATTRA:
9287                 return xfs_ioc_fsgetxattr(ip, 1, arg);
9288         case XFS_IOC_FSSETXATTR:
9289 +               if (IS_BARRIER(inode)) {
9290 +                       vxwprintk_task(1, "messing with the barrier.");
9291 +                       return -XFS_ERROR(EACCES);
9292 +               }
9293                 return xfs_ioc_fssetxattr(ip, filp, arg);
9294         case XFS_IOC_GETXFLAGS:
9295                 return xfs_ioc_getxflags(ip, arg);
9296         case XFS_IOC_SETXFLAGS:
9297 +               if (IS_BARRIER(inode)) {
9298 +                       vxwprintk_task(1, "messing with the barrier.");
9299 +                       return -XFS_ERROR(EACCES);
9300 +               }
9301                 return xfs_ioc_setxflags(ip, filp, arg);
9302  
9303         case XFS_IOC_FSSETDM: {
9304 diff -NurpP --minimal linux-3.0/fs/xfs/linux-2.6/xfs_ioctl.h linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_ioctl.h
9305 --- linux-3.0/fs/xfs/linux-2.6/xfs_ioctl.h      2010-07-07 18:31:54.000000000 +0200
9306 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_ioctl.h 2011-06-10 22:11:24.000000000 +0200
9307 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
9308         void __user             *uhandle,
9309         u32                     hlen);
9310  
9311 +extern int
9312 +xfs_sync_flags(
9313 +       struct inode            *inode,
9314 +       int                     flags,
9315 +       int                     vflags);
9316 +
9317  extern long
9318  xfs_file_ioctl(
9319         struct file             *filp,
9320 diff -NurpP --minimal linux-3.0/fs/xfs/linux-2.6/xfs_iops.c linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_iops.c
9321 --- linux-3.0/fs/xfs/linux-2.6/xfs_iops.c       2011-07-22 11:18:09.000000000 +0200
9322 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_iops.c  2011-06-22 12:39:15.000000000 +0200
9323 @@ -30,6 +30,7 @@
9324  #include "xfs_bmap_btree.h"
9325  #include "xfs_dinode.h"
9326  #include "xfs_inode.h"
9327 +#include "xfs_ioctl.h"
9328  #include "xfs_bmap.h"
9329  #include "xfs_rtalloc.h"
9330  #include "xfs_error.h"
9331 @@ -48,6 +49,7 @@
9332  #include <linux/security.h>
9333  #include <linux/fiemap.h>
9334  #include <linux/slab.h>
9335 +#include <linux/vs_tag.h>
9336  
9337  /*
9338   * Bring the timestamps in the XFS inode uptodate.
9339 @@ -464,6 +466,7 @@ xfs_vn_getattr(
9340         stat->nlink = ip->i_d.di_nlink;
9341         stat->uid = ip->i_d.di_uid;
9342         stat->gid = ip->i_d.di_gid;
9343 +       stat->tag = ip->i_d.di_tag;
9344         stat->ino = ip->i_ino;
9345         stat->atime = inode->i_atime;
9346         stat->mtime = inode->i_mtime;
9347 @@ -599,6 +602,7 @@ static const struct inode_operations xfs
9348         .removexattr            = generic_removexattr,
9349         .listxattr              = xfs_vn_listxattr,
9350         .fiemap                 = xfs_vn_fiemap,
9351 +       .sync_flags             = xfs_sync_flags,
9352  };
9353  
9354  static const struct inode_operations xfs_dir_inode_operations = {
9355 @@ -624,6 +628,7 @@ static const struct inode_operations xfs
9356         .getxattr               = generic_getxattr,
9357         .removexattr            = generic_removexattr,
9358         .listxattr              = xfs_vn_listxattr,
9359 +       .sync_flags             = xfs_sync_flags,
9360  };
9361  
9362  static const struct inode_operations xfs_dir_ci_inode_operations = {
9363 @@ -673,6 +678,10 @@ xfs_diflags_to_iflags(
9364                 inode->i_flags |= S_IMMUTABLE;
9365         else
9366                 inode->i_flags &= ~S_IMMUTABLE;
9367 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
9368 +               inode->i_flags |= S_IXUNLINK;
9369 +       else
9370 +               inode->i_flags &= ~S_IXUNLINK;
9371         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
9372                 inode->i_flags |= S_APPEND;
9373         else
9374 @@ -685,6 +694,15 @@ xfs_diflags_to_iflags(
9375                 inode->i_flags |= S_NOATIME;
9376         else
9377                 inode->i_flags &= ~S_NOATIME;
9378 +
9379 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
9380 +               inode->i_vflags |= V_BARRIER;
9381 +       else
9382 +               inode->i_vflags &= ~V_BARRIER;
9383 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
9384 +               inode->i_vflags |= V_COW;
9385 +       else
9386 +               inode->i_vflags &= ~V_COW;
9387  }
9388  
9389  /*
9390 @@ -716,6 +734,7 @@ xfs_setup_inode(
9391         inode->i_nlink  = ip->i_d.di_nlink;
9392         inode->i_uid    = ip->i_d.di_uid;
9393         inode->i_gid    = ip->i_d.di_gid;
9394 +       inode->i_tag    = ip->i_d.di_tag;
9395  
9396         switch (inode->i_mode & S_IFMT) {
9397         case S_IFBLK:
9398 diff -NurpP --minimal linux-3.0/fs/xfs/linux-2.6/xfs_linux.h linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_linux.h
9399 --- linux-3.0/fs/xfs/linux-2.6/xfs_linux.h      2011-07-22 11:18:09.000000000 +0200
9400 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_linux.h 2011-06-10 22:11:24.000000000 +0200
9401 @@ -115,6 +115,7 @@
9402  
9403  #define current_cpu()          (raw_smp_processor_id())
9404  #define current_pid()          (current->pid)
9405 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
9406  #define current_test_flags(f)  (current->flags & (f))
9407  #define current_set_flags_nested(sp, f)                \
9408                 (*(sp) = current->flags, current->flags |= (f))
9409 diff -NurpP --minimal linux-3.0/fs/xfs/linux-2.6/xfs_super.c linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_super.c
9410 --- linux-3.0/fs/xfs/linux-2.6/xfs_super.c      2011-07-22 11:18:09.000000000 +0200
9411 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/linux-2.6/xfs_super.c 2011-06-22 12:39:15.000000000 +0200
9412 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
9413  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
9414  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
9415  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
9416 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
9417 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
9418 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
9419  
9420  /*
9421   * Table driven mount option parser.
9422 @@ -122,10 +125,14 @@ mempool_t *xfs_ioend_pool;
9423   * in the future, too.
9424   */
9425  enum {
9426 +       Opt_tag, Opt_notag,
9427         Opt_barrier, Opt_nobarrier, Opt_err
9428  };
9429  
9430  static const match_table_t tokens = {
9431 +       {Opt_tag, "tagxid"},
9432 +       {Opt_tag, "tag"},
9433 +       {Opt_notag, "notag"},
9434         {Opt_barrier, "barrier"},
9435         {Opt_nobarrier, "nobarrier"},
9436         {Opt_err, NULL}
9437 @@ -373,6 +380,19 @@ xfs_parseargs(
9438                 } else if (!strcmp(this_char, "irixsgid")) {
9439                         xfs_warn(mp,
9440         "irixsgid is now a sysctl(2) variable, option is deprecated.");
9441 +#ifndef CONFIG_TAGGING_NONE
9442 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9443 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
9444 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
9445 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
9446 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
9447 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
9448 +#endif
9449 +#ifdef CONFIG_PROPAGATE
9450 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9451 +                       /* use value */
9452 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
9453 +#endif
9454                 } else {
9455                         xfs_warn(mp, "unknown mount option [%s].", this_char);
9456                         return EINVAL;
9457 @@ -1182,6 +1202,16 @@ xfs_fs_remount(
9458                 case Opt_nobarrier:
9459                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
9460                         break;
9461 +               case Opt_tag:
9462 +                       if (!(sb->s_flags & MS_TAGGED)) {
9463 +                               printk(KERN_INFO
9464 +                                       "XFS: %s: tagging not permitted on remount.\n",
9465 +                                       sb->s_id);
9466 +                               return -EINVAL;
9467 +                       }
9468 +                       break;
9469 +               case Opt_notag:
9470 +                       break;
9471                 default:
9472                         /*
9473                          * Logically we would return an error here to prevent
9474 @@ -1397,6 +1427,9 @@ xfs_fs_fill_super(
9475         if (error)
9476                 goto out_free_sb;
9477  
9478 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
9479 +               sb->s_flags |= MS_TAGGED;
9480 +
9481         /*
9482          * we must configure the block size in the superblock before we run the
9483          * full mount process as the mount process can lookup and cache inodes.
9484 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_dinode.h linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_dinode.h
9485 --- linux-3.0/fs/xfs/xfs_dinode.h       2011-01-05 21:50:28.000000000 +0100
9486 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_dinode.h  2011-06-10 22:11:24.000000000 +0200
9487 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
9488         __be32          di_nlink;       /* number of links to file */
9489         __be16          di_projid_lo;   /* lower part of owner's project id */
9490         __be16          di_projid_hi;   /* higher part owner's project id */
9491 -       __u8            di_pad[6];      /* unused, zeroed space */
9492 +       __u8            di_pad[2];      /* unused, zeroed space */
9493 +       __be16          di_tag;         /* context tagging */
9494 +       __be16          di_vflags;      /* vserver specific flags */
9495         __be16          di_flushiter;   /* incremented on flush */
9496         xfs_timestamp_t di_atime;       /* time last accessed */
9497         xfs_timestamp_t di_mtime;       /* time last modified */
9498 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
9499  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
9500  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
9501  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
9502 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
9503 +
9504  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
9505  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
9506  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
9507 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
9508  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
9509  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
9510  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
9511 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
9512  
9513  #ifdef CONFIG_XFS_RT
9514  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
9515 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
9516          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
9517          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
9518          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
9519 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
9520 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
9521 +        XFS_DIFLAG_IXUNLINK)
9522 +
9523 +#define XFS_DIVFLAG_BARRIER    0x01
9524 +#define XFS_DIVFLAG_COW                0x02
9525  
9526  #endif /* __XFS_DINODE_H__ */
9527 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_fs.h linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_fs.h
9528 --- linux-3.0/fs/xfs/xfs_fs.h   2011-01-05 21:50:28.000000000 +0100
9529 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_fs.h      2011-06-10 22:11:24.000000000 +0200
9530 @@ -67,6 +67,9 @@ struct fsxattr {
9531  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
9532  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
9533  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
9534 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
9535 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
9536 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
9537  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
9538  
9539  /*
9540 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
9541  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
9542         __u16           bs_forkoff;     /* inode fork offset in bytes   */
9543         __u16           bs_projid_hi;   /* higher part of project id    */
9544 -       unsigned char   bs_pad[10];     /* pad space, unused            */
9545 +       unsigned char   bs_pad[8];      /* pad space, unused            */
9546 +       __u16           bs_tag;         /* context tagging              */
9547         __u32           bs_dmevmask;    /* DMIG event mask              */
9548         __u16           bs_dmstate;     /* DMIG state info              */
9549         __u16           bs_aextents;    /* attribute number of extents  */
9550 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_ialloc.c linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_ialloc.c
9551 --- linux-3.0/fs/xfs/xfs_ialloc.c       2011-05-22 16:17:54.000000000 +0200
9552 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_ialloc.c  2011-06-10 22:11:24.000000000 +0200
9553 @@ -37,7 +37,6 @@
9554  #include "xfs_error.h"
9555  #include "xfs_bmap.h"
9556  
9557 -
9558  /*
9559   * Allocation group level functions.
9560   */
9561 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_inode.c linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_inode.c
9562 --- linux-3.0/fs/xfs/xfs_inode.c        2011-07-22 11:18:10.000000000 +0200
9563 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_inode.c   2011-06-10 22:11:24.000000000 +0200
9564 @@ -243,6 +243,7 @@ xfs_inotobp(
9565         return 0;
9566  }
9567  
9568 +#include <linux/vs_tag.h>
9569  
9570  /*
9571   * This routine is called to map an inode to the buffer containing
9572 @@ -641,15 +642,25 @@ xfs_iformat_btree(
9573  STATIC void
9574  xfs_dinode_from_disk(
9575         xfs_icdinode_t          *to,
9576 -       xfs_dinode_t            *from)
9577 +       xfs_dinode_t            *from,
9578 +       int tagged)
9579  {
9580 +       uint32_t uid, gid, tag;
9581 +
9582         to->di_magic = be16_to_cpu(from->di_magic);
9583         to->di_mode = be16_to_cpu(from->di_mode);
9584         to->di_version = from ->di_version;
9585         to->di_format = from->di_format;
9586         to->di_onlink = be16_to_cpu(from->di_onlink);
9587 -       to->di_uid = be32_to_cpu(from->di_uid);
9588 -       to->di_gid = be32_to_cpu(from->di_gid);
9589 +
9590 +       uid = be32_to_cpu(from->di_uid);
9591 +       gid = be32_to_cpu(from->di_gid);
9592 +       tag = be16_to_cpu(from->di_tag);
9593 +
9594 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
9595 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
9596 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
9597 +
9598         to->di_nlink = be32_to_cpu(from->di_nlink);
9599         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
9600         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
9601 @@ -671,21 +682,26 @@ xfs_dinode_from_disk(
9602         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
9603         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
9604         to->di_flags    = be16_to_cpu(from->di_flags);
9605 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
9606         to->di_gen      = be32_to_cpu(from->di_gen);
9607  }
9608  
9609  void
9610  xfs_dinode_to_disk(
9611         xfs_dinode_t            *to,
9612 -       xfs_icdinode_t          *from)
9613 +       xfs_icdinode_t          *from,
9614 +       int tagged)
9615  {
9616         to->di_magic = cpu_to_be16(from->di_magic);
9617         to->di_mode = cpu_to_be16(from->di_mode);
9618         to->di_version = from ->di_version;
9619         to->di_format = from->di_format;
9620         to->di_onlink = cpu_to_be16(from->di_onlink);
9621 -       to->di_uid = cpu_to_be32(from->di_uid);
9622 -       to->di_gid = cpu_to_be32(from->di_gid);
9623 +
9624 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
9625 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
9626 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
9627 +
9628         to->di_nlink = cpu_to_be32(from->di_nlink);
9629         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
9630         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
9631 @@ -707,12 +723,14 @@ xfs_dinode_to_disk(
9632         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
9633         to->di_dmstate = cpu_to_be16(from->di_dmstate);
9634         to->di_flags = cpu_to_be16(from->di_flags);
9635 +       to->di_vflags = cpu_to_be16(from->di_vflags);
9636         to->di_gen = cpu_to_be32(from->di_gen);
9637  }
9638  
9639  STATIC uint
9640  _xfs_dic2xflags(
9641 -       __uint16_t              di_flags)
9642 +       __uint16_t              di_flags,
9643 +       __uint16_t              di_vflags)
9644  {
9645         uint                    flags = 0;
9646  
9647 @@ -723,6 +741,8 @@ _xfs_dic2xflags(
9648                         flags |= XFS_XFLAG_PREALLOC;
9649                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
9650                         flags |= XFS_XFLAG_IMMUTABLE;
9651 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
9652 +                       flags |= XFS_XFLAG_IXUNLINK;
9653                 if (di_flags & XFS_DIFLAG_APPEND)
9654                         flags |= XFS_XFLAG_APPEND;
9655                 if (di_flags & XFS_DIFLAG_SYNC)
9656 @@ -747,6 +767,10 @@ _xfs_dic2xflags(
9657                         flags |= XFS_XFLAG_FILESTREAM;
9658         }
9659  
9660 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
9661 +               flags |= FS_BARRIER_FL;
9662 +       if (di_vflags & XFS_DIVFLAG_COW)
9663 +               flags |= FS_COW_FL;
9664         return flags;
9665  }
9666  
9667 @@ -756,7 +780,7 @@ xfs_ip2xflags(
9668  {
9669         xfs_icdinode_t          *dic = &ip->i_d;
9670  
9671 -       return _xfs_dic2xflags(dic->di_flags) |
9672 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
9673                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
9674  }
9675  
9676 @@ -764,7 +788,8 @@ uint
9677  xfs_dic2xflags(
9678         xfs_dinode_t            *dip)
9679  {
9680 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
9681 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
9682 +                               be16_to_cpu(dip->di_vflags)) |
9683                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
9684  }
9685  
9686 @@ -797,7 +822,6 @@ xfs_iread(
9687         if (error)
9688                 return error;
9689         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
9690 -
9691         /*
9692          * If we got something that isn't an inode it means someone
9693          * (nfs or dmi) has a stale handle.
9694 @@ -820,7 +844,8 @@ xfs_iread(
9695          * Otherwise, just get the truly permanent information.
9696          */
9697         if (dip->di_mode) {
9698 -               xfs_dinode_from_disk(&ip->i_d, dip);
9699 +               xfs_dinode_from_disk(&ip->i_d, dip,
9700 +                       mp->m_flags & XFS_MOUNT_TAGGED);
9701                 error = xfs_iformat(ip, dip);
9702                 if (error)  {
9703  #ifdef DEBUG
9704 @@ -1015,6 +1040,7 @@ xfs_ialloc(
9705         ASSERT(ip->i_d.di_nlink == nlink);
9706         ip->i_d.di_uid = current_fsuid();
9707         ip->i_d.di_gid = current_fsgid();
9708 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
9709         xfs_set_projid(ip, prid);
9710         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
9711  
9712 @@ -1075,6 +1101,7 @@ xfs_ialloc(
9713         ip->i_d.di_dmevmask = 0;
9714         ip->i_d.di_dmstate = 0;
9715         ip->i_d.di_flags = 0;
9716 +       ip->i_d.di_vflags = 0;
9717         flags = XFS_ILOG_CORE;
9718         switch (mode & S_IFMT) {
9719         case S_IFIFO:
9720 @@ -2108,6 +2135,7 @@ xfs_ifree(
9721         }
9722         ip->i_d.di_mode = 0;            /* mark incore inode as free */
9723         ip->i_d.di_flags = 0;
9724 +       ip->i_d.di_vflags = 0;
9725         ip->i_d.di_dmevmask = 0;
9726         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
9727         ip->i_df.if_ext_max =
9728 @@ -2987,7 +3015,8 @@ xfs_iflush_int(
9729          * because if the inode is dirty at all the core must
9730          * be.
9731          */
9732 -       xfs_dinode_to_disk(dip, &ip->i_d);
9733 +       xfs_dinode_to_disk(dip, &ip->i_d,
9734 +               mp->m_flags & XFS_MOUNT_TAGGED);
9735  
9736         /* Wrap, we never let the log put out DI_MAX_FLUSH */
9737         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
9738 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_inode.h linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_inode.h
9739 --- linux-3.0/fs/xfs/xfs_inode.h        2011-07-22 11:18:10.000000000 +0200
9740 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_inode.h   2011-07-01 11:35:35.000000000 +0200
9741 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
9742         __uint32_t      di_nlink;       /* number of links to file */
9743         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
9744         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
9745 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
9746 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
9747 +       __uint16_t      di_tag;         /* context tagging */
9748 +       __uint16_t      di_vflags;      /* vserver specific flags */
9749         __uint16_t      di_flushiter;   /* incremented on flush */
9750         xfs_ictimestamp_t di_atime;     /* time last accessed */
9751         xfs_ictimestamp_t di_mtime;     /* time last modified */
9752 @@ -546,7 +548,7 @@ int         xfs_itobp(struct xfs_mount *, struc
9753  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
9754                           struct xfs_inode *, uint);
9755  void           xfs_dinode_to_disk(struct xfs_dinode *,
9756 -                                  struct xfs_icdinode *);
9757 +                                  struct xfs_icdinode *, int);
9758  void           xfs_idestroy_fork(struct xfs_inode *, int);
9759  void           xfs_idata_realloc(struct xfs_inode *, int, int);
9760  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
9761 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_itable.c linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_itable.c
9762 --- linux-3.0/fs/xfs/xfs_itable.c       2011-05-22 16:17:54.000000000 +0200
9763 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_itable.c  2011-06-10 22:11:24.000000000 +0200
9764 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
9765         buf->bs_mode = dic->di_mode;
9766         buf->bs_uid = dic->di_uid;
9767         buf->bs_gid = dic->di_gid;
9768 +       buf->bs_tag = dic->di_tag;
9769         buf->bs_size = dic->di_size;
9770  
9771         /*
9772 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_log_recover.c linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_log_recover.c
9773 --- linux-3.0/fs/xfs/xfs_log_recover.c  2011-07-22 11:18:10.000000000 +0200
9774 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_log_recover.c     2011-06-10 22:11:24.000000000 +0200
9775 @@ -2343,7 +2343,8 @@ xlog_recover_inode_pass2(
9776         }
9777  
9778         /* The core is in in-core format */
9779 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
9780 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
9781 +               mp->m_flags & XFS_MOUNT_TAGGED);
9782  
9783         /* the rest is in on-disk format */
9784         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
9785 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_mount.h linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_mount.h
9786 --- linux-3.0/fs/xfs/xfs_mount.h        2011-07-22 11:18:10.000000000 +0200
9787 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_mount.h   2011-06-10 22:11:24.000000000 +0200
9788 @@ -249,6 +249,7 @@ typedef struct xfs_mount {
9789                                                    allocator */
9790  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
9791  
9792 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
9793  
9794  /*
9795   * Default minimum read and write sizes.
9796 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_vnodeops.c linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_vnodeops.c
9797 --- linux-3.0/fs/xfs/xfs_vnodeops.c     2011-07-22 11:18:10.000000000 +0200
9798 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_vnodeops.c        2011-07-01 11:35:35.000000000 +0200
9799 @@ -50,6 +50,78 @@
9800  #include "xfs_vnodeops.h"
9801  #include "xfs_trace.h"
9802  
9803 +
9804 +STATIC void
9805 +xfs_get_inode_flags(
9806 +       xfs_inode_t     *ip)
9807 +{
9808 +       struct inode    *inode = VFS_I(ip);
9809 +       unsigned int    flags = inode->i_flags;
9810 +       unsigned int    vflags = inode->i_vflags;
9811 +
9812 +       if (flags & S_IMMUTABLE)
9813 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
9814 +       else
9815 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
9816 +       if (flags & S_IXUNLINK)
9817 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
9818 +       else
9819 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
9820 +
9821 +       if (vflags & V_BARRIER)
9822 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
9823 +       else
9824 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
9825 +       if (vflags & V_COW)
9826 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
9827 +       else
9828 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
9829 +}
9830 +
9831 +int
9832 +xfs_sync_flags(
9833 +       struct inode            *inode,
9834 +       int                     flags,
9835 +       int                     vflags)
9836 +{
9837 +       struct xfs_inode        *ip = XFS_I(inode);
9838 +       struct xfs_mount        *mp = ip->i_mount;
9839 +       struct xfs_trans        *tp;
9840 +       unsigned int            lock_flags = 0;
9841 +       int                     code;
9842 +
9843 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
9844 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
9845 +       if (code)
9846 +               goto error_out;
9847 +
9848 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
9849 +
9850 +       xfs_trans_ijoin(tp, ip);
9851 +
9852 +       inode->i_flags = flags;
9853 +       inode->i_vflags = vflags;
9854 +       xfs_get_inode_flags(ip);
9855 +
9856 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
9857 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
9858 +
9859 +       XFS_STATS_INC(xs_ig_attrchg);
9860 +
9861 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
9862 +               xfs_trans_set_sync(tp);
9863 +       code = xfs_trans_commit(tp, 0);
9864 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
9865 +       return code;
9866 +
9867 +error_out:
9868 +       xfs_trans_cancel(tp, 0);
9869 +       if (lock_flags)
9870 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
9871 +       return code;
9872 +}
9873 +
9874 +
9875  int
9876  xfs_setattr(
9877         struct xfs_inode        *ip,
9878 @@ -65,6 +137,7 @@ xfs_setattr(
9879         uint                    commit_flags=0;
9880         uid_t                   uid=0, iuid=0;
9881         gid_t                   gid=0, igid=0;
9882 +       tag_t                   tag=0, itag=0;
9883         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
9884         int                     need_iolock = 1;
9885  
9886 @@ -147,7 +220,7 @@ xfs_setattr(
9887         /*
9888          * Change file ownership.  Must be the owner or privileged.
9889          */
9890 -       if (mask & (ATTR_UID|ATTR_GID)) {
9891 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
9892                 /*
9893                  * These IDs could have changed since we last looked at them.
9894                  * But, we're assured that if the ownership did change
9895 @@ -156,8 +229,10 @@ xfs_setattr(
9896                  */
9897                 iuid = ip->i_d.di_uid;
9898                 igid = ip->i_d.di_gid;
9899 +               itag = ip->i_d.di_tag;
9900                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
9901                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
9902 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
9903  
9904                 /*
9905                  * Do a quota reservation only if uid/gid is actually
9906 @@ -165,7 +240,8 @@ xfs_setattr(
9907                  */
9908                 if (XFS_IS_QUOTA_RUNNING(mp) &&
9909                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
9910 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
9911 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
9912 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
9913                         ASSERT(tp);
9914                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
9915                                                 capable(CAP_FOWNER) ?
9916 @@ -329,7 +405,7 @@ xfs_setattr(
9917         /*
9918          * Change file ownership.  Must be the owner or privileged.
9919          */
9920 -       if (mask & (ATTR_UID|ATTR_GID)) {
9921 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
9922                 /*
9923                  * CAP_FSETID overrides the following restrictions:
9924                  *
9925 @@ -345,6 +421,10 @@ xfs_setattr(
9926                  * Change the ownerships and register quota modifications
9927                  * in the transaction.
9928                  */
9929 +               if (itag != tag) {
9930 +                       ip->i_d.di_tag = tag;
9931 +                       inode->i_tag = tag;
9932 +               }
9933                 if (iuid != uid) {
9934                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
9935                                 ASSERT(mask & ATTR_UID);
9936 diff -NurpP --minimal linux-3.0/fs/xfs/xfs_vnodeops.h linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_vnodeops.h
9937 --- linux-3.0/fs/xfs/xfs_vnodeops.h     2011-05-22 16:17:54.000000000 +0200
9938 +++ linux-3.0-vs2.3.1-pre6/fs/xfs/xfs_vnodeops.h        2011-06-10 22:11:24.000000000 +0200
9939 @@ -13,6 +13,7 @@ struct xfs_inode;
9940  struct xfs_iomap;
9941  
9942  
9943 +int xfs_sync_xflags(struct xfs_inode *ip);
9944  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
9945  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
9946  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
9947 diff -NurpP --minimal linux-3.0/include/asm-generic/tlb.h linux-3.0-vs2.3.1-pre6/include/asm-generic/tlb.h
9948 --- linux-3.0/include/asm-generic/tlb.h 2011-07-22 11:18:10.000000000 +0200
9949 +++ linux-3.0-vs2.3.1-pre6/include/asm-generic/tlb.h    2011-06-10 22:11:24.000000000 +0200
9950 @@ -16,6 +16,7 @@
9951  #define _ASM_GENERIC__TLB_H
9952  
9953  #include <linux/swap.h>
9954 +#include <linux/vs_memory.h>
9955  #include <asm/pgalloc.h>
9956  #include <asm/tlbflush.h>
9957  
9958 diff -NurpP --minimal linux-3.0/include/linux/Kbuild linux-3.0-vs2.3.1-pre6/include/linux/Kbuild
9959 --- linux-3.0/include/linux/Kbuild      2011-07-22 11:18:10.000000000 +0200
9960 +++ linux-3.0-vs2.3.1-pre6/include/linux/Kbuild 2011-06-10 22:11:24.000000000 +0200
9961 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
9962  header-y += netfilter_ipv4/
9963  header-y += netfilter_ipv6/
9964  header-y += usb/
9965 +header-y += vserver/
9966  header-y += wimax/
9967  
9968  objhdr-y += version.h
9969 diff -NurpP --minimal linux-3.0/include/linux/capability.h linux-3.0-vs2.3.1-pre6/include/linux/capability.h
9970 --- linux-3.0/include/linux/capability.h        2011-07-22 11:18:10.000000000 +0200
9971 +++ linux-3.0-vs2.3.1-pre6/include/linux/capability.h   2011-06-10 22:11:24.000000000 +0200
9972 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
9973     arbitrary SCSI commands */
9974  /* Allow setting encryption key on loopback filesystem */
9975  /* Allow setting zone reclaim policy */
9976 +/* Allow the selection of a security context */
9977  
9978  #define CAP_SYS_ADMIN        21
9979  
9980 @@ -362,7 +363,12 @@ struct cpu_vfs_cap_data {
9981  
9982  #define CAP_LAST_CAP         CAP_WAKE_ALARM
9983  
9984 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
9985 +/* Allow context manipulations */
9986 +/* Allow changing context info on files */
9987 +
9988 +#define CAP_CONTEXT         63
9989 +
9990 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
9991  
9992  /*
9993   * Bit location of each capability (used by user-space library and kernel)
9994 diff -NurpP --minimal linux-3.0/include/linux/cred.h linux-3.0-vs2.3.1-pre6/include/linux/cred.h
9995 --- linux-3.0/include/linux/cred.h      2011-07-22 11:18:10.000000000 +0200
9996 +++ linux-3.0-vs2.3.1-pre6/include/linux/cred.h 2011-06-10 22:11:24.000000000 +0200
9997 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
9998  extern int copy_creds(struct task_struct *, unsigned long);
9999  extern const struct cred *get_task_cred(struct task_struct *);
10000  extern struct cred *cred_alloc_blank(void);
10001 +extern struct cred *__prepare_creds(const struct cred *);
10002  extern struct cred *prepare_creds(void);
10003  extern struct cred *prepare_exec_creds(void);
10004  extern int commit_creds(struct cred *);
10005 @@ -209,6 +210,31 @@ static inline void validate_process_cred
10006  }
10007  #endif
10008  
10009 +static inline void set_cred_subscribers(struct cred *cred, int n)
10010 +{
10011 +#ifdef CONFIG_DEBUG_CREDENTIALS
10012 +       atomic_set(&cred->subscribers, n);
10013 +#endif
10014 +}
10015 +
10016 +static inline int read_cred_subscribers(const struct cred *cred)
10017 +{
10018 +#ifdef CONFIG_DEBUG_CREDENTIALS
10019 +       return atomic_read(&cred->subscribers);
10020 +#else
10021 +       return 0;
10022 +#endif
10023 +}
10024 +
10025 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
10026 +{
10027 +#ifdef CONFIG_DEBUG_CREDENTIALS
10028 +       struct cred *cred = (struct cred *) _cred;
10029 +
10030 +       atomic_add(n, &cred->subscribers);
10031 +#endif
10032 +}
10033 +
10034  /**
10035   * get_new_cred - Get a reference on a new set of credentials
10036   * @cred: The new credentials to reference
10037 diff -NurpP --minimal linux-3.0/include/linux/devpts_fs.h linux-3.0-vs2.3.1-pre6/include/linux/devpts_fs.h
10038 --- linux-3.0/include/linux/devpts_fs.h 2008-12-25 00:26:37.000000000 +0100
10039 +++ linux-3.0-vs2.3.1-pre6/include/linux/devpts_fs.h    2011-06-10 22:11:24.000000000 +0200
10040 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
10041  
10042  #endif
10043  
10044 -
10045  #endif /* _LINUX_DEVPTS_FS_H */
10046 diff -NurpP --minimal linux-3.0/include/linux/ext2_fs.h linux-3.0-vs2.3.1-pre6/include/linux/ext2_fs.h
10047 --- linux-3.0/include/linux/ext2_fs.h   2010-02-25 11:52:07.000000000 +0100
10048 +++ linux-3.0-vs2.3.1-pre6/include/linux/ext2_fs.h      2011-06-10 22:11:24.000000000 +0200
10049 @@ -189,8 +189,12 @@ struct ext2_group_desc
10050  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
10051  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
10052  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
10053 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
10054  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
10055  
10056 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
10057 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
10058 +
10059  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
10060  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
10061  
10062 @@ -274,7 +278,8 @@ struct ext2_inode {
10063                         __u16   i_pad1;
10064                         __le16  l_i_uid_high;   /* these 2 fields    */
10065                         __le16  l_i_gid_high;   /* were reserved2[0] */
10066 -                       __u32   l_i_reserved2;
10067 +                       __le16  l_i_tag;        /* Context Tag */
10068 +                       __u16   l_i_reserved2;
10069                 } linux2;
10070                 struct {
10071                         __u8    h_i_frag;       /* Fragment number */
10072 @@ -303,6 +308,7 @@ struct ext2_inode {
10073  #define i_gid_low      i_gid
10074  #define i_uid_high     osd2.linux2.l_i_uid_high
10075  #define i_gid_high     osd2.linux2.l_i_gid_high
10076 +#define i_raw_tag      osd2.linux2.l_i_tag
10077  #define i_reserved2    osd2.linux2.l_i_reserved2
10078  #endif
10079  
10080 @@ -347,6 +353,7 @@ struct ext2_inode {
10081  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
10082  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
10083  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
10084 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
10085  
10086  
10087  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
10088 diff -NurpP --minimal linux-3.0/include/linux/ext3_fs.h linux-3.0-vs2.3.1-pre6/include/linux/ext3_fs.h
10089 --- linux-3.0/include/linux/ext3_fs.h   2011-07-22 11:18:10.000000000 +0200
10090 +++ linux-3.0-vs2.3.1-pre6/include/linux/ext3_fs.h      2011-06-10 22:11:24.000000000 +0200
10091 @@ -173,10 +173,14 @@ struct ext3_group_desc
10092  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
10093  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
10094  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
10095 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
10096  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
10097  
10098 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
10099 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
10100 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
10101 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
10102 +
10103 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
10104 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
10105  
10106  /* Flags that should be inherited by new inodes from their parent. */
10107  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
10108 @@ -312,7 +316,8 @@ struct ext3_inode {
10109                         __u16   i_pad1;
10110                         __le16  l_i_uid_high;   /* these 2 fields    */
10111                         __le16  l_i_gid_high;   /* were reserved2[0] */
10112 -                       __u32   l_i_reserved2;
10113 +                       __le16  l_i_tag;        /* Context Tag */
10114 +                       __u16   l_i_reserved2;
10115                 } linux2;
10116                 struct {
10117                         __u8    h_i_frag;       /* Fragment number */
10118 @@ -343,6 +348,7 @@ struct ext3_inode {
10119  #define i_gid_low      i_gid
10120  #define i_uid_high     osd2.linux2.l_i_uid_high
10121  #define i_gid_high     osd2.linux2.l_i_gid_high
10122 +#define i_raw_tag      osd2.linux2.l_i_tag
10123  #define i_reserved2    osd2.linux2.l_i_reserved2
10124  
10125  #elif defined(__GNU__)
10126 @@ -405,6 +411,7 @@ struct ext3_inode {
10127  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
10128  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
10129                                                   * error in ordered mode */
10130 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
10131  
10132  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
10133  #ifndef _LINUX_EXT2_FS_H
10134 @@ -919,6 +926,7 @@ extern void ext3_get_inode_flags(struct 
10135  extern void ext3_set_aops(struct inode *inode);
10136  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
10137                        u64 start, u64 len);
10138 +extern int ext3_sync_flags(struct inode *, int, int);
10139  
10140  /* ioctl.c */
10141  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
10142 diff -NurpP --minimal linux-3.0/include/linux/fs.h linux-3.0-vs2.3.1-pre6/include/linux/fs.h
10143 --- linux-3.0/include/linux/fs.h        2011-07-22 11:18:10.000000000 +0200
10144 +++ linux-3.0-vs2.3.1-pre6/include/linux/fs.h   2011-07-01 11:35:35.000000000 +0200
10145 @@ -208,6 +208,9 @@ struct inodes_stat_t {
10146  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
10147  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
10148  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
10149 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
10150 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
10151 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
10152  #define MS_NOSEC       (1<<28)
10153  #define MS_BORN                (1<<29)
10154  #define MS_ACTIVE      (1<<30)
10155 @@ -239,6 +242,14 @@ struct inodes_stat_t {
10156  #define S_IMA          1024    /* Inode has an associated IMA struct */
10157  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
10158  #define S_NOSEC                4096    /* no suid or xattr security attributes */
10159 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
10160 +
10161 +/* Linux-VServer related Inode flags */
10162 +
10163 +#define V_VALID                1
10164 +#define V_XATTR                2
10165 +#define V_BARRIER      4       /* Barrier for chroot() */
10166 +#define V_COW          8       /* Copy on Write */
10167  
10168  /*
10169   * Note that nosuid etc flags are inode-specific: setting some file-system
10170 @@ -261,12 +272,15 @@ struct inodes_stat_t {
10171  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
10172                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
10173  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
10174 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
10175 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
10176 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
10177 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
10178 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
10179  
10180  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
10181  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
10182  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
10183 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
10184 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
10185  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
10186  
10187  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
10188 @@ -277,6 +291,16 @@ struct inodes_stat_t {
10189  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
10190  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
10191  
10192 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
10193 +
10194 +#ifdef CONFIG_VSERVER_COWBL
10195 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
10196 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
10197 +#else
10198 +#  define IS_COW(inode)                (0)
10199 +#  define IS_COW_LINK(inode)   (0)
10200 +#endif
10201 +
10202  /* the read-only stuff doesn't really belong here, but any other place is
10203     probably as bad and I don't want to create yet another include file. */
10204  
10205 @@ -362,11 +386,14 @@ struct inodes_stat_t {
10206  #define FS_EXTENT_FL                   0x00080000 /* Extents */
10207  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
10208  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
10209 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
10210  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
10211  
10212 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
10213 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
10214 -
10215 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
10216 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
10217 +
10218 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
10219 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
10220  
10221  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
10222  #define SYNC_FILE_RANGE_WRITE          2
10223 @@ -447,6 +474,7 @@ typedef void (dio_iodone_t)(struct kiocb
10224  #define ATTR_KILL_PRIV (1 << 14)
10225  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
10226  #define ATTR_TIMES_SET (1 << 16)
10227 +#define ATTR_TAG       (1 << 17)
10228  
10229  /*
10230   * This is the Inode Attributes structure, used for notify_change().  It
10231 @@ -462,6 +490,7 @@ struct iattr {
10232         umode_t         ia_mode;
10233         uid_t           ia_uid;
10234         gid_t           ia_gid;
10235 +       tag_t           ia_tag;
10236         loff_t          ia_size;
10237         struct timespec ia_atime;
10238         struct timespec ia_mtime;
10239 @@ -475,6 +504,9 @@ struct iattr {
10240         struct file     *ia_file;
10241  };
10242  
10243 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
10244 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
10245 +
10246  /*
10247   * Includes for diskquotas.
10248   */
10249 @@ -740,11 +772,13 @@ struct inode {
10250         umode_t                 i_mode;
10251         uid_t                   i_uid;
10252         gid_t                   i_gid;
10253 +       tag_t                   i_tag;
10254         const struct inode_operations   *i_op;
10255         struct super_block      *i_sb;
10256  
10257         spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
10258 -       unsigned int            i_flags;
10259 +       unsigned short          i_flags;
10260 +       unsigned short          i_vflags;
10261         unsigned long           i_state;
10262  #ifdef CONFIG_SECURITY
10263         void                    *i_security;
10264 @@ -766,6 +800,7 @@ struct inode {
10265         atomic_t                i_count;
10266         unsigned int            i_nlink;
10267         dev_t                   i_rdev;
10268 +       dev_t                   i_mdev;
10269         unsigned int            i_blkbits;
10270         u64                     i_version;
10271         loff_t                  i_size;
10272 @@ -890,12 +925,12 @@ static inline void i_size_write(struct i
10273  
10274  static inline unsigned iminor(const struct inode *inode)
10275  {
10276 -       return MINOR(inode->i_rdev);
10277 +       return MINOR(inode->i_mdev);
10278  }
10279  
10280  static inline unsigned imajor(const struct inode *inode)
10281  {
10282 -       return MAJOR(inode->i_rdev);
10283 +       return MAJOR(inode->i_mdev);
10284  }
10285  
10286  extern struct block_device *I_BDEV(struct inode *inode);
10287 @@ -957,6 +992,7 @@ struct file {
10288         loff_t                  f_pos;
10289         struct fown_struct      f_owner;
10290         const struct cred       *f_cred;
10291 +       xid_t                   f_xid;
10292         struct file_ra_state    f_ra;
10293  
10294         u64                     f_version;
10295 @@ -1101,6 +1137,7 @@ struct file_lock {
10296         struct file *fl_file;
10297         loff_t fl_start;
10298         loff_t fl_end;
10299 +       xid_t fl_xid;
10300  
10301         struct fasync_struct *  fl_fasync; /* for lease break notifications */
10302         unsigned long fl_break_time;    /* for nonblocking lease breaks */
10303 @@ -1600,6 +1637,7 @@ struct inode_operations {
10304         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
10305         ssize_t (*listxattr) (struct dentry *, char *, size_t);
10306         int (*removexattr) (struct dentry *, const char *);
10307 +       int (*sync_flags) (struct inode *, int, int);
10308         void (*truncate_range)(struct inode *, loff_t, loff_t);
10309         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
10310                       u64 len);
10311 @@ -1618,6 +1656,7 @@ extern ssize_t vfs_readv(struct file *, 
10312                 unsigned long, loff_t *);
10313  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
10314                 unsigned long, loff_t *);
10315 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
10316  
10317  struct super_operations {
10318         struct inode *(*alloc_inode)(struct super_block *sb);
10319 @@ -2437,6 +2476,7 @@ extern int dcache_dir_open(struct inode 
10320  extern int dcache_dir_close(struct inode *, struct file *);
10321  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
10322  extern int dcache_readdir(struct file *, void *, filldir_t);
10323 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
10324  extern int simple_setattr(struct dentry *, struct iattr *);
10325  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
10326  extern int simple_statfs(struct dentry *, struct kstatfs *);
10327 diff -NurpP --minimal linux-3.0/include/linux/gfs2_ondisk.h linux-3.0-vs2.3.1-pre6/include/linux/gfs2_ondisk.h
10328 --- linux-3.0/include/linux/gfs2_ondisk.h       2010-07-07 18:31:55.000000000 +0200
10329 +++ linux-3.0-vs2.3.1-pre6/include/linux/gfs2_ondisk.h  2011-06-10 22:11:24.000000000 +0200
10330 @@ -211,6 +211,9 @@ enum {
10331         gfs2fl_NoAtime          = 7,
10332         gfs2fl_Sync             = 8,
10333         gfs2fl_System           = 9,
10334 +       gfs2fl_IXUnlink         = 16,
10335 +       gfs2fl_Barrier          = 17,
10336 +       gfs2fl_Cow              = 18,
10337         gfs2fl_TruncInProg      = 29,
10338         gfs2fl_InheritDirectio  = 30,
10339         gfs2fl_InheritJdata     = 31,
10340 @@ -227,6 +230,9 @@ enum {
10341  #define GFS2_DIF_NOATIME               0x00000080
10342  #define GFS2_DIF_SYNC                  0x00000100
10343  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
10344 +#define GFS2_DIF_IXUNLINK              0x00010000
10345 +#define GFS2_DIF_BARRIER               0x00020000
10346 +#define GFS2_DIF_COW                   0x00040000
10347  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
10348  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
10349  #define GFS2_DIF_INHERIT_JDATA         0x80000000
10350 diff -NurpP --minimal linux-3.0/include/linux/if_tun.h linux-3.0-vs2.3.1-pre6/include/linux/if_tun.h
10351 --- linux-3.0/include/linux/if_tun.h    2010-08-02 16:52:54.000000000 +0200
10352 +++ linux-3.0-vs2.3.1-pre6/include/linux/if_tun.h       2011-06-10 22:11:24.000000000 +0200
10353 @@ -53,6 +53,7 @@
10354  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
10355  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
10356  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
10357 +#define TUNSETNID     _IOW('T', 217, int)
10358  
10359  /* TUNSETIFF ifr flags */
10360  #define IFF_TUN                0x0001
10361 diff -NurpP --minimal linux-3.0/include/linux/init_task.h linux-3.0-vs2.3.1-pre6/include/linux/init_task.h
10362 --- linux-3.0/include/linux/init_task.h 2011-07-22 11:18:10.000000000 +0200
10363 +++ linux-3.0-vs2.3.1-pre6/include/linux/init_task.h    2011-06-10 22:11:24.000000000 +0200
10364 @@ -193,6 +193,10 @@ extern struct cred init_cred;
10365         INIT_FTRACE_GRAPH                                               \
10366         INIT_TRACE_RECURSION                                            \
10367         INIT_TASK_RCU_PREEMPT(tsk)                                      \
10368 +       .xid            = 0,                                            \
10369 +       .vx_info        = NULL,                                         \
10370 +       .nid            = 0,                                            \
10371 +       .nx_info        = NULL,                                         \
10372  }
10373  
10374  
10375 diff -NurpP --minimal linux-3.0/include/linux/ipc.h linux-3.0-vs2.3.1-pre6/include/linux/ipc.h
10376 --- linux-3.0/include/linux/ipc.h       2009-12-03 20:02:55.000000000 +0100
10377 +++ linux-3.0-vs2.3.1-pre6/include/linux/ipc.h  2011-06-10 22:11:24.000000000 +0200
10378 @@ -91,6 +91,7 @@ struct kern_ipc_perm
10379         key_t           key;
10380         uid_t           uid;
10381         gid_t           gid;
10382 +       xid_t           xid;
10383         uid_t           cuid;
10384         gid_t           cgid;
10385         mode_t          mode; 
10386 diff -NurpP --minimal linux-3.0/include/linux/ipc_namespace.h linux-3.0-vs2.3.1-pre6/include/linux/ipc_namespace.h
10387 --- linux-3.0/include/linux/ipc_namespace.h     2011-05-22 16:17:55.000000000 +0200
10388 +++ linux-3.0-vs2.3.1-pre6/include/linux/ipc_namespace.h        2011-06-13 14:09:44.000000000 +0200
10389 @@ -94,7 +94,8 @@ static inline int mq_init_ns(struct ipc_
10390  
10391  #if defined(CONFIG_IPC_NS)
10392  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
10393 -                                      struct task_struct *tsk);
10394 +                                      struct ipc_namespace *old_ns,
10395 +                                      struct user_namespace *user_ns);
10396  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
10397  {
10398         if (ns)
10399 @@ -105,12 +106,13 @@ static inline struct ipc_namespace *get_
10400  extern void put_ipc_ns(struct ipc_namespace *ns);
10401  #else
10402  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
10403 -                                             struct task_struct *tsk)
10404 +                                             struct ipc_namespace *old_ns,
10405 +                                             struct user_namespace *user_ns)
10406  {
10407         if (flags & CLONE_NEWIPC)
10408                 return ERR_PTR(-EINVAL);
10409  
10410 -       return tsk->nsproxy->ipc_ns;
10411 +       return old_ns;
10412  }
10413  
10414  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
10415 diff -NurpP --minimal linux-3.0/include/linux/loop.h linux-3.0-vs2.3.1-pre6/include/linux/loop.h
10416 --- linux-3.0/include/linux/loop.h      2009-09-10 15:26:25.000000000 +0200
10417 +++ linux-3.0-vs2.3.1-pre6/include/linux/loop.h 2011-06-10 22:11:24.000000000 +0200
10418 @@ -45,6 +45,7 @@ struct loop_device {
10419         struct loop_func_table *lo_encryption;
10420         __u32           lo_init[2];
10421         uid_t           lo_key_owner;   /* Who set the key */
10422 +       xid_t           lo_xid;
10423         int             (*ioctl)(struct loop_device *, int cmd, 
10424                                  unsigned long arg); 
10425  
10426 diff -NurpP --minimal linux-3.0/include/linux/magic.h linux-3.0-vs2.3.1-pre6/include/linux/magic.h
10427 --- linux-3.0/include/linux/magic.h     2011-05-22 16:17:55.000000000 +0200
10428 +++ linux-3.0-vs2.3.1-pre6/include/linux/magic.h        2011-06-10 22:11:24.000000000 +0200
10429 @@ -3,7 +3,7 @@
10430  
10431  #define ADFS_SUPER_MAGIC       0xadf5
10432  #define AFFS_SUPER_MAGIC       0xadff
10433 -#define AFS_SUPER_MAGIC                0x5346414F
10434 +#define AFS_SUPER_MAGIC                0x5346414F
10435  #define AUTOFS_SUPER_MAGIC     0x0187
10436  #define CODA_SUPER_MAGIC       0x73757245
10437  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
10438 @@ -41,6 +41,7 @@
10439  #define NFS_SUPER_MAGIC                0x6969
10440  #define OPENPROM_SUPER_MAGIC   0x9fa1
10441  #define PROC_SUPER_MAGIC       0x9fa0
10442 +#define DEVPTS_SUPER_MAGIC     0x1cd1
10443  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
10444  
10445  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
10446 diff -NurpP --minimal linux-3.0/include/linux/major.h linux-3.0-vs2.3.1-pre6/include/linux/major.h
10447 --- linux-3.0/include/linux/major.h     2009-09-10 15:26:25.000000000 +0200
10448 +++ linux-3.0-vs2.3.1-pre6/include/linux/major.h        2011-06-10 22:11:24.000000000 +0200
10449 @@ -15,6 +15,7 @@
10450  #define HD_MAJOR               IDE0_MAJOR
10451  #define PTY_SLAVE_MAJOR                3
10452  #define TTY_MAJOR              4
10453 +#define VROOT_MAJOR            4
10454  #define TTYAUX_MAJOR           5
10455  #define LP_MAJOR               6
10456  #define VCS_MAJOR              7
10457 diff -NurpP --minimal linux-3.0/include/linux/memcontrol.h linux-3.0-vs2.3.1-pre6/include/linux/memcontrol.h
10458 --- linux-3.0/include/linux/memcontrol.h        2011-07-22 11:18:10.000000000 +0200
10459 +++ linux-3.0-vs2.3.1-pre6/include/linux/memcontrol.h   2011-06-22 12:39:15.000000000 +0200
10460 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
10461  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
10462  extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
10463  
10464 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
10465 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
10466 +
10467 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
10468 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
10469 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
10470 +
10471  static inline
10472  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
10473  {
10474 diff -NurpP --minimal linux-3.0/include/linux/mm_types.h linux-3.0-vs2.3.1-pre6/include/linux/mm_types.h
10475 --- linux-3.0/include/linux/mm_types.h  2011-07-22 11:18:11.000000000 +0200
10476 +++ linux-3.0-vs2.3.1-pre6/include/linux/mm_types.h     2011-06-10 22:11:24.000000000 +0200
10477 @@ -268,6 +268,7 @@ struct mm_struct {
10478  
10479         /* Architecture-specific MM context */
10480         mm_context_t context;
10481 +       struct vx_info *mm_vx_info;
10482  
10483         /* Swap token stuff */
10484         /*
10485 diff -NurpP --minimal linux-3.0/include/linux/mmzone.h linux-3.0-vs2.3.1-pre6/include/linux/mmzone.h
10486 --- linux-3.0/include/linux/mmzone.h    2011-07-22 11:18:11.000000000 +0200
10487 +++ linux-3.0-vs2.3.1-pre6/include/linux/mmzone.h       2011-07-01 11:35:35.000000000 +0200
10488 @@ -654,6 +654,13 @@ typedef struct pglist_data {
10489         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
10490  })
10491  
10492 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
10493 +
10494 +#define node_end_pfn(nid) ({\
10495 +       pg_data_t *__pgdat = NODE_DATA(nid);\
10496 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
10497 +})
10498 +
10499  #include <linux/memory_hotplug.h>
10500  
10501  extern struct mutex zonelists_mutex;
10502 diff -NurpP --minimal linux-3.0/include/linux/mount.h linux-3.0-vs2.3.1-pre6/include/linux/mount.h
10503 --- linux-3.0/include/linux/mount.h     2011-03-15 18:07:39.000000000 +0100
10504 +++ linux-3.0-vs2.3.1-pre6/include/linux/mount.h        2011-06-10 22:11:24.000000000 +0200
10505 @@ -52,6 +52,9 @@ struct mnt_pcp {
10506         int mnt_writers;
10507  };
10508  
10509 +#define MNT_TAGID      0x10000
10510 +#define MNT_NOTAG      0x20000
10511 +
10512  struct vfsmount {
10513         struct list_head mnt_hash;
10514         struct vfsmount *mnt_parent;    /* fs we are mounted on */
10515 @@ -86,6 +89,7 @@ struct vfsmount {
10516         int mnt_expiry_mark;            /* true if marked for expiry */
10517         int mnt_pinned;
10518         int mnt_ghosts;
10519 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
10520  };
10521  
10522  struct file; /* forward dec */
10523 diff -NurpP --minimal linux-3.0/include/linux/net.h linux-3.0-vs2.3.1-pre6/include/linux/net.h
10524 --- linux-3.0/include/linux/net.h       2011-07-22 11:18:11.000000000 +0200
10525 +++ linux-3.0-vs2.3.1-pre6/include/linux/net.h  2011-06-10 22:11:24.000000000 +0200
10526 @@ -72,6 +72,7 @@ struct net;
10527  #define SOCK_NOSPACE           2
10528  #define SOCK_PASSCRED          3
10529  #define SOCK_PASSSEC           4
10530 +#define SOCK_USER_SOCKET       5
10531  
10532  #ifndef ARCH_HAS_SOCKET_TYPES
10533  /**
10534 diff -NurpP --minimal linux-3.0/include/linux/nfs_mount.h linux-3.0-vs2.3.1-pre6/include/linux/nfs_mount.h
10535 --- linux-3.0/include/linux/nfs_mount.h 2011-01-05 21:50:31.000000000 +0100
10536 +++ linux-3.0-vs2.3.1-pre6/include/linux/nfs_mount.h    2011-06-10 22:11:24.000000000 +0200
10537 @@ -63,7 +63,8 @@ struct nfs_mount_data {
10538  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
10539  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
10540  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
10541 -#define NFS_MOUNT_FLAGMASK     0xFFFF
10542 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
10543 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
10544  
10545  /* The following are for internal use only */
10546  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
10547 diff -NurpP --minimal linux-3.0/include/linux/nsproxy.h linux-3.0-vs2.3.1-pre6/include/linux/nsproxy.h
10548 --- linux-3.0/include/linux/nsproxy.h   2011-07-22 11:18:11.000000000 +0200
10549 +++ linux-3.0-vs2.3.1-pre6/include/linux/nsproxy.h      2011-06-10 22:11:24.000000000 +0200
10550 @@ -3,6 +3,7 @@
10551  
10552  #include <linux/spinlock.h>
10553  #include <linux/sched.h>
10554 +#include <linux/vserver/debug.h>
10555  
10556  struct mnt_namespace;
10557  struct uts_namespace;
10558 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
10559  }
10560  
10561  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
10562 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
10563  void exit_task_namespaces(struct task_struct *tsk);
10564  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
10565  void free_nsproxy(struct nsproxy *ns);
10566  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
10567         struct fs_struct *);
10568  
10569 -static inline void put_nsproxy(struct nsproxy *ns)
10570 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
10571 +
10572 +static inline void __get_nsproxy(struct nsproxy *ns,
10573 +       const char *_file, int _line)
10574  {
10575 -       if (atomic_dec_and_test(&ns->count)) {
10576 -               free_nsproxy(ns);
10577 -       }
10578 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
10579 +               ns, atomic_read(&ns->count), _file, _line);
10580 +       atomic_inc(&ns->count);
10581  }
10582  
10583 -static inline void get_nsproxy(struct nsproxy *ns)
10584 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
10585 +
10586 +static inline void __put_nsproxy(struct nsproxy *ns,
10587 +       const char *_file, int _line)
10588  {
10589 -       atomic_inc(&ns->count);
10590 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
10591 +               ns, atomic_read(&ns->count), _file, _line);
10592 +       if (atomic_dec_and_test(&ns->count)) {
10593 +               free_nsproxy(ns);
10594 +       }
10595  }
10596  
10597  #endif
10598 diff -NurpP --minimal linux-3.0/include/linux/pid.h linux-3.0-vs2.3.1-pre6/include/linux/pid.h
10599 --- linux-3.0/include/linux/pid.h       2011-07-22 11:18:11.000000000 +0200
10600 +++ linux-3.0-vs2.3.1-pre6/include/linux/pid.h  2011-06-10 22:11:24.000000000 +0200
10601 @@ -8,7 +8,8 @@ enum pid_type
10602         PIDTYPE_PID,
10603         PIDTYPE_PGID,
10604         PIDTYPE_SID,
10605 -       PIDTYPE_MAX
10606 +       PIDTYPE_MAX,
10607 +       PIDTYPE_REALPID
10608  };
10609  
10610  /*
10611 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
10612  }
10613  
10614  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
10615 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
10616  pid_t pid_vnr(struct pid *pid);
10617  
10618  #define do_each_pid_task(pid, type, task)                              \
10619 diff -NurpP --minimal linux-3.0/include/linux/proc_fs.h linux-3.0-vs2.3.1-pre6/include/linux/proc_fs.h
10620 --- linux-3.0/include/linux/proc_fs.h   2011-07-22 11:18:11.000000000 +0200
10621 +++ linux-3.0-vs2.3.1-pre6/include/linux/proc_fs.h      2011-06-10 22:11:24.000000000 +0200
10622 @@ -56,6 +56,7 @@ struct proc_dir_entry {
10623         nlink_t nlink;
10624         uid_t uid;
10625         gid_t gid;
10626 +       int vx_flags;
10627         loff_t size;
10628         const struct inode_operations *proc_iops;
10629         /*
10630 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
10631  extern const struct proc_ns_operations utsns_operations;
10632  extern const struct proc_ns_operations ipcns_operations;
10633  
10634 +struct vx_info;
10635 +struct nx_info;
10636 +
10637  union proc_op {
10638         int (*proc_get_link)(struct inode *, struct path *);
10639         int (*proc_read)(struct task_struct *task, char *page);
10640         int (*proc_show)(struct seq_file *m,
10641                 struct pid_namespace *ns, struct pid *pid,
10642                 struct task_struct *task);
10643 +       int (*proc_vs_read)(char *page);
10644 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
10645 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
10646  };
10647  
10648  struct ctl_table_header;
10649 @@ -265,6 +272,7 @@ struct ctl_table;
10650  
10651  struct proc_inode {
10652         struct pid *pid;
10653 +       int vx_flags;
10654         int fd;
10655         union proc_op op;
10656         struct proc_dir_entry *pde;
10657 diff -NurpP --minimal linux-3.0/include/linux/quotaops.h linux-3.0-vs2.3.1-pre6/include/linux/quotaops.h
10658 --- linux-3.0/include/linux/quotaops.h  2011-05-22 16:17:57.000000000 +0200
10659 +++ linux-3.0-vs2.3.1-pre6/include/linux/quotaops.h     2011-06-10 22:11:24.000000000 +0200
10660 @@ -8,6 +8,7 @@
10661  #define _LINUX_QUOTAOPS_
10662  
10663  #include <linux/fs.h>
10664 +#include <linux/vs_dlimit.h>
10665  
10666  #define DQUOT_SPACE_WARN       0x1
10667  #define DQUOT_SPACE_RESERVE    0x2
10668 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
10669  
10670  static inline int dquot_alloc_inode(const struct inode *inode)
10671  {
10672 -       return 0;
10673 +       return dl_alloc_inode(inode);
10674  }
10675  
10676  static inline void dquot_free_inode(const struct inode *inode)
10677  {
10678 +       dl_free_inode(inode);
10679  }
10680  
10681  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
10682 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
10683  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
10684                 int flags)
10685  {
10686 +       int ret = 0;
10687 +
10688 +       if ((ret = dl_alloc_space(inode, number)))
10689 +               return ret;
10690         if (!(flags & DQUOT_SPACE_RESERVE))
10691                 inode_add_bytes(inode, number);
10692         return 0;
10693 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
10694  {
10695         if (!(flags & DQUOT_SPACE_RESERVE))
10696                 inode_sub_bytes(inode, number);
10697 +       dl_free_space(inode, number);
10698  }
10699  
10700  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
10701 diff -NurpP --minimal linux-3.0/include/linux/reboot.h linux-3.0-vs2.3.1-pre6/include/linux/reboot.h
10702 --- linux-3.0/include/linux/reboot.h    2010-07-07 18:31:56.000000000 +0200
10703 +++ linux-3.0-vs2.3.1-pre6/include/linux/reboot.h       2011-06-10 22:11:24.000000000 +0200
10704 @@ -33,6 +33,7 @@
10705  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
10706  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
10707  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
10708 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
10709  
10710  
10711  #ifdef __KERNEL__
10712 diff -NurpP --minimal linux-3.0/include/linux/reiserfs_fs.h linux-3.0-vs2.3.1-pre6/include/linux/reiserfs_fs.h
10713 --- linux-3.0/include/linux/reiserfs_fs.h       2011-05-22 16:17:58.000000000 +0200
10714 +++ linux-3.0-vs2.3.1-pre6/include/linux/reiserfs_fs.h  2011-06-10 22:11:24.000000000 +0200
10715 @@ -976,6 +976,11 @@ struct stat_data_v1 {
10716  #define REISERFS_COMPR_FL     FS_COMPR_FL
10717  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
10718  
10719 +/* unfortunately reiserfs sdattr is only 16 bit */
10720 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
10721 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
10722 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
10723 +
10724  /* persistent flags that file inherits from the parent directory */
10725  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
10726                                 REISERFS_SYNC_FL |      \
10727 @@ -985,6 +990,9 @@ struct stat_data_v1 {
10728                                 REISERFS_COMPR_FL |     \
10729                                 REISERFS_NOTAIL_FL )
10730  
10731 +#define REISERFS_FL_USER_VISIBLE       0x80FF
10732 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
10733 +
10734  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
10735     address blocks) */
10736  struct stat_data {
10737 @@ -2073,6 +2081,7 @@ static inline void reiserfs_update_sd(st
10738  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
10739  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
10740  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
10741 +int reiserfs_sync_flags(struct inode *inode, int, int);
10742  
10743  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
10744  
10745 diff -NurpP --minimal linux-3.0/include/linux/reiserfs_fs_sb.h linux-3.0-vs2.3.1-pre6/include/linux/reiserfs_fs_sb.h
10746 --- linux-3.0/include/linux/reiserfs_fs_sb.h    2010-02-25 11:52:07.000000000 +0100
10747 +++ linux-3.0-vs2.3.1-pre6/include/linux/reiserfs_fs_sb.h       2011-06-10 22:11:24.000000000 +0200
10748 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
10749         REISERFS_EXPOSE_PRIVROOT,
10750         REISERFS_BARRIER_NONE,
10751         REISERFS_BARRIER_FLUSH,
10752 +       REISERFS_TAGGED,
10753  
10754         /* Actions on error */
10755         REISERFS_ERROR_PANIC,
10756 diff -NurpP --minimal linux-3.0/include/linux/sched.h linux-3.0-vs2.3.1-pre6/include/linux/sched.h
10757 --- linux-3.0/include/linux/sched.h     2011-07-22 11:18:11.000000000 +0200
10758 +++ linux-3.0-vs2.3.1-pre6/include/linux/sched.h        2011-07-22 11:20:39.000000000 +0200
10759 @@ -1406,6 +1406,14 @@ struct task_struct {
10760  #endif
10761         seccomp_t seccomp;
10762  
10763 +/* vserver context data */
10764 +       struct vx_info *vx_info;
10765 +       struct nx_info *nx_info;
10766 +
10767 +       xid_t xid;
10768 +       nid_t nid;
10769 +       tag_t tag;
10770 +
10771  /* Thread group tracking */
10772         u32 parent_exec_id;
10773         u32 self_exec_id;
10774 @@ -1649,6 +1657,11 @@ struct pid_namespace;
10775  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
10776                         struct pid_namespace *ns);
10777  
10778 +#include <linux/vserver/base.h>
10779 +#include <linux/vserver/context.h>
10780 +#include <linux/vserver/debug.h>
10781 +#include <linux/vserver/pid.h>
10782 +
10783  static inline pid_t task_pid_nr(struct task_struct *tsk)
10784  {
10785         return tsk->pid;
10786 @@ -1662,7 +1675,8 @@ static inline pid_t task_pid_nr_ns(struc
10787  
10788  static inline pid_t task_pid_vnr(struct task_struct *tsk)
10789  {
10790 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
10791 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
10792 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
10793  }
10794  
10795  
10796 @@ -1675,7 +1689,7 @@ pid_t task_tgid_nr_ns(struct task_struct
10797  
10798  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
10799  {
10800 -       return pid_vnr(task_tgid(tsk));
10801 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
10802  }
10803  
10804  
10805 diff -NurpP --minimal linux-3.0/include/linux/shmem_fs.h linux-3.0-vs2.3.1-pre6/include/linux/shmem_fs.h
10806 --- linux-3.0/include/linux/shmem_fs.h  2011-07-22 11:18:11.000000000 +0200
10807 +++ linux-3.0-vs2.3.1-pre6/include/linux/shmem_fs.h     2011-07-01 11:35:35.000000000 +0200
10808 @@ -12,6 +12,9 @@
10809  
10810  #define SHMEM_SYMLINK_INLINE_LEN (SHMEM_NR_DIRECT * sizeof(swp_entry_t))
10811  
10812 +#define TMPFS_SUPER_MAGIC      0x01021994
10813 +
10814 +
10815  struct shmem_inode_info {
10816         spinlock_t              lock;
10817         unsigned long           flags;
10818 diff -NurpP --minimal linux-3.0/include/linux/stat.h linux-3.0-vs2.3.1-pre6/include/linux/stat.h
10819 --- linux-3.0/include/linux/stat.h      2008-12-25 00:26:37.000000000 +0100
10820 +++ linux-3.0-vs2.3.1-pre6/include/linux/stat.h 2011-06-10 22:11:24.000000000 +0200
10821 @@ -66,6 +66,7 @@ struct kstat {
10822         unsigned int    nlink;
10823         uid_t           uid;
10824         gid_t           gid;
10825 +       tag_t           tag;
10826         dev_t           rdev;
10827         loff_t          size;
10828         struct timespec  atime;
10829 diff -NurpP --minimal linux-3.0/include/linux/sunrpc/auth.h linux-3.0-vs2.3.1-pre6/include/linux/sunrpc/auth.h
10830 --- linux-3.0/include/linux/sunrpc/auth.h       2011-03-15 18:07:39.000000000 +0100
10831 +++ linux-3.0-vs2.3.1-pre6/include/linux/sunrpc/auth.h  2011-06-10 22:11:24.000000000 +0200
10832 @@ -25,6 +25,7 @@
10833  struct auth_cred {
10834         uid_t   uid;
10835         gid_t   gid;
10836 +       tag_t   tag;
10837         struct group_info *group_info;
10838         unsigned char machine_cred : 1;
10839  };
10840 diff -NurpP --minimal linux-3.0/include/linux/sunrpc/clnt.h linux-3.0-vs2.3.1-pre6/include/linux/sunrpc/clnt.h
10841 --- linux-3.0/include/linux/sunrpc/clnt.h       2011-05-22 16:17:58.000000000 +0200
10842 +++ linux-3.0-vs2.3.1-pre6/include/linux/sunrpc/clnt.h  2011-06-10 22:11:24.000000000 +0200
10843 @@ -49,7 +49,8 @@ struct rpc_clnt {
10844         unsigned int            cl_softrtry : 1,/* soft timeouts */
10845                                 cl_discrtry : 1,/* disconnect before retry */
10846                                 cl_autobind : 1,/* use getport() */
10847 -                               cl_chatty   : 1;/* be verbose */
10848 +                               cl_chatty   : 1,/* be verbose */
10849 +                               cl_tag      : 1;/* context tagging */
10850  
10851         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
10852         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
10853 diff -NurpP --minimal linux-3.0/include/linux/syscalls.h linux-3.0-vs2.3.1-pre6/include/linux/syscalls.h
10854 --- linux-3.0/include/linux/syscalls.h  2011-07-22 11:18:11.000000000 +0200
10855 +++ linux-3.0-vs2.3.1-pre6/include/linux/syscalls.h     2011-06-10 22:11:24.000000000 +0200
10856 @@ -483,6 +483,8 @@ asmlinkage long sys_symlink(const char _
10857  asmlinkage long sys_unlink(const char __user *pathname);
10858  asmlinkage long sys_rename(const char __user *oldname,
10859                                 const char __user *newname);
10860 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
10861 +                               umode_t mode);
10862  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
10863  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
10864  
10865 diff -NurpP --minimal linux-3.0/include/linux/sysctl.h linux-3.0-vs2.3.1-pre6/include/linux/sysctl.h
10866 --- linux-3.0/include/linux/sysctl.h    2011-03-15 18:07:40.000000000 +0100
10867 +++ linux-3.0-vs2.3.1-pre6/include/linux/sysctl.h       2011-06-10 22:11:24.000000000 +0200
10868 @@ -60,6 +60,7 @@ enum
10869         CTL_ABI=9,              /* Binary emulation */
10870         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
10871         CTL_ARLAN=254,          /* arlan wireless driver */
10872 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
10873         CTL_S390DBF=5677,       /* s390 debug */
10874         CTL_SUNRPC=7249,        /* sunrpc debug */
10875         CTL_PM=9899,            /* frv power management */
10876 @@ -94,6 +95,7 @@ enum
10877  
10878         KERN_PANIC=15,          /* int: panic timeout */
10879         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
10880 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
10881  
10882         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
10883         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
10884 diff -NurpP --minimal linux-3.0/include/linux/sysfs.h linux-3.0-vs2.3.1-pre6/include/linux/sysfs.h
10885 --- linux-3.0/include/linux/sysfs.h     2011-07-22 11:18:11.000000000 +0200
10886 +++ linux-3.0-vs2.3.1-pre6/include/linux/sysfs.h        2011-06-22 12:39:15.000000000 +0200
10887 @@ -19,6 +19,8 @@
10888  #include <linux/kobject_ns.h>
10889  #include <asm/atomic.h>
10890  
10891 +#define SYSFS_SUPER_MAGIC      0x62656572
10892 +
10893  struct kobject;
10894  struct module;
10895  enum kobj_ns_type;
10896 diff -NurpP --minimal linux-3.0/include/linux/time.h linux-3.0-vs2.3.1-pre6/include/linux/time.h
10897 --- linux-3.0/include/linux/time.h      2011-07-22 11:18:11.000000000 +0200
10898 +++ linux-3.0-vs2.3.1-pre6/include/linux/time.h 2011-06-10 22:11:24.000000000 +0200
10899 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
10900         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
10901         a->tv_nsec = ns;
10902  }
10903 +
10904 +#include <linux/vs_time.h>
10905 +
10906  #endif /* __KERNEL__ */
10907  
10908  #define NFDBITS                        __NFDBITS
10909 diff -NurpP --minimal linux-3.0/include/linux/types.h linux-3.0-vs2.3.1-pre6/include/linux/types.h
10910 --- linux-3.0/include/linux/types.h     2011-05-22 16:17:58.000000000 +0200
10911 +++ linux-3.0-vs2.3.1-pre6/include/linux/types.h        2011-06-10 22:11:24.000000000 +0200
10912 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
10913  typedef __kernel_gid32_t       gid_t;
10914  typedef __kernel_uid16_t        uid16_t;
10915  typedef __kernel_gid16_t        gid16_t;
10916 +typedef unsigned int           xid_t;
10917 +typedef unsigned int           nid_t;
10918 +typedef unsigned int           tag_t;
10919  
10920  typedef unsigned long          uintptr_t;
10921  
10922 diff -NurpP --minimal linux-3.0/include/linux/utsname.h linux-3.0-vs2.3.1-pre6/include/linux/utsname.h
10923 --- linux-3.0/include/linux/utsname.h   2011-05-22 16:17:58.000000000 +0200
10924 +++ linux-3.0-vs2.3.1-pre6/include/linux/utsname.h      2011-06-13 14:36:48.000000000 +0200
10925 @@ -54,7 +54,8 @@ static inline void get_uts_ns(struct uts
10926  }
10927  
10928  extern struct uts_namespace *copy_utsname(unsigned long flags,
10929 -                                         struct task_struct *tsk);
10930 +                                         struct uts_namespace *old_ns,
10931 +                                         struct user_namespace *user_ns);
10932  extern void free_uts_ns(struct kref *kref);
10933  
10934  static inline void put_uts_ns(struct uts_namespace *ns)
10935 @@ -71,12 +72,13 @@ static inline void put_uts_ns(struct uts
10936  }
10937  
10938  static inline struct uts_namespace *copy_utsname(unsigned long flags,
10939 -                                                struct task_struct *tsk)
10940 +                                                struct uts_namespace *old_ns,
10941 +                                                struct user_namespace *user_ns)
10942  {
10943         if (flags & CLONE_NEWUTS)
10944                 return ERR_PTR(-EINVAL);
10945  
10946 -       return tsk->nsproxy->uts_ns;
10947 +       return old_ns;
10948  }
10949  #endif
10950  
10951 diff -NurpP --minimal linux-3.0/include/linux/vroot.h linux-3.0-vs2.3.1-pre6/include/linux/vroot.h
10952 --- linux-3.0/include/linux/vroot.h     1970-01-01 01:00:00.000000000 +0100
10953 +++ linux-3.0-vs2.3.1-pre6/include/linux/vroot.h        2011-06-10 22:11:24.000000000 +0200
10954 @@ -0,0 +1,51 @@
10955 +
10956 +/*
10957 + * include/linux/vroot.h
10958 + *
10959 + * written by Herbert Pötzl, 9/11/2002
10960 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
10961 + *
10962 + * Copyright (C) 2002-2007 by Herbert Pötzl.
10963 + * Redistribution of this file is permitted under the
10964 + * GNU General Public License.
10965 + */
10966 +
10967 +#ifndef _LINUX_VROOT_H
10968 +#define _LINUX_VROOT_H
10969 +
10970 +
10971 +#ifdef __KERNEL__
10972 +
10973 +/* Possible states of device */
10974 +enum {
10975 +       Vr_unbound,
10976 +       Vr_bound,
10977 +};
10978 +
10979 +struct vroot_device {
10980 +       int             vr_number;
10981 +       int             vr_refcnt;
10982 +
10983 +       struct semaphore        vr_ctl_mutex;
10984 +       struct block_device    *vr_device;
10985 +       int                     vr_state;
10986 +};
10987 +
10988 +
10989 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
10990 +
10991 +extern int register_vroot_grb(vroot_grb_func *);
10992 +extern int unregister_vroot_grb(vroot_grb_func *);
10993 +
10994 +#endif /* __KERNEL__ */
10995 +
10996 +#define MAX_VROOT_DEFAULT      8
10997 +
10998 +/*
10999 + * IOCTL commands --- we will commandeer 0x56 ('V')
11000 + */
11001 +
11002 +#define VROOT_SET_DEV          0x5600
11003 +#define VROOT_CLR_DEV          0x5601
11004 +
11005 +#endif /* _LINUX_VROOT_H */
11006 diff -NurpP --minimal linux-3.0/include/linux/vs_base.h linux-3.0-vs2.3.1-pre6/include/linux/vs_base.h
11007 --- linux-3.0/include/linux/vs_base.h   1970-01-01 01:00:00.000000000 +0100
11008 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_base.h      2011-06-10 22:11:24.000000000 +0200
11009 @@ -0,0 +1,10 @@
11010 +#ifndef _VS_BASE_H
11011 +#define _VS_BASE_H
11012 +
11013 +#include "vserver/base.h"
11014 +#include "vserver/check.h"
11015 +#include "vserver/debug.h"
11016 +
11017 +#else
11018 +#warning duplicate inclusion
11019 +#endif
11020 diff -NurpP --minimal linux-3.0/include/linux/vs_context.h linux-3.0-vs2.3.1-pre6/include/linux/vs_context.h
11021 --- linux-3.0/include/linux/vs_context.h        1970-01-01 01:00:00.000000000 +0100
11022 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_context.h   2011-06-10 22:11:24.000000000 +0200
11023 @@ -0,0 +1,242 @@
11024 +#ifndef _VS_CONTEXT_H
11025 +#define _VS_CONTEXT_H
11026 +
11027 +#include "vserver/base.h"
11028 +#include "vserver/check.h"
11029 +#include "vserver/context.h"
11030 +#include "vserver/history.h"
11031 +#include "vserver/debug.h"
11032 +
11033 +#include <linux/sched.h>
11034 +
11035 +
11036 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
11037 +
11038 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
11039 +       const char *_file, int _line, void *_here)
11040 +{
11041 +       if (!vxi)
11042 +               return NULL;
11043 +
11044 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
11045 +               vxi, vxi ? vxi->vx_id : 0,
11046 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11047 +               _file, _line);
11048 +       __vxh_get_vx_info(vxi, _here);
11049 +
11050 +       atomic_inc(&vxi->vx_usecnt);
11051 +       return vxi;
11052 +}
11053 +
11054 +
11055 +extern void free_vx_info(struct vx_info *);
11056 +
11057 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
11058 +
11059 +static inline void __put_vx_info(struct vx_info *vxi,
11060 +       const char *_file, int _line, void *_here)
11061 +{
11062 +       if (!vxi)
11063 +               return;
11064 +
11065 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
11066 +               vxi, vxi ? vxi->vx_id : 0,
11067 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11068 +               _file, _line);
11069 +       __vxh_put_vx_info(vxi, _here);
11070 +
11071 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
11072 +               free_vx_info(vxi);
11073 +}
11074 +
11075 +
11076 +#define init_vx_info(p, i) \
11077 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
11078 +
11079 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
11080 +       const char *_file, int _line, void *_here)
11081 +{
11082 +       if (vxi) {
11083 +               vxlprintk(VXD_CBIT(xid, 3),
11084 +                       "init_vx_info(%p[#%d.%d])",
11085 +                       vxi, vxi ? vxi->vx_id : 0,
11086 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11087 +                       _file, _line);
11088 +               __vxh_init_vx_info(vxi, vxp, _here);
11089 +
11090 +               atomic_inc(&vxi->vx_usecnt);
11091 +       }
11092 +       *vxp = vxi;
11093 +}
11094 +
11095 +
11096 +#define set_vx_info(p, i) \
11097 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
11098 +
11099 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
11100 +       const char *_file, int _line, void *_here)
11101 +{
11102 +       struct vx_info *vxo;
11103 +
11104 +       if (!vxi)
11105 +               return;
11106 +
11107 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
11108 +               vxi, vxi ? vxi->vx_id : 0,
11109 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11110 +               _file, _line);
11111 +       __vxh_set_vx_info(vxi, vxp, _here);
11112 +
11113 +       atomic_inc(&vxi->vx_usecnt);
11114 +       vxo = xchg(vxp, vxi);
11115 +       BUG_ON(vxo);
11116 +}
11117 +
11118 +
11119 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
11120 +
11121 +static inline void __clr_vx_info(struct vx_info **vxp,
11122 +       const char *_file, int _line, void *_here)
11123 +{
11124 +       struct vx_info *vxo;
11125 +
11126 +       vxo = xchg(vxp, NULL);
11127 +       if (!vxo)
11128 +               return;
11129 +
11130 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
11131 +               vxo, vxo ? vxo->vx_id : 0,
11132 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
11133 +               _file, _line);
11134 +       __vxh_clr_vx_info(vxo, vxp, _here);
11135 +
11136 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
11137 +               free_vx_info(vxo);
11138 +}
11139 +
11140 +
11141 +#define claim_vx_info(v, p) \
11142 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
11143 +
11144 +static inline void __claim_vx_info(struct vx_info *vxi,
11145 +       struct task_struct *task,
11146 +       const char *_file, int _line, void *_here)
11147 +{
11148 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
11149 +               vxi, vxi ? vxi->vx_id : 0,
11150 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11151 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
11152 +               task, _file, _line);
11153 +       __vxh_claim_vx_info(vxi, task, _here);
11154 +
11155 +       atomic_inc(&vxi->vx_tasks);
11156 +}
11157 +
11158 +
11159 +extern void unhash_vx_info(struct vx_info *);
11160 +
11161 +#define release_vx_info(v, p) \
11162 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
11163 +
11164 +static inline void __release_vx_info(struct vx_info *vxi,
11165 +       struct task_struct *task,
11166 +       const char *_file, int _line, void *_here)
11167 +{
11168 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
11169 +               vxi, vxi ? vxi->vx_id : 0,
11170 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11171 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
11172 +               task, _file, _line);
11173 +       __vxh_release_vx_info(vxi, task, _here);
11174 +
11175 +       might_sleep();
11176 +
11177 +       if (atomic_dec_and_test(&vxi->vx_tasks))
11178 +               unhash_vx_info(vxi);
11179 +}
11180 +
11181 +
11182 +#define task_get_vx_info(p) \
11183 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
11184 +
11185 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
11186 +       const char *_file, int _line, void *_here)
11187 +{
11188 +       struct vx_info *vxi;
11189 +
11190 +       task_lock(p);
11191 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
11192 +               p, _file, _line);
11193 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
11194 +       task_unlock(p);
11195 +       return vxi;
11196 +}
11197 +
11198 +
11199 +static inline void __wakeup_vx_info(struct vx_info *vxi)
11200 +{
11201 +       if (waitqueue_active(&vxi->vx_wait))
11202 +               wake_up_interruptible(&vxi->vx_wait);
11203 +}
11204 +
11205 +
11206 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
11207 +
11208 +static inline void __enter_vx_info(struct vx_info *vxi,
11209 +       struct vx_info_save *vxis, const char *_file, int _line)
11210 +{
11211 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
11212 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
11213 +               current->xid, current->vx_info, _file, _line);
11214 +       vxis->vxi = xchg(&current->vx_info, vxi);
11215 +       vxis->xid = current->xid;
11216 +       current->xid = vxi ? vxi->vx_id : 0;
11217 +}
11218 +
11219 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
11220 +
11221 +static inline void __leave_vx_info(struct vx_info_save *vxis,
11222 +       const char *_file, int _line)
11223 +{
11224 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
11225 +               vxis, vxis->xid, vxis->vxi, current,
11226 +               current->xid, current->vx_info, _file, _line);
11227 +       (void)xchg(&current->vx_info, vxis->vxi);
11228 +       current->xid = vxis->xid;
11229 +}
11230 +
11231 +
11232 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
11233 +{
11234 +       vxis->vxi = xchg(&current->vx_info, NULL);
11235 +       vxis->xid = xchg(&current->xid, (xid_t)0);
11236 +}
11237 +
11238 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
11239 +{
11240 +       (void)xchg(&current->xid, vxis->xid);
11241 +       (void)xchg(&current->vx_info, vxis->vxi);
11242 +}
11243 +
11244 +#define task_is_init(p) \
11245 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
11246 +
11247 +static inline int __task_is_init(struct task_struct *p,
11248 +       const char *_file, int _line, void *_here)
11249 +{
11250 +       int is_init = is_global_init(p);
11251 +
11252 +       task_lock(p);
11253 +       if (p->vx_info)
11254 +               is_init = p->vx_info->vx_initpid == p->pid;
11255 +       task_unlock(p);
11256 +       return is_init;
11257 +}
11258 +
11259 +extern void exit_vx_info(struct task_struct *, int);
11260 +extern void exit_vx_info_early(struct task_struct *, int);
11261 +
11262 +
11263 +#else
11264 +#warning duplicate inclusion
11265 +#endif
11266 diff -NurpP --minimal linux-3.0/include/linux/vs_cowbl.h linux-3.0-vs2.3.1-pre6/include/linux/vs_cowbl.h
11267 --- linux-3.0/include/linux/vs_cowbl.h  1970-01-01 01:00:00.000000000 +0100
11268 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_cowbl.h     2011-06-10 22:11:24.000000000 +0200
11269 @@ -0,0 +1,48 @@
11270 +#ifndef _VS_COWBL_H
11271 +#define _VS_COWBL_H
11272 +
11273 +#include <linux/fs.h>
11274 +#include <linux/dcache.h>
11275 +#include <linux/namei.h>
11276 +#include <linux/slab.h>
11277 +
11278 +extern struct dentry *cow_break_link(const char *pathname);
11279 +
11280 +static inline int cow_check_and_break(struct path *path)
11281 +{
11282 +       struct inode *inode = path->dentry->d_inode;
11283 +       int error = 0;
11284 +
11285 +       /* do we need this check? */
11286 +       if (IS_RDONLY(inode))
11287 +               return -EROFS;
11288 +
11289 +       if (IS_COW(inode)) {
11290 +               if (IS_COW_LINK(inode)) {
11291 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
11292 +                       char *pp, *buf;
11293 +
11294 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
11295 +                       if (!buf) {
11296 +                               return -ENOMEM;
11297 +                       }
11298 +                       pp = d_path(path, buf, PATH_MAX);
11299 +                       new_dentry = cow_break_link(pp);
11300 +                       kfree(buf);
11301 +                       if (!IS_ERR(new_dentry)) {
11302 +                               path->dentry = new_dentry;
11303 +                               dput(old_dentry);
11304 +                       } else
11305 +                               error = PTR_ERR(new_dentry);
11306 +               } else {
11307 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
11308 +                       inode->i_ctime = CURRENT_TIME;
11309 +                       mark_inode_dirty(inode);
11310 +               }
11311 +       }
11312 +       return error;
11313 +}
11314 +
11315 +#else
11316 +#warning duplicate inclusion
11317 +#endif
11318 diff -NurpP --minimal linux-3.0/include/linux/vs_cvirt.h linux-3.0-vs2.3.1-pre6/include/linux/vs_cvirt.h
11319 --- linux-3.0/include/linux/vs_cvirt.h  1970-01-01 01:00:00.000000000 +0100
11320 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_cvirt.h     2011-06-10 22:11:24.000000000 +0200
11321 @@ -0,0 +1,50 @@
11322 +#ifndef _VS_CVIRT_H
11323 +#define _VS_CVIRT_H
11324 +
11325 +#include "vserver/cvirt.h"
11326 +#include "vserver/context.h"
11327 +#include "vserver/base.h"
11328 +#include "vserver/check.h"
11329 +#include "vserver/debug.h"
11330 +
11331 +
11332 +static inline void vx_activate_task(struct task_struct *p)
11333 +{
11334 +       struct vx_info *vxi;
11335 +
11336 +       if ((vxi = p->vx_info)) {
11337 +               vx_update_load(vxi);
11338 +               atomic_inc(&vxi->cvirt.nr_running);
11339 +       }
11340 +}
11341 +
11342 +static inline void vx_deactivate_task(struct task_struct *p)
11343 +{
11344 +       struct vx_info *vxi;
11345 +
11346 +       if ((vxi = p->vx_info)) {
11347 +               vx_update_load(vxi);
11348 +               atomic_dec(&vxi->cvirt.nr_running);
11349 +       }
11350 +}
11351 +
11352 +static inline void vx_uninterruptible_inc(struct task_struct *p)
11353 +{
11354 +       struct vx_info *vxi;
11355 +
11356 +       if ((vxi = p->vx_info))
11357 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
11358 +}
11359 +
11360 +static inline void vx_uninterruptible_dec(struct task_struct *p)
11361 +{
11362 +       struct vx_info *vxi;
11363 +
11364 +       if ((vxi = p->vx_info))
11365 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
11366 +}
11367 +
11368 +
11369 +#else
11370 +#warning duplicate inclusion
11371 +#endif
11372 diff -NurpP --minimal linux-3.0/include/linux/vs_device.h linux-3.0-vs2.3.1-pre6/include/linux/vs_device.h
11373 --- linux-3.0/include/linux/vs_device.h 1970-01-01 01:00:00.000000000 +0100
11374 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_device.h    2011-06-10 22:11:24.000000000 +0200
11375 @@ -0,0 +1,45 @@
11376 +#ifndef _VS_DEVICE_H
11377 +#define _VS_DEVICE_H
11378 +
11379 +#include "vserver/base.h"
11380 +#include "vserver/device.h"
11381 +#include "vserver/debug.h"
11382 +
11383 +
11384 +#ifdef CONFIG_VSERVER_DEVICE
11385 +
11386 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
11387 +
11388 +#define vs_device_perm(v, d, m, p) \
11389 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
11390 +
11391 +#else
11392 +
11393 +static inline
11394 +int vs_map_device(struct vx_info *vxi,
11395 +       dev_t device, dev_t *target, umode_t mode)
11396 +{
11397 +       if (target)
11398 +               *target = device;
11399 +       return ~0;
11400 +}
11401 +
11402 +#define vs_device_perm(v, d, m, p) ((p) == (p))
11403 +
11404 +#endif
11405 +
11406 +
11407 +#define vs_map_chrdev(d, t, p) \
11408 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
11409 +#define vs_map_blkdev(d, t, p) \
11410 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
11411 +
11412 +#define vs_chrdev_perm(d, p) \
11413 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
11414 +#define vs_blkdev_perm(d, p) \
11415 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
11416 +
11417 +
11418 +#else
11419 +#warning duplicate inclusion
11420 +#endif
11421 diff -NurpP --minimal linux-3.0/include/linux/vs_dlimit.h linux-3.0-vs2.3.1-pre6/include/linux/vs_dlimit.h
11422 --- linux-3.0/include/linux/vs_dlimit.h 1970-01-01 01:00:00.000000000 +0100
11423 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_dlimit.h    2011-06-10 22:11:24.000000000 +0200
11424 @@ -0,0 +1,215 @@
11425 +#ifndef _VS_DLIMIT_H
11426 +#define _VS_DLIMIT_H
11427 +
11428 +#include <linux/fs.h>
11429 +
11430 +#include "vserver/dlimit.h"
11431 +#include "vserver/base.h"
11432 +#include "vserver/debug.h"
11433 +
11434 +
11435 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
11436 +
11437 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
11438 +       const char *_file, int _line)
11439 +{
11440 +       if (!dli)
11441 +               return NULL;
11442 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
11443 +               dli, dli ? dli->dl_tag : 0,
11444 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11445 +               _file, _line);
11446 +       atomic_inc(&dli->dl_usecnt);
11447 +       return dli;
11448 +}
11449 +
11450 +
11451 +#define free_dl_info(i) \
11452 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
11453 +
11454 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
11455 +
11456 +static inline void __put_dl_info(struct dl_info *dli,
11457 +       const char *_file, int _line)
11458 +{
11459 +       if (!dli)
11460 +               return;
11461 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
11462 +               dli, dli ? dli->dl_tag : 0,
11463 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11464 +               _file, _line);
11465 +       if (atomic_dec_and_test(&dli->dl_usecnt))
11466 +               free_dl_info(dli);
11467 +}
11468 +
11469 +
11470 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
11471 +
11472 +static inline int __dl_alloc_space(struct super_block *sb,
11473 +       tag_t tag, dlsize_t nr, const char *file, int line)
11474 +{
11475 +       struct dl_info *dli = NULL;
11476 +       int ret = 0;
11477 +
11478 +       if (nr == 0)
11479 +               goto out;
11480 +       dli = locate_dl_info(sb, tag);
11481 +       if (!dli)
11482 +               goto out;
11483 +
11484 +       spin_lock(&dli->dl_lock);
11485 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
11486 +       if (!ret)
11487 +               dli->dl_space_used += nr;
11488 +       spin_unlock(&dli->dl_lock);
11489 +       put_dl_info(dli);
11490 +out:
11491 +       vxlprintk(VXD_CBIT(dlim, 1),
11492 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
11493 +               sb, tag, __dlimit_char(dli), (long long)nr,
11494 +               ret, file, line);
11495 +       return ret ? -ENOSPC : 0;
11496 +}
11497 +
11498 +static inline void __dl_free_space(struct super_block *sb,
11499 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
11500 +{
11501 +       struct dl_info *dli = NULL;
11502 +
11503 +       if (nr == 0)
11504 +               goto out;
11505 +       dli = locate_dl_info(sb, tag);
11506 +       if (!dli)
11507 +               goto out;
11508 +
11509 +       spin_lock(&dli->dl_lock);
11510 +       if (dli->dl_space_used > nr)
11511 +               dli->dl_space_used -= nr;
11512 +       else
11513 +               dli->dl_space_used = 0;
11514 +       spin_unlock(&dli->dl_lock);
11515 +       put_dl_info(dli);
11516 +out:
11517 +       vxlprintk(VXD_CBIT(dlim, 1),
11518 +               "FREE  (%p,#%d)%c %lld bytes",
11519 +               sb, tag, __dlimit_char(dli), (long long)nr,
11520 +               _file, _line);
11521 +}
11522 +
11523 +static inline int __dl_alloc_inode(struct super_block *sb,
11524 +       tag_t tag, const char *_file, int _line)
11525 +{
11526 +       struct dl_info *dli;
11527 +       int ret = 0;
11528 +
11529 +       dli = locate_dl_info(sb, tag);
11530 +       if (!dli)
11531 +               goto out;
11532 +
11533 +       spin_lock(&dli->dl_lock);
11534 +       dli->dl_inodes_used++;
11535 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
11536 +       spin_unlock(&dli->dl_lock);
11537 +       put_dl_info(dli);
11538 +out:
11539 +       vxlprintk(VXD_CBIT(dlim, 0),
11540 +               "ALLOC (%p,#%d)%c inode (%d)",
11541 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
11542 +       return ret ? -ENOSPC : 0;
11543 +}
11544 +
11545 +static inline void __dl_free_inode(struct super_block *sb,
11546 +       tag_t tag, const char *_file, int _line)
11547 +{
11548 +       struct dl_info *dli;
11549 +
11550 +       dli = locate_dl_info(sb, tag);
11551 +       if (!dli)
11552 +               goto out;
11553 +
11554 +       spin_lock(&dli->dl_lock);
11555 +       if (dli->dl_inodes_used > 1)
11556 +               dli->dl_inodes_used--;
11557 +       else
11558 +               dli->dl_inodes_used = 0;
11559 +       spin_unlock(&dli->dl_lock);
11560 +       put_dl_info(dli);
11561 +out:
11562 +       vxlprintk(VXD_CBIT(dlim, 0),
11563 +               "FREE  (%p,#%d)%c inode",
11564 +               sb, tag, __dlimit_char(dli), _file, _line);
11565 +}
11566 +
11567 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
11568 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
11569 +       const char *_file, int _line)
11570 +{
11571 +       struct dl_info *dli;
11572 +       uint64_t broot, bfree;
11573 +
11574 +       dli = locate_dl_info(sb, tag);
11575 +       if (!dli)
11576 +               return;
11577 +
11578 +       spin_lock(&dli->dl_lock);
11579 +       broot = (dli->dl_space_total -
11580 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
11581 +               >> sb->s_blocksize_bits;
11582 +       bfree = (dli->dl_space_total - dli->dl_space_used)
11583 +                       >> sb->s_blocksize_bits;
11584 +       spin_unlock(&dli->dl_lock);
11585 +
11586 +       vxlprintk(VXD_CBIT(dlim, 2),
11587 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
11588 +               (long long)bfree, (long long)broot,
11589 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
11590 +               _file, _line);
11591 +       if (free_blocks) {
11592 +               if (*free_blocks > bfree)
11593 +                       *free_blocks = bfree;
11594 +       }
11595 +       if (root_blocks) {
11596 +               if (*root_blocks > broot)
11597 +                       *root_blocks = broot;
11598 +       }
11599 +       put_dl_info(dli);
11600 +}
11601 +
11602 +#define dl_prealloc_space(in, bytes) \
11603 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11604 +               __FILE__, __LINE__ )
11605 +
11606 +#define dl_alloc_space(in, bytes) \
11607 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11608 +               __FILE__, __LINE__ )
11609 +
11610 +#define dl_reserve_space(in, bytes) \
11611 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11612 +               __FILE__, __LINE__ )
11613 +
11614 +#define dl_claim_space(in, bytes) (0)
11615 +
11616 +#define dl_release_space(in, bytes) \
11617 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11618 +               __FILE__, __LINE__ )
11619 +
11620 +#define dl_free_space(in, bytes) \
11621 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11622 +               __FILE__, __LINE__ )
11623 +
11624 +
11625 +
11626 +#define dl_alloc_inode(in) \
11627 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11628 +
11629 +#define dl_free_inode(in) \
11630 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11631 +
11632 +
11633 +#define dl_adjust_block(sb, tag, fb, rb) \
11634 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
11635 +
11636 +
11637 +#else
11638 +#warning duplicate inclusion
11639 +#endif
11640 diff -NurpP --minimal linux-3.0/include/linux/vs_inet.h linux-3.0-vs2.3.1-pre6/include/linux/vs_inet.h
11641 --- linux-3.0/include/linux/vs_inet.h   1970-01-01 01:00:00.000000000 +0100
11642 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_inet.h      2011-06-10 22:11:24.000000000 +0200
11643 @@ -0,0 +1,351 @@
11644 +#ifndef _VS_INET_H
11645 +#define _VS_INET_H
11646 +
11647 +#include "vserver/base.h"
11648 +#include "vserver/network.h"
11649 +#include "vserver/debug.h"
11650 +
11651 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
11652 +
11653 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
11654 +                       NIPQUAD((a)->mask), (a)->type
11655 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
11656 +
11657 +#define NIPQUAD(addr) \
11658 +       ((unsigned char *)&addr)[0], \
11659 +       ((unsigned char *)&addr)[1], \
11660 +       ((unsigned char *)&addr)[2], \
11661 +       ((unsigned char *)&addr)[3]
11662 +
11663 +#define NIPQUAD_FMT "%u.%u.%u.%u"
11664 +
11665 +
11666 +static inline
11667 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
11668 +{
11669 +       __be32 ip = nxa->ip[0].s_addr;
11670 +       __be32 mask = nxa->mask.s_addr;
11671 +       __be32 bcast = ip | ~mask;
11672 +       int ret = 0;
11673 +
11674 +       switch (nxa->type & tmask) {
11675 +       case NXA_TYPE_MASK:
11676 +               ret = (ip == (addr & mask));
11677 +               break;
11678 +       case NXA_TYPE_ADDR:
11679 +               ret = 3;
11680 +               if (addr == ip)
11681 +                       break;
11682 +               /* fall through to broadcast */
11683 +       case NXA_MOD_BCAST:
11684 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
11685 +               break;
11686 +       case NXA_TYPE_RANGE:
11687 +               ret = ((nxa->ip[0].s_addr <= addr) &&
11688 +                       (nxa->ip[1].s_addr > addr));
11689 +               break;
11690 +       case NXA_TYPE_ANY:
11691 +               ret = 2;
11692 +               break;
11693 +       }
11694 +
11695 +       vxdprintk(VXD_CBIT(net, 0),
11696 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
11697 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
11698 +       return ret;
11699 +}
11700 +
11701 +static inline
11702 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
11703 +{
11704 +       struct nx_addr_v4 *nxa;
11705 +       int ret = 1;
11706 +
11707 +       if (!nxi)
11708 +               goto out;
11709 +
11710 +       ret = 2;
11711 +       /* allow 127.0.0.1 when remapping lback */
11712 +       if ((tmask & NXA_LOOPBACK) &&
11713 +               (addr == IPI_LOOPBACK) &&
11714 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
11715 +               goto out;
11716 +       ret = 3;
11717 +       /* check for lback address */
11718 +       if ((tmask & NXA_MOD_LBACK) &&
11719 +               (nxi->v4_lback.s_addr == addr))
11720 +               goto out;
11721 +       ret = 4;
11722 +       /* check for broadcast address */
11723 +       if ((tmask & NXA_MOD_BCAST) &&
11724 +               (nxi->v4_bcast.s_addr == addr))
11725 +               goto out;
11726 +       ret = 5;
11727 +       /* check for v4 addresses */
11728 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
11729 +               if (v4_addr_match(nxa, addr, tmask))
11730 +                       goto out;
11731 +       ret = 0;
11732 +out:
11733 +       vxdprintk(VXD_CBIT(net, 0),
11734 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
11735 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
11736 +       return ret;
11737 +}
11738 +
11739 +static inline
11740 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
11741 +{
11742 +       /* FIXME: needs full range checks */
11743 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
11744 +}
11745 +
11746 +static inline
11747 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
11748 +{
11749 +       struct nx_addr_v4 *ptr;
11750 +
11751 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
11752 +               if (v4_nx_addr_match(ptr, nxa, mask))
11753 +                       return 1;
11754 +       return 0;
11755 +}
11756 +
11757 +#include <net/inet_sock.h>
11758 +
11759 +/*
11760 + *     Check if a given address matches for a socket
11761 + *
11762 + *     nxi:            the socket's nx_info if any
11763 + *     addr:           to be verified address
11764 + */
11765 +static inline
11766 +int v4_sock_addr_match (
11767 +       struct nx_info *nxi,
11768 +       struct inet_sock *inet,
11769 +       __be32 addr)
11770 +{
11771 +       __be32 saddr = inet->inet_rcv_saddr;
11772 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
11773 +
11774 +       if (addr && (saddr == addr || bcast == addr))
11775 +               return 1;
11776 +       if (!saddr)
11777 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
11778 +       return 0;
11779 +}
11780 +
11781 +
11782 +/* inet related checks and helpers */
11783 +
11784 +
11785 +struct in_ifaddr;
11786 +struct net_device;
11787 +struct sock;
11788 +
11789 +#ifdef CONFIG_INET
11790 +
11791 +#include <linux/netdevice.h>
11792 +#include <linux/inetdevice.h>
11793 +#include <net/inet_sock.h>
11794 +#include <net/inet_timewait_sock.h>
11795 +
11796 +
11797 +int dev_in_nx_info(struct net_device *, struct nx_info *);
11798 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
11799 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
11800 +
11801 +
11802 +/*
11803 + *     check if address is covered by socket
11804 + *
11805 + *     sk:     the socket to check against
11806 + *     addr:   the address in question (must be != 0)
11807 + */
11808 +
11809 +static inline
11810 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
11811 +{
11812 +       struct nx_info *nxi = sk->sk_nx_info;
11813 +       __be32 saddr = sk_rcv_saddr(sk);
11814 +
11815 +       vxdprintk(VXD_CBIT(net, 5),
11816 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
11817 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
11818 +               (sk->sk_socket?sk->sk_socket->flags:0));
11819 +
11820 +       if (saddr) {            /* direct address match */
11821 +               return v4_addr_match(nxa, saddr, -1);
11822 +       } else if (nxi) {       /* match against nx_info */
11823 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
11824 +       } else {                /* unrestricted any socket */
11825 +               return 1;
11826 +       }
11827 +}
11828 +
11829 +
11830 +
11831 +static inline
11832 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
11833 +{
11834 +       vxdprintk(VXD_CBIT(net, 1),
11835 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
11836 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
11837 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
11838 +
11839 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
11840 +               return 1;
11841 +       if (dev_in_nx_info(dev, nxi))
11842 +               return 1;
11843 +       return 0;
11844 +}
11845 +
11846 +
11847 +static inline
11848 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
11849 +{
11850 +       if (!nxi)
11851 +               return 1;
11852 +       if (!ifa)
11853 +               return 0;
11854 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
11855 +}
11856 +
11857 +static inline
11858 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
11859 +{
11860 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
11861 +               nxi, nxi ? nxi->nx_id : 0, ifa,
11862 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
11863 +
11864 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
11865 +               return 1;
11866 +       if (v4_ifa_in_nx_info(ifa, nxi))
11867 +               return 1;
11868 +       return 0;
11869 +}
11870 +
11871 +
11872 +struct nx_v4_sock_addr {
11873 +       __be32 saddr;   /* Address used for validation */
11874 +       __be32 baddr;   /* Address used for socket bind */
11875 +};
11876 +
11877 +static inline
11878 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
11879 +       struct nx_v4_sock_addr *nsa)
11880 +{
11881 +       struct sock *sk = &inet->sk;
11882 +       struct nx_info *nxi = sk->sk_nx_info;
11883 +       __be32 saddr = addr->sin_addr.s_addr;
11884 +       __be32 baddr = saddr;
11885 +
11886 +       vxdprintk(VXD_CBIT(net, 3),
11887 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
11888 +               sk, sk->sk_nx_info, sk->sk_socket,
11889 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
11890 +               NIPQUAD(saddr));
11891 +
11892 +       if (nxi) {
11893 +               if (saddr == INADDR_ANY) {
11894 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
11895 +                               baddr = nxi->v4.ip[0].s_addr;
11896 +               } else if (saddr == IPI_LOOPBACK) {
11897 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
11898 +                               baddr = nxi->v4_lback.s_addr;
11899 +               } else {        /* normal address bind */
11900 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
11901 +                               return -EADDRNOTAVAIL;
11902 +               }
11903 +       }
11904 +
11905 +       vxdprintk(VXD_CBIT(net, 3),
11906 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
11907 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
11908 +
11909 +       nsa->saddr = saddr;
11910 +       nsa->baddr = baddr;
11911 +       return 0;
11912 +}
11913 +
11914 +static inline
11915 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
11916 +{
11917 +       inet->inet_saddr = nsa->baddr;
11918 +       inet->inet_rcv_saddr = nsa->baddr;
11919 +}
11920 +
11921 +
11922 +/*
11923 + *      helper to simplify inet_lookup_listener
11924 + *
11925 + *      nxi:   the socket's nx_info if any
11926 + *      addr:  to be verified address
11927 + *      saddr: socket address
11928 + */
11929 +static inline int v4_inet_addr_match (
11930 +       struct nx_info *nxi,
11931 +       __be32 addr,
11932 +       __be32 saddr)
11933 +{
11934 +       if (addr && (saddr == addr))
11935 +               return 1;
11936 +       if (!saddr)
11937 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
11938 +       return 0;
11939 +}
11940 +
11941 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
11942 +{
11943 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
11944 +               (addr == nxi->v4_lback.s_addr))
11945 +               return IPI_LOOPBACK;
11946 +       return addr;
11947 +}
11948 +
11949 +static inline
11950 +int nx_info_has_v4(struct nx_info *nxi)
11951 +{
11952 +       if (!nxi)
11953 +               return 1;
11954 +       if (NX_IPV4(nxi))
11955 +               return 1;
11956 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
11957 +               return 1;
11958 +       return 0;
11959 +}
11960 +
11961 +#else /* CONFIG_INET */
11962 +
11963 +static inline
11964 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
11965 +{
11966 +       return 1;
11967 +}
11968 +
11969 +static inline
11970 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
11971 +{
11972 +       return 1;
11973 +}
11974 +
11975 +static inline
11976 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
11977 +{
11978 +       return 1;
11979 +}
11980 +
11981 +static inline
11982 +int nx_info_has_v4(struct nx_info *nxi)
11983 +{
11984 +       return 0;
11985 +}
11986 +
11987 +#endif /* CONFIG_INET */
11988 +
11989 +#define current_nx_info_has_v4() \
11990 +       nx_info_has_v4(current_nx_info())
11991 +
11992 +#else
11993 +// #warning duplicate inclusion
11994 +#endif
11995 diff -NurpP --minimal linux-3.0/include/linux/vs_inet6.h linux-3.0-vs2.3.1-pre6/include/linux/vs_inet6.h
11996 --- linux-3.0/include/linux/vs_inet6.h  1970-01-01 01:00:00.000000000 +0100
11997 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_inet6.h     2011-06-10 22:11:24.000000000 +0200
11998 @@ -0,0 +1,246 @@
11999 +#ifndef _VS_INET6_H
12000 +#define _VS_INET6_H
12001 +
12002 +#include "vserver/base.h"
12003 +#include "vserver/network.h"
12004 +#include "vserver/debug.h"
12005 +
12006 +#include <net/ipv6.h>
12007 +
12008 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
12009 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
12010 +
12011 +
12012 +#ifdef CONFIG_IPV6
12013 +
12014 +static inline
12015 +int v6_addr_match(struct nx_addr_v6 *nxa,
12016 +       const struct in6_addr *addr, uint16_t mask)
12017 +{
12018 +       int ret = 0;
12019 +
12020 +       switch (nxa->type & mask) {
12021 +       case NXA_TYPE_MASK:
12022 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
12023 +               break;
12024 +       case NXA_TYPE_ADDR:
12025 +               ret = ipv6_addr_equal(&nxa->ip, addr);
12026 +               break;
12027 +       case NXA_TYPE_ANY:
12028 +               ret = 1;
12029 +               break;
12030 +       }
12031 +       vxdprintk(VXD_CBIT(net, 0),
12032 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
12033 +               nxa, NXAV6(nxa), addr, mask, ret);
12034 +       return ret;
12035 +}
12036 +
12037 +static inline
12038 +int v6_addr_in_nx_info(struct nx_info *nxi,
12039 +       const struct in6_addr *addr, uint16_t mask)
12040 +{
12041 +       struct nx_addr_v6 *nxa;
12042 +       int ret = 1;
12043 +
12044 +       if (!nxi)
12045 +               goto out;
12046 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
12047 +               if (v6_addr_match(nxa, addr, mask))
12048 +                       goto out;
12049 +       ret = 0;
12050 +out:
12051 +       vxdprintk(VXD_CBIT(net, 0),
12052 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
12053 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
12054 +       return ret;
12055 +}
12056 +
12057 +static inline
12058 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
12059 +{
12060 +       /* FIXME: needs full range checks */
12061 +       return v6_addr_match(nxa, &addr->ip, mask);
12062 +}
12063 +
12064 +static inline
12065 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
12066 +{
12067 +       struct nx_addr_v6 *ptr;
12068 +
12069 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
12070 +               if (v6_nx_addr_match(ptr, nxa, mask))
12071 +                       return 1;
12072 +       return 0;
12073 +}
12074 +
12075 +
12076 +/*
12077 + *     Check if a given address matches for a socket
12078 + *
12079 + *     nxi:            the socket's nx_info if any
12080 + *     addr:           to be verified address
12081 + */
12082 +static inline
12083 +int v6_sock_addr_match (
12084 +       struct nx_info *nxi,
12085 +       struct inet_sock *inet,
12086 +       struct in6_addr *addr)
12087 +{
12088 +       struct sock *sk = &inet->sk;
12089 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12090 +
12091 +       if (!ipv6_addr_any(addr) &&
12092 +               ipv6_addr_equal(saddr, addr))
12093 +               return 1;
12094 +       if (ipv6_addr_any(saddr))
12095 +               return v6_addr_in_nx_info(nxi, addr, -1);
12096 +       return 0;
12097 +}
12098 +
12099 +/*
12100 + *     check if address is covered by socket
12101 + *
12102 + *     sk:     the socket to check against
12103 + *     addr:   the address in question (must be != 0)
12104 + */
12105 +
12106 +static inline
12107 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
12108 +{
12109 +       struct nx_info *nxi = sk->sk_nx_info;
12110 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12111 +
12112 +       vxdprintk(VXD_CBIT(net, 5),
12113 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
12114 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
12115 +               (sk->sk_socket?sk->sk_socket->flags:0));
12116 +
12117 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
12118 +               return v6_addr_match(nxa, saddr, -1);
12119 +       } else if (nxi) {               /* match against nx_info */
12120 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
12121 +       } else {                        /* unrestricted any socket */
12122 +               return 1;
12123 +       }
12124 +}
12125 +
12126 +
12127 +/* inet related checks and helpers */
12128 +
12129 +
12130 +struct in_ifaddr;
12131 +struct net_device;
12132 +struct sock;
12133 +
12134 +
12135 +#include <linux/netdevice.h>
12136 +#include <linux/inetdevice.h>
12137 +#include <net/inet_timewait_sock.h>
12138 +
12139 +
12140 +int dev_in_nx_info(struct net_device *, struct nx_info *);
12141 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
12142 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
12143 +
12144 +
12145 +
12146 +static inline
12147 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
12148 +{
12149 +       if (!nxi)
12150 +               return 1;
12151 +       if (!ifa)
12152 +               return 0;
12153 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
12154 +}
12155 +
12156 +static inline
12157 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
12158 +{
12159 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
12160 +               nxi, nxi ? nxi->nx_id : 0, ifa,
12161 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
12162 +
12163 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
12164 +               return 1;
12165 +       if (v6_ifa_in_nx_info(ifa, nxi))
12166 +               return 1;
12167 +       return 0;
12168 +}
12169 +
12170 +
12171 +struct nx_v6_sock_addr {
12172 +       struct in6_addr saddr;  /* Address used for validation */
12173 +       struct in6_addr baddr;  /* Address used for socket bind */
12174 +};
12175 +
12176 +static inline
12177 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
12178 +       struct nx_v6_sock_addr *nsa)
12179 +{
12180 +       // struct sock *sk = &inet->sk;
12181 +       // struct nx_info *nxi = sk->sk_nx_info;
12182 +       struct in6_addr saddr = addr->sin6_addr;
12183 +       struct in6_addr baddr = saddr;
12184 +
12185 +       nsa->saddr = saddr;
12186 +       nsa->baddr = baddr;
12187 +       return 0;
12188 +}
12189 +
12190 +static inline
12191 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
12192 +{
12193 +       // struct sock *sk = &inet->sk;
12194 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
12195 +
12196 +       // *saddr = nsa->baddr;
12197 +       // inet->inet_saddr = nsa->baddr;
12198 +}
12199 +
12200 +static inline
12201 +int nx_info_has_v6(struct nx_info *nxi)
12202 +{
12203 +       if (!nxi)
12204 +               return 1;
12205 +       if (NX_IPV6(nxi))
12206 +               return 1;
12207 +       return 0;
12208 +}
12209 +
12210 +#else /* CONFIG_IPV6 */
12211 +
12212 +static inline
12213 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
12214 +{
12215 +       return 1;
12216 +}
12217 +
12218 +
12219 +static inline
12220 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
12221 +{
12222 +       return 1;
12223 +}
12224 +
12225 +static inline
12226 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
12227 +{
12228 +       return 1;
12229 +}
12230 +
12231 +static inline
12232 +int nx_info_has_v6(struct nx_info *nxi)
12233 +{
12234 +       return 0;
12235 +}
12236 +
12237 +#endif /* CONFIG_IPV6 */
12238 +
12239 +#define current_nx_info_has_v6() \
12240 +       nx_info_has_v6(current_nx_info())
12241 +
12242 +#else
12243 +#warning duplicate inclusion
12244 +#endif
12245 diff -NurpP --minimal linux-3.0/include/linux/vs_limit.h linux-3.0-vs2.3.1-pre6/include/linux/vs_limit.h
12246 --- linux-3.0/include/linux/vs_limit.h  1970-01-01 01:00:00.000000000 +0100
12247 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_limit.h     2011-06-10 22:11:24.000000000 +0200
12248 @@ -0,0 +1,140 @@
12249 +#ifndef _VS_LIMIT_H
12250 +#define _VS_LIMIT_H
12251 +
12252 +#include "vserver/limit.h"
12253 +#include "vserver/base.h"
12254 +#include "vserver/context.h"
12255 +#include "vserver/debug.h"
12256 +#include "vserver/context.h"
12257 +#include "vserver/limit_int.h"
12258 +
12259 +
12260 +#define vx_acc_cres(v, d, p, r) \
12261 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
12262 +
12263 +#define vx_acc_cres_cond(x, d, p, r) \
12264 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
12265 +       r, d, p, __FILE__, __LINE__)
12266 +
12267 +
12268 +#define vx_add_cres(v, a, p, r) \
12269 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
12270 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
12271 +
12272 +#define vx_add_cres_cond(x, a, p, r) \
12273 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
12274 +       r, a, p, __FILE__, __LINE__)
12275 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
12276 +
12277 +
12278 +/* process and file limits */
12279 +
12280 +#define vx_nproc_inc(p) \
12281 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
12282 +
12283 +#define vx_nproc_dec(p) \
12284 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
12285 +
12286 +#define vx_files_inc(f) \
12287 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
12288 +
12289 +#define vx_files_dec(f) \
12290 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
12291 +
12292 +#define vx_locks_inc(l) \
12293 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
12294 +
12295 +#define vx_locks_dec(l) \
12296 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
12297 +
12298 +#define vx_openfd_inc(f) \
12299 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
12300 +
12301 +#define vx_openfd_dec(f) \
12302 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
12303 +
12304 +
12305 +#define vx_cres_avail(v, n, r) \
12306 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
12307 +
12308 +
12309 +#define vx_nproc_avail(n) \
12310 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
12311 +
12312 +#define vx_files_avail(n) \
12313 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
12314 +
12315 +#define vx_locks_avail(n) \
12316 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
12317 +
12318 +#define vx_openfd_avail(n) \
12319 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
12320 +
12321 +
12322 +/* dentry limits */
12323 +
12324 +#define vx_dentry_inc(d) do {                                          \
12325 +       if ((d)->d_count == 1)                                          \
12326 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
12327 +       } while (0)
12328 +
12329 +#define vx_dentry_dec(d) do {                                          \
12330 +       if ((d)->d_count == 0)                                          \
12331 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
12332 +       } while (0)
12333 +
12334 +#define vx_dentry_avail(n) \
12335 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
12336 +
12337 +
12338 +/* socket limits */
12339 +
12340 +#define vx_sock_inc(s) \
12341 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
12342 +
12343 +#define vx_sock_dec(s) \
12344 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
12345 +
12346 +#define vx_sock_avail(n) \
12347 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
12348 +
12349 +
12350 +/* ipc resource limits */
12351 +
12352 +#define vx_ipcmsg_add(v, u, a) \
12353 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
12354 +
12355 +#define vx_ipcmsg_sub(v, u, a) \
12356 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
12357 +
12358 +#define vx_ipcmsg_avail(v, a) \
12359 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
12360 +
12361 +
12362 +#define vx_ipcshm_add(v, k, a) \
12363 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
12364 +
12365 +#define vx_ipcshm_sub(v, k, a) \
12366 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
12367 +
12368 +#define vx_ipcshm_avail(v, a) \
12369 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
12370 +
12371 +
12372 +#define vx_semary_inc(a) \
12373 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
12374 +
12375 +#define vx_semary_dec(a) \
12376 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
12377 +
12378 +
12379 +#define vx_nsems_add(a,n) \
12380 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
12381 +
12382 +#define vx_nsems_sub(a,n) \
12383 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
12384 +
12385 +
12386 +#else
12387 +#warning duplicate inclusion
12388 +#endif
12389 diff -NurpP --minimal linux-3.0/include/linux/vs_memory.h linux-3.0-vs2.3.1-pre6/include/linux/vs_memory.h
12390 --- linux-3.0/include/linux/vs_memory.h 1970-01-01 01:00:00.000000000 +0100
12391 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_memory.h    2011-06-10 22:11:24.000000000 +0200
12392 @@ -0,0 +1,58 @@
12393 +#ifndef _VS_MEMORY_H
12394 +#define _VS_MEMORY_H
12395 +
12396 +#include "vserver/limit.h"
12397 +#include "vserver/base.h"
12398 +#include "vserver/context.h"
12399 +#include "vserver/debug.h"
12400 +#include "vserver/context.h"
12401 +#include "vserver/limit_int.h"
12402 +
12403 +enum {
12404 +       VXPT_UNKNOWN = 0,
12405 +       VXPT_ANON,
12406 +       VXPT_NONE,
12407 +       VXPT_FILE,
12408 +       VXPT_SWAP,
12409 +       VXPT_WRITE
12410 +};
12411 +
12412 +#if 0
12413 +#define        vx_page_fault(mm, vma, type, ret)
12414 +#else
12415 +
12416 +static inline
12417 +void __vx_page_fault(struct mm_struct *mm,
12418 +       struct vm_area_struct *vma, int type, int ret)
12419 +{
12420 +       struct vx_info *vxi = mm->mm_vx_info;
12421 +       int what;
12422 +/*
12423 +       static char *page_type[6] =
12424 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
12425 +       static char *page_what[4] =
12426 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
12427 +*/
12428 +
12429 +       if (!vxi)
12430 +               return;
12431 +
12432 +       what = (ret & 0x3);
12433 +
12434 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
12435 +               type, what, ret, page_type[type], page_what[what]);
12436 +*/
12437 +       if (ret & VM_FAULT_WRITE)
12438 +               what |= 0x4;
12439 +       atomic_inc(&vxi->cacct.page[type][what]);
12440 +}
12441 +
12442 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
12443 +#endif
12444 +
12445 +
12446 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
12447 +
12448 +#else
12449 +#warning duplicate inclusion
12450 +#endif
12451 diff -NurpP --minimal linux-3.0/include/linux/vs_network.h linux-3.0-vs2.3.1-pre6/include/linux/vs_network.h
12452 --- linux-3.0/include/linux/vs_network.h        1970-01-01 01:00:00.000000000 +0100
12453 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_network.h   2011-06-10 22:11:24.000000000 +0200
12454 @@ -0,0 +1,169 @@
12455 +#ifndef _NX_VS_NETWORK_H
12456 +#define _NX_VS_NETWORK_H
12457 +
12458 +#include "vserver/context.h"
12459 +#include "vserver/network.h"
12460 +#include "vserver/base.h"
12461 +#include "vserver/check.h"
12462 +#include "vserver/debug.h"
12463 +
12464 +#include <linux/sched.h>
12465 +
12466 +
12467 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
12468 +
12469 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
12470 +       const char *_file, int _line)
12471 +{
12472 +       if (!nxi)
12473 +               return NULL;
12474 +
12475 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
12476 +               nxi, nxi ? nxi->nx_id : 0,
12477 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12478 +               _file, _line);
12479 +
12480 +       atomic_inc(&nxi->nx_usecnt);
12481 +       return nxi;
12482 +}
12483 +
12484 +
12485 +extern void free_nx_info(struct nx_info *);
12486 +
12487 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
12488 +
12489 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
12490 +{
12491 +       if (!nxi)
12492 +               return;
12493 +
12494 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
12495 +               nxi, nxi ? nxi->nx_id : 0,
12496 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12497 +               _file, _line);
12498 +
12499 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
12500 +               free_nx_info(nxi);
12501 +}
12502 +
12503 +
12504 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
12505 +
12506 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
12507 +               const char *_file, int _line)
12508 +{
12509 +       if (nxi) {
12510 +               vxlprintk(VXD_CBIT(nid, 3),
12511 +                       "init_nx_info(%p[#%d.%d])",
12512 +                       nxi, nxi ? nxi->nx_id : 0,
12513 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12514 +                       _file, _line);
12515 +
12516 +               atomic_inc(&nxi->nx_usecnt);
12517 +       }
12518 +       *nxp = nxi;
12519 +}
12520 +
12521 +
12522 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
12523 +
12524 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
12525 +       const char *_file, int _line)
12526 +{
12527 +       struct nx_info *nxo;
12528 +
12529 +       if (!nxi)
12530 +               return;
12531 +
12532 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
12533 +               nxi, nxi ? nxi->nx_id : 0,
12534 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12535 +               _file, _line);
12536 +
12537 +       atomic_inc(&nxi->nx_usecnt);
12538 +       nxo = xchg(nxp, nxi);
12539 +       BUG_ON(nxo);
12540 +}
12541 +
12542 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
12543 +
12544 +static inline void __clr_nx_info(struct nx_info **nxp,
12545 +       const char *_file, int _line)
12546 +{
12547 +       struct nx_info *nxo;
12548 +
12549 +       nxo = xchg(nxp, NULL);
12550 +       if (!nxo)
12551 +               return;
12552 +
12553 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
12554 +               nxo, nxo ? nxo->nx_id : 0,
12555 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
12556 +               _file, _line);
12557 +
12558 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
12559 +               free_nx_info(nxo);
12560 +}
12561 +
12562 +
12563 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
12564 +
12565 +static inline void __claim_nx_info(struct nx_info *nxi,
12566 +       struct task_struct *task, const char *_file, int _line)
12567 +{
12568 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
12569 +               nxi, nxi ? nxi->nx_id : 0,
12570 +               nxi?atomic_read(&nxi->nx_usecnt):0,
12571 +               nxi?atomic_read(&nxi->nx_tasks):0,
12572 +               task, _file, _line);
12573 +
12574 +       atomic_inc(&nxi->nx_tasks);
12575 +}
12576 +
12577 +
12578 +extern void unhash_nx_info(struct nx_info *);
12579 +
12580 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
12581 +
12582 +static inline void __release_nx_info(struct nx_info *nxi,
12583 +       struct task_struct *task, const char *_file, int _line)
12584 +{
12585 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
12586 +               nxi, nxi ? nxi->nx_id : 0,
12587 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12588 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
12589 +               task, _file, _line);
12590 +
12591 +       might_sleep();
12592 +
12593 +       if (atomic_dec_and_test(&nxi->nx_tasks))
12594 +               unhash_nx_info(nxi);
12595 +}
12596 +
12597 +
12598 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
12599 +
12600 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
12601 +       const char *_file, int _line)
12602 +{
12603 +       struct nx_info *nxi;
12604 +
12605 +       task_lock(p);
12606 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
12607 +               p, _file, _line);
12608 +       nxi = __get_nx_info(p->nx_info, _file, _line);
12609 +       task_unlock(p);
12610 +       return nxi;
12611 +}
12612 +
12613 +
12614 +static inline void exit_nx_info(struct task_struct *p)
12615 +{
12616 +       if (p->nx_info)
12617 +               release_nx_info(p->nx_info, p);
12618 +}
12619 +
12620 +
12621 +#else
12622 +#warning duplicate inclusion
12623 +#endif
12624 diff -NurpP --minimal linux-3.0/include/linux/vs_pid.h linux-3.0-vs2.3.1-pre6/include/linux/vs_pid.h
12625 --- linux-3.0/include/linux/vs_pid.h    1970-01-01 01:00:00.000000000 +0100
12626 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_pid.h       2011-06-10 22:11:24.000000000 +0200
12627 @@ -0,0 +1,50 @@
12628 +#ifndef _VS_PID_H
12629 +#define _VS_PID_H
12630 +
12631 +#include "vserver/base.h"
12632 +#include "vserver/check.h"
12633 +#include "vserver/context.h"
12634 +#include "vserver/debug.h"
12635 +#include "vserver/pid.h"
12636 +#include <linux/pid_namespace.h>
12637 +
12638 +
12639 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
12640 +
12641 +static inline
12642 +int vx_proc_task_visible(struct task_struct *task)
12643 +{
12644 +       if ((task->pid == 1) &&
12645 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
12646 +               /* show a blend through init */
12647 +               goto visible;
12648 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
12649 +               goto visible;
12650 +       return 0;
12651 +visible:
12652 +       return 1;
12653 +}
12654 +
12655 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
12656 +
12657 +
12658 +static inline
12659 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
12660 +{
12661 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
12662 +
12663 +       if (task && !vx_proc_task_visible(task)) {
12664 +               vxdprintk(VXD_CBIT(misc, 6),
12665 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
12666 +                       task, task->xid, task->pid,
12667 +                       current, current->xid, current->pid);
12668 +               put_task_struct(task);
12669 +               task = NULL;
12670 +       }
12671 +       return task;
12672 +}
12673 +
12674 +
12675 +#else
12676 +#warning duplicate inclusion
12677 +#endif
12678 diff -NurpP --minimal linux-3.0/include/linux/vs_sched.h linux-3.0-vs2.3.1-pre6/include/linux/vs_sched.h
12679 --- linux-3.0/include/linux/vs_sched.h  1970-01-01 01:00:00.000000000 +0100
12680 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_sched.h     2011-06-10 22:11:24.000000000 +0200
12681 @@ -0,0 +1,40 @@
12682 +#ifndef _VS_SCHED_H
12683 +#define _VS_SCHED_H
12684 +
12685 +#include "vserver/base.h"
12686 +#include "vserver/context.h"
12687 +#include "vserver/sched.h"
12688 +
12689 +
12690 +#define MAX_PRIO_BIAS           20
12691 +#define MIN_PRIO_BIAS          -20
12692 +
12693 +static inline
12694 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
12695 +{
12696 +       struct vx_info *vxi = p->vx_info;
12697 +
12698 +       if (vxi)
12699 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
12700 +       return prio;
12701 +}
12702 +
12703 +static inline void vx_account_user(struct vx_info *vxi,
12704 +       cputime_t cputime, int nice)
12705 +{
12706 +       if (!vxi)
12707 +               return;
12708 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
12709 +}
12710 +
12711 +static inline void vx_account_system(struct vx_info *vxi,
12712 +       cputime_t cputime, int idle)
12713 +{
12714 +       if (!vxi)
12715 +               return;
12716 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
12717 +}
12718 +
12719 +#else
12720 +#warning duplicate inclusion
12721 +#endif
12722 diff -NurpP --minimal linux-3.0/include/linux/vs_socket.h linux-3.0-vs2.3.1-pre6/include/linux/vs_socket.h
12723 --- linux-3.0/include/linux/vs_socket.h 1970-01-01 01:00:00.000000000 +0100
12724 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_socket.h    2011-06-10 22:11:24.000000000 +0200
12725 @@ -0,0 +1,67 @@
12726 +#ifndef _VS_SOCKET_H
12727 +#define _VS_SOCKET_H
12728 +
12729 +#include "vserver/debug.h"
12730 +#include "vserver/base.h"
12731 +#include "vserver/cacct.h"
12732 +#include "vserver/context.h"
12733 +#include "vserver/tag.h"
12734 +
12735 +
12736 +/* socket accounting */
12737 +
12738 +#include <linux/socket.h>
12739 +
12740 +static inline int vx_sock_type(int family)
12741 +{
12742 +       switch (family) {
12743 +       case PF_UNSPEC:
12744 +               return VXA_SOCK_UNSPEC;
12745 +       case PF_UNIX:
12746 +               return VXA_SOCK_UNIX;
12747 +       case PF_INET:
12748 +               return VXA_SOCK_INET;
12749 +       case PF_INET6:
12750 +               return VXA_SOCK_INET6;
12751 +       case PF_PACKET:
12752 +               return VXA_SOCK_PACKET;
12753 +       default:
12754 +               return VXA_SOCK_OTHER;
12755 +       }
12756 +}
12757 +
12758 +#define vx_acc_sock(v, f, p, s) \
12759 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
12760 +
12761 +static inline void __vx_acc_sock(struct vx_info *vxi,
12762 +       int family, int pos, int size, char *file, int line)
12763 +{
12764 +       if (vxi) {
12765 +               int type = vx_sock_type(family);
12766 +
12767 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
12768 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
12769 +       }
12770 +}
12771 +
12772 +#define vx_sock_recv(sk, s) \
12773 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
12774 +#define vx_sock_send(sk, s) \
12775 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
12776 +#define vx_sock_fail(sk, s) \
12777 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
12778 +
12779 +
12780 +#define sock_vx_init(s) do {           \
12781 +       (s)->sk_xid = 0;                \
12782 +       (s)->sk_vx_info = NULL;         \
12783 +       } while (0)
12784 +
12785 +#define sock_nx_init(s) do {           \
12786 +       (s)->sk_nid = 0;                \
12787 +       (s)->sk_nx_info = NULL;         \
12788 +       } while (0)
12789 +
12790 +#else
12791 +#warning duplicate inclusion
12792 +#endif
12793 diff -NurpP --minimal linux-3.0/include/linux/vs_tag.h linux-3.0-vs2.3.1-pre6/include/linux/vs_tag.h
12794 --- linux-3.0/include/linux/vs_tag.h    1970-01-01 01:00:00.000000000 +0100
12795 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_tag.h       2011-06-10 22:11:24.000000000 +0200
12796 @@ -0,0 +1,47 @@
12797 +#ifndef _VS_TAG_H
12798 +#define _VS_TAG_H
12799 +
12800 +#include <linux/vserver/tag.h>
12801 +
12802 +/* check conditions */
12803 +
12804 +#define DX_ADMIN       0x0001
12805 +#define DX_WATCH       0x0002
12806 +#define DX_HOSTID      0x0008
12807 +
12808 +#define DX_IDENT       0x0010
12809 +
12810 +#define DX_ARG_MASK    0x0010
12811 +
12812 +
12813 +#define dx_task_tag(t) ((t)->tag)
12814 +
12815 +#define dx_current_tag() dx_task_tag(current)
12816 +
12817 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
12818 +
12819 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
12820 +
12821 +
12822 +/*
12823 + * check current context for ADMIN/WATCH and
12824 + * optionally against supplied argument
12825 + */
12826 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
12827 +{
12828 +       if (mode & DX_ARG_MASK) {
12829 +               if ((mode & DX_IDENT) && (id == cid))
12830 +                       return 1;
12831 +       }
12832 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
12833 +               ((mode & DX_WATCH) && (cid == 1)) ||
12834 +               ((mode & DX_HOSTID) && (id == 0)));
12835 +}
12836 +
12837 +struct inode;
12838 +int dx_permission(const struct inode *inode, int mask);
12839 +
12840 +
12841 +#else
12842 +#warning duplicate inclusion
12843 +#endif
12844 diff -NurpP --minimal linux-3.0/include/linux/vs_time.h linux-3.0-vs2.3.1-pre6/include/linux/vs_time.h
12845 --- linux-3.0/include/linux/vs_time.h   1970-01-01 01:00:00.000000000 +0100
12846 +++ linux-3.0-vs2.3.1-pre6/include/linux/vs_time.h      2011-06-13 14:57:45.000000000 +0200
12847 @@ -0,0 +1,19 @@
12848 +#ifndef _VS_TIME_H
12849 +#define _VS_TIME_H
12850 +
12851 +
12852 +/* time faking stuff */
12853 +
12854 +#ifdef CONFIG_VSERVER_VTIME
12855 +
12856 +extern void vx_adjust_timespec(struct timespec *ts);
12857 +extern int vx_settimeofday(const struct timespec *ts);
12858 +
12859 +#else
12860 +#define        vx_adjust_timespec(t)   do { } while (0)
12861 +#define        vx_settimeofday(t)      do_settimeofday(t)
12862 +#endif
12863 +
12864 +#else
12865 +#warning duplicate inclusion
12866 +#endif
12867 diff -NurpP --minimal linux-3.0/include/linux/vserver/Kbuild linux-3.0-vs2.3.1-pre6/include/linux/vserver/Kbuild
12868 --- linux-3.0/include/linux/vserver/Kbuild      1970-01-01 01:00:00.000000000 +0100
12869 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/Kbuild 2011-06-10 22:11:24.000000000 +0200
12870 @@ -0,0 +1,8 @@
12871 +
12872 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
12873 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12874 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12875 +       debug_cmd.h device_cmd.h
12876 +
12877 +unifdef-y += switch.h network.h monitor.h inode.h device.h
12878 +
12879 diff -NurpP --minimal linux-3.0/include/linux/vserver/base.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/base.h
12880 --- linux-3.0/include/linux/vserver/base.h      1970-01-01 01:00:00.000000000 +0100
12881 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/base.h 2011-06-13 14:09:44.000000000 +0200
12882 @@ -0,0 +1,173 @@
12883 +#ifndef _VX_BASE_H
12884 +#define _VX_BASE_H
12885 +
12886 +
12887 +/* context state changes */
12888 +
12889 +enum {
12890 +       VSC_STARTUP = 1,
12891 +       VSC_SHUTDOWN,
12892 +
12893 +       VSC_NETUP,
12894 +       VSC_NETDOWN,
12895 +};
12896 +
12897 +
12898 +
12899 +#define vx_task_xid(t) ((t)->xid)
12900 +
12901 +#define vx_current_xid() vx_task_xid(current)
12902 +
12903 +#define current_vx_info() (current->vx_info)
12904 +
12905 +
12906 +#define nx_task_nid(t) ((t)->nid)
12907 +
12908 +#define nx_current_nid() nx_task_nid(current)
12909 +
12910 +#define current_nx_info() (current->nx_info)
12911 +
12912 +
12913 +/* generic flag merging */
12914 +
12915 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
12916 +
12917 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
12918 +
12919 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
12920 +
12921 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
12922 +
12923 +
12924 +/* context flags */
12925 +
12926 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
12927 +
12928 +#define vx_current_flags()     __vx_flags(current_vx_info())
12929 +
12930 +#define vx_info_flags(v, m, f) \
12931 +       vs_check_flags(__vx_flags(v), m, f)
12932 +
12933 +#define task_vx_flags(t, m, f) \
12934 +       ((t) && vx_info_flags((t)->vx_info, m, f))
12935 +
12936 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
12937 +
12938 +
12939 +/* context caps */
12940 +
12941 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
12942 +
12943 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
12944 +
12945 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
12946 +
12947 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
12948 +
12949 +
12950 +
12951 +/* network flags */
12952 +
12953 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
12954 +
12955 +#define nx_current_flags()     __nx_flags(current_nx_info())
12956 +
12957 +#define nx_info_flags(n, m, f) \
12958 +       vs_check_flags(__nx_flags(n), m, f)
12959 +
12960 +#define task_nx_flags(t, m, f) \
12961 +       ((t) && nx_info_flags((t)->nx_info, m, f))
12962 +
12963 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
12964 +
12965 +
12966 +/* network caps */
12967 +
12968 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
12969 +
12970 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
12971 +
12972 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
12973 +
12974 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
12975 +
12976 +
12977 +/* context mask capabilities */
12978 +
12979 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
12980 +
12981 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
12982 +
12983 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
12984 +
12985 +
12986 +/* context bcap mask */
12987 +
12988 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
12989 +
12990 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
12991 +
12992 +
12993 +/* mask given bcaps */
12994 +
12995 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
12996 +
12997 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
12998 +
12999 +
13000 +/* masked cap_bset */
13001 +
13002 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
13003 +
13004 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
13005 +
13006 +#if 0
13007 +#define vx_info_mbcap(v, b) \
13008 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
13009 +       vx_info_bcaps(v, b) : (b))
13010 +
13011 +#define task_vx_mbcap(t, b) \
13012 +       vx_info_mbcap((t)->vx_info, (t)->b)
13013 +
13014 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
13015 +#endif
13016 +
13017 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
13018 +
13019 +#define vx_capable(b, c) (capable(b) || \
13020 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
13021 +
13022 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
13023 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
13024 +
13025 +#define nx_capable(b, c) (capable(b) || \
13026 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
13027 +
13028 +#define vx_task_initpid(t, n) \
13029 +       ((t)->vx_info && \
13030 +       ((t)->vx_info->vx_initpid == (n)))
13031 +
13032 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
13033 +
13034 +
13035 +/* context unshare mask */
13036 +
13037 +#define __vx_umask(v)          ((v)->vx_umask)
13038 +
13039 +#define vx_current_umask()     __vx_umask(current_vx_info())
13040 +
13041 +#define vx_can_unshare(b, f) (capable(b) || \
13042 +       (cap_raised(current_cap(), b) && \
13043 +       !((f) & ~vx_current_umask())))
13044 +
13045 +
13046 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
13047 +
13048 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
13049 +
13050 +
13051 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
13052 +
13053 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
13054 +
13055 +#endif
13056 diff -NurpP --minimal linux-3.0/include/linux/vserver/cacct.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/cacct.h
13057 --- linux-3.0/include/linux/vserver/cacct.h     1970-01-01 01:00:00.000000000 +0100
13058 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/cacct.h        2011-06-10 22:11:24.000000000 +0200
13059 @@ -0,0 +1,15 @@
13060 +#ifndef _VX_CACCT_H
13061 +#define _VX_CACCT_H
13062 +
13063 +
13064 +enum sock_acc_field {
13065 +       VXA_SOCK_UNSPEC = 0,
13066 +       VXA_SOCK_UNIX,
13067 +       VXA_SOCK_INET,
13068 +       VXA_SOCK_INET6,
13069 +       VXA_SOCK_PACKET,
13070 +       VXA_SOCK_OTHER,
13071 +       VXA_SOCK_SIZE   /* array size */
13072 +};
13073 +
13074 +#endif /* _VX_CACCT_H */
13075 diff -NurpP --minimal linux-3.0/include/linux/vserver/cacct_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/cacct_cmd.h
13076 --- linux-3.0/include/linux/vserver/cacct_cmd.h 1970-01-01 01:00:00.000000000 +0100
13077 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/cacct_cmd.h    2011-06-10 22:11:24.000000000 +0200
13078 @@ -0,0 +1,23 @@
13079 +#ifndef _VX_CACCT_CMD_H
13080 +#define _VX_CACCT_CMD_H
13081 +
13082 +
13083 +/* virtual host info name commands */
13084 +
13085 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
13086 +
13087 +struct vcmd_sock_stat_v0 {
13088 +       uint32_t field;
13089 +       uint32_t count[3];
13090 +       uint64_t total[3];
13091 +};
13092 +
13093 +
13094 +#ifdef __KERNEL__
13095 +
13096 +#include <linux/compiler.h>
13097 +
13098 +extern int vc_sock_stat(struct vx_info *, void __user *);
13099 +
13100 +#endif /* __KERNEL__ */
13101 +#endif /* _VX_CACCT_CMD_H */
13102 diff -NurpP --minimal linux-3.0/include/linux/vserver/cacct_def.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/cacct_def.h
13103 --- linux-3.0/include/linux/vserver/cacct_def.h 1970-01-01 01:00:00.000000000 +0100
13104 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/cacct_def.h    2011-06-10 22:11:24.000000000 +0200
13105 @@ -0,0 +1,43 @@
13106 +#ifndef _VX_CACCT_DEF_H
13107 +#define _VX_CACCT_DEF_H
13108 +
13109 +#include <asm/atomic.h>
13110 +#include <linux/vserver/cacct.h>
13111 +
13112 +
13113 +struct _vx_sock_acc {
13114 +       atomic_long_t count;
13115 +       atomic_long_t total;
13116 +};
13117 +
13118 +/* context sub struct */
13119 +
13120 +struct _vx_cacct {
13121 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
13122 +       atomic_t slab[8];
13123 +       atomic_t page[6][8];
13124 +};
13125 +
13126 +#ifdef CONFIG_VSERVER_DEBUG
13127 +
13128 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
13129 +{
13130 +       int i, j;
13131 +
13132 +       printk("\t_vx_cacct:");
13133 +       for (i = 0; i < 6; i++) {
13134 +               struct _vx_sock_acc *ptr = cacct->sock[i];
13135 +
13136 +               printk("\t [%d] =", i);
13137 +               for (j = 0; j < 3; j++) {
13138 +                       printk(" [%d] = %8lu, %8lu", j,
13139 +                               atomic_long_read(&ptr[j].count),
13140 +                               atomic_long_read(&ptr[j].total));
13141 +               }
13142 +               printk("\n");
13143 +       }
13144 +}
13145 +
13146 +#endif
13147 +
13148 +#endif /* _VX_CACCT_DEF_H */
13149 diff -NurpP --minimal linux-3.0/include/linux/vserver/cacct_int.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/cacct_int.h
13150 --- linux-3.0/include/linux/vserver/cacct_int.h 1970-01-01 01:00:00.000000000 +0100
13151 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/cacct_int.h    2011-06-10 22:11:24.000000000 +0200
13152 @@ -0,0 +1,21 @@
13153 +#ifndef _VX_CACCT_INT_H
13154 +#define _VX_CACCT_INT_H
13155 +
13156 +
13157 +#ifdef __KERNEL__
13158 +
13159 +static inline
13160 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
13161 +{
13162 +       return atomic_long_read(&cacct->sock[type][pos].count);
13163 +}
13164 +
13165 +
13166 +static inline
13167 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
13168 +{
13169 +       return atomic_long_read(&cacct->sock[type][pos].total);
13170 +}
13171 +
13172 +#endif /* __KERNEL__ */
13173 +#endif /* _VX_CACCT_INT_H */
13174 diff -NurpP --minimal linux-3.0/include/linux/vserver/check.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/check.h
13175 --- linux-3.0/include/linux/vserver/check.h     1970-01-01 01:00:00.000000000 +0100
13176 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/check.h        2011-06-10 22:11:24.000000000 +0200
13177 @@ -0,0 +1,89 @@
13178 +#ifndef _VS_CHECK_H
13179 +#define _VS_CHECK_H
13180 +
13181 +
13182 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
13183 +
13184 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
13185 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
13186 +#else
13187 +#define MIN_D_CONTEXT  65536
13188 +#endif
13189 +
13190 +/* check conditions */
13191 +
13192 +#define VS_ADMIN       0x0001
13193 +#define VS_WATCH       0x0002
13194 +#define VS_HIDE                0x0004
13195 +#define VS_HOSTID      0x0008
13196 +
13197 +#define VS_IDENT       0x0010
13198 +#define VS_EQUIV       0x0020
13199 +#define VS_PARENT      0x0040
13200 +#define VS_CHILD       0x0080
13201 +
13202 +#define VS_ARG_MASK    0x00F0
13203 +
13204 +#define VS_DYNAMIC     0x0100
13205 +#define VS_STATIC      0x0200
13206 +
13207 +#define VS_ATR_MASK    0x0F00
13208 +
13209 +#ifdef CONFIG_VSERVER_PRIVACY
13210 +#define VS_ADMIN_P     (0)
13211 +#define VS_WATCH_P     (0)
13212 +#else
13213 +#define VS_ADMIN_P     VS_ADMIN
13214 +#define VS_WATCH_P     VS_WATCH
13215 +#endif
13216 +
13217 +#define VS_HARDIRQ     0x1000
13218 +#define VS_SOFTIRQ     0x2000
13219 +#define VS_IRQ         0x4000
13220 +
13221 +#define VS_IRQ_MASK    0xF000
13222 +
13223 +#include <linux/hardirq.h>
13224 +
13225 +/*
13226 + * check current context for ADMIN/WATCH and
13227 + * optionally against supplied argument
13228 + */
13229 +static inline int __vs_check(int cid, int id, unsigned int mode)
13230 +{
13231 +       if (mode & VS_ARG_MASK) {
13232 +               if ((mode & VS_IDENT) && (id == cid))
13233 +                       return 1;
13234 +       }
13235 +       if (mode & VS_ATR_MASK) {
13236 +               if ((mode & VS_DYNAMIC) &&
13237 +                       (id >= MIN_D_CONTEXT) &&
13238 +                       (id <= MAX_S_CONTEXT))
13239 +                       return 1;
13240 +               if ((mode & VS_STATIC) &&
13241 +                       (id > 1) && (id < MIN_D_CONTEXT))
13242 +                       return 1;
13243 +       }
13244 +       if (mode & VS_IRQ_MASK) {
13245 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
13246 +                       return 1;
13247 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
13248 +                       return 1;
13249 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
13250 +                       return 1;
13251 +       }
13252 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
13253 +               ((mode & VS_WATCH) && (cid == 1)) ||
13254 +               ((mode & VS_HOSTID) && (id == 0)));
13255 +}
13256 +
13257 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
13258 +
13259 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
13260 +
13261 +
13262 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
13263 +
13264 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
13265 +
13266 +#endif
13267 diff -NurpP --minimal linux-3.0/include/linux/vserver/context.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/context.h
13268 --- linux-3.0/include/linux/vserver/context.h   1970-01-01 01:00:00.000000000 +0100
13269 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/context.h      2011-06-10 22:11:24.000000000 +0200
13270 @@ -0,0 +1,189 @@
13271 +#ifndef _VX_CONTEXT_H
13272 +#define _VX_CONTEXT_H
13273 +
13274 +#include <linux/types.h>
13275 +#include <linux/capability.h>
13276 +
13277 +
13278 +/* context flags */
13279 +
13280 +#define VXF_INFO_SCHED         0x00000002
13281 +#define VXF_INFO_NPROC         0x00000004
13282 +#define VXF_INFO_PRIVATE       0x00000008
13283 +
13284 +#define VXF_INFO_INIT          0x00000010
13285 +#define VXF_INFO_HIDE          0x00000020
13286 +#define VXF_INFO_ULIMIT                0x00000040
13287 +#define VXF_INFO_NSPACE                0x00000080
13288 +
13289 +#define VXF_SCHED_HARD         0x00000100
13290 +#define VXF_SCHED_PRIO         0x00000200
13291 +#define VXF_SCHED_PAUSE                0x00000400
13292 +
13293 +#define VXF_VIRT_MEM           0x00010000
13294 +#define VXF_VIRT_UPTIME                0x00020000
13295 +#define VXF_VIRT_CPU           0x00040000
13296 +#define VXF_VIRT_LOAD          0x00080000
13297 +#define VXF_VIRT_TIME          0x00100000
13298 +
13299 +#define VXF_HIDE_MOUNT         0x01000000
13300 +/* was VXF_HIDE_NETIF          0x02000000 */
13301 +#define VXF_HIDE_VINFO         0x04000000
13302 +
13303 +#define VXF_STATE_SETUP                (1ULL << 32)
13304 +#define VXF_STATE_INIT         (1ULL << 33)
13305 +#define VXF_STATE_ADMIN                (1ULL << 34)
13306 +
13307 +#define VXF_SC_HELPER          (1ULL << 36)
13308 +#define VXF_REBOOT_KILL                (1ULL << 37)
13309 +#define VXF_PERSISTENT         (1ULL << 38)
13310 +
13311 +#define VXF_FORK_RSS           (1ULL << 48)
13312 +#define VXF_PROLIFIC           (1ULL << 49)
13313 +
13314 +#define VXF_IGNEG_NICE         (1ULL << 52)
13315 +
13316 +#define VXF_ONE_TIME           (0x0007ULL << 32)
13317 +
13318 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
13319 +
13320 +
13321 +/* context migration */
13322 +
13323 +#define VXM_SET_INIT           0x00000001
13324 +#define VXM_SET_REAPER         0x00000002
13325 +
13326 +/* context caps */
13327 +
13328 +#define VXC_CAP_MASK           0x00000000
13329 +
13330 +#define VXC_SET_UTSNAME                0x00000001
13331 +#define VXC_SET_RLIMIT         0x00000002
13332 +#define VXC_FS_SECURITY                0x00000004
13333 +#define VXC_FS_TRUSTED         0x00000008
13334 +#define VXC_TIOCSTI            0x00000010
13335 +
13336 +/* was VXC_RAW_ICMP            0x00000100 */
13337 +#define VXC_SYSLOG             0x00001000
13338 +#define VXC_OOM_ADJUST         0x00002000
13339 +#define VXC_AUDIT_CONTROL      0x00004000
13340 +
13341 +#define VXC_SECURE_MOUNT       0x00010000
13342 +#define VXC_SECURE_REMOUNT     0x00020000
13343 +#define VXC_BINARY_MOUNT       0x00040000
13344 +
13345 +#define VXC_QUOTA_CTL          0x00100000
13346 +#define VXC_ADMIN_MAPPER       0x00200000
13347 +#define VXC_ADMIN_CLOOP                0x00400000
13348 +
13349 +#define VXC_KTHREAD            0x01000000
13350 +#define VXC_NAMESPACE          0x02000000
13351 +
13352 +
13353 +#ifdef __KERNEL__
13354 +
13355 +#include <linux/list.h>
13356 +#include <linux/spinlock.h>
13357 +#include <linux/rcupdate.h>
13358 +
13359 +#include "limit_def.h"
13360 +#include "sched_def.h"
13361 +#include "cvirt_def.h"
13362 +#include "cacct_def.h"
13363 +#include "device_def.h"
13364 +
13365 +#define VX_SPACES      2
13366 +
13367 +struct _vx_info_pc {
13368 +       struct _vx_sched_pc sched_pc;
13369 +       struct _vx_cvirt_pc cvirt_pc;
13370 +};
13371 +
13372 +struct _vx_space {
13373 +       unsigned long vx_nsmask;                /* assignment mask */
13374 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
13375 +       struct fs_struct *vx_fs;                /* private namespace fs */
13376 +       const struct cred *vx_cred;             /* task credentials */
13377 +};
13378 +
13379 +struct vx_info {
13380 +       struct hlist_node vx_hlist;             /* linked list of contexts */
13381 +       xid_t vx_id;                            /* context id */
13382 +       atomic_t vx_usecnt;                     /* usage count */
13383 +       atomic_t vx_tasks;                      /* tasks count */
13384 +       struct vx_info *vx_parent;              /* parent context */
13385 +       int vx_state;                           /* context state */
13386 +
13387 +       struct _vx_space space[VX_SPACES];      /* namespace store */
13388 +
13389 +       uint64_t vx_flags;                      /* context flags */
13390 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
13391 +       uint64_t vx_umask;                      /* unshare mask (guest) */
13392 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
13393 +
13394 +       struct task_struct *vx_reaper;          /* guest reaper process */
13395 +       pid_t vx_initpid;                       /* PID of guest init */
13396 +       int64_t vx_badness_bias;                /* OOM points bias */
13397 +
13398 +       struct _vx_limit limit;                 /* vserver limits */
13399 +       struct _vx_sched sched;                 /* vserver scheduler */
13400 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
13401 +       struct _vx_cacct cacct;                 /* context accounting */
13402 +
13403 +       struct _vx_device dmap;                 /* default device map targets */
13404 +
13405 +#ifndef CONFIG_SMP
13406 +       struct _vx_info_pc info_pc;             /* per cpu data */
13407 +#else
13408 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
13409 +#endif
13410 +
13411 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
13412 +       int reboot_cmd;                         /* last sys_reboot() cmd */
13413 +       int exit_code;                          /* last process exit code */
13414 +
13415 +       char vx_name[65];                       /* vserver name */
13416 +};
13417 +
13418 +#ifndef CONFIG_SMP
13419 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
13420 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
13421 +#else
13422 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
13423 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
13424 +#endif
13425 +
13426 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
13427 +
13428 +
13429 +struct vx_info_save {
13430 +       struct vx_info *vxi;
13431 +       xid_t xid;
13432 +};
13433 +
13434 +
13435 +/* status flags */
13436 +
13437 +#define VXS_HASHED     0x0001
13438 +#define VXS_PAUSED     0x0010
13439 +#define VXS_SHUTDOWN   0x0100
13440 +#define VXS_HELPER     0x1000
13441 +#define VXS_RELEASED   0x8000
13442 +
13443 +
13444 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
13445 +extern void release_vx_info(struct vx_info *, struct task_struct *);
13446 +
13447 +extern struct vx_info *lookup_vx_info(int);
13448 +extern struct vx_info *lookup_or_create_vx_info(int);
13449 +
13450 +extern int get_xid_list(int, unsigned int *, int);
13451 +extern int xid_is_hashed(xid_t);
13452 +
13453 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
13454 +
13455 +extern long vs_state_change(struct vx_info *, unsigned int);
13456 +
13457 +
13458 +#endif /* __KERNEL__ */
13459 +#endif /* _VX_CONTEXT_H */
13460 diff -NurpP --minimal linux-3.0/include/linux/vserver/context_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/context_cmd.h
13461 --- linux-3.0/include/linux/vserver/context_cmd.h       1970-01-01 01:00:00.000000000 +0100
13462 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/context_cmd.h  2011-06-10 22:11:24.000000000 +0200
13463 @@ -0,0 +1,145 @@
13464 +#ifndef _VX_CONTEXT_CMD_H
13465 +#define _VX_CONTEXT_CMD_H
13466 +
13467 +
13468 +/* vinfo commands */
13469 +
13470 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
13471 +
13472 +#ifdef __KERNEL__
13473 +extern int vc_task_xid(uint32_t);
13474 +
13475 +#endif /* __KERNEL__ */
13476 +
13477 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
13478 +
13479 +struct vcmd_vx_info_v0 {
13480 +       uint32_t xid;
13481 +       uint32_t initpid;
13482 +       /* more to come */
13483 +};
13484 +
13485 +#ifdef __KERNEL__
13486 +extern int vc_vx_info(struct vx_info *, void __user *);
13487 +
13488 +#endif /* __KERNEL__ */
13489 +
13490 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
13491 +
13492 +struct vcmd_ctx_stat_v0 {
13493 +       uint32_t usecnt;
13494 +       uint32_t tasks;
13495 +       /* more to come */
13496 +};
13497 +
13498 +#ifdef __KERNEL__
13499 +extern int vc_ctx_stat(struct vx_info *, void __user *);
13500 +
13501 +#endif /* __KERNEL__ */
13502 +
13503 +/* context commands */
13504 +
13505 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
13506 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
13507 +
13508 +struct vcmd_ctx_create {
13509 +       uint64_t flagword;
13510 +};
13511 +
13512 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
13513 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
13514 +
13515 +struct vcmd_ctx_migrate {
13516 +       uint64_t flagword;
13517 +};
13518 +
13519 +#ifdef __KERNEL__
13520 +extern int vc_ctx_create(uint32_t, void __user *);
13521 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
13522 +
13523 +#endif /* __KERNEL__ */
13524 +
13525 +
13526 +/* flag commands */
13527 +
13528 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
13529 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
13530 +
13531 +struct vcmd_ctx_flags_v0 {
13532 +       uint64_t flagword;
13533 +       uint64_t mask;
13534 +};
13535 +
13536 +#ifdef __KERNEL__
13537 +extern int vc_get_cflags(struct vx_info *, void __user *);
13538 +extern int vc_set_cflags(struct vx_info *, void __user *);
13539 +
13540 +#endif /* __KERNEL__ */
13541 +
13542 +
13543 +/* context caps commands */
13544 +
13545 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
13546 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
13547 +
13548 +struct vcmd_ctx_caps_v1 {
13549 +       uint64_t ccaps;
13550 +       uint64_t cmask;
13551 +};
13552 +
13553 +#ifdef __KERNEL__
13554 +extern int vc_get_ccaps(struct vx_info *, void __user *);
13555 +extern int vc_set_ccaps(struct vx_info *, void __user *);
13556 +
13557 +#endif /* __KERNEL__ */
13558 +
13559 +
13560 +/* bcaps commands */
13561 +
13562 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
13563 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
13564 +
13565 +struct vcmd_bcaps {
13566 +       uint64_t bcaps;
13567 +       uint64_t bmask;
13568 +};
13569 +
13570 +#ifdef __KERNEL__
13571 +extern int vc_get_bcaps(struct vx_info *, void __user *);
13572 +extern int vc_set_bcaps(struct vx_info *, void __user *);
13573 +
13574 +#endif /* __KERNEL__ */
13575 +
13576 +
13577 +/* umask commands */
13578 +
13579 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
13580 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
13581 +
13582 +struct vcmd_umask {
13583 +       uint64_t umask;
13584 +       uint64_t mask;
13585 +};
13586 +
13587 +#ifdef __KERNEL__
13588 +extern int vc_get_umask(struct vx_info *, void __user *);
13589 +extern int vc_set_umask(struct vx_info *, void __user *);
13590 +
13591 +#endif /* __KERNEL__ */
13592 +
13593 +
13594 +/* OOM badness */
13595 +
13596 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
13597 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
13598 +
13599 +struct vcmd_badness_v0 {
13600 +       int64_t bias;
13601 +};
13602 +
13603 +#ifdef __KERNEL__
13604 +extern int vc_get_badness(struct vx_info *, void __user *);
13605 +extern int vc_set_badness(struct vx_info *, void __user *);
13606 +
13607 +#endif /* __KERNEL__ */
13608 +#endif /* _VX_CONTEXT_CMD_H */
13609 diff -NurpP --minimal linux-3.0/include/linux/vserver/cvirt.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/cvirt.h
13610 --- linux-3.0/include/linux/vserver/cvirt.h     1970-01-01 01:00:00.000000000 +0100
13611 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/cvirt.h        2011-06-10 22:11:24.000000000 +0200
13612 @@ -0,0 +1,20 @@
13613 +#ifndef _VX_CVIRT_H
13614 +#define _VX_CVIRT_H
13615 +
13616 +
13617 +#ifdef __KERNEL__
13618 +
13619 +struct timespec;
13620 +
13621 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13622 +
13623 +
13624 +struct vx_info;
13625 +
13626 +void vx_update_load(struct vx_info *);
13627 +
13628 +
13629 +int vx_do_syslog(int, char __user *, int);
13630 +
13631 +#endif /* __KERNEL__ */
13632 +#endif /* _VX_CVIRT_H */
13633 diff -NurpP --minimal linux-3.0/include/linux/vserver/cvirt_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/cvirt_cmd.h
13634 --- linux-3.0/include/linux/vserver/cvirt_cmd.h 1970-01-01 01:00:00.000000000 +0100
13635 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/cvirt_cmd.h    2011-06-10 22:11:24.000000000 +0200
13636 @@ -0,0 +1,53 @@
13637 +#ifndef _VX_CVIRT_CMD_H
13638 +#define _VX_CVIRT_CMD_H
13639 +
13640 +
13641 +/* virtual host info name commands */
13642 +
13643 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
13644 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
13645 +
13646 +struct vcmd_vhi_name_v0 {
13647 +       uint32_t field;
13648 +       char name[65];
13649 +};
13650 +
13651 +
13652 +enum vhi_name_field {
13653 +       VHIN_CONTEXT = 0,
13654 +       VHIN_SYSNAME,
13655 +       VHIN_NODENAME,
13656 +       VHIN_RELEASE,
13657 +       VHIN_VERSION,
13658 +       VHIN_MACHINE,
13659 +       VHIN_DOMAINNAME,
13660 +};
13661 +
13662 +
13663 +#ifdef __KERNEL__
13664 +
13665 +#include <linux/compiler.h>
13666 +
13667 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
13668 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
13669 +
13670 +#endif /* __KERNEL__ */
13671 +
13672 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
13673 +
13674 +struct vcmd_virt_stat_v0 {
13675 +       uint64_t offset;
13676 +       uint64_t uptime;
13677 +       uint32_t nr_threads;
13678 +       uint32_t nr_running;
13679 +       uint32_t nr_uninterruptible;
13680 +       uint32_t nr_onhold;
13681 +       uint32_t nr_forks;
13682 +       uint32_t load[3];
13683 +};
13684 +
13685 +#ifdef __KERNEL__
13686 +extern int vc_virt_stat(struct vx_info *, void __user *);
13687 +
13688 +#endif /* __KERNEL__ */
13689 +#endif /* _VX_CVIRT_CMD_H */
13690 diff -NurpP --minimal linux-3.0/include/linux/vserver/cvirt_def.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/cvirt_def.h
13691 --- linux-3.0/include/linux/vserver/cvirt_def.h 1970-01-01 01:00:00.000000000 +0100
13692 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/cvirt_def.h    2011-06-10 22:11:24.000000000 +0200
13693 @@ -0,0 +1,80 @@
13694 +#ifndef _VX_CVIRT_DEF_H
13695 +#define _VX_CVIRT_DEF_H
13696 +
13697 +#include <linux/jiffies.h>
13698 +#include <linux/spinlock.h>
13699 +#include <linux/wait.h>
13700 +#include <linux/time.h>
13701 +#include <asm/atomic.h>
13702 +
13703 +
13704 +struct _vx_usage_stat {
13705 +       uint64_t user;
13706 +       uint64_t nice;
13707 +       uint64_t system;
13708 +       uint64_t softirq;
13709 +       uint64_t irq;
13710 +       uint64_t idle;
13711 +       uint64_t iowait;
13712 +};
13713 +
13714 +struct _vx_syslog {
13715 +       wait_queue_head_t log_wait;
13716 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
13717 +
13718 +       unsigned long log_start;        /* next char to be read by syslog() */
13719 +       unsigned long con_start;        /* next char to be sent to consoles */
13720 +       unsigned long log_end;  /* most-recently-written-char + 1 */
13721 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
13722 +
13723 +       char log_buf[1024];
13724 +};
13725 +
13726 +
13727 +/* context sub struct */
13728 +
13729 +struct _vx_cvirt {
13730 +       atomic_t nr_threads;            /* number of current threads */
13731 +       atomic_t nr_running;            /* number of running threads */
13732 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
13733 +
13734 +       atomic_t nr_onhold;             /* processes on hold */
13735 +       uint32_t onhold_last;           /* jiffies when put on hold */
13736 +
13737 +       struct timespec bias_ts;        /* time offset to the host */
13738 +       struct timespec bias_idle;
13739 +       struct timespec bias_uptime;    /* context creation point */
13740 +       uint64_t bias_clock;            /* offset in clock_t */
13741 +
13742 +       spinlock_t load_lock;           /* lock for the load averages */
13743 +       atomic_t load_updates;          /* nr of load updates done so far */
13744 +       uint32_t load_last;             /* last time load was calculated */
13745 +       uint32_t load[3];               /* load averages 1,5,15 */
13746 +
13747 +       atomic_t total_forks;           /* number of forks so far */
13748 +
13749 +       struct _vx_syslog syslog;
13750 +};
13751 +
13752 +struct _vx_cvirt_pc {
13753 +       struct _vx_usage_stat cpustat;
13754 +};
13755 +
13756 +
13757 +#ifdef CONFIG_VSERVER_DEBUG
13758 +
13759 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
13760 +{
13761 +       printk("\t_vx_cvirt:\n");
13762 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
13763 +               atomic_read(&cvirt->nr_threads),
13764 +               atomic_read(&cvirt->nr_running),
13765 +               atomic_read(&cvirt->nr_uninterruptible),
13766 +               atomic_read(&cvirt->nr_onhold));
13767 +       /* add rest here */
13768 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
13769 +}
13770 +
13771 +#endif
13772 +
13773 +#endif /* _VX_CVIRT_DEF_H */
13774 diff -NurpP --minimal linux-3.0/include/linux/vserver/debug.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/debug.h
13775 --- linux-3.0/include/linux/vserver/debug.h     1970-01-01 01:00:00.000000000 +0100
13776 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/debug.h        2011-06-10 22:11:24.000000000 +0200
13777 @@ -0,0 +1,140 @@
13778 +#ifndef _VX_DEBUG_H
13779 +#define _VX_DEBUG_H
13780 +
13781 +
13782 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
13783 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
13784 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
13785 +
13786 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
13787 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
13788 +#define VXF_DEV                "%p[%lu,%d:%d]"
13789 +
13790 +#if    defined(CONFIG_QUOTES_UTF8)
13791 +#define        VS_Q_LQM        "\xc2\xbb"
13792 +#define        VS_Q_RQM        "\xc2\xab"
13793 +#elif  defined(CONFIG_QUOTES_ASCII)
13794 +#define        VS_Q_LQM        "\x27"
13795 +#define        VS_Q_RQM        "\x27"
13796 +#else
13797 +#define        VS_Q_LQM        "\xbb"
13798 +#define        VS_Q_RQM        "\xab"
13799 +#endif
13800 +
13801 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
13802 +
13803 +
13804 +#define vxd_path(p)                                            \
13805 +       ({ static char _buffer[PATH_MAX];                       \
13806 +          d_path(p, _buffer, sizeof(_buffer)); })
13807 +
13808 +#define vxd_cond_path(n)                                       \
13809 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
13810 +
13811 +
13812 +#ifdef CONFIG_VSERVER_DEBUG
13813 +
13814 +extern unsigned int vx_debug_switch;
13815 +extern unsigned int vx_debug_xid;
13816 +extern unsigned int vx_debug_nid;
13817 +extern unsigned int vx_debug_tag;
13818 +extern unsigned int vx_debug_net;
13819 +extern unsigned int vx_debug_limit;
13820 +extern unsigned int vx_debug_cres;
13821 +extern unsigned int vx_debug_dlim;
13822 +extern unsigned int vx_debug_quota;
13823 +extern unsigned int vx_debug_cvirt;
13824 +extern unsigned int vx_debug_space;
13825 +extern unsigned int vx_debug_misc;
13826 +
13827 +
13828 +#define VX_LOGLEVEL    "vxD: "
13829 +#define VX_PROC_FMT    "%p: "
13830 +#define VX_PROCESS     current
13831 +
13832 +#define vxdprintk(c, f, x...)                                  \
13833 +       do {                                                    \
13834 +               if (c)                                          \
13835 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
13836 +                               VX_PROCESS , ##x);              \
13837 +       } while (0)
13838 +
13839 +#define vxlprintk(c, f, x...)                                  \
13840 +       do {                                                    \
13841 +               if (c)                                          \
13842 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
13843 +       } while (0)
13844 +
13845 +#define vxfprintk(c, f, x...)                                  \
13846 +       do {                                                    \
13847 +               if (c)                                          \
13848 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
13849 +       } while (0)
13850 +
13851 +
13852 +struct vx_info;
13853 +
13854 +void dump_vx_info(struct vx_info *, int);
13855 +void dump_vx_info_inactive(int);
13856 +
13857 +#else  /* CONFIG_VSERVER_DEBUG */
13858 +
13859 +#define vx_debug_switch 0
13860 +#define vx_debug_xid   0
13861 +#define vx_debug_nid   0
13862 +#define vx_debug_tag   0
13863 +#define vx_debug_net   0
13864 +#define vx_debug_limit 0
13865 +#define vx_debug_cres  0
13866 +#define vx_debug_dlim  0
13867 +#define vx_debug_cvirt 0
13868 +
13869 +#define vxdprintk(x...) do { } while (0)
13870 +#define vxlprintk(x...) do { } while (0)
13871 +#define vxfprintk(x...) do { } while (0)
13872 +
13873 +#endif /* CONFIG_VSERVER_DEBUG */
13874 +
13875 +
13876 +#ifdef CONFIG_VSERVER_WARN
13877 +
13878 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
13879 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
13880 +#define VX_WARN_XID    "[xid #%u] "
13881 +#define VX_WARN_NID    "[nid #%u] "
13882 +#define VX_WARN_TAG    "[tag #%u] "
13883 +
13884 +#define vxwprintk(c, f, x...)                                  \
13885 +       do {                                                    \
13886 +               if (c)                                          \
13887 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
13888 +       } while (0)
13889 +
13890 +#else  /* CONFIG_VSERVER_WARN */
13891 +
13892 +#define vxwprintk(x...) do { } while (0)
13893 +
13894 +#endif /* CONFIG_VSERVER_WARN */
13895 +
13896 +#define vxwprintk_task(c, f, x...)                             \
13897 +       vxwprintk(c, VX_WARN_TASK f,                            \
13898 +               current->comm, current->pid,                    \
13899 +               current->xid, current->nid, current->tag, ##x)
13900 +#define vxwprintk_xid(c, f, x...)                              \
13901 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
13902 +#define vxwprintk_nid(c, f, x...)                              \
13903 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
13904 +#define vxwprintk_tag(c, f, x...)                              \
13905 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
13906 +
13907 +#ifdef CONFIG_VSERVER_DEBUG
13908 +#define vxd_assert_lock(l)     assert_spin_locked(l)
13909 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
13910 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
13911 +#else
13912 +#define vxd_assert_lock(l)     do { } while (0)
13913 +#define vxd_assert(c, f, x...) do { } while (0)
13914 +#endif
13915 +
13916 +
13917 +#endif /* _VX_DEBUG_H */
13918 diff -NurpP --minimal linux-3.0/include/linux/vserver/debug_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/debug_cmd.h
13919 --- linux-3.0/include/linux/vserver/debug_cmd.h 1970-01-01 01:00:00.000000000 +0100
13920 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/debug_cmd.h    2011-06-10 22:11:24.000000000 +0200
13921 @@ -0,0 +1,58 @@
13922 +#ifndef _VX_DEBUG_CMD_H
13923 +#define _VX_DEBUG_CMD_H
13924 +
13925 +
13926 +/* debug commands */
13927 +
13928 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
13929 +
13930 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
13931 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
13932 +
13933 +struct  vcmd_read_history_v0 {
13934 +       uint32_t index;
13935 +       uint32_t count;
13936 +       char __user *data;
13937 +};
13938 +
13939 +struct  vcmd_read_monitor_v0 {
13940 +       uint32_t index;
13941 +       uint32_t count;
13942 +       char __user *data;
13943 +};
13944 +
13945 +
13946 +#ifdef __KERNEL__
13947 +
13948 +#ifdef CONFIG_COMPAT
13949 +
13950 +#include <asm/compat.h>
13951 +
13952 +struct vcmd_read_history_v0_x32 {
13953 +       uint32_t index;
13954 +       uint32_t count;
13955 +       compat_uptr_t data_ptr;
13956 +};
13957 +
13958 +struct vcmd_read_monitor_v0_x32 {
13959 +       uint32_t index;
13960 +       uint32_t count;
13961 +       compat_uptr_t data_ptr;
13962 +};
13963 +
13964 +#endif  /* CONFIG_COMPAT */
13965 +
13966 +extern int vc_dump_history(uint32_t);
13967 +
13968 +extern int vc_read_history(uint32_t, void __user *);
13969 +extern int vc_read_monitor(uint32_t, void __user *);
13970 +
13971 +#ifdef CONFIG_COMPAT
13972 +
13973 +extern int vc_read_history_x32(uint32_t, void __user *);
13974 +extern int vc_read_monitor_x32(uint32_t, void __user *);
13975 +
13976 +#endif  /* CONFIG_COMPAT */
13977 +
13978 +#endif /* __KERNEL__ */
13979 +#endif /* _VX_DEBUG_CMD_H */
13980 diff -NurpP --minimal linux-3.0/include/linux/vserver/device.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/device.h
13981 --- linux-3.0/include/linux/vserver/device.h    1970-01-01 01:00:00.000000000 +0100
13982 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/device.h       2011-06-10 22:11:24.000000000 +0200
13983 @@ -0,0 +1,15 @@
13984 +#ifndef _VX_DEVICE_H
13985 +#define _VX_DEVICE_H
13986 +
13987 +
13988 +#define DATTR_CREATE   0x00000001
13989 +#define DATTR_OPEN     0x00000002
13990 +
13991 +#define DATTR_REMAP    0x00000010
13992 +
13993 +#define DATTR_MASK     0x00000013
13994 +
13995 +
13996 +#else  /* _VX_DEVICE_H */
13997 +#warning duplicate inclusion
13998 +#endif /* _VX_DEVICE_H */
13999 diff -NurpP --minimal linux-3.0/include/linux/vserver/device_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/device_cmd.h
14000 --- linux-3.0/include/linux/vserver/device_cmd.h        1970-01-01 01:00:00.000000000 +0100
14001 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/device_cmd.h   2011-06-10 22:11:24.000000000 +0200
14002 @@ -0,0 +1,44 @@
14003 +#ifndef _VX_DEVICE_CMD_H
14004 +#define _VX_DEVICE_CMD_H
14005 +
14006 +
14007 +/*  device vserver commands */
14008 +
14009 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
14010 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
14011 +
14012 +struct vcmd_set_mapping_v0 {
14013 +       const char __user *device;
14014 +       const char __user *target;
14015 +       uint32_t flags;
14016 +};
14017 +
14018 +
14019 +#ifdef __KERNEL__
14020 +
14021 +#ifdef CONFIG_COMPAT
14022 +
14023 +#include <asm/compat.h>
14024 +
14025 +struct vcmd_set_mapping_v0_x32 {
14026 +       compat_uptr_t device_ptr;
14027 +       compat_uptr_t target_ptr;
14028 +       uint32_t flags;
14029 +};
14030 +
14031 +#endif /* CONFIG_COMPAT */
14032 +
14033 +#include <linux/compiler.h>
14034 +
14035 +extern int vc_set_mapping(struct vx_info *, void __user *);
14036 +extern int vc_unset_mapping(struct vx_info *, void __user *);
14037 +
14038 +#ifdef CONFIG_COMPAT
14039 +
14040 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
14041 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
14042 +
14043 +#endif /* CONFIG_COMPAT */
14044 +
14045 +#endif /* __KERNEL__ */
14046 +#endif /* _VX_DEVICE_CMD_H */
14047 diff -NurpP --minimal linux-3.0/include/linux/vserver/device_def.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/device_def.h
14048 --- linux-3.0/include/linux/vserver/device_def.h        1970-01-01 01:00:00.000000000 +0100
14049 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/device_def.h   2011-06-10 22:11:24.000000000 +0200
14050 @@ -0,0 +1,17 @@
14051 +#ifndef _VX_DEVICE_DEF_H
14052 +#define _VX_DEVICE_DEF_H
14053 +
14054 +#include <linux/types.h>
14055 +
14056 +struct vx_dmap_target {
14057 +       dev_t target;
14058 +       uint32_t flags;
14059 +};
14060 +
14061 +struct _vx_device {
14062 +#ifdef CONFIG_VSERVER_DEVICE
14063 +       struct vx_dmap_target targets[2];
14064 +#endif
14065 +};
14066 +
14067 +#endif /* _VX_DEVICE_DEF_H */
14068 diff -NurpP --minimal linux-3.0/include/linux/vserver/dlimit.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/dlimit.h
14069 --- linux-3.0/include/linux/vserver/dlimit.h    1970-01-01 01:00:00.000000000 +0100
14070 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/dlimit.h       2011-06-10 22:11:24.000000000 +0200
14071 @@ -0,0 +1,54 @@
14072 +#ifndef _VX_DLIMIT_H
14073 +#define _VX_DLIMIT_H
14074 +
14075 +#include "switch.h"
14076 +
14077 +
14078 +#ifdef __KERNEL__
14079 +
14080 +/*      keep in sync with CDLIM_INFINITY       */
14081 +
14082 +#define DLIM_INFINITY          (~0ULL)
14083 +
14084 +#include <linux/spinlock.h>
14085 +#include <linux/rcupdate.h>
14086 +
14087 +struct super_block;
14088 +
14089 +struct dl_info {
14090 +       struct hlist_node dl_hlist;             /* linked list of contexts */
14091 +       struct rcu_head dl_rcu;                 /* the rcu head */
14092 +       tag_t dl_tag;                           /* context tag */
14093 +       atomic_t dl_usecnt;                     /* usage count */
14094 +       atomic_t dl_refcnt;                     /* reference count */
14095 +
14096 +       struct super_block *dl_sb;              /* associated superblock */
14097 +
14098 +       spinlock_t dl_lock;                     /* protect the values */
14099 +
14100 +       unsigned long long dl_space_used;       /* used space in bytes */
14101 +       unsigned long long dl_space_total;      /* maximum space in bytes */
14102 +       unsigned long dl_inodes_used;           /* used inodes */
14103 +       unsigned long dl_inodes_total;          /* maximum inodes */
14104 +
14105 +       unsigned int dl_nrlmult;                /* non root limit mult */
14106 +};
14107 +
14108 +struct rcu_head;
14109 +
14110 +extern void rcu_free_dl_info(struct rcu_head *);
14111 +extern void unhash_dl_info(struct dl_info *);
14112 +
14113 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
14114 +
14115 +
14116 +struct kstatfs;
14117 +
14118 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
14119 +
14120 +typedef uint64_t dlsize_t;
14121 +
14122 +#endif /* __KERNEL__ */
14123 +#else  /* _VX_DLIMIT_H */
14124 +#warning duplicate inclusion
14125 +#endif /* _VX_DLIMIT_H */
14126 diff -NurpP --minimal linux-3.0/include/linux/vserver/dlimit_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/dlimit_cmd.h
14127 --- linux-3.0/include/linux/vserver/dlimit_cmd.h        1970-01-01 01:00:00.000000000 +0100
14128 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/dlimit_cmd.h   2011-06-10 22:11:24.000000000 +0200
14129 @@ -0,0 +1,109 @@
14130 +#ifndef _VX_DLIMIT_CMD_H
14131 +#define _VX_DLIMIT_CMD_H
14132 +
14133 +
14134 +/*  dlimit vserver commands */
14135 +
14136 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
14137 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
14138 +
14139 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
14140 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
14141 +
14142 +struct vcmd_ctx_dlimit_base_v0 {
14143 +       const char __user *name;
14144 +       uint32_t flags;
14145 +};
14146 +
14147 +struct vcmd_ctx_dlimit_v0 {
14148 +       const char __user *name;
14149 +       uint32_t space_used;                    /* used space in kbytes */
14150 +       uint32_t space_total;                   /* maximum space in kbytes */
14151 +       uint32_t inodes_used;                   /* used inodes */
14152 +       uint32_t inodes_total;                  /* maximum inodes */
14153 +       uint32_t reserved;                      /* reserved for root in % */
14154 +       uint32_t flags;
14155 +};
14156 +
14157 +#define CDLIM_UNSET            ((uint32_t)0UL)
14158 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
14159 +#define CDLIM_KEEP             ((uint32_t)~1UL)
14160 +
14161 +#define DLIME_UNIT     0
14162 +#define DLIME_KILO     1
14163 +#define DLIME_MEGA     2
14164 +#define DLIME_GIGA     3
14165 +
14166 +#define DLIMF_SHIFT    0x10
14167 +
14168 +#define DLIMS_USED     0
14169 +#define DLIMS_TOTAL    2
14170 +
14171 +static inline
14172 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
14173 +{
14174 +       int exp = (flags & DLIMF_SHIFT) ?
14175 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
14176 +       return ((uint64_t)val) << (10 * exp);
14177 +}
14178 +
14179 +static inline
14180 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
14181 +{
14182 +       int exp = 0;
14183 +
14184 +       if (*flags & DLIMF_SHIFT) {
14185 +               while (val > (1LL << 32) && (exp < 3)) {
14186 +                       val >>= 10;
14187 +                       exp++;
14188 +               }
14189 +               *flags &= ~(DLIME_GIGA << shift);
14190 +               *flags |= exp << shift;
14191 +       } else
14192 +               val >>= 10;
14193 +       return val;
14194 +}
14195 +
14196 +#ifdef __KERNEL__
14197 +
14198 +#ifdef CONFIG_COMPAT
14199 +
14200 +#include <asm/compat.h>
14201 +
14202 +struct vcmd_ctx_dlimit_base_v0_x32 {
14203 +       compat_uptr_t name_ptr;
14204 +       uint32_t flags;
14205 +};
14206 +
14207 +struct vcmd_ctx_dlimit_v0_x32 {
14208 +       compat_uptr_t name_ptr;
14209 +       uint32_t space_used;                    /* used space in kbytes */
14210 +       uint32_t space_total;                   /* maximum space in kbytes */
14211 +       uint32_t inodes_used;                   /* used inodes */
14212 +       uint32_t inodes_total;                  /* maximum inodes */
14213 +       uint32_t reserved;                      /* reserved for root in % */
14214 +       uint32_t flags;
14215 +};
14216 +
14217 +#endif /* CONFIG_COMPAT */
14218 +
14219 +#include <linux/compiler.h>
14220 +
14221 +extern int vc_add_dlimit(uint32_t, void __user *);
14222 +extern int vc_rem_dlimit(uint32_t, void __user *);
14223 +
14224 +extern int vc_set_dlimit(uint32_t, void __user *);
14225 +extern int vc_get_dlimit(uint32_t, void __user *);
14226 +
14227 +#ifdef CONFIG_COMPAT
14228 +
14229 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
14230 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
14231 +
14232 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
14233 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
14234 +
14235 +#endif /* CONFIG_COMPAT */
14236 +
14237 +#endif /* __KERNEL__ */
14238 +#endif /* _VX_DLIMIT_CMD_H */
14239 diff -NurpP --minimal linux-3.0/include/linux/vserver/global.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/global.h
14240 --- linux-3.0/include/linux/vserver/global.h    1970-01-01 01:00:00.000000000 +0100
14241 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/global.h       2011-06-10 22:11:24.000000000 +0200
14242 @@ -0,0 +1,19 @@
14243 +#ifndef _VX_GLOBAL_H
14244 +#define _VX_GLOBAL_H
14245 +
14246 +
14247 +extern atomic_t vx_global_ctotal;
14248 +extern atomic_t vx_global_cactive;
14249 +
14250 +extern atomic_t nx_global_ctotal;
14251 +extern atomic_t nx_global_cactive;
14252 +
14253 +extern atomic_t vs_global_nsproxy;
14254 +extern atomic_t vs_global_fs;
14255 +extern atomic_t vs_global_mnt_ns;
14256 +extern atomic_t vs_global_uts_ns;
14257 +extern atomic_t vs_global_user_ns;
14258 +extern atomic_t vs_global_pid_ns;
14259 +
14260 +
14261 +#endif /* _VX_GLOBAL_H */
14262 diff -NurpP --minimal linux-3.0/include/linux/vserver/history.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/history.h
14263 --- linux-3.0/include/linux/vserver/history.h   1970-01-01 01:00:00.000000000 +0100
14264 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/history.h      2011-06-10 22:11:24.000000000 +0200
14265 @@ -0,0 +1,197 @@
14266 +#ifndef _VX_HISTORY_H
14267 +#define _VX_HISTORY_H
14268 +
14269 +
14270 +enum {
14271 +       VXH_UNUSED = 0,
14272 +       VXH_THROW_OOPS = 1,
14273 +
14274 +       VXH_GET_VX_INFO,
14275 +       VXH_PUT_VX_INFO,
14276 +       VXH_INIT_VX_INFO,
14277 +       VXH_SET_VX_INFO,
14278 +       VXH_CLR_VX_INFO,
14279 +       VXH_CLAIM_VX_INFO,
14280 +       VXH_RELEASE_VX_INFO,
14281 +       VXH_ALLOC_VX_INFO,
14282 +       VXH_DEALLOC_VX_INFO,
14283 +       VXH_HASH_VX_INFO,
14284 +       VXH_UNHASH_VX_INFO,
14285 +       VXH_LOC_VX_INFO,
14286 +       VXH_LOOKUP_VX_INFO,
14287 +       VXH_CREATE_VX_INFO,
14288 +};
14289 +
14290 +struct _vxhe_vxi {
14291 +       struct vx_info *ptr;
14292 +       unsigned xid;
14293 +       unsigned usecnt;
14294 +       unsigned tasks;
14295 +};
14296 +
14297 +struct _vxhe_set_clr {
14298 +       void *data;
14299 +};
14300 +
14301 +struct _vxhe_loc_lookup {
14302 +       unsigned arg;
14303 +};
14304 +
14305 +struct _vx_hist_entry {
14306 +       void *loc;
14307 +       unsigned short seq;
14308 +       unsigned short type;
14309 +       struct _vxhe_vxi vxi;
14310 +       union {
14311 +               struct _vxhe_set_clr sc;
14312 +               struct _vxhe_loc_lookup ll;
14313 +       };
14314 +};
14315 +
14316 +#ifdef CONFIG_VSERVER_HISTORY
14317 +
14318 +extern unsigned volatile int vxh_active;
14319 +
14320 +struct _vx_hist_entry *vxh_advance(void *loc);
14321 +
14322 +
14323 +static inline
14324 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
14325 +{
14326 +       entry->vxi.ptr = vxi;
14327 +       if (vxi) {
14328 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
14329 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
14330 +               entry->vxi.xid = vxi->vx_id;
14331 +       }
14332 +}
14333 +
14334 +
14335 +#define        __HERE__ current_text_addr()
14336 +
14337 +#define __VXH_BODY(__type, __data, __here)     \
14338 +       struct _vx_hist_entry *entry;           \
14339 +                                               \
14340 +       preempt_disable();                      \
14341 +       entry = vxh_advance(__here);            \
14342 +       __data;                                 \
14343 +       entry->type = __type;                   \
14344 +       preempt_enable();
14345 +
14346 +
14347 +       /* pass vxi only */
14348 +
14349 +#define __VXH_SMPL                             \
14350 +       __vxh_copy_vxi(entry, vxi)
14351 +
14352 +static inline
14353 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
14354 +{
14355 +       __VXH_BODY(__type, __VXH_SMPL, __here)
14356 +}
14357 +
14358 +       /* pass vxi and data (void *) */
14359 +
14360 +#define __VXH_DATA                             \
14361 +       __vxh_copy_vxi(entry, vxi);             \
14362 +       entry->sc.data = data
14363 +
14364 +static inline
14365 +void   __vxh_data(struct vx_info *vxi, void *data,
14366 +                       int __type, void *__here)
14367 +{
14368 +       __VXH_BODY(__type, __VXH_DATA, __here)
14369 +}
14370 +
14371 +       /* pass vxi and arg (long) */
14372 +
14373 +#define __VXH_LONG                             \
14374 +       __vxh_copy_vxi(entry, vxi);             \
14375 +       entry->ll.arg = arg
14376 +
14377 +static inline
14378 +void   __vxh_long(struct vx_info *vxi, long arg,
14379 +                       int __type, void *__here)
14380 +{
14381 +       __VXH_BODY(__type, __VXH_LONG, __here)
14382 +}
14383 +
14384 +
14385 +static inline
14386 +void   __vxh_throw_oops(void *__here)
14387 +{
14388 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
14389 +       /* prevent further acquisition */
14390 +       vxh_active = 0;
14391 +}
14392 +
14393 +
14394 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
14395 +
14396 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
14397 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
14398 +
14399 +#define __vxh_init_vx_info(v, d, h) \
14400 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
14401 +#define __vxh_set_vx_info(v, d, h) \
14402 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
14403 +#define __vxh_clr_vx_info(v, d, h) \
14404 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
14405 +
14406 +#define __vxh_claim_vx_info(v, d, h) \
14407 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
14408 +#define __vxh_release_vx_info(v, d, h) \
14409 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
14410 +
14411 +#define vxh_alloc_vx_info(v) \
14412 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
14413 +#define vxh_dealloc_vx_info(v) \
14414 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
14415 +
14416 +#define vxh_hash_vx_info(v) \
14417 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
14418 +#define vxh_unhash_vx_info(v) \
14419 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
14420 +
14421 +#define vxh_loc_vx_info(v, l) \
14422 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
14423 +#define vxh_lookup_vx_info(v, l) \
14424 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
14425 +#define vxh_create_vx_info(v, l) \
14426 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
14427 +
14428 +extern void vxh_dump_history(void);
14429 +
14430 +
14431 +#else  /* CONFIG_VSERVER_HISTORY */
14432 +
14433 +#define        __HERE__        0
14434 +
14435 +#define vxh_throw_oops()               do { } while (0)
14436 +
14437 +#define __vxh_get_vx_info(v, h)                do { } while (0)
14438 +#define __vxh_put_vx_info(v, h)                do { } while (0)
14439 +
14440 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
14441 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
14442 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
14443 +
14444 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
14445 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
14446 +
14447 +#define vxh_alloc_vx_info(v)           do { } while (0)
14448 +#define vxh_dealloc_vx_info(v)         do { } while (0)
14449 +
14450 +#define vxh_hash_vx_info(v)            do { } while (0)
14451 +#define vxh_unhash_vx_info(v)          do { } while (0)
14452 +
14453 +#define vxh_loc_vx_info(v, l)          do { } while (0)
14454 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
14455 +#define vxh_create_vx_info(v, l)       do { } while (0)
14456 +
14457 +#define vxh_dump_history()             do { } while (0)
14458 +
14459 +
14460 +#endif /* CONFIG_VSERVER_HISTORY */
14461 +
14462 +#endif /* _VX_HISTORY_H */
14463 diff -NurpP --minimal linux-3.0/include/linux/vserver/inode.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/inode.h
14464 --- linux-3.0/include/linux/vserver/inode.h     1970-01-01 01:00:00.000000000 +0100
14465 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/inode.h        2011-06-10 22:11:24.000000000 +0200
14466 @@ -0,0 +1,39 @@
14467 +#ifndef _VX_INODE_H
14468 +#define _VX_INODE_H
14469 +
14470 +
14471 +#define IATTR_TAG      0x01000000
14472 +
14473 +#define IATTR_ADMIN    0x00000001
14474 +#define IATTR_WATCH    0x00000002
14475 +#define IATTR_HIDE     0x00000004
14476 +#define IATTR_FLAGS    0x00000007
14477 +
14478 +#define IATTR_BARRIER  0x00010000
14479 +#define IATTR_IXUNLINK 0x00020000
14480 +#define IATTR_IMMUTABLE 0x00040000
14481 +#define IATTR_COW      0x00080000
14482 +
14483 +#ifdef __KERNEL__
14484 +
14485 +
14486 +#ifdef CONFIG_VSERVER_PROC_SECURE
14487 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
14488 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14489 +#else
14490 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
14491 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14492 +#endif
14493 +
14494 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
14495 +
14496 +#endif /* __KERNEL__ */
14497 +
14498 +/* inode ioctls */
14499 +
14500 +#define FIOC_GETXFLG   _IOR('x', 5, long)
14501 +#define FIOC_SETXFLG   _IOW('x', 6, long)
14502 +
14503 +#else  /* _VX_INODE_H */
14504 +#warning duplicate inclusion
14505 +#endif /* _VX_INODE_H */
14506 diff -NurpP --minimal linux-3.0/include/linux/vserver/inode_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/inode_cmd.h
14507 --- linux-3.0/include/linux/vserver/inode_cmd.h 1970-01-01 01:00:00.000000000 +0100
14508 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/inode_cmd.h    2011-06-10 22:11:24.000000000 +0200
14509 @@ -0,0 +1,59 @@
14510 +#ifndef _VX_INODE_CMD_H
14511 +#define _VX_INODE_CMD_H
14512 +
14513 +
14514 +/*  inode vserver commands */
14515 +
14516 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
14517 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
14518 +
14519 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
14520 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
14521 +
14522 +struct vcmd_ctx_iattr_v1 {
14523 +       const char __user *name;
14524 +       uint32_t tag;
14525 +       uint32_t flags;
14526 +       uint32_t mask;
14527 +};
14528 +
14529 +struct vcmd_ctx_fiattr_v0 {
14530 +       uint32_t tag;
14531 +       uint32_t flags;
14532 +       uint32_t mask;
14533 +};
14534 +
14535 +
14536 +#ifdef __KERNEL__
14537 +
14538 +
14539 +#ifdef CONFIG_COMPAT
14540 +
14541 +#include <asm/compat.h>
14542 +
14543 +struct vcmd_ctx_iattr_v1_x32 {
14544 +       compat_uptr_t name_ptr;
14545 +       uint32_t tag;
14546 +       uint32_t flags;
14547 +       uint32_t mask;
14548 +};
14549 +
14550 +#endif /* CONFIG_COMPAT */
14551 +
14552 +#include <linux/compiler.h>
14553 +
14554 +extern int vc_get_iattr(void __user *);
14555 +extern int vc_set_iattr(void __user *);
14556 +
14557 +extern int vc_fget_iattr(uint32_t, void __user *);
14558 +extern int vc_fset_iattr(uint32_t, void __user *);
14559 +
14560 +#ifdef CONFIG_COMPAT
14561 +
14562 +extern int vc_get_iattr_x32(void __user *);
14563 +extern int vc_set_iattr_x32(void __user *);
14564 +
14565 +#endif /* CONFIG_COMPAT */
14566 +
14567 +#endif /* __KERNEL__ */
14568 +#endif /* _VX_INODE_CMD_H */
14569 diff -NurpP --minimal linux-3.0/include/linux/vserver/limit.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/limit.h
14570 --- linux-3.0/include/linux/vserver/limit.h     1970-01-01 01:00:00.000000000 +0100
14571 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/limit.h        2011-06-10 22:11:24.000000000 +0200
14572 @@ -0,0 +1,71 @@
14573 +#ifndef _VX_LIMIT_H
14574 +#define _VX_LIMIT_H
14575 +
14576 +#define VLIMIT_NSOCK   16
14577 +#define VLIMIT_OPENFD  17
14578 +#define VLIMIT_ANON    18
14579 +#define VLIMIT_SHMEM   19
14580 +#define VLIMIT_SEMARY  20
14581 +#define VLIMIT_NSEMS   21
14582 +#define VLIMIT_DENTRY  22
14583 +#define VLIMIT_MAPPED  23
14584 +
14585 +
14586 +#ifdef __KERNEL__
14587 +
14588 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
14589 +
14590 +/*     keep in sync with CRLIM_INFINITY */
14591 +
14592 +#define        VLIM_INFINITY   (~0ULL)
14593 +
14594 +#include <asm/atomic.h>
14595 +#include <asm/resource.h>
14596 +
14597 +#ifndef RLIM_INFINITY
14598 +#warning RLIM_INFINITY is undefined
14599 +#endif
14600 +
14601 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
14602 +
14603 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
14604 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
14605 +
14606 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
14607 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
14608 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
14609 +
14610 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
14611 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
14612 +
14613 +typedef atomic_long_t rlim_atomic_t;
14614 +typedef unsigned long rlim_t;
14615 +
14616 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
14617 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
14618 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
14619 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
14620 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
14621 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
14622 +
14623 +
14624 +#if    (RLIM_INFINITY == VLIM_INFINITY)
14625 +#define        VX_VLIM(r) ((long long)(long)(r))
14626 +#define        VX_RLIM(v) ((rlim_t)(v))
14627 +#else
14628 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
14629 +               ? VLIM_INFINITY : (long long)(r))
14630 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
14631 +               ? RLIM_INFINITY : (rlim_t)(v))
14632 +#endif
14633 +
14634 +struct sysinfo;
14635 +
14636 +void vx_vsi_meminfo(struct sysinfo *);
14637 +void vx_vsi_swapinfo(struct sysinfo *);
14638 +long vx_vsi_cached(struct sysinfo *);
14639 +
14640 +#define NUM_LIMITS     24
14641 +
14642 +#endif /* __KERNEL__ */
14643 +#endif /* _VX_LIMIT_H */
14644 diff -NurpP --minimal linux-3.0/include/linux/vserver/limit_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/limit_cmd.h
14645 --- linux-3.0/include/linux/vserver/limit_cmd.h 1970-01-01 01:00:00.000000000 +0100
14646 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/limit_cmd.h    2011-06-10 22:11:24.000000000 +0200
14647 @@ -0,0 +1,71 @@
14648 +#ifndef _VX_LIMIT_CMD_H
14649 +#define _VX_LIMIT_CMD_H
14650 +
14651 +
14652 +/*  rlimit vserver commands */
14653 +
14654 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
14655 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
14656 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
14657 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
14658 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
14659 +
14660 +struct vcmd_ctx_rlimit_v0 {
14661 +       uint32_t id;
14662 +       uint64_t minimum;
14663 +       uint64_t softlimit;
14664 +       uint64_t maximum;
14665 +};
14666 +
14667 +struct vcmd_ctx_rlimit_mask_v0 {
14668 +       uint32_t minimum;
14669 +       uint32_t softlimit;
14670 +       uint32_t maximum;
14671 +};
14672 +
14673 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
14674 +
14675 +struct vcmd_rlimit_stat_v0 {
14676 +       uint32_t id;
14677 +       uint32_t hits;
14678 +       uint64_t value;
14679 +       uint64_t minimum;
14680 +       uint64_t maximum;
14681 +};
14682 +
14683 +#define CRLIM_UNSET            (0ULL)
14684 +#define CRLIM_INFINITY         (~0ULL)
14685 +#define CRLIM_KEEP             (~1ULL)
14686 +
14687 +#ifdef __KERNEL__
14688 +
14689 +#ifdef CONFIG_IA32_EMULATION
14690 +
14691 +struct vcmd_ctx_rlimit_v0_x32 {
14692 +       uint32_t id;
14693 +       uint64_t minimum;
14694 +       uint64_t softlimit;
14695 +       uint64_t maximum;
14696 +} __attribute__ ((packed));
14697 +
14698 +#endif /* CONFIG_IA32_EMULATION */
14699 +
14700 +#include <linux/compiler.h>
14701 +
14702 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
14703 +extern int vc_get_rlimit(struct vx_info *, void __user *);
14704 +extern int vc_set_rlimit(struct vx_info *, void __user *);
14705 +extern int vc_reset_hits(struct vx_info *, void __user *);
14706 +extern int vc_reset_minmax(struct vx_info *, void __user *);
14707 +
14708 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
14709 +
14710 +#ifdef CONFIG_IA32_EMULATION
14711 +
14712 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
14713 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
14714 +
14715 +#endif /* CONFIG_IA32_EMULATION */
14716 +
14717 +#endif /* __KERNEL__ */
14718 +#endif /* _VX_LIMIT_CMD_H */
14719 diff -NurpP --minimal linux-3.0/include/linux/vserver/limit_def.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/limit_def.h
14720 --- linux-3.0/include/linux/vserver/limit_def.h 1970-01-01 01:00:00.000000000 +0100
14721 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/limit_def.h    2011-06-10 22:11:24.000000000 +0200
14722 @@ -0,0 +1,47 @@
14723 +#ifndef _VX_LIMIT_DEF_H
14724 +#define _VX_LIMIT_DEF_H
14725 +
14726 +#include <asm/atomic.h>
14727 +#include <asm/resource.h>
14728 +
14729 +#include "limit.h"
14730 +
14731 +
14732 +struct _vx_res_limit {
14733 +       rlim_t soft;            /* Context soft limit */
14734 +       rlim_t hard;            /* Context hard limit */
14735 +
14736 +       rlim_atomic_t rcur;     /* Current value */
14737 +       rlim_t rmin;            /* Context minimum */
14738 +       rlim_t rmax;            /* Context maximum */
14739 +
14740 +       atomic_t lhit;          /* Limit hits */
14741 +};
14742 +
14743 +/* context sub struct */
14744 +
14745 +struct _vx_limit {
14746 +       struct _vx_res_limit res[NUM_LIMITS];
14747 +};
14748 +
14749 +#ifdef CONFIG_VSERVER_DEBUG
14750 +
14751 +static inline void __dump_vx_limit(struct _vx_limit *limit)
14752 +{
14753 +       int i;
14754 +
14755 +       printk("\t_vx_limit:");
14756 +       for (i = 0; i < NUM_LIMITS; i++) {
14757 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
14758 +                       i, (unsigned long)__rlim_get(limit, i),
14759 +                       (unsigned long)__rlim_rmin(limit, i),
14760 +                       (unsigned long)__rlim_rmax(limit, i),
14761 +                       (long)__rlim_soft(limit, i),
14762 +                       (long)__rlim_hard(limit, i),
14763 +                       atomic_read(&__rlim_lhit(limit, i)));
14764 +       }
14765 +}
14766 +
14767 +#endif
14768 +
14769 +#endif /* _VX_LIMIT_DEF_H */
14770 diff -NurpP --minimal linux-3.0/include/linux/vserver/limit_int.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/limit_int.h
14771 --- linux-3.0/include/linux/vserver/limit_int.h 1970-01-01 01:00:00.000000000 +0100
14772 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/limit_int.h    2011-06-10 22:11:24.000000000 +0200
14773 @@ -0,0 +1,198 @@
14774 +#ifndef _VX_LIMIT_INT_H
14775 +#define _VX_LIMIT_INT_H
14776 +
14777 +#include "context.h"
14778 +
14779 +#ifdef __KERNEL__
14780 +
14781 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
14782 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
14783 +
14784 +extern const char *vlimit_name[NUM_LIMITS];
14785 +
14786 +static inline void __vx_acc_cres(struct vx_info *vxi,
14787 +       int res, int dir, void *_data, char *_file, int _line)
14788 +{
14789 +       if (VXD_RCRES_COND(res))
14790 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
14791 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14792 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14793 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
14794 +       if (!vxi)
14795 +               return;
14796 +
14797 +       if (dir > 0)
14798 +               __rlim_inc(&vxi->limit, res);
14799 +       else
14800 +               __rlim_dec(&vxi->limit, res);
14801 +}
14802 +
14803 +static inline void __vx_add_cres(struct vx_info *vxi,
14804 +       int res, int amount, void *_data, char *_file, int _line)
14805 +{
14806 +       if (VXD_RCRES_COND(res))
14807 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
14808 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14809 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14810 +                       amount, _data, _file, _line);
14811 +       if (amount == 0)
14812 +               return;
14813 +       if (!vxi)
14814 +               return;
14815 +       __rlim_add(&vxi->limit, res, amount);
14816 +}
14817 +
14818 +static inline
14819 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
14820 +{
14821 +       int cond = (value > __rlim_rmax(limit, res));
14822 +
14823 +       if (cond)
14824 +               __rlim_rmax(limit, res) = value;
14825 +       return cond;
14826 +}
14827 +
14828 +static inline
14829 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
14830 +{
14831 +       int cond = (value < __rlim_rmin(limit, res));
14832 +
14833 +       if (cond)
14834 +               __rlim_rmin(limit, res) = value;
14835 +       return cond;
14836 +}
14837 +
14838 +static inline
14839 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
14840 +{
14841 +       if (!__vx_cres_adjust_max(limit, res, value))
14842 +               __vx_cres_adjust_min(limit, res, value);
14843 +}
14844 +
14845 +
14846 +/*     return values:
14847 +        +1 ... no limit hit
14848 +        -1 ... over soft limit
14849 +         0 ... over hard limit         */
14850 +
14851 +static inline int __vx_cres_avail(struct vx_info *vxi,
14852 +       int res, int num, char *_file, int _line)
14853 +{
14854 +       struct _vx_limit *limit;
14855 +       rlim_t value;
14856 +
14857 +       if (VXD_RLIMIT_COND(res))
14858 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
14859 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14860 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
14861 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
14862 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14863 +                       num, _file, _line);
14864 +       if (!vxi)
14865 +               return 1;
14866 +
14867 +       limit = &vxi->limit;
14868 +       value = __rlim_get(limit, res);
14869 +
14870 +       if (!__vx_cres_adjust_max(limit, res, value))
14871 +               __vx_cres_adjust_min(limit, res, value);
14872 +
14873 +       if (num == 0)
14874 +               return 1;
14875 +
14876 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
14877 +               return -1;
14878 +       if (value + num <= __rlim_soft(limit, res))
14879 +               return -1;
14880 +
14881 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
14882 +               return 1;
14883 +       if (value + num <= __rlim_hard(limit, res))
14884 +               return 1;
14885 +
14886 +       __rlim_hit(limit, res);
14887 +       return 0;
14888 +}
14889 +
14890 +
14891 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
14892 +
14893 +static inline
14894 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
14895 +{
14896 +       rlim_t value, sum = 0;
14897 +       int res;
14898 +
14899 +       while ((res = *array++)) {
14900 +               value = __rlim_get(limit, res);
14901 +               __vx_cres_fixup(limit, res, value);
14902 +               sum += value;
14903 +       }
14904 +       return sum;
14905 +}
14906 +
14907 +static inline
14908 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
14909 +{
14910 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
14911 +       int res = *array;
14912 +
14913 +       if (value == __rlim_get(limit, res))
14914 +               return value;
14915 +
14916 +       __rlim_set(limit, res, value);
14917 +       /* now adjust min/max */
14918 +       if (!__vx_cres_adjust_max(limit, res, value))
14919 +               __vx_cres_adjust_min(limit, res, value);
14920 +
14921 +       return value;
14922 +}
14923 +
14924 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
14925 +       const int *array, int num, char *_file, int _line)
14926 +{
14927 +       struct _vx_limit *limit;
14928 +       rlim_t value = 0;
14929 +       int res;
14930 +
14931 +       if (num == 0)
14932 +               return 1;
14933 +       if (!vxi)
14934 +               return 1;
14935 +
14936 +       limit = &vxi->limit;
14937 +       res = *array;
14938 +       value = __vx_cres_array_sum(limit, array + 1);
14939 +
14940 +       __rlim_set(limit, res, value);
14941 +       __vx_cres_fixup(limit, res, value);
14942 +
14943 +       return __vx_cres_avail(vxi, res, num, _file, _line);
14944 +}
14945 +
14946 +
14947 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
14948 +{
14949 +       rlim_t value;
14950 +       int res;
14951 +
14952 +       /* complex resources first */
14953 +       if ((id < 0) || (id == RLIMIT_RSS))
14954 +               __vx_cres_array_fixup(limit, VLA_RSS);
14955 +
14956 +       for (res = 0; res < NUM_LIMITS; res++) {
14957 +               if ((id > 0) && (res != id))
14958 +                       continue;
14959 +
14960 +               value = __rlim_get(limit, res);
14961 +               __vx_cres_fixup(limit, res, value);
14962 +
14963 +               /* not supposed to happen, maybe warn? */
14964 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
14965 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
14966 +       }
14967 +}
14968 +
14969 +
14970 +#endif /* __KERNEL__ */
14971 +#endif /* _VX_LIMIT_INT_H */
14972 diff -NurpP --minimal linux-3.0/include/linux/vserver/monitor.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/monitor.h
14973 --- linux-3.0/include/linux/vserver/monitor.h   1970-01-01 01:00:00.000000000 +0100
14974 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/monitor.h      2011-06-10 22:11:24.000000000 +0200
14975 @@ -0,0 +1,96 @@
14976 +#ifndef _VX_MONITOR_H
14977 +#define _VX_MONITOR_H
14978 +
14979 +#include <linux/types.h>
14980 +
14981 +enum {
14982 +       VXM_UNUSED = 0,
14983 +
14984 +       VXM_SYNC = 0x10,
14985 +
14986 +       VXM_UPDATE = 0x20,
14987 +       VXM_UPDATE_1,
14988 +       VXM_UPDATE_2,
14989 +
14990 +       VXM_RQINFO_1 = 0x24,
14991 +       VXM_RQINFO_2,
14992 +
14993 +       VXM_ACTIVATE = 0x40,
14994 +       VXM_DEACTIVATE,
14995 +       VXM_IDLE,
14996 +
14997 +       VXM_HOLD = 0x44,
14998 +       VXM_UNHOLD,
14999 +
15000 +       VXM_MIGRATE = 0x48,
15001 +       VXM_RESCHED,
15002 +
15003 +       /* all other bits are flags */
15004 +       VXM_SCHED = 0x80,
15005 +};
15006 +
15007 +struct _vxm_update_1 {
15008 +       uint32_t tokens_max;
15009 +       uint32_t fill_rate;
15010 +       uint32_t interval;
15011 +};
15012 +
15013 +struct _vxm_update_2 {
15014 +       uint32_t tokens_min;
15015 +       uint32_t fill_rate;
15016 +       uint32_t interval;
15017 +};
15018 +
15019 +struct _vxm_rqinfo_1 {
15020 +       uint16_t running;
15021 +       uint16_t onhold;
15022 +       uint16_t iowait;
15023 +       uint16_t uintr;
15024 +       uint32_t idle_tokens;
15025 +};
15026 +
15027 +struct _vxm_rqinfo_2 {
15028 +       uint32_t norm_time;
15029 +       uint32_t idle_time;
15030 +       uint32_t idle_skip;
15031 +};
15032 +
15033 +struct _vxm_sched {
15034 +       uint32_t tokens;
15035 +       uint32_t norm_time;
15036 +       uint32_t idle_time;
15037 +};
15038 +
15039 +struct _vxm_task {
15040 +       uint16_t pid;
15041 +       uint16_t state;
15042 +};
15043 +
15044 +struct _vxm_event {
15045 +       uint32_t jif;
15046 +       union {
15047 +               uint32_t seq;
15048 +               uint32_t sec;
15049 +       };
15050 +       union {
15051 +               uint32_t tokens;
15052 +               uint32_t nsec;
15053 +               struct _vxm_task tsk;
15054 +       };
15055 +};
15056 +
15057 +struct _vx_mon_entry {
15058 +       uint16_t type;
15059 +       uint16_t xid;
15060 +       union {
15061 +               struct _vxm_event ev;
15062 +               struct _vxm_sched sd;
15063 +               struct _vxm_update_1 u1;
15064 +               struct _vxm_update_2 u2;
15065 +               struct _vxm_rqinfo_1 q1;
15066 +               struct _vxm_rqinfo_2 q2;
15067 +       };
15068 +};
15069 +
15070 +
15071 +#endif /* _VX_MONITOR_H */
15072 diff -NurpP --minimal linux-3.0/include/linux/vserver/network.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/network.h
15073 --- linux-3.0/include/linux/vserver/network.h   1970-01-01 01:00:00.000000000 +0100
15074 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/network.h      2011-06-10 22:11:24.000000000 +0200
15075 @@ -0,0 +1,146 @@
15076 +#ifndef _VX_NETWORK_H
15077 +#define _VX_NETWORK_H
15078 +
15079 +#include <linux/types.h>
15080 +
15081 +
15082 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
15083 +
15084 +
15085 +/* network flags */
15086 +
15087 +#define NXF_INFO_PRIVATE       0x00000008
15088 +
15089 +#define NXF_SINGLE_IP          0x00000100
15090 +#define NXF_LBACK_REMAP                0x00000200
15091 +#define NXF_LBACK_ALLOW                0x00000400
15092 +
15093 +#define NXF_HIDE_NETIF         0x02000000
15094 +#define NXF_HIDE_LBACK         0x04000000
15095 +
15096 +#define NXF_STATE_SETUP                (1ULL << 32)
15097 +#define NXF_STATE_ADMIN                (1ULL << 34)
15098 +
15099 +#define NXF_SC_HELPER          (1ULL << 36)
15100 +#define NXF_PERSISTENT         (1ULL << 38)
15101 +
15102 +#define NXF_ONE_TIME           (0x0005ULL << 32)
15103 +
15104 +
15105 +#define        NXF_INIT_SET            (__nxf_init_set())
15106 +
15107 +static inline uint64_t __nxf_init_set(void) {
15108 +       return    NXF_STATE_ADMIN
15109 +#ifdef CONFIG_VSERVER_AUTO_LBACK
15110 +               | NXF_LBACK_REMAP
15111 +               | NXF_HIDE_LBACK
15112 +#endif
15113 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
15114 +               | NXF_SINGLE_IP
15115 +#endif
15116 +               | NXF_HIDE_NETIF;
15117 +}
15118 +
15119 +
15120 +/* network caps */
15121 +
15122 +#define NXC_TUN_CREATE         0x00000001
15123 +
15124 +#define NXC_RAW_ICMP           0x00000100
15125 +
15126 +
15127 +/* address types */
15128 +
15129 +#define NXA_TYPE_IPV4          0x0001
15130 +#define NXA_TYPE_IPV6          0x0002
15131 +
15132 +#define NXA_TYPE_NONE          0x0000
15133 +#define NXA_TYPE_ANY           0x00FF
15134 +
15135 +#define NXA_TYPE_ADDR          0x0010
15136 +#define NXA_TYPE_MASK          0x0020
15137 +#define NXA_TYPE_RANGE         0x0040
15138 +
15139 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
15140 +
15141 +#define NXA_MOD_BCAST          0x0100
15142 +#define NXA_MOD_LBACK          0x0200
15143 +
15144 +#define NXA_LOOPBACK           0x1000
15145 +
15146 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
15147 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
15148 +
15149 +#ifdef __KERNEL__
15150 +
15151 +#include <linux/list.h>
15152 +#include <linux/spinlock.h>
15153 +#include <linux/rcupdate.h>
15154 +#include <linux/in.h>
15155 +#include <linux/in6.h>
15156 +#include <asm/atomic.h>
15157 +
15158 +struct nx_addr_v4 {
15159 +       struct nx_addr_v4 *next;
15160 +       struct in_addr ip[2];
15161 +       struct in_addr mask;
15162 +       uint16_t type;
15163 +       uint16_t flags;
15164 +};
15165 +
15166 +struct nx_addr_v6 {
15167 +       struct nx_addr_v6 *next;
15168 +       struct in6_addr ip;
15169 +       struct in6_addr mask;
15170 +       uint32_t prefix;
15171 +       uint16_t type;
15172 +       uint16_t flags;
15173 +};
15174 +
15175 +struct nx_info {
15176 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
15177 +       nid_t nx_id;                    /* vnet id */
15178 +       atomic_t nx_usecnt;             /* usage count */
15179 +       atomic_t nx_tasks;              /* tasks count */
15180 +       int nx_state;                   /* context state */
15181 +
15182 +       uint64_t nx_flags;              /* network flag word */
15183 +       uint64_t nx_ncaps;              /* network capabilities */
15184 +
15185 +       struct in_addr v4_lback;        /* Loopback address */
15186 +       struct in_addr v4_bcast;        /* Broadcast address */
15187 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
15188 +#ifdef CONFIG_IPV6
15189 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
15190 +#endif
15191 +       char nx_name[65];               /* network context name */
15192 +};
15193 +
15194 +
15195 +/* status flags */
15196 +
15197 +#define NXS_HASHED      0x0001
15198 +#define NXS_SHUTDOWN    0x0100
15199 +#define NXS_RELEASED    0x8000
15200 +
15201 +extern struct nx_info *lookup_nx_info(int);
15202 +
15203 +extern int get_nid_list(int, unsigned int *, int);
15204 +extern int nid_is_hashed(nid_t);
15205 +
15206 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
15207 +
15208 +extern long vs_net_change(struct nx_info *, unsigned int);
15209 +
15210 +struct sock;
15211 +
15212 +
15213 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
15214 +#ifdef  CONFIG_IPV6
15215 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
15216 +#else
15217 +#define NX_IPV6(n)     (0)
15218 +#endif
15219 +
15220 +#endif /* __KERNEL__ */
15221 +#endif /* _VX_NETWORK_H */
15222 diff -NurpP --minimal linux-3.0/include/linux/vserver/network_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/network_cmd.h
15223 --- linux-3.0/include/linux/vserver/network_cmd.h       1970-01-01 01:00:00.000000000 +0100
15224 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/network_cmd.h  2011-06-10 22:11:24.000000000 +0200
15225 @@ -0,0 +1,164 @@
15226 +#ifndef _VX_NETWORK_CMD_H
15227 +#define _VX_NETWORK_CMD_H
15228 +
15229 +
15230 +/* vinfo commands */
15231 +
15232 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
15233 +
15234 +#ifdef __KERNEL__
15235 +extern int vc_task_nid(uint32_t);
15236 +
15237 +#endif /* __KERNEL__ */
15238 +
15239 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
15240 +
15241 +struct vcmd_nx_info_v0 {
15242 +       uint32_t nid;
15243 +       /* more to come */
15244 +};
15245 +
15246 +#ifdef __KERNEL__
15247 +extern int vc_nx_info(struct nx_info *, void __user *);
15248 +
15249 +#endif /* __KERNEL__ */
15250 +
15251 +#include <linux/in.h>
15252 +#include <linux/in6.h>
15253 +
15254 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
15255 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
15256 +
15257 +struct  vcmd_net_create {
15258 +       uint64_t flagword;
15259 +};
15260 +
15261 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
15262 +
15263 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
15264 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
15265 +
15266 +struct vcmd_net_addr_v0 {
15267 +       uint16_t type;
15268 +       uint16_t count;
15269 +       struct in_addr ip[4];
15270 +       struct in_addr mask[4];
15271 +};
15272 +
15273 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
15274 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
15275 +
15276 +struct vcmd_net_addr_ipv4_v1 {
15277 +       uint16_t type;
15278 +       uint16_t flags;
15279 +       struct in_addr ip;
15280 +       struct in_addr mask;
15281 +};
15282 +
15283 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
15284 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
15285 +
15286 +struct vcmd_net_addr_ipv4_v2 {
15287 +       uint16_t type;
15288 +       uint16_t flags;
15289 +       struct in_addr ip;
15290 +       struct in_addr ip2;
15291 +       struct in_addr mask;
15292 +};
15293 +
15294 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
15295 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
15296 +
15297 +struct vcmd_net_addr_ipv6_v1 {
15298 +       uint16_t type;
15299 +       uint16_t flags;
15300 +       uint32_t prefix;
15301 +       struct in6_addr ip;
15302 +       struct in6_addr mask;
15303 +};
15304 +
15305 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
15306 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
15307 +
15308 +struct vcmd_match_ipv4_v0 {
15309 +       uint16_t type;
15310 +       uint16_t flags;
15311 +       uint16_t parent;
15312 +       uint16_t prefix;
15313 +       struct in_addr ip;
15314 +       struct in_addr ip2;
15315 +       struct in_addr mask;
15316 +};
15317 +
15318 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
15319 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
15320 +
15321 +struct vcmd_match_ipv6_v0 {
15322 +       uint16_t type;
15323 +       uint16_t flags;
15324 +       uint16_t parent;
15325 +       uint16_t prefix;
15326 +       struct in6_addr ip;
15327 +       struct in6_addr ip2;
15328 +       struct in6_addr mask;
15329 +};
15330 +
15331 +
15332 +#ifdef __KERNEL__
15333 +extern int vc_net_create(uint32_t, void __user *);
15334 +extern int vc_net_migrate(struct nx_info *, void __user *);
15335 +
15336 +extern int vc_net_add(struct nx_info *, void __user *);
15337 +extern int vc_net_remove(struct nx_info *, void __user *);
15338 +
15339 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
15340 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
15341 +
15342 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
15343 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
15344 +
15345 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
15346 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
15347 +
15348 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
15349 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
15350 +
15351 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
15352 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
15353 +
15354 +#endif /* __KERNEL__ */
15355 +
15356 +
15357 +/* flag commands */
15358 +
15359 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
15360 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
15361 +
15362 +struct vcmd_net_flags_v0 {
15363 +       uint64_t flagword;
15364 +       uint64_t mask;
15365 +};
15366 +
15367 +#ifdef __KERNEL__
15368 +extern int vc_get_nflags(struct nx_info *, void __user *);
15369 +extern int vc_set_nflags(struct nx_info *, void __user *);
15370 +
15371 +#endif /* __KERNEL__ */
15372 +
15373 +
15374 +/* network caps commands */
15375 +
15376 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
15377 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
15378 +
15379 +struct vcmd_net_caps_v0 {
15380 +       uint64_t ncaps;
15381 +       uint64_t cmask;
15382 +};
15383 +
15384 +#ifdef __KERNEL__
15385 +extern int vc_get_ncaps(struct nx_info *, void __user *);
15386 +extern int vc_set_ncaps(struct nx_info *, void __user *);
15387 +
15388 +#endif /* __KERNEL__ */
15389 +#endif /* _VX_CONTEXT_CMD_H */
15390 diff -NurpP --minimal linux-3.0/include/linux/vserver/percpu.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/percpu.h
15391 --- linux-3.0/include/linux/vserver/percpu.h    1970-01-01 01:00:00.000000000 +0100
15392 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/percpu.h       2011-06-10 22:11:24.000000000 +0200
15393 @@ -0,0 +1,14 @@
15394 +#ifndef _VX_PERCPU_H
15395 +#define _VX_PERCPU_H
15396 +
15397 +#include "cvirt_def.h"
15398 +#include "sched_def.h"
15399 +
15400 +struct _vx_percpu {
15401 +       struct _vx_cvirt_pc cvirt;
15402 +       struct _vx_sched_pc sched;
15403 +};
15404 +
15405 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
15406 +
15407 +#endif /* _VX_PERCPU_H */
15408 diff -NurpP --minimal linux-3.0/include/linux/vserver/pid.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/pid.h
15409 --- linux-3.0/include/linux/vserver/pid.h       1970-01-01 01:00:00.000000000 +0100
15410 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/pid.h  2011-06-10 22:11:24.000000000 +0200
15411 @@ -0,0 +1,51 @@
15412 +#ifndef _VSERVER_PID_H
15413 +#define _VSERVER_PID_H
15414 +
15415 +/* pid faking stuff */
15416 +
15417 +#define vx_info_map_pid(v, p) \
15418 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
15419 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
15420 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
15421 +#define vx_map_tgid(p) vx_map_pid(p)
15422 +
15423 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
15424 +       const char *func, const char *file, int line)
15425 +{
15426 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
15427 +               vxfprintk(VXD_CBIT(cvirt, 2),
15428 +                       "vx_map_tgid: %p/%llx: %d -> %d",
15429 +                       vxi, (long long)vxi->vx_flags, pid,
15430 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
15431 +                       func, file, line);
15432 +               if (pid == 0)
15433 +                       return 0;
15434 +               if (pid == vxi->vx_initpid)
15435 +                       return 1;
15436 +       }
15437 +       return pid;
15438 +}
15439 +
15440 +#define vx_info_rmap_pid(v, p) \
15441 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
15442 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
15443 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
15444 +
15445 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
15446 +       const char *func, const char *file, int line)
15447 +{
15448 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
15449 +               vxfprintk(VXD_CBIT(cvirt, 2),
15450 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
15451 +                       vxi, (long long)vxi->vx_flags, pid,
15452 +                       (pid == 1) ? vxi->vx_initpid : pid,
15453 +                       func, file, line);
15454 +               if ((pid == 1) && vxi->vx_initpid)
15455 +                       return vxi->vx_initpid;
15456 +               if (pid == vxi->vx_initpid)
15457 +                       return ~0U;
15458 +       }
15459 +       return pid;
15460 +}
15461 +
15462 +#endif
15463 diff -NurpP --minimal linux-3.0/include/linux/vserver/sched.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/sched.h
15464 --- linux-3.0/include/linux/vserver/sched.h     1970-01-01 01:00:00.000000000 +0100
15465 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/sched.h        2011-06-10 22:11:24.000000000 +0200
15466 @@ -0,0 +1,23 @@
15467 +#ifndef _VX_SCHED_H
15468 +#define _VX_SCHED_H
15469 +
15470 +
15471 +#ifdef __KERNEL__
15472 +
15473 +struct timespec;
15474 +
15475 +void vx_vsi_uptime(struct timespec *, struct timespec *);
15476 +
15477 +
15478 +struct vx_info;
15479 +
15480 +void vx_update_load(struct vx_info *);
15481 +
15482 +
15483 +void vx_update_sched_param(struct _vx_sched *sched,
15484 +       struct _vx_sched_pc *sched_pc);
15485 +
15486 +#endif /* __KERNEL__ */
15487 +#else  /* _VX_SCHED_H */
15488 +#warning duplicate inclusion
15489 +#endif /* _VX_SCHED_H */
15490 diff -NurpP --minimal linux-3.0/include/linux/vserver/sched_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/sched_cmd.h
15491 --- linux-3.0/include/linux/vserver/sched_cmd.h 1970-01-01 01:00:00.000000000 +0100
15492 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/sched_cmd.h    2011-06-10 22:11:24.000000000 +0200
15493 @@ -0,0 +1,21 @@
15494 +#ifndef _VX_SCHED_CMD_H
15495 +#define _VX_SCHED_CMD_H
15496 +
15497 +
15498 +struct vcmd_prio_bias {
15499 +       int32_t cpu_id;
15500 +       int32_t prio_bias;
15501 +};
15502 +
15503 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
15504 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
15505 +
15506 +#ifdef __KERNEL__
15507 +
15508 +#include <linux/compiler.h>
15509 +
15510 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
15511 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
15512 +
15513 +#endif /* __KERNEL__ */
15514 +#endif /* _VX_SCHED_CMD_H */
15515 diff -NurpP --minimal linux-3.0/include/linux/vserver/sched_def.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/sched_def.h
15516 --- linux-3.0/include/linux/vserver/sched_def.h 1970-01-01 01:00:00.000000000 +0100
15517 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/sched_def.h    2011-06-10 22:11:24.000000000 +0200
15518 @@ -0,0 +1,38 @@
15519 +#ifndef _VX_SCHED_DEF_H
15520 +#define _VX_SCHED_DEF_H
15521 +
15522 +#include <linux/spinlock.h>
15523 +#include <linux/jiffies.h>
15524 +#include <linux/cpumask.h>
15525 +#include <asm/atomic.h>
15526 +#include <asm/param.h>
15527 +
15528 +
15529 +/* context sub struct */
15530 +
15531 +struct _vx_sched {
15532 +       int prio_bias;                  /* bias offset for priority */
15533 +
15534 +       cpumask_t update;               /* CPUs which should update */
15535 +};
15536 +
15537 +struct _vx_sched_pc {
15538 +       int prio_bias;                  /* bias offset for priority */
15539 +
15540 +       uint64_t user_ticks;            /* token tick events */
15541 +       uint64_t sys_ticks;             /* token tick events */
15542 +       uint64_t hold_ticks;            /* token ticks paused */
15543 +};
15544 +
15545 +
15546 +#ifdef CONFIG_VSERVER_DEBUG
15547 +
15548 +static inline void __dump_vx_sched(struct _vx_sched *sched)
15549 +{
15550 +       printk("\t_vx_sched:\n");
15551 +       printk("\t priority = %4d\n", sched->prio_bias);
15552 +}
15553 +
15554 +#endif
15555 +
15556 +#endif /* _VX_SCHED_DEF_H */
15557 diff -NurpP --minimal linux-3.0/include/linux/vserver/signal.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/signal.h
15558 --- linux-3.0/include/linux/vserver/signal.h    1970-01-01 01:00:00.000000000 +0100
15559 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/signal.h       2011-06-10 22:11:24.000000000 +0200
15560 @@ -0,0 +1,14 @@
15561 +#ifndef _VX_SIGNAL_H
15562 +#define _VX_SIGNAL_H
15563 +
15564 +
15565 +#ifdef __KERNEL__
15566 +
15567 +struct vx_info;
15568 +
15569 +int vx_info_kill(struct vx_info *, int, int);
15570 +
15571 +#endif /* __KERNEL__ */
15572 +#else  /* _VX_SIGNAL_H */
15573 +#warning duplicate inclusion
15574 +#endif /* _VX_SIGNAL_H */
15575 diff -NurpP --minimal linux-3.0/include/linux/vserver/signal_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/signal_cmd.h
15576 --- linux-3.0/include/linux/vserver/signal_cmd.h        1970-01-01 01:00:00.000000000 +0100
15577 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/signal_cmd.h   2011-06-10 22:11:24.000000000 +0200
15578 @@ -0,0 +1,43 @@
15579 +#ifndef _VX_SIGNAL_CMD_H
15580 +#define _VX_SIGNAL_CMD_H
15581 +
15582 +
15583 +/*  signalling vserver commands */
15584 +
15585 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
15586 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
15587 +
15588 +struct vcmd_ctx_kill_v0 {
15589 +       int32_t pid;
15590 +       int32_t sig;
15591 +};
15592 +
15593 +struct vcmd_wait_exit_v0 {
15594 +       int32_t reboot_cmd;
15595 +       int32_t exit_code;
15596 +};
15597 +
15598 +#ifdef __KERNEL__
15599 +
15600 +extern int vc_ctx_kill(struct vx_info *, void __user *);
15601 +extern int vc_wait_exit(struct vx_info *, void __user *);
15602 +
15603 +#endif /* __KERNEL__ */
15604 +
15605 +/*  process alteration commands */
15606 +
15607 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
15608 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
15609 +
15610 +struct vcmd_pflags_v0 {
15611 +       uint32_t flagword;
15612 +       uint32_t mask;
15613 +};
15614 +
15615 +#ifdef __KERNEL__
15616 +
15617 +extern int vc_get_pflags(uint32_t pid, void __user *);
15618 +extern int vc_set_pflags(uint32_t pid, void __user *);
15619 +
15620 +#endif /* __KERNEL__ */
15621 +#endif /* _VX_SIGNAL_CMD_H */
15622 diff -NurpP --minimal linux-3.0/include/linux/vserver/space.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/space.h
15623 --- linux-3.0/include/linux/vserver/space.h     1970-01-01 01:00:00.000000000 +0100
15624 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/space.h        2011-06-10 22:11:24.000000000 +0200
15625 @@ -0,0 +1,12 @@
15626 +#ifndef _VX_SPACE_H
15627 +#define _VX_SPACE_H
15628 +
15629 +#include <linux/types.h>
15630 +
15631 +struct vx_info;
15632 +
15633 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
15634 +
15635 +#else  /* _VX_SPACE_H */
15636 +#warning duplicate inclusion
15637 +#endif /* _VX_SPACE_H */
15638 diff -NurpP --minimal linux-3.0/include/linux/vserver/space_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/space_cmd.h
15639 --- linux-3.0/include/linux/vserver/space_cmd.h 1970-01-01 01:00:00.000000000 +0100
15640 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/space_cmd.h    2011-06-10 22:11:24.000000000 +0200
15641 @@ -0,0 +1,38 @@
15642 +#ifndef _VX_SPACE_CMD_H
15643 +#define _VX_SPACE_CMD_H
15644 +
15645 +
15646 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
15647 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
15648 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
15649 +
15650 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
15651 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
15652 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
15653 +
15654 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
15655 +
15656 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
15657 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
15658 +
15659 +
15660 +struct vcmd_space_mask_v1 {
15661 +       uint64_t mask;
15662 +};
15663 +
15664 +struct vcmd_space_mask_v2 {
15665 +       uint64_t mask;
15666 +       uint32_t index;
15667 +};
15668 +
15669 +
15670 +#ifdef __KERNEL__
15671 +
15672 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
15673 +extern int vc_set_space_v1(struct vx_info *, void __user *);
15674 +extern int vc_enter_space(struct vx_info *, void __user *);
15675 +extern int vc_set_space(struct vx_info *, void __user *);
15676 +extern int vc_get_space_mask(void __user *, int);
15677 +
15678 +#endif /* __KERNEL__ */
15679 +#endif /* _VX_SPACE_CMD_H */
15680 diff -NurpP --minimal linux-3.0/include/linux/vserver/switch.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/switch.h
15681 --- linux-3.0/include/linux/vserver/switch.h    1970-01-01 01:00:00.000000000 +0100
15682 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/switch.h       2011-06-10 22:11:24.000000000 +0200
15683 @@ -0,0 +1,98 @@
15684 +#ifndef _VX_SWITCH_H
15685 +#define _VX_SWITCH_H
15686 +
15687 +#include <linux/types.h>
15688 +
15689 +
15690 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
15691 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
15692 +#define VC_VERSION(c)          ((c) & 0xFFF)
15693 +
15694 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
15695 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
15696 +
15697 +/*
15698 +
15699 +  Syscall Matrix V2.8
15700 +
15701 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
15702 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
15703 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
15704 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15705 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
15706 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
15707 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15708 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
15709 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
15710 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15711 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
15712 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
15713 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15714 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
15715 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
15716 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15717 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
15718 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
15719 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15720 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
15721 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
15722 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
15723 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
15724 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
15725 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15726 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
15727 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
15728 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15729 +
15730 +*/
15731 +
15732 +#define VC_CAT_VERSION         0
15733 +
15734 +#define VC_CAT_VSETUP          1
15735 +#define VC_CAT_VHOST           2
15736 +
15737 +#define VC_CAT_DEVICE          6
15738 +
15739 +#define VC_CAT_VPROC           9
15740 +#define VC_CAT_PROCALT         10
15741 +#define VC_CAT_PROCMIG         11
15742 +#define VC_CAT_PROCTRL         12
15743 +
15744 +#define VC_CAT_SCHED           14
15745 +#define VC_CAT_MEMCTRL         20
15746 +
15747 +#define VC_CAT_VNET            25
15748 +#define VC_CAT_NETALT          26
15749 +#define VC_CAT_NETMIG          27
15750 +#define VC_CAT_NETCTRL         28
15751 +
15752 +#define VC_CAT_TAGMIG          35
15753 +#define VC_CAT_DLIMIT          36
15754 +#define VC_CAT_INODE           38
15755 +
15756 +#define VC_CAT_VSTAT           40
15757 +#define VC_CAT_VINFO           46
15758 +#define VC_CAT_EVENT           48
15759 +
15760 +#define VC_CAT_FLAGS           52
15761 +#define VC_CAT_VSPACE          54
15762 +#define VC_CAT_DEBUG           56
15763 +#define VC_CAT_RLIMIT          60
15764 +
15765 +#define VC_CAT_SYSTEST         61
15766 +#define VC_CAT_COMPAT          63
15767 +
15768 +/*  query version */
15769 +
15770 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
15771 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
15772 +
15773 +
15774 +#ifdef __KERNEL__
15775 +
15776 +#include <linux/errno.h>
15777 +
15778 +#endif /* __KERNEL__ */
15779 +
15780 +#endif /* _VX_SWITCH_H */
15781 +
15782 diff -NurpP --minimal linux-3.0/include/linux/vserver/tag.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/tag.h
15783 --- linux-3.0/include/linux/vserver/tag.h       1970-01-01 01:00:00.000000000 +0100
15784 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/tag.h  2011-06-10 22:11:24.000000000 +0200
15785 @@ -0,0 +1,143 @@
15786 +#ifndef _DX_TAG_H
15787 +#define _DX_TAG_H
15788 +
15789 +#include <linux/types.h>
15790 +
15791 +
15792 +#define DX_TAG(in)     (IS_TAGGED(in))
15793 +
15794 +
15795 +#ifdef CONFIG_TAG_NFSD
15796 +#define DX_TAG_NFSD    1
15797 +#else
15798 +#define DX_TAG_NFSD    0
15799 +#endif
15800 +
15801 +
15802 +#ifdef CONFIG_TAGGING_NONE
15803 +
15804 +#define MAX_UID                0xFFFFFFFF
15805 +#define MAX_GID                0xFFFFFFFF
15806 +
15807 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
15808 +
15809 +#define TAGINO_UID(cond, uid, tag)     (uid)
15810 +#define TAGINO_GID(cond, gid, tag)     (gid)
15811 +
15812 +#endif
15813 +
15814 +
15815 +#ifdef CONFIG_TAGGING_GID16
15816 +
15817 +#define MAX_UID                0xFFFFFFFF
15818 +#define MAX_GID                0x0000FFFF
15819 +
15820 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15821 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
15822 +
15823 +#define TAGINO_UID(cond, uid, tag)     (uid)
15824 +#define TAGINO_GID(cond, gid, tag)     \
15825 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
15826 +
15827 +#endif
15828 +
15829 +
15830 +#ifdef CONFIG_TAGGING_ID24
15831 +
15832 +#define MAX_UID                0x00FFFFFF
15833 +#define MAX_GID                0x00FFFFFF
15834 +
15835 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15836 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
15837 +
15838 +#define TAGINO_UID(cond, uid, tag)     \
15839 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
15840 +#define TAGINO_GID(cond, gid, tag)     \
15841 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
15842 +
15843 +#endif
15844 +
15845 +
15846 +#ifdef CONFIG_TAGGING_UID16
15847 +
15848 +#define MAX_UID                0x0000FFFF
15849 +#define MAX_GID                0xFFFFFFFF
15850 +
15851 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15852 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
15853 +
15854 +#define TAGINO_UID(cond, uid, tag)     \
15855 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
15856 +#define TAGINO_GID(cond, gid, tag)     (gid)
15857 +
15858 +#endif
15859 +
15860 +
15861 +#ifdef CONFIG_TAGGING_INTERN
15862 +
15863 +#define MAX_UID                0xFFFFFFFF
15864 +#define MAX_GID                0xFFFFFFFF
15865 +
15866 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15867 +       ((cond) ? (tag) : 0)
15868 +
15869 +#define TAGINO_UID(cond, uid, tag)     (uid)
15870 +#define TAGINO_GID(cond, gid, tag)     (gid)
15871 +
15872 +#endif
15873 +
15874 +
15875 +#ifndef CONFIG_TAGGING_NONE
15876 +#define dx_current_fstag(sb)   \
15877 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
15878 +#else
15879 +#define dx_current_fstag(sb)   (0)
15880 +#endif
15881 +
15882 +#ifndef CONFIG_TAGGING_INTERN
15883 +#define TAGINO_TAG(cond, tag)  (0)
15884 +#else
15885 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
15886 +#endif
15887 +
15888 +#define INOTAG_UID(cond, uid, gid)     \
15889 +       ((cond) ? ((uid) & MAX_UID) : (uid))
15890 +#define INOTAG_GID(cond, uid, gid)     \
15891 +       ((cond) ? ((gid) & MAX_GID) : (gid))
15892 +
15893 +
15894 +static inline uid_t dx_map_uid(uid_t uid)
15895 +{
15896 +       if ((uid > MAX_UID) && (uid != -1))
15897 +               uid = -2;
15898 +       return (uid & MAX_UID);
15899 +}
15900 +
15901 +static inline gid_t dx_map_gid(gid_t gid)
15902 +{
15903 +       if ((gid > MAX_GID) && (gid != -1))
15904 +               gid = -2;
15905 +       return (gid & MAX_GID);
15906 +}
15907 +
15908 +struct peer_tag {
15909 +       int32_t xid;
15910 +       int32_t nid;
15911 +};
15912 +
15913 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
15914 +
15915 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
15916 +                unsigned long *flags);
15917 +
15918 +#ifdef CONFIG_PROPAGATE
15919 +
15920 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
15921 +
15922 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
15923 +
15924 +#else
15925 +#define dx_propagate_tag(n, i) do { } while (0)
15926 +#endif
15927 +
15928 +#endif /* _DX_TAG_H */
15929 diff -NurpP --minimal linux-3.0/include/linux/vserver/tag_cmd.h linux-3.0-vs2.3.1-pre6/include/linux/vserver/tag_cmd.h
15930 --- linux-3.0/include/linux/vserver/tag_cmd.h   1970-01-01 01:00:00.000000000 +0100
15931 +++ linux-3.0-vs2.3.1-pre6/include/linux/vserver/tag_cmd.h      2011-06-10 22:11:24.000000000 +0200
15932 @@ -0,0 +1,22 @@
15933 +#ifndef _VX_TAG_CMD_H
15934 +#define _VX_TAG_CMD_H
15935 +
15936 +
15937 +/* vinfo commands */
15938 +
15939 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
15940 +
15941 +#ifdef __KERNEL__
15942 +extern int vc_task_tag(uint32_t);
15943 +
15944 +#endif /* __KERNEL__ */
15945 +
15946 +/* context commands */
15947 +
15948 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
15949 +
15950 +#ifdef __KERNEL__
15951 +extern int vc_tag_migrate(uint32_t);
15952 +
15953 +#endif /* __KERNEL__ */
15954 +#endif /* _VX_TAG_CMD_H */
15955 diff -NurpP --minimal linux-3.0/include/net/addrconf.h linux-3.0-vs2.3.1-pre6/include/net/addrconf.h
15956 --- linux-3.0/include/net/addrconf.h    2011-07-22 11:18:11.000000000 +0200
15957 +++ linux-3.0-vs2.3.1-pre6/include/net/addrconf.h       2011-06-10 22:11:24.000000000 +0200
15958 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
15959                                                struct net_device *dev,
15960                                                const struct in6_addr *daddr,
15961                                                unsigned int srcprefs,
15962 -                                              struct in6_addr *saddr);
15963 +                                              struct in6_addr *saddr,
15964 +                                              struct nx_info *nxi);
15965  extern int                     ipv6_get_lladdr(struct net_device *dev,
15966                                                 struct in6_addr *addr,
15967                                                 unsigned char banned_flags);
15968 diff -NurpP --minimal linux-3.0/include/net/af_unix.h linux-3.0-vs2.3.1-pre6/include/net/af_unix.h
15969 --- linux-3.0/include/net/af_unix.h     2011-07-22 11:18:11.000000000 +0200
15970 +++ linux-3.0-vs2.3.1-pre6/include/net/af_unix.h        2011-06-10 22:11:24.000000000 +0200
15971 @@ -4,6 +4,7 @@
15972  #include <linux/socket.h>
15973  #include <linux/un.h>
15974  #include <linux/mutex.h>
15975 +#include <linux/vs_base.h>
15976  #include <net/sock.h>
15977  
15978  extern void unix_inflight(struct file *fp);
15979 diff -NurpP --minimal linux-3.0/include/net/inet_timewait_sock.h linux-3.0-vs2.3.1-pre6/include/net/inet_timewait_sock.h
15980 --- linux-3.0/include/net/inet_timewait_sock.h  2011-03-15 18:07:40.000000000 +0100
15981 +++ linux-3.0-vs2.3.1-pre6/include/net/inet_timewait_sock.h     2011-06-10 22:11:24.000000000 +0200
15982 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
15983  #define tw_net                 __tw_common.skc_net
15984  #define tw_daddr               __tw_common.skc_daddr
15985  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
15986 +#define tw_xid                 __tw_common.skc_xid
15987 +#define tw_vx_info             __tw_common.skc_vx_info
15988 +#define tw_nid                 __tw_common.skc_nid
15989 +#define tw_nx_info             __tw_common.skc_nx_info
15990         int                     tw_timeout;
15991         volatile unsigned char  tw_substate;
15992         unsigned char           tw_rcv_wscale;
15993 diff -NurpP --minimal linux-3.0/include/net/ip6_route.h linux-3.0-vs2.3.1-pre6/include/net/ip6_route.h
15994 --- linux-3.0/include/net/ip6_route.h   2011-07-22 11:18:11.000000000 +0200
15995 +++ linux-3.0-vs2.3.1-pre6/include/net/ip6_route.h      2011-06-16 14:16:51.000000000 +0200
15996 @@ -86,7 +86,8 @@ extern int                    ip6_route_get_saddr(struct 
15997                                                     struct rt6_info *rt,
15998                                                     const struct in6_addr *daddr,
15999                                                     unsigned int prefs,
16000 -                                                   struct in6_addr *saddr);
16001 +                                                   struct in6_addr *saddr,
16002 +                                                   struct nx_info *nxi);
16003  
16004  extern struct rt6_info         *rt6_lookup(struct net *net,
16005                                             const struct in6_addr *daddr,
16006 diff -NurpP --minimal linux-3.0/include/net/route.h linux-3.0-vs2.3.1-pre6/include/net/route.h
16007 --- linux-3.0/include/net/route.h       2011-07-22 11:18:11.000000000 +0200
16008 +++ linux-3.0-vs2.3.1-pre6/include/net/route.h  2011-06-13 18:20:44.000000000 +0200
16009 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
16010                 dst_release(&rt->dst);
16011  }
16012  
16013 +#include <linux/vs_base.h>
16014 +#include <linux/vs_inet.h>
16015 +
16016  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
16017  
16018  extern const __u8 ip_tos2prio[16];
16019 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
16020                            protocol, flow_flags, dst, src, dport, sport);
16021  }
16022  
16023 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
16024 +       struct flowi4 *);
16025 +
16026  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
16027                                               __be32 dst, __be32 src, u32 tos,
16028                                               int oif, u8 protocol,
16029 @@ -261,11 +267,24 @@ static inline struct rtable *ip_route_co
16030  {
16031         struct net *net = sock_net(sk);
16032         struct rtable *rt;
16033 +       struct nx_info *nx_info = current_nx_info();
16034  
16035         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
16036                               sport, dport, sk, can_sleep);
16037  
16038 -       if (!dst || !src) {
16039 +       if (sk)
16040 +               nx_info = sk->sk_nx_info;
16041 +
16042 +       vxdprintk(VXD_CBIT(net, 4),
16043 +               "ip_route_connect(%p) %p,%p;%lx",
16044 +               sk, nx_info, sk->sk_socket,
16045 +               (sk->sk_socket?sk->sk_socket->flags:0));
16046 +
16047 +       rt = ip_v4_find_src(net, nx_info, fl4);
16048 +       if (IS_ERR(rt))
16049 +               return rt;
16050 +
16051 +       if (!fl4->daddr || !fl4->saddr) {
16052                 rt = __ip_route_output_key(net, fl4);
16053                 if (IS_ERR(rt))
16054                         return rt;
16055 diff -NurpP --minimal linux-3.0/include/net/sock.h linux-3.0-vs2.3.1-pre6/include/net/sock.h
16056 --- linux-3.0/include/net/sock.h        2011-07-22 11:18:12.000000000 +0200
16057 +++ linux-3.0-vs2.3.1-pre6/include/net/sock.h   2011-07-01 11:35:35.000000000 +0200
16058 @@ -149,6 +149,10 @@ struct sock_common {
16059  #ifdef CONFIG_NET_NS
16060         struct net              *skc_net;
16061  #endif
16062 +       xid_t                   skc_xid;
16063 +       struct vx_info          *skc_vx_info;
16064 +       nid_t                   skc_nid;
16065 +       struct nx_info          *skc_nx_info;
16066         /*
16067          * fields between dontcopy_begin/dontcopy_end
16068          * are not copied in sock_copy()
16069 @@ -256,6 +260,10 @@ struct sock {
16070  #define sk_bind_node           __sk_common.skc_bind_node
16071  #define sk_prot                        __sk_common.skc_prot
16072  #define sk_net                 __sk_common.skc_net
16073 +#define sk_xid                 __sk_common.skc_xid
16074 +#define sk_vx_info             __sk_common.skc_vx_info
16075 +#define sk_nid                 __sk_common.skc_nid
16076 +#define sk_nx_info             __sk_common.skc_nx_info
16077         socket_lock_t           sk_lock;
16078         struct sk_buff_head     sk_receive_queue;
16079         /*
16080 diff -NurpP --minimal linux-3.0/init/Kconfig linux-3.0-vs2.3.1-pre6/init/Kconfig
16081 --- linux-3.0/init/Kconfig      2011-07-22 11:18:12.000000000 +0200
16082 +++ linux-3.0-vs2.3.1-pre6/init/Kconfig 2011-07-20 02:16:43.000000000 +0200
16083 @@ -574,6 +574,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
16084  menuconfig CGROUPS
16085         boolean "Control Group support"
16086         depends on EVENTFD
16087 +       default y
16088         help
16089           This option adds support for grouping sets of processes together, for
16090           use with process control subsystems such as Cpusets, CFS, memory
16091 @@ -790,7 +791,7 @@ config IPC_NS
16092  config USER_NS
16093         bool "User namespace (EXPERIMENTAL)"
16094         depends on EXPERIMENTAL
16095 -       default y
16096 +       default n
16097         help
16098           This allows containers, i.e. vservers, to use user namespaces
16099           to provide different user info for different servers.
16100 diff -NurpP --minimal linux-3.0/init/main.c linux-3.0-vs2.3.1-pre6/init/main.c
16101 --- linux-3.0/init/main.c       2011-07-22 11:18:12.000000000 +0200
16102 +++ linux-3.0-vs2.3.1-pre6/init/main.c  2011-06-22 12:39:15.000000000 +0200
16103 @@ -68,6 +68,7 @@
16104  #include <linux/shmem_fs.h>
16105  #include <linux/slab.h>
16106  #include <linux/perf_event.h>
16107 +#include <linux/vserver/percpu.h>
16108  
16109  #include <asm/io.h>
16110  #include <asm/bugs.h>
16111 diff -NurpP --minimal linux-3.0/ipc/mqueue.c linux-3.0-vs2.3.1-pre6/ipc/mqueue.c
16112 --- linux-3.0/ipc/mqueue.c      2011-03-15 18:07:41.000000000 +0100
16113 +++ linux-3.0-vs2.3.1-pre6/ipc/mqueue.c 2011-06-10 22:11:24.000000000 +0200
16114 @@ -33,6 +33,8 @@
16115  #include <linux/pid.h>
16116  #include <linux/ipc_namespace.h>
16117  #include <linux/slab.h>
16118 +#include <linux/vs_context.h>
16119 +#include <linux/vs_limit.h>
16120  
16121  #include <net/sock.h>
16122  #include "util.h"
16123 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
16124         struct sigevent notify;
16125         struct pid* notify_owner;
16126         struct user_struct *user;       /* user who created, for accounting */
16127 +       struct vx_info *vxi;
16128         struct sock *notify_sock;
16129         struct sk_buff *notify_cookie;
16130  
16131 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
16132                 if (S_ISREG(mode)) {
16133                         struct mqueue_inode_info *info;
16134                         struct task_struct *p = current;
16135 +                       struct vx_info *vxi = p->vx_info;
16136                         unsigned long mq_bytes, mq_msg_tblsz;
16137  
16138                         inode->i_fop = &mqueue_file_operations;
16139 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
16140                         info->notify_owner = NULL;
16141                         info->qsize = 0;
16142                         info->user = NULL;      /* set when all is ok */
16143 +                       info->vxi = NULL;
16144                         memset(&info->attr, 0, sizeof(info->attr));
16145                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
16146                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
16147 @@ -157,16 +162,19 @@ static struct inode *mqueue_get_inode(st
16148                         spin_lock(&mq_lock);
16149                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
16150                             u->mq_bytes + mq_bytes >
16151 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
16152 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
16153 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
16154                                 spin_unlock(&mq_lock);
16155                                 /* mqueue_evict_inode() releases info->messages */
16156                                 goto out_inode;
16157                         }
16158                         u->mq_bytes += mq_bytes;
16159 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
16160                         spin_unlock(&mq_lock);
16161  
16162                         /* all is ok */
16163                         info->user = get_uid(u);
16164 +                       info->vxi = get_vx_info(vxi);
16165                 } else if (S_ISDIR(mode)) {
16166                         inc_nlink(inode);
16167                         /* Some things misbehave if size == 0 on a directory */
16168 @@ -275,8 +283,11 @@ static void mqueue_evict_inode(struct in
16169             + info->attr.mq_msgsize);
16170         user = info->user;
16171         if (user) {
16172 +               struct vx_info *vxi = info->vxi;
16173 +
16174                 spin_lock(&mq_lock);
16175                 user->mq_bytes -= mq_bytes;
16176 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
16177                 /*
16178                  * get_ns_from_inode() ensures that the
16179                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
16180 @@ -286,6 +297,7 @@ static void mqueue_evict_inode(struct in
16181                 if (ipc_ns)
16182                         ipc_ns->mq_queues_count--;
16183                 spin_unlock(&mq_lock);
16184 +               put_vx_info(vxi);
16185                 free_uid(user);
16186         }
16187         if (ipc_ns)
16188 diff -NurpP --minimal linux-3.0/ipc/msg.c linux-3.0-vs2.3.1-pre6/ipc/msg.c
16189 --- linux-3.0/ipc/msg.c 2011-05-22 16:17:59.000000000 +0200
16190 +++ linux-3.0-vs2.3.1-pre6/ipc/msg.c    2011-06-10 22:11:24.000000000 +0200
16191 @@ -37,6 +37,7 @@
16192  #include <linux/rwsem.h>
16193  #include <linux/nsproxy.h>
16194  #include <linux/ipc_namespace.h>
16195 +#include <linux/vs_base.h>
16196  
16197  #include <asm/current.h>
16198  #include <asm/uaccess.h>
16199 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
16200  
16201         msq->q_perm.mode = msgflg & S_IRWXUGO;
16202         msq->q_perm.key = key;
16203 +       msq->q_perm.xid = vx_current_xid();
16204  
16205         msq->q_perm.security = NULL;
16206         retval = security_msg_queue_alloc(msq);
16207 diff -NurpP --minimal linux-3.0/ipc/namespace.c linux-3.0-vs2.3.1-pre6/ipc/namespace.c
16208 --- linux-3.0/ipc/namespace.c   2011-07-22 11:18:12.000000000 +0200
16209 +++ linux-3.0-vs2.3.1-pre6/ipc/namespace.c      2011-06-13 14:09:44.000000000 +0200
16210 @@ -13,11 +13,12 @@
16211  #include <linux/mount.h>
16212  #include <linux/user_namespace.h>
16213  #include <linux/proc_fs.h>
16214 +#include <linux/vs_base.h>
16215 +#include <linux/vserver/global.h>
16216  
16217  #include "util.h"
16218  
16219 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
16220 -                                          struct ipc_namespace *old_ns)
16221 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
16222  {
16223         struct ipc_namespace *ns;
16224         int err;
16225 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
16226         ipcns_notify(IPCNS_CREATED);
16227         register_ipcns_notifier(ns);
16228  
16229 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
16230 +       ns->user_ns = get_user_ns(user_ns);
16231  
16232         return ns;
16233  }
16234  
16235  struct ipc_namespace *copy_ipcs(unsigned long flags,
16236 -                               struct task_struct *tsk)
16237 +                               struct ipc_namespace *old_ns,
16238 +                               struct user_namespace *user_ns)
16239  {
16240 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
16241 -
16242         if (!(flags & CLONE_NEWIPC))
16243 -               return get_ipc_ns(ns);
16244 -       return create_ipc_ns(tsk, ns);
16245 +               return get_ipc_ns(old_ns);
16246 +       return create_ipc_ns(user_ns);
16247  }
16248  
16249  /*
16250 diff -NurpP --minimal linux-3.0/ipc/sem.c linux-3.0-vs2.3.1-pre6/ipc/sem.c
16251 --- linux-3.0/ipc/sem.c 2011-05-22 16:17:59.000000000 +0200
16252 +++ linux-3.0-vs2.3.1-pre6/ipc/sem.c    2011-06-10 22:11:24.000000000 +0200
16253 @@ -86,6 +86,8 @@
16254  #include <linux/rwsem.h>
16255  #include <linux/nsproxy.h>
16256  #include <linux/ipc_namespace.h>
16257 +#include <linux/vs_base.h>
16258 +#include <linux/vs_limit.h>
16259  
16260  #include <asm/uaccess.h>
16261  #include "util.h"
16262 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
16263  
16264         sma->sem_perm.mode = (semflg & S_IRWXUGO);
16265         sma->sem_perm.key = key;
16266 +       sma->sem_perm.xid = vx_current_xid();
16267  
16268         sma->sem_perm.security = NULL;
16269         retval = security_sem_alloc(sma);
16270 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
16271                 return id;
16272         }
16273         ns->used_sems += nsems;
16274 +       /* FIXME: obsoleted? */
16275 +       vx_semary_inc(sma);
16276 +       vx_nsems_add(sma, nsems);
16277  
16278         sma->sem_base = (struct sem *) &sma[1];
16279  
16280 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
16281  
16282         wake_up_sem_queue_do(&tasks);
16283         ns->used_sems -= sma->sem_nsems;
16284 +       /* FIXME: obsoleted? */
16285 +       vx_nsems_sub(sma, sma->sem_nsems);
16286 +       vx_semary_dec(sma);
16287         security_sem_free(sma);
16288         ipc_rcu_putref(sma);
16289  }
16290 diff -NurpP --minimal linux-3.0/ipc/shm.c linux-3.0-vs2.3.1-pre6/ipc/shm.c
16291 --- linux-3.0/ipc/shm.c 2011-07-22 11:18:12.000000000 +0200
16292 +++ linux-3.0-vs2.3.1-pre6/ipc/shm.c    2011-06-10 22:11:24.000000000 +0200
16293 @@ -39,6 +39,8 @@
16294  #include <linux/nsproxy.h>
16295  #include <linux/mount.h>
16296  #include <linux/ipc_namespace.h>
16297 +#include <linux/vs_context.h>
16298 +#include <linux/vs_limit.h>
16299  
16300  #include <asm/uaccess.h>
16301  
16302 @@ -173,7 +175,12 @@ static void shm_open(struct vm_area_stru
16303   */
16304  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
16305  {
16306 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
16307 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
16308 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
16309 +
16310 +       vx_ipcshm_sub(vxi, shp, numpages);
16311 +       ns->shm_tot -= numpages;
16312 +
16313         shm_rmid(ns, shp);
16314         shm_unlock(shp);
16315         if (!is_file_hugepages(shp->shm_file))
16316 @@ -183,6 +190,7 @@ static void shm_destroy(struct ipc_names
16317                                                 shp->mlock_user);
16318         fput (shp->shm_file);
16319         security_shm_free(shp);
16320 +       put_vx_info(vxi);
16321         ipc_rcu_putref(shp);
16322  }
16323  
16324 @@ -355,11 +363,15 @@ static int newseg(struct ipc_namespace *
16325         if (ns->shm_tot + numpages > ns->shm_ctlall)
16326                 return -ENOSPC;
16327  
16328 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
16329 +               return -ENOSPC;
16330 +
16331         shp = ipc_rcu_alloc(sizeof(*shp));
16332         if (!shp)
16333                 return -ENOMEM;
16334  
16335         shp->shm_perm.key = key;
16336 +       shp->shm_perm.xid = vx_current_xid();
16337         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
16338         shp->mlock_user = NULL;
16339  
16340 @@ -413,6 +425,7 @@ static int newseg(struct ipc_namespace *
16341         ns->shm_tot += numpages;
16342         error = shp->shm_perm.id;
16343         shm_unlock(shp);
16344 +       vx_ipcshm_add(current_vx_info(), key, numpages);
16345         return error;
16346  
16347  no_id:
16348 diff -NurpP --minimal linux-3.0/kernel/Makefile linux-3.0-vs2.3.1-pre6/kernel/Makefile
16349 --- linux-3.0/kernel/Makefile   2011-07-22 11:18:12.000000000 +0200
16350 +++ linux-3.0-vs2.3.1-pre6/kernel/Makefile      2011-06-10 22:11:24.000000000 +0200
16351 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
16352  CFLAGS_REMOVE_irq_work.o = -pg
16353  endif
16354  
16355 +obj-y += vserver/
16356  obj-$(CONFIG_FREEZER) += freezer.o
16357  obj-$(CONFIG_PROFILING) += profile.o
16358  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
16359 diff -NurpP --minimal linux-3.0/kernel/capability.c linux-3.0-vs2.3.1-pre6/kernel/capability.c
16360 --- linux-3.0/kernel/capability.c       2011-07-22 11:18:12.000000000 +0200
16361 +++ linux-3.0-vs2.3.1-pre6/kernel/capability.c  2011-07-19 19:27:53.000000000 +0200
16362 @@ -15,6 +15,7 @@
16363  #include <linux/syscalls.h>
16364  #include <linux/pid_namespace.h>
16365  #include <linux/user_namespace.h>
16366 +#include <linux/vs_context.h>
16367  #include <asm/uaccess.h>
16368  
16369  /*
16370 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
16371         return 0;
16372  }
16373  
16374 +
16375  /*
16376   * The only thing that can change the capabilities of the current
16377   * process is the current process. As such, we can't be in this code
16378 @@ -340,6 +342,8 @@ bool has_capability_noaudit(struct task_
16379         return (ret == 0);
16380  }
16381  
16382 +#include <linux/vserver/base.h>
16383 +
16384  /**
16385   * capable - Determine if the current task has a superior capability in effect
16386   * @cap: The capability to be tested for
16387 @@ -374,6 +378,9 @@ bool ns_capable(struct user_namespace *n
16388                 BUG();
16389         }
16390  
16391 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
16392 +               return true;
16393 +
16394         if (security_capable(ns, current_cred(), cap) == 0) {
16395                 current->flags |= PF_SUPERPRIV;
16396                 return true;
16397 diff -NurpP --minimal linux-3.0/kernel/compat.c linux-3.0-vs2.3.1-pre6/kernel/compat.c
16398 --- linux-3.0/kernel/compat.c   2011-07-22 11:18:12.000000000 +0200
16399 +++ linux-3.0-vs2.3.1-pre6/kernel/compat.c      2011-06-10 22:11:24.000000000 +0200
16400 @@ -970,7 +970,7 @@ asmlinkage long compat_sys_stime(compat_
16401         if (err)
16402                 return err;
16403  
16404 -       do_settimeofday(&tv);
16405 +       vx_settimeofday(&tv);
16406         return 0;
16407  }
16408  
16409 diff -NurpP --minimal linux-3.0/kernel/cred.c linux-3.0-vs2.3.1-pre6/kernel/cred.c
16410 --- linux-3.0/kernel/cred.c     2011-07-22 11:18:12.000000000 +0200
16411 +++ linux-3.0-vs2.3.1-pre6/kernel/cred.c        2011-06-10 22:11:24.000000000 +0200
16412 @@ -61,31 +61,6 @@ struct cred init_cred = {
16413  #endif
16414  };
16415  
16416 -static inline void set_cred_subscribers(struct cred *cred, int n)
16417 -{
16418 -#ifdef CONFIG_DEBUG_CREDENTIALS
16419 -       atomic_set(&cred->subscribers, n);
16420 -#endif
16421 -}
16422 -
16423 -static inline int read_cred_subscribers(const struct cred *cred)
16424 -{
16425 -#ifdef CONFIG_DEBUG_CREDENTIALS
16426 -       return atomic_read(&cred->subscribers);
16427 -#else
16428 -       return 0;
16429 -#endif
16430 -}
16431 -
16432 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
16433 -{
16434 -#ifdef CONFIG_DEBUG_CREDENTIALS
16435 -       struct cred *cred = (struct cred *) _cred;
16436 -
16437 -       atomic_add(n, &cred->subscribers);
16438 -#endif
16439 -}
16440 -
16441  /*
16442   * Dispose of the shared task group credentials
16443   */
16444 @@ -281,21 +256,16 @@ error:
16445   *
16446   * Call commit_creds() or abort_creds() to clean up.
16447   */
16448 -struct cred *prepare_creds(void)
16449 +struct cred *__prepare_creds(const struct cred *old)
16450  {
16451 -       struct task_struct *task = current;
16452 -       const struct cred *old;
16453         struct cred *new;
16454  
16455 -       validate_process_creds();
16456 -
16457         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
16458         if (!new)
16459                 return NULL;
16460  
16461         kdebug("prepare_creds() alloc %p", new);
16462  
16463 -       old = task->cred;
16464         memcpy(new, old, sizeof(struct cred));
16465  
16466         atomic_set(&new->usage, 1);
16467 @@ -322,6 +292,13 @@ error:
16468         abort_creds(new);
16469         return NULL;
16470  }
16471 +
16472 +struct cred *prepare_creds(void)
16473 +{
16474 +       validate_process_creds();
16475 +
16476 +       return __prepare_creds(current->cred);
16477 +}
16478  EXPORT_SYMBOL(prepare_creds);
16479  
16480  /*
16481 diff -NurpP --minimal linux-3.0/kernel/exit.c linux-3.0-vs2.3.1-pre6/kernel/exit.c
16482 --- linux-3.0/kernel/exit.c     2011-07-22 11:18:12.000000000 +0200
16483 +++ linux-3.0-vs2.3.1-pre6/kernel/exit.c        2011-06-22 12:39:15.000000000 +0200
16484 @@ -48,6 +48,10 @@
16485  #include <linux/fs_struct.h>
16486  #include <linux/init_task.h>
16487  #include <linux/perf_event.h>
16488 +#include <linux/vs_limit.h>
16489 +#include <linux/vs_context.h>
16490 +#include <linux/vs_network.h>
16491 +#include <linux/vs_pid.h>
16492  #include <trace/events/sched.h>
16493  #include <linux/hw_breakpoint.h>
16494  #include <linux/oom.h>
16495 @@ -494,9 +498,11 @@ static void close_files(struct files_str
16496                                         filp_close(file, files);
16497                                         cond_resched();
16498                                 }
16499 +                               vx_openfd_dec(i);
16500                         }
16501                         i++;
16502                         set >>= 1;
16503 +                       cond_resched();
16504                 }
16505         }
16506  }
16507 @@ -1047,11 +1053,16 @@ NORET_TYPE void do_exit(long code)
16508  
16509         validate_creds_for_do_exit(tsk);
16510  
16511 +       /* needs to stay after exit_notify() */
16512 +       exit_vx_info(tsk, code);
16513 +       exit_nx_info(tsk);
16514 +
16515         preempt_disable();
16516         exit_rcu();
16517         /* causes final put_task_struct in finish_task_switch(). */
16518         tsk->state = TASK_DEAD;
16519         schedule();
16520 +       printk("bad task: %p [%lx]\n", current, current->state);
16521         BUG();
16522         /* Avoid "noreturn function does return".  */
16523         for (;;)
16524 diff -NurpP --minimal linux-3.0/kernel/fork.c linux-3.0-vs2.3.1-pre6/kernel/fork.c
16525 --- linux-3.0/kernel/fork.c     2011-07-22 11:18:12.000000000 +0200
16526 +++ linux-3.0-vs2.3.1-pre6/kernel/fork.c        2011-06-10 22:21:02.000000000 +0200
16527 @@ -67,6 +67,10 @@
16528  #include <linux/user-return-notifier.h>
16529  #include <linux/oom.h>
16530  #include <linux/khugepaged.h>
16531 +#include <linux/vs_context.h>
16532 +#include <linux/vs_network.h>
16533 +#include <linux/vs_limit.h>
16534 +#include <linux/vs_memory.h>
16535  
16536  #include <asm/pgtable.h>
16537  #include <asm/pgalloc.h>
16538 @@ -167,6 +171,8 @@ void free_task(struct task_struct *tsk)
16539         account_kernel_stack(tsk->stack, -1);
16540         free_thread_info(tsk->stack);
16541         rt_mutex_debug_task_free(tsk);
16542 +       clr_vx_info(&tsk->vx_info);
16543 +       clr_nx_info(&tsk->nx_info);
16544         ftrace_graph_exit_task(tsk);
16545         free_task_struct(tsk);
16546  }
16547 @@ -505,6 +511,7 @@ static struct mm_struct * mm_init(struct
16548         if (likely(!mm_alloc_pgd(mm))) {
16549                 mm->def_flags = 0;
16550                 mmu_notifier_mm_init(mm);
16551 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
16552                 return mm;
16553         }
16554  
16555 @@ -542,6 +549,7 @@ void __mmdrop(struct mm_struct *mm)
16556  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
16557         VM_BUG_ON(mm->pmd_huge_pte);
16558  #endif
16559 +       clr_vx_info(&mm->mm_vx_info);
16560         free_mm(mm);
16561  }
16562  EXPORT_SYMBOL_GPL(__mmdrop);
16563 @@ -729,6 +737,7 @@ struct mm_struct *dup_mm(struct task_str
16564                 goto fail_nomem;
16565  
16566         memcpy(mm, oldmm, sizeof(*mm));
16567 +       mm->mm_vx_info = NULL;
16568         mm_init_cpumask(mm);
16569  
16570         /* Initializing for Swap token stuff */
16571 @@ -772,6 +781,7 @@ fail_nocontext:
16572          * If init_new_context() failed, we cannot use mmput() to free the mm
16573          * because it calls destroy_context()
16574          */
16575 +       clr_vx_info(&mm->mm_vx_info);
16576         mm_free_pgd(mm);
16577         free_mm(mm);
16578         return NULL;
16579 @@ -1057,6 +1067,8 @@ static struct task_struct *copy_process(
16580         int retval;
16581         struct task_struct *p;
16582         int cgroup_callbacks_done = 0;
16583 +       struct vx_info *vxi;
16584 +       struct nx_info *nxi;
16585  
16586         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
16587                 return ERR_PTR(-EINVAL);
16588 @@ -1103,7 +1115,12 @@ static struct task_struct *copy_process(
16589         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
16590         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
16591  #endif
16592 +       init_vx_info(&p->vx_info, current_vx_info());
16593 +       init_nx_info(&p->nx_info, current_nx_info());
16594 +
16595         retval = -EAGAIN;
16596 +       if (!vx_nproc_avail(1))
16597 +               goto bad_fork_free;
16598         if (atomic_read(&p->real_cred->user->processes) >=
16599                         task_rlimit(p, RLIMIT_NPROC)) {
16600                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
16601 @@ -1360,6 +1377,18 @@ static struct task_struct *copy_process(
16602  
16603         total_forks++;
16604         spin_unlock(&current->sighand->siglock);
16605 +
16606 +       /* p is copy of current */
16607 +       vxi = p->vx_info;
16608 +       if (vxi) {
16609 +               claim_vx_info(vxi, p);
16610 +               atomic_inc(&vxi->cvirt.nr_threads);
16611 +               atomic_inc(&vxi->cvirt.total_forks);
16612 +               vx_nproc_inc(p);
16613 +       }
16614 +       nxi = p->nx_info;
16615 +       if (nxi)
16616 +               claim_nx_info(nxi, p);
16617         write_unlock_irq(&tasklist_lock);
16618         proc_fork_connector(p);
16619         cgroup_post_fork(p);
16620 diff -NurpP --minimal linux-3.0/kernel/kthread.c linux-3.0-vs2.3.1-pre6/kernel/kthread.c
16621 --- linux-3.0/kernel/kthread.c  2011-07-22 11:18:12.000000000 +0200
16622 +++ linux-3.0-vs2.3.1-pre6/kernel/kthread.c     2011-06-10 22:11:24.000000000 +0200
16623 @@ -16,6 +16,7 @@
16624  #include <linux/mutex.h>
16625  #include <linux/slab.h>
16626  #include <linux/freezer.h>
16627 +#include <linux/vs_pid.h>
16628  #include <trace/events/sched.h>
16629  
16630  static DEFINE_SPINLOCK(kthread_create_lock);
16631 diff -NurpP --minimal linux-3.0/kernel/nsproxy.c linux-3.0-vs2.3.1-pre6/kernel/nsproxy.c
16632 --- linux-3.0/kernel/nsproxy.c  2011-07-22 11:18:12.000000000 +0200
16633 +++ linux-3.0-vs2.3.1-pre6/kernel/nsproxy.c     2011-06-13 14:09:44.000000000 +0200
16634 @@ -20,6 +20,8 @@
16635  #include <linux/mnt_namespace.h>
16636  #include <linux/utsname.h>
16637  #include <linux/pid_namespace.h>
16638 +#include <linux/vserver/global.h>
16639 +#include <linux/vserver/debug.h>
16640  #include <net/net_namespace.h>
16641  #include <linux/ipc_namespace.h>
16642  #include <linux/proc_fs.h>
16643 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
16644         struct nsproxy *nsproxy;
16645  
16646         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
16647 -       if (nsproxy)
16648 +       if (nsproxy) {
16649                 atomic_set(&nsproxy->count, 1);
16650 +               atomic_inc(&vs_global_nsproxy);
16651 +       }
16652 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
16653         return nsproxy;
16654  }
16655  
16656 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
16657   * Return the newly created nsproxy.  Do not attach this to the task,
16658   * leave it to the caller to do proper locking and attach it to task.
16659   */
16660 -static struct nsproxy *create_new_namespaces(unsigned long flags,
16661 -                       struct task_struct *tsk, struct fs_struct *new_fs)
16662 +static struct nsproxy *unshare_namespaces(unsigned long flags,
16663 +                       struct nsproxy *orig,
16664 +                       struct fs_struct *new_fs,
16665 +                       struct user_namespace *new_user,
16666 +                       struct pid_namespace *new_pid)
16667  {
16668         struct nsproxy *new_nsp;
16669         int err;
16670 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
16671         if (!new_nsp)
16672                 return ERR_PTR(-ENOMEM);
16673  
16674 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
16675 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
16676         if (IS_ERR(new_nsp->mnt_ns)) {
16677                 err = PTR_ERR(new_nsp->mnt_ns);
16678                 goto out_ns;
16679         }
16680  
16681 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
16682 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
16683         if (IS_ERR(new_nsp->uts_ns)) {
16684                 err = PTR_ERR(new_nsp->uts_ns);
16685                 goto out_uts;
16686         }
16687  
16688 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
16689 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
16690         if (IS_ERR(new_nsp->ipc_ns)) {
16691                 err = PTR_ERR(new_nsp->ipc_ns);
16692                 goto out_ipc;
16693         }
16694  
16695 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
16696 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
16697         if (IS_ERR(new_nsp->pid_ns)) {
16698                 err = PTR_ERR(new_nsp->pid_ns);
16699                 goto out_pid;
16700         }
16701  
16702 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
16703 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
16704         if (IS_ERR(new_nsp->net_ns)) {
16705                 err = PTR_ERR(new_nsp->net_ns);
16706                 goto out_net;
16707 @@ -115,6 +123,40 @@ out_ns:
16708         return ERR_PTR(err);
16709  }
16710  
16711 +static struct nsproxy *create_new_namespaces(unsigned long flags,
16712 +                       struct task_struct *tsk, struct fs_struct *new_fs)
16713 +{
16714 +       return unshare_namespaces(flags, tsk->nsproxy,
16715 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
16716 +               task_active_pid_ns(tsk));
16717 +}
16718 +
16719 +/*
16720 + * copies the nsproxy, setting refcount to 1, and grabbing a
16721 + * reference to all contained namespaces.
16722 + */
16723 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
16724 +{
16725 +       struct nsproxy *ns = create_nsproxy();
16726 +
16727 +       if (ns) {
16728 +               memcpy(ns, orig, sizeof(struct nsproxy));
16729 +               atomic_set(&ns->count, 1);
16730 +
16731 +               if (ns->mnt_ns)
16732 +                       get_mnt_ns(ns->mnt_ns);
16733 +               if (ns->uts_ns)
16734 +                       get_uts_ns(ns->uts_ns);
16735 +               if (ns->ipc_ns)
16736 +                       get_ipc_ns(ns->ipc_ns);
16737 +               if (ns->pid_ns)
16738 +                       get_pid_ns(ns->pid_ns);
16739 +               if (ns->net_ns)
16740 +                       get_net(ns->net_ns);
16741 +       }
16742 +       return ns;
16743 +}
16744 +
16745  /*
16746   * called from clone.  This now handles copy for nsproxy and all
16747   * namespaces therein.
16748 @@ -122,9 +164,12 @@ out_ns:
16749  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
16750  {
16751         struct nsproxy *old_ns = tsk->nsproxy;
16752 -       struct nsproxy *new_ns;
16753 +       struct nsproxy *new_ns = NULL;
16754         int err = 0;
16755  
16756 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
16757 +               flags, tsk, old_ns);
16758 +
16759         if (!old_ns)
16760                 return 0;
16761  
16762 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
16763                                 CLONE_NEWPID | CLONE_NEWNET)))
16764                 return 0;
16765  
16766 -       if (!capable(CAP_SYS_ADMIN)) {
16767 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
16768                 err = -EPERM;
16769                 goto out;
16770         }
16771 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
16772  
16773  out:
16774         put_nsproxy(old_ns);
16775 +       vxdprintk(VXD_CBIT(space, 3),
16776 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
16777 +               flags, tsk, old_ns, err, new_ns);
16778         return err;
16779  }
16780  
16781 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
16782                 put_ipc_ns(ns->ipc_ns);
16783         if (ns->pid_ns)
16784                 put_pid_ns(ns->pid_ns);
16785 -       put_net(ns->net_ns);
16786 +       if (ns->net_ns)
16787 +               put_net(ns->net_ns);
16788 +       atomic_dec(&vs_global_nsproxy);
16789         kmem_cache_free(nsproxy_cachep, ns);
16790  }
16791  
16792 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
16793  {
16794         int err = 0;
16795  
16796 +       vxdprintk(VXD_CBIT(space, 4),
16797 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
16798 +               unshare_flags, current->nsproxy);
16799 +
16800         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
16801                                CLONE_NEWNET)))
16802                 return 0;
16803  
16804 -       if (!capable(CAP_SYS_ADMIN))
16805 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
16806                 return -EPERM;
16807  
16808         *new_nsp = create_new_namespaces(unshare_flags, current,
16809 diff -NurpP --minimal linux-3.0/kernel/pid.c linux-3.0-vs2.3.1-pre6/kernel/pid.c
16810 --- linux-3.0/kernel/pid.c      2011-05-22 16:17:59.000000000 +0200
16811 +++ linux-3.0-vs2.3.1-pre6/kernel/pid.c 2011-06-10 22:11:24.000000000 +0200
16812 @@ -36,6 +36,7 @@
16813  #include <linux/pid_namespace.h>
16814  #include <linux/init_task.h>
16815  #include <linux/syscalls.h>
16816 +#include <linux/vs_pid.h>
16817  
16818  #define pid_hashfn(nr, ns)     \
16819         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
16820 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
16821  
16822  struct pid *find_vpid(int nr)
16823  {
16824 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
16825 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
16826  }
16827  EXPORT_SYMBOL_GPL(find_vpid);
16828  
16829 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
16830  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
16831  {
16832         struct task_struct *result = NULL;
16833 +
16834 +       if (type == PIDTYPE_REALPID)
16835 +               type = PIDTYPE_PID;
16836         if (pid) {
16837                 struct hlist_node *first;
16838                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
16839 @@ -420,7 +424,7 @@ EXPORT_SYMBOL(pid_task);
16840  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
16841  {
16842         rcu_lockdep_assert(rcu_read_lock_held());
16843 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
16844 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
16845  }
16846  
16847  struct task_struct *find_task_by_vpid(pid_t vnr)
16848 @@ -464,7 +468,7 @@ struct pid *find_get_pid(pid_t nr)
16849  }
16850  EXPORT_SYMBOL_GPL(find_get_pid);
16851  
16852 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
16853 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
16854  {
16855         struct upid *upid;
16856         pid_t nr = 0;
16857 @@ -477,6 +481,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
16858         return nr;
16859  }
16860  
16861 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
16862 +{
16863 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
16864 +}
16865 +
16866  pid_t pid_vnr(struct pid *pid)
16867  {
16868         return pid_nr_ns(pid, current->nsproxy->pid_ns);
16869 diff -NurpP --minimal linux-3.0/kernel/pid_namespace.c linux-3.0-vs2.3.1-pre6/kernel/pid_namespace.c
16870 --- linux-3.0/kernel/pid_namespace.c    2011-05-22 16:17:59.000000000 +0200
16871 +++ linux-3.0-vs2.3.1-pre6/kernel/pid_namespace.c       2011-06-10 22:17:45.000000000 +0200
16872 @@ -15,6 +15,7 @@
16873  #include <linux/acct.h>
16874  #include <linux/slab.h>
16875  #include <linux/proc_fs.h>
16876 +#include <linux/vserver/global.h>
16877  
16878  #define BITS_PER_PAGE          (PAGE_SIZE*8)
16879  
16880 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
16881                 goto out_free_map;
16882  
16883         kref_init(&ns->kref);
16884 +       atomic_inc(&vs_global_pid_ns);
16885         ns->level = level;
16886         ns->parent = get_pid_ns(parent_pid_ns);
16887  
16888 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
16889  
16890         for (i = 0; i < PIDMAP_ENTRIES; i++)
16891                 kfree(ns->pidmap[i].page);
16892 +       atomic_dec(&vs_global_pid_ns);
16893         kmem_cache_free(pid_ns_cachep, ns);
16894  }
16895  
16896 diff -NurpP --minimal linux-3.0/kernel/posix-timers.c linux-3.0-vs2.3.1-pre6/kernel/posix-timers.c
16897 --- linux-3.0/kernel/posix-timers.c     2011-07-22 11:18:12.000000000 +0200
16898 +++ linux-3.0-vs2.3.1-pre6/kernel/posix-timers.c        2011-06-10 22:11:24.000000000 +0200
16899 @@ -47,6 +47,7 @@
16900  #include <linux/wait.h>
16901  #include <linux/workqueue.h>
16902  #include <linux/module.h>
16903 +#include <linux/vs_context.h>
16904  
16905  /*
16906   * Management arrays for POSIX timers.  Timers are kept in slab memory
16907 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
16908  {
16909         struct task_struct *task;
16910         int shared, ret = -1;
16911 +
16912         /*
16913          * FIXME: if ->sigq is queued we can race with
16914          * dequeue_signal()->do_schedule_next_timer().
16915 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
16916         rcu_read_lock();
16917         task = pid_task(timr->it_pid, PIDTYPE_PID);
16918         if (task) {
16919 +               struct vx_info_save vxis;
16920 +               struct vx_info *vxi;
16921 +
16922 +               vxi = get_vx_info(task->vx_info);
16923 +               enter_vx_info(vxi, &vxis);
16924                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
16925                 ret = send_sigqueue(timr->sigq, task, shared);
16926 +               leave_vx_info(&vxis);
16927 +               put_vx_info(vxi);
16928         }
16929         rcu_read_unlock();
16930 +
16931         /* If we failed to send the signal the timer stops. */
16932         return ret > 0;
16933  }
16934 diff -NurpP --minimal linux-3.0/kernel/printk.c linux-3.0-vs2.3.1-pre6/kernel/printk.c
16935 --- linux-3.0/kernel/printk.c   2011-07-22 11:18:12.000000000 +0200
16936 +++ linux-3.0-vs2.3.1-pre6/kernel/printk.c      2011-06-10 22:11:24.000000000 +0200
16937 @@ -41,6 +41,7 @@
16938  #include <linux/cpu.h>
16939  #include <linux/notifier.h>
16940  #include <linux/rculist.h>
16941 +#include <linux/vs_cvirt.h>
16942  
16943  #include <asm/uaccess.h>
16944  
16945 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
16946                 return 0;
16947  
16948         if (syslog_action_restricted(type)) {
16949 -               if (capable(CAP_SYSLOG))
16950 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
16951                         return 0;
16952                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
16953                 if (capable(CAP_SYS_ADMIN)) {
16954 @@ -342,12 +343,9 @@ int do_syslog(int type, char __user *buf
16955         if (error)
16956                 return error;
16957  
16958 -       switch (type) {
16959 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
16960 -               break;
16961 -       case SYSLOG_ACTION_OPEN:        /* Open log */
16962 -               break;
16963 -       case SYSLOG_ACTION_READ:        /* Read from log */
16964 +       if ((type == SYSLOG_ACTION_READ) ||
16965 +           (type == SYSLOG_ACTION_READ_ALL) ||
16966 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
16967                 error = -EINVAL;
16968                 if (!buf || len < 0)
16969                         goto out;
16970 @@ -358,6 +356,16 @@ int do_syslog(int type, char __user *buf
16971                         error = -EFAULT;
16972                         goto out;
16973                 }
16974 +       }
16975 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16976 +               return vx_do_syslog(type, buf, len);
16977 +
16978 +       switch (type) {
16979 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
16980 +               break;
16981 +       case SYSLOG_ACTION_OPEN:        /* Open log */
16982 +               break;
16983 +       case SYSLOG_ACTION_READ:        /* Read from log */
16984                 error = wait_event_interruptible(log_wait,
16985                                                         (log_start - log_end));
16986                 if (error)
16987 @@ -384,16 +392,6 @@ int do_syslog(int type, char __user *buf
16988                 /* FALL THRU */
16989         /* Read last kernel messages */
16990         case SYSLOG_ACTION_READ_ALL:
16991 -               error = -EINVAL;
16992 -               if (!buf || len < 0)
16993 -                       goto out;
16994 -               error = 0;
16995 -               if (!len)
16996 -                       goto out;
16997 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16998 -                       error = -EFAULT;
16999 -                       goto out;
17000 -               }
17001                 count = len;
17002                 if (count > log_buf_len)
17003                         count = log_buf_len;
17004 diff -NurpP --minimal linux-3.0/kernel/ptrace.c linux-3.0-vs2.3.1-pre6/kernel/ptrace.c
17005 --- linux-3.0/kernel/ptrace.c   2011-07-22 11:18:12.000000000 +0200
17006 +++ linux-3.0-vs2.3.1-pre6/kernel/ptrace.c      2011-06-10 22:11:24.000000000 +0200
17007 @@ -22,6 +22,7 @@
17008  #include <linux/syscalls.h>
17009  #include <linux/uaccess.h>
17010  #include <linux/regset.h>
17011 +#include <linux/vs_context.h>
17012  #include <linux/hw_breakpoint.h>
17013  
17014  
17015 @@ -169,6 +170,11 @@ ok:
17016                 dumpable = get_dumpable(task->mm);
17017         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
17018                 return -EPERM;
17019 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
17020 +               return -EPERM;
17021 +       if (!vx_check(task->xid, VS_IDENT) &&
17022 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
17023 +               return -EACCES;
17024  
17025         return security_ptrace_access_check(task, mode);
17026  }
17027 diff -NurpP --minimal linux-3.0/kernel/sched.c linux-3.0-vs2.3.1-pre6/kernel/sched.c
17028 --- linux-3.0/kernel/sched.c    2011-07-22 11:18:12.000000000 +0200
17029 +++ linux-3.0-vs2.3.1-pre6/kernel/sched.c       2011-07-22 11:20:39.000000000 +0200
17030 @@ -71,6 +71,8 @@
17031  #include <linux/ctype.h>
17032  #include <linux/ftrace.h>
17033  #include <linux/slab.h>
17034 +#include <linux/vs_sched.h>
17035 +#include <linux/vs_cvirt.h>
17036  
17037  #include <asm/tlb.h>
17038  #include <asm/irq_regs.h>
17039 @@ -3461,9 +3463,17 @@ static void calc_global_nohz(unsigned lo
17040   */
17041  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
17042  {
17043 -       loads[0] = (avenrun[0] + offset) << shift;
17044 -       loads[1] = (avenrun[1] + offset) << shift;
17045 -       loads[2] = (avenrun[2] + offset) << shift;
17046 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
17047 +               struct vx_info *vxi = current_vx_info();
17048 +
17049 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
17050 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
17051 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
17052 +       } else {
17053 +               loads[0] = (avenrun[0] + offset) << shift;
17054 +               loads[1] = (avenrun[1] + offset) << shift;
17055 +               loads[2] = (avenrun[2] + offset) << shift;
17056 +       }
17057  }
17058  
17059  /*
17060 @@ -3746,16 +3756,19 @@ void account_user_time(struct task_struc
17061                        cputime_t cputime_scaled)
17062  {
17063         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
17064 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
17065         cputime64_t tmp;
17066 +       int nice = (TASK_NICE(p) > 0);
17067  
17068         /* Add user time to process. */
17069         p->utime = cputime_add(p->utime, cputime);
17070         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
17071 +       vx_account_user(vxi, cputime, nice);
17072         account_group_user_time(p, cputime);
17073  
17074         /* Add user time to cpustat. */
17075         tmp = cputime_to_cputime64(cputime);
17076 -       if (TASK_NICE(p) > 0)
17077 +       if (nice)
17078                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
17079         else
17080                 cpustat->user = cputime64_add(cpustat->user, tmp);
17081 @@ -3807,10 +3820,12 @@ void __account_system_time(struct task_s
17082                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
17083  {
17084         cputime64_t tmp = cputime_to_cputime64(cputime);
17085 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
17086  
17087         /* Add system time to process. */
17088         p->stime = cputime_add(p->stime, cputime);
17089         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
17090 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
17091         account_group_system_time(p, cputime);
17092  
17093         /* Add system time to cpustat. */
17094 @@ -4968,7 +4983,7 @@ SYSCALL_DEFINE1(nice, int, increment)
17095                 nice = 19;
17096  
17097         if (increment < 0 && !can_nice(current, nice))
17098 -               return -EPERM;
17099 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
17100  
17101         retval = security_task_setnice(current, nice);
17102         if (retval)
17103 diff -NurpP --minimal linux-3.0/kernel/sched_fair.c linux-3.0-vs2.3.1-pre6/kernel/sched_fair.c
17104 --- linux-3.0/kernel/sched_fair.c       2011-07-22 11:18:12.000000000 +0200
17105 +++ linux-3.0-vs2.3.1-pre6/kernel/sched_fair.c  2011-07-22 11:20:39.000000000 +0200
17106 @@ -998,6 +998,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
17107                 __enqueue_entity(cfs_rq, se);
17108         se->on_rq = 1;
17109  
17110 +       if (entity_is_task(se))
17111 +               vx_activate_task(task_of(se));
17112         if (cfs_rq->nr_running == 1)
17113                 list_add_leaf_cfs_rq(cfs_rq);
17114  }
17115 @@ -1074,6 +1076,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
17116         if (se != cfs_rq->curr)
17117                 __dequeue_entity(cfs_rq, se);
17118         se->on_rq = 0;
17119 +       if (entity_is_task(se))
17120 +               vx_deactivate_task(task_of(se));
17121         update_cfs_load(cfs_rq, 0);
17122         account_entity_dequeue(cfs_rq, se);
17123  
17124 diff -NurpP --minimal linux-3.0/kernel/signal.c linux-3.0-vs2.3.1-pre6/kernel/signal.c
17125 --- linux-3.0/kernel/signal.c   2011-07-22 11:18:12.000000000 +0200
17126 +++ linux-3.0-vs2.3.1-pre6/kernel/signal.c      2011-07-22 11:20:39.000000000 +0200
17127 @@ -28,6 +28,8 @@
17128  #include <linux/freezer.h>
17129  #include <linux/pid_namespace.h>
17130  #include <linux/nsproxy.h>
17131 +#include <linux/vs_context.h>
17132 +#include <linux/vs_pid.h>
17133  #define CREATE_TRACE_POINTS
17134  #include <trace/events/signal.h>
17135  
17136 @@ -744,9 +746,18 @@ static int check_kill_permission(int sig
17137         struct pid *sid;
17138         int error;
17139  
17140 +       vxdprintk(VXD_CBIT(misc, 7),
17141 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17142 +               sig, info, t, vx_task_xid(t), t->pid);
17143 +
17144         if (!valid_signal(sig))
17145                 return -EINVAL;
17146  
17147 +/*     FIXME: needed? if so, why?
17148 +       if ((info != SEND_SIG_NOINFO) &&
17149 +               (is_si_special(info) || !si_fromuser(info)))
17150 +               goto skip;      */
17151 +
17152         if (!si_fromuser(info))
17153                 return 0;
17154  
17155 @@ -770,6 +781,20 @@ static int check_kill_permission(int sig
17156                 }
17157         }
17158  
17159 +       error = -EPERM;
17160 +       if (t->pid == 1 && current->xid)
17161 +               return error;
17162 +
17163 +       error = -ESRCH;
17164 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
17165 +                 loops, maybe ENOENT or EACCES? */
17166 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17167 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17168 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17169 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17170 +               return error;
17171 +       }
17172 +/* skip: */
17173         return security_task_kill(t, info, sig, 0);
17174  }
17175  
17176 @@ -1246,7 +1271,7 @@ int kill_pid_info(int sig, struct siginf
17177         rcu_read_lock();
17178  retry:
17179         p = pid_task(pid, PIDTYPE_PID);
17180 -       if (p) {
17181 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
17182                 error = group_send_sig_info(sig, info, p);
17183                 if (unlikely(error == -ESRCH))
17184                         /*
17185 @@ -1285,7 +1310,7 @@ int kill_pid_info_as_uid(int sig, struct
17186  
17187         rcu_read_lock();
17188         p = pid_task(pid, PIDTYPE_PID);
17189 -       if (!p) {
17190 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
17191                 ret = -ESRCH;
17192                 goto out_unlock;
17193         }
17194 @@ -1340,8 +1365,10 @@ static int kill_something_info(int sig, 
17195                 struct task_struct * p;
17196  
17197                 for_each_process(p) {
17198 -                       if (task_pid_vnr(p) > 1 &&
17199 -                                       !same_thread_group(p, current)) {
17200 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
17201 +                               task_pid_vnr(p) > 1 &&
17202 +                               !same_thread_group(p, current) &&
17203 +                               !vx_current_initpid(p->pid)) {
17204                                 int err = group_send_sig_info(sig, info, p);
17205                                 ++count;
17206                                 if (err != -EPERM)
17207 @@ -2140,6 +2167,11 @@ relock:
17208                                 !sig_kernel_only(signr))
17209                         continue;
17210  
17211 +               /* virtual init is protected against user signals */
17212 +               if ((info->si_code == SI_USER) &&
17213 +                       vx_current_initpid(current->pid))
17214 +                       continue;
17215 +
17216                 if (sig_kernel_stop(signr)) {
17217                         /*
17218                          * The default action is to stop all threads in
17219 diff -NurpP --minimal linux-3.0/kernel/softirq.c linux-3.0-vs2.3.1-pre6/kernel/softirq.c
17220 --- linux-3.0/kernel/softirq.c  2011-07-22 11:18:12.000000000 +0200
17221 +++ linux-3.0-vs2.3.1-pre6/kernel/softirq.c     2011-07-22 11:20:39.000000000 +0200
17222 @@ -24,6 +24,7 @@
17223  #include <linux/ftrace.h>
17224  #include <linux/smp.h>
17225  #include <linux/tick.h>
17226 +#include <linux/vs_context.h>
17227  
17228  #define CREATE_TRACE_POINTS
17229  #include <trace/events/irq.h>
17230 diff -NurpP --minimal linux-3.0/kernel/sys.c linux-3.0-vs2.3.1-pre6/kernel/sys.c
17231 --- linux-3.0/kernel/sys.c      2011-07-22 11:18:12.000000000 +0200
17232 +++ linux-3.0-vs2.3.1-pre6/kernel/sys.c 2011-07-23 03:31:10.000000000 +0200
17233 @@ -43,6 +43,7 @@
17234  #include <linux/syscalls.h>
17235  #include <linux/kprobes.h>
17236  #include <linux/user_namespace.h>
17237 +#include <linux/vs_pid.h>
17238  
17239  #include <linux/kmsg_dump.h>
17240  
17241 @@ -151,7 +152,10 @@ static int set_one_prio(struct task_stru
17242                 goto out;
17243         }
17244         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17245 -               error = -EACCES;
17246 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17247 +                       error = 0;
17248 +               else
17249 +                       error = -EACCES;
17250                 goto out;
17251         }
17252         no_nice = security_task_setnice(p, niceval);
17253 @@ -201,6 +205,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
17254                         else
17255                                 pgrp = task_pgrp(current);
17256                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17257 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17258 +                                       continue;
17259                                 error = set_one_prio(p, niceval, error);
17260                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
17261                         break;
17262 @@ -264,6 +270,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
17263                         else
17264                                 pgrp = task_pgrp(current);
17265                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17266 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17267 +                                       continue;
17268                                 niceval = 20 - task_nice(p);
17269                                 if (niceval > retval)
17270                                         retval = niceval;
17271 @@ -383,6 +391,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
17272  
17273  static DEFINE_MUTEX(reboot_mutex);
17274  
17275 +long vs_reboot(unsigned int, void __user *);
17276 +
17277  /*
17278   * Reboot system call: for obvious reasons only root may call it,
17279   * and even root needs to set up some magic numbers in the registers
17280 @@ -415,6 +425,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
17281         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17282                 cmd = LINUX_REBOOT_CMD_HALT;
17283  
17284 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17285 +               return vs_reboot(cmd, arg);
17286 +
17287         mutex_lock(&reboot_mutex);
17288         switch (cmd) {
17289         case LINUX_REBOOT_CMD_RESTART:
17290 @@ -1197,7 +1210,8 @@ SYSCALL_DEFINE2(sethostname, char __user
17291         int errno;
17292         char tmp[__NEW_UTS_LEN];
17293  
17294 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
17295 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
17296 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17297                 return -EPERM;
17298  
17299         if (len < 0 || len > __NEW_UTS_LEN)
17300 @@ -1247,7 +1261,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
17301         int errno;
17302         char tmp[__NEW_UTS_LEN];
17303  
17304 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
17305 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
17306 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17307                 return -EPERM;
17308         if (len < 0 || len > __NEW_UTS_LEN)
17309                 return -EINVAL;
17310 @@ -1365,7 +1380,7 @@ int do_prlimit(struct task_struct *tsk, 
17311                 /* Keep the capable check against init_user_ns until
17312                    cgroups can contain all limits */
17313                 if (new_rlim->rlim_max > rlim->rlim_max &&
17314 -                               !capable(CAP_SYS_RESOURCE))
17315 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17316                         retval = -EPERM;
17317                 if (!retval)
17318                         retval = security_task_setrlimit(tsk->group_leader,
17319 diff -NurpP --minimal linux-3.0/kernel/sysctl.c linux-3.0-vs2.3.1-pre6/kernel/sysctl.c
17320 --- linux-3.0/kernel/sysctl.c   2011-07-22 11:18:12.000000000 +0200
17321 +++ linux-3.0-vs2.3.1-pre6/kernel/sysctl.c      2011-06-15 02:40:14.000000000 +0200
17322 @@ -75,6 +75,7 @@
17323  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
17324  #include <linux/lockdep.h>
17325  #endif
17326 +extern char vshelper_path[];
17327  #ifdef CONFIG_CHR_DEV_SG
17328  #include <scsi/sg.h>
17329  #endif
17330 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
17331                 .proc_handler   = proc_dostring,
17332         },
17333  #endif
17334 +       {
17335 +               .procname       = "vshelper",
17336 +               .data           = &vshelper_path,
17337 +               .maxlen         = 256,
17338 +               .mode           = 0644,
17339 +               .proc_handler   = &proc_dostring,
17340 +       },
17341  #ifdef CONFIG_CHR_DEV_SG
17342         {
17343                 .procname       = "sg-big-buff",
17344 diff -NurpP --minimal linux-3.0/kernel/sysctl_binary.c linux-3.0-vs2.3.1-pre6/kernel/sysctl_binary.c
17345 --- linux-3.0/kernel/sysctl_binary.c    2011-05-22 16:17:59.000000000 +0200
17346 +++ linux-3.0-vs2.3.1-pre6/kernel/sysctl_binary.c       2011-06-10 22:11:24.000000000 +0200
17347 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
17348  
17349         { CTL_INT,      KERN_PANIC,                     "panic" },
17350         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
17351 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
17352  
17353         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
17354         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
17355 diff -NurpP --minimal linux-3.0/kernel/time/timekeeping.c linux-3.0-vs2.3.1-pre6/kernel/time/timekeeping.c
17356 --- linux-3.0/kernel/time/timekeeping.c 2011-07-22 11:18:12.000000000 +0200
17357 +++ linux-3.0-vs2.3.1-pre6/kernel/time/timekeeping.c    2011-06-10 22:11:24.000000000 +0200
17358 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
17359         } while (read_seqretry(&xtime_lock, seq));
17360  
17361         timespec_add_ns(ts, nsecs);
17362 +       vx_adjust_timespec(ts);
17363  }
17364  
17365  EXPORT_SYMBOL(getnstimeofday);
17366 diff -NurpP --minimal linux-3.0/kernel/time.c linux-3.0-vs2.3.1-pre6/kernel/time.c
17367 --- linux-3.0/kernel/time.c     2011-05-22 16:17:59.000000000 +0200
17368 +++ linux-3.0-vs2.3.1-pre6/kernel/time.c        2011-06-10 22:11:24.000000000 +0200
17369 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17370         if (err)
17371                 return err;
17372  
17373 -       do_settimeofday(&tv);
17374 +       vx_settimeofday(&tv);
17375         return 0;
17376  }
17377  
17378 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
17379                 /* SMP safe, again the code in arch/foo/time.c should
17380                  * globally block out interrupts when it runs.
17381                  */
17382 -               return do_settimeofday(tv);
17383 +               return vx_settimeofday(tv);
17384         }
17385         return 0;
17386  }
17387 diff -NurpP --minimal linux-3.0/kernel/timer.c linux-3.0-vs2.3.1-pre6/kernel/timer.c
17388 --- linux-3.0/kernel/timer.c    2011-07-22 11:18:12.000000000 +0200
17389 +++ linux-3.0-vs2.3.1-pre6/kernel/timer.c       2011-06-15 02:40:14.000000000 +0200
17390 @@ -40,6 +40,10 @@
17391  #include <linux/irq_work.h>
17392  #include <linux/sched.h>
17393  #include <linux/slab.h>
17394 +#include <linux/vs_base.h>
17395 +#include <linux/vs_cvirt.h>
17396 +#include <linux/vs_pid.h>
17397 +#include <linux/vserver/sched.h>
17398  
17399  #include <asm/uaccess.h>
17400  #include <asm/unistd.h>
17401 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17402  
17403  #endif
17404  
17405 -#ifndef __alpha__
17406 -
17407 -/*
17408 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17409 - * should be moved into arch/i386 instead?
17410 - */
17411  
17412  /**
17413   * sys_getpid - return the thread group id of the current process
17414 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
17415         rcu_read_lock();
17416         pid = task_tgid_vnr(current->real_parent);
17417         rcu_read_unlock();
17418 +       return vx_map_pid(pid);
17419 +}
17420  
17421 -       return pid;
17422 +#ifdef __alpha__
17423 +
17424 +/*
17425 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17426 + */
17427 +
17428 +asmlinkage long do_getxpid(long *ppid)
17429 +{
17430 +       *ppid = sys_getppid();
17431 +       return sys_getpid();
17432  }
17433  
17434 +#else /* _alpha_ */
17435 +
17436  SYSCALL_DEFINE0(getuid)
17437  {
17438         /* Only we change this so SMP safe */
17439 diff -NurpP --minimal linux-3.0/kernel/user_namespace.c linux-3.0-vs2.3.1-pre6/kernel/user_namespace.c
17440 --- linux-3.0/kernel/user_namespace.c   2011-03-15 18:07:42.000000000 +0100
17441 +++ linux-3.0-vs2.3.1-pre6/kernel/user_namespace.c      2011-06-10 22:11:24.000000000 +0200
17442 @@ -11,6 +11,7 @@
17443  #include <linux/user_namespace.h>
17444  #include <linux/highuid.h>
17445  #include <linux/cred.h>
17446 +#include <linux/vserver/global.h>
17447  
17448  static struct kmem_cache *user_ns_cachep __read_mostly;
17449  
17450 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
17451                 return -ENOMEM;
17452  
17453         kref_init(&ns->kref);
17454 +       atomic_inc(&vs_global_user_ns);
17455  
17456         for (n = 0; n < UIDHASH_SZ; ++n)
17457                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17458 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
17459         struct user_namespace *ns =
17460                 container_of(kref, struct user_namespace, kref);
17461  
17462 +       /* FIXME: maybe move into destroyer? */
17463 +       atomic_dec(&vs_global_user_ns);
17464         INIT_WORK(&ns->destroyer, free_user_ns_work);
17465         schedule_work(&ns->destroyer);
17466  }
17467 diff -NurpP --minimal linux-3.0/kernel/utsname.c linux-3.0-vs2.3.1-pre6/kernel/utsname.c
17468 --- linux-3.0/kernel/utsname.c  2011-07-22 11:18:12.000000000 +0200
17469 +++ linux-3.0-vs2.3.1-pre6/kernel/utsname.c     2011-06-13 14:09:44.000000000 +0200
17470 @@ -16,14 +16,17 @@
17471  #include <linux/slab.h>
17472  #include <linux/user_namespace.h>
17473  #include <linux/proc_fs.h>
17474 +#include <linux/vserver/global.h>
17475  
17476  static struct uts_namespace *create_uts_ns(void)
17477  {
17478         struct uts_namespace *uts_ns;
17479  
17480         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
17481 -       if (uts_ns)
17482 +       if (uts_ns) {
17483                 kref_init(&uts_ns->kref);
17484 +               atomic_inc(&vs_global_uts_ns);
17485 +       }
17486         return uts_ns;
17487  }
17488  
17489 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
17490   * @old_ns: namespace to clone
17491   * Return NULL on error (failure to kmalloc), new ns otherwise
17492   */
17493 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
17494 -                                         struct uts_namespace *old_ns)
17495 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
17496 +                                         struct user_namespace *old_user)
17497  {
17498         struct uts_namespace *ns;
17499  
17500 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
17501  
17502         down_read(&uts_sem);
17503         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17504 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
17505 +       ns->user_ns = get_user_ns(old_user);
17506         up_read(&uts_sem);
17507         return ns;
17508  }
17509 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
17510   * versa.
17511   */
17512  struct uts_namespace *copy_utsname(unsigned long flags,
17513 -                                  struct task_struct *tsk)
17514 +                                  struct uts_namespace *old_ns,
17515 +                                  struct user_namespace *user_ns)
17516  {
17517 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
17518         struct uts_namespace *new_ns;
17519  
17520         BUG_ON(!old_ns);
17521 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
17522         if (!(flags & CLONE_NEWUTS))
17523                 return old_ns;
17524  
17525 -       new_ns = clone_uts_ns(tsk, old_ns);
17526 +       new_ns = clone_uts_ns(old_ns, user_ns);
17527  
17528         put_uts_ns(old_ns);
17529         return new_ns;
17530 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
17531  
17532         ns = container_of(kref, struct uts_namespace, kref);
17533         put_user_ns(ns->user_ns);
17534 +       atomic_dec(&vs_global_uts_ns);
17535         kfree(ns);
17536  }
17537  
17538 diff -NurpP --minimal linux-3.0/kernel/vserver/Kconfig linux-3.0-vs2.3.1-pre6/kernel/vserver/Kconfig
17539 --- linux-3.0/kernel/vserver/Kconfig    1970-01-01 01:00:00.000000000 +0100
17540 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/Kconfig       2011-07-20 02:15:23.000000000 +0200
17541 @@ -0,0 +1,228 @@
17542 +#
17543 +# Linux VServer configuration
17544 +#
17545 +
17546 +menu "Linux VServer"
17547 +
17548 +config VSERVER_AUTO_LBACK
17549 +       bool    "Automatically Assign Loopback IP"
17550 +       default y
17551 +       help
17552 +         Automatically assign a guest specific loopback
17553 +         IP and add it to the kernel network stack on
17554 +         startup.
17555 +
17556 +config VSERVER_AUTO_SINGLE
17557 +       bool    "Automatic Single IP Special Casing"
17558 +       depends on EXPERIMENTAL
17559 +       default y
17560 +       help
17561 +         This allows network contexts with a single IP to
17562 +         automatically remap 0.0.0.0 bindings to that IP,
17563 +         avoiding further network checks and improving
17564 +         performance.
17565 +
17566 +         (note: such guests do not allow to change the ip
17567 +          on the fly and do not show loopback addresses)
17568 +
17569 +config VSERVER_COWBL
17570 +       bool    "Enable COW Immutable Link Breaking"
17571 +       default y
17572 +       help
17573 +         This enables the COW (Copy-On-Write) link break code.
17574 +         It allows you to treat unified files like normal files
17575 +         when writing to them (which will implicitely break the
17576 +         link and create a copy of the unified file)
17577 +
17578 +config VSERVER_VTIME
17579 +       bool    "Enable Virtualized Guest Time"
17580 +       depends on EXPERIMENTAL
17581 +       default n
17582 +       help
17583 +         This enables per guest time offsets to allow for
17584 +         adjusting the system clock individually per guest.
17585 +         this adds some overhead to the time functions and
17586 +         therefore should not be enabled without good reason.
17587 +
17588 +config VSERVER_DEVICE
17589 +       bool    "Enable Guest Device Mapping"
17590 +       depends on EXPERIMENTAL
17591 +       default n
17592 +       help
17593 +         This enables generic device remapping.
17594 +
17595 +config VSERVER_PROC_SECURE
17596 +       bool    "Enable Proc Security"
17597 +       depends on PROC_FS
17598 +       default y
17599 +       help
17600 +         This configures ProcFS security to initially hide
17601 +         non-process entries for all contexts except the main and
17602 +         spectator context (i.e. for all guests), which is a secure
17603 +         default.
17604 +
17605 +         (note: on 1.2x the entries were visible by default)
17606 +
17607 +choice
17608 +       prompt  "Persistent Inode Tagging"
17609 +       default TAGGING_ID24
17610 +       help
17611 +         This adds persistent context information to filesystems
17612 +         mounted with the tagxid option. Tagging is a requirement
17613 +         for per-context disk limits and per-context quota.
17614 +
17615 +
17616 +config TAGGING_NONE
17617 +       bool    "Disabled"
17618 +       help
17619 +         do not store per-context information in inodes.
17620 +
17621 +config TAGGING_UID16
17622 +       bool    "UID16/GID32"
17623 +       help
17624 +         reduces UID to 16 bit, but leaves GID at 32 bit.
17625 +
17626 +config TAGGING_GID16
17627 +       bool    "UID32/GID16"
17628 +       help
17629 +         reduces GID to 16 bit, but leaves UID at 32 bit.
17630 +
17631 +config TAGGING_ID24
17632 +       bool    "UID24/GID24"
17633 +       help
17634 +         uses the upper 8bit from UID and GID for XID tagging
17635 +         which leaves 24bit for UID/GID each, which should be
17636 +         more than sufficient for normal use.
17637 +
17638 +config TAGGING_INTERN
17639 +       bool    "UID32/GID32"
17640 +       help
17641 +         this uses otherwise reserved inode fields in the on
17642 +         disk representation, which limits the use to a few
17643 +         filesystems (currently ext2 and ext3)
17644 +
17645 +endchoice
17646 +
17647 +config TAG_NFSD
17648 +       bool    "Tag NFSD User Auth and Files"
17649 +       default n
17650 +       help
17651 +         Enable this if you do want the in-kernel NFS
17652 +         Server to use the tagging specified above.
17653 +         (will require patched clients too)
17654 +
17655 +config VSERVER_PRIVACY
17656 +       bool    "Honor Privacy Aspects of Guests"
17657 +       default n
17658 +       help
17659 +         When enabled, most context checks will disallow
17660 +         access to structures assigned to a specific context,
17661 +         like ptys or loop devices.
17662 +
17663 +config VSERVER_CONTEXTS
17664 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
17665 +       range 1 65533
17666 +       default "768"   if 64BIT
17667 +       default "256"
17668 +       help
17669 +         This setting will optimize certain data structures
17670 +         and memory allocations according to the expected
17671 +         maximum.
17672 +
17673 +         note: this is not a strict upper limit.
17674 +
17675 +config VSERVER_WARN
17676 +       bool    "VServer Warnings"
17677 +       default y
17678 +       help
17679 +         This enables various runtime warnings, which will
17680 +         notify about potential manipulation attempts or
17681 +         resource shortage. It is generally considered to
17682 +         be a good idea to have that enabled.
17683 +
17684 +config VSERVER_WARN_DEVPTS
17685 +       bool    "VServer DevPTS Warnings"
17686 +       depends on VSERVER_WARN
17687 +       default y
17688 +       help
17689 +         This enables DevPTS related warnings, issued when a
17690 +         process inside a context tries to lookup or access
17691 +         a dynamic pts from the host or a different context.
17692 +
17693 +config VSERVER_DEBUG
17694 +       bool    "VServer Debugging Code"
17695 +       default n
17696 +       help
17697 +         Set this to yes if you want to be able to activate
17698 +         debugging output at runtime. It adds a very small
17699 +         overhead to all vserver related functions and
17700 +         increases the kernel size by about 20k.
17701 +
17702 +config VSERVER_HISTORY
17703 +       bool    "VServer History Tracing"
17704 +       depends on VSERVER_DEBUG
17705 +       default n
17706 +       help
17707 +         Set this to yes if you want to record the history of
17708 +         linux-vserver activities, so they can be replayed in
17709 +         the event of a kernel panic or oops.
17710 +
17711 +config VSERVER_HISTORY_SIZE
17712 +       int     "Per-CPU History Size (32-65536)"
17713 +       depends on VSERVER_HISTORY
17714 +       range 32 65536
17715 +       default 64
17716 +       help
17717 +         This allows you to specify the number of entries in
17718 +         the per-CPU history buffer.
17719 +
17720 +config VSERVER_LEGACY_MEM
17721 +       bool    "Legacy Memory Limits"
17722 +       default n
17723 +       help
17724 +         This provides fake memory limits to keep
17725 +         older tools happy in the face of memory
17726 +         cgroups
17727 +
17728 +choice
17729 +       prompt  "Quotes used in debug and warn messages"
17730 +       default QUOTES_ISO8859
17731 +
17732 +config QUOTES_ISO8859
17733 +       bool    "Extended ASCII (ISO 8859) angle quotes"
17734 +       help
17735 +         This uses the extended ASCII characters \xbb
17736 +         and \xab for quoting file and process names.
17737 +
17738 +config QUOTES_UTF8
17739 +       bool    "UTF-8 angle quotes"
17740 +       help
17741 +         This uses the the UTF-8 sequences for angle
17742 +         quotes to quote file and process names.
17743 +
17744 +config QUOTES_ASCII
17745 +       bool    "ASCII single quotes"
17746 +       help
17747 +         This uses the ASCII single quote character
17748 +         (\x27) to quote file and process names.
17749 +
17750 +endchoice
17751 +
17752 +endmenu
17753 +
17754 +
17755 +config VSERVER
17756 +       bool
17757 +       default y
17758 +       select NAMESPACES
17759 +       select UTS_NS
17760 +       select IPC_NS
17761 +#      select USER_NS
17762 +       select SYSVIPC
17763 +
17764 +config VSERVER_SECURITY
17765 +       bool
17766 +       depends on SECURITY
17767 +       default y
17768 +       select SECURITY_CAPABILITIES
17769 +
17770 diff -NurpP --minimal linux-3.0/kernel/vserver/Makefile linux-3.0-vs2.3.1-pre6/kernel/vserver/Makefile
17771 --- linux-3.0/kernel/vserver/Makefile   1970-01-01 01:00:00.000000000 +0100
17772 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/Makefile      2011-06-10 22:11:24.000000000 +0200
17773 @@ -0,0 +1,18 @@
17774 +#
17775 +# Makefile for the Linux vserver routines.
17776 +#
17777 +
17778 +
17779 +obj-y          += vserver.o
17780 +
17781 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
17782 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
17783 +                  dlimit.o tag.o
17784 +
17785 +vserver-$(CONFIG_INET) += inet.o
17786 +vserver-$(CONFIG_PROC_FS) += proc.o
17787 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
17788 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
17789 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
17790 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
17791 +
17792 diff -NurpP --minimal linux-3.0/kernel/vserver/cacct.c linux-3.0-vs2.3.1-pre6/kernel/vserver/cacct.c
17793 --- linux-3.0/kernel/vserver/cacct.c    1970-01-01 01:00:00.000000000 +0100
17794 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/cacct.c       2011-06-10 22:11:24.000000000 +0200
17795 @@ -0,0 +1,42 @@
17796 +/*
17797 + *  linux/kernel/vserver/cacct.c
17798 + *
17799 + *  Virtual Server: Context Accounting
17800 + *
17801 + *  Copyright (C) 2006-2007 Herbert Pötzl
17802 + *
17803 + *  V0.01  added accounting stats
17804 + *
17805 + */
17806 +
17807 +#include <linux/types.h>
17808 +#include <linux/vs_context.h>
17809 +#include <linux/vserver/cacct_cmd.h>
17810 +#include <linux/vserver/cacct_int.h>
17811 +
17812 +#include <asm/errno.h>
17813 +#include <asm/uaccess.h>
17814 +
17815 +
17816 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17817 +{
17818 +       struct vcmd_sock_stat_v0 vc_data;
17819 +       int j, field;
17820 +
17821 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17822 +               return -EFAULT;
17823 +
17824 +       field = vc_data.field;
17825 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17826 +               return -EINVAL;
17827 +
17828 +       for (j = 0; j < 3; j++) {
17829 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17830 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17831 +       }
17832 +
17833 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17834 +               return -EFAULT;
17835 +       return 0;
17836 +}
17837 +
17838 diff -NurpP --minimal linux-3.0/kernel/vserver/cacct_init.h linux-3.0-vs2.3.1-pre6/kernel/vserver/cacct_init.h
17839 --- linux-3.0/kernel/vserver/cacct_init.h       1970-01-01 01:00:00.000000000 +0100
17840 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/cacct_init.h  2011-06-10 22:11:24.000000000 +0200
17841 @@ -0,0 +1,25 @@
17842 +
17843 +
17844 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17845 +{
17846 +       int i, j;
17847 +
17848 +
17849 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17850 +               for (j = 0; j < 3; j++) {
17851 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
17852 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
17853 +               }
17854 +       }
17855 +       for (i = 0; i < 8; i++)
17856 +               atomic_set(&cacct->slab[i], 0);
17857 +       for (i = 0; i < 5; i++)
17858 +               for (j = 0; j < 4; j++)
17859 +                       atomic_set(&cacct->page[i][j], 0);
17860 +}
17861 +
17862 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17863 +{
17864 +       return;
17865 +}
17866 +
17867 diff -NurpP --minimal linux-3.0/kernel/vserver/cacct_proc.h linux-3.0-vs2.3.1-pre6/kernel/vserver/cacct_proc.h
17868 --- linux-3.0/kernel/vserver/cacct_proc.h       1970-01-01 01:00:00.000000000 +0100
17869 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/cacct_proc.h  2011-06-10 22:11:24.000000000 +0200
17870 @@ -0,0 +1,53 @@
17871 +#ifndef _VX_CACCT_PROC_H
17872 +#define _VX_CACCT_PROC_H
17873 +
17874 +#include <linux/vserver/cacct_int.h>
17875 +
17876 +
17877 +#define VX_SOCKA_TOP   \
17878 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17879 +
17880 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17881 +{
17882 +       int i, j, length = 0;
17883 +       static char *type[VXA_SOCK_SIZE] = {
17884 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17885 +       };
17886 +
17887 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17888 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17889 +               length += sprintf(buffer + length, "%s:", type[i]);
17890 +               for (j = 0; j < 3; j++) {
17891 +                       length += sprintf(buffer + length,
17892 +                               "\t%10lu/%-10lu",
17893 +                               vx_sock_count(cacct, i, j),
17894 +                               vx_sock_total(cacct, i, j));
17895 +               }
17896 +               buffer[length++] = '\n';
17897 +       }
17898 +
17899 +       length += sprintf(buffer + length, "\n");
17900 +       length += sprintf(buffer + length,
17901 +               "slab:\t %8u %8u %8u %8u\n",
17902 +               atomic_read(&cacct->slab[1]),
17903 +               atomic_read(&cacct->slab[4]),
17904 +               atomic_read(&cacct->slab[0]),
17905 +               atomic_read(&cacct->slab[2]));
17906 +
17907 +       length += sprintf(buffer + length, "\n");
17908 +       for (i = 0; i < 5; i++) {
17909 +               length += sprintf(buffer + length,
17910 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17911 +                       atomic_read(&cacct->page[i][0]),
17912 +                       atomic_read(&cacct->page[i][1]),
17913 +                       atomic_read(&cacct->page[i][2]),
17914 +                       atomic_read(&cacct->page[i][3]),
17915 +                       atomic_read(&cacct->page[i][4]),
17916 +                       atomic_read(&cacct->page[i][5]),
17917 +                       atomic_read(&cacct->page[i][6]),
17918 +                       atomic_read(&cacct->page[i][7]));
17919 +       }
17920 +       return length;
17921 +}
17922 +
17923 +#endif /* _VX_CACCT_PROC_H */
17924 diff -NurpP --minimal linux-3.0/kernel/vserver/context.c linux-3.0-vs2.3.1-pre6/kernel/vserver/context.c
17925 --- linux-3.0/kernel/vserver/context.c  1970-01-01 01:00:00.000000000 +0100
17926 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/context.c     2011-07-19 19:22:49.000000000 +0200
17927 @@ -0,0 +1,1080 @@
17928 +/*
17929 + *  linux/kernel/vserver/context.c
17930 + *
17931 + *  Virtual Server: Context Support
17932 + *
17933 + *  Copyright (C) 2003-2010  Herbert Pötzl
17934 + *
17935 + *  V0.01  context helper
17936 + *  V0.02  vx_ctx_kill syscall command
17937 + *  V0.03  replaced context_info calls
17938 + *  V0.04  redesign of struct (de)alloc
17939 + *  V0.05  rlimit basic implementation
17940 + *  V0.06  task_xid and info commands
17941 + *  V0.07  context flags and caps
17942 + *  V0.08  switch to RCU based hash
17943 + *  V0.09  revert to non RCU for now
17944 + *  V0.10  and back to working RCU hash
17945 + *  V0.11  and back to locking again
17946 + *  V0.12  referenced context store
17947 + *  V0.13  separate per cpu data
17948 + *  V0.14  changed vcmds to vxi arg
17949 + *  V0.15  added context stat
17950 + *  V0.16  have __create claim() the vxi
17951 + *  V0.17  removed older and legacy stuff
17952 + *  V0.18  added user credentials
17953 + *
17954 + */
17955 +
17956 +#include <linux/slab.h>
17957 +#include <linux/types.h>
17958 +#include <linux/security.h>
17959 +#include <linux/pid_namespace.h>
17960 +#include <linux/capability.h>
17961 +
17962 +#include <linux/vserver/context.h>
17963 +#include <linux/vserver/network.h>
17964 +#include <linux/vserver/debug.h>
17965 +#include <linux/vserver/limit.h>
17966 +#include <linux/vserver/limit_int.h>
17967 +#include <linux/vserver/space.h>
17968 +#include <linux/init_task.h>
17969 +#include <linux/fs_struct.h>
17970 +#include <linux/cred.h>
17971 +
17972 +#include <linux/vs_context.h>
17973 +#include <linux/vs_limit.h>
17974 +#include <linux/vs_pid.h>
17975 +#include <linux/vserver/context_cmd.h>
17976 +
17977 +#include "cvirt_init.h"
17978 +#include "cacct_init.h"
17979 +#include "limit_init.h"
17980 +#include "sched_init.h"
17981 +
17982 +
17983 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17984 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17985 +
17986 +
17987 +/*     now inactive context structures */
17988 +
17989 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17990 +
17991 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
17992 +
17993 +
17994 +/*     __alloc_vx_info()
17995 +
17996 +       * allocate an initialized vx_info struct
17997 +       * doesn't make it visible (hash)                        */
17998 +
17999 +static struct vx_info *__alloc_vx_info(xid_t xid)
18000 +{
18001 +       struct vx_info *new = NULL;
18002 +       int cpu, index;
18003 +
18004 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
18005 +
18006 +       /* would this benefit from a slab cache? */
18007 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
18008 +       if (!new)
18009 +               return 0;
18010 +
18011 +       memset(new, 0, sizeof(struct vx_info));
18012 +#ifdef CONFIG_SMP
18013 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
18014 +       if (!new->ptr_pc)
18015 +               goto error;
18016 +#endif
18017 +       new->vx_id = xid;
18018 +       INIT_HLIST_NODE(&new->vx_hlist);
18019 +       atomic_set(&new->vx_usecnt, 0);
18020 +       atomic_set(&new->vx_tasks, 0);
18021 +       new->vx_parent = NULL;
18022 +       new->vx_state = 0;
18023 +       init_waitqueue_head(&new->vx_wait);
18024 +
18025 +       /* prepare reaper */
18026 +       get_task_struct(init_pid_ns.child_reaper);
18027 +       new->vx_reaper = init_pid_ns.child_reaper;
18028 +       new->vx_badness_bias = 0;
18029 +
18030 +       /* rest of init goes here */
18031 +       vx_info_init_limit(&new->limit);
18032 +       vx_info_init_sched(&new->sched);
18033 +       vx_info_init_cvirt(&new->cvirt);
18034 +       vx_info_init_cacct(&new->cacct);
18035 +
18036 +       /* per cpu data structures */
18037 +       for_each_possible_cpu(cpu) {
18038 +               vx_info_init_sched_pc(
18039 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
18040 +               vx_info_init_cvirt_pc(
18041 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
18042 +       }
18043 +
18044 +       new->vx_flags = VXF_INIT_SET;
18045 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
18046 +       new->vx_ccaps = 0;
18047 +       new->vx_umask = 0;
18048 +
18049 +       new->reboot_cmd = 0;
18050 +       new->exit_code = 0;
18051 +
18052 +       // preconfig spaces
18053 +       for (index = 0; index < VX_SPACES; index++) {
18054 +               struct _vx_space *space = &new->space[index];
18055 +
18056 +               // filesystem
18057 +               spin_lock(&init_fs.lock);
18058 +               init_fs.users++;
18059 +               spin_unlock(&init_fs.lock);
18060 +               space->vx_fs = &init_fs;
18061 +
18062 +               /* FIXME: do we want defaults? */
18063 +               // space->vx_real_cred = 0;
18064 +               // space->vx_cred = 0;
18065 +       }
18066 +
18067 +
18068 +       vxdprintk(VXD_CBIT(xid, 0),
18069 +               "alloc_vx_info(%d) = %p", xid, new);
18070 +       vxh_alloc_vx_info(new);
18071 +       atomic_inc(&vx_global_ctotal);
18072 +       return new;
18073 +#ifdef CONFIG_SMP
18074 +error:
18075 +       kfree(new);
18076 +       return 0;
18077 +#endif
18078 +}
18079 +
18080 +/*     __dealloc_vx_info()
18081 +
18082 +       * final disposal of vx_info                             */
18083 +
18084 +static void __dealloc_vx_info(struct vx_info *vxi)
18085 +{
18086 +#ifdef CONFIG_VSERVER_WARN
18087 +       struct vx_info_save vxis;
18088 +       int cpu;
18089 +#endif
18090 +       vxdprintk(VXD_CBIT(xid, 0),
18091 +               "dealloc_vx_info(%p)", vxi);
18092 +       vxh_dealloc_vx_info(vxi);
18093 +
18094 +#ifdef CONFIG_VSERVER_WARN
18095 +       enter_vx_info(vxi, &vxis);
18096 +       vx_info_exit_limit(&vxi->limit);
18097 +       vx_info_exit_sched(&vxi->sched);
18098 +       vx_info_exit_cvirt(&vxi->cvirt);
18099 +       vx_info_exit_cacct(&vxi->cacct);
18100 +
18101 +       for_each_possible_cpu(cpu) {
18102 +               vx_info_exit_sched_pc(
18103 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
18104 +               vx_info_exit_cvirt_pc(
18105 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
18106 +       }
18107 +       leave_vx_info(&vxis);
18108 +#endif
18109 +
18110 +       vxi->vx_id = -1;
18111 +       vxi->vx_state |= VXS_RELEASED;
18112 +
18113 +#ifdef CONFIG_SMP
18114 +       free_percpu(vxi->ptr_pc);
18115 +#endif
18116 +       kfree(vxi);
18117 +       atomic_dec(&vx_global_ctotal);
18118 +}
18119 +
18120 +static void __shutdown_vx_info(struct vx_info *vxi)
18121 +{
18122 +       struct nsproxy *nsproxy;
18123 +       struct fs_struct *fs;
18124 +       struct cred *cred;
18125 +       int index, kill;
18126 +
18127 +       might_sleep();
18128 +
18129 +       vxi->vx_state |= VXS_SHUTDOWN;
18130 +       vs_state_change(vxi, VSC_SHUTDOWN);
18131 +
18132 +       for (index = 0; index < VX_SPACES; index++) {
18133 +               struct _vx_space *space = &vxi->space[index];
18134 +
18135 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
18136 +               if (nsproxy)
18137 +                       put_nsproxy(nsproxy);
18138 +
18139 +               fs = xchg(&space->vx_fs, NULL);
18140 +               spin_lock(&fs->lock);
18141 +               kill = !--fs->users;
18142 +               spin_unlock(&fs->lock);
18143 +               if (kill)
18144 +                       free_fs_struct(fs);
18145 +
18146 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
18147 +               if (cred)
18148 +                       abort_creds(cred);
18149 +       }
18150 +}
18151 +
18152 +/* exported stuff */
18153 +
18154 +void free_vx_info(struct vx_info *vxi)
18155 +{
18156 +       unsigned long flags;
18157 +       unsigned index;
18158 +
18159 +       /* check for reference counts first */
18160 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
18161 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18162 +
18163 +       /* context must not be hashed */
18164 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18165 +
18166 +       /* context shutdown is mandatory */
18167 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
18168 +
18169 +       /* spaces check */
18170 +       for (index = 0; index < VX_SPACES; index++) {
18171 +               struct _vx_space *space = &vxi->space[index];
18172 +
18173 +               BUG_ON(space->vx_nsproxy);
18174 +               BUG_ON(space->vx_fs);
18175 +               // BUG_ON(space->vx_real_cred);
18176 +               // BUG_ON(space->vx_cred);
18177 +       }
18178 +
18179 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18180 +       hlist_del(&vxi->vx_hlist);
18181 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18182 +
18183 +       __dealloc_vx_info(vxi);
18184 +}
18185 +
18186 +
18187 +/*     hash table for vx_info hash */
18188 +
18189 +#define VX_HASH_SIZE   13
18190 +
18191 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
18192 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
18193 +
18194 +static DEFINE_SPINLOCK(vx_info_hash_lock);
18195 +
18196 +
18197 +static inline unsigned int __hashval(xid_t xid)
18198 +{
18199 +       return (xid % VX_HASH_SIZE);
18200 +}
18201 +
18202 +
18203 +
18204 +/*     __hash_vx_info()
18205 +
18206 +       * add the vxi to the global hash table
18207 +       * requires the hash_lock to be held                     */
18208 +
18209 +static inline void __hash_vx_info(struct vx_info *vxi)
18210 +{
18211 +       struct hlist_head *head;
18212 +
18213 +       vxd_assert_lock(&vx_info_hash_lock);
18214 +       vxdprintk(VXD_CBIT(xid, 4),
18215 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
18216 +       vxh_hash_vx_info(vxi);
18217 +
18218 +       /* context must not be hashed */
18219 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18220 +
18221 +       vxi->vx_state |= VXS_HASHED;
18222 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
18223 +       hlist_add_head(&vxi->vx_hlist, head);
18224 +       atomic_inc(&vx_global_cactive);
18225 +}
18226 +
18227 +/*     __unhash_vx_info()
18228 +
18229 +       * remove the vxi from the global hash table
18230 +       * requires the hash_lock to be held                     */
18231 +
18232 +static inline void __unhash_vx_info(struct vx_info *vxi)
18233 +{
18234 +       unsigned long flags;
18235 +
18236 +       vxd_assert_lock(&vx_info_hash_lock);
18237 +       vxdprintk(VXD_CBIT(xid, 4),
18238 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
18239 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
18240 +       vxh_unhash_vx_info(vxi);
18241 +
18242 +       /* context must be hashed */
18243 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
18244 +       /* but without tasks */
18245 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18246 +
18247 +       vxi->vx_state &= ~VXS_HASHED;
18248 +       hlist_del_init(&vxi->vx_hlist);
18249 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18250 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
18251 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18252 +       atomic_dec(&vx_global_cactive);
18253 +}
18254 +
18255 +
18256 +/*     __lookup_vx_info()
18257 +
18258 +       * requires the hash_lock to be held
18259 +       * doesn't increment the vx_refcnt                       */
18260 +
18261 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
18262 +{
18263 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
18264 +       struct hlist_node *pos;
18265 +       struct vx_info *vxi;
18266 +
18267 +       vxd_assert_lock(&vx_info_hash_lock);
18268 +       hlist_for_each(pos, head) {
18269 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18270 +
18271 +               if (vxi->vx_id == xid)
18272 +                       goto found;
18273 +       }
18274 +       vxi = NULL;
18275 +found:
18276 +       vxdprintk(VXD_CBIT(xid, 0),
18277 +               "__lookup_vx_info(#%u): %p[#%u]",
18278 +               xid, vxi, vxi ? vxi->vx_id : 0);
18279 +       vxh_lookup_vx_info(vxi, xid);
18280 +       return vxi;
18281 +}
18282 +
18283 +
18284 +/*     __create_vx_info()
18285 +
18286 +       * create the requested context
18287 +       * get(), claim() and hash it                            */
18288 +
18289 +static struct vx_info *__create_vx_info(int id)
18290 +{
18291 +       struct vx_info *new, *vxi = NULL;
18292 +
18293 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
18294 +
18295 +       if (!(new = __alloc_vx_info(id)))
18296 +               return ERR_PTR(-ENOMEM);
18297 +
18298 +       /* required to make dynamic xids unique */
18299 +       spin_lock(&vx_info_hash_lock);
18300 +
18301 +       /* static context requested */
18302 +       if ((vxi = __lookup_vx_info(id))) {
18303 +               vxdprintk(VXD_CBIT(xid, 0),
18304 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18305 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18306 +                       vxi = ERR_PTR(-EBUSY);
18307 +               else
18308 +                       vxi = ERR_PTR(-EEXIST);
18309 +               goto out_unlock;
18310 +       }
18311 +       /* new context */
18312 +       vxdprintk(VXD_CBIT(xid, 0),
18313 +               "create_vx_info(%d) = %p (new)", id, new);
18314 +       claim_vx_info(new, NULL);
18315 +       __hash_vx_info(get_vx_info(new));
18316 +       vxi = new, new = NULL;
18317 +
18318 +out_unlock:
18319 +       spin_unlock(&vx_info_hash_lock);
18320 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18321 +       if (new)
18322 +               __dealloc_vx_info(new);
18323 +       return vxi;
18324 +}
18325 +
18326 +
18327 +/*     exported stuff                                          */
18328 +
18329 +
18330 +void unhash_vx_info(struct vx_info *vxi)
18331 +{
18332 +       spin_lock(&vx_info_hash_lock);
18333 +       __unhash_vx_info(vxi);
18334 +       spin_unlock(&vx_info_hash_lock);
18335 +       __shutdown_vx_info(vxi);
18336 +       __wakeup_vx_info(vxi);
18337 +}
18338 +
18339 +
18340 +/*     lookup_vx_info()
18341 +
18342 +       * search for a vx_info and get() it
18343 +       * negative id means current                             */
18344 +
18345 +struct vx_info *lookup_vx_info(int id)
18346 +{
18347 +       struct vx_info *vxi = NULL;
18348 +
18349 +       if (id < 0) {
18350 +               vxi = get_vx_info(current_vx_info());
18351 +       } else if (id > 1) {
18352 +               spin_lock(&vx_info_hash_lock);
18353 +               vxi = get_vx_info(__lookup_vx_info(id));
18354 +               spin_unlock(&vx_info_hash_lock);
18355 +       }
18356 +       return vxi;
18357 +}
18358 +
18359 +/*     xid_is_hashed()
18360 +
18361 +       * verify that xid is still hashed                       */
18362 +
18363 +int xid_is_hashed(xid_t xid)
18364 +{
18365 +       int hashed;
18366 +
18367 +       spin_lock(&vx_info_hash_lock);
18368 +       hashed = (__lookup_vx_info(xid) != NULL);
18369 +       spin_unlock(&vx_info_hash_lock);
18370 +       return hashed;
18371 +}
18372 +
18373 +#ifdef CONFIG_PROC_FS
18374 +
18375 +/*     get_xid_list()
18376 +
18377 +       * get a subset of hashed xids for proc
18378 +       * assumes size is at least one                          */
18379 +
18380 +int get_xid_list(int index, unsigned int *xids, int size)
18381 +{
18382 +       int hindex, nr_xids = 0;
18383 +
18384 +       /* only show current and children */
18385 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18386 +               if (index > 0)
18387 +                       return 0;
18388 +               xids[nr_xids] = vx_current_xid();
18389 +               return 1;
18390 +       }
18391 +
18392 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18393 +               struct hlist_head *head = &vx_info_hash[hindex];
18394 +               struct hlist_node *pos;
18395 +
18396 +               spin_lock(&vx_info_hash_lock);
18397 +               hlist_for_each(pos, head) {
18398 +                       struct vx_info *vxi;
18399 +
18400 +                       if (--index > 0)
18401 +                               continue;
18402 +
18403 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18404 +                       xids[nr_xids] = vxi->vx_id;
18405 +                       if (++nr_xids >= size) {
18406 +                               spin_unlock(&vx_info_hash_lock);
18407 +                               goto out;
18408 +                       }
18409 +               }
18410 +               /* keep the lock time short */
18411 +               spin_unlock(&vx_info_hash_lock);
18412 +       }
18413 +out:
18414 +       return nr_xids;
18415 +}
18416 +#endif
18417 +
18418 +#ifdef CONFIG_VSERVER_DEBUG
18419 +
18420 +void   dump_vx_info_inactive(int level)
18421 +{
18422 +       struct hlist_node *entry, *next;
18423 +
18424 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18425 +               struct vx_info *vxi =
18426 +                       list_entry(entry, struct vx_info, vx_hlist);
18427 +
18428 +               dump_vx_info(vxi, level);
18429 +       }
18430 +}
18431 +
18432 +#endif
18433 +
18434 +#if 0
18435 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18436 +{
18437 +       struct user_struct *new_user, *old_user;
18438 +
18439 +       if (!p || !vxi)
18440 +               BUG();
18441 +
18442 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18443 +               return -EACCES;
18444 +
18445 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18446 +       if (!new_user)
18447 +               return -ENOMEM;
18448 +
18449 +       old_user = p->user;
18450 +       if (new_user != old_user) {
18451 +               atomic_inc(&new_user->processes);
18452 +               atomic_dec(&old_user->processes);
18453 +               p->user = new_user;
18454 +       }
18455 +       free_uid(old_user);
18456 +       return 0;
18457 +}
18458 +#endif
18459 +
18460 +#if 0
18461 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18462 +{
18463 +       // p->cap_effective &= vxi->vx_cap_bset;
18464 +       p->cap_effective =
18465 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18466 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18467 +       p->cap_inheritable =
18468 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18469 +       // p->cap_permitted &= vxi->vx_cap_bset;
18470 +       p->cap_permitted =
18471 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18472 +}
18473 +#endif
18474 +
18475 +
18476 +#include <linux/file.h>
18477 +#include <linux/fdtable.h>
18478 +
18479 +static int vx_openfd_task(struct task_struct *tsk)
18480 +{
18481 +       struct files_struct *files = tsk->files;
18482 +       struct fdtable *fdt;
18483 +       const unsigned long *bptr;
18484 +       int count, total;
18485 +
18486 +       /* no rcu_read_lock() because of spin_lock() */
18487 +       spin_lock(&files->file_lock);
18488 +       fdt = files_fdtable(files);
18489 +       bptr = fdt->open_fds->fds_bits;
18490 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18491 +       for (total = 0; count > 0; count--) {
18492 +               if (*bptr)
18493 +                       total += hweight_long(*bptr);
18494 +               bptr++;
18495 +       }
18496 +       spin_unlock(&files->file_lock);
18497 +       return total;
18498 +}
18499 +
18500 +
18501 +/*     for *space compatibility */
18502 +
18503 +asmlinkage long sys_unshare(unsigned long);
18504 +
18505 +/*
18506 + *     migrate task to new context
18507 + *     gets vxi, puts old_vxi on change
18508 + *     optionally unshares namespaces (hack)
18509 + */
18510 +
18511 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18512 +{
18513 +       struct vx_info *old_vxi;
18514 +       int ret = 0;
18515 +
18516 +       if (!p || !vxi)
18517 +               BUG();
18518 +
18519 +       vxdprintk(VXD_CBIT(xid, 5),
18520 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18521 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18522 +
18523 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18524 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18525 +               return -EACCES;
18526 +
18527 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18528 +               return -EFAULT;
18529 +
18530 +       old_vxi = task_get_vx_info(p);
18531 +       if (old_vxi == vxi)
18532 +               goto out;
18533 +
18534 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18535 +       {
18536 +               int openfd;
18537 +
18538 +               task_lock(p);
18539 +               openfd = vx_openfd_task(p);
18540 +
18541 +               if (old_vxi) {
18542 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18543 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18544 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18545 +                       /* FIXME: what about the struct files here? */
18546 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18547 +                       /* account for the executable */
18548 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18549 +               }
18550 +               atomic_inc(&vxi->cvirt.nr_threads);
18551 +               atomic_inc(&vxi->cvirt.nr_running);
18552 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18553 +               /* FIXME: what about the struct files here? */
18554 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18555 +               /* account for the executable */
18556 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18557 +
18558 +               if (old_vxi) {
18559 +                       release_vx_info(old_vxi, p);
18560 +                       clr_vx_info(&p->vx_info);
18561 +               }
18562 +               claim_vx_info(vxi, p);
18563 +               set_vx_info(&p->vx_info, vxi);
18564 +               p->xid = vxi->vx_id;
18565 +
18566 +               vxdprintk(VXD_CBIT(xid, 5),
18567 +                       "moved task %p into vxi:%p[#%d]",
18568 +                       p, vxi, vxi->vx_id);
18569 +
18570 +               // vx_mask_cap_bset(vxi, p);
18571 +               task_unlock(p);
18572 +
18573 +               /* hack for *spaces to provide compatibility */
18574 +               if (unshare) {
18575 +                       struct nsproxy *old_nsp, *new_nsp;
18576 +
18577 +                       ret = unshare_nsproxy_namespaces(
18578 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18579 +                               &new_nsp, NULL);
18580 +                       if (ret)
18581 +                               goto out;
18582 +
18583 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18584 +                       vx_set_space(vxi,
18585 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18586 +                       put_nsproxy(old_nsp);
18587 +               }
18588 +       }
18589 +out:
18590 +       put_vx_info(old_vxi);
18591 +       return ret;
18592 +}
18593 +
18594 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18595 +{
18596 +       struct task_struct *old_reaper;
18597 +
18598 +       if (!vxi)
18599 +               return -EINVAL;
18600 +
18601 +       vxdprintk(VXD_CBIT(xid, 6),
18602 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18603 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18604 +
18605 +       old_reaper = vxi->vx_reaper;
18606 +       if (old_reaper == p)
18607 +               return 0;
18608 +
18609 +       /* set new child reaper */
18610 +       get_task_struct(p);
18611 +       vxi->vx_reaper = p;
18612 +       put_task_struct(old_reaper);
18613 +       return 0;
18614 +}
18615 +
18616 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18617 +{
18618 +       if (!vxi)
18619 +               return -EINVAL;
18620 +
18621 +       vxdprintk(VXD_CBIT(xid, 6),
18622 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18623 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18624 +
18625 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18626 +       // vxi->vx_initpid = p->tgid;
18627 +       vxi->vx_initpid = p->pid;
18628 +       return 0;
18629 +}
18630 +
18631 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18632 +{
18633 +       vxdprintk(VXD_CBIT(xid, 6),
18634 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18635 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18636 +
18637 +       vxi->exit_code = code;
18638 +       vxi->vx_initpid = 0;
18639 +}
18640 +
18641 +
18642 +void vx_set_persistent(struct vx_info *vxi)
18643 +{
18644 +       vxdprintk(VXD_CBIT(xid, 6),
18645 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18646 +
18647 +       get_vx_info(vxi);
18648 +       claim_vx_info(vxi, NULL);
18649 +}
18650 +
18651 +void vx_clear_persistent(struct vx_info *vxi)
18652 +{
18653 +       vxdprintk(VXD_CBIT(xid, 6),
18654 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18655 +
18656 +       release_vx_info(vxi, NULL);
18657 +       put_vx_info(vxi);
18658 +}
18659 +
18660 +void vx_update_persistent(struct vx_info *vxi)
18661 +{
18662 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18663 +               vx_set_persistent(vxi);
18664 +       else
18665 +               vx_clear_persistent(vxi);
18666 +}
18667 +
18668 +
18669 +/*     task must be current or locked          */
18670 +
18671 +void   exit_vx_info(struct task_struct *p, int code)
18672 +{
18673 +       struct vx_info *vxi = p->vx_info;
18674 +
18675 +       if (vxi) {
18676 +               atomic_dec(&vxi->cvirt.nr_threads);
18677 +               vx_nproc_dec(p);
18678 +
18679 +               vxi->exit_code = code;
18680 +               release_vx_info(vxi, p);
18681 +       }
18682 +}
18683 +
18684 +void   exit_vx_info_early(struct task_struct *p, int code)
18685 +{
18686 +       struct vx_info *vxi = p->vx_info;
18687 +
18688 +       if (vxi) {
18689 +               if (vxi->vx_initpid == p->pid)
18690 +                       vx_exit_init(vxi, p, code);
18691 +               if (vxi->vx_reaper == p)
18692 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18693 +       }
18694 +}
18695 +
18696 +
18697 +/* vserver syscall commands below here */
18698 +
18699 +/* taks xid and vx_info functions */
18700 +
18701 +#include <asm/uaccess.h>
18702 +
18703 +
18704 +int vc_task_xid(uint32_t id)
18705 +{
18706 +       xid_t xid;
18707 +
18708 +       if (id) {
18709 +               struct task_struct *tsk;
18710 +
18711 +               rcu_read_lock();
18712 +               tsk = find_task_by_real_pid(id);
18713 +               xid = (tsk) ? tsk->xid : -ESRCH;
18714 +               rcu_read_unlock();
18715 +       } else
18716 +               xid = vx_current_xid();
18717 +       return xid;
18718 +}
18719 +
18720 +
18721 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18722 +{
18723 +       struct vcmd_vx_info_v0 vc_data;
18724 +
18725 +       vc_data.xid = vxi->vx_id;
18726 +       vc_data.initpid = vxi->vx_initpid;
18727 +
18728 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18729 +               return -EFAULT;
18730 +       return 0;
18731 +}
18732 +
18733 +
18734 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18735 +{
18736 +       struct vcmd_ctx_stat_v0 vc_data;
18737 +
18738 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18739 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18740 +
18741 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18742 +               return -EFAULT;
18743 +       return 0;
18744 +}
18745 +
18746 +
18747 +/* context functions */
18748 +
18749 +int vc_ctx_create(uint32_t xid, void __user *data)
18750 +{
18751 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18752 +       struct vx_info *new_vxi;
18753 +       int ret;
18754 +
18755 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18756 +               return -EFAULT;
18757 +
18758 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18759 +               return -EINVAL;
18760 +
18761 +       new_vxi = __create_vx_info(xid);
18762 +       if (IS_ERR(new_vxi))
18763 +               return PTR_ERR(new_vxi);
18764 +
18765 +       /* initial flags */
18766 +       new_vxi->vx_flags = vc_data.flagword;
18767 +
18768 +       ret = -ENOEXEC;
18769 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18770 +               goto out;
18771 +
18772 +       ret = vx_migrate_task(current, new_vxi, (!data));
18773 +       if (ret)
18774 +               goto out;
18775 +
18776 +       /* return context id on success */
18777 +       ret = new_vxi->vx_id;
18778 +
18779 +       /* get a reference for persistent contexts */
18780 +       if ((vc_data.flagword & VXF_PERSISTENT))
18781 +               vx_set_persistent(new_vxi);
18782 +out:
18783 +       release_vx_info(new_vxi, NULL);
18784 +       put_vx_info(new_vxi);
18785 +       return ret;
18786 +}
18787 +
18788 +
18789 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18790 +{
18791 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18792 +       int ret;
18793 +
18794 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18795 +               return -EFAULT;
18796 +
18797 +       ret = vx_migrate_task(current, vxi, 0);
18798 +       if (ret)
18799 +               return ret;
18800 +       if (vc_data.flagword & VXM_SET_INIT)
18801 +               ret = vx_set_init(vxi, current);
18802 +       if (ret)
18803 +               return ret;
18804 +       if (vc_data.flagword & VXM_SET_REAPER)
18805 +               ret = vx_set_reaper(vxi, current);
18806 +       return ret;
18807 +}
18808 +
18809 +
18810 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18811 +{
18812 +       struct vcmd_ctx_flags_v0 vc_data;
18813 +
18814 +       vc_data.flagword = vxi->vx_flags;
18815 +
18816 +       /* special STATE flag handling */
18817 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18818 +
18819 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18820 +               return -EFAULT;
18821 +       return 0;
18822 +}
18823 +
18824 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18825 +{
18826 +       struct vcmd_ctx_flags_v0 vc_data;
18827 +       uint64_t mask, trigger;
18828 +
18829 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18830 +               return -EFAULT;
18831 +
18832 +       /* special STATE flag handling */
18833 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18834 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18835 +
18836 +       if (vxi == current_vx_info()) {
18837 +               /* if (trigger & VXF_STATE_SETUP)
18838 +                       vx_mask_cap_bset(vxi, current); */
18839 +               if (trigger & VXF_STATE_INIT) {
18840 +                       int ret;
18841 +
18842 +                       ret = vx_set_init(vxi, current);
18843 +                       if (ret)
18844 +                               return ret;
18845 +                       ret = vx_set_reaper(vxi, current);
18846 +                       if (ret)
18847 +                               return ret;
18848 +               }
18849 +       }
18850 +
18851 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18852 +               vc_data.flagword, mask);
18853 +       if (trigger & VXF_PERSISTENT)
18854 +               vx_update_persistent(vxi);
18855 +
18856 +       return 0;
18857 +}
18858 +
18859 +
18860 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18861 +{
18862 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18863 +
18864 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18865 +       return v;
18866 +}
18867 +
18868 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18869 +{
18870 +       kernel_cap_t c = __cap_empty_set;
18871 +
18872 +       c.cap[0] = v & 0xFFFFFFFF;
18873 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18874 +
18875 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18876 +       return c;
18877 +}
18878 +
18879 +
18880 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18881 +{
18882 +       if (bcaps)
18883 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18884 +       if (ccaps)
18885 +               *ccaps = vxi->vx_ccaps;
18886 +
18887 +       return 0;
18888 +}
18889 +
18890 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18891 +{
18892 +       struct vcmd_ctx_caps_v1 vc_data;
18893 +       int ret;
18894 +
18895 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18896 +       if (ret)
18897 +               return ret;
18898 +       vc_data.cmask = ~0ULL;
18899 +
18900 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18901 +               return -EFAULT;
18902 +       return 0;
18903 +}
18904 +
18905 +static int do_set_caps(struct vx_info *vxi,
18906 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18907 +{
18908 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18909 +
18910 +#if 0
18911 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18912 +               bcaps, bmask, ccaps, cmask);
18913 +#endif
18914 +       vxi->vx_bcaps = cap_t_from_caps(
18915 +               vs_mask_flags(bcold, bcaps, bmask));
18916 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18917 +
18918 +       return 0;
18919 +}
18920 +
18921 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18922 +{
18923 +       struct vcmd_ctx_caps_v1 vc_data;
18924 +
18925 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18926 +               return -EFAULT;
18927 +
18928 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18929 +}
18930 +
18931 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18932 +{
18933 +       struct vcmd_bcaps vc_data;
18934 +       int ret;
18935 +
18936 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18937 +       if (ret)
18938 +               return ret;
18939 +       vc_data.bmask = ~0ULL;
18940 +
18941 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18942 +               return -EFAULT;
18943 +       return 0;
18944 +}
18945 +
18946 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18947 +{
18948 +       struct vcmd_bcaps vc_data;
18949 +
18950 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18951 +               return -EFAULT;
18952 +
18953 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18954 +}
18955 +
18956 +
18957 +int vc_get_umask(struct vx_info *vxi, void __user *data)
18958 +{
18959 +       struct vcmd_umask vc_data;
18960 +
18961 +       vc_data.umask = vxi->vx_umask;
18962 +       vc_data.mask = ~0ULL;
18963 +
18964 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18965 +               return -EFAULT;
18966 +       return 0;
18967 +}
18968 +
18969 +int vc_set_umask(struct vx_info *vxi, void __user *data)
18970 +{
18971 +       struct vcmd_umask vc_data;
18972 +
18973 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18974 +               return -EFAULT;
18975 +
18976 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
18977 +               vc_data.umask, vc_data.mask);
18978 +       return 0;
18979 +}
18980 +
18981 +
18982 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18983 +{
18984 +       struct vcmd_badness_v0 vc_data;
18985 +
18986 +       vc_data.bias = vxi->vx_badness_bias;
18987 +
18988 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18989 +               return -EFAULT;
18990 +       return 0;
18991 +}
18992 +
18993 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18994 +{
18995 +       struct vcmd_badness_v0 vc_data;
18996 +
18997 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18998 +               return -EFAULT;
18999 +
19000 +       vxi->vx_badness_bias = vc_data.bias;
19001 +       return 0;
19002 +}
19003 +
19004 +#include <linux/module.h>
19005 +
19006 +EXPORT_SYMBOL_GPL(free_vx_info);
19007 +
19008 diff -NurpP --minimal linux-3.0/kernel/vserver/cvirt.c linux-3.0-vs2.3.1-pre6/kernel/vserver/cvirt.c
19009 --- linux-3.0/kernel/vserver/cvirt.c    1970-01-01 01:00:00.000000000 +0100
19010 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/cvirt.c       2011-06-13 14:57:26.000000000 +0200
19011 @@ -0,0 +1,303 @@
19012 +/*
19013 + *  linux/kernel/vserver/cvirt.c
19014 + *
19015 + *  Virtual Server: Context Virtualization
19016 + *
19017 + *  Copyright (C) 2004-2007  Herbert Pötzl
19018 + *
19019 + *  V0.01  broken out from limit.c
19020 + *  V0.02  added utsname stuff
19021 + *  V0.03  changed vcmds to vxi arg
19022 + *
19023 + */
19024 +
19025 +#include <linux/types.h>
19026 +#include <linux/utsname.h>
19027 +#include <linux/vs_cvirt.h>
19028 +#include <linux/vserver/switch.h>
19029 +#include <linux/vserver/cvirt_cmd.h>
19030 +
19031 +#include <asm/uaccess.h>
19032 +
19033 +
19034 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
19035 +{
19036 +       struct vx_info *vxi = current_vx_info();
19037 +
19038 +       set_normalized_timespec(uptime,
19039 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
19040 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
19041 +       if (!idle)
19042 +               return;
19043 +       set_normalized_timespec(idle,
19044 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
19045 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
19046 +       return;
19047 +}
19048 +
19049 +uint64_t vx_idle_jiffies(void)
19050 +{
19051 +       return init_task.utime + init_task.stime;
19052 +}
19053 +
19054 +
19055 +
19056 +static inline uint32_t __update_loadavg(uint32_t load,
19057 +       int wsize, int delta, int n)
19058 +{
19059 +       unsigned long long calc, prev;
19060 +
19061 +       /* just set it to n */
19062 +       if (unlikely(delta >= wsize))
19063 +               return (n << FSHIFT);
19064 +
19065 +       calc = delta * n;
19066 +       calc <<= FSHIFT;
19067 +       prev = (wsize - delta);
19068 +       prev *= load;
19069 +       calc += prev;
19070 +       do_div(calc, wsize);
19071 +       return calc;
19072 +}
19073 +
19074 +
19075 +void vx_update_load(struct vx_info *vxi)
19076 +{
19077 +       uint32_t now, last, delta;
19078 +       unsigned int nr_running, nr_uninterruptible;
19079 +       unsigned int total;
19080 +       unsigned long flags;
19081 +
19082 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
19083 +
19084 +       now = jiffies;
19085 +       last = vxi->cvirt.load_last;
19086 +       delta = now - last;
19087 +
19088 +       if (delta < 5*HZ)
19089 +               goto out;
19090 +
19091 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
19092 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
19093 +       total = nr_running + nr_uninterruptible;
19094 +
19095 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
19096 +               60*HZ, delta, total);
19097 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
19098 +               5*60*HZ, delta, total);
19099 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
19100 +               15*60*HZ, delta, total);
19101 +
19102 +       vxi->cvirt.load_last = now;
19103 +out:
19104 +       atomic_inc(&vxi->cvirt.load_updates);
19105 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
19106 +}
19107 +
19108 +
19109 +/*
19110 + * Commands to do_syslog:
19111 + *
19112 + *      0 -- Close the log.  Currently a NOP.
19113 + *      1 -- Open the log. Currently a NOP.
19114 + *      2 -- Read from the log.
19115 + *      3 -- Read all messages remaining in the ring buffer.
19116 + *      4 -- Read and clear all messages remaining in the ring buffer
19117 + *      5 -- Clear ring buffer.
19118 + *      6 -- Disable printk's to console
19119 + *      7 -- Enable printk's to console
19120 + *      8 -- Set level of messages printed to console
19121 + *      9 -- Return number of unread characters in the log buffer
19122 + *     10 -- Return size of the log buffer
19123 + */
19124 +int vx_do_syslog(int type, char __user *buf, int len)
19125 +{
19126 +       int error = 0;
19127 +       int do_clear = 0;
19128 +       struct vx_info *vxi = current_vx_info();
19129 +       struct _vx_syslog *log;
19130 +
19131 +       if (!vxi)
19132 +               return -EINVAL;
19133 +       log = &vxi->cvirt.syslog;
19134 +
19135 +       switch (type) {
19136 +       case 0:         /* Close log */
19137 +       case 1:         /* Open log */
19138 +               break;
19139 +       case 2:         /* Read from log */
19140 +               error = wait_event_interruptible(log->log_wait,
19141 +                       (log->log_start - log->log_end));
19142 +               if (error)
19143 +                       break;
19144 +               spin_lock_irq(&log->logbuf_lock);
19145 +               spin_unlock_irq(&log->logbuf_lock);
19146 +               break;
19147 +       case 4:         /* Read/clear last kernel messages */
19148 +               do_clear = 1;
19149 +               /* fall through */
19150 +       case 3:         /* Read last kernel messages */
19151 +               return 0;
19152 +
19153 +       case 5:         /* Clear ring buffer */
19154 +               return 0;
19155 +
19156 +       case 6:         /* Disable logging to console */
19157 +       case 7:         /* Enable logging to console */
19158 +       case 8:         /* Set level of messages printed to console */
19159 +               break;
19160 +
19161 +       case 9:         /* Number of chars in the log buffer */
19162 +               return 0;
19163 +       case 10:        /* Size of the log buffer */
19164 +               return 0;
19165 +       default:
19166 +               error = -EINVAL;
19167 +               break;
19168 +       }
19169 +       return error;
19170 +}
19171 +
19172 +
19173 +/* virtual host info names */
19174 +
19175 +static char *vx_vhi_name(struct vx_info *vxi, int id)
19176 +{
19177 +       struct nsproxy *nsproxy;
19178 +       struct uts_namespace *uts;
19179 +
19180 +       if (id == VHIN_CONTEXT)
19181 +               return vxi->vx_name;
19182 +
19183 +       nsproxy = vxi->space[0].vx_nsproxy;
19184 +       if (!nsproxy)
19185 +               return NULL;
19186 +
19187 +       uts = nsproxy->uts_ns;
19188 +       if (!uts)
19189 +               return NULL;
19190 +
19191 +       switch (id) {
19192 +       case VHIN_SYSNAME:
19193 +               return uts->name.sysname;
19194 +       case VHIN_NODENAME:
19195 +               return uts->name.nodename;
19196 +       case VHIN_RELEASE:
19197 +               return uts->name.release;
19198 +       case VHIN_VERSION:
19199 +               return uts->name.version;
19200 +       case VHIN_MACHINE:
19201 +               return uts->name.machine;
19202 +       case VHIN_DOMAINNAME:
19203 +               return uts->name.domainname;
19204 +       default:
19205 +               return NULL;
19206 +       }
19207 +       return NULL;
19208 +}
19209 +
19210 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
19211 +{
19212 +       struct vcmd_vhi_name_v0 vc_data;
19213 +       char *name;
19214 +
19215 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19216 +               return -EFAULT;
19217 +
19218 +       name = vx_vhi_name(vxi, vc_data.field);
19219 +       if (!name)
19220 +               return -EINVAL;
19221 +
19222 +       memcpy(name, vc_data.name, 65);
19223 +       return 0;
19224 +}
19225 +
19226 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
19227 +{
19228 +       struct vcmd_vhi_name_v0 vc_data;
19229 +       char *name;
19230 +
19231 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19232 +               return -EFAULT;
19233 +
19234 +       name = vx_vhi_name(vxi, vc_data.field);
19235 +       if (!name)
19236 +               return -EINVAL;
19237 +
19238 +       memcpy(vc_data.name, name, 65);
19239 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19240 +               return -EFAULT;
19241 +       return 0;
19242 +}
19243 +
19244 +
19245 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
19246 +{
19247 +       struct vcmd_virt_stat_v0 vc_data;
19248 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
19249 +       struct timespec uptime;
19250 +
19251 +       do_posix_clock_monotonic_gettime(&uptime);
19252 +       set_normalized_timespec(&uptime,
19253 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
19254 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
19255 +
19256 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
19257 +       vc_data.uptime = timespec_to_ns(&uptime);
19258 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
19259 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
19260 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
19261 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
19262 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
19263 +       vc_data.load[0] = cvirt->load[0];
19264 +       vc_data.load[1] = cvirt->load[1];
19265 +       vc_data.load[2] = cvirt->load[2];
19266 +
19267 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19268 +               return -EFAULT;
19269 +       return 0;
19270 +}
19271 +
19272 +
19273 +#ifdef CONFIG_VSERVER_VTIME
19274 +
19275 +/* virtualized time base */
19276 +
19277 +void vx_adjust_timespec(struct timespec *ts)
19278 +{
19279 +       struct vx_info *vxi;
19280 +
19281 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19282 +               return;
19283 +
19284 +       vxi = current_vx_info();
19285 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
19286 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
19287 +
19288 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
19289 +               ts->tv_sec++;
19290 +               ts->tv_nsec -= NSEC_PER_SEC;
19291 +       } else if (ts->tv_nsec < 0) {
19292 +               ts->tv_sec--;
19293 +               ts->tv_nsec += NSEC_PER_SEC;
19294 +       }
19295 +}
19296 +
19297 +int vx_settimeofday(const struct timespec *ts)
19298 +{
19299 +       struct timespec ats, delta;
19300 +       struct vx_info *vxi;
19301 +
19302 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19303 +               return do_settimeofday(ts);
19304 +
19305 +       getnstimeofday(&ats);
19306 +       delta = timespec_sub(*ts, ats);
19307 +
19308 +       vxi = current_vx_info();
19309 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
19310 +       return 0;
19311 +}
19312 +
19313 +#endif
19314 +
19315 diff -NurpP --minimal linux-3.0/kernel/vserver/cvirt_init.h linux-3.0-vs2.3.1-pre6/kernel/vserver/cvirt_init.h
19316 --- linux-3.0/kernel/vserver/cvirt_init.h       1970-01-01 01:00:00.000000000 +0100
19317 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/cvirt_init.h  2011-06-10 22:11:24.000000000 +0200
19318 @@ -0,0 +1,70 @@
19319 +
19320 +
19321 +extern uint64_t vx_idle_jiffies(void);
19322 +
19323 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19324 +{
19325 +       uint64_t idle_jiffies = vx_idle_jiffies();
19326 +       uint64_t nsuptime;
19327 +
19328 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19329 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19330 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19331 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19332 +       cvirt->bias_ts.tv_sec = 0;
19333 +       cvirt->bias_ts.tv_nsec = 0;
19334 +
19335 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19336 +       atomic_set(&cvirt->nr_threads, 0);
19337 +       atomic_set(&cvirt->nr_running, 0);
19338 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19339 +       atomic_set(&cvirt->nr_onhold, 0);
19340 +
19341 +       spin_lock_init(&cvirt->load_lock);
19342 +       cvirt->load_last = jiffies;
19343 +       atomic_set(&cvirt->load_updates, 0);
19344 +       cvirt->load[0] = 0;
19345 +       cvirt->load[1] = 0;
19346 +       cvirt->load[2] = 0;
19347 +       atomic_set(&cvirt->total_forks, 0);
19348 +
19349 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19350 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19351 +       cvirt->syslog.log_start = 0;
19352 +       cvirt->syslog.log_end = 0;
19353 +       cvirt->syslog.con_start = 0;
19354 +       cvirt->syslog.logged_chars = 0;
19355 +}
19356 +
19357 +static inline
19358 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19359 +{
19360 +       // cvirt_pc->cpustat = { 0 };
19361 +}
19362 +
19363 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19364 +{
19365 +#ifdef CONFIG_VSERVER_WARN
19366 +       int value;
19367 +#endif
19368 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19369 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19370 +               cvirt, value);
19371 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19372 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19373 +               cvirt, value);
19374 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19375 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19376 +               cvirt, value);
19377 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19378 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19379 +               cvirt, value);
19380 +       return;
19381 +}
19382 +
19383 +static inline
19384 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19385 +{
19386 +       return;
19387 +}
19388 +
19389 diff -NurpP --minimal linux-3.0/kernel/vserver/cvirt_proc.h linux-3.0-vs2.3.1-pre6/kernel/vserver/cvirt_proc.h
19390 --- linux-3.0/kernel/vserver/cvirt_proc.h       1970-01-01 01:00:00.000000000 +0100
19391 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/cvirt_proc.h  2011-06-10 22:11:24.000000000 +0200
19392 @@ -0,0 +1,135 @@
19393 +#ifndef _VX_CVIRT_PROC_H
19394 +#define _VX_CVIRT_PROC_H
19395 +
19396 +#include <linux/nsproxy.h>
19397 +#include <linux/mnt_namespace.h>
19398 +#include <linux/ipc_namespace.h>
19399 +#include <linux/utsname.h>
19400 +#include <linux/ipc.h>
19401 +
19402 +
19403 +static inline
19404 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19405 +{
19406 +       struct mnt_namespace *ns;
19407 +       struct uts_namespace *uts;
19408 +       struct ipc_namespace *ipc;
19409 +       struct path path;
19410 +       char *pstr, *root;
19411 +       int length = 0;
19412 +
19413 +       if (!nsproxy)
19414 +               goto out;
19415 +
19416 +       length += sprintf(buffer + length,
19417 +               "NSProxy:\t%p [%p,%p,%p]\n",
19418 +               nsproxy, nsproxy->mnt_ns,
19419 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19420 +
19421 +       ns = nsproxy->mnt_ns;
19422 +       if (!ns)
19423 +               goto skip_ns;
19424 +
19425 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19426 +       if (!pstr)
19427 +               goto skip_ns;
19428 +
19429 +       path.mnt = ns->root;
19430 +       path.dentry = ns->root->mnt_root;
19431 +       root = d_path(&path, pstr, PATH_MAX - 2);
19432 +       length += sprintf(buffer + length,
19433 +               "Namespace:\t%p [#%u]\n"
19434 +               "RootPath:\t%s\n",
19435 +               ns, atomic_read(&ns->count),
19436 +               root);
19437 +       kfree(pstr);
19438 +skip_ns:
19439 +
19440 +       uts = nsproxy->uts_ns;
19441 +       if (!uts)
19442 +               goto skip_uts;
19443 +
19444 +       length += sprintf(buffer + length,
19445 +               "SysName:\t%.*s\n"
19446 +               "NodeName:\t%.*s\n"
19447 +               "Release:\t%.*s\n"
19448 +               "Version:\t%.*s\n"
19449 +               "Machine:\t%.*s\n"
19450 +               "DomainName:\t%.*s\n",
19451 +               __NEW_UTS_LEN, uts->name.sysname,
19452 +               __NEW_UTS_LEN, uts->name.nodename,
19453 +               __NEW_UTS_LEN, uts->name.release,
19454 +               __NEW_UTS_LEN, uts->name.version,
19455 +               __NEW_UTS_LEN, uts->name.machine,
19456 +               __NEW_UTS_LEN, uts->name.domainname);
19457 +skip_uts:
19458 +
19459 +       ipc = nsproxy->ipc_ns;
19460 +       if (!ipc)
19461 +               goto skip_ipc;
19462 +
19463 +       length += sprintf(buffer + length,
19464 +               "SEMS:\t\t%d %d %d %d  %d\n"
19465 +               "MSG:\t\t%d %d %d\n"
19466 +               "SHM:\t\t%lu %lu  %d %d\n",
19467 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19468 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19469 +               ipc->used_sems,
19470 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19471 +               (unsigned long)ipc->shm_ctlmax,
19472 +               (unsigned long)ipc->shm_ctlall,
19473 +               ipc->shm_ctlmni, ipc->shm_tot);
19474 +skip_ipc:
19475 +out:
19476 +       return length;
19477 +}
19478 +
19479 +
19480 +#include <linux/sched.h>
19481 +
19482 +#define LOAD_INT(x) ((x) >> FSHIFT)
19483 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19484 +
19485 +static inline
19486 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19487 +{
19488 +       int length = 0;
19489 +       int a, b, c;
19490 +
19491 +       length += sprintf(buffer + length,
19492 +               "BiasUptime:\t%lu.%02lu\n",
19493 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19494 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19495 +
19496 +       a = cvirt->load[0] + (FIXED_1 / 200);
19497 +       b = cvirt->load[1] + (FIXED_1 / 200);
19498 +       c = cvirt->load[2] + (FIXED_1 / 200);
19499 +       length += sprintf(buffer + length,
19500 +               "nr_threads:\t%d\n"
19501 +               "nr_running:\t%d\n"
19502 +               "nr_unintr:\t%d\n"
19503 +               "nr_onhold:\t%d\n"
19504 +               "load_updates:\t%d\n"
19505 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19506 +               "total_forks:\t%d\n",
19507 +               atomic_read(&cvirt->nr_threads),
19508 +               atomic_read(&cvirt->nr_running),
19509 +               atomic_read(&cvirt->nr_uninterruptible),
19510 +               atomic_read(&cvirt->nr_onhold),
19511 +               atomic_read(&cvirt->load_updates),
19512 +               LOAD_INT(a), LOAD_FRAC(a),
19513 +               LOAD_INT(b), LOAD_FRAC(b),
19514 +               LOAD_INT(c), LOAD_FRAC(c),
19515 +               atomic_read(&cvirt->total_forks));
19516 +       return length;
19517 +}
19518 +
19519 +static inline
19520 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19521 +       char *buffer, int cpu)
19522 +{
19523 +       int length = 0;
19524 +       return length;
19525 +}
19526 +
19527 +#endif /* _VX_CVIRT_PROC_H */
19528 diff -NurpP --minimal linux-3.0/kernel/vserver/debug.c linux-3.0-vs2.3.1-pre6/kernel/vserver/debug.c
19529 --- linux-3.0/kernel/vserver/debug.c    1970-01-01 01:00:00.000000000 +0100
19530 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/debug.c       2011-06-10 22:11:24.000000000 +0200
19531 @@ -0,0 +1,32 @@
19532 +/*
19533 + *  kernel/vserver/debug.c
19534 + *
19535 + *  Copyright (C) 2005-2007 Herbert Pötzl
19536 + *
19537 + *  V0.01  vx_info dump support
19538 + *
19539 + */
19540 +
19541 +#include <linux/module.h>
19542 +
19543 +#include <linux/vserver/context.h>
19544 +
19545 +
19546 +void   dump_vx_info(struct vx_info *vxi, int level)
19547 +{
19548 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19549 +               atomic_read(&vxi->vx_usecnt),
19550 +               atomic_read(&vxi->vx_tasks),
19551 +               vxi->vx_state);
19552 +       if (level > 0) {
19553 +               __dump_vx_limit(&vxi->limit);
19554 +               __dump_vx_sched(&vxi->sched);
19555 +               __dump_vx_cvirt(&vxi->cvirt);
19556 +               __dump_vx_cacct(&vxi->cacct);
19557 +       }
19558 +       printk("---\n");
19559 +}
19560 +
19561 +
19562 +EXPORT_SYMBOL_GPL(dump_vx_info);
19563 +
19564 diff -NurpP --minimal linux-3.0/kernel/vserver/device.c linux-3.0-vs2.3.1-pre6/kernel/vserver/device.c
19565 --- linux-3.0/kernel/vserver/device.c   1970-01-01 01:00:00.000000000 +0100
19566 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/device.c      2011-06-10 23:20:56.000000000 +0200
19567 @@ -0,0 +1,443 @@
19568 +/*
19569 + *  linux/kernel/vserver/device.c
19570 + *
19571 + *  Linux-VServer: Device Support
19572 + *
19573 + *  Copyright (C) 2006  Herbert Pötzl
19574 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19575 + *
19576 + *  V0.01  device mapping basics
19577 + *  V0.02  added defaults
19578 + *
19579 + */
19580 +
19581 +#include <linux/slab.h>
19582 +#include <linux/rcupdate.h>
19583 +#include <linux/fs.h>
19584 +#include <linux/namei.h>
19585 +#include <linux/hash.h>
19586 +
19587 +#include <asm/errno.h>
19588 +#include <asm/uaccess.h>
19589 +#include <linux/vserver/base.h>
19590 +#include <linux/vserver/debug.h>
19591 +#include <linux/vserver/context.h>
19592 +#include <linux/vserver/device.h>
19593 +#include <linux/vserver/device_cmd.h>
19594 +
19595 +
19596 +#define DMAP_HASH_BITS 4
19597 +
19598 +
19599 +struct vs_mapping {
19600 +       union {
19601 +               struct hlist_node hlist;
19602 +               struct list_head list;
19603 +       } u;
19604 +#define dm_hlist       u.hlist
19605 +#define dm_list                u.list
19606 +       xid_t xid;
19607 +       dev_t device;
19608 +       struct vx_dmap_target target;
19609 +};
19610 +
19611 +
19612 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19613 +
19614 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
19615 +
19616 +static struct vx_dmap_target dmap_defaults[2] = {
19617 +       { .flags = DATTR_OPEN },
19618 +       { .flags = DATTR_OPEN },
19619 +};
19620 +
19621 +
19622 +struct kmem_cache *dmap_cachep __read_mostly;
19623 +
19624 +int __init dmap_cache_init(void)
19625 +{
19626 +       dmap_cachep = kmem_cache_create("dmap_cache",
19627 +               sizeof(struct vs_mapping), 0,
19628 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19629 +       return 0;
19630 +}
19631 +
19632 +__initcall(dmap_cache_init);
19633 +
19634 +
19635 +static inline unsigned int __hashval(dev_t dev, int bits)
19636 +{
19637 +       return hash_long((unsigned long)dev, bits);
19638 +}
19639 +
19640 +
19641 +/*     __hash_mapping()
19642 + *     add the mapping to the hash table
19643 + */
19644 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19645 +{
19646 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19647 +       struct hlist_head *head, *hash = dmap_main_hash;
19648 +       int device = vdm->device;
19649 +
19650 +       spin_lock(hash_lock);
19651 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19652 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19653 +
19654 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19655 +       hlist_add_head(&vdm->dm_hlist, head);
19656 +       spin_unlock(hash_lock);
19657 +}
19658 +
19659 +
19660 +static inline int __mode_to_default(umode_t mode)
19661 +{
19662 +       switch (mode) {
19663 +       case S_IFBLK:
19664 +               return 0;
19665 +       case S_IFCHR:
19666 +               return 1;
19667 +       default:
19668 +               BUG();
19669 +       }
19670 +}
19671 +
19672 +
19673 +/*     __set_default()
19674 + *     set a default
19675 + */
19676 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19677 +       struct vx_dmap_target *vdmt)
19678 +{
19679 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19680 +       spin_lock(hash_lock);
19681 +
19682 +       if (vxi)
19683 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19684 +       else
19685 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19686 +
19687 +
19688 +       spin_unlock(hash_lock);
19689 +
19690 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19691 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19692 +}
19693 +
19694 +
19695 +/*     __remove_default()
19696 + *     remove a default
19697 + */
19698 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19699 +{
19700 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19701 +       spin_lock(hash_lock);
19702 +
19703 +       if (vxi)
19704 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19705 +       else    /* remove == reset */
19706 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19707 +
19708 +       spin_unlock(hash_lock);
19709 +       return 0;
19710 +}
19711 +
19712 +
19713 +/*     __find_mapping()
19714 + *     find a mapping in the hash table
19715 + *
19716 + *     caller must hold hash_lock
19717 + */
19718 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19719 +       struct vs_mapping **local, struct vs_mapping **global)
19720 +{
19721 +       struct hlist_head *hash = dmap_main_hash;
19722 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19723 +       struct hlist_node *pos;
19724 +       struct vs_mapping *vdm;
19725 +
19726 +       *local = NULL;
19727 +       if (global)
19728 +               *global = NULL;
19729 +
19730 +       hlist_for_each(pos, head) {
19731 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19732 +
19733 +               if ((vdm->device == device) &&
19734 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19735 +                       if (vdm->xid == xid) {
19736 +                               *local = vdm;
19737 +                               return 1;
19738 +                       } else if (global && vdm->xid == 0)
19739 +                               *global = vdm;
19740 +               }
19741 +       }
19742 +
19743 +       if (global && *global)
19744 +               return 0;
19745 +       else
19746 +               return -ENOENT;
19747 +}
19748 +
19749 +
19750 +/*     __lookup_mapping()
19751 + *     find a mapping and store the result in target and flags
19752 + */
19753 +static inline int __lookup_mapping(struct vx_info *vxi,
19754 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19755 +{
19756 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19757 +       struct vs_mapping *vdm, *global;
19758 +       struct vx_dmap_target *vdmt;
19759 +       int ret = 0;
19760 +       xid_t xid = vxi->vx_id;
19761 +       int index;
19762 +
19763 +       spin_lock(hash_lock);
19764 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19765 +               ret = 1;
19766 +               vdmt = &vdm->target;
19767 +               goto found;
19768 +       }
19769 +
19770 +       index = __mode_to_default(mode);
19771 +       if (vxi && vxi->dmap.targets[index].flags) {
19772 +               ret = 2;
19773 +               vdmt = &vxi->dmap.targets[index];
19774 +       } else if (global) {
19775 +               ret = 3;
19776 +               vdmt = &global->target;
19777 +               goto found;
19778 +       } else {
19779 +               ret = 4;
19780 +               vdmt = &dmap_defaults[index];
19781 +       }
19782 +
19783 +found:
19784 +       if (target && (vdmt->flags & DATTR_REMAP))
19785 +               *target = vdmt->target;
19786 +       else if (target)
19787 +               *target = device;
19788 +       if (flags)
19789 +               *flags = vdmt->flags;
19790 +
19791 +       spin_unlock(hash_lock);
19792 +
19793 +       return ret;
19794 +}
19795 +
19796 +
19797 +/*     __remove_mapping()
19798 + *     remove a mapping from the hash table
19799 + */
19800 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19801 +       umode_t mode)
19802 +{
19803 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19804 +       struct vs_mapping *vdm = NULL;
19805 +       int ret = 0;
19806 +
19807 +       spin_lock(hash_lock);
19808 +
19809 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19810 +               NULL);
19811 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19812 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19813 +       if (ret < 0)
19814 +               goto out;
19815 +       hlist_del(&vdm->dm_hlist);
19816 +
19817 +out:
19818 +       spin_unlock(hash_lock);
19819 +       if (vdm)
19820 +               kmem_cache_free(dmap_cachep, vdm);
19821 +       return ret;
19822 +}
19823 +
19824 +
19825 +
19826 +int vs_map_device(struct vx_info *vxi,
19827 +       dev_t device, dev_t *target, umode_t mode)
19828 +{
19829 +       int ret, flags = DATTR_MASK;
19830 +
19831 +       if (!vxi) {
19832 +               if (target)
19833 +                       *target = device;
19834 +               goto out;
19835 +       }
19836 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19837 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19838 +               device, target ? *target : 0, flags, mode, ret);
19839 +out:
19840 +       return (flags & DATTR_MASK);
19841 +}
19842 +
19843 +
19844 +
19845 +static int do_set_mapping(struct vx_info *vxi,
19846 +       dev_t device, dev_t target, int flags, umode_t mode)
19847 +{
19848 +       if (device) {
19849 +               struct vs_mapping *new;
19850 +
19851 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19852 +               if (!new)
19853 +                       return -ENOMEM;
19854 +
19855 +               INIT_HLIST_NODE(&new->dm_hlist);
19856 +               new->device = device;
19857 +               new->target.target = target;
19858 +               new->target.flags = flags | mode;
19859 +               new->xid = (vxi ? vxi->vx_id : 0);
19860 +
19861 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19862 +               __hash_mapping(vxi, new);
19863 +       } else {
19864 +               struct vx_dmap_target new = {
19865 +                       .target = target,
19866 +                       .flags = flags | mode,
19867 +               };
19868 +               __set_default(vxi, mode, &new);
19869 +       }
19870 +       return 0;
19871 +}
19872 +
19873 +
19874 +static int do_unset_mapping(struct vx_info *vxi,
19875 +       dev_t device, dev_t target, int flags, umode_t mode)
19876 +{
19877 +       int ret = -EINVAL;
19878 +
19879 +       if (device) {
19880 +               ret = __remove_mapping(vxi, device, mode);
19881 +               if (ret < 0)
19882 +                       goto out;
19883 +       } else {
19884 +               ret = __remove_default(vxi, mode);
19885 +               if (ret < 0)
19886 +                       goto out;
19887 +       }
19888 +
19889 +out:
19890 +       return ret;
19891 +}
19892 +
19893 +
19894 +static inline int __user_device(const char __user *name, dev_t *dev,
19895 +       umode_t *mode)
19896 +{
19897 +       struct nameidata nd;
19898 +       int ret;
19899 +
19900 +       if (!name) {
19901 +               *dev = 0;
19902 +               return 0;
19903 +       }
19904 +       ret = user_lpath(name, &nd.path);
19905 +       if (ret)
19906 +               return ret;
19907 +       if (nd.path.dentry->d_inode) {
19908 +               *dev = nd.path.dentry->d_inode->i_rdev;
19909 +               *mode = nd.path.dentry->d_inode->i_mode;
19910 +       }
19911 +       path_put(&nd.path);
19912 +       return 0;
19913 +}
19914 +
19915 +static inline int __mapping_mode(dev_t device, dev_t target,
19916 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19917 +{
19918 +       if (device)
19919 +               *mode = device_mode & S_IFMT;
19920 +       else if (target)
19921 +               *mode = target_mode & S_IFMT;
19922 +       else
19923 +               return -EINVAL;
19924 +
19925 +       /* if both given, device and target mode have to match */
19926 +       if (device && target &&
19927 +               ((device_mode ^ target_mode) & S_IFMT))
19928 +               return -EINVAL;
19929 +       return 0;
19930 +}
19931 +
19932 +
19933 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19934 +       const char __user *target_path, int flags, int set)
19935 +{
19936 +       dev_t device = ~0, target = ~0;
19937 +       umode_t device_mode = 0, target_mode = 0, mode;
19938 +       int ret;
19939 +
19940 +       ret = __user_device(device_path, &device, &device_mode);
19941 +       if (ret)
19942 +               return ret;
19943 +       ret = __user_device(target_path, &target, &target_mode);
19944 +       if (ret)
19945 +               return ret;
19946 +
19947 +       ret = __mapping_mode(device, target,
19948 +               device_mode, target_mode, &mode);
19949 +       if (ret)
19950 +               return ret;
19951 +
19952 +       if (set)
19953 +               return do_set_mapping(vxi, device, target,
19954 +                       flags, mode);
19955 +       else
19956 +               return do_unset_mapping(vxi, device, target,
19957 +                       flags, mode);
19958 +}
19959 +
19960 +
19961 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19962 +{
19963 +       struct vcmd_set_mapping_v0 vc_data;
19964 +
19965 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19966 +               return -EFAULT;
19967 +
19968 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19969 +               vc_data.flags, 1);
19970 +}
19971 +
19972 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19973 +{
19974 +       struct vcmd_set_mapping_v0 vc_data;
19975 +
19976 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19977 +               return -EFAULT;
19978 +
19979 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19980 +               vc_data.flags, 0);
19981 +}
19982 +
19983 +
19984 +#ifdef CONFIG_COMPAT
19985 +
19986 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19987 +{
19988 +       struct vcmd_set_mapping_v0_x32 vc_data;
19989 +
19990 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19991 +               return -EFAULT;
19992 +
19993 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19994 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19995 +}
19996 +
19997 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19998 +{
19999 +       struct vcmd_set_mapping_v0_x32 vc_data;
20000 +
20001 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20002 +               return -EFAULT;
20003 +
20004 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
20005 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
20006 +}
20007 +
20008 +#endif /* CONFIG_COMPAT */
20009 +
20010 +
20011 diff -NurpP --minimal linux-3.0/kernel/vserver/dlimit.c linux-3.0-vs2.3.1-pre6/kernel/vserver/dlimit.c
20012 --- linux-3.0/kernel/vserver/dlimit.c   1970-01-01 01:00:00.000000000 +0100
20013 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/dlimit.c      2011-06-10 23:20:56.000000000 +0200
20014 @@ -0,0 +1,531 @@
20015 +/*
20016 + *  linux/kernel/vserver/dlimit.c
20017 + *
20018 + *  Virtual Server: Context Disk Limits
20019 + *
20020 + *  Copyright (C) 2004-2009  Herbert Pötzl
20021 + *
20022 + *  V0.01  initial version
20023 + *  V0.02  compat32 splitup
20024 + *  V0.03  extended interface
20025 + *
20026 + */
20027 +
20028 +#include <linux/statfs.h>
20029 +#include <linux/sched.h>
20030 +#include <linux/namei.h>
20031 +#include <linux/vs_tag.h>
20032 +#include <linux/vs_dlimit.h>
20033 +#include <linux/vserver/dlimit_cmd.h>
20034 +#include <linux/slab.h>
20035 +// #include <linux/gfp.h>
20036 +
20037 +#include <asm/uaccess.h>
20038 +
20039 +/*     __alloc_dl_info()
20040 +
20041 +       * allocate an initialized dl_info struct
20042 +       * doesn't make it visible (hash)                        */
20043 +
20044 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
20045 +{
20046 +       struct dl_info *new = NULL;
20047 +
20048 +       vxdprintk(VXD_CBIT(dlim, 5),
20049 +               "alloc_dl_info(%p,%d)*", sb, tag);
20050 +
20051 +       /* would this benefit from a slab cache? */
20052 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
20053 +       if (!new)
20054 +               return 0;
20055 +
20056 +       memset(new, 0, sizeof(struct dl_info));
20057 +       new->dl_tag = tag;
20058 +       new->dl_sb = sb;
20059 +       // INIT_RCU_HEAD(&new->dl_rcu);
20060 +       INIT_HLIST_NODE(&new->dl_hlist);
20061 +       spin_lock_init(&new->dl_lock);
20062 +       atomic_set(&new->dl_refcnt, 0);
20063 +       atomic_set(&new->dl_usecnt, 0);
20064 +
20065 +       /* rest of init goes here */
20066 +
20067 +       vxdprintk(VXD_CBIT(dlim, 4),
20068 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
20069 +       return new;
20070 +}
20071 +
20072 +/*     __dealloc_dl_info()
20073 +
20074 +       * final disposal of dl_info                             */
20075 +
20076 +static void __dealloc_dl_info(struct dl_info *dli)
20077 +{
20078 +       vxdprintk(VXD_CBIT(dlim, 4),
20079 +               "dealloc_dl_info(%p)", dli);
20080 +
20081 +       dli->dl_hlist.next = LIST_POISON1;
20082 +       dli->dl_tag = -1;
20083 +       dli->dl_sb = 0;
20084 +
20085 +       BUG_ON(atomic_read(&dli->dl_usecnt));
20086 +       BUG_ON(atomic_read(&dli->dl_refcnt));
20087 +
20088 +       kfree(dli);
20089 +}
20090 +
20091 +
20092 +/*     hash table for dl_info hash */
20093 +
20094 +#define DL_HASH_SIZE   13
20095 +
20096 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
20097 +
20098 +static DEFINE_SPINLOCK(dl_info_hash_lock);
20099 +
20100 +
20101 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
20102 +{
20103 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
20104 +}
20105 +
20106 +
20107 +
20108 +/*     __hash_dl_info()
20109 +
20110 +       * add the dli to the global hash table
20111 +       * requires the hash_lock to be held                     */
20112 +
20113 +static inline void __hash_dl_info(struct dl_info *dli)
20114 +{
20115 +       struct hlist_head *head;
20116 +
20117 +       vxdprintk(VXD_CBIT(dlim, 6),
20118 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
20119 +       get_dl_info(dli);
20120 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
20121 +       hlist_add_head_rcu(&dli->dl_hlist, head);
20122 +}
20123 +
20124 +/*     __unhash_dl_info()
20125 +
20126 +       * remove the dli from the global hash table
20127 +       * requires the hash_lock to be held                     */
20128 +
20129 +static inline void __unhash_dl_info(struct dl_info *dli)
20130 +{
20131 +       vxdprintk(VXD_CBIT(dlim, 6),
20132 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
20133 +       hlist_del_rcu(&dli->dl_hlist);
20134 +       put_dl_info(dli);
20135 +}
20136 +
20137 +
20138 +/*     __lookup_dl_info()
20139 +
20140 +       * requires the rcu_read_lock()
20141 +       * doesn't increment the dl_refcnt                       */
20142 +
20143 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
20144 +{
20145 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
20146 +       struct hlist_node *pos;
20147 +       struct dl_info *dli;
20148 +
20149 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
20150 +
20151 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
20152 +                       return dli;
20153 +               }
20154 +       }
20155 +       return NULL;
20156 +}
20157 +
20158 +
20159 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
20160 +{
20161 +       struct dl_info *dli;
20162 +
20163 +       rcu_read_lock();
20164 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
20165 +       vxdprintk(VXD_CBIT(dlim, 7),
20166 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
20167 +       rcu_read_unlock();
20168 +       return dli;
20169 +}
20170 +
20171 +void rcu_free_dl_info(struct rcu_head *head)
20172 +{
20173 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
20174 +       int usecnt, refcnt;
20175 +
20176 +       BUG_ON(!dli || !head);
20177 +
20178 +       usecnt = atomic_read(&dli->dl_usecnt);
20179 +       BUG_ON(usecnt < 0);
20180 +
20181 +       refcnt = atomic_read(&dli->dl_refcnt);
20182 +       BUG_ON(refcnt < 0);
20183 +
20184 +       vxdprintk(VXD_CBIT(dlim, 3),
20185 +               "rcu_free_dl_info(%p)", dli);
20186 +       if (!usecnt)
20187 +               __dealloc_dl_info(dli);
20188 +       else
20189 +               printk("!!! rcu didn't free\n");
20190 +}
20191 +
20192 +
20193 +
20194 +
20195 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
20196 +       uint32_t flags, int add)
20197 +{
20198 +       struct path path;
20199 +       int ret;
20200 +
20201 +       ret = user_lpath(name, &path);
20202 +       if (!ret) {
20203 +               struct super_block *sb;
20204 +               struct dl_info *dli;
20205 +
20206 +               ret = -EINVAL;
20207 +               if (!path.dentry->d_inode)
20208 +                       goto out_release;
20209 +               if (!(sb = path.dentry->d_inode->i_sb))
20210 +                       goto out_release;
20211 +
20212 +               if (add) {
20213 +                       dli = __alloc_dl_info(sb, id);
20214 +                       spin_lock(&dl_info_hash_lock);
20215 +
20216 +                       ret = -EEXIST;
20217 +                       if (__lookup_dl_info(sb, id))
20218 +                               goto out_unlock;
20219 +                       __hash_dl_info(dli);
20220 +                       dli = NULL;
20221 +               } else {
20222 +                       spin_lock(&dl_info_hash_lock);
20223 +                       dli = __lookup_dl_info(sb, id);
20224 +
20225 +                       ret = -ESRCH;
20226 +                       if (!dli)
20227 +                               goto out_unlock;
20228 +                       __unhash_dl_info(dli);
20229 +               }
20230 +               ret = 0;
20231 +       out_unlock:
20232 +               spin_unlock(&dl_info_hash_lock);
20233 +               if (add && dli)
20234 +                       __dealloc_dl_info(dli);
20235 +       out_release:
20236 +               path_put(&path);
20237 +       }
20238 +       return ret;
20239 +}
20240 +
20241 +int vc_add_dlimit(uint32_t id, void __user *data)
20242 +{
20243 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20244 +
20245 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20246 +               return -EFAULT;
20247 +
20248 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
20249 +}
20250 +
20251 +int vc_rem_dlimit(uint32_t id, void __user *data)
20252 +{
20253 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20254 +
20255 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20256 +               return -EFAULT;
20257 +
20258 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
20259 +}
20260 +
20261 +#ifdef CONFIG_COMPAT
20262 +
20263 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
20264 +{
20265 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20266 +
20267 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20268 +               return -EFAULT;
20269 +
20270 +       return do_addrem_dlimit(id,
20271 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
20272 +}
20273 +
20274 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
20275 +{
20276 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20277 +
20278 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20279 +               return -EFAULT;
20280 +
20281 +       return do_addrem_dlimit(id,
20282 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
20283 +}
20284 +
20285 +#endif /* CONFIG_COMPAT */
20286 +
20287 +
20288 +static inline
20289 +int do_set_dlimit(uint32_t id, const char __user *name,
20290 +       uint32_t space_used, uint32_t space_total,
20291 +       uint32_t inodes_used, uint32_t inodes_total,
20292 +       uint32_t reserved, uint32_t flags)
20293 +{
20294 +       struct path path;
20295 +       int ret;
20296 +
20297 +       ret = user_lpath(name, &path);
20298 +       if (!ret) {
20299 +               struct super_block *sb;
20300 +               struct dl_info *dli;
20301 +
20302 +               ret = -EINVAL;
20303 +               if (!path.dentry->d_inode)
20304 +                       goto out_release;
20305 +               if (!(sb = path.dentry->d_inode->i_sb))
20306 +                       goto out_release;
20307 +
20308 +               /* sanity checks */
20309 +               if ((reserved != CDLIM_KEEP &&
20310 +                       reserved > 100) ||
20311 +                       (inodes_used != CDLIM_KEEP &&
20312 +                       inodes_used > inodes_total) ||
20313 +                       (space_used != CDLIM_KEEP &&
20314 +                       space_used > space_total))
20315 +                       goto out_release;
20316 +
20317 +               ret = -ESRCH;
20318 +               dli = locate_dl_info(sb, id);
20319 +               if (!dli)
20320 +                       goto out_release;
20321 +
20322 +               spin_lock(&dli->dl_lock);
20323 +
20324 +               if (inodes_used != CDLIM_KEEP)
20325 +                       dli->dl_inodes_used = inodes_used;
20326 +               if (inodes_total != CDLIM_KEEP)
20327 +                       dli->dl_inodes_total = inodes_total;
20328 +               if (space_used != CDLIM_KEEP)
20329 +                       dli->dl_space_used = dlimit_space_32to64(
20330 +                               space_used, flags, DLIMS_USED);
20331 +
20332 +               if (space_total == CDLIM_INFINITY)
20333 +                       dli->dl_space_total = DLIM_INFINITY;
20334 +               else if (space_total != CDLIM_KEEP)
20335 +                       dli->dl_space_total = dlimit_space_32to64(
20336 +                               space_total, flags, DLIMS_TOTAL);
20337 +
20338 +               if (reserved != CDLIM_KEEP)
20339 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
20340 +
20341 +               spin_unlock(&dli->dl_lock);
20342 +
20343 +               put_dl_info(dli);
20344 +               ret = 0;
20345 +
20346 +       out_release:
20347 +               path_put(&path);
20348 +       }
20349 +       return ret;
20350 +}
20351 +
20352 +int vc_set_dlimit(uint32_t id, void __user *data)
20353 +{
20354 +       struct vcmd_ctx_dlimit_v0 vc_data;
20355 +
20356 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20357 +               return -EFAULT;
20358 +
20359 +       return do_set_dlimit(id, vc_data.name,
20360 +               vc_data.space_used, vc_data.space_total,
20361 +               vc_data.inodes_used, vc_data.inodes_total,
20362 +               vc_data.reserved, vc_data.flags);
20363 +}
20364 +
20365 +#ifdef CONFIG_COMPAT
20366 +
20367 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20368 +{
20369 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20370 +
20371 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20372 +               return -EFAULT;
20373 +
20374 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20375 +               vc_data.space_used, vc_data.space_total,
20376 +               vc_data.inodes_used, vc_data.inodes_total,
20377 +               vc_data.reserved, vc_data.flags);
20378 +}
20379 +
20380 +#endif /* CONFIG_COMPAT */
20381 +
20382 +
20383 +static inline
20384 +int do_get_dlimit(uint32_t id, const char __user *name,
20385 +       uint32_t *space_used, uint32_t *space_total,
20386 +       uint32_t *inodes_used, uint32_t *inodes_total,
20387 +       uint32_t *reserved, uint32_t *flags)
20388 +{
20389 +       struct path path;
20390 +       int ret;
20391 +
20392 +       ret = user_lpath(name, &path);
20393 +       if (!ret) {
20394 +               struct super_block *sb;
20395 +               struct dl_info *dli;
20396 +
20397 +               ret = -EINVAL;
20398 +               if (!path.dentry->d_inode)
20399 +                       goto out_release;
20400 +               if (!(sb = path.dentry->d_inode->i_sb))
20401 +                       goto out_release;
20402 +
20403 +               ret = -ESRCH;
20404 +               dli = locate_dl_info(sb, id);
20405 +               if (!dli)
20406 +                       goto out_release;
20407 +
20408 +               spin_lock(&dli->dl_lock);
20409 +               *inodes_used = dli->dl_inodes_used;
20410 +               *inodes_total = dli->dl_inodes_total;
20411 +
20412 +               *space_used = dlimit_space_64to32(
20413 +                       dli->dl_space_used, flags, DLIMS_USED);
20414 +
20415 +               if (dli->dl_space_total == DLIM_INFINITY)
20416 +                       *space_total = CDLIM_INFINITY;
20417 +               else
20418 +                       *space_total = dlimit_space_64to32(
20419 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
20420 +
20421 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20422 +               spin_unlock(&dli->dl_lock);
20423 +
20424 +               put_dl_info(dli);
20425 +               ret = -EFAULT;
20426 +
20427 +               ret = 0;
20428 +       out_release:
20429 +               path_put(&path);
20430 +       }
20431 +       return ret;
20432 +}
20433 +
20434 +
20435 +int vc_get_dlimit(uint32_t id, void __user *data)
20436 +{
20437 +       struct vcmd_ctx_dlimit_v0 vc_data;
20438 +       int ret;
20439 +
20440 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20441 +               return -EFAULT;
20442 +
20443 +       ret = do_get_dlimit(id, vc_data.name,
20444 +               &vc_data.space_used, &vc_data.space_total,
20445 +               &vc_data.inodes_used, &vc_data.inodes_total,
20446 +               &vc_data.reserved, &vc_data.flags);
20447 +       if (ret)
20448 +               return ret;
20449 +
20450 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20451 +               return -EFAULT;
20452 +       return 0;
20453 +}
20454 +
20455 +#ifdef CONFIG_COMPAT
20456 +
20457 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20458 +{
20459 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20460 +       int ret;
20461 +
20462 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20463 +               return -EFAULT;
20464 +
20465 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20466 +               &vc_data.space_used, &vc_data.space_total,
20467 +               &vc_data.inodes_used, &vc_data.inodes_total,
20468 +               &vc_data.reserved, &vc_data.flags);
20469 +       if (ret)
20470 +               return ret;
20471 +
20472 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20473 +               return -EFAULT;
20474 +       return 0;
20475 +}
20476 +
20477 +#endif /* CONFIG_COMPAT */
20478 +
20479 +
20480 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20481 +{
20482 +       struct dl_info *dli;
20483 +       __u64 blimit, bfree, bavail;
20484 +       __u32 ifree;
20485 +
20486 +       dli = locate_dl_info(sb, dx_current_tag());
20487 +       if (!dli)
20488 +               return;
20489 +
20490 +       spin_lock(&dli->dl_lock);
20491 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20492 +               goto no_ilim;
20493 +
20494 +       /* reduce max inodes available to limit */
20495 +       if (buf->f_files > dli->dl_inodes_total)
20496 +               buf->f_files = dli->dl_inodes_total;
20497 +
20498 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20499 +       /* reduce free inodes to min */
20500 +       if (ifree < buf->f_ffree)
20501 +               buf->f_ffree = ifree;
20502 +
20503 +no_ilim:
20504 +       if (dli->dl_space_total == DLIM_INFINITY)
20505 +               goto no_blim;
20506 +
20507 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20508 +
20509 +       if (dli->dl_space_total < dli->dl_space_used)
20510 +               bfree = 0;
20511 +       else
20512 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20513 +                       >> sb->s_blocksize_bits;
20514 +
20515 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20516 +       if (bavail < dli->dl_space_used)
20517 +               bavail = 0;
20518 +       else
20519 +               bavail = (bavail - dli->dl_space_used)
20520 +                       >> sb->s_blocksize_bits;
20521 +
20522 +       /* reduce max space available to limit */
20523 +       if (buf->f_blocks > blimit)
20524 +               buf->f_blocks = blimit;
20525 +
20526 +       /* reduce free space to min */
20527 +       if (bfree < buf->f_bfree)
20528 +               buf->f_bfree = bfree;
20529 +
20530 +       /* reduce avail space to min */
20531 +       if (bavail < buf->f_bavail)
20532 +               buf->f_bavail = bavail;
20533 +
20534 +no_blim:
20535 +       spin_unlock(&dli->dl_lock);
20536 +       put_dl_info(dli);
20537 +
20538 +       return;
20539 +}
20540 +
20541 +#include <linux/module.h>
20542 +
20543 +EXPORT_SYMBOL_GPL(locate_dl_info);
20544 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20545 +
20546 diff -NurpP --minimal linux-3.0/kernel/vserver/helper.c linux-3.0-vs2.3.1-pre6/kernel/vserver/helper.c
20547 --- linux-3.0/kernel/vserver/helper.c   1970-01-01 01:00:00.000000000 +0100
20548 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/helper.c      2011-06-10 22:11:24.000000000 +0200
20549 @@ -0,0 +1,223 @@
20550 +/*
20551 + *  linux/kernel/vserver/helper.c
20552 + *
20553 + *  Virtual Context Support
20554 + *
20555 + *  Copyright (C) 2004-2007  Herbert Pötzl
20556 + *
20557 + *  V0.01  basic helper
20558 + *
20559 + */
20560 +
20561 +#include <linux/kmod.h>
20562 +#include <linux/reboot.h>
20563 +#include <linux/vs_context.h>
20564 +#include <linux/vs_network.h>
20565 +#include <linux/vserver/signal.h>
20566 +
20567 +
20568 +char vshelper_path[255] = "/sbin/vshelper";
20569 +
20570 +
20571 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20572 +{
20573 +       int ret;
20574 +
20575 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20576 +               printk( KERN_WARNING
20577 +                       "%s: (%s %s) returned %s with %d\n",
20578 +                       name, argv[1], argv[2],
20579 +                       sync ? "sync" : "async", ret);
20580 +       }
20581 +       vxdprintk(VXD_CBIT(switch, 4),
20582 +               "%s: (%s %s) returned %s with %d",
20583 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20584 +       return ret;
20585 +}
20586 +
20587 +/*
20588 + *      vshelper path is set via /proc/sys
20589 + *      invoked by vserver sys_reboot(), with
20590 + *      the following arguments
20591 + *
20592 + *      argv [0] = vshelper_path;
20593 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20594 + *      argv [2] = context identifier
20595 + *
20596 + *      envp [*] = type-specific parameters
20597 + */
20598 +
20599 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20600 +{
20601 +       char id_buf[8], cmd_buf[16];
20602 +       char uid_buf[16], pid_buf[16];
20603 +       int ret;
20604 +
20605 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20606 +       char *envp[] = {"HOME=/", "TERM=linux",
20607 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20608 +                       uid_buf, pid_buf, cmd_buf, 0};
20609 +
20610 +       if (vx_info_state(vxi, VXS_HELPER))
20611 +               return -EAGAIN;
20612 +       vxi->vx_state |= VXS_HELPER;
20613 +
20614 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20615 +
20616 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20617 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
20618 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20619 +
20620 +       switch (cmd) {
20621 +       case LINUX_REBOOT_CMD_RESTART:
20622 +               argv[1] = "restart";
20623 +               break;
20624 +
20625 +       case LINUX_REBOOT_CMD_HALT:
20626 +               argv[1] = "halt";
20627 +               break;
20628 +
20629 +       case LINUX_REBOOT_CMD_POWER_OFF:
20630 +               argv[1] = "poweroff";
20631 +               break;
20632 +
20633 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20634 +               argv[1] = "swsusp";
20635 +               break;
20636 +
20637 +       case LINUX_REBOOT_CMD_OOM:
20638 +               argv[1] = "oom";
20639 +               break;
20640 +
20641 +       default:
20642 +               vxi->vx_state &= ~VXS_HELPER;
20643 +               return 0;
20644 +       }
20645 +
20646 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20647 +       vxi->vx_state &= ~VXS_HELPER;
20648 +       __wakeup_vx_info(vxi);
20649 +       return (ret) ? -EPERM : 0;
20650 +}
20651 +
20652 +
20653 +long vs_reboot(unsigned int cmd, void __user *arg)
20654 +{
20655 +       struct vx_info *vxi = current_vx_info();
20656 +       long ret = 0;
20657 +
20658 +       vxdprintk(VXD_CBIT(misc, 5),
20659 +               "vs_reboot(%p[#%d],%u)",
20660 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20661 +
20662 +       ret = vs_reboot_helper(vxi, cmd, arg);
20663 +       if (ret)
20664 +               return ret;
20665 +
20666 +       vxi->reboot_cmd = cmd;
20667 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20668 +               switch (cmd) {
20669 +               case LINUX_REBOOT_CMD_RESTART:
20670 +               case LINUX_REBOOT_CMD_HALT:
20671 +               case LINUX_REBOOT_CMD_POWER_OFF:
20672 +                       vx_info_kill(vxi, 0, SIGKILL);
20673 +                       vx_info_kill(vxi, 1, SIGKILL);
20674 +               default:
20675 +                       break;
20676 +               }
20677 +       }
20678 +       return 0;
20679 +}
20680 +
20681 +long vs_oom_action(unsigned int cmd)
20682 +{
20683 +       struct vx_info *vxi = current_vx_info();
20684 +       long ret = 0;
20685 +
20686 +       vxdprintk(VXD_CBIT(misc, 5),
20687 +               "vs_oom_action(%p[#%d],%u)",
20688 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20689 +
20690 +       ret = vs_reboot_helper(vxi, cmd, NULL);
20691 +       if (ret)
20692 +               return ret;
20693 +
20694 +       vxi->reboot_cmd = cmd;
20695 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20696 +               vx_info_kill(vxi, 0, SIGKILL);
20697 +               vx_info_kill(vxi, 1, SIGKILL);
20698 +       }
20699 +       return 0;
20700 +}
20701 +
20702 +/*
20703 + *      argv [0] = vshelper_path;
20704 + *      argv [1] = action: "startup", "shutdown"
20705 + *      argv [2] = context identifier
20706 + *
20707 + *      envp [*] = type-specific parameters
20708 + */
20709 +
20710 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20711 +{
20712 +       char id_buf[8], cmd_buf[16];
20713 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20714 +       char *envp[] = {"HOME=/", "TERM=linux",
20715 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20716 +
20717 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20718 +               return 0;
20719 +
20720 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20721 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20722 +
20723 +       switch (cmd) {
20724 +       case VSC_STARTUP:
20725 +               argv[1] = "startup";
20726 +               break;
20727 +       case VSC_SHUTDOWN:
20728 +               argv[1] = "shutdown";
20729 +               break;
20730 +       default:
20731 +               return 0;
20732 +       }
20733 +
20734 +       return do_vshelper(vshelper_path, argv, envp, 1);
20735 +}
20736 +
20737 +
20738 +/*
20739 + *      argv [0] = vshelper_path;
20740 + *      argv [1] = action: "netup", "netdown"
20741 + *      argv [2] = context identifier
20742 + *
20743 + *      envp [*] = type-specific parameters
20744 + */
20745 +
20746 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20747 +{
20748 +       char id_buf[8], cmd_buf[16];
20749 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20750 +       char *envp[] = {"HOME=/", "TERM=linux",
20751 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20752 +
20753 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20754 +               return 0;
20755 +
20756 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20757 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20758 +
20759 +       switch (cmd) {
20760 +       case VSC_NETUP:
20761 +               argv[1] = "netup";
20762 +               break;
20763 +       case VSC_NETDOWN:
20764 +               argv[1] = "netdown";
20765 +               break;
20766 +       default:
20767 +               return 0;
20768 +       }
20769 +
20770 +       return do_vshelper(vshelper_path, argv, envp, 1);
20771 +}
20772 +
20773 diff -NurpP --minimal linux-3.0/kernel/vserver/history.c linux-3.0-vs2.3.1-pre6/kernel/vserver/history.c
20774 --- linux-3.0/kernel/vserver/history.c  1970-01-01 01:00:00.000000000 +0100
20775 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/history.c     2011-06-10 22:11:24.000000000 +0200
20776 @@ -0,0 +1,258 @@
20777 +/*
20778 + *  kernel/vserver/history.c
20779 + *
20780 + *  Virtual Context History Backtrace
20781 + *
20782 + *  Copyright (C) 2004-2007  Herbert Pötzl
20783 + *
20784 + *  V0.01  basic structure
20785 + *  V0.02  hash/unhash and trace
20786 + *  V0.03  preemption fixes
20787 + *
20788 + */
20789 +
20790 +#include <linux/module.h>
20791 +#include <asm/uaccess.h>
20792 +
20793 +#include <linux/vserver/context.h>
20794 +#include <linux/vserver/debug.h>
20795 +#include <linux/vserver/debug_cmd.h>
20796 +#include <linux/vserver/history.h>
20797 +
20798 +
20799 +#ifdef CONFIG_VSERVER_HISTORY
20800 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20801 +#else
20802 +#define VXH_SIZE       64
20803 +#endif
20804 +
20805 +struct _vx_history {
20806 +       unsigned int counter;
20807 +
20808 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20809 +};
20810 +
20811 +
20812 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20813 +
20814 +unsigned volatile int vxh_active = 1;
20815 +
20816 +static atomic_t sequence = ATOMIC_INIT(0);
20817 +
20818 +
20819 +/*     vxh_advance()
20820 +
20821 +       * requires disabled preemption                          */
20822 +
20823 +struct _vx_hist_entry *vxh_advance(void *loc)
20824 +{
20825 +       unsigned int cpu = smp_processor_id();
20826 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20827 +       struct _vx_hist_entry *entry;
20828 +       unsigned int index;
20829 +
20830 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20831 +       entry = &hist->entry[index];
20832 +
20833 +       entry->seq = atomic_inc_return(&sequence);
20834 +       entry->loc = loc;
20835 +       return entry;
20836 +}
20837 +
20838 +EXPORT_SYMBOL_GPL(vxh_advance);
20839 +
20840 +
20841 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20842 +
20843 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20844 +
20845 +
20846 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20847 +
20848 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20849 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20850 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20851 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20852 +
20853 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20854 +{
20855 +       switch (e->type) {
20856 +       case VXH_THROW_OOPS:
20857 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20858 +               break;
20859 +
20860 +       case VXH_GET_VX_INFO:
20861 +       case VXH_PUT_VX_INFO:
20862 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20863 +                       VXH_LOC_ARGS(e),
20864 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20865 +                       VXH_VXI_ARGS(e));
20866 +               break;
20867 +
20868 +       case VXH_INIT_VX_INFO:
20869 +       case VXH_SET_VX_INFO:
20870 +       case VXH_CLR_VX_INFO:
20871 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20872 +                       VXH_LOC_ARGS(e),
20873 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20874 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20875 +                       VXH_VXI_ARGS(e), e->sc.data);
20876 +               break;
20877 +
20878 +       case VXH_CLAIM_VX_INFO:
20879 +       case VXH_RELEASE_VX_INFO:
20880 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20881 +                       VXH_LOC_ARGS(e),
20882 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20883 +                       VXH_VXI_ARGS(e), e->sc.data);
20884 +               break;
20885 +
20886 +       case VXH_ALLOC_VX_INFO:
20887 +       case VXH_DEALLOC_VX_INFO:
20888 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20889 +                       VXH_LOC_ARGS(e),
20890 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20891 +                       VXH_VXI_ARGS(e));
20892 +               break;
20893 +
20894 +       case VXH_HASH_VX_INFO:
20895 +       case VXH_UNHASH_VX_INFO:
20896 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20897 +                       VXH_LOC_ARGS(e),
20898 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20899 +                       VXH_VXI_ARGS(e));
20900 +               break;
20901 +
20902 +       case VXH_LOC_VX_INFO:
20903 +       case VXH_LOOKUP_VX_INFO:
20904 +       case VXH_CREATE_VX_INFO:
20905 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20906 +                       VXH_LOC_ARGS(e),
20907 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20908 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20909 +                       e->ll.arg, VXH_VXI_ARGS(e));
20910 +               break;
20911 +       }
20912 +}
20913 +
20914 +static void __vxh_dump_history(void)
20915 +{
20916 +       unsigned int i, cpu;
20917 +
20918 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20919 +               atomic_read(&sequence), NR_CPUS);
20920 +
20921 +       for (i = 0; i < VXH_SIZE; i++) {
20922 +               for_each_online_cpu(cpu) {
20923 +                       struct _vx_history *hist =
20924 +                               &per_cpu(vx_history_buffer, cpu);
20925 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20926 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20927 +
20928 +                       vxh_dump_entry(entry, cpu);
20929 +               }
20930 +       }
20931 +}
20932 +
20933 +void   vxh_dump_history(void)
20934 +{
20935 +       vxh_active = 0;
20936 +#ifdef CONFIG_SMP
20937 +       local_irq_enable();
20938 +       smp_send_stop();
20939 +       local_irq_disable();
20940 +#endif
20941 +       __vxh_dump_history();
20942 +}
20943 +
20944 +
20945 +/* vserver syscall commands below here */
20946 +
20947 +
20948 +int vc_dump_history(uint32_t id)
20949 +{
20950 +       vxh_active = 0;
20951 +       __vxh_dump_history();
20952 +       vxh_active = 1;
20953 +
20954 +       return 0;
20955 +}
20956 +
20957 +
20958 +int do_read_history(struct __user _vx_hist_entry *data,
20959 +       int cpu, uint32_t *index, uint32_t *count)
20960 +{
20961 +       int pos, ret = 0;
20962 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20963 +       int end = hist->counter;
20964 +       int start = end - VXH_SIZE + 2;
20965 +       int idx = *index;
20966 +
20967 +       /* special case: get current pos */
20968 +       if (!*count) {
20969 +               *index = end;
20970 +               return 0;
20971 +       }
20972 +
20973 +       /* have we lost some data? */
20974 +       if (idx < start)
20975 +               idx = start;
20976 +
20977 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20978 +               struct _vx_hist_entry *entry =
20979 +                       &hist->entry[idx % VXH_SIZE];
20980 +
20981 +               /* send entry to userspace */
20982 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20983 +               if (ret)
20984 +                       break;
20985 +       }
20986 +       /* save new index and count */
20987 +       *index = idx;
20988 +       *count = pos;
20989 +       return ret ? ret : (*index < end);
20990 +}
20991 +
20992 +int vc_read_history(uint32_t id, void __user *data)
20993 +{
20994 +       struct vcmd_read_history_v0 vc_data;
20995 +       int ret;
20996 +
20997 +       if (id >= NR_CPUS)
20998 +               return -EINVAL;
20999 +
21000 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21001 +               return -EFAULT;
21002 +
21003 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
21004 +               id, &vc_data.index, &vc_data.count);
21005 +
21006 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21007 +               return -EFAULT;
21008 +       return ret;
21009 +}
21010 +
21011 +#ifdef CONFIG_COMPAT
21012 +
21013 +int vc_read_history_x32(uint32_t id, void __user *data)
21014 +{
21015 +       struct vcmd_read_history_v0_x32 vc_data;
21016 +       int ret;
21017 +
21018 +       if (id >= NR_CPUS)
21019 +               return -EINVAL;
21020 +
21021 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21022 +               return -EFAULT;
21023 +
21024 +       ret = do_read_history((struct __user _vx_hist_entry *)
21025 +               compat_ptr(vc_data.data_ptr),
21026 +               id, &vc_data.index, &vc_data.count);
21027 +
21028 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21029 +               return -EFAULT;
21030 +       return ret;
21031 +}
21032 +
21033 +#endif /* CONFIG_COMPAT */
21034 +
21035 diff -NurpP --minimal linux-3.0/kernel/vserver/inet.c linux-3.0-vs2.3.1-pre6/kernel/vserver/inet.c
21036 --- linux-3.0/kernel/vserver/inet.c     1970-01-01 01:00:00.000000000 +0100
21037 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/inet.c        2011-06-13 18:20:44.000000000 +0200
21038 @@ -0,0 +1,225 @@
21039 +
21040 +#include <linux/in.h>
21041 +#include <linux/inetdevice.h>
21042 +#include <linux/vs_inet.h>
21043 +#include <linux/vs_inet6.h>
21044 +#include <linux/vserver/debug.h>
21045 +#include <net/route.h>
21046 +#include <net/addrconf.h>
21047 +
21048 +
21049 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
21050 +{
21051 +       int ret = 0;
21052 +
21053 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
21054 +               ret = 1;
21055 +       else {
21056 +               struct nx_addr_v4 *ptr;
21057 +
21058 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
21059 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
21060 +                               ret = 1;
21061 +                               break;
21062 +                       }
21063 +               }
21064 +       }
21065 +
21066 +       vxdprintk(VXD_CBIT(net, 2),
21067 +               "nx_v4_addr_conflict(%p,%p): %d",
21068 +               nxi1, nxi2, ret);
21069 +
21070 +       return ret;
21071 +}
21072 +
21073 +
21074 +#ifdef CONFIG_IPV6
21075 +
21076 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
21077 +{
21078 +       int ret = 0;
21079 +
21080 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
21081 +               ret = 1;
21082 +       else {
21083 +               struct nx_addr_v6 *ptr;
21084 +
21085 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
21086 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
21087 +                               ret = 1;
21088 +                               break;
21089 +                       }
21090 +               }
21091 +       }
21092 +
21093 +       vxdprintk(VXD_CBIT(net, 2),
21094 +               "nx_v6_addr_conflict(%p,%p): %d",
21095 +               nxi1, nxi2, ret);
21096 +
21097 +       return ret;
21098 +}
21099 +
21100 +#endif
21101 +
21102 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21103 +{
21104 +       struct in_device *in_dev;
21105 +       struct in_ifaddr **ifap;
21106 +       struct in_ifaddr *ifa;
21107 +       int ret = 0;
21108 +
21109 +       if (!dev)
21110 +               goto out;
21111 +       in_dev = in_dev_get(dev);
21112 +       if (!in_dev)
21113 +               goto out;
21114 +
21115 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
21116 +               ifap = &ifa->ifa_next) {
21117 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
21118 +                       ret = 1;
21119 +                       break;
21120 +               }
21121 +       }
21122 +       in_dev_put(in_dev);
21123 +out:
21124 +       return ret;
21125 +}
21126 +
21127 +
21128 +#ifdef CONFIG_IPV6
21129 +
21130 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21131 +{
21132 +       struct inet6_dev *in_dev;
21133 +       struct inet6_ifaddr *ifa;
21134 +       int ret = 0;
21135 +
21136 +       if (!dev)
21137 +               goto out;
21138 +       in_dev = in6_dev_get(dev);
21139 +       if (!in_dev)
21140 +               goto out;
21141 +
21142 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
21143 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
21144 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
21145 +                       ret = 1;
21146 +                       break;
21147 +               }
21148 +       }
21149 +       in6_dev_put(in_dev);
21150 +out:
21151 +       return ret;
21152 +}
21153 +
21154 +#endif
21155 +
21156 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21157 +{
21158 +       int ret = 1;
21159 +
21160 +       if (!nxi)
21161 +               goto out;
21162 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
21163 +               goto out;
21164 +#ifdef CONFIG_IPV6
21165 +       ret = 2;
21166 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
21167 +               goto out;
21168 +#endif
21169 +       ret = 0;
21170 +out:
21171 +       vxdprintk(VXD_CBIT(net, 3),
21172 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
21173 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
21174 +       return ret;
21175 +}
21176 +
21177 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
21178 +       struct flowi4 *fl4)
21179 +{
21180 +       struct rtable *rt;
21181 +
21182 +       if (!nxi)
21183 +               return NULL;
21184 +
21185 +       /* FIXME: handle lback only case */
21186 +       if (!NX_IPV4(nxi))
21187 +               return ERR_PTR(EPERM);
21188 +
21189 +       vxdprintk(VXD_CBIT(net, 4),
21190 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
21191 +               nxi, nxi ? nxi->nx_id : 0,
21192 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
21193 +
21194 +       /* single IP is unconditional */
21195 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
21196 +               (fl4->saddr == INADDR_ANY))
21197 +               fl4->saddr = nxi->v4.ip[0].s_addr;
21198 +
21199 +       if (fl4->saddr == INADDR_ANY) {
21200 +               struct nx_addr_v4 *ptr;
21201 +               __be32 found = 0;
21202 +
21203 +               rt = __ip_route_output_key(net, fl4);
21204 +               if (!IS_ERR(rt)) {
21205 +                       found = fl4->saddr;
21206 +                       ip_rt_put(rt);
21207 +                       vxdprintk(VXD_CBIT(net, 4),
21208 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21209 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
21210 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
21211 +                               goto found;
21212 +               }
21213 +
21214 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
21215 +                       __be32 primary = ptr->ip[0].s_addr;
21216 +                       __be32 mask = ptr->mask.s_addr;
21217 +                       __be32 neta = primary & mask;
21218 +
21219 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
21220 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
21221 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
21222 +                               NIPQUAD(mask), NIPQUAD(neta));
21223 +                       if ((found & mask) != neta)
21224 +                               continue;
21225 +
21226 +                       fl4->saddr = primary;
21227 +                       rt = __ip_route_output_key(net, fl4);
21228 +                       vxdprintk(VXD_CBIT(net, 4),
21229 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21230 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
21231 +                       if (!IS_ERR(rt)) {
21232 +                               found = fl4->saddr;
21233 +                               ip_rt_put(rt);
21234 +                               if (found == primary)
21235 +                                       goto found;
21236 +                       }
21237 +               }
21238 +               /* still no source ip? */
21239 +               found = ipv4_is_loopback(fl4->daddr)
21240 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
21241 +       found:
21242 +               /* assign src ip to flow */
21243 +               fl4->saddr = found;
21244 +
21245 +       } else {
21246 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
21247 +                       return ERR_PTR(EPERM);
21248 +       }
21249 +
21250 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
21251 +               if (ipv4_is_loopback(fl4->daddr))
21252 +                       fl4->daddr = nxi->v4_lback.s_addr;
21253 +               if (ipv4_is_loopback(fl4->saddr))
21254 +                       fl4->saddr = nxi->v4_lback.s_addr;
21255 +       } else if (ipv4_is_loopback(fl4->daddr) &&
21256 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
21257 +               return ERR_PTR(EPERM);
21258 +
21259 +       return NULL;
21260 +}
21261 +
21262 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
21263 +
21264 diff -NurpP --minimal linux-3.0/kernel/vserver/init.c linux-3.0-vs2.3.1-pre6/kernel/vserver/init.c
21265 --- linux-3.0/kernel/vserver/init.c     1970-01-01 01:00:00.000000000 +0100
21266 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/init.c        2011-06-10 22:11:24.000000000 +0200
21267 @@ -0,0 +1,45 @@
21268 +/*
21269 + *  linux/kernel/init.c
21270 + *
21271 + *  Virtual Server Init
21272 + *
21273 + *  Copyright (C) 2004-2007  Herbert Pötzl
21274 + *
21275 + *  V0.01  basic structure
21276 + *
21277 + */
21278 +
21279 +#include <linux/init.h>
21280 +
21281 +int    vserver_register_sysctl(void);
21282 +void   vserver_unregister_sysctl(void);
21283 +
21284 +
21285 +static int __init init_vserver(void)
21286 +{
21287 +       int ret = 0;
21288 +
21289 +#ifdef CONFIG_VSERVER_DEBUG
21290 +       vserver_register_sysctl();
21291 +#endif
21292 +       return ret;
21293 +}
21294 +
21295 +
21296 +static void __exit exit_vserver(void)
21297 +{
21298 +
21299 +#ifdef CONFIG_VSERVER_DEBUG
21300 +       vserver_unregister_sysctl();
21301 +#endif
21302 +       return;
21303 +}
21304 +
21305 +/* FIXME: GFP_ZONETYPES gone
21306 +long vx_slab[GFP_ZONETYPES]; */
21307 +long vx_area;
21308 +
21309 +
21310 +module_init(init_vserver);
21311 +module_exit(exit_vserver);
21312 +
21313 diff -NurpP --minimal linux-3.0/kernel/vserver/inode.c linux-3.0-vs2.3.1-pre6/kernel/vserver/inode.c
21314 --- linux-3.0/kernel/vserver/inode.c    1970-01-01 01:00:00.000000000 +0100
21315 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/inode.c       2011-06-10 22:11:24.000000000 +0200
21316 @@ -0,0 +1,437 @@
21317 +/*
21318 + *  linux/kernel/vserver/inode.c
21319 + *
21320 + *  Virtual Server: File System Support
21321 + *
21322 + *  Copyright (C) 2004-2007  Herbert Pötzl
21323 + *
21324 + *  V0.01  separated from vcontext V0.05
21325 + *  V0.02  moved to tag (instead of xid)
21326 + *
21327 + */
21328 +
21329 +#include <linux/tty.h>
21330 +#include <linux/proc_fs.h>
21331 +#include <linux/devpts_fs.h>
21332 +#include <linux/fs.h>
21333 +#include <linux/file.h>
21334 +#include <linux/mount.h>
21335 +#include <linux/parser.h>
21336 +#include <linux/namei.h>
21337 +#include <linux/vserver/inode.h>
21338 +#include <linux/vserver/inode_cmd.h>
21339 +#include <linux/vs_base.h>
21340 +#include <linux/vs_tag.h>
21341 +
21342 +#include <asm/uaccess.h>
21343 +
21344 +
21345 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21346 +{
21347 +       struct proc_dir_entry *entry;
21348 +
21349 +       if (!in || !in->i_sb)
21350 +               return -ESRCH;
21351 +
21352 +       *flags = IATTR_TAG
21353 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
21354 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
21355 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
21356 +               | (IS_COW(in) ? IATTR_COW : 0);
21357 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
21358 +
21359 +       if (S_ISDIR(in->i_mode))
21360 +               *mask |= IATTR_BARRIER;
21361 +
21362 +       if (IS_TAGGED(in)) {
21363 +               *tag = in->i_tag;
21364 +               *mask |= IATTR_TAG;
21365 +       }
21366 +
21367 +       switch (in->i_sb->s_magic) {
21368 +       case PROC_SUPER_MAGIC:
21369 +               entry = PROC_I(in)->pde;
21370 +
21371 +               /* check for specific inodes? */
21372 +               if (entry)
21373 +                       *mask |= IATTR_FLAGS;
21374 +               if (entry)
21375 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21376 +               else
21377 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21378 +               break;
21379 +
21380 +       case DEVPTS_SUPER_MAGIC:
21381 +               *tag = in->i_tag;
21382 +               *mask |= IATTR_TAG;
21383 +               break;
21384 +
21385 +       default:
21386 +               break;
21387 +       }
21388 +       return 0;
21389 +}
21390 +
21391 +int vc_get_iattr(void __user *data)
21392 +{
21393 +       struct path path;
21394 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21395 +       int ret;
21396 +
21397 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21398 +               return -EFAULT;
21399 +
21400 +       ret = user_lpath(vc_data.name, &path);
21401 +       if (!ret) {
21402 +               ret = __vc_get_iattr(path.dentry->d_inode,
21403 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21404 +               path_put(&path);
21405 +       }
21406 +       if (ret)
21407 +               return ret;
21408 +
21409 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21410 +               ret = -EFAULT;
21411 +       return ret;
21412 +}
21413 +
21414 +#ifdef CONFIG_COMPAT
21415 +
21416 +int vc_get_iattr_x32(void __user *data)
21417 +{
21418 +       struct path path;
21419 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21420 +       int ret;
21421 +
21422 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21423 +               return -EFAULT;
21424 +
21425 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21426 +       if (!ret) {
21427 +               ret = __vc_get_iattr(path.dentry->d_inode,
21428 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21429 +               path_put(&path);
21430 +       }
21431 +       if (ret)
21432 +               return ret;
21433 +
21434 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21435 +               ret = -EFAULT;
21436 +       return ret;
21437 +}
21438 +
21439 +#endif /* CONFIG_COMPAT */
21440 +
21441 +
21442 +int vc_fget_iattr(uint32_t fd, void __user *data)
21443 +{
21444 +       struct file *filp;
21445 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21446 +       int ret;
21447 +
21448 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21449 +               return -EFAULT;
21450 +
21451 +       filp = fget(fd);
21452 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21453 +               return -EBADF;
21454 +
21455 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21456 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21457 +
21458 +       fput(filp);
21459 +
21460 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21461 +               ret = -EFAULT;
21462 +       return ret;
21463 +}
21464 +
21465 +
21466 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21467 +{
21468 +       struct inode *in = de->d_inode;
21469 +       int error = 0, is_proc = 0, has_tag = 0;
21470 +       struct iattr attr = { 0 };
21471 +
21472 +       if (!in || !in->i_sb)
21473 +               return -ESRCH;
21474 +
21475 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21476 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21477 +               return -EINVAL;
21478 +
21479 +       has_tag = IS_TAGGED(in) ||
21480 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21481 +       if ((*mask & IATTR_TAG) && !has_tag)
21482 +               return -EINVAL;
21483 +
21484 +       mutex_lock(&in->i_mutex);
21485 +       if (*mask & IATTR_TAG) {
21486 +               attr.ia_tag = *tag;
21487 +               attr.ia_valid |= ATTR_TAG;
21488 +       }
21489 +
21490 +       if (*mask & IATTR_FLAGS) {
21491 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21492 +               unsigned int iflags = PROC_I(in)->vx_flags;
21493 +
21494 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21495 +                       | (*flags & IATTR_FLAGS);
21496 +               PROC_I(in)->vx_flags = iflags;
21497 +               if (entry)
21498 +                       entry->vx_flags = iflags;
21499 +       }
21500 +
21501 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
21502 +               IATTR_BARRIER | IATTR_COW)) {
21503 +               int iflags = in->i_flags;
21504 +               int vflags = in->i_vflags;
21505 +
21506 +               if (*mask & IATTR_IMMUTABLE) {
21507 +                       if (*flags & IATTR_IMMUTABLE)
21508 +                               iflags |= S_IMMUTABLE;
21509 +                       else
21510 +                               iflags &= ~S_IMMUTABLE;
21511 +               }
21512 +               if (*mask & IATTR_IXUNLINK) {
21513 +                       if (*flags & IATTR_IXUNLINK)
21514 +                               iflags |= S_IXUNLINK;
21515 +                       else
21516 +                               iflags &= ~S_IXUNLINK;
21517 +               }
21518 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21519 +                       if (*flags & IATTR_BARRIER)
21520 +                               vflags |= V_BARRIER;
21521 +                       else
21522 +                               vflags &= ~V_BARRIER;
21523 +               }
21524 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
21525 +                       if (*flags & IATTR_COW)
21526 +                               vflags |= V_COW;
21527 +                       else
21528 +                               vflags &= ~V_COW;
21529 +               }
21530 +               if (in->i_op && in->i_op->sync_flags) {
21531 +                       error = in->i_op->sync_flags(in, iflags, vflags);
21532 +                       if (error)
21533 +                               goto out;
21534 +               }
21535 +       }
21536 +
21537 +       if (attr.ia_valid) {
21538 +               if (in->i_op && in->i_op->setattr)
21539 +                       error = in->i_op->setattr(de, &attr);
21540 +               else {
21541 +                       error = inode_change_ok(in, &attr);
21542 +                       if (!error) {
21543 +                               setattr_copy(in, &attr);
21544 +                               mark_inode_dirty(in);
21545 +                       }
21546 +               }
21547 +       }
21548 +
21549 +out:
21550 +       mutex_unlock(&in->i_mutex);
21551 +       return error;
21552 +}
21553 +
21554 +int vc_set_iattr(void __user *data)
21555 +{
21556 +       struct path path;
21557 +       struct vcmd_ctx_iattr_v1 vc_data;
21558 +       int ret;
21559 +
21560 +       if (!capable(CAP_LINUX_IMMUTABLE))
21561 +               return -EPERM;
21562 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21563 +               return -EFAULT;
21564 +
21565 +       ret = user_lpath(vc_data.name, &path);
21566 +       if (!ret) {
21567 +               ret = __vc_set_iattr(path.dentry,
21568 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21569 +               path_put(&path);
21570 +       }
21571 +
21572 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21573 +               ret = -EFAULT;
21574 +       return ret;
21575 +}
21576 +
21577 +#ifdef CONFIG_COMPAT
21578 +
21579 +int vc_set_iattr_x32(void __user *data)
21580 +{
21581 +       struct path path;
21582 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21583 +       int ret;
21584 +
21585 +       if (!capable(CAP_LINUX_IMMUTABLE))
21586 +               return -EPERM;
21587 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21588 +               return -EFAULT;
21589 +
21590 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21591 +       if (!ret) {
21592 +               ret = __vc_set_iattr(path.dentry,
21593 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21594 +               path_put(&path);
21595 +       }
21596 +
21597 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21598 +               ret = -EFAULT;
21599 +       return ret;
21600 +}
21601 +
21602 +#endif /* CONFIG_COMPAT */
21603 +
21604 +int vc_fset_iattr(uint32_t fd, void __user *data)
21605 +{
21606 +       struct file *filp;
21607 +       struct vcmd_ctx_fiattr_v0 vc_data;
21608 +       int ret;
21609 +
21610 +       if (!capable(CAP_LINUX_IMMUTABLE))
21611 +               return -EPERM;
21612 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21613 +               return -EFAULT;
21614 +
21615 +       filp = fget(fd);
21616 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21617 +               return -EBADF;
21618 +
21619 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21620 +               &vc_data.flags, &vc_data.mask);
21621 +
21622 +       fput(filp);
21623 +
21624 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21625 +               return -EFAULT;
21626 +       return ret;
21627 +}
21628 +
21629 +
21630 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21631 +
21632 +static match_table_t tokens = {
21633 +       {Opt_notagcheck, "notagcheck"},
21634 +#ifdef CONFIG_PROPAGATE
21635 +       {Opt_notag, "notag"},
21636 +       {Opt_tag, "tag"},
21637 +       {Opt_tagid, "tagid=%u"},
21638 +#endif
21639 +       {Opt_err, NULL}
21640 +};
21641 +
21642 +
21643 +static void __dx_parse_remove(char *string, char *opt)
21644 +{
21645 +       char *p = strstr(string, opt);
21646 +       char *q = p;
21647 +
21648 +       if (p) {
21649 +               while (*q != '\0' && *q != ',')
21650 +                       q++;
21651 +               while (*q)
21652 +                       *p++ = *q++;
21653 +               while (*p)
21654 +                       *p++ = '\0';
21655 +       }
21656 +}
21657 +
21658 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21659 +                unsigned long *flags)
21660 +{
21661 +       int set = 0;
21662 +       substring_t args[MAX_OPT_ARGS];
21663 +       int token;
21664 +       char *s, *p, *opts;
21665 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_WARN)
21666 +       int option = 0;
21667 +#endif
21668 +
21669 +       if (!string)
21670 +               return 0;
21671 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21672 +       if (!s)
21673 +               return 0;
21674 +
21675 +       opts = s;
21676 +       while ((p = strsep(&opts, ",")) != NULL) {
21677 +               token = match_token(p, tokens, args);
21678 +
21679 +               switch (token) {
21680 +#ifdef CONFIG_PROPAGATE
21681 +               case Opt_tag:
21682 +                       if (tag)
21683 +                               *tag = 0;
21684 +                       if (remove)
21685 +                               __dx_parse_remove(s, "tag");
21686 +                       *mnt_flags |= MNT_TAGID;
21687 +                       set |= MNT_TAGID;
21688 +                       break;
21689 +               case Opt_notag:
21690 +                       if (remove)
21691 +                               __dx_parse_remove(s, "notag");
21692 +                       *mnt_flags |= MNT_NOTAG;
21693 +                       set |= MNT_NOTAG;
21694 +                       break;
21695 +               case Opt_tagid:
21696 +                       if (tag && !match_int(args, &option))
21697 +                               *tag = option;
21698 +                       if (remove)
21699 +                               __dx_parse_remove(s, "tagid");
21700 +                       *mnt_flags |= MNT_TAGID;
21701 +                       set |= MNT_TAGID;
21702 +                       break;
21703 +#endif
21704 +               case Opt_notagcheck:
21705 +                       if (remove)
21706 +                               __dx_parse_remove(s, "notagcheck");
21707 +                       *flags |= MS_NOTAGCHECK;
21708 +                       set |= MS_NOTAGCHECK;
21709 +                       break;
21710 +               }
21711 +               vxdprintk(VXD_CBIT(tag, 7),
21712 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
21713 +                       p, token, option);
21714 +       }
21715 +       if (set)
21716 +               strcpy(string, s);
21717 +       kfree(s);
21718 +       return set;
21719 +}
21720 +
21721 +#ifdef CONFIG_PROPAGATE
21722 +
21723 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21724 +{
21725 +       tag_t new_tag = 0;
21726 +       struct vfsmount *mnt;
21727 +       int propagate;
21728 +
21729 +       if (!nd)
21730 +               return;
21731 +       mnt = nd->path.mnt;
21732 +       if (!mnt)
21733 +               return;
21734 +
21735 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21736 +       if (propagate)
21737 +               new_tag = mnt->mnt_tag;
21738 +
21739 +       vxdprintk(VXD_CBIT(tag, 7),
21740 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21741 +               inode, inode->i_ino, inode->i_tag,
21742 +               new_tag, (propagate) ? 1 : 0);
21743 +
21744 +       if (propagate)
21745 +               inode->i_tag = new_tag;
21746 +}
21747 +
21748 +#include <linux/module.h>
21749 +
21750 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21751 +
21752 +#endif /* CONFIG_PROPAGATE */
21753 +
21754 diff -NurpP --minimal linux-3.0/kernel/vserver/limit.c linux-3.0-vs2.3.1-pre6/kernel/vserver/limit.c
21755 --- linux-3.0/kernel/vserver/limit.c    1970-01-01 01:00:00.000000000 +0100
21756 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/limit.c       2011-06-10 22:11:24.000000000 +0200
21757 @@ -0,0 +1,354 @@
21758 +/*
21759 + *  linux/kernel/vserver/limit.c
21760 + *
21761 + *  Virtual Server: Context Limits
21762 + *
21763 + *  Copyright (C) 2004-2010  Herbert Pötzl
21764 + *
21765 + *  V0.01  broken out from vcontext V0.05
21766 + *  V0.02  changed vcmds to vxi arg
21767 + *  V0.03  added memory cgroup support
21768 + *
21769 + */
21770 +
21771 +#include <linux/sched.h>
21772 +#include <linux/module.h>
21773 +#include <linux/memcontrol.h>
21774 +#include <linux/res_counter.h>
21775 +#include <linux/vs_limit.h>
21776 +#include <linux/vserver/limit.h>
21777 +#include <linux/vserver/limit_cmd.h>
21778 +
21779 +#include <asm/uaccess.h>
21780 +
21781 +
21782 +const char *vlimit_name[NUM_LIMITS] = {
21783 +#ifdef CONFIG_VSERVER_LEGACY_MEM
21784 +       [RLIMIT_RSS]            = "RSS",
21785 +       [RLIMIT_AS]             = "VM",
21786 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
21787 +       [RLIMIT_CPU]            = "CPU",
21788 +       [RLIMIT_NPROC]          = "NPROC",
21789 +       [RLIMIT_NOFILE]         = "NOFILE",
21790 +       [RLIMIT_LOCKS]          = "LOCKS",
21791 +       [RLIMIT_SIGPENDING]     = "SIGP",
21792 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21793 +
21794 +       [VLIMIT_NSOCK]          = "NSOCK",
21795 +       [VLIMIT_OPENFD]         = "OPENFD",
21796 +       [VLIMIT_SHMEM]          = "SHMEM",
21797 +       [VLIMIT_DENTRY]         = "DENTRY",
21798 +};
21799 +
21800 +EXPORT_SYMBOL_GPL(vlimit_name);
21801 +
21802 +#define MASK_ENTRY(x)  (1 << (x))
21803 +
21804 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21805 +               /* minimum */
21806 +       0
21807 +       ,       /* softlimit */
21808 +#ifdef CONFIG_VSERVER_LEGACY_MEM
21809 +       MASK_ENTRY( RLIMIT_RSS          ) |
21810 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
21811 +       0
21812 +       ,       /* maximum */
21813 +#ifdef CONFIG_VSERVER_LEGACY_MEM
21814 +       MASK_ENTRY( RLIMIT_RSS          ) |
21815 +       MASK_ENTRY( RLIMIT_AS           ) |
21816 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
21817 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21818 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21819 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21820 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21821 +
21822 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21823 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21824 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21825 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21826 +       0
21827 +};
21828 +               /* accounting only */
21829 +uint32_t account_mask =
21830 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21831 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21832 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21833 +       0;
21834 +
21835 +
21836 +static int is_valid_vlimit(int id)
21837 +{
21838 +       uint32_t mask = vlimit_mask.minimum |
21839 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21840 +       return mask & (1 << id);
21841 +}
21842 +
21843 +static int is_accounted_vlimit(int id)
21844 +{
21845 +       if (is_valid_vlimit(id))
21846 +               return 1;
21847 +       return account_mask & (1 << id);
21848 +}
21849 +
21850 +
21851 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21852 +{
21853 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21854 +       return VX_VLIM(limit);
21855 +}
21856 +
21857 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21858 +{
21859 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21860 +       return VX_VLIM(limit);
21861 +}
21862 +
21863 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21864 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21865 +{
21866 +       if (!is_valid_vlimit(id))
21867 +               return -EINVAL;
21868 +
21869 +       if (minimum)
21870 +               *minimum = CRLIM_UNSET;
21871 +       if (softlimit)
21872 +               *softlimit = vc_get_soft(vxi, id);
21873 +       if (maximum)
21874 +               *maximum = vc_get_hard(vxi, id);
21875 +       return 0;
21876 +}
21877 +
21878 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21879 +{
21880 +       struct vcmd_ctx_rlimit_v0 vc_data;
21881 +       int ret;
21882 +
21883 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21884 +               return -EFAULT;
21885 +
21886 +       ret = do_get_rlimit(vxi, vc_data.id,
21887 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21888 +       if (ret)
21889 +               return ret;
21890 +
21891 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21892 +               return -EFAULT;
21893 +       return 0;
21894 +}
21895 +
21896 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21897 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21898 +{
21899 +       if (!is_valid_vlimit(id))
21900 +               return -EINVAL;
21901 +
21902 +       if (maximum != CRLIM_KEEP)
21903 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21904 +       if (softlimit != CRLIM_KEEP)
21905 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21906 +
21907 +       /* clamp soft limit */
21908 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21909 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21910 +
21911 +       return 0;
21912 +}
21913 +
21914 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21915 +{
21916 +       struct vcmd_ctx_rlimit_v0 vc_data;
21917 +
21918 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21919 +               return -EFAULT;
21920 +
21921 +       return do_set_rlimit(vxi, vc_data.id,
21922 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21923 +}
21924 +
21925 +#ifdef CONFIG_IA32_EMULATION
21926 +
21927 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21928 +{
21929 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21930 +
21931 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21932 +               return -EFAULT;
21933 +
21934 +       return do_set_rlimit(vxi, vc_data.id,
21935 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21936 +}
21937 +
21938 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21939 +{
21940 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21941 +       int ret;
21942 +
21943 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21944 +               return -EFAULT;
21945 +
21946 +       ret = do_get_rlimit(vxi, vc_data.id,
21947 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21948 +       if (ret)
21949 +               return ret;
21950 +
21951 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21952 +               return -EFAULT;
21953 +       return 0;
21954 +}
21955 +
21956 +#endif /* CONFIG_IA32_EMULATION */
21957 +
21958 +
21959 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21960 +{
21961 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21962 +               return -EFAULT;
21963 +       return 0;
21964 +}
21965 +
21966 +
21967 +static inline void vx_reset_hits(struct _vx_limit *limit)
21968 +{
21969 +       int lim;
21970 +
21971 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21972 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21973 +       }
21974 +}
21975 +
21976 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
21977 +{
21978 +       vx_reset_hits(&vxi->limit);
21979 +       return 0;
21980 +}
21981 +
21982 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21983 +{
21984 +       rlim_t value;
21985 +       int lim;
21986 +
21987 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21988 +               value = __rlim_get(limit, lim);
21989 +               __rlim_rmax(limit, lim) = value;
21990 +               __rlim_rmin(limit, lim) = value;
21991 +       }
21992 +}
21993 +
21994 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21995 +{
21996 +       vx_reset_minmax(&vxi->limit);
21997 +       return 0;
21998 +}
21999 +
22000 +
22001 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
22002 +{
22003 +       struct vcmd_rlimit_stat_v0 vc_data;
22004 +       struct _vx_limit *limit = &vxi->limit;
22005 +       int id;
22006 +
22007 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22008 +               return -EFAULT;
22009 +
22010 +       id = vc_data.id;
22011 +       if (!is_accounted_vlimit(id))
22012 +               return -EINVAL;
22013 +
22014 +       vx_limit_fixup(limit, id);
22015 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
22016 +       vc_data.value = __rlim_get(limit, id);
22017 +       vc_data.minimum = __rlim_rmin(limit, id);
22018 +       vc_data.maximum = __rlim_rmax(limit, id);
22019 +
22020 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22021 +               return -EFAULT;
22022 +       return 0;
22023 +}
22024 +
22025 +
22026 +void vx_vsi_meminfo(struct sysinfo *val)
22027 +{
22028 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22029 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22030 +       u64 res_limit, res_usage;
22031 +
22032 +       if (!mcg)
22033 +               return;
22034 +
22035 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
22036 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
22037 +
22038 +       if (res_limit != RESOURCE_MAX)
22039 +               val->totalram = (res_limit >> PAGE_SHIFT);
22040 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
22041 +       val->bufferram = 0;
22042 +       val->totalhigh = 0;
22043 +       val->freehigh = 0;
22044 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
22045 +       return;
22046 +}
22047 +
22048 +void vx_vsi_swapinfo(struct sysinfo *val)
22049 +{
22050 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22051 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
22052 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22053 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
22054 +       s64 swap_limit, swap_usage;
22055 +
22056 +       if (!mcg)
22057 +               return;
22058 +
22059 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
22060 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
22061 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
22062 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
22063 +
22064 +       if (res_limit == RESOURCE_MAX)
22065 +               return;
22066 +
22067 +       swap_limit = memsw_limit - res_limit;
22068 +       if (memsw_limit != RESOURCE_MAX)
22069 +               val->totalswap = swap_limit >> PAGE_SHIFT;
22070 +
22071 +       swap_usage = memsw_usage - res_usage;
22072 +       val->freeswap = (swap_usage < swap_limit) ?
22073 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
22074 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22075 +       val->totalswap = 0;
22076 +       val->freeswap = 0;
22077 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22078 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
22079 +       return;
22080 +}
22081 +
22082 +long vx_vsi_cached(struct sysinfo *val)
22083 +{
22084 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22085 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22086 +
22087 +       return mem_cgroup_stat_read_cache(mcg);
22088 +#else
22089 +       return 0;
22090 +#endif
22091 +}
22092 +
22093 +
22094 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
22095 +{
22096 +       struct vx_info *vxi = mm->mm_vx_info;
22097 +       unsigned long points;
22098 +       rlim_t v, w;
22099 +
22100 +       if (!vxi)
22101 +               return 0;
22102 +
22103 +       points = vxi->vx_badness_bias;
22104 +
22105 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22106 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22107 +       points += (v > w) ? (v - w) : 0;
22108 +
22109 +       return points;
22110 +}
22111 +
22112 diff -NurpP --minimal linux-3.0/kernel/vserver/limit_init.h linux-3.0-vs2.3.1-pre6/kernel/vserver/limit_init.h
22113 --- linux-3.0/kernel/vserver/limit_init.h       1970-01-01 01:00:00.000000000 +0100
22114 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/limit_init.h  2011-06-10 22:11:24.000000000 +0200
22115 @@ -0,0 +1,31 @@
22116 +
22117 +
22118 +static inline void vx_info_init_limit(struct _vx_limit *limit)
22119 +{
22120 +       int lim;
22121 +
22122 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22123 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
22124 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
22125 +               __rlim_set(limit, lim, 0);
22126 +               atomic_set(&__rlim_lhit(limit, lim), 0);
22127 +               __rlim_rmin(limit, lim) = 0;
22128 +               __rlim_rmax(limit, lim) = 0;
22129 +       }
22130 +}
22131 +
22132 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
22133 +{
22134 +       rlim_t value;
22135 +       int lim;
22136 +
22137 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22138 +               if ((1 << lim) & VLIM_NOCHECK)
22139 +                       continue;
22140 +               value = __rlim_get(limit, lim);
22141 +               vxwprintk_xid(value,
22142 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
22143 +                       limit, vlimit_name[lim], lim, (long)value);
22144 +       }
22145 +}
22146 +
22147 diff -NurpP --minimal linux-3.0/kernel/vserver/limit_proc.h linux-3.0-vs2.3.1-pre6/kernel/vserver/limit_proc.h
22148 --- linux-3.0/kernel/vserver/limit_proc.h       1970-01-01 01:00:00.000000000 +0100
22149 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/limit_proc.h  2011-06-10 22:11:24.000000000 +0200
22150 @@ -0,0 +1,57 @@
22151 +#ifndef _VX_LIMIT_PROC_H
22152 +#define _VX_LIMIT_PROC_H
22153 +
22154 +#include <linux/vserver/limit_int.h>
22155 +
22156 +
22157 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22158 +#define VX_LIMIT_TOP   \
22159 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22160 +
22161 +#define VX_LIMIT_ARG(r)                                \
22162 +       (unsigned long)__rlim_get(limit, r),    \
22163 +       (unsigned long)__rlim_rmin(limit, r),   \
22164 +       (unsigned long)__rlim_rmax(limit, r),   \
22165 +       VX_VLIM(__rlim_soft(limit, r)),         \
22166 +       VX_VLIM(__rlim_hard(limit, r)),         \
22167 +       atomic_read(&__rlim_lhit(limit, r))
22168 +
22169 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22170 +{
22171 +       vx_limit_fixup(limit, -1);
22172 +       return sprintf(buffer, VX_LIMIT_TOP
22173 +               "PROC"  VX_LIMIT_FMT
22174 +               "VM"    VX_LIMIT_FMT
22175 +               "VML"   VX_LIMIT_FMT
22176 +               "RSS"   VX_LIMIT_FMT
22177 +               "ANON"  VX_LIMIT_FMT
22178 +               "RMAP"  VX_LIMIT_FMT
22179 +               "FILES" VX_LIMIT_FMT
22180 +               "OFD"   VX_LIMIT_FMT
22181 +               "LOCKS" VX_LIMIT_FMT
22182 +               "SOCK"  VX_LIMIT_FMT
22183 +               "MSGQ"  VX_LIMIT_FMT
22184 +               "SHM"   VX_LIMIT_FMT
22185 +               "SEMA"  VX_LIMIT_FMT
22186 +               "SEMS"  VX_LIMIT_FMT
22187 +               "DENT"  VX_LIMIT_FMT,
22188 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22189 +               VX_LIMIT_ARG(RLIMIT_AS),
22190 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22191 +               VX_LIMIT_ARG(RLIMIT_RSS),
22192 +               VX_LIMIT_ARG(VLIMIT_ANON),
22193 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22194 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22195 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22196 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22197 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22198 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22199 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22200 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22201 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22202 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22203 +}
22204 +
22205 +#endif /* _VX_LIMIT_PROC_H */
22206 +
22207 +
22208 diff -NurpP --minimal linux-3.0/kernel/vserver/network.c linux-3.0-vs2.3.1-pre6/kernel/vserver/network.c
22209 --- linux-3.0/kernel/vserver/network.c  1970-01-01 01:00:00.000000000 +0100
22210 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/network.c     2011-06-10 23:20:56.000000000 +0200
22211 @@ -0,0 +1,912 @@
22212 +/*
22213 + *  linux/kernel/vserver/network.c
22214 + *
22215 + *  Virtual Server: Network Support
22216 + *
22217 + *  Copyright (C) 2003-2007  Herbert Pötzl
22218 + *
22219 + *  V0.01  broken out from vcontext V0.05
22220 + *  V0.02  cleaned up implementation
22221 + *  V0.03  added equiv nx commands
22222 + *  V0.04  switch to RCU based hash
22223 + *  V0.05  and back to locking again
22224 + *  V0.06  changed vcmds to nxi arg
22225 + *  V0.07  have __create claim() the nxi
22226 + *
22227 + */
22228 +
22229 +#include <linux/err.h>
22230 +#include <linux/slab.h>
22231 +#include <linux/rcupdate.h>
22232 +
22233 +#include <linux/vs_network.h>
22234 +#include <linux/vs_pid.h>
22235 +#include <linux/vserver/network_cmd.h>
22236 +
22237 +
22238 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22239 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22240 +
22241 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22242 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22243 +
22244 +
22245 +static int __init init_network(void)
22246 +{
22247 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22248 +               sizeof(struct nx_addr_v4), 0,
22249 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22250 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22251 +               sizeof(struct nx_addr_v6), 0,
22252 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22253 +       return 0;
22254 +}
22255 +
22256 +
22257 +/*     __alloc_nx_addr_v4()                                    */
22258 +
22259 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22260 +{
22261 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22262 +               nx_addr_v4_cachep, GFP_KERNEL);
22263 +
22264 +       if (!IS_ERR(nxa))
22265 +               memset(nxa, 0, sizeof(*nxa));
22266 +       return nxa;
22267 +}
22268 +
22269 +/*     __dealloc_nx_addr_v4()                                  */
22270 +
22271 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22272 +{
22273 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22274 +}
22275 +
22276 +/*     __dealloc_nx_addr_v4_all()                              */
22277 +
22278 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22279 +{
22280 +       while (nxa) {
22281 +               struct nx_addr_v4 *next = nxa->next;
22282 +
22283 +               __dealloc_nx_addr_v4(nxa);
22284 +               nxa = next;
22285 +       }
22286 +}
22287 +
22288 +
22289 +#ifdef CONFIG_IPV6
22290 +
22291 +/*     __alloc_nx_addr_v6()                                    */
22292 +
22293 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22294 +{
22295 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22296 +               nx_addr_v6_cachep, GFP_KERNEL);
22297 +
22298 +       if (!IS_ERR(nxa))
22299 +               memset(nxa, 0, sizeof(*nxa));
22300 +       return nxa;
22301 +}
22302 +
22303 +/*     __dealloc_nx_addr_v6()                                  */
22304 +
22305 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22306 +{
22307 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22308 +}
22309 +
22310 +/*     __dealloc_nx_addr_v6_all()                              */
22311 +
22312 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22313 +{
22314 +       while (nxa) {
22315 +               struct nx_addr_v6 *next = nxa->next;
22316 +
22317 +               __dealloc_nx_addr_v6(nxa);
22318 +               nxa = next;
22319 +       }
22320 +}
22321 +
22322 +#endif /* CONFIG_IPV6 */
22323 +
22324 +/*     __alloc_nx_info()
22325 +
22326 +       * allocate an initialized nx_info struct
22327 +       * doesn't make it visible (hash)                        */
22328 +
22329 +static struct nx_info *__alloc_nx_info(nid_t nid)
22330 +{
22331 +       struct nx_info *new = NULL;
22332 +
22333 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22334 +
22335 +       /* would this benefit from a slab cache? */
22336 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22337 +       if (!new)
22338 +               return 0;
22339 +
22340 +       memset(new, 0, sizeof(struct nx_info));
22341 +       new->nx_id = nid;
22342 +       INIT_HLIST_NODE(&new->nx_hlist);
22343 +       atomic_set(&new->nx_usecnt, 0);
22344 +       atomic_set(&new->nx_tasks, 0);
22345 +       new->nx_state = 0;
22346 +
22347 +       new->nx_flags = NXF_INIT_SET;
22348 +
22349 +       /* rest of init goes here */
22350 +
22351 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22352 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22353 +
22354 +       vxdprintk(VXD_CBIT(nid, 0),
22355 +               "alloc_nx_info(%d) = %p", nid, new);
22356 +       atomic_inc(&nx_global_ctotal);
22357 +       return new;
22358 +}
22359 +
22360 +/*     __dealloc_nx_info()
22361 +
22362 +       * final disposal of nx_info                             */
22363 +
22364 +static void __dealloc_nx_info(struct nx_info *nxi)
22365 +{
22366 +       vxdprintk(VXD_CBIT(nid, 0),
22367 +               "dealloc_nx_info(%p)", nxi);
22368 +
22369 +       nxi->nx_hlist.next = LIST_POISON1;
22370 +       nxi->nx_id = -1;
22371 +
22372 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22373 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22374 +
22375 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22376 +
22377 +       nxi->nx_state |= NXS_RELEASED;
22378 +       kfree(nxi);
22379 +       atomic_dec(&nx_global_ctotal);
22380 +}
22381 +
22382 +static void __shutdown_nx_info(struct nx_info *nxi)
22383 +{
22384 +       nxi->nx_state |= NXS_SHUTDOWN;
22385 +       vs_net_change(nxi, VSC_NETDOWN);
22386 +}
22387 +
22388 +/*     exported stuff                                          */
22389 +
22390 +void free_nx_info(struct nx_info *nxi)
22391 +{
22392 +       /* context shutdown is mandatory */
22393 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22394 +
22395 +       /* context must not be hashed */
22396 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22397 +
22398 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22399 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22400 +
22401 +       __dealloc_nx_info(nxi);
22402 +}
22403 +
22404 +
22405 +void __nx_set_lback(struct nx_info *nxi)
22406 +{
22407 +       int nid = nxi->nx_id;
22408 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22409 +
22410 +       nxi->v4_lback.s_addr = lback;
22411 +}
22412 +
22413 +extern int __nx_inet_add_lback(__be32 addr);
22414 +extern int __nx_inet_del_lback(__be32 addr);
22415 +
22416 +
22417 +/*     hash table for nx_info hash */
22418 +
22419 +#define NX_HASH_SIZE   13
22420 +
22421 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22422 +
22423 +static DEFINE_SPINLOCK(nx_info_hash_lock);
22424 +
22425 +
22426 +static inline unsigned int __hashval(nid_t nid)
22427 +{
22428 +       return (nid % NX_HASH_SIZE);
22429 +}
22430 +
22431 +
22432 +
22433 +/*     __hash_nx_info()
22434 +
22435 +       * add the nxi to the global hash table
22436 +       * requires the hash_lock to be held                     */
22437 +
22438 +static inline void __hash_nx_info(struct nx_info *nxi)
22439 +{
22440 +       struct hlist_head *head;
22441 +
22442 +       vxd_assert_lock(&nx_info_hash_lock);
22443 +       vxdprintk(VXD_CBIT(nid, 4),
22444 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22445 +
22446 +       /* context must not be hashed */
22447 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22448 +
22449 +       nxi->nx_state |= NXS_HASHED;
22450 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22451 +       hlist_add_head(&nxi->nx_hlist, head);
22452 +       atomic_inc(&nx_global_cactive);
22453 +}
22454 +
22455 +/*     __unhash_nx_info()
22456 +
22457 +       * remove the nxi from the global hash table
22458 +       * requires the hash_lock to be held                     */
22459 +
22460 +static inline void __unhash_nx_info(struct nx_info *nxi)
22461 +{
22462 +       vxd_assert_lock(&nx_info_hash_lock);
22463 +       vxdprintk(VXD_CBIT(nid, 4),
22464 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22465 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22466 +
22467 +       /* context must be hashed */
22468 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22469 +       /* but without tasks */
22470 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22471 +
22472 +       nxi->nx_state &= ~NXS_HASHED;
22473 +       hlist_del(&nxi->nx_hlist);
22474 +       atomic_dec(&nx_global_cactive);
22475 +}
22476 +
22477 +
22478 +/*     __lookup_nx_info()
22479 +
22480 +       * requires the hash_lock to be held
22481 +       * doesn't increment the nx_refcnt                       */
22482 +
22483 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22484 +{
22485 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22486 +       struct hlist_node *pos;
22487 +       struct nx_info *nxi;
22488 +
22489 +       vxd_assert_lock(&nx_info_hash_lock);
22490 +       hlist_for_each(pos, head) {
22491 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22492 +
22493 +               if (nxi->nx_id == nid)
22494 +                       goto found;
22495 +       }
22496 +       nxi = NULL;
22497 +found:
22498 +       vxdprintk(VXD_CBIT(nid, 0),
22499 +               "__lookup_nx_info(#%u): %p[#%u]",
22500 +               nid, nxi, nxi ? nxi->nx_id : 0);
22501 +       return nxi;
22502 +}
22503 +
22504 +
22505 +/*     __create_nx_info()
22506 +
22507 +       * create the requested context
22508 +       * get(), claim() and hash it                            */
22509 +
22510 +static struct nx_info *__create_nx_info(int id)
22511 +{
22512 +       struct nx_info *new, *nxi = NULL;
22513 +
22514 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22515 +
22516 +       if (!(new = __alloc_nx_info(id)))
22517 +               return ERR_PTR(-ENOMEM);
22518 +
22519 +       /* required to make dynamic xids unique */
22520 +       spin_lock(&nx_info_hash_lock);
22521 +
22522 +       /* static context requested */
22523 +       if ((nxi = __lookup_nx_info(id))) {
22524 +               vxdprintk(VXD_CBIT(nid, 0),
22525 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22526 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22527 +                       nxi = ERR_PTR(-EBUSY);
22528 +               else
22529 +                       nxi = ERR_PTR(-EEXIST);
22530 +               goto out_unlock;
22531 +       }
22532 +       /* new context */
22533 +       vxdprintk(VXD_CBIT(nid, 0),
22534 +               "create_nx_info(%d) = %p (new)", id, new);
22535 +       claim_nx_info(new, NULL);
22536 +       __nx_set_lback(new);
22537 +       __hash_nx_info(get_nx_info(new));
22538 +       nxi = new, new = NULL;
22539 +
22540 +out_unlock:
22541 +       spin_unlock(&nx_info_hash_lock);
22542 +       if (new)
22543 +               __dealloc_nx_info(new);
22544 +       return nxi;
22545 +}
22546 +
22547 +
22548 +
22549 +/*     exported stuff                                          */
22550 +
22551 +
22552 +void unhash_nx_info(struct nx_info *nxi)
22553 +{
22554 +       __shutdown_nx_info(nxi);
22555 +       spin_lock(&nx_info_hash_lock);
22556 +       __unhash_nx_info(nxi);
22557 +       spin_unlock(&nx_info_hash_lock);
22558 +}
22559 +
22560 +/*     lookup_nx_info()
22561 +
22562 +       * search for a nx_info and get() it
22563 +       * negative id means current                             */
22564 +
22565 +struct nx_info *lookup_nx_info(int id)
22566 +{
22567 +       struct nx_info *nxi = NULL;
22568 +
22569 +       if (id < 0) {
22570 +               nxi = get_nx_info(current_nx_info());
22571 +       } else if (id > 1) {
22572 +               spin_lock(&nx_info_hash_lock);
22573 +               nxi = get_nx_info(__lookup_nx_info(id));
22574 +               spin_unlock(&nx_info_hash_lock);
22575 +       }
22576 +       return nxi;
22577 +}
22578 +
22579 +/*     nid_is_hashed()
22580 +
22581 +       * verify that nid is still hashed                       */
22582 +
22583 +int nid_is_hashed(nid_t nid)
22584 +{
22585 +       int hashed;
22586 +
22587 +       spin_lock(&nx_info_hash_lock);
22588 +       hashed = (__lookup_nx_info(nid) != NULL);
22589 +       spin_unlock(&nx_info_hash_lock);
22590 +       return hashed;
22591 +}
22592 +
22593 +
22594 +#ifdef CONFIG_PROC_FS
22595 +
22596 +/*     get_nid_list()
22597 +
22598 +       * get a subset of hashed nids for proc
22599 +       * assumes size is at least one                          */
22600 +
22601 +int get_nid_list(int index, unsigned int *nids, int size)
22602 +{
22603 +       int hindex, nr_nids = 0;
22604 +
22605 +       /* only show current and children */
22606 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22607 +               if (index > 0)
22608 +                       return 0;
22609 +               nids[nr_nids] = nx_current_nid();
22610 +               return 1;
22611 +       }
22612 +
22613 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22614 +               struct hlist_head *head = &nx_info_hash[hindex];
22615 +               struct hlist_node *pos;
22616 +
22617 +               spin_lock(&nx_info_hash_lock);
22618 +               hlist_for_each(pos, head) {
22619 +                       struct nx_info *nxi;
22620 +
22621 +                       if (--index > 0)
22622 +                               continue;
22623 +
22624 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22625 +                       nids[nr_nids] = nxi->nx_id;
22626 +                       if (++nr_nids >= size) {
22627 +                               spin_unlock(&nx_info_hash_lock);
22628 +                               goto out;
22629 +                       }
22630 +               }
22631 +               /* keep the lock time short */
22632 +               spin_unlock(&nx_info_hash_lock);
22633 +       }
22634 +out:
22635 +       return nr_nids;
22636 +}
22637 +#endif
22638 +
22639 +
22640 +/*
22641 + *     migrate task to new network
22642 + *     gets nxi, puts old_nxi on change
22643 + */
22644 +
22645 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22646 +{
22647 +       struct nx_info *old_nxi;
22648 +       int ret = 0;
22649 +
22650 +       if (!p || !nxi)
22651 +               BUG();
22652 +
22653 +       vxdprintk(VXD_CBIT(nid, 5),
22654 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22655 +               p, nxi, nxi->nx_id,
22656 +               atomic_read(&nxi->nx_usecnt),
22657 +               atomic_read(&nxi->nx_tasks));
22658 +
22659 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22660 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22661 +               return -EACCES;
22662 +
22663 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22664 +               return -EFAULT;
22665 +
22666 +       /* maybe disallow this completely? */
22667 +       old_nxi = task_get_nx_info(p);
22668 +       if (old_nxi == nxi)
22669 +               goto out;
22670 +
22671 +       task_lock(p);
22672 +       if (old_nxi)
22673 +               clr_nx_info(&p->nx_info);
22674 +       claim_nx_info(nxi, p);
22675 +       set_nx_info(&p->nx_info, nxi);
22676 +       p->nid = nxi->nx_id;
22677 +       task_unlock(p);
22678 +
22679 +       vxdprintk(VXD_CBIT(nid, 5),
22680 +               "moved task %p into nxi:%p[#%d]",
22681 +               p, nxi, nxi->nx_id);
22682 +
22683 +       if (old_nxi)
22684 +               release_nx_info(old_nxi, p);
22685 +       ret = 0;
22686 +out:
22687 +       put_nx_info(old_nxi);
22688 +       return ret;
22689 +}
22690 +
22691 +
22692 +void nx_set_persistent(struct nx_info *nxi)
22693 +{
22694 +       vxdprintk(VXD_CBIT(nid, 6),
22695 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22696 +
22697 +       get_nx_info(nxi);
22698 +       claim_nx_info(nxi, NULL);
22699 +}
22700 +
22701 +void nx_clear_persistent(struct nx_info *nxi)
22702 +{
22703 +       vxdprintk(VXD_CBIT(nid, 6),
22704 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22705 +
22706 +       release_nx_info(nxi, NULL);
22707 +       put_nx_info(nxi);
22708 +}
22709 +
22710 +void nx_update_persistent(struct nx_info *nxi)
22711 +{
22712 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22713 +               nx_set_persistent(nxi);
22714 +       else
22715 +               nx_clear_persistent(nxi);
22716 +}
22717 +
22718 +/* vserver syscall commands below here */
22719 +
22720 +/* taks nid and nx_info functions */
22721 +
22722 +#include <asm/uaccess.h>
22723 +
22724 +
22725 +int vc_task_nid(uint32_t id)
22726 +{
22727 +       nid_t nid;
22728 +
22729 +       if (id) {
22730 +               struct task_struct *tsk;
22731 +
22732 +               rcu_read_lock();
22733 +               tsk = find_task_by_real_pid(id);
22734 +               nid = (tsk) ? tsk->nid : -ESRCH;
22735 +               rcu_read_unlock();
22736 +       } else
22737 +               nid = nx_current_nid();
22738 +       return nid;
22739 +}
22740 +
22741 +
22742 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22743 +{
22744 +       struct vcmd_nx_info_v0 vc_data;
22745 +
22746 +       vc_data.nid = nxi->nx_id;
22747 +
22748 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22749 +               return -EFAULT;
22750 +       return 0;
22751 +}
22752 +
22753 +
22754 +/* network functions */
22755 +
22756 +int vc_net_create(uint32_t nid, void __user *data)
22757 +{
22758 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22759 +       struct nx_info *new_nxi;
22760 +       int ret;
22761 +
22762 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22763 +               return -EFAULT;
22764 +
22765 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22766 +               return -EINVAL;
22767 +
22768 +       new_nxi = __create_nx_info(nid);
22769 +       if (IS_ERR(new_nxi))
22770 +               return PTR_ERR(new_nxi);
22771 +
22772 +       /* initial flags */
22773 +       new_nxi->nx_flags = vc_data.flagword;
22774 +
22775 +       ret = -ENOEXEC;
22776 +       if (vs_net_change(new_nxi, VSC_NETUP))
22777 +               goto out;
22778 +
22779 +       ret = nx_migrate_task(current, new_nxi);
22780 +       if (ret)
22781 +               goto out;
22782 +
22783 +       /* return context id on success */
22784 +       ret = new_nxi->nx_id;
22785 +
22786 +       /* get a reference for persistent contexts */
22787 +       if ((vc_data.flagword & NXF_PERSISTENT))
22788 +               nx_set_persistent(new_nxi);
22789 +out:
22790 +       release_nx_info(new_nxi, NULL);
22791 +       put_nx_info(new_nxi);
22792 +       return ret;
22793 +}
22794 +
22795 +
22796 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22797 +{
22798 +       return nx_migrate_task(current, nxi);
22799 +}
22800 +
22801 +
22802 +
22803 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22804 +       uint16_t type, uint16_t flags)
22805 +{
22806 +       struct nx_addr_v4 *nxa = &nxi->v4;
22807 +
22808 +       if (NX_IPV4(nxi)) {
22809 +               /* locate last entry */
22810 +               for (; nxa->next; nxa = nxa->next);
22811 +               nxa->next = __alloc_nx_addr_v4();
22812 +               nxa = nxa->next;
22813 +
22814 +               if (IS_ERR(nxa))
22815 +                       return PTR_ERR(nxa);
22816 +       }
22817 +
22818 +       if (nxi->v4.next)
22819 +               /* remove single ip for ip list */
22820 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22821 +
22822 +       nxa->ip[0].s_addr = ip;
22823 +       nxa->ip[1].s_addr = ip2;
22824 +       nxa->mask.s_addr = mask;
22825 +       nxa->type = type;
22826 +       nxa->flags = flags;
22827 +       return 0;
22828 +}
22829 +
22830 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22831 +       uint16_t type, uint16_t flags)
22832 +{
22833 +       struct nx_addr_v4 *nxa = &nxi->v4;
22834 +
22835 +       switch (type) {
22836 +/*     case NXA_TYPE_ADDR:
22837 +               break;          */
22838 +
22839 +       case NXA_TYPE_ANY:
22840 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
22841 +               memset(nxa, 0, sizeof(*nxa));
22842 +               break;
22843 +
22844 +       default:
22845 +               return -EINVAL;
22846 +       }
22847 +       return 0;
22848 +}
22849 +
22850 +
22851 +int vc_net_add(struct nx_info *nxi, void __user *data)
22852 +{
22853 +       struct vcmd_net_addr_v0 vc_data;
22854 +       int index, ret = 0;
22855 +
22856 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22857 +               return -EFAULT;
22858 +
22859 +       switch (vc_data.type) {
22860 +       case NXA_TYPE_IPV4:
22861 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22862 +                       return -EINVAL;
22863 +
22864 +               index = 0;
22865 +               while (index < vc_data.count) {
22866 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22867 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22868 +                       if (ret)
22869 +                               return ret;
22870 +                       index++;
22871 +               }
22872 +               ret = index;
22873 +               break;
22874 +
22875 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22876 +               nxi->v4_bcast = vc_data.ip[0];
22877 +               ret = 1;
22878 +               break;
22879 +
22880 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22881 +               nxi->v4_lback = vc_data.ip[0];
22882 +               ret = 1;
22883 +               break;
22884 +
22885 +       default:
22886 +               ret = -EINVAL;
22887 +               break;
22888 +       }
22889 +       return ret;
22890 +}
22891 +
22892 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22893 +{
22894 +       struct vcmd_net_addr_v0 vc_data;
22895 +
22896 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22897 +               return -EFAULT;
22898 +
22899 +       switch (vc_data.type) {
22900 +       case NXA_TYPE_ANY:
22901 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22902 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22903 +               break;
22904 +
22905 +       default:
22906 +               return -EINVAL;
22907 +       }
22908 +       return 0;
22909 +}
22910 +
22911 +
22912 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
22913 +{
22914 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22915 +
22916 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22917 +               return -EFAULT;
22918 +
22919 +       switch (vc_data.type) {
22920 +       case NXA_TYPE_ADDR:
22921 +       case NXA_TYPE_MASK:
22922 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22923 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22924 +
22925 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22926 +               nxi->v4_bcast = vc_data.ip;
22927 +               break;
22928 +
22929 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22930 +               nxi->v4_lback = vc_data.ip;
22931 +               break;
22932 +
22933 +       default:
22934 +               return -EINVAL;
22935 +       }
22936 +       return 0;
22937 +}
22938 +
22939 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22940 +{
22941 +       struct vcmd_net_addr_ipv4_v2 vc_data;
22942 +
22943 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22944 +               return -EFAULT;
22945 +
22946 +       switch (vc_data.type) {
22947 +       case NXA_TYPE_ADDR:
22948 +       case NXA_TYPE_MASK:
22949 +       case NXA_TYPE_RANGE:
22950 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
22951 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22952 +
22953 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22954 +               nxi->v4_bcast = vc_data.ip;
22955 +               break;
22956 +
22957 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22958 +               nxi->v4_lback = vc_data.ip;
22959 +               break;
22960 +
22961 +       default:
22962 +               return -EINVAL;
22963 +       }
22964 +       return 0;
22965 +}
22966 +
22967 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
22968 +{
22969 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22970 +
22971 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22972 +               return -EFAULT;
22973 +
22974 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
22975 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22976 +}
22977 +
22978 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
22979 +{
22980 +       struct vcmd_net_addr_ipv4_v2 vc_data;
22981 +
22982 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22983 +               return -EFAULT;
22984 +
22985 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
22986 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22987 +}
22988 +
22989 +#ifdef CONFIG_IPV6
22990 +
22991 +int do_add_v6_addr(struct nx_info *nxi,
22992 +       struct in6_addr *ip, struct in6_addr *mask,
22993 +       uint32_t prefix, uint16_t type, uint16_t flags)
22994 +{
22995 +       struct nx_addr_v6 *nxa = &nxi->v6;
22996 +
22997 +       if (NX_IPV6(nxi)) {
22998 +               /* locate last entry */
22999 +               for (; nxa->next; nxa = nxa->next);
23000 +               nxa->next = __alloc_nx_addr_v6();
23001 +               nxa = nxa->next;
23002 +
23003 +               if (IS_ERR(nxa))
23004 +                       return PTR_ERR(nxa);
23005 +       }
23006 +
23007 +       nxa->ip = *ip;
23008 +       nxa->mask = *mask;
23009 +       nxa->prefix = prefix;
23010 +       nxa->type = type;
23011 +       nxa->flags = flags;
23012 +       return 0;
23013 +}
23014 +
23015 +
23016 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
23017 +{
23018 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23019 +
23020 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23021 +               return -EFAULT;
23022 +
23023 +       switch (vc_data.type) {
23024 +       case NXA_TYPE_ADDR:
23025 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
23026 +               /* fallthrough */
23027 +       case NXA_TYPE_MASK:
23028 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
23029 +                       vc_data.prefix, vc_data.type, vc_data.flags);
23030 +       default:
23031 +               return -EINVAL;
23032 +       }
23033 +       return 0;
23034 +}
23035 +
23036 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
23037 +{
23038 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23039 +
23040 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23041 +               return -EFAULT;
23042 +
23043 +       switch (vc_data.type) {
23044 +       case NXA_TYPE_ANY:
23045 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
23046 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
23047 +               break;
23048 +
23049 +       default:
23050 +               return -EINVAL;
23051 +       }
23052 +       return 0;
23053 +}
23054 +
23055 +#endif /* CONFIG_IPV6 */
23056 +
23057 +
23058 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23059 +{
23060 +       struct vcmd_net_flags_v0 vc_data;
23061 +
23062 +       vc_data.flagword = nxi->nx_flags;
23063 +
23064 +       /* special STATE flag handling */
23065 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23066 +
23067 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23068 +               return -EFAULT;
23069 +       return 0;
23070 +}
23071 +
23072 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23073 +{
23074 +       struct vcmd_net_flags_v0 vc_data;
23075 +       uint64_t mask, trigger;
23076 +
23077 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23078 +               return -EFAULT;
23079 +
23080 +       /* special STATE flag handling */
23081 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23082 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23083 +
23084 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23085 +               vc_data.flagword, mask);
23086 +       if (trigger & NXF_PERSISTENT)
23087 +               nx_update_persistent(nxi);
23088 +
23089 +       return 0;
23090 +}
23091 +
23092 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23093 +{
23094 +       struct vcmd_net_caps_v0 vc_data;
23095 +
23096 +       vc_data.ncaps = nxi->nx_ncaps;
23097 +       vc_data.cmask = ~0ULL;
23098 +
23099 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23100 +               return -EFAULT;
23101 +       return 0;
23102 +}
23103 +
23104 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23105 +{
23106 +       struct vcmd_net_caps_v0 vc_data;
23107 +
23108 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23109 +               return -EFAULT;
23110 +
23111 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23112 +               vc_data.ncaps, vc_data.cmask);
23113 +       return 0;
23114 +}
23115 +
23116 +
23117 +#include <linux/module.h>
23118 +
23119 +module_init(init_network);
23120 +
23121 +EXPORT_SYMBOL_GPL(free_nx_info);
23122 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23123 +
23124 diff -NurpP --minimal linux-3.0/kernel/vserver/proc.c linux-3.0-vs2.3.1-pre6/kernel/vserver/proc.c
23125 --- linux-3.0/kernel/vserver/proc.c     1970-01-01 01:00:00.000000000 +0100
23126 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/proc.c        2011-06-10 22:11:24.000000000 +0200
23127 @@ -0,0 +1,1100 @@
23128 +/*
23129 + *  linux/kernel/vserver/proc.c
23130 + *
23131 + *  Virtual Context Support
23132 + *
23133 + *  Copyright (C) 2003-2007  Herbert Pötzl
23134 + *
23135 + *  V0.01  basic structure
23136 + *  V0.02  adaptation vs1.3.0
23137 + *  V0.03  proc permissions
23138 + *  V0.04  locking/generic
23139 + *  V0.05  next generation procfs
23140 + *  V0.06  inode validation
23141 + *  V0.07  generic rewrite vid
23142 + *  V0.08  remove inode type
23143 + *
23144 + */
23145 +
23146 +#include <linux/proc_fs.h>
23147 +#include <linux/fs_struct.h>
23148 +#include <linux/mount.h>
23149 +#include <asm/unistd.h>
23150 +
23151 +#include <linux/vs_context.h>
23152 +#include <linux/vs_network.h>
23153 +#include <linux/vs_cvirt.h>
23154 +
23155 +#include <linux/in.h>
23156 +#include <linux/inetdevice.h>
23157 +#include <linux/vs_inet.h>
23158 +#include <linux/vs_inet6.h>
23159 +
23160 +#include <linux/vserver/global.h>
23161 +
23162 +#include "cvirt_proc.h"
23163 +#include "cacct_proc.h"
23164 +#include "limit_proc.h"
23165 +#include "sched_proc.h"
23166 +#include "vci_config.h"
23167 +
23168 +
23169 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
23170 +{
23171 +       unsigned __capi;
23172 +
23173 +       CAP_FOR_EACH_U32(__capi) {
23174 +               buffer += sprintf(buffer, "%08x",
23175 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
23176 +       }
23177 +       return buffer;
23178 +}
23179 +
23180 +
23181 +static struct proc_dir_entry *proc_virtual;
23182 +
23183 +static struct proc_dir_entry *proc_virtnet;
23184 +
23185 +
23186 +/* first the actual feeds */
23187 +
23188 +
23189 +static int proc_vci(char *buffer)
23190 +{
23191 +       return sprintf(buffer,
23192 +               "VCIVersion:\t%04x:%04x\n"
23193 +               "VCISyscall:\t%d\n"
23194 +               "VCIKernel:\t%08x\n",
23195 +               VCI_VERSION >> 16,
23196 +               VCI_VERSION & 0xFFFF,
23197 +               __NR_vserver,
23198 +               vci_kernel_config());
23199 +}
23200 +
23201 +static int proc_virtual_info(char *buffer)
23202 +{
23203 +       return proc_vci(buffer);
23204 +}
23205 +
23206 +static int proc_virtual_status(char *buffer)
23207 +{
23208 +       return sprintf(buffer,
23209 +               "#CTotal:\t%d\n"
23210 +               "#CActive:\t%d\n"
23211 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
23212 +               "#InitTask:\t%d\t%d %d\n",
23213 +               atomic_read(&vx_global_ctotal),
23214 +               atomic_read(&vx_global_cactive),
23215 +               atomic_read(&vs_global_nsproxy),
23216 +               atomic_read(&vs_global_fs),
23217 +               atomic_read(&vs_global_mnt_ns),
23218 +               atomic_read(&vs_global_uts_ns),
23219 +               atomic_read(&nr_ipc_ns),
23220 +               atomic_read(&vs_global_user_ns),
23221 +               atomic_read(&vs_global_pid_ns),
23222 +               atomic_read(&init_task.usage),
23223 +               atomic_read(&init_task.nsproxy->count),
23224 +               init_task.fs->users);
23225 +}
23226 +
23227 +
23228 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23229 +{
23230 +       int length;
23231 +
23232 +       length = sprintf(buffer,
23233 +               "ID:\t%d\n"
23234 +               "Info:\t%p\n"
23235 +               "Init:\t%d\n"
23236 +               "OOM:\t%lld\n",
23237 +               vxi->vx_id,
23238 +               vxi,
23239 +               vxi->vx_initpid,
23240 +               vxi->vx_badness_bias);
23241 +       return length;
23242 +}
23243 +
23244 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23245 +{
23246 +       char *orig = buffer;
23247 +
23248 +       buffer += sprintf(buffer,
23249 +               "UseCnt:\t%d\n"
23250 +               "Tasks:\t%d\n"
23251 +               "Flags:\t%016llx\n",
23252 +               atomic_read(&vxi->vx_usecnt),
23253 +               atomic_read(&vxi->vx_tasks),
23254 +               (unsigned long long)vxi->vx_flags);
23255 +
23256 +       buffer += sprintf(buffer, "BCaps:\t");
23257 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23258 +       buffer += sprintf(buffer, "\n");
23259 +
23260 +       buffer += sprintf(buffer,
23261 +               "CCaps:\t%016llx\n"
23262 +               "Umask:\t%16llx\n"
23263 +               "Spaces:\t%08lx %08lx\n",
23264 +               (unsigned long long)vxi->vx_ccaps,
23265 +               (unsigned long long)vxi->vx_umask,
23266 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
23267 +       return buffer - orig;
23268 +}
23269 +
23270 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23271 +{
23272 +       return vx_info_proc_limit(&vxi->limit, buffer);
23273 +}
23274 +
23275 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23276 +{
23277 +       int cpu, length;
23278 +
23279 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23280 +       for_each_online_cpu(cpu) {
23281 +               length += vx_info_proc_sched_pc(
23282 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23283 +                       buffer + length, cpu);
23284 +       }
23285 +       return length;
23286 +}
23287 +
23288 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23289 +{
23290 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
23291 +}
23292 +
23293 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23294 +{
23295 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
23296 +}
23297 +
23298 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23299 +{
23300 +       int cpu, length;
23301 +
23302 +       vx_update_load(vxi);
23303 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23304 +       for_each_online_cpu(cpu) {
23305 +               length += vx_info_proc_cvirt_pc(
23306 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23307 +                       buffer + length, cpu);
23308 +       }
23309 +       return length;
23310 +}
23311 +
23312 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23313 +{
23314 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23315 +}
23316 +
23317 +
23318 +static int proc_virtnet_info(char *buffer)
23319 +{
23320 +       return proc_vci(buffer);
23321 +}
23322 +
23323 +static int proc_virtnet_status(char *buffer)
23324 +{
23325 +       return sprintf(buffer,
23326 +               "#CTotal:\t%d\n"
23327 +               "#CActive:\t%d\n",
23328 +               atomic_read(&nx_global_ctotal),
23329 +               atomic_read(&nx_global_cactive));
23330 +}
23331 +
23332 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23333 +{
23334 +       struct nx_addr_v4 *v4a;
23335 +#ifdef CONFIG_IPV6
23336 +       struct nx_addr_v6 *v6a;
23337 +#endif
23338 +       int length, i;
23339 +
23340 +       length = sprintf(buffer,
23341 +               "ID:\t%d\n"
23342 +               "Info:\t%p\n"
23343 +               "Bcast:\t" NIPQUAD_FMT "\n"
23344 +               "Lback:\t" NIPQUAD_FMT "\n",
23345 +               nxi->nx_id,
23346 +               nxi,
23347 +               NIPQUAD(nxi->v4_bcast.s_addr),
23348 +               NIPQUAD(nxi->v4_lback.s_addr));
23349 +
23350 +       if (!NX_IPV4(nxi))
23351 +               goto skip_v4;
23352 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23353 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23354 +                       i, NXAV4(v4a));
23355 +skip_v4:
23356 +#ifdef CONFIG_IPV6
23357 +       if (!NX_IPV6(nxi))
23358 +               goto skip_v6;
23359 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23360 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23361 +                       i, NXAV6(v6a));
23362 +skip_v6:
23363 +#endif
23364 +       return length;
23365 +}
23366 +
23367 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23368 +{
23369 +       int length;
23370 +
23371 +       length = sprintf(buffer,
23372 +               "UseCnt:\t%d\n"
23373 +               "Tasks:\t%d\n"
23374 +               "Flags:\t%016llx\n"
23375 +               "NCaps:\t%016llx\n",
23376 +               atomic_read(&nxi->nx_usecnt),
23377 +               atomic_read(&nxi->nx_tasks),
23378 +               (unsigned long long)nxi->nx_flags,
23379 +               (unsigned long long)nxi->nx_ncaps);
23380 +       return length;
23381 +}
23382 +
23383 +
23384 +
23385 +/* here the inode helpers */
23386 +
23387 +struct vs_entry {
23388 +       int len;
23389 +       char *name;
23390 +       mode_t mode;
23391 +       struct inode_operations *iop;
23392 +       struct file_operations *fop;
23393 +       union proc_op op;
23394 +};
23395 +
23396 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23397 +{
23398 +       struct inode *inode = new_inode(sb);
23399 +
23400 +       if (!inode)
23401 +               goto out;
23402 +
23403 +       inode->i_mode = p->mode;
23404 +       if (p->iop)
23405 +               inode->i_op = p->iop;
23406 +       if (p->fop)
23407 +               inode->i_fop = p->fop;
23408 +
23409 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23410 +       inode->i_flags |= S_IMMUTABLE;
23411 +
23412 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23413 +
23414 +       inode->i_uid = 0;
23415 +       inode->i_gid = 0;
23416 +       inode->i_tag = 0;
23417 +out:
23418 +       return inode;
23419 +}
23420 +
23421 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23422 +       struct dentry *dentry, int id, void *ptr)
23423 +{
23424 +       struct vs_entry *p = ptr;
23425 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23426 +       struct dentry *error = ERR_PTR(-EINVAL);
23427 +
23428 +       if (!inode)
23429 +               goto out;
23430 +
23431 +       PROC_I(inode)->op = p->op;
23432 +       PROC_I(inode)->fd = id;
23433 +       d_add(dentry, inode);
23434 +       error = NULL;
23435 +out:
23436 +       return error;
23437 +}
23438 +
23439 +/* Lookups */
23440 +
23441 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23442 +
23443 +/*
23444 + * Fill a directory entry.
23445 + *
23446 + * If possible create the dcache entry and derive our inode number and
23447 + * file type from dcache entry.
23448 + *
23449 + * Since all of the proc inode numbers are dynamically generated, the inode
23450 + * numbers do not exist until the inode is cache.  This means creating the
23451 + * the dcache entry in readdir is necessary to keep the inode numbers
23452 + * reported by readdir in sync with the inode numbers reported
23453 + * by stat.
23454 + */
23455 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23456 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23457 +{
23458 +       struct dentry *child, *dir = filp->f_dentry;
23459 +       struct inode *inode;
23460 +       struct qstr qname;
23461 +       ino_t ino = 0;
23462 +       unsigned type = DT_UNKNOWN;
23463 +
23464 +       qname.name = name;
23465 +       qname.len  = len;
23466 +       qname.hash = full_name_hash(name, len);
23467 +
23468 +       child = d_lookup(dir, &qname);
23469 +       if (!child) {
23470 +               struct dentry *new;
23471 +               new = d_alloc(dir, &qname);
23472 +               if (new) {
23473 +                       child = instantiate(dir->d_inode, new, id, ptr);
23474 +                       if (child)
23475 +                               dput(new);
23476 +                       else
23477 +                               child = new;
23478 +               }
23479 +       }
23480 +       if (!child || IS_ERR(child) || !child->d_inode)
23481 +               goto end_instantiate;
23482 +       inode = child->d_inode;
23483 +       if (inode) {
23484 +               ino = inode->i_ino;
23485 +               type = inode->i_mode >> 12;
23486 +       }
23487 +       dput(child);
23488 +end_instantiate:
23489 +       if (!ino)
23490 +               ino = find_inode_number(dir, &qname);
23491 +       if (!ino)
23492 +               ino = 1;
23493 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23494 +}
23495 +
23496 +
23497 +
23498 +/* get and revalidate vx_info/xid */
23499 +
23500 +static inline
23501 +struct vx_info *get_proc_vx_info(struct inode *inode)
23502 +{
23503 +       return lookup_vx_info(PROC_I(inode)->fd);
23504 +}
23505 +
23506 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23507 +{
23508 +       struct inode *inode = dentry->d_inode;
23509 +       xid_t xid = PROC_I(inode)->fd;
23510 +
23511 +       if (!xid || xid_is_hashed(xid))
23512 +               return 1;
23513 +       d_drop(dentry);
23514 +       return 0;
23515 +}
23516 +
23517 +
23518 +/* get and revalidate nx_info/nid */
23519 +
23520 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23521 +{
23522 +       struct inode *inode = dentry->d_inode;
23523 +       nid_t nid = PROC_I(inode)->fd;
23524 +
23525 +       if (!nid || nid_is_hashed(nid))
23526 +               return 1;
23527 +       d_drop(dentry);
23528 +       return 0;
23529 +}
23530 +
23531 +
23532 +
23533 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23534 +
23535 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23536 +                         size_t count, loff_t *ppos)
23537 +{
23538 +       struct inode *inode = file->f_dentry->d_inode;
23539 +       unsigned long page;
23540 +       ssize_t length = 0;
23541 +
23542 +       if (count > PROC_BLOCK_SIZE)
23543 +               count = PROC_BLOCK_SIZE;
23544 +
23545 +       /* fade that out as soon as stable */
23546 +       WARN_ON(PROC_I(inode)->fd);
23547 +
23548 +       if (!(page = __get_free_page(GFP_KERNEL)))
23549 +               return -ENOMEM;
23550 +
23551 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23552 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23553 +
23554 +       if (length >= 0)
23555 +               length = simple_read_from_buffer(buf, count, ppos,
23556 +                       (char *)page, length);
23557 +
23558 +       free_page(page);
23559 +       return length;
23560 +}
23561 +
23562 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23563 +                         size_t count, loff_t *ppos)
23564 +{
23565 +       struct inode *inode = file->f_dentry->d_inode;
23566 +       struct vx_info *vxi = NULL;
23567 +       xid_t xid = PROC_I(inode)->fd;
23568 +       unsigned long page;
23569 +       ssize_t length = 0;
23570 +
23571 +       if (count > PROC_BLOCK_SIZE)
23572 +               count = PROC_BLOCK_SIZE;
23573 +
23574 +       /* fade that out as soon as stable */
23575 +       WARN_ON(!xid);
23576 +       vxi = lookup_vx_info(xid);
23577 +       if (!vxi)
23578 +               goto out;
23579 +
23580 +       length = -ENOMEM;
23581 +       if (!(page = __get_free_page(GFP_KERNEL)))
23582 +               goto out_put;
23583 +
23584 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23585 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23586 +
23587 +       if (length >= 0)
23588 +               length = simple_read_from_buffer(buf, count, ppos,
23589 +                       (char *)page, length);
23590 +
23591 +       free_page(page);
23592 +out_put:
23593 +       put_vx_info(vxi);
23594 +out:
23595 +       return length;
23596 +}
23597 +
23598 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23599 +                         size_t count, loff_t *ppos)
23600 +{
23601 +       struct inode *inode = file->f_dentry->d_inode;
23602 +       struct nx_info *nxi = NULL;
23603 +       nid_t nid = PROC_I(inode)->fd;
23604 +       unsigned long page;
23605 +       ssize_t length = 0;
23606 +
23607 +       if (count > PROC_BLOCK_SIZE)
23608 +               count = PROC_BLOCK_SIZE;
23609 +
23610 +       /* fade that out as soon as stable */
23611 +       WARN_ON(!nid);
23612 +       nxi = lookup_nx_info(nid);
23613 +       if (!nxi)
23614 +               goto out;
23615 +
23616 +       length = -ENOMEM;
23617 +       if (!(page = __get_free_page(GFP_KERNEL)))
23618 +               goto out_put;
23619 +
23620 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23621 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23622 +
23623 +       if (length >= 0)
23624 +               length = simple_read_from_buffer(buf, count, ppos,
23625 +                       (char *)page, length);
23626 +
23627 +       free_page(page);
23628 +out_put:
23629 +       put_nx_info(nxi);
23630 +out:
23631 +       return length;
23632 +}
23633 +
23634 +
23635 +
23636 +/* here comes the lower level */
23637 +
23638 +
23639 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23640 +       .len  = sizeof(NAME) - 1,       \
23641 +       .name = (NAME),                 \
23642 +       .mode = MODE,                   \
23643 +       .iop  = IOP,                    \
23644 +       .fop  = FOP,                    \
23645 +       .op   = OP,                     \
23646 +}
23647 +
23648 +
23649 +#define DIR(NAME, MODE, OTYPE)                         \
23650 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23651 +               &proc_ ## OTYPE ## _inode_operations,   \
23652 +               &proc_ ## OTYPE ## _file_operations, { } )
23653 +
23654 +#define INF(NAME, MODE, OTYPE)                         \
23655 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23656 +               &proc_vs_info_file_operations,          \
23657 +               { .proc_vs_read = &proc_##OTYPE } )
23658 +
23659 +#define VINF(NAME, MODE, OTYPE)                                \
23660 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23661 +               &proc_vx_info_file_operations,          \
23662 +               { .proc_vxi_read = &proc_##OTYPE } )
23663 +
23664 +#define NINF(NAME, MODE, OTYPE)                                \
23665 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23666 +               &proc_nx_info_file_operations,          \
23667 +               { .proc_nxi_read = &proc_##OTYPE } )
23668 +
23669 +
23670 +static struct file_operations proc_vs_info_file_operations = {
23671 +       .read =         proc_vs_info_read,
23672 +};
23673 +
23674 +static struct file_operations proc_vx_info_file_operations = {
23675 +       .read =         proc_vx_info_read,
23676 +};
23677 +
23678 +static struct dentry_operations proc_xid_dentry_operations = {
23679 +       .d_revalidate = proc_xid_revalidate,
23680 +};
23681 +
23682 +static struct vs_entry vx_base_stuff[] = {
23683 +       VINF("info",    S_IRUGO, vxi_info),
23684 +       VINF("status",  S_IRUGO, vxi_status),
23685 +       VINF("limit",   S_IRUGO, vxi_limit),
23686 +       VINF("sched",   S_IRUGO, vxi_sched),
23687 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23688 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23689 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23690 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23691 +       {}
23692 +};
23693 +
23694 +
23695 +
23696 +
23697 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23698 +       struct dentry *dentry, int id, void *ptr)
23699 +{
23700 +       dentry->d_op = &proc_xid_dentry_operations;
23701 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23702 +}
23703 +
23704 +static struct dentry *proc_xid_lookup(struct inode *dir,
23705 +       struct dentry *dentry, struct nameidata *nd)
23706 +{
23707 +       struct vs_entry *p = vx_base_stuff;
23708 +       struct dentry *error = ERR_PTR(-ENOENT);
23709 +
23710 +       for (; p->name; p++) {
23711 +               if (p->len != dentry->d_name.len)
23712 +                       continue;
23713 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23714 +                       break;
23715 +       }
23716 +       if (!p->name)
23717 +               goto out;
23718 +
23719 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23720 +out:
23721 +       return error;
23722 +}
23723 +
23724 +static int proc_xid_readdir(struct file *filp,
23725 +       void *dirent, filldir_t filldir)
23726 +{
23727 +       struct dentry *dentry = filp->f_dentry;
23728 +       struct inode *inode = dentry->d_inode;
23729 +       struct vs_entry *p = vx_base_stuff;
23730 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23731 +       int pos, index;
23732 +       u64 ino;
23733 +
23734 +       pos = filp->f_pos;
23735 +       switch (pos) {
23736 +       case 0:
23737 +               ino = inode->i_ino;
23738 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23739 +                       goto out;
23740 +               pos++;
23741 +               /* fall through */
23742 +       case 1:
23743 +               ino = parent_ino(dentry);
23744 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23745 +                       goto out;
23746 +               pos++;
23747 +               /* fall through */
23748 +       default:
23749 +               index = pos - 2;
23750 +               if (index >= size)
23751 +                       goto out;
23752 +               for (p += index; p->name; p++) {
23753 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23754 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23755 +                               goto out;
23756 +                       pos++;
23757 +               }
23758 +       }
23759 +out:
23760 +       filp->f_pos = pos;
23761 +       return 1;
23762 +}
23763 +
23764 +
23765 +
23766 +static struct file_operations proc_nx_info_file_operations = {
23767 +       .read =         proc_nx_info_read,
23768 +};
23769 +
23770 +static struct dentry_operations proc_nid_dentry_operations = {
23771 +       .d_revalidate = proc_nid_revalidate,
23772 +};
23773 +
23774 +static struct vs_entry nx_base_stuff[] = {
23775 +       NINF("info",    S_IRUGO, nxi_info),
23776 +       NINF("status",  S_IRUGO, nxi_status),
23777 +       {}
23778 +};
23779 +
23780 +
23781 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23782 +       struct dentry *dentry, int id, void *ptr)
23783 +{
23784 +       dentry->d_op = &proc_nid_dentry_operations;
23785 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23786 +}
23787 +
23788 +static struct dentry *proc_nid_lookup(struct inode *dir,
23789 +       struct dentry *dentry, struct nameidata *nd)
23790 +{
23791 +       struct vs_entry *p = nx_base_stuff;
23792 +       struct dentry *error = ERR_PTR(-ENOENT);
23793 +
23794 +       for (; p->name; p++) {
23795 +               if (p->len != dentry->d_name.len)
23796 +                       continue;
23797 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23798 +                       break;
23799 +       }
23800 +       if (!p->name)
23801 +               goto out;
23802 +
23803 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23804 +out:
23805 +       return error;
23806 +}
23807 +
23808 +static int proc_nid_readdir(struct file *filp,
23809 +       void *dirent, filldir_t filldir)
23810 +{
23811 +       struct dentry *dentry = filp->f_dentry;
23812 +       struct inode *inode = dentry->d_inode;
23813 +       struct vs_entry *p = nx_base_stuff;
23814 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23815 +       int pos, index;
23816 +       u64 ino;
23817 +
23818 +       pos = filp->f_pos;
23819 +       switch (pos) {
23820 +       case 0:
23821 +               ino = inode->i_ino;
23822 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23823 +                       goto out;
23824 +               pos++;
23825 +               /* fall through */
23826 +       case 1:
23827 +               ino = parent_ino(dentry);
23828 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23829 +                       goto out;
23830 +               pos++;
23831 +               /* fall through */
23832 +       default:
23833 +               index = pos - 2;
23834 +               if (index >= size)
23835 +                       goto out;
23836 +               for (p += index; p->name; p++) {
23837 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23838 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23839 +                               goto out;
23840 +                       pos++;
23841 +               }
23842 +       }
23843 +out:
23844 +       filp->f_pos = pos;
23845 +       return 1;
23846 +}
23847 +
23848 +
23849 +#define MAX_MULBY10    ((~0U - 9) / 10)
23850 +
23851 +static inline int atovid(const char *str, int len)
23852 +{
23853 +       int vid, c;
23854 +
23855 +       vid = 0;
23856 +       while (len-- > 0) {
23857 +               c = *str - '0';
23858 +               str++;
23859 +               if (c > 9)
23860 +                       return -1;
23861 +               if (vid >= MAX_MULBY10)
23862 +                       return -1;
23863 +               vid *= 10;
23864 +               vid += c;
23865 +               if (!vid)
23866 +                       return -1;
23867 +       }
23868 +       return vid;
23869 +}
23870 +
23871 +/* now the upper level (virtual) */
23872 +
23873 +
23874 +static struct file_operations proc_xid_file_operations = {
23875 +       .read =         generic_read_dir,
23876 +       .readdir =      proc_xid_readdir,
23877 +};
23878 +
23879 +static struct inode_operations proc_xid_inode_operations = {
23880 +       .lookup =       proc_xid_lookup,
23881 +};
23882 +
23883 +static struct vs_entry vx_virtual_stuff[] = {
23884 +       INF("info",     S_IRUGO, virtual_info),
23885 +       INF("status",   S_IRUGO, virtual_status),
23886 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23887 +};
23888 +
23889 +
23890 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23891 +       struct dentry *dentry, struct nameidata *nd)
23892 +{
23893 +       struct vs_entry *p = vx_virtual_stuff;
23894 +       struct dentry *error = ERR_PTR(-ENOENT);
23895 +       int id = 0;
23896 +
23897 +       for (; p->name; p++) {
23898 +               if (p->len != dentry->d_name.len)
23899 +                       continue;
23900 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23901 +                       break;
23902 +       }
23903 +       if (p->name)
23904 +               goto instantiate;
23905 +
23906 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23907 +       if ((id < 0) || !xid_is_hashed(id))
23908 +               goto out;
23909 +
23910 +instantiate:
23911 +       error = proc_xid_instantiate(dir, dentry, id, p);
23912 +out:
23913 +       return error;
23914 +}
23915 +
23916 +static struct file_operations proc_nid_file_operations = {
23917 +       .read =         generic_read_dir,
23918 +       .readdir =      proc_nid_readdir,
23919 +};
23920 +
23921 +static struct inode_operations proc_nid_inode_operations = {
23922 +       .lookup =       proc_nid_lookup,
23923 +};
23924 +
23925 +static struct vs_entry nx_virtnet_stuff[] = {
23926 +       INF("info",     S_IRUGO, virtnet_info),
23927 +       INF("status",   S_IRUGO, virtnet_status),
23928 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23929 +};
23930 +
23931 +
23932 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23933 +       struct dentry *dentry, struct nameidata *nd)
23934 +{
23935 +       struct vs_entry *p = nx_virtnet_stuff;
23936 +       struct dentry *error = ERR_PTR(-ENOENT);
23937 +       int id = 0;
23938 +
23939 +       for (; p->name; p++) {
23940 +               if (p->len != dentry->d_name.len)
23941 +                       continue;
23942 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23943 +                       break;
23944 +       }
23945 +       if (p->name)
23946 +               goto instantiate;
23947 +
23948 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23949 +       if ((id < 0) || !nid_is_hashed(id))
23950 +               goto out;
23951 +
23952 +instantiate:
23953 +       error = proc_nid_instantiate(dir, dentry, id, p);
23954 +out:
23955 +       return error;
23956 +}
23957 +
23958 +
23959 +#define PROC_MAXVIDS 32
23960 +
23961 +int proc_virtual_readdir(struct file *filp,
23962 +       void *dirent, filldir_t filldir)
23963 +{
23964 +       struct dentry *dentry = filp->f_dentry;
23965 +       struct inode *inode = dentry->d_inode;
23966 +       struct vs_entry *p = vx_virtual_stuff;
23967 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23968 +       int pos, index;
23969 +       unsigned int xid_array[PROC_MAXVIDS];
23970 +       char buf[PROC_NUMBUF];
23971 +       unsigned int nr_xids, i;
23972 +       u64 ino;
23973 +
23974 +       pos = filp->f_pos;
23975 +       switch (pos) {
23976 +       case 0:
23977 +               ino = inode->i_ino;
23978 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23979 +                       goto out;
23980 +               pos++;
23981 +               /* fall through */
23982 +       case 1:
23983 +               ino = parent_ino(dentry);
23984 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23985 +                       goto out;
23986 +               pos++;
23987 +               /* fall through */
23988 +       default:
23989 +               index = pos - 2;
23990 +               if (index >= size)
23991 +                       goto entries;
23992 +               for (p += index; p->name; p++) {
23993 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23994 +                               vs_proc_instantiate, 0, p))
23995 +                               goto out;
23996 +                       pos++;
23997 +               }
23998 +       entries:
23999 +               index = pos - size;
24000 +               p = &vx_virtual_stuff[size - 1];
24001 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
24002 +               for (i = 0; i < nr_xids; i++) {
24003 +                       int n, xid = xid_array[i];
24004 +                       unsigned int j = PROC_NUMBUF;
24005 +
24006 +                       n = xid;
24007 +                       do
24008 +                               buf[--j] = '0' + (n % 10);
24009 +                       while (n /= 10);
24010 +
24011 +                       if (proc_fill_cache(filp, dirent, filldir,
24012 +                               buf + j, PROC_NUMBUF - j,
24013 +                               vs_proc_instantiate, xid, p))
24014 +                               goto out;
24015 +                       pos++;
24016 +               }
24017 +       }
24018 +out:
24019 +       filp->f_pos = pos;
24020 +       return 0;
24021 +}
24022 +
24023 +static int proc_virtual_getattr(struct vfsmount *mnt,
24024 +       struct dentry *dentry, struct kstat *stat)
24025 +{
24026 +       struct inode *inode = dentry->d_inode;
24027 +
24028 +       generic_fillattr(inode, stat);
24029 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
24030 +       return 0;
24031 +}
24032 +
24033 +static struct file_operations proc_virtual_dir_operations = {
24034 +       .read =         generic_read_dir,
24035 +       .readdir =      proc_virtual_readdir,
24036 +};
24037 +
24038 +static struct inode_operations proc_virtual_dir_inode_operations = {
24039 +       .getattr =      proc_virtual_getattr,
24040 +       .lookup =       proc_virtual_lookup,
24041 +};
24042 +
24043 +
24044 +
24045 +
24046 +
24047 +int proc_virtnet_readdir(struct file *filp,
24048 +       void *dirent, filldir_t filldir)
24049 +{
24050 +       struct dentry *dentry = filp->f_dentry;
24051 +       struct inode *inode = dentry->d_inode;
24052 +       struct vs_entry *p = nx_virtnet_stuff;
24053 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24054 +       int pos, index;
24055 +       unsigned int nid_array[PROC_MAXVIDS];
24056 +       char buf[PROC_NUMBUF];
24057 +       unsigned int nr_nids, i;
24058 +       u64 ino;
24059 +
24060 +       pos = filp->f_pos;
24061 +       switch (pos) {
24062 +       case 0:
24063 +               ino = inode->i_ino;
24064 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24065 +                       goto out;
24066 +               pos++;
24067 +               /* fall through */
24068 +       case 1:
24069 +               ino = parent_ino(dentry);
24070 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24071 +                       goto out;
24072 +               pos++;
24073 +               /* fall through */
24074 +       default:
24075 +               index = pos - 2;
24076 +               if (index >= size)
24077 +                       goto entries;
24078 +               for (p += index; p->name; p++) {
24079 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24080 +                               vs_proc_instantiate, 0, p))
24081 +                               goto out;
24082 +                       pos++;
24083 +               }
24084 +       entries:
24085 +               index = pos - size;
24086 +               p = &nx_virtnet_stuff[size - 1];
24087 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24088 +               for (i = 0; i < nr_nids; i++) {
24089 +                       int n, nid = nid_array[i];
24090 +                       unsigned int j = PROC_NUMBUF;
24091 +
24092 +                       n = nid;
24093 +                       do
24094 +                               buf[--j] = '0' + (n % 10);
24095 +                       while (n /= 10);
24096 +
24097 +                       if (proc_fill_cache(filp, dirent, filldir,
24098 +                               buf + j, PROC_NUMBUF - j,
24099 +                               vs_proc_instantiate, nid, p))
24100 +                               goto out;
24101 +                       pos++;
24102 +               }
24103 +       }
24104 +out:
24105 +       filp->f_pos = pos;
24106 +       return 0;
24107 +}
24108 +
24109 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24110 +       struct dentry *dentry, struct kstat *stat)
24111 +{
24112 +       struct inode *inode = dentry->d_inode;
24113 +
24114 +       generic_fillattr(inode, stat);
24115 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24116 +       return 0;
24117 +}
24118 +
24119 +static struct file_operations proc_virtnet_dir_operations = {
24120 +       .read =         generic_read_dir,
24121 +       .readdir =      proc_virtnet_readdir,
24122 +};
24123 +
24124 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24125 +       .getattr =      proc_virtnet_getattr,
24126 +       .lookup =       proc_virtnet_lookup,
24127 +};
24128 +
24129 +
24130 +
24131 +void proc_vx_init(void)
24132 +{
24133 +       struct proc_dir_entry *ent;
24134 +
24135 +       ent = proc_mkdir("virtual", 0);
24136 +       if (ent) {
24137 +               ent->proc_fops = &proc_virtual_dir_operations;
24138 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24139 +       }
24140 +       proc_virtual = ent;
24141 +
24142 +       ent = proc_mkdir("virtnet", 0);
24143 +       if (ent) {
24144 +               ent->proc_fops = &proc_virtnet_dir_operations;
24145 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24146 +       }
24147 +       proc_virtnet = ent;
24148 +}
24149 +
24150 +
24151 +
24152 +
24153 +/* per pid info */
24154 +
24155 +
24156 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24157 +{
24158 +       struct vx_info *vxi;
24159 +       char *orig = buffer;
24160 +
24161 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24162 +
24163 +       vxi = task_get_vx_info(p);
24164 +       if (!vxi)
24165 +               goto out;
24166 +
24167 +       buffer += sprintf(buffer, "BCaps:\t");
24168 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24169 +       buffer += sprintf(buffer, "\n");
24170 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24171 +               (unsigned long long)vxi->vx_ccaps);
24172 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24173 +               (unsigned long long)vxi->vx_flags);
24174 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24175 +
24176 +       put_vx_info(vxi);
24177 +out:
24178 +       return buffer - orig;
24179 +}
24180 +
24181 +
24182 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24183 +{
24184 +       struct nx_info *nxi;
24185 +       struct nx_addr_v4 *v4a;
24186 +#ifdef CONFIG_IPV6
24187 +       struct nx_addr_v6 *v6a;
24188 +#endif
24189 +       char *orig = buffer;
24190 +       int i;
24191 +
24192 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24193 +
24194 +       nxi = task_get_nx_info(p);
24195 +       if (!nxi)
24196 +               goto out;
24197 +
24198 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24199 +               (unsigned long long)nxi->nx_ncaps);
24200 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24201 +               (unsigned long long)nxi->nx_flags);
24202 +
24203 +       buffer += sprintf(buffer,
24204 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24205 +               NIPQUAD(nxi->v4_bcast.s_addr));
24206 +       buffer += sprintf (buffer,
24207 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24208 +               NIPQUAD(nxi->v4_lback.s_addr));
24209 +       if (!NX_IPV4(nxi))
24210 +               goto skip_v4;
24211 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24212 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24213 +                       i, NXAV4(v4a));
24214 +skip_v4:
24215 +#ifdef CONFIG_IPV6
24216 +       if (!NX_IPV6(nxi))
24217 +               goto skip_v6;
24218 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24219 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24220 +                       i, NXAV6(v6a));
24221 +skip_v6:
24222 +#endif
24223 +       put_nx_info(nxi);
24224 +out:
24225 +       return buffer - orig;
24226 +}
24227 +
24228 diff -NurpP --minimal linux-3.0/kernel/vserver/sched.c linux-3.0-vs2.3.1-pre6/kernel/vserver/sched.c
24229 --- linux-3.0/kernel/vserver/sched.c    1970-01-01 01:00:00.000000000 +0100
24230 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/sched.c       2011-06-10 22:11:24.000000000 +0200
24231 @@ -0,0 +1,82 @@
24232 +/*
24233 + *  linux/kernel/vserver/sched.c
24234 + *
24235 + *  Virtual Server: Scheduler Support
24236 + *
24237 + *  Copyright (C) 2004-2010  Herbert Pötzl
24238 + *
24239 + *  V0.01  adapted Sam Vilains version to 2.6.3
24240 + *  V0.02  removed legacy interface
24241 + *  V0.03  changed vcmds to vxi arg
24242 + *  V0.04  removed older and legacy interfaces
24243 + *  V0.05  removed scheduler code/commands
24244 + *
24245 + */
24246 +
24247 +#include <linux/vs_context.h>
24248 +#include <linux/vs_sched.h>
24249 +#include <linux/vserver/sched_cmd.h>
24250 +
24251 +#include <asm/uaccess.h>
24252 +
24253 +
24254 +void vx_update_sched_param(struct _vx_sched *sched,
24255 +       struct _vx_sched_pc *sched_pc)
24256 +{
24257 +       sched_pc->prio_bias = sched->prio_bias;
24258 +}
24259 +
24260 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
24261 +{
24262 +       int cpu;
24263 +
24264 +       if (data->prio_bias > MAX_PRIO_BIAS)
24265 +               data->prio_bias = MAX_PRIO_BIAS;
24266 +       if (data->prio_bias < MIN_PRIO_BIAS)
24267 +               data->prio_bias = MIN_PRIO_BIAS;
24268 +
24269 +       if (data->cpu_id != ~0) {
24270 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24271 +               cpus_and(vxi->sched.update, cpu_online_map,
24272 +                       vxi->sched.update);
24273 +       } else
24274 +               vxi->sched.update = cpu_online_map;
24275 +
24276 +       for_each_cpu_mask(cpu, vxi->sched.update)
24277 +               vx_update_sched_param(&vxi->sched,
24278 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24279 +       return 0;
24280 +}
24281 +
24282 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
24283 +{
24284 +       struct vcmd_prio_bias vc_data;
24285 +
24286 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24287 +               return -EFAULT;
24288 +
24289 +       return do_set_prio_bias(vxi, &vc_data);
24290 +}
24291 +
24292 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
24293 +{
24294 +       struct vcmd_prio_bias vc_data;
24295 +       struct _vx_sched_pc *pcd;
24296 +       int cpu;
24297 +
24298 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24299 +               return -EFAULT;
24300 +
24301 +       cpu = vc_data.cpu_id;
24302 +
24303 +       if (!cpu_possible(cpu))
24304 +               return -EINVAL;
24305 +
24306 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
24307 +       vc_data.prio_bias = pcd->prio_bias;
24308 +
24309 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24310 +               return -EFAULT;
24311 +       return 0;
24312 +}
24313 +
24314 diff -NurpP --minimal linux-3.0/kernel/vserver/sched_init.h linux-3.0-vs2.3.1-pre6/kernel/vserver/sched_init.h
24315 --- linux-3.0/kernel/vserver/sched_init.h       1970-01-01 01:00:00.000000000 +0100
24316 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/sched_init.h  2011-06-10 22:11:24.000000000 +0200
24317 @@ -0,0 +1,27 @@
24318 +
24319 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24320 +{
24321 +       /* scheduling; hard code starting values as constants */
24322 +       sched->prio_bias = 0;
24323 +}
24324 +
24325 +static inline
24326 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24327 +{
24328 +       sched_pc->prio_bias = 0;
24329 +
24330 +       sched_pc->user_ticks = 0;
24331 +       sched_pc->sys_ticks = 0;
24332 +       sched_pc->hold_ticks = 0;
24333 +}
24334 +
24335 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24336 +{
24337 +       return;
24338 +}
24339 +
24340 +static inline
24341 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24342 +{
24343 +       return;
24344 +}
24345 diff -NurpP --minimal linux-3.0/kernel/vserver/sched_proc.h linux-3.0-vs2.3.1-pre6/kernel/vserver/sched_proc.h
24346 --- linux-3.0/kernel/vserver/sched_proc.h       1970-01-01 01:00:00.000000000 +0100
24347 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/sched_proc.h  2011-06-10 22:11:24.000000000 +0200
24348 @@ -0,0 +1,32 @@
24349 +#ifndef _VX_SCHED_PROC_H
24350 +#define _VX_SCHED_PROC_H
24351 +
24352 +
24353 +static inline
24354 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24355 +{
24356 +       int length = 0;
24357 +
24358 +       length += sprintf(buffer,
24359 +               "PrioBias:\t%8d\n",
24360 +               sched->prio_bias);
24361 +       return length;
24362 +}
24363 +
24364 +static inline
24365 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24366 +       char *buffer, int cpu)
24367 +{
24368 +       int length = 0;
24369 +
24370 +       length += sprintf(buffer + length,
24371 +               "cpu %d: %lld %lld %lld", cpu,
24372 +               (unsigned long long)sched_pc->user_ticks,
24373 +               (unsigned long long)sched_pc->sys_ticks,
24374 +               (unsigned long long)sched_pc->hold_ticks);
24375 +       length += sprintf(buffer + length,
24376 +               " %d\n", sched_pc->prio_bias);
24377 +       return length;
24378 +}
24379 +
24380 +#endif /* _VX_SCHED_PROC_H */
24381 diff -NurpP --minimal linux-3.0/kernel/vserver/signal.c linux-3.0-vs2.3.1-pre6/kernel/vserver/signal.c
24382 --- linux-3.0/kernel/vserver/signal.c   1970-01-01 01:00:00.000000000 +0100
24383 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/signal.c      2011-06-10 22:11:24.000000000 +0200
24384 @@ -0,0 +1,134 @@
24385 +/*
24386 + *  linux/kernel/vserver/signal.c
24387 + *
24388 + *  Virtual Server: Signal Support
24389 + *
24390 + *  Copyright (C) 2003-2007  Herbert Pötzl
24391 + *
24392 + *  V0.01  broken out from vcontext V0.05
24393 + *  V0.02  changed vcmds to vxi arg
24394 + *  V0.03  adjusted siginfo for kill
24395 + *
24396 + */
24397 +
24398 +#include <asm/uaccess.h>
24399 +
24400 +#include <linux/vs_context.h>
24401 +#include <linux/vs_pid.h>
24402 +#include <linux/vserver/signal_cmd.h>
24403 +
24404 +
24405 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24406 +{
24407 +       int retval, count = 0;
24408 +       struct task_struct *p;
24409 +       struct siginfo *sip = SEND_SIG_PRIV;
24410 +
24411 +       retval = -ESRCH;
24412 +       vxdprintk(VXD_CBIT(misc, 4),
24413 +               "vx_info_kill(%p[#%d],%d,%d)*",
24414 +               vxi, vxi->vx_id, pid, sig);
24415 +       read_lock(&tasklist_lock);
24416 +       switch (pid) {
24417 +       case  0:
24418 +       case -1:
24419 +               for_each_process(p) {
24420 +                       int err = 0;
24421 +
24422 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24423 +                               (pid && vxi->vx_initpid == p->pid))
24424 +                               continue;
24425 +
24426 +                       err = group_send_sig_info(sig, sip, p);
24427 +                       ++count;
24428 +                       if (err != -EPERM)
24429 +                               retval = err;
24430 +               }
24431 +               break;
24432 +
24433 +       case 1:
24434 +               if (vxi->vx_initpid) {
24435 +                       pid = vxi->vx_initpid;
24436 +                       /* for now, only SIGINT to private init ... */
24437 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24438 +                               /* ... as long as there are tasks left */
24439 +                               (atomic_read(&vxi->vx_tasks) > 1))
24440 +                               sig = SIGINT;
24441 +               }
24442 +               /* fallthrough */
24443 +       default:
24444 +               rcu_read_lock();
24445 +               p = find_task_by_real_pid(pid);
24446 +               rcu_read_unlock();
24447 +               if (p) {
24448 +                       if (vx_task_xid(p) == vxi->vx_id)
24449 +                               retval = group_send_sig_info(sig, sip, p);
24450 +               }
24451 +               break;
24452 +       }
24453 +       read_unlock(&tasklist_lock);
24454 +       vxdprintk(VXD_CBIT(misc, 4),
24455 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24456 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24457 +       return retval;
24458 +}
24459 +
24460 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24461 +{
24462 +       struct vcmd_ctx_kill_v0 vc_data;
24463 +
24464 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24465 +               return -EFAULT;
24466 +
24467 +       /* special check to allow guest shutdown */
24468 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24469 +               /* forbid killall pid=0 when init is present */
24470 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24471 +               (vc_data.pid > 1)))
24472 +               return -EACCES;
24473 +
24474 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24475 +}
24476 +
24477 +
24478 +static int __wait_exit(struct vx_info *vxi)
24479 +{
24480 +       DECLARE_WAITQUEUE(wait, current);
24481 +       int ret = 0;
24482 +
24483 +       add_wait_queue(&vxi->vx_wait, &wait);
24484 +       set_current_state(TASK_INTERRUPTIBLE);
24485 +
24486 +wait:
24487 +       if (vx_info_state(vxi,
24488 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24489 +               goto out;
24490 +       if (signal_pending(current)) {
24491 +               ret = -ERESTARTSYS;
24492 +               goto out;
24493 +       }
24494 +       schedule();
24495 +       goto wait;
24496 +
24497 +out:
24498 +       set_current_state(TASK_RUNNING);
24499 +       remove_wait_queue(&vxi->vx_wait, &wait);
24500 +       return ret;
24501 +}
24502 +
24503 +
24504 +
24505 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24506 +{
24507 +       struct vcmd_wait_exit_v0 vc_data;
24508 +       int ret;
24509 +
24510 +       ret = __wait_exit(vxi);
24511 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24512 +       vc_data.exit_code = vxi->exit_code;
24513 +
24514 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24515 +               ret = -EFAULT;
24516 +       return ret;
24517 +}
24518 +
24519 diff -NurpP --minimal linux-3.0/kernel/vserver/space.c linux-3.0-vs2.3.1-pre6/kernel/vserver/space.c
24520 --- linux-3.0/kernel/vserver/space.c    1970-01-01 01:00:00.000000000 +0100
24521 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/space.c       2011-07-20 02:11:49.000000000 +0200
24522 @@ -0,0 +1,435 @@
24523 +/*
24524 + *  linux/kernel/vserver/space.c
24525 + *
24526 + *  Virtual Server: Context Space Support
24527 + *
24528 + *  Copyright (C) 2003-2010  Herbert Pötzl
24529 + *
24530 + *  V0.01  broken out from context.c 0.07
24531 + *  V0.02  added task locking for namespace
24532 + *  V0.03  broken out vx_enter_namespace
24533 + *  V0.04  added *space support and commands
24534 + *  V0.05  added credential support
24535 + *
24536 + */
24537 +
24538 +#include <linux/utsname.h>
24539 +#include <linux/nsproxy.h>
24540 +#include <linux/err.h>
24541 +#include <linux/fs_struct.h>
24542 +#include <linux/cred.h>
24543 +#include <asm/uaccess.h>
24544 +
24545 +#include <linux/vs_context.h>
24546 +#include <linux/vserver/space.h>
24547 +#include <linux/vserver/space_cmd.h>
24548 +
24549 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24550 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24551 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24552 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24553 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24554 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24555 +
24556 +
24557 +/* namespace functions */
24558 +
24559 +#include <linux/mnt_namespace.h>
24560 +#include <linux/user_namespace.h>
24561 +#include <linux/pid_namespace.h>
24562 +#include <linux/ipc_namespace.h>
24563 +#include <net/net_namespace.h>
24564 +
24565 +
24566 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24567 +       .mask = CLONE_FS |
24568 +               CLONE_NEWNS |
24569 +#ifdef CONFIG_UTS_NS
24570 +               CLONE_NEWUTS |
24571 +#endif
24572 +#ifdef CONFIG_IPC_NS
24573 +               CLONE_NEWIPC |
24574 +#endif
24575 +#ifdef CONFIG_USER_NS
24576 +               CLONE_NEWUSER |
24577 +#endif
24578 +               0
24579 +};
24580 +
24581 +static const struct vcmd_space_mask_v1 space_mask = {
24582 +       .mask = CLONE_FS |
24583 +               CLONE_NEWNS |
24584 +#ifdef CONFIG_UTS_NS
24585 +               CLONE_NEWUTS |
24586 +#endif
24587 +#ifdef CONFIG_IPC_NS
24588 +               CLONE_NEWIPC |
24589 +#endif
24590 +#ifdef CONFIG_USER_NS
24591 +               CLONE_NEWUSER |
24592 +#endif
24593 +#ifdef CONFIG_PID_NS
24594 +               CLONE_NEWPID |
24595 +#endif
24596 +#ifdef CONFIG_NET_NS
24597 +               CLONE_NEWNET |
24598 +#endif
24599 +               0
24600 +};
24601 +
24602 +static const struct vcmd_space_mask_v1 default_space_mask = {
24603 +       .mask = CLONE_FS |
24604 +               CLONE_NEWNS |
24605 +#ifdef CONFIG_UTS_NS
24606 +               CLONE_NEWUTS |
24607 +#endif
24608 +#ifdef CONFIG_IPC_NS
24609 +               CLONE_NEWIPC |
24610 +#endif
24611 +#ifdef CONFIG_USER_NS
24612 +               CLONE_NEWUSER |
24613 +#endif
24614 +#ifdef CONFIG_PID_NS
24615 +//             CLONE_NEWPID |
24616 +#endif
24617 +               0
24618 +};
24619 +
24620 +/*
24621 + *     build a new nsproxy mix
24622 + *      assumes that both proxies are 'const'
24623 + *     does not touch nsproxy refcounts
24624 + *     will hold a reference on the result.
24625 + */
24626 +
24627 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24628 +       struct nsproxy *new_nsproxy, unsigned long mask)
24629 +{
24630 +       struct mnt_namespace *old_ns;
24631 +       struct uts_namespace *old_uts;
24632 +       struct ipc_namespace *old_ipc;
24633 +#ifdef CONFIG_PID_NS
24634 +       struct pid_namespace *old_pid;
24635 +#endif
24636 +#ifdef CONFIG_NET_NS
24637 +       struct net *old_net;
24638 +#endif
24639 +       struct nsproxy *nsproxy;
24640 +
24641 +       nsproxy = copy_nsproxy(old_nsproxy);
24642 +       if (!nsproxy)
24643 +               goto out;
24644 +
24645 +       if (mask & CLONE_NEWNS) {
24646 +               old_ns = nsproxy->mnt_ns;
24647 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24648 +               if (nsproxy->mnt_ns)
24649 +                       get_mnt_ns(nsproxy->mnt_ns);
24650 +       } else
24651 +               old_ns = NULL;
24652 +
24653 +       if (mask & CLONE_NEWUTS) {
24654 +               old_uts = nsproxy->uts_ns;
24655 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24656 +               if (nsproxy->uts_ns)
24657 +                       get_uts_ns(nsproxy->uts_ns);
24658 +       } else
24659 +               old_uts = NULL;
24660 +
24661 +       if (mask & CLONE_NEWIPC) {
24662 +               old_ipc = nsproxy->ipc_ns;
24663 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24664 +               if (nsproxy->ipc_ns)
24665 +                       get_ipc_ns(nsproxy->ipc_ns);
24666 +       } else
24667 +               old_ipc = NULL;
24668 +
24669 +#ifdef CONFIG_PID_NS
24670 +       if (mask & CLONE_NEWPID) {
24671 +               old_pid = nsproxy->pid_ns;
24672 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24673 +               if (nsproxy->pid_ns)
24674 +                       get_pid_ns(nsproxy->pid_ns);
24675 +       } else
24676 +               old_pid = NULL;
24677 +#endif
24678 +#ifdef CONFIG_NET_NS
24679 +       if (mask & CLONE_NEWNET) {
24680 +               old_net = nsproxy->net_ns;
24681 +               nsproxy->net_ns = new_nsproxy->net_ns;
24682 +               if (nsproxy->net_ns)
24683 +                       get_net(nsproxy->net_ns);
24684 +       } else
24685 +               old_net = NULL;
24686 +#endif
24687 +       if (old_ns)
24688 +               put_mnt_ns(old_ns);
24689 +       if (old_uts)
24690 +               put_uts_ns(old_uts);
24691 +       if (old_ipc)
24692 +               put_ipc_ns(old_ipc);
24693 +#ifdef CONFIG_PID_NS
24694 +       if (old_pid)
24695 +               put_pid_ns(old_pid);
24696 +#endif
24697 +#ifdef CONFIG_NET_NS
24698 +       if (old_net)
24699 +               put_net(old_net);
24700 +#endif
24701 +out:
24702 +       return nsproxy;
24703 +}
24704 +
24705 +
24706 +/*
24707 + *     merge two nsproxy structs into a new one.
24708 + *     will hold a reference on the result.
24709 + */
24710 +
24711 +static inline
24712 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24713 +       struct nsproxy *proxy, unsigned long mask)
24714 +{
24715 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24716 +
24717 +       if (!proxy)
24718 +               return NULL;
24719 +
24720 +       if (mask) {
24721 +               /* vs_mix_nsproxy returns with reference */
24722 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24723 +                       proxy, mask);
24724 +       }
24725 +       get_nsproxy(proxy);
24726 +       return proxy;
24727 +}
24728 +
24729 +
24730 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24731 +{
24732 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24733 +       struct fs_struct *fs_cur, *fs = NULL;
24734 +       struct _vx_space *space;
24735 +       int ret, kill = 0;
24736 +
24737 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24738 +               vxi, vxi->vx_id, mask, index);
24739 +
24740 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24741 +               return -EACCES;
24742 +
24743 +       if (index >= VX_SPACES)
24744 +               return -EINVAL;
24745 +
24746 +       space = &vxi->space[index];
24747 +
24748 +       if (!mask)
24749 +               mask = space->vx_nsmask;
24750 +
24751 +       if ((mask & space->vx_nsmask) != mask)
24752 +               return -EINVAL;
24753 +
24754 +       if (mask & CLONE_FS) {
24755 +               fs = copy_fs_struct(space->vx_fs);
24756 +               if (!fs)
24757 +                       return -ENOMEM;
24758 +       }
24759 +       proxy = space->vx_nsproxy;
24760 +
24761 +       vxdprintk(VXD_CBIT(space, 9),
24762 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
24763 +               vxi, vxi->vx_id, mask, index, proxy, fs);
24764 +
24765 +       task_lock(current);
24766 +       fs_cur = current->fs;
24767 +
24768 +       if (mask & CLONE_FS) {
24769 +               spin_lock(&fs_cur->lock);
24770 +               current->fs = fs;
24771 +               kill = !--fs_cur->users;
24772 +               spin_unlock(&fs_cur->lock);
24773 +       }
24774 +
24775 +       proxy_cur = current->nsproxy;
24776 +       get_nsproxy(proxy_cur);
24777 +       task_unlock(current);
24778 +
24779 +       if (kill)
24780 +               free_fs_struct(fs_cur);
24781 +
24782 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24783 +       if (IS_ERR(proxy_new)) {
24784 +               ret = PTR_ERR(proxy_new);
24785 +               goto out_put;
24786 +       }
24787 +
24788 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24789 +
24790 +       if (mask & CLONE_NEWUSER) {
24791 +               struct cred *cred;
24792 +
24793 +               vxdprintk(VXD_CBIT(space, 10),
24794 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
24795 +                       vxi, vxi->vx_id, space->vx_cred,
24796 +                       current->real_cred, current->cred);
24797 +
24798 +               if (space->vx_cred) {
24799 +                       cred = __prepare_creds(space->vx_cred);
24800 +                       if (cred)
24801 +                               commit_creds(cred);
24802 +               }
24803 +       }
24804 +
24805 +       ret = 0;
24806 +
24807 +       if (proxy_new)
24808 +               put_nsproxy(proxy_new);
24809 +out_put:
24810 +       if (proxy_cur)
24811 +               put_nsproxy(proxy_cur);
24812 +       return ret;
24813 +}
24814 +
24815 +
24816 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24817 +{
24818 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24819 +       struct fs_struct *fs_vxi, *fs;
24820 +       struct _vx_space *space;
24821 +       int ret, kill = 0;
24822 +
24823 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24824 +               vxi, vxi->vx_id, mask, index);
24825 +
24826 +       if ((mask & space_mask.mask) != mask)
24827 +               return -EINVAL;
24828 +
24829 +       if (index >= VX_SPACES)
24830 +               return -EINVAL;
24831 +
24832 +       space = &vxi->space[index];
24833 +
24834 +       proxy_vxi = space->vx_nsproxy;
24835 +       fs_vxi = space->vx_fs;
24836 +
24837 +       if (mask & CLONE_FS) {
24838 +               fs = copy_fs_struct(current->fs);
24839 +               if (!fs)
24840 +                       return -ENOMEM;
24841 +       }
24842 +
24843 +       task_lock(current);
24844 +
24845 +       if (mask & CLONE_FS) {
24846 +               spin_lock(&fs_vxi->lock);
24847 +               space->vx_fs = fs;
24848 +               kill = !--fs_vxi->users;
24849 +               spin_unlock(&fs_vxi->lock);
24850 +       }
24851 +
24852 +       proxy_cur = current->nsproxy;
24853 +       get_nsproxy(proxy_cur);
24854 +       task_unlock(current);
24855 +
24856 +       if (kill)
24857 +               free_fs_struct(fs_vxi);
24858 +
24859 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24860 +       if (IS_ERR(proxy_new)) {
24861 +               ret = PTR_ERR(proxy_new);
24862 +               goto out_put;
24863 +       }
24864 +
24865 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
24866 +       space->vx_nsmask |= mask;
24867 +
24868 +       if (mask & CLONE_NEWUSER) {
24869 +               struct cred *cred;
24870 +
24871 +               vxdprintk(VXD_CBIT(space, 10),
24872 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
24873 +                       vxi, vxi->vx_id, space->vx_cred,
24874 +                       current->real_cred, current->cred);
24875 +
24876 +               cred = prepare_creds();
24877 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
24878 +               if (cred)
24879 +                       abort_creds(cred);
24880 +       }
24881 +
24882 +       ret = 0;
24883 +
24884 +       if (proxy_new)
24885 +               put_nsproxy(proxy_new);
24886 +out_put:
24887 +       if (proxy_cur)
24888 +               put_nsproxy(proxy_cur);
24889 +       return ret;
24890 +}
24891 +
24892 +
24893 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24894 +{
24895 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24896 +
24897 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24898 +               return -EFAULT;
24899 +
24900 +       return vx_enter_space(vxi, vc_data.mask, 0);
24901 +}
24902 +
24903 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24904 +{
24905 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24906 +
24907 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24908 +               return -EFAULT;
24909 +
24910 +       if (vc_data.index >= VX_SPACES)
24911 +               return -EINVAL;
24912 +
24913 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24914 +}
24915 +
24916 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24917 +{
24918 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24919 +
24920 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24921 +               return -EFAULT;
24922 +
24923 +       return vx_set_space(vxi, vc_data.mask, 0);
24924 +}
24925 +
24926 +int vc_set_space(struct vx_info *vxi, void __user *data)
24927 +{
24928 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24929 +
24930 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24931 +               return -EFAULT;
24932 +
24933 +       if (vc_data.index >= VX_SPACES)
24934 +               return -EINVAL;
24935 +
24936 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24937 +}
24938 +
24939 +int vc_get_space_mask(void __user *data, int type)
24940 +{
24941 +       const struct vcmd_space_mask_v1 *mask;
24942 +
24943 +       if (type == 0)
24944 +               mask = &space_mask_v0;
24945 +       else if (type == 1)
24946 +               mask = &space_mask;
24947 +       else
24948 +               mask = &default_space_mask;
24949 +
24950 +       vxdprintk(VXD_CBIT(space, 10),
24951 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24952 +
24953 +       if (copy_to_user(data, mask, sizeof(*mask)))
24954 +               return -EFAULT;
24955 +       return 0;
24956 +}
24957 +
24958 diff -NurpP --minimal linux-3.0/kernel/vserver/switch.c linux-3.0-vs2.3.1-pre6/kernel/vserver/switch.c
24959 --- linux-3.0/kernel/vserver/switch.c   1970-01-01 01:00:00.000000000 +0100
24960 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/switch.c      2011-07-20 02:40:51.000000000 +0200
24961 @@ -0,0 +1,548 @@
24962 +/*
24963 + *  linux/kernel/vserver/switch.c
24964 + *
24965 + *  Virtual Server: Syscall Switch
24966 + *
24967 + *  Copyright (C) 2003-2007  Herbert Pötzl
24968 + *
24969 + *  V0.01  syscall switch
24970 + *  V0.02  added signal to context
24971 + *  V0.03  added rlimit functions
24972 + *  V0.04  added iattr, task/xid functions
24973 + *  V0.05  added debug/history stuff
24974 + *  V0.06  added compat32 layer
24975 + *  V0.07  vcmd args and perms
24976 + *  V0.08  added status commands
24977 + *  V0.09  added tag commands
24978 + *  V0.10  added oom bias
24979 + *  V0.11  added device commands
24980 + *
24981 + */
24982 +
24983 +#include <linux/vs_context.h>
24984 +#include <linux/vs_network.h>
24985 +#include <linux/vserver/switch.h>
24986 +
24987 +#include "vci_config.h"
24988 +
24989 +
24990 +static inline
24991 +int vc_get_version(uint32_t id)
24992 +{
24993 +       return VCI_VERSION;
24994 +}
24995 +
24996 +static inline
24997 +int vc_get_vci(uint32_t id)
24998 +{
24999 +       return vci_kernel_config();
25000 +}
25001 +
25002 +#include <linux/vserver/context_cmd.h>
25003 +#include <linux/vserver/cvirt_cmd.h>
25004 +#include <linux/vserver/cacct_cmd.h>
25005 +#include <linux/vserver/limit_cmd.h>
25006 +#include <linux/vserver/network_cmd.h>
25007 +#include <linux/vserver/sched_cmd.h>
25008 +#include <linux/vserver/debug_cmd.h>
25009 +#include <linux/vserver/inode_cmd.h>
25010 +#include <linux/vserver/dlimit_cmd.h>
25011 +#include <linux/vserver/signal_cmd.h>
25012 +#include <linux/vserver/space_cmd.h>
25013 +#include <linux/vserver/tag_cmd.h>
25014 +#include <linux/vserver/device_cmd.h>
25015 +
25016 +#include <linux/vserver/inode.h>
25017 +#include <linux/vserver/dlimit.h>
25018 +
25019 +
25020 +#ifdef CONFIG_COMPAT
25021 +#define __COMPAT(name, id, data, compat)       \
25022 +       (compat) ? name ## _x32(id, data) : name(id, data)
25023 +#define __COMPAT_NO_ID(name, data, compat)     \
25024 +       (compat) ? name ## _x32(data) : name(data)
25025 +#else
25026 +#define __COMPAT(name, id, data, compat)       \
25027 +       name(id, data)
25028 +#define __COMPAT_NO_ID(name, data, compat)     \
25029 +       name(data)
25030 +#endif
25031 +
25032 +
25033 +static inline
25034 +long do_vcmd(uint32_t cmd, uint32_t id,
25035 +       struct vx_info *vxi, struct nx_info *nxi,
25036 +       void __user *data, int compat)
25037 +{
25038 +       switch (cmd) {
25039 +
25040 +       case VCMD_get_version:
25041 +               return vc_get_version(id);
25042 +       case VCMD_get_vci:
25043 +               return vc_get_vci(id);
25044 +
25045 +       case VCMD_task_xid:
25046 +               return vc_task_xid(id);
25047 +       case VCMD_vx_info:
25048 +               return vc_vx_info(vxi, data);
25049 +
25050 +       case VCMD_task_nid:
25051 +               return vc_task_nid(id);
25052 +       case VCMD_nx_info:
25053 +               return vc_nx_info(nxi, data);
25054 +
25055 +       case VCMD_task_tag:
25056 +               return vc_task_tag(id);
25057 +
25058 +       case VCMD_set_space_v1:
25059 +               return vc_set_space_v1(vxi, data);
25060 +       /* this is version 2 */
25061 +       case VCMD_set_space:
25062 +               return vc_set_space(vxi, data);
25063 +
25064 +       case VCMD_get_space_mask_v0:
25065 +               return vc_get_space_mask(data, 0);
25066 +       /* this is version 1 */
25067 +       case VCMD_get_space_mask:
25068 +               return vc_get_space_mask(data, 1);
25069 +
25070 +       case VCMD_get_space_default:
25071 +               return vc_get_space_mask(data, -1);
25072 +
25073 +       case VCMD_set_umask:
25074 +               return vc_set_umask(vxi, data);
25075 +
25076 +       case VCMD_get_umask:
25077 +               return vc_get_umask(vxi, data);
25078 +
25079 +#ifdef CONFIG_IA32_EMULATION
25080 +       case VCMD_get_rlimit:
25081 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25082 +       case VCMD_set_rlimit:
25083 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25084 +#else
25085 +       case VCMD_get_rlimit:
25086 +               return vc_get_rlimit(vxi, data);
25087 +       case VCMD_set_rlimit:
25088 +               return vc_set_rlimit(vxi, data);
25089 +#endif
25090 +       case VCMD_get_rlimit_mask:
25091 +               return vc_get_rlimit_mask(id, data);
25092 +       case VCMD_reset_hits:
25093 +               return vc_reset_hits(vxi, data);
25094 +       case VCMD_reset_minmax:
25095 +               return vc_reset_minmax(vxi, data);
25096 +
25097 +       case VCMD_get_vhi_name:
25098 +               return vc_get_vhi_name(vxi, data);
25099 +       case VCMD_set_vhi_name:
25100 +               return vc_set_vhi_name(vxi, data);
25101 +
25102 +       case VCMD_ctx_stat:
25103 +               return vc_ctx_stat(vxi, data);
25104 +       case VCMD_virt_stat:
25105 +               return vc_virt_stat(vxi, data);
25106 +       case VCMD_sock_stat:
25107 +               return vc_sock_stat(vxi, data);
25108 +       case VCMD_rlimit_stat:
25109 +               return vc_rlimit_stat(vxi, data);
25110 +
25111 +       case VCMD_set_cflags:
25112 +               return vc_set_cflags(vxi, data);
25113 +       case VCMD_get_cflags:
25114 +               return vc_get_cflags(vxi, data);
25115 +
25116 +       /* this is version 1 */
25117 +       case VCMD_set_ccaps:
25118 +               return vc_set_ccaps(vxi, data);
25119 +       /* this is version 1 */
25120 +       case VCMD_get_ccaps:
25121 +               return vc_get_ccaps(vxi, data);
25122 +       case VCMD_set_bcaps:
25123 +               return vc_set_bcaps(vxi, data);
25124 +       case VCMD_get_bcaps:
25125 +               return vc_get_bcaps(vxi, data);
25126 +
25127 +       case VCMD_set_badness:
25128 +               return vc_set_badness(vxi, data);
25129 +       case VCMD_get_badness:
25130 +               return vc_get_badness(vxi, data);
25131 +
25132 +       case VCMD_set_nflags:
25133 +               return vc_set_nflags(nxi, data);
25134 +       case VCMD_get_nflags:
25135 +               return vc_get_nflags(nxi, data);
25136 +
25137 +       case VCMD_set_ncaps:
25138 +               return vc_set_ncaps(nxi, data);
25139 +       case VCMD_get_ncaps:
25140 +               return vc_get_ncaps(nxi, data);
25141 +
25142 +       case VCMD_set_prio_bias:
25143 +               return vc_set_prio_bias(vxi, data);
25144 +       case VCMD_get_prio_bias:
25145 +               return vc_get_prio_bias(vxi, data);
25146 +       case VCMD_add_dlimit:
25147 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25148 +       case VCMD_rem_dlimit:
25149 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25150 +       case VCMD_set_dlimit:
25151 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25152 +       case VCMD_get_dlimit:
25153 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25154 +
25155 +       case VCMD_ctx_kill:
25156 +               return vc_ctx_kill(vxi, data);
25157 +
25158 +       case VCMD_wait_exit:
25159 +               return vc_wait_exit(vxi, data);
25160 +
25161 +       case VCMD_get_iattr:
25162 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25163 +       case VCMD_set_iattr:
25164 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25165 +
25166 +       case VCMD_fget_iattr:
25167 +               return vc_fget_iattr(id, data);
25168 +       case VCMD_fset_iattr:
25169 +               return vc_fset_iattr(id, data);
25170 +
25171 +       case VCMD_enter_space_v0:
25172 +               return vc_enter_space_v1(vxi, NULL);
25173 +       case VCMD_enter_space_v1:
25174 +               return vc_enter_space_v1(vxi, data);
25175 +       /* this is version 2 */
25176 +       case VCMD_enter_space:
25177 +               return vc_enter_space(vxi, data);
25178 +
25179 +       case VCMD_ctx_create_v0:
25180 +               return vc_ctx_create(id, NULL);
25181 +       case VCMD_ctx_create:
25182 +               return vc_ctx_create(id, data);
25183 +       case VCMD_ctx_migrate_v0:
25184 +               return vc_ctx_migrate(vxi, NULL);
25185 +       case VCMD_ctx_migrate:
25186 +               return vc_ctx_migrate(vxi, data);
25187 +
25188 +       case VCMD_net_create_v0:
25189 +               return vc_net_create(id, NULL);
25190 +       case VCMD_net_create:
25191 +               return vc_net_create(id, data);
25192 +       case VCMD_net_migrate:
25193 +               return vc_net_migrate(nxi, data);
25194 +
25195 +       case VCMD_tag_migrate:
25196 +               return vc_tag_migrate(id);
25197 +
25198 +       case VCMD_net_add:
25199 +               return vc_net_add(nxi, data);
25200 +       case VCMD_net_remove:
25201 +               return vc_net_remove(nxi, data);
25202 +
25203 +       case VCMD_net_add_ipv4_v1:
25204 +               return vc_net_add_ipv4_v1(nxi, data);
25205 +       /* this is version 2 */
25206 +       case VCMD_net_add_ipv4:
25207 +               return vc_net_add_ipv4(nxi, data);
25208 +
25209 +       case VCMD_net_rem_ipv4_v1:
25210 +               return vc_net_rem_ipv4_v1(nxi, data);
25211 +       /* this is version 2 */
25212 +       case VCMD_net_rem_ipv4:
25213 +               return vc_net_rem_ipv4(nxi, data);
25214 +#ifdef CONFIG_IPV6
25215 +       case VCMD_net_add_ipv6:
25216 +               return vc_net_add_ipv6(nxi, data);
25217 +       case VCMD_net_remove_ipv6:
25218 +               return vc_net_remove_ipv6(nxi, data);
25219 +#endif
25220 +/*     case VCMD_add_match_ipv4:
25221 +               return vc_add_match_ipv4(nxi, data);
25222 +       case VCMD_get_match_ipv4:
25223 +               return vc_get_match_ipv4(nxi, data);
25224 +#ifdef CONFIG_IPV6
25225 +       case VCMD_add_match_ipv6:
25226 +               return vc_add_match_ipv6(nxi, data);
25227 +       case VCMD_get_match_ipv6:
25228 +               return vc_get_match_ipv6(nxi, data);
25229 +#endif */
25230 +
25231 +#ifdef CONFIG_VSERVER_DEVICE
25232 +       case VCMD_set_mapping:
25233 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25234 +       case VCMD_unset_mapping:
25235 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25236 +#endif
25237 +#ifdef CONFIG_VSERVER_HISTORY
25238 +       case VCMD_dump_history:
25239 +               return vc_dump_history(id);
25240 +       case VCMD_read_history:
25241 +               return __COMPAT(vc_read_history, id, data, compat);
25242 +#endif
25243 +       default:
25244 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25245 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25246 +       }
25247 +       return -ENOSYS;
25248 +}
25249 +
25250 +
25251 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25252 +       case VCMD_ ## vcmd: perm = _perm;               \
25253 +               args = _args; flags = _flags; break
25254 +
25255 +
25256 +#define VCA_NONE       0x00
25257 +#define VCA_VXI                0x01
25258 +#define VCA_NXI                0x02
25259 +
25260 +#define VCF_NONE       0x00
25261 +#define VCF_INFO       0x01
25262 +#define VCF_ADMIN      0x02
25263 +#define VCF_ARES       0x06    /* includes admin */
25264 +#define VCF_SETUP      0x08
25265 +
25266 +#define VCF_ZIDOK      0x10    /* zero id okay */
25267 +
25268 +
25269 +static inline
25270 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25271 +{
25272 +       long ret;
25273 +       int permit = -1, state = 0;
25274 +       int perm = -1, args = 0, flags = 0;
25275 +       struct vx_info *vxi = NULL;
25276 +       struct nx_info *nxi = NULL;
25277 +
25278 +       switch (cmd) {
25279 +       /* unpriviledged commands */
25280 +       __VCMD(get_version,      0, VCA_NONE,   0);
25281 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25282 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25283 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25284 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25285 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25286 +
25287 +       /* info commands */
25288 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25289 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
25290 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25291 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25292 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25293 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25294 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25295 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
25296 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25297 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25298 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25299 +
25300 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25301 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25302 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25303 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25304 +
25305 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25306 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25307 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25308 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25309 +
25310 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25311 +
25312 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25313 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25314 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25315 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
25316 +
25317 +       /* lower admin commands */
25318 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25319 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25320 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25321 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25322 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25323 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25324 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25325 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25326 +
25327 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25328 +       __VCMD(net_create,       5, VCA_NONE,   0);
25329 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25330 +
25331 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25332 +
25333 +       /* higher admin commands */
25334 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25335 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25336 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25337 +
25338 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25339 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25340 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25341 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25342 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25343 +
25344 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25345 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25346 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25347 +
25348 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25349 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25350 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25351 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25352 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25353 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25354 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25355 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25356 +#ifdef CONFIG_IPV6
25357 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25358 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25359 +#endif
25360 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25361 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25362 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25363 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25364 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25365 +
25366 +#ifdef CONFIG_VSERVER_DEVICE
25367 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25368 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25369 +#endif
25370 +       /* debug level admin commands */
25371 +#ifdef CONFIG_VSERVER_HISTORY
25372 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25373 +       __VCMD(read_history,     9, VCA_NONE,   0);
25374 +#endif
25375 +
25376 +       default:
25377 +               perm = -1;
25378 +       }
25379 +
25380 +       vxdprintk(VXD_CBIT(switch, 0),
25381 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25382 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25383 +               VC_VERSION(cmd), id, data, compat,
25384 +               perm, args, flags);
25385 +
25386 +       ret = -ENOSYS;
25387 +       if (perm < 0)
25388 +               goto out;
25389 +
25390 +       state = 1;
25391 +       if (!capable(CAP_CONTEXT))
25392 +               goto out;
25393 +
25394 +       state = 2;
25395 +       /* moved here from the individual commands */
25396 +       ret = -EPERM;
25397 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25398 +               goto out;
25399 +
25400 +       state = 3;
25401 +       /* vcmd involves resource management  */
25402 +       ret = -EPERM;
25403 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25404 +               goto out;
25405 +
25406 +       state = 4;
25407 +       /* various legacy exceptions */
25408 +       switch (cmd) {
25409 +       /* will go away when spectator is a cap */
25410 +       case VCMD_ctx_migrate_v0:
25411 +       case VCMD_ctx_migrate:
25412 +               if (id == 1) {
25413 +                       current->xid = 1;
25414 +                       ret = 1;
25415 +                       goto out;
25416 +               }
25417 +               break;
25418 +
25419 +       /* will go away when spectator is a cap */
25420 +       case VCMD_net_migrate:
25421 +               if (id == 1) {
25422 +                       current->nid = 1;
25423 +                       ret = 1;
25424 +                       goto out;
25425 +               }
25426 +               break;
25427 +       }
25428 +
25429 +       /* vcmds are fine by default */
25430 +       permit = 1;
25431 +
25432 +       /* admin type vcmds require admin ... */
25433 +       if (flags & VCF_ADMIN)
25434 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25435 +
25436 +       /* ... but setup type vcmds override that */
25437 +       if (!permit && (flags & VCF_SETUP))
25438 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25439 +
25440 +       state = 5;
25441 +       ret = -EPERM;
25442 +       if (!permit)
25443 +               goto out;
25444 +
25445 +       state = 6;
25446 +       if (!id && (flags & VCF_ZIDOK))
25447 +               goto skip_id;
25448 +
25449 +       ret = -ESRCH;
25450 +       if (args & VCA_VXI) {
25451 +               vxi = lookup_vx_info(id);
25452 +               if (!vxi)
25453 +                       goto out;
25454 +
25455 +               if ((flags & VCF_ADMIN) &&
25456 +                       /* special case kill for shutdown */
25457 +                       (cmd != VCMD_ctx_kill) &&
25458 +                       /* can context be administrated? */
25459 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25460 +                       ret = -EACCES;
25461 +                       goto out_vxi;
25462 +               }
25463 +       }
25464 +       state = 7;
25465 +       if (args & VCA_NXI) {
25466 +               nxi = lookup_nx_info(id);
25467 +               if (!nxi)
25468 +                       goto out_vxi;
25469 +
25470 +               if ((flags & VCF_ADMIN) &&
25471 +                       /* can context be administrated? */
25472 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25473 +                       ret = -EACCES;
25474 +                       goto out_nxi;
25475 +               }
25476 +       }
25477 +skip_id:
25478 +       state = 8;
25479 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25480 +
25481 +out_nxi:
25482 +       if ((args & VCA_NXI) && nxi)
25483 +               put_nx_info(nxi);
25484 +out_vxi:
25485 +       if ((args & VCA_VXI) && vxi)
25486 +               put_vx_info(vxi);
25487 +out:
25488 +       vxdprintk(VXD_CBIT(switch, 1),
25489 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25490 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25491 +               VC_VERSION(cmd), ret, ret, state, permit);
25492 +       return ret;
25493 +}
25494 +
25495 +asmlinkage long
25496 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25497 +{
25498 +       return do_vserver(cmd, id, data, 0);
25499 +}
25500 +
25501 +#ifdef CONFIG_COMPAT
25502 +
25503 +asmlinkage long
25504 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25505 +{
25506 +       return do_vserver(cmd, id, data, 1);
25507 +}
25508 +
25509 +#endif /* CONFIG_COMPAT */
25510 diff -NurpP --minimal linux-3.0/kernel/vserver/sysctl.c linux-3.0-vs2.3.1-pre6/kernel/vserver/sysctl.c
25511 --- linux-3.0/kernel/vserver/sysctl.c   1970-01-01 01:00:00.000000000 +0100
25512 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/sysctl.c      2011-06-10 22:11:24.000000000 +0200
25513 @@ -0,0 +1,241 @@
25514 +/*
25515 + *  kernel/vserver/sysctl.c
25516 + *
25517 + *  Virtual Context Support
25518 + *
25519 + *  Copyright (C) 2004-2007  Herbert Pötzl
25520 + *
25521 + *  V0.01  basic structure
25522 + *
25523 + */
25524 +
25525 +#include <linux/module.h>
25526 +#include <linux/ctype.h>
25527 +#include <linux/sysctl.h>
25528 +#include <linux/parser.h>
25529 +#include <asm/uaccess.h>
25530 +
25531 +enum {
25532 +       CTL_DEBUG_ERROR         = 0,
25533 +       CTL_DEBUG_SWITCH        = 1,
25534 +       CTL_DEBUG_XID,
25535 +       CTL_DEBUG_NID,
25536 +       CTL_DEBUG_TAG,
25537 +       CTL_DEBUG_NET,
25538 +       CTL_DEBUG_LIMIT,
25539 +       CTL_DEBUG_CRES,
25540 +       CTL_DEBUG_DLIM,
25541 +       CTL_DEBUG_QUOTA,
25542 +       CTL_DEBUG_CVIRT,
25543 +       CTL_DEBUG_SPACE,
25544 +       CTL_DEBUG_MISC,
25545 +};
25546 +
25547 +
25548 +unsigned int vx_debug_switch   = 0;
25549 +unsigned int vx_debug_xid      = 0;
25550 +unsigned int vx_debug_nid      = 0;
25551 +unsigned int vx_debug_tag      = 0;
25552 +unsigned int vx_debug_net      = 0;
25553 +unsigned int vx_debug_limit    = 0;
25554 +unsigned int vx_debug_cres     = 0;
25555 +unsigned int vx_debug_dlim     = 0;
25556 +unsigned int vx_debug_quota    = 0;
25557 +unsigned int vx_debug_cvirt    = 0;
25558 +unsigned int vx_debug_space    = 0;
25559 +unsigned int vx_debug_misc     = 0;
25560 +
25561 +
25562 +static struct ctl_table_header *vserver_table_header;
25563 +static ctl_table vserver_root_table[];
25564 +
25565 +
25566 +void vserver_register_sysctl(void)
25567 +{
25568 +       if (!vserver_table_header) {
25569 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25570 +       }
25571 +
25572 +}
25573 +
25574 +void vserver_unregister_sysctl(void)
25575 +{
25576 +       if (vserver_table_header) {
25577 +               unregister_sysctl_table(vserver_table_header);
25578 +               vserver_table_header = NULL;
25579 +       }
25580 +}
25581 +
25582 +
25583 +static int proc_dodebug(ctl_table *table, int write,
25584 +       void __user *buffer, size_t *lenp, loff_t *ppos)
25585 +{
25586 +       char            tmpbuf[20], *p, c;
25587 +       unsigned int    value;
25588 +       size_t          left, len;
25589 +
25590 +       if ((*ppos && !write) || !*lenp) {
25591 +               *lenp = 0;
25592 +               return 0;
25593 +       }
25594 +
25595 +       left = *lenp;
25596 +
25597 +       if (write) {
25598 +               if (!access_ok(VERIFY_READ, buffer, left))
25599 +                       return -EFAULT;
25600 +               p = (char *)buffer;
25601 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25602 +                       left--, p++;
25603 +               if (!left)
25604 +                       goto done;
25605 +
25606 +               if (left > sizeof(tmpbuf) - 1)
25607 +                       return -EINVAL;
25608 +               if (copy_from_user(tmpbuf, p, left))
25609 +                       return -EFAULT;
25610 +               tmpbuf[left] = '\0';
25611 +
25612 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25613 +                       value = 10 * value + (*p - '0');
25614 +               if (*p && !isspace(*p))
25615 +                       return -EINVAL;
25616 +               while (left && isspace(*p))
25617 +                       left--, p++;
25618 +               *(unsigned int *)table->data = value;
25619 +       } else {
25620 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25621 +                       return -EFAULT;
25622 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25623 +               if (len > left)
25624 +                       len = left;
25625 +               if (__copy_to_user(buffer, tmpbuf, len))
25626 +                       return -EFAULT;
25627 +               if ((left -= len) > 0) {
25628 +                       if (put_user('\n', (char *)buffer + len))
25629 +                               return -EFAULT;
25630 +                       left--;
25631 +               }
25632 +       }
25633 +
25634 +done:
25635 +       *lenp -= left;
25636 +       *ppos += *lenp;
25637 +       return 0;
25638 +}
25639 +
25640 +static int zero;
25641 +
25642 +#define        CTL_ENTRY(ctl, name)                            \
25643 +       {                                               \
25644 +               .procname       = #name,                \
25645 +               .data           = &vx_ ## name,         \
25646 +               .maxlen         = sizeof(int),          \
25647 +               .mode           = 0644,                 \
25648 +               .proc_handler   = &proc_dodebug,        \
25649 +               .extra1         = &zero,                \
25650 +               .extra2         = &zero,                \
25651 +       }
25652 +
25653 +static ctl_table vserver_debug_table[] = {
25654 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25655 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25656 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25657 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25658 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25659 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25660 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25661 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25662 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25663 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25664 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25665 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25666 +       { 0 }
25667 +};
25668 +
25669 +static ctl_table vserver_root_table[] = {
25670 +       {
25671 +               .procname       = "vserver",
25672 +               .mode           = 0555,
25673 +               .child          = vserver_debug_table
25674 +       },
25675 +       { 0 }
25676 +};
25677 +
25678 +
25679 +static match_table_t tokens = {
25680 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25681 +       { CTL_DEBUG_XID,        "xid=%x"        },
25682 +       { CTL_DEBUG_NID,        "nid=%x"        },
25683 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25684 +       { CTL_DEBUG_NET,        "net=%x"        },
25685 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25686 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25687 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25688 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25689 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25690 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25691 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25692 +       { CTL_DEBUG_ERROR,      NULL            }
25693 +};
25694 +
25695 +#define        HANDLE_CASE(id, name, val)                              \
25696 +       case CTL_DEBUG_ ## id:                                  \
25697 +               vx_debug_ ## name = val;                        \
25698 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25699 +               break
25700 +
25701 +
25702 +static int __init vs_debug_setup(char *str)
25703 +{
25704 +       char *p;
25705 +       int token;
25706 +
25707 +       printk("vs_debug_setup(%s)\n", str);
25708 +       while ((p = strsep(&str, ",")) != NULL) {
25709 +               substring_t args[MAX_OPT_ARGS];
25710 +               unsigned int value;
25711 +
25712 +               if (!*p)
25713 +                       continue;
25714 +
25715 +               token = match_token(p, tokens, args);
25716 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25717 +
25718 +               switch (token) {
25719 +               HANDLE_CASE(SWITCH, switch, value);
25720 +               HANDLE_CASE(XID,    xid,    value);
25721 +               HANDLE_CASE(NID,    nid,    value);
25722 +               HANDLE_CASE(TAG,    tag,    value);
25723 +               HANDLE_CASE(NET,    net,    value);
25724 +               HANDLE_CASE(LIMIT,  limit,  value);
25725 +               HANDLE_CASE(CRES,   cres,   value);
25726 +               HANDLE_CASE(DLIM,   dlim,   value);
25727 +               HANDLE_CASE(QUOTA,  quota,  value);
25728 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25729 +               HANDLE_CASE(SPACE,  space,  value);
25730 +               HANDLE_CASE(MISC,   misc,   value);
25731 +               default:
25732 +                       return -EINVAL;
25733 +                       break;
25734 +               }
25735 +       }
25736 +       return 1;
25737 +}
25738 +
25739 +__setup("vsdebug=", vs_debug_setup);
25740 +
25741 +
25742 +
25743 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25744 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25745 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25746 +EXPORT_SYMBOL_GPL(vx_debug_net);
25747 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25748 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25749 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25750 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25751 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25752 +EXPORT_SYMBOL_GPL(vx_debug_space);
25753 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25754 +
25755 diff -NurpP --minimal linux-3.0/kernel/vserver/tag.c linux-3.0-vs2.3.1-pre6/kernel/vserver/tag.c
25756 --- linux-3.0/kernel/vserver/tag.c      1970-01-01 01:00:00.000000000 +0100
25757 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/tag.c 2011-06-10 22:11:24.000000000 +0200
25758 @@ -0,0 +1,63 @@
25759 +/*
25760 + *  linux/kernel/vserver/tag.c
25761 + *
25762 + *  Virtual Server: Shallow Tag Space
25763 + *
25764 + *  Copyright (C) 2007  Herbert Pötzl
25765 + *
25766 + *  V0.01  basic implementation
25767 + *
25768 + */
25769 +
25770 +#include <linux/sched.h>
25771 +#include <linux/vserver/debug.h>
25772 +#include <linux/vs_pid.h>
25773 +#include <linux/vs_tag.h>
25774 +
25775 +#include <linux/vserver/tag_cmd.h>
25776 +
25777 +
25778 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25779 +{
25780 +       if (!p)
25781 +               BUG();
25782 +
25783 +       vxdprintk(VXD_CBIT(tag, 5),
25784 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25785 +
25786 +       task_lock(p);
25787 +       p->tag = tag;
25788 +       task_unlock(p);
25789 +
25790 +       vxdprintk(VXD_CBIT(tag, 5),
25791 +               "moved task %p into [#%d]", p, tag);
25792 +       return 0;
25793 +}
25794 +
25795 +/* vserver syscall commands below here */
25796 +
25797 +/* taks xid and vx_info functions */
25798 +
25799 +
25800 +int vc_task_tag(uint32_t id)
25801 +{
25802 +       tag_t tag;
25803 +
25804 +       if (id) {
25805 +               struct task_struct *tsk;
25806 +               rcu_read_lock();
25807 +               tsk = find_task_by_real_pid(id);
25808 +               tag = (tsk) ? tsk->tag : -ESRCH;
25809 +               rcu_read_unlock();
25810 +       } else
25811 +               tag = dx_current_tag();
25812 +       return tag;
25813 +}
25814 +
25815 +
25816 +int vc_tag_migrate(uint32_t tag)
25817 +{
25818 +       return dx_migrate_task(current, tag & 0xFFFF);
25819 +}
25820 +
25821 +
25822 diff -NurpP --minimal linux-3.0/kernel/vserver/vci_config.h linux-3.0-vs2.3.1-pre6/kernel/vserver/vci_config.h
25823 --- linux-3.0/kernel/vserver/vci_config.h       1970-01-01 01:00:00.000000000 +0100
25824 +++ linux-3.0-vs2.3.1-pre6/kernel/vserver/vci_config.h  2011-06-10 22:11:24.000000000 +0200
25825 @@ -0,0 +1,76 @@
25826 +
25827 +/*  interface version */
25828 +
25829 +#define VCI_VERSION            0x00020308
25830 +
25831 +
25832 +enum {
25833 +       VCI_KCBIT_NO_DYNAMIC = 0,
25834 +
25835 +       VCI_KCBIT_PROC_SECURE = 4,
25836 +       /* VCI_KCBIT_HARDCPU = 5, */
25837 +       /* VCI_KCBIT_IDLELIMIT = 6, */
25838 +       /* VCI_KCBIT_IDLETIME = 7, */
25839 +
25840 +       VCI_KCBIT_COWBL = 8,
25841 +       VCI_KCBIT_FULLCOWBL = 9,
25842 +       VCI_KCBIT_SPACES = 10,
25843 +       VCI_KCBIT_NETV2 = 11,
25844 +       VCI_KCBIT_MEMCG = 12,
25845 +
25846 +       VCI_KCBIT_DEBUG = 16,
25847 +       VCI_KCBIT_HISTORY = 20,
25848 +       VCI_KCBIT_TAGGED = 24,
25849 +       VCI_KCBIT_PPTAG = 28,
25850 +
25851 +       VCI_KCBIT_MORE = 31,
25852 +};
25853 +
25854 +
25855 +static inline uint32_t vci_kernel_config(void)
25856 +{
25857 +       return
25858 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25859 +
25860 +       /* configured features */
25861 +#ifdef CONFIG_VSERVER_PROC_SECURE
25862 +       (1 << VCI_KCBIT_PROC_SECURE) |
25863 +#endif
25864 +#ifdef CONFIG_VSERVER_COWBL
25865 +       (1 << VCI_KCBIT_COWBL) |
25866 +       (1 << VCI_KCBIT_FULLCOWBL) |
25867 +#endif
25868 +       (1 << VCI_KCBIT_SPACES) |
25869 +       (1 << VCI_KCBIT_NETV2) |
25870 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
25871 +       (1 << VCI_KCBIT_MEMCG) |
25872 +#endif
25873 +
25874 +       /* debug options */
25875 +#ifdef CONFIG_VSERVER_DEBUG
25876 +       (1 << VCI_KCBIT_DEBUG) |
25877 +#endif
25878 +#ifdef CONFIG_VSERVER_HISTORY
25879 +       (1 << VCI_KCBIT_HISTORY) |
25880 +#endif
25881 +
25882 +       /* inode context tagging */
25883 +#if    defined(CONFIG_TAGGING_NONE)
25884 +       (0 << VCI_KCBIT_TAGGED) |
25885 +#elif  defined(CONFIG_TAGGING_UID16)
25886 +       (1 << VCI_KCBIT_TAGGED) |
25887 +#elif  defined(CONFIG_TAGGING_GID16)
25888 +       (2 << VCI_KCBIT_TAGGED) |
25889 +#elif  defined(CONFIG_TAGGING_ID24)
25890 +       (3 << VCI_KCBIT_TAGGED) |
25891 +#elif  defined(CONFIG_TAGGING_INTERN)
25892 +       (4 << VCI_KCBIT_TAGGED) |
25893 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25894 +       (5 << VCI_KCBIT_TAGGED) |
25895 +#else
25896 +       (7 << VCI_KCBIT_TAGGED) |
25897 +#endif
25898 +       (1 << VCI_KCBIT_PPTAG) |
25899 +       0;
25900 +}
25901 +
25902 diff -NurpP --minimal linux-3.0/mm/filemap_xip.c linux-3.0-vs2.3.1-pre6/mm/filemap_xip.c
25903 --- linux-3.0/mm/filemap_xip.c  2011-07-22 11:18:12.000000000 +0200
25904 +++ linux-3.0-vs2.3.1-pre6/mm/filemap_xip.c     2011-06-10 22:11:24.000000000 +0200
25905 @@ -18,6 +18,7 @@
25906  #include <linux/seqlock.h>
25907  #include <linux/mutex.h>
25908  #include <linux/gfp.h>
25909 +#include <linux/vs_memory.h>
25910  #include <asm/tlbflush.h>
25911  #include <asm/io.h>
25912  
25913 diff -NurpP --minimal linux-3.0/mm/fremap.c linux-3.0-vs2.3.1-pre6/mm/fremap.c
25914 --- linux-3.0/mm/fremap.c       2011-07-22 11:18:12.000000000 +0200
25915 +++ linux-3.0-vs2.3.1-pre6/mm/fremap.c  2011-06-10 22:11:24.000000000 +0200
25916 @@ -16,6 +16,7 @@
25917  #include <linux/module.h>
25918  #include <linux/syscalls.h>
25919  #include <linux/mmu_notifier.h>
25920 +#include <linux/vs_memory.h>
25921  
25922  #include <asm/mmu_context.h>
25923  #include <asm/cacheflush.h>
25924 diff -NurpP --minimal linux-3.0/mm/hugetlb.c linux-3.0-vs2.3.1-pre6/mm/hugetlb.c
25925 --- linux-3.0/mm/hugetlb.c      2011-07-22 11:18:12.000000000 +0200
25926 +++ linux-3.0-vs2.3.1-pre6/mm/hugetlb.c 2011-06-22 12:39:16.000000000 +0200
25927 @@ -28,6 +28,7 @@
25928  
25929  #include <linux/hugetlb.h>
25930  #include <linux/node.h>
25931 +#include <linux/vs_memory.h>
25932  #include "internal.h"
25933  
25934  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25935 diff -NurpP --minimal linux-3.0/mm/memcontrol.c linux-3.0-vs2.3.1-pre6/mm/memcontrol.c
25936 --- linux-3.0/mm/memcontrol.c   2011-07-22 11:18:12.000000000 +0200
25937 +++ linux-3.0-vs2.3.1-pre6/mm/memcontrol.c      2011-07-19 00:44:39.000000000 +0200
25938 @@ -741,6 +741,31 @@ struct mem_cgroup *mem_cgroup_from_task(
25939                                 struct mem_cgroup, css);
25940  }
25941  
25942 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
25943 +{
25944 +       return res_counter_read_u64(&mem->res, member);
25945 +}
25946 +
25947 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
25948 +{
25949 +       return res_counter_read_u64(&mem->memsw, member);
25950 +}
25951 +
25952 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
25953 +{
25954 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
25955 +}
25956 +
25957 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
25958 +{
25959 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
25960 +}
25961 +
25962 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
25963 +{
25964 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
25965 +}
25966 +
25967  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
25968  {
25969         struct mem_cgroup *mem = NULL;
25970 diff -NurpP --minimal linux-3.0/mm/memory.c linux-3.0-vs2.3.1-pre6/mm/memory.c
25971 --- linux-3.0/mm/memory.c       2011-07-22 11:18:12.000000000 +0200
25972 +++ linux-3.0-vs2.3.1-pre6/mm/memory.c  2011-07-19 00:44:39.000000000 +0200
25973 @@ -3332,6 +3332,7 @@ int handle_pte_fault(struct mm_struct *m
25974  {
25975         pte_t entry;
25976         spinlock_t *ptl;
25977 +       int ret = 0, type = VXPT_UNKNOWN;
25978  
25979         entry = *pte;
25980         if (!pte_present(entry)) {
25981 @@ -3356,9 +3357,12 @@ int handle_pte_fault(struct mm_struct *m
25982         if (unlikely(!pte_same(*pte, entry)))
25983                 goto unlock;
25984         if (flags & FAULT_FLAG_WRITE) {
25985 -               if (!pte_write(entry))
25986 -                       return do_wp_page(mm, vma, address,
25987 +               if (!pte_write(entry)) {
25988 +                       ret = do_wp_page(mm, vma, address,
25989                                         pte, pmd, ptl, entry);
25990 +                       type = VXPT_WRITE;
25991 +                       goto out;
25992 +               }
25993                 entry = pte_mkdirty(entry);
25994         }
25995         entry = pte_mkyoung(entry);
25996 @@ -3376,7 +3380,10 @@ int handle_pte_fault(struct mm_struct *m
25997         }
25998  unlock:
25999         pte_unmap_unlock(pte, ptl);
26000 -       return 0;
26001 +       ret = 0;
26002 +out:
26003 +       vx_page_fault(mm, vma, type, ret);
26004 +       return ret;
26005  }
26006  
26007  /*
26008 diff -NurpP --minimal linux-3.0/mm/mremap.c linux-3.0-vs2.3.1-pre6/mm/mremap.c
26009 --- linux-3.0/mm/mremap.c       2011-07-22 11:18:12.000000000 +0200
26010 +++ linux-3.0-vs2.3.1-pre6/mm/mremap.c  2011-06-10 22:11:24.000000000 +0200
26011 @@ -19,6 +19,7 @@
26012  #include <linux/security.h>
26013  #include <linux/syscalls.h>
26014  #include <linux/mmu_notifier.h>
26015 +#include <linux/vs_memory.h>
26016  
26017  #include <asm/uaccess.h>
26018  #include <asm/cacheflush.h>
26019 diff -NurpP --minimal linux-3.0/mm/oom_kill.c linux-3.0-vs2.3.1-pre6/mm/oom_kill.c
26020 --- linux-3.0/mm/oom_kill.c     2011-07-22 11:18:12.000000000 +0200
26021 +++ linux-3.0-vs2.3.1-pre6/mm/oom_kill.c        2011-06-10 22:11:24.000000000 +0200
26022 @@ -32,6 +32,9 @@
26023  #include <linux/mempolicy.h>
26024  #include <linux/security.h>
26025  #include <linux/ptrace.h>
26026 +#include <linux/reboot.h>
26027 +#include <linux/vs_memory.h>
26028 +#include <linux/vs_context.h>
26029  
26030  int sysctl_panic_on_oom;
26031  int sysctl_oom_kill_allocating_task;
26032 @@ -134,11 +137,18 @@ struct task_struct *find_lock_task_mm(st
26033  static bool oom_unkillable_task(struct task_struct *p,
26034                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
26035  {
26036 -       if (is_global_init(p))
26037 +       unsigned xid = vx_current_xid();
26038 +
26039 +       /* skip the init task, global and per guest */
26040 +       if (task_is_init(p))
26041                 return true;
26042         if (p->flags & PF_KTHREAD)
26043                 return true;
26044  
26045 +       /* skip other guest and host processes if oom in guest */
26046 +       if (xid && vx_task_xid(p) != xid)
26047 +               return true;
26048 +
26049         /* When mem_cgroup_out_of_memory() and p is not member of the group */
26050         if (mem && !task_in_mem_cgroup(p, mem))
26051                 return true;
26052 @@ -214,6 +224,18 @@ unsigned int oom_badness(struct task_str
26053         points += p->signal->oom_score_adj;
26054  
26055         /*
26056 +        * add points for context badness and
26057 +        * reduce badness for processes belonging to
26058 +        * a different context
26059 +        */
26060 +
26061 +       points += vx_badness(p, p->mm);
26062 +
26063 +       if ((vx_current_xid() > 1) &&
26064 +               vx_current_xid() != vx_task_xid(p))
26065 +               points /= 16;
26066 +
26067 +       /*
26068          * Never return 0 for an eligible task that may be killed since it's
26069          * possible that no single user task uses more than 0.1% of memory and
26070          * no single admin tasks uses more than 3.0%.
26071 @@ -427,8 +449,8 @@ static int oom_kill_task(struct task_str
26072         /* mm cannot be safely dereferenced after task_unlock(p) */
26073         mm = p->mm;
26074  
26075 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
26076 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
26077 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
26078 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
26079                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
26080                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
26081         task_unlock(p);
26082 @@ -482,8 +504,8 @@ static int oom_kill_process(struct task_
26083         }
26084  
26085         task_lock(p);
26086 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
26087 -               message, task_pid_nr(p), p->comm, points);
26088 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
26089 +               message, task_pid_nr(p), p->xid, p->comm, points);
26090         task_unlock(p);
26091  
26092         /*
26093 @@ -584,6 +606,8 @@ int unregister_oom_notifier(struct notif
26094  }
26095  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
26096  
26097 +long vs_oom_action(unsigned int);
26098 +
26099  /*
26100   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
26101   * if a parallel OOM killing is already taking place that includes a zone in
26102 @@ -742,7 +766,12 @@ retry:
26103         if (!p) {
26104                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
26105                 read_unlock(&tasklist_lock);
26106 -               panic("Out of memory and no killable processes...\n");
26107 +
26108 +               /* avoid panic for guest OOM */
26109 +               if (current->xid)
26110 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
26111 +               else
26112 +                       panic("Out of memory and no killable processes...\n");
26113         }
26114  
26115         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
26116 diff -NurpP --minimal linux-3.0/mm/page_alloc.c linux-3.0-vs2.3.1-pre6/mm/page_alloc.c
26117 --- linux-3.0/mm/page_alloc.c   2011-07-22 11:18:12.000000000 +0200
26118 +++ linux-3.0-vs2.3.1-pre6/mm/page_alloc.c      2011-06-10 22:24:12.000000000 +0200
26119 @@ -57,6 +57,8 @@
26120  #include <linux/ftrace_event.h>
26121  #include <linux/memcontrol.h>
26122  #include <linux/prefetch.h>
26123 +#include <linux/vs_base.h>
26124 +#include <linux/vs_limit.h>
26125  
26126  #include <asm/tlbflush.h>
26127  #include <asm/div64.h>
26128 @@ -2470,6 +2472,9 @@ void si_meminfo(struct sysinfo *val)
26129         val->totalhigh = totalhigh_pages;
26130         val->freehigh = nr_free_highpages();
26131         val->mem_unit = PAGE_SIZE;
26132 +
26133 +       if (vx_flags(VXF_VIRT_MEM, 0))
26134 +               vx_vsi_meminfo(val);
26135  }
26136  
26137  EXPORT_SYMBOL(si_meminfo);
26138 @@ -2490,6 +2495,9 @@ void si_meminfo_node(struct sysinfo *val
26139         val->freehigh = 0;
26140  #endif
26141         val->mem_unit = PAGE_SIZE;
26142 +
26143 +       if (vx_flags(VXF_VIRT_MEM, 0))
26144 +               vx_vsi_meminfo(val);
26145  }
26146  #endif
26147  
26148 diff -NurpP --minimal linux-3.0/mm/pgtable-generic.c linux-3.0-vs2.3.1-pre6/mm/pgtable-generic.c
26149 --- linux-3.0/mm/pgtable-generic.c      2011-03-15 18:07:42.000000000 +0100
26150 +++ linux-3.0-vs2.3.1-pre6/mm/pgtable-generic.c 2011-06-10 22:11:24.000000000 +0200
26151 @@ -6,6 +6,8 @@
26152   *  Copyright (C) 2010  Linus Torvalds
26153   */
26154  
26155 +#include <linux/mm.h>
26156 +
26157  #include <linux/pagemap.h>
26158  #include <asm/tlb.h>
26159  #include <asm-generic/pgtable.h>
26160 diff -NurpP --minimal linux-3.0/mm/rmap.c linux-3.0-vs2.3.1-pre6/mm/rmap.c
26161 --- linux-3.0/mm/rmap.c 2011-07-22 11:18:12.000000000 +0200
26162 +++ linux-3.0-vs2.3.1-pre6/mm/rmap.c    2011-07-01 11:35:35.000000000 +0200
26163 @@ -57,6 +57,7 @@
26164  #include <linux/mmu_notifier.h>
26165  #include <linux/migrate.h>
26166  #include <linux/hugetlb.h>
26167 +#include <linux/vs_memory.h>
26168  
26169  #include <asm/tlbflush.h>
26170  
26171 diff -NurpP --minimal linux-3.0/mm/shmem.c linux-3.0-vs2.3.1-pre6/mm/shmem.c
26172 --- linux-3.0/mm/shmem.c        2011-07-22 11:18:12.000000000 +0200
26173 +++ linux-3.0-vs2.3.1-pre6/mm/shmem.c   2011-07-01 11:35:35.000000000 +0200
26174 @@ -1850,7 +1850,7 @@ static int shmem_statfs(struct dentry *d
26175  {
26176         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26177  
26178 -       buf->f_type = TMPFS_MAGIC;
26179 +       buf->f_type = TMPFS_SUPER_MAGIC;
26180         buf->f_bsize = PAGE_CACHE_SIZE;
26181         buf->f_namelen = NAME_MAX;
26182         if (sbinfo->max_blocks) {
26183 @@ -2605,7 +2605,7 @@ int shmem_fill_super(struct super_block 
26184         sb->s_maxbytes = SHMEM_MAX_BYTES;
26185         sb->s_blocksize = PAGE_CACHE_SIZE;
26186         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26187 -       sb->s_magic = TMPFS_MAGIC;
26188 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26189         sb->s_op = &shmem_ops;
26190         sb->s_time_gran = 1;
26191  #ifdef CONFIG_TMPFS_XATTR
26192 diff -NurpP --minimal linux-3.0/mm/slab.c linux-3.0-vs2.3.1-pre6/mm/slab.c
26193 --- linux-3.0/mm/slab.c 2011-07-22 11:18:12.000000000 +0200
26194 +++ linux-3.0-vs2.3.1-pre6/mm/slab.c    2011-06-15 02:41:23.000000000 +0200
26195 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
26196  #define STATS_INC_FREEMISS(x)  do { } while (0)
26197  #endif
26198  
26199 +#include "slab_vs.h"
26200 +
26201  #if DEBUG
26202  
26203  /*
26204 @@ -3348,6 +3350,7 @@ retry:
26205  
26206         obj = slab_get_obj(cachep, slabp, nodeid);
26207         check_slabp(cachep, slabp);
26208 +       vx_slab_alloc(cachep, flags);
26209         l3->free_objects--;
26210         /* move slabp to correct slabp list: */
26211         list_del(&slabp->list);
26212 @@ -3425,6 +3428,7 @@ __cache_alloc_node(struct kmem_cache *ca
26213         /* ___cache_alloc_node can fall back to other nodes */
26214         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26215    out:
26216 +       vx_slab_alloc(cachep, flags);
26217         local_irq_restore(save_flags);
26218         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26219         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
26220 @@ -3612,6 +3616,7 @@ static inline void __cache_free(struct k
26221         check_irq_off();
26222         kmemleak_free_recursive(objp, cachep->flags);
26223         objp = cache_free_debugcheck(cachep, objp, caller);
26224 +       vx_slab_free(cachep);
26225  
26226         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
26227  
26228 diff -NurpP --minimal linux-3.0/mm/slab_vs.h linux-3.0-vs2.3.1-pre6/mm/slab_vs.h
26229 --- linux-3.0/mm/slab_vs.h      1970-01-01 01:00:00.000000000 +0100
26230 +++ linux-3.0-vs2.3.1-pre6/mm/slab_vs.h 2011-06-10 22:11:24.000000000 +0200
26231 @@ -0,0 +1,29 @@
26232 +
26233 +#include <linux/vserver/context.h>
26234 +
26235 +#include <linux/vs_context.h>
26236 +
26237 +static inline
26238 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26239 +{
26240 +       int what = gfp_zone(cachep->gfpflags);
26241 +       struct vx_info *vxi = current_vx_info();
26242 +
26243 +       if (!vxi)
26244 +               return;
26245 +
26246 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
26247 +}
26248 +
26249 +static inline
26250 +void vx_slab_free(struct kmem_cache *cachep)
26251 +{
26252 +       int what = gfp_zone(cachep->gfpflags);
26253 +       struct vx_info *vxi = current_vx_info();
26254 +
26255 +       if (!vxi)
26256 +               return;
26257 +
26258 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
26259 +}
26260 +
26261 diff -NurpP --minimal linux-3.0/mm/swapfile.c linux-3.0-vs2.3.1-pre6/mm/swapfile.c
26262 --- linux-3.0/mm/swapfile.c     2011-07-22 11:18:12.000000000 +0200
26263 +++ linux-3.0-vs2.3.1-pre6/mm/swapfile.c        2011-07-01 11:35:35.000000000 +0200
26264 @@ -37,6 +37,8 @@
26265  #include <asm/tlbflush.h>
26266  #include <linux/swapops.h>
26267  #include <linux/page_cgroup.h>
26268 +#include <linux/vs_base.h>
26269 +#include <linux/vs_memory.h>
26270  
26271  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
26272                                  unsigned char);
26273 @@ -1759,6 +1761,16 @@ static int swap_show(struct seq_file *sw
26274  
26275         if (si == SEQ_START_TOKEN) {
26276                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
26277 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
26278 +                       struct sysinfo si;
26279 +
26280 +                       vx_vsi_swapinfo(&si);
26281 +                       if (si.totalswap < (1 << 10))
26282 +                               return 0;
26283 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
26284 +                               "hdv0", "partition", si.totalswap >> 10,
26285 +                               (si.totalswap - si.freeswap) >> 10, -1);
26286 +               }
26287                 return 0;
26288         }
26289  
26290 @@ -2186,6 +2198,8 @@ void si_swapinfo(struct sysinfo *val)
26291         val->freeswap = nr_swap_pages + nr_to_be_unused;
26292         val->totalswap = total_swap_pages + nr_to_be_unused;
26293         spin_unlock(&swap_lock);
26294 +       if (vx_flags(VXF_VIRT_MEM, 0))
26295 +               vx_vsi_swapinfo(val);
26296  }
26297  
26298  /*
26299 diff -NurpP --minimal linux-3.0/net/bridge/br_multicast.c linux-3.0-vs2.3.1-pre6/net/bridge/br_multicast.c
26300 --- linux-3.0/net/bridge/br_multicast.c 2011-07-22 11:18:12.000000000 +0200
26301 +++ linux-3.0-vs2.3.1-pre6/net/bridge/br_multicast.c    2011-07-19 00:44:39.000000000 +0200
26302 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
26303         ip6h->hop_limit = 1;
26304         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
26305         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
26306 -                          &ip6h->saddr);
26307 +                          &ip6h->saddr, NULL);
26308         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
26309  
26310         hopopt = (u8 *)(ip6h + 1);
26311 diff -NurpP --minimal linux-3.0/net/core/dev.c linux-3.0-vs2.3.1-pre6/net/core/dev.c
26312 --- linux-3.0/net/core/dev.c    2011-07-22 11:18:13.000000000 +0200
26313 +++ linux-3.0-vs2.3.1-pre6/net/core/dev.c       2011-06-15 02:40:14.000000000 +0200
26314 @@ -127,6 +127,7 @@
26315  #include <linux/in.h>
26316  #include <linux/jhash.h>
26317  #include <linux/random.h>
26318 +#include <linux/vs_inet.h>
26319  #include <trace/events/napi.h>
26320  #include <trace/events/net.h>
26321  #include <trace/events/skb.h>
26322 @@ -609,7 +610,8 @@ struct net_device *__dev_get_by_name(str
26323         struct hlist_head *head = dev_name_hash(net, name);
26324  
26325         hlist_for_each_entry(dev, p, head, name_hlist)
26326 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26327 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26328 +                   nx_dev_visible(current_nx_info(), dev))
26329                         return dev;
26330  
26331         return NULL;
26332 @@ -635,7 +637,8 @@ struct net_device *dev_get_by_name_rcu(s
26333         struct hlist_head *head = dev_name_hash(net, name);
26334  
26335         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
26336 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26337 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26338 +                   nx_dev_visible(current_nx_info(), dev))
26339                         return dev;
26340  
26341         return NULL;
26342 @@ -686,7 +689,8 @@ struct net_device *__dev_get_by_index(st
26343         struct hlist_head *head = dev_index_hash(net, ifindex);
26344  
26345         hlist_for_each_entry(dev, p, head, index_hlist)
26346 -               if (dev->ifindex == ifindex)
26347 +               if ((dev->ifindex == ifindex) &&
26348 +                   nx_dev_visible(current_nx_info(), dev))
26349                         return dev;
26350  
26351         return NULL;
26352 @@ -711,7 +715,8 @@ struct net_device *dev_get_by_index_rcu(
26353         struct hlist_head *head = dev_index_hash(net, ifindex);
26354  
26355         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
26356 -               if (dev->ifindex == ifindex)
26357 +               if ((dev->ifindex == ifindex) &&
26358 +                   nx_dev_visible(current_nx_info(), dev))
26359                         return dev;
26360  
26361         return NULL;
26362 @@ -764,7 +769,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
26363  
26364         for_each_netdev_rcu(net, dev)
26365                 if (dev->type == type &&
26366 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
26367 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
26368 +                   nx_dev_visible(current_nx_info(), dev))
26369                         return dev;
26370  
26371         return NULL;
26372 @@ -776,9 +782,11 @@ struct net_device *__dev_getfirstbyhwtyp
26373         struct net_device *dev;
26374  
26375         ASSERT_RTNL();
26376 -       for_each_netdev(net, dev)
26377 -               if (dev->type == type)
26378 +       for_each_netdev(net, dev) {
26379 +               if ((dev->type == type) &&
26380 +                   nx_dev_visible(current_nx_info(), dev))
26381                         return dev;
26382 +       }
26383  
26384         return NULL;
26385  }
26386 @@ -896,6 +904,8 @@ static int __dev_alloc_name(struct net *
26387                                 continue;
26388                         if (i < 0 || i >= max_netdevices)
26389                                 continue;
26390 +                       if (!nx_dev_visible(current_nx_info(), d))
26391 +                               continue;
26392  
26393                         /*  avoid cases where sscanf is not exact inverse of printf */
26394                         snprintf(buf, IFNAMSIZ, name, i);
26395 @@ -3937,6 +3947,8 @@ static int dev_ifconf(struct net *net, c
26396  
26397         total = 0;
26398         for_each_netdev(net, dev) {
26399 +               if (!nx_dev_visible(current_nx_info(), dev))
26400 +                       continue;
26401                 for (i = 0; i < NPROTO; i++) {
26402                         if (gifconf_list[i]) {
26403                                 int done;
26404 @@ -4011,6 +4023,10 @@ static void dev_seq_printf_stats(struct 
26405         struct rtnl_link_stats64 temp;
26406         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
26407  
26408 +       /* device visible inside network context? */
26409 +       if (!nx_dev_visible(current_nx_info(), dev))
26410 +               return;
26411 +
26412         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
26413                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
26414                    dev->name, stats->rx_bytes, stats->rx_packets,
26415 diff -NurpP --minimal linux-3.0/net/core/rtnetlink.c linux-3.0-vs2.3.1-pre6/net/core/rtnetlink.c
26416 --- linux-3.0/net/core/rtnetlink.c      2011-07-22 11:18:13.000000000 +0200
26417 +++ linux-3.0-vs2.3.1-pre6/net/core/rtnetlink.c 2011-06-10 22:11:24.000000000 +0200
26418 @@ -1015,6 +1015,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26419                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
26420                         if (idx < s_idx)
26421                                 goto cont;
26422 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26423 +                               continue;
26424                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26425                                              NETLINK_CB(cb->skb).pid,
26426                                              cb->nlh->nlmsg_seq, 0,
26427 @@ -1848,6 +1850,9 @@ void rtmsg_ifinfo(int type, struct net_d
26428         struct sk_buff *skb;
26429         int err = -ENOBUFS;
26430  
26431 +       if (!nx_dev_visible(current_nx_info(), dev))
26432 +               return;
26433 +
26434         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26435         if (skb == NULL)
26436                 goto errout;
26437 diff -NurpP --minimal linux-3.0/net/core/sock.c linux-3.0-vs2.3.1-pre6/net/core/sock.c
26438 --- linux-3.0/net/core/sock.c   2011-05-22 16:18:00.000000000 +0200
26439 +++ linux-3.0-vs2.3.1-pre6/net/core/sock.c      2011-06-10 22:11:24.000000000 +0200
26440 @@ -127,6 +127,10 @@
26441  #include <net/cls_cgroup.h>
26442  
26443  #include <linux/filter.h>
26444 +#include <linux/vs_socket.h>
26445 +#include <linux/vs_limit.h>
26446 +#include <linux/vs_context.h>
26447 +#include <linux/vs_network.h>
26448  
26449  #ifdef CONFIG_INET
26450  #include <net/tcp.h>
26451 @@ -1070,6 +1074,8 @@ static struct sock *sk_prot_alloc(struct
26452                         goto out_free_sec;
26453                 sk_tx_queue_clear(sk);
26454         }
26455 +               sock_vx_init(sk);
26456 +               sock_nx_init(sk);
26457  
26458         return sk;
26459  
26460 @@ -1169,6 +1175,11 @@ static void __sk_free(struct sock *sk)
26461                 put_cred(sk->sk_peer_cred);
26462         put_pid(sk->sk_peer_pid);
26463         put_net(sock_net(sk));
26464 +       vx_sock_dec(sk);
26465 +       clr_vx_info(&sk->sk_vx_info);
26466 +       sk->sk_xid = -1;
26467 +       clr_nx_info(&sk->sk_nx_info);
26468 +       sk->sk_nid = -1;
26469         sk_prot_free(sk->sk_prot_creator, sk);
26470  }
26471  
26472 @@ -1216,6 +1227,8 @@ struct sock *sk_clone(const struct sock 
26473  
26474                 /* SANITY */
26475                 get_net(sock_net(newsk));
26476 +               sock_vx_init(newsk);
26477 +               sock_nx_init(newsk);
26478                 sk_node_init(&newsk->sk_node);
26479                 sock_lock_init(newsk);
26480                 bh_lock_sock(newsk);
26481 @@ -1271,6 +1284,12 @@ struct sock *sk_clone(const struct sock 
26482                 smp_wmb();
26483                 atomic_set(&newsk->sk_refcnt, 2);
26484  
26485 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26486 +               newsk->sk_xid = sk->sk_xid;
26487 +               vx_sock_inc(newsk);
26488 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26489 +               newsk->sk_nid = sk->sk_nid;
26490 +
26491                 /*
26492                  * Increment the counter in the same struct proto as the master
26493                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26494 @@ -2017,6 +2036,12 @@ void sock_init_data(struct socket *sock,
26495  
26496         sk->sk_stamp = ktime_set(-1L, 0);
26497  
26498 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
26499 +       sk->sk_xid = vx_current_xid();
26500 +       vx_sock_inc(sk);
26501 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
26502 +       sk->sk_nid = nx_current_nid();
26503 +
26504         /*
26505          * Before updating sk_refcnt, we must commit prior changes to memory
26506          * (Documentation/RCU/rculist_nulls.txt for details)
26507 diff -NurpP --minimal linux-3.0/net/ipv4/af_inet.c linux-3.0-vs2.3.1-pre6/net/ipv4/af_inet.c
26508 --- linux-3.0/net/ipv4/af_inet.c        2011-07-22 11:18:13.000000000 +0200
26509 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/af_inet.c   2011-07-19 00:44:39.000000000 +0200
26510 @@ -117,6 +117,7 @@
26511  #ifdef CONFIG_IP_MROUTE
26512  #include <linux/mroute.h>
26513  #endif
26514 +#include <linux/vs_limit.h>
26515  
26516  
26517  /* The inetsw table contains everything that inet_create needs to
26518 @@ -326,9 +327,13 @@ lookup_protocol:
26519         }
26520  
26521         err = -EPERM;
26522 +       if ((protocol == IPPROTO_ICMP) &&
26523 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
26524 +               goto override;
26525 +
26526         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
26527                 goto out_rcu_unlock;
26528 -
26529 +override:
26530         err = -EAFNOSUPPORT;
26531         if (!inet_netns_ok(net, protocol))
26532                 goto out_rcu_unlock;
26533 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
26534         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26535         struct sock *sk = sock->sk;
26536         struct inet_sock *inet = inet_sk(sk);
26537 +       struct nx_v4_sock_addr nsa;
26538         unsigned short snum;
26539         int chk_addr_ret;
26540         int err;
26541 @@ -470,7 +476,11 @@ int inet_bind(struct socket *sock, struc
26542                 goto out;
26543         }
26544  
26545 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26546 +       err = v4_map_sock_addr(inet, addr, &nsa);
26547 +       if (err)
26548 +               goto out;
26549 +
26550 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26551  
26552         /* Not specified by any standard per-se, however it breaks too
26553          * many applications when removed.  It is unfortunate since
26554 @@ -482,7 +492,7 @@ int inet_bind(struct socket *sock, struc
26555         err = -EADDRNOTAVAIL;
26556         if (!sysctl_ip_nonlocal_bind &&
26557             !(inet->freebind || inet->transparent) &&
26558 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26559 +           nsa.saddr != htonl(INADDR_ANY) &&
26560             chk_addr_ret != RTN_LOCAL &&
26561             chk_addr_ret != RTN_MULTICAST &&
26562             chk_addr_ret != RTN_BROADCAST)
26563 @@ -507,7 +517,7 @@ int inet_bind(struct socket *sock, struc
26564         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
26565                 goto out_release_sock;
26566  
26567 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
26568 +       v4_set_sock_addr(inet, &nsa);
26569         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26570                 inet->inet_saddr = 0;  /* Use device */
26571  
26572 @@ -710,11 +720,13 @@ int inet_getname(struct socket *sock, st
26573                      peer == 1))
26574                         return -ENOTCONN;
26575                 sin->sin_port = inet->inet_dport;
26576 -               sin->sin_addr.s_addr = inet->inet_daddr;
26577 +               sin->sin_addr.s_addr =
26578 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
26579         } else {
26580                 __be32 addr = inet->inet_rcv_saddr;
26581                 if (!addr)
26582                         addr = inet->inet_saddr;
26583 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26584                 sin->sin_port = inet->inet_sport;
26585                 sin->sin_addr.s_addr = addr;
26586         }
26587 diff -NurpP --minimal linux-3.0/net/ipv4/devinet.c linux-3.0-vs2.3.1-pre6/net/ipv4/devinet.c
26588 --- linux-3.0/net/ipv4/devinet.c        2011-07-22 11:18:13.000000000 +0200
26589 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/devinet.c   2011-06-10 22:11:24.000000000 +0200
26590 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
26591  }
26592  EXPORT_SYMBOL(inetdev_by_index);
26593  
26594 +
26595  /* Called only from RTNL semaphored context. No locks. */
26596  
26597  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26598 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
26599  
26600         in_dev = __in_dev_get_rtnl(dev);
26601         if (in_dev) {
26602 +               struct nx_info *nxi = current_nx_info();
26603 +
26604                 if (tryaddrmatch) {
26605                         /* Matthias Andree */
26606                         /* compare label and address (4.4BSD style) */
26607 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
26608                            This is checked above. */
26609                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26610                              ifap = &ifa->ifa_next) {
26611 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26612 +                                       continue;
26613                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26614                                     sin_orig.sin_addr.s_addr ==
26615                                                         ifa->ifa_local) {
26616 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
26617                    comparing just the label */
26618                 if (!ifa) {
26619                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26620 -                            ifap = &ifa->ifa_next)
26621 +                            ifap = &ifa->ifa_next) {
26622 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26623 +                                       continue;
26624                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26625                                         break;
26626 +                       }
26627                 }
26628         }
26629  
26630 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
26631                 goto out;
26632  
26633         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
26634 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
26635 +                       continue;
26636                 if (!buf) {
26637                         done += sizeof(ifr);
26638                         continue;
26639 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
26640         struct net_device *dev;
26641         struct in_device *in_dev;
26642         struct in_ifaddr *ifa;
26643 +       struct sock *sk = skb->sk;
26644         struct hlist_head *head;
26645         struct hlist_node *node;
26646  
26647 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
26648  
26649                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26650                              ifa = ifa->ifa_next, ip_idx++) {
26651 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26652 +                               continue;
26653                                 if (ip_idx < s_ip_idx)
26654                                         continue;
26655                                 if (inet_fill_ifaddr(skb, ifa,
26656 diff -NurpP --minimal linux-3.0/net/ipv4/inet_connection_sock.c linux-3.0-vs2.3.1-pre6/net/ipv4/inet_connection_sock.c
26657 --- linux-3.0/net/ipv4/inet_connection_sock.c   2011-07-22 11:18:13.000000000 +0200
26658 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/inet_connection_sock.c      2011-06-10 22:11:24.000000000 +0200
26659 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
26660  }
26661  EXPORT_SYMBOL(inet_get_local_port_range);
26662  
26663 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26664 +{
26665 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
26666 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
26667 +
26668 +       if (inet_v6_ipv6only(sk2))
26669 +               return 0;
26670 +
26671 +       if (sk1_rcv_saddr &&
26672 +           sk2_rcv_saddr &&
26673 +           sk1_rcv_saddr == sk2_rcv_saddr)
26674 +               return 1;
26675 +
26676 +       if (sk1_rcv_saddr &&
26677 +           !sk2_rcv_saddr &&
26678 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26679 +               return 1;
26680 +
26681 +       if (sk2_rcv_saddr &&
26682 +           !sk1_rcv_saddr &&
26683 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26684 +               return 1;
26685 +
26686 +       if (!sk1_rcv_saddr &&
26687 +           !sk2_rcv_saddr &&
26688 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26689 +               return 1;
26690 +
26691 +       return 0;
26692 +}
26693 +
26694  int inet_csk_bind_conflict(const struct sock *sk,
26695                            const struct inet_bind_bucket *tb)
26696  {
26697 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
26698                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26699                         if (!reuse || !sk2->sk_reuse ||
26700                             sk2->sk_state == TCP_LISTEN) {
26701 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
26702 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
26703 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
26704 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26705                                         break;
26706                         }
26707                 }
26708 diff -NurpP --minimal linux-3.0/net/ipv4/inet_diag.c linux-3.0-vs2.3.1-pre6/net/ipv4/inet_diag.c
26709 --- linux-3.0/net/ipv4/inet_diag.c      2011-07-22 11:18:13.000000000 +0200
26710 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/inet_diag.c 2011-06-22 12:39:16.000000000 +0200
26711 @@ -33,6 +33,8 @@
26712  #include <linux/stddef.h>
26713  
26714  #include <linux/inet_diag.h>
26715 +#include <linux/vs_network.h>
26716 +#include <linux/vs_inet.h>
26717  
26718  static const struct inet_diag_handler **inet_diag_table;
26719  
26720 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
26721  
26722         r->id.idiag_sport = inet->inet_sport;
26723         r->id.idiag_dport = inet->inet_dport;
26724 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
26725 -       r->id.idiag_dst[0] = inet->inet_daddr;
26726 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
26727 +               inet->inet_rcv_saddr);
26728 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
26729 +               inet->inet_daddr);
26730  
26731  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26732         if (r->idiag_family == AF_INET6) {
26733 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
26734         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26735         r->id.idiag_sport     = tw->tw_sport;
26736         r->id.idiag_dport     = tw->tw_dport;
26737 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26738 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26739 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26740 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26741         r->idiag_state        = tw->tw_substate;
26742         r->idiag_timer        = 3;
26743         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26744 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
26745         err = -EINVAL;
26746  
26747         if (req->idiag_family == AF_INET) {
26748 +               /* TODO: lback */
26749                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26750                                  req->id.idiag_dport, req->id.idiag_src[0],
26751                                  req->id.idiag_sport, req->id.idiag_if);
26752 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
26753                 } else
26754  #endif
26755                 {
26756 +                       /* TODO: lback */
26757                         entry.saddr = &inet->inet_rcv_saddr;
26758                         entry.daddr = &inet->inet_daddr;
26759                 }
26760 @@ -543,6 +549,7 @@ static int inet_twsk_diag_dump(struct in
26761                 } else
26762  #endif
26763                 {
26764 +                       /* TODO: lback */
26765                         entry.saddr = &tw->tw_rcv_saddr;
26766                         entry.daddr = &tw->tw_daddr;
26767                 }
26768 @@ -589,8 +596,8 @@ static int inet_diag_fill_req(struct sk_
26769  
26770         r->id.idiag_sport = inet->inet_sport;
26771         r->id.idiag_dport = ireq->rmt_port;
26772 -       r->id.idiag_src[0] = ireq->loc_addr;
26773 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26774 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26775 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26776         r->idiag_expires = jiffies_to_msecs(tmo);
26777         r->idiag_rqueue = 0;
26778         r->idiag_wqueue = 0;
26779 @@ -661,6 +668,7 @@ static int inet_diag_dump_reqs(struct sk
26780                                 continue;
26781  
26782                         if (bc) {
26783 +                               /* TODO: lback */
26784                                 entry.saddr =
26785  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26786                                         (entry.family == AF_INET6) ?
26787 @@ -731,6 +739,8 @@ static int inet_diag_dump(struct sk_buff
26788                         sk_nulls_for_each(sk, node, &ilb->head) {
26789                                 struct inet_sock *inet = inet_sk(sk);
26790  
26791 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26792 +                                       continue;
26793                                 if (num < s_num) {
26794                                         num++;
26795                                         continue;
26796 @@ -797,6 +807,8 @@ skip_listen_ht:
26797                 sk_nulls_for_each(sk, node, &head->chain) {
26798                         struct inet_sock *inet = inet_sk(sk);
26799  
26800 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26801 +                               continue;
26802                         if (num < s_num)
26803                                 goto next_normal;
26804                         if (!(r->idiag_states & (1 << sk->sk_state)))
26805 @@ -821,6 +833,8 @@ next_normal:
26806                         inet_twsk_for_each(tw, node,
26807                                     &head->twchain) {
26808  
26809 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26810 +                                       continue;
26811                                 if (num < s_num)
26812                                         goto next_dying;
26813                                 if (r->id.idiag_sport != tw->tw_sport &&
26814 diff -NurpP --minimal linux-3.0/net/ipv4/inet_hashtables.c linux-3.0-vs2.3.1-pre6/net/ipv4/inet_hashtables.c
26815 --- linux-3.0/net/ipv4/inet_hashtables.c        2011-01-05 21:50:42.000000000 +0100
26816 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/inet_hashtables.c   2011-06-10 22:11:24.000000000 +0200
26817 @@ -21,6 +21,7 @@
26818  
26819  #include <net/inet_connection_sock.h>
26820  #include <net/inet_hashtables.h>
26821 +#include <net/route.h>
26822  #include <net/ip.h>
26823  
26824  /*
26825 @@ -155,6 +156,11 @@ static inline int compute_score(struct s
26826                         if (rcv_saddr != daddr)
26827                                 return -1;
26828                         score += 2;
26829 +               } else {
26830 +                       /* block non nx_info ips */
26831 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
26832 +                               daddr, NXA_MASK_BIND))
26833 +                               return -1;
26834                 }
26835                 if (sk->sk_bound_dev_if) {
26836                         if (sk->sk_bound_dev_if != dif)
26837 @@ -172,7 +178,6 @@ static inline int compute_score(struct s
26838   * wildcarded during the search since they can never be otherwise.
26839   */
26840  
26841 -
26842  struct sock *__inet_lookup_listener(struct net *net,
26843                                     struct inet_hashinfo *hashinfo,
26844                                     const __be32 daddr, const unsigned short hnum,
26845 @@ -195,6 +200,7 @@ begin:
26846                         hiscore = score;
26847                 }
26848         }
26849 +
26850         /*
26851          * if the nulls value we got at the end of this lookup is
26852          * not the expected one, we must restart lookup.
26853 diff -NurpP --minimal linux-3.0/net/ipv4/netfilter/nf_nat_helper.c linux-3.0-vs2.3.1-pre6/net/ipv4/netfilter/nf_nat_helper.c
26854 --- linux-3.0/net/ipv4/netfilter/nf_nat_helper.c        2011-07-22 11:18:13.000000000 +0200
26855 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/netfilter/nf_nat_helper.c   2011-06-15 02:40:14.000000000 +0200
26856 @@ -20,6 +20,7 @@
26857  #include <net/route.h>
26858  
26859  #include <linux/netfilter_ipv4.h>
26860 +#include <net/route.h>
26861  #include <net/netfilter/nf_conntrack.h>
26862  #include <net/netfilter/nf_conntrack_helper.h>
26863  #include <net/netfilter/nf_conntrack_ecache.h>
26864 diff -NurpP --minimal linux-3.0/net/ipv4/netfilter.c linux-3.0-vs2.3.1-pre6/net/ipv4/netfilter.c
26865 --- linux-3.0/net/ipv4/netfilter.c      2011-07-22 11:18:13.000000000 +0200
26866 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/netfilter.c 2011-07-19 00:44:39.000000000 +0200
26867 @@ -5,7 +5,7 @@
26868  #include <linux/ip.h>
26869  #include <linux/skbuff.h>
26870  #include <linux/gfp.h>
26871 -#include <net/route.h>
26872 +// #include <net/route.h>
26873  #include <net/xfrm.h>
26874  #include <net/ip.h>
26875  #include <net/netfilter/nf_queue.h>
26876 diff -NurpP --minimal linux-3.0/net/ipv4/raw.c linux-3.0-vs2.3.1-pre6/net/ipv4/raw.c
26877 --- linux-3.0/net/ipv4/raw.c    2011-07-22 11:18:13.000000000 +0200
26878 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/raw.c       2011-06-10 22:11:24.000000000 +0200
26879 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
26880  
26881                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
26882                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
26883 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
26884 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
26885                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
26886                         goto found; /* gotcha */
26887         }
26888 @@ -385,6 +385,12 @@ static int raw_send_hdrinc(struct sock *
26889                 icmp_out_count(net, ((struct icmphdr *)
26890                         skb_transport_header(skb))->type);
26891  
26892 +       err = -EPERM;
26893 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
26894 +               sk->sk_nx_info &&
26895 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
26896 +               goto error_free;
26897 +
26898         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
26899                       rt->dst.dev, dst_output);
26900         if (err > 0)
26901 @@ -647,17 +653,19 @@ static int raw_bind(struct sock *sk, str
26902  {
26903         struct inet_sock *inet = inet_sk(sk);
26904         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
26905 +       struct nx_v4_sock_addr nsa = { 0 };
26906         int ret = -EINVAL;
26907         int chk_addr_ret;
26908  
26909         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
26910                 goto out;
26911 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26912 +       v4_map_sock_addr(inet, addr, &nsa);
26913 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26914         ret = -EADDRNOTAVAIL;
26915 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
26916 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
26917             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
26918                 goto out;
26919 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
26920 +       v4_set_sock_addr(inet, &nsa);
26921         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26922                 inet->inet_saddr = 0;  /* Use device */
26923         sk_dst_reset(sk);
26924 @@ -709,7 +717,8 @@ static int raw_recvmsg(struct kiocb *ioc
26925         /* Copy the address. */
26926         if (sin) {
26927                 sin->sin_family = AF_INET;
26928 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26929 +               sin->sin_addr.s_addr =
26930 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
26931                 sin->sin_port = 0;
26932                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
26933         }
26934 @@ -905,7 +914,8 @@ static struct sock *raw_get_first(struct
26935                 struct hlist_node *node;
26936  
26937                 sk_for_each(sk, node, &state->h->ht[state->bucket])
26938 -                       if (sock_net(sk) == seq_file_net(seq))
26939 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
26940 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26941                                 goto found;
26942         }
26943         sk = NULL;
26944 @@ -921,7 +931,8 @@ static struct sock *raw_get_next(struct 
26945                 sk = sk_next(sk);
26946  try_again:
26947                 ;
26948 -       } while (sk && sock_net(sk) != seq_file_net(seq));
26949 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
26950 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26951  
26952         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
26953                 sk = sk_head(&state->h->ht[state->bucket]);
26954 diff -NurpP --minimal linux-3.0/net/ipv4/tcp.c linux-3.0-vs2.3.1-pre6/net/ipv4/tcp.c
26955 --- linux-3.0/net/ipv4/tcp.c    2011-07-22 11:18:13.000000000 +0200
26956 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/tcp.c       2011-07-19 00:44:39.000000000 +0200
26957 @@ -266,6 +266,7 @@
26958  #include <linux/crypto.h>
26959  #include <linux/time.h>
26960  #include <linux/slab.h>
26961 +#include <linux/in.h>
26962  
26963  #include <net/icmp.h>
26964  #include <net/tcp.h>
26965 diff -NurpP --minimal linux-3.0/net/ipv4/tcp_ipv4.c linux-3.0-vs2.3.1-pre6/net/ipv4/tcp_ipv4.c
26966 --- linux-3.0/net/ipv4/tcp_ipv4.c       2011-07-22 11:18:13.000000000 +0200
26967 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/tcp_ipv4.c  2011-06-22 12:39:16.000000000 +0200
26968 @@ -2002,6 +2002,12 @@ static void *listening_get_next(struct s
26969                 req = req->dl_next;
26970                 while (1) {
26971                         while (req) {
26972 +                               vxdprintk(VXD_CBIT(net, 6),
26973 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
26974 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
26975 +                               if (req->sk &&
26976 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
26977 +                                       continue;
26978                                 if (req->rsk_ops->family == st->family) {
26979                                         cur = req;
26980                                         goto out;
26981 @@ -2026,6 +2032,10 @@ get_req:
26982         }
26983  get_sk:
26984         sk_nulls_for_each_from(sk, node) {
26985 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
26986 +                       sk, sk->sk_nid, nx_current_nid());
26987 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26988 +                       continue;
26989                 if (!net_eq(sock_net(sk), net))
26990                         continue;
26991                 if (sk->sk_family == st->family) {
26992 @@ -2102,6 +2112,11 @@ static void *established_get_first(struc
26993  
26994                 spin_lock_bh(lock);
26995                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
26996 +                       vxdprintk(VXD_CBIT(net, 6),
26997 +                               "sk,egf: %p [#%d] (from %d)",
26998 +                               sk, sk->sk_nid, nx_current_nid());
26999 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27000 +                               continue;
27001                         if (sk->sk_family != st->family ||
27002                             !net_eq(sock_net(sk), net)) {
27003                                 continue;
27004 @@ -2112,6 +2127,11 @@ static void *established_get_first(struc
27005                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27006                 inet_twsk_for_each(tw, node,
27007                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27008 +                       vxdprintk(VXD_CBIT(net, 6),
27009 +                               "tw: %p [#%d] (from %d)",
27010 +                               tw, tw->tw_nid, nx_current_nid());
27011 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27012 +                               continue;
27013                         if (tw->tw_family != st->family ||
27014                             !net_eq(twsk_net(tw), net)) {
27015                                 continue;
27016 @@ -2141,7 +2161,9 @@ static void *established_get_next(struct
27017                 tw = cur;
27018                 tw = tw_next(tw);
27019  get_tw:
27020 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27021 +               while (tw && (tw->tw_family != st->family ||
27022 +                       !net_eq(twsk_net(tw), net) ||
27023 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27024                         tw = tw_next(tw);
27025                 }
27026                 if (tw) {
27027 @@ -2165,6 +2187,11 @@ get_tw:
27028                 sk = sk_nulls_next(sk);
27029  
27030         sk_nulls_for_each_from(sk, node) {
27031 +               vxdprintk(VXD_CBIT(net, 6),
27032 +                       "sk,egn: %p [#%d] (from %d)",
27033 +                       sk, sk->sk_nid, nx_current_nid());
27034 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27035 +                       continue;
27036                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27037                         goto found;
27038         }
27039 @@ -2374,9 +2401,9 @@ static void get_openreq4(struct sock *sk
27040         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27041                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
27042                 i,
27043 -               ireq->loc_addr,
27044 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27045                 ntohs(inet_sk(sk)->inet_sport),
27046 -               ireq->rmt_addr,
27047 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27048                 ntohs(ireq->rmt_port),
27049                 TCP_SYN_RECV,
27050                 0, 0, /* could print option size, but that is af dependent. */
27051 diff -NurpP --minimal linux-3.0/net/ipv4/tcp_minisocks.c linux-3.0-vs2.3.1-pre6/net/ipv4/tcp_minisocks.c
27052 --- linux-3.0/net/ipv4/tcp_minisocks.c  2011-03-15 18:07:45.000000000 +0100
27053 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/tcp_minisocks.c     2011-06-10 22:11:24.000000000 +0200
27054 @@ -23,6 +23,9 @@
27055  #include <linux/slab.h>
27056  #include <linux/sysctl.h>
27057  #include <linux/workqueue.h>
27058 +#include <linux/vs_limit.h>
27059 +#include <linux/vs_socket.h>
27060 +#include <linux/vs_context.h>
27061  #include <net/tcp.h>
27062  #include <net/inet_common.h>
27063  #include <net/xfrm.h>
27064 @@ -335,6 +338,11 @@ void tcp_time_wait(struct sock *sk, int 
27065                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27066                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27067  
27068 +               tw->tw_xid              = sk->sk_xid;
27069 +               tw->tw_vx_info          = NULL;
27070 +               tw->tw_nid              = sk->sk_nid;
27071 +               tw->tw_nx_info          = NULL;
27072 +
27073  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27074                 if (tw->tw_family == PF_INET6) {
27075                         struct ipv6_pinfo *np = inet6_sk(sk);
27076 diff -NurpP --minimal linux-3.0/net/ipv4/udp.c linux-3.0-vs2.3.1-pre6/net/ipv4/udp.c
27077 --- linux-3.0/net/ipv4/udp.c    2011-07-22 11:18:13.000000000 +0200
27078 +++ linux-3.0-vs2.3.1-pre6/net/ipv4/udp.c       2011-07-19 00:44:39.000000000 +0200
27079 @@ -296,14 +296,7 @@ fail:
27080  }
27081  EXPORT_SYMBOL(udp_lib_get_port);
27082  
27083 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27084 -{
27085 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27086 -
27087 -       return  (!ipv6_only_sock(sk2)  &&
27088 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
27089 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
27090 -}
27091 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27092  
27093  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
27094                                        unsigned int port)
27095 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
27096                         if (inet->inet_rcv_saddr != daddr)
27097                                 return -1;
27098                         score += 2;
27099 +               } else {
27100 +                       /* block non nx_info ips */
27101 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27102 +                               daddr, NXA_MASK_BIND))
27103 +                               return -1;
27104                 }
27105                 if (inet->inet_daddr) {
27106                         if (inet->inet_daddr != saddr)
27107 @@ -441,6 +439,7 @@ exact_match:
27108         return result;
27109  }
27110  
27111 +
27112  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27113   * harder than this. -DaveM
27114   */
27115 @@ -486,6 +485,11 @@ begin:
27116         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27117                 score = compute_score(sk, net, saddr, hnum, sport,
27118                                       daddr, dport, dif);
27119 +               /* FIXME: disabled?
27120 +               if (score == 9) {
27121 +                       result = sk;
27122 +                       break;
27123 +               } else */
27124                 if (score > badness) {
27125                         result = sk;
27126                         badness = score;
27127 @@ -499,6 +503,7 @@ begin:
27128         if (get_nulls_value(node) != slot)
27129                 goto begin;
27130  
27131 +
27132         if (result) {
27133                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
27134                         result = NULL;
27135 @@ -508,6 +513,7 @@ begin:
27136                         goto begin;
27137                 }
27138         }
27139 +
27140         rcu_read_unlock();
27141         return result;
27142  }
27143 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
27144                     udp_sk(s)->udp_port_hash != hnum ||
27145                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
27146                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
27147 -                   (inet->inet_rcv_saddr &&
27148 -                    inet->inet_rcv_saddr != loc_addr) ||
27149 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27150                     ipv6_only_sock(s) ||
27151                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27152                         continue;
27153 @@ -1226,7 +1231,8 @@ try_again:
27154         if (sin) {
27155                 sin->sin_family = AF_INET;
27156                 sin->sin_port = udp_hdr(skb)->source;
27157 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27158 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27159 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27160                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27161         }
27162         if (inet->cmsg_flags)
27163 @@ -1970,6 +1976,8 @@ static struct sock *udp_get_first(struct
27164                 sk_nulls_for_each(sk, node, &hslot->head) {
27165                         if (!net_eq(sock_net(sk), net))
27166                                 continue;
27167 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27168 +                               continue;
27169                         if (sk->sk_family == state->family)
27170                                 goto found;
27171                 }
27172 @@ -1987,7 +1995,9 @@ static struct sock *udp_get_next(struct 
27173  
27174         do {
27175                 sk = sk_nulls_next(sk);
27176 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27177 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27178 +               sk->sk_family != state->family ||
27179 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27180  
27181         if (!sk) {
27182                 if (state->bucket <= state->udp_table->mask)
27183 diff -NurpP --minimal linux-3.0/net/ipv6/Kconfig linux-3.0-vs2.3.1-pre6/net/ipv6/Kconfig
27184 --- linux-3.0/net/ipv6/Kconfig  2010-08-02 16:52:59.000000000 +0200
27185 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/Kconfig     2011-06-10 22:11:24.000000000 +0200
27186 @@ -4,8 +4,8 @@
27187  
27188  #   IPv6 as module will cause a CRASH if you try to unload it
27189  menuconfig IPV6
27190 -       tristate "The IPv6 protocol"
27191 -       default m
27192 +       bool "The IPv6 protocol"
27193 +       default n
27194         ---help---
27195           This is complemental support for the IP version 6.
27196           You will still be able to do traditional IPv4 networking as well.
27197 diff -NurpP --minimal linux-3.0/net/ipv6/addrconf.c linux-3.0-vs2.3.1-pre6/net/ipv6/addrconf.c
27198 --- linux-3.0/net/ipv6/addrconf.c       2011-07-22 11:18:13.000000000 +0200
27199 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/addrconf.c  2011-06-10 22:11:24.000000000 +0200
27200 @@ -87,6 +87,8 @@
27201  
27202  #include <linux/proc_fs.h>
27203  #include <linux/seq_file.h>
27204 +#include <linux/vs_network.h>
27205 +#include <linux/vs_inet6.h>
27206  
27207  /* Set to 3 to get tracing... */
27208  #define ACONF_DEBUG 2
27209 @@ -1108,7 +1110,7 @@ out:
27210  
27211  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27212                        const struct in6_addr *daddr, unsigned int prefs,
27213 -                      struct in6_addr *saddr)
27214 +                      struct in6_addr *saddr, struct nx_info *nxi)
27215  {
27216         struct ipv6_saddr_score scores[2],
27217                                 *score = &scores[0], *hiscore = &scores[1];
27218 @@ -1180,6 +1182,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27219                                                dev->name);
27220                                 continue;
27221                         }
27222 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27223 +                               continue;
27224  
27225                         score->rule = -1;
27226                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27227 @@ -3048,7 +3052,10 @@ static void if6_seq_stop(struct seq_file
27228  static int if6_seq_show(struct seq_file *seq, void *v)
27229  {
27230         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27231 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27232 +
27233 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27234 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27235 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27236                    &ifp->addr,
27237                    ifp->idev->dev->ifindex,
27238                    ifp->prefix_len,
27239 @@ -3554,6 +3561,11 @@ static int in6_dump_addrs(struct inet6_d
27240         struct ifacaddr6 *ifaca;
27241         int err = 1;
27242         int ip_idx = *p_ip_idx;
27243 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27244 +
27245 +       /* disable ipv6 on non v6 guests */
27246 +       if (nxi && !nx_info_has_v6(nxi))
27247 +               return skb->len;
27248  
27249         read_lock_bh(&idev->lock);
27250         switch (type) {
27251 @@ -3564,6 +3576,8 @@ static int in6_dump_addrs(struct inet6_d
27252                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
27253                         if (++ip_idx < s_ip_idx)
27254                                 continue;
27255 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27256 +                                       continue;
27257                         err = inet6_fill_ifaddr(skb, ifa,
27258                                                 NETLINK_CB(cb->skb).pid,
27259                                                 cb->nlh->nlmsg_seq,
27260 @@ -3580,6 +3594,8 @@ static int in6_dump_addrs(struct inet6_d
27261                      ifmca = ifmca->next, ip_idx++) {
27262                         if (ip_idx < s_ip_idx)
27263                                 continue;
27264 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27265 +                                       continue;
27266                         err = inet6_fill_ifmcaddr(skb, ifmca,
27267                                                   NETLINK_CB(cb->skb).pid,
27268                                                   cb->nlh->nlmsg_seq,
27269 @@ -3595,6 +3611,8 @@ static int in6_dump_addrs(struct inet6_d
27270                      ifaca = ifaca->aca_next, ip_idx++) {
27271                         if (ip_idx < s_ip_idx)
27272                                 continue;
27273 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27274 +                                       continue;
27275                         err = inet6_fill_ifacaddr(skb, ifaca,
27276                                                   NETLINK_CB(cb->skb).pid,
27277                                                   cb->nlh->nlmsg_seq,
27278 @@ -3980,6 +3998,11 @@ static int inet6_dump_ifinfo(struct sk_b
27279         struct inet6_dev *idev;
27280         struct hlist_head *head;
27281         struct hlist_node *node;
27282 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27283 +
27284 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27285 +       if (skb->sk && skb->sk->sk_vx_info)
27286 +               return skb->len; */
27287  
27288         s_h = cb->args[0];
27289         s_idx = cb->args[1];
27290 @@ -3991,6 +4014,8 @@ static int inet6_dump_ifinfo(struct sk_b
27291                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
27292                         if (idx < s_idx)
27293                                 goto cont;
27294 +                       if (!v6_dev_in_nx_info(dev, nxi))
27295 +                               goto cont;
27296                         idev = __in6_dev_get(dev);
27297                         if (!idev)
27298                                 goto cont;
27299 diff -NurpP --minimal linux-3.0/net/ipv6/af_inet6.c linux-3.0-vs2.3.1-pre6/net/ipv6/af_inet6.c
27300 --- linux-3.0/net/ipv6/af_inet6.c       2011-07-22 11:18:13.000000000 +0200
27301 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/af_inet6.c  2011-07-19 00:44:39.000000000 +0200
27302 @@ -42,6 +42,8 @@
27303  #include <linux/netdevice.h>
27304  #include <linux/icmpv6.h>
27305  #include <linux/netfilter_ipv6.h>
27306 +#include <linux/vs_inet.h>
27307 +#include <linux/vs_inet6.h>
27308  
27309  #include <net/ip.h>
27310  #include <net/ipv6.h>
27311 @@ -160,9 +162,12 @@ lookup_protocol:
27312         }
27313  
27314         err = -EPERM;
27315 +       if ((protocol == IPPROTO_ICMPV6) &&
27316 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
27317 +               goto override;
27318         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
27319                 goto out_rcu_unlock;
27320 -
27321 +override:
27322         sock->ops = answer->ops;
27323         answer_prot = answer->prot;
27324         answer_no_check = answer->no_check;
27325 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
27326         struct inet_sock *inet = inet_sk(sk);
27327         struct ipv6_pinfo *np = inet6_sk(sk);
27328         struct net *net = sock_net(sk);
27329 +       struct nx_v6_sock_addr nsa;
27330         __be32 v4addr = 0;
27331         unsigned short snum;
27332         int addr_type = 0;
27333 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
27334         if (addr->sin6_family != AF_INET6)
27335                 return -EAFNOSUPPORT;
27336  
27337 +       err = v6_map_sock_addr(inet, addr, &nsa);
27338 +       if (err)
27339 +               return err;
27340 +
27341         addr_type = ipv6_addr_type(&addr->sin6_addr);
27342         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27343                 return -EINVAL;
27344 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
27345                 /* Reproduce AF_INET checks to make the bindings consistent */
27346                 v4addr = addr->sin6_addr.s6_addr32[3];
27347                 chk_addr_ret = inet_addr_type(net, v4addr);
27348 +
27349                 if (!sysctl_ip_nonlocal_bind &&
27350                     !(inet->freebind || inet->transparent) &&
27351                     v4addr != htonl(INADDR_ANY) &&
27352 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
27353                         err = -EADDRNOTAVAIL;
27354                         goto out;
27355                 }
27356 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27357 +                       err = -EADDRNOTAVAIL;
27358 +                       goto out;
27359 +               }
27360         } else {
27361                 if (addr_type != IPV6_ADDR_ANY) {
27362                         struct net_device *dev = NULL;
27363 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
27364                                 }
27365                         }
27366  
27367 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27368 +                               err = -EADDRNOTAVAIL;
27369 +                               goto out;
27370 +                       }
27371 +
27372                         /* ipv4 addr of the socket is invalid.  Only the
27373                          * unspecified and mapped address have a v4 equivalent.
27374                          */
27375 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
27376                 }
27377         }
27378  
27379 +       /* what's that for? */
27380 +       v6_set_sock_addr(inet, &nsa);
27381 +
27382         inet->inet_rcv_saddr = v4addr;
27383         inet->inet_saddr = v4addr;
27384  
27385 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
27386                         return -ENOTCONN;
27387                 sin->sin6_port = inet->inet_dport;
27388                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27389 +               /* FIXME: remap lback? */
27390                 if (np->sndflow)
27391                         sin->sin6_flowinfo = np->flow_label;
27392         } else {
27393 +               /* FIXME: remap lback? */
27394                 if (ipv6_addr_any(&np->rcv_saddr))
27395                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27396                 else
27397 diff -NurpP --minimal linux-3.0/net/ipv6/fib6_rules.c linux-3.0-vs2.3.1-pre6/net/ipv6/fib6_rules.c
27398 --- linux-3.0/net/ipv6/fib6_rules.c     2011-05-22 16:18:00.000000000 +0200
27399 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/fib6_rules.c        2011-06-10 22:11:24.000000000 +0200
27400 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
27401                                                ip6_dst_idev(&rt->dst)->dev,
27402                                                &flp6->daddr,
27403                                                rt6_flags2srcprefs(flags),
27404 -                                              &saddr))
27405 +                                              &saddr, NULL))
27406                                 goto again;
27407                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27408                                                r->src.plen))
27409 diff -NurpP --minimal linux-3.0/net/ipv6/inet6_hashtables.c linux-3.0-vs2.3.1-pre6/net/ipv6/inet6_hashtables.c
27410 --- linux-3.0/net/ipv6/inet6_hashtables.c       2011-05-22 16:18:00.000000000 +0200
27411 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/inet6_hashtables.c  2011-06-10 22:11:24.000000000 +0200
27412 @@ -16,6 +16,7 @@
27413  
27414  #include <linux/module.h>
27415  #include <linux/random.h>
27416 +#include <linux/vs_inet6.h>
27417  
27418  #include <net/inet_connection_sock.h>
27419  #include <net/inet_hashtables.h>
27420 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
27421         unsigned int slot = hash & hashinfo->ehash_mask;
27422         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
27423  
27424 -
27425         rcu_read_lock();
27426  begin:
27427         sk_nulls_for_each_rcu(sk, node, &head->chain) {
27428 @@ -94,7 +94,7 @@ begin:
27429                                 sock_put(sk);
27430                                 goto begin;
27431                         }
27432 -               goto out;
27433 +                       goto out;
27434                 }
27435         }
27436         if (get_nulls_value(node) != slot)
27437 @@ -140,6 +140,9 @@ static inline int compute_score(struct s
27438                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27439                                 return -1;
27440                         score++;
27441 +               } else {
27442 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27443 +                               return -1;
27444                 }
27445                 if (sk->sk_bound_dev_if) {
27446                         if (sk->sk_bound_dev_if != dif)
27447 diff -NurpP --minimal linux-3.0/net/ipv6/ip6_output.c linux-3.0-vs2.3.1-pre6/net/ipv6/ip6_output.c
27448 --- linux-3.0/net/ipv6/ip6_output.c     2011-07-22 11:18:13.000000000 +0200
27449 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/ip6_output.c        2011-06-16 14:16:51.000000000 +0200
27450 @@ -933,7 +933,8 @@ static int ip6_dst_lookup_tail(struct so
27451                 struct rt6_info *rt = (struct rt6_info *) *dst;
27452                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
27453                                           sk ? inet6_sk(sk)->srcprefs : 0,
27454 -                                         &fl6->saddr);
27455 +                                         &fl6->saddr,
27456 +                                         sk ? sk->sk_nx_info : NULL);
27457                 if (err)
27458                         goto out_err_release;
27459         }
27460 diff -NurpP --minimal linux-3.0/net/ipv6/ndisc.c linux-3.0-vs2.3.1-pre6/net/ipv6/ndisc.c
27461 --- linux-3.0/net/ipv6/ndisc.c  2011-07-22 11:18:13.000000000 +0200
27462 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/ndisc.c     2011-06-10 22:11:24.000000000 +0200
27463 @@ -597,7 +597,7 @@ static void ndisc_send_na(struct net_dev
27464         } else {
27465                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27466                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27467 -                                      &tmpaddr))
27468 +                                      &tmpaddr, NULL))
27469                         return;
27470                 src_addr = &tmpaddr;
27471         }
27472 diff -NurpP --minimal linux-3.0/net/ipv6/raw.c linux-3.0-vs2.3.1-pre6/net/ipv6/raw.c
27473 --- linux-3.0/net/ipv6/raw.c    2011-07-22 11:18:13.000000000 +0200
27474 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/raw.c       2011-06-10 22:11:24.000000000 +0200
27475 @@ -30,6 +30,7 @@
27476  #include <linux/icmpv6.h>
27477  #include <linux/netfilter.h>
27478  #include <linux/netfilter_ipv6.h>
27479 +#include <linux/vs_inet6.h>
27480  #include <linux/skbuff.h>
27481  #include <linux/compat.h>
27482  #include <asm/uaccess.h>
27483 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
27484                                 goto out_unlock;
27485                 }
27486  
27487 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27488 +                       err = -EADDRNOTAVAIL;
27489 +                       if (dev)
27490 +                               dev_put(dev);
27491 +                       goto out;
27492 +               }
27493 +
27494                 /* ipv4 addr of the socket is invalid.  Only the
27495                  * unspecified and mapped address have a v4 equivalent.
27496                  */
27497 diff -NurpP --minimal linux-3.0/net/ipv6/route.c linux-3.0-vs2.3.1-pre6/net/ipv6/route.c
27498 --- linux-3.0/net/ipv6/route.c  2011-07-22 11:18:13.000000000 +0200
27499 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/route.c     2011-07-19 00:44:39.000000000 +0200
27500 @@ -54,6 +54,7 @@
27501  #include <net/xfrm.h>
27502  #include <net/netevent.h>
27503  #include <net/netlink.h>
27504 +#include <linux/vs_inet6.h>
27505  
27506  #include <asm/uaccess.h>
27507  
27508 @@ -2050,15 +2051,17 @@ int ip6_route_get_saddr(struct net *net,
27509                         struct rt6_info *rt,
27510                         const struct in6_addr *daddr,
27511                         unsigned int prefs,
27512 -                       struct in6_addr *saddr)
27513 +                       struct in6_addr *saddr,
27514 +                       struct nx_info *nxi)
27515  {
27516         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
27517         int err = 0;
27518 -       if (rt->rt6i_prefsrc.plen)
27519 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
27520 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
27521                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
27522         else
27523                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27524 -                                        daddr, prefs, saddr);
27525 +                                        daddr, prefs, saddr, nxi);
27526         return err;
27527  }
27528  
27529 @@ -2387,7 +2390,8 @@ static int rt6_fill_node(struct net *net
27530                         NLA_PUT_U32(skb, RTA_IIF, iif);
27531         } else if (dst) {
27532                 struct in6_addr saddr_buf;
27533 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
27534 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
27535 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27536                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27537         }
27538  
27539 diff -NurpP --minimal linux-3.0/net/ipv6/tcp_ipv6.c linux-3.0-vs2.3.1-pre6/net/ipv6/tcp_ipv6.c
27540 --- linux-3.0/net/ipv6/tcp_ipv6.c       2011-07-22 11:18:13.000000000 +0200
27541 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/tcp_ipv6.c  2011-06-22 12:39:16.000000000 +0200
27542 @@ -69,6 +69,7 @@
27543  
27544  #include <linux/crypto.h>
27545  #include <linux/scatterlist.h>
27546 +#include <linux/vs_inet6.h>
27547  
27548  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27549  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27550 @@ -161,8 +162,15 @@ static int tcp_v6_connect(struct sock *s
27551          *      connect() to INADDR_ANY means loopback (BSD'ism).
27552          */
27553  
27554 -       if(ipv6_addr_any(&usin->sin6_addr))
27555 -               usin->sin6_addr.s6_addr[15] = 0x1;
27556 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27557 +               struct nx_info *nxi =  sk->sk_nx_info;
27558 +
27559 +               if (nxi && nx_info_has_v6(nxi))
27560 +                       /* FIXME: remap lback? */
27561 +                       usin->sin6_addr = nxi->v6.ip;
27562 +               else
27563 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27564 +       }
27565  
27566         addr_type = ipv6_addr_type(&usin->sin6_addr);
27567  
27568 diff -NurpP --minimal linux-3.0/net/ipv6/udp.c linux-3.0-vs2.3.1-pre6/net/ipv6/udp.c
27569 --- linux-3.0/net/ipv6/udp.c    2011-07-22 11:18:13.000000000 +0200
27570 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/udp.c       2011-07-19 00:44:39.000000000 +0200
27571 @@ -45,41 +45,67 @@
27572  #include <net/tcp_states.h>
27573  #include <net/ip6_checksum.h>
27574  #include <net/xfrm.h>
27575 +#include <linux/vs_inet6.h>
27576  
27577  #include <linux/proc_fs.h>
27578  #include <linux/seq_file.h>
27579  #include "udp_impl.h"
27580  
27581 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27582 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27583  {
27584 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27585 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
27586         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27587 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
27588 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
27589         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
27590 -       int sk_ipv6only = ipv6_only_sock(sk);
27591 +       int sk1_ipv6only = ipv6_only_sock(sk1);
27592         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27593 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27594 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
27595         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27596  
27597         /* if both are mapped, treat as IPv4 */
27598 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
27599 -               return (!sk2_ipv6only &&
27600 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
27601 +               if (!sk2_ipv6only &&
27602                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
27603 -                         sk1_rcv_saddr == sk2_rcv_saddr));
27604 +                         sk1_rcv_saddr == sk2_rcv_saddr))
27605 +                       goto vs_v4;
27606 +               else
27607 +                       return 0;
27608 +       }
27609  
27610         if (addr_type2 == IPV6_ADDR_ANY &&
27611             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27612 -               return 1;
27613 +               goto vs;
27614  
27615         if (addr_type == IPV6_ADDR_ANY &&
27616 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27617 -               return 1;
27618 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27619 +               goto vs;
27620  
27621         if (sk2_rcv_saddr6 &&
27622 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27623 -               return 1;
27624 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
27625 +               goto vs;
27626  
27627         return 0;
27628 +
27629 +vs_v4:
27630 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
27631 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
27632 +       if (!sk2_rcv_saddr)
27633 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
27634 +       if (!sk1_rcv_saddr)
27635 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
27636 +       return 1;
27637 +vs:
27638 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
27639 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
27640 +       else if (addr_type2 == IPV6_ADDR_ANY)
27641 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
27642 +       else if (addr_type == IPV6_ADDR_ANY) {
27643 +               if (addr_type2 == IPV6_ADDR_MAPPED)
27644 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
27645 +               else
27646 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
27647 +       }
27648 +       return 1;
27649  }
27650  
27651  static unsigned int udp6_portaddr_hash(struct net *net,
27652 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
27653                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27654                                 return -1;
27655                         score++;
27656 +               } else {
27657 +                       /* block non nx_info ips */
27658 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27659 +                               return -1;
27660                 }
27661                 if (!ipv6_addr_any(&np->daddr)) {
27662                         if (!ipv6_addr_equal(&np->daddr, saddr))
27663 diff -NurpP --minimal linux-3.0/net/ipv6/xfrm6_policy.c linux-3.0-vs2.3.1-pre6/net/ipv6/xfrm6_policy.c
27664 --- linux-3.0/net/ipv6/xfrm6_policy.c   2011-07-22 11:18:13.000000000 +0200
27665 +++ linux-3.0-vs2.3.1-pre6/net/ipv6/xfrm6_policy.c      2011-06-10 22:11:24.000000000 +0200
27666 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
27667         dev = ip6_dst_idev(dst)->dev;
27668         ipv6_dev_get_saddr(dev_net(dev), dev,
27669                            (struct in6_addr *)&daddr->a6, 0,
27670 -                          (struct in6_addr *)&saddr->a6);
27671 +                          (struct in6_addr *)&saddr->a6, NULL);
27672         dst_release(dst);
27673         return 0;
27674  }
27675 diff -NurpP --minimal linux-3.0/net/netfilter/ipvs/ip_vs_xmit.c linux-3.0-vs2.3.1-pre6/net/netfilter/ipvs/ip_vs_xmit.c
27676 --- linux-3.0/net/netfilter/ipvs/ip_vs_xmit.c   2011-07-22 11:18:13.000000000 +0200
27677 +++ linux-3.0-vs2.3.1-pre6/net/netfilter/ipvs/ip_vs_xmit.c      2011-07-22 15:27:52.000000000 +0200
27678 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
27679                 return dst;
27680         if (ipv6_addr_any(&fl6.saddr) &&
27681             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
27682 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
27683 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
27684                 goto out_err;
27685         if (do_xfrm) {
27686                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
27687 diff -NurpP --minimal linux-3.0/net/netlink/af_netlink.c linux-3.0-vs2.3.1-pre6/net/netlink/af_netlink.c
27688 --- linux-3.0/net/netlink/af_netlink.c  2011-07-22 11:18:13.000000000 +0200
27689 +++ linux-3.0-vs2.3.1-pre6/net/netlink/af_netlink.c     2011-06-10 22:11:24.000000000 +0200
27690 @@ -55,6 +55,9 @@
27691  #include <linux/types.h>
27692  #include <linux/audit.h>
27693  #include <linux/mutex.h>
27694 +#include <linux/vs_context.h>
27695 +#include <linux/vs_network.h>
27696 +#include <linux/vs_limit.h>
27697  
27698  #include <net/net_namespace.h>
27699  #include <net/sock.h>
27700 @@ -1907,6 +1910,8 @@ static struct sock *netlink_seq_socket_i
27701                         sk_for_each(s, node, &hash->table[j]) {
27702                                 if (sock_net(s) != seq_file_net(seq))
27703                                         continue;
27704 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27705 +                                       continue;
27706                                 if (off == pos) {
27707                                         iter->link = i;
27708                                         iter->hash_idx = j;
27709 @@ -1941,7 +1946,8 @@ static void *netlink_seq_next(struct seq
27710         s = v;
27711         do {
27712                 s = sk_next(s);
27713 -       } while (s && sock_net(s) != seq_file_net(seq));
27714 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27715 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27716         if (s)
27717                 return s;
27718  
27719 @@ -1953,7 +1959,8 @@ static void *netlink_seq_next(struct seq
27720  
27721                 for (; j <= hash->mask; j++) {
27722                         s = sk_head(&hash->table[j]);
27723 -                       while (s && sock_net(s) != seq_file_net(seq))
27724 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27725 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27726                                 s = sk_next(s);
27727                         if (s) {
27728                                 iter->link = i;
27729 diff -NurpP --minimal linux-3.0/net/socket.c linux-3.0-vs2.3.1-pre6/net/socket.c
27730 --- linux-3.0/net/socket.c      2011-07-22 11:18:13.000000000 +0200
27731 +++ linux-3.0-vs2.3.1-pre6/net/socket.c 2011-06-16 14:16:51.000000000 +0200
27732 @@ -98,6 +98,10 @@
27733  
27734  #include <net/sock.h>
27735  #include <linux/netfilter.h>
27736 +#include <linux/vs_base.h>
27737 +#include <linux/vs_socket.h>
27738 +#include <linux/vs_inet.h>
27739 +#include <linux/vs_inet6.h>
27740  
27741  #include <linux/if_tun.h>
27742  #include <linux/ipv6_route.h>
27743 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
27744                                        struct msghdr *msg, size_t size)
27745  {
27746         struct sock_iocb *si = kiocb_to_siocb(iocb);
27747 +       size_t len;
27748  
27749         sock_update_classid(sock->sk);
27750  
27751 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
27752         si->msg = msg;
27753         si->size = size;
27754  
27755 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27756 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27757 +       if (sock->sk) {
27758 +               if (len == size)
27759 +                       vx_sock_send(sock->sk, size);
27760 +               else
27761 +                       vx_sock_fail(sock->sk, size);
27762 +       }
27763 +       vxdprintk(VXD_CBIT(net, 7),
27764 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27765 +               sock, sock->sk,
27766 +               (sock->sk)?sock->sk->sk_nx_info:0,
27767 +               (sock->sk)?sock->sk->sk_vx_info:0,
27768 +               (sock->sk)?sock->sk->sk_xid:0,
27769 +               (sock->sk)?sock->sk->sk_nid:0,
27770 +               (unsigned int)size, len);
27771 +       return len;
27772  }
27773  
27774  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
27775 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
27776                                        struct msghdr *msg, size_t size, int flags)
27777  {
27778         struct sock_iocb *si = kiocb_to_siocb(iocb);
27779 +       int len;
27780  
27781         sock_update_classid(sock->sk);
27782  
27783 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
27784         si->size = size;
27785         si->flags = flags;
27786  
27787 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27788 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27789 +       if ((len >= 0) && sock->sk)
27790 +               vx_sock_recv(sock->sk, len);
27791 +       vxdprintk(VXD_CBIT(net, 7),
27792 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27793 +               sock, sock->sk,
27794 +               (sock->sk)?sock->sk->sk_nx_info:0,
27795 +               (sock->sk)?sock->sk->sk_vx_info:0,
27796 +               (sock->sk)?sock->sk->sk_xid:0,
27797 +               (sock->sk)?sock->sk->sk_nid:0,
27798 +               (unsigned int)size, len);
27799 +       return len;
27800  }
27801  
27802  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27803 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
27804         if (type < 0 || type >= SOCK_MAX)
27805                 return -EINVAL;
27806  
27807 +       if (!nx_check(0, VS_ADMIN)) {
27808 +               if (family == PF_INET && !current_nx_info_has_v4())
27809 +                       return -EAFNOSUPPORT;
27810 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27811 +                       return -EAFNOSUPPORT;
27812 +       }
27813 +
27814         /* Compatibility.
27815  
27816            This uglymoron is moved from INET layer to here to avoid
27817 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
27818         if (retval < 0)
27819                 goto out;
27820  
27821 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27822         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27823         if (retval < 0)
27824                 goto out_release;
27825 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
27826         err = sock_create(family, type, protocol, &sock1);
27827         if (err < 0)
27828                 goto out;
27829 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27830  
27831         err = sock_create(family, type, protocol, &sock2);
27832         if (err < 0)
27833                 goto out_release_1;
27834 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27835  
27836         err = sock1->ops->socketpair(sock1, sock2);
27837         if (err < 0)
27838 diff -NurpP --minimal linux-3.0/net/sunrpc/auth.c linux-3.0-vs2.3.1-pre6/net/sunrpc/auth.c
27839 --- linux-3.0/net/sunrpc/auth.c 2011-07-22 11:18:13.000000000 +0200
27840 +++ linux-3.0-vs2.3.1-pre6/net/sunrpc/auth.c    2011-06-10 22:11:24.000000000 +0200
27841 @@ -14,6 +14,7 @@
27842  #include <linux/hash.h>
27843  #include <linux/sunrpc/clnt.h>
27844  #include <linux/spinlock.h>
27845 +#include <linux/vs_tag.h>
27846  
27847  #ifdef RPC_DEBUG
27848  # define RPCDBG_FACILITY       RPCDBG_AUTH
27849 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27850         memset(&acred, 0, sizeof(acred));
27851         acred.uid = cred->fsuid;
27852         acred.gid = cred->fsgid;
27853 +       acred.tag = dx_current_tag();
27854         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
27855  
27856         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
27857 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
27858         struct auth_cred acred = {
27859                 .uid = 0,
27860                 .gid = 0,
27861 +               .tag = dx_current_tag(),
27862         };
27863  
27864         dprintk("RPC: %5u looking up %s cred\n",
27865 diff -NurpP --minimal linux-3.0/net/sunrpc/auth_unix.c linux-3.0-vs2.3.1-pre6/net/sunrpc/auth_unix.c
27866 --- linux-3.0/net/sunrpc/auth_unix.c    2010-10-21 13:08:01.000000000 +0200
27867 +++ linux-3.0-vs2.3.1-pre6/net/sunrpc/auth_unix.c       2011-06-10 22:11:24.000000000 +0200
27868 @@ -12,12 +12,14 @@
27869  #include <linux/module.h>
27870  #include <linux/sunrpc/clnt.h>
27871  #include <linux/sunrpc/auth.h>
27872 +#include <linux/vs_tag.h>
27873  
27874  #define NFS_NGROUPS    16
27875  
27876  struct unx_cred {
27877         struct rpc_cred         uc_base;
27878         gid_t                   uc_gid;
27879 +       tag_t                   uc_tag;
27880         gid_t                   uc_gids[NFS_NGROUPS];
27881  };
27882  #define uc_uid                 uc_base.cr_uid
27883 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
27884                 groups = NFS_NGROUPS;
27885  
27886         cred->uc_gid = acred->gid;
27887 +       cred->uc_tag = acred->tag;
27888         for (i = 0; i < groups; i++)
27889                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
27890         if (i < NFS_NGROUPS)
27891 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
27892         unsigned int i;
27893  
27894  
27895 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
27896 +       if (cred->uc_uid != acred->uid ||
27897 +               cred->uc_gid != acred->gid ||
27898 +               cred->uc_tag != acred->tag)
27899                 return 0;
27900  
27901         if (acred->group_info != NULL)
27902 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
27903         struct rpc_clnt *clnt = task->tk_client;
27904         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
27905         __be32          *base, *hold;
27906 -       int             i;
27907 +       int             i, tag;
27908  
27909         *p++ = htonl(RPC_AUTH_UNIX);
27910         base = p++;
27911 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
27912          * Copy the UTS nodename captured when the client was created.
27913          */
27914         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
27915 +       tag = task->tk_client->cl_tag;
27916  
27917 -       *p++ = htonl((u32) cred->uc_uid);
27918 -       *p++ = htonl((u32) cred->uc_gid);
27919 +       *p++ = htonl((u32) TAGINO_UID(tag,
27920 +               cred->uc_uid, cred->uc_tag));
27921 +       *p++ = htonl((u32) TAGINO_GID(tag,
27922 +               cred->uc_gid, cred->uc_tag));
27923         hold = p++;
27924         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27925                 *p++ = htonl((u32) cred->uc_gids[i]);
27926 diff -NurpP --minimal linux-3.0/net/sunrpc/clnt.c linux-3.0-vs2.3.1-pre6/net/sunrpc/clnt.c
27927 --- linux-3.0/net/sunrpc/clnt.c 2011-07-22 11:18:13.000000000 +0200
27928 +++ linux-3.0-vs2.3.1-pre6/net/sunrpc/clnt.c    2011-07-01 11:35:35.000000000 +0200
27929 @@ -31,6 +31,7 @@
27930  #include <linux/in.h>
27931  #include <linux/in6.h>
27932  #include <linux/un.h>
27933 +#include <linux/vs_cvirt.h>
27934  
27935  #include <linux/sunrpc/clnt.h>
27936  #include <linux/sunrpc/rpc_pipe_fs.h>
27937 @@ -362,6 +363,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27938         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
27939                 clnt->cl_chatty = 1;
27940  
27941 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27942 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27943 +               clnt->cl_tag = 1; */
27944         return clnt;
27945  }
27946  EXPORT_SYMBOL_GPL(rpc_create);
27947 diff -NurpP --minimal linux-3.0/net/unix/af_unix.c linux-3.0-vs2.3.1-pre6/net/unix/af_unix.c
27948 --- linux-3.0/net/unix/af_unix.c        2011-07-22 11:18:13.000000000 +0200
27949 +++ linux-3.0-vs2.3.1-pre6/net/unix/af_unix.c   2011-06-10 22:11:24.000000000 +0200
27950 @@ -114,6 +114,8 @@
27951  #include <linux/mount.h>
27952  #include <net/checksum.h>
27953  #include <linux/security.h>
27954 +#include <linux/vs_context.h>
27955 +#include <linux/vs_limit.h>
27956  
27957  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
27958  static DEFINE_SPINLOCK(unix_table_lock);
27959 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
27960                 if (!net_eq(sock_net(s), net))
27961                         continue;
27962  
27963 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27964 +                       continue;
27965                 if (u->addr->len == len &&
27966                     !memcmp(u->addr->name, sunname, len))
27967                         goto found;
27968 @@ -2208,6 +2212,8 @@ static struct sock *unix_seq_idx(struct 
27969         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
27970                 if (sock_net(s) != seq_file_net(seq))
27971                         continue;
27972 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27973 +                       continue;
27974                 if (off == pos)
27975                         return s;
27976                 ++off;
27977 @@ -2232,7 +2238,8 @@ static void *unix_seq_next(struct seq_fi
27978                 sk = first_unix_socket(&iter->i);
27979         else
27980                 sk = next_unix_socket(&iter->i, sk);
27981 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
27982 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
27983 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
27984                 sk = next_unix_socket(&iter->i, sk);
27985         return sk;
27986  }
27987 diff -NurpP --minimal linux-3.0/scripts/checksyscalls.sh linux-3.0-vs2.3.1-pre6/scripts/checksyscalls.sh
27988 --- linux-3.0/scripts/checksyscalls.sh  2011-03-15 18:07:46.000000000 +0100
27989 +++ linux-3.0-vs2.3.1-pre6/scripts/checksyscalls.sh     2011-06-10 22:11:24.000000000 +0200
27990 @@ -193,7 +193,6 @@ cat << EOF
27991  #define __IGNORE_afs_syscall
27992  #define __IGNORE_getpmsg
27993  #define __IGNORE_putpmsg
27994 -#define __IGNORE_vserver
27995  EOF
27996  }
27997  
27998 diff -NurpP --minimal linux-3.0/security/commoncap.c linux-3.0-vs2.3.1-pre6/security/commoncap.c
27999 --- linux-3.0/security/commoncap.c      2011-07-22 11:18:14.000000000 +0200
28000 +++ linux-3.0-vs2.3.1-pre6/security/commoncap.c 2011-06-16 14:16:51.000000000 +0200
28001 @@ -62,6 +62,7 @@ int cap_netlink_recv(struct sk_buff *skb
28002                 return -EPERM;
28003         return 0;
28004  }
28005 +
28006  EXPORT_SYMBOL(cap_netlink_recv);
28007  
28008  /**
28009 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
28010  int cap_capable(struct task_struct *tsk, const struct cred *cred,
28011                 struct user_namespace *targ_ns, int cap, int audit)
28012  {
28013 +       struct vx_info *vxi = tsk->vx_info;
28014 +
28015         for (;;) {
28016                 /* The creator of the user namespace has all caps. */
28017                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
28018                         return 0;
28019  
28020                 /* Do we have the necessary capabilities? */
28021 -               if (targ_ns == cred->user->user_ns)
28022 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
28023 +               if (targ_ns == cred->user->user_ns) {
28024 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28025 +                           cap_raised(cred->cap_effective, cap))
28026 +                               return 0;
28027 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
28028 +               }
28029  
28030                 /* Have we tried all of the parent namespaces? */
28031                 if (targ_ns == &init_user_ns)
28032 @@ -611,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
28033  
28034         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28035                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
28036 -           !capable(CAP_SYS_ADMIN))
28037 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28038                 return -EPERM;
28039         return 0;
28040  }
28041 @@ -637,7 +644,7 @@ int cap_inode_removexattr(struct dentry 
28042  
28043         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28044                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
28045 -           !capable(CAP_SYS_ADMIN))
28046 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28047                 return -EPERM;
28048         return 0;
28049  }
28050 @@ -971,3 +978,4 @@ int cap_file_mmap(struct file *file, uns
28051         }
28052         return ret;
28053  }
28054 +
28055 diff -NurpP --minimal linux-3.0/security/selinux/hooks.c linux-3.0-vs2.3.1-pre6/security/selinux/hooks.c
28056 --- linux-3.0/security/selinux/hooks.c  2011-07-22 11:18:14.000000000 +0200
28057 +++ linux-3.0-vs2.3.1-pre6/security/selinux/hooks.c     2011-06-15 02:40:14.000000000 +0200
28058 @@ -67,7 +67,6 @@
28059  #include <linux/dccp.h>
28060  #include <linux/quota.h>
28061  #include <linux/un.h>          /* for Unix socket types */
28062 -#include <net/af_unix.h>       /* for Unix socket types */
28063  #include <linux/parser.h>
28064  #include <linux/nfs_mount.h>
28065  #include <net/ipv6.h>
This page took 2.444209 seconds and 4 git commands to generate.