2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # See how well reflink handles reflinking a file with a million extents.
10 _begin_fstest auto clone punch
12 # Import common functions.
17 # real QA test starts here
18 _require_scratch_reflink
20 _require_xfs_io_command "fpunch"
21 _require_test_program "punch-alternating"
25 echo "Format and mount"
26 _scratch_mkfs > "$seqres.full" 2>&1
27 _scratch_mount >> "$seqres.full" 2>&1
29 testdir="$SCRATCH_MNT/test-$seq"
32 # Setup for one million blocks, but we'll accept stress testing down to
33 # 2^17 blocks... that should be plenty for anyone.
35 free_blocks=$(stat -f -c '%a' "$testdir")
36 blksz=$(_get_block_size "$testdir")
37 space_avail=$((free_blocks * blksz))
39 blocks_needed=$(( 2 ** (fnr + 1) ))
40 space_needed=$((blocks_needed * blksz * 5 / 4))
43 while test $space_needed -gt $space_avail; do
47 test $fnr -lt 17 && _notrun "Insufficient space for stress test; would only create $blocks_needed extents."
49 echo "Create a many-block file"
50 echo "creating $blocks_needed blocks..." >> "$seqres.full"
51 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b 4194304 0 $((2 ** (fnr + 1) * blksz))" "$testdir/file1" >> "$seqres.full"
52 echo "punching..." >> "$seqres.full"
53 "$here/src/punch-alternating" "$testdir/file1" >> "$seqres.full"
54 echo "...done" >> "$seqres.full"
57 echo "Reflink the big file"
58 bytes=$((blocks_needed * blksz))
59 echo "reflinking $((blocks_needed / 2)) blocks, $((bytes / 2)) bytes" >> "$seqres.full"
60 _reflink_range "$testdir/file1" 0 "$testdir/file2" 0 $bytes >> "$seqres.full"