nfs: fix oops in nfs_rename()
[safe/jmp/linux-2.6] / fs / xfs / xfs_buf_item.c
index c557fd6..a30f7e9 100644 (file)
@@ -29,6 +29,7 @@
 #include "xfs_buf_item.h"
 #include "xfs_trans_priv.h"
 #include "xfs_error.h"
+#include "xfs_trace.h"
 
 
 kmem_zone_t    *xfs_buf_item_zone;
@@ -164,7 +165,7 @@ xfs_buf_item_size(
                 * is the buf log format structure with the
                 * cancel flag in it.
                 */
-               xfs_buf_item_trace("SIZE STALE", bip);
+               trace_xfs_buf_item_size_stale(bip);
                ASSERT(bip->bli_format.blf_flags & XFS_BLI_CANCEL);
                return 1;
        }
@@ -206,7 +207,7 @@ xfs_buf_item_size(
                }
        }
 
-       xfs_buf_item_trace("SIZE NORM", bip);
+       trace_xfs_buf_item_size(bip);
        return nvecs;
 }
 
@@ -259,7 +260,7 @@ xfs_buf_item_format(
                 * is the buf log format structure with the
                 * cancel flag in it.
                 */
-               xfs_buf_item_trace("FORMAT STALE", bip);
+               trace_xfs_buf_item_format_stale(bip);
                ASSERT(bip->bli_format.blf_flags & XFS_BLI_CANCEL);
                bip->bli_format.blf_size = nvecs;
                return;
@@ -335,7 +336,7 @@ xfs_buf_item_format(
        /*
         * Check to make sure everything is consistent.
         */
-       xfs_buf_item_trace("FORMAT NORM", bip);
+       trace_xfs_buf_item_format(bip);
        xfs_buf_item_log_check(bip);
 }
 
@@ -355,8 +356,7 @@ xfs_buf_item_pin(
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
        ASSERT((bip->bli_flags & XFS_BLI_LOGGED) ||
               (bip->bli_flags & XFS_BLI_STALE));
-       xfs_buf_item_trace("PIN", bip);
-       xfs_buftrace("XFS_PIN", bp);
+       trace_xfs_buf_item_pin(bip);
        xfs_bpin(bp);
 }
 
@@ -375,7 +375,7 @@ 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;
 
@@ -383,11 +383,10 @@ xfs_buf_item_unpin(
        ASSERT(bp != NULL);
        ASSERT(XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *) == bip);
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
-       xfs_buf_item_trace("UNPIN", bip);
-       xfs_buftrace("XFS_UNPIN", bp);
+       trace_xfs_buf_item_unpin(bip);
 
        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);
