Commit 6b126139 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: don't append work items to logged xfs_defer_pending objects

When someone tries to add a deferred work item to xfs_defer_add, it will
try to attach the work item to the most recently added xfs_defer_pending
object attached to the transaction.  However, it doesn't check if the
pending object has a log intent item attached to it.  This is incorrect
behavior because we cannot add more work to an object that has already
been committed to the ondisk log.

Therefore, change the behavior not to append to pending items with a non
null dfp_intent.  In practice this has not been an issue because the
only way xfs_defer_add gets called after log intent items have been
committed is from the defer ops ->finish_item functions themselves, and
the @dop_pending isolation in xfs_defer_finish_noroll protects the
pending items that have already been logged.

However, the next patch will add the ability to pause a deferred extent
free object during online btree rebuilding, and any new extfree work
items need to have their own pending event.

While we're at it, hoist the predicate to its own static inline function
for readability.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent 3f113c27
...@@ -695,6 +695,51 @@ xfs_defer_cancel( ...@@ -695,6 +695,51 @@ xfs_defer_cancel(
xfs_defer_cancel_list(mp, &tp->t_dfops); xfs_defer_cancel_list(mp, &tp->t_dfops);
} }
/*
* Return the last pending work item attached to this transaction if it matches
* the deferred op type.
*/
static inline struct xfs_defer_pending *
xfs_defer_find_last(
struct xfs_trans *tp,
enum xfs_defer_ops_type type,
const struct xfs_defer_op_type *ops)
{
struct xfs_defer_pending *dfp = NULL;
/* No dfops at all? */
if (list_empty(&tp->t_dfops))
return NULL;
dfp = list_last_entry(&tp->t_dfops, struct xfs_defer_pending,
dfp_list);
/* Wrong type? */
if (dfp->dfp_type != type)
return NULL;
return dfp;
}
/*
* Decide if we can add a deferred work item to the last dfops item attached
* to the transaction.
*/
static inline bool
xfs_defer_can_append(
struct xfs_defer_pending *dfp,
const struct xfs_defer_op_type *ops)
{
/* Already logged? */
if (dfp->dfp_intent)
return false;
/* Already full? */
if (ops->max_items && dfp->dfp_count >= ops->max_items)
return false;
return true;
}
/* Add an item for later deferred processing. */ /* Add an item for later deferred processing. */
void void
xfs_defer_add( xfs_defer_add(
...@@ -708,19 +753,9 @@ xfs_defer_add( ...@@ -708,19 +753,9 @@ xfs_defer_add(
ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
BUILD_BUG_ON(ARRAY_SIZE(defer_op_types) != XFS_DEFER_OPS_TYPE_MAX); BUILD_BUG_ON(ARRAY_SIZE(defer_op_types) != XFS_DEFER_OPS_TYPE_MAX);
/* dfp = xfs_defer_find_last(tp, type, ops);
* Add the item to a pending item at the end of the intake list. if (!dfp || !xfs_defer_can_append(dfp, ops)) {
* If the last pending item has the same type, reuse it. Else, /* Create a new pending item at the end of the intake list. */
* create a new pending item at the end of the intake list.
*/
if (!list_empty(&tp->t_dfops)) {
dfp = list_last_entry(&tp->t_dfops,
struct xfs_defer_pending, dfp_list);
if (dfp->dfp_type != type ||
(ops->max_items && dfp->dfp_count >= ops->max_items))
dfp = NULL;
}
if (!dfp) {
dfp = kmem_cache_zalloc(xfs_defer_pending_cache, dfp = kmem_cache_zalloc(xfs_defer_pending_cache,
GFP_NOFS | __GFP_NOFAIL); GFP_NOFS | __GFP_NOFAIL);
dfp->dfp_type = type; dfp->dfp_type = type;
......
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