Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ding Feng" <dingf3ng@gmail.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH] generic: punch a hole past EOF over preallocated blocks
Date: Thu, 03 Dec 2026 09:30:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-247464@kernel.org> (raw)
In-Reply-To: <20261203091452.74081-1-dingf3ng@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] fstests: stat -c %b limit in generic/810 ignores inode
  metadata blocks
- [Medium] fstests: hardcoded 4k/1m offsets in generic/810 ignore file
  block size
- [Low] fstests: generic/810 leaves TEST_DIR test file behind without
  _cleanup()
--

commit ddbdf0d7928967d0167f771003c32e951506eb24
Author: Ding Feng <dingf3ng@gmail.com>

generic: punch a hole past EOF over preallocated blocks

This commit adds fstest generic/810 to verify that punching a hole past
EOF frees blocks preallocated with FALLOC_FL_KEEP_SIZE without changing
the file size or data below EOF.

> diff --git a/tests/generic/810 b/tests/generic/810
> new file mode 100755
> index 0000000000000..60f92b38a270f
> --- /dev/null
> +++ b/tests/generic/810

[ ... ]

> +file=$TEST_DIR/$seq.file
> +rm -f $file

[Severity: Low]
Should this test override _cleanup() to remove $file on exit?  TEST_DIR
persists across tests, and the default _cleanup() only removes $tmp.*,
leaving $TEST_DIR/$seq.file behind after every run or interruption.

> +
> +$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)

[Severity: Medium]
Can the hardcoded 4k, 1m, and 1020k offsets cause false failures or
vacuous passes depending on the file block size?

When bs does not divide 1m (such as an XFS realtime volume with a 12k
rextsize), xfs_bmap_extsize_align() rounds the falloc end past 1m while
xfs_free_file_space() rounds the fpunch end down, leaving the trailing
extent allocated and exceeding limit on a working filesystem.

When bs is 1m or larger (such as ext4 bigalloc or XFS rextsize >= 1m),
both pwrite and falloc fit in the first allocation unit.  Because the
test never checks allocated blocks before fpunch, it passes vacuously
even on a buggy kernel.

Querying bs first, scaling the write, preallocation, and punch ranges to
multiples of bs, and verifying that blocks past EOF were allocated before
punching would avoid both issues.

> +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"

[Severity: Medium]
Can this stat -c %b check fail spuriously because st_blocks includes
per-inode metadata blocks?

On ext4 with 128-byte inodes under SELinux or default ACLs,
ext4_xattr_block_set() charges an external xattr block to i_blocks (and
XFS similarly includes out-of-line attribute fork blocks in
xfs_vn_getattr()).

On a fragmented TEST_DIR, ext4_ext_grow_indepth() can also allocate an
extent-tree block that ext4_ext_remove_space() retains while the first
extent remains, leaving allocated above limit even when all post-EOF data
blocks are freed.

Checking data extents past EOF directly (for example with xfs_io fiemap)
or accounting for metadata blocks would avoid these false failures.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203091452.74081-1-dingf3ng@gmail.com?part=1

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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=sashiko-outbox-247464@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dingf3ng@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /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