generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 165
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 165
6 #
7 # Test for races or FS corruption between reflink and direct I/O reading the
8 # target file.
9 #
10 . ./common/preamble
11 _begin_fstest auto clone
12
13 _register_cleanup "_cleanup" BUS
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18     cd /
19     rm -rf $tmp.* $finished_file
20     wait
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/reflink
26
27 # real QA test starts here
28 _require_scratch_reflink
29 _require_cp_reflink
30 _require_odirect
31
32 echo "Format and mount"
33 _scratch_mkfs > $seqres.full 2>&1
34 _scratch_mount >> $seqres.full 2>&1
35
36 testdir=$SCRATCH_MNT/test-$seq
37 finished_file=/tmp/finished
38 rm -rf $finished_file
39 mkdir $testdir
40
41 loops=512
42 nr_loops=$((loops - 1))
43 blksz=65536
44
45 echo "Initialize files"
46 echo >> $seqres.full
47 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
48 _pwrite_byte 0x62 0 $((loops * blksz)) $testdir/file2 >> $seqres.full
49 _cp_reflink $testdir/file1 $testdir/file3
50 _scratch_cycle_mount
51
52 fbytes() {
53         egrep -v '(61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61|62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62)'
54 }
55
56 reader() {
57         while [ ! -e $finished_file ]; do
58                 _read_range $testdir/file3 0 $((loops * blksz)) -d | fbytes
59         done
60 }
61
62 echo "Reflink and dio reread the files!"
63 reader &
64 for i in `seq 1 2`; do
65         seq $nr_loops -1 0 | while read i; do
66                 _reflink_range  $testdir/file1 $((i * blksz)) \
67                                 $testdir/file3 $((i * blksz)) $blksz >> $seqres.full
68                 [ $? -ne 0 ] && break
69         done
70         seq $nr_loops -1 0 | while read i; do
71                 _reflink_range  $testdir/file2 $((i * blksz)) \
72                                 $testdir/file3 $((i * blksz)) $blksz >> $seqres.full
73                 [ $? -ne 0 ] && break
74         done
75 done
76 echo "Finished reflinking"
77 touch $finished_file
78 wait
79
80 # success, all done
81 status=0
82 exit