]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: refactor xfs_scrub_excessive_errors
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 1 Nov 2019 21:58:14 +0000 (17:58 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 1 Nov 2019 21:58:14 +0000 (17:58 -0400)
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 <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
[sandeen: don't check unsigned max_errors for < 0]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
scrub/common.c

index 26756c58019d1f6bf38ce52d7ca1aba8c350cfb3..32ef8cd29718fdee11fca15ad52ea4727e3aa233 100644 (file)
@@ -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 {