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