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