populate: add _require_populate_commands to check for tools
[xfstests-dev.git] / tests / xfs / 208
1 #! /bin/bash
2 # FS QA Test No. 208
3 #
4 # Ensure that the effective cow extent allocation size hint is the maximum of
5 # the cowextsize and extsize inode fields.
6 # - Create two reflinked files.  Set extsz hint on second file to $blocksize
7 #   and cowextsize hint to 1MB.
8 # - Buffered write to random offsets to scatter CoW reservations.
9 # - Rewrite the whole file to use up reservations.
10 # - Check the number of extents.
11 # - Repeat, but with extsz = 1MB and cowextsz = $blocksize.
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1    # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41     cd /
42     rm -rf $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48 . ./common/reflink
49
50 # real QA test starts here
51 _supported_os Linux
52 _supported_fs xfs
53 _require_scratch_reflink
54 _require_cp_reflink
55 _require_fiemap
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 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
80 $XFS_IO_PROG -f -c "extsize $real_blksz" $testdir/file2
81 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
82 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
83 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
84
85 $XFS_IO_PROG -f -c "extsize $bufsize" $testdir/file3
86 $XFS_IO_PROG -f -c "cowextsize $real_blksz" $testdir/file3
87 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
88 _scratch_cycle_mount
89
90 echo "Compare files"
91 md5sum $testdir/file1 | _filter_scratch
92 md5sum $testdir/file2 | _filter_scratch
93 md5sum $testdir/file3 | _filter_scratch
94
95 echo "CoW and unmount"
96 echo "extsize" >> $seqres.full
97 $XFS_IO_PROG -f -c "extsize" $testdir/file2 >> $seqres.full
98 echo "cowextsize" >> $seqres.full
99 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
100
101 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file2 >> $seqres.full
102 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file2 >> $seqres.full
103
104 echo "extsize" >> $seqres.full
105 $XFS_IO_PROG -f -c "extsize" $testdir/file3 >> $seqres.full
106 echo "cowextsize" >> $seqres.full
107 $XFS_IO_PROG -f -c "cowextsize" $testdir/file3 >> $seqres.full
108
109 $XFS_IO_PROG -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" -c "fdatasync" $testdir/file3 >> $seqres.full
110 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file3 >> $seqres.full
111 _scratch_cycle_mount
112
113 echo "Compare files"
114 md5sum $testdir/file1 | _filter_scratch
115 md5sum $testdir/file2 | _filter_scratch
116 md5sum $testdir/file3 | _filter_scratch
117
118 echo "Check extent counts"
119 old_extents=$(_count_extents $testdir/file1)
120 new_extents=$(_count_extents $testdir/file2)
121
122 echo "old extents: $old_extents" >> $seqres.full
123 echo "new extents: $new_extents" >> $seqres.full
124 echo "maximum extents: $internal_blks" >> $seqres.full
125 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
126         || echo "file2 badly fragmented"
127
128 new_extents=$(_count_extents $testdir/file3)
129
130 echo "old extents: $old_extents" >> $seqres.full
131 echo "new extents: $new_extents" >> $seqres.full
132 echo "maximum extents: $internal_blks" >> $seqres.full
133 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
134         || echo "file3 badly fragmented"
135
136 # success, all done
137 status=0
138 exit