162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2016 Oracle.  All Rights Reserved.
462306a36Sopenharmony_ci * Author: Darrick J. Wong <darrick.wong@oracle.com>
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef __XFS_AG_RESV_H__
762306a36Sopenharmony_ci#define	__XFS_AG_RESV_H__
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciint xfs_ag_resv_free(struct xfs_perag *pag);
1062306a36Sopenharmony_ciint xfs_ag_resv_init(struct xfs_perag *pag, struct xfs_trans *tp);
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cibool xfs_ag_resv_critical(struct xfs_perag *pag, enum xfs_ag_resv_type type);
1362306a36Sopenharmony_cixfs_extlen_t xfs_ag_resv_needed(struct xfs_perag *pag,
1462306a36Sopenharmony_ci		enum xfs_ag_resv_type type);
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_civoid xfs_ag_resv_alloc_extent(struct xfs_perag *pag, enum xfs_ag_resv_type type,
1762306a36Sopenharmony_ci		struct xfs_alloc_arg *args);
1862306a36Sopenharmony_civoid xfs_ag_resv_free_extent(struct xfs_perag *pag, enum xfs_ag_resv_type type,
1962306a36Sopenharmony_ci		struct xfs_trans *tp, xfs_extlen_t len);
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_cistatic inline struct xfs_ag_resv *
2262306a36Sopenharmony_cixfs_perag_resv(
2362306a36Sopenharmony_ci	struct xfs_perag	*pag,
2462306a36Sopenharmony_ci	enum xfs_ag_resv_type	type)
2562306a36Sopenharmony_ci{
2662306a36Sopenharmony_ci	switch (type) {
2762306a36Sopenharmony_ci	case XFS_AG_RESV_METADATA:
2862306a36Sopenharmony_ci		return &pag->pag_meta_resv;
2962306a36Sopenharmony_ci	case XFS_AG_RESV_RMAPBT:
3062306a36Sopenharmony_ci		return &pag->pag_rmapbt_resv;
3162306a36Sopenharmony_ci	default:
3262306a36Sopenharmony_ci		return NULL;
3362306a36Sopenharmony_ci	}
3462306a36Sopenharmony_ci}
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci/*
3762306a36Sopenharmony_ci * RMAPBT reservation accounting wrappers. Since rmapbt blocks are sourced from
3862306a36Sopenharmony_ci * the AGFL, they are allocated one at a time and the reservation updates don't
3962306a36Sopenharmony_ci * require a transaction.
4062306a36Sopenharmony_ci */
4162306a36Sopenharmony_cistatic inline void
4262306a36Sopenharmony_cixfs_ag_resv_rmapbt_alloc(
4362306a36Sopenharmony_ci	struct xfs_mount	*mp,
4462306a36Sopenharmony_ci	xfs_agnumber_t		agno)
4562306a36Sopenharmony_ci{
4662306a36Sopenharmony_ci	struct xfs_alloc_arg	args = { NULL };
4762306a36Sopenharmony_ci	struct xfs_perag	*pag;
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci	args.len = 1;
5062306a36Sopenharmony_ci	pag = xfs_perag_get(mp, agno);
5162306a36Sopenharmony_ci	xfs_ag_resv_alloc_extent(pag, XFS_AG_RESV_RMAPBT, &args);
5262306a36Sopenharmony_ci	xfs_perag_put(pag);
5362306a36Sopenharmony_ci}
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci#endif	/* __XFS_AG_RESV_H__ */
56