4 # See what happens if we CoW blocks 2-4 of a page's worth of blocks when the
5 # surrounding blocks vary between unwritten/regular/delalloc/hole.
7 # This test is dependent on the system page size, so we cannot use md5 in
8 # the golden output; we can only compare to a check file.
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #-----------------------------------------------------------------------
28 seqres="$RESULT_DIR/$seq"
29 echo "QA output created by $seq"
33 status=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
39 rm -rf "$tmp".* "$TESTDIR"
42 # get standard environment, filters and checks
47 # real QA test starts here
49 _require_scratch_reflink
50 _require_xfs_io_command "falloc"
54 PAGESZ=$(getconf PAGE_SIZE)
57 echo "Format and mount"
58 _scratch_mkfs_blocksized $BLKSZ > "$seqres.full" 2>&1
59 _scratch_mount >> "$seqres.full" 2>&1
61 TESTDIR="$SCRATCH_MNT/test-$seq"
65 REAL_BLKSZ=$(stat -f -c '%S' $TESTDIR)
66 test "$REAL_BLKSZ" != "$BLKSZ" && _notrun "Failed to format with small blocksize."
74 echo "Create the original files"
76 _pwrite_byte 0x61 0 $PAGESZ "$dir/file1" >> "$seqres.full"
78 "$XFS_IO_PROG" -f -c "truncate $PAGESZ" "$dir/file2" >> "$seqres.full"
79 "$XFS_IO_PROG" -f -c "truncate $PAGESZ" "$dir/file2.chk" >> "$seqres.full"
83 _pwrite_byte 0x61 $BLKSZ $BLKSZ "$dir/file2" >> "$seqres.full"
84 _pwrite_byte 0x61 $BLKSZ $BLKSZ "$dir/file2.chk" >> "$seqres.full"
87 "$XFS_IO_PROG" -f -c "falloc -k $BLKSZ $BLKSZ" "$dir/file2" >> "$seqres.full"
88 _pwrite_byte 0x00 $BLKSZ $BLKSZ "$dir/file2.chk" >> "$seqres.full"
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 "falloc -k $((BLKSZ * 3)) $BLKSZ" "$dir/file2" >> "$seqres.full"
103 _pwrite_byte 0x00 $((BLKSZ * 3)) $BLKSZ "$dir/file2.chk" >> "$seqres.full"
109 _reflink_range "$dir/file1" $BLKSZ "$dir/file2" $((BLKSZ * 2)) $BLKSZ >> "$seqres.full"
110 _pwrite_byte 0x61 $((BLKSZ * 2)) $BLKSZ "$dir/file2.chk" >> "$seqres.full"
114 ! cmp -s "$dir/file1" "$dir/file2" || _fail "file1 and file2 don't match."
115 cmp -s "$dir/file2" "$dir/file2.chk" || _fail "file2 and file2.chk don't match."
117 echo "CoW and unmount"
118 if [ "$b2" = "delalloc" ]; then
119 _pwrite_byte 0x61 $BLKSZ $BLKSZ "$dir/file2" >> "$seqres.full"
120 _pwrite_byte 0x61 $BLKSZ $BLKSZ "$dir/file2.chk" >> "$seqres.full"
123 if [ "$b4" = "delalloc" ]; then
124 _pwrite_byte 0x61 $((BLKSZ * 3)) $BLKSZ "$dir/file2" >> "$seqres.full"
125 _pwrite_byte 0x61 $((BLKSZ * 3)) $BLKSZ "$dir/file2.chk" >> "$seqres.full"
128 "$XFS_IO_PROG" -f -c "pwrite -S 0x63 $((BLKSZ + 17)) $((BLKSZ * 3 - 34))" "$dir/file2" >> "$seqres.full"
129 "$XFS_IO_PROG" -f -c "pwrite -S 0x63 $((BLKSZ + 17)) $((BLKSZ * 3 - 34))" "$dir/file2.chk" >> "$seqres.full"
133 ! cmp -s "$dir/file1" "$dir/file2" || _fail "file1 and file2 don't match."
134 cmp -s "$dir/file2" "$dir/file2.chk" || _fail "file2 and file2.chk don't match."
137 runtest regular delalloc "$TESTDIR/r-d"
138 runtest regular unwritten "$TESTDIR/r-u"
139 runtest regular hole "$TESTDIR/r-h"
140 runtest regular regular "$TESTDIR/r-r"
142 runtest hole delalloc "$TESTDIR/h-d"
143 runtest hole unwritten "$TESTDIR/h-u"
144 runtest hole hole "$TESTDIR/h-h"
145 runtest hole regular "$TESTDIR/h-r"
147 runtest unwritten delalloc "$TESTDIR/u-d"
148 runtest unwritten unwritten "$TESTDIR/u-u"
149 runtest unwritten hole "$TESTDIR/u-h"
150 runtest unwritten regular "$TESTDIR/u-r"
152 runtest delalloc delalloc "$TESTDIR/d-d"
153 runtest delalloc unwritten "$TESTDIR/d-u"
154 runtest delalloc hole "$TESTDIR/d-h"
155 runtest delalloc regular "$TESTDIR/d-r"
157 echo "Check for damage"
158 umount "$SCRATCH_MNT"