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