xfs: create a new buf_ops pointer to verify structure metadata
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 8 Jan 2018 18:51:08 +0000 (10:51 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Mon, 8 Jan 2018 18:54:47 +0000 (10:54 -0800)
Expose all metadata structure buffer verifier functions via buf_ops.
These will be used by the online scrub mechanism to look for problems
with buffers that are already sitting around in memory.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
17 files changed:
fs/xfs/libxfs/xfs_alloc.c
fs/xfs/libxfs/xfs_alloc_btree.c
fs/xfs/libxfs/xfs_attr_leaf.c
fs/xfs/libxfs/xfs_attr_remote.c
fs/xfs/libxfs/xfs_bmap_btree.c
fs/xfs/libxfs/xfs_da_btree.c
fs/xfs/libxfs/xfs_dir2_block.c
fs/xfs/libxfs/xfs_dir2_data.c
fs/xfs/libxfs/xfs_dir2_leaf.c
fs/xfs/libxfs/xfs_dir2_node.c
fs/xfs/libxfs/xfs_dquot_buf.c
fs/xfs/libxfs/xfs_ialloc.c
fs/xfs/libxfs/xfs_ialloc_btree.c
fs/xfs/libxfs/xfs_refcount_btree.c
fs/xfs/libxfs/xfs_rmap_btree.c
fs/xfs/libxfs/xfs_symlink_remote.c
fs/xfs/xfs_buf.h

index 6bace8cb47dab11c88d82468895807e9c3937131..50ba989481cc9904ff74eef2646ef4a0d8448ca5 100644 (file)
@@ -528,6 +528,15 @@ xfs_agfl_verify(
        struct xfs_agfl *agfl = XFS_BUF_TO_AGFL(bp);
        int             i;
 
+       /*
+        * There is no verification of non-crc AGFLs because mkfs does not
+        * initialise the AGFL to zero or NULL. Hence the only valid part of the
+        * AGFL is what the AGF says is active. We can't get to the AGF, so we
+        * can't verify just those entries are valid.
+        */
+       if (!xfs_sb_version_hascrc(&mp->m_sb))
+               return NULL;
+
        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)
@@ -605,6 +614,7 @@ const struct xfs_buf_ops xfs_agfl_buf_ops = {
        .name = "xfs_agfl",
        .verify_read = xfs_agfl_read_verify,
        .verify_write = xfs_agfl_write_verify,
+       .verify_struct = xfs_agfl_verify,
 };
 
 /*
@@ -2402,10 +2412,10 @@ xfs_alloc_put_freelist(
 
 static xfs_failaddr_t
 xfs_agf_verify(
-       struct xfs_mount *mp,
-       struct xfs_buf  *bp)
- {
-       struct xfs_agf  *agf = XFS_BUF_TO_AGF(bp);
+       struct xfs_buf          *bp)
+{
+       struct xfs_mount        *mp = bp->b_target->bt_mount;
+       struct xfs_agf          *agf = XFS_BUF_TO_AGF(bp);
 
        if (xfs_sb_version_hascrc(&mp->m_sb)) {
                if (!uuid_equal(&agf->agf_uuid, &mp->m_sb.sb_meta_uuid))
@@ -2467,7 +2477,7 @@ xfs_agf_read_verify(
            !xfs_buf_verify_cksum(bp, XFS_AGF_CRC_OFF))
                xfs_verifier_error(bp, -EFSBADCRC, __this_address);
        else {
-               fa = xfs_agf_verify(mp, bp);
+               fa = xfs_agf_verify(bp);
                if (XFS_TEST_ERROR(fa, mp, XFS_ERRTAG_ALLOC_READ_AGF))
                        xfs_verifier_error(bp, -EFSCORRUPTED, fa);
        }
@@ -2481,7 +2491,7 @@ xfs_agf_write_verify(
        struct xfs_buf_log_item *bip = bp->b_fspriv;
        xfs_failaddr_t          fa;
 
-       fa = xfs_agf_verify(mp, bp);
+       fa = xfs_agf_verify(bp);
        if (fa) {
                xfs_verifier_error(bp, -EFSCORRUPTED, fa);
                return;
@@ -2500,6 +2510,7 @@ const struct xfs_buf_ops xfs_agf_buf_ops = {
        .name = "xfs_agf",
        .verify_read = xfs_agf_read_verify,
        .verify_write = xfs_agf_write_verify,
+       .verify_struct = xfs_agf_verify,
 };
 
 /*
index 060d6fa83a7f2612bd5647a2d66d6329c47669b7..6840b588187e5e27f8b330e6a71dd593be430d82 100644 (file)
@@ -400,6 +400,7 @@ const struct xfs_buf_ops xfs_allocbt_buf_ops = {
        .name = "xfs_allocbt",
        .verify_read = xfs_allocbt_read_verify,
        .verify_write = xfs_allocbt_write_verify,
+       .verify_struct = xfs_allocbt_verify,
 };
 
 
index 7168827ca7583d7e941d655e710793334df2ed59..6fddce7bbd54c41be102d8536410b3fde2984424 100644 (file)
@@ -339,6 +339,7 @@ const struct xfs_buf_ops xfs_attr3_leaf_buf_ops = {
        .name = "xfs_attr3_leaf",
        .verify_read = xfs_attr3_leaf_read_verify,
        .verify_write = xfs_attr3_leaf_write_verify,
+       .verify_struct = xfs_attr3_leaf_verify,
 };
 
 int
index 55514b34321609e4294f805476ea524676f29d2a..21be186067a2b4cf6049f1a0dbb0b150469242d6 100644 (file)
@@ -116,20 +116,21 @@ xfs_attr3_rmt_verify(
        return NULL;
 }
 
-static void
-xfs_attr3_rmt_read_verify(
-       struct xfs_buf  *bp)
+static int
+__xfs_attr3_rmt_read_verify(
+       struct xfs_buf  *bp,
+       bool            check_crc,
+       xfs_failaddr_t  *failaddr)
 {
        struct xfs_mount *mp = bp->b_target->bt_mount;
        char            *ptr;
-       xfs_failaddr_t  fa;
        int             len;
        xfs_daddr_t     bno;
        int             blksize = mp->m_attr_geo->blksize;
 
        /* no verification of non-crc buffers */
        if (!xfs_sb_version_hascrc(&mp->m_sb))
-               return;
+               return 0;
 
        ptr = bp->b_addr;
        bno = bp->b_bn;
@@ -137,22 +138,48 @@ xfs_attr3_rmt_read_verify(
        ASSERT(len >= blksize);
 
        while (len > 0) {
-               if (!xfs_verify_cksum(ptr, blksize, XFS_ATTR3_RMT_CRC_OFF)) {
-                       xfs_verifier_error(bp, -EFSBADCRC, __this_address);
-                       return;
-               }
-               fa = xfs_attr3_rmt_verify(mp, ptr, blksize, bno);
-               if (fa) {
-                       xfs_verifier_error(bp, -EFSCORRUPTED, fa);
-                       break;
+               if (check_crc &&
+                   !xfs_verify_cksum(ptr, blksize, XFS_ATTR3_RMT_CRC_OFF)) {
+                       *failaddr = __this_address;
+                       return -EFSBADCRC;
                }
+               *failaddr = xfs_attr3_rmt_verify(mp, ptr, blksize, bno);
+               if (*failaddr)
+                       return -EFSCORRUPTED;
                len -= blksize;
                ptr += blksize;
                bno += BTOBB(blksize);
        }
 
-       if (len != 0)
-               xfs_verifier_error(bp, -EFSCORRUPTED, __this_address);
+       if (len != 0) {
+               *failaddr = __this_address;
+               return -EFSCORRUPTED;
+       }
+
+       return 0;
+}
+
+static void
+xfs_attr3_rmt_read_verify(
+       struct xfs_buf  *bp)
+{
+       xfs_failaddr_t  fa;
+       int             error;
+
+       error = __xfs_attr3_rmt_read_verify(bp, true, &fa);
+       if (error)
+               xfs_verifier_error(bp, error, fa);
+}
+
+static xfs_failaddr_t
+xfs_attr3_rmt_verify_struct(
+       struct xfs_buf  *bp)
+{
+       xfs_failaddr_t  fa;
+       int             error;
+
+       error = __xfs_attr3_rmt_read_verify(bp, false, &fa);
+       return error ? fa : NULL;
 }
 
 static void
@@ -207,6 +234,7 @@ const struct xfs_buf_ops xfs_attr3_rmt_buf_ops = {
        .name = "xfs_attr3_rmt",
        .verify_read = xfs_attr3_rmt_read_verify,
        .verify_write = xfs_attr3_rmt_write_verify,
+       .verify_struct = xfs_attr3_rmt_verify_struct,
 };
 
 STATIC int
index 64ae0eea9812da86b086151bac4a24e2571ce57a..9faf479aba497ec4a4297f44700a6f809ea4ad59 100644 (file)
@@ -501,6 +501,7 @@ 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,
 };
 
 
index 0ae39617a6c1e61ec732764927b4116dd441f944..cf07585b9d83de46a6c88787a595ff8dcb374452 100644 (file)
@@ -243,10 +243,35 @@ xfs_da3_node_read_verify(
        }
 }
 
