generic: add _require_odirect to generic/113 and generic/214
[xfstests-dev.git] / tests / generic / 018
1 #! /bin/bash
2 # FS QA Test No. generic/018
3 #
4 # Basic defragmentation sanity tests
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2009 Eric Sandeen.  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 15
32
33 _cleanup()
34 {
35     cd /
36     rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 . ./common/defrag
43
44 # real QA test starts here
45 _supported_fs generic
46 _supported_os Linux
47
48 # We require scratch so that we'll have free contiguous space
49 _require_scratch
50 _scratch_mkfs >/dev/null 2>&1
51 _scratch_mount
52
53 _require_defrag
54
55 fragfile=$SCRATCH_MNT/fragfile.$$
56
57 rm -f $fragfile
58
59 # Craft some fragmented files, defrag them, check the result.
60 bsize=4096
61
62 echo "zero-length file:" | tee -a $seqres.full
63 touch $fragfile
64 _defrag --before 0 --after 0 $fragfile
65
66 echo "Sparse file (no blocks):" | tee -a $seqres.full
67 $XFS_IO_PROG -f -c "truncate 1m" $fragfile
68 _defrag --before 0 --after 0 $fragfile
69
70 echo "Contiguous file:" | tee -a $seqres.full
71 $XFS_IO_PROG -f -c "pwrite -b $((4 * bsize)) 0 $((4 * bsize))" $fragfile \
72                                         > /dev/null
73 _defrag --before 1 --after 1 $fragfile
74
75 echo "Write backwards sync, but contiguous - should defrag to 1 extent" | tee -a $seqres.full
76 for i in `seq 9 -1 0`; do
77         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
78                                         > /dev/null
79 done
80
81 # Accept fewer fragments than we might expect; we don't have perfect control.
82 _defrag --max_before 10 --min_before 5 --after 1 $fragfile
83
84 echo "Write backwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
85 for i in `seq 31 -2 0`; do
86         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
87                                         > /dev/null
88 done
89 _defrag --before 16 --after 16 $fragfile
90
91 echo "Write forwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
92 for i in `seq 0 2 31`; do
93         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
94                                         > /dev/null
95 done
96 _defrag --before 16 --after 16 $fragfile
97
98 rm -f $seqres.full
99 status=0
100 exit