btrfs/124-5: add missing umount for raid5 tests
[xfstests-dev.git] / tests / btrfs / 124
1 #! /bin/bash
2 # FS QA Test 124
3 #
4 # This test verify the RAID1 reconstruction on the reappeared
5 # device. By using the following steps:
6 # Initialize a RAID1 with some data
7 #
8 # Re-mount RAID1 degraded with dev2 missing and write up to
9 # half of the FS capacity.
10 # Save md5sum checkpoint1
11 #
12 # Re-mount healthy RAID1
13 #
14 # Let balance re-silver.
15 # Save md5sum checkpoint2
16 #
17 # Re-mount RAID1 degraded with dev1 missing
18 # Save md5sum checkpoint3
19 #
20 # Verify if all three checkpoints match
21 #
22 #---------------------------------------------------------------------
23 # Copyright (c) 2016 Oracle.  All Rights Reserved.
24 #
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.
28 #
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.
33 #
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 #---------------------------------------------------------------------
38 #
39
40 seq=`basename $0`
41 seqres=$RESULT_DIR/$seq
42 echo "QA output created by $seq"
43
44 here=`pwd`
45 tmp=/tmp/$$
46 status=1        # failure is the default!
47 trap "_cleanup; exit \$status" 0 1 2 3 15
48
49 _cleanup()
50 {
51         cd /
52         rm -f $tmp.*
53 }
54
55 # get standard environment, filters and checks
56 . ./common/rc
57 . ./common/filter
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 2
67
68 # the mounted test dir prevent btrfs unload, we need to unmount
69 _test_unmount
70 _require_btrfs_loadable
71
72 _scratch_dev_pool_get 2
73
74 dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
75 dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
76
77 dev1_sz=`blockdev --getsize64 $dev1`
78 dev2_sz=`blockdev --getsize64 $dev2`
79 # get min of both
80 max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort | head -1`
81 # Need disks with more than 2G.
82 if [ $max_fs_sz -lt 2000000000 ]; then
83         _scratch_dev_pool_put
84         _test_mount
85         _notrun "Smallest dev size $max_fs_sz, Need at least 2G"
86 fi
87 max_fs_sz=1200000000
88 bs="1M"
89 count=$(($max_fs_sz / 1000000))
90
91 echo >> $seqres.full
92 echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
93 echo "-----Initialize -----" >> $seqres.full
94 _scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
95 _scratch_mount >> $seqres.full 2>&1
96 _run_btrfs_util_prog filesystem show
97 dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
98                                         >>$seqres.full 2>&1
99 count=$(( count-- ))
100 echo "unmount" >> $seqres.full
101 echo "clean btrfs ko" >> $seqres.full
102 _scratch_unmount
103
104 # un-scan the btrfs devices
105 _reload_btrfs_ko
106
107 echo >> $seqres.full
108 echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
109 echo
110 echo "Write data with degraded mount"
111 # Since we didn't run dev scan, btrfs kernel does not know
112 # about the dev2
113 # don't use _scratch_mount as we want to control
114 # the device used for mounting.
115
116 _mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
117 _run_btrfs_util_prog filesystem show
118 dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
119                                         >>$seqres.full 2>&1
120 checkpoint1=`md5sum $SCRATCH_MNT/tf2`
121 echo $checkpoint1 >> $seqres.full 2>&1
122 _scratch_unmount
123 echo "unmount" >> $seqres.full
124
125 echo >> $seqres.full
126 echo "-----Mount normal-----" >> $seqres.full
127 echo
128 echo "Mount normal and balance"
129 _run_btrfs_util_prog device scan
130 _scratch_mount >> $seqres.full 2>&1
131 _run_btrfs_util_prog filesystem show
132 echo >> $seqres.full
133 _run_btrfs_util_prog balance start ${SCRATCH_MNT}
134
135 checkpoint2=`md5sum $SCRATCH_MNT/tf2`
136 echo $checkpoint2 >> $seqres.full 2>&1
137
138 echo >> $seqres.full
139 echo "-----Mount degraded with the other dev -----" >> $seqres.full
140 echo
141 echo "Mount degraded with the other dev"
142 _scratch_unmount
143 # un-scan the btrfs devices
144 _reload_btrfs_ko
145 _mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
146 _run_btrfs_util_prog filesystem show
147 checkpoint3=`md5sum $SCRATCH_MNT/tf2`
148 echo $checkpoint3 >> $seqres.full 2>&1
149
150 if [ "$checkpoint1" != "$checkpoint2" ]; then
151         echo $checkpoint1
152         echo $checkpoint2
153         echo "Inital sum does not match with after balance"
154 fi
155
156 if [ "$checkpoint1" != "$checkpoint3" ]; then
157         echo $checkpoint1
158         echo $checkpoint3
159         echo "Inital sum does not match with data on dev2 written by balance"
160 fi
161
162 $UMOUNT_PROG $dev2
163 _scratch_dev_pool_put
164 _test_mount
165
166 status=0
167 exit