generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 670
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # FS QA Test No. 670
5 #
6 # Test for races or FS corruption between reflink and mmap reading the
7 # target file. (MMAP version of generic/164,165)
8 #
9 . ./common/preamble
10 _begin_fstest auto clone
11
12 _register_cleanup "_cleanup" BUS
13
14 # Import common functions.
15 . ./common/filter
16 . ./common/reflink
17
18 # real QA test starts here
19 _require_scratch_reflink
20 _require_cp_reflink
21
22 echo "Format and mount"
23 _scratch_mkfs > $seqres.full 2>&1
24 _scratch_mount >> $seqres.full 2>&1
25
26 testdir=$SCRATCH_MNT/test-$seq
27 finished_file=/tmp/finished
28 rm -rf $finished_file
29 mkdir $testdir
30
31 loops=512
32 nr_loops=$((loops - 1))
33 blksz=65536
34
35 echo "Initialize files"
36 echo >> $seqres.full
37 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
38 _pwrite_byte 0x62 0 $((loops * blksz)) $testdir/file2 >> $seqres.full
39 _cp_reflink $testdir/file1 $testdir/file3
40 _scratch_cycle_mount
41
42 fbytes() {
43         # Different with generic/164,165, mread copies data from mmapped area
44         # one-byte-at-a-time, which may cause races during reflink_range().
45         # So the result of _mread_range() may be a mix of 61 and 62.
46         egrep -v '((61|62) ){15}(61|62)'
47 }
48
49 reader() {
50         while [ ! -e $finished_file ]; do
51                 _mread_range $testdir/file3 0 $((loops * blksz)) | fbytes
52         done
53 }
54
55 echo "Reflink and mmap reread the files!"
56 reader &
57 for i in `seq 1 2`; do
58         seq $nr_loops -1 0 | while read i; do
59                 _reflink_range  $testdir/file1 $((i * blksz)) \
60                                 $testdir/file3 $((i * blksz)) $blksz >> $seqres.full
61                 [ $? -ne 0 ] && break
62         done
63         seq $nr_loops -1 0 | while read i; do
64                 _reflink_range  $testdir/file2 $((i * blksz)) \
65                                 $testdir/file3 $((i * blksz)) $blksz >> $seqres.full
66                 [ $? -ne 0 ] && break
67         done
68 done
69 echo "Finished reflinking"
70 touch $finished_file
71 wait
72
73 # success, all done
74 status=0
75 exit