blob: 80e5026bba44ac719f5047706f9a135b546b2738 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0+
Darrick J. Wong36fd6e82017-10-17 21:37:34 -07002/*
3 * Copyright (C) 2017 Oracle. All Rights Reserved.
Darrick J. Wong36fd6e82017-10-17 21:37:34 -07004 * Author: Darrick J. Wong <darrick.wong@oracle.com>
Darrick J. Wong36fd6e82017-10-17 21:37:34 -07005 */
6#ifndef __XFS_SCRUB_SCRUB_H__
7#define __XFS_SCRUB_SCRUB_H__
8
Darrick J. Wong1d8a7482018-07-19 12:29:12 -07009struct xfs_scrub;
Darrick J. Wonga5637182017-10-17 21:37:35 -070010
Eric Sandeen8e630832018-01-08 10:41:34 -080011/* Type info and names for the scrub types. */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070012enum xchk_type {
Eric Sandeen8e630832018-01-08 10:41:34 -080013 ST_NONE = 1, /* disabled */
14 ST_PERAG, /* per-AG metadata */
15 ST_FS, /* per-FS metadata */
16 ST_INODE, /* per-inode metadata */
17};
18
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070019struct xchk_meta_ops {
Darrick J. Wonga5637182017-10-17 21:37:35 -070020 /* Acquire whatever resources are needed for the operation. */
Darrick J. Wong026f57e2021-04-07 17:59:39 -070021 int (*setup)(struct xfs_scrub *sc);
Darrick J. Wonga5637182017-10-17 21:37:35 -070022
23 /* Examine metadata for errors. */
Darrick J. Wong1d8a7482018-07-19 12:29:12 -070024 int (*scrub)(struct xfs_scrub *);
Darrick J. Wonga5637182017-10-17 21:37:35 -070025
Darrick J. Wong84d42ea2018-05-14 06:34:36 -070026 /* Repair or optimize the metadata. */
Darrick J. Wong1d8a7482018-07-19 12:29:12 -070027 int (*repair)(struct xfs_scrub *);
Darrick J. Wong84d42ea2018-05-14 06:34:36 -070028
Darrick J. Wonga5637182017-10-17 21:37:35 -070029 /* Decide if we even have this piece of metadata. */
Dave Chinner55fafb32021-08-18 18:46:54 -070030 bool (*has)(struct xfs_mount *);
Eric Sandeen8e630832018-01-08 10:41:34 -080031
32 /* type describing required/allowed inputs */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070033 enum xchk_type type;
Darrick J. Wonga5637182017-10-17 21:37:35 -070034};
35
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070036/* Buffer pointers and btree cursors for an entire AG. */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070037struct xchk_ag {
Darrick J. Wong032d91f2018-07-19 12:29:12 -070038 struct xfs_perag *pag;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070039
40 /* AG btree roots */
Darrick J. Wong032d91f2018-07-19 12:29:12 -070041 struct xfs_buf *agf_bp;
42 struct xfs_buf *agfl_bp;
43 struct xfs_buf *agi_bp;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070044
45 /* AG btrees */
Darrick J. Wong032d91f2018-07-19 12:29:12 -070046 struct xfs_btree_cur *bno_cur;
47 struct xfs_btree_cur *cnt_cur;
48 struct xfs_btree_cur *ino_cur;
49 struct xfs_btree_cur *fino_cur;
50 struct xfs_btree_cur *rmap_cur;
51 struct xfs_btree_cur *refc_cur;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070052};
53
Darrick J. Wong1d8a7482018-07-19 12:29:12 -070054struct xfs_scrub {
Darrick J. Wonga5637182017-10-17 21:37:35 -070055 /* General scrub state. */
56 struct xfs_mount *mp;
57 struct xfs_scrub_metadata *sm;
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070058 const struct xchk_meta_ops *ops;
Darrick J. Wonga5637182017-10-17 21:37:35 -070059 struct xfs_trans *tp;
Darrick J. Wong71bddbc2021-03-22 09:51:51 -070060
61 /* File that scrub was called with. */
62 struct file *file;
63
64 /*
65 * File that is undergoing the scrub operation. This can differ from
66 * the file that scrub was called with if we're checking file-based fs
67 * metadata (e.g. rt bitmaps) or if we're doing a scrub-by-handle for
68 * something that can't be opened directly (e.g. symlinks).
69 */
Darrick J. Wonga5637182017-10-17 21:37:35 -070070 struct xfs_inode *ip;
Darrick J. Wong71bddbc2021-03-22 09:51:51 -070071
Darrick J. Wongeec04822017-10-17 21:37:45 -070072 void *buf;
Darrick J. Wong80e4e122017-10-17 21:37:42 -070073 uint ilock_flags;
Darrick J. Wongf8c2a222019-04-16 08:21:59 -070074
Darrick J. Wong160b5a72019-04-16 08:22:00 -070075 /* See the XCHK/XREP state flags below. */
Darrick J. Wongf8c2a222019-04-16 08:21:59 -070076 unsigned int flags;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070077
Darrick J. Wong4860a052019-04-16 08:22:00 -070078 /*
79 * The XFS_SICK_* flags that correspond to the metadata being scrubbed
80 * or repaired. We will use this mask to update the in-core fs health
81 * status with whatever we find.
82 */
83 unsigned int sick_mask;
84
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070085 /* State tracking for single-AG operations. */
Darrick J. Wong032d91f2018-07-19 12:29:12 -070086 struct xchk_ag sa;
Darrick J. Wonga5637182017-10-17 21:37:35 -070087};
88
Darrick J. Wong160b5a72019-04-16 08:22:00 -070089/* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */
Darrick J. Wongf8c2a222019-04-16 08:21:59 -070090#define XCHK_TRY_HARDER (1 << 0) /* can't get resources, try again */
91#define XCHK_HAS_QUOTAOFFLOCK (1 << 1) /* we hold the quotaoff lock */
Darrick J. Wong9a1f3042019-04-25 18:26:23 -070092#define XCHK_REAPING_DISABLED (1 << 2) /* background block reaping paused */
Darrick J. Wong160b5a72019-04-16 08:22:00 -070093#define XREP_ALREADY_FIXED (1 << 31) /* checking our repair work */
Darrick J. Wongf8c2a222019-04-16 08:21:59 -070094
Darrick J. Wong36fd6e82017-10-17 21:37:34 -070095/* Metadata scrubbers */
Darrick J. Wong1d8a7482018-07-19 12:29:12 -070096int xchk_tester(struct xfs_scrub *sc);
97int xchk_superblock(struct xfs_scrub *sc);
98int xchk_agf(struct xfs_scrub *sc);
99int xchk_agfl(struct xfs_scrub *sc);
100int xchk_agi(struct xfs_scrub *sc);
101int xchk_bnobt(struct xfs_scrub *sc);
102int xchk_cntbt(struct xfs_scrub *sc);
103int xchk_inobt(struct xfs_scrub *sc);
104int xchk_finobt(struct xfs_scrub *sc);
105int xchk_rmapbt(struct xfs_scrub *sc);
106int xchk_refcountbt(struct xfs_scrub *sc);
107int xchk_inode(struct xfs_scrub *sc);
108int xchk_bmap_data(struct xfs_scrub *sc);
109int xchk_bmap_attr(struct xfs_scrub *sc);
110int xchk_bmap_cow(struct xfs_scrub *sc);
111int xchk_directory(struct xfs_scrub *sc);
112int xchk_xattr(struct xfs_scrub *sc);
113int xchk_symlink(struct xfs_scrub *sc);
114int xchk_parent(struct xfs_scrub *sc);
Darrick J. Wong29b07672017-10-17 21:37:46 -0700115#ifdef CONFIG_XFS_RT
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700116int xchk_rtbitmap(struct xfs_scrub *sc);
117int xchk_rtsummary(struct xfs_scrub *sc);
Darrick J. Wong29b07672017-10-17 21:37:46 -0700118#else
119static inline int
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700120xchk_rtbitmap(struct xfs_scrub *sc)
Darrick J. Wong29b07672017-10-17 21:37:46 -0700121{
122 return -ENOENT;
123}
124static inline int
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700125xchk_rtsummary(struct xfs_scrub *sc)
Darrick J. Wong29b07672017-10-17 21:37:46 -0700126{
127 return -ENOENT;
128}
129#endif
Darrick J. Wongc2fc3382017-10-17 21:37:47 -0700130#ifdef CONFIG_XFS_QUOTA
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700131int xchk_quota(struct xfs_scrub *sc);
Darrick J. Wongc2fc3382017-10-17 21:37:47 -0700132#else
133static inline int
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700134xchk_quota(struct xfs_scrub *sc)
Darrick J. Wongc2fc3382017-10-17 21:37:47 -0700135{
136 return -ENOENT;
137}
138#endif
Darrick J. Wong75efa572019-04-25 18:26:24 -0700139int xchk_fscounters(struct xfs_scrub *sc);
Darrick J. Wong36fd6e82017-10-17 21:37:34 -0700140
Darrick J. Wong52dc4b42018-01-16 18:53:06 -0800141/* cross-referencing helpers */
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700142void xchk_xref_is_used_space(struct xfs_scrub *sc, xfs_agblock_t agbno,
143 xfs_extlen_t len);
144void xchk_xref_is_not_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
145 xfs_extlen_t len);
146void xchk_xref_is_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
147 xfs_extlen_t len);
148void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
Darrick J. Wong66e32372018-12-12 08:46:23 -0800149 xfs_extlen_t len, const struct xfs_owner_info *oinfo);
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700150void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
Darrick J. Wong66e32372018-12-12 08:46:23 -0800151 xfs_extlen_t len, const struct xfs_owner_info *oinfo);
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700152void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_agblock_t agbno,
153 xfs_extlen_t len);
154void xchk_xref_is_cow_staging(struct xfs_scrub *sc, xfs_agblock_t bno,
155 xfs_extlen_t len);
156void xchk_xref_is_not_shared(struct xfs_scrub *sc, xfs_agblock_t bno,
157 xfs_extlen_t len);
Darrick J. Wong46d9bfb2018-01-16 18:53:10 -0800158#ifdef CONFIG_XFS_RT
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700159void xchk_xref_is_used_rt_space(struct xfs_scrub *sc, xfs_rtblock_t rtbno,
160 xfs_extlen_t len);
Darrick J. Wong46d9bfb2018-01-16 18:53:10 -0800161#else
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700162# define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
Darrick J. Wong46d9bfb2018-01-16 18:53:10 -0800163#endif
Darrick J. Wong52dc4b42018-01-16 18:53:06 -0800164
Darrick J. Wong75efa572019-04-25 18:26:24 -0700165struct xchk_fscounters {
166 uint64_t icount;
167 uint64_t ifree;
168 uint64_t fdblocks;
169 unsigned long long icount_min;
170 unsigned long long icount_max;
171};
172
Darrick J. Wong36fd6e82017-10-17 21:37:34 -0700173#endif /* __XFS_SCRUB_SCRUB_H__ */