Linux Audio

Check our new training course

Loading...
v6.9.4
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Copyright (c) 2018 Red Hat, Inc.
  4 * All rights reserved.
  5 */
  6
  7#ifndef __LIBXFS_AG_H
  8#define __LIBXFS_AG_H 1
  9
 
 
 10struct xfs_mount;
 11struct xfs_trans;
 12struct xfs_perag;
 13
 14/*
 15 * Per-ag infrastructure
 16 */
 17
 18/* per-AG block reservation data structures*/
 19struct xfs_ag_resv {
 20	/* number of blocks originally reserved here */
 21	xfs_extlen_t			ar_orig_reserved;
 22	/* number of blocks reserved here */
 23	xfs_extlen_t			ar_reserved;
 24	/* number of blocks originally asked for */
 25	xfs_extlen_t			ar_asked;
 26};
 27
 28/*
 29 * Per-ag incore structure, copies of information in agf and agi, to improve the
 30 * performance of allocation group selection.
 31 */
 32struct xfs_perag {
 33	struct xfs_mount *pag_mount;	/* owner filesystem */
 34	xfs_agnumber_t	pag_agno;	/* AG this structure belongs to */
 35	atomic_t	pag_ref;	/* passive reference count */
 36	atomic_t	pag_active_ref;	/* active reference count */
 37	wait_queue_head_t pag_active_wq;/* woken active_ref falls to zero */
 38	unsigned long	pag_opstate;
 39	uint8_t		pagf_bno_level;	/* # of levels in bno btree */
 40	uint8_t		pagf_cnt_level;	/* # of levels in cnt btree */
 41	uint8_t		pagf_rmap_level;/* # of levels in rmap btree */
 42	uint32_t	pagf_flcount;	/* count of blocks in freelist */
 43	xfs_extlen_t	pagf_freeblks;	/* total free blocks */
 44	xfs_extlen_t	pagf_longest;	/* longest free space */
 45	uint32_t	pagf_btreeblks;	/* # of blocks held in AGF btrees */
 46	xfs_agino_t	pagi_freecount;	/* number of free inodes */
 47	xfs_agino_t	pagi_count;	/* number of allocated inodes */
 48
 49	/*
 50	 * Inode allocation search lookup optimisation.
 51	 * If the pagino matches, the search for new inodes
 52	 * doesn't need to search the near ones again straight away
 53	 */
 54	xfs_agino_t	pagl_pagino;
 55	xfs_agino_t	pagl_leftrec;
 56	xfs_agino_t	pagl_rightrec;
 57
 58	int		pagb_count;	/* pagb slots in use */
 59	uint8_t		pagf_refcount_level; /* recount btree height */
 60
 61	/* Blocks reserved for all kinds of metadata. */
 62	struct xfs_ag_resv	pag_meta_resv;
 63	/* Blocks reserved for the reverse mapping btree. */
 64	struct xfs_ag_resv	pag_rmapbt_resv;
 65
 66	/* for rcu-safe freeing */
 67	struct rcu_head	rcu_head;
 68
 69	/* Precalculated geometry info */
 70	xfs_agblock_t		block_count;
 71	xfs_agblock_t		min_block;
 72	xfs_agino_t		agino_min;
 73	xfs_agino_t		agino_max;
 74
 75#ifdef __KERNEL__
 76	/* -- kernel only structures below this line -- */
 77
 78	/*
 79	 * Bitsets of per-ag metadata that have been checked and/or are sick.
 80	 * Callers should hold pag_state_lock before accessing this field.
 81	 */
 82	uint16_t	pag_checked;
 83	uint16_t	pag_sick;
 84
 85#ifdef CONFIG_XFS_ONLINE_REPAIR
 86	/*
 87	 * Alternate btree heights so that online repair won't trip the write
 88	 * verifiers while rebuilding the AG btrees.
 89	 */
 90	uint8_t		pagf_repair_bno_level;
 91	uint8_t		pagf_repair_cnt_level;
 92	uint8_t		pagf_repair_refcount_level;
 93	uint8_t		pagf_repair_rmap_level;
 94#endif
 95
 96	spinlock_t	pag_state_lock;
 97
 98	spinlock_t	pagb_lock;	/* lock for pagb_tree */
 99	struct rb_root	pagb_tree;	/* ordered tree of busy extents */
100	unsigned int	pagb_gen;	/* generation count for pagb_tree */
101	wait_queue_head_t pagb_wait;	/* woken when pagb_gen changes */
102
103	atomic_t        pagf_fstrms;    /* # of filestreams active in this AG */
104
105	spinlock_t	pag_ici_lock;	/* incore inode cache lock */
106	struct radix_tree_root pag_ici_root;	/* incore inode cache root */
107	int		pag_ici_reclaimable;	/* reclaimable inodes */
108	unsigned long	pag_ici_reclaim_cursor;	/* reclaim restart point */
109
110	struct xfs_buf_cache	pag_bcache;
111
112	/* background prealloc block trimming */
113	struct delayed_work	pag_blockgc_work;
114
115	/*
116	 * We use xfs_drain to track the number of deferred log intent items
117	 * that have been queued (but not yet processed) so that waiters (e.g.
118	 * scrub) will not lock resources when other threads are in the middle
119	 * of processing a chain of intent items only to find momentary
120	 * inconsistencies.
121	 */
122	struct xfs_defer_drain	pag_intents_drain;
123
124	/* Hook to feed rmapbt updates to an active online repair. */
125	struct xfs_hooks	pag_rmap_update_hooks;
126#endif /* __KERNEL__ */
127};
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129/*
130 * Per-AG operational state. These are atomic flag bits.
131 */
132#define XFS_AGSTATE_AGF_INIT		0
133#define XFS_AGSTATE_AGI_INIT		1
134#define XFS_AGSTATE_PREFERS_METADATA	2
135#define XFS_AGSTATE_ALLOWS_INODES	3
136#define XFS_AGSTATE_AGFL_NEEDS_RESET	4
137
138#define __XFS_AG_OPSTATE(name, NAME) \
139static inline bool xfs_perag_ ## name (struct xfs_perag *pag) \
140{ \
141	return test_bit(XFS_AGSTATE_ ## NAME, &pag->pag_opstate); \
142}
143
144__XFS_AG_OPSTATE(initialised_agf, AGF_INIT)
145__XFS_AG_OPSTATE(initialised_agi, AGI_INIT)
146__XFS_AG_OPSTATE(prefers_metadata, PREFERS_METADATA)
147__XFS_AG_OPSTATE(allows_inodes, ALLOWS_INODES)
148__XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET)
149
150void xfs_free_unused_perag_range(struct xfs_mount *mp, xfs_agnumber_t agstart,
151			xfs_agnumber_t agend);
152int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t agcount,
153			xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi);
 