+/* Verify the structure of a da3 block. */
+static xfs_failaddr_t
+xfs_da3_node_verify_struct(
+       struct xfs_buf          *bp)
+{
+       struct xfs_da_blkinfo   *info = bp->b_addr;
+
+       switch (be16_to_cpu(info->magic)) {
+       case XFS_DA3_NODE_MAGIC:
+       case XFS_DA_NODE_MAGIC:
+               return xfs_da3_node_verify(bp);
+       case XFS_ATTR_LEAF_MAGIC:
+       case XFS_ATTR3_LEAF_MAGIC:
+               bp->b_ops = &xfs_attr3_leaf_buf_ops;
+               return bp->b_ops->verify_struct(bp);
+       case XFS_DIR2_LEAFN_MAGIC:
+       case XFS_DIR3_LEAFN_MAGIC:
+               bp->b_ops = &xfs_dir3_leafn_buf_ops;
+               return bp->b_ops->verify_struct(bp);
+       default:
+               return __this_address;
+       }
+}
+
 const struct xfs_buf_ops xfs_da3_node_buf_ops = {
        .name = "xfs_da3_node",
        .verify_read = xfs_da3_node_read_verify,
        .verify_write = xfs_da3_node_write_verify,
+       .verify_struct = xfs_da3_node_verify_struct,
 };
 
 int
