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 _begin_fstest auto quick clone punch
22 # Import common functions.
26 # real QA test starts here
29 _require_scratch_reflink
30 _require_xfs_io_command "falloc"
31 _require_xfs_io_command "cowextsize"
32 _require_xfs_io_command "fpunch"
33 _require_xfs_io_command "bmap" "-c"
36 echo "Format and mount"
37 _scratch_mkfs > $seqres.full 2>&1
38 _scratch_mount >> $seqres.full 2>&1
40 testdir=$SCRATCH_MNT/test-$seq
43 echo "Create the original files"
46 filesize=$((blksz * nr))
48 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
49 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
50 $XFS_IO_PROG -f -c "truncate $filesize" $testdir/file3 >> $seqres.full
51 # 0 blocks are reflinked
52 seq 0 5 $nr | while read f; do
53 _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
54 _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
56 # 1 blocks are unwritten
57 seq 1 5 $nr | while read f; do
58 $XFS_IO_PROG -f -c "falloc $((blksz * f)) $blksz" $testdir/file3 >> $seqres.full
59 _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
62 seq 2 5 $nr | while read f; do
63 _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
65 # 3 blocks are regular
66 seq 3 5 $nr | while read f; do
67 _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
68 _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
71 # 4 blocks are delalloc (do later)
72 seq 4 5 $nr | while read f; do
73 _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
74 _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
78 seq 0 10 $((nr/2)) | while read f; do
79 _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3 >> $seqres.full
80 _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3.chk >> $seqres.full
84 md5sum $testdir/file1 | _filter_scratch
85 md5sum $testdir/file3 | _filter_scratch
86 md5sum $testdir/file3.chk | _filter_scratch
89 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
90 echo "Delayed allocation CoW extents:"
91 test $(_xfs_bmapx_find cow $testdir/file3 delalloc) -gt 0 || \
92 echo "Expected to find a delalloc CoW extent"
93 echo "Shared data extents:"
94 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
95 echo "Expected to find a shared data extent"
96 echo "Unwritten data extents:"
97 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
98 echo "Expected to find an unwritten data extent"
99 echo "Hole data extents:"
100 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
101 echo "Expected to find a hole data extent"
102 echo "Regular data extents:"
103 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
104 echo "Expected to find a regular data extent"
108 echo "Dump extents after sync"
109 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
110 echo "Delayed allocation CoW extents:"
111 test $(_xfs_bmapx_find cow $testdir/file3 -v hole ) -gt 0 || \
112 echo "Expected to find a regular CoW extent"
113 echo "Real CoW extents:"
114 test $(_xfs_bmapx_find cow $testdir/file3 delalloc ) -eq 0 || \
115 echo "Expected to find zero delalloc CoW extent"
116 echo "Shared data extents:"
117 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
118 echo "Expected to find a shared data extent"
119 echo "Unwritten data extents:"
120 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
121 echo "Expected to find an unwritten data extent"
122 echo "Hole data extents:"
123 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
124 echo "Expected to find a hole data extent"
125 echo "Regular data extents:"
126 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
127 echo "Expected to find a regular data extent"
132 md5sum $testdir/file1 | _filter_scratch
133 md5sum $testdir/file3 | _filter_scratch
134 md5sum $testdir/file3.chk | _filter_scratch