Whamcloud - gitweb
LU-6155 osd-zfs: dbuf_hold_impl() called without the lock
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index 10e3c11..f8d7413 100644 (file)
@@ -34,8 +34,6 @@ init_test_env $@
 init_logging
 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
 
-[ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
-
 require_dsh_mds || exit 0
 require_dsh_ost || exit 0
 
@@ -45,13 +43,23 @@ if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
        exec $LUSTRE/tests/sanity-quota-old.sh
 fi
 
-# if e2fsprogs support quota feature?
-if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] && \
-       ! $DEBUGFS -c -R supported_features | grep -q 'quota'; then
+# Does e2fsprogs support quota feature?
+if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
+       do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
+               grep -q 'quota'"; then
        skip "e2fsprogs doesn't support quota" && exit 0
 fi
 
-[ "$SLOW" = "no" ] && EXCEPT_SLOW="9 18 21"
+if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
+# bug number for skipped test:        LU-2836 LU-6836 LU-2836 LU-2059
+       ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3       4a      6       7d"
+# bug number for skipped test:        LU-5638
+       ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
+# bug number:     LU-2887
+       ZFS_SLOW="12a"
+fi
+
+[ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW 9 18 21"
 
 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
 
@@ -80,21 +88,18 @@ SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
 build_test_filter
 
 lustre_fail() {
-        local fail_node=$1
+       local fail_node=$1
        local fail_loc=$2
        local fail_val=${3:-0}
+       local NODES=
 
-       if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
-               do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
-               do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
-       fi
+       case $fail_node in
+       mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
+       mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
+       ost) NODES="$(comma_list $(osts_nodes))";;
+       esac
 
-       if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
-               for num in `seq $OSTCOUNT`; do
-                       do_facet ost$num "lctl set_param fail_val=$fail_val"
-                       do_facet ost$num "lctl set_param fail_loc=$fail_loc"
-               done
-       fi
+       do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
 }
 
 RUNAS="runas -u $TSTID -g $TSTID"
@@ -135,7 +140,7 @@ quota_scan() {
        fi
 
        if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
-               $LFS quota -v -u $LOCAL_ID $DIR
+               $LFS quota -v -g $LOCAL_ID $DIR
                log "Files for group ($LOCAL_ID):"
                ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
                        xargs stat 2>/dev/null)
