Whamcloud - gitweb
LU-15097 quota: stop pool_recalc before killing pool
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index b630044..f0e310b 100755 (executable)
@@ -1108,6 +1108,76 @@ test_1h() {
 }
 run_test 1h "Block hard limit test using fallocate"
 
+test_1i() {
+       local global_limit=200  # 200M
+       local limit1=10  # 10M
+       local TESTDIR="$DIR/$tdir/"
+       local testfile="$TESTDIR/$tfile-0"
+       local testfile1="$TESTDIR/$tfile-1"
+       local testfile2="$TESTDIR/$tfile-2"
+       local qpool1="qpool1"
+
+       mds_supports_qp
+       setup_quota_test || error "setup quota failed with $?"
+       stack_trap cleanup_quota_test EXIT
+
+       # enable ost quota
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+       log "User quota (block hardlimit:$global_limit MB)"
+       $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
+               error "set user quota failed"
+
+       pool_add $qpool1 || error "pool_add failed"
+       pool_add_targets $qpool1 0 0 ||
+               error "pool_add_targets failed"
+
+       $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
+               error "set user quota failed"
+
+       # make sure the system is clean
+       local used=$(getquota -u $TSTUSR global curspace)
+       [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
+
+       $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
+
+       # hit pool limit
+       test_1_check_write $testfile "user" $limit1
+       $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
+               error "set user quota failed"
+
+       $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
+       $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
+               quota_error u $TSTUSR "write failure, but expect success"
+
+       rm -f $testfile
+       rm -f $testfile1
+       wait_delete_completed || error "wait_delete_completed failed"
+       sync_all_data || true
+
+       $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
+               error "set user quota failed"
+       test_1_check_write $testfile "user" $limit1
+       local tmp_limit=$(($limit1*2))
+       # increase pool limit
+       $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
+               error "set user quota failed"
+       # now write shouldn't fail
+       $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
+               quota_error u $TSTUSR "write failure, but expect success"
+       # decrease pool limit
+       $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
+               error "set user quota failed"
+       $RUNAS $DD of=$testfile2 count=$((limit1/3))
+       # flush cache, ensure noquota flag is set on client
+       cancel_lru_locks osc
+       sync; sync_all_data || true
+       $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
+               quota_error u $TSTUSR "write success, but expect failure"
+       return 0
+}
+run_test 1i "Quota pools: different limit and usage relations"
+
 # test inode hardlimit
 test_2() {
        local TESTFILE="$DIR/$tdir/$tfile-0"
@@ -4152,8 +4222,8 @@ test_66() {
        local testdir=$DIR/$tdir/foo
 
        do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
-       stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
-               EXIT
+       stack_trap "do_facet mds1 $LCTL \
+               set_param mdt.*.enable_chprojid_gid=$old" EXIT
 
        mkdir_on_mdt0 $testdir || error "failed to mkdir"
        chown -R $TSTID:$TSTID $testdir
@@ -4993,6 +5063,163 @@ test_77()
 }
 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
 
+test_78()
+{
+       (( $OST1_VERSION >= $(version_code 2.14.55) )) ||
+               skip "need OST at least 2.14.55"
+       check_set_fallocate_or_skip
+
+       setup_quota_test || error "setup quota failed with $?"
+
+       # enable ost quota
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+       mkdir -p $DIR/$tdir || error "failed to create $tdir"
+       chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
+
+       # setup quota limit
+       $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
+               error "lfs setquota failed"
+
+       # call fallocate
+       runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
+
+       kbytes=$(lfs quota -u $TSTUSR $DIR |
+               awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
+       echo "kbytes returned:$kbytes"
+
+       # For file size of 204800. We should be having roughly 200 kbytes
+       # returned. Anything alarmingly low (50 taken as arbitrary value)
+       # would bail out this TC. Also this also avoids $kbytes of 0
+       # to be used in calculation below.
+       (( $kbytes > 50 )) ||
+               error "fallocate did not use quota. kbytes returned:$kbytes"
+
+       local expect_lo=$(($kbytes * 95 / 100)) # 5% below
+       local expect_hi=$(($kbytes * 105 / 100)) # 5% above
+
+       # Verify kbytes is 200 (204800/1024). With a permited  5% drift
+       (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
+               error "fallocate did not use quota correctly"
+}
+run_test 78 "Check fallocate increase quota usage"
+
+test_79()
+{
+       local qpool="qpool1"
+       local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
+       local stopf=$TMP/$tfile
+
+       do_facet mds1 "touch $stopf"
+       stack_trap "do_facet mds1 'rm -f $stopf'"
+       do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
+       local pid=$!
+       pool_add $qpool || error "pool_add failed"
+       do_facet mds1 "rm $stopf"
+       wait $pid
+}
+run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
+
+test_80()
+{
+       local dir1="$DIR/$tdir/dir1"
+       local dir2="$DIR/$tdir/dir2"
+       local TESTFILE0="$dir1/$tfile-0"
+       local TESTFILE1="$dir1/$tfile-1"
+       local TESTFILE2="$dir1/$tfile-2"
+       local TESTFILE3="$dir2/$tfile-0"
+       local global_limit=100 # 100M
+       local limit=10 # 10M
+       local qpool="qpool1"
+
+       [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
+       mds_supports_qp
+       [ "$ost1_FSTYPE" == zfs ] &&
+               skip "ZFS grants some block space together with inode"
+       setup_quota_test || error "setup quota failed with $?"
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+       # make sure the system is clean
+       local used=$(getquota -u $TSTUSR global curspace)
+       [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
+
+       pool_add $qpool || error "pool_add failed"
+       pool_add_targets $qpool 0 1 ||
+               error "pool_add_targets failed"
+
+       $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
+               error "set user quota failed"
+
+       $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
+               error "set user quota failed"
+       $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
+               error "set user quota failed"
+
+       mkdir -p $dir1 || error "failed to mkdir"
+       chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
+       mkdir -p $dir2 || error "failed to mkdir"
+       chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
+
+       $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
+       $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
+       lfs getstripe $dir1
+       lfs getstripe $dir2
+       sleep 3
+
+       $LFS quota -uv $TSTUSR $DIR
+       #define OBD_FAIL_QUOTA_PREACQ            0xA06
+       do_facet mds1 $LCTL set_param fail_loc=0xa06
+       $RUNAS $DD of=$TESTFILE3 count=3 ||
+               quota_error u $TSTUSR "write failed"
+       $RUNAS $DD of=$TESTFILE2 count=7 ||
+               quota_error u $TSTUSR "write failed"
+       $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
+               quota_error u $TSTUSR "write failed"
+       sync
+       sleep 3
+       $LFS quota -uv --pool $qpool $TSTUSR $DIR
+
+       rm -f $TESTFILE2
+       stop ost2
+       do_facet mds1 $LCTL set_param fail_loc=0
+       start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
+       $LFS quota -uv $TSTUSR --pool $qpool $DIR
+       # OST0 needs some time to update quota usage after removing TESTFILE2
+       sleep 4
+       $LFS quota -uv $TSTUSR --pool $qpool $DIR
+       $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
+               quota_error u $TSTUSR "write failure, but expect success"
+}
+run_test 80 "check for EDQUOT after OST failover"
+
+test_81() {
+       local global_limit=20  # 100M
+       local testfile="$DIR/$tdir/$tfile-0"
+       local qpool="qpool1"
+
+       mds_supports_qp
+       setup_quota_test || error "setup quota failed with $?"
+
+       # enable ost quota
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+       # test for user
+       log "User quota (block hardlimit:$global_limit MB)"
+       $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
+
+       pool_add $qpool || error "pool_add failed"
+       #define OBD_FAIL_QUOTA_RECALC   0xA07
+       do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
+       # added OST casues to start pool recalculation
+       pool_add_targets $qpool 0 0 1
+       stop mds1 -f || error "MDS umount failed"
+
+       #start mds1 back to destroy created pool
+       start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
+       clients_up || true
+}
+run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
+
 quota_fini()
 {
        do_nodes $(comma_list $(nodes_list)) \