xfs/24[356]: checking cow fork bmap requires CONFIG_XFS_DEBUG=y
[xfstests-dev.git] / tests / xfs / 243
1 #! /bin/bash
2 # FS QA Test No. 243
3 #
4 # Ensuring that copy on write in buffered mode works when the CoW
5 # range originally covers multiple extents, some unwritten, some not.
6 #   - Set cowextsize hint.
7 #   - Create a file with the following repeating sequence of blocks:
8 #     1. reflinked
9 #     2. unwritten
10 #     3. hole
11 #     4. regular block
12 #     5. delalloc
13 #   - CoW across the halfway mark, starting with the unwritten extent.
14 #   - Check that the files are now different where we say they're different.
15 #
16 #-----------------------------------------------------------------------
17 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
18 #
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License as
21 # published by the Free Software Foundation.
22 #
23 # This program is distributed in the hope that it would be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write the Free Software Foundation,
30 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
31 #-----------------------------------------------------------------------
32
33 seq=`basename $0`
34 seqres=$RESULT_DIR/$seq
35 echo "QA output created by $seq"
36
37 here=`pwd`
38 tmp=/tmp/$$
39 status=1    # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 _cleanup()
43 {
44     cd /
45     rm -rf $tmp.*
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51 . ./common/reflink
52
53 # real QA test starts here
54 _supported_os Linux
55 _supported_fs xfs
56 _require_xfs_debug
57 _require_scratch_reflink
58 _require_xfs_io_command "falloc"
59 _require_xfs_io_command "cowextsize"
60 _require_xfs_io_command "fpunch"
61 _require_xfs_io_command "bmap" "-c"
62 _require_cp_reflink
63
64 rm -f $seqres.full
65
66 echo "Format and mount"
67 _scratch_mkfs > $seqres.full 2>&1
68 _scratch_mount >> $seqres.full 2>&1
69
70 testdir=$SCRATCH_MNT/test-$seq
71 mkdir $testdir
72
73 echo "Create the original files"
74 blksz=65536
75 nr=64
76 filesize=$((blksz * nr))
77
78 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
79 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
80 $XFS_IO_PROG -f -c "truncate $filesize" $testdir/file3 >> $seqres.full
81 # 0 blocks are reflinked
82 seq 0 5 $nr | while read f; do
83         _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
84         _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
85 done
86 # 1 blocks are unwritten
87 seq 1 5 $nr | while read f; do
88         $XFS_IO_PROG -f -c "falloc $((blksz * f)) $blksz" $testdir/file3 >> $seqres.full
89         _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
90 done
91 # 2 blocks are holes
92 seq 2 5 $nr | while read f; do
93         _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
94 done
95 # 3 blocks are regular
96 seq 3 5 $nr | while read f; do
97         _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
98         _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
99 done
100 sync
101 # 4 blocks are delalloc (do later)
102 seq 4 5 $nr | while read f; do
103         _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
104         _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
105 done
106
107 # 10 blocks are cow'd
108 seq 0 10 $((nr/2)) | while read f; do
109         _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3 >> $seqres.full
110         _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3.chk >> $seqres.full
111 done
112
113 echo "Compare files"
114 md5sum $testdir/file1 | _filter_scratch
115 md5sum $testdir/file3 | _filter_scratch
116 md5sum $testdir/file3.chk | _filter_scratch
117
118 echo "Dump extents"
119 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
120 echo "Delayed allocation CoW extents:"
121 test $(_xfs_bmapx_find cow $testdir/file3 delalloc) -gt 0 || \
122         echo "Expected to find a delalloc CoW extent"
123 echo "Shared data extents:"
124 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
125         echo "Expected to find a shared data extent"
126 echo "Unwritten data extents:"
127 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
128         echo "Expected to find an unwritten data extent"
129 echo "Hole data extents:"
130 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
131         echo "Expected to find a hole data extent"
132 echo "Regular data extents:"
133 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
134         echo "Expected to find a regular data extent"
135
136 sync
137
138 echo "Dump extents after sync"
139 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
140 echo "Delayed allocation CoW extents:"
141 test $(_xfs_bmapx_find cow $testdir/file3 -v hole ) -gt 0 || \
142         echo "Expected to find a regular CoW extent"
143 echo "Real CoW extents:"
144 test $(_xfs_bmapx_find cow $testdir/file3 delalloc ) -eq 0 || \
145         echo "Expected to find zero delalloc CoW extent"
146 echo "Shared data extents:"
147 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
148         echo "Expected to find a shared data extent"
149 echo "Unwritten data extents:"
150 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
151         echo "Expected to find an unwritten data extent"
152 echo "Hole data extents:"
153 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
154         echo "Expected to find a hole data extent"
155 echo "Regular data extents:"
156 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
157         echo "Expected to find a regular data extent"
158
159 _scratch_cycle_mount
160
161 echo "Compare files"
162 md5sum $testdir/file1 | _filter_scratch
163 md5sum $testdir/file3 | _filter_scratch
164 md5sum $testdir/file3.chk | _filter_scratch
165
166 # success, all done
167 status=0
168 exit