Whamcloud - gitweb
LU-15179 tests: add trap cleanup_quota_test 18/45418/5
authorSergey Cheremencev <sergey.cheremencev@hpe.com>
Fri, 29 Oct 2021 19:00:46 +0000 (22:00 +0300)
committerOleg Drokin <green@whamcloud.com>
Tue, 30 Nov 2021 03:45:26 +0000 (03:45 +0000)
Add stack_trap cleanup_quota_test to the tests that
use setup_quota_test. If a test fails without calling
cleanup_quota_test, it may cause later tests to fail
due to used space > 0.

Remove ${tdir}_dom, if exists, in cleanup_quota_test.
sanity-quota_75 doesn't remove test_dom directory.

Test-Parameters: trivial  testlist=sanity-quota
Fixes: a4fbe734("LU-14739 quota: nodemap squashed root cannot bypass quota")
Change-Id: Ife4fd499b427bee79f74a5e172d233fe6a83e240
Signed-off-by: Sergey Cheremencev <sergey.cheremencev@hpe.com>
Reviewed-on: https://review.whamcloud.com/45418
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Alexander Zarochentsev <alexander.zarochentsev@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity-quota.sh

index 596442e..6734587 100755 (executable)
@@ -408,11 +408,13 @@ setup_quota_test() {
        # always clear fail_loc in case of fail_loc isn't cleared
        # properly when previous test failed
        lustre_fail mds_ost 0
        # always clear fail_loc in case of fail_loc isn't cleared
        # properly when previous test failed
        lustre_fail mds_ost 0
+       stack_trap cleanup_quota_test EXIT
 }
 
 cleanup_quota_test() {
        echo "Delete files..."
        rm -rf $DIR/$tdir
 }
 
 cleanup_quota_test() {
        echo "Delete files..."
        rm -rf $DIR/$tdir
+       [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
        echo "Wait for unlink objects finished..."
        wait_delete_completed
        sync_all_data || true
        echo "Wait for unlink objects finished..."
        wait_delete_completed
        sync_all_data || true
@@ -533,7 +535,6 @@ test_0() {
                skip "not enough space ${free_space} KB, " \
                        "required $((MB * 1024)) KB"
        setup_quota_test || error "setup quota failed with $?"
                skip "not enough space ${free_space} KB, " \
                        "required $((MB * 1024)) KB"
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype "none" || error "disable ost quota failed"
        test_quota_performance $MB
 
        set_ost_qtype "none" || error "disable ost quota failed"
        test_quota_performance $MB
@@ -542,8 +543,6 @@ test_0() {
        $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
                error "set quota failed"
        test_quota_performance $MB
        $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
                error "set quota failed"
        test_quota_performance $MB
-
-       cleanup_quota_test
 }
 run_test 0 "Test basic quota performance"
 
 }
 run_test 0 "Test basic quota performance"
 
@@ -571,6 +570,7 @@ test_1_check_write() {
        $RUNAS $DD of=$testfile count=1 seek=$limit &&
                quota_error $short_qtype $TSTUSR \
                        "user write success, but expect EDQUOT"
        $RUNAS $DD of=$testfile count=1 seek=$limit &&
                quota_error $short_qtype $TSTUSR \
                        "user write success, but expect EDQUOT"
+       return 0
 }
 
 check_write_fallocate() {
 }
 
 check_write_fallocate() {
@@ -601,7 +601,6 @@ test_1a() {
        local testfile="$DIR/$tdir/$tfile-0"
 
        setup_quota_test || error "setup quota failed with $?"
        local testfile="$DIR/$tdir/$tfile-0"
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -653,7 +652,6 @@ test_1a() {
 
        if ! is_project_quota_supported; then
                echo "Project quota is not supported"
 
        if ! is_project_quota_supported; then
                echo "Project quota is not supported"
-               cleanup_quota_test
                return 0
        fi
 
                return 0
        fi
 
@@ -694,7 +692,6 @@ test_1b() {
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -760,7 +757,6 @@ test_1b() {
 
        if ! is_project_quota_supported; then
                echo "Project quota is not supported"
 
        if ! is_project_quota_supported; then
                echo "Project quota is not supported"
-               cleanup_quota_test
                return 0
        fi
 
                return 0
        fi
 
@@ -803,7 +799,6 @@ test_1c() {
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -848,12 +843,8 @@ test_1c() {
        sync_all_data || true
 
        used=$(getquota -u $TSTUSR global curspace $qpool1)
        sync_all_data || true
 
        used=$(getquota -u $TSTUSR global curspace $qpool1)
-       [ $used -ne 0 ] && quota_error u $TSTUSR \
+       [ $used -eq 0 ] || quota_error u $TSTUSR \
                "user quota isn't released after deletion"
                "user quota isn't released after deletion"
-       resetquota -u $TSTUSR
-
-       # cleanup
-       cleanup_quota_test
 }
 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
 
 }
 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
 
@@ -867,7 +858,6 @@ test_1d() {
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -910,12 +900,8 @@ test_1d() {
        sync_all_data || true
 
        used=$(getquota -u $TSTUSR global curspace $qpool1)
        sync_all_data || true
 
        used=$(getquota -u $TSTUSR global curspace $qpool1)
-       [ $used -ne 0 ] && quota_error u $TSTUSR \
+       [ $used -eq 0 ] || quota_error u $TSTUSR \
                "user quota isn't released after deletion"
                "user quota isn't released after deletion"
-       resetquota -u $TSTUSR
-
-       # cleanup
-       cleanup_quota_test
 }
 run_test 1d "Quota pools: check block hardlimit on different pools"
 
 }
 run_test 1d "Quota pools: check block hardlimit on different pools"
 
@@ -928,7 +914,6 @@ test_1e() {
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -972,12 +957,8 @@ test_1e() {
        sync_all_data || true
 
        used=$(getquota -u $TSTUSR global curspace $qpool1)
        sync_all_data || true
 
        used=$(getquota -u $TSTUSR global curspace $qpool1)
-       [ $used -ne 0 ] && quota_error u $TSTUSR \
+       [ $used -eq 0 ] || quota_error u $TSTUSR \
                "user quota isn't released after deletion"
                "user quota isn't released after deletion"
-       resetquota -u $TSTUSR
-
-       # cleanup
-       cleanup_quota_test
 }
 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
 
 }
 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
 
@@ -990,7 +971,6 @@ test_1f() {
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -1030,9 +1010,6 @@ test_1f() {
        # became > 10M. QMT returned EINPROGRESS in a loop.
        # Check that it doesn't hung anymore.
        test_1_check_write $testfile "user" $limit1
        # became > 10M. QMT returned EINPROGRESS in a loop.
        # Check that it doesn't hung anymore.
        test_1_check_write $testfile "user" $limit1
-
-       # cleanup
-       cleanup_quota_test
 }
 run_test 1f "Quota pools: correct qunit after removing/adding OST"
 
 }
 run_test 1f "Quota pools: correct qunit after removing/adding OST"
 
@@ -1046,7 +1023,6 @@ test_1g() {
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
        $LCTL set_param $mdmb_param=1
        stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
 
        $LCTL set_param $mdmb_param=1
        stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
 
@@ -1106,7 +1082,6 @@ test_1h() {
        check_set_fallocate_or_skip
 
        setup_quota_test || error "setup quota failed with $?"
        check_set_fallocate_or_skip
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -1129,9 +1104,8 @@ test_1h() {
        wait_delete_completed || error "wait_delete_completed failed"
        sync_all_data || true
        used=$(getquota -u $TSTUSR global curspace)
        wait_delete_completed || error "wait_delete_completed failed"
        sync_all_data || true
        used=$(getquota -u $TSTUSR global curspace)
-       [ $used -ne 0 ] && quota_error u $TSTUSR \
+       [ $used -eq 0 ] || quota_error u $TSTUSR \
                "user quota isn't released after deletion"
                "user quota isn't released after deletion"
-       resetquota -u $TSTUSR
 }
 run_test 1h "Block hard limit test using fallocate"
 
 }
 run_test 1h "Block hard limit test using fallocate"
 
@@ -1154,7 +1128,6 @@ test_2() {
                skip "not enough free inodes $FREE_INODES required $LIMIT"
 
        setup_quota_test || error "setup quota failed with $?"
                skip "not enough free inodes $FREE_INODES required $LIMIT"
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # enable mdt quota
        set_mdt_qtype $QTYPE || error "enable mdt quota failed"
 
        # enable mdt quota
        set_mdt_qtype $QTYPE || error "enable mdt quota failed"
@@ -1213,7 +1186,7 @@ test_2() {
                "user quota isn't released after deletion"
 
        resetquota -g $TSTUSR
                "user quota isn't released after deletion"
 
        resetquota -g $TSTUSR
-       ! is_project_quota_supported && cleanup_quota_test &&
+       ! is_project_quota_supported &&
                echo "Skip project quota is not supported" && return 0
 
        # test for project
                echo "Skip project quota is not supported" && return 0
 
        # test for project
@@ -1256,7 +1229,6 @@ test_block_soft() {
                qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
 
        setup_quota_test
                qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
 
        setup_quota_test
-       stack_trap cleanup_quota_test EXIT
 
        $LFS setstripe $testfile -c 1 -i 0
        chown $TSTUSR.$TSTUSR $testfile
 
        $LFS setstripe $testfile -c 1 -i 0
        chown $TSTUSR.$TSTUSR $testfile
@@ -1587,7 +1559,6 @@ test_file_soft() {
                qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
 
        setup_quota_test
                qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
 
        setup_quota_test
-       trap cleanup_quota_test EXIT
        is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
 
        echo "Create files to exceed soft limit"
        is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
 
        echo "Create files to exceed soft limit"
@@ -1750,7 +1721,6 @@ test_5() {
        local ILIMIT=10 # inodes
 
        setup_quota_test || error "setup quota failed with $?"
        local ILIMIT=10 # inodes
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_mdt_qtype $QTYPE || error "enable mdt quota failed"
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        set_mdt_qtype $QTYPE || error "enable mdt quota failed"
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -1802,7 +1772,6 @@ test_5() {
        # cleanup
        unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
                error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
        # cleanup
        unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
                error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
-       cleanup_quota_test
 }
 run_test 5 "Chown & chgrp successfully even out of block/file quota"
 
 }
 run_test 5 "Chown & chgrp successfully even out of block/file quota"
 
@@ -1815,7 +1784,6 @@ test_6() {
        do_facet ost1 dmesg -c > /dev/null
 
        setup_quota_test || error "setup quota failed with $?"
        do_facet ost1 dmesg -c > /dev/null
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
@@ -1912,8 +1880,6 @@ test_6() {
                fi
                sleep 1
        done
                fi
                sleep 1
        done
-
-       cleanup_quota_test
 }
 run_test 6 "Test dropping acquire request on master"
 
 }
 run_test 6 "Test dropping acquire request on master"
 
@@ -1925,7 +1891,6 @@ test_7a() {
        [ "$SLOW" = "no" ] && LIMIT=5
 
        setup_quota_test || error "setup quota failed with $?"
        [ "$SLOW" = "no" ] && LIMIT=5
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
@@ -1984,8 +1949,6 @@ test_7a() {
        # hardlimit should be cleared on slave during reintegration
        $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
                quota_error u $TSTUSR "write error, but expect success"
        # hardlimit should be cleared on slave during reintegration
        $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
                quota_error u $TSTUSR "write error, but expect success"
-
-       cleanup_quota_test
 }
 run_test 7a "Quota reintegration (global index)"
 
 }
 run_test 7a "Quota reintegration (global index)"
 
@@ -1995,7 +1958,6 @@ test_7b() {
        local TESTFILE=$DIR/$tdir/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
        local TESTFILE=$DIR/$tdir/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
@@ -2057,7 +2019,6 @@ test_7c() {
        [ "$SLOW" = "no" ] && LIMIT=5
 
        setup_quota_test || error "setup quota failed with $?"
        [ "$SLOW" = "no" ] && LIMIT=5
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
@@ -2095,8 +2056,7 @@ test_7c() {
        # reintegration, write will exceed quota
        $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
                quota_error u $TSTUSR "write success, but expect EDQUOT"
        # reintegration, write will exceed quota
        $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
                quota_error u $TSTUSR "write success, but expect EDQUOT"
-
-       cleanup_quota_test
+       return 0
 }
 run_test 7c "Quota reintegration (restart mds during reintegration)"
 
 }
 run_test 7c "Quota reintegration (restart mds during reintegration)"
 
@@ -2107,7 +2067,6 @@ test_7d(){
        local limit=20 # MB
 
        setup_quota_test || error "setup quota failed with $?"
        local limit=20 # MB
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype "none" || error "disable ost quota failed"
        $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
 
        set_ost_qtype "none" || error "disable ost quota failed"
        $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
@@ -2131,8 +2090,7 @@ test_7d(){
 
        $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
                quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
 
        $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
                quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
-
-       cleanup_quota_test
+       return 0
 }
 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
 
 }
 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
 
@@ -2155,7 +2113,6 @@ test_7e() {
        local TESTFILE=$DIR/${tdir}-1/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
        local TESTFILE=$DIR/${tdir}-1/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curinodes)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curinodes)
@@ -2217,8 +2174,6 @@ test_7e() {
 
        $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
        rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
 
        $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
        rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
-
-       cleanup_quota_test
 }
 run_test 7e "Quota reintegration (inode limits)"
 
 }
 run_test 7e "Quota reintegration (inode limits)"
 
@@ -2228,7 +2183,6 @@ test_8() {
        local FILE_LIMIT=1000000
 
        setup_quota_test || error "setup quota failed with $?"
        local FILE_LIMIT=1000000
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_mdt_qtype $QTYPE || error "enable mdt quota failed"
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        set_mdt_qtype $QTYPE || error "enable mdt quota failed"
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -2253,7 +2207,6 @@ test_8() {
                quota_error a $TSTUSR "dbench failed!"
 
        is_project_quota_supported && change_project -C $DIR/$tdir
                quota_error a $TSTUSR "dbench failed!"
 
        is_project_quota_supported && change_project -C $DIR/$tdir
-       cleanup_quota_test
 }
 run_test 8 "Run dbench with quota enabled"
 
 }
 run_test 8 "Run dbench with quota enabled"
 
@@ -2278,7 +2231,6 @@ test_9() {
        check_whether_skip && return 0
 
        setup_quota_test || error "setup quota failed with $?"
        check_whether_skip && return 0
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype "ug" || error "enable ost quota failed"
 
 
        set_ost_qtype "ug" || error "enable ost quota failed"
 
@@ -2323,7 +2275,6 @@ test_10() {
        local TESTFILE=$DIR/$tdir/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
        local TESTFILE=$DIR/$tdir/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # set limit to root user should fail
        $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
 
        # set limit to root user should fail
        $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
@@ -2345,15 +2296,12 @@ test_10() {
 
        runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
                error "write failure, expect success"
 
        runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
                error "write failure, expect success"
-
-       cleanup_quota_test
 }
 run_test 10 "Test quota for root user"
 
 test_11() {
        local TESTFILE=$DIR/$tdir/$tfile
        setup_quota_test || error "setup quota failed with $?"
 }
 run_test 10 "Test quota for root user"
 
 test_11() {
        local TESTFILE=$DIR/$tdir/$tfile
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_mdt_qtype "ug" || error "enable mdt quota failed"
        $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
 
        set_mdt_qtype "ug" || error "enable mdt quota failed"
        $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
@@ -2368,8 +2316,6 @@ test_11() {
        $SHOW_QUOTA_USER
        local USED=$(getquota -u $TSTUSR global curinodes)
        [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
        $SHOW_QUOTA_USER
        local USED=$(getquota -u $TSTUSR global curinodes)
        [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
-
-       cleanup_quota_test
 }
 run_test 11 "Chown/chgrp ignores quota"
 
 }
 run_test 11 "Chown/chgrp ignores quota"
 
@@ -2382,7 +2328,6 @@ test_12a() {
        local TESTFILE1="$DIR/$tdir/$tfile"-1
 
        setup_quota_test || error "setup quota failed with $?"
        local TESTFILE1="$DIR/$tdir/$tfile"-1
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype "u" || error "enable ost quota failed"
        quota_show_check b u $TSTUSR
 
        set_ost_qtype "u" || error "enable ost quota failed"
        quota_show_check b u $TSTUSR
@@ -2411,8 +2356,6 @@ test_12a() {
        echo "Write to ost1 after space freed from ost0..."
        $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
                quota_error a $TSTUSR "rebalancing failed"
        echo "Write to ost1 after space freed from ost0..."
        $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
                quota_error a $TSTUSR "rebalancing failed"
-
-       cleanup_quota_test
 }
 run_test 12a "Block quota rebalancing"
 
 }
 run_test 12a "Block quota rebalancing"
 
@@ -2424,7 +2367,6 @@ test_12b() {
        local TESTFILE1=$DIR/${tdir}-1/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
        local TESTFILE1=$DIR/${tdir}-1/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
        chmod 0777 $DIR/${tdir}-1
 
        $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
        chmod 0777 $DIR/${tdir}-1
@@ -2455,8 +2397,6 @@ test_12b() {
        $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
                error "unlink mdt1 files failed"
        rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
        $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
                error "unlink mdt1 files failed"
        rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
-
-       cleanup_quota_test
 }
 run_test 12b "Inode quota rebalancing"
 
 }
 run_test 12b "Inode quota rebalancing"
 
@@ -2466,7 +2406,6 @@ test_13(){
        local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
 
        setup_quota_test || error "setup quota failed with $?"
        local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype "u" || error "enable ost quota failed"
        quota_show_check b u $TSTUSR
 
        set_ost_qtype "u" || error "enable ost quota failed"
        quota_show_check b u $TSTUSR
@@ -2504,8 +2443,6 @@ test_13(){
        local space=$(getquota -u $TSTUSR $OSTUUID curspace)
        [ $limit -le $space ] ||
                error "spare quota isn't released, limit:$limit, space:$space"
        local space=$(getquota -u $TSTUSR $OSTUUID curspace)
        [ $limit -le $space ] ||
                error "spare quota isn't released, limit:$limit, space:$space"
-
-       cleanup_quota_test
 }
 run_test 13 "Cancel per-ID lock in the LRU list"
 
 }
 run_test 13 "Cancel per-ID lock in the LRU list"
 
@@ -2539,7 +2476,6 @@ test_17sub() {
        local TESTFILE=$DIR/$tdir/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
        local TESTFILE=$DIR/$tdir/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
@@ -2616,7 +2552,6 @@ test_18_sub () {
        local TESTFILE="$DIR/$tdir/$tfile"
 
        setup_quota_test || error "setup quota failed with $?"
        local TESTFILE="$DIR/$tdir/$tfile"
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype "u" || error "enable ost quota failed"
        log "User quota (limit: $blimit)"
 
        set_ost_qtype "u" || error "enable ost quota failed"
        log "User quota (limit: $blimit)"
@@ -2695,7 +2630,6 @@ test_19() {
        local TESTFILE=$DIR/$tdir/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
        local TESTFILE=$DIR/$tdir/$tfile
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
 
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
@@ -2719,8 +2653,6 @@ test_19() {
        $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
                quota_error u $TSTUSR "Write success, expect failure"
        $SHOW_QUOTA_USER
        $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
                quota_error u $TSTUSR "Write success, expect failure"
        $SHOW_QUOTA_USER
-
-       cleanup_quota_test
 }
 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
 
 }
 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
 
@@ -2771,7 +2703,6 @@ test_21() {
        local ILIMIT=1000000
 
        setup_quota_test || error "setup quota failed with $?"
        local ILIMIT=1000000
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype $QTYPE || error "Enable ost quota failed"
 
 
        set_ost_qtype $QTYPE || error "Enable ost quota failed"
 
@@ -2835,8 +2766,6 @@ test_21() {
                sleep 1
        done
        echo "(dd_pid=$DDPID2, time=$count)successful"
                sleep 1
        done
        echo "(dd_pid=$DDPID2, time=$count)successful"
-
-       cleanup_quota_test
 }
 run_test 21 "Setquota while writing & deleting (b16053)"
 
 }
 run_test 21 "Setquota while writing & deleting (b16053)"
 
@@ -2884,7 +2813,6 @@ test_23_sub() {
        local LIMIT=$1
 
        setup_quota_test || error "setup quota failed with $?"
        local LIMIT=$1
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype $QTYPE || error "Enable ost quota failed"
 
 
        set_ost_qtype $QTYPE || error "Enable ost quota failed"
 
@@ -2947,7 +2875,6 @@ test_24() {
        local TESTFILE="$DIR/$tdir/$tfile"
 
        setup_quota_test || error "setup quota failed with $?"
        local TESTFILE="$DIR/$tdir/$tfile"
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
 
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
@@ -2966,8 +2893,6 @@ test_24() {
        sync_all_data || true
 
        $SHOW_QUOTA_USER | grep '*' || error "no matching *"
        sync_all_data || true
 
        $SHOW_QUOTA_USER | grep '*' || error "no matching *"
-
-       cleanup_quota_test
 }
 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
 
 }
 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
 
@@ -3051,7 +2976,6 @@ test_30() {
        local GRACE=10
 
        setup_quota_test || error "setup quota failed with $?"
        local GRACE=10
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        set_ost_qtype "u" || error "enable ost quota failed"
 
 
        set_ost_qtype "u" || error "enable ost quota failed"
 
@@ -3075,8 +2999,6 @@ test_30() {
        $SHOW_QUOTA_USER
        $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
                error "grace times were reset"
        $SHOW_QUOTA_USER
        $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
                error "grace times were reset"
-       # cleanup
-       cleanup_quota_test
        $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
                $MAX_IQ_TIME $DIR || error "restore grace time failed"
 }
        $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
                $MAX_IQ_TIME $DIR || error "restore grace time failed"
 }
@@ -3089,7 +3011,6 @@ test_33() {
        local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
 
        setup_quota_test || error "setup quota failed with $?"
        local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTID global curspace)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTID global curspace)
@@ -3174,7 +3095,6 @@ test_34() {
 
        is_project_quota_supported && project_supported="yes"
        setup_quota_test || error "setup quota failed with $?"
 
        is_project_quota_supported && project_supported="yes"
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTID global curspace)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTID global curspace)
@@ -3254,8 +3174,7 @@ test_34() {
                [ $USED -lt $BLK_CNT ] && error \
                        "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
        fi
                [ $USED -lt $BLK_CNT ] && error \
                        "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
        fi
-
-       cleanup_quota_test
+       return 0
 }
 run_test 34 "Usage transfer for user & group & project"
 
 }
 run_test 34 "Usage transfer for user & group & project"
 
@@ -3264,7 +3183,6 @@ test_35() {
        local BLK_CNT=2 # MB
 
        setup_quota_test || error "setup quota failed with $?"
        local BLK_CNT=2 # MB
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        echo "Write file..."
        $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
 
        echo "Write file..."
        $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
@@ -3359,8 +3277,6 @@ test_35() {
                        error "Used space for project $TSTPRJID isn't " \
                                "increased orig:$ORIG_PRJ_SPACE, now:$USED"
        fi
                        error "Used space for project $TSTPRJID isn't " \
                                "increased orig:$ORIG_PRJ_SPACE, now:$USED"
        fi
-
-       cleanup_quota_test
 }
 run_test 35 "Usage is still accessible across reboot"
 
 }
 run_test 35 "Usage is still accessible across reboot"
 
@@ -3371,7 +3287,6 @@ test_37() {
                skip "Old server doesn't have LU-5006 fix."
 
        setup_quota_test || error "setup quota failed with $?"
                skip "Old server doesn't have LU-5006 fix."
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTID global curspace)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTID global curspace)
@@ -3392,8 +3307,6 @@ test_37() {
 
        USED=$(getquota -u $TSTID global curspace)
        [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
 
        USED=$(getquota -u $TSTID global curspace)
        [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
-
-       cleanup_quota_test
 }
 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
 
 }
 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
 
@@ -3405,7 +3318,6 @@ test_38() {
        [ "$UID" != 0 ] && skip_env "must run as root" && return
 
        setup_quota_test || error "setup quota failed with $?"
        [ "$UID" != 0 ] && skip_env "must run as root" && return
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTID global curspace)
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTID global curspace)
@@ -3440,8 +3352,6 @@ test_38() {
                do_facet mds1 $LCTL get_param $procf
                error "skipped id entries"
        }
                do_facet mds1 $LCTL get_param $procf
                error "skipped id entries"
        }
-
-       cleanup_quota_test
 }
 run_test 38 "Quota accounting iterator doesn't skip id entries"
 
 }
 run_test 38 "Quota accounting iterator doesn't skip id entries"
 
@@ -3465,10 +3375,8 @@ test_39() {
        mount
        setupall
        projectid=$(lfs project $TESTFILE | awk '{print $1}')
        mount
        setupall
        projectid=$(lfs project $TESTFILE | awk '{print $1}')
-       [ $projectid -ne 1024 ] &&
+       [ $projectid -eq 1024 ] ||
                error "Project id should be 1024 not $projectid"
                error "Project id should be 1024 not $projectid"
-
-       cleanup_quota_test
 }
 run_test 39 "Project ID interface works correctly"
 
 }
 run_test 39 "Project ID interface works correctly"
 
@@ -3486,9 +3394,7 @@ test_40a() {
 
        ln $dir1/1 $dir2/1_link &&
                error "Hard link across different project quota should fail"
 
        ln $dir1/1 $dir2/1_link &&
                error "Hard link across different project quota should fail"
-       rm -rf $dir1 $dir2
-
-       cleanup_quota_test
+       return 0
 }
 run_test 40a "Hard link across different project ID"
 
 }
 run_test 40a "Hard link across different project ID"
 
@@ -3505,11 +3411,7 @@ test_40b() {
 
        mv $dir1/1 $dir2/2 || error "mv failed $?"
        local projid=$(lfs project $dir2/2 | awk '{print $1}')
 
        mv $dir1/1 $dir2/2 || error "mv failed $?"
        local projid=$(lfs project $dir2/2 | awk '{print $1}')
-       if [ "$projid" != "2" ]; then
-               error "project id expected 2 not $projid"
-       fi
-       rm -rf $dir1 $dir2
-       cleanup_quota_test
+       [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
 }
 run_test 40b "Mv across different project ID"
 
 }
 run_test 40b "Mv across different project ID"
 
@@ -3532,13 +3434,9 @@ test_40c() {
                error "file under remote dir expected 1 not $projid"
 
        #Agent inode should be ignored for project quota
                error "file under remote dir expected 1 not $projid"
 
        #Agent inode should be ignored for project quota
-       USED=$(getquota -p 1 global curinodes)
-       [ "$USED" != "3" ] &&
-               error "file count expected 3 got $USED"
-
-       rm -rf $dir
-       cleanup_quota_test
-       return 0
+       local used=$(getquota -p 1 global curinodes)
+       [ $used -eq 3 ] ||
+               error "file count expected 3 got $used"
 }
 run_test 40c "Remote child Dir inherit project quota properly"
 
 }
 run_test 40c "Remote child Dir inherit project quota properly"
 
@@ -3568,12 +3466,9 @@ test_40d() {
        done
 
        # account should be 1 + (2 + 1) *10 + 1 * 5
        done
 
        # account should be 1 + (2 + 1) *10 + 1 * 5
-       USED=$(getquota -p $TSTPRJID global curinodes)
-       [ "$USED" == "36" ] ||
-               error "file count expected 36 got $USED"
-
-       rm -rf $dir
-       cleanup_quota_test
+       local used=$(getquota -p $TSTPRJID global curinodes)
+       [ $used -eq 36 ] ||
+               error "file count expected 36 got $used"
 }
 run_test 40d "Stripe Directory inherit project quota properly"
 
 }
 run_test 40d "Stripe Directory inherit project quota properly"
 
@@ -3581,7 +3476,6 @@ test_41() {
        is_project_quota_supported ||
                skip "Project quota is not supported"
        setup_quota_test || error "setup quota failed with $?"
        is_project_quota_supported ||
                skip "Project quota is not supported"
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
        local dir="$DIR/$tdir/dir"
        local blimit=102400
        local ilimit=4096
        local dir="$DIR/$tdir/dir"
        local blimit=102400
        local ilimit=4096
@@ -3616,8 +3510,6 @@ test_41() {
                 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
                "$expected" ||
                error "failed to get correct statfs for project quota"
                 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
                "$expected" ||
                error "failed to get correct statfs for project quota"
-
-       cleanup_quota_test
 }
 run_test 41 "df should return projid-specific values"
 
 }
 run_test 41 "df should return projid-specific values"
 
@@ -3642,10 +3534,7 @@ test_50() {
 
        # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
        count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
 
        # 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
+       [ $count -eq 22 ] || error "expected 22 but got $count"
 }
 run_test 50 "Test if lfs find --projid works"
 
 }
 run_test 50 "Test if lfs find --projid works"
 
@@ -3674,10 +3563,7 @@ test_51() {
        #try mv to dir
        mv $DIR/$tdir/6 $dir/7
        used=$(getquota -p 1 global curinodes)
        #try mv to dir
        mv $DIR/$tdir/6 $dir/7
        used=$(getquota -p 1 global curinodes)
-       [ $used != "6" ] && error "expected 6 got $used"
-
-       rm -rf $dir
-       cleanup_quota_test
+       [ $used -eq 6 ] || error "expected 6 got $used"
 }
 run_test 51 "Test project accounting with mv/cp"
 
 }
 run_test 51 "Test project accounting with mv/cp"
 
@@ -3694,8 +3580,7 @@ test_52() {
                mrename $DIR/$tdir/file $dir/file >&/dev/null &&
                        error "rename should fail"
        done
                mrename $DIR/$tdir/file $dir/file >&/dev/null &&
                        error "rename should fail"
        done
-       rm -rf $dir
-       cleanup_quota_test
+       return 0
 }
 run_test 52 "Rename across different project ID"
 
 }
 run_test 52 "Rename across different project ID"
 
@@ -3705,14 +3590,12 @@ test_53() {
        setup_quota_test || error "setup quota failed with $?"
        local dir="$DIR/$tdir/dir"
        mkdir $dir && change_project -s $dir
        setup_quota_test || error "setup quota failed with $?"
        local dir="$DIR/$tdir/dir"
        mkdir $dir && change_project -s $dir
-       lfs project -d $dir | grep P || error "inherit attribute should be set"
+       [[ $($LFS project -d $dir) =~ " P " ]] ||
+               error "inherit attribute should be set"
 
        change_project -C $dir
 
        change_project -C $dir
-       lfs project -d $dir | grep P &&
+       [[ $($LFS project -d $dir) =~ " - " ]] ||
                error "inherit attribute should be cleared"
                error "inherit attribute should be cleared"
-
-       rm -rf $dir
-       cleanup_quota_test
 }
 run_test 53 "Project inherit attribute could be cleared"
 
 }
 run_test 53 "Project inherit attribute could be cleared"
 
@@ -3720,7 +3603,6 @@ test_54() {
        ! is_project_quota_supported &&
                skip "Project quota is not supported"
        setup_quota_test || error "setup quota failed with $?"
        ! 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
        local testfile="$DIR/$tdir/$tfile-0"
 
        #set project ID/inherit attribute
@@ -3765,8 +3647,6 @@ test_54() {
        #cleanup
        unlinkmany ${testfile} 100 ||
                error "unlink many files failed"
        #cleanup
        unlinkmany ${testfile} 100 ||
                error "unlink many files failed"
-
-       cleanup_quota_test
 }
 run_test 54 "basic lfs project interface test"
 
 }
 run_test 54 "basic lfs project interface test"
 
@@ -3808,8 +3688,6 @@ test_55() {
        error "chgrp should succeed"
 
        $LFS quota -v -g $TSTUSR2 $DIR
        error "chgrp should succeed"
 
        $LFS quota -v -g $TSTUSR2 $DIR
-
-       cleanup_quota_test
 }
 run_test 55 "Chgrp should be affected by group quota"
 
 }
 run_test 55 "Chgrp should be affected by group quota"
 
@@ -3827,8 +3705,6 @@ test_56() {
                $LFS quota -t -u $DIR
                error "expected grace time: 10s;10s, got:$grace_time"
        fi
                $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"
 
 }
 run_test 56 "lfs quota -t should work well"
 
@@ -3847,8 +3723,6 @@ test_57() {
        ln -s $dir/not_exist_file $dir/ccc
        local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
        [ $cnt -eq 7 ] || error "expected 7 got $cnt"
        ln -s $dir/not_exist_file $dir/ccc
        local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
        [ $cnt -eq 7 ] || error "expected 7 got $cnt"
-
-       cleanup_quota_test
 }
 run_test 57 "lfs project could tolerate errors"
 
 }
 run_test 57 "lfs project could tolerate errors"
 
@@ -3864,7 +3738,6 @@ test_59() {
        touch $testfile && lfs project -sp 1 $testfile
 
        enable_project_quota
        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"
 
 }
 run_test 59 "lfs project dosen't crash kernel with project disabled"
 
@@ -3872,7 +3745,6 @@ 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 $?"
        [ $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
 
        local testfile=$DIR/$tdir/$tfile
        local limit=100
@@ -3893,8 +3765,6 @@ test_60() {
        # root user can overrun quota
        runas -u 0 -g 0 touch $DIR/$tdir/foo ||
                error "root user should succeed"
        # 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"
 
 }
 run_test 60 "Test quota for root with setgid"
 
@@ -3937,7 +3807,6 @@ test_default_quota() {
        }
 
        setup_quota_test || error "setup quota failed with $?"
        }
 
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        quota_init
 
 
        quota_init
 
@@ -4078,7 +3947,6 @@ test_default_quota() {
                error "reset default quota failed"
        $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
                error "reset quota failed"
                error "reset default quota failed"
        $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
                error "reset quota failed"
-
        cleanup_quota_test
 }
 
        cleanup_quota_test
 }
 
