All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ding Feng <dingf3ng@gmail.com>
To: zlang@kernel.org
Cc: fstests@vger.kernel.org, linux-ext4@vger.kernel.org
Subject: [PATCH v2] generic: punch a hole past EOF over preallocated blocks
Date: Thu,  3 Dec 2026 19:52:29 +0800	[thread overview]
Message-ID: <20261203115229.50163-1-dingf3ng@gmail.com> (raw)

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


             reply	other threads:[~2026-12-03 11:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 11:52 Ding Feng [this message]
2026-12-03 12:01 ` [PATCH v2] generic: punch a hole past EOF over preallocated blocks sashiko-bot

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=20261203115229.50163-1-dingf3ng@gmail.com \
    --to=dingf3ng@gmail.com \
    --cc=fstests@vger.kernel.org \
    --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.