+ 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))
+
+}
+run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
+
+test_20()
+{
+ LSTR=(1t 2g 3m 4k) # limits strings
+ LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
+
+ $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
+ $MOUNT || error "could not set quota limits"
+
+ $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
+ --inode-softlimit ${LSTR[2]} \
+ --inode-hardlimit ${LSTR[3]} \
+ $MOUNT || error "could not set quota limits"
+
+ [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
+ [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
+ [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
+ [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
+
+ resetquota -u $TSTUSR
+}
+run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
+
+test_21_sub() {
+ local testfile=$1
+ local blk_number=$2
+ local seconds=$3
+
+ time=$(($(date +%s) + seconds))
+ while [ $(date +%s) -lt $time ]; do
+ $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
+ rm -f $testfile
+ done
+}
+
+# run for fixing bug16053, setquota shouldn't fail when writing and
+# deleting are happening
+test_21() {
+ set_blk_tunesz 512
+ set_blk_unitsz 1024
+
+ wait_delete_completed
+
+ TESTFILE="$DIR/$tdir/$tfile"
+
+ BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
+ FILE_LIMIT=1000000
+
+ 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 $MOUNT
+ 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 $MOUNT
+
+ # repeat writing on a 1M file
+ test_21_sub ${TESTFILE}_1 1024 30 &
+ DDPID1=$!
+ # repeat writing on a 128M file
+ test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
+ DDPID2=$!
+
+ time=$(($(date +%s) + 30))
+ i=1
+ while [ $(date +%s) -lt $time ]; do
+ log " Set quota for $i times"
+ $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
+ $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
+ i=$((i+1))
+ sleep 1
+ done
+
+ count=0
+ while [ true ]; do
+ if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
+ count=$[count+1]
+ if [ $count -gt 60 ]; then
+ quota_error a $TSTUSR "dd should be finished!"
+ fi
+ sleep 1
+ done
+ echo "(dd_pid=$DDPID1, time=$count)successful"
+
+ count=0
+ while [ true ]; do
+ if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
+ count=$[count+1]
+ if [ $count -gt 60 ]; then
+ quota_error a $TSTUSR "dd should be finished!"
+ fi
+ sleep 1
+ done
+ echo "(dd_pid=$DDPID2, time=$count)successful"
+
+ set_blk_unitsz $((128 * 1024))
+ set_blk_tunesz $((128 * 1024 / 2))
+ resetquota -u $TSTUSR
+ resetquota -g $TSTUSR
+
+ return $RC
+}
+run_test_with_stat 21 "run for fixing bug16053 ==========="
+
+test_22() {
+ quota_save_version "ug3"
+
+ stopall
+ mount
+ setupall
+
+ echo "checking parameters"
+
+ do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
+ do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
+
+ quota_init
+}
+run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
+
+test_23_sub() {
+ mkdir -p $DIR/$tdir
+ chmod 0777 $DIR/$tdir
+ TESTFILE="$DIR/$tdir/$tfile-0"
+ rm -f $TESTFILE
+ local bs_unit=$((1024*1024))
+ LIMIT=$1
+
+ wait_delete_completed
+
+ # test for user
+ log " User quota (limit: $LIMIT kbytes)"
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
+ sleep 3
+ quota_show_check b u $TSTUSR
+
+ $LFS setstripe $TESTFILE -c 1
+ chown $TSTUSR.$TSTUSR $TESTFILE
+
+ 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"
+ 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"
+ log " Step1: done"
+
+ log " Step2: rewrite should succeed"
+ $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
+ wait_delete_completed
+ OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
+ OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
+ echo $OST0_QUOTA_USED
+ [ $OST0_QUOTA_USED -ne 0 ] && \
+ ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
+ $SHOW_QUOTA_USER
+ resetquota -u $TSTUSR
+}
+
+test_23() {
+ log "run for $((OSTCOUNT * 4))MB test file"
+ test_23_sub $((OSTCOUNT * 4 * 1024))
+
+ OST0_MIN=120000
+ check_whether_skip && return 0
+ log "run for $((OSTCOUNT * 40))MB test file"
+ test_23_sub $((OSTCOUNT * 40 * 1024))
+}
+run_test_with_stat 23 "run for fixing bug16125 ==========="
+
+test_24() {
+ local TESTFILE="$DIR/$tdir/$tfile"
+ mkdir -p $DIR/$tdir
+
+ run_to_block_limit $TESTFILE
+ $SHOW_QUOTA_USER | grep '*' || error "no matching *"
+
+ # cleanup
+ rm -f $TESTFILE
+ resetquota -u $TSTUSR
+
+ set_blk_unitsz $((128 * 1024))
+ set_blk_tunesz $((128 * 1024 / 2))
+
+}
+run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
+
+show_quota() {
+ if [ $1 = "-u" ]; then
+ if [ $2 = "$TSTUSR" ]; then
+ $SHOW_QUOTA_USER
+ else
+ $SHOW_QUOTA_USER2
+ fi
+ else
+ if [ $2 = "$TSTUSR" ]; then
+ $SHOW_QUOTA_GROUP
+ else
+ $SHOW_QUOTA_GROUP2
+ fi
+ fi
+}
+
+test_25_sub() {
+ mkdir -p $DIR/$tdir
+ chmod 0777 $DIR/$tdir
+ TESTFILE="$DIR/$tdir/$tfile-0"
+ rm -f $TESTFILE
+ LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
+
+ wait_delete_completed
+
+ # set quota for $TSTUSR
+ log "setquota for $TSTUSR"
+ $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
+ sleep 3
+ if [ "$1" == "-u" ]; then
+ quota_show_check a u $TSTUSR
+ else
+ quota_show_check a g $TSTUSR
+ fi
+
+ # set quota for $TSTUSR2
+ log "setquota for $TSTUSR2"
+ $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
+ sleep 3
+ if [ "$1" == "-u" ]; then
+ quota_show_check a u $TSTUSR2
+ else
+ quota_show_check a g $TSTUSR2
+ fi
+
+ # set stripe index to 0
+ log "setstripe for $DIR/$tdir to 0"
+ $LFS setstripe $DIR/$tdir -c 1 -i 0
+ MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
+ OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
+ MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
+ OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
+ MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
+ OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
+
+ # TSTUSR write 4M
+ log "$TSTUSR write 4M to $TESTFILE"
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
+ sync
+ show_quota $1 $TSTUSR
+ show_quota $1 $TSTUSR2
+ MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
+ [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
+ quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
+ OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
+ OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
+ [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
+ quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
+
+ # chown/chgrp from $TSTUSR to $TSTUSR2
+ if [ $1 = "-u" ]; then
+ log "chown from $TSTUSR to $TSTUSR2"
+ chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
+ else
+ log "chgrp from $TSTUSR to $TSTUSR2"
+ chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
+ fi
+ sync
+ show_quota $1 $TSTUSR
+ show_quota $1 $TSTUSR2
+ MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
+ [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
+ quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
+ OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
+ # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
+ OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
+ OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
+ [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
+ quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
+ MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
+ [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
+ quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
+ OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
+ [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
+ quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
+
+ rm -f $TESTFILE
+ wait_delete_completed
+ resetquota $1 $TSTUSR
+ resetquota $1 $TSTUSR2
+}
+
+test_25() {
+ log "run for chown case"
+ test_25_sub -u
+
+ log "run for chgrp case"
+ test_25_sub -g
+}
+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 + 1) * 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_27a() {
+ $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 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
+
+test_27b() {
+ $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
+ error "lfs setquota failed with uid argument"
+ $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
+ error "lfs stequota failed with gid argument"
+ $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
+ $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
+ resetquota -u $TSTUSR
+ resetquota -g $TSTUSR
+ return 0
+}
+run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
+
+test_28() {
+ BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
+ echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
+ $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
+ $SHOW_QUOTA_USER
+
+ echo "Step 2: reset system ..."
+ cleanup_and_setup_lustre
+ quota_init
+
+ echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
+ 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"
+ mkdir -p $DIR/$tdir
+
+ BLK_LIMIT=$((100 * 1024)) # 100M
+ echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
+ $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
+ $SHOW_QUOTA_USER
+
+ touch $TESTFILE
+ chown $TSTUSR.$TSTUSR $TESTFILE
+
+ echo "Step 5: write the test file1 [10M] ..."
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
+ || quota_error a $TSTUSR "write 10M file failure"
+ $SHOW_QUOTA_USER
+
+ rm -f $TESTFILE
+ 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
+}
+run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
+
+test_29()
+{
+ local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
+ local timeout
+ local pid
+
+ if at_is_enabled; then
+ timeout=$(at_max_get client)
+ at_max_set 10 client
+ else
+ timeout=$(lctl get_param -n timeout)
+ lctl set_param timeout=10
+ fi
+
+ #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
+ lustre_fail mds 0x12e
+
+ $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
+
+ echo "sleeping for $((10 * 2)) seconds"
+ sleep $((10 * 2))
+ ps -p $pid && error "lfs hadn't finished by timeout"
+ wait $pid && error "succeeded, but should have failed"
+
+ lustre_fail mds 0
+
+ if at_is_enabled; then
+ at_max_set $timeout client
+ else
+ lctl set_param timeout=$timeout
+ fi
+
+ resetquota -u $TSTUSR
+}
+run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
+
+test_30()
+{
+ local output
+ local LIMIT=1024
+ local TESTFILE="$DIR/$tdir/$tfile"
+ local GRACE=10
+
+ set_blk_tunesz 512
+ set_blk_unitsz 1024
+
+ mkdir -p $DIR/$tdir
+ chmod 0777 $DIR/$tdir
+
+ $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 -B 0 -i 0 -I 0 $DIR
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
+ cancel_lru_locks osc
+ sleep $GRACE
+ $LFS setquota -u $TSTUSR -B 0 $DIR
+ # 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 if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
+ cancel_lru_locks osc
+ # now over-quota flag should be settled and further writes should fail
+ $SHOW_QUOTA_USER
+ $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
+ rm -f $TESTFILE
+ resetquota -u $TSTUSR
+ $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
+
+ set_blk_unitsz $((128 * 1024))
+ set_blk_tunesz $((128 * 1024 / 2))
+}
+run_test_with_stat 30 "hard limit updates should not reset grace times ================"
+
+# test duplicate quota releases b=18630
+test_31() {
+ mkdir -p $DIR/$tdir
+ chmod 0777 $DIR/$tdir
+
+ LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
+ TESTFILE="$DIR/$tdir/$tfile-0"
+ TESTFILE2="$DIR/$tdir/$tfile-1"
+
+ wait_delete_completed
+
+ log " User quota (limit: $LIMIT kbytes)"
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
+
+ $LFS setstripe $TESTFILE -i 0 -c 1
+ chown $TSTUSR.$TSTUSR $TESTFILE
+ $LFS setstripe $TESTFILE2 -i 0 -c 1
+ chown $TSTUSR.$TSTUSR $TESTFILE2
+
+ log " step1: write out of block quota ..."
+ $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
+ $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
+
+ #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
+ #define OBD_FAIL_SOME 0x10000000 /* fail N times */
+ lustre_fail ost $((0x00000A04 | 0x10000000)) 1
+
+ log " step2: delete two files so that triggering duplicate quota release ..."
+ rm -f $TESTFILE $TESTFILE2
+ sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
+ wait_delete_completed
+
+ log " step3: verify if the ost failed"
+ do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
+ watchdog=`awk '/test 31/ {start = 1;}
+ /release quota error/ {
+ if (start) {
+ print;
+ }
+ }' $TMP/lustre-log-${TESTNAME}.log`
+ [ "$watchdog" ] && error "$watchdog"
+ rm -f $TMP/lustre-log-${TESTNAME}.log
+
+ lustre_fail ost 0
+ resetquota -u $TSTUSR
+}
+run_test_with_stat 31 "test duplicate quota releases ==="
+
+# check hash_cur_bits
+check_quota_hash_cur_bits() {
+ local bits=$1
+
+ # check quota_hash_cur_bits on all obdfilters
+ for num in `seq $OSTCOUNT`; do
+ cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
+ if [ $cb -gt $bits ]; then
+ echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
+ return 1;
+ fi
+ done
+ # check quota_hash_cur_bits on mds
+ cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
+ if [ $cb -gt $bits ]; then
+ echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
+ return 1;
+ fi
+ return 0;
+}
+
+# check lqs hash
+check_lqs_hash() {
+ # check distribution of all obdfilters
+ for num in `seq $OSTCOUNT`; do
+ do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
+ rehash_count=`echo $line | awk '{print $9}'`
+ if [ $rehash_count -eq 0 ]; then
+ echo -e "ost$num:\n $line"
+ error "Rehearsh didn't happen"
+ fi
+ done
+ done
+ # check distribution of mds
+ do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
+ rehash_count=`echo $line | awk '{print $9}'`
+ if [ $rehash_count -eq 0 ]; then
+ echo -e "mdt:\n $line"
+ error "Rehearsh didn't happen"
+ fi
+ done
+}
+
+test_32()
+{
+ # reset system so that quota_hash_cur_bits==3
+ echo "Reset system ..."
+ local LMR_orig=$LOAD_MODULES_REMOTE
+ LOAD_MODULES_REMOTE=true
+ cleanup_and_setup_lustre
+ LOAD_MODULES_REMOTE=$LMR_orig
+
+ for user in $SANITY_QUOTA_USERS; do
+ check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
+ missing_users="$missing_users $user"
+ done
+ [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
+ check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
+
+ $LFS quotaoff -ug $DIR
+ $LFS quotacheck -ug $DIR
+
+ for user in $SANITY_QUOTA_USERS; do
+ $LFS setquota -u $user --block-hardlimit 1048576 $DIR
+ done
+
+ check_lqs_hash
+
+ for user in $SANITY_QUOTA_USERS; do
+ resetquota -u $user
+ done
+}
+run_test 32 "check lqs hash(bug 21846) =========================================="
+
+# turn off quota
+quota_fini()
+{
+ $LFS quotaoff $DIR
+ do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
+}
+quota_fini
+
+log "cleanup: ======================================================"
+cd $ORIG_PWD
+check_and_cleanup_lustre