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 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
29 # real QA test starts here
33 # We require scratch so that we'll have free contiguous space
35 _scratch_mkfs >/dev/null 2>&1
40 fragfile=$SCRATCH_MNT/fragfile.$$
44 # Craft some fragmented files, defrag them, check the result.
45 bsize=$(_get_file_block_size $SCRATCH_MNT)
47 echo "zero-length file:" | tee -a $seqres.full
49 _defrag --before 0 --after 0 $fragfile
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
55 echo "Contiguous file:" | tee -a $seqres.full
56 $XFS_IO_PROG -f -c "pwrite -b $((4 * bsize)) 0 $((4 * bsize))" $fragfile \
58 _defrag --before 1 --after 1 $fragfile
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 \
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
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 \
74 _defrag --before 16 --after 16 $fragfile
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 \
81 _defrag --before 16 --after 16 $fragfile