xref: /OK3568_Linux_fs/kernel/fs/xfs/xfs_extent_busy.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
4*4882a593Smuzhiyun  * Copyright (c) 2010 David Chinner.
5*4882a593Smuzhiyun  * Copyright (c) 2011 Christoph Hellwig.
6*4882a593Smuzhiyun  * All Rights Reserved.
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun #ifndef __XFS_EXTENT_BUSY_H__
9*4882a593Smuzhiyun #define	__XFS_EXTENT_BUSY_H__
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun struct xfs_mount;
12*4882a593Smuzhiyun struct xfs_trans;
13*4882a593Smuzhiyun struct xfs_alloc_arg;
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /*
16*4882a593Smuzhiyun  * Busy block/extent entry.  Indexed by a rbtree in perag to mark blocks that
17*4882a593Smuzhiyun  * have been freed but whose transactions aren't committed to disk yet.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * Note that we use the transaction ID to record the transaction, not the
20*4882a593Smuzhiyun  * transaction structure itself. See xfs_extent_busy_insert() for details.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun struct xfs_extent_busy {
23*4882a593Smuzhiyun 	struct rb_node	rb_node;	/* ag by-bno indexed search tree */
24*4882a593Smuzhiyun 	struct list_head list;		/* transaction busy extent list */
25*4882a593Smuzhiyun 	xfs_agnumber_t	agno;
26*4882a593Smuzhiyun 	xfs_agblock_t	bno;
27*4882a593Smuzhiyun 	xfs_extlen_t	length;
28*4882a593Smuzhiyun 	unsigned int	flags;
29*4882a593Smuzhiyun #define XFS_EXTENT_BUSY_DISCARDED	0x01	/* undergoing a discard op. */
30*4882a593Smuzhiyun #define XFS_EXTENT_BUSY_SKIP_DISCARD	0x02	/* do not discard */
31*4882a593Smuzhiyun };
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun void
34*4882a593Smuzhiyun xfs_extent_busy_insert(struct xfs_trans *tp, xfs_agnumber_t agno,
35*4882a593Smuzhiyun 	xfs_agblock_t bno, xfs_extlen_t len, unsigned int flags);
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun void
38*4882a593Smuzhiyun xfs_extent_busy_clear(struct xfs_mount *mp, struct list_head *list,
39*4882a593Smuzhiyun 	bool do_discard);
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun int
42*4882a593Smuzhiyun xfs_extent_busy_search(struct xfs_mount *mp, xfs_agnumber_t agno,
43*4882a593Smuzhiyun 	xfs_agblock_t bno, xfs_extlen_t len);
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun void
46*4882a593Smuzhiyun xfs_extent_busy_reuse(struct xfs_mount *mp, xfs_agnumber_t agno,
47*4882a593Smuzhiyun 	xfs_agblock_t fbno, xfs_extlen_t flen, bool userdata);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun bool
50*4882a593Smuzhiyun xfs_extent_busy_trim(struct xfs_alloc_arg *args, xfs_agblock_t *bno,
51*4882a593Smuzhiyun 		xfs_extlen_t *len, unsigned *busy_gen);
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun void
54*4882a593Smuzhiyun xfs_extent_busy_flush(struct xfs_mount *mp, struct xfs_perag *pag,
55*4882a593Smuzhiyun 	unsigned busy_gen);
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun void
58*4882a593Smuzhiyun xfs_extent_busy_wait_all(struct xfs_mount *mp);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun int
61*4882a593Smuzhiyun xfs_extent_busy_ag_cmp(void *priv, struct list_head *a, struct list_head *b);
62*4882a593Smuzhiyun 
xfs_extent_busy_sort(struct list_head * list)63*4882a593Smuzhiyun static inline void xfs_extent_busy_sort(struct list_head *list)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun 	list_sort(NULL, list, xfs_extent_busy_ag_cmp);
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun #endif /* __XFS_EXTENT_BUSY_H__ */
69