* [PATCH v2] generic: punch a hole past EOF over preallocated blocks
@ 2026-12-03 11:52 Ding Feng
0 siblings, 0 replies; only message in thread
From: Ding Feng @ 2026-12-03 11:52 UTC (permalink / raw)
To: zlang; +Cc: 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 one block, preallocate 16 blocks with KEEP_SIZE, punch the 15
blocks past EOF, and check with fiemap that no extent is left there, and
that the size and the data below EOF are unchanged.
Signed-off-by: Ding Feng <dingf3ng@gmail.com>
---
v2, from the Sashiko review [1]:
- Look for extents past EOF with fiemap instead of reading st_blocks,
which also counts xattr and extent tree blocks.
- Size the write, the preallocation and the punch in file blocks, and
skip the test when falloc -k allocates nothing past EOF.
- Remove the test file on exit.
- Renumbered to 811: 810 is "generic: test that insert range respects
RLIMIT_FSIZE".
On v7.4-rc5, x86_64 under QEMU, it fails on ext4 (an unwritten extent
stays past EOF), passes with v2 of "ext4: punch hole beyond i_size",
and passes on XFS with and without it.
v1: https://lore.kernel.org/all/20261203091452.74081-1-dingf3ng@gmail.com/
[1] https://lore.kernel.org/all/sashiko-outbox-247464@kernel.org/
tests/generic/811 | 52 +++++++++++++++++++++++++++++++++++++++++++
tests/generic/811.out | 2 ++
2 files changed, 54 insertions(+)
create mode 100755 tests/generic/811
create mode 100644 tests/generic/811.out
diff --git a/tests/generic/811 b/tests/generic/811
new file mode 100755
index 00000000..b8ec6a2e
--- /dev/null
+++ b/tests/generic/811
@@ -0,0 +1,52 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Ding Feng. All Rights Reserved.
+#
+# FS QA Test No. 811
+#
+# 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
+
+# Override the default cleanup function.
+_cleanup()
+{
+ cd /
+ rm -f $tmp.* $file
+}
+
+_fixed_by_fs_commit ext4 xxxxxxxxxxxx \
+ "ext4: punch hole beyond i_size"
+
+_require_test
+_require_xfs_io_command "falloc" "-k"
+_require_xfs_io_command "fpunch"
+_require_xfs_io_command "fiemap" "ranged"
+
+file=$TEST_DIR/$seq.file
+bs=$(_get_file_block_size $TEST_DIR)
+
+# Print the extents of $file in [$bs, 16 * $bs), holes left out.
+extents_past_eof()
+{
+ $XFS_IO_PROG -c "fiemap $bs $((15 * bs))" $file | tail -n +2 | grep -v hole
+}
+
+rm -f $file
+$XFS_IO_PROG -f -c "pwrite -S 0x61 0 $bs" -c "falloc -k 0 $((16 * bs))" \
+ -c fsync $file >> $seqres.full
+[ -n "$(extents_past_eof)" ] || _notrun "falloc -k allocated nothing past EOF"
+before=$(md5sum < $file)
+
+$XFS_IO_PROG -c "fpunch $bs $((15 * bs))" -c fsync $file >> $seqres.full
+
+extents_past_eof
+[ $(stat -c %s $file) -eq $bs ] || 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/811.out b/tests/generic/811.out
new file mode 100644
index 00000000..cf30f69b
--- /dev/null
+++ b/tests/generic/811.out
@@ -0,0 +1,2 @@
+QA output created by 811
+Silence is golden
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-03 11:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 11:52 [PATCH v2] generic: punch a hole past EOF over preallocated blocks Ding Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox