generic: add mmap CoW test for unwritten&destination extents
[xfstests-dev.git] / tests / generic / 659
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # FS QA Test No. 659
5 #
6 # Ensuring that copy on write in mmap mode works when the CoW
7 # range originally covers multiple extents, some unwritten, some not.
8 # (MMAP version of generic/189,188)
9 #   - Create a file and fallocate a second file.
10 #   - Reflink the odd blocks of the first file into the second file.
11 #   - mmap CoW across the halfway mark, starting with the unwritten extent.
12 #   - Check that the files are now different where we say they're different.
13 #
14 . ./common/preamble
15 _begin_fstest auto quick clone
16
17 # Import common functions.
18 . ./common/filter
19 . ./common/reflink
20
21 # real QA test starts here
22 _require_scratch_reflink
23 _require_xfs_io_command "falloc"
24
25 echo "Format and mount"
26 _scratch_mkfs > $seqres.full 2>&1
27 _scratch_mount >> $seqres.full 2>&1
28
29 testdir=$SCRATCH_MNT/test-$seq
30 mkdir $testdir
31
32 echo "Create the original files"
33 blksz=65536
34 nr=64
35 filesize=$((blksz * nr))
36 _weave_reflink_unwritten $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
37 _scratch_cycle_mount
38
39 echo "Compare files"
40 md5sum $testdir/file1 | _filter_scratch
41 md5sum $testdir/file3 | _filter_scratch
42 md5sum $testdir/file3.chk | _filter_scratch
43
44 echo "mmap CoW across the transition"
45 cowoff=$((filesize / 4))
46 cowsz=$((filesize / 2))
47 mmapsz=$((cowoff + cowsz))
48 _mwrite_byte 0x63 $cowoff $cowsz $mmapsz $testdir/file3 >> $seqres.full
49 _mwrite_byte 0x63 $cowoff $cowsz $mmapsz $testdir/file3.chk >> $seqres.full
50 _scratch_cycle_mount
51
52 echo "Compare files"
53 md5sum $testdir/file1 | _filter_scratch
54 md5sum $testdir/file3 | _filter_scratch
55 md5sum $testdir/file3.chk | _filter_scratch
56
57 # success, all done
58 status=0
59 exit