btrfs: Use _require_btrfs_qgroup_report to replace open code
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Fri, 9 Dec 2016 01:19:59 +0000 (09:19 +0800)
committerEryu Guan <eguan@redhat.com>
Fri, 9 Dec 2016 07:55:19 +0000 (15:55 +0800)
Introduce new _require_btrfs_qgroup_report function, which will
check the accessibility to "btrfs check --qgroup-report", then set a
global flag to info _check_scratch_fs() to do extra qgroup check.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
check
common/btrfs
common/rc
tests/btrfs/022
tests/btrfs/028
tests/btrfs/042
tests/btrfs/099
tests/btrfs/104
tests/btrfs/122
tests/btrfs/123
tests/btrfs/126

diff --git a/check b/check
index 8f2a1bbb3fb5b3f8309a00334a7496e668d87190..76eb0548b7efd0bf7e1d5d35aaf92e3b1b7e1e08 100755 (executable)
--- a/check
+++ b/check
@@ -405,11 +405,11 @@ _check_filesystems()
 {
        if [ -f ${RESULT_DIR}/require_test ]; then
                _check_test_fs || err=true
-               rm -f ${RESULT_DIR}/require_test
+               rm -f ${RESULT_DIR}/require_test*
        fi
        if [ -f ${RESULT_DIR}/require_scratch ]; then
                _check_scratch_fs || err=true
-               rm -f ${RESULT_DIR}/require_scratch
+               rm -f ${RESULT_DIR}/require_scratch*
        fi
 }
 
index d9350ea5a78202cf95d6a9763a18165d88379974..237bb3d88c0ff458bfd5539031979b860d6ea6d8 100644 (file)
@@ -41,6 +41,13 @@ _require_btrfs_command()
        [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd $param)"
 }
 
+# Require extra check on btrfs qgroup numbers
+_require_btrfs_qgroup_report()
+{
+       _require_btrfs_command check --qgroup-report
+       touch ${RESULT_DIR}/require_scratch.require_qgroup_report
+}
+
 _run_btrfs_util_prog()
 {
        run_check $BTRFS_UTIL_PROG $*
@@ -98,7 +105,20 @@ _check_btrfs_filesystem()
                mountpoint=`_umount_or_remount_ro $device`
        fi
 
-       btrfsck $device >$tmp.fsck 2>&1
+       if [ -f ${RESULT_DIR}/require_scratch.require_qgroup_report ]; then
+               $BTRFS_UTIL_PROG check $device --qgroup-report > $tmp.qgroup_report 2>&1
+               if grep -qE "Counts for qgroup.*are different" $tmp.qgroup_report ; then
+                       echo "_check_btrfs_filesystem: filesystem on $device has wrong qgroup numbers (see $seqres.full)"
+                       echo "_check_btrfs_filesystem: filesystem on $device has wrong qgroup numbers" \
+                               >> $seqres.full
+                       echo "*** qgroup_report.$FSTYP output ***"      >>$seqres.full
+                       cat $tmp.qgroup_report                          >>$seqres.full
+                       echo "*** qgroup_report.$FSTYP output ***"      >>$seqres.full
+               fi
+               rm -f $tmp.qgroup_report
+       fi
+
+       $BTRFS_UTIL_PROG check $device >$tmp.fsck 2>&1
        if [ $? -ne 0 ]; then
                echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
 
index d863e5694df8cd38f8b38d02a9e411b2336f56cc..6d9694f7418de4fdf60c4c4e5c0386398e9e65fc 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -1222,8 +1222,9 @@ _notrun()
 {
     echo "$*" > $seqres.notrun
     echo "$seq not run: $*"
-    rm -f ${RESULT_DIR}/require_test
-    rm -f ${RESULT_DIR}/require_scratch
+    rm -f ${RESULT_DIR}/require_test*
+    rm -f ${RESULT_DIR}/require_scratch*
+
     status=0
     exit
 }
index 56d4f3d405be5bd6b5cba8bdd77f6fad1b694714..9abad6c9909926ed82b02f0d4e9a9950685078b5 100755 (executable)
@@ -43,6 +43,7 @@ _cleanup()
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
+_require_btrfs_qgroup_report
 
 rm -f $seqres.full
 
@@ -125,16 +126,19 @@ _scratch_mkfs > /dev/null 2>&1
 _scratch_mount
 _basic_test
 _scratch_unmount
+_check_scratch_fs
 
 _scratch_mkfs > /dev/null 2>&1
 _scratch_mount
 _rescan_test
 _scratch_unmount
+_check_scratch_fs
 
 _scratch_mkfs > /dev/null 2>&1
 _scratch_mount
 _limit_test_exceed
 _scratch_unmount
+_check_scratch_fs
 
 _scratch_mkfs > /dev/null 2>&1
 _scratch_mount
index 1425609c4c3a7528dff5f54ff13f7264518e1ed6..a3d9a271c5c3362adb55a5ddc8f34bb5c84ebca0 100755 (executable)
@@ -51,6 +51,7 @@ rm -f $seqres.full
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
+_require_btrfs_qgroup_report
 
 _scratch_mkfs
 _scratch_mount
@@ -86,9 +87,7 @@ _run_btrfs_util_prog filesystem sync $SCRATCH_MNT
 
 _scratch_unmount
 
-# generate a qgroup report and look for inconsistent groups
-$BTRFS_UTIL_PROG check --qgroup-report $SCRATCH_DEV 2>&1 | \
-       grep -E "Counts for qgroup.*are different"
+# qgroup will be checked at _check_scratch_fs() by fstest.
 echo "Silence is golden"
 status=0
 
index 498ccc9ad19a7fc78da4d9a2319f87437cb6c409..cf3eac239b0fea0fa12777e4bf13914f41e22992 100755 (executable)
@@ -43,6 +43,7 @@ _cleanup()
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
+_require_btrfs_qgroup_report
 
 rm -f $seqres.full
 
index 70f07b5a1d58332c690dbefbf9fc443bc13b90ae..65ea79b3dd824ea09d3de58f945a3e8054f7d9a7 100755 (executable)
@@ -46,6 +46,7 @@ _cleanup()
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
+_require_btrfs_qgroup_report
 
 # Use big blocksize to ensure there is still enough space left for metadata
 # space reserve.
index 6afaa022252d60cf7a01ededc4582a7128a9d38e..e6a6d3b544ede27ec88294a7957e5b6cfd685da7 100755 (executable)
@@ -58,6 +58,7 @@ rm -f $seqres.full
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
+_require_btrfs_qgroup_report
 
 rm -f $seqres.full
 
@@ -145,21 +146,10 @@ _scratch_cycle_mount
 # referenced above.
 _run_btrfs_util_prog subvolume delete $SCRATCH_MNT/snap1
 
-# There is no way from userspace to force btrfs_drop_snapshot to run
-# at a given time (even via mount/unmount). We must wait for it to
-# start and complete. This is the shortest time on my tests systems I
-# have found which always allows drop_snapshot to run to completion.
-sleep 45
+# "btrfs filesystem sync" will trigger subvolume deletion
+_run_btrfs_util_prog filesystem sync $SCRATCH_MNT
 
-_scratch_unmount
-
-# generate a qgroup report and look for inconsistent groups
-#  - don't use _run_btrfs_util_prog here as it captures the output and
-#    we need to grep it.
-$BTRFS_UTIL_PROG check --qgroup-report $SCRATCH_DEV 2>&1 | \
-                       grep -E -q "Counts for qgroup.*are different"
-if [ $? -ne 0 ]; then
-       status=0
-fi
+# Qgroup will be checked by fstest at _check_scratch_fs()
 
+status=0
 exit
index 82252abe3d70cfe328bc77f32c797a9baffff975..6a7f17f2df8dac1a4dcc19d90ee50bf225dd0609 100755 (executable)
@@ -49,6 +49,7 @@ rm -f $seqres.full
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
+_require_btrfs_qgroup_report
 
 rm -f $seqres.full
 
@@ -78,11 +79,7 @@ _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/snap2"
 
 _scratch_unmount
 
-# generate a qgroup report and look for inconsistent groups
-$BTRFS_UTIL_PROG check --qgroup-report $SCRATCH_DEV 2>&1 | \
-                       grep -q -E "Counts for qgroup.*are different"
-if [ $? -ne 0 ]; then
-       status=0
-fi
 
+# qgroup will be checked by fstest at _check_scratch_fs()
+status=0
 exit
index e89d54171951e0f1b9e05a27f4d9bf6fea27b644..52d87fbb46bf3e80da784fa59a8de129a7609f6f 100755 (executable)
@@ -53,6 +53,7 @@ rm -f $seqres.full
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
+_require_btrfs_qgroup_report
 
 _scratch_mkfs
 # Need to use inline extents to fill metadata rapidly
@@ -76,9 +77,7 @@ _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
 _run_btrfs_util_prog balance start -d $SCRATCH_MNT
 
 _scratch_unmount
-# generate a qgroup report and look for inconsistent groups
-$BTRFS_UTIL_PROG check --qgroup-report $SCRATCH_DEV 2>&1 | \
-               grep -E "Counts for qgroup.*are different"
+# qgroup will be check at _check_scratch_fs() by fstest
 
 # success, all done
 status=0
index cc51f4a81b3dc85f1697815bf6d76280c9f613c2..c06c00b4f25c4f1df90d48373fdf1ec88a0b3f57 100755 (executable)
@@ -49,6 +49,7 @@ rm -f $seqres.full
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
+_require_btrfs_qgroup_report
 
 _scratch_mkfs
 # Use enospc_debug mount option to trigger restrict space info check