xfs: always check magic values in on-disk byte order
authorBrian Foster <bfoster@redhat.com>
Thu, 7 Feb 2019 18:45:45 +0000 (10:45 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Tue, 12 Feb 2019 00:07:01 +0000 (16:07 -0800)
Most verifiers that check on-disk magic values convert the CPU
endian magic value constant to disk endian to facilitate compile
time optimization of the byte swap and reduce the need for runtime
byte swaps in buffer verifiers. Several buffer verifiers do not
follow this pattern. Update those verifiers for consistency.

Also fix up a random typo in the inode readahead verifier name.

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_alloc.c
fs/xfs/libxfs/xfs_attr_leaf.c
fs/xfs/libxfs/xfs_da_btree.c
fs/xfs/libxfs/xfs_inode_buf.c
fs/xfs/libxfs/xfs_sb.c

index b715668886a4824adf8a1c4527236469afed89fe..48aab07e71388087ffd5d26d06edf7cf6d2c6370 100644 (file)
@@ -570,7 +570,7 @@ xfs_agfl_verify(
 
        if (!uuid_equal(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid))
                return __this_address;
-       if (be32_to_cpu(agfl->agfl_magicnum) != XFS_AGFL_MAGIC)
+       if (agfl->agfl_magicnum != cpu_to_be32(XFS_AGFL_MAGIC))
                return __this_address;
        /*
         * during growfs operations, the perag is not fully initialised,
index 2652d00842d6ba8c6479f816765c87dfc622d1cb..e60eba7f129c28347294530340fe3902d6a1c870 100644 (file)
@@ -251,7 +251,7 @@ xfs_attr3_leaf_verify(
        if (xfs_sb_version_hascrc(&mp->m_sb)) {
                struct xfs_da3_node_hdr *hdr3 = bp->b_addr;
 
-               if (ichdr.magic != XFS_ATTR3_LEAF_MAGIC)
+               if (hdr3->info.hdr.magic != cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
                        return __this_address;
 
                if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid))
@@ -261,7 +261,7 @@ xfs_attr3_leaf_verify(
                if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn)))
                        return __this_address;
        } else {
-               if (ichdr.magic != XFS_ATTR_LEAF_MAGIC)
+               if (leaf->hdr.info.magic != cpu_to_be16(XFS_ATTR_LEAF_MAGIC))
                        return __this_address;
        }
        /*
index 376bee94b5dd0b92ecc94cab2a92247a08adc88e..355322688c9fa7eb75e225d7bc0697dd1fedbaa1 100644 (file)
@@ -132,7 +132,7 @@ xfs_da3_node_verify(
        if (xfs_sb_version_hascrc(&mp->m_sb)) {
                struct xfs_da3_node_hdr *hdr3 = bp->b_addr;
 
-               if (ichdr.magic != XFS_DA3_NODE_MAGIC)
+               if (hdr3->info.hdr.magic != cpu_to_be16(XFS_DA3_NODE_MAGIC))
                        return __this_address;
 
                if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid))
@@ -142,7 +142,7 @@ xfs_da3_node_verify(
                if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->info.lsn)))
                        return __this_address;
        } else {
-               if (ichdr.magic != XFS_DA_NODE_MAGIC)
+               if (hdr->hdr.info.magic != cpu_to_be16(XFS_DA_NODE_MAGIC))
                        return __this_address;
        }
        if (ichdr.level == 0)
index 82c4374acb4c63fc4d2146f6a58ad41784e0f0ae..01ebc9557f6949cf59ecf205d8f098a65a5bf47f 100644 (file)
@@ -151,7 +151,7 @@ const struct xfs_buf_ops xfs_inode_buf_ops = {
 };
 
 const struct xfs_buf_ops xfs_inode_buf_ra_ops = {
-       .name = "xxfs_inode_ra",
+       .name = "xfs_inode_ra",
        .verify_read = xfs_inode_buf_readahead_verify,
        .verify_write = xfs_inode_buf_write_verify,
 };
index b5a82acd7dfe01d9225c345bbd15740fb4995e83..a2f52a9580917007b29b1f168393fdd5d96d2606 100644 (file)
@@ -225,10 +225,11 @@ xfs_validate_sb_common(
        struct xfs_buf          *bp,
        struct xfs_sb           *sbp)
 {
+       struct xfs_dsb          *dsb = XFS_BUF_TO_SBP(bp);
        uint32_t                agcount = 0;
        uint32_t                rem;
 
-       if (sbp->sb_magicnum != XFS_SB_MAGIC) {
+       if (dsb->sb_magicnum != cpu_to_be32(XFS_SB_MAGIC)) {
                xfs_warn(mp, "bad magic number");
                return -EWRONGFS;
        }