1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (C) 2016 Oracle.  All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 */
6#ifndef __XFS_AG_RESV_H__
7#define	__XFS_AG_RESV_H__
8
9int xfs_ag_resv_free(struct xfs_perag *pag);
10int xfs_ag_resv_init(struct xfs_perag *pag, struct xfs_trans *tp);
11
12bool xfs_ag_resv_critical(struct xfs_perag *pag, enum xfs_ag_resv_type type);
13xfs_extlen_t xfs_ag_resv_needed(struct xfs_perag *pag,
14		enum xfs_ag_resv_type type);
15
16void xfs_ag_resv_alloc_extent(struct xfs_perag *pag, enum xfs_ag_resv_type type,
17		struct xfs_alloc_arg *args);
18void xfs_ag_resv_free_extent(struct xfs_perag *pag, enum xfs_ag_resv_type type,
19		struct xfs_trans *tp, xfs_extlen_t len);
20
21static inline struct xfs_ag_resv *
22xfs_perag_resv(
23	struct xfs_perag	*pag,
24	enum xfs_ag_resv_type	type)
25{
26	switch (type) {
27	case XFS_AG_RESV_METADATA:
28		return &pag->pag_meta_resv;
29	case XFS_AG_RESV_RMAPBT:
30		return &pag->pag_rmapbt_resv;
31	default:
32		return NULL;
33	}
34}
35
36/*
37 * RMAPBT reservation accounting wrappers. Since rmapbt blocks are sourced from
38 * the AGFL, they are allocated one at a time and the reservation updates don't
39 * require a transaction.
40 */
41static inline void
42xfs_ag_resv_rmapbt_alloc(
43	struct xfs_mount	*mp,
44	xfs_agnumber_t		agno)
45{
46	struct xfs_alloc_arg	args = { NULL };
47	struct xfs_perag	*pag;
48
49	args.len = 1;
50	pag = xfs_perag_get(mp, agno);
51	xfs_ag_resv_alloc_extent(pag, XFS_AG_RESV_RMAPBT, &args);
52	xfs_perag_put(pag);
53}
54
55#endif	/* __XFS_AG_RESV_H__ */
56