[PATCH 3/5] xfs_db: report ranges of invalid rt blocks

Darrick J. Wong
2020-10-26T23:32:16Z

From: Darrick J. Wong <darrick.wong@oracle.com>

Copy-pasta the block range reporting code from check_range into
check_rrange so that we don't flood stdout with a ton of low value
messages when a bit flips somewhere in rt metadata.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
db/check.c | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/db/check.c b/db/check.c
index 553249dc9a41..5aede6cca15c 100644
--- a/db/check.c
+++ b/db/check.c
@@ -1569,19 +1569,46 @@ check_rootdir(void)
}
}

+static inline void
+report_rrange(
+ xfs_rfsblock_t low,
+ xfs_rfsblock_t high)
+{
+ if (low == high)
+ dbprintf(_("rtblock %llu out of range\n"), low);
+ else
+ dbprintf(_("rtblocks %llu..%llu out of range\n"), low, high);
+}
+
static int
check_rrange(
xfs_rfsblock_t bno,
xfs_extlen_t len)
{
xfs_extlen_t i;
+ xfs_rfsblock_t low = 0;
+ xfs_rfsblock_t high = 0;
+ bool valid_range = false;
+ int cur, prev = 0;

if (bno + len - 1 >= mp->m_sb.sb_rblocks) {
for (i = 0; i < len; i++) {
- if (!sflag || CHECK_BLIST(bno + i))
- dbprintf(_("rtblock %llu out of range\n"),
- bno + i);
+ cur = !sflag || CHECK_BLIST(bno + i) ? 1 : 0;
+ if (cur == 1 && prev == 0) {
+ low = high = bno + i;
+ valid_range = true;
+ } else if (cur == 0 && prev == 0) {
+ /* Do nothing */
+ } else if (cur == 0 && prev == 1) {
+ report_rrange(low, high);
+ valid_range = false;
+ } else if (cur == 1 && prev == 1) {
+ high = bno + i;
+ }
+ prev = cur;
}
+ if (valid_range)
+ report_rrange(low, high);
error++;
return 0;
}