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
40 _require_scratch_reflink
41 _require_xfs_io_command "falloc"
42 _require_xfs_io_command "cowextsize"
43 _require_xfs_io_command "fpunch"
49 echo "Format and mount"
50 _scratch_mkfs > $seqres.full 2>&1
51 _scratch_mount >> $seqres.full 2>&1
53 testdir=$SCRATCH_MNT/test-$seq
56 echo "Create the original files"
59 filesize=$((blksz * nr))
60 real_blksz=$(_get_block_size $testdir)
61 internal_blks=$((filesize / real_blksz))
62 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
63 _weave_reflink_rainbow $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
67 md5sum $testdir/file1 | _filter_scratch
68 md5sum $testdir/file3 | _filter_scratch
69 md5sum $testdir/file3.chk | _filter_scratch
71 echo "directio CoW across the transition"
72 cowoff=$((filesize / 4))
73 cowsz=$((filesize / 2))
74 _weave_reflink_rainbow_delalloc $blksz $nr $testdir/file3 >> $seqres.full
76 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
77 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
81 md5sum $testdir/file1 | _filter_scratch
82 md5sum $testdir/file3 | _filter_scratch
83 md5sum $testdir/file3.chk | _filter_scratch
85 echo "Check extent counts"
86 old_extents=$(_count_extents $testdir/file1)
87 new_extents=$(_count_extents $testdir/file3)
89 echo "old extents: $old_extents" >> $seqres.full
90 echo "new extents: $new_extents" >> $seqres.full
91 echo "maximum extents: $internal_blks" >> $seqres.full
92 test $((new_extents - (nr * 4 / 10))) -lt $((internal_blks / 2)) || echo "file3 badly fragmented"