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:
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.
16 #-----------------------------------------------------------------------
17 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
34 seqres=$RESULT_DIR/$seq
35 echo "QA output created by $seq"
39 status=1 # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
48 # get standard environment, filters and checks
53 # real QA test starts here
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"
66 echo "Format and mount"
67 _scratch_mkfs > $seqres.full 2>&1
68 _scratch_mount >> $seqres.full 2>&1
70 testdir=$SCRATCH_MNT/test-$seq
73 echo "Create the original files"
76 filesize=$((blksz * nr))
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
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
92 seq 2 5 $nr | while read f; do
93 _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
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
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
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
114 md5sum $testdir/file1 | _filter_scratch
115 md5sum $testdir/file3 | _filter_scratch
116 md5sum $testdir/file3.chk | _filter_scratch
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"
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"
162 md5sum $testdir/file1 | _filter_scratch
163 md5sum $testdir/file3 | _filter_scratch
164 md5sum $testdir/file3.chk | _filter_scratch