]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: move FITRIM to phase 8
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:23:11 +0000 (16:23 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:09 +0000 (17:01 -0700)
Issuing discards against the filesystem should be the *last* thing that
xfs_scrub does, after everything else has been checked, repaired, and
found to be clean.  If we can't satisfy all those conditions, we have no
business telling the storage to discard itself.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
scrub/Makefile
scrub/phase4.c
scrub/phase8.c [new file with mode: 0644]
scrub/xfs_scrub.h

index c11c2b5fe84e4520a8bd2c1cb09270155a310eba..8ccc67d01df353cb46fe57a8578d4fc8641e94c7 100644 (file)
@@ -68,6 +68,7 @@ phase4.c \
 phase5.c \
 phase6.c \
 phase7.c \
+phase8.c \
 progress.c \
 read_verify.c \
 repair.c \
index 9080d38818f7e426a58563230d295e29a76a99ce..451101811c9bb7b9cb7f2043adc991214f2095dd 100644 (file)
@@ -227,16 +227,6 @@ repair_everything(
        return action_list_process(ctx, ctx->fs_repair_list, XRM_FINAL_WARNING);
 }
 
-/* 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. */
 int
 phase4_func(
@@ -248,7 +238,7 @@ phase4_func(
 
        if (action_list_empty(ctx->fs_repair_list) &&
            action_list_empty(ctx->file_repair_list))
-               goto maybe_trim;
+               return 0;
 
        /*
         * Check the resource usage counters early.  Normally we do this during
@@ -281,20 +271,7 @@ phase4_func(
        if (ret)
                return ret;
 
-       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;
+       return repair_everything(ctx);
 }
 
 /* Estimate how much work we're going to do. */
@@ -307,10 +284,9 @@ phase4_estimate(
 {
        unsigned long long      need_fixing;
 
-       /* Everything on the repair list plus FSTRIM. */
+       /* Everything on the repair lis. */
        need_fixing = action_list_length(ctx->fs_repair_list) +
                      action_list_length(ctx->file_repair_list);
-       need_fixing++;
 
        *items = need_fixing;
        *nr_threads = scrub_nproc(ctx) + 1;
diff --git a/scrub/phase8.c b/scrub/phase8.c
new file mode 100644 (file)
index 0000000..07726b5
--- /dev/null
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018-2024 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#include "xfs.h"
+#include <stdint.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/statvfs.h>
+#include "list.h"
+#include "libfrog/paths.h"
+#include "libfrog/workqueue.h"
+#include "xfs_scrub.h"
+#include "common.h"
+#include "progress.h"
+#include "scrub.h"
+#include "repair.h"
+#include "vfs.h"
+#include "atomic.h"
+
+/* Phase 8: Trim filesystem. */
+
+/* Trim the unused areas of the filesystem if the caller asked us to. */
+static void
+trim_filesystem(
+       struct scrub_ctx        *ctx)
+{
+       fstrim(ctx);
+       progress_add(1);
+}
+
+/* Trim the filesystem, if desired. */
+int
+phase8_func(
+       struct scrub_ctx        *ctx)
+{
+       if (action_list_empty(ctx->fs_repair_list) &&
+           action_list_empty(ctx->file_repair_list))
+               goto maybe_trim;
+
+       /*
+        * 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. */
+int
+phase8_estimate(
+       struct scrub_ctx        *ctx,
+       uint64_t                *items,
+       unsigned int            *nr_threads,
+       int                     *rshift)
+{
+       *items = 1;
+       *nr_threads = 1;
+       *rshift = 0;
+       return 0;
+}
index ed86d0093db3f681eda01b3d2b710c0255fd0d24..6272a36879e7f1cccea020c6b5d884bf0ef63250 100644 (file)
@@ -98,6 +98,7 @@ int phase4_func(struct scrub_ctx *ctx);
 int phase5_func(struct scrub_ctx *ctx);
 int phase6_func(struct scrub_ctx *ctx);
 int phase7_func(struct scrub_ctx *ctx);
+int phase8_func(struct scrub_ctx *ctx);
 
 /* Progress estimator functions */
 unsigned int scrub_estimate_ag_work(struct scrub_ctx *ctx);
@@ -112,5 +113,7 @@ int phase5_estimate(struct scrub_ctx *ctx, uint64_t *items,
                    unsigned int *nr_threads, int *rshift);
 int phase6_estimate(struct scrub_ctx *ctx, uint64_t *items,
                    unsigned int *nr_threads, int *rshift);
+int phase8_estimate(struct scrub_ctx *ctx, uint64_t *items,
+                   unsigned int *nr_threads, int *rshift);
 
 #endif /* XFS_SCRUB_XFS_SCRUB_H_ */