generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 166
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. 166
6 #
7 # Test for races or FS corruption when DIO writing to a file that's also
8 # the source 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_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 do_snapshot=/tmp/snapshot
39 rm -rf $finished_file
40 mkdir $testdir
41
42 loops=1024
43 nr_loops=$((loops - 1))
44 blksz=65536
45
46 echo "Initialize file"
47 echo >> $seqres.full
48 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
49 _scratch_cycle_mount
50
51 # Snapshot creator...
52 #
53 # We rate limit the snapshot creator to one snapshot per full file write.  this
54 # limits the runtime on slow devices, whilst not substantially reducing the the
55 # number of snapshots taken on fast devices.
56 snappy() {
57         n=0
58         while [ ! -e $finished_file ]; do
59                 if [ ! -e $do_snapshot ]; then
60                         sleep 0.01
61                         continue;
62                 fi
63                 out="$(_cp_reflink $testdir/file1 $testdir/snap_$n 2>&1)"
64                 res=$?
65                 echo "$out" | grep -q "No space left" && break
66                 test -n "$out" && echo "$out"
67                 test $res -ne 0 && break
68                 n=$((n + 1))
69                 rm -f $do_snapshot
70         done
71 }
72
73 echo "Snapshot a file undergoing directio rewrite"
74 snappy &
75 seq $nr_loops -1 0 | while read i; do
76         _pwrite_byte 0x63 $((i * blksz)) $blksz -d $testdir/file1 >> $seqres.full
77         touch $do_snapshot
78 done
79 touch $finished_file
80 wait
81
82 # success, all done
83 status=0
84 exit