From 2e9720d51a1e9efa6535b540f3c9ff88e95aabe9 Mon Sep 17 00:00:00 2001
From: "Darrick J. Wong" <djwong@kernel.org>
Date: Wed, 27 Apr 2022 23:11:09 -0400
Subject: [PATCH] xfs_repair: fix AG header btree level comparisons

It's not an error if repair encounters a btree with the maximal
height, so don't print warnings.  Also, we don't allow zero-height
btrees.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
---
 repair/scan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/repair/scan.c b/repair/scan.c
index 909c449..e2d281a 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -2297,7 +2297,7 @@ validate_agf(
 		priv.nr_blocks = 0;
 
 		levels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]);
-		if (levels >= XFS_BTREE_MAXLEVELS) {
+		if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) {
 			do_warn(_("bad levels %u for rmapbt root, agno %d\n"),
 				levels, agno);
 			rmap_avoid_check();
@@ -2323,7 +2323,7 @@ validate_agf(
 		unsigned int	levels;
 
 		levels = be32_to_cpu(agf->agf_refcount_level);
-		if (levels >= XFS_BTREE_MAXLEVELS) {
+		if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) {
 			do_warn(_("bad levels %u for refcountbt root, agno %d\n"),
 				levels, agno);
 			refcount_avoid_check();
-- 
1.8.3.1

