]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/phase2.c
xfs_scrub: remove moveon from repair action list helpers
[thirdparty/xfsprogs-dev.git] / scrub / phase2.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 <sys/types.h>
9 #include <sys/statvfs.h>
10 #include "list.h"
11 #include "libfrog/paths.h"
12 #include "libfrog/workqueue.h"
13 #include "xfs_scrub.h"
14 #include "common.h"
15 #include "scrub.h"
16 #include "repair.h"
17
18 /* Phase 2: Check internal metadata. */
19
20 /* Scrub each AG's metadata btrees. */
21 static void
22 xfs_scan_ag_metadata(
23 struct workqueue *wq,
24 xfs_agnumber_t agno,
25 void *arg)
26 {
27 struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx;
28 bool *pmoveon = arg;
29 struct action_list alist;
30 struct action_list immediate_alist;
31 unsigned long long broken_primaries;
32 unsigned long long broken_secondaries;
33 char descr[DESCR_BUFSZ];
34 int ret;
35
36 action_list_init(&alist);
37 action_list_init(&immediate_alist);
38 snprintf(descr, DESCR_BUFSZ, _("AG %u"), agno);
39
40 /*
41 * First we scrub and fix the AG headers, because we need
42 * them to work well enough to check the AG btrees.
43 */
44 ret = xfs_scrub_ag_headers(ctx, agno, &alist);
45 if (ret)
46 goto err;
47
48 /* Repair header damage. */
49 ret = action_list_process_or_defer(ctx, agno, &alist);
50 if (ret)
51 goto err;
52
53 /* Now scrub the AG btrees. */
54 ret = xfs_scrub_ag_metadata(ctx, agno, &alist);
55 if (ret)
56 goto err;
57
58 /*
59 * Figure out if we need to perform early fixing. The only
60 * reason we need to do this is if the inobt is broken, which
61 * prevents phase 3 (inode scan) from running. We can rebuild
62 * the inobt from rmapbt data, but if the rmapbt is broken even
63 * at this early phase then we are sunk.
64 */
65 broken_secondaries = 0;
66 broken_primaries = 0;
67 action_list_find_mustfix(&alist, &immediate_alist,
68 &broken_primaries, &broken_secondaries);
69 if (broken_secondaries && !debug_tweak_on("XFS_SCRUB_FORCE_REPAIR")) {
70 if (broken_primaries)
71 str_info(ctx, descr,
72 _("Corrupt primary and secondary block mapping metadata."));
73 else
74 str_info(ctx, descr,
75 _("Corrupt secondary block mapping metadata."));
76 str_info(ctx, descr,
77 _("Filesystem might not be repairable."));
78 }
79
80 /* Repair (inode) btree damage. */
81 ret = action_list_process_or_defer(ctx, agno, &immediate_alist);
82 if (ret)
83 goto err;
84
85 /* Everything else gets fixed during phase 4. */
86 action_list_defer(ctx, agno, &alist);
87
88 return;
89 err:
90 *pmoveon = false;
91 }
92
93 /* Scrub whole-FS metadata btrees. */
94 static void
95 xfs_scan_fs_metadata(
96 struct workqueue *wq,
97 xfs_agnumber_t agno,
98 void *arg)
99 {
100 struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx;
101 bool *pmoveon = arg;
102 struct action_list alist;
103 int ret;
104
105 action_list_init(&alist);
106 ret = xfs_scrub_fs_metadata(ctx, &alist);
107 if (ret)
108 *pmoveon = false;
109
110 action_list_defer(ctx, agno, &alist);
111 }
112
113 /* Scan all filesystem metadata. */
114 bool
115 xfs_scan_metadata(
116 struct scrub_ctx *ctx)
117 {
118 struct action_list alist;
119 struct workqueue wq;
120 xfs_agnumber_t agno;
121 bool moveon = true;
122 int ret;
123
124 ret = workqueue_create(&wq, (struct xfs_mount *)ctx,
125 scrub_nproc_workqueue(ctx));
126 if (ret) {
127 str_liberror(ctx, ret, _("creating scrub workqueue"));
128 return false;
129 }
130
131 /*
132 * In case we ever use the primary super scrubber to perform fs
133 * upgrades (followed by a full scrub), do that before we launch
134 * anything else.
135 */
136 action_list_init(&alist);
137 ret = xfs_scrub_primary_super(ctx, &alist);
138 if (ret) {
139 moveon = false;
140 goto out;
141 }
142 ret = action_list_process_or_defer(ctx, 0, &alist);
143 if (ret) {
144 moveon = false;
145 goto out;
146 }
147
148 for (agno = 0; moveon && agno < ctx->mnt.fsgeom.agcount; agno++) {
149 ret = workqueue_add(&wq, xfs_scan_ag_metadata, agno, &moveon);
150 if (ret) {
151 moveon = false;
152 str_liberror(ctx, ret, _("queueing per-AG scrub work"));
153 goto out;
154 }
155 }
156
157 if (!moveon)
158 goto out;
159
160 ret = workqueue_add(&wq, xfs_scan_fs_metadata, 0, &moveon);
161 if (ret) {
162 moveon = false;
163 str_liberror(ctx, ret, _("queueing per-FS scrub work"));
164 goto out;
165 }
166
167 out:
168 ret = workqueue_terminate(&wq);
169 if (ret) {
170 moveon = false;
171 str_liberror(ctx, ret, _("finishing scrub work"));
172 }
173 workqueue_destroy(&wq);
174 return moveon;
175 }
176
177 /* Estimate how much work we're going to do. */
178 bool
179 xfs_estimate_metadata_work(
180 struct scrub_ctx *ctx,
181 uint64_t *items,
182 unsigned int *nr_threads,
183 int *rshift)
184 {
185 *items = scrub_estimate_ag_work(ctx);
186 *nr_threads = scrub_nproc(ctx);
187 *rshift = 0;
188 return true;
189 }