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
43 _require_scratch_reflink
44 _require_xfs_io_command "falloc"
45 _require_xfs_io_command "cowextsize"
46 _require_xfs_io_command "fpunch"
47 _require_xfs_io_command "bmap" "-c"
52 echo "Format and mount"
53 _scratch_mkfs > $seqres.full 2>&1
54 _scratch_mount >> $seqres.full 2>&1
56 testdir=$SCRATCH_MNT/test-$seq
59 echo "Create the original files"
62 filesize=$((blksz * nr))
64 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
65 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
66 $XFS_IO_PROG -f -c "truncate $filesize" $testdir/file3 >> $seqres.full
67 # 0 blocks are reflinked
68 seq 0 5 $nr | while read f; do
69 _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
70 _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
72 # 1 blocks are unwritten
73 seq 1 5 $nr | while read f; do
74 $XFS_IO_PROG -f -c "falloc $((blksz * f)) $blksz" $testdir/file3 >> $seqres.full
75 _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
78 seq 2 5 $nr | while read f; do
79 _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
81 # 3 blocks are regular
82 seq 3 5 $nr | while read f; do
83 _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
84 _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
87 # 4 blocks are delalloc (do later)
88 seq 4 5 $nr | while read f; do
89 _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
90 _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
94 seq 0 10 $((nr/2)) | while read f; do
95 _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3 >> $seqres.full
96 _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3.chk >> $seqres.full
100 md5sum $testdir/file1 | _filter_scratch
101 md5sum $testdir/file3 | _filter_scratch
102 md5sum $testdir/file3.chk | _filter_scratch
105 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
106 echo "Delayed allocation CoW extents:"
107 test $(_xfs_bmapx_find cow $testdir/file3 delalloc) -gt 0 || \
108 echo "Expected to find a delalloc CoW extent"
109 echo "Shared data extents:"
110 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
111 echo "Expected to find a shared data extent"
112 echo "Unwritten data extents:"
113 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
114 echo "Expected to find an unwritten data extent"
115 echo "Hole data extents:"
116 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
117 echo "Expected to find a hole data extent"
118 echo "Regular data extents:"
119 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
120 echo "Expected to find a regular data extent"
124 echo "Dump extents after sync"
125 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
126 echo "Delayed allocation CoW extents:"
127 test $(_xfs_bmapx_find cow $testdir/file3 -v hole ) -gt 0 || \
128 echo "Expected to find a regular CoW extent"
129 echo "Real CoW extents:"
130 test $(_xfs_bmapx_find cow $testdir/file3 delalloc ) -eq 0 || \
131 echo "Expected to find zero delalloc CoW extent"
132 echo "Shared data extents:"
133 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
134 echo "Expected to find a shared data extent"
135 echo "Unwritten data extents:"
136 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
137 echo "Expected to find an unwritten data extent"
138 echo "Hole data extents:"
139 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
140 echo "Expected to find a hole data extent"
141 echo "Regular data extents:"
142 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
143 echo "Expected to find a regular data extent"
148 md5sum $testdir/file1 | _filter_scratch
149 md5sum $testdir/file3 | _filter_scratch
150 md5sum $testdir/file3.chk | _filter_scratch