18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#ifndef __XFS_RTALLOC_H__
78c2ecf20Sopenharmony_ci#define	__XFS_RTALLOC_H__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/* kernel only definitions and functions */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistruct xfs_mount;
128c2ecf20Sopenharmony_cistruct xfs_trans;
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*
158c2ecf20Sopenharmony_ci * XXX: Most of the realtime allocation functions deal in units of realtime
168c2ecf20Sopenharmony_ci * extents, not realtime blocks.  This looks funny when paired with the type
178c2ecf20Sopenharmony_ci * name and screams for a larger cleanup.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_cistruct xfs_rtalloc_rec {
208c2ecf20Sopenharmony_ci	xfs_rtblock_t		ar_startext;
218c2ecf20Sopenharmony_ci	xfs_rtblock_t		ar_extcount;
228c2ecf20Sopenharmony_ci};
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_citypedef int (*xfs_rtalloc_query_range_fn)(
258c2ecf20Sopenharmony_ci	struct xfs_trans	*tp,
268c2ecf20Sopenharmony_ci	struct xfs_rtalloc_rec	*rec,
278c2ecf20Sopenharmony_ci	void			*priv);
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#ifdef CONFIG_XFS_RT
308c2ecf20Sopenharmony_ci/*
318c2ecf20Sopenharmony_ci * Function prototypes for exported functions.
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/*
358c2ecf20Sopenharmony_ci * Allocate an extent in the realtime subvolume, with the usual allocation
368c2ecf20Sopenharmony_ci * parameters.  The length units are all in realtime extents, as is the
378c2ecf20Sopenharmony_ci * result block number.
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_ciint					/* error */
408c2ecf20Sopenharmony_cixfs_rtallocate_extent(
418c2ecf20Sopenharmony_ci	struct xfs_trans	*tp,	/* transaction pointer */
428c2ecf20Sopenharmony_ci	xfs_rtblock_t		bno,	/* starting block number to allocate */
438c2ecf20Sopenharmony_ci	xfs_extlen_t		minlen,	/* minimum length to allocate */
448c2ecf20Sopenharmony_ci	xfs_extlen_t		maxlen,	/* maximum length to allocate */
458c2ecf20Sopenharmony_ci	xfs_extlen_t		*len,	/* out: actual length allocated */
468c2ecf20Sopenharmony_ci	int			wasdel,	/* was a delayed allocation extent */
478c2ecf20Sopenharmony_ci	xfs_extlen_t		prod,	/* extent product factor */
488c2ecf20Sopenharmony_ci	xfs_rtblock_t		*rtblock); /* out: start block allocated */
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/*
518c2ecf20Sopenharmony_ci * Free an extent in the realtime subvolume.  Length is expressed in
528c2ecf20Sopenharmony_ci * realtime extents, as is the block number.
538c2ecf20Sopenharmony_ci */
548c2ecf20Sopenharmony_ciint					/* error */
558c2ecf20Sopenharmony_cixfs_rtfree_extent(
568c2ecf20Sopenharmony_ci	struct xfs_trans	*tp,	/* transaction pointer */
578c2ecf20Sopenharmony_ci	xfs_rtblock_t		bno,	/* starting block number to free */
588c2ecf20Sopenharmony_ci	xfs_extlen_t		len);	/* length of extent freed */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/*
618c2ecf20Sopenharmony_ci * Initialize realtime fields in the mount structure.
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_ciint					/* error */
648c2ecf20Sopenharmony_cixfs_rtmount_init(
658c2ecf20Sopenharmony_ci	struct xfs_mount	*mp);	/* file system mount structure */
668c2ecf20Sopenharmony_civoid
678c2ecf20Sopenharmony_cixfs_rtunmount_inodes(
688c2ecf20Sopenharmony_ci	struct xfs_mount	*mp);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/*
718c2ecf20Sopenharmony_ci * Get the bitmap and summary inodes into the mount structure
728c2ecf20Sopenharmony_ci * at mount time.
738c2ecf20Sopenharmony_ci */
748c2ecf20Sopenharmony_ciint					/* error */
758c2ecf20Sopenharmony_cixfs_rtmount_inodes(
768c2ecf20Sopenharmony_ci	struct xfs_mount	*mp);	/* file system mount structure */
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/*
798c2ecf20Sopenharmony_ci * Pick an extent for allocation at the start of a new realtime file.
808c2ecf20Sopenharmony_ci * Use the sequence number stored in the atime field of the bitmap inode.
818c2ecf20Sopenharmony_ci * Translate this to a fraction of the rtextents, and return the product
828c2ecf20Sopenharmony_ci * of rtextents and the fraction.
838c2ecf20Sopenharmony_ci * The fraction sequence is 0, 1/2, 1/4, 3/4, 1/8, ..., 7/8, 1/16, ...
848c2ecf20Sopenharmony_ci */
858c2ecf20Sopenharmony_ciint					/* error */
868c2ecf20Sopenharmony_cixfs_rtpick_extent(
878c2ecf20Sopenharmony_ci	struct xfs_mount	*mp,	/* file system mount point */
888c2ecf20Sopenharmony_ci	struct xfs_trans	*tp,	/* transaction pointer */
898c2ecf20Sopenharmony_ci	xfs_extlen_t		len,	/* allocation length (rtextents) */
908c2ecf20Sopenharmony_ci	xfs_rtblock_t		*pick);	/* result rt extent */
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/*
938c2ecf20Sopenharmony_ci * Grow the realtime area of the filesystem.
948c2ecf20Sopenharmony_ci */
958c2ecf20Sopenharmony_ciint
968c2ecf20Sopenharmony_cixfs_growfs_rt(
978c2ecf20Sopenharmony_ci	struct xfs_mount	*mp,	/* file system mount structure */
988c2ecf20Sopenharmony_ci	xfs_growfs_rt_t		*in);	/* user supplied growfs struct */
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/*
1018c2ecf20Sopenharmony_ci * From xfs_rtbitmap.c
1028c2ecf20Sopenharmony_ci */
1038c2ecf20Sopenharmony_ciint xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
1048c2ecf20Sopenharmony_ci		  xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
1058c2ecf20Sopenharmony_ciint xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
1068c2ecf20Sopenharmony_ci		      xfs_rtblock_t start, xfs_extlen_t len, int val,
1078c2ecf20Sopenharmony_ci		      xfs_rtblock_t *new, int *stat);
1088c2ecf20Sopenharmony_ciint xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
1098c2ecf20Sopenharmony_ci		    xfs_rtblock_t start, xfs_rtblock_t limit,
1108c2ecf20Sopenharmony_ci		    xfs_rtblock_t *rtblock);
1118c2ecf20Sopenharmony_ciint xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
1128c2ecf20Sopenharmony_ci		    xfs_rtblock_t start, xfs_rtblock_t limit,
1138c2ecf20Sopenharmony_ci		    xfs_rtblock_t *rtblock);
1148c2ecf20Sopenharmony_ciint xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
1158c2ecf20Sopenharmony_ci		       xfs_rtblock_t start, xfs_extlen_t len, int val);
1168c2ecf20Sopenharmony_ciint xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
1178c2ecf20Sopenharmony_ci			     int log, xfs_rtblock_t bbno, int delta,
1188c2ecf20Sopenharmony_ci			     xfs_buf_t **rbpp, xfs_fsblock_t *rsb,
1198c2ecf20Sopenharmony_ci			     xfs_suminfo_t *sum);
1208c2ecf20Sopenharmony_ciint xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
1218c2ecf20Sopenharmony_ci			 xfs_rtblock_t bbno, int delta, xfs_buf_t **rbpp,
1228c2ecf20Sopenharmony_ci			 xfs_fsblock_t *rsb);
1238c2ecf20Sopenharmony_ciint xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
1248c2ecf20Sopenharmony_ci		     xfs_rtblock_t start, xfs_extlen_t len,
1258c2ecf20Sopenharmony_ci		     struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
1268c2ecf20Sopenharmony_ciint xfs_rtalloc_query_range(struct xfs_trans *tp,
1278c2ecf20Sopenharmony_ci			    struct xfs_rtalloc_rec *low_rec,
1288c2ecf20Sopenharmony_ci			    struct xfs_rtalloc_rec *high_rec,
1298c2ecf20Sopenharmony_ci			    xfs_rtalloc_query_range_fn fn,
1308c2ecf20Sopenharmony_ci			    void *priv);
1318c2ecf20Sopenharmony_ciint xfs_rtalloc_query_all(struct xfs_trans *tp,
1328c2ecf20Sopenharmony_ci			  xfs_rtalloc_query_range_fn fn,
1338c2ecf20Sopenharmony_ci			  void *priv);
1348c2ecf20Sopenharmony_cibool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
1358c2ecf20Sopenharmony_ciint xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
1368c2ecf20Sopenharmony_ci			       xfs_rtblock_t start, xfs_extlen_t len,
1378c2ecf20Sopenharmony_ci			       bool *is_free);
1388c2ecf20Sopenharmony_ci#else
1398c2ecf20Sopenharmony_ci# define xfs_rtallocate_extent(t,b,min,max,l,f,p,rb)    (ENOSYS)
1408c2ecf20Sopenharmony_ci# define xfs_rtfree_extent(t,b,l)                       (ENOSYS)
1418c2ecf20Sopenharmony_ci# define xfs_rtpick_extent(m,t,l,rb)                    (ENOSYS)
1428c2ecf20Sopenharmony_ci# define xfs_growfs_rt(mp,in)                           (ENOSYS)
1438c2ecf20Sopenharmony_ci# define xfs_rtalloc_query_range(t,l,h,f,p)             (ENOSYS)
1448c2ecf20Sopenharmony_ci# define xfs_rtalloc_query_all(t,f,p)                   (ENOSYS)
1458c2ecf20Sopenharmony_ci# define xfs_rtbuf_get(m,t,b,i,p)                       (ENOSYS)
1468c2ecf20Sopenharmony_ci# define xfs_verify_rtbno(m, r)			(false)
1478c2ecf20Sopenharmony_ci# define xfs_rtalloc_extent_is_free(m,t,s,l,i)          (ENOSYS)
1488c2ecf20Sopenharmony_cistatic inline int		/* error */
1498c2ecf20Sopenharmony_cixfs_rtmount_init(
1508c2ecf20Sopenharmony_ci	xfs_mount_t	*mp)	/* file system mount structure */
1518c2ecf20Sopenharmony_ci{
1528c2ecf20Sopenharmony_ci	if (mp->m_sb.sb_rblocks == 0)
1538c2ecf20Sopenharmony_ci		return 0;
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	xfs_warn(mp, "Not built with CONFIG_XFS_RT");
1568c2ecf20Sopenharmony_ci	return -ENOSYS;
1578c2ecf20Sopenharmony_ci}
1588c2ecf20Sopenharmony_ci# define xfs_rtmount_inodes(m)  (((mp)->m_sb.sb_rblocks == 0)? 0 : (ENOSYS))
1598c2ecf20Sopenharmony_ci# define xfs_rtunmount_inodes(m)
1608c2ecf20Sopenharmony_ci#endif	/* CONFIG_XFS_RT */
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci#endif	/* __XFS_RTALLOC_H__ */
163