7a59dbacaf5182d4c82343784d6a728a9df4c118
[xfstests-dev.git] / tests / xfs / 224
1 #! /bin/bash
2 # FS QA Test No. 224
3 #
4 # Ensuring that copy on write in buffered mode works when the CoW
5 # range originally covers multiple extents, some delalloc, some not.
6 #   - Set cowextsize hint.
7 #   - Create a file.
8 #   - Reflink the odd blocks of the first file into the second file.
9 #   - Buffered write the even blocks of the second file.
10 #   - CoW across the halfway mark, starting with the unwritten extent.
11 #   - Check that the files are now different where we say they're different.
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1    # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41     cd /
42     rm -rf $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48 . ./common/reflink
49
50 # real QA test starts here
51 _supported_os Linux
52 _require_scratch_reflink
53 _require_xfs_io_command "falloc"
54 _require_xfs_io_command "cowextsize"
55
56 rm -f $seqres.full
57
58 echo "Format and mount"
59 _scratch_mkfs > $seqres.full 2>&1
60 _scratch_mount >> $seqres.full 2>&1
61
62 testdir=$SCRATCH_MNT/test-$seq
63 mkdir $testdir
64
65 echo "Create the original files"
66 blksz=65536
67 nr=64
68 filesize=$((blksz * nr))
69 real_blksz=$(get_block_size $testdir)
70 internal_blks=$((filesize / real_blksz))
71 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
72 _weave_reflink_holes $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
73 _scratch_cycle_mount
74
75 echo "Compare files"
76 md5sum $testdir/file1 | _filter_scratch
77 md5sum $testdir/file3 | _filter_scratch
78 md5sum $testdir/file3.chk | _filter_scratch
79
80 echo "CoW across the transition"
81 cowoff=$((filesize / 4))
82 cowsz=$((filesize / 2))
83 _weave_reflink_holes_delalloc $blksz $nr $testdir/file3 >> $seqres.full
84 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
85 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
86 _scratch_cycle_mount
87
88 echo "Compare files"
89 md5sum $testdir/file1 | _filter_scratch
90 md5sum $testdir/file3 | _filter_scratch
91 md5sum $testdir/file3.chk | _filter_scratch
92
93 echo "Check extent counts"
94 old_extents=$(_count_extents $testdir/file1)
95 new_extents=$(_count_extents $testdir/file3)
96
97 echo "old extents: $old_extents" >> $seqres.full
98 echo "new extents: $new_extents" >> $seqres.full
99 echo "maximum extents: $internal_blks" >> $seqres.full
100 test $((new_extents - (nr / 2))) -lt $((internal_blks / 2)) || echo "file3 badly fragmented"
101
102 # success, all done
103 status=0
104 exit