]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/phase4.c
xfs_scrub: progress indicator
[thirdparty/xfsprogs-dev.git] / scrub / phase4.c
1 /*
2 * Copyright (C) 2018 Oracle. All Rights Reserved.
3 *
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <dirent.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <sys/statvfs.h>
27 #include "xfs.h"
28 #include "xfs_fs.h"
29 #include "list.h"
30 #include "path.h"
31 #include "workqueue.h"
32 #include "xfs_scrub.h"
33 #include "common.h"
34 #include "progress.h"
35 #include "scrub.h"
36 #include "vfs.h"
37
38 /* Phase 4: Repair filesystem. */
39
40 /* Process all the action items. */
41 static bool
42 xfs_process_action_items(
43 struct scrub_ctx *ctx)
44 {
45 bool moveon = true;
46
47 pthread_mutex_lock(&ctx->lock);
48 if (moveon && ctx->errors_found == 0 && want_fstrim) {
49 fstrim(ctx);
50 progress_add(1);
51 }
52 pthread_mutex_unlock(&ctx->lock);
53
54 return moveon;
55 }
56
57 /* Fix everything that needs fixing. */
58 bool
59 xfs_repair_fs(
60 struct scrub_ctx *ctx)
61 {
62 return xfs_process_action_items(ctx);
63 }
64
65 /* Run the optimize-only phase if there are no errors. */
66 bool
67 xfs_optimize_fs(
68 struct scrub_ctx *ctx)
69 {
70 /*
71 * In preen mode, corruptions are immediately recorded as errors,
72 * so if there are any corruptions on the filesystem errors_found
73 * will be non-zero and we won't do anything.
74 */
75 if (ctx->errors_found) {
76 str_info(ctx, ctx->mntpoint,
77 _("Errors found, please re-run with -y."));
78 return true;
79 }
80
81 return xfs_process_action_items(ctx);
82 }
83
84 /* Estimate how much work we're going to do. */
85 bool
86 xfs_estimate_repair_work(
87 struct scrub_ctx *ctx,
88 uint64_t *items,
89 unsigned int *nr_threads,
90 int *rshift)
91 {
92 *items = 1;
93 *nr_threads = 1;
94 *rshift = 0;
95 return true;
96 }