generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 446
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test No. 446
6 #
7 # Regression test for commit:
8 # 04197b3 ("xfs: don't BUG() on mixed direct and mapped I/O")
9 #
10 # This case tests a race between a direct I/O read and a
11 # mapped write to a hole in a file.  On xfs filesystem, it
12 # will trigger a BUG_ON().
13 #
14 . ./common/preamble
15 _begin_fstest auto quick rw punch
16
17 # get standard environment and checks
18 . ./common/filter
19
20 # real QA test starts here
21 _require_scratch
22 _require_xfs_io_command "truncate"
23 _require_xfs_io_command "fpunch"
24
25 # format and mount
26 _scratch_mkfs > $seqres.full 2>&1
27 _scratch_mount >> $seqres.full 2>&1
28
29 filesz=$((65536 * 2))
30
31 # create a test file with a hole
32 $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file >> $seqres.full
33
34 # run a background dio read to a hole in a loop
35 for i in `seq 0 999`; do
36         $XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file > /dev/null 2>&1
37 done &
38
39 dread_pid=$!
40
41 # run mapped write to the same hole as dio read
42 # loop until background dio read exits
43 while kill -s 0 $dread_pid >/dev/null 2>&1; do
44         $XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
45                 > /dev/null
46         $XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
47 done
48
49 wait $dread_pid > /dev/null 2>&1
50
51 echo "Silence is golden"
52
53 # check dmesg, filtering out expected warnings about mixed mmap/dio
54 # and umount first in case umount triggers warnings
55 _scratch_unmount
56 _check_dmesg _filter_aiodio_dmesg
57
58 status=$?
59 exit