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