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 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
30 # real QA test starts here
32 _require_scratch_reflink
34 _require_test_program "punch-alternating"
35 _require_xfs_io_command "falloc" # used in FSR
36 _require_command "$XFS_FSR_PROG" "xfs_fsr"
40 echo "Format and mount"
41 _scratch_mkfs > "$seqres.full" 2>&1
42 _scratch_mount >> "$seqres.full" 2>&1
44 testdir="$SCRATCH_MNT/test-$seq"
47 # Setup for 16000 blocks, but we'll accept stress testing down to
48 # 2^10 blocks... that should be plenty for anyone.
49 fnr=$((12 + LOAD_FACTOR))
50 free_blocks=$(stat -f -c '%a' "$testdir")
51 blksz=$(_get_file_block_size $testdir)
52 space_avail=$((free_blocks * blksz))
55 blocks_needed=$(( 2 ** (fnr + 1) ))
56 space_needed=$((blocks_needed * blksz * 5 / 4))
59 while test $space_needed -gt $space_avail; do
63 test $fnr -lt 10 && _notrun "Insufficient space for stress test; would only create $blocks_needed extents."
64 bytes=$((blocks_needed * blksz))
66 echo "Create a many-block file"
67 echo "creating $blocks_needed blocks..." >> "$seqres.full"
68 _pwrite_byte 0x62 0 $blksz $testdir/file0 >> $seqres.full
69 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b 4194304 0 $bytes" "$testdir/file1" >> "$seqres.full"
70 echo "punching..." >> "$seqres.full"
71 "$here/src/punch-alternating" "$testdir/file1" >> "$seqres.full"
72 seq 0 2 $((2 ** (fnr + 1) )) | while read lblk; do
73 _reflink_range $testdir/file0 0 $testdir/file1 $((lblk * blksz)) $blksz >> $seqres.full
75 echo "...done" >> "$seqres.full"
78 echo "Reflink the big file"
79 echo "reflinking $((blocks_needed / 2)) blocks, $((bytes / 2)) bytes" >> "$seqres.full"
80 _reflink_range "$testdir/file1" 0 "$testdir/file2" 0 $bytes >> "$seqres.full"
82 echo "Defrag the big file"
83 old_nextents=$(_count_extents $testdir/file1)
84 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full
85 new_nextents=$(_count_extents $testdir/file1)
87 echo "Check extent count"
88 $XFS_IO_PROG -c 'stat -v' $testdir/file1 >> $seqres.full
89 $XFS_IO_PROG -c 'stat -v' $testdir/file2 >> $seqres.full
90 echo "extents: $old_nextents -> $new_nextents" >> $seqres.full
91 test $old_nextents -gt $new_nextents || echo "FAIL: $old_nextents -> $new_nextents"