blob: 0f59a47c4bb039d06f3c933b14c1443685521304 [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. Wonga5637182017-10-17 21:37:35 -07009struct xfs_scrub_context;
10
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. */
21 int (*setup)(struct xfs_scrub_context *,
22 struct xfs_inode *);
23
24 /* Examine metadata for errors. */
25 int (*scrub)(struct xfs_scrub_context *);
26
Darrick J. Wong84d42ea2018-05-14 06:34:36 -070027 /* Repair or optimize the metadata. */
28 int (*repair)(struct xfs_scrub_context *);
29
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. Wongb6c1beb2017-10-17 21:37:38 -070039 xfs_agnumber_t agno;
Darrick J. Wong51863d72018-05-29 22:24:44 -070040 struct xfs_perag *pag;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070041
42 /* AG btree roots */
43 struct xfs_buf *agf_bp;
44 struct xfs_buf *agfl_bp;
45 struct xfs_buf *agi_bp;
46
47 /* AG btrees */
48 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;
54};
55
Darrick J. Wonga5637182017-10-17 21:37:35 -070056struct xfs_scrub_context {
57 /* 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. Wonga5637182017-10-17 21:37:35 -070065 bool try_harder;
Darrick J. Wongeb41c932018-05-09 10:02:00 -070066 bool has_quotaofflock;
Darrick J. Wongb6c1beb2017-10-17 21:37:38 -070067
68 /* State tracking for single-AG operations. */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070069 struct xchk_ag sa;
Darrick J. Wonga5637182017-10-17 21:37:35 -070070};
71
Darrick J. Wong36fd6e82017-10-17 21:37:34 -070072/* Metadata scrubbers */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070073int xchk_tester(struct xfs_scrub_context *sc);
74int xchk_superblock(struct xfs_scrub_context *sc);
75int xchk_agf(struct xfs_scrub_context *sc);
76int xchk_agfl(struct xfs_scrub_context *sc);
77int xchk_agi(struct xfs_scrub_context *sc);
78int xchk_bnobt(struct xfs_scrub_context *sc);
79int xchk_cntbt(struct xfs_scrub_context *sc);
80int xchk_inobt(struct xfs_scrub_context *sc);
81int xchk_finobt(struct xfs_scrub_context *sc);
82int xchk_rmapbt(struct xfs_scrub_context *sc);
83int xchk_refcountbt(struct xfs_scrub_context *sc);
84int xchk_inode(struct xfs_scrub_context *sc);
85int xchk_bmap_data(struct xfs_scrub_context *sc);
86int xchk_bmap_attr(struct xfs_scrub_context *sc);
87int xchk_bmap_cow(struct xfs_scrub_context *sc);
88int xchk_directory(struct xfs_scrub_context *sc);
89int xchk_xattr(struct xfs_scrub_context *sc);
90int xchk_symlink(struct xfs_scrub_context *sc);
91int xchk_parent(struct xfs_scrub_context *sc);
Darrick J. Wong29b07672017-10-17 21:37:46 -070092#ifdef CONFIG_XFS_RT
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070093int xchk_rtbitmap(struct xfs_scrub_context *sc);
94int xchk_rtsummary(struct xfs_scrub_context *sc);
Darrick J. Wong29b07672017-10-17 21:37:46 -070095#else
96static inline int
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070097xchk_rtbitmap(struct xfs_scrub_context *sc)
Darrick J. Wong29b07672017-10-17 21:37:46 -070098{
99 return -ENOENT;
100}
101static inline int
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700102xchk_rtsummary(struct xfs_scrub_context *sc)
Darrick J. Wong29b07672017-10-17 21:37:46 -0700103{
104 return -ENOENT;
105}
106#endif
Darrick J. Wongc2fc3382017-10-17 21:37:47 -0700107#ifdef CONFIG_XFS_QUOTA
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700108int xchk_quota(struct xfs_scrub_context *sc);
Darrick J. Wongc2fc3382017-10-17 21:37:47 -0700109#else
110static inline int
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700111xchk_quota(struct xfs_scrub_context *sc)
Darrick J. Wongc2fc3382017-10-17 21:37:47 -0700112{
113 return -ENOENT;
114}
115#endif
Darrick J. Wong36fd6e82017-10-17 21:37:34 -0700116
Darrick J. Wong52dc4b42018-01-16 18:53:06 -0800117/* cross-referencing helpers */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700118void xchk_xref_is_used_space(struct xfs_scrub_context *sc,
Darrick J. Wong52dc4b42018-01-16 18:53:06 -0800119 xfs_agblock_t agbno, xfs_extlen_t len);
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700120void xchk_xref_is_not_inode_chunk(struct xfs_scrub_context *sc,
Darrick J. Wong2e6f2752018-01-16 18:53:07 -0800121 xfs_agblock_t agbno, xfs_extlen_t len);
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700122void xchk_xref_is_inode_chunk(struct xfs_scrub_context *sc,
Darrick J. Wong2e6f2752018-01-16 18:53:07 -0800123 xfs_agblock_t agbno, xfs_extlen_t len);
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700124void xchk_xref_is_owned_by(struct xfs_scrub_context *sc,
Darrick J. Wongd8526572018-01-16 18:53:08 -0800125 xfs_agblock_t agbno, xfs_extlen_t len,
126 struct xfs_owner_info *oinfo);
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700127void xchk_xref_is_not_owned_by(struct xfs_scrub_context *sc,
Darrick J. Wongd8526572018-01-16 18:53:08 -0800128 xfs_agblock_t agbno, xfs_extlen_t len,
129 struct xfs_owner_info *oinfo);
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700130void xchk_xref_has_no_owner(struct xfs_scrub_context *sc,
Darrick J. Wongd8526572018-01-16 18:53:08 -0800131 xfs_agblock_t agbno, xfs_extlen_t len);
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700132void xchk_xref_is_cow_staging(struct xfs_scrub_context *sc,
Darrick J. Wongf6d5fc22018-01-16 18:53:09 -0800133 xfs_agblock_t bno, xfs_extlen_t len);
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700134void xchk_xref_is_not_shared(struct xfs_scrub_context *sc,
Darrick J. Wongf6d5fc22018-01-16 18:53:09 -0800135 xfs_agblock_t bno, xfs_extlen_t len);
Darrick J. Wong46d9bfb2018-01-16 18:53:10 -0800136#ifdef CONFIG_XFS_RT
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700137void xchk_xref_is_used_rt_space(struct xfs_scrub_context *sc,
Darrick J. Wong46d9bfb2018-01-16 18:53:10 -0800138 xfs_rtblock_t rtbno, xfs_extlen_t len);
139#else
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700140# define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
Darrick J. Wong46d9bfb2018-01-16 18:53:10 -0800141#endif
Darrick J. Wong52dc4b42018-01-16 18:53:06 -0800142
Darrick J. Wong36fd6e82017-10-17 21:37:34 -0700143#endif /* __XFS_SCRUB_SCRUB_H__ */