]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_db: fix inode CRC validity state, and warn on read if invalid
authorEric Sandeen <sandeen@sandeen.net>
Mon, 6 Apr 2015 23:19:28 +0000 (09:19 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 6 Apr 2015 23:19:28 +0000 (09:19 +1000)
Currently, the "ino_crc_ok" field on the io cursor reflects
overall inode validity, not CRC correctness.  Because it is
only used when printing CRC validity, change it to reflect
only that state - and update it whenever we re-write the
inode (thus updating the CRC).

In addition, when reading an inode, warn if the CRC is bad.

Note, when specifying an inode which doesn't actually exist,
this will claim corruption; I'm not sure if that's good or
bad. Today, it already issues corruption errors on the way;
this adds a new message as well:

xfs_db> inode 129
Metadata corruption detected at block 0x80/0x2000
Metadata corruption detected at block 0x80/0x2000
...
Metadata CRC error detected for ino 129

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
db/inode.c
db/io.c
include/libxfs.h

index 24170ba82b26999f3139d64dbc035a89122c579a..4f9c65df2e69888b2b011c6b6088b8efd0d84740 100644 (file)
@@ -684,13 +684,22 @@ set_cur_inode(
                numblks, DB_RING_IGN, NULL);
        off_cur(offset << mp->m_sb.sb_inodelog, mp->m_sb.sb_inodesize);
        dip = iocur_top->data;
-       iocur_top->ino_crc_ok = libxfs_dinode_verify(mp, ino, dip);
        iocur_top->ino_buf = 1;
        iocur_top->ino = ino;
        iocur_top->mode = be16_to_cpu(dip->di_mode);
        if ((iocur_top->mode & S_IFMT) == S_IFDIR)
                iocur_top->dirino = ino;
 
+       if (xfs_sb_version_hascrc(&mp->m_sb)) {
+               iocur_top->ino_crc_ok = libxfs_verify_cksum((char *)dip,
+                                                   mp->m_sb.sb_inodesize,
+                                                   XFS_DINODE_CRC_OFF);
+               if (!iocur_top->ino_crc_ok)
+                       dbprintf(
+_("Metadata CRC error detected for ino %lld\n"),
+                               ino);
+       }
+
        /* track updated info in ring */
        ring_add();
 }
diff --git a/db/io.c b/db/io.c
index c5898f1e5d05548240dbff3464c337a6fe56ff4c..d90612335b228e33aa44a3ad3cbc583d287746b0 100644 (file)
--- a/db/io.c
+++ b/db/io.c
@@ -471,8 +471,10 @@ write_cur(void)
                return;
        }
 
-       if (iocur_top->ino_buf)
+       if (xfs_sb_version_hascrc(&mp->m_sb) && iocur_top->ino_buf) {
                libxfs_dinode_calc_crc(mp, iocur_top->data);
+               iocur_top->ino_crc_ok = 1;
+       }
        if (iocur_top->dquot_buf)
                xfs_update_cksum(iocur_top->data, sizeof(struct xfs_dqblk),
                                 XFS_DQUOT_CRC_OFF);
index 45a924fc90dfff4d59742c71bf26328390b226b2..962e3194ee47342c007881f6a8e967704d7da0c2 100644 (file)
@@ -782,6 +782,8 @@ extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);
 
 #include <xfs/xfs_cksum.h>
 
+#define libxfs_verify_cksum    xfs_verify_cksum
+
 static inline int
 xfs_buf_verify_cksum(struct xfs_buf *bp, unsigned long cksum_offset)
 {