btrfs/057: Fix false alerts due to orphan files
[xfstests-dev.git] / tests / btrfs / 065
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/065
6 #
7 # Run btrfs subvolume create/mount/umount/delete and device replace
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 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         local subvol_mnt=$TEST_DIR/$seq.mnt
45         local stop_file=$TEST_DIR/$seq.stop.$$
46
47         echo "Test $mkfs_opts" >>$seqres.full
48
49         # remove the last device from the SCRATCH_DEV_POOL list so
50         # _scratch_pool_mkfs won't use all devices in pool
51         local last_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
52         SCRATCH_DEV_POOL=`echo $SCRATCH_DEV_POOL | sed -e "s# *$last_dev *##"`
53         _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
54         # make sure we created btrfs with desired options
55         if [ $? -ne 0 ]; then
56                 echo "mkfs $mkfs_opts failed"
57                 SCRATCH_DEV_POOL=$saved_scratch_dev_pool
58                 return
59         fi
60         _scratch_mount >>$seqres.full 2>&1
61         SCRATCH_DEV_POOL=$saved_scratch_dev_pool
62
63         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
64         echo "Run fsstress $args" >>$seqres.full
65         $FSSTRESS_PROG $args >/dev/null 2>&1 &
66         fsstress_pid=$!
67
68         # make sure the stop sign is not there
69         rm -f $stop_file
70         echo -n "Start subvolume worker: " >>$seqres.full
71         _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
72         subvol_pid=$!
73         echo "$subvol_pid" >>$seqres.full
74
75         echo -n "Start replace worker: " >>$seqres.full
76         _btrfs_stress_replace $SCRATCH_MNT >>$seqres.full 2>&1 &
77         replace_pid=$!
78         echo "$replace_pid" >>$seqres.full
79
80         echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
81         wait $fsstress_pid
82
83         touch $stop_file
84         kill $replace_pid
85         wait
86         # wait for the replace operation to finish
87         while ps aux | grep "replace start" | grep -qv grep; do
88                 sleep 1
89         done
90
91         echo "Scrub the filesystem" >>$seqres.full
92         $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
93         if [ $? -ne 0 ]; then
94                 echo "Scrub find errors in \"$mkfs_opts\" test" | tee -a $seqres.full
95         fi
96
97         # in case the subvolume is still mounted
98         $UMOUNT_PROG $subvol_mnt >/dev/null 2>&1
99         _scratch_unmount
100         # we called _require_scratch_nocheck instead of _require_scratch
101         # do check after test for each profile config
102         _check_scratch_fs
103 }
104
105 echo "Silence is golden"
106 for t in "${_btrfs_profile_configs[@]}"; do
107         run_test "$t"
108 done
109
110 status=0
111 exit