]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor xfs_trans_roll
authorChristoph Hellwig <hch@lst.de>
Wed, 18 Oct 2017 18:38:49 +0000 (13:38 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 18 Oct 2017 18:38:49 +0000 (13:38 -0500)
Source kernel commit: 411350df14a3d6f1c769ea64a8b43a71f8d9760e

Split xfs_trans_roll into a low-level helper that just rolls the
actual transaction and a new higher level xfs_trans_roll_inode
that takes care of logging and rejoining the inode.  This gets
rid of the NULL inode case, and allows to simplify the special
cases in the deferred operation code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/xfs_trans.h
libxfs/libxfs_api_defs.h
libxfs/libxfs_priv.h
libxfs/trans.c
libxfs/util.c
libxfs/xfs_attr.c
libxfs/xfs_attr_leaf.c
libxfs/xfs_attr_remote.c
libxfs/xfs_defer.c

index 17d286acc466e6d3ff653bbf229db36443eccd25..59659843a04191f0742ca6059725fc2bb0d5ddfe 100644 (file)
@@ -85,7 +85,7 @@ typedef struct xfs_trans {
 } xfs_trans_t;
 
 void   xfs_trans_init(struct xfs_mount *);
-int    xfs_trans_roll(struct xfs_trans **, struct xfs_inode *);
+int    xfs_trans_roll(struct xfs_trans **);
 
 int    libxfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp,
                           uint blocks, uint rtextents, uint flags,
@@ -101,6 +101,7 @@ void        libxfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *, uint);
 void   libxfs_trans_ijoin_ref(struct xfs_trans *, struct xfs_inode *, int);
 void   libxfs_trans_log_inode (struct xfs_trans *, struct xfs_inode *,
                                uint);
+int    libxfs_trans_roll_inode (struct xfs_trans **, struct xfs_inode *);
 
 void   libxfs_trans_brelse(struct xfs_trans *, struct xfs_buf *);
 void   libxfs_trans_binval(struct xfs_trans *, struct xfs_buf *);
index d299b7a24a6f3697f95b925b92f7fa42ad3bfb37..9726103998e5ec9b4681a718ab94dd5120e94a3e 100644 (file)
@@ -51,6 +51,7 @@
 #define xfs_trans_inode_alloc_buf      libxfs_trans_inode_alloc_buf
 #define xfs_trans_log_buf              libxfs_trans_log_buf
 #define xfs_trans_log_inode            libxfs_trans_log_inode
+#define xfs_trans_roll_inode           libxfs_trans_roll_inode
 #define xfs_trans_mod_sb               libxfs_trans_mod_sb
 #define xfs_trans_read_buf             libxfs_trans_read_buf
 #define xfs_trans_read_buf_map         libxfs_trans_read_buf_map
index c051eaaf2bd5d2765ed8e7836162cf059f298297..812ce88c93f5e8dfdd4490e229568bc61f7f35d3 100644 (file)
@@ -445,7 +445,7 @@ void xfs_mount_common(struct xfs_mount *, struct xfs_sb *);
  * logitem.c and trans.c prototypes
  */
 void xfs_trans_init(struct xfs_mount *);
-int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *);
+int xfs_trans_roll(struct xfs_trans **);
 
 /* xfs_trans_item.c */
 void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
@@ -472,8 +472,6 @@ int  libxfs_mod_incore_sb(struct xfs_mount *, int, int64_t, int);
 #define xfs_reinit_percpu_counters(mp)
 
 void xfs_trans_mod_sb(struct xfs_trans *, uint, long);
-void xfs_trans_init(struct xfs_mount *);
-int  xfs_trans_roll(struct xfs_trans **, struct xfs_inode *);
 void xfs_verifier_error(struct xfs_buf *bp);
 
 /* XXX: this is clearly a bug - a shared header needs to export this */
