common: kill _supported_os
[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 _require_scratch_dev_pool 2
52 _test_unmount
53 _require_btrfs_forget_or_module_loadable
54
55 _scratch_dev_pool_get 2
56
57 dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
58 dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
59
60 dev1_sz=`blockdev --getsize64 $dev1`
61 dev2_sz=`blockdev --getsize64 $dev2`
62 # get min of both
63 max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort -n | head -1`
64 # Need disks with more than 2G.
65 if [ $max_fs_sz -lt 2000000000 ]; then
66         _scratch_dev_pool_put
67         _test_mount
68         _notrun "Smallest dev size $max_fs_sz, Need at least 2G"
69 fi
70 max_fs_sz=1200000000
71 bs="1M"
72 count=$(($max_fs_sz / 1000000))
73
74 echo >> $seqres.full
75 echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
76 echo "-----Initialize -----" >> $seqres.full
77 _scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
78 _scratch_mount >> $seqres.full 2>&1
79 _run_btrfs_util_prog filesystem show
80 dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
81                                         >>$seqres.full 2>&1
82 count=$(( count-- ))
83 echo "unmount" >> $seqres.full
84 echo "clean btrfs ko" >> $seqres.full
85 _scratch_unmount
86
87 # un-scan the btrfs devices
88 _btrfs_forget_or_module_reload
89
90 echo >> $seqres.full
91 echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
92 echo
93 echo "Write data with degraded mount"
94 # Since we didn't run dev scan, btrfs kernel does not know
95 # about the dev2
96 # don't use _scratch_mount as we want to control
97 # the device used for mounting.
98
99 _mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
100 _run_btrfs_util_prog filesystem show
101 dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
102                                         >>$seqres.full 2>&1
103 checkpoint1=`md5sum $SCRATCH_MNT/tf2`
104 echo $checkpoint1 >> $seqres.full 2>&1
105 _scratch_unmount
106 echo "unmount" >> $seqres.full
107
108 echo >> $seqres.full
109 echo "-----Mount normal-----" >> $seqres.full
110 echo
111 echo "Mount normal and balance"
112 _run_btrfs_util_prog device scan
113 _scratch_mount >> $seqres.full 2>&1
114 _run_btrfs_util_prog filesystem show
115 echo >> $seqres.full
116 _run_btrfs_balance_start ${SCRATCH_MNT} >>$seqres.full
117
118 checkpoint2=`md5sum $SCRATCH_MNT/tf2`
119 echo $checkpoint2 >> $seqres.full 2>&1
120
121 echo >> $seqres.full
122 echo "-----Mount degraded with the other dev -----" >> $seqres.full
123 echo
124 echo "Mount degraded with the other dev"
125 _scratch_unmount
126 # un-scan the btrfs devices
127 _btrfs_forget_or_module_reload
128 _mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
129 _run_btrfs_util_prog filesystem show
130 checkpoint3=`md5sum $SCRATCH_MNT/tf2`
131 echo $checkpoint3 >> $seqres.full 2>&1
132
133 if [ "$checkpoint1" != "$checkpoint2" ]; then
134         echo $checkpoint1
135         echo $checkpoint2
136         echo "Inital sum does not match with after balance"
137 fi
138
139 if [ "$checkpoint1" != "$checkpoint3" ]; then
140         echo $checkpoint1
141         echo $checkpoint3
142         echo "Inital sum does not match with data on dev2 written by balance"
143 fi
144
145 $UMOUNT_PROG $dev2
146 _scratch_dev_pool_put
147 _test_mount
148
149 status=0
150 exit