4 # Test delayed allocation with a large number of extents that are merged.
5 # Regression test for patch "Btrfs: fix delalloc accounting leak caused
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2017 Facebook. All Rights Reserved.
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #-----------------------------------------------------------------------
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 test_file="$TEST_DIR/$seq"
40 rm -f $tmp.* "$test_file"
52 # Create 32k extents. All of these extents will be accounted as outstanding and
54 for ((i = 0; i < 32 * 1024; i++)); do
55 $XFS_IO_PROG -f -c "pwrite $((2 * 4096 * i)) 4096" "$test_file" >>"$seqres.full"
58 # Fill in the gaps between the created extents. The outstanding extents will
59 # all be merged into 1, but there will still be 32k reserved.
60 for ((i = 0; i < 32 * 1024; i++)); do
61 $XFS_IO_PROG -f -c "pwrite $((2 * 4096 * i + 1)) 4096" "$test_file" >>"$seqres.full"
64 # Flush the delayed allocations.
67 # Make sure that we didn't leak any metadata space.
68 uuid="$(findmnt -n -o UUID "$TEST_DIR")"
69 cd "/sys/fs/btrfs/$uuid/allocation"
70 echo "$(($(cat metadata/bytes_may_use) - $(cat global_rsv_reserved))) bytes leaked" | grep -v '^0 '
72 echo "Silence is golden"