]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: create a new buf_ops pointer to verify structure metadata
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 27 Feb 2018 04:43:17 +0000 (22:43 -0600)
committerEric Sandeen <sandeen@redhat.com>
Tue, 27 Feb 2018 04:43:17 +0000 (22:43 -0600)
Source kernel commit: b55725974c9d3a5afcdf83daff6fba7d3f91ffca

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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
17 files changed:
libxfs/libxfs_io.h
libxfs/xfs_alloc.c
libxfs/xfs_alloc_btree.c
libxfs/xfs_attr_leaf.c
libxfs/xfs_attr_remote.c
libxfs/xfs_bmap_btree.c
libxfs/xfs_da_btree.c
libxfs/xfs_dir2_block.c
libxfs/xfs_dir2_data.c
libxfs/xfs_dir2_leaf.c
libxfs/xfs_dir2_node.c
libxfs/xfs_dquot_buf.c
libxfs/xfs_ialloc.c
libxfs/xfs_ialloc_btree.c
libxfs/xfs_refcount_btree.c
libxfs/xfs_rmap_btree.c
libxfs/xfs_symlink_remote.c

index 2fce04dad4239517af4ecc2e394b14e105b914dc..6087fe084a84a3be1ebacf0b84a73975ac00be29 100644 (file)
@@ -55,6 +55,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 *);
 };
 
 typedef struct xfs_buf {
index 1e2470793afa62699370f1bac9f82869d235b728..8936191acf2f059d6dd0538922c6e0823207b545 100644 (file)
@@ -524,6 +524,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)
@@ -601,6 +610,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,
 };
 
 /*
@@ -2398,10 +2408,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))
@@ -2463,7 +2473,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);
        }
@@ -2477,7 +2487,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;
@@ -2496,6 +2506,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 e3a3d4aa1b472666d1c64c60ddc546ea49c94560..d1b47a27d18097b8d4b6bf9db8d6deff4c6618e3 100644 (file)
@@ -398,6 +398,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 9c11a0c37e8b38096d64b8bc3975cd99f6344e5e..072e3b0a23d0e671a4959ed9eeb2780df36b3f80 100644 (file)
@@ -334,6 +334,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 cff9d79545e30b75df4b7c0b6feb5fb4d82122ea..e75a46613b5d093dad79da66d40e37227e0f459e 100644 (file)
@@ -111,20 +111,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;
@@ -132,22 +133,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
@@ -202,6 +229,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 2c1b0bd582f9b6b8f2535766ac3662f87637bda1..e2a1fec249fa07ae7f7e979f82f4c10052c45b7f 100644 (file)
@@ -498,6 +498,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 2027b0f74bf0068789bd3e7e883a6285a093f2d3..b442d9a4b911237a0d36536494ddc7f5ce1a1cbb 100644 (file)
@@ -238,10 +238,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 765fba143ddad18b6089bf7e8acb8bfa7993911c..f69561ebaf666ad5de05406ee6f1a6a1b965ab28 100644 (file)
@@ -122,6 +122,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 6099cff304a71a2d749d713dd122184e45cd15b9..0ef5177821a3c88440f6fc94b2a95344d7ed1167 100644 (file)
@@ -331,6 +331,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 4c76f844830a4bd8e3052aa94e927310bfb48970..ff2996be15b9106bf57c167a398cb70001c0aa8d 100644 (file)
@@ -224,6 +224,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)
@@ -238,6 +245,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)
@@ -256,12 +270,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 c5ef0b54a3a39b32205f12519a331926736e0fb1..530983b74c15c86697b4f3b22ba2a8cdacebe348 100644 (file)
@@ -161,6 +161,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 2dcf5c018d5321320c03b85be1823819f1cfd17a..4dcc3cfb1021f783cf092167f9401571387baf90 100644 (file)
@@ -240,6 +240,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)
@@ -292,6 +303,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 6d66440f7a06b19c6e6a060dc3bee6b5c5689945..f9bc820a44c8171174bec0e3ea2f650281748a55 100644 (file)
@@ -2573,6 +2573,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 ea8ca12d80a9d3795b723dbc138155240229c15c..8ce5db7982d3555301ec501634b267c05740dd85 100644 (file)
@@ -328,6 +328,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 dd3b4d6a2bba5479b46da079741b2c046d357433..72994b5a1faca5b062418bba07e0d072af1f7c91 100644 (file)
@@ -289,6 +289,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 1a2d9084306ac44483a8c295a7c688cd2371c4d1..2676aab3870b740bf66da8688898254908a8c76a 100644 (file)
@@ -380,6 +380,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 0ad1318e659e8195a631e59584c00cc19d9d3239..4f920f19416a343ba251315d2805f3bdf6e3c691 100644 (file)
@@ -169,6 +169,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