Whamcloud - gitweb
LU-4306 test: bump grace time in test_4a of s-q
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index 1029b52..2b16a2b 100644 (file)
@@ -43,17 +43,21 @@ 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
 
-[ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
-# bug number for skipped test:        LU-2836 LU-2837 LU-2059
+if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
+# bug number for skipped test:        LU-2836 LU-2836 LU-2059
        ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3       6       7d"
+# bug number:     LU-2887
+       ZFS_SLOW="12a"
+fi
 
-[ "$SLOW" = "no" ] && EXCEPT_SLOW="9 18 21"
+[ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW 9 18 21"
 
 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
 
@@ -82,21 +86,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"
@@ -137,7 +138,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)
@@ -364,8 +365,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
 }
@@ -479,7 +486,8 @@ test_2() {
 
        [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
 
-       local FREE_INODES=$(lfs_df -i | grep "summary" | awk '{print $4}')
+       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
@@ -627,7 +635,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"
@@ -728,7 +736,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"
 
@@ -851,6 +859,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
 
@@ -909,25 +921,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
 
@@ -1096,7 +1109,8 @@ test_7c() {
        # trigger reintegration
        local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
        procf=${procf}quota_slave.force_reint
-       $LCTL set_param $procf=1 || "force reintegration failed"
+       do_facet ost1 $LCTL set_param $procf=1 ||
+               error "force reintegration failed"
 
        echo "Stop mds..."
        stop mds1
@@ -1228,7 +1242,7 @@ test_7e() {
                quota_error -u $TSTUSR "create failed, expect success"
 
        $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
-       $LFS rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
+       rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
 
        cleanup_quota_test
        resetquota -u $TSTUSR
@@ -1464,7 +1478,7 @@ test_12b() {
 
        $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
                error "unlink mdt1 files failed"
-       $LFS rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
+       rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
 
        cleanup_quota_test
        resetquota -u $TSTUSR
@@ -1677,7 +1691,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
@@ -1687,17 +1701,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
 }
@@ -1993,6 +2007,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
@@ -2018,11 +2058,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
@@ -2101,6 +2141,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"
@@ -2137,6 +2180,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"
@@ -2241,7 +2302,7 @@ test_36() {
        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
+       do_node $mdt0_node umount -d -f $mntpt
 
        echo "Setup all..."
        setupall
@@ -2288,6 +2349,36 @@ test_36() {
 }
 run_test 36 "Migrate old admin files into new global indexes"
 
+# chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
+# LU-5006
+test_37() {
+       setup_quota_test
+       trap cleanup_quota_test EXIT
+
+       # 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."
+
+       # 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 37 "Quota accounted properly for file created by 'lfs setstripe'"
+
 quota_fini()
 {
         do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"