fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / btrfs / 069
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 Red Hat Inc. All rights reserved.
4 #
5 # FSQA Test No. btrfs/069
6 #
7 # Run btrfs replace operations and scrub simultaneously with fsstress
8 # running in background.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs btrfs
31 # we check scratch dev after each loop
32 _require_scratch_nocheck
33 _require_scratch_dev_pool 5
34 _require_scratch_dev_pool_equal_size
35 _btrfs_get_profile_configs replace
36
37 rm -f $seqres.full
38
39 run_test()
40 {
41         local mkfs_opts=$1
42         local saved_scratch_dev_pool=$SCRATCH_DEV_POOL
43
44         echo "Test $mkfs_opts" >>$seqres.full
45
46         # remove the last device from the SCRATCH_DEV_POOL list so
47         # _scratch_pool_mkfs won't use all devices in pool
48         local last_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
49         SCRATCH_DEV_POOL=`echo $SCRATCH_DEV_POOL | sed -e "s# *$last_dev *##"`
50         _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
51         # make sure we created btrfs with desired options
52         if [ $? -ne 0 ]; then
53                 echo "mkfs $mkfs_opts failed"
54                 SCRATCH_DEV_POOL=$saved_scratch_dev_pool
55                 return
56         fi
57         _scratch_mount >>$seqres.full 2>&1
58         SCRATCH_DEV_POOL=$saved_scratch_dev_pool
59
60         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
61         echo "Run fsstress $args" >>$seqres.full
62         $FSSTRESS_PROG $args >/dev/null 2>&1 &
63         fsstress_pid=$!
64
65         echo -n "Start replace worker: " >>$seqres.full
66         _btrfs_stress_replace $SCRATCH_MNT >>$seqres.full 2>&1 &
67         replace_pid=$!
68         echo "$replace_pid" >>$seqres.full
69
70         echo -n "Start scrub worker: " >>$seqres.full
71         _btrfs_stress_scrub $SCRATCH_MNT >/dev/null 2>&1 &
72         scrub_pid=$!
73         echo "$scrub_pid" >>$seqres.full
74
75         echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
76         wait $fsstress_pid
77         kill $replace_pid $scrub_pid
78         wait
79
80         # wait for the scrub and replace operations to finish
81         while ps aux | grep "scrub start" | grep -qv grep; do
82                 sleep 1
83         done
84         while ps aux | grep "replace start" | grep -qv grep; do
85                 sleep 1
86         done
87
88         echo "Scrub the filesystem" >>$seqres.full
89         $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
90         if [ $? -ne 0 ]; then
91                 echo "Scrub find errors in \"$mkfs_opts\" test" | tee -a $seqres.full
92         fi
93
94         _scratch_unmount
95         # we called _require_scratch_nocheck instead of _require_scratch
96         # do check after test for each profile config
97         _check_scratch_fs
98 }
99
100 echo "Silence is golden"
101 for t in "${_btrfs_profile_configs[@]}"; do
102         run_test "$t"
103 done
104
105 status=0
106 exit