Commit 411350df authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: refactor xfs_trans_roll

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent f2e9ad21
...@@ -341,7 +341,7 @@ xfs_attr_set( ...@@ -341,7 +341,7 @@ xfs_attr_set(
* transaction to add the new attribute to the leaf. * 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) if (error)
goto out; goto out;
...@@ -605,7 +605,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -605,7 +605,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
* Commit the current trans (including the inode) and start * Commit the current trans (including the inode) and start
* a new one. * a new one.
*/ */
error = xfs_trans_roll(&args->trans, dp); error = xfs_trans_roll_inode(&args->trans, dp);
if (error) if (error)
return error; return error;
...@@ -620,7 +620,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -620,7 +620,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
* Commit the transaction that added the attr name so that * Commit the transaction that added the attr name so that
* later routines can manage their own transactions. * later routines can manage their own transactions.
*/ */
error = xfs_trans_roll(&args->trans, dp); error = xfs_trans_roll_inode(&args->trans, dp);
if (error) if (error)
return error; return error;
...@@ -697,7 +697,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -697,7 +697,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
/* /*
* Commit the remove and start the next trans in series. * 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) { } else if (args->rmtblkno > 0) {
/* /*
...@@ -885,7 +885,7 @@ xfs_attr_node_addname(xfs_da_args_t *args) ...@@ -885,7 +885,7 @@ xfs_attr_node_addname(xfs_da_args_t *args)
* Commit the node conversion and start the next * Commit the node conversion and start the next
* trans in the chain. * trans in the chain.
*/ */
error = xfs_trans_roll(&args->trans, dp); error = xfs_trans_roll_inode(&args->trans, dp);
if (error) if (error)
goto out; goto out;
...@@ -925,7 +925,7 @@ xfs_attr_node_addname(xfs_da_args_t *args) ...@@ -925,7 +925,7 @@ xfs_attr_node_addname(xfs_da_args_t *args)
* Commit the leaf addition or btree split and start the next * Commit the leaf addition or btree split and start the next
* trans in the chain. * trans in the chain.
*/ */
error = xfs_trans_roll(&args->trans, dp); error = xfs_trans_roll_inode(&args->trans, dp);
if (error) if (error)
goto out; goto out;
...@@ -1012,7 +1012,7 @@ xfs_attr_node_addname(xfs_da_args_t *args) ...@@ -1012,7 +1012,7 @@ xfs_attr_node_addname(xfs_da_args_t *args)
/* /*
* Commit and start the next trans in the chain. * 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) if (error)
goto out; goto out;
...@@ -1132,7 +1132,7 @@ xfs_attr_node_removename(xfs_da_args_t *args) ...@@ -1132,7 +1132,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)
/* /*
* Commit the Btree join operation and start a new trans. * 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) if (error)
goto out; goto out;
} }
......
...@@ -2608,7 +2608,7 @@ xfs_attr3_leaf_clearflag( ...@@ -2608,7 +2608,7 @@ xfs_attr3_leaf_clearflag(
/* /*
* Commit the flag value change and start the next trans in series. * 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);
} }
/* /*
...@@ -2659,7 +2659,7 @@ xfs_attr3_leaf_setflag( ...@@ -2659,7 +2659,7 @@ xfs_attr3_leaf_setflag(
/* /*
* Commit the flag value change and start the next trans in series. * 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);
} }
/* /*
...@@ -2777,7 +2777,7 @@ xfs_attr3_leaf_flipflags( ...@@ -2777,7 +2777,7 @@ xfs_attr3_leaf_flipflags(
/* /*
* Commit the flag value change and start the next trans in series. * 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; return error;
} }
...@@ -484,7 +484,7 @@ xfs_attr_rmtval_set( ...@@ -484,7 +484,7 @@ xfs_attr_rmtval_set(
/* /*
* Start the next trans in the chain. * Start the next trans in the chain.
*/ */
error = xfs_trans_roll(&args->trans, dp); error = xfs_trans_roll_inode(&args->trans, dp);
if (error) if (error)
return error; return error;
} }
...@@ -621,7 +621,7 @@ xfs_attr_rmtval_remove( ...@@ -621,7 +621,7 @@ xfs_attr_rmtval_remove(
/* /*
* Close out trans and start the next one in the chain. * 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) if (error)
return error; return error;
} }
......
...@@ -240,23 +240,19 @@ xfs_defer_trans_abort( ...@@ -240,23 +240,19 @@ xfs_defer_trans_abort(
STATIC int STATIC int
xfs_defer_trans_roll( xfs_defer_trans_roll(
struct xfs_trans **tp, struct xfs_trans **tp,
struct xfs_defer_ops *dop, struct xfs_defer_ops *dop)
struct xfs_inode *ip)
{ {
int i; int i;
int error; int error;
/* Log all the joined inodes except the one we passed in. */ /* Log all the joined inodes. */
for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++) { for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++)
if (dop->dop_inodes[i] == ip)
continue;
xfs_trans_log_inode(*tp, dop->dop_inodes[i], XFS_ILOG_CORE); xfs_trans_log_inode(*tp, dop->dop_inodes[i], XFS_ILOG_CORE);
}
trace_xfs_defer_trans_roll((*tp)->t_mountp, dop); trace_xfs_defer_trans_roll((*tp)->t_mountp, dop);
/* Roll the transaction. */ /* Roll the transaction. */
error = xfs_trans_roll(tp, ip); error = xfs_trans_roll(tp);
if (error) { if (error) {
trace_xfs_defer_trans_roll_error((*tp)->t_mountp, dop, error); trace_xfs_defer_trans_roll_error((*tp)->t_mountp, dop, error);
xfs_defer_trans_abort(*tp, dop, error); xfs_defer_trans_abort(*tp, dop, error);
...@@ -264,12 +260,9 @@ xfs_defer_trans_roll( ...@@ -264,12 +260,9 @@ xfs_defer_trans_roll(
} }
dop->dop_committed = true; dop->dop_committed = true;
/* Rejoin the joined inodes except the one we passed in. */ /* Rejoin the joined inodes. */
for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++) { for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++)
if (dop->dop_inodes[i] == ip)
continue;
xfs_trans_ijoin(*tp, dop->dop_inodes[i], 0); xfs_trans_ijoin(*tp, dop->dop_inodes[i], 0);
}
return error; return error;
} }
...@@ -331,13 +324,15 @@ xfs_defer_finish( ...@@ -331,13 +324,15 @@ xfs_defer_finish(
trace_xfs_defer_finish((*tp)->t_mountp, dop); trace_xfs_defer_finish((*tp)->t_mountp, dop);
xfs_defer_join(dop, ip);
/* Until we run out of pending work to finish... */ /* Until we run out of pending work to finish... */
while (xfs_defer_has_unfinished_work(dop)) { while (xfs_defer_has_unfinished_work(dop)) {
/* Log intents for work items sitting in the intake. */ /* Log intents for work items sitting in the intake. */
xfs_defer_intake_work(*tp, dop); xfs_defer_intake_work(*tp, dop);
/* Roll the transaction. */ /* Roll the transaction. */
error = xfs_defer_trans_roll(tp, dop, ip); error = xfs_defer_trans_roll(tp, dop);
if (error) if (error)
goto out; goto out;
......
...@@ -97,7 +97,7 @@ xfs_attr3_leaf_freextent( ...@@ -97,7 +97,7 @@ xfs_attr3_leaf_freextent(
/* /*
* Roll to next transaction. * Roll to next transaction.
*/ */
error = xfs_trans_roll(trans, dp); error = xfs_trans_roll_inode(trans, dp);
if (error) if (error)
return error; return error;
} }
...@@ -308,7 +308,7 @@ xfs_attr3_node_inactive( ...@@ -308,7 +308,7 @@ xfs_attr3_node_inactive(
/* /*
* Atomically commit the whole invalidate stuff. * Atomically commit the whole invalidate stuff.
*/ */
error = xfs_trans_roll(trans, dp); error = xfs_trans_roll_inode(trans, dp);
if (error) if (error)
return error; return error;
} }
...@@ -375,7 +375,7 @@ xfs_attr3_root_inactive( ...@@ -375,7 +375,7 @@ xfs_attr3_root_inactive(
/* /*
* Commit the invalidate and start the next transaction. * Commit the invalidate and start the next transaction.
*/ */
error = xfs_trans_roll(trans, dp); error = xfs_trans_roll_inode(trans, dp);
return error; return error;
} }
......
...@@ -1055,7 +1055,7 @@ xfs_dir_ialloc( ...@@ -1055,7 +1055,7 @@ xfs_dir_ialloc(
tp->t_flags &= ~(XFS_TRANS_DQ_DIRTY); tp->t_flags &= ~(XFS_TRANS_DQ_DIRTY);
} }
code = xfs_trans_roll(&tp, NULL); code = xfs_trans_roll(&tp);
if (committed != NULL) if (committed != NULL)
*committed = 1; *committed = 1;
...@@ -1611,7 +1611,7 @@ xfs_itruncate_extents( ...@@ -1611,7 +1611,7 @@ xfs_itruncate_extents(
if (error) if (error)
goto out_bmap_cancel; goto out_bmap_cancel;
error = xfs_trans_roll(&tp, ip); error = xfs_trans_roll_inode(&tp, ip);
if (error) if (error)
goto out; goto out;
} }
......
...@@ -1035,25 +1035,18 @@ xfs_trans_cancel( ...@@ -1035,25 +1035,18 @@ xfs_trans_cancel(
*/ */
int int
xfs_trans_roll( xfs_trans_roll(
struct xfs_trans **tpp, struct xfs_trans **tpp)
struct xfs_inode *dp)
{ {
struct xfs_trans *trans; struct xfs_trans *trans = *tpp;
struct xfs_trans_res tres; struct xfs_trans_res tres;
int error; 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. * Copy the critical parameters from one trans to the next.
*/ */
tres.tr_logres = trans->t_log_res; tres.tr_logres = trans->t_log_res;
tres.tr_logcount = trans->t_log_count; tres.tr_logcount = trans->t_log_count;
*tpp = xfs_trans_dup(trans); *tpp = xfs_trans_dup(trans);
/* /*
...@@ -1067,10 +1060,8 @@ xfs_trans_roll( ...@@ -1067,10 +1060,8 @@ xfs_trans_roll(
if (error) if (error)
return error; return error;
trans = *tpp;
/* /*
* 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, * 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 * 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 * that we want to use. This requires that either nothing be locked
...@@ -1078,14 +1069,5 @@ xfs_trans_roll( ...@@ -1078,14 +1069,5 @@ xfs_trans_roll(
* the prior and the next transactions. * the prior and the next transactions.
*/ */
tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
error = xfs_trans_reserve(trans, &tres, 0, 0); return xfs_trans_reserve(*tpp, &tres, 0, 0);
/*
* 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;
} }
...@@ -228,7 +228,8 @@ int xfs_trans_free_extent(struct xfs_trans *, ...@@ -228,7 +228,8 @@ int xfs_trans_free_extent(struct xfs_trans *,
struct xfs_efd_log_item *, xfs_fsblock_t, struct xfs_efd_log_item *, xfs_fsblock_t,
xfs_extlen_t, struct xfs_owner_info *); xfs_extlen_t, struct xfs_owner_info *);
int xfs_trans_commit(struct xfs_trans *); int xfs_trans_commit(struct xfs_trans *);
int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *); int xfs_trans_roll(struct xfs_trans **);
int xfs_trans_roll_inode(struct xfs_trans **, struct xfs_inode *);
void xfs_trans_cancel(xfs_trans_t *); void xfs_trans_cancel(xfs_trans_t *);
int xfs_trans_ail_init(struct xfs_mount *); int xfs_trans_ail_init(struct xfs_mount *);
void xfs_trans_ail_destroy(struct xfs_mount *); void xfs_trans_ail_destroy(struct xfs_mount *);
......
...@@ -134,3 +134,17 @@ xfs_trans_log_inode( ...@@ -134,3 +134,17 @@ xfs_trans_log_inode(
flags |= ip->i_itemp->ili_last_fields; flags |= ip->i_itemp->ili_last_fields;
ip->i_itemp->ili_fields |= flags; ip->i_itemp->ili_fields |= flags;
} }
int
xfs_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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment