generic/446: make sure all background processes are dead before umount
[xfstests-dev.git] / tests / generic / 446
1 #! /bin/bash
2 # FS QA Test No. 446
3 #
4 # Regression test for commit:
5 # 04197b3 ("xfs: don't BUG() on mixed direct and mapped I/O")
6 #
7 # This case tests a race between a direct I/O read and a
8 # mapped write to a hole in a file.  On xfs filesystem, it
9 # will trigger a BUG_ON().
10 #
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2017 Fujitsu.  All Rights Reserved.
13 # Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27 #-----------------------------------------------------------------------
28
29 seq=`basename $0`
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32
33 here=`pwd`
34 tmp=/tmp/$$
35 status=1    # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 _cleanup()
39 {
40         rm -rf $tmp.*
41 }
42
43 # get standard environment and checks
44 . ./common/rc
45
46 # real QA test starts here
47 _supported_os Linux
48 _require_scratch
49 _require_xfs_io_command "truncate"
50 _require_xfs_io_command "fpunch"
51
52 rm -f $seqres.full
53
54 # format and mount
55 _scratch_mkfs > $seqres.full 2>&1
56 _scratch_mount >> $seqres.full 2>&1
57
58 filesz=$((65536 * 2))
59
60 # create a test file with a hole
61 $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file >> $seqres.full
62
63 # run a background dio read to a hole in a loop
64 for i in `seq 0 999`; do
65         $XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file > /dev/null 2>&1
66 done &
67
68 dread_pid=$!
69
70 # run mapped write to the same hole as dio read
71 # loop until background dio read exits
72 while kill -s 0 $dread_pid >/dev/null 2>&1; do
73         $XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
74                 > /dev/null
75         $XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
76 done
77
78 wait $dread_pid > /dev/null 2>&1
79
80 echo "Silence is golden"
81
82 # check dmesg, filtering out expected XFS warnings about mixed mmap/dio
83 # and umount first in case umount triggers warnings
84 _scratch_unmount
85 if [ "$FSTYP" == "xfs" ]; then
86         _check_dmesg _filter_xfs_dmesg
87 else
88         _check_dmesg
89 fi
90 status=$?
91 exit