2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Oracle. All Rights Reserved.
7 # This test verify the RAID1 reconstruction on the reappeared
8 # device. By using the following steps:
9 # Initialize a RAID1 with some data
11 # Re-mount RAID1 degraded with dev2 missing and write up to
12 # half of the FS capacity.
13 # Save md5sum checkpoint1
15 # Re-mount healthy RAID1
17 # Let balance re-silver.
18 # Save md5sum checkpoint2
20 # Re-mount RAID1 degraded with dev1 missing
21 # Save md5sum checkpoint3
23 # Verify if all three checkpoints match
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
41 # get standard environment, filters and checks
46 # remove previous $seqres.full before test
49 # real QA test starts here
52 _require_scratch_dev_pool 2
54 _require_btrfs_forget_or_module_loadable
56 _scratch_dev_pool_get 2
58 dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
59 dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
61 dev1_sz=`blockdev --getsize64 $dev1`
62 dev2_sz=`blockdev --getsize64 $dev2`
64 max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort -n | head -1`
65 # Need disks with more than 2G.
66 if [ $max_fs_sz -lt 2000000000 ]; then
69 _notrun "Smallest dev size $max_fs_sz, Need at least 2G"
73 count=$(($max_fs_sz / 1000000))
76 echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
77 echo "-----Initialize -----" >> $seqres.full
78 _scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
79 _scratch_mount >> $seqres.full 2>&1
80 _run_btrfs_util_prog filesystem show
81 dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
84 echo "unmount" >> $seqres.full
85 echo "clean btrfs ko" >> $seqres.full
88 # un-scan the btrfs devices
89 _btrfs_forget_or_module_reload
92 echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
94 echo "Write data with degraded mount"
95 # Since we didn't run dev scan, btrfs kernel does not know
97 # don't use _scratch_mount as we want to control
98 # the device used for mounting.
100 _mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
101 _run_btrfs_util_prog filesystem show
102 dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
104 checkpoint1=`md5sum $SCRATCH_MNT/tf2`
105 echo $checkpoint1 >> $seqres.full 2>&1
107 echo "unmount" >> $seqres.full
110 echo "-----Mount normal-----" >> $seqres.full
112 echo "Mount normal and balance"
113 _run_btrfs_util_prog device scan
114 _scratch_mount >> $seqres.full 2>&1
115 _run_btrfs_util_prog filesystem show
117 _run_btrfs_balance_start ${SCRATCH_MNT} >>$seqres.full
119 checkpoint2=`md5sum $SCRATCH_MNT/tf2`
120 echo $checkpoint2 >> $seqres.full 2>&1
123 echo "-----Mount degraded with the other dev -----" >> $seqres.full
125 echo "Mount degraded with the other dev"
127 # un-scan the btrfs devices
128 _btrfs_forget_or_module_reload
129 _mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
130 _run_btrfs_util_prog filesystem show
131 checkpoint3=`md5sum $SCRATCH_MNT/tf2`
132 echo $checkpoint3 >> $seqres.full 2>&1
134 if [ "$checkpoint1" != "$checkpoint2" ]; then
137 echo "Inital sum does not match with after balance"
140 if [ "$checkpoint1" != "$checkpoint3" ]; then
143 echo "Inital sum does not match with data on dev2 written by balance"
147 _scratch_dev_pool_put
148 _btrfs_rescan_devices