diff mbox series

btrfs: test send clones extents with unaligned end offset ending at i_size

Message ID 177f429d65afb5cc99a7f950779ba15b130cd581.1723470203.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: test send clones extents with unaligned end offset ending at i_size | expand

Commit Message

Filipe Manana Aug. 12, 2024, 1:51 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

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@suse.com>
---
 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

Comments

David Sterba Aug. 12, 2024, 2:36 p.m. UTC | #1
On Mon, Aug 12, 2024 at 02:51:09PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> 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@suse.com>

Reviewed-by: David Sterba <dsterba@suse.com>
Qu Wenruo Aug. 12, 2024, 10:28 p.m. UTC | #2
在 2024/8/12 23:21, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> 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@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   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
Anand Jain Aug. 16, 2024, 10:58 a.m. UTC | #3
On 12/8/24 9:51 pm, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> 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@suse.com>


Reviewed-by: Anand Jain <anand.jain@oracle.com>

Zorro,

Could you please add this to the patches in queue? Since this is the 
only patch pending, I will not be sending a PR this week

Thx, Anand
Zorro Lang Aug. 16, 2024, 11:42 a.m. UTC | #4
On Fri, Aug 16, 2024 at 06:58:37PM +0800, Anand Jain wrote:
> On 12/8/24 9:51 pm, fdmanana@kernel.org wrote:
> > From: Filipe Manana <fdmanana@suse.com>
> > 
> > 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@suse.com>
> 
> 
> Reviewed-by: Anand Jain <anand.jain@oracle.com>
> 
> Zorro,
> 
> Could you please add this to the patches in queue? Since this is the only
> patch pending, I will not be sending a PR this week

Sure, thanks Anand :)

> 
> Thx, Anand
>
diff mbox series

Patch

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