xfs: improve metadata I/O merging in the elevator
[safe/jmp/linux-2.6] / fs / xfs / xfs_rw.c
index fea6861..5aa07ca 100644 (file)
@@ -44,6 +44,7 @@
 #include "xfs_error.h"
 #include "xfs_buf_item.h"
 #include "xfs_rw.h"
+#include "xfs_trace.h"
 
 /*
  * This is a subroutine for xfs_write() and other writers (xfs_ioctl)
@@ -88,90 +89,6 @@ xfs_write_clear_setuid(
 }
 
 /*
- * Handle logging requirements of various synchronous types of write.
- */
-int
-xfs_write_sync_logforce(
-       xfs_mount_t     *mp,
-       xfs_inode_t     *ip)
-{
-       int             error = 0;
-
-       /*
-        * If we're treating this as O_DSYNC and we have not updated the
-        * size, force the log.
-        */
-       if (!(mp->m_flags & XFS_MOUNT_OSYNCISOSYNC) &&
-           !(ip->i_update_size)) {
-               xfs_inode_log_item_t    *iip = ip->i_itemp;
-
-               /*
-                * If an allocation transaction occurred
-                * without extending the size, then we have to force
-                * the log up the proper point to ensure that the
-                * allocation is permanent.  We can't count on
-                * the fact that buffered writes lock out direct I/O
-                * writes - the direct I/O write could have extended
-                * the size nontransactionally, then finished before
-                * we started.  xfs_write_file will think that the file
-                * didn't grow but the update isn't safe unless the
-                * size change is logged.
-                *
-                * Force the log if we've committed a transaction
-                * against the inode or if someone else has and
-                * the commit record hasn't gone to disk (e.g.
-                * the inode is pinned).  This guarantees that
-                * all changes affecting the inode are permanent
-                * when we return.
-                */
-               if (iip && iip->ili_last_lsn) {
-                       error = _xfs_log_force(mp, iip->ili_last_lsn,
-                                       XFS_LOG_FORCE | XFS_LOG_SYNC, NULL);
-               } else if (xfs_ipincount(ip) > 0) {
-                       error = _xfs_log_force(mp, (xfs_lsn_t)0,
-                                       XFS_LOG_FORCE | XFS_LOG_SYNC, NULL);
-               }
-
-       } else {
-               xfs_trans_t     *tp;
-
-               /*
-                * O_SYNC or O_DSYNC _with_ a size update are handled
-                * the same way.
-                *
-                * If the write was synchronous then we need to make
-                * sure that the inode modification time is permanent.
-                * We'll have updated the timestamp above, so here
-                * we use a synchronous transaction to log the inode.
-                * It's not fast, but it's necessary.
-                *
-                * If this a dsync write and the size got changed
-                * non-transactionally, then we need to ensure that
-                * the size change gets logged in a synchronous
-                * transaction.
-                */
-               tp = xfs_trans_alloc(mp, XFS_TRANS_WRITE_SYNC);
-               if ((error = xfs_trans_reserve(tp, 0,
-                                               XFS_SWRITE_LOG_RES(mp),
-                                               0, 0, 0))) {
-                       /* Transaction reserve failed */
-                       xfs_trans_cancel(tp, 0);
-               } else {
-                       /* Transaction reserve successful */
-                       xfs_ilock(ip, XFS_ILOCK_EXCL);
-                       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-                       xfs_trans_ihold(tp, ip);
-                       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
-                       xfs_trans_set_sync(tp);
-                       error = xfs_trans_commit(tp, 0);
-                       xfs_iunlock(ip, XFS_ILOCK_EXCL);
-               }
-       }
-
-       return error;
-}
-
-/*
  * Force a shutdown of the filesystem instantly while keeping
  * the filesystem consistent. We don't do an unmount here; just shutdown
  * the shop, make sure that absolutely nothing persistent happens to
@@ -255,7 +172,6 @@ xfs_bioerror(
         * No need to wait until the buffer is unpinned.
         * We aren't flushing it.
         */
-       xfs_buftrace("XFS IOERROR", bp);
        XFS_BUF_ERROR(bp, EIO);
        /*
         * We're calling biodone, so delete B_DONE flag. Either way
@@ -289,7 +205,6 @@ xfs_bioerror_relse(
        ASSERT(XFS_BUF_IODONE_FUNC(bp) != xfs_buf_iodone_callbacks);
        ASSERT(XFS_BUF_IODONE_FUNC(bp) != xlog_iodone);
 
-       xfs_buftrace("XFS IOERRELSE", bp);
        fl = XFS_BUF_BFLAGS(bp);
        /*
         * No need to wait until the buffer is unpinned.
@@ -361,10 +276,10 @@ xfs_read_buf(
        xfs_buf_t        *bp;
        int              error;
 
-       if (flags)
-               bp = xfs_buf_read_flags(target, blkno, len, flags);
-       else
-               bp = xfs_buf_read(target, blkno, len, flags);
+       if (!flags)
+               flags = XBF_LOCK | XBF_MAPPED;
+
+       bp = xfs_buf_read(target, blkno, len, flags);
        if (!bp)
                return XFS_ERROR(EIO);
        error = XFS_BUF_GETERROR(bp);
@@ -420,3 +335,25 @@ xfs_bwrite(
        }
        return (error);
 }
+
+/*
+ * helper function to extract extent size hint from inode
+ */
+xfs_extlen_t
+xfs_get_extsz_hint(
+       struct xfs_inode        *ip)
+{
+       xfs_extlen_t            extsz;
+
+       if (unlikely(XFS_IS_REALTIME_INODE(ip))) {
+               extsz = (ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE)
+                               ? ip->i_d.di_extsize
+                               : ip->i_mount->m_sb.sb_rextsize;
+               ASSERT(extsz);
+       } else {
+               extsz = (ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE)
+                               ? ip->i_d.di_extsize : 0;
+       }
+
+       return extsz;
+}