btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 067
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/067
6 #
7 # Run btrfs subvolume create/mount/umount/delete and btrfs defrag
8 # operation 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 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         local subvol_mnt=$TEST_DIR/$seq.mnt
44         local stop_file=$TEST_DIR/$seq.stop.$$
45
46         echo "Test $mkfs_opts with $with_compress" >>$seqres.full
47
48         _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
49         # make sure we created btrfs with desired options
50         if [ $? -ne 0 ]; then
51                 echo "mkfs $mkfs_opts failed"
52                 return
53         fi
54         _scratch_mount >>$seqres.full 2>&1
55
56         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
57         echo "Run fsstress $args" >>$seqres.full
58         $FSSTRESS_PROG $args >/dev/null 2>&1 &
59         fsstress_pid=$!
60
61         # make sure the stop sign is not there
62         rm -f $stop_file
63         echo -n "Start subvolume worker: " >>$seqres.full
64         _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
65         subvol_pid=$!
66         echo "$subvol_pid" >>$seqres.full
67
68         echo -n "Start defrag worker: " >>$seqres.full
69         _btrfs_stress_defrag $SCRATCH_MNT $with_compress >/dev/null 2>&1 &
70         defrag_pid=$!
71         echo "$defrag_pid" >>$seqres.full
72
73         echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
74         wait $fsstress_pid
75
76         touch $stop_file
77         kill $defrag_pid
78         wait
79         # wait for btrfs defrag process to exit, otherwise it will block umount
80         while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
81                 sleep 1
82         done
83
84         echo "Scrub the filesystem" >>$seqres.full
85         $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
86         if [ $? -ne 0 ]; then
87                 echo "Scrub find errors in \"$mkfs_opts\" test" | tee -a $seqres.full
88         fi
89
90         # in case the subvolume is still mounted
91         $UMOUNT_PROG $subvol_mnt >/dev/null 2>&1
92         _scratch_unmount
93         # we called _require_scratch_nocheck instead of _require_scratch
94         # do check after test for each profile config
95         _check_scratch_fs
96 }
97
98 echo "Silence is golden"
99 for t in "${_btrfs_profile_configs[@]}"; do
100         run_test "$t" nocompress
101         run_test "$t" compress
102 done
103
104 status=0
105 exit