2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 Red Hat Inc. All rights reserved.
5 # FSQA Test No. btrfs/064
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.
13 _begin_fstest auto balance replace volume
15 # Import common functions.
18 # real QA test starts here
20 # we check scratch dev after each loop
21 _require_scratch_nocheck
22 _require_scratch_dev_pool 5
23 _require_scratch_dev_pool_equal_size
24 _btrfs_get_profile_configs replace
29 local saved_scratch_dev_pool=$SCRATCH_DEV_POOL
31 echo "Test $mkfs_opts" >>$seqres.full
33 # remove the last device from the SCRATCH_DEV_POOL list so
34 # _scratch_pool_mkfs won't use all devices in pool
35 local last_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
36 SCRATCH_DEV_POOL=`echo $SCRATCH_DEV_POOL | sed -e "s# *$last_dev *##"`
37 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
38 # make sure we created btrfs with desired options
40 echo "mkfs $mkfs_opts failed"
41 SCRATCH_DEV_POOL=$saved_scratch_dev_pool
44 _scratch_mount >>$seqres.full 2>&1
45 SCRATCH_DEV_POOL=$saved_scratch_dev_pool
47 args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
48 echo "Run fsstress $args" >>$seqres.full
49 $FSSTRESS_PROG $args >/dev/null 2>&1 &
52 # Start both balance and replace in the background.
53 # Either balance or replace shall run, the other fails.
54 echo -n "Start balance worker: " >>$seqres.full
55 _btrfs_stress_balance $SCRATCH_MNT >/dev/null 2>&1 &
57 echo "$balance_pid" >>$seqres.full
59 echo -n "Start replace worker: " >>$seqres.full
60 _btrfs_stress_replace $SCRATCH_MNT >>$seqres.full 2>&1 &
62 echo "$replace_pid" >>$seqres.full
64 echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
66 kill $balance_pid $replace_pid
68 # wait for the balance and replace operations to finish
69 while ps aux | grep "balance start" | grep -qv grep; do
72 while ps aux | grep "replace start" | grep -qv grep; do
76 echo "Scrub the filesystem" >>$seqres.full
77 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
79 echo "Scrub find errors in \"$mkfs_opts\" test" | tee -a $seqres.full
83 # we called _require_scratch_nocheck instead of _require_scratch
84 # do check after test for each profile config
88 echo "Silence is golden"
89 for t in "${_btrfs_profile_configs[@]}"; do