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