[PATCH 0/7] ntfs: delayed allocation accounting and stale data fixes, part 1

From: Ernest Borowski via B4 Relay

Date: Sun Nov 22 2026 - 13:20:06 EST


A write/truncate/punch-hole stress test on a 128 MiB volume showed the
free space reported by statfs() falling from 79 MB to zero within 80
seconds, after which writes failed with ENOSPC or came back short, while
$Bitmap stayed correct. The reservations that delayed allocation keeps
in vol->dirty_clusters were not given back on several paths. The short
writes then exposed a second bug, the file keeping the full size of the
write, which Zhan Xusheng's "ntfs: trim the sizes after a short write"
[1] fixes.

Patches 1, 2, 3 and 5 fix the reservation accounting: truncate of dirty
delalloc data, hole filling by fallocate()/direct I/O/page_mkwrite()
that consumed other files' reservations, removal of named streams and
eviction, and buffered writes that fail after ->iomap_begin() reserved
space. Patch 4 fixes the runlist split helpers, which turned a delalloc
run into a run of real clusters when a punch, collapse or insert split
it (reachable through the stale runs patch 5 removes; it corrupted
$Bitmap).

Patches 6 and 7 fix stale data exposure in buffered writes into holes.
The page cache zeroing of the partial first and last cluster gave up as
soon as writeback (the flusher, or FIEMAP_FLAG_SYNC) allocated the new
delalloc run, and a copy that stops inside a new cluster left the rest
of it unzeroed; in both cases the reallocated clusters showed what they
held before, below initialized_size. Patch 7 also covers a writer
killed by SIGKILL in the middle of the copy: iomap_zero_range() refuses
to run for a task with a fatal signal pending, so the zeroing then runs
from a worker. [1] needs the same for its own zeroing after a short
write; I suggested the change in reply to it, and whichever lands second
can share one copy of the helper.

Six more patches of the same work (a failed cluster allocation that
drops every file's reservation, st_blocks of delalloc data, and the
remaining stale data windows of write faults, writeback and direct I/O
into holes) follow as part 2: they need rebasing onto the current
ntfs-next first.

Each patch has a reproducer that fails before and passes after it. The
reproducers run in QEMU on a kernel with KASAN, lockdep and UBSAN, at
512 B, 4 KiB, 16 KiB and 64 KiB clusters, with ntfsck -n after every
case. On ntfs-next f674e4b6c315 this series makes short_copy_stale,
delalloc_accounting, delalloc_failed_write, delalloc_zero_race and
stale_wb_race pass, and every test that passed before still passes; the
same holds with [1] and the change suggested for it applied as well.
The tests and the runs, on Ubuntu 26.04 and Arch Linux:

tests: https://github.com/xerrni/linux-ntfs
ntfs-next: https://github.com/xerrni/linux-ntfs/actions/runs/45032649068
ntfs-next + this series: https://github.com/xerrni/linux-ntfs/actions/runs/45029297643
ntfs-next + [1] + the suggested change + this series:
https://github.com/xerrni/linux-ntfs/actions/runs/45029305849

[1] https://lore.kernel.org/all/20261120023504.4134966-1-zhanxusheng1024@xxxxxxxxx/

---
Ernest Borowski (7):
ntfs: release delalloc reservations cut off by truncate
ntfs: do not consume delalloc reservations when filling holes
ntfs: release the delalloc reservations of an evicted inode
ntfs: do not shift the cluster number of a delalloc run on split
ntfs: punch out the delalloc reservation of a failed buffered write
ntfs: zero new delalloc clusters even when writeback allocates them
ntfs: zero the rest of a new cluster after a short buffered write

fs/ntfs/attrib.c | 106 +++++++++++++++++-
fs/ntfs/attrib.h | 2 +
fs/ntfs/inode.c | 12 ++-
fs/ntfs/iomap.c | 316 +++++++++++++++++++++++++++++++++++++++++++-----------
fs/ntfs/runlist.c | 13 +--
5 files changed, 378 insertions(+), 71 deletions(-)
---
base-commit: f674e4b6c315ebe742d08af80659386992d58ce9
change-id: 20261122-b4-ntfs-delalloc-fixes-5ba9d4e97353

Best regards,
--
Ernest Borowski <ernest.borowski.git@xxxxxxxxx>