diff mbox series

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

Message ID 160375513208.879169.14762082637245127153.stgit@magnolia (mailing list archive)
State Superseded, archived
Headers show
Series xfsprogs: fixes for 5.10 | expand

Commit Message

Darrick J. Wong Oct. 26, 2020, 11:32 p.m. UTC
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(-)

Comments

Allison Henderson Oct. 27, 2020, 5:35 a.m. UTC | #1
On 10/26/20 4:32 PM, Darrick J. Wong wrote:
> 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.
> 
Ok, makes sense
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
> 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;
>   	}
>
Christoph Hellwig Oct. 28, 2020, 7:33 a.m. UTC | #2
On Mon, Oct 26, 2020 at 04:32:12PM -0700, Darrick J. Wong wrote:
> 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>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

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;
 	}