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
31 _require_scratch_reflink
32 _require_test_program "punch-alternating"
33 _require_xfs_io_command "fpunch"
37 _scratch_mkfs_sized $((512 * 1024 * 1024)) >>$seqres.full 2>&1
40 file_size=$(( 200 * 1024 * 1024 )) # 200Mb
42 # Create a file with many small extents.
43 $XFS_IO_PROG -f -c "pwrite -S 0xe5 -b $file_size 0 $file_size" \
44 $SCRATCH_MNT/foo >>/dev/null
45 $here/src/punch-alternating $SCRATCH_MNT/foo >> $seqres.full
47 # Create file bar with the same size that file foo has but with large extents.
48 $XFS_IO_PROG -f -c "pwrite -S 0xc7 -b $file_size 0 $file_size" \
49 $SCRATCH_MNT/bar >>/dev/null
51 # Fill the fs (For btrfs we are interested in filling all unallocated space
52 # and most of the existing metadata block group(s), so that after this there
53 # will be no unallocated space and metadata space will be mostly full but with
54 # more than enough free space for the clone operation below to succeed, we
55 # create files with 2Kb because that results in extents inlined in the metadata
56 # (btree leafs) and it's the fastest way to fill metadata space on btrfs, by
57 # default btrfs inlines up to 2Kb of data).
60 $XFS_IO_PROG -f -c "pwrite 0 2K" $SCRATCH_MNT/filler_$i &> /dev/null
65 # Now clone file bar into file foo. This is supposed to succeed and not fail
66 # with ENOSPC for example.
67 _reflink $SCRATCH_MNT/bar $SCRATCH_MNT/foo >>$seqres.full
69 # Unmount and mount the filesystem again to verify the operation was durably
73 echo "File foo data after cloning and remount:"
74 od -A d -t x1 $SCRATCH_MNT/foo