Blame SOURCES/xfsprogs-5.7.0-xfs_repair-convert-to-libxfs_verify_agbno.patch

1569e6
From dcd6c2e1490ba5c59c14ca8ea843ca36048888b8 Mon Sep 17 00:00:00 2001
1569e6
From: "Darrick J. Wong" <darrick.wong@oracle.com>
1569e6
Date: Fri, 10 Jul 2020 15:35:45 -0400
1569e6
Subject: [PATCH] xfs_repair: convert to libxfs_verify_agbno
1569e6
1569e6
Convert the homegrown verify_agbno callers to use the libxfs function,
1569e6
as needed.  In some places we drop the "bno != 0" checks because those
1569e6
conditionals are checking btree roots; btree roots should never be
1569e6
zero if the corresponding feature bit is set; and repair skips the if
1569e6
clause entirely if the feature bit is disabled.
1569e6
1569e6
In effect, this strengthens repair to validate that AG btree pointers
1569e6
neither point to the AG headers nor past the end of the AG.
1569e6
1569e6
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1569e6
Reviewed-by: Christoph Hellwig <hch@lst.de>
1569e6
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
1569e6
---
1569e6
 libxfs/libxfs_api_defs.h |  1 +
1569e6
 repair/dinode.c          | 11 -----------
1569e6
 repair/dinode.h          |  5 -----
1569e6
 repair/scan.c            | 36 +++++++++++++++++++++++-------------
1569e6
 4 files changed, 24 insertions(+), 29 deletions(-)
1569e6
1569e6
Index: xfsprogs-5.0.0/libxfs/libxfs_api_defs.h
1569e6
===================================================================
1569e6
--- xfsprogs-5.0.0.orig/libxfs/libxfs_api_defs.h
1569e6
+++ xfsprogs-5.0.0/libxfs/libxfs_api_defs.h
1569e6
@@ -121,6 +121,7 @@
1569e6
 #define xfs_verify_agbno		libxfs_verify_agbno
1569e6
 #define xfs_verify_cksum		libxfs_verify_cksum
1569e6
 #define xfs_dinode_verify		libxfs_dinode_verify
1569e6
+#define xfs_ag_block_count		libxfs_ag_block_count
1569e6
 
1569e6
 #define xfs_alloc_ag_max_usable		libxfs_alloc_ag_max_usable
1569e6
 #define xfs_allocbt_maxrecs		libxfs_allocbt_maxrecs
1569e6
Index: xfsprogs-5.0.0/repair/dinode.c
1569e6
===================================================================
1569e6
--- xfsprogs-5.0.0.orig/repair/dinode.c
1569e6
+++ xfsprogs-5.0.0/repair/dinode.c
1569e6
@@ -284,17 +284,6 @@ verify_dfsbno_range(xfs_mount_t	*mp,
1569e6
 	return (XR_DFSBNORANGE_VALID);
1569e6
 }
1569e6
 
1569e6
-int
1569e6
-verify_agbno(xfs_mount_t	*mp,
1569e6
-		xfs_agnumber_t	agno,
1569e6
-		xfs_agblock_t	agbno)
1569e6
-{
1569e6
-	xfs_sb_t	*sbp = &mp->m_sb;;
1569e6
-
1569e6
-	/* range check ag #, ag block.  range-checking offset is pointless */
1569e6
-	return verify_ag_bno(sbp, agno, agbno) == 0;
1569e6
-}
1569e6
-
1569e6
 static int
