2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that if we clone a file with some large extents into a file that has
8 # many small extents, when the fs is nearly full, the clone operation does
9 # not fail and produces the correct result.
12 seqres=$RESULT_DIR/$seq
13 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 _require_scratch_reflink
33 _require_test_program "punch-alternating"
34 _require_xfs_io_command "fpunch"
38 _scratch_mkfs_sized $((512 * 1024 * 1024)) >>$seqres.full 2>&1
41 file_size=$(( 200 * 1024 * 1024 )) # 200Mb
43 # Create a file with many small extents.
44 $XFS_IO_PROG -f -c "pwrite -S 0xe5 -b $file_size 0 $file_size" \
45 $SCRATCH_MNT/foo >>/dev/null
46 $here/src/punch-alternating $SCRATCH_MNT/foo >> $seqres.full
48 # Create file bar with the same size that file foo has but with large extents.
49 $XFS_IO_PROG -f -c "pwrite -S 0xc7 -b $file_size 0 $file_size" \
50 $SCRATCH_MNT/bar >>/dev/null
52 # Fill the fs (For btrfs we are interested in filling all unallocated space
53 # and most of the existing metadata block group(s), so that after this there
54 # will be no unallocated space and metadata space will be mostly full but with
55 # more than enough free space for the clone operation below to succeed, we
56 # create files with 2Kb because that results in extents inlined in the metadata
57 # (btree leafs) and it's the fastest way to fill metadata space on btrfs, by
58 # default btrfs inlines up to 2Kb of data).
61 $XFS_IO_PROG -f -c "pwrite 0 2K" $SCRATCH_MNT/filler_$i &> /dev/null
66 # Now clone file bar into file foo. This is supposed to succeed and not fail
67 # with ENOSPC for example.
68 _reflink $SCRATCH_MNT/bar $SCRATCH_MNT/foo >>$seqres.full
70 # Unmount and mount the filesystem again to verify the operation was durably
74 echo "File foo data after cloning and remount:"
75 od -A d -t x1 $SCRATCH_MNT/foo