generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 333
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 333
6 #
7 # Test for races or FS corruption when trying to hit ENOSPC while DIO writing
8 # to a file that's also 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 $abort_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_sized $((400 * 1048576)) > $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 abort_file=/tmp/abort
40 rm -rf $abort_file
41 mkdir $testdir
42
43 loops=1024
44 nr_loops=$((loops - 1))
45 blksz=65536
46
47 echo "Initialize file"
48 echo >> $seqres.full
49 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
50 _scratch_cycle_mount
51
52 # Snapshot creator...
53 snappy() {
54         n=0
55         while [ ! -e $finished_file ]; do
56                 out="$(_cp_reflink $testdir/file1 $testdir/snap_$n 2>&1)"
57                 res=$?
58                 echo $out | grep -q "No space left" && break
59                 test -n "$out" && echo $out
60                 test $res -ne 0 && break
61                 n=$((n + 1))
62         done
63         touch $abort_file
64 }
65
66 echo "Snapshot a file undergoing directio rewrite"
67 snappy &
68 seq 1 1000 | while read j; do
69         seq $nr_loops -1 0 | while read i; do
70                 out="$(_pwrite_byte 0x63 $((i * blksz)) $blksz -d $testdir/file1 2>&1)"
71                 echo $out >> $seqres.full
72                 echo $out | grep -q "No space left" && touch $abort_file
73                 echo $out | grep -qi "error" && touch $abort_file
74                 test -e $abort_file && break
75         done
76         test -e $abort_file && break
77 done
78 touch $finished_file
79 wait
80
81 # success, all done
82 status=0
83 exit