4 # Ensuring that copy on write in buffered mode works when free space
5 # is heavily fragmented.
7 # - Reflink the odd blocks of the first file into a third file.
8 # - Reflink the even blocks of the second file into the third file.
9 # - Try to fragment the free space by allocating a huge file and
10 # punching out every other block.
11 # - CoW across the halfway mark.
12 # - Check that the files are now different where we say they're different.
14 #-----------------------------------------------------------------------
15 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #-----------------------------------------------------------------------
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
37 status=1 # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
43 # rm -rf $tmp.* $testdir
46 # get standard environment, filters and checks
51 # real QA test starts here
53 _require_scratch_reflink
55 _require_xfs_io_command "falloc"
56 _require_xfs_io_command "fpunch"
57 test $FSTYP = "btrfs" && _notrun "Can't fragment free space on btrfs."
65 # consume nearly all available space (leave ~1MB)
66 avail=`_get_available_space $SCRATCH_MNT`
67 echo "$avail bytes left"
68 filesize=$((avail - 1048576))
69 $XFS_IO_PROG -fc "truncate $filesize" $file
72 chunksizemb=$((filesize / chunks / 1048576))
73 seq 1 $chunks | while read f; do
74 echo "$((f * chunksizemb)) file size $f / 20"
75 $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" $file
79 chunksizemb=$((filesize / chunks / 1048576))
80 seq 80 $chunks | while read f; do
81 echo "$((f * chunksizemb)) file size $f / $chunks"
82 $XFS_IO_PROG -fc "falloc -k $(( (f - 1) * chunksizemb))m ${chunksizemb}m" $file
85 filesizemb=$((filesize / 1048576))
86 $XFS_IO_PROG -fc "falloc -k 0 ${filesizemb}m" $file
89 avail=`_get_available_space $SCRATCH_MNT`
90 $XFS_IO_PROG -fc "pwrite -S 0x65 0 $avail" ${file}.${i}
92 # Punch out whatever we need
93 seq 1 $((nr * 4)) | while read f; do
94 $XFS_IO_PROG -f -c "fpunch $((f * 2 * blksz)) $blksz" $file
98 echo "Format and mount"
99 _scratch_mkfs > $seqres.full 2>&1
100 _scratch_mount >> $seqres.full 2>&1
102 testdir=$SCRATCH_MNT/test-$seq
105 echo "Create the original files"
108 filesize=$((blksz * nr))
109 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
110 _pwrite_byte 0x62 0 $filesize $testdir/file2 >> $seqres.full
111 seq 0 2 $((nr-1)) | while read f; do
112 _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
113 _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
115 seq 1 2 $((nr-1)) | while read f; do
116 _reflink_range $testdir/file2 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
117 _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
120 _fragment_freesp $testdir/bigfile >> $seqres.full 2>&1
121 filesize=$((blksz * nr))
125 md5sum $testdir/file1 | _filter_scratch
126 md5sum $testdir/file2 | _filter_scratch
127 md5sum $testdir/file3 | _filter_scratch
128 md5sum $testdir/file3.chk | _filter_scratch
130 echo "CoW with multiple extents?"
131 cowoff=$((filesize / 4))
132 cowsz=$((filesize / 2))
133 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
134 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
138 md5sum $testdir/file1 | _filter_scratch
139 md5sum $testdir/file2 | _filter_scratch
140 md5sum $testdir/file3 | _filter_scratch
141 md5sum $testdir/file3.chk | _filter_scratch