]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/phase4.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
10 #include <sys/statvfs.h>
12 #include "libfrog/paths.h"
13 #include "libfrog/workqueue.h"
14 #include "xfs_scrub.h"
21 /* Phase 4: Repair filesystem. */
23 /* Fix all the problems in our per-AG list. */
30 struct scrub_ctx
*ctx
= (struct scrub_ctx
*)wq
->wq_ctx
;
32 struct xfs_action_list
*alist
;
35 unsigned int flags
= 0;
38 alist
= &ctx
->action_lists
[agno
];
39 unfixed
= xfs_action_list_length(alist
);
41 /* Repair anything broken until we fail to make progress. */
43 moveon
= xfs_action_list_process(ctx
, ctx
->mnt
.fd
, alist
, flags
);
48 new_unfixed
= xfs_action_list_length(alist
);
49 if (new_unfixed
== unfixed
)
51 unfixed
= new_unfixed
;
52 } while (unfixed
> 0 && *pmoveon
);
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
);
64 /* Process all the action items. */
66 xfs_process_action_items(
67 struct scrub_ctx
*ctx
)
74 ret
= workqueue_create(&wq
, (struct xfs_mount
*)ctx
,
75 scrub_nproc_workqueue(ctx
));
77 str_liberror(ctx
, ret
, _("creating repair workqueue"));
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
);
85 str_liberror(ctx
, ret
,
86 _("queueing repair work"));
94 ret
= workqueue_terminate(&wq
);
97 str_liberror(ctx
, ret
, _("finishing repair work"));
99 workqueue_destroy(&wq
);
101 pthread_mutex_lock(&ctx
->lock
);
103 ctx
->corruptions_found
== 0 &&
104 ctx
->unfixable_errors
== 0 &&
109 pthread_mutex_unlock(&ctx
->lock
);
114 /* Fix everything that needs fixing. */
117 struct scrub_ctx
*ctx
)
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.
127 ret
= xfs_scrub_fs_summary(ctx
, &ctx
->action_lists
[0]);
131 return xfs_process_action_items(ctx
);
134 /* Estimate how much work we're going to do. */
136 xfs_estimate_repair_work(
137 struct scrub_ctx
*ctx
,
139 unsigned int *nr_threads
,
143 size_t need_fixing
= 0;
145 for (agno
= 0; agno
< ctx
->mnt
.fsgeom
.agcount
; agno
++)
146 need_fixing
+= xfs_action_list_length(&ctx
->action_lists
[agno
]);
148 *items
= need_fixing
;
149 *nr_threads
= scrub_nproc(ctx
) + 1;