be3afe03f0227fc15cfaddacbe68c9c061a761da
[xfstests-dev.git] / tests / btrfs / 071
1 #! /bin/bash
2 # FSQA Test No. btrfs/071
3 #
4 # Run btrfs replace operations and remount with different compress
5 # algorithms simultaneously with fsstress running in background.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (C) 2014 Red Hat Inc. All rights reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
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
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         rm -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # real QA test starts here
46 _supported_fs btrfs
47 _supported_os Linux
48 # we check scratch dev after each loop
49 _require_scratch_nocheck
50 _require_scratch_dev_pool 5
51 _require_scratch_dev_pool_equal_size
52 _btrfs_get_profile_configs replace
53
54 rm -f $seqres.full
55
56 run_test()
57 {
58         local mkfs_opts=$1
59         local saved_scratch_dev_pool=$SCRATCH_DEV_POOL
60
61         echo "Test $mkfs_opts" >>$seqres.full
62
63         # remove the last device from the SCRATCH_DEV_POOL list so
64         # _scratch_pool_mkfs won't use all devices in pool
65         local last_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
66         SCRATCH_DEV_POOL=`echo $SCRATCH_DEV_POOL | sed -e "s# *$last_dev *##"`
67         _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
68         # make sure we created btrfs with desired options
69         if [ $? -ne 0 ]; then
70                 echo "mkfs $mkfs_opts failed"
71                 SCRATCH_DEV_POOL=$saved_scratch_dev_pool
72                 return
73         fi
74         _scratch_mount >>$seqres.full 2>&1
75         SCRATCH_DEV_POOL=$saved_scratch_dev_pool
76
77         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
78         echo "Run fsstress $args" >>$seqres.full
79         $FSSTRESS_PROG $args >/dev/null 2>&1 &
80         fsstress_pid=$!
81
82         echo -n "Start replace worker: " >>$seqres.full
83         _btrfs_stress_replace $SCRATCH_MNT >>$seqres.full 2>&1 &
84         replace_pid=$!
85         echo "$replace_pid" >>$seqres.full
86
87         echo -n "Start remount worker: " >>$seqres.full
88         _btrfs_stress_remount_compress $SCRATCH_MNT >/dev/null 2>&1 &
89         remount_pid=$!
90         echo "$remount_pid" >>$seqres.full
91
92         echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
93         wait $fsstress_pid
94         kill $replace_pid $remount_pid
95         wait
96
97         # wait for the remount and replace operations to finish
98         while ps aux | grep "replace start" | grep -qv grep; do
99                 sleep 1
100         done
101         while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
102                 sleep 1
103         done
104
105         echo "Scrub the filesystem" >>$seqres.full
106         $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
107         if [ $? -ne 0 ]; then
108                 echo "Scrub find errors in \"$mkfs_opts\" test" | tee -a $seqres.full
109         fi
110
111         _scratch_unmount
112         # we called _require_scratch_nocheck instead of _require_scratch
113         # do check after test for each profile config
114         _check_scratch_fs
115 }
116
117 echo "Silence is golden"
118 for t in "${_btrfs_profile_configs[@]}"; do
119         run_test "$t"
120 done
121
122 status=0
123 exit