libxfs: refactor short btree block verification
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 4 Jan 2016 05:13:21 +0000 (16:13 +1100)
committerDave Chinner <david@fromorbit.com>
Mon, 4 Jan 2016 05:13:21 +0000 (16:13 +1100)
Create xfs_btree_sblock_verify() to verify short-format btree blocks
(i.e. the per-AG btrees with 32-bit block pointers) instead of
open-coding them.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/libxfs/xfs_alloc_btree.c
fs/xfs/libxfs/xfs_btree.c
fs/xfs/libxfs/xfs_btree.h
fs/xfs/libxfs/xfs_ialloc_btree.c

index eb8bbfe85484e33554fe6b3e48e1d7b5c252fac6..444626ddbd1b9ba2baca676b48a62d90299d515e 100644 (file)
@@ -293,14 +293,7 @@ xfs_allocbt_verify(
        level = be16_to_cpu(block->bb_level);
        switch (block->bb_magic) {
        case cpu_to_be32(XFS_ABTB_CRC_MAGIC):
-               if (!xfs_sb_version_hascrc(&mp->m_sb))
-                       return false;
-               if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))
-                       return false;
-               if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn))
-                       return false;
-               if (pag &&
-                   be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno)
+               if (!xfs_btree_sblock_v5hdr_verify(bp))
                        return false;
                /* fall through */
        case cpu_to_be32(XFS_ABTB_MAGIC):
@@ -311,14 +304,7 @@ xfs_allocbt_verify(
                        return false;
                break;
        case cpu_to_be32(XFS_ABTC_CRC_MAGIC):
-               if (!xfs_sb_version_hascrc(&mp->m_sb))
-                       return false;
-               if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))
-                       return false;
-               if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn))
-                       return false;
-               if (pag &&
-                   be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno)
+               if (!xfs_btree_sblock_v5hdr_verify(bp))
                        return false;
                /* fall through */
        case cpu_to_be32(XFS_ABTC_MAGIC):
@@ -332,21 +318,7 @@ xfs_allocbt_verify(
                return false;
        }
 
-       /* numrecs verification */
-       if (be16_to_cpu(block->bb_numrecs) > mp->m_alloc_mxr[level != 0])
-               return false;
-
-       /* sibling pointer verification */
-       if (!block->bb_u.s.bb_leftsib ||
-           (be32_to_cpu(block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks &&
-            block->bb_u.s.bb_leftsib != cpu_to_be32(NULLAGBLOCK)))
-               return false;
-       if (!block->bb_u.s.bb_rightsib ||
-           (be32_to_cpu(block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks &&
-            block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK)))
-               return false;
-
-       return true;
+       return xfs_btree_sblock_verify(bp, mp->m_alloc_mxr[level != 0]);
 }
 
 static void
index af1bbee5586e4fef04ee03b6b826f89a56566f39..a0eb18ce3ad38f205f5f3487ea4684937b7b287c 100644 (file)
@@ -4080,3 +4080,61 @@ xfs_btree_change_owner(
 
        return 0;
 }
+
+/**
+ * xfs_btree_sblock_v5hdr_verify() -- verify the v5 fields of a short-format
+ *                                   btree block
+ *
+ * @bp: buffer containing the btree block
+ * @max_recs: pointer to the m_*_mxr max records field in the xfs mount
+ * @pag_max_level: pointer to the per-ag max level field
+ */
+bool
+xfs_btree_sblock_v5hdr_verify(
+       struct xfs_buf          *bp)
+{
+       struct xfs_mount        *mp = bp->b_target->bt_mount;
+       struct xfs_btree_block  *block = XFS_BUF_TO_BLOCK(bp);
+       struct xfs_perag        *pag = bp->b_pag;
+
+       if (!xfs_sb_version_hascrc(&mp->m_sb))
+               return false;
+       if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))
+               return false;
+       if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn))
+               return false;
+       if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno)
+               return false;
+       return true;
+}
+
+/**
+ * xfs_btree_sblock_verify() -- verify a short-format btree block
+ *
+ * @bp: buffer containing the btree block
+ * @max_recs: maximum records allowed in this btree node
+ */
+bool
+xfs_btree_sblock_verify(
+       struct xfs_buf          *bp,
+       unsigned int            max_recs)
+{
+       struct xfs_mount        *mp = bp->b_target->bt_mount;
+       struct xfs_btree_block  *block = XFS_BUF_TO_BLOCK(bp);
+
+       /* numrecs verification */
+       if (be16_to_cpu(block->bb_numrecs) > max_recs)
+               return false;
+
+       /* sibling pointer verification */
+       if (!block->bb_u.s.bb_leftsib ||
+           (be32_to_cpu(block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks &&
+            block->bb_u.s.bb_leftsib != cpu_to_be32(NULLAGBLOCK)))
+               return false;
+       if (!block->bb_u.s.bb_rightsib ||
+           (be32_to_cpu(block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks &&
+            block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK)))
+               return false;
+
+       return true;
+}
index 992dec0638f331095bffb51d910eb63b5ac67ac9..2e874be702093f1409fb7428efc5a1bdbc0e3bcd 100644 (file)
@@ -472,4 +472,7 @@ static inline int xfs_btree_get_level(struct xfs_btree_block *block)
 #define XFS_BTREE_TRACE_ARGR(c, r)
 #define        XFS_BTREE_TRACE_CURSOR(c, t)
 
+bool xfs_btree_sblock_v5hdr_verify(struct xfs_buf *bp);
+bool xfs_btree_sblock_verify(struct xfs_buf *bp, unsigned int max_recs);
+
 #endif /* __XFS_BTREE_H__ */
index 6dd44f9ea7270fecf48ab9edfca83f183075bb3e..c679f3c05b63cb535de34e7de5543a75ac57faac 100644 (file)
@@ -221,7 +221,6 @@ xfs_inobt_verify(
 {
        struct xfs_mount        *mp = bp->b_target->bt_mount;
        struct xfs_btree_block  *block = XFS_BUF_TO_BLOCK(bp);
-       struct xfs_perag        *pag = bp->b_pag;
        unsigned int            level;
 
        /*
@@ -237,14 +236,7 @@ xfs_inobt_verify(
        switch (block->bb_magic) {
        case cpu_to_be32(XFS_IBT_CRC_MAGIC):
        case cpu_to_be32(XFS_FIBT_CRC_MAGIC):
-               if (!xfs_sb_version_hascrc(&mp->m_sb))
-                       return false;
-               if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))
-                       return false;
-               if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn))
-                       return false;
-               if (pag &&
-                   be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno)
+               if (!xfs_btree_sblock_v5hdr_verify(bp))
                        return false;
                /* fall through */
        case cpu_to_be32(XFS_IBT_MAGIC):
@@ -254,24 +246,12 @@ xfs_inobt_verify(
                return 0;
        }
 
-       /* numrecs and level verification */
+       /* level verification */
        level = be16_to_cpu(block->bb_level);
        if (level >= mp->m_in_maxlevels)
                return false;
-       if (be16_to_cpu(block->bb_numrecs) > mp->m_inobt_mxr[level != 0])
-               return false;
-
-       /* sibling pointer verification */
-       if (!block->bb_u.s.bb_leftsib ||
-           (be32_to_cpu(block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks &&
-            block->bb_u.s.bb_leftsib != cpu_to_be32(NULLAGBLOCK)))
-               return false;
-       if (!block->bb_u.s.bb_rightsib ||
-           (be32_to_cpu(block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks &&
-            block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK)))
-               return false;
 
-       return true;
+       return xfs_btree_sblock_verify(bp, mp->m_inobt_mxr[level != 0]);
 }
 
 static void