generic/520: Remove sync in clean_dir
[xfstests-dev.git] / tests / generic / 018
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Eric Sandeen.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/018
6 #
7 # Basic defragmentation sanity tests
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/defrag
28
29 # real QA test starts here
30 _supported_fs generic
31 _supported_os Linux
32
33 # We require scratch so that we'll have free contiguous space
34 _require_scratch
35 _scratch_mkfs >/dev/null 2>&1
36 _scratch_mount
37
38 _require_defrag
39
40 fragfile=$SCRATCH_MNT/fragfile.$$
41
42 rm -f $fragfile
43
44 # Craft some fragmented files, defrag them, check the result.
45 bsize=$(_get_file_block_size $SCRATCH_MNT)
46
47 echo "zero-length file:" | tee -a $seqres.full
48 touch $fragfile
49 _defrag --before 0 --after 0 $fragfile
50
51 echo "Sparse file (no blocks):" | tee -a $seqres.full
52 $XFS_IO_PROG -f -c "truncate 1m" $fragfile
53 _defrag --before 0 --after 0 $fragfile
54
55 echo "Contiguous file:" | tee -a $seqres.full
56 $XFS_IO_PROG -f -c "pwrite -b $((4 * bsize)) 0 $((4 * bsize))" $fragfile \
57                                         > /dev/null
58 _defrag --before 1 --after 1 $fragfile
59
60 echo "Write backwards sync, but contiguous - should defrag to 1 extent" | tee -a $seqres.full
61 for i in `seq 9 -1 0`; do
62         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
63                                         > /dev/null
64 done
65
66 # Accept fewer fragments than we might expect; we don't have perfect control.
67 _defrag --max_before 10 --min_before 5 --after 1 $fragfile
68
69 echo "Write backwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
70 for i in `seq 31 -2 0`; do
71         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
72                                         > /dev/null
73 done
74 _defrag --before 16 --after 16 $fragfile
75
76 echo "Write forwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
77 for i in `seq 0 2 31`; do
78         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
79                                         > /dev/null
80 done
81 _defrag --before 16 --after 16 $fragfile
82
83 rm -f $seqres.full
84 status=0
85 exit