xref: /freebsd/sys/contrib/openzfs/include/sys/bptree.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24  */
25 
26 #ifndef	_SYS_BPTREE_H
27 #define	_SYS_BPTREE_H
28 
29 #include <sys/spa.h>
30 #include <sys/zio.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct bptree_phys {
37 	uint64_t bt_begin;
38 	uint64_t bt_end;
39 	uint64_t bt_bytes;
40 	uint64_t bt_comp;
41 	uint64_t bt_uncomp;
42 } bptree_phys_t;
43 
44 typedef struct bptree_entry_phys {
45 	blkptr_t be_bp;
46 	uint64_t be_birth_txg; /* only delete blocks born after this txg */
47 	zbookmark_phys_t be_zb; /* holds traversal resume point if needed */
48 } bptree_entry_phys_t;
49 
50 typedef int bptree_itor_t(void *arg, const blkptr_t *bp, dmu_tx_t *tx);
51 
52 uint64_t bptree_alloc(objset_t *os, dmu_tx_t *tx);
53 int bptree_free(objset_t *os, uint64_t obj, dmu_tx_t *tx);
54 boolean_t bptree_is_empty(objset_t *os, uint64_t obj);
55 
56 void bptree_add(objset_t *os, uint64_t obj, blkptr_t *bp, uint64_t birth_txg,
57     uint64_t bytes, uint64_t comp, uint64_t uncomp, dmu_tx_t *tx);
58 
59 int bptree_iterate(objset_t *os, uint64_t obj, boolean_t free,
60     bptree_itor_t func, void *arg, dmu_tx_t *tx);
61 
62 #ifdef	__cplusplus
63 }
64 #endif
65 
66 #endif	/* _SYS_BPTREE_H */
67