index b9ee3cff7ed2d3448033cdbe801c6315bc771308..bc708c2765da1dff64b289f1a7f0a734e64d9f35 100644 (file)
@@ -100,22 +100,14 @@ libxfs_trans_del_item(
  */
 int
 libxfs_trans_roll(
-       struct xfs_trans        **tpp,
-       struct xfs_inode        *dp)
+       struct xfs_trans        **tpp)
 {
        struct xfs_mount        *mp;
-       struct xfs_trans        *trans;
+       struct xfs_trans        *trans = *tpp;
        struct xfs_trans_res    tres;
        unsigned int            old_blk_res;
        int                     error;
 
-       /*
-        * Ensure that the inode is always logged.
-        */
-       trans = *tpp;
-       if (dp)
-               xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
-
        /*
         * Copy the critical parameters from one trans to the next.
         */
@@ -135,9 +127,8 @@ libxfs_trans_roll(
        if (error)
                return error;
 
-
        /*
-        * Reserve space in the log for th next transaction.
+        * Reserve space in the log for the next transaction.
         * This also pushes items in the "AIL", the list of logged items,
         * out to disk if they are taking up space at the tail of the log
         * that we want to use.  This requires that either nothing be locked
@@ -149,14 +140,6 @@ libxfs_trans_roll(
        trans = *tpp;
        trans->t_blk_res = old_blk_res;
 
-       /*
-        *  Ensure that the inode is in the new transaction and locked.
-        */
-       if (error)
-               return error;
-
-       if (dp)
-               xfs_trans_ijoin(trans, dp, 0);
        return 0;
 }
 
@@ -358,6 +341,21 @@ xfs_trans_log_inode(
        ip->i_itemp->ili_fields |= flags;
 }
 
+int
+libxfs_trans_roll_inode(
+       struct xfs_trans        **tpp,
+       struct xfs_inode        *ip)
+{
+       int                     error;
+
+       xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE);
+       error = xfs_trans_roll(tpp);
+       if (!error)
+               xfs_trans_ijoin(*tpp, ip, 0);
+       return error;
+}
+
+
 /*
  * This is called to mark bytes first through last inclusive of the given
  * buffer as needing to be logged when the transaction is committed.
index 74b1bdb8c8e8e0e6c23d6fa5842bac6f59562569..5a4c1d70e03f8372c913272bc54f296a806333e0 100644 (file)
@@ -681,7 +681,7 @@ libxfs_inode_alloc(
 
                xfs_trans_bhold(*tp, ialloc_context);
 
-               error = xfs_trans_roll(tp, NULL);
+               error = xfs_trans_roll(tp);
                if (error) {
                        fprintf(stderr, _("%s: cannot duplicate transaction: %s\n"),
                                progname, strerror(error));
index a595fbf6c7d67eef8c2e3ae046ca12e2172cfc2e..9877692a5757bc5d754ef461933df57b89bcb214 100644 (file)
@@ -336,7 +336,7 @@ xfs_attr_set(
                 * transaction to add the new attribute to the leaf.
                 */
 
-               error = xfs_trans_roll(&args.trans, dp);
+               error = xfs_trans_roll_inode(&args.trans, dp);
                if (error)
                        goto out;
 
@@ -600,7 +600,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
                 * Commit the current trans (including the inode) and start
                 * a new one.
                 */
-               error = xfs_trans_roll(&args->trans, dp);
+               error = xfs_trans_roll_inode(&args->trans, dp);
                if (error)
                        return error;
 
@@ -615,7 +615,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
         * Commit the transaction that added the attr name so that
         * later routines can manage their own transactions.
         */
-       error = xfs_trans_roll(&args->trans, dp);
+       error = xfs_trans_roll_inode(&args->trans, dp);
        if (error)
                return error;
 
@@ -692,7 +692,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
                /*
                 * Commit the remove and start the next trans in series.
                 */
-               error = xfs_trans_roll(&args->trans, dp);
+               error = xfs_trans_roll_inode(&args->trans, dp);
 
        } else if (args->rmtblkno > 0) {
                /*
@@ -880,7 +880,7 @@ restart:
                         * Commit the node conversion and start the next
                         * trans in the chain.
                         */
-                       error = xfs_trans_roll(&args->trans, dp);
+                       error = xfs_trans_roll_inode(&args->trans, dp);
                        if (error)
                                goto out;
 
@@ -920,7 +920,7 @@ restart:
         * Commit the leaf addition or btree split and start the next
         * trans in the chain.
         */
-       error = xfs_trans_roll(&args->trans, dp);
+       error = xfs_trans_roll_inode(&args->trans, dp);
        if (error)
                goto out;
 
@@ -1007,7 +1007,7 @@ restart:
                /*
                 * Commit and start the next trans in the chain.
                 */
-               error = xfs_trans_roll(&args->trans, dp);
+               error = xfs_trans_roll_inode(&args->trans, dp);
                if (error)
                        goto out;
 
@@ -1127,7 +1127,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)
                /*
                 * Commit the Btree join operation and start a new trans.
                 */