154int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno);
155void xfs_free_perag(struct xfs_mount *mp);
156
157/* Passive AG references */
158struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno);
159struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *mp, xfs_agnumber_t agno,
160		unsigned int tag);
161struct xfs_perag *xfs_perag_hold(struct xfs_perag *pag);
162void xfs_perag_put(struct xfs_perag *pag);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
164/* Active AG references */
165struct xfs_perag *xfs_perag_grab(struct xfs_mount *, xfs_agnumber_t);
166struct xfs_perag *xfs_perag_grab_tag(struct xfs_mount *, xfs_agnumber_t,
167				   int tag);
168void xfs_perag_rele(struct xfs_perag *pag);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
170/*
171 * Per-ag geometry infomation and validation
172 */
173xfs_agblock_t xfs_ag_block_count(struct xfs_mount *mp, xfs_agnumber_t agno);
174void xfs_agino_range(struct xfs_mount *mp, xfs_agnumber_t agno,
175		xfs_agino_t *first, xfs_agino_t *last);
176
177static inline bool
178xfs_verify_agbno(struct xfs_perag *pag, xfs_agblock_t agbno)
179{
180	if (agbno >= pag->block_count)
181		return false;
182	if (agbno <= pag->min_block)
183		return false;
184	return true;
185}
186
187static inline bool
188xfs_verify_agbext(
189	struct xfs_perag	*pag,
190	xfs_agblock_t		agbno,
191	xfs_agblock_t		len)
192{
193	if (agbno + len <= agbno)
194		return false;
195
196	if (!xfs_verify_agbno(pag, agbno))
197		return false;
198
199	return xfs_verify_agbno(pag, agbno + len - 1);
200}
201
202/*
203 * Verify that an AG inode number pointer neither points outside the AG
204 * nor points at static metadata.
205 */
206static inline bool
207xfs_verify_agino(struct xfs_perag *pag, xfs_agino_t agino)
208{
209	if (agino < pag->agino_min)
210		return false;
211	if (agino > pag->agino_max)
212		return false;
213	return true;
214}
215
216/*
217 * Verify that an AG inode number pointer neither points outside the AG
218 * nor points at static metadata, or is NULLAGINO.
219 */
220static inline bool
221xfs_verify_agino_or_null(struct xfs_perag *pag, xfs_agino_t agino)
222{
223	if (agino == NULLAGINO)
224		return true;
225	return xfs_verify_agino(pag, agino);
226}
227
228static inline bool
229xfs_ag_contains_log(struct xfs_mount *mp, xfs_agnumber_t agno)
230{
231	return mp->m_sb.sb_logstart > 0 &&
232	       agno == XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart);
233}
234
235/*
236 * Perag iteration APIs
237 */
238static inline struct xfs_perag *
239xfs_perag_next(
240	struct xfs_perag	*pag,
241	xfs_agnumber_t		*agno,
242	xfs_agnumber_t		end_agno)
243{
244	struct xfs_mount	*mp = pag->pag_mount;
245
246	*agno = pag->pag_agno + 1;
247	xfs_perag_rele(pag);
248	while (*agno <= end_agno) {
249		pag = xfs_perag_grab(mp, *agno);
250		if (pag)
251			return pag;
252		(*agno)++;
253	}
254	return NULL;
255}
256
257#define for_each_perag_range(mp, agno, end_agno, pag) \
258	for ((pag) = xfs_perag_grab((mp), (agno)); \
259		(pag) != NULL; \
260		(pag) = xfs_perag_next((pag), &(agno), (end_agno)))
261
262#define for_each_perag_from(mp, agno, pag) \
263	for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount - 1, (pag))
264
265#define for_each_perag(mp, agno, pag) \
266	(agno) = 0; \
267	for_each_perag_from((mp), (agno), (pag))
268
269#define for_each_perag_tag(mp, agno, pag, tag) \
270	for ((agno) = 0, (pag) = xfs_perag_grab_tag((mp), 0, (tag)); \
271		(pag) != NULL; \
272		(agno) = (pag)->pag_agno + 1, \
273		xfs_perag_rele(pag), \
274		(pag) = xfs_perag_grab_tag((mp), (agno), (tag)))
275
276static inline struct xfs_perag *
277xfs_perag_next_wrap(
278	struct xfs_perag	*pag,
279	xfs_agnumber_t		*agno,
280	xfs_agnumber_t		stop_agno,
281	xfs_agnumber_t		restart_agno,
282	xfs_agnumber_t		wrap_agno)
283{
284	struct xfs_mount	*mp = pag->pag_mount;
285
286	*agno = pag->pag_agno + 1;
287	xfs_perag_rele(pag);
288	while (*agno != stop_agno) {
289		if (*agno >= wrap_agno) {
290			if (restart_agno >= stop_agno)
291				break;
292			*agno = restart_agno;
293		}
294
295		pag = xfs_perag_grab(mp, *agno);
296		if (pag)
297			return pag;
298		(*agno)++;
299	}
300	return NULL;
301}
302
303/*
304 * Iterate all AGs from start_agno through wrap_agno, then restart_agno through
305 * (start_agno - 1).
306 */
307#define for_each_perag_wrap_range(mp, start_agno, restart_agno, wrap_agno, agno, pag) \
308	for ((agno) = (start_agno), (pag) = xfs_perag_grab((mp), (agno)); \
309		(pag) != NULL; \
310		(pag) = xfs_perag_next_wrap((pag), &(agno), (start_agno), \
311				(restart_agno), (wrap_agno)))
312/*
313 * Iterate all AGs from start_agno through wrap_agno, then 0 through
314 * (start_agno - 1).
315 */
316#define for_each_perag_wrap_at(mp, start_agno, wrap_agno, agno, pag) \
317	for_each_perag_wrap_range((mp), (start_agno), 0, (wrap_agno), (agno), (pag))
318
319/*
320 * Iterate all AGs from start_agno through to the end of the filesystem, then 0
321 * through (start_agno - 1).
322 */
323#define for_each_perag_wrap(mp, start_agno, agno, pag) \
324	for_each_perag_wrap_at((mp), (start_agno), (mp)->m_sb.sb_agcount, \
325				(agno), (pag))
326
327
328struct aghdr_init_data {
329	/* per ag data */
330	xfs_agblock_t		agno;		/* ag to init */
331	xfs_extlen_t		agsize;		/* new AG size */
332	struct list_head	buffer_list;	/* buffer writeback list */
333	xfs_rfsblock_t		nfree;		/* cumulative new free space */
334
335	/* per header data */
336	xfs_daddr_t		daddr;		/* header location */
337	size_t			numblks;	/* size of header */
338	const struct xfs_btree_ops *bc_ops;	/* btree ops */
339};
340
341int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id);
342int xfs_ag_shrink_space(struct xfs_perag *pag, struct xfs_trans **tpp,
343			xfs_extlen_t delta);
344int xfs_ag_extend_space(struct xfs_perag *pag, struct xfs_trans *tp,
345			xfs_extlen_t len);
346int xfs_ag_get_geometry(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
348#endif /* __LIBXFS_AG_H */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Copyright (c) 2018 Red Hat, Inc.
  4 * All rights reserved.
  5 */
  6
  7#ifndef __LIBXFS_AG_H
  8#define __LIBXFS_AG_H 1
  9
 10#include "xfs_group.h"
 11
 12struct xfs_mount;
 13struct xfs_trans;
 14struct xfs_perag;
 15
 16/*
 17 * Per-ag infrastructure
 18 */
 19
 20/* per-AG block reservation data structures*/
 21struct xfs_ag_resv {
 22	/* number of blocks originally reserved here */
 23	xfs_extlen_t			ar_orig_reserved;
 24	/* number of blocks reserved here */
 25	xfs_extlen_t			ar_reserved;
 26	/* number of blocks originally asked for */
 27	xfs_extlen_t			ar_asked;
 28};
 29
 30/*
 31 * Per-ag incore structure, copies of information in agf and agi, to improve the
 32 * performance of allocation group selection.
 33 */
 34struct xfs_perag {
 35	struct xfs_group pag_group;
 
 
 
 
 36	unsigned long	pag_opstate;
 37	uint8_t		pagf_bno_level;	/* # of levels in bno btree */
 38	uint8_t		pagf_cnt_level;	/* # of levels in cnt btree */
 39	uint8_t		pagf_rmap_level;/* # of levels in rmap btree */
 40	uint32_t	pagf_flcount;	/* count of blocks in freelist */
 41	xfs_extlen_t	pagf_freeblks;	/* total free blocks */
 42	xfs_extlen_t	pagf_longest;	/* longest free space */
 43	uint32_t	pagf_btreeblks;	/* # of blocks held in AGF btrees */
 44	xfs_agino_t	pagi_freecount;	/* number of free inodes */
 45	xfs_agino_t	pagi_count;	/* number of allocated inodes */
 46
 47	/*
 48	 * Inode allocation search lookup optimisation.
 49	 * If the pagino matches, the search for new inodes
 50	 * doesn't need to search the near ones again straight away
 51	 */
 52	xfs_agino_t	pagl_pagino;
 53	xfs_agino_t	pagl_leftrec;
 54	xfs_agino_t	pagl_rightrec;
 55
 
 56	uint8_t		pagf_refcount_level; /* recount btree height */
 57
 58	/* Blocks reserved for all kinds of metadata. */
 59	struct xfs_ag_resv	pag_meta_resv;
 60	/* Blocks reserved for the reverse mapping btree. */
 61	struct xfs_ag_resv	pag_rmapbt_resv;
 62
 
 
 
 63	/* Precalculated geometry info */
 
 
 64	xfs_agino_t		agino_min;
 65	xfs_agino_t		agino_max;
 66
 67#ifdef __KERNEL__
 68	/* -- kernel only structures below this line -- */
 69
 
 
 
 
 
 
 
 70#ifdef CONFIG_XFS_ONLINE_REPAIR
 71	/*
 72	 * Alternate btree heights so that online repair won't trip the write
 73	 * verifiers while rebuilding the AG btrees.
 74	 */
 75	uint8_t		pagf_repair_bno_level;
 76	uint8_t		pagf_repair_cnt_level;
 77	uint8_t		pagf_repair_refcount_level;
 78	uint8_t		pagf_repair_rmap_level;
 79#endif
 80
 
 
 
 
 
 
 
 81	atomic_t        pagf_fstrms;    /* # of filestreams active in this AG */
 82
 83	spinlock_t	pag_ici_lock;	/* incore inode cache lock */
 84	struct radix_tree_root pag_ici_root;	/* incore inode cache root */
 85	int		pag_ici_reclaimable;	/* reclaimable inodes */
 86	unsigned long	pag_ici_reclaim_cursor;	/* reclaim restart point */
 87
 88	struct xfs_buf_cache	pag_bcache;
 89
 90	/* background prealloc block trimming */
 91	struct delayed_work	pag_blockgc_work;
 
 
 
 
 
 
 
 
 
 
 
 
 92#endif /* __KERNEL__ */
 93};
 94
 95static inline struct xfs_perag *to_perag(struct xfs_group *xg)
 96{
 97	return container_of(xg, struct xfs_perag, pag_group);
 98}
 99
100static inline struct xfs_group *pag_group(struct xfs_perag *pag)
101{
102	return &pag->pag_group;
103}
104
105static inline struct xfs_mount *pag_mount(const struct xfs_perag *pag)
106{
107	return pag->pag_group.xg_mount;
108}
109
110static inline xfs_agnumber_t pag_agno(const struct xfs_perag *pag)
111{
112	return pag->pag_group.xg_gno;
113}
114
115/*
116 * Per-AG operational state. These are atomic flag bits.
117 */
118#define XFS_AGSTATE_AGF_INIT		0
119#define XFS_AGSTATE_AGI_INIT		1
120#define XFS_AGSTATE_PREFERS_METADATA	2
121#define XFS_AGSTATE_ALLOWS_INODES	3
122#define XFS_AGSTATE_AGFL_NEEDS_RESET	4
123
124#define __XFS_AG_OPSTATE(name, NAME) \
125static inline bool xfs_perag_ ## name (struct xfs_perag *pag) \
126{ \
127	return test_bit(XFS_AGSTATE_ ## NAME, &pag->pag_opstate); \
128}
129
130__XFS_AG_OPSTATE(initialised_agf, AGF_INIT)
131__XFS_AG_OPSTATE(initialised_agi, AGI_INIT)
132__XFS_AG_OPSTATE(prefers_metadata, PREFERS_METADATA)
133__XFS_AG_OPSTATE(allows_inodes, ALLOWS_INODES)
134__XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET)
135
136int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t orig_agcount,
137		xfs_agnumber_t new_agcount, xfs_rfsblock_t dcount,
138		xfs_agnumber_t *maxagi);
139void xfs_free_perag_range(struct xfs_mount *mp, xfs_agnumber_t first_agno,
140		xfs_agnumber_t end_agno);
141int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno);
142int xfs_update_last_ag_size(struct xfs_mount *mp, xfs_agnumber_t prev_agcount);
143
144/* Passive AG references */
145static inline struct xfs_perag *
146xfs_perag_get(
147	struct xfs_mount	*mp,
148	xfs_agnumber_t		agno)
149{
150	return to_perag(xfs_group_get(mp, agno, XG_TYPE_AG));
151}
152
153static inline struct xfs_perag *
154xfs_perag_hold(
155	struct xfs_perag	*pag)
156{
157	return to_perag(xfs_group_hold(pag_group(pag)));
158}
159
160static inline void
161xfs_perag_put(
162	struct xfs_perag	*pag)
163{
164	xfs_group_put(pag_group(pag));
165}
166
167/* Active AG references */
168static inline struct xfs_perag *
169xfs_perag_grab(
170	struct xfs_mount	*mp,
171	xfs_agnumber_t		agno)
172{
173	return to_perag(xfs_group_grab(mp, agno, XG_TYPE_AG));
174}
175
176static inline void
177xfs_perag_rele(
178	struct xfs_perag	*pag)
179{
180	xfs_group_rele(pag_group(pag));
181}
182
183static inline struct xfs_perag *
184xfs_perag_next_range(
185	struct xfs_mount	*mp,
186	struct xfs_perag	*pag,
187	xfs_agnumber_t		start_agno,
188	xfs_agnumber_t		end_agno)
189{
190	return to_perag(xfs_group_next_range(mp, pag ? pag_group(pag) : NULL,
191			start_agno, end_agno, XG_TYPE_AG));
192}
193
194static inline struct xfs_perag *
195xfs_perag_next_from(
196	struct xfs_mount	*mp,
197	struct xfs_perag	*pag,
198	xfs_agnumber_t		start_agno)
199{
200	return xfs_perag_next_range(mp, pag, start_agno, mp->m_sb.sb_agcount - 1);
201}
202
203static inline struct xfs_perag *
204xfs_perag_next(
205	struct xfs_mount	*mp,
206	struct xfs_perag	*pag)
207{
208	return xfs_perag_next_from(mp, pag, 0);
209}
210
211/*
212 * Per-ag geometry infomation and validation
213 */
214xfs_agblock_t xfs_ag_block_count(struct xfs_mount *mp, xfs_agnumber_t agno);
215void xfs_agino_range(struct xfs_mount *mp, xfs_agnumber_t agno,
216		xfs_agino_t *first, xfs_agino_t *last);
217
218static inline bool
219xfs_verify_agbno(struct xfs_perag *pag, xfs_agblock_t agbno)
220{
221	return xfs_verify_gbno(pag_group(pag), agbno);
 
 
 
 
222}
223
224static inline bool
225xfs_verify_agbext(
226	struct xfs_perag	*pag,
227	xfs_agblock_t		agbno,
228	xfs_agblock_t		len)
229{
230	return xfs_verify_gbext(pag_group(pag), agbno, len);
 
 
 
 
 
 
231}
232
233/*
234 * Verify that an AG inode number pointer neither points outside the AG
235 * nor points at static metadata.
236 */
237static inline bool
238xfs_verify_agino(struct xfs_perag *pag, xfs_agino_t agino)
239{
240	if (agino < pag->agino_min)
241		return false;
242	if (agino > pag->agino_max)
243		return false;
244	return true;
245}
246
247/*
248 * Verify that an AG inode number pointer neither points outside the AG
249 * nor points at static metadata, or is NULLAGINO.
250 */
251static inline bool
252xfs_verify_agino_or_null(struct xfs_perag *pag, xfs_agino_t agino)
253{
254	if (agino == NULLAGINO)
255		return true;
256	return xfs_verify_agino(pag, agino);
257}
258
259static inline bool
260xfs_ag_contains_log(struct xfs_mount *mp, xfs_agnumber_t agno)
261{
262	return mp->m_sb.sb_logstart > 0 &&
263	       agno == XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart);
264}
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266static inline struct xfs_perag *
267xfs_perag_next_wrap(
268	struct xfs_perag	*pag,
269	xfs_agnumber_t		*agno,
270	xfs_agnumber_t		stop_agno,
271	xfs_agnumber_t		restart_agno,
272	xfs_agnumber_t		wrap_agno)
273{
274	struct xfs_mount	*mp = pag_mount(pag);
275
276	*agno = pag_agno(pag) + 1;
277	xfs_perag_rele(pag);
278	while (*agno != stop_agno) {
279		if (*agno >= wrap_agno) {
280			if (restart_agno >= stop_agno)
281				break;
282			*agno = restart_agno;
283		}
284
285		pag = xfs_perag_grab(mp, *agno);
286		if (pag)
287			return pag;
288		(*agno)++;
289	}
290	return NULL;
291}
292
293/*
294 * Iterate all AGs from start_agno through wrap_agno, then restart_agno through
295 * (start_agno - 1).
296 */
297#define for_each_perag_wrap_range(mp, start_agno, restart_agno, wrap_agno, agno, pag) \
298	for ((agno) = (start_agno), (pag) = xfs_perag_grab((mp), (agno)); \
299		(pag) != NULL; \
300		(pag) = xfs_perag_next_wrap((pag), &(agno), (start_agno), \
301				(restart_agno), (wrap_agno)))
302/*
303 * Iterate all AGs from start_agno through wrap_agno, then 0 through
304 * (start_agno - 1).
305 */
306#define for_each_perag_wrap_at(mp, start_agno, wrap_agno, agno, pag) \
307	for_each_perag_wrap_range((mp), (start_agno), 0, (wrap_agno), (agno), (pag))
308
309/*
310 * Iterate all AGs from start_agno through to the end of the filesystem, then 0
311 * through (start_agno - 1).
312 */
313#define for_each_perag_wrap(mp, start_agno, agno, pag) \
314	for_each_perag_wrap_at((mp), (start_agno), (mp)->m_sb.sb_agcount, \
315				(agno), (pag))
316
317
318struct aghdr_init_data {
319	/* per ag data */
320	xfs_agblock_t		agno;		/* ag to init */
321	xfs_extlen_t		agsize;		/* new AG size */
322	struct list_head	buffer_list;	/* buffer writeback list */
323	xfs_rfsblock_t		nfree;		/* cumulative new free space */
324
325	/* per header data */
326	xfs_daddr_t		daddr;		/* header location */
327	size_t			numblks;	/* size of header */
328	const struct xfs_btree_ops *bc_ops;	/* btree ops */
329};
330
331int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id);
332int xfs_ag_shrink_space(struct xfs_perag *pag, struct xfs_trans **tpp,
333			xfs_extlen_t delta);
334int xfs_ag_extend_space(struct xfs_perag *pag, struct xfs_trans *tp,
335			xfs_extlen_t len);
336int xfs_ag_get_geometry(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
337
338static inline xfs_fsblock_t
339xfs_agbno_to_fsb(
340	struct xfs_perag	*pag,
341	xfs_agblock_t		agbno)
342{
343	return XFS_AGB_TO_FSB(pag_mount(pag), pag_agno(pag), agbno);
344}
345
346static inline xfs_daddr_t
347xfs_agbno_to_daddr(
348	struct xfs_perag	*pag,
349	xfs_agblock_t		agbno)
350{
351	return XFS_AGB_TO_DADDR(pag_mount(pag), pag_agno(pag), agbno);
352}
353
354static inline xfs_ino_t
355xfs_agino_to_ino(
356	struct xfs_perag	*pag,
357	xfs_agino_t		agino)
358{
359	return XFS_AGINO_TO_INO(pag_mount(pag), pag_agno(pag), agino);
360}
361
362#endif /* __LIBXFS_AG_H */