fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 167
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. 167
6 #
7 # Test for races or FS corruption when 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
31 echo "Format and mount"
32 _scratch_mkfs > $seqres.full 2>&1
33 _scratch_mount >> $seqres.full 2>&1
34
35 testdir=$SCRATCH_MNT/test-$seq
36 finished_file=/tmp/finished
37 rm -rf $finished_file
38 mkdir $testdir
39
40 loops=1024
41 nr_loops=$((loops - 1))
42 blksz=65536
43
44 echo "Initialize file"
45 echo >> $seqres.full
46 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
47 _scratch_cycle_mount
48
49 # Snapshot creator...
50 snappy() {
51         n=0
52         while [ ! -e $finished_file ]; do
53                 out="$(_cp_reflink $testdir/file1 $testdir/snap_$n 2>&1)"
54                 res=$?
55                 echo "$out" | grep -q "No space left" && break
56                 test -n "$out" && echo "$out"
57                 test $res -ne 0 && break
58                 n=$((n + 1))
59         done
60 }
61
62 echo "Snapshot a file undergoing buffered rewrite"
63 snappy &
64 seq $nr_loops -1 0 | while read i; do
65         _pwrite_byte 0x63 $((i * blksz)) $blksz $testdir/file1 >> $seqres.full
66 done
67 touch $finished_file
68 wait
69
70 # success, all done
71 status=0
72 exit