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 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
22 status=1 # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
31 # get standard environment, filters and checks
36 # real QA test starts here
39 _require_scratch_reflink
41 _require_xfs_io_command "fiemap"
42 _require_xfs_io_command "cowextsize"
46 echo "Format and mount"
47 _scratch_mkfs > $seqres.full 2>&1
48 _scratch_mount >> $seqres.full 2>&1
50 testdir=$SCRATCH_MNT/test-$seq
55 filesize=$((blksz * nr))
57 bufsize=$((blksz * bufnr))
59 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
60 real_blksz=$(_get_block_size $testdir)
61 internal_blks=$((filesize / real_blksz))
63 echo "Create the original files"
64 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
66 $XFS_IO_PROG -f -c "extsize $real_blksz" $testdir/file2
67 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
68 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
69 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
71 $XFS_IO_PROG -f -c "extsize $bufsize" $testdir/file3
72 $XFS_IO_PROG -f -c "cowextsize $real_blksz" $testdir/file3
73 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
77 md5sum $testdir/file1 | _filter_scratch
78 md5sum $testdir/file2 | _filter_scratch
79 md5sum $testdir/file3 | _filter_scratch
81 echo "CoW and unmount"
82 echo "extsize" >> $seqres.full
83 $XFS_IO_PROG -f -c "extsize" $testdir/file2 >> $seqres.full
84 echo "cowextsize" >> $seqres.full
85 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
87 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
88 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file2 >> $seqres.full
90 echo "extsize" >> $seqres.full
91 $XFS_IO_PROG -f -c "extsize" $testdir/file3 >> $seqres.full
92 echo "cowextsize" >> $seqres.full
93 $XFS_IO_PROG -f -c "cowextsize" $testdir/file3 >> $seqres.full
95 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file3 >> $seqres.full
96 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file3 >> $seqres.full
100 md5sum $testdir/file1 | _filter_scratch
101 md5sum $testdir/file2 | _filter_scratch
102 md5sum $testdir/file3 | _filter_scratch
104 echo "Check extent counts"
105 old_extents=$(_count_extents $testdir/file1)
106 new_extents=$(_count_extents $testdir/file2)
108 echo "old extents: $old_extents" >> $seqres.full
109 echo "new extents: $new_extents" >> $seqres.full
110 echo "maximum extents: $internal_blks" >> $seqres.full
111 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
112 || echo "file2 badly fragmented"
114 new_extents=$(_count_extents $testdir/file3)
116 echo "old extents: $old_extents" >> $seqres.full
117 echo "new extents: $new_extents" >> $seqres.full
118 echo "maximum extents: $internal_blks" >> $seqres.full
119 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
120 || echo "file3 badly fragmented"