4 # Test non-recovery of unused CoW reservations for dirty files:
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 # - Dirty a single byte anywhere in the second file.
9 # - Wait for the reclaim to run.
10 # - Write more and see how bad fragmentation is.
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #-----------------------------------------------------------------------
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
35 status=1 # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
41 echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
45 # get standard environment, filters and checks
50 # real QA test starts here
53 _require_xfs_io_command "cowextsize"
54 _require_scratch_reflink
58 old_cow_lifetime=$(cat /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime)
62 echo "Format and mount"
63 _scratch_mkfs > $seqres.full 2>&1
64 _scratch_mount >> $seqres.full 2>&1
66 testdir=$SCRATCH_MNT/test-$seq
71 filesize=$((blksz * nr))
73 bufsize=$((blksz * bufnr))
75 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
76 real_blksz=$(_get_block_size $testdir)
77 internal_blks=$((filesize / real_blksz))
79 echo "Create the original files"
80 $XFS_IO_PROG -c "cowextsize $bufsize" $testdir
81 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
82 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file2.chk >> $seqres.full
83 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
87 md5sum $testdir/file1 | _filter_scratch
88 md5sum $testdir/file2 | _filter_scratch
89 md5sum $testdir/file2.chk | _filter_scratch
91 echo "CoW and leave leftovers"
92 echo 2 > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
93 seq 2 2 $((nr - 1)) | while read f; do
94 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2 >> $seqres.full
95 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2.chk >> $seqres.full
99 echo "Wait for CoW expiration"
100 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * 2)) 1" $testdir/file2 >> $seqres.full
103 echo "Allocate free space"
104 for i in $(seq 1 32); do
105 $XFS_IO_PROG -f -c "falloc 0 1" $testdir/junk.$i >> $seqres.full
107 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testdir/junk >> $seqres.full
109 echo "CoW and leave leftovers"
110 echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
111 seq 2 2 $((nr - 1)) | while read f; do
112 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2 >> $seqres.full
113 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2.chk >> $seqres.full
118 md5sum $testdir/file1 | _filter_scratch
119 md5sum $testdir/file2 | _filter_scratch
120 md5sum $testdir/file2.chk | _filter_scratch
122 echo "Check extent counts"
123 old_extents=$(_count_extents $testdir/file1)
124 new_extents=$(_count_extents $testdir/file2)
126 echo "old extents: $old_extents" >> $seqres.full
127 echo "new extents: $new_extents" >> $seqres.full
128 echo "maximum extents: $internal_blks" >> $seqres.full
129 test $new_extents -le $((2 * nr / bufnr)) || echo "file2 more fragmented than expected"