btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 071
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/071
6 #
7 # Run btrfs replace operations and remount with different compress
8 # algorithms simultaneously with fsstress 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 5
35 _require_scratch_dev_pool_equal_size
36 _btrfs_get_profile_configs replace
37
38 rm -f $seqres.full
39
40 run_test()
41 {
42         local mkfs_opts=$1
43         local saved_scratch_dev_pool=$SCRATCH_DEV_POOL
44
45         echo "Test $mkfs_opts" >>$seqres.full
46
47         # remove the last device from the SCRATCH_DEV_POOL list so
48         # _scratch_pool_mkfs won't use all devices in pool
49         local last_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
50         SCRATCH_DEV_POOL=`echo $SCRATCH_DEV_POOL | sed -e "s# *$last_dev *##"`
51         _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
52         # make sure we created btrfs with desired options
53         if [ $? -ne 0 ]; then
54                 echo "mkfs $mkfs_opts failed"
55                 SCRATCH_DEV_POOL=$saved_scratch_dev_pool
56                 return
57         fi
58         _scratch_mount >>$seqres.full 2>&1
59         SCRATCH_DEV_POOL=$saved_scratch_dev_pool
60
61         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
62         echo "Run fsstress $args" >>$seqres.full
63         $FSSTRESS_PROG $args >/dev/null 2>&1 &
64         fsstress_pid=$!
65
66         echo -n "Start replace worker: " >>$seqres.full
67         _btrfs_stress_replace $SCRATCH_MNT >>$seqres.full 2>&1 &
68         replace_pid=$!
69         echo "$replace_pid" >>$seqres.full
70
71         echo -n "Start remount worker: " >>$seqres.full
72         _btrfs_stress_remount_compress $SCRATCH_MNT >/dev/null 2>&1 &
73         remount_pid=$!
74         echo "$remount_pid" >>$seqres.full
75
76         echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
77         wait $fsstress_pid
78         kill $replace_pid $remount_pid
79         wait
80
81         # wait for the remount and replace operations to finish
82         while ps aux | grep "replace start" | grep -qv grep; do
83                 sleep 1
84         done
85         while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
86                 sleep 1
87         done
88
89         echo "Scrub the filesystem" >>$seqres.full
90         $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
91         if [ $? -ne 0 ]; then
92                 echo "Scrub find errors in \"$mkfs_opts\" test" | tee -a $seqres.full
93         fi
94
95         _scratch_unmount
96         # we called _require_scratch_nocheck instead of _require_scratch
97         # do check after test for each profile config
98         _check_scratch_fs
99 }
100
101 echo "Silence is golden"
102 for t in "${_btrfs_profile_configs[@]}"; do
103         run_test "$t"
104 done
105
106 status=0
107 exit