xfs: fix more xfs_db open-coding instances
[xfstests-dev.git] / tests / xfs / 193
1 #! /bin/bash
2 # FS QA Test No. 193
3 #
4 # Test fragmentation after a lot of random CoW:
5 # - Create two reflinked files.  Set extsz hint on second file.
6 # - Buffered write to random offsets to scatter CoW reservations.
7 # - Check the number of extents.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1    # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -rf $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44 . ./common/reflink
45
46 # real QA test starts here
47 _supported_os Linux
48 _supported_fs xfs
49 _require_scratch_reflink
50 _require_cp_reflink
51 _require_fiemap
52 _require_xfs_io_command "cowextsize"
53
54 rm -f $seqres.full
55
56 echo "Format and mount"
57 _scratch_mkfs > $seqres.full 2>&1
58 _scratch_mount >> $seqres.full 2>&1
59
60 testdir=$SCRATCH_MNT/test-$seq
61 mkdir $testdir
62
63 blksz=65536
64 nr=128
65 filesize=$((blksz * nr))
66 bufnr=16
67 bufsize=$((blksz * bufnr))
68
69 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
70 real_blksz=$(get_block_size $testdir)
71 internal_blks=$((filesize / real_blksz))
72
73 echo "Create the original files"
74 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
75 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
76 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
77 _scratch_cycle_mount
78
79 echo "Compare files"
80 md5sum $testdir/file1 | _filter_scratch
81 md5sum $testdir/file2 | _filter_scratch
82
83 echo "CoW and unmount"
84 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
85 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
86 _scratch_cycle_mount
87
88 echo "Compare files"
89 md5sum $testdir/file1 | _filter_scratch
90
91 echo "Check extent counts"
92 old_extents=$(_count_extents $testdir/file1)
93 new_extents=$(_count_extents $testdir/file2)
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 * 2 / 3)) || echo "file2 badly fragmented"
99
100 # success, all done
101 status=0
102 exit