xref: /linux/fs/xfs/libxfs/xfs_group.h (revision adbc76aa0fedcb6da2d1ceb1ce786d1f963afee8)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2018 Red Hat, Inc.
4  */
5 #ifndef __LIBXFS_GROUP_H
6 #define __LIBXFS_GROUP_H 1
7 
8 struct xfs_group {
9 	struct xfs_mount	*xg_mount;
10 	uint32_t		xg_gno;
11 	enum xfs_group_type	xg_type;
12 	atomic_t		xg_ref;		/* passive reference count */
13 	atomic_t		xg_active_ref;	/* active reference count */
14 
15 #ifdef __KERNEL__
16 	/* -- kernel only structures below this line -- */
17 
18 	/*
19 	 * Track freed but not yet committed extents.
20 	 */
21 	struct xfs_extent_busy_tree *xg_busy_extents;
22 
23 	/*
24 	 * Bitsets of per-ag metadata that have been checked and/or are sick.
25 	 * Callers should hold xg_state_lock before accessing this field.
26 	 */
27 	uint16_t		xg_checked;
28 	uint16_t		xg_sick;
29 	spinlock_t		xg_state_lock;
30 
31 	/*
32 	 * We use xfs_drain to track the number of deferred log intent items
33 	 * that have been queued (but not yet processed) so that waiters (e.g.
34 	 * scrub) will not lock resources when other threads are in the middle
35 	 * of processing a chain of intent items only to find momentary
36 	 * inconsistencies.
37 	 */
38 	struct xfs_defer_drain	xg_intents_drain;
39 
40 	/*
41 	 * Hook to feed rmapbt updates to an active online repair.
42 	 */
43 	struct xfs_hooks	xg_rmap_update_hooks;
44 #endif /* __KERNEL__ */
45 };
46 
47 struct xfs_group *xfs_group_get(struct xfs_mount *mp, uint32_t index,
48 		enum xfs_group_type type);
49 struct xfs_group *xfs_group_hold(struct xfs_group *xg);
50 void xfs_group_put(struct xfs_group *xg);
51 
52 struct xfs_group *xfs_group_grab(struct xfs_mount *mp, uint32_t index,
53 		enum xfs_group_type type);
54 struct xfs_group *xfs_group_next_range(struct xfs_mount *mp,
55 		struct xfs_group *xg, uint32_t start_index, uint32_t end_index,
56 		enum xfs_group_type type);
57 struct xfs_group *xfs_group_grab_next_mark(struct xfs_mount *mp,
58 		struct xfs_group *xg, xa_mark_t mark, enum xfs_group_type type);
59 void xfs_group_rele(struct xfs_group *xg);
60 
61 void xfs_group_free(struct xfs_mount *mp, uint32_t index,
62 		enum xfs_group_type type, void (*uninit)(struct xfs_group *xg));
63 int xfs_group_insert(struct xfs_mount *mp, struct xfs_group *xg,
64 		uint32_t index, enum xfs_group_type);
65 
66 #define xfs_group_set_mark(_xg, _mark) \
67 	xa_set_mark(&(_xg)->xg_mount->m_groups[(_xg)->xg_type].xa, \
68 			(_xg)->xg_gno, (_mark))
69 #define xfs_group_clear_mark(_xg, _mark) \
70 	xa_clear_mark(&(_xg)->xg_mount->m_groups[(_xg)->xg_type].xa, \
71 			(_xg)->xg_gno, (_mark))
72 #define xfs_group_marked(_mp, _type, _mark) \
73 	xa_marked(&(_mp)->m_groups[(_type)].xa, (_mark))
74 
75 #endif /* __LIBXFS_GROUP_H */
76