btrfs: Verify falloc on multiple holes won't leak qgroup reserved data space
[xfstests-dev.git] / tests / btrfs / 123
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Fujitsu. All Rights Reserved.
4 #
5 # FS QA Test 123
6 #
7 # Test if btrfs leaks qgroup numbers for data extents
8 #
9 # Due to balance code is doing trick tree block swap, which doing
10 # non-standard extent reference update, qgroup can't handle it correctly,
11 # and leads to corrupted qgroup numbers.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36
37 # Modify as appropriate.
38 _supported_fs btrfs
39 _supported_os Linux
40 _require_scratch
41 _require_btrfs_qgroup_report
42
43 _scratch_mkfs >/dev/null
44 # Need to use inline extents to fill metadata rapidly
45 _scratch_mount "-o max_inline=2048"
46
47 # create 64K inlined metadata, which will ensure there is a 2-level
48 # metadata. Even for maximum nodesize(64K)
49 for i in $(seq 32); do
50         _pwrite_byte 0xcdcdcdcd 0 2k $SCRATCH_MNT/small_$i | _filter_xfs_io
51 done
52
53 # then a large data write to make the quota corruption obvious enough
54 _pwrite_byte 0xcdcdcdcd 0 32m $SCRATCH_MNT/large | _filter_xfs_io
55 sync
56
57 # enable quota and rescan to get correct number
58 _run_btrfs_util_prog quota enable $SCRATCH_MNT
59 _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
60
61 # now balance data block groups to corrupt qgroup
62 _run_btrfs_util_prog balance start -d $SCRATCH_MNT
63
64 _scratch_unmount
65 # qgroup will be check at _check_scratch_fs() by fstest
66
67 # success, all done
68 status=0
69 exit