From fc46966ce3d53f0106620637dce2f3221da75124 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Mon, 6 Oct 2025 14:40:17 +0200 Subject: [PATCH] xfs: return the allocated transaction from xfs_trans_alloc_empty Source kernel commit: d8e1ea43e5a314bc01ec059ce93396639dcf9112 xfs_trans_alloc_empty can't return errors, so return the allocated transaction directly instead of an output double pointer argument. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino Signed-off-by: Andrey Albershteyn Reviewed-by: "Darrick J. Wong" --- db/attrset.c | 6 +----- db/dquot.c | 4 +--- db/fsmap.c | 8 +------- db/info.c | 8 +------- db/namei.c | 4 +--- db/rdump.c | 7 +------ include/xfs_trans.h | 2 +- libxfs/inode.c | 4 +--- libxfs/trans.c | 33 ++++++++++++++++++++------------- libxfs/xfs_refcount.c | 4 +--- repair/phase2.c | 6 +----- repair/pptr.c | 4 ++-- repair/quotacheck.c | 9 ++------- repair/rcbag.c | 8 ++------ repair/rmap.c | 4 +--- repair/rt.c | 10 ++-------- 16 files changed, 39 insertions(+), 82 deletions(-) diff --git a/db/attrset.c b/db/attrset.c index e3ffb75a..273c2029 100644 --- a/db/attrset.c +++ b/db/attrset.c @@ -823,11 +823,7 @@ attr_list_f( return 0; } - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) { - dbprintf(_("failed to allocate empty transaction\n")); - return 0; - } + tp = libxfs_trans_alloc_empty(mp); error = -libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip); if (error) { diff --git a/db/dquot.c b/db/dquot.c index d2c76fd7..c028d50e 100644 --- a/db/dquot.c +++ b/db/dquot.c @@ -92,9 +92,7 @@ dqtype_to_inode( xfs_ino_t ret = NULLFSINO; int error; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - return NULLFSINO; + tp = libxfs_trans_alloc_empty(mp); if (xfs_has_metadir(mp)) { error = -libxfs_dqinode_load_parent(tp, &dp); diff --git a/db/fsmap.c b/db/fsmap.c index ddbe4e6a..a59a4d12 100644 --- a/db/fsmap.c +++ b/db/fsmap.c @@ -133,13 +133,7 @@ fsmap_rtgroup( struct xfs_btree_cur *bt_cur; int error; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) { - dbprintf( - _("Cannot alloc transaction to look up rtgroup %u rmap inode\n"), - rtg_rgno(rtg)); - return error; - } + tp = libxfs_trans_alloc_empty(mp); error = -libxfs_rtginode_load_parent(tp); if (error) { diff --git a/db/info.c b/db/info.c index 6ad3e238..9c233c9c 100644 --- a/db/info.c +++ b/db/info.c @@ -174,13 +174,7 @@ print_rgresv_info( xfs_filblks_t used = 0; int error; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) { - dbprintf( - _("Cannot alloc transaction to look up rtgroup %u rmap inode\n"), - rtg_rgno(rtg)); - return; - } + tp = libxfs_trans_alloc_empty(mp); error = -libxfs_rtginode_load_parent(tp); if (error) { diff --git a/db/namei.c b/db/namei.c index 1d9581c3..0a50ec87 100644 --- a/db/namei.c +++ b/db/namei.c @@ -94,9 +94,7 @@ path_navigate( unsigned int i; int error; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - return error; + tp = libxfs_trans_alloc_empty(mp); error = -libxfs_iget(mp, tp, ino, 0, &dp); if (error) diff --git a/db/rdump.c b/db/rdump.c index a50df4b8..599d0727 100644 --- a/db/rdump.c +++ b/db/rdump.c @@ -926,15 +926,10 @@ rdump_path( set_cur_inode(mp->m_sb.sb_rootino); } - ret = -libxfs_trans_alloc_empty(mp, &tp); - if (ret) { - dbprintf(_("allocating state: %s\n"), strerror(ret)); - goto out_pbuf; - } + tp = libxfs_trans_alloc_empty(mp); ret = rdump_file(tp, iocur_top->ino, destdir, pbuf); libxfs_trans_cancel(tp); -out_pbuf: free(pbuf); return ret; } diff --git a/include/xfs_trans.h b/include/xfs_trans.h index 24806401..4f4bfff3 100644 --- a/include/xfs_trans.h +++ b/include/xfs_trans.h @@ -98,7 +98,7 @@ int libxfs_trans_alloc_dir(struct xfs_inode *dp, struct xfs_trans_res *resv, struct xfs_trans **tpp, int *nospace_error); int libxfs_trans_alloc_rollable(struct xfs_mount *mp, uint blocks, struct xfs_trans **tpp); -int libxfs_trans_alloc_empty(struct xfs_mount *mp, struct xfs_trans **tpp); +struct xfs_trans *libxfs_trans_alloc_empty(struct xfs_mount *mp); int libxfs_trans_commit(struct xfs_trans *); void libxfs_trans_cancel(struct xfs_trans *); int libxfs_trans_reserve_more(struct xfs_trans *tp, uint blocks, diff --git a/libxfs/inode.c b/libxfs/inode.c index 0598a70f..1ce159fc 100644 --- a/libxfs/inode.c +++ b/libxfs/inode.c @@ -258,9 +258,7 @@ libxfs_metafile_iget( struct xfs_trans *tp; int error; - error = libxfs_trans_alloc_empty(mp, &tp); - if (error) - return error; + tp = libxfs_trans_alloc_empty(mp); error = libxfs_trans_metafile_iget(tp, ino, metafile_type, ipp); libxfs_trans_cancel(tp); diff --git a/libxfs/trans.c b/libxfs/trans.c index 5c896ba1..64457d17 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -247,6 +247,22 @@ undo_blocks: return error; } +static inline struct xfs_trans * +__libxfs_trans_alloc( + struct xfs_mount *mp, + uint flags) +{ + struct xfs_trans *tp; + + tp = kmem_cache_zalloc(xfs_trans_cache, 0); + tp->t_mountp = mp; + INIT_LIST_HEAD(&tp->t_items); + INIT_LIST_HEAD(&tp->t_dfops); + tp->t_highest_agno = NULLAGNUMBER; + + return tp; +} + int libxfs_trans_alloc( struct xfs_mount *mp, @@ -257,15 +273,9 @@ libxfs_trans_alloc( struct xfs_trans **tpp) { - struct xfs_trans *tp; + struct xfs_trans *tp = __libxfs_trans_alloc(mp, flags); int error; - tp = kmem_cache_zalloc(xfs_trans_cache, 0); - tp->t_mountp = mp; - INIT_LIST_HEAD(&tp->t_items); - INIT_LIST_HEAD(&tp->t_dfops); - tp->t_highest_agno = NULLAGNUMBER; - error = xfs_trans_reserve(tp, resp, blocks, rtextents); if (error) { xfs_trans_cancel(tp); @@ -290,14 +300,11 @@ libxfs_trans_alloc( * Note the zero-length reservation; this transaction MUST be cancelled * without any dirty data. */ -int +struct xfs_trans * libxfs_trans_alloc_empty( - struct xfs_mount *mp, - struct xfs_trans **tpp) + struct xfs_mount *mp) { - struct xfs_trans_res resv = {0}; - - return xfs_trans_alloc(mp, &resv, 0, 0, XFS_TRANS_NO_WRITECOUNT, tpp); + return __libxfs_trans_alloc(mp, XFS_TRANS_NO_WRITECOUNT); } /* diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 1000bab2..4d31c337 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -2097,9 +2097,7 @@ xfs_refcount_recover_cow_leftovers( * recording the CoW debris we cancel the (empty) transaction * and everything goes away cleanly. */ - error = xfs_trans_alloc_empty(mp, &tp); - if (error) - return error; + tp = xfs_trans_alloc_empty(mp); if (isrt) { xfs_rtgroup_lock(to_rtg(xg), XFS_RTGLOCK_REFCOUNT); diff --git a/repair/phase2.c b/repair/phase2.c index e2499805..fc96f9c4 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -296,11 +296,7 @@ check_fs_free_space( * there while we try to make a per-AG reservation with the new * geometry. */ - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - do_error( - _("Cannot reserve resources for upgrade check, err=%d.\n"), - error); + tp = libxfs_trans_alloc_empty(mp); error = -libxfs_ialloc_read_agi(pag, tp, 0, &agi_bp); if (error) diff --git a/repair/pptr.c b/repair/pptr.c index ac0a9c61..6a9e072b 100644 --- a/repair/pptr.c +++ b/repair/pptr.c @@ -1217,7 +1217,7 @@ check_file_parent_ptrs( fscan->have_garbage = false; fscan->nr_file_pptrs = 0; - libxfs_trans_alloc_empty(ip->i_mount, &tp); + tp = libxfs_trans_alloc_empty(ip->i_mount); error = xattr_walk(tp, ip, examine_xattr, fscan); if (tp) libxfs_trans_cancel(tp); @@ -1417,7 +1417,7 @@ try_erase_parent_ptrs( do_error("init garbage pptr names failed: %s\n", strerror(error)); - libxfs_trans_alloc_empty(ip->i_mount, &tp); + tp = libxfs_trans_alloc_empty(ip->i_mount); error = xattr_walk(tp, ip, erase_pptrs, &fscan); if (tp) libxfs_trans_cancel(tp); diff --git a/repair/quotacheck.c b/repair/quotacheck.c index df6cde2d..f4c03141 100644 --- a/repair/quotacheck.c +++ b/repair/quotacheck.c @@ -437,9 +437,7 @@ quotacheck_verify( if (!dquots || !chkd_flags) return; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - do_error(_("could not alloc transaction to open quota file\n")); + tp = libxfs_trans_alloc_empty(mp); ino = get_quota_inode(type); error = -libxfs_trans_metafile_iget(tp, ino, metafile_type, &ip); @@ -679,9 +677,7 @@ discover_quota_inodes( struct xfs_inode *dp = NULL; int error, err2; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - goto out; + tp = libxfs_trans_alloc_empty(mp); error = -libxfs_dqinode_load_parent(tp, &dp); if (error) @@ -698,7 +694,6 @@ discover_quota_inodes( libxfs_irele(dp); out_cancel: libxfs_trans_cancel(tp); -out: if (error) { switch (error) { case EFSCORRUPTED: diff --git a/repair/rcbag.c b/repair/rcbag.c index 21732b65..d7addbf5 100644 --- a/repair/rcbag.c +++ b/repair/rcbag.c @@ -95,9 +95,7 @@ rcbag_add( int has; int error; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - do_error(_("allocating tx for refcount bag update\n")); + tp = libxfs_trans_alloc_empty(mp); cur = rcbagbt_mem_cursor(mp, tp, &bag->xfbtree); error = rcbagbt_lookup_eq(cur, rmap, &has); @@ -217,9 +215,7 @@ rcbag_remove_ending_at( int has; int error; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - do_error(_("allocating tx for refcount bag update\n")); + tp = libxfs_trans_alloc_empty(mp); /* go to the right edge of the tree */ cur = rcbagbt_mem_cursor(mp, tp, &bag->xfbtree); diff --git a/repair/rmap.c b/repair/rmap.c index 97510dd8..e89bd32d 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -323,9 +323,7 @@ rmap_add_mem_rec( int error; xfbt = &rmaps_for_group(isrt, agno)->ar_xfbtree; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - do_error(_("allocating tx for in-memory rmap update\n")); + tp = libxfs_trans_alloc_empty(mp); error = rmap_init_mem_cursor(mp, tp, isrt, agno, &rmcur); if (error) diff --git a/repair/rt.c b/repair/rt.c index 1ac2bf6f..781d8968 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -301,10 +301,7 @@ try_load_sb_rtfile( if (rtg->rtg_inodes[type]) goto out_rtg; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - goto out_rtg; - + tp = libxfs_trans_alloc_empty(mp); error = -libxfs_rtginode_load(rtg, type, tp); if (error) @@ -497,9 +494,7 @@ discover_rtgroup_inodes( int error, err2; int i; - error = -libxfs_trans_alloc_empty(mp, &tp); - if (error) - goto out; + tp = libxfs_trans_alloc_empty(mp); if (xfs_has_rtgroups(mp) && mp->m_sb.sb_rgcount > 0) { error = -libxfs_rtginode_load_parent(tp); if (error) @@ -516,7 +511,6 @@ discover_rtgroup_inodes( out_cancel: libxfs_trans_cancel(tp); -out: if (xfs_has_rtgroups(mp) && error) { /* * Old xfs_repair didn't complain if rtbitmaps didn't load -- 2.47.3