generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 170
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. 170
6 #
7 # Test for races or FS corruption when DIO writing to a file that's also
8 # the target of a reflink operation.
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_odirect
30
31 echo "Format and mount"
32 _scratch_mkfs > $seqres.full 2>&1
33 _scratch_mount >> $seqres.full 2>&1
34
35 testdir=$SCRATCH_MNT/test-$seq
36 finished_file=/tmp/finished
37 rm -rf $finished_file
38 mkdir $testdir
39
40 loops=1024
41 nr_loops=$((loops - 1))
42 blksz=65536
43
44 echo "Initialize files"
45 echo >> $seqres.full
46 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
47 _pwrite_byte 0x62 0 $((loops * blksz)) $testdir/file2 >> $seqres.full
48 _scratch_cycle_mount
49
50 # Direct I/O overwriter...
51 overwrite() {
52         while [ ! -e $finished_file ]; do
53                 seq $nr_loops -1 0 | while read i; do
54                         _pwrite_byte 0x63 $((i * blksz)) $blksz -d $testdir/file2 >> $seqres.full
55                 done
56         done
57 }
58
59 echo "Reflink and dio write the target"
60 overwrite &
61 seq 1 10 | while read j; do
62         seq 0 $nr_loops | while read i; do
63                 _reflink_range  $testdir/file1 $((i * blksz)) \
64                                 $testdir/file2 $((i * blksz)) $blksz >> $seqres.full
65                 [ $? -ne 0 ] && exit
66         done
67 done
68 touch $finished_file
69 wait
70
71 # success, all done
72 status=0
73 exit