xfs_alloc.h 8.4 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
L
Linus Torvalds 已提交
2
/*
3 4
 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
 * All Rights Reserved.
L
Linus Torvalds 已提交
5 6 7 8 9
 */
#ifndef __XFS_ALLOC_H__
#define	__XFS_ALLOC_H__

struct xfs_buf;
C
Christoph Hellwig 已提交
10
struct xfs_btree_cur;
L
Linus Torvalds 已提交
11 12 13 14
struct xfs_mount;
struct xfs_perag;
struct xfs_trans;

15 16
extern struct workqueue_struct *xfs_alloc_wq;

17 18
unsigned int xfs_agfl_size(struct xfs_mount *mp);

L
Linus Torvalds 已提交
19 20 21
/*
 * Freespace allocation types.  Argument to xfs_alloc_[v]extent.
 */
22 23 24 25 26 27 28 29
#define XFS_ALLOCTYPE_FIRST_AG	0x02	/* ... start at ag 0 */
#define XFS_ALLOCTYPE_THIS_AG	0x08	/* anywhere in this a.g. */
#define XFS_ALLOCTYPE_START_BNO	0x10	/* near this block else anywhere */
#define XFS_ALLOCTYPE_NEAR_BNO	0x20	/* in this a.g. and near this block */
#define XFS_ALLOCTYPE_THIS_BNO	0x40	/* at exactly this block */

/* this should become an enum again when the tracing code is fixed */
typedef unsigned int xfs_alloctype_t;
L
Linus Torvalds 已提交
30

C
Christoph Hellwig 已提交
31 32 33 34 35 36 37
#define XFS_ALLOC_TYPES \
	{ XFS_ALLOCTYPE_FIRST_AG,	"FIRST_AG" }, \
	{ XFS_ALLOCTYPE_THIS_AG,	"THIS_AG" }, \
	{ XFS_ALLOCTYPE_START_BNO,	"START_BNO" }, \
	{ XFS_ALLOCTYPE_NEAR_BNO,	"NEAR_BNO" }, \
	{ XFS_ALLOCTYPE_THIS_BNO,	"THIS_BNO" }

L
Linus Torvalds 已提交
38 39 40 41
/*
 * Flags for xfs_alloc_fix_freelist.
 */
#define	XFS_ALLOC_FLAG_TRYLOCK	0x00000001  /* use trylock for buffer locking */
42
#define	XFS_ALLOC_FLAG_FREEING	0x00000002  /* indicate caller is freeing extents*/
43 44
#define	XFS_ALLOC_FLAG_NORMAP	0x00000004  /* don't modify the rmapbt */
#define	XFS_ALLOC_FLAG_NOSHRINK	0x00000008  /* don't shrink the freelist */
45
#define	XFS_ALLOC_FLAG_CHECK	0x00000010  /* test only, don't modify args */
L
Linus Torvalds 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

/*
 * Argument structure for xfs_alloc routines.
 * This is turned into a structure to avoid having 20 arguments passed
 * down several levels of the stack.
 */
typedef struct xfs_alloc_arg {
	struct xfs_trans *tp;		/* transaction pointer */
	struct xfs_mount *mp;		/* file system mount point */
	struct xfs_buf	*agbp;		/* buffer for a.g. freelist header */
	struct xfs_perag *pag;		/* per-ag struct for this agno */
	xfs_fsblock_t	fsbno;		/* file system block number */
	xfs_agnumber_t	agno;		/* allocation group number */
	xfs_agblock_t	agbno;		/* allocation group-relative block # */
	xfs_extlen_t	minlen;		/* minimum size of extent */
	xfs_extlen_t	maxlen;		/* maximum size of extent */
	xfs_extlen_t	mod;		/* mod value for extent size */
	xfs_extlen_t	prod;		/* prod value for extent size */
	xfs_extlen_t	minleft;	/* min blocks must be left after us */
	xfs_extlen_t	total;		/* total blocks needed in xaction */
	xfs_extlen_t	alignment;	/* align answer to multiple of this */
	xfs_extlen_t	minalignslop;	/* slop for minlen+alignment calcs */
68 69
	xfs_agblock_t	min_agbno;	/* set an agbno range for NEAR allocs */
	xfs_agblock_t	max_agbno;	/* ... */
L
Linus Torvalds 已提交
70 71 72
	xfs_extlen_t	len;		/* output: actual size of extent */
	xfs_alloctype_t	type;		/* allocation type XFS_ALLOCTYPE_... */
	xfs_alloctype_t	otype;		/* original allocation type */
73
	int		datatype;	/* mask defining data type treatment */
L
Linus Torvalds 已提交
74 75
	char		wasdel;		/* set if allocation was prev delayed */
	char		wasfromfl;	/* set if allocation is from freelist */
76
	struct xfs_owner_info	oinfo;	/* owner of blocks being allocated */
77
	enum xfs_ag_resv_type	resv;	/* block reservation to use */
78 79 80
#ifdef DEBUG
	bool		alloc_minlen_only; /* allocate exact minlen extent */
#endif
L
Linus Torvalds 已提交
81 82 83
} xfs_alloc_arg_t;

