2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
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.
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.
14 _begin_fstest auto quick clone
16 # Override the default cleanup function.
20 rm -rf $tmp.* $testdir
23 # Import common functions.
27 # real QA test starts here
28 _require_scratch_reflink
29 _require_xfs_io_command "falloc"
31 pagesz=$(getconf PAGE_SIZE)
34 echo "Format and mount"
35 _scratch_mkfs_blocksized $blksz > $seqres.full 2>&1
36 _scratch_mount >> $seqres.full 2>&1
38 testdir=$SCRATCH_MNT/test-$seq
41 real_blksz=$(_get_file_block_size $testdir)
42 test $real_blksz != $blksz && _notrun "Failed to format with small blocksize."
50 echo "Create the original files"
52 _pwrite_byte 0x61 0 $pagesz $dir/file1 >> $seqres.full
54 $XFS_IO_PROG -f -c "truncate $pagesz" $dir/file2 >> $seqres.full
55 $XFS_IO_PROG -f -c "truncate $pagesz" $dir/file2.chk >> $seqres.full
59 _pwrite_byte 0x61 $blksz $blksz $dir/file2 >> $seqres.full
60 _pwrite_byte 0x61 $blksz $blksz $dir/file2.chk >> $seqres.full
63 $XFS_IO_PROG -f -c "falloc -k $blksz $blksz" $dir/file2 >> $seqres.full
64 _pwrite_byte 0x00 $blksz $blksz $dir/file2.chk >> $seqres.full
72 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2 >> $seqres.full
73 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
76 $XFS_IO_PROG -f -c "falloc -k $((blksz * 3)) $blksz" $dir/file2 >> $seqres.full
77 _pwrite_byte 0x00 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
83 _reflink_range $dir/file1 $blksz $dir/file2 $((blksz * 2)) $blksz >> $seqres.full
84 _pwrite_byte 0x61 $((blksz * 2)) $blksz $dir/file2.chk >> $seqres.full
88 ! cmp -s $dir/file1 $dir/file2 || _fail "file1 and file2 don't match."
89 cmp -s $dir/file2 $dir/file2.chk || _fail "file2 and file2.chk don't match."
91 echo "CoW and unmount"
92 if [ $b2 = "delalloc" ]; then
93 _pwrite_byte 0x61 $blksz $blksz $dir/file2 >> $seqres.full
94 _pwrite_byte 0x61 $blksz $blksz $dir/file2.chk >> $seqres.full
97 if [ $b4 = "delalloc" ]; then
98 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2 >> $seqres.full
99 _pwrite_byte 0x61 $((blksz * 3)) $blksz $dir/file2.chk >> $seqres.full
102 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz + 17)) $((blksz * 3 - 34))" $dir/file2 >> $seqres.full
103 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz + 17)) $((blksz * 3 - 34))" $dir/file2.chk >> $seqres.full
107 ! cmp -s $dir/file1 $dir/file2 || _fail "file1 and file2 don't match."
108 cmp -s $dir/file2 $dir/file2.chk || _fail "file2 and file2.chk don't match."
111 runtest regular delalloc "$testdir/r-d"
112 runtest regular unwritten "$testdir/r-u"
113 runtest regular hole "$testdir/r-h"
114 runtest regular regular "$testdir/r-r"
116 runtest hole delalloc "$testdir/h-d"
117 runtest hole unwritten "$testdir/h-u"
118 runtest hole hole "$testdir/h-h"
119 runtest hole regular "$testdir/h-r"
121 runtest unwritten delalloc "$testdir/u-d"
122 runtest unwritten unwritten "$testdir/u-u"
123 runtest unwritten hole "$testdir/u-h"
124 runtest unwritten regular "$testdir/u-r"
126 runtest delalloc delalloc "$testdir/d-d"
127 runtest delalloc unwritten "$testdir/d-u"
128 runtest delalloc hole "$testdir/d-h"
129 runtest delalloc regular "$testdir/d-r"