]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/phase3.c
b35ef164be7eb5855d4675120ad3808d27cfdc2d
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
9 #include <sys/statvfs.h>
11 #include "libfrog/paths.h"
12 #include "libfrog/workqueue.h"
13 #include "xfs_scrub.h"
21 /* Phase 3: Scan all inodes. */
24 * Run a per-file metadata scanner. We use the ino/gen interface to
25 * ensure that the inode we're checking matches what the inode scan
30 struct scrub_ctx
*ctx
,
31 int (*fn
)(struct scrub_ctx
*ctx
, uint64_t ino
,
32 uint32_t gen
, struct action_list
*a
),
33 struct xfs_bulkstat
*bs
,
34 struct action_list
*alist
)
36 return fn(ctx
, bs
->bs_ino
, bs
->bs_gen
, alist
);
39 struct scrub_inode_ctx
{
40 struct ptcounter
*icount
;
44 /* Report a filesystem error that the vfs fed us on close. */
46 xfs_scrub_inode_vfs_error(
47 struct scrub_ctx
*ctx
,
48 struct xfs_bulkstat
*bstat
)
50 char descr
[DESCR_BUFSZ
];
51 int old_errno
= errno
;
53 scrub_render_ino_descr(ctx
, descr
, DESCR_BUFSZ
, bstat
->bs_ino
,
56 str_errno(ctx
, descr
);
59 /* Verify the contents, xattrs, and extent maps of an inode. */
62 struct scrub_ctx
*ctx
,
63 struct xfs_handle
*handle
,
64 struct xfs_bulkstat
*bstat
,
67 struct action_list alist
;
68 struct scrub_inode_ctx
*ictx
= arg
;
69 struct ptcounter
*icount
= ictx
->icount
;
75 action_list_init(&alist
);
76 agno
= cvt_ino_to_agno(&ctx
->mnt
, bstat
->bs_ino
);
79 /* Try to open the inode to pin it. */
80 if (S_ISREG(bstat
->bs_mode
)) {
81 fd
= scrub_open_handle(handle
);
82 /* Stale inode means we scan the whole cluster again. */
83 if (fd
< 0 && errno
== ESTALE
)
87 /* Scrub the inode. */
88 error
= scrub_fd(ctx
, xfs_scrub_inode_fields
, bstat
, &alist
);
92 error
= action_list_process_or_defer(ctx
, agno
, &alist
);
96 /* Scrub all block mappings. */
97 error
= scrub_fd(ctx
, xfs_scrub_data_fork
, bstat
, &alist
);
100 error
= scrub_fd(ctx
, xfs_scrub_attr_fork
, bstat
, &alist
);
103 error
= scrub_fd(ctx
, xfs_scrub_cow_fork
, bstat
, &alist
);
107 error
= action_list_process_or_defer(ctx
, agno
, &alist
);
111 if (S_ISLNK(bstat
->bs_mode
)) {
112 /* Check symlink contents. */
113 error
= xfs_scrub_symlink(ctx
, bstat
->bs_ino
, bstat
->bs_gen
,
115 } else if (S_ISDIR(bstat
->bs_mode
)) {
116 /* Check the directory entries. */
117 error
= scrub_fd(ctx
, xfs_scrub_dir
, bstat
, &alist
);
122 /* Check all the extended attributes. */
123 error
= scrub_fd(ctx
, xfs_scrub_attr
, bstat
, &alist
);
127 /* Check parent pointers. */
128 error
= scrub_fd(ctx
, xfs_scrub_parent
, bstat
, &alist
);
132 /* Try to repair the file while it's open. */
133 error
= action_list_process_or_defer(ctx
, agno
, &alist
);
140 error
= ptcounter_add(icount
, 1);
142 str_liberror(ctx
, error
,
143 _("incrementing scanned inode counter"));
147 action_list_defer(ctx
, agno
, &alist
);
151 xfs_scrub_inode_vfs_error(ctx
, bstat
);
154 ictx
->moveon
= false;
155 return ictx
->moveon
? 0 : XFS_ITERATE_INODES_ABORT
;
158 /* Verify all the inodes in a filesystem. */
161 struct scrub_ctx
*ctx
)
163 struct scrub_inode_ctx ictx
;
168 err
= ptcounter_alloc(scrub_nproc(ctx
), &ictx
.icount
);
170 str_liberror(ctx
, err
, _("creating scanned inode counter"));
174 err
= scrub_scan_all_inodes(ctx
, xfs_scrub_inode
, &ictx
);
179 xfs_scrub_report_preen_triggers(ctx
);
180 err
= ptcounter_value(ictx
.icount
, &val
);
182 str_liberror(ctx
, err
, _("summing scanned inode counter"));
185 ctx
->inodes_checked
= val
;
187 ptcounter_free(ictx
.icount
);
191 /* Estimate how much work we're going to do. */
193 xfs_estimate_inodes_work(
194 struct scrub_ctx
*ctx
,
196 unsigned int *nr_threads
,
199 *items
= ctx
->mnt_sv
.f_files
- ctx
->mnt_sv
.f_ffree
;
200 *nr_threads
= scrub_nproc(ctx
);