xfs: cleanup bmap extent state macros
[safe/jmp/linux-2.6] / fs / xfs / xfs_buf_item.c
index 7a55c24..92af409 100644 (file)
@@ -23,6 +23,7 @@
 #include "xfs_inum.h"
 #include "xfs_trans.h"
 #include "xfs_sb.h"
+#include "xfs_ag.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_buf_item.h"
@@ -374,10 +375,9 @@ xfs_buf_item_unpin(
        xfs_buf_log_item_t      *bip,
        int                     stale)
 {
-       xfs_mount_t     *mp;
+       struct xfs_ail  *ailp;
        xfs_buf_t       *bp;
        int             freed;
-       SPLDECL(s);
 
        bp = bip->bli_buf;
        ASSERT(bp != NULL);
@@ -387,7 +387,7 @@ xfs_buf_item_unpin(
        xfs_buftrace("XFS_UNPIN", bp);
 
        freed = atomic_dec_and_test(&bip->bli_refcount);
-       mp = bip->bli_item.li_mountp;
+       ailp = bip->bli_item.li_ailp;
        xfs_bunpin(bp);
        if (freed && stale) {
                ASSERT(bip->bli_flags & XFS_BLI_STALE);
@@ -399,17 +399,17 @@ xfs_buf_item_unpin(
                xfs_buftrace("XFS_UNPIN STALE", bp);
                /*
                 * If we get called here because of an IO error, we may
-                * or may not have the item on the AIL. xfs_trans_delete_ail()
+                * or may not have the item on the AIL. xfs_trans_ail_delete()
                 * will take care of that situation.
-                * xfs_trans_delete_ail() drops the AIL lock.
+                * xfs_trans_ail_delete() drops the AIL lock.
                 */
                if (bip->bli_flags & XFS_BLI_STALE_INODE) {
                        xfs_buf_do_callbacks(bp, (xfs_log_item_t *)bip);
                        XFS_BUF_SET_FSPRIVATE(bp, NULL);
                        XFS_BUF_CLR_IODONE_FUNC(bp);
                } else {
-                       AIL_LOCK(mp,s);
-                       xfs_trans_delete_ail(mp, (xfs_log_item_t *)bip, s);
+                       spin_lock(&ailp->xa_lock);
+                       xfs_trans_ail_delete(ailp, (xfs_log_item_t *)bip);
                        xfs_buf_item_relse(bp);
                        ASSERT(XFS_BUF_FSPRIVATE(bp, void *) == NULL);
                }
@@ -580,8 +580,8 @@ xfs_buf_item_unlock(
         * If the buf item isn't tracking any data, free it.
         * Otherwise, if XFS_BLI_HOLD is set clear it.
         */
-       if (xfs_count_bits(bip->bli_format.blf_data_map,
-                             bip->bli_format.blf_map_size, 0) == 0) {
+       if (xfs_bitmap_empty(bip->bli_format.blf_data_map,
+                            bip->bli_format.blf_map_size)) {
                xfs_buf_item_relse(bp);
        } else if (hold) {
                bip->bli_flags &= ~XFS_BLI_HOLD;
@@ -645,7 +645,12 @@ xfs_buf_item_push(
        bp = bip->bli_buf;
 
        if (XFS_BUF_ISDELAYWRITE(bp)) {
-               xfs_bawrite(bip->bli_item.li_mountp, bp);
+               int     error;
+               error = xfs_bawrite(bip->bli_item.li_mountp, bp);
+               if (error)
+                       xfs_fs_cmn_err(CE_WARN, bip->bli_item.li_mountp,
+                       "xfs_buf_item_push: pushbuf error %d on bip %p, bp %p",
+                                       error, bip, bp);
        } else {
                xfs_buf_relse(bp);
        }
@@ -660,7 +665,7 @@ xfs_buf_item_committing(xfs_buf_log_item_t *bip, xfs_lsn_t commit_lsn)
 /*
  * This is the ops vector shared by all buf log items.
  */
-STATIC struct xfs_item_ops xfs_buf_item_ops = {
+static struct xfs_item_ops xfs_buf_item_ops = {
        .iop_size       = (uint(*)(xfs_log_item_t*))xfs_buf_item_size,
        .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
                                        xfs_buf_item_format,
@@ -702,8 +707,8 @@ xfs_buf_item_init(
         * the first.  If we do already have one, there is
         * nothing to do here so return.
         */
-       if (XFS_BUF_FSPRIVATE3(bp, xfs_mount_t *) != mp)
-               XFS_BUF_SET_FSPRIVATE3(bp, mp);
+       if (bp->b_mount != mp)
+               bp->b_mount = mp;
        XFS_BUF_SET_BDSTRAT_FUNC(bp, xfs_bdstrat_cb);
        if (XFS_BUF_FSPRIVATE(bp, void *) != NULL) {
                lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
@@ -726,13 +731,15 @@ xfs_buf_item_init(
        bip->bli_item.li_type = XFS_LI_BUF;
        bip->bli_item.li_ops = &xfs_buf_item_ops;
        bip->bli_item.li_mountp = mp;
+       bip->bli_item.li_ailp = mp->m_ail;
        bip->bli_buf = bp;
+       xfs_buf_hold(bp);
        bip->bli_format.blf_type = XFS_LI_BUF;
        bip->bli_format.blf_blkno = (__int64_t)XFS_BUF_ADDR(bp);
        bip->bli_format.blf_len = (ushort)BTOBB(XFS_BUF_COUNT(bp));
        bip->bli_format.blf_map_size = map_size;
 #ifdef XFS_BLI_TRACE
-       bip->bli_trace = ktrace_alloc(XFS_BLI_TRACE_SIZE, KM_SLEEP);
+       bip->bli_trace = ktrace_alloc(XFS_BLI_TRACE_SIZE, KM_NOFS);
 #endif
 
 #ifdef XFS_TRANS_DEBUG
@@ -862,6 +869,21 @@ xfs_buf_item_dirty(
        return (bip->bli_flags & XFS_BLI_DIRTY);
 }
 
+STATIC void
+xfs_buf_item_free(
+       xfs_buf_log_item_t      *bip)
+{
+#ifdef XFS_TRANS_DEBUG
+       kmem_free(bip->bli_orig);
+       kmem_free(bip->bli_logged);
+#endif /* XFS_TRANS_DEBUG */
+
+#ifdef XFS_BLI_TRACE
+       ktrace_free(bip->bli_trace);
+#endif
+       kmem_zone_free(xfs_buf_item_zone, bip);
+}
+
 /*
  * This is called when the buf log item is no longer needed.  It should
  * free the buf log item associated with the given buffer and clear
@@ -882,18 +904,8 @@ xfs_buf_item_relse(
            (XFS_BUF_IODONE_FUNC(bp) != NULL)) {
                XFS_BUF_CLR_IODONE_FUNC(bp);
        }
-
-#ifdef XFS_TRANS_DEBUG
-       kmem_free(bip->bli_orig, XFS_BUF_COUNT(bp));
-       bip->bli_orig = NULL;
-       kmem_free(bip->bli_logged, XFS_BUF_COUNT(bp) / NBBY);
-       bip->bli_logged = NULL;
-#endif /* XFS_TRANS_DEBUG */
-
-#ifdef XFS_BLI_TRACE
-       ktrace_free(bip->bli_trace);
-#endif
-       kmem_zone_free(xfs_buf_item_zone, bip);
+       xfs_buf_rele(bp);
+       xfs_buf_item_free(bip);
 }
 
 
@@ -986,21 +998,7 @@ xfs_buf_iodone_callbacks(
                        xfs_buf_do_callbacks(bp, lip);
                        XFS_BUF_SET_FSPRIVATE(bp, NULL);
                        XFS_BUF_CLR_IODONE_FUNC(bp);
-
-                       /*
-                        * XFS_SHUT flag gets set when we go thru the
-                        * entire buffer cache and deliberately start
-                        * throwing away delayed write buffers.
-                        * Since there's no biowait done on those,
-                        * we should just brelse them.
-                        */
-                       if (XFS_BUF_ISSHUT(bp)) {
-                           XFS_BUF_UNSHUT(bp);
-                               xfs_buf_relse(bp);
-                       } else {
-                               xfs_biodone(bp);
-                       }
-
+                       xfs_biodone(bp);
                        return;
                }
 
@@ -1051,7 +1049,7 @@ xfs_buf_iodone_callbacks(
                           anyway. */
                        XFS_BUF_SET_BRELSE_FUNC(bp,xfs_buf_error_relse);
                        XFS_BUF_DONE(bp);
-                       XFS_BUF_V_IODONESEMA(bp);
+                       XFS_BUF_FINISH_IOWAIT(bp);
                }
                return;
        }
@@ -1111,39 +1109,24 @@ xfs_buf_iodone(
        xfs_buf_t               *bp,
        xfs_buf_log_item_t      *bip)
 {
-       struct xfs_mount        *mp;
-       SPLDECL(s);
+       struct xfs_ail          *ailp = bip->bli_item.li_ailp;
 
        ASSERT(bip->bli_buf == bp);
 
-       mp = bip->bli_item.li_mountp;
+       xfs_buf_rele(bp);
 
        /*
         * If we are forcibly shutting down, this may well be
         * off the AIL already. That's because we simulate the
         * log-committed callbacks to unpin these buffers. Or we may never
         * have put this item on AIL because of the transaction was
-        * aborted forcibly. xfs_trans_delete_ail() takes care of these.
+        * aborted forcibly. xfs_trans_ail_delete() takes care of these.
         *
         * Either way, AIL is useless if we're forcing a shutdown.
         */
-       AIL_LOCK(mp,s);
-       /*
-        * xfs_trans_delete_ail() drops the AIL lock.
-        */
-       xfs_trans_delete_ail(mp, (xfs_log_item_t *)bip, s);
-
-#ifdef XFS_TRANS_DEBUG
-       kmem_free(bip->bli_orig, XFS_BUF_COUNT(bp));
-       bip->bli_orig = NULL;
-       kmem_free(bip->bli_logged, XFS_BUF_COUNT(bp) / NBBY);
-       bip->bli_logged = NULL;
-#endif /* XFS_TRANS_DEBUG */
-
-#ifdef XFS_BLI_TRACE
-       ktrace_free(bip->bli_trace);
-#endif
-       kmem_zone_free(xfs_buf_item_zone, bip);
+       spin_lock(&ailp->xa_lock);
+       xfs_trans_ail_delete(ailp, (xfs_log_item_t *)bip);
+       xfs_buf_item_free(bip);
 }
 
 #if defined(XFS_BLI_TRACE)