Whamcloud - gitweb
LU-12787 tests: skip project quota if it is disabled
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index 14a20cd..4689018 100755 (executable)
@@ -3,22 +3,32 @@
 # Run select tests by setting ONLY, or as arguments to the script.
 # Skip specific tests by setting EXCEPT.
 #
-# Run test by setting NOSETUP=true when ltest has setup env for us
 set -e
 
-SRCDIR=$(dirname $0)
-export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
-
 ONLY=${ONLY:-"$*"}
-# Bug number for skipped test:      LU-5152
-ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT 55"
+
+LUSTRE=${LUSTRE:-$(dirname $0)/..}
+. $LUSTRE/tests/test-framework.sh
+init_test_env $@
+init_logging
+
+ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
+# Bug number for skipped test:  LU-5152
+ALWAYS_EXCEPT+="                55"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
-[ "$ALWAYS_EXCEPT$EXCEPT" ] &&
-       echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
+# Test duration:                   30 min
+[ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
 
-TMP=${TMP:-/tmp}
+if [ "$mds1_FSTYPE" = zfs ]; then
+       # bug number:                        LU-2887
+       # Test duration:                     21      9 min"
+       [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a     9"
+fi
 
+build_test_filter
+
+DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
 ORIG_PWD=${PWD}
 TSTID=${TSTID:-60000}
 TSTID2=${TSTID2:-60001}
@@ -30,34 +40,14 @@ MAX_DQ_TIME=604800
 MAX_IQ_TIME=604800
 QTYPE="ugp"
 
-LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
-. $LUSTRE/tests/test-framework.sh
-init_test_env $@
-. ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
-
-init_logging
-DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
-
 require_dsh_mds || exit 0
 require_dsh_ost || exit 0
 
 # Does e2fsprogs support quota feature?
-if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
+if [ "$mds1_FSTYPE" == ldiskfs ] &&
        do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
                grep -q 'quota'"; then
-       skip_env "e2fsprogs doesn't support quota" && exit 0
-fi
-
-# Test duration:                   30 min
-[ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
-
-if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
-       # bug number for skipped test:
-       ALWAYS_EXCEPT="$ALWAYS_EXCEPT"
-
-       # bug number:                        LU-2887
-       # Test duration:                     21      9 min"
-       [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a     9"
+       skip_env "e2fsprogs doesn't support quota"
 fi
 
 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
@@ -73,24 +63,6 @@ export QUOTA_AUTO=0
 check_and_setup_lustre
 
 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
-is_project_quota_supported() {
-       $ENABLE_PROJECT_QUOTAS || return 1
-       [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
-               [ $(lustre_version_code $SINGLEMDS) -gt \
-               $(version_code 2.9.55) ] &&
-               lfs --help | grep project >&/dev/null &&
-               egrep -q "7." /etc/redhat-release && return 0
-
-       if [ "$(facet_fstype $SINGLEMDS)" == "zfs" ]; then
-               [ $(lustre_version_code $SINGLEMDS) -le \
-                       $(version_code 2.10.53) ] && return 1
-
-               do_facet mds1 $ZPOOL upgrade -v |
-                       grep project_quota && return 0
-       fi
-
-       return 1
-}
 
 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
@@ -101,8 +73,6 @@ SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
 
-build_test_filter
-
 lustre_fail() {
        local fail_node=$1
        local fail_loc=$2
@@ -168,6 +138,7 @@ quota_scan() {
                        xargs stat 2>/dev/null)
        fi
 
+       is_project_quota_supported || return 0
        if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
                $LFS quota -v -p $TSTPRJID $DIR
                log "Files for project ($TSTPRJID):"
@@ -351,23 +322,42 @@ wait_ost_reint() {
        return 0
 }
 
-disable_project_quota() {
-       is_project_quota_supported || return 0
-       [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
-       stopall || error "failed to stopall (1)"
-
-       for num in $(seq $MDSCOUNT); do
-               do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
-                       error "tune2fs $(mdsdevname $num) failed"
-       done
+wait_grace_time() {
+       local qtype=$1
+       local flavour=$2
+       local extrasleep=${3:-5}
+       local qarg
+
+       case $qtype in
+               u|g) qarg=$TSTUSR ;;
+               p) qarg=$TSTPRJID ;;
+               *) error "get_grace_time: Invalid quota type: $qtype"
+       esac
 
-       for num in $(seq $OSTCOUNT); do
-               do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
-                       error "tune2fs $(ostdevname $num) failed"
-       done
+       case $flavour in
+               block)
+                       time=$(lfs quota -$qtype $qarg $DIR|
+                                  awk 'NR == 3{ print $5 }'| sed 's/s$//')
+                       ;;
+               file)
+                       time=$(lfs quota -$qtype $qarg $DIR|
+                                  awk 'NR == 3{ print $9 }'| sed 's/s$//')
+                       ;;
+               *)
+                       error "Unknown quota type: $flavour"
+                       ;;
+       esac
 
-       mount
-       setupall
+       echo "Sleep through grace ..."
+       [ "$time" == "-" ] &&
+           error "Grace timeout was not set or quota not exceeded"
+       if [ "$time" == "none" ]; then
+           echo "...Grace timeout already expired"
+       else
+               let time+=$extrasleep
+               echo "...sleep $time seconds"
+               sleep $time
+       fi
 }
 
 setup_quota_test() {
@@ -421,34 +411,25 @@ quota_show_check() {
        fi
 }
 
-enable_project_quota() {
-       is_project_quota_supported || return 0
-       [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
-       stopall || error "failed to stopall (1)"
-
-       for num in $(seq $MDSCOUNT); do
-               do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
-                       error "tune2fs $(mdsdevname $num) failed"
-       done
-
-       for num in $(seq $OSTCOUNT); do
-               do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
-                       error "tune2fs $(ostdevname $num) failed"
-       done
-
-       mount
-       setupall
-}
-
 project_quota_enabled () {
        local rc=0
-       for num in $(seq $MDSCOUNT); do
-               do_facet mds$num $DEBUGFS -R features $(mdsdevname $num) |
-                       grep -q project || rc=1
-       done
-       for num in $(seq $OSTCOUNT); do
-               do_facet ost$num $DEBUGFS -R features $(ostdevname $num) |
-                       grep -q project || rc=1
+       local zfeat="feature@project_quota"
+
+       for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
+               local facet_fstype=${facet:0:3}1_FSTYPE
+               local devname
+
+               if [ "${!facet_fstype}" = "zfs" ]; then
+                       devname=$(zpool_name ${facet})
+                       do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
+                               grep -wq active || rc=1
+               else
+                       [ ${facet:0:3} == "mds" ] &&
+                               devname=$(mdsdevname ${facet:3}) ||
+                               devname=$(ostdevname ${facet:3})
+                       do_facet ${facet} $DEBUGFS -R features $devname |
+                               grep -q project || rc=1
+               fi
        done
        [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
        return $rc
@@ -458,9 +439,13 @@ project_quota_enabled || enable_project_quota
 
 reset_quota_settings() {
        resetquota -u $TSTUSR
+       resetquota -u $TSTID
        resetquota -g $TSTUSR
+       resetquota -g $TSTID
        resetquota -u $TSTUSR2
+       resetquota -u $TSTID2
        resetquota -g $TSTUSR2
+       resetquota -g $TSTID2
        resetquota -p $TSTPRJID
 }
 
@@ -485,15 +470,15 @@ test_quota_performance() {
        local etime=$(date +%s)
        delta=$((etime - stime))
        if [ $delta -gt 0 ]; then
-           rate=$((size * 1024 / delta))
-           if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
-               # LU-2872 - see LU-2887 for fix
-               [ $rate -gt 64 ] ||
-                       error "SLOW IO for $TSTUSR (user): $rate KB/sec"
-           else
-               [ $rate -gt 1024 ] ||
-                       error "SLOW IO for $TSTUSR (user): $rate KB/sec"
-           fi
+               rate=$((size * 1024 / delta))
+               if [ "$mds1_FSTYPE" = zfs ]; then
+                       # LU-2872 - see LU-2887 for fix
+                       [ $rate -gt 64 ] ||
+                               error "SLOW IO for $TSTUSR (user): $rate KB/sec"
+               else
+                       [ $rate -gt 1024 ] ||
+                               error "SLOW IO for $TSTUSR (user): $rate KB/sec"
+               fi
        fi
        rm -f $TESTFILE
 }
@@ -745,7 +730,7 @@ run_test 2 "File hard limit (normal use and out of quota)"
 
 test_block_soft() {
        local TESTFILE=$1
-       local TIMER=$(($2 * 3 / 2))
+       local GRACE=$2
        local LIMIT=$3
        local OFFSET=0
        local qtype=$4
@@ -783,8 +768,7 @@ test_block_soft() {
        OFFSET=$((OFFSET + 1024))
        cancel_lru_locks osc
 
-       echo "Sleep $TIMER seconds ..."
-       sleep $TIMER
+       wait_grace_time $qtype "block"
 
        $SHOW_QUOTA_USER
        $SHOW_QUOTA_GROUP
@@ -833,10 +817,16 @@ test_block_soft() {
 
 # block soft limit
 test_3() {
-       local LIMIT=1  # 1MB
        local GRACE=20 # 20s
+       if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
+           GRACE=60
+       fi
        local TESTFILE=$DIR/$tdir/$tfile-0
 
+       # get minimum soft qunit size
+       local LIMIT=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
+               qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
+
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        echo "User quota (soft limit:$LIMIT MB  grace:$GRACE seconds)"
@@ -897,7 +887,7 @@ test_file_soft() {
        local TESTFILE=$1
        local LIMIT=$2
        local grace=$3
-       local TIMER=$(($grace * 3 / 2))
+       local qtype=$4
 
        setup_quota_test
        trap cleanup_quota_test EXIT
@@ -920,8 +910,7 @@ test_file_soft() {
                        "but expect success. $trigger_time, $cur_time"
        sync_all_data || true
 
-       echo "Sleep $TIMER seconds ..."
-       sleep $TIMER
+       wait_grace_time $qtype "file"
 
        $SHOW_QUOTA_USER
        $SHOW_QUOTA_GROUP
@@ -964,7 +953,8 @@ test_file_soft() {
 
 # file soft limit
 test_4a() {
-       local LIMIT=10 # inodes
+       local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
+               qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
        local TESTFILE=$DIR/$tdir/$tfile-0
        local GRACE=12
 
@@ -980,9 +970,9 @@ test_4a() {
        $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
                error "set user quota failed"
 
-       [ $(facet_fstype $SINGLEMDS) = "zfs" ] && GRACE=20
+       [ "$mds1_FSTYPE" = zfs ] && GRACE=20
 
-       test_file_soft $TESTFILE $LIMIT $GRACE
+       test_file_soft $TESTFILE $LIMIT $GRACE "u"
 
        echo "Group quota (soft limit:$LIMIT files  grace:$GRACE seconds)"
        # make sure the system is clean
@@ -995,7 +985,7 @@ test_4a() {
                error "set group quota failed"
        TESTFILE=$DIR/$tdir/$tfile-1
 
-       test_file_soft $TESTFILE $LIMIT $GRACE
+       test_file_soft $TESTFILE $LIMIT $GRACE "g"
 
        if is_project_quota_supported; then
                echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
@@ -1011,7 +1001,7 @@ test_4a() {
 
                TESTFILE=$DIR/$tdir/$tfile-1
                # one less than limit, because of parent directory included.
-               test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
+               test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
                resetquota -p $TSTPRJID
                $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
                        $MAX_IQ_TIME $DIR ||
@@ -1159,6 +1149,19 @@ test_6() {
                error "write $TESTFILE failure, expect success"
        $RUNAS2 $DD of=$TESTFILE2 count=1 ||
                error "write $TESTFILE2 failure, expect success"
+
+       if at_is_enabled; then
+               at_max_saved=$(at_max_get ost1)
+               at_max_set $TIMEOUT ost1
+
+               # write to enforced ID ($TSTUSR) to exceed limit to make sure
+               # DQACQ is sent, which makes at_max to take effect
+               $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
+                                                               conv=notrunc
+               rm -f $TESTFILE
+               wait_delete_completed
+       fi
+
        sync; sync
        sync_all_data || true
 
@@ -1182,6 +1185,8 @@ test_6() {
        echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
        sleep $((TIMEOUT * 2 + 1))
 
+       [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
+
        # write should be blocked and never finished
        if ! ps -p $DDPID  > /dev/null 2>&1; then
                lustre_fail mds 0 0
@@ -1192,7 +1197,7 @@ test_6() {
 
        # no watchdog is triggered
        do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
-       watchdog=$(awk '/Service thread pid/ && /was inactive/ \
+       watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
                        { print; }' $TMP/lustre-log-${TESTNAME}.log)
        [ -z "$watchdog" ] || error "$watchdog"
 
@@ -1375,7 +1380,7 @@ test_7c() {
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
        # trigger reintegration
-       local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
+       local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
        procf=${procf}quota_slave.force_reint
        do_facet ost1 $LCTL set_param $procf=1 ||
                error "force reintegration failed"
@@ -1444,7 +1449,7 @@ test_7e() {
 
        # LU-2435: skip this quota test if underlying zfs version has not
        # supported native dnode accounting
-       [ "$(facet_fstype mds1)" == "zfs" ] && {
+       [ "$mds1_FSTYPE" == zfs ] && {
                local F="feature@userobj_accounting"
                local pool=$(zpool_name mds1)
                local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
@@ -1985,7 +1990,7 @@ test_18() {
 
        # check if watchdog is triggered
        do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
-       local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
+       local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
                        { print; }' $TMP/lustre-log-${TESTNAME}.log)
        [ -z "$watchdog" ] || error "$watchdog"
        rm -f $TMP/lustre-log-${TESTNAME}.log
@@ -2228,7 +2233,7 @@ test_23_sub() {
 }
 
 test_23() {
-       [ $(facet_fstype ost1) == "zfs" ] &&
+       [ "$ost1_FSTYPE" == zfs ] &&
                skip "Overwrite in place is not guaranteed to be " \
                "space neutral on ZFS"
 
@@ -2298,8 +2303,8 @@ test_27b() { # b20200
                $SHOW_QUOTA_PROJID ||
                        error "lfs quota failed with projid argument"
        fi
-       resetquota -u $TSTUSR
-       resetquota -g $TSTUSR
+       resetquota -u $TSTID
+       resetquota -g $TSTID
        resetquota -p $TSTPRJID
        return 0
 }
@@ -2669,7 +2674,7 @@ run_test 35 "Usage is still accessible across reboot"
 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
 # LU-5006
 test_37() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
+       [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
                skip "Old server doesn't have LU-5006 fix."
 
        setup_quota_test || error "setup quota failed with $?"
@@ -2701,7 +2706,7 @@ run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
 
 # LU-8801
 test_38() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
+       [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
                skip "Old server doesn't have LU-8801 fix."
 
        [ "$UID" != 0 ] && skip_env "must run as root" && return
@@ -2730,7 +2735,7 @@ test_38() {
        cancel_lru_locks osc
        sync; sync_all_data || true
 
-       local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
+       local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
        procf=${procf}.quota_slave.acct_user
        local accnt_cnt
 
@@ -2966,8 +2971,8 @@ test_54() {
        #clear project but with kept projid
        change_project -rCk $DIR/$tdir
        proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
-       [ $proj_count1 -eq $proj_count ] ||
-                       error "c3: expected $proj_count got $proj_count1"
+       [ $proj_count1 -eq 1 ] ||
+                       error "c3: expected 1 got $proj_count1"
 
        #verify projid untouched.
        proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
@@ -2994,7 +2999,7 @@ test_54() {
 run_test 54 "basic lfs project interface test"
 
 test_55() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
                skip "Not supported before 2.10.58."
        setup_quota_test || error "setup quota failed with $?"
 
@@ -3064,7 +3069,7 @@ test_57() {
        #try to change pipe file should not hang and return failure
        wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
                awk -F ':' '{ print \\\$2 }'" \
-                       " failed to get xattr for '$dir/pipe'" || return 1
+                       " unable to get xattr for fifo '$dir/pipe'" || return 1
        #command can process further if it hit some errors
        touch $dir/aaa $dir/bbb
        mkdir $dir/subdir -p
@@ -3079,7 +3084,7 @@ test_57() {
 run_test 57 "lfs project could tolerate errors"
 
 test_59() {
-       [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
+       [ "$mds1_FSTYPE" != ldiskfs ] &&
                skip "ldiskfs only test"
        disable_project_quota
        setup_quota_test || error "setup quota failed with $?"
@@ -3126,7 +3131,7 @@ run_test 60 "Test quota for root with setgid"
 
 # test default quota
 test_default_quota() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
+       [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
                skip "Not supported before 2.11.51."
 
        local qtype=$1
@@ -3321,8 +3326,8 @@ test_62() {
 run_test 62 "Project inherit should be only changed by root"
 
 test_dom() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
-               skip "Not supported before 2.11.55" && return
+       [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
+               skip "Not supported before 2.11.55"
 
        local qtype=$1
        local qid=$TSTUSR
@@ -3432,6 +3437,99 @@ test_63() {
 }
 run_test 63 "quota on DoM tests"
 
+test_64() {
+       ! is_project_quota_supported &&
+               skip "Project quota is not supported"
+       setup_quota_test || error "setup quota failed with $?"
+       local dir1="$DIR/$tdir/"
+
+       touch $dir1/file
+       ln -s $dir1/file $dir1/file_link
+
+       $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
+               error "set symlink file's project should fail"
+
+       $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
+               error "get symlink file's project should fail"
+
+       cleanup_quota_test
+}
+run_test 64 "lfs project on symlink files should fail"
+
+test_65() {
+       local SIZE=10 #10M
+       local TESTFILE="$DIR/$tdir/$tfile-0"
+
+       setup_quota_test || error "setup quota failed with $?"
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+       quota_init
+
+       echo "Write..."
+       $RUNAS $DD of=$TESTFILE count=$SIZE ||
+               error "failed to write"
+       # flush cache, ensure noquota flag is set on client
+       cancel_lru_locks osc
+       sync; sync_all_data || true
+
+       local quota_u=$($LFS quota -u $TSTUSR $DIR)
+       local quota_g=$($LFS quota -g $TSTUSR $DIR)
+       local quota_all=$($RUNAS $LFS quota $DIR)
+
+       [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
+               error "usr quota not match"
+       [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
+               error "grp quota not match"
+
+       rm -f $TESTFILE
+       # cleanup
+       cleanup_quota_test
+}
+run_test 65 "Check lfs quota result"
+
+test_66() {
+       ! is_project_quota_supported &&
+               skip "Project quota is not supported"
+       setup_quota_test || error "setup quota failed with $?"
+       stack_trap cleanup_quota_test EXIT
+       local old=$(do_facet mds1 $LCTL get_param -n \
+                   mdt.*.enable_chprojid_gid | head -1)
+       local testdir=$DIR/$tdir/foo
+
+       do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
+       stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
+               EXIT
+
+       test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
+       chown -R $TSTID:$TSTID $testdir
+       change_project -sp $TSTPRJID $testdir
+       $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
+
+       $RUNAS lfs project -p 0 $testdir/foo &&
+               error "nonroot user should fail to set projid"
+
+       $RUNAS lfs project -C $testdir/foo &&
+               error "nonroot user should fail to clear projid"
+
+       change_project -C $testdir/foo || error "failed to clear project"
+
+       do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
+       $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
+       "failed to set projid with normal user when enable_chprojid_gid=-1"
+
+       $RUNAS lfs project -rC $testdir/ || error \
+"failed to clear project state with normal user when enable_chprojid_gid=-1"
+
+       touch $testdir/bar || error "failed touch $testdir/bar"
+       $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
+       "normal user should not be able to set projid on root owned file"
+
+       change_project -p $TSTPRJID $testdir/bar || error \
+               "root should be able to change its own file's projid"
+
+       cleanup_quota_test
+}
+run_test 66 "nonroot user can not change project state in default"
+
 quota_fini()
 {
        do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"