Re: [PATCH v2 1/2] xfs: factor the mapping of one pNFS extent out of xfs_fs_map_blocks()
From: Christoph Hellwig
Date: Tue Dec 01 2026 - 03:17:54 EST
> + * can change in between, so a mapping that reaches back can overlap
> + * one already in the layout. Don't extend the mapping past EOF
> + * beyond the range either: xfs_free_eofblocks() can free blocks past
> + * EOF without breaking the layout.
> + */
> + error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb,
> + imap, &nimaps, XFS_BMAPI_ENTIRE);
> + if (error) {
> + xfs_iunlock(ip, lock_flags);
> + return error;
> + }
> + if (nimaps)
> + xfs_trim_extent(imap, offset_fsb,
> + max_t(xfs_fileoff_t, end_fsb,
> + XFS_B_TO_FSB(mp, XFS_ISIZE(ip))) -
> + offset_fsb);
nimaps must be non-NULL here (I should have spotted that in your
original patch adding the check).
> + *seq = xfs_iomap_inode_sequence(ip, 0);
> +
> + ASSERT(!nimaps || imap->br_startblock != DELAYSTARTBLOCK);
Or the very original addition. IIRC we used to have a corner case
where 0 nimaps with a 0 return value could happen, but we fied that a long
time ago.
> +
> + if (!write || (nimaps && imap->br_startblock != HOLESTARTBLOCK)) {
> + xfs_iunlock(ip, lock_flags);
> + return 0;
> + }
> +
> + if (end > XFS_ISIZE(ip))
> + end_fsb = xfs_iomap_eof_align_last_fsb(ip, end_fsb);
> + else if (nimaps)
> + end_fsb = min(end_fsb, imap->br_startoff + imap->br_blockcount);
> + xfs_iunlock(ip, lock_flags);
> +
> + error = xfs_iomap_write_direct(ip, offset_fsb, end_fsb - offset_fsb, 0,
> + imap, seq);
> + if (error)
> + return error;
> + *update_inode = true;
Maybe keep the original flow here that leaves the alloction is the more
exceptional path in the branch?
> + error = xfs_fs_map_extent(ip, XFS_B_TO_FSBT(mp, offset),
> + offset + length, write, &imap, &seq, &update_inode);
Passing the offset as FSB and the end as bytes is a bit odd. I'll
see if there is a good reason for that in the next patch, but in doubt
we should avoid this if possible.