]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/phase3.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>
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. */
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
;
74 action_list_init(&alist
);
75 agno
= cvt_ino_to_agno(&ctx
->mnt
, bstat
->bs_ino
);
78 /* Try to open the inode to pin it. */
79 if (S_ISREG(bstat
->bs_mode
)) {
80 fd
= scrub_open_handle(handle
);
81 /* Stale inode means we scan the whole cluster again. */
82 if (fd
< 0 && errno
== ESTALE
)
86 /* Scrub the inode. */
87 error
= scrub_fd(ctx
, xfs_scrub_inode_fields
, bstat
, &alist
);
91 error
= action_list_process_or_defer(ctx
, agno
, &alist
);
95 /* Scrub all block mappings. */
96 error
= scrub_fd(ctx
, xfs_scrub_data_fork
, bstat
, &alist
);
99 error
= scrub_fd(ctx
, xfs_scrub_attr_fork
, bstat
, &alist
);
102 error
= scrub_fd(ctx
, xfs_scrub_cow_fork
, bstat
, &alist
);
106 error
= action_list_process_or_defer(ctx
, agno
, &alist
);
110 if (S_ISLNK(bstat
->bs_mode
)) {
111 /* Check symlink contents. */
112 error
= xfs_scrub_symlink(ctx
, bstat
->bs_ino
, bstat
->bs_gen
,
114 } else if (S_ISDIR(bstat
->bs_mode
)) {
115 /* Check the directory entries. */
116 error
= scrub_fd(ctx
, xfs_scrub_dir
, bstat
, &alist
);
121 /* Check all the extended attributes. */
122 error
= scrub_fd(ctx
, xfs_scrub_attr
, bstat
, &alist
);
126 /* Check parent pointers. */
127 error
= scrub_fd(ctx
, xfs_scrub_parent
, bstat
, &alist
);
131 /* Try to repair the file while it's open. */
132 error
= action_list_process_or_defer(ctx
, agno
, &alist
);
138 ictx
->aborted
= true;
140 error
= ptcounter_add(icount
, 1);
142 str_liberror(ctx
, error
,
143 _("incrementing scanned inode counter"));
144 ictx
->aborted
= true;
147 action_list_defer(ctx
, agno
, &alist
);
153 report_close_error(ctx
, bstat
);
154 ictx
->aborted
= true;
158 if (!error
&& ictx
->aborted
)
163 /* Verify all the inodes in a filesystem. */
166 struct scrub_ctx
*ctx
)
168 struct scrub_inode_ctx ictx
= { NULL
};
172 err
= ptcounter_alloc(scrub_nproc(ctx
), &ictx
.icount
);
174 str_liberror(ctx
, err
, _("creating scanned inode counter"));
178 err
= scrub_scan_all_inodes(ctx
, scrub_inode
, &ictx
);
179 if (!err
&& ictx
.aborted
)
184 xfs_scrub_report_preen_triggers(ctx
);
185 err
= ptcounter_value(ictx
.icount
, &val
);
187 str_liberror(ctx
, err
, _("summing scanned inode counter"));
191 ctx
->inodes_checked
= val
;
193 ptcounter_free(ictx
.icount
);
197 /* Estimate how much work we're going to do. */
200 struct scrub_ctx
*ctx
,
202 unsigned int *nr_threads
,
205 *items
= ctx
->mnt_sv
.f_files
- ctx
->mnt_sv
.f_ffree
;
206 *nr_threads
= scrub_nproc(ctx
);