]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: return the allocated transaction from xfs_trans_alloc_empty
authorChristoph Hellwig <hch@lst.de>
Mon, 6 Oct 2025 12:40:17 +0000 (14:40 +0200)
committerAndrey Albershteyn <aalbersh@kernel.org>
Mon, 13 Oct 2025 09:53:39 +0000 (11:53 +0200)
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 <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
16 files changed:
db/attrset.c
db/dquot.c
db/fsmap.c
db/info.c
db/namei.c
db/rdump.c
include/xfs_trans.h
libxfs/inode.c
libxfs/trans.c
libxfs/xfs_refcount.c
repair/phase2.c
repair/pptr.c
repair/quotacheck.c
repair/rcbag.c
repair/rmap.c
repair/rt.c

index e3ffb75aa448321a5790a8b1d9aa5af6f1987e90..273c202956004703b46294ae9b485cf54b80d6e5 100644 (file)
@@ -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) {
index d2c76fd70bf1a6a30699dad17f8657c4cee560df..c028d50e4ca4e613c2dbbc6e8eaf171d252f3040 100644 (file)
@@ -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);
index ddbe4e6a3dfcfa5f292b2f1f7fd712c517993138..a59a4d12303026c6b409db2595452ed314e2ddc3 100644 (file)
@@ -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) {
index 6ad3e23832faa36e834b8a95a779e220b58edb60..9c233c9c0e6602e2dfb71a93d726350e96e07f78 100644 (file)
--- 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) {
index 1d9581c323cd6775cb83d7093448f6d38e9c913e..0a50ec87df9f540abb2c814313d0ef3bed5381a6 100644 (file)
@@ -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)
index a50df4b8c72302901cd07d636b7971b443111e88..599d0727e78892d293d825a8f446bbb7d8dc148b 100644 (file)
@@ -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;
 }
index 248064019a0ab567d0c0ba3022ed10f043d2689b..4f4bfff350a4c45763eb220f78a4c9d42355fc78 100644 (file)
@@ -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,
index 0598a70ff504a465f031f8d27a6c511528808c3f..1ce159fcc9d61a82cccbc98fad4084f579c98675 100644 (file)
@@ -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);
index 5c896ba1661b10d6c04b19381e4fec012f06bc9e..64457d1710bbd6727030624eb52911989bdee1cf 100644 (file)
@@ -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);
 }
 
 /*
index 1000bab245284fa3e8f89bb3abb53508b1feb5aa..4d31c3379df7d61147c92664a88cc530828428fd 100644 (file)
@@ -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);
index e249980527a0a9a6810c45b5f7f2de5c09c53306..fc96f9c4223cb56f933942bc3fa7d409a659965f 100644 (file)
@@ -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)
index ac0a9c618bc87d29f54b808f8c84aace75d1eddf..6a9e072b360d7dc941a203a8af7244e926d6985f 100644 (file)
@@ -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);
index df6cde2d58aec0f604f522127b4e646412f35f7f..f4c0314177b01347672a1b8eca12be4ef58c592f 100644 (file)
@@ -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:
index 21732b65c6eece55ee5faf6edd48907592309101..d7addbf58e3061828e74c716733b561aa866becc 100644 (file)
@@ -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);
index 97510dd875911abb098fccde155483c5dc4a1666..e89bd32d63a953707be55005190c623300ad07bf 100644 (file)
@@ -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)
index 1ac2bf6fc454a73c3f0c0e9abac5e4a7c9fd0fff..781d8968446c27e21ae102e8d9fdc48bbbad43f5 100644 (file)
@@ -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