1569e6
 process_rt_rec(
1569e6
 	xfs_mount_t		*mp,
1569e6
Index: xfsprogs-5.0.0/repair/dinode.h
1569e6
===================================================================
1569e6
--- xfsprogs-5.0.0.orig/repair/dinode.h
1569e6
+++ xfsprogs-5.0.0/repair/dinode.h
1569e6
@@ -10,11 +10,6 @@ struct blkmap;
1569e6
 struct prefetch_args;
1569e6
 
1569e6
 int
1569e6
-verify_agbno(xfs_mount_t	*mp,
1569e6
-		xfs_agnumber_t	agno,
1569e6
-		xfs_agblock_t	agbno);
1569e6
-
1569e6
-int
1569e6
 verify_dfsbno(xfs_mount_t	*mp,
1569e6
 		xfs_fsblock_t	fsbno);
1569e6
 
1569e6
Index: xfsprogs-5.0.0/repair/scan.c
1569e6
===================================================================
1569e6
--- xfsprogs-5.0.0.orig/repair/scan.c
1569e6
+++ xfsprogs-5.0.0/repair/scan.c
1569e6
@@ -642,14 +642,14 @@ _("%s freespace btree block claimed (sta
1569e6
 			len = be32_to_cpu(rp[i].ar_blockcount);
1569e6
 			end = b + len;
1569e6
 
1569e6
-			if (b == 0 || !verify_agbno(mp, agno, b)) {
1569e6
+			if (!libxfs_verify_agbno(mp, agno, b)) {
1569e6
 				do_warn(
1569e6
 	_("invalid start block %u in record %u of %s btree block %u/%u\n"),
1569e6
 					b, i, name, agno, bno);
1569e6
 				continue;
1569e6
 			}
1569e6
 			if (len == 0 || end <= b ||
1569e6
-			    !verify_agbno(mp, agno, end - 1)) {
1569e6
+			    !libxfs_verify_agbno(mp, agno, end - 1)) {
1569e6
 				do_warn(
1569e6
 	_("invalid length %u in record %u of %s btree block %u/%u\n"),
1569e6
 					len, i, name, agno, bno);
1569e6
@@ -914,6 +914,16 @@ rmap_in_order(
1569e6
 	return offset > lastoffset;
1569e6
 }
1569e6
 
1569e6
+static inline bool
1569e6
+verify_rmap_agbno(
1569e6
+	struct xfs_mount	*mp,
1569e6
+	xfs_agnumber_t		agno,
1569e6
+	xfs_agblock_t		agbno)
1569e6
+{
1569e6
+	return agbno < libxfs_ag_block_count(mp, agno);
1569e6
+}
1569e6
+
1569e6
+
1569e6
 static void
1569e6
 scan_rmapbt(
1569e6
 	struct xfs_btree_block	*block,
1569e6
@@ -1031,14 +1041,14 @@ _("%s rmap btree block claimed (state %d
1569e6
 			end = key.rm_startblock + key.rm_blockcount;
1569e6
 
1569e6
 			/* Make sure agbno & len make sense. */
1569e6
-			if (!verify_agbno(mp, agno, b)) {
1569e6
+			if (!verify_rmap_agbno(mp, agno, b)) {
1569e6
 				do_warn(
1569e6
 	_("invalid start block %u in record %u of %s btree block %u/%u\n"),
1569e6
 					b, i, name, agno, bno);
1569e6
 				continue;
1569e6
 			}
1569e6
 			if (len == 0 || end <= b ||
1569e6
-			    !verify_agbno(mp, agno, end - 1)) {
1569e6
+			    !verify_rmap_agbno(mp, agno, end - 1)) {
1569e6
 				do_warn(
1569e6
 	_("invalid length %u in record %u of %s btree block %u/%u\n"),
1569e6
 					len, i, name, agno, bno);
1569e6
@@ -1325,14 +1335,14 @@ _("leftover CoW extent has invalid start
1569e6
 			}
1569e6
 			end = agb + len;
1569e6
 
1569e6
-			if (!verify_agbno(mp, agno, agb)) {
1569e6
+			if (!libxfs_verify_agbno(mp, agno, agb)) {
1569e6
 				do_warn(
1569e6
 	_("invalid start block %u in record %u of %s btree block %u/%u\n"),
1569e6
 					b, i, name, agno, bno);
1569e6
 				continue;
1569e6
 			}
1569e6
 			if (len == 0 || end <= agb ||
1569e6
-			    !verify_agbno(mp, agno, end - 1)) {
1569e6
+			    !libxfs_verify_agbno(mp, agno, end - 1)) {
1569e6
 				do_warn(
1569e6
 	_("invalid length %u in record %u of %s btree block %u/%u\n"),
1569e6
 					len, i, name, agno, bno);
1569e6
@@ -2145,7 +2155,7 @@ scan_agfl(
1569e6
 {
1569e6
 	struct agfl_state	*as = priv;
1569e6
 
1569e6
-	if (verify_agbno(mp, as->agno, bno))
1569e6
+	if (libxfs_verify_agbno(mp, as->agno, bno))
1569e6
 		set_bmap(as->agno, bno, XR_E_FREE);
1569e6
 	else
1569e6
 		do_warn(_("bad agbno %u in agfl, agno %d\n"),
1569e6
@@ -2217,7 +2227,7 @@ validate_agf(
1569e6
 	uint32_t		magic;
1569e6
 
1569e6
 	bno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_BNO]);
1569e6
-	if (bno != 0 && verify_agbno(mp, agno, bno)) {
1569e6
+	if (libxfs_verify_agbno(mp, agno, bno)) {
1569e6
 		magic = xfs_sb_version_hascrc(&mp->m_sb) ? XFS_ABTB_CRC_MAGIC
1569e6
 							 : XFS_ABTB_MAGIC;
1569e6
 		scan_sbtree(bno, be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]),
1569e6
@@ -2229,7 +2239,7 @@ validate_agf(
1569e6
 	}
1569e6
 
1569e6
 	bno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_CNT]);
1569e6
-	if (bno != 0 && verify_agbno(mp, agno, bno)) {
1569e6
+	if (libxfs_verify_agbno(mp, agno, bno)) {
1569e6
 		magic = xfs_sb_version_hascrc(&mp->m_sb) ? XFS_ABTC_CRC_MAGIC
1569e6
 							 : XFS_ABTC_MAGIC;
1569e6
 		scan_sbtree(bno, be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]),
1569e6
@@ -2249,7 +2259,7 @@ validate_agf(
1569e6
 		priv.last_rec.rm_owner = XFS_RMAP_OWN_UNKNOWN;
1569e6
 		priv.nr_blocks = 0;
1569e6
 		bno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_RMAP]);
1569e6
-		if (bno != 0 && verify_agbno(mp, agno, bno)) {
1569e6
+		if (libxfs_verify_agbno(mp, agno, bno)) {
1569e6
 			scan_sbtree(bno,
1569e6
 				    be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]),
1569e6
 				    agno, 0, scan_rmapbt, 1, XFS_RMAP_CRC_MAGIC,
1569e6
@@ -2267,7 +2277,7 @@ validate_agf(
1569e6
 
1569e6
 	if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1569e6
 		bno = be32_to_cpu(agf->agf_refcount_root);
1569e6
-		if (bno != 0 && verify_agbno(mp, agno, bno)) {
1569e6
+		if (libxfs_verify_agbno(mp, agno, bno)) {
1569e6
 			struct refc_priv	priv;
1569e6
 
1569e6
 			memset(&priv, 0, sizeof(priv));
1569e6
@@ -2315,7 +2325,7 @@ validate_agi(
1569e6
 	uint32_t		magic;
1569e6
 
1569e6
 	bno = be32_to_cpu(agi->agi_root);
1569e6
-	if (bno != 0 && verify_agbno(mp, agno, bno)) {
1569e6
+	if (libxfs_verify_agbno(mp, agno, bno)) {
1569e6
 		magic = xfs_sb_version_hascrc(&mp->m_sb) ? XFS_IBT_CRC_MAGIC
1569e6
 							 : XFS_IBT_MAGIC;
1569e6
 		scan_sbtree(bno, be32_to_cpu(agi->agi_level),
1569e6
@@ -2328,7 +2338,7 @@ validate_agi(
1569e6
 
1569e6
 	if (xfs_sb_version_hasfinobt(&mp->m_sb)) {
1569e6
 		bno = be32_to_cpu(agi->agi_free_root);
1569e6
-		if (bno != 0 && verify_agbno(mp, agno, bno)) {
1569e6
+		if (libxfs_verify_agbno(mp, agno, bno)) {
1569e6
 			magic = xfs_sb_version_hascrc(&mp->m_sb) ?
1569e6
 					XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
1569e6
 			scan_sbtree(bno, be32_to_cpu(agi->agi_free_level),