@@ -192,30 +197,41 @@ getquota() {
 # usage: set_mdt_qtype ug|u|g|none
 set_mdt_qtype() {
        local qtype=$1
-       local varsvc=${SINGLEMDS}_svc
+       local varsvc
+       local mdts=$(get_facets MDS)
+       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
-       fi
+       # we have to make sure each MDT received config changes
+       for mdt in ${mdts//,/ }; do
+               varsvc=${mdt}_svc
+               cmd="$LCTL get_param -n "
+               cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
+               cmd=${cmd}.quota_slave.enabled
+
+               if $(facet_up $mdt); then
+                       wait_update_facet $mdt "$cmd" "$qtype" || return 1
+               fi
+       done
        return 0
 }
 
 # set ost quota type
-# usage: set_ost_quota_type ug|u|g|none
+# usage: set_ost_qtype ug|u|g|none
 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,54 +240,57 @@ 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
+       local tgts
 
        if [ $ntype == "mdt" ]; then
-               varsvc=${SINGLEMDS}_svc
-               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
-               fi
+               tgts=$(get_facets MDS)
        else
-               local osts=$(get_facets OST)
-               for ost in ${osts//,/ }; do
-                       varsvc=${ost}_svc
-                       if $(facet_up $ost); then
-                               wait_update_facet $ost "$LCTL get_param -n \
-                               osd-$FSTYPE.${!varsvc}.quota_slave.info |
-                               grep "$qtype" | awk '{ print \\\$3 }'" \
-                                       "$result" || return 1
-                       fi
-               done
+               tgts=$(get_facets OST)
        fi
+
+       for tgt in ${tgts//,/ }; do
+               varsvc=${tgt}_svc
+               cmd="$LCTL get_param -n "
+               cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
+               cmd=${cmd}.quota_slave.info
+
+               if $(facet_up $tgt); then
+                       wait_update_facet $tgt "$cmd |
+                               grep "$qtype" | awk '{ print \\\$3 }'" \
+                                       "$result" $max || return 1
+               fi
+       done
        return 0
 }
 
 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
 }
@@ -281,7 +300,7 @@ setup_quota_test() {
        wait_delete_completed
        echo "Creating test directory"
        mkdir -p $DIR/$tdir
-       chmod 077 $DIR/$tdir
+       chmod 0777 $DIR/$tdir
        # always clear fail_loc in case of fail_loc isn't cleared
        # properly when previous test failed
        lustre_fail mds_ost 0
@@ -333,6 +352,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
@@ -343,8 +367,14 @@ test_quota_performance() {
        delta=$((etime - stime))
        if [ $delta -gt 0 ]; then
            rate=$((size * 1024 / delta))
-           [ $rate -gt 1024 ] ||
-               error "SLOW IO for $TSTUSR (user): $rate KB/sec"
+           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
        fi
        rm -f $TESTFILE
 }
@@ -354,8 +384,7 @@ test_0() {
        local MB=100 # 100M
        [ "$SLOW" = "no" ] && MB=10
 
-       local free_space=$(lfs df | grep "filesystem summary" | \
-                               awk '{print $5}')
+       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
@@ -459,8 +488,8 @@ test_2() {
 
        [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
 
-       local FREE_INODES=$(lfs df -i | grep "filesystem summary" | \
-                               awk '{print $5}')
+       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
@@ -608,7 +637,7 @@ test_block_soft() {
 # block soft limit
 test_3() {
        local LIMIT=1  # 1MB
-       local GRACE=10 # 10s
+       local GRACE=20 # 20s
        local TESTFILE=$DIR/$tdir/$tfile-0
 
        set_ost_qtype "ug" || error "enable ost quota failed"
@@ -651,7 +680,8 @@ run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
 test_file_soft() {
        local TESTFILE=$1
        local LIMIT=$2
-       local TIMER=$(($3 * 3 / 2))
+       local grace=$3
+       local TIMER=$(($grace * 3 / 2))
 
        setup_quota_test
        trap cleanup_quota_test EXIT
@@ -659,13 +689,19 @@ test_file_soft() {
        echo "Create files to exceed soft limit"
        $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
                quota_error a $TSTUSR "create failure, but expect success"
-       sync; sleep 1; sync
+       local trigger_time=$(date +%s)
+
+       sync_all_data || true
+
+       local cur_time=$(date +%s)
+       [ $(($cur_time - $trigger_time)) -ge $grace ] &&
+               error "Passed grace time $grace, $trigger_time, $cur_time"
 
        echo "Create file before timer goes off"
        $RUNAS touch ${TESTFILE}_before ||
                quota_error a $TSTUSR "failed create before timer expired," \
-                       "but expect success"
-       sync; sleep 1; sync
+                       "but expect success. $trigger_time, $cur_time"
+       sync_all_data || true
 
        echo "Sleep $TIMER seconds ..."
        sleep $TIMER
@@ -680,11 +716,11 @@ test_file_soft() {
        # hasn't been decreased from the pending write, if we acquire quota
        # in this window, we'll acquire more than we needed.
        $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
-       sync; sleep 1; sync
+       sync_all_data || true
        $RUNAS touch ${TESTFILE}_after_3 &&
                quota_error a $TSTUSR "create after timer expired," \
                        "but expect EDQUOT"
-       sync; sleep 1; sync
+       sync_all_data || true
 
        $SHOW_QUOTA_USER
        $SHOW_QUOTA_GROUP
@@ -699,7 +735,7 @@ test_file_soft() {
        $RUNAS touch ${TESTFILE}_xxx ||
                quota_error a $TSTUSR "touch after timer stop failure," \
                        "but expect success"
-       sync; sleep 1; sync
+       sync_all_data || true
 
        # cleanup
        cleanup_quota_test
@@ -709,7 +745,7 @@ test_file_soft() {
 test_4a() {
        local LIMIT=10 # inodes
        local TESTFILE=$DIR/$tdir/$tfile-0
-       local GRACE=5
+       local GRACE=12
 
        set_mdt_qtype "ug" || error "enable mdt quota failed"
 
@@ -832,6 +868,10 @@ run_test 5 "Chown & chgrp successfully even out of block/file quota"
 test_6() {
        local LIMIT=3 # 3M
 
+       # Clear dmesg so watchdog is not triggered by previous
+       # test output
+       do_facet ost1 dmesg -c > /dev/null
+
        setup_quota_test
        trap cleanup_quota_test EXIT
 
@@ -890,25 +930,26 @@ test_6() {
 
        # no watchdog is triggered
        do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
-       watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
-                      /Service thread pid/ && /was inactive/ {
-                              if (start) {
-                                      print;
-                              }
-                      }' $TMP/lustre-log-${TESTNAME}.log)
+       watchdog=$(awk '/Service thread pid/ && /was inactive/ \
+                       { print; }' $TMP/lustre-log-${TESTNAME}.log)
        [ -z "$watchdog" ] || error "$watchdog"
 
        rm -f $TMP/lustre-log-${TESTNAME}.log
 
-       # write should continue & succeed
+       # write should continue then fail with EDQUOT
        local count=0
+       local c_size
        while [ true ]; do
                if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
-               if [ $count -ge 120 ]; then
+               if [ $count -ge 240 ]; then
                        quota_error u $TSTUSR "dd not finished in $count secs"
                fi
                count=$((count + 1))
-               [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
+               if [ $((count % 30)) -eq 0 ]; then
+                       c_size=$(stat -c %s $TESTFILE)
+                       echo "Waiting $count secs. $c_size"
+                       $SHOW_QUOTA_USER
+               fi
                sleep 1
        done
 
@@ -955,6 +996,7 @@ test_7a() {
 
        echo "Start ost1..."
        start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
+       quota_init
 
        wait_ost_reint "ug" || error "reintegration failed"
 
@@ -976,6 +1018,7 @@ test_7a() {
 
        echo "Start ost1..."
        start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
+       quota_init
 
        wait_ost_reint "ug" || error "reintegration failed"
 
@@ -1036,6 +1079,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"
 
@@ -1069,8 +1113,13 @@ test_7c() {
        # 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
+       do_facet ost1 $LCTL set_param $procf=1 ||
+               error "force reintegration failed"
 
        echo "Stop mds..."
        stop mds1
@@ -1079,8 +1128,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
@@ -1102,13 +1154,10 @@ test_7d(){
        trap cleanup_quota_test EXIT
 
        set_ost_qtype "none" || error "disable ost quota failed"
-       # LU-2284. Enable trace for debug log.
-       do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+trace"
        $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"
-       do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-trace"
 
        #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
        lustre_fail mds 0x608 0
@@ -1133,6 +1182,82 @@ test_7d(){
 }
 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
 
+# quota reintegration (inode limits)
+test_7e() {
+       [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
+
+       local ilimit=$((1024 * 2)) # 2k inodes
+       local TESTFILE=$DIR/${tdir}-1/$tfile
+
+       setup_quota_test
+       trap cleanup_quota_test EXIT
+
+       # make sure the system is clean
+       local USED=$(getquota -u $TSTUSR global curinodes)
+       [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
+
+       # make sure no granted quota on mdt1
+       set_mdt_qtype "ug" || error "enable mdt quota failed"
+       resetquota -u $TSTUSR
+       set_mdt_qtype "none" || error "disable mdt quota failed"
+
+       local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
+       USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
+       [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
+               "$TSTUSR isn't 0."
+
+       echo "Stop mds${MDSCOUNT}..."
+       stop mds${MDSCOUNT}
+
+       echo "Enable quota & set quota limit for $TSTUSR"
+       set_mdt_qtype "ug" || error "enable mdt quota failed"
+       $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit  $DIR ||
+               error "set quota failed"
+
+       echo "Start mds${MDSCOUNT}..."
+       start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
+       quota_init
+
+       wait_mdt_reint "ug" || error "reintegration failed"
+
+       echo "create remote dir"
+       $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
+               error "create remote dir failed"
+       chmod 0777 $DIR/${tdir}-1
+
+       # hardlimit should have been fetched by slave during global
+       # reintegration, create will exceed quota
+       $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
+               quota_error u $TSTUSR "create succeeded, expect EDQUOT"
+
+       $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
+       wait_delete_completed
+       sync_all_data || true
+
+       echo "Stop mds${MDSCOUNT}..."
+       stop mds${MDSCOUNT}
+
+       $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
+               error "clear quota failed"
+
+       echo "Start mds${MDSCOUNT}..."
+       start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
+       quota_init
+
+       wait_mdt_reint "ug" || error "reintegration failed"
+
+       # hardlimit should be cleared on slave during reintegration
+       $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
+               quota_error -u $TSTUSR "create failed, expect success"
+
+       $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
+       rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
+
+       cleanup_quota_test
+       resetquota -u $TSTUSR
+}
+run_test 7e "Quota reintegration (inode limits)"
+
 # run dbench with quota enabled
 test_8() {
        local BLK_LIMIT="100g" #100G
@@ -1178,7 +1303,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
 
@@ -1280,7 +1405,7 @@ test_11() {
 }
 run_test 11 "Chown/chgrp ignores quota"
 
-test_12() {
+test_12a() {
        [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
 
        local blimit=22 # 22M
@@ -1322,12 +1447,57 @@ test_12() {
        cleanup_quota_test
        resetquota -u $TSTUSR
 }
-run_test 12 "Block quota rebalancing"
+run_test 12a "Block quota rebalancing"
+
+test_12b() {
+       [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
+
+       local ilimit=$((1024 * 2)) # 2k inodes
+       local TESTFILE0=$DIR/$tdir/$tfile
+       local TESTFILE1=$DIR/${tdir}-1/$tfile
+
+       setup_quota_test
+       trap cleanup_quota_test EXIT
+
+       $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
+       chmod 0777 $DIR/${tdir}-1
+
+       set_mdt_qtype "u" || "enable mdt quota failed"
+       quota_show_check f u $TSTUSR
+
+       $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
+               error "set quota failed"
+
+       echo "Create $ilimit files on mdt0..."
+       $RUNAS createmany -m $TESTFILE0 $ilimit ||
+               quota_error u $TSTUSR "create failed, but expect success"
+
+       echo "Create files on mdt1..."
+       $RUNAS createmany -m $TESTFILE1 1 &&
+               quota_error a $TSTUSR "create succeeded, expect EDQUOT"
+
+       echo "Free space from mdt0..."
+       $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
+       wait_delete_completed
+       sync_all_data || true
+
+       echo "Create files on mdt1 after space freed from mdt0..."
+       $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
+               quota_error a $TSTUSR "rebalancing failed"
+
+       $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
+               error "unlink mdt1 files failed"
+       rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
+
+       cleanup_quota_test
+       resetquota -u $TSTUSR
+}
+run_test 12b "Inode quota rebalancing"
 
 test_13(){
        local TESTFILE=$DIR/$tdir/$tfile
-       # the name of osp on ost1 name is MDT0000-osp-OST0000
-       local procf="ldlm.namespaces.*MDT0000-osp-OST0000.lru_size"
+       # the name of lwp on ost1 name is MDT0000-lwp-OST0000
+       local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
 
        setup_quota_test
        trap cleanup_quota_test EXIT
@@ -1530,7 +1700,7 @@ test_18_sub () {
 
        local testfile_size=$(stat -c %s $TESTFILE)
        if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
-               quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
+               quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
                        "got ${testfile_size}. Verifying file failed!"
        fi
        cleanup_quota_test
@@ -1540,17 +1710,17 @@ test_18_sub () {
 # test when mds does failover, the ost still could work well
 # this test shouldn't trigger watchdog b=14840
 test_18() {
+       # Clear dmesg so watchdog is not triggered by previous
+       # test output
+       do_facet ost1 dmesg -c > /dev/null
+
        test_18_sub normal
        test_18_sub directio
 
        # check if watchdog is triggered
        do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
-       local watchdog=$(awk '/sanity-quota test 18/ {start = 1;}
-                      /Service thread pid/ && /was inactive/ {
-                              if (start) {
-                                      print;
-                              }
-                      }' $TMP/lustre-log-${TESTNAME}.log)
+       local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
+                       { print; }' $TMP/lustre-log-${TESTNAME}.log)
        [ -z "$watchdog" ] || error "$watchdog"
        rm -f $TMP/lustre-log-${TESTNAME}.log
 }
@@ -1722,6 +1892,7 @@ test_22() {
        stopall
        mount
        setupall
+       quota_init
 
        echo "Verify if quota is disabled"
        qtype=$(mdt_quota_type)
@@ -1729,7 +1900,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'"
 
@@ -1781,6 +1952,10 @@ test_23_sub() {
 }
 
 test_23() {
+       [ $(facet_fstype ost1) == "zfs" ] &&
+               skip "Overwrite in place is not guaranteed to be " \
+               "space neutral on ZFS" && return
+
        local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
        check_whether_skip && return 0
        log "run for 4MB test file"
@@ -1845,6 +2020,32 @@ test_27b() { # b20200
 }
 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
 
+test_27c() {
+       local limit
+
+       $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
+               error "lfs setquota failed"
+
+       limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
+       [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
+       limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
+       [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
+
+       $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
+               error "lfs setquota for $TSTID failed"
+
+       limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
+       [ $limit != "1.465G" ] && error "wrong softlimit $limit"
+       limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
+       [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
+
+       $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
+               error "total allocated inode/block limit not printed"
+
+       resetquota -u $TSTUSR
+}
+run_test 27c "lfs quota should support human-readable output"
+
 test_30() {
        local output
        local LIMIT=4 # 4MB
@@ -1870,11 +2071,11 @@ test_30() {
        # over-quota flag has not yet settled since we do not trigger async
        # events based on grace time period expiration
        $SHOW_QUOTA_USER
-       $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
+       $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
        cancel_lru_locks osc
        # now over-quota flag should be settled and further writes should fail
        $SHOW_QUOTA_USER
-       $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
+       $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
                error "grace times were reset"
        # cleanup
        cleanup_quota_test
@@ -1953,6 +2154,9 @@ test_34() {
        USED=$(getquota -g $TSTID global curspace)
        [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
 
+       local USED=$(getquota -u $TSTID2 global curspace)
+       [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
+
        echo "Write file..."
        $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
                error "write failed"
@@ -1989,6 +2193,24 @@ test_34() {
        [ $USED -eq 1 ] ||
                error "Used inodes for group $TSTID is $USED, expected 1"
 
+       # chown won't change the ost object group. LU-4345 */
+       echo "chown the file to user $TSTID2"
+       chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
+
+       echo "Wait for setattr on objects finished..."
+       wait_delete_completed
+
+       echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
+       USED=$(getquota -u $TSTID2 global curspace)
+       [ $USED -lt $BLK_CNT ] &&
+               error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
+       USED=$(getquota -u $TSTID global curspace)
+       [ $USED -ne 0 ] &&
+               error "Used space for user $TSTID is $USED, expected 0"
+       USED=$(getquota -g $TSTID global curspace)
+       [ $USED -lt $BLK_CNT ] &&
+               error "Used space for group $TSTID is $USED, expected $BLK_CNT"
+
        cleanup_quota_test
 }
 run_test 34 "Usage transfer for user & group"
@@ -2068,77 +2290,35 @@ test_35() {
 }
 run_test 35 "Usage is still accessible across reboot"
 
-# test migrating old amdin quota files (in Linux quota file format v2) into new
-# quota global index (in IAM format)
-test_36() {
-       [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
-               skip "skipping migration test" && return
-
-       # get the mdt0 device name
-       local mdt0_node=$(facet_active_host $SINGLEMDS)
-       local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
-
-       echo "Reformat..."
-       formatall
-
-       echo "Copy admin quota files into MDT0..."
-       local mntpt=$(facet_mntpt $SINGLEMDS)
-       local mdt0_fstype=$(facet_fstype $SINGLEMDS)
-       local opt
-       if ! do_node $mdt0_node test -b $mdt0_fstype; then
-               opt="-o loop"
-       fi
-       echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
-       do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
-       do_node $mdt0_node mkdir $mntpt/OBJECTS
-       do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
-       do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
-       do_node $mdt0_node umount -f $mntpt
-
-       echo "Setup all..."
-       setupall
+# chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
+# LU-5006
+test_37() {
+       setup_quota_test
+       trap cleanup_quota_test EXIT
 
-       echo "Verify global limits..."
-       local id_cnt
-       local limit
+       # make sure the system is clean
+       local USED=$(getquota -u $TSTID global curspace)
+       [ $USED -ne 0 ] &&
+               error "Used space ($USED) for user $TSTID isn't 0."
 
-       local proc="qmt.*.md-0x0.glb-usr"
-       id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
-       [ $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)
-       [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
-
-       proc="qmt.*.md-0x0.glb-grp"
-       id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
-       [ $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)
-       [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
-
-       proc=" qmt.*.dt-0x0.glb-usr"
-       id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
-       [ $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)
-       [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
-
-       proc="qmt.*.dt-0x0.glb-grp"
-       id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
-       [ $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)
-       [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
-
-       echo "Cleanup..."
-       formatall
-       setupall
+       # create file with MDS_OPEN_DELAY_CREATE flag
+       $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 \
+               oflag=sync || error "Write file failed"
+       # chown to the file
+       chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
+
+       # wait for setattr on objects finished..."
+       wait_delete_completed
+
+       USED=$(getquota -u $TSTID global curspace)
+       [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
+
+       cleanup_quota_test
 }
-run_test 36 "Migrate old admin files into new global indexes"
+run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
 
 quota_fini()
 {