[XFS] Unwrap XFS_SB_LOCK.
[pandora-kernel.git] / fs / xfs / xfs_bmap.c
index 9a654fa..97f0328 100644 (file)
@@ -52,6 +52,8 @@
 #include "xfs_quota.h"
 #include "xfs_trans_space.h"
 #include "xfs_buf_item.h"
+#include "xfs_filestream.h"
+#include "xfs_vnodeops.h"
 
 
 #ifdef DEBUG
@@ -247,7 +249,7 @@ xfs_bmap_local_to_extents(
  * Else, *lastxp will be set to the index of the found
  * entry; *gotp will contain the entry.
  */
-STATIC xfs_bmbt_rec_t *                        /* pointer to found extent entry */
+STATIC xfs_bmbt_rec_host_t *           /* pointer to found extent entry */
 xfs_bmap_search_extents(
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_fileoff_t   bno,            /* block number searched for */
@@ -271,27 +273,12 @@ xfs_bmap_isaeof(
        char            *aeof);         /* return value */
 
 #ifdef XFS_BMAP_TRACE
-/*
- * Add a bmap trace buffer entry.  Base routine for the others.
- */
-STATIC void
-xfs_bmap_trace_addentry(
-       int             opcode,         /* operation */
-       char            *fname,         /* function name */
-       char            *desc,          /* operation description */
-       xfs_inode_t     *ip,            /* incore inode pointer */
-       xfs_extnum_t    idx,            /* index of entry(ies) */
-       xfs_extnum_t    cnt,            /* count of entries, 1 or 2 */
-       xfs_bmbt_rec_t  *r1,            /* first record */
-       xfs_bmbt_rec_t  *r2,            /* second record or null */
-       int             whichfork);     /* data or attr fork */
-
 /*
  * Add bmap trace entry prior to a call to xfs_iext_remove.
  */
 STATIC void
 xfs_bmap_trace_delete(
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        char            *desc,          /* operation description */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    idx,            /* index of entry(entries) deleted */
@@ -304,7 +291,7 @@ xfs_bmap_trace_delete(
  */
 STATIC void
 xfs_bmap_trace_insert(
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        char            *desc,          /* operation description */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    idx,            /* index of entry(entries) inserted */
@@ -318,7 +305,7 @@ xfs_bmap_trace_insert(
  */
 STATIC void
 xfs_bmap_trace_post_update(
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        char            *desc,          /* operation description */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    idx,            /* index of entry updated */
@@ -329,17 +316,25 @@ xfs_bmap_trace_post_update(
  */
 STATIC void
 xfs_bmap_trace_pre_update(
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        char            *desc,          /* operation description */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    idx,            /* index of entry to be updated */
        int             whichfork);     /* data or attr fork */
 
+#define        XFS_BMAP_TRACE_DELETE(d,ip,i,c,w)       \
+       xfs_bmap_trace_delete(__FUNCTION__,d,ip,i,c,w)
+#define        XFS_BMAP_TRACE_INSERT(d,ip,i,c,r1,r2,w) \
+       xfs_bmap_trace_insert(__FUNCTION__,d,ip,i,c,r1,r2,w)
+#define        XFS_BMAP_TRACE_POST_UPDATE(d,ip,i,w)    \
+       xfs_bmap_trace_post_update(__FUNCTION__,d,ip,i,w)
+#define        XFS_BMAP_TRACE_PRE_UPDATE(d,ip,i,w)     \
+       xfs_bmap_trace_pre_update(__FUNCTION__,d,ip,i,w)
 #else
-#define        xfs_bmap_trace_delete(f,d,ip,i,c,w)
-#define        xfs_bmap_trace_insert(f,d,ip,i,c,r1,r2,w)
-#define        xfs_bmap_trace_post_update(f,d,ip,i,w)
-#define        xfs_bmap_trace_pre_update(f,d,ip,i,w)
+#define        XFS_BMAP_TRACE_DELETE(d,ip,i,c,w)
+#define        XFS_BMAP_TRACE_INSERT(d,ip,i,c,r1,r2,w)
+#define        XFS_BMAP_TRACE_POST_UPDATE(d,ip,i,w)
+#define        XFS_BMAP_TRACE_PRE_UPDATE(d,ip,i,w)
 #endif /* XFS_BMAP_TRACE */
 
 /*
@@ -531,9 +526,6 @@ xfs_bmap_add_extent(
        xfs_filblks_t           da_new; /* new count del alloc blocks used */
        xfs_filblks_t           da_old; /* old count del alloc blocks used */
        int                     error;  /* error return value */
-#ifdef XFS_BMAP_TRACE
-       static char             fname[] = "xfs_bmap_add_extent";
-#endif
        xfs_ifork_t             *ifp;   /* inode fork ptr */
        int                     logflags; /* returned value */
        xfs_extnum_t            nextents; /* number of extents in file now */
@@ -551,8 +543,8 @@ xfs_bmap_add_extent(
         * already extents in the list.
         */
        if (nextents == 0) {
-               xfs_bmap_trace_insert(fname, "insert empty", ip, 0, 1, new,
-                       NULL, whichfork);
+               XFS_BMAP_TRACE_INSERT("insert empty", ip, 0, 1, new, NULL,
+                       whichfork);
                xfs_iext_insert(ifp, 0, 1, new);
                ASSERT(cur == NULL);
                ifp->if_lastex = 0;
@@ -708,11 +700,8 @@ xfs_bmap_add_extent_delay_real(
 {
        xfs_btree_cur_t         *cur;   /* btree cursor */
        int                     diff;   /* temp value */
-       xfs_bmbt_rec_t          *ep;    /* extent entry for idx */
+       xfs_bmbt_rec_host_t     *ep;    /* extent entry for idx */
        int                     error;  /* error return value */
-#ifdef XFS_BMAP_TRACE
-       static char             fname[] = "xfs_bmap_add_extent_delay_real";
-#endif
        int                     i;      /* temp state */
        xfs_ifork_t             *ifp;   /* inode fork pointer */
        xfs_fileoff_t           new_endoff;     /* end offset of new entry */
@@ -808,15 +797,14 @@ xfs_bmap_add_extent_delay_real(
                 * Filling in all of a previously delayed allocation extent.
                 * The left and right neighbors are both contiguous with new.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|RF|LC|RC", ip, idx - 1,
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|RF|LC|RC", ip, idx - 1,
                        XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1),
                        LEFT.br_blockcount + PREV.br_blockcount +
                        RIGHT.br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LF|RF|LC|RC", ip, idx - 1,
-                       XFS_DATA_FORK);
-               xfs_bmap_trace_delete(fname, "LF|RF|LC|RC", ip, idx, 2,
+               XFS_BMAP_TRACE_POST_UPDATE("LF|RF|LC|RC", ip, idx - 1,
                        XFS_DATA_FORK);
+               XFS_BMAP_TRACE_DELETE("LF|RF|LC|RC", ip, idx, 2, XFS_DATA_FORK);
                xfs_iext_remove(ifp, idx, 2);
                ip->i_df.if_lastex = idx - 1;
                ip->i_d.di_nextents--;
@@ -855,15 +843,14 @@ xfs_bmap_add_extent_delay_real(
                 * Filling in all of a previously delayed allocation extent.
                 * The left neighbor is contiguous, the right is not.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|RF|LC", ip, idx - 1,
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|RF|LC", ip, idx - 1,
                        XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1),
                        LEFT.br_blockcount + PREV.br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LF|RF|LC", ip, idx - 1,
+               XFS_BMAP_TRACE_POST_UPDATE("LF|RF|LC", ip, idx - 1,
                        XFS_DATA_FORK);
                ip->i_df.if_lastex = idx - 1;
-               xfs_bmap_trace_delete(fname, "LF|RF|LC", ip, idx, 1,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_DELETE("LF|RF|LC", ip, idx, 1, XFS_DATA_FORK);
                xfs_iext_remove(ifp, idx, 1);
                if (cur == NULL)
                        rval = XFS_ILOG_DEXT;
@@ -892,16 +879,13 @@ xfs_bmap_add_extent_delay_real(
                 * Filling in all of a previously delayed allocation extent.
                 * The right neighbor is contiguous, the left is not.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|RF|RC", ip, idx,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|RF|RC", ip, idx, XFS_DATA_FORK);
                xfs_bmbt_set_startblock(ep, new->br_startblock);
                xfs_bmbt_set_blockcount(ep,
                        PREV.br_blockcount + RIGHT.br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LF|RF|RC", ip, idx,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("LF|RF|RC", ip, idx, XFS_DATA_FORK);
                ip->i_df.if_lastex = idx;
-               xfs_bmap_trace_delete(fname, "LF|RF|RC", ip, idx + 1, 1,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_DELETE("LF|RF|RC", ip, idx + 1, 1, XFS_DATA_FORK);
                xfs_iext_remove(ifp, idx + 1, 1);
                if (cur == NULL)
                        rval = XFS_ILOG_DEXT;
@@ -931,11 +915,9 @@ xfs_bmap_add_extent_delay_real(
                 * Neither the left nor right neighbors are contiguous with
                 * the new one.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|RF", ip, idx,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|RF", ip, idx, XFS_DATA_FORK);
                xfs_bmbt_set_startblock(ep, new->br_startblock);
-               xfs_bmap_trace_post_update(fname, "LF|RF", ip, idx,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("LF|RF", ip, idx, XFS_DATA_FORK);
                ip->i_df.if_lastex = idx;
                ip->i_d.di_nextents++;
                if (cur == NULL)
@@ -963,17 +945,14 @@ xfs_bmap_add_extent_delay_real(
                 * Filling in the first part of a previous delayed allocation.
                 * The left neighbor is contiguous.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|LC", ip, idx - 1,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|LC", ip, idx - 1, XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1),
                        LEFT.br_blockcount + new->br_blockcount);
                xfs_bmbt_set_startoff(ep,
                        PREV.br_startoff + new->br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LF|LC", ip, idx - 1,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("LF|LC", ip, idx - 1, XFS_DATA_FORK);
                temp = PREV.br_blockcount - new->br_blockcount;
-               xfs_bmap_trace_pre_update(fname, "LF|LC", ip, idx,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|LC", ip, idx, XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(ep, temp);
                ip->i_df.if_lastex = idx - 1;
                if (cur == NULL)
@@ -995,8 +974,7 @@ xfs_bmap_add_extent_delay_real(
                temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
                        STARTBLOCKVAL(PREV.br_startblock));
                xfs_bmbt_set_startblock(ep, NULLSTARTBLOCK((int)temp));
-               xfs_bmap_trace_post_update(fname, "LF|LC", ip, idx,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("LF|LC", ip, idx, XFS_DATA_FORK);
                *dnew = temp;
                /* DELTA: The boundary between two in-core extents moved. */
                temp = LEFT.br_startoff;
@@ -1009,11 +987,11 @@ xfs_bmap_add_extent_delay_real(
                 * Filling in the first part of a previous delayed allocation.
                 * The left neighbor is not contiguous.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("LF", ip, idx, XFS_DATA_FORK);
                xfs_bmbt_set_startoff(ep, new_endoff);
                temp = PREV.br_blockcount - new->br_blockcount;
                xfs_bmbt_set_blockcount(ep, temp);
-               xfs_bmap_trace_insert(fname, "LF", ip, idx, 1, new, NULL,
+               XFS_BMAP_TRACE_INSERT("LF", ip, idx, 1, new, NULL,
                        XFS_DATA_FORK);
                xfs_iext_insert(ifp, idx, 1, new);
                ip->i_df.if_lastex = idx;
@@ -1046,8 +1024,7 @@ xfs_bmap_add_extent_delay_real(
                        (cur ? cur->bc_private.b.allocated : 0));
                ep = xfs_iext_get_ext(ifp, idx + 1);
                xfs_bmbt_set_startblock(ep, NULLSTARTBLOCK((int)temp));
-               xfs_bmap_trace_post_update(fname, "LF", ip, idx + 1,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("LF", ip, idx + 1, XFS_DATA_FORK);
                *dnew = temp;
                /* DELTA: One in-core extent is split in two. */
                temp = PREV.br_startoff;
@@ -1060,17 +1037,14 @@ xfs_bmap_add_extent_delay_real(
                 * The right neighbor is contiguous with the new allocation.
                 */
                temp = PREV.br_blockcount - new->br_blockcount;
-               xfs_bmap_trace_pre_update(fname, "RF|RC", ip, idx,
-                       XFS_DATA_FORK);
-               xfs_bmap_trace_pre_update(fname, "RF|RC", ip, idx + 1,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("RF|RC", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("RF|RC", ip, idx + 1, XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(ep, temp);
                xfs_bmbt_set_allf(xfs_iext_get_ext(ifp, idx + 1),
                        new->br_startoff, new->br_startblock,
                        new->br_blockcount + RIGHT.br_blockcount,
                        RIGHT.br_state);
-               xfs_bmap_trace_post_update(fname, "RF|RC", ip, idx + 1,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("RF|RC", ip, idx + 1, XFS_DATA_FORK);
                ip->i_df.if_lastex = idx + 1;
                if (cur == NULL)
                        rval = XFS_ILOG_DEXT;
@@ -1091,8 +1065,7 @@ xfs_bmap_add_extent_delay_real(
                temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
                        STARTBLOCKVAL(PREV.br_startblock));
                xfs_bmbt_set_startblock(ep, NULLSTARTBLOCK((int)temp));
-               xfs_bmap_trace_post_update(fname, "RF|RC", ip, idx,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("RF|RC", ip, idx, XFS_DATA_FORK);
                *dnew = temp;
                /* DELTA: The boundary between two in-core extents moved. */
                temp = PREV.br_startoff;
@@ -1106,10 +1079,10 @@ xfs_bmap_add_extent_delay_real(
                 * The right neighbor is not contiguous.
                 */
                temp = PREV.br_blockcount - new->br_blockcount;
-               xfs_bmap_trace_pre_update(fname, "RF", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("RF", ip, idx, XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(ep, temp);
-               xfs_bmap_trace_insert(fname, "RF", ip, idx + 1, 1,
-                       new, NULL, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_INSERT("RF", ip, idx + 1, 1, new, NULL,
+                       XFS_DATA_FORK);
                xfs_iext_insert(ifp, idx + 1, 1, new);
                ip->i_df.if_lastex = idx + 1;
                ip->i_d.di_nextents++;
@@ -1141,7 +1114,7 @@ xfs_bmap_add_extent_delay_real(
                        (cur ? cur->bc_private.b.allocated : 0));
                ep = xfs_iext_get_ext(ifp, idx);
                xfs_bmbt_set_startblock(ep, NULLSTARTBLOCK((int)temp));
-               xfs_bmap_trace_post_update(fname, "RF", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("RF", ip, idx, XFS_DATA_FORK);
                *dnew = temp;
                /* DELTA: One in-core extent is split in two. */
                temp = PREV.br_startoff;
@@ -1155,7 +1128,7 @@ xfs_bmap_add_extent_delay_real(
                 * This case is avoided almost all the time.
                 */
                temp = new->br_startoff - PREV.br_startoff;
-               xfs_bmap_trace_pre_update(fname, "0", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("0", ip, idx, XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(ep, temp);
                r[0] = *new;
                r[1].br_state = PREV.br_state;
@@ -1163,7 +1136,7 @@ xfs_bmap_add_extent_delay_real(
                r[1].br_startoff = new_endoff;
                temp2 = PREV.br_startoff + PREV.br_blockcount - new_endoff;
                r[1].br_blockcount = temp2;
-               xfs_bmap_trace_insert(fname, "0", ip, idx + 1, 2, &r[0], &r[1],
+               XFS_BMAP_TRACE_INSERT("0", ip, idx + 1, 2, &r[0], &r[1],
                        XFS_DATA_FORK);
                xfs_iext_insert(ifp, idx + 1, 2, &r[0]);
                ip->i_df.if_lastex = idx + 1;
@@ -1222,13 +1195,11 @@ xfs_bmap_add_extent_delay_real(
                }
                ep = xfs_iext_get_ext(ifp, idx);
                xfs_bmbt_set_startblock(ep, NULLSTARTBLOCK((int)temp));
-               xfs_bmap_trace_post_update(fname, "0", ip, idx, XFS_DATA_FORK);
-               xfs_bmap_trace_pre_update(fname, "0", ip, idx + 2,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("0", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("0", ip, idx + 2, XFS_DATA_FORK);
                xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, idx + 2),
                        NULLSTARTBLOCK((int)temp2));
-               xfs_bmap_trace_post_update(fname, "0", ip, idx + 2,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("0", ip, idx + 2, XFS_DATA_FORK);
                *dnew = temp + temp2;
                /* DELTA: One in-core extent is split in three. */
                temp = PREV.br_startoff;
@@ -1285,11 +1256,8 @@ xfs_bmap_add_extent_unwritten_real(
        xfs_extdelta_t          *delta) /* Change made to incore extents */
 {
        xfs_btree_cur_t         *cur;   /* btree cursor */
-       xfs_bmbt_rec_t          *ep;    /* extent entry for idx */
+       xfs_bmbt_rec_host_t     *ep;    /* extent entry for idx */
        int                     error;  /* error return value */
-#ifdef XFS_BMAP_TRACE
-       static char             fname[] = "xfs_bmap_add_extent_unwritten_real";
-#endif
        int                     i;      /* temp state */
        xfs_ifork_t             *ifp;   /* inode fork pointer */
        xfs_fileoff_t           new_endoff;     /* end offset of new entry */
@@ -1390,15 +1358,14 @@ xfs_bmap_add_extent_unwritten_real(
                 * Setting all of a previous oldext extent to newext.
                 * The left and right neighbors are both contiguous with new.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|RF|LC|RC", ip, idx - 1,
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|RF|LC|RC", ip, idx - 1,
                        XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1),
                        LEFT.br_blockcount + PREV.br_blockcount +
                        RIGHT.br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LF|RF|LC|RC", ip, idx - 1,
-                       XFS_DATA_FORK);
-               xfs_bmap_trace_delete(fname, "LF|RF|LC|RC", ip, idx, 2,
+               XFS_BMAP_TRACE_POST_UPDATE("LF|RF|LC|RC", ip, idx - 1,
                        XFS_DATA_FORK);
+               XFS_BMAP_TRACE_DELETE("LF|RF|LC|RC", ip, idx, 2, XFS_DATA_FORK);
                xfs_iext_remove(ifp, idx, 2);
                ip->i_df.if_lastex = idx - 1;
                ip->i_d.di_nextents -= 2;
@@ -1441,15 +1408,14 @@ xfs_bmap_add_extent_unwritten_real(
                 * Setting all of a previous oldext extent to newext.
                 * The left neighbor is contiguous, the right is not.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|RF|LC", ip, idx - 1,
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|RF|LC", ip, idx - 1,
                        XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1),
                        LEFT.br_blockcount + PREV.br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LF|RF|LC", ip, idx - 1,
+               XFS_BMAP_TRACE_POST_UPDATE("LF|RF|LC", ip, idx - 1,
                        XFS_DATA_FORK);
                ip->i_df.if_lastex = idx - 1;
-               xfs_bmap_trace_delete(fname, "LF|RF|LC", ip, idx, 1,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_DELETE("LF|RF|LC", ip, idx, 1, XFS_DATA_FORK);
                xfs_iext_remove(ifp, idx, 1);
                ip->i_d.di_nextents--;
                if (cur == NULL)
@@ -1484,16 +1450,15 @@ xfs_bmap_add_extent_unwritten_real(
                 * Setting all of a previous oldext extent to newext.
                 * The right neighbor is contiguous, the left is not.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|RF|RC", ip, idx,
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|RF|RC", ip, idx,
                        XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(ep,
                        PREV.br_blockcount + RIGHT.br_blockcount);
                xfs_bmbt_set_state(ep, newext);
-               xfs_bmap_trace_post_update(fname, "LF|RF|RC", ip, idx,
+               XFS_BMAP_TRACE_POST_UPDATE("LF|RF|RC", ip, idx,
                        XFS_DATA_FORK);
                ip->i_df.if_lastex = idx;
-               xfs_bmap_trace_delete(fname, "LF|RF|RC", ip, idx + 1, 1,
-                       XFS_DATA_FORK);
+               XFS_BMAP_TRACE_DELETE("LF|RF|RC", ip, idx + 1, 1, XFS_DATA_FORK);
                xfs_iext_remove(ifp, idx + 1, 1);
                ip->i_d.di_nextents--;
                if (cur == NULL)
@@ -1529,10 +1494,10 @@ xfs_bmap_add_extent_unwritten_real(
                 * Neither the left nor right neighbors are contiguous with
                 * the new one.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|RF", ip, idx,
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|RF", ip, idx,
                        XFS_DATA_FORK);
                xfs_bmbt_set_state(ep, newext);
-               xfs_bmap_trace_post_update(fname, "LF|RF", ip, idx,
+               XFS_BMAP_TRACE_POST_UPDATE("LF|RF", ip, idx,
                        XFS_DATA_FORK);
                ip->i_df.if_lastex = idx;
                if (cur == NULL)
@@ -1559,21 +1524,21 @@ xfs_bmap_add_extent_unwritten_real(
                 * Setting the first part of a previous oldext extent to newext.
                 * The left neighbor is contiguous.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF|LC", ip, idx - 1,
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|LC", ip, idx - 1,
                        XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1),
                        LEFT.br_blockcount + new->br_blockcount);
                xfs_bmbt_set_startoff(ep,
                        PREV.br_startoff + new->br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LF|LC", ip, idx - 1,
+               XFS_BMAP_TRACE_POST_UPDATE("LF|LC", ip, idx - 1,
                        XFS_DATA_FORK);
-               xfs_bmap_trace_pre_update(fname, "LF|LC", ip, idx,
+               XFS_BMAP_TRACE_PRE_UPDATE("LF|LC", ip, idx,
                        XFS_DATA_FORK);
                xfs_bmbt_set_startblock(ep,
                        new->br_startblock + new->br_blockcount);
                xfs_bmbt_set_blockcount(ep,
                        PREV.br_blockcount - new->br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LF|LC", ip, idx,
+               XFS_BMAP_TRACE_POST_UPDATE("LF|LC", ip, idx,
                        XFS_DATA_FORK);
                ip->i_df.if_lastex = idx - 1;
                if (cur == NULL)
@@ -1610,15 +1575,15 @@ xfs_bmap_add_extent_unwritten_real(
                 * Setting the first part of a previous oldext extent to newext.
                 * The left neighbor is not contiguous.
                 */
-               xfs_bmap_trace_pre_update(fname, "LF", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("LF", ip, idx, XFS_DATA_FORK);
                ASSERT(ep && xfs_bmbt_get_state(ep) == oldext);
                xfs_bmbt_set_startoff(ep, new_endoff);
                xfs_bmbt_set_blockcount(ep,
                        PREV.br_blockcount - new->br_blockcount);
                xfs_bmbt_set_startblock(ep,
                        new->br_startblock + new->br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LF", ip, idx, XFS_DATA_FORK);
-               xfs_bmap_trace_insert(fname, "LF", ip, idx, 1, new, NULL,
+               XFS_BMAP_TRACE_POST_UPDATE("LF", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_INSERT("LF", ip, idx, 1, new, NULL,
                        XFS_DATA_FORK);
                xfs_iext_insert(ifp, idx, 1, new);
                ip->i_df.if_lastex = idx;
@@ -1653,18 +1618,18 @@ xfs_bmap_add_extent_unwritten_real(
                 * Setting the last part of a previous oldext extent to newext.
                 * The right neighbor is contiguous with the new allocation.
                 */
-               xfs_bmap_trace_pre_update(fname, "RF|RC", ip, idx,
+               XFS_BMAP_TRACE_PRE_UPDATE("RF|RC", ip, idx,
                        XFS_DATA_FORK);
-               xfs_bmap_trace_pre_update(fname, "RF|RC", ip, idx + 1,
+               XFS_BMAP_TRACE_PRE_UPDATE("RF|RC", ip, idx + 1,
                        XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(ep,
                        PREV.br_blockcount - new->br_blockcount);
-               xfs_bmap_trace_post_update(fname, "RF|RC", ip, idx,
+               XFS_BMAP_TRACE_POST_UPDATE("RF|RC", ip, idx,
                        XFS_DATA_FORK);
                xfs_bmbt_set_allf(xfs_iext_get_ext(ifp, idx + 1),
                        new->br_startoff, new->br_startblock,
                        new->br_blockcount + RIGHT.br_blockcount, newext);
-               xfs_bmap_trace_post_update(fname, "RF|RC", ip, idx + 1,
+               XFS_BMAP_TRACE_POST_UPDATE("RF|RC", ip, idx + 1,
                        XFS_DATA_FORK);
                ip->i_df.if_lastex = idx + 1;
                if (cur == NULL)
@@ -1700,12 +1665,12 @@ xfs_bmap_add_extent_unwritten_real(
                 * Setting the last part of a previous oldext extent to newext.
                 * The right neighbor is not contiguous.
                 */
-               xfs_bmap_trace_pre_update(fname, "RF", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("RF", ip, idx, XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(ep,
                        PREV.br_blockcount - new->br_blockcount);
-               xfs_bmap_trace_post_update(fname, "RF", ip, idx, XFS_DATA_FORK);
-               xfs_bmap_trace_insert(fname, "RF", ip, idx + 1, 1,
-                       new, NULL, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("RF", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_INSERT("RF", ip, idx + 1, 1, new, NULL,
+                       XFS_DATA_FORK);
                xfs_iext_insert(ifp, idx + 1, 1, new);
                ip->i_df.if_lastex = idx + 1;
                ip->i_d.di_nextents++;
@@ -1744,17 +1709,17 @@ xfs_bmap_add_extent_unwritten_real(
                 * newext.  Contiguity is impossible here.
                 * One extent becomes three extents.
                 */
-               xfs_bmap_trace_pre_update(fname, "0", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("0", ip, idx, XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(ep,
                        new->br_startoff - PREV.br_startoff);
-               xfs_bmap_trace_post_update(fname, "0", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("0", ip, idx, XFS_DATA_FORK);
                r[0] = *new;
                r[1].br_startoff = new_endoff;
                r[1].br_blockcount =
                        PREV.br_startoff + PREV.br_blockcount - new_endoff;
                r[1].br_startblock = new->br_startblock + new->br_blockcount;
                r[1].br_state = oldext;
-               xfs_bmap_trace_insert(fname, "0", ip, idx + 1, 2, &r[0], &r[1],
+               XFS_BMAP_TRACE_INSERT("0", ip, idx + 1, 2, &r[0], &r[1],
                        XFS_DATA_FORK);
                xfs_iext_insert(ifp, idx + 1, 2, &r[0]);
                ip->i_df.if_lastex = idx + 1;
@@ -1844,10 +1809,7 @@ xfs_bmap_add_extent_hole_delay(
        xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     rsvd)           /* OK to allocate reserved blocks */
 {
-       xfs_bmbt_rec_t          *ep;    /* extent record for idx */
-#ifdef XFS_BMAP_TRACE
-       static char             fname[] = "xfs_bmap_add_extent_hole_delay";
-#endif
+       xfs_bmbt_rec_host_t     *ep;    /* extent record for idx */
        xfs_ifork_t             *ifp;   /* inode fork pointer */
        xfs_bmbt_irec_t         left;   /* left neighbor extent entry */
        xfs_filblks_t           newlen=0;       /* new indirect size */
@@ -1919,7 +1881,7 @@ xfs_bmap_add_extent_hole_delay(
                 */
                temp = left.br_blockcount + new->br_blockcount +
                        right.br_blockcount;
-               xfs_bmap_trace_pre_update(fname, "LC|RC", ip, idx - 1,
+               XFS_BMAP_TRACE_PRE_UPDATE("LC|RC", ip, idx - 1,
                        XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), temp);
                oldlen = STARTBLOCKVAL(left.br_startblock) +
@@ -1928,10 +1890,9 @@ xfs_bmap_add_extent_hole_delay(
                newlen = xfs_bmap_worst_indlen(ip, temp);
                xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, idx - 1),
                        NULLSTARTBLOCK((int)newlen));
-               xfs_bmap_trace_post_update(fname, "LC|RC", ip, idx - 1,
-                       XFS_DATA_FORK);
-               xfs_bmap_trace_delete(fname, "LC|RC", ip, idx, 1,
+               XFS_BMAP_TRACE_POST_UPDATE("LC|RC", ip, idx - 1,
                        XFS_DATA_FORK);
+               XFS_BMAP_TRACE_DELETE("LC|RC", ip, idx, 1, XFS_DATA_FORK);
                xfs_iext_remove(ifp, idx, 1);
                ip->i_df.if_lastex = idx - 1;
                /* DELTA: Two in-core extents were replaced by one. */
@@ -1946,7 +1907,7 @@ xfs_bmap_add_extent_hole_delay(
                 * Merge the new allocation with the left neighbor.
                 */
                temp = left.br_blockcount + new->br_blockcount;
-               xfs_bmap_trace_pre_update(fname, "LC", ip, idx - 1,
+               XFS_BMAP_TRACE_PRE_UPDATE("LC", ip, idx - 1,
                        XFS_DATA_FORK);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), temp);
                oldlen = STARTBLOCKVAL(left.br_startblock) +
@@ -1954,7 +1915,7 @@ xfs_bmap_add_extent_hole_delay(
                newlen = xfs_bmap_worst_indlen(ip, temp);
                xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, idx - 1),
                        NULLSTARTBLOCK((int)newlen));
-               xfs_bmap_trace_post_update(fname, "LC", ip, idx - 1,
+               XFS_BMAP_TRACE_POST_UPDATE("LC", ip, idx - 1,
                        XFS_DATA_FORK);
                ip->i_df.if_lastex = idx - 1;
                /* DELTA: One in-core extent grew into a hole. */
@@ -1968,14 +1929,14 @@ xfs_bmap_add_extent_hole_delay(
                 * on the right.
                 * Merge the new allocation with the right neighbor.
                 */
-               xfs_bmap_trace_pre_update(fname, "RC", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_PRE_UPDATE("RC", ip, idx, XFS_DATA_FORK);
                temp = new->br_blockcount + right.br_blockcount;
                oldlen = STARTBLOCKVAL(new->br_startblock) +
                        STARTBLOCKVAL(right.br_startblock);
                newlen = xfs_bmap_worst_indlen(ip, temp);
                xfs_bmbt_set_allf(ep, new->br_startoff,
                        NULLSTARTBLOCK((int)newlen), temp, right.br_state);
-               xfs_bmap_trace_post_update(fname, "RC", ip, idx, XFS_DATA_FORK);
+               XFS_BMAP_TRACE_POST_UPDATE("RC", ip, idx, XFS_DATA_FORK);
                ip->i_df.if_lastex = idx;
                /* DELTA: One in-core extent grew into a hole. */
                temp2 = temp;
@@ -1989,7 +1950,7 @@ xfs_bmap_add_extent_hole_delay(
                 * Insert a new entry.
                 */
                oldlen = newlen = 0;
-               xfs_bmap_trace_insert(fname, "0", ip, idx, 1, new, NULL,
+               XFS_BMAP_TRACE_INSERT("0", ip, idx, 1, new, NULL,
                        XFS_DATA_FORK);
                xfs_iext_insert(ifp, idx, 1, new);
                ip->i_df.if_lastex = idx;
@@ -2037,11 +1998,8 @@ xfs_bmap_add_extent_hole_real(
        xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     whichfork) /* data or attr fork */
 {
-       xfs_bmbt_rec_t          *ep;    /* pointer to extent entry ins. point */
+       xfs_bmbt_rec_host_t     *ep;    /* pointer to extent entry ins. point */
        int                     error;  /* error return value */
-#ifdef XFS_BMAP_TRACE
-       static char             fname[] = "xfs_bmap_add_extent_hole_real";
-#endif
        int                     i;      /* temp state */
        xfs_ifork_t             *ifp;   /* inode fork pointer */
        xfs_bmbt_irec_t         left;   /* left neighbor extent entry */
@@ -2118,15 +2076,14 @@ xfs_bmap_add_extent_hole_real(
                 * left and on the right.
                 * Merge all three into a single extent record.
                 */
-               xfs_bmap_trace_pre_update(fname, "LC|RC", ip, idx - 1,
+               XFS_BMAP_TRACE_PRE_UPDATE("LC|RC", ip, idx - 1,
                        whichfork);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1),
                        left.br_blockcount + new->br_blockcount +
                        right.br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LC|RC", ip, idx - 1,
+               XFS_BMAP_TRACE_POST_UPDATE("LC|RC", ip, idx - 1,
                        whichfork);
-               xfs_bmap_trace_delete(fname, "LC|RC", ip,
-                       idx, 1, whichfork);
+               XFS_BMAP_TRACE_DELETE("LC|RC", ip, idx, 1, whichfork);
                xfs_iext_remove(ifp, idx, 1);
                ifp->if_lastex = idx - 1;
                XFS_IFORK_NEXT_SET(ip, whichfork,
@@ -2168,10 +2125,10 @@ xfs_bmap_add_extent_hole_real(
                 * on the left.
                 * Merge the new allocation with the left neighbor.
                 */
-               xfs_bmap_trace_pre_update(fname, "LC", ip, idx - 1, whichfork);
+               XFS_BMAP_TRACE_PRE_UPDATE("LC", ip, idx - 1, whichfork);
                xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1),
                        left.br_blockcount + new->br_blockcount);
-               xfs_bmap_trace_post_update(fname, "LC", ip, idx - 1, whichfork);
+               XFS_BMAP_TRACE_POST_UPDATE("LC", ip, idx - 1, whichfork);
                ifp->if_lastex = idx - 1;
                if (cur == NULL) {
                        rval = XFS_ILOG_FEXT(whichfork);
@@ -2202,11 +2159,11 @@ xfs_bmap_add_extent_hole_real(
                 * on the right.
                 * Merge the new allocation with the right neighbor.
                 */
-               xfs_bmap_trace_pre_update(fname, "RC", ip, idx, whichfork);
+               XFS_BMAP_TRACE_PRE_UPDATE("RC", ip, idx, whichfork);
                xfs_bmbt_set_allf(ep, new->br_startoff, new->br_startblock,
                        new->br_blockcount + right.br_blockcount,
                        right.br_state);
-               xfs_bmap_trace_post_update(fname, "RC", ip, idx, whichfork);
+               XFS_BMAP_TRACE_POST_UPDATE("RC", ip, idx, whichfork);
                ifp->if_lastex = idx;
                if (cur == NULL) {
                        rval = XFS_ILOG_FEXT(whichfork);
@@ -2237,8 +2194,7 @@ xfs_bmap_add_extent_hole_real(
                 * real allocation.
                 * Insert a new entry.
                 */
-               xfs_bmap_trace_insert(fname, "0", ip, idx, 1, new, NULL,
-                       whichfork);
+               XFS_BMAP_TRACE_INSERT("0", ip, idx, 1, new, NULL, whichfork);
                xfs_iext_insert(ifp, idx, 1, new);
                ifp->if_lastex = idx;
                XFS_IFORK_NEXT_SET(ip, whichfork,
@@ -2605,12 +2561,10 @@ xfs_bmap_rtalloc(
        xfs_extlen_t    prod = 0;       /* product factor for allocators */
        xfs_extlen_t    ralen = 0;      /* realtime allocation length */
        xfs_extlen_t    align;          /* minimum allocation alignment */
-       xfs_rtblock_t   rtx;            /* realtime extent number */
        xfs_rtblock_t   rtb;
 
        mp = ap->ip->i_mount;
-       align = ap->ip->i_d.di_extsize ?
-               ap->ip->i_d.di_extsize : mp->m_sb.sb_rextsize;
+       align = xfs_get_extsz_hint(ap->ip);
        prod = align / mp->m_sb.sb_rextsize;
        error = xfs_bmap_extsize_align(mp, ap->gotp, ap->prevp,
                                        align, 1, ap->eof, 0,
@@ -2644,6 +2598,8 @@ xfs_bmap_rtalloc(
         * pick an extent that will space things out in the rt area.
         */
        if (ap->eof && ap->off == 0) {
+               xfs_rtblock_t uninitialized_var(rtx); /* realtime extent no */
+
                error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx);
                if (error)
                        return error;
@@ -2715,9 +2671,7 @@ xfs_bmap_btalloc(
        int             error;
 
        mp = ap->ip->i_mount;
-       align = (ap->userdata && ap->ip->i_d.di_extsize &&
-               (ap->ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE)) ?
-               ap->ip->i_d.di_extsize : 0;
+       align = ap->userdata ? xfs_get_extsz_hint(ap->ip) : 0;
        if (unlikely(align)) {
                error = xfs_bmap_extsize_align(mp, ap->gotp, ap->prevp,
                                                align, 0, ap->eof, 0, ap->conv,
@@ -2727,9 +2681,15 @@ xfs_bmap_btalloc(
        }
        nullfb = ap->firstblock == NULLFSBLOCK;
        fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, ap->firstblock);
-       if (nullfb)
-               ap->rval = XFS_INO_TO_FSB(mp, ap->ip->i_ino);
-       else
+       if (nullfb) {
+               if (ap->userdata && xfs_inode_is_filestream(ap->ip)) {
+                       ag = xfs_filestream_lookup_ag(ap->ip);
+                       ag = (ag != NULLAGNUMBER) ? ag : 0;
+                       ap->rval = XFS_AGB_TO_FSB(mp, ag, 0);
+               } else {
+                       ap->rval = XFS_INO_TO_FSB(mp, ap->ip->i_ino);
+               }
+       } else
                ap->rval = ap->firstblock;
 
        xfs_bmap_adjacent(ap);
@@ -2753,13 +2713,22 @@ xfs_bmap_btalloc(
        args.firstblock = ap->firstblock;
        blen = 0;
        if (nullfb) {
-               args.type = XFS_ALLOCTYPE_START_BNO;
+               if (ap->userdata && xfs_inode_is_filestream(ap->ip))
+                       args.type = XFS_ALLOCTYPE_NEAR_BNO;
+               else
+                       args.type = XFS_ALLOCTYPE_START_BNO;
                args.total = ap->total;
+
                /*
-                * Find the longest available space.
-                * We're going to try for the whole allocation at once.
+                * Search for an allocation group with a single extent
+                * large enough for the request.
+                *
+                * If one isn't found, then adjust the minimum allocation
+                * size to the largest space found.
                 */
                startag = ag = XFS_FSB_TO_AGNO(mp, args.fsbno);
+               if (startag == NULLAGNUMBER)
+                       startag = ag = 0;
                notinit = 0;
                down_read(&mp->m_peraglock);
                while (blen < ap->alen) {
@@ -2785,6 +2754,35 @@ xfs_bmap_btalloc(
                                        blen = longest;
                        } else
                                notinit = 1;
+
+                       if (xfs_inode_is_filestream(ap->ip)) {
+                               if (blen >= ap->alen)
+                                       break;
+
+                               if (ap->userdata) {
+                                       /*
+                                        * If startag is an invalid AG, we've
+                                        * come here once before and
+                                        * xfs_filestream_new_ag picked the
+                                        * best currently available.
+                                        *
+                                        * Don't continue looping, since we
+                                        * could loop forever.
+                                        */
+                                       if (startag == NULLAGNUMBER)
+                                               break;
+
+                                       error = xfs_filestream_new_ag(ap, &ag);
+                                       if (error) {
+                                               up_read(&mp->m_peraglock);
+                                               return error;
+                                       }
+
+                                       /* loop again to set 'blen'*/
+                                       startag = NULLAGNUMBER;
+                                       continue;
+                               }
+                       }
                        if (++ag == mp->m_sb.sb_agcount)
                                ag = 0;
                        if (ag == startag)
@@ -2809,17 +2807,27 @@ xfs_bmap_btalloc(
                 */
                else
                        args.minlen = ap->alen;
+
+               /*
+                * set the failure fallback case to look in the selected
+                * AG as the stream may have moved.
+                */
+               if (xfs_inode_is_filestream(ap->ip))
+                       ap->rval = args.fsbno = XFS_AGB_TO_FSB(mp, ag, 0);
        } else if (ap->low) {
-               args.type = XFS_ALLOCTYPE_START_BNO;
+               if (xfs_inode_is_filestream(ap->ip))
+                       args.type = XFS_ALLOCTYPE_FIRST_AG;
+               else
+                       args.type = XFS_ALLOCTYPE_START_BNO;
                args.total = args.minlen = ap->minlen;
        } else {
                args.type = XFS_ALLOCTYPE_NEAR_BNO;
                args.total = ap->total;
                args.minlen = ap->minlen;
        }
-       if (unlikely(ap->userdata && ap->ip->i_d.di_extsize &&
-                   (ap->ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE))) {
-               args.prod = ap->ip->i_d.di_extsize;
+       /* apply extent size hints if obtained earlier */
+       if (unlikely(align)) {
+               args.prod = align;
                if ((args.mod = (xfs_extlen_t)do_mod(ap->off, args.prod)))
                        args.mod = (xfs_extlen_t)(args.prod - args.mod);
        } else if (mp->m_sb.sb_blocksize >= NBPP) {
@@ -3048,12 +3056,9 @@ xfs_bmap_del_extent(
        xfs_fileoff_t           del_endoff;     /* first offset past del */
        int                     delay;  /* current block is delayed allocated */
        int                     do_fx;  /* free extent at end of routine */
-       xfs_bmbt_rec_t          *ep;    /* current extent entry pointer */
+       xfs_bmbt_rec_host_t     *ep;    /* current extent entry pointer */
        int                     error;  /* error return value */
        int                     flags;  /* inode logging flags */
-#ifdef XFS_BMAP_TRACE
-       static char             fname[] = "xfs_bmap_del_extent";
-#endif
        xfs_bmbt_irec_t         got;    /* current extent entry */
        xfs_fileoff_t           got_endoff;     /* first offset past got */
        int                     i;      /* temp state */
@@ -3147,7 +3152,7 @@ xfs_bmap_del_extent(
                /*
                 * Matches the whole extent.  Delete the entry.
                 */
-               xfs_bmap_trace_delete(fname, "3", ip, idx, 1, whichfork);
+               XFS_BMAP_TRACE_DELETE("3", ip, idx, 1, whichfork);
                xfs_iext_remove(ifp, idx, 1);
                ifp->if_lastex = idx;
                if (delay)
@@ -3168,7 +3173,7 @@ xfs_bmap_del_extent(
                /*
                 * Deleting the first part of the extent.
                 */
-               xfs_bmap_trace_pre_update(fname, "2", ip, idx, whichfork);
+               XFS_BMAP_TRACE_PRE_UPDATE("2", ip, idx, whichfork);
                xfs_bmbt_set_startoff(ep, del_endoff);
                temp = got.br_blockcount - del->br_blockcount;
                xfs_bmbt_set_blockcount(ep, temp);
@@ -3177,13 +3182,13 @@ xfs_bmap_del_extent(
                        temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
                                da_old);
                        xfs_bmbt_set_startblock(ep, NULLSTARTBLOCK((int)temp));
-                       xfs_bmap_trace_post_update(fname, "2", ip, idx,
+                       XFS_BMAP_TRACE_POST_UPDATE("2", ip, idx,
                                whichfork);
                        da_new = temp;
                        break;
                }
                xfs_bmbt_set_startblock(ep, del_endblock);
-               xfs_bmap_trace_post_update(fname, "2", ip, idx, whichfork);
+               XFS_BMAP_TRACE_POST_UPDATE("2", ip, idx, whichfork);
                if (!cur) {
                        flags |= XFS_ILOG_FEXT(whichfork);
                        break;
@@ -3199,19 +3204,19 @@ xfs_bmap_del_extent(
                 * Deleting the last part of the extent.
                 */
                temp = got.br_blockcount - del->br_blockcount;
-               xfs_bmap_trace_pre_update(fname, "1", ip, idx, whichfork);
+               XFS_BMAP_TRACE_PRE_UPDATE("1", ip, idx, whichfork);
                xfs_bmbt_set_blockcount(ep, temp);
                ifp->if_lastex = idx;
                if (delay) {
                        temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
                                da_old);
                        xfs_bmbt_set_startblock(ep, NULLSTARTBLOCK((int)temp));
-                       xfs_bmap_trace_post_update(fname, "1", ip, idx,
+                       XFS_BMAP_TRACE_POST_UPDATE("1", ip, idx,
                                whichfork);
                        da_new = temp;
                        break;
                }
-               xfs_bmap_trace_post_update(fname, "1", ip, idx, whichfork);
+               XFS_BMAP_TRACE_POST_UPDATE("1", ip, idx, whichfork);
                if (!cur) {
                        flags |= XFS_ILOG_FEXT(whichfork);
                        break;
@@ -3228,7 +3233,7 @@ xfs_bmap_del_extent(
                 * Deleting the middle of the extent.
                 */
                temp = del->br_startoff - got.br_startoff;
-               xfs_bmap_trace_pre_update(fname, "0", ip, idx, whichfork);
+               XFS_BMAP_TRACE_PRE_UPDATE("0", ip, idx, whichfork);
                xfs_bmbt_set_blockcount(ep, temp);
                new.br_startoff = del_endoff;
                temp2 = got_endoff - del_endoff;
@@ -3315,8 +3320,8 @@ xfs_bmap_del_extent(
                                }
                        }
                }
-               xfs_bmap_trace_post_update(fname, "0", ip, idx, whichfork);
-               xfs_bmap_trace_insert(fname, "0", ip, idx + 1, 1, &new, NULL,
+               XFS_BMAP_TRACE_POST_UPDATE("0", ip, idx, whichfork);
+               XFS_BMAP_TRACE_INSERT("0", ip, idx + 1, 1, &new, NULL,
                        whichfork);
                xfs_iext_insert(ifp, idx + 1, 1, &new);
                ifp->if_lastex = idx + 1;
@@ -3399,7 +3404,7 @@ xfs_bmap_extents_to_btree(
        xfs_bmbt_rec_t          *arp;           /* child record pointer */
        xfs_bmbt_block_t        *block;         /* btree root block */
        xfs_btree_cur_t         *cur;           /* bmap btree cursor */
-       xfs_bmbt_rec_t          *ep;            /* extent record pointer */
+       xfs_bmbt_rec_host_t     *ep;            /* extent record pointer */
        int                     error;          /* error return value */
        xfs_extnum_t            i, cnt;         /* extent record index */
        xfs_ifork_t             *ifp;           /* inode fork pointer */
@@ -3488,8 +3493,8 @@ xfs_bmap_extents_to_btree(
        for (cnt = i = 0; i < nextents; i++) {
                ep = xfs_iext_get_ext(ifp, i);
                if (!ISNULLSTARTBLOCK(xfs_bmbt_get_startblock(ep))) {
-                       arp->l0 = INT_GET(ep->l0, ARCH_CONVERT);
-                       arp->l1 = INT_GET(ep->l1, ARCH_CONVERT);
+                       arp->l0 = cpu_to_be64(ep->l0);
+                       arp->l1 = cpu_to_be64(ep->l1);
                        arp++; cnt++;
                }
        }
@@ -3556,9 +3561,6 @@ xfs_bmap_local_to_extents(
 {
        int             error;          /* error return value */
        int             flags;          /* logging flags returned */
-#ifdef XFS_BMAP_TRACE
-       static char     fname[] = "xfs_bmap_local_to_extents";
-#endif
        xfs_ifork_t     *ifp;           /* inode fork pointer */
 
        /*
@@ -3574,7 +3576,7 @@ xfs_bmap_local_to_extents(
        if (ifp->if_bytes) {
                xfs_alloc_arg_t args;   /* allocation arguments */
                xfs_buf_t       *bp;    /* buffer for extent block */
-               xfs_bmbt_rec_t  *ep;    /* extent record pointer */
+               xfs_bmbt_rec_host_t *ep;/* extent record pointer */
 
                args.tp = tp;
                args.mp = ip->i_mount;
@@ -3613,7 +3615,7 @@ xfs_bmap_local_to_extents(
                xfs_iext_add(ifp, 0, 1);
                ep = xfs_iext_get_ext(ifp, 0);
                xfs_bmbt_set_allf(ep, 0, args.fsbno, 1, XFS_EXT_NORM);
-               xfs_bmap_trace_post_update(fname, "new", ip, 0, whichfork);
+               XFS_BMAP_TRACE_POST_UPDATE("new", ip, 0, whichfork);
                XFS_IFORK_NEXT_SET(ip, whichfork, 1);
                ip->i_d.di_nblocks = 1;
                XFS_TRANS_MOD_DQUOT_BYINO(args.mp, tp, ip,
@@ -3639,7 +3641,7 @@ done:
  * entry (null if none).  Else, *lastxp will be set to the index
  * of the found entry; *gotp will contain the entry.
  */
-xfs_bmbt_rec_t *                       /* pointer to found extent entry */
+xfs_bmbt_rec_host_t *                  /* pointer to found extent entry */
 xfs_bmap_search_multi_extents(
        xfs_ifork_t     *ifp,           /* inode fork pointer */
        xfs_fileoff_t   bno,            /* block number searched for */
@@ -3648,7 +3650,7 @@ xfs_bmap_search_multi_extents(
        xfs_bmbt_irec_t *gotp,          /* out: extent entry found */
        xfs_bmbt_irec_t *prevp)         /* out: previous extent entry found */
 {
-       xfs_bmbt_rec_t  *ep;            /* extent record pointer */
+       xfs_bmbt_rec_host_t *ep;                /* extent record pointer */
        xfs_extnum_t    lastx;          /* last extent index */
 
        /*
@@ -3690,7 +3692,7 @@ xfs_bmap_search_multi_extents(
  * Else, *lastxp will be set to the index of the found
  * entry; *gotp will contain the entry.
  */
-STATIC xfs_bmbt_rec_t *                 /* pointer to found extent entry */
+STATIC xfs_bmbt_rec_host_t *                 /* pointer to found extent entry */
 xfs_bmap_search_extents(
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_fileoff_t   bno,            /* block number searched for */
@@ -3701,7 +3703,7 @@ xfs_bmap_search_extents(
        xfs_bmbt_irec_t *prevp)         /* out: previous extent entry found */
 {
        xfs_ifork_t     *ifp;           /* inode fork pointer */
-       xfs_bmbt_rec_t  *ep;            /* extent record pointer */
+       xfs_bmbt_rec_host_t  *ep;            /* extent record pointer */
 
        XFS_STATS_INC(xs_look_exlist);
        ifp = XFS_IFORK_PTR(ip, fork);
@@ -3736,16 +3738,16 @@ ktrace_t        *xfs_bmap_trace_buf;
 STATIC void
 xfs_bmap_trace_addentry(
        int             opcode,         /* operation */
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        char            *desc,          /* operation description */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    idx,            /* index of entry(ies) */
        xfs_extnum_t    cnt,            /* count of entries, 1 or 2 */
-       xfs_bmbt_rec_t  *r1,            /* first record */
-       xfs_bmbt_rec_t  *r2,            /* second record or null */
+       xfs_bmbt_rec_host_t *r1,        /* first record */
+       xfs_bmbt_rec_host_t *r2,        /* second record or null */
        int             whichfork)      /* data or attr fork */
 {
-       xfs_bmbt_rec_ tr2;
+       xfs_bmbt_rec_host_t tr2;
 
        ASSERT(cnt == 1 || cnt == 2);
        ASSERT(r1 != NULL);
@@ -3795,7 +3797,7 @@ xfs_bmap_trace_addentry(
  */
 STATIC void
 xfs_bmap_trace_delete(
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        char            *desc,          /* operation description */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    idx,            /* index of entry(entries) deleted */
@@ -3817,7 +3819,7 @@ xfs_bmap_trace_delete(
  */
 STATIC void
 xfs_bmap_trace_insert(
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        char            *desc,          /* operation description */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    idx,            /* index of entry(entries) inserted */
@@ -3826,8 +3828,8 @@ xfs_bmap_trace_insert(
        xfs_bmbt_irec_t *r2,            /* inserted record 2 or null */
        int             whichfork)      /* data or attr fork */
 {
-       xfs_bmbt_rec_t  tr1;            /* compressed record 1 */
-       xfs_bmbt_rec_t  tr2;            /* compressed record 2 if needed */
+       xfs_bmbt_rec_host_t tr1;        /* compressed record 1 */
+       xfs_bmbt_rec_host_t tr2;        /* compressed record 2 if needed */
 
        xfs_bmbt_set_all(&tr1, r1);
        if (cnt == 2) {
@@ -3846,7 +3848,7 @@ xfs_bmap_trace_insert(
  */
 STATIC void
 xfs_bmap_trace_post_update(
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        char            *desc,          /* operation description */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    idx,            /* index of entry updated */
@@ -3864,7 +3866,7 @@ xfs_bmap_trace_post_update(
  */
 STATIC void
 xfs_bmap_trace_pre_update(
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        char            *desc,          /* operation description */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    idx,            /* index of entry to be updated */
@@ -3954,7 +3956,6 @@ xfs_bmap_add_attrfork(
        xfs_bmap_free_t         flist;          /* freed extent records */
        xfs_mount_t             *mp;            /* mount structure */
        xfs_trans_t             *tp;            /* transaction pointer */
-       unsigned long           s;              /* spinlock spl value */
        int                     blks;           /* space reservation */
        int                     version = 1;    /* superblock attr version */
        int                     committed;      /* xaction was committed */
@@ -4051,7 +4052,7 @@ xfs_bmap_add_attrfork(
           (!XFS_SB_VERSION_HASATTR2(&mp->m_sb) && version == 2)) {
                __int64_t sbfields = 0;
 
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
                if (!XFS_SB_VERSION_HASATTR(&mp->m_sb)) {
                        XFS_SB_VERSION_ADDATTR(&mp->m_sb);
                        sbfields |= XFS_SB_VERSIONNUM;
@@ -4061,10 +4062,10 @@ xfs_bmap_add_attrfork(
                        sbfields |= (XFS_SB_VERSIONNUM | XFS_SB_FEATURES2);
                }
                if (sbfields) {
-                       XFS_SB_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_sb_lock);
                        xfs_mod_sb(tp, sbfields);
                } else
-                       XFS_SB_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_sb_lock);
        }
        if ((error = xfs_bmap_finish(&tp, &flist, &committed)))
                goto error2;
@@ -4300,7 +4301,6 @@ xfs_bmap_first_unused(
        xfs_fileoff_t   *first_unused,          /* unused block */
        int             whichfork)              /* data or attr fork */
 {
-       xfs_bmbt_rec_t  *ep;                    /* pointer to an extent entry */
        int             error;                  /* error return value */
        int             idx;                    /* extent record index */
        xfs_ifork_t     *ifp;                   /* inode fork pointer */
@@ -4324,7 +4324,7 @@ xfs_bmap_first_unused(
        lowest = *first_unused;
        nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
        for (idx = 0, lastaddr = 0, max = lowest; idx < nextents; idx++) {
-               ep = xfs_iext_get_ext(ifp, idx);
+               xfs_bmbt_rec_host_t *ep = xfs_iext_get_ext(ifp, idx);
                off = xfs_bmbt_get_startoff(ep);
                /*
                 * See if the hole before this extent will work.
@@ -4355,7 +4355,7 @@ xfs_bmap_last_before(
 {
        xfs_fileoff_t   bno;                    /* input file offset */
        int             eof;                    /* hit end of file */
-       xfs_bmbt_rec_t  *ep;                    /* pointer to last extent */
+       xfs_bmbt_rec_host_t *ep;                /* pointer to last extent */
        int             error;                  /* error return value */
        xfs_bmbt_irec_t got;                    /* current extent value */
        xfs_ifork_t     *ifp;                   /* inode fork pointer */
@@ -4401,7 +4401,7 @@ xfs_bmap_last_offset(
        xfs_fileoff_t   *last_block,            /* last block */
        int             whichfork)              /* data or attr fork */
 {
-       xfs_bmbt_rec_t  *ep;                    /* pointer to last extent */
+       xfs_bmbt_rec_host_t *ep;                /* pointer to last extent */
        int             error;                  /* error return value */
        xfs_ifork_t     *ifp;                   /* inode fork pointer */
        xfs_extnum_t    nextents;               /* number of extent entries */
@@ -4438,7 +4438,7 @@ xfs_bmap_one_block(
        xfs_inode_t     *ip,            /* incore inode */
        int             whichfork)      /* data or attr fork */
 {
-       xfs_bmbt_rec_t  *ep;            /* ptr to fork's extent */
+       xfs_bmbt_rec_host_t *ep;        /* ptr to fork's extent */
        xfs_ifork_t     *ifp;           /* inode fork pointer */
        int             rval;           /* return value */
        xfs_bmbt_irec_t s;              /* internal version of extent */
@@ -4481,9 +4481,6 @@ xfs_bmap_read_extents(
        xfs_buf_t               *bp;    /* buffer for "block" */
        int                     error;  /* error return value */
        xfs_exntfmt_t           exntf;  /* XFS_EXTFMT_NOSTATE, if checking */
-#ifdef XFS_BMAP_TRACE
-       static char             fname[] = "xfs_bmap_read_extents";
-#endif
        xfs_extnum_t            i, j;   /* index into the extents list */
        xfs_ifork_t             *ifp;   /* fork structure */
        int                     level;  /* btree level, for checking */
@@ -4536,7 +4533,7 @@ xfs_bmap_read_extents(
         * Loop over all leaf nodes.  Copy information to the extent records.
         */
        for (;;) {
-               xfs_bmbt_rec_t  *frp, *trp;
+               xfs_bmbt_rec_t  *frp;
                xfs_fsblock_t   nextbno;
                xfs_extnum_t    num_recs;
                xfs_extnum_t    start;
@@ -4568,9 +4565,9 @@ xfs_bmap_read_extents(
                frp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, 1);
                start = i;
                for (j = 0; j < num_recs; j++, i++, frp++) {
-                       trp = xfs_iext_get_ext(ifp, i);
-                       trp->l0 = INT_GET(frp->l0, ARCH_CONVERT);
-                       trp->l1 = INT_GET(frp->l1, ARCH_CONVERT);
+                       xfs_bmbt_rec_host_t *trp = xfs_iext_get_ext(ifp, i);
+                       trp->l0 = be64_to_cpu(frp->l0);
+                       trp->l1 = be64_to_cpu(frp->l1);
                }
                if (exntf == XFS_EXTFMT_NOSTATE) {
                        /*
@@ -4600,7 +4597,7 @@ xfs_bmap_read_extents(
        }
        ASSERT(i == (ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t)));
        ASSERT(i == XFS_IFORK_NEXTENTS(ip, whichfork));
-       xfs_bmap_trace_exlist(fname, ip, i, whichfork);
+       XFS_BMAP_TRACE_EXLIST(ip, i, whichfork);
        return 0;
 error0:
        xfs_trans_brelse(tp, bp);
@@ -4613,12 +4610,12 @@ error0:
  */
 void
 xfs_bmap_trace_exlist(
-       char            *fname,         /* function name */
+       const char      *fname,         /* function name */
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_extnum_t    cnt,            /* count of entries in the list */
        int             whichfork)      /* data or attr fork */
 {
-       xfs_bmbt_rec_t  *ep;            /* current extent record */
+       xfs_bmbt_rec_host_t *ep;        /* current extent record */
        xfs_extnum_t    idx;            /* extent record index */
        xfs_ifork_t     *ifp;           /* inode fork pointer */
        xfs_bmbt_irec_t s;              /* file extent record */
@@ -4628,7 +4625,7 @@ xfs_bmap_trace_exlist(
        for (idx = 0; idx < cnt; idx++) {
                ep = xfs_iext_get_ext(ifp, idx);
                xfs_bmbt_get_all(ep, &s);
-               xfs_bmap_trace_insert(fname, "exlist", ip, idx, 1, &s, NULL,
+               XFS_BMAP_TRACE_INSERT("exlist", ip, idx, 1, &s, NULL,
                        whichfork);
        }
 }
@@ -4714,7 +4711,7 @@ xfs_bmapi(
        xfs_btree_cur_t *cur;           /* bmap btree cursor */
        xfs_fileoff_t   end;            /* end of mapped file region */
        int             eof;            /* we've hit the end of extents */
-       xfs_bmbt_rec_t  *ep;            /* extent record pointer */
+       xfs_bmbt_rec_host_t *ep;        /* extent record pointer */
        int             error;          /* error return */
        xfs_bmbt_irec_t got;            /* current file extent record */
        xfs_ifork_t     *ifp;           /* inode fork pointer */
@@ -4868,12 +4865,7 @@ xfs_bmapi(
                                xfs_extlen_t    extsz;
 
                                /* Figure out the extent size, adjust alen */
-                               if (rt) {
-                                       if (!(extsz = ip->i_d.di_extsize))
-                                               extsz = mp->m_sb.sb_rextsize;
-                               } else {
-                                       extsz = ip->i_d.di_extsize;
-                               }
+                               extsz = xfs_get_extsz_hint(ip);
                                if (extsz) {
                                        error = xfs_bmap_extsize_align(mp,
                                                        &got, &prev, extsz,
@@ -5370,7 +5362,7 @@ xfs_bunmapi(
        xfs_btree_cur_t         *cur;           /* bmap btree cursor */
        xfs_bmbt_irec_t         del;            /* extent being deleted */
        int                     eof;            /* is deleting at eof */
-       xfs_bmbt_rec_t          *ep;            /* extent record pointer */
+       xfs_bmbt_rec_host_t     *ep;            /* extent record pointer */
        int                     error;          /* error return value */
        xfs_extnum_t            extno;          /* extent number in list */
        xfs_bmbt_irec_t         got;            /* current extent record */
@@ -5734,12 +5726,45 @@ error0:
        return error;
 }
 
+/*
+ * returns 1 for success, 0 if we failed to map the extent.
+ */
+STATIC int
+xfs_getbmapx_fix_eof_hole(
+       xfs_inode_t             *ip,            /* xfs incore inode pointer */
+       struct getbmap          *out,           /* output structure */
+       int                     prealloced,     /* this is a file with
+                                               * preallocated data space */
+       __int64_t               end,            /* last block requested */
+       xfs_fsblock_t           startblock)
+{
+       __int64_t               fixlen;
+       xfs_mount_t             *mp;            /* file system mount point */
+
+       if (startblock == HOLESTARTBLOCK) {
+               mp = ip->i_mount;
+               out->bmv_block = -1;
+               fixlen = XFS_FSB_TO_BB(mp, XFS_B_TO_FSB(mp, ip->i_size));
+               fixlen -= out->bmv_offset;
+               if (prealloced && out->bmv_offset + out->bmv_length == end) {
+                       /* Came to hole at EOF. Trim it. */
+                       if (fixlen <= 0)
+                               return 0;
+                       out->bmv_length = fixlen;
+               }
+       } else {
+               out->bmv_block = XFS_FSB_TO_DB(ip, startblock);
+       }
+
+       return 1;
+}
+
 /*
  * Fcntl interface to xfs_bmapi.
  */
 int                                            /* error code */
 xfs_getbmap(
-       bhv_desc_t              *bdp,           /* XFS behavior descriptor*/
+       xfs_inode_t             *ip,
        struct getbmap          *bmv,           /* user bmap structure */
        void                    __user *ap,     /* pointer to user's array */
        int                     interface)      /* interface flags */
@@ -5748,7 +5773,6 @@ xfs_getbmap(
        int                     error;          /* return value */
        __int64_t               fixlen;         /* length for -1 case */
        int                     i;              /* extent number */
-       xfs_inode_t             *ip;            /* xfs incore inode pointer */
        bhv_vnode_t             *vp;            /* corresponding vnode */
        int                     lock;           /* lock state */
        xfs_bmbt_irec_t         *map;           /* buffer for user's data */
@@ -5766,8 +5790,7 @@ xfs_getbmap(
        int                     bmapi_flags;    /* flags for xfs_bmapi */
        __int32_t               oflags;         /* getbmapx bmv_oflags field */
 
-       vp = BHV_TO_VNODE(bdp);
-       ip = XFS_BHVTOI(bdp);
+       vp = XFS_ITOV(ip);
        mp = ip->i_mount;
 
        whichfork = interface & BMV_IF_ATTRFORK ? XFS_ATTR_FORK : XFS_DATA_FORK;
@@ -5786,10 +5809,9 @@ xfs_getbmap(
         *      could misinterpret holes in a DMAPI file as true holes,
         *      when in fact they may represent offline user data.
         */
-       if (   (interface & BMV_IF_NO_DMAPI_READ) == 0
-           && DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ)
-           && whichfork == XFS_DATA_FORK) {
-
+       if ((interface & BMV_IF_NO_DMAPI_READ) == 0 &&
+           DM_EVENT_ENABLED(ip, DM_EVENT_READ) &&
+           whichfork == XFS_DATA_FORK) {
                error = XFS_SEND_DATA(mp, DM_EVENT_READ, vp, 0, 0, 0, NULL);
                if (error)
                        return XFS_ERROR(error);
@@ -5813,8 +5835,7 @@ xfs_getbmap(
                   ip->i_d.di_format != XFS_DINODE_FMT_LOCAL)
                return XFS_ERROR(EINVAL);
        if (whichfork == XFS_DATA_FORK) {
-               if ((ip->i_d.di_extsize && (ip->i_d.di_flags &
-                               (XFS_DIFLAG_REALTIME|XFS_DIFLAG_EXTSIZE))) ||
+               if (xfs_get_extsz_hint(ip) ||
                    ip->i_d.di_flags & (XFS_DIFLAG_PREALLOC|XFS_DIFLAG_APPEND)){
                        prealloced = 1;
                        fixlen = XFS_MAXIOFFSET(mp);
@@ -5847,7 +5868,8 @@ xfs_getbmap(
        if (whichfork == XFS_DATA_FORK &&
                (ip->i_delayed_blks || ip->i_size > ip->i_d.di_size)) {
                /* xfs_fsize_t last_byte = xfs_file_last_byte(ip); */
-               error = bhv_vop_flush_pages(vp, (xfs_off_t)0, -1, 0, FI_REMAPF);
+               error = xfs_flush_pages(ip, (xfs_off_t)0,
+                                              -1, 0, FI_REMAPF);
        }
 
        ASSERT(whichfork == XFS_ATTR_FORK || ip->i_delayed_blks == 0);
@@ -5897,18 +5919,15 @@ xfs_getbmap(
                        out.bmv_length = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
                        ASSERT(map[i].br_startblock != DELAYSTARTBLOCK);
                         if (map[i].br_startblock == HOLESTARTBLOCK &&
-                           ((prealloced && out.bmv_offset + out.bmv_length == bmvend) ||
-                             whichfork == XFS_ATTR_FORK )) {
-                                /*
-                                 * came to hole at end of file or the end of
-                                   attribute fork
-                                 */
+                           whichfork == XFS_ATTR_FORK) {
+                               /* came to the end of attribute fork */
                                goto unlock_and_return;
                        } else {
-                               out.bmv_block =
-                                   (map[i].br_startblock == HOLESTARTBLOCK) ?
-                                       -1 :
-                                       XFS_FSB_TO_DB(ip, map[i].br_startblock);
+                               if (!xfs_getbmapx_fix_eof_hole(ip, &out,
+                                                       prealloced, bmvend,
+                                                       map[i].br_startblock)) {
+                                       goto unlock_and_return;
+                               }
 
                                /* return either getbmap/getbmapx structure. */
                                if (interface & BMV_IF_EXTENDED) {
@@ -5967,7 +5986,7 @@ xfs_bmap_isaeof(
 {
        int             error;          /* error return value */
        xfs_ifork_t     *ifp;           /* inode fork pointer */
-       xfs_bmbt_rec_t  *lastrec;       /* extent record pointer */
+       xfs_bmbt_rec_host_t *lastrec;   /* extent record pointer */
        xfs_extnum_t    nextents;       /* number of file extents */
        xfs_bmbt_irec_t s;              /* expanded extent record */
 
@@ -6011,7 +6030,7 @@ xfs_bmap_eof(
        xfs_fsblock_t   blockcount;     /* extent block count */
        int             error;          /* error return value */
        xfs_ifork_t     *ifp;           /* inode fork pointer */
-       xfs_bmbt_rec_t  *lastrec;       /* extent record pointer */
+       xfs_bmbt_rec_host_t *lastrec;   /* extent record pointer */
        xfs_extnum_t    nextents;       /* number of file extents */
        xfs_fileoff_t   startoff;       /* extent starting file offset */
 
@@ -6458,10 +6477,9 @@ xfs_bmap_count_leaves(
        int                     *count)
 {
        int             b;
-       xfs_bmbt_rec_t  *frp;
 
        for (b = 0; b < numrecs; b++) {
-               frp = xfs_iext_get_ext(ifp, idx + b);
+               xfs_bmbt_rec_host_t *frp = xfs_iext_get_ext(ifp, idx + b);
                *count += xfs_bmbt_get_blockcount(frp);
        }
        return 0;