Blame SOURCES/xfsprogs-5.10.0-xfs_repair-check-inode-btree-block-counters-in-AGI.patch

f49185
From 62c713cb0c7791717c0b2a663ff0cc72842fe6c7 Mon Sep 17 00:00:00 2001
f49185
From: "Darrick J. Wong" <darrick.wong@oracle.com>
f49185
Date: Fri, 20 Nov 2020 17:03:27 -0500
f49185
Subject: [PATCH] xfs_repair: check inode btree block counters in AGI
f49185
f49185
Make sure that both inode btree block counters in the AGI are correct.
f49185
f49185
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
f49185
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
f49185
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
f49185
---
f49185
f49185
diff --git a/repair/scan.c b/repair/scan.c
f49185
index 5b76212..086a3cd 100644
f49185
--- a/repair/scan.c
f49185
+++ b/repair/scan.c
f49185
@@ -1933,6 +1933,12 @@ _("invalid inode count, inode chunk %d/%u, count %d ninodes %d\n"),
f49185
 	return suspect;
f49185
 }
f49185
 
f49185
+struct ino_priv {
f49185
+	struct aghdr_cnts	*agcnts;
f49185
+	uint32_t		ino_blocks;
f49185
+	uint32_t		fino_blocks;
f49185
+};
f49185
+
f49185
 /*
f49185
  * this one walks the inode btrees sucking the info there into
f49185
  * the incore avl tree.  We try and rescue corrupted btree records
f49185
@@ -1961,7 +1967,8 @@ scan_inobt(
f49185
 	void			*priv,
f49185
 	const struct xfs_buf_ops *ops)
f49185
 {
f49185
-	struct aghdr_cnts	*agcnts = priv;
f49185
+	struct ino_priv		*ipriv = priv;
f49185
+	struct aghdr_cnts	*agcnts = ipriv->agcnts;
f49185
 	char			*name;
f49185
 	int			i;
f49185
 	int			numrecs;
f49185
@@ -1977,10 +1984,12 @@ scan_inobt(
f49185
 	case XFS_FIBT_MAGIC:
f49185
 	case XFS_FIBT_CRC_MAGIC:
f49185
 		name = "fino";
f49185
+		ipriv->fino_blocks++;
f49185
 		break;
f49185
 	case XFS_IBT_MAGIC:
f49185
 	case XFS_IBT_CRC_MAGIC:
f49185
 		name = "ino";
f49185
+		ipriv->ino_blocks++;
f49185
 		break;
f49185
 	default:
f49185
 		name = "(unknown)";
f49185
@@ -2320,6 +2329,9 @@ validate_agi(
f49185
 	xfs_agnumber_t		agno,
f49185
 	struct aghdr_cnts	*agcnts)
f49185
 {
f49185
+	struct ino_priv		priv = {
f49185
+		.agcnts = agcnts,
f49185
+	};
f49185
 	xfs_agblock_t		bno;
f49185
 	int			i;
f49185
 	uint32_t		magic;
f49185
@@ -2329,7 +2341,7 @@ validate_agi(
f49185
 		magic = xfs_sb_version_hascrc(&mp->m_sb) ? XFS_IBT_CRC_MAGIC
f49185
 							 : XFS_IBT_MAGIC;
f49185
 		scan_sbtree(bno, be32_to_cpu(agi->agi_level),
f49185
-			    agno, 0, scan_inobt, 1, magic, agcnts,
f49185
+			    agno, 0, scan_inobt, 1, magic, &priv,
f49185
 			    &xfs_inobt_buf_ops);
f49185
 	} else {
f49185
 		do_warn(_("bad agbno %u for inobt root, agno %d\n"),
f49185
@@ -2342,7 +2354,7 @@ validate_agi(
f49185
 			magic = xfs_sb_version_hascrc(&mp->m_sb) ?
f49185
 					XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
f49185
 			scan_sbtree(bno, be32_to_cpu(agi->agi_free_level),
f49185
-				    agno, 0, scan_inobt, 1, magic, agcnts,
f49185
+				    agno, 0, scan_inobt, 1, magic, &priv,
f49185
 				    &xfs_inobt_buf_ops);
f49185
 		} else {
f49185
 			do_warn(_("bad agbno %u for finobt root, agno %d\n"),
f49185
@@ -2350,6 +2362,17 @@ validate_agi(
f49185
 		}
f49185
 	}
f49185
 
f49185
+	if (xfs_sb_version_hasinobtcounts(&mp->m_sb)) {
f49185
+		if (be32_to_cpu(agi->agi_iblocks) != priv.ino_blocks)
f49185
+			do_warn(_("bad inobt block count %u, saw %u\n"),
f49185
+					be32_to_cpu(agi->agi_iblocks),
f49185
+					priv.ino_blocks);
f49185
+		if (be32_to_cpu(agi->agi_fblocks) != priv.fino_blocks)
f49185
+			do_warn(_("bad finobt block count %u, saw %u\n"),
f49185
+					be32_to_cpu(agi->agi_fblocks),
f49185
+					priv.fino_blocks);
f49185
+	}
f49185
+
f49185
 	if (be32_to_cpu(agi->agi_count) != agcnts->agicount) {
f49185
 		do_warn(_("agi_count %u, counted %u in ag %u\n"),
f49185
 			 be32_to_cpu(agi->agi_count), agcnts->agicount, agno);