/*
84
 * Defines for datatype
L
Linus Torvalds 已提交
85
 */
86 87
#define XFS_ALLOC_USERDATA		(1 << 0)/* allocation is for user data*/
#define XFS_ALLOC_INITIAL_USER_DATA	(1 << 1)/* special case start of file */
88
#define XFS_ALLOC_NOBUSY		(1 << 2)/* Busy extents not allowed */
89

90 91 92 93
/* freespace limit calculations */
unsigned int xfs_alloc_set_aside(struct xfs_mount *mp);
unsigned int xfs_alloc_ag_max_usable(struct xfs_mount *mp);

94 95
xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
		xfs_extlen_t need, xfs_extlen_t reserved);
96
unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
97
		struct xfs_perag *pag);
98 99
int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
		struct xfs_buf *agfbp, xfs_agblock_t *bnop, int	 btreeblk);
100 101 102
int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
		struct xfs_buf *agfbp, struct xfs_buf *agflbp,
		xfs_agblock_t bno, int btreeblk);
L
Linus Torvalds 已提交
103 104

/*
105
 * Compute and fill in value of m_alloc_maxlevels.
L
Linus Torvalds 已提交
106 107 108 109 110 111 112 113 114 115 116 117
 */
void
xfs_alloc_compute_maxlevels(
	struct xfs_mount	*mp);	/* file system mount structure */

/*
 * Log the given fields from the agf structure.
 */
void
xfs_alloc_log_agf(
	struct xfs_trans *tp,	/* transaction pointer */
	struct xfs_buf	*bp,	/* buffer for a.g. freelist header */
118
	uint32_t	fields);/* mask of fields to be logged (XFS_AGF_...) */
L
Linus Torvalds 已提交
119 120 121 122 123 124 125 126 127 128 129 130

/*
 * Allocate an extent (variable-size).
 */
int				/* error */
xfs_alloc_vextent(
	xfs_alloc_arg_t	*args);	/* allocation argument structure */

/*
 * Free an extent.
 */
int				/* error */
B
Brian Foster 已提交
131
__xfs_free_extent(
132 133 134
	struct xfs_trans	*tp,	/* transaction pointer */
	xfs_fsblock_t		bno,	/* starting block number of extent */
	xfs_extlen_t		len,	/* length of extent */
135
	const struct xfs_owner_info	*oinfo,	/* extent owner */
B
Brian Foster 已提交
136 137 138 139 140 141 142 143
	enum xfs_ag_resv_type	type,	/* block reservation type */
	bool			skip_discard);

static inline int
xfs_free_extent(
	struct xfs_trans	*tp,
	xfs_fsblock_t		bno,
	xfs_extlen_t		len,
144
	const struct xfs_owner_info	*oinfo,
B
Brian Foster 已提交
145 146 147 148 149
	enum xfs_ag_resv_type	type)
{
	return __xfs_free_extent(tp, bno, len, oinfo, type, false);
}

150 151 152 153 154 155 156
int				/* error */
xfs_alloc_lookup_le(
	struct xfs_btree_cur	*cur,	/* btree cursor */
	xfs_agblock_t		bno,	/* starting block of extent */
	xfs_extlen_t		len,	/* length of extent */
	int			*stat);	/* success/failure */

157 158 159 160 161 162 163
int				/* error */
xfs_alloc_lookup_ge(
	struct xfs_btree_cur	*cur,	/* btree cursor */
	xfs_agblock_t		bno,	/* starting block of extent */
	xfs_extlen_t		len,	/* length of extent */
	int			*stat);	/* success/failure */

