btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / generic / 168
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. 168
6 #
7 # Test for races or FS corruption when writing to a file that's also
8 # the target 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 _require_scratch_reflink
33
34 echo "Format and mount"
35 _scratch_mkfs > $seqres.full 2>&1
36 _scratch_mount >> $seqres.full 2>&1
37
38 testdir=$SCRATCH_MNT/test-$seq
39 finished_file=/tmp/finished
40 rm -rf $finished_file
41 mkdir $testdir
42
43 loops=1024
44 nr_loops=$((loops - 1))
45 blksz=65536
46
47 echo "Initialize files"
48 echo >> $seqres.full
49 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
50 _pwrite_byte 0x62 0 $((loops * blksz)) $testdir/file2 >> $seqres.full
51 _scratch_cycle_mount
52
53 # Direct I/O overwriter...
54 overwrite() {
55         while [ ! -e $finished_file ]; do
56                 seq $nr_loops -1 0 | while read i; do
57                         _pwrite_byte 0x63 $((i * blksz)) $blksz $testdir/file2 >> $seqres.full
58                 done
59         done
60 }
61
62 echo "Reflink and write the target"
63 overwrite &
64 seq 1 10 | while read j; do
65         seq 0 $nr_loops | while read i; do
66                 _reflink_range  $testdir/file1 $((i * blksz)) \
67                                 $testdir/file2 $((i * blksz)) $blksz >> $seqres.full
68                 [ $? -ne 0 ] && exit
69         done
70 done
71 touch $finished_file
72 wait
73
74 # success, all done
75 status=0
76 exit