+ sync; sleep 3; sync;
+}
+run_test_with_stat 14a "test setting quota on root ==="
+
+test_15(){
+ LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
+ PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
+
+ wait_delete_completed
+
+ # test for user
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
+ TOTAL_LIMIT="`$LFS quota -v -u $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
+ [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
+ echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
+ resetquota -u $TSTUSR
+
+ # test for group
+ $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
+ TOTAL_LIMIT="`$LFS quota -v -g $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
+ [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
+ echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
+ resetquota -g $TSTUSR
+ $LFS quotaoff -ug $DIR
+ do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
+ error "fail to set version for $SINGLEMDS"
+ for j in `seq $OSTCOUNT`; do
+ do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
+ error "fail to set version for ost$j"
+ done
+
+ echo "invalidating quota files"
+ $LFS quotainv -ug $DIR
+ $LFS quotainv -ugf $DIR
+ $LFS quotacheck -ug $DIR
+}
+run_test_with_stat 15 "set block quota more than 4T ==="
+
+# $1=u/g $2=with qunit adjust or not
+test_16_tub() {
+ LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
+ TESTFILE="$DIR/$tdir/$tfile"
+ mkdir -p $DIR/$tdir
+
+ wait_delete_completed
+
+ echo " User quota (limit: $LIMIT kbytes)"
+ if [ $1 == "u" ]; then
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
+ quota_show_check b u $TSTUSR
+ else
+ $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
+ quota_show_check b g $TSTUSR
+ fi
+
+ $LFS setstripe $TESTFILE -c 1
+ chown $TSTUSR.$TSTUSR $TESTFILE
+
+ echo " Write ..."
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
+ quota_error a $TSTUSR "(usr) write failure, but expect success"
+ echo " Done"
+ echo " Write out of block quota ..."
+ # this time maybe cache write, ignore it's failure
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
+ # flush cache, ensure noquota flag is setted on client
+ cancel_lru_locks osc
+ if [ $2 -eq 1 ]; then
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
+ quota_error a $TSTUSR "(write failure, but expect success"
+ else
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
+ quota_error a $TSTUSR "(write success, but expect EDQUOT"
+ fi
+
+ rm -f $TESTFILE
+ sync; sleep 3; sync;
+ resetquota -$1 $TSTUSR
+}
+
+# test without adjusting qunit
+# 2.0 version does not support WITHOUT_CHANGE_QS, so such test is obsolete
+test_16 () {
+ set_blk_tunesz $((BUNIT_SZ * 2))
+ set_blk_unitsz $((BUNIT_SZ * 4))
+ for i in u g; do
+ for j in 0 1; do
+ # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS 0xA01
+ echo " grp/usr: $i, adjust qunit: $j"
+ echo "-------------------------------"
+ [ $j -eq 1 ] && lustre_fail mds_ost 0
+ [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
+ test_16_tub $i $j
+ done
+ done
+ set_blk_unitsz $((128 * 1024))
+ set_blk_tunesz $((128 * 1024 / 2))
+}
+#run_test_with_stat 16 "test without adjusting qunit"
+
+# run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
+test_17() {
+ set_blk_tunesz 512
+ set_blk_unitsz 1024
+
+ wait_delete_completed
+
+ #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
+ lustre_fail ost 0x80000A02
+
+ TESTFILE="$DIR/$tdir/$tfile-a"
+ TESTFILE2="$DIR/$tdir/$tfile-b"
+ mkdir -p $DIR/$tdir
+
+ BLK_LIMIT=$((100 * 1024)) # 100M
+
+ log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
+ $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
+ log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
+ $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
+
+ quota_show_check b u $TSTUSR
+ quota_show_check b g $TSTUSR
+
+ touch $TESTFILE
+ chown $TSTUSR.$TSTUSR $TESTFILE
+ touch $TESTFILE2
+ chown $TSTUSR.$TSTUSR $TESTFILE2
+
+ log " Write the test file1 ..."
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
+ || quota_error a $TSTUSR "write 10M file failure"
+
+ $SHOW_QUOTA_USER
+ $SHOW_QUOTA_GROUP
+
+ log " write the test file2 ..."
+ $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
+ || quota_error a $TSTUSR "write 10M file failure"
+
+ $SHOW_QUOTA_USER
+ $SHOW_QUOTA_GROUP
+
+ rm -f $TESTFILE $TESTFILE2
+ RC=$?
+ sync; sleep 3; sync;
+
+ # make qd_count 64 bit
+ lustre_fail ost 0
+
+ set_blk_unitsz $((128 * 1024))
+ set_blk_tunesz $((128 * 1024 / 2))
+
+ resetquota -u $TSTUSR
+ resetquota -g $TSTUSR
+
+ return $RC
+}
+run_test_with_stat 17 "run for fixing bug14526 ==========="
+
+# test when mds takes a long time to handle a quota req so that
+# the ost has dropped it, the ost still could work well b=14840
+test_18() {
+ LIMIT=$((100 * 1024 * 1024)) # 100G
+ TESTFILE="$DIR/$tdir/$tfile"
+ mkdir -p $DIR/$tdir
+
+ wait_delete_completed
+
+ set_blk_tunesz 512
+ set_blk_unitsz 1024
+
+ log " User quota (limit: $LIMIT kbytes)"
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
+ quota_show_check b u $TSTUSR
+
+ $LFS setstripe $TESTFILE -i 0 -c 1
+ chown $TSTUSR.$TSTUSR $TESTFILE
+
+ #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
+ lustre_fail mds 0x13c
+
+ log " step1: write 100M block ..."
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
+ DDPID=$!
+
+ sleep 5
+ lustre_fail mds 0
+
+ echo " step2: testing ......"
+ count=0
+ if at_is_valid && at_is_enabled; then
+ timeout=$(at_max_get mds)
+ else
+ timeout=$(lctl get_param -n timeout)
+ fi
+ while [ true ]; do
+ if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
+ count=$[count+1]
+ if [ $count -gt $((4 * $timeout)) ]; then
+ quota_error u $TSTUSR "count=$count dd should be finished!"
+ fi
+ 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!"
+ $SHOW_QUOTA_USER
+ rm -f $TESTFILE
+ sync
+
+ resetquota -u $TSTUSR
+ set_blk_unitsz $((128 * 1024))
+ set_blk_tunesz $((128 * 1024 / 2))
+}
+run_test_with_stat 18 "run for fixing bug14840 ==========="
+
+# test when mds drops a quota req, the ost still could work well b=14840
+test_18a() {
+ LIMIT=$((100 * 1024 * 1024)) # 100G
+ TESTFILE="$DIR/$tdir/$tfile-a"
+ mkdir -p $DIR/$tdir
+
+ wait_delete_completed
+
+ set_blk_tunesz 512
+ set_blk_unitsz 1024
+
+ log " User quota (limit: $LIMIT kbytes)"
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
+ quota_show_check b u $TSTUSR
+
+ $LFS setstripe $TESTFILE -i 0 -c 1
+ chown $TSTUSR.$TSTUSR $TESTFILE
+
+ #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
+ lustre_fail mds 0x8000013d
+
+ log " step1: write 100M block ..."
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
+ DDPID=$!
+
+ echo " step2: testing ......"
+ count=0
+ if at_is_valid && at_is_enabled; then
+ timeout=$(at_max_get mds)
+ else
+ timeout=$(lctl get_param -n timeout)
+ fi
+ while [ true ]; do
+ if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
+ count=$[count+1]
+ if [ $count -gt $((6 * $timeout)) ]; then
+ lustre_fail mds 0
+ quota_error u $TSTUSR "count=$count dd should be finished!"
+ fi
+ sleep 1
+ done
+ log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
+
+ lustre_fail mds 0
+ rm -f $TESTFILE
+ sync
+
+ resetquota -u $TSTUSR
+ set_blk_unitsz $((128 * 1024))
+ set_blk_tunesz $((128 * 1024 / 2))
+}
+run_test_with_stat 18a "run for fixing bug14840 ==========="
+
+# test when mds do failover, the ost still could work well without trigger
+# watchdog b=14840
+test_18bc_sub() {
+ type=$1
+
+ LIMIT=$((110 * 1024 )) # 110M
+ TESTFILE="$DIR/$tdir/$tfile"
+ mkdir -p $DIR/$tdir
+
+ wait_delete_completed
+
+ set_blk_tunesz 512
+ set_blk_unitsz 1024
+
+ log " User quota (limit: $LIMIT kbytes)"
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
+ quota_show_check b u $TSTUSR
+
+ $LFS setstripe $TESTFILE -i 0 -c 1
+ chown $TSTUSR.$TSTUSR $TESTFILE
+
+ timeout=$(sysctl -n lustre.timeout)
+
+ if [ $type = "directio" ]; then
+ log " write 100M block(directio) ..."
+ $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
+ else
+ log " write 100M block(normal) ..."
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
+ fi
+
+ DDPID=$!
+ do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
+
+ log "failing mds for $((2 * timeout)) seconds"
+ fail $SINGLEMDS $((2 * timeout))
+
+ # check if quotaon successful
+ $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
+ if [ $? -eq 0 ]; then
+ error "quotaon failed!"
+ rm -rf $TESTFILE
+ return
+ fi
+
+ count=0
+ if at_is_valid && at_is_enabled; then
+ timeout=$(at_max_get mds)
+ else
+ timeout=$(lctl get_param -n timeout)
+ fi
+ while [ true ]; do
+ if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
+ if [ $((++count % (2 * timeout) )) -eq 0 ]; then
+ log "it took $count second"
+ fi
+ 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!"
+ $SHOW_QUOTA_USER
+ 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
+# this test shouldn't trigger watchdog b=14840
+test_18b() {
+ test_18bc_sub normal
+ test_18bc_sub directio
+ # check if watchdog is triggered
+ do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
+ watchdog=`awk '/test 18b/ {start = 1;}
+ /Watchdog triggered/ {
+ if (start) {
+ print;
+ }
+ }' $TMP/lustre-log-${TESTNAME}.log`
+ [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
+ rm -f $TMP/lustre-log-${TESTNAME}.log
+}
+run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
+
+# test when mds does failover, the ost still could work well
+# this test will prevent OST_DISCONNET from happening b=14840
+test_18c() {
+ # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
+ lustre_fail ost 0x202
+ test_18bc_sub normal
+ test_18bc_sub directio
+ lustre_fail ost 0
+}
+run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
+
+run_to_block_limit() {
+ local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
+ local TESTFILE=$1
+ wait_delete_completed
+
+ # set 1 Mb quota unit size
+ set_blk_tunesz 512
+ set_blk_unitsz 1024
+
+ # bind file to a single OST
+ $LFS setstripe -c 1 $TESTFILE
+ chown $TSTUSR.$TSTUSR $TESTFILE
+
+ echo " User quota (limit: $LIMIT kbytes)"
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
+ quota_show_check b u $TSTUSR
+ echo " Updating quota limits"
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
+ quota_show_check b u $TSTUSR
+
+ RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
+ $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
+ # for now page cache of TESTFILE may still be dirty,
+ # let's push it to the corresponding OST, this will also
+ # cache NOQUOTA on the client from OST's reply
+ cancel_lru_locks osc
+ $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
+}
+
+test_19() {
+ # 1 Mb bunit per each MDS/OSS
+ local TESTFILE="$DIR/$tdir/$tfile"
+ mkdir -p $DIR/$tdir
+
+ run_to_block_limit $TESTFILE
+ $SHOW_QUOTA_USER
+
+ # cleanup
+ rm -f $TESTFILE
+ resetquota -u $TSTUSR
+
+ set_blk_unitsz $((128 * 1024))
+ set_blk_tunesz $((128 * 1024 / 2))
+