reflink: more CoW tests for reflink and dedupe
[xfstests-dev.git] / tests / generic / 199
1 #! /bin/bash
2 # FS QA Test No. 199
3 #
4 # Ensuring that copy on write in direct-io mode works when the CoW
5 # range originally covers multiple extents, some unwritten, some not.
6 #   - Create a file with the following repeating sequence of blocks:
7 #     1. reflinked
8 #     2. unwritten
9 #     3. hole
10 #     4. regular block
11 #     5. delalloc
12 #   - directio CoW across the halfway mark, starting with the unwritten extent.
13 #   - Check that the files are now different where we say they're different.
14 #
15 #-----------------------------------------------------------------------
16 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
17 #
18 # This program is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License as
20 # published by the Free Software Foundation.
21 #
22 # This program is distributed in the hope that it would be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
26 #
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write the Free Software Foundation,
29 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
30 #-----------------------------------------------------------------------
31
32 seq=`basename "$0"`
33 seqres="$RESULT_DIR/$seq"
34 echo "QA output created by $seq"
35
36 here=`pwd`
37 tmp=/tmp/$$
38 status=1    # failure is the default!
39 trap "_cleanup; exit \$status" 0 1 2 3 15
40
41 _cleanup()
42 {
43     cd /
44     rm -rf "$tmp".* "$TESTDIR"
45 }
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50 . ./common/reflink
51
52 # real QA test starts here
53 _supported_os Linux
54 _require_scratch_reflink
55 _require_xfs_io_command "falloc"
56 _require_xfs_io_command "fpunch"
57 _require_cp_reflink
58
59 rm -f "$seqres.full"
60
61 echo "Format and mount"
62 _scratch_mkfs > "$seqres.full" 2>&1
63 _scratch_mount >> "$seqres.full" 2>&1
64
65 TESTDIR="$SCRATCH_MNT/test-$seq"
66 rm -rf $TESTDIR
67 mkdir $TESTDIR
68
69 echo "Create the original files"
70 BLKSZ=65536
71 NR=64
72 _pwrite_byte 0x61 0 $((BLKSZ * NR)) "$TESTDIR/file1" >> "$seqres.full"
73 $XFS_IO_PROG -f -c "truncate $((BLKSZ * NR))" "$TESTDIR/file3" >> "$seqres.full"
74 # 0 blocks are reflinked
75 seq 0 5 $NR | while read f; do
76         _reflink_range "$TESTDIR/file1" $((BLKSZ * f)) "$TESTDIR/file3" $((BLKSZ * f)) $BLKSZ >> "$seqres.full"
77         _pwrite_byte 0x61 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
78 done
79 sync
80 # 1 blocks are unwritten
81 seq 1 5 $NR | while read f; do
82         $XFS_IO_PROG -f -c "falloc $((BLKSZ * f)) $BLKSZ" "$TESTDIR/file3" >> "$seqres.full"
83         _pwrite_byte 0x00 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
84 done
85 sync
86 # 2 blocks are holes
87 seq 2 5 $NR | while read f; do
88         _pwrite_byte 0x00 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
89 done
90 # 3 blocks are regular
91 seq 3 5 $NR | while read f; do
92         _pwrite_byte 0x71 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
93         _pwrite_byte 0x71 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
94 done
95 sync
96 _scratch_remount
97
98 echo "Compare files"
99 md5sum "$TESTDIR/file1" | _filter_scratch
100 md5sum "$TESTDIR/file3" | _filter_scratch
101 md5sum "$TESTDIR/file3.chk" | _filter_scratch
102
103 echo "directio CoW across the transition"
104 # 4 blocks are delalloc (do later)
105 seq 4 5 $NR | while read f; do
106         _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3" >> "$seqres.full"
107         _pwrite_byte 0x62 $((BLKSZ * f)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
108 done
109 # now cow
110 "$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((BLKSZ * NR / 2)) $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2))" "$TESTDIR/file3" >> "$seqres.full"
111 _pwrite_byte 0x63 $((BLKSZ * NR / 4)) $((BLKSZ * NR / 2)) "$TESTDIR/file3.chk" >> "$seqres.full"
112 _scratch_remount
113
114 echo "Compare files"
115 md5sum "$TESTDIR/file1" | _filter_scratch
116 md5sum "$TESTDIR/file3" | _filter_scratch
117 md5sum "$TESTDIR/file3.chk" | _filter_scratch
118
119 echo "Check for damage"
120 umount "$SCRATCH_MNT"
121 _check_scratch_fs
122
123 # success, all done
124 status=0
125 exit