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