4 # Ensure that the effective cow extent allocation size hint is the maximum of
5 # the cowextsize and extsize inode fields.
6 # - Create two reflinked files. Set extsz hint on second file to $blocksize
7 # and cowextsize hint to 1MB.
8 # - Buffered write to random offsets to scatter CoW reservations.
9 # - Rewrite the whole file to use up reservations.
10 # - Check the number of extents.
11 # - Repeat, but with extsz = 1MB and cowextsz = $blocksize.
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #-----------------------------------------------------------------------
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
36 status=1 # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
45 # get standard environment, filters and checks
50 # real QA test starts here
53 _require_scratch_reflink
56 _require_xfs_io_command "cowextsize"
60 echo "Format and mount"
61 _scratch_mkfs > $seqres.full 2>&1
62 _scratch_mount >> $seqres.full 2>&1
64 testdir=$SCRATCH_MNT/test-$seq
69 filesize=$((blksz * nr))
71 bufsize=$((blksz * bufnr))
73 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
74 real_blksz=$(get_block_size $testdir)
75 internal_blks=$((filesize / real_blksz))
77 echo "Create the original files"
78 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
80 $XFS_IO_PROG -f -c "extsize $real_blksz" $testdir/file2
81 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
82 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
83 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
85 $XFS_IO_PROG -f -c "extsize $bufsize" $testdir/file3
86 $XFS_IO_PROG -f -c "cowextsize $real_blksz" $testdir/file3
87 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
91 md5sum $testdir/file1 | _filter_scratch
92 md5sum $testdir/file2 | _filter_scratch
93 md5sum $testdir/file3 | _filter_scratch
95 echo "CoW and unmount"
96 echo "extsize" >> $seqres.full
97 $XFS_IO_PROG -f -c "extsize" $testdir/file2 >> $seqres.full
98 echo "cowextsize" >> $seqres.full
99 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
101 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
102 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file2 >> $seqres.full
104 echo "extsize" >> $seqres.full
105 $XFS_IO_PROG -f -c "extsize" $testdir/file3 >> $seqres.full
106 echo "cowextsize" >> $seqres.full
107 $XFS_IO_PROG -f -c "cowextsize" $testdir/file3 >> $seqres.full
109 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file3 >> $seqres.full
110 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file3 >> $seqres.full
114 md5sum $testdir/file1 | _filter_scratch
115 md5sum $testdir/file2 | _filter_scratch
116 md5sum $testdir/file3 | _filter_scratch
118 echo "Check extent counts"
119 old_extents=$(_count_extents $testdir/file1)
120 new_extents=$(_count_extents $testdir/file2)
122 echo "old extents: $old_extents" >> $seqres.full
123 echo "new extents: $new_extents" >> $seqres.full
124 echo "maximum extents: $internal_blks" >> $seqres.full
125 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
126 || echo "file2 badly fragmented"
128 new_extents=$(_count_extents $testdir/file3)
130 echo "old extents: $old_extents" >> $seqres.full
131 echo "new extents: $new_extents" >> $seqres.full
132 echo "maximum extents: $internal_blks" >> $seqres.full
133 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
134 || echo "file3 badly fragmented"