xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 223
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 223
6 #
7 # Ensuring that copy on write in direct-io mode works when the CoW
8 # range originally covers multiple extents, some delalloc, some not.
9 #   - Set cowextsize hint.
10 #   - Create a file.
11 #   - Reflink the odd blocks of the first file into the second file.
12 #   - Buffered write the even blocks of the second file.
13 #   - directio CoW across the halfway mark, starting with the unwritten extent.
14 #   - Check that the files are now different where we say they're different.
15 #
16 . ./common/preamble
17 _begin_fstest auto quick clone
18
19 # Import common functions.
20 . ./common/filter
21 . ./common/reflink
22
23 # real QA test starts here
24 _require_scratch_reflink
25 _require_xfs_io_command "falloc"
26 _require_xfs_io_command "cowextsize"
27 _require_odirect
28
29 echo "Format and mount"
30 _scratch_mkfs > $seqres.full 2>&1
31 _scratch_mount >> $seqres.full 2>&1
32
33 testdir=$SCRATCH_MNT/test-$seq
34 mkdir $testdir
35
36 echo "Create the original files"
37 blksz=65536
38 nr=64
39 filesize=$((blksz * nr))
40 real_blksz=$(_get_block_size $testdir)
41 internal_blks=$((filesize / real_blksz))
42 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
43 _weave_reflink_holes $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 "directio CoW across the transition"
52 cowoff=$((filesize / 4))
53 cowsz=$((filesize / 2))
54 _weave_reflink_holes_delalloc $blksz $nr $testdir/file3 >> $seqres.full
55 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
56 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
57 _scratch_cycle_mount
58
59 echo "Compare files"
60 md5sum $testdir/file1 | _filter_scratch
61 md5sum $testdir/file3 | _filter_scratch
62 md5sum $testdir/file3.chk | _filter_scratch
63
64 echo "Check extent counts"
65 old_extents=$(_count_extents $testdir/file1)
66 new_extents=$(_count_extents $testdir/file3)
67
68 echo "old extents: $old_extents" >> $seqres.full
69 echo "new extents: $new_extents" >> $seqres.full
70 echo "maximum extents: $internal_blks" >> $seqres.full
71 test $((new_extents - (nr / 2))) -lt $((internal_blks / 2)) || echo "file3 badly fragmented"
72
73 # success, all done
74 status=0
75 exit