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.
9 # - Buffered write to random offsets to scatter CoW reservations.
10 # - Check the number of extents.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # get standard environment, filters and checks
32 # real QA test starts here
33 _require_scratch_reflink
35 _require_xfs_io_command "fiemap"
39 echo "Format and mount"
40 _scratch_mkfs > $seqres.full 2>&1
41 _scratch_mount >> $seqres.full 2>&1
43 testdir=$SCRATCH_MNT/test-$seq
48 filesize=$((blksz * nr))
50 bufsize=$((blksz * bufnr))
52 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
53 real_blksz=$(_get_block_size $testdir)
54 internal_blks=$((filesize / real_blksz))
56 echo "Create the original files"
57 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
58 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
62 md5sum $testdir/file1 | _filter_scratch
63 md5sum $testdir/file2 | _filter_scratch
65 echo "CoW and unmount"
66 for i in `seq 1 8`; do
67 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
72 md5sum $testdir/file1 | _filter_scratch
74 echo "Check extent counts"
75 old_extents=$(_count_extents $testdir/file1)
76 new_extents=$(_count_extents $testdir/file2)
78 echo "old extents: $old_extents" >> $seqres.full
79 echo "new extents: $new_extents" >> $seqres.full
80 echo "maximum extents: $internal_blks" >> $seqres.full
81 test $new_extents -lt $((internal_blks * 2 / 3)) || echo "file2 badly fragmented"