xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / btrfs / 064
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/064
6 #
7 # Run btrfs balance and replace operations simultaneously with fsstress running
8 # in the background, check with the scrub if all the blocks are ok.
9 # Balance and replace operations are mutually exclusive operations they can't
10 # run simultaneously. One of them is expected to fail when the other is running.
11
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # real QA test starts here
32 _supported_fs btrfs
33 # we check scratch dev after each loop
34 _require_scratch_nocheck
35 _require_scratch_dev_pool 5
36 _require_scratch_dev_pool_equal_size
37 _btrfs_get_profile_configs replace
38
39 rm -f $seqres.full
40
41 run_test()
42 {
43         local mkfs_opts=$1
44         local saved_scratch_dev_pool=$SCRATCH_DEV_POOL
45
46         echo "Test $mkfs_opts" >>$seqres.full
47
48         # remove the last device from the SCRATCH_DEV_POOL list so
49         # _scratch_pool_mkfs won't use all devices in pool
50         local last_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
51         SCRATCH_DEV_POOL=`echo $SCRATCH_DEV_POOL | sed -e "s# *$last_dev *##"`
52         _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
53         # make sure we created btrfs with desired options
54         if [ $? -ne 0 ]; then
55                 echo "mkfs $mkfs_opts failed"
56                 SCRATCH_DEV_POOL=$saved_scratch_dev_pool
57                 return
58         fi
59         _scratch_mount >>$seqres.full 2>&1
60         SCRATCH_DEV_POOL=$saved_scratch_dev_pool
61
62         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
63         echo "Run fsstress $args" >>$seqres.full
64         $FSSTRESS_PROG $args >/dev/null 2>&1 &
65         fsstress_pid=$!
66
67         # Start both balance and replace in the background.
68         # Either balance or replace shall run, the other fails.
69         echo -n "Start balance worker: " >>$seqres.full
70         _btrfs_stress_balance $SCRATCH_MNT >/dev/null 2>&1 &
71         balance_pid=$!
72         echo "$balance_pid" >>$seqres.full
73
74         echo -n "Start replace worker: " >>$seqres.full
75         _btrfs_stress_replace $SCRATCH_MNT >>$seqres.full 2>&1 &
76         replace_pid=$!
77         echo "$replace_pid" >>$seqres.full
78
79         echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
80         wait $fsstress_pid
81         kill $balance_pid $replace_pid
82         wait
83         # wait for the balance and replace operations to finish
84         while ps aux | grep "balance start" | grep -qv grep; do
85                 sleep 1
86         done
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         _scratch_unmount
98         # we called _require_scratch_nocheck instead of _require_scratch
99         # do check after test for each profile config
100         _check_scratch_fs
101 }
102
103 echo "Silence is golden"
104 for t in "${_btrfs_profile_configs[@]}"; do
105         run_test "$t"
106 done
107
108 status=0
109 exit