2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # A general test to validate that balance and qgroups work correctly when
8 # balance needs to be resumed on mount.
11 _begin_fstest auto quick replay balance qgroup recoveryloop
13 # Import common functions.
15 . ./common/dmlogwrites
17 # real QA test starts here
19 # Modify as appropriate.
22 # and we need extra device as log device
25 nr_files=512 # enough metadata to bump tree height
26 file_size=2048 # small enough to be inlined
28 _log_writes_init $SCRATCH_DEV
29 _log_writes_mkfs >> $seqres.full 2>&1
32 $BTRFS_UTIL_PROG quota enable $SCRATCH_MNT >> $seqres.full
33 $BTRFS_UTIL_PROG quota rescan -w $SCRATCH_MNT >> $seqres.full
35 # Create enough metadata for later balance
36 for ((i = 0; i < $nr_files; i++)); do
37 _pwrite_byte 0xcd 0 $file_size $SCRATCH_MNT/file_$i > /dev/null
40 # Flush delalloc so that balance has work to do.
43 # Balance metadata so we will have at least one transaction committed with
44 # valid reloc tree, and hopefully another commit with orphan reloc tree.
45 _run_btrfs_balance_start -f -m $SCRATCH_MNT >> $seqres.full
50 cur=$(_log_writes_find_next_fua 0)
51 echo "cur=$cur" >> $seqres.full
52 while [ ! -z "$cur" ]; do
53 _log_writes_replay_log_range $cur $SCRATCH_DEV >> $seqres.full
55 # Test that no crashes happen or any other kind of failure.
59 # Don't trigger fsck here, as relocation get paused,
60 # at that transistent state, qgroup number may differ
61 # and cause false alert.
64 cur=$(_log_writes_find_next_fua $(($cur + 1)))
65 [ -z "$cur" ] && break
68 # Now the fs has finished its balance and qgroup should be consistent.
69 # Fstest will automatically check the fs and btrfs check will report
70 # any qgroup inconsistent if something went wrong.
72 echo "Silence is golden"