[PATCH 25/33] xfs: plumb struct xfs_trans *tp into xfs_iomap_write_direct
Dave Chinner <[email protected]> Wed, 29 Jul 2026 20:02:09 +1000
| Newsgroups | org.kernel.vger.linux-xfs |
|---|---|
| Message-ID | <[email protected]> |
Add a struct xfs_trans *tp parameter to xfs_iomap_write_direct(). When a non-NULL transaction is provided, use it directly for the allocation instead of allocating one internally. The block reservation is added to the caller's transaction via xfs_trans_reserve_more_inode(). On success with a caller-supplied transaction, the function returns without committing or unlocking. On error, it returns the error without cancelling. When tp is NULL, the existing behaviour is preserved. All callers currently pass NULL, so there is no functional change. Assisted-by: LLM Signed-off-by: Dave Chinner <[email protected]> --- fs/xfs/xfs_iomap.c | 41 ++++++++++++++++++++++++++++------------- fs/xfs/xfs_iomap.h | 7 ++++--- fs/xfs/xfs_pnfs.c | 2 +- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index e43ce4811283..f3e4f243e877 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -267,6 +267,7 @@ xfs_iomap_eof_align_last_fsb( int xfs_iomap_write_direct( + struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t offset_fsb, xfs_fileoff_t count_fsb, @@ -275,7 +276,7 @@ xfs_iomap_write_direct( u64 *seq) { struct xfs_mount *mp = ip->i_mount; - struct xfs_trans *tp; + struct xfs_trans *local_tp = NULL; xfs_filblks_t resaligned; int nimaps; unsigned int dblocks, rblocks; @@ -296,7 +297,10 @@ xfs_iomap_write_direct( rblocks = 0; } - error = xfs_qm_dqattach(ip); + if (tp) + error = xfs_qm_dqattach_locked(ip, false); + else + error = xfs_qm_dqattach(ip); if (error) return error; @@ -322,10 +326,18 @@ xfs_iomap_write_direct( } } - error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, dblocks, - rblocks, force, &tp); - if (error) - return error; + if (tp) { + error = xfs_trans_reserve_more_inode(tp, ip, dblocks, rblocks, + force); + if (error) + return error; + } else { + error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, dblocks, + rblocks, force, &tp); + if (error) + return error; + local_tp = tp; + } error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, nr_exts); if (error) @@ -341,9 +353,9 @@ xfs_iomap_write_direct( if (error) goto out_trans_cancel; - /* - * Complete the transaction - */ + if (!local_tp) + return 0; + error = xfs_trans_commit(tp); if (error) goto out_unlock; @@ -359,8 +371,11 @@ xfs_iomap_write_direct( return error; out_trans_cancel: - xfs_trans_cancel(tp); - goto out_unlock; + if (local_tp) { + xfs_trans_cancel(tp); + goto out_unlock; + } + return error; } STATIC bool @@ -1154,8 +1169,8 @@ xfs_direct_write_iomap_begin( end_fsb = min(end_fsb, imap.br_startoff + imap.br_blockcount); xfs_iunlock(ip, lockmode); - error = xfs_iomap_write_direct(ip, offset_fsb, end_fsb - offset_fsb, - flags, &imap, &seq); + error = xfs_iomap_write_direct(NULL, ip, offset_fsb, + end_fsb - offset_fsb, flags, &imap, &seq); if (error) return error; diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h index ebcce7d49446..937a61c7a610 100644 --- a/fs/xfs/xfs_iomap.h +++ b/fs/xfs/xfs_iomap.h @@ -12,9 +12,10 @@ struct xfs_inode; struct xfs_bmbt_irec; struct xfs_zone_alloc_ctx; -int xfs_iomap_write_direct(struct xfs_inode *ip, xfs_fileoff_t offset_fsb, - xfs_fileoff_t count_fsb, unsigned int flags, - struct xfs_bmbt_irec *imap, u64 *sequence); +int xfs_iomap_write_direct(struct xfs_trans *tp, struct xfs_inode *ip, + xfs_fileoff_t offset_fsb, xfs_fileoff_t count_fsb, + unsigned int flags, struct xfs_bmbt_irec *imap, + u64 *sequence); int xfs_iomap_write_unwritten(struct xfs_inode *, xfs_off_t, xfs_off_t, bool); xfs_fileoff_t xfs_iomap_eof_align_last_fsb(struct xfs_inode *ip, xfs_fileoff_t end_fsb); diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c index f8535ecde21a..442564967b39 100644 --- a/fs/xfs/xfs_pnfs.c +++ b/fs/xfs/xfs_pnfs.c @@ -202,7 +202,7 @@ xfs_fs_map_blocks( imap.br_blockcount); xfs_iunlock(ip, lock_flags); - error = xfs_iomap_write_direct(ip, offset_fsb, + error = xfs_iomap_write_direct(NULL, ip, offset_fsb, end_fsb - offset_fsb, 0, &imap, &seq); if (error) goto out_unlock; -- 2.55.0