From: Filipe Manana <fdmanana@xxxxxxxx> Test that a send operation will issue a clone operation for a shared extent of a file if the extent ends at the i_size of the file and the i_size is not sector size aligned. This verifies an improvement to the btrfs send feature implemented by the following kernel patch: "btrfs: send: allow cloning non-aligned extent if it ends at i_size" Signed-off-by: Filipe Manana <fdmanana@xxxxxxxx> --- tests/btrfs/319 | 80 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/319.out | 16 +++++++++ 2 files changed, 96 insertions(+) create mode 100755 tests/btrfs/319 create mode 100644 tests/btrfs/319.out diff --git a/tests/btrfs/319 b/tests/btrfs/319 new file mode 100755 index 00000000..2fe80185 --- /dev/null +++ b/tests/btrfs/319 @@ -0,0 +1,80 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2024 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 319 +# +# Test that a send operation will issue a clone operation for a shared extent +# of a file if the extent ends at the i_size of the file and the i_size is not +# sector size aligned. +# +. ./common/preamble +_begin_fstest auto quick send clone fiemap + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -fr $tmp.* + rm -fr $send_files_dir +} + +. ./common/filter +. ./common/reflink +. ./common/punch # for _filter_fiemap_flags + +_require_test +_require_scratch_reflink +_require_cp_reflink +_require_xfs_io_command "fiemap" +_require_odirect + +_fixed_by_kernel_commit xxxxxxxxxxxx \ + "btrfs: send: allow cloning non-aligned extent if it ends at i_size" + +send_files_dir=$TEST_DIR/btrfs-test-$seq +send_stream=$send_files_dir/snap.stream + +rm -fr $send_files_dir +mkdir $send_files_dir + +_scratch_mkfs >> $seqres.full 2>&1 || _fail "first mkfs failed" +_scratch_mount + +# Use a file size that is not aligned to any possible sector size (1M + 5 bytes). +file_size=$((1024 * 1024 + 5)) +# Use O_DIRECT to guarantee a single extent. +$XFS_IO_PROG -f -d -c "pwrite -S 0xab -b $file_size 0 $file_size" \ + $SCRATCH_MNT/foo | _filter_xfs_io + +# Clone the file. +_cp_reflink $SCRATCH_MNT/foo $SCRATCH_MNT/bar + +echo "Creating snapshot and a send stream for it..." +_btrfs subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap +$BTRFS_UTIL_PROG send -f $send_stream $SCRATCH_MNT/snap >> $seqres.full 2>&1 + +echo "File digests in the original filesystem:" +md5sum $SCRATCH_MNT/snap/foo | _filter_scratch +md5sum $SCRATCH_MNT/snap/bar | _filter_scratch + +echo "File bar fiemap in the original filesystem:" +$XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap/bar | _filter_fiemap_flags + +echo "Creating a new filesystem to receive the send stream..." +_scratch_unmount +_scratch_mkfs >> $seqres.full 2>&1 || _fail "second mkfs failed" +_scratch_mount + +$BTRFS_UTIL_PROG receive -f $send_stream $SCRATCH_MNT + +echo "File digests in the new filesystem:" +md5sum $SCRATCH_MNT/snap/foo | _filter_scratch +md5sum $SCRATCH_MNT/snap/bar | _filter_scratch + +echo "File bar fiemap in the new filesystem:" +$XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap/bar | _filter_fiemap_flags + +# success, all done +status=0 +exit diff --git a/tests/btrfs/319.out b/tests/btrfs/319.out new file mode 100644 index 00000000..14079dbe --- /dev/null +++ b/tests/btrfs/319.out @@ -0,0 +1,16 @@ +QA output created by 319 +wrote 1048581/1048581 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Creating snapshot and a send stream for it... +File digests in the original filesystem: +e61178ee0288ebe3fa36a3c975b02c94 SCRATCH_MNT/snap/foo +e61178ee0288ebe3fa36a3c975b02c94 SCRATCH_MNT/snap/bar +File bar fiemap in the original filesystem: +0: [0..2055]: shared|last +Creating a new filesystem to receive the send stream... +At subvol snap +File digests in the new filesystem: +e61178ee0288ebe3fa36a3c975b02c94 SCRATCH_MNT/snap/foo +e61178ee0288ebe3fa36a3c975b02c94 SCRATCH_MNT/snap/bar +File bar fiemap in the new filesystem: +0: [0..2055]: shared|last -- 2.43.0