2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Facebook. All Rights Reserved.
7 # Test replace of a missing device on various data and metadata profiles.
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
28 # remove previous $seqres.full before test
31 # real QA test starts here
35 # we check scratch dev after each loop
36 _require_scratch_nocheck
37 _require_scratch_dev_pool 5
38 _require_scratch_dev_pool_equal_size
39 _btrfs_get_profile_configs replace-missing
40 _require_command "$WIPEFS_PROG" wipefs
45 local ndevs=`echo $SCRATCH_DEV_POOL | wc -w`
47 # reserve one for replace target
50 _scratch_dev_pool_get $ndevs
53 echo "Test $mkfs_opts" >>$seqres.full
55 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
56 # make sure we created btrfs with desired options
58 echo "mkfs $mkfs_opts failed"
63 _scratch_mount >>$seqres.full 2>&1
65 local missing_dev=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
66 local missing_dev_id=`$BTRFS_UTIL_PROG filesystem show $SCRATCH_MNT | grep $missing_dev | awk '{print $2}'`
68 # get some data on the filesystem so there's something to replace
69 _ddt of="$SCRATCH_MNT"/file1 bs=1M count=1 >> $seqres.full 2>&1
70 _ddt of="$SCRATCH_MNT"/file2 bs=1M count=2 >> $seqres.full 2>&1
71 _ddt of="$SCRATCH_MNT"/file3 bs=1M count=4 >> $seqres.full 2>&1
73 # nuke a device and remount in degraded mode
75 $WIPEFS_PROG -a "$missing_dev" >>$seqres.full 2>&1
76 _scratch_mount -o degraded >>$seqres.full 2>&1
78 # replace $missing_dev with $replace_dev and scrub it to double-check
79 $BTRFS_UTIL_PROG replace start -B -f -r $missing_dev_id $SPARE_DEV \
80 $SCRATCH_MNT >>$seqres.full 2>&1
82 echo "btrfs replace failed"
88 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
90 echo "btrfs scrub failed"
98 # we called _require_scratch_nocheck instead of _require_scratch
99 # do check after test for each profile config
102 _scratch_dev_pool_put
105 echo "Silence is golden"
106 for t in "${_btrfs_profile_configs[@]}"; do