]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/phase4.c
xfs_scrub: remove moveon from scrub ioctl wrappers
[thirdparty/xfsprogs-dev.git] / scrub / phase4.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 */
6 #include "xfs.h"
7 #include <stdint.h>
8 #include <dirent.h>
9 #include <sys/types.h>
10 #include <sys/statvfs.h>
11 #include "list.h"
12 #include "libfrog/paths.h"
13 #include "libfrog/workqueue.h"
14 #include "xfs_scrub.h"
15 #include "common.h"
16 #include "progress.h"
17 #include "scrub.h"
18 #include "repair.h"
19 #include "vfs.h"
20
21 /* Phase 4: Repair filesystem. */
22
23 /* Fix all the problems in our per-AG list. */
24 static void
25 xfs_repair_ag(
26 struct workqueue *wq,
27 xfs_agnumber_t agno,
28 void *priv)
29 {
30 struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx;
31 bool *pmoveon = priv;
32 struct xfs_action_list *alist;
33 size_t unfixed;
34 size_t new_unfixed;
35 unsigned int flags = 0;
36 bool moveon;
37
38 alist = &ctx->action_lists[agno];
39 unfixed = xfs_action_list_length(alist);
40
41 /* Repair anything broken until we fail to make progress. */
42 do {
43 moveon = xfs_action_list_process(ctx, ctx->mnt.fd, alist, flags);
44 if (!moveon) {
45 *pmoveon = false;
46 return;
47 }
48 new_unfixed = xfs_action_list_length(alist);
49 if (new_unfixed == unfixed)
50 break;
51 unfixed = new_unfixed;
52 } while (unfixed > 0 && *pmoveon);
53
54 if (!*pmoveon)
55 return;
56
57 /* Try once more, but this time complain if we can't fix things. */
58 flags |= ALP_COMPLAIN_IF_UNFIXED;
59 moveon = xfs_action_list_process(ctx, ctx->mnt.fd, alist, flags);
60 if (!moveon)
61 *pmoveon = false;
62 }
63
64 /* Process all the action items. */
65 static bool
66 xfs_process_action_items(
67 struct scrub_ctx *ctx)
68 {
69 struct workqueue wq;
70 xfs_agnumber_t agno;
71 bool moveon = true;
72 int ret;
73
74 ret = workqueue_create(&wq, (struct xfs_mount *)ctx,
75 scrub_nproc_workqueue(ctx));
76 if (ret) {
77 str_liberror(ctx, ret, _("creating repair workqueue"));
78 return false;
79 }
80 for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++) {
81 if (xfs_action_list_length(&ctx->action_lists[agno]) > 0) {
82 ret = workqueue_add(&wq, xfs_repair_ag, agno, &moveon);
83 if (ret) {
84 moveon = false;
85 str_liberror(ctx, ret,
86 _("queueing repair work"));
87 break;
88 }
89 }
90 if (!moveon)
91 break;
92 }
93
94 ret = workqueue_terminate(&wq);
95 if (ret) {
96 moveon = false;
97 str_liberror(ctx, ret, _("finishing repair work"));
98 }
99 workqueue_destroy(&wq);
100
101 pthread_mutex_lock(&ctx->lock);
102 if (moveon &&
103 ctx->corruptions_found == 0 &&
104 ctx->unfixable_errors == 0 &&
105 want_fstrim) {
106 fstrim(ctx);
107 progress_add(1);
108 }
109 pthread_mutex_unlock(&ctx->lock);
110
111 return moveon;
112 }
113
114 /* Fix everything that needs fixing. */
115 bool
116 xfs_repair_fs(
117 struct scrub_ctx *ctx)
118 {
119 int ret;
120
121 /*
122 * Check the summary counters early. Normally we do this during phase
123 * seven, but some of the cross-referencing requires fairly-accurate
124 * counters, so counter repairs have to be put on the list now so that
125 * they get fixed before we stop retrying unfixed metadata repairs.
126 */
127 ret = xfs_scrub_fs_summary(ctx, &ctx->action_lists[0]);
128 if (ret)
129 return false;
130
131 return xfs_process_action_items(ctx);
132 }
133
134 /* Estimate how much work we're going to do. */
135 bool
136 xfs_estimate_repair_work(
137 struct scrub_ctx *ctx,
138 uint64_t *items,
139 unsigned int *nr_threads,
140 int *rshift)
141 {
142 xfs_agnumber_t agno;
143 size_t need_fixing = 0;
144
145 for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++)
146 need_fixing += xfs_action_list_length(&ctx->action_lists[agno]);
147 need_fixing++;
148 *items = need_fixing;
149 *nr_threads = scrub_nproc(ctx) + 1;
150 *rshift = 0;
151 return true;
152 }