summaryrefslogtreecommitdiff
path: root/fs/xfs/scrub/quotacheck.h
blob: 660eac4e87cd2b99c20150f3f1a1c94ab435edce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2021 Oracle.  All Rights Reserved.
 * Author: Darrick J. Wong <djwong@kernel.org>
 */
#ifndef __XFS_SCRUB_QUOTACHECK_H__
#define __XFS_SCRUB_QUOTACHECK_H__

/*
 * Quota counters for live quotacheck.  Pad the structure to 32 bytes to avoid
 * a weird interaction between sparse xfbma arrays and shmem files, and so that
 * we never mistake a zero-count xchk_dquot for a null record.
 */
struct xqcheck_dquot {
	/* block usage count */
	int64_t			bcount;

	/* inode usage count */
	int64_t			icount;

	/* realtime block usage count */
	int64_t			rtbcount;
};

/* Live quotacheck control structure. */
struct xqcheck {
	struct xfs_scrub	*sc;

	/* Shadow dquot counter data. */
	struct xfbma		*ucounts;
	struct xfbma		*gcounts;
	struct xfbma		*pcounts;

	struct xchk_iscan	iscan;

	/* Hooks into the quota code. */
	struct notifier_block	mod_hook;
	struct notifier_block	apply_hook;

	/* Shadow quota delta tracking structure. */
	struct rhashtable	shadow_dquot_acct;

	/* Something failed during live tracking. */
	bool			hook_dead;
};

/* Return the incore counter array for a given quota type. */
static inline struct xfbma *
xqcheck_counters_for(
	struct xqcheck		*xqc,
	xfs_dqtype_t		dqtype)
{
	switch (dqtype) {
	case XFS_DQTYPE_USER:
		return xqc->ucounts;
	case XFS_DQTYPE_GROUP:
		return xqc->gcounts;
	case XFS_DQTYPE_PROJ:
		return xqc->pcounts;
	}

	ASSERT(0);
	return NULL;
}

int xqcheck_get_shadow_dquot(struct xfbma *counts, xfs_dqid_t id,
		struct xqcheck_dquot *xcdq);

#endif /* __XFS_SCRUB_QUOTACHECK_H__ */