blob: 4a118131059fc836cf0b3038aec844253d87e615 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Dave Chinnerefc27b52012-04-29 10:39:43 +00002/*
3 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
4 * Copyright (c) 2010 David Chinner.
5 * Copyright (c) 2011 Christoph Hellwig.
6 * All Rights Reserved.
Dave Chinnerefc27b52012-04-29 10:39:43 +00007 */
8#ifndef __XFS_EXTENT_BUSY_H__
9#define __XFS_EXTENT_BUSY_H__
10
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110011struct xfs_mount;
Dave Chinner45d06622021-06-02 10:48:24 +100012struct xfs_perag;
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110013struct xfs_trans;
14struct xfs_alloc_arg;
15
Dave Chinnerefc27b52012-04-29 10:39:43 +000016/*
17 * Busy block/extent entry. Indexed by a rbtree in perag to mark blocks that
18 * have been freed but whose transactions aren't committed to disk yet.
19 *
20 * Note that we use the transaction ID to record the transaction, not the
21 * transaction structure itself. See xfs_extent_busy_insert() for details.
22 */
Dave Chinner4ecbfe62012-04-29 10:41:10 +000023struct xfs_extent_busy {
Dave Chinnerefc27b52012-04-29 10:39:43 +000024 struct rb_node rb_node; /* ag by-bno indexed search tree */
25 struct list_head list; /* transaction busy extent list */
26 xfs_agnumber_t agno;
27 xfs_agblock_t bno;
28 xfs_extlen_t length;
29 unsigned int flags;
Dave Chinner4ecbfe62012-04-29 10:41:10 +000030#define XFS_EXTENT_BUSY_DISCARDED 0x01 /* undergoing a discard op. */
31#define XFS_EXTENT_BUSY_SKIP_DISCARD 0x02 /* do not discard */
Dave Chinnerefc27b52012-04-29 10:39:43 +000032};
33
34void
Dave Chinner45d06622021-06-02 10:48:24 +100035xfs_extent_busy_insert(struct xfs_trans *tp, struct xfs_perag *pag,
Dave Chinnerefc27b52012-04-29 10:39:43 +000036 xfs_agblock_t bno, xfs_extlen_t len, unsigned int flags);
37
38void
Dave Chinner4ecbfe62012-04-29 10:41:10 +000039xfs_extent_busy_clear(struct xfs_mount *mp, struct list_head *list,
Dave Chinnerefc27b52012-04-29 10:39:43 +000040 bool do_discard);
41
42int
Dave Chinner45d06622021-06-02 10:48:24 +100043xfs_extent_busy_search(struct xfs_mount *mp, struct xfs_perag *pag,
Dave Chinnerefc27b52012-04-29 10:39:43 +000044 xfs_agblock_t bno, xfs_extlen_t len);
45
46void
Dave Chinner45d06622021-06-02 10:48:24 +100047xfs_extent_busy_reuse(struct xfs_mount *mp, struct xfs_perag *pag,
Dave Chinnerefc27b52012-04-29 10:39:43 +000048 xfs_agblock_t fbno, xfs_extlen_t flen, bool userdata);
49
Christoph Hellwigebf55872017-02-07 14:06:57 -080050bool
51xfs_extent_busy_trim(struct xfs_alloc_arg *args, xfs_agblock_t *bno,
52 xfs_extlen_t *len, unsigned *busy_gen);
53
Ben Myerse700a062012-05-10 13:55:33 -050054void
Christoph Hellwigebf55872017-02-07 14:06:57 -080055xfs_extent_busy_flush(struct xfs_mount *mp, struct xfs_perag *pag,
56 unsigned busy_gen);
57
58void
59xfs_extent_busy_wait_all(struct xfs_mount *mp);
Ben Myerse700a062012-05-10 13:55:33 -050060
Dave Chinnerefc27b52012-04-29 10:39:43 +000061int
Sami Tolvanen4f0f5862021-04-08 11:28:34 -070062xfs_extent_busy_ag_cmp(void *priv, const struct list_head *a,
63 const struct list_head *b);
Dave Chinnerefc27b52012-04-29 10:39:43 +000064
Dave Chinner4ecbfe62012-04-29 10:41:10 +000065static inline void xfs_extent_busy_sort(struct list_head *list)
Dave Chinnerefc27b52012-04-29 10:39:43 +000066{
Dave Chinner4ecbfe62012-04-29 10:41:10 +000067 list_sort(NULL, list, xfs_extent_busy_ag_cmp);
Dave Chinnerefc27b52012-04-29 10:39:43 +000068}
69
70#endif /* __XFS_EXTENT_BUSY_H__ */