btrfs: test incremental send after renaming and linking file
[xfstests-dev.git] / tests / btrfs / 010
1 #! /bin/bash
2 # FS QA Test 10
3 #
4 # Test delayed allocation with a large number of extents that are merged.
5 # Regression test for patch "Btrfs: fix delalloc accounting leak caused
6 # by u32 overflow".
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2017 Facebook.  All Rights Reserved.
10 #
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.
14 #
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.
19 #
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 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 test_file="$TEST_DIR/$seq"
36
37 _cleanup()
38 {
39         cd /
40         rm -f $tmp.* "$test_file"
41 }
42
43 . ./common/rc
44 . ./common/filter
45
46 rm -f $seqres.full
47
48 _supported_fs btrfs
49 _supported_os Linux
50 _require_test
51
52 # Create 32k extents. All of these extents will be accounted as outstanding and
53 # reserved.
54 for ((i = 0; i < 32 * 1024; i++)); do
55         $XFS_IO_PROG -f -c "pwrite $((2 * 4096 * i)) 4096" "$test_file" >>"$seqres.full"
56 done
57
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"
62 done
63
64 # Flush the delayed allocations.
65 sync
66
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 '
71
72 echo "Silence is golden"
73
74 status=0
75 exit