xref: /linux/fs/xfs/scrub/quotacheck.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
148dd9117SDarrick J. Wong /* SPDX-License-Identifier: GPL-2.0-or-later */
248dd9117SDarrick J. Wong /*
348dd9117SDarrick J. Wong  * Copyright (c) 2020-2024 Oracle.  All Rights Reserved.
448dd9117SDarrick J. Wong  * Author: Darrick J. Wong <djwong@kernel.org>
548dd9117SDarrick J. Wong  */
648dd9117SDarrick J. Wong #ifndef __XFS_SCRUB_QUOTACHECK_H__
748dd9117SDarrick J. Wong #define __XFS_SCRUB_QUOTACHECK_H__
848dd9117SDarrick J. Wong 
948dd9117SDarrick J. Wong /* Quota counters for live quotacheck. */
1048dd9117SDarrick J. Wong struct xqcheck_dquot {
1148dd9117SDarrick J. Wong 	/* block usage count */
1248dd9117SDarrick J. Wong 	int64_t			bcount;
1348dd9117SDarrick J. Wong 
1448dd9117SDarrick J. Wong 	/* inode usage count */
1548dd9117SDarrick J. Wong 	int64_t			icount;
1648dd9117SDarrick J. Wong 
1748dd9117SDarrick J. Wong 	/* realtime block usage count */
1848dd9117SDarrick J. Wong 	int64_t			rtbcount;
1948dd9117SDarrick J. Wong 
2048dd9117SDarrick J. Wong 	/* Record state */
2148dd9117SDarrick J. Wong 	unsigned int		flags;
2248dd9117SDarrick J. Wong };
2348dd9117SDarrick J. Wong 
2448dd9117SDarrick J. Wong /*
2548dd9117SDarrick J. Wong  * This incore dquot record has been written at least once.  We never want to
2648dd9117SDarrick J. Wong  * store an xqcheck_dquot that looks uninitialized.
2748dd9117SDarrick J. Wong  */
2848dd9117SDarrick J. Wong #define XQCHECK_DQUOT_WRITTEN		(1U << 0)
2948dd9117SDarrick J. Wong 
3048dd9117SDarrick J. Wong /* Already checked this dquot. */
3148dd9117SDarrick J. Wong #define XQCHECK_DQUOT_COMPARE_SCANNED	(1U << 1)
3248dd9117SDarrick J. Wong 
33*96ed2ae4SDarrick J. Wong /* Already repaired this dquot. */
34*96ed2ae4SDarrick J. Wong #define XQCHECK_DQUOT_REPAIR_SCANNED	(1U << 2)
35*96ed2ae4SDarrick J. Wong 
3648dd9117SDarrick J. Wong /* Live quotacheck control structure. */
3748dd9117SDarrick J. Wong struct xqcheck {
3848dd9117SDarrick J. Wong 	struct xfs_scrub	*sc;
3948dd9117SDarrick J. Wong 
4048dd9117SDarrick J. Wong 	/* Shadow dquot counter data. */
4148dd9117SDarrick J. Wong 	struct xfarray		*ucounts;
4248dd9117SDarrick J. Wong 	struct xfarray		*gcounts;
4348dd9117SDarrick J. Wong 	struct xfarray		*pcounts;
4448dd9117SDarrick J. Wong 
4548dd9117SDarrick J. Wong 	/* Lock protecting quotacheck count observations */
4648dd9117SDarrick J. Wong 	struct mutex		lock;
4748dd9117SDarrick J. Wong 
4848dd9117SDarrick J. Wong 	struct xchk_iscan	iscan;
4920049187SDarrick J. Wong 
5020049187SDarrick J. Wong 	/* Hooks into the quota code. */
5120049187SDarrick J. Wong 	struct xfs_dqtrx_hook	qhook;
5220049187SDarrick J. Wong 
5320049187SDarrick J. Wong 	/* Shadow quota delta tracking structure. */
5420049187SDarrick J. Wong 	struct rhashtable	shadow_dquot_acct;
5548dd9117SDarrick J. Wong };
5648dd9117SDarrick J. Wong 
5748dd9117SDarrick J. Wong /* Return the incore counter array for a given quota type. */
5848dd9117SDarrick J. Wong static inline struct xfarray *
xqcheck_counters_for(struct xqcheck * xqc,xfs_dqtype_t dqtype)5948dd9117SDarrick J. Wong xqcheck_counters_for(
6048dd9117SDarrick J. Wong 	struct xqcheck		*xqc,
6148dd9117SDarrick J. Wong 	xfs_dqtype_t		dqtype)
6248dd9117SDarrick J. Wong {
6348dd9117SDarrick J. Wong 	switch (dqtype) {
6448dd9117SDarrick J. Wong 	case XFS_DQTYPE_USER:
6548dd9117SDarrick J. Wong 		return xqc->ucounts;
6648dd9117SDarrick J. Wong 	case XFS_DQTYPE_GROUP:
6748dd9117SDarrick J. Wong 		return xqc->gcounts;
6848dd9117SDarrick J. Wong 	case XFS_DQTYPE_PROJ:
6948dd9117SDarrick J. Wong 		return xqc->pcounts;
7048dd9117SDarrick J. Wong 	}
7148dd9117SDarrick J. Wong 
7248dd9117SDarrick J. Wong 	ASSERT(0);
7348dd9117SDarrick J. Wong 	return NULL;
7448dd9117SDarrick J. Wong }
7548dd9117SDarrick J. Wong 
7648dd9117SDarrick J. Wong #endif /* __XFS_SCRUB_QUOTACHECK_H__ */
77