4 # Test for reappearing missing device functionality.
5 # This test will fail without the btrfs kernel patch
6 # [PATCH] btrfs: handle dynamically reappearing missing device
8 #---------------------------------------------------------------------
9 # Copyright (c) 2017 Oracle. All Rights Reserved.
10 # Author: Anand Jain <anand.jain@oracle.com>
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #---------------------------------------------------------------------
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
33 status=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
42 # get standard environment, filters and checks
47 # remove previous $seqres.full before test
50 # real QA test starts here
54 _require_scratch_dev_pool 2
55 _require_loadable_fs_module "btrfs"
57 _scratch_dev_pool_get 2
59 DEV1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
60 DEV2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
62 echo DEV1=$DEV1 >> $seqres.full
63 echo DEV2=$DEV2 >> $seqres.full
65 # Balance won't be successful if filled too much
66 DEV1_SZ=`blockdev --getsize64 $DEV1`
67 DEV2_SZ=`blockdev --getsize64 $DEV2`
70 MAX_FS_SZ=`echo -e "$DEV1_SZ\n$DEV2_SZ" | sort | head -1`
71 # Need disks with more than 2G
72 if [ $MAX_FS_SZ -lt 2000000000 ]; then
74 _notrun "Smallest dev size $MAX_FS_SZ, Need at least 2G"
79 COUNT=$(($MAX_FS_SZ / 1000000))
86 echo "MAX_FS_SZ=$MAX_FS_SZ COUNT=$COUNT" >> $seqres.full
88 echo "-----setup-----" >> $seqres.full
89 _scratch_pool_mkfs "-mraid1 -draid1" >> $seqres.full 2>&1
90 _scratch_mount >> $seqres.full 2>&1
91 dd if=/dev/urandom of="$SCRATCH_MNT"/tf bs=$bs count=1 \
93 _run_btrfs_util_prog filesystem show -m ${SCRATCH_MNT}
94 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
95 COUNT=$(( $COUNT - 1 ))
96 echo "unmount" >> $seqres.full
100 degrade_mount_write()
103 echo "--degraded mount: max_fs_sz $max_fs_sz bytes--" >> $seqres.full
105 echo "degraded mount"
107 echo "clean btrfs ko" >> $seqres.full
108 # un-scan the btrfs devices
109 _reload_fs_module "btrfs"
110 _mount -o degraded $DEV1 $SCRATCH_MNT >>$seqres.full 2>&1
112 dd if=/dev/urandom of="$SCRATCH_MNT"/tf1 bs=$bs count=$cnt \
114 COUNT=$(( $COUNT - $cnt ))
115 _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
116 _run_btrfs_util_prog filesystem df $SCRATCH_MNT
117 CHECKPOINT1=`md5sum $SCRATCH_MNT/tf1`
118 echo $SCRATCH_MNT/tf1:$CHECKPOINT1 >> $seqres.full
121 scan_missing_dev_and_write()
124 echo "--scan missing $DEV2--" >> $seqres.full
126 echo "scan missing dev and write"
128 _run_btrfs_util_prog device scan $DEV2
132 _run_btrfs_util_prog filesystem show -m ${SCRATCH_MNT}
133 _run_btrfs_util_prog filesystem df ${SCRATCH_MNT}
135 dd if=/dev/urandom of="$SCRATCH_MNT"/tf2 bs=$bs count=$COUNT \
137 CHECKPOINT2=`md5sum $SCRATCH_MNT/tf2`
138 echo $SCRATCH_MNT/tf2:$CHECKPOINT2 >> $seqres.full
144 echo "----- run balance -----" >> $seqres.full
148 _run_btrfs_util_prog balance start --full-balance -dconvert=raid1 \
149 -mconvert=raid1 ${SCRATCH_MNT}
155 echo "--mount reconstructed dev only and check md5sum--" >> $seqres.full
157 echo "mount reconstructed dev only and check md5sum"
158 echo "unmount" >> $seqres.full
161 _reload_fs_module "btrfs"
162 _mount -o degraded $DEV2 $SCRATCH_MNT >>$seqres.full 2>&1
163 verify_checkpoint1=`md5sum $SCRATCH_MNT/tf1`
164 verify_checkpoint2=`md5sum $SCRATCH_MNT/tf2`
166 if [ "$verify_checkpoint1" != "$CHECKPOINT1" ]; then
167 echo "checkpoint1 on reappeared disk does not match after balance"
170 if [ "$verify_checkpoint2" != "$CHECKPOINT2" ]; then
171 echo "checkpoint2 on reappeared disk does not match after balance"
177 scan_missing_dev_and_write
182 _scratch_dev_pool_put