common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / btrfs / 021
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 021
6 #
7 # A regression test of running btrfs balance and defrag concurrently.
8 #
9 # The test aims to trigger snapshot-aware defrag path in endio by
10 # running balance, which is not expected and leads to a crash.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # real QA test starts here
32 run_test()
33 {
34         _run_btrfs_balance_start $SCRATCH_MNT >> $seqres.full &
35
36         sleep 0.5
37
38         find $SCRATCH_MNT -type f -print0 | xargs -0 \
39         $BTRFS_UTIL_PROG filesystem defrag -f
40
41         sync
42         wait
43 }
44
45 _supported_fs btrfs
46 _supported_os Linux
47 _require_scratch
48
49 rm -f $seqres.full
50
51 _scratch_mkfs > /dev/null 2>&1
52 _scratch_mount
53
54 # This is going to reproduce a race senario between balance and the writeback
55 # of snapshot-aware defragment.
56
57 # we first create a few files to get higher btree height.
58 for j in `seq 0 100`; do
59         touch $SCRATCH_MNT/padding-$j
60 done
61
62 # Get 50 files with fragments by using backwards writes.
63 for j in `seq 0 50`; do
64         for i in `seq 20 -1 1`; do
65                 $XFS_IO_PROG -f -d -c "pwrite $(($i * 4096)) 4096" \
66                 $SCRATCH_MNT/foo-$j >> $seqres.full | _filter_xfs_io
67         done
68 done
69
70 # Make sure that our metadata makes it self on disk.
71 sync
72
73 run_test
74
75 # success, all done
76 echo "Silence is golden"
77 status=0
78 exit