Skip to content

Commit 816c330

Browse files
Dave Chinnercmaiolino
authored andcommitted
xfs: factor out stale buffer item completion
The stale buffer item completion handling is currently only done from BLI unpinning. We need to perform this function from where-ever the last reference to the BLI is dropped, so first we need to factor this code out into a helper. Signed-off-by: Dave Chinner <[email protected]> Reviewed-by: Carlos Maiolino <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent d2fe5c4 commit 816c330

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

fs/xfs/xfs_buf_item.c

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,42 @@ xfs_buf_item_pin(
444444
atomic_inc(&bip->bli_buf->b_pin_count);
445445
}
446446

447+
/*
448+
* For a stale BLI, process all the necessary completions that must be
449+
* performed when the final BLI reference goes away. The buffer will be
450+
* referenced and locked here - we return to the caller with the buffer still
451+
* referenced and locked for them to finalise processing of the buffer.
452+
*/
453+
static void
454+
xfs_buf_item_finish_stale(
455+
struct xfs_buf_log_item *bip)
456+
{
457+
struct xfs_buf *bp = bip->bli_buf;
458+
struct xfs_log_item *lip = &bip->bli_item;
459+
460+
ASSERT(bip->bli_flags & XFS_BLI_STALE);
461+
ASSERT(xfs_buf_islocked(bp));
462+
ASSERT(bp->b_flags & XBF_STALE);
463+
ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
464+
ASSERT(list_empty(&lip->li_trans));
465+
ASSERT(!bp->b_transp);
466+
467+
if (bip->bli_flags & XFS_BLI_STALE_INODE) {
468+
xfs_buf_item_done(bp);
469+
xfs_buf_inode_iodone(bp);
470+
ASSERT(list_empty(&bp->b_li_list));
471+
return;
472+
}
473+
474+
/*
475+
* We may or may not be on the AIL here, xfs_trans_ail_delete() will do
476+
* the right thing regardless of the situation in which we are called.
477+
*/
478+
xfs_trans_ail_delete(lip, SHUTDOWN_LOG_IO_ERROR);
479+
xfs_buf_item_relse(bip);
480+
ASSERT(bp->b_log_item == NULL);
481+
}
482+
447483
/*
448484
* This is called to unpin the buffer associated with the buf log item which was
449485
* previously pinned with a call to xfs_buf_item_pin(). We enter this function
@@ -493,13 +529,6 @@ xfs_buf_item_unpin(
493529
}
494530

495531
if (stale) {
496-
ASSERT(bip->bli_flags & XFS_BLI_STALE);
497-
ASSERT(xfs_buf_islocked(bp));
498-
ASSERT(bp->b_flags & XBF_STALE);
499-
ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
500-
ASSERT(list_empty(&lip->li_trans));
501-
ASSERT(!bp->b_transp);
502-
503532
trace_xfs_buf_item_unpin_stale(bip);
504533

505534
/*
@@ -510,22 +539,7 @@ xfs_buf_item_unpin(
510539
* processing is complete.
511540
*/
512541
xfs_buf_rele(bp);
513-
514-
/*
515-
* If we get called here because of an IO error, we may or may
516-
* not have the item on the AIL. xfs_trans_ail_delete() will
517-
* take care of that situation. xfs_trans_ail_delete() drops
518-
* the AIL lock.
519-
*/
520-
if (bip->bli_flags & XFS_BLI_STALE_INODE) {
521-
xfs_buf_item_done(bp);
522-
xfs_buf_inode_iodone(bp);
523-
ASSERT(list_empty(&bp->b_li_list));
524-
} else {
525-
xfs_trans_ail_delete(lip, SHUTDOWN_LOG_IO_ERROR);
526-
xfs_buf_item_relse(bip);
527-
ASSERT(bp->b_log_item == NULL);
528-
}
542+
xfs_buf_item_finish_stale(bip);
529543
xfs_buf_relse(bp);
530544
return;
531545
}

0 commit comments

Comments
 (0)