1425609c4c3a7528dff5f54ff13f7264518e1ed6
[xfstests-dev.git] / tests / btrfs / 028
1 #! /bin/bash
2 # FS QA Test 028
3 #
4 # Test if qgroup can handle extent de-reference during reallocation.
5 # "extent de-reference" means that reducing an extent's reference count
6 # or freeing an extent.
7 # Although current qgroup can handle it, we still need to prevent any
8 # regression which may break current qgroup.
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2016 Fujitsu. All Rights Reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39         cd /
40         rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46
47 # remove previous $seqres.full before test
48 rm -f $seqres.full
49
50 # real QA test starts here
51 _supported_fs btrfs
52 _supported_os Linux
53 _require_scratch
54
55 _scratch_mkfs
56 _scratch_mount
57
58 _run_btrfs_util_prog quota enable $SCRATCH_MNT
59 _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
60
61 # Increase the probability of generating de-refer extent, and decrease
62 # other.
63 args=`_scale_fsstress_args -z \
64         -f write=10 -f unlink=10 \
65         -f creat=10 -f fsync=10 \
66         -f fsync=10 -n 100000 -p 2 \
67         -d $SCRATCH_MNT/stress_dir`
68 echo "Run fsstress $args" >>$seqres.full
69 $FSSTRESS_PROG $args >/dev/null 2>&1 &
70 fsstress_pid=$!
71
72 echo "Start balance" >>$seqres.full
73 _btrfs_stress_balance -d $SCRATCH_MNT >/dev/null 2>&1 &
74 balance_pid=$!
75
76 # 30s is enough to trigger bug
77 sleep $((30*$TIME_FACTOR))
78 kill $fsstress_pid $balance_pid
79 wait
80
81 # kill _btrfs_stress_balance can't end balance, so call btrfs balance cancel
82 # to cancel running or paused balance.
83 $BTRFS_UTIL_PROG balance cancel $SCRATCH_MNT &> /dev/null
84
85 _run_btrfs_util_prog filesystem sync $SCRATCH_MNT
86
87 _scratch_unmount
88
89 # generate a qgroup report and look for inconsistent groups
90 $BTRFS_UTIL_PROG check --qgroup-report $SCRATCH_DEV 2>&1 | \
91         grep -E "Counts for qgroup.*are different"
92 echo "Silence is golden"
93 status=0
94
95 exit