public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_repair: validate & fix inode CRCs
@ 2014-09-16 21:30 Eric Sandeen
  2014-09-22 13:18 ` Brian Foster
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2014-09-16 21:30 UTC (permalink / raw)
  To: xfs-oss

xfs_repair doesn't ever check an inode's CRC, so it never repairs
them.  If the root inode or realtime inodes have bad crcs, the
fs won't even mount and can't be fixed (without using xfs_db).

It's fairly straightforward to just test the inode CRC before
we do any other checking or modification of the inode, once we
get past the "verify only" phase of process_dinode_int();
just mark it dirty if it's wrong and needs to be re-written.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

forgive the gratuitous big honkin' comment line, but
process_dinode_int is so long, I thought the visual delimiter was
useful.  ;)

diff --git a/repair/dinode.c b/repair/dinode.c
index 8891e84..27c0da6 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -2524,6 +2524,30 @@ _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"),
 	if (verify_mode)
 		return retval;
 
+	/* =========== END OF VERIFY MODE =================== */
+
+	/*
+	 * We'd really like to know if the CRC is bad before we
+	 * go fixing anything; that way we have some hint about
+	 * bit-rot vs bugs.  Also, any changes will invalidate the
+	 * existing CRC, so this is the only valid point to test it.
+	 *
+	 * Of course if we make any modifications after this, the
+	 * inode gets rewritten, and CRC is updated automagically.
+	 */
+	if (xfs_sb_version_hascrc(&mp->m_sb)) {
+		ASSERT(!verify_mode);
+		if(!xfs_verify_cksum((char *)dino, mp->m_sb.sb_inodesize,
+                		XFS_DINODE_CRC_OFF)) {
+			do_warn(_("bad CRC for inode %" PRIu64), lino);
+			if (!no_modify) {
+				do_warn(_(", will rewrite\n"));
+				*dirty = 1;
+			} else
+				do_warn(_(", would rewrite\n"));
+		}
+	}
+
 	/*
 	 * clear the next unlinked field if necessary on a good
 	 * inode only during phase 4 -- when checking for inodes


_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-22 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-16 21:30 [PATCH] xfs_repair: validate & fix inode CRCs Eric Sandeen
2014-09-22 13:18 ` Brian Foster
2014-09-22 14:45   ` Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox