2 # SPDX-License-Identifier: GPL-2.0
6 # Test for races or FS corruption between reflink and mmap reading the
7 # target file. (MMAP version of generic/164,165)
10 _begin_fstest auto clone
12 _register_cleanup "_cleanup" BUS
14 # Import common functions.
18 # real QA test starts here
19 _require_scratch_reflink
22 echo "Format and mount"
23 _scratch_mkfs > $seqres.full 2>&1
24 _scratch_mount >> $seqres.full 2>&1
26 testdir=$SCRATCH_MNT/test-$seq
27 finished_file=/tmp/finished
32 nr_loops=$((loops - 1))
35 echo "Initialize files"
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
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)'
50 while [ ! -e $finished_file ]; do
51 _mread_range $testdir/file3 0 $((loops * blksz)) | fbytes
55 echo "Reflink and mmap reread the files!"
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
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
69 echo "Finished reflinking"