xfs: kill xfs_trans_set/clear_context() helpers

Open code the helpers so that tp->t_pflags access is explicit, reducing
the risk of misusing them outside the transaction owner thread as seen
in xfs_btree_split_worker().

Suggested-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
This commit is contained in:
Kefeng Wang 2026-11-03 18:56:54 +08:00 committed by Carlos Maiolino
parent 30bb61651d
commit 7ba9663607
3 changed files with 7 additions and 21 deletions

View File

@ -3009,10 +3009,6 @@ xfs_btree_split_worker(
struct xfs_btree_split_args, work);
unsigned int nofs_flags;
/*
* Don't use xfs_trans_set_context() here: it would overwrite the
* caller's saved NOFS state in tp->t_pflags. Use a local scope.
*/
nofs_flags = memalloc_nofs_save();
args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,

View File

@ -264,20 +264,6 @@ int xfs_trans_alloc_dir(struct xfs_inode *dp, struct xfs_trans_res *resv,
struct xfs_inode *ip, unsigned int *dblocks,
struct xfs_trans **tpp, int *nospace_error);
static inline void
xfs_trans_set_context(
struct xfs_trans *tp)
{
tp->t_pflags = memalloc_nofs_save();
}
static inline void
xfs_trans_clear_context(
struct xfs_trans *tp)
{
memalloc_nofs_restore(tp->t_pflags);
}
static inline void
xfs_trans_cancel(
struct xfs_trans *tp)

View File

@ -72,7 +72,7 @@ xfs_trans_free(
xfs_extent_busy_clear(&tp->t_busy, false);
trace_xfs_trans_free(tp, _RET_IP_);
xfs_trans_clear_context(tp);
memalloc_nofs_restore(tp->t_pflags);
if (!(tp->t_flags & XFS_TRANS_NO_WRITECOUNT))
sb_end_intwrite(tp->t_mountp->m_super);
xfs_trans_free_dqinfo(tp);
@ -220,7 +220,11 @@ __xfs_trans_alloc(
tp = kmem_cache_zalloc(xfs_trans_cache, GFP_KERNEL | __GFP_NOFAIL);
if (!(flags & XFS_TRANS_NO_WRITECOUNT))
sb_start_intwrite(mp->m_super);
xfs_trans_set_context(tp);
/*
* Save NOFS state for xfs_trans_free() to restore. Only the
* transaction owner thread may touch tp->t_pflags.
*/
tp->t_pflags = memalloc_nofs_save();
tp->t_flags = flags;
tp->t_mountp = mp;
INIT_LIST_HEAD(&tp->t_items);
@ -1038,7 +1042,7 @@ xfs_trans_roll(
* xfs_trans_free. Set it again here before doing memory
* allocations.
*/
xfs_trans_set_context(tp);
tp->t_pflags = memalloc_nofs_save();
if (error)
return error;