aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2012-11-07 10:10:02 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2012-11-07 10:10:02 +0000
commit2f93ec80e1baa3766f9074463b730d2b1ea6c68e (patch)
treee93fcc6505eda5a7f1f4e473f92da1cc62cd30db
parent94c5d09f454a624f9a0eec01be68e36d0c5a47c8 (diff)
downloadalpine_aports-2f93ec80e1baa3766f9074463b730d2b1ea6c68e.tar.bz2
alpine_aports-2f93ec80e1baa3766f9074463b730d2b1ea6c68e.tar.xz
alpine_aports-2f93ec80e1baa3766f9074463b730d2b1ea6c68e.zip
main/linux-vserver: enable IR and more DVB drivers, upgrade to vs2.3.4.3.1
-rw-r--r--main/linux-vserver/APKBUILD10
-rw-r--r--main/linux-vserver/kernelconfig.x86138
-rw-r--r--main/linux-vserver/kernelconfig.x86_64138
-rw-r--r--main/linux-vserver/patch-3.6.6-vs2.3.4.3.1-noxfs-nocow.diff25752
4 files changed, 26029 insertions, 9 deletions
diff --git a/main/linux-vserver/APKBUILD b/main/linux-vserver/APKBUILD
index d333eb7358..0208ff04bc 100644
--- a/main/linux-vserver/APKBUILD
+++ b/main/linux-vserver/APKBUILD
@@ -3,8 +3,8 @@
3_flavor=vserver 3_flavor=vserver
4pkgname=linux-${_flavor} 4pkgname=linux-${_flavor}
5pkgver=3.6.6 5pkgver=3.6.6
6pkgrel=0 6pkgrel=1
7_vsver=vs2.3.4.3-noxfs-nocow 7_vsver=vs2.3.4.3.1-noxfs-nocow
8 8
9if [ "${pkgver##*.*.*}" = "$pkgver" ]; then 9if [ "${pkgver##*.*.*}" = "$pkgver" ]; then
10 _kernver=$pkgver 10 _kernver=$pkgver
@@ -137,6 +137,6 @@ dev() {
137 137
138md5sums="1a1760420eac802c541a20ab51a093d1 linux-3.6.tar.xz 138md5sums="1a1760420eac802c541a20ab51a093d1 linux-3.6.tar.xz
13911d6d8749d4612a77f43f0531c0f2824 patch-3.6.6.xz 13911d6d8749d4612a77f43f0531c0f2824 patch-3.6.6.xz
1405be3e577aa4bd603b2b45d8e2a597f38 patch-3.6.6-vs2.3.4.3-noxfs-nocow.diff 1401e24532ef919846f5711fb42565ada15 patch-3.6.6-vs2.3.4.3.1-noxfs-nocow.diff
141207e74fd8e1ed06be50f2c149b3b1020 kernelconfig.x86 14161ebfebc08753b2bbd1d52a71da62395 kernelconfig.x86
142c7024467717b4f4fc9c6972a9992a4e6 kernelconfig.x86_64" 1422a648d04d03e44334c8dcf48f8ebe4dc kernelconfig.x86_64"
diff --git a/main/linux-vserver/kernelconfig.x86 b/main/linux-vserver/kernelconfig.x86
index bdc63077b8..320c459707 100644
--- a/main/linux-vserver/kernelconfig.x86
+++ b/main/linux-vserver/kernelconfig.x86
@@ -3236,7 +3236,7 @@ CONFIG_MEDIA_CAMERA_SUPPORT=y
3236# CONFIG_MEDIA_ANALOG_TV_SUPPORT is not set 3236# CONFIG_MEDIA_ANALOG_TV_SUPPORT is not set
3237CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y 3237CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
3238# CONFIG_MEDIA_RADIO_SUPPORT is not set 3238# CONFIG_MEDIA_RADIO_SUPPORT is not set
3239# CONFIG_MEDIA_RC_SUPPORT is not set 3239CONFIG_MEDIA_RC_SUPPORT=y
3240CONFIG_MEDIA_CONTROLLER=y 3240CONFIG_MEDIA_CONTROLLER=y
3241CONFIG_VIDEO_DEV=m 3241CONFIG_VIDEO_DEV=m
3242CONFIG_VIDEO_V4L2_COMMON=m 3242CONFIG_VIDEO_V4L2_COMMON=m
@@ -3249,10 +3249,55 @@ CONFIG_DVB_NET=y
3249# 3249#
3250CONFIG_VIDEO_SAA7146=m 3250CONFIG_VIDEO_SAA7146=m
3251CONFIG_VIDEO_SAA7146_VV=m 3251CONFIG_VIDEO_SAA7146_VV=m
3252# CONFIG_MEDIA_ATTACH is not set 3252CONFIG_RC_CORE=m
3253CONFIG_RC_MAP=m
3254CONFIG_RC_DECODERS=y
3255# CONFIG_LIRC is not set
3256CONFIG_IR_NEC_DECODER=m
3257CONFIG_IR_RC5_DECODER=m
3258CONFIG_IR_RC6_DECODER=m
3259CONFIG_IR_JVC_DECODER=m
3260CONFIG_IR_SONY_DECODER=m
3261CONFIG_IR_RC5_SZ_DECODER=m
3262CONFIG_IR_SANYO_DECODER=m
3263CONFIG_IR_MCE_KBD_DECODER=m
3264CONFIG_RC_DEVICES=y
3265CONFIG_RC_ATI_REMOTE=m
3266CONFIG_IR_ENE=m
3267CONFIG_IR_IMON=m
3268CONFIG_IR_MCEUSB=m
3269CONFIG_IR_ITE_CIR=m
3270CONFIG_IR_FINTEK=m
3271CONFIG_IR_NUVOTON=m
3272CONFIG_IR_REDRAT3=m
3273CONFIG_IR_STREAMZAP=m
3274CONFIG_IR_WINBOND_CIR=m
3275CONFIG_IR_IGUANA=m
3276CONFIG_RC_LOOPBACK=m
3277CONFIG_IR_GPIO_CIR=m
3278CONFIG_MEDIA_ATTACH=y
3253CONFIG_MEDIA_TUNER_SIMPLE=m 3279CONFIG_MEDIA_TUNER_SIMPLE=m
3280CONFIG_MEDIA_TUNER_TDA827X=m
3281CONFIG_MEDIA_TUNER_TDA18271=m
3254CONFIG_MEDIA_TUNER_TDA9887=m 3282CONFIG_MEDIA_TUNER_TDA9887=m
3283CONFIG_MEDIA_TUNER_MT2060=m
3284CONFIG_MEDIA_TUNER_MT2063=m
3285CONFIG_MEDIA_TUNER_MT2266=m
3255CONFIG_MEDIA_TUNER_MT2131=m 3286CONFIG_MEDIA_TUNER_MT2131=m
3287CONFIG_MEDIA_TUNER_QT1010=m
3288CONFIG_MEDIA_TUNER_XC2028=m
3289CONFIG_MEDIA_TUNER_XC5000=m
3290CONFIG_MEDIA_TUNER_XC4000=m
3291CONFIG_MEDIA_TUNER_MXL5005S=m
3292CONFIG_MEDIA_TUNER_MXL5007T=m
3293CONFIG_MEDIA_TUNER_MC44S803=m
3294CONFIG_MEDIA_TUNER_MAX2165=m
3295CONFIG_MEDIA_TUNER_TDA18218=m
3296CONFIG_MEDIA_TUNER_FC0011=m
3297CONFIG_MEDIA_TUNER_FC0012=m
3298CONFIG_MEDIA_TUNER_FC0013=m
3299CONFIG_MEDIA_TUNER_TDA18212=m
3300CONFIG_MEDIA_TUNER_TUA9001=m
3256CONFIG_VIDEO_V4L2=m 3301CONFIG_VIDEO_V4L2=m
3257CONFIG_VIDEOBUF_GEN=m 3302CONFIG_VIDEOBUF_GEN=m
3258CONFIG_VIDEOBUF_DMA_SG=m 3303CONFIG_VIDEOBUF_DMA_SG=m
@@ -3267,6 +3312,7 @@ CONFIG_VIDEO_CAPTURE_DRIVERS=y
3267# CONFIG_VIDEO_ADV_DEBUG is not set 3312# CONFIG_VIDEO_ADV_DEBUG is not set
3268# CONFIG_VIDEO_FIXED_MINOR_RANGES is not set 3313# CONFIG_VIDEO_FIXED_MINOR_RANGES is not set
3269# CONFIG_VIDEO_HELPER_CHIPS_AUTO is not set 3314# CONFIG_VIDEO_HELPER_CHIPS_AUTO is not set
3315CONFIG_VIDEO_IR_I2C=m
3270 3316
3271# 3317#
3272# Encoders, decoders, sensors and other helper chips 3318# Encoders, decoders, sensors and other helper chips
@@ -3434,6 +3480,7 @@ CONFIG_USB_SN9C102=m
3434CONFIG_VIDEO_EM28XX=m 3480CONFIG_VIDEO_EM28XX=m
3435CONFIG_VIDEO_EM28XX_ALSA=m 3481CONFIG_VIDEO_EM28XX_ALSA=m
3436# CONFIG_VIDEO_EM28XX_DVB is not set 3482# CONFIG_VIDEO_EM28XX_DVB is not set
3483CONFIG_VIDEO_EM28XX_RC=m
3437# CONFIG_V4L_ISA_PARPORT_DRIVERS is not set 3484# CONFIG_V4L_ISA_PARPORT_DRIVERS is not set
3438# CONFIG_V4L_PLATFORM_DRIVERS is not set 3485# CONFIG_V4L_PLATFORM_DRIVERS is not set
3439CONFIG_V4L_MEM2MEM_DRIVERS=y 3486CONFIG_V4L_MEM2MEM_DRIVERS=y
@@ -3450,14 +3497,61 @@ CONFIG_DVB_AV7110=m
3450CONFIG_DVB_AV7110_OSD=y 3497CONFIG_DVB_AV7110_OSD=y
3451CONFIG_DVB_BUDGET_CORE=m 3498CONFIG_DVB_BUDGET_CORE=m
3452CONFIG_DVB_BUDGET=m 3499CONFIG_DVB_BUDGET=m
3500CONFIG_DVB_BUDGET_CI=m
3453CONFIG_DVB_BUDGET_AV=m 3501CONFIG_DVB_BUDGET_AV=m
3454CONFIG_DVB_BUDGET_PATCH=m 3502CONFIG_DVB_BUDGET_PATCH=m
3455 3503
3456# 3504#
3457# Supported USB Adapters 3505# Supported USB Adapters
3458# 3506#
3507CONFIG_DVB_USB=m
3508# CONFIG_DVB_USB_DEBUG is not set
3509CONFIG_DVB_USB_A800=m
3510CONFIG_DVB_USB_DIBUSB_MB=m
3511# CONFIG_DVB_USB_DIBUSB_MB_FAULTY is not set
3512CONFIG_DVB_USB_DIBUSB_MC=m
3513CONFIG_DVB_USB_DIB0700=m
3514CONFIG_DVB_USB_UMT_010=m
3515CONFIG_DVB_USB_CXUSB=m
3516CONFIG_DVB_USB_M920X=m
3517CONFIG_DVB_USB_GL861=m
3518CONFIG_DVB_USB_AU6610=m
3519CONFIG_DVB_USB_DIGITV=m
3520CONFIG_DVB_USB_VP7045=m
3521CONFIG_DVB_USB_VP702X=m
3522CONFIG_DVB_USB_GP8PSK=m
3523CONFIG_DVB_USB_NOVA_T_USB2=m
3524CONFIG_DVB_USB_TTUSB2=m
3525CONFIG_DVB_USB_DTT200U=m
3526CONFIG_DVB_USB_OPERA1=m
3527CONFIG_DVB_USB_AF9005=m
3528CONFIG_DVB_USB_AF9005_REMOTE=m
3529CONFIG_DVB_USB_PCTV452E=m
3530CONFIG_DVB_USB_DW2102=m
3531CONFIG_DVB_USB_CINERGY_T2=m
3532CONFIG_DVB_USB_ANYSEE=m
3533CONFIG_DVB_USB_DTV5100=m
3534CONFIG_DVB_USB_AF9015=m
3535CONFIG_DVB_USB_CE6230=m
3536CONFIG_DVB_USB_FRIIO=m
3537CONFIG_DVB_USB_EC168=m
3538CONFIG_DVB_USB_AZ6007=m
3539CONFIG_DVB_USB_AZ6027=m
3540CONFIG_DVB_USB_LME2510=m
3541CONFIG_DVB_USB_TECHNISAT_USB2=m
3542CONFIG_DVB_USB_IT913X=m
3543CONFIG_DVB_USB_MXL111SF=m
3544CONFIG_DVB_USB_RTL28XXU=m
3545CONFIG_DVB_USB_AF9035=m
3459CONFIG_DVB_TTUSB_BUDGET=m 3546CONFIG_DVB_TTUSB_BUDGET=m
3460CONFIG_DVB_TTUSB_DEC=m 3547CONFIG_DVB_TTUSB_DEC=m
3548CONFIG_SMS_SIANO_MDTV=m
3549
3550#
3551# Siano module components
3552#
3553# CONFIG_SMS_USB_DRV is not set
3554# CONFIG_SMS_SDIO_DRV is not set
3461 3555
3462# 3556#
3463# Supported FlexCopII (B2C2) Adapters 3557# Supported FlexCopII (B2C2) Adapters
@@ -3479,6 +3573,7 @@ CONFIG_DVB_PLUTO2=m
3479# 3573#
3480# Supported SDMC DM1105 Adapters 3574# Supported SDMC DM1105 Adapters
3481# 3575#
3576CONFIG_DVB_DM1105=m
3482 3577
3483# 3578#
3484# Supported FireWire (IEEE 1394) Adapters 3579# Supported FireWire (IEEE 1394) Adapters
@@ -3494,6 +3589,9 @@ CONFIG_DVB_PT1=m
3494# 3589#
3495# Supported Mantis Adapters 3590# Supported Mantis Adapters
3496# 3591#
3592CONFIG_MANTIS_CORE=m
3593CONFIG_DVB_MANTIS=m
3594CONFIG_DVB_HOPPER=m
3497 3595
3498# 3596#
3499# Supported nGene Adapters 3597# Supported nGene Adapters
@@ -3514,6 +3612,7 @@ CONFIG_DVB_DDBRIDGE=m
3514# Multistandard (satellite) frontends 3612# Multistandard (satellite) frontends
3515# 3613#
3516CONFIG_DVB_STB0899=m 3614CONFIG_DVB_STB0899=m
3615CONFIG_DVB_STB6100=m
3517CONFIG_DVB_STV090x=m 3616CONFIG_DVB_STV090x=m
3518CONFIG_DVB_STV6110x=m 3617CONFIG_DVB_STV6110x=m
3519 3618
@@ -3528,8 +3627,13 @@ CONFIG_DVB_TDA18271C2DD=m
3528# 3627#
3529CONFIG_DVB_CX24123=m 3628CONFIG_DVB_CX24123=m
3530CONFIG_DVB_MT312=m 3629CONFIG_DVB_MT312=m
3630CONFIG_DVB_ZL10039=m
3531CONFIG_DVB_S5H1420=m 3631CONFIG_DVB_S5H1420=m
3632CONFIG_DVB_STV0288=m
3633CONFIG_DVB_STB6000=m
3532CONFIG_DVB_STV0299=m 3634CONFIG_DVB_STV0299=m
3635CONFIG_DVB_STV6110=m
3636CONFIG_DVB_STV0900=m
3533CONFIG_DVB_TDA8083=m 3637CONFIG_DVB_TDA8083=m
3534CONFIG_DVB_TDA10086=m 3638CONFIG_DVB_TDA10086=m
3535CONFIG_DVB_TDA8261=m 3639CONFIG_DVB_TDA8261=m
@@ -3538,15 +3642,31 @@ CONFIG_DVB_TUNER_ITD1000=m
3538CONFIG_DVB_TUNER_CX24113=m 3642CONFIG_DVB_TUNER_CX24113=m
3539CONFIG_DVB_TDA826X=m 3643CONFIG_DVB_TDA826X=m
3540CONFIG_DVB_TUA6100=m 3644CONFIG_DVB_TUA6100=m
3645CONFIG_DVB_CX24116=m
3646CONFIG_DVB_SI21XX=m
3647CONFIG_DVB_DS3000=m
3648CONFIG_DVB_MB86A16=m
3541 3649
3542# 3650#
3543# DVB-T (terrestrial) frontends 3651# DVB-T (terrestrial) frontends
3544# 3652#
3545CONFIG_DVB_SP8870=m 3653CONFIG_DVB_SP8870=m
3546CONFIG_DVB_CX22700=m 3654CONFIG_DVB_CX22700=m
3655CONFIG_DVB_CX22702=m
3547CONFIG_DVB_L64781=m 3656CONFIG_DVB_L64781=m
3548CONFIG_DVB_TDA1004X=m 3657CONFIG_DVB_TDA1004X=m
3658CONFIG_DVB_NXT6000=m
3549CONFIG_DVB_MT352=m 3659CONFIG_DVB_MT352=m
3660CONFIG_DVB_ZL10353=m
3661CONFIG_DVB_DIB3000MB=m
3662CONFIG_DVB_DIB3000MC=m
3663CONFIG_DVB_DIB7000M=m
3664CONFIG_DVB_DIB7000P=m
3665CONFIG_DVB_AF9013=m
3666CONFIG_DVB_EC100=m
3667CONFIG_DVB_CXD2820R=m
3668CONFIG_DVB_RTL2830=m
3669CONFIG_DVB_RTL2832=m
3550 3670
3551# 3671#
3552# DVB-C (cable) frontends 3672# DVB-C (cable) frontends
@@ -3562,22 +3682,36 @@ CONFIG_DVB_STV0297=m
3562CONFIG_DVB_NXT200X=m 3682CONFIG_DVB_NXT200X=m
3563CONFIG_DVB_BCM3510=m 3683CONFIG_DVB_BCM3510=m
3564CONFIG_DVB_LGDT330X=m 3684CONFIG_DVB_LGDT330X=m
3685CONFIG_DVB_LGDT3305=m
3686CONFIG_DVB_LG2160=m
3687CONFIG_DVB_S5H1411=m
3565 3688
3566# 3689#
3567# ISDB-T (terrestrial) frontends 3690# ISDB-T (terrestrial) frontends
3568# 3691#
3692CONFIG_DVB_DIB8000=m
3569 3693
3570# 3694#
3571# Digital terrestrial only tuners/PLL 3695# Digital terrestrial only tuners/PLL
3572# 3696#
3573CONFIG_DVB_PLL=m 3697CONFIG_DVB_PLL=m
3698CONFIG_DVB_TUNER_DIB0070=m
3699CONFIG_DVB_TUNER_DIB0090=m
3574 3700
3575# 3701#
3576# SEC control devices for DVB-S 3702# SEC control devices for DVB-S
3577# 3703#
3578CONFIG_DVB_LNBP21=m 3704CONFIG_DVB_LNBP21=m
3705CONFIG_DVB_LNBP22=m
3579CONFIG_DVB_ISL6421=m 3706CONFIG_DVB_ISL6421=m
3580CONFIG_DVB_ISL6423=m 3707CONFIG_DVB_ISL6423=m
3708CONFIG_DVB_LGS8GXX=m
3709CONFIG_DVB_ATBM8830=m
3710CONFIG_DVB_TDA665x=m
3711CONFIG_DVB_IX2505V=m
3712CONFIG_DVB_IT913X_FE=m
3713CONFIG_DVB_M88RS2000=m
3714CONFIG_DVB_AF9033=m
3581 3715
3582# 3716#
3583# Tools to develop new frontends 3717# Tools to develop new frontends
diff --git a/main/linux-vserver/kernelconfig.x86_64 b/main/linux-vserver/kernelconfig.x86_64
index 0da3acb1ec..3c24fd30a1 100644
--- a/main/linux-vserver/kernelconfig.x86_64
+++ b/main/linux-vserver/kernelconfig.x86_64
@@ -3190,7 +3190,7 @@ CONFIG_MEDIA_CAMERA_SUPPORT=y
3190# CONFIG_MEDIA_ANALOG_TV_SUPPORT is not set 3190# CONFIG_MEDIA_ANALOG_TV_SUPPORT is not set
3191CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y 3191CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
3192# CONFIG_MEDIA_RADIO_SUPPORT is not set 3192# CONFIG_MEDIA_RADIO_SUPPORT is not set
3193# CONFIG_MEDIA_RC_SUPPORT is not set 3193CONFIG_MEDIA_RC_SUPPORT=y
3194CONFIG_MEDIA_CONTROLLER=y 3194CONFIG_MEDIA_CONTROLLER=y
3195CONFIG_VIDEO_DEV=m 3195CONFIG_VIDEO_DEV=m
3196CONFIG_VIDEO_V4L2_COMMON=m 3196CONFIG_VIDEO_V4L2_COMMON=m
@@ -3203,10 +3203,55 @@ CONFIG_DVB_NET=y
3203# 3203#
3204CONFIG_VIDEO_SAA7146=m 3204CONFIG_VIDEO_SAA7146=m
3205CONFIG_VIDEO_SAA7146_VV=m 3205CONFIG_VIDEO_SAA7146_VV=m
3206# CONFIG_MEDIA_ATTACH is not set 3206CONFIG_RC_CORE=m
3207CONFIG_RC_MAP=m
3208CONFIG_RC_DECODERS=y
3209# CONFIG_LIRC is not set
3210CONFIG_IR_NEC_DECODER=m
3211CONFIG_IR_RC5_DECODER=m
3212CONFIG_IR_RC6_DECODER=m
3213CONFIG_IR_JVC_DECODER=m
3214CONFIG_IR_SONY_DECODER=m
3215CONFIG_IR_RC5_SZ_DECODER=m
3216CONFIG_IR_SANYO_DECODER=m
3217CONFIG_IR_MCE_KBD_DECODER=m
3218CONFIG_RC_DEVICES=y
3219CONFIG_RC_ATI_REMOTE=m
3220CONFIG_IR_ENE=m
3221CONFIG_IR_IMON=m
3222CONFIG_IR_MCEUSB=m
3223CONFIG_IR_ITE_CIR=m
3224CONFIG_IR_FINTEK=m
3225CONFIG_IR_NUVOTON=m
3226CONFIG_IR_REDRAT3=m
3227CONFIG_IR_STREAMZAP=m
3228CONFIG_IR_WINBOND_CIR=m
3229CONFIG_IR_IGUANA=m
3230CONFIG_RC_LOOPBACK=m
3231CONFIG_IR_GPIO_CIR=m
3232CONFIG_MEDIA_ATTACH=y
3207CONFIG_MEDIA_TUNER_SIMPLE=m 3233CONFIG_MEDIA_TUNER_SIMPLE=m
3234CONFIG_MEDIA_TUNER_TDA827X=m
3235CONFIG_MEDIA_TUNER_TDA18271=m
3208CONFIG_MEDIA_TUNER_TDA9887=m 3236CONFIG_MEDIA_TUNER_TDA9887=m
3237CONFIG_MEDIA_TUNER_MT2060=m
3238CONFIG_MEDIA_TUNER_MT2063=m
3239CONFIG_MEDIA_TUNER_MT2266=m
3209CONFIG_MEDIA_TUNER_MT2131=m 3240CONFIG_MEDIA_TUNER_MT2131=m
3241CONFIG_MEDIA_TUNER_QT1010=m
3242CONFIG_MEDIA_TUNER_XC2028=m
3243CONFIG_MEDIA_TUNER_XC5000=m
3244CONFIG_MEDIA_TUNER_XC4000=m
3245CONFIG_MEDIA_TUNER_MXL5005S=m
3246CONFIG_MEDIA_TUNER_MXL5007T=m
3247CONFIG_MEDIA_TUNER_MC44S803=m
3248CONFIG_MEDIA_TUNER_MAX2165=m
3249CONFIG_MEDIA_TUNER_TDA18218=m
3250CONFIG_MEDIA_TUNER_FC0011=m
3251CONFIG_MEDIA_TUNER_FC0012=m
3252CONFIG_MEDIA_TUNER_FC0013=m
3253CONFIG_MEDIA_TUNER_TDA18212=m
3254CONFIG_MEDIA_TUNER_TUA9001=m
3210CONFIG_VIDEO_V4L2=m 3255CONFIG_VIDEO_V4L2=m
3211CONFIG_VIDEOBUF_GEN=m 3256CONFIG_VIDEOBUF_GEN=m
3212CONFIG_VIDEOBUF_DMA_SG=m 3257CONFIG_VIDEOBUF_DMA_SG=m
@@ -3221,6 +3266,7 @@ CONFIG_VIDEO_CAPTURE_DRIVERS=y
3221# CONFIG_VIDEO_ADV_DEBUG is not set 3266# CONFIG_VIDEO_ADV_DEBUG is not set
3222# CONFIG_VIDEO_FIXED_MINOR_RANGES is not set 3267# CONFIG_VIDEO_FIXED_MINOR_RANGES is not set
3223# CONFIG_VIDEO_HELPER_CHIPS_AUTO is not set 3268# CONFIG_VIDEO_HELPER_CHIPS_AUTO is not set
3269CONFIG_VIDEO_IR_I2C=m
3224 3270
3225# 3271#
3226# Encoders, decoders, sensors and other helper chips 3272# Encoders, decoders, sensors and other helper chips
@@ -3388,6 +3434,7 @@ CONFIG_USB_SN9C102=m
3388CONFIG_VIDEO_EM28XX=m 3434CONFIG_VIDEO_EM28XX=m
3389CONFIG_VIDEO_EM28XX_ALSA=m 3435CONFIG_VIDEO_EM28XX_ALSA=m
3390# CONFIG_VIDEO_EM28XX_DVB is not set 3436# CONFIG_VIDEO_EM28XX_DVB is not set
3437CONFIG_VIDEO_EM28XX_RC=m
3391# CONFIG_V4L_ISA_PARPORT_DRIVERS is not set 3438# CONFIG_V4L_ISA_PARPORT_DRIVERS is not set
3392# CONFIG_V4L_PLATFORM_DRIVERS is not set 3439# CONFIG_V4L_PLATFORM_DRIVERS is not set
3393CONFIG_V4L_MEM2MEM_DRIVERS=y 3440CONFIG_V4L_MEM2MEM_DRIVERS=y
@@ -3404,14 +3451,61 @@ CONFIG_DVB_AV7110=m
3404CONFIG_DVB_AV7110_OSD=y 3451CONFIG_DVB_AV7110_OSD=y
3405CONFIG_DVB_BUDGET_CORE=m 3452CONFIG_DVB_BUDGET_CORE=m
3406CONFIG_DVB_BUDGET=m 3453CONFIG_DVB_BUDGET=m
3454CONFIG_DVB_BUDGET_CI=m
3407CONFIG_DVB_BUDGET_AV=m 3455CONFIG_DVB_BUDGET_AV=m
3408CONFIG_DVB_BUDGET_PATCH=m 3456CONFIG_DVB_BUDGET_PATCH=m
3409 3457
3410# 3458#
3411# Supported USB Adapters 3459# Supported USB Adapters
3412# 3460#
3461CONFIG_DVB_USB=m
3462# CONFIG_DVB_USB_DEBUG is not set
3463CONFIG_DVB_USB_A800=m
3464CONFIG_DVB_USB_DIBUSB_MB=m
3465# CONFIG_DVB_USB_DIBUSB_MB_FAULTY is not set
3466CONFIG_DVB_USB_DIBUSB_MC=m
3467CONFIG_DVB_USB_DIB0700=m
3468CONFIG_DVB_USB_UMT_010=m
3469CONFIG_DVB_USB_CXUSB=m
3470CONFIG_DVB_USB_M920X=m
3471CONFIG_DVB_USB_GL861=m
3472CONFIG_DVB_USB_AU6610=m
3473CONFIG_DVB_USB_DIGITV=m
3474CONFIG_DVB_USB_VP7045=m
3475CONFIG_DVB_USB_VP702X=m
3476CONFIG_DVB_USB_GP8PSK=m
3477CONFIG_DVB_USB_NOVA_T_USB2=m
3478CONFIG_DVB_USB_TTUSB2=m
3479CONFIG_DVB_USB_DTT200U=m
3480CONFIG_DVB_USB_OPERA1=m
3481CONFIG_DVB_USB_AF9005=m
3482CONFIG_DVB_USB_AF9005_REMOTE=m
3483CONFIG_DVB_USB_PCTV452E=m
3484CONFIG_DVB_USB_DW2102=m
3485CONFIG_DVB_USB_CINERGY_T2=m
3486CONFIG_DVB_USB_ANYSEE=m
3487CONFIG_DVB_USB_DTV5100=m
3488CONFIG_DVB_USB_AF9015=m
3489CONFIG_DVB_USB_CE6230=m
3490CONFIG_DVB_USB_FRIIO=m
3491CONFIG_DVB_USB_EC168=m
3492CONFIG_DVB_USB_AZ6007=m
3493CONFIG_DVB_USB_AZ6027=m
3494CONFIG_DVB_USB_LME2510=m
3495CONFIG_DVB_USB_TECHNISAT_USB2=m
3496CONFIG_DVB_USB_IT913X=m
3497CONFIG_DVB_USB_MXL111SF=m
3498CONFIG_DVB_USB_RTL28XXU=m
3499CONFIG_DVB_USB_AF9035=m
3413CONFIG_DVB_TTUSB_BUDGET=m 3500CONFIG_DVB_TTUSB_BUDGET=m
3414CONFIG_DVB_TTUSB_DEC=m 3501CONFIG_DVB_TTUSB_DEC=m
3502CONFIG_SMS_SIANO_MDTV=m
3503
3504#
3505# Siano module components
3506#
3507# CONFIG_SMS_USB_DRV is not set
3508# CONFIG_SMS_SDIO_DRV is not set
3415 3509
3416# 3510#
3417# Supported FlexCopII (B2C2) Adapters 3511# Supported FlexCopII (B2C2) Adapters
@@ -3433,6 +3527,7 @@ CONFIG_DVB_PLUTO2=m
3433# 3527#
3434# Supported SDMC DM1105 Adapters 3528# Supported SDMC DM1105 Adapters
3435# 3529#
3530CONFIG_DVB_DM1105=m
3436 3531
3437# 3532#
3438# Supported FireWire (IEEE 1394) Adapters 3533# Supported FireWire (IEEE 1394) Adapters
@@ -3448,6 +3543,9 @@ CONFIG_DVB_PT1=m
3448# 3543#
3449# Supported Mantis Adapters 3544# Supported Mantis Adapters
3450# 3545#
3546CONFIG_MANTIS_CORE=m
3547CONFIG_DVB_MANTIS=m
3548CONFIG_DVB_HOPPER=m
3451 3549
3452# 3550#
3453# Supported nGene Adapters 3551# Supported nGene Adapters
@@ -3468,6 +3566,7 @@ CONFIG_DVB_DDBRIDGE=m
3468# Multistandard (satellite) frontends 3566# Multistandard (satellite) frontends
3469# 3567#
3470CONFIG_DVB_STB0899=m 3568CONFIG_DVB_STB0899=m
3569CONFIG_DVB_STB6100=m
3471CONFIG_DVB_STV090x=m 3570CONFIG_DVB_STV090x=m
3472CONFIG_DVB_STV6110x=m 3571CONFIG_DVB_STV6110x=m
3473 3572
@@ -3482,8 +3581,13 @@ CONFIG_DVB_TDA18271C2DD=m
3482# 3581#
3483CONFIG_DVB_CX24123=m 3582CONFIG_DVB_CX24123=m
3484CONFIG_DVB_MT312=m 3583CONFIG_DVB_MT312=m
3584CONFIG_DVB_ZL10039=m
3485CONFIG_DVB_S5H1420=m 3585CONFIG_DVB_S5H1420=m
3586CONFIG_DVB_STV0288=m
3587CONFIG_DVB_STB6000=m
3486CONFIG_DVB_STV0299=m 3588CONFIG_DVB_STV0299=m
3589CONFIG_DVB_STV6110=m
3590CONFIG_DVB_STV0900=m
3487CONFIG_DVB_TDA8083=m 3591CONFIG_DVB_TDA8083=m
3488CONFIG_DVB_TDA10086=m 3592CONFIG_DVB_TDA10086=m
3489CONFIG_DVB_TDA8261=m 3593CONFIG_DVB_TDA8261=m
@@ -3492,15 +3596,31 @@ CONFIG_DVB_TUNER_ITD1000=m
3492CONFIG_DVB_TUNER_CX24113=m 3596CONFIG_DVB_TUNER_CX24113=m
3493CONFIG_DVB_TDA826X=m 3597CONFIG_DVB_TDA826X=m
3494CONFIG_DVB_TUA6100=m 3598CONFIG_DVB_TUA6100=m
3599CONFIG_DVB_CX24116=m
3600CONFIG_DVB_SI21XX=m
3601CONFIG_DVB_DS3000=m
3602CONFIG_DVB_MB86A16=m
3495 3603
3496# 3604#
3497# DVB-T (terrestrial) frontends 3605# DVB-T (terrestrial) frontends
3498# 3606#
3499CONFIG_DVB_SP8870=m 3607CONFIG_DVB_SP8870=m
3500CONFIG_DVB_CX22700=m 3608CONFIG_DVB_CX22700=m
3609CONFIG_DVB_CX22702=m
3501CONFIG_DVB_L64781=m 3610CONFIG_DVB_L64781=m
3502CONFIG_DVB_TDA1004X=m 3611CONFIG_DVB_TDA1004X=m
3612CONFIG_DVB_NXT6000=m
3503CONFIG_DVB_MT352=m 3613CONFIG_DVB_MT352=m
3614CONFIG_DVB_ZL10353=m
3615CONFIG_DVB_DIB3000MB=m
3616CONFIG_DVB_DIB3000MC=m
3617CONFIG_DVB_DIB7000M=m
3618CONFIG_DVB_DIB7000P=m
3619CONFIG_DVB_AF9013=m
3620CONFIG_DVB_EC100=m
3621CONFIG_DVB_CXD2820R=m
3622CONFIG_DVB_RTL2830=m
3623CONFIG_DVB_RTL2832=m
3504 3624
3505# 3625#
3506# DVB-C (cable) frontends 3626# DVB-C (cable) frontends
@@ -3516,22 +3636,36 @@ CONFIG_DVB_STV0297=m
3516CONFIG_DVB_NXT200X=m 3636CONFIG_DVB_NXT200X=m
3517CONFIG_DVB_BCM3510=m 3637CONFIG_DVB_BCM3510=m
3518CONFIG_DVB_LGDT330X=m 3638CONFIG_DVB_LGDT330X=m
3639CONFIG_DVB_LGDT3305=m
3640CONFIG_DVB_LG2160=m
3641CONFIG_DVB_S5H1411=m
3519 3642
3520# 3643#
3521# ISDB-T (terrestrial) frontends 3644# ISDB-T (terrestrial) frontends
3522# 3645#
3646CONFIG_DVB_DIB8000=m
3523 3647
3524# 3648#
3525# Digital terrestrial only tuners/PLL 3649# Digital terrestrial only tuners/PLL
3526# 3650#
3527CONFIG_DVB_PLL=m 3651CONFIG_DVB_PLL=m
3652CONFIG_DVB_TUNER_DIB0070=m
3653CONFIG_DVB_TUNER_DIB0090=m
3528 3654
3529# 3655#
3530# SEC control devices for DVB-S 3656# SEC control devices for DVB-S
3531# 3657#
3532CONFIG_DVB_LNBP21=m 3658CONFIG_DVB_LNBP21=m
3659CONFIG_DVB_LNBP22=m
3533CONFIG_DVB_ISL6421=m 3660CONFIG_DVB_ISL6421=m
3534CONFIG_DVB_ISL6423=m 3661CONFIG_DVB_ISL6423=m
3662CONFIG_DVB_LGS8GXX=m
3663CONFIG_DVB_ATBM8830=m
3664CONFIG_DVB_TDA665x=m
3665CONFIG_DVB_IX2505V=m
3666CONFIG_DVB_IT913X_FE=m
3667CONFIG_DVB_M88RS2000=m
3668CONFIG_DVB_AF9033=m
3535 3669
3536# 3670#
3537# Tools to develop new frontends 3671# Tools to develop new frontends
diff --git a/main/linux-vserver/patch-3.6.6-vs2.3.4.3.1-noxfs-nocow.diff b/main/linux-vserver/patch-3.6.6-vs2.3.4.3.1-noxfs-nocow.diff
new file mode 100644
index 0000000000..40814c0a36
--- /dev/null
+++ b/main/linux-vserver/patch-3.6.6-vs2.3.4.3.1-noxfs-nocow.diff
@@ -0,0 +1,25752 @@
1diff -NurpP --minimal linux-3.6.6/Documentation/vserver/debug.txt linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/Documentation/vserver/debug.txt
2--- linux-3.6.6/Documentation/vserver/debug.txt 1970-01-01 01:00:00.000000000 +0100
3+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/Documentation/vserver/debug.txt 2012-10-04 18:46:59.000000000 +0200
4@@ -0,0 +1,154 @@
5+
6+debug_cvirt:
7+
8+ 2 4 "vx_map_tgid: %p/%llx: %d -> %d"
9+ "vx_rmap_tgid: %p/%llx: %d -> %d"
10+
11+debug_dlim:
12+
13+ 0 1 "ALLOC (%p,#%d)%c inode (%d)"
14+ "FREE (%p,#%d)%c inode"
15+ 1 2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16+ "FREE (%p,#%d)%c %lld bytes"
17+ 2 4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18+ 3 8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19+ "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20+ "rcu_free_dl_info(%p)"
21+ 4 10 "alloc_dl_info(%p,%d) = %p"
22+ "dealloc_dl_info(%p)"
23+ "get_dl_info(%p[#%d.%d])"
24+ "put_dl_info(%p[#%d.%d])"
25+ 5 20 "alloc_dl_info(%p,%d)*"
26+ 6 40 "__hash_dl_info: %p[#%d]"
27+ "__unhash_dl_info: %p[#%d]"
28+ 7 80 "locate_dl_info(%p,#%d) = %p"
29+
30+debug_misc:
31+
32+ 0 1 "destroy_dqhash: %p [#0x%08x] c=%d"
33+ "new_dqhash: %p [#0x%08x]"
34+ "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35+ "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36+ "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37+ "vroot_get_real_bdev not set"
38+ 1 2 "cow_break_link(»%s«)"
39+ "temp copy »%s«"
40+ 2 4 "dentry_open(new): %p"
41+ "dentry_open(old): %p"
42+ "lookup_create(new): %p"
43+ "old path »%s«"
44+ "path_lookup(old): %d"
45+ "vfs_create(new): %d"
46+ "vfs_rename: %d"
47+ "vfs_sendfile: %d"
48+ 3 8 "fput(new_file=%p[#%d])"
49+ "fput(old_file=%p[#%d])"
50+ 4 10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51+ "vx_info_kill(%p[#%d],%d,%d)*"
52+ 5 20 "vs_reboot(%p[#%d],%d)"
53+ 6 40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
54+
55+debug_net:
56+
57+ 2 4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58+ 3 8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59+ "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60+ 4 10 "ip_route_connect(%p) %p,%p;%lx"
61+ 5 20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62+ 6 40 "sk,egf: %p [#%d] (from %d)"
63+ "sk,egn: %p [#%d] (from %d)"
64+ "sk,req: %p [#%d] (from %d)"
65+ "sk: %p [#%d] (from %d)"
66+ "tw: %p [#%d] (from %d)"
67+ 7 80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68+ "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
69+
70+debug_nid:
71+
72+ 0 1 "__lookup_nx_info(#%u): %p[#%u]"
73+ "alloc_nx_info(%d) = %p"
74+ "create_nx_info(%d) (dynamic rejected)"
75+ "create_nx_info(%d) = %p (already there)"
76+ "create_nx_info(%d) = %p (new)"
77+ "dealloc_nx_info(%p)"
78+ 1 2 "alloc_nx_info(%d)*"
79+ "create_nx_info(%d)*"
80+ 2 4 "get_nx_info(%p[#%d.%d])"
81+ "put_nx_info(%p[#%d.%d])"
82+ 3 8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83+ "clr_nx_info(%p[#%d.%d])"
84+ "init_nx_info(%p[#%d.%d])"
85+ "release_nx_info(%p[#%d.%d.%d]) %p"
86+ "set_nx_info(%p[#%d.%d])"
87+ 4 10 "__hash_nx_info: %p[#%d]"
88+ "__nx_dynamic_id: [#%d]"
89+ "__unhash_nx_info: %p[#%d.%d.%d]"
90+ 5 20 "moved task %p into nxi:%p[#%d]"
91+ "nx_migrate_task(%p,%p[#%d.%d.%d])"
92+ "task_get_nx_info(%p)"
93+ 6 40 "nx_clear_persistent(%p[#%d])"
94+
95+debug_quota:
96+
97+ 0 1 "quota_sync_dqh(%p,%d) discard inode %p"
98+ 1 2 "quota_sync_dqh(%p,%d)"
99+ "sync_dquots(%p,%d)"
100+ "sync_dquots_dqh(%p,%d)"
101+ 3 8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
102+
103+debug_switch:
104+
105+ 0 1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106+ 1 2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107+ 4 10 "%s: (%s %s) returned %s with %d"
108+
109+debug_tag:
110+
111+ 7 80 "dx_parse_tag(»%s«): %d:#%d"
112+ "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113+
114+debug_xid:
115+
116+ 0 1 "__lookup_vx_info(#%u): %p[#%u]"
117+ "alloc_vx_info(%d) = %p"
118+ "alloc_vx_info(%d)*"
119+ "create_vx_info(%d) (dynamic rejected)"
120+ "create_vx_info(%d) = %p (already there)"
121+ "create_vx_info(%d) = %p (new)"
122+ "dealloc_vx_info(%p)"
123+ "loc_vx_info(%d) = %p (found)"
124+ "loc_vx_info(%d) = %p (new)"
125+ "loc_vx_info(%d) = %p (not available)"
126+ 1 2 "create_vx_info(%d)*"
127+ "loc_vx_info(%d)*"
128+ 2 4 "get_vx_info(%p[#%d.%d])"
129+ "put_vx_info(%p[#%d.%d])"
130+ 3 8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131+ "clr_vx_info(%p[#%d.%d])"
132+ "init_vx_info(%p[#%d.%d])"
133+ "release_vx_info(%p[#%d.%d.%d]) %p"
134+ "set_vx_info(%p[#%d.%d])"
135+ 4 10 "__hash_vx_info: %p[#%d]"
136+ "__unhash_vx_info: %p[#%d.%d.%d]"
137+ "__vx_dynamic_id: [#%d]"
138+ 5 20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139+ "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140+ "moved task %p into vxi:%p[#%d]"
141+ "task_get_vx_info(%p)"
142+ "vx_migrate_task(%p,%p[#%d.%d])"
143+ 6 40 "vx_clear_persistent(%p[#%d])"
144+ "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145+ "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146+ "vx_set_persistent(%p[#%d])"
147+ "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148+ 7 80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
149+
150+
151+debug_limit:
152+
153+ n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154+ "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155+
156+ m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157+ "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158+ "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159diff -NurpP --minimal linux-3.6.6/Makefile linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/Makefile
160--- linux-3.6.6/Makefile 2012-11-06 18:42:06.000000000 +0100
161+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/Makefile 2012-11-06 19:34:47.000000000 +0100
162@@ -1,7 +1,7 @@
163 VERSION = 3
164 PATCHLEVEL = 6
165 SUBLEVEL = 6
166-EXTRAVERSION =
167+EXTRAVERSION = -vs2.3.4.3.1-noxfs-nocow
168 NAME = Terrified Chipmunk
169
170 # *DOCUMENTATION*
171diff -NurpP --minimal linux-3.6.6/arch/alpha/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/alpha/Kconfig
172--- linux-3.6.6/arch/alpha/Kconfig 2012-10-04 15:26:43.000000000 +0200
173+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/alpha/Kconfig 2012-10-04 18:46:59.000000000 +0200
174@@ -664,6 +664,8 @@ config DUMMY_CONSOLE
175 depends on VGA_HOSE
176 default y
177
178+source "kernel/vserver/Kconfig"
179+
180 source "security/Kconfig"
181
182 source "crypto/Kconfig"
183diff -NurpP --minimal linux-3.6.6/arch/alpha/kernel/ptrace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/alpha/kernel/ptrace.c
184--- linux-3.6.6/arch/alpha/kernel/ptrace.c 2012-05-21 18:06:12.000000000 +0200
185+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/alpha/kernel/ptrace.c 2012-10-04 18:46:59.000000000 +0200
186@@ -13,6 +13,7 @@
187 #include <linux/user.h>
188 #include <linux/security.h>
189 #include <linux/signal.h>
190+#include <linux/vs_base.h>
191
192 #include <asm/uaccess.h>
193 #include <asm/pgtable.h>
194diff -NurpP --minimal linux-3.6.6/arch/alpha/kernel/systbls.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/alpha/kernel/systbls.S
195--- linux-3.6.6/arch/alpha/kernel/systbls.S 2012-10-04 15:26:43.000000000 +0200
196+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/alpha/kernel/systbls.S 2012-10-04 18:46:59.000000000 +0200
197@@ -446,7 +446,7 @@ sys_call_table:
198 .quad sys_stat64 /* 425 */
199 .quad sys_lstat64
200 .quad sys_fstat64
201- .quad sys_ni_syscall /* sys_vserver */
202+ .quad sys_vserver /* sys_vserver */
203 .quad sys_ni_syscall /* sys_mbind */
204 .quad sys_ni_syscall /* sys_get_mempolicy */
205 .quad sys_ni_syscall /* sys_set_mempolicy */
206diff -NurpP --minimal linux-3.6.6/arch/alpha/kernel/traps.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/alpha/kernel/traps.c
207--- linux-3.6.6/arch/alpha/kernel/traps.c 2012-05-21 18:06:12.000000000 +0200
208+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/alpha/kernel/traps.c 2012-10-04 18:46:59.000000000 +0200
209@@ -184,7 +184,8 @@ die_if_kernel(char * str, struct pt_regs
210 #ifdef CONFIG_SMP
211 printk("CPU %d ", hard_smp_processor_id());
212 #endif
213- printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
214+ printk("%s(%d[#%u]): %s %ld\n", current->comm,
215+ task_pid_nr(current), current->xid, str, err);
216 dik_show_regs(regs, r9_15);
217 add_taint(TAINT_DIE);
218 dik_show_trace((unsigned long *)(regs+1));
219diff -NurpP --minimal linux-3.6.6/arch/arm/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/arm/Kconfig
220--- linux-3.6.6/arch/arm/Kconfig 2012-11-06 18:42:06.000000000 +0100
221+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/arm/Kconfig 2012-11-06 18:43:40.000000000 +0100
222@@ -2341,6 +2341,8 @@ source "fs/Kconfig"
223
224 source "arch/arm/Kconfig.debug"
225
226+source "kernel/vserver/Kconfig"
227+
228 source "security/Kconfig"
229
230 source "crypto/Kconfig"
231diff -NurpP --minimal linux-3.6.6/arch/arm/kernel/calls.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/arm/kernel/calls.S
232--- linux-3.6.6/arch/arm/kernel/calls.S 2012-10-04 15:26:43.000000000 +0200
233+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/arm/kernel/calls.S 2012-10-04 18:46:59.000000000 +0200
234@@ -322,7 +322,7 @@
235 /* 310 */ CALL(sys_request_key)
236 CALL(sys_keyctl)
237 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
238-/* vserver */ CALL(sys_ni_syscall)
239+ CALL(sys_vserver)
240 CALL(sys_ioprio_set)
241 /* 315 */ CALL(sys_ioprio_get)
242 CALL(sys_inotify_init)
243diff -NurpP --minimal linux-3.6.6/arch/arm/kernel/process.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/arm/kernel/process.c
244--- linux-3.6.6/arch/arm/kernel/process.c 2012-10-04 15:26:43.000000000 +0200
245+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/arm/kernel/process.c 2012-10-04 18:46:59.000000000 +0200
246@@ -337,7 +337,8 @@ void __show_regs(struct pt_regs *regs)
247 void show_regs(struct pt_regs * regs)
248 {
249 printk("\n");
250- printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
251+ printk("Pid: %d[#%u], comm: %20s\n",
252+ task_pid_nr(current), current->xid, current->comm);
253 __show_regs(regs);
254 dump_stack();
255 }
256diff -NurpP --minimal linux-3.6.6/arch/arm/kernel/traps.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/arm/kernel/traps.c
257--- linux-3.6.6/arch/arm/kernel/traps.c 2012-10-04 15:26:44.000000000 +0200
258+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/arm/kernel/traps.c 2012-10-04 19:03:56.000000000 +0200
259@@ -249,8 +249,8 @@ static int __die(const char *str, int er
260
261 print_modules();
262 __show_regs(regs);
263- printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
264- TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
265+ printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
266+ TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
267
268 if (!user_mode(regs) || in_interrupt()) {
269 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
270diff -NurpP --minimal linux-3.6.6/arch/cris/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/cris/Kconfig
271--- linux-3.6.6/arch/cris/Kconfig 2012-10-04 15:26:51.000000000 +0200
272+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/cris/Kconfig 2012-10-04 18:46:59.000000000 +0200
273@@ -673,6 +673,8 @@ source "drivers/staging/Kconfig"
274
275 source "arch/cris/Kconfig.debug"
276
277+source "kernel/vserver/Kconfig"
278+
279 source "security/Kconfig"
280
281 source "crypto/Kconfig"
282diff -NurpP --minimal linux-3.6.6/arch/frv/kernel/kernel_thread.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/frv/kernel/kernel_thread.S
283--- linux-3.6.6/arch/frv/kernel/kernel_thread.S 2012-10-04 15:26:51.000000000 +0200
284+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/frv/kernel/kernel_thread.S 2012-10-04 18:46:59.000000000 +0200
285@@ -37,7 +37,7 @@ kernel_thread:
286
287 # start by forking the current process, but with shared VM
288 setlos.p #__NR_clone,gr7 ; syscall number
289- ori gr10,#CLONE_VM,gr8 ; first syscall arg [clone_flags]
290+ ori gr10,#CLONE_KT,gr8 ; first syscall arg [clone_flags]
291 sethi.p #0xe4e4,gr9 ; second syscall arg [newsp]
292 setlo #0xe4e4,gr9
293 setlos.p #0,gr10 ; third syscall arg [parent_tidptr]
294diff -NurpP --minimal linux-3.6.6/arch/h8300/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/h8300/Kconfig
295--- linux-3.6.6/arch/h8300/Kconfig 2012-10-04 15:26:51.000000000 +0200
296+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/h8300/Kconfig 2012-10-04 18:46:59.000000000 +0200
297@@ -215,6 +215,8 @@ source "fs/Kconfig"
298
299 source "arch/h8300/Kconfig.debug"
300
301+source "kernel/vserver/Kconfig"
302+
303 source "security/Kconfig"
304
305 source "crypto/Kconfig"
306diff -NurpP --minimal linux-3.6.6/arch/ia64/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/Kconfig
307--- linux-3.6.6/arch/ia64/Kconfig 2012-10-04 15:26:51.000000000 +0200
308+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/Kconfig 2012-10-04 18:46:59.000000000 +0200
309@@ -652,6 +652,8 @@ source "fs/Kconfig"
310
311 source "arch/ia64/Kconfig.debug"
312
313+source "kernel/vserver/Kconfig"
314+
315 source "security/Kconfig"
316
317 source "crypto/Kconfig"
318diff -NurpP --minimal linux-3.6.6/arch/ia64/kernel/entry.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/kernel/entry.S
319--- linux-3.6.6/arch/ia64/kernel/entry.S 2012-03-19 19:46:40.000000000 +0100
320+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/kernel/entry.S 2012-10-04 18:46:59.000000000 +0200
321@@ -1714,7 +1714,7 @@ sys_call_table:
322 data8 sys_mq_notify
323 data8 sys_mq_getsetattr
324 data8 sys_kexec_load
325- data8 sys_ni_syscall // reserved for vserver
326+ data8 sys_vserver
327 data8 sys_waitid // 1270
328 data8 sys_add_key
329 data8 sys_request_key
330diff -NurpP --minimal linux-3.6.6/arch/ia64/kernel/process.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/kernel/process.c
331--- linux-3.6.6/arch/ia64/kernel/process.c 2012-11-06 18:42:07.000000000 +0100
332+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/kernel/process.c 2012-11-06 18:43:40.000000000 +0100
333@@ -111,8 +111,8 @@ show_regs (struct pt_regs *regs)
334 unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
335
336 print_modules();
337- printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
338- smp_processor_id(), current->comm);
339+ printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
340+ current->xid, smp_processor_id(), current->comm);
341 printk("psr : %016lx ifs : %016lx ip : [<%016lx>] %s (%s)\n",
342 regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
343 init_utsname()->release);
344diff -NurpP --minimal linux-3.6.6/arch/ia64/kernel/ptrace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/kernel/ptrace.c
345--- linux-3.6.6/arch/ia64/kernel/ptrace.c 2012-05-21 18:06:26.000000000 +0200
346+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/kernel/ptrace.c 2012-10-04 18:46:59.000000000 +0200
347@@ -21,6 +21,7 @@
348 #include <linux/regset.h>
349 #include <linux/elf.h>
350 #include <linux/tracehook.h>
351+#include <linux/vs_base.h>
352
353 #include <asm/pgtable.h>
354 #include <asm/processor.h>
355diff -NurpP --minimal linux-3.6.6/arch/ia64/kernel/traps.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/kernel/traps.c
356--- linux-3.6.6/arch/ia64/kernel/traps.c 2012-05-21 18:06:26.000000000 +0200
357+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/ia64/kernel/traps.c 2012-10-04 18:47:00.000000000 +0200
358@@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
359 put_cpu();
360
361 if (++die.lock_owner_depth < 3) {
362- printk("%s[%d]: %s %ld [%d]\n",
363- current->comm, task_pid_nr(current), str, err, ++die_counter);
364+ printk("%s[%d[#%u]]: %s %ld [%d]\n",
365+ current->comm, task_pid_nr(current), current->xid,
366+ str, err, ++die_counter);
367 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
368 != NOTIFY_STOP)
369 show_regs(regs);
370@@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
371 if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
372 last.time = current_jiffies + 5 * HZ;
373 printk(KERN_WARNING
374- "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
375- current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
376+ "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
377+ current->comm, task_pid_nr(current), current->xid,
378+ regs->cr_iip + ia64_psr(regs)->ri, isr);
379 }
380 }
381 }
382diff -NurpP --minimal linux-3.6.6/arch/m32r/kernel/traps.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/m32r/kernel/traps.c
383--- linux-3.6.6/arch/m32r/kernel/traps.c 2012-05-21 18:06:26.000000000 +0200
384+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/m32r/kernel/traps.c 2012-10-04 18:47:00.000000000 +0200
385@@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
386 } else {
387 printk("SPI: %08lx\n", sp);
388 }
389- printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
390- current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
391+ printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
392+ current->comm, task_pid_nr(current), current->xid,
393+ 0xffff & i, 4096+(unsigned long)current);
394
395 /*
396 * When in-kernel, we also print out the stack and code at the
397diff -NurpP --minimal linux-3.6.6/arch/m68k/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/m68k/Kconfig
398--- linux-3.6.6/arch/m68k/Kconfig 2012-10-04 15:26:51.000000000 +0200
399+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/m68k/Kconfig 2012-10-04 18:47:00.000000000 +0200
400@@ -129,6 +129,8 @@ source "fs/Kconfig"
401
402 source "arch/m68k/Kconfig.debug"
403
404+source "kernel/vserver/Kconfig"
405+
406 source "security/Kconfig"
407
408 source "crypto/Kconfig"
409diff -NurpP --minimal linux-3.6.6/arch/mips/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/Kconfig
410--- linux-3.6.6/arch/mips/Kconfig 2012-10-04 15:26:52.000000000 +0200
411+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/Kconfig 2012-10-04 18:47:00.000000000 +0200
412@@ -2554,6 +2554,8 @@ source "fs/Kconfig"
413
414 source "arch/mips/Kconfig.debug"
415
416+source "kernel/vserver/Kconfig"
417+
418 source "security/Kconfig"
419
420 source "crypto/Kconfig"
421diff -NurpP --minimal linux-3.6.6/arch/mips/kernel/ptrace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/ptrace.c
422--- linux-3.6.6/arch/mips/kernel/ptrace.c 2012-07-22 23:38:52.000000000 +0200
423+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/ptrace.c 2012-10-04 18:47:00.000000000 +0200
424@@ -25,6 +25,7 @@
425 #include <linux/security.h>
426 #include <linux/audit.h>
427 #include <linux/seccomp.h>
428+#include <linux/vs_base.h>
429
430 #include <asm/byteorder.h>
431 #include <asm/cpu.h>
432@@ -262,6 +263,9 @@ long arch_ptrace(struct task_struct *chi
433 void __user *datavp = (void __user *) data;
434 unsigned long __user *datalp = (void __user *) data;
435
436+ if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
437+ goto out;
438+
439 switch (request) {
440 /* when I and D space are separate, these will need to be fixed. */
441 case PTRACE_PEEKTEXT: /* read word at location addr. */
442diff -NurpP --minimal linux-3.6.6/arch/mips/kernel/scall32-o32.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/scall32-o32.S
443--- linux-3.6.6/arch/mips/kernel/scall32-o32.S 2012-01-09 16:14:05.000000000 +0100
444+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/scall32-o32.S 2012-10-04 18:47:00.000000000 +0200
445@@ -523,7 +523,7 @@ einval: li v0, -ENOSYS
446 sys sys_mq_timedreceive 5
447 sys sys_mq_notify 2 /* 4275 */
448 sys sys_mq_getsetattr 3
449- sys sys_ni_syscall 0 /* sys_vserver */
450+ sys sys_vserver 3
451 sys sys_waitid 5
452 sys sys_ni_syscall 0 /* available, was setaltroot */
453 sys sys_add_key 5 /* 4280 */
454diff -NurpP --minimal linux-3.6.6/arch/mips/kernel/scall64-64.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/scall64-64.S
455--- linux-3.6.6/arch/mips/kernel/scall64-64.S 2012-01-09 16:14:05.000000000 +0100
456+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/scall64-64.S 2012-10-04 18:47:00.000000000 +0200
457@@ -362,7 +362,7 @@ sys_call_table:
458 PTR sys_mq_timedreceive
459 PTR sys_mq_notify
460 PTR sys_mq_getsetattr /* 5235 */
461- PTR sys_ni_syscall /* sys_vserver */
462+ PTR sys_vserver
463 PTR sys_waitid
464 PTR sys_ni_syscall /* available, was setaltroot */
465 PTR sys_add_key
466diff -NurpP --minimal linux-3.6.6/arch/mips/kernel/scall64-n32.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/scall64-n32.S
467--- linux-3.6.6/arch/mips/kernel/scall64-n32.S 2012-01-09 16:14:05.000000000 +0100
468+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/scall64-n32.S 2012-10-04 18:47:00.000000000 +0200
469@@ -361,7 +361,7 @@ EXPORT(sysn32_call_table)
470 PTR compat_sys_mq_timedreceive
471 PTR compat_sys_mq_notify
472 PTR compat_sys_mq_getsetattr
473- PTR sys_ni_syscall /* 6240, sys_vserver */
474+ PTR sys32_vserver /* 6240 */
475 PTR compat_sys_waitid
476 PTR sys_ni_syscall /* available, was setaltroot */
477 PTR sys_add_key
478diff -NurpP --minimal linux-3.6.6/arch/mips/kernel/scall64-o32.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/scall64-o32.S
479--- linux-3.6.6/arch/mips/kernel/scall64-o32.S 2012-01-09 16:14:05.000000000 +0100
480+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/scall64-o32.S 2012-10-04 18:47:00.000000000 +0200
481@@ -480,7 +480,7 @@ sys_call_table:
482 PTR compat_sys_mq_timedreceive
483 PTR compat_sys_mq_notify /* 4275 */
484 PTR compat_sys_mq_getsetattr
485- PTR sys_ni_syscall /* sys_vserver */
486+ PTR sys32_vserver
487 PTR sys_32_waitid
488 PTR sys_ni_syscall /* available, was setaltroot */
489 PTR sys_add_key /* 4280 */
490diff -NurpP --minimal linux-3.6.6/arch/mips/kernel/traps.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/traps.c
491--- linux-3.6.6/arch/mips/kernel/traps.c 2012-10-04 15:26:53.000000000 +0200
492+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/mips/kernel/traps.c 2012-10-04 18:47:00.000000000 +0200
493@@ -347,9 +347,10 @@ void show_registers(struct pt_regs *regs
494
495 __show_regs(regs);
496 print_modules();
497- printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
498- current->comm, current->pid, current_thread_info(), current,
499- field, current_thread_info()->tp_value);
500+ printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
501+ current->comm, task_pid_nr(current), current->xid,
502+ current_thread_info(), current,
503+ field, current_thread_info()->tp_value);
504 if (cpu_has_userlocal) {
505 unsigned long tls;
506
507diff -NurpP --minimal linux-3.6.6/arch/parisc/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/parisc/Kconfig
508--- linux-3.6.6/arch/parisc/Kconfig 2012-07-22 23:38:52.000000000 +0200
509+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/parisc/Kconfig 2012-10-04 18:47:00.000000000 +0200
510@@ -281,6 +281,8 @@ source "fs/Kconfig"
511
512 source "arch/parisc/Kconfig.debug"
513
514+source "kernel/vserver/Kconfig"
515+
516 source "security/Kconfig"
517
518 source "crypto/Kconfig"
519diff -NurpP --minimal linux-3.6.6/arch/parisc/kernel/syscall_table.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/parisc/kernel/syscall_table.S
520--- linux-3.6.6/arch/parisc/kernel/syscall_table.S 2011-10-24 18:45:00.000000000 +0200
521+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/parisc/kernel/syscall_table.S 2012-10-04 18:47:00.000000000 +0200
522@@ -361,7 +361,7 @@
523 ENTRY_COMP(mbind) /* 260 */
524 ENTRY_COMP(get_mempolicy)
525 ENTRY_COMP(set_mempolicy)
526- ENTRY_SAME(ni_syscall) /* 263: reserved for vserver */
527+ ENTRY_DIFF(vserver)
528 ENTRY_SAME(add_key)
529 ENTRY_SAME(request_key) /* 265 */
530 ENTRY_SAME(keyctl)
531diff -NurpP --minimal linux-3.6.6/arch/parisc/kernel/traps.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/parisc/kernel/traps.c
532--- linux-3.6.6/arch/parisc/kernel/traps.c 2012-05-21 18:06:28.000000000 +0200
533+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/parisc/kernel/traps.c 2012-10-04 18:47:00.000000000 +0200
534@@ -235,8 +235,9 @@ void die_if_kernel(char *str, struct pt_
535 if (err == 0)
536 return; /* STFU */
537
538- printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
539- current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
540+ printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
541+ current->comm, task_pid_nr(current), current->xid,
542+ str, err, regs->iaoq[0]);
543 #ifdef PRINT_USER_FAULTS
544 /* XXX for debugging only */
545 show_regs(regs);
546@@ -269,8 +270,8 @@ void die_if_kernel(char *str, struct pt_
547 pdc_console_restart();
548
549 if (err)
550- printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
551- current->comm, task_pid_nr(current), str, err);
552+ printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
553+ current->comm, task_pid_nr(current), current->xid, str, err);
554
555 /* Wot's wrong wif bein' racy? */
556 if (current->thread.flags & PARISC_KERNEL_DEATH) {
557diff -NurpP --minimal linux-3.6.6/arch/parisc/mm/fault.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/parisc/mm/fault.c
558--- linux-3.6.6/arch/parisc/mm/fault.c 2010-08-02 16:52:06.000000000 +0200
559+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/parisc/mm/fault.c 2012-10-04 18:47:00.000000000 +0200
560@@ -237,8 +237,9 @@ bad_area:
561
562 #ifdef PRINT_USER_FAULTS
563 printk(KERN_DEBUG "\n");
564- printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
565- task_pid_nr(tsk), tsk->comm, code, address);
566+ printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
567+ "command='%s' type=%lu address=0x%08lx\n",
568+ task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
569 if (vma) {
570 printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
571 vma->vm_start, vma->vm_end);
572diff -NurpP --minimal linux-3.6.6/arch/powerpc/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/powerpc/Kconfig
573--- linux-3.6.6/arch/powerpc/Kconfig 2012-10-04 15:26:53.000000000 +0200
574+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/powerpc/Kconfig 2012-10-04 18:47:00.000000000 +0200
575@@ -996,6 +996,8 @@ source "lib/Kconfig"
576
577 source "arch/powerpc/Kconfig.debug"
578
579+source "kernel/vserver/Kconfig"
580+
581 source "security/Kconfig"
582
583 config KEYS_COMPAT
584diff -NurpP --minimal linux-3.6.6/arch/powerpc/include/asm/unistd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/powerpc/include/asm/unistd.h
585--- linux-3.6.6/arch/powerpc/include/asm/unistd.h 2012-10-04 15:26:53.000000000 +0200
586+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/powerpc/include/asm/unistd.h 2012-10-04 18:47:00.000000000 +0200
587@@ -275,7 +275,7 @@
588 #endif
589 #define __NR_rtas 255
590 #define __NR_sys_debug_setcontext 256
591-/* Number 257 is reserved for vserver */
592+#define __NR_vserver 257
593 #define __NR_migrate_pages 258
594 #define __NR_mbind 259
595 #define __NR_get_mempolicy 260
596diff -NurpP --minimal linux-3.6.6/arch/powerpc/kernel/process.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/powerpc/kernel/process.c
597--- linux-3.6.6/arch/powerpc/kernel/process.c 2012-10-04 15:26:54.000000000 +0200
598+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/powerpc/kernel/process.c 2012-10-04 18:47:00.000000000 +0200
599@@ -661,8 +661,9 @@ void show_regs(struct pt_regs * regs)
600 #else
601 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
602 #endif
603- printk("TASK = %p[%d] '%s' THREAD: %p",
604- current, task_pid_nr(current), current->comm, task_thread_info(current));
605+ printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
606+ current, task_pid_nr(current), current->xid,
607+ current->comm, task_thread_info(current));
608
609 #ifdef CONFIG_SMP
610 printk(" CPU: %d", raw_smp_processor_id());
611diff -NurpP --minimal linux-3.6.6/arch/powerpc/kernel/traps.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/powerpc/kernel/traps.c
612--- linux-3.6.6/arch/powerpc/kernel/traps.c 2012-10-04 15:26:54.000000000 +0200
613+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/powerpc/kernel/traps.c 2012-10-04 18:47:00.000000000 +0200
614@@ -1119,8 +1119,9 @@ void nonrecoverable_exception(struct pt_
615
616 void trace_syscall(struct pt_regs *regs)
617 {
618- printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
619- current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
620+ printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
621+ current, task_pid_nr(current), current->xid,
622+ regs->nip, regs->link, regs->gpr[0],
623 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
624 }
625
626diff -NurpP --minimal linux-3.6.6/arch/s390/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/Kconfig
627--- linux-3.6.6/arch/s390/Kconfig 2012-10-04 15:26:54.000000000 +0200
628+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/Kconfig 2012-10-04 18:47:00.000000000 +0200
629@@ -634,6 +634,8 @@ source "fs/Kconfig"
630
631 source "arch/s390/Kconfig.debug"
632
633+source "kernel/vserver/Kconfig"
634+
635 source "security/Kconfig"
636
637 source "crypto/Kconfig"
638diff -NurpP --minimal linux-3.6.6/arch/s390/include/asm/tlb.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/include/asm/tlb.h
639--- linux-3.6.6/arch/s390/include/asm/tlb.h 2012-07-22 23:38:59.000000000 +0200
640+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/include/asm/tlb.h 2012-10-04 18:47:00.000000000 +0200
641@@ -24,6 +24,7 @@
642 #include <linux/mm.h>
643 #include <linux/pagemap.h>
644 #include <linux/swap.h>
645+
646 #include <asm/processor.h>
647 #include <asm/pgalloc.h>
648 #include <asm/tlbflush.h>
649diff -NurpP --minimal linux-3.6.6/arch/s390/include/asm/unistd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/include/asm/unistd.h
650--- linux-3.6.6/arch/s390/include/asm/unistd.h 2012-10-04 15:26:55.000000000 +0200
651+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/include/asm/unistd.h 2012-10-04 18:47:00.000000000 +0200
652@@ -200,7 +200,7 @@
653 #define __NR_clock_gettime (__NR_timer_create+6)
654 #define __NR_clock_getres (__NR_timer_create+7)
655 #define __NR_clock_nanosleep (__NR_timer_create+8)
656-/* Number 263 is reserved for vserver */
657+#define __NR_vserver 263
658 #define __NR_statfs64 265
659 #define __NR_fstatfs64 266
660 #define __NR_remap_file_pages 267
661diff -NurpP --minimal linux-3.6.6/arch/s390/kernel/ptrace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/kernel/ptrace.c
662--- linux-3.6.6/arch/s390/kernel/ptrace.c 2012-10-04 15:26:55.000000000 +0200
663+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/kernel/ptrace.c 2012-10-04 18:47:00.000000000 +0200
664@@ -21,6 +21,7 @@
665 #include <linux/tracehook.h>
666 #include <linux/seccomp.h>
667 #include <linux/compat.h>
668+#include <linux/vs_base.h>
669 #include <trace/syscall.h>
670 #include <asm/segment.h>
671 #include <asm/page.h>
672diff -NurpP --minimal linux-3.6.6/arch/s390/kernel/syscalls.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/kernel/syscalls.S
673--- linux-3.6.6/arch/s390/kernel/syscalls.S 2012-01-09 16:14:06.000000000 +0100
674+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/s390/kernel/syscalls.S 2012-10-04 18:47:00.000000000 +0200
675@@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
676 SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper) /* 260 */
677 SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
678 SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
679-NI_SYSCALL /* reserved for vserver */
680+SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
681 SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
682 SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
683 SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
684diff -NurpP --minimal linux-3.6.6/arch/sh/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sh/Kconfig
685--- linux-3.6.6/arch/sh/Kconfig 2012-10-04 15:26:55.000000000 +0200
686+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sh/Kconfig 2012-10-04 18:47:00.000000000 +0200
687@@ -940,6 +940,8 @@ source "fs/Kconfig"
688
689 source "arch/sh/Kconfig.debug"
690
691+source "kernel/vserver/Kconfig"
692+
693 source "security/Kconfig"
694
695 source "crypto/Kconfig"
696diff -NurpP --minimal linux-3.6.6/arch/sh/kernel/irq.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sh/kernel/irq.c
697--- linux-3.6.6/arch/sh/kernel/irq.c 2012-10-04 15:26:56.000000000 +0200
698+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sh/kernel/irq.c 2012-10-04 18:47:00.000000000 +0200
699@@ -14,6 +14,7 @@
700 #include <linux/ftrace.h>
701 #include <linux/delay.h>
702 #include <linux/ratelimit.h>
703+// #include <linux/vs_context.h>
704 #include <asm/processor.h>
705 #include <asm/machvec.h>
706 #include <asm/uaccess.h>
707diff -NurpP --minimal linux-3.6.6/arch/sparc/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sparc/Kconfig
708--- linux-3.6.6/arch/sparc/Kconfig 2012-10-04 15:26:58.000000000 +0200
709+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sparc/Kconfig 2012-10-04 18:47:00.000000000 +0200
710@@ -593,6 +593,8 @@ source "fs/Kconfig"
711
712 source "arch/sparc/Kconfig.debug"
713
714+source "kernel/vserver/Kconfig"
715+
716 source "security/Kconfig"
717
718 source "crypto/Kconfig"
719diff -NurpP --minimal linux-3.6.6/arch/sparc/include/asm/unistd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sparc/include/asm/unistd.h
720--- linux-3.6.6/arch/sparc/include/asm/unistd.h 2012-10-04 15:26:59.000000000 +0200
721+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sparc/include/asm/unistd.h 2012-10-04 18:47:00.000000000 +0200
722@@ -335,7 +335,7 @@
723 #define __NR_timer_getoverrun 264
724 #define __NR_timer_delete 265
725 #define __NR_timer_create 266
726-/* #define __NR_vserver 267 Reserved for VSERVER */
727+#define __NR_vserver 267
728 #define __NR_io_setup 268
729 #define __NR_io_destroy 269
730 #define __NR_io_submit 270
731diff -NurpP --minimal linux-3.6.6/arch/sparc/kernel/systbls_32.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sparc/kernel/systbls_32.S
732--- linux-3.6.6/arch/sparc/kernel/systbls_32.S 2012-01-09 16:14:09.000000000 +0100
733+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sparc/kernel/systbls_32.S 2012-10-04 18:47:00.000000000 +0200
734@@ -70,7 +70,7 @@ sys_call_table:
735 /*250*/ .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
736 /*255*/ .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
737 /*260*/ .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
738-/*265*/ .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
739+/*265*/ .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
740 /*270*/ .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
741 /*275*/ .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
742 /*280*/ .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
743diff -NurpP --minimal linux-3.6.6/arch/sparc/kernel/systbls_64.S linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sparc/kernel/systbls_64.S
744--- linux-3.6.6/arch/sparc/kernel/systbls_64.S 2012-07-22 23:39:00.000000000 +0200
745+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/sparc/kernel/systbls_64.S 2012-10-04 18:47:00.000000000 +0200
746@@ -71,7 +71,7 @@ sys_call_table32:
747 /*250*/ .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys_nis_syscall
748 .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
749 /*260*/ .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
750- .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
751+ .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
752 /*270*/ .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
753 .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
754 /*280*/ .word sys32_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
755@@ -148,7 +148,7 @@ sys_call_table:
756 /*250*/ .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
757 .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
758 /*260*/ .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
759- .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
760+ .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
761 /*270*/ .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
762 .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
763 /*280*/ .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
764diff -NurpP --minimal linux-3.6.6/arch/um/Kconfig.rest linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/um/Kconfig.rest
765--- linux-3.6.6/arch/um/Kconfig.rest 2012-01-09 16:14:09.000000000 +0100
766+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/um/Kconfig.rest 2012-10-04 18:47:00.000000000 +0200
767@@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
768
769 source "fs/Kconfig"
770
771+source "kernel/vserver/Kconfig"
772+
773 source "security/Kconfig"
774
775 source "crypto/Kconfig"
776diff -NurpP --minimal linux-3.6.6/arch/um/include/shared/kern_constants.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/um/include/shared/kern_constants.h
777--- linux-3.6.6/arch/um/include/shared/kern_constants.h 1970-01-01 01:00:00.000000000 +0100
778+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/um/include/shared/kern_constants.h 2012-10-04 18:47:00.000000000 +0200
779@@ -0,0 +1 @@
780+#include "../../../../include/generated/asm-offsets.h"
781diff -NurpP --minimal linux-3.6.6/arch/um/include/shared/user_constants.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/um/include/shared/user_constants.h
782--- linux-3.6.6/arch/um/include/shared/user_constants.h 1970-01-01 01:00:00.000000000 +0100
783+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/um/include/shared/user_constants.h 2012-10-04 18:47:00.000000000 +0200
784@@ -0,0 +1,40 @@
785+/*
786+ * DO NOT MODIFY.
787+ *
788+ * This file was generated by arch/um/Makefile
789+ *
790+ */
791+
792+#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2) # */
793+#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err) # */
794+#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno) # */
795+#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long) # */
796+#define HOST_RBX 5 /* RBX # */
797+#define HOST_RCX 11 /* RCX # */
798+#define HOST_RDI 14 /* RDI # */
799+#define HOST_RSI 13 /* RSI # */
800+#define HOST_RDX 12 /* RDX # */
801+#define HOST_RBP 4 /* RBP # */
802+#define HOST_RAX 10 /* RAX # */
803+#define HOST_R8 9 /* R8 # */
804+#define HOST_R9 8 /* R9 # */
805+#define HOST_R10 7 /* R10 # */
806+#define HOST_R11 6 /* R11 # */
807+#define HOST_R12 3 /* R12 # */
808+#define HOST_R13 2 /* R13 # */
809+#define HOST_R14 1 /* R14 # */
810+#define HOST_R15 0 /* R15 # */
811+#define HOST_ORIG_RAX 15 /* ORIG_RAX # */
812+#define HOST_CS 17 /* CS # */
813+#define HOST_SS 20 /* SS # */
814+#define HOST_EFLAGS 18 /* EFLAGS # */
815+#define HOST_IP 16 /* RIP # */
816+#define HOST_SP 19 /* RSP # */
817+#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct) # */
818+#define UM_POLLIN 1 /* POLLIN # */
819+#define UM_POLLPRI 2 /* POLLPRI # */
820+#define UM_POLLOUT 4 /* POLLOUT # */
821+#define UM_PROT_READ 1 /* PROT_READ # */
822+#define UM_PROT_WRITE 2 /* PROT_WRITE # */
823+#define UM_PROT_EXEC 4 /* PROT_EXEC # */
824+
825diff -NurpP --minimal linux-3.6.6/arch/x86/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/x86/Kconfig
826--- linux-3.6.6/arch/x86/Kconfig 2012-10-04 15:27:00.000000000 +0200
827+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/x86/Kconfig 2012-10-04 18:47:00.000000000 +0200
828@@ -2228,6 +2228,8 @@ source "fs/Kconfig"
829
830 source "arch/x86/Kconfig.debug"
831
832+source "kernel/vserver/Kconfig"
833+
834 source "security/Kconfig"
835
836 source "crypto/Kconfig"
837diff -NurpP --minimal linux-3.6.6/arch/x86/syscalls/syscall_32.tbl linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/x86/syscalls/syscall_32.tbl
838--- linux-3.6.6/arch/x86/syscalls/syscall_32.tbl 2012-07-22 23:39:02.000000000 +0200
839+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/x86/syscalls/syscall_32.tbl 2012-10-04 18:47:00.000000000 +0200
840@@ -279,7 +279,7 @@
841 270 i386 tgkill sys_tgkill
842 271 i386 utimes sys_utimes compat_sys_utimes
843 272 i386 fadvise64_64 sys_fadvise64_64 sys32_fadvise64_64
844-273 i386 vserver
845+273 i386 vserver sys_vserver sys32_vserver
846 274 i386 mbind sys_mbind
847 275 i386 get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy
848 276 i386 set_mempolicy sys_set_mempolicy
849diff -NurpP --minimal linux-3.6.6/arch/x86/syscalls/syscall_64.tbl linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/x86/syscalls/syscall_64.tbl
850--- linux-3.6.6/arch/x86/syscalls/syscall_64.tbl 2012-10-04 15:27:01.000000000 +0200
851+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/arch/x86/syscalls/syscall_64.tbl 2012-10-04 18:47:00.000000000 +0200
852@@ -242,7 +242,7 @@
853 233 common epoll_ctl sys_epoll_ctl
854 234 common tgkill sys_tgkill
855 235 common utimes sys_utimes
856-236 64 vserver
857+236 64 vserver sys_vserver
858 237 common mbind sys_mbind
859 238 common set_mempolicy sys_set_mempolicy
860 239 common get_mempolicy sys_get_mempolicy
861diff -NurpP --minimal linux-3.6.6/drivers/block/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/block/Kconfig
862--- linux-3.6.6/drivers/block/Kconfig 2012-05-21 18:06:43.000000000 +0200
863+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/block/Kconfig 2012-10-04 18:47:00.000000000 +0200
864@@ -290,6 +290,13 @@ config BLK_DEV_CRYPTOLOOP
865
866 source "drivers/block/drbd/Kconfig"
867
868+config BLK_DEV_VROOT
869+ tristate "Virtual Root device support"
870+ depends on QUOTACTL
871+ ---help---
872+ Saying Y here will allow you to use quota/fs ioctls on a shared
873+ partition within a virtual server without compromising security.
874+
875 config BLK_DEV_NBD
876 tristate "Network block device support"
877 depends on NET
878diff -NurpP --minimal linux-3.6.6/drivers/block/Makefile linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/block/Makefile
879--- linux-3.6.6/drivers/block/Makefile 2012-03-19 19:46:52.000000000 +0100
880+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/block/Makefile 2012-10-04 18:47:00.000000000 +0200
881@@ -35,6 +35,7 @@ obj-$(CONFIG_VIODASD) += viodasd.o
882 obj-$(CONFIG_BLK_DEV_SX8) += sx8.o
883 obj-$(CONFIG_BLK_DEV_UB) += ub.o
884 obj-$(CONFIG_BLK_DEV_HD) += hd.o
885+obj-$(CONFIG_BLK_DEV_VROOT) += vroot.o
886
887 obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
888 obj-$(CONFIG_XEN_BLKDEV_BACKEND) += xen-blkback/
889diff -NurpP --minimal linux-3.6.6/drivers/block/loop.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/block/loop.c
890--- linux-3.6.6/drivers/block/loop.c 2012-07-22 23:39:02.000000000 +0200
891+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/block/loop.c 2012-10-04 18:47:00.000000000 +0200
892@@ -76,6 +76,7 @@
893 #include <linux/sysfs.h>
894 #include <linux/miscdevice.h>
895 #include <linux/falloc.h>
896+#include <linux/vs_context.h>
897
898 #include <asm/uaccess.h>
899
900@@ -869,6 +870,7 @@ static int loop_set_fd(struct loop_devic
901 lo->lo_blocksize = lo_blocksize;
902 lo->lo_device = bdev;
903 lo->lo_flags = lo_flags;
904+ lo->lo_xid = vx_current_xid();
905 lo->lo_backing_file = file;
906 lo->transfer = transfer_none;
907 lo->ioctl = NULL;
908@@ -1001,6 +1003,7 @@ static int loop_clr_fd(struct loop_devic
909 lo->lo_sizelimit = 0;
910 lo->lo_encrypt_key_size = 0;
911 lo->lo_thread = NULL;
912+ lo->lo_xid = 0;
913 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
914 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
915 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
916@@ -1042,7 +1045,7 @@ loop_set_status(struct loop_device *lo,
917
918 if (lo->lo_encrypt_key_size &&
919 lo->lo_key_owner != uid &&
920- !capable(CAP_SYS_ADMIN))
921+ !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
922 return -EPERM;
923 if (lo->lo_state != Lo_bound)
924 return -ENXIO;
925@@ -1132,7 +1135,8 @@ loop_get_status(struct loop_device *lo,
926 memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
927 info->lo_encrypt_type =
928 lo->lo_encryption ? lo->lo_encryption->number : 0;
929- if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
930+ if (lo->lo_encrypt_key_size &&
931+ vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
932 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
933 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
934 lo->lo_encrypt_key_size);
935@@ -1492,6 +1496,11 @@ static int lo_open(struct block_device *
936 goto out;
937 }
938
939+ if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
940+ err = -EACCES;
941+ goto out;
942+ }
943+
944 mutex_lock(&lo->lo_ctl_mutex);
945 lo->lo_refcnt++;
946 mutex_unlock(&lo->lo_ctl_mutex);
947diff -NurpP --minimal linux-3.6.6/drivers/block/vroot.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/block/vroot.c
948--- linux-3.6.6/drivers/block/vroot.c 1970-01-01 01:00:00.000000000 +0100
949+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/block/vroot.c 2012-10-04 18:47:00.000000000 +0200
950@@ -0,0 +1,291 @@
951+/*
952+ * linux/drivers/block/vroot.c
953+ *
954+ * written by Herbert Pötzl, 9/11/2002
955+ * ported to 2.6.10 by Herbert Pötzl, 30/12/2004
956+ *
957+ * based on the loop.c code by Theodore Ts'o.
958+ *
959+ * Copyright (C) 2002-2007 by Herbert Pötzl.
960+ * Redistribution of this file is permitted under the
961+ * GNU General Public License.
962+ *
963+ */
964+
965+#include <linux/module.h>
966+#include <linux/moduleparam.h>
967+#include <linux/file.h>
968+#include <linux/major.h>
969+#include <linux/blkdev.h>
970+#include <linux/slab.h>
971+
972+#include <linux/vroot.h>
973+#include <linux/vs_context.h>
974+
975+
976+static int max_vroot = 8;
977+
978+static struct vroot_device *vroot_dev;
979+static struct gendisk **disks;
980+
981+
982+static int vroot_set_dev(
983+ struct vroot_device *vr,
984+ struct block_device *bdev,
985+ unsigned int arg)
986+{
987+ struct block_device *real_bdev;
988+ struct file *file;
989+ struct inode *inode;
990+ int error;
991+
992+ error = -EBUSY;
993+ if (vr->vr_state != Vr_unbound)
994+ goto out;
995+
996+ error = -EBADF;
997+ file = fget(arg);
998+ if (!file)
999+ goto out;
1000+
1001+ error = -EINVAL;
1002+ inode = file->f_dentry->d_inode;
1003+
1004+
1005+ if (S_ISBLK(inode->i_mode)) {
1006+ real_bdev = inode->i_bdev;
1007+ vr->vr_device = real_bdev;
1008+ __iget(real_bdev->bd_inode);
1009+ } else
1010+ goto out_fput;
1011+
1012+ vxdprintk(VXD_CBIT(misc, 0),
1013+ "vroot[%d]_set_dev: dev=" VXF_DEV,
1014+ vr->vr_number, VXD_DEV(real_bdev));
1015+
1016+ vr->vr_state = Vr_bound;
1017+ error = 0;
1018+
1019+ out_fput:
1020+ fput(file);
1021+ out:
1022+ return error;
1023+}
1024+
1025+static int vroot_clr_dev(
1026+ struct vroot_device *vr,
1027+ struct block_device *bdev)
1028+{
1029+ struct block_device *real_bdev;
1030+
1031+ if (vr->vr_state != Vr_bound)
1032+ return -ENXIO;
1033+ if (vr->vr_refcnt > 1) /* we needed one fd for the ioctl */
1034+ return -EBUSY;
1035+
1036+ real_bdev = vr->vr_device;
1037+
1038+ vxdprintk(VXD_CBIT(misc, 0),
1039+ "vroot[%d]_clr_dev: dev=" VXF_DEV,
1040+ vr->vr_number, VXD_DEV(real_bdev));
1041+
1042+ bdput(real_bdev);
1043+ vr->vr_state = Vr_unbound;
1044+ vr->vr_device = NULL;
1045+ return 0;
1046+}
1047+
1048+
1049+static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1050+ unsigned int cmd, unsigned long arg)
1051+{
1052+ struct vroot_device *vr = bdev->bd_disk->private_data;
1053+ int err;
1054+
1055+ down(&vr->vr_ctl_mutex);
1056+ switch (cmd) {
1057+ case VROOT_SET_DEV:
1058+ err = vroot_set_dev(vr, bdev, arg);
1059+ break;
1060+ case VROOT_CLR_DEV:
1061+ err = vroot_clr_dev(vr, bdev);
1062+ break;
1063+ default:
1064+ err = -EINVAL;
1065+ break;
1066+ }
1067+ up(&vr->vr_ctl_mutex);
1068+ return err;
1069+}
1070+
1071+static int vr_open(struct block_device *bdev, fmode_t mode)
1072+{
1073+ struct vroot_device *vr = bdev->bd_disk->private_data;
1074+
1075+ down(&vr->vr_ctl_mutex);
1076+ vr->vr_refcnt++;
1077+ up(&vr->vr_ctl_mutex);
1078+ return 0;
1079+}
1080+
1081+static int vr_release(struct gendisk *disk, fmode_t mode)
1082+{
1083+ struct vroot_device *vr = disk->private_data;
1084+
1085+ down(&vr->vr_ctl_mutex);
1086+ --vr->vr_refcnt;
1087+ up(&vr->vr_ctl_mutex);
1088+ return 0;
1089+}
1090+
1091+static struct block_device_operations vr_fops = {
1092+ .owner = THIS_MODULE,
1093+ .open = vr_open,
1094+ .release = vr_release,
1095+ .ioctl = vr_ioctl,
1096+};
1097+
1098+static void vroot_make_request(struct request_queue *q, struct bio *bio)
1099+{
1100+ printk("vroot_make_request %p, %p\n", q, bio);
1101+ bio_io_error(bio);
1102+}
1103+
1104+struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1105+{
1106+ struct inode *inode = bdev->bd_inode;
1107+ struct vroot_device *vr;
1108+ struct block_device *real_bdev;
1109+ int minor = iminor(inode);
1110+
1111+ vr = &vroot_dev[minor];
1112+ real_bdev = vr->vr_device;
1113+
1114+ vxdprintk(VXD_CBIT(misc, 0),
1115+ "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1116+ vr->vr_number, VXD_DEV(real_bdev));
1117+
1118+ if (vr->vr_state != Vr_bound)
1119+ return ERR_PTR(-ENXIO);
1120+
1121+ __iget(real_bdev->bd_inode);
1122+ return real_bdev;
1123+}
1124+
1125+
1126+
1127+/*
1128+ * And now the modules code and kernel interface.
1129+ */
1130+
1131+module_param(max_vroot, int, 0);
1132+
1133+MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1134+MODULE_LICENSE("GPL");
1135+MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1136+
1137+MODULE_AUTHOR ("Herbert Pötzl");
1138+MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1139+
1140+
1141+int __init vroot_init(void)
1142+{
1143+ int err, i;
1144+
1145+ if (max_vroot < 1 || max_vroot > 256) {
1146+ max_vroot = MAX_VROOT_DEFAULT;
1147+ printk(KERN_WARNING "vroot: invalid max_vroot "
1148+ "(must be between 1 and 256), "
1149+ "using default (%d)\n", max_vroot);
1150+ }
1151+
1152+ if (register_blkdev(VROOT_MAJOR, "vroot"))
1153+ return -EIO;
1154+
1155+ err = -ENOMEM;
1156+ vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1157+ if (!vroot_dev)
1158+ goto out_mem1;
1159+ memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1160+
1161+ disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1162+ if (!disks)
1163+ goto out_mem2;
1164+
1165+ for (i = 0; i < max_vroot; i++) {
1166+ disks[i] = alloc_disk(1);
1167+ if (!disks[i])
1168+ goto out_mem3;
1169+ disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1170+ if (!disks[i]->queue)
1171+ goto out_mem3;
1172+ blk_queue_make_request(disks[i]->queue, vroot_make_request);
1173+ }
1174+
1175+ for (i = 0; i < max_vroot; i++) {
1176+ struct vroot_device *vr = &vroot_dev[i];
1177+ struct gendisk *disk = disks[i];
1178+
1179+ memset(vr, 0, sizeof(*vr));
1180+ sema_init(&vr->vr_ctl_mutex, 1);
1181+ vr->vr_number = i;
1182+ disk->major = VROOT_MAJOR;
1183+ disk->first_minor = i;
1184+ disk->fops = &vr_fops;
1185+ sprintf(disk->disk_name, "vroot%d", i);
1186+ disk->private_data = vr;
1187+ }
1188+
1189+ err = register_vroot_grb(&__vroot_get_real_bdev);
1190+ if (err)
1191+ goto out_mem3;
1192+
1193+ for (i = 0; i < max_vroot; i++)
1194+ add_disk(disks[i]);
1195+ printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1196+ return 0;
1197+
1198+out_mem3:
1199+ while (i--)
1200+ put_disk(disks[i]);
1201+ kfree(disks);
1202+out_mem2:
1203+ kfree(vroot_dev);
1204+out_mem1:
1205+ unregister_blkdev(VROOT_MAJOR, "vroot");
1206+ printk(KERN_ERR "vroot: ran out of memory\n");
1207+ return err;
1208+}
1209+
1210+void vroot_exit(void)
1211+{
1212+ int i;
1213+
1214+ if (unregister_vroot_grb(&__vroot_get_real_bdev))
1215+ printk(KERN_WARNING "vroot: cannot unregister grb\n");
1216+
1217+ for (i = 0; i < max_vroot; i++) {
1218+ del_gendisk(disks[i]);
1219+ put_disk(disks[i]);
1220+ }
1221+ unregister_blkdev(VROOT_MAJOR, "vroot");
1222+
1223+ kfree(disks);
1224+ kfree(vroot_dev);
1225+}
1226+
1227+module_init(vroot_init);
1228+module_exit(vroot_exit);
1229+
1230+#ifndef MODULE
1231+
1232+static int __init max_vroot_setup(char *str)
1233+{
1234+ max_vroot = simple_strtol(str, NULL, 0);
1235+ return 1;
1236+}
1237+
1238+__setup("max_vroot=", max_vroot_setup);
1239+
1240+#endif
1241+
1242diff -NurpP --minimal linux-3.6.6/drivers/infiniband/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/infiniband/Kconfig
1243--- linux-3.6.6/drivers/infiniband/Kconfig 2012-07-22 23:39:06.000000000 +0200
1244+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/infiniband/Kconfig 2012-10-04 18:47:00.000000000 +0200
1245@@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1246 config INFINIBAND_ADDR_TRANS
1247 bool
1248 depends on INET
1249- depends on !(INFINIBAND = y && IPV6 = m)
1250+ depends on !(INFINIBAND = y && IPV6 = y)
1251 default y
1252
1253 source "drivers/infiniband/hw/mthca/Kconfig"
1254diff -NurpP --minimal linux-3.6.6/drivers/infiniband/core/addr.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/infiniband/core/addr.c
1255--- linux-3.6.6/drivers/infiniband/core/addr.c 2012-10-04 15:27:10.000000000 +0200
1256+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/infiniband/core/addr.c 2012-10-04 18:47:00.000000000 +0200
1257@@ -263,7 +263,7 @@ static int addr6_resolve(struct sockaddr
1258
1259 if (ipv6_addr_any(&fl6.saddr)) {
1260 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1261- &fl6.daddr, 0, &fl6.saddr);
1262+ &fl6.daddr, 0, &fl6.saddr, NULL);
1263 if (ret)
1264 goto put;
1265
1266diff -NurpP --minimal linux-3.6.6/drivers/md/dm-ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/md/dm-ioctl.c
1267--- linux-3.6.6/drivers/md/dm-ioctl.c 2012-10-04 15:27:11.000000000 +0200
1268+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/md/dm-ioctl.c 2012-10-04 18:47:00.000000000 +0200
1269@@ -16,6 +16,7 @@
1270 #include <linux/dm-ioctl.h>
1271 #include <linux/hdreg.h>
1272 #include <linux/compat.h>
1273+#include <linux/vs_context.h>
1274
1275 #include <asm/uaccess.h>
1276
1277@@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1278 unsigned int h = hash_str(str);
1279
1280 list_for_each_entry (hc, _name_buckets + h, name_list)
1281- if (!strcmp(hc->name, str)) {
1282+ if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1283+ !strcmp(hc->name, str)) {
1284 dm_get(hc->md);
1285 return hc;
1286 }
1287@@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1288 unsigned int h = hash_str(str);
1289
1290 list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1291- if (!strcmp(hc->uuid, str)) {
1292+ if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1293+ !strcmp(hc->uuid, str)) {
1294 dm_get(hc->md);
1295 return hc;
1296 }
1297@@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1298 static struct hash_cell *__get_dev_cell(uint64_t dev)
1299 {
1300 struct mapped_device *md;
1301- struct hash_cell *hc;
1302+ struct hash_cell *hc = NULL;
1303
1304 md = dm_get_md(huge_decode_dev(dev));
1305 if (!md)
1306 return NULL;
1307
1308- hc = dm_get_mdptr(md);
1309+ if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1310+ hc = dm_get_mdptr(md);
1311+
1312 if (!hc) {
1313 dm_put(md);
1314 return NULL;
1315@@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1316
1317 static int remove_all(struct dm_ioctl *param, size_t param_size)
1318 {
1319+ if (!vx_check(0, VS_ADMIN))
1320+ return -EPERM;
1321+
1322 dm_hash_remove_all(1);
1323 param->data_size = 0;
1324 return 0;
1325@@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1326 */
1327 for (i = 0; i < NUM_BUCKETS; i++) {
1328 list_for_each_entry (hc, _name_buckets + i, name_list) {
1329+ if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1330+ continue;
1331 needed += sizeof(struct dm_name_list);
1332 needed += strlen(hc->name) + 1;
1333 needed += ALIGN_MASK;
1334@@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1335 */
1336 for (i = 0; i < NUM_BUCKETS; i++) {
1337 list_for_each_entry (hc, _name_buckets + i, name_list) {
1338+ if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1339+ continue;
1340 if (old_nl)
1341 old_nl->next = (uint32_t) ((void *) nl -
1342 (void *) old_nl);
1343@@ -1619,8 +1631,8 @@ static int ctl_ioctl(uint command, struc
1344 ioctl_fn fn = NULL;
1345 size_t input_param_size;
1346
1347- /* only root can play with this */
1348- if (!capable(CAP_SYS_ADMIN))
1349+ /* only root and certain contexts can play with this */
1350+ if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1351 return -EACCES;
1352
1353 if (_IOC_TYPE(command) != DM_IOCTL)
1354diff -NurpP --minimal linux-3.6.6/drivers/md/dm.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/md/dm.c
1355--- linux-3.6.6/drivers/md/dm.c 2012-10-04 15:27:11.000000000 +0200
1356+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/md/dm.c 2012-10-04 18:47:00.000000000 +0200
1357@@ -19,6 +19,7 @@
1358 #include <linux/idr.h>
1359 #include <linux/hdreg.h>
1360 #include <linux/delay.h>
1361+#include <linux/vs_base.h>
1362
1363 #include <trace/events/block.h>
1364
1365@@ -131,6 +132,7 @@ struct mapped_device {
1366 rwlock_t map_lock;
1367 atomic_t holders;
1368 atomic_t open_count;
1369+ xid_t xid;
1370
1371 unsigned long flags;
1372
1373@@ -343,6 +345,7 @@ int dm_deleting_md(struct mapped_device
1374 static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1375 {
1376 struct mapped_device *md;
1377+ int ret = -ENXIO;
1378
1379 spin_lock(&_minor_lock);
1380
1381@@ -351,18 +354,19 @@ static int dm_blk_open(struct block_devi
1382 goto out;
1383
1384 if (test_bit(DMF_FREEING, &md->flags) ||
1385- dm_deleting_md(md)) {
1386- md = NULL;
1387+ dm_deleting_md(md))
1388+ goto out;
1389+
1390+ ret = -EACCES;
1391+ if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1392 goto out;
1393- }
1394
1395 dm_get(md);
1396 atomic_inc(&md->open_count);
1397-
1398+ ret = 0;
1399 out:
1400 spin_unlock(&_minor_lock);
1401-
1402- return md ? 0 : -ENXIO;
1403+ return ret;
1404 }
1405
1406 static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1407@@ -583,6 +587,14 @@ int dm_set_geometry(struct mapped_device
1408 return 0;
1409 }
1410
1411+/*
1412+ * Get the xid associated with a dm device
1413+ */
1414+xid_t dm_get_xid(struct mapped_device *md)
1415+{
1416+ return md->xid;
1417+}
1418+
1419 /*-----------------------------------------------------------------
1420 * CRUD START:
1421 * A more elegant soln is in the works that uses the queue
1422@@ -1892,6 +1904,7 @@ static struct mapped_device *alloc_dev(i
1423 INIT_LIST_HEAD(&md->uevent_list);
1424 spin_lock_init(&md->uevent_lock);
1425
1426+ md->xid = vx_current_xid();
1427 md->queue = blk_alloc_queue(GFP_KERNEL);
1428 if (!md->queue)
1429 goto bad_queue;
1430diff -NurpP --minimal linux-3.6.6/drivers/md/dm.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/md/dm.h
1431--- linux-3.6.6/drivers/md/dm.h 2012-10-04 15:27:11.000000000 +0200
1432+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/md/dm.h 2012-10-04 18:47:00.000000000 +0200
1433@@ -46,6 +46,8 @@ struct dm_dev_internal {
1434 struct dm_table;
1435 struct dm_md_mempools;
1436
1437+xid_t dm_get_xid(struct mapped_device *md);
1438+
1439 /*-----------------------------------------------------------------
1440 * Internal table functions.
1441 *---------------------------------------------------------------*/
1442diff -NurpP --minimal linux-3.6.6/drivers/net/tun.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/net/tun.c
1443--- linux-3.6.6/drivers/net/tun.c 2012-10-04 15:27:20.000000000 +0200
1444+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/net/tun.c 2012-10-04 18:47:00.000000000 +0200
1445@@ -64,6 +64,7 @@
1446 #include <linux/nsproxy.h>
1447 #include <linux/virtio_net.h>
1448 #include <linux/rcupdate.h>
1449+#include <linux/vs_network.h>
1450 #include <net/net_namespace.h>
1451 #include <net/netns/generic.h>
1452 #include <net/rtnetlink.h>
1453@@ -122,6 +123,7 @@ struct tun_struct {
1454 unsigned int flags;
1455 uid_t owner;
1456 gid_t group;
1457+ nid_t nid;
1458
1459 struct net_device *dev;
1460 netdev_features_t set_features;
1461@@ -1033,6 +1035,7 @@ static void tun_setup(struct net_device
1462
1463 tun->owner = -1;
1464 tun->group = -1;
1465+ tun->nid = current->nid;
1466
1467 dev->ethtool_ops = &tun_ethtool_ops;
1468 dev->destructor = tun_free_netdev;
1469@@ -1191,7 +1194,7 @@ static int tun_set_iff(struct net *net,
1470
1471 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1472 (tun->group != -1 && !in_egroup_p(tun->group))) &&
1473- !capable(CAP_NET_ADMIN))
1474+ !cap_raised(current_cap(), CAP_NET_ADMIN))
1475 return -EPERM;
1476 err = security_tun_dev_attach(tun->socket.sk);
1477 if (err < 0)
1478@@ -1205,7 +1208,7 @@ static int tun_set_iff(struct net *net,
1479 char *name;
1480 unsigned long flags = 0;
1481
1482- if (!capable(CAP_NET_ADMIN))
1483+ if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1484 return -EPERM;
1485 err = security_tun_dev_create();
1486 if (err < 0)
1487@@ -1276,6 +1279,9 @@ static int tun_set_iff(struct net *net,
1488
1489 sk->sk_destruct = tun_sock_destruct;
1490
1491+ if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1492+ return -EPERM;
1493+
1494 err = tun_attach(tun, file);
1495 if (err < 0)
1496 goto failed;
1497@@ -1459,6 +1465,16 @@ static long __tun_chr_ioctl(struct file
1498 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1499 break;
1500
1501+ case TUNSETNID:
1502+ if (!capable(CAP_CONTEXT))
1503+ return -EPERM;
1504+
1505+ /* Set nid owner of the device */
1506+ tun->nid = (nid_t) arg;
1507+
1508+ tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1509+ break;
1510+
1511 case TUNSETLINK:
1512 /* Only allow setting the type when the interface is down */
1513 if (tun->dev->flags & IFF_UP) {
1514diff -NurpP --minimal linux-3.6.6/drivers/tty/sysrq.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/tty/sysrq.c
1515--- linux-3.6.6/drivers/tty/sysrq.c 2012-05-21 18:07:16.000000000 +0200
1516+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/tty/sysrq.c 2012-10-04 18:47:00.000000000 +0200
1517@@ -41,6 +41,7 @@
1518 #include <linux/slab.h>
1519 #include <linux/input.h>
1520 #include <linux/uaccess.h>
1521+#include <linux/vserver/debug.h>
1522
1523 #include <asm/ptrace.h>
1524 #include <asm/irq_regs.h>
1525@@ -398,6 +399,21 @@ static struct sysrq_key_op sysrq_unrt_op
1526 .enable_mask = SYSRQ_ENABLE_RTNICE,
1527 };
1528
1529+
1530+#ifdef CONFIG_VSERVER_DEBUG
1531+static void sysrq_handle_vxinfo(int key)
1532+{
1533+ dump_vx_info_inactive((key == 'x') ? 0 : 1);
1534+}
1535+
1536+static struct sysrq_key_op sysrq_showvxinfo_op = {
1537+ .handler = sysrq_handle_vxinfo,
1538+ .help_msg = "conteXt",
1539+ .action_msg = "Show Context Info",
1540+ .enable_mask = SYSRQ_ENABLE_DUMP,
1541+};
1542+#endif
1543+
1544 /* Key Operations table and lock */
1545 static DEFINE_SPINLOCK(sysrq_key_table_lock);
1546
1547@@ -452,7 +468,11 @@ static struct sysrq_key_op *sysrq_key_ta
1548 NULL, /* v */
1549 &sysrq_showstate_blocked_op, /* w */
1550 /* x: May be registered on ppc/powerpc for xmon */
1551+#ifdef CONFIG_VSERVER_DEBUG
1552+ &sysrq_showvxinfo_op, /* x */
1553+#else
1554 NULL, /* x */
1555+#endif
1556 /* y: May be registered on sparc64 for global register dump */
1557 NULL, /* y */
1558 &sysrq_ftrace_dump_op, /* z */
1559@@ -467,6 +487,8 @@ static int sysrq_key_table_key2index(int
1560 retval = key - '0';
1561 else if ((key >= 'a') && (key <= 'z'))
1562 retval = key + 10 - 'a';
1563+ else if ((key >= 'A') && (key <= 'Z'))
1564+ retval = key + 10 - 'A';
1565 else
1566 retval = -1;
1567 return retval;
1568diff -NurpP --minimal linux-3.6.6/drivers/tty/tty_io.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/tty/tty_io.c
1569--- linux-3.6.6/drivers/tty/tty_io.c 2012-07-22 23:39:32.000000000 +0200
1570+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/drivers/tty/tty_io.c 2012-10-04 18:47:00.000000000 +0200
1571@@ -104,6 +104,7 @@
1572
1573 #include <linux/kmod.h>
1574 #include <linux/nsproxy.h>
1575+#include <linux/vs_pid.h>
1576
1577 #undef TTY_DEBUG_HANGUP
1578
1579@@ -2123,7 +2124,8 @@ static int tiocsti(struct tty_struct *tt
1580 char ch, mbz = 0;
1581 struct tty_ldisc *ld;
1582
1583- if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1584+ if (((current->signal->tty != tty) &&
1585+ !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1586 return -EPERM;
1587 if (get_user(ch, p))
1588 return -EFAULT;
1589@@ -2411,6 +2413,7 @@ static int tiocspgrp(struct tty_struct *
1590 return -ENOTTY;
1591 if (get_user(pgrp_nr, p))
1592 return -EFAULT;
1593+ pgrp_nr = vx_rmap_pid(pgrp_nr);
1594 if (pgrp_nr < 0)
1595 return -EINVAL;
1596 rcu_read_lock();
1597diff -NurpP --minimal linux-3.6.6/fs/attr.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/attr.c
1598--- linux-3.6.6/fs/attr.c 2012-10-04 15:27:39.000000000 +0200
1599+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/attr.c 2012-10-04 18:47:00.000000000 +0200
1600@@ -14,6 +14,9 @@
1601 #include <linux/fcntl.h>
1602 #include <linux/security.h>
1603 #include <linux/evm.h>
1604+#include <linux/proc_fs.h>
1605+#include <linux/devpts_fs.h>
1606+#include <linux/vs_tag.h>
1607
1608 /**
1609 * inode_change_ok - check if attribute changes to an inode are allowed
1610@@ -74,6 +77,10 @@ int inode_change_ok(const struct inode *
1611 return -EPERM;
1612 }
1613
1614+ /* check for inode tag permission */
1615+ if (dx_permission(inode, MAY_WRITE))
1616+ return -EACCES;
1617+
1618 return 0;
1619 }
1620 EXPORT_SYMBOL(inode_change_ok);
1621@@ -144,6 +151,8 @@ void setattr_copy(struct inode *inode, c
1622 inode->i_uid = attr->ia_uid;
1623 if (ia_valid & ATTR_GID)
1624 inode->i_gid = attr->ia_gid;
1625+ if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1626+ inode->i_tag = attr->ia_tag;
1627 if (ia_valid & ATTR_ATIME)
1628 inode->i_atime = timespec_trunc(attr->ia_atime,
1629 inode->i_sb->s_time_gran);
1630@@ -173,7 +182,8 @@ int notify_change(struct dentry * dentry
1631
1632 WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1633
1634- if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1635+ if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1636+ ATTR_TAG | ATTR_TIMES_SET)) {
1637 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1638 return -EPERM;
1639 }
1640diff -NurpP --minimal linux-3.6.6/fs/block_dev.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/block_dev.c
1641--- linux-3.6.6/fs/block_dev.c 2012-10-04 15:27:39.000000000 +0200
1642+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/block_dev.c 2012-10-04 18:47:00.000000000 +0200
1643@@ -27,6 +27,7 @@
1644 #include <linux/namei.h>
1645 #include <linux/log2.h>
1646 #include <linux/cleancache.h>
1647+#include <linux/vs_device.h>
1648 #include <asm/uaccess.h>
1649 #include "internal.h"
1650
1651@@ -581,6 +582,7 @@ struct block_device *bdget(dev_t dev)
1652 bdev->bd_invalidated = 0;
1653 inode->i_mode = S_IFBLK;
1654 inode->i_rdev = dev;
1655+ inode->i_mdev = dev;
1656 inode->i_bdev = bdev;
1657 inode->i_data.a_ops = &def_blk_aops;
1658 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1659@@ -627,6 +629,11 @@ EXPORT_SYMBOL(bdput);
1660 static struct block_device *bd_acquire(struct inode *inode)
1661 {
1662 struct block_device *bdev;
1663+ dev_t mdev;
1664+
1665+ if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1666+ return NULL;
1667+ inode->i_mdev = mdev;
1668
1669 spin_lock(&bdev_lock);
1670 bdev = inode->i_bdev;
1671@@ -637,7 +644,7 @@ static struct block_device *bd_acquire(s
1672 }
1673 spin_unlock(&bdev_lock);
1674
1675- bdev = bdget(inode->i_rdev);
1676+ bdev = bdget(mdev);
1677 if (bdev) {
1678 spin_lock(&bdev_lock);
1679 if (!inode->i_bdev) {
1680diff -NurpP --minimal linux-3.6.6/fs/btrfs/ctree.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/ctree.h
1681--- linux-3.6.6/fs/btrfs/ctree.h 2012-10-04 15:27:39.000000000 +0200
1682+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/ctree.h 2012-10-04 18:47:00.000000000 +0200
1683@@ -674,11 +674,14 @@ struct btrfs_inode_item {
1684 /* modification sequence number for NFS */
1685 __le64 sequence;
1686
1687+ __le16 tag;
1688 /*
1689 * a little future expansion, for more than this we can
1690 * just grow the inode item and version it
1691 */
1692- __le64 reserved[4];
1693+ __le16 reserved16;
1694+ __le32 reserved32;
1695+ __le64 reserved[3];
1696 struct btrfs_timespec atime;
1697 struct btrfs_timespec ctime;
1698 struct btrfs_timespec mtime;
1699@@ -1727,6 +1730,8 @@ struct btrfs_ioctl_defrag_range_args {
1700 #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1701 #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22)
1702
1703+#define BTRFS_MOUNT_TAGGED (1 << 24)
1704+
1705 #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1706 #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
1707 #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \
1708@@ -1988,6 +1993,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1709 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1710 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1711 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1712+BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1713 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1714 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1715 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1716@@ -2041,6 +2047,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1717
1718 BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1719
1720+#define BTRFS_INODE_IXUNLINK (1 << 24)
1721+#define BTRFS_INODE_BARRIER (1 << 25)
1722+#define BTRFS_INODE_COW (1 << 26)
1723+
1724
1725 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1726
1727@@ -3305,6 +3315,7 @@ extern const struct dentry_operations bt
1728 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1729 void btrfs_update_iflags(struct inode *inode);
1730 void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1731+int btrfs_sync_flags(struct inode *inode, int, int);
1732 int btrfs_defrag_file(struct inode *inode, struct file *file,
1733 struct btrfs_ioctl_defrag_range_args *range,
1734 u64 newer_than, unsigned long max_pages);
1735diff -NurpP --minimal linux-3.6.6/fs/btrfs/disk-io.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/disk-io.c
1736--- linux-3.6.6/fs/btrfs/disk-io.c 2012-10-04 15:27:39.000000000 +0200
1737+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/disk-io.c 2012-10-04 18:47:00.000000000 +0200
1738@@ -2187,6 +2187,9 @@ int open_ctree(struct super_block *sb,
1739 goto fail_alloc;
1740 }
1741
1742+ if (btrfs_test_opt(tree_root, TAGGED))
1743+ sb->s_flags |= MS_TAGGED;
1744+
1745 features = btrfs_super_incompat_flags(disk_super) &
1746 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1747 if (features) {
1748diff -NurpP --minimal linux-3.6.6/fs/btrfs/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/inode.c
1749--- linux-3.6.6/fs/btrfs/inode.c 2012-10-04 15:27:39.000000000 +0200
1750+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/inode.c 2012-10-04 18:47:00.000000000 +0200
1751@@ -39,6 +39,7 @@
1752 #include <linux/slab.h>
1753 #include <linux/ratelimit.h>
1754 #include <linux/mount.h>
1755+#include <linux/vs_tag.h>
1756 #include "compat.h"
1757 #include "ctree.h"
1758 #include "disk-io.h"
1759@@ -2545,6 +2546,8 @@ static void btrfs_read_locked_inode(stru
1760 struct btrfs_key location;
1761 int maybe_acls;
1762 u32 rdev;
1763+ uid_t uid;
1764+ gid_t gid;
1765 int ret;
1766 bool filled = false;
1767
1768@@ -2572,8 +2575,13 @@ static void btrfs_read_locked_inode(stru
1769 struct btrfs_inode_item);
1770 inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1771 set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1772- inode->i_uid = btrfs_inode_uid(leaf, inode_item);
1773- inode->i_gid = btrfs_inode_gid(leaf, inode_item);
1774+
1775+ uid = btrfs_inode_uid(leaf, inode_item);
1776+ gid = btrfs_inode_gid(leaf, inode_item);
1777+ inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
1778+ inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
1779+ inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
1780+ btrfs_inode_tag(leaf, inode_item));
1781 btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1782
1783 tspec = btrfs_inode_atime(inode_item);
1784@@ -2651,8 +2659,14 @@ static void fill_inode_item(struct btrfs
1785 struct btrfs_inode_item *item,
1786 struct inode *inode)
1787 {
1788- btrfs_set_inode_uid(leaf, item, inode->i_uid);
1789- btrfs_set_inode_gid(leaf, item, inode->i_gid);
1790+ uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
1791+ gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
1792+
1793+ btrfs_set_inode_uid(leaf, item, uid);
1794+ btrfs_set_inode_gid(leaf, item, gid);
1795+#ifdef CONFIG_TAGGING_INTERN
1796+ btrfs_set_inode_tag(leaf, item, inode->i_tag);
1797+#endif
1798 btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1799 btrfs_set_inode_mode(leaf, item, inode->i_mode);
1800 btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1801@@ -7636,11 +7650,13 @@ static const struct inode_operations btr
1802 .listxattr = btrfs_listxattr,
1803 .removexattr = btrfs_removexattr,
1804 .permission = btrfs_permission,
1805+ .sync_flags = btrfs_sync_flags,
1806 .get_acl = btrfs_get_acl,
1807 };
1808 static const struct inode_operations btrfs_dir_ro_inode_operations = {
1809 .lookup = btrfs_lookup,
1810 .permission = btrfs_permission,
1811+ .sync_flags = btrfs_sync_flags,
1812 .get_acl = btrfs_get_acl,
1813 };
1814
1815diff -NurpP --minimal linux-3.6.6/fs/btrfs/ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/ioctl.c
1816--- linux-3.6.6/fs/btrfs/ioctl.c 2012-10-04 15:27:39.000000000 +0200
1817+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/ioctl.c 2012-10-04 18:47:00.000000000 +0200
1818@@ -74,10 +74,13 @@ static unsigned int btrfs_flags_to_ioctl
1819 {
1820 unsigned int iflags = 0;
1821
1822- if (flags & BTRFS_INODE_SYNC)
1823- iflags |= FS_SYNC_FL;
1824 if (flags & BTRFS_INODE_IMMUTABLE)
1825 iflags |= FS_IMMUTABLE_FL;
1826+ if (flags & BTRFS_INODE_IXUNLINK)
1827+ iflags |= FS_IXUNLINK_FL;
1828+
1829+ if (flags & BTRFS_INODE_SYNC)
1830+ iflags |= FS_SYNC_FL;
1831 if (flags & BTRFS_INODE_APPEND)
1832 iflags |= FS_APPEND_FL;
1833 if (flags & BTRFS_INODE_NODUMP)
1834@@ -94,28 +97,78 @@ static unsigned int btrfs_flags_to_ioctl
1835 else if (flags & BTRFS_INODE_NOCOMPRESS)
1836 iflags |= FS_NOCOMP_FL;
1837
1838+ if (flags & BTRFS_INODE_BARRIER)
1839+ iflags |= FS_BARRIER_FL;
1840+ if (flags & BTRFS_INODE_COW)
1841+ iflags |= FS_COW_FL;
1842 return iflags;
1843 }
1844
1845 /*
1846- * Update inode->i_flags based on the btrfs internal flags.
1847+ * Update inode->i_(v)flags based on the btrfs internal flags.
1848 */
1849 void btrfs_update_iflags(struct inode *inode)
1850 {
1851 struct btrfs_inode *ip = BTRFS_I(inode);
1852
1853- inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1854+ inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1855+ S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1856
1857- if (ip->flags & BTRFS_INODE_SYNC)
1858- inode->i_flags |= S_SYNC;
1859 if (ip->flags & BTRFS_INODE_IMMUTABLE)
1860 inode->i_flags |= S_IMMUTABLE;
1861+ if (ip->flags & BTRFS_INODE_IXUNLINK)
1862+ inode->i_flags |= S_IXUNLINK;
1863+
1864+ if (ip->flags & BTRFS_INODE_SYNC)
1865+ inode->i_flags |= S_SYNC;
1866 if (ip->flags & BTRFS_INODE_APPEND)
1867 inode->i_flags |= S_APPEND;
1868 if (ip->flags & BTRFS_INODE_NOATIME)
1869 inode->i_flags |= S_NOATIME;
1870 if (ip->flags & BTRFS_INODE_DIRSYNC)
1871 inode->i_flags |= S_DIRSYNC;
1872+
1873+ inode->i_vflags &= ~(V_BARRIER | V_COW);
1874+
1875+ if (ip->flags & BTRFS_INODE_BARRIER)
1876+ inode->i_vflags |= V_BARRIER;
1877+ if (ip->flags & BTRFS_INODE_COW)
1878+ inode->i_vflags |= V_COW;
1879+}
1880+
1881+/*
1882+ * Update btrfs internal flags from inode->i_(v)flags.
1883+ */
1884+void btrfs_update_flags(struct inode *inode)
1885+{
1886+ struct btrfs_inode *ip = BTRFS_I(inode);
1887+
1888+ unsigned int flags = inode->i_flags;
1889+ unsigned int vflags = inode->i_vflags;
1890+
1891+ ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1892+ BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1893+ BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1894+ BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1895+
1896+ if (flags & S_IMMUTABLE)
1897+ ip->flags |= BTRFS_INODE_IMMUTABLE;
1898+ if (flags & S_IXUNLINK)
1899+ ip->flags |= BTRFS_INODE_IXUNLINK;
1900+
1901+ if (flags & S_SYNC)
1902+ ip->flags |= BTRFS_INODE_SYNC;
1903+ if (flags & S_APPEND)
1904+ ip->flags |= BTRFS_INODE_APPEND;
1905+ if (flags & S_NOATIME)
1906+ ip->flags |= BTRFS_INODE_NOATIME;
1907+ if (flags & S_DIRSYNC)
1908+ ip->flags |= BTRFS_INODE_DIRSYNC;
1909+
1910+ if (vflags & V_BARRIER)
1911+ ip->flags |= BTRFS_INODE_BARRIER;
1912+ if (vflags & V_COW)
1913+ ip->flags |= BTRFS_INODE_COW;
1914 }
1915
1916 /*
1917@@ -131,6 +184,7 @@ void btrfs_inherit_iflags(struct inode *
1918 return;
1919
1920 flags = BTRFS_I(dir)->flags;
1921+ flags &= ~BTRFS_INODE_BARRIER;
1922
1923 if (flags & BTRFS_INODE_NOCOMPRESS) {
1924 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1925@@ -146,6 +200,30 @@ void btrfs_inherit_iflags(struct inode *
1926 btrfs_update_iflags(inode);
1927 }
1928
1929+int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1930+{
1931+ struct btrfs_inode *ip = BTRFS_I(inode);
1932+ struct btrfs_root *root = ip->root;
1933+ struct btrfs_trans_handle *trans;
1934+ int ret;
1935+
1936+ trans = btrfs_join_transaction(root);
1937+ BUG_ON(!trans);
1938+
1939+ inode->i_flags = flags;
1940+ inode->i_vflags = vflags;
1941+ btrfs_update_flags(inode);
1942+
1943+ ret = btrfs_update_inode(trans, root, inode);
1944+ BUG_ON(ret);
1945+
1946+ btrfs_update_iflags(inode);
1947+ inode->i_ctime = CURRENT_TIME;
1948+ btrfs_end_transaction(trans, root);
1949+
1950+ return 0;
1951+}
1952+
1953 static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1954 {
1955 struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
1956@@ -206,21 +284,27 @@ static int btrfs_ioctl_setflags(struct f
1957
1958 flags = btrfs_mask_flags(inode->i_mode, flags);
1959 oldflags = btrfs_flags_to_ioctl(ip->flags);
1960- if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1961+ if ((flags ^ oldflags) & (FS_APPEND_FL |
1962+ FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1963 if (!capable(CAP_LINUX_IMMUTABLE)) {
1964 ret = -EPERM;
1965 goto out_unlock;
1966 }
1967 }
1968
1969- if (flags & FS_SYNC_FL)
1970- ip->flags |= BTRFS_INODE_SYNC;
1971- else
1972- ip->flags &= ~BTRFS_INODE_SYNC;
1973 if (flags & FS_IMMUTABLE_FL)
1974 ip->flags |= BTRFS_INODE_IMMUTABLE;
1975 else
1976 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1977+ if (flags & FS_IXUNLINK_FL)
1978+ ip->flags |= BTRFS_INODE_IXUNLINK;
1979+ else
1980+ ip->flags &= ~BTRFS_INODE_IXUNLINK;
1981+
1982+ if (flags & FS_SYNC_FL)
1983+ ip->flags |= BTRFS_INODE_SYNC;
1984+ else
1985+ ip->flags &= ~BTRFS_INODE_SYNC;
1986 if (flags & FS_APPEND_FL)
1987 ip->flags |= BTRFS_INODE_APPEND;
1988 else
1989diff -NurpP --minimal linux-3.6.6/fs/btrfs/super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/super.c
1990--- linux-3.6.6/fs/btrfs/super.c 2012-10-04 15:27:39.000000000 +0200
1991+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/btrfs/super.c 2012-10-04 18:47:00.000000000 +0200
1992@@ -306,7 +306,7 @@ enum {
1993 Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
1994 Opt_check_integrity, Opt_check_integrity_including_extent_data,
1995 Opt_check_integrity_print_mask, Opt_fatal_errors,
1996- Opt_err,
1997+ Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1998 };
1999
2000 static match_table_t tokens = {
2001@@ -346,6 +346,9 @@ static match_table_t tokens = {
2002 {Opt_check_integrity_including_extent_data, "check_int_data"},
2003 {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
2004 {Opt_fatal_errors, "fatal_errors=%s"},
2005+ {Opt_tag, "tag"},
2006+ {Opt_notag, "notag"},
2007+ {Opt_tagid, "tagid=%u"},
2008 {Opt_err, NULL},
2009 };
2010
2011@@ -596,6 +599,22 @@ int btrfs_parse_options(struct btrfs_roo
2012 goto out;
2013 }
2014 break;
2015+#ifndef CONFIG_TAGGING_NONE
2016+ case Opt_tag:
2017+ printk(KERN_INFO "btrfs: use tagging\n");
2018+ btrfs_set_opt(info->mount_opt, TAGGED);
2019+ break;
2020+ case Opt_notag:
2021+ printk(KERN_INFO "btrfs: disabled tagging\n");
2022+ btrfs_clear_opt(info->mount_opt, TAGGED);
2023+ break;
2024+#endif
2025+#ifdef CONFIG_PROPAGATE
2026+ case Opt_tagid:
2027+ /* use args[0] */
2028+ btrfs_set_opt(info->mount_opt, TAGGED);
2029+ break;
2030+#endif
2031 case Opt_err:
2032 printk(KERN_INFO "btrfs: unrecognized mount option "
2033 "'%s'\n", p);
2034@@ -1196,6 +1215,12 @@ static int btrfs_remount(struct super_bl
2035 btrfs_resize_thread_pool(fs_info,
2036 fs_info->thread_pool_size, old_thread_pool_size);
2037
2038+ if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2039+ printk("btrfs: %s: tagging not permitted on remount.\n",
2040+ sb->s_id);
2041+ return -EINVAL;
2042+ }
2043+
2044 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2045 return 0;
2046
2047diff -NurpP --minimal linux-3.6.6/fs/char_dev.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/char_dev.c
2048--- linux-3.6.6/fs/char_dev.c 2012-03-19 19:47:25.000000000 +0100
2049+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/char_dev.c 2012-10-04 18:47:00.000000000 +0200
2050@@ -21,6 +21,8 @@
2051 #include <linux/mutex.h>
2052 #include <linux/backing-dev.h>
2053 #include <linux/tty.h>
2054+#include <linux/vs_context.h>
2055+#include <linux/vs_device.h>
2056
2057 #include "internal.h"
2058
2059@@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2060 struct cdev *p;
2061 struct cdev *new = NULL;
2062 int ret = 0;
2063+ dev_t mdev;
2064+
2065+ if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2066+ return -EPERM;
2067+ inode->i_mdev = mdev;
2068
2069 spin_lock(&cdev_lock);
2070 p = inode->i_cdev;
2071 if (!p) {
2072 struct kobject *kobj;
2073 int idx;
2074+
2075 spin_unlock(&cdev_lock);
2076- kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2077+
2078+ kobj = kobj_lookup(cdev_map, mdev, &idx);
2079 if (!kobj)
2080 return -ENXIO;
2081 new = container_of(kobj, struct cdev, kobj);
2082diff -NurpP --minimal linux-3.6.6/fs/dcache.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/dcache.c
2083--- linux-3.6.6/fs/dcache.c 2012-10-04 15:27:39.000000000 +0200
2084+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/dcache.c 2012-10-04 18:47:00.000000000 +0200
2085@@ -37,6 +37,7 @@
2086 #include <linux/rculist_bl.h>
2087 #include <linux/prefetch.h>
2088 #include <linux/ratelimit.h>
2089+#include <linux/vs_limit.h>
2090 #include "internal.h"
2091 #include "mount.h"
2092
2093@@ -617,6 +618,8 @@ int d_invalidate(struct dentry * dentry)
2094 spin_lock(&dentry->d_lock);
2095 }
2096
2097+ vx_dentry_dec(dentry);
2098+
2099 /*
2100 * Somebody else still using it?
2101 *
2102@@ -646,6 +649,7 @@ EXPORT_SYMBOL(d_invalidate);
2103 static inline void __dget_dlock(struct dentry *dentry)
2104 {
2105 dentry->d_count++;
2106+ vx_dentry_inc(dentry);
2107 }
2108
2109 static inline void __dget(struct dentry *dentry)
2110@@ -1276,6 +1280,9 @@ struct dentry *__d_alloc(struct super_bl
2111 struct dentry *dentry;
2112 char *dname;
2113
2114+ if (!vx_dentry_avail(1))
2115+ return NULL;
2116+
2117 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2118 if (!dentry)
2119 return NULL;
2120@@ -1308,6 +1315,7 @@ struct dentry *__d_alloc(struct super_bl
2121
2122 dentry->d_count = 1;
2123 dentry->d_flags = 0;
2124+ vx_dentry_inc(dentry);
2125 spin_lock_init(&dentry->d_lock);
2126 seqcount_init(&dentry->d_seq);
2127 dentry->d_inode = NULL;
2128@@ -2012,6 +2020,7 @@ struct dentry *__d_lookup(struct dentry
2129 }
2130
2131 dentry->d_count++;
2132+ vx_dentry_inc(dentry);
2133 found = dentry;
2134 spin_unlock(&dentry->d_lock);
2135 break;
2136diff -NurpP --minimal linux-3.6.6/fs/devpts/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/devpts/inode.c
2137--- linux-3.6.6/fs/devpts/inode.c 2012-10-04 15:27:39.000000000 +0200
2138+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/devpts/inode.c 2012-10-04 18:47:00.000000000 +0200
2139@@ -25,6 +25,7 @@
2140 #include <linux/parser.h>
2141 #include <linux/fsnotify.h>
2142 #include <linux/seq_file.h>
2143+#include <linux/vs_base.h>
2144
2145 #define DEVPTS_DEFAULT_MODE 0600
2146 /*
2147@@ -36,6 +37,21 @@
2148 #define DEVPTS_DEFAULT_PTMX_MODE 0000
2149 #define PTMX_MINOR 2
2150
2151+static int devpts_permission(struct inode *inode, int mask)
2152+{
2153+ int ret = -EACCES;
2154+
2155+ /* devpts is xid tagged */
2156+ if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2157+ ret = generic_permission(inode, mask);
2158+ return ret;
2159+}
2160+
2161+static struct inode_operations devpts_file_inode_operations = {
2162+ .permission = devpts_permission,
2163+};
2164+
2165+
2166 /*
2167 * sysctl support for setting limits on the number of Unix98 ptys allocated.
2168 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2169@@ -336,6 +352,34 @@ static int devpts_show_options(struct se
2170 return 0;
2171 }
2172
2173+static int devpts_filter(struct dentry *de)
2174+{
2175+ xid_t xid = 0;
2176+
2177+ /* devpts is xid tagged */
2178+ if (de && de->d_inode)
2179+ xid = (xid_t)de->d_inode->i_tag;
2180+#ifdef CONFIG_VSERVER_WARN_DEVPTS
2181+ else
2182+ vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2183+ de->d_name.len, de->d_name.name);
2184+#endif
2185+ return vx_check(xid, VS_WATCH_P | VS_IDENT);
2186+}
2187+
2188+static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2189+{
2190+ return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2191+}
2192+
2193+static struct file_operations devpts_dir_operations = {
2194+ .open = dcache_dir_open,
2195+ .release = dcache_dir_close,
2196+ .llseek = dcache_dir_lseek,
2197+ .read = generic_read_dir,
2198+ .readdir = devpts_readdir,
2199+};
2200+
2201 static const struct super_operations devpts_sops = {
2202 .statfs = simple_statfs,
2203 .remount_fs = devpts_remount,
2204@@ -379,8 +423,10 @@ devpts_fill_super(struct super_block *s,
2205 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2206 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2207 inode->i_op = &simple_dir_inode_operations;
2208- inode->i_fop = &simple_dir_operations;
2209+ inode->i_fop = &devpts_dir_operations;
2210 set_nlink(inode, 2);
2211+ /* devpts is xid tagged */
2212+ inode->i_tag = (tag_t)vx_current_xid();
2213
2214 s->s_root = d_make_root(inode);
2215 if (s->s_root)
2216@@ -572,6 +618,9 @@ int devpts_pty_new(struct inode *ptmx_in
2217 inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2218 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2219 init_special_inode(inode, S_IFCHR|opts->mode, device);
2220+ /* devpts is xid tagged */
2221+ inode->i_tag = (tag_t)vx_current_xid();
2222+ inode->i_op = &devpts_file_inode_operations;
2223 inode->i_private = tty;
2224 tty->driver_data = inode;
2225
2226diff -NurpP --minimal linux-3.6.6/fs/ext2/balloc.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/balloc.c
2227--- linux-3.6.6/fs/ext2/balloc.c 2012-10-04 15:27:39.000000000 +0200
2228+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/balloc.c 2012-10-04 18:47:00.000000000 +0200
2229@@ -699,7 +699,6 @@ ext2_try_to_allocate(struct super_block
2230 start = 0;
2231 end = EXT2_BLOCKS_PER_GROUP(sb);
2232 }
2233-
2234 BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2235
2236 repeat:
2237diff -NurpP --minimal linux-3.6.6/fs/ext2/ext2.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/ext2.h
2238--- linux-3.6.6/fs/ext2/ext2.h 2012-07-22 23:39:39.000000000 +0200
2239+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/ext2.h 2012-10-04 18:47:00.000000000 +0200
2240@@ -244,8 +244,12 @@ struct ext2_group_desc
2241 #define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
2242 #define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
2243 #define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
2244+#define EXT2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
2245 #define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
2246
2247+#define EXT2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
2248+#define EXT2_COW_FL FS_COW_FL /* Copy on Write marker */
2249+
2250 #define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
2251 #define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
2252
2253@@ -329,7 +333,8 @@ struct ext2_inode {
2254 __u16 i_pad1;
2255 __le16 l_i_uid_high; /* these 2 fields */
2256 __le16 l_i_gid_high; /* were reserved2[0] */
2257- __u32 l_i_reserved2;
2258+ __le16 l_i_tag; /* Context Tag */
2259+ __u16 l_i_reserved2;
2260 } linux2;
2261 struct {
2262 __u8 h_i_frag; /* Fragment number */
2263@@ -357,6 +362,7 @@ struct ext2_inode {
2264 #define i_gid_low i_gid
2265 #define i_uid_high osd2.linux2.l_i_uid_high
2266 #define i_gid_high osd2.linux2.l_i_gid_high
2267+#define i_raw_tag osd2.linux2.l_i_tag
2268 #define i_reserved2 osd2.linux2.l_i_reserved2
2269
2270 /*
2271@@ -384,6 +390,7 @@ struct ext2_inode {
2272 #define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
2273 #define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
2274 #define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
2275+#define EXT2_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2276
2277
2278 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
2279@@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2280 extern void ext2_get_inode_flags(struct ext2_inode_info *);
2281 extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2282 u64 start, u64 len);
2283+extern int ext2_sync_flags(struct inode *, int, int);
2284
2285 /* ioctl.c */
2286 extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2287diff -NurpP --minimal linux-3.6.6/fs/ext2/file.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/file.c
2288--- linux-3.6.6/fs/ext2/file.c 2011-10-24 18:45:27.000000000 +0200
2289+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/file.c 2012-10-04 18:47:00.000000000 +0200
2290@@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2291 .setattr = ext2_setattr,
2292 .get_acl = ext2_get_acl,
2293 .fiemap = ext2_fiemap,
2294+ .sync_flags = ext2_sync_flags,
2295 };
2296diff -NurpP --minimal linux-3.6.6/fs/ext2/ialloc.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/ialloc.c
2297--- linux-3.6.6/fs/ext2/ialloc.c 2012-10-04 15:27:39.000000000 +0200
2298+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/ialloc.c 2012-10-04 18:47:00.000000000 +0200
2299@@ -17,6 +17,7 @@
2300 #include <linux/backing-dev.h>
2301 #include <linux/buffer_head.h>
2302 #include <linux/random.h>
2303+#include <linux/vs_tag.h>
2304 #include "ext2.h"
2305 #include "xattr.h"
2306 #include "acl.h"
2307@@ -547,6 +548,7 @@ got:
2308 inode->i_mode = mode;
2309 inode->i_uid = current_fsuid();
2310 inode->i_gid = dir->i_gid;
2311+ inode->i_tag = dx_current_fstag(sb);
2312 } else
2313 inode_init_owner(inode, dir, mode);
2314
2315diff -NurpP --minimal linux-3.6.6/fs/ext2/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/inode.c
2316--- linux-3.6.6/fs/ext2/inode.c 2012-10-04 15:27:39.000000000 +0200
2317+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/inode.c 2012-10-04 18:47:00.000000000 +0200
2318@@ -31,6 +31,7 @@
2319 #include <linux/mpage.h>
2320 #include <linux/fiemap.h>
2321 #include <linux/namei.h>
2322+#include <linux/vs_tag.h>
2323 #include "ext2.h"
2324 #include "acl.h"
2325 #include "xip.h"
2326@@ -1165,7 +1166,7 @@ static void ext2_truncate_blocks(struct
2327 return;
2328 if (ext2_inode_is_fast_symlink(inode))
2329 return;
2330- if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2331+ if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2332 return;
2333 __ext2_truncate_blocks(inode, offset);
2334 }
2335@@ -1256,36 +1257,61 @@ void ext2_set_inode_flags(struct inode *
2336 {
2337 unsigned int flags = EXT2_I(inode)->i_flags;
2338
2339- inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2340+ inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2341+ S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2342+
2343+
2344+ if (flags & EXT2_IMMUTABLE_FL)
2345+ inode->i_flags |= S_IMMUTABLE;
2346+ if (flags & EXT2_IXUNLINK_FL)
2347+ inode->i_flags |= S_IXUNLINK;
2348+
2349 if (flags & EXT2_SYNC_FL)
2350 inode->i_flags |= S_SYNC;
2351 if (flags & EXT2_APPEND_FL)
2352 inode->i_flags |= S_APPEND;
2353- if (flags & EXT2_IMMUTABLE_FL)
2354- inode->i_flags |= S_IMMUTABLE;
2355 if (flags & EXT2_NOATIME_FL)
2356 inode->i_flags |= S_NOATIME;
2357 if (flags & EXT2_DIRSYNC_FL)
2358 inode->i_flags |= S_DIRSYNC;
2359+
2360+ inode->i_vflags &= ~(V_BARRIER | V_COW);
2361+
2362+ if (flags & EXT2_BARRIER_FL)
2363+ inode->i_vflags |= V_BARRIER;
2364+ if (flags & EXT2_COW_FL)
2365+ inode->i_vflags |= V_COW;
2366 }
2367
2368 /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2369 void ext2_get_inode_flags(struct ext2_inode_info *ei)
2370 {
2371 unsigned int flags = ei->vfs_inode.i_flags;
2372+ unsigned int vflags = ei->vfs_inode.i_vflags;
2373+
2374+ ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2375+ EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2376+ EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2377+ EXT2_BARRIER_FL | EXT2_COW_FL);
2378+
2379+ if (flags & S_IMMUTABLE)
2380+ ei->i_flags |= EXT2_IMMUTABLE_FL;
2381+ if (flags & S_IXUNLINK)
2382+ ei->i_flags |= EXT2_IXUNLINK_FL;
2383
2384- ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2385- EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2386 if (flags & S_SYNC)
2387 ei->i_flags |= EXT2_SYNC_FL;
2388 if (flags & S_APPEND)
2389 ei->i_flags |= EXT2_APPEND_FL;
2390- if (flags & S_IMMUTABLE)
2391- ei->i_flags |= EXT2_IMMUTABLE_FL;
2392 if (flags & S_NOATIME)
2393 ei->i_flags |= EXT2_NOATIME_FL;
2394 if (flags & S_DIRSYNC)
2395 ei->i_flags |= EXT2_DIRSYNC_FL;
2396+
2397+ if (vflags & V_BARRIER)
2398+ ei->i_flags |= EXT2_BARRIER_FL;
2399+ if (vflags & V_COW)
2400+ ei->i_flags |= EXT2_COW_FL;
2401 }
2402
2403 struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2404@@ -1321,8 +1347,10 @@ struct inode *ext2_iget (struct super_bl
2405 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2406 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2407 }
2408- i_uid_write(inode, i_uid);
2409- i_gid_write(inode, i_gid);
2410+ i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2411+ i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2412+ inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2413+ le16_to_cpu(raw_inode->i_raw_tag));
2414 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2415 inode->i_size = le32_to_cpu(raw_inode->i_size);
2416 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2417@@ -1420,8 +1448,8 @@ static int __ext2_write_inode(struct ino
2418 struct ext2_inode_info *ei = EXT2_I(inode);
2419 struct super_block *sb = inode->i_sb;
2420 ino_t ino = inode->i_ino;
2421- uid_t uid = i_uid_read(inode);
2422- gid_t gid = i_gid_read(inode);
2423+ uid_t uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
2424+ gid_t gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
2425 struct buffer_head * bh;
2426 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2427 int n;
2428@@ -1457,6 +1485,9 @@ static int __ext2_write_inode(struct ino
2429 raw_inode->i_uid_high = 0;
2430 raw_inode->i_gid_high = 0;
2431 }
2432+#ifdef CONFIG_TAGGING_INTERN
2433+ raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2434+#endif
2435 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2436 raw_inode->i_size = cpu_to_le32(inode->i_size);
2437 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2438@@ -1537,7 +1568,8 @@ int ext2_setattr(struct dentry *dentry,
2439 if (is_quota_modification(inode, iattr))
2440 dquot_initialize(inode);
2441 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2442- (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2443+ (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2444+ (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2445 error = dquot_transfer(inode, iattr);
2446 if (error)
2447 return error;
2448diff -NurpP --minimal linux-3.6.6/fs/ext2/ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/ioctl.c
2449--- linux-3.6.6/fs/ext2/ioctl.c 2012-03-19 19:47:25.000000000 +0100
2450+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/ioctl.c 2012-10-04 18:47:00.000000000 +0200
2451@@ -17,6 +17,16 @@
2452 #include <asm/uaccess.h>
2453
2454
2455+int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2456+{
2457+ inode->i_flags = flags;
2458+ inode->i_vflags = vflags;
2459+ ext2_get_inode_flags(EXT2_I(inode));
2460+ inode->i_ctime = CURRENT_TIME_SEC;
2461+ mark_inode_dirty(inode);
2462+ return 0;
2463+}
2464+
2465 long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2466 {
2467 struct inode *inode = filp->f_dentry->d_inode;
2468@@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2469
2470 flags = ext2_mask_flags(inode->i_mode, flags);
2471
2472+ if (IS_BARRIER(inode)) {
2473+ vxwprintk_task(1, "messing with the barrier.");
2474+ return -EACCES;
2475+ }
2476+
2477 mutex_lock(&inode->i_mutex);
2478 /* Is it quota file? Do not allow user to mess with it */
2479 if (IS_NOQUOTA(inode)) {
2480@@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2481 *
2482 * This test looks nicer. Thanks to Pauline Middelink
2483 */
2484- if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2485+ if ((oldflags & EXT2_IMMUTABLE_FL) ||
2486+ ((flags ^ oldflags) & (EXT2_APPEND_FL |
2487+ EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2488 if (!capable(CAP_LINUX_IMMUTABLE)) {
2489 mutex_unlock(&inode->i_mutex);
2490 ret = -EPERM;
2491@@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2492 }
2493 }
2494
2495- flags = flags & EXT2_FL_USER_MODIFIABLE;
2496+ flags &= EXT2_FL_USER_MODIFIABLE;
2497 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2498 ei->i_flags = flags;
2499
2500diff -NurpP --minimal linux-3.6.6/fs/ext2/namei.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/namei.c
2501--- linux-3.6.6/fs/ext2/namei.c 2012-10-04 15:27:39.000000000 +0200
2502+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/namei.c 2012-10-04 18:47:00.000000000 +0200
2503@@ -32,6 +32,7 @@
2504
2505 #include <linux/pagemap.h>
2506 #include <linux/quotaops.h>
2507+#include <linux/vs_tag.h>
2508 #include "ext2.h"
2509 #include "xattr.h"
2510 #include "acl.h"
2511@@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2512 (unsigned long) ino);
2513 return ERR_PTR(-EIO);
2514 }
2515+ dx_propagate_tag(nd, inode);
2516 }
2517 return d_splice_alias(inode, dentry);
2518 }
2519@@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2520 .removexattr = generic_removexattr,
2521 #endif
2522 .setattr = ext2_setattr,
2523+ .sync_flags = ext2_sync_flags,
2524 .get_acl = ext2_get_acl,
2525 };
2526
2527diff -NurpP --minimal linux-3.6.6/fs/ext2/super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/super.c
2528--- linux-3.6.6/fs/ext2/super.c 2012-10-04 15:27:39.000000000 +0200
2529+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext2/super.c 2012-10-04 18:47:00.000000000 +0200
2530@@ -390,7 +390,8 @@ enum {
2531 Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2532 Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2533 Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2534- Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2535+ Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2536+ Opt_tag, Opt_notag, Opt_tagid
2537 };
2538
2539 static const match_table_t tokens = {
2540@@ -418,6 +419,9 @@ static const match_table_t tokens = {
2541 {Opt_acl, "acl"},
2542 {Opt_noacl, "noacl"},
2543 {Opt_xip, "xip"},
2544+ {Opt_tag, "tag"},
2545+ {Opt_notag, "notag"},
2546+ {Opt_tagid, "tagid=%u"},
2547 {Opt_grpquota, "grpquota"},
2548 {Opt_ignore, "noquota"},
2549 {Opt_quota, "quota"},
2550@@ -501,6 +505,20 @@ static int parse_options(char *options,
2551 case Opt_nouid32:
2552 set_opt (sbi->s_mount_opt, NO_UID32);
2553 break;
2554+#ifndef CONFIG_TAGGING_NONE
2555+ case Opt_tag:
2556+ set_opt (sbi->s_mount_opt, TAGGED);
2557+ break;
2558+ case Opt_notag:
2559+ clear_opt (sbi->s_mount_opt, TAGGED);
2560+ break;
2561+#endif
2562+#ifdef CONFIG_PROPAGATE
2563+ case Opt_tagid:
2564+ /* use args[0] */
2565+ set_opt (sbi->s_mount_opt, TAGGED);
2566+ break;
2567+#endif
2568 case Opt_nocheck:
2569 clear_opt (sbi->s_mount_opt, CHECK);
2570 break;
2571@@ -859,6 +877,8 @@ static int ext2_fill_super(struct super_
2572 if (!parse_options((char *) data, sb))
2573 goto failed_mount;
2574
2575+ if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2576+ sb->s_flags |= MS_TAGGED;
2577 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2578 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2579 MS_POSIXACL : 0);
2580@@ -1265,6 +1285,14 @@ static int ext2_remount (struct super_bl
2581 goto restore_opts;
2582 }
2583
2584+ if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2585+ !(sb->s_flags & MS_TAGGED)) {
2586+ printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2587+ sb->s_id);
2588+ err = -EINVAL;
2589+ goto restore_opts;
2590+ }
2591+
2592 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2593 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2594
2595diff -NurpP --minimal linux-3.6.6/fs/ext3/ext3.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/ext3.h
2596--- linux-3.6.6/fs/ext3/ext3.h 2012-07-22 23:39:39.000000000 +0200
2597+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/ext3.h 2012-10-04 18:47:00.000000000 +0200
2598@@ -151,10 +151,14 @@ struct ext3_group_desc
2599 #define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */
2600 #define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
2601 #define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
2602+#define EXT3_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2603 #define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */
2604
2605-#define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
2606-#define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
2607+#define EXT3_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2608+#define EXT3_COW_FL 0x20000000 /* Copy on Write marker */
2609+
2610+#define EXT3_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
2611+#define EXT3_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
2612
2613 /* Flags that should be inherited by new inodes from their parent. */
2614 #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2615@@ -290,7 +294,8 @@ struct ext3_inode {
2616 __u16 i_pad1;
2617 __le16 l_i_uid_high; /* these 2 fields */
2618 __le16 l_i_gid_high; /* were reserved2[0] */
2619- __u32 l_i_reserved2;
2620+ __le16 l_i_tag; /* Context Tag */
2621+ __u16 l_i_reserved2;
2622 } linux2;
2623 struct {
2624 __u8 h_i_frag; /* Fragment number */
2625@@ -320,6 +325,7 @@ struct ext3_inode {
2626 #define i_gid_low i_gid
2627 #define i_uid_high osd2.linux2.l_i_uid_high
2628 #define i_gid_high osd2.linux2.l_i_gid_high
2629+#define i_raw_tag osd2.linux2.l_i_tag
2630 #define i_reserved2 osd2.linux2.l_i_reserved2
2631
2632 /*
2633@@ -364,6 +370,7 @@ struct ext3_inode {
2634 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2635 #define EXT3_MOUNT_DATA_ERR_ABORT 0x400000 /* Abort on file data write
2636 * error in ordered mode */
2637+#define EXT3_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2638
2639 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2640 #ifndef _LINUX_EXT2_FS_H
2641@@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2642 extern void ext3_set_aops(struct inode *inode);
2643 extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2644 u64 start, u64 len);
2645+extern int ext3_sync_flags(struct inode *, int, int);
2646
2647 /* ioctl.c */
2648 extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2649diff -NurpP --minimal linux-3.6.6/fs/ext3/file.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/file.c
2650--- linux-3.6.6/fs/ext3/file.c 2012-05-21 18:07:20.000000000 +0200
2651+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/file.c 2012-10-04 18:47:00.000000000 +0200
2652@@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2653 #endif
2654 .get_acl = ext3_get_acl,
2655 .fiemap = ext3_fiemap,
2656+ .sync_flags = ext3_sync_flags,
2657 };
2658
2659diff -NurpP --minimal linux-3.6.6/fs/ext3/ialloc.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/ialloc.c
2660--- linux-3.6.6/fs/ext3/ialloc.c 2012-07-22 23:39:39.000000000 +0200
2661+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/ialloc.c 2012-10-04 18:47:00.000000000 +0200
2662@@ -14,6 +14,7 @@
2663
2664 #include <linux/quotaops.h>
2665 #include <linux/random.h>
2666+#include <linux/vs_tag.h>
2667
2668 #include "ext3.h"
2669 #include "xattr.h"
2670@@ -469,6 +470,7 @@ got:
2671 inode->i_mode = mode;
2672 inode->i_uid = current_fsuid();
2673 inode->i_gid = dir->i_gid;
2674+ inode->i_tag = dx_current_fstag(sb);
2675 } else
2676 inode_init_owner(inode, dir, mode);
2677
2678diff -NurpP --minimal linux-3.6.6/fs/ext3/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/inode.c
2679--- linux-3.6.6/fs/ext3/inode.c 2012-10-04 15:27:39.000000000 +0200
2680+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/inode.c 2012-10-04 18:47:00.000000000 +0200
2681@@ -27,6 +27,8 @@
2682 #include <linux/writeback.h>
2683 #include <linux/mpage.h>
2684 #include <linux/namei.h>
2685+#include <linux/vs_tag.h>
2686+
2687 #include "ext3.h"
2688 #include "xattr.h"
2689 #include "acl.h"
2690@@ -2848,36 +2850,60 @@ void ext3_set_inode_flags(struct inode *
2691 {
2692 unsigned int flags = EXT3_I(inode)->i_flags;
2693
2694- inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2695+ inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2696+ S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2697+
2698+ if (flags & EXT3_IMMUTABLE_FL)
2699+ inode->i_flags |= S_IMMUTABLE;
2700+ if (flags & EXT3_IXUNLINK_FL)
2701+ inode->i_flags |= S_IXUNLINK;
2702+
2703 if (flags & EXT3_SYNC_FL)
2704 inode->i_flags |= S_SYNC;
2705 if (flags & EXT3_APPEND_FL)
2706 inode->i_flags |= S_APPEND;
2707- if (flags & EXT3_IMMUTABLE_FL)
2708- inode->i_flags |= S_IMMUTABLE;
2709 if (flags & EXT3_NOATIME_FL)
2710 inode->i_flags |= S_NOATIME;
2711 if (flags & EXT3_DIRSYNC_FL)
2712 inode->i_flags |= S_DIRSYNC;
2713+
2714+ inode->i_vflags &= ~(V_BARRIER | V_COW);
2715+
2716+ if (flags & EXT3_BARRIER_FL)
2717+ inode->i_vflags |= V_BARRIER;
2718+ if (flags & EXT3_COW_FL)
2719+ inode->i_vflags |= V_COW;
2720 }
2721
2722 /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2723 void ext3_get_inode_flags(struct ext3_inode_info *ei)
2724 {
2725 unsigned int flags = ei->vfs_inode.i_flags;
2726+ unsigned int vflags = ei->vfs_inode.i_vflags;
2727+
2728+ ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2729+ EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2730+ EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2731+ EXT3_BARRIER_FL | EXT3_COW_FL);
2732+
2733+ if (flags & S_IMMUTABLE)
2734+ ei->i_flags |= EXT3_IMMUTABLE_FL;
2735+ if (flags & S_IXUNLINK)
2736+ ei->i_flags |= EXT3_IXUNLINK_FL;
2737
2738- ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2739- EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2740 if (flags & S_SYNC)
2741 ei->i_flags |= EXT3_SYNC_FL;
2742 if (flags & S_APPEND)
2743 ei->i_flags |= EXT3_APPEND_FL;
2744- if (flags & S_IMMUTABLE)
2745- ei->i_flags |= EXT3_IMMUTABLE_FL;
2746 if (flags & S_NOATIME)
2747 ei->i_flags |= EXT3_NOATIME_FL;
2748 if (flags & S_DIRSYNC)
2749 ei->i_flags |= EXT3_DIRSYNC_FL;
2750+
2751+ if (vflags & V_BARRIER)
2752+ ei->i_flags |= EXT3_BARRIER_FL;
2753+ if (vflags & V_COW)
2754+ ei->i_flags |= EXT3_COW_FL;
2755 }
2756
2757 struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2758@@ -2915,8 +2941,10 @@ struct inode *ext3_iget(struct super_blo
2759 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2760 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2761 }
2762- i_uid_write(inode, i_uid);
2763- i_gid_write(inode, i_gid);
2764+ i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2765+ i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2766+ inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2767+ le16_to_cpu(raw_inode->i_raw_tag));
2768 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2769 inode->i_size = le32_to_cpu(raw_inode->i_size);
2770 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2771@@ -3088,8 +3116,8 @@ again:
2772
2773 ext3_get_inode_flags(ei);
2774 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2775- i_uid = i_uid_read(inode);
2776- i_gid = i_gid_read(inode);
2777+ i_uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
2778+ i_gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
2779 if(!(test_opt(inode->i_sb, NO_UID32))) {
2780 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2781 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2782@@ -3114,6 +3142,9 @@ again:
2783 raw_inode->i_uid_high = 0;
2784 raw_inode->i_gid_high = 0;
2785 }
2786+#ifdef CONFIG_TAGGING_INTERN
2787+ raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2788+#endif
2789 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2790 disksize = cpu_to_le32(ei->i_disksize);
2791 if (disksize != raw_inode->i_size) {
2792@@ -3282,7 +3313,8 @@ int ext3_setattr(struct dentry *dentry,
2793 if (is_quota_modification(inode, attr))
2794 dquot_initialize(inode);
2795 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2796- (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2797+ (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2798+ (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2799 handle_t *handle;
2800
2801 /* (user+group)*(old+new) structure, inode write (sb,
2802@@ -3304,6 +3336,8 @@ int ext3_setattr(struct dentry *dentry,
2803 inode->i_uid = attr->ia_uid;
2804 if (attr->ia_valid & ATTR_GID)
2805 inode->i_gid = attr->ia_gid;
2806+ if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2807+ inode->i_tag = attr->ia_tag;
2808 error = ext3_mark_inode_dirty(handle, inode);
2809 ext3_journal_stop(handle);
2810 }
2811diff -NurpP --minimal linux-3.6.6/fs/ext3/ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/ioctl.c
2812--- linux-3.6.6/fs/ext3/ioctl.c 2012-05-21 18:07:20.000000000 +0200
2813+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/ioctl.c 2012-10-04 18:47:00.000000000 +0200
2814@@ -12,6 +12,34 @@
2815 #include <asm/uaccess.h>
2816 #include "ext3.h"
2817
2818+
2819+int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2820+{
2821+ handle_t *handle = NULL;
2822+ struct ext3_iloc iloc;
2823+ int err;
2824+
2825+ handle = ext3_journal_start(inode, 1);
2826+ if (IS_ERR(handle))
2827+ return PTR_ERR(handle);
2828+
2829+ if (IS_SYNC(inode))
2830+ handle->h_sync = 1;
2831+ err = ext3_reserve_inode_write(handle, inode, &iloc);
2832+ if (err)
2833+ goto flags_err;
2834+
2835+ inode->i_flags = flags;
2836+ inode->i_vflags = vflags;
2837+ ext3_get_inode_flags(EXT3_I(inode));
2838+ inode->i_ctime = CURRENT_TIME_SEC;
2839+
2840+ err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2841+flags_err:
2842+ ext3_journal_stop(handle);
2843+ return err;
2844+}
2845+
2846 long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2847 {
2848 struct inode *inode = filp->f_dentry->d_inode;
2849@@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2850
2851 flags = ext3_mask_flags(inode->i_mode, flags);
2852
2853+ if (IS_BARRIER(inode)) {
2854+ vxwprintk_task(1, "messing with the barrier.");
2855+ return -EACCES;
2856+ }
2857+
2858 mutex_lock(&inode->i_mutex);
2859
2860 /* Is it quota file? Do not allow user to mess with it */
2861@@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2862 *
2863 * This test looks nicer. Thanks to Pauline Middelink
2864 */
2865- if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2866+ if ((oldflags & EXT3_IMMUTABLE_FL) ||
2867+ ((flags ^ oldflags) & (EXT3_APPEND_FL |
2868+ EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2869 if (!capable(CAP_LINUX_IMMUTABLE))
2870 goto flags_out;
2871 }
2872@@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2873 if (err)
2874 goto flags_err;
2875
2876- flags = flags & EXT3_FL_USER_MODIFIABLE;
2877+ flags &= EXT3_FL_USER_MODIFIABLE;
2878 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2879 ei->i_flags = flags;
2880
2881diff -NurpP --minimal linux-3.6.6/fs/ext3/namei.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/namei.c
2882--- linux-3.6.6/fs/ext3/namei.c 2012-10-04 15:27:39.000000000 +0200
2883+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/namei.c 2012-10-04 18:47:00.000000000 +0200
2884@@ -25,6 +25,8 @@
2885 */
2886
2887 #include <linux/quotaops.h>
2888+#include <linux/vs_tag.h>
2889+
2890 #include "ext3.h"
2891 #include "namei.h"
2892 #include "xattr.h"
2893@@ -915,6 +917,7 @@ restart:
2894 submit_bh(READ | REQ_META | REQ_PRIO,
2895 bh);
2896 }
2897+ dx_propagate_tag(nd, inode);
2898 }
2899 }
2900 if ((bh = bh_use[ra_ptr++]) == NULL)
2901@@ -2526,6 +2529,7 @@ const struct inode_operations ext3_dir_i
2902 .listxattr = ext3_listxattr,
2903 .removexattr = generic_removexattr,
2904 #endif
2905+ .sync_flags = ext3_sync_flags,
2906 .get_acl = ext3_get_acl,
2907 };
2908
2909diff -NurpP --minimal linux-3.6.6/fs/ext3/super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/super.c
2910--- linux-3.6.6/fs/ext3/super.c 2012-10-04 15:27:39.000000000 +0200
2911+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext3/super.c 2012-10-04 18:47:00.000000000 +0200
2912@@ -811,7 +811,8 @@ enum {
2913 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2914 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2915 Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2916- Opt_resize, Opt_usrquota, Opt_grpquota
2917+ Opt_resize, Opt_usrquota, Opt_grpquota,
2918+ Opt_tag, Opt_notag, Opt_tagid
2919 };
2920
2921 static const match_table_t tokens = {
2922@@ -868,6 +869,9 @@ static const match_table_t tokens = {
2923 {Opt_barrier, "barrier"},
2924 {Opt_nobarrier, "nobarrier"},
2925 {Opt_resize, "resize"},
2926+ {Opt_tag, "tag"},
2927+ {Opt_notag, "notag"},
2928+ {Opt_tagid, "tagid=%u"},
2929 {Opt_err, NULL},
2930 };
2931
2932@@ -1033,6 +1037,20 @@ static int parse_options (char *options,
2933 case Opt_nouid32:
2934 set_opt (sbi->s_mount_opt, NO_UID32);
2935 break;
2936+#ifndef CONFIG_TAGGING_NONE
2937+ case Opt_tag:
2938+ set_opt (sbi->s_mount_opt, TAGGED);
2939+ break;
2940+ case Opt_notag:
2941+ clear_opt (sbi->s_mount_opt, TAGGED);
2942+ break;
2943+#endif
2944+#ifdef CONFIG_PROPAGATE
2945+ case Opt_tagid:
2946+ /* use args[0] */
2947+ set_opt (sbi->s_mount_opt, TAGGED);
2948+ break;
2949+#endif
2950 case Opt_nocheck:
2951 clear_opt (sbi->s_mount_opt, CHECK);
2952 break;
2953@@ -1731,6 +1749,9 @@ static int ext3_fill_super (struct super
2954 NULL, 0))
2955 goto failed_mount;
2956
2957+ if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2958+ sb->s_flags |= MS_TAGGED;
2959+
2960 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2961 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2962
2963@@ -2618,6 +2639,14 @@ static int ext3_remount (struct super_bl
2964 if (test_opt(sb, ABORT))
2965 ext3_abort(sb, __func__, "Abort forced by user");
2966
2967+ if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2968+ !(sb->s_flags & MS_TAGGED)) {
2969+ printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2970+ sb->s_id);
2971+ err = -EINVAL;
2972+ goto restore_opts;
2973+ }
2974+
2975 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2976 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2977
2978diff -NurpP --minimal linux-3.6.6/fs/ext4/ext4.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/ext4.h
2979--- linux-3.6.6/fs/ext4/ext4.h 2012-11-06 18:42:12.000000000 +0100
2980+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/ext4.h 2012-11-06 18:43:41.000000000 +0100
2981@@ -393,8 +393,12 @@ struct flex_groups {
2982 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
2983 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
2984 #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
2985+#define EXT4_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2986 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
2987
2988+#define EXT4_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2989+#define EXT4_COW_FL 0x20000000 /* Copy on Write marker */
2990+
2991 #define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */
2992 #define EXT4_FL_USER_MODIFIABLE 0x004B80FF /* User modifiable flags */
2993
2994@@ -666,7 +670,7 @@ struct ext4_inode {
2995 __le16 l_i_uid_high; /* these 2 fields */
2996 __le16 l_i_gid_high; /* were reserved2[0] */
2997 __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2998- __le16 l_i_reserved;
2999+ __le16 l_i_tag; /* Context Tag */
3000 } linux2;
3001 struct {
3002 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
3003@@ -784,6 +788,7 @@ do { \
3004 #define i_gid_low i_gid
3005 #define i_uid_high osd2.linux2.l_i_uid_high
3006 #define i_gid_high osd2.linux2.l_i_gid_high
3007+#define i_raw_tag osd2.linux2.l_i_tag
3008 #define i_checksum_lo osd2.linux2.l_i_checksum_lo
3009
3010 #elif defined(__GNU__)
3011@@ -964,6 +969,7 @@ struct ext4_inode_info {
3012 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
3013 #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
3014 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
3015+#define EXT4_MOUNT_TAGGED 0x40000 /* Enable Context Tags */
3016 #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
3017 #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
3018 #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
3019@@ -2393,6 +2399,7 @@ extern int ext4_map_blocks(handle_t *han
3020 struct ext4_map_blocks *map, int flags);
3021 extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3022 __u64 start, __u64 len);
3023+extern int ext4_sync_flags(struct inode *, int, int);
3024 /* move_extent.c */
3025 extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3026 __u64 start_orig, __u64 start_donor,
3027diff -NurpP --minimal linux-3.6.6/fs/ext4/file.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/file.c
3028--- linux-3.6.6/fs/ext4/file.c 2012-10-04 15:27:39.000000000 +0200
3029+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/file.c 2012-10-04 18:47:00.000000000 +0200
3030@@ -334,5 +334,6 @@ const struct inode_operations ext4_file_
3031 #endif
3032 .get_acl = ext4_get_acl,
3033 .fiemap = ext4_fiemap,
3034+ .sync_flags = ext4_sync_flags,
3035 };
3036
3037diff -NurpP --minimal linux-3.6.6/fs/ext4/ialloc.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/ialloc.c
3038--- linux-3.6.6/fs/ext4/ialloc.c 2012-11-06 18:42:12.000000000 +0100
3039+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/ialloc.c 2012-11-06 18:43:41.000000000 +0100
3040@@ -22,6 +22,7 @@
3041 #include <linux/random.h>
3042 #include <linux/bitops.h>
3043 #include <linux/blkdev.h>
3044+#include <linux/vs_tag.h>
3045 #include <asm/byteorder.h>
3046
3047 #include "ext4.h"
3048@@ -839,6 +840,7 @@ got:
3049 inode->i_mode = mode;
3050 inode->i_uid = current_fsuid();
3051 inode->i_gid = dir->i_gid;
3052+ inode->i_tag = dx_current_fstag(sb);
3053 } else
3054 inode_init_owner(inode, dir, mode);
3055
3056diff -NurpP --minimal linux-3.6.6/fs/ext4/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/inode.c
3057--- linux-3.6.6/fs/ext4/inode.c 2012-11-06 18:42:12.000000000 +0100
3058+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/inode.c 2012-11-06 18:43:41.000000000 +0100
3059@@ -37,6 +37,7 @@
3060 #include <linux/printk.h>
3061 #include <linux/slab.h>
3062 #include <linux/ratelimit.h>
3063+#include <linux/vs_tag.h>
3064
3065 #include "ext4_jbd2.h"
3066 #include "xattr.h"
3067@@ -3715,41 +3716,64 @@ void ext4_set_inode_flags(struct inode *
3068 {
3069 unsigned int flags = EXT4_I(inode)->i_flags;
3070
3071- inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3072+ inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3073+ S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3074+
3075+ if (flags & EXT4_IMMUTABLE_FL)
3076+ inode->i_flags |= S_IMMUTABLE;
3077+ if (flags & EXT4_IXUNLINK_FL)
3078+ inode->i_flags |= S_IXUNLINK;
3079+
3080 if (flags & EXT4_SYNC_FL)
3081 inode->i_flags |= S_SYNC;
3082 if (flags & EXT4_APPEND_FL)
3083 inode->i_flags |= S_APPEND;
3084- if (flags & EXT4_IMMUTABLE_FL)
3085- inode->i_flags |= S_IMMUTABLE;
3086 if (flags & EXT4_NOATIME_FL)
3087 inode->i_flags |= S_NOATIME;
3088 if (flags & EXT4_DIRSYNC_FL)
3089 inode->i_flags |= S_DIRSYNC;
3090+
3091+ inode->i_vflags &= ~(V_BARRIER | V_COW);
3092+
3093+ if (flags & EXT4_BARRIER_FL)
3094+ inode->i_vflags |= V_BARRIER;
3095+ if (flags & EXT4_COW_FL)
3096+ inode->i_vflags |= V_COW;
3097 }
3098
3099 /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3100 void ext4_get_inode_flags(struct ext4_inode_info *ei)
3101 {
3102- unsigned int vfs_fl;
3103+ unsigned int vfs_fl, vfs_vf;
3104 unsigned long old_fl, new_fl;
3105
3106 do {
3107 vfs_fl = ei->vfs_inode.i_flags;
3108+ vfs_vf = ei->vfs_inode.i_vflags;
3109 old_fl = ei->i_flags;
3110 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3111 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3112- EXT4_DIRSYNC_FL);
3113+ EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3114+ EXT4_COW_FL);
3115+
3116+ if (vfs_fl & S_IMMUTABLE)
3117+ new_fl |= EXT4_IMMUTABLE_FL;
3118+ if (vfs_fl & S_IXUNLINK)
3119+ new_fl |= EXT4_IXUNLINK_FL;
3120+
3121 if (vfs_fl & S_SYNC)
3122 new_fl |= EXT4_SYNC_FL;
3123 if (vfs_fl & S_APPEND)
3124 new_fl |= EXT4_APPEND_FL;
3125- if (vfs_fl & S_IMMUTABLE)
3126- new_fl |= EXT4_IMMUTABLE_FL;
3127 if (vfs_fl & S_NOATIME)
3128 new_fl |= EXT4_NOATIME_FL;
3129 if (vfs_fl & S_DIRSYNC)
3130 new_fl |= EXT4_DIRSYNC_FL;
3131+
3132+ if (vfs_vf & V_BARRIER)
3133+ new_fl |= EXT4_BARRIER_FL;
3134+ if (vfs_vf & V_COW)
3135+ new_fl |= EXT4_COW_FL;
3136 } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3137 }
3138
3139@@ -3841,8 +3865,10 @@ struct inode *ext4_iget(struct super_blo
3140 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3141 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3142 }
3143- i_uid_write(inode, i_uid);
3144- i_gid_write(inode, i_gid);
3145+ i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3146+ i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3147+ inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3148+ le16_to_cpu(raw_inode->i_raw_tag));
3149 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3150
3151 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
3152@@ -4066,8 +4092,8 @@ static int ext4_do_update_inode(handle_t
3153
3154 ext4_get_inode_flags(ei);
3155 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3156- i_uid = i_uid_read(inode);
3157- i_gid = i_gid_read(inode);
3158+ i_uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
3159+ i_gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
3160 if (!(test_opt(inode->i_sb, NO_UID32))) {
3161 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3162 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3163@@ -4090,6 +4116,9 @@ static int ext4_do_update_inode(handle_t
3164 raw_inode->i_uid_high = 0;
3165 raw_inode->i_gid_high = 0;
3166 }
3167+#ifdef CONFIG_TAGGING_INTERN
3168+ raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3169+#endif
3170 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3171
3172 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3173@@ -4278,7 +4307,8 @@ int ext4_setattr(struct dentry *dentry,
3174 if (is_quota_modification(inode, attr))
3175 dquot_initialize(inode);
3176 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3177- (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3178+ (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3179+ (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3180 handle_t *handle;
3181
3182 /* (user+group)*(old+new) structure, inode write (sb,
3183@@ -4300,6 +4330,8 @@ int ext4_setattr(struct dentry *dentry,
3184 inode->i_uid = attr->ia_uid;
3185 if (attr->ia_valid & ATTR_GID)
3186 inode->i_gid = attr->ia_gid;
3187+ if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3188+ inode->i_tag = attr->ia_tag;
3189 error = ext4_mark_inode_dirty(handle, inode);
3190 ext4_journal_stop(handle);
3191 }
3192diff -NurpP --minimal linux-3.6.6/fs/ext4/ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/ioctl.c
3193--- linux-3.6.6/fs/ext4/ioctl.c 2012-10-04 15:27:39.000000000 +0200
3194+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/ioctl.c 2012-10-04 18:47:00.000000000 +0200
3195@@ -14,12 +14,40 @@
3196 #include <linux/compat.h>
3197 #include <linux/mount.h>
3198 #include <linux/file.h>
3199+#include <linux/vs_tag.h>
3200 #include <asm/uaccess.h>
3201 #include "ext4_jbd2.h"
3202 #include "ext4.h"
3203
3204 #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3205
3206+int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3207+{
3208+ handle_t *handle = NULL;
3209+ struct ext4_iloc iloc;
3210+ int err;
3211+
3212+ handle = ext4_journal_start(inode, 1);
3213+ if (IS_ERR(handle))
3214+ return PTR_ERR(handle);
3215+
3216+ if (IS_SYNC(inode))
3217+ ext4_handle_sync(handle);
3218+ err = ext4_reserve_inode_write(handle, inode, &iloc);
3219+ if (err)
3220+ goto flags_err;
3221+
3222+ inode->i_flags = flags;
3223+ inode->i_vflags = vflags;
3224+ ext4_get_inode_flags(EXT4_I(inode));
3225+ inode->i_ctime = ext4_current_time(inode);
3226+
3227+ err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3228+flags_err:
3229+ ext4_journal_stop(handle);
3230+ return err;
3231+}
3232+
3233 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3234 {
3235 struct inode *inode = filp->f_dentry->d_inode;
3236@@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3237
3238 flags = ext4_mask_flags(inode->i_mode, flags);
3239
3240+ if (IS_BARRIER(inode)) {
3241+ vxwprintk_task(1, "messing with the barrier.");
3242+ return -EACCES;
3243+ }
3244+
3245 err = -EPERM;
3246 mutex_lock(&inode->i_mutex);
3247 /* Is it quota file? Do not allow user to mess with it */
3248@@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3249 *
3250 * This test looks nicer. Thanks to Pauline Middelink
3251 */
3252- if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3253+ if ((oldflags & EXT4_IMMUTABLE_FL) ||
3254+ ((flags ^ oldflags) & (EXT4_APPEND_FL |
3255+ EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3256 if (!capable(CAP_LINUX_IMMUTABLE))
3257 goto flags_out;
3258 }
3259diff -NurpP --minimal linux-3.6.6/fs/ext4/namei.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/namei.c
3260--- linux-3.6.6/fs/ext4/namei.c 2012-11-06 18:42:13.000000000 +0100
3261+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/namei.c 2012-11-06 18:43:41.000000000 +0100
3262@@ -34,6 +34,7 @@
3263 #include <linux/quotaops.h>
3264 #include <linux/buffer_head.h>
3265 #include <linux/bio.h>
3266+#include <linux/vs_tag.h>
3267 #include "ext4.h"
3268 #include "ext4_jbd2.h"
3269
3270@@ -1199,6 +1200,7 @@ restart:
3271 ll_rw_block(READ | REQ_META | REQ_PRIO,
3272 1, &bh);
3273 }
3274+ dx_propagate_tag(nd, inode);
3275 }
3276 if ((bh = bh_use[ra_ptr++]) == NULL)
3277 goto next;
3278@@ -2982,6 +2984,7 @@ const struct inode_operations ext4_dir_i
3279 #endif
3280 .get_acl = ext4_get_acl,
3281 .fiemap = ext4_fiemap,
3282+ .sync_flags = ext4_sync_flags,
3283 };
3284
3285 const struct inode_operations ext4_special_inode_operations = {
3286diff -NurpP --minimal linux-3.6.6/fs/ext4/super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/super.c
3287--- linux-3.6.6/fs/ext4/super.c 2012-11-06 18:42:13.000000000 +0100
3288+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ext4/super.c 2012-11-06 18:43:41.000000000 +0100
3289@@ -1219,6 +1219,7 @@ enum {
3290 Opt_inode_readahead_blks, Opt_journal_ioprio,
3291 Opt_dioread_nolock, Opt_dioread_lock,
3292 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3293+ Opt_tag, Opt_notag, Opt_tagid
3294 };
3295
3296 static const match_table_t tokens = {
3297@@ -1297,6 +1298,9 @@ static const match_table_t tokens = {
3298 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
3299 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3300 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
3301+ {Opt_tag, "tag"},
3302+ {Opt_notag, "notag"},
3303+ {Opt_tagid, "tagid=%u"},
3304 {Opt_err, NULL},
3305 };
3306
3307@@ -1543,6 +1547,20 @@ static int handle_mount_opt(struct super
3308 return -1;
3309 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
3310 return 1;
3311+#ifndef CONFIG_TAGGING_NONE
3312+ case Opt_tag:
3313+ set_opt(sb, TAGGED);
3314+ return 1;
3315+ case Opt_notag:
3316+ clear_opt(sb, TAGGED);
3317+ return 1;
3318+#endif
3319+#ifdef CONFIG_PROPAGATE
3320+ case Opt_tagid:
3321+ /* use args[0] */
3322+ set_opt(sb, TAGGED);
3323+ return 1;
3324+#endif
3325 }
3326
3327 for (m = ext4_mount_opts; m->token != Opt_err; m++) {
3328@@ -3417,6 +3435,9 @@ static int ext4_fill_super(struct super_
3329 }
3330 }
3331
3332+ if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3333+ sb->s_flags |= MS_TAGGED;
3334+
3335 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3336 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3337
3338@@ -4582,6 +4603,14 @@ static int ext4_remount(struct super_blo
3339 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3340 ext4_abort(sb, "Abort forced by user");
3341
3342+ if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3343+ !(sb->s_flags & MS_TAGGED)) {
3344+ printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3345+ sb->s_id);
3346+ err = -EINVAL;
3347+ goto restore_opts;
3348+ }
3349+
3350 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3351 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3352
3353diff -NurpP --minimal linux-3.6.6/fs/fcntl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/fcntl.c
3354--- linux-3.6.6/fs/fcntl.c 2012-10-04 15:27:39.000000000 +0200
3355+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/fcntl.c 2012-10-04 19:05:02.000000000 +0200
3356@@ -21,6 +21,7 @@
3357 #include <linux/rcupdate.h>
3358 #include <linux/pid_namespace.h>
3359 #include <linux/user_namespace.h>
3360+#include <linux/vs_limit.h>
3361
3362 #include <asm/poll.h>
3363 #include <asm/siginfo.h>
3364@@ -104,6 +105,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3365
3366 if (tofree)
3367 filp_close(tofree, files);
3368+ else
3369+ vx_openfd_inc(newfd); /* fd was unused */
3370
3371 return newfd;
3372
3373@@ -477,6 +480,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3374 filp = fget_raw_light(fd, &fput_needed);
3375 if (!filp)
3376 goto out;
3377+ if (!vx_files_avail(1))
3378+ goto out;
3379
3380 if (unlikely(filp->f_mode & FMODE_PATH)) {
3381 if (!check_fcntl_cmd(cmd))
3382diff -NurpP --minimal linux-3.6.6/fs/file.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/file.c
3383--- linux-3.6.6/fs/file.c 2012-05-21 18:07:20.000000000 +0200
3384+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/file.c 2012-10-04 18:47:00.000000000 +0200
3385@@ -21,6 +21,7 @@
3386 #include <linux/spinlock.h>
3387 #include <linux/rcupdate.h>
3388 #include <linux/workqueue.h>
3389+#include <linux/vs_limit.h>
3390
3391 struct fdtable_defer {
3392 spinlock_t lock;
3393@@ -358,6 +359,8 @@ struct files_struct *dup_fd(struct files
3394 struct file *f = *old_fds++;
3395 if (f) {
3396 get_file(f);
3397+ /* TODO: sum it first for check and performance */
3398+ vx_openfd_inc(open_files - i);
3399 } else {
3400 /*
3401 * The fd may be claimed in the fd bitmap but not yet
3402@@ -464,6 +467,7 @@ repeat:
3403 else
3404 __clear_close_on_exec(fd, fdt);
3405 error = fd;
3406+ vx_openfd_inc(fd);
3407 #if 1
3408 /* Sanity check */
3409 if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3410diff -NurpP --minimal linux-3.6.6/fs/file_table.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/file_table.c
3411--- linux-3.6.6/fs/file_table.c 2012-10-04 15:27:39.000000000 +0200
3412+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/file_table.c 2012-10-04 19:10:21.000000000 +0200
3413@@ -26,6 +26,8 @@
3414 #include <linux/hardirq.h>
3415 #include <linux/task_work.h>
3416 #include <linux/ima.h>
3417+#include <linux/vs_limit.h>
3418+#include <linux/vs_context.h>
3419
3420 #include <linux/atomic.h>
3421
3422@@ -136,6 +138,8 @@ struct file *get_empty_filp(void)
3423 spin_lock_init(&f->f_lock);
3424 eventpoll_init_file(f);
3425 /* f->f_version: 0 */
3426+ f->f_xid = vx_current_xid();
3427+ vx_files_inc(f);
3428 return f;
3429
3430 over:
3431@@ -257,6 +261,8 @@ static void __fput(struct file *file)
3432 i_readcount_dec(inode);
3433 if (file->f_mode & FMODE_WRITE)
3434 drop_file_write_access(file);
3435+ vx_files_dec(file);
3436+ file->f_xid = 0;
3437 file->f_path.dentry = NULL;
3438 file->f_path.mnt = NULL;
3439 file_free(file);
3440@@ -449,6 +455,8 @@ void put_filp(struct file *file)
3441 {
3442 if (atomic_long_dec_and_test(&file->f_count)) {
3443 security_file_free(file);
3444+ vx_files_dec(file);
3445+ file->f_xid = 0;
3446 file_sb_list_del(file);
3447 file_free(file);
3448 }
3449diff -NurpP --minimal linux-3.6.6/fs/fs_struct.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/fs_struct.c
3450--- linux-3.6.6/fs/fs_struct.c 2012-10-04 15:27:39.000000000 +0200
3451+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/fs_struct.c 2012-10-04 19:08:56.000000000 +0200
3452@@ -4,6 +4,7 @@
3453 #include <linux/path.h>
3454 #include <linux/slab.h>
3455 #include <linux/fs_struct.h>
3456+#include <linux/vserver/global.h>
3457 #include "internal.h"
3458
3459 /*
3460@@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3461 {
3462 path_put(&fs->root);
3463 path_put(&fs->pwd);
3464+ atomic_dec(&vs_global_fs);
3465 kmem_cache_free(fs_cachep, fs);
3466 }
3467
3468@@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3469 fs->pwd = old->pwd;
3470 path_get(&fs->pwd);
3471 spin_unlock(&old->lock);
3472+ atomic_inc(&vs_global_fs);
3473 }
3474 return fs;
3475 }
3476diff -NurpP --minimal linux-3.6.6/fs/gfs2/file.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/gfs2/file.c
3477--- linux-3.6.6/fs/gfs2/file.c 2012-10-04 15:27:40.000000000 +0200
3478+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/gfs2/file.c 2012-10-04 19:05:34.000000000 +0200
3479@@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3480 [12] = GFS2_DIF_EXHASH,
3481 [14] = GFS2_DIF_INHERIT_JDATA,
3482 [17] = GFS2_DIF_TOPDIR,
3483+ [27] = GFS2_DIF_IXUNLINK,
3484+ [26] = GFS2_DIF_BARRIER,
3485+ [29] = GFS2_DIF_COW,
3486 };
3487
3488 static const u32 gfs2_to_fsflags[32] = {
3489@@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3490 [gfs2fl_ExHash] = FS_INDEX_FL,
3491 [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3492 [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3493+ [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3494+ [gfs2fl_Barrier] = FS_BARRIER_FL,
3495+ [gfs2fl_Cow] = FS_COW_FL,
3496 };
3497
3498 static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3499@@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3500 {
3501 struct gfs2_inode *ip = GFS2_I(inode);
3502 unsigned int flags = inode->i_flags;
3503+ unsigned int vflags = inode->i_vflags;
3504+
3505+ flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3506+ S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3507
3508- flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3509 if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3510 inode->i_flags |= S_NOSEC;
3511 if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3512 flags |= S_IMMUTABLE;
3513+ if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3514+ flags |= S_IXUNLINK;
3515+
3516 if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3517 flags |= S_APPEND;
3518 if (ip->i_diskflags & GFS2_DIF_NOATIME)
3519@@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3520 if (ip->i_diskflags & GFS2_DIF_SYNC)
3521 flags |= S_SYNC;
3522 inode->i_flags = flags;
3523+
3524+ vflags &= ~(V_BARRIER | V_COW);
3525+
3526+ if (ip->i_diskflags & GFS2_DIF_BARRIER)
3527+ vflags |= V_BARRIER;
3528+ if (ip->i_diskflags & GFS2_DIF_COW)
3529+ vflags |= V_COW;
3530+ inode->i_vflags = vflags;
3531+}
3532+
3533+void gfs2_get_inode_flags(struct inode *inode)
3534+{
3535+ struct gfs2_inode *ip = GFS2_I(inode);
3536+ unsigned int flags = inode->i_flags;
3537+ unsigned int vflags = inode->i_vflags;
3538+
3539+ ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3540+ GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3541+ GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3542+ GFS2_DIF_BARRIER | GFS2_DIF_COW);
3543+
3544+ if (flags & S_IMMUTABLE)
3545+ ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3546+ if (flags & S_IXUNLINK)
3547+ ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3548+
3549+ if (flags & S_APPEND)
3550+ ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3551+ if (flags & S_NOATIME)
3552+ ip->i_diskflags |= GFS2_DIF_NOATIME;
3553+ if (flags & S_SYNC)
3554+ ip->i_diskflags |= GFS2_DIF_SYNC;
3555+
3556+ if (vflags & V_BARRIER)
3557+ ip->i_diskflags |= GFS2_DIF_BARRIER;
3558+ if (vflags & V_COW)
3559+ ip->i_diskflags |= GFS2_DIF_COW;
3560 }
3561
3562 /* Flags that can be set by user space */
3563@@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3564 return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3565 }
3566
3567+int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3568+{
3569+ struct gfs2_inode *ip = GFS2_I(inode);
3570+ struct gfs2_sbd *sdp = GFS2_SB(inode);
3571+ struct buffer_head *bh;
3572+ struct gfs2_holder gh;
3573+ int error;
3574+
3575+ error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3576+ if (error)
3577+ return error;
3578+ error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3579+ if (error)
3580+ goto out;
3581+ error = gfs2_meta_inode_buffer(ip, &bh);
3582+ if (error)
3583+ goto out_trans_end;
3584+ gfs2_trans_add_bh(ip->i_gl, bh, 1);
3585+ inode->i_flags = flags;
3586+ inode->i_vflags = vflags;
3587+ gfs2_get_inode_flags(inode);
3588+ gfs2_dinode_out(ip, bh->b_data);
3589+ brelse(bh);
3590+ gfs2_set_aops(inode);
3591+out_trans_end:
3592+ gfs2_trans_end(sdp);
3593+out:
3594+ gfs2_glock_dq_uninit(&gh);
3595+ return error;
3596+}
3597+
3598 static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3599 {
3600 switch(cmd) {
3601diff -NurpP --minimal linux-3.6.6/fs/gfs2/inode.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/gfs2/inode.h
3602--- linux-3.6.6/fs/gfs2/inode.h 2012-07-22 23:39:40.000000000 +0200
3603+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/gfs2/inode.h 2012-10-04 18:47:00.000000000 +0200
3604@@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3605 extern const struct file_operations gfs2_dir_fops_nolock;
3606
3607 extern void gfs2_set_inode_flags(struct inode *inode);
3608+extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3609
3610 #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3611 extern const struct file_operations gfs2_file_fops;
3612diff -NurpP --minimal linux-3.6.6/fs/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/inode.c
3613--- linux-3.6.6/fs/inode.c 2012-10-04 15:27:40.000000000 +0200
3614+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/inode.c 2012-10-04 18:47:00.000000000 +0200
3615@@ -17,6 +17,7 @@
3616 #include <linux/prefetch.h>
3617 #include <linux/buffer_head.h> /* for inode_has_buffers */
3618 #include <linux/ratelimit.h>
3619+#include <linux/vs_tag.h>
3620 #include "internal.h"
3621
3622 /*
3623@@ -128,6 +129,9 @@ int inode_init_always(struct super_block
3624 struct address_space *const mapping = &inode->i_data;
3625
3626 inode->i_sb = sb;
3627+
3628+ /* essential because of inode slab reuse */
3629+ inode->i_tag = 0;
3630 inode->i_blkbits = sb->s_blocksize_bits;
3631 inode->i_flags = 0;
3632 atomic_set(&inode->i_count, 1);
3633@@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3634 inode->i_bdev = NULL;
3635 inode->i_cdev = NULL;
3636 inode->i_rdev = 0;
3637+ inode->i_mdev = 0;
3638 inode->dirtied_when = 0;
3639
3640 if (security_inode_alloc(inode))
3641@@ -470,6 +475,8 @@ void __insert_inode_hash(struct inode *i
3642 }
3643 EXPORT_SYMBOL(__insert_inode_hash);
3644
3645+EXPORT_SYMBOL_GPL(__iget);
3646+
3647 /**
3648 * __remove_inode_hash - remove an inode from the hash
3649 * @inode: inode to unhash
3650@@ -1792,9 +1799,11 @@ void init_special_inode(struct inode *in
3651 if (S_ISCHR(mode)) {
3652 inode->i_fop = &def_chr_fops;
3653 inode->i_rdev = rdev;
3654+ inode->i_mdev = rdev;
3655 } else if (S_ISBLK(mode)) {
3656 inode->i_fop = &def_blk_fops;
3657 inode->i_rdev = rdev;
3658+ inode->i_mdev = rdev;
3659 } else if (S_ISFIFO(mode))
3660 inode->i_fop = &def_fifo_fops;
3661 else if (S_ISSOCK(mode))
3662@@ -1823,6 +1832,7 @@ void inode_init_owner(struct inode *inod
3663 } else
3664 inode->i_gid = current_fsgid();
3665 inode->i_mode = mode;
3666+ inode->i_tag = dx_current_fstag(inode->i_sb);
3667 }
3668 EXPORT_SYMBOL(inode_init_owner);
3669
3670diff -NurpP --minimal linux-3.6.6/fs/ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ioctl.c
3671--- linux-3.6.6/fs/ioctl.c 2012-05-21 18:07:24.000000000 +0200
3672+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ioctl.c 2012-10-04 18:47:00.000000000 +0200
3673@@ -15,6 +15,9 @@
3674 #include <linux/writeback.h>
3675 #include <linux/buffer_head.h>
3676 #include <linux/falloc.h>
3677+#include <linux/proc_fs.h>
3678+#include <linux/vserver/inode.h>
3679+#include <linux/vs_tag.h>
3680
3681 #include <asm/ioctls.h>
3682
3683diff -NurpP --minimal linux-3.6.6/fs/ioprio.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ioprio.c
3684--- linux-3.6.6/fs/ioprio.c 2012-07-22 23:39:40.000000000 +0200
3685+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ioprio.c 2012-10-04 18:47:00.000000000 +0200
3686@@ -28,6 +28,7 @@
3687 #include <linux/syscalls.h>
3688 #include <linux/security.h>
3689 #include <linux/pid_namespace.h>
3690+#include <linux/vs_base.h>
3691
3692 int set_task_ioprio(struct task_struct *task, int ioprio)
3693 {
3694@@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3695 else
3696 pgrp = find_vpid(who);
3697 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3698+ if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3699+ continue;
3700 ret = set_task_ioprio(p, ioprio);
3701 if (ret)
3702 break;
3703@@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3704 else
3705 pgrp = find_vpid(who);
3706 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3707+ if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3708+ continue;
3709 tmpio = get_task_ioprio(p);
3710 if (tmpio < 0)
3711 continue;
3712diff -NurpP --minimal linux-3.6.6/fs/jfs/file.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/file.c
3713--- linux-3.6.6/fs/jfs/file.c 2011-10-24 18:45:27.000000000 +0200
3714+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/file.c 2012-10-04 18:47:00.000000000 +0200
3715@@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3716 if (is_quota_modification(inode, iattr))
3717 dquot_initialize(inode);
3718 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3719- (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3720+ (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3721+ (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3722 rc = dquot_transfer(inode, iattr);
3723 if (rc)
3724 return rc;
3725@@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3726 #ifdef CONFIG_JFS_POSIX_ACL
3727 .get_acl = jfs_get_acl,
3728 #endif
3729+ .sync_flags = jfs_sync_flags,
3730 };
3731
3732 const struct file_operations jfs_file_operations = {
3733diff -NurpP --minimal linux-3.6.6/fs/jfs/ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/ioctl.c
3734--- linux-3.6.6/fs/jfs/ioctl.c 2012-03-19 19:47:25.000000000 +0100
3735+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/ioctl.c 2012-10-04 18:47:00.000000000 +0200
3736@@ -11,6 +11,7 @@
3737 #include <linux/mount.h>
3738 #include <linux/time.h>
3739 #include <linux/sched.h>
3740+#include <linux/mount.h>
3741 #include <asm/current.h>
3742 #include <asm/uaccess.h>
3743
3744@@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3745 }
3746
3747
3748+int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3749+{
3750+ inode->i_flags = flags;
3751+ inode->i_vflags = vflags;
3752+ jfs_get_inode_flags(JFS_IP(inode));
3753+ inode->i_ctime = CURRENT_TIME_SEC;
3754+ mark_inode_dirty(inode);
3755+ return 0;
3756+}
3757+
3758 long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3759 {
3760 struct inode *inode = filp->f_dentry->d_inode;
3761@@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3762 if (!S_ISDIR(inode->i_mode))
3763 flags &= ~JFS_DIRSYNC_FL;
3764
3765+ if (IS_BARRIER(inode)) {
3766+ vxwprintk_task(1, "messing with the barrier.");
3767+ return -EACCES;
3768+ }
3769+
3770 /* Is it quota file? Do not allow user to mess with it */
3771 if (IS_NOQUOTA(inode)) {
3772 err = -EPERM;
3773@@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3774 * the relevant capability.
3775 */
3776 if ((oldflags & JFS_IMMUTABLE_FL) ||
3777- ((flags ^ oldflags) &
3778- (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3779+ ((flags ^ oldflags) & (JFS_APPEND_FL |
3780+ JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3781 if (!capable(CAP_LINUX_IMMUTABLE)) {
3782 mutex_unlock(&inode->i_mutex);
3783 err = -EPERM;
3784@@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3785 }
3786 }
3787
3788- flags = flags & JFS_FL_USER_MODIFIABLE;
3789+ flags &= JFS_FL_USER_MODIFIABLE;
3790 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3791 jfs_inode->mode2 = flags;
3792
3793diff -NurpP --minimal linux-3.6.6/fs/jfs/jfs_dinode.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_dinode.h
3794--- linux-3.6.6/fs/jfs/jfs_dinode.h 2008-12-25 00:26:37.000000000 +0100
3795+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_dinode.h 2012-10-04 18:47:00.000000000 +0200
3796@@ -161,9 +161,13 @@ struct dinode {
3797
3798 #define JFS_APPEND_FL 0x01000000 /* writes to file may only append */
3799 #define JFS_IMMUTABLE_FL 0x02000000 /* Immutable file */
3800+#define JFS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
3801
3802-#define JFS_FL_USER_VISIBLE 0x03F80000
3803-#define JFS_FL_USER_MODIFIABLE 0x03F80000
3804+#define JFS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
3805+#define JFS_COW_FL 0x20000000 /* Copy on Write marker */
3806+
3807+#define JFS_FL_USER_VISIBLE 0x07F80000
3808+#define JFS_FL_USER_MODIFIABLE 0x07F80000
3809 #define JFS_FL_INHERIT 0x03C80000
3810
3811 /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3812diff -NurpP --minimal linux-3.6.6/fs/jfs/jfs_filsys.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_filsys.h
3813--- linux-3.6.6/fs/jfs/jfs_filsys.h 2008-12-25 00:26:37.000000000 +0100
3814+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_filsys.h 2012-10-04 18:47:00.000000000 +0200
3815@@ -263,6 +263,7 @@
3816 #define JFS_NAME_MAX 255
3817 #define JFS_PATH_MAX BPSIZE
3818
3819+#define JFS_TAGGED 0x00800000 /* Context Tagging */
3820
3821 /*
3822 * file system state (superblock state)
3823diff -NurpP --minimal linux-3.6.6/fs/jfs/jfs_imap.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_imap.c
3824--- linux-3.6.6/fs/jfs/jfs_imap.c 2012-01-09 16:14:54.000000000 +0100
3825+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_imap.c 2012-10-04 18:47:00.000000000 +0200
3826@@ -46,6 +46,7 @@
3827 #include <linux/pagemap.h>
3828 #include <linux/quotaops.h>
3829 #include <linux/slab.h>
3830+#include <linux/vs_tag.h>
3831
3832 #include "jfs_incore.h"
3833 #include "jfs_inode.h"
3834@@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3835 {
3836 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3837 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3838+ uid_t uid;
3839+ gid_t gid;
3840
3841 jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3842 jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3843@@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3844 }
3845 set_nlink(ip, le32_to_cpu(dip->di_nlink));
3846
3847- jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3848+ uid = le32_to_cpu(dip->di_uid);
3849+ gid = le32_to_cpu(dip->di_gid);
3850+ ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
3851+
3852+ jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3853 if (sbi->uid == -1)
3854 ip->i_uid = jfs_ip->saved_uid;
3855 else {
3856 ip->i_uid = sbi->uid;
3857 }
3858
3859- jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3860+ jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3861 if (sbi->gid == -1)
3862 ip->i_gid = jfs_ip->saved_gid;
3863 else {
3864@@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
3865 dip->di_size = cpu_to_le64(ip->i_size);
3866 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3867 dip->di_nlink = cpu_to_le32(ip->i_nlink);
3868- if (sbi->uid == -1)
3869- dip->di_uid = cpu_to_le32(ip->i_uid);
3870- else
3871- dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
3872- if (sbi->gid == -1)
3873- dip->di_gid = cpu_to_le32(ip->i_gid);
3874- else
3875- dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
3876+
3877+ dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
3878+ (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
3879+ dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
3880+ (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
3881+
3882 jfs_get_inode_flags(jfs_ip);
3883 /*
3884 * mode2 is only needed for storing the higher order bits.
3885diff -NurpP --minimal linux-3.6.6/fs/jfs/jfs_inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_inode.c
3886--- linux-3.6.6/fs/jfs/jfs_inode.c 2012-01-09 16:14:54.000000000 +0100
3887+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_inode.c 2012-10-04 18:47:00.000000000 +0200
3888@@ -18,6 +18,7 @@
3889
3890 #include <linux/fs.h>
3891 #include <linux/quotaops.h>
3892+#include <linux/vs_tag.h>
3893 #include "jfs_incore.h"
3894 #include "jfs_inode.h"
3895 #include "jfs_filsys.h"
3896@@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3897 {
3898 unsigned int flags = JFS_IP(inode)->mode2;
3899
3900- inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3901- S_NOATIME | S_DIRSYNC | S_SYNC);
3902+ inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3903+ S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3904
3905 if (flags & JFS_IMMUTABLE_FL)
3906 inode->i_flags |= S_IMMUTABLE;
3907+ if (flags & JFS_IXUNLINK_FL)
3908+ inode->i_flags |= S_IXUNLINK;
3909+
3910+ if (flags & JFS_SYNC_FL)
3911+ inode->i_flags |= S_SYNC;
3912 if (flags & JFS_APPEND_FL)
3913 inode->i_flags |= S_APPEND;
3914 if (flags & JFS_NOATIME_FL)
3915 inode->i_flags |= S_NOATIME;
3916 if (flags & JFS_DIRSYNC_FL)
3917 inode->i_flags |= S_DIRSYNC;
3918- if (flags & JFS_SYNC_FL)
3919- inode->i_flags |= S_SYNC;
3920+
3921+ inode->i_vflags &= ~(V_BARRIER | V_COW);
3922+
3923+ if (flags & JFS_BARRIER_FL)
3924+ inode->i_vflags |= V_BARRIER;
3925+ if (flags & JFS_COW_FL)
3926+ inode->i_vflags |= V_COW;
3927 }
3928
3929 void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3930 {
3931 unsigned int flags = jfs_ip->vfs_inode.i_flags;
3932+ unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3933+
3934+ jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3935+ JFS_APPEND_FL | JFS_NOATIME_FL |
3936+ JFS_DIRSYNC_FL | JFS_SYNC_FL |
3937+ JFS_BARRIER_FL | JFS_COW_FL);
3938
3939- jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3940- JFS_DIRSYNC_FL | JFS_SYNC_FL);
3941 if (flags & S_IMMUTABLE)
3942 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3943+ if (flags & S_IXUNLINK)
3944+ jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3945+
3946 if (flags & S_APPEND)
3947 jfs_ip->mode2 |= JFS_APPEND_FL;
3948 if (flags & S_NOATIME)
3949@@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3950 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3951 if (flags & S_SYNC)
3952 jfs_ip->mode2 |= JFS_SYNC_FL;
3953+
3954+ if (vflags & V_BARRIER)
3955+ jfs_ip->mode2 |= JFS_BARRIER_FL;
3956+ if (vflags & V_COW)
3957+ jfs_ip->mode2 |= JFS_COW_FL;
3958 }
3959
3960 /*
3961diff -NurpP --minimal linux-3.6.6/fs/jfs/jfs_inode.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_inode.h
3962--- linux-3.6.6/fs/jfs/jfs_inode.h 2011-10-24 18:45:27.000000000 +0200
3963+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/jfs_inode.h 2012-10-04 18:47:00.000000000 +0200
3964@@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3965 extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3966 int fh_len, int fh_type);
3967 extern void jfs_set_inode_flags(struct inode *);
3968+extern int jfs_sync_flags(struct inode *, int, int);
3969 extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3970 extern int jfs_setattr(struct dentry *, struct iattr *);
3971
3972diff -NurpP --minimal linux-3.6.6/fs/jfs/namei.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/namei.c
3973--- linux-3.6.6/fs/jfs/namei.c 2012-10-04 15:27:40.000000000 +0200
3974+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/namei.c 2012-10-04 18:47:00.000000000 +0200
3975@@ -22,6 +22,7 @@
3976 #include <linux/ctype.h>
3977 #include <linux/quotaops.h>
3978 #include <linux/exportfs.h>
3979+#include <linux/vs_tag.h>
3980 #include "jfs_incore.h"
3981 #include "jfs_superblock.h"
3982 #include "jfs_inode.h"
3983@@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3984 jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3985 }
3986
3987+ dx_propagate_tag(nd, ip);
3988 return d_splice_alias(ip, dentry);
3989 }
3990
3991@@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3992 #ifdef CONFIG_JFS_POSIX_ACL
3993 .get_acl = jfs_get_acl,
3994 #endif
3995+ .sync_flags = jfs_sync_flags,
3996 };
3997
3998 const struct file_operations jfs_dir_operations = {
3999diff -NurpP --minimal linux-3.6.6/fs/jfs/super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/super.c
4000--- linux-3.6.6/fs/jfs/super.c 2012-10-04 15:27:40.000000000 +0200
4001+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/jfs/super.c 2012-10-04 18:47:00.000000000 +0200
4002@@ -197,7 +197,8 @@ static void jfs_put_super(struct super_b
4003 enum {
4004 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4005 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4006- Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4007+ Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4008+ Opt_tag, Opt_notag, Opt_tagid
4009 };
4010
4011 static const match_table_t tokens = {
4012@@ -207,6 +208,10 @@ static const match_table_t tokens = {
4013 {Opt_resize, "resize=%u"},
4014 {Opt_resize_nosize, "resize"},
4015 {Opt_errors, "errors=%s"},
4016+ {Opt_tag, "tag"},
4017+ {Opt_notag, "notag"},
4018+ {Opt_tagid, "tagid=%u"},
4019+ {Opt_tag, "tagxid"},
4020 {Opt_ignore, "noquota"},
4021 {Opt_ignore, "quota"},
4022 {Opt_usrquota, "usrquota"},
4023@@ -341,6 +346,20 @@ static int parse_options(char *options,
4024 }
4025 break;
4026 }
4027+#ifndef CONFIG_TAGGING_NONE
4028+ case Opt_tag:
4029+ *flag |= JFS_TAGGED;
4030+ break;
4031+ case Opt_notag:
4032+ *flag &= JFS_TAGGED;
4033+ break;
4034+#endif
4035+#ifdef CONFIG_PROPAGATE
4036+ case Opt_tagid:
4037+ /* use args[0] */
4038+ *flag |= JFS_TAGGED;
4039+ break;
4040+#endif
4041 default:
4042 printk("jfs: Unrecognized mount option \"%s\" "
4043 " or missing value\n", p);
4044@@ -372,6 +391,12 @@ static int jfs_remount(struct super_bloc
4045 return -EINVAL;
4046 }
4047
4048+ if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4049+ printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4050+ sb->s_id);
4051+ return -EINVAL;
4052+ }
4053+
4054 if (newLVSize) {
4055 if (sb->s_flags & MS_RDONLY) {
4056 printk(KERN_ERR
4057@@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4058 #ifdef CONFIG_JFS_POSIX_ACL
4059 sb->s_flags |= MS_POSIXACL;
4060 #endif
4061+ /* map mount option tagxid */
4062+ if (sbi->flag & JFS_TAGGED)
4063+ sb->s_flags |= MS_TAGGED;
4064
4065 if (newLVSize) {
4066 printk(KERN_ERR "resize option for remount only\n");
4067diff -NurpP --minimal linux-3.6.6/fs/libfs.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/libfs.c
4068--- linux-3.6.6/fs/libfs.c 2012-10-04 15:27:40.000000000 +0200
4069+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/libfs.c 2012-10-04 18:47:00.000000000 +0200
4070@@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4071 * both impossible due to the lock on directory.
4072 */
4073
4074-int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4075+static inline int do_dcache_readdir_filter(struct file *filp,
4076+ void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4077 {
4078 struct dentry *dentry = filp->f_path.dentry;
4079 struct dentry *cursor = filp->private_data;
4080@@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4081 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4082 struct dentry *next;
4083 next = list_entry(p, struct dentry, d_u.d_child);
4084+ if (filter && !filter(next))
4085+ continue;
4086 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4087 if (!simple_positive(next)) {
4088 spin_unlock(&next->d_lock);
4089@@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4090 return 0;
4091 }
4092
4093+int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4094+{
4095+ return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4096+}
4097+
4098+int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4099+ int (*filter)(struct dentry *))
4100+{
4101+ return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4102+}
4103+
4104 ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4105 {
4106 return -EISDIR;
4107@@ -983,6 +997,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4108 EXPORT_SYMBOL(dcache_dir_lseek);
4109 EXPORT_SYMBOL(dcache_dir_open);
4110 EXPORT_SYMBOL(dcache_readdir);
4111+EXPORT_SYMBOL(dcache_readdir_filter);
4112 EXPORT_SYMBOL(generic_read_dir);
4113 EXPORT_SYMBOL(mount_pseudo);
4114 EXPORT_SYMBOL(simple_write_begin);
4115diff -NurpP --minimal linux-3.6.6/fs/locks.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/locks.c
4116--- linux-3.6.6/fs/locks.c 2012-10-04 15:27:40.000000000 +0200
4117+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/locks.c 2012-10-04 18:47:00.000000000 +0200
4118@@ -126,6 +126,8 @@
4119 #include <linux/time.h>
4120 #include <linux/rcupdate.h>
4121 #include <linux/pid_namespace.h>
4122+#include <linux/vs_base.h>
4123+#include <linux/vs_limit.h>
4124
4125 #include <asm/uaccess.h>
4126
4127@@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4128 /* Allocate an empty lock structure. */
4129 struct file_lock *locks_alloc_lock(void)
4130 {
4131- struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4132+ struct file_lock *fl;
4133
4134- if (fl)
4135- locks_init_lock_heads(fl);
4136+ if (!vx_locks_avail(1))
4137+ return NULL;
4138
4139+ fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4140+
4141+ if (fl) {
4142+ locks_init_lock_heads(fl);
4143+ fl->fl_xid = -1;
4144+ }
4145 return fl;
4146 }
4147 EXPORT_SYMBOL_GPL(locks_alloc_lock);
4148@@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4149 BUG_ON(!list_empty(&fl->fl_block));
4150 BUG_ON(!list_empty(&fl->fl_link));
4151
4152+ vx_locks_dec(fl);
4153 locks_release_private(fl);
4154 kmem_cache_free(filelock_cache, fl);
4155 }
4156@@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4157 {
4158 memset(fl, 0, sizeof(struct file_lock));
4159 locks_init_lock_heads(fl);
4160+ fl->fl_xid = -1;
4161 }
4162
4163 EXPORT_SYMBOL(locks_init_lock);
4164@@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4165 new->fl_file = fl->fl_file;
4166 new->fl_ops = fl->fl_ops;
4167 new->fl_lmops = fl->fl_lmops;
4168+ new->fl_xid = fl->fl_xid;
4169
4170 locks_copy_private(new, fl);
4171 }
4172@@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4173 fl->fl_flags = FL_FLOCK;
4174 fl->fl_type = type;
4175 fl->fl_end = OFFSET_MAX;
4176+
4177+ vxd_assert(filp->f_xid == vx_current_xid(),
4178+ "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4179+ fl->fl_xid = filp->f_xid;
4180+ vx_locks_inc(fl);
4181
4182 *lock = fl;
4183 return 0;
4184@@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4185
4186 fl->fl_owner = current->files;
4187 fl->fl_pid = current->tgid;
4188+ fl->fl_xid = vx_current_xid();
4189
4190 fl->fl_file = filp;
4191 fl->fl_flags = FL_LEASE;
4192@@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4193 if (fl == NULL)
4194 return ERR_PTR(error);
4195
4196+ fl->fl_xid = vx_current_xid();
4197+ if (filp)
4198+ vxd_assert(filp->f_xid == fl->fl_xid,
4199+ "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4200+ vx_locks_inc(fl);
4201 error = lease_init(filp, type, fl);
4202 if (error) {
4203 locks_free_lock(fl);
4204@@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4205 lock_flocks();
4206 }
4207
4208+ new_fl->fl_xid = -1;
4209 find_conflict:
4210 for_each_lock(inode, before) {
4211 struct file_lock *fl = *before;
4212@@ -773,6 +796,7 @@ find_conflict:
4213 goto out;
4214 locks_copy_lock(new_fl, request);
4215 locks_insert_lock(before, new_fl);
4216+ vx_locks_inc(new_fl);
4217 new_fl = NULL;
4218 error = 0;
4219
4220@@ -783,7 +807,8 @@ out:
4221 return error;
4222 }
4223
4224-static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4225+static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4226+ struct file_lock *conflock, xid_t xid)
4227 {
4228 struct file_lock *fl;
4229 struct file_lock *new_fl = NULL;
4230@@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4231 struct file_lock **before;
4232 int error, added = 0;
4233
4234+ vxd_assert(xid == vx_current_xid(),
4235+ "xid(%d) == current(%d)", xid, vx_current_xid());
4236 /*
4237 * We may need two file_lock structures for this operation,
4238 * so we get them in advance to avoid races.
4239@@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4240 (request->fl_type != F_UNLCK ||
4241 request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4242 new_fl = locks_alloc_lock();
4243+ new_fl->fl_xid = xid;
4244+ vx_locks_inc(new_fl);
4245 new_fl2 = locks_alloc_lock();
4246+ new_fl2->fl_xid = xid;
4247+ vx_locks_inc(new_fl2);
4248 }
4249
4250 lock_flocks();
4251@@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4252 int posix_lock_file(struct file *filp, struct file_lock *fl,
4253 struct file_lock *conflock)
4254 {
4255- return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4256+ return __posix_lock_file(filp->f_path.dentry->d_inode,
4257+ fl, conflock, filp->f_xid);
4258 }
4259 EXPORT_SYMBOL(posix_lock_file);
4260
4261@@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4262 fl.fl_end = offset + count - 1;
4263
4264 for (;;) {
4265- error = __posix_lock_file(inode, &fl, NULL);
4266+ error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4267 if (error != FILE_LOCK_DEFERRED)
4268 break;
4269 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4270@@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4271 goto out;
4272
4273 locks_insert_lock(before, lease);
4274+ vx_locks_inc(lease);
4275 return 0;
4276
4277 out:
4278@@ -1838,6 +1871,11 @@ int fcntl_setlk(unsigned int fd, struct
4279 if (file_lock == NULL)
4280 return -ENOLCK;
4281
4282+ vxd_assert(filp->f_xid == vx_current_xid(),
4283+ "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4284+ file_lock->fl_xid = filp->f_xid;
4285+ vx_locks_inc(file_lock);
4286+
4287 /*
4288 * This might block, so we do it before checking the inode.
4289 */
4290@@ -1956,6 +1994,11 @@ int fcntl_setlk64(unsigned int fd, struc
4291 if (file_lock == NULL)
4292 return -ENOLCK;
4293
4294+ vxd_assert(filp->f_xid == vx_current_xid(),
4295+ "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4296+ file_lock->fl_xid = filp->f_xid;
4297+ vx_locks_inc(file_lock);
4298+
4299 /*
4300 * This might block, so we do it before checking the inode.
4301 */
4302@@ -2221,8 +2264,11 @@ static int locks_show(struct seq_file *f
4303
4304 lock_get_status(f, fl, *((loff_t *)f->private), "");
4305
4306- list_for_each_entry(bfl, &fl->fl_block, fl_block)
4307+ list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4308+ if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4309+ continue;
4310 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4311+ }
4312
4313 return 0;
4314 }
4315diff -NurpP --minimal linux-3.6.6/fs/mount.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/mount.h
4316--- linux-3.6.6/fs/mount.h 2012-10-04 15:27:40.000000000 +0200
4317+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/mount.h 2012-10-04 18:47:00.000000000 +0200
4318@@ -46,6 +46,7 @@ struct mount {
4319 int mnt_expiry_mark; /* true if marked for expiry */
4320 int mnt_pinned;
4321 int mnt_ghosts;
4322+ tag_t mnt_tag; /* tagging used for vfsmount */
4323 };
4324
4325 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4326diff -NurpP --minimal linux-3.6.6/fs/namei.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/namei.c
4327--- linux-3.6.6/fs/namei.c 2012-11-06 18:42:13.000000000 +0100
4328+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/namei.c 2012-11-06 18:43:41.000000000 +0100
4329@@ -34,6 +34,14 @@
4330 #include <linux/device_cgroup.h>
4331 #include <linux/fs_struct.h>
4332 #include <linux/posix_acl.h>
4333+#include <linux/proc_fs.h>
4334+#include <linux/vserver/inode.h>
4335+#include <linux/vs_base.h>
4336+#include <linux/vs_tag.h>
4337+#include <linux/vs_cowbl.h>
4338+#include <linux/vs_device.h>
4339+#include <linux/vs_context.h>
4340+#include <linux/pid_namespace.h>
4341 #include <asm/uaccess.h>
4342
4343 #include "internal.h"
4344@@ -212,6 +220,89 @@ static int check_acl(struct inode *inode
4345 return -EAGAIN;
4346 }
4347
4348+static inline int dx_barrier(const struct inode *inode)
4349+{
4350+ if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4351+ vxwprintk_task(1, "did hit the barrier.");
4352+ return 1;
4353+ }
4354+ return 0;
4355+}
4356+
4357+static int __dx_permission(const struct inode *inode, int mask)
4358+{
4359+ if (dx_barrier(inode))
4360+ return -EACCES;
4361+
4362+ if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4363+ /* devpts is xid tagged */
4364+ if (S_ISDIR(inode->i_mode) ||
4365+ vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4366+ return 0;
4367+
4368+ /* just pretend we didn't find anything */
4369+ return -ENOENT;
4370+ }
4371+ else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4372+ struct proc_dir_entry *de = PDE(inode);
4373+
4374+ if (de && !vx_hide_check(0, de->vx_flags))
4375+ goto out;
4376+
4377+ if ((mask & (MAY_WRITE | MAY_APPEND))) {
4378+ struct pid *pid;
4379+ struct task_struct *tsk;
4380+
4381+ if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4382+ vx_flags(VXF_STATE_SETUP, 0))
4383+ return 0;
4384+
4385+ pid = PROC_I(inode)->pid;
4386+ if (!pid)
4387+ goto out;
4388+
4389+ rcu_read_lock();
4390+ tsk = pid_task(pid, PIDTYPE_PID);
4391+ vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4392+ tsk, (tsk ? vx_task_xid(tsk) : 0));
4393+ if (tsk &&
4394+ vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4395+ rcu_read_unlock();
4396+ return 0;
4397+ }
4398+ rcu_read_unlock();
4399+ }
4400+ else {
4401+ /* FIXME: Should we block some entries here? */
4402+ return 0;
4403+ }
4404+ }
4405+ else {
4406+ if (dx_notagcheck(inode->i_sb) ||
4407+ dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4408+ DX_IDENT))
4409+ return 0;
4410+ }
4411+
4412+out:
4413+ return -EACCES;
4414+}
4415+
4416+int dx_permission(const struct inode *inode, int mask)
4417+{
4418+ int ret = __dx_permission(inode, mask);
4419+ if (unlikely(ret)) {
4420+#ifndef CONFIG_VSERVER_WARN_DEVPTS
4421+ if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4422+#endif
4423+ vxwprintk_task(1,
4424+ "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4425+ mask, inode->i_sb->s_id, inode, inode->i_tag,
4426+ inode->i_ino);
4427+ }
4428+ return ret;
4429+}
4430+
4431 /*
4432 * This does the basic permission checking
4433 */
4434@@ -334,10 +425,14 @@ int __inode_permission(struct inode *ino
4435 /*
4436 * Nobody gets write access to an immutable file.
4437 */
4438- if (IS_IMMUTABLE(inode))
4439+ if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4440 return -EACCES;
4441 }
4442
4443+ retval = dx_permission(inode, mask);
4444+ if (retval)
4445+ return retval;
4446+
4447 retval = do_inode_permission(inode, mask);
4448 if (retval)
4449 return retval;
4450@@ -1189,7 +1284,8 @@ static void follow_dotdot(struct nameida
4451
4452 if (nd->path.dentry == nd->root.dentry &&
4453 nd->path.mnt == nd->root.mnt) {
4454- break;
4455+ /* for sane '/' avoid follow_mount() */
4456+ return;
4457 }
4458 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4459 /* rare case of legitimate dget_parent()... */
4460@@ -1338,6 +1434,9 @@ static int lookup_fast(struct nameidata
4461 goto unlazy;
4462 }
4463 }
4464+
4465+ /* FIXME: check dx permission */
4466+
4467 path->mnt = mnt;
4468 path->dentry = dentry;
4469 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4470@@ -1373,6 +1472,8 @@ unlazy:
4471 }
4472 }
4473
4474+ /* FIXME: check dx permission */
4475+
4476 path->mnt = mnt;
4477 path->dentry = dentry;
4478 err = follow_managed(path, nd->flags);
4479@@ -2192,7 +2293,7 @@ static int may_delete(struct inode *dir,
4480 if (IS_APPEND(dir))
4481 return -EPERM;
4482 if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4483- IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4484+ IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4485 return -EPERM;
4486 if (isdir) {
4487 if (!S_ISDIR(victim->d_inode->i_mode))
4488@@ -2271,19 +2372,25 @@ int vfs_create(struct inode *dir, struct
4489 bool want_excl)
4490 {
4491 int error = may_create(dir, dentry);
4492- if (error)
4493- return error;
4494+ if (error) {
4495+ vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4496+ return error;
4497+ }
4498
4499 if (!dir->i_op->create)
4500 return -EACCES; /* shouldn't it be ENOSYS? */
4501 mode &= S_IALLUGO;
4502 mode |= S_IFREG;
4503 error = security_inode_create(dir, dentry, mode);
4504- if (error)
4505- return error;
4506+ if (error) {
4507+ vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4508+ return error;
4509+ }
4510 error = dir->i_op->create(dir, dentry, mode, want_excl);
4511 if (!error)
4512 fsnotify_create(dir, dentry);
4513+ else
4514+ vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4515 return error;
4516 }
4517
4518@@ -2318,6 +2425,15 @@ static int may_open(struct path *path, i
4519 break;
4520 }
4521
4522+#ifdef CONFIG_VSERVER_COWBL
4523+ if (IS_COW(inode) &&
4524+ ((flag & O_ACCMODE) != O_RDONLY)) {
4525+ if (IS_COW_LINK(inode))
4526+ return -EMLINK;
4527+ inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4528+ mark_inode_dirty(inode);
4529+ }
4530+#endif
4531 error = inode_permission(inode, acc_mode);
4532 if (error)
4533 return error;
4534@@ -2820,6 +2936,16 @@ finish_open:
4535 }
4536 finish_open_created:
4537 error = may_open(&nd->path, acc_mode, open_flag);
4538+#ifdef CONFIG_VSERVER_COWBL
4539+ if (error == -EMLINK) {
4540+ struct dentry *dentry;
4541+ dentry = cow_break_link(pathname);
4542+ if (IS_ERR(dentry))
4543+ error = PTR_ERR(dentry);
4544+ else
4545+ dput(dentry);
4546+ }
4547+#endif
4548 if (error)
4549 goto out;
4550 file->f_path.mnt = nd->path.mnt;
4551@@ -2884,6 +3010,7 @@ static struct file *path_openat(int dfd,
4552 int opened = 0;
4553 int error;
4554
4555+restart:
4556 file = get_empty_filp();
4557 if (!file)
4558 return ERR_PTR(-ENFILE);
4559@@ -2920,6 +3047,17 @@ static struct file *path_openat(int dfd,
4560 error = do_last(nd, &path, file, op, &opened, pathname);
4561 put_link(nd, &link, cookie);
4562 }
4563+
4564+#ifdef CONFIG_VSERVER_COWBL
4565+ if (filp == ERR_PTR(-EMLINK)) {
4566+ if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4567+ path_put(&nd->root);
4568+ if (base)
4569+ fput(base);
4570+ release_open_intent(nd);
4571+ goto restart;
4572+ }
4573+#endif
4574 out:
4575 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4576 path_put(&nd->root);
4577@@ -3023,6 +3161,11 @@ struct dentry *kern_path_create(int dfd,
4578 goto fail;
4579 }
4580 *path = nd.path;
4581+ vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4582+ path->dentry, path->dentry->d_name.len,
4583+ path->dentry->d_name.name, dentry,
4584+ dentry->d_name.len, dentry->d_name.name,
4585+ path->dentry->d_inode);
4586 return dentry;
4587 fail:
4588 dput(dentry);
4589@@ -3489,7 +3632,7 @@ int vfs_link(struct dentry *old_dentry,
4590 /*
4591 * A link to an append-only or immutable file cannot be created.
4592 */
4593- if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4594+ if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4595 return -EPERM;
4596 if (!dir->i_op->link)
4597 return -EPERM;
4598@@ -3874,6 +4017,253 @@ int vfs_follow_link(struct nameidata *nd
4599 return __vfs_follow_link(nd, link);
4600 }
4601
4602+
4603+#ifdef CONFIG_VSERVER_COWBL
4604+
4605+static inline
4606+long do_cow_splice(struct file *in, struct file *out, size_t len)
4607+{
4608+ loff_t ppos = 0;
4609+
4610+ return do_splice_direct(in, &ppos, out, len, 0);
4611+}
4612+
4613+extern unsigned int mnt_get_count(struct mount *mnt);
4614+
4615+struct dentry *cow_break_link(const char *pathname)
4616+{
4617+ int ret, mode, pathlen, redo = 0;
4618+ struct nameidata old_nd, dir_nd;
4619+ struct path old_path, dir_path;
4620+ struct dentry *dir, *old_dentry, *new_dentry = NULL;
4621+ struct file *old_file;
4622+ struct file *new_file;
4623+ char *to, *path, pad='\251';
4624+ loff_t size;
4625+
4626+ vxdprintk(VXD_CBIT(misc, 1),
4627+ "cow_break_link(" VS_Q("%s") ")", pathname);
4628+ path = kmalloc(PATH_MAX, GFP_KERNEL);
4629+ ret = -ENOMEM;
4630+ if (!path)
4631+ goto out;
4632+
4633+ /* old_nd will have refs to dentry and mnt */
4634+ ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4635+ vxdprintk(VXD_CBIT(misc, 2),
4636+ "do_path_lookup(old): %d [r=%d]",
4637+ ret, mnt_get_count(real_mount(old_nd.path.mnt)));
4638+ if (ret < 0)
4639+ goto out_free_path;
4640+
4641+ old_path = old_nd.path;
4642+ old_dentry = old_path.dentry;
4643+ mode = old_dentry->d_inode->i_mode;
4644+
4645+ to = d_path(&old_path, path, PATH_MAX-2);
4646+ pathlen = strlen(to);
4647+ vxdprintk(VXD_CBIT(misc, 2),
4648+ "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4649+ old_dentry,
4650+ old_dentry->d_name.len, old_dentry->d_name.name,
4651+ old_dentry->d_name.len);
4652+
4653+ to[pathlen + 1] = 0;
4654+retry:
4655+ new_dentry = NULL;
4656+ to[pathlen] = pad--;
4657+ ret = -ELOOP;
4658+ if (pad <= '\240')
4659+ goto out_rel_old;
4660+
4661+ vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4662+ /* dir_nd will have refs to dentry and mnt */
4663+ ret = do_path_lookup(AT_FDCWD, to,
4664+ LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4665+ vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4666+ if (ret < 0)
4667+ goto retry;
4668+
4669+ /* this puppy downs the dir inode mutex if successful */
4670+ new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4671+ if (!new_dentry || IS_ERR(new_dentry)) {
4672+ path_put(&dir_nd.path);
4673+ vxdprintk(VXD_CBIT(misc, 2),
4674+ "kern_path_create(new) failed with %ld",
4675+ PTR_ERR(new_dentry));
4676+ goto retry;
4677+ }
4678+ path_put(&dir_path);
4679+ vxdprintk(VXD_CBIT(misc, 2),
4680+ "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4681+ new_dentry,
4682+ new_dentry->d_name.len, new_dentry->d_name.name,
4683+ new_dentry->d_name.len);
4684+
4685+ dir = dir_nd.path.dentry;
4686+
4687+ ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4688+ vxdprintk(VXD_CBIT(misc, 2),
4689+ "vfs_create(new): %d", ret);
4690+ if (ret == -EEXIST) {
4691+ mutex_unlock(&dir->d_inode->i_mutex);
4692+ path_put(&dir_nd.path);
4693+ dput(new_dentry);
4694+ goto retry;
4695+ }
4696+ else if (ret < 0)
4697+ goto out_unlock_new;
4698+
4699+ /* drop out early, ret passes ENOENT */
4700+ ret = -ENOENT;
4701+ if ((redo = d_unhashed(old_dentry)))
4702+ goto out_unlock_new;
4703+
4704+ path_get(&old_path);
4705+ /* this one cleans up the dentry/mnt in case of failure */
4706+ old_file = dentry_open(old_dentry, old_path.mnt,
4707+ O_RDONLY, current_cred());
4708+ vxdprintk(VXD_CBIT(misc, 2),
4709+ "dentry_open(old): %p", old_file);
4710+ if (IS_ERR(old_file)) {
4711+ ret = PTR_ERR(old_file);
4712+ goto out_unlock_new;
4713+ }
4714+
4715+ dget(new_dentry);
4716+ mntget(old_path.mnt);
4717+ /* this one cleans up the dentry/mnt in case of failure */
4718+ new_file = dentry_open(new_dentry, old_path.mnt,
4719+ O_WRONLY, current_cred());
4720+ vxdprintk(VXD_CBIT(misc, 2),
4721+ "dentry_open(new): %p", new_file);
4722+ if (IS_ERR(new_file)) {
4723+ ret = PTR_ERR(new_file);
4724+ goto out_fput_old;
4725+ }
4726+
4727+ size = i_size_read(old_file->f_dentry->d_inode);
4728+ ret = do_cow_splice(old_file, new_file, size);
4729+ vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4730+ if (ret < 0) {
4731+ goto out_fput_both;
4732+ } else if (ret < size) {
4733+ ret = -ENOSPC;
4734+ goto out_fput_both;
4735+ } else {
4736+ struct inode *old_inode = old_dentry->d_inode;
4737+ struct inode *new_inode = new_dentry->d_inode;
4738+ struct iattr attr = {
4739+ .ia_uid = old_inode->i_uid,
4740+ .ia_gid = old_inode->i_gid,
4741+ .ia_valid = ATTR_UID | ATTR_GID
4742+ };
4743+
4744+ setattr_copy(new_inode, &attr);
4745+ mark_inode_dirty(new_inode);
4746+ }
4747+
4748+ mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4749+
4750+ /* drop out late */
4751+ ret = -ENOENT;
4752+ if ((redo = d_unhashed(old_dentry)))
4753+ goto out_unlock;
4754+
4755+ vxdprintk(VXD_CBIT(misc, 2),
4756+ "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4757+ new_dentry->d_name.len, new_dentry->d_name.name,
4758+ new_dentry->d_name.len,
4759+ old_dentry->d_name.len, old_dentry->d_name.name,
4760+ old_dentry->d_name.len);
4761+ ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4762+ old_dentry->d_parent->d_inode, old_dentry);
4763+ vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4764+
4765+out_unlock:
4766+ mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4767+
4768+out_fput_both:
4769+ vxdprintk(VXD_CBIT(misc, 3),
4770+ "fput(new_file=%p[#%ld])", new_file,
4771+ atomic_long_read(&new_file->f_count));
4772+ fput(new_file);
4773+
4774+out_fput_old:
4775+ vxdprintk(VXD_CBIT(misc, 3),
4776+ "fput(old_file=%p[#%ld])", old_file,
4777+ atomic_long_read(&old_file->f_count));
4778+ fput(old_file);
4779+
4780+out_unlock_new:
4781+ mutex_unlock(&dir->d_inode->i_mutex);
4782+ if (!ret)
4783+ goto out_redo;
4784+
4785+ /* error path cleanup */
4786+ vfs_unlink(dir->d_inode, new_dentry);
4787+
4788+out_redo:
4789+ if (!redo)
4790+ goto out_rel_both;
4791+ /* lookup dentry once again */
4792+ /* old_nd.path is freed as old_path in out_rel_old */
4793+ ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4794+ if (ret)
4795+ goto out_rel_both;
4796+
4797+ dput(new_dentry);
4798+ new_dentry = old_nd.path.dentry;
4799+ vxdprintk(VXD_CBIT(misc, 2),
4800+ "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4801+ new_dentry,
4802+ new_dentry->d_name.len, new_dentry->d_name.name,
4803+ new_dentry->d_name.len);
4804+ dget(new_dentry);
4805+
4806+out_rel_both:
4807+ path_put(&dir_nd.path);
4808+out_rel_old:
4809+ path_put(&old_path);
4810+out_free_path:
4811+ kfree(path);
4812+out:
4813+ if (ret) {
4814+ dput(new_dentry);
4815+ new_dentry = ERR_PTR(ret);
4816+ }
4817+ vxdprintk(VXD_CBIT(misc, 3),
4818+ "cow_break_link returning with %p [r=%d]",
4819+ new_dentry, mnt_get_count(real_mount(old_nd.path.mnt)));
4820+ return new_dentry;
4821+}
4822+
4823+#endif
4824+
4825+int vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4826+{
4827+ struct path path;
4828+ struct vfsmount *vmnt;
4829+ char *pstr, *root;
4830+ int length = 0;
4831+
4832+ pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4833+ if (!pstr)
4834+ return 0;
4835+
4836+ vmnt = &ns->root->mnt;
4837+ path.mnt = vmnt;
4838+ path.dentry = vmnt->mnt_root;
4839+ root = d_path(&path, pstr, PATH_MAX - 2);
4840+ length = sprintf(buffer + length,
4841+ "Namespace:\t%p [#%u]\n"
4842+ "RootPath:\t%s\n",
4843+ ns, atomic_read(&ns->count),
4844+ root);
4845+ kfree(pstr);
4846+ return length;
4847+}
4848+
4849 /* get the link contents into pagecache */
4850 static char *page_getlink(struct dentry * dentry, struct page **ppage)
4851 {
4852@@ -3998,3 +4388,4 @@ EXPORT_SYMBOL(vfs_symlink);
4853 EXPORT_SYMBOL(vfs_unlink);
4854 EXPORT_SYMBOL(dentry_unhash);
4855 EXPORT_SYMBOL(generic_readlink);
4856+EXPORT_SYMBOL(vx_info_mnt_namespace);
4857diff -NurpP --minimal linux-3.6.6/fs/namespace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/namespace.c
4858--- linux-3.6.6/fs/namespace.c 2012-10-04 15:27:40.000000000 +0200
4859+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/namespace.c 2012-10-04 18:47:00.000000000 +0200
4860@@ -20,6 +20,11 @@
4861 #include <linux/fs_struct.h> /* get_fs_root et.al. */
4862 #include <linux/fsnotify.h> /* fsnotify_vfsmount_delete */
4863 #include <linux/uaccess.h>
4864+#include <linux/vs_base.h>
4865+#include <linux/vs_context.h>
4866+#include <linux/vs_tag.h>
4867+#include <linux/vserver/space.h>
4868+#include <linux/vserver/global.h>
4869 #include "pnode.h"
4870 #include "internal.h"
4871
4872@@ -749,6 +754,10 @@ vfs_kern_mount(struct file_system_type *
4873 if (!type)
4874 return ERR_PTR(-ENODEV);
4875
4876+ if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4877+ !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4878+ return ERR_PTR(-EPERM);
4879+
4880 mnt = alloc_vfsmnt(name);
4881 if (!mnt)
4882 return ERR_PTR(-ENOMEM);
4883@@ -801,6 +810,7 @@ static struct mount *clone_mnt(struct mo
4884 mnt->mnt.mnt_root = dget(root);
4885 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4886 mnt->mnt_parent = mnt;
4887+ mnt->mnt_tag = old->mnt_tag;
4888 br_write_lock(&vfsmount_lock);
4889 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4890 br_write_unlock(&vfsmount_lock);
4891@@ -1266,7 +1276,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
4892 goto dput_and_out;
4893
4894 retval = -EPERM;
4895- if (!capable(CAP_SYS_ADMIN))
4896+ if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4897 goto dput_and_out;
4898
4899 retval = do_umount(mnt, flags);
4900@@ -1292,7 +1302,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
4901
4902 static int mount_is_safe(struct path *path)
4903 {
4904- if (capable(CAP_SYS_ADMIN))
4905+ if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4906 return 0;
4907 return -EPERM;
4908 #ifdef notyet
4909@@ -1610,7 +1620,7 @@ static int do_change_type(struct path *p
4910 int type;
4911 int err = 0;
4912
4913- if (!capable(CAP_SYS_ADMIN))
4914+ if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
4915 return -EPERM;
4916
4917 if (path->dentry != path->mnt->mnt_root)
4918@@ -1626,6 +1636,7 @@ static int do_change_type(struct path *p
4919 if (err)
4920 goto out_unlock;
4921 }
4922+ // mnt->mnt_flags = mnt_flags;
4923
4924 br_write_lock(&vfsmount_lock);
4925 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4926@@ -1641,12 +1652,14 @@ static int do_change_type(struct path *p
4927 * do loopback mount.
4928 */
4929 static int do_loopback(struct path *path, char *old_name,
4930- int recurse)
4931+ tag_t tag, unsigned long flags, int mnt_flags)
4932 {
4933 LIST_HEAD(umount_list);
4934 struct path old_path;
4935 struct mount *mnt = NULL, *old;
4936 int err = mount_is_safe(path);
4937+ int recurse = flags & MS_REC;
4938+
4939 if (err)
4940 return err;
4941 if (!old_name || !*old_name)
4942@@ -1715,13 +1728,13 @@ static int change_mount_flags(struct vfs
4943 * on it - tough luck.
4944 */
4945 static int do_remount(struct path *path, int flags, int mnt_flags,
4946- void *data)
4947+ void *data, xid_t xid)
4948 {
4949 int err;
4950 struct super_block *sb = path->mnt->mnt_sb;
4951 struct mount *mnt = real_mount(path->mnt);
4952
4953- if (!capable(CAP_SYS_ADMIN))
4954+ if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
4955 return -EPERM;
4956
4957 if (!check_mnt(mnt))
4958@@ -1770,7 +1783,7 @@ static int do_move_mount(struct path *pa
4959 struct mount *p;
4960 struct mount *old;
4961 int err = 0;
4962- if (!capable(CAP_SYS_ADMIN))
4963+ if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4964 return -EPERM;
4965 if (!old_name || !*old_name)
4966 return -EINVAL;
4967@@ -1927,7 +1940,7 @@ static int do_new_mount(struct path *pat
4968 return -EINVAL;
4969
4970 /* we need capabilities... */
4971- if (!capable(CAP_SYS_ADMIN))
4972+ if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4973 return -EPERM;
4974
4975 mnt = do_kern_mount(type, flags, name, data);
4976@@ -2197,6 +2210,7 @@ long do_mount(char *dev_name, char *dir_
4977 struct path path;
4978 int retval = 0;
4979 int mnt_flags = 0;
4980+ tag_t tag = 0;
4981
4982 /* Discard magic */
4983 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4984@@ -2224,6 +2238,12 @@ long do_mount(char *dev_name, char *dir_
4985 if (!(flags & MS_NOATIME))
4986 mnt_flags |= MNT_RELATIME;
4987
4988+ if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4989+ /* FIXME: bind and re-mounts get the tag flag? */
4990+ if (flags & (MS_BIND|MS_REMOUNT))
4991+ flags |= MS_TAGID;
4992+ }
4993+
4994 /* Separate the per-mountpoint flags */
4995 if (flags & MS_NOSUID)
4996 mnt_flags |= MNT_NOSUID;
4997@@ -2240,15 +2260,17 @@ long do_mount(char *dev_name, char *dir_
4998 if (flags & MS_RDONLY)
4999 mnt_flags |= MNT_READONLY;
5000
5001+ if (!capable(CAP_SYS_ADMIN))
5002+ mnt_flags |= MNT_NODEV;
5003 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5004 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5005 MS_STRICTATIME);
5006
5007 if (flags & MS_REMOUNT)
5008 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5009- data_page);
5010+ data_page, tag);
5011 else if (flags & MS_BIND)
5012- retval = do_loopback(&path, dev_name, flags & MS_REC);
5013+ retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5014 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5015 retval = do_change_type(&path, flags);
5016 else if (flags & MS_MOVE)
5017@@ -2329,6 +2351,7 @@ static struct mnt_namespace *dup_mnt_ns(
5018 q = next_mnt(q, new);
5019 }
5020 up_write(&namespace_sem);
5021+ atomic_inc(&vs_global_mnt_ns);
5022
5023 if (rootmnt)
5024 mntput(rootmnt);
5025@@ -2524,9 +2547,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5026 error = -EINVAL;
5027 new_mnt = real_mount(new.mnt);
5028 root_mnt = real_mount(root.mnt);
5029- if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5030+ if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5031 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5032- IS_MNT_SHARED(root_mnt->mnt_parent))
5033+ IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5034+ !vx_flags(VXF_STATE_SETUP, 0))
5035 goto out4;
5036 if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5037 goto out4;
5038@@ -2647,6 +2671,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5039 br_write_unlock(&vfsmount_lock);
5040 up_write(&namespace_sem);
5041 release_mounts(&umount_list);
5042+ atomic_dec(&vs_global_mnt_ns);
5043 kfree(ns);
5044 }
5045
5046diff -NurpP --minimal linux-3.6.6/fs/nfs/client.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/client.c
5047--- linux-3.6.6/fs/nfs/client.c 2012-11-06 18:42:13.000000000 +0100
5048+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/client.c 2012-11-06 18:43:41.000000000 +0100
5049@@ -692,6 +692,9 @@ int nfs_init_server_rpcclient(struct nfs
5050 if (server->flags & NFS_MOUNT_SOFT)
5051 server->client->cl_softrtry = 1;
5052
5053+ server->client->cl_tag = 0;
5054+ if (server->flags & NFS_MOUNT_TAGGED)
5055+ server->client->cl_tag = 1;
5056 return 0;
5057 }
5058 EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5059@@ -869,6 +872,10 @@ static void nfs_server_set_fsinfo(struct
5060 server->acdirmin = server->acdirmax = 0;
5061 }
5062
5063+ /* FIXME: needs fsinfo
5064+ if (server->flags & NFS_MOUNT_TAGGED)
5065+ sb->s_flags |= MS_TAGGED; */
5066+
5067 server->maxfilesize = fsinfo->maxfilesize;
5068
5069 server->time_delta = fsinfo->time_delta;
5070diff -NurpP --minimal linux-3.6.6/fs/nfs/dir.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/dir.c
5071--- linux-3.6.6/fs/nfs/dir.c 2012-10-04 15:27:40.000000000 +0200
5072+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/dir.c 2012-10-04 18:47:00.000000000 +0200
5073@@ -36,6 +36,7 @@
5074 #include <linux/sched.h>
5075 #include <linux/kmemleak.h>
5076 #include <linux/xattr.h>
5077+#include <linux/vs_tag.h>
5078
5079 #include "delegation.h"
5080 #include "iostat.h"
5081@@ -1251,6 +1252,7 @@ struct dentry *nfs_lookup(struct inode *
5082 /* Success: notify readdir to use READDIRPLUS */
5083 nfs_advise_use_readdirplus(dir);
5084
5085+ dx_propagate_tag(nd, inode);
5086 no_entry:
5087 res = d_materialise_unique(dentry, inode);
5088 if (res != NULL) {
5089diff -NurpP --minimal linux-3.6.6/fs/nfs/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/inode.c
5090--- linux-3.6.6/fs/nfs/inode.c 2012-10-04 15:27:40.000000000 +0200
5091+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/inode.c 2012-10-04 18:47:00.000000000 +0200
5092@@ -39,6 +39,7 @@
5093 #include <linux/compat.h>
5094 #include <linux/freezer.h>
5095 #include <linux/crc32.h>
5096+#include <linux/vs_tag.h>
5097
5098 #include <asm/uaccess.h>
5099
5100@@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5101 if (inode->i_state & I_NEW) {
5102 struct nfs_inode *nfsi = NFS_I(inode);
5103 unsigned long now = jiffies;
5104+ uid_t uid;
5105+ gid_t gid;
5106
5107 /* We set i_ino for the few things that still rely on it,
5108 * such as stat(2) */
5109@@ -323,8 +326,8 @@ nfs_fhget(struct super_block *sb, struct
5110 inode->i_version = 0;
5111 inode->i_size = 0;
5112 clear_nlink(inode);
5113- inode->i_uid = -2;
5114- inode->i_gid = -2;
5115+ uid = -2;
5116+ gid = -2;
5117 inode->i_blocks = 0;
5118 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5119 nfsi->write_io = 0;
5120@@ -358,11 +361,11 @@ nfs_fhget(struct super_block *sb, struct
5121 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5122 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5123 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5124- inode->i_uid = fattr->uid;
5125+ uid = fattr->uid;
5126 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5127 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5128 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5129- inode->i_gid = fattr->gid;
5130+ gid = fattr->gid;
5131 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5132 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5133 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5134@@ -373,6 +376,11 @@ nfs_fhget(struct super_block *sb, struct
5135 */
5136 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5137 }
5138+ inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5139+ inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5140+ inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5141+ /* maybe fattr->xid someday */
5142+
5143 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5144 nfsi->attrtimeo_timestamp = now;
5145 nfsi->access_cache = RB_ROOT;
5146@@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5147 inode->i_uid = attr->ia_uid;
5148 if ((attr->ia_valid & ATTR_GID) != 0)
5149 inode->i_gid = attr->ia_gid;
5150+ if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5151+ inode->i_tag = attr->ia_tag;
5152 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5153 spin_unlock(&inode->i_lock);
5154 }
5155@@ -965,6 +975,9 @@ static int nfs_check_inode_attributes(st
5156 struct nfs_inode *nfsi = NFS_I(inode);
5157 loff_t cur_size, new_isize;
5158 unsigned long invalid = 0;
5159+ uid_t uid;
5160+ gid_t gid;
5161+ tag_t tag;
5162
5163
5164 if (nfs_have_delegated_attributes(inode))
5165@@ -990,13 +1003,18 @@ static int nfs_check_inode_attributes(st
5166 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5167 }
5168
5169+ uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5170+ gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5171+ tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5172+
5173 /* Have any file permissions changed? */
5174 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5175 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5176- if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5177+ if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5178 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5179- if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5180+ if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5181 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5182+ /* maybe check for tag too? */
5183
5184 /* Has the link count changed? */
5185 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5186@@ -1300,6 +1318,9 @@ static int nfs_update_inode(struct inode
5187 unsigned long invalid = 0;
5188 unsigned long now = jiffies;
5189 unsigned long save_cache_validity;
5190+ uid_t uid;
5191+ gid_t gid;
5192+ tag_t tag;
5193
5194 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5195 __func__, inode->i_sb->s_id, inode->i_ino,
5196@@ -1401,6 +1422,9 @@ static int nfs_update_inode(struct inode
5197 | NFS_INO_REVAL_PAGECACHE
5198 | NFS_INO_REVAL_FORCED);
5199
5200+ uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5201+ gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5202+ tag = inode->i_tag;
5203
5204 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5205 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5206@@ -1422,9 +1446,9 @@ static int nfs_update_inode(struct inode
5207 | NFS_INO_REVAL_FORCED);
5208
5209 if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5210- if (inode->i_uid != fattr->uid) {
5211+ if (uid != fattr->uid) {
5212 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5213- inode->i_uid = fattr->uid;
5214+ uid = fattr->uid;
5215 }
5216 } else if (server->caps & NFS_CAP_OWNER)
5217 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5218@@ -1433,9 +1457,9 @@ static int nfs_update_inode(struct inode
5219 | NFS_INO_REVAL_FORCED);
5220
5221 if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5222- if (inode->i_gid != fattr->gid) {
5223+ if (gid != fattr->gid) {
5224 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5225- inode->i_gid = fattr->gid;
5226+ gid = fattr->gid;
5227 }
5228 } else if (server->caps & NFS_CAP_OWNER_GROUP)
5229 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5230@@ -1443,6 +1467,10 @@ static int nfs_update_inode(struct inode
5231 | NFS_INO_INVALID_ACL
5232 | NFS_INO_REVAL_FORCED);
5233
5234+ inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5235+ inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5236+ inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5237+
5238 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5239 if (inode->i_nlink != fattr->nlink) {
5240 invalid |= NFS_INO_INVALID_ATTR;
5241diff -NurpP --minimal linux-3.6.6/fs/nfs/nfs3xdr.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/nfs3xdr.c
5242--- linux-3.6.6/fs/nfs/nfs3xdr.c 2012-10-04 15:27:40.000000000 +0200
5243+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/nfs3xdr.c 2012-10-04 18:47:00.000000000 +0200
5244@@ -20,6 +20,7 @@
5245 #include <linux/nfs3.h>
5246 #include <linux/nfs_fs.h>
5247 #include <linux/nfsacl.h>
5248+#include <linux/vs_tag.h>
5249 #include "internal.h"
5250
5251 #define NFSDBG_FACILITY NFSDBG_XDR
5252@@ -560,7 +561,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5253 * set_mtime mtime;
5254 * };
5255 */
5256-static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5257+static void encode_sattr3(struct xdr_stream *xdr,
5258+ const struct iattr *attr, int tag)
5259 {
5260 u32 nbytes;
5261 __be32 *p;
5262@@ -592,15 +594,19 @@ static void encode_sattr3(struct xdr_str
5263 } else
5264 *p++ = xdr_zero;
5265
5266- if (attr->ia_valid & ATTR_UID) {
5267+ if (attr->ia_valid & ATTR_UID ||
5268+ (tag && (attr->ia_valid & ATTR_TAG))) {
5269 *p++ = xdr_one;
5270- *p++ = cpu_to_be32(attr->ia_uid);
5271+ *p++ = cpu_to_be32(TAGINO_UID(tag,
5272+ attr->ia_uid, attr->ia_tag));
5273 } else
5274 *p++ = xdr_zero;
5275
5276- if (attr->ia_valid & ATTR_GID) {
5277+ if (attr->ia_valid & ATTR_GID ||
5278+ (tag && (attr->ia_valid & ATTR_TAG))) {
5279 *p++ = xdr_one;
5280- *p++ = cpu_to_be32(attr->ia_gid);
5281+ *p++ = cpu_to_be32(TAGINO_GID(tag,
5282+ attr->ia_gid, attr->ia_tag));
5283 } else
5284 *p++ = xdr_zero;
5285
5286@@ -879,7 +885,7 @@ static void nfs3_xdr_enc_setattr3args(st
5287 const struct nfs3_sattrargs *args)
5288 {
5289 encode_nfs_fh3(xdr, args->fh);
5290- encode_sattr3(xdr, args->sattr);
5291+ encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5292 encode_sattrguard3(xdr, args);
5293 }
5294
5295@@ -1029,13 +1035,13 @@ static void nfs3_xdr_enc_write3args(stru
5296 * };
5297 */
5298 static void encode_createhow3(struct xdr_stream *xdr,
5299- const struct nfs3_createargs *args)
5300+ const struct nfs3_createargs *args, int tag)
5301 {
5302 encode_uint32(xdr, args->createmode);
5303 switch (args->createmode) {
5304 case NFS3_CREATE_UNCHECKED:
5305 case NFS3_CREATE_GUARDED:
5306- encode_sattr3(xdr, args->sattr);
5307+ encode_sattr3(xdr, args->sattr, tag);
5308 break;
5309 case NFS3_CREATE_EXCLUSIVE:
5310 encode_createverf3(xdr, args->verifier);
5311@@ -1050,7 +1056,7 @@ static void nfs3_xdr_enc_create3args(str
5312 const struct nfs3_createargs *args)
5313 {
5314 encode_diropargs3(xdr, args->fh, args->name, args->len);
5315- encode_createhow3(xdr, args);
5316+ encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5317 }
5318
5319 /*
5320@@ -1066,7 +1072,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5321 const struct nfs3_mkdirargs *args)
5322 {
5323 encode_diropargs3(xdr, args->fh, args->name, args->len);
5324- encode_sattr3(xdr, args->sattr);
5325+ encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5326 }
5327
5328 /*
5329@@ -1083,9 +1089,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5330 * };
5331 */
5332 static void encode_symlinkdata3(struct xdr_stream *xdr,
5333- const struct nfs3_symlinkargs *args)
5334+ const struct nfs3_symlinkargs *args, int tag)
5335 {
5336- encode_sattr3(xdr, args->sattr);
5337+ encode_sattr3(xdr, args->sattr, tag);
5338 encode_nfspath3(xdr, args->pages, args->pathlen);
5339 }
5340
5341@@ -1094,7 +1100,7 @@ static void nfs3_xdr_enc_symlink3args(st
5342 const struct nfs3_symlinkargs *args)
5343 {
5344 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5345- encode_symlinkdata3(xdr, args);
5346+ encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5347 }
5348
5349 /*
5350@@ -1122,24 +1128,24 @@ static void nfs3_xdr_enc_symlink3args(st
5351 * };
5352 */
5353 static void encode_devicedata3(struct xdr_stream *xdr,
5354- const struct nfs3_mknodargs *args)
5355+ const struct nfs3_mknodargs *args, int tag)
5356 {
5357- encode_sattr3(xdr, args->sattr);
5358+ encode_sattr3(xdr, args->sattr, tag);
5359 encode_specdata3(xdr, args->rdev);
5360 }
5361
5362 static void encode_mknoddata3(struct xdr_stream *xdr,
5363- const struct nfs3_mknodargs *args)
5364+ const struct nfs3_mknodargs *args, int tag)
5365 {
5366 encode_ftype3(xdr, args->type);
5367 switch (args->type) {
5368 case NF3CHR:
5369 case NF3BLK:
5370- encode_devicedata3(xdr, args);
5371+ encode_devicedata3(xdr, args, tag);
5372 break;
5373 case NF3SOCK:
5374 case NF3FIFO:
5375- encode_sattr3(xdr, args->sattr);
5376+ encode_sattr3(xdr, args->sattr, tag);
5377 break;
5378 case NF3REG:
5379 case NF3DIR:
5380@@ -1154,7 +1160,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5381 const struct nfs3_mknodargs *args)
5382 {
5383 encode_diropargs3(xdr, args->fh, args->name, args->len);
5384- encode_mknoddata3(xdr, args);
5385+ encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5386 }
5387
5388 /*
5389diff -NurpP --minimal linux-3.6.6/fs/nfs/super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/super.c
5390--- linux-3.6.6/fs/nfs/super.c 2012-10-04 15:27:40.000000000 +0200
5391+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfs/super.c 2012-10-04 18:47:00.000000000 +0200
5392@@ -54,6 +54,7 @@
5393 #include <linux/parser.h>
5394 #include <linux/nsproxy.h>
5395 #include <linux/rcupdate.h>
5396+#include <linux/vs_tag.h>
5397
5398 #include <asm/uaccess.h>
5399
5400@@ -88,6 +89,7 @@ enum {
5401 Opt_sharecache, Opt_nosharecache,
5402 Opt_resvport, Opt_noresvport,
5403 Opt_fscache, Opt_nofscache,
5404+ Opt_tag, Opt_notag,
5405
5406 /* Mount options that take integer arguments */
5407 Opt_port,
5408@@ -100,6 +102,7 @@ enum {
5409 Opt_mountport,
5410 Opt_mountvers,
5411 Opt_minorversion,
5412+ Opt_tagid,
5413
5414 /* Mount options that take string arguments */
5415 Opt_nfsvers,
5416@@ -182,6 +185,10 @@ static const match_table_t nfs_mount_opt
5417 /* The following needs to be listed after all other options */
5418 { Opt_nfsvers, "v%s" },
5419
5420+ { Opt_tag, "tag" },
5421+ { Opt_notag, "notag" },
5422+ { Opt_tagid, "tagid=%u" },
5423+
5424 { Opt_err, NULL }
5425 };
5426
5427@@ -626,6 +633,7 @@ static void nfs_show_mount_options(struc
5428 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5429 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5430 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5431+ { NFS_MOUNT_TAGGED, ",tag", "" },
5432 { 0, NULL, NULL }
5433 };
5434 const struct proc_nfs_info *nfs_infop;
5435@@ -1243,6 +1251,14 @@ static int nfs_parse_mount_options(char
5436 kfree(mnt->fscache_uniq);
5437 mnt->fscache_uniq = NULL;
5438 break;
5439+#ifndef CONFIG_TAGGING_NONE
5440+ case Opt_tag:
5441+ mnt->flags |= NFS_MOUNT_TAGGED;
5442+ break;
5443+ case Opt_notag:
5444+ mnt->flags &= ~NFS_MOUNT_TAGGED;
5445+ break;
5446+#endif
5447
5448 /*
5449 * options that take numeric values
5450@@ -1329,6 +1345,12 @@ static int nfs_parse_mount_options(char
5451 goto out_invalid_value;
5452 mnt->minorversion = option;
5453 break;
5454+#ifdef CONFIG_PROPAGATE
5455+ case Opt_tagid:
5456+ /* use args[0] */
5457+ nfs_data.flags |= NFS_MOUNT_TAGGED;
5458+ break;
5459+#endif
5460
5461 /*
5462 * options that take text values
5463diff -NurpP --minimal linux-3.6.6/fs/nfsd/auth.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfsd/auth.c
5464--- linux-3.6.6/fs/nfsd/auth.c 2012-07-22 23:39:41.000000000 +0200
5465+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfsd/auth.c 2012-10-04 18:47:00.000000000 +0200
5466@@ -2,6 +2,7 @@
5467
5468 #include <linux/sched.h>
5469 #include <linux/user_namespace.h>
5470+#include <linux/vs_tag.h>
5471 #include "nfsd.h"
5472 #include "auth.h"
5473
5474@@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5475
5476 new->fsuid = rqstp->rq_cred.cr_uid;
5477 new->fsgid = rqstp->rq_cred.cr_gid;
5478+ /* FIXME: this desperately needs a tag :)
5479+ new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5480+ */
5481
5482 rqgi = rqstp->rq_cred.cr_group_info;
5483
5484diff -NurpP --minimal linux-3.6.6/fs/nfsd/nfs3xdr.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfsd/nfs3xdr.c
5485--- linux-3.6.6/fs/nfsd/nfs3xdr.c 2012-05-21 18:07:26.000000000 +0200
5486+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfsd/nfs3xdr.c 2012-10-04 18:47:00.000000000 +0200
5487@@ -7,6 +7,7 @@
5488 */
5489
5490 #include <linux/namei.h>
5491+#include <linux/vs_tag.h>
5492 #include "xdr3.h"
5493 #include "auth.h"
5494
5495@@ -95,6 +96,8 @@ static __be32 *
5496 decode_sattr3(__be32 *p, struct iattr *iap)
5497 {
5498 u32 tmp;
5499+ uid_t uid = 0;
5500+ gid_t gid = 0;
5501
5502 iap->ia_valid = 0;
5503
5504@@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5505 }
5506 if (*p++) {
5507 iap->ia_valid |= ATTR_UID;
5508- iap->ia_uid = ntohl(*p++);
5509+ uid = ntohl(*p++);
5510 }
5511 if (*p++) {
5512 iap->ia_valid |= ATTR_GID;
5513- iap->ia_gid = ntohl(*p++);
5514+ gid = ntohl(*p++);
5515 }
5516+ iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5517+ iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5518+ iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5519 if (*p++) {
5520 u64 newsize;
5521
5522@@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5523 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5524 *p++ = htonl((u32) stat->mode);
5525 *p++ = htonl((u32) stat->nlink);
5526- *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5527- *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5528+ *p++ = htonl((u32) nfsd_ruid(rqstp,
5529+ TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5530+ stat->uid, stat->tag)));
5531+ *p++ = htonl((u32) nfsd_rgid(rqstp,
5532+ TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5533+ stat->gid, stat->tag)));
5534 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5535 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5536 } else {
5537diff -NurpP --minimal linux-3.6.6/fs/nfsd/nfs4xdr.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfsd/nfs4xdr.c
5538--- linux-3.6.6/fs/nfsd/nfs4xdr.c 2012-10-04 15:27:40.000000000 +0200
5539+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfsd/nfs4xdr.c 2012-10-04 18:47:00.000000000 +0200
5540@@ -46,6 +46,7 @@
5541 #include <linux/utsname.h>
5542 #include <linux/pagemap.h>
5543 #include <linux/sunrpc/svcauth_gss.h>
5544+#include <linux/vs_tag.h>
5545
5546 #include "idmap.h"
5547 #include "acl.h"
5548@@ -2351,14 +2352,18 @@ out_acl:
5549 WRITE32(stat.nlink);
5550 }
5551 if (bmval1 & FATTR4_WORD1_OWNER) {
5552- status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5553+ status = nfsd4_encode_user(rqstp,
5554+ TAGINO_UID(DX_TAG(dentry->d_inode),
5555+ stat.uid, stat.tag), &p, &buflen);
5556 if (status == nfserr_resource)
5557 goto out_resource;
5558 if (status)
5559 goto out;
5560 }
5561 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5562- status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5563+ status = nfsd4_encode_group(rqstp,
5564+ TAGINO_GID(DX_TAG(dentry->d_inode),
5565+ stat.gid, stat.tag), &p, &buflen);
5566 if (status == nfserr_resource)
5567 goto out_resource;
5568 if (status)
5569diff -NurpP --minimal linux-3.6.6/fs/nfsd/nfsxdr.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfsd/nfsxdr.c
5570--- linux-3.6.6/fs/nfsd/nfsxdr.c 2011-05-22 16:17:53.000000000 +0200
5571+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/nfsd/nfsxdr.c 2012-10-04 18:47:00.000000000 +0200
5572@@ -6,6 +6,7 @@
5573
5574 #include "xdr.h"
5575 #include "auth.h"
5576+#include <linux/vs_tag.h>
5577
5578 #define NFSDDBG_FACILITY NFSDDBG_XDR
5579
5580@@ -88,6 +89,8 @@ static __be32 *
5581 decode_sattr(__be32 *p, struct iattr *iap)
5582 {
5583 u32 tmp, tmp1;
5584+ uid_t uid = 0;
5585+ gid_t gid = 0;
5586
5587 iap->ia_valid = 0;
5588
5589@@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5590 }
5591 if ((tmp = ntohl(*p++)) != (u32)-1) {
5592 iap->ia_valid |= ATTR_UID;
5593- iap->ia_uid = tmp;
5594+ uid = tmp;
5595 }
5596 if ((tmp = ntohl(*p++)) != (u32)-1) {
5597 iap->ia_valid |= ATTR_GID;
5598- iap->ia_gid = tmp;
5599+ gid = tmp;
5600 }
5601+ iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5602+ iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5603+ iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5604 if ((tmp = ntohl(*p++)) != (u32)-1) {
5605 iap->ia_valid |= ATTR_SIZE;
5606 iap->ia_size = tmp;
5607@@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5608 *p++ = htonl(nfs_ftypes[type >> 12]);
5609 *p++ = htonl((u32) stat->mode);
5610 *p++ = htonl((u32) stat->nlink);
5611- *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5612- *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5613+ *p++ = htonl((u32) nfsd_ruid(rqstp,
5614+ TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5615+ *p++ = htonl((u32) nfsd_rgid(rqstp,
5616+ TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5617
5618 if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5619 *p++ = htonl(NFS_MAXPATHLEN);
5620diff -NurpP --minimal linux-3.6.6/fs/ocfs2/dlmglue.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/dlmglue.c
5621--- linux-3.6.6/fs/ocfs2/dlmglue.c 2012-07-22 23:39:41.000000000 +0200
5622+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/dlmglue.c 2012-10-04 18:47:00.000000000 +0200
5623@@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5624 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5625 lvb->lvb_iuid = cpu_to_be32(inode->i_uid);
5626 lvb->lvb_igid = cpu_to_be32(inode->i_gid);
5627+ lvb->lvb_itag = cpu_to_be16(inode->i_tag);
5628 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
5629 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
5630 lvb->lvb_iatime_packed =
5631@@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5632
5633 inode->i_uid = be32_to_cpu(lvb->lvb_iuid);
5634 inode->i_gid = be32_to_cpu(lvb->lvb_igid);
5635+ inode->i_tag = be16_to_cpu(lvb->lvb_itag);
5636 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
5637 set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5638 ocfs2_unpack_timespec(&inode->i_atime,
5639diff -NurpP --minimal linux-3.6.6/fs/ocfs2/dlmglue.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/dlmglue.h
5640--- linux-3.6.6/fs/ocfs2/dlmglue.h 2010-10-21 13:07:50.000000000 +0200
5641+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/dlmglue.h 2012-10-04 18:47:00.000000000 +0200
5642@@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5643 __be16 lvb_inlink;
5644 __be32 lvb_iattr;
5645 __be32 lvb_igeneration;
5646- __be32 lvb_reserved2;
5647+ __be16 lvb_itag;
5648+ __be16 lvb_reserved2;
5649 };
5650
5651 #define OCFS2_QINFO_LVB_VERSION 1
5652diff -NurpP --minimal linux-3.6.6/fs/ocfs2/file.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/file.c
5653--- linux-3.6.6/fs/ocfs2/file.c 2012-10-04 15:27:41.000000000 +0200
5654+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/file.c 2012-10-04 18:47:00.000000000 +0200
5655@@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5656 attr->ia_valid &= ~ATTR_SIZE;
5657
5658 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5659- | ATTR_GID | ATTR_UID | ATTR_MODE)
5660+ | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5661 if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5662 return 0;
5663
5664diff -NurpP --minimal linux-3.6.6/fs/ocfs2/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/inode.c
5665--- linux-3.6.6/fs/ocfs2/inode.c 2012-07-22 23:39:41.000000000 +0200
5666+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/inode.c 2012-10-04 18:47:00.000000000 +0200
5667@@ -28,6 +28,7 @@
5668 #include <linux/highmem.h>
5669 #include <linux/pagemap.h>
5670 #include <linux/quotaops.h>
5671+#include <linux/vs_tag.h>
5672
5673 #include <asm/byteorder.h>
5674
5675@@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5676 {
5677 unsigned int flags = OCFS2_I(inode)->ip_attr;
5678
5679- inode->i_flags &= ~(S_IMMUTABLE |
5680+ inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5681 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5682
5683 if (flags & OCFS2_IMMUTABLE_FL)
5684 inode->i_flags |= S_IMMUTABLE;
5685+ if (flags & OCFS2_IXUNLINK_FL)
5686+ inode->i_flags |= S_IXUNLINK;
5687
5688 if (flags & OCFS2_SYNC_FL)
5689 inode->i_flags |= S_SYNC;
5690@@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5691 inode->i_flags |= S_NOATIME;
5692 if (flags & OCFS2_DIRSYNC_FL)
5693 inode->i_flags |= S_DIRSYNC;
5694+
5695+ inode->i_vflags &= ~(V_BARRIER | V_COW);
5696+
5697+ if (flags & OCFS2_BARRIER_FL)
5698+ inode->i_vflags |= V_BARRIER;
5699+ if (flags & OCFS2_COW_FL)
5700+ inode->i_vflags |= V_COW;
5701 }
5702
5703 /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5704 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5705 {
5706 unsigned int flags = oi->vfs_inode.i_flags;
5707+ unsigned int vflags = oi->vfs_inode.i_vflags;
5708+
5709+ oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5710+ OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5711+ OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5712+ OCFS2_BARRIER_FL | OCFS2_COW_FL);
5713+
5714+ if (flags & S_IMMUTABLE)
5715+ oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5716+ if (flags & S_IXUNLINK)
5717+ oi->ip_attr |= OCFS2_IXUNLINK_FL;
5718
5719- oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5720- OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5721 if (flags & S_SYNC)
5722 oi->ip_attr |= OCFS2_SYNC_FL;
5723 if (flags & S_APPEND)
5724 oi->ip_attr |= OCFS2_APPEND_FL;
5725- if (flags & S_IMMUTABLE)
5726- oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5727 if (flags & S_NOATIME)
5728 oi->ip_attr |= OCFS2_NOATIME_FL;
5729 if (flags & S_DIRSYNC)
5730 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5731+
5732+ if (vflags & V_BARRIER)
5733+ oi->ip_attr |= OCFS2_BARRIER_FL;
5734+ if (vflags & V_COW)
5735+ oi->ip_attr |= OCFS2_COW_FL;
5736 }
5737
5738 struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5739@@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5740 struct super_block *sb;
5741 struct ocfs2_super *osb;
5742 int use_plocks = 1;
5743+ uid_t uid;
5744+ gid_t gid;
5745
5746 sb = inode->i_sb;
5747 osb = OCFS2_SB(sb);
5748@@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5749 inode->i_generation = le32_to_cpu(fe->i_generation);
5750 inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5751 inode->i_mode = le16_to_cpu(fe->i_mode);
5752- inode->i_uid = le32_to_cpu(fe->i_uid);
5753- inode->i_gid = le32_to_cpu(fe->i_gid);
5754+ uid = le32_to_cpu(fe->i_uid);
5755+ gid = le32_to_cpu(fe->i_gid);
5756+ inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5757+ inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5758+ inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5759+ /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5760
5761 /* Fast symlinks will have i_size but no allocated clusters. */
5762 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5763diff -NurpP --minimal linux-3.6.6/fs/ocfs2/inode.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/inode.h
5764--- linux-3.6.6/fs/ocfs2/inode.h 2012-01-09 16:14:55.000000000 +0100
5765+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/inode.h 2012-10-04 18:47:00.000000000 +0200
5766@@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5767
5768 void ocfs2_set_inode_flags(struct inode *inode);
5769 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5770+int ocfs2_sync_flags(struct inode *inode, int, int);
5771
5772 static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5773 {
5774diff -NurpP --minimal linux-3.6.6/fs/ocfs2/ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/ioctl.c
5775--- linux-3.6.6/fs/ocfs2/ioctl.c 2012-10-04 15:27:41.000000000 +0200
5776+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/ioctl.c 2012-10-04 18:47:00.000000000 +0200
5777@@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5778 return status;
5779 }
5780
5781-static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5782+int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5783+{
5784+ struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5785+ struct buffer_head *bh = NULL;
5786+ handle_t *handle = NULL;
5787+ int status;
5788+
5789+ status = ocfs2_inode_lock(inode, &bh, 1);
5790+ if (status < 0) {
5791+ mlog_errno(status);
5792+ return status;
5793+ }
5794+ handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5795+ if (IS_ERR(handle)) {
5796+ status = PTR_ERR(handle);
5797+ mlog_errno(status);
5798+ goto bail_unlock;
5799+ }
5800+
5801+ inode->i_flags = flags;
5802+ inode->i_vflags = vflags;
5803+ ocfs2_get_inode_flags(OCFS2_I(inode));
5804+
5805+ status = ocfs2_mark_inode_dirty(handle, inode, bh);
5806+ if (status < 0)
5807+ mlog_errno(status);
5808+
5809+ ocfs2_commit_trans(osb, handle);
5810+bail_unlock:
5811+ ocfs2_inode_unlock(inode, 1);
5812+ brelse(bh);
5813+ return status;
5814+}
5815+
5816+int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5817 unsigned mask)
5818 {
5819 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5820@@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5821 if (!S_ISDIR(inode->i_mode))
5822 flags &= ~OCFS2_DIRSYNC_FL;
5823
5824+ if (IS_BARRIER(inode)) {
5825+ vxwprintk_task(1, "messing with the barrier.");
5826+ goto bail_unlock;
5827+ }
5828+
5829 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5830 if (IS_ERR(handle)) {
5831 status = PTR_ERR(handle);
5832@@ -879,6 +918,7 @@ bail:
5833 return status;
5834 }
5835
5836+
5837 long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5838 {
5839 struct inode *inode = filp->f_path.dentry->d_inode;
5840diff -NurpP --minimal linux-3.6.6/fs/ocfs2/namei.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/namei.c
5841--- linux-3.6.6/fs/ocfs2/namei.c 2012-10-04 15:27:41.000000000 +0200
5842+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/namei.c 2012-10-04 18:47:00.000000000 +0200
5843@@ -41,6 +41,7 @@
5844 #include <linux/slab.h>
5845 #include <linux/highmem.h>
5846 #include <linux/quotaops.h>
5847+#include <linux/vs_tag.h>
5848
5849 #include <cluster/masklog.h>
5850
5851@@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5852 struct ocfs2_dinode *fe = NULL;
5853 struct ocfs2_extent_list *fel;
5854 u16 feat;
5855+ tag_t tag;
5856
5857 *new_fe_bh = NULL;
5858
5859@@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5860 fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5861 fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5862 fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5863- fe->i_uid = cpu_to_le32(inode->i_uid);
5864- fe->i_gid = cpu_to_le32(inode->i_gid);
5865+
5866+ tag = dx_current_fstag(osb->sb);
5867+ fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5868+ fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
5869+ inode->i_tag = tag;
5870 fe->i_mode = cpu_to_le16(inode->i_mode);
5871 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5872 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5873diff -NurpP --minimal linux-3.6.6/fs/ocfs2/ocfs2.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/ocfs2.h
5874--- linux-3.6.6/fs/ocfs2/ocfs2.h 2012-01-09 16:14:55.000000000 +0100
5875+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/ocfs2.h 2012-10-04 18:47:00.000000000 +0200
5876@@ -272,6 +272,7 @@ enum ocfs2_mount_options
5877 writes */
5878 OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5879 OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5880+ OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5881 };
5882
5883 #define OCFS2_OSB_SOFT_RO 0x0001
5884diff -NurpP --minimal linux-3.6.6/fs/ocfs2/ocfs2_fs.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/ocfs2_fs.h
5885--- linux-3.6.6/fs/ocfs2/ocfs2_fs.h 2011-05-22 16:17:53.000000000 +0200
5886+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/ocfs2_fs.h 2012-10-04 18:47:00.000000000 +0200
5887@@ -266,6 +266,11 @@
5888 #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
5889 #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
5890
5891+#define OCFS2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
5892+
5893+#define OCFS2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
5894+#define OCFS2_COW_FL FS_COW_FL /* Copy on Write marker */
5895+
5896 #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
5897 #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
5898
5899diff -NurpP --minimal linux-3.6.6/fs/ocfs2/super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/super.c
5900--- linux-3.6.6/fs/ocfs2/super.c 2012-05-21 18:07:26.000000000 +0200
5901+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/ocfs2/super.c 2012-10-04 18:47:00.000000000 +0200
5902@@ -185,6 +185,7 @@ enum {
5903 Opt_coherency_full,
5904 Opt_resv_level,
5905 Opt_dir_resv_level,
5906+ Opt_tag, Opt_notag, Opt_tagid,
5907 Opt_err,
5908 };
5909
5910@@ -216,6 +217,9 @@ static const match_table_t tokens = {
5911 {Opt_coherency_full, "coherency=full"},
5912 {Opt_resv_level, "resv_level=%u"},
5913 {Opt_dir_resv_level, "dir_resv_level=%u"},
5914+ {Opt_tag, "tag"},
5915+ {Opt_notag, "notag"},
5916+ {Opt_tagid, "tagid=%u"},
5917 {Opt_err, NULL}
5918 };
5919
5920@@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5921 goto out;
5922 }
5923
5924+ if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5925+ (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5926+ ret = -EINVAL;
5927+ mlog(ML_ERROR, "Cannot change tagging on remount\n");
5928+ goto out;
5929+ }
5930+
5931 /* We're going to/from readonly mode. */
5932 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5933 /* Disable quota accounting before remounting RO */
5934@@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5935
5936 ocfs2_complete_mount_recovery(osb);
5937
5938+ if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5939+ sb->s_flags |= MS_TAGGED;
5940+
5941 if (ocfs2_mount_local(osb))
5942 snprintf(nodestr, sizeof(nodestr), "local");
5943 else
5944@@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5945 option < OCFS2_MAX_RESV_LEVEL)
5946 mopt->dir_resv_level = option;
5947 break;
5948+#ifndef CONFIG_TAGGING_NONE
5949+ case Opt_tag:
5950+ mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5951+ break;
5952+ case Opt_notag:
5953+ mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5954+ break;
5955+#endif
5956+#ifdef CONFIG_PROPAGATE
5957+ case Opt_tagid:
5958+ /* use args[0] */
5959+ mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5960+ break;
5961+#endif
5962 default:
5963 mlog(ML_ERROR,
5964 "Unrecognized mount option \"%s\" "
5965diff -NurpP --minimal linux-3.6.6/fs/open.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/open.c
5966--- linux-3.6.6/fs/open.c 2012-10-04 15:27:41.000000000 +0200
5967+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/open.c 2012-10-04 18:47:00.000000000 +0200
5968@@ -30,6 +30,11 @@
5969 #include <linux/fs_struct.h>
5970 #include <linux/ima.h>
5971 #include <linux/dnotify.h>
5972+#include <linux/vs_base.h>
5973+#include <linux/vs_limit.h>
5974+#include <linux/vs_tag.h>
5975+#include <linux/vs_cowbl.h>
5976+#include <linux/vserver/dlimit.h>
5977
5978 #include "internal.h"
5979
5980@@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
5981 error = user_path(pathname, &path);
5982 if (error)
5983 goto out;
5984+
5985+#ifdef CONFIG_VSERVER_COWBL
5986+ error = cow_check_and_break(&path);
5987+ if (error)
5988+ goto dput_and_out;
5989+#endif
5990 inode = path.dentry->d_inode;
5991
5992 /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5993@@ -495,6 +506,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5994
5995 error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
5996 if (!error) {
5997+#ifdef CONFIG_VSERVER_COWBL
5998+ error = cow_check_and_break(&path);
5999+ if (!error)
6000+#endif
6001 error = chmod_common(&path, mode);
6002 path_put(&path);
6003 }
6004@@ -522,13 +537,13 @@ static int chown_common(struct path *pat
6005 if (!uid_valid(uid))
6006 return -EINVAL;
6007 newattrs.ia_valid |= ATTR_UID;
6008- newattrs.ia_uid = uid;
6009+ newattrs.ia_uid = dx_map_uid(user);
6010 }
6011 if (group != (gid_t) -1) {
6012 if (!gid_valid(gid))
6013 return -EINVAL;
6014 newattrs.ia_valid |= ATTR_GID;
6015- newattrs.ia_gid = gid;
6016+ newattrs.ia_gid = dx_map_gid(group);
6017 }
6018 if (!S_ISDIR(inode->i_mode))
6019 newattrs.ia_valid |=
6020@@ -561,6 +576,18 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6021 error = mnt_want_write(path.mnt);
6022 if (error)
6023 goto out_release;
6024+#ifdef CONFIG_VSERVER_COWBL
6025+ error = cow_check_and_break(&path);
6026+ if (!error)
6027+#endif
6028+#ifdef CONFIG_VSERVER_COWBL
6029+ error = cow_check_and_break(&path);
6030+ if (!error)
6031+#endif
6032+#ifdef CONFIG_VSERVER_COWBL
6033+ error = cow_check_and_break(&path);
6034+ if (!error)
6035+#endif
6036 error = chown_common(&path, user, group);
6037 mnt_drop_write(path.mnt);
6038 out_release:
6039@@ -809,6 +836,7 @@ static void __put_unused_fd(struct files
6040 __clear_open_fd(fd, fdt);
6041 if (fd < files->next_fd)
6042 files->next_fd = fd;
6043+ vx_openfd_dec(fd);
6044 }
6045
6046 void put_unused_fd(unsigned int fd)
6047diff -NurpP --minimal linux-3.6.6/fs/proc/array.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/array.c
6048--- linux-3.6.6/fs/proc/array.c 2012-07-22 23:39:42.000000000 +0200
6049+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/array.c 2012-10-04 18:47:00.000000000 +0200
6050@@ -82,6 +82,8 @@
6051 #include <linux/ptrace.h>
6052 #include <linux/tracehook.h>
6053 #include <linux/user_namespace.h>
6054+#include <linux/vs_context.h>
6055+#include <linux/vs_network.h>
6056
6057 #include <asm/pgtable.h>
6058 #include <asm/processor.h>
6059@@ -172,6 +174,9 @@ static inline void task_state(struct seq
6060 rcu_read_lock();
6061 ppid = pid_alive(p) ?
6062 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6063+ if (unlikely(vx_current_initpid(p->pid)))
6064+ ppid = 0;
6065+
6066 tpid = 0;
6067 if (pid_alive(p)) {
6068 struct task_struct *tracer = ptrace_parent(p);
6069@@ -296,7 +301,7 @@ static inline void task_sig(struct seq_f
6070 }
6071
6072 static void render_cap_t(struct seq_file *m, const char *header,
6073- kernel_cap_t *a)
6074+ struct vx_info *vxi, kernel_cap_t *a)
6075 {
6076 unsigned __capi;
6077
6078@@ -321,10 +326,11 @@ static inline void task_cap(struct seq_f
6079 cap_bset = cred->cap_bset;
6080 rcu_read_unlock();
6081
6082- render_cap_t(m, "CapInh:\t", &cap_inheritable);
6083- render_cap_t(m, "CapPrm:\t", &cap_permitted);
6084- render_cap_t(m, "CapEff:\t", &cap_effective);
6085- render_cap_t(m, "CapBnd:\t", &cap_bset);
6086+ /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6087+ render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6088+ render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6089+ render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6090+ render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6091 }
6092
6093 static inline void task_context_switch_counts(struct seq_file *m,
6094@@ -346,6 +352,42 @@ static void task_cpus_allowed(struct seq
6095 seq_putc(m, '\n');
6096 }
6097
6098+int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6099+ struct pid *pid, struct task_struct *task)
6100+{
6101+ seq_printf(m, "Proxy:\t%p(%c)\n"
6102+ "Count:\t%u\n"
6103+ "uts:\t%p(%c)\n"
6104+ "ipc:\t%p(%c)\n"
6105+ "mnt:\t%p(%c)\n"
6106+ "pid:\t%p(%c)\n"
6107+ "net:\t%p(%c)\n",
6108+ task->nsproxy,
6109+ (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6110+ atomic_read(&task->nsproxy->count),
6111+ task->nsproxy->uts_ns,
6112+ (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6113+ task->nsproxy->ipc_ns,
6114+ (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6115+ task->nsproxy->mnt_ns,
6116+ (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6117+ task->nsproxy->pid_ns,
6118+ (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6119+ task->nsproxy->net_ns,
6120+ (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6121+ return 0;
6122+}
6123+
6124+void task_vs_id(struct seq_file *m, struct task_struct *task)
6125+{
6126+ if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6127+ return;
6128+
6129+ seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6130+ seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6131+}
6132+
6133+
6134 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6135 struct pid *pid, struct task_struct *task)
6136 {
6137@@ -362,6 +404,7 @@ int proc_pid_status(struct seq_file *m,
6138 task_cap(m, task);
6139 task_cpus_allowed(m, task);
6140 cpuset_task_status_allowed(m, task);
6141+ task_vs_id(m, task);
6142 task_context_switch_counts(m, task);
6143 return 0;
6144 }
6145@@ -471,6 +514,17 @@ static int do_task_stat(struct seq_file
6146 /* convert nsec -> ticks */
6147 start_time = nsec_to_clock_t(start_time);
6148
6149+ /* fixup start time for virt uptime */
6150+ if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6151+ unsigned long long bias =
6152+ current->vx_info->cvirt.bias_clock;
6153+
6154+ if (start_time > bias)
6155+ start_time -= bias;
6156+ else
6157+ start_time = 0;
6158+ }
6159+
6160 seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6161 seq_put_decimal_ll(m, ' ', ppid);
6162 seq_put_decimal_ll(m, ' ', pgid);
6163diff -NurpP --minimal linux-3.6.6/fs/proc/base.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/base.c
6164--- linux-3.6.6/fs/proc/base.c 2012-10-04 15:27:41.000000000 +0200
6165+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/base.c 2012-10-04 18:47:00.000000000 +0200
6166@@ -85,6 +85,8 @@
6167 #include <linux/fs_struct.h>
6168 #include <linux/slab.h>
6169 #include <linux/flex_array.h>
6170+#include <linux/vs_context.h>
6171+#include <linux/vs_network.h>
6172 #ifdef CONFIG_HARDWALL
6173 #include <asm/hardwall.h>
6174 #endif
6175@@ -941,11 +943,16 @@ static ssize_t oom_adjust_write(struct f
6176 goto err_task_lock;
6177 }
6178
6179- if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6180+ if (oom_adjust < task->signal->oom_adj &&
6181+ !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6182 err = -EACCES;
6183 goto err_sighand;
6184 }
6185
6186+ /* prevent guest processes from circumventing the oom killer */
6187+ if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6188+ oom_adjust = OOM_ADJUST_MIN;
6189+
6190 /*
6191 * Warn that /proc/pid/oom_adj is deprecated, see
6192 * Documentation/feature-removal-schedule.txt.
6193@@ -1548,6 +1555,8 @@ struct inode *proc_pid_make_inode(struct
6194 inode->i_gid = cred->egid;
6195 rcu_read_unlock();
6196 }
6197+ /* procfs is xid tagged */
6198+ inode->i_tag = (tag_t)vx_task_xid(task);
6199 security_task_to_inode(task, inode);
6200
6201 out:
6202@@ -1593,6 +1602,8 @@ int pid_getattr(struct vfsmount *mnt, st
6203
6204 /* dentry stuff */
6205
6206+static unsigned name_to_int(struct dentry *dentry);
6207+
6208 /*
6209 * Exceptional case: normally we are not allowed to unhash a busy
6210 * directory. In this case, however, we can do it - no aliasing problems
6211@@ -1621,6 +1632,12 @@ int pid_revalidate(struct dentry *dentry
6212 task = get_proc_task(inode);
6213
6214 if (task) {
6215+ unsigned pid = name_to_int(dentry);
6216+
6217+ if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6218+ put_task_struct(task);
6219+ goto drop;
6220+ }
6221 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6222 task_dumpable(task)) {
6223 rcu_read_lock();
6224@@ -1637,6 +1654,7 @@ int pid_revalidate(struct dentry *dentry
6225 put_task_struct(task);
6226 return 1;
6227 }
6228+drop:
6229 d_drop(dentry);
6230 return 0;
6231 }
6232@@ -2457,6 +2475,13 @@ static struct dentry *proc_pident_lookup
6233 if (!task)
6234 goto out_no_task;
6235
6236+ /* TODO: maybe we can come up with a generic approach? */
6237+ if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6238+ (dentry->d_name.len == 5) &&
6239+ (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6240+ !memcmp(dentry->d_name.name, "ninfo", 5)))
6241+ goto out;
6242+
6243 /*
6244 * Yes, it does not scale. And it should not. Don't add
6245 * new entries into /proc/<tgid>/ without very good reasons.
6246@@ -2842,7 +2867,7 @@ out_iput:
6247 static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6248 {
6249 struct dentry *error;
6250- struct task_struct *task = get_proc_task(dir);
6251+ struct task_struct *task = get_proc_task_real(dir);
6252 const struct pid_entry *p, *last;
6253
6254 error = ERR_PTR(-ENOENT);
6255@@ -3017,6 +3042,9 @@ static int proc_pid_personality(struct s
6256 static const struct file_operations proc_task_operations;
6257 static const struct inode_operations proc_task_inode_operations;
6258
6259+extern int proc_pid_vx_info(struct task_struct *, char *);
6260+extern int proc_pid_nx_info(struct task_struct *, char *);
6261+
6262 static const struct pid_entry tgid_base_stuff[] = {
6263 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6264 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6265@@ -3083,6 +3111,8 @@ static const struct pid_entry tgid_base_
6266 #ifdef CONFIG_CGROUPS
6267 REG("cgroup", S_IRUGO, proc_cgroup_operations),
6268 #endif
6269+ INF("vinfo", S_IRUGO, proc_pid_vx_info),
6270+ INF("ninfo", S_IRUGO, proc_pid_nx_info),
6271 INF("oom_score", S_IRUGO, proc_oom_score),
6272 REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6273 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6274@@ -3106,6 +3136,7 @@ static const struct pid_entry tgid_base_
6275 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
6276 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
6277 #endif
6278+ ONE("nsproxy", S_IRUGO, proc_pid_nsproxy),
6279 };
6280
6281 static int proc_tgid_base_readdir(struct file * filp,
6282@@ -3300,7 +3331,7 @@ retry:
6283 iter.task = NULL;
6284 pid = find_ge_pid(iter.tgid, ns);
6285 if (pid) {
6286- iter.tgid = pid_nr_ns(pid, ns);
6287+ iter.tgid = pid_unmapped_nr_ns(pid, ns);
6288 iter.task = pid_task(pid, PIDTYPE_PID);
6289 /* What we to know is if the pid we have find is the
6290 * pid of a thread_group_leader. Testing for task
6291@@ -3330,7 +3361,7 @@ static int proc_pid_fill_cache(struct fi
6292 struct tgid_iter iter)
6293 {
6294 char name[PROC_NUMBUF];
6295- int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6296+ int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6297 return proc_fill_cache(filp, dirent, filldir, name, len,
6298 proc_pid_instantiate, iter.task, NULL);
6299 }
6300@@ -3354,7 +3385,7 @@ int proc_pid_readdir(struct file * filp,
6301 goto out_no_task;
6302 nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6303
6304- reaper = get_proc_task(filp->f_path.dentry->d_inode);
6305+ reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6306 if (!reaper)
6307 goto out_no_task;
6308
6309@@ -3376,6 +3407,8 @@ int proc_pid_readdir(struct file * filp,
6310 __filldir = fake_filldir;
6311
6312 filp->f_pos = iter.tgid + TGID_OFFSET;
6313+ if (!vx_proc_task_visible(iter.task))
6314+ continue;
6315 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6316 put_task_struct(iter.task);
6317 goto out;
6318@@ -3537,6 +3570,8 @@ static struct dentry *proc_task_lookup(s
6319 tid = name_to_int(dentry);
6320 if (tid == ~0U)
6321 goto out;
6322+ if (vx_current_initpid(tid))
6323+ goto out;
6324
6325 ns = dentry->d_sb->s_fs_info;
6326 rcu_read_lock();
6327diff -NurpP --minimal linux-3.6.6/fs/proc/generic.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/generic.c
6328--- linux-3.6.6/fs/proc/generic.c 2012-10-04 15:27:41.000000000 +0200
6329+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/generic.c 2012-10-04 18:47:00.000000000 +0200
6330@@ -22,6 +22,7 @@
6331 #include <linux/bitops.h>
6332 #include <linux/spinlock.h>
6333 #include <linux/completion.h>
6334+#include <linux/vserver/inode.h>
6335 #include <asm/uaccess.h>
6336
6337 #include "internal.h"
6338@@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6339 for (de = de->subdir; de ; de = de->next) {
6340 if (de->namelen != dentry->d_name.len)
6341 continue;
6342+ if (!vx_hide_check(0, de->vx_flags))
6343+ continue;
6344 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6345 pde_get(de);
6346 spin_unlock(&proc_subdir_lock);
6347 error = -EINVAL;
6348 inode = proc_get_inode(dir->i_sb, de);
6349+ /* generic proc entries belong to the host */
6350+ inode->i_tag = 0;
6351 goto out_unlock;
6352 }
6353 }
6354@@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6355
6356 /* filldir passes info to user space */
6357 pde_get(de);
6358+ if (!vx_hide_check(0, de->vx_flags))
6359+ goto skip;
6360 spin_unlock(&proc_subdir_lock);
6361 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6362 de->low_ino, de->mode >> 12) < 0) {
6363@@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6364 goto out;
6365 }
6366 spin_lock(&proc_subdir_lock);
6367+ skip:
6368 filp->f_pos++;
6369 next = de->next;
6370 pde_put(de);
6371@@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6372 ent->nlink = nlink;
6373 atomic_set(&ent->count, 1);
6374 ent->pde_users = 0;
6375+ ent->vx_flags = IATTR_PROC_DEFAULT;
6376 spin_lock_init(&ent->pde_unload_lock);
6377 ent->pde_unload_completion = NULL;
6378 INIT_LIST_HEAD(&ent->pde_openers);
6379@@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6380 kfree(ent->data);
6381 kfree(ent);
6382 ent = NULL;
6383- }
6384+ } else
6385+ ent->vx_flags = IATTR_PROC_SYMLINK;
6386 } else {
6387 kfree(ent);
6388 ent = NULL;
6389diff -NurpP --minimal linux-3.6.6/fs/proc/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/inode.c
6390--- linux-3.6.6/fs/proc/inode.c 2012-07-22 23:39:42.000000000 +0200
6391+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/inode.c 2012-10-04 18:47:00.000000000 +0200
6392@@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6393 inode->i_uid = de->uid;
6394 inode->i_gid = de->gid;
6395 }
6396+ if (de->vx_flags)
6397+ PROC_I(inode)->vx_flags = de->vx_flags;
6398 if (de->size)
6399 inode->i_size = de->size;
6400 if (de->nlink)
6401diff -NurpP --minimal linux-3.6.6/fs/proc/internal.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/internal.h
6402--- linux-3.6.6/fs/proc/internal.h 2012-10-04 15:27:41.000000000 +0200
6403+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/internal.h 2012-10-04 18:47:00.000000000 +0200
6404@@ -10,6 +10,8 @@
6405 */
6406
6407 #include <linux/proc_fs.h>
6408+#include <linux/vs_pid.h>
6409+
6410 struct ctl_table_header;
6411
6412 extern struct proc_dir_entry proc_root;
6413@@ -52,6 +54,9 @@ extern int proc_pid_status(struct seq_fi
6414 struct pid *pid, struct task_struct *task);
6415 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6416 struct pid *pid, struct task_struct *task);
6417+extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6418+ struct pid *pid, struct task_struct *task);
6419+
6420 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6421
6422 extern const struct file_operations proc_tid_children_operations;
6423@@ -81,11 +86,16 @@ static inline struct pid *proc_pid(struc
6424 return PROC_I(inode)->pid;
6425 }
6426
6427-static inline struct task_struct *get_proc_task(struct inode *inode)
6428+static inline struct task_struct *get_proc_task_real(struct inode *inode)
6429 {
6430 return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6431 }
6432
6433+static inline struct task_struct *get_proc_task(struct inode *inode)
6434+{
6435+ return vx_get_proc_task(inode, proc_pid(inode));
6436+}
6437+
6438 static inline int proc_fd(struct inode *inode)
6439 {
6440 return PROC_I(inode)->fd;
6441diff -NurpP --minimal linux-3.6.6/fs/proc/loadavg.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/loadavg.c
6442--- linux-3.6.6/fs/proc/loadavg.c 2009-09-10 15:26:23.000000000 +0200
6443+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/loadavg.c 2012-10-04 18:47:00.000000000 +0200
6444@@ -12,15 +12,27 @@
6445
6446 static int loadavg_proc_show(struct seq_file *m, void *v)
6447 {
6448+ unsigned long running;
6449+ unsigned int threads;
6450 unsigned long avnrun[3];
6451
6452 get_avenrun(avnrun, FIXED_1/200, 0);
6453
6454+ if (vx_flags(VXF_VIRT_LOAD, 0)) {
6455+ struct vx_info *vxi = current_vx_info();
6456+
6457+ running = atomic_read(&vxi->cvirt.nr_running);
6458+ threads = atomic_read(&vxi->cvirt.nr_threads);
6459+ } else {
6460+ running = nr_running();
6461+ threads = nr_threads;
6462+ }
6463+
6464 seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6465 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6466 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6467 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6468- nr_running(), nr_threads,
6469+ running, threads,
6470 task_active_pid_ns(current)->last_pid);
6471 return 0;
6472 }
6473diff -NurpP --minimal linux-3.6.6/fs/proc/meminfo.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/meminfo.c
6474--- linux-3.6.6/fs/proc/meminfo.c 2012-01-09 16:14:55.000000000 +0100
6475+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/meminfo.c 2012-10-04 18:47:00.000000000 +0200
6476@@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6477 allowed = ((totalram_pages - hugetlb_total_pages())
6478 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6479
6480- cached = global_page_state(NR_FILE_PAGES) -
6481+ cached = vx_flags(VXF_VIRT_MEM, 0) ?
6482+ vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6483 total_swapcache_pages - i.bufferram;
6484 if (cached < 0)
6485 cached = 0;
6486diff -NurpP --minimal linux-3.6.6/fs/proc/root.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/root.c
6487--- linux-3.6.6/fs/proc/root.c 2012-10-04 15:27:41.000000000 +0200
6488+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/root.c 2012-10-04 18:47:00.000000000 +0200
6489@@ -19,9 +19,14 @@
6490 #include <linux/mount.h>
6491 #include <linux/pid_namespace.h>
6492 #include <linux/parser.h>
6493+#include <linux/vserver/inode.h>
6494
6495 #include "internal.h"
6496
6497+struct proc_dir_entry *proc_virtual;
6498+
6499+extern void proc_vx_init(void);
6500+
6501 static int proc_test_super(struct super_block *sb, void *data)
6502 {
6503 return sb->s_fs_info == data;
6504@@ -189,6 +194,7 @@ void __init proc_root_init(void)
6505 #endif
6506 proc_mkdir("bus", NULL);
6507 proc_sys_init();
6508+ proc_vx_init();
6509 }
6510
6511 static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6512@@ -255,6 +261,7 @@ struct proc_dir_entry proc_root = {
6513 .proc_iops = &proc_root_inode_operations,
6514 .proc_fops = &proc_root_operations,
6515 .parent = &proc_root,
6516+ .vx_flags = IATTR_ADMIN | IATTR_WATCH,
6517 .name = "/proc",
6518 };
6519
6520diff -NurpP --minimal linux-3.6.6/fs/proc/stat.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/stat.c
6521--- linux-3.6.6/fs/proc/stat.c 2012-11-06 18:42:13.000000000 +0100
6522+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/stat.c 2012-11-06 18:43:41.000000000 +0100
6523@@ -9,6 +9,7 @@
6524 #include <linux/slab.h>
6525 #include <linux/time.h>
6526 #include <linux/irqnr.h>
6527+#include <linux/vserver/cvirt.h>
6528 #include <asm/cputime.h>
6529 #include <linux/tick.h>
6530
6531@@ -92,6 +93,10 @@ static int show_stat(struct seq_file *p,
6532 irq = softirq = steal = 0;
6533 guest = guest_nice = 0;
6534 getboottime(&boottime);
6535+
6536+ if (vx_flags(VXF_VIRT_UPTIME, 0))
6537+ vx_vsi_boottime(&boottime);
6538+
6539 jif = boottime.tv_sec;
6540
6541 for_each_possible_cpu(i) {
6542diff -NurpP --minimal linux-3.6.6/fs/proc/uptime.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/uptime.c
6543--- linux-3.6.6/fs/proc/uptime.c 2012-03-19 19:47:26.000000000 +0100
6544+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc/uptime.c 2012-10-04 18:47:00.000000000 +0200
6545@@ -5,6 +5,7 @@
6546 #include <linux/seq_file.h>
6547 #include <linux/time.h>
6548 #include <linux/kernel_stat.h>
6549+#include <linux/vserver/cvirt.h>
6550 #include <asm/cputime.h>
6551
6552 static int uptime_proc_show(struct seq_file *m, void *v)
6553@@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6554 nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6555 idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6556 idle.tv_nsec = rem;
6557+
6558+ if (vx_flags(VXF_VIRT_UPTIME, 0))
6559+ vx_vsi_uptime(&uptime, &idle);
6560+
6561 seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6562 (unsigned long) uptime.tv_sec,
6563 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6564diff -NurpP --minimal linux-3.6.6/fs/proc_namespace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc_namespace.c
6565--- linux-3.6.6/fs/proc_namespace.c 2012-10-04 15:27:41.000000000 +0200
6566+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/proc_namespace.c 2012-10-04 18:47:00.000000000 +0200
6567@@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6568 { MS_SYNCHRONOUS, ",sync" },
6569 { MS_DIRSYNC, ",dirsync" },
6570 { MS_MANDLOCK, ",mand" },
6571+ { MS_TAGGED, ",tag" },
6572+ { MS_NOTAGCHECK, ",notagcheck" },
6573 { 0, NULL }
6574 };
6575 const struct proc_fs_info *fs_infop;
6576@@ -80,6 +82,34 @@ static inline void mangle(struct seq_fil
6577 seq_escape(m, s, " \t\n\\");
6578 }
6579
6580+static int mnt_is_reachable(struct vfsmount *vfsmnt)
6581+{
6582+ struct path root;
6583+ struct dentry *point;
6584+ struct mount *mnt = real_mount(vfsmnt);
6585+ struct mount *root_mnt;
6586+ int ret;
6587+
6588+ if (mnt == mnt->mnt_ns->root)
6589+ return 1;
6590+
6591+ br_read_lock(&vfsmount_lock);
6592+ root = current->fs->root;
6593+ root_mnt = real_mount(root.mnt);
6594+ point = root.dentry;
6595+
6596+ while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6597+ point = mnt->mnt_mountpoint;
6598+ mnt = mnt->mnt_parent;
6599+ }
6600+
6601+ ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6602+
6603+ br_read_unlock(&vfsmount_lock);
6604+
6605+ return ret;
6606+}
6607+
6608 static void show_type(struct seq_file *m, struct super_block *sb)
6609 {
6610 mangle(m, sb->s_type->name);
6611@@ -96,6 +126,17 @@ static int show_vfsmnt(struct seq_file *
6612 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6613 struct super_block *sb = mnt_path.dentry->d_sb;
6614
6615+ if (vx_flags(VXF_HIDE_MOUNT, 0))
6616+ return SEQ_SKIP;
6617+ if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6618+ return SEQ_SKIP;
6619+
6620+ if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6621+ mnt == current->fs->root.mnt) {
6622+ seq_puts(m, "/dev/root / ");
6623+ goto type;
6624+ }
6625+
6626 if (sb->s_op->show_devname) {
6627 err = sb->s_op->show_devname(m, mnt_path.dentry);
6628 if (err)
6629@@ -106,6 +147,7 @@ static int show_vfsmnt(struct seq_file *
6630 seq_putc(m, ' ');
6631 seq_path(m, &mnt_path, " \t\n\\");
6632 seq_putc(m, ' ');
6633+type:
6634 show_type(m, sb);
6635 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6636 err = show_sb_opts(m, sb);
6637@@ -128,6 +170,11 @@ static int show_mountinfo(struct seq_fil
6638 struct path root = p->root;
6639 int err = 0;
6640
6641+ if (vx_flags(VXF_HIDE_MOUNT, 0))
6642+ return SEQ_SKIP;
6643+ if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6644+ return SEQ_SKIP;
6645+
6646 seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6647 MAJOR(sb->s_dev), MINOR(sb->s_dev));
6648 if (sb->s_op->show_path)
6649@@ -187,6 +234,17 @@ static int show_vfsstat(struct seq_file
6650 struct super_block *sb = mnt_path.dentry->d_sb;
6651 int err = 0;
6652
6653+ if (vx_flags(VXF_HIDE_MOUNT, 0))
6654+ return SEQ_SKIP;
6655+ if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6656+ return SEQ_SKIP;
6657+
6658+ if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6659+ mnt == current->fs->root.mnt) {
6660+ seq_puts(m, "device /dev/root mounted on / ");
6661+ goto type;
6662+ }
6663+
6664 /* device */
6665 if (sb->s_op->show_devname) {
6666 seq_puts(m, "device ");
6667@@ -203,7 +261,7 @@ static int show_vfsstat(struct seq_file
6668 seq_puts(m, " mounted on ");
6669 seq_path(m, &mnt_path, " \t\n\\");
6670 seq_putc(m, ' ');
6671-
6672+type:
6673 /* file system type */
6674 seq_puts(m, "with fstype ");
6675 show_type(m, sb);
6676diff -NurpP --minimal linux-3.6.6/fs/quota/dquot.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/quota/dquot.c
6677--- linux-3.6.6/fs/quota/dquot.c 2012-10-04 15:27:41.000000000 +0200
6678+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/quota/dquot.c 2012-10-04 18:47:00.000000000 +0200
6679@@ -1580,6 +1580,9 @@ int __dquot_alloc_space(struct inode *in
6680 struct dquot **dquots = inode->i_dquot;
6681 int reserve = flags & DQUOT_SPACE_RESERVE;
6682
6683+ if ((ret = dl_alloc_space(inode, number)))
6684+ return ret;
6685+
6686 /*
6687 * First test before acquiring mutex - solves deadlocks when we
6688 * re-enter the quota code and are already holding the mutex
6689@@ -1635,6 +1638,9 @@ int dquot_alloc_inode(const struct inode
6690 struct dquot_warn warn[MAXQUOTAS];
6691 struct dquot * const *dquots = inode->i_dquot;
6692
6693+ if ((ret = dl_alloc_inode(inode)))
6694+ return ret;
6695+
6696 /* First test before acquiring mutex - solves deadlocks when we
6697 * re-enter the quota code and are already holding the mutex */
6698 if (!dquot_active(inode))
6699@@ -1706,6 +1712,8 @@ void __dquot_free_space(struct inode *in
6700 struct dquot **dquots = inode->i_dquot;
6701 int reserve = flags & DQUOT_SPACE_RESERVE;
6702
6703+ dl_free_space(inode, number);
6704+
6705 /* First test before acquiring mutex - solves deadlocks when we
6706 * re-enter the quota code and are already holding the mutex */
6707 if (!dquot_active(inode)) {
6708@@ -1750,6 +1758,8 @@ void dquot_free_inode(const struct inode
6709 struct dquot_warn warn[MAXQUOTAS];
6710 struct dquot * const *dquots = inode->i_dquot;
6711
6712+ dl_free_inode(inode);
6713+
6714 /* First test before acquiring mutex - solves deadlocks when we
6715 * re-enter the quota code and are already holding the mutex */
6716 if (!dquot_active(inode))
6717diff -NurpP --minimal linux-3.6.6/fs/quota/quota.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/quota/quota.c
6718--- linux-3.6.6/fs/quota/quota.c 2012-10-04 15:27:41.000000000 +0200
6719+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/quota/quota.c 2012-10-04 18:47:00.000000000 +0200
6720@@ -8,6 +8,7 @@
6721 #include <linux/fs.h>
6722 #include <linux/namei.h>
6723 #include <linux/slab.h>
6724+#include <linux/vs_context.h>
6725 #include <asm/current.h>
6726 #include <linux/uaccess.h>
6727 #include <linux/kernel.h>
6728@@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6729 break;
6730 /*FALLTHROUGH*/
6731 default:
6732- if (!capable(CAP_SYS_ADMIN))
6733+ if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6734 return -EPERM;
6735 }
6736
6737@@ -291,6 +292,46 @@ static int do_quotactl(struct super_bloc
6738 }
6739 }
6740
6741+#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6742+
6743+#include <linux/vroot.h>
6744+#include <linux/major.h>
6745+#include <linux/module.h>
6746+#include <linux/kallsyms.h>
6747+#include <linux/vserver/debug.h>
6748+
6749+static vroot_grb_func *vroot_get_real_bdev = NULL;
6750+
6751+static DEFINE_SPINLOCK(vroot_grb_lock);
6752+
6753+int register_vroot_grb(vroot_grb_func *func) {
6754+ int ret = -EBUSY;
6755+
6756+ spin_lock(&vroot_grb_lock);
6757+ if (!vroot_get_real_bdev) {
6758+ vroot_get_real_bdev = func;
6759+ ret = 0;
6760+ }
6761+ spin_unlock(&vroot_grb_lock);
6762+ return ret;
6763+}
6764+EXPORT_SYMBOL(register_vroot_grb);
6765+
6766+int unregister_vroot_grb(vroot_grb_func *func) {
6767+ int ret = -EINVAL;
6768+
6769+ spin_lock(&vroot_grb_lock);
6770+ if (vroot_get_real_bdev) {
6771+ vroot_get_real_bdev = NULL;
6772+ ret = 0;
6773+ }
6774+ spin_unlock(&vroot_grb_lock);
6775+ return ret;
6776+}
6777+EXPORT_SYMBOL(unregister_vroot_grb);
6778+
6779+#endif
6780+
6781 /* Return 1 if 'cmd' will block on frozen filesystem */
6782 static int quotactl_cmd_write(int cmd)
6783 {
6784@@ -323,6 +364,22 @@ static struct super_block *quotactl_bloc
6785 putname(tmp);
6786 if (IS_ERR(bdev))
6787 return ERR_CAST(bdev);
6788+#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6789+ if (bdev && bdev->bd_inode &&
6790+ imajor(bdev->bd_inode) == VROOT_MAJOR) {
6791+ struct block_device *bdnew = (void *)-EINVAL;
6792+
6793+ if (vroot_get_real_bdev)
6794+ bdnew = vroot_get_real_bdev(bdev);
6795+ else
6796+ vxdprintk(VXD_CBIT(misc, 0),
6797+ "vroot_get_real_bdev not set");
6798+ bdput(bdev);
6799+ if (IS_ERR(bdnew))
6800+ return ERR_PTR(PTR_ERR(bdnew));
6801+ bdev = bdnew;
6802+ }
6803+#endif
6804 if (quotactl_cmd_write(cmd))
6805 sb = get_super_thawed(bdev);
6806 else
6807diff -NurpP --minimal linux-3.6.6/fs/reiserfs/file.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/file.c
6808--- linux-3.6.6/fs/reiserfs/file.c 2012-05-21 18:07:26.000000000 +0200
6809+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/file.c 2012-10-04 18:47:00.000000000 +0200
6810@@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6811 .listxattr = reiserfs_listxattr,
6812 .removexattr = reiserfs_removexattr,
6813 .permission = reiserfs_permission,
6814+ .sync_flags = reiserfs_sync_flags,
6815 .get_acl = reiserfs_get_acl,
6816 };
6817diff -NurpP --minimal linux-3.6.6/fs/reiserfs/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/inode.c
6818--- linux-3.6.6/fs/reiserfs/inode.c 2012-11-06 18:42:13.000000000 +0100
6819+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/inode.c 2012-11-06 18:43:41.000000000 +0100
6820@@ -18,6 +18,7 @@
6821 #include <linux/writeback.h>
6822 #include <linux/quotaops.h>
6823 #include <linux/swap.h>
6824+#include <linux/vs_tag.h>
6825
6826 int reiserfs_commit_write(struct file *f, struct page *page,
6827 unsigned from, unsigned to);
6828@@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6829 struct buffer_head *bh;
6830 struct item_head *ih;
6831 __u32 rdev;
6832+ uid_t uid;
6833+ gid_t gid;
6834 //int version = ITEM_VERSION_1;
6835
6836 bh = PATH_PLAST_BUFFER(path);
6837@@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6838 (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6839 unsigned long blocks;
6840
6841+ uid = sd_v1_uid(sd);
6842+ gid = sd_v1_gid(sd);
6843+
6844 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6845 set_inode_sd_version(inode, STAT_DATA_V1);
6846 inode->i_mode = sd_v1_mode(sd);
6847 set_nlink(inode, sd_v1_nlink(sd));
6848- inode->i_uid = sd_v1_uid(sd);
6849- inode->i_gid = sd_v1_gid(sd);
6850 inode->i_size = sd_v1_size(sd);
6851 inode->i_atime.tv_sec = sd_v1_atime(sd);
6852 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6853@@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6854 // (directories and symlinks)
6855 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6856
6857+ uid = sd_v2_uid(sd);
6858+ gid = sd_v2_gid(sd);
6859+
6860 inode->i_mode = sd_v2_mode(sd);
6861 set_nlink(inode, sd_v2_nlink(sd));
6862- inode->i_uid = sd_v2_uid(sd);
6863 inode->i_size = sd_v2_size(sd);
6864- inode->i_gid = sd_v2_gid(sd);
6865 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6866 inode->i_atime.tv_sec = sd_v2_atime(sd);
6867 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6868@@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6869 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6870 }
6871
6872+ inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6873+ inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6874+ inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6875+
6876 pathrelse(path);
6877 if (S_ISREG(inode->i_mode)) {
6878 inode->i_op = &reiserfs_file_inode_operations;
6879@@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6880 static void inode2sd(void *sd, struct inode *inode, loff_t size)
6881 {
6882 struct stat_data *sd_v2 = (struct stat_data *)sd;
6883+ uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6884+ gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6885 __u16 flags;
6886
6887+ set_sd_v2_uid(sd_v2, uid);
6888+ set_sd_v2_gid(sd_v2, gid);
6889 set_sd_v2_mode(sd_v2, inode->i_mode);
6890 set_sd_v2_nlink(sd_v2, inode->i_nlink);
6891- set_sd_v2_uid(sd_v2, inode->i_uid);
6892 set_sd_v2_size(sd_v2, size);
6893- set_sd_v2_gid(sd_v2, inode->i_gid);
6894 set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6895 set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6896 set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6897@@ -2866,14 +2877,19 @@ int reiserfs_commit_write(struct file *f
6898 void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6899 {
6900 if (reiserfs_attrs(inode->i_sb)) {
6901- if (sd_attrs & REISERFS_SYNC_FL)
6902- inode->i_flags |= S_SYNC;
6903- else
6904- inode->i_flags &= ~S_SYNC;
6905 if (sd_attrs & REISERFS_IMMUTABLE_FL)
6906 inode->i_flags |= S_IMMUTABLE;
6907 else
6908 inode->i_flags &= ~S_IMMUTABLE;
6909+ if (sd_attrs & REISERFS_IXUNLINK_FL)
6910+ inode->i_flags |= S_IXUNLINK;
6911+ else
6912+ inode->i_flags &= ~S_IXUNLINK;
6913+
6914+ if (sd_attrs & REISERFS_SYNC_FL)
6915+ inode->i_flags |= S_SYNC;
6916+ else
6917+ inode->i_flags &= ~S_SYNC;
6918 if (sd_attrs & REISERFS_APPEND_FL)
6919 inode->i_flags |= S_APPEND;
6920 else
6921@@ -2886,6 +2902,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
6922 REISERFS_I(inode)->i_flags |= i_nopack_mask;
6923 else
6924 REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
6925+
6926+ if (sd_attrs & REISERFS_BARRIER_FL)
6927+ inode->i_vflags |= V_BARRIER;
6928+ else
6929+ inode->i_vflags &= ~V_BARRIER;
6930+ if (sd_attrs & REISERFS_COW_FL)
6931+ inode->i_vflags |= V_COW;
6932+ else
6933+ inode->i_vflags &= ~V_COW;
6934 }
6935 }
6936
6937@@ -2896,6 +2921,11 @@ void i_attrs_to_sd_attrs(struct inode *i
6938 *sd_attrs |= REISERFS_IMMUTABLE_FL;
6939 else
6940 *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
6941+ if (inode->i_flags & S_IXUNLINK)
6942+ *sd_attrs |= REISERFS_IXUNLINK_FL;
6943+ else
6944+ *sd_attrs &= ~REISERFS_IXUNLINK_FL;
6945+
6946 if (inode->i_flags & S_SYNC)
6947 *sd_attrs |= REISERFS_SYNC_FL;
6948 else
6949@@ -2908,6 +2938,15 @@ void i_attrs_to_sd_attrs(struct inode *i
6950 *sd_attrs |= REISERFS_NOTAIL_FL;
6951 else
6952 *sd_attrs &= ~REISERFS_NOTAIL_FL;
6953+
6954+ if (inode->i_vflags & V_BARRIER)
6955+ *sd_attrs |= REISERFS_BARRIER_FL;
6956+ else
6957+ *sd_attrs &= ~REISERFS_BARRIER_FL;
6958+ if (inode->i_vflags & V_COW)
6959+ *sd_attrs |= REISERFS_COW_FL;
6960+ else
6961+ *sd_attrs &= ~REISERFS_COW_FL;
6962 }
6963 }
6964
6965@@ -3153,7 +3192,8 @@ int reiserfs_setattr(struct dentry *dent
6966 }
6967
6968 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
6969- (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
6970+ (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
6971+ (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
6972 struct reiserfs_transaction_handle th;
6973 int jbegin_count =
6974 2 *
6975@@ -3182,6 +3222,9 @@ int reiserfs_setattr(struct dentry *dent
6976 inode->i_uid = attr->ia_uid;
6977 if (attr->ia_valid & ATTR_GID)
6978 inode->i_gid = attr->ia_gid;
6979+ if ((attr->ia_valid & ATTR_TAG) &&
6980+ IS_TAGGED(inode))
6981+ inode->i_tag = attr->ia_tag;
6982 mark_inode_dirty(inode);
6983 error = journal_end(&th, inode->i_sb, jbegin_count);
6984 if (error)
6985diff -NurpP --minimal linux-3.6.6/fs/reiserfs/ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/ioctl.c
6986--- linux-3.6.6/fs/reiserfs/ioctl.c 2012-05-21 18:07:27.000000000 +0200
6987+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/ioctl.c 2012-10-04 18:47:00.000000000 +0200
6988@@ -11,6 +11,21 @@
6989 #include <linux/pagemap.h>
6990 #include <linux/compat.h>
6991
6992+
6993+int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
6994+{
6995+ __u16 sd_attrs = 0;
6996+
6997+ inode->i_flags = flags;
6998+ inode->i_vflags = vflags;
6999+
7000+ i_attrs_to_sd_attrs(inode, &sd_attrs);
7001+ REISERFS_I(inode)->i_attrs = sd_attrs;
7002+ inode->i_ctime = CURRENT_TIME_SEC;
7003+ mark_inode_dirty(inode);
7004+ return 0;
7005+}
7006+
7007 /*
7008 * reiserfs_ioctl - handler for ioctl for inode
7009 * supported commands:
7010@@ -22,7 +37,7 @@
7011 long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7012 {
7013 struct inode *inode = filp->f_path.dentry->d_inode;
7014- unsigned int flags;
7015+ unsigned int flags, oldflags;
7016 int err = 0;
7017
7018 reiserfs_write_lock(inode->i_sb);
7019@@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7020
7021 flags = REISERFS_I(inode)->i_attrs;
7022 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7023+ flags &= REISERFS_FL_USER_VISIBLE;
7024 err = put_user(flags, (int __user *)arg);
7025 break;
7026 case REISERFS_IOC_SETFLAGS:{
7027@@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7028 err = -EFAULT;
7029 goto setflags_out;
7030 }
7031+ if (IS_BARRIER(inode)) {
7032+ vxwprintk_task(1, "messing with the barrier.");
7033+ return -EACCES;
7034+ }
7035 /*
7036 * Is it quota file? Do not allow user to mess with it
7037 */
7038@@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7039 goto setflags_out;
7040 }
7041 }
7042+
7043+ oldflags = REISERFS_I(inode)->i_attrs;
7044+ flags &= REISERFS_FL_USER_MODIFIABLE;
7045+ flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7046 sd_attrs_to_i_attrs(flags, inode);
7047 REISERFS_I(inode)->i_attrs = flags;
7048 inode->i_ctime = CURRENT_TIME_SEC;
7049diff -NurpP --minimal linux-3.6.6/fs/reiserfs/namei.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/namei.c
7050--- linux-3.6.6/fs/reiserfs/namei.c 2012-10-04 15:27:41.000000000 +0200
7051+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/namei.c 2012-10-04 18:47:00.000000000 +0200
7052@@ -18,6 +18,7 @@
7053 #include "acl.h"
7054 #include "xattr.h"
7055 #include <linux/quotaops.h>
7056+#include <linux/vs_tag.h>
7057
7058 #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) set_nlink(i, 1); }
7059 #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7060@@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7061 if (retval == IO_ERROR) {
7062 return ERR_PTR(-EIO);
7063 }
7064+ dx_propagate_tag(nd, inode);
7065
7066 return d_splice_alias(inode, dentry);
7067 }
7068diff -NurpP --minimal linux-3.6.6/fs/reiserfs/reiserfs.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/reiserfs.h
7069--- linux-3.6.6/fs/reiserfs/reiserfs.h 2012-07-22 23:39:42.000000000 +0200
7070+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/reiserfs.h 2012-10-04 18:47:00.000000000 +0200
7071@@ -549,6 +549,7 @@ enum reiserfs_mount_options {
7072 REISERFS_EXPOSE_PRIVROOT,
7073 REISERFS_BARRIER_NONE,
7074 REISERFS_BARRIER_FLUSH,
7075+ REISERFS_TAGGED,
7076
7077 /* Actions on error */
7078 REISERFS_ERROR_PANIC,
7079@@ -1548,6 +1549,11 @@ struct stat_data_v1 {
7080 #define REISERFS_COMPR_FL FS_COMPR_FL
7081 #define REISERFS_NOTAIL_FL FS_NOTAIL_FL
7082
7083+/* unfortunately reiserfs sdattr is only 16 bit */
7084+#define REISERFS_IXUNLINK_FL (FS_IXUNLINK_FL >> 16)
7085+#define REISERFS_BARRIER_FL (FS_BARRIER_FL >> 16)
7086+#define REISERFS_COW_FL (FS_COW_FL >> 16)
7087+
7088 /* persistent flags that file inherits from the parent directory */
7089 #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL | \
7090 REISERFS_SYNC_FL | \
7091@@ -1557,6 +1563,9 @@ struct stat_data_v1 {
7092 REISERFS_COMPR_FL | \
7093 REISERFS_NOTAIL_FL )
7094
7095+#define REISERFS_FL_USER_VISIBLE 0x80FF
7096+#define REISERFS_FL_USER_MODIFIABLE 0x80FF
7097+
7098 /* Stat Data on disk (reiserfs version of UFS disk inode minus the
7099 address blocks) */
7100 struct stat_data {
7101@@ -2647,6 +2656,7 @@ static inline void reiserfs_update_sd(st
7102 void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
7103 void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
7104 int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
7105+int reiserfs_sync_flags(struct inode *inode, int, int);
7106
7107 int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
7108
7109diff -NurpP --minimal linux-3.6.6/fs/reiserfs/super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/super.c
7110--- linux-3.6.6/fs/reiserfs/super.c 2012-10-04 15:27:41.000000000 +0200
7111+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/super.c 2012-10-04 18:47:00.000000000 +0200
7112@@ -1018,6 +1018,14 @@ static int reiserfs_parse_options(struct
7113 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7114 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7115 #endif
7116+#ifndef CONFIG_TAGGING_NONE
7117+ {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7118+ {"tag",.setmask = 1 << REISERFS_TAGGED},
7119+ {"notag",.clrmask = 1 << REISERFS_TAGGED},
7120+#endif
7121+#ifdef CONFIG_PROPAGATE
7122+ {"tag",.arg_required = 'T',.values = NULL},
7123+#endif
7124 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7125 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7126 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7127@@ -1336,6 +1344,14 @@ static int reiserfs_remount(struct super
7128 handle_quota_files(s, qf_names, &qfmt);
7129 #endif
7130
7131+ if ((mount_options & (1 << REISERFS_TAGGED)) &&
7132+ !(s->s_flags & MS_TAGGED)) {
7133+ reiserfs_warning(s, "super-vs01",
7134+ "reiserfs: tagging not permitted on remount.");
7135+ err = -EINVAL;
7136+ goto out_err;
7137+ }
7138+
7139 handle_attrs(s);
7140
7141 /* Add options that are safe here */
7142@@ -1816,6 +1832,10 @@ static int reiserfs_fill_super(struct su
7143 goto error_unlocked;
7144 }
7145
7146+ /* map mount option tagxid */
7147+ if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7148+ s->s_flags |= MS_TAGGED;
7149+
7150 rs = SB_DISK_SUPER_BLOCK(s);
7151 /* Let's do basic sanity check to verify that underlying device is not
7152 smaller than the filesystem. If the check fails then abort and scream,
7153diff -NurpP --minimal linux-3.6.6/fs/reiserfs/xattr.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/xattr.c
7154--- linux-3.6.6/fs/reiserfs/xattr.c 2012-10-04 15:27:41.000000000 +0200
7155+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/reiserfs/xattr.c 2012-10-04 18:47:00.000000000 +0200
7156@@ -40,6 +40,7 @@
7157 #include <linux/errno.h>
7158 #include <linux/gfp.h>
7159 #include <linux/fs.h>
7160+#include <linux/mount.h>
7161 #include <linux/file.h>
7162 #include <linux/pagemap.h>
7163 #include <linux/xattr.h>
7164diff -NurpP --minimal linux-3.6.6/fs/stat.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/stat.c
7165--- linux-3.6.6/fs/stat.c 2012-10-04 15:27:41.000000000 +0200
7166+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/stat.c 2012-10-04 18:47:00.000000000 +0200
7167@@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7168 stat->nlink = inode->i_nlink;
7169 stat->uid = inode->i_uid;
7170 stat->gid = inode->i_gid;
7171+ stat->tag = inode->i_tag;
7172 stat->rdev = inode->i_rdev;
7173 stat->size = i_size_read(inode);
7174 stat->atime = inode->i_atime;
7175diff -NurpP --minimal linux-3.6.6/fs/statfs.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/statfs.c
7176--- linux-3.6.6/fs/statfs.c 2012-07-22 23:39:42.000000000 +0200
7177+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/statfs.c 2012-10-04 18:47:00.000000000 +0200
7178@@ -7,6 +7,8 @@
7179 #include <linux/statfs.h>
7180 #include <linux/security.h>
7181 #include <linux/uaccess.h>
7182+#include <linux/vs_base.h>
7183+#include <linux/vs_dlimit.h>
7184 #include "internal.h"
7185
7186 static int flags_by_mnt(int mnt_flags)
7187@@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
7188 retval = dentry->d_sb->s_op->statfs(dentry, buf);
7189 if (retval == 0 && buf->f_frsize == 0)
7190 buf->f_frsize = buf->f_bsize;
7191+ if (!vx_check(0, VS_ADMIN|VS_WATCH))
7192+ vx_vsi_statfs(dentry->d_sb, buf);
7193 return retval;
7194 }
7195
7196diff -NurpP --minimal linux-3.6.6/fs/super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/super.c
7197--- linux-3.6.6/fs/super.c 2012-10-04 15:27:41.000000000 +0200
7198+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/super.c 2012-10-04 19:06:05.000000000 +0200
7199@@ -34,6 +34,8 @@
7200 #include <linux/cleancache.h>
7201 #include <linux/fsnotify.h>
7202 #include <linux/lockdep.h>
7203+#include <linux/magic.h>
7204+#include <linux/vs_context.h>
7205 #include "internal.h"
7206
7207
7208@@ -1148,6 +1150,13 @@ mount_fs(struct file_system_type *type,
7209 WARN_ON(sb->s_bdi == &default_backing_dev_info);
7210 sb->s_flags |= MS_BORN;
7211
7212+ error = -EPERM;
7213+ if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7214+ !sb->s_bdev &&
7215+ (sb->s_magic != PROC_SUPER_MAGIC) &&
7216+ (sb->s_magic != DEVPTS_SUPER_MAGIC))
7217+ goto out_sb;
7218+
7219 error = security_sb_kern_mount(sb, flags, secdata);
7220 if (error)
7221 goto out_sb;
7222diff -NurpP --minimal linux-3.6.6/fs/sysfs/mount.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/sysfs/mount.c
7223--- linux-3.6.6/fs/sysfs/mount.c 2012-10-04 15:27:41.000000000 +0200
7224+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/sysfs/mount.c 2012-10-04 18:47:00.000000000 +0200
7225@@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7226
7227 sb->s_blocksize = PAGE_CACHE_SIZE;
7228 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7229- sb->s_magic = SYSFS_MAGIC;
7230+ sb->s_magic = SYSFS_SUPER_MAGIC;
7231 sb->s_op = &sysfs_ops;
7232 sb->s_time_gran = 1;
7233
7234diff -NurpP --minimal linux-3.6.6/fs/utimes.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/utimes.c
7235--- linux-3.6.6/fs/utimes.c 2012-07-22 23:39:42.000000000 +0200
7236+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/utimes.c 2012-10-04 18:47:00.000000000 +0200
7237@@ -8,6 +8,8 @@
7238 #include <linux/stat.h>
7239 #include <linux/utime.h>
7240 #include <linux/syscalls.h>
7241+#include <linux/mount.h>
7242+#include <linux/vs_cowbl.h>
7243 #include <asm/uaccess.h>
7244 #include <asm/unistd.h>
7245
7246@@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7247 {
7248 int error;
7249 struct iattr newattrs;
7250- struct inode *inode = path->dentry->d_inode;
7251+ struct inode *inode;
7252
7253 error = mnt_want_write(path->mnt);
7254 if (error)
7255 goto out;
7256
7257+ error = cow_check_and_break(path);
7258+ if (error)
7259+ goto mnt_drop_write_and_out;
7260+
7261+ inode = path->dentry->d_inode;
7262+
7263 if (times && times[0].tv_nsec == UTIME_NOW &&
7264 times[1].tv_nsec == UTIME_NOW)
7265 times = NULL;
7266diff -NurpP --minimal linux-3.6.6/fs/xattr.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xattr.c
7267--- linux-3.6.6/fs/xattr.c 2012-10-04 15:27:44.000000000 +0200
7268+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xattr.c 2012-10-04 18:47:00.000000000 +0200
7269@@ -20,6 +20,7 @@
7270 #include <linux/fsnotify.h>
7271 #include <linux/audit.h>
7272 #include <linux/vmalloc.h>
7273+#include <linux/mount.h>
7274
7275 #include <asm/uaccess.h>
7276
7277@@ -51,7 +52,7 @@ xattr_permission(struct inode *inode, co
7278 * The trusted.* namespace can only be accessed by privileged users.
7279 */
7280 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7281- if (!capable(CAP_SYS_ADMIN))
7282+ if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7283 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7284 return 0;
7285 }
7286diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_dinode.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_dinode.h
7287--- linux-3.6.6/fs/xfs/xfs_dinode.h 2012-10-04 15:27:44.000000000 +0200
7288+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_dinode.h 2012-10-04 18:47:00.000000000 +0200
7289@@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7290 __be32 di_nlink; /* number of links to file */
7291 __be16 di_projid_lo; /* lower part of owner's project id */
7292 __be16 di_projid_hi; /* higher part owner's project id */
7293- __u8 di_pad[6]; /* unused, zeroed space */
7294+ __u8 di_pad[2]; /* unused, zeroed space */
7295+ __be16 di_tag; /* context tagging */
7296+ __be16 di_vflags; /* vserver specific flags */
7297 __be16 di_flushiter; /* incremented on flush */
7298 xfs_timestamp_t di_atime; /* time last accessed */
7299 xfs_timestamp_t di_mtime; /* time last modified */
7300@@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7301 #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7302 #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
7303 #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */
7304+#define XFS_DIFLAG_IXUNLINK_BIT 15 /* Immutable inver on unlink */
7305+
7306 #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
7307 #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
7308 #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
7309@@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7310 #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7311 #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
7312 #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT)
7313+#define XFS_DIFLAG_IXUNLINK (1 << XFS_DIFLAG_IXUNLINK_BIT)
7314
7315 #ifdef CONFIG_XFS_RT
7316 #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7317@@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7318 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7319 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7320 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7321- XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7322+ XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7323+ XFS_DIFLAG_IXUNLINK)
7324+
7325+#define XFS_DIVFLAG_BARRIER 0x01
7326+#define XFS_DIVFLAG_COW 0x02
7327
7328 #endif /* __XFS_DINODE_H__ */
7329diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_fs.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_fs.h
7330--- linux-3.6.6/fs/xfs/xfs_fs.h 2011-10-24 18:45:31.000000000 +0200
7331+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_fs.h 2012-10-04 18:47:00.000000000 +0200
7332@@ -67,6 +67,9 @@ struct fsxattr {
7333 #define XFS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
7334 #define XFS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
7335 #define XFS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
7336+#define XFS_XFLAG_IXUNLINK 0x00008000 /* immutable invert on unlink */
7337+#define XFS_XFLAG_BARRIER 0x10000000 /* chroot() barrier */
7338+#define XFS_XFLAG_COW 0x20000000 /* copy on write mark */
7339 #define XFS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
7340
7341 /*
7342@@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7343 #define bs_projid bs_projid_lo /* (previously just bs_projid) */
7344 __u16 bs_forkoff; /* inode fork offset in bytes */
7345 __u16 bs_projid_hi; /* higher part of project id */
7346- unsigned char bs_pad[10]; /* pad space, unused */
7347+ unsigned char bs_pad[8]; /* pad space, unused */
7348+ __u16 bs_tag; /* context tagging */
7349 __u32 bs_dmevmask; /* DMIG event mask */
7350 __u16 bs_dmstate; /* DMIG state info */
7351 __u16 bs_aextents; /* attribute number of extents */
7352diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_ialloc.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_ialloc.c
7353--- linux-3.6.6/fs/xfs/xfs_ialloc.c 2012-10-04 15:27:44.000000000 +0200
7354+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_ialloc.c 2012-10-04 18:47:00.000000000 +0200
7355@@ -37,7 +37,6 @@
7356 #include "xfs_error.h"
7357 #include "xfs_bmap.h"
7358
7359-
7360 /*
7361 * Allocation group level functions.
7362 */
7363diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_inode.c
7364--- linux-3.6.6/fs/xfs/xfs_inode.c 2012-10-04 15:27:44.000000000 +0200
7365+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_inode.c 2012-10-04 18:47:00.000000000 +0200
7366@@ -1833,6 +1833,7 @@ xfs_iroot_realloc(
7367 return;
7368 }
7369
7370+#include <linux/vs_tag.h>
7371
7372 /*
7373 * This is called when the amount of space needed for if_data
7374@@ -2521,7 +2522,8 @@ xfs_iflush_int(
7375 * because if the inode is dirty at all the core must
7376 * be.
7377 */
7378- xfs_dinode_to_disk(dip, &ip->i_d);
7379+ xfs_dinode_to_disk(dip, &ip->i_d,
7380+ mp->m_flags & XFS_MOUNT_TAGGED);
7381
7382 /* Wrap, we never let the log put out DI_MAX_FLUSH */
7383 if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7384diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_inode.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_inode.h
7385--- linux-3.6.6/fs/xfs/xfs_inode.h 2012-10-04 15:27:44.000000000 +0200
7386+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_inode.h 2012-10-04 18:47:00.000000000 +0200
7387@@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7388 __uint32_t di_nlink; /* number of links to file */
7389 __uint16_t di_projid_lo; /* lower part of owner's project id */
7390 __uint16_t di_projid_hi; /* higher part of owner's project id */
7391- __uint8_t di_pad[6]; /* unused, zeroed space */
7392+ __uint8_t di_pad[2]; /* unused, zeroed space */
7393+ __uint16_t di_tag; /* context tagging */
7394+ __uint16_t di_vflags; /* vserver specific flags */
7395 __uint16_t di_flushiter; /* incremented on flush */
7396 xfs_ictimestamp_t di_atime; /* time last accessed */
7397 xfs_ictimestamp_t di_mtime; /* time last modified */
7398@@ -561,7 +563,7 @@ int xfs_imap_to_bp(struct xfs_mount *,
7399 int xfs_iread(struct xfs_mount *, struct xfs_trans *,
7400 struct xfs_inode *, uint);
7401 void xfs_dinode_to_disk(struct xfs_dinode *,
7402- struct xfs_icdinode *);
7403+ struct xfs_icdinode *, int);
7404 void xfs_idestroy_fork(struct xfs_inode *, int);
7405 void xfs_idata_realloc(struct xfs_inode *, int, int);
7406 void xfs_iroot_realloc(struct xfs_inode *, int, int);
7407diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_ioctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_ioctl.c
7408--- linux-3.6.6/fs/xfs/xfs_ioctl.c 2012-10-04 15:27:44.000000000 +0200
7409+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_ioctl.c 2012-10-04 18:47:00.000000000 +0200
7410@@ -26,7 +26,7 @@
7411 #include "xfs_bmap_btree.h"
7412 #include "xfs_dinode.h"
7413 #include "xfs_inode.h"
7414-#include "xfs_ioctl.h"
7415+// #include "xfs_ioctl.h"
7416 #include "xfs_rtalloc.h"
7417 #include "xfs_itable.h"
7418 #include "xfs_error.h"
7419@@ -762,6 +762,10 @@ xfs_merge_ioc_xflags(
7420 xflags |= XFS_XFLAG_IMMUTABLE;
7421 else
7422 xflags &= ~XFS_XFLAG_IMMUTABLE;
7423+ if (flags & FS_IXUNLINK_FL)
7424+ xflags |= XFS_XFLAG_IXUNLINK;
7425+ else
7426+ xflags &= ~XFS_XFLAG_IXUNLINK;
7427 if (flags & FS_APPEND_FL)
7428 xflags |= XFS_XFLAG_APPEND;
7429 else
7430@@ -790,6 +794,8 @@ xfs_di2lxflags(
7431
7432 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7433 flags |= FS_IMMUTABLE_FL;
7434+ if (di_flags & XFS_DIFLAG_IXUNLINK)
7435+ flags |= FS_IXUNLINK_FL;
7436 if (di_flags & XFS_DIFLAG_APPEND)
7437 flags |= FS_APPEND_FL;
7438 if (di_flags & XFS_DIFLAG_SYNC)
7439@@ -850,6 +856,8 @@ xfs_set_diflags(
7440 di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7441 if (xflags & XFS_XFLAG_IMMUTABLE)
7442 di_flags |= XFS_DIFLAG_IMMUTABLE;
7443+ if (xflags & XFS_XFLAG_IXUNLINK)
7444+ di_flags |= XFS_DIFLAG_IXUNLINK;
7445 if (xflags & XFS_XFLAG_APPEND)
7446 di_flags |= XFS_DIFLAG_APPEND;
7447 if (xflags & XFS_XFLAG_SYNC)
7448@@ -892,6 +900,10 @@ xfs_diflags_to_linux(
7449 inode->i_flags |= S_IMMUTABLE;
7450 else
7451 inode->i_flags &= ~S_IMMUTABLE;
7452+ if (xflags & XFS_XFLAG_IXUNLINK)
7453+ inode->i_flags |= S_IXUNLINK;
7454+ else
7455+ inode->i_flags &= ~S_IXUNLINK;
7456 if (xflags & XFS_XFLAG_APPEND)
7457 inode->i_flags |= S_APPEND;
7458 else
7459@@ -1396,10 +1408,18 @@ xfs_file_ioctl(
7460 case XFS_IOC_FSGETXATTRA:
7461 return xfs_ioc_fsgetxattr(ip, 1, arg);
7462 case XFS_IOC_FSSETXATTR:
7463+ if (IS_BARRIER(inode)) {
7464+ vxwprintk_task(1, "messing with the barrier.");
7465+ return -XFS_ERROR(EACCES);
7466+ }
7467 return xfs_ioc_fssetxattr(ip, filp, arg);
7468 case XFS_IOC_GETXFLAGS:
7469 return xfs_ioc_getxflags(ip, arg);
7470 case XFS_IOC_SETXFLAGS:
7471+ if (IS_BARRIER(inode)) {
7472+ vxwprintk_task(1, "messing with the barrier.");
7473+ return -XFS_ERROR(EACCES);
7474+ }
7475 return xfs_ioc_setxflags(ip, filp, arg);
7476
7477 case XFS_IOC_FSSETDM: {
7478diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_ioctl.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_ioctl.h
7479--- linux-3.6.6/fs/xfs/xfs_ioctl.h 2011-10-24 18:45:31.000000000 +0200
7480+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_ioctl.h 2012-10-04 18:47:00.000000000 +0200
7481@@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7482 void __user *uhandle,
7483 u32 hlen);
7484
7485+extern int
7486+xfs_sync_flags(
7487+ struct inode *inode,
7488+ int flags,
7489+ int vflags);
7490+
7491 extern long
7492 xfs_file_ioctl(
7493 struct file *filp,
7494diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_iops.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_iops.c
7495--- linux-3.6.6/fs/xfs/xfs_iops.c 2012-10-04 15:27:44.000000000 +0200
7496+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_iops.c 2012-10-04 18:47:00.000000000 +0200
7497@@ -28,6 +28,7 @@
7498 #include "xfs_bmap_btree.h"
7499 #include "xfs_dinode.h"
7500 #include "xfs_inode.h"
7501+#include "xfs_ioctl.h"
7502 #include "xfs_bmap.h"
7503 #include "xfs_rtalloc.h"
7504 #include "xfs_error.h"
7505@@ -46,6 +47,7 @@
7506 #include <linux/security.h>
7507 #include <linux/fiemap.h>
7508 #include <linux/slab.h>
7509+#include <linux/vs_tag.h>
7510
7511 static int
7512 xfs_initxattrs(
7513@@ -421,6 +423,7 @@ xfs_vn_getattr(
7514 stat->nlink = ip->i_d.di_nlink;
7515 stat->uid = ip->i_d.di_uid;
7516 stat->gid = ip->i_d.di_gid;
7517+ stat->tag = ip->i_d.di_tag;
7518 stat->ino = ip->i_ino;
7519 stat->atime = inode->i_atime;
7520 stat->mtime = inode->i_mtime;
7521@@ -1110,6 +1113,10 @@ xfs_diflags_to_iflags(
7522 inode->i_flags |= S_IMMUTABLE;
7523 else
7524 inode->i_flags &= ~S_IMMUTABLE;
7525+ if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7526+ inode->i_flags |= S_IXUNLINK;
7527+ else
7528+ inode->i_flags &= ~S_IXUNLINK;
7529 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7530 inode->i_flags |= S_APPEND;
7531 else
7532@@ -1122,6 +1129,15 @@ xfs_diflags_to_iflags(
7533 inode->i_flags |= S_NOATIME;
7534 else
7535 inode->i_flags &= ~S_NOATIME;
7536+
7537+ if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7538+ inode->i_vflags |= V_BARRIER;
7539+ else
7540+ inode->i_vflags &= ~V_BARRIER;
7541+ if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7542+ inode->i_vflags |= V_COW;
7543+ else
7544+ inode->i_vflags &= ~V_COW;
7545 }
7546
7547 /*
7548@@ -1153,6 +1169,7 @@ xfs_setup_inode(
7549 set_nlink(inode, ip->i_d.di_nlink);
7550 inode->i_uid = ip->i_d.di_uid;
7551 inode->i_gid = ip->i_d.di_gid;
7552+ inode->i_tag = ip->i_d.di_tag;
7553
7554 switch (inode->i_mode & S_IFMT) {
7555 case S_IFBLK:
7556diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_itable.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_itable.c
7557--- linux-3.6.6/fs/xfs/xfs_itable.c 2012-10-04 15:27:44.000000000 +0200
7558+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_itable.c 2012-10-04 18:47:00.000000000 +0200
7559@@ -96,6 +96,7 @@ xfs_bulkstat_one_int(
7560 buf->bs_mode = dic->di_mode;
7561 buf->bs_uid = dic->di_uid;
7562 buf->bs_gid = dic->di_gid;
7563+ buf->bs_tag = dic->di_tag;
7564 buf->bs_size = dic->di_size;
7565 buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7566 buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7567diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_linux.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_linux.h
7568--- linux-3.6.6/fs/xfs/xfs_linux.h 2011-10-24 18:45:31.000000000 +0200
7569+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_linux.h 2012-10-04 18:47:00.000000000 +0200
7570@@ -121,6 +121,7 @@
7571
7572 #define current_cpu() (raw_smp_processor_id())
7573 #define current_pid() (current->pid)
7574+#define current_fstag(vp) (dx_current_fstag((vp)->i_sb))
7575 #define current_test_flags(f) (current->flags & (f))
7576 #define current_set_flags_nested(sp, f) \
7577 (*(sp) = current->flags, current->flags |= (f))
7578diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_log_recover.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_log_recover.c
7579--- linux-3.6.6/fs/xfs/xfs_log_recover.c 2012-10-04 15:27:44.000000000 +0200
7580+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_log_recover.c 2012-10-04 18:47:00.000000000 +0200
7581@@ -2359,7 +2359,8 @@ xlog_recover_inode_pass2(
7582 }
7583
7584 /* The core is in in-core format */
7585- xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7586+ xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7587+ mp->m_flags & XFS_MOUNT_TAGGED);
7588
7589 /* the rest is in on-disk format */
7590 if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7591diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_mount.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_mount.h
7592--- linux-3.6.6/fs/xfs/xfs_mount.h 2012-10-04 15:27:44.000000000 +0200
7593+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_mount.h 2012-10-04 18:47:00.000000000 +0200
7594@@ -251,6 +251,7 @@ typedef struct xfs_mount {
7595 allocator */
7596 #define XFS_MOUNT_NOATTR2 (1ULL << 25) /* disable use of attr2 format */
7597
7598+#define XFS_MOUNT_TAGGED (1ULL << 31) /* context tagging */
7599
7600 /*
7601 * Default minimum read and write sizes.
7602diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_super.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_super.c
7603--- linux-3.6.6/fs/xfs/xfs_super.c 2012-10-04 15:27:44.000000000 +0200
7604+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_super.c 2012-10-04 18:47:00.000000000 +0200
7605@@ -112,6 +112,9 @@ mempool_t *xfs_ioend_pool;
7606 #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
7607 #define MNTOPT_DISCARD "discard" /* Discard unused blocks */
7608 #define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
7609+#define MNTOPT_TAGXID "tagxid" /* context tagging for inodes */
7610+#define MNTOPT_TAGGED "tag" /* context tagging for inodes */
7611+#define MNTOPT_NOTAGTAG "notag" /* do not use context tagging */
7612
7613 /*
7614 * Table driven mount option parser.
7615@@ -120,10 +123,14 @@ mempool_t *xfs_ioend_pool;
7616 * in the future, too.
7617 */
7618 enum {
7619+ Opt_tag, Opt_notag,
7620 Opt_barrier, Opt_nobarrier, Opt_err
7621 };
7622
7623 static const match_table_t tokens = {
7624+ {Opt_tag, "tagxid"},
7625+ {Opt_tag, "tag"},
7626+ {Opt_notag, "notag"},
7627 {Opt_barrier, "barrier"},
7628 {Opt_nobarrier, "nobarrier"},
7629 {Opt_err, NULL}
7630@@ -371,6 +378,19 @@ xfs_parseargs(
7631 } else if (!strcmp(this_char, "irixsgid")) {
7632 xfs_warn(mp,
7633 "irixsgid is now a sysctl(2) variable, option is deprecated.");
7634+#ifndef CONFIG_TAGGING_NONE
7635+ } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7636+ mp->m_flags |= XFS_MOUNT_TAGGED;
7637+ } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7638+ mp->m_flags &= ~XFS_MOUNT_TAGGED;
7639+ } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7640+ mp->m_flags |= XFS_MOUNT_TAGGED;
7641+#endif
7642+#ifdef CONFIG_PROPAGATE
7643+ } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7644+ /* use value */
7645+ mp->m_flags |= XFS_MOUNT_TAGGED;
7646+#endif
7647 } else {
7648 xfs_warn(mp, "unknown mount option [%s].", this_char);
7649 return EINVAL;
7650@@ -1056,6 +1076,16 @@ xfs_fs_remount(
7651 case Opt_nobarrier:
7652 mp->m_flags &= ~XFS_MOUNT_BARRIER;
7653 break;
7654+ case Opt_tag:
7655+ if (!(sb->s_flags & MS_TAGGED)) {
7656+ printk(KERN_INFO
7657+ "XFS: %s: tagging not permitted on remount.\n",
7658+ sb->s_id);
7659+ return -EINVAL;
7660+ }
7661+ break;
7662+ case Opt_notag:
7663+ break;
7664 default:
7665 /*
7666 * Logically we would return an error here to prevent
7667@@ -1275,6 +1305,9 @@ xfs_fs_fill_super(
7668 if (error)
7669 goto out_free_sb;
7670
7671+ if (mp->m_flags & XFS_MOUNT_TAGGED)
7672+ sb->s_flags |= MS_TAGGED;
7673+
7674 /*
7675 * we must configure the block size in the superblock before we run the
7676 * full mount process as the mount process can lookup and cache inodes.
7677diff -NurpP --minimal linux-3.6.6/fs/xfs/xfs_vnodeops.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_vnodeops.c
7678--- linux-3.6.6/fs/xfs/xfs_vnodeops.c 2012-10-04 15:27:44.000000000 +0200
7679+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/fs/xfs/xfs_vnodeops.c 2012-10-04 18:47:00.000000000 +0200
7680@@ -103,6 +103,77 @@ xfs_readlink_bmap(
7681 return error;
7682 }
7683
7684+
7685+STATIC void
7686+xfs_get_inode_flags(
7687+ xfs_inode_t *ip)
7688+{
7689+ struct inode *inode = VFS_I(ip);
7690+ unsigned int flags = inode->i_flags;
7691+ unsigned int vflags = inode->i_vflags;
7692+
7693+ if (flags & S_IMMUTABLE)
7694+ ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7695+ else
7696+ ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7697+ if (flags & S_IXUNLINK)
7698+ ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7699+ else
7700+ ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7701+
7702+ if (vflags & V_BARRIER)
7703+ ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7704+ else
7705+ ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7706+ if (vflags & V_COW)
7707+ ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7708+ else
7709+ ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7710+}
7711+
7712+int
7713+xfs_sync_flags(
7714+ struct inode *inode,
7715+ int flags,
7716+ int vflags)
7717+{
7718+ struct xfs_inode *ip = XFS_I(inode);
7719+ struct xfs_mount *mp = ip->i_mount;
7720+ struct xfs_trans *tp;
7721+ unsigned int lock_flags = 0;
7722+ int code;
7723+
7724+ tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7725+ code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7726+ if (code)
7727+ goto error_out;
7728+
7729+ xfs_ilock(ip, XFS_ILOCK_EXCL);
7730+ xfs_trans_ijoin(tp, ip, 0);
7731+
7732+ inode->i_flags = flags;
7733+ inode->i_vflags = vflags;
7734+ xfs_get_inode_flags(ip);
7735+
7736+ xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7737+ xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7738+
7739+ XFS_STATS_INC(xs_ig_attrchg);
7740+
7741+ if (mp->m_flags & XFS_MOUNT_WSYNC)
7742+ xfs_trans_set_sync(tp);
7743+ code = xfs_trans_commit(tp, 0);
7744+ xfs_iunlock(ip, XFS_ILOCK_EXCL);
7745+ return code;
7746+
7747+error_out:
7748+ xfs_trans_cancel(tp, 0);
7749+ if (lock_flags)
7750+ xfs_iunlock(ip, XFS_ILOCK_EXCL);
7751+ return code;
7752+}
7753+
7754+
7755 int
7756 xfs_readlink(
7757 xfs_inode_t *ip,
7758diff -NurpP --minimal linux-3.6.6/include/linux/Kbuild linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/Kbuild
7759--- linux-3.6.6/include/linux/Kbuild 2012-10-04 15:27:45.000000000 +0200
7760+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/Kbuild 2012-10-04 18:47:00.000000000 +0200
7761@@ -18,6 +18,7 @@ header-y += netfilter_bridge/
7762 header-y += netfilter_ipv4/
7763 header-y += netfilter_ipv6/
7764 header-y += usb/
7765+header-y += vserver/
7766 header-y += wimax/
7767
7768 objhdr-y += version.h
7769diff -NurpP --minimal linux-3.6.6/include/linux/capability.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/capability.h
7770--- linux-3.6.6/include/linux/capability.h 2012-07-22 23:39:43.000000000 +0200
7771+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/capability.h 2012-10-04 18:47:00.000000000 +0200
7772@@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
7773 arbitrary SCSI commands */
7774 /* Allow setting encryption key on loopback filesystem */
7775 /* Allow setting zone reclaim policy */
7776+/* Allow the selection of a security context */
7777
7778 #define CAP_SYS_ADMIN 21
7779
7780@@ -366,7 +367,12 @@ struct cpu_vfs_cap_data {
7781
7782 #define CAP_LAST_CAP CAP_BLOCK_SUSPEND
7783
7784-#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
7785+/* Allow context manipulations */
7786+/* Allow changing context info on files */
7787+
7788+#define CAP_CONTEXT 63
7789+
7790+#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
7791
7792 /*
7793 * Bit location of each capability (used by user-space library and kernel)
7794diff -NurpP --minimal linux-3.6.6/include/linux/cred.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/cred.h
7795--- linux-3.6.6/include/linux/cred.h 2012-07-22 23:39:43.000000000 +0200
7796+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/cred.h 2012-10-04 18:47:00.000000000 +0200
7797@@ -157,6 +157,7 @@ extern void exit_creds(struct task_struc
7798 extern int copy_creds(struct task_struct *, unsigned long);
7799 extern const struct cred *get_task_cred(struct task_struct *);
7800 extern struct cred *cred_alloc_blank(void);
7801+extern struct cred *__prepare_creds(const struct cred *);
7802 extern struct cred *prepare_creds(void);
7803 extern struct cred *prepare_exec_creds(void);
7804 extern int commit_creds(struct cred *);
7805@@ -210,6 +211,31 @@ static inline void validate_process_cred
7806 }
7807 #endif
7808
7809+static inline void set_cred_subscribers(struct cred *cred, int n)
7810+{
7811+#ifdef CONFIG_DEBUG_CREDENTIALS
7812+ atomic_set(&cred->subscribers, n);
7813+#endif
7814+}
7815+
7816+static inline int read_cred_subscribers(const struct cred *cred)
7817+{
7818+#ifdef CONFIG_DEBUG_CREDENTIALS
7819+ return atomic_read(&cred->subscribers);
7820+#else
7821+ return 0;
7822+#endif
7823+}
7824+
7825+static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7826+{
7827+#ifdef CONFIG_DEBUG_CREDENTIALS
7828+ struct cred *cred = (struct cred *) _cred;
7829+
7830+ atomic_add(n, &cred->subscribers);
7831+#endif
7832+}
7833+
7834 /**
7835 * get_new_cred - Get a reference on a new set of credentials
7836 * @cred: The new credentials to reference
7837diff -NurpP --minimal linux-3.6.6/include/linux/devpts_fs.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/devpts_fs.h
7838--- linux-3.6.6/include/linux/devpts_fs.h 2008-12-25 00:26:37.000000000 +0100
7839+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/devpts_fs.h 2012-10-04 18:47:00.000000000 +0200
7840@@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7841
7842 #endif
7843
7844-
7845 #endif /* _LINUX_DEVPTS_FS_H */
7846diff -NurpP --minimal linux-3.6.6/include/linux/fs.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/fs.h
7847--- linux-3.6.6/include/linux/fs.h 2012-10-04 15:27:45.000000000 +0200
7848+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/fs.h 2012-10-04 18:47:00.000000000 +0200
7849@@ -225,6 +225,9 @@ struct inodes_stat_t {
7850 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
7851 #define MS_I_VERSION (1<<23) /* Update inode I_version field */
7852 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
7853+#define MS_TAGGED (1<<25) /* use generic inode tagging */
7854+#define MS_TAGID (1<<26) /* use specific tag for this mount */
7855+#define MS_NOTAGCHECK (1<<27) /* don't check tags */
7856 #define MS_NOSEC (1<<28)
7857 #define MS_BORN (1<<29)
7858 #define MS_ACTIVE (1<<30)
7859@@ -256,6 +259,14 @@ struct inodes_stat_t {
7860 #define S_IMA 1024 /* Inode has an associated IMA struct */
7861 #define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
7862 #define S_NOSEC 4096 /* no suid or xattr security attributes */
7863+#define S_IXUNLINK 8192 /* Immutable Invert on unlink */
7864+
7865+/* Linux-VServer related Inode flags */
7866+
7867+#define V_VALID 1
7868+#define V_XATTR 2
7869+#define V_BARRIER 4 /* Barrier for chroot() */
7870+#define V_COW 8 /* Copy on Write */
7871
7872 /*
7873 * Note that nosuid etc flags are inode-specific: setting some file-system
7874@@ -278,12 +289,15 @@ struct inodes_stat_t {
7875 #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
7876 ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
7877 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
7878-#define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7879-#define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
7880+#define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7881+#define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
7882+#define IS_TAGGED(inode) __IS_FLG(inode, MS_TAGGED)
7883
7884 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
7885 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
7886 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
7887+#define IS_IXUNLINK(inode) ((inode)->i_flags & S_IXUNLINK)
7888+#define IS_IXORUNLINK(inode) ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7889 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
7890
7891 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
7892@@ -294,6 +308,16 @@ struct inodes_stat_t {
7893 #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
7894 #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
7895
7896+#define IS_BARRIER(inode) (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7897+
7898+#ifdef CONFIG_VSERVER_COWBL
7899+# define IS_COW(inode) (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7900+# define IS_COW_LINK(inode) (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7901+#else
7902+# define IS_COW(inode) (0)
7903+# define IS_COW_LINK(inode) (0)
7904+#endif
7905+
7906 /* the read-only stuff doesn't really belong here, but any other place is
7907 probably as bad and I don't want to create yet another include file. */
7908
7909@@ -380,11 +404,14 @@ struct inodes_stat_t {
7910 #define FS_EXTENT_FL 0x00080000 /* Extents */
7911 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
7912 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
7913+#define FS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
7914 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
7915
7916-#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
7917-#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
7918+#define FS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
7919+#define FS_COW_FL 0x20000000 /* Copy on Write marker */
7920
7921+#define FS_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
7922+#define FS_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
7923
7924 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
7925 #define SYNC_FILE_RANGE_WRITE 2
7926@@ -472,6 +499,7 @@ typedef void (dio_iodone_t)(struct kiocb
7927 #define ATTR_KILL_PRIV (1 << 14)
7928 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
7929 #define ATTR_TIMES_SET (1 << 16)
7930+#define ATTR_TAG (1 << 17)
7931
7932 /*
7933 * This is the Inode Attributes structure, used for notify_change(). It
7934@@ -487,6 +515,7 @@ struct iattr {
7935 umode_t ia_mode;
7936 kuid_t ia_uid;
7937 kgid_t ia_gid;
7938+ tag_t ia_tag;
7939 loff_t ia_size;
7940 struct timespec ia_atime;
7941 struct timespec ia_mtime;
7942@@ -500,6 +529,9 @@ struct iattr {
7943 struct file *ia_file;
7944 };
7945
7946+#define ATTR_FLAG_BARRIER 512 /* Barrier for chroot() */
7947+#define ATTR_FLAG_IXUNLINK 1024 /* Immutable invert on unlink */
7948+
7949 /*
7950 * Includes for diskquotas.
7951 */
7952@@ -784,7 +816,9 @@ struct inode {
7953 unsigned short i_opflags;
7954 kuid_t i_uid;
7955 kgid_t i_gid;
7956- unsigned int i_flags;
7957+ tag_t i_tag;
7958+ unsigned short i_flags;
7959+ unsigned short i_vflags;
7960
7961 #ifdef CONFIG_FS_POSIX_ACL
7962 struct posix_acl *i_acl;
7963@@ -813,6 +847,7 @@ struct inode {
7964 unsigned int __i_nlink;
7965 };
7966 dev_t i_rdev;
7967+ dev_t i_mdev;
7968 loff_t i_size;
7969 struct timespec i_atime;
7970 struct timespec i_mtime;
7971@@ -975,12 +1010,12 @@ static inline void i_gid_write(struct in
7972
7973 static inline unsigned iminor(const struct inode *inode)
7974 {
7975- return MINOR(inode->i_rdev);
7976+ return MINOR(inode->i_mdev);
7977 }
7978
7979 static inline unsigned imajor(const struct inode *inode)
7980 {
7981- return MAJOR(inode->i_rdev);
7982+ return MAJOR(inode->i_mdev);
7983 }
7984
7985 extern struct block_device *I_BDEV(struct inode *inode);
7986@@ -1047,6 +1082,7 @@ struct file {
7987 loff_t f_pos;
7988 struct fown_struct f_owner;
7989 const struct cred *f_cred;
7990+ xid_t f_xid;
7991 struct file_ra_state f_ra;
7992
7993 u64 f_version;
7994@@ -1194,6 +1230,7 @@ struct file_lock {
7995 struct file *fl_file;
7996 loff_t fl_start;
7997 loff_t fl_end;
7998+ xid_t fl_xid;
7999
8000 struct fasync_struct * fl_fasync; /* for lease break notifications */
8001 /* for lease breaks: */
8002@@ -1829,6 +1866,7 @@ struct inode_operations {
8003 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8004 ssize_t (*listxattr) (struct dentry *, char *, size_t);
8005 int (*removexattr) (struct dentry *, const char *);
8006+ int (*sync_flags) (struct inode *, int, int);
8007 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8008 u64 len);
8009 int (*update_time)(struct inode *, struct timespec *, int);
8010@@ -1850,6 +1888,7 @@ extern ssize_t vfs_readv(struct file *,
8011 unsigned long, loff_t *);
8012 extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8013 unsigned long, loff_t *);
8014+ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8015
8016 struct super_operations {
8017 struct inode *(*alloc_inode)(struct super_block *sb);
8018@@ -2692,6 +2731,7 @@ extern int dcache_dir_open(struct inode
8019 extern int dcache_dir_close(struct inode *, struct file *);
8020 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8021 extern int dcache_readdir(struct file *, void *, filldir_t);
8022+extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8023 extern int simple_setattr(struct dentry *, struct iattr *);
8024 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8025 extern int simple_statfs(struct dentry *, struct kstatfs *);
8026diff -NurpP --minimal linux-3.6.6/include/linux/gfs2_ondisk.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/gfs2_ondisk.h
8027--- linux-3.6.6/include/linux/gfs2_ondisk.h 2012-10-04 15:27:45.000000000 +0200
8028+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/gfs2_ondisk.h 2012-10-04 18:54:29.000000000 +0200
8029@@ -225,6 +225,9 @@ enum {
8030 gfs2fl_Sync = 8,
8031 gfs2fl_System = 9,
8032 gfs2fl_TopLevel = 10,
8033+ gfs2fl_IXUnlink = 16,
8034+ gfs2fl_Barrier = 17,
8035+ gfs2fl_Cow = 18,
8036 gfs2fl_TruncInProg = 29,
8037 gfs2fl_InheritDirectio = 30,
8038 gfs2fl_InheritJdata = 31,
8039@@ -242,6 +245,9 @@ enum {
8040 #define GFS2_DIF_SYNC 0x00000100
8041 #define GFS2_DIF_SYSTEM 0x00000200 /* New in gfs2 */
8042 #define GFS2_DIF_TOPDIR 0x00000400 /* New in gfs2 */
8043+#define GFS2_DIF_IXUNLINK 0x00010000
8044+#define GFS2_DIF_BARRIER 0x00020000
8045+#define GFS2_DIF_COW 0x00040000
8046 #define GFS2_DIF_TRUNC_IN_PROG 0x20000000 /* New in gfs2 */
8047 #define GFS2_DIF_INHERIT_DIRECTIO 0x40000000 /* only in gfs1 */
8048 #define GFS2_DIF_INHERIT_JDATA 0x80000000
8049diff -NurpP --minimal linux-3.6.6/include/linux/if_tun.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/if_tun.h
8050--- linux-3.6.6/include/linux/if_tun.h 2010-08-02 16:52:54.000000000 +0200
8051+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/if_tun.h 2012-10-04 18:47:00.000000000 +0200
8052@@ -53,6 +53,7 @@
8053 #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8054 #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8055 #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8056+#define TUNSETNID _IOW('T', 217, int)
8057
8058 /* TUNSETIFF ifr flags */
8059 #define IFF_TUN 0x0001
8060diff -NurpP --minimal linux-3.6.6/include/linux/init_task.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/init_task.h
8061--- linux-3.6.6/include/linux/init_task.h 2012-10-04 15:27:45.000000000 +0200
8062+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/init_task.h 2012-10-04 18:47:00.000000000 +0200
8063@@ -210,6 +210,10 @@ extern struct task_group root_task_group
8064 INIT_TRACE_RECURSION \
8065 INIT_TASK_RCU_PREEMPT(tsk) \
8066 INIT_CPUSET_SEQ \
8067+ .xid = 0, \
8068+ .vx_info = NULL, \
8069+ .nid = 0, \
8070+ .nx_info = NULL, \
8071 }
8072
8073
8074diff -NurpP --minimal linux-3.6.6/include/linux/ipc.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/ipc.h
8075--- linux-3.6.6/include/linux/ipc.h 2012-03-19 19:47:28.000000000 +0100
8076+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/ipc.h 2012-10-04 18:47:00.000000000 +0200
8077@@ -91,6 +91,7 @@ struct kern_ipc_perm
8078 key_t key;
8079 uid_t uid;
8080 gid_t gid;
8081+ xid_t xid;
8082 uid_t cuid;
8083 gid_t cgid;
8084 umode_t mode;
8085diff -NurpP --minimal linux-3.6.6/include/linux/ipc_namespace.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/ipc_namespace.h
8086--- linux-3.6.6/include/linux/ipc_namespace.h 2012-07-22 23:39:43.000000000 +0200
8087+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/ipc_namespace.h 2012-10-04 18:47:00.000000000 +0200
8088@@ -133,7 +133,8 @@ static inline int mq_init_ns(struct ipc_
8089
8090 #if defined(CONFIG_IPC_NS)
8091 extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8092- struct task_struct *tsk);
8093+ struct ipc_namespace *old_ns,
8094+ struct user_namespace *user_ns);
8095 static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8096 {
8097 if (ns)
8098@@ -144,12 +145,13 @@ static inline struct ipc_namespace *get_
8099 extern void put_ipc_ns(struct ipc_namespace *ns);
8100 #else
8101 static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8102- struct task_struct *tsk)
8103+ struct ipc_namespace *old_ns,
8104+ struct user_namespace *user_ns)
8105 {
8106 if (flags & CLONE_NEWIPC)
8107 return ERR_PTR(-EINVAL);
8108
8109- return tsk->nsproxy->ipc_ns;
8110+ return old_ns;
8111 }
8112
8113 static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8114diff -NurpP --minimal linux-3.6.6/include/linux/loop.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/loop.h
8115--- linux-3.6.6/include/linux/loop.h 2012-01-09 16:14:58.000000000 +0100
8116+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/loop.h 2012-10-04 18:47:00.000000000 +0200
8117@@ -45,6 +45,7 @@ struct loop_device {
8118 struct loop_func_table *lo_encryption;
8119 __u32 lo_init[2];
8120 uid_t lo_key_owner; /* Who set the key */
8121+ xid_t lo_xid;
8122 int (*ioctl)(struct loop_device *, int cmd,
8123 unsigned long arg);
8124
8125diff -NurpP --minimal linux-3.6.6/include/linux/magic.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/magic.h
8126--- linux-3.6.6/include/linux/magic.h 2012-05-21 18:07:31.000000000 +0200
8127+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/magic.h 2012-10-04 18:47:00.000000000 +0200
8128@@ -3,7 +3,7 @@
8129
8130 #define ADFS_SUPER_MAGIC 0xadf5
8131 #define AFFS_SUPER_MAGIC 0xadff
8132-#define AFS_SUPER_MAGIC 0x5346414F
8133+#define AFS_SUPER_MAGIC 0x5346414F
8134 #define AUTOFS_SUPER_MAGIC 0x0187
8135 #define CODA_SUPER_MAGIC 0x73757245
8136 #define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
8137diff -NurpP --minimal linux-3.6.6/include/linux/major.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/major.h
8138--- linux-3.6.6/include/linux/major.h 2009-09-10 15:26:25.000000000 +0200
8139+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/major.h 2012-10-04 18:47:00.000000000 +0200
8140@@ -15,6 +15,7 @@
8141 #define HD_MAJOR IDE0_MAJOR
8142 #define PTY_SLAVE_MAJOR 3
8143 #define TTY_MAJOR 4
8144+#define VROOT_MAJOR 4
8145 #define TTYAUX_MAJOR 5
8146 #define LP_MAJOR 6
8147 #define VCS_MAJOR 7
8148diff -NurpP --minimal linux-3.6.6/include/linux/memcontrol.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/memcontrol.h
8149--- linux-3.6.6/include/linux/memcontrol.h 2012-10-04 15:27:45.000000000 +0200
8150+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/memcontrol.h 2012-10-04 18:47:00.000000000 +0200
8151@@ -83,6 +83,13 @@ extern struct mem_cgroup *try_get_mem_cg
8152 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
8153 extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
8154
8155+extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8156+extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8157+
8158+extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8159+extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8160+extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8161+
8162 static inline
8163 int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8164 {
8165diff -NurpP --minimal linux-3.6.6/include/linux/mm_types.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/mm_types.h
8166--- linux-3.6.6/include/linux/mm_types.h 2012-10-04 15:27:46.000000000 +0200
8167+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/mm_types.h 2012-10-04 18:47:00.000000000 +0200
8168@@ -370,6 +370,7 @@ struct mm_struct {
8169
8170 /* Architecture-specific MM context */
8171 mm_context_t context;
8172+ struct vx_info *mm_vx_info;
8173
8174 unsigned long flags; /* Must use atomic bitops to access the bits */
8175
8176diff -NurpP --minimal linux-3.6.6/include/linux/mmzone.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/mmzone.h
8177--- linux-3.6.6/include/linux/mmzone.h 2012-10-04 15:27:46.000000000 +0200
8178+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/mmzone.h 2012-10-04 18:47:00.000000000 +0200
8179@@ -727,6 +727,13 @@ typedef struct pglist_data {
8180 __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8181 })
8182
8183+#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
8184+
8185+#define node_end_pfn(nid) ({\
8186+ pg_data_t *__pgdat = NODE_DATA(nid);\
8187+ __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8188+})
8189+
8190 #include <linux/memory_hotplug.h>
8191
8192 extern struct mutex zonelists_mutex;
8193diff -NurpP --minimal linux-3.6.6/include/linux/mount.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/mount.h
8194--- linux-3.6.6/include/linux/mount.h 2012-03-19 19:47:28.000000000 +0100
8195+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/mount.h 2012-10-04 18:47:00.000000000 +0200
8196@@ -47,6 +47,9 @@ struct mnt_namespace;
8197
8198 #define MNT_INTERNAL 0x4000
8199
8200+#define MNT_TAGID 0x10000
8201+#define MNT_NOTAG 0x20000
8202+
8203 struct vfsmount {
8204 struct dentry *mnt_root; /* root of the mounted tree */
8205 struct super_block *mnt_sb; /* pointer to superblock */
8206diff -NurpP --minimal linux-3.6.6/include/linux/net.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/net.h
8207--- linux-3.6.6/include/linux/net.h 2012-10-04 15:27:46.000000000 +0200
8208+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/net.h 2012-10-04 18:47:00.000000000 +0200
8209@@ -73,6 +73,7 @@ struct net;
8210 #define SOCK_PASSCRED 3
8211 #define SOCK_PASSSEC 4
8212 #define SOCK_EXTERNALLY_ALLOCATED 5
8213+#define SOCK_USER_SOCKET 6
8214
8215 #ifndef ARCH_HAS_SOCKET_TYPES
8216 /**
8217diff -NurpP --minimal linux-3.6.6/include/linux/netdevice.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/netdevice.h
8218--- linux-3.6.6/include/linux/netdevice.h 2012-10-04 15:27:46.000000000 +0200
8219+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/netdevice.h 2012-10-04 18:47:00.000000000 +0200
8220@@ -1651,6 +1651,7 @@ extern void netdev_resync_ops(struct ne
8221
8222 extern struct net_device *dev_get_by_index(struct net *net, int ifindex);
8223 extern struct net_device *__dev_get_by_index(struct net *net, int ifindex);
8224+extern struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8225 extern struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
8226 extern int dev_restart(struct net_device *dev);
8227 #ifdef CONFIG_NETPOLL_TRAP
8228diff -NurpP --minimal linux-3.6.6/include/linux/nfs_mount.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/nfs_mount.h
8229--- linux-3.6.6/include/linux/nfs_mount.h 2011-01-05 21:50:31.000000000 +0100
8230+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/nfs_mount.h 2012-10-04 18:47:00.000000000 +0200
8231@@ -63,7 +63,8 @@ struct nfs_mount_data {
8232 #define NFS_MOUNT_SECFLAVOUR 0x2000 /* 5 */
8233 #define NFS_MOUNT_NORDIRPLUS 0x4000 /* 5 */
8234 #define NFS_MOUNT_UNSHARED 0x8000 /* 5 */
8235-#define NFS_MOUNT_FLAGMASK 0xFFFF
8236+#define NFS_MOUNT_TAGGED 0x10000 /* context tagging */
8237+#define NFS_MOUNT_FLAGMASK 0x1FFFF
8238
8239 /* The following are for internal use only */
8240 #define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000
8241diff -NurpP --minimal linux-3.6.6/include/linux/nsproxy.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/nsproxy.h
8242--- linux-3.6.6/include/linux/nsproxy.h 2011-10-24 18:45:32.000000000 +0200
8243+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/nsproxy.h 2012-10-04 18:47:00.000000000 +0200
8244@@ -3,6 +3,7 @@
8245
8246 #include <linux/spinlock.h>
8247 #include <linux/sched.h>
8248+#include <linux/vserver/debug.h>
8249
8250 struct mnt_namespace;
8251 struct uts_namespace;
8252@@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8253 }
8254
8255 int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8256+struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8257 void exit_task_namespaces(struct task_struct *tsk);
8258 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8259 void free_nsproxy(struct nsproxy *ns);
8260@@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
8261 struct fs_struct *);
8262 int __init nsproxy_cache_init(void);
8263
8264-static inline void put_nsproxy(struct nsproxy *ns)
8265+#define get_nsproxy(n) __get_nsproxy(n, __FILE__, __LINE__)
8266+
8267+static inline void __get_nsproxy(struct nsproxy *ns,
8268+ const char *_file, int _line)
8269 {
8270- if (atomic_dec_and_test(&ns->count)) {
8271- free_nsproxy(ns);
8272- }
8273+ vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8274+ ns, atomic_read(&ns->count), _file, _line);
8275+ atomic_inc(&ns->count);
8276 }
8277
8278-static inline void get_nsproxy(struct nsproxy *ns)
8279+#define put_nsproxy(n) __put_nsproxy(n, __FILE__, __LINE__)
8280+
8281+static inline void __put_nsproxy(struct nsproxy *ns,
8282+ const char *_file, int _line)
8283 {
8284- atomic_inc(&ns->count);
8285+ vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8286+ ns, atomic_read(&ns->count), _file, _line);
8287+ if (atomic_dec_and_test(&ns->count)) {
8288+ free_nsproxy(ns);
8289+ }
8290 }
8291
8292 #endif
8293diff -NurpP --minimal linux-3.6.6/include/linux/pid.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/pid.h
8294--- linux-3.6.6/include/linux/pid.h 2011-07-22 11:18:11.000000000 +0200
8295+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/pid.h 2012-10-04 18:47:00.000000000 +0200
8296@@ -8,7 +8,8 @@ enum pid_type
8297 PIDTYPE_PID,
8298 PIDTYPE_PGID,
8299 PIDTYPE_SID,
8300- PIDTYPE_MAX
8301+ PIDTYPE_MAX,
8302+ PIDTYPE_REALPID
8303 };
8304
8305 /*
8306@@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8307 }
8308
8309 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8310+pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8311 pid_t pid_vnr(struct pid *pid);
8312
8313 #define do_each_pid_task(pid, type, task) \
8314diff -NurpP --minimal linux-3.6.6/include/linux/proc_fs.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/proc_fs.h
8315--- linux-3.6.6/include/linux/proc_fs.h 2012-07-22 23:39:44.000000000 +0200
8316+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/proc_fs.h 2012-10-04 18:47:00.000000000 +0200
8317@@ -54,6 +54,7 @@ struct proc_dir_entry {
8318 nlink_t nlink;
8319 kuid_t uid;
8320 kgid_t gid;
8321+ int vx_flags;
8322 loff_t size;
8323 const struct inode_operations *proc_iops;
8324 /*
8325@@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8326 extern const struct proc_ns_operations utsns_operations;
8327 extern const struct proc_ns_operations ipcns_operations;
8328
8329+struct vx_info;
8330+struct nx_info;
8331+
8332 union proc_op {
8333 int (*proc_get_link)(struct dentry *, struct path *);
8334 int (*proc_read)(struct task_struct *task, char *page);
8335 int (*proc_show)(struct seq_file *m,
8336 struct pid_namespace *ns, struct pid *pid,
8337 struct task_struct *task);
8338+ int (*proc_vs_read)(char *page);
8339+ int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8340+ int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8341 };
8342
8343 struct ctl_table_header;
8344@@ -265,6 +272,7 @@ struct ctl_table;
8345
8346 struct proc_inode {
8347 struct pid *pid;
8348+ int vx_flags;
8349 int fd;
8350 union proc_op op;
8351 struct proc_dir_entry *pde;
8352diff -NurpP --minimal linux-3.6.6/include/linux/quotaops.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/quotaops.h
8353--- linux-3.6.6/include/linux/quotaops.h 2012-10-04 15:27:46.000000000 +0200
8354+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/quotaops.h 2012-10-04 18:47:00.000000000 +0200
8355@@ -8,6 +8,7 @@
8356 #define _LINUX_QUOTAOPS_
8357
8358 #include <linux/fs.h>
8359+#include <linux/vs_dlimit.h>
8360
8361 #define DQUOT_SPACE_WARN 0x1
8362 #define DQUOT_SPACE_RESERVE 0x2
8363@@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8364
8365 static inline int dquot_alloc_inode(const struct inode *inode)
8366 {
8367- return 0;
8368+ return dl_alloc_inode(inode);
8369 }
8370
8371 static inline void dquot_free_inode(const struct inode *inode)
8372 {
8373+ dl_free_inode(inode);
8374 }
8375
8376 static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8377@@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8378 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8379 int flags)
8380 {
8381+ int ret = 0;
8382+
8383+ if ((ret = dl_alloc_space(inode, number)))
8384+ return ret;
8385 if (!(flags & DQUOT_SPACE_RESERVE))
8386 inode_add_bytes(inode, number);
8387 return 0;
8388@@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8389 {
8390 if (!(flags & DQUOT_SPACE_RESERVE))
8391 inode_sub_bytes(inode, number);
8392+ dl_free_space(inode, number);
8393 }
8394
8395 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8396diff -NurpP --minimal linux-3.6.6/include/linux/reboot.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/reboot.h
8397--- linux-3.6.6/include/linux/reboot.h 2011-10-24 18:45:32.000000000 +0200
8398+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/reboot.h 2012-10-04 18:47:00.000000000 +0200
8399@@ -33,6 +33,7 @@
8400 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
8401 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
8402 #define LINUX_REBOOT_CMD_KEXEC 0x45584543
8403+#define LINUX_REBOOT_CMD_OOM 0xDEADBEEF
8404
8405
8406 #ifdef __KERNEL__
8407diff -NurpP --minimal linux-3.6.6/include/linux/sched.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sched.h
8408--- linux-3.6.6/include/linux/sched.h 2012-10-04 15:27:46.000000000 +0200
8409+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sched.h 2012-10-04 18:47:00.000000000 +0200
8410@@ -1422,6 +1422,14 @@ struct task_struct {
8411 #endif
8412 struct seccomp seccomp;
8413
8414+/* vserver context data */
8415+ struct vx_info *vx_info;
8416+ struct nx_info *nx_info;
8417+
8418+ xid_t xid;
8419+ nid_t nid;
8420+ tag_t tag;
8421+
8422 /* Thread group tracking */
8423 u32 parent_exec_id;
8424 u32 self_exec_id;
8425@@ -1668,6 +1676,11 @@ struct pid_namespace;
8426 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8427 struct pid_namespace *ns);
8428
8429+#include <linux/vserver/base.h>
8430+#include <linux/vserver/context.h>
8431+#include <linux/vserver/debug.h>
8432+#include <linux/vserver/pid.h>
8433+
8434 static inline pid_t task_pid_nr(struct task_struct *tsk)
8435 {
8436 return tsk->pid;
8437@@ -1681,7 +1694,8 @@ static inline pid_t task_pid_nr_ns(struc
8438
8439 static inline pid_t task_pid_vnr(struct task_struct *tsk)
8440 {
8441- return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8442+ // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8443+ return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8444 }
8445
8446
8447@@ -1694,7 +1708,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8448
8449 static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8450 {
8451- return pid_vnr(task_tgid(tsk));
8452+ return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8453 }
8454
8455
8456diff -NurpP --minimal linux-3.6.6/include/linux/shmem_fs.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/shmem_fs.h
8457--- linux-3.6.6/include/linux/shmem_fs.h 2012-07-22 23:39:44.000000000 +0200
8458+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/shmem_fs.h 2012-10-04 18:47:00.000000000 +0200
8459@@ -8,6 +8,9 @@
8460
8461 /* inode in-kernel data */
8462
8463+#define TMPFS_SUPER_MAGIC 0x01021994
8464+
8465+
8466 struct shmem_inode_info {
8467 spinlock_t lock;
8468 unsigned long flags;
8469diff -NurpP --minimal linux-3.6.6/include/linux/stat.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/stat.h
8470--- linux-3.6.6/include/linux/stat.h 2012-07-22 23:39:44.000000000 +0200
8471+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/stat.h 2012-10-04 18:47:00.000000000 +0200
8472@@ -67,6 +67,7 @@ struct kstat {
8473 unsigned int nlink;
8474 kuid_t uid;
8475 kgid_t gid;
8476+ tag_t tag;
8477 dev_t rdev;
8478 loff_t size;
8479 struct timespec atime;
8480diff -NurpP --minimal linux-3.6.6/include/linux/sunrpc/auth.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sunrpc/auth.h
8481--- linux-3.6.6/include/linux/sunrpc/auth.h 2012-10-04 15:27:46.000000000 +0200
8482+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sunrpc/auth.h 2012-10-04 18:47:00.000000000 +0200
8483@@ -25,6 +25,7 @@
8484 struct auth_cred {
8485 uid_t uid;
8486 gid_t gid;
8487+ tag_t tag;
8488 struct group_info *group_info;
8489 const char *principal;
8490 unsigned char machine_cred : 1;
8491diff -NurpP --minimal linux-3.6.6/include/linux/sunrpc/clnt.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sunrpc/clnt.h
8492--- linux-3.6.6/include/linux/sunrpc/clnt.h 2012-05-21 18:07:32.000000000 +0200
8493+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sunrpc/clnt.h 2012-10-04 18:47:00.000000000 +0200
8494@@ -49,7 +49,8 @@ struct rpc_clnt {
8495 unsigned int cl_softrtry : 1,/* soft timeouts */
8496 cl_discrtry : 1,/* disconnect before retry */
8497 cl_autobind : 1,/* use getport() */
8498- cl_chatty : 1;/* be verbose */
8499+ cl_chatty : 1,/* be verbose */
8500+ cl_tag : 1;/* context tagging */
8501
8502 struct rpc_rtt * cl_rtt; /* RTO estimator data */
8503 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
8504diff -NurpP --minimal linux-3.6.6/include/linux/sysctl.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sysctl.h
8505--- linux-3.6.6/include/linux/sysctl.h 2012-05-21 18:07:32.000000000 +0200
8506+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sysctl.h 2012-10-04 18:47:00.000000000 +0200
8507@@ -60,6 +60,7 @@ enum
8508 CTL_ABI=9, /* Binary emulation */
8509 CTL_CPU=10, /* CPU stuff (speed scaling, etc) */
8510 CTL_ARLAN=254, /* arlan wireless driver */
8511+ CTL_VSERVER=4242, /* Linux-VServer debug */
8512 CTL_S390DBF=5677, /* s390 debug */
8513 CTL_SUNRPC=7249, /* sunrpc debug */
8514 CTL_PM=9899, /* frv power management */
8515@@ -94,6 +95,7 @@ enum
8516
8517 KERN_PANIC=15, /* int: panic timeout */
8518 KERN_REALROOTDEV=16, /* real root device to mount after initrd */
8519+ KERN_VSHELPER=17, /* string: path to vshelper policy agent */
8520
8521 KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
8522 KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
8523diff -NurpP --minimal linux-3.6.6/include/linux/sysfs.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sysfs.h
8524--- linux-3.6.6/include/linux/sysfs.h 2012-07-22 23:39:44.000000000 +0200
8525+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/sysfs.h 2012-10-04 18:47:00.000000000 +0200
8526@@ -19,6 +19,8 @@
8527 #include <linux/kobject_ns.h>
8528 #include <linux/atomic.h>
8529
8530+#define SYSFS_SUPER_MAGIC 0x62656572
8531+
8532 struct kobject;
8533 struct module;
8534 enum kobj_ns_type;
8535diff -NurpP --minimal linux-3.6.6/include/linux/time.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/time.h
8536--- linux-3.6.6/include/linux/time.h 2012-10-04 15:27:46.000000000 +0200
8537+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/time.h 2012-10-04 18:47:00.000000000 +0200
8538@@ -280,6 +280,8 @@ static __always_inline void timespec_add
8539 a->tv_nsec = ns;
8540 }
8541
8542+#include <linux/vs_time.h>
8543+
8544 #endif /* __KERNEL__ */
8545
8546 /*
8547diff -NurpP --minimal linux-3.6.6/include/linux/types.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/types.h
8548--- linux-3.6.6/include/linux/types.h 2012-10-04 15:27:47.000000000 +0200
8549+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/types.h 2012-10-04 18:47:00.000000000 +0200
8550@@ -41,6 +41,9 @@ typedef __kernel_uid32_t uid_t;
8551 typedef __kernel_gid32_t gid_t;
8552 typedef __kernel_uid16_t uid16_t;
8553 typedef __kernel_gid16_t gid16_t;
8554+typedef unsigned int xid_t;
8555+typedef unsigned int nid_t;
8556+typedef unsigned int tag_t;
8557
8558 typedef unsigned long uintptr_t;
8559
8560diff -NurpP --minimal linux-3.6.6/include/linux/utsname.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/utsname.h
8561--- linux-3.6.6/include/linux/utsname.h 2012-01-09 16:14:59.000000000 +0100
8562+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/utsname.h 2012-10-04 18:47:00.000000000 +0200
8563@@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8564 }
8565
8566 extern struct uts_namespace *copy_utsname(unsigned long flags,
8567- struct task_struct *tsk);
8568+ struct uts_namespace *old_ns,
8569+ struct user_namespace *user_ns);
8570 extern void free_uts_ns(struct kref *kref);
8571
8572 static inline void put_uts_ns(struct uts_namespace *ns)
8573@@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8574 }
8575
8576 static inline struct uts_namespace *copy_utsname(unsigned long flags,
8577- struct task_struct *tsk)
8578+ struct uts_namespace *old_ns,
8579+ struct user_namespace *user_ns)
8580 {
8581 if (flags & CLONE_NEWUTS)
8582 return ERR_PTR(-EINVAL);
8583
8584- return tsk->nsproxy->uts_ns;
8585+ return old_ns;
8586 }
8587 #endif
8588
8589diff -NurpP --minimal linux-3.6.6/include/linux/vroot.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vroot.h
8590--- linux-3.6.6/include/linux/vroot.h 1970-01-01 01:00:00.000000000 +0100
8591+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vroot.h 2012-10-04 18:47:00.000000000 +0200
8592@@ -0,0 +1,51 @@
8593+
8594+/*
8595+ * include/linux/vroot.h
8596+ *
8597+ * written by Herbert Pötzl, 9/11/2002
8598+ * ported to 2.6 by Herbert Pötzl, 30/12/2004
8599+ *
8600+ * Copyright (C) 2002-2007 by Herbert Pötzl.
8601+ * Redistribution of this file is permitted under the
8602+ * GNU General Public License.
8603+ */
8604+
8605+#ifndef _LINUX_VROOT_H
8606+#define _LINUX_VROOT_H
8607+
8608+
8609+#ifdef __KERNEL__
8610+
8611+/* Possible states of device */
8612+enum {
8613+ Vr_unbound,
8614+ Vr_bound,
8615+};
8616+
8617+struct vroot_device {
8618+ int vr_number;
8619+ int vr_refcnt;
8620+
8621+ struct semaphore vr_ctl_mutex;
8622+ struct block_device *vr_device;
8623+ int vr_state;
8624+};
8625+
8626+
8627+typedef struct block_device *(vroot_grb_func)(struct block_device *);
8628+
8629+extern int register_vroot_grb(vroot_grb_func *);
8630+extern int unregister_vroot_grb(vroot_grb_func *);
8631+
8632+#endif /* __KERNEL__ */
8633+
8634+#define MAX_VROOT_DEFAULT 8
8635+
8636+/*
8637+ * IOCTL commands --- we will commandeer 0x56 ('V')
8638+ */
8639+
8640+#define VROOT_SET_DEV 0x5600
8641+#define VROOT_CLR_DEV 0x5601
8642+
8643+#endif /* _LINUX_VROOT_H */
8644diff -NurpP --minimal linux-3.6.6/include/linux/vs_base.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_base.h
8645--- linux-3.6.6/include/linux/vs_base.h 1970-01-01 01:00:00.000000000 +0100
8646+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_base.h 2012-10-04 18:47:00.000000000 +0200
8647@@ -0,0 +1,10 @@
8648+#ifndef _VS_BASE_H
8649+#define _VS_BASE_H
8650+
8651+#include "vserver/base.h"
8652+#include "vserver/check.h"
8653+#include "vserver/debug.h"
8654+
8655+#else
8656+#warning duplicate inclusion
8657+#endif
8658diff -NurpP --minimal linux-3.6.6/include/linux/vs_context.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_context.h
8659--- linux-3.6.6/include/linux/vs_context.h 1970-01-01 01:00:00.000000000 +0100
8660+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_context.h 2012-10-04 18:47:00.000000000 +0200
8661@@ -0,0 +1,242 @@
8662+#ifndef _VS_CONTEXT_H
8663+#define _VS_CONTEXT_H
8664+
8665+#include "vserver/base.h"
8666+#include "vserver/check.h"
8667+#include "vserver/context.h"
8668+#include "vserver/history.h"
8669+#include "vserver/debug.h"
8670+
8671+#include <linux/sched.h>
8672+
8673+
8674+#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8675+
8676+static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8677+ const char *_file, int _line, void *_here)
8678+{
8679+ if (!vxi)
8680+ return NULL;
8681+
8682+ vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8683+ vxi, vxi ? vxi->vx_id : 0,
8684+ vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8685+ _file, _line);
8686+ __vxh_get_vx_info(vxi, _here);
8687+
8688+ atomic_inc(&vxi->vx_usecnt);
8689+ return vxi;
8690+}
8691+
8692+
8693+extern void free_vx_info(struct vx_info *);
8694+
8695+#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8696+
8697+static inline void __put_vx_info(struct vx_info *vxi,
8698+ const char *_file, int _line, void *_here)
8699+{
8700+ if (!vxi)
8701+ return;
8702+
8703+ vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8704+ vxi, vxi ? vxi->vx_id : 0,
8705+ vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8706+ _file, _line);
8707+ __vxh_put_vx_info(vxi, _here);
8708+
8709+ if (atomic_dec_and_test(&vxi->vx_usecnt))
8710+ free_vx_info(vxi);
8711+}
8712+
8713+
8714+#define init_vx_info(p, i) \
8715+ __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8716+
8717+static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8718+ const char *_file, int _line, void *_here)
8719+{
8720+ if (vxi) {
8721+ vxlprintk(VXD_CBIT(xid, 3),
8722+ "init_vx_info(%p[#%d.%d])",
8723+ vxi, vxi ? vxi->vx_id : 0,
8724+ vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8725+ _file, _line);
8726+ __vxh_init_vx_info(vxi, vxp, _here);
8727+
8728+ atomic_inc(&vxi->vx_usecnt);
8729+ }
8730+ *vxp = vxi;
8731+}
8732+
8733+
8734+#define set_vx_info(p, i) \
8735+ __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8736+
8737+static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8738+ const char *_file, int _line, void *_here)
8739+{
8740+ struct vx_info *vxo;
8741+
8742+ if (!vxi)
8743+ return;
8744+
8745+ vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8746+ vxi, vxi ? vxi->vx_id : 0,
8747+ vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8748+ _file, _line);
8749+ __vxh_set_vx_info(vxi, vxp, _here);
8750+
8751+ atomic_inc(&vxi->vx_usecnt);
8752+ vxo = xchg(vxp, vxi);
8753+ BUG_ON(vxo);
8754+}
8755+
8756+
8757+#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8758+
8759+static inline void __clr_vx_info(struct vx_info **vxp,
8760+ const char *_file, int _line, void *_here)
8761+{
8762+ struct vx_info *vxo;
8763+
8764+ vxo = xchg(vxp, NULL);
8765+ if (!vxo)
8766+ return;
8767+
8768+ vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8769+ vxo, vxo ? vxo->vx_id : 0,
8770+ vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8771+ _file, _line);
8772+ __vxh_clr_vx_info(vxo, vxp, _here);
8773+
8774+ if (atomic_dec_and_test(&vxo->vx_usecnt))
8775+ free_vx_info(vxo);
8776+}
8777+
8778+
8779+#define claim_vx_info(v, p) \
8780+ __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8781+
8782+static inline void __claim_vx_info(struct vx_info *vxi,
8783+ struct task_struct *task,
8784+ const char *_file, int _line, void *_here)
8785+{
8786+ vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8787+ vxi, vxi ? vxi->vx_id : 0,
8788+ vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8789+ vxi ? atomic_read(&vxi->vx_tasks) : 0,
8790+ task, _file, _line);
8791+ __vxh_claim_vx_info(vxi, task, _here);
8792+
8793+ atomic_inc(&vxi->vx_tasks);
8794+}
8795+
8796+
8797+extern void unhash_vx_info(struct vx_info *);
8798+
8799+#define release_vx_info(v, p) \
8800+ __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8801+
8802+static inline void __release_vx_info(struct vx_info *vxi,
8803+ struct task_struct *task,
8804+ const char *_file, int _line, void *_here)
8805+{
8806+ vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8807+ vxi, vxi ? vxi->vx_id : 0,
8808+ vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8809+ vxi ? atomic_read(&vxi->vx_tasks) : 0,
8810+ task, _file, _line);
8811+ __vxh_release_vx_info(vxi, task, _here);
8812+
8813+ might_sleep();
8814+
8815+ if (atomic_dec_and_test(&vxi->vx_tasks))
8816+ unhash_vx_info(vxi);
8817+}
8818+
8819+
8820+#define task_get_vx_info(p) \
8821+ __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8822+
8823+static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8824+ const char *_file, int _line, void *_here)
8825+{
8826+ struct vx_info *vxi;
8827+
8828+ task_lock(p);
8829+ vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8830+ p, _file, _line);
8831+ vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8832+ task_unlock(p);
8833+ return vxi;
8834+}
8835+
8836+
8837+static inline void __wakeup_vx_info(struct vx_info *vxi)
8838+{
8839+ if (waitqueue_active(&vxi->vx_wait))
8840+ wake_up_interruptible(&vxi->vx_wait);
8841+}
8842+
8843+
8844+#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8845+
8846+static inline void __enter_vx_info(struct vx_info *vxi,
8847+ struct vx_info_save *vxis, const char *_file, int _line)
8848+{
8849+ vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8850+ vxi, vxi ? vxi->vx_id : 0, vxis, current,
8851+ current->xid, current->vx_info, _file, _line);
8852+ vxis->vxi = xchg(&current->vx_info, vxi);
8853+ vxis->xid = current->xid;
8854+ current->xid = vxi ? vxi->vx_id : 0;
8855+}
8856+
8857+#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8858+
8859+static inline void __leave_vx_info(struct vx_info_save *vxis,
8860+ const char *_file, int _line)
8861+{
8862+ vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8863+ vxis, vxis->xid, vxis->vxi, current,
8864+ current->xid, current->vx_info, _file, _line);
8865+ (void)xchg(&current->vx_info, vxis->vxi);
8866+ current->xid = vxis->xid;
8867+}
8868+
8869+
8870+static inline void __enter_vx_admin(struct vx_info_save *vxis)
8871+{
8872+ vxis->vxi = xchg(&current->vx_info, NULL);
8873+ vxis->xid = xchg(&current->xid, (xid_t)0);
8874+}
8875+
8876+static inline void __leave_vx_admin(struct vx_info_save *vxis)
8877+{
8878+ (void)xchg(&current->xid, vxis->xid);
8879+ (void)xchg(&current->vx_info, vxis->vxi);
8880+}
8881+
8882+#define task_is_init(p) \
8883+ __task_is_init(p, __FILE__, __LINE__, __HERE__)
8884+
8885+static inline int __task_is_init(struct task_struct *p,
8886+ const char *_file, int _line, void *_here)
8887+{
8888+ int is_init = is_global_init(p);
8889+
8890+ task_lock(p);
8891+ if (p->vx_info)
8892+ is_init = p->vx_info->vx_initpid == p->pid;
8893+ task_unlock(p);
8894+ return is_init;
8895+}
8896+
8897+extern void exit_vx_info(struct task_struct *, int);
8898+extern void exit_vx_info_early(struct task_struct *, int);
8899+
8900+
8901+#else
8902+#warning duplicate inclusion
8903+#endif
8904diff -NurpP --minimal linux-3.6.6/include/linux/vs_cowbl.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_cowbl.h
8905--- linux-3.6.6/include/linux/vs_cowbl.h 1970-01-01 01:00:00.000000000 +0100
8906+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_cowbl.h 2012-10-04 18:47:00.000000000 +0200
8907@@ -0,0 +1,48 @@
8908+#ifndef _VS_COWBL_H
8909+#define _VS_COWBL_H
8910+
8911+#include <linux/fs.h>
8912+#include <linux/dcache.h>
8913+#include <linux/namei.h>
8914+#include <linux/slab.h>
8915+
8916+extern struct dentry *cow_break_link(const char *pathname);
8917+
8918+static inline int cow_check_and_break(struct path *path)
8919+{
8920+ struct inode *inode = path->dentry->d_inode;
8921+ int error = 0;
8922+
8923+ /* do we need this check? */
8924+ if (IS_RDONLY(inode))
8925+ return -EROFS;
8926+
8927+ if (IS_COW(inode)) {
8928+ if (IS_COW_LINK(inode)) {
8929+ struct dentry *new_dentry, *old_dentry = path->dentry;
8930+ char *pp, *buf;
8931+
8932+ buf = kmalloc(PATH_MAX, GFP_KERNEL);
8933+ if (!buf) {
8934+ return -ENOMEM;
8935+ }
8936+ pp = d_path(path, buf, PATH_MAX);
8937+ new_dentry = cow_break_link(pp);
8938+ kfree(buf);
8939+ if (!IS_ERR(new_dentry)) {
8940+ path->dentry = new_dentry;
8941+ dput(old_dentry);
8942+ } else
8943+ error = PTR_ERR(new_dentry);
8944+ } else {
8945+ inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8946+ inode->i_ctime = CURRENT_TIME;
8947+ mark_inode_dirty(inode);
8948+ }
8949+ }
8950+ return error;
8951+}
8952+
8953+#else
8954+#warning duplicate inclusion
8955+#endif
8956diff -NurpP --minimal linux-3.6.6/include/linux/vs_cvirt.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_cvirt.h
8957--- linux-3.6.6/include/linux/vs_cvirt.h 1970-01-01 01:00:00.000000000 +0100
8958+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_cvirt.h 2012-10-04 18:47:00.000000000 +0200
8959@@ -0,0 +1,50 @@
8960+#ifndef _VS_CVIRT_H
8961+#define _VS_CVIRT_H
8962+
8963+#include "vserver/cvirt.h"
8964+#include "vserver/context.h"
8965+#include "vserver/base.h"
8966+#include "vserver/check.h"
8967+#include "vserver/debug.h"
8968+
8969+
8970+static inline void vx_activate_task(struct task_struct *p)
8971+{
8972+ struct vx_info *vxi;
8973+
8974+ if ((vxi = p->vx_info)) {
8975+ vx_update_load(vxi);
8976+ atomic_inc(&vxi->cvirt.nr_running);
8977+ }
8978+}
8979+
8980+static inline void vx_deactivate_task(struct task_struct *p)
8981+{
8982+ struct vx_info *vxi;
8983+
8984+ if ((vxi = p->vx_info)) {
8985+ vx_update_load(vxi);
8986+ atomic_dec(&vxi->cvirt.nr_running);
8987+ }
8988+}
8989+
8990+static inline void vx_uninterruptible_inc(struct task_struct *p)
8991+{
8992+ struct vx_info *vxi;
8993+
8994+ if ((vxi = p->vx_info))
8995+ atomic_inc(&vxi->cvirt.nr_uninterruptible);
8996+}
8997+
8998+static inline void vx_uninterruptible_dec(struct task_struct *p)
8999+{
9000+ struct vx_info *vxi;
9001+
9002+ if ((vxi = p->vx_info))
9003+ atomic_dec(&vxi->cvirt.nr_uninterruptible);
9004+}
9005+
9006+
9007+#else
9008+#warning duplicate inclusion
9009+#endif
9010diff -NurpP --minimal linux-3.6.6/include/linux/vs_device.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_device.h
9011--- linux-3.6.6/include/linux/vs_device.h 1970-01-01 01:00:00.000000000 +0100
9012+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_device.h 2012-10-04 18:47:00.000000000 +0200
9013@@ -0,0 +1,45 @@
9014+#ifndef _VS_DEVICE_H
9015+#define _VS_DEVICE_H
9016+
9017+#include "vserver/base.h"
9018+#include "vserver/device.h"
9019+#include "vserver/debug.h"
9020+
9021+
9022+#ifdef CONFIG_VSERVER_DEVICE
9023+
9024+int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9025+
9026+#define vs_device_perm(v, d, m, p) \
9027+ ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9028+
9029+#else
9030+
9031+static inline
9032+int vs_map_device(struct vx_info *vxi,
9033+ dev_t device, dev_t *target, umode_t mode)
9034+{
9035+ if (target)
9036+ *target = device;
9037+ return ~0;
9038+}
9039+
9040+#define vs_device_perm(v, d, m, p) ((p) == (p))
9041+
9042+#endif
9043+
9044+
9045+#define vs_map_chrdev(d, t, p) \
9046+ ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9047+#define vs_map_blkdev(d, t, p) \
9048+ ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9049+
9050+#define vs_chrdev_perm(d, p) \
9051+ vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9052+#define vs_blkdev_perm(d, p) \
9053+ vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9054+
9055+
9056+#else
9057+#warning duplicate inclusion
9058+#endif
9059diff -NurpP --minimal linux-3.6.6/include/linux/vs_dlimit.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_dlimit.h
9060--- linux-3.6.6/include/linux/vs_dlimit.h 1970-01-01 01:00:00.000000000 +0100
9061+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_dlimit.h 2012-10-04 18:47:00.000000000 +0200
9062@@ -0,0 +1,215 @@
9063+#ifndef _VS_DLIMIT_H
9064+#define _VS_DLIMIT_H
9065+
9066+#include <linux/fs.h>
9067+
9068+#include "vserver/dlimit.h"
9069+#include "vserver/base.h"
9070+#include "vserver/debug.h"
9071+
9072+
9073+#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9074+
9075+static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9076+ const char *_file, int _line)
9077+{
9078+ if (!dli)
9079+ return NULL;
9080+ vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9081+ dli, dli ? dli->dl_tag : 0,
9082+ dli ? atomic_read(&dli->dl_usecnt) : 0,
9083+ _file, _line);
9084+ atomic_inc(&dli->dl_usecnt);
9085+ return dli;
9086+}
9087+
9088+
9089+#define free_dl_info(i) \
9090+ call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9091+
9092+#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9093+
9094+static inline void __put_dl_info(struct dl_info *dli,
9095+ const char *_file, int _line)
9096+{
9097+ if (!dli)
9098+ return;
9099+ vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9100+ dli, dli ? dli->dl_tag : 0,
9101+ dli ? atomic_read(&dli->dl_usecnt) : 0,
9102+ _file, _line);
9103+ if (atomic_dec_and_test(&dli->dl_usecnt))
9104+ free_dl_info(dli);
9105+}
9106+
9107+
9108+#define __dlimit_char(d) ((d) ? '*' : ' ')
9109+
9110+static inline int __dl_alloc_space(struct super_block *sb,
9111+ tag_t tag, dlsize_t nr, const char *file, int line)
9112+{
9113+ struct dl_info *dli = NULL;
9114+ int ret = 0;
9115+
9116+ if (nr == 0)
9117+ goto out;
9118+ dli = locate_dl_info(sb, tag);
9119+ if (!dli)
9120+ goto out;
9121+
9122+ spin_lock(&dli->dl_lock);
9123+ ret = (dli->dl_space_used + nr > dli->dl_space_total);
9124+ if (!ret)
9125+ dli->dl_space_used += nr;
9126+ spin_unlock(&dli->dl_lock);
9127+ put_dl_info(dli);
9128+out:
9129+ vxlprintk(VXD_CBIT(dlim, 1),
9130+ "ALLOC (%p,#%d)%c %lld bytes (%d)",
9131+ sb, tag, __dlimit_char(dli), (long long)nr,
9132+ ret, file, line);
9133+ return ret ? -ENOSPC : 0;
9134+}
9135+
9136+static inline void __dl_free_space(struct super_block *sb,
9137+ tag_t tag, dlsize_t nr, const char *_file, int _line)
9138+{
9139+ struct dl_info *dli = NULL;
9140+
9141+ if (nr == 0)
9142+ goto out;
9143+ dli = locate_dl_info(sb, tag);
9144+ if (!dli)
9145+ goto out;
9146+
9147+ spin_lock(&dli->dl_lock);
9148+ if (dli->dl_space_used > nr)
9149+ dli->dl_space_used -= nr;
9150+ else
9151+ dli->dl_space_used = 0;
9152+ spin_unlock(&dli->dl_lock);
9153+ put_dl_info(dli);
9154+out:
9155+ vxlprintk(VXD_CBIT(dlim, 1),
9156+ "FREE (%p,#%d)%c %lld bytes",
9157+ sb, tag, __dlimit_char(dli), (long long)nr,
9158+ _file, _line);
9159+}
9160+
9161+static inline int __dl_alloc_inode(struct super_block *sb,
9162+ tag_t tag, const char *_file, int _line)
9163+{
9164+ struct dl_info *dli;
9165+ int ret = 0;
9166+
9167+ dli = locate_dl_info(sb, tag);
9168+ if (!dli)
9169+ goto out;
9170+
9171+ spin_lock(&dli->dl_lock);
9172+ dli->dl_inodes_used++;
9173+ ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9174+ spin_unlock(&dli->dl_lock);
9175+ put_dl_info(dli);
9176+out:
9177+ vxlprintk(VXD_CBIT(dlim, 0),
9178+ "ALLOC (%p,#%d)%c inode (%d)",
9179+ sb, tag, __dlimit_char(dli), ret, _file, _line);
9180+ return ret ? -ENOSPC : 0;
9181+}
9182+
9183+static inline void __dl_free_inode(struct super_block *sb,
9184+ tag_t tag, const char *_file, int _line)
9185+{
9186+ struct dl_info *dli;
9187+
9188+ dli = locate_dl_info(sb, tag);
9189+ if (!dli)
9190+ goto out;
9191+
9192+ spin_lock(&dli->dl_lock);
9193+ if (dli->dl_inodes_used > 1)
9194+ dli->dl_inodes_used--;
9195+ else
9196+ dli->dl_inodes_used = 0;
9197+ spin_unlock(&dli->dl_lock);
9198+ put_dl_info(dli);
9199+out:
9200+ vxlprintk(VXD_CBIT(dlim, 0),
9201+ "FREE (%p,#%d)%c inode",
9202+ sb, tag, __dlimit_char(dli), _file, _line);
9203+}
9204+
9205+static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9206+ unsigned long long *free_blocks, unsigned long long *root_blocks,
9207+ const char *_file, int _line)
9208+{
9209+ struct dl_info *dli;
9210+ uint64_t broot, bfree;
9211+
9212+ dli = locate_dl_info(sb, tag);
9213+ if (!dli)
9214+ return;
9215+
9216+ spin_lock(&dli->dl_lock);
9217+ broot = (dli->dl_space_total -
9218+ (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9219+ >> sb->s_blocksize_bits;
9220+ bfree = (dli->dl_space_total - dli->dl_space_used)
9221+ >> sb->s_blocksize_bits;
9222+ spin_unlock(&dli->dl_lock);
9223+
9224+ vxlprintk(VXD_CBIT(dlim, 2),
9225+ "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9226+ (long long)bfree, (long long)broot,
9227+ *free_blocks, *root_blocks, dli->dl_nrlmult,
9228+ _file, _line);
9229+ if (free_blocks) {
9230+ if (*free_blocks > bfree)
9231+ *free_blocks = bfree;
9232+ }
9233+ if (root_blocks) {
9234+ if (*root_blocks > broot)
9235+ *root_blocks = broot;
9236+ }
9237+ put_dl_info(dli);
9238+}
9239+
9240+#define dl_prealloc_space(in, bytes) \
9241+ __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9242+ __FILE__, __LINE__ )
9243+
9244+#define dl_alloc_space(in, bytes) \
9245+ __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9246+ __FILE__, __LINE__ )
9247+
9248+#define dl_reserve_space(in, bytes) \
9249+ __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9250+ __FILE__, __LINE__ )
9251+
9252+#define dl_claim_space(in, bytes) (0)
9253+
9254+#define dl_release_space(in, bytes) \
9255+ __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9256+ __FILE__, __LINE__ )
9257+
9258+#define dl_free_space(in, bytes) \
9259+ __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9260+ __FILE__, __LINE__ )
9261+
9262+
9263+
9264+#define dl_alloc_inode(in) \
9265+ __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9266+
9267+#define dl_free_inode(in) \
9268+ __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9269+
9270+
9271+#define dl_adjust_block(sb, tag, fb, rb) \
9272+ __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9273+
9274+
9275+#else
9276+#warning duplicate inclusion
9277+#endif
9278diff -NurpP --minimal linux-3.6.6/include/linux/vs_inet.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_inet.h
9279--- linux-3.6.6/include/linux/vs_inet.h 1970-01-01 01:00:00.000000000 +0100
9280+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_inet.h 2012-10-04 18:47:00.000000000 +0200
9281@@ -0,0 +1,353 @@
9282+#ifndef _VS_INET_H
9283+#define _VS_INET_H
9284+
9285+#include "vserver/base.h"
9286+#include "vserver/network.h"
9287+#include "vserver/debug.h"
9288+
9289+#define IPI_LOOPBACK htonl(INADDR_LOOPBACK)
9290+
9291+#define NXAV4(a) NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9292+ NIPQUAD((a)->mask), (a)->type
9293+#define NXAV4_FMT "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9294+
9295+#define NIPQUAD(addr) \
9296+ ((unsigned char *)&addr)[0], \
9297+ ((unsigned char *)&addr)[1], \
9298+ ((unsigned char *)&addr)[2], \
9299+ ((unsigned char *)&addr)[3]
9300+
9301+#define NIPQUAD_FMT "%u.%u.%u.%u"
9302+
9303+
9304+static inline
9305+int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9306+{
9307+ __be32 ip = nxa->ip[0].s_addr;
9308+ __be32 mask = nxa->mask.s_addr;
9309+ __be32 bcast = ip | ~mask;
9310+ int ret = 0;
9311+
9312+ switch (nxa->type & tmask) {
9313+ case NXA_TYPE_MASK:
9314+ ret = (ip == (addr & mask));
9315+ break;
9316+ case NXA_TYPE_ADDR:
9317+ ret = 3;
9318+ if (addr == ip)
9319+ break;
9320+ /* fall through to broadcast */
9321+ case NXA_MOD_BCAST:
9322+ ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9323+ break;
9324+ case NXA_TYPE_RANGE:
9325+ ret = ((nxa->ip[0].s_addr <= addr) &&
9326+ (nxa->ip[1].s_addr > addr));
9327+ break;
9328+ case NXA_TYPE_ANY:
9329+ ret = 2;
9330+ break;
9331+ }
9332+
9333+ vxdprintk(VXD_CBIT(net, 0),
9334+ "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9335+ nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9336+ return ret;
9337+}
9338+
9339+static inline
9340+int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9341+{
9342+ struct nx_addr_v4 *nxa;
9343+ int ret = 1;
9344+
9345+ if (!nxi)
9346+ goto out;
9347+
9348+ ret = 2;
9349+ /* allow 127.0.0.1 when remapping lback */
9350+ if ((tmask & NXA_LOOPBACK) &&
9351+ (addr == IPI_LOOPBACK) &&
9352+ nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9353+ goto out;
9354+ ret = 3;
9355+ /* check for lback address */
9356+ if ((tmask & NXA_MOD_LBACK) &&
9357+ (nxi->v4_lback.s_addr == addr))
9358+ goto out;
9359+ ret = 4;
9360+ /* check for broadcast address */
9361+ if ((tmask & NXA_MOD_BCAST) &&
9362+ (nxi->v4_bcast.s_addr == addr))
9363+ goto out;
9364+ ret = 5;
9365+ /* check for v4 addresses */
9366+ for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9367+ if (v4_addr_match(nxa, addr, tmask))
9368+ goto out;
9369+ ret = 0;
9370+out:
9371+ vxdprintk(VXD_CBIT(net, 0),
9372+ "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9373+ nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9374+ return ret;
9375+}
9376+
9377+static inline
9378+int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9379+{
9380+ /* FIXME: needs full range checks */
9381+ return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9382+}
9383+
9384+static inline
9385+int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9386+{
9387+ struct nx_addr_v4 *ptr;
9388+
9389+ for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9390+ if (v4_nx_addr_match(ptr, nxa, mask))
9391+ return 1;
9392+ return 0;
9393+}
9394+
9395+#include <net/inet_sock.h>
9396+
9397+/*
9398+ * Check if a given address matches for a socket
9399+ *
9400+ * nxi: the socket's nx_info if any
9401+ * addr: to be verified address
9402+ */
9403+static inline
9404+int v4_sock_addr_match (
9405+ struct nx_info *nxi,
9406+ struct inet_sock *inet,
9407+ __be32 addr)
9408+{
9409+ __be32 saddr = inet->inet_rcv_saddr;
9410+ __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9411+
9412+ if (addr && (saddr == addr || bcast == addr))
9413+ return 1;
9414+ if (!saddr)
9415+ return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9416+ return 0;
9417+}
9418+
9419+
9420+/* inet related checks and helpers */
9421+
9422+
9423+struct in_ifaddr;
9424+struct net_device;
9425+struct sock;
9426+
9427+#ifdef CONFIG_INET
9428+
9429+#include <linux/netdevice.h>
9430+#include <linux/inetdevice.h>
9431+#include <net/inet_sock.h>
9432+#include <net/inet_timewait_sock.h>
9433+
9434+
9435+int dev_in_nx_info(struct net_device *, struct nx_info *);
9436+int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9437+int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9438+
9439+
9440+/*
9441+ * check if address is covered by socket
9442+ *
9443+ * sk: the socket to check against
9444+ * addr: the address in question (must be != 0)
9445+ */
9446+
9447+static inline
9448+int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9449+{
9450+ struct nx_info *nxi = sk->sk_nx_info;
9451+ __be32 saddr = sk_rcv_saddr(sk);
9452+
9453+ vxdprintk(VXD_CBIT(net, 5),
9454+ "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9455+ sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9456+ (sk->sk_socket?sk->sk_socket->flags:0));
9457+
9458+ if (saddr) { /* direct address match */
9459+ return v4_addr_match(nxa, saddr, -1);
9460+ } else if (nxi) { /* match against nx_info */
9461+ return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9462+ } else { /* unrestricted any socket */
9463+ return 1;
9464+ }
9465+}
9466+
9467+
9468+
9469+static inline
9470+int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9471+{
9472+ vxdprintk(VXD_CBIT(net, 1),
9473+ "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9474+ nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9475+ nxi ? dev_in_nx_info(dev, nxi) : 0);
9476+
9477+ if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9478+ return 1;
9479+ if (dev_in_nx_info(dev, nxi))
9480+ return 1;
9481+ return 0;
9482+}
9483+
9484+
9485+static inline
9486+int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9487+{
9488+ if (!nxi)
9489+ return 1;
9490+ if (!ifa)
9491+ return 0;
9492+ return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9493+}
9494+
9495+static inline
9496+int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9497+{
9498+ vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9499+ nxi, nxi ? nxi->nx_id : 0, ifa,
9500+ nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9501+
9502+ if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9503+ return 1;
9504+ if (v4_ifa_in_nx_info(ifa, nxi))
9505+ return 1;
9506+ return 0;
9507+}
9508+
9509+
9510+struct nx_v4_sock_addr {
9511+ __be32 saddr; /* Address used for validation */
9512+ __be32 baddr; /* Address used for socket bind */
9513+};
9514+
9515+static inline
9516+int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9517+ struct nx_v4_sock_addr *nsa)
9518+{
9519+ struct sock *sk = &inet->sk;
9520+ struct nx_info *nxi = sk->sk_nx_info;
9521+ __be32 saddr = addr->sin_addr.s_addr;
9522+ __be32 baddr = saddr;
9523+
9524+ vxdprintk(VXD_CBIT(net, 3),
9525+ "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9526+ sk, sk->sk_nx_info, sk->sk_socket,
9527+ (sk->sk_socket ? sk->sk_socket->flags : 0),
9528+ NIPQUAD(saddr));
9529+
9530+ if (nxi) {
9531+ if (saddr == INADDR_ANY) {
9532+ if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9533+ baddr = nxi->v4.ip[0].s_addr;
9534+ } else if (saddr == IPI_LOOPBACK) {
9535+ if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9536+ baddr = nxi->v4_lback.s_addr;
9537+ } else if (!ipv4_is_multicast(saddr) ||
9538+ !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9539+ /* normal address bind */
9540+ if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9541+ return -EADDRNOTAVAIL;
9542+ }
9543+ }
9544+
9545+ vxdprintk(VXD_CBIT(net, 3),
9546+ "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9547+ sk, NIPQUAD(saddr), NIPQUAD(baddr));
9548+
9549+ nsa->saddr = saddr;
9550+ nsa->baddr = baddr;
9551+ return 0;
9552+}
9553+
9554+static inline
9555+void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9556+{
9557+ inet->inet_saddr = nsa->baddr;
9558+ inet->inet_rcv_saddr = nsa->baddr;
9559+}
9560+
9561+
9562+/*
9563+ * helper to simplify inet_lookup_listener
9564+ *
9565+ * nxi: the socket's nx_info if any
9566+ * addr: to be verified address
9567+ * saddr: socket address
9568+ */
9569+static inline int v4_inet_addr_match (
9570+ struct nx_info *nxi,
9571+ __be32 addr,
9572+ __be32 saddr)
9573+{
9574+ if (addr && (saddr == addr))
9575+ return 1;
9576+ if (!saddr)
9577+ return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9578+ return 0;
9579+}
9580+
9581+static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9582+{
9583+ if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9584+ (addr == nxi->v4_lback.s_addr))
9585+ return IPI_LOOPBACK;
9586+ return addr;
9587+}
9588+
9589+static inline
9590+int nx_info_has_v4(struct nx_info *nxi)
9591+{
9592+ if (!nxi)
9593+ return 1;
9594+ if (NX_IPV4(nxi))
9595+ return 1;
9596+ if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9597+ return 1;
9598+ return 0;
9599+}
9600+
9601+#else /* CONFIG_INET */
9602+
9603+static inline
9604+int nx_dev_visible(struct nx_info *n, struct net_device *d)
9605+{
9606+ return 1;
9607+}
9608+
9609+static inline
9610+int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9611+{
9612+ return 1;
9613+}
9614+
9615+static inline
9616+int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9617+{
9618+ return 1;
9619+}
9620+
9621+static inline
9622+int nx_info_has_v4(struct nx_info *nxi)
9623+{
9624+ return 0;
9625+}
9626+
9627+#endif /* CONFIG_INET */
9628+
9629+#define current_nx_info_has_v4() \
9630+ nx_info_has_v4(current_nx_info())
9631+
9632+#else
9633+// #warning duplicate inclusion
9634+#endif
9635diff -NurpP --minimal linux-3.6.6/include/linux/vs_inet6.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_inet6.h
9636--- linux-3.6.6/include/linux/vs_inet6.h 1970-01-01 01:00:00.000000000 +0100
9637+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_inet6.h 2012-10-04 18:47:00.000000000 +0200
9638@@ -0,0 +1,246 @@
9639+#ifndef _VS_INET6_H
9640+#define _VS_INET6_H
9641+
9642+#include "vserver/base.h"
9643+#include "vserver/network.h"
9644+#include "vserver/debug.h"
9645+
9646+#include <net/ipv6.h>
9647+
9648+#define NXAV6(a) &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9649+#define NXAV6_FMT "[%pI6/%pI6/%d:%04x]"
9650+
9651+
9652+#ifdef CONFIG_IPV6
9653+
9654+static inline
9655+int v6_addr_match(struct nx_addr_v6 *nxa,
9656+ const struct in6_addr *addr, uint16_t mask)
9657+{
9658+ int ret = 0;
9659+
9660+ switch (nxa->type & mask) {
9661+ case NXA_TYPE_MASK:
9662+ ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9663+ break;
9664+ case NXA_TYPE_ADDR:
9665+ ret = ipv6_addr_equal(&nxa->ip, addr);
9666+ break;
9667+ case NXA_TYPE_ANY:
9668+ ret = 1;
9669+ break;
9670+ }
9671+ vxdprintk(VXD_CBIT(net, 0),
9672+ "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9673+ nxa, NXAV6(nxa), addr, mask, ret);
9674+ return ret;
9675+}
9676+
9677+static inline
9678+int v6_addr_in_nx_info(struct nx_info *nxi,
9679+ const struct in6_addr *addr, uint16_t mask)
9680+{
9681+ struct nx_addr_v6 *nxa;
9682+ int ret = 1;
9683+
9684+ if (!nxi)
9685+ goto out;
9686+ for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9687+ if (v6_addr_match(nxa, addr, mask))
9688+ goto out;
9689+ ret = 0;
9690+out:
9691+ vxdprintk(VXD_CBIT(net, 0),
9692+ "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9693+ nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9694+ return ret;
9695+}
9696+
9697+static inline
9698+int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9699+{
9700+ /* FIXME: needs full range checks */
9701+ return v6_addr_match(nxa, &addr->ip, mask);
9702+}
9703+
9704+static inline
9705+int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9706+{
9707+ struct nx_addr_v6 *ptr;
9708+
9709+ for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9710+ if (v6_nx_addr_match(ptr, nxa, mask))
9711+ return 1;
9712+ return 0;
9713+}
9714+
9715+
9716+/*
9717+ * Check if a given address matches for a socket
9718+ *
9719+ * nxi: the socket's nx_info if any
9720+ * addr: to be verified address
9721+ */
9722+static inline
9723+int v6_sock_addr_match (
9724+ struct nx_info *nxi,
9725+ struct inet_sock *inet,
9726+ struct in6_addr *addr)
9727+{
9728+ struct sock *sk = &inet->sk;
9729+ struct in6_addr *saddr = inet6_rcv_saddr(sk);
9730+
9731+ if (!ipv6_addr_any(addr) &&
9732+ ipv6_addr_equal(saddr, addr))
9733+ return 1;
9734+ if (ipv6_addr_any(saddr))
9735+ return v6_addr_in_nx_info(nxi, addr, -1);
9736+ return 0;
9737+}
9738+
9739+/*
9740+ * check if address is covered by socket
9741+ *
9742+ * sk: the socket to check against
9743+ * addr: the address in question (must be != 0)
9744+ */
9745+
9746+static inline
9747+int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9748+{
9749+ struct nx_info *nxi = sk->sk_nx_info;
9750+ struct in6_addr *saddr = inet6_rcv_saddr(sk);
9751+
9752+ vxdprintk(VXD_CBIT(net, 5),
9753+ "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9754+ sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9755+ (sk->sk_socket?sk->sk_socket->flags:0));
9756+
9757+ if (!ipv6_addr_any(saddr)) { /* direct address match */
9758+ return v6_addr_match(nxa, saddr, -1);
9759+ } else if (nxi) { /* match against nx_info */
9760+ return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9761+ } else { /* unrestricted any socket */
9762+ return 1;
9763+ }
9764+}
9765+
9766+
9767+/* inet related checks and helpers */
9768+
9769+
9770+struct in_ifaddr;
9771+struct net_device;
9772+struct sock;
9773+
9774+
9775+#include <linux/netdevice.h>
9776+#include <linux/inetdevice.h>
9777+#include <net/inet_timewait_sock.h>
9778+
9779+
9780+int dev_in_nx_info(struct net_device *, struct nx_info *);
9781+int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9782+int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9783+
9784+
9785+
9786+static inline
9787+int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9788+{
9789+ if (!nxi)
9790+ return 1;
9791+ if (!ifa)
9792+ return 0;
9793+ return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9794+}
9795+
9796+static inline
9797+int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9798+{
9799+ vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9800+ nxi, nxi ? nxi->nx_id : 0, ifa,
9801+ nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9802+
9803+ if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9804+ return 1;
9805+ if (v6_ifa_in_nx_info(ifa, nxi))
9806+ return 1;
9807+ return 0;
9808+}
9809+
9810+
9811+struct nx_v6_sock_addr {
9812+ struct in6_addr saddr; /* Address used for validation */
9813+ struct in6_addr baddr; /* Address used for socket bind */
9814+};
9815+
9816+static inline
9817+int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9818+ struct nx_v6_sock_addr *nsa)
9819+{
9820+ // struct sock *sk = &inet->sk;
9821+ // struct nx_info *nxi = sk->sk_nx_info;
9822+ struct in6_addr saddr = addr->sin6_addr;
9823+ struct in6_addr baddr = saddr;
9824+
9825+ nsa->saddr = saddr;
9826+ nsa->baddr = baddr;
9827+ return 0;
9828+}
9829+
9830+static inline
9831+void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9832+{
9833+ // struct sock *sk = &inet->sk;
9834+ // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9835+
9836+ // *saddr = nsa->baddr;
9837+ // inet->inet_saddr = nsa->baddr;
9838+}
9839+
9840+static inline
9841+int nx_info_has_v6(struct nx_info *nxi)
9842+{
9843+ if (!nxi)
9844+ return 1;
9845+ if (NX_IPV6(nxi))
9846+ return 1;
9847+ return 0;
9848+}
9849+
9850+#else /* CONFIG_IPV6 */
9851+
9852+static inline
9853+int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9854+{
9855+ return 1;
9856+}
9857+
9858+
9859+static inline
9860+int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9861+{
9862+ return 1;
9863+}
9864+
9865+static inline
9866+int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9867+{
9868+ return 1;
9869+}
9870+
9871+static inline
9872+int nx_info_has_v6(struct nx_info *nxi)
9873+{
9874+ return 0;
9875+}
9876+
9877+#endif /* CONFIG_IPV6 */
9878+
9879+#define current_nx_info_has_v6() \
9880+ nx_info_has_v6(current_nx_info())
9881+
9882+#else
9883+#warning duplicate inclusion
9884+#endif
9885diff -NurpP --minimal linux-3.6.6/include/linux/vs_limit.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_limit.h
9886--- linux-3.6.6/include/linux/vs_limit.h 1970-01-01 01:00:00.000000000 +0100
9887+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_limit.h 2012-10-04 18:47:00.000000000 +0200
9888@@ -0,0 +1,140 @@
9889+#ifndef _VS_LIMIT_H
9890+#define _VS_LIMIT_H
9891+
9892+#include "vserver/limit.h"
9893+#include "vserver/base.h"
9894+#include "vserver/context.h"
9895+#include "vserver/debug.h"
9896+#include "vserver/context.h"
9897+#include "vserver/limit_int.h"
9898+
9899+
9900+#define vx_acc_cres(v, d, p, r) \
9901+ __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9902+
9903+#define vx_acc_cres_cond(x, d, p, r) \
9904+ __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9905+ r, d, p, __FILE__, __LINE__)
9906+
9907+
9908+#define vx_add_cres(v, a, p, r) \
9909+ __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9910+#define vx_sub_cres(v, a, p, r) vx_add_cres(v, -(a), p, r)
9911+
9912+#define vx_add_cres_cond(x, a, p, r) \
9913+ __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9914+ r, a, p, __FILE__, __LINE__)
9915+#define vx_sub_cres_cond(x, a, p, r) vx_add_cres_cond(x, -(a), p, r)
9916+
9917+
9918+/* process and file limits */
9919+
9920+#define vx_nproc_inc(p) \
9921+ vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9922+
9923+#define vx_nproc_dec(p) \
9924+ vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9925+
9926+#define vx_files_inc(f) \
9927+ vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9928+
9929+#define vx_files_dec(f) \
9930+ vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9931+
9932+#define vx_locks_inc(l) \
9933+ vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9934+
9935+#define vx_locks_dec(l) \
9936+ vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9937+
9938+#define vx_openfd_inc(f) \
9939+ vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9940+
9941+#define vx_openfd_dec(f) \
9942+ vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9943+
9944+
9945+#define vx_cres_avail(v, n, r) \
9946+ __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9947+
9948+
9949+#define vx_nproc_avail(n) \
9950+ vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9951+
9952+#define vx_files_avail(n) \
9953+ vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9954+
9955+#define vx_locks_avail(n) \
9956+ vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9957+
9958+#define vx_openfd_avail(n) \
9959+ vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9960+
9961+
9962+/* dentry limits */
9963+
9964+#define vx_dentry_inc(d) do { \
9965+ if ((d)->d_count == 1) \
9966+ vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY); \
9967+ } while (0)
9968+
9969+#define vx_dentry_dec(d) do { \
9970+ if ((d)->d_count == 0) \
9971+ vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY); \
9972+ } while (0)
9973+
9974+#define vx_dentry_avail(n) \
9975+ vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9976+
9977+
9978+/* socket limits */
9979+
9980+#define vx_sock_inc(s) \
9981+ vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9982+
9983+#define vx_sock_dec(s) \
9984+ vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9985+
9986+#define vx_sock_avail(n) \
9987+ vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9988+
9989+
9990+/* ipc resource limits */
9991+
9992+#define vx_ipcmsg_add(v, u, a) \
9993+ vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9994+
9995+#define vx_ipcmsg_sub(v, u, a) \
9996+ vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9997+
9998+#define vx_ipcmsg_avail(v, a) \
9999+ vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10000+
10001+
10002+#define vx_ipcshm_add(v, k, a) \
10003+ vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10004+
10005+#define vx_ipcshm_sub(v, k, a) \
10006+ vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10007+
10008+#define vx_ipcshm_avail(v, a) \
10009+ vx_cres_avail(v, a, VLIMIT_SHMEM)
10010+
10011+
10012+#define vx_semary_inc(a) \
10013+ vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10014+
10015+#define vx_semary_dec(a) \
10016+ vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10017+
10018+
10019+#define vx_nsems_add(a,n) \
10020+ vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10021+
10022+#define vx_nsems_sub(a,n) \
10023+ vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10024+
10025+
10026+#else
10027+#warning duplicate inclusion
10028+#endif
10029diff -NurpP --minimal linux-3.6.6/include/linux/vs_network.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_network.h
10030--- linux-3.6.6/include/linux/vs_network.h 1970-01-01 01:00:00.000000000 +0100
10031+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_network.h 2012-10-04 18:47:00.000000000 +0200
10032@@ -0,0 +1,169 @@
10033+#ifndef _NX_VS_NETWORK_H
10034+#define _NX_VS_NETWORK_H
10035+
10036+#include "vserver/context.h"
10037+#include "vserver/network.h"
10038+#include "vserver/base.h"
10039+#include "vserver/check.h"
10040+#include "vserver/debug.h"
10041+
10042+#include <linux/sched.h>
10043+
10044+
10045+#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10046+
10047+static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10048+ const char *_file, int _line)
10049+{
10050+ if (!nxi)
10051+ return NULL;
10052+
10053+ vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10054+ nxi, nxi ? nxi->nx_id : 0,
10055+ nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10056+ _file, _line);
10057+
10058+ atomic_inc(&nxi->nx_usecnt);
10059+ return nxi;
10060+}
10061+
10062+
10063+extern void free_nx_info(struct nx_info *);
10064+
10065+#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10066+
10067+static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10068+{
10069+ if (!nxi)
10070+ return;
10071+
10072+ vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10073+ nxi, nxi ? nxi->nx_id : 0,
10074+ nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10075+ _file, _line);
10076+
10077+ if (atomic_dec_and_test(&nxi->nx_usecnt))
10078+ free_nx_info(nxi);
10079+}
10080+
10081+
10082+#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10083+
10084+static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10085+ const char *_file, int _line)
10086+{
10087+ if (nxi) {
10088+ vxlprintk(VXD_CBIT(nid, 3),
10089+ "init_nx_info(%p[#%d.%d])",
10090+ nxi, nxi ? nxi->nx_id : 0,
10091+ nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10092+ _file, _line);
10093+
10094+ atomic_inc(&nxi->nx_usecnt);
10095+ }
10096+ *nxp = nxi;
10097+}
10098+
10099+
10100+#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10101+
10102+static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10103+ const char *_file, int _line)
10104+{
10105+ struct nx_info *nxo;
10106+
10107+ if (!nxi)
10108+ return;
10109+
10110+ vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10111+ nxi, nxi ? nxi->nx_id : 0,
10112+ nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10113+ _file, _line);
10114+
10115+ atomic_inc(&nxi->nx_usecnt);
10116+ nxo = xchg(nxp, nxi);
10117+ BUG_ON(nxo);
10118+}
10119+
10120+#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10121+
10122+static inline void __clr_nx_info(struct nx_info **nxp,
10123+ const char *_file, int _line)
10124+{
10125+ struct nx_info *nxo;
10126+
10127+ nxo = xchg(nxp, NULL);
10128+ if (!nxo)
10129+ return;
10130+
10131+ vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10132+ nxo, nxo ? nxo->nx_id : 0,
10133+ nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10134+ _file, _line);
10135+
10136+ if (atomic_dec_and_test(&nxo->nx_usecnt))
10137+ free_nx_info(nxo);
10138+}
10139+
10140+
10141+#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10142+
10143+static inline void __claim_nx_info(struct nx_info *nxi,
10144+ struct task_struct *task, const char *_file, int _line)
10145+{
10146+ vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10147+ nxi, nxi ? nxi->nx_id : 0,
10148+ nxi?atomic_read(&nxi->nx_usecnt):0,
10149+ nxi?atomic_read(&nxi->nx_tasks):0,
10150+ task, _file, _line);
10151+
10152+ atomic_inc(&nxi->nx_tasks);
10153+}
10154+
10155+
10156+extern void unhash_nx_info(struct nx_info *);
10157+
10158+#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10159+
10160+static inline void __release_nx_info(struct nx_info *nxi,
10161+ struct task_struct *task, const char *_file, int _line)
10162+{
10163+ vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10164+ nxi, nxi ? nxi->nx_id : 0,
10165+ nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10166+ nxi ? atomic_read(&nxi->nx_tasks) : 0,
10167+ task, _file, _line);
10168+
10169+ might_sleep();
10170+
10171+ if (atomic_dec_and_test(&nxi->nx_tasks))
10172+ unhash_nx_info(nxi);
10173+}
10174+
10175+
10176+#define task_get_nx_info(i) __task_get_nx_info(i, __FILE__, __LINE__)
10177+
10178+static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10179+ const char *_file, int _line)
10180+{
10181+ struct nx_info *nxi;
10182+
10183+ task_lock(p);
10184+ vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10185+ p, _file, _line);
10186+ nxi = __get_nx_info(p->nx_info, _file, _line);
10187+ task_unlock(p);
10188+ return nxi;
10189+}
10190+
10191+
10192+static inline void exit_nx_info(struct task_struct *p)
10193+{
10194+ if (p->nx_info)
10195+ release_nx_info(p->nx_info, p);
10196+}
10197+
10198+
10199+#else
10200+#warning duplicate inclusion
10201+#endif
10202diff -NurpP --minimal linux-3.6.6/include/linux/vs_pid.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_pid.h
10203--- linux-3.6.6/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
10204+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_pid.h 2012-10-04 18:47:00.000000000 +0200
10205@@ -0,0 +1,50 @@
10206+#ifndef _VS_PID_H
10207+#define _VS_PID_H
10208+
10209+#include "vserver/base.h"
10210+#include "vserver/check.h"
10211+#include "vserver/context.h"
10212+#include "vserver/debug.h"
10213+#include "vserver/pid.h"
10214+#include <linux/pid_namespace.h>
10215+
10216+
10217+#define VXF_FAKE_INIT (VXF_INFO_INIT | VXF_STATE_INIT)
10218+
10219+static inline
10220+int vx_proc_task_visible(struct task_struct *task)
10221+{
10222+ if ((task->pid == 1) &&
10223+ !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10224+ /* show a blend through init */
10225+ goto visible;
10226+ if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10227+ goto visible;
10228+ return 0;
10229+visible:
10230+ return 1;
10231+}
10232+
10233+#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10234+
10235+
10236+static inline
10237+struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10238+{
10239+ struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10240+
10241+ if (task && !vx_proc_task_visible(task)) {
10242+ vxdprintk(VXD_CBIT(misc, 6),
10243+ "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10244+ task, task->xid, task->pid,
10245+ current, current->xid, current->pid);
10246+ put_task_struct(task);
10247+ task = NULL;
10248+ }
10249+ return task;
10250+}
10251+
10252+
10253+#else
10254+#warning duplicate inclusion
10255+#endif
10256diff -NurpP --minimal linux-3.6.6/include/linux/vs_sched.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_sched.h
10257--- linux-3.6.6/include/linux/vs_sched.h 1970-01-01 01:00:00.000000000 +0100
10258+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_sched.h 2012-10-04 18:47:00.000000000 +0200
10259@@ -0,0 +1,40 @@
10260+#ifndef _VS_SCHED_H
10261+#define _VS_SCHED_H
10262+
10263+#include "vserver/base.h"
10264+#include "vserver/context.h"
10265+#include "vserver/sched.h"
10266+
10267+
10268+#define MAX_PRIO_BIAS 20
10269+#define MIN_PRIO_BIAS -20
10270+
10271+static inline
10272+int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10273+{
10274+ struct vx_info *vxi = p->vx_info;
10275+
10276+ if (vxi)
10277+ prio += vx_cpu(vxi, sched_pc).prio_bias;
10278+ return prio;
10279+}
10280+
10281+static inline void vx_account_user(struct vx_info *vxi,
10282+ cputime_t cputime, int nice)
10283+{
10284+ if (!vxi)
10285+ return;
10286+ vx_cpu(vxi, sched_pc).user_ticks += cputime;
10287+}
10288+
10289+static inline void vx_account_system(struct vx_info *vxi,
10290+ cputime_t cputime, int idle)
10291+{
10292+ if (!vxi)
10293+ return;
10294+ vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10295+}
10296+
10297+#else
10298+#warning duplicate inclusion
10299+#endif
10300diff -NurpP --minimal linux-3.6.6/include/linux/vs_socket.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_socket.h
10301--- linux-3.6.6/include/linux/vs_socket.h 1970-01-01 01:00:00.000000000 +0100
10302+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_socket.h 2012-10-04 18:47:00.000000000 +0200
10303@@ -0,0 +1,67 @@
10304+#ifndef _VS_SOCKET_H
10305+#define _VS_SOCKET_H
10306+
10307+#include "vserver/debug.h"
10308+#include "vserver/base.h"
10309+#include "vserver/cacct.h"
10310+#include "vserver/context.h"
10311+#include "vserver/tag.h"
10312+
10313+
10314+/* socket accounting */
10315+
10316+#include <linux/socket.h>
10317+
10318+static inline int vx_sock_type(int family)
10319+{
10320+ switch (family) {
10321+ case PF_UNSPEC:
10322+ return VXA_SOCK_UNSPEC;
10323+ case PF_UNIX:
10324+ return VXA_SOCK_UNIX;
10325+ case PF_INET:
10326+ return VXA_SOCK_INET;
10327+ case PF_INET6:
10328+ return VXA_SOCK_INET6;
10329+ case PF_PACKET:
10330+ return VXA_SOCK_PACKET;
10331+ default:
10332+ return VXA_SOCK_OTHER;
10333+ }
10334+}
10335+
10336+#define vx_acc_sock(v, f, p, s) \
10337+ __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10338+
10339+static inline void __vx_acc_sock(struct vx_info *vxi,
10340+ int family, int pos, int size, char *file, int line)
10341+{
10342+ if (vxi) {
10343+ int type = vx_sock_type(family);
10344+
10345+ atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10346+ atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10347+ }
10348+}
10349+
10350+#define vx_sock_recv(sk, s) \
10351+ vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10352+#define vx_sock_send(sk, s) \
10353+ vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10354+#define vx_sock_fail(sk, s) \
10355+ vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10356+
10357+
10358+#define sock_vx_init(s) do { \
10359+ (s)->sk_xid = 0; \
10360+ (s)->sk_vx_info = NULL; \
10361+ } while (0)
10362+
10363+#define sock_nx_init(s) do { \
10364+ (s)->sk_nid = 0; \
10365+ (s)->sk_nx_info = NULL; \
10366+ } while (0)
10367+
10368+#else
10369+#warning duplicate inclusion
10370+#endif
10371diff -NurpP --minimal linux-3.6.6/include/linux/vs_tag.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_tag.h
10372--- linux-3.6.6/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
10373+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_tag.h 2012-10-04 18:47:00.000000000 +0200
10374@@ -0,0 +1,47 @@
10375+#ifndef _VS_TAG_H
10376+#define _VS_TAG_H
10377+
10378+#include <linux/vserver/tag.h>
10379+
10380+/* check conditions */
10381+
10382+#define DX_ADMIN 0x0001
10383+#define DX_WATCH 0x0002
10384+#define DX_HOSTID 0x0008
10385+
10386+#define DX_IDENT 0x0010
10387+
10388+#define DX_ARG_MASK 0x0010
10389+
10390+
10391+#define dx_task_tag(t) ((t)->tag)
10392+
10393+#define dx_current_tag() dx_task_tag(current)
10394+
10395+#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10396+
10397+#define dx_weak_check(c, m) ((m) ? dx_check(c, m) : 1)
10398+
10399+
10400+/*
10401+ * check current context for ADMIN/WATCH and
10402+ * optionally against supplied argument
10403+ */
10404+static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10405+{
10406+ if (mode & DX_ARG_MASK) {
10407+ if ((mode & DX_IDENT) && (id == cid))
10408+ return 1;
10409+ }
10410+ return (((mode & DX_ADMIN) && (cid == 0)) ||
10411+ ((mode & DX_WATCH) && (cid == 1)) ||
10412+ ((mode & DX_HOSTID) && (id == 0)));
10413+}
10414+
10415+struct inode;
10416+int dx_permission(const struct inode *inode, int mask);
10417+
10418+
10419+#else
10420+#warning duplicate inclusion
10421+#endif
10422diff -NurpP --minimal linux-3.6.6/include/linux/vs_time.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_time.h
10423--- linux-3.6.6/include/linux/vs_time.h 1970-01-01 01:00:00.000000000 +0100
10424+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vs_time.h 2012-10-04 18:47:00.000000000 +0200
10425@@ -0,0 +1,19 @@
10426+#ifndef _VS_TIME_H
10427+#define _VS_TIME_H
10428+
10429+
10430+/* time faking stuff */
10431+
10432+#ifdef CONFIG_VSERVER_VTIME
10433+
10434+extern void vx_adjust_timespec(struct timespec *ts);
10435+extern int vx_settimeofday(const struct timespec *ts);
10436+
10437+#else
10438+#define vx_adjust_timespec(t) do { } while (0)
10439+#define vx_settimeofday(t) do_settimeofday(t)
10440+#endif
10441+
10442+#else
10443+#warning duplicate inclusion
10444+#endif
10445diff -NurpP --minimal linux-3.6.6/include/linux/vserver/Kbuild linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/Kbuild
10446--- linux-3.6.6/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
10447+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/Kbuild 2012-10-04 18:47:00.000000000 +0200
10448@@ -0,0 +1,8 @@
10449+
10450+header-y += context_cmd.h network_cmd.h space_cmd.h \
10451+ cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10452+ inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10453+ debug_cmd.h device_cmd.h
10454+
10455+header-y += switch.h network.h monitor.h inode.h device.h
10456+
10457diff -NurpP --minimal linux-3.6.6/include/linux/vserver/base.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/base.h
10458--- linux-3.6.6/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
10459+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/base.h 2012-10-04 18:47:00.000000000 +0200
10460@@ -0,0 +1,178 @@
10461+#ifndef _VX_BASE_H
10462+#define _VX_BASE_H
10463+
10464+
10465+/* context state changes */
10466+
10467+enum {
10468+ VSC_STARTUP = 1,
10469+ VSC_SHUTDOWN,
10470+
10471+ VSC_NETUP,
10472+ VSC_NETDOWN,
10473+};
10474+
10475+
10476+
10477+#define vx_task_xid(t) ((t)->xid)
10478+
10479+#define vx_current_xid() vx_task_xid(current)
10480+
10481+#define current_vx_info() (current->vx_info)
10482+
10483+
10484+#define nx_task_nid(t) ((t)->nid)
10485+
10486+#define nx_current_nid() nx_task_nid(current)
10487+
10488+#define current_nx_info() (current->nx_info)
10489+
10490+
10491+/* generic flag merging */
10492+
10493+#define vs_check_flags(v, m, f) (((v) & (m)) ^ (f))
10494+
10495+#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10496+
10497+#define vs_mask_mask(v, f, m) (((v) & ~(m)) | ((v) & (f) & (m)))
10498+
10499+#define vs_check_bit(v, n) ((v) & (1LL << (n)))
10500+
10501+
10502+/* context flags */
10503+
10504+#define __vx_flags(v) ((v) ? (v)->vx_flags : 0)
10505+
10506+#define vx_current_flags() __vx_flags(current_vx_info())
10507+
10508+#define vx_info_flags(v, m, f) \
10509+ vs_check_flags(__vx_flags(v), m, f)
10510+
10511+#define task_vx_flags(t, m, f) \
10512+ ((t) && vx_info_flags((t)->vx_info, m, f))
10513+
10514+#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10515+
10516+
10517+/* context caps */
10518+
10519+#define __vx_ccaps(v) ((v) ? (v)->vx_ccaps : 0)
10520+
10521+#define vx_current_ccaps() __vx_ccaps(current_vx_info())
10522+
10523+#define vx_info_ccaps(v, c) (__vx_ccaps(v) & (c))
10524+
10525+#define vx_ccaps(c) vx_info_ccaps(current_vx_info(), (c))
10526+
10527+
10528+
10529+/* network flags */
10530+
10531+#define __nx_flags(n) ((n) ? (n)->nx_flags : 0)
10532+
10533+#define nx_current_flags() __nx_flags(current_nx_info())
10534+
10535+#define nx_info_flags(n, m, f) \
10536+ vs_check_flags(__nx_flags(n), m, f)
10537+
10538+#define task_nx_flags(t, m, f) \
10539+ ((t) && nx_info_flags((t)->nx_info, m, f))
10540+
10541+#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10542+
10543+
10544+/* network caps */
10545+
10546+#define __nx_ncaps(n) ((n) ? (n)->nx_ncaps : 0)
10547+
10548+#define nx_current_ncaps() __nx_ncaps(current_nx_info())
10549+
10550+#define nx_info_ncaps(n, c) (__nx_ncaps(n) & (c))
10551+
10552+#define nx_ncaps(c) nx_info_ncaps(current_nx_info(), c)
10553+
10554+
10555+/* context mask capabilities */
10556+
10557+#define __vx_mcaps(v) ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10558+
10559+#define vx_info_mcaps(v, c) (__vx_mcaps(v) & (c))
10560+
10561+#define vx_mcaps(c) vx_info_mcaps(current_vx_info(), c)
10562+
10563+
10564+/* context bcap mask */
10565+
10566+#define __vx_bcaps(v) ((v)->vx_bcaps)
10567+
10568+#define vx_current_bcaps() __vx_bcaps(current_vx_info())
10569+
10570+
10571+/* mask given bcaps */
10572+
10573+#define vx_info_mbcaps(v, c) ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10574+
10575+#define vx_mbcaps(c) vx_info_mbcaps(current_vx_info(), c)
10576+
10577+
10578+/* masked cap_bset */
10579+
10580+#define vx_info_cap_bset(v) vx_info_mbcaps(v, current->cap_bset)
10581+
10582+#define vx_current_cap_bset() vx_info_cap_bset(current_vx_info())
10583+
10584+#if 0
10585+#define vx_info_mbcap(v, b) \
10586+ (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10587+ vx_info_bcaps(v, b) : (b))
10588+
10589+#define task_vx_mbcap(t, b) \
10590+ vx_info_mbcap((t)->vx_info, (t)->b)
10591+
10592+#define vx_mbcap(b) task_vx_mbcap(current, b)
10593+#endif
10594+
10595+#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10596+
10597+#define vx_capable(b, c) (capable(b) || \
10598+ (cap_raised(current_cap(), b) && vx_ccaps(c)))
10599+
10600+#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10601+ (cap_raised(current_cap(), b) && vx_ccaps(c)))
10602+
10603+#define nx_capable(b, c) (capable(b) || \
10604+ (cap_raised(current_cap(), b) && nx_ncaps(c)))
10605+
10606+#define vx_task_initpid(t, n) \
10607+ ((t)->vx_info && \
10608+ ((t)->vx_info->vx_initpid == (n)))
10609+
10610+#define vx_current_initpid(n) vx_task_initpid(current, n)
10611+
10612+
10613+/* context unshare mask */
10614+
10615+#define __vx_umask(v) ((v)->vx_umask)
10616+
10617+#define vx_current_umask() __vx_umask(current_vx_info())
10618+
10619+#define vx_can_unshare(b, f) (capable(b) || \
10620+ (cap_raised(current_cap(), b) && \
10621+ !((f) & ~vx_current_umask())))
10622+
10623+
10624+#define __vx_wmask(v) ((v)->vx_wmask)
10625+
10626+#define vx_current_wmask() __vx_wmask(current_vx_info())
10627+
10628+
10629+#define __vx_state(v) ((v) ? ((v)->vx_state) : 0)
10630+
10631+#define vx_info_state(v, m) (__vx_state(v) & (m))
10632+
10633+
10634+#define __nx_state(n) ((n) ? ((n)->nx_state) : 0)
10635+
10636+#define nx_info_state(n, m) (__nx_state(n) & (m))
10637+
10638+#endif
10639diff -NurpP --minimal linux-3.6.6/include/linux/vserver/cacct.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cacct.h
10640--- linux-3.6.6/include/linux/vserver/cacct.h 1970-01-01 01:00:00.000000000 +0100
10641+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cacct.h 2012-10-04 18:47:00.000000000 +0200
10642@@ -0,0 +1,15 @@
10643+#ifndef _VX_CACCT_H
10644+#define _VX_CACCT_H
10645+
10646+
10647+enum sock_acc_field {
10648+ VXA_SOCK_UNSPEC = 0,
10649+ VXA_SOCK_UNIX,
10650+ VXA_SOCK_INET,
10651+ VXA_SOCK_INET6,
10652+ VXA_SOCK_PACKET,
10653+ VXA_SOCK_OTHER,
10654+ VXA_SOCK_SIZE /* array size */
10655+};
10656+
10657+#endif /* _VX_CACCT_H */
10658diff -NurpP --minimal linux-3.6.6/include/linux/vserver/cacct_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cacct_cmd.h
10659--- linux-3.6.6/include/linux/vserver/cacct_cmd.h 1970-01-01 01:00:00.000000000 +0100
10660+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cacct_cmd.h 2012-10-04 18:47:00.000000000 +0200
10661@@ -0,0 +1,23 @@
10662+#ifndef _VX_CACCT_CMD_H
10663+#define _VX_CACCT_CMD_H
10664+
10665+
10666+/* virtual host info name commands */
10667+
10668+#define VCMD_sock_stat VC_CMD(VSTAT, 5, 0)
10669+
10670+struct vcmd_sock_stat_v0 {
10671+ uint32_t field;
10672+ uint32_t count[3];
10673+ uint64_t total[3];
10674+};
10675+
10676+
10677+#ifdef __KERNEL__
10678+
10679+#include <linux/compiler.h>
10680+
10681+extern int vc_sock_stat(struct vx_info *, void __user *);
10682+
10683+#endif /* __KERNEL__ */
10684+#endif /* _VX_CACCT_CMD_H */
10685diff -NurpP --minimal linux-3.6.6/include/linux/vserver/cacct_def.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cacct_def.h
10686--- linux-3.6.6/include/linux/vserver/cacct_def.h 1970-01-01 01:00:00.000000000 +0100
10687+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cacct_def.h 2012-10-04 18:47:00.000000000 +0200
10688@@ -0,0 +1,43 @@
10689+#ifndef _VX_CACCT_DEF_H
10690+#define _VX_CACCT_DEF_H
10691+
10692+#include <asm/atomic.h>
10693+#include <linux/vserver/cacct.h>
10694+
10695+
10696+struct _vx_sock_acc {
10697+ atomic_long_t count;
10698+ atomic_long_t total;
10699+};
10700+
10701+/* context sub struct */
10702+
10703+struct _vx_cacct {
10704+ struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10705+ atomic_t slab[8];
10706+ atomic_t page[6][8];
10707+};
10708+
10709+#ifdef CONFIG_VSERVER_DEBUG
10710+
10711+static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10712+{
10713+ int i, j;
10714+
10715+ printk("\t_vx_cacct:");
10716+ for (i = 0; i < 6; i++) {
10717+ struct _vx_sock_acc *ptr = cacct->sock[i];
10718+
10719+ printk("\t [%d] =", i);
10720+ for (j = 0; j < 3; j++) {
10721+ printk(" [%d] = %8lu, %8lu", j,
10722+ atomic_long_read(&ptr[j].count),
10723+ atomic_long_read(&ptr[j].total));
10724+ }
10725+ printk("\n");
10726+ }
10727+}
10728+
10729+#endif
10730+
10731+#endif /* _VX_CACCT_DEF_H */
10732diff -NurpP --minimal linux-3.6.6/include/linux/vserver/cacct_int.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cacct_int.h
10733--- linux-3.6.6/include/linux/vserver/cacct_int.h 1970-01-01 01:00:00.000000000 +0100
10734+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cacct_int.h 2012-10-04 18:47:00.000000000 +0200
10735@@ -0,0 +1,21 @@
10736+#ifndef _VX_CACCT_INT_H
10737+#define _VX_CACCT_INT_H
10738+
10739+
10740+#ifdef __KERNEL__
10741+
10742+static inline
10743+unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10744+{
10745+ return atomic_long_read(&cacct->sock[type][pos].count);
10746+}
10747+
10748+
10749+static inline
10750+unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10751+{
10752+ return atomic_long_read(&cacct->sock[type][pos].total);
10753+}
10754+
10755+#endif /* __KERNEL__ */
10756+#endif /* _VX_CACCT_INT_H */
10757diff -NurpP --minimal linux-3.6.6/include/linux/vserver/check.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/check.h
10758--- linux-3.6.6/include/linux/vserver/check.h 1970-01-01 01:00:00.000000000 +0100
10759+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/check.h 2012-10-04 18:47:00.000000000 +0200
10760@@ -0,0 +1,89 @@
10761+#ifndef _VS_CHECK_H
10762+#define _VS_CHECK_H
10763+
10764+
10765+#define MAX_S_CONTEXT 65535 /* Arbitrary limit */
10766+
10767+#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10768+#define MIN_D_CONTEXT 49152 /* dynamic contexts start here */
10769+#else
10770+#define MIN_D_CONTEXT 65536
10771+#endif
10772+
10773+/* check conditions */
10774+
10775+#define VS_ADMIN 0x0001
10776+#define VS_WATCH 0x0002
10777+#define VS_HIDE 0x0004
10778+#define VS_HOSTID 0x0008
10779+
10780+#define VS_IDENT 0x0010
10781+#define VS_EQUIV 0x0020
10782+#define VS_PARENT 0x0040
10783+#define VS_CHILD 0x0080
10784+
10785+#define VS_ARG_MASK 0x00F0
10786+
10787+#define VS_DYNAMIC 0x0100
10788+#define VS_STATIC 0x0200
10789+
10790+#define VS_ATR_MASK 0x0F00
10791+
10792+#ifdef CONFIG_VSERVER_PRIVACY
10793+#define VS_ADMIN_P (0)
10794+#define VS_WATCH_P (0)
10795+#else
10796+#define VS_ADMIN_P VS_ADMIN
10797+#define VS_WATCH_P VS_WATCH
10798+#endif
10799+
10800+#define VS_HARDIRQ 0x1000
10801+#define VS_SOFTIRQ 0x2000
10802+#define VS_IRQ 0x4000
10803+
10804+#define VS_IRQ_MASK 0xF000
10805+
10806+#include <linux/hardirq.h>
10807+
10808+/*
10809+ * check current context for ADMIN/WATCH and
10810+ * optionally against supplied argument
10811+ */
10812+static inline int __vs_check(int cid, int id, unsigned int mode)
10813+{
10814+ if (mode & VS_ARG_MASK) {
10815+ if ((mode & VS_IDENT) && (id == cid))
10816+ return 1;
10817+ }
10818+ if (mode & VS_ATR_MASK) {
10819+ if ((mode & VS_DYNAMIC) &&
10820+ (id >= MIN_D_CONTEXT) &&
10821+ (id <= MAX_S_CONTEXT))
10822+ return 1;
10823+ if ((mode & VS_STATIC) &&
10824+ (id > 1) && (id < MIN_D_CONTEXT))
10825+ return 1;
10826+ }
10827+ if (mode & VS_IRQ_MASK) {
10828+ if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10829+ return 1;
10830+ if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10831+ return 1;
10832+ if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10833+ return 1;
10834+ }
10835+ return (((mode & VS_ADMIN) && (cid == 0)) ||
10836+ ((mode & VS_WATCH) && (cid == 1)) ||
10837+ ((mode & VS_HOSTID) && (id == 0)));
10838+}
10839+
10840+#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10841+
10842+#define vx_weak_check(c, m) ((m) ? vx_check(c, m) : 1)
10843+
10844+
10845+#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10846+
10847+#define nx_weak_check(c, m) ((m) ? nx_check(c, m) : 1)
10848+
10849+#endif
10850diff -NurpP --minimal linux-3.6.6/include/linux/vserver/context.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/context.h
10851--- linux-3.6.6/include/linux/vserver/context.h 1970-01-01 01:00:00.000000000 +0100
10852+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/context.h 2012-10-04 18:47:00.000000000 +0200
10853@@ -0,0 +1,188 @@
10854+#ifndef _VX_CONTEXT_H
10855+#define _VX_CONTEXT_H
10856+
10857+#include <linux/types.h>
10858+#include <linux/capability.h>
10859+
10860+
10861+/* context flags */
10862+
10863+#define VXF_INFO_SCHED 0x00000002
10864+#define VXF_INFO_NPROC 0x00000004
10865+#define VXF_INFO_PRIVATE 0x00000008
10866+
10867+#define VXF_INFO_INIT 0x00000010
10868+#define VXF_INFO_HIDE 0x00000020
10869+#define VXF_INFO_ULIMIT 0x00000040
10870+#define VXF_INFO_NSPACE 0x00000080
10871+
10872+#define VXF_SCHED_HARD 0x00000100
10873+#define VXF_SCHED_PRIO 0x00000200
10874+#define VXF_SCHED_PAUSE 0x00000400
10875+
10876+#define VXF_VIRT_MEM 0x00010000
10877+#define VXF_VIRT_UPTIME 0x00020000
10878+#define VXF_VIRT_CPU 0x00040000
10879+#define VXF_VIRT_LOAD 0x00080000
10880+#define VXF_VIRT_TIME 0x00100000
10881+
10882+#define VXF_HIDE_MOUNT 0x01000000
10883+/* was VXF_HIDE_NETIF 0x02000000 */
10884+#define VXF_HIDE_VINFO 0x04000000
10885+
10886+#define VXF_STATE_SETUP (1ULL << 32)
10887+#define VXF_STATE_INIT (1ULL << 33)
10888+#define VXF_STATE_ADMIN (1ULL << 34)
10889+
10890+#define VXF_SC_HELPER (1ULL << 36)
10891+#define VXF_REBOOT_KILL (1ULL << 37)
10892+#define VXF_PERSISTENT (1ULL << 38)
10893+
10894+#define VXF_FORK_RSS (1ULL << 48)
10895+#define VXF_PROLIFIC (1ULL << 49)
10896+
10897+#define VXF_IGNEG_NICE (1ULL << 52)
10898+
10899+#define VXF_ONE_TIME (0x0007ULL << 32)
10900+
10901+#define VXF_INIT_SET (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10902+
10903+
10904+/* context migration */
10905+
10906+#define VXM_SET_INIT 0x00000001
10907+#define VXM_SET_REAPER 0x00000002
10908+
10909+/* context caps */
10910+
10911+#define VXC_SET_UTSNAME 0x00000001
10912+#define VXC_SET_RLIMIT 0x00000002
10913+#define VXC_FS_SECURITY 0x00000004
10914+#define VXC_FS_TRUSTED 0x00000008
10915+#define VXC_TIOCSTI 0x00000010
10916+
10917+/* was VXC_RAW_ICMP 0x00000100 */
10918+#define VXC_SYSLOG 0x00001000
10919+#define VXC_OOM_ADJUST 0x00002000
10920+#define VXC_AUDIT_CONTROL 0x00004000
10921+
10922+#define VXC_SECURE_MOUNT 0x00010000
10923+#define VXC_SECURE_REMOUNT 0x00020000
10924+#define VXC_BINARY_MOUNT 0x00040000
10925+
10926+#define VXC_QUOTA_CTL 0x00100000
10927+#define VXC_ADMIN_MAPPER 0x00200000
10928+#define VXC_ADMIN_CLOOP 0x00400000
10929+
10930+#define VXC_KTHREAD 0x01000000
10931+#define VXC_NAMESPACE 0x02000000
10932+
10933+
10934+#ifdef __KERNEL__
10935+
10936+#include <linux/list.h>
10937+#include <linux/spinlock.h>
10938+#include <linux/rcupdate.h>
10939+
10940+#include "limit_def.h"
10941+#include "sched_def.h"
10942+#include "cvirt_def.h"
10943+#include "cacct_def.h"
10944+#include "device_def.h"
10945+
10946+#define VX_SPACES 2
10947+
10948+struct _vx_info_pc {
10949+ struct _vx_sched_pc sched_pc;
10950+ struct _vx_cvirt_pc cvirt_pc;
10951+};
10952+
10953+struct _vx_space {
10954+ unsigned long vx_nsmask; /* assignment mask */
10955+ struct nsproxy *vx_nsproxy; /* private namespaces */
10956+ struct fs_struct *vx_fs; /* private namespace fs */
10957+ const struct cred *vx_cred; /* task credentials */
10958+};
10959+
10960+struct vx_info {
10961+ struct hlist_node vx_hlist; /* linked list of contexts */
10962+ xid_t vx_id; /* context id */
10963+ atomic_t vx_usecnt; /* usage count */
10964+ atomic_t vx_tasks; /* tasks count */
10965+ struct vx_info *vx_parent; /* parent context */
10966+ int vx_state; /* context state */
10967+
10968+ struct _vx_space space[VX_SPACES]; /* namespace store */
10969+
10970+ uint64_t vx_flags; /* context flags */
10971+ uint64_t vx_ccaps; /* context caps (vserver) */
10972+ uint64_t vx_umask; /* unshare mask (guest) */
10973+ uint64_t vx_wmask; /* warn mask (guest) */
10974+ kernel_cap_t vx_bcaps; /* bounding caps (system) */
10975+
10976+ struct task_struct *vx_reaper; /* guest reaper process */
10977+ pid_t vx_initpid; /* PID of guest init */
10978+ int64_t vx_badness_bias; /* OOM points bias */
10979+
10980+ struct _vx_limit limit; /* vserver limits */
10981+ struct _vx_sched sched; /* vserver scheduler */
10982+ struct _vx_cvirt cvirt; /* virtual/bias stuff */
10983+ struct _vx_cacct cacct; /* context accounting */
10984+
10985+ struct _vx_device dmap; /* default device map targets */
10986+
10987+#ifndef CONFIG_SMP
10988+ struct _vx_info_pc info_pc; /* per cpu data */
10989+#else
10990+ struct _vx_info_pc *ptr_pc; /* per cpu array */
10991+#endif
10992+
10993+ wait_queue_head_t vx_wait; /* context exit waitqueue */
10994+ int reboot_cmd; /* last sys_reboot() cmd */
10995+ int exit_code; /* last process exit code */
10996+
10997+ char vx_name[65]; /* vserver name */
10998+};
10999+
11000+#ifndef CONFIG_SMP
11001+#define vx_ptr_pc(vxi) (&(vxi)->info_pc)
11002+#define vx_per_cpu(vxi, v, id) vx_ptr_pc(vxi)->v
11003+#else
11004+#define vx_ptr_pc(vxi) ((vxi)->ptr_pc)
11005+#define vx_per_cpu(vxi, v, id) per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11006+#endif
11007+
11008+#define vx_cpu(vxi, v) vx_per_cpu(vxi, v, smp_processor_id())
11009+
11010+
11011+struct vx_info_save {
11012+ struct vx_info *vxi;
11013+ xid_t xid;
11014+};
11015+
11016+
11017+/* status flags */
11018+
11019+#define VXS_HASHED 0x0001
11020+#define VXS_PAUSED 0x0010
11021+#define VXS_SHUTDOWN 0x0100
11022+#define VXS_HELPER 0x1000
11023+#define VXS_RELEASED 0x8000
11024+
11025+
11026+extern void claim_vx_info(struct vx_info *, struct task_struct *);
11027+extern void release_vx_info(struct vx_info *, struct task_struct *);
11028+
11029+extern struct vx_info *lookup_vx_info(int);
11030+extern struct vx_info *lookup_or_create_vx_info(int);
11031+
11032+extern int get_xid_list(int, unsigned int *, int);
11033+extern int xid_is_hashed(xid_t);
11034+
11035+extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11036+
11037+extern long vs_state_change(struct vx_info *, unsigned int);
11038+
11039+
11040+#endif /* __KERNEL__ */
11041+#endif /* _VX_CONTEXT_H */
11042diff -NurpP --minimal linux-3.6.6/include/linux/vserver/context_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/context_cmd.h
11043--- linux-3.6.6/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
11044+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/context_cmd.h 2012-10-04 18:47:00.000000000 +0200
11045@@ -0,0 +1,162 @@
11046+#ifndef _VX_CONTEXT_CMD_H
11047+#define _VX_CONTEXT_CMD_H
11048+
11049+
11050+/* vinfo commands */
11051+
11052+#define VCMD_task_xid VC_CMD(VINFO, 1, 0)
11053+
11054+#ifdef __KERNEL__
11055+extern int vc_task_xid(uint32_t);
11056+
11057+#endif /* __KERNEL__ */
11058+
11059+#define VCMD_vx_info VC_CMD(VINFO, 5, 0)
11060+
11061+struct vcmd_vx_info_v0 {
11062+ uint32_t xid;
11063+ uint32_t initpid;
11064+ /* more to come */
11065+};
11066+
11067+#ifdef __KERNEL__
11068+extern int vc_vx_info(struct vx_info *, void __user *);
11069+
11070+#endif /* __KERNEL__ */
11071+
11072+#define VCMD_ctx_stat VC_CMD(VSTAT, 0, 0)
11073+
11074+struct vcmd_ctx_stat_v0 {
11075+ uint32_t usecnt;
11076+ uint32_t tasks;
11077+ /* more to come */
11078+};
11079+
11080+#ifdef __KERNEL__
11081+extern int vc_ctx_stat(struct vx_info *, void __user *);
11082+
11083+#endif /* __KERNEL__ */
11084+
11085+/* context commands */
11086+
11087+#define VCMD_ctx_create_v0 VC_CMD(VPROC, 1, 0)
11088+#define VCMD_ctx_create VC_CMD(VPROC, 1, 1)
11089+
11090+struct vcmd_ctx_create {
11091+ uint64_t flagword;
11092+};
11093+
11094+#define VCMD_ctx_migrate_v0 VC_CMD(PROCMIG, 1, 0)
11095+#define VCMD_ctx_migrate VC_CMD(PROCMIG, 1, 1)
11096+
11097+struct vcmd_ctx_migrate {
11098+ uint64_t flagword;
11099+};
11100+
11101+#ifdef __KERNEL__
11102+extern int vc_ctx_create(uint32_t, void __user *);
11103+extern int vc_ctx_migrate(struct vx_info *, void __user *);
11104+
11105+#endif /* __KERNEL__ */
11106+
11107+
11108+/* flag commands */
11109+
11110+#define VCMD_get_cflags VC_CMD(FLAGS, 1, 0)
11111+#define VCMD_set_cflags VC_CMD(FLAGS, 2, 0)
11112+
11113+struct vcmd_ctx_flags_v0 {
11114+ uint64_t flagword;
11115+ uint64_t mask;
11116+};
11117+
11118+#ifdef __KERNEL__
11119+extern int vc_get_cflags(struct vx_info *, void __user *);
11120+extern int vc_set_cflags(struct vx_info *, void __user *);
11121+
11122+#endif /* __KERNEL__ */
11123+
11124+
11125+/* context caps commands */
11126+
11127+#define VCMD_get_ccaps VC_CMD(FLAGS, 3, 1)
11128+#define VCMD_set_ccaps VC_CMD(FLAGS, 4, 1)
11129+
11130+struct vcmd_ctx_caps_v1 {
11131+ uint64_t ccaps;
11132+ uint64_t cmask;
11133+};
11134+
11135+#ifdef __KERNEL__
11136+extern int vc_get_ccaps(struct vx_info *, void __user *);
11137+extern int vc_set_ccaps(struct vx_info *, void __user *);
11138+
11139+#endif /* __KERNEL__ */
11140+
11141+
11142+/* bcaps commands */
11143+
11144+#define VCMD_get_bcaps VC_CMD(FLAGS, 9, 0)
11145+#define VCMD_set_bcaps VC_CMD(FLAGS, 10, 0)
11146+
11147+struct vcmd_bcaps {
11148+ uint64_t bcaps;
11149+ uint64_t bmask;
11150+};
11151+
11152+#ifdef __KERNEL__
11153+extern int vc_get_bcaps(struct vx_info *, void __user *);
11154+extern int vc_set_bcaps(struct vx_info *, void __user *);
11155+
11156+#endif /* __KERNEL__ */
11157+
11158+
11159+/* umask commands */
11160+
11161+#define VCMD_get_umask VC_CMD(FLAGS, 13, 0)
11162+#define VCMD_set_umask VC_CMD(FLAGS, 14, 0)
11163+
11164+struct vcmd_umask {
11165+ uint64_t umask;
11166+ uint64_t mask;
11167+};
11168+
11169+#ifdef __KERNEL__
11170+extern int vc_get_umask(struct vx_info *, void __user *);
11171+extern int vc_set_umask(struct vx_info *, void __user *);
11172+
11173+#endif /* __KERNEL__ */
11174+
11175+
11176+/* wmask commands */
11177+
11178+#define VCMD_get_wmask VC_CMD(FLAGS, 15, 0)
11179+#define VCMD_set_wmask VC_CMD(FLAGS, 16, 0)
11180+
11181+struct vcmd_wmask {
11182+ uint64_t wmask;
11183+ uint64_t mask;
11184+};
11185+
11186+#ifdef __KERNEL__
11187+extern int vc_get_wmask(struct vx_info *, void __user *);
11188+extern int vc_set_wmask(struct vx_info *, void __user *);
11189+
11190+#endif /* __KERNEL__ */
11191+
11192+
11193+/* OOM badness */
11194+
11195+#define VCMD_get_badness VC_CMD(MEMCTRL, 5, 0)
11196+#define VCMD_set_badness VC_CMD(MEMCTRL, 6, 0)
11197+
11198+struct vcmd_badness_v0 {
11199+ int64_t bias;
11200+};
11201+
11202+#ifdef __KERNEL__
11203+extern int vc_get_badness(struct vx_info *, void __user *);
11204+extern int vc_set_badness(struct vx_info *, void __user *);
11205+
11206+#endif /* __KERNEL__ */
11207+#endif /* _VX_CONTEXT_CMD_H */
11208diff -NurpP --minimal linux-3.6.6/include/linux/vserver/cvirt.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cvirt.h
11209--- linux-3.6.6/include/linux/vserver/cvirt.h 1970-01-01 01:00:00.000000000 +0100
11210+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cvirt.h 2012-10-04 18:47:00.000000000 +0200
11211@@ -0,0 +1,22 @@
11212+#ifndef _VX_CVIRT_H
11213+#define _VX_CVIRT_H
11214+
11215+
11216+#ifdef __KERNEL__
11217+
11218+struct timespec;
11219+
11220+void vx_vsi_boottime(struct timespec *);
11221+
11222+void vx_vsi_uptime(struct timespec *, struct timespec *);
11223+
11224+
11225+struct vx_info;
11226+
11227+void vx_update_load(struct vx_info *);
11228+
11229+
11230+int vx_do_syslog(int, char __user *, int);
11231+
11232+#endif /* __KERNEL__ */
11233+#endif /* _VX_CVIRT_H */
11234diff -NurpP --minimal linux-3.6.6/include/linux/vserver/cvirt_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cvirt_cmd.h
11235--- linux-3.6.6/include/linux/vserver/cvirt_cmd.h 1970-01-01 01:00:00.000000000 +0100
11236+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cvirt_cmd.h 2012-10-04 18:47:00.000000000 +0200
11237@@ -0,0 +1,53 @@
11238+#ifndef _VX_CVIRT_CMD_H
11239+#define _VX_CVIRT_CMD_H
11240+
11241+
11242+/* virtual host info name commands */
11243+
11244+#define VCMD_set_vhi_name VC_CMD(VHOST, 1, 0)
11245+#define VCMD_get_vhi_name VC_CMD(VHOST, 2, 0)
11246+
11247+struct vcmd_vhi_name_v0 {
11248+ uint32_t field;
11249+ char name[65];
11250+};
11251+
11252+
11253+enum vhi_name_field {
11254+ VHIN_CONTEXT = 0,
11255+ VHIN_SYSNAME,
11256+ VHIN_NODENAME,
11257+ VHIN_RELEASE,
11258+ VHIN_VERSION,
11259+ VHIN_MACHINE,
11260+ VHIN_DOMAINNAME,
11261+};
11262+
11263+
11264+#ifdef __KERNEL__
11265+
11266+#include <linux/compiler.h>
11267+
11268+extern int vc_set_vhi_name(struct vx_info *, void __user *);
11269+extern int vc_get_vhi_name(struct vx_info *, void __user *);
11270+
11271+#endif /* __KERNEL__ */
11272+
11273+#define VCMD_virt_stat VC_CMD(VSTAT, 3, 0)
11274+
11275+struct vcmd_virt_stat_v0 {
11276+ uint64_t offset;
11277+ uint64_t uptime;
11278+ uint32_t nr_threads;
11279+ uint32_t nr_running;
11280+ uint32_t nr_uninterruptible;
11281+ uint32_t nr_onhold;
11282+ uint32_t nr_forks;
11283+ uint32_t load[3];
11284+};
11285+
11286+#ifdef __KERNEL__
11287+extern int vc_virt_stat(struct vx_info *, void __user *);
11288+
11289+#endif /* __KERNEL__ */
11290+#endif /* _VX_CVIRT_CMD_H */
11291diff -NurpP --minimal linux-3.6.6/include/linux/vserver/cvirt_def.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cvirt_def.h
11292--- linux-3.6.6/include/linux/vserver/cvirt_def.h 1970-01-01 01:00:00.000000000 +0100
11293+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/cvirt_def.h 2012-10-04 18:47:00.000000000 +0200
11294@@ -0,0 +1,80 @@
11295+#ifndef _VX_CVIRT_DEF_H
11296+#define _VX_CVIRT_DEF_H
11297+
11298+#include <linux/jiffies.h>
11299+#include <linux/spinlock.h>
11300+#include <linux/wait.h>
11301+#include <linux/time.h>
11302+#include <asm/atomic.h>
11303+
11304+
11305+struct _vx_usage_stat {
11306+ uint64_t user;
11307+ uint64_t nice;
11308+ uint64_t system;
11309+ uint64_t softirq;
11310+ uint64_t irq;
11311+ uint64_t idle;
11312+ uint64_t iowait;
11313+};
11314+
11315+struct _vx_syslog {
11316+ wait_queue_head_t log_wait;
11317+ spinlock_t logbuf_lock; /* lock for the log buffer */
11318+
11319+ unsigned long log_start; /* next char to be read by syslog() */
11320+ unsigned long con_start; /* next char to be sent to consoles */
11321+ unsigned long log_end; /* most-recently-written-char + 1 */
11322+ unsigned long logged_chars; /* #chars since last read+clear operation */
11323+
11324+ char log_buf[1024];
11325+};
11326+
11327+
11328+/* context sub struct */
11329+
11330+struct _vx_cvirt {
11331+ atomic_t nr_threads; /* number of current threads */
11332+ atomic_t nr_running; /* number of running threads */
11333+ atomic_t nr_uninterruptible; /* number of uninterruptible threads */
11334+
11335+ atomic_t nr_onhold; /* processes on hold */
11336+ uint32_t onhold_last; /* jiffies when put on hold */
11337+
11338+ struct timespec bias_ts; /* time offset to the host */
11339+ struct timespec bias_idle;
11340+ struct timespec bias_uptime; /* context creation point */
11341+ uint64_t bias_clock; /* offset in clock_t */
11342+
11343+ spinlock_t load_lock; /* lock for the load averages */
11344+ atomic_t load_updates; /* nr of load updates done so far */
11345+ uint32_t load_last; /* last time load was calculated */
11346+ uint32_t load[3]; /* load averages 1,5,15 */
11347+
11348+ atomic_t total_forks; /* number of forks so far */
11349+
11350+ struct _vx_syslog syslog;
11351+};
11352+
11353+struct _vx_cvirt_pc {
11354+ struct _vx_usage_stat cpustat;
11355+};
11356+
11357+
11358+#ifdef CONFIG_VSERVER_DEBUG
11359+
11360+static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11361+{
11362+ printk("\t_vx_cvirt:\n");
11363+ printk("\t threads: %4d, %4d, %4d, %4d\n",
11364+ atomic_read(&cvirt->nr_threads),
11365+ atomic_read(&cvirt->nr_running),
11366+ atomic_read(&cvirt->nr_uninterruptible),
11367+ atomic_read(&cvirt->nr_onhold));
11368+ /* add rest here */
11369+ printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11370+}
11371+
11372+#endif
11373+
11374+#endif /* _VX_CVIRT_DEF_H */
11375diff -NurpP --minimal linux-3.6.6/include/linux/vserver/debug.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/debug.h
11376--- linux-3.6.6/include/linux/vserver/debug.h 1970-01-01 01:00:00.000000000 +0100
11377+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/debug.h 2012-10-04 18:47:00.000000000 +0200
11378@@ -0,0 +1,145 @@
11379+#ifndef _VX_DEBUG_H
11380+#define _VX_DEBUG_H
11381+
11382+
11383+#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11384+#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11385+#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11386+
11387+#define VXD_DEV(d) (d), (d)->bd_inode->i_ino, \
11388+ imajor((d)->bd_inode), iminor((d)->bd_inode)
11389+#define VXF_DEV "%p[%lu,%d:%d]"
11390+
11391+#if defined(CONFIG_QUOTES_UTF8)
11392+#define VS_Q_LQM "\xc2\xbb"
11393+#define VS_Q_RQM "\xc2\xab"
11394+#elif defined(CONFIG_QUOTES_ASCII)
11395+#define VS_Q_LQM "\x27"
11396+#define VS_Q_RQM "\x27"
11397+#else
11398+#define VS_Q_LQM "\xbb"
11399+#define VS_Q_RQM "\xab"
11400+#endif
11401+
11402+#define VS_Q(f) VS_Q_LQM f VS_Q_RQM
11403+
11404+
11405+#define vxd_path(p) \
11406+ ({ static char _buffer[PATH_MAX]; \
11407+ d_path(p, _buffer, sizeof(_buffer)); })
11408+
11409+#define vxd_cond_path(n) \
11410+ ((n) ? vxd_path(&(n)->path) : "<null>" )
11411+
11412+
11413+#ifdef CONFIG_VSERVER_DEBUG
11414+
11415+extern unsigned int vs_debug_switch;
11416+extern unsigned int vs_debug_xid;
11417+extern unsigned int vs_debug_nid;
11418+extern unsigned int vs_debug_tag;
11419+extern unsigned int vs_debug_net;
11420+extern unsigned int vs_debug_limit;
11421+extern unsigned int vs_debug_cres;
11422+extern unsigned int vs_debug_dlim;
11423+extern unsigned int vs_debug_quota;
11424+extern unsigned int vs_debug_cvirt;
11425+extern unsigned int vs_debug_space;
11426+extern unsigned int vs_debug_perm;
11427+extern unsigned int vs_debug_misc;
11428+
11429+
11430+#define VX_LOGLEVEL "vxD: "
11431+#define VX_PROC_FMT "%p: "
11432+#define VX_PROCESS current
11433+
11434+#define vxdprintk(c, f, x...) \
11435+ do { \
11436+ if (c) \
11437+ printk(VX_LOGLEVEL VX_PROC_FMT f "\n", \
11438+ VX_PROCESS , ##x); \
11439+ } while (0)
11440+
11441+#define vxlprintk(c, f, x...) \
11442+ do { \
11443+ if (c) \
11444+ printk(VX_LOGLEVEL f " @%s:%d\n", x); \
11445+ } while (0)
11446+
11447+#define vxfprintk(c, f, x...) \
11448+ do { \
11449+ if (c) \
11450+ printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11451+ } while (0)
11452+
11453+
11454+struct vx_info;
11455+
11456+void dump_vx_info(struct vx_info *, int);
11457+void dump_vx_info_inactive(int);
11458+
11459+#else /* CONFIG_VSERVER_DEBUG */
11460+
11461+#define vs_debug_switch 0
11462+#define vs_debug_xid 0
11463+#define vs_debug_nid 0
11464+#define vs_debug_tag 0
11465+#define vs_debug_net 0
11466+#define vs_debug_limit 0
11467+#define vs_debug_cres 0
11468+#define vs_debug_dlim 0
11469+#define vs_debug_quota 0
11470+#define vs_debug_cvirt 0
11471+#define vs_debug_space 0
11472+#define vs_debug_perm 0
11473+#define vs_debug_misc 0
11474+
11475+#define vxdprintk(x...) do { } while (0)
11476+#define vxlprintk(x...) do { } while (0)
11477+#define vxfprintk(x...) do { } while (0)
11478+
11479+#endif /* CONFIG_VSERVER_DEBUG */
11480+
11481+
11482+#ifdef CONFIG_VSERVER_WARN
11483+
11484+#define VX_WARNLEVEL KERN_WARNING "vxW: "
11485+#define VX_WARN_TASK "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11486+#define VX_WARN_XID "[xid #%u] "
11487+#define VX_WARN_NID "[nid #%u] "
11488+#define VX_WARN_TAG "[tag #%u] "
11489+
11490+#define vxwprintk(c, f, x...) \
11491+ do { \
11492+ if (c) \
11493+ printk(VX_WARNLEVEL f "\n", ##x); \
11494+ } while (0)
11495+
11496+#else /* CONFIG_VSERVER_WARN */
11497+
11498+#define vxwprintk(x...) do { } while (0)
11499+
11500+#endif /* CONFIG_VSERVER_WARN */
11501+
11502+#define vxwprintk_task(c, f, x...) \
11503+ vxwprintk(c, VX_WARN_TASK f, \
11504+ current->comm, current->pid, \
11505+ current->xid, current->nid, current->tag, ##x)
11506+#define vxwprintk_xid(c, f, x...) \
11507+ vxwprintk(c, VX_WARN_XID f, current->xid, x)
11508+#define vxwprintk_nid(c, f, x...) \
11509+ vxwprintk(c, VX_WARN_NID f, current->nid, x)
11510+#define vxwprintk_tag(c, f, x...) \
11511+ vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11512+
11513+#ifdef CONFIG_VSERVER_DEBUG
11514+#define vxd_assert_lock(l) assert_spin_locked(l)
11515+#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11516+ "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11517+#else
11518+#define vxd_assert_lock(l) do { } while (0)
11519+#define vxd_assert(c, f, x...) do { } while (0)
11520+#endif
11521+
11522+
11523+#endif /* _VX_DEBUG_H */
11524diff -NurpP --minimal linux-3.6.6/include/linux/vserver/debug_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/debug_cmd.h
11525--- linux-3.6.6/include/linux/vserver/debug_cmd.h 1970-01-01 01:00:00.000000000 +0100
11526+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/debug_cmd.h 2012-10-04 18:47:00.000000000 +0200
11527@@ -0,0 +1,58 @@
11528+#ifndef _VX_DEBUG_CMD_H
11529+#define _VX_DEBUG_CMD_H
11530+
11531+
11532+/* debug commands */
11533+
11534+#define VCMD_dump_history VC_CMD(DEBUG, 1, 0)
11535+
11536+#define VCMD_read_history VC_CMD(DEBUG, 5, 0)
11537+#define VCMD_read_monitor VC_CMD(DEBUG, 6, 0)
11538+
11539+struct vcmd_read_history_v0 {
11540+ uint32_t index;
11541+ uint32_t count;
11542+ char __user *data;
11543+};
11544+
11545+struct vcmd_read_monitor_v0 {
11546+ uint32_t index;
11547+ uint32_t count;
11548+ char __user *data;
11549+};
11550+
11551+
11552+#ifdef __KERNEL__
11553+
11554+#ifdef CONFIG_COMPAT
11555+
11556+#include <asm/compat.h>
11557+
11558+struct vcmd_read_history_v0_x32 {
11559+ uint32_t index;
11560+ uint32_t count;
11561+ compat_uptr_t data_ptr;
11562+};
11563+
11564+struct vcmd_read_monitor_v0_x32 {
11565+ uint32_t index;
11566+ uint32_t count;
11567+ compat_uptr_t data_ptr;
11568+};
11569+
11570+#endif /* CONFIG_COMPAT */
11571+
11572+extern int vc_dump_history(uint32_t);
11573+
11574+extern int vc_read_history(uint32_t, void __user *);
11575+extern int vc_read_monitor(uint32_t, void __user *);
11576+
11577+#ifdef CONFIG_COMPAT
11578+
11579+extern int vc_read_history_x32(uint32_t, void __user *);
11580+extern int vc_read_monitor_x32(uint32_t, void __user *);
11581+
11582+#endif /* CONFIG_COMPAT */
11583+
11584+#endif /* __KERNEL__ */
11585+#endif /* _VX_DEBUG_CMD_H */
11586diff -NurpP --minimal linux-3.6.6/include/linux/vserver/device.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/device.h
11587--- linux-3.6.6/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11588+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/device.h 2012-10-04 18:47:00.000000000 +0200
11589@@ -0,0 +1,15 @@
11590+#ifndef _VX_DEVICE_H
11591+#define _VX_DEVICE_H
11592+
11593+
11594+#define DATTR_CREATE 0x00000001
11595+#define DATTR_OPEN 0x00000002
11596+
11597+#define DATTR_REMAP 0x00000010
11598+
11599+#define DATTR_MASK 0x00000013
11600+
11601+
11602+#else /* _VX_DEVICE_H */
11603+#warning duplicate inclusion
11604+#endif /* _VX_DEVICE_H */
11605diff -NurpP --minimal linux-3.6.6/include/linux/vserver/device_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/device_cmd.h
11606--- linux-3.6.6/include/linux/vserver/device_cmd.h 1970-01-01 01:00:00.000000000 +0100
11607+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/device_cmd.h 2012-10-04 18:47:00.000000000 +0200
11608@@ -0,0 +1,44 @@
11609+#ifndef _VX_DEVICE_CMD_H
11610+#define _VX_DEVICE_CMD_H
11611+
11612+
11613+/* device vserver commands */
11614+
11615+#define VCMD_set_mapping VC_CMD(DEVICE, 1, 0)
11616+#define VCMD_unset_mapping VC_CMD(DEVICE, 2, 0)
11617+
11618+struct vcmd_set_mapping_v0 {
11619+ const char __user *device;
11620+ const char __user *target;
11621+ uint32_t flags;
11622+};
11623+
11624+
11625+#ifdef __KERNEL__
11626+
11627+#ifdef CONFIG_COMPAT
11628+
11629+#include <asm/compat.h>
11630+
11631+struct vcmd_set_mapping_v0_x32 {
11632+ compat_uptr_t device_ptr;
11633+ compat_uptr_t target_ptr;
11634+ uint32_t flags;
11635+};
11636+
11637+#endif /* CONFIG_COMPAT */
11638+
11639+#include <linux/compiler.h>
11640+
11641+extern int vc_set_mapping(struct vx_info *, void __user *);
11642+extern int vc_unset_mapping(struct vx_info *, void __user *);
11643+
11644+#ifdef CONFIG_COMPAT
11645+
11646+extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11647+extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11648+
11649+#endif /* CONFIG_COMPAT */
11650+
11651+#endif /* __KERNEL__ */
11652+#endif /* _VX_DEVICE_CMD_H */
11653diff -NurpP --minimal linux-3.6.6/include/linux/vserver/device_def.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/device_def.h
11654--- linux-3.6.6/include/linux/vserver/device_def.h 1970-01-01 01:00:00.000000000 +0100
11655+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/device_def.h 2012-10-04 18:47:00.000000000 +0200
11656@@ -0,0 +1,17 @@
11657+#ifndef _VX_DEVICE_DEF_H
11658+#define _VX_DEVICE_DEF_H
11659+
11660+#include <linux/types.h>
11661+
11662+struct vx_dmap_target {
11663+ dev_t target;
11664+ uint32_t flags;
11665+};
11666+
11667+struct _vx_device {
11668+#ifdef CONFIG_VSERVER_DEVICE
11669+ struct vx_dmap_target targets[2];
11670+#endif
11671+};
11672+
11673+#endif /* _VX_DEVICE_DEF_H */
11674diff -NurpP --minimal linux-3.6.6/include/linux/vserver/dlimit.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/dlimit.h
11675--- linux-3.6.6/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11676+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/dlimit.h 2012-10-04 18:47:00.000000000 +0200
11677@@ -0,0 +1,54 @@
11678+#ifndef _VX_DLIMIT_H
11679+#define _VX_DLIMIT_H
11680+
11681+#include "switch.h"
11682+
11683+
11684+#ifdef __KERNEL__
11685+
11686+/* keep in sync with CDLIM_INFINITY */
11687+
11688+#define DLIM_INFINITY (~0ULL)
11689+
11690+#include <linux/spinlock.h>
11691+#include <linux/rcupdate.h>
11692+
11693+struct super_block;
11694+
11695+struct dl_info {
11696+ struct hlist_node dl_hlist; /* linked list of contexts */
11697+ struct rcu_head dl_rcu; /* the rcu head */
11698+ tag_t dl_tag; /* context tag */
11699+ atomic_t dl_usecnt; /* usage count */
11700+ atomic_t dl_refcnt; /* reference count */
11701+
11702+ struct super_block *dl_sb; /* associated superblock */
11703+
11704+ spinlock_t dl_lock; /* protect the values */
11705+
11706+ unsigned long long dl_space_used; /* used space in bytes */
11707+ unsigned long long dl_space_total; /* maximum space in bytes */
11708+ unsigned long dl_inodes_used; /* used inodes */
11709+ unsigned long dl_inodes_total; /* maximum inodes */
11710+
11711+ unsigned int dl_nrlmult; /* non root limit mult */
11712+};
11713+
11714+struct rcu_head;
11715+
11716+extern void rcu_free_dl_info(struct rcu_head *);
11717+extern void unhash_dl_info(struct dl_info *);
11718+
11719+extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11720+
11721+
11722+struct kstatfs;
11723+
11724+extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11725+
11726+typedef uint64_t dlsize_t;
11727+
11728+#endif /* __KERNEL__ */
11729+#else /* _VX_DLIMIT_H */
11730+#warning duplicate inclusion
11731+#endif /* _VX_DLIMIT_H */
11732diff -NurpP --minimal linux-3.6.6/include/linux/vserver/dlimit_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/dlimit_cmd.h
11733--- linux-3.6.6/include/linux/vserver/dlimit_cmd.h 1970-01-01 01:00:00.000000000 +0100
11734+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/dlimit_cmd.h 2012-10-04 18:47:00.000000000 +0200
11735@@ -0,0 +1,109 @@
11736+#ifndef _VX_DLIMIT_CMD_H
11737+#define _VX_DLIMIT_CMD_H
11738+
11739+
11740+/* dlimit vserver commands */
11741+
11742+#define VCMD_add_dlimit VC_CMD(DLIMIT, 1, 0)
11743+#define VCMD_rem_dlimit VC_CMD(DLIMIT, 2, 0)
11744+
11745+#define VCMD_set_dlimit VC_CMD(DLIMIT, 5, 0)
11746+#define VCMD_get_dlimit VC_CMD(DLIMIT, 6, 0)
11747+
11748+struct vcmd_ctx_dlimit_base_v0 {
11749+ const char __user *name;
11750+ uint32_t flags;
11751+};
11752+
11753+struct vcmd_ctx_dlimit_v0 {
11754+ const char __user *name;
11755+ uint32_t space_used; /* used space in kbytes */
11756+ uint32_t space_total; /* maximum space in kbytes */
11757+ uint32_t inodes_used; /* used inodes */
11758+ uint32_t inodes_total; /* maximum inodes */
11759+ uint32_t reserved; /* reserved for root in % */
11760+ uint32_t flags;
11761+};
11762+
11763+#define CDLIM_UNSET ((uint32_t)0UL)
11764+#define CDLIM_INFINITY ((uint32_t)~0UL)
11765+#define CDLIM_KEEP ((uint32_t)~1UL)
11766+
11767+#define DLIME_UNIT 0
11768+#define DLIME_KILO 1
11769+#define DLIME_MEGA 2
11770+#define DLIME_GIGA 3
11771+
11772+#define DLIMF_SHIFT 0x10
11773+
11774+#define DLIMS_USED 0
11775+#define DLIMS_TOTAL 2
11776+
11777+static inline
11778+uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11779+{
11780+ int exp = (flags & DLIMF_SHIFT) ?
11781+ (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11782+ return ((uint64_t)val) << (10 * exp);
11783+}
11784+
11785+static inline
11786+uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11787+{
11788+ int exp = 0;
11789+
11790+ if (*flags & DLIMF_SHIFT) {
11791+ while (val > (1LL << 32) && (exp < 3)) {
11792+ val >>= 10;
11793+ exp++;
11794+ }
11795+ *flags &= ~(DLIME_GIGA << shift);
11796+ *flags |= exp << shift;
11797+ } else
11798+ val >>= 10;
11799+ return val;
11800+}
11801+
11802+#ifdef __KERNEL__
11803+
11804+#ifdef CONFIG_COMPAT
11805+
11806+#include <asm/compat.h>
11807+
11808+struct vcmd_ctx_dlimit_base_v0_x32 {
11809+ compat_uptr_t name_ptr;
11810+ uint32_t flags;
11811+};
11812+
11813+struct vcmd_ctx_dlimit_v0_x32 {
11814+ compat_uptr_t name_ptr;
11815+ uint32_t space_used; /* used space in kbytes */
11816+ uint32_t space_total; /* maximum space in kbytes */
11817+ uint32_t inodes_used; /* used inodes */
11818+ uint32_t inodes_total; /* maximum inodes */
11819+ uint32_t reserved; /* reserved for root in % */
11820+ uint32_t flags;
11821+};
11822+
11823+#endif /* CONFIG_COMPAT */
11824+
11825+#include <linux/compiler.h>
11826+
11827+extern int vc_add_dlimit(uint32_t, void __user *);
11828+extern int vc_rem_dlimit(uint32_t, void __user *);
11829+
11830+extern int vc_set_dlimit(uint32_t, void __user *);
11831+extern int vc_get_dlimit(uint32_t, void __user *);
11832+
11833+#ifdef CONFIG_COMPAT
11834+
11835+extern int vc_add_dlimit_x32(uint32_t, void __user *);
11836+extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11837+
11838+extern int vc_set_dlimit_x32(uint32_t, void __user *);
11839+extern int vc_get_dlimit_x32(uint32_t, void __user *);
11840+
11841+#endif /* CONFIG_COMPAT */
11842+
11843+#endif /* __KERNEL__ */
11844+#endif /* _VX_DLIMIT_CMD_H */
11845diff -NurpP --minimal linux-3.6.6/include/linux/vserver/global.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/global.h
11846--- linux-3.6.6/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
11847+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/global.h 2012-10-04 18:47:00.000000000 +0200
11848@@ -0,0 +1,19 @@
11849+#ifndef _VX_GLOBAL_H
11850+#define _VX_GLOBAL_H
11851+
11852+
11853+extern atomic_t vx_global_ctotal;
11854+extern atomic_t vx_global_cactive;
11855+
11856+extern atomic_t nx_global_ctotal;
11857+extern atomic_t nx_global_cactive;
11858+
11859+extern atomic_t vs_global_nsproxy;
11860+extern atomic_t vs_global_fs;
11861+extern atomic_t vs_global_mnt_ns;
11862+extern atomic_t vs_global_uts_ns;
11863+extern atomic_t vs_global_user_ns;
11864+extern atomic_t vs_global_pid_ns;
11865+
11866+
11867+#endif /* _VX_GLOBAL_H */
11868diff -NurpP --minimal linux-3.6.6/include/linux/vserver/history.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/history.h
11869--- linux-3.6.6/include/linux/vserver/history.h 1970-01-01 01:00:00.000000000 +0100
11870+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/history.h 2012-10-04 18:47:00.000000000 +0200
11871@@ -0,0 +1,197 @@
11872+#ifndef _VX_HISTORY_H
11873+#define _VX_HISTORY_H
11874+
11875+
11876+enum {
11877+ VXH_UNUSED = 0,
11878+ VXH_THROW_OOPS = 1,
11879+
11880+ VXH_GET_VX_INFO,
11881+ VXH_PUT_VX_INFO,
11882+ VXH_INIT_VX_INFO,
11883+ VXH_SET_VX_INFO,
11884+ VXH_CLR_VX_INFO,
11885+ VXH_CLAIM_VX_INFO,
11886+ VXH_RELEASE_VX_INFO,
11887+ VXH_ALLOC_VX_INFO,
11888+ VXH_DEALLOC_VX_INFO,
11889+ VXH_HASH_VX_INFO,
11890+ VXH_UNHASH_VX_INFO,
11891+ VXH_LOC_VX_INFO,
11892+ VXH_LOOKUP_VX_INFO,
11893+ VXH_CREATE_VX_INFO,
11894+};
11895+
11896+struct _vxhe_vxi {
11897+ struct vx_info *ptr;
11898+ unsigned xid;
11899+ unsigned usecnt;
11900+ unsigned tasks;
11901+};
11902+
11903+struct _vxhe_set_clr {
11904+ void *data;
11905+};
11906+
11907+struct _vxhe_loc_lookup {
11908+ unsigned arg;
11909+};
11910+
11911+struct _vx_hist_entry {
11912+ void *loc;
11913+ unsigned short seq;
11914+ unsigned short type;
11915+ struct _vxhe_vxi vxi;
11916+ union {
11917+ struct _vxhe_set_clr sc;
11918+ struct _vxhe_loc_lookup ll;
11919+ };
11920+};
11921+
11922+#ifdef CONFIG_VSERVER_HISTORY
11923+
11924+extern unsigned volatile int vxh_active;
11925+
11926+struct _vx_hist_entry *vxh_advance(void *loc);
11927+
11928+
11929+static inline
11930+void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11931+{
11932+ entry->vxi.ptr = vxi;
11933+ if (vxi) {
11934+ entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11935+ entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11936+ entry->vxi.xid = vxi->vx_id;
11937+ }
11938+}
11939+
11940+
11941+#define __HERE__ current_text_addr()
11942+
11943+#define __VXH_BODY(__type, __data, __here) \
11944+ struct _vx_hist_entry *entry; \
11945+ \
11946+ preempt_disable(); \
11947+ entry = vxh_advance(__here); \
11948+ __data; \
11949+ entry->type = __type; \
11950+ preempt_enable();
11951+
11952+
11953+ /* pass vxi only */
11954+
11955+#define __VXH_SMPL \
11956+ __vxh_copy_vxi(entry, vxi)
11957+
11958+static inline
11959+void __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11960+{
11961+ __VXH_BODY(__type, __VXH_SMPL, __here)
11962+}
11963+
11964+ /* pass vxi and data (void *) */
11965+
11966+#define __VXH_DATA \
11967+ __vxh_copy_vxi(entry, vxi); \
11968+ entry->sc.data = data
11969+
11970+static inline
11971+void __vxh_data(struct vx_info *vxi, void *data,
11972+ int __type, void *__here)
11973+{
11974+ __VXH_BODY(__type, __VXH_DATA, __here)
11975+}
11976+
11977+ /* pass vxi and arg (long) */
11978+
11979+#define __VXH_LONG \
11980+ __vxh_copy_vxi(entry, vxi); \
11981+ entry->ll.arg = arg
11982+
11983+static inline
11984+void __vxh_long(struct vx_info *vxi, long arg,
11985+ int __type, void *__here)
11986+{
11987+ __VXH_BODY(__type, __VXH_LONG, __here)
11988+}
11989+
11990+
11991+static inline
11992+void __vxh_throw_oops(void *__here)
11993+{
11994+ __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11995+ /* prevent further acquisition */
11996+ vxh_active = 0;
11997+}
11998+
11999+
12000+#define vxh_throw_oops() __vxh_throw_oops(__HERE__);
12001+
12002+#define __vxh_get_vx_info(v, h) __vxh_smpl(v, VXH_GET_VX_INFO, h);
12003+#define __vxh_put_vx_info(v, h) __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12004+
12005+#define __vxh_init_vx_info(v, d, h) \
12006+ __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12007+#define __vxh_set_vx_info(v, d, h) \
12008+ __vxh_data(v, d, VXH_SET_VX_INFO, h);
12009+#define __vxh_clr_vx_info(v, d, h) \
12010+ __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12011+
12012+#define __vxh_claim_vx_info(v, d, h) \
12013+ __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12014+#define __vxh_release_vx_info(v, d, h) \
12015+ __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12016+
12017+#define vxh_alloc_vx_info(v) \
12018+ __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12019+#define vxh_dealloc_vx_info(v) \
12020+ __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12021+
12022+#define vxh_hash_vx_info(v) \
12023+ __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12024+#define vxh_unhash_vx_info(v) \
12025+ __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12026+
12027+#define vxh_loc_vx_info(v, l) \
12028+ __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12029+#define vxh_lookup_vx_info(v, l) \
12030+ __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12031+#define vxh_create_vx_info(v, l) \
12032+ __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12033+
12034+extern void vxh_dump_history(void);
12035+
12036+
12037+#else /* CONFIG_VSERVER_HISTORY */
12038+
12039+#define __HERE__ 0
12040+
12041+#define vxh_throw_oops() do { } while (0)
12042+
12043+#define __vxh_get_vx_info(v, h) do { } while (0)
12044+#define __vxh_put_vx_info(v, h) do { } while (0)
12045+
12046+#define __vxh_init_vx_info(v, d, h) do { } while (0)
12047+#define __vxh_set_vx_info(v, d, h) do { } while (0)
12048+#define __vxh_clr_vx_info(v, d, h) do { } while (0)
12049+
12050+#define __vxh_claim_vx_info(v, d, h) do { } while (0)
12051+#define __vxh_release_vx_info(v, d, h) do { } while (0)
12052+
12053+#define vxh_alloc_vx_info(v) do { } while (0)
12054+#define vxh_dealloc_vx_info(v) do { } while (0)
12055+
12056+#define vxh_hash_vx_info(v) do { } while (0)
12057+#define vxh_unhash_vx_info(v) do { } while (0)
12058+
12059+#define vxh_loc_vx_info(v, l) do { } while (0)
12060+#define vxh_lookup_vx_info(v, l) do { } while (0)
12061+#define vxh_create_vx_info(v, l) do { } while (0)
12062+
12063+#define vxh_dump_history() do { } while (0)
12064+
12065+
12066+#endif /* CONFIG_VSERVER_HISTORY */
12067+
12068+#endif /* _VX_HISTORY_H */
12069diff -NurpP --minimal linux-3.6.6/include/linux/vserver/inode.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/inode.h
12070--- linux-3.6.6/include/linux/vserver/inode.h 1970-01-01 01:00:00.000000000 +0100
12071+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/inode.h 2012-10-04 18:47:00.000000000 +0200
12072@@ -0,0 +1,39 @@
12073+#ifndef _VX_INODE_H
12074+#define _VX_INODE_H
12075+
12076+
12077+#define IATTR_TAG 0x01000000
12078+
12079+#define IATTR_ADMIN 0x00000001
12080+#define IATTR_WATCH 0x00000002
12081+#define IATTR_HIDE 0x00000004
12082+#define IATTR_FLAGS 0x00000007
12083+
12084+#define IATTR_BARRIER 0x00010000
12085+#define IATTR_IXUNLINK 0x00020000
12086+#define IATTR_IMMUTABLE 0x00040000
12087+#define IATTR_COW 0x00080000
12088+
12089+#ifdef __KERNEL__
12090+
12091+
12092+#ifdef CONFIG_VSERVER_PROC_SECURE
12093+#define IATTR_PROC_DEFAULT ( IATTR_ADMIN | IATTR_HIDE )
12094+#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
12095+#else
12096+#define IATTR_PROC_DEFAULT ( IATTR_ADMIN )
12097+#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
12098+#endif
12099+
12100+#define vx_hide_check(c, m) (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12101+
12102+#endif /* __KERNEL__ */
12103+
12104+/* inode ioctls */
12105+
12106+#define FIOC_GETXFLG _IOR('x', 5, long)
12107+#define FIOC_SETXFLG _IOW('x', 6, long)
12108+
12109+#else /* _VX_INODE_H */
12110+#warning duplicate inclusion
12111+#endif /* _VX_INODE_H */
12112diff -NurpP --minimal linux-3.6.6/include/linux/vserver/inode_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/inode_cmd.h
12113--- linux-3.6.6/include/linux/vserver/inode_cmd.h 1970-01-01 01:00:00.000000000 +0100
12114+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/inode_cmd.h 2012-10-04 18:47:00.000000000 +0200
12115@@ -0,0 +1,59 @@
12116+#ifndef _VX_INODE_CMD_H
12117+#define _VX_INODE_CMD_H
12118+
12119+
12120+/* inode vserver commands */
12121+
12122+#define VCMD_get_iattr VC_CMD(INODE, 1, 1)
12123+#define VCMD_set_iattr VC_CMD(INODE, 2, 1)
12124+
12125+#define VCMD_fget_iattr VC_CMD(INODE, 3, 0)
12126+#define VCMD_fset_iattr VC_CMD(INODE, 4, 0)
12127+
12128+struct vcmd_ctx_iattr_v1 {
12129+ const char __user *name;
12130+ uint32_t tag;
12131+ uint32_t flags;
12132+ uint32_t mask;
12133+};
12134+
12135+struct vcmd_ctx_fiattr_v0 {
12136+ uint32_t tag;
12137+ uint32_t flags;
12138+ uint32_t mask;
12139+};
12140+
12141+
12142+#ifdef __KERNEL__
12143+
12144+
12145+#ifdef CONFIG_COMPAT
12146+
12147+#include <asm/compat.h>
12148+
12149+struct vcmd_ctx_iattr_v1_x32 {
12150+ compat_uptr_t name_ptr;
12151+ uint32_t tag;
12152+ uint32_t flags;
12153+ uint32_t mask;
12154+};
12155+
12156+#endif /* CONFIG_COMPAT */
12157+
12158+#include <linux/compiler.h>
12159+
12160+extern int vc_get_iattr(void __user *);
12161+extern int vc_set_iattr(void __user *);
12162+
12163+extern int vc_fget_iattr(uint32_t, void __user *);
12164+extern int vc_fset_iattr(uint32_t, void __user *);
12165+
12166+#ifdef CONFIG_COMPAT
12167+
12168+extern int vc_get_iattr_x32(void __user *);
12169+extern int vc_set_iattr_x32(void __user *);
12170+
12171+#endif /* CONFIG_COMPAT */
12172+
12173+#endif /* __KERNEL__ */
12174+#endif /* _VX_INODE_CMD_H */
12175diff -NurpP --minimal linux-3.6.6/include/linux/vserver/limit.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/limit.h
12176--- linux-3.6.6/include/linux/vserver/limit.h 1970-01-01 01:00:00.000000000 +0100
12177+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/limit.h 2012-10-04 18:47:00.000000000 +0200
12178@@ -0,0 +1,71 @@
12179+#ifndef _VX_LIMIT_H
12180+#define _VX_LIMIT_H
12181+
12182+#define VLIMIT_NSOCK 16
12183+#define VLIMIT_OPENFD 17
12184+#define VLIMIT_ANON 18
12185+#define VLIMIT_SHMEM 19
12186+#define VLIMIT_SEMARY 20
12187+#define VLIMIT_NSEMS 21
12188+#define VLIMIT_DENTRY 22
12189+#define VLIMIT_MAPPED 23
12190+
12191+
12192+#ifdef __KERNEL__
12193+
12194+#define VLIM_NOCHECK ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12195+
12196+/* keep in sync with CRLIM_INFINITY */
12197+
12198+#define VLIM_INFINITY (~0ULL)
12199+
12200+#include <asm/atomic.h>
12201+#include <asm/resource.h>
12202+
12203+#ifndef RLIM_INFINITY
12204+#warning RLIM_INFINITY is undefined
12205+#endif
12206+
12207+#define __rlim_val(l, r, v) ((l)->res[r].v)
12208+
12209+#define __rlim_soft(l, r) __rlim_val(l, r, soft)
12210+#define __rlim_hard(l, r) __rlim_val(l, r, hard)
12211+
12212+#define __rlim_rcur(l, r) __rlim_val(l, r, rcur)
12213+#define __rlim_rmin(l, r) __rlim_val(l, r, rmin)
12214+#define __rlim_rmax(l, r) __rlim_val(l, r, rmax)
12215+
12216+#define __rlim_lhit(l, r) __rlim_val(l, r, lhit)
12217+#define __rlim_hit(l, r) atomic_inc(&__rlim_lhit(l, r))
12218+
12219+typedef atomic_long_t rlim_atomic_t;
12220+typedef unsigned long rlim_t;
12221+
12222+#define __rlim_get(l, r) atomic_long_read(&__rlim_rcur(l, r))
12223+#define __rlim_set(l, r, v) atomic_long_set(&__rlim_rcur(l, r), v)
12224+#define __rlim_inc(l, r) atomic_long_inc(&__rlim_rcur(l, r))
12225+#define __rlim_dec(l, r) atomic_long_dec(&__rlim_rcur(l, r))
12226+#define __rlim_add(l, r, v) atomic_long_add(v, &__rlim_rcur(l, r))
12227+#define __rlim_sub(l, r, v) atomic_long_sub(v, &__rlim_rcur(l, r))
12228+
12229+
12230+#if (RLIM_INFINITY == VLIM_INFINITY)
12231+#define VX_VLIM(r) ((long long)(long)(r))
12232+#define VX_RLIM(v) ((rlim_t)(v))
12233+#else
12234+#define VX_VLIM(r) (((r) == RLIM_INFINITY) \
12235+ ? VLIM_INFINITY : (long long)(r))
12236+#define VX_RLIM(v) (((v) == VLIM_INFINITY) \
12237+ ? RLIM_INFINITY : (rlim_t)(v))
12238+#endif
12239+
12240+struct sysinfo;
12241+
12242+void vx_vsi_meminfo(struct sysinfo *);
12243+void vx_vsi_swapinfo(struct sysinfo *);
12244+long vx_vsi_cached(struct sysinfo *);
12245+
12246+#define NUM_LIMITS 24
12247+
12248+#endif /* __KERNEL__ */
12249+#endif /* _VX_LIMIT_H */
12250diff -NurpP --minimal linux-3.6.6/include/linux/vserver/limit_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/limit_cmd.h
12251--- linux-3.6.6/include/linux/vserver/limit_cmd.h 1970-01-01 01:00:00.000000000 +0100
12252+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/limit_cmd.h 2012-10-04 18:47:00.000000000 +0200
12253@@ -0,0 +1,71 @@
12254+#ifndef _VX_LIMIT_CMD_H
12255+#define _VX_LIMIT_CMD_H
12256+
12257+
12258+/* rlimit vserver commands */
12259+
12260+#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
12261+#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
12262+#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
12263+#define VCMD_reset_hits VC_CMD(RLIMIT, 7, 0)
12264+#define VCMD_reset_minmax VC_CMD(RLIMIT, 9, 0)
12265+
12266+struct vcmd_ctx_rlimit_v0 {
12267+ uint32_t id;
12268+ uint64_t minimum;
12269+ uint64_t softlimit;
12270+ uint64_t maximum;
12271+};
12272+
12273+struct vcmd_ctx_rlimit_mask_v0 {
12274+ uint32_t minimum;
12275+ uint32_t softlimit;
12276+ uint32_t maximum;
12277+};
12278+
12279+#define VCMD_rlimit_stat VC_CMD(VSTAT, 1, 0)
12280+
12281+struct vcmd_rlimit_stat_v0 {
12282+ uint32_t id;
12283+ uint32_t hits;
12284+ uint64_t value;
12285+ uint64_t minimum;
12286+ uint64_t maximum;
12287+};
12288+
12289+#define CRLIM_UNSET (0ULL)
12290+#define CRLIM_INFINITY (~0ULL)
12291+#define CRLIM_KEEP (~1ULL)
12292+
12293+#ifdef __KERNEL__
12294+
12295+#ifdef CONFIG_IA32_EMULATION
12296+
12297+struct vcmd_ctx_rlimit_v0_x32 {
12298+ uint32_t id;
12299+ uint64_t minimum;
12300+ uint64_t softlimit;
12301+ uint64_t maximum;
12302+} __attribute__ ((packed));
12303+
12304+#endif /* CONFIG_IA32_EMULATION */
12305+
12306+#include <linux/compiler.h>
12307+
12308+extern int vc_get_rlimit_mask(uint32_t, void __user *);
12309+extern int vc_get_rlimit(struct vx_info *, void __user *);
12310+extern int vc_set_rlimit(struct vx_info *, void __user *);
12311+extern int vc_reset_hits(struct vx_info *, void __user *);
12312+extern int vc_reset_minmax(struct vx_info *, void __user *);
12313+
12314+extern int vc_rlimit_stat(struct vx_info *, void __user *);
12315+
12316+#ifdef CONFIG_IA32_EMULATION
12317+
12318+extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12319+extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12320+
12321+#endif /* CONFIG_IA32_EMULATION */
12322+
12323+#endif /* __KERNEL__ */
12324+#endif /* _VX_LIMIT_CMD_H */
12325diff -NurpP --minimal linux-3.6.6/include/linux/vserver/limit_def.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/limit_def.h
12326--- linux-3.6.6/include/linux/vserver/limit_def.h 1970-01-01 01:00:00.000000000 +0100
12327+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/limit_def.h 2012-10-04 18:47:00.000000000 +0200
12328@@ -0,0 +1,47 @@
12329+#ifndef _VX_LIMIT_DEF_H
12330+#define _VX_LIMIT_DEF_H
12331+
12332+#include <asm/atomic.h>
12333+#include <asm/resource.h>
12334+
12335+#include "limit.h"
12336+
12337+
12338+struct _vx_res_limit {
12339+ rlim_t soft; /* Context soft limit */
12340+ rlim_t hard; /* Context hard limit */
12341+
12342+ rlim_atomic_t rcur; /* Current value */
12343+ rlim_t rmin; /* Context minimum */
12344+ rlim_t rmax; /* Context maximum */
12345+
12346+ atomic_t lhit; /* Limit hits */
12347+};
12348+
12349+/* context sub struct */
12350+
12351+struct _vx_limit {
12352+ struct _vx_res_limit res[NUM_LIMITS];
12353+};
12354+
12355+#ifdef CONFIG_VSERVER_DEBUG
12356+
12357+static inline void __dump_vx_limit(struct _vx_limit *limit)
12358+{
12359+ int i;
12360+
12361+ printk("\t_vx_limit:");
12362+ for (i = 0; i < NUM_LIMITS; i++) {
12363+ printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12364+ i, (unsigned long)__rlim_get(limit, i),
12365+ (unsigned long)__rlim_rmin(limit, i),
12366+ (unsigned long)__rlim_rmax(limit, i),
12367+ (long)__rlim_soft(limit, i),
12368+ (long)__rlim_hard(limit, i),
12369+ atomic_read(&__rlim_lhit(limit, i)));
12370+ }
12371+}
12372+
12373+#endif
12374+
12375+#endif /* _VX_LIMIT_DEF_H */
12376diff -NurpP --minimal linux-3.6.6/include/linux/vserver/limit_int.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/limit_int.h
12377--- linux-3.6.6/include/linux/vserver/limit_int.h 1970-01-01 01:00:00.000000000 +0100
12378+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/limit_int.h 2012-10-04 18:47:00.000000000 +0200
12379@@ -0,0 +1,198 @@
12380+#ifndef _VX_LIMIT_INT_H
12381+#define _VX_LIMIT_INT_H
12382+
12383+#include "context.h"
12384+
12385+#ifdef __KERNEL__
12386+
12387+#define VXD_RCRES_COND(r) VXD_CBIT(cres, r)
12388+#define VXD_RLIMIT_COND(r) VXD_CBIT(limit, r)
12389+
12390+extern const char *vlimit_name[NUM_LIMITS];
12391+
12392+static inline void __vx_acc_cres(struct vx_info *vxi,
12393+ int res, int dir, void *_data, char *_file, int _line)
12394+{
12395+ if (VXD_RCRES_COND(res))
12396+ vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12397+ (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12398+ (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12399+ (dir > 0) ? "++" : "--", _data, _file, _line);
12400+ if (!vxi)
12401+ return;
12402+
12403+ if (dir > 0)
12404+ __rlim_inc(&vxi->limit, res);
12405+ else
12406+ __rlim_dec(&vxi->limit, res);
12407+}
12408+
12409+static inline void __vx_add_cres(struct vx_info *vxi,
12410+ int res, int amount, void *_data, char *_file, int _line)
12411+{
12412+ if (VXD_RCRES_COND(res))
12413+ vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12414+ (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12415+ (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12416+ amount, _data, _file, _line);
12417+ if (amount == 0)
12418+ return;
12419+ if (!vxi)
12420+ return;
12421+ __rlim_add(&vxi->limit, res, amount);
12422+}
12423+
12424+static inline
12425+int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12426+{
12427+ int cond = (value > __rlim_rmax(limit, res));
12428+
12429+ if (cond)
12430+ __rlim_rmax(limit, res) = value;
12431+ return cond;
12432+}
12433+
12434+static inline
12435+int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12436+{
12437+ int cond = (value < __rlim_rmin(limit, res));
12438+
12439+ if (cond)
12440+ __rlim_rmin(limit, res) = value;
12441+ return cond;
12442+}
12443+
12444+static inline
12445+void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12446+{
12447+ if (!__vx_cres_adjust_max(limit, res, value))
12448+ __vx_cres_adjust_min(limit, res, value);
12449+}
12450+
12451+
12452+/* return values:
12453+ +1 ... no limit hit
12454+ -1 ... over soft limit
12455+ 0 ... over hard limit */
12456+
12457+static inline int __vx_cres_avail(struct vx_info *vxi,
12458+ int res, int num, char *_file, int _line)
12459+{
12460+ struct _vx_limit *limit;
12461+ rlim_t value;
12462+
12463+ if (VXD_RLIMIT_COND(res))
12464+ vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12465+ (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12466+ (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12467+ (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12468+ (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12469+ num, _file, _line);
12470+ if (!vxi)
12471+ return 1;
12472+
12473+ limit = &vxi->limit;
12474+ value = __rlim_get(limit, res);
12475+
12476+ if (!__vx_cres_adjust_max(limit, res, value))
12477+ __vx_cres_adjust_min(limit, res, value);
12478+
12479+ if (num == 0)
12480+ return 1;
12481+
12482+ if (__rlim_soft(limit, res) == RLIM_INFINITY)
12483+ return -1;
12484+ if (value + num <= __rlim_soft(limit, res))
12485+ return -1;
12486+
12487+ if (__rlim_hard(limit, res) == RLIM_INFINITY)
12488+ return 1;
12489+ if (value + num <= __rlim_hard(limit, res))
12490+ return 1;
12491+
12492+ __rlim_hit(limit, res);
12493+ return 0;
12494+}
12495+
12496+
12497+static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12498+
12499+static inline
12500+rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12501+{
12502+ rlim_t value, sum = 0;
12503+ int res;
12504+
12505+ while ((res = *array++)) {
12506+ value = __rlim_get(limit, res);
12507+ __vx_cres_fixup(limit, res, value);
12508+ sum += value;
12509+ }
12510+ return sum;
12511+}
12512+
12513+static inline
12514+rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12515+{
12516+ rlim_t value = __vx_cres_array_sum(limit, array + 1);
12517+ int res = *array;
12518+
12519+ if (value == __rlim_get(limit, res))
12520+ return value;
12521+
12522+ __rlim_set(limit, res, value);
12523+ /* now adjust min/max */
12524+ if (!__vx_cres_adjust_max(limit, res, value))
12525+ __vx_cres_adjust_min(limit, res, value);
12526+
12527+ return value;
12528+}
12529+
12530+static inline int __vx_cres_array_avail(struct vx_info *vxi,
12531+ const int *array, int num, char *_file, int _line)
12532+{
12533+ struct _vx_limit *limit;
12534+ rlim_t value = 0;
12535+ int res;
12536+
12537+ if (num == 0)
12538+ return 1;
12539+ if (!vxi)
12540+ return 1;
12541+
12542+ limit = &vxi->limit;
12543+ res = *array;
12544+ value = __vx_cres_array_sum(limit, array + 1);
12545+
12546+ __rlim_set(limit, res, value);
12547+ __vx_cres_fixup(limit, res, value);
12548+
12549+ return __vx_cres_avail(vxi, res, num, _file, _line);
12550+}
12551+
12552+
12553+static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12554+{
12555+ rlim_t value;
12556+ int res;
12557+
12558+ /* complex resources first */
12559+ if ((id < 0) || (id == RLIMIT_RSS))
12560+ __vx_cres_array_fixup(limit, VLA_RSS);
12561+
12562+ for (res = 0; res < NUM_LIMITS; res++) {
12563+ if ((id > 0) && (res != id))
12564+ continue;
12565+
12566+ value = __rlim_get(limit, res);
12567+ __vx_cres_fixup(limit, res, value);
12568+
12569+ /* not supposed to happen, maybe warn? */
12570+ if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12571+ __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12572+ }
12573+}
12574+
12575+
12576+#endif /* __KERNEL__ */
12577+#endif /* _VX_LIMIT_INT_H */
12578diff -NurpP --minimal linux-3.6.6/include/linux/vserver/monitor.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/monitor.h
12579--- linux-3.6.6/include/linux/vserver/monitor.h 1970-01-01 01:00:00.000000000 +0100
12580+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/monitor.h 2012-10-04 18:47:00.000000000 +0200
12581@@ -0,0 +1,96 @@
12582+#ifndef _VX_MONITOR_H
12583+#define _VX_MONITOR_H
12584+
12585+#include <linux/types.h>
12586+
12587+enum {
12588+ VXM_UNUSED = 0,
12589+
12590+ VXM_SYNC = 0x10,
12591+
12592+ VXM_UPDATE = 0x20,
12593+ VXM_UPDATE_1,
12594+ VXM_UPDATE_2,
12595+
12596+ VXM_RQINFO_1 = 0x24,
12597+ VXM_RQINFO_2,
12598+
12599+ VXM_ACTIVATE = 0x40,
12600+ VXM_DEACTIVATE,
12601+ VXM_IDLE,
12602+
12603+ VXM_HOLD = 0x44,
12604+ VXM_UNHOLD,
12605+
12606+ VXM_MIGRATE = 0x48,
12607+ VXM_RESCHED,
12608+
12609+ /* all other bits are flags */
12610+ VXM_SCHED = 0x80,
12611+};
12612+
12613+struct _vxm_update_1 {
12614+ uint32_t tokens_max;
12615+ uint32_t fill_rate;
12616+ uint32_t interval;
12617+};
12618+
12619+struct _vxm_update_2 {
12620+ uint32_t tokens_min;
12621+ uint32_t fill_rate;
12622+ uint32_t interval;
12623+};
12624+
12625+struct _vxm_rqinfo_1 {
12626+ uint16_t running;
12627+ uint16_t onhold;
12628+ uint16_t iowait;
12629+ uint16_t uintr;
12630+ uint32_t idle_tokens;
12631+};
12632+
12633+struct _vxm_rqinfo_2 {
12634+ uint32_t norm_time;
12635+ uint32_t idle_time;
12636+ uint32_t idle_skip;
12637+};
12638+
12639+struct _vxm_sched {
12640+ uint32_t tokens;
12641+ uint32_t norm_time;
12642+ uint32_t idle_time;
12643+};
12644+
12645+struct _vxm_task {
12646+ uint16_t pid;
12647+ uint16_t state;
12648+};
12649+
12650+struct _vxm_event {
12651+ uint32_t jif;
12652+ union {
12653+ uint32_t seq;
12654+ uint32_t sec;
12655+ };
12656+ union {
12657+ uint32_t tokens;
12658+ uint32_t nsec;
12659+ struct _vxm_task tsk;
12660+ };
12661+};
12662+
12663+struct _vx_mon_entry {
12664+ uint16_t type;
12665+ uint16_t xid;
12666+ union {
12667+ struct _vxm_event ev;
12668+ struct _vxm_sched sd;
12669+ struct _vxm_update_1 u1;
12670+ struct _vxm_update_2 u2;
12671+ struct _vxm_rqinfo_1 q1;
12672+ struct _vxm_rqinfo_2 q2;
12673+ };
12674+};
12675+
12676+
12677+#endif /* _VX_MONITOR_H */
12678diff -NurpP --minimal linux-3.6.6/include/linux/vserver/network.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/network.h
12679--- linux-3.6.6/include/linux/vserver/network.h 1970-01-01 01:00:00.000000000 +0100
12680+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/network.h 2012-10-04 18:47:00.000000000 +0200
12681@@ -0,0 +1,148 @@
12682+#ifndef _VX_NETWORK_H
12683+#define _VX_NETWORK_H
12684+
12685+#include <linux/types.h>
12686+
12687+
12688+#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
12689+
12690+
12691+/* network flags */
12692+
12693+#define NXF_INFO_PRIVATE 0x00000008
12694+
12695+#define NXF_SINGLE_IP 0x00000100
12696+#define NXF_LBACK_REMAP 0x00000200
12697+#define NXF_LBACK_ALLOW 0x00000400
12698+
12699+#define NXF_HIDE_NETIF 0x02000000
12700+#define NXF_HIDE_LBACK 0x04000000
12701+
12702+#define NXF_STATE_SETUP (1ULL << 32)
12703+#define NXF_STATE_ADMIN (1ULL << 34)
12704+
12705+#define NXF_SC_HELPER (1ULL << 36)
12706+#define NXF_PERSISTENT (1ULL << 38)
12707+
12708+#define NXF_ONE_TIME (0x0005ULL << 32)
12709+
12710+
12711+#define NXF_INIT_SET (__nxf_init_set())
12712+
12713+static inline uint64_t __nxf_init_set(void) {
12714+ return NXF_STATE_ADMIN
12715+#ifdef CONFIG_VSERVER_AUTO_LBACK
12716+ | NXF_LBACK_REMAP
12717+ | NXF_HIDE_LBACK
12718+#endif
12719+#ifdef CONFIG_VSERVER_AUTO_SINGLE
12720+ | NXF_SINGLE_IP
12721+#endif
12722+ | NXF_HIDE_NETIF;
12723+}
12724+
12725+
12726+/* network caps */
12727+
12728+#define NXC_TUN_CREATE 0x00000001
12729+
12730+#define NXC_RAW_ICMP 0x00000100
12731+
12732+#define NXC_MULTICAST 0x00001000
12733+
12734+
12735+/* address types */
12736+
12737+#define NXA_TYPE_IPV4 0x0001
12738+#define NXA_TYPE_IPV6 0x0002
12739+
12740+#define NXA_TYPE_NONE 0x0000
12741+#define NXA_TYPE_ANY 0x00FF
12742+
12743+#define NXA_TYPE_ADDR 0x0010
12744+#define NXA_TYPE_MASK 0x0020
12745+#define NXA_TYPE_RANGE 0x0040
12746+
12747+#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12748+
12749+#define NXA_MOD_BCAST 0x0100
12750+#define NXA_MOD_LBACK 0x0200
12751+
12752+#define NXA_LOOPBACK 0x1000
12753+
12754+#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12755+#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
12756+
12757+#ifdef __KERNEL__
12758+
12759+#include <linux/list.h>
12760+#include <linux/spinlock.h>
12761+#include <linux/rcupdate.h>
12762+#include <linux/in.h>
12763+#include <linux/in6.h>
12764+#include <asm/atomic.h>
12765+
12766+struct nx_addr_v4 {
12767+ struct nx_addr_v4 *next;
12768+ struct in_addr ip[2];
12769+ struct in_addr mask;
12770+ uint16_t type;
12771+ uint16_t flags;
12772+};
12773+
12774+struct nx_addr_v6 {
12775+ struct nx_addr_v6 *next;
12776+ struct in6_addr ip;
12777+ struct in6_addr mask;
12778+ uint32_t prefix;
12779+ uint16_t type;
12780+ uint16_t flags;
12781+};
12782+
12783+struct nx_info {
12784+ struct hlist_node nx_hlist; /* linked list of nxinfos */
12785+ nid_t nx_id; /* vnet id */
12786+ atomic_t nx_usecnt; /* usage count */
12787+ atomic_t nx_tasks; /* tasks count */
12788+ int nx_state; /* context state */
12789+
12790+ uint64_t nx_flags; /* network flag word */
12791+ uint64_t nx_ncaps; /* network capabilities */
12792+
12793+ struct in_addr v4_lback; /* Loopback address */
12794+ struct in_addr v4_bcast; /* Broadcast address */
12795+ struct nx_addr_v4 v4; /* First/Single ipv4 address */
12796+#ifdef CONFIG_IPV6
12797+ struct nx_addr_v6 v6; /* First/Single ipv6 address */
12798+#endif
12799+ char nx_name[65]; /* network context name */
12800+};
12801+
12802+
12803+/* status flags */
12804+
12805+#define NXS_HASHED 0x0001
12806+#define NXS_SHUTDOWN 0x0100
12807+#define NXS_RELEASED 0x8000
12808+
12809+extern struct nx_info *lookup_nx_info(int);
12810+
12811+extern int get_nid_list(int, unsigned int *, int);
12812+extern int nid_is_hashed(nid_t);
12813+
12814+extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12815+
12816+extern long vs_net_change(struct nx_info *, unsigned int);
12817+
12818+struct sock;
12819+
12820+
12821+#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
12822+#ifdef CONFIG_IPV6
12823+#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
12824+#else
12825+#define NX_IPV6(n) (0)
12826+#endif
12827+
12828+#endif /* __KERNEL__ */
12829+#endif /* _VX_NETWORK_H */
12830diff -NurpP --minimal linux-3.6.6/include/linux/vserver/network_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/network_cmd.h
12831--- linux-3.6.6/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
12832+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/network_cmd.h 2012-10-04 18:47:00.000000000 +0200
12833@@ -0,0 +1,164 @@
12834+#ifndef _VX_NETWORK_CMD_H
12835+#define _VX_NETWORK_CMD_H
12836+
12837+
12838+/* vinfo commands */
12839+
12840+#define VCMD_task_nid VC_CMD(VINFO, 2, 0)
12841+
12842+#ifdef __KERNEL__
12843+extern int vc_task_nid(uint32_t);
12844+
12845+#endif /* __KERNEL__ */
12846+
12847+#define VCMD_nx_info VC_CMD(VINFO, 6, 0)
12848+
12849+struct vcmd_nx_info_v0 {
12850+ uint32_t nid;
12851+ /* more to come */
12852+};
12853+
12854+#ifdef __KERNEL__
12855+extern int vc_nx_info(struct nx_info *, void __user *);
12856+
12857+#endif /* __KERNEL__ */
12858+
12859+#include <linux/in.h>
12860+#include <linux/in6.h>
12861+
12862+#define VCMD_net_create_v0 VC_CMD(VNET, 1, 0)
12863+#define VCMD_net_create VC_CMD(VNET, 1, 1)
12864+
12865+struct vcmd_net_create {
12866+ uint64_t flagword;
12867+};
12868+
12869+#define VCMD_net_migrate VC_CMD(NETMIG, 1, 0)
12870+
12871+#define VCMD_net_add VC_CMD(NETALT, 1, 0)
12872+#define VCMD_net_remove VC_CMD(NETALT, 2, 0)
12873+
12874+struct vcmd_net_addr_v0 {
12875+ uint16_t type;
12876+ uint16_t count;
12877+ struct in_addr ip[4];
12878+ struct in_addr mask[4];
12879+};
12880+
12881+#define VCMD_net_add_ipv4_v1 VC_CMD(NETALT, 1, 1)
12882+#define VCMD_net_rem_ipv4_v1 VC_CMD(NETALT, 2, 1)
12883+
12884+struct vcmd_net_addr_ipv4_v1 {
12885+ uint16_t type;
12886+ uint16_t flags;
12887+ struct in_addr ip;
12888+ struct in_addr mask;
12889+};
12890+
12891+#define VCMD_net_add_ipv4 VC_CMD(NETALT, 1, 2)
12892+#define VCMD_net_rem_ipv4 VC_CMD(NETALT, 2, 2)
12893+
12894+struct vcmd_net_addr_ipv4_v2 {
12895+ uint16_t type;
12896+ uint16_t flags;
12897+ struct in_addr ip;
12898+ struct in_addr ip2;
12899+ struct in_addr mask;
12900+};
12901+
12902+#define VCMD_net_add_ipv6 VC_CMD(NETALT, 3, 1)
12903+#define VCMD_net_remove_ipv6 VC_CMD(NETALT, 4, 1)
12904+
12905+struct vcmd_net_addr_ipv6_v1 {
12906+ uint16_t type;
12907+ uint16_t flags;
12908+ uint32_t prefix;
12909+ struct in6_addr ip;
12910+ struct in6_addr mask;
12911+};
12912+
12913+#define VCMD_add_match_ipv4 VC_CMD(NETALT, 5, 0)
12914+#define VCMD_get_match_ipv4 VC_CMD(NETALT, 6, 0)
12915+
12916+struct vcmd_match_ipv4_v0 {
12917+ uint16_t type;
12918+ uint16_t flags;
12919+ uint16_t parent;
12920+ uint16_t prefix;
12921+ struct in_addr ip;
12922+ struct in_addr ip2;
12923+ struct in_addr mask;
12924+};
12925+
12926+#define VCMD_add_match_ipv6 VC_CMD(NETALT, 7, 0)
12927+#define VCMD_get_match_ipv6 VC_CMD(NETALT, 8, 0)
12928+
12929+struct vcmd_match_ipv6_v0 {
12930+ uint16_t type;
12931+ uint16_t flags;
12932+ uint16_t parent;
12933+ uint16_t prefix;
12934+ struct in6_addr ip;
12935+ struct in6_addr ip2;
12936+ struct in6_addr mask;
12937+};
12938+
12939+
12940+#ifdef __KERNEL__
12941+extern int vc_net_create(uint32_t, void __user *);
12942+extern int vc_net_migrate(struct nx_info *, void __user *);
12943+
12944+extern int vc_net_add(struct nx_info *, void __user *);
12945+extern int vc_net_remove(struct nx_info *, void __user *);
12946+
12947+extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
12948+extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12949+
12950+extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
12951+extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
12952+
12953+extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12954+extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12955+
12956+extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12957+extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12958+
12959+extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12960+extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12961+
12962+#endif /* __KERNEL__ */
12963+
12964+
12965+/* flag commands */
12966+
12967+#define VCMD_get_nflags VC_CMD(FLAGS, 5, 0)
12968+#define VCMD_set_nflags VC_CMD(FLAGS, 6, 0)
12969+
12970+struct vcmd_net_flags_v0 {
12971+ uint64_t flagword;
12972+ uint64_t mask;
12973+};
12974+
12975+#ifdef __KERNEL__
12976+extern int vc_get_nflags(struct nx_info *, void __user *);
12977+extern int vc_set_nflags(struct nx_info *, void __user *);
12978+
12979+#endif /* __KERNEL__ */
12980+
12981+
12982+/* network caps commands */
12983+
12984+#define VCMD_get_ncaps VC_CMD(FLAGS, 7, 0)
12985+#define VCMD_set_ncaps VC_CMD(FLAGS, 8, 0)
12986+
12987+struct vcmd_net_caps_v0 {
12988+ uint64_t ncaps;
12989+ uint64_t cmask;
12990+};
12991+
12992+#ifdef __KERNEL__
12993+extern int vc_get_ncaps(struct nx_info *, void __user *);
12994+extern int vc_set_ncaps(struct nx_info *, void __user *);
12995+
12996+#endif /* __KERNEL__ */
12997+#endif /* _VX_CONTEXT_CMD_H */
12998diff -NurpP --minimal linux-3.6.6/include/linux/vserver/percpu.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/percpu.h
12999--- linux-3.6.6/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
13000+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/percpu.h 2012-10-04 18:47:00.000000000 +0200
13001@@ -0,0 +1,14 @@
13002+#ifndef _VX_PERCPU_H
13003+#define _VX_PERCPU_H
13004+
13005+#include "cvirt_def.h"
13006+#include "sched_def.h"
13007+
13008+struct _vx_percpu {
13009+ struct _vx_cvirt_pc cvirt;
13010+ struct _vx_sched_pc sched;
13011+};
13012+
13013+#define PERCPU_PERCTX (sizeof(struct _vx_percpu))
13014+
13015+#endif /* _VX_PERCPU_H */
13016diff -NurpP --minimal linux-3.6.6/include/linux/vserver/pid.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/pid.h
13017--- linux-3.6.6/include/linux/vserver/pid.h 1970-01-01 01:00:00.000000000 +0100
13018+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/pid.h 2012-10-04 18:47:00.000000000 +0200
13019@@ -0,0 +1,51 @@
13020+#ifndef _VSERVER_PID_H
13021+#define _VSERVER_PID_H
13022+
13023+/* pid faking stuff */
13024+
13025+#define vx_info_map_pid(v, p) \
13026+ __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13027+#define vx_info_map_tgid(v,p) vx_info_map_pid(v,p)
13028+#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13029+#define vx_map_tgid(p) vx_map_pid(p)
13030+
13031+static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13032+ const char *func, const char *file, int line)
13033+{
13034+ if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13035+ vxfprintk(VXD_CBIT(cvirt, 2),
13036+ "vx_map_tgid: %p/%llx: %d -> %d",
13037+ vxi, (long long)vxi->vx_flags, pid,
13038+ (pid && pid == vxi->vx_initpid) ? 1 : pid,
13039+ func, file, line);
13040+ if (pid == 0)
13041+ return 0;
13042+ if (pid == vxi->vx_initpid)
13043+ return 1;
13044+ }
13045+ return pid;
13046+}
13047+
13048+#define vx_info_rmap_pid(v, p) \
13049+ __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13050+#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13051+#define vx_rmap_tgid(p) vx_rmap_pid(p)
13052+
13053+static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13054+ const char *func, const char *file, int line)
13055+{
13056+ if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13057+ vxfprintk(VXD_CBIT(cvirt, 2),
13058+ "vx_rmap_tgid: %p/%llx: %d -> %d",
13059+ vxi, (long long)vxi->vx_flags, pid,
13060+ (pid == 1) ? vxi->vx_initpid : pid,
13061+ func, file, line);
13062+ if ((pid == 1) && vxi->vx_initpid)
13063+ return vxi->vx_initpid;
13064+ if (pid == vxi->vx_initpid)
13065+ return ~0U;
13066+ }
13067+ return pid;
13068+}
13069+
13070+#endif
13071diff -NurpP --minimal linux-3.6.6/include/linux/vserver/sched.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/sched.h
13072--- linux-3.6.6/include/linux/vserver/sched.h 1970-01-01 01:00:00.000000000 +0100
13073+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/sched.h 2012-10-04 18:47:00.000000000 +0200
13074@@ -0,0 +1,23 @@
13075+#ifndef _VX_SCHED_H
13076+#define _VX_SCHED_H
13077+
13078+
13079+#ifdef __KERNEL__
13080+
13081+struct timespec;
13082+
13083+void vx_vsi_uptime(struct timespec *, struct timespec *);
13084+
13085+
13086+struct vx_info;
13087+
13088+void vx_update_load(struct vx_info *);
13089+
13090+
13091+void vx_update_sched_param(struct _vx_sched *sched,
13092+ struct _vx_sched_pc *sched_pc);
13093+
13094+#endif /* __KERNEL__ */
13095+#else /* _VX_SCHED_H */
13096+#warning duplicate inclusion
13097+#endif /* _VX_SCHED_H */
13098diff -NurpP --minimal linux-3.6.6/include/linux/vserver/sched_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/sched_cmd.h
13099--- linux-3.6.6/include/linux/vserver/sched_cmd.h 1970-01-01 01:00:00.000000000 +0100
13100+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/sched_cmd.h 2012-10-04 18:47:00.000000000 +0200
13101@@ -0,0 +1,21 @@
13102+#ifndef _VX_SCHED_CMD_H
13103+#define _VX_SCHED_CMD_H
13104+
13105+
13106+struct vcmd_prio_bias {
13107+ int32_t cpu_id;
13108+ int32_t prio_bias;
13109+};
13110+
13111+#define VCMD_set_prio_bias VC_CMD(SCHED, 4, 0)
13112+#define VCMD_get_prio_bias VC_CMD(SCHED, 5, 0)
13113+
13114+#ifdef __KERNEL__
13115+
13116+#include <linux/compiler.h>
13117+
13118+extern int vc_set_prio_bias(struct vx_info *, void __user *);
13119+extern int vc_get_prio_bias(struct vx_info *, void __user *);
13120+
13121+#endif /* __KERNEL__ */
13122+#endif /* _VX_SCHED_CMD_H */
13123diff -NurpP --minimal linux-3.6.6/include/linux/vserver/sched_def.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/sched_def.h
13124--- linux-3.6.6/include/linux/vserver/sched_def.h 1970-01-01 01:00:00.000000000 +0100
13125+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/sched_def.h 2012-10-04 18:47:00.000000000 +0200
13126@@ -0,0 +1,38 @@
13127+#ifndef _VX_SCHED_DEF_H
13128+#define _VX_SCHED_DEF_H
13129+
13130+#include <linux/spinlock.h>
13131+#include <linux/jiffies.h>
13132+#include <linux/cpumask.h>
13133+#include <asm/atomic.h>
13134+#include <asm/param.h>
13135+
13136+
13137+/* context sub struct */
13138+
13139+struct _vx_sched {
13140+ int prio_bias; /* bias offset for priority */
13141+
13142+ cpumask_t update; /* CPUs which should update */
13143+};
13144+
13145+struct _vx_sched_pc {
13146+ int prio_bias; /* bias offset for priority */
13147+
13148+ uint64_t user_ticks; /* token tick events */
13149+ uint64_t sys_ticks; /* token tick events */
13150+ uint64_t hold_ticks; /* token ticks paused */
13151+};
13152+
13153+
13154+#ifdef CONFIG_VSERVER_DEBUG
13155+
13156+static inline void __dump_vx_sched(struct _vx_sched *sched)
13157+{
13158+ printk("\t_vx_sched:\n");
13159+ printk("\t priority = %4d\n", sched->prio_bias);
13160+}
13161+
13162+#endif
13163+
13164+#endif /* _VX_SCHED_DEF_H */
13165diff -NurpP --minimal linux-3.6.6/include/linux/vserver/signal.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/signal.h
13166--- linux-3.6.6/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
13167+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/signal.h 2012-10-04 18:47:00.000000000 +0200
13168@@ -0,0 +1,14 @@
13169+#ifndef _VX_SIGNAL_H
13170+#define _VX_SIGNAL_H
13171+
13172+
13173+#ifdef __KERNEL__
13174+
13175+struct vx_info;
13176+
13177+int vx_info_kill(struct vx_info *, int, int);
13178+
13179+#endif /* __KERNEL__ */
13180+#else /* _VX_SIGNAL_H */
13181+#warning duplicate inclusion
13182+#endif /* _VX_SIGNAL_H */
13183diff -NurpP --minimal linux-3.6.6/include/linux/vserver/signal_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/signal_cmd.h
13184--- linux-3.6.6/include/linux/vserver/signal_cmd.h 1970-01-01 01:00:00.000000000 +0100
13185+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/signal_cmd.h 2012-10-04 18:47:00.000000000 +0200
13186@@ -0,0 +1,43 @@
13187+#ifndef _VX_SIGNAL_CMD_H
13188+#define _VX_SIGNAL_CMD_H
13189+
13190+
13191+/* signalling vserver commands */
13192+
13193+#define VCMD_ctx_kill VC_CMD(PROCTRL, 1, 0)
13194+#define VCMD_wait_exit VC_CMD(EVENT, 99, 0)
13195+
13196+struct vcmd_ctx_kill_v0 {
13197+ int32_t pid;
13198+ int32_t sig;
13199+};
13200+
13201+struct vcmd_wait_exit_v0 {
13202+ int32_t reboot_cmd;
13203+ int32_t exit_code;
13204+};
13205+
13206+#ifdef __KERNEL__
13207+
13208+extern int vc_ctx_kill(struct vx_info *, void __user *);
13209+extern int vc_wait_exit(struct vx_info *, void __user *);
13210+
13211+#endif /* __KERNEL__ */
13212+
13213+/* process alteration commands */
13214+
13215+#define VCMD_get_pflags VC_CMD(PROCALT, 5, 0)
13216+#define VCMD_set_pflags VC_CMD(PROCALT, 6, 0)
13217+
13218+struct vcmd_pflags_v0 {
13219+ uint32_t flagword;
13220+ uint32_t mask;
13221+};
13222+
13223+#ifdef __KERNEL__
13224+
13225+extern int vc_get_pflags(uint32_t pid, void __user *);
13226+extern int vc_set_pflags(uint32_t pid, void __user *);
13227+
13228+#endif /* __KERNEL__ */
13229+#endif /* _VX_SIGNAL_CMD_H */
13230diff -NurpP --minimal linux-3.6.6/include/linux/vserver/space.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/space.h
13231--- linux-3.6.6/include/linux/vserver/space.h 1970-01-01 01:00:00.000000000 +0100
13232+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/space.h 2012-10-04 18:47:00.000000000 +0200
13233@@ -0,0 +1,12 @@
13234+#ifndef _VX_SPACE_H
13235+#define _VX_SPACE_H
13236+
13237+#include <linux/types.h>
13238+
13239+struct vx_info;
13240+
13241+int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13242+
13243+#else /* _VX_SPACE_H */
13244+#warning duplicate inclusion
13245+#endif /* _VX_SPACE_H */
13246diff -NurpP --minimal linux-3.6.6/include/linux/vserver/space_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/space_cmd.h
13247--- linux-3.6.6/include/linux/vserver/space_cmd.h 1970-01-01 01:00:00.000000000 +0100
13248+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/space_cmd.h 2012-10-04 18:47:00.000000000 +0200
13249@@ -0,0 +1,38 @@
13250+#ifndef _VX_SPACE_CMD_H
13251+#define _VX_SPACE_CMD_H
13252+
13253+
13254+#define VCMD_enter_space_v0 VC_CMD(PROCALT, 1, 0)
13255+#define VCMD_enter_space_v1 VC_CMD(PROCALT, 1, 1)
13256+#define VCMD_enter_space VC_CMD(PROCALT, 1, 2)
13257+
13258+#define VCMD_set_space_v0 VC_CMD(PROCALT, 3, 0)
13259+#define VCMD_set_space_v1 VC_CMD(PROCALT, 3, 1)
13260+#define VCMD_set_space VC_CMD(PROCALT, 3, 2)
13261+
13262+#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13263+
13264+#define VCMD_get_space_mask VC_CMD(VSPACE, 0, 1)
13265+#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13266+
13267+
13268+struct vcmd_space_mask_v1 {
13269+ uint64_t mask;
13270+};
13271+
13272+struct vcmd_space_mask_v2 {
13273+ uint64_t mask;
13274+ uint32_t index;
13275+};
13276+
13277+
13278+#ifdef __KERNEL__
13279+
13280+extern int vc_enter_space_v1(struct vx_info *, void __user *);
13281+extern int vc_set_space_v1(struct vx_info *, void __user *);
13282+extern int vc_enter_space(struct vx_info *, void __user *);
13283+extern int vc_set_space(struct vx_info *, void __user *);
13284+extern int vc_get_space_mask(void __user *, int);
13285+
13286+#endif /* __KERNEL__ */
13287+#endif /* _VX_SPACE_CMD_H */
13288diff -NurpP --minimal linux-3.6.6/include/linux/vserver/switch.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/switch.h
13289--- linux-3.6.6/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
13290+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/switch.h 2012-10-04 18:47:00.000000000 +0200
13291@@ -0,0 +1,98 @@
13292+#ifndef _VX_SWITCH_H
13293+#define _VX_SWITCH_H
13294+
13295+#include <linux/types.h>
13296+
13297+
13298+#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
13299+#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
13300+#define VC_VERSION(c) ((c) & 0xFFF)
13301+
13302+#define VC_CMD(c, i, v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
13303+ | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13304+
13305+/*
13306+
13307+ Syscall Matrix V2.8
13308+
13309+ |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13310+ |STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
13311+ |INFO |SETUP | |MOVE | | | | | |
13312+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13313+ SYSTEM |VERSION|VSETUP |VHOST | | | | |DEVICE | |
13314+ HOST | 00| 01| 02| 03| 04| 05| | 06| 07|
13315+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13316+ CPU | |VPROC |PROCALT|PROCMIG|PROCTRL| | |SCHED. | |
13317+ PROCESS| 08| 09| 10| 11| 12| 13| | 14| 15|
13318+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13319+ MEMORY | | | | |MEMCTRL| | |SWAP | |
13320+ | 16| 17| 18| 19| 20| 21| | 22| 23|
13321+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13322+ NETWORK| |VNET |NETALT |NETMIG |NETCTL | | |SERIAL | |
13323+ | 24| 25| 26| 27| 28| 29| | 30| 31|
13324+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13325+ DISK | | | |TAGMIG |DLIMIT | | |INODE | |
13326+ VFS | 32| 33| 34| 35| 36| 37| | 38| 39|
13327+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13328+ OTHER |VSTAT | | | | | | |VINFO | |
13329+ | 40| 41| 42| 43| 44| 45| | 46| 47|
13330+ =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13331+ SPECIAL|EVENT | | | |FLAGS | | |VSPACE | |
13332+ | 48| 49| 50| 51| 52| 53| | 54| 55|
13333+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13334+ SPECIAL|DEBUG | | | |RLIMIT |SYSCALL| | |COMPAT |
13335+ | 56| 57| 58| 59| 60|TEST 61| | 62| 63|
13336+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13337+
13338+*/
13339+
13340+#define VC_CAT_VERSION 0
13341+
13342+#define VC_CAT_VSETUP 1
13343+#define VC_CAT_VHOST 2
13344+
13345+#define VC_CAT_DEVICE 6
13346+
13347+#define VC_CAT_VPROC 9
13348+#define VC_CAT_PROCALT 10
13349+#define VC_CAT_PROCMIG 11
13350+#define VC_CAT_PROCTRL 12
13351+
13352+#define VC_CAT_SCHED 14
13353+#define VC_CAT_MEMCTRL 20
13354+
13355+#define VC_CAT_VNET 25
13356+#define VC_CAT_NETALT 26
13357+#define VC_CAT_NETMIG 27
13358+#define VC_CAT_NETCTRL 28
13359+
13360+#define VC_CAT_TAGMIG 35
13361+#define VC_CAT_DLIMIT 36
13362+#define VC_CAT_INODE 38
13363+
13364+#define VC_CAT_VSTAT 40
13365+#define VC_CAT_VINFO 46
13366+#define VC_CAT_EVENT 48
13367+
13368+#define VC_CAT_FLAGS 52
13369+#define VC_CAT_VSPACE 54
13370+#define VC_CAT_DEBUG 56
13371+#define VC_CAT_RLIMIT 60
13372+
13373+#define VC_CAT_SYSTEST 61
13374+#define VC_CAT_COMPAT 63
13375+
13376+/* query version */
13377+
13378+#define VCMD_get_version VC_CMD(VERSION, 0, 0)
13379+#define VCMD_get_vci VC_CMD(VERSION, 1, 0)
13380+
13381+
13382+#ifdef __KERNEL__
13383+
13384+#include <linux/errno.h>
13385+
13386+#endif /* __KERNEL__ */
13387+
13388+#endif /* _VX_SWITCH_H */
13389+
13390diff -NurpP --minimal linux-3.6.6/include/linux/vserver/tag.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/tag.h
13391--- linux-3.6.6/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
13392+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/tag.h 2012-10-04 18:47:00.000000000 +0200
13393@@ -0,0 +1,143 @@
13394+#ifndef _DX_TAG_H
13395+#define _DX_TAG_H
13396+
13397+#include <linux/types.h>
13398+
13399+
13400+#define DX_TAG(in) (IS_TAGGED(in))
13401+
13402+
13403+#ifdef CONFIG_TAG_NFSD
13404+#define DX_TAG_NFSD 1
13405+#else
13406+#define DX_TAG_NFSD 0
13407+#endif
13408+
13409+
13410+#ifdef CONFIG_TAGGING_NONE
13411+
13412+#define MAX_UID 0xFFFFFFFF
13413+#define MAX_GID 0xFFFFFFFF
13414+
13415+#define INOTAG_TAG(cond, uid, gid, tag) (0)
13416+
13417+#define TAGINO_UID(cond, uid, tag) (uid)
13418+#define TAGINO_GID(cond, gid, tag) (gid)
13419+
13420+#endif
13421+
13422+
13423+#ifdef CONFIG_TAGGING_GID16
13424+
13425+#define MAX_UID 0xFFFFFFFF
13426+#define MAX_GID 0x0000FFFF
13427+
13428+#define INOTAG_TAG(cond, uid, gid, tag) \
13429+ ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13430+
13431+#define TAGINO_UID(cond, uid, tag) (uid)
13432+#define TAGINO_GID(cond, gid, tag) \
13433+ ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13434+
13435+#endif
13436+
13437+
13438+#ifdef CONFIG_TAGGING_ID24
13439+
13440+#define MAX_UID 0x00FFFFFF
13441+#define MAX_GID 0x00FFFFFF
13442+
13443+#define INOTAG_TAG(cond, uid, gid, tag) \
13444+ ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13445+
13446+#define TAGINO_UID(cond, uid, tag) \
13447+ ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13448+#define TAGINO_GID(cond, gid, tag) \
13449+ ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13450+
13451+#endif
13452+
13453+
13454+#ifdef CONFIG_TAGGING_UID16
13455+
13456+#define MAX_UID 0x0000FFFF
13457+#define MAX_GID 0xFFFFFFFF
13458+
13459+#define INOTAG_TAG(cond, uid, gid, tag) \
13460+ ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13461+
13462+#define TAGINO_UID(cond, uid, tag) \
13463+ ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13464+#define TAGINO_GID(cond, gid, tag) (gid)
13465+
13466+#endif
13467+
13468+
13469+#ifdef CONFIG_TAGGING_INTERN
13470+
13471+#define MAX_UID 0xFFFFFFFF
13472+#define MAX_GID 0xFFFFFFFF
13473+
13474+#define INOTAG_TAG(cond, uid, gid, tag) \
13475+ ((cond) ? (tag) : 0)
13476+
13477+#define TAGINO_UID(cond, uid, tag) (uid)
13478+#define TAGINO_GID(cond, gid, tag) (gid)
13479+
13480+#endif
13481+
13482+
13483+#ifndef CONFIG_TAGGING_NONE
13484+#define dx_current_fstag(sb) \
13485+ ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13486+#else
13487+#define dx_current_fstag(sb) (0)
13488+#endif
13489+
13490+#ifndef CONFIG_TAGGING_INTERN
13491+#define TAGINO_TAG(cond, tag) (0)
13492+#else
13493+#define TAGINO_TAG(cond, tag) ((cond) ? (tag) : 0)
13494+#endif
13495+
13496+#define INOTAG_UID(cond, uid, gid) \
13497+ ((cond) ? ((uid) & MAX_UID) : (uid))
13498+#define INOTAG_GID(cond, uid, gid) \
13499+ ((cond) ? ((gid) & MAX_GID) : (gid))
13500+
13501+
13502+static inline uid_t dx_map_uid(uid_t uid)
13503+{
13504+ if ((uid > MAX_UID) && (uid != -1))
13505+ uid = -2;
13506+ return (uid & MAX_UID);
13507+}
13508+
13509+static inline gid_t dx_map_gid(gid_t gid)
13510+{
13511+ if ((gid > MAX_GID) && (gid != -1))
13512+ gid = -2;
13513+ return (gid & MAX_GID);
13514+}
13515+
13516+struct peer_tag {
13517+ int32_t xid;
13518+ int32_t nid;
13519+};
13520+
13521+#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13522+
13523+int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13524+ unsigned long *flags);
13525+
13526+#ifdef CONFIG_PROPAGATE
13527+
13528+void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13529+
13530+#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13531+
13532+#else
13533+#define dx_propagate_tag(n, i) do { } while (0)
13534+#endif
13535+
13536+#endif /* _DX_TAG_H */
13537diff -NurpP --minimal linux-3.6.6/include/linux/vserver/tag_cmd.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/tag_cmd.h
13538--- linux-3.6.6/include/linux/vserver/tag_cmd.h 1970-01-01 01:00:00.000000000 +0100
13539+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/linux/vserver/tag_cmd.h 2012-10-04 18:47:00.000000000 +0200
13540@@ -0,0 +1,22 @@
13541+#ifndef _VX_TAG_CMD_H
13542+#define _VX_TAG_CMD_H
13543+
13544+
13545+/* vinfo commands */
13546+
13547+#define VCMD_task_tag VC_CMD(VINFO, 3, 0)
13548+
13549+#ifdef __KERNEL__
13550+extern int vc_task_tag(uint32_t);
13551+
13552+#endif /* __KERNEL__ */
13553+
13554+/* context commands */
13555+
13556+#define VCMD_tag_migrate VC_CMD(TAGMIG, 1, 0)
13557+
13558+#ifdef __KERNEL__
13559+extern int vc_tag_migrate(uint32_t);
13560+
13561+#endif /* __KERNEL__ */
13562+#endif /* _VX_TAG_CMD_H */
13563diff -NurpP --minimal linux-3.6.6/include/net/addrconf.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/addrconf.h
13564--- linux-3.6.6/include/net/addrconf.h 2012-10-04 15:27:47.000000000 +0200
13565+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/addrconf.h 2012-10-04 18:47:00.000000000 +0200
13566@@ -81,7 +81,8 @@ extern int ipv6_dev_get_saddr(struct n
13567 struct net_device *dev,
13568 const struct in6_addr *daddr,
13569 unsigned int srcprefs,
13570- struct in6_addr *saddr);
13571+ struct in6_addr *saddr,
13572+ struct nx_info *nxi);
13573 extern int ipv6_get_lladdr(struct net_device *dev,
13574 struct in6_addr *addr,
13575 unsigned char banned_flags);
13576diff -NurpP --minimal linux-3.6.6/include/net/af_unix.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/af_unix.h
13577--- linux-3.6.6/include/net/af_unix.h 2012-10-04 15:27:47.000000000 +0200
13578+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/af_unix.h 2012-10-04 18:47:00.000000000 +0200
13579@@ -4,6 +4,7 @@
13580 #include <linux/socket.h>
13581 #include <linux/un.h>
13582 #include <linux/mutex.h>
13583+#include <linux/vs_base.h>
13584 #include <net/sock.h>
13585
13586 extern void unix_inflight(struct file *fp);
13587diff -NurpP --minimal linux-3.6.6/include/net/inet_timewait_sock.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/inet_timewait_sock.h
13588--- linux-3.6.6/include/net/inet_timewait_sock.h 2012-03-19 19:47:29.000000000 +0100
13589+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/inet_timewait_sock.h 2012-10-04 18:47:00.000000000 +0200
13590@@ -112,6 +112,10 @@ struct inet_timewait_sock {
13591 #define tw_net __tw_common.skc_net
13592 #define tw_daddr __tw_common.skc_daddr
13593 #define tw_rcv_saddr __tw_common.skc_rcv_saddr
13594+#define tw_xid __tw_common.skc_xid
13595+#define tw_vx_info __tw_common.skc_vx_info
13596+#define tw_nid __tw_common.skc_nid
13597+#define tw_nx_info __tw_common.skc_nx_info
13598 int tw_timeout;
13599 volatile unsigned char tw_substate;
13600 unsigned char tw_rcv_wscale;
13601diff -NurpP --minimal linux-3.6.6/include/net/ip6_route.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/ip6_route.h
13602--- linux-3.6.6/include/net/ip6_route.h 2012-10-04 15:27:47.000000000 +0200
13603+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/ip6_route.h 2012-10-04 18:47:00.000000000 +0200
13604@@ -97,7 +97,8 @@ extern int ip6_route_get_saddr(struct
13605 struct rt6_info *rt,
13606 const struct in6_addr *daddr,
13607 unsigned int prefs,
13608- struct in6_addr *saddr);
13609+ struct in6_addr *saddr,
13610+ struct nx_info *nxi);
13611
13612 extern struct rt6_info *rt6_lookup(struct net *net,
13613 const struct in6_addr *daddr,
13614diff -NurpP --minimal linux-3.6.6/include/net/route.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/route.h
13615--- linux-3.6.6/include/net/route.h 2012-11-06 18:42:13.000000000 +0100
13616+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/route.h 2012-11-06 18:43:41.000000000 +0100
13617@@ -204,6 +204,9 @@ static inline void ip_rt_put(struct rtab
13618 dst_release(&rt->dst);
13619 }
13620
13621+#include <linux/vs_base.h>
13622+#include <linux/vs_inet.h>
13623+
13624 #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)
13625
13626 extern const __u8 ip_tos2prio[16];
13627@@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13628 protocol, flow_flags, dst, src, dport, sport);
13629 }
13630
13631+extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13632+ struct flowi4 *);
13633+
13634 static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13635 __be32 dst, __be32 src, u32 tos,
13636 int oif, u8 protocol,
13637@@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13638 {
13639 struct net *net = sock_net(sk);
13640 struct rtable *rt;
13641+ struct nx_info *nx_info = current_nx_info();
13642
13643 ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13644 sport, dport, sk, can_sleep);
13645
13646- if (!dst || !src) {
13647+ if (sk)
13648+ nx_info = sk->sk_nx_info;
13649+
13650+ vxdprintk(VXD_CBIT(net, 4),
13651+ "ip_route_connect(%p) %p,%p;%lx",
13652+ sk, nx_info, sk->sk_socket,
13653+ (sk->sk_socket?sk->sk_socket->flags:0));
13654+
13655+ rt = ip_v4_find_src(net, nx_info, fl4);
13656+ if (IS_ERR(rt))
13657+ return rt;
13658+ ip_rt_put(rt);
13659+
13660+ if (!fl4->daddr || !fl4->saddr) {
13661 rt = __ip_route_output_key(net, fl4);
13662 if (IS_ERR(rt))
13663 return rt;
13664diff -NurpP --minimal linux-3.6.6/include/net/sock.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/sock.h
13665--- linux-3.6.6/include/net/sock.h 2012-10-04 15:27:47.000000000 +0200
13666+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/include/net/sock.h 2012-10-04 18:47:00.000000000 +0200
13667@@ -171,6 +171,10 @@ struct sock_common {
13668 #ifdef CONFIG_NET_NS
13669 struct net *skc_net;
13670 #endif
13671+ xid_t skc_xid;
13672+ struct vx_info *skc_vx_info;
13673+ nid_t skc_nid;
13674+ struct nx_info *skc_nx_info;
13675 /*
13676 * fields between dontcopy_begin/dontcopy_end
13677 * are not copied in sock_copy()
13678@@ -284,6 +288,10 @@ struct sock {
13679 #define sk_bind_node __sk_common.skc_bind_node
13680 #define sk_prot __sk_common.skc_prot
13681 #define sk_net __sk_common.skc_net
13682+#define sk_xid __sk_common.skc_xid
13683+#define sk_vx_info __sk_common.skc_vx_info
13684+#define sk_nid __sk_common.skc_nid
13685+#define sk_nx_info __sk_common.skc_nx_info
13686 socket_lock_t sk_lock;
13687 struct sk_buff_head sk_receive_queue;
13688 /*
13689diff -NurpP --minimal linux-3.6.6/init/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/init/Kconfig
13690--- linux-3.6.6/init/Kconfig 2012-10-04 15:27:48.000000000 +0200
13691+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/init/Kconfig 2012-10-04 18:47:00.000000000 +0200
13692@@ -624,6 +624,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
13693 menuconfig CGROUPS
13694 boolean "Control Group support"
13695 depends on EVENTFD
13696+ default y
13697 help
13698 This option adds support for grouping sets of processes together, for
13699 use with process control subsystems such as Cpusets, CFS, memory
13700@@ -889,6 +890,7 @@ config USER_NS
13701 bool "User namespace (EXPERIMENTAL)"
13702 depends on EXPERIMENTAL
13703 depends on UIDGID_CONVERTED
13704+ depends on VSERVER_DISABLED
13705 select UIDGID_STRICT_TYPE_CHECKS
13706
13707 default n
13708diff -NurpP --minimal linux-3.6.6/init/main.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/init/main.c
13709--- linux-3.6.6/init/main.c 2012-11-06 18:42:13.000000000 +0100
13710+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/init/main.c 2012-11-06 18:43:41.000000000 +0100
13711@@ -69,6 +69,7 @@
13712 #include <linux/slab.h>
13713 #include <linux/perf_event.h>
13714 #include <linux/file.h>
13715+#include <linux/vserver/percpu.h>
13716
13717 #include <asm/io.h>
13718 #include <asm/bugs.h>
13719diff -NurpP --minimal linux-3.6.6/ipc/mqueue.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/mqueue.c
13720--- linux-3.6.6/ipc/mqueue.c 2012-10-04 15:27:48.000000000 +0200
13721+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/mqueue.c 2012-10-04 18:47:00.000000000 +0200
13722@@ -35,6 +35,8 @@
13723 #include <linux/ipc_namespace.h>
13724 #include <linux/user_namespace.h>
13725 #include <linux/slab.h>
13726+#include <linux/vs_context.h>
13727+#include <linux/vs_limit.h>
13728
13729 #include <net/sock.h>
13730 #include "util.h"
13731@@ -76,6 +78,7 @@ struct mqueue_inode_info {
13732 struct pid* notify_owner;
13733 struct user_namespace *notify_user_ns;
13734 struct user_struct *user; /* user who created, for accounting */
13735+ struct vx_info *vxi;
13736 struct sock *notify_sock;
13737 struct sk_buff *notify_cookie;
13738
13739@@ -235,6 +238,7 @@ static struct inode *mqueue_get_inode(st
13740 if (S_ISREG(mode)) {
13741 struct mqueue_inode_info *info;
13742 unsigned long mq_bytes, mq_treesize;
13743+ struct vx_info *vxi = current_vx_info();
13744
13745 inode->i_fop = &mqueue_file_operations;
13746 inode->i_size = FILENT_SIZE;
13747@@ -248,6 +252,7 @@ static struct inode *mqueue_get_inode(st
13748 info->notify_user_ns = NULL;
13749 info->qsize = 0;
13750 info->user = NULL; /* set when all is ok */
13751+ info->vxi = NULL;
13752 info->msg_tree = RB_ROOT;
13753 info->node_cache = NULL;
13754 memset(&info->attr, 0, sizeof(info->attr));
13755@@ -281,17 +286,20 @@ static struct inode *mqueue_get_inode(st
13756
13757 spin_lock(&mq_lock);
13758 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13759- u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13760+ u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13761+ !vx_ipcmsg_avail(vxi, mq_bytes)) {
13762 spin_unlock(&mq_lock);
13763 /* mqueue_evict_inode() releases info->messages */
13764 ret = -EMFILE;
13765 goto out_inode;
13766 }
13767 u->mq_bytes += mq_bytes;
13768+ vx_ipcmsg_add(vxi, u, mq_bytes);
13769 spin_unlock(&mq_lock);
13770
13771 /* all is ok */
13772 info->user = get_uid(u);
13773+ info->vxi = get_vx_info(vxi);
13774 } else if (S_ISDIR(mode)) {
13775 inc_nlink(inode);
13776 /* Some things misbehave if size == 0 on a directory */
13777@@ -395,8 +403,11 @@ static void mqueue_evict_inode(struct in
13778
13779 user = info->user;
13780 if (user) {
13781+ struct vx_info *vxi = info->vxi;
13782+
13783 spin_lock(&mq_lock);
13784 user->mq_bytes -= mq_bytes;
13785+ vx_ipcmsg_sub(vxi, user, mq_bytes);
13786 /*
13787 * get_ns_from_inode() ensures that the
13788 * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13789@@ -406,6 +417,7 @@ static void mqueue_evict_inode(struct in
13790 if (ipc_ns)
13791 ipc_ns->mq_queues_count--;
13792 spin_unlock(&mq_lock);
13793+ put_vx_info(vxi);
13794 free_uid(user);
13795 }
13796 if (ipc_ns)
13797diff -NurpP --minimal linux-3.6.6/ipc/msg.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/msg.c
13798--- linux-3.6.6/ipc/msg.c 2011-05-22 16:17:59.000000000 +0200
13799+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/msg.c 2012-10-04 18:47:00.000000000 +0200
13800@@ -37,6 +37,7 @@
13801 #include <linux/rwsem.h>
13802 #include <linux/nsproxy.h>
13803 #include <linux/ipc_namespace.h>
13804+#include <linux/vs_base.h>
13805
13806 #include <asm/current.h>
13807 #include <asm/uaccess.h>
13808@@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13809
13810 msq->q_perm.mode = msgflg & S_IRWXUGO;
13811 msq->q_perm.key = key;
13812+ msq->q_perm.xid = vx_current_xid();
13813
13814 msq->q_perm.security = NULL;
13815 retval = security_msg_queue_alloc(msq);
13816diff -NurpP --minimal linux-3.6.6/ipc/namespace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/namespace.c
13817--- linux-3.6.6/ipc/namespace.c 2012-07-22 23:39:46.000000000 +0200
13818+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/namespace.c 2012-10-04 18:47:00.000000000 +0200
13819@@ -13,11 +13,12 @@
13820 #include <linux/mount.h>
13821 #include <linux/user_namespace.h>
13822 #include <linux/proc_fs.h>
13823+#include <linux/vs_base.h>
13824+#include <linux/vserver/global.h>
13825
13826 #include "util.h"
13827
13828-static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
13829- struct ipc_namespace *old_ns)
13830+static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
13831 {
13832 struct ipc_namespace *ns;
13833 int err;
13834@@ -46,19 +47,19 @@ static struct ipc_namespace *create_ipc_
13835 ipcns_notify(IPCNS_CREATED);
13836 register_ipcns_notifier(ns);
13837
13838- ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
13839+ // ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
13840+ ns->user_ns = get_user_ns(user_ns);
13841
13842 return ns;
13843 }
13844
13845 struct ipc_namespace *copy_ipcs(unsigned long flags,
13846- struct task_struct *tsk)
13847+ struct ipc_namespace *old_ns,
13848+ struct user_namespace *user_ns)
13849 {
13850- struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
13851-
13852 if (!(flags & CLONE_NEWIPC))
13853- return get_ipc_ns(ns);
13854- return create_ipc_ns(tsk, ns);
13855+ return get_ipc_ns(old_ns);
13856+ return create_ipc_ns(user_ns);
13857 }
13858
13859 /*
13860diff -NurpP --minimal linux-3.6.6/ipc/sem.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/sem.c
13861--- linux-3.6.6/ipc/sem.c 2012-01-09 16:14:59.000000000 +0100
13862+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/sem.c 2012-10-04 18:47:00.000000000 +0200
13863@@ -86,6 +86,8 @@
13864 #include <linux/rwsem.h>
13865 #include <linux/nsproxy.h>
13866 #include <linux/ipc_namespace.h>
13867+#include <linux/vs_base.h>
13868+#include <linux/vs_limit.h>
13869
13870 #include <asm/uaccess.h>
13871 #include "util.h"
13872@@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13873
13874 sma->sem_perm.mode = (semflg & S_IRWXUGO);
13875 sma->sem_perm.key = key;
13876+ sma->sem_perm.xid = vx_current_xid();
13877
13878 sma->sem_perm.security = NULL;
13879 retval = security_sem_alloc(sma);
13880@@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13881 return id;
13882 }
13883 ns->used_sems += nsems;
13884+ /* FIXME: obsoleted? */
13885+ vx_semary_inc(sma);
13886+ vx_nsems_add(sma, nsems);
13887
13888 sma->sem_base = (struct sem *) &sma[1];
13889
13890@@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13891
13892 wake_up_sem_queue_do(&tasks);
13893 ns->used_sems -= sma->sem_nsems;
13894+ /* FIXME: obsoleted? */
13895+ vx_nsems_sub(sma, sma->sem_nsems);
13896+ vx_semary_dec(sma);
13897 security_sem_free(sma);
13898 ipc_rcu_putref(sma);
13899 }
13900diff -NurpP --minimal linux-3.6.6/ipc/shm.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/shm.c
13901--- linux-3.6.6/ipc/shm.c 2012-10-04 15:27:48.000000000 +0200
13902+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/ipc/shm.c 2012-10-04 18:47:00.000000000 +0200
13903@@ -39,6 +39,8 @@
13904 #include <linux/nsproxy.h>
13905 #include <linux/mount.h>
13906 #include <linux/ipc_namespace.h>
13907+#include <linux/vs_context.h>
13908+#include <linux/vs_limit.h>
13909
13910 #include <asm/uaccess.h>
13911
13912@@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13913 */
13914 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13915 {
13916- ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13917+ struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13918+ int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13919+
13920+ vx_ipcshm_sub(vxi, shp, numpages);
13921+ ns->shm_tot -= numpages;
13922+
13923 shm_rmid(ns, shp);
13924 shm_unlock(shp);
13925 if (!is_file_hugepages(shp->shm_file))
13926@@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13927 shp->mlock_user);
13928 fput (shp->shm_file);
13929 security_shm_free(shp);
13930+ put_vx_info(vxi);
13931 ipc_rcu_putref(shp);
13932 }
13933
13934@@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13935 if (ns->shm_tot + numpages > ns->shm_ctlall)
13936 return -ENOSPC;
13937
13938+ if (!vx_ipcshm_avail(current_vx_info(), numpages))
13939+ return -ENOSPC;
13940+
13941 shp = ipc_rcu_alloc(sizeof(*shp));
13942 if (!shp)
13943 return -ENOMEM;
13944
13945 shp->shm_perm.key = key;
13946+ shp->shm_perm.xid = vx_current_xid();
13947 shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13948 shp->mlock_user = NULL;
13949
13950@@ -533,6 +545,7 @@ static int newseg(struct ipc_namespace *
13951 ns->shm_tot += numpages;
13952 error = shp->shm_perm.id;
13953 shm_unlock(shp);
13954+ vx_ipcshm_add(current_vx_info(), key, numpages);
13955 return error;
13956
13957 no_id:
13958diff -NurpP --minimal linux-3.6.6/kernel/Makefile linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/Makefile
13959--- linux-3.6.6/kernel/Makefile 2012-07-22 23:39:46.000000000 +0200
13960+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/Makefile 2012-10-04 18:47:00.000000000 +0200
13961@@ -24,6 +24,7 @@ endif
13962
13963 obj-y += sched/
13964 obj-y += power/
13965+obj-y += vserver/
13966
13967 ifeq ($(CONFIG_CHECKPOINT_RESTORE),y)
13968 obj-$(CONFIG_X86) += kcmp.o
13969diff -NurpP --minimal linux-3.6.6/kernel/auditsc.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/auditsc.c
13970--- linux-3.6.6/kernel/auditsc.c 2012-07-22 23:39:46.000000000 +0200
13971+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/auditsc.c 2012-10-04 18:47:00.000000000 +0200
13972@@ -2309,7 +2309,7 @@ int audit_set_loginuid(uid_t loginuid)
13973 if (task->loginuid != -1)
13974 return -EPERM;
13975 #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13976- if (!capable(CAP_AUDIT_CONTROL))
13977+ if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13978 return -EPERM;
13979 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13980
13981diff -NurpP --minimal linux-3.6.6/kernel/capability.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/capability.c
13982--- linux-3.6.6/kernel/capability.c 2012-07-22 23:39:46.000000000 +0200
13983+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/capability.c 2012-10-04 18:47:00.000000000 +0200
13984@@ -15,6 +15,7 @@
13985 #include <linux/syscalls.h>
13986 #include <linux/pid_namespace.h>
13987 #include <linux/user_namespace.h>
13988+#include <linux/vs_context.h>
13989 #include <asm/uaccess.h>
13990
13991 /*
13992@@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13993 return 0;
13994 }
13995
13996+
13997 /*
13998 * The only thing that can change the capabilities of the current
13999 * process is the current process. As such, we can't be in this code
14000@@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14001 return (ret == 0);
14002 }
14003
14004+#include <linux/vserver/base.h>
14005+
14006 /**
14007 * has_capability_noaudit - Does a task have a capability (unaudited) in the
14008 * initial user ns
14009diff -NurpP --minimal linux-3.6.6/kernel/compat.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/compat.c
14010--- linux-3.6.6/kernel/compat.c 2012-07-22 23:39:46.000000000 +0200
14011+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/compat.c 2012-10-04 18:47:00.000000000 +0200
14012@@ -1054,7 +1054,7 @@ asmlinkage long compat_sys_stime(compat_
14013 if (err)
14014 return err;
14015
14016- do_settimeofday(&tv);
14017+ vx_settimeofday(&tv);
14018 return 0;
14019 }
14020
14021diff -NurpP --minimal linux-3.6.6/kernel/cred.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/cred.c
14022--- linux-3.6.6/kernel/cred.c 2012-07-22 23:39:46.000000000 +0200
14023+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/cred.c 2012-10-04 18:47:00.000000000 +0200
14024@@ -70,31 +70,6 @@ struct cred init_cred = {
14025 #endif
14026 };
14027
14028-static inline void set_cred_subscribers(struct cred *cred, int n)
14029-{
14030-#ifdef CONFIG_DEBUG_CREDENTIALS
14031- atomic_set(&cred->subscribers, n);
14032-#endif
14033-}
14034-
14035-static inline int read_cred_subscribers(const struct cred *cred)
14036-{
14037-#ifdef CONFIG_DEBUG_CREDENTIALS
14038- return atomic_read(&cred->subscribers);
14039-#else
14040- return 0;
14041-#endif
14042-}
14043-
14044-static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14045-{
14046-#ifdef CONFIG_DEBUG_CREDENTIALS
14047- struct cred *cred = (struct cred *) _cred;
14048-
14049- atomic_add(n, &cred->subscribers);
14050-#endif
14051-}
14052-
14053 /*
14054 * Dispose of the shared task group credentials
14055 */
14056@@ -284,21 +259,16 @@ error:
14057 *
14058 * Call commit_creds() or abort_creds() to clean up.
14059 */
14060-struct cred *prepare_creds(void)
14061+struct cred *__prepare_creds(const struct cred *old)
14062 {
14063- struct task_struct *task = current;
14064- const struct cred *old;
14065 struct cred *new;
14066
14067- validate_process_creds();
14068-
14069 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14070 if (!new)
14071 return NULL;
14072
14073 kdebug("prepare_creds() alloc %p", new);
14074
14075- old = task->cred;
14076 memcpy(new, old, sizeof(struct cred));
14077
14078 atomic_set(&new->usage, 1);
14079@@ -326,6 +296,13 @@ error:
14080 abort_creds(new);
14081 return NULL;
14082 }
14083+
14084+struct cred *prepare_creds(void)
14085+{
14086+ validate_process_creds();
14087+
14088+ return __prepare_creds(current->cred);
14089+}
14090 EXPORT_SYMBOL(prepare_creds);
14091
14092 /*
14093diff -NurpP --minimal linux-3.6.6/kernel/exit.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/exit.c
14094--- linux-3.6.6/kernel/exit.c 2012-10-04 15:27:48.000000000 +0200
14095+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/exit.c 2012-10-04 18:47:00.000000000 +0200
14096@@ -48,6 +48,10 @@
14097 #include <linux/fs_struct.h>
14098 #include <linux/init_task.h>
14099 #include <linux/perf_event.h>
14100+#include <linux/vs_limit.h>
14101+#include <linux/vs_context.h>
14102+#include <linux/vs_network.h>
14103+#include <linux/vs_pid.h>
14104 #include <trace/events/sched.h>
14105 #include <linux/hw_breakpoint.h>
14106 #include <linux/oom.h>
14107@@ -494,9 +498,11 @@ static void close_files(struct files_str
14108 filp_close(file, files);
14109 cond_resched();
14110 }
14111+ vx_openfd_dec(i);
14112 }
14113 i++;
14114 set >>= 1;
14115+ cond_resched();
14116 }
14117 }
14118 }
14119@@ -1018,6 +1024,9 @@ void do_exit(long code)
14120 */
14121 ptrace_put_breakpoints(tsk);
14122
14123+ /* needs to stay before exit_notify() */
14124+ exit_vx_info_early(tsk, code);
14125+
14126 exit_notify(tsk, group_dead);
14127 #ifdef CONFIG_NUMA
14128 task_lock(tsk);
14129@@ -1068,10 +1077,15 @@ void do_exit(long code)
14130 smp_mb();
14131 raw_spin_unlock_wait(&tsk->pi_lock);
14132
14133+ /* needs to stay after exit_notify() */
14134+ exit_vx_info(tsk, code);
14135+ exit_nx_info(tsk);
14136+
14137 /* causes final put_task_struct in finish_task_switch(). */
14138 tsk->state = TASK_DEAD;
14139 tsk->flags |= PF_NOFREEZE; /* tell freezer to ignore us */
14140 schedule();
14141+ printk("bad task: %p [%lx]\n", current, current->state);
14142 BUG();
14143 /* Avoid "noreturn function does return". */
14144 for (;;)
14145diff -NurpP --minimal linux-3.6.6/kernel/fork.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/fork.c
14146--- linux-3.6.6/kernel/fork.c 2012-10-04 15:27:48.000000000 +0200
14147+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/fork.c 2012-10-04 18:47:00.000000000 +0200
14148@@ -70,6 +70,9 @@
14149 #include <linux/khugepaged.h>
14150 #include <linux/signalfd.h>
14151 #include <linux/uprobes.h>
14152+#include <linux/vs_context.h>
14153+#include <linux/vs_network.h>
14154+#include <linux/vs_limit.h>
14155
14156 #include <asm/pgtable.h>
14157 #include <asm/pgalloc.h>
14158@@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14159 arch_release_thread_info(tsk->stack);
14160 free_thread_info(tsk->stack);
14161 rt_mutex_debug_task_free(tsk);
14162+ clr_vx_info(&tsk->vx_info);
14163+ clr_nx_info(&tsk->nx_info);
14164 ftrace_graph_exit_task(tsk);
14165 put_seccomp_filter(tsk);
14166 arch_release_task_struct(tsk);
14167@@ -541,6 +546,7 @@ static struct mm_struct *mm_init(struct
14168 if (likely(!mm_alloc_pgd(mm))) {
14169 mm->def_flags = 0;
14170 mmu_notifier_mm_init(mm);
14171+ set_vx_info(&mm->mm_vx_info, p->vx_info);
14172 return mm;
14173 }
14174
14175@@ -593,6 +599,7 @@ void __mmdrop(struct mm_struct *mm)
14176 destroy_context(mm);
14177 mmu_notifier_mm_destroy(mm);
14178 check_mm(mm);
14179+ clr_vx_info(&mm->mm_vx_info);
14180 free_mm(mm);
14181 }
14182 EXPORT_SYMBOL_GPL(__mmdrop);
14183@@ -834,6 +841,7 @@ struct mm_struct *dup_mm(struct task_str
14184 goto fail_nomem;
14185
14186 memcpy(mm, oldmm, sizeof(*mm));
14187+ mm->mm_vx_info = NULL;
14188 mm_init_cpumask(mm);
14189
14190 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14191@@ -874,6 +882,7 @@ fail_nocontext:
14192 * If init_new_context() failed, we cannot use mmput() to free the mm
14193 * because it calls destroy_context()
14194 */
14195+ clr_vx_info(&mm->mm_vx_info);
14196 mm_free_pgd(mm);
14197 free_mm(mm);
14198 return NULL;
14199@@ -1157,6 +1166,8 @@ static struct task_struct *copy_process(
14200 int retval;
14201 struct task_struct *p;
14202 int cgroup_callbacks_done = 0;
14203+ struct vx_info *vxi;
14204+ struct nx_info *nxi;
14205
14206 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14207 return ERR_PTR(-EINVAL);
14208@@ -1204,7 +1215,12 @@ static struct task_struct *copy_process(
14209 DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14210 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14211 #endif
14212+ init_vx_info(&p->vx_info, current_vx_info());
14213+ init_nx_info(&p->nx_info, current_nx_info());
14214+
14215 retval = -EAGAIN;
14216+ if (!vx_nproc_avail(1))
14217+ goto bad_fork_free;
14218 if (atomic_read(&p->real_cred->user->processes) >=
14219 task_rlimit(p, RLIMIT_NPROC)) {
14220 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14221@@ -1483,6 +1499,18 @@ static struct task_struct *copy_process(
14222
14223 total_forks++;
14224 spin_unlock(&current->sighand->siglock);
14225+
14226+ /* p is copy of current */
14227+ vxi = p->vx_info;
14228+ if (vxi) {
14229+ claim_vx_info(vxi, p);
14230+ atomic_inc(&vxi->cvirt.nr_threads);
14231+ atomic_inc(&vxi->cvirt.total_forks);
14232+ vx_nproc_inc(p);
14233+ }
14234+ nxi = p->nx_info;
14235+ if (nxi)
14236+ claim_nx_info(nxi, p);
14237 write_unlock_irq(&tasklist_lock);
14238 proc_fork_connector(p);
14239 cgroup_post_fork(p);
14240diff -NurpP --minimal linux-3.6.6/kernel/kthread.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/kthread.c
14241--- linux-3.6.6/kernel/kthread.c 2012-10-04 15:27:48.000000000 +0200
14242+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/kthread.c 2012-10-04 18:47:00.000000000 +0200
14243@@ -16,6 +16,7 @@
14244 #include <linux/mutex.h>
14245 #include <linux/slab.h>
14246 #include <linux/freezer.h>
14247+#include <linux/vs_pid.h>
14248 #include <trace/events/sched.h>
14249
14250 static DEFINE_SPINLOCK(kthread_create_lock);
14251diff -NurpP --minimal linux-3.6.6/kernel/nsproxy.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/nsproxy.c
14252--- linux-3.6.6/kernel/nsproxy.c 2012-01-09 16:15:00.000000000 +0100
14253+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/nsproxy.c 2012-10-04 18:47:00.000000000 +0200
14254@@ -20,11 +20,14 @@
14255 #include <linux/mnt_namespace.h>
14256 #include <linux/utsname.h>
14257 #include <linux/pid_namespace.h>
14258+#include <linux/vserver/global.h>
14259+#include <linux/vserver/debug.h>
14260 #include <net/net_namespace.h>
14261 #include <linux/ipc_namespace.h>
14262 #include <linux/proc_fs.h>
14263 #include <linux/file.h>
14264 #include <linux/syscalls.h>
14265+#include "../fs/mount.h"
14266
14267 static struct kmem_cache *nsproxy_cachep;
14268
14269@@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14270 struct nsproxy *nsproxy;
14271
14272 nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14273- if (nsproxy)
14274+ if (nsproxy) {
14275 atomic_set(&nsproxy->count, 1);
14276+ atomic_inc(&vs_global_nsproxy);
14277+ }
14278+ vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14279 return nsproxy;
14280 }
14281
14282@@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14283 * Return the newly created nsproxy. Do not attach this to the task,
14284 * leave it to the caller to do proper locking and attach it to task.
14285 */
14286-static struct nsproxy *create_new_namespaces(unsigned long flags,
14287- struct task_struct *tsk, struct fs_struct *new_fs)
14288+static struct nsproxy *unshare_namespaces(unsigned long flags,
14289+ struct nsproxy *orig,
14290+ struct fs_struct *new_fs,
14291+ struct user_namespace *new_user,
14292+ struct pid_namespace *new_pid)
14293 {
14294 struct nsproxy *new_nsp;
14295 int err;
14296@@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14297 if (!new_nsp)
14298 return ERR_PTR(-ENOMEM);
14299
14300- new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14301+ new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14302 if (IS_ERR(new_nsp->mnt_ns)) {
14303 err = PTR_ERR(new_nsp->mnt_ns);
14304 goto out_ns;
14305 }
14306
14307- new_nsp->uts_ns = copy_utsname(flags, tsk);
14308+ new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14309 if (IS_ERR(new_nsp->uts_ns)) {
14310 err = PTR_ERR(new_nsp->uts_ns);
14311 goto out_uts;
14312 }
14313
14314- new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14315+ new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14316 if (IS_ERR(new_nsp->ipc_ns)) {
14317 err = PTR_ERR(new_nsp->ipc_ns);
14318 goto out_ipc;
14319 }
14320
14321- new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14322+ new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14323 if (IS_ERR(new_nsp->pid_ns)) {
14324 err = PTR_ERR(new_nsp->pid_ns);
14325 goto out_pid;
14326 }
14327
14328- new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14329+ new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14330 if (IS_ERR(new_nsp->net_ns)) {
14331 err = PTR_ERR(new_nsp->net_ns);
14332 goto out_net;
14333@@ -115,6 +124,40 @@ out_ns:
14334 return ERR_PTR(err);
14335 }
14336
14337+static struct nsproxy *create_new_namespaces(unsigned long flags,
14338+ struct task_struct *tsk, struct fs_struct *new_fs)
14339+{
14340+ return unshare_namespaces(flags, tsk->nsproxy,
14341+ new_fs, task_cred_xxx(tsk, user_ns),
14342+ task_active_pid_ns(tsk));
14343+}
14344+
14345+/*
14346+ * copies the nsproxy, setting refcount to 1, and grabbing a
14347+ * reference to all contained namespaces.
14348+ */
14349+struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14350+{
14351+ struct nsproxy *ns = create_nsproxy();
14352+
14353+ if (ns) {
14354+ memcpy(ns, orig, sizeof(struct nsproxy));
14355+ atomic_set(&ns->count, 1);
14356+
14357+ if (ns->mnt_ns)
14358+ get_mnt_ns(ns->mnt_ns);
14359+ if (ns->uts_ns)
14360+ get_uts_ns(ns->uts_ns);
14361+ if (ns->ipc_ns)
14362+ get_ipc_ns(ns->ipc_ns);
14363+ if (ns->pid_ns)
14364+ get_pid_ns(ns->pid_ns);
14365+ if (ns->net_ns)
14366+ get_net(ns->net_ns);
14367+ }
14368+ return ns;
14369+}
14370+
14371 /*
14372 * called from clone. This now handles copy for nsproxy and all
14373 * namespaces therein.
14374@@ -122,9 +165,12 @@ out_ns:
14375 int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14376 {
14377 struct nsproxy *old_ns = tsk->nsproxy;
14378- struct nsproxy *new_ns;
14379+ struct nsproxy *new_ns = NULL;
14380 int err = 0;
14381
14382+ vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14383+ flags, tsk, old_ns);
14384+
14385 if (!old_ns)
14386 return 0;
14387
14388@@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14389 CLONE_NEWPID | CLONE_NEWNET)))
14390 return 0;
14391
14392- if (!capable(CAP_SYS_ADMIN)) {
14393+ if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14394 err = -EPERM;
14395 goto out;
14396 }
14397@@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14398
14399 out:
14400 put_nsproxy(old_ns);
14401+ vxdprintk(VXD_CBIT(space, 3),
14402+ "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14403+ flags, tsk, old_ns, err, new_ns);
14404 return err;
14405 }
14406
14407@@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14408 put_ipc_ns(ns->ipc_ns);
14409 if (ns->pid_ns)
14410 put_pid_ns(ns->pid_ns);
14411- put_net(ns->net_ns);
14412+ if (ns->net_ns)
14413+ put_net(ns->net_ns);
14414+ atomic_dec(&vs_global_nsproxy);
14415 kmem_cache_free(nsproxy_cachep, ns);
14416 }
14417
14418@@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned
14419 {
14420 int err = 0;
14421
14422+ vxdprintk(VXD_CBIT(space, 4),
14423+ "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14424+ unshare_flags, current->nsproxy);
14425+
14426 if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14427 CLONE_NEWNET)))
14428 return 0;
14429
14430- if (!capable(CAP_SYS_ADMIN))
14431+ if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14432 return -EPERM;
14433
14434 *new_nsp = create_new_namespaces(unshare_flags, current,
14435diff -NurpP --minimal linux-3.6.6/kernel/pid.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/pid.c
14436--- linux-3.6.6/kernel/pid.c 2012-07-22 23:39:46.000000000 +0200
14437+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/pid.c 2012-10-04 18:47:00.000000000 +0200
14438@@ -36,6 +36,7 @@
14439 #include <linux/pid_namespace.h>
14440 #include <linux/init_task.h>
14441 #include <linux/syscalls.h>
14442+#include <linux/vs_pid.h>
14443
14444 #define pid_hashfn(nr, ns) \
14445 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14446@@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14447
14448 struct pid *find_vpid(int nr)
14449 {
14450- return find_pid_ns(nr, current->nsproxy->pid_ns);
14451+ return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14452 }
14453 EXPORT_SYMBOL_GPL(find_vpid);
14454
14455@@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14456 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14457 {
14458 struct task_struct *result = NULL;
14459+
14460+ if (type == PIDTYPE_REALPID)
14461+ type = PIDTYPE_PID;
14462 if (pid) {
14463 struct hlist_node *first;
14464 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14465@@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14466 rcu_lockdep_assert(rcu_read_lock_held(),
14467 "find_task_by_pid_ns() needs rcu_read_lock()"
14468 " protection");
14469- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14470+ return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14471 }
14472
14473 struct task_struct *find_task_by_vpid(pid_t vnr)
14474@@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14475 }
14476 EXPORT_SYMBOL_GPL(find_get_pid);
14477
14478-pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14479+pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14480 {
14481 struct upid *upid;
14482 pid_t nr = 0;
14483@@ -480,6 +484,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14484 return nr;
14485 }
14486
14487+pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14488+{
14489+ return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14490+}
14491+
14492 pid_t pid_vnr(struct pid *pid)
14493 {
14494 return pid_nr_ns(pid, current->nsproxy->pid_ns);
14495diff -NurpP --minimal linux-3.6.6/kernel/pid_namespace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/pid_namespace.c
14496--- linux-3.6.6/kernel/pid_namespace.c 2012-10-04 15:27:48.000000000 +0200
14497+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/pid_namespace.c 2012-10-04 18:47:00.000000000 +0200
14498@@ -16,6 +16,7 @@
14499 #include <linux/slab.h>
14500 #include <linux/proc_fs.h>
14501 #include <linux/reboot.h>
14502+#include <linux/vserver/global.h>
14503
14504 #define BITS_PER_PAGE (PAGE_SIZE*8)
14505
14506@@ -89,6 +90,7 @@ static struct pid_namespace *create_pid_
14507 goto out_free_map;
14508
14509 kref_init(&ns->kref);
14510+ atomic_inc(&vs_global_pid_ns);
14511 ns->level = level;
14512 ns->parent = get_pid_ns(parent_pid_ns);
14513
14514@@ -120,6 +122,7 @@ static void destroy_pid_namespace(struct
14515
14516 for (i = 0; i < PIDMAP_ENTRIES; i++)
14517 kfree(ns->pidmap[i].page);
14518+ atomic_dec(&vs_global_pid_ns);
14519 kmem_cache_free(pid_ns_cachep, ns);
14520 }
14521
14522diff -NurpP --minimal linux-3.6.6/kernel/posix-timers.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/posix-timers.c
14523--- linux-3.6.6/kernel/posix-timers.c 2012-01-09 16:15:00.000000000 +0100
14524+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/posix-timers.c 2012-10-04 18:47:00.000000000 +0200
14525@@ -47,6 +47,7 @@
14526 #include <linux/wait.h>
14527 #include <linux/workqueue.h>
14528 #include <linux/export.h>
14529+#include <linux/vs_context.h>
14530
14531 /*
14532 * Management arrays for POSIX timers. Timers are kept in slab memory
14533@@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14534 {
14535 struct task_struct *task;
14536 int shared, ret = -1;
14537+
14538 /*
14539 * FIXME: if ->sigq is queued we can race with
14540 * dequeue_signal()->do_schedule_next_timer().
14541@@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14542 rcu_read_lock();
14543 task = pid_task(timr->it_pid, PIDTYPE_PID);
14544 if (task) {
14545+ struct vx_info_save vxis;
14546+ struct vx_info *vxi;
14547+
14548+ vxi = get_vx_info(task->vx_info);
14549+ enter_vx_info(vxi, &vxis);
14550 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14551 ret = send_sigqueue(timr->sigq, task, shared);
14552+ leave_vx_info(&vxis);
14553+ put_vx_info(vxi);
14554 }
14555 rcu_read_unlock();
14556+
14557 /* If we failed to send the signal the timer stops. */
14558 return ret > 0;
14559 }
14560diff -NurpP --minimal linux-3.6.6/kernel/printk.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/printk.c
14561--- linux-3.6.6/kernel/printk.c 2012-10-04 15:27:48.000000000 +0200
14562+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/printk.c 2012-10-04 18:47:00.000000000 +0200
14563@@ -42,6 +42,7 @@
14564 #include <linux/notifier.h>
14565 #include <linux/rculist.h>
14566 #include <linux/poll.h>
14567+#include <linux/vs_cvirt.h>
14568
14569 #include <asm/uaccess.h>
14570
14571@@ -818,7 +819,7 @@ static int check_syslog_permissions(int
14572 return 0;
14573
14574 if (syslog_action_restricted(type)) {
14575- if (capable(CAP_SYSLOG))
14576+ if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14577 return 0;
14578 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14579 if (capable(CAP_SYS_ADMIN)) {
14580@@ -1111,12 +1112,9 @@ int do_syslog(int type, char __user *buf
14581 if (error)
14582 return error;
14583
14584- switch (type) {
14585- case SYSLOG_ACTION_CLOSE: /* Close log */
14586- break;
14587- case SYSLOG_ACTION_OPEN: /* Open log */
14588- break;
14589- case SYSLOG_ACTION_READ: /* Read from log */
14590+ if ((type == SYSLOG_ACTION_READ) ||
14591+ (type == SYSLOG_ACTION_READ_ALL) ||
14592+ (type == SYSLOG_ACTION_READ_CLEAR)) {
14593 error = -EINVAL;
14594 if (!buf || len < 0)
14595 goto out;
14596@@ -1127,6 +1125,16 @@ int do_syslog(int type, char __user *buf
14597 error = -EFAULT;
14598 goto out;
14599 }
14600+ }
14601+ if (!vx_check(0, VS_ADMIN|VS_WATCH))
14602+ return vx_do_syslog(type, buf, len);
14603+
14604+ switch (type) {
14605+ case SYSLOG_ACTION_CLOSE: /* Close log */
14606+ break;
14607+ case SYSLOG_ACTION_OPEN: /* Open log */
14608+ break;
14609+ case SYSLOG_ACTION_READ: /* Read from log */
14610 error = wait_event_interruptible(log_wait,
14611 syslog_seq != log_next_seq);
14612 if (error)
14613@@ -1139,16 +1147,6 @@ int do_syslog(int type, char __user *buf
14614 /* FALL THRU */
14615 /* Read last kernel messages */
14616 case SYSLOG_ACTION_READ_ALL:
14617- error = -EINVAL;
14618- if (!buf || len < 0)
14619- goto out;
14620- error = 0;
14621- if (!len)
14622- goto out;
14623- if (!access_ok(VERIFY_WRITE, buf, len)) {
14624- error = -EFAULT;
14625- goto out;
14626- }
14627 error = syslog_print_all(buf, len, clear);
14628 break;
14629 /* Clear ring buffer */
14630diff -NurpP --minimal linux-3.6.6/kernel/ptrace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/ptrace.c
14631--- linux-3.6.6/kernel/ptrace.c 2012-07-22 23:39:46.000000000 +0200
14632+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/ptrace.c 2012-10-04 18:47:00.000000000 +0200
14633@@ -22,6 +22,7 @@
14634 #include <linux/syscalls.h>
14635 #include <linux/uaccess.h>
14636 #include <linux/regset.h>
14637+#include <linux/vs_context.h>
14638 #include <linux/hw_breakpoint.h>
14639 #include <linux/cn_proc.h>
14640
14641@@ -216,6 +217,11 @@ ok:
14642 dumpable = get_dumpable(task->mm);
14643 if (!dumpable && !ptrace_has_cap(task_user_ns(task), mode))
14644 return -EPERM;
14645+ if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14646+ return -EPERM;
14647+ if (!vx_check(task->xid, VS_IDENT) &&
14648+ !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14649+ return -EACCES;
14650
14651 return security_ptrace_access_check(task, mode);
14652 }
14653diff -NurpP --minimal linux-3.6.6/kernel/sched/core.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sched/core.c
14654--- linux-3.6.6/kernel/sched/core.c 2012-11-06 18:42:14.000000000 +0100
14655+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sched/core.c 2012-11-06 18:43:41.000000000 +0100
14656@@ -72,6 +72,8 @@
14657 #include <linux/slab.h>
14658 #include <linux/init_task.h>
14659 #include <linux/binfmts.h>
14660+#include <linux/vs_sched.h>
14661+#include <linux/vs_cvirt.h>
14662
14663 #include <asm/switch_to.h>
14664 #include <asm/tlb.h>
14665@@ -2223,9 +2225,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14666 */
14667 void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14668 {
14669- loads[0] = (avenrun[0] + offset) << shift;
14670- loads[1] = (avenrun[1] + offset) << shift;
14671- loads[2] = (avenrun[2] + offset) << shift;
14672+ if (vx_flags(VXF_VIRT_LOAD, 0)) {
14673+ struct vx_info *vxi = current_vx_info();
14674+
14675+ loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14676+ loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14677+ loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14678+ } else {
14679+ loads[0] = (avenrun[0] + offset) << shift;
14680+ loads[1] = (avenrun[1] + offset) << shift;
14681+ loads[2] = (avenrun[2] + offset) << shift;
14682+ }
14683 }
14684
14685 static long calc_load_fold_active(struct rq *this_rq)
14686@@ -2854,14 +2864,17 @@ static inline void task_group_account_fi
14687 void account_user_time(struct task_struct *p, cputime_t cputime,
14688 cputime_t cputime_scaled)
14689 {
14690+ struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14691+ int nice = (TASK_NICE(p) > 0);
14692 int index;
14693
14694 /* Add user time to process. */
14695 p->utime += cputime;
14696 p->utimescaled += cputime_scaled;
14697+ vx_account_user(vxi, cputime, nice);
14698 account_group_user_time(p, cputime);
14699
14700- index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14701+ index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14702
14703 /* Add user time to cpustat. */
14704 task_group_account_field(p, index, (__force u64) cputime);
14705@@ -2908,9 +2921,12 @@ static inline
14706 void __account_system_time(struct task_struct *p, cputime_t cputime,
14707 cputime_t cputime_scaled, int index)
14708 {
14709+ struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14710+
14711 /* Add system time to process. */
14712 p->stime += cputime;
14713 p->stimescaled += cputime_scaled;
14714+ vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14715 account_group_system_time(p, cputime);
14716
14717 /* Add system time to cpustat. */
14718@@ -4137,7 +4153,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14719 nice = 19;
14720
14721 if (increment < 0 && !can_nice(current, nice))
14722- return -EPERM;
14723+ return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14724
14725 retval = security_task_setnice(current, nice);
14726 if (retval)
14727diff -NurpP --minimal linux-3.6.6/kernel/sched/fair.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sched/fair.c
14728--- linux-3.6.6/kernel/sched/fair.c 2012-10-04 15:27:48.000000000 +0200
14729+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sched/fair.c 2012-10-04 18:47:00.000000000 +0200
14730@@ -26,6 +26,7 @@
14731 #include <linux/slab.h>
14732 #include <linux/profile.h>
14733 #include <linux/interrupt.h>
14734+#include <linux/vs_cvirt.h>
14735
14736 #include <trace/events/sched.h>
14737
14738@@ -1111,6 +1112,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14739 __enqueue_entity(cfs_rq, se);
14740 se->on_rq = 1;
14741
14742+ if (entity_is_task(se))
14743+ vx_activate_task(task_of(se));
14744 if (cfs_rq->nr_running == 1) {
14745 list_add_leaf_cfs_rq(cfs_rq);
14746 check_enqueue_throttle(cfs_rq);
14747@@ -1191,6 +1194,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14748 if (se != cfs_rq->curr)
14749 __dequeue_entity(cfs_rq, se);
14750 se->on_rq = 0;
14751+ if (entity_is_task(se))
14752+ vx_deactivate_task(task_of(se));
14753 update_cfs_load(cfs_rq, 0);
14754 account_entity_dequeue(cfs_rq, se);
14755
14756diff -NurpP --minimal linux-3.6.6/kernel/signal.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/signal.c
14757--- linux-3.6.6/kernel/signal.c 2012-10-04 15:27:48.000000000 +0200
14758+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/signal.c 2012-10-04 18:47:00.000000000 +0200
14759@@ -30,6 +30,8 @@
14760 #include <linux/nsproxy.h>
14761 #include <linux/user_namespace.h>
14762 #include <linux/uprobes.h>
14763+#include <linux/vs_context.h>
14764+#include <linux/vs_pid.h>
14765 #define CREATE_TRACE_POINTS
14766 #include <trace/events/signal.h>
14767
14768@@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14769 struct pid *sid;
14770 int error;
14771
14772+ vxdprintk(VXD_CBIT(misc, 7),
14773+ "check_kill_permission(%d,%p,%p[#%u,%u])",
14774+ sig, info, t, vx_task_xid(t), t->pid);
14775+
14776 if (!valid_signal(sig))
14777 return -EINVAL;
14778
14779+/* FIXME: needed? if so, why?
14780+ if ((info != SEND_SIG_NOINFO) &&
14781+ (is_si_special(info) || !si_fromuser(info)))
14782+ goto skip; */
14783+
14784 if (!si_fromuser(info))
14785 return 0;
14786
14787@@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14788 }
14789 }
14790
14791+ error = -EPERM;
14792+ if (t->pid == 1 && current->xid)
14793+ return error;
14794+
14795+ error = -ESRCH;
14796+ /* FIXME: we shouldn't return ESRCH ever, to avoid
14797+ loops, maybe ENOENT or EACCES? */
14798+ if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14799+ vxdprintk(current->xid || VXD_CBIT(misc, 7),
14800+ "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14801+ sig, info, t, vx_task_xid(t), t->pid, current->xid);
14802+ return error;
14803+ }
14804+/* skip: */
14805 return security_task_kill(t, info, sig, 0);
14806 }
14807
14808@@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14809 rcu_read_lock();
14810 retry:
14811 p = pid_task(pid, PIDTYPE_PID);
14812- if (p) {
14813+ if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14814 error = group_send_sig_info(sig, info, p);
14815 if (unlikely(error == -ESRCH))
14816 /*
14817@@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14818
14819 rcu_read_lock();
14820 p = pid_task(pid, PIDTYPE_PID);
14821- if (!p) {
14822+ if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14823 ret = -ESRCH;
14824 goto out_unlock;
14825 }
14826@@ -1451,8 +1476,10 @@ static int kill_something_info(int sig,
14827 struct task_struct * p;
14828
14829 for_each_process(p) {
14830- if (task_pid_vnr(p) > 1 &&
14831- !same_thread_group(p, current)) {
14832+ if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14833+ task_pid_vnr(p) > 1 &&
14834+ !same_thread_group(p, current) &&
14835+ !vx_current_initpid(p->pid)) {
14836 int err = group_send_sig_info(sig, info, p);
14837 ++count;
14838 if (err != -EPERM)
14839@@ -2317,6 +2344,11 @@ relock:
14840 !sig_kernel_only(signr))
14841 continue;
14842
14843+ /* virtual init is protected against user signals */
14844+ if ((info->si_code == SI_USER) &&
14845+ vx_current_initpid(current->pid))
14846+ continue;
14847+
14848 if (sig_kernel_stop(signr)) {
14849 /*
14850 * The default action is to stop all threads in
14851diff -NurpP --minimal linux-3.6.6/kernel/softirq.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/softirq.c
14852--- linux-3.6.6/kernel/softirq.c 2012-10-04 15:27:48.000000000 +0200
14853+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/softirq.c 2012-10-04 18:47:00.000000000 +0200
14854@@ -24,6 +24,7 @@
14855 #include <linux/ftrace.h>
14856 #include <linux/smp.h>
14857 #include <linux/tick.h>
14858+#include <linux/vs_context.h>
14859
14860 #define CREATE_TRACE_POINTS
14861 #include <trace/events/irq.h>
14862diff -NurpP --minimal linux-3.6.6/kernel/sys.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sys.c
14863--- linux-3.6.6/kernel/sys.c 2012-11-06 18:42:14.000000000 +0100
14864+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sys.c 2012-11-06 18:43:41.000000000 +0100
14865@@ -47,6 +47,7 @@
14866 #include <linux/syscalls.h>
14867 #include <linux/kprobes.h>
14868 #include <linux/user_namespace.h>
14869+#include <linux/vs_pid.h>
14870
14871 #include <linux/kmsg_dump.h>
14872 /* Move somewhere else to avoid recompiling? */
14873@@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
14874 goto out;
14875 }
14876 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14877- error = -EACCES;
14878+ if (vx_flags(VXF_IGNEG_NICE, 0))
14879+ error = 0;
14880+ else
14881+ error = -EACCES;
14882 goto out;
14883 }
14884 no_nice = security_task_setnice(p, niceval);
14885@@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14886 else
14887 pgrp = task_pgrp(current);
14888 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14889+ if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14890+ continue;
14891 error = set_one_prio(p, niceval, error);
14892 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14893 break;
14894@@ -270,6 +276,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14895 else
14896 pgrp = task_pgrp(current);
14897 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14898+ if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14899+ continue;
14900 niceval = 20 - task_nice(p);
14901 if (niceval > retval)
14902 retval = niceval;
14903@@ -422,6 +430,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14904
14905 static DEFINE_MUTEX(reboot_mutex);
14906
14907+long vs_reboot(unsigned int, void __user *);
14908+
14909 /*
14910 * Reboot system call: for obvious reasons only root may call it,
14911 * and even root needs to set up some magic numbers in the registers
14912@@ -463,6 +473,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14913 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14914 cmd = LINUX_REBOOT_CMD_HALT;
14915
14916+ if (!vx_check(0, VS_ADMIN|VS_WATCH))
14917+ return vs_reboot(cmd, arg);
14918+
14919 mutex_lock(&reboot_mutex);
14920 switch (cmd) {
14921 case LINUX_REBOOT_CMD_RESTART:
14922@@ -1370,7 +1383,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14923 int errno;
14924 char tmp[__NEW_UTS_LEN];
14925
14926- if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14927+ if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14928+ CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14929 return -EPERM;
14930
14931 if (len < 0 || len > __NEW_UTS_LEN)
14932@@ -1421,7 +1435,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14933 int errno;
14934 char tmp[__NEW_UTS_LEN];
14935
14936- if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14937+ if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14938+ CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14939 return -EPERM;
14940 if (len < 0 || len > __NEW_UTS_LEN)
14941 return -EINVAL;
14942@@ -1540,7 +1555,7 @@ int do_prlimit(struct task_struct *tsk,
14943 /* Keep the capable check against init_user_ns until
14944 cgroups can contain all limits */
14945 if (new_rlim->rlim_max > rlim->rlim_max &&
14946- !capable(CAP_SYS_RESOURCE))
14947+ !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14948 retval = -EPERM;
14949 if (!retval)
14950 retval = security_task_setrlimit(tsk->group_leader,
14951@@ -1593,7 +1608,8 @@ static int check_prlimit_permission(stru
14952 gid_eq(cred->gid, tcred->sgid) &&
14953 gid_eq(cred->gid, tcred->gid))
14954 return 0;
14955- if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14956+ if (vx_ns_capable(tcred->user_ns,
14957+ CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14958 return 0;
14959
14960 return -EPERM;
14961diff -NurpP --minimal linux-3.6.6/kernel/sysctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sysctl.c
14962--- linux-3.6.6/kernel/sysctl.c 2012-10-04 15:27:48.000000000 +0200
14963+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sysctl.c 2012-10-04 18:47:00.000000000 +0200
14964@@ -82,6 +82,7 @@
14965 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14966 #include <linux/lockdep.h>
14967 #endif
14968+extern char vshelper_path[];
14969 #ifdef CONFIG_CHR_DEV_SG
14970 #include <scsi/sg.h>
14971 #endif
14972@@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
14973 .proc_handler = proc_dostring,
14974 },
14975 #endif
14976+ {
14977+ .procname = "vshelper",
14978+ .data = &vshelper_path,
14979+ .maxlen = 256,
14980+ .mode = 0644,
14981+ .proc_handler = &proc_dostring,
14982+ },
14983 #ifdef CONFIG_CHR_DEV_SG
14984 {
14985 .procname = "sg-big-buff",
14986diff -NurpP --minimal linux-3.6.6/kernel/sysctl_binary.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sysctl_binary.c
14987--- linux-3.6.6/kernel/sysctl_binary.c 2012-10-04 15:27:48.000000000 +0200
14988+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/sysctl_binary.c 2012-10-04 18:47:00.000000000 +0200
14989@@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14990
14991 { CTL_INT, KERN_PANIC, "panic" },
14992 { CTL_INT, KERN_REALROOTDEV, "real-root-dev" },
14993+ { CTL_STR, KERN_VSHELPER, "vshelper" },
14994
14995 { CTL_STR, KERN_SPARC_REBOOT, "reboot-cmd" },
14996 { CTL_INT, KERN_CTLALTDEL, "ctrl-alt-del" },
14997diff -NurpP --minimal linux-3.6.6/kernel/time/timekeeping.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/time/timekeeping.c
14998--- linux-3.6.6/kernel/time/timekeeping.c 2012-11-06 18:42:14.000000000 +0100
14999+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/time/timekeeping.c 2012-11-06 18:43:41.000000000 +0100
15000@@ -309,6 +309,7 @@ void getnstimeofday(struct timespec *ts)
15001
15002 ts->tv_nsec = 0;
15003 timespec_add_ns(ts, nsecs);
15004+ vx_adjust_timespec(ts);
15005 }
15006 EXPORT_SYMBOL(getnstimeofday);
15007
15008diff -NurpP --minimal linux-3.6.6/kernel/time.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/time.c
15009--- linux-3.6.6/kernel/time.c 2012-05-21 18:07:34.000000000 +0200
15010+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/time.c 2012-10-04 18:47:00.000000000 +0200
15011@@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15012 if (err)
15013 return err;
15014
15015- do_settimeofday(&tv);
15016+ vx_settimeofday(&tv);
15017 return 0;
15018 }
15019
15020@@ -172,7 +172,7 @@ int do_sys_settimeofday(const struct tim
15021 }
15022 }
15023 if (tv)
15024- return do_settimeofday(tv);
15025+ return vx_settimeofday(tv);
15026 return 0;
15027 }
15028
15029diff -NurpP --minimal linux-3.6.6/kernel/timer.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/timer.c
15030--- linux-3.6.6/kernel/timer.c 2012-11-06 18:42:14.000000000 +0100
15031+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/timer.c 2012-11-06 18:43:41.000000000 +0100
15032@@ -40,6 +40,10 @@
15033 #include <linux/irq_work.h>
15034 #include <linux/sched.h>
15035 #include <linux/slab.h>
15036+#include <linux/vs_base.h>
15037+#include <linux/vs_cvirt.h>
15038+#include <linux/vs_pid.h>
15039+#include <linux/vserver/sched.h>
15040
15041 #include <asm/uaccess.h>
15042 #include <asm/unistd.h>
15043diff -NurpP --minimal linux-3.6.6/kernel/user_namespace.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/user_namespace.c
15044--- linux-3.6.6/kernel/user_namespace.c 2012-07-22 23:39:47.000000000 +0200
15045+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/user_namespace.c 2012-10-04 18:47:00.000000000 +0200
15046@@ -19,6 +19,7 @@
15047 #include <linux/fs.h>
15048 #include <linux/uaccess.h>
15049 #include <linux/ctype.h>
15050+#include <linux/vserver/global.h>
15051
15052 static struct kmem_cache *user_ns_cachep __read_mostly;
15053
15054@@ -52,6 +53,7 @@ int create_user_ns(struct cred *new)
15055 return -ENOMEM;
15056
15057 kref_init(&ns->kref);
15058+ atomic_inc(&vs_global_user_ns);
15059 ns->parent = parent_ns;
15060 ns->owner = owner;
15061 ns->group = group;
15062@@ -84,6 +86,9 @@ void free_user_ns(struct kref *kref)
15063
15064 parent = ns->parent;
15065 kmem_cache_free(user_ns_cachep, ns);
15066+
15067+ /* FIXME: maybe move into destroyer? */
15068+ atomic_dec(&vs_global_user_ns);
15069 put_user_ns(parent);
15070 }
15071 EXPORT_SYMBOL(free_user_ns);
15072diff -NurpP --minimal linux-3.6.6/kernel/utsname.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/utsname.c
15073--- linux-3.6.6/kernel/utsname.c 2012-07-22 23:39:47.000000000 +0200
15074+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/utsname.c 2012-10-04 18:47:00.000000000 +0200
15075@@ -16,14 +16,17 @@
15076 #include <linux/slab.h>
15077 #include <linux/user_namespace.h>
15078 #include <linux/proc_fs.h>
15079+#include <linux/vserver/global.h>
15080
15081 static struct uts_namespace *create_uts_ns(void)
15082 {
15083 struct uts_namespace *uts_ns;
15084
15085 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15086- if (uts_ns)
15087+ if (uts_ns) {
15088 kref_init(&uts_ns->kref);
15089+ atomic_inc(&vs_global_uts_ns);
15090+ }
15091 return uts_ns;
15092 }
15093
15094@@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15095 * @old_ns: namespace to clone
15096 * Return NULL on error (failure to kmalloc), new ns otherwise
15097 */
15098-static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15099- struct uts_namespace *old_ns)
15100+static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15101+ struct user_namespace *old_user)
15102 {
15103 struct uts_namespace *ns;
15104
15105@@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15106
15107 down_read(&uts_sem);
15108 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15109- ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
15110+ ns->user_ns = get_user_ns(old_user);
15111 up_read(&uts_sem);
15112 return ns;
15113 }
15114@@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15115 * versa.
15116 */
15117 struct uts_namespace *copy_utsname(unsigned long flags,
15118- struct task_struct *tsk)
15119+ struct uts_namespace *old_ns,
15120+ struct user_namespace *user_ns)
15121 {
15122- struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15123 struct uts_namespace *new_ns;
15124
15125 BUG_ON(!old_ns);
15126@@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15127 if (!(flags & CLONE_NEWUTS))
15128 return old_ns;
15129
15130- new_ns = clone_uts_ns(tsk, old_ns);
15131+ new_ns = clone_uts_ns(old_ns, user_ns);
15132
15133 put_uts_ns(old_ns);
15134 return new_ns;
15135@@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15136
15137 ns = container_of(kref, struct uts_namespace, kref);
15138 put_user_ns(ns->user_ns);
15139+ atomic_dec(&vs_global_uts_ns);
15140 kfree(ns);
15141 }
15142
15143diff -NurpP --minimal linux-3.6.6/kernel/vserver/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/Kconfig
15144--- linux-3.6.6/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
15145+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/Kconfig 2012-10-04 18:47:00.000000000 +0200
15146@@ -0,0 +1,224 @@
15147+#
15148+# Linux VServer configuration
15149+#
15150+
15151+menu "Linux VServer"
15152+
15153+config VSERVER_AUTO_LBACK
15154+ bool "Automatically Assign Loopback IP"
15155+ default y
15156+ help
15157+ Automatically assign a guest specific loopback
15158+ IP and add it to the kernel network stack on
15159+ startup.
15160+
15161+config VSERVER_AUTO_SINGLE
15162+ bool "Automatic Single IP Special Casing"
15163+ depends on EXPERIMENTAL
15164+ default y
15165+ help
15166+ This allows network contexts with a single IP to
15167+ automatically remap 0.0.0.0 bindings to that IP,
15168+ avoiding further network checks and improving
15169+ performance.
15170+
15171+ (note: such guests do not allow to change the ip
15172+ on the fly and do not show loopback addresses)
15173+
15174+config VSERVER_COWBL
15175+ bool "Enable COW Immutable Link Breaking"
15176+ default y
15177+ help
15178+ This enables the COW (Copy-On-Write) link break code.
15179+ It allows you to treat unified files like normal files
15180+ when writing to them (which will implicitely break the
15181+ link and create a copy of the unified file)
15182+
15183+config VSERVER_VTIME
15184+ bool "Enable Virtualized Guest Time"
15185+ depends on EXPERIMENTAL
15186+ default n
15187+ help
15188+ This enables per guest time offsets to allow for
15189+ adjusting the system clock individually per guest.
15190+ this adds some overhead to the time functions and
15191+ therefore should not be enabled without good reason.
15192+
15193+config VSERVER_DEVICE
15194+ bool "Enable Guest Device Mapping"
15195+ depends on EXPERIMENTAL
15196+ default n
15197+ help
15198+ This enables generic device remapping.
15199+
15200+config VSERVER_PROC_SECURE
15201+ bool "Enable Proc Security"
15202+ depends on PROC_FS
15203+ default y
15204+ help
15205+ This configures ProcFS security to initially hide
15206+ non-process entries for all contexts except the main and
15207+ spectator context (i.e. for all guests), which is a secure
15208+ default.
15209+
15210+ (note: on 1.2x the entries were visible by default)
15211+
15212+choice
15213+ prompt "Persistent Inode Tagging"
15214+ default TAGGING_ID24
15215+ help
15216+ This adds persistent context information to filesystems
15217+ mounted with the tagxid option. Tagging is a requirement
15218+ for per-context disk limits and per-context quota.
15219+
15220+
15221+config TAGGING_NONE
15222+ bool "Disabled"
15223+ help
15224+ do not store per-context information in inodes.
15225+
15226+config TAGGING_UID16
15227+ bool "UID16/GID32"
15228+ help
15229+ reduces UID to 16 bit, but leaves GID at 32 bit.
15230+
15231+config TAGGING_GID16
15232+ bool "UID32/GID16"
15233+ help
15234+ reduces GID to 16 bit, but leaves UID at 32 bit.
15235+
15236+config TAGGING_ID24
15237+ bool "UID24/GID24"
15238+ help
15239+ uses the upper 8bit from UID and GID for XID tagging
15240+ which leaves 24bit for UID/GID each, which should be
15241+ more than sufficient for normal use.
15242+
15243+config TAGGING_INTERN
15244+ bool "UID32/GID32"
15245+ help
15246+ this uses otherwise reserved inode fields in the on
15247+ disk representation, which limits the use to a few
15248+ filesystems (currently ext2 and ext3)
15249+
15250+endchoice
15251+
15252+config TAG_NFSD
15253+ bool "Tag NFSD User Auth and Files"
15254+ default n
15255+ help
15256+ Enable this if you do want the in-kernel NFS
15257+ Server to use the tagging specified above.
15258+ (will require patched clients too)
15259+
15260+config VSERVER_PRIVACY
15261+ bool "Honor Privacy Aspects of Guests"
15262+ default n
15263+ help
15264+ When enabled, most context checks will disallow
15265+ access to structures assigned to a specific context,
15266+ like ptys or loop devices.
15267+
15268+config VSERVER_CONTEXTS
15269+ int "Maximum number of Contexts (1-65533)" if EMBEDDED
15270+ range 1 65533
15271+ default "768" if 64BIT
15272+ default "256"
15273+ help
15274+ This setting will optimize certain data structures
15275+ and memory allocations according to the expected
15276+ maximum.
15277+
15278+ note: this is not a strict upper limit.
15279+
15280+config VSERVER_WARN
15281+ bool "VServer Warnings"
15282+ default y
15283+ help
15284+ This enables various runtime warnings, which will
15285+ notify about potential manipulation attempts or
15286+ resource shortage. It is generally considered to
15287+ be a good idea to have that enabled.
15288+
15289+config VSERVER_WARN_DEVPTS
15290+ bool "VServer DevPTS Warnings"
15291+ depends on VSERVER_WARN
15292+ default y
15293+ help
15294+ This enables DevPTS related warnings, issued when a
15295+ process inside a context tries to lookup or access
15296+ a dynamic pts from the host or a different context.
15297+
15298+config VSERVER_DEBUG
15299+ bool "VServer Debugging Code"
15300+ default n
15301+ help
15302+ Set this to yes if you want to be able to activate
15303+ debugging output at runtime. It adds a very small
15304+ overhead to all vserver related functions and
15305+ increases the kernel size by about 20k.
15306+
15307+config VSERVER_HISTORY
15308+ bool "VServer History Tracing"
15309+ depends on VSERVER_DEBUG
15310+ default n
15311+ help
15312+ Set this to yes if you want to record the history of
15313+ linux-vserver activities, so they can be replayed in
15314+ the event of a kernel panic or oops.
15315+
15316+config VSERVER_HISTORY_SIZE
15317+ int "Per-CPU History Size (32-65536)"
15318+ depends on VSERVER_HISTORY
15319+ range 32 65536
15320+ default 64
15321+ help
15322+ This allows you to specify the number of entries in
15323+ the per-CPU history buffer.
15324+
15325+choice
15326+ prompt "Quotes used in debug and warn messages"
15327+ default QUOTES_ISO8859
15328+
15329+config QUOTES_ISO8859
15330+ bool "Extended ASCII (ISO 8859) angle quotes"
15331+ help
15332+ This uses the extended ASCII characters \xbb
15333+ and \xab for quoting file and process names.
15334+
15335+config QUOTES_UTF8
15336+ bool "UTF-8 angle quotes"
15337+ help
15338+ This uses the the UTF-8 sequences for angle
15339+ quotes to quote file and process names.
15340+
15341+config QUOTES_ASCII
15342+ bool "ASCII single quotes"
15343+ help
15344+ This uses the ASCII single quote character
15345+ (\x27) to quote file and process names.
15346+
15347+endchoice
15348+
15349+endmenu
15350+
15351+
15352+config VSERVER
15353+ bool
15354+ default y
15355+ select NAMESPACES
15356+ select UTS_NS
15357+ select IPC_NS
15358+# select USER_NS
15359+ select SYSVIPC
15360+
15361+config VSERVER_SECURITY
15362+ bool
15363+ depends on SECURITY
15364+ default y
15365+ select SECURITY_CAPABILITIES
15366+
15367+config VSERVER_DISABLED
15368+ bool
15369+ default n
15370+
15371diff -NurpP --minimal linux-3.6.6/kernel/vserver/Makefile linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/Makefile
15372--- linux-3.6.6/kernel/vserver/Makefile 1970-01-01 01:00:00.000000000 +0100
15373+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/Makefile 2012-10-04 18:47:00.000000000 +0200
15374@@ -0,0 +1,18 @@
15375+#
15376+# Makefile for the Linux vserver routines.
15377+#
15378+
15379+
15380+obj-y += vserver.o
15381+
15382+vserver-y := switch.o context.o space.o sched.o network.o inode.o \
15383+ limit.o cvirt.o cacct.o signal.o helper.o init.o \
15384+ dlimit.o tag.o
15385+
15386+vserver-$(CONFIG_INET) += inet.o
15387+vserver-$(CONFIG_PROC_FS) += proc.o
15388+vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15389+vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15390+vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15391+vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15392+
15393diff -NurpP --minimal linux-3.6.6/kernel/vserver/cacct.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cacct.c
15394--- linux-3.6.6/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
15395+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cacct.c 2012-10-04 18:47:00.000000000 +0200
15396@@ -0,0 +1,42 @@
15397+/*
15398+ * linux/kernel/vserver/cacct.c
15399+ *
15400+ * Virtual Server: Context Accounting
15401+ *
15402+ * Copyright (C) 2006-2007 Herbert Pötzl
15403+ *
15404+ * V0.01 added accounting stats
15405+ *
15406+ */
15407+
15408+#include <linux/types.h>
15409+#include <linux/vs_context.h>
15410+#include <linux/vserver/cacct_cmd.h>
15411+#include <linux/vserver/cacct_int.h>
15412+
15413+#include <asm/errno.h>
15414+#include <asm/uaccess.h>
15415+
15416+
15417+int vc_sock_stat(struct vx_info *vxi, void __user *data)
15418+{
15419+ struct vcmd_sock_stat_v0 vc_data;
15420+ int j, field;
15421+
15422+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15423+ return -EFAULT;
15424+
15425+ field = vc_data.field;
15426+ if ((field < 0) || (field >= VXA_SOCK_SIZE))
15427+ return -EINVAL;
15428+
15429+ for (j = 0; j < 3; j++) {
15430+ vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15431+ vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15432+ }
15433+
15434+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15435+ return -EFAULT;
15436+ return 0;
15437+}
15438+
15439diff -NurpP --minimal linux-3.6.6/kernel/vserver/cacct_init.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cacct_init.h
15440--- linux-3.6.6/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
15441+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cacct_init.h 2012-10-04 18:47:00.000000000 +0200
15442@@ -0,0 +1,25 @@
15443+
15444+
15445+static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15446+{
15447+ int i, j;
15448+
15449+
15450+ for (i = 0; i < VXA_SOCK_SIZE; i++) {
15451+ for (j = 0; j < 3; j++) {
15452+ atomic_long_set(&cacct->sock[i][j].count, 0);
15453+ atomic_long_set(&cacct->sock[i][j].total, 0);
15454+ }
15455+ }
15456+ for (i = 0; i < 8; i++)
15457+ atomic_set(&cacct->slab[i], 0);
15458+ for (i = 0; i < 5; i++)
15459+ for (j = 0; j < 4; j++)
15460+ atomic_set(&cacct->page[i][j], 0);
15461+}
15462+
15463+static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15464+{
15465+ return;
15466+}
15467+
15468diff -NurpP --minimal linux-3.6.6/kernel/vserver/cacct_proc.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cacct_proc.h
15469--- linux-3.6.6/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
15470+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cacct_proc.h 2012-10-04 18:47:00.000000000 +0200
15471@@ -0,0 +1,53 @@
15472+#ifndef _VX_CACCT_PROC_H
15473+#define _VX_CACCT_PROC_H
15474+
15475+#include <linux/vserver/cacct_int.h>
15476+
15477+
15478+#define VX_SOCKA_TOP \
15479+ "Type\t recv #/bytes\t\t send #/bytes\t\t fail #/bytes\n"
15480+
15481+static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15482+{
15483+ int i, j, length = 0;
15484+ static char *type[VXA_SOCK_SIZE] = {
15485+ "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15486+ };
15487+
15488+ length += sprintf(buffer + length, VX_SOCKA_TOP);
15489+ for (i = 0; i < VXA_SOCK_SIZE; i++) {
15490+ length += sprintf(buffer + length, "%s:", type[i]);
15491+ for (j = 0; j < 3; j++) {
15492+ length += sprintf(buffer + length,
15493+ "\t%10lu/%-10lu",
15494+ vx_sock_count(cacct, i, j),
15495+ vx_sock_total(cacct, i, j));
15496+ }
15497+ buffer[length++] = '\n';
15498+ }
15499+
15500+ length += sprintf(buffer + length, "\n");
15501+ length += sprintf(buffer + length,
15502+ "slab:\t %8u %8u %8u %8u\n",
15503+ atomic_read(&cacct->slab[1]),
15504+ atomic_read(&cacct->slab[4]),
15505+ atomic_read(&cacct->slab[0]),
15506+ atomic_read(&cacct->slab[2]));
15507+
15508+ length += sprintf(buffer + length, "\n");
15509+ for (i = 0; i < 5; i++) {
15510+ length += sprintf(buffer + length,
15511+ "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15512+ atomic_read(&cacct->page[i][0]),
15513+ atomic_read(&cacct->page[i][1]),
15514+ atomic_read(&cacct->page[i][2]),
15515+ atomic_read(&cacct->page[i][3]),
15516+ atomic_read(&cacct->page[i][4]),
15517+ atomic_read(&cacct->page[i][5]),
15518+ atomic_read(&cacct->page[i][6]),
15519+ atomic_read(&cacct->page[i][7]));
15520+ }
15521+ return length;
15522+}
15523+
15524+#endif /* _VX_CACCT_PROC_H */
15525diff -NurpP --minimal linux-3.6.6/kernel/vserver/context.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/context.c
15526--- linux-3.6.6/kernel/vserver/context.c 1970-01-01 01:00:00.000000000 +0100
15527+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/context.c 2012-10-04 18:47:00.000000000 +0200
15528@@ -0,0 +1,1119 @@
15529+/*
15530+ * linux/kernel/vserver/context.c
15531+ *
15532+ * Virtual Server: Context Support
15533+ *
15534+ * Copyright (C) 2003-2011 Herbert Pötzl
15535+ *
15536+ * V0.01 context helper
15537+ * V0.02 vx_ctx_kill syscall command
15538+ * V0.03 replaced context_info calls
15539+ * V0.04 redesign of struct (de)alloc
15540+ * V0.05 rlimit basic implementation
15541+ * V0.06 task_xid and info commands
15542+ * V0.07 context flags and caps
15543+ * V0.08 switch to RCU based hash
15544+ * V0.09 revert to non RCU for now
15545+ * V0.10 and back to working RCU hash
15546+ * V0.11 and back to locking again
15547+ * V0.12 referenced context store
15548+ * V0.13 separate per cpu data
15549+ * V0.14 changed vcmds to vxi arg
15550+ * V0.15 added context stat
15551+ * V0.16 have __create claim() the vxi
15552+ * V0.17 removed older and legacy stuff
15553+ * V0.18 added user credentials
15554+ * V0.19 added warn mask
15555+ *
15556+ */
15557+
15558+#include <linux/slab.h>
15559+#include <linux/types.h>
15560+#include <linux/security.h>
15561+#include <linux/pid_namespace.h>
15562+#include <linux/capability.h>
15563+
15564+#include <linux/vserver/context.h>
15565+#include <linux/vserver/network.h>
15566+#include <linux/vserver/debug.h>
15567+#include <linux/vserver/limit.h>
15568+#include <linux/vserver/limit_int.h>
15569+#include <linux/vserver/space.h>
15570+#include <linux/init_task.h>
15571+#include <linux/fs_struct.h>
15572+#include <linux/cred.h>
15573+
15574+#include <linux/vs_context.h>
15575+#include <linux/vs_limit.h>
15576+#include <linux/vs_pid.h>
15577+#include <linux/vserver/context_cmd.h>
15578+
15579+#include "cvirt_init.h"
15580+#include "cacct_init.h"
15581+#include "limit_init.h"
15582+#include "sched_init.h"
15583+
15584+
15585+atomic_t vx_global_ctotal = ATOMIC_INIT(0);
15586+atomic_t vx_global_cactive = ATOMIC_INIT(0);
15587+
15588+
15589+/* now inactive context structures */
15590+
15591+static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15592+
15593+static DEFINE_SPINLOCK(vx_info_inactive_lock);
15594+
15595+
15596+/* __alloc_vx_info()
15597+
15598+ * allocate an initialized vx_info struct
15599+ * doesn't make it visible (hash) */
15600+
15601+static struct vx_info *__alloc_vx_info(xid_t xid)
15602+{
15603+ struct vx_info *new = NULL;
15604+ int cpu, index;
15605+
15606+ vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15607+
15608+ /* would this benefit from a slab cache? */
15609+ new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15610+ if (!new)
15611+ return 0;
15612+
15613+ memset(new, 0, sizeof(struct vx_info));
15614+#ifdef CONFIG_SMP
15615+ new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15616+ if (!new->ptr_pc)
15617+ goto error;
15618+#endif
15619+ new->vx_id = xid;
15620+ INIT_HLIST_NODE(&new->vx_hlist);
15621+ atomic_set(&new->vx_usecnt, 0);
15622+ atomic_set(&new->vx_tasks, 0);
15623+ new->vx_parent = NULL;
15624+ new->vx_state = 0;
15625+ init_waitqueue_head(&new->vx_wait);
15626+
15627+ /* prepare reaper */
15628+ get_task_struct(init_pid_ns.child_reaper);
15629+ new->vx_reaper = init_pid_ns.child_reaper;
15630+ new->vx_badness_bias = 0;
15631+
15632+ /* rest of init goes here */
15633+ vx_info_init_limit(&new->limit);
15634+ vx_info_init_sched(&new->sched);
15635+ vx_info_init_cvirt(&new->cvirt);
15636+ vx_info_init_cacct(&new->cacct);
15637+
15638+ /* per cpu data structures */
15639+ for_each_possible_cpu(cpu) {
15640+ vx_info_init_sched_pc(
15641+ &vx_per_cpu(new, sched_pc, cpu), cpu);
15642+ vx_info_init_cvirt_pc(
15643+ &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15644+ }
15645+
15646+ new->vx_flags = VXF_INIT_SET;
15647+ new->vx_bcaps = CAP_FULL_SET; // maybe ~CAP_SETPCAP
15648+ new->vx_ccaps = 0;
15649+ new->vx_umask = 0;
15650+ new->vx_wmask = 0;
15651+
15652+ new->reboot_cmd = 0;
15653+ new->exit_code = 0;
15654+
15655+ // preconfig spaces
15656+ for (index = 0; index < VX_SPACES; index++) {
15657+ struct _vx_space *space = &new->space[index];
15658+
15659+ // filesystem
15660+ spin_lock(&init_fs.lock);
15661+ init_fs.users++;
15662+ spin_unlock(&init_fs.lock);
15663+ space->vx_fs = &init_fs;
15664+
15665+ /* FIXME: do we want defaults? */
15666+ // space->vx_real_cred = 0;
15667+ // space->vx_cred = 0;
15668+ }
15669+
15670+
15671+ vxdprintk(VXD_CBIT(xid, 0),
15672+ "alloc_vx_info(%d) = %p", xid, new);
15673+ vxh_alloc_vx_info(new);
15674+ atomic_inc(&vx_global_ctotal);
15675+ return new;
15676+#ifdef CONFIG_SMP
15677+error:
15678+ kfree(new);
15679+ return 0;
15680+#endif
15681+}
15682+
15683+/* __dealloc_vx_info()
15684+
15685+ * final disposal of vx_info */
15686+
15687+static void __dealloc_vx_info(struct vx_info *vxi)
15688+{
15689+#ifdef CONFIG_VSERVER_WARN
15690+ struct vx_info_save vxis;
15691+ int cpu;
15692+#endif
15693+ vxdprintk(VXD_CBIT(xid, 0),
15694+ "dealloc_vx_info(%p)", vxi);
15695+ vxh_dealloc_vx_info(vxi);
15696+
15697+#ifdef CONFIG_VSERVER_WARN
15698+ enter_vx_info(vxi, &vxis);
15699+ vx_info_exit_limit(&vxi->limit);
15700+ vx_info_exit_sched(&vxi->sched);
15701+ vx_info_exit_cvirt(&vxi->cvirt);
15702+ vx_info_exit_cacct(&vxi->cacct);
15703+
15704+ for_each_possible_cpu(cpu) {
15705+ vx_info_exit_sched_pc(
15706+ &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15707+ vx_info_exit_cvirt_pc(
15708+ &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15709+ }
15710+ leave_vx_info(&vxis);
15711+#endif
15712+
15713+ vxi->vx_id = -1;
15714+ vxi->vx_state |= VXS_RELEASED;
15715+
15716+#ifdef CONFIG_SMP
15717+ free_percpu(vxi->ptr_pc);
15718+#endif
15719+ kfree(vxi);
15720+ atomic_dec(&vx_global_ctotal);
15721+}
15722+
15723+static void __shutdown_vx_info(struct vx_info *vxi)
15724+{
15725+ struct nsproxy *nsproxy;
15726+ struct fs_struct *fs;
15727+ struct cred *cred;
15728+ int index, kill;
15729+
15730+ might_sleep();
15731+
15732+ vxi->vx_state |= VXS_SHUTDOWN;
15733+ vs_state_change(vxi, VSC_SHUTDOWN);
15734+
15735+ for (index = 0; index < VX_SPACES; index++) {
15736+ struct _vx_space *space = &vxi->space[index];
15737+
15738+ nsproxy = xchg(&space->vx_nsproxy, NULL);
15739+ if (nsproxy)
15740+ put_nsproxy(nsproxy);
15741+
15742+ fs = xchg(&space->vx_fs, NULL);
15743+ spin_lock(&fs->lock);
15744+ kill = !--fs->users;
15745+ spin_unlock(&fs->lock);
15746+ if (kill)
15747+ free_fs_struct(fs);
15748+
15749+ cred = (struct cred *)xchg(&space->vx_cred, NULL);
15750+ if (cred)
15751+ abort_creds(cred);
15752+ }
15753+}
15754+
15755+/* exported stuff */
15756+
15757+void free_vx_info(struct vx_info *vxi)
15758+{
15759+ unsigned long flags;
15760+ unsigned index;
15761+
15762+ /* check for reference counts first */
15763+ BUG_ON(atomic_read(&vxi->vx_usecnt));
15764+ BUG_ON(atomic_read(&vxi->vx_tasks));
15765+
15766+ /* context must not be hashed */
15767+ BUG_ON(vx_info_state(vxi, VXS_HASHED));
15768+
15769+ /* context shutdown is mandatory */
15770+ BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15771+
15772+ /* spaces check */
15773+ for (index = 0; index < VX_SPACES; index++) {
15774+ struct _vx_space *space = &vxi->space[index];
15775+
15776+ BUG_ON(space->vx_nsproxy);
15777+ BUG_ON(space->vx_fs);
15778+ // BUG_ON(space->vx_real_cred);
15779+ // BUG_ON(space->vx_cred);
15780+ }
15781+
15782+ spin_lock_irqsave(&vx_info_inactive_lock, flags);
15783+ hlist_del(&vxi->vx_hlist);
15784+ spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15785+
15786+ __dealloc_vx_info(vxi);
15787+}
15788+
15789+
15790+/* hash table for vx_info hash */
15791+
15792+#define VX_HASH_SIZE 13
15793+
15794+static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15795+ { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15796+
15797+static DEFINE_SPINLOCK(vx_info_hash_lock);
15798+
15799+
15800+static inline unsigned int __hashval(xid_t xid)
15801+{
15802+ return (xid % VX_HASH_SIZE);
15803+}
15804+
15805+
15806+
15807+/* __hash_vx_info()
15808+
15809+ * add the vxi to the global hash table
15810+ * requires the hash_lock to be held */
15811+
15812+static inline void __hash_vx_info(struct vx_info *vxi)
15813+{
15814+ struct hlist_head *head;
15815+
15816+ vxd_assert_lock(&vx_info_hash_lock);
15817+ vxdprintk(VXD_CBIT(xid, 4),
15818+ "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15819+ vxh_hash_vx_info(vxi);
15820+
15821+ /* context must not be hashed */
15822+ BUG_ON(vx_info_state(vxi, VXS_HASHED));
15823+
15824+ vxi->vx_state |= VXS_HASHED;
15825+ head = &vx_info_hash[__hashval(vxi->vx_id)];
15826+ hlist_add_head(&vxi->vx_hlist, head);
15827+ atomic_inc(&vx_global_cactive);
15828+}
15829+
15830+/* __unhash_vx_info()
15831+
15832+ * remove the vxi from the global hash table
15833+ * requires the hash_lock to be held */
15834+
15835+static inline void __unhash_vx_info(struct vx_info *vxi)
15836+{
15837+ unsigned long flags;
15838+
15839+ vxd_assert_lock(&vx_info_hash_lock);
15840+ vxdprintk(VXD_CBIT(xid, 4),
15841+ "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15842+ atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15843+ vxh_unhash_vx_info(vxi);
15844+
15845+ /* context must be hashed */
15846+ BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15847+ /* but without tasks */
15848+ BUG_ON(atomic_read(&vxi->vx_tasks));
15849+
15850+ vxi->vx_state &= ~VXS_HASHED;
15851+ hlist_del_init(&vxi->vx_hlist);
15852+ spin_lock_irqsave(&vx_info_inactive_lock, flags);
15853+ hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15854+ spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15855+ atomic_dec(&vx_global_cactive);
15856+}
15857+
15858+
15859+/* __lookup_vx_info()
15860+
15861+ * requires the hash_lock to be held
15862+ * doesn't increment the vx_refcnt */
15863+
15864+static inline struct vx_info *__lookup_vx_info(xid_t xid)
15865+{
15866+ struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15867+ struct hlist_node *pos;
15868+ struct vx_info *vxi;
15869+
15870+ vxd_assert_lock(&vx_info_hash_lock);
15871+ hlist_for_each(pos, head) {
15872+ vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15873+
15874+ if (vxi->vx_id == xid)
15875+ goto found;
15876+ }
15877+ vxi = NULL;
15878+found:
15879+ vxdprintk(VXD_CBIT(xid, 0),
15880+ "__lookup_vx_info(#%u): %p[#%u]",
15881+ xid, vxi, vxi ? vxi->vx_id : 0);
15882+ vxh_lookup_vx_info(vxi, xid);
15883+ return vxi;
15884+}
15885+
15886+
15887+/* __create_vx_info()
15888+
15889+ * create the requested context
15890+ * get(), claim() and hash it */
15891+
15892+static struct vx_info *__create_vx_info(int id)
15893+{
15894+ struct vx_info *new, *vxi = NULL;
15895+
15896+ vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15897+
15898+ if (!(new = __alloc_vx_info(id)))
15899+ return ERR_PTR(-ENOMEM);
15900+
15901+ /* required to make dynamic xids unique */
15902+ spin_lock(&vx_info_hash_lock);
15903+
15904+ /* static context requested */
15905+ if ((vxi = __lookup_vx_info(id))) {
15906+ vxdprintk(VXD_CBIT(xid, 0),
15907+ "create_vx_info(%d) = %p (already there)", id, vxi);
15908+ if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15909+ vxi = ERR_PTR(-EBUSY);
15910+ else
15911+ vxi = ERR_PTR(-EEXIST);
15912+ goto out_unlock;
15913+ }
15914+ /* new context */
15915+ vxdprintk(VXD_CBIT(xid, 0),
15916+ "create_vx_info(%d) = %p (new)", id, new);
15917+ claim_vx_info(new, NULL);
15918+ __hash_vx_info(get_vx_info(new));
15919+ vxi = new, new = NULL;
15920+
15921+out_unlock:
15922+ spin_unlock(&vx_info_hash_lock);
15923+ vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15924+ if (new)
15925+ __dealloc_vx_info(new);
15926+ return vxi;
15927+}
15928+
15929+
15930+/* exported stuff */
15931+
15932+
15933+void unhash_vx_info(struct vx_info *vxi)
15934+{
15935+ spin_lock(&vx_info_hash_lock);
15936+ __unhash_vx_info(vxi);
15937+ spin_unlock(&vx_info_hash_lock);
15938+ __shutdown_vx_info(vxi);
15939+ __wakeup_vx_info(vxi);
15940+}
15941+
15942+
15943+/* lookup_vx_info()
15944+
15945+ * search for a vx_info and get() it
15946+ * negative id means current */
15947+
15948+struct vx_info *lookup_vx_info(int id)
15949+{
15950+ struct vx_info *vxi = NULL;
15951+
15952+ if (id < 0) {
15953+ vxi = get_vx_info(current_vx_info());
15954+ } else if (id > 1) {
15955+ spin_lock(&vx_info_hash_lock);
15956+ vxi = get_vx_info(__lookup_vx_info(id));
15957+ spin_unlock(&vx_info_hash_lock);
15958+ }
15959+ return vxi;
15960+}
15961+
15962+/* xid_is_hashed()
15963+
15964+ * verify that xid is still hashed */
15965+
15966+int xid_is_hashed(xid_t xid)
15967+{
15968+ int hashed;
15969+
15970+ spin_lock(&vx_info_hash_lock);
15971+ hashed = (__lookup_vx_info(xid) != NULL);
15972+ spin_unlock(&vx_info_hash_lock);
15973+ return hashed;
15974+}
15975+
15976+#ifdef CONFIG_PROC_FS
15977+
15978+/* get_xid_list()
15979+
15980+ * get a subset of hashed xids for proc
15981+ * assumes size is at least one */
15982+
15983+int get_xid_list(int index, unsigned int *xids, int size)
15984+{
15985+ int hindex, nr_xids = 0;
15986+
15987+ /* only show current and children */
15988+ if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15989+ if (index > 0)
15990+ return 0;
15991+ xids[nr_xids] = vx_current_xid();
15992+ return 1;
15993+ }
15994+
15995+ for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15996+ struct hlist_head *head = &vx_info_hash[hindex];
15997+ struct hlist_node *pos;
15998+
15999+ spin_lock(&vx_info_hash_lock);
16000+ hlist_for_each(pos, head) {
16001+ struct vx_info *vxi;
16002+
16003+ if (--index > 0)
16004+ continue;
16005+
16006+ vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16007+ xids[nr_xids] = vxi->vx_id;
16008+ if (++nr_xids >= size) {
16009+ spin_unlock(&vx_info_hash_lock);
16010+ goto out;
16011+ }
16012+ }
16013+ /* keep the lock time short */
16014+ spin_unlock(&vx_info_hash_lock);
16015+ }
16016+out:
16017+ return nr_xids;
16018+}
16019+#endif
16020+
16021+#ifdef CONFIG_VSERVER_DEBUG
16022+
16023+void dump_vx_info_inactive(int level)
16024+{
16025+ struct hlist_node *entry, *next;
16026+
16027+ hlist_for_each_safe(entry, next, &vx_info_inactive) {
16028+ struct vx_info *vxi =
16029+ list_entry(entry, struct vx_info, vx_hlist);
16030+
16031+ dump_vx_info(vxi, level);
16032+ }
16033+}
16034+
16035+#endif
16036+
16037+#if 0
16038+int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16039+{
16040+ struct user_struct *new_user, *old_user;
16041+
16042+ if (!p || !vxi)
16043+ BUG();
16044+
16045+ if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16046+ return -EACCES;
16047+
16048+ new_user = alloc_uid(vxi->vx_id, p->uid);
16049+ if (!new_user)
16050+ return -ENOMEM;
16051+
16052+ old_user = p->user;
16053+ if (new_user != old_user) {
16054+ atomic_inc(&new_user->processes);
16055+ atomic_dec(&old_user->processes);
16056+ p->user = new_user;
16057+ }
16058+ free_uid(old_user);
16059+ return 0;
16060+}
16061+#endif
16062+
16063+#if 0
16064+void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16065+{
16066+ // p->cap_effective &= vxi->vx_cap_bset;
16067+ p->cap_effective =
16068+ cap_intersect(p->cap_effective, vxi->cap_bset);
16069+ // p->cap_inheritable &= vxi->vx_cap_bset;
16070+ p->cap_inheritable =
16071+ cap_intersect(p->cap_inheritable, vxi->cap_bset);
16072+ // p->cap_permitted &= vxi->vx_cap_bset;
16073+ p->cap_permitted =
16074+ cap_intersect(p->cap_permitted, vxi->cap_bset);
16075+}
16076+#endif
16077+
16078+
16079+#include <linux/file.h>
16080+#include <linux/fdtable.h>
16081+
16082+static int vx_openfd_task(struct task_struct *tsk)
16083+{
16084+ struct files_struct *files = tsk->files;
16085+ struct fdtable *fdt;
16086+ const unsigned long *bptr;
16087+ int count, total;
16088+
16089+ /* no rcu_read_lock() because of spin_lock() */
16090+ spin_lock(&files->file_lock);
16091+ fdt = files_fdtable(files);
16092+ bptr = fdt->open_fds;
16093+ count = fdt->max_fds / (sizeof(unsigned long) * 8);
16094+ for (total = 0; count > 0; count--) {
16095+ if (*bptr)
16096+ total += hweight_long(*bptr);
16097+ bptr++;
16098+ }
16099+ spin_unlock(&files->file_lock);
16100+ return total;
16101+}
16102+
16103+
16104+/* for *space compatibility */
16105+
16106+asmlinkage long sys_unshare(unsigned long);
16107+
16108+/*
16109+ * migrate task to new context
16110+ * gets vxi, puts old_vxi on change
16111+ * optionally unshares namespaces (hack)
16112+ */
16113+
16114+int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16115+{
16116+ struct vx_info *old_vxi;
16117+ int ret = 0;
16118+
16119+ if (!p || !vxi)
16120+ BUG();
16121+
16122+ vxdprintk(VXD_CBIT(xid, 5),
16123+ "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16124+ vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16125+
16126+ if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16127+ !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16128+ return -EACCES;
16129+
16130+ if (vx_info_state(vxi, VXS_SHUTDOWN))
16131+ return -EFAULT;
16132+
16133+ old_vxi = task_get_vx_info(p);
16134+ if (old_vxi == vxi)
16135+ goto out;
16136+
16137+// if (!(ret = vx_migrate_user(p, vxi))) {
16138+ {
16139+ int openfd;
16140+
16141+ task_lock(p);
16142+ openfd = vx_openfd_task(p);
16143+
16144+ if (old_vxi) {
16145+ atomic_dec(&old_vxi->cvirt.nr_threads);
16146+ atomic_dec(&old_vxi->cvirt.nr_running);
16147+ __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16148+ /* FIXME: what about the struct files here? */
16149+ __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16150+ /* account for the executable */
16151+ __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16152+ }
16153+ atomic_inc(&vxi->cvirt.nr_threads);
16154+ atomic_inc(&vxi->cvirt.nr_running);
16155+ __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16156+ /* FIXME: what about the struct files here? */
16157+ __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16158+ /* account for the executable */
16159+ __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16160+
16161+ if (old_vxi) {
16162+ release_vx_info(old_vxi, p);
16163+ clr_vx_info(&p->vx_info);
16164+ }
16165+ claim_vx_info(vxi, p);
16166+ set_vx_info(&p->vx_info, vxi);
16167+ p->xid = vxi->vx_id;
16168+
16169+ vxdprintk(VXD_CBIT(xid, 5),
16170+ "moved task %p into vxi:%p[#%d]",
16171+ p, vxi, vxi->vx_id);
16172+
16173+ // vx_mask_cap_bset(vxi, p);
16174+ task_unlock(p);
16175+
16176+ /* hack for *spaces to provide compatibility */
16177+ if (unshare) {
16178+ struct nsproxy *old_nsp, *new_nsp;
16179+
16180+ ret = unshare_nsproxy_namespaces(
16181+ CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16182+ &new_nsp, NULL);
16183+ if (ret)
16184+ goto out;
16185+
16186+ old_nsp = xchg(&p->nsproxy, new_nsp);
16187+ vx_set_space(vxi,
16188+ CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16189+ put_nsproxy(old_nsp);
16190+ }
16191+ }
16192+out:
16193+ put_vx_info(old_vxi);
16194+ return ret;
16195+}
16196+
16197+int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16198+{
16199+ struct task_struct *old_reaper;
16200+ struct vx_info *reaper_vxi;
16201+
16202+ if (!vxi)
16203+ return -EINVAL;
16204+
16205+ vxdprintk(VXD_CBIT(xid, 6),
16206+ "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16207+ vxi, vxi->vx_id, p, p->xid, p->pid);
16208+
16209+ old_reaper = vxi->vx_reaper;
16210+ if (old_reaper == p)
16211+ return 0;
16212+
16213+ reaper_vxi = task_get_vx_info(p);
16214+ if (reaper_vxi && reaper_vxi != vxi) {
16215+ vxwprintk(1,
16216+ "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16217+ "for [xid #%u]",
16218+ p->comm, p->pid, p->xid, vx_current_xid());
16219+ goto out;
16220+ }
16221+
16222+ /* set new child reaper */
16223+ get_task_struct(p);
16224+ vxi->vx_reaper = p;
16225+ put_task_struct(old_reaper);
16226+out:
16227+ put_vx_info(reaper_vxi);
16228+ return 0;
16229+}
16230+
16231+int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16232+{
16233+ if (!vxi)
16234+ return -EINVAL;
16235+
16236+ vxdprintk(VXD_CBIT(xid, 6),
16237+ "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16238+ vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16239+
16240+ vxi->vx_flags &= ~VXF_STATE_INIT;
16241+ // vxi->vx_initpid = p->tgid;
16242+ vxi->vx_initpid = p->pid;
16243+ return 0;
16244+}
16245+
16246+void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16247+{
16248+ vxdprintk(VXD_CBIT(xid, 6),
16249+ "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16250+ vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16251+
16252+ vxi->exit_code = code;
16253+ vxi->vx_initpid = 0;
16254+}
16255+
16256+
16257+void vx_set_persistent(struct vx_info *vxi)
16258+{
16259+ vxdprintk(VXD_CBIT(xid, 6),
16260+ "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16261+
16262+ get_vx_info(vxi);
16263+ claim_vx_info(vxi, NULL);
16264+}
16265+
16266+void vx_clear_persistent(struct vx_info *vxi)
16267+{
16268+ vxdprintk(VXD_CBIT(xid, 6),
16269+ "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16270+
16271+ release_vx_info(vxi, NULL);
16272+ put_vx_info(vxi);
16273+}
16274+
16275+void vx_update_persistent(struct vx_info *vxi)
16276+{
16277+ if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16278+ vx_set_persistent(vxi);
16279+ else
16280+ vx_clear_persistent(vxi);
16281+}
16282+
16283+
16284+/* task must be current or locked */
16285+
16286+void exit_vx_info(struct task_struct *p, int code)
16287+{
16288+ struct vx_info *vxi = p->vx_info;
16289+
16290+ if (vxi) {
16291+ atomic_dec(&vxi->cvirt.nr_threads);
16292+ vx_nproc_dec(p);
16293+
16294+ vxi->exit_code = code;
16295+ release_vx_info(vxi, p);
16296+ }
16297+}
16298+
16299+void exit_vx_info_early(struct task_struct *p, int code)
16300+{
16301+ struct vx_info *vxi = p->vx_info;
16302+
16303+ if (vxi) {
16304+ if (vxi->vx_initpid == p->pid)
16305+ vx_exit_init(vxi, p, code);
16306+ if (vxi->vx_reaper == p)
16307+ vx_set_reaper(vxi, init_pid_ns.child_reaper);
16308+ }
16309+}
16310+
16311+
16312+/* vserver syscall commands below here */
16313+
16314+/* taks xid and vx_info functions */
16315+
16316+#include <asm/uaccess.h>
16317+
16318+
16319+int vc_task_xid(uint32_t id)
16320+{
16321+ xid_t xid;
16322+
16323+ if (id) {
16324+ struct task_struct *tsk;
16325+
16326+ rcu_read_lock();
16327+ tsk = find_task_by_real_pid(id);
16328+ xid = (tsk) ? tsk->xid : -ESRCH;
16329+ rcu_read_unlock();
16330+ } else
16331+ xid = vx_current_xid();
16332+ return xid;
16333+}
16334+
16335+
16336+int vc_vx_info(struct vx_info *vxi, void __user *data)
16337+{
16338+ struct vcmd_vx_info_v0 vc_data;
16339+
16340+ vc_data.xid = vxi->vx_id;
16341+ vc_data.initpid = vxi->vx_initpid;
16342+
16343+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16344+ return -EFAULT;
16345+ return 0;
16346+}
16347+
16348+
16349+int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16350+{
16351+ struct vcmd_ctx_stat_v0 vc_data;
16352+
16353+ vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16354+ vc_data.tasks = atomic_read(&vxi->vx_tasks);
16355+
16356+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16357+ return -EFAULT;
16358+ return 0;
16359+}
16360+
16361+
16362+/* context functions */
16363+
16364+int vc_ctx_create(uint32_t xid, void __user *data)
16365+{
16366+ struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16367+ struct vx_info *new_vxi;
16368+ int ret;
16369+
16370+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16371+ return -EFAULT;
16372+
16373+ if ((xid > MAX_S_CONTEXT) || (xid < 2))
16374+ return -EINVAL;
16375+
16376+ new_vxi = __create_vx_info(xid);
16377+ if (IS_ERR(new_vxi))
16378+ return PTR_ERR(new_vxi);
16379+
16380+ /* initial flags */
16381+ new_vxi->vx_flags = vc_data.flagword;
16382+
16383+ ret = -ENOEXEC;
16384+ if (vs_state_change(new_vxi, VSC_STARTUP))
16385+ goto out;
16386+
16387+ ret = vx_migrate_task(current, new_vxi, (!data));
16388+ if (ret)
16389+ goto out;
16390+
16391+ /* return context id on success */
16392+ ret = new_vxi->vx_id;
16393+
16394+ /* get a reference for persistent contexts */
16395+ if ((vc_data.flagword & VXF_PERSISTENT))
16396+ vx_set_persistent(new_vxi);
16397+out:
16398+ release_vx_info(new_vxi, NULL);
16399+ put_vx_info(new_vxi);
16400+ return ret;
16401+}
16402+
16403+
16404+int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16405+{
16406+ struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16407+ int ret;
16408+
16409+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16410+ return -EFAULT;
16411+
16412+ ret = vx_migrate_task(current, vxi, 0);
16413+ if (ret)
16414+ return ret;
16415+ if (vc_data.flagword & VXM_SET_INIT)
16416+ ret = vx_set_init(vxi, current);
16417+ if (ret)
16418+ return ret;
16419+ if (vc_data.flagword & VXM_SET_REAPER)
16420+ ret = vx_set_reaper(vxi, current);
16421+ return ret;
16422+}
16423+
16424+
16425+int vc_get_cflags(struct vx_info *vxi, void __user *data)
16426+{
16427+ struct vcmd_ctx_flags_v0 vc_data;
16428+
16429+ vc_data.flagword = vxi->vx_flags;
16430+
16431+ /* special STATE flag handling */
16432+ vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16433+
16434+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16435+ return -EFAULT;
16436+ return 0;
16437+}
16438+
16439+int vc_set_cflags(struct vx_info *vxi, void __user *data)
16440+{
16441+ struct vcmd_ctx_flags_v0 vc_data;
16442+ uint64_t mask, trigger;
16443+
16444+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16445+ return -EFAULT;
16446+
16447+ /* special STATE flag handling */
16448+ mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16449+ trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16450+
16451+ if (vxi == current_vx_info()) {
16452+ /* if (trigger & VXF_STATE_SETUP)
16453+ vx_mask_cap_bset(vxi, current); */
16454+ if (trigger & VXF_STATE_INIT) {
16455+ int ret;
16456+
16457+ ret = vx_set_init(vxi, current);
16458+ if (ret)
16459+ return ret;
16460+ ret = vx_set_reaper(vxi, current);
16461+ if (ret)
16462+ return ret;
16463+ }
16464+ }
16465+
16466+ vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16467+ vc_data.flagword, mask);
16468+ if (trigger & VXF_PERSISTENT)
16469+ vx_update_persistent(vxi);
16470+
16471+ return 0;
16472+}
16473+
16474+
16475+static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16476+{
16477+ uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16478+
16479+ // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16480+ return v;
16481+}
16482+
16483+static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16484+{
16485+ kernel_cap_t c = __cap_empty_set;
16486+
16487+ c.cap[0] = v & 0xFFFFFFFF;
16488+ c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16489+
16490+ // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16491+ return c;
16492+}
16493+
16494+
16495+static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16496+{
16497+ if (bcaps)
16498+ *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16499+ if (ccaps)
16500+ *ccaps = vxi->vx_ccaps;
16501+
16502+ return 0;
16503+}
16504+
16505+int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16506+{
16507+ struct vcmd_ctx_caps_v1 vc_data;
16508+ int ret;
16509+
16510+ ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16511+ if (ret)
16512+ return ret;
16513+ vc_data.cmask = ~0ULL;
16514+
16515+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16516+ return -EFAULT;
16517+ return 0;
16518+}
16519+
16520+static int do_set_caps(struct vx_info *vxi,
16521+ uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16522+{
16523+ uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16524+
16525+#if 0
16526+ printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16527+ bcaps, bmask, ccaps, cmask);
16528+#endif
16529+ vxi->vx_bcaps = cap_t_from_caps(
16530+ vs_mask_flags(bcold, bcaps, bmask));
16531+ vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16532+
16533+ return 0;
16534+}
16535+
16536+int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16537+{
16538+ struct vcmd_ctx_caps_v1 vc_data;
16539+
16540+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16541+ return -EFAULT;
16542+
16543+ return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16544+}
16545+
16546+int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16547+{
16548+ struct vcmd_bcaps vc_data;
16549+ int ret;
16550+
16551+ ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16552+ if (ret)
16553+ return ret;
16554+ vc_data.bmask = ~0ULL;
16555+
16556+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16557+ return -EFAULT;
16558+ return 0;
16559+}
16560+
16561+int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16562+{
16563+ struct vcmd_bcaps vc_data;
16564+
16565+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16566+ return -EFAULT;
16567+
16568+ return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16569+}
16570+
16571+
16572+int vc_get_umask(struct vx_info *vxi, void __user *data)
16573+{
16574+ struct vcmd_umask vc_data;
16575+
16576+ vc_data.umask = vxi->vx_umask;
16577+ vc_data.mask = ~0ULL;
16578+
16579+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16580+ return -EFAULT;
16581+ return 0;
16582+}
16583+
16584+int vc_set_umask(struct vx_info *vxi, void __user *data)
16585+{
16586+ struct vcmd_umask vc_data;
16587+
16588+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16589+ return -EFAULT;
16590+
16591+ vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16592+ vc_data.umask, vc_data.mask);
16593+ return 0;
16594+}
16595+
16596+
16597+int vc_get_wmask(struct vx_info *vxi, void __user *data)
16598+{
16599+ struct vcmd_wmask vc_data;
16600+
16601+ vc_data.wmask = vxi->vx_wmask;
16602+ vc_data.mask = ~0ULL;
16603+
16604+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16605+ return -EFAULT;
16606+ return 0;
16607+}
16608+
16609+int vc_set_wmask(struct vx_info *vxi, void __user *data)
16610+{
16611+ struct vcmd_wmask vc_data;
16612+
16613+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16614+ return -EFAULT;
16615+
16616+ vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16617+ vc_data.wmask, vc_data.mask);
16618+ return 0;
16619+}
16620+
16621+
16622+int vc_get_badness(struct vx_info *vxi, void __user *data)
16623+{
16624+ struct vcmd_badness_v0 vc_data;
16625+
16626+ vc_data.bias = vxi->vx_badness_bias;
16627+
16628+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16629+ return -EFAULT;
16630+ return 0;
16631+}
16632+
16633+int vc_set_badness(struct vx_info *vxi, void __user *data)
16634+{
16635+ struct vcmd_badness_v0 vc_data;
16636+
16637+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16638+ return -EFAULT;
16639+
16640+ vxi->vx_badness_bias = vc_data.bias;
16641+ return 0;
16642+}
16643+
16644+#include <linux/module.h>
16645+
16646+EXPORT_SYMBOL_GPL(free_vx_info);
16647+
16648diff -NurpP --minimal linux-3.6.6/kernel/vserver/cvirt.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cvirt.c
16649--- linux-3.6.6/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
16650+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cvirt.c 2012-10-04 18:47:00.000000000 +0200
16651@@ -0,0 +1,313 @@
16652+/*
16653+ * linux/kernel/vserver/cvirt.c
16654+ *
16655+ * Virtual Server: Context Virtualization
16656+ *
16657+ * Copyright (C) 2004-2007 Herbert Pötzl
16658+ *
16659+ * V0.01 broken out from limit.c
16660+ * V0.02 added utsname stuff
16661+ * V0.03 changed vcmds to vxi arg
16662+ *
16663+ */
16664+
16665+#include <linux/types.h>
16666+#include <linux/utsname.h>
16667+#include <linux/vs_cvirt.h>
16668+#include <linux/vserver/switch.h>
16669+#include <linux/vserver/cvirt_cmd.h>
16670+
16671+#include <asm/uaccess.h>
16672+
16673+
16674+void vx_vsi_boottime(struct timespec *boottime)
16675+{
16676+ struct vx_info *vxi = current_vx_info();
16677+
16678+ set_normalized_timespec(boottime,
16679+ boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16680+ boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16681+ return;
16682+}
16683+
16684+void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16685+{
16686+ struct vx_info *vxi = current_vx_info();
16687+
16688+ set_normalized_timespec(uptime,
16689+ uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16690+ uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16691+ if (!idle)
16692+ return;
16693+ set_normalized_timespec(idle,
16694+ idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16695+ idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16696+ return;
16697+}
16698+
16699+uint64_t vx_idle_jiffies(void)
16700+{
16701+ return init_task.utime + init_task.stime;
16702+}
16703+
16704+
16705+
16706+static inline uint32_t __update_loadavg(uint32_t load,
16707+ int wsize, int delta, int n)
16708+{
16709+ unsigned long long calc, prev;
16710+
16711+ /* just set it to n */
16712+ if (unlikely(delta >= wsize))
16713+ return (n << FSHIFT);
16714+
16715+ calc = delta * n;
16716+ calc <<= FSHIFT;
16717+ prev = (wsize - delta);
16718+ prev *= load;
16719+ calc += prev;
16720+ do_div(calc, wsize);
16721+ return calc;
16722+}
16723+
16724+
16725+void vx_update_load(struct vx_info *vxi)
16726+{
16727+ uint32_t now, last, delta;
16728+ unsigned int nr_running, nr_uninterruptible;
16729+ unsigned int total;
16730+ unsigned long flags;
16731+
16732+ spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16733+
16734+ now = jiffies;
16735+ last = vxi->cvirt.load_last;
16736+ delta = now - last;
16737+
16738+ if (delta < 5*HZ)
16739+ goto out;
16740+
16741+ nr_running = atomic_read(&vxi->cvirt.nr_running);
16742+ nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16743+ total = nr_running + nr_uninterruptible;
16744+
16745+ vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16746+ 60*HZ, delta, total);
16747+ vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16748+ 5*60*HZ, delta, total);
16749+ vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16750+ 15*60*HZ, delta, total);
16751+
16752+ vxi->cvirt.load_last = now;
16753+out:
16754+ atomic_inc(&vxi->cvirt.load_updates);
16755+ spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16756+}
16757+
16758+
16759+/*
16760+ * Commands to do_syslog:
16761+ *
16762+ * 0 -- Close the log. Currently a NOP.
16763+ * 1 -- Open the log. Currently a NOP.
16764+ * 2 -- Read from the log.
16765+ * 3 -- Read all messages remaining in the ring buffer.
16766+ * 4 -- Read and clear all messages remaining in the ring buffer
16767+ * 5 -- Clear ring buffer.
16768+ * 6 -- Disable printk's to console
16769+ * 7 -- Enable printk's to console
16770+ * 8 -- Set level of messages printed to console
16771+ * 9 -- Return number of unread characters in the log buffer
16772+ * 10 -- Return size of the log buffer
16773+ */
16774+int vx_do_syslog(int type, char __user *buf, int len)
16775+{
16776+ int error = 0;
16777+ int do_clear = 0;
16778+ struct vx_info *vxi = current_vx_info();
16779+ struct _vx_syslog *log;
16780+
16781+ if (!vxi)
16782+ return -EINVAL;
16783+ log = &vxi->cvirt.syslog;
16784+
16785+ switch (type) {
16786+ case 0: /* Close log */
16787+ case 1: /* Open log */
16788+ break;
16789+ case 2: /* Read from log */
16790+ error = wait_event_interruptible(log->log_wait,
16791+ (log->log_start - log->log_end));
16792+ if (error)
16793+ break;
16794+ spin_lock_irq(&log->logbuf_lock);
16795+ spin_unlock_irq(&log->logbuf_lock);
16796+ break;
16797+ case 4: /* Read/clear last kernel messages */
16798+ do_clear = 1;
16799+ /* fall through */
16800+ case 3: /* Read last kernel messages */
16801+ return 0;
16802+
16803+ case 5: /* Clear ring buffer */
16804+ return 0;
16805+
16806+ case 6: /* Disable logging to console */
16807+ case 7: /* Enable logging to console */
16808+ case 8: /* Set level of messages printed to console */
16809+ break;
16810+
16811+ case 9: /* Number of chars in the log buffer */
16812+ return 0;
16813+ case 10: /* Size of the log buffer */
16814+ return 0;
16815+ default:
16816+ error = -EINVAL;
16817+ break;
16818+ }
16819+ return error;
16820+}
16821+
16822+
16823+/* virtual host info names */
16824+
16825+static char *vx_vhi_name(struct vx_info *vxi, int id)
16826+{
16827+ struct nsproxy *nsproxy;
16828+ struct uts_namespace *uts;
16829+
16830+ if (id == VHIN_CONTEXT)
16831+ return vxi->vx_name;
16832+
16833+ nsproxy = vxi->space[0].vx_nsproxy;
16834+ if (!nsproxy)
16835+ return NULL;
16836+
16837+ uts = nsproxy->uts_ns;
16838+ if (!uts)
16839+ return NULL;
16840+
16841+ switch (id) {
16842+ case VHIN_SYSNAME:
16843+ return uts->name.sysname;
16844+ case VHIN_NODENAME:
16845+ return uts->name.nodename;
16846+ case VHIN_RELEASE:
16847+ return uts->name.release;
16848+ case VHIN_VERSION:
16849+ return uts->name.version;
16850+ case VHIN_MACHINE:
16851+ return uts->name.machine;
16852+ case VHIN_DOMAINNAME:
16853+ return uts->name.domainname;
16854+ default:
16855+ return NULL;
16856+ }
16857+ return NULL;
16858+}
16859+
16860+int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16861+{
16862+ struct vcmd_vhi_name_v0 vc_data;
16863+ char *name;
16864+
16865+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16866+ return -EFAULT;
16867+
16868+ name = vx_vhi_name(vxi, vc_data.field);
16869+ if (!name)
16870+ return -EINVAL;
16871+
16872+ memcpy(name, vc_data.name, 65);
16873+ return 0;
16874+}
16875+
16876+int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16877+{
16878+ struct vcmd_vhi_name_v0 vc_data;
16879+ char *name;
16880+
16881+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16882+ return -EFAULT;
16883+
16884+ name = vx_vhi_name(vxi, vc_data.field);
16885+ if (!name)
16886+ return -EINVAL;
16887+
16888+ memcpy(vc_data.name, name, 65);
16889+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16890+ return -EFAULT;
16891+ return 0;
16892+}
16893+
16894+
16895+int vc_virt_stat(struct vx_info *vxi, void __user *data)
16896+{
16897+ struct vcmd_virt_stat_v0 vc_data;
16898+ struct _vx_cvirt *cvirt = &vxi->cvirt;
16899+ struct timespec uptime;
16900+
16901+ do_posix_clock_monotonic_gettime(&uptime);
16902+ set_normalized_timespec(&uptime,
16903+ uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16904+ uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16905+
16906+ vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16907+ vc_data.uptime = timespec_to_ns(&uptime);
16908+ vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16909+ vc_data.nr_running = atomic_read(&cvirt->nr_running);
16910+ vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16911+ vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16912+ vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16913+ vc_data.load[0] = cvirt->load[0];
16914+ vc_data.load[1] = cvirt->load[1];
16915+ vc_data.load[2] = cvirt->load[2];
16916+
16917+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16918+ return -EFAULT;
16919+ return 0;
16920+}
16921+
16922+
16923+#ifdef CONFIG_VSERVER_VTIME
16924+
16925+/* virtualized time base */
16926+
16927+void vx_adjust_timespec(struct timespec *ts)
16928+{
16929+ struct vx_info *vxi;
16930+
16931+ if (!vx_flags(VXF_VIRT_TIME, 0))
16932+ return;
16933+
16934+ vxi = current_vx_info();
16935+ ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16936+ ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16937+
16938+ if (ts->tv_nsec >= NSEC_PER_SEC) {
16939+ ts->tv_sec++;
16940+ ts->tv_nsec -= NSEC_PER_SEC;
16941+ } else if (ts->tv_nsec < 0) {
16942+ ts->tv_sec--;
16943+ ts->tv_nsec += NSEC_PER_SEC;
16944+ }
16945+}
16946+
16947+int vx_settimeofday(const struct timespec *ts)
16948+{
16949+ struct timespec ats, delta;
16950+ struct vx_info *vxi;
16951+
16952+ if (!vx_flags(VXF_VIRT_TIME, 0))
16953+ return do_settimeofday(ts);
16954+
16955+ getnstimeofday(&ats);
16956+ delta = timespec_sub(*ts, ats);
16957+
16958+ vxi = current_vx_info();
16959+ vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16960+ return 0;
16961+}
16962+
16963+#endif
16964+
16965diff -NurpP --minimal linux-3.6.6/kernel/vserver/cvirt_init.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cvirt_init.h
16966--- linux-3.6.6/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
16967+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cvirt_init.h 2012-10-04 18:47:00.000000000 +0200
16968@@ -0,0 +1,70 @@
16969+
16970+
16971+extern uint64_t vx_idle_jiffies(void);
16972+
16973+static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16974+{
16975+ uint64_t idle_jiffies = vx_idle_jiffies();
16976+ uint64_t nsuptime;
16977+
16978+ do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16979+ nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16980+ * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16981+ cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16982+ cvirt->bias_ts.tv_sec = 0;
16983+ cvirt->bias_ts.tv_nsec = 0;
16984+
16985+ jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16986+ atomic_set(&cvirt->nr_threads, 0);
16987+ atomic_set(&cvirt->nr_running, 0);
16988+ atomic_set(&cvirt->nr_uninterruptible, 0);
16989+ atomic_set(&cvirt->nr_onhold, 0);
16990+
16991+ spin_lock_init(&cvirt->load_lock);
16992+ cvirt->load_last = jiffies;
16993+ atomic_set(&cvirt->load_updates, 0);
16994+ cvirt->load[0] = 0;
16995+ cvirt->load[1] = 0;
16996+ cvirt->load[2] = 0;
16997+ atomic_set(&cvirt->total_forks, 0);
16998+
16999+ spin_lock_init(&cvirt->syslog.logbuf_lock);
17000+ init_waitqueue_head(&cvirt->syslog.log_wait);
17001+ cvirt->syslog.log_start = 0;
17002+ cvirt->syslog.log_end = 0;
17003+ cvirt->syslog.con_start = 0;
17004+ cvirt->syslog.logged_chars = 0;
17005+}
17006+
17007+static inline
17008+void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17009+{
17010+ // cvirt_pc->cpustat = { 0 };
17011+}
17012+
17013+static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17014+{
17015+#ifdef CONFIG_VSERVER_WARN
17016+ int value;
17017+#endif
17018+ vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17019+ "!!! cvirt: %p[nr_threads] = %d on exit.",
17020+ cvirt, value);
17021+ vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17022+ "!!! cvirt: %p[nr_running] = %d on exit.",
17023+ cvirt, value);
17024+ vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17025+ "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17026+ cvirt, value);
17027+ vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17028+ "!!! cvirt: %p[nr_onhold] = %d on exit.",
17029+ cvirt, value);
17030+ return;
17031+}
17032+
17033+static inline
17034+void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17035+{
17036+ return;
17037+}
17038+
17039diff -NurpP --minimal linux-3.6.6/kernel/vserver/cvirt_proc.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cvirt_proc.h
17040--- linux-3.6.6/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
17041+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/cvirt_proc.h 2012-10-04 18:47:00.000000000 +0200
17042@@ -0,0 +1,123 @@
17043+#ifndef _VX_CVIRT_PROC_H
17044+#define _VX_CVIRT_PROC_H
17045+
17046+#include <linux/nsproxy.h>
17047+#include <linux/mnt_namespace.h>
17048+#include <linux/ipc_namespace.h>
17049+#include <linux/utsname.h>
17050+#include <linux/ipc.h>
17051+
17052+extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17053+
17054+static inline
17055+int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17056+{
17057+ struct mnt_namespace *ns;
17058+ struct uts_namespace *uts;
17059+ struct ipc_namespace *ipc;
17060+ int length = 0;
17061+
17062+ if (!nsproxy)
17063+ goto out;
17064+
17065+ length += sprintf(buffer + length,
17066+ "NSProxy:\t%p [%p,%p,%p]\n",
17067+ nsproxy, nsproxy->mnt_ns,
17068+ nsproxy->uts_ns, nsproxy->ipc_ns);
17069+
17070+ ns = nsproxy->mnt_ns;
17071+ if (!ns)
17072+ goto skip_ns;
17073+
17074+ length += vx_info_mnt_namespace(ns, buffer + length);
17075+
17076+skip_ns:
17077+
17078+ uts = nsproxy->uts_ns;
17079+ if (!uts)
17080+ goto skip_uts;
17081+
17082+ length += sprintf(buffer + length,
17083+ "SysName:\t%.*s\n"
17084+ "NodeName:\t%.*s\n"
17085+ "Release:\t%.*s\n"
17086+ "Version:\t%.*s\n"
17087+ "Machine:\t%.*s\n"
17088+ "DomainName:\t%.*s\n",
17089+ __NEW_UTS_LEN, uts->name.sysname,
17090+ __NEW_UTS_LEN, uts->name.nodename,
17091+ __NEW_UTS_LEN, uts->name.release,
17092+ __NEW_UTS_LEN, uts->name.version,
17093+ __NEW_UTS_LEN, uts->name.machine,
17094+ __NEW_UTS_LEN, uts->name.domainname);
17095+skip_uts:
17096+
17097+ ipc = nsproxy->ipc_ns;
17098+ if (!ipc)
17099+ goto skip_ipc;
17100+
17101+ length += sprintf(buffer + length,
17102+ "SEMS:\t\t%d %d %d %d %d\n"
17103+ "MSG:\t\t%d %d %d\n"
17104+ "SHM:\t\t%lu %lu %d %d\n",
17105+ ipc->sem_ctls[0], ipc->sem_ctls[1],
17106+ ipc->sem_ctls[2], ipc->sem_ctls[3],
17107+ ipc->used_sems,
17108+ ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17109+ (unsigned long)ipc->shm_ctlmax,
17110+ (unsigned long)ipc->shm_ctlall,
17111+ ipc->shm_ctlmni, ipc->shm_tot);
17112+skip_ipc:
17113+out:
17114+ return length;
17115+}
17116+
17117+
17118+#include <linux/sched.h>
17119+
17120+#define LOAD_INT(x) ((x) >> FSHIFT)
17121+#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17122+
17123+static inline
17124+int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17125+{
17126+ int length = 0;
17127+ int a, b, c;
17128+
17129+ length += sprintf(buffer + length,
17130+ "BiasUptime:\t%lu.%02lu\n",
17131+ (unsigned long)cvirt->bias_uptime.tv_sec,
17132+ (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17133+
17134+ a = cvirt->load[0] + (FIXED_1 / 200);
17135+ b = cvirt->load[1] + (FIXED_1 / 200);
17136+ c = cvirt->load[2] + (FIXED_1 / 200);
17137+ length += sprintf(buffer + length,
17138+ "nr_threads:\t%d\n"
17139+ "nr_running:\t%d\n"
17140+ "nr_unintr:\t%d\n"
17141+ "nr_onhold:\t%d\n"
17142+ "load_updates:\t%d\n"
17143+ "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17144+ "total_forks:\t%d\n",
17145+ atomic_read(&cvirt->nr_threads),
17146+ atomic_read(&cvirt->nr_running),
17147+ atomic_read(&cvirt->nr_uninterruptible),
17148+ atomic_read(&cvirt->nr_onhold),
17149+ atomic_read(&cvirt->load_updates),
17150+ LOAD_INT(a), LOAD_FRAC(a),
17151+ LOAD_INT(b), LOAD_FRAC(b),
17152+ LOAD_INT(c), LOAD_FRAC(c),
17153+ atomic_read(&cvirt->total_forks));
17154+ return length;
17155+}
17156+
17157+static inline
17158+int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17159+ char *buffer, int cpu)
17160+{
17161+ int length = 0;
17162+ return length;
17163+}
17164+
17165+#endif /* _VX_CVIRT_PROC_H */
17166diff -NurpP --minimal linux-3.6.6/kernel/vserver/debug.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/debug.c
17167--- linux-3.6.6/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
17168+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/debug.c 2012-10-04 18:47:00.000000000 +0200
17169@@ -0,0 +1,32 @@
17170+/*
17171+ * kernel/vserver/debug.c
17172+ *
17173+ * Copyright (C) 2005-2007 Herbert Pötzl
17174+ *
17175+ * V0.01 vx_info dump support
17176+ *
17177+ */
17178+
17179+#include <linux/module.h>
17180+
17181+#include <linux/vserver/context.h>
17182+
17183+
17184+void dump_vx_info(struct vx_info *vxi, int level)
17185+{
17186+ printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17187+ atomic_read(&vxi->vx_usecnt),
17188+ atomic_read(&vxi->vx_tasks),
17189+ vxi->vx_state);
17190+ if (level > 0) {
17191+ __dump_vx_limit(&vxi->limit);
17192+ __dump_vx_sched(&vxi->sched);
17193+ __dump_vx_cvirt(&vxi->cvirt);
17194+ __dump_vx_cacct(&vxi->cacct);
17195+ }
17196+ printk("---\n");
17197+}
17198+
17199+
17200+EXPORT_SYMBOL_GPL(dump_vx_info);
17201+
17202diff -NurpP --minimal linux-3.6.6/kernel/vserver/device.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/device.c
17203--- linux-3.6.6/kernel/vserver/device.c 1970-01-01 01:00:00.000000000 +0100
17204+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/device.c 2012-10-04 18:47:00.000000000 +0200
17205@@ -0,0 +1,443 @@
17206+/*
17207+ * linux/kernel/vserver/device.c
17208+ *
17209+ * Linux-VServer: Device Support
17210+ *
17211+ * Copyright (C) 2006 Herbert Pötzl
17212+ * Copyright (C) 2007 Daniel Hokka Zakrisson
17213+ *
17214+ * V0.01 device mapping basics
17215+ * V0.02 added defaults
17216+ *
17217+ */
17218+
17219+#include <linux/slab.h>
17220+#include <linux/rcupdate.h>
17221+#include <linux/fs.h>
17222+#include <linux/namei.h>
17223+#include <linux/hash.h>
17224+
17225+#include <asm/errno.h>
17226+#include <asm/uaccess.h>
17227+#include <linux/vserver/base.h>
17228+#include <linux/vserver/debug.h>
17229+#include <linux/vserver/context.h>
17230+#include <linux/vserver/device.h>
17231+#include <linux/vserver/device_cmd.h>
17232+
17233+
17234+#define DMAP_HASH_BITS 4
17235+
17236+
17237+struct vs_mapping {
17238+ union {
17239+ struct hlist_node hlist;
17240+ struct list_head list;
17241+ } u;
17242+#define dm_hlist u.hlist
17243+#define dm_list u.list
17244+ xid_t xid;
17245+ dev_t device;
17246+ struct vx_dmap_target target;
17247+};
17248+
17249+
17250+static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17251+
17252+static DEFINE_SPINLOCK(dmap_main_hash_lock);
17253+
17254+static struct vx_dmap_target dmap_defaults[2] = {
17255+ { .flags = DATTR_OPEN },
17256+ { .flags = DATTR_OPEN },
17257+};
17258+
17259+
17260+struct kmem_cache *dmap_cachep __read_mostly;
17261+
17262+int __init dmap_cache_init(void)
17263+{
17264+ dmap_cachep = kmem_cache_create("dmap_cache",
17265+ sizeof(struct vs_mapping), 0,
17266+ SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17267+ return 0;
17268+}
17269+
17270+__initcall(dmap_cache_init);
17271+
17272+
17273+static inline unsigned int __hashval(dev_t dev, int bits)
17274+{
17275+ return hash_long((unsigned long)dev, bits);
17276+}
17277+
17278+
17279+/* __hash_mapping()
17280+ * add the mapping to the hash table
17281+ */
17282+static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17283+{
17284+ spinlock_t *hash_lock = &dmap_main_hash_lock;
17285+ struct hlist_head *head, *hash = dmap_main_hash;
17286+ int device = vdm->device;
17287+
17288+ spin_lock(hash_lock);
17289+ vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17290+ vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17291+
17292+ head = &hash[__hashval(device, DMAP_HASH_BITS)];
17293+ hlist_add_head(&vdm->dm_hlist, head);
17294+ spin_unlock(hash_lock);
17295+}
17296+
17297+
17298+static inline int __mode_to_default(umode_t mode)
17299+{
17300+ switch (mode) {
17301+ case S_IFBLK:
17302+ return 0;
17303+ case S_IFCHR:
17304+ return 1;
17305+ default:
17306+ BUG();
17307+ }
17308+}
17309+
17310+
17311+/* __set_default()
17312+ * set a default
17313+ */
17314+static inline void __set_default(struct vx_info *vxi, umode_t mode,
17315+ struct vx_dmap_target *vdmt)
17316+{
17317+ spinlock_t *hash_lock = &dmap_main_hash_lock;
17318+ spin_lock(hash_lock);
17319+
17320+ if (vxi)
17321+ vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17322+ else
17323+ dmap_defaults[__mode_to_default(mode)] = *vdmt;
17324+
17325+
17326+ spin_unlock(hash_lock);
17327+
17328+ vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17329+ vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17330+}
17331+
17332+
17333+/* __remove_default()
17334+ * remove a default
17335+ */
17336+static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17337+{
17338+ spinlock_t *hash_lock = &dmap_main_hash_lock;
17339+ spin_lock(hash_lock);
17340+
17341+ if (vxi)
17342+ vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17343+ else /* remove == reset */
17344+ dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17345+
17346+ spin_unlock(hash_lock);
17347+ return 0;
17348+}
17349+
17350+
17351+/* __find_mapping()
17352+ * find a mapping in the hash table
17353+ *
17354+ * caller must hold hash_lock
17355+ */
17356+static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17357+ struct vs_mapping **local, struct vs_mapping **global)
17358+{
17359+ struct hlist_head *hash = dmap_main_hash;
17360+ struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17361+ struct hlist_node *pos;
17362+ struct vs_mapping *vdm;
17363+
17364+ *local = NULL;
17365+ if (global)
17366+ *global = NULL;
17367+
17368+ hlist_for_each(pos, head) {
17369+ vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17370+
17371+ if ((vdm->device == device) &&
17372+ !((vdm->target.flags ^ mode) & S_IFMT)) {
17373+ if (vdm->xid == xid) {
17374+ *local = vdm;
17375+ return 1;
17376+ } else if (global && vdm->xid == 0)
17377+ *global = vdm;
17378+ }
17379+ }
17380+
17381+ if (global && *global)
17382+ return 0;
17383+ else
17384+ return -ENOENT;
17385+}
17386+
17387+
17388+/* __lookup_mapping()
17389+ * find a mapping and store the result in target and flags
17390+ */
17391+static inline int __lookup_mapping(struct vx_info *vxi,
17392+ dev_t device, dev_t *target, int *flags, umode_t mode)
17393+{
17394+ spinlock_t *hash_lock = &dmap_main_hash_lock;
17395+ struct vs_mapping *vdm, *global;
17396+ struct vx_dmap_target *vdmt;
17397+ int ret = 0;
17398+ xid_t xid = vxi->vx_id;
17399+ int index;
17400+
17401+ spin_lock(hash_lock);
17402+ if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17403+ ret = 1;
17404+ vdmt = &vdm->target;
17405+ goto found;
17406+ }
17407+
17408+ index = __mode_to_default(mode);
17409+ if (vxi && vxi->dmap.targets[index].flags) {
17410+ ret = 2;
17411+ vdmt = &vxi->dmap.targets[index];
17412+ } else if (global) {
17413+ ret = 3;
17414+ vdmt = &global->target;
17415+ goto found;
17416+ } else {
17417+ ret = 4;
17418+ vdmt = &dmap_defaults[index];
17419+ }
17420+
17421+found:
17422+ if (target && (vdmt->flags & DATTR_REMAP))
17423+ *target = vdmt->target;
17424+ else if (target)
17425+ *target = device;
17426+ if (flags)
17427+ *flags = vdmt->flags;
17428+
17429+ spin_unlock(hash_lock);
17430+
17431+ return ret;
17432+}
17433+
17434+
17435+/* __remove_mapping()
17436+ * remove a mapping from the hash table
17437+ */
17438+static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17439+ umode_t mode)
17440+{
17441+ spinlock_t *hash_lock = &dmap_main_hash_lock;
17442+ struct vs_mapping *vdm = NULL;
17443+ int ret = 0;
17444+
17445+ spin_lock(hash_lock);
17446+
17447+ ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17448+ NULL);
17449+ vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17450+ vxi, vxi ? vxi->vx_id : 0, device, mode);
17451+ if (ret < 0)
17452+ goto out;
17453+ hlist_del(&vdm->dm_hlist);
17454+
17455+out:
17456+ spin_unlock(hash_lock);
17457+ if (vdm)
17458+ kmem_cache_free(dmap_cachep, vdm);
17459+ return ret;
17460+}
17461+
17462+
17463+
17464+int vs_map_device(struct vx_info *vxi,
17465+ dev_t device, dev_t *target, umode_t mode)
17466+{
17467+ int ret, flags = DATTR_MASK;
17468+
17469+ if (!vxi) {
17470+ if (target)
17471+ *target = device;
17472+ goto out;
17473+ }
17474+ ret = __lookup_mapping(vxi, device, target, &flags, mode);
17475+ vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17476+ device, target ? *target : 0, flags, mode, ret);
17477+out:
17478+ return (flags & DATTR_MASK);
17479+}
17480+
17481+
17482+
17483+static int do_set_mapping(struct vx_info *vxi,
17484+ dev_t device, dev_t target, int flags, umode_t mode)
17485+{
17486+ if (device) {
17487+ struct vs_mapping *new;
17488+
17489+ new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17490+ if (!new)
17491+ return -ENOMEM;
17492+
17493+ INIT_HLIST_NODE(&new->dm_hlist);
17494+ new->device = device;
17495+ new->target.target = target;
17496+ new->target.flags = flags | mode;
17497+ new->xid = (vxi ? vxi->vx_id : 0);
17498+
17499+ vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17500+ __hash_mapping(vxi, new);
17501+ } else {
17502+ struct vx_dmap_target new = {
17503+ .target = target,
17504+ .flags = flags | mode,
17505+ };
17506+ __set_default(vxi, mode, &new);
17507+ }
17508+ return 0;
17509+}
17510+
17511+
17512+static int do_unset_mapping(struct vx_info *vxi,
17513+ dev_t device, dev_t target, int flags, umode_t mode)
17514+{
17515+ int ret = -EINVAL;
17516+
17517+ if (device) {
17518+ ret = __remove_mapping(vxi, device, mode);
17519+ if (ret < 0)
17520+ goto out;
17521+ } else {
17522+ ret = __remove_default(vxi, mode);
17523+ if (ret < 0)
17524+ goto out;
17525+ }
17526+
17527+out:
17528+ return ret;
17529+}
17530+
17531+
17532+static inline int __user_device(const char __user *name, dev_t *dev,
17533+ umode_t *mode)
17534+{
17535+ struct nameidata nd;
17536+ int ret;
17537+
17538+ if (!name) {
17539+ *dev = 0;
17540+ return 0;
17541+ }
17542+ ret = user_lpath(name, &nd.path);
17543+ if (ret)
17544+ return ret;
17545+ if (nd.path.dentry->d_inode) {
17546+ *dev = nd.path.dentry->d_inode->i_rdev;
17547+ *mode = nd.path.dentry->d_inode->i_mode;
17548+ }
17549+ path_put(&nd.path);
17550+ return 0;
17551+}
17552+
17553+static inline int __mapping_mode(dev_t device, dev_t target,
17554+ umode_t device_mode, umode_t target_mode, umode_t *mode)
17555+{
17556+ if (device)
17557+ *mode = device_mode & S_IFMT;
17558+ else if (target)
17559+ *mode = target_mode & S_IFMT;
17560+ else
17561+ return -EINVAL;
17562+
17563+ /* if both given, device and target mode have to match */
17564+ if (device && target &&
17565+ ((device_mode ^ target_mode) & S_IFMT))
17566+ return -EINVAL;
17567+ return 0;
17568+}
17569+
17570+
17571+static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17572+ const char __user *target_path, int flags, int set)
17573+{
17574+ dev_t device = ~0, target = ~0;
17575+ umode_t device_mode = 0, target_mode = 0, mode;
17576+ int ret;
17577+
17578+ ret = __user_device(device_path, &device, &device_mode);
17579+ if (ret)
17580+ return ret;
17581+ ret = __user_device(target_path, &target, &target_mode);
17582+ if (ret)
17583+ return ret;
17584+
17585+ ret = __mapping_mode(device, target,
17586+ device_mode, target_mode, &mode);
17587+ if (ret)
17588+ return ret;
17589+
17590+ if (set)
17591+ return do_set_mapping(vxi, device, target,
17592+ flags, mode);
17593+ else
17594+ return do_unset_mapping(vxi, device, target,
17595+ flags, mode);
17596+}
17597+
17598+
17599+int vc_set_mapping(struct vx_info *vxi, void __user *data)
17600+{
17601+ struct vcmd_set_mapping_v0 vc_data;
17602+
17603+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17604+ return -EFAULT;
17605+
17606+ return do_mapping(vxi, vc_data.device, vc_data.target,
17607+ vc_data.flags, 1);
17608+}
17609+
17610+int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17611+{
17612+ struct vcmd_set_mapping_v0 vc_data;
17613+
17614+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17615+ return -EFAULT;
17616+
17617+ return do_mapping(vxi, vc_data.device, vc_data.target,
17618+ vc_data.flags, 0);
17619+}
17620+
17621+
17622+#ifdef CONFIG_COMPAT
17623+
17624+int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17625+{
17626+ struct vcmd_set_mapping_v0_x32 vc_data;
17627+
17628+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17629+ return -EFAULT;
17630+
17631+ return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17632+ compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17633+}
17634+
17635+int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17636+{
17637+ struct vcmd_set_mapping_v0_x32 vc_data;
17638+
17639+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17640+ return -EFAULT;
17641+
17642+ return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17643+ compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17644+}
17645+
17646+#endif /* CONFIG_COMPAT */
17647+
17648+
17649diff -NurpP --minimal linux-3.6.6/kernel/vserver/dlimit.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/dlimit.c
17650--- linux-3.6.6/kernel/vserver/dlimit.c 1970-01-01 01:00:00.000000000 +0100
17651+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/dlimit.c 2012-10-04 18:47:00.000000000 +0200
17652@@ -0,0 +1,531 @@
17653+/*
17654+ * linux/kernel/vserver/dlimit.c
17655+ *
17656+ * Virtual Server: Context Disk Limits
17657+ *
17658+ * Copyright (C) 2004-2009 Herbert Pötzl
17659+ *
17660+ * V0.01 initial version
17661+ * V0.02 compat32 splitup
17662+ * V0.03 extended interface
17663+ *
17664+ */
17665+
17666+#include <linux/statfs.h>
17667+#include <linux/sched.h>
17668+#include <linux/namei.h>
17669+#include <linux/vs_tag.h>
17670+#include <linux/vs_dlimit.h>
17671+#include <linux/vserver/dlimit_cmd.h>
17672+#include <linux/slab.h>
17673+// #include <linux/gfp.h>
17674+
17675+#include <asm/uaccess.h>
17676+
17677+/* __alloc_dl_info()
17678+
17679+ * allocate an initialized dl_info struct
17680+ * doesn't make it visible (hash) */
17681+
17682+static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17683+{
17684+ struct dl_info *new = NULL;
17685+
17686+ vxdprintk(VXD_CBIT(dlim, 5),
17687+ "alloc_dl_info(%p,%d)*", sb, tag);
17688+
17689+ /* would this benefit from a slab cache? */
17690+ new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17691+ if (!new)
17692+ return 0;
17693+
17694+ memset(new, 0, sizeof(struct dl_info));
17695+ new->dl_tag = tag;
17696+ new->dl_sb = sb;
17697+ // INIT_RCU_HEAD(&new->dl_rcu);
17698+ INIT_HLIST_NODE(&new->dl_hlist);
17699+ spin_lock_init(&new->dl_lock);
17700+ atomic_set(&new->dl_refcnt, 0);
17701+ atomic_set(&new->dl_usecnt, 0);
17702+
17703+ /* rest of init goes here */
17704+
17705+ vxdprintk(VXD_CBIT(dlim, 4),
17706+ "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17707+ return new;
17708+}
17709+
17710+/* __dealloc_dl_info()
17711+
17712+ * final disposal of dl_info */
17713+
17714+static void __dealloc_dl_info(struct dl_info *dli)
17715+{
17716+ vxdprintk(VXD_CBIT(dlim, 4),
17717+ "dealloc_dl_info(%p)", dli);
17718+
17719+ dli->dl_hlist.next = LIST_POISON1;
17720+ dli->dl_tag = -1;
17721+ dli->dl_sb = 0;
17722+
17723+ BUG_ON(atomic_read(&dli->dl_usecnt));
17724+ BUG_ON(atomic_read(&dli->dl_refcnt));
17725+
17726+ kfree(dli);
17727+}
17728+
17729+
17730+/* hash table for dl_info hash */
17731+
17732+#define DL_HASH_SIZE 13
17733+
17734+struct hlist_head dl_info_hash[DL_HASH_SIZE];
17735+
17736+static DEFINE_SPINLOCK(dl_info_hash_lock);
17737+
17738+
17739+static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17740+{
17741+ return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17742+}
17743+
17744+
17745+
17746+/* __hash_dl_info()
17747+
17748+ * add the dli to the global hash table
17749+ * requires the hash_lock to be held */
17750+
17751+static inline void __hash_dl_info(struct dl_info *dli)
17752+{
17753+ struct hlist_head *head;
17754+
17755+ vxdprintk(VXD_CBIT(dlim, 6),
17756+ "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17757+ get_dl_info(dli);
17758+ head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17759+ hlist_add_head_rcu(&dli->dl_hlist, head);
17760+}
17761+
17762+/* __unhash_dl_info()
17763+
17764+ * remove the dli from the global hash table
17765+ * requires the hash_lock to be held */
17766+
17767+static inline void __unhash_dl_info(struct dl_info *dli)
17768+{
17769+ vxdprintk(VXD_CBIT(dlim, 6),
17770+ "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17771+ hlist_del_rcu(&dli->dl_hlist);
17772+ put_dl_info(dli);
17773+}
17774+
17775+
17776+/* __lookup_dl_info()
17777+
17778+ * requires the rcu_read_lock()
17779+ * doesn't increment the dl_refcnt */
17780+
17781+static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17782+{
17783+ struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17784+ struct hlist_node *pos;
17785+ struct dl_info *dli;
17786+
17787+ hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
17788+
17789+ if (dli->dl_tag == tag && dli->dl_sb == sb) {
17790+ return dli;
17791+ }
17792+ }
17793+ return NULL;
17794+}
17795+
17796+
17797+struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17798+{
17799+ struct dl_info *dli;
17800+
17801+ rcu_read_lock();
17802+ dli = get_dl_info(__lookup_dl_info(sb, tag));
17803+ vxdprintk(VXD_CBIT(dlim, 7),
17804+ "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17805+ rcu_read_unlock();
17806+ return dli;
17807+}
17808+
17809+void rcu_free_dl_info(struct rcu_head *head)
17810+{
17811+ struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17812+ int usecnt, refcnt;
17813+
17814+ BUG_ON(!dli || !head);
17815+
17816+ usecnt = atomic_read(&dli->dl_usecnt);
17817+ BUG_ON(usecnt < 0);
17818+
17819+ refcnt = atomic_read(&dli->dl_refcnt);
17820+ BUG_ON(refcnt < 0);
17821+
17822+ vxdprintk(VXD_CBIT(dlim, 3),
17823+ "rcu_free_dl_info(%p)", dli);
17824+ if (!usecnt)
17825+ __dealloc_dl_info(dli);
17826+ else
17827+ printk("!!! rcu didn't free\n");
17828+}
17829+
17830+
17831+
17832+
17833+static int do_addrem_dlimit(uint32_t id, const char __user *name,
17834+ uint32_t flags, int add)
17835+{
17836+ struct path path;
17837+ int ret;
17838+
17839+ ret = user_lpath(name, &path);
17840+ if (!ret) {
17841+ struct super_block *sb;
17842+ struct dl_info *dli;
17843+
17844+ ret = -EINVAL;
17845+ if (!path.dentry->d_inode)
17846+ goto out_release;
17847+ if (!(sb = path.dentry->d_inode->i_sb))
17848+ goto out_release;
17849+
17850+ if (add) {
17851+ dli = __alloc_dl_info(sb, id);
17852+ spin_lock(&dl_info_hash_lock);
17853+
17854+ ret = -EEXIST;
17855+ if (__lookup_dl_info(sb, id))
17856+ goto out_unlock;
17857+ __hash_dl_info(dli);
17858+ dli = NULL;
17859+ } else {
17860+ spin_lock(&dl_info_hash_lock);
17861+ dli = __lookup_dl_info(sb, id);
17862+
17863+ ret = -ESRCH;
17864+ if (!dli)
17865+ goto out_unlock;
17866+ __unhash_dl_info(dli);
17867+ }
17868+ ret = 0;
17869+ out_unlock:
17870+ spin_unlock(&dl_info_hash_lock);
17871+ if (add && dli)
17872+ __dealloc_dl_info(dli);
17873+ out_release:
17874+ path_put(&path);
17875+ }
17876+ return ret;
17877+}
17878+
17879+int vc_add_dlimit(uint32_t id, void __user *data)
17880+{
17881+ struct vcmd_ctx_dlimit_base_v0 vc_data;
17882+
17883+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17884+ return -EFAULT;
17885+
17886+ return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17887+}
17888+
17889+int vc_rem_dlimit(uint32_t id, void __user *data)
17890+{
17891+ struct vcmd_ctx_dlimit_base_v0 vc_data;
17892+
17893+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17894+ return -EFAULT;
17895+
17896+ return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17897+}
17898+
17899+#ifdef CONFIG_COMPAT
17900+
17901+int vc_add_dlimit_x32(uint32_t id, void __user *data)
17902+{
17903+ struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17904+
17905+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17906+ return -EFAULT;
17907+
17908+ return do_addrem_dlimit(id,
17909+ compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17910+}
17911+
17912+int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17913+{
17914+ struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17915+
17916+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17917+ return -EFAULT;
17918+
17919+ return do_addrem_dlimit(id,
17920+ compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17921+}
17922+
17923+#endif /* CONFIG_COMPAT */
17924+
17925+
17926+static inline
17927+int do_set_dlimit(uint32_t id, const char __user *name,
17928+ uint32_t space_used, uint32_t space_total,
17929+ uint32_t inodes_used, uint32_t inodes_total,
17930+ uint32_t reserved, uint32_t flags)
17931+{
17932+ struct path path;
17933+ int ret;
17934+
17935+ ret = user_lpath(name, &path);
17936+ if (!ret) {
17937+ struct super_block *sb;
17938+ struct dl_info *dli;
17939+
17940+ ret = -EINVAL;
17941+ if (!path.dentry->d_inode)
17942+ goto out_release;
17943+ if (!(sb = path.dentry->d_inode->i_sb))
17944+ goto out_release;
17945+
17946+ /* sanity checks */
17947+ if ((reserved != CDLIM_KEEP &&
17948+ reserved > 100) ||
17949+ (inodes_used != CDLIM_KEEP &&
17950+ inodes_used > inodes_total) ||
17951+ (space_used != CDLIM_KEEP &&
17952+ space_used > space_total))
17953+ goto out_release;
17954+
17955+ ret = -ESRCH;
17956+ dli = locate_dl_info(sb, id);
17957+ if (!dli)
17958+ goto out_release;
17959+
17960+ spin_lock(&dli->dl_lock);
17961+
17962+ if (inodes_used != CDLIM_KEEP)
17963+ dli->dl_inodes_used = inodes_used;
17964+ if (inodes_total != CDLIM_KEEP)
17965+ dli->dl_inodes_total = inodes_total;
17966+ if (space_used != CDLIM_KEEP)
17967+ dli->dl_space_used = dlimit_space_32to64(
17968+ space_used, flags, DLIMS_USED);
17969+
17970+ if (space_total == CDLIM_INFINITY)
17971+ dli->dl_space_total = DLIM_INFINITY;
17972+ else if (space_total != CDLIM_KEEP)
17973+ dli->dl_space_total = dlimit_space_32to64(
17974+ space_total, flags, DLIMS_TOTAL);
17975+
17976+ if (reserved != CDLIM_KEEP)
17977+ dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17978+
17979+ spin_unlock(&dli->dl_lock);
17980+
17981+ put_dl_info(dli);
17982+ ret = 0;
17983+
17984+ out_release:
17985+ path_put(&path);
17986+ }
17987+ return ret;
17988+}
17989+
17990+int vc_set_dlimit(uint32_t id, void __user *data)
17991+{
17992+ struct vcmd_ctx_dlimit_v0 vc_data;
17993+
17994+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17995+ return -EFAULT;
17996+
17997+ return do_set_dlimit(id, vc_data.name,
17998+ vc_data.space_used, vc_data.space_total,
17999+ vc_data.inodes_used, vc_data.inodes_total,
18000+ vc_data.reserved, vc_data.flags);
18001+}
18002+
18003+#ifdef CONFIG_COMPAT
18004+
18005+int vc_set_dlimit_x32(uint32_t id, void __user *data)
18006+{
18007+ struct vcmd_ctx_dlimit_v0_x32 vc_data;
18008+
18009+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18010+ return -EFAULT;
18011+
18012+ return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18013+ vc_data.space_used, vc_data.space_total,
18014+ vc_data.inodes_used, vc_data.inodes_total,
18015+ vc_data.reserved, vc_data.flags);
18016+}
18017+
18018+#endif /* CONFIG_COMPAT */
18019+
18020+
18021+static inline
18022+int do_get_dlimit(uint32_t id, const char __user *name,
18023+ uint32_t *space_used, uint32_t *space_total,
18024+ uint32_t *inodes_used, uint32_t *inodes_total,
18025+ uint32_t *reserved, uint32_t *flags)
18026+{
18027+ struct path path;
18028+ int ret;
18029+
18030+ ret = user_lpath(name, &path);
18031+ if (!ret) {
18032+ struct super_block *sb;
18033+ struct dl_info *dli;
18034+
18035+ ret = -EINVAL;
18036+ if (!path.dentry->d_inode)
18037+ goto out_release;
18038+ if (!(sb = path.dentry->d_inode->i_sb))
18039+ goto out_release;
18040+
18041+ ret = -ESRCH;
18042+ dli = locate_dl_info(sb, id);
18043+ if (!dli)
18044+ goto out_release;
18045+
18046+ spin_lock(&dli->dl_lock);
18047+ *inodes_used = dli->dl_inodes_used;
18048+ *inodes_total = dli->dl_inodes_total;
18049+
18050+ *space_used = dlimit_space_64to32(
18051+ dli->dl_space_used, flags, DLIMS_USED);
18052+
18053+ if (dli->dl_space_total == DLIM_INFINITY)
18054+ *space_total = CDLIM_INFINITY;
18055+ else
18056+ *space_total = dlimit_space_64to32(
18057+ dli->dl_space_total, flags, DLIMS_TOTAL);
18058+
18059+ *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18060+ spin_unlock(&dli->dl_lock);
18061+
18062+ put_dl_info(dli);
18063+ ret = -EFAULT;
18064+
18065+ ret = 0;
18066+ out_release:
18067+ path_put(&path);
18068+ }
18069+ return ret;
18070+}
18071+
18072+
18073+int vc_get_dlimit(uint32_t id, void __user *data)
18074+{
18075+ struct vcmd_ctx_dlimit_v0 vc_data;
18076+ int ret;
18077+
18078+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18079+ return -EFAULT;
18080+
18081+ ret = do_get_dlimit(id, vc_data.name,
18082+ &vc_data.space_used, &vc_data.space_total,
18083+ &vc_data.inodes_used, &vc_data.inodes_total,
18084+ &vc_data.reserved, &vc_data.flags);
18085+ if (ret)
18086+ return ret;
18087+
18088+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18089+ return -EFAULT;
18090+ return 0;
18091+}
18092+
18093+#ifdef CONFIG_COMPAT
18094+
18095+int vc_get_dlimit_x32(uint32_t id, void __user *data)
18096+{
18097+ struct vcmd_ctx_dlimit_v0_x32 vc_data;
18098+ int ret;
18099+
18100+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18101+ return -EFAULT;
18102+
18103+ ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18104+ &vc_data.space_used, &vc_data.space_total,
18105+ &vc_data.inodes_used, &vc_data.inodes_total,
18106+ &vc_data.reserved, &vc_data.flags);
18107+ if (ret)
18108+ return ret;
18109+
18110+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18111+ return -EFAULT;
18112+ return 0;
18113+}
18114+
18115+#endif /* CONFIG_COMPAT */
18116+
18117+
18118+void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18119+{
18120+ struct dl_info *dli;
18121+ __u64 blimit, bfree, bavail;
18122+ __u32 ifree;
18123+
18124+ dli = locate_dl_info(sb, dx_current_tag());
18125+ if (!dli)
18126+ return;
18127+
18128+ spin_lock(&dli->dl_lock);
18129+ if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18130+ goto no_ilim;
18131+
18132+ /* reduce max inodes available to limit */
18133+ if (buf->f_files > dli->dl_inodes_total)
18134+ buf->f_files = dli->dl_inodes_total;
18135+
18136+ ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18137+ /* reduce free inodes to min */
18138+ if (ifree < buf->f_ffree)
18139+ buf->f_ffree = ifree;
18140+
18141+no_ilim:
18142+ if (dli->dl_space_total == DLIM_INFINITY)
18143+ goto no_blim;
18144+
18145+ blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18146+
18147+ if (dli->dl_space_total < dli->dl_space_used)
18148+ bfree = 0;
18149+ else
18150+ bfree = (dli->dl_space_total - dli->dl_space_used)
18151+ >> sb->s_blocksize_bits;
18152+
18153+ bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18154+ if (bavail < dli->dl_space_used)
18155+ bavail = 0;
18156+ else
18157+ bavail = (bavail - dli->dl_space_used)
18158+ >> sb->s_blocksize_bits;
18159+
18160+ /* reduce max space available to limit */
18161+ if (buf->f_blocks > blimit)
18162+ buf->f_blocks = blimit;
18163+
18164+ /* reduce free space to min */
18165+ if (bfree < buf->f_bfree)
18166+ buf->f_bfree = bfree;
18167+
18168+ /* reduce avail space to min */
18169+ if (bavail < buf->f_bavail)
18170+ buf->f_bavail = bavail;
18171+
18172+no_blim:
18173+ spin_unlock(&dli->dl_lock);
18174+ put_dl_info(dli);
18175+
18176+ return;
18177+}
18178+
18179+#include <linux/module.h>
18180+
18181+EXPORT_SYMBOL_GPL(locate_dl_info);
18182+EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18183+
18184diff -NurpP --minimal linux-3.6.6/kernel/vserver/helper.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/helper.c
18185--- linux-3.6.6/kernel/vserver/helper.c 1970-01-01 01:00:00.000000000 +0100
18186+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/helper.c 2012-10-04 18:47:00.000000000 +0200
18187@@ -0,0 +1,229 @@
18188+/*
18189+ * linux/kernel/vserver/helper.c
18190+ *
18191+ * Virtual Context Support
18192+ *
18193+ * Copyright (C) 2004-2007 Herbert Pötzl
18194+ *
18195+ * V0.01 basic helper
18196+ *
18197+ */
18198+
18199+#include <linux/kmod.h>
18200+#include <linux/reboot.h>
18201+#include <linux/vs_context.h>
18202+#include <linux/vs_network.h>
18203+#include <linux/vserver/signal.h>
18204+
18205+
18206+char vshelper_path[255] = "/sbin/vshelper";
18207+
18208+static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18209+{
18210+ current->flags &= ~PF_THREAD_BOUND;
18211+ return 0;
18212+}
18213+
18214+static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18215+{
18216+ int ret;
18217+
18218+ if ((ret = call_usermodehelper_fns(name, argv, envp,
18219+ sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18220+ vshelper_init, NULL, NULL))) {
18221+ printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18222+ name, argv[1], argv[2],
18223+ sync ? "sync" : "async", ret);
18224+ }
18225+ vxdprintk(VXD_CBIT(switch, 4),
18226+ "%s: (%s %s) returned %s with %d",
18227+ name, argv[1], argv[2], sync ? "sync" : "async", ret);
18228+ return ret;
18229+}
18230+
18231+/*
18232+ * vshelper path is set via /proc/sys
18233+ * invoked by vserver sys_reboot(), with
18234+ * the following arguments
18235+ *
18236+ * argv [0] = vshelper_path;
18237+ * argv [1] = action: "restart", "halt", "poweroff", ...
18238+ * argv [2] = context identifier
18239+ *
18240+ * envp [*] = type-specific parameters
18241+ */
18242+
18243+long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18244+{
18245+ char id_buf[8], cmd_buf[16];
18246+ char uid_buf[16], pid_buf[16];
18247+ int ret;
18248+
18249+ char *argv[] = {vshelper_path, NULL, id_buf, 0};
18250+ char *envp[] = {"HOME=/", "TERM=linux",
18251+ "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18252+ uid_buf, pid_buf, cmd_buf, 0};
18253+
18254+ if (vx_info_state(vxi, VXS_HELPER))
18255+ return -EAGAIN;
18256+ vxi->vx_state |= VXS_HELPER;
18257+
18258+ snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18259+
18260+ snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18261+ snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18262+ snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18263+
18264+ switch (cmd) {
18265+ case LINUX_REBOOT_CMD_RESTART:
18266+ argv[1] = "restart";
18267+ break;
18268+
18269+ case LINUX_REBOOT_CMD_HALT:
18270+ argv[1] = "halt";
18271+ break;
18272+
18273+ case LINUX_REBOOT_CMD_POWER_OFF:
18274+ argv[1] = "poweroff";
18275+ break;
18276+
18277+ case LINUX_REBOOT_CMD_SW_SUSPEND:
18278+ argv[1] = "swsusp";
18279+ break;
18280+
18281+ case LINUX_REBOOT_CMD_OOM:
18282+ argv[1] = "oom";
18283+ break;
18284+
18285+ default:
18286+ vxi->vx_state &= ~VXS_HELPER;
18287+ return 0;
18288+ }
18289+
18290+ ret = do_vshelper(vshelper_path, argv, envp, 0);
18291+ vxi->vx_state &= ~VXS_HELPER;
18292+ __wakeup_vx_info(vxi);
18293+ return (ret) ? -EPERM : 0;
18294+}
18295+
18296+
18297+long vs_reboot(unsigned int cmd, void __user *arg)
18298+{
18299+ struct vx_info *vxi = current_vx_info();
18300+ long ret = 0;
18301+
18302+ vxdprintk(VXD_CBIT(misc, 5),
18303+ "vs_reboot(%p[#%d],%u)",
18304+ vxi, vxi ? vxi->vx_id : 0, cmd);
18305+
18306+ ret = vs_reboot_helper(vxi, cmd, arg);
18307+ if (ret)
18308+ return ret;
18309+
18310+ vxi->reboot_cmd = cmd;
18311+ if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18312+ switch (cmd) {
18313+ case LINUX_REBOOT_CMD_RESTART:
18314+ case LINUX_REBOOT_CMD_HALT:
18315+ case LINUX_REBOOT_CMD_POWER_OFF:
18316+ vx_info_kill(vxi, 0, SIGKILL);
18317+ vx_info_kill(vxi, 1, SIGKILL);
18318+ default:
18319+ break;
18320+ }
18321+ }
18322+ return 0;
18323+}
18324+
18325+long vs_oom_action(unsigned int cmd)
18326+{
18327+ struct vx_info *vxi = current_vx_info();
18328+ long ret = 0;
18329+
18330+ vxdprintk(VXD_CBIT(misc, 5),
18331+ "vs_oom_action(%p[#%d],%u)",
18332+ vxi, vxi ? vxi->vx_id : 0, cmd);
18333+
18334+ ret = vs_reboot_helper(vxi, cmd, NULL);
18335+ if (ret)
18336+ return ret;
18337+
18338+ vxi->reboot_cmd = cmd;
18339+ if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18340+ vx_info_kill(vxi, 0, SIGKILL);
18341+ vx_info_kill(vxi, 1, SIGKILL);
18342+ }
18343+ return 0;
18344+}
18345+
18346+/*
18347+ * argv [0] = vshelper_path;
18348+ * argv [1] = action: "startup", "shutdown"
18349+ * argv [2] = context identifier
18350+ *
18351+ * envp [*] = type-specific parameters
18352+ */
18353+
18354+long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18355+{
18356+ char id_buf[8], cmd_buf[16];
18357+ char *argv[] = {vshelper_path, NULL, id_buf, 0};
18358+ char *envp[] = {"HOME=/", "TERM=linux",
18359+ "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18360+
18361+ if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18362+ return 0;
18363+
18364+ snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18365+ snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18366+
18367+ switch (cmd) {
18368+ case VSC_STARTUP:
18369+ argv[1] = "startup";
18370+ break;
18371+ case VSC_SHUTDOWN:
18372+ argv[1] = "shutdown";
18373+ break;
18374+ default:
18375+ return 0;
18376+ }
18377+
18378+ return do_vshelper(vshelper_path, argv, envp, 1);
18379+}
18380+
18381+
18382+/*
18383+ * argv [0] = vshelper_path;
18384+ * argv [1] = action: "netup", "netdown"
18385+ * argv [2] = context identifier
18386+ *
18387+ * envp [*] = type-specific parameters
18388+ */
18389+
18390+long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18391+{
18392+ char id_buf[8], cmd_buf[16];
18393+ char *argv[] = {vshelper_path, NULL, id_buf, 0};
18394+ char *envp[] = {"HOME=/", "TERM=linux",
18395+ "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18396+
18397+ if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18398+ return 0;
18399+
18400+ snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18401+ snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18402+
18403+ switch (cmd) {
18404+ case VSC_NETUP:
18405+ argv[1] = "netup";
18406+ break;
18407+ case VSC_NETDOWN:
18408+ argv[1] = "netdown";
18409+ break;
18410+ default:
18411+ return 0;
18412+ }
18413+
18414+ return do_vshelper(vshelper_path, argv, envp, 1);
18415+}
18416+
18417diff -NurpP --minimal linux-3.6.6/kernel/vserver/history.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/history.c
18418--- linux-3.6.6/kernel/vserver/history.c 1970-01-01 01:00:00.000000000 +0100
18419+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/history.c 2012-10-04 18:47:00.000000000 +0200
18420@@ -0,0 +1,258 @@
18421+/*
18422+ * kernel/vserver/history.c
18423+ *
18424+ * Virtual Context History Backtrace
18425+ *
18426+ * Copyright (C) 2004-2007 Herbert Pötzl
18427+ *
18428+ * V0.01 basic structure
18429+ * V0.02 hash/unhash and trace
18430+ * V0.03 preemption fixes
18431+ *
18432+ */
18433+
18434+#include <linux/module.h>
18435+#include <asm/uaccess.h>
18436+
18437+#include <linux/vserver/context.h>
18438+#include <linux/vserver/debug.h>
18439+#include <linux/vserver/debug_cmd.h>
18440+#include <linux/vserver/history.h>
18441+
18442+
18443+#ifdef CONFIG_VSERVER_HISTORY
18444+#define VXH_SIZE CONFIG_VSERVER_HISTORY_SIZE
18445+#else
18446+#define VXH_SIZE 64
18447+#endif
18448+
18449+struct _vx_history {
18450+ unsigned int counter;
18451+
18452+ struct _vx_hist_entry entry[VXH_SIZE + 1];
18453+};
18454+
18455+
18456+DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18457+
18458+unsigned volatile int vxh_active = 1;
18459+
18460+static atomic_t sequence = ATOMIC_INIT(0);
18461+
18462+
18463+/* vxh_advance()
18464+
18465+ * requires disabled preemption */
18466+
18467+struct _vx_hist_entry *vxh_advance(void *loc)
18468+{
18469+ unsigned int cpu = smp_processor_id();
18470+ struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18471+ struct _vx_hist_entry *entry;
18472+ unsigned int index;
18473+
18474+ index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18475+ entry = &hist->entry[index];
18476+
18477+ entry->seq = atomic_inc_return(&sequence);
18478+ entry->loc = loc;
18479+ return entry;
18480+}
18481+
18482+EXPORT_SYMBOL_GPL(vxh_advance);
18483+
18484+
18485+#define VXH_LOC_FMTS "(#%04x,*%d):%p"
18486+
18487+#define VXH_LOC_ARGS(e) (e)->seq, cpu, (e)->loc
18488+
18489+
18490+#define VXH_VXI_FMTS "%p[#%d,%d.%d]"
18491+
18492+#define VXH_VXI_ARGS(e) (e)->vxi.ptr, \
18493+ (e)->vxi.ptr ? (e)->vxi.xid : 0, \
18494+ (e)->vxi.ptr ? (e)->vxi.usecnt : 0, \
18495+ (e)->vxi.ptr ? (e)->vxi.tasks : 0
18496+
18497+void vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18498+{
18499+ switch (e->type) {
18500+ case VXH_THROW_OOPS:
18501+ printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18502+ break;
18503+
18504+ case VXH_GET_VX_INFO:
18505+ case VXH_PUT_VX_INFO:
18506+ printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18507+ VXH_LOC_ARGS(e),
18508+ (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18509+ VXH_VXI_ARGS(e));
18510+ break;
18511+
18512+ case VXH_INIT_VX_INFO:
18513+ case VXH_SET_VX_INFO:
18514+ case VXH_CLR_VX_INFO:
18515+ printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18516+ VXH_LOC_ARGS(e),
18517+ (e->type == VXH_INIT_VX_INFO) ? "init" :
18518+ ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18519+ VXH_VXI_ARGS(e), e->sc.data);
18520+ break;
18521+
18522+ case VXH_CLAIM_VX_INFO:
18523+ case VXH_RELEASE_VX_INFO:
18524+ printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18525+ VXH_LOC_ARGS(e),
18526+ (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18527+ VXH_VXI_ARGS(e), e->sc.data);
18528+ break;
18529+
18530+ case VXH_ALLOC_VX_INFO:
18531+ case VXH_DEALLOC_VX_INFO:
18532+ printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18533+ VXH_LOC_ARGS(e),
18534+ (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18535+ VXH_VXI_ARGS(e));
18536+ break;
18537+
18538+ case VXH_HASH_VX_INFO:
18539+ case VXH_UNHASH_VX_INFO:
18540+ printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18541+ VXH_LOC_ARGS(e),
18542+ (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18543+ VXH_VXI_ARGS(e));
18544+ break;
18545+
18546+ case VXH_LOC_VX_INFO:
18547+ case VXH_LOOKUP_VX_INFO:
18548+ case VXH_CREATE_VX_INFO:
18549+ printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18550+ VXH_LOC_ARGS(e),
18551+ (e->type == VXH_CREATE_VX_INFO) ? "create" :
18552+ ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18553+ e->ll.arg, VXH_VXI_ARGS(e));
18554+ break;
18555+ }
18556+}
18557+
18558+static void __vxh_dump_history(void)
18559+{
18560+ unsigned int i, cpu;
18561+
18562+ printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18563+ atomic_read(&sequence), NR_CPUS);
18564+
18565+ for (i = 0; i < VXH_SIZE; i++) {
18566+ for_each_online_cpu(cpu) {
18567+ struct _vx_history *hist =
18568+ &per_cpu(vx_history_buffer, cpu);
18569+ unsigned int index = (hist->counter - i) % VXH_SIZE;
18570+ struct _vx_hist_entry *entry = &hist->entry[index];
18571+
18572+ vxh_dump_entry(entry, cpu);
18573+ }
18574+ }
18575+}
18576+
18577+void vxh_dump_history(void)
18578+{
18579+ vxh_active = 0;
18580+#ifdef CONFIG_SMP
18581+ local_irq_enable();
18582+ smp_send_stop();
18583+ local_irq_disable();
18584+#endif
18585+ __vxh_dump_history();
18586+}
18587+
18588+
18589+/* vserver syscall commands below here */
18590+
18591+
18592+int vc_dump_history(uint32_t id)
18593+{
18594+ vxh_active = 0;
18595+ __vxh_dump_history();
18596+ vxh_active = 1;
18597+
18598+ return 0;
18599+}
18600+
18601+
18602+int do_read_history(struct __user _vx_hist_entry *data,
18603+ int cpu, uint32_t *index, uint32_t *count)
18604+{
18605+ int pos, ret = 0;
18606+ struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18607+ int end = hist->counter;
18608+ int start = end - VXH_SIZE + 2;
18609+ int idx = *index;
18610+
18611+ /* special case: get current pos */
18612+ if (!*count) {
18613+ *index = end;
18614+ return 0;
18615+ }
18616+
18617+ /* have we lost some data? */
18618+ if (idx < start)
18619+ idx = start;
18620+
18621+ for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18622+ struct _vx_hist_entry *entry =
18623+ &hist->entry[idx % VXH_SIZE];
18624+
18625+ /* send entry to userspace */
18626+ ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18627+ if (ret)
18628+ break;
18629+ }
18630+ /* save new index and count */
18631+ *index = idx;
18632+ *count = pos;
18633+ return ret ? ret : (*index < end);
18634+}
18635+
18636+int vc_read_history(uint32_t id, void __user *data)
18637+{
18638+ struct vcmd_read_history_v0 vc_data;
18639+ int ret;
18640+
18641+ if (id >= NR_CPUS)
18642+ return -EINVAL;
18643+
18644+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18645+ return -EFAULT;
18646+
18647+ ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18648+ id, &vc_data.index, &vc_data.count);
18649+
18650+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18651+ return -EFAULT;
18652+ return ret;
18653+}
18654+
18655+#ifdef CONFIG_COMPAT
18656+
18657+int vc_read_history_x32(uint32_t id, void __user *data)
18658+{
18659+ struct vcmd_read_history_v0_x32 vc_data;
18660+ int ret;
18661+
18662+ if (id >= NR_CPUS)
18663+ return -EINVAL;
18664+
18665+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18666+ return -EFAULT;
18667+
18668+ ret = do_read_history((struct __user _vx_hist_entry *)
18669+ compat_ptr(vc_data.data_ptr),
18670+ id, &vc_data.index, &vc_data.count);
18671+
18672+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18673+ return -EFAULT;
18674+ return ret;
18675+}
18676+
18677+#endif /* CONFIG_COMPAT */
18678+
18679diff -NurpP --minimal linux-3.6.6/kernel/vserver/inet.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/inet.c
18680--- linux-3.6.6/kernel/vserver/inet.c 1970-01-01 01:00:00.000000000 +0100
18681+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/inet.c 2012-10-04 18:47:00.000000000 +0200
18682@@ -0,0 +1,226 @@
18683+
18684+#include <linux/in.h>
18685+#include <linux/inetdevice.h>
18686+#include <linux/export.h>
18687+#include <linux/vs_inet.h>
18688+#include <linux/vs_inet6.h>
18689+#include <linux/vserver/debug.h>
18690+#include <net/route.h>
18691+#include <net/addrconf.h>
18692+
18693+
18694+int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18695+{
18696+ int ret = 0;
18697+
18698+ if (!nxi1 || !nxi2 || nxi1 == nxi2)
18699+ ret = 1;
18700+ else {
18701+ struct nx_addr_v4 *ptr;
18702+
18703+ for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18704+ if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18705+ ret = 1;
18706+ break;
18707+ }
18708+ }
18709+ }
18710+
18711+ vxdprintk(VXD_CBIT(net, 2),
18712+ "nx_v4_addr_conflict(%p,%p): %d",
18713+ nxi1, nxi2, ret);
18714+
18715+ return ret;
18716+}
18717+
18718+
18719+#ifdef CONFIG_IPV6
18720+
18721+int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18722+{
18723+ int ret = 0;
18724+
18725+ if (!nxi1 || !nxi2 || nxi1 == nxi2)
18726+ ret = 1;
18727+ else {
18728+ struct nx_addr_v6 *ptr;
18729+
18730+ for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18731+ if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18732+ ret = 1;
18733+ break;
18734+ }
18735+ }
18736+ }
18737+
18738+ vxdprintk(VXD_CBIT(net, 2),
18739+ "nx_v6_addr_conflict(%p,%p): %d",
18740+ nxi1, nxi2, ret);
18741+
18742+ return ret;
18743+}
18744+
18745+#endif
18746+
18747+int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18748+{
18749+ struct in_device *in_dev;
18750+ struct in_ifaddr **ifap;
18751+ struct in_ifaddr *ifa;
18752+ int ret = 0;
18753+
18754+ if (!dev)
18755+ goto out;
18756+ in_dev = in_dev_get(dev);
18757+ if (!in_dev)
18758+ goto out;
18759+
18760+ for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18761+ ifap = &ifa->ifa_next) {
18762+ if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18763+ ret = 1;
18764+ break;
18765+ }
18766+ }
18767+ in_dev_put(in_dev);
18768+out:
18769+ return ret;
18770+}
18771+
18772+
18773+#ifdef CONFIG_IPV6
18774+
18775+int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18776+{
18777+ struct inet6_dev *in_dev;
18778+ struct inet6_ifaddr *ifa;
18779+ int ret = 0;
18780+
18781+ if (!dev)
18782+ goto out;
18783+ in_dev = in6_dev_get(dev);
18784+ if (!in_dev)
18785+ goto out;
18786+
18787+ // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18788+ list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18789+ if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18790+ ret = 1;
18791+ break;
18792+ }
18793+ }
18794+ in6_dev_put(in_dev);
18795+out:
18796+ return ret;
18797+}
18798+
18799+#endif
18800+
18801+int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18802+{
18803+ int ret = 1;
18804+
18805+ if (!nxi)
18806+ goto out;
18807+ if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18808+ goto out;
18809+#ifdef CONFIG_IPV6
18810+ ret = 2;
18811+ if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18812+ goto out;
18813+#endif
18814+ ret = 0;
18815+out:
18816+ vxdprintk(VXD_CBIT(net, 3),
18817+ "dev_in_nx_info(%p,%p[#%d]) = %d",
18818+ dev, nxi, nxi ? nxi->nx_id : 0, ret);
18819+ return ret;
18820+}
18821+
18822+struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18823+ struct flowi4 *fl4)
18824+{
18825+ struct rtable *rt;
18826+
18827+ if (!nxi)
18828+ return NULL;
18829+
18830+ /* FIXME: handle lback only case */
18831+ if (!NX_IPV4(nxi))
18832+ return ERR_PTR(-EPERM);
18833+
18834+ vxdprintk(VXD_CBIT(net, 4),
18835+ "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18836+ nxi, nxi ? nxi->nx_id : 0,
18837+ NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18838+
18839+ /* single IP is unconditional */
18840+ if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18841+ (fl4->saddr == INADDR_ANY))
18842+ fl4->saddr = nxi->v4.ip[0].s_addr;
18843+
18844+ if (fl4->saddr == INADDR_ANY) {
18845+ struct nx_addr_v4 *ptr;
18846+ __be32 found = 0;
18847+
18848+ rt = __ip_route_output_key(net, fl4);
18849+ if (!IS_ERR(rt)) {
18850+ found = fl4->saddr;
18851+ ip_rt_put(rt);
18852+ vxdprintk(VXD_CBIT(net, 4),
18853+ "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18854+ nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18855+ if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18856+ goto found;
18857+ }
18858+
18859+ for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18860+ __be32 primary = ptr->ip[0].s_addr;
18861+ __be32 mask = ptr->mask.s_addr;
18862+ __be32 neta = primary & mask;
18863+
18864+ vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18865+ NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18866+ nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18867+ NIPQUAD(mask), NIPQUAD(neta));
18868+ if ((found & mask) != neta)
18869+ continue;
18870+
18871+ fl4->saddr = primary;
18872+ rt = __ip_route_output_key(net, fl4);
18873+ vxdprintk(VXD_CBIT(net, 4),
18874+ "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18875+ nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18876+ if (!IS_ERR(rt)) {
18877+ found = fl4->saddr;
18878+ ip_rt_put(rt);
18879+ if (found == primary)
18880+ goto found;
18881+ }
18882+ }
18883+ /* still no source ip? */
18884+ found = ipv4_is_loopback(fl4->daddr)
18885+ ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18886+ found:
18887+ /* assign src ip to flow */
18888+ fl4->saddr = found;
18889+
18890+ } else {
18891+ if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18892+ return ERR_PTR(-EPERM);
18893+ }
18894+
18895+ if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18896+ if (ipv4_is_loopback(fl4->daddr))
18897+ fl4->daddr = nxi->v4_lback.s_addr;
18898+ if (ipv4_is_loopback(fl4->saddr))
18899+ fl4->saddr = nxi->v4_lback.s_addr;
18900+ } else if (ipv4_is_loopback(fl4->daddr) &&
18901+ !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18902+ return ERR_PTR(-EPERM);
18903+
18904+ return NULL;
18905+}
18906+
18907+EXPORT_SYMBOL_GPL(ip_v4_find_src);
18908+
18909diff -NurpP --minimal linux-3.6.6/kernel/vserver/init.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/init.c
18910--- linux-3.6.6/kernel/vserver/init.c 1970-01-01 01:00:00.000000000 +0100
18911+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/init.c 2012-10-04 18:47:00.000000000 +0200
18912@@ -0,0 +1,45 @@
18913+/*
18914+ * linux/kernel/init.c
18915+ *
18916+ * Virtual Server Init
18917+ *
18918+ * Copyright (C) 2004-2007 Herbert Pötzl
18919+ *
18920+ * V0.01 basic structure
18921+ *
18922+ */
18923+
18924+#include <linux/init.h>
18925+
18926+int vserver_register_sysctl(void);
18927+void vserver_unregister_sysctl(void);
18928+
18929+
18930+static int __init init_vserver(void)
18931+{
18932+ int ret = 0;
18933+
18934+#ifdef CONFIG_VSERVER_DEBUG
18935+ vserver_register_sysctl();
18936+#endif
18937+ return ret;
18938+}
18939+
18940+
18941+static void __exit exit_vserver(void)
18942+{
18943+
18944+#ifdef CONFIG_VSERVER_DEBUG
18945+ vserver_unregister_sysctl();
18946+#endif
18947+ return;
18948+}
18949+
18950+/* FIXME: GFP_ZONETYPES gone
18951+long vx_slab[GFP_ZONETYPES]; */
18952+long vx_area;
18953+
18954+
18955+module_init(init_vserver);
18956+module_exit(exit_vserver);
18957+
18958diff -NurpP --minimal linux-3.6.6/kernel/vserver/inode.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/inode.c
18959--- linux-3.6.6/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
18960+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/inode.c 2012-10-04 18:47:00.000000000 +0200
18961@@ -0,0 +1,437 @@
18962+/*
18963+ * linux/kernel/vserver/inode.c
18964+ *
18965+ * Virtual Server: File System Support
18966+ *
18967+ * Copyright (C) 2004-2007 Herbert Pötzl
18968+ *
18969+ * V0.01 separated from vcontext V0.05
18970+ * V0.02 moved to tag (instead of xid)
18971+ *
18972+ */
18973+
18974+#include <linux/tty.h>
18975+#include <linux/proc_fs.h>
18976+#include <linux/devpts_fs.h>
18977+#include <linux/fs.h>
18978+#include <linux/file.h>
18979+#include <linux/mount.h>
18980+#include <linux/parser.h>
18981+#include <linux/namei.h>
18982+#include <linux/vserver/inode.h>
18983+#include <linux/vserver/inode_cmd.h>
18984+#include <linux/vs_base.h>
18985+#include <linux/vs_tag.h>
18986+
18987+#include <asm/uaccess.h>
18988+
18989+
18990+static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18991+{
18992+ struct proc_dir_entry *entry;
18993+
18994+ if (!in || !in->i_sb)
18995+ return -ESRCH;
18996+
18997+ *flags = IATTR_TAG
18998+ | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18999+ | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19000+ | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19001+ | (IS_COW(in) ? IATTR_COW : 0);
19002+ *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19003+
19004+ if (S_ISDIR(in->i_mode))
19005+ *mask |= IATTR_BARRIER;
19006+
19007+ if (IS_TAGGED(in)) {
19008+ *tag = in->i_tag;
19009+ *mask |= IATTR_TAG;
19010+ }
19011+
19012+ switch (in->i_sb->s_magic) {
19013+ case PROC_SUPER_MAGIC:
19014+ entry = PROC_I(in)->pde;
19015+
19016+ /* check for specific inodes? */
19017+ if (entry)
19018+ *mask |= IATTR_FLAGS;
19019+ if (entry)
19020+ *flags |= (entry->vx_flags & IATTR_FLAGS);
19021+ else
19022+ *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19023+ break;
19024+
19025+ case DEVPTS_SUPER_MAGIC:
19026+ *tag = in->i_tag;
19027+ *mask |= IATTR_TAG;
19028+ break;
19029+
19030+ default:
19031+ break;
19032+ }
19033+ return 0;
19034+}
19035+
19036+int vc_get_iattr(void __user *data)
19037+{
19038+ struct path path;
19039+ struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19040+ int ret;
19041+
19042+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19043+ return -EFAULT;
19044+
19045+ ret = user_lpath(vc_data.name, &path);
19046+ if (!ret) {
19047+ ret = __vc_get_iattr(path.dentry->d_inode,
19048+ &vc_data.tag, &vc_data.flags, &vc_data.mask);
19049+ path_put(&path);
19050+ }
19051+ if (ret)
19052+ return ret;
19053+
19054+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19055+ ret = -EFAULT;
19056+ return ret;
19057+}
19058+
19059+#ifdef CONFIG_COMPAT
19060+
19061+int vc_get_iattr_x32(void __user *data)
19062+{
19063+ struct path path;
19064+ struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19065+ int ret;
19066+
19067+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19068+ return -EFAULT;
19069+
19070+ ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19071+ if (!ret) {
19072+ ret = __vc_get_iattr(path.dentry->d_inode,
19073+ &vc_data.tag, &vc_data.flags, &vc_data.mask);
19074+ path_put(&path);
19075+ }
19076+ if (ret)
19077+ return ret;
19078+
19079+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19080+ ret = -EFAULT;
19081+ return ret;
19082+}
19083+
19084+#endif /* CONFIG_COMPAT */
19085+
19086+
19087+int vc_fget_iattr(uint32_t fd, void __user *data)
19088+{
19089+ struct file *filp;
19090+ struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19091+ int ret;
19092+
19093+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19094+ return -EFAULT;
19095+
19096+ filp = fget(fd);
19097+ if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19098+ return -EBADF;
19099+
19100+ ret = __vc_get_iattr(filp->f_dentry->d_inode,
19101+ &vc_data.tag, &vc_data.flags, &vc_data.mask);
19102+
19103+ fput(filp);
19104+
19105+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19106+ ret = -EFAULT;
19107+ return ret;
19108+}
19109+
19110+
19111+static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19112+{
19113+ struct inode *in = de->d_inode;
19114+ int error = 0, is_proc = 0, has_tag = 0;
19115+ struct iattr attr = { 0 };
19116+
19117+ if (!in || !in->i_sb)
19118+ return -ESRCH;
19119+
19120+ is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19121+ if ((*mask & IATTR_FLAGS) && !is_proc)
19122+ return -EINVAL;
19123+
19124+ has_tag = IS_TAGGED(in) ||
19125+ (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19126+ if ((*mask & IATTR_TAG) && !has_tag)
19127+ return -EINVAL;
19128+
19129+ mutex_lock(&in->i_mutex);
19130+ if (*mask & IATTR_TAG) {
19131+ attr.ia_tag = *tag;
19132+ attr.ia_valid |= ATTR_TAG;
19133+ }
19134+
19135+ if (*mask & IATTR_FLAGS) {
19136+ struct proc_dir_entry *entry = PROC_I(in)->pde;
19137+ unsigned int iflags = PROC_I(in)->vx_flags;
19138+
19139+ iflags = (iflags & ~(*mask & IATTR_FLAGS))
19140+ | (*flags & IATTR_FLAGS);
19141+ PROC_I(in)->vx_flags = iflags;
19142+ if (entry)
19143+ entry->vx_flags = iflags;
19144+ }
19145+
19146+ if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19147+ IATTR_BARRIER | IATTR_COW)) {
19148+ int iflags = in->i_flags;
19149+ int vflags = in->i_vflags;
19150+
19151+ if (*mask & IATTR_IMMUTABLE) {
19152+ if (*flags & IATTR_IMMUTABLE)
19153+ iflags |= S_IMMUTABLE;
19154+ else
19155+ iflags &= ~S_IMMUTABLE;
19156+ }
19157+ if (*mask & IATTR_IXUNLINK) {
19158+ if (*flags & IATTR_IXUNLINK)
19159+ iflags |= S_IXUNLINK;
19160+ else
19161+ iflags &= ~S_IXUNLINK;
19162+ }
19163+ if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19164+ if (*flags & IATTR_BARRIER)
19165+ vflags |= V_BARRIER;
19166+ else
19167+ vflags &= ~V_BARRIER;
19168+ }
19169+ if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19170+ if (*flags & IATTR_COW)
19171+ vflags |= V_COW;
19172+ else
19173+ vflags &= ~V_COW;
19174+ }
19175+ if (in->i_op && in->i_op->sync_flags) {
19176+ error = in->i_op->sync_flags(in, iflags, vflags);
19177+ if (error)
19178+ goto out;
19179+ }
19180+ }
19181+
19182+ if (attr.ia_valid) {
19183+ if (in->i_op && in->i_op->setattr)
19184+ error = in->i_op->setattr(de, &attr);
19185+ else {
19186+ error = inode_change_ok(in, &attr);
19187+ if (!error) {
19188+ setattr_copy(in, &attr);
19189+ mark_inode_dirty(in);
19190+ }
19191+ }
19192+ }
19193+
19194+out:
19195+ mutex_unlock(&in->i_mutex);
19196+ return error;
19197+}
19198+
19199+int vc_set_iattr(void __user *data)
19200+{
19201+ struct path path;
19202+ struct vcmd_ctx_iattr_v1 vc_data;
19203+ int ret;
19204+
19205+ if (!capable(CAP_LINUX_IMMUTABLE))
19206+ return -EPERM;
19207+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19208+ return -EFAULT;
19209+
19210+ ret = user_lpath(vc_data.name, &path);
19211+ if (!ret) {
19212+ ret = __vc_set_iattr(path.dentry,
19213+ &vc_data.tag, &vc_data.flags, &vc_data.mask);
19214+ path_put(&path);
19215+ }
19216+
19217+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19218+ ret = -EFAULT;
19219+ return ret;
19220+}
19221+
19222+#ifdef CONFIG_COMPAT
19223+
19224+int vc_set_iattr_x32(void __user *data)
19225+{
19226+ struct path path;
19227+ struct vcmd_ctx_iattr_v1_x32 vc_data;
19228+ int ret;
19229+
19230+ if (!capable(CAP_LINUX_IMMUTABLE))
19231+ return -EPERM;
19232+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19233+ return -EFAULT;
19234+
19235+ ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19236+ if (!ret) {
19237+ ret = __vc_set_iattr(path.dentry,
19238+ &vc_data.tag, &vc_data.flags, &vc_data.mask);
19239+ path_put(&path);
19240+ }
19241+
19242+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19243+ ret = -EFAULT;
19244+ return ret;
19245+}
19246+
19247+#endif /* CONFIG_COMPAT */
19248+
19249+int vc_fset_iattr(uint32_t fd, void __user *data)
19250+{
19251+ struct file *filp;
19252+ struct vcmd_ctx_fiattr_v0 vc_data;
19253+ int ret;
19254+
19255+ if (!capable(CAP_LINUX_IMMUTABLE))
19256+ return -EPERM;
19257+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19258+ return -EFAULT;
19259+
19260+ filp = fget(fd);
19261+ if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19262+ return -EBADF;
19263+
19264+ ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19265+ &vc_data.flags, &vc_data.mask);
19266+
19267+ fput(filp);
19268+
19269+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19270+ return -EFAULT;
19271+ return ret;
19272+}
19273+
19274+
19275+enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19276+
19277+static match_table_t tokens = {
19278+ {Opt_notagcheck, "notagcheck"},
19279+#ifdef CONFIG_PROPAGATE
19280+ {Opt_notag, "notag"},
19281+ {Opt_tag, "tag"},
19282+ {Opt_tagid, "tagid=%u"},
19283+#endif
19284+ {Opt_err, NULL}
19285+};
19286+
19287+
19288+static void __dx_parse_remove(char *string, char *opt)
19289+{
19290+ char *p = strstr(string, opt);
19291+ char *q = p;
19292+
19293+ if (p) {
19294+ while (*q != '\0' && *q != ',')
19295+ q++;
19296+ while (*q)
19297+ *p++ = *q++;
19298+ while (*p)
19299+ *p++ = '\0';
19300+ }
19301+}
19302+
19303+int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19304+ unsigned long *flags)
19305+{
19306+ int set = 0;
19307+ substring_t args[MAX_OPT_ARGS];
19308+ int token;
19309+ char *s, *p, *opts;
19310+#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19311+ int option = 0;
19312+#endif
19313+
19314+ if (!string)
19315+ return 0;
19316+ s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19317+ if (!s)
19318+ return 0;
19319+
19320+ opts = s;
19321+ while ((p = strsep(&opts, ",")) != NULL) {
19322+ token = match_token(p, tokens, args);
19323+
19324+ switch (token) {
19325+#ifdef CONFIG_PROPAGATE
19326+ case Opt_tag:
19327+ if (tag)
19328+ *tag = 0;
19329+ if (remove)
19330+ __dx_parse_remove(s, "tag");
19331+ *mnt_flags |= MNT_TAGID;
19332+ set |= MNT_TAGID;
19333+ break;
19334+ case Opt_notag:
19335+ if (remove)
19336+ __dx_parse_remove(s, "notag");
19337+ *mnt_flags |= MNT_NOTAG;
19338+ set |= MNT_NOTAG;
19339+ break;
19340+ case Opt_tagid:
19341+ if (tag && !match_int(args, &option))
19342+ *tag = option;
19343+ if (remove)
19344+ __dx_parse_remove(s, "tagid");
19345+ *mnt_flags |= MNT_TAGID;
19346+ set |= MNT_TAGID;
19347+ break;
19348+#endif /* CONFIG_PROPAGATE */
19349+ case Opt_notagcheck:
19350+ if (remove)
19351+ __dx_parse_remove(s, "notagcheck");
19352+ *flags |= MS_NOTAGCHECK;
19353+ set |= MS_NOTAGCHECK;
19354+ break;
19355+ }
19356+ vxdprintk(VXD_CBIT(tag, 7),
19357+ "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19358+ p, token, option);
19359+ }
19360+ if (set)
19361+ strcpy(string, s);
19362+ kfree(s);
19363+ return set;
19364+}
19365+
19366+#ifdef CONFIG_PROPAGATE
19367+
19368+void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19369+{
19370+ tag_t new_tag = 0;
19371+ struct vfsmount *mnt;
19372+ int propagate;
19373+
19374+ if (!nd)
19375+ return;
19376+ mnt = nd->path.mnt;
19377+ if (!mnt)
19378+ return;
19379+
19380+ propagate = (mnt->mnt_flags & MNT_TAGID);
19381+ if (propagate)
19382+ new_tag = mnt->mnt_tag;
19383+
19384+ vxdprintk(VXD_CBIT(tag, 7),
19385+ "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19386+ inode, inode->i_ino, inode->i_tag,
19387+ new_tag, (propagate) ? 1 : 0);
19388+
19389+ if (propagate)
19390+ inode->i_tag = new_tag;
19391+}
19392+
19393+#include <linux/module.h>
19394+
19395+EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19396+
19397+#endif /* CONFIG_PROPAGATE */
19398+
19399diff -NurpP --minimal linux-3.6.6/kernel/vserver/limit.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/limit.c
19400--- linux-3.6.6/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
19401+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/limit.c 2012-10-04 18:47:00.000000000 +0200
19402@@ -0,0 +1,345 @@
19403+/*
19404+ * linux/kernel/vserver/limit.c
19405+ *
19406+ * Virtual Server: Context Limits
19407+ *
19408+ * Copyright (C) 2004-2010 Herbert Pötzl
19409+ *
19410+ * V0.01 broken out from vcontext V0.05
19411+ * V0.02 changed vcmds to vxi arg
19412+ * V0.03 added memory cgroup support
19413+ *
19414+ */
19415+
19416+#include <linux/sched.h>
19417+#include <linux/module.h>
19418+#include <linux/memcontrol.h>
19419+#include <linux/res_counter.h>
19420+#include <linux/vs_limit.h>
19421+#include <linux/vserver/limit.h>
19422+#include <linux/vserver/limit_cmd.h>
19423+
19424+#include <asm/uaccess.h>
19425+
19426+
19427+const char *vlimit_name[NUM_LIMITS] = {
19428+ [RLIMIT_CPU] = "CPU",
19429+ [RLIMIT_NPROC] = "NPROC",
19430+ [RLIMIT_NOFILE] = "NOFILE",
19431+ [RLIMIT_LOCKS] = "LOCKS",
19432+ [RLIMIT_SIGPENDING] = "SIGP",
19433+ [RLIMIT_MSGQUEUE] = "MSGQ",
19434+
19435+ [VLIMIT_NSOCK] = "NSOCK",
19436+ [VLIMIT_OPENFD] = "OPENFD",
19437+ [VLIMIT_SHMEM] = "SHMEM",
19438+ [VLIMIT_DENTRY] = "DENTRY",
19439+};
19440+
19441+EXPORT_SYMBOL_GPL(vlimit_name);
19442+
19443+#define MASK_ENTRY(x) (1 << (x))
19444+
19445+const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19446+ /* minimum */
19447+ 0
19448+ , /* softlimit */
19449+ 0
19450+ , /* maximum */
19451+ MASK_ENTRY( RLIMIT_NPROC ) |
19452+ MASK_ENTRY( RLIMIT_NOFILE ) |
19453+ MASK_ENTRY( RLIMIT_LOCKS ) |
19454+ MASK_ENTRY( RLIMIT_MSGQUEUE ) |
19455+
19456+ MASK_ENTRY( VLIMIT_NSOCK ) |
19457+ MASK_ENTRY( VLIMIT_OPENFD ) |
19458+ MASK_ENTRY( VLIMIT_SHMEM ) |
19459+ MASK_ENTRY( VLIMIT_DENTRY ) |
19460+ 0
19461+};
19462+ /* accounting only */
19463+uint32_t account_mask =
19464+ MASK_ENTRY( VLIMIT_SEMARY ) |
19465+ MASK_ENTRY( VLIMIT_NSEMS ) |
19466+ MASK_ENTRY( VLIMIT_MAPPED ) |
19467+ 0;
19468+
19469+
19470+static int is_valid_vlimit(int id)
19471+{
19472+ uint32_t mask = vlimit_mask.minimum |
19473+ vlimit_mask.softlimit | vlimit_mask.maximum;
19474+ return mask & (1 << id);
19475+}
19476+
19477+static int is_accounted_vlimit(int id)
19478+{
19479+ if (is_valid_vlimit(id))
19480+ return 1;
19481+ return account_mask & (1 << id);
19482+}
19483+
19484+
19485+static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19486+{
19487+ rlim_t limit = __rlim_soft(&vxi->limit, id);
19488+ return VX_VLIM(limit);
19489+}
19490+
19491+static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19492+{
19493+ rlim_t limit = __rlim_hard(&vxi->limit, id);
19494+ return VX_VLIM(limit);
19495+}
19496+
19497+static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19498+ uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19499+{
19500+ if (!is_valid_vlimit(id))
19501+ return -EINVAL;
19502+
19503+ if (minimum)
19504+ *minimum = CRLIM_UNSET;
19505+ if (softlimit)
19506+ *softlimit = vc_get_soft(vxi, id);
19507+ if (maximum)
19508+ *maximum = vc_get_hard(vxi, id);
19509+ return 0;
19510+}
19511+
19512+int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19513+{
19514+ struct vcmd_ctx_rlimit_v0 vc_data;
19515+ int ret;
19516+
19517+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19518+ return -EFAULT;
19519+
19520+ ret = do_get_rlimit(vxi, vc_data.id,
19521+ &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19522+ if (ret)
19523+ return ret;
19524+
19525+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19526+ return -EFAULT;
19527+ return 0;
19528+}
19529+
19530+static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19531+ uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19532+{
19533+ if (!is_valid_vlimit(id))
19534+ return -EINVAL;
19535+
19536+ if (maximum != CRLIM_KEEP)
19537+ __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19538+ if (softlimit != CRLIM_KEEP)
19539+ __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19540+
19541+ /* clamp soft limit */
19542+ if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19543+ __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19544+
19545+ return 0;
19546+}
19547+
19548+int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19549+{
19550+ struct vcmd_ctx_rlimit_v0 vc_data;
19551+
19552+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19553+ return -EFAULT;
19554+
19555+ return do_set_rlimit(vxi, vc_data.id,
19556+ vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19557+}
19558+
19559+#ifdef CONFIG_IA32_EMULATION
19560+
19561+int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19562+{
19563+ struct vcmd_ctx_rlimit_v0_x32 vc_data;
19564+
19565+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19566+ return -EFAULT;
19567+
19568+ return do_set_rlimit(vxi, vc_data.id,
19569+ vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19570+}
19571+
19572+int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19573+{
19574+ struct vcmd_ctx_rlimit_v0_x32 vc_data;
19575+ int ret;
19576+
19577+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19578+ return -EFAULT;
19579+
19580+ ret = do_get_rlimit(vxi, vc_data.id,
19581+ &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19582+ if (ret)
19583+ return ret;
19584+
19585+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19586+ return -EFAULT;
19587+ return 0;
19588+}
19589+
19590+#endif /* CONFIG_IA32_EMULATION */
19591+
19592+
19593+int vc_get_rlimit_mask(uint32_t id, void __user *data)
19594+{
19595+ if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19596+ return -EFAULT;
19597+ return 0;
19598+}
19599+
19600+
19601+static inline void vx_reset_hits(struct _vx_limit *limit)
19602+{
19603+ int lim;
19604+
19605+ for (lim = 0; lim < NUM_LIMITS; lim++) {
19606+ atomic_set(&__rlim_lhit(limit, lim), 0);
19607+ }
19608+}
19609+
19610+int vc_reset_hits(struct vx_info *vxi, void __user *data)
19611+{
19612+ vx_reset_hits(&vxi->limit);
19613+ return 0;
19614+}
19615+
19616+static inline void vx_reset_minmax(struct _vx_limit *limit)
19617+{
19618+ rlim_t value;
19619+ int lim;
19620+
19621+ for (lim = 0; lim < NUM_LIMITS; lim++) {
19622+ value = __rlim_get(limit, lim);
19623+ __rlim_rmax(limit, lim) = value;
19624+ __rlim_rmin(limit, lim) = value;
19625+ }
19626+}
19627+
19628+int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19629+{
19630+ vx_reset_minmax(&vxi->limit);
19631+ return 0;
19632+}
19633+
19634+
19635+int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19636+{
19637+ struct vcmd_rlimit_stat_v0 vc_data;
19638+ struct _vx_limit *limit = &vxi->limit;
19639+ int id;
19640+
19641+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19642+ return -EFAULT;
19643+
19644+ id = vc_data.id;
19645+ if (!is_accounted_vlimit(id))
19646+ return -EINVAL;
19647+
19648+ vx_limit_fixup(limit, id);
19649+ vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19650+ vc_data.value = __rlim_get(limit, id);
19651+ vc_data.minimum = __rlim_rmin(limit, id);
19652+ vc_data.maximum = __rlim_rmax(limit, id);
19653+
19654+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19655+ return -EFAULT;
19656+ return 0;
19657+}
19658+
19659+
19660+void vx_vsi_meminfo(struct sysinfo *val)
19661+{
19662+#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19663+ struct mem_cgroup *mcg;
19664+ u64 res_limit, res_usage;
19665+
19666+ rcu_read_lock();
19667+ mcg = mem_cgroup_from_task(current);
19668+ rcu_read_unlock();
19669+ if (!mcg)
19670+ goto out;
19671+
19672+ res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19673+ res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19674+
19675+ if (res_limit != RESOURCE_MAX)
19676+ val->totalram = (res_limit >> PAGE_SHIFT);
19677+ val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19678+ val->bufferram = 0;
19679+ val->totalhigh = 0;
19680+ val->freehigh = 0;
19681+out:
19682+#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19683+ return;
19684+}
19685+
19686+void vx_vsi_swapinfo(struct sysinfo *val)
19687+{
19688+#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19689+#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
19690+ struct mem_cgroup *mcg;
19691+ u64 res_limit, res_usage, memsw_limit, memsw_usage;
19692+ s64 swap_limit, swap_usage;
19693+
19694+ rcu_read_lock();
19695+ mcg = mem_cgroup_from_task(current);
19696+ rcu_read_unlock();
19697+ if (!mcg)
19698+ goto out;
19699+
19700+ res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19701+ res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19702+ memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19703+ memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19704+
19705+ /* memory unlimited */
19706+ if (res_limit == RESOURCE_MAX)
19707+ goto out;
19708+
19709+ swap_limit = memsw_limit - res_limit;
19710+ /* we have a swap limit? */
19711+ if (memsw_limit != RESOURCE_MAX)
19712+ val->totalswap = swap_limit >> PAGE_SHIFT;
19713+
19714+ /* calculate swap part */
19715+ swap_usage = (memsw_usage > res_usage) ?
19716+ memsw_usage - res_usage : 0;
19717+
19718+ /* total shown minus usage gives free swap */
19719+ val->freeswap = (swap_usage < swap_limit) ?
19720+ val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19721+out:
19722+#else /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
19723+ val->totalswap = 0;
19724+ val->freeswap = 0;
19725+#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
19726+#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19727+ return;
19728+}
19729+
19730+long vx_vsi_cached(struct sysinfo *val)
19731+{
19732+ long cache = 0;
19733+#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19734+ struct mem_cgroup *mcg;
19735+
19736+ rcu_read_lock();
19737+ mcg = mem_cgroup_from_task(current);
19738+ rcu_read_unlock();
19739+ if (!mcg)
19740+ goto out;
19741+
19742+ cache = mem_cgroup_stat_read_cache(mcg);
19743+out:
19744+#endif
19745+ return cache;
19746+}
19747+
19748diff -NurpP --minimal linux-3.6.6/kernel/vserver/limit_init.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/limit_init.h
19749--- linux-3.6.6/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
19750+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/limit_init.h 2012-10-04 18:47:00.000000000 +0200
19751@@ -0,0 +1,31 @@
19752+
19753+
19754+static inline void vx_info_init_limit(struct _vx_limit *limit)
19755+{
19756+ int lim;
19757+
19758+ for (lim = 0; lim < NUM_LIMITS; lim++) {
19759+ __rlim_soft(limit, lim) = RLIM_INFINITY;
19760+ __rlim_hard(limit, lim) = RLIM_INFINITY;
19761+ __rlim_set(limit, lim, 0);
19762+ atomic_set(&__rlim_lhit(limit, lim), 0);
19763+ __rlim_rmin(limit, lim) = 0;
19764+ __rlim_rmax(limit, lim) = 0;
19765+ }
19766+}
19767+
19768+static inline void vx_info_exit_limit(struct _vx_limit *limit)
19769+{
19770+ rlim_t value;
19771+ int lim;
19772+
19773+ for (lim = 0; lim < NUM_LIMITS; lim++) {
19774+ if ((1 << lim) & VLIM_NOCHECK)
19775+ continue;
19776+ value = __rlim_get(limit, lim);
19777+ vxwprintk_xid(value,
19778+ "!!! limit: %p[%s,%d] = %ld on exit.",
19779+ limit, vlimit_name[lim], lim, (long)value);
19780+ }
19781+}
19782+
19783diff -NurpP --minimal linux-3.6.6/kernel/vserver/limit_proc.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/limit_proc.h
19784--- linux-3.6.6/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
19785+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/limit_proc.h 2012-10-04 18:47:00.000000000 +0200
19786@@ -0,0 +1,57 @@
19787+#ifndef _VX_LIMIT_PROC_H
19788+#define _VX_LIMIT_PROC_H
19789+
19790+#include <linux/vserver/limit_int.h>
19791+
19792+
19793+#define VX_LIMIT_FMT ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19794+#define VX_LIMIT_TOP \
19795+ "Limit\t current\t min/max\t\t soft/hard\t\thits\n"
19796+
19797+#define VX_LIMIT_ARG(r) \
19798+ (unsigned long)__rlim_get(limit, r), \
19799+ (unsigned long)__rlim_rmin(limit, r), \
19800+ (unsigned long)__rlim_rmax(limit, r), \
19801+ VX_VLIM(__rlim_soft(limit, r)), \
19802+ VX_VLIM(__rlim_hard(limit, r)), \
19803+ atomic_read(&__rlim_lhit(limit, r))
19804+
19805+static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19806+{
19807+ vx_limit_fixup(limit, -1);
19808+ return sprintf(buffer, VX_LIMIT_TOP
19809+ "PROC" VX_LIMIT_FMT
19810+ "VM" VX_LIMIT_FMT
19811+ "VML" VX_LIMIT_FMT
19812+ "RSS" VX_LIMIT_FMT
19813+ "ANON" VX_LIMIT_FMT
19814+ "RMAP" VX_LIMIT_FMT
19815+ "FILES" VX_LIMIT_FMT
19816+ "OFD" VX_LIMIT_FMT
19817+ "LOCKS" VX_LIMIT_FMT
19818+ "SOCK" VX_LIMIT_FMT
19819+ "MSGQ" VX_LIMIT_FMT
19820+ "SHM" VX_LIMIT_FMT
19821+ "SEMA" VX_LIMIT_FMT
19822+ "SEMS" VX_LIMIT_FMT
19823+ "DENT" VX_LIMIT_FMT,
19824+ VX_LIMIT_ARG(RLIMIT_NPROC),
19825+ VX_LIMIT_ARG(RLIMIT_AS),
19826+ VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19827+ VX_LIMIT_ARG(RLIMIT_RSS),
19828+ VX_LIMIT_ARG(VLIMIT_ANON),
19829+ VX_LIMIT_ARG(VLIMIT_MAPPED),
19830+ VX_LIMIT_ARG(RLIMIT_NOFILE),
19831+ VX_LIMIT_ARG(VLIMIT_OPENFD),
19832+ VX_LIMIT_ARG(RLIMIT_LOCKS),
19833+ VX_LIMIT_ARG(VLIMIT_NSOCK),
19834+ VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19835+ VX_LIMIT_ARG(VLIMIT_SHMEM),
19836+ VX_LIMIT_ARG(VLIMIT_SEMARY),
19837+ VX_LIMIT_ARG(VLIMIT_NSEMS),
19838+ VX_LIMIT_ARG(VLIMIT_DENTRY));
19839+}
19840+
19841+#endif /* _VX_LIMIT_PROC_H */
19842+
19843+
19844diff -NurpP --minimal linux-3.6.6/kernel/vserver/network.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/network.c
19845--- linux-3.6.6/kernel/vserver/network.c 1970-01-01 01:00:00.000000000 +0100
19846+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/network.c 2012-10-04 18:47:00.000000000 +0200
19847@@ -0,0 +1,912 @@
19848+/*
19849+ * linux/kernel/vserver/network.c
19850+ *
19851+ * Virtual Server: Network Support
19852+ *
19853+ * Copyright (C) 2003-2007 Herbert Pötzl
19854+ *
19855+ * V0.01 broken out from vcontext V0.05
19856+ * V0.02 cleaned up implementation
19857+ * V0.03 added equiv nx commands
19858+ * V0.04 switch to RCU based hash
19859+ * V0.05 and back to locking again
19860+ * V0.06 changed vcmds to nxi arg
19861+ * V0.07 have __create claim() the nxi
19862+ *
19863+ */
19864+
19865+#include <linux/err.h>
19866+#include <linux/slab.h>
19867+#include <linux/rcupdate.h>
19868+
19869+#include <linux/vs_network.h>
19870+#include <linux/vs_pid.h>
19871+#include <linux/vserver/network_cmd.h>
19872+
19873+
19874+atomic_t nx_global_ctotal = ATOMIC_INIT(0);
19875+atomic_t nx_global_cactive = ATOMIC_INIT(0);
19876+
19877+static struct kmem_cache *nx_addr_v4_cachep = NULL;
19878+static struct kmem_cache *nx_addr_v6_cachep = NULL;
19879+
19880+
19881+static int __init init_network(void)
19882+{
19883+ nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19884+ sizeof(struct nx_addr_v4), 0,
19885+ SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19886+ nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19887+ sizeof(struct nx_addr_v6), 0,
19888+ SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19889+ return 0;
19890+}
19891+
19892+
19893+/* __alloc_nx_addr_v4() */
19894+
19895+static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19896+{
19897+ struct nx_addr_v4 *nxa = kmem_cache_alloc(
19898+ nx_addr_v4_cachep, GFP_KERNEL);
19899+
19900+ if (!IS_ERR(nxa))
19901+ memset(nxa, 0, sizeof(*nxa));
19902+ return nxa;
19903+}
19904+
19905+/* __dealloc_nx_addr_v4() */
19906+
19907+static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19908+{
19909+ kmem_cache_free(nx_addr_v4_cachep, nxa);
19910+}
19911+
19912+/* __dealloc_nx_addr_v4_all() */
19913+
19914+static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19915+{
19916+ while (nxa) {
19917+ struct nx_addr_v4 *next = nxa->next;
19918+
19919+ __dealloc_nx_addr_v4(nxa);
19920+ nxa = next;
19921+ }
19922+}
19923+
19924+
19925+#ifdef CONFIG_IPV6
19926+
19927+/* __alloc_nx_addr_v6() */
19928+
19929+static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19930+{
19931+ struct nx_addr_v6 *nxa = kmem_cache_alloc(
19932+ nx_addr_v6_cachep, GFP_KERNEL);
19933+
19934+ if (!IS_ERR(nxa))
19935+ memset(nxa, 0, sizeof(*nxa));
19936+ return nxa;
19937+}
19938+
19939+/* __dealloc_nx_addr_v6() */
19940+
19941+static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19942+{
19943+ kmem_cache_free(nx_addr_v6_cachep, nxa);
19944+}
19945+
19946+/* __dealloc_nx_addr_v6_all() */
19947+
19948+static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19949+{
19950+ while (nxa) {
19951+ struct nx_addr_v6 *next = nxa->next;
19952+
19953+ __dealloc_nx_addr_v6(nxa);
19954+ nxa = next;
19955+ }
19956+}
19957+
19958+#endif /* CONFIG_IPV6 */
19959+
19960+/* __alloc_nx_info()
19961+
19962+ * allocate an initialized nx_info struct
19963+ * doesn't make it visible (hash) */
19964+
19965+static struct nx_info *__alloc_nx_info(nid_t nid)
19966+{
19967+ struct nx_info *new = NULL;
19968+
19969+ vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19970+
19971+ /* would this benefit from a slab cache? */
19972+ new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19973+ if (!new)
19974+ return 0;
19975+
19976+ memset(new, 0, sizeof(struct nx_info));
19977+ new->nx_id = nid;
19978+ INIT_HLIST_NODE(&new->nx_hlist);
19979+ atomic_set(&new->nx_usecnt, 0);
19980+ atomic_set(&new->nx_tasks, 0);
19981+ new->nx_state = 0;
19982+
19983+ new->nx_flags = NXF_INIT_SET;
19984+
19985+ /* rest of init goes here */
19986+
19987+ new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19988+ new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19989+
19990+ vxdprintk(VXD_CBIT(nid, 0),
19991+ "alloc_nx_info(%d) = %p", nid, new);
19992+ atomic_inc(&nx_global_ctotal);
19993+ return new;
19994+}
19995+
19996+/* __dealloc_nx_info()
19997+
19998+ * final disposal of nx_info */
19999+
20000+static void __dealloc_nx_info(struct nx_info *nxi)
20001+{
20002+ vxdprintk(VXD_CBIT(nid, 0),
20003+ "dealloc_nx_info(%p)", nxi);
20004+
20005+ nxi->nx_hlist.next = LIST_POISON1;
20006+ nxi->nx_id = -1;
20007+
20008+ BUG_ON(atomic_read(&nxi->nx_usecnt));
20009+ BUG_ON(atomic_read(&nxi->nx_tasks));
20010+
20011+ __dealloc_nx_addr_v4_all(nxi->v4.next);
20012+
20013+ nxi->nx_state |= NXS_RELEASED;
20014+ kfree(nxi);
20015+ atomic_dec(&nx_global_ctotal);
20016+}
20017+
20018+static void __shutdown_nx_info(struct nx_info *nxi)
20019+{
20020+ nxi->nx_state |= NXS_SHUTDOWN;
20021+ vs_net_change(nxi, VSC_NETDOWN);
20022+}
20023+
20024+/* exported stuff */
20025+
20026+void free_nx_info(struct nx_info *nxi)
20027+{
20028+ /* context shutdown is mandatory */
20029+ BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20030+
20031+ /* context must not be hashed */
20032+ BUG_ON(nxi->nx_state & NXS_HASHED);
20033+
20034+ BUG_ON(atomic_read(&nxi->nx_usecnt));
20035+ BUG_ON(atomic_read(&nxi->nx_tasks));
20036+
20037+ __dealloc_nx_info(nxi);
20038+}
20039+
20040+
20041+void __nx_set_lback(struct nx_info *nxi)
20042+{
20043+ int nid = nxi->nx_id;
20044+ __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20045+
20046+ nxi->v4_lback.s_addr = lback;
20047+}
20048+
20049+extern int __nx_inet_add_lback(__be32 addr);
20050+extern int __nx_inet_del_lback(__be32 addr);
20051+
20052+
20053+/* hash table for nx_info hash */
20054+
20055+#define NX_HASH_SIZE 13
20056+
20057+struct hlist_head nx_info_hash[NX_HASH_SIZE];
20058+
20059+static DEFINE_SPINLOCK(nx_info_hash_lock);
20060+
20061+
20062+static inline unsigned int __hashval(nid_t nid)
20063+{
20064+ return (nid % NX_HASH_SIZE);
20065+}
20066+
20067+
20068+
20069+/* __hash_nx_info()
20070+
20071+ * add the nxi to the global hash table
20072+ * requires the hash_lock to be held */
20073+
20074+static inline void __hash_nx_info(struct nx_info *nxi)
20075+{
20076+ struct hlist_head *head;
20077+
20078+ vxd_assert_lock(&nx_info_hash_lock);
20079+ vxdprintk(VXD_CBIT(nid, 4),
20080+ "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20081+
20082+ /* context must not be hashed */
20083+ BUG_ON(nx_info_state(nxi, NXS_HASHED));
20084+
20085+ nxi->nx_state |= NXS_HASHED;
20086+ head = &nx_info_hash[__hashval(nxi->nx_id)];
20087+ hlist_add_head(&nxi->nx_hlist, head);
20088+ atomic_inc(&nx_global_cactive);
20089+}
20090+
20091+/* __unhash_nx_info()
20092+
20093+ * remove the nxi from the global hash table
20094+ * requires the hash_lock to be held */
20095+
20096+static inline void __unhash_nx_info(struct nx_info *nxi)
20097+{
20098+ vxd_assert_lock(&nx_info_hash_lock);
20099+ vxdprintk(VXD_CBIT(nid, 4),
20100+ "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20101+ atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20102+
20103+ /* context must be hashed */
20104+ BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20105+ /* but without tasks */
20106+ BUG_ON(atomic_read(&nxi->nx_tasks));
20107+
20108+ nxi->nx_state &= ~NXS_HASHED;
20109+ hlist_del(&nxi->nx_hlist);
20110+ atomic_dec(&nx_global_cactive);
20111+}
20112+
20113+
20114+/* __lookup_nx_info()
20115+
20116+ * requires the hash_lock to be held
20117+ * doesn't increment the nx_refcnt */
20118+
20119+static inline struct nx_info *__lookup_nx_info(nid_t nid)
20120+{
20121+ struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20122+ struct hlist_node *pos;
20123+ struct nx_info *nxi;
20124+
20125+ vxd_assert_lock(&nx_info_hash_lock);
20126+ hlist_for_each(pos, head) {
20127+ nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20128+
20129+ if (nxi->nx_id == nid)
20130+ goto found;
20131+ }
20132+ nxi = NULL;
20133+found:
20134+ vxdprintk(VXD_CBIT(nid, 0),
20135+ "__lookup_nx_info(#%u): %p[#%u]",
20136+ nid, nxi, nxi ? nxi->nx_id : 0);
20137+ return nxi;
20138+}
20139+
20140+
20141+/* __create_nx_info()
20142+
20143+ * create the requested context
20144+ * get(), claim() and hash it */
20145+
20146+static struct nx_info *__create_nx_info(int id)
20147+{
20148+ struct nx_info *new, *nxi = NULL;
20149+
20150+ vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20151+
20152+ if (!(new = __alloc_nx_info(id)))
20153+ return ERR_PTR(-ENOMEM);
20154+
20155+ /* required to make dynamic xids unique */
20156+ spin_lock(&nx_info_hash_lock);
20157+
20158+ /* static context requested */
20159+ if ((nxi = __lookup_nx_info(id))) {
20160+ vxdprintk(VXD_CBIT(nid, 0),
20161+ "create_nx_info(%d) = %p (already there)", id, nxi);
20162+ if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20163+ nxi = ERR_PTR(-EBUSY);
20164+ else
20165+ nxi = ERR_PTR(-EEXIST);
20166+ goto out_unlock;
20167+ }
20168+ /* new context */
20169+ vxdprintk(VXD_CBIT(nid, 0),
20170+ "create_nx_info(%d) = %p (new)", id, new);
20171+ claim_nx_info(new, NULL);
20172+ __nx_set_lback(new);
20173+ __hash_nx_info(get_nx_info(new));
20174+ nxi = new, new = NULL;
20175+
20176+out_unlock:
20177+ spin_unlock(&nx_info_hash_lock);
20178+ if (new)
20179+ __dealloc_nx_info(new);
20180+ return nxi;
20181+}
20182+
20183+
20184+
20185+/* exported stuff */
20186+
20187+
20188+void unhash_nx_info(struct nx_info *nxi)
20189+{
20190+ __shutdown_nx_info(nxi);
20191+ spin_lock(&nx_info_hash_lock);
20192+ __unhash_nx_info(nxi);
20193+ spin_unlock(&nx_info_hash_lock);
20194+}
20195+
20196+/* lookup_nx_info()
20197+
20198+ * search for a nx_info and get() it
20199+ * negative id means current */
20200+
20201+struct nx_info *lookup_nx_info(int id)
20202+{
20203+ struct nx_info *nxi = NULL;
20204+
20205+ if (id < 0) {
20206+ nxi = get_nx_info(current_nx_info());
20207+ } else if (id > 1) {
20208+ spin_lock(&nx_info_hash_lock);
20209+ nxi = get_nx_info(__lookup_nx_info(id));
20210+ spin_unlock(&nx_info_hash_lock);
20211+ }
20212+ return nxi;
20213+}
20214+
20215+/* nid_is_hashed()
20216+
20217+ * verify that nid is still hashed */
20218+
20219+int nid_is_hashed(nid_t nid)
20220+{
20221+ int hashed;
20222+
20223+ spin_lock(&nx_info_hash_lock);
20224+ hashed = (__lookup_nx_info(nid) != NULL);
20225+ spin_unlock(&nx_info_hash_lock);
20226+ return hashed;
20227+}
20228+
20229+
20230+#ifdef CONFIG_PROC_FS
20231+
20232+/* get_nid_list()
20233+
20234+ * get a subset of hashed nids for proc
20235+ * assumes size is at least one */
20236+
20237+int get_nid_list(int index, unsigned int *nids, int size)
20238+{
20239+ int hindex, nr_nids = 0;
20240+
20241+ /* only show current and children */
20242+ if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20243+ if (index > 0)
20244+ return 0;
20245+ nids[nr_nids] = nx_current_nid();
20246+ return 1;
20247+ }
20248+
20249+ for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20250+ struct hlist_head *head = &nx_info_hash[hindex];
20251+ struct hlist_node *pos;
20252+
20253+ spin_lock(&nx_info_hash_lock);
20254+ hlist_for_each(pos, head) {
20255+ struct nx_info *nxi;
20256+
20257+ if (--index > 0)
20258+ continue;
20259+
20260+ nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20261+ nids[nr_nids] = nxi->nx_id;
20262+ if (++nr_nids >= size) {
20263+ spin_unlock(&nx_info_hash_lock);
20264+ goto out;
20265+ }
20266+ }
20267+ /* keep the lock time short */
20268+ spin_unlock(&nx_info_hash_lock);
20269+ }
20270+out:
20271+ return nr_nids;
20272+}
20273+#endif
20274+
20275+
20276+/*
20277+ * migrate task to new network
20278+ * gets nxi, puts old_nxi on change
20279+ */
20280+
20281+int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20282+{
20283+ struct nx_info *old_nxi;
20284+ int ret = 0;
20285+
20286+ if (!p || !nxi)
20287+ BUG();
20288+
20289+ vxdprintk(VXD_CBIT(nid, 5),
20290+ "nx_migrate_task(%p,%p[#%d.%d.%d])",
20291+ p, nxi, nxi->nx_id,
20292+ atomic_read(&nxi->nx_usecnt),
20293+ atomic_read(&nxi->nx_tasks));
20294+
20295+ if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20296+ !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20297+ return -EACCES;
20298+
20299+ if (nx_info_state(nxi, NXS_SHUTDOWN))
20300+ return -EFAULT;
20301+
20302+ /* maybe disallow this completely? */
20303+ old_nxi = task_get_nx_info(p);
20304+ if (old_nxi == nxi)
20305+ goto out;
20306+
20307+ task_lock(p);
20308+ if (old_nxi)
20309+ clr_nx_info(&p->nx_info);
20310+ claim_nx_info(nxi, p);
20311+ set_nx_info(&p->nx_info, nxi);
20312+ p->nid = nxi->nx_id;
20313+ task_unlock(p);
20314+
20315+ vxdprintk(VXD_CBIT(nid, 5),
20316+ "moved task %p into nxi:%p[#%d]",
20317+ p, nxi, nxi->nx_id);
20318+
20319+ if (old_nxi)
20320+ release_nx_info(old_nxi, p);
20321+ ret = 0;
20322+out:
20323+ put_nx_info(old_nxi);
20324+ return ret;
20325+}
20326+
20327+
20328+void nx_set_persistent(struct nx_info *nxi)
20329+{
20330+ vxdprintk(VXD_CBIT(nid, 6),
20331+ "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20332+
20333+ get_nx_info(nxi);
20334+ claim_nx_info(nxi, NULL);
20335+}
20336+
20337+void nx_clear_persistent(struct nx_info *nxi)
20338+{
20339+ vxdprintk(VXD_CBIT(nid, 6),
20340+ "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20341+
20342+ release_nx_info(nxi, NULL);
20343+ put_nx_info(nxi);
20344+}
20345+
20346+void nx_update_persistent(struct nx_info *nxi)
20347+{
20348+ if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20349+ nx_set_persistent(nxi);
20350+ else
20351+ nx_clear_persistent(nxi);
20352+}
20353+
20354+/* vserver syscall commands below here */
20355+
20356+/* taks nid and nx_info functions */
20357+
20358+#include <asm/uaccess.h>
20359+
20360+
20361+int vc_task_nid(uint32_t id)
20362+{
20363+ nid_t nid;
20364+
20365+ if (id) {
20366+ struct task_struct *tsk;
20367+
20368+ rcu_read_lock();
20369+ tsk = find_task_by_real_pid(id);
20370+ nid = (tsk) ? tsk->nid : -ESRCH;
20371+ rcu_read_unlock();
20372+ } else
20373+ nid = nx_current_nid();
20374+ return nid;
20375+}
20376+
20377+
20378+int vc_nx_info(struct nx_info *nxi, void __user *data)
20379+{
20380+ struct vcmd_nx_info_v0 vc_data;
20381+
20382+ vc_data.nid = nxi->nx_id;
20383+
20384+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20385+ return -EFAULT;
20386+ return 0;
20387+}
20388+
20389+
20390+/* network functions */
20391+
20392+int vc_net_create(uint32_t nid, void __user *data)
20393+{
20394+ struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20395+ struct nx_info *new_nxi;
20396+ int ret;
20397+
20398+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20399+ return -EFAULT;
20400+
20401+ if ((nid > MAX_S_CONTEXT) || (nid < 2))
20402+ return -EINVAL;
20403+
20404+ new_nxi = __create_nx_info(nid);
20405+ if (IS_ERR(new_nxi))
20406+ return PTR_ERR(new_nxi);
20407+
20408+ /* initial flags */
20409+ new_nxi->nx_flags = vc_data.flagword;
20410+
20411+ ret = -ENOEXEC;
20412+ if (vs_net_change(new_nxi, VSC_NETUP))
20413+ goto out;
20414+
20415+ ret = nx_migrate_task(current, new_nxi);
20416+ if (ret)
20417+ goto out;
20418+
20419+ /* return context id on success */
20420+ ret = new_nxi->nx_id;
20421+
20422+ /* get a reference for persistent contexts */
20423+ if ((vc_data.flagword & NXF_PERSISTENT))
20424+ nx_set_persistent(new_nxi);
20425+out:
20426+ release_nx_info(new_nxi, NULL);
20427+ put_nx_info(new_nxi);
20428+ return ret;
20429+}
20430+
20431+
20432+int vc_net_migrate(struct nx_info *nxi, void __user *data)
20433+{
20434+ return nx_migrate_task(current, nxi);
20435+}
20436+
20437+
20438+
20439+int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20440+ uint16_t type, uint16_t flags)
20441+{
20442+ struct nx_addr_v4 *nxa = &nxi->v4;
20443+
20444+ if (NX_IPV4(nxi)) {
20445+ /* locate last entry */
20446+ for (; nxa->next; nxa = nxa->next);
20447+ nxa->next = __alloc_nx_addr_v4();
20448+ nxa = nxa->next;
20449+
20450+ if (IS_ERR(nxa))
20451+ return PTR_ERR(nxa);
20452+ }
20453+
20454+ if (nxi->v4.next)
20455+ /* remove single ip for ip list */
20456+ nxi->nx_flags &= ~NXF_SINGLE_IP;
20457+
20458+ nxa->ip[0].s_addr = ip;
20459+ nxa->ip[1].s_addr = ip2;
20460+ nxa->mask.s_addr = mask;
20461+ nxa->type = type;
20462+ nxa->flags = flags;
20463+ return 0;
20464+}
20465+
20466+int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20467+ uint16_t type, uint16_t flags)
20468+{
20469+ struct nx_addr_v4 *nxa = &nxi->v4;
20470+
20471+ switch (type) {
20472+/* case NXA_TYPE_ADDR:
20473+ break; */
20474+
20475+ case NXA_TYPE_ANY:
20476+ __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20477+ memset(nxa, 0, sizeof(*nxa));
20478+ break;
20479+
20480+ default:
20481+ return -EINVAL;
20482+ }
20483+ return 0;
20484+}
20485+
20486+
20487+int vc_net_add(struct nx_info *nxi, void __user *data)
20488+{
20489+ struct vcmd_net_addr_v0 vc_data;
20490+ int index, ret = 0;
20491+
20492+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20493+ return -EFAULT;
20494+
20495+ switch (vc_data.type) {
20496+ case NXA_TYPE_IPV4:
20497+ if ((vc_data.count < 1) || (vc_data.count > 4))
20498+ return -EINVAL;
20499+
20500+ index = 0;
20501+ while (index < vc_data.count) {
20502+ ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20503+ vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20504+ if (ret)
20505+ return ret;
20506+ index++;
20507+ }
20508+ ret = index;
20509+ break;
20510+
20511+ case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20512+ nxi->v4_bcast = vc_data.ip[0];
20513+ ret = 1;
20514+ break;
20515+
20516+ case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20517+ nxi->v4_lback = vc_data.ip[0];
20518+ ret = 1;
20519+ break;
20520+
20521+ default:
20522+ ret = -EINVAL;
20523+ break;
20524+ }
20525+ return ret;
20526+}
20527+
20528+int vc_net_remove(struct nx_info *nxi, void __user *data)
20529+{
20530+ struct vcmd_net_addr_v0 vc_data;
20531+
20532+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20533+ return -EFAULT;
20534+
20535+ switch (vc_data.type) {
20536+ case NXA_TYPE_ANY:
20537+ __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20538+ memset(&nxi->v4, 0, sizeof(nxi->v4));
20539+ break;
20540+
20541+ default:
20542+ return -EINVAL;
20543+ }
20544+ return 0;
20545+}
20546+
20547+
20548+int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20549+{
20550+ struct vcmd_net_addr_ipv4_v1 vc_data;
20551+
20552+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20553+ return -EFAULT;
20554+
20555+ switch (vc_data.type) {
20556+ case NXA_TYPE_ADDR:
20557+ case NXA_TYPE_MASK:
20558+ return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20559+ vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20560+
20561+ case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20562+ nxi->v4_bcast = vc_data.ip;
20563+ break;
20564+
20565+ case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20566+ nxi->v4_lback = vc_data.ip;
20567+ break;
20568+
20569+ default:
20570+ return -EINVAL;
20571+ }
20572+ return 0;
20573+}
20574+
20575+int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20576+{
20577+ struct vcmd_net_addr_ipv4_v2 vc_data;
20578+
20579+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20580+ return -EFAULT;
20581+
20582+ switch (vc_data.type) {
20583+ case NXA_TYPE_ADDR:
20584+ case NXA_TYPE_MASK:
20585+ case NXA_TYPE_RANGE:
20586+ return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20587+ vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20588+
20589+ case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20590+ nxi->v4_bcast = vc_data.ip;
20591+ break;
20592+
20593+ case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20594+ nxi->v4_lback = vc_data.ip;
20595+ break;
20596+
20597+ default:
20598+ return -EINVAL;
20599+ }
20600+ return 0;
20601+}
20602+
20603+int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20604+{
20605+ struct vcmd_net_addr_ipv4_v1 vc_data;
20606+
20607+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20608+ return -EFAULT;
20609+
20610+ return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20611+ vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20612+}
20613+
20614+int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20615+{
20616+ struct vcmd_net_addr_ipv4_v2 vc_data;
20617+
20618+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20619+ return -EFAULT;
20620+
20621+ return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20622+ vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20623+}
20624+
20625+#ifdef CONFIG_IPV6
20626+
20627+int do_add_v6_addr(struct nx_info *nxi,
20628+ struct in6_addr *ip, struct in6_addr *mask,
20629+ uint32_t prefix, uint16_t type, uint16_t flags)
20630+{
20631+ struct nx_addr_v6 *nxa = &nxi->v6;
20632+
20633+ if (NX_IPV6(nxi)) {
20634+ /* locate last entry */
20635+ for (; nxa->next; nxa = nxa->next);
20636+ nxa->next = __alloc_nx_addr_v6();
20637+ nxa = nxa->next;
20638+
20639+ if (IS_ERR(nxa))
20640+ return PTR_ERR(nxa);
20641+ }
20642+
20643+ nxa->ip = *ip;
20644+ nxa->mask = *mask;
20645+ nxa->prefix = prefix;
20646+ nxa->type = type;
20647+ nxa->flags = flags;
20648+ return 0;
20649+}
20650+
20651+
20652+int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20653+{
20654+ struct vcmd_net_addr_ipv6_v1 vc_data;
20655+
20656+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20657+ return -EFAULT;
20658+
20659+ switch (vc_data.type) {
20660+ case NXA_TYPE_ADDR:
20661+ memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20662+ /* fallthrough */
20663+ case NXA_TYPE_MASK:
20664+ return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20665+ vc_data.prefix, vc_data.type, vc_data.flags);
20666+ default:
20667+ return -EINVAL;
20668+ }
20669+ return 0;
20670+}
20671+
20672+int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20673+{
20674+ struct vcmd_net_addr_ipv6_v1 vc_data;
20675+
20676+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20677+ return -EFAULT;
20678+
20679+ switch (vc_data.type) {
20680+ case NXA_TYPE_ANY:
20681+ __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20682+ memset(&nxi->v6, 0, sizeof(nxi->v6));
20683+ break;
20684+
20685+ default:
20686+ return -EINVAL;
20687+ }
20688+ return 0;
20689+}
20690+
20691+#endif /* CONFIG_IPV6 */
20692+
20693+
20694+int vc_get_nflags(struct nx_info *nxi, void __user *data)
20695+{
20696+ struct vcmd_net_flags_v0 vc_data;
20697+
20698+ vc_data.flagword = nxi->nx_flags;
20699+
20700+ /* special STATE flag handling */
20701+ vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20702+
20703+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20704+ return -EFAULT;
20705+ return 0;
20706+}
20707+
20708+int vc_set_nflags(struct nx_info *nxi, void __user *data)
20709+{
20710+ struct vcmd_net_flags_v0 vc_data;
20711+ uint64_t mask, trigger;
20712+
20713+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20714+ return -EFAULT;
20715+
20716+ /* special STATE flag handling */
20717+ mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20718+ trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20719+
20720+ nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20721+ vc_data.flagword, mask);
20722+ if (trigger & NXF_PERSISTENT)
20723+ nx_update_persistent(nxi);
20724+
20725+ return 0;
20726+}
20727+
20728+int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20729+{
20730+ struct vcmd_net_caps_v0 vc_data;
20731+
20732+ vc_data.ncaps = nxi->nx_ncaps;
20733+ vc_data.cmask = ~0ULL;
20734+
20735+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20736+ return -EFAULT;
20737+ return 0;
20738+}
20739+
20740+int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20741+{
20742+ struct vcmd_net_caps_v0 vc_data;
20743+
20744+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20745+ return -EFAULT;
20746+
20747+ nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20748+ vc_data.ncaps, vc_data.cmask);
20749+ return 0;
20750+}
20751+
20752+
20753+#include <linux/module.h>
20754+
20755+module_init(init_network);
20756+
20757+EXPORT_SYMBOL_GPL(free_nx_info);
20758+EXPORT_SYMBOL_GPL(unhash_nx_info);
20759+
20760diff -NurpP --minimal linux-3.6.6/kernel/vserver/proc.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/proc.c
20761--- linux-3.6.6/kernel/vserver/proc.c 1970-01-01 01:00:00.000000000 +0100
20762+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/proc.c 2012-10-09 14:19:59.000000000 +0200
20763@@ -0,0 +1,1110 @@
20764+/*
20765+ * linux/kernel/vserver/proc.c
20766+ *
20767+ * Virtual Context Support
20768+ *
20769+ * Copyright (C) 2003-2011 Herbert Pötzl
20770+ *
20771+ * V0.01 basic structure
20772+ * V0.02 adaptation vs1.3.0
20773+ * V0.03 proc permissions
20774+ * V0.04 locking/generic
20775+ * V0.05 next generation procfs
20776+ * V0.06 inode validation
20777+ * V0.07 generic rewrite vid
20778+ * V0.08 remove inode type
20779+ * V0.09 added u/wmask info
20780+ *
20781+ */
20782+
20783+#include <linux/proc_fs.h>
20784+#include <linux/fs_struct.h>
20785+#include <linux/mount.h>
20786+#include <linux/namei.h>
20787+#include <asm/unistd.h>
20788+
20789+#include <linux/vs_context.h>
20790+#include <linux/vs_network.h>
20791+#include <linux/vs_cvirt.h>
20792+
20793+#include <linux/in.h>
20794+#include <linux/inetdevice.h>
20795+#include <linux/vs_inet.h>
20796+#include <linux/vs_inet6.h>
20797+
20798+#include <linux/vserver/global.h>
20799+
20800+#include "cvirt_proc.h"
20801+#include "cacct_proc.h"
20802+#include "limit_proc.h"
20803+#include "sched_proc.h"
20804+#include "vci_config.h"
20805+
20806+
20807+static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20808+{
20809+ unsigned __capi;
20810+
20811+ CAP_FOR_EACH_U32(__capi) {
20812+ buffer += sprintf(buffer, "%08x",
20813+ c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20814+ }
20815+ return buffer;
20816+}
20817+
20818+
20819+static struct proc_dir_entry *proc_virtual;
20820+
20821+static struct proc_dir_entry *proc_virtnet;
20822+
20823+
20824+/* first the actual feeds */
20825+
20826+
20827+static int proc_vci(char *buffer)
20828+{
20829+ return sprintf(buffer,
20830+ "VCIVersion:\t%04x:%04x\n"
20831+ "VCISyscall:\t%d\n"
20832+ "VCIKernel:\t%08x\n",
20833+ VCI_VERSION >> 16,
20834+ VCI_VERSION & 0xFFFF,
20835+ __NR_vserver,
20836+ vci_kernel_config());
20837+}
20838+
20839+static int proc_virtual_info(char *buffer)
20840+{
20841+ return proc_vci(buffer);
20842+}
20843+
20844+static int proc_virtual_status(char *buffer)
20845+{
20846+ return sprintf(buffer,
20847+ "#CTotal:\t%d\n"
20848+ "#CActive:\t%d\n"
20849+ "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20850+ "#InitTask:\t%d\t%d %d\n",
20851+ atomic_read(&vx_global_ctotal),
20852+ atomic_read(&vx_global_cactive),
20853+ atomic_read(&vs_global_nsproxy),
20854+ atomic_read(&vs_global_fs),
20855+ atomic_read(&vs_global_mnt_ns),
20856+ atomic_read(&vs_global_uts_ns),
20857+ atomic_read(&nr_ipc_ns),
20858+ atomic_read(&vs_global_user_ns),
20859+ atomic_read(&vs_global_pid_ns),
20860+ atomic_read(&init_task.usage),
20861+ atomic_read(&init_task.nsproxy->count),
20862+ init_task.fs->users);
20863+}
20864+
20865+
20866+int proc_vxi_info(struct vx_info *vxi, char *buffer)
20867+{
20868+ int length;
20869+
20870+ length = sprintf(buffer,
20871+ "ID:\t%d\n"
20872+ "Info:\t%p\n"
20873+ "Init:\t%d\n"
20874+ "OOM:\t%lld\n",
20875+ vxi->vx_id,
20876+ vxi,
20877+ vxi->vx_initpid,
20878+ vxi->vx_badness_bias);
20879+ return length;
20880+}
20881+
20882+int proc_vxi_status(struct vx_info *vxi, char *buffer)
20883+{
20884+ char *orig = buffer;
20885+
20886+ buffer += sprintf(buffer,
20887+ "UseCnt:\t%d\n"
20888+ "Tasks:\t%d\n"
20889+ "Flags:\t%016llx\n",
20890+ atomic_read(&vxi->vx_usecnt),
20891+ atomic_read(&vxi->vx_tasks),
20892+ (unsigned long long)vxi->vx_flags);
20893+
20894+ buffer += sprintf(buffer, "BCaps:\t");
20895+ buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20896+ buffer += sprintf(buffer, "\n");
20897+
20898+ buffer += sprintf(buffer,
20899+ "CCaps:\t%016llx\n"
20900+ "Umask:\t%16llx\n"
20901+ "Wmask:\t%16llx\n"
20902+ "Spaces:\t%08lx %08lx\n",
20903+ (unsigned long long)vxi->vx_ccaps,
20904+ (unsigned long long)vxi->vx_umask,
20905+ (unsigned long long)vxi->vx_wmask,
20906+ vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20907+ return buffer - orig;
20908+}
20909+
20910+int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20911+{
20912+ return vx_info_proc_limit(&vxi->limit, buffer);
20913+}
20914+
20915+int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20916+{
20917+ int cpu, length;
20918+
20919+ length = vx_info_proc_sched(&vxi->sched, buffer);
20920+ for_each_online_cpu(cpu) {
20921+ length += vx_info_proc_sched_pc(
20922+ &vx_per_cpu(vxi, sched_pc, cpu),
20923+ buffer + length, cpu);
20924+ }
20925+ return length;
20926+}
20927+
20928+int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20929+{
20930+ return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20931+}
20932+
20933+int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20934+{
20935+ return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20936+}
20937+
20938+int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20939+{
20940+ int cpu, length;
20941+
20942+ vx_update_load(vxi);
20943+ length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20944+ for_each_online_cpu(cpu) {
20945+ length += vx_info_proc_cvirt_pc(
20946+ &vx_per_cpu(vxi, cvirt_pc, cpu),
20947+ buffer + length, cpu);
20948+ }
20949+ return length;
20950+}
20951+
20952+int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20953+{
20954+ return vx_info_proc_cacct(&vxi->cacct, buffer);
20955+}
20956+
20957+
20958+static int proc_virtnet_info(char *buffer)
20959+{
20960+ return proc_vci(buffer);
20961+}
20962+
20963+static int proc_virtnet_status(char *buffer)
20964+{
20965+ return sprintf(buffer,
20966+ "#CTotal:\t%d\n"
20967+ "#CActive:\t%d\n",
20968+ atomic_read(&nx_global_ctotal),
20969+ atomic_read(&nx_global_cactive));
20970+}
20971+
20972+int proc_nxi_info(struct nx_info *nxi, char *buffer)
20973+{
20974+ struct nx_addr_v4 *v4a;
20975+#ifdef CONFIG_IPV6
20976+ struct nx_addr_v6 *v6a;
20977+#endif
20978+ int length, i;
20979+
20980+ length = sprintf(buffer,
20981+ "ID:\t%d\n"
20982+ "Info:\t%p\n"
20983+ "Bcast:\t" NIPQUAD_FMT "\n"
20984+ "Lback:\t" NIPQUAD_FMT "\n",
20985+ nxi->nx_id,
20986+ nxi,
20987+ NIPQUAD(nxi->v4_bcast.s_addr),
20988+ NIPQUAD(nxi->v4_lback.s_addr));
20989+
20990+ if (!NX_IPV4(nxi))
20991+ goto skip_v4;
20992+ for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20993+ length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20994+ i, NXAV4(v4a));
20995+skip_v4:
20996+#ifdef CONFIG_IPV6
20997+ if (!NX_IPV6(nxi))
20998+ goto skip_v6;
20999+ for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21000+ length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21001+ i, NXAV6(v6a));
21002+skip_v6:
21003+#endif
21004+ return length;
21005+}
21006+
21007+int proc_nxi_status(struct nx_info *nxi, char *buffer)
21008+{
21009+ int length;
21010+
21011+ length = sprintf(buffer,
21012+ "UseCnt:\t%d\n"
21013+ "Tasks:\t%d\n"
21014+ "Flags:\t%016llx\n"
21015+ "NCaps:\t%016llx\n",
21016+ atomic_read(&nxi->nx_usecnt),
21017+ atomic_read(&nxi->nx_tasks),
21018+ (unsigned long long)nxi->nx_flags,
21019+ (unsigned long long)nxi->nx_ncaps);
21020+ return length;
21021+}
21022+
21023+
21024+
21025+/* here the inode helpers */
21026+
21027+struct vs_entry {
21028+ int len;
21029+ char *name;
21030+ mode_t mode;
21031+ struct inode_operations *iop;
21032+ struct file_operations *fop;
21033+ union proc_op op;
21034+};
21035+
21036+static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21037+{
21038+ struct inode *inode = new_inode(sb);
21039+
21040+ if (!inode)
21041+ goto out;
21042+
21043+ inode->i_mode = p->mode;
21044+ if (p->iop)
21045+ inode->i_op = p->iop;
21046+ if (p->fop)
21047+ inode->i_fop = p->fop;
21048+
21049+ set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21050+ inode->i_flags |= S_IMMUTABLE;
21051+
21052+ inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21053+
21054+ inode->i_uid = 0;
21055+ inode->i_gid = 0;
21056+ inode->i_tag = 0;
21057+out:
21058+ return inode;
21059+}
21060+
21061+static struct dentry *vs_proc_instantiate(struct inode *dir,
21062+ struct dentry *dentry, int id, void *ptr)
21063+{
21064+ struct vs_entry *p = ptr;
21065+ struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21066+ struct dentry *error = ERR_PTR(-EINVAL);
21067+
21068+ if (!inode)
21069+ goto out;
21070+
21071+ PROC_I(inode)->op = p->op;
21072+ PROC_I(inode)->fd = id;
21073+ d_add(dentry, inode);
21074+ error = NULL;
21075+out:
21076+ return error;
21077+}
21078+
21079+/* Lookups */
21080+
21081+typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21082+
21083+/*
21084+ * Fill a directory entry.
21085+ *
21086+ * If possible create the dcache entry and derive our inode number and
21087+ * file type from dcache entry.
21088+ *
21089+ * Since all of the proc inode numbers are dynamically generated, the inode
21090+ * numbers do not exist until the inode is cache. This means creating the
21091+ * the dcache entry in readdir is necessary to keep the inode numbers
21092+ * reported by readdir in sync with the inode numbers reported
21093+ * by stat.
21094+ */
21095+static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21096+ char *name, int len, instantiate_t instantiate, int id, void *ptr)
21097+{
21098+ struct dentry *child, *dir = filp->f_dentry;
21099+ struct inode *inode;
21100+ struct qstr qname;
21101+ ino_t ino = 0;
21102+ unsigned type = DT_UNKNOWN;
21103+
21104+ qname.name = name;
21105+ qname.len = len;
21106+ qname.hash = full_name_hash(name, len);
21107+
21108+ child = d_lookup(dir, &qname);
21109+ if (!child) {
21110+ struct dentry *new;
21111+ new = d_alloc(dir, &qname);
21112+ if (new) {
21113+ child = instantiate(dir->d_inode, new, id, ptr);
21114+ if (child)
21115+ dput(new);
21116+ else
21117+ child = new;
21118+ }
21119+ }
21120+ if (!child || IS_ERR(child) || !child->d_inode)
21121+ goto end_instantiate;
21122+ inode = child->d_inode;
21123+ if (inode) {
21124+ ino = inode->i_ino;
21125+ type = inode->i_mode >> 12;
21126+ }
21127+ dput(child);
21128+end_instantiate:
21129+ if (!ino)
21130+ ino = find_inode_number(dir, &qname);
21131+ if (!ino)
21132+ ino = 1;
21133+ return filldir(dirent, name, len, filp->f_pos, ino, type);
21134+}
21135+
21136+
21137+
21138+/* get and revalidate vx_info/xid */
21139+
21140+static inline
21141+struct vx_info *get_proc_vx_info(struct inode *inode)
21142+{
21143+ return lookup_vx_info(PROC_I(inode)->fd);
21144+}
21145+
21146+static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21147+{
21148+ struct inode *inode = dentry->d_inode;
21149+ xid_t xid = PROC_I(inode)->fd;
21150+
21151+ if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21152+ return -ECHILD;
21153+
21154+ if (!xid || xid_is_hashed(xid))
21155+ return 1;
21156+ d_drop(dentry);
21157+ return 0;
21158+}
21159+
21160+
21161+/* get and revalidate nx_info/nid */
21162+
21163+static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21164+{
21165+ struct inode *inode = dentry->d_inode;
21166+ nid_t nid = PROC_I(inode)->fd;
21167+
21168+ if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21169+ return -ECHILD;
21170+
21171+ if (!nid || nid_is_hashed(nid))
21172+ return 1;
21173+ d_drop(dentry);
21174+ return 0;
21175+}
21176+
21177+
21178+
21179+#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21180+
21181+static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21182+ size_t count, loff_t *ppos)
21183+{
21184+ struct inode *inode = file->f_dentry->d_inode;
21185+ unsigned long page;
21186+ ssize_t length = 0;
21187+
21188+ if (count > PROC_BLOCK_SIZE)
21189+ count = PROC_BLOCK_SIZE;
21190+
21191+ /* fade that out as soon as stable */
21192+ WARN_ON(PROC_I(inode)->fd);
21193+
21194+ if (!(page = __get_free_page(GFP_KERNEL)))
21195+ return -ENOMEM;
21196+
21197+ BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21198+ length = PROC_I(inode)->op.proc_vs_read((char *)page);
21199+
21200+ if (length >= 0)
21201+ length = simple_read_from_buffer(buf, count, ppos,
21202+ (char *)page, length);
21203+
21204+ free_page(page);
21205+ return length;
21206+}
21207+
21208+static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21209+ size_t count, loff_t *ppos)
21210+{
21211+ struct inode *inode = file->f_dentry->d_inode;
21212+ struct vx_info *vxi = NULL;
21213+ xid_t xid = PROC_I(inode)->fd;
21214+ unsigned long page;
21215+ ssize_t length = 0;
21216+
21217+ if (count > PROC_BLOCK_SIZE)
21218+ count = PROC_BLOCK_SIZE;
21219+
21220+ /* fade that out as soon as stable */
21221+ WARN_ON(!xid);
21222+ vxi = lookup_vx_info(xid);
21223+ if (!vxi)
21224+ goto out;
21225+
21226+ length = -ENOMEM;
21227+ if (!(page = __get_free_page(GFP_KERNEL)))
21228+ goto out_put;
21229+
21230+ BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21231+ length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21232+
21233+ if (length >= 0)
21234+ length = simple_read_from_buffer(buf, count, ppos,
21235+ (char *)page, length);
21236+
21237+ free_page(page);
21238+out_put:
21239+ put_vx_info(vxi);
21240+out:
21241+ return length;
21242+}
21243+
21244+static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21245+ size_t count, loff_t *ppos)
21246+{
21247+ struct inode *inode = file->f_dentry->d_inode;
21248+ struct nx_info *nxi = NULL;
21249+ nid_t nid = PROC_I(inode)->fd;
21250+ unsigned long page;
21251+ ssize_t length = 0;
21252+
21253+ if (count > PROC_BLOCK_SIZE)
21254+ count = PROC_BLOCK_SIZE;
21255+
21256+ /* fade that out as soon as stable */
21257+ WARN_ON(!nid);
21258+ nxi = lookup_nx_info(nid);
21259+ if (!nxi)
21260+ goto out;
21261+
21262+ length = -ENOMEM;
21263+ if (!(page = __get_free_page(GFP_KERNEL)))
21264+ goto out_put;
21265+
21266+ BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21267+ length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21268+
21269+ if (length >= 0)
21270+ length = simple_read_from_buffer(buf, count, ppos,
21271+ (char *)page, length);
21272+
21273+ free_page(page);
21274+out_put:
21275+ put_nx_info(nxi);
21276+out:
21277+ return length;
21278+}
21279+
21280+
21281+
21282+/* here comes the lower level */
21283+
21284+
21285+#define NOD(NAME, MODE, IOP, FOP, OP) { \
21286+ .len = sizeof(NAME) - 1, \
21287+ .name = (NAME), \
21288+ .mode = MODE, \
21289+ .iop = IOP, \
21290+ .fop = FOP, \
21291+ .op = OP, \
21292+}
21293+
21294+
21295+#define DIR(NAME, MODE, OTYPE) \
21296+ NOD(NAME, (S_IFDIR | (MODE)), \
21297+ &proc_ ## OTYPE ## _inode_operations, \
21298+ &proc_ ## OTYPE ## _file_operations, { } )
21299+
21300+#define INF(NAME, MODE, OTYPE) \
21301+ NOD(NAME, (S_IFREG | (MODE)), NULL, \
21302+ &proc_vs_info_file_operations, \
21303+ { .proc_vs_read = &proc_##OTYPE } )
21304+
21305+#define VINF(NAME, MODE, OTYPE) \
21306+ NOD(NAME, (S_IFREG | (MODE)), NULL, \
21307+ &proc_vx_info_file_operations, \
21308+ { .proc_vxi_read = &proc_##OTYPE } )
21309+
21310+#define NINF(NAME, MODE, OTYPE) \
21311+ NOD(NAME, (S_IFREG | (MODE)), NULL, \
21312+ &proc_nx_info_file_operations, \
21313+ { .proc_nxi_read = &proc_##OTYPE } )
21314+
21315+
21316+static struct file_operations proc_vs_info_file_operations = {
21317+ .read = proc_vs_info_read,
21318+};
21319+
21320+static struct file_operations proc_vx_info_file_operations = {
21321+ .read = proc_vx_info_read,
21322+};
21323+
21324+static struct dentry_operations proc_xid_dentry_operations = {
21325+ .d_revalidate = proc_xid_revalidate,
21326+};
21327+
21328+static struct vs_entry vx_base_stuff[] = {
21329+ VINF("info", S_IRUGO, vxi_info),
21330+ VINF("status", S_IRUGO, vxi_status),
21331+ VINF("limit", S_IRUGO, vxi_limit),
21332+ VINF("sched", S_IRUGO, vxi_sched),
21333+ VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21334+ VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21335+ VINF("cvirt", S_IRUGO, vxi_cvirt),
21336+ VINF("cacct", S_IRUGO, vxi_cacct),
21337+ {}
21338+};
21339+
21340+
21341+
21342+
21343+static struct dentry *proc_xid_instantiate(struct inode *dir,
21344+ struct dentry *dentry, int id, void *ptr)
21345+{
21346+ dentry->d_op = &proc_xid_dentry_operations;
21347+ return vs_proc_instantiate(dir, dentry, id, ptr);
21348+}
21349+
21350+static struct dentry *proc_xid_lookup(struct inode *dir,
21351+ struct dentry *dentry, unsigned int flags)
21352+{
21353+ struct vs_entry *p = vx_base_stuff;
21354+ struct dentry *error = ERR_PTR(-ENOENT);
21355+
21356+ for (; p->name; p++) {
21357+ if (p->len != dentry->d_name.len)
21358+ continue;
21359+ if (!memcmp(dentry->d_name.name, p->name, p->len))
21360+ break;
21361+ }
21362+ if (!p->name)
21363+ goto out;
21364+
21365+ error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21366+out:
21367+ return error;
21368+}
21369+
21370+static int proc_xid_readdir(struct file *filp,
21371+ void *dirent, filldir_t filldir)
21372+{
21373+ struct dentry *dentry = filp->f_dentry;
21374+ struct inode *inode = dentry->d_inode;
21375+ struct vs_entry *p = vx_base_stuff;
21376+ int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21377+ int pos, index;
21378+ u64 ino;
21379+
21380+ pos = filp->f_pos;
21381+ switch (pos) {
21382+ case 0:
21383+ ino = inode->i_ino;
21384+ if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21385+ goto out;
21386+ pos++;
21387+ /* fall through */
21388+ case 1:
21389+ ino = parent_ino(dentry);
21390+ if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21391+ goto out;
21392+ pos++;
21393+ /* fall through */
21394+ default:
21395+ index = pos - 2;
21396+ if (index >= size)
21397+ goto out;
21398+ for (p += index; p->name; p++) {
21399+ if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21400+ vs_proc_instantiate, PROC_I(inode)->fd, p))
21401+ goto out;
21402+ pos++;
21403+ }
21404+ }
21405+out:
21406+ filp->f_pos = pos;
21407+ return 1;
21408+}
21409+
21410+
21411+
21412+static struct file_operations proc_nx_info_file_operations = {
21413+ .read = proc_nx_info_read,
21414+};
21415+
21416+static struct dentry_operations proc_nid_dentry_operations = {
21417+ .d_revalidate = proc_nid_revalidate,
21418+};
21419+
21420+static struct vs_entry nx_base_stuff[] = {
21421+ NINF("info", S_IRUGO, nxi_info),
21422+ NINF("status", S_IRUGO, nxi_status),
21423+ {}
21424+};
21425+
21426+
21427+static struct dentry *proc_nid_instantiate(struct inode *dir,
21428+ struct dentry *dentry, int id, void *ptr)
21429+{
21430+ dentry->d_op = &proc_nid_dentry_operations;
21431+ return vs_proc_instantiate(dir, dentry, id, ptr);
21432+}
21433+
21434+static struct dentry *proc_nid_lookup(struct inode *dir,
21435+ struct dentry *dentry, unsigned int flags)
21436+{
21437+ struct vs_entry *p = nx_base_stuff;
21438+ struct dentry *error = ERR_PTR(-ENOENT);
21439+
21440+ for (; p->name; p++) {
21441+ if (p->len != dentry->d_name.len)
21442+ continue;
21443+ if (!memcmp(dentry->d_name.name, p->name, p->len))
21444+ break;
21445+ }
21446+ if (!p->name)
21447+ goto out;
21448+
21449+ error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21450+out:
21451+ return error;
21452+}
21453+
21454+static int proc_nid_readdir(struct file *filp,
21455+ void *dirent, filldir_t filldir)
21456+{
21457+ struct dentry *dentry = filp->f_dentry;
21458+ struct inode *inode = dentry->d_inode;
21459+ struct vs_entry *p = nx_base_stuff;
21460+ int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21461+ int pos, index;
21462+ u64 ino;
21463+
21464+ pos = filp->f_pos;
21465+ switch (pos) {
21466+ case 0:
21467+ ino = inode->i_ino;
21468+ if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21469+ goto out;
21470+ pos++;
21471+ /* fall through */
21472+ case 1:
21473+ ino = parent_ino(dentry);
21474+ if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21475+ goto out;
21476+ pos++;
21477+ /* fall through */
21478+ default:
21479+ index = pos - 2;
21480+ if (index >= size)
21481+ goto out;
21482+ for (p += index; p->name; p++) {
21483+ if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21484+ vs_proc_instantiate, PROC_I(inode)->fd, p))
21485+ goto out;
21486+ pos++;
21487+ }
21488+ }
21489+out:
21490+ filp->f_pos = pos;
21491+ return 1;
21492+}
21493+
21494+
21495+#define MAX_MULBY10 ((~0U - 9) / 10)
21496+
21497+static inline int atovid(const char *str, int len)
21498+{
21499+ int vid, c;
21500+
21501+ vid = 0;
21502+ while (len-- > 0) {
21503+ c = *str - '0';
21504+ str++;
21505+ if (c > 9)
21506+ return -1;
21507+ if (vid >= MAX_MULBY10)
21508+ return -1;
21509+ vid *= 10;
21510+ vid += c;
21511+ if (!vid)
21512+ return -1;
21513+ }
21514+ return vid;
21515+}
21516+
21517+/* now the upper level (virtual) */
21518+
21519+
21520+static struct file_operations proc_xid_file_operations = {
21521+ .read = generic_read_dir,
21522+ .readdir = proc_xid_readdir,
21523+};
21524+
21525+static struct inode_operations proc_xid_inode_operations = {
21526+ .lookup = proc_xid_lookup,
21527+};
21528+
21529+static struct vs_entry vx_virtual_stuff[] = {
21530+ INF("info", S_IRUGO, virtual_info),
21531+ INF("status", S_IRUGO, virtual_status),
21532+ DIR(NULL, S_IRUGO | S_IXUGO, xid),
21533+};
21534+
21535+
21536+static struct dentry *proc_virtual_lookup(struct inode *dir,
21537+ struct dentry *dentry, unsigned int flags)
21538+{
21539+ struct vs_entry *p = vx_virtual_stuff;
21540+ struct dentry *error = ERR_PTR(-ENOENT);
21541+ int id = 0;
21542+
21543+ for (; p->name; p++) {
21544+ if (p->len != dentry->d_name.len)
21545+ continue;
21546+ if (!memcmp(dentry->d_name.name, p->name, p->len))
21547+ break;
21548+ }
21549+ if (p->name)
21550+ goto instantiate;
21551+
21552+ id = atovid(dentry->d_name.name, dentry->d_name.len);
21553+ if ((id < 0) || !xid_is_hashed(id))
21554+ goto out;
21555+
21556+instantiate:
21557+ error = proc_xid_instantiate(dir, dentry, id, p);
21558+out:
21559+ return error;
21560+}
21561+
21562+static struct file_operations proc_nid_file_operations = {
21563+ .read = generic_read_dir,
21564+ .readdir = proc_nid_readdir,
21565+};
21566+
21567+static struct inode_operations proc_nid_inode_operations = {
21568+ .lookup = proc_nid_lookup,
21569+};
21570+
21571+static struct vs_entry nx_virtnet_stuff[] = {
21572+ INF("info", S_IRUGO, virtnet_info),
21573+ INF("status", S_IRUGO, virtnet_status),
21574+ DIR(NULL, S_IRUGO | S_IXUGO, nid),
21575+};
21576+
21577+
21578+static struct dentry *proc_virtnet_lookup(struct inode *dir,
21579+ struct dentry *dentry, unsigned int flags)
21580+{
21581+ struct vs_entry *p = nx_virtnet_stuff;
21582+ struct dentry *error = ERR_PTR(-ENOENT);
21583+ int id = 0;
21584+
21585+ for (; p->name; p++) {
21586+ if (p->len != dentry->d_name.len)
21587+ continue;
21588+ if (!memcmp(dentry->d_name.name, p->name, p->len))
21589+ break;
21590+ }
21591+ if (p->name)
21592+ goto instantiate;
21593+
21594+ id = atovid(dentry->d_name.name, dentry->d_name.len);
21595+ if ((id < 0) || !nid_is_hashed(id))
21596+ goto out;
21597+
21598+instantiate:
21599+ error = proc_nid_instantiate(dir, dentry, id, p);
21600+out:
21601+ return error;
21602+}
21603+
21604+
21605+#define PROC_MAXVIDS 32
21606+
21607+int proc_virtual_readdir(struct file *filp,
21608+ void *dirent, filldir_t filldir)
21609+{
21610+ struct dentry *dentry = filp->f_dentry;
21611+ struct inode *inode = dentry->d_inode;
21612+ struct vs_entry *p = vx_virtual_stuff;
21613+ int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21614+ int pos, index;
21615+ unsigned int xid_array[PROC_MAXVIDS];
21616+ char buf[PROC_NUMBUF];
21617+ unsigned int nr_xids, i;
21618+ u64 ino;
21619+
21620+ pos = filp->f_pos;
21621+ switch (pos) {
21622+ case 0:
21623+ ino = inode->i_ino;
21624+ if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21625+ goto out;
21626+ pos++;
21627+ /* fall through */
21628+ case 1:
21629+ ino = parent_ino(dentry);
21630+ if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21631+ goto out;
21632+ pos++;
21633+ /* fall through */
21634+ default:
21635+ index = pos - 2;
21636+ if (index >= size)
21637+ goto entries;
21638+ for (p += index; p->name; p++) {
21639+ if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21640+ vs_proc_instantiate, 0, p))
21641+ goto out;
21642+ pos++;
21643+ }
21644+ entries:
21645+ index = pos - size;
21646+ p = &vx_virtual_stuff[size - 1];
21647+ nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21648+ for (i = 0; i < nr_xids; i++) {
21649+ int n, xid = xid_array[i];
21650+ unsigned int j = PROC_NUMBUF;
21651+
21652+ n = xid;
21653+ do
21654+ buf[--j] = '0' + (n % 10);
21655+ while (n /= 10);
21656+
21657+ if (proc_fill_cache(filp, dirent, filldir,
21658+ buf + j, PROC_NUMBUF - j,
21659+ vs_proc_instantiate, xid, p))
21660+ goto out;
21661+ pos++;
21662+ }
21663+ }
21664+out:
21665+ filp->f_pos = pos;
21666+ return 0;
21667+}
21668+
21669+static int proc_virtual_getattr(struct vfsmount *mnt,
21670+ struct dentry *dentry, struct kstat *stat)
21671+{
21672+ struct inode *inode = dentry->d_inode;
21673+
21674+ generic_fillattr(inode, stat);
21675+ stat->nlink = 2 + atomic_read(&vx_global_cactive);
21676+ return 0;
21677+}
21678+
21679+static struct file_operations proc_virtual_dir_operations = {
21680+ .read = generic_read_dir,
21681+ .readdir = proc_virtual_readdir,
21682+};
21683+
21684+static struct inode_operations proc_virtual_dir_inode_operations = {
21685+ .getattr = proc_virtual_getattr,
21686+ .lookup = proc_virtual_lookup,
21687+};
21688+
21689+
21690+
21691+
21692+
21693+int proc_virtnet_readdir(struct file *filp,
21694+ void *dirent, filldir_t filldir)
21695+{
21696+ struct dentry *dentry = filp->f_dentry;
21697+ struct inode *inode = dentry->d_inode;
21698+ struct vs_entry *p = nx_virtnet_stuff;
21699+ int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21700+ int pos, index;
21701+ unsigned int nid_array[PROC_MAXVIDS];
21702+ char buf[PROC_NUMBUF];
21703+ unsigned int nr_nids, i;
21704+ u64 ino;
21705+
21706+ pos = filp->f_pos;
21707+ switch (pos) {
21708+ case 0:
21709+ ino = inode->i_ino;
21710+ if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21711+ goto out;
21712+ pos++;
21713+ /* fall through */
21714+ case 1:
21715+ ino = parent_ino(dentry);
21716+ if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21717+ goto out;
21718+ pos++;
21719+ /* fall through */
21720+ default:
21721+ index = pos - 2;
21722+ if (index >= size)
21723+ goto entries;
21724+ for (p += index; p->name; p++) {
21725+ if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21726+ vs_proc_instantiate, 0, p))
21727+ goto out;
21728+ pos++;
21729+ }
21730+ entries:
21731+ index = pos - size;
21732+ p = &nx_virtnet_stuff[size - 1];
21733+ nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21734+ for (i = 0; i < nr_nids; i++) {
21735+ int n, nid = nid_array[i];
21736+ unsigned int j = PROC_NUMBUF;
21737+
21738+ n = nid;
21739+ do
21740+ buf[--j] = '0' + (n % 10);
21741+ while (n /= 10);
21742+
21743+ if (proc_fill_cache(filp, dirent, filldir,
21744+ buf + j, PROC_NUMBUF - j,
21745+ vs_proc_instantiate, nid, p))
21746+ goto out;
21747+ pos++;
21748+ }
21749+ }
21750+out:
21751+ filp->f_pos = pos;
21752+ return 0;
21753+}
21754+
21755+static int proc_virtnet_getattr(struct vfsmount *mnt,
21756+ struct dentry *dentry, struct kstat *stat)
21757+{
21758+ struct inode *inode = dentry->d_inode;
21759+
21760+ generic_fillattr(inode, stat);
21761+ stat->nlink = 2 + atomic_read(&nx_global_cactive);
21762+ return 0;
21763+}
21764+
21765+static struct file_operations proc_virtnet_dir_operations = {
21766+ .read = generic_read_dir,
21767+ .readdir = proc_virtnet_readdir,
21768+};
21769+
21770+static struct inode_operations proc_virtnet_dir_inode_operations = {
21771+ .getattr = proc_virtnet_getattr,
21772+ .lookup = proc_virtnet_lookup,
21773+};
21774+
21775+
21776+
21777+void proc_vx_init(void)
21778+{
21779+ struct proc_dir_entry *ent;
21780+
21781+ ent = proc_mkdir("virtual", 0);
21782+ if (ent) {
21783+ ent->proc_fops = &proc_virtual_dir_operations;
21784+ ent->proc_iops = &proc_virtual_dir_inode_operations;
21785+ }
21786+ proc_virtual = ent;
21787+
21788+ ent = proc_mkdir("virtnet", 0);
21789+ if (ent) {
21790+ ent->proc_fops = &proc_virtnet_dir_operations;
21791+ ent->proc_iops = &proc_virtnet_dir_inode_operations;
21792+ }
21793+ proc_virtnet = ent;
21794+}
21795+
21796+
21797+
21798+
21799+/* per pid info */
21800+
21801+
21802+int proc_pid_vx_info(struct task_struct *p, char *buffer)
21803+{
21804+ struct vx_info *vxi;
21805+ char *orig = buffer;
21806+
21807+ buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21808+
21809+ vxi = task_get_vx_info(p);
21810+ if (!vxi)
21811+ goto out;
21812+
21813+ buffer += sprintf(buffer, "BCaps:\t");
21814+ buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21815+ buffer += sprintf(buffer, "\n");
21816+ buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21817+ (unsigned long long)vxi->vx_ccaps);
21818+ buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21819+ (unsigned long long)vxi->vx_flags);
21820+ buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21821+
21822+ put_vx_info(vxi);
21823+out:
21824+ return buffer - orig;
21825+}
21826+
21827+
21828+int proc_pid_nx_info(struct task_struct *p, char *buffer)
21829+{
21830+ struct nx_info *nxi;
21831+ struct nx_addr_v4 *v4a;
21832+#ifdef CONFIG_IPV6
21833+ struct nx_addr_v6 *v6a;
21834+#endif
21835+ char *orig = buffer;
21836+ int i;
21837+
21838+ buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21839+
21840+ nxi = task_get_nx_info(p);
21841+ if (!nxi)
21842+ goto out;
21843+
21844+ buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21845+ (unsigned long long)nxi->nx_ncaps);
21846+ buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21847+ (unsigned long long)nxi->nx_flags);
21848+
21849+ buffer += sprintf(buffer,
21850+ "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21851+ NIPQUAD(nxi->v4_bcast.s_addr));
21852+ buffer += sprintf (buffer,
21853+ "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21854+ NIPQUAD(nxi->v4_lback.s_addr));
21855+ if (!NX_IPV4(nxi))
21856+ goto skip_v4;
21857+ for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21858+ buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21859+ i, NXAV4(v4a));
21860+skip_v4:
21861+#ifdef CONFIG_IPV6
21862+ if (!NX_IPV6(nxi))
21863+ goto skip_v6;
21864+ for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21865+ buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21866+ i, NXAV6(v6a));
21867+skip_v6:
21868+#endif
21869+ put_nx_info(nxi);
21870+out:
21871+ return buffer - orig;
21872+}
21873+
21874diff -NurpP --minimal linux-3.6.6/kernel/vserver/sched.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/sched.c
21875--- linux-3.6.6/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
21876+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/sched.c 2012-10-04 18:47:00.000000000 +0200
21877@@ -0,0 +1,83 @@
21878+/*
21879+ * linux/kernel/vserver/sched.c
21880+ *
21881+ * Virtual Server: Scheduler Support
21882+ *
21883+ * Copyright (C) 2004-2010 Herbert Pötzl
21884+ *
21885+ * V0.01 adapted Sam Vilains version to 2.6.3
21886+ * V0.02 removed legacy interface
21887+ * V0.03 changed vcmds to vxi arg
21888+ * V0.04 removed older and legacy interfaces
21889+ * V0.05 removed scheduler code/commands
21890+ *
21891+ */
21892+
21893+#include <linux/vs_context.h>
21894+#include <linux/vs_sched.h>
21895+#include <linux/cpumask.h>
21896+#include <linux/vserver/sched_cmd.h>
21897+
21898+#include <asm/uaccess.h>
21899+
21900+
21901+void vx_update_sched_param(struct _vx_sched *sched,
21902+ struct _vx_sched_pc *sched_pc)
21903+{
21904+ sched_pc->prio_bias = sched->prio_bias;
21905+}
21906+
21907+static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21908+{
21909+ int cpu;
21910+
21911+ if (data->prio_bias > MAX_PRIO_BIAS)
21912+ data->prio_bias = MAX_PRIO_BIAS;
21913+ if (data->prio_bias < MIN_PRIO_BIAS)
21914+ data->prio_bias = MIN_PRIO_BIAS;
21915+
21916+ if (data->cpu_id != ~0) {
21917+ vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21918+ cpumask_and(&vxi->sched.update, &vxi->sched.update,
21919+ cpu_online_mask);
21920+ } else
21921+ cpumask_copy(&vxi->sched.update, cpu_online_mask);
21922+
21923+ for_each_cpu_mask(cpu, vxi->sched.update)
21924+ vx_update_sched_param(&vxi->sched,
21925+ &vx_per_cpu(vxi, sched_pc, cpu));
21926+ return 0;
21927+}
21928+
21929+int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21930+{
21931+ struct vcmd_prio_bias vc_data;
21932+
21933+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21934+ return -EFAULT;
21935+
21936+ return do_set_prio_bias(vxi, &vc_data);
21937+}
21938+
21939+int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21940+{
21941+ struct vcmd_prio_bias vc_data;
21942+ struct _vx_sched_pc *pcd;
21943+ int cpu;
21944+
21945+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21946+ return -EFAULT;
21947+
21948+ cpu = vc_data.cpu_id;
21949+
21950+ if (!cpu_possible(cpu))
21951+ return -EINVAL;
21952+
21953+ pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21954+ vc_data.prio_bias = pcd->prio_bias;
21955+
21956+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21957+ return -EFAULT;
21958+ return 0;
21959+}
21960+
21961diff -NurpP --minimal linux-3.6.6/kernel/vserver/sched_init.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/sched_init.h
21962--- linux-3.6.6/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
21963+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/sched_init.h 2012-10-04 18:47:00.000000000 +0200
21964@@ -0,0 +1,27 @@
21965+
21966+static inline void vx_info_init_sched(struct _vx_sched *sched)
21967+{
21968+ /* scheduling; hard code starting values as constants */
21969+ sched->prio_bias = 0;
21970+}
21971+
21972+static inline
21973+void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21974+{
21975+ sched_pc->prio_bias = 0;
21976+
21977+ sched_pc->user_ticks = 0;
21978+ sched_pc->sys_ticks = 0;
21979+ sched_pc->hold_ticks = 0;
21980+}
21981+
21982+static inline void vx_info_exit_sched(struct _vx_sched *sched)
21983+{
21984+ return;
21985+}
21986+
21987+static inline
21988+void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21989+{
21990+ return;
21991+}
21992diff -NurpP --minimal linux-3.6.6/kernel/vserver/sched_proc.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/sched_proc.h
21993--- linux-3.6.6/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
21994+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/sched_proc.h 2012-10-04 18:47:00.000000000 +0200
21995@@ -0,0 +1,32 @@
21996+#ifndef _VX_SCHED_PROC_H
21997+#define _VX_SCHED_PROC_H
21998+
21999+
22000+static inline
22001+int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22002+{
22003+ int length = 0;
22004+
22005+ length += sprintf(buffer,
22006+ "PrioBias:\t%8d\n",
22007+ sched->prio_bias);
22008+ return length;
22009+}
22010+
22011+static inline
22012+int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22013+ char *buffer, int cpu)
22014+{
22015+ int length = 0;
22016+
22017+ length += sprintf(buffer + length,
22018+ "cpu %d: %lld %lld %lld", cpu,
22019+ (unsigned long long)sched_pc->user_ticks,
22020+ (unsigned long long)sched_pc->sys_ticks,
22021+ (unsigned long long)sched_pc->hold_ticks);
22022+ length += sprintf(buffer + length,
22023+ " %d\n", sched_pc->prio_bias);
22024+ return length;
22025+}
22026+
22027+#endif /* _VX_SCHED_PROC_H */
22028diff -NurpP --minimal linux-3.6.6/kernel/vserver/signal.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/signal.c
22029--- linux-3.6.6/kernel/vserver/signal.c 1970-01-01 01:00:00.000000000 +0100
22030+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/signal.c 2012-10-04 18:47:00.000000000 +0200
22031@@ -0,0 +1,134 @@
22032+/*
22033+ * linux/kernel/vserver/signal.c
22034+ *
22035+ * Virtual Server: Signal Support
22036+ *
22037+ * Copyright (C) 2003-2007 Herbert Pötzl
22038+ *
22039+ * V0.01 broken out from vcontext V0.05
22040+ * V0.02 changed vcmds to vxi arg
22041+ * V0.03 adjusted siginfo for kill
22042+ *
22043+ */
22044+
22045+#include <asm/uaccess.h>
22046+
22047+#include <linux/vs_context.h>
22048+#include <linux/vs_pid.h>
22049+#include <linux/vserver/signal_cmd.h>
22050+
22051+
22052+int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22053+{
22054+ int retval, count = 0;
22055+ struct task_struct *p;
22056+ struct siginfo *sip = SEND_SIG_PRIV;
22057+
22058+ retval = -ESRCH;
22059+ vxdprintk(VXD_CBIT(misc, 4),
22060+ "vx_info_kill(%p[#%d],%d,%d)*",
22061+ vxi, vxi->vx_id, pid, sig);
22062+ read_lock(&tasklist_lock);
22063+ switch (pid) {
22064+ case 0:
22065+ case -1:
22066+ for_each_process(p) {
22067+ int err = 0;
22068+
22069+ if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22070+ (pid && vxi->vx_initpid == p->pid))
22071+ continue;
22072+
22073+ err = group_send_sig_info(sig, sip, p);
22074+ ++count;
22075+ if (err != -EPERM)
22076+ retval = err;
22077+ }
22078+ break;
22079+
22080+ case 1:
22081+ if (vxi->vx_initpid) {
22082+ pid = vxi->vx_initpid;
22083+ /* for now, only SIGINT to private init ... */
22084+ if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22085+ /* ... as long as there are tasks left */
22086+ (atomic_read(&vxi->vx_tasks) > 1))
22087+ sig = SIGINT;
22088+ }
22089+ /* fallthrough */
22090+ default:
22091+ rcu_read_lock();
22092+ p = find_task_by_real_pid(pid);
22093+ rcu_read_unlock();
22094+ if (p) {
22095+ if (vx_task_xid(p) == vxi->vx_id)
22096+ retval = group_send_sig_info(sig, sip, p);
22097+ }
22098+ break;
22099+ }
22100+ read_unlock(&tasklist_lock);
22101+ vxdprintk(VXD_CBIT(misc, 4),
22102+ "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22103+ vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22104+ return retval;
22105+}
22106+
22107+int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22108+{
22109+ struct vcmd_ctx_kill_v0 vc_data;
22110+
22111+ if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22112+ return -EFAULT;
22113+
22114+ /* special check to allow guest shutdown */
22115+ if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22116+ /* forbid killall pid=0 when init is present */
22117+ (((vc_data.pid < 1) && vxi->vx_initpid) ||
22118+ (vc_data.pid > 1)))
22119+ return -EACCES;
22120+
22121+ return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22122+}
22123+
22124+
22125+static int __wait_exit(struct vx_info *vxi)
22126+{
22127+ DECLARE_WAITQUEUE(wait, current);
22128+ int ret = 0;
22129+
22130+ add_wait_queue(&vxi->vx_wait, &wait);
22131+ set_current_state(TASK_INTERRUPTIBLE);
22132+
22133+wait:
22134+ if (vx_info_state(vxi,
22135+ VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22136+ goto out;
22137+ if (signal_pending(current)) {
22138+ ret = -ERESTARTSYS;
22139+ goto out;
22140+ }
22141+ schedule();
22142+ goto wait;
22143+
22144+out:
22145+ set_current_state(TASK_RUNNING);
22146+ remove_wait_queue(&vxi->vx_wait, &wait);
22147+ return ret;
22148+}
22149+
22150+
22151+
22152+int vc_wait_exit(struct vx_info *vxi, void __user *data)
22153+{
22154+ struct vcmd_wait_exit_v0 vc_data;
22155+ int ret;
22156+
22157+ ret = __wait_exit(vxi);
22158+ vc_data.reboot_cmd = vxi->reboot_cmd;
22159+ vc_data.exit_code = vxi->exit_code;
22160+
22161+ if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22162+ ret = -EFAULT;
22163+ return ret;
22164+}
22165+
22166diff -NurpP --minimal linux-3.6.6/kernel/vserver/space.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/space.c
22167--- linux-3.6.6/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
22168+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/space.c 2012-10-04 18:47:00.000000000 +0200
22169@@ -0,0 +1,436 @@
22170+/*
22171+ * linux/kernel/vserver/space.c
22172+ *
22173+ * Virtual Server: Context Space Support
22174+ *
22175+ * Copyright (C) 2003-2010 Herbert Pötzl
22176+ *
22177+ * V0.01 broken out from context.c 0.07
22178+ * V0.02 added task locking for namespace
22179+ * V0.03 broken out vx_enter_namespace
22180+ * V0.04 added *space support and commands
22181+ * V0.05 added credential support
22182+ *
22183+ */
22184+
22185+#include <linux/utsname.h>
22186+#include <linux/nsproxy.h>
22187+#include <linux/err.h>
22188+#include <linux/fs_struct.h>
22189+#include <linux/cred.h>
22190+#include <asm/uaccess.h>
22191+
22192+#include <linux/vs_context.h>
22193+#include <linux/vserver/space.h>
22194+#include <linux/vserver/space_cmd.h>
22195+
22196+atomic_t vs_global_nsproxy = ATOMIC_INIT(0);
22197+atomic_t vs_global_fs = ATOMIC_INIT(0);
22198+atomic_t vs_global_mnt_ns = ATOMIC_INIT(0);
22199+atomic_t vs_global_uts_ns = ATOMIC_INIT(0);
22200+atomic_t vs_global_user_ns = ATOMIC_INIT(0);
22201+atomic_t vs_global_pid_ns = ATOMIC_INIT(0);
22202+
22203+
22204+/* namespace functions */
22205+
22206+#include <linux/mnt_namespace.h>
22207+#include <linux/user_namespace.h>
22208+#include <linux/pid_namespace.h>
22209+#include <linux/ipc_namespace.h>
22210+#include <net/net_namespace.h>
22211+#include "../fs/mount.h"
22212+
22213+
22214+static const struct vcmd_space_mask_v1 space_mask_v0 = {
22215+ .mask = CLONE_FS |
22216+ CLONE_NEWNS |
22217+#ifdef CONFIG_UTS_NS
22218+ CLONE_NEWUTS |
22219+#endif
22220+#ifdef CONFIG_IPC_NS
22221+ CLONE_NEWIPC |
22222+#endif
22223+#ifdef CONFIG_USER_NS
22224+ CLONE_NEWUSER |
22225+#endif
22226+ 0
22227+};
22228+
22229+static const struct vcmd_space_mask_v1 space_mask = {
22230+ .mask = CLONE_FS |
22231+ CLONE_NEWNS |
22232+#ifdef CONFIG_UTS_NS
22233+ CLONE_NEWUTS |
22234+#endif
22235+#ifdef CONFIG_IPC_NS
22236+ CLONE_NEWIPC |
22237+#endif
22238+#ifdef CONFIG_USER_NS
22239+ CLONE_NEWUSER |
22240+#endif
22241+#ifdef CONFIG_PID_NS
22242+ CLONE_NEWPID |
22243+#endif
22244+#ifdef CONFIG_NET_NS
22245+ CLONE_NEWNET |
22246+#endif
22247+ 0
22248+};
22249+
22250+static const struct vcmd_space_mask_v1 default_space_mask = {
22251+ .mask = CLONE_FS |
22252+ CLONE_NEWNS |
22253+#ifdef CONFIG_UTS_NS
22254+ CLONE_NEWUTS |
22255+#endif
22256+#ifdef CONFIG_IPC_NS
22257+ CLONE_NEWIPC |
22258+#endif
22259+#ifdef CONFIG_USER_NS
22260+ CLONE_NEWUSER |
22261+#endif
22262+#ifdef CONFIG_PID_NS
22263+// CLONE_NEWPID |
22264+#endif
22265+ 0
22266+};
22267+
22268+/*
22269+ * build a new nsproxy mix
22270+ * assumes that both proxies are 'const'
22271+ * does not touch nsproxy refcounts
22272+ * will hold a reference on the result.
22273+ */
22274+
22275+struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22276+ struct nsproxy *new_nsproxy, unsigned long mask)
22277+{
22278+ struct mnt_namespace *old_ns;
22279+ struct uts_namespace *old_uts;
22280+ struct ipc_namespace *old_ipc;
22281+#ifdef CONFIG_PID_NS
22282+ struct pid_namespace *old_pid;
22283+#endif
22284+#ifdef CONFIG_NET_NS
22285+ struct net *old_net;
22286+#endif
22287+ struct nsproxy *nsproxy;
22288+
22289+ nsproxy = copy_nsproxy(old_nsproxy);
22290+ if (!nsproxy)
22291+ goto out;
22292+
22293+ if (mask & CLONE_NEWNS) {
22294+ old_ns = nsproxy->mnt_ns;
22295+ nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22296+ if (nsproxy->mnt_ns)
22297+ get_mnt_ns(nsproxy->mnt_ns);
22298+ } else
22299+ old_ns = NULL;
22300+
22301+ if (mask & CLONE_NEWUTS) {
22302+ old_uts = nsproxy->uts_ns;
22303+ nsproxy->uts_ns = new_nsproxy->uts_ns;
22304+ if (nsproxy->uts_ns)
22305+ get_uts_ns(nsproxy->uts_ns);
22306+ } else
22307+ old_uts = NULL;
22308+
22309+ if (mask & CLONE_NEWIPC) {
22310+ old_ipc = nsproxy->ipc_ns;
22311+ nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22312+ if (nsproxy->ipc_ns)
22313+ get_ipc_ns(nsproxy->ipc_ns);
22314+ } else
22315+ old_ipc = NULL;
22316+
22317+#ifdef CONFIG_PID_NS
22318+ if (mask & CLONE_NEWPID) {
22319+ old_pid = nsproxy->pid_ns;
22320+ nsproxy->pid_ns = new_nsproxy->pid_ns;
22321+ if (nsproxy->pid_ns)
22322+ get_pid_ns(nsproxy->pid_ns);
22323+ } else
22324+ old_pid = NULL;
22325+#endif
22326+#ifdef CONFIG_NET_NS
22327+ if (mask & CLONE_NEWNET) {
22328+ old_net = nsproxy->net_ns;
22329+ nsproxy->net_ns = new_nsproxy->net_ns;
22330+ if (nsproxy->net_ns)
22331+ get_net(nsproxy->net_ns);
22332+ } else
22333+ old_net = NULL;
22334+#endif
22335+ if (old_ns)
22336+ put_mnt_ns(old_ns);
22337+ if (old_uts)
22338+ put_uts_ns(old_uts);
22339+ if (old_ipc)
22340+ put_ipc_ns(old_ipc);
22341+#ifdef CONFIG_PID_NS
22342+ if (old_pid)
22343+ put_pid_ns(old_pid);
22344+#endif
22345+#ifdef CONFIG_NET_NS
22346+ if (old_net)
22347+ put_net(old_net);
22348+#endif
22349+out:
22350+ return nsproxy;
22351+}
22352+
22353+
22354+/*
22355+ * merge two nsproxy structs into a new one.
22356+ * will hold a reference on the result.
22357+ */
22358+
22359+static inline
22360+struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22361+ struct nsproxy *proxy, unsigned long mask)
22362+{
22363+ struct nsproxy null_proxy = { .mnt_ns = NULL };
22364+
22365+ if (!proxy)
22366+ return NULL;
22367+
22368+ if (mask) {
22369+ /* vs_mix_nsproxy returns with reference */
22370+ return vs_mix_nsproxy(old ? old : &null_proxy,
22371+ proxy, mask);
22372+ }
22373+ get_nsproxy(proxy);
22374+ return proxy;
22375+}
22376+
22377+
22378+int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22379+{
22380+ struct nsproxy *proxy, *proxy_cur, *proxy_new;
22381+ struct fs_struct *fs_cur, *fs = NULL;
22382+ struct _vx_space *space;
22383+ int ret, kill = 0;
22384+
22385+ vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22386+ vxi, vxi->vx_id, mask, index);
22387+
22388+ if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22389+ return -EACCES;
22390+
22391+ if (index >= VX_SPACES)
22392+ return -EINVAL;
22393+
22394+ space = &vxi->space[index];
22395+
22396+ if (!mask)
22397+ mask = space->vx_nsmask;
22398+
22399+ if ((mask & space->vx_nsmask) != mask)
22400+ return -EINVAL;
22401+
22402+ if (mask & CLONE_FS) {
22403+ fs = copy_fs_struct(space->vx_fs);
22404+ if (!fs)
22405+ return -ENOMEM;
22406+ }
22407+ proxy = space->vx_nsproxy;
22408+
22409+ vxdprintk(VXD_CBIT(space, 9),
22410+ "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22411+ vxi, vxi->vx_id, mask, index, proxy, fs);
22412+
22413+ task_lock(current);
22414+ fs_cur = current->fs;
22415+
22416+ if (mask & CLONE_FS) {
22417+ spin_lock(&fs_cur->lock);
22418+ current->fs = fs;
22419+ kill = !--fs_cur->users;
22420+ spin_unlock(&fs_cur->lock);
22421+ }
22422+
22423+ proxy_cur = current->nsproxy;
22424+ get_nsproxy(proxy_cur);
22425+ task_unlock(current);
22426+
22427+ if (kill)
22428+ free_fs_struct(fs_cur);
22429+
22430+ proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22431+ if (IS_ERR(proxy_new)) {
22432+ ret = PTR_ERR(proxy_new);
22433+ goto out_put;
22434+ }
22435+
22436+ proxy_new = xchg(&current->nsproxy, proxy_new);
22437+
22438+ if (mask & CLONE_NEWUSER) {
22439+ struct cred *cred;
22440+
22441+ vxdprintk(VXD_CBIT(space, 10),
22442+ "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22443+ vxi, vxi->vx_id, space->vx_cred,
22444+ current->real_cred, current->cred);
22445+
22446+ if (space->vx_cred) {
22447+ cred = __prepare_creds(space->vx_cred);
22448+ if (cred)
22449+ commit_creds(cred);
22450+ }
22451+ }
22452+
22453+ ret = 0;
22454+
22455+ if (proxy_new)
22456+ put_nsproxy(proxy_new);
22457+out_put:
22458+ if (proxy_cur)
22459+ put_nsproxy(proxy_cur);
22460+ return ret;
22461+}
22462+
22463+
22464+int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22465+{
22466+ struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22467+ struct fs_struct *fs_vxi, *fs;
22468+ struct _vx_space *space;
22469+ int ret, kill = 0;
22470+
22471+ vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22472+ vxi, vxi->vx_id, mask, index);
22473+
22474+ if ((mask & space_mask.mask) != mask)
22475+ return -EINVAL;
22476+
22477+ if (index >= VX_SPACES)
22478+ return -EINVAL;
22479+
22480+ space = &vxi->space[index];
22481+
22482+ proxy_vxi = space->vx_nsproxy;
22483+ fs_vxi = space->vx_fs;
22484+
22485+ if (mask & CLONE_FS) {
22486+ fs = copy_fs_struct(current->fs);
22487+ if (!fs)
22488+ return -ENOMEM;
22489+ }
22490+
22491+ task_lock(current);
22492+
22493+ if (mask & CLONE_FS) {
22494+ spin_lock(&fs_vxi->lock);
22495+ space->vx_fs = fs;
22496+ kill = !--fs_vxi->users;
22497+ spin_unlock(&fs_vxi->lock);
22498+ }
22499+
22500+ proxy_cur = current->nsproxy;
22501+ get_nsproxy(proxy_cur);
22502+ task_unlock(current);
22503+
22504+ if (kill)
22505+ free_fs_struct(fs_vxi);
22506+
22507+ proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22508+ if (IS_ERR(proxy_new)) {
22509+ ret = PTR_ERR(proxy_new);
22510+ goto out_put;
22511+ }
22512+
22513+ proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22514+ space->vx_nsmask |= mask;
22515+
22516+ if (mask & CLONE_NEWUSER) {
22517+ struct cred *cred;
22518+
22519+ vxdprintk(VXD_CBIT(space, 10),
22520+ "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22521+ vxi, vxi->vx_id, space->vx_cred,
22522+ current->real_cred, current->cred);
22523+
22524+ cred = prepare_creds();
22525+ cred = (struct cred *)xchg(&space->vx_cred, cred);
22526+ if (cred)
22527+ abort_creds(cred);
22528+ }
22529+
22530+ ret = 0;
22531+
22532+ if (proxy_new)
22533+ put_nsproxy(proxy_new);
22534+out_put:
22535+ if (proxy_cur)
22536+ put_nsproxy(proxy_cur);
22537+ return ret;
22538+}
22539+
22540+
22541+int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22542+{
22543+ struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22544+
22545+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22546+ return -EFAULT;
22547+
22548+ return vx_enter_space(vxi, vc_data.mask, 0);
22549+}
22550+
22551+int vc_enter_space(struct vx_info *vxi, void __user *data)
22552+{
22553+ struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22554+
22555+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22556+ return -EFAULT;
22557+
22558+ if (vc_data.index >= VX_SPACES)
22559+ return -EINVAL;
22560+
22561+ return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22562+}
22563+
22564+int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22565+{
22566+ struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22567+
22568+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22569+ return -EFAULT;
22570+
22571+ return vx_set_space(vxi, vc_data.mask, 0);
22572+}
22573+
22574+int vc_set_space(struct vx_info *vxi, void __user *data)
22575+{
22576+ struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22577+
22578+ if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22579+ return -EFAULT;
22580+
22581+ if (vc_data.index >= VX_SPACES)
22582+ return -EINVAL;
22583+
22584+ return vx_set_space(vxi, vc_data.mask, vc_data.index);
22585+}
22586+
22587+int vc_get_space_mask(void __user *data, int type)
22588+{
22589+ const struct vcmd_space_mask_v1 *mask;
22590+
22591+ if (type == 0)
22592+ mask = &space_mask_v0;
22593+ else if (type == 1)
22594+ mask = &space_mask;
22595+ else
22596+ mask = &default_space_mask;
22597+
22598+ vxdprintk(VXD_CBIT(space, 10),
22599+ "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22600+
22601+ if (copy_to_user(data, mask, sizeof(*mask)))
22602+ return -EFAULT;
22603+ return 0;
22604+}
22605+
22606diff -NurpP --minimal linux-3.6.6/kernel/vserver/switch.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/switch.c
22607--- linux-3.6.6/kernel/vserver/switch.c 1970-01-01 01:00:00.000000000 +0100
22608+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/switch.c 2012-10-04 18:47:00.000000000 +0200
22609@@ -0,0 +1,556 @@
22610+/*
22611+ * linux/kernel/vserver/switch.c
22612+ *
22613+ * Virtual Server: Syscall Switch
22614+ *
22615+ * Copyright (C) 2003-2011 Herbert Pötzl
22616+ *
22617+ * V0.01 syscall switch
22618+ * V0.02 added signal to context
22619+ * V0.03 added rlimit functions
22620+ * V0.04 added iattr, task/xid functions
22621+ * V0.05 added debug/history stuff
22622+ * V0.06 added compat32 layer
22623+ * V0.07 vcmd args and perms
22624+ * V0.08 added status commands
22625+ * V0.09 added tag commands
22626+ * V0.10 added oom bias
22627+ * V0.11 added device commands
22628+ * V0.12 added warn mask
22629+ *
22630+ */
22631+
22632+#include <linux/vs_context.h>
22633+#include <linux/vs_network.h>
22634+#include <linux/vserver/switch.h>
22635+
22636+#include "vci_config.h"
22637+
22638+
22639+static inline
22640+int vc_get_version(uint32_t id)
22641+{
22642+ return VCI_VERSION;
22643+}
22644+
22645+static inline
22646+int vc_get_vci(uint32_t id)
22647+{
22648+ return vci_kernel_config();
22649+}
22650+
22651+#include <linux/vserver/context_cmd.h>
22652+#include <linux/vserver/cvirt_cmd.h>
22653+#include <linux/vserver/cacct_cmd.h>
22654+#include <linux/vserver/limit_cmd.h>
22655+#include <linux/vserver/network_cmd.h>
22656+#include <linux/vserver/sched_cmd.h>
22657+#include <linux/vserver/debug_cmd.h>
22658+#include <linux/vserver/inode_cmd.h>
22659+#include <linux/vserver/dlimit_cmd.h>
22660+#include <linux/vserver/signal_cmd.h>
22661+#include <linux/vserver/space_cmd.h>
22662+#include <linux/vserver/tag_cmd.h>
22663+#include <linux/vserver/device_cmd.h>
22664+
22665+#include <linux/vserver/inode.h>
22666+#include <linux/vserver/dlimit.h>
22667+
22668+
22669+#ifdef CONFIG_COMPAT
22670+#define __COMPAT(name, id, data, compat) \
22671+ (compat) ? name ## _x32(id, data) : name(id, data)
22672+#define __COMPAT_NO_ID(name, data, compat) \
22673+ (compat) ? name ## _x32(data) : name(data)
22674+#else
22675+#define __COMPAT(name, id, data, compat) \
22676+ name(id, data)
22677+#define __COMPAT_NO_ID(name, data, compat) \
22678+ name(data)
22679+#endif
22680+
22681+
22682+static inline
22683+long do_vcmd(uint32_t cmd, uint32_t id,
22684+ struct vx_info *vxi, struct nx_info *nxi,
22685+ void __user *data, int compat)
22686+{
22687+ switch (cmd) {
22688+
22689+ case VCMD_get_version:
22690+ return vc_get_version(id);
22691+ case VCMD_get_vci:
22692+ return vc_get_vci(id);
22693+
22694+ case VCMD_task_xid:
22695+ return vc_task_xid(id);
22696+ case VCMD_vx_info:
22697+ return vc_vx_info(vxi, data);
22698+
22699+ case VCMD_task_nid:
22700+ return vc_task_nid(id);
22701+ case VCMD_nx_info:
22702+ return vc_nx_info(nxi, data);
22703+
22704+ case VCMD_task_tag:
22705+ return vc_task_tag(id);
22706+
22707+ case VCMD_set_space_v1:
22708+ return vc_set_space_v1(vxi, data);
22709+ /* this is version 2 */
22710+ case VCMD_set_space:
22711+ return vc_set_space(vxi, data);
22712+
22713+ case VCMD_get_space_mask_v0:
22714+ return vc_get_space_mask(data, 0);
22715+ /* this is version 1 */
22716+ case VCMD_get_space_mask:
22717+ return vc_get_space_mask(data, 1);
22718+
22719+ case VCMD_get_space_default:
22720+ return vc_get_space_mask(data, -1);
22721+
22722+ case VCMD_set_umask:
22723+ return vc_set_umask(vxi, data);
22724+
22725+ case VCMD_get_umask:
22726+ return vc_get_umask(vxi, data);
22727+
22728+ case VCMD_set_wmask:
22729+ return vc_set_wmask(vxi, data);
22730+
22731+ case VCMD_get_wmask:
22732+ return vc_get_wmask(vxi, data);
22733+#ifdef CONFIG_IA32_EMULATION
22734+ case VCMD_get_rlimit:
22735+ return __COMPAT(vc_get_rlimit, vxi, data, compat);
22736+ case VCMD_set_rlimit:
22737+ return __COMPAT(vc_set_rlimit, vxi, data, compat);
22738+#else
22739+ case VCMD_get_rlimit:
22740+ return vc_get_rlimit(vxi, data);
22741+ case VCMD_set_rlimit:
22742+ return vc_set_rlimit(vxi, data);
22743+#endif
22744+ case VCMD_get_rlimit_mask:
22745+ return vc_get_rlimit_mask(id, data);
22746+ case VCMD_reset_hits:
22747+ return vc_reset_hits(vxi, data);
22748+ case VCMD_reset_minmax:
22749+ return vc_reset_minmax(vxi, data);
22750+
22751+ case VCMD_get_vhi_name:
22752+ return vc_get_vhi_name(vxi, data);
22753+ case VCMD_set_vhi_name:
22754+ return vc_set_vhi_name(vxi, data);
22755+
22756+ case VCMD_ctx_stat:
22757+ return vc_ctx_stat(vxi, data);
22758+ case VCMD_virt_stat:
22759+ return vc_virt_stat(vxi, data);
22760+ case VCMD_sock_stat:
22761+ return vc_sock_stat(vxi, data);
22762+ case VCMD_rlimit_stat:
22763+ return vc_rlimit_stat(vxi, data);
22764+
22765+ case VCMD_set_cflags:
22766+ return vc_set_cflags(vxi, data);
22767+ case VCMD_get_cflags:
22768+ return vc_get_cflags(vxi, data);
22769+
22770+ /* this is version 1 */
22771+ case VCMD_set_ccaps:
22772+ return vc_set_ccaps(vxi, data);
22773+ /* this is version 1 */
22774+ case VCMD_get_ccaps:
22775+ return vc_get_ccaps(vxi, data);
22776+ case VCMD_set_bcaps:
22777+ return vc_set_bcaps(vxi, data);
22778+ case VCMD_get_bcaps:
22779+ return vc_get_bcaps(vxi, data);
22780+
22781+ case VCMD_set_badness:
22782+ return vc_set_badness(vxi, data);
22783+ case VCMD_get_badness:
22784+ return vc_get_badness(vxi, data);
22785+
22786+ case VCMD_set_nflags:
22787+ return vc_set_nflags(nxi, data);
22788+ case VCMD_get_nflags:
22789+ return vc_get_nflags(nxi, data);
22790+
22791+ case VCMD_set_ncaps:
22792+ return vc_set_ncaps(nxi, data);
22793+ case VCMD_get_ncaps:
22794+ return vc_get_ncaps(nxi, data);
22795+
22796+ case VCMD_set_prio_bias:
22797+ return vc_set_prio_bias(vxi, data);
22798+ case VCMD_get_prio_bias:
22799+ return vc_get_prio_bias(vxi, data);
22800+ case VCMD_add_dlimit:
22801+ return __COMPAT(vc_add_dlimit, id, data, compat);
22802+ case VCMD_rem_dlimit:
22803+ return __COMPAT(vc_rem_dlimit, id, data, compat);
22804+ case VCMD_set_dlimit:
22805+ return __COMPAT(vc_set_dlimit, id, data, compat);
22806+ case VCMD_get_dlimit:
22807+ return __COMPAT(vc_get_dlimit, id, data, compat);
22808+
22809+ case VCMD_ctx_kill:
22810+ return vc_ctx_kill(vxi, data);
22811+
22812+ case VCMD_wait_exit:
22813+ return vc_wait_exit(vxi, data);
22814+
22815+ case VCMD_get_iattr:
22816+ return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22817+ case VCMD_set_iattr:
22818+ return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22819+
22820+ case VCMD_fget_iattr:
22821+ return vc_fget_iattr(id, data);
22822+ case VCMD_fset_iattr:
22823+ return vc_fset_iattr(id, data);
22824+
22825+ case VCMD_enter_space_v0:
22826+ return vc_enter_space_v1(vxi, NULL);
22827+ case VCMD_enter_space_v1:
22828+ return vc_enter_space_v1(vxi, data);
22829+ /* this is version 2 */
22830+ case VCMD_enter_space:
22831+ return vc_enter_space(vxi, data);
22832+
22833+ case VCMD_ctx_create_v0:
22834+ return vc_ctx_create(id, NULL);
22835+ case VCMD_ctx_create:
22836+ return vc_ctx_create(id, data);
22837+ case VCMD_ctx_migrate_v0:
22838+ return vc_ctx_migrate(vxi, NULL);
22839+ case VCMD_ctx_migrate:
22840+ return vc_ctx_migrate(vxi, data);
22841+
22842+ case VCMD_net_create_v0:
22843+ return vc_net_create(id, NULL);
22844+ case VCMD_net_create:
22845+ return vc_net_create(id, data);
22846+ case VCMD_net_migrate:
22847+ return vc_net_migrate(nxi, data);
22848+
22849+ case VCMD_tag_migrate:
22850+ return vc_tag_migrate(id);
22851+
22852+ case VCMD_net_add:
22853+ return vc_net_add(nxi, data);
22854+ case VCMD_net_remove:
22855+ return vc_net_remove(nxi, data);
22856+
22857+ case VCMD_net_add_ipv4_v1:
22858+ return vc_net_add_ipv4_v1(nxi, data);
22859+ /* this is version 2 */
22860+ case VCMD_net_add_ipv4:
22861+ return vc_net_add_ipv4(nxi, data);
22862+
22863+ case VCMD_net_rem_ipv4_v1:
22864+ return vc_net_rem_ipv4_v1(nxi, data);
22865+ /* this is version 2 */
22866+ case VCMD_net_rem_ipv4:
22867+ return vc_net_rem_ipv4(nxi, data);
22868+#ifdef CONFIG_IPV6
22869+ case VCMD_net_add_ipv6:
22870+ return vc_net_add_ipv6(nxi, data);
22871+ case VCMD_net_remove_ipv6:
22872+ return vc_net_remove_ipv6(nxi, data);
22873+#endif
22874+/* case VCMD_add_match_ipv4:
22875+ return vc_add_match_ipv4(nxi, data);
22876+ case VCMD_get_match_ipv4:
22877+ return vc_get_match_ipv4(nxi, data);
22878+#ifdef CONFIG_IPV6
22879+ case VCMD_add_match_ipv6:
22880+ return vc_add_match_ipv6(nxi, data);
22881+ case VCMD_get_match_ipv6:
22882+ return vc_get_match_ipv6(nxi, data);
22883+#endif */
22884+
22885+#ifdef CONFIG_VSERVER_DEVICE
22886+ case VCMD_set_mapping:
22887+ return __COMPAT(vc_set_mapping, vxi, data, compat);
22888+ case VCMD_unset_mapping:
22889+ return __COMPAT(vc_unset_mapping, vxi, data, compat);
22890+#endif
22891+#ifdef CONFIG_VSERVER_HISTORY
22892+ case VCMD_dump_history:
22893+ return vc_dump_history(id);
22894+ case VCMD_read_history:
22895+ return __COMPAT(vc_read_history, id, data, compat);
22896+#endif
22897+ default:
22898+ vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22899+ VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22900+ }
22901+ return -ENOSYS;
22902+}
22903+
22904+
22905+#define __VCMD(vcmd, _perm, _args, _flags) \
22906+ case VCMD_ ## vcmd: perm = _perm; \
22907+ args = _args; flags = _flags; break
22908+
22909+
22910+#define VCA_NONE 0x00
22911+#define VCA_VXI 0x01
22912+#define VCA_NXI 0x02
22913+
22914+#define VCF_NONE 0x00
22915+#define VCF_INFO 0x01
22916+#define VCF_ADMIN 0x02
22917+#define VCF_ARES 0x06 /* includes admin */
22918+#define VCF_SETUP 0x08
22919+
22920+#define VCF_ZIDOK 0x10 /* zero id okay */
22921+
22922+
22923+static inline
22924+long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22925+{
22926+ long ret;
22927+ int permit = -1, state = 0;
22928+ int perm = -1, args = 0, flags = 0;
22929+ struct vx_info *vxi = NULL;
22930+ struct nx_info *nxi = NULL;
22931+
22932+ switch (cmd) {
22933+ /* unpriviledged commands */
22934+ __VCMD(get_version, 0, VCA_NONE, 0);
22935+ __VCMD(get_vci, 0, VCA_NONE, 0);
22936+ __VCMD(get_rlimit_mask, 0, VCA_NONE, 0);
22937+ __VCMD(get_space_mask_v0,0, VCA_NONE, 0);
22938+ __VCMD(get_space_mask, 0, VCA_NONE, 0);
22939+ __VCMD(get_space_default,0, VCA_NONE, 0);
22940+
22941+ /* info commands */
22942+ __VCMD(task_xid, 2, VCA_NONE, 0);
22943+ __VCMD(reset_hits, 2, VCA_VXI, 0);
22944+ __VCMD(reset_minmax, 2, VCA_VXI, 0);
22945+ __VCMD(vx_info, 3, VCA_VXI, VCF_INFO);
22946+ __VCMD(get_bcaps, 3, VCA_VXI, VCF_INFO);
22947+ __VCMD(get_ccaps, 3, VCA_VXI, VCF_INFO);
22948+ __VCMD(get_cflags, 3, VCA_VXI, VCF_INFO);
22949+ __VCMD(get_umask, 3, VCA_VXI, VCF_INFO);
22950+ __VCMD(get_wmask, 3, VCA_VXI, VCF_INFO);
22951+ __VCMD(get_badness, 3, VCA_VXI, VCF_INFO);
22952+ __VCMD(get_vhi_name, 3, VCA_VXI, VCF_INFO);
22953+ __VCMD(get_rlimit, 3, VCA_VXI, VCF_INFO);
22954+
22955+ __VCMD(ctx_stat, 3, VCA_VXI, VCF_INFO);
22956+ __VCMD(virt_stat, 3, VCA_VXI, VCF_INFO);
22957+ __VCMD(sock_stat, 3, VCA_VXI, VCF_INFO);
22958+ __VCMD(rlimit_stat, 3, VCA_VXI, VCF_INFO);
22959+
22960+ __VCMD(task_nid, 2, VCA_NONE, 0);
22961+ __VCMD(nx_info, 3, VCA_NXI, VCF_INFO);
22962+ __VCMD(get_ncaps, 3, VCA_NXI, VCF_INFO);
22963+ __VCMD(get_nflags, 3, VCA_NXI, VCF_INFO);
22964+
22965+ __VCMD(task_tag, 2, VCA_NONE, 0);
22966+
22967+ __VCMD(get_iattr, 2, VCA_NONE, 0);
22968+ __VCMD(fget_iattr, 2, VCA_NONE, 0);
22969+ __VCMD(get_dlimit, 3, VCA_NONE, VCF_INFO);
22970+ __VCMD(get_prio_bias, 3, VCA_VXI, VCF_INFO);
22971+
22972+ /* lower admin commands */
22973+ __VCMD(wait_exit, 4, VCA_VXI, VCF_INFO);
22974+ __VCMD(ctx_create_v0, 5, VCA_NONE, 0);
22975+ __VCMD(ctx_create, 5, VCA_NONE, 0);
22976+ __VCMD(ctx_migrate_v0, 5, VCA_VXI, VCF_ADMIN);
22977+ __VCMD(ctx_migrate, 5, VCA_VXI, VCF_ADMIN);
22978+ __VCMD(enter_space_v0, 5, VCA_VXI, VCF_ADMIN);
22979+ __VCMD(enter_space_v1, 5, VCA_VXI, VCF_ADMIN);
22980+ __VCMD(enter_space, 5, VCA_VXI, VCF_ADMIN);
22981+
22982+ __VCMD(net_create_v0, 5, VCA_NONE, 0);
22983+ __VCMD(net_create, 5, VCA_NONE, 0);
22984+ __VCMD(net_migrate, 5, VCA_NXI, VCF_ADMIN);
22985+
22986+ __VCMD(tag_migrate, 5, VCA_NONE, VCF_ADMIN);
22987+
22988+ /* higher admin commands */
22989+ __VCMD(ctx_kill, 6, VCA_VXI, VCF_ARES);
22990+ __VCMD(set_space_v1, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22991+ __VCMD(set_space, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22992+
22993+ __VCMD(set_ccaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22994+ __VCMD(set_bcaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22995+ __VCMD(set_cflags, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22996+ __VCMD(set_umask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22997+ __VCMD(set_wmask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22998+ __VCMD(set_badness, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22999+
23000+ __VCMD(set_vhi_name, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23001+ __VCMD(set_rlimit, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23002+ __VCMD(set_prio_bias, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23003+
23004+ __VCMD(set_ncaps, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
23005+ __VCMD(set_nflags, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
23006+ __VCMD(net_add, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23007+ __VCMD(net_remove, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23008+ __VCMD(net_add_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23009+ __VCMD(net_rem_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23010+ __VCMD(net_add_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23011+ __VCMD(net_rem_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23012+#ifdef CONFIG_IPV6
23013+ __VCMD(net_add_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23014+ __VCMD(net_remove_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23015+#endif
23016+ __VCMD(set_iattr, 7, VCA_NONE, 0);
23017+ __VCMD(fset_iattr, 7, VCA_NONE, 0);
23018+ __VCMD(set_dlimit, 7, VCA_NONE, VCF_ARES);
23019+ __VCMD(add_dlimit, 8, VCA_NONE, VCF_ARES);
23020+ __VCMD(rem_dlimit, 8, VCA_NONE, VCF_ARES);
23021+
23022+#ifdef CONFIG_VSERVER_DEVICE
23023+ __VCMD(set_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
23024+ __VCMD(unset_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
23025+#endif
23026+ /* debug level admin commands */
23027+#ifdef CONFIG_VSERVER_HISTORY
23028+ __VCMD(dump_history, 9, VCA_NONE, 0);
23029+ __VCMD(read_history, 9, VCA_NONE, 0);
23030+#endif
23031+
23032+ default:
23033+ perm = -1;
23034+ }
23035+
23036+ vxdprintk(VXD_CBIT(switch, 0),
23037+ "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23038+ VC_CATEGORY(cmd), VC_COMMAND(cmd),
23039+ VC_VERSION(cmd), id, data, compat,
23040+ perm, args, flags);
23041+
23042+ ret = -ENOSYS;
23043+ if (perm < 0)
23044+ goto out;
23045+
23046+ state = 1;
23047+ if (!capable(CAP_CONTEXT))
23048+ goto out;
23049+
23050+ state = 2;
23051+ /* moved here from the individual commands */
23052+ ret = -EPERM;
23053+ if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23054+ goto out;
23055+
23056+ state = 3;
23057+ /* vcmd involves resource management */
23058+ ret = -EPERM;
23059+ if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23060+ goto out;
23061+
23062+ state = 4;
23063+ /* various legacy exceptions */
23064+ switch (cmd) {
23065+ /* will go away when spectator is a cap */
23066+ case VCMD_ctx_migrate_v0:
23067+ case VCMD_ctx_migrate:
23068+ if (id == 1) {
23069+ current->xid = 1;
23070+ ret = 1;
23071+ goto out;
23072+ }
23073+ break;
23074+
23075+ /* will go away when spectator is a cap */
23076+ case VCMD_net_migrate:
23077+ if (id == 1) {
23078+ current->nid = 1;
23079+ ret = 1;
23080+ goto out;
23081+ }
23082+ break;
23083+ }
23084+
23085+ /* vcmds are fine by default */
23086+ permit = 1;
23087+
23088+ /* admin type vcmds require admin ... */
23089+ if (flags & VCF_ADMIN)
23090+ permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23091+
23092+ /* ... but setup type vcmds override that */
23093+ if (!permit && (flags & VCF_SETUP))
23094+ permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23095+
23096+ state = 5;
23097+ ret = -EPERM;
23098+ if (!permit)
23099+ goto out;
23100+
23101+ state = 6;
23102+ if (!id && (flags & VCF_ZIDOK))
23103+ goto skip_id;
23104+
23105+ ret = -ESRCH;
23106+ if (args & VCA_VXI) {
23107+ vxi = lookup_vx_info(id);
23108+ if (!vxi)
23109+ goto out;
23110+
23111+ if ((flags & VCF_ADMIN) &&
23112+ /* special case kill for shutdown */
23113+ (cmd != VCMD_ctx_kill) &&
23114+ /* can context be administrated? */
23115+ !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23116+ ret = -EACCES;
23117+ goto out_vxi;
23118+ }
23119+ }
23120+ state = 7;
23121+ if (args & VCA_NXI) {
23122+ nxi = lookup_nx_info(id);
23123+ if (!nxi)
23124+ goto out_vxi;
23125+
23126+ if ((flags & VCF_ADMIN) &&
23127+ /* can context be administrated? */
23128+ !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23129+ ret = -EACCES;
23130+ goto out_nxi;
23131+ }
23132+ }
23133+skip_id:
23134+ state = 8;
23135+ ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23136+
23137+out_nxi:
23138+ if ((args & VCA_NXI) && nxi)
23139+ put_nx_info(nxi);
23140+out_vxi:
23141+ if ((args & VCA_VXI) && vxi)
23142+ put_vx_info(vxi);
23143+out:
23144+ vxdprintk(VXD_CBIT(switch, 1),
23145+ "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23146+ VC_CATEGORY(cmd), VC_COMMAND(cmd),
23147+ VC_VERSION(cmd), ret, ret, state, permit);
23148+ return ret;
23149+}
23150+
23151+asmlinkage long
23152+sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23153+{
23154+ return do_vserver(cmd, id, data, 0);
23155+}
23156+
23157+#ifdef CONFIG_COMPAT
23158+
23159+asmlinkage long
23160+sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23161+{
23162+ return do_vserver(cmd, id, data, 1);
23163+}
23164+
23165+#endif /* CONFIG_COMPAT */
23166diff -NurpP --minimal linux-3.6.6/kernel/vserver/sysctl.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/sysctl.c
23167--- linux-3.6.6/kernel/vserver/sysctl.c 1970-01-01 01:00:00.000000000 +0100
23168+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/sysctl.c 2012-10-04 18:47:00.000000000 +0200
23169@@ -0,0 +1,247 @@
23170+/*
23171+ * kernel/vserver/sysctl.c
23172+ *
23173+ * Virtual Context Support
23174+ *
23175+ * Copyright (C) 2004-2007 Herbert Pötzl
23176+ *
23177+ * V0.01 basic structure
23178+ *
23179+ */
23180+
23181+#include <linux/module.h>
23182+#include <linux/ctype.h>
23183+#include <linux/sysctl.h>
23184+#include <linux/parser.h>
23185+#include <asm/uaccess.h>
23186+
23187+enum {
23188+ CTL_DEBUG_ERROR = 0,
23189+ CTL_DEBUG_SWITCH = 1,
23190+ CTL_DEBUG_XID,
23191+ CTL_DEBUG_NID,
23192+ CTL_DEBUG_TAG,
23193+ CTL_DEBUG_NET,
23194+ CTL_DEBUG_LIMIT,
23195+ CTL_DEBUG_CRES,
23196+ CTL_DEBUG_DLIM,
23197+ CTL_DEBUG_QUOTA,
23198+ CTL_DEBUG_CVIRT,
23199+ CTL_DEBUG_SPACE,
23200+ CTL_DEBUG_PERM,
23201+ CTL_DEBUG_MISC,
23202+};
23203+
23204+
23205+unsigned int vs_debug_switch = 0;
23206+unsigned int vs_debug_xid = 0;
23207+unsigned int vs_debug_nid = 0;
23208+unsigned int vs_debug_tag = 0;
23209+unsigned int vs_debug_net = 0;
23210+unsigned int vs_debug_limit = 0;
23211+unsigned int vs_debug_cres = 0;
23212+unsigned int vs_debug_dlim = 0;
23213+unsigned int vs_debug_quota = 0;
23214+unsigned int vs_debug_cvirt = 0;
23215+unsigned int vs_debug_space = 0;
23216+unsigned int vs_debug_perm = 0;
23217+unsigned int vs_debug_misc = 0;
23218+
23219+
23220+static struct ctl_table_header *vserver_table_header;
23221+static ctl_table vserver_root_table[];
23222+
23223+
23224+void vserver_register_sysctl(void)
23225+{
23226+ if (!vserver_table_header) {
23227+ vserver_table_header = register_sysctl_table(vserver_root_table);
23228+ }
23229+
23230+}
23231+
23232+void vserver_unregister_sysctl(void)
23233+{
23234+ if (vserver_table_header) {
23235+ unregister_sysctl_table(vserver_table_header);
23236+ vserver_table_header = NULL;
23237+ }
23238+}
23239+
23240+
23241+static int proc_dodebug(ctl_table *table, int write,
23242+ void __user *buffer, size_t *lenp, loff_t *ppos)
23243+{
23244+ char tmpbuf[20], *p, c;
23245+ unsigned int value;
23246+ size_t left, len;
23247+
23248+ if ((*ppos && !write) || !*lenp) {
23249+ *lenp = 0;
23250+ return 0;
23251+ }
23252+
23253+ left = *lenp;
23254+
23255+ if (write) {
23256+ if (!access_ok(VERIFY_READ, buffer, left))
23257+ return -EFAULT;
23258+ p = (char *)buffer;
23259+ while (left && __get_user(c, p) >= 0 && isspace(c))
23260+ left--, p++;
23261+ if (!left)
23262+ goto done;
23263+
23264+ if (left > sizeof(tmpbuf) - 1)
23265+ return -EINVAL;
23266+ if (copy_from_user(tmpbuf, p, left))
23267+ return -EFAULT;
23268+ tmpbuf[left] = '\0';
23269+
23270+ for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23271+ value = 10 * value + (*p - '0');
23272+ if (*p && !isspace(*p))
23273+ return -EINVAL;
23274+ while (left && isspace(*p))
23275+ left--, p++;
23276+ *(unsigned int *)table->data = value;
23277+ } else {
23278+ if (!access_ok(VERIFY_WRITE, buffer, left))
23279+ return -EFAULT;
23280+ len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23281+ if (len > left)
23282+ len = left;
23283+ if (__copy_to_user(buffer, tmpbuf, len))
23284+ return -EFAULT;
23285+ if ((left -= len) > 0) {
23286+ if (put_user('\n', (char *)buffer + len))
23287+ return -EFAULT;
23288+ left--;
23289+ }
23290+ }
23291+
23292+done:
23293+ *lenp -= left;
23294+ *ppos += *lenp;
23295+ return 0;
23296+}
23297+
23298+static int zero;
23299+
23300+#define CTL_ENTRY(ctl, name) \
23301+ { \
23302+ .procname = #name, \
23303+ .data = &vs_ ## name, \
23304+ .maxlen = sizeof(int), \
23305+ .mode = 0644, \
23306+ .proc_handler = &proc_dodebug, \
23307+ .extra1 = &zero, \
23308+ .extra2 = &zero, \
23309+ }
23310+
23311+static ctl_table vserver_debug_table[] = {
23312+ CTL_ENTRY(CTL_DEBUG_SWITCH, debug_switch),
23313+ CTL_ENTRY(CTL_DEBUG_XID, debug_xid),
23314+ CTL_ENTRY(CTL_DEBUG_NID, debug_nid),
23315+ CTL_ENTRY(CTL_DEBUG_TAG, debug_tag),
23316+ CTL_ENTRY(CTL_DEBUG_NET, debug_net),
23317+ CTL_ENTRY(CTL_DEBUG_LIMIT, debug_limit),
23318+ CTL_ENTRY(CTL_DEBUG_CRES, debug_cres),
23319+ CTL_ENTRY(CTL_DEBUG_DLIM, debug_dlim),
23320+ CTL_ENTRY(CTL_DEBUG_QUOTA, debug_quota),
23321+ CTL_ENTRY(CTL_DEBUG_CVIRT, debug_cvirt),
23322+ CTL_ENTRY(CTL_DEBUG_SPACE, debug_space),
23323+ CTL_ENTRY(CTL_DEBUG_PERM, debug_perm),
23324+ CTL_ENTRY(CTL_DEBUG_MISC, debug_misc),
23325+ { 0 }
23326+};
23327+
23328+static ctl_table vserver_root_table[] = {
23329+ {
23330+ .procname = "vserver",
23331+ .mode = 0555,
23332+ .child = vserver_debug_table
23333+ },
23334+ { 0 }
23335+};
23336+
23337+
23338+static match_table_t tokens = {
23339+ { CTL_DEBUG_SWITCH, "switch=%x" },
23340+ { CTL_DEBUG_XID, "xid=%x" },
23341+ { CTL_DEBUG_NID, "nid=%x" },
23342+ { CTL_DEBUG_TAG, "tag=%x" },
23343+ { CTL_DEBUG_NET, "net=%x" },
23344+ { CTL_DEBUG_LIMIT, "limit=%x" },
23345+ { CTL_DEBUG_CRES, "cres=%x" },
23346+ { CTL_DEBUG_DLIM, "dlim=%x" },
23347+ { CTL_DEBUG_QUOTA, "quota=%x" },
23348+ { CTL_DEBUG_CVIRT, "cvirt=%x" },
23349+ { CTL_DEBUG_SPACE, "space=%x" },
23350+ { CTL_DEBUG_PERM, "perm=%x" },
23351+ { CTL_DEBUG_MISC, "misc=%x" },
23352+ { CTL_DEBUG_ERROR, NULL }
23353+};
23354+
23355+#define HANDLE_CASE(id, name, val) \
23356+ case CTL_DEBUG_ ## id: \
23357+ vs_debug_ ## name = val; \
23358+ printk("vs_debug_" #name "=0x%x\n", val); \
23359+ break
23360+
23361+
23362+static int __init vs_debug_setup(char *str)
23363+{
23364+ char *p;
23365+ int token;
23366+
23367+ printk("vs_debug_setup(%s)\n", str);
23368+ while ((p = strsep(&str, ",")) != NULL) {
23369+ substring_t args[MAX_OPT_ARGS];
23370+ unsigned int value;
23371+
23372+ if (!*p)
23373+ continue;
23374+
23375+ token = match_token(p, tokens, args);
23376+ value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23377+
23378+ switch (token) {
23379+ HANDLE_CASE(SWITCH, switch, value);
23380+ HANDLE_CASE(XID, xid, value);
23381+ HANDLE_CASE(NID, nid, value);
23382+ HANDLE_CASE(TAG, tag, value);
23383+ HANDLE_CASE(NET, net, value);
23384+ HANDLE_CASE(LIMIT, limit, value);
23385+ HANDLE_CASE(CRES, cres, value);
23386+ HANDLE_CASE(DLIM, dlim, value);
23387+ HANDLE_CASE(QUOTA, quota, value);
23388+ HANDLE_CASE(CVIRT, cvirt, value);
23389+ HANDLE_CASE(SPACE, space, value);
23390+ HANDLE_CASE(PERM, perm, value);
23391+ HANDLE_CASE(MISC, misc, value);
23392+ default:
23393+ return -EINVAL;
23394+ break;
23395+ }
23396+ }
23397+ return 1;
23398+}
23399+
23400+__setup("vsdebug=", vs_debug_setup);
23401+
23402+
23403+
23404+EXPORT_SYMBOL_GPL(vs_debug_switch);
23405+EXPORT_SYMBOL_GPL(vs_debug_xid);
23406+EXPORT_SYMBOL_GPL(vs_debug_nid);
23407+EXPORT_SYMBOL_GPL(vs_debug_net);
23408+EXPORT_SYMBOL_GPL(vs_debug_limit);
23409+EXPORT_SYMBOL_GPL(vs_debug_cres);
23410+EXPORT_SYMBOL_GPL(vs_debug_dlim);
23411+EXPORT_SYMBOL_GPL(vs_debug_quota);
23412+EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23413+EXPORT_SYMBOL_GPL(vs_debug_space);
23414+EXPORT_SYMBOL_GPL(vs_debug_perm);
23415+EXPORT_SYMBOL_GPL(vs_debug_misc);
23416+
23417diff -NurpP --minimal linux-3.6.6/kernel/vserver/tag.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/tag.c
23418--- linux-3.6.6/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
23419+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/tag.c 2012-10-04 18:47:00.000000000 +0200
23420@@ -0,0 +1,63 @@
23421+/*
23422+ * linux/kernel/vserver/tag.c
23423+ *
23424+ * Virtual Server: Shallow Tag Space
23425+ *
23426+ * Copyright (C) 2007 Herbert Pötzl
23427+ *
23428+ * V0.01 basic implementation
23429+ *
23430+ */
23431+
23432+#include <linux/sched.h>
23433+#include <linux/vserver/debug.h>
23434+#include <linux/vs_pid.h>
23435+#include <linux/vs_tag.h>
23436+
23437+#include <linux/vserver/tag_cmd.h>
23438+
23439+
23440+int dx_migrate_task(struct task_struct *p, tag_t tag)
23441+{
23442+ if (!p)
23443+ BUG();
23444+
23445+ vxdprintk(VXD_CBIT(tag, 5),
23446+ "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23447+
23448+ task_lock(p);
23449+ p->tag = tag;
23450+ task_unlock(p);
23451+
23452+ vxdprintk(VXD_CBIT(tag, 5),
23453+ "moved task %p into [#%d]", p, tag);
23454+ return 0;
23455+}
23456+
23457+/* vserver syscall commands below here */
23458+
23459+/* taks xid and vx_info functions */
23460+
23461+
23462+int vc_task_tag(uint32_t id)
23463+{
23464+ tag_t tag;
23465+
23466+ if (id) {
23467+ struct task_struct *tsk;
23468+ rcu_read_lock();
23469+ tsk = find_task_by_real_pid(id);
23470+ tag = (tsk) ? tsk->tag : -ESRCH;
23471+ rcu_read_unlock();
23472+ } else
23473+ tag = dx_current_tag();
23474+ return tag;
23475+}
23476+
23477+
23478+int vc_tag_migrate(uint32_t tag)
23479+{
23480+ return dx_migrate_task(current, tag & 0xFFFF);
23481+}
23482+
23483+
23484diff -NurpP --minimal linux-3.6.6/kernel/vserver/vci_config.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/vci_config.h
23485--- linux-3.6.6/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
23486+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/kernel/vserver/vci_config.h 2012-10-04 18:47:00.000000000 +0200
23487@@ -0,0 +1,76 @@
23488+
23489+/* interface version */
23490+
23491+#define VCI_VERSION 0x00020308
23492+
23493+
23494+enum {
23495+ VCI_KCBIT_NO_DYNAMIC = 0,
23496+
23497+ VCI_KCBIT_PROC_SECURE = 4,
23498+ /* VCI_KCBIT_HARDCPU = 5, */
23499+ /* VCI_KCBIT_IDLELIMIT = 6, */
23500+ /* VCI_KCBIT_IDLETIME = 7, */
23501+
23502+ VCI_KCBIT_COWBL = 8,
23503+ VCI_KCBIT_FULLCOWBL = 9,
23504+ VCI_KCBIT_SPACES = 10,
23505+ VCI_KCBIT_NETV2 = 11,
23506+ VCI_KCBIT_MEMCG = 12,
23507+
23508+ VCI_KCBIT_DEBUG = 16,
23509+ VCI_KCBIT_HISTORY = 20,
23510+ VCI_KCBIT_TAGGED = 24,
23511+ VCI_KCBIT_PPTAG = 28,
23512+
23513+ VCI_KCBIT_MORE = 31,
23514+};
23515+
23516+
23517+static inline uint32_t vci_kernel_config(void)
23518+{
23519+ return
23520+ (1 << VCI_KCBIT_NO_DYNAMIC) |
23521+
23522+ /* configured features */
23523+#ifdef CONFIG_VSERVER_PROC_SECURE
23524+ (1 << VCI_KCBIT_PROC_SECURE) |
23525+#endif
23526+#ifdef CONFIG_VSERVER_COWBL
23527+ (1 << VCI_KCBIT_COWBL) |
23528+ (1 << VCI_KCBIT_FULLCOWBL) |
23529+#endif
23530+ (1 << VCI_KCBIT_SPACES) |
23531+ (1 << VCI_KCBIT_NETV2) |
23532+#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23533+ (1 << VCI_KCBIT_MEMCG) |
23534+#endif
23535+
23536+ /* debug options */
23537+#ifdef CONFIG_VSERVER_DEBUG
23538+ (1 << VCI_KCBIT_DEBUG) |
23539+#endif
23540+#ifdef CONFIG_VSERVER_HISTORY
23541+ (1 << VCI_KCBIT_HISTORY) |
23542+#endif
23543+
23544+ /* inode context tagging */
23545+#if defined(CONFIG_TAGGING_NONE)
23546+ (0 << VCI_KCBIT_TAGGED) |
23547+#elif defined(CONFIG_TAGGING_UID16)
23548+ (1 << VCI_KCBIT_TAGGED) |
23549+#elif defined(CONFIG_TAGGING_GID16)
23550+ (2 << VCI_KCBIT_TAGGED) |
23551+#elif defined(CONFIG_TAGGING_ID24)
23552+ (3 << VCI_KCBIT_TAGGED) |
23553+#elif defined(CONFIG_TAGGING_INTERN)
23554+ (4 << VCI_KCBIT_TAGGED) |
23555+#elif defined(CONFIG_TAGGING_RUNTIME)
23556+ (5 << VCI_KCBIT_TAGGED) |
23557+#else
23558+ (7 << VCI_KCBIT_TAGGED) |
23559+#endif
23560+ (1 << VCI_KCBIT_PPTAG) |
23561+ 0;
23562+}
23563+
23564diff -NurpP --minimal linux-3.6.6/mm/memcontrol.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/memcontrol.c
23565--- linux-3.6.6/mm/memcontrol.c 2012-10-04 15:27:48.000000000 +0200
23566+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/memcontrol.c 2012-10-04 18:47:00.000000000 +0200
23567@@ -885,6 +885,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23568 return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23569 }
23570
23571+u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23572+{
23573+ return res_counter_read_u64(&mem->res, member);
23574+}
23575+
23576+u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23577+{
23578+ return res_counter_read_u64(&mem->memsw, member);
23579+}
23580+
23581+s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23582+{
23583+ return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23584+}
23585+
23586+s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23587+{
23588+ return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23589+}
23590+
23591+s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23592+{
23593+ return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23594+}
23595+
23596 struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23597 {
23598 struct mem_cgroup *memcg = NULL;
23599diff -NurpP --minimal linux-3.6.6/mm/oom_kill.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/oom_kill.c
23600--- linux-3.6.6/mm/oom_kill.c 2012-10-04 15:27:48.000000000 +0200
23601+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/oom_kill.c 2012-10-04 18:53:46.000000000 +0200
23602@@ -35,6 +35,8 @@
23603 #include <linux/freezer.h>
23604 #include <linux/ftrace.h>
23605 #include <linux/ratelimit.h>
23606+#include <linux/reboot.h>
23607+#include <linux/vs_context.h>
23608
23609 #define CREATE_TRACE_POINTS
23610 #include <trace/events/oom.h>
23611@@ -155,11 +157,18 @@ struct task_struct *find_lock_task_mm(st
23612 static bool oom_unkillable_task(struct task_struct *p,
23613 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23614 {
23615- if (is_global_init(p))
23616+ unsigned xid = vx_current_xid();
23617+
23618+ /* skip the init task, global and per guest */
23619+ if (task_is_init(p))
23620 return true;
23621 if (p->flags & PF_KTHREAD)
23622 return true;
23623
23624+ /* skip other guest and host processes if oom in guest */
23625+ if (xid && vx_task_xid(p) != xid)
23626+ return true;
23627+
23628 /* When mem_cgroup_out_of_memory() and p is not member of the group */
23629 if (memcg && !task_in_mem_cgroup(p, memcg))
23630 return true;
23631@@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23632 dump_header(p, gfp_mask, order, memcg, nodemask);
23633
23634 task_lock(p);
23635- pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23636- message, task_pid_nr(p), p->comm, points);
23637+ pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23638+ message, task_pid_nr(p), p->xid, p->comm, points);
23639 task_unlock(p);
23640
23641 /*
23642@@ -518,8 +527,8 @@ void oom_kill_process(struct task_struct
23643
23644 /* mm cannot safely be dereferenced after task_unlock(victim) */
23645 mm = victim->mm;
23646- pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23647- task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23648+ pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23649+ task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23650 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23651 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23652 task_unlock(victim);
23653@@ -589,6 +598,8 @@ int unregister_oom_notifier(struct notif
23654 }
23655 EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23656
23657+long vs_oom_action(unsigned int);
23658+
23659 /*
23660 * Try to acquire the OOM killer lock for the zones in zonelist. Returns zero
23661 * if a parallel OOM killing is already taking place that includes a zone in
23662@@ -738,7 +749,12 @@ void out_of_memory(struct zonelist *zone
23663 /* Found nothing?!?! Either we hang forever, or we panic. */
23664 if (!p) {
23665 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23666- panic("Out of memory and no killable processes...\n");
23667+
23668+ /* avoid panic for guest OOM */
23669+ if (current->xid)
23670+ vs_oom_action(LINUX_REBOOT_CMD_OOM);
23671+ else
23672+ panic("Out of memory and no killable processes...\n");
23673 }
23674 if (PTR_ERR(p) != -1UL) {
23675 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23676diff -NurpP --minimal linux-3.6.6/mm/page_alloc.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/page_alloc.c
23677--- linux-3.6.6/mm/page_alloc.c 2012-10-04 15:27:48.000000000 +0200
23678+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/page_alloc.c 2012-10-04 18:47:00.000000000 +0200
23679@@ -58,6 +58,8 @@
23680 #include <linux/prefetch.h>
23681 #include <linux/migrate.h>
23682 #include <linux/page-debug-flags.h>
23683+#include <linux/vs_base.h>
23684+#include <linux/vs_limit.h>
23685
23686 #include <asm/tlbflush.h>
23687 #include <asm/div64.h>
23688@@ -2773,6 +2775,9 @@ void si_meminfo(struct sysinfo *val)
23689 val->totalhigh = totalhigh_pages;
23690 val->freehigh = nr_free_highpages();
23691 val->mem_unit = PAGE_SIZE;
23692+
23693+ if (vx_flags(VXF_VIRT_MEM, 0))
23694+ vx_vsi_meminfo(val);
23695 }
23696
23697 EXPORT_SYMBOL(si_meminfo);
23698@@ -2793,6 +2798,9 @@ void si_meminfo_node(struct sysinfo *val
23699 val->freehigh = 0;
23700 #endif
23701 val->mem_unit = PAGE_SIZE;
23702+
23703+ if (vx_flags(VXF_VIRT_MEM, 0))
23704+ vx_vsi_meminfo(val);
23705 }
23706 #endif
23707
23708diff -NurpP --minimal linux-3.6.6/mm/pgtable-generic.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/pgtable-generic.c
23709--- linux-3.6.6/mm/pgtable-generic.c 2012-07-22 23:39:47.000000000 +0200
23710+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/pgtable-generic.c 2012-10-04 18:47:00.000000000 +0200
23711@@ -6,6 +6,8 @@
23712 * Copyright (C) 2010 Linus Torvalds
23713 */
23714
23715+#include <linux/mm.h>
23716+
23717 #include <linux/pagemap.h>
23718 #include <asm/tlb.h>
23719 #include <asm-generic/pgtable.h>
23720diff -NurpP --minimal linux-3.6.6/mm/shmem.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/shmem.c
23721--- linux-3.6.6/mm/shmem.c 2012-11-06 18:42:14.000000000 +0100
23722+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/shmem.c 2012-11-06 18:43:41.000000000 +0100
23723@@ -1814,7 +1814,7 @@ static int shmem_statfs(struct dentry *d
23724 {
23725 struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23726
23727- buf->f_type = TMPFS_MAGIC;
23728+ buf->f_type = TMPFS_SUPER_MAGIC;
23729 buf->f_bsize = PAGE_CACHE_SIZE;
23730 buf->f_namelen = NAME_MAX;
23731 if (sbinfo->max_blocks) {
23732@@ -2632,7 +2632,7 @@ int shmem_fill_super(struct super_block
23733 sb->s_maxbytes = MAX_LFS_FILESIZE;
23734 sb->s_blocksize = PAGE_CACHE_SIZE;
23735 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23736- sb->s_magic = TMPFS_MAGIC;
23737+ sb->s_magic = TMPFS_SUPER_MAGIC;
23738 sb->s_op = &shmem_ops;
23739 sb->s_time_gran = 1;
23740 #ifdef CONFIG_TMPFS_XATTR
23741diff -NurpP --minimal linux-3.6.6/mm/slab.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/slab.c
23742--- linux-3.6.6/mm/slab.c 2012-11-06 18:42:14.000000000 +0100
23743+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/slab.c 2012-11-06 18:43:41.000000000 +0100
23744@@ -445,6 +445,8 @@ static void kmem_list3_init(struct kmem_
23745 #define STATS_INC_FREEMISS(x) do { } while (0)
23746 #endif
23747
23748+#include "slab_vs.h"
23749+
23750 #if DEBUG
23751
23752 /*
23753@@ -3539,6 +3541,7 @@ retry:
23754
23755 obj = slab_get_obj(cachep, slabp, nodeid);
23756 check_slabp(cachep, slabp);
23757+ vx_slab_alloc(cachep, flags);
23758 l3->free_objects--;
23759 /* move slabp to correct slabp list: */
23760 list_del(&slabp->list);
23761@@ -3616,6 +3619,7 @@ __cache_alloc_node(struct kmem_cache *ca
23762 /* ___cache_alloc_node can fall back to other nodes */
23763 ptr = ____cache_alloc_node(cachep, flags, nodeid);
23764 out:
23765+ vx_slab_alloc(cachep, flags);
23766 local_irq_restore(save_flags);
23767 ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23768 kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23769@@ -3806,6 +3810,7 @@ static inline void __cache_free(struct k
23770 check_irq_off();
23771 kmemleak_free_recursive(objp, cachep->flags);
23772 objp = cache_free_debugcheck(cachep, objp, caller);
23773+ vx_slab_free(cachep);
23774
23775 kmemcheck_slab_free(cachep, objp, cachep->object_size);
23776
23777diff -NurpP --minimal linux-3.6.6/mm/slab_vs.h linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/slab_vs.h
23778--- linux-3.6.6/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
23779+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/slab_vs.h 2012-10-09 16:28:11.000000000 +0200
23780@@ -0,0 +1,29 @@
23781+
23782+#include <linux/vserver/context.h>
23783+
23784+#include <linux/vs_context.h>
23785+
23786+static inline
23787+void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23788+{
23789+ int what = gfp_zone(cachep->allocflags);
23790+ struct vx_info *vxi = current_vx_info();
23791+
23792+ if (!vxi)
23793+ return;
23794+
23795+ atomic_add(cachep->size, &vxi->cacct.slab[what]);
23796+}
23797+
23798+static inline
23799+void vx_slab_free(struct kmem_cache *cachep)
23800+{
23801+ int what = gfp_zone(cachep->allocflags);
23802+ struct vx_info *vxi = current_vx_info();
23803+
23804+ if (!vxi)
23805+ return;
23806+
23807+ atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23808+}
23809+
23810diff -NurpP --minimal linux-3.6.6/mm/swapfile.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/swapfile.c
23811--- linux-3.6.6/mm/swapfile.c 2012-10-04 15:27:48.000000000 +0200
23812+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/mm/swapfile.c 2012-10-04 18:47:00.000000000 +0200
23813@@ -39,6 +39,7 @@
23814 #include <asm/tlbflush.h>
23815 #include <linux/swapops.h>
23816 #include <linux/page_cgroup.h>
23817+#include <linux/vs_base.h>
23818
23819 static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23820 unsigned char);
23821@@ -1686,6 +1687,16 @@ static int swap_show(struct seq_file *sw
23822
23823 if (si == SEQ_START_TOKEN) {
23824 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23825+ if (vx_flags(VXF_VIRT_MEM, 0)) {
23826+ struct sysinfo si;
23827+
23828+ vx_vsi_swapinfo(&si);
23829+ if (si.totalswap < (1 << 10))
23830+ return 0;
23831+ seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23832+ "hdv0", "partition", si.totalswap >> 10,
23833+ (si.totalswap - si.freeswap) >> 10, -1);
23834+ }
23835 return 0;
23836 }
23837
23838@@ -2113,6 +2124,8 @@ void si_swapinfo(struct sysinfo *val)
23839 val->freeswap = nr_swap_pages + nr_to_be_unused;
23840 val->totalswap = total_swap_pages + nr_to_be_unused;
23841 spin_unlock(&swap_lock);
23842+ if (vx_flags(VXF_VIRT_MEM, 0))
23843+ vx_vsi_swapinfo(val);
23844 }
23845
23846 /*
23847diff -NurpP --minimal linux-3.6.6/net/bridge/br_multicast.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/bridge/br_multicast.c
23848--- linux-3.6.6/net/bridge/br_multicast.c 2012-10-04 15:27:49.000000000 +0200
23849+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/bridge/br_multicast.c 2012-10-04 18:47:00.000000000 +0200
23850@@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23851 ip6h->hop_limit = 1;
23852 ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23853 if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23854- &ip6h->saddr)) {
23855+ &ip6h->saddr, NULL)) {
23856 kfree_skb(skb);
23857 return NULL;
23858 }
23859diff -NurpP --minimal linux-3.6.6/net/core/dev.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/core/dev.c
23860--- linux-3.6.6/net/core/dev.c 2012-11-06 18:42:14.000000000 +0100
23861+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/core/dev.c 2012-11-06 18:43:41.000000000 +0100
23862@@ -126,6 +126,7 @@
23863 #include <linux/in.h>
23864 #include <linux/jhash.h>
23865 #include <linux/random.h>
23866+#include <linux/vs_inet.h>
23867 #include <trace/events/napi.h>
23868 #include <trace/events/net.h>
23869 #include <trace/events/skb.h>
23870@@ -620,7 +621,8 @@ struct net_device *__dev_get_by_name(str
23871 struct hlist_head *head = dev_name_hash(net, name);
23872
23873 hlist_for_each_entry(dev, p, head, name_hlist)
23874- if (!strncmp(dev->name, name, IFNAMSIZ))
23875+ if (!strncmp(dev->name, name, IFNAMSIZ) &&
23876+ nx_dev_visible(current_nx_info(), dev))
23877 return dev;
23878
23879 return NULL;
23880@@ -646,7 +648,8 @@ struct net_device *dev_get_by_name_rcu(s
23881 struct hlist_head *head = dev_name_hash(net, name);
23882
23883 hlist_for_each_entry_rcu(dev, p, head, name_hlist)
23884- if (!strncmp(dev->name, name, IFNAMSIZ))
23885+ if (!strncmp(dev->name, name, IFNAMSIZ) &&
23886+ nx_dev_visible(current_nx_info(), dev))
23887 return dev;
23888
23889 return NULL;
23890@@ -697,7 +700,8 @@ struct net_device *__dev_get_by_index(st
23891 struct hlist_head *head = dev_index_hash(net, ifindex);
23892
23893 hlist_for_each_entry(dev, p, head, index_hlist)
23894- if (dev->ifindex == ifindex)
23895+ if ((dev->ifindex == ifindex) &&
23896+ nx_dev_visible(current_nx_info(), dev))
23897 return dev;
23898
23899 return NULL;
23900@@ -715,7 +719,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23901 * about locking. The caller must hold RCU lock.
23902 */
23903
23904-struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23905+struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23906 {
23907 struct hlist_node *p;
23908 struct net_device *dev;
23909@@ -727,6 +731,16 @@ struct net_device *dev_get_by_index_rcu(
23910
23911 return NULL;
23912 }
23913+EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23914+
23915+struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23916+{
23917+ struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23918+
23919+ if (nx_dev_visible(current_nx_info(), dev))
23920+ return dev;
23921+ return NULL;
23922+}
23923 EXPORT_SYMBOL(dev_get_by_index_rcu);
23924
23925
23926@@ -775,7 +789,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23927
23928 for_each_netdev_rcu(net, dev)
23929 if (dev->type == type &&
23930- !memcmp(dev->dev_addr, ha, dev->addr_len))
23931+ !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23932+ nx_dev_visible(current_nx_info(), dev))
23933 return dev;
23934
23935 return NULL;
23936@@ -787,9 +802,11 @@ struct net_device *__dev_getfirstbyhwtyp
23937 struct net_device *dev;
23938
23939 ASSERT_RTNL();
23940- for_each_netdev(net, dev)
23941- if (dev->type == type)
23942+ for_each_netdev(net, dev) {
23943+ if ((dev->type == type) &&
23944+ nx_dev_visible(current_nx_info(), dev))
23945 return dev;
23946+ }
23947
23948 return NULL;
23949 }
23950@@ -907,6 +924,8 @@ static int __dev_alloc_name(struct net *
23951 continue;
23952 if (i < 0 || i >= max_netdevices)
23953 continue;
23954+ if (!nx_dev_visible(current_nx_info(), d))
23955+ continue;
23956
23957 /* avoid cases where sscanf is not exact inverse of printf */
23958 snprintf(buf, IFNAMSIZ, name, i);
23959@@ -4074,6 +4093,8 @@ static int dev_ifconf(struct net *net, c
23960
23961 total = 0;
23962 for_each_netdev(net, dev) {
23963+ if (!nx_dev_visible(current_nx_info(), dev))
23964+ continue;
23965 for (i = 0; i < NPROTO; i++) {
23966 if (gifconf_list[i]) {
23967 int done;
23968@@ -4176,6 +4197,10 @@ static void dev_seq_printf_stats(struct
23969 struct rtnl_link_stats64 temp;
23970 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23971
23972+ /* device visible inside network context? */
23973+ if (!nx_dev_visible(current_nx_info(), dev))
23974+ return;
23975+
23976 seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23977 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23978 dev->name, stats->rx_bytes, stats->rx_packets,
23979diff -NurpP --minimal linux-3.6.6/net/core/rtnetlink.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/core/rtnetlink.c
23980--- linux-3.6.6/net/core/rtnetlink.c 2012-10-04 15:27:49.000000000 +0200
23981+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/core/rtnetlink.c 2012-10-04 18:47:00.000000000 +0200
23982@@ -1080,6 +1080,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23983 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
23984 if (idx < s_idx)
23985 goto cont;
23986+ if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23987+ continue;
23988 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23989 NETLINK_CB(cb->skb).pid,
23990 cb->nlh->nlmsg_seq, 0,
23991@@ -1969,6 +1971,9 @@ void rtmsg_ifinfo(int type, struct net_d
23992 int err = -ENOBUFS;
23993 size_t if_info_size;
23994
23995+ if (!nx_dev_visible(current_nx_info(), dev))
23996+ return;
23997+
23998 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
23999 if (skb == NULL)
24000 goto errout;
24001diff -NurpP --minimal linux-3.6.6/net/core/sock.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/core/sock.c
24002--- linux-3.6.6/net/core/sock.c 2012-10-04 15:27:49.000000000 +0200
24003+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/core/sock.c 2012-10-04 18:47:00.000000000 +0200
24004@@ -132,6 +132,10 @@
24005 #include <net/netprio_cgroup.h>
24006
24007 #include <linux/filter.h>
24008+#include <linux/vs_socket.h>
24009+#include <linux/vs_limit.h>
24010+#include <linux/vs_context.h>
24011+#include <linux/vs_network.h>
24012
24013 #include <trace/events/sock.h>
24014
24015@@ -1194,6 +1198,8 @@ static struct sock *sk_prot_alloc(struct
24016 goto out_free_sec;
24017 sk_tx_queue_clear(sk);
24018 }
24019+ sock_vx_init(sk);
24020+ sock_nx_init(sk);
24021
24022 return sk;
24023
24024@@ -1302,6 +1308,11 @@ static void __sk_free(struct sock *sk)
24025 put_cred(sk->sk_peer_cred);
24026 put_pid(sk->sk_peer_pid);
24027 put_net(sock_net(sk));
24028+ vx_sock_dec(sk);
24029+ clr_vx_info(&sk->sk_vx_info);
24030+ sk->sk_xid = -1;
24031+ clr_nx_info(&sk->sk_nx_info);
24032+ sk->sk_nid = -1;
24033 sk_prot_free(sk->sk_prot_creator, sk);
24034 }
24035
24036@@ -1362,6 +1373,8 @@ struct sock *sk_clone_lock(const struct
24037
24038 /* SANITY */
24039 get_net(sock_net(newsk));
24040+ sock_vx_init(newsk);
24041+ sock_nx_init(newsk);
24042 sk_node_init(&newsk->sk_node);
24043 sock_lock_init(newsk);
24044 bh_lock_sock(newsk);
24045@@ -1418,6 +1431,12 @@ struct sock *sk_clone_lock(const struct
24046 smp_wmb();
24047 atomic_set(&newsk->sk_refcnt, 2);
24048
24049+ set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24050+ newsk->sk_xid = sk->sk_xid;
24051+ vx_sock_inc(newsk);
24052+ set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24053+ newsk->sk_nid = sk->sk_nid;
24054+
24055 /*
24056 * Increment the counter in the same struct proto as the master
24057 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24058@@ -2187,6 +2206,12 @@ void sock_init_data(struct socket *sock,
24059
24060 sk->sk_stamp = ktime_set(-1L, 0);
24061
24062+ set_vx_info(&sk->sk_vx_info, current_vx_info());
24063+ sk->sk_xid = vx_current_xid();
24064+ vx_sock_inc(sk);
24065+ set_nx_info(&sk->sk_nx_info, current_nx_info());
24066+ sk->sk_nid = nx_current_nid();
24067+
24068 /*
24069 * Before updating sk_refcnt, we must commit prior changes to memory
24070 * (Documentation/RCU/rculist_nulls.txt for details)
24071diff -NurpP --minimal linux-3.6.6/net/ipv4/af_inet.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/af_inet.c
24072--- linux-3.6.6/net/ipv4/af_inet.c 2012-10-04 15:27:49.000000000 +0200
24073+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/af_inet.c 2012-10-04 18:47:00.000000000 +0200
24074@@ -118,6 +118,7 @@
24075 #ifdef CONFIG_IP_MROUTE
24076 #include <linux/mroute.h>
24077 #endif
24078+#include <linux/vs_limit.h>
24079
24080
24081 /* The inetsw table contains everything that inet_create needs to
24082@@ -326,9 +327,13 @@ lookup_protocol:
24083 }
24084
24085 err = -EPERM;
24086+ if ((protocol == IPPROTO_ICMP) &&
24087+ nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24088+ goto override;
24089+
24090 if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24091 goto out_rcu_unlock;
24092-
24093+override:
24094 err = -EAFNOSUPPORT;
24095 if (!inet_netns_ok(net, protocol))
24096 goto out_rcu_unlock;
24097@@ -453,6 +458,7 @@ int inet_bind(struct socket *sock, struc
24098 struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24099 struct sock *sk = sock->sk;
24100 struct inet_sock *inet = inet_sk(sk);
24101+ struct nx_v4_sock_addr nsa;
24102 unsigned short snum;
24103 int chk_addr_ret;
24104 int err;
24105@@ -476,7 +482,11 @@ int inet_bind(struct socket *sock, struc
24106 goto out;
24107 }
24108
24109- chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24110+ err = v4_map_sock_addr(inet, addr, &nsa);
24111+ if (err)
24112+ goto out;
24113+
24114+ chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24115
24116 /* Not specified by any standard per-se, however it breaks too
24117 * many applications when removed. It is unfortunate since
24118@@ -488,7 +498,7 @@ int inet_bind(struct socket *sock, struc
24119 err = -EADDRNOTAVAIL;
24120 if (!sysctl_ip_nonlocal_bind &&
24121 !(inet->freebind || inet->transparent) &&
24122- addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24123+ nsa.saddr != htonl(INADDR_ANY) &&
24124 chk_addr_ret != RTN_LOCAL &&
24125 chk_addr_ret != RTN_MULTICAST &&
24126 chk_addr_ret != RTN_BROADCAST)
24127@@ -513,7 +523,7 @@ int inet_bind(struct socket *sock, struc
24128 if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24129 goto out_release_sock;
24130
24131- inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24132+ v4_set_sock_addr(inet, &nsa);
24133 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24134 inet->inet_saddr = 0; /* Use device */
24135
24136@@ -731,11 +741,13 @@ int inet_getname(struct socket *sock, st
24137 peer == 1))
24138 return -ENOTCONN;
24139 sin->sin_port = inet->inet_dport;
24140- sin->sin_addr.s_addr = inet->inet_daddr;
24141+ sin->sin_addr.s_addr =
24142+ nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24143 } else {
24144 __be32 addr = inet->inet_rcv_saddr;
24145 if (!addr)
24146 addr = inet->inet_saddr;
24147+ addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24148 sin->sin_port = inet->inet_sport;
24149 sin->sin_addr.s_addr = addr;
24150 }
24151diff -NurpP --minimal linux-3.6.6/net/ipv4/arp.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/arp.c
24152--- linux-3.6.6/net/ipv4/arp.c 2012-10-04 15:27:49.000000000 +0200
24153+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/arp.c 2012-10-04 18:47:00.000000000 +0200
24154@@ -1318,6 +1318,7 @@ static void arp_format_neigh_entry(struc
24155 struct net_device *dev = n->dev;
24156 int hatype = dev->type;
24157
24158+ /* FIXME: check for network context */
24159 read_lock(&n->lock);
24160 /* Convert hardware address to XX:XX:XX:XX ... form. */
24161 #if IS_ENABLED(CONFIG_AX25)
24162@@ -1349,6 +1350,7 @@ static void arp_format_pneigh_entry(stru
24163 int hatype = dev ? dev->type : 0;
24164 char tbuf[16];
24165
24166+ /* FIXME: check for network context */
24167 sprintf(tbuf, "%pI4", n->key);
24168 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
24169 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24170diff -NurpP --minimal linux-3.6.6/net/ipv4/devinet.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/devinet.c
24171--- linux-3.6.6/net/ipv4/devinet.c 2012-10-04 15:27:49.000000000 +0200
24172+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/devinet.c 2012-10-04 18:47:00.000000000 +0200
24173@@ -516,6 +516,7 @@ struct in_device *inetdev_by_index(struc
24174 }
24175 EXPORT_SYMBOL(inetdev_by_index);
24176
24177+
24178 /* Called only from RTNL semaphored context. No locks. */
24179
24180 struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24181@@ -757,6 +758,8 @@ int devinet_ioctl(struct net *net, unsig
24182
24183 in_dev = __in_dev_get_rtnl(dev);
24184 if (in_dev) {
24185+ struct nx_info *nxi = current_nx_info();
24186+
24187 if (tryaddrmatch) {
24188 /* Matthias Andree */
24189 /* compare label and address (4.4BSD style) */
24190@@ -765,6 +768,8 @@ int devinet_ioctl(struct net *net, unsig
24191 This is checked above. */
24192 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24193 ifap = &ifa->ifa_next) {
24194+ if (!nx_v4_ifa_visible(nxi, ifa))
24195+ continue;
24196 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24197 sin_orig.sin_addr.s_addr ==
24198 ifa->ifa_local) {
24199@@ -777,9 +782,12 @@ int devinet_ioctl(struct net *net, unsig
24200 comparing just the label */
24201 if (!ifa) {
24202 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24203- ifap = &ifa->ifa_next)
24204+ ifap = &ifa->ifa_next) {
24205+ if (!nx_v4_ifa_visible(nxi, ifa))
24206+ continue;
24207 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24208 break;
24209+ }
24210 }
24211 }
24212
24213@@ -932,6 +940,8 @@ static int inet_gifconf(struct net_devic
24214 goto out;
24215
24216 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24217+ if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24218+ continue;
24219 if (!buf) {
24220 done += sizeof(ifr);
24221 continue;
24222@@ -1291,6 +1301,7 @@ static int inet_dump_ifaddr(struct sk_bu
24223 struct net_device *dev;
24224 struct in_device *in_dev;
24225 struct in_ifaddr *ifa;
24226+ struct sock *sk = skb->sk;
24227 struct hlist_head *head;
24228 struct hlist_node *node;
24229
24230@@ -1313,6 +1324,8 @@ static int inet_dump_ifaddr(struct sk_bu
24231
24232 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24233 ifa = ifa->ifa_next, ip_idx++) {
24234+ if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24235+ continue;
24236 if (ip_idx < s_ip_idx)
24237 continue;
24238 if (inet_fill_ifaddr(skb, ifa,
24239diff -NurpP --minimal linux-3.6.6/net/ipv4/fib_trie.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/fib_trie.c
24240--- linux-3.6.6/net/ipv4/fib_trie.c 2012-10-04 15:27:49.000000000 +0200
24241+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/fib_trie.c 2012-10-04 18:47:00.000000000 +0200
24242@@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
24243 || fa->fa_type == RTN_MULTICAST)
24244 continue;
24245
24246+ /* FIXME: check for network context? */
24247 if (fi)
24248 seq_printf(seq,
24249 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24250diff -NurpP --minimal linux-3.6.6/net/ipv4/inet_connection_sock.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/inet_connection_sock.c
24251--- linux-3.6.6/net/ipv4/inet_connection_sock.c 2012-11-06 18:42:14.000000000 +0100
24252+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/inet_connection_sock.c 2012-11-06 18:43:41.000000000 +0100
24253@@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24254 }
24255 EXPORT_SYMBOL(inet_get_local_port_range);
24256
24257+int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24258+{
24259+ __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1),
24260+ sk2_rcv_saddr = sk_rcv_saddr(sk2);
24261+
24262+ if (inet_v6_ipv6only(sk2))
24263+ return 0;
24264+
24265+ if (sk1_rcv_saddr &&
24266+ sk2_rcv_saddr &&
24267+ sk1_rcv_saddr == sk2_rcv_saddr)
24268+ return 1;
24269+
24270+ if (sk1_rcv_saddr &&
24271+ !sk2_rcv_saddr &&
24272+ v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24273+ return 1;
24274+
24275+ if (sk2_rcv_saddr &&
24276+ !sk1_rcv_saddr &&
24277+ v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24278+ return 1;
24279+
24280+ if (!sk1_rcv_saddr &&
24281+ !sk2_rcv_saddr &&
24282+ nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24283+ return 1;
24284+
24285+ return 0;
24286+}
24287+
24288 int inet_csk_bind_conflict(const struct sock *sk,
24289 const struct inet_bind_bucket *tb, bool relax)
24290 {
24291@@ -75,9 +106,7 @@ int inet_csk_bind_conflict(const struct
24292 sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24293 if (!reuse || !sk2->sk_reuse ||
24294 sk2->sk_state == TCP_LISTEN) {
24295- const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24296- if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24297- sk2_rcv_saddr == sk_rcv_saddr(sk))
24298+ if (ipv4_rcv_saddr_equal(sk, sk2))
24299 break;
24300 }
24301 if (!relax && reuse && sk2->sk_reuse &&
24302diff -NurpP --minimal linux-3.6.6/net/ipv4/inet_diag.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/inet_diag.c
24303--- linux-3.6.6/net/ipv4/inet_diag.c 2012-10-04 15:27:49.000000000 +0200
24304+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/inet_diag.c 2012-10-04 19:02:16.000000000 +0200
24305@@ -31,6 +31,8 @@
24306
24307 #include <linux/inet.h>
24308 #include <linux/stddef.h>
24309+#include <linux/vs_network.h>
24310+#include <linux/vs_inet.h>
24311
24312 #include <linux/inet_diag.h>
24313 #include <linux/sock_diag.h>
24314@@ -101,8 +103,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24315
24316 r->id.idiag_sport = inet->inet_sport;
24317 r->id.idiag_dport = inet->inet_dport;
24318- r->id.idiag_src[0] = inet->inet_rcv_saddr;
24319- r->id.idiag_dst[0] = inet->inet_daddr;
24320+ r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24321+ inet->inet_rcv_saddr);
24322+ r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24323+ inet->inet_daddr);
24324
24325 /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24326 * hence this needs to be included regardless of socket family.
24327@@ -233,8 +237,8 @@ static int inet_twsk_diag_fill(struct in
24328 sock_diag_save_cookie(tw, r->id.idiag_cookie);
24329 r->id.idiag_sport = tw->tw_sport;
24330 r->id.idiag_dport = tw->tw_dport;
24331- r->id.idiag_src[0] = tw->tw_rcv_saddr;
24332- r->id.idiag_dst[0] = tw->tw_daddr;
24333+ r->id.idiag_src[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24334+ r->id.idiag_dst[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24335 r->idiag_state = tw->tw_substate;
24336 r->idiag_timer = 3;
24337 r->idiag_expires = DIV_ROUND_UP(tmo * 1000, HZ);
24338@@ -276,12 +280,14 @@ int inet_diag_dump_one_icsk(struct inet_
24339
24340 err = -EINVAL;
24341 if (req->sdiag_family == AF_INET) {
24342+ /* TODO: lback */
24343 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24344 req->id.idiag_dport, req->id.idiag_src[0],
24345 req->id.idiag_sport, req->id.idiag_if);
24346 }
24347 #if IS_ENABLED(CONFIG_IPV6)
24348 else if (req->sdiag_family == AF_INET6) {
24349+ /* TODO: lback */
24350 sk = inet6_lookup(net, hashinfo,
24351 (struct in6_addr *)req->id.idiag_dst,
24352 req->id.idiag_dport,
24353@@ -476,6 +482,7 @@ int inet_diag_bc_sk(const struct nlattr
24354 } else
24355 #endif
24356 {
24357+ /* TODO: lback */
24358 entry.saddr = &inet->inet_rcv_saddr;
24359 entry.daddr = &inet->inet_daddr;
24360 }
24361@@ -574,6 +581,7 @@ static int inet_twsk_diag_dump(struct in
24362 } else
24363 #endif
24364 {
24365+ /* TODO: lback */
24366 entry.saddr = &tw->tw_rcv_saddr;
24367 entry.daddr = &tw->tw_daddr;
24368 }
24369@@ -620,8 +628,8 @@ static int inet_diag_fill_req(struct sk_
24370
24371 r->id.idiag_sport = inet->inet_sport;
24372 r->id.idiag_dport = ireq->rmt_port;
24373- r->id.idiag_src[0] = ireq->loc_addr;
24374- r->id.idiag_dst[0] = ireq->rmt_addr;
24375+ r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24376+ r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24377 r->idiag_expires = jiffies_to_msecs(tmo);
24378 r->idiag_rqueue = 0;
24379 r->idiag_wqueue = 0;
24380@@ -683,6 +691,7 @@ static int inet_diag_dump_reqs(struct sk
24381 continue;
24382
24383 if (bc) {
24384+ /* TODO: lback */
24385 entry.saddr =
24386 #if IS_ENABLED(CONFIG_IPV6)
24387 (entry.family == AF_INET6) ?
24388@@ -748,6 +757,8 @@ void inet_diag_dump_icsk(struct inet_has
24389 if (!net_eq(sock_net(sk), net))
24390 continue;
24391
24392+ if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24393+ continue;
24394 if (num < s_num) {
24395 num++;
24396 continue;
24397@@ -820,6 +831,8 @@ skip_listen_ht:
24398
24399 if (!net_eq(sock_net(sk), net))
24400 continue;
24401+ if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24402+ continue;
24403 if (num < s_num)
24404 goto next_normal;
24405 if (!(r->idiag_states & (1 << sk->sk_state)))
24406@@ -848,7 +861,8 @@ next_normal:
24407 &head->twchain) {
24408 if (!net_eq(twsk_net(tw), net))
24409 continue;
24410-
24411+ if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24412+ continue;
24413 if (num < s_num)
24414 goto next_dying;
24415 if (r->sdiag_family != AF_UNSPEC &&
24416diff -NurpP --minimal linux-3.6.6/net/ipv4/inet_hashtables.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/inet_hashtables.c
24417--- linux-3.6.6/net/ipv4/inet_hashtables.c 2012-07-22 23:39:48.000000000 +0200
24418+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/inet_hashtables.c 2012-10-04 18:47:00.000000000 +0200
24419@@ -22,6 +22,7 @@
24420 #include <net/inet_connection_sock.h>
24421 #include <net/inet_hashtables.h>
24422 #include <net/secure_seq.h>
24423+#include <net/route.h>
24424 #include <net/ip.h>
24425
24426 /*
24427@@ -156,6 +157,11 @@ static inline int compute_score(struct s
24428 if (rcv_saddr != daddr)
24429 return -1;
24430 score += 2;
24431+ } else {
24432+ /* block non nx_info ips */
24433+ if (!v4_addr_in_nx_info(sk->sk_nx_info,
24434+ daddr, NXA_MASK_BIND))
24435+ return -1;
24436 }
24437 if (sk->sk_bound_dev_if) {
24438 if (sk->sk_bound_dev_if != dif)
24439@@ -173,7 +179,6 @@ static inline int compute_score(struct s
24440 * wildcarded during the search since they can never be otherwise.
24441 */
24442
24443-
24444 struct sock *__inet_lookup_listener(struct net *net,
24445 struct inet_hashinfo *hashinfo,
24446 const __be32 daddr, const unsigned short hnum,
24447@@ -196,6 +201,7 @@ begin:
24448 hiscore = score;
24449 }
24450 }
24451+
24452 /*
24453 * if the nulls value we got at the end of this lookup is
24454 * not the expected one, we must restart lookup.
24455diff -NurpP --minimal linux-3.6.6/net/ipv4/netfilter/nf_nat_helper.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/netfilter/nf_nat_helper.c
24456--- linux-3.6.6/net/ipv4/netfilter/nf_nat_helper.c 2012-10-04 15:27:50.000000000 +0200
24457+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/netfilter/nf_nat_helper.c 2012-10-04 18:47:00.000000000 +0200
24458@@ -20,6 +20,7 @@
24459 #include <net/route.h>
24460
24461 #include <linux/netfilter_ipv4.h>
24462+#include <net/route.h>
24463 #include <net/netfilter/nf_conntrack.h>
24464 #include <net/netfilter/nf_conntrack_helper.h>
24465 #include <net/netfilter/nf_conntrack_ecache.h>
24466diff -NurpP --minimal linux-3.6.6/net/ipv4/netfilter.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/netfilter.c
24467--- linux-3.6.6/net/ipv4/netfilter.c 2012-07-22 23:39:48.000000000 +0200
24468+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/netfilter.c 2012-10-04 18:47:00.000000000 +0200
24469@@ -6,7 +6,7 @@
24470 #include <linux/skbuff.h>
24471 #include <linux/gfp.h>
24472 #include <linux/export.h>
24473-#include <net/route.h>
24474+// #include <net/route.h>
24475 #include <net/xfrm.h>
24476 #include <net/ip.h>
24477 #include <net/netfilter/nf_queue.h>
24478diff -NurpP --minimal linux-3.6.6/net/ipv4/raw.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/raw.c
24479--- linux-3.6.6/net/ipv4/raw.c 2012-10-04 15:27:50.000000000 +0200
24480+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/raw.c 2012-10-04 18:47:00.000000000 +0200
24481@@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24482
24483 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
24484 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
24485- !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24486+ v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
24487 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24488 goto found; /* gotcha */
24489 }
24490@@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
24491 icmp_out_count(net, ((struct icmphdr *)
24492 skb_transport_header(skb))->type);
24493
24494+ err = -EPERM;
24495+ if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24496+ sk->sk_nx_info &&
24497+ !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24498+ goto error_free;
24499+
24500 err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24501 rt->dst.dev, dst_output);
24502 if (err > 0)
24503@@ -582,6 +588,16 @@ static int raw_sendmsg(struct kiocb *ioc
24504 goto done;
24505 }
24506
24507+ if (sk->sk_nx_info) {
24508+ rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24509+ if (IS_ERR(rt)) {
24510+ err = PTR_ERR(rt);
24511+ rt = NULL;
24512+ goto done;
24513+ }
24514+ ip_rt_put(rt);
24515+ }
24516+
24517 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24518 rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24519 if (IS_ERR(rt)) {
24520@@ -658,17 +674,19 @@ static int raw_bind(struct sock *sk, str
24521 {
24522 struct inet_sock *inet = inet_sk(sk);
24523 struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24524+ struct nx_v4_sock_addr nsa = { 0 };
24525 int ret = -EINVAL;
24526 int chk_addr_ret;
24527
24528 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24529 goto out;
24530- chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24531+ v4_map_sock_addr(inet, addr, &nsa);
24532+ chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24533 ret = -EADDRNOTAVAIL;
24534- if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24535+ if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24536 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24537 goto out;
24538- inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24539+ v4_set_sock_addr(inet, &nsa);
24540 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24541 inet->inet_saddr = 0; /* Use device */
24542 sk_dst_reset(sk);
24543@@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
24544 /* Copy the address. */
24545 if (sin) {
24546 sin->sin_family = AF_INET;
24547- sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24548+ sin->sin_addr.s_addr =
24549+ nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24550 sin->sin_port = 0;
24551 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24552 }
24553@@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
24554 struct hlist_node *node;
24555
24556 sk_for_each(sk, node, &state->h->ht[state->bucket])
24557- if (sock_net(sk) == seq_file_net(seq))
24558+ if ((sock_net(sk) == seq_file_net(seq)) &&
24559+ nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24560 goto found;
24561 }
24562 sk = NULL;
24563@@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
24564 sk = sk_next(sk);
24565 try_again:
24566 ;
24567- } while (sk && sock_net(sk) != seq_file_net(seq));
24568+ } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24569+ !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24570
24571 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24572 sk = sk_head(&state->h->ht[state->bucket]);
24573diff -NurpP --minimal linux-3.6.6/net/ipv4/route.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/route.c
24574--- linux-3.6.6/net/ipv4/route.c 2012-11-06 18:42:15.000000000 +0100
24575+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/route.c 2012-11-06 18:43:41.000000000 +0100
24576@@ -1946,7 +1946,7 @@ struct rtable *__ip_route_output_key(str
24577
24578
24579 if (fl4->flowi4_oif) {
24580- dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24581+ dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24582 rth = ERR_PTR(-ENODEV);
24583 if (dev_out == NULL)
24584 goto out;
24585diff -NurpP --minimal linux-3.6.6/net/ipv4/tcp.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/tcp.c
24586--- linux-3.6.6/net/ipv4/tcp.c 2012-10-04 15:27:50.000000000 +0200
24587+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/tcp.c 2012-10-04 18:47:00.000000000 +0200
24588@@ -268,6 +268,7 @@
24589 #include <linux/crypto.h>
24590 #include <linux/time.h>
24591 #include <linux/slab.h>
24592+#include <linux/in.h>
24593
24594 #include <net/icmp.h>
24595 #include <net/inet_common.h>
24596diff -NurpP --minimal linux-3.6.6/net/ipv4/tcp_ipv4.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/tcp_ipv4.c
24597--- linux-3.6.6/net/ipv4/tcp_ipv4.c 2012-11-06 18:42:15.000000000 +0100
24598+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/tcp_ipv4.c 2012-11-06 18:43:41.000000000 +0100
24599@@ -2034,6 +2034,12 @@ static void *listening_get_next(struct s
24600 req = req->dl_next;
24601 while (1) {
24602 while (req) {
24603+ vxdprintk(VXD_CBIT(net, 6),
24604+ "sk,req: %p [#%d] (from %d)", req->sk,
24605+ (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24606+ if (req->sk &&
24607+ !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24608+ continue;
24609 if (req->rsk_ops->family == st->family) {
24610 cur = req;
24611 goto out;
24612@@ -2058,6 +2064,10 @@ get_req:
24613 }
24614 get_sk:
24615 sk_nulls_for_each_from(sk, node) {
24616+ vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24617+ sk, sk->sk_nid, nx_current_nid());
24618+ if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24619+ continue;
24620 if (!net_eq(sock_net(sk), net))
24621 continue;
24622 if (sk->sk_family == st->family) {
24623@@ -2134,6 +2144,11 @@ static void *established_get_first(struc
24624
24625 spin_lock_bh(lock);
24626 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24627+ vxdprintk(VXD_CBIT(net, 6),
24628+ "sk,egf: %p [#%d] (from %d)",
24629+ sk, sk->sk_nid, nx_current_nid());
24630+ if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24631+ continue;
24632 if (sk->sk_family != st->family ||
24633 !net_eq(sock_net(sk), net)) {
24634 continue;
24635@@ -2144,6 +2159,11 @@ static void *established_get_first(struc
24636 st->state = TCP_SEQ_STATE_TIME_WAIT;
24637 inet_twsk_for_each(tw, node,
24638 &tcp_hashinfo.ehash[st->bucket].twchain) {
24639+ vxdprintk(VXD_CBIT(net, 6),
24640+ "tw: %p [#%d] (from %d)",
24641+ tw, tw->tw_nid, nx_current_nid());
24642+ if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24643+ continue;
24644 if (tw->tw_family != st->family ||
24645 !net_eq(twsk_net(tw), net)) {
24646 continue;
24647@@ -2173,7 +2193,9 @@ static void *established_get_next(struct
24648 tw = cur;
24649 tw = tw_next(tw);
24650 get_tw:
24651- while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24652+ while (tw && (tw->tw_family != st->family ||
24653+ !net_eq(twsk_net(tw), net) ||
24654+ !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24655 tw = tw_next(tw);
24656 }
24657 if (tw) {
24658@@ -2197,6 +2219,11 @@ get_tw:
24659 sk = sk_nulls_next(sk);
24660
24661 sk_nulls_for_each_from(sk, node) {
24662+ vxdprintk(VXD_CBIT(net, 6),
24663+ "sk,egn: %p [#%d] (from %d)",
24664+ sk, sk->sk_nid, nx_current_nid());
24665+ if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24666+ continue;
24667 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24668 goto found;
24669 }
24670@@ -2402,9 +2429,9 @@ static void get_openreq4(const struct so
24671 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24672 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24673 i,
24674- ireq->loc_addr,
24675+ nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24676 ntohs(inet_sk(sk)->inet_sport),
24677- ireq->rmt_addr,
24678+ nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24679 ntohs(ireq->rmt_port),
24680 TCP_SYN_RECV,
24681 0, 0, /* could print option size, but that is af dependent. */
24682@@ -2426,8 +2453,8 @@ static void get_tcp4_sock(struct sock *s
24683 const struct tcp_sock *tp = tcp_sk(sk);
24684 const struct inet_connection_sock *icsk = inet_csk(sk);
24685 const struct inet_sock *inet = inet_sk(sk);
24686- __be32 dest = inet->inet_daddr;
24687- __be32 src = inet->inet_rcv_saddr;
24688+ __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24689+ __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24690 __u16 destp = ntohs(inet->inet_dport);
24691 __u16 srcp = ntohs(inet->inet_sport);
24692 int rx_queue;
24693@@ -2484,8 +2511,8 @@ static void get_timewait4_sock(const str
24694 if (ttd < 0)
24695 ttd = 0;
24696
24697- dest = tw->tw_daddr;
24698- src = tw->tw_rcv_saddr;
24699+ dest = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24700+ src = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24701 destp = ntohs(tw->tw_dport);
24702 srcp = ntohs(tw->tw_sport);
24703
24704diff -NurpP --minimal linux-3.6.6/net/ipv4/tcp_minisocks.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/tcp_minisocks.c
24705--- linux-3.6.6/net/ipv4/tcp_minisocks.c 2012-10-04 15:27:50.000000000 +0200
24706+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/tcp_minisocks.c 2012-10-04 18:47:00.000000000 +0200
24707@@ -23,6 +23,9 @@
24708 #include <linux/slab.h>
24709 #include <linux/sysctl.h>
24710 #include <linux/workqueue.h>
24711+#include <linux/vs_limit.h>
24712+#include <linux/vs_socket.h>
24713+#include <linux/vs_context.h>
24714 #include <net/tcp.h>
24715 #include <net/inet_common.h>
24716 #include <net/xfrm.h>
24717@@ -287,6 +290,11 @@ void tcp_time_wait(struct sock *sk, int
24718 tcptw->tw_ts_recent = tp->rx_opt.ts_recent;
24719 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24720
24721+ tw->tw_xid = sk->sk_xid;
24722+ tw->tw_vx_info = NULL;
24723+ tw->tw_nid = sk->sk_nid;
24724+ tw->tw_nx_info = NULL;
24725+
24726 #if IS_ENABLED(CONFIG_IPV6)
24727 if (tw->tw_family == PF_INET6) {
24728 struct ipv6_pinfo *np = inet6_sk(sk);
24729diff -NurpP --minimal linux-3.6.6/net/ipv4/udp.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/udp.c
24730--- linux-3.6.6/net/ipv4/udp.c 2012-10-04 15:27:50.000000000 +0200
24731+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv4/udp.c 2012-10-04 18:47:00.000000000 +0200
24732@@ -300,14 +300,7 @@ fail:
24733 }
24734 EXPORT_SYMBOL(udp_lib_get_port);
24735
24736-static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24737-{
24738- struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24739-
24740- return (!ipv6_only_sock(sk2) &&
24741- (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24742- inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24743-}
24744+extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24745
24746 static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24747 unsigned int port)
24748@@ -342,6 +335,11 @@ static inline int compute_score(struct s
24749 if (inet->inet_rcv_saddr != daddr)
24750 return -1;
24751 score += 2;
24752+ } else {
24753+ /* block non nx_info ips */
24754+ if (!v4_addr_in_nx_info(sk->sk_nx_info,
24755+ daddr, NXA_MASK_BIND))
24756+ return -1;
24757 }
24758 if (inet->inet_daddr) {
24759 if (inet->inet_daddr != saddr)
24760@@ -445,6 +443,7 @@ exact_match:
24761 return result;
24762 }
24763
24764+
24765 /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24766 * harder than this. -DaveM
24767 */
24768@@ -490,6 +489,11 @@ begin:
24769 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24770 score = compute_score(sk, net, saddr, hnum, sport,
24771 daddr, dport, dif);
24772+ /* FIXME: disabled?
24773+ if (score == 9) {
24774+ result = sk;
24775+ break;
24776+ } else */
24777 if (score > badness) {
24778 result = sk;
24779 badness = score;
24780@@ -503,6 +507,7 @@ begin:
24781 if (get_nulls_value(node) != slot)
24782 goto begin;
24783
24784+
24785 if (result) {
24786 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24787 result = NULL;
24788@@ -512,6 +517,7 @@ begin:
24789 goto begin;
24790 }
24791 }
24792+
24793 rcu_read_unlock();
24794 return result;
24795 }
24796@@ -555,8 +561,7 @@ static inline struct sock *udp_v4_mcast_
24797 udp_sk(s)->udp_port_hash != hnum ||
24798 (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24799 (inet->inet_dport != rmt_port && inet->inet_dport) ||
24800- (inet->inet_rcv_saddr &&
24801- inet->inet_rcv_saddr != loc_addr) ||
24802+ !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24803 ipv6_only_sock(s) ||
24804 (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24805 continue;
24806@@ -939,6 +944,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24807 inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24808 faddr, saddr, dport, inet->inet_sport);
24809
24810+ if (sk->sk_nx_info) {
24811+ rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24812+ if (IS_ERR(rt)) {
24813+ err = PTR_ERR(rt);
24814+ rt = NULL;
24815+ goto out;
24816+ }
24817+ ip_rt_put(rt);
24818+ }
24819+
24820 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24821 rt = ip_route_output_flow(net, fl4, sk);
24822 if (IS_ERR(rt)) {
24823@@ -1244,7 +1259,8 @@ try_again:
24824 if (sin) {
24825 sin->sin_family = AF_INET;
24826 sin->sin_port = udp_hdr(skb)->source;
24827- sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24828+ sin->sin_addr.s_addr = nx_map_sock_lback(
24829+ skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24830 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24831 }
24832 if (inet->cmsg_flags)
24833@@ -1992,6 +2008,8 @@ static struct sock *udp_get_first(struct
24834 sk_nulls_for_each(sk, node, &hslot->head) {
24835 if (!net_eq(sock_net(sk), net))
24836 continue;
24837+ if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24838+ continue;
24839 if (sk->sk_family == state->family)
24840 goto found;
24841 }
24842@@ -2009,7 +2027,9 @@ static struct sock *udp_get_next(struct
24843
24844 do {
24845 sk = sk_nulls_next(sk);
24846- } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24847+ } while (sk && (!net_eq(sock_net(sk), net) ||
24848+ sk->sk_family != state->family ||
24849+ !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24850
24851 if (!sk) {
24852 if (state->bucket <= state->udp_table->mask)
24853@@ -2105,8 +2125,8 @@ static void udp4_format_sock(struct sock
24854 int bucket, int *len)
24855 {
24856 struct inet_sock *inet = inet_sk(sp);
24857- __be32 dest = inet->inet_daddr;
24858- __be32 src = inet->inet_rcv_saddr;
24859+ __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24860+ __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24861 __u16 destp = ntohs(inet->inet_dport);
24862 __u16 srcp = ntohs(inet->inet_sport);
24863
24864diff -NurpP --minimal linux-3.6.6/net/ipv6/Kconfig linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/Kconfig
24865--- linux-3.6.6/net/ipv6/Kconfig 2012-07-22 23:39:48.000000000 +0200
24866+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/Kconfig 2012-10-04 18:47:00.000000000 +0200
24867@@ -4,8 +4,8 @@
24868
24869 # IPv6 as module will cause a CRASH if you try to unload it
24870 menuconfig IPV6
24871- tristate "The IPv6 protocol"
24872- default m
24873+ bool "The IPv6 protocol"
24874+ default n
24875 ---help---
24876 This is complemental support for the IP version 6.
24877 You will still be able to do traditional IPv4 networking as well.
24878diff -NurpP --minimal linux-3.6.6/net/ipv6/addrconf.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/addrconf.c
24879--- linux-3.6.6/net/ipv6/addrconf.c 2012-11-06 18:42:15.000000000 +0100
24880+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/addrconf.c 2012-11-06 18:43:41.000000000 +0100
24881@@ -92,6 +92,8 @@
24882 #include <linux/proc_fs.h>
24883 #include <linux/seq_file.h>
24884 #include <linux/export.h>
24885+#include <linux/vs_network.h>
24886+#include <linux/vs_inet6.h>
24887
24888 /* Set to 3 to get tracing... */
24889 #define ACONF_DEBUG 2
24890@@ -1101,7 +1103,7 @@ out:
24891
24892 int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
24893 const struct in6_addr *daddr, unsigned int prefs,
24894- struct in6_addr *saddr)
24895+ struct in6_addr *saddr, struct nx_info *nxi)
24896 {
24897 struct ipv6_saddr_score scores[2],
24898 *score = &scores[0], *hiscore = &scores[1];
24899@@ -1173,6 +1175,8 @@ int ipv6_dev_get_saddr(struct net *net,
24900 dev->name);
24901 continue;
24902 }
24903+ if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24904+ continue;
24905
24906 score->rule = -1;
24907 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24908@@ -3159,7 +3163,10 @@ static void if6_seq_stop(struct seq_file
24909 static int if6_seq_show(struct seq_file *seq, void *v)
24910 {
24911 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24912- seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24913+
24914+ if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24915+ v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24916+ seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24917 &ifp->addr,
24918 ifp->idev->dev->ifindex,
24919 ifp->prefix_len,
24920@@ -3665,6 +3672,11 @@ static int in6_dump_addrs(struct inet6_d
24921 struct ifacaddr6 *ifaca;
24922 int err = 1;
24923 int ip_idx = *p_ip_idx;
24924+ struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24925+
24926+ /* disable ipv6 on non v6 guests */
24927+ if (nxi && !nx_info_has_v6(nxi))
24928+ return skb->len;
24929
24930 read_lock_bh(&idev->lock);
24931 switch (type) {
24932@@ -3675,6 +3687,8 @@ static int in6_dump_addrs(struct inet6_d
24933 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24934 if (++ip_idx < s_ip_idx)
24935 continue;
24936+ if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24937+ continue;
24938 err = inet6_fill_ifaddr(skb, ifa,
24939 NETLINK_CB(cb->skb).pid,
24940 cb->nlh->nlmsg_seq,
24941@@ -3691,6 +3705,8 @@ static int in6_dump_addrs(struct inet6_d
24942 ifmca = ifmca->next, ip_idx++) {
24943 if (ip_idx < s_ip_idx)
24944 continue;
24945+ if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24946+ continue;
24947 err = inet6_fill_ifmcaddr(skb, ifmca,
24948 NETLINK_CB(cb->skb).pid,
24949 cb->nlh->nlmsg_seq,
24950@@ -3706,6 +3722,8 @@ static int in6_dump_addrs(struct inet6_d
24951 ifaca = ifaca->aca_next, ip_idx++) {
24952 if (ip_idx < s_ip_idx)
24953 continue;
24954+ if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24955+ continue;
24956 err = inet6_fill_ifacaddr(skb, ifaca,
24957 NETLINK_CB(cb->skb).pid,
24958 cb->nlh->nlmsg_seq,
24959@@ -4089,6 +4107,11 @@ static int inet6_dump_ifinfo(struct sk_b
24960 struct inet6_dev *idev;
24961 struct hlist_head *head;
24962 struct hlist_node *node;
24963+ struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24964+
24965+ /* FIXME: maybe disable ipv6 on non v6 guests?
24966+ if (skb->sk && skb->sk->sk_vx_info)
24967+ return skb->len; */
24968
24969 s_h = cb->args[0];
24970 s_idx = cb->args[1];
24971@@ -4100,6 +4123,8 @@ static int inet6_dump_ifinfo(struct sk_b
24972 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24973 if (idx < s_idx)
24974 goto cont;
24975+ if (!v6_dev_in_nx_info(dev, nxi))
24976+ goto cont;
24977 idev = __in6_dev_get(dev);
24978 if (!idev)
24979 goto cont;
24980diff -NurpP --minimal linux-3.6.6/net/ipv6/af_inet6.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/af_inet6.c
24981--- linux-3.6.6/net/ipv6/af_inet6.c 2012-11-06 18:42:15.000000000 +0100
24982+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/af_inet6.c 2012-11-06 18:43:41.000000000 +0100
24983@@ -43,6 +43,8 @@
24984 #include <linux/netdevice.h>
24985 #include <linux/icmpv6.h>
24986 #include <linux/netfilter_ipv6.h>
24987+#include <linux/vs_inet.h>
24988+#include <linux/vs_inet6.h>
24989
24990 #include <net/ip.h>
24991 #include <net/ipv6.h>
24992@@ -160,9 +162,12 @@ lookup_protocol:
24993 }
24994
24995 err = -EPERM;
24996+ if ((protocol == IPPROTO_ICMPV6) &&
24997+ nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24998+ goto override;
24999 if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25000 goto out_rcu_unlock;
25001-
25002+override:
25003 sock->ops = answer->ops;
25004 answer_prot = answer->prot;
25005 answer_no_check = answer->no_check;
25006@@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25007 struct inet_sock *inet = inet_sk(sk);
25008 struct ipv6_pinfo *np = inet6_sk(sk);
25009 struct net *net = sock_net(sk);
25010+ struct nx_v6_sock_addr nsa;
25011 __be32 v4addr = 0;
25012 unsigned short snum;
25013 int addr_type = 0;
25014@@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25015 if (addr->sin6_family != AF_INET6)
25016 return -EAFNOSUPPORT;
25017
25018+ err = v6_map_sock_addr(inet, addr, &nsa);
25019+ if (err)
25020+ return err;
25021+
25022 addr_type = ipv6_addr_type(&addr->sin6_addr);
25023 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25024 return -EINVAL;
25025@@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25026 /* Reproduce AF_INET checks to make the bindings consistent */
25027 v4addr = addr->sin6_addr.s6_addr32[3];
25028 chk_addr_ret = inet_addr_type(net, v4addr);
25029+
25030 if (!sysctl_ip_nonlocal_bind &&
25031 !(inet->freebind || inet->transparent) &&
25032 v4addr != htonl(INADDR_ANY) &&
25033@@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25034 err = -EADDRNOTAVAIL;
25035 goto out;
25036 }
25037+ if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25038+ err = -EADDRNOTAVAIL;
25039+ goto out;
25040+ }
25041 } else {
25042 if (addr_type != IPV6_ADDR_ANY) {
25043 struct net_device *dev = NULL;
25044@@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25045 }
25046 }
25047
25048+ if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25049+ err = -EADDRNOTAVAIL;
25050+ goto out_unlock;
25051+ }
25052+
25053 /* ipv4 addr of the socket is invalid. Only the
25054 * unspecified and mapped address have a v4 equivalent.
25055 */
25056@@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25057 }
25058 }
25059
25060+ /* what's that for? */
25061+ v6_set_sock_addr(inet, &nsa);
25062+
25063 inet->inet_rcv_saddr = v4addr;
25064 inet->inet_saddr = v4addr;
25065
25066@@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25067 return -ENOTCONN;
25068 sin->sin6_port = inet->inet_dport;
25069 sin->sin6_addr = np->daddr;
25070+ /* FIXME: remap lback? */
25071 if (np->sndflow)
25072 sin->sin6_flowinfo = np->flow_label;
25073 } else {
25074+ /* FIXME: remap lback? */
25075 if (ipv6_addr_any(&np->rcv_saddr))
25076 sin->sin6_addr = np->saddr;
25077 else
25078diff -NurpP --minimal linux-3.6.6/net/ipv6/datagram.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/datagram.c
25079--- linux-3.6.6/net/ipv6/datagram.c 2012-07-22 23:39:48.000000000 +0200
25080+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/datagram.c 2012-10-04 18:47:00.000000000 +0200
25081@@ -645,7 +645,7 @@ int datagram_send_ctl(struct net *net, s
25082
25083 rcu_read_lock();
25084 if (fl6->flowi6_oif) {
25085- dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25086+ dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25087 if (!dev) {
25088 rcu_read_unlock();
25089 return -ENODEV;
25090diff -NurpP --minimal linux-3.6.6/net/ipv6/fib6_rules.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/fib6_rules.c
25091--- linux-3.6.6/net/ipv6/fib6_rules.c 2012-07-22 23:39:48.000000000 +0200
25092+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/fib6_rules.c 2012-10-04 18:47:00.000000000 +0200
25093@@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25094 ip6_dst_idev(&rt->dst)->dev,
25095 &flp6->daddr,
25096 rt6_flags2srcprefs(flags),
25097- &saddr))
25098+ &saddr, NULL))
25099 goto again;
25100 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25101 r->src.plen))
25102diff -NurpP --minimal linux-3.6.6/net/ipv6/inet6_hashtables.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/inet6_hashtables.c
25103--- linux-3.6.6/net/ipv6/inet6_hashtables.c 2011-10-24 18:45:34.000000000 +0200
25104+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/inet6_hashtables.c 2012-10-04 18:47:00.000000000 +0200
25105@@ -16,6 +16,7 @@
25106
25107 #include <linux/module.h>
25108 #include <linux/random.h>
25109+#include <linux/vs_inet6.h>
25110
25111 #include <net/inet_connection_sock.h>
25112 #include <net/inet_hashtables.h>
25113@@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25114 unsigned int slot = hash & hashinfo->ehash_mask;
25115 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25116
25117-
25118 rcu_read_lock();
25119 begin:
25120 sk_nulls_for_each_rcu(sk, node, &head->chain) {
25121@@ -95,7 +95,7 @@ begin:
25122 sock_put(sk);
25123 goto begin;
25124 }
25125- goto out;
25126+ goto out;
25127 }
25128 }
25129 if (get_nulls_value(node) != slot)
25130@@ -141,6 +141,9 @@ static inline int compute_score(struct s
25131 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25132 return -1;
25133 score++;
25134+ } else {
25135+ if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25136+ return -1;
25137 }
25138 if (sk->sk_bound_dev_if) {
25139 if (sk->sk_bound_dev_if != dif)
25140diff -NurpP --minimal linux-3.6.6/net/ipv6/ip6_output.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/ip6_output.c
25141--- linux-3.6.6/net/ipv6/ip6_output.c 2012-10-04 15:27:50.000000000 +0200
25142+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/ip6_output.c 2012-10-04 18:47:00.000000000 +0200
25143@@ -966,7 +966,8 @@ static int ip6_dst_lookup_tail(struct so
25144 struct rt6_info *rt = (struct rt6_info *) *dst;
25145 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25146 sk ? inet6_sk(sk)->srcprefs : 0,
25147- &fl6->saddr);
25148+ &fl6->saddr,
25149+ sk ? sk->sk_nx_info : NULL);
25150 if (err)
25151 goto out_err_release;
25152 }
25153diff -NurpP --minimal linux-3.6.6/net/ipv6/ndisc.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/ndisc.c
25154--- linux-3.6.6/net/ipv6/ndisc.c 2012-10-04 15:27:50.000000000 +0200
25155+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/ndisc.c 2012-10-04 18:47:00.000000000 +0200
25156@@ -517,7 +517,7 @@ static void ndisc_send_na(struct net_dev
25157 } else {
25158 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25159 inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25160- &tmpaddr))
25161+ &tmpaddr, NULL))
25162 return;
25163 src_addr = &tmpaddr;
25164 }
25165diff -NurpP --minimal linux-3.6.6/net/ipv6/raw.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/raw.c
25166--- linux-3.6.6/net/ipv6/raw.c 2012-10-04 15:27:50.000000000 +0200
25167+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/raw.c 2012-10-04 18:47:00.000000000 +0200
25168@@ -30,6 +30,7 @@
25169 #include <linux/icmpv6.h>
25170 #include <linux/netfilter.h>
25171 #include <linux/netfilter_ipv6.h>
25172+#include <linux/vs_inet6.h>
25173 #include <linux/skbuff.h>
25174 #include <linux/compat.h>
25175 #include <asm/uaccess.h>
25176@@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25177 goto out_unlock;
25178 }
25179
25180+ if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25181+ err = -EADDRNOTAVAIL;
25182+ if (dev)
25183+ dev_put(dev);
25184+ goto out;
25185+ }
25186+
25187 /* ipv4 addr of the socket is invalid. Only the
25188 * unspecified and mapped address have a v4 equivalent.
25189 */
25190diff -NurpP --minimal linux-3.6.6/net/ipv6/route.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/route.c
25191--- linux-3.6.6/net/ipv6/route.c 2012-11-06 18:42:15.000000000 +0100
25192+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/route.c 2012-11-06 18:43:41.000000000 +0100
25193@@ -57,6 +57,7 @@
25194 #include <net/xfrm.h>
25195 #include <net/netevent.h>
25196 #include <net/netlink.h>
25197+#include <linux/vs_inet6.h>
25198
25199 #include <asm/uaccess.h>
25200
25201@@ -2112,15 +2113,17 @@ int ip6_route_get_saddr(struct net *net,
25202 struct rt6_info *rt,
25203 const struct in6_addr *daddr,
25204 unsigned int prefs,
25205- struct in6_addr *saddr)
25206+ struct in6_addr *saddr,
25207+ struct nx_info *nxi)
25208 {
25209 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25210 int err = 0;
25211- if (rt->rt6i_prefsrc.plen)
25212+ if (rt->rt6i_prefsrc.plen && (!nxi ||
25213+ v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25214 *saddr = rt->rt6i_prefsrc.addr;
25215 else
25216 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25217- daddr, prefs, saddr);
25218+ daddr, prefs, saddr, nxi);
25219 return err;
25220 }
25221
25222@@ -2456,7 +2459,8 @@ static int rt6_fill_node(struct net *net
25223 goto nla_put_failure;
25224 } else if (dst) {
25225 struct in6_addr saddr_buf;
25226- if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25227+ if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25228+ (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25229 nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25230 goto nla_put_failure;
25231 }
25232@@ -2674,6 +2678,7 @@ static int rt6_info_route(struct rt6_inf
25233 struct seq_file *m = p_arg;
25234 struct neighbour *n;
25235
25236+ /* FIXME: check for network context? */
25237 seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25238
25239 #ifdef CONFIG_IPV6_SUBTREES
25240diff -NurpP --minimal linux-3.6.6/net/ipv6/tcp_ipv6.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/tcp_ipv6.c
25241--- linux-3.6.6/net/ipv6/tcp_ipv6.c 2012-11-06 18:42:15.000000000 +0100
25242+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/tcp_ipv6.c 2012-11-06 18:43:41.000000000 +0100
25243@@ -71,6 +71,7 @@
25244
25245 #include <linux/crypto.h>
25246 #include <linux/scatterlist.h>
25247+#include <linux/vs_inet6.h>
25248
25249 static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25250 static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25251@@ -175,8 +176,15 @@ static int tcp_v6_connect(struct sock *s
25252 * connect() to INADDR_ANY means loopback (BSD'ism).
25253 */
25254
25255- if(ipv6_addr_any(&usin->sin6_addr))
25256- usin->sin6_addr.s6_addr[15] = 0x1;
25257+ if(ipv6_addr_any(&usin->sin6_addr)) {
25258+ struct nx_info *nxi = sk->sk_nx_info;
25259+
25260+ if (nxi && nx_info_has_v6(nxi))
25261+ /* FIXME: remap lback? */
25262+ usin->sin6_addr = nxi->v6.ip;
25263+ else
25264+ usin->sin6_addr.s6_addr[15] = 0x1;
25265+ }
25266
25267 addr_type = ipv6_addr_type(&usin->sin6_addr);
25268
25269diff -NurpP --minimal linux-3.6.6/net/ipv6/udp.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/udp.c
25270--- linux-3.6.6/net/ipv6/udp.c 2012-10-04 15:27:50.000000000 +0200
25271+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/udp.c 2012-10-04 18:56:03.000000000 +0200
25272@@ -45,42 +45,68 @@
25273 #include <net/tcp_states.h>
25274 #include <net/ip6_checksum.h>
25275 #include <net/xfrm.h>
25276+#include <linux/vs_inet6.h>
25277
25278 #include <linux/proc_fs.h>
25279 #include <linux/seq_file.h>
25280 #include <trace/events/skb.h>
25281 #include "udp_impl.h"
25282
25283-int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25284+int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25285 {
25286- const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25287+ const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25288 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25289- __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25290+ __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25291 __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25292- int sk_ipv6only = ipv6_only_sock(sk);
25293+ int sk1_ipv6only = ipv6_only_sock(sk1);
25294 int sk2_ipv6only = inet_v6_ipv6only(sk2);
25295- int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25296+ int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25297 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25298
25299 /* if both are mapped, treat as IPv4 */
25300- if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25301- return (!sk2_ipv6only &&
25302+ if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25303+ if (!sk2_ipv6only &&
25304 (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25305- sk1_rcv_saddr == sk2_rcv_saddr));
25306+ sk1_rcv_saddr == sk2_rcv_saddr))
25307+ goto vs_v4;
25308+ else
25309+ return 0;
25310+ }
25311
25312 if (addr_type2 == IPV6_ADDR_ANY &&
25313 !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25314- return 1;
25315+ goto vs;
25316
25317 if (addr_type == IPV6_ADDR_ANY &&
25318- !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25319- return 1;
25320+ !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25321+ goto vs;
25322
25323 if (sk2_rcv_saddr6 &&
25324- ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25325- return 1;
25326+ ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25327+ goto vs;
25328
25329 return 0;
25330+
25331+vs_v4:
25332+ if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25333+ return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25334+ if (!sk2_rcv_saddr)
25335+ return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25336+ if (!sk1_rcv_saddr)
25337+ return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25338+ return 1;
25339+vs:
25340+ if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25341+ return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25342+ else if (addr_type2 == IPV6_ADDR_ANY)
25343+ return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25344+ else if (addr_type == IPV6_ADDR_ANY) {
25345+ if (addr_type2 == IPV6_ADDR_MAPPED)
25346+ return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25347+ else
25348+ return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25349+ }
25350+ return 1;
25351 }
25352
25353 static unsigned int udp6_portaddr_hash(struct net *net,
25354@@ -144,6 +170,10 @@ static inline int compute_score(struct s
25355 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25356 return -1;
25357 score++;
25358+ } else {
25359+ /* block non nx_info ips */
25360+ if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25361+ return -1;
25362 }
25363 if (!ipv6_addr_any(&np->daddr)) {
25364 if (!ipv6_addr_equal(&np->daddr, saddr))
25365diff -NurpP --minimal linux-3.6.6/net/ipv6/xfrm6_policy.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/xfrm6_policy.c
25366--- linux-3.6.6/net/ipv6/xfrm6_policy.c 2012-10-04 15:27:50.000000000 +0200
25367+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/ipv6/xfrm6_policy.c 2012-10-04 18:47:00.000000000 +0200
25368@@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25369 dev = ip6_dst_idev(dst)->dev;
25370 ipv6_dev_get_saddr(dev_net(dev), dev,
25371 (struct in6_addr *)&daddr->a6, 0,
25372- (struct in6_addr *)&saddr->a6);
25373+ (struct in6_addr *)&saddr->a6, NULL);
25374 dst_release(dst);
25375 return 0;
25376 }
25377diff -NurpP --minimal linux-3.6.6/net/netfilter/ipvs/ip_vs_xmit.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/netfilter/ipvs/ip_vs_xmit.c
25378--- linux-3.6.6/net/netfilter/ipvs/ip_vs_xmit.c 2012-11-06 18:42:15.000000000 +0100
25379+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/netfilter/ipvs/ip_vs_xmit.c 2012-11-06 18:43:41.000000000 +0100
25380@@ -231,7 +231,7 @@ __ip_vs_route_output_v6(struct net *net,
25381 return dst;
25382 if (ipv6_addr_any(&fl6.saddr) &&
25383 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25384- &fl6.daddr, 0, &fl6.saddr) < 0)
25385+ &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25386 goto out_err;
25387 if (do_xfrm) {
25388 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25389diff -NurpP --minimal linux-3.6.6/net/netlink/af_netlink.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/netlink/af_netlink.c
25390--- linux-3.6.6/net/netlink/af_netlink.c 2012-11-06 18:42:15.000000000 +0100
25391+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/netlink/af_netlink.c 2012-11-06 18:43:41.000000000 +0100
25392@@ -55,6 +55,9 @@
25393 #include <linux/types.h>
25394 #include <linux/audit.h>
25395 #include <linux/mutex.h>
25396+#include <linux/vs_context.h>
25397+#include <linux/vs_network.h>
25398+#include <linux/vs_limit.h>
25399
25400 #include <net/net_namespace.h>
25401 #include <net/sock.h>
25402@@ -1972,6 +1975,8 @@ static struct sock *netlink_seq_socket_i
25403 sk_for_each(s, node, &hash->table[j]) {
25404 if (sock_net(s) != seq_file_net(seq))
25405 continue;
25406+ if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25407+ continue;
25408 if (off == pos) {
25409 iter->link = i;
25410 iter->hash_idx = j;
25411@@ -2006,7 +2011,8 @@ static void *netlink_seq_next(struct seq
25412 s = v;
25413 do {
25414 s = sk_next(s);
25415- } while (s && sock_net(s) != seq_file_net(seq));
25416+ } while (s && (sock_net(s) != seq_file_net(seq) ||
25417+ !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25418 if (s)
25419 return s;
25420
25421@@ -2018,7 +2024,8 @@ static void *netlink_seq_next(struct seq
25422
25423 for (; j <= hash->mask; j++) {
25424 s = sk_head(&hash->table[j]);
25425- while (s && sock_net(s) != seq_file_net(seq))
25426+ while (s && (sock_net(s) != seq_file_net(seq) ||
25427+ !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25428 s = sk_next(s);
25429 if (s) {
25430 iter->link = i;
25431diff -NurpP --minimal linux-3.6.6/net/socket.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/socket.c
25432--- linux-3.6.6/net/socket.c 2012-10-04 15:27:51.000000000 +0200
25433+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/socket.c 2012-10-04 18:47:00.000000000 +0200
25434@@ -98,6 +98,10 @@
25435
25436 #include <net/sock.h>
25437 #include <linux/netfilter.h>
25438+#include <linux/vs_base.h>
25439+#include <linux/vs_socket.h>
25440+#include <linux/vs_inet.h>
25441+#include <linux/vs_inet6.h>
25442
25443 #include <linux/if_tun.h>
25444 #include <linux/ipv6_route.h>
25445@@ -552,6 +556,7 @@ static inline int __sock_sendmsg_nosec(s
25446 struct msghdr *msg, size_t size)
25447 {
25448 struct sock_iocb *si = kiocb_to_siocb(iocb);
25449+ size_t len;
25450
25451 sock_update_classid(sock->sk);
25452
25453@@ -560,7 +565,22 @@ static inline int __sock_sendmsg_nosec(s
25454 si->msg = msg;
25455 si->size = size;
25456
25457- return sock->ops->sendmsg(iocb, sock, msg, size);
25458+ len = sock->ops->sendmsg(iocb, sock, msg, size);
25459+ if (sock->sk) {
25460+ if (len == size)
25461+ vx_sock_send(sock->sk, size);
25462+ else
25463+ vx_sock_fail(sock->sk, size);
25464+ }
25465+ vxdprintk(VXD_CBIT(net, 7),
25466+ "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25467+ sock, sock->sk,
25468+ (sock->sk)?sock->sk->sk_nx_info:0,
25469+ (sock->sk)?sock->sk->sk_vx_info:0,
25470+ (sock->sk)?sock->sk->sk_xid:0,
25471+ (sock->sk)?sock->sk->sk_nid:0,
25472+ (unsigned int)size, len);
25473+ return len;
25474 }
25475
25476 static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25477@@ -716,6 +736,7 @@ static inline int __sock_recvmsg_nosec(s
25478 struct msghdr *msg, size_t size, int flags)
25479 {
25480 struct sock_iocb *si = kiocb_to_siocb(iocb);
25481+ int len;
25482
25483 sock_update_classid(sock->sk);
25484
25485@@ -725,7 +746,18 @@ static inline int __sock_recvmsg_nosec(s
25486 si->size = size;
25487 si->flags = flags;
25488
25489- return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25490+ len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25491+ if ((len >= 0) && sock->sk)
25492+ vx_sock_recv(sock->sk, len);
25493+ vxdprintk(VXD_CBIT(net, 7),
25494+ "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25495+ sock, sock->sk,
25496+ (sock->sk)?sock->sk->sk_nx_info:0,
25497+ (sock->sk)?sock->sk->sk_vx_info:0,
25498+ (sock->sk)?sock->sk->sk_xid:0,
25499+ (sock->sk)?sock->sk->sk_nid:0,
25500+ (unsigned int)size, len);
25501+ return len;
25502 }
25503
25504 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25505@@ -1210,6 +1242,13 @@ int __sock_create(struct net *net, int f
25506 if (type < 0 || type >= SOCK_MAX)
25507 return -EINVAL;
25508
25509+ if (!nx_check(0, VS_ADMIN)) {
25510+ if (family == PF_INET && !current_nx_info_has_v4())
25511+ return -EAFNOSUPPORT;
25512+ if (family == PF_INET6 && !current_nx_info_has_v6())
25513+ return -EAFNOSUPPORT;
25514+ }
25515+
25516 /* Compatibility.
25517
25518 This uglymoron is moved from INET layer to here to avoid
25519@@ -1344,6 +1383,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25520 if (retval < 0)
25521 goto out;
25522
25523+ set_bit(SOCK_USER_SOCKET, &sock->flags);
25524 retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25525 if (retval < 0)
25526 goto out_release;
25527@@ -1385,10 +1425,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25528 err = sock_create(family, type, protocol, &sock1);
25529 if (err < 0)
25530 goto out;
25531+ set_bit(SOCK_USER_SOCKET, &sock1->flags);
25532
25533 err = sock_create(family, type, protocol, &sock2);
25534 if (err < 0)
25535 goto out_release_1;
25536+ set_bit(SOCK_USER_SOCKET, &sock2->flags);
25537
25538 err = sock1->ops->socketpair(sock1, sock2);
25539 if (err < 0)
25540diff -NurpP --minimal linux-3.6.6/net/sunrpc/auth.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/sunrpc/auth.c
25541--- linux-3.6.6/net/sunrpc/auth.c 2012-10-04 15:27:51.000000000 +0200
25542+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/sunrpc/auth.c 2012-10-04 18:47:00.000000000 +0200
25543@@ -15,6 +15,7 @@
25544 #include <linux/sunrpc/clnt.h>
25545 #include <linux/sunrpc/gss_api.h>
25546 #include <linux/spinlock.h>
25547+#include <linux/vs_tag.h>
25548
25549 #ifdef RPC_DEBUG
25550 # define RPCDBG_FACILITY RPCDBG_AUTH
25551@@ -481,6 +482,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25552 memset(&acred, 0, sizeof(acred));
25553 acred.uid = cred->fsuid;
25554 acred.gid = cred->fsgid;
25555+ acred.tag = dx_current_tag();
25556 acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25557
25558 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25559@@ -521,6 +523,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25560 struct auth_cred acred = {
25561 .uid = 0,
25562 .gid = 0,
25563+ .tag = dx_current_tag(),
25564 };
25565
25566 dprintk("RPC: %5u looking up %s cred\n",
25567diff -NurpP --minimal linux-3.6.6/net/sunrpc/auth_unix.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/sunrpc/auth_unix.c
25568--- linux-3.6.6/net/sunrpc/auth_unix.c 2012-07-22 23:39:49.000000000 +0200
25569+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/sunrpc/auth_unix.c 2012-10-04 18:47:00.000000000 +0200
25570@@ -13,11 +13,13 @@
25571 #include <linux/sunrpc/clnt.h>
25572 #include <linux/sunrpc/auth.h>
25573 #include <linux/user_namespace.h>
25574+#include <linux/vs_tag.h>
25575
25576 #define NFS_NGROUPS 16
25577
25578 struct unx_cred {
25579 struct rpc_cred uc_base;
25580+ tag_t uc_tag;
25581 gid_t uc_gid;
25582 gid_t uc_gids[NFS_NGROUPS];
25583 };
25584@@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
25585 groups = NFS_NGROUPS;
25586
25587 cred->uc_gid = acred->gid;
25588+ cred->uc_tag = acred->tag;
25589 for (i = 0; i < groups; i++) {
25590 gid_t gid;
25591 gid = from_kgid(&init_user_ns, GROUP_AT(acred->group_info, i));
25592@@ -123,7 +126,9 @@ unx_match(struct auth_cred *acred, struc
25593 unsigned int i;
25594
25595
25596- if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25597+ if (cred->uc_uid != acred->uid ||
25598+ cred->uc_gid != acred->gid ||
25599+ cred->uc_tag != acred->tag)
25600 return 0;
25601
25602 if (acred->group_info != NULL)
25603@@ -152,7 +157,7 @@ unx_marshal(struct rpc_task *task, __be3
25604 struct rpc_clnt *clnt = task->tk_client;
25605 struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25606 __be32 *base, *hold;
25607- int i;
25608+ int i, tag;
25609
25610 *p++ = htonl(RPC_AUTH_UNIX);
25611 base = p++;
25612@@ -162,9 +167,12 @@ unx_marshal(struct rpc_task *task, __be3
25613 * Copy the UTS nodename captured when the client was created.
25614 */
25615 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25616+ tag = task->tk_client->cl_tag;
25617
25618- *p++ = htonl((u32) cred->uc_uid);
25619- *p++ = htonl((u32) cred->uc_gid);
25620+ *p++ = htonl((u32) TAGINO_UID(tag,
25621+ cred->uc_uid, cred->uc_tag));
25622+ *p++ = htonl((u32) TAGINO_GID(tag,
25623+ cred->uc_gid, cred->uc_tag));
25624 hold = p++;
25625 for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25626 *p++ = htonl((u32) cred->uc_gids[i]);
25627diff -NurpP --minimal linux-3.6.6/net/sunrpc/clnt.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/sunrpc/clnt.c
25628--- linux-3.6.6/net/sunrpc/clnt.c 2012-10-04 15:27:51.000000000 +0200
25629+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/sunrpc/clnt.c 2012-10-04 18:47:00.000000000 +0200
25630@@ -31,6 +31,7 @@
25631 #include <linux/in6.h>
25632 #include <linux/un.h>
25633 #include <linux/rcupdate.h>
25634+#include <linux/vs_cvirt.h>
25635
25636 #include <linux/sunrpc/clnt.h>
25637 #include <linux/sunrpc/rpc_pipe_fs.h>
25638@@ -481,6 +482,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25639 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25640 clnt->cl_chatty = 1;
25641
25642+ /* TODO: handle RPC_CLNT_CREATE_TAGGED
25643+ if (args->flags & RPC_CLNT_CREATE_TAGGED)
25644+ clnt->cl_tag = 1; */
25645 return clnt;
25646 }
25647 EXPORT_SYMBOL_GPL(rpc_create);
25648diff -NurpP --minimal linux-3.6.6/net/unix/af_unix.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/unix/af_unix.c
25649--- linux-3.6.6/net/unix/af_unix.c 2012-10-04 15:27:51.000000000 +0200
25650+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/net/unix/af_unix.c 2012-10-04 18:59:36.000000000 +0200
25651@@ -114,6 +114,8 @@
25652 #include <linux/mount.h>
25653 #include <net/checksum.h>
25654 #include <linux/security.h>
25655+#include <linux/vs_context.h>
25656+#include <linux/vs_limit.h>
25657
25658 struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25659 EXPORT_SYMBOL_GPL(unix_socket_table);
25660@@ -271,6 +273,8 @@ static struct sock *__unix_find_socket_b
25661 if (!net_eq(sock_net(s), net))
25662 continue;
25663
25664+ if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25665+ continue;
25666 if (u->addr->len == len &&
25667 !memcmp(u->addr->name, sunname, len))
25668 goto found;
25669@@ -2258,6 +2262,8 @@ static struct sock *unix_from_bucket(str
25670 for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25671 if (sock_net(sk) != seq_file_net(seq))
25672 continue;
25673+ if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25674+ continue;
25675 if (++count == offset)
25676 break;
25677 }
25678@@ -2275,6 +2281,8 @@ static struct sock *unix_next_socket(str
25679 sk = sk_next(sk);
25680 if (!sk)
25681 goto next_bucket;
25682+ if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25683+ continue;
25684 if (sock_net(sk) == seq_file_net(seq))
25685 return sk;
25686 }
25687diff -NurpP --minimal linux-3.6.6/scripts/checksyscalls.sh linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/scripts/checksyscalls.sh
25688--- linux-3.6.6/scripts/checksyscalls.sh 2012-10-04 15:27:51.000000000 +0200
25689+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/scripts/checksyscalls.sh 2012-10-04 18:47:00.000000000 +0200
25690@@ -193,7 +193,6 @@ cat << EOF
25691 #define __IGNORE_afs_syscall
25692 #define __IGNORE_getpmsg
25693 #define __IGNORE_putpmsg
25694-#define __IGNORE_vserver
25695 EOF
25696 }
25697
25698diff -NurpP --minimal linux-3.6.6/security/commoncap.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/security/commoncap.c
25699--- linux-3.6.6/security/commoncap.c 2012-07-22 23:39:51.000000000 +0200
25700+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/security/commoncap.c 2012-10-04 18:47:00.000000000 +0200
25701@@ -76,14 +76,20 @@ int cap_netlink_send(struct sock *sk, st
25702 int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25703 int cap, int audit)
25704 {
25705+ struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25706+
25707 for (;;) {
25708 /* The owner of the user namespace has all caps. */
25709 if (targ_ns != &init_user_ns && uid_eq(targ_ns->owner, cred->euid))
25710 return 0;
25711
25712 /* Do we have the necessary capabilities? */
25713- if (targ_ns == cred->user_ns)
25714- return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25715+ if (targ_ns == cred->user_ns) {
25716+ if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25717+ cap_raised(cred->cap_effective, cap))
25718+ return 0;
25719+ return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25720+ }
25721
25722 /* Have we tried all of the parent namespaces? */
25723 if (targ_ns == &init_user_ns)
25724@@ -619,7 +625,7 @@ int cap_inode_setxattr(struct dentry *de
25725
25726 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25727 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25728- !capable(CAP_SYS_ADMIN))
25729+ !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25730 return -EPERM;
25731 return 0;
25732 }
25733@@ -645,7 +651,7 @@ int cap_inode_removexattr(struct dentry
25734
25735 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25736 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25737- !capable(CAP_SYS_ADMIN))
25738+ !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25739 return -EPERM;
25740 return 0;
25741 }
25742diff -NurpP --minimal linux-3.6.6/security/selinux/hooks.c linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/security/selinux/hooks.c
25743--- linux-3.6.6/security/selinux/hooks.c 2012-10-04 15:27:53.000000000 +0200
25744+++ linux-3.6.6-vs2.3.4.3.1-noxfs-nocow/security/selinux/hooks.c 2012-10-04 18:47:00.000000000 +0200
25745@@ -66,7 +66,6 @@
25746 #include <linux/dccp.h>
25747 #include <linux/quota.h>
25748 #include <linux/un.h> /* for Unix socket types */
25749-#include <net/af_unix.h> /* for Unix socket types */
25750 #include <linux/parser.h>
25751 #include <linux/nfs_mount.h>
25752 #include <net/ipv6.h>