RE:(2) [PATCH 2/8] xfs: refuse a direct allocation whose block reservation would wrap

From: Daejun Park

Date: Sun Oct 11 2026 - 22:48:09 EST


On Thu, Oct 08, 2026 at 08:40:17AM -0700, Darrick J. Wong wrote:
> Uh... seeing as extent records can only map 2^21 blocks maximum and
> iomap/pnfs can handle xfs returning a mapping of whatever length we
> want, why don't we constrain count_fsb to XFS_BMBT_MAX_EXTLEN?

I tried that first. It stops the wrap, but it changes what an RW
LAYOUTGET for a range longer than the free space does. Today
xfs_iomap_write_direct() reserves the whole count, so such a request
fails with -ENOSPC before anything is allocated. With the count capped,
each ->map_blocks call allocates up to 2^21 blocks, and nfsd calls it
once per extent, so the request allocates until the filesystem is full
and then fails.

On a 32 GiB XFS with nfsd-testing at the time, an RW LAYOUTGET at offset
0 of an empty file for 16 TiB, or to the end of the file, got
NFS4ERR_NOSPC with the cap, and df showed 25 GiB in use afterwards
instead of 663 MiB. The blocks stay past EOF, as each call that
allocated marked the inode XFS_DIFLAG_PREALLOC. One for 100 GiB gets
NFS4ERR_NOSPC with nothing allocated, both without this patch and with
it.

The check in this patch only refuses a count whose reservation does not
fit in an unsigned int, so a count that fits is handled as before.