70ece651a3adba573529ac9b212fbe320ea48a35
[xfstests-dev.git] / tests / shared / 218
1 #! /bin/bash
2 # FS QA Test No. 218
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 seqres=$RESULT_DIR/$seq
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 -f $tmp.*
39     _cleanup_testdir
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/defrag
46
47 # real QA test starts here
48 _supported_fs xfs ext4 btrfs
49 _supported_os Linux
50
51 _setup_testdir
52 # We require scratch so that we'll have free contiguous space
53 _require_scratch
54 _scratch_mkfs >/dev/null 2>&1
55 _scratch_mount
56
57 _require_defrag
58
59 fragfile=$SCRATCH_MNT/fragfile.$$
60
61 rm -f $fragfile
62
63 # Craft some fragmented files, defrag them, check the result.
64
65 echo "zero-length file:" | tee -a $seqres.full
66 touch $fragfile
67 _defrag $fragfile
68
69 echo "Sparse file (no blocks):" | tee -a $seqres.full
70 xfs_io -F -f -c "truncate 1m" $fragfile
71 _defrag $fragfile
72
73 echo "Contiguous file:" | tee -a $seqres.full
74 dd if=/dev/zero of=$fragfile bs=4k count=4 &>/dev/null
75 _defrag $fragfile
76
77 echo "Write backwards sync, but contiguous - should defrag to 1 extent" | tee -a $seqres.full
78 for I in `seq 9 -1 0`; do
79         dd if=/dev/zero of=$fragfile bs=4k count=1 conv=notrunc seek=$I oflag=sync &>/dev/null
80 done
81 _defrag $fragfile
82
83 echo "Write backwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
84 for I in `seq 31 -2 0`; do
85         dd if=/dev/zero of=$fragfile bs=4k count=1 conv=notrunc seek=$I oflag=sync &>/dev/null
86 done
87 _defrag $fragfile
88
89 echo "Write forwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
90 for I in `seq 0 2 31`; do
91         dd if=/dev/zero of=$fragfile bs=4k count=1 conv=notrunc seek=$I oflag=sync &>/dev/null
92 done
93 _defrag $fragfile
94
95 rm -f $seqres.full
96 status=0
97 exit