fstests: add module reloading helpers
[xfstests-dev.git] / tests / btrfs / 125
1 #! /bin/bash
2 # FS QA Test 125
3 #
4 # This test verify if the reconstructed data on the RAID5 is good.
5 # Steps:
6 # Initialize RAID5 with some data
7 #
8 # Re-mount RAID5 degraded with dev3 missing and write data
9 # Save md5sum checkpoint1
10 #
11 # Re-mount healthy RAID5
12 #
13 # Let balance fix the RAID5.
14 # Save md5sum checkpoint2
15 #
16 # Re-mount RAID5 degraded with dev1 as missing.
17 # Save md5sum checkpoint3
18 #
19 # Verify if all three checkpoints match
20 #
21 #---------------------------------------------------------------------
22 # Copyright (c) 2016 Oracle.  All Rights Reserved.
23 #
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.
27 #
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.
32 #
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 #---------------------------------------------------------------------
37 #
38
39 seq=`basename $0`
40 seqres=$RESULT_DIR/$seq
41 echo "QA output created by $seq"
42
43 here=`pwd`
44 tmp=/tmp/$$
45 status=1        # failure is the default!
46 trap "_cleanup; exit \$status" 0 1 2 3 15
47
48 _cleanup()
49 {
50         cd /
51         rm -f $tmp.*
52 }
53
54 # get standard environment, filters and checks
55 . ./common/rc
56 . ./common/filter
57 . ./common/module
58
59 # remove previous $seqres.full before test
60 rm -f $seqres.full
61
62 # real QA test starts here
63
64 _supported_fs btrfs
65 _supported_os Linux
66 _require_scratch_dev_pool 3
67 _test_unmount
68 _require_loadable_fs_module "btrfs"
69
70 _scratch_dev_pool_get 3
71
72 dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
73 dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
74 dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
75
76 echo dev1=$dev1 >> $seqres.full
77 echo dev2=$dev2 >> $seqres.full
78 echo dev3=$dev3 >> $seqres.full
79
80 # Balance won't be successful if filled too much
81 dev1_sz=`blockdev --getsize64 $dev1`
82 dev2_sz=`blockdev --getsize64 $dev2`
83 dev3_sz=`blockdev --getsize64 $dev3`
84
85 # get min of both.
86 max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz\n$dev3_sz" | sort | head -1`
87 # Need disks with more than 2G
88 if [ $max_fs_sz -lt 2000000000 ]; then
89         _scratch_dev_pool_put
90         _test_mount
91         _notrun "Smallest dev size $max_fs_sz, Need at least 2G"
92 fi
93 max_fs_sz=100000000
94 bs="1M"
95 count=$(($max_fs_sz / 1000000))
96
97 #-------------normal init-------------------
98 echo >> $seqres.full
99 echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
100 echo "-----Initialize -----" >> $seqres.full
101 _scratch_pool_mkfs "-mraid5 -draid5" >> $seqres.full 2>&1
102 _scratch_mount >> $seqres.full 2>&1
103 dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
104                                         >>$seqres.full 2>&1
105 _run_btrfs_util_prog filesystem show
106 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
107 count=$(( count-- ))
108
109
110 #-------------degraded-init-------------------
111 echo >> $seqres.full
112 echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
113 echo
114 echo "Write data with degraded mount"
115
116 echo "unmount" >> $seqres.full
117 _scratch_unmount
118 echo "clean btrfs ko" >> $seqres.full
119 # un-scan the btrfs devices
120 _reload_fs_module "btrfs"
121 _mount -o degraded,device=$dev2 $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
122 dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
123                                         >>$seqres.full 2>&1
124 _run_btrfs_util_prog filesystem show
125 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
126 checkpoint1=`md5sum $SCRATCH_MNT/tf2`
127 echo $checkpoint1 >> $seqres.full 2>&1
128
129 #-------------balance-------------------
130 echo >> $seqres.full
131 echo "-----Mount normal-----" >> $seqres.full
132 echo
133 echo "Mount normal and balance"
134
135 _scratch_unmount
136 _run_btrfs_util_prog device scan
137 _scratch_mount >> $seqres.full 2>&1
138
139 echo >> $seqres.full
140 _run_btrfs_util_prog balance start ${SCRATCH_MNT}
141
142 _run_btrfs_util_prog filesystem show
143 _run_btrfs_util_prog filesystem df ${SCRATCH_MNT}
144
145 checkpoint2=`md5sum $SCRATCH_MNT/tf2`
146 echo $checkpoint2 >> $seqres.full 2>&1
147
148 #-------------degraded-mount-------------------
149 echo >> $seqres.full
150 echo "-----Mount degraded with dev1 missing-----" >> $seqres.full
151 echo
152 echo "Mount degraded but with other dev"
153
154 _scratch_unmount
155 # un-scan the btrfs devices
156 _reload_fs_module "btrfs"
157
158 _mount -o degraded,device=${dev2} $dev3 $SCRATCH_MNT >>$seqres.full 2>&1
159
160 _run_btrfs_util_prog filesystem show
161 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
162 checkpoint3=`md5sum $SCRATCH_MNT/tf2`
163 echo $checkpoint3 >> $seqres.full 2>&1
164
165 if [ "$checkpoint1" != "$checkpoint2" ]; then
166         echo $checkpoint1
167         echo $checkpoint2
168         echo "Inital sum does not match with after balance"
169 fi
170
171 if [ "$checkpoint1" != "$checkpoint3" ]; then
172         echo $checkpoint1
173         echo $checkpoint3
174         echo "Inital sum does not match with data on dev2 written by balance"
175 fi
176
177 $UMOUNT_PROG $dev2
178 _scratch_dev_pool_put
179 _test_mount
180
181 status=0
182 exit