xfs: factor xfs_da3_blkinfo verification into common helper
authorBrian Foster <bfoster@redhat.com>
Thu, 7 Feb 2019 18:45:48 +0000 (10:45 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Tue, 12 Feb 2019 00:07:01 +0000 (16:07 -0800)
With the verifier magic value helper in place, we've left a bit more
duplicate code across the verifiers that involve struct
xfs_da3_blkinfo. This includes the da node, xattr leaf and dir leaf
verifiers, all of which perform similar checks for v4 and v5
filesystems.

Create a common helper to verify an xfs_da3_blkinfo structure,
taking care to only access v5 fields where appropriate, and refactor
the aforementioned verifiers to use the helper. No functional
changes.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/xfs/libxfs/xfs_attr_leaf.c
fs/xfs/libxfs/xfs_da_btree.c
fs/xfs/libxfs/xfs_da_format.h
fs/xfs/libxfs/xfs_dir2_leaf.c

index f164f296f1b8606034616a870f987233d80b1423..0c92987f57fcc3d2923980c02b27aa502a6031fd 100644 (file)
@@ -245,22 +245,14 @@ xfs_attr3_leaf_verify(
        struct xfs_attr_leaf_entry      *entries;
        uint32_t                        end;    /* must be 32bit - see below */
        int                             i;
+       xfs_failaddr_t                  fa;
 
        xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf);
 
-       if (!xfs_verify_magic(bp, leaf->hdr.info.magic))
-               return __this_address;
-
-       if (xfs_sb_version_hascrc(&mp->m_sb)) {
-               struct xfs_da3_node_hdr *hdr3 = bp->b_addr;
+       fa = xfs_da3_blkinfo_verify(bp, bp->b_addr);
+       if (fa)
+               return fa;
 
-               if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid))
-                       return __this_address;
-               if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn)
-                       return __this_address;
-               if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn)))
-                       return __this_address;
-       }
        /*
         * In recovery there is a transient state where count == 0 is valid
         * because we may have transitioned an empty shortform attr to a leaf
index e02d2f407e12cf799de1d75110a41b2ebf5005da..eb2cee428f26ef0fde35d393202ce5fb3596c615 100644 (file)
@@ -116,6 +116,34 @@ xfs_da_state_free(xfs_da_state_t *state)
        kmem_zone_free(xfs_da_state_zone, state);
 }
 
+/*
+ * Verify an xfs_da3_blkinfo structure. Note that the da3 fields are only
+ * accessible on v5 filesystems. This header format is common across da node,
+ * attr leaf and dir leaf blocks.
+ */
+xfs_failaddr_t
+xfs_da3_blkinfo_verify(
+       struct xfs_buf          *bp,
+       struct xfs_da3_blkinfo  *hdr3)
+{
+       struct xfs_mount        *mp = bp->b_target->bt_mount;
+       struct xfs_da_blkinfo   *hdr = &hdr3->hdr;
+
+       if (!xfs_verify_magic(bp, hdr->magic))
+               return __this_address;
+
+       if (xfs_sb_version_hascrc(&mp->m_sb)) {
+               if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid))
+                       return __this_address;
+               if (be64_to_cpu(hdr3->blkno) != bp->b_bn)
+                       return __this_address;
+               if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn)))
+                       return __this_address;
+       }
+
+       return 0;
+}
+
 static xfs_failaddr_t
 xfs_da3_node_verify(
        struct xfs_buf          *bp)
@@ -124,24 +152,16 @@ xfs_da3_node_verify(
        struct xfs_da_intnode   *hdr = bp->b_addr;
        struct xfs_da3_icnode_hdr ichdr;
        const struct xfs_dir_ops *ops;
+       xfs_failaddr_t          fa;
 
        ops = xfs_dir_get_ops(mp, NULL);
 
        ops->node_hdr_from_disk(&ichdr, hdr);
 
-       if (!xfs_verify_magic(bp, hdr->hdr.info.magic))
-               return __this_address;
+       fa = xfs_da3_blkinfo_verify(bp, bp->b_addr);
+       if (fa)
+               return fa;
 
-       if (xfs_sb_version_hascrc(&mp->m_sb)) {
-               struct xfs_da3_node_hdr *hdr3 = bp->b_addr;
-
-               if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid))
-                       return __this_address;
-               if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn)
-                       return __this_address;
-               if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn)))
-                       return __this_address;
-       }
        if (ichdr.level == 0)
                return __this_address;
        if (ichdr.level > XFS_DA_NODE_MAXDEPTH)
index 5d5bf3bffc783a1f3711cdf9edca5c2e4ccc2e4b..ae654e06b2fb693627311c8e59235d1f04e79773 100644 (file)
@@ -869,4 +869,7 @@ static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp)
        return 1 << (sbp->sb_blocklog + sbp->sb_dirblklog);
 }
 
+xfs_failaddr_t xfs_da3_blkinfo_verify(struct xfs_buf *bp,
+                                     struct xfs_da3_blkinfo *hdr3);
+
 #endif /* __XFS_DA_FORMAT_H__ */
index dee0fd333d9ddd5e9de5142b38c86a5ca32a3211..094028b7b1625fe4d605021de08d40c4f3ebd414 100644 (file)
@@ -146,20 +146,11 @@ xfs_dir3_leaf_verify(
 {
        struct xfs_mount        *mp = bp->b_target->bt_mount;
        struct xfs_dir2_leaf    *leaf = bp->b_addr;
+       xfs_failaddr_t          fa;
 
-       if (!xfs_verify_magic(bp, leaf->hdr.info.magic))
-               return __this_address;
-
-       if (xfs_sb_version_hascrc(&mp->m_sb)) {
-               struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr;
-
-               if (!uuid_equal(&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid))
-                       return __this_address;
-               if (be64_to_cpu(leaf3->info.blkno) != bp->b_bn)
-                       return __this_address;
-               if (!xfs_log_check_lsn(mp, be64_to_cpu(leaf3->info.lsn)))
-                       return __this_address;
-       }
+       fa = xfs_da3_blkinfo_verify(bp, bp->b_addr);
+       if (fa)
+               return fa;
 
        return xfs_dir3_leaf_check_int(mp, NULL, NULL, leaf);
 }