generic: test for file fsync after moving it to a new parent directory
[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 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1    # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         rm -rf $tmp.*
26 }
27
28 # get standard environment and checks
29 . ./common/rc
30 . ./common/filter
31
32 # real QA test starts here
33 _supported_os Linux
34 _require_scratch
35 _require_xfs_io_command "truncate"
36 _require_xfs_io_command "fpunch"
37
38 rm -f $seqres.full
39
40 # format and mount
41 _scratch_mkfs > $seqres.full 2>&1
42 _scratch_mount >> $seqres.full 2>&1
43
44 filesz=$((65536 * 2))
45
46 # create a test file with a hole
47 $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file >> $seqres.full
48
49 # run a background dio read to a hole in a loop
50 for i in `seq 0 999`; do
51         $XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file > /dev/null 2>&1
52 done &
53
54 dread_pid=$!
55
56 # run mapped write to the same hole as dio read
57 # loop until background dio read exits
58 while kill -s 0 $dread_pid >/dev/null 2>&1; do
59         $XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
60                 > /dev/null
61         $XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
62 done
63
64 wait $dread_pid > /dev/null 2>&1
65
66 echo "Silence is golden"
67
68 # check dmesg, filtering out expected warnings about mixed mmap/dio
69 # and umount first in case umount triggers warnings
70 _scratch_unmount
71 _check_dmesg _filter_aiodio_dmesg
72
73 status=$?
74 exit