cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

scrub.h (4980B)


      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_SCRUB_H__
      7#define __XFS_SCRUB_SCRUB_H__
      8
      9struct xfs_scrub;
     10
     11/* Type info and names for the scrub types. */
     12enum xchk_type {
     13	ST_NONE = 1,	/* disabled */
     14	ST_PERAG,	/* per-AG metadata */
     15	ST_FS,		/* per-FS metadata */
     16	ST_INODE,	/* per-inode metadata */
     17};
     18
     19struct xchk_meta_ops {
     20	/* Acquire whatever resources are needed for the operation. */
     21	int		(*setup)(struct xfs_scrub *sc);
     22
     23	/* Examine metadata for errors. */
     24	int		(*scrub)(struct xfs_scrub *);
     25
     26	/* Repair or optimize the metadata. */
     27	int		(*repair)(struct xfs_scrub *);
     28
     29	/* Decide if we even have this piece of metadata. */
     30	bool		(*has)(struct xfs_mount *);
     31
     32	/* type describing required/allowed inputs */
     33	enum xchk_type	type;
     34};
     35
     36/* Buffer pointers and btree cursors for an entire AG. */
     37struct xchk_ag {
     38	struct xfs_perag	*pag;
     39
     40	/* AG btree roots */
     41	struct xfs_buf		*agf_bp;
     42	struct xfs_buf		*agfl_bp;
     43	struct xfs_buf		*agi_bp;
     44
     45	/* AG btrees */
     46	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;
     52};
     53
     54struct xfs_scrub {
     55	/* General scrub state. */
     56	struct xfs_mount		*mp;
     57	struct xfs_scrub_metadata	*sm;
     58	const struct xchk_meta_ops	*ops;
     59	struct xfs_trans		*tp;
     60
     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	 */
     70	struct xfs_inode		*ip;
     71
     72	void				*buf;
     73	uint				ilock_flags;
     74
     75	/* See the XCHK/XREP state flags below. */
     76	unsigned int			flags;
     77
     78	/*
     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
     85	/* State tracking for single-AG operations. */
     86	struct xchk_ag			sa;
     87};
     88
     89/* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */
     90#define XCHK_TRY_HARDER		(1 << 0)  /* can't get resources, try again */
     91#define XCHK_REAPING_DISABLED	(1 << 2)  /* background block reaping paused */
     92#define XREP_ALREADY_FIXED	(1 << 31) /* checking our repair work */
     93
     94/* Metadata scrubbers */
     95int xchk_tester(struct xfs_scrub *sc);
     96int xchk_superblock(struct xfs_scrub *sc);
     97int xchk_agf(struct xfs_scrub *sc);
     98int xchk_agfl(struct xfs_scrub *sc);
     99int xchk_agi(struct xfs_scrub *sc);
    100int xchk_bnobt(struct xfs_scrub *sc);
    101int xchk_cntbt(struct xfs_scrub *sc);
    102int xchk_inobt(struct xfs_scrub *sc);
    103int xchk_finobt(struct xfs_scrub *sc);
    104int xchk_rmapbt(struct xfs_scrub *sc);
    105int xchk_refcountbt(struct xfs_scrub *sc);
    106int xchk_inode(struct xfs_scrub *sc);
    107int xchk_bmap_data(struct xfs_scrub *sc);
    108int xchk_bmap_attr(struct xfs_scrub *sc);
    109int xchk_bmap_cow(struct xfs_scrub *sc);
    110int xchk_directory(struct xfs_scrub *sc);
    111int xchk_xattr(struct xfs_scrub *sc);
    112int xchk_symlink(struct xfs_scrub *sc);
    113int xchk_parent(struct xfs_scrub *sc);
    114#ifdef CONFIG_XFS_RT
    115int xchk_rtbitmap(struct xfs_scrub *sc);
    116int xchk_rtsummary(struct xfs_scrub *sc);
    117#else
    118static inline int
    119xchk_rtbitmap(struct xfs_scrub *sc)
    120{
    121	return -ENOENT;
    122}
    123static inline int
    124xchk_rtsummary(struct xfs_scrub *sc)
    125{
    126	return -ENOENT;
    127}
    128#endif
    129#ifdef CONFIG_XFS_QUOTA
    130int xchk_quota(struct xfs_scrub *sc);
    131#else
    132static inline int
    133xchk_quota(struct xfs_scrub *sc)
    134{
    135	return -ENOENT;
    136}
    137#endif
    138int xchk_fscounters(struct xfs_scrub *sc);
    139
    140/* cross-referencing helpers */
    141void xchk_xref_is_used_space(struct xfs_scrub *sc, xfs_agblock_t agbno,
    142		xfs_extlen_t len);
    143void xchk_xref_is_not_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
    144		xfs_extlen_t len);
    145void xchk_xref_is_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
    146		xfs_extlen_t len);
    147void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
    148		xfs_extlen_t len, const struct xfs_owner_info *oinfo);
    149void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
    150		xfs_extlen_t len, const struct xfs_owner_info *oinfo);
    151void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_agblock_t agbno,
    152		xfs_extlen_t len);
    153void xchk_xref_is_cow_staging(struct xfs_scrub *sc, xfs_agblock_t bno,
    154		xfs_extlen_t len);
    155void xchk_xref_is_not_shared(struct xfs_scrub *sc, xfs_agblock_t bno,
    156		xfs_extlen_t len);
    157#ifdef CONFIG_XFS_RT
    158void xchk_xref_is_used_rt_space(struct xfs_scrub *sc, xfs_rtblock_t rtbno,
    159		xfs_extlen_t len);
    160#else
    161# define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
    162#endif
    163
    164struct xchk_fscounters {
    165	uint64_t		icount;
    166	uint64_t		ifree;
    167	uint64_t		fdblocks;
    168	unsigned long long	icount_min;
    169	unsigned long long	icount_max;
    170};
    171
    172#endif	/* __XFS_SCRUB_SCRUB_H__ */