fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 328
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 328
6 #
7 # See how well xfs_fsr handles "defragging" a file with a hojillion extents.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick clone fsr
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/attr
15 . ./common/reflink
16
17 # real QA test starts here
18 _supported_fs xfs
19 _require_scratch_reflink
20 _require_cp_reflink
21 _require_test_program "punch-alternating"
22 _require_xfs_io_command "falloc" # used in FSR
23 _require_command "$XFS_FSR_PROG" "xfs_fsr"
24
25 rm -f "$seqres.full"
26
27 echo "Format and mount"
28 _scratch_mkfs > "$seqres.full" 2>&1
29 _scratch_mount >> "$seqres.full" 2>&1
30
31 testdir="$SCRATCH_MNT/test-$seq"
32 mkdir "$testdir"
33
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))
40 calc_space()
41 {
42         blocks_needed=$(( 2 ** (fnr + 1) ))
43         space_needed=$((blocks_needed * blksz * 5 / 4))
44 }
45 calc_space
46 while test $space_needed -gt $space_avail; do
47         fnr=$((fnr - 1))
48         calc_space
49 done
50 test $fnr -lt 10 && _notrun "Insufficient space for stress test; would only create $blocks_needed extents."
51 bytes=$((blocks_needed * blksz))
52
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
61 done
62 echo "...done" >> "$seqres.full"
63 _scratch_cycle_mount
64
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"
68
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)
73
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"
79
80 # success, all done
81 status=0
82 exit