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 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
28 . ./common/dmlogwrites
30 # remove previous $seqres.full before test
33 # real QA test starts here
35 # Modify as appropriate.
38 # and we need extra device as log device
41 nr_files=512 # enough metadata to bump tree height
42 file_size=2048 # small enough to be inlined
44 _log_writes_init $SCRATCH_DEV
45 _log_writes_mkfs >> $seqres.full 2>&1
48 $BTRFS_UTIL_PROG quota enable $SCRATCH_MNT >> $seqres.full
49 $BTRFS_UTIL_PROG quota rescan -w $SCRATCH_MNT >> $seqres.full
51 # Create enough metadata for later balance
52 for ((i = 0; i < $nr_files; i++)); do
53 _pwrite_byte 0xcd 0 $file_size $SCRATCH_MNT/file_$i > /dev/null
56 # Flush delalloc so that balance has work to do.
59 # Balance metadata so we will have at least one transaction committed with
60 # valid reloc tree, and hopefully another commit with orphan reloc tree.
61 _run_btrfs_balance_start -f -m $SCRATCH_MNT >> $seqres.full
66 cur=$(_log_writes_find_next_fua 0)
67 echo "cur=$cur" >> $seqres.full
68 while [ ! -z "$cur" ]; do
69 _log_writes_replay_log_range $cur $SCRATCH_DEV >> $seqres.full
71 # Test that no crashes happen or any other kind of failure.
75 # Don't trigger fsck here, as relocation get paused,
76 # at that transistent state, qgroup number may differ
77 # and cause false alert.
80 cur=$(_log_writes_find_next_fua $(($cur + 1)))
81 [ -z "$cur" ] && break
84 # Now the fs has finished its balance and qgroup should be consistent.
85 # Fstest will automatically check the fs and btrfs check will report
86 # any qgroup inconsistent if something went wrong.
88 echo "Silence is golden"