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
32 # We require scratch so that we'll have free contiguous space
34 _scratch_mkfs >/dev/null 2>&1
39 fragfile=$SCRATCH_MNT/fragfile.$$
43 # Craft some fragmented files, defrag them, check the result.
44 bsize=$(_get_file_block_size $SCRATCH_MNT)
46 echo "zero-length file:" | tee -a $seqres.full
48 _defrag --before 0 --after 0 $fragfile
50 echo "Sparse file (no blocks):" | tee -a $seqres.full
51 $XFS_IO_PROG -f -c "truncate 1m" $fragfile
52 _defrag --before 0 --after 0 $fragfile
54 echo "Contiguous file:" | tee -a $seqres.full
55 $XFS_IO_PROG -f -c "pwrite -b $((4 * bsize)) 0 $((4 * bsize))" $fragfile \
57 _defrag --before 1 --after 1 $fragfile
59 echo "Write backwards sync, but contiguous - should defrag to 1 extent" | tee -a $seqres.full
60 for i in `seq 9 -1 0`; do
61 $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
65 # Accept fewer fragments than we might expect; we don't have perfect control.
66 _defrag --max_before 10 --min_before 5 --after 1 $fragfile
68 echo "Write backwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
69 for i in `seq 31 -2 0`; do
70 $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
73 _defrag --before 16 --after 16 $fragfile
75 echo "Write forwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
76 for i in `seq 0 2 31`; do
77 $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
80 _defrag --before 16 --after 16 $fragfile