generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 146
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Jeff Layton <jlayton@redhat.com>
4 #
5 # FS QA Test No. 146
6 #
7 # Open a file several times, write to it, fsync on all fds and make sure that
8 # they all return 0. Change the device to start throwing errors. Write again
9 # on all fds and fsync on all fds. Ensure that we get errors on all of them.
10 # Then fsync on all one last time and verify that all return 0.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick eio
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18     cd /
19     rm -rf $tmp.* $testdir
20     _dmerror_cleanup
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/dmerror
26
27 # real QA test starts here
28 _supported_fs btrfs
29 _require_scratch
30 _require_scratch_dev_pool
31 _require_dm_target error
32 _require_test_program fsync-err
33 _require_test_program dmerror
34
35 # bring up dmerror device
36 _dmerror_init
37
38 # Replace first device with error-test device
39 old_SCRATCH_DEV=$SCRATCH_DEV
40 SCRATCH_DEV_POOL=`echo $SCRATCH_DEV_POOL | perl -pe "s#$SCRATCH_DEV#$DMERROR_DEV#"`
41 SCRATCH_DEV=$DMERROR_DEV
42
43 echo "Format and mount"
44
45 # Build a filesystem with 2 devices that stripes the data across
46 # both devices, but mirrors metadata across both. Then, make one
47 # of the devices fail and test what it does.
48 _scratch_pool_mkfs "-d raid0 -m raid1" > $seqres.full 2>&1
49 _scratch_mount
50
51 # How much do we need to write? We need to hit all of the stripes. btrfs uses a
52 # fixed 64k stripesize, so write enough to hit each one. In the case of
53 # compression, each 128K input data chunk will be compressed to 4K (because of
54 # the characters written are duplicate). Therefore we have to write
55 # (128K * 16) = 2048K to make sure every stripe can be hit.
56 number_of_devices=`echo $SCRATCH_DEV_POOL | wc -w`
57 write_kb=$(($number_of_devices * 2048))
58 _require_fs_space $SCRATCH_MNT $write_kb
59
60 testfile=$SCRATCH_MNT/fsync-err-test
61
62 SCRATCH_DEV=$old_SCRATCH_DEV
63 $here/src/fsync-err -b $(($write_kb * 1024)) -d $here/src/dmerror $testfile
64
65 # success, all done
66 _dmerror_load_working_table
67
68 # fs may be corrupt after this -- attempt to repair it
69 _repair_scratch_fs >> $seqres.full
70
71 # remove dmerror device
72 _dmerror_cleanup
73
74 status=0
75 exit