4 # This test verify if the reconstructed data on the RAID5 is good.
6 # Initialize RAID5 with some data
8 # Re-mount RAID5 degraded with dev3 missing and write data
9 # Save md5sum checkpoint1
11 # Re-mount healthy RAID5
13 # Let balance fix the RAID5.
14 # Save md5sum checkpoint2
16 # Re-mount RAID5 degraded with dev1 as missing.
17 # Save md5sum checkpoint3
19 # Verify if all three checkpoints match
21 #---------------------------------------------------------------------
22 # Copyright (c) 2016 Oracle. All Rights Reserved.
24 # This program is free software; you can redistribute it and/or
25 # modify it under the terms of the GNU General Public License as
26 # published by the Free Software Foundation.
28 # This program is distributed in the hope that it would be useful,
29 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 # GNU General Public License for more details.
33 # You should have received a copy of the GNU General Public License
34 # along with this program; if not, write the Free Software Foundation,
35 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 #---------------------------------------------------------------------
40 seqres=$RESULT_DIR/$seq
41 echo "QA output created by $seq"
45 status=1 # failure is the default!
46 trap "_cleanup; exit \$status" 0 1 2 3 15
54 # get standard environment, filters and checks
58 # remove previous $seqres.full before test
61 # real QA test starts here
65 _require_scratch_dev_pool 3
67 # we need btrfs to unload, need test dir unmounted
69 _require_btrfs_loadable
71 _scratch_dev_pool_get 3
73 dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
74 dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
75 dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
77 echo dev1=$dev1 >> $seqres.full
78 echo dev2=$dev2 >> $seqres.full
79 echo dev3=$dev3 >> $seqres.full
81 # Balance won't be successful if filled too much
82 dev1_sz=`blockdev --getsize64 $dev1`
83 dev2_sz=`blockdev --getsize64 $dev2`
84 dev3_sz=`blockdev --getsize64 $dev3`
87 max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz\n$dev3_sz" | sort | head -1`
88 # Need disks with more than 2G
89 if [ $max_fs_sz -lt 2000000000 ]; then
92 _notrun "Smallest dev size $max_fs_sz, Need at least 2G"
96 count=$(($max_fs_sz / 1000000))
98 #-------------normal init-------------------
100 echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
101 echo "-----Initialize -----" >> $seqres.full
102 _scratch_pool_mkfs "-mraid5 -draid5" >> $seqres.full 2>&1
103 _scratch_mount >> $seqres.full 2>&1
104 dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
106 _run_btrfs_util_prog filesystem show
107 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
111 #-------------degraded-init-------------------
113 echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
115 echo "Write data with degraded mount"
117 echo "unmount" >> $seqres.full
119 echo "clean btrfs ko" >> $seqres.full
120 # un-scan the btrfs devices
122 _mount -o degraded,device=$dev2 $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
123 dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
125 _run_btrfs_util_prog filesystem show
126 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
127 checkpoint1=`md5sum $SCRATCH_MNT/tf2`
128 echo $checkpoint1 >> $seqres.full 2>&1
130 #-------------balance-------------------
132 echo "-----Mount normal-----" >> $seqres.full
134 echo "Mount normal and balance"
137 _run_btrfs_util_prog device scan
138 _scratch_mount >> $seqres.full 2>&1
141 _run_btrfs_util_prog balance start ${SCRATCH_MNT}
143 _run_btrfs_util_prog filesystem show
144 _run_btrfs_util_prog filesystem df ${SCRATCH_MNT}
146 checkpoint2=`md5sum $SCRATCH_MNT/tf2`
147 echo $checkpoint2 >> $seqres.full 2>&1
149 #-------------degraded-mount-------------------
151 echo "-----Mount degraded with dev1 missing-----" >> $seqres.full
153 echo "Mount degraded but with other dev"
156 # un-scan the btrfs devices
159 _mount -o degraded,device=${dev2} $dev3 $SCRATCH_MNT >>$seqres.full 2>&1
161 _run_btrfs_util_prog filesystem show
162 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
163 checkpoint3=`md5sum $SCRATCH_MNT/tf2`
164 echo $checkpoint3 >> $seqres.full 2>&1
166 if [ "$checkpoint1" != "$checkpoint2" ]; then
169 echo "Inital sum does not match with after balance"
172 if [ "$checkpoint1" != "$checkpoint3" ]; then
175 echo "Inital sum does not match with data on dev2 written by balance"
179 _scratch_dev_pool_put