-               error = xfs_trans_roll(&args->trans, dp);
+               error = xfs_trans_roll_inode(&args->trans, dp);
                if (error)
                        goto out;
        }
index 6053b56a9624efc568d4b1e6a8b51da324edef16..f0cf6f692929c326e3497f2756cfaa68ee6599b7 100644 (file)
@@ -2603,7 +2603,7 @@ xfs_attr3_leaf_clearflag(
        /*
         * Commit the flag value change and start the next trans in series.
         */
-       return xfs_trans_roll(&args->trans, args->dp);
+       return xfs_trans_roll_inode(&args->trans, args->dp);
 }
 
 /*
@@ -2654,7 +2654,7 @@ xfs_attr3_leaf_setflag(
        /*
         * Commit the flag value change and start the next trans in series.
         */
-       return xfs_trans_roll(&args->trans, args->dp);
+       return xfs_trans_roll_inode(&args->trans, args->dp);
 }
 
 /*
@@ -2772,7 +2772,7 @@ xfs_attr3_leaf_flipflags(
        /*
         * Commit the flag value change and start the next trans in series.
         */
-       error = xfs_trans_roll(&args->trans, args->dp);
+       error = xfs_trans_roll_inode(&args->trans, args->dp);
 
        return error;
 }
index 34c0550868a840ed9af0f5caec36ef7e71954cb0..4c7781a374dee34f12080b61262718f794f13e28 100644 (file)
@@ -479,7 +479,7 @@ xfs_attr_rmtval_set(
                /*
                 * Start the next trans in the chain.
                 */
-               error = xfs_trans_roll(&args->trans, dp);
+               error = xfs_trans_roll_inode(&args->trans, dp);
                if (error)
                        return error;
        }
@@ -616,7 +616,7 @@ xfs_attr_rmtval_remove(
                /*
                 * Close out trans and start the next one in the chain.
                 */
-               error = xfs_trans_roll(&args->trans, args->dp);
+               error = xfs_trans_roll_inode(&args->trans, args->dp);
                if (error)
                        return error;
        }
index d880d59e9f300c9655c61b4c6c48e587f513ff9e..fa3f72d214fdcfb0633ac3470a8b233bd0f1d7d7 100644 (file)
@@ -240,23 +240,19 @@ xfs_defer_trans_abort(
 STATIC int
 xfs_defer_trans_roll(
        struct xfs_trans                **tp,
-       struct xfs_defer_ops            *dop,
-       struct xfs_inode                *ip)
+       struct xfs_defer_ops            *dop)
 {
        int                             i;
        int                             error;
 
-       /* Log all the joined inodes except the one we passed in. */
-       for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++) {
-               if (dop->dop_inodes[i] == ip)
-                       continue;
+       /* Log all the joined inodes. */
+       for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++)
                xfs_trans_log_inode(*tp, dop->dop_inodes[i], XFS_ILOG_CORE);
-       }
 
        trace_xfs_defer_trans_roll((*tp)->t_mountp, dop);
 
        /* Roll the transaction. */
-       error = xfs_trans_roll(tp, ip);
+       error = xfs_trans_roll(tp);
        if (error) {
                trace_xfs_defer_trans_roll_error((*tp)->t_mountp, dop, error);
                xfs_defer_trans_abort(*tp, dop, error);
@@ -264,12 +260,9 @@ xfs_defer_trans_roll(
        }
        dop->dop_committed = true;
 
-       /* Rejoin the joined inodes except the one we passed in. */
-       for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++) {
-               if (dop->dop_inodes[i] == ip)
-                       continue;
+       /* Rejoin the joined inodes. */
+       for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++)
                xfs_trans_ijoin(*tp, dop->dop_inodes[i], 0);
-       }
 
        return error;
 }
@@ -331,13 +324,15 @@ xfs_defer_finish(
 
        trace_xfs_defer_finish((*tp)->t_mountp, dop);
 
+       xfs_defer_join(dop, ip);
+
        /* Until we run out of pending work to finish... */
        while (xfs_defer_has_unfinished_work(dop)) {
                /* Log intents for work items sitting in the intake. */
                xfs_defer_intake_work(*tp, dop);
 
                /* Roll the transaction. */
-               error = xfs_defer_trans_roll(tp, dop, ip);
+               error = xfs_defer_trans_roll(tp, dop);
                if (error)
                        goto out;