generic: test deadlock on O_DIRECT|O_DSYNC
[xfstests-dev.git] / tests / generic / 334
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. 334
6 #
7 # Test for races or FS corruption when trying to hit ENOSPC while writing
8 # to a file that's also the source of a reflink operation.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 7 15
18
19 _cleanup()
20 {
21     cd /
22     rm -rf $tmp.* $finished_file $abort_file
23     wait
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30
31 # real QA test starts here
32 _supported_os Linux
33 _require_scratch_reflink
34 _require_cp_reflink
35
36 echo "Format and mount"
37 _scratch_mkfs_sized $((400 * 1048576)) > $seqres.full 2>&1
38 _scratch_mount >> $seqres.full 2>&1
39
40 testdir=$SCRATCH_MNT/test-$seq
41 finished_file=/tmp/finished
42 rm -rf $finished_file
43 abort_file=/tmp/abort
44 rm -rf $abort_file
45 mkdir $testdir
46
47 loops=1024
48 nr_loops=$((loops - 1))
49 blksz=65536
50
51 echo "Initialize file"
52 echo >> $seqres.full
53 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
54 _scratch_cycle_mount
55
56 # Snapshot creator...
57 snappy() {
58         n=0
59         while [ ! -e $finished_file ]; do
60                 out="$(_cp_reflink $testdir/file1 $testdir/snap_$n 2>&1)"
61                 res=$?
62                 echo $out | grep -q "No space left" && break
63                 test -n "$out" && echo $out
64                 test $res -ne 0 && break
65                 n=$((n + 1))
66         done
67         touch $abort_file
68 }
69
70 echo "Snapshot a file undergoing buffered rewrite"
71 snappy &
72 seq 1 1000 | while read j; do
73         seq $nr_loops -1 0 | while read i; do
74                 out="$(_pwrite_byte 0x63 $((i * blksz)) $blksz $testdir/file1 2>&1)"
75                 echo $out >> $seqres.full
76                 echo $out | grep -q "No space left" && touch $abort_file
77                 echo $out | grep -qi "error" && touch $abort_file
78                 test -e $abort_file && break
79         done
80         test -e $abort_file && break
81 done
82 touch $finished_file
83 wait
84
85 # success, all done
86 status=0
87 exit