btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 010
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 10
6 #
7 # Test delayed allocation with a large number of extents that are merged.
8 # Regression test for patch "Btrfs: fix delalloc accounting leak caused
9 # by u32 overflow".
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 test_file="$TEST_DIR/$seq"
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.* "$test_file"
26 }
27
28 . ./common/rc
29 . ./common/filter
30
31 rm -f $seqres.full
32
33 _supported_fs btrfs
34 _supported_os Linux
35 _require_test
36 _require_btrfs_fs_sysfs
37
38 # Create 32k extents. All of these extents will be accounted as outstanding and
39 # reserved.
40 for ((i = 0; i < 32 * 1024; i++)); do
41         $XFS_IO_PROG -f -c "pwrite $((2 * 4096 * i)) 4096" "$test_file" >>"$seqres.full"
42 done
43
44 # Fill in the gaps between the created extents. The outstanding extents will
45 # all be merged into 1, but there will still be 32k reserved.
46 for ((i = 0; i < 32 * 1024; i++)); do
47         $XFS_IO_PROG -f -c "pwrite $((2 * 4096 * i + 4096)) 4096" "$test_file" >>"$seqres.full"
48 done
49
50 # Flush the delayed allocations.
51 sync
52
53 # Make sure that we didn't leak any metadata space.
54 uuid="$(findmnt -n -o UUID "$TEST_DIR")"
55 cd "/sys/fs/btrfs/$uuid/allocation"
56 echo "$(($(cat metadata/bytes_may_use) - $(cat global_rsv_reserved))) bytes leaked" | grep -v '^0 '
57
58 echo "Silence is golden"
59
60 status=0
61 exit