* [PATCH] generic: test that insert range respects RLIMIT_FSIZE
@ 2026-12-03 10:53 Ding Feng
2026-12-03 11:08 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Ding Feng @ 2026-12-03 10:53 UTC (permalink / raw)
To: fstests; +Cc: zlang, hch, jack, dennylin0707, linux-ext4
FALLOC_FL_INSERT_RANGE grows a file by the length of the range, so it
must fail with EFBIG once the new size would exceed RLIMIT_FSIZE, as
truncate and extending fallocate do (generic/394, generic/228). XFS
refuses such an insert; ext4 checks only s_maxbytes and grows the file
past the limit.
Start from a 2-block file: inserting one block under a 2-block limit
must fail and leave the size unchanged, and the same insert under a
3-block limit must succeed.
Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Ding Feng <dingf3ng@gmail.com>
---
Tested on v7.4-rc5, x86_64 under QEMU:
ext4 fails: the insert under the 2-block limit succeeds, size 3
ext4 with "ext4: check RLIMIT_FSIZE in insert range" [1] passes
xfs passes, with and without that patch
[1] https://lore.kernel.org/all/20261116185810.82581-1-dennylin0707@gmail.com/
tests/generic/810 | 46 +++++++++++++++++++++++++++++++++++++++++++
tests/generic/810.out | 6 ++++++
2 files changed, 52 insertions(+)
create mode 100755 tests/generic/810
create mode 100644 tests/generic/810.out
diff --git a/tests/generic/810 b/tests/generic/810
new file mode 100755
index 00000000..25f5ece4
--- /dev/null
+++ b/tests/generic/810
@@ -0,0 +1,46 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Ding Feng. All Rights Reserved.
+#
+# FS QA Test No. 810
+#
+# Check that FALLOC_FL_INSERT_RANGE respects RLIMIT_FSIZE: an insert range
+# grows the file by its length, so it must fail with EFBIG when the new size
+# exceeds the limit, and leave the file size unchanged.
+#
+. ./common/preamble
+_begin_fstest auto quick insert prealloc
+
+_fixed_by_fs_commit ext4 xxxxxxxxxxxx \
+ "ext4: check RLIMIT_FSIZE in insert range"
+
+_require_test
+_require_xfs_io_command "finsert"
+
+file=$TEST_DIR/$seq.file
+
+# Insert range works in whole file blocks, and ulimit -f in 1 KiB units.
+unit=$(_get_file_block_size $TEST_DIR)
+[ $unit -lt 4096 ] && unit=4096
+
+# Run "finsert 0 $unit" on $file under an FSIZE limit of $1 units. SIGXFSZ is
+# ignored so that the call fails with EFBIG instead of killing xfs_io.
+insert_under_limit()
+{
+ bash -c "ulimit -f $(($1 * unit / 1024)); trap '' SIGXFSZ; \
+ $XFS_IO_PROG -c 'finsert 0 $unit' $file"
+ echo "size: $(($(stat -c %s $file) / unit)) units"
+}
+
+rm -f $file
+$XFS_IO_PROG -f -c "pwrite -S 0x61 0 $((2 * unit))" $file >> $seqres.full
+
+echo "Insert one unit into a 2-unit file under a 2-unit limit. This should fail."
+insert_under_limit 2
+
+echo "Insert one unit into a 2-unit file under a 3-unit limit. This should succeed."
+insert_under_limit 3
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/810.out b/tests/generic/810.out
new file mode 100644
index 00000000..7542704d
--- /dev/null
+++ b/tests/generic/810.out
@@ -0,0 +1,6 @@
+QA output created by 810
+Insert one unit into a 2-unit file under a 2-unit limit. This should fail.
+fallocate: File too large
+size: 2 units
+Insert one unit into a 2-unit file under a 3-unit limit. This should succeed.
+size: 3 units
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] generic: test that insert range respects RLIMIT_FSIZE
2026-12-03 10:53 [PATCH] generic: test that insert range respects RLIMIT_FSIZE Ding Feng
@ 2026-12-03 11:08 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 11:08 UTC (permalink / raw)
To: Ding Feng; +Cc: linux-ext4, tytso
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] generic/810: insert_under_limit() truncates ulimit -f for
non-KiB unit sizes
- [Low] fstests: missing _cleanup() in generic/810 leaves TEST_DIR file
--
commit cf8171da3dc9f8ba5bc63d270ae5caa9e2305ada
Author: Ding Feng <dingf3ng@gmail.com>
generic: test that insert range respects RLIMIT_FSIZE
This commit adds fstest generic/810 to verify that FALLOC_FL_INSERT_RANGE
fails with EFBIG when the resulting file size would exceed RLIMIT_FSIZE and
succeeds when within the limit.
> diff --git a/tests/generic/810 b/tests/generic/810
> new file mode 100755
> index 0000000000000..25f5ece4210b1
> --- /dev/null
> +++ b/tests/generic/810
> @@ -0,0 +1,46 @@
[ ... ]
> +. ./common/preamble
> +_begin_fstest auto quick insert prealloc
> +
> +_fixed_by_fs_commit ext4 xxxxxxxxxxxx \
> + "ext4: check RLIMIT_FSIZE in insert range"
> +
> +_require_test
> +_require_xfs_io_command "finsert"
> +
> +file=$TEST_DIR/$seq.file
[Severity: Low]
Does this leave $TEST_DIR/$seq.file behind after the test finishes?
common/preamble's default _cleanup() only removes $tmp.*, and this test only
removes $file during setup, so it remains on TEST_DIR after exit or failure.
Overriding _cleanup() to also remove $file would keep TEST_DIR clean.
> +
> +# Insert range works in whole file blocks, and ulimit -f in 1 KiB units.
> +unit=$(_get_file_block_size $TEST_DIR)
> +[ $unit -lt 4096 ] && unit=4096
> +
> +# Run "finsert 0 $unit" on $file under an FSIZE limit of $1 units. SIGXFSZ is
> +# ignored so that the call fails with EFBIG instead of killing xfs_io.
> +insert_under_limit()
> +{
> + bash -c "ulimit -f $(($1 * unit / 1024)); trap '' SIGXFSZ; \
> + $XFS_IO_PROG -c 'finsert 0 $unit' $file"
> + echo "size: $(($(stat -c %s $file) / unit)) units"
> +}
[Severity: Low]
Can ulimit -f $(($1 * unit / 1024)) truncate below $1 * unit and cause the
3-unit insert to fail with EFBIG?
On an XFS v4 filesystem with 512-byte blocks and an odd realtime extent size
(such as 9 blocks, or 4608 bytes), _get_file_block_size returns a value over
4096 that is not a multiple of 1024. insert_under_limit 3 then sets
RLIMIT_FSIZE to 13 KiB (13312 bytes) for a 13824-byte target size.
Doubling unit when unit % 1024 is non-zero preserves allocation-unit
alignment while making $1 * unit an exact multiple of 1024.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203105330.65937-1-dingf3ng@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 11:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 10:53 [PATCH] generic: test that insert range respects RLIMIT_FSIZE Ding Feng
2026-12-03 11:08 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox