Whamcloud - gitweb
LU-12787 tests: skip project quota if it is disabled
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index a6dff5d..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:
-ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
+
+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,35 +40,16 @@ 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
+       skip_env "e2fsprogs doesn't support quota"
 fi
 
-if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
-# bug number for skipped test:        LU-2836 LU-6836 LU-2836
-       ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3       4a      6"
-# bug number for skipped test:        LU-5638
-       ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
-# bug number:     LU-2887
-       #         21  9   (min)"
-       ZFS_SLOW="12a 9"
-fi
-
-[ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW"
-
 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
 
 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
@@ -71,12 +62,7 @@ export QUOTA_AUTO=0
 
 check_and_setup_lustre
 
-is_project_quota_supported() {
-       [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
-               [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ] &&
-                       egrep -q "7." /etc/redhat-release &&
-                               man chattr | grep project >&/dev/null
-}
+ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
 
 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
@@ -87,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
@@ -106,8 +90,8 @@ lustre_fail() {
 
 change_project()
 {
-       echo "chattr $*"
-       chattr $* || error "chattr $* failed"
+       echo "lfs project $*"
+       lfs project $* || error "lfs project $* failed"
 }
 
 RUNAS="runas -u $TSTID -g $TSTID"
@@ -116,11 +100,6 @@ DD="dd if=/dev/zero bs=1M"
 
 FAIL_ON_ERROR=false
 
-check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
-       error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
-check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
-       error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
-
 # clear quota limits for a user or a group
 # usage: resetquota -u username
 #        resetquota -g groupname
@@ -159,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):"
@@ -186,6 +166,8 @@ getquota() {
        local spec
        local uuid
 
+       sync_all_data > /dev/null 2>&1 || true
+
        [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
        [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
                error "getquota: wrong u/g/p specifier $1 passed"
@@ -221,7 +203,13 @@ set_mdt_qtype() {
        local cmd
        [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
                qtype=$(tr -d 'p' <<<$qtype)
-       do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
+
+       if [[ $PERM_CMD == *"set_param -P"* ]]; then
+               do_facet mgs $PERM_CMD \
+                       osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
+       else
+               do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
+       fi
        # we have to make sure each MDT received config changes
        for mdt in ${mdts//,/ }; do
                varsvc=${mdt}_svc
@@ -245,7 +233,13 @@ set_ost_qtype() {
        local cmd
        [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
                qtype=$(tr -d 'p' <<<$qtype)
-       do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
+
+       if [[ $PERM_CMD == *"set_param -P"* ]]; then
+               do_facet mgs $PERM_CMD \
+                       osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
+       else
+               do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
+       fi
        # we have to make sure each OST received config changes
        for ost in ${osts//,/ }; do
                varsvc=${ost}_svc
@@ -328,22 +322,42 @@ wait_ost_reint() {
        return 0
 }
 
-disable_project_quota() {
-       is_project_quota_supported || 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() {
@@ -363,6 +377,7 @@ cleanup_quota_test() {
        echo "Wait for unlink objects finished..."
        wait_delete_completed
        sync_all_data || true
+       reset_quota_settings
 }
 
 quota_show_check() {
@@ -396,36 +411,55 @@ quota_show_check() {
        fi
 }
 
-enable_project_quota() {
-       is_project_quota_supported ||  return 0
-       stopall || error "failed to stopall (1)"
+project_quota_enabled () {
+       local rc=0
+       local zfeat="feature@project_quota"
 
-       for num in $(seq $MDSCOUNT); do
-               do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
-                       error "tune2fs $(mdsdevname $num) failed"
-       done
+       for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
+               local facet_fstype=${facet:0:3}1_FSTYPE
+               local devname
 
-       for num in $(seq $OSTCOUNT); do
-               do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
-                       error "tune2fs $(ostdevname $num) failed"
+               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
+}
 
-       mount
-       setupall
+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
 }
-enable_project_quota
 
 # enable quota debug
 quota_init() {
        do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
 }
 quota_init
+reset_quota_settings
 
-resetquota -u $TSTUSR
-resetquota -g $TSTUSR
-resetquota -u $TSTUSR2
-resetquota -g $TSTUSR2
-resetquota -p $TSTPRJID
+check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
+       error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
+check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
+       error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
 
 test_quota_performance() {
        local TESTFILE="$DIR/$tdir/$tfile-0"
@@ -436,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
 }
@@ -457,7 +491,7 @@ test_0() {
        local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
        [ $free_space -le $((MB * 1024)) ] &&
                skip "not enough space ${free_space} KB, " \
-                       "required $((MB * 1024)) KB" && return
+                       "required $((MB * 1024)) KB"
        setup_quota_test || error "setup quota failed with $?"
        trap cleanup_quota_test EXIT
 
@@ -470,7 +504,6 @@ test_0() {
        test_quota_performance $MB
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 0 "Test basic quota performance"
 
@@ -494,7 +527,7 @@ test_1() {
        local USED=$(getquota -u $TSTUSR global curspace)
        [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
 
-       $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        log "Write..."
@@ -528,7 +561,7 @@ test_1() {
        USED=$(getquota -g $TSTUSR global curspace)
        [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
 
-       $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        log "Write ..."
@@ -563,11 +596,11 @@ test_1() {
 
        # test for Project
        log "--------------------------------------"
-       log "project quota (block hardlimit:$LIMIT mb)"
+       log "Project quota (block hardlimit:$LIMIT mb)"
        $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
                error "set project quota failed"
 
-       $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
        chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
        change_project -p $TSTPRJID $TESTFILE
 
@@ -580,16 +613,14 @@ test_1() {
        cancel_lru_locks osc
        sync; sync_all_data || true
        $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
-               $TSTPRJID "project write success, but expect edquot"
+               $TSTPRJID "project write success, but expect EDQUOT"
 
        # cleanup
        cleanup_quota_test
 
        USED=$(getquota -p $TSTPRJID global curspace)
-       [ $USED -ne 0 ] && quota_error p $TSTPRJID \
+       [ $USED -eq 0 ] || quota_error p $TSTPRJID \
                "project quota isn't released after deletion"
-
-       resetquota -p $TSTPRJID
 }
 run_test 1 "Block hard limit (normal use and out of quota)"
 
@@ -603,8 +634,7 @@ test_2() {
        local FREE_INODES=$(mdt_free_inodes 0)
        echo "$FREE_INODES free inodes on master MDT"
        [ $FREE_INODES -lt $LIMIT ] &&
-               skip "not enough free inodes $FREE_INODES required $LIMIT" &&
-               return
+               skip "not enough free inodes $FREE_INODES required $LIMIT"
 
        setup_quota_test || error "setup quota failed with $?"
        trap cleanup_quota_test EXIT
@@ -681,30 +711,26 @@ test_2() {
        [ $USED -ne 0 ] &&
                error "Used inodes($USED) for project $TSTPRJID isn't 0"
 
-       change_project +P $DIR/$tdir/
-       change_project -p $TSTPRJID -d $DIR/$tdir
+       change_project -sp $TSTPRJID $DIR/$tdir
        log "Create $LIMIT files ..."
        $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
                $TSTPRJID "project create fail, but expect success"
        log "Create out of file quota ..."
        $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
                "project create success, but expect EDQUOT"
-       change_project -P $DIR/$tdir
-       change_project -p 0 -d $DIR/$tdir
+       change_project -C $DIR/$tdir
 
        cleanup_quota_test
        USED=$(getquota -p $TSTPRJID global curinodes)
-       [ $USED -ne 0 ] && quota_error p $TSTPRJID \
+       [ $USED -eq 0 ] || quota_error p $TSTPRJID \
                "project quota isn't released after deletion"
 
-       resetquota -p $TSTPRJID
-
 }
 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
@@ -712,7 +738,7 @@ test_block_soft() {
        setup_quota_test
        trap cleanup_quota_test EXIT
 
-       $SETSTRIPE $TESTFILE -c 1 -i 0
+       $LFS setstripe $TESTFILE -c 1 -i 0
        chown $TSTUSR.$TSTUSR $TESTFILE
        [ "$qtype" == "p" ] && is_project_quota_supported &&
                change_project -p $TSTPRJID $TESTFILE
@@ -742,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
@@ -779,7 +804,7 @@ test_block_soft() {
        $SHOW_QUOTA_INFO_GROUP
        $SHOW_QUOTA_INFO_PROJID
 
-       $SETSTRIPE $TESTFILE -c 1 -i 0
+       $LFS setstripe $TESTFILE -c 1 -i 0
        chown $TSTUSR.$TSTUSR $TESTFILE
        [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
 
@@ -792,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)"
@@ -809,7 +840,6 @@ test_3() {
                error "set user quota failed"
 
        test_block_soft $TESTFILE $GRACE $LIMIT "u"
-       resetquota -u $TSTUSR
 
        echo "Group quota (soft limit:$LIMIT MB  grace:$GRACE seconds)"
        TESTFILE=$DIR/$tdir/$tfile-1
@@ -823,7 +853,6 @@ test_3() {
                error "set group quota failed"
 
        test_block_soft $TESTFILE $GRACE $LIMIT "g"
-       resetquota -g $TSTUSR
 
        if is_project_quota_supported; then
                echo "Project quota (soft limit:$LIMIT MB  grace:$GRACE sec)"
@@ -831,7 +860,7 @@ test_3() {
                # make sure the system is clean
                USED=$(getquota -p $TSTPRJID global curspace)
                [ $USED -ne 0 ] && error \
-                       "Used space($USED) for project $TSTPROJID isn't 0."
+                       "Used space($USED) for project $TSTPRJID isn't 0."
 
                $LFS setquota -t -p --block-grace $GRACE --inode-grace \
                        $MAX_IQ_TIME $DIR ||
@@ -858,12 +887,11 @@ 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
-       is_project_quota_supported && change_project +P $DIR/$tdir/ &&
-               change_project -p $TSTPRJID -d $DIR/$tdir
+       is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
 
        echo "Create files to exceed soft limit"
        $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
@@ -882,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
@@ -926,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
 
@@ -942,8 +970,9 @@ test_4a() {
        $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
                error "set user quota failed"
 
-       test_file_soft $TESTFILE $LIMIT $GRACE
-       resetquota -u $TSTUSR
+       [ "$mds1_FSTYPE" = zfs ] && GRACE=20
+
+       test_file_soft $TESTFILE $LIMIT $GRACE "u"
 
        echo "Group quota (soft limit:$LIMIT files  grace:$GRACE seconds)"
        # make sure the system is clean
@@ -956,8 +985,7 @@ test_4a() {
                error "set group quota failed"
        TESTFILE=$DIR/$tdir/$tfile-1
 
-       test_file_soft $TESTFILE $LIMIT $GRACE
-       resetquota -g $TSTUSR
+       test_file_soft $TESTFILE $LIMIT $GRACE "g"
 
        if is_project_quota_supported; then
                echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
@@ -973,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 ||
@@ -1054,6 +1082,9 @@ test_5() {
        USED=$(getquota -g $TSTUSR global curspace)
        [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
        if is_project_quota_supported; then
+               USED=$(getquota -p $TSTPRJID global curinodes)
+               [ $USED -ne 0 ] &&
+                       error "Used inode($USED) for project $TSTPRJID isn't 0."
                USED=$(getquota -p $TSTPRJID global curspace)
                [ $USED -ne 0 ] &&
                        error "Used block($USED) for project $TSTPRJID isn't 0."
@@ -1079,10 +1110,6 @@ test_5() {
        unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
                error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
        cleanup_quota_test
-
-       resetquota -u $TSTUSR
-       resetquota -g $TSTUSR
-       resetquota -p $TSTPRJID
 }
 run_test 5 "Chown & chgrp successfully even out of block/file quota"
 
@@ -1107,12 +1134,12 @@ test_6() {
 
        # create file for $TSTUSR
        local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
-       $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        # create file for $TSTUSR2
        local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
-       $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
+       $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
        chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
 
        # cache per-ID lock for $TSTUSR on slave
@@ -1122,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
 
@@ -1129,6 +1169,9 @@ test_6() {
        #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
        lustre_fail mds 0x513 601
 
+       do_facet ost1 $LCTL set_param \
+                       osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
+
        # write to un-enforced ID ($TSTUSR2) should succeed
        $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
                error "write failure, expect success"
@@ -1142,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
@@ -1152,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"
 
@@ -1176,7 +1221,6 @@ test_6() {
        done
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 6 "Test dropping acquire request on master"
 
@@ -1205,7 +1249,7 @@ test_7a() {
                error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
 
        # create test file
-       $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        echo "Stop ost1..."
@@ -1249,7 +1293,6 @@ test_7a() {
                quota_error u $TSTUSR "write error, but expect success"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 7a "Quota reintegration (global index)"
 
@@ -1276,7 +1319,7 @@ test_7b() {
                error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
 
        # create test file
-       $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        # consume some space to make sure the granted space will not
@@ -1309,7 +1352,6 @@ test_7b() {
        [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
        $SHOW_QUOTA_USER
 }
 run_test 7b "Quota reintegration (slave index)"
@@ -1338,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"
@@ -1362,7 +1404,6 @@ test_7c() {
                quota_error u $TSTUSR "write success, but expect EDQUOT"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 7c "Quota reintegration (restart mds during reintegration)"
 
@@ -1399,25 +1440,22 @@ test_7d(){
                quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
-       resetquota -u $TSTUSR2
 }
 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
 
 # quota reintegration (inode limits)
 test_7e() {
-       [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
+       [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
 
        # 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)
 
                [[ "$feature" != *" active "* ]] &&
-                       skip "requires zpool with active userobj_accounting" &&
-                       return
+                       skip "requires zpool with active userobj_accounting"
        }
 
        local ilimit=$((1024 * 2)) # 2k inodes
@@ -1488,7 +1526,6 @@ test_7e() {
        rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 7e "Quota reintegration (inode limits)"
 
@@ -1510,8 +1547,7 @@ test_8() {
        $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
                error "set group quota failed"
        if is_project_quota_supported; then
-               change_project +P $DIR/$tdir && change_project -p \
-                       $TSTPRJID -d $DIR/$tdir
+               change_project -sp $TSTPRJID $DIR/$tdir
                echo "Set enough high limit for project: $TSTPRJID"
                $LFS setquota -p $TSTPRJID -b 0 \
                        -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
@@ -1523,12 +1559,8 @@ test_8() {
        $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
                quota_error a $TSTUSR "dbench failed!"
 
-       is_project_quota_supported && change_project -P $DIR/$tdir &&
-       change_project -dp 0 $DIR/$tdir
+       is_project_quota_supported && change_project -C $DIR/$tdir
        cleanup_quota_test
-       resetquota -u $TSTUSR
-       resetquota -g $TSTUSR
-       resetquota -p $TSTPRJID
 }
 run_test 8 "Run dbench with quota enabled"
 
@@ -1577,7 +1609,7 @@ test_9() {
        quota_show_check a g $TSTUSR
 
        echo "Create test file"
-       $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        log "Write the big file of 4.5G ..."
@@ -1588,8 +1620,6 @@ test_9() {
        $SHOW_QUOTA_GROUP
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
-       resetquota -g $TSTUSR
 
        $SHOW_QUOTA_USER
        $SHOW_QUOTA_GROUP
@@ -1617,14 +1647,13 @@ test_10() {
                error "set quota failed"
        quota_show_check b u $TSTUSR
 
-       $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
                error "write failure, expect success"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 10 "Test quota for root user"
 
@@ -1648,12 +1677,11 @@ test_11() {
        [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 11 "Chown/chgrp ignores quota"
 
 test_12a() {
-       [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs" && return
+       [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
 
        local blimit=22 # 22M
        local blk_cnt=$((blimit - 5))
@@ -1669,8 +1697,8 @@ test_12a() {
        $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
                error "set quota failed"
 
-       $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
-       $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
+       $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
+       $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
        chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
        chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
 
@@ -1692,12 +1720,11 @@ test_12a() {
                quota_error a $TSTUSR "rebalancing failed"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 12a "Block quota rebalancing"
 
 test_12b() {
-       [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
+       [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
 
        local ilimit=$((1024 * 2)) # 2k inodes
        local TESTFILE0=$DIR/$tdir/$tfile
@@ -1737,7 +1764,6 @@ test_12b() {
        rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 12b "Inode quota rebalancing"
 
@@ -1754,7 +1780,7 @@ test_13(){
 
        $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
                error "set quota failed"
-       $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        # clear the locks in cache first
@@ -1868,7 +1894,6 @@ test_17sub() {
                "Used space(${USED}K) is less than ${BLKS}M"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 
 # DQACQ return recoverable error
@@ -1906,7 +1931,7 @@ test_18_sub () {
                error "set quota failed"
        quota_show_check b u $TSTUSR
 
-       $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        local timeout=$(sysctl -n lustre.timeout)
@@ -1951,7 +1976,6 @@ test_18_sub () {
                        "got ${testfile_size}. Verifying file failed!"
        fi
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 
 # test when mds does failover, the ost still could work well
@@ -1966,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
@@ -1983,7 +2007,7 @@ test_19() {
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # bind file to a single OST
-       $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
+       $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        echo "Set user quota (limit: ${blimit}M)"
@@ -2004,7 +2028,6 @@ test_19() {
        $SHOW_QUOTA_USER
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
 
@@ -2121,9 +2144,6 @@ test_21() {
        echo "(dd_pid=$DDPID2, time=$count)successful"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
-       resetquota -g $TSTUSR
-       resetquota -p $TSTPRJID
 }
 run_test 21 "Setquota while writing & deleting (b16053)"
 
@@ -2142,7 +2162,7 @@ test_22() {
 
        echo "Verify if quota is enabled"
        local qtype1=$(mdt_quota_type)
-       [ $qtype1 != $qtype] && error "mdt quota setting is lost"
+       [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
        qtype=$(ost_quota_type)
        [ $qtype1 != $qtype ] && error "ost quota setting is lost"
 
@@ -2164,7 +2184,7 @@ test_22() {
 
        return 0
 }
-run_test 22 "enable/disable quota by 'lctl conf_param'"
+run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
 
 test_23_sub() {
        local TESTFILE="$DIR/$tdir/$tfile"
@@ -2181,7 +2201,7 @@ test_23_sub() {
                error "set quota failed"
        quota_show_check b u $TSTUSR
 
-       $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        log "Step1: trigger EDQUOT with O_DIRECT"
@@ -2210,13 +2230,12 @@ test_23_sub() {
                ($SHOW_QUOTA_USER; \
                quota_error u $TSTUSR "quota isn't released")
        $SHOW_QUOTA_USER
-       resetquota -u $TSTUSR
 }
 
 test_23() {
-       [ $(facet_fstype ost1) == "zfs" ] &&
+       [ "$ost1_FSTYPE" == zfs ] &&
                skip "Overwrite in place is not guaranteed to be " \
-               "space neutral on ZFS" && return
+               "space neutral on ZFS"
 
        local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
        check_whether_skip && return 0
@@ -2240,7 +2259,7 @@ test_24() {
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # bind file to a single OST
-       $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
+       $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        echo "Set user quota (limit: ${blimit}M)"
@@ -2256,7 +2275,6 @@ test_24() {
        $SHOW_QUOTA_USER | grep '*' || error "no matching *"
 
        cleanup_quota_test
-       resetquota -u $TSTUSR
 }
 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
 
@@ -2285,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
 }
@@ -2344,7 +2362,7 @@ test_30() {
 
        set_ost_qtype "u" || error "enable ost quota failed"
 
-       $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
+       $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
        chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
 
        $LFS setquota -t -u --block-grace $GRACE --inode-grace \
@@ -2366,7 +2384,6 @@ test_30() {
                error "grace times were reset"
        # cleanup
        cleanup_quota_test
-       resetquota -u $TSTUSR
        $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
                $MAX_IQ_TIME $DIR || error "restore grace time failed"
 }
@@ -2447,6 +2464,9 @@ test_33() {
        USED=$(getquota -g $TSTID global curinodes)
        [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
        if is_project_quota_supported; then
+               USED=$(getquota -p $TSTPRJID global curspace)
+               [ $USED -eq 0 ] ||
+                       error "Used space for project $TSTPRJID isn't 0. $USED"
                USED=$(getquota -p $TSTPRJID global curinodes)
                [ $USED -eq 0 ] ||
                        error "Used inodes for project $TSTPRJID isn't 0. $USED"
@@ -2592,10 +2612,8 @@ test_35() {
        fi
 
        log "Restart..."
-       local ORIG_REFORMAT=$REFORMAT
-       REFORMAT=""
-       cleanup_and_setup_lustre
-       REFORMAT=$ORIG_REFORMAT
+       stopall
+       setupall
        quota_init
 
        echo "Verify disk usage after restart"
@@ -2656,8 +2674,8 @@ 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) ] &&
-               skip "Old server doesn't have LU-5006 fix." && return
+       [ "$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 $?"
        trap cleanup_quota_test EXIT
@@ -2668,7 +2686,7 @@ test_37() {
                error "Used space ($USED) for user $TSTID isn't 0."
 
        # create file with MDS_OPEN_DELAY_CREATE flag
-       $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
+       $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
                error "Create file failed"
        # write to file
        dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
@@ -2688,8 +2706,8 @@ 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) ] &&
-               skip "Old server doesn't have LU-8801 fix." && return
+       [ "$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
 
@@ -2711,19 +2729,24 @@ test_38() {
        echo "Create $file_cnt files..."
        for i in `seq $file_cnt`; do
                touch $TESTFILE-$i
-               chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i
+               chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
+                       error "failed to chown $TESTFILE-$i"
        done
        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
 
-       acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | wc -l)
+       acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
+                  awk '{if ($3 < 10000) {print $3}}' | wc -l)
        echo "Found $acct_cnt id entries"
 
-       [ $file_cnt -eq $acct_cnt ] || error "skipped id entries"
+       [ $file_cnt -eq $acct_cnt ] || {
+               do_facet mds1 $LCTL get_param $procf
+               error "skipped id entries"
+       }
 
        cleanup_quota_test
 }
@@ -2732,23 +2755,23 @@ run_test 38 "Quota accounting iterator doesn't skip id entries"
 test_39() {
        local TESTFILE="$DIR/$tdir/project"
        ! is_project_quota_supported &&
-               skip "Project quota is not supported" && return 0
+               skip "Project quota is not supported"
 
        setup_quota_test || error "setup quota failed with $?"
 
        touch $TESTFILE
-       projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
+       projectid=$(lfs project $TESTFILE | awk '{print $1}')
        [ $projectid -ne 0 ] &&
                error "Project id should be 0 not $projectid"
        change_project -p 1024 $TESTFILE
-       projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
+       projectid=$(lfs project $TESTFILE | awk '{print $1}')
        [ $projectid -ne 1024 ] &&
                error "Project id should be 1024 not $projectid"
 
        stopall || error "failed to stopall (1)"
        mount
        setupall
-       projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
+       projectid=$(lfs project $TESTFILE | awk '{print $1}')
        [ $projectid -ne 1024 ] &&
                error "Project id should be 1024 not $projectid"
 
@@ -2758,15 +2781,15 @@ run_test 39 "Project ID interface works correctly"
 
 test_40a() {
        ! is_project_quota_supported &&
-               skip "Project quota is not supported" && return 0
+               skip "Project quota is not supported"
        local dir1="$DIR/$tdir/dir1"
        local dir2="$DIR/$tdir/dir2"
 
        setup_quota_test || error "setup quota failed with $?"
 
        mkdir -p $dir1 $dir2
-       change_project +P $dir1 && change_project -p 1 -d $dir1 && touch $dir1/1
-       change_project +P $dir2 && change_project -p 2 -d $dir2
+       change_project -sp 1 $dir1 && touch $dir1/1
+       change_project -sp 2 $dir2
 
        ln $dir1/1 $dir2/1_link &&
                error "Hard link across different project quota should fail"
@@ -2778,17 +2801,17 @@ run_test 40a "Hard link across different project ID"
 
 test_40b() {
        ! is_project_quota_supported &&
-               skip "Project quota is not supported" && return 0
+               skip "Project quota is not supported"
        local dir1="$DIR/$tdir/dir1"
        local dir2="$DIR/$tdir/dir2"
 
        setup_quota_test || error "setup quota failed with $?"
        mkdir -p $dir1 $dir2
-       change_project +P $dir1 && change_project -p 1 -d $dir1 && touch $dir1/1
-       change_project +P $dir2 && change_project -p 2 -d $dir2
+       change_project -sp 1 $dir1 && touch $dir1/1
+       change_project -sp 2 $dir2
 
        mv $dir1/1 $dir2/2 || error "mv failed $?"
-       local projid=$(lsattr -p $dir2/2 | awk '{print $1}')
+       local projid=$(lfs project $dir2/2 | awk '{print $1}')
        if [ "$projid" != "2" ]; then
                error "project id expected 2 not $projid"
        fi
@@ -2798,20 +2821,20 @@ test_40b() {
 run_test 40b "Mv across different project ID"
 
 test_40c() {
-       [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
+       [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
                ! is_project_quota_supported &&
-                       skip "Project quota is not supported" && return 0
+                       skip "Project quota is not supported"
 
        setup_quota_test || error "setup quota failed with $?"
        local dir="$DIR/$tdir/dir"
 
-       mkdir -p $dir && change_project +P $dir && change_project -dp 1 $dir
+       mkdir -p $dir && change_project -sp 1 $dir
        $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
-       local projid=$(lsattr -dp $dir/remote_dir | awk '{print $1}')
+       local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
        [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
        touch $dir/remote_dir/file
        #verify inherit works file for remote dir.
-       local projid=$(lsattr -dp $dir/remote_dir/file | awk '{print $1}')
+       local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
        [ "$projid" != "1" ] &&
                error "file under remote dir expected 1 not $projid"
 
@@ -2828,46 +2851,58 @@ run_test 40c "Remote child Dir inherit project quota properly"
 
 test_50() {
        ! is_project_quota_supported &&
-               skip "Project quota is not supported" && return 0
+               skip "Project quota is not supported"
 
        setup_quota_test || error "setup quota failed with $?"
-       local dir="$DIR/$tdir/dir"
+       local dir1="$DIR/$tdir/dir1"
+       local dir2="$DIR/$tdir/dir2"
+
+       mkdir -p $dir1 && change_project -sp 1 $dir1
+       mkdir -p $dir2 && change_project -sp 2 $dir2
+       for num in $(seq 1 10); do
+               touch $dir1/file_$num $dir2/file_$num
+               ln -s $dir1/file_$num $dir1/file_$num"_link"
+               ln -s $dir2/file_$num $dir2/file_$num"_link"
+       done
 
-       mkdir $dir && change_project -dp 1 $dir
        count=$($LFS find --projid 1 $DIR | wc -l)
-       [ "$count" != 1 ] && error "expected 1 but got $count"
+       [ "$count" != 21 ] && error "expected 21 but got $count"
 
-       rm -rf $dir
+       # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
+       count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
+       [ "$count" != 22 ] && error "expected 22 but got $count"
+
+       rm -rf $dir1 $dir2
        cleanup_quota_test
 }
 run_test 50 "Test if lfs find --projid works"
 
 test_51() {
        ! is_project_quota_supported &&
-               skip "Project quota is not supported" && return 0
+               skip "Project quota is not supported"
        setup_quota_test || error "setup quota failed with $?"
        local dir="$DIR/$tdir/dir"
 
-       mkdir $dir && change_project -dp 1 $dir && change_project +P $dir
+       mkdir $dir && change_project -sp 1 $dir
        local used=$(getquota -p 1 global curinodes)
-       [ $used != "1" ] &&  error "expected 1 got $used"
+       [ $used != "1" ] && error "expected 1 got $used"
 
        touch $dir/1
        touch $dir/2
        cp $dir/2 $dir/3
        used=$(getquota -p 1 global curinodes)
-       [ $used != "4" ] &&  error "expected 4 got $used"
+       [ $used != "4" ] && error "expected 4 got $used"
 
        $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
        #try cp to dir
        cp $DIR/$tdir/6 $dir/6
        used=$(getquota -p 1 global curinodes)
-       [ $used != "5" ] &&  error "expected 5 got $used"
+       [ $used != "5" ] && error "expected 5 got $used"
 
        #try mv to dir
        mv $DIR/$tdir/6 $dir/7
        used=$(getquota -p 1 global curinodes)
-       [ $used != "6" ] &&  error "expected 6 got $used"
+       [ $used != "6" ] && error "expected 6 got $used"
 
        rm -rf $dir
        cleanup_quota_test
@@ -2876,10 +2911,10 @@ run_test 51 "Test project accounting with mv/cp"
 
 test_52() {
        ! is_project_quota_supported &&
-               skip "Project quota is not supported" && return 0
+               skip "Project quota is not supported"
        setup_quota_test || error "setup quota failed with $?"
        local dir="$DIR/$tdir/dir"
-       mkdir $dir && change_project -dp 1 $dir && change_project +P $dir
+       mkdir $dir && change_project -sp 1 $dir
 
        touch $DIR/$tdir/file
        #Try renaming a file into the project.  This should fail.
@@ -2894,25 +2929,615 @@ run_test 52 "Rename across different project ID"
 
 test_53() {
        ! is_project_quota_supported &&
-               skip "Project quota is not supported" && return 0
+               skip "Project quota is not supported"
        setup_quota_test || error "setup quota failed with $?"
        local dir="$DIR/$tdir/dir"
-       mkdir $dir && change_project +P $dir
-       lsattr -pd $dir | grep P || error "inherit attribute should be set"
+       mkdir $dir && change_project -s $dir
+       lfs project -d $dir | grep P || error "inherit attribute should be set"
 
-       change_project -Pd $dir
-       lsattr -pd $dir | grep P && error "inherit attribute should be cleared"
+       change_project -C $dir
+       lfs project -d $dir | grep P &&
+               error "inherit attribute should be cleared"
 
        rm -rf $dir
        cleanup_quota_test
 }
 run_test 53 "Project inherit attribute could be cleared"
 
+test_54() {
+       ! is_project_quota_supported &&
+               skip "Project quota is not supported"
+       setup_quota_test || error "setup quota failed with $?"
+       trap cleanup_quota_test EXIT
+       local testfile="$DIR/$tdir/$tfile-0"
+
+       #set project ID/inherit attribute
+       change_project -sp $TSTPRJID $DIR/$tdir
+       $RUNAS createmany -m ${testfile} 100 ||
+               error "create many files failed"
+
+       local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
+       # one more count for directory itself */
+       ((proj_count++))
+
+       #check project
+       local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
+       [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
+
+       proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
+       [ $proj_count1 -eq $proj_count ] ||
+                       error "c2: expected $proj_count got $proj_count1"
+
+       #clear project but with kept projid
+       change_project -rCk $DIR/$tdir
+       proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
+       [ $proj_count1 -eq 1 ] ||
+                       error "c3: expected 1 got $proj_count1"
+
+       #verify projid untouched.
+       proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
+       ((proj_count1++))
+       [ $proj_count1 -eq $proj_count ] ||
+                       error "c4: expected $proj_count got $proj_count1"
+
+       # test -0 option
+       lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
+       proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
+       [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
+
+       #this time clear all
+       change_project -rC $DIR/$tdir
+       proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
+       [ $proj_count1 -eq 0 ] ||
+                       error "c6: expected 0 got $proj_count1"
+       #cleanup
+       unlinkmany ${testfile} 100 ||
+               error "unlink many files failed"
+
+       cleanup_quota_test
+}
+run_test 54 "basic lfs project interface test"
+
+test_55() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
+               skip "Not supported before 2.10.58."
+       setup_quota_test || error "setup quota failed with $?"
+
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+       quota_init
+
+       #add second group to TSTUSR
+       usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
+
+       #prepare test file
+       $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
+       error "failed to dd"
+
+       cancel_lru_locks osc
+       sync; sync_all_data || true
+
+       $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
+       error "failed to setquota on group $TSTUSR2"
+
+       $LFS quota -v -g $TSTUSR2 $DIR
+
+       runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
+       error "chgrp should failed with -EDQUOT"
+
+       USED=$(getquota -g $TSTUSR2 global curspace)
+       echo "$USED"
+
+       $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
+       error "failed to setquota on group $TSTUSR2"
+
+       $LFS quota -v -g $TSTUSR2 $DIR
+
+       runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
+       error "chgrp should succeed"
+
+       $LFS quota -v -g $TSTUSR2 $DIR
+
+       cleanup_quota_test
+}
+run_test 55 "Chgrp should be affected by group quota"
+
+test_56() {
+       setup_quota_test || error "setup quota failed with $?"
+
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+       quota_init
+
+       $LFS setquota -t -u -b 10 -i 10 $DIR ||
+               erro "failed to set grace time for usr quota"
+       grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
+                    awk '{print $4 $8}')
+       if [ "x$grace_time" != "x10s;10s" ]; then
+               $LFS quota -t -u $DIR
+               error "expected grace time: 10s;10s, got:$grace_time"
+       fi
+
+       cleanup_quota_test
+}
+run_test 56 "lfs quota -t should work well"
+
+test_57() {
+       setup_quota_test || error "setup quota failed with $?"
+
+       local dir="$DIR/$tdir/dir"
+       mkdir -p $dir
+       mkfifo $dir/pipe
+       #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 }'" \
+                       " 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
+       touch $dir/subdir/aaa $dir/subdir/bbb
+       #create one invalid link file
+       ln -s $dir/not_exist_file $dir/ccc
+       local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
+       [ $cnt -eq 5 ] || error "expected 5 got $cnt"
+
+       cleanup_quota_test
+}
+run_test 57 "lfs project could tolerate errors"
+
+test_59() {
+       [ "$mds1_FSTYPE" != ldiskfs ] &&
+               skip "ldiskfs only test"
+       disable_project_quota
+       setup_quota_test || error "setup quota failed with $?"
+       quota_init
+
+       local testfile="$DIR/$tdir/$tfile-0"
+       #make sure it did not crash kernel
+       touch $testfile && lfs project -sp 1 $testfile
+
+       enable_project_quota
+       cleanup_quota_test
+}
+run_test 59 "lfs project dosen't crash kernel with project disabled"
+
+test_60() {
+       [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
+               skip "Needs MDS version 2.11.53 or later."
+       setup_quota_test || error "setup quota failed with $?"
+       trap cleanup_quota_test EXIT
+
+       local testfile=$DIR/$tdir/$tfile
+       local limit=100
+
+       set_mdt_qtype "ug" || error "enable mdt quota failed"
+
+       $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
+               error "set quota failed"
+       quota_show_check a g $TSTUSR
+
+       chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
+       chmod g+s $DIR/$tdir || error "chmod g+s failed"
+       $RUNAS createmany -m ${testfile} $((limit-1)) ||
+               error "create many files failed"
+
+       $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
+
+       # root user can overrun quota
+       runas -u 0 -g 0 touch $DIR/$tdir/foo ||
+               error "root user should succeed"
+
+       cleanup_quota_test
+}
+run_test 60 "Test quota for root with setgid"
+
+# test default quota
+test_default_quota() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
+               skip "Not supported before 2.11.51."
+
+       local qtype=$1
+       local qpool=$2
+       local qid=$TSTUSR
+       local qprjid=$TSTPRJID
+       local qdtype="-U"
+       local qs="-b"
+       local qh="-B"
+       local LIMIT=20480 #20M disk space
+       local TESTFILE="$DIR/$tdir/$tfile-0"
+
+       [ $qtype == "-p" ] && ! is_project_quota_supported &&
+               echo "Project quota is not supported" && return 0
+
+       [ $qtype == "-u" ] && qdtype="-U"
+       [ $qtype == "-g" ] && qdtype="-G"
+       [ $qtype == "-p" ] && {
+               qdtype="-P"
+               qid=$qprjid
+       }
+
+       [ $qpool == "meta" ] && {
+               LIMIT=10240 #10K inodes
+               qs="-i"
+               qh="-I"
+       }
+
+       setup_quota_test || error "setup quota failed with $?"
+       trap cleanup_quota_test EXIT
+
+       quota_init
+
+       # enable mdt/ost quota
+       set_mdt_qtype $QTYPE || error "enable mdt quota failed"
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+       log "set to use default quota"
+       $LFS setquota $qtype $qid -d $DIR ||
+               error "set $qid to use default quota failed"
+
+       log "set default quota"
+       $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
+               error "set $qid default quota failed"
+
+       log "get default quota"
+       $LFS quota $qdtype $DIR || error "get default quota failed"
+
+       if [ $qpool == "data" ]; then
+               local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
+                                                       awk '{print $2}')
+               [ $SLIMIT -eq $LIMIT ] ||
+                       error "the returned default quota is wrong"
+       else
+               local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
+                                                       awk '{print $5}')
+               [ $SLIMIT -eq $LIMIT ] ||
+                       error "the returned default quota is wrong"
+       fi
+
+       # make sure the system is clean
+       local USED=$(getquota $qtype $qid global curspace)
+       [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
+
+       $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
+       chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+       [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
+
+       log "Test not out of quota"
+       if [ $qpool == "data" ]; then
+               $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
+                       quota_error $qtype $qid "write failed, expect succeed"
+       else
+               $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
+                       quota_error $qtype $qid "create failed, expect succeed"
+
+               unlinkmany $TESTFILE $((LIMIT/2))
+       fi
+
+       log "Test out of quota"
+       # flush cache, ensure noquota flag is set on client
+       cancel_lru_locks osc
+       cancel_lru_locks mdc
+       sync; sync_all_data || true
+       if [ $qpool == "data" ]; then
+               $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
+                       quota_error $qtype $qid "write succeed, expect EDQUOT"
+       else
+               $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
+                       quota_error $qtype $qid "create succeed, expect EDQUOT"
+
+               unlinkmany $TESTFILE $((LIMIT*2))
+       fi
+
+       log "Increase default quota"
+       # increase default quota
+       $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
+               error "set default quota failed"
+
+       cancel_lru_locks osc
+       cancel_lru_locks mdc
+       sync; sync_all_data || true
+       if [ $qpool == "data" ]; then
+               $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
+                       quota_error $qtype $qid "write failed, expect succeed"
+       else
+               $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
+                       quota_error $qtype $qid "create failed, expect succeed"
+
+               unlinkmany $TESTFILE $((LIMIT*2))
+       fi
+
+       log "Set quota to override default quota"
+       $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
+               error "set $qid quota failed"
+
+       cancel_lru_locks osc
+       cancel_lru_locks mdc
+       sync; sync_all_data || true
+       if [ $qpool == "data" ]; then
+               $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
+                       quota_error $qtype $qid "write succeed, expect EQUOT"
+       else
+               $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
+                       quota_error $qtype $qid "create succeed, expect EQUOT"
+
+               unlinkmany $TESTFILE $((LIMIT*2))
+       fi
+
+       log "Set to use default quota again"
+       $LFS setquota $qtype $qid -d $DIR ||
+               error "set $qid to use default quota failed"
+
+       cancel_lru_locks osc
+       cancel_lru_locks mdc
+       sync; sync_all_data || true
+       if [ $qpool == "data" ]; then
+               $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
+                       quota_error $qtype $qid "write failed, expect succeed"
+       else
+               $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
+                       quota_error $qtype $qid "create failed, expect succeed"
+
+               unlinkmany $TESTFILE $((LIMIT*2))
+       fi
+
+       log "Cleanup"
+       rm -f $TESTFILE
+       wait_delete_completed || error "wait_delete_completed failed"
+       sync_all_data || true
+       $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
+               error "reset default quota failed"
+       $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
+               error "reset quota failed"
+
+       cleanup_quota_test
+}
+
+test_61() {
+       test_default_quota "-u" "data"
+       test_default_quota "-u" "meta"
+       test_default_quota "-g" "data"
+       test_default_quota "-g" "meta"
+       test_default_quota "-p" "data"
+       test_default_quota "-p" "meta"
+}
+run_test 61 "default quota tests"
+
+test_62() {
+       ! is_project_quota_supported &&
+               skip "Project quota is not supported"
+        [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
+               skip "chattr did not support project quota"
+       setup_quota_test || error "setup quota failed with $?"
+       local testdir=$DIR/$tdir/
+
+       $RUNAS mkdir -p $testdir || error "failed to mkdir"
+       change_project -s $testdir
+       [[ $($LFS project -d $testdir) =~ "P" ]] ||
+               error "inherit attribute should be set"
+       # chattr used FS_IOC_SETFLAGS ioctl
+       $RUNAS chattr -P $testdir &&
+               error "regular user clear inherit should fail"
+       [[ $($LFS project -d $testdir) =~ "P" ]] ||
+               error "inherit attribute should still be set"
+       chattr -P $testdir || error "root failed to clear inherit"
+       [[ $($LFS project -d $testdir) =~ "P" ]] &&
+               error "inherit attribute should be cleared"
+       cleanup_quota_test
+}
+run_test 62 "Project inherit should be only changed by root"
+
+test_dom() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
+               skip "Not supported before 2.11.55"
+
+       local qtype=$1
+       local qid=$TSTUSR
+       local dd_failed=false
+       local tdir_dom=${tdir}_dom
+       local LIMIT=20480 #20M
+
+       [ $qtype == "p" ] && ! is_project_quota_supported &&
+               echo "Project quota is not supported" && return 0
+
+       [ $qtype == "p" ] && qid=$TSTPRJID
+
+       setup_quota_test || error "setup quota failed with $?"
+       trap cleanup_quota_test EXIT
+
+       quota_init
+
+       # enable mdt/ost quota
+       set_mdt_qtype $QTYPE || error "enable mdt quota failed"
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+       # make sure the system is clean
+       local USED=$(getquota -$qtype $qid global curspace)
+       [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
+
+       chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
+
+       mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
+       $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
+               error "setstripe $tdir_dom failed"
+       chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
+
+       [ $qtype == "p" ] && {
+               change_project -sp $TSTPRJID $DIR/$tdir
+               change_project -sp $TSTPRJID $DIR/$tdir_dom
+       }
+
+       $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
+               error "set $qid quota failed"
+
+       for ((i = 0; i < $((LIMIT/2048)); i++)); do
+               $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
+                                                               dd_failed=true
+       done
+
+       $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
+
+       for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
+               $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
+                                                               dd_failed=true
+       done
+
+       $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
+
+       rm -f $DIR/$tdir_dom/*
+
+       # flush cache, ensure noquota flag is set on client
+       cancel_lru_locks osc
+       cancel_lru_locks mdc
+       sync; sync_all_data || true
+
+       dd_failed=false
+
+       $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
+               quota_error $qtype $qid "write failed, expect succeed"
+
+       for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
+               $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
+                                                               dd_failed=true
+       done
+
+       $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
+
+       rm -f $DIR/$tdir/*
+       rm -f $DIR/$tdir_dom/*
+
+       # flush cache, ensure noquota flag is set on client
+       cancel_lru_locks osc
+       cancel_lru_locks mdc
+       sync; sync_all_data || true
+
+       dd_failed=false
+
+       for ((i = 0; i < $((LIMIT/2048)); i++)); do
+               $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
+                                                               dd_failed=true
+       done
+
+       $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
+
+       $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
+               quota_error $qtype $qid "write succeed, expect EDQUOT"
+
+       rm -f $DIR/$tdir/*
+       rm -fr $DIR/$tdir_dom
+
+       $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
+               error "reset usr quota failed"
+
+       cleanup_quota_test
+}
+
+test_63() {
+       test_dom "u"
+       test_dom "g"
+       test_dom "p"
+}
+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"
-       disable_project_quota
+       if $PQ_CLEANUP; then
+               disable_project_quota
+       fi
 }
+reset_quota_settings
 quota_fini
 
 cd $ORIG_PWD