]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/phase2.c
libfrog: fix workqueue error communication problems
[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 xfs_action_list alist;
30 struct xfs_action_list immediate_alist;
31 unsigned long long broken_primaries;
32 unsigned long long broken_secondaries;
33 bool moveon;
34 char descr[DESCR_BUFSZ];
35
36 xfs_action_list_init(&alist);
37 xfs_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 moveon = xfs_scrub_ag_headers(ctx, agno, &alist);
45 if (!moveon)
46 goto err;
47
48 /* Repair header damage. */
49 moveon = xfs_action_list_process_or_defer(ctx, agno, &alist);
50 if (!moveon)
51 goto err;
52
53 /* Now scrub the AG btrees. */
54 moveon = xfs_scrub_ag_metadata(ctx, agno, &alist);
55 if (!moveon)
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 xfs_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 moveon = xfs_action_list_process_or_defer(ctx, agno, &immediate_alist);
82 if (!moveon)
83 goto err;
84
85 /* Everything else gets fixed during phase 4. */
86 xfs_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 xfs_action_list alist;
103 bool moveon;
104
105 xfs_action_list_init(&alist);
106 moveon = xfs_scrub_fs_metadata(ctx, &alist);
107 if (!moveon)
108 *pmoveon = false;
109
110 xfs_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 xfs_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 xfs_action_list_init(&alist);
137 moveon = xfs_scrub_primary_super(ctx, &alist);
138 if (!moveon)
139 goto out;
140 moveon = xfs_action_list_process_or_defer(ctx, 0, &alist);
141 if (!moveon)
142 goto out;
143
144 for (agno = 0; moveon && agno < ctx->mnt.fsgeom.agcount; agno++) {
145 ret = workqueue_add(&wq, xfs_scan_ag_metadata, agno, &moveon);
146 if (ret) {
147 moveon = false;
148 str_liberror(ctx, ret, _("queueing per-AG scrub work"));
149 goto out;
150 }
151 }
152
153 if (!moveon)
154 goto out;
155
156 ret = workqueue_add(&wq, xfs_scan_fs_metadata, 0, &moveon);
157 if (ret) {
158 moveon = false;
159 str_liberror(ctx, ret, _("queueing per-FS scrub work"));
160 goto out;
161 }
162
163 out:
164 workqueue_destroy(&wq);
165 return moveon;
166 }
167
168 /* Estimate how much work we're going to do. */
169 bool
170 xfs_estimate_metadata_work(
171 struct scrub_ctx *ctx,
172 uint64_t *items,
173 unsigned int *nr_threads,
174 int *rshift)
175 {
176 *items = xfs_scrub_estimate_ag_work(ctx);
177 *nr_threads = scrub_nproc(ctx);
178 *rshift = 0;
179 return true;
180 }