From 059215441a51dadb78afd0daed31c896bac22870 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Fri, 1 Nov 2019 17:58:14 -0400 Subject: [PATCH] xfs_scrub: refactor xfs_scrub_excessive_errors Refactor this helper to avoid cycling the scrub context lock when the user hasn't configured a maximum error count threshold. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen [sandeen: don't check unsigned max_errors for < 0] Signed-off-by: Eric Sandeen --- scrub/common.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scrub/common.c b/scrub/common.c index 26756c580..32ef8cd29 100644 --- a/scrub/common.c +++ b/scrub/common.c @@ -33,13 +33,20 @@ bool xfs_scrub_excessive_errors( struct scrub_ctx *ctx) { - bool ret; + unsigned long long errors_seen; + + /* + * We only set max_errors at the start of the program, so it's safe to + * access it locklessly. + */ + if (ctx->max_errors == 0) + return false; pthread_mutex_lock(&ctx->lock); - ret = ctx->max_errors > 0 && ctx->corruptions_found >= ctx->max_errors; + errors_seen = ctx->corruptions_found; pthread_mutex_unlock(&ctx->lock); - return ret; + return errors_seen >= ctx->max_errors; } static struct { -- 2.47.2