xfs: fix more xfs_db open-coding instances
[xfstests-dev.git] / tests / xfs / 280
1 #! /bin/bash
2 # FS QA Test No. 280
3 #
4 # Check that GETBMAPX accurately report shared extents.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2016 Oracle, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 7 15
32
33 _cleanup()
34 {
35         cd /
36         rm -rf $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 . ./common/reflink
43
44 # real QA test starts here
45 _supported_os Linux
46 _supported_fs xfs
47 _require_scratch_reflink
48 _require_xfs_io_command "bmap"
49
50 echo "Format and mount"
51 _scratch_mkfs > $seqres.full 2>&1
52 _scratch_mount >> $seqres.full 2>&1
53
54 testdir=$SCRATCH_MNT/test-$seq
55 mkdir $testdir
56
57 blocks=5
58 blksz=65536
59 sz=$((blocks * blksz))
60
61 echo "Create the original files"
62 $XFS_IO_PROG -f -c "falloc 0 $sz" $testdir/file1 >> $seqres.full
63 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
64 _scratch_cycle_mount
65
66 bmap() {
67         $XFS_IO_PROG -c 'bmap -v' $1 | grep '^[[:space:]]*[0-9]*:'
68 }
69
70 echo "file1 extents and holes"
71 bmap $testdir/file1 | grep -v -c hole
72 bmap $testdir/file1 | grep -c hole
73
74 _reflink_range $testdir/file1 $blksz $testdir/file2 $((blksz * 3)) $blksz >> $seqres.full
75 _reflink_range $testdir/file1 $((blksz * 3)) $testdir/file2 $blksz $blksz >> $seqres.full
76 _scratch_cycle_mount
77
78 echo "Compare files"
79 md5sum $testdir/file1 | _filter_scratch
80 md5sum $testdir/file2 | _filter_scratch
81
82 echo "file1 extents and holes"
83 bmap $testdir/file1 | grep -v -c hole
84 bmap $testdir/file1 | grep -c hole
85 echo "file2 extents and holes"
86 bmap $testdir/file2 | grep -v -c hole
87 bmap $testdir/file2 | grep -c hole
88 echo "file1 shared extents"
89 bmap $testdir/file1 | grep -c '1.....$'
90
91 # success, all done
92 status=0
93 exit