2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Test fragmentation after a lot of random CoW:
8 # - Create two reflinked files. Set extsz hint on second file.
9 # - Buffered write to random offsets to scatter CoW reservations.
10 # - Check the number of extents.
13 _begin_fstest auto quick clone
15 # Import common functions.
19 # real QA test starts here
21 _require_scratch_reflink
23 _require_xfs_io_command "fiemap"
24 _require_xfs_io_command "cowextsize"
26 echo "Format and mount"
27 _scratch_mkfs > $seqres.full 2>&1
28 _scratch_mount >> $seqres.full 2>&1
30 testdir=$SCRATCH_MNT/test-$seq
35 filesize=$((blksz * nr))
37 bufsize=$((blksz * bufnr))
39 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
40 real_blksz=$(_get_block_size $testdir)
41 internal_blks=$((filesize / real_blksz))
43 echo "Create the original files"
44 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
45 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
46 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
50 md5sum $testdir/file1 | _filter_scratch
51 md5sum $testdir/file2 | _filter_scratch
53 echo "CoW and unmount"
54 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
55 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
59 md5sum $testdir/file1 | _filter_scratch
61 echo "Check extent counts"
62 old_extents=$(_count_extents $testdir/file1)
63 new_extents=$(_count_extents $testdir/file2)
65 echo "old extents: $old_extents" >> $seqres.full
66 echo "new extents: $new_extents" >> $seqres.full
67 echo "maximum extents: $internal_blks" >> $seqres.full
68 test $new_extents -lt $((internal_blks * 2 / 3)) || echo "file2 badly fragmented"