From: Darrick J. Wong Date: Fri, 1 Nov 2019 21:58:14 +0000 (-0400) Subject: xfs_scrub: refactor xfs_scrub_excessive_errors X-Git-Tag: v5.3.0-rc2~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=059215441a51dadb78afd0daed31c896bac22870;p=thirdparty%2Fxfsprogs-dev.git 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 --- 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 {