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