btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 100
1 #! /bin/bash
2 # FS QA Test No. btrfs/100
3 #
4 # Test device replace works when the source device has EIO
5 #
6 # Copyright (c) 2015 Oracle.  All Rights Reserved.
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it would be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write the Free Software Foundation,
19 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 #
21
22 seq=`basename $0`
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
25
26 here=`pwd`
27 tmp=/tmp/$$
28
29 status=1        # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32
33 _cleanup()
34 {
35         _dmerror_cleanup
36         rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 . ./common/filter.btrfs
43 . ./common/dmerror
44
45 _supported_fs btrfs
46 _supported_os Linux
47 _require_scratch_dev_pool 3
48 _require_dm_target error
49
50 rm -f $seqres.full
51
52 dev1="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}'`"
53 dev2="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}'`"
54
55 _dmerror_init
56 _mkfs_dev "-f -d raid1 -m raid1 $dev1 $DMERROR_DEV"
57 _dmerror_mount
58
59 _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
60 $BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | _filter_btrfs_filesystem_show
61
62 error_devid=`$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT |\
63                         egrep $DMERROR_DEV | $AWK_PROG '{print $2}'`
64
65 snapshot_cmd="$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT"
66 snapshot_cmd="$snapshot_cmd $SCRATCH_MNT/snap_\`date +'%H_%M_%S_%N'\`"
67 run_check $FSSTRESS_PROG -d $SCRATCH_MNT -n 200 -p 8 $FSSTRESS_AVOID -x \
68                                                         "$snapshot_cmd" -X 50
69
70 # now load the error into the DMERROR_DEV
71 _dmerror_load_error_table
72
73 _run_btrfs_util_prog replace start -B $error_devid $dev2 $SCRATCH_MNT
74
75 _run_btrfs_util_prog filesystem show -m $SCRATCH_MNT
76 $BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | _filter_btrfs_filesystem_show
77
78 echo "=== device replace completed"
79
80 status=0; exit