4 # Test if btrfs leaks qgroup numbers for data extents
6 # Due to balance code is doing trick tree block swap, which doing
7 # non-standard extent reference update, qgroup can't handle it correctly,
8 # and leads to corrupted qgroup numbers.
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2016 Fujitsu. All Rights Reserved.
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
43 # get standard environment, filters and checks
47 # remove previous $seqres.full before test
50 # real QA test starts here
52 # Modify as appropriate.
58 # Need to use inline extents to fill metadata rapidly
59 _scratch_mount "-o max_inline=2048"
61 # create 64K inlined metadata, which will ensure there is a 2-level
62 # metadata. Even for maximum nodesize(64K)
63 for i in $(seq 32); do
64 _pwrite_byte 0xcdcdcdcd 0 2k $SCRATCH_MNT/small_$i | _filter_xfs_io
67 # then a large data write to make the quota corruption obvious enough
68 _pwrite_byte 0xcdcdcdcd 0 32m $SCRATCH_MNT/large | _filter_xfs_io
71 # enable quota and rescan to get correct number
72 _run_btrfs_util_prog quota enable $SCRATCH_MNT
73 _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
75 # now balance data block groups to corrupt qgroup
76 _run_btrfs_util_prog balance start -d $SCRATCH_MNT
79 # generate a qgroup report and look for inconsistent groups
80 $BTRFS_UTIL_PROG check --qgroup-report $SCRATCH_DEV 2>&1 | \
81 grep -E "Counts for qgroup.*are different"