]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: factor out a xfs_buf_item_finish_stale helper
authorDave Chinner <dchinner@redhat.com>
Fri, 23 May 2025 04:40:41 +0000 (06:40 +0200)
committerChristoph Hellwig <hch@lst.de>
Fri, 23 May 2025 04:48:06 +0000 (06:48 +0200)
hch: split from a larger patch by Dave, needs a proper commit log

fs/xfs/xfs_buf_item.c

index 90139e0f32719214b8ef1bf3117fdbf7545e88d8..45fd664de3e5eedecaed45e6b47d400d570efabd 100644 (file)
@@ -389,6 +389,44 @@ xfs_buf_item_pin(
        atomic_inc(&bip->bli_buf->b_pin_count);
 }
 
+/*
+ * For a stale BLI, process all the necessary completions that must be
+ * performed when the final BLI reference goes away. The buffer will be
+ * referenced and locked here - we return to the caller with it still referenced
+ * and locked so that the caller can release and unlock the buffer as required.
+ */
+static void
+xfs_buf_item_finish_stale(
+       struct xfs_buf          *bp)
+{
+       struct xfs_buf_log_item *bip = bp->b_log_item;
+       struct xfs_log_item     *lip = &bip->bli_item;
+
+       ASSERT(bip->bli_flags & XFS_BLI_STALE);
+       ASSERT(xfs_buf_islocked(bp));
+       ASSERT(bp->b_flags & XBF_STALE);
+       ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
+       ASSERT(list_empty(&lip->li_trans));
+       ASSERT(!bp->b_transp);
+
+       /*
+        * If we get called here because of an IO error, we may or may
+        * not have the item on the AIL. xfs_trans_ail_delete() will
+        * take care of that situation. xfs_trans_ail_delete() drops
+        * the AIL lock.
+        */
+       if (bip->bli_flags & XFS_BLI_STALE_INODE) {
+               xfs_buf_item_done(bp);
+               xfs_buf_inode_iodone(bp);
+               ASSERT(list_empty(&bp->b_li_list));
+       } else {
+               xfs_trans_ail_delete(lip, SHUTDOWN_LOG_IO_ERROR);
+               xfs_buf_item_relse(bp);
+               ASSERT(bp->b_log_item == NULL);
+       }
+       return;
+}
+
 /*
  * This is called to unpin the buffer associated with the buf log item which was
  * previously pinned with a call to xfs_buf_item_pin().  We enter this function
@@ -438,13 +476,6 @@ xfs_buf_item_unpin(
        }
 
        if (stale) {
-               ASSERT(bip->bli_flags & XFS_BLI_STALE);
-               ASSERT(xfs_buf_islocked(bp));
-               ASSERT(bp->b_flags & XBF_STALE);
-               ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
-               ASSERT(list_empty(&lip->li_trans));
-               ASSERT(!bp->b_transp);
-
                trace_xfs_buf_item_unpin_stale(bip);
 
                /*
@@ -455,22 +486,7 @@ xfs_buf_item_unpin(
                 * processing is complete.
                 */
                xfs_buf_rele(bp);
-
-               /*
-                * If we get called here because of an IO error, we may or may
-                * not have the item on the AIL. xfs_trans_ail_delete() will
-                * take care of that situation. xfs_trans_ail_delete() drops
-                * the AIL lock.
-                */
-               if (bip->bli_flags & XFS_BLI_STALE_INODE) {
-                       xfs_buf_item_done(bp);
-                       xfs_buf_inode_iodone(bp);
-                       ASSERT(list_empty(&bp->b_li_list));
-               } else {
-                       xfs_trans_ail_delete(lip, SHUTDOWN_LOG_IO_ERROR);
-                       xfs_buf_item_relse(bp);
-                       ASSERT(bp->b_log_item == NULL);
-               }
+               xfs_buf_item_finish_stale(bp);
                xfs_buf_relse(bp);
                return;
        }