generic/563: use a loop device to avoid partition incompatibility
[xfstests-dev.git] / tests / btrfs / 072
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/072
6 #
7 # Run btrfs scrub and defrag operations 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 4
34 _btrfs_get_profile_configs
35
36 rm -f $seqres.full
37
38 run_test()
39 {
40         local mkfs_opts=$1
41         local with_compress=$2
42
43         echo "Test $mkfs_opts with $with_compress" >>$seqres.full
44
45         _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
46         # make sure we created btrfs with desired options
47         if [ $? -ne 0 ]; then
48                 echo "mkfs $mkfs_opts failed"
49                 return
50         fi
51         _scratch_mount >>$seqres.full 2>&1
52
53         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
54         echo "Run fsstress $args" >>$seqres.full
55         $FSSTRESS_PROG $args >/dev/null 2>&1 &
56         fsstress_pid=$!
57
58         echo -n "Start scrub worker: " >>$seqres.full
59         _btrfs_stress_scrub $SCRATCH_MNT >/dev/null 2>&1 &
60         scrub_pid=$!
61         echo "$scrub_pid" >>$seqres.full
62
63         echo -n "Start defrag worker: " >>$seqres.full
64         _btrfs_stress_defrag $SCRATCH_MNT $with_compress >/dev/null 2>&1 &
65         defrag_pid=$!
66         echo "$defrag_pid" >>$seqres.full
67
68         echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
69         wait $fsstress_pid
70         kill $scrub_pid $defrag_pid
71         wait
72         # wait for the scrub and defrag operations to finish
73         while ps aux | grep "scrub start" | grep -qv grep; do
74                 sleep 1
75         done
76         while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
77                 sleep 1
78         done
79
80         echo "Scrub the filesystem" >>$seqres.full
81         $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
82         if [ $? -ne 0 ]; then
83                 echo "Scrub find errors in \"$mkfs_opts\" test" | tee -a $seqres.full
84         fi
85
86         _scratch_unmount
87         # we called _require_scratch_nocheck instead of _require_scratch
88         # do check after test for each profile config
89         _check_scratch_fs
90 }
91
92 echo "Silence is golden"
93 for t in "${_btrfs_profile_configs[@]}"; do
94         run_test "$t" nocompress
95         run_test "$t" compress
96 done
97
98 status=0
99 exit