]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame_incremental - fs/xfs/scrub/common.h
Merge tag 'xfs-5.15-merge-6' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[mirror_ubuntu-jammy-kernel.git] / fs / xfs / scrub / common.h
... / ...
CommitLineData
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2017 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 */
6#ifndef __XFS_SCRUB_COMMON_H__
7#define __XFS_SCRUB_COMMON_H__
8
9/*
10 * We /could/ terminate a scrub/repair operation early. If we're not
11 * in a good place to continue (fatal signal, etc.) then bail out.
12 * Note that we're careful not to make any judgements about *error.
13 */
14static inline bool
15xchk_should_terminate(
16 struct xfs_scrub *sc,
17 int *error)
18{
19 /*
20 * If preemption is disabled, we need to yield to the scheduler every
21 * few seconds so that we don't run afoul of the soft lockup watchdog
22 * or RCU stall detector.
23 */
24 cond_resched();
25
26 if (fatal_signal_pending(current)) {
27 if (*error == 0)
28 *error = -EAGAIN;
29 return true;
30 }
31 return false;
32}
33
34int xchk_trans_alloc(struct xfs_scrub *sc, uint resblks);
35bool xchk_process_error(struct xfs_scrub *sc, xfs_agnumber_t agno,
36 xfs_agblock_t bno, int *error);
37bool xchk_fblock_process_error(struct xfs_scrub *sc, int whichfork,
38 xfs_fileoff_t offset, int *error);
39
40bool xchk_xref_process_error(struct xfs_scrub *sc,
41 xfs_agnumber_t agno, xfs_agblock_t bno, int *error);
42bool xchk_fblock_xref_process_error(struct xfs_scrub *sc,
43 int whichfork, xfs_fileoff_t offset, int *error);
44
45void xchk_block_set_preen(struct xfs_scrub *sc,
46 struct xfs_buf *bp);
47void xchk_ino_set_preen(struct xfs_scrub *sc, xfs_ino_t ino);
48
49void xchk_set_corrupt(struct xfs_scrub *sc);
50void xchk_block_set_corrupt(struct xfs_scrub *sc,
51 struct xfs_buf *bp);
52void xchk_ino_set_corrupt(struct xfs_scrub *sc, xfs_ino_t ino);
53void xchk_fblock_set_corrupt(struct xfs_scrub *sc, int whichfork,
54 xfs_fileoff_t offset);
55
56void xchk_block_xref_set_corrupt(struct xfs_scrub *sc,
57 struct xfs_buf *bp);
58void xchk_ino_xref_set_corrupt(struct xfs_scrub *sc,
59 xfs_ino_t ino);
60void xchk_fblock_xref_set_corrupt(struct xfs_scrub *sc,
61 int whichfork, xfs_fileoff_t offset);
62
63void xchk_ino_set_warning(struct xfs_scrub *sc, xfs_ino_t ino);
64void xchk_fblock_set_warning(struct xfs_scrub *sc, int whichfork,
65 xfs_fileoff_t offset);
66
67void xchk_set_incomplete(struct xfs_scrub *sc);
68int xchk_checkpoint_log(struct xfs_mount *mp);
69
70/* Are we set up for a cross-referencing check? */
71bool xchk_should_check_xref(struct xfs_scrub *sc, int *error,
72 struct xfs_btree_cur **curpp);
73
74/* Setup functions */
75int xchk_setup_fs(struct xfs_scrub *sc);
76int xchk_setup_ag_allocbt(struct xfs_scrub *sc);
77int xchk_setup_ag_iallocbt(struct xfs_scrub *sc);
78int xchk_setup_ag_rmapbt(struct xfs_scrub *sc);
79int xchk_setup_ag_refcountbt(struct xfs_scrub *sc);
80int xchk_setup_inode(struct xfs_scrub *sc);
81int xchk_setup_inode_bmap(struct xfs_scrub *sc);
82int xchk_setup_inode_bmap_data(struct xfs_scrub *sc);
83int xchk_setup_directory(struct xfs_scrub *sc);
84int xchk_setup_xattr(struct xfs_scrub *sc);
85int xchk_setup_symlink(struct xfs_scrub *sc);
86int xchk_setup_parent(struct xfs_scrub *sc);
87#ifdef CONFIG_XFS_RT
88int xchk_setup_rt(struct xfs_scrub *sc);
89#else
90static inline int
91xchk_setup_rt(struct xfs_scrub *sc)
92{
93 return -ENOENT;
94}
95#endif
96#ifdef CONFIG_XFS_QUOTA
97int xchk_setup_quota(struct xfs_scrub *sc);
98#else
99static inline int
100xchk_setup_quota(struct xfs_scrub *sc)
101{
102 return -ENOENT;
103}
104#endif
105int xchk_setup_fscounters(struct xfs_scrub *sc);
106
107void xchk_ag_free(struct xfs_scrub *sc, struct xchk_ag *sa);
108int xchk_ag_init(struct xfs_scrub *sc, xfs_agnumber_t agno,
109 struct xchk_ag *sa);
110
111/*
112 * Grab all AG resources, treating the inability to grab the perag structure as
113 * a fs corruption. This is intended for callers checking an ondisk reference
114 * to a given AG, which means that the AG must still exist.
115 */
116static inline int
117xchk_ag_init_existing(
118 struct xfs_scrub *sc,
119 xfs_agnumber_t agno,
120 struct xchk_ag *sa)
121{
122 int error = xchk_ag_init(sc, agno, sa);
123
124 return error == -ENOENT ? -EFSCORRUPTED : error;
125}
126
127int xchk_ag_read_headers(struct xfs_scrub *sc, xfs_agnumber_t agno,
128 struct xchk_ag *sa);
129void xchk_ag_btcur_free(struct xchk_ag *sa);
130void xchk_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
131int xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
132 const struct xfs_owner_info *oinfo, xfs_filblks_t *blocks);
133
134int xchk_setup_ag_btree(struct xfs_scrub *sc, bool force_log);
135int xchk_get_inode(struct xfs_scrub *sc);
136int xchk_setup_inode_contents(struct xfs_scrub *sc, unsigned int resblks);
137void xchk_buffer_recheck(struct xfs_scrub *sc, struct xfs_buf *bp);
138
139/*
140 * Don't bother cross-referencing if we already found corruption or cross
141 * referencing discrepancies.
142 */
143static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm)
144{
145 return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
146 XFS_SCRUB_OFLAG_XCORRUPT);
147}
148
149int xchk_metadata_inode_forks(struct xfs_scrub *sc);
150int xchk_ilock_inverted(struct xfs_inode *ip, uint lock_mode);
151void xchk_stop_reaping(struct xfs_scrub *sc);
152void xchk_start_reaping(struct xfs_scrub *sc);
153
154#endif /* __XFS_SCRUB_COMMON_H__ */