14e4d5207SChristoph Hellwig /* SPDX-License-Identifier: GPL-2.0 */
24e4d5207SChristoph Hellwig #ifndef _XFS_ZONE_ALLOC_H
34e4d5207SChristoph Hellwig #define _XFS_ZONE_ALLOC_H
44e4d5207SChristoph Hellwig
54e4d5207SChristoph Hellwig struct iomap_ioend;
64e4d5207SChristoph Hellwig struct xfs_open_zone;
74e4d5207SChristoph Hellwig
80bb21930SChristoph Hellwig struct xfs_zone_alloc_ctx {
90bb21930SChristoph Hellwig struct xfs_open_zone *open_zone;
100bb21930SChristoph Hellwig xfs_filblks_t reserved_blocks;
110bb21930SChristoph Hellwig };
120bb21930SChristoph Hellwig
130bb21930SChristoph Hellwig /*
140bb21930SChristoph Hellwig * Grab any available space, even if it is less than what the caller asked for.
150bb21930SChristoph Hellwig */
160bb21930SChristoph Hellwig #define XFS_ZR_GREEDY (1U << 0)
170bb21930SChristoph Hellwig /*
180bb21930SChristoph Hellwig * Only grab instantly available space, don't wait or GC.
190bb21930SChristoph Hellwig */
200bb21930SChristoph Hellwig #define XFS_ZR_NOWAIT (1U << 1)
210bb21930SChristoph Hellwig /*
220bb21930SChristoph Hellwig * Dip into the reserved pool.
230bb21930SChristoph Hellwig */
240bb21930SChristoph Hellwig #define XFS_ZR_RESERVED (1U << 2)
250bb21930SChristoph Hellwig
260bb21930SChristoph Hellwig int xfs_zoned_space_reserve(struct xfs_inode *ip, xfs_filblks_t count_fsb,
270bb21930SChristoph Hellwig unsigned int flags, struct xfs_zone_alloc_ctx *ac);
280bb21930SChristoph Hellwig void xfs_zoned_space_unreserve(struct xfs_inode *ip,
290bb21930SChristoph Hellwig struct xfs_zone_alloc_ctx *ac);
300bb21930SChristoph Hellwig void xfs_zoned_add_available(struct xfs_mount *mp, xfs_filblks_t count_fsb);
310bb21930SChristoph Hellwig
324e4d5207SChristoph Hellwig void xfs_zone_alloc_and_submit(struct iomap_ioend *ioend,
334e4d5207SChristoph Hellwig struct xfs_open_zone **oz);
344e4d5207SChristoph Hellwig int xfs_zone_free_blocks(struct xfs_trans *tp, struct xfs_rtgroup *rtg,
354e4d5207SChristoph Hellwig xfs_fsblock_t fsbno, xfs_filblks_t len);
364e4d5207SChristoph Hellwig int xfs_zoned_end_io(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count,
374e4d5207SChristoph Hellwig xfs_daddr_t daddr, struct xfs_open_zone *oz,
384e4d5207SChristoph Hellwig xfs_fsblock_t old_startblock);
394e4d5207SChristoph Hellwig void xfs_open_zone_put(struct xfs_open_zone *oz);
404e4d5207SChristoph Hellwig
414e4d5207SChristoph Hellwig void xfs_zoned_wake_all(struct xfs_mount *mp);
424e4d5207SChristoph Hellwig bool xfs_zone_rgbno_is_valid(struct xfs_rtgroup *rtg, xfs_rgnumber_t rgbno);
434e4d5207SChristoph Hellwig void xfs_mark_rtg_boundary(struct iomap_ioend *ioend);
444e4d5207SChristoph Hellwig
450bb21930SChristoph Hellwig uint64_t xfs_zoned_default_resblks(struct xfs_mount *mp,
460bb21930SChristoph Hellwig enum xfs_free_counter ctr);
47*5443041bSHans Holmberg void xfs_zoned_show_stats(struct seq_file *m, struct xfs_mount *mp);
480bb21930SChristoph Hellwig
494e4d5207SChristoph Hellwig #ifdef CONFIG_XFS_RT
504e4d5207SChristoph Hellwig int xfs_mount_zones(struct xfs_mount *mp);
514e4d5207SChristoph Hellwig void xfs_unmount_zones(struct xfs_mount *mp);
52080d01c4SChristoph Hellwig void xfs_zone_gc_start(struct xfs_mount *mp);
53080d01c4SChristoph Hellwig void xfs_zone_gc_stop(struct xfs_mount *mp);
544e4d5207SChristoph Hellwig #else
xfs_mount_zones(struct xfs_mount * mp)554e4d5207SChristoph Hellwig static inline int xfs_mount_zones(struct xfs_mount *mp)
564e4d5207SChristoph Hellwig {
574e4d5207SChristoph Hellwig return -EIO;
584e4d5207SChristoph Hellwig }
xfs_unmount_zones(struct xfs_mount * mp)594e4d5207SChristoph Hellwig static inline void xfs_unmount_zones(struct xfs_mount *mp)
604e4d5207SChristoph Hellwig {
614e4d5207SChristoph Hellwig }
xfs_zone_gc_start(struct xfs_mount * mp)62080d01c4SChristoph Hellwig static inline void xfs_zone_gc_start(struct xfs_mount *mp)
63080d01c4SChristoph Hellwig {
64080d01c4SChristoph Hellwig }
xfs_zone_gc_stop(struct xfs_mount * mp)65080d01c4SChristoph Hellwig static inline void xfs_zone_gc_stop(struct xfs_mount *mp)
66080d01c4SChristoph Hellwig {
67080d01c4SChristoph Hellwig }
684e4d5207SChristoph Hellwig #endif /* CONFIG_XFS_RT */
694e4d5207SChristoph Hellwig
704e4d5207SChristoph Hellwig #endif /* _XFS_ZONE_ALLOC_H */
71