Linux EXT4 FS development
 help / color / mirror / Atom feed
* [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

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