btrfs: Add a test for dead looping balance after balance cancel
authorQu Wenruo <wqu@suse.com>
Thu, 21 May 2020 00:52:15 +0000 (08:52 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 24 May 2020 16:29:08 +0000 (00:29 +0800)
Test if canceling a running balance can cause later balance to dead
loop.

The fix is titled "btrfs: relocation: Clear the DEAD_RELOC_TREE bit for
 orphan roots to prevent runaway balance".

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/213 [new file with mode: 0755]
tests/btrfs/213.out [new file with mode: 0644]
tests/btrfs/group

diff --git a/tests/btrfs/213 b/tests/btrfs/213
new file mode 100755 (executable)
index 0000000..a125eb6
--- /dev/null
@@ -0,0 +1,66 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test 213
+#
+# Test if canceling a running balance can lead to dead looping balance
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       kill $write_pid &> /dev/null
+       rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# Modify as appropriate.
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch
+_require_xfs_io_command pwrite -D
+
+_scratch_mkfs >> $seqres.full
+_scratch_mount
+
+runtime=4
+
+# Create enough IO so that we need around $runtime seconds to relocate it.
+#
+# Here we don't want any wrapper, as we want full control of the process.
+$XFS_IO_PROG -f -c "pwrite -D -b 1M 0 1024T" "$SCRATCH_MNT/file" &> /dev/null &
+write_pid=$!
+sleep $runtime
+kill $write_pid
+wait $write_pid
+
+# Now balance should take at least $runtime seconds, we can cancel it at
+# $runtime/2 to ensure a success cancel.
+_run_btrfs_balance_start -d --bg "$SCRATCH_MNT"
+sleep $(($runtime / 2))
+$BTRFS_UTIL_PROG balance cancel "$SCRATCH_MNT"
+
+# Now check if we can finish relocating metadata, which should finish very
+# quickly.
+$BTRFS_UTIL_PROG balance start -m "$SCRATCH_MNT" >> $seqres.full
+
+echo "Silence is golden"
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/213.out b/tests/btrfs/213.out
new file mode 100644 (file)
index 0000000..bd8f243
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 213
+Silence is golden
index 8d65bddd92e460bf1f953c3cf96381ac9bcfdc1c..9e48ecc11d08bad690e8b195ac506dbda8aa7f72 100644 (file)
 210 auto quick qgroup snapshot
 211 auto quick log prealloc
 212 auto balance dangerous
+213 auto balance dangerous