]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
db: introduce verifier support into set_cur
authorDave Chinner <dchinner@redhat.com>
Wed, 13 Nov 2013 06:40:45 +0000 (06:40 +0000)
committerRich Johnston <rjohnston@sgi.com>
Wed, 13 Nov 2013 17:12:20 +0000 (11:12 -0600)
To be able to use read and write verifiers, we need to pass the
verifier to the IO routines. We do this via the set_cur() function
used to trigger reading the buffer.

For most metadata types, there is only one type of verifier needed.
For these, we can simply add the verifier to the type table entry
for the given type and use that directly. This type entry is already
carried around by the IO context, so if we ever need to get it again
we have direct access to it in the context we'll be doing IO.

Only attach the verifiers to the v5 filesystem type table; there is
not need for them on v4 filesystems as we don't have to verify or
calculate CRCs for them.

There are some metadata types that have more than one buffer format,
or aren't based in directly in buffers. For these, leave the type
table verifier NULL for now - these will need to be addressed
individually.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Rich Johnston <rjohnston@sgi.com>
db/io.c
db/type.c
db/type.h

diff --git a/db/io.c b/db/io.c
index ca893548dd951de622a075ab8c2d0ddba05264c0..2d1cc5676e8c22b4b6036cd3b4fc50e9df701587 100644 (file)
--- a/db/io.c
+++ b/db/io.c
@@ -482,12 +482,14 @@ set_cur(
        xfs_ino_t       dirino;
        xfs_ino_t       ino;
        __uint16_t      mode;
+       const struct xfs_buf_ops *ops = t ? t->bops : NULL;
 
        if (iocur_sp < 0) {
                dbprintf(_("set_cur no stack element to set\n"));
                return;
        }
 
+
        ino = iocur_top->ino;
        dirino = iocur_top->dirino;
        mode = iocur_top->mode;
@@ -509,12 +511,17 @@ set_cur(
                        return;
                memcpy(iocur_top->bbmap, bbmap, sizeof(struct bbmap));
                bp = libxfs_readbuf_map(mp->m_ddev_targp, bbmap->b,
-                                       bbmap->nmaps, 0, NULL);
+                                       bbmap->nmaps, 0, ops);
        } else {
-               bp = libxfs_readbuf(mp->m_ddev_targp, d, c, 0, NULL);
+               bp = libxfs_readbuf(mp->m_ddev_targp, d, c, 0, ops);
                iocur_top->bbmap = NULL;
        }
-       if (!bp || bp->b_error)
+
+       /*
+        * keep the buffer even if the verifier says it is corrupted.
+        * We're a diagnostic tool, after all.
+        */
+       if (!bp || (bp->b_error && bp->b_error != EFSCORRUPTED))
                return;
        iocur_top->buf = bp->b_addr;
        iocur_top->bp = bp;
