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
38 _require_scratch_reflink
40 _require_xfs_io_command "fiemap"
41 _require_xfs_io_command "cowextsize"
45 echo "Format and mount"
46 _scratch_mkfs > $seqres.full 2>&1
47 _scratch_mount >> $seqres.full 2>&1
49 testdir=$SCRATCH_MNT/test-$seq
54 filesize=$((blksz * nr))
56 bufsize=$((blksz * bufnr))
58 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
59 real_blksz=$(_get_block_size $testdir)
60 internal_blks=$((filesize / real_blksz))
62 echo "Create the original files"
63 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
65 $XFS_IO_PROG -f -c "extsize $real_blksz" $testdir/file2
66 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
67 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
68 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
70 $XFS_IO_PROG -f -c "extsize $bufsize" $testdir/file3
71 $XFS_IO_PROG -f -c "cowextsize $real_blksz" $testdir/file3
72 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
76 md5sum $testdir/file1 | _filter_scratch
77 md5sum $testdir/file2 | _filter_scratch
78 md5sum $testdir/file3 | _filter_scratch
80 echo "CoW and unmount"
81 echo "extsize" >> $seqres.full
82 $XFS_IO_PROG -f -c "extsize" $testdir/file2 >> $seqres.full
83 echo "cowextsize" >> $seqres.full
84 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
86 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
87 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file2 >> $seqres.full
89 echo "extsize" >> $seqres.full
90 $XFS_IO_PROG -f -c "extsize" $testdir/file3 >> $seqres.full
91 echo "cowextsize" >> $seqres.full
92 $XFS_IO_PROG -f -c "cowextsize" $testdir/file3 >> $seqres.full
94 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file3 >> $seqres.full
95 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file3 >> $seqres.full
99 md5sum $testdir/file1 | _filter_scratch
100 md5sum $testdir/file2 | _filter_scratch
101 md5sum $testdir/file3 | _filter_scratch
103 echo "Check extent counts"
104 old_extents=$(_count_extents $testdir/file1)
105 new_extents=$(_count_extents $testdir/file2)
107 echo "old extents: $old_extents" >> $seqres.full
108 echo "new extents: $new_extents" >> $seqres.full
109 echo "maximum extents: $internal_blks" >> $seqres.full
110 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
111 || echo "file2 badly fragmented"
113 new_extents=$(_count_extents $testdir/file3)
115 echo "old extents: $old_extents" >> $seqres.full
116 echo "new extents: $new_extents" >> $seqres.full
117 echo "maximum extents: $internal_blks" >> $seqres.full
118 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
119 || echo "file3 badly fragmented"