generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 163
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. 163
6 #
7 # Test for race between dedupe and writing the source file
8 #
9 . ./common/preamble
10 _begin_fstest auto quick clone dedupe
11
12 _register_cleanup "_cleanup" BUS
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17     cd /
18     rm -rf $tmp.* $finished_file
19     wait
20 }
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/reflink
25
26 # real QA test starts here
27 _require_scratch_dedupe
28
29 echo "Format and mount"
30 _scratch_mkfs > $seqres.full 2>&1
31 _scratch_mount >> $seqres.full 2>&1
32
33 testdir=$SCRATCH_MNT/test-$seq
34 finished_file=/tmp/finished
35 rm -rf $finished_file
36 mkdir $testdir
37
38 loops=512
39 nr_loops=$((loops - 1))
40 blksz=65536
41
42 echo "Initialize files"
43 echo >> $seqres.full
44 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
45 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file2 >> $seqres.full
46 _scratch_cycle_mount
47
48 overwrite() {
49         while [ ! -e $finished_file ]; do
50                 seq $nr_loops -1 0 | while read i; do
51                         _pwrite_byte 0x61 $((i * blksz)) $blksz $testdir/file1 >> $seqres.full
52                 done
53         done
54 }
55
56 echo "Dedupe and rewrite the file!"
57 overwrite &
58 for i in `seq 1 2`; do
59         seq $nr_loops -1 0 | while read i; do
60                 _dedupe_range   $testdir/file1 $((i * blksz)) \
61                                 $testdir/file2 $((i * blksz)) $blksz >> $seqres.full
62                 [ $? -ne 0 ] && break
63         done
64 done
65 echo "Finished dedupeing"
66 touch $finished_file
67 wait
68
69 # success, all done
70 status=0
71 exit