2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Facebook. All Rights Reserved.
7 # Test delayed allocation with a large number of extents that are merged.
8 # Regression test for patch "Btrfs: fix delalloc accounting leak caused
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
20 test_file="$TEST_DIR/$seq"
25 rm -f $tmp.* "$test_file"
35 _require_btrfs_fs_sysfs
37 # Create 32k extents. All of these extents will be accounted as outstanding and
39 for ((i = 0; i < 32 * 1024; i++)); do
40 $XFS_IO_PROG -f -c "pwrite $((2 * 4096 * i)) 4096" "$test_file" >>"$seqres.full"
43 # Fill in the gaps between the created extents. The outstanding extents will
44 # all be merged into 1, but there will still be 32k reserved.
45 for ((i = 0; i < 32 * 1024; i++)); do
46 $XFS_IO_PROG -f -c "pwrite $((2 * 4096 * i + 4096)) 4096" "$test_file" >>"$seqres.full"
49 # Flush the delayed allocations.
52 # Make sure that we didn't leak any metadata space.
53 uuid="$(findmnt -n -o UUID "$TEST_DIR")"
54 cd "/sys/fs/btrfs/$uuid/allocation"
55 echo "$(($(cat metadata/bytes_may_use) - $(cat global_rsv_reserved))) bytes leaked" | grep -v '^0 '
57 echo "Silence is golden"