94c35fe1ede8b4f02c8d881416439d0e83808db2
[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 . ./common/module
59
60 # remove previous $seqres.full before test
61 rm -f $seqres.full
62
63 # real QA test starts here
64
65 _supported_fs btrfs
66 _supported_os Linux
67 _require_scratch_dev_pool 2
68 _test_unmount
69 _require_loadable_fs_module "btrfs"
70
71 _scratch_dev_pool_get 2
72
73 dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
74 dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
75
76 dev1_sz=`blockdev --getsize64 $dev1`
77 dev2_sz=`blockdev --getsize64 $dev2`
78 # get min of both
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
82         _scratch_dev_pool_put
83         _test_mount
84         _notrun "Smallest dev size $max_fs_sz, Need at least 2G"
85 fi
86 max_fs_sz=1200000000
87 bs="1M"
88 count=$(($max_fs_sz / 1000000))
89
90 echo >> $seqres.full
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 \
97                                         >>$seqres.full 2>&1
98 count=$(( count-- ))
99 echo "unmount" >> $seqres.full
100 echo "clean btrfs ko" >> $seqres.full
101 _scratch_unmount
102
103 # un-scan the btrfs devices
104 _reload_fs_module "btrfs"
105
106 echo >> $seqres.full
107 echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
108 echo
109 echo "Write data with degraded mount"
110 # Since we didn't run dev scan, btrfs kernel does not know
111 # about the dev2
112 # don't use _scratch_mount as we want to control
113 # the device used for mounting.
114
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 \
118                                         >>$seqres.full 2>&1
119 checkpoint1=`md5sum $SCRATCH_MNT/tf2`
120 echo $checkpoint1 >> $seqres.full 2>&1
121 _scratch_unmount
122 echo "unmount" >> $seqres.full
123
124 echo >> $seqres.full
125 echo "-----Mount normal-----" >> $seqres.full
126 echo
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
131 echo >> $seqres.full
132 _run_btrfs_balance_start ${SCRATCH_MNT}
133
134 checkpoint2=`md5sum $SCRATCH_MNT/tf2`
135 echo $checkpoint2 >> $seqres.full 2>&1
136
137 echo >> $seqres.full
138 echo "-----Mount degraded with the other dev -----" >> $seqres.full
139 echo
140 echo "Mount degraded with the other dev"
141 _scratch_unmount
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
148
149 if [ "$checkpoint1" != "$checkpoint2" ]; then
150         echo $checkpoint1
151         echo $checkpoint2
152         echo "Inital sum does not match with after balance"
153 fi
154
155 if [ "$checkpoint1" != "$checkpoint3" ]; then
156         echo $checkpoint1
157         echo $checkpoint3
158         echo "Inital sum does not match with data on dev2 written by balance"
159 fi
160
161 $UMOUNT_PROG $dev2
162 _scratch_dev_pool_put
163 _test_mount
164
165 status=0
166 exit