reflink: test CoW with blocksize < pagesize
[xfstests-dev.git] / tests / generic / 222
1 #! /bin/bash
2 # FS QA Test No. 222
3 #
4 # See what happens if we CoW blocks 2-4 of a page's worth of blocks when the
5 # second block is delalloc.
6 #
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.
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
12 #
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.
16 #
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.
21 #
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 #-----------------------------------------------------------------------
26
27 seq=`basename "$0"`
28 seqres="$RESULT_DIR/$seq"
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1    # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -rf "$tmp".* "$TESTDIR"
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/reflink
46
47 # real QA test starts here
48 _supported_os Linux
49 _require_scratch_reflink
50 _require_xfs_io_command "falloc"
51
52 rm -f "$seqres.full"
53
54 PAGESZ=$(getconf PAGE_SIZE)
55 BLKSZ=$((PAGESZ / 4))
56
57 echo "Format and mount"
58 _scratch_mkfs_blocksized $BLKSZ > "$seqres.full" 2>&1
59 _scratch_mount >> "$seqres.full" 2>&1
60
61 TESTDIR="$SCRATCH_MNT/test-$seq"
62 rm -rf $TESTDIR
63 mkdir $TESTDIR
64
65 REAL_BLKSZ=$(stat -f -c '%S' $TESTDIR)
66 test "$REAL_BLKSZ" != "$BLKSZ" && _notrun "Failed to format with small blocksize."
67
68 echo "Create the original files"
69 _pwrite_byte 0x61 0 $PAGESZ "$TESTDIR/file1" >> "$seqres.full"
70
71 "$XFS_IO_PROG" -f -c "truncate $PAGESZ" "$TESTDIR/file2" >> "$seqres.full"
72 "$XFS_IO_PROG" -f -c "truncate $PAGESZ" "$TESTDIR/file2.chk" >> "$seqres.full"
73
74 _reflink_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file2" $((BLKSZ * 2)) $BLKSZ >> "$seqres.full"
75 _pwrite_byte 0x61 $((BLKSZ * 2)) $BLKSZ "$TESTDIR/file2.chk" >> "$seqres.full"
76 _scratch_remount
77
78 echo "Compare files"
79 ! cmp -s "$TESTDIR/file1" "$TESTDIR/file2" || _fail "file1 and file2 don't match."
80 cmp -s "$TESTDIR/file2" "$TESTDIR/file2.chk" || _fail "file2 and file2.chk don't match."
81
82 echo "CoW and unmount"
83 _pwrite_byte 0x61 $BLKSZ $BLKSZ "$TESTDIR/file2" >> "$seqres.full"
84 _pwrite_byte 0x61 $BLKSZ $BLKSZ "$TESTDIR/file2.chk" >> "$seqres.full"
85
86 _pwrite_byte 0x61 $((BLKSZ * 3)) $BLKSZ "$TESTDIR/file2" >> "$seqres.full"
87 _pwrite_byte 0x61 $((BLKSZ * 3)) $BLKSZ "$TESTDIR/file2.chk" >> "$seqres.full"
88
89 "$XFS_IO_PROG" -f -c "pwrite -S 0x63 $((BLKSZ + 17)) $((BLKSZ * 3 - 34))" "$TESTDIR/file2" >> "$seqres.full"
90 "$XFS_IO_PROG" -f -c "pwrite -S 0x63 $((BLKSZ + 17)) $((BLKSZ * 3 - 34))" "$TESTDIR/file2.chk" >> "$seqres.full"
91 _scratch_remount
92
93 echo "Compare files"
94 ! cmp -s "$TESTDIR/file1" "$TESTDIR/file2" || _fail "file1 and file2 don't match."
95 cmp -s "$TESTDIR/file2" "$TESTDIR/file2.chk" || _fail "file2 and file2.chk don't match."
96
97 echo "Check for damage"
98 umount "$SCRATCH_MNT"
99 _check_scratch_fs
100
101 # success, all done
102 status=0
103 exit