]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: make phase 4 go straight to fstrim if nothing to fix
authorDarrick J. Wong <djwong@kernel.org>
Wed, 18 May 2022 02:48:13 +0000 (22:48 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Wed, 18 May 2022 02:48:13 +0000 (22:48 -0400)
If there's nothing to repair in phase 4, there's no need to hold up the
FITRIM call to do the summary count scan that prepares us to repair
filesystem metadata.  Rearrange this a bit.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[sandeen: fix unfixable_errors test logic thinko]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
scrub/phase4.c

index 6ed7210fcd544c304f7005de592afaf32a3b738e..4fd1cb799a4619dd6804107560b82a382074c71d 100644 (file)
@@ -95,15 +95,32 @@ repair_everything(
        if (aborted)
                return ECANCELED;
 
-       pthread_mutex_lock(&ctx->lock);
-       if (ctx->corruptions_found == 0 && ctx->unfixable_errors == 0 &&
-           want_fstrim) {
-               fstrim(ctx);
-               progress_add(1);
+       return 0;
+}
+
+/* Decide if we have any repair work to do. */
+static inline bool
+have_action_items(
+       struct scrub_ctx        *ctx)
+{
+       xfs_agnumber_t          agno;
+
+       for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++) {
+               if (action_list_length(&ctx->action_lists[agno]) > 0)
+                       return true;
        }
-       pthread_mutex_unlock(&ctx->lock);
 
-       return 0;
+       return false;
+}
+
+/* Trim the unused areas of the filesystem if the caller asked us to. */
+static void
+trim_filesystem(
+       struct scrub_ctx        *ctx)
+{
+       if (want_fstrim)
+               fstrim(ctx);
+       progress_add(1);
 }
 
 /* Fix everything that needs fixing. */
@@ -113,6 +130,9 @@ phase4_func(
 {
        int                     ret;
 
+       if (!have_action_items(ctx))
+               goto maybe_trim;
+
        /*
         * Check the summary counters early.  Normally we do this during phase
         * seven, but some of the cross-referencing requires fairly-accurate
@@ -123,7 +143,20 @@ phase4_func(
        if (ret)
                return ret;
 
-       return repair_everything(ctx);
+       ret = repair_everything(ctx);
+       if (ret)
+               return ret;
+
+       /*
+        * If errors remain on the filesystem, do not trim anything.  We don't
+        * have any threads running, so it's ok to skip the ctx lock here.
+        */
+       if (ctx->corruptions_found || ctx->unfixable_errors != 0)
+               return 0;
+
+maybe_trim:
+       trim_filesystem(ctx);
+       return 0;
 }
 
 /* Estimate how much work we're going to do. */