generic: Verify the inheritance behavior of FS_XFLAG_DAX flag in various combinations
[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 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
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 _require_odirect
36
37 echo "Format and mount"
38 _scratch_mkfs > $seqres.full 2>&1
39 _scratch_mount >> $seqres.full 2>&1
40
41 testdir=$SCRATCH_MNT/test-$seq
42 finished_file=/tmp/finished
43 do_snapshot=/tmp/snapshot
44 rm -rf $finished_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 #
58 # We rate limit the snapshot creator to one snapshot per full file write.  this
59 # limits the runtime on slow devices, whilst not substantially reducing the the
60 # number of snapshots taken on fast devices.
61 snappy() {
62         n=0
63         while [ ! -e $finished_file ]; do
64                 if [ ! -e $do_snapshot ]; then
65                         sleep 0.01
66                         continue;
67                 fi
68                 out="$(_cp_reflink $testdir/file1 $testdir/snap_$n 2>&1)"
69                 res=$?
70                 echo "$out" | grep -q "No space left" && break
71                 test -n "$out" && echo "$out"
72                 test $res -ne 0 && break
73                 n=$((n + 1))
74                 rm -f $do_snapshot
75         done
76 }
77
78 echo "Snapshot a file undergoing directio rewrite"
79 snappy &
80 seq $nr_loops -1 0 | while read i; do
81         _pwrite_byte 0x63 $((i * blksz)) $blksz -d $testdir/file1 >> $seqres.full
82         touch $do_snapshot
83 done
84 touch $finished_file
85 wait
86
87 # success, all done
88 status=0
89 exit