All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ding Feng <dingf3ng@gmail.com>
To: fstests@vger.kernel.org
Cc: zlang@kernel.org, hch@infradead.org, jack@suse.cz,
	dennylin0707@gmail.com, linux-ext4@vger.kernel.org
Subject: [PATCH] generic: test that insert range respects RLIMIT_FSIZE
Date: Thu,  3 Dec 2026 18:53:30 +0800	[thread overview]
Message-ID: <20261203105330.65937-1-dingf3ng@gmail.com> (raw)

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


             reply	other threads:[~2026-12-03 10:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 10:53 Ding Feng [this message]
2026-12-03 11:08 ` [PATCH] generic: test that insert range respects RLIMIT_FSIZE sashiko-bot
2026-12-04  8:46 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203105330.65937-1-dingf3ng@gmail.com \
    --to=dingf3ng@gmail.com \
    --cc=dennylin0707@gmail.com \
    --cc=fstests@vger.kernel.org \
    --cc=hch@infradead.org \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=zlang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.