btrfs: test incremental send after renaming and linking file
[xfstests-dev.git] / tests / btrfs / 021
1 #! /bin/bash
2 # FS QA Test No. 021
3 #
4 # A regression test of running btrfs balance and defrag concurrently.
5 #
6 # The test aims to trigger snapshot-aware defrag path in endio by
7 # running balance, which is not expected and leads to a crash.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2013 Oracle.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -f $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45
46 # real QA test starts here
47 run_test()
48 {
49         $BTRFS_UTIL_PROG balance start $SCRATCH_MNT >> $seqres.full &
50
51         sleep 0.5
52
53         find $SCRATCH_MNT -type f -print0 | xargs -0 \
54         $BTRFS_UTIL_PROG filesystem defrag -f
55
56         sync
57         wait
58 }
59
60 _supported_fs btrfs
61 _supported_os Linux
62 _require_scratch
63
64 rm -f $seqres.full
65
66 _scratch_mkfs > /dev/null 2>&1
67 _scratch_mount
68
69 # This is going to reproduce a race senario between balance and the writeback
70 # of snapshot-aware defragment.
71
72 # we first create a few files to get higher btree height.
73 for j in `seq 0 100`; do
74         touch $SCRATCH_MNT/padding-$j
75 done
76
77 # Get 50 files with fragments by using backwards writes.
78 for j in `seq 0 50`; do
79         for i in `seq 20 -1 1`; do
80                 $XFS_IO_PROG -f -d -c "pwrite $(($i * 4096)) 4096" \
81                 $SCRATCH_MNT/foo-$j >> $seqres.full | _filter_xfs_io
82         done
83 done
84
85 # Make sure that our metadata makes it self on disk.
86 sync
87
88 run_test
89
90 # success, all done
91 echo "Silence is golden"
92 status=0
93 exit