blob: ad1ceb44a628570f122849cc357f9d0d23ecac98 [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. Wong1d8a7482018-07-19 12:29:12 -070021 int (*setup)(struct xfs_scrub *,
Darrick J. Wonga5637182017-10-17 21:37:35 -070022 struct xfs_inode *);
23
24 /* Examine metadata for errors. */
Darrick J. Wong1d8a7482018-07-19 12:29:12 -070025 int (*scrub)(struct xfs_scrub *);
Darrick J. Wonga5637182017-10-17 21:37:35 -070026
Darrick J. Wong84d42ea2018-05-14 06:34:36 -070027 /* Repair or optimize the metadata. */
Darrick J. Wong1d8a7482018-07-19 12:29:12 -070028 int (*repair)(struct xfs_scrub *);
Darrick J. Wong84d42ea2018-05-14 06:34:36 -070029
Darrick J. Wonga5637182017-10-17 21:37:35 -070030 /* Decide if we even have this piece of metadata. */
31 bool (*has)(struct xfs_sb *);
Eric Sandeen8e630832018-01-08 10:41:34 -080032
33 /* type describing required/allowed inputs */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070034 enum xchk_type type;
Darrick J. Wonga5637182017-10-17 21:37:35 -070035};
36
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070037/* Buffer pointers and btree cursors for an entire AG. */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070038struct xchk_ag {
Darrick J. Wong032d91f2018-07-19 12:29:12 -070039 xfs_agnumber_t agno;
40 struct xfs_perag *pag;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070041
42 /* AG btree roots */
Darrick J. Wong032d91f2018-07-19 12:29:12 -070043 struct xfs_buf *agf_bp;
44 struct xfs_buf *agfl_bp;
45 struct xfs_buf *agi_bp;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070046
47 /* AG btrees */
Darrick J. Wong032d91f2018-07-19 12:29:12 -070048 struct xfs_btree_cur *bno_cur;
49 struct xfs_btree_cur *cnt_cur;
50 struct xfs_btree_cur *ino_cur;
51 struct xfs_btree_cur *fino_cur;
52 struct xfs_btree_cur *rmap_cur;
53 struct xfs_btree_cur *refc_cur;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070054};
55
Darrick J. Wong1d8a7482018-07-19 12:29:12 -070056struct xfs_scrub {
Darrick J. Wonga5637182017-10-17 21:37:35 -070057 /* General scrub state. */
58 struct xfs_mount *mp;
59 struct xfs_scrub_metadata *sm;
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070060 const struct xchk_meta_ops *ops;
Darrick J. Wonga5637182017-10-17 21:37:35 -070061 struct xfs_trans *tp;
62 struct xfs_inode *ip;
Darrick J. Wongeec04822017-10-17 21:37:45 -070063 void *buf;
Darrick J. Wong80e4e122017-10-17 21:37:42 -070064 uint ilock_flags;
Darrick J. Wongf8c2a222019-04-16 08:21:59 -070065
Darrick J. Wong160b5a72019-04-16 08:22:00 -070066 /* See the XCHK/XREP state flags below. */
Darrick J. Wongf8c2a222019-04-16 08:21:59 -070067 unsigned int flags;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070068
Darrick J. Wong4860a052019-04-16 08:22:00 -070069 /*
70 * The XFS_SICK_* flags that correspond to the metadata being scrubbed
71 * or repaired. We will use this mask to update the in-core fs health
72 * status with whatever we find.
73 */
74 unsigned int sick_mask;
75
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070076 /* State tracking for single-AG operations. */
Darrick J. Wong032d91f2018-07-19 12:29:12 -070077 struct xchk_ag sa;
Darrick J. Wonga5637182017-10-17 21:37:35 -070078};
79
Darrick J. Wong160b5a72019-04-16 08:22:00 -070080/* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */
Darrick J. Wongf8c2a222019-04-16 08:21:59 -070081#define XCHK_TRY_HARDER (1 << 0) /* can't get resources, try again */
82#define XCHK_HAS_QUOTAOFFLOCK (1 << 1) /* we hold the quotaoff lock */
Darrick J. Wong9a1f3042019-04-25 18:26:23 -070083#define XCHK_REAPING_DISABLED (1 << 2) /* background block reaping paused */
Darrick J. Wong160b5a72019-04-16 08:22:00 -070084#define XREP_ALREADY_FIXED (1 << 31) /* checking our repair work */
Darrick J. Wongf8c2a222019-04-16 08:21:59 -070085
Darrick J. Wong36fd6e82017-10-17 21:37:34 -070086/* Metadata scrubbers */
Darrick J. Wong1d8a7482018-07-19 12:29:12 -070087int xchk_tester(struct xfs_scrub *sc);
88int xchk_superblock(struct xfs_scrub *sc);
89int xchk_agf(struct xfs_scrub *sc);
90int xchk_agfl(struct xfs_scrub *sc);
91int xchk_agi(struct xfs_scrub *sc);
92int xchk_bnobt(struct xfs_scrub *sc);
93int xchk_cntbt(struct xfs_scrub *sc);
94int xchk_inobt(struct xfs_scrub *sc);
95int xchk_finobt(struct xfs_scrub *sc);
96int xchk_rmapbt(struct xfs_scrub *sc);
97int xchk_refcountbt(struct xfs_scrub *sc);
98int xchk_inode(struct xfs_scrub *sc);
99int xchk_bmap_data(struct xfs_scrub *sc);
100int xchk_bmap_attr(struct xfs_scrub *sc);
101int xchk_bmap_cow(struct xfs_scrub *sc);
102int xchk_directory(struct xfs_scrub *sc);
103int xchk_xattr(struct xfs_scrub *sc);
104int xchk_symlink(struct xfs_scrub *sc);
105int xchk_parent(struct xfs_scrub *sc);
Darrick J. Wong29b07672017-10-17 21:37:46 -0700106#ifdef CONFIG_XFS_RT
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700107int xchk_rtbitmap(struct xfs_scrub *sc);
108int xchk_rtsummary(struct xfs_scrub *sc);
Darrick J. Wong29b07672017-10-17 21:37:46 -0700109#else
110static inline int
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700111xchk_rtbitmap(struct xfs_scrub *sc)
Darrick J. Wong29b07672017-10-17 21:37:46 -0700112{
113 return -ENOENT;
114}
115static inline int
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700116xchk_rtsummary(struct xfs_scrub *sc)
Darrick J. Wong29b07672017-10-17 21:37:46 -0700117{
118 return -ENOENT;
119}
120#endif
Darrick J. Wongc2fc3382017-10-17 21:37:47 -0700121#ifdef CONFIG_XFS_QUOTA
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700122int xchk_quota(struct xfs_scrub *sc);
Darrick J. Wongc2fc3382017-10-17 21:37:47 -0700123#else
124static inline int
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700125xchk_quota(struct xfs_scrub *sc)
Darrick J. Wongc2fc3382017-10-17 21:37:47 -0700126{
127 return -ENOENT;
128}
129#endif
Darrick J. Wong75efa572019-04-25 18:26:24 -0700130int xchk_fscounters(struct xfs_scrub *sc);
Darrick J. Wong36fd6e82017-10-17 21:37:34 -0700131
Darrick J. Wong52dc4b42018-01-16 18:53:06 -0800132/* cross-referencing helpers */
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700133void xchk_xref_is_used_space(struct xfs_scrub *sc, xfs_agblock_t agbno,
134 xfs_extlen_t len);
135void xchk_xref_is_not_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
136 xfs_extlen_t len);
137void xchk_xref_is_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
138 xfs_extlen_t len);
139void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
Darrick J. Wong66e32372018-12-12 08:46:23 -0800140 xfs_extlen_t len, const struct xfs_owner_info *oinfo);
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700141void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
Darrick J. Wong66e32372018-12-12 08:46:23 -0800142 xfs_extlen_t len, const struct xfs_owner_info *oinfo);
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700143void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_agblock_t agbno,
144 xfs_extlen_t len);
145void xchk_xref_is_cow_staging(struct xfs_scrub *sc, xfs_agblock_t bno,
146 xfs_extlen_t len);
147void xchk_xref_is_not_shared(struct xfs_scrub *sc, xfs_agblock_t bno,
148 xfs_extlen_t len);
Darrick J. Wong46d9bfb2018-01-16 18:53:10 -0800149#ifdef CONFIG_XFS_RT
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700150void xchk_xref_is_used_rt_space(struct xfs_scrub *sc, xfs_rtblock_t rtbno,
151 xfs_extlen_t len);
Darrick J. Wong46d9bfb2018-01-16 18:53:10 -0800152#else
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700153# define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
Darrick J. Wong46d9bfb2018-01-16 18:53:10 -0800154#endif
Darrick J. Wong52dc4b42018-01-16 18:53:06 -0800155
Darrick J. Wong75efa572019-04-25 18:26:24 -0700156struct xchk_fscounters {
157 uint64_t icount;
158 uint64_t ifree;
159 uint64_t fdblocks;
160 unsigned long long icount_min;
161 unsigned long long icount_max;
162};
163
Darrick J. Wong36fd6e82017-10-17 21:37:34 -0700164#endif /* __XFS_SCRUB_SCRUB_H__ */