populate: add _require_populate_commands to check for tools
[xfstests-dev.git] / tests / xfs / 245
1 #! /bin/bash
2 # FS QA Test No. 245
3 #
4 # Make sure that reflink deals with extents going beyond EOF.
5 # - fallocate 256k in file1
6 # - pwrite 252-257k to cause it to speculatively prealloc file1
7 # - reflink file1 to file2
8 # - compare file[12]
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1    # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -rf $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/reflink
46
47 # real QA test starts here
48 _supported_os Linux
49 _supported_fs xfs
50 _require_scratch_reflink
51 _require_xfs_io_command "falloc"
52 _require_xfs_io_command "bmap" "-c"
53 _require_cp_reflink
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 $XFS_IO_PROG -f -c "falloc 0 256k" -c "pwrite 252k 6k" $testdir/file1 >> $seqres.full
66 _scratch_cycle_mount
67 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
68
69 echo "Compare files"
70 md5sum $testdir/file1 | _filter_scratch
71 md5sum $testdir/file2 | _filter_scratch
72
73 echo "Unwritten data extents"
74 test $(_xfs_bmapx_find data $testdir/file1 '10000$') -gt 0 || \
75         echo "Expected to find an unwritten file1 extent"
76 echo "Shared data extents"
77 test $(_xfs_bmapx_find data $testdir/file1 '100000$') -gt 0 || \
78         echo "Expected to find a shared data extent"
79
80 echo "Hole data extents"
81 test $(_xfs_bmapx_find data $testdir/file2 'hole') -gt 0 || \
82         echo "Expected to find a hole data extent"
83 echo "Shared data extents"
84 test $(_xfs_bmapx_find data $testdir/file2 '100000$') -gt 0 || \
85         echo "Expected to find a shared data extent"
86
87 echo "Hole cow extents"
88 test $(_xfs_bmapx_find cow $testdir/file1 'hole') -gt 0 || \
89         echo "Expected to find a hole cow extent"
90 echo "Hole cow extents"
91 test $(_xfs_bmapx_find cow $testdir/file2 'hole') -gt 0 || \
92         echo "Expected to find a hole cow extent"
93
94 # success, all done
95 status=0
96 exit