2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Eric Sandeen. All Rights Reserved.
5 # FS QA Test No. generic/018
7 # Basic defragmentation sanity tests
10 _begin_fstest auto fsr quick defrag
12 # Import common functions.
16 # real QA test starts here
19 # We require scratch so that we'll have free contiguous space
21 _scratch_mkfs >/dev/null 2>&1
26 fragfile=$SCRATCH_MNT/fragfile.$$
30 # Craft some fragmented files, defrag them, check the result.
31 bsize=$(_get_file_block_size $SCRATCH_MNT)
33 echo "zero-length file:" | tee -a $seqres.full
35 _defrag --before 0 --after 0 $fragfile
37 echo "Sparse file (no blocks):" | tee -a $seqres.full
38 $XFS_IO_PROG -f -c "truncate 1m" $fragfile
39 _defrag --before 0 --after 0 $fragfile
41 echo "Contiguous file:" | tee -a $seqres.full
42 $XFS_IO_PROG -f -c "pwrite -b $((4 * bsize)) 0 $((4 * bsize))" $fragfile \
44 _defrag --before 1 --after 1 $fragfile
46 echo "Write backwards sync, but contiguous - should defrag to 1 extent" | tee -a $seqres.full
47 for i in `seq 9 -1 0`; do
48 $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
52 # Accept fewer fragments than we might expect; we don't have perfect control.
53 _defrag --max_before 10 --min_before 5 --after 1 $fragfile
55 echo "Write backwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
56 for i in `seq 31 -2 0`; do
57 $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
60 _defrag --before 16 --after 16 $fragfile
62 echo "Write forwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
63 for i in `seq 0 2 31`; do
64 $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
67 _defrag --before 16 --after 16 $fragfile