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 zero extsz hint on second file.
9 # - Directio write to random offsets to scatter CoW reservations.
10 # - falloc the whole file to unshare blocks.
11 # - Check the number of extents.
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
33 # real QA test starts here
35 _require_scratch_reflink
37 _require_xfs_io_command "fiemap"
38 _require_xfs_io_command "cowextsize"
39 _require_xfs_io_command "funshare"
44 echo "Format and mount"
45 _scratch_mkfs > $seqres.full 2>&1
46 _scratch_mount >> $seqres.full 2>&1
48 testdir=$SCRATCH_MNT/test-$seq
53 filesize=$((blksz * nr))
55 bufsize=$((blksz * bufnr))
57 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
58 real_blksz=$(_get_file_block_size $testdir)
59 internal_blks=$((filesize / real_blksz))
61 echo "Create the original files"
62 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
63 $XFS_IO_PROG -f -c "cowextsize $real_blksz" $testdir/file2
64 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
68 md5sum $testdir/file1 | _filter_scratch
69 md5sum $testdir/file2 | _filter_scratch
71 echo "CoW and unmount"
72 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
73 $XFS_IO_PROG -d -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" $testdir/file2 >> $seqres.full
74 $XFS_IO_PROG -d -f -c "funshare 0 $filesize" $testdir/file2 >> $seqres.full
78 md5sum $testdir/file1 | _filter_scratch
80 echo "Check extent counts"
81 old_extents=$(_count_extents $testdir/file1)
82 new_extents=$(_count_extents $testdir/file2)
84 echo "old extents: $old_extents" >> $seqres.full
85 echo "new extents: $new_extents" >> $seqres.full
86 echo "maximum extents: $internal_blks" >> $seqres.full