fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 243
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 243
6 #
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:
11 #     1. reflinked
12 #     2. unwritten
13 #     3. hole
14 #     4. regular block
15 #     5. delalloc
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.
18 #
19 seq=`basename $0`
20 seqres=$RESULT_DIR/$seq
21 echo "QA output created by $seq"
22
23 here=`pwd`
24 tmp=/tmp/$$
25 status=1    # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
27
28 _cleanup()
29 {
30     cd /
31     rm -rf $tmp.*
32 }
33
34 # get standard environment, filters and checks
35 . ./common/rc
36 . ./common/filter
37 . ./common/reflink
38
39 # real QA test starts here
40 _supported_os Linux
41 _supported_fs xfs
42 _require_xfs_debug
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"
48 _require_cp_reflink
49
50 rm -f $seqres.full
51
52 echo "Format and mount"
53 _scratch_mkfs > $seqres.full 2>&1
54 _scratch_mount >> $seqres.full 2>&1
55
56 testdir=$SCRATCH_MNT/test-$seq
57 mkdir $testdir
58
59 echo "Create the original files"
60 blksz=65536
61 nr=64
62 filesize=$((blksz * nr))
63
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
71 done
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
76 done
77 # 2 blocks are holes
78 seq 2 5 $nr | while read f; do
79         _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
80 done
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
85 done
86 sync
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
91 done
92
93 # 10 blocks are cow'd
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
97 done
98
99 echo "Compare files"
100 md5sum $testdir/file1 | _filter_scratch
101 md5sum $testdir/file3 | _filter_scratch
102 md5sum $testdir/file3.chk | _filter_scratch
103
104 echo "Dump extents"
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"
121
122 sync
123
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"
144
145 _scratch_cycle_mount
146
147 echo "Compare files"
148 md5sum $testdir/file1 | _filter_scratch
149 md5sum $testdir/file3 | _filter_scratch
150 md5sum $testdir/file3.chk | _filter_scratch
151
152 # success, all done
153 status=0
154 exit