4 # This test verify the RAID1 reconstruction on the reappeared
5 # device. By using the following steps:
6 # Initialize a RAID1 with some data
8 # Re-mount RAID1 degraded with dev2 missing and write up to
9 # half of the FS capacity.
10 # Save md5sum checkpoint1
12 # Re-mount healthy RAID1
14 # Let balance re-silver.
15 # Save md5sum checkpoint2
17 # Re-mount RAID1 degraded with dev1 missing
18 # Save md5sum checkpoint3
20 # Verify if all three checkpoints match
22 #---------------------------------------------------------------------
23 # Copyright (c) 2016 Oracle. All Rights Reserved.
25 # This program is free software; you can redistribute it and/or
26 # modify it under the terms of the GNU General Public License as
27 # published by the Free Software Foundation.
29 # This program is distributed in the hope that it would be useful,
30 # but WITHOUT ANY WARRANTY; without even the implied warranty of
31 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 # GNU General Public License for more details.
34 # You should have received a copy of the GNU General Public License
35 # along with this program; if not, write the Free Software Foundation,
36 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37 #---------------------------------------------------------------------
41 seqres=$RESULT_DIR/$seq
42 echo "QA output created by $seq"
46 status=1 # failure is the default!
47 trap "_cleanup; exit \$status" 0 1 2 3 15
55 # get standard environment, filters and checks
60 # remove previous $seqres.full before test
63 # real QA test starts here
67 _require_scratch_dev_pool 2
69 _require_loadable_fs_module "btrfs"
71 _scratch_dev_pool_get 2
73 dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
74 dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
76 dev1_sz=`blockdev --getsize64 $dev1`
77 dev2_sz=`blockdev --getsize64 $dev2`
79 max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
80 # Need disks with more than 2G.
81 if [ $max_fs_sz -lt 2000000000 ]; then
84 _notrun "Smallest dev size $max_fs_sz, Need at least 2G"
88 count=$(($max_fs_sz / 1000000))
91 echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
92 echo "-----Initialize -----" >> $seqres.full
93 _scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
94 _scratch_mount >> $seqres.full 2>&1
95 _run_btrfs_util_prog filesystem show
96 dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
99 echo "unmount" >> $seqres.full
100 echo "clean btrfs ko" >> $seqres.full
103 # un-scan the btrfs devices
104 _reload_fs_module "btrfs"
107 echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
109 echo "Write data with degraded mount"
110 # Since we didn't run dev scan, btrfs kernel does not know
112 # don't use _scratch_mount as we want to control
113 # the device used for mounting.
115 _mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
116 _run_btrfs_util_prog filesystem show
117 dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
119 checkpoint1=`md5sum $SCRATCH_MNT/tf2`
120 echo $checkpoint1 >> $seqres.full 2>&1
122 echo "unmount" >> $seqres.full
125 echo "-----Mount normal-----" >> $seqres.full
127 echo "Mount normal and balance"
128 _run_btrfs_util_prog device scan
129 _scratch_mount >> $seqres.full 2>&1
130 _run_btrfs_util_prog filesystem show
132 _run_btrfs_balance_start ${SCRATCH_MNT}
134 checkpoint2=`md5sum $SCRATCH_MNT/tf2`
135 echo $checkpoint2 >> $seqres.full 2>&1
138 echo "-----Mount degraded with the other dev -----" >> $seqres.full
140 echo "Mount degraded with the other dev"
142 # un-scan the btrfs devices
143 _reload_fs_module "btrfs"
144 _mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
145 _run_btrfs_util_prog filesystem show
146 checkpoint3=`md5sum $SCRATCH_MNT/tf2`
147 echo $checkpoint3 >> $seqres.full 2>&1
149 if [ "$checkpoint1" != "$checkpoint2" ]; then
152 echo "Inital sum does not match with after balance"
155 if [ "$checkpoint1" != "$checkpoint3" ]; then
158 echo "Inital sum does not match with data on dev2 written by balance"
162 _scratch_dev_pool_put