Whamcloud - gitweb
LU-2526 quota: writer proper size in test_9
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index 09806a5..113ba49 100644 (file)
@@ -99,12 +99,15 @@ lustre_fail() {
 
 RUNAS="runas -u $TSTID -g $TSTID"
 RUNAS2="runas -u $TSTID2 -g $TSTID2"
-FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
-FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
 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
@@ -114,13 +117,10 @@ resetquota() {
        [ "$1" != "-u" -a "$1" != "-g" ] &&
                error "resetquota: wrong specifier $1 passed"
 
-       $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
-       # The usage should be 0 now, enforce quota to trigger quota
-       # release for each slave, sleep 3 seconds to wait for the release
-       # done, then we can make sure granted quota for each slave is 0.
-       $LFS setquota "$1" "$2" -b 0 -B 1 -i 0 -I 1 $MOUNT
-       sleep 3
-       $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
+       $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
+               error "clear quota for [type:$1 name:$2] failed"
+       # give a chance to slave to release space
+       sleep 1
 }
 
 quota_scan() {
@@ -193,11 +193,14 @@ getquota() {
 set_mdt_qtype() {
        local qtype=$1
        local varsvc=${SINGLEMDS}_svc
+       local cmd
        do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
        if $(facet_up $SINGLEMDS); then
-               wait_update_facet $SINGLEMDS "$LCTL get_param -n \
-                       osd-$FSTYPE.${!varsvc}.quota_slave.enabled" "$qtype" ||
-                               return 1
+               cmd="$LCTL get_param -n "
+               cmd=${cmd}osd-$(facet_fstype $SINGLEMDS).${!varsvc}
+               cmd=${cmd}.quota_slave.enabled
+
+               wait_update_facet $SINGLEMDS "$cmd" "$qtype" || return 1
        fi
        return 0
 }
@@ -208,14 +211,17 @@ set_ost_qtype() {
        local qtype=$1
        local varsvc
        local osts=$(get_facets OST)
+       local cmd
        do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
        # we have to make sure each OST received config changes
        for ost in ${osts//,/ }; do
                varsvc=${ost}_svc
+               cmd="$LCTL get_param -n "
+               cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
+               cmd=${cmd}.quota_slave.enabled
+
                if $(facet_up $ost); then
-                       wait_update_facet $ost "$LCTL get_param -n \
-                               osd-$FSTYPE.${!varsvc}.quota_slave.enabled" \
-                                       "$qtype" || return 1
+                       wait_update_facet $ost "$cmd" "$qtype" || return 1
                fi
        done
        return 0
@@ -224,26 +230,34 @@ set_ost_qtype() {
 wait_reintegration() {
        local ntype=$1
        local qtype=$2
+       local max=$3
        local result="glb[1],slv[1],reint[0]"
        local varsvc
+       local cmd
 
        if [ $ntype == "mdt" ]; then
                varsvc=${SINGLEMDS}_svc
+               cmd="$LCTL get_param -n "
+               cmd=${cmd}osd-$(facet_fstype $SINGLEMDS).${!varsvc}
+               cmd=${cmd}.quota_slave.info
+
                if $(facet_up $SINGLEMDS); then
-                       wait_update_facet $SINGLEMDS "$LCTL get_param -n \
-                       osd-$FSTYPE.${!varsvc}.quota_slave.info |
-                       grep "$qtype" | awk '{ print \\\$3 }'" "$result" ||
-                               return 1
+                       wait_update_facet $SINGLEMDS "$cmd |
+                       grep "$qtype" | awk '{ print \\\$3 }'" \
+                               "$result" $max || return 1
                fi
        else
                local osts=$(get_facets OST)
                for ost in ${osts//,/ }; do
                        varsvc=${ost}_svc
+                       cmd="$LCTL get_param -n "
+                       cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
+                       cmd=${cmd}.quota_slave.info
+
                        if $(facet_up $ost); then
-                               wait_update_facet $ost "$LCTL get_param -n \
-                               osd-$FSTYPE.${!varsvc}.quota_slave.info |
+                               wait_update_facet $ost "$cmd |
                                grep "$qtype" | awk '{ print \\\$3 }'" \
-                                       "$result" || return 1
+                                       "$result" $max || return 1
                        fi
                done
        fi
@@ -252,26 +266,28 @@ wait_reintegration() {
 
 wait_mdt_reint() {
        local qtype=$1
+       local max=${2:-90}
 
        if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
-               wait_reintegration "mdt" "user" || return 1
+               wait_reintegration "mdt" "user" $max || return 1
        fi
 
        if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
-               wait_reintegration "mdt" "group" || return 1
+               wait_reintegration "mdt" "group" $max || return 1
        fi
        return 0
 }
 
 wait_ost_reint() {
        local qtype=$1
+       local max=${2:-90}
 
        if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
-               wait_reintegration "ost" "user" || return 1
+               wait_reintegration "ost" "user" $max || return 1
        fi
 
        if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
-               wait_reintegration "ost" "group" || return 1
+               wait_reintegration "ost" "group" $max || return 1
        fi
        return 0
 }
@@ -333,6 +349,11 @@ quota_init() {
 }
 quota_init
 
+resetquota -u $TSTUSR
+resetquota -g $TSTUSR
+resetquota -u $TSTUSR2
+resetquota -g $TSTUSR2
+
 test_quota_performance() {
        local TESTFILE="$DIR/$tdir/$tfile-0"
        local size=$1 # in MB
@@ -351,17 +372,22 @@ test_quota_performance() {
 
 # test basic quota performance b=21696
 test_0() {
-       setup_quota_test
-       trap cleanup_quota_test EXIT
-
        local MB=100 # 100M
        [ "$SLOW" = "no" ] && MB=10
 
+       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
+       setup_quota_test
+       trap cleanup_quota_test EXIT
+
        set_ost_qtype "none" || error "disable ost quota failed"
        test_quota_performance $MB
 
        set_ost_qtype "ug" || error "enable ost quota failed"
-       $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
+               error "set quota failed"
        test_quota_performance $MB
 
        cleanup_quota_test
@@ -382,7 +408,8 @@ test_1() {
 
        # test for user
        log "User quota (block hardlimit:$LIMIT MB)"
-       $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
+               error "set user quota failed"
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curspace)
@@ -413,7 +440,8 @@ test_1() {
        # test for group
        log "--------------------------------------"
        log "Group quota (block hardlimit:$LIMIT MB)"
-       $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
+       $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
+               error "set group quota failed"
 
        TESTFILE="$DIR/$tdir/$tfile-1"
        # make sure the system is clean
@@ -451,6 +479,11 @@ test_2() {
 
        [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
 
+       local FREE_INODES=$(lfs_df -i | grep "summary" | awk '{print $4}')
+       [ $FREE_INODES -lt $LIMIT ] &&
+               skip "not enough free inodes $FREE_INODES required $LIMIT" &&
+               return
+
        setup_quota_test
        trap cleanup_quota_test EXIT
 
@@ -459,7 +492,8 @@ test_2() {
 
        # test for user
        log "User quota (inode hardlimit:$LIMIT files)"
-       $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
+               error "set user quota failed"
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curinodes)
@@ -485,7 +519,8 @@ test_2() {
        # test for group
        log "--------------------------------------"
        log "Group quota (inode hardlimit:$LIMIT files)"
-       $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
+       $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
+               error "set group quota failed"
 
         TESTFILE=$DIR/$tdir/$tfile-1
        # make sure the system is clean
@@ -602,8 +637,10 @@ test_3() {
        local USED=$(getquota -u $TSTUSR global curspace)
        [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
 
-       $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
-       $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
+       $LFS setquota -t -u --block-grace $GRACE --inode-grace \
+               $MAX_IQ_TIME $DIR || error "set user grace time failed"
+       $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
+               error "set user quota failed"
 
        test_block_soft $TESTFILE $GRACE $LIMIT
        resetquota -u $TSTUSR
@@ -614,17 +651,19 @@ test_3() {
        USED=$(getquota -g $TSTUSR global curspace)
        [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
 
-       $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
-       $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
+       $LFS setquota -t -g --block-grace $GRACE --inode-grace \
+               $MAX_IQ_TIME $DIR || error "set group grace time failed"
+       $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
+               error "set group quota failed"
 
        test_block_soft $TESTFILE $GRACE $LIMIT
        resetquota -g $TSTUSR
 
        # cleanup
        $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
-               $MAX_IQ_TIME $DIR
+               $MAX_IQ_TIME $DIR || error "restore user grace time failed"
        $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
-               $MAX_IQ_TIME $DIR
+               $MAX_IQ_TIME $DIR || error "restore group grace time failed"
 }
 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
 
@@ -698,8 +737,10 @@ test_4a() {
        local USED=$(getquota -u $TSTUSR global curinodes)
        [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
 
-       $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
-       $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
+       $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
+               $GRACE $DIR || error "set user grace time failed"
+       $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
@@ -709,8 +750,10 @@ test_4a() {
        USED=$(getquota -g $TSTUSR global curinodes)
        [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
 
-       $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
-       $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
+       $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
+               $GRACE $DIR || error "set group grace time failed"
+       $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
+               error "set group quota failed"
        TESTFILE=$DIR/$tdir/$tfile-1
 
        test_file_soft $TESTFILE $LIMIT $GRACE
@@ -718,9 +761,9 @@ test_4a() {
 
        # cleanup
        $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
-               $MAX_IQ_TIME $DIR
+               $MAX_IQ_TIME $DIR || error "restore user grace time failed"
        $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
-               $MAX_IQ_TIME $DIR
+               $MAX_IQ_TIME $DIR || error "restore group grace time failed"
 }
 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
 
@@ -736,9 +779,11 @@ test_4b() {
 
        # test of valid grace strings handling
        echo "Valid grace strings test"
-       $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
+       $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
+               $GR_STR2 $DIR || error "set user grace time failed"
        $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
-       $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
+       $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
+               $GR_STR4 $DIR || error "set group grace time quota failed"
        $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
 
        # test of invalid grace strings handling
@@ -748,9 +793,9 @@ test_4b() {
 
        # cleanup
        $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
-               $MAX_IQ_TIME $DIR
+               $MAX_IQ_TIME $DIR || error "restore user grace time failed"
        $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
-               $MAX_IQ_TIME $DIR
+               $MAX_IQ_TIME $DIR || error "restore group grace time failed"
 }
 run_test 4b "Grace time strings handling"
 
@@ -766,8 +811,10 @@ test_5() {
        set_ost_qtype "ug" || error "enable ost quota failed"
 
        echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
-       $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR
-       $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
+               error "set user quota failed"
+       $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
+               error "set group quota failed"
 
        # make sure the system is clean
        local USED=$(getquota -u $TSTUSR global curinodes)
@@ -802,6 +849,8 @@ run_test 5 "Chown & chgrp successfully even out of block/file quota"
 
 # test dropping acquire request on master
 test_6() {
+       local LIMIT=3 # 3M
+
        setup_quota_test
        trap cleanup_quota_test EXIT
 
@@ -824,7 +873,8 @@ test_6() {
        chown $TSTUSR2.$TSTUSR2 $TESTFILE2
 
        # cache per-ID lock for $TSTUSR on slave
-       $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
+               error "set quota failed"
        $RUNAS $DD of=$TESTFILE count=1 ||
                error "write $TESTFILE failure, expect success"
        $RUNAS2 $DD of=$TESTFILE2 count=1 ||
@@ -837,16 +887,17 @@ test_6() {
        lustre_fail mds 0x513 601
 
        # write to un-enforced ID ($TSTUSR2) should succeed
-       $RUNAS2 $DD of=$TESTFILE2 count=1 seek=1 oflag=sync conv=notrunc ||
+       $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
                error "write failure, expect success"
 
        # write to enforced ID ($TSTUSR) in background, exceeding limit
        # to make sure DQACQ is sent
-       $RUNAS $DD of=$TESTFILE count=2 seek=1 oflag=sync conv=notrunc &
+       $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
        DDPID=$!
 
-       echo "Sleep for $TIMEOUT"
-       sleep $TIMEOUT
+       # watchdog timer uses a factor of 2
+       echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
+       sleep $((TIMEOUT * 2 + 1))
 
        # write should be blocked and never finished
        if ! ps -p $DDPID  > /dev/null 2>&1; then
@@ -918,10 +969,12 @@ test_7a() {
 
        echo "Enable quota & set quota limit for $TSTUSR"
        set_ost_qtype "ug" || error "enable ost quota failed"
-       $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
+               error "set quota failed"
 
        echo "Start ost1..."
        start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
+       quota_init
 
        wait_ost_reint "ug" || error "reintegration failed"
 
@@ -930,6 +983,27 @@ test_7a() {
        $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
                quota_error u $TSTUSR "write success, but expect EDQUOT"
 
+       rm -f $TESTFILE
+       wait_delete_completed
+       sync_all_data || true
+       sleep 3
+
+       echo "Stop ost1..."
+       stop ost1
+
+       $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
+               error "clear quota failed"
+
+       echo "Start ost1..."
+       start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
+       quota_init
+
+       wait_ost_reint "ug" || error "reintegration failed"
+
+       # 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
        resetquota -u $TSTUSR
 }
@@ -970,7 +1044,8 @@ test_7b() {
        lustre_fail mds 0xa02
 
        set_ost_qtype "ug" || error "enable ost quota failed"
-       $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
+               error "set quota failed"
 
        # ignore the write error
        $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
@@ -982,6 +1057,7 @@ test_7b() {
        echo "Restart ost to trigger reintegration..."
        stop ost1
        start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
+       quota_init
 
        wait_ost_reint "ug" || error "reintegration failed"
 
@@ -1009,13 +1085,18 @@ test_7c() {
        [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
 
        set_ost_qtype "none" || error "disable ost quota failed"
-       $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
+               error "set quota failed"
 
        # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
        lustre_fail ost 0xa03
 
-       # enable ost quota to trigger reintegration
+       # enable ost quota
        set_ost_qtype "ug" || error "enable ost quota failed"
+       # trigger reintegration
+       local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
+       procf=${procf}quota_slave.force_reint
+       $LCTL set_param $procf=1 || "force reintegration failed"
 
        echo "Stop mds..."
        stop mds1
@@ -1024,8 +1105,11 @@ test_7c() {
 
        echo "Start mds..."
        start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
+       quota_init
 
-       wait_ost_reint "ug" || error "reintegration failed"
+       # wait longer than usual to make sure the reintegration
+       # is triggered by quota wb thread.
+       wait_ost_reint "ug" 200 || error "reintegration failed"
 
        # hardlimit should have been fetched by slave during global
        # reintegration, write will exceed quota
@@ -1037,6 +1121,44 @@ test_7c() {
 }
 run_test 7c "Quota reintegration (restart mds during reintegration)"
 
+# Quota reintegration (Transfer index in multiple bulks)
+test_7d(){
+       local TESTFILE=$DIR/$tdir/$tfile
+       local TESTFILE1="$DIR/$tdir/$tfile"-1
+       local limit=20 #20M
+
+       setup_quota_test
+       trap cleanup_quota_test EXIT
+
+       set_ost_qtype "none" || error "disable ost quota failed"
+       $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
+               error "set quota for $TSTUSR failed"
+       $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
+               error "set quota for $TSTUSR2 failed"
+
+       #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
+       lustre_fail mds 0x608 0
+
+       # enable quota to tirgger reintegration
+       set_ost_qtype "u" || error "enable ost quota failed"
+       wait_ost_reint "u" || error "reintegration failed"
+
+       lustre_fail mds 0
+
+       # hardlimit should have been fetched by slave during global
+       # reintegration, write will exceed quota
+       $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
+               quota_error u $TSTUSR "$TSTUSR 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
+       resetquota -u $TSTUSR
+       resetquota -u $TSTUSR2
+}
+run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
+
 # run dbench with quota enabled
 test_8() {
        local BLK_LIMIT="100g" #100G
@@ -1049,9 +1171,11 @@ test_8() {
        set_ost_qtype "ug" || error "enable ost quota failed"
 
        echo "Set enough high limit for user: $TSTUSR"
-       $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
+               error "set user quota failed"
        echo "Set enough high limit for group: $TSTUSR"
-       $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
+       $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
+               error "set group quota failed"
 
        local duration=""
        [ "$SLOW" = "no" ] && duration=" -t 120"
@@ -1080,7 +1204,7 @@ check_whether_skip () {
 
 # run for fixing bug10707, it needs a big room. test for 64bit
 test_9() {
-       local filesize=$((1024 * 1024 * 1024 * 9 / 2)) # 4.5G
+       local filesize=$((1024 * 9 / 2)) # 4.5G
 
        check_whether_skip && return 0
 
@@ -1097,11 +1221,13 @@ test_9() {
 
        log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
                "for user: $TSTUSR"
-       $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
+               error "set user quota failed"
 
        log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
                "for group: $TSTUSR"
-       $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
+       $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
+               error "set group quota failed"
 
        quota_show_check a u $TSTUSR
        quota_show_check a g $TSTUSR
@@ -1141,7 +1267,8 @@ test_10() {
        # root user can overrun quota
        set_ost_qtype "ug" || "enable ost quota failed"
 
-       $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
+               error "set quota failed"
        quota_show_check b u $TSTUSR
 
        $LFS setstripe $TESTFILE -c 1
@@ -1161,7 +1288,8 @@ test_11() {
        trap cleanup_quota_test EXIT
 
        set_mdt_qtype "ug" || "enable mdt quota failed"
-       $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
+               error "set quota failed"
 
        touch "$TESTFILE"-0
        touch "$TESTFILE"-1
@@ -1192,7 +1320,8 @@ test_12() {
        set_ost_qtype "u" || "enable ost quota failed"
        quota_show_check b u $TSTUSR
 
-       $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
+               error "set quota failed"
 
        $LFS setstripe $TESTFILE0 -c 1 -i 0
        $LFS setstripe $TESTFILE1 -c 1 -i 1
@@ -1232,7 +1361,8 @@ test_13(){
        set_ost_qtype "u" || "enable ost quota failed"
        quota_show_check b u $TSTUSR
 
-       $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
+               error "set quota failed"
        $LFS setstripe $TESTFILE -c 1 -i 0
        chown $TSTUSR.$TSTUSR $TESTFILE
 
@@ -1276,14 +1406,16 @@ test_15(){
        sync_all_data || true
 
         # test for user
-       $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
+               error "set user quota failed"
        local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
        [ $TOTAL_LIMIT -eq $LIMIT ] ||
                error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
        resetquota -u $TSTUSR
 
        # test for group
-       $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
+       $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
+               error "set group quota failed"
        TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
        [ $TOTAL_LIMIT -eq $LIMIT ] ||
                error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
@@ -1306,7 +1438,8 @@ test_17sub() {
        set_ost_qtype "ug" || error "enable ost quota failed"
        # make sure no granted quota on ost
        resetquota -u $TSTUSR
-       $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
+               error "set quota failed"
 
        quota_show_check b u $TSTUSR
 
@@ -1378,7 +1511,8 @@ test_18_sub () {
 
        set_ost_qtype "u" || error "enable ost quota failed"
        log "User quota (limit: $blimit)"
-       $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT
+       $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
+               error "set quota failed"
        quota_show_check b u $TSTUSR
 
        $LFS setstripe $TESTFILE -i 0 -c 1
@@ -1437,7 +1571,7 @@ test_18() {
 
        # check if watchdog is triggered
        do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
-       local watchdog=$(awk '/test 18b/ {start = 1;}
+       local watchdog=$(awk '/sanity-quota test 18/ {start = 1;}
                       /Service thread pid/ && /was inactive/ {
                               if (start) {
                                       print;
@@ -1462,10 +1596,12 @@ test_19() {
        chown $TSTUSR.$TSTUSR $TESTFILE
 
        echo "Set user quota (limit: "$blimit"M)"
-       $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
+       $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
+               error "set user quota failed"
        quota_show_check b u $TSTUSR
        echo "Update quota limits"
-       $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
+       $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
+               error "set group quota failed"
        quota_show_check b u $TSTUSR
 
        # first wirte might be cached
@@ -1532,9 +1668,11 @@ test_21() {
        set_ost_qtype "ug" || error "Enable ost quota failed"
 
        log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
-       $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT
+       $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
+               error "set user quota failed"
        log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
-       $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT
+       $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
+               error "set group quota failed"
 
        # repeat writing on a 1M file
        test_21_sub ${TESTFILE}_1 1 30 &
@@ -1610,6 +1748,7 @@ test_22() {
        stopall
        mount
        setupall
+       quota_init
 
        echo "Verify if quota is disabled"
        qtype=$(mdt_quota_type)
@@ -1617,7 +1756,7 @@ test_22() {
        qtype=$(ost_quota_type)
        [ $qtype != "none" ] && error "ost quota setting is lost"
 
-       quota_init
+       return 0
 }
 run_test 22 "enable/disable quota by 'lctl conf_param'"
 
@@ -1632,7 +1771,8 @@ test_23_sub() {
 
        # test for user
        log "User quota (limit: $LIMIT MB)"
-       $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR
+       $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
+               error "set quota failed"
        quota_show_check b u $TSTUSR
 
        $LFS setstripe $TESTFILE -c 1 -i 0
@@ -1694,7 +1834,8 @@ test_24() {
        chown $TSTUSR.$TSTUSR $TESTFILE
 
        echo "Set user quota (limit: "$blimit"M)"
-       $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
+       $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
+               error "set quota failed"
 
        # overrun quota by root user
        runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
@@ -1745,12 +1886,14 @@ test_30() {
        $LFS setstripe $TESTFILE -i 0 -c 1
        chown $TSTUSR.$TSTUSR $TESTFILE
 
-       $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
-       $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
+       $LFS setquota -t -u --block-grace $GRACE --inode-grace \
+               $MAX_IQ_TIME $DIR || error "set grace time failed"
+       $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
+               error "set quota failed"
        $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
        cancel_lru_locks osc
        sleep $GRACE
-       $LFS setquota -u $TSTUSR -B 0 $DIR
+       $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
        # over-quota flag has not yet settled since we do not trigger async
        # events based on grace time period expiration
        $SHOW_QUOTA_USER
@@ -1764,7 +1907,7 @@ test_30() {
        cleanup_quota_test
        resetquota -u $TSTUSR
        $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
-               $MAX_IQ_TIME $DIR
+               $MAX_IQ_TIME $DIR || error "restore grace time failed"
 }
 run_test 30 "Hard limit updates should not reset grace times"
 
@@ -1988,7 +2131,7 @@ test_36() {
 
        local proc="qmt.*.md-0x0.glb-usr"
        id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
-       [ $id_cnt -eq 401 ] || error "Migrate inode user limit failed: $id_cnt"
+       [ $id_cnt -eq 403 ] || error "Migrate inode user limit failed: $id_cnt"
        limit=$(getquota -u 1 global isoftlimit)
        [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
        limit=$(getquota -u 1 global ihardlimit)
@@ -1996,7 +2139,7 @@ test_36() {
 
        proc="qmt.*.md-0x0.glb-grp"
        id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
-       [ $id_cnt -eq 401 ] || error "Migrate inode group limit failed: $id_cnt"
+       [ $id_cnt -eq 403 ] || error "Migrate inode group limit failed: $id_cnt"
        limit=$(getquota -g 1 global isoftlimit)
        [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
        limit=$(getquota -g 1 global ihardlimit)
@@ -2004,7 +2147,7 @@ test_36() {
 
        proc=" qmt.*.dt-0x0.glb-usr"
        id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
-       [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
+       [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
        limit=$(getquota -u 60001 global bsoftlimit)
        [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
        limit=$(getquota -u 60001 global bhardlimit)
@@ -2012,7 +2155,7 @@ test_36() {
 
        proc="qmt.*.dt-0x0.glb-grp"
        id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
-       [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
+       [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
        limit=$(getquota -g 60001 global bsoftlimit)
        [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
        limit=$(getquota -g 60001 global bhardlimit)
@@ -2031,7 +2174,7 @@ quota_fini()
 quota_fini
 
 cd $ORIG_PWD
-complete $(basename $0) $SECONDS
+complete $SECONDS
 check_and_cleanup_lustre
 export QUOTA_AUTO=$QUOTA_AUTO_OLD
 exit_status