2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensuring that copy on write in buffered mode works when the CoW
8 # range originally covers multiple extents, some unwritten, some not.
9 # - Set cowextsize hint.
10 # - Create a file with the following repeating sequence of blocks:
16 # - CoW across the halfway mark, starting with the unwritten extent.
17 # - Check that the files are now different where we say they're different.
20 seqres=$RESULT_DIR/$seq
21 echo "QA output created by $seq"
25 status=1 # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
34 # get standard environment, filters and checks
39 # real QA test starts here
42 _require_scratch_reflink
43 _require_xfs_io_command "falloc"
44 _require_xfs_io_command "cowextsize"
45 _require_xfs_io_command "fpunch"
46 _require_xfs_io_command "bmap" "-c"
51 echo "Format and mount"
52 _scratch_mkfs > $seqres.full 2>&1
53 _scratch_mount >> $seqres.full 2>&1
55 testdir=$SCRATCH_MNT/test-$seq
58 echo "Create the original files"
61 filesize=$((blksz * nr))
63 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
64 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
65 $XFS_IO_PROG -f -c "truncate $filesize" $testdir/file3 >> $seqres.full
66 # 0 blocks are reflinked
67 seq 0 5 $nr | while read f; do
68 _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
69 _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
71 # 1 blocks are unwritten
72 seq 1 5 $nr | while read f; do
73 $XFS_IO_PROG -f -c "falloc $((blksz * f)) $blksz" $testdir/file3 >> $seqres.full
74 _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
77 seq 2 5 $nr | while read f; do
78 _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
80 # 3 blocks are regular
81 seq 3 5 $nr | while read f; do
82 _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
83 _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
86 # 4 blocks are delalloc (do later)
87 seq 4 5 $nr | while read f; do
88 _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
89 _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
93 seq 0 10 $((nr/2)) | while read f; do
94 _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3 >> $seqres.full
95 _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3.chk >> $seqres.full
99 md5sum $testdir/file1 | _filter_scratch
100 md5sum $testdir/file3 | _filter_scratch
101 md5sum $testdir/file3.chk | _filter_scratch
104 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
105 echo "Delayed allocation CoW extents:"
106 test $(_xfs_bmapx_find cow $testdir/file3 delalloc) -gt 0 || \
107 echo "Expected to find a delalloc CoW extent"
108 echo "Shared data extents:"
109 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
110 echo "Expected to find a shared data extent"
111 echo "Unwritten data extents:"
112 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
113 echo "Expected to find an unwritten data extent"
114 echo "Hole data extents:"
115 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
116 echo "Expected to find a hole data extent"
117 echo "Regular data extents:"
118 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
119 echo "Expected to find a regular data extent"
123 echo "Dump extents after sync"
124 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
125 echo "Delayed allocation CoW extents:"
126 test $(_xfs_bmapx_find cow $testdir/file3 -v hole ) -gt 0 || \
127 echo "Expected to find a regular CoW extent"
128 echo "Real CoW extents:"
129 test $(_xfs_bmapx_find cow $testdir/file3 delalloc ) -eq 0 || \
130 echo "Expected to find zero delalloc CoW extent"
131 echo "Shared data extents:"
132 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
133 echo "Expected to find a shared data extent"
134 echo "Unwritten data extents:"
135 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
136 echo "Expected to find an unwritten data extent"
137 echo "Hole data extents:"
138 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
139 echo "Expected to find a hole data extent"
140 echo "Regular data extents:"
141 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
142 echo "Expected to find a regular data extent"
147 md5sum $testdir/file1 | _filter_scratch
148 md5sum $testdir/file3 | _filter_scratch
149 md5sum $testdir/file3.chk | _filter_scratch