btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / btrfs / 190
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 SUSE Linux Products GmbH.  All Rights Reserved.
4 #
5 # FS QA Test 190
6 #
7 # A general test to validate that balance and qgroups work correctly when
8 # balance needs to be resumed on mount.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/dmlogwrites
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
34
35 # Modify as appropriate.
36 _supported_fs btrfs
37 _require_scratch
38 # and we need extra device as log device
39 _require_log_writes
40
41 nr_files=512                            # enough metadata to bump tree height
42 file_size=2048                          # small enough to be inlined
43
44 _log_writes_init $SCRATCH_DEV
45 _log_writes_mkfs >> $seqres.full 2>&1
46
47 _log_writes_mount
48 $BTRFS_UTIL_PROG quota enable $SCRATCH_MNT >> $seqres.full
49 $BTRFS_UTIL_PROG quota rescan -w $SCRATCH_MNT >> $seqres.full
50
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
54 done
55
56 # Flush delalloc so that balance has work to do.
57 sync
58
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
62
63 _log_writes_unmount
64 _log_writes_remove
65
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
70
71         # Test that no crashes happen or any other kind of failure.
72         _scratch_mount
73         _scratch_unmount
74
75         # Don't trigger fsck here, as relocation get paused,
76         # at that transistent state, qgroup number may differ
77         # and cause false alert.
78
79         prev=$cur
80         cur=$(_log_writes_find_next_fua $(($cur + 1)))
81         [ -z "$cur" ] && break
82 done
83
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.
87
88 echo "Silence is golden"
89
90 # success, all done
91 status=0
92 exit