Whamcloud - gitweb
b=19702
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index 0444562..f45fad5 100644 (file)
@@ -41,6 +41,8 @@ IUNIT_SZ=${IUNIT_SZ:-10}      # min inode quota unit
 MAX_DQ_TIME=604800
 MAX_IQ_TIME=604800
 
+unset ENABLE_QUOTA
+
 TRACE=${TRACE:-""}
 LUSTRE=${LUSTRE:-`dirname $0`/..}
 . $LUSTRE/tests/test-framework.sh
@@ -63,6 +65,12 @@ DIR2=${DIR2:-$MOUNT2}
 
 check_and_setup_lustre
 
+if [ x"$(som_check)" = x"enabled" ]; then
+        echo "Som is enabled, Quota is temporary conflicts with it"
+        check_and_cleanup_lustre
+        exit 0
+fi
+
 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
 
@@ -70,7 +78,7 @@ SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
-SHOW_QUOTA_INFO="$LFS quota -t $DIR"
+SHOW_QUOTA_INFO="$LFS quota -t -u $DIR; $LFS quota -t -g $DIR"
 
 # control the time of tests
 cycle=30
@@ -171,12 +179,35 @@ run_test_with_stat() {
 #        resetquota -g groupname
 
 resetquota() {
-       [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
-       [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
-       $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT || error "resetquota failed"
+        [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
+        [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
+
+        count=0
+        if at_is_enabled; then
+           timeout=$(at_max_get mds)
+        else
+           timeout=$(lctl get_param -n timeout)
+        fi
+
+        while [ $((count++)) -lt $timeout ]; do
+                $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
+                RC=$?
+                if [ $RC -ne 0 ]; then
+                        if [ $RC -eq 240 ]; then # 240 means -EBUSY
+                                log "resetquota is blocked for quota master recovery, retry after 1 sec"
+                                sleep 1
+                                continue
+                        else
+                                error "resetquota failed: $RC"
+                        fi
+                fi
+                break
+        done
+
+        [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
 }
 
-quota_error() {
+quota_scan() {
         LOCAL_UG=$1
         LOCAL_ID=$2
 
@@ -189,11 +220,20 @@ quota_error() {
                 log "Files for group ($LOCAL_ID):"
                 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
         fi
+}
 
+quota_error() {
+        quota_scan $1 $2
         shift 2
         error "$*"
 }
 
+quota_log() {
+        quota_scan $1 $2
+        shift 2
+        log "$*"
+}
+
 quota_show_check() {
         LOCAL_BF=$1
         LOCAL_UG=$2
@@ -204,12 +244,20 @@ quota_show_check() {
 
         if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
                USAGE="`$LFS quota -$LOCAL_UG $LOCAL_ID $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $2 }'`"
-                [ $USAGE -ne 0 ] && quota_error $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
+                if [ -z $USAGE ]; then
+                        quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
+                else
+                        [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
+                fi
         fi
 
         if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
                USAGE="`$LFS quota -$LOCAL_UG $LOCAL_ID $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $5 }'`"
-                [ $USAGE -ne 0 ] && quota_error $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
+                if [ -z $USAGE ]; then
+                        quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
+                else
+                        [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
+                fi
         fi
 }
 
@@ -248,7 +296,12 @@ test_1_sub() {
         chown $TSTUSR.$TSTUSR $TESTFILE
 
         log "    Write ..."
+        stime=`date +%s`
        $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
+        etime=`date +%s`
+        delta=$((etime - stime))
+        rate=$((BLK_SZ * LIMIT / 2 / delta / 1024))
+        [ $rate -gt 1024 ] || error_exit "SLOW IO for $TSTUSR (user): $rate KB/sec"
         log "    Done"
         log "    Write out of block quota ..."
        # this time maybe cache write,  ignore it's failure
@@ -279,7 +332,12 @@ test_1_sub() {
         chown $TSTUSR.$TSTUSR $TESTFILE
 
         log "    Write ..."
+        stime=`date +%s`
        $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
+        etime=`date +%s`
+        delta=$((etime - stime))
+        rate=$((BLK_SZ * LIMIT / 2 / delta / 1024))
+        [ $rate -gt 1024 ] || error_exit "SLOW IO for $TSTUSR (group): $rate KB/sec"
         log "    Done"
         log "    Write out of block quota ..."
        # this time maybe cache write, ignore it's failure
@@ -682,37 +740,76 @@ test_6() {
        chown $TSTUSR.$TSTUSR $FILEB
 
        echo "  Exceed quota limit ..."
-        RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
+        RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
         $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
-               quota_error a $TSTUSR "write fileb failure, but expect success"
+               quota_error a $TSTUSR "write filea failure, but expect success"
 
         cancel_lru_locks osc
         $SHOW_QUOTA_USER
         $SHOW_QUOTA_GROUP
         $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
-               quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
+               quota_error a $TSTUSR "write filea success, but expect EDQUOT"
         cancel_lru_locks osc
-       echo "  Write to OST0 return EDQUOT"
+       echo "  Write to OST1 return EDQUOT"
        # this write maybe cache write, ignore it's failure
-        RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
+        RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
         $RUNDD count=$(($BUNIT_SZ * 2)) || true
         cancel_lru_locks osc
         $SHOW_QUOTA_USER
         $SHOW_QUOTA_GROUP
         $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
-               quota_error a $TSTUSR "write filea success, but expect EDQUOT"
+               quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
 
-       echo "  Remove fileb to let OST1 release quota"
-       rm -f $FILEB
-        sync; sleep 10; sync; # need to allow journal commit for small fs
+       echo "  Remove filea to let OST0 release quota"
+       rm -f $FILEA
+
+        if at_is_enabled; then
+           timeout=$(at_max_get mds)
+        else
+           timeout=$(lctl get_param -n timeout)
+        fi
+        count=$((timeout / 5))
+        OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
+
+        while [ $((count--)) -gt 0 ]; do
+                sync && sleep 5
+
+               OST0_QUOTA_HOLD=`$LFS quota -o $OST0_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $3 }'`
+                if [ -z $OST0_QUOTA_HOLD ]; then
+                        error "System is error when query quota for block (U:$TSTUSR)."
+                else
+                        [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
+                fi
 
-       echo "  Write to OST0"
+                break
+        done
+
+        [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
+        $SHOW_QUOTA_USER
+
+        while [ $((count--)) -gt 0 ]; do
+                sync && sleep 5
+
+               OST0_QUOTA_HOLD=`$LFS quota -o $OST0_UUID -g $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $3 }'`
+                if [ -z $OST0_QUOTA_HOLD ]; then
+                        error "System is error when query quota for block (G:$TSTUSR)."
+                else
+                        [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
+                fi
+
+                break
+        done
+
+        [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
+        $SHOW_QUOTA_GROUP
+
+       echo "  Write to OST1"
        $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
-               quota_error a $TSTUSR "write filea failure, expect success"
+               quota_error a $TSTUSR "write fileb failure, expect success"
        echo "  Done"
 
        # cleanup
-       rm -f $FILEA
+       rm -f $FILEB
        sync; sleep 3; sync;
 
        resetquota -u $TSTUSR
@@ -791,6 +888,7 @@ test_8() {
        [ "$SLOW" = "no" ] && duration=" -t 120"
        $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
 
+        rm -rf $DIR/$tdir
        sync; sleep 3; sync;
 
        return 0
@@ -1184,13 +1282,6 @@ test_14a() {     # was test_14 b=12223 -- setting quota on root
 }
 run_test_with_stat 14a "test setting quota on root ==="
 
-# save quota version (both administrative and operational quotas)
-quota_save_version() {
-        do_facet mgs "lctl conf_param ${FSNAME}-MDT*.mdd.quota_type=$1"
-        do_facet mgs "lctl conf_param ${FSNAME}-OST*.ost.quota_type=$1"
-        sleep 5
-}
-
 test_15(){
         LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
         PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
@@ -1378,7 +1469,7 @@ test_18() {
 
        echo  "   step2: testing ......"
        count=0
-       if at_is_valid && at_is_enabled; then
+       if at_is_enabled; then
            timeout=$(at_max_get mds)
        else
            timeout=$(lctl get_param -n timeout)
@@ -1392,15 +1483,18 @@ test_18() {
            sleep 1
        done
         log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
+        sync
+        cancel_lru_locks mdc
+        cancel_lru_locks osc
 
         testfile_size=$(stat -c %s $TESTFILE)
         [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
            quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
-       rm -f $TESTFILE
-       sync; sleep 3; sync;
+        $SHOW_QUOTA_USER
+        rm -f $TESTFILE
+        sync
 
        resetquota -u $TSTUSR
-
        set_blk_unitsz $((128 * 1024))
        set_blk_tunesz $((128 * 1024 / 2))
 }
@@ -1433,7 +1527,7 @@ test_18a() {
 
        echo  "   step2: testing ......"
        count=0
-       if at_is_valid && at_is_enabled; then
+       if at_is_enabled; then
            timeout=$(at_max_get mds)
        else
            timeout=$(lctl get_param -n timeout)
@@ -1450,12 +1544,10 @@ test_18a() {
         log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
 
         lustre_fail mds 0
-
        rm -f $TESTFILE
-       sync; sleep 3; sync;
+       sync
 
        resetquota -u $TSTUSR
-
        set_blk_unitsz $((128 * 1024))
        set_blk_tunesz $((128 * 1024 / 2))
 }
@@ -1507,7 +1599,7 @@ test_18bc_sub() {
         fi
 
         count=0
-        if at_is_valid && at_is_enabled; then
+       if at_is_enabled; then
            timeout=$(at_max_get mds)
         else
            timeout=$(lctl get_param -n timeout)
@@ -1520,15 +1612,20 @@ test_18bc_sub() {
             sleep 1
         done
         log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
-        sync; sleep 1; sync
+        sync
+        cancel_lru_locks mdc
+        cancel_lru_locks osc
 
         testfile_size=$(stat -c %s $TESTFILE)
         [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
            quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
         $SHOW_QUOTA_USER
-        resetquota -u $TSTUSR
-        rm -rf $TESTFILE
-        sync; sleep 1; sync
+        rm -f $TESTFILE
+        sync
+
+       resetquota -u $TSTUSR
+       set_blk_unitsz $((128 * 1024))
+       set_blk_tunesz $((128 * 1024 / 2))
 }
 
 # test when mds does failover, the ost still could work well
@@ -1707,18 +1804,11 @@ test_21() {
 run_test_with_stat 21 "run for fixing bug16053 ==========="
 
 test_22() {
-        local SAVEREFORMAT
-
-        SAVEREFORMAT=$REFORMAT
-        $LFS quotaoff -ug $DIR || error "could not turn quotas off"
-
         quota_save_version "ug"
 
-        REFORMAT="reformat"
         stopall
         mount
         setupall
-        REFORMAT=$SAVEREFORMAT
 
         echo "checking parameters"
 
@@ -1750,13 +1840,16 @@ test_23_sub() {
 
        log "    Step1: trigger quota with 0_DIRECT"
        log "      Write half of file"
-       $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
+       $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
+                quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
        log "      Write out of block quota ..."
-       $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
+       $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
+                quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
        log "    Step1: done"
 
        log "    Step2: rewrite should succeed"
-       $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) 1 $bs_unit || quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
+       $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
+                quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
        log "    Step2: done"
 
        rm -f $TESTFILE
@@ -1907,6 +2000,58 @@ test_25() {
 }
 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
 
+test_26() {
+       mkdir -p $DIR/$tdir
+       chmod 0777 $DIR/$tdir
+       TESTFILE="$DIR/$tdir/$tfile-0"
+       TESTFILE2="$DIR/$tdir/$tfile-1"
+       set_blk_tunesz 512
+       set_blk_unitsz 1024
+
+       wait_delete_completed
+
+       # every quota slave gets 20MB
+       b_limit=$((OSTCOUNT * 20 * 1024))
+       log "limit: ${b_limit}KB"
+       $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
+       sleep 3
+       quota_show_check b u $TSTUSR
+
+       $LFS setstripe $TESTFILE  -c 1 -i 0
+       $LFS setstripe $TESTFILE2 -c 1 -i 0
+       chown $TSTUSR.$TSTUSR $TESTFILE
+       chown $TSTUSR.$TSTUSR $TESTFILE2
+
+       #define OBD_FAIL_QUOTA_DELAY_REL         0xA03
+       lustre_fail ost 0xA03
+
+       log "    Write the first file..."
+       $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
+       log "    Delete the first file..."
+       rm -f $TESTFILE
+
+
+       wait_delete_completed
+
+       log "    Write the second file..."
+       $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
+       log "    Delete the second file..."
+       rm -f $TESTFILE2
+
+       lustre_fail ost 0
+       set_blk_unitsz $((128 * 1024))
+       set_blk_tunesz $((128 * 1024 / 2))
+       resetquota -u $TSTUSR
+}
+run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
+
+test_27() {
+        $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
+        $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
+        return 0
+}
+run_test_with_stat 27 "lfs quota/setquota should handle wrong arguments (19612) ================="
+
 # turn off quota
 test_99()
 {