C
Christoph Hellwig 已提交
164 165 166 167 168 169 170
int					/* error */
xfs_alloc_get_rec(
	struct xfs_btree_cur	*cur,	/* btree cursor */
	xfs_agblock_t		*bno,	/* output: starting block of extent */
	xfs_extlen_t		*len,	/* output: length of extent */
	int			*stat);	/* output: success/failure */

D
Dave Chinner 已提交
171 172
int xfs_read_agf(struct xfs_perag *pag, struct xfs_trans *tp, int flags,
		struct xfs_buf **agfbpp);
173 174
int xfs_alloc_read_agf(struct xfs_perag *pag, struct xfs_trans *tp, int flags,
		struct xfs_buf **agfbpp);
175 176
int xfs_alloc_read_agfl(struct xfs_mount *mp, struct xfs_trans *tp,
			xfs_agnumber_t agno, struct xfs_buf **bpp);
177 178
int xfs_free_agfl_block(struct xfs_trans *, xfs_agnumber_t, xfs_agblock_t,
			struct xfs_buf *, struct xfs_owner_info *);
179
int xfs_alloc_fix_freelist(struct xfs_alloc_arg *args, int flags);
180
int xfs_free_extent_fix_freelist(struct xfs_trans *tp, struct xfs_perag *pag,
181
		struct xfs_buf **agbp);
182

183 184
xfs_extlen_t xfs_prealloc_blocks(struct xfs_mount *mp);

185
typedef int (*xfs_alloc_query_range_fn)(
186 187 188
	struct xfs_btree_cur			*cur,
	const struct xfs_alloc_rec_incore	*rec,
	void					*priv);
189 190

int xfs_alloc_query_range(struct xfs_btree_cur *cur,
191 192
		const struct xfs_alloc_rec_incore *low_rec,
		const struct xfs_alloc_rec_incore *high_rec,
193
		xfs_alloc_query_range_fn fn, void *priv);
194 195
int xfs_alloc_query_all(struct xfs_btree_cur *cur, xfs_alloc_query_range_fn fn,
		void *priv);
196

197 198 199
int xfs_alloc_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
		xfs_extlen_t len, bool *exist);

200 201 202 203 204
typedef int (*xfs_agfl_walk_fn)(struct xfs_mount *mp, xfs_agblock_t bno,
		void *priv);
int xfs_agfl_walk(struct xfs_mount *mp, struct xfs_agf *agf,
		struct xfs_buf *agflbp, xfs_agfl_walk_fn walk_fn, void *priv);

205 206 207 208
static inline __be32 *
xfs_buf_to_agfl_bno(
	struct xfs_buf		*bp)
{
209
	if (xfs_has_crc(bp->b_mount))
210 211 212 213
		return bp->b_addr + sizeof(struct xfs_agfl);
	return bp->b_addr;
}

214 215 216 217 218 219 220 221 222 223
void __xfs_free_extent_later(struct xfs_trans *tp, xfs_fsblock_t bno,
		xfs_filblks_t len, const struct xfs_owner_info *oinfo,
		bool skip_discard);

/*
 * List of extents to be free "later".
 * The list is kept sorted on xbf_startblock.
 */
struct xfs_extent_free_item {
	struct list_head	xefi_list;
224
	uint64_t		xefi_owner;
225 226
	xfs_fsblock_t		xefi_startblock;/* starting fs block number */
	xfs_extlen_t		xefi_blockcount;/* number of blocks in extent */
227
	unsigned int		xefi_flags;
228 229
};

230 231 232 233
#define XFS_EFI_SKIP_DISCARD	(1U << 0) /* don't issue discard */
#define XFS_EFI_ATTR_FORK	(1U << 1) /* freeing attr fork block */
#define XFS_EFI_BMBT_BLOCK	(1U << 2) /* freeing bmap btree block */

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
static inline void
xfs_free_extent_later(
	struct xfs_trans		*tp,
	xfs_fsblock_t			bno,
	xfs_filblks_t			len,
	const struct xfs_owner_info	*oinfo)
{
	__xfs_free_extent_later(tp, bno, len, oinfo, false);
}


extern struct kmem_cache	*xfs_extfree_item_cache;

int __init xfs_extfree_intent_init_cache(void);
void xfs_extfree_intent_destroy_cache(void);

L
Linus Torvalds 已提交
250
#endif	/* __XFS_ALLOC_H__ */