2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that the effective cow extent allocation size hint is the maximum of
8 # the cowextsize and extsize inode fields.
9 # - Create two reflinked files. Set extsz hint on second file to $blocksize
10 # and cowextsize hint to 1MB.
11 # - Buffered write to random offsets to scatter CoW reservations.
12 # - Rewrite the whole file to use up reservations.
13 # - Check the number of extents.
14 # - Repeat, but with extsz = 1MB and cowextsz = $blocksize.
17 _begin_fstest auto quick clone
19 # Import common functions.
23 # real QA test starts here
25 _require_scratch_reflink
27 _require_xfs_io_command "fiemap"
28 _require_xfs_io_command "cowextsize"
30 echo "Format and mount"
31 _scratch_mkfs > $seqres.full 2>&1
32 _scratch_mount >> $seqres.full 2>&1
34 testdir=$SCRATCH_MNT/test-$seq
39 filesize=$((blksz * nr))
41 bufsize=$((blksz * bufnr))
43 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
44 real_blksz=$(_get_file_block_size $testdir)
45 internal_blks=$((filesize / real_blksz))
47 echo "Create the original files"
48 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
50 $XFS_IO_PROG -f -c "extsize $real_blksz" $testdir/file2
51 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
52 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
53 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
55 $XFS_IO_PROG -f -c "extsize $bufsize" $testdir/file3
56 $XFS_IO_PROG -f -c "cowextsize $real_blksz" $testdir/file3
57 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
61 md5sum $testdir/file1 | _filter_scratch
62 md5sum $testdir/file2 | _filter_scratch
63 md5sum $testdir/file3 | _filter_scratch
65 echo "CoW and unmount"
66 echo "extsize" >> $seqres.full
67 $XFS_IO_PROG -f -c "extsize" $testdir/file2 >> $seqres.full
68 echo "cowextsize" >> $seqres.full
69 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
71 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
72 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file2 >> $seqres.full
74 echo "extsize" >> $seqres.full
75 $XFS_IO_PROG -f -c "extsize" $testdir/file3 >> $seqres.full
76 echo "cowextsize" >> $seqres.full
77 $XFS_IO_PROG -f -c "cowextsize" $testdir/file3 >> $seqres.full
79 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file3 >> $seqres.full
80 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file3 >> $seqres.full
84 md5sum $testdir/file1 | _filter_scratch
85 md5sum $testdir/file2 | _filter_scratch
86 md5sum $testdir/file3 | _filter_scratch
88 echo "Check extent counts"
89 old_extents=$(_count_extents $testdir/file1)
90 new_extents=$(_count_extents $testdir/file2)
92 echo "old extents: $old_extents" >> $seqres.full
93 echo "new extents: $new_extents" >> $seqres.full
94 echo "maximum extents: $internal_blks" >> $seqres.full
95 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
96 || echo "file2 badly fragmented"
98 new_extents=$(_count_extents $testdir/file3)
100 echo "old extents: $old_extents" >> $seqres.full
101 echo "new extents: $new_extents" >> $seqres.full
102 echo "maximum extents: $internal_blks" >> $seqres.full
103 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
104 || echo "file3 badly fragmented"