2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Oracle. All Rights Reserved.
7 # This test verify the RAID1 reconstruction on the reappeared
8 # device. By using the following steps:
9 # Initialize a RAID1 with some data
11 # Re-mount RAID1 degraded with dev2 missing and write up to
12 # half of the FS capacity.
13 # Save md5sum checkpoint1
15 # Re-mount healthy RAID1
17 # Let balance re-silver.
18 # Save md5sum checkpoint2
20 # Re-mount RAID1 degraded with dev1 missing
21 # Save md5sum checkpoint3
23 # Verify if all three checkpoints match
26 _begin_fstest auto replace volume balance
28 # Override the default cleanup function.
36 # Import common functions.
39 # real QA test starts here
42 _require_scratch_dev_pool 2
44 _require_btrfs_forget_or_module_loadable
46 _scratch_dev_pool_get 2
48 dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
49 dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
51 # RAID1 is not supported on zoned btrfs
52 _require_non_zoned_device "$dev1"
53 _require_non_zoned_device "$dev2"
55 dev1_sz=`blockdev --getsize64 $dev1`
56 dev2_sz=`blockdev --getsize64 $dev2`
58 max_fs_sz=`echo -e "$dev1_sz\n$dev2_sz" | sort -n | head -1`
59 # Need disks with more than 2G.
60 if [ $max_fs_sz -lt 2000000000 ]; then
63 _notrun "Smallest dev size $max_fs_sz, Need at least 2G"
67 count=$(($max_fs_sz / 1000000))
70 echo "max_fs_sz=$max_fs_sz count=$count" >> $seqres.full
71 echo "-----Initialize -----" >> $seqres.full
72 _scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
73 _scratch_mount >> $seqres.full 2>&1
74 _run_btrfs_util_prog filesystem show
75 dd if=/dev/zero of="$SCRATCH_MNT"/tf1 bs=$bs count=1 \
78 echo "unmount" >> $seqres.full
79 echo "clean btrfs ko" >> $seqres.full
82 # un-scan the btrfs devices
83 _btrfs_forget_or_module_reload
86 echo "-----Write degraded mount fill upto $max_fs_sz bytes-----" >> $seqres.full
88 echo "Write data with degraded mount"
89 # Since we didn't run dev scan, btrfs kernel does not know
91 # don't use _scratch_mount as we want to control
92 # the device used for mounting.
94 _mount -o degraded $dev1 $SCRATCH_MNT >>$seqres.full 2>&1
95 _run_btrfs_util_prog filesystem show
96 dd if=/dev/zero of="$SCRATCH_MNT"/tf2 bs=$bs count=$count \
98 checkpoint1=`md5sum $SCRATCH_MNT/tf2`
99 echo $checkpoint1 >> $seqres.full 2>&1
101 echo "unmount" >> $seqres.full
104 echo "-----Mount normal-----" >> $seqres.full
106 echo "Mount normal and balance"
107 _run_btrfs_util_prog device scan
108 _scratch_mount >> $seqres.full 2>&1
109 _run_btrfs_util_prog filesystem show
111 _run_btrfs_balance_start ${SCRATCH_MNT} >>$seqres.full
113 checkpoint2=`md5sum $SCRATCH_MNT/tf2`
114 echo $checkpoint2 >> $seqres.full 2>&1
117 echo "-----Mount degraded with the other dev -----" >> $seqres.full
119 echo "Mount degraded with the other dev"
121 # un-scan the btrfs devices
122 _btrfs_forget_or_module_reload
123 _mount -o degraded $dev2 $SCRATCH_MNT >>$seqres.full 2>&1
124 _run_btrfs_util_prog filesystem show
125 checkpoint3=`md5sum $SCRATCH_MNT/tf2`
126 echo $checkpoint3 >> $seqres.full 2>&1
128 if [ "$checkpoint1" != "$checkpoint2" ]; then
131 echo "Inital sum does not match with after balance"
134 if [ "$checkpoint1" != "$checkpoint3" ]; then
137 echo "Inital sum does not match with data on dev2 written by balance"
141 _scratch_dev_pool_put
142 _btrfs_rescan_devices