generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 451
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 451
6 #
7 # Test data integrity when mixing buffered reads and asynchronous
8 # direct writes a file.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick rw aio
12
13 # Import common functions.
14
15 # real QA test starts here
16 _supported_fs generic
17 _require_test
18 _require_test_program "feature"
19 _require_aiodio aio-dio-cycle-write
20 _require_command "$TIMEOUT_PROG" timeout
21
22 TESTFILE=$TEST_DIR/tst-aio-dio-cycle-write.$seq
23 FSIZE=655360    # bytes
24
25 # More read processes can help to reproduce the bug easier, so run
26 # 2 ~ 20 readers according to the number of CPUs
27 nr_cpu=`$here/src/feature -o`
28 loops=$((nr_cpu / 2))
29 if [ $loops -lt 2 ]; then
30         loops=2
31 elif [ $loops -gt 20 ]; then
32         loops=20
33 fi
34
35 keep_reading=$tmp.reading
36 touch $keep_reading
37 # buffered reads the file frequently
38 for ((i=0; i<loops; i++)); do
39         while [ -e $keep_reading ]; do
40                 $XFS_IO_PROG -f -c "pread 0 $FSIZE" $TESTFILE >/dev/null 2>&1
41         done &
42         reader_pid="$reader_pid $!"
43 done
44
45 # start an aio writer, which does writing loops internally and check
46 # data integrality.
47 # For reproduce the original bug, keep testing about 30s will be better,
48 # So let the AIO_TEST run as many loops as it can, then kill it in 30s.
49 $TIMEOUT_PROG -s TERM 30s $AIO_TEST -c 999999 -b $FSIZE $TESTFILE >/dev/null
50
51 # Remove $keep_reading file to stop the reader cycle
52 rm -f $keep_reading
53 wait $reader_pid
54
55 echo "Silence is golden"
56
57 status=0
58 exit