2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle. All Rights Reserved.
7 # Test for reappearing missing device functionality.
8 # This test will fail without the btrfs kernel patch
9 # [PATCH] btrfs: handle dynamically reappearing missing device
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
31 # remove previous $seqres.full before test
34 # real QA test starts here
38 _require_scratch_dev_pool 2
39 _require_btrfs_forget_or_module_loadable
41 _scratch_dev_pool_get 2
43 DEV1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
44 DEV2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
46 echo DEV1=$DEV1 >> $seqres.full
47 echo DEV2=$DEV2 >> $seqres.full
49 # Balance won't be successful if filled too much
50 DEV1_SZ=`blockdev --getsize64 $DEV1`
51 DEV2_SZ=`blockdev --getsize64 $DEV2`
54 MAX_FS_SZ=`echo -e "$DEV1_SZ\n$DEV2_SZ" | sort -n | head -1`
55 # Need disks with more than 2G
56 if [ $MAX_FS_SZ -lt 2000000000 ]; then
58 _notrun "Smallest dev size $MAX_FS_SZ, Need at least 2G"
63 COUNT=$(($MAX_FS_SZ / 1000000))
70 echo "MAX_FS_SZ=$MAX_FS_SZ COUNT=$COUNT" >> $seqres.full
72 echo "-----setup-----" >> $seqres.full
73 _scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
74 _scratch_mount >> $seqres.full 2>&1
75 dd if=/dev/urandom of="$SCRATCH_MNT"/tf bs=$bs count=1 \
77 _run_btrfs_util_prog filesystem show -m ${SCRATCH_MNT}
78 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
79 COUNT=$(( $COUNT - 1 ))
80 echo "unmount" >> $seqres.full
87 echo "--degraded mount: max_fs_sz $max_fs_sz bytes--" >> $seqres.full
91 echo "clean btrfs ko" >> $seqres.full
92 # un-scan the btrfs devices
93 _btrfs_forget_or_module_reload
94 _mount -o degraded $DEV1 $SCRATCH_MNT >>$seqres.full 2>&1
96 dd if=/dev/urandom of="$SCRATCH_MNT"/tf1 bs=$bs count=$cnt \
98 COUNT=$(( $COUNT - $cnt ))
99 _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
100 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
101 CHECKPOINT1=`md5sum $SCRATCH_MNT/tf1`
102 echo $SCRATCH_MNT/tf1:$CHECKPOINT1 >> $seqres.full
105 scan_missing_dev_and_write()
108 echo "--scan missing $DEV2--" >> $seqres.full
110 echo "scan missing dev and write"
112 _run_btrfs_util_prog device scan $DEV2
116 _run_btrfs_util_prog filesystem show -m ${SCRATCH_MNT}
117 _run_btrfs_util_prog filesystem df ${SCRATCH_MNT}
119 dd if=/dev/urandom of="$SCRATCH_MNT"/tf2 bs=$bs count=$COUNT \
121 CHECKPOINT2=`md5sum $SCRATCH_MNT/tf2`
122 echo $SCRATCH_MNT/tf2:$CHECKPOINT2 >> $seqres.full
128 echo "----- run balance -----" >> $seqres.full
132 _run_btrfs_balance_start -dconvert=raid1 \
133 -mconvert=raid1 $SCRATCH_MNT >> $seqres.full
139 echo "--mount reconstructed dev only and check md5sum--" >> $seqres.full
141 echo "mount reconstructed dev only and check md5sum"
142 echo "unmount" >> $seqres.full
145 _btrfs_forget_or_module_reload
146 _mount -o degraded $DEV2 $SCRATCH_MNT >>$seqres.full 2>&1
147 verify_checkpoint1=`md5sum $SCRATCH_MNT/tf1`
148 verify_checkpoint2=`md5sum $SCRATCH_MNT/tf2`
150 if [ "$verify_checkpoint1" != "$CHECKPOINT1" ]; then
151 echo "checkpoint1 on reappeared disk does not match after balance"
154 if [ "$verify_checkpoint2" != "$CHECKPOINT2" ]; then
155 echo "checkpoint2 on reappeared disk does not match after balance"
161 scan_missing_dev_and_write
166 _scratch_dev_pool_put