Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] generic: punch a hole past EOF over preallocated blocks
@ 2026-12-03  9:14 Ding Feng
  2026-12-03  9:30 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ding Feng @ 2026-12-03  9:14 UTC (permalink / raw)
  To: Zorro Lang; +Cc: Ding Feng, fstests, linux-ext4

Blocks that fallocate(FALLOC_FL_KEEP_SIZE) allocates past EOF should be
freed by a later FALLOC_FL_PUNCH_HOLE over them; fallocate(2) says whole
blocks in the range are removed. XFS and tmpfs do so. ext4 returns
early for a hole that starts at or past i_size and leaves them allocated.

Write 4k, preallocate 1M with KEEP_SIZE, punch [4k, 1M), and check that at
most the block holding EOF stays allocated, and that the size and the data
below EOF are unchanged.

On v7.4-rc5 this fails on ext4 (1048576 bytes stay allocated) and passes on
XFS. It passes on ext4 with "ext4: punch hole beyond i_size", sent to
linux-ext4.

Signed-off-by: Ding Feng <dingf3ng@gmail.com>
---
 tests/generic/810     | 37 ++++++++++++++++++++++++++++++
 tests/generic/810.out |  2 ++
 2 files changed, 39 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
--- /dev/null
+++ b/tests/generic/810
@@ -0,0 +1,37 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Ding Feng.  All Rights Reserved.
+#
+# FS QA Test No. 810
+#
+# Punch a hole past EOF over blocks preallocated with FALLOC_FL_KEEP_SIZE
+# and check that the blocks are freed while the size and the data below
+# EOF stay unchanged.
+#
+. ./common/preamble
+_begin_fstest auto quick punch prealloc
+
+_require_test
+_require_xfs_io_command "falloc" "-k"
+_require_xfs_io_command "fpunch"
+
+file=$TEST_DIR/$seq.file
+rm -f $file
+
+$XFS_IO_PROG -f -c "pwrite -S 0x61 0 4k" -c "falloc -k 0 1m" -c fsync \
+	$file >> $seqres.full
+before=$(md5sum < $file)
+
+$XFS_IO_PROG -c "fpunch 4k 1020k" -c fsync $file >> $seqres.full
+
+bs=$(_get_file_block_size $TEST_DIR)
+limit=$(( (4096 + bs - 1) / bs * bs ))
+allocated=$(( $(stat -c %b $file) * 512 ))
+[ $allocated -le $limit ] || \
+	echo "$allocated bytes allocated after punching past EOF, expected at most $limit"
+[ $(stat -c %s $file) -eq 4096 ] || echo "size changed to $(stat -c %s $file)"
+[ "$(md5sum < $file)" = "$before" ] || echo "data below EOF changed"
+
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/generic/810.out b/tests/generic/810.out
new file mode 100644
--- /dev/null
+++ b/tests/generic/810.out
@@ -0,0 +1,2 @@
+QA output created by 810
+Silence is golden

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03  9:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  9:14 [PATCH] generic: punch a hole past EOF over preallocated blocks Ding Feng
2026-12-03  9:30 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox