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