@@ -4112,7 +3980,7 @@ test_62() {
        chattr -P $testdir || error "root failed to clear inherit"
        [[ $($LFS project -d $testdir) =~ "P" ]] &&
                error "inherit attribute should be cleared"
        chattr -P $testdir || error "root failed to clear inherit"
        [[ $($LFS project -d $testdir) =~ "P" ]] &&
                error "inherit attribute should be cleared"
-       cleanup_quota_test
+       return 0
 }
 run_test 62 "Project inherit should be only changed by root"
 
 }
 run_test 62 "Project inherit should be only changed by root"
 
@@ -4132,7 +4000,6 @@ test_dom() {
        [ $qtype == "p" ] && qid=$TSTPRJID
 
        setup_quota_test || error "setup quota failed with $?"
        [ $qtype == "p" ] && qid=$TSTPRJID
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        quota_init
 
 
        quota_init
 
@@ -4212,13 +4079,11 @@ test_dom() {
        $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
                quota_error $qtype $qid "write succeed, expect EDQUOT"
 
        $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
        rm -fr $DIR/$tdir_dom
 
        $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
                error "reset usr quota failed"
        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_63() {
@@ -4248,8 +4113,6 @@ test_64() {
 
        used=$(getquota -p $TSTPRJID global curinodes)
        [ $used -eq 0 ] || error "expected 0 got $used"
 
        used=$(getquota -p $TSTPRJID global curinodes)
        [ $used -eq 0 ] || error "expected 0 got $used"
-
-       cleanup_quota_test
 }
 run_test 64 "lfs project on non dir/files should succeed"
 
 }
 run_test 64 "lfs project on non dir/files should succeed"
 
@@ -4272,14 +4135,10 @@ test_65() {
        local quota_g=$($LFS quota -g $TSTUSR $DIR)
        local quota_all=$($RUNAS $LFS quota $DIR)
 
        local quota_g=$($LFS quota -g $TSTUSR $DIR)
        local quota_all=$($RUNAS $LFS quota $DIR)
 
-       [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
+       [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
                error "usr quota not match"
                error "usr quota not match"
-       [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
+       [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
                error "grp quota not match"
                error "grp quota not match"
-
-       rm -f $TESTFILE
-       # cleanup
-       cleanup_quota_test
 }
 run_test 65 "Check lfs quota result"
 
 }
 run_test 65 "Check lfs quota result"
 
@@ -4289,7 +4148,6 @@ test_66() {
        [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
                skip "Not supported before 2.12.4"
        setup_quota_test || error "setup quota failed with $?"
        [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
                skip "Not supported before 2.12.4"
        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
        local old=$(do_facet mds1 $LCTL get_param -n \
                    mdt.*.enable_chprojid_gid | head -1)
        local testdir=$DIR/$tdir/foo
@@ -4324,8 +4182,6 @@ test_66() {
 
        change_project -p $TSTPRJID $testdir/bar || error \
                "root should be able to change its own file's projid"
 
        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"
 
 }
 run_test 66 "nonroot user can not change project state in default"
 
@@ -4382,7 +4238,6 @@ test_67() {
                skip "ZFS grants some block space together with inode"
 
        setup_quota_test || error "setup quota failed with $?"
                skip "ZFS grants some block space together with inode"
 
        setup_quota_test || error "setup quota failed with $?"
-       trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -4482,11 +4337,8 @@ test_67() {
        wait_delete_completed || error "wait_delete_completed failed"
        sync_all_data || true
        used=$(getquota -u $TSTUSR global curspace)
        wait_delete_completed || error "wait_delete_completed failed"
        sync_all_data || true
        used=$(getquota -u $TSTUSR global curspace)
-       [ $used -ne 0 ] && quota_error u $TSTUSR \
+       [ $used -eq 0 ] || quota_error u $TSTUSR \
                "user quota isn't released after deletion"
                "user quota isn't released after deletion"
-       resetquota -u $TSTUSR
-
-       cleanup_quota_test
 }
 run_test 67 "quota pools recalculation"
 
 }
 run_test 67 "quota pools recalculation"
 
@@ -4505,7 +4357,6 @@ test_68()
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -4543,10 +4394,8 @@ test_68()
 
        # Check again that all is fine with global pool
        nr=$(get_slave_nr "0x0" "usr")
 
        # Check again that all is fine with global pool
        nr=$(get_slave_nr "0x0" "usr")
-       [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
+       [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
                error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
                error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
-
-       cleanup_quota_test
 }
 run_test 68 "slave number in quota pool changed after each add/remove OST"
 
 }
 run_test 68 "slave number in quota pool changed after each add/remove OST"
 
@@ -4560,7 +4409,6 @@ test_69()
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -4608,8 +4456,6 @@ test_69()
 
        $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
                oflag=sync || quota_error u $TSTUSR "write failed"
 
        $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
                oflag=sync || quota_error u $TSTUSR "write failed"
-
-       cleanup_quota_test
 }
 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
 
 }
 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
 
@@ -4624,7 +4470,6 @@ test_70()
                skip "Needs a client >= $VERSION_WITH_QP"
 
        setup_quota_test || error "setup quota failed with $?"
                skip "Needs a client >= $VERSION_WITH_QP"
 
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # MDS returns EFAULT for unsupported quotactl command
        [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
 
        # MDS returns EFAULT for unsupported quotactl command
        [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
@@ -4648,8 +4493,6 @@ test_70()
        $LFS quota -u $TSTUSR --pool $qpool $DIR
        rc=$?
        [ $rc -eq $err ] || error "quota res $rc != $err"
        $LFS quota -u $TSTUSR --pool $qpool $DIR
        rc=$?
        [ $rc -eq $err ] || error "quota res $rc != $err"
-
-       cleanup_quota_test
 }
 run_test 70 "check lfs setquota/quota with a pool option"
 
 }
 run_test 70 "check lfs setquota/quota with a pool option"
 
@@ -4666,7 +4509,6 @@ test_71a()
        [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
        [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -4732,8 +4574,6 @@ test_71a()
        # write to the 1st component - OST0 is empty
        $RUNAS $DD of=$testfile count=$limit seek=0 ||
                quota_error u $TSTUSR "write failed"
        # write to the 1st component - OST0 is empty
        $RUNAS $DD of=$testfile count=$limit seek=0 ||
                quota_error u $TSTUSR "write failed"
-
-       cleanup_quota_test
 }
 run_test 71a "Check PFL with quota pools"
 
 }
 run_test 71a "Check PFL with quota pools"
 
@@ -4751,7 +4591,6 @@ test_71b()
        [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
        [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -4799,8 +4638,7 @@ test_71b()
        # write over limit in qpool2
        $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
                quota_error u $TSTUSR "user write success, but expect EDQUOT"
        # write over limit in qpool2
        $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
                quota_error u $TSTUSR "user write success, but expect EDQUOT"
-
-       cleanup_quota_test
+       return 0
 }
 run_test 71b "Check SEL with quota pools"
 
 }
 run_test 71b "Check SEL with quota pools"
 
@@ -4813,7 +4651,6 @@ test_72()
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -4846,8 +4683,7 @@ test_72()
        # was added in a pool
        lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
                grep "OST\|MDT" && error "$qpool consists wrong targets"
        # was added in a pool
        lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
                grep "OST\|MDT" && error "$qpool consists wrong targets"
-
-       cleanup_quota_test
+       return 0
 }
 run_test 72 "lfs quota --pool prints only pool's OSTs"
 
 }
 run_test 72 "lfs quota --pool prints only pool's OSTs"
 
@@ -4874,7 +4710,6 @@ test_73b()
        mds_supports_qp
 
        setup_quota_test || error "setup quota failed with $?"
        mds_supports_qp
 
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
        quota_init
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        quota_init
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
@@ -4913,7 +4748,6 @@ test_74()
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
 
        mds_supports_qp
        setup_quota_test || error "setup quota failed with $?"
-       stack_trap cleanup_quota_test EXIT
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
 
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
@@ -4975,8 +4809,6 @@ function cleanup_quota_test_75()
        wait_nm_sync active
 
        resetquota -u $TSTUSR
        wait_nm_sync active
 
        resetquota -u $TSTUSR
-
-       cleanup_quota_test
 }
 
 test_dom_75() {
 }
 
 test_dom_75() {
@@ -5149,8 +4981,7 @@ test_76() {
        touch $testfile
        $LFS project -p 4294967295 $testfile &&
                error "set project ID should fail"
        touch $testfile
        $LFS project -p 4294967295 $testfile &&
                error "set project ID should fail"
-
-       cleanup_quota_test
+       return 0
 }
 run_test 76 "project ID 4294967295 should be not allowed"
 
 }
 run_test 76 "project ID 4294967295 should be not allowed"