FS/XFS testing framework
 help / color / mirror / Atom feed
From: Ding Feng <dingf3ng@gmail.com>
To: Zorro Lang <zlang@kernel.org>
Cc: Ding Feng <dingf3ng@gmail.com>,
	fstests@vger.kernel.org, linux-ext4@vger.kernel.org
Subject: [PATCH] generic: punch a hole past EOF over preallocated blocks
Date: Thu,  3 Dec 2026 17:14:52 +0800	[thread overview]
Message-ID: <20261203091452.74081-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 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

                 reply	other threads:[~2026-12-03  9:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261203091452.74081-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox