2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # See how well xfs_fsr handles "defragging" a file with a hojillion extents.
10 _begin_fstest auto quick clone fsr
12 # Import common functions.
17 # real QA test starts here
19 _require_scratch_reflink
21 _require_test_program "punch-alternating"
22 _require_xfs_io_command "falloc" # used in FSR
23 _require_command "$XFS_FSR_PROG" "xfs_fsr"
27 echo "Format and mount"
28 _scratch_mkfs > "$seqres.full" 2>&1
29 _scratch_mount >> "$seqres.full" 2>&1
31 testdir="$SCRATCH_MNT/test-$seq"
34 # Setup for 16000 blocks, but we'll accept stress testing down to
35 # 2^10 blocks... that should be plenty for anyone.
36 fnr=$((12 + LOAD_FACTOR))
37 free_blocks=$(stat -f -c '%a' "$testdir")
38 blksz=$(_get_file_block_size $testdir)
39 space_avail=$((free_blocks * blksz))
42 blocks_needed=$(( 2 ** (fnr + 1) ))
43 space_needed=$((blocks_needed * blksz * 5 / 4))
46 while test $space_needed -gt $space_avail; do
50 test $fnr -lt 10 && _notrun "Insufficient space for stress test; would only create $blocks_needed extents."
51 bytes=$((blocks_needed * blksz))
53 echo "Create a many-block file"
54 echo "creating $blocks_needed blocks..." >> "$seqres.full"
55 _pwrite_byte 0x62 0 $blksz $testdir/file0 >> $seqres.full
56 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b 4194304 0 $bytes" "$testdir/file1" >> "$seqres.full"
57 echo "punching..." >> "$seqres.full"
58 "$here/src/punch-alternating" "$testdir/file1" >> "$seqres.full"
59 seq 0 2 $((2 ** (fnr + 1) )) | while read lblk; do
60 _reflink_range $testdir/file0 0 $testdir/file1 $((lblk * blksz)) $blksz >> $seqres.full
62 echo "...done" >> "$seqres.full"
65 echo "Reflink the big file"
66 echo "reflinking $((blocks_needed / 2)) blocks, $((bytes / 2)) bytes" >> "$seqres.full"
67 _reflink_range "$testdir/file1" 0 "$testdir/file2" 0 $bytes >> "$seqres.full"
69 echo "Defrag the big file"
70 old_nextents=$(_count_extents $testdir/file1)
71 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full
72 new_nextents=$(_count_extents $testdir/file1)
74 echo "Check extent count"
75 $XFS_IO_PROG -c 'stat -v' $testdir/file1 >> $seqres.full
76 $XFS_IO_PROG -c 'stat -v' $testdir/file2 >> $seqres.full
77 echo "extents: $old_nextents -> $new_nextents" >> $seqres.full
78 test $old_nextents -gt $new_nextents || echo "FAIL: $old_nextents -> $new_nextents"