2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensuring that reflinking works when the source range covers multiple
8 # extents, some unwritten, some not:
10 # - Create a file with the following repeating sequence of blocks:
16 # - reflink across the halfway mark, starting with the unwritten extent.
17 # - Check that the files are now different where we say they're different.
20 _begin_fstest auto quick clone
22 # Import common functions.
26 # real QA test starts here
28 _require_scratch_reflink
29 _require_scratch_delalloc
30 _require_xfs_io_command "falloc"
32 echo "Format and mount"
33 _scratch_mkfs > $seqres.full 2>&1
34 _scratch_mount >> $seqres.full 2>&1
36 testdir=$SCRATCH_MNT/test-$seq
39 echo "Create the original files"
42 filesize=$((blksz * nr))
43 _pwrite_byte 0x64 0 $((blksz * nr)) $testdir/file2 >> $seqres.full
44 _pwrite_byte 0x64 0 $((blksz * nr)) $testdir/file2.chk >> $seqres.full
45 _weave_reflink_rainbow $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
49 md5sum $testdir/file1 | _filter_scratch
50 md5sum $testdir/file2 | _filter_scratch
51 md5sum $testdir/file2.chk | _filter_scratch
52 md5sum $testdir/file3 | _filter_scratch
53 md5sum $testdir/file3.chk | _filter_scratch
55 echo "reflink across the transition"
56 roff=$((filesize / 4))
58 _weave_reflink_rainbow_delalloc $blksz $nr $testdir/file3 >> $seqres.full
60 # now reflink the rainbow
61 echo "before reflink" >> $seqres.full
62 $FILEFRAG_PROG -v $testdir/file2 >> $seqres.full 2>&1
63 $FILEFRAG_PROG -v $testdir/file3 >> $seqres.full 2>&1
64 $XFS_IO_PROG -f -c "reflink $testdir/file3 $roff $roff $rsz" $testdir/file2 >> $seqres.full
65 cp $testdir/file3.chk $testdir/file2.chk
66 _pwrite_byte 0x64 0 $roff $testdir/file2.chk >> $seqres.full
67 _pwrite_byte 0x64 $((roff + rsz)) $((filesize - (roff + rsz) )) $testdir/file2.chk >> $seqres.full
71 echo "after reflink" >> $seqres.full
72 $FILEFRAG_PROG -v $testdir/file2 >> $seqres.full 2>&1
73 $FILEFRAG_PROG -v $testdir/file3 >> $seqres.full 2>&1
74 md5sum $testdir/file1 | _filter_scratch
75 md5sum $testdir/file2 | _filter_scratch
76 md5sum $testdir/file2.chk | _filter_scratch
77 md5sum $testdir/file3 | _filter_scratch
78 md5sum $testdir/file3.chk | _filter_scratch