index 64e2ef4e2835d41cb1d245cfe1f0fa10d947c4f4..b3f3d8783edc1bad54319074e882aea619751964 100644 (file)
--- a/db/type.c
+++ b/db/type.c
@@ -50,50 +50,58 @@ static const cmdinfo_t      type_cmd =
          N_("set/show current data type"), NULL };
 
 static const typ_t     __typtab[] = {
-       { TYP_AGF, "agf", handle_struct, agf_hfld },
-       { TYP_AGFL, "agfl", handle_struct, agfl_hfld },
-       { TYP_AGI, "agi", handle_struct, agi_hfld },
-       { TYP_ATTR, "attr", handle_struct, attr_hfld },
-       { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_hfld },
-       { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_hfld },
-       { TYP_BNOBT, "bnobt", handle_struct, bnobt_hfld },
-       { TYP_CNTBT, "cntbt", handle_struct, cntbt_hfld },
-       { TYP_DATA, "data", handle_block, NULL },
-       { TYP_DIR2, "dir2", handle_struct, dir2_hfld },
-       { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld },
-       { TYP_INOBT, "inobt", handle_struct, inobt_hfld },
-       { TYP_INODATA, "inodata", NULL, NULL },
-       { TYP_INODE, "inode", handle_struct, inode_hfld },
-       { TYP_LOG, "log", NULL, NULL },
-       { TYP_RTBITMAP, "rtbitmap", NULL, NULL },
-       { TYP_RTSUMMARY, "rtsummary", NULL, NULL },
-       { TYP_SB, "sb", handle_struct, sb_hfld },
-       { TYP_SYMLINK, "symlink", handle_string, NULL },
-       { TYP_TEXT, "text", handle_text, NULL },
+       { TYP_AGF, "agf", handle_struct, agf_hfld, NULL },
+       { TYP_AGFL, "agfl", handle_struct, agfl_hfld, NULL },
+       { TYP_AGI, "agi", handle_struct, agi_hfld, NULL },
+       { TYP_ATTR, "attr", handle_struct, attr_hfld, NULL },
+       { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_hfld, NULL },
+       { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_hfld, NULL },
+       { TYP_BNOBT, "bnobt", handle_struct, bnobt_hfld, NULL },
+       { TYP_CNTBT, "cntbt", handle_struct, cntbt_hfld, NULL },
+       { TYP_DATA, "data", handle_block, NULL, NULL },
+       { TYP_DIR2, "dir2", handle_struct, dir2_hfld, NULL },
+       { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld, NULL },
+       { TYP_INOBT, "inobt", handle_struct, inobt_hfld, NULL },
+       { TYP_INODATA, "inodata", NULL, NULL, NULL },
+       { TYP_INODE, "inode", handle_struct, inode_hfld, NULL },
+       { TYP_LOG, "log", NULL, NULL, NULL },
+       { TYP_RTBITMAP, "rtbitmap", NULL, NULL, NULL },
+       { TYP_RTSUMMARY, "rtsummary", NULL, NULL, NULL },
+       { TYP_SB, "sb", handle_struct, sb_hfld, NULL },
+       { TYP_SYMLINK, "symlink", handle_string, NULL, NULL },
+       { TYP_TEXT, "text", handle_text, NULL, NULL },
        { TYP_NONE, NULL }
 };
 
 static const typ_t     __typtab_crc[] = {
-       { TYP_AGF, "agf", handle_struct, agf_hfld },
-       { TYP_AGFL, "agfl", handle_struct, agfl_crc_hfld },
-       { TYP_AGI, "agi", handle_struct, agi_hfld },
-       { TYP_ATTR, "attr3", handle_struct, attr3_hfld },
-       { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_crc_hfld },
-       { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_crc_hfld },
-       { TYP_BNOBT, "bnobt", handle_struct, bnobt_crc_hfld },
-       { TYP_CNTBT, "cntbt", handle_struct, cntbt_crc_hfld },
-       { TYP_DATA, "data", handle_block, NULL },
-       { TYP_DIR2, "dir3", handle_struct, dir3_hfld },
-       { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld },
-       { TYP_INOBT, "inobt", handle_struct, inobt_crc_hfld },
-       { TYP_INODATA, "inodata", NULL, NULL },
-       { TYP_INODE, "inode", handle_struct, inode_crc_hfld },
-       { TYP_LOG, "log", NULL, NULL },
-       { TYP_RTBITMAP, "rtbitmap", NULL, NULL },
-       { TYP_RTSUMMARY, "rtsummary", NULL, NULL },
-       { TYP_SB, "sb", handle_struct, sb_hfld },
-       { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld },
-       { TYP_TEXT, "text", handle_text, NULL },
+       { TYP_AGF, "agf", handle_struct, agf_hfld, &xfs_agf_buf_ops },
+       { TYP_AGFL, "agfl", handle_struct, agfl_crc_hfld, &xfs_agfl_buf_ops },
+       { TYP_AGI, "agi", handle_struct, agi_hfld, &xfs_agfl_buf_ops },
+       { TYP_ATTR, "attr3", handle_struct, attr3_hfld, NULL },
+       { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_crc_hfld,
+               &xfs_bmbt_buf_ops },
+       { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_crc_hfld,
+               &xfs_bmbt_buf_ops },
+       { TYP_BNOBT, "bnobt", handle_struct, bnobt_crc_hfld,
+               &xfs_allocbt_buf_ops },
+       { TYP_CNTBT, "cntbt", handle_struct, cntbt_crc_hfld,
+               &xfs_allocbt_buf_ops },
+       { TYP_DATA, "data", handle_block, NULL, NULL },
+       { TYP_DIR2, "dir3", handle_struct, dir3_hfld, NULL },
+       { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld,
+               &xfs_dquot_buf_ops },
+       { TYP_INOBT, "inobt", handle_struct, inobt_crc_hfld,
+               &xfs_inobt_buf_ops },
+       { TYP_INODATA, "inodata", NULL, NULL, NULL },
+       { TYP_INODE, "inode", handle_struct, inode_crc_hfld,
+               &xfs_inode_buf_ops },
+       { TYP_LOG, "log", NULL, NULL, NULL },
+       { TYP_RTBITMAP, "rtbitmap", NULL, NULL, NULL },
+       { TYP_RTSUMMARY, "rtsummary", NULL, NULL, NULL },
+       { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops },
+       { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld,
+               &xfs_symlink_buf_ops },
+       { TYP_TEXT, "text", handle_text, NULL, NULL },
        { TYP_NONE, NULL }
 };
 
index c41aca4d8c1dd2ce1c552c126a07c0103c9da03f..3bb26f1744160ee2a38d3b28538666600c099aee 100644 (file)
--- a/db/type.h
+++ b/db/type.h
@@ -42,6 +42,7 @@ typedef struct typ
        char                    *name;
        pfunc_t                 pfunc;
        const struct field      *fields;
+       const struct xfs_buf_ops *bops;
 } typ_t;
 extern const typ_t     *typtab, *cur_typ;