]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: simplify usage of the rcur local variable in xfs_rmap_finish_one
authorChristoph Hellwig <hch@lst.de>
Thu, 2 Nov 2023 12:08:08 +0000 (13:08 +0100)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 22 Nov 2023 23:03:37 +0000 (15:03 -0800)
Only update rcur when we know the final *pcur value.

Signed-off-by: Christoph Hellwig <hch@lst.de>
[djwong: don't leave the caller with a dangling ref]
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/defer_item.c
libxfs/xfs_rmap.c

index d86aced2b87be1d3e8668bba308000e08655424e..e4f7f63aeacc3fe94751f2678968c262d1d9f3ff 100644 (file)
@@ -28,6 +28,7 @@
 #include "xfs_ag.h"
 #include "xfs_swapext.h"
 #include "defer_item.h"
+#include "xfs_btree.h"
 
 /* Dummy defer item ops, since we don't do logging. */
 
@@ -368,6 +369,23 @@ xfs_rmap_update_abort_intent(
 {
 }
 
+/* Clean up after calling xfs_rmap_finish_one. */
+STATIC void
+xfs_rmap_finish_one_cleanup(
+       struct xfs_trans        *tp,
+       struct xfs_btree_cur    *rcur,
+       int                     error)
+{
+       struct xfs_buf          *agbp = NULL;
+
+       if (rcur == NULL)
+               return;
+       agbp = rcur->bc_ag.agbp;
+       xfs_btree_del_cursor(rcur, error);
+       if (error && agbp)
+               xfs_trans_brelse(tp, agbp);
+}
+
 const struct xfs_defer_op_type xfs_rmap_update_defer_type = {
        .create_intent  = xfs_rmap_update_create_intent,
        .abort_intent   = xfs_rmap_update_abort_intent,
index a54f7aef63ba9c776b8f37ec90c8870ee88bf2ce..4bdf6864cd23e1089aaaf2657f9c5d8bc07c704e 100644 (file)
@@ -2560,7 +2560,7 @@ xfs_rmap_finish_one(
 {
        struct xfs_owner_info           oinfo;
        struct xfs_mount                *mp = tp->t_mountp;
-       struct xfs_btree_cur            *rcur;
+       struct xfs_btree_cur            *rcur = *pcur;
        struct xfs_buf                  *agbp = NULL;
        xfs_agblock_t                   bno;
        bool                            unwritten;
@@ -2575,7 +2575,6 @@ xfs_rmap_finish_one(
         * If we haven't gotten a cursor or the cursor AG doesn't match
         * the startblock, get one now.
         */
-       rcur = *pcur;
        if (rcur != NULL && rcur->bc_ag.pag != ri->ri_pag) {
                xfs_btree_del_cursor(rcur, 0);
                rcur = NULL;
@@ -2597,9 +2596,8 @@ xfs_rmap_finish_one(
                        return -EFSCORRUPTED;
                }
 
-               rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, ri->ri_pag);
+               *pcur = rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, ri->ri_pag);
        }
-       *pcur = rcur;
 
        xfs_rmap_ino_owner(&oinfo, ri->ri_owner, ri->ri_whichfork,
                        ri->ri_bmap.br_startoff);