btrfs/012: check free size of scratch device before copying files
[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_fs xfs
41 _require_xfs_debug
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"
47 _require_cp_reflink
48
49 rm -f $seqres.full
50
51 echo "Format and mount"
52 _scratch_mkfs > $seqres.full 2>&1
53 _scratch_mount >> $seqres.full 2>&1
54
55 testdir=$SCRATCH_MNT/test-$seq
56 mkdir $testdir
57
58 echo "Create the original files"
59 blksz=65536
60 nr=64
61 filesize=$((blksz * nr))
62
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
70 done
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
75 done
76 # 2 blocks are holes
77 seq 2 5 $nr | while read f; do
78         _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
79 done
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
84 done
85 sync
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
90 done
91
92 # 10 blocks are cow'd
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
96 done
97
98 echo "Compare files"
99 md5sum $testdir/file1 | _filter_scratch
100 md5sum $testdir/file3 | _filter_scratch
101 md5sum $testdir/file3.chk | _filter_scratch
102
103 echo "Dump extents"
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"
120
121 sync
122
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"
143
144 _scratch_cycle_mount
145
146 echo "Compare files"
147 md5sum $testdir/file1 | _filter_scratch
148 md5sum $testdir/file3 | _filter_scratch
149 md5sum $testdir/file3.chk | _filter_scratch
150
151 # success, all done
152 status=0
153 exit