]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/xfs_bmap_btree.c
libxfs: refactor manage_zones()
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_bmap_btree.c
index 89ba30799845723fce9053cb9f9242e734bcb393..24c32a9c0c32d55c8d934e43c906157a6ae568d0 100644 (file)
@@ -1,19 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 #include "libxfs_priv.h"
 #include "xfs_fs.h"
 #include "xfs_cksum.h"
 #include "xfs_rmap.h"
 
-/*
- * Determine the extent state.
- */
-/* ARGSUSED */
-STATIC xfs_exntst_t
-xfs_extent_state(
-       xfs_filblks_t           blks,
-       int                     extent_flag)
-{
-       if (extent_flag) {
-               ASSERT(blks != 0);      /* saved for DMIG */
-               return XFS_EXT_UNWRITTEN;
-       }
-       return XFS_EXT_NORM;
-}
-
 /*
  * Convert on-disk form of btree root to in-memory form.
  */
@@ -68,15 +40,9 @@ xfs_bmdr_to_bmbt(
        xfs_bmbt_key_t          *tkp;
        __be64                  *tpp;
 
-       if (xfs_sb_version_hascrc(&mp->m_sb))
-               xfs_btree_init_block_int(mp, rblock, XFS_BUF_DADDR_NULL,
-                                XFS_BMAP_CRC_MAGIC, 0, 0, ip->i_ino,
-                                XFS_BTREE_LONG_PTRS | XFS_BTREE_CRC_BLOCKS);
-       else
-               xfs_btree_init_block_int(mp, rblock, XFS_BUF_DADDR_NULL,
-                                XFS_BMAP_MAGIC, 0, 0, ip->i_ino,
+       xfs_btree_init_block_int(mp, rblock, XFS_BUF_DADDR_NULL,
+                                XFS_BTNUM_BMAP, 0, 0, ip->i_ino,
                                 XFS_BTREE_LONG_PTRS);
-
        rblock->bb_level = dblock->bb_level;
        ASSERT(be16_to_cpu(rblock->bb_level) > 0);
        rblock->bb_numrecs = dblock->bb_numrecs;
@@ -90,84 +56,21 @@ xfs_bmdr_to_bmbt(
        memcpy(tpp, fpp, sizeof(*fpp) * dmxr);
 }
 
-/*
- * Convert a compressed bmap extent record to an uncompressed form.
- * This code must be in sync with the routines xfs_bmbt_get_startoff,
- * xfs_bmbt_get_startblock, xfs_bmbt_get_blockcount and xfs_bmbt_get_state.
- */
-STATIC void
-__xfs_bmbt_get_all(
-               __uint64_t l0,
-               __uint64_t l1,
-               xfs_bmbt_irec_t *s)
-{
-       int     ext_flag;
-       xfs_exntst_t st;
-
-       ext_flag = (int)(l0 >> (64 - BMBT_EXNTFLAG_BITLEN));
-       s->br_startoff = ((xfs_fileoff_t)l0 &
-                          xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
-       s->br_startblock = (((xfs_fsblock_t)l0 & xfs_mask64lo(9)) << 43) |
-                          (((xfs_fsblock_t)l1) >> 21);
-       s->br_blockcount = (xfs_filblks_t)(l1 & xfs_mask64lo(21));
-       /* This is xfs_extent_state() in-line */
-       if (ext_flag) {
-               ASSERT(s->br_blockcount != 0);  /* saved for DMIG */
-               st = XFS_EXT_UNWRITTEN;
-       } else
-               st = XFS_EXT_NORM;
-       s->br_state = st;
-}
-
 void
-xfs_bmbt_get_all(
-       xfs_bmbt_rec_host_t *r,
-       xfs_bmbt_irec_t *s)
-{
-       __xfs_bmbt_get_all(r->l0, r->l1, s);
-}
-
-/*
- * Extract the blockcount field from an in memory bmap extent record.
- */
-xfs_filblks_t
-xfs_bmbt_get_blockcount(
-       xfs_bmbt_rec_host_t     *r)
-{
-       return (xfs_filblks_t)(r->l1 & xfs_mask64lo(21));
-}
-
-/*
- * Extract the startblock field from an in memory bmap extent record.
- */
-xfs_fsblock_t
-xfs_bmbt_get_startblock(
-       xfs_bmbt_rec_host_t     *r)
-{
-       return (((xfs_fsblock_t)r->l0 & xfs_mask64lo(9)) << 43) |
-              (((xfs_fsblock_t)r->l1) >> 21);
-}
-
-/*
- * Extract the startoff field from an in memory bmap extent record.
- */
-xfs_fileoff_t
-xfs_bmbt_get_startoff(
-       xfs_bmbt_rec_host_t     *r)
-{
-       return ((xfs_fileoff_t)r->l0 &
-                xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
-}
-
-xfs_exntst_t
-xfs_bmbt_get_state(
-       xfs_bmbt_rec_host_t     *r)
-{
-       int     ext_flag;
-
-       ext_flag = (int)((r->l0) >> (64 - BMBT_EXNTFLAG_BITLEN));
-       return xfs_extent_state(xfs_bmbt_get_blockcount(r),
-                               ext_flag);
+xfs_bmbt_disk_get_all(
+       struct xfs_bmbt_rec     *rec,
+       struct xfs_bmbt_irec    *irec)
+{
+       uint64_t                l0 = get_unaligned_be64(&rec->l0);
+       uint64_t                l1 = get_unaligned_be64(&rec->l1);
+
+       irec->br_startoff = (l0 & xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
+       irec->br_startblock = ((l0 & xfs_mask64lo(9)) << 43) | (l1 >> 21);
+       irec->br_blockcount = l1 & xfs_mask64lo(21);
+       if (l0 >> (64 - BMBT_EXNTFLAG_BITLEN))
+               irec->br_state = XFS_EXT_UNWRITTEN;
+       else
+               irec->br_state = XFS_EXT_NORM;
 }
 
 /*
@@ -191,142 +94,29 @@ xfs_bmbt_disk_get_startoff(
                 xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
 }
 
-
-/*
- * Set all the fields in a bmap extent record from the arguments.
- */
-void
-xfs_bmbt_set_allf(
-       xfs_bmbt_rec_host_t     *r,
-       xfs_fileoff_t           startoff,
-       xfs_fsblock_t           startblock,
-       xfs_filblks_t           blockcount,
-       xfs_exntst_t            state)
-{
-       int             extent_flag = (state == XFS_EXT_NORM) ? 0 : 1;
-
-       ASSERT(state == XFS_EXT_NORM || state == XFS_EXT_UNWRITTEN);
-       ASSERT((startoff & xfs_mask64hi(64-BMBT_STARTOFF_BITLEN)) == 0);
-       ASSERT((blockcount & xfs_mask64hi(64-BMBT_BLOCKCOUNT_BITLEN)) == 0);
-
-       ASSERT((startblock & xfs_mask64hi(64-BMBT_STARTBLOCK_BITLEN)) == 0);
-
-       r->l0 = ((xfs_bmbt_rec_base_t)extent_flag << 63) |
-               ((xfs_bmbt_rec_base_t)startoff << 9) |
-               ((xfs_bmbt_rec_base_t)startblock >> 43);
-       r->l1 = ((xfs_bmbt_rec_base_t)startblock << 21) |
-               ((xfs_bmbt_rec_base_t)blockcount &
-               (xfs_bmbt_rec_base_t)xfs_mask64lo(21));
-}
-
 /*
  * Set all the fields in a bmap extent record from the uncompressed form.
  */
 void
-xfs_bmbt_set_all(
-       xfs_bmbt_rec_host_t *r,
-       xfs_bmbt_irec_t *s)
-{
-       xfs_bmbt_set_allf(r, s->br_startoff, s->br_startblock,
-                            s->br_blockcount, s->br_state);
-}
-
-
-/*
- * Set all the fields in a disk format bmap extent record from the arguments.
- */
-void
-xfs_bmbt_disk_set_allf(
-       xfs_bmbt_rec_t          *r,
-       xfs_fileoff_t           startoff,
-       xfs_fsblock_t           startblock,
-       xfs_filblks_t           blockcount,
-       xfs_exntst_t            state)
-{
-       int                     extent_flag = (state == XFS_EXT_NORM) ? 0 : 1;
-
-       ASSERT(state == XFS_EXT_NORM || state == XFS_EXT_UNWRITTEN);
-       ASSERT((startoff & xfs_mask64hi(64-BMBT_STARTOFF_BITLEN)) == 0);
-       ASSERT((blockcount & xfs_mask64hi(64-BMBT_BLOCKCOUNT_BITLEN)) == 0);
-       ASSERT((startblock & xfs_mask64hi(64-BMBT_STARTBLOCK_BITLEN)) == 0);
-
-       r->l0 = cpu_to_be64(
-               ((xfs_bmbt_rec_base_t)extent_flag << 63) |
-                ((xfs_bmbt_rec_base_t)startoff << 9) |
-                ((xfs_bmbt_rec_base_t)startblock >> 43));
-       r->l1 = cpu_to_be64(
-               ((xfs_bmbt_rec_base_t)startblock << 21) |
-                ((xfs_bmbt_rec_base_t)blockcount &
-                 (xfs_bmbt_rec_base_t)xfs_mask64lo(21)));
-}
-
-/*
- * Set all the fields in a bmap extent record from the uncompressed form.
- */
-STATIC void
 xfs_bmbt_disk_set_all(
-       xfs_bmbt_rec_t  *r,
-       xfs_bmbt_irec_t *s)
+       struct xfs_bmbt_rec     *r,
+       struct xfs_bmbt_irec    *s)
 {
-       xfs_bmbt_disk_set_allf(r, s->br_startoff, s->br_startblock,
-                                 s->br_blockcount, s->br_state);
-}
+       int                     extent_flag = (s->br_state != XFS_EXT_NORM);
 
-/*
- * Set the blockcount field in a bmap extent record.
- */
-void
-xfs_bmbt_set_blockcount(
-       xfs_bmbt_rec_host_t *r,
-       xfs_filblks_t   v)
-{
-       ASSERT((v & xfs_mask64hi(43)) == 0);
-       r->l1 = (r->l1 & (xfs_bmbt_rec_base_t)xfs_mask64hi(43)) |
-                 (xfs_bmbt_rec_base_t)(v & xfs_mask64lo(21));
-}
-
-/*
- * Set the startblock field in a bmap extent record.
- */
-void
-xfs_bmbt_set_startblock(
-       xfs_bmbt_rec_host_t *r,
-       xfs_fsblock_t   v)
-{
-       ASSERT((v & xfs_mask64hi(12)) == 0);
-       r->l0 = (r->l0 & (xfs_bmbt_rec_base_t)xfs_mask64hi(55)) |
-                 (xfs_bmbt_rec_base_t)(v >> 43);
-       r->l1 = (r->l1 & (xfs_bmbt_rec_base_t)xfs_mask64lo(21)) |
-                 (xfs_bmbt_rec_base_t)(v << 21);
-}
+       ASSERT(s->br_state == XFS_EXT_NORM || s->br_state == XFS_EXT_UNWRITTEN);
+       ASSERT(!(s->br_startoff & xfs_mask64hi(64-BMBT_STARTOFF_BITLEN)));
+       ASSERT(!(s->br_blockcount & xfs_mask64hi(64-BMBT_BLOCKCOUNT_BITLEN)));
+       ASSERT(!(s->br_startblock & xfs_mask64hi(64-BMBT_STARTBLOCK_BITLEN)));
 
-/*
- * Set the startoff field in a bmap extent record.
- */
-void
-xfs_bmbt_set_startoff(
-       xfs_bmbt_rec_host_t *r,
-       xfs_fileoff_t   v)
-{
-       ASSERT((v & xfs_mask64hi(9)) == 0);
-       r->l0 = (r->l0 & (xfs_bmbt_rec_base_t) xfs_mask64hi(1)) |
-               ((xfs_bmbt_rec_base_t)v << 9) |
-                 (r->l0 & (xfs_bmbt_rec_base_t)xfs_mask64lo(9));
-}
-
-/*
- * Set the extent state field in a bmap extent record.
- */
-void
-xfs_bmbt_set_state(
-       xfs_bmbt_rec_host_t *r,
-       xfs_exntst_t    v)
-{
-       ASSERT(v == XFS_EXT_NORM || v == XFS_EXT_UNWRITTEN);
-       if (v == XFS_EXT_NORM)
-               r->l0 &= xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN);
-       else
-               r->l0 |= xfs_mask64hi(BMBT_EXNTFLAG_BITLEN);
+       put_unaligned_be64(
+               ((xfs_bmbt_rec_base_t)extent_flag << 63) |
+                ((xfs_bmbt_rec_base_t)s->br_startoff << 9) |
+                ((xfs_bmbt_rec_base_t)s->br_startblock >> 43), &r->l0);
+       put_unaligned_be64(
+               ((xfs_bmbt_rec_base_t)s->br_startblock << 21) |
+                ((xfs_bmbt_rec_base_t)s->br_blockcount &
+                 (xfs_bmbt_rec_base_t)xfs_mask64lo(21)), &r->l1);
 }
 
 /*
@@ -369,32 +159,6 @@ xfs_bmbt_to_bmdr(
        memcpy(tpp, fpp, sizeof(*fpp) * dmxr);
 }
 
-/*
- * Check extent records, which have just been read, for
- * any bit in the extent flag field. ASSERT on debug
- * kernels, as this condition should not occur.
- * Return an error condition (1) if any flags found,
- * otherwise return 0.
- */
-
-int
-xfs_check_nostate_extents(
-       xfs_ifork_t             *ifp,
-       xfs_extnum_t            idx,
-       xfs_extnum_t            num)
-{
-       for (; num > 0; num--, idx++) {
-               xfs_bmbt_rec_host_t *ep = xfs_iext_get_ext(ifp, idx);
-               if ((ep->l0 >>
-                    (64 - BMBT_EXNTFLAG_BITLEN)) != 0) {
-                       ASSERT(0);
-                       return 1;
-               }
-       }
-       return 0;
-}
-
-
 STATIC struct xfs_btree_cur *
 xfs_bmbt_dup_cursor(
        struct xfs_btree_cur    *cur)
@@ -408,8 +172,6 @@ xfs_bmbt_dup_cursor(
         * Copy the firstblock, dfops, and flags values,
         * since init cursor doesn't get them.
         */
-       new->bc_private.b.firstblock = cur->bc_private.b.firstblock;
-       new->bc_private.b.dfops = cur->bc_private.b.dfops;
        new->bc_private.b.flags = cur->bc_private.b.flags;
 
        return new;
@@ -420,12 +182,11 @@ xfs_bmbt_update_cursor(
        struct xfs_btree_cur    *src,
        struct xfs_btree_cur    *dst)
 {
-       ASSERT((dst->bc_private.b.firstblock != NULLFSBLOCK) ||
+       ASSERT((dst->bc_tp->t_firstblock != NULLFSBLOCK) ||
               (dst->bc_private.b.ip->i_d.di_flags & XFS_DIFLAG_REALTIME));
-       ASSERT(dst->bc_private.b.dfops == src->bc_private.b.dfops);
 
        dst->bc_private.b.allocated += src->bc_private.b.allocated;
-       dst->bc_private.b.firstblock = src->bc_private.b.firstblock;
+       dst->bc_tp->t_firstblock = src->bc_tp->t_firstblock;
 
        src->bc_private.b.allocated = 0;
 }
@@ -443,14 +204,12 @@ xfs_bmbt_alloc_block(
        memset(&args, 0, sizeof(args));
        args.tp = cur->bc_tp;
        args.mp = cur->bc_mp;
-       args.fsbno = cur->bc_private.b.firstblock;
-       args.firstblock = args.fsbno;
+       args.fsbno = cur->bc_tp->t_firstblock;
        xfs_rmap_ino_bmbt_owner(&args.oinfo, cur->bc_private.b.ip->i_ino,
                        cur->bc_private.b.whichfork);
 
        if (args.fsbno == NULLFSBLOCK) {
                args.fsbno = be64_to_cpu(start->l);
-try_another_ag:
                args.type = XFS_ALLOCTYPE_START_BNO;
                /*
                 * Make sure there is sufficient room left in the AG to
@@ -464,7 +223,7 @@ try_another_ag:
                 * block allocation here and corrupt the filesystem.
                 */
                args.minleft = args.tp->t_blk_res;
-       } else if (cur->bc_private.b.dfops->dop_low) {
+       } else if (cur->bc_tp->t_flags & XFS_TRANS_LOWMODE) {
                args.type = XFS_ALLOCTYPE_START_BNO;
        } else {
                args.type = XFS_ALLOCTYPE_NEAR_BNO;
@@ -480,43 +239,26 @@ try_another_ag:
        if (error)
                goto error0;
 
-       /*
-        * During a CoW operation, the allocation and bmbt updates occur in
-        * different transactions.  The mapping code tries to put new bmbt
-        * blocks near extents being mapped, but the only way to guarantee this
-        * is if the alloc and the mapping happen in a single transaction that
-        * has a block reservation.  That isn't the case here, so if we run out
-        * of space we'll try again with another AG.
-        */
-       if (xfs_sb_version_hasreflink(&cur->bc_mp->m_sb) &&
-           args.fsbno == NULLFSBLOCK &&
-           args.type == XFS_ALLOCTYPE_NEAR_BNO) {
-               cur->bc_private.b.dfops->dop_low = true;
-               args.fsbno = cur->bc_private.b.firstblock;
-               goto try_another_ag;
-       }
-
        if (args.fsbno == NULLFSBLOCK && args.minleft) {
                /*
                 * Could not find an AG with enough free space to satisfy
-                * a full btree split.  Try again without minleft and if
+                * a full btree split.  Try again and if
                 * successful activate the lowspace algorithm.
                 */
                args.fsbno = 0;
                args.type = XFS_ALLOCTYPE_FIRST_AG;
-               args.minleft = 0;
                error = xfs_alloc_vextent(&args);
                if (error)
                        goto error0;
-               cur->bc_private.b.dfops->dop_low = true;
+               cur->bc_tp->t_flags |= XFS_TRANS_LOWMODE;
        }
-       if (args.fsbno == NULLFSBLOCK) {
-               XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
+       if (WARN_ON_ONCE(args.fsbno == NULLFSBLOCK)) {
                *stat = 0;
                return 0;
        }
+
        ASSERT(args.len == 1);
-       cur->bc_private.b.firstblock = args.fsbno;
+       cur->bc_tp->t_firstblock = args.fsbno;
        cur->bc_private.b.allocated++;
        cur->bc_private.b.ip->i_d.di_nblocks++;
        xfs_trans_log_inode(args.tp, cur->bc_private.b.ip, XFS_ILOG_CORE);
@@ -525,12 +267,10 @@ try_another_ag:
 
        new->l = cpu_to_be64(args.fsbno);
 
-       XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
        *stat = 1;
        return 0;
 
  error0:
-       XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
        return error;
 }
 
@@ -546,7 +286,7 @@ xfs_bmbt_free_block(
        struct xfs_owner_info   oinfo;
 
        xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, cur->bc_private.b.whichfork);
-       xfs_bmap_add_free(mp, cur->bc_private.b.dfops, fsbno, 1, &oinfo);
+       xfs_bmap_add_free(cur->bc_tp, fsbno, 1, &oinfo);
        ip->i_d.di_nblocks--;
 
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
@@ -619,6 +359,16 @@ xfs_bmbt_init_key_from_rec(
                cpu_to_be64(xfs_bmbt_disk_get_startoff(&rec->bmbt));
 }
 
+STATIC void
+xfs_bmbt_init_high_key_from_rec(
+       union xfs_btree_key     *key,
+       union xfs_btree_rec     *rec)
+{
+       key->bmbt.br_startoff = cpu_to_be64(
+                       xfs_bmbt_disk_get_startoff(&rec->bmbt) +
+                       xfs_bmbt_disk_get_blockcount(&rec->bmbt) - 1);
+}
+
 STATIC void
 xfs_bmbt_init_rec_from_cur(
        struct xfs_btree_cur    *cur,
@@ -635,42 +385,48 @@ xfs_bmbt_init_ptr_from_cur(
        ptr->l = 0;
 }
 
-STATIC __int64_t
+STATIC int64_t
 xfs_bmbt_key_diff(
        struct xfs_btree_cur    *cur,
        union xfs_btree_key     *key)
 {
-       return (__int64_t)be64_to_cpu(key->bmbt.br_startoff) -
+       return (int64_t)be64_to_cpu(key->bmbt.br_startoff) -
                                      cur->bc_rec.b.br_startoff;
 }
 
-static bool
+STATIC int64_t
+xfs_bmbt_diff_two_keys(
+       struct xfs_btree_cur    *cur,
+       union xfs_btree_key     *k1,
+       union xfs_btree_key     *k2)
+{
+       return (int64_t)be64_to_cpu(k1->bmbt.br_startoff) -
+                         be64_to_cpu(k2->bmbt.br_startoff);
+}
+
+static xfs_failaddr_t
 xfs_bmbt_verify(
        struct xfs_buf          *bp)
 {
        struct xfs_mount        *mp = bp->b_target->bt_mount;
        struct xfs_btree_block  *block = XFS_BUF_TO_BLOCK(bp);
+       xfs_failaddr_t          fa;
        unsigned int            level;
 
        switch (block->bb_magic) {
        case cpu_to_be32(XFS_BMAP_CRC_MAGIC):
-               if (!xfs_sb_version_hascrc(&mp->m_sb))
-                       return false;
-               if (!uuid_equal(&block->bb_u.l.bb_uuid, &mp->m_sb.sb_meta_uuid))
-                       return false;
-               if (be64_to_cpu(block->bb_u.l.bb_blkno) != bp->b_bn)
-                       return false;
                /*
                 * XXX: need a better way of verifying the owner here. Right now
                 * just make sure there has been one set.
                 */
-               if (be64_to_cpu(block->bb_u.l.bb_owner) == 0)
-                       return false;
+               fa = xfs_btree_lblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN);
+               if (fa)
+                       return fa;
                /* fall through */
        case cpu_to_be32(XFS_BMAP_MAGIC):
                break;
        default:
-               return false;
+               return __this_address;
        }
 
        /*
@@ -682,46 +438,39 @@ xfs_bmbt_verify(
         */
        level = be16_to_cpu(block->bb_level);
        if (level > max(mp->m_bm_maxlevels[0], mp->m_bm_maxlevels[1]))
-               return false;
-       if (be16_to_cpu(block->bb_numrecs) > mp->m_bmap_dmxr[level != 0])
-               return false;
-
-       /* sibling pointer verification */
-       if (!block->bb_u.l.bb_leftsib ||
-           (block->bb_u.l.bb_leftsib != cpu_to_be64(NULLFSBLOCK) &&
-            !XFS_FSB_SANITY_CHECK(mp, be64_to_cpu(block->bb_u.l.bb_leftsib))))
-               return false;
-       if (!block->bb_u.l.bb_rightsib ||
-           (block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK) &&
-            !XFS_FSB_SANITY_CHECK(mp, be64_to_cpu(block->bb_u.l.bb_rightsib))))
-               return false;
-
-       return true;
+               return __this_address;
+
+       return xfs_btree_lblock_verify(bp, mp->m_bmap_dmxr[level != 0]);
 }
 
 static void
 xfs_bmbt_read_verify(
        struct xfs_buf  *bp)
 {
+       xfs_failaddr_t  fa;
+
        if (!xfs_btree_lblock_verify_crc(bp))
-               xfs_buf_ioerror(bp, -EFSBADCRC);
-       else if (!xfs_bmbt_verify(bp))
-               xfs_buf_ioerror(bp, -EFSCORRUPTED);
+               xfs_verifier_error(bp, -EFSBADCRC, __this_address);
+       else {
+               fa = xfs_bmbt_verify(bp);
+               if (fa)
+                       xfs_verifier_error(bp, -EFSCORRUPTED, fa);
+       }
 
-       if (bp->b_error) {
+       if (bp->b_error)
                trace_xfs_btree_corrupt(bp, _RET_IP_);
-               xfs_verifier_error(bp);
-       }
 }
 
 static void
 xfs_bmbt_write_verify(
        struct xfs_buf  *bp)
 {
-       if (!xfs_bmbt_verify(bp)) {
+       xfs_failaddr_t  fa;
+
+       fa = xfs_bmbt_verify(bp);
+       if (fa) {
                trace_xfs_btree_corrupt(bp, _RET_IP_);
-               xfs_buf_ioerror(bp, -EFSCORRUPTED);
-               xfs_verifier_error(bp);
+               xfs_verifier_error(bp, -EFSCORRUPTED, fa);
                return;
        }
        xfs_btree_lblock_calc_crc(bp);
@@ -731,10 +480,10 @@ const struct xfs_buf_ops xfs_bmbt_buf_ops = {
        .name = "xfs_bmbt",
        .verify_read = xfs_bmbt_read_verify,
        .verify_write = xfs_bmbt_write_verify,
+       .verify_struct = xfs_bmbt_verify,
 };
 
 
-#if defined(DEBUG) || defined(XFS_WARN)
 STATIC int
 xfs_bmbt_keys_inorder(
        struct xfs_btree_cur    *cur,
@@ -755,7 +504,6 @@ xfs_bmbt_recs_inorder(
                xfs_bmbt_disk_get_blockcount(&r1->bmbt) <=
                xfs_bmbt_disk_get_startoff(&r2->bmbt);
 }
-#endif /* DEBUG */
 
 static const struct xfs_btree_ops xfs_bmbt_ops = {
        .rec_len                = sizeof(xfs_bmbt_rec_t),
@@ -769,14 +517,14 @@ static const struct xfs_btree_ops xfs_bmbt_ops = {
        .get_minrecs            = xfs_bmbt_get_minrecs,
        .get_dmaxrecs           = xfs_bmbt_get_dmaxrecs,
        .init_key_from_rec      = xfs_bmbt_init_key_from_rec,
+       .init_high_key_from_rec = xfs_bmbt_init_high_key_from_rec,
        .init_rec_from_cur      = xfs_bmbt_init_rec_from_cur,
        .init_ptr_from_cur      = xfs_bmbt_init_ptr_from_cur,
        .key_diff               = xfs_bmbt_key_diff,
+       .diff_two_keys          = xfs_bmbt_diff_two_keys,
        .buf_ops                = &xfs_bmbt_buf_ops,
-#if defined(DEBUG) || defined(XFS_WARN)
        .keys_inorder           = xfs_bmbt_keys_inorder,
        .recs_inorder           = xfs_bmbt_recs_inorder,
-#endif
 };
 
 /*
@@ -793,7 +541,7 @@ xfs_bmbt_init_cursor(
        struct xfs_btree_cur    *cur;
        ASSERT(whichfork != XFS_COW_FORK);
 
-       cur = kmem_zone_zalloc(xfs_btree_cur_zone, KM_SLEEP);
+       cur = kmem_zone_zalloc(xfs_btree_cur_zone, KM_NOFS);
 
        cur->bc_tp = tp;
        cur->bc_mp = mp;
@@ -809,8 +557,6 @@ xfs_bmbt_init_cursor(
 
        cur->bc_private.b.forksize = XFS_IFORK_SIZE(ip, whichfork);
        cur->bc_private.b.ip = ip;
-       cur->bc_private.b.firstblock = NULLFSBLOCK;
-       cur->bc_private.b.dfops = NULL;
        cur->bc_private.b.allocated = 0;
        cur->bc_private.b.flags = 0;
        cur->bc_private.b.whichfork = whichfork;
@@ -887,8 +633,18 @@ xfs_bmbt_change_owner(
        cur = xfs_bmbt_init_cursor(ip->i_mount, tp, ip, whichfork);
        if (!cur)
                return -ENOMEM;
+       cur->bc_private.b.flags |= XFS_BTCUR_BPRV_INVALID_OWNER;
 
        error = xfs_btree_change_owner(cur, new_owner, buffer_list);
-       xfs_btree_del_cursor(cur, error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
+       xfs_btree_del_cursor(cur, error);
        return error;
 }
+
+/* Calculate the bmap btree size for some records. */
+unsigned long long
+xfs_bmbt_calc_size(
+       struct xfs_mount        *mp,
+       unsigned long long      len)
+{
+       return xfs_btree_calc_size(mp->m_bmap_dmnr, len);
+}