* [PATCH] generic: add a test case for fallocate i_size extension
@ 2026-05-19 17:14 fdmanana
2026-05-19 22:08 ` Qu Wenruo
2026-05-20 6:20 ` Zorro Lang
0 siblings, 2 replies; 3+ messages in thread
From: fdmanana @ 2026-05-19 17:14 UTC (permalink / raw)
To: fstests; +Cc: linux-btrfs, Filipe Manana
From: Filipe Manana <fdmanana@suse.com>
Test an i_size expanding fallocate into a range beyond current i_size that
already has a preallocated extent, with an unmount and mount after each
fallocate to verify that no metadata (i_size) and extents were lost.
This used to fail on btrfs when not using the no-holes feature (which is
a default since btrfs-progs 5.15) before this recent kernel fix:
c562ba61fc5e ("btrfs: fix incorrect i_size after remount caused by KEEP_SIZE prealloc gap")
So in order to reproduce the failure when using an unpatched kernel and
a btrfs-progs >= 5.15, one must run the test with:
MKFS_OPTIONS="-O ^no-holes"
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
tests/generic/795 | 52 +++++++++++++++++++++++++++++++++++++++++++
tests/generic/795.out | 5 +++++
2 files changed, 57 insertions(+)
create mode 100755 tests/generic/795
create mode 100644 tests/generic/795.out
diff --git a/tests/generic/795 b/tests/generic/795
new file mode 100755
index 00000000..299c8134
--- /dev/null
+++ b/tests/generic/795
@@ -0,0 +1,52 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A. All Rights Reserved.
+#
+# FS QA Test 795
+#
+# Test an i_size expanding fallocate into a range beyond current i_size that
+# already has a preallocated extent, with an unmount and mount after each
+# fallocate to verify that no metadata (i_size) and extents were lost.
+#
+. ./common/preamble
+_begin_fstest auto quick prealloc fiemap
+
+. ./common/punch # for _filter_fiemap
+
+_require_scratch
+_require_xfs_io_command "falloc" "-k"
+_require_xfs_io_command "fiemap"
+
+_fixed_by_fs_commit btrfs c562ba61fc5e \
+ "btrfs: fix incorrect i_size after remount caused by KEEP_SIZE prealloc gap"
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount
+
+# The fiemap results in the golden output requires file allocations to align to
+# 1M boundaries.
+_require_congruent_file_oplen $SCRATCH_MNT 1048576
+
+# Create our file with a size of 0 and a prealloc extent in the range [4M, 8M].
+$XFS_IO_PROG -f -c "falloc -k 4M 4M" $SCRATCH_MNT/foo
+
+# Unmount and mount again to remove any in memory state of the inode. We will
+# verify later that neither metadata nor extents were lost during unmount.
+_scratch_cycle_mount
+
+# Do an i_size expanding fallocate that overlaps the previous prealloc range
+# and extents past it. This increases the file size to 9M and allocates an
+# extent in the range [8M, 9M].
+$XFS_IO_PROG -c "falloc 7M 2M" $SCRATCH_MNT/foo
+
+# Unmount and mount again to remove any in memory state of the inode. We will
+# verify later that neither metadata nor extents were lost during unmount.
+_scratch_cycle_mount
+
+# File size should be 9M and we should have unwritten extents in range [4M, 9M].
+echo "File size after cycle mounts: $(stat -c %s $SCRATCH_MNT/foo)"
+echo "Fiemap output:"
+$XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foo | _filter_fiemap
+
+# Success, all done.
+_exit 0
diff --git a/tests/generic/795.out b/tests/generic/795.out
new file mode 100644
index 00000000..b2f78ac0
--- /dev/null
+++ b/tests/generic/795.out
@@ -0,0 +1,5 @@
+QA output created by 795
+File size after cycle mounts: 9437184
+Fiemap output:
+0: [0..8191]: hole
+1: [8192..18431]: unwritten
--
2.47.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] generic: add a test case for fallocate i_size extension
2026-05-19 17:14 [PATCH] generic: add a test case for fallocate i_size extension fdmanana
@ 2026-05-19 22:08 ` Qu Wenruo
2026-05-20 6:20 ` Zorro Lang
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2026-05-19 22:08 UTC (permalink / raw)
To: fdmanana, fstests; +Cc: linux-btrfs, Filipe Manana
在 2026/5/20 02:44, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> Test an i_size expanding fallocate into a range beyond current i_size that
> already has a preallocated extent, with an unmount and mount after each
> fallocate to verify that no metadata (i_size) and extents were lost.
>
> This used to fail on btrfs when not using the no-holes feature (which is
> a default since btrfs-progs 5.15) before this recent kernel fix:
>
> c562ba61fc5e ("btrfs: fix incorrect i_size after remount caused by KEEP_SIZE prealloc gap")
>
> So in order to reproduce the failure when using an unpatched kernel and
> a btrfs-progs >= 5.15, one must run the test with:
>
> MKFS_OPTIONS="-O ^no-holes"
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> tests/generic/795 | 52 +++++++++++++++++++++++++++++++++++++++++++
> tests/generic/795.out | 5 +++++
> 2 files changed, 57 insertions(+)
> create mode 100755 tests/generic/795
> create mode 100644 tests/generic/795.out
>
> diff --git a/tests/generic/795 b/tests/generic/795
> new file mode 100755
> index 00000000..299c8134
> --- /dev/null
> +++ b/tests/generic/795
> @@ -0,0 +1,52 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2026 SUSE S.A. All Rights Reserved.
> +#
> +# FS QA Test 795
> +#
> +# Test an i_size expanding fallocate into a range beyond current i_size that
> +# already has a preallocated extent, with an unmount and mount after each
> +# fallocate to verify that no metadata (i_size) and extents were lost.
> +#
> +. ./common/preamble
> +_begin_fstest auto quick prealloc fiemap
> +
> +. ./common/punch # for _filter_fiemap
> +
> +_require_scratch
> +_require_xfs_io_command "falloc" "-k"
> +_require_xfs_io_command "fiemap"
> +
> +_fixed_by_fs_commit btrfs c562ba61fc5e \
> + "btrfs: fix incorrect i_size after remount caused by KEEP_SIZE prealloc gap"
> +
> +_scratch_mkfs >>$seqres.full 2>&1
> +_scratch_mount
> +
> +# The fiemap results in the golden output requires file allocations to align to
> +# 1M boundaries.
> +_require_congruent_file_oplen $SCRATCH_MNT 1048576
> +
> +# Create our file with a size of 0 and a prealloc extent in the range [4M, 8M].
> +$XFS_IO_PROG -f -c "falloc -k 4M 4M" $SCRATCH_MNT/foo
> +
> +# Unmount and mount again to remove any in memory state of the inode. We will
> +# verify later that neither metadata nor extents were lost during unmount.
> +_scratch_cycle_mount
> +
> +# Do an i_size expanding fallocate that overlaps the previous prealloc range
> +# and extents past it. This increases the file size to 9M and allocates an
> +# extent in the range [8M, 9M].
> +$XFS_IO_PROG -c "falloc 7M 2M" $SCRATCH_MNT/foo
> +
> +# Unmount and mount again to remove any in memory state of the inode. We will
> +# verify later that neither metadata nor extents were lost during unmount.
> +_scratch_cycle_mount
> +
> +# File size should be 9M and we should have unwritten extents in range [4M, 9M].
> +echo "File size after cycle mounts: $(stat -c %s $SCRATCH_MNT/foo)"
> +echo "Fiemap output:"
> +$XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foo | _filter_fiemap
> +
> +# Success, all done.
> +_exit 0
> diff --git a/tests/generic/795.out b/tests/generic/795.out
> new file mode 100644
> index 00000000..b2f78ac0
> --- /dev/null
> +++ b/tests/generic/795.out
> @@ -0,0 +1,5 @@
> +QA output created by 795
> +File size after cycle mounts: 9437184
> +Fiemap output:
> +0: [0..8191]: hole
> +1: [8192..18431]: unwritten
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] generic: add a test case for fallocate i_size extension
2026-05-19 17:14 [PATCH] generic: add a test case for fallocate i_size extension fdmanana
2026-05-19 22:08 ` Qu Wenruo
@ 2026-05-20 6:20 ` Zorro Lang
1 sibling, 0 replies; 3+ messages in thread
From: Zorro Lang @ 2026-05-20 6:20 UTC (permalink / raw)
To: fdmanana; +Cc: fstests, linux-btrfs, Filipe Manana
On Tue, May 19, 2026 at 06:14:10PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> Test an i_size expanding fallocate into a range beyond current i_size that
> already has a preallocated extent, with an unmount and mount after each
> fallocate to verify that no metadata (i_size) and extents were lost.
>
> This used to fail on btrfs when not using the no-holes feature (which is
> a default since btrfs-progs 5.15) before this recent kernel fix:
>
> c562ba61fc5e ("btrfs: fix incorrect i_size after remount caused by KEEP_SIZE prealloc gap")
>
> So in order to reproduce the failure when using an unpatched kernel and
> a btrfs-progs >= 5.15, one must run the test with:
>
> MKFS_OPTIONS="-O ^no-holes"
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
Classic, Filipe! As standard as always. Even the tiny details like comments,
groups, _require_congruent_file_oplen and so on are perfect.
Reviewed-by: Zorro Lang <zlang@kernel.org>
> tests/generic/795 | 52 +++++++++++++++++++++++++++++++++++++++++++
> tests/generic/795.out | 5 +++++
> 2 files changed, 57 insertions(+)
> create mode 100755 tests/generic/795
> create mode 100644 tests/generic/795.out
>
> diff --git a/tests/generic/795 b/tests/generic/795
> new file mode 100755
> index 00000000..299c8134
> --- /dev/null
> +++ b/tests/generic/795
> @@ -0,0 +1,52 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2026 SUSE S.A. All Rights Reserved.
> +#
> +# FS QA Test 795
> +#
> +# Test an i_size expanding fallocate into a range beyond current i_size that
> +# already has a preallocated extent, with an unmount and mount after each
> +# fallocate to verify that no metadata (i_size) and extents were lost.
> +#
> +. ./common/preamble
> +_begin_fstest auto quick prealloc fiemap
> +
> +. ./common/punch # for _filter_fiemap
> +
> +_require_scratch
> +_require_xfs_io_command "falloc" "-k"
> +_require_xfs_io_command "fiemap"
> +
> +_fixed_by_fs_commit btrfs c562ba61fc5e \
> + "btrfs: fix incorrect i_size after remount caused by KEEP_SIZE prealloc gap"
> +
> +_scratch_mkfs >>$seqres.full 2>&1
> +_scratch_mount
> +
> +# The fiemap results in the golden output requires file allocations to align to
> +# 1M boundaries.
> +_require_congruent_file_oplen $SCRATCH_MNT 1048576
> +
> +# Create our file with a size of 0 and a prealloc extent in the range [4M, 8M].
> +$XFS_IO_PROG -f -c "falloc -k 4M 4M" $SCRATCH_MNT/foo
> +
> +# Unmount and mount again to remove any in memory state of the inode. We will
> +# verify later that neither metadata nor extents were lost during unmount.
> +_scratch_cycle_mount
> +
> +# Do an i_size expanding fallocate that overlaps the previous prealloc range
> +# and extents past it. This increases the file size to 9M and allocates an
> +# extent in the range [8M, 9M].
> +$XFS_IO_PROG -c "falloc 7M 2M" $SCRATCH_MNT/foo
> +
> +# Unmount and mount again to remove any in memory state of the inode. We will
> +# verify later that neither metadata nor extents were lost during unmount.
> +_scratch_cycle_mount
> +
> +# File size should be 9M and we should have unwritten extents in range [4M, 9M].
> +echo "File size after cycle mounts: $(stat -c %s $SCRATCH_MNT/foo)"
> +echo "Fiemap output:"
> +$XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foo | _filter_fiemap
> +
> +# Success, all done.
> +_exit 0
> diff --git a/tests/generic/795.out b/tests/generic/795.out
> new file mode 100644
> index 00000000..b2f78ac0
> --- /dev/null
> +++ b/tests/generic/795.out
> @@ -0,0 +1,5 @@
> +QA output created by 795
> +File size after cycle mounts: 9437184
> +Fiemap output:
> +0: [0..8191]: hole
> +1: [8192..18431]: unwritten
> --
> 2.47.2
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-20 6:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19 17:14 [PATCH] generic: add a test case for fallocate i_size extension fdmanana
2026-05-19 22:08 ` Qu Wenruo
2026-05-20 6:20 ` Zorro Lang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox