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 unwritten, some not.
9 # - Set cowextsize hint.
10 # - Create a file with the following repeating sequence of blocks:
16 # - CoW across the halfway mark, starting with the unwritten extent.
17 # - Check that the files are now different where we say they're different.
20 seqres=$RESULT_DIR/$seq
21 echo "QA output created by $seq"
25 status=1 # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
34 # get standard environment, filters and checks
39 # real QA test starts here
41 _require_scratch_reflink
42 _require_xfs_io_command "falloc"
43 _require_xfs_io_command "cowextsize"
44 _require_xfs_io_command "fpunch"
50 echo "Format and mount"
51 _scratch_mkfs > $seqres.full 2>&1
52 _scratch_mount >> $seqres.full 2>&1
54 testdir=$SCRATCH_MNT/test-$seq
57 echo "Create the original files"
60 filesize=$((blksz * nr))
61 real_blksz=$(_get_block_size $testdir)
62 internal_blks=$((filesize / real_blksz))
63 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
64 _weave_reflink_rainbow $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
68 md5sum $testdir/file1 | _filter_scratch
69 md5sum $testdir/file3 | _filter_scratch
70 md5sum $testdir/file3.chk | _filter_scratch
72 echo "directio CoW across the transition"
73 cowoff=$((filesize / 4))
74 cowsz=$((filesize / 2))
75 _weave_reflink_rainbow_delalloc $blksz $nr $testdir/file3 >> $seqres.full
77 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
78 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
82 md5sum $testdir/file1 | _filter_scratch
83 md5sum $testdir/file3 | _filter_scratch
84 md5sum $testdir/file3.chk | _filter_scratch
86 echo "Check extent counts"
87 old_extents=$(_count_extents $testdir/file1)
88 new_extents=$(_count_extents $testdir/file3)
90 echo "old extents: $old_extents" >> $seqres.full
91 echo "new extents: $new_extents" >> $seqres.full
92 echo "maximum extents: $internal_blks" >> $seqres.full
93 test $((new_extents - (nr * 4 / 10))) -lt $((internal_blks / 2)) || echo "file3 badly fragmented"