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
34 # we check scratch dev after each loop
35 _require_scratch_nocheck
36 _require_scratch_dev_pool 5
37 _require_scratch_dev_pool_equal_size
38 _btrfs_get_profile_configs replace-missing
39 _require_command "$WIPEFS_PROG" wipefs
44 local ndevs=`echo $SCRATCH_DEV_POOL | wc -w`
46 # reserve one for replace target
49 _scratch_dev_pool_get $ndevs
52 echo "Test $mkfs_opts" >>$seqres.full
54 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
55 # make sure we created btrfs with desired options
57 echo "mkfs $mkfs_opts failed"
62 _scratch_mount >>$seqres.full 2>&1
64 local missing_dev=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
65 local missing_dev_id=`$BTRFS_UTIL_PROG filesystem show $SCRATCH_MNT | grep $missing_dev | awk '{print $2}'`
67 # get some data on the filesystem so there's something to replace
68 _ddt of="$SCRATCH_MNT"/file1 bs=1M count=1 >> $seqres.full 2>&1
69 _ddt of="$SCRATCH_MNT"/file2 bs=1M count=2 >> $seqres.full 2>&1
70 _ddt of="$SCRATCH_MNT"/file3 bs=1M count=4 >> $seqres.full 2>&1
72 # nuke a device and remount in degraded mode
74 $WIPEFS_PROG -a "$missing_dev" >>$seqres.full 2>&1
75 _scratch_mount -o degraded >>$seqres.full 2>&1
77 # replace $missing_dev with $replace_dev and scrub it to double-check
78 $BTRFS_UTIL_PROG replace start -B -f -r $missing_dev_id $SPARE_DEV \
79 $SCRATCH_MNT >>$seqres.full 2>&1
81 echo "btrfs replace failed"
87 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
89 echo "btrfs scrub failed"
97 # we called _require_scratch_nocheck instead of _require_scratch
98 # do check after test for each profile config
101 _scratch_dev_pool_put
104 echo "Silence is golden"
105 for t in "${_btrfs_profile_configs[@]}"; do