2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensuring that copy on write in buffered mode works when the CoW
8 # range originally covers multiple extents, some delalloc, some not.
9 # - Set cowextsize hint.
11 # - Reflink the odd blocks of the first file into the second file.
12 # - Buffered write the even blocks of the second file.
13 # - CoW across the halfway mark, starting with the unwritten extent.
14 # - Check that the files are now different where we say they're different.
17 _begin_fstest auto quick clone
19 # Import common functions.
23 # real QA test starts here
24 _require_scratch_reflink
25 _require_xfs_io_command "falloc"
26 _require_xfs_io_command "cowextsize"
28 echo "Format and mount"
29 _scratch_mkfs > $seqres.full 2>&1
30 _scratch_mount >> $seqres.full 2>&1
32 testdir=$SCRATCH_MNT/test-$seq
35 echo "Create the original files"
38 filesize=$((blksz * nr))
39 real_blksz=$(_get_block_size $testdir)
40 internal_blks=$((filesize / real_blksz))
41 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
42 _weave_reflink_holes $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
46 md5sum $testdir/file1 | _filter_scratch
47 md5sum $testdir/file3 | _filter_scratch
48 md5sum $testdir/file3.chk | _filter_scratch
50 echo "CoW across the transition"
51 cowoff=$((filesize / 4))
52 cowsz=$((filesize / 2))
53 _weave_reflink_holes_delalloc $blksz $nr $testdir/file3 >> $seqres.full
54 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
55 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
59 md5sum $testdir/file1 | _filter_scratch
60 md5sum $testdir/file3 | _filter_scratch
61 md5sum $testdir/file3.chk | _filter_scratch
63 echo "Check extent counts"
64 old_extents=$(_count_extents $testdir/file1)
65 new_extents=$(_count_extents $testdir/file3)
67 echo "old extents: $old_extents" >> $seqres.full
68 echo "new extents: $new_extents" >> $seqres.full
69 echo "maximum extents: $internal_blks" >> $seqres.full
70 test $((new_extents - (nr / 2))) -lt $((internal_blks / 2)) || echo "file3 badly fragmented"