4 # Test recovery of unused CoW reservations:
5 # - Create two reflinked files. Set extsz hint on second file.
6 # - Dirty a single byte on a number of CoW reservations in the second file.
7 # - Fsync to flush out the dirty pages.
8 # - Wait for the reclaim to run.
9 # - Write more and see how bad fragmentation is.
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
40 echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
44 # get standard environment, filters and checks
49 # real QA test starts here
52 _require_scratch_reflink
54 _require_xfs_io_command "cowextsize"
55 _require_xfs_io_command "fiemap"
57 old_cow_lifetime=$(cat /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime)
61 echo "Format and mount"
62 _scratch_mkfs > $seqres.full 2>&1
63 _scratch_mount >> $seqres.full 2>&1
65 testdir=$SCRATCH_MNT/test-$seq
70 filesize=$((blksz * nr))
72 bufsize=$((blksz * bufnr))
74 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
75 real_blksz=$(_get_block_size $testdir)
76 internal_blks=$((filesize / real_blksz))
78 echo "Create the original files"
79 $XFS_IO_PROG -c "cowextsize $bufsize" $testdir
80 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
81 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file2.chk >> $seqres.full
82 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
86 md5sum $testdir/file1 | _filter_scratch
87 md5sum $testdir/file2 | _filter_scratch
88 md5sum $testdir/file2.chk | _filter_scratch
90 echo "CoW and leave leftovers"
91 echo 2 > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
92 seq 2 2 $((nr - 1)) | while read f; do
93 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2 >> $seqres.full
94 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2.chk >> $seqres.full
98 echo "Wait for CoW expiration"
101 echo "Allocate free space"
102 for i in $(seq 1 32); do
103 $XFS_IO_PROG -f -c "falloc 0 1" $testdir/junk.$i >> $seqres.full
105 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testdir/junk >> $seqres.full
107 echo "CoW and leave leftovers"
108 echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
109 seq 2 2 $((nr - 1)) | while read f; do
110 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2 >> $seqres.full
111 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2.chk >> $seqres.full
116 md5sum $testdir/file1 | _filter_scratch
117 md5sum $testdir/file2 | _filter_scratch
118 md5sum $testdir/file2.chk | _filter_scratch
120 echo "Check extent counts"
121 old_extents=$(_count_extents $testdir/file1)
122 new_extents=$(_count_extents $testdir/file2)
124 echo "old extents: $old_extents" >> $seqres.full
125 echo "new extents: $new_extents" >> $seqres.full
126 echo "maximum extents: $internal_blks" >> $seqres.full
127 test $new_extents -le $((3 * nr / bufnr)) || echo "file2 more fragmented than expected"