generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 229
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 229
6 #
7 # See what happens if we CoW blocks 2-4 of a page's worth of blocks when the
8 # surrounding blocks vary between unwritten/regular/delalloc/hole.
9 #
10 # This test is dependent on the system page size, so we cannot use md5 in
11 # the golden output; we can only compare to a check file.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1    # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24     cd /
25     rm -rf $tmp.* $testdir
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/reflink
32
33 # real QA test starts here
34 _supported_os Linux
35 _require_scratch_reflink
36 _require_xfs_io_command "falloc"
37
38 rm -f $seqres.full
39
40 pagesz=$(getconf PAGE_SIZE)
41 blksz=$((pagesz / 4))
42
43 echo "Format and mount"
44 _scratch_mkfs_blocksized $blksz > $seqres.full 2>&1
45 _scratch_mount >> $seqres.full 2>&1
46
47 testdir=$SCRATCH_MNT/test-$seq
48 mkdir $testdir
49
50 real_blksz=$(_get_file_block_size $testdir)
51 test $real_blksz != $blksz && _notrun "Failed to format with small blocksize."
52
53 runtest() {
54         echo "runtest $1 $2"
55         b2=$1
56         b4=$2
57         dir=$3
58
59         echo "Create the original files"
60         mkdir -p $dir
61         _pwrite_byte 0x61 0 $pagesz $dir/file1 >> $seqres.full
62
63         $XFS_IO_PROG -f -c "truncate $pagesz" $dir/file2 >> $seqres.full
64         $XFS_IO_PROG -f -c "truncate $pagesz" $dir/file2.chk >> $seqres.full
65
66         case $b2 in
67         "regular")
68                 _pwrite_byte 0x61 $blksz $blksz $dir/file2 >> $seqres.full
69                 _pwrite_byte 0x61 $blksz $blksz $dir/file2.chk >> $seqres.full
70                 ;;
71         "unwritten")
72                 $XFS_IO_PROG -f -c "falloc -k $blksz $blksz" $dir/file2 >> $seqres.full
73                 _pwrite_byte 0x00 $blksz $blksz $dir/file2.chk >> $seqres.full
74                 ;;
75         "hole")
76                 ;;
77         esac
78
79
80
81         case $b4 in
82         "regular")
83                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2 >> $seqres.full
84                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
85                 ;;
86         "unwritten")
87                 $XFS_IO_PROG -f -c "falloc -k $((blksz * 3)) $blksz" $dir/file2 >> $seqres.full
88                 _pwrite_byte 0x00 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
89                 ;;
90         "hole")
91                 ;;
92         esac
93
94         _reflink_range $dir/file1 $blksz $dir/file2 $((blksz * 2)) $blksz >> $seqres.full
95         _pwrite_byte 0x61 $((blksz * 2)) $blksz $dir/file2.chk >> $seqres.full
96         _scratch_cycle_mount
97
98         echo "Compare files"
99         ! cmp -s $dir/file1 $dir/file2 || _fail "file1 and file2 don't match."
100         cmp -s $dir/file2 $dir/file2.chk || _fail "file2 and file2.chk don't match."
101
102         echo "CoW and unmount"
103         if [ $b2 = "delalloc" ]; then
104                 _pwrite_byte 0x61 $blksz $blksz $dir/file2 >> $seqres.full
105                 _pwrite_byte 0x61 $blksz $blksz $dir/file2.chk >> $seqres.full
106         fi
107
108         if [ $b4 = "delalloc" ]; then
109                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2 >> $seqres.full
110                 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
111         fi
112
113         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz + 17)) $((blksz * 3 - 34))" $dir/file2 >> $seqres.full
114         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz + 17)) $((blksz * 3 - 34))" $dir/file2.chk >> $seqres.full
115         _scratch_cycle_mount
116
117         echo "Compare files"
118         ! cmp -s $dir/file1 $dir/file2 || _fail "file1 and file2 don't match."
119         cmp -s $dir/file2 $dir/file2.chk || _fail "file2 and file2.chk don't match."
120 }
121
122 runtest regular delalloc "$testdir/r-d"
123 runtest regular unwritten "$testdir/r-u"
124 runtest regular hole "$testdir/r-h"
125 runtest regular regular "$testdir/r-r"
126
127 runtest hole delalloc "$testdir/h-d"
128 runtest hole unwritten "$testdir/h-u"
129 runtest hole hole "$testdir/h-h"
130 runtest hole regular "$testdir/h-r"
131
132 runtest unwritten delalloc "$testdir/u-d"
133 runtest unwritten unwritten "$testdir/u-u"
134 runtest unwritten hole "$testdir/u-h"
135 runtest unwritten regular "$testdir/u-r"
136
137 runtest delalloc delalloc "$testdir/d-d"
138 runtest delalloc unwritten "$testdir/d-u"
139 runtest delalloc hole "$testdir/d-h"
140 runtest delalloc regular "$testdir/d-r"
141
142 # success, all done
143 status=0
144 exit