@@ -395,21 +394,21 @@ xfs_buf_item_unpin(
                ASSERT(!(XFS_BUF_ISDELAYWRITE(bp)));
                ASSERT(XFS_BUF_ISSTALE(bp));
                ASSERT(bip->bli_format.blf_flags & XFS_BLI_CANCEL);
-               xfs_buf_item_trace("UNPIN STALE", bip);
-               xfs_buftrace("XFS_UNPIN STALE", bp);
+               trace_xfs_buf_item_unpin_stale(bip);
+
                /*
                 * 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 {
-                       spin_lock(&mp->m_ail->xa_lock);
-                       xfs_trans_delete_ail(mp, (xfs_log_item_t *)bip);
+                       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);
                }
@@ -440,8 +439,8 @@ xfs_buf_item_unpin_remove(
        if ((atomic_read(&bip->bli_refcount) == 1) &&
            (bip->bli_flags & XFS_BLI_STALE)) {
                ASSERT(XFS_BUF_VALUSEMA(bip->bli_buf) <= 0);
-               xfs_buf_item_trace("UNPIN REMOVE", bip);
-               xfs_buftrace("XFS_UNPIN_REMOVE", bp);
+               trace_xfs_buf_item_unpin_stale(bip);
+
                /*
                 * yes -- clear the xaction descriptor in-use flag
                 * and free the chunk if required.  We can safely
@@ -495,7 +494,7 @@ xfs_buf_item_trylock(
        XFS_BUF_HOLD(bp);
 
        ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
-       xfs_buf_item_trace("TRYLOCK SUCCESS", bip);
+       trace_xfs_buf_item_trylock(bip);
        return XFS_ITEM_SUCCESS;
 }
 
@@ -524,7 +523,6 @@ xfs_buf_item_unlock(
        uint            hold;
 
        bp = bip->bli_buf;
-       xfs_buftrace("XFS_UNLOCK", bp);
 
        /*
         * Clear the buffer's association with this transaction.
@@ -547,7 +545,7 @@ xfs_buf_item_unlock(
         */
        if (bip->bli_flags & XFS_BLI_STALE) {
                bip->bli_flags &= ~XFS_BLI_LOGGED;
-               xfs_buf_item_trace("UNLOCK STALE", bip);
+               trace_xfs_buf_item_unlock_stale(bip);
                ASSERT(bip->bli_format.blf_flags & XFS_BLI_CANCEL);
                if (!aborted)
                        return;
@@ -574,7 +572,7 @@ xfs_buf_item_unlock(
         * release the buffer at the end of this routine.
         */
        hold = bip->bli_flags & XFS_BLI_HOLD;
-       xfs_buf_item_trace("UNLOCK", bip);
+       trace_xfs_buf_item_unlock(bip);
 
        /*
         * If the buf item isn't tracking any data, free it.
@@ -618,7 +616,8 @@ xfs_buf_item_committed(
        xfs_buf_log_item_t      *bip,
        xfs_lsn_t               lsn)
 {
-       xfs_buf_item_trace("COMMITTED", bip);
+       trace_xfs_buf_item_committed(bip);
+
        if ((bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF) &&
            (bip->bli_item.li_lsn != 0)) {
                return bip->bli_item.li_lsn;
@@ -640,7 +639,7 @@ xfs_buf_item_push(
        xfs_buf_t       *bp;
 
        ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
-       xfs_buf_item_trace("PUSH", bip);
+       trace_xfs_buf_item_push(bip);
 
        bp = bip->bli_buf;
 
@@ -707,8 +706,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 *);
@@ -731,15 +730,13 @@ 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_NOFS);
-#endif
 
 #ifdef XFS_TRANS_DEBUG
        /*
@@ -877,9 +874,6 @@ xfs_buf_item_free(
        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);
 }
 
@@ -896,7 +890,8 @@ xfs_buf_item_relse(
 {
        xfs_buf_log_item_t      *bip;
 
-       xfs_buftrace("XFS_RELSE", bp);
+       trace_xfs_buf_item_relse(bp, _RET_IP_);
+
        bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t*);
        XFS_BUF_SET_FSPRIVATE(bp, bip->bli_item.li_bio_list);
        if ((XFS_BUF_FSPRIVATE(bp, void *) == NULL) &&
@@ -993,25 +988,11 @@ xfs_buf_iodone_callbacks(
                if (XFS_FORCED_SHUTDOWN(mp)) {
                        ASSERT(XFS_BUF_TARGET(bp) == mp->m_ddev_targp);
                        XFS_BUF_SUPER_STALE(bp);
-                       xfs_buftrace("BUF_IODONE_CB", bp);
+                       trace_xfs_buf_item_iodone(bp, _RET_IP_);
                        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;
                }
 
@@ -1043,7 +1024,7 @@ xfs_buf_iodone_callbacks(
                                XFS_BUF_SET_START(bp);
                        }
                        ASSERT(XFS_BUF_IODONE_FUNC(bp));
-                       xfs_buftrace("BUF_IODONE ASYNC", bp);
+                       trace_xfs_buf_item_iodone_async(bp, _RET_IP_);
                        xfs_buf_relse(bp);
                } else {
                        /*
@@ -1066,9 +1047,7 @@ xfs_buf_iodone_callbacks(
                }
                return;
        }
-#ifdef XFSERRORDEBUG
-       xfs_buftrace("XFS BUFCB NOERR", bp);
-#endif
+
        xfs_buf_do_callbacks(bp, lip);
        XFS_BUF_SET_FSPRIVATE(bp, NULL);
        XFS_BUF_CLR_IODONE_FUNC(bp);
@@ -1094,7 +1073,9 @@ xfs_buf_error_relse(
        XFS_BUF_DONE(bp);
        XFS_BUF_UNDELAYWRITE(bp);
        XFS_BUF_ERROR(bp,0);
-       xfs_buftrace("BUF_ERROR_RELSE", bp);
+
+       trace_xfs_buf_error_relse(bp, _RET_IP_);
+
        if (! XFS_FORCED_SHUTDOWN(mp))
                xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR);
        /*
@@ -1122,57 +1103,22 @@ xfs_buf_iodone(
        xfs_buf_t               *bp,
        xfs_buf_log_item_t      *bip)
 {
-       struct xfs_mount        *mp;
+       struct xfs_ail          *ailp = bip->bli_item.li_ailp;
 
        ASSERT(bip->bli_buf == bp);
 
        xfs_buf_rele(bp);
-       mp = bip->bli_item.li_mountp;
 
        /*
         * 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.
         */
-       spin_lock(&mp->m_ail->xa_lock);
-       /*
-        * xfs_trans_delete_ail() drops the AIL lock.
-        */
-       xfs_trans_delete_ail(mp, (xfs_log_item_t *)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)
-void
-xfs_buf_item_trace(
-       char                    *id,
-       xfs_buf_log_item_t      *bip)
-{
-       xfs_buf_t               *bp;
-       ASSERT(bip->bli_trace != NULL);
-
-       bp = bip->bli_buf;
-       ktrace_enter(bip->bli_trace,
-                    (void *)id,
-                    (void *)bip->bli_buf,
-                    (void *)((unsigned long)bip->bli_flags),
-                    (void *)((unsigned long)bip->bli_recur),
-                    (void *)((unsigned long)atomic_read(&bip->bli_refcount)),
-                    (void *)((unsigned long)
-                               (0xFFFFFFFF & XFS_BUF_ADDR(bp) >> 32)),
-                    (void *)((unsigned long)(0xFFFFFFFF & XFS_BUF_ADDR(bp))),
-                    (void *)((unsigned long)XFS_BUF_COUNT(bp)),
-                    (void *)((unsigned long)XFS_BUF_BFLAGS(bp)),
-                    XFS_BUF_FSPRIVATE(bp, void *),
-                    XFS_BUF_FSPRIVATE2(bp, void *),
-                    (void *)(unsigned long)XFS_BUF_ISPINNED(bp),
-                    (void *)XFS_BUF_IODONE_FUNC(bp),
-                    (void *)((unsigned long)(XFS_BUF_VALUSEMA(bp))),
-                    (void *)bip->bli_item.li_desc,
-                    (void *)((unsigned long)bip->bli_item.li_flags));
-}
-#endif /* XFS_BLI_TRACE */