index cfd2777bf918473caa1b6f00073275fe5cc6ce7b..fe951fa1a583e483d81b9e9a20a62ed2d3b62517 100644 (file)
@@ -126,6 +126,7 @@ const struct xfs_buf_ops xfs_dir3_block_buf_ops = {
        .name = "xfs_dir3_block",
        .verify_read = xfs_dir3_block_read_verify,
        .verify_write = xfs_dir3_block_write_verify,
+       .verify_struct = xfs_dir3_block_verify,
 };
 
 int
index 2fa7c34023fbae8b189e95ad64bd02e321cf0389..32378122cd1f4fced3449cbd467c8dffc4598e3e 100644 (file)
@@ -334,6 +334,7 @@ const struct xfs_buf_ops xfs_dir3_data_buf_ops = {
        .name = "xfs_dir3_data",
        .verify_read = xfs_dir3_data_read_verify,
        .verify_write = xfs_dir3_data_write_verify,
+       .verify_struct = xfs_dir3_data_verify,
 };
 
 static const struct xfs_buf_ops xfs_dir3_data_reada_buf_ops = {
index a03d67995811035b91cc6bd84ab86cbf6a58cd25..a7ad649398c70402a97ec21ec62455e0bf3ebe18 100644 (file)
@@ -227,6 +227,13 @@ __write_verify(
        xfs_buf_update_cksum(bp, XFS_DIR3_LEAF_CRC_OFF);
 }
 
+static xfs_failaddr_t
+xfs_dir3_leaf1_verify(
+       struct xfs_buf  *bp)
+{
+       return xfs_dir3_leaf_verify(bp, XFS_DIR2_LEAF1_MAGIC);
+}
+
 static void
 xfs_dir3_leaf1_read_verify(
        struct xfs_buf  *bp)
@@ -241,6 +248,13 @@ xfs_dir3_leaf1_write_verify(
        __write_verify(bp, XFS_DIR2_LEAF1_MAGIC);
 }
 
+static xfs_failaddr_t
+xfs_dir3_leafn_verify(
+       struct xfs_buf  *bp)
+{
+       return xfs_dir3_leaf_verify(bp, XFS_DIR2_LEAFN_MAGIC);
+}
+
 static void
 xfs_dir3_leafn_read_verify(
        struct xfs_buf  *bp)
@@ -259,12 +273,14 @@ const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops = {
        .name = "xfs_dir3_leaf1",
        .verify_read = xfs_dir3_leaf1_read_verify,
        .verify_write = xfs_dir3_leaf1_write_verify,
+       .verify_struct = xfs_dir3_leaf1_verify,
 };
 
 const struct xfs_buf_ops xfs_dir3_leafn_buf_ops = {
        .name = "xfs_dir3_leafn",
        .verify_read = xfs_dir3_leafn_read_verify,
        .verify_write = xfs_dir3_leafn_write_verify,
+       .verify_struct = xfs_dir3_leafn_verify,
 };
 
 int
index 3bdbe18972121d76891aa11d1024926a4b4a6ad4..915c4fe5e4c3ca6a2f7c715f77230de978a3f174 100644 (file)
@@ -164,6 +164,7 @@ const struct xfs_buf_ops xfs_dir3_free_buf_ops = {
        .name = "xfs_dir3_free",
        .verify_read = xfs_dir3_free_read_verify,
        .verify_write = xfs_dir3_free_write_verify,
+       .verify_struct = xfs_dir3_free_verify,
 };
 
 /* Everything ok in the free block header? */
index 5e022c1a52c4336f5edcc4dc9e04ba9060809649..f8b62fca9f6a033d2aba227f753a0529eb9fbfa1 100644 (file)
@@ -242,6 +242,17 @@ xfs_dquot_buf_verify(
        return true;
 }
 
+static xfs_failaddr_t
+xfs_dquot_buf_verify_struct(
+       struct xfs_buf  *bp)
+{
+       struct xfs_mount        *mp = bp->b_target->bt_mount;
+
+       if (!xfs_dquot_buf_verify(mp, bp, 0))
+               return __this_address;
+       return NULL;
+}
+
 static void
 xfs_dquot_buf_read_verify(
        struct xfs_buf  *bp)
@@ -294,6 +305,7 @@ const struct xfs_buf_ops xfs_dquot_buf_ops = {
        .name = "xfs_dquot",
        .verify_read = xfs_dquot_buf_read_verify,
        .verify_write = xfs_dquot_buf_write_verify,
+       .verify_struct = xfs_dquot_buf_verify_struct,
 };
 
 const struct xfs_buf_ops xfs_dquot_buf_ra_ops = {
index 344b6a3525e1b06bc32287ac91f79e7429d5c9c8..c01ed9cfc5ae55491c65a9b6db1eb25d9cc18d36 100644 (file)
@@ -2579,6 +2579,7 @@ const struct xfs_buf_ops xfs_agi_buf_ops = {
        .name = "xfs_agi",
        .verify_read = xfs_agi_read_verify,
        .verify_write = xfs_agi_write_verify,
+       .verify_struct = xfs_agi_verify,
 };
 
 /*
index 9c691ad00220cea23b539ddf91b399fce2b8e7ad..47f44d624cb1332e461284c7811586fbdf20d1c1 100644 (file)
@@ -329,6 +329,7 @@ const struct xfs_buf_ops xfs_inobt_buf_ops = {
        .name = "xfs_inobt",
        .verify_read = xfs_inobt_read_verify,
        .verify_write = xfs_inobt_write_verify,
+       .verify_struct = xfs_inobt_verify,
 };
 
 STATIC int
index 715c272a609ce6bd64021a585731ea2d560d59f4..8479769e470d0c87822212b577082720026ef62d 100644 (file)
@@ -290,6 +290,7 @@ const struct xfs_buf_ops xfs_refcountbt_buf_ops = {
        .name                   = "xfs_refcountbt",
        .verify_read            = xfs_refcountbt_read_verify,
        .verify_write           = xfs_refcountbt_write_verify,
+       .verify_struct          = xfs_refcountbt_verify,
 };
 
 STATIC int
index d089a48ac530dad31ccdfe752753ded9922891f8..e829c3e489ea43d4e913166d594490161f39fe29 100644 (file)
@@ -382,6 +382,7 @@ const struct xfs_buf_ops xfs_rmapbt_buf_ops = {
        .name                   = "xfs_rmapbt",
        .verify_read            = xfs_rmapbt_read_verify,
        .verify_write           = xfs_rmapbt_write_verify,
+       .verify_struct          = xfs_rmapbt_verify,
 };
 
 STATIC int
index adf2d7833abdff870c1d6ab494b87b7fb77330b0..091e3cf0868f9f4775531b8ce247281ea5b01fa1 100644 (file)
@@ -173,6 +173,7 @@ const struct xfs_buf_ops xfs_symlink_buf_ops = {
        .name = "xfs_symlink",
        .verify_read = xfs_symlink_read_verify,
        .verify_write = xfs_symlink_write_verify,
+       .verify_struct = xfs_symlink_verify,
 };
 
 void
index 6f907a365f85cb30509e8413a00cf64517423adc..5b5b4861c729ad83ca6f6acc05a603710ad1d4d9 100644 (file)
@@ -140,6 +140,7 @@ struct xfs_buf_ops {
        char *name;
        void (*verify_read)(struct xfs_buf *);
        void (*verify_write)(struct xfs_buf *);
+       xfs_failaddr_t (*verify_struct)(struct xfs_buf *bp);
 };
 
 typedef struct xfs_buf {