2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 Red Hat Inc. All rights reserved.
5 # FSQA Test No. btrfs/070
7 # Run btrfs replace operations and defrag simultaneously with fsstress
8 # running in background.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
29 # real QA test starts here
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
43 local with_compress=$2
44 local saved_scratch_dev_pool=$SCRATCH_DEV_POOL
46 echo "Test $mkfs_opts with $with_compress" >>$seqres.full
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
55 echo "mkfs $mkfs_opts failed"
56 SCRATCH_DEV_POOL=$saved_scratch_dev_pool
59 _scratch_mount >>$seqres.full 2>&1
60 SCRATCH_DEV_POOL=$saved_scratch_dev_pool
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 &
67 echo -n "Start replace worker: " >>$seqres.full
68 _btrfs_stress_replace $SCRATCH_MNT >>$seqres.full 2>&1 &
70 echo "$replace_pid" >>$seqres.full
72 echo -n "Start defrag worker: " >>$seqres.full
73 _btrfs_stress_defrag $SCRATCH_MNT $with_compress >/dev/null 2>&1 &
75 echo "$defrag_pid" >>$seqres.full
77 echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
79 kill $replace_pid $defrag_pid
82 # wait for the defrag and replace operations to finish
83 while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
86 while ps aux | grep "replace start" | grep -qv grep; do
90 echo "Scrub the filesystem" >>$seqres.full
91 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
93 echo "Scrub find errors in \"$mkfs_opts\" test" | tee -a $seqres.full
97 # we called _require_scratch_nocheck instead of _require_scratch
98 # do check after test for each profile config
102 echo "Silence is golden"
103 for t in "${_btrfs_profile_configs[@]}"; do
104 run_test "$t" nocompress
105 run_test "$t" compress