xref: /freebsd/sys/contrib/openzfs/include/sys/bpobj.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) 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright (c) 2015, 2019 by Delphix. All rights reserved.
25  */
26 
27 #ifndef	_SYS_BPOBJ_H
28 #define	_SYS_BPOBJ_H
29 
30 #include <sys/dmu.h>
31 #include <sys/spa.h>
32 #include <sys/txg.h>
33 #include <sys/zio.h>
34 #include <sys/zfs_context.h>
35 #include <sys/bplist.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 typedef struct bpobj_phys {
42 	/*
43 	 * This is the bonus buffer for the dead lists.  The object's
44 	 * contents is an array of bpo_entries blkptr_t's, representing
45 	 * a total of bpo_bytes physical space.
46 	 */
47 	uint64_t	bpo_num_blkptrs;
48 	uint64_t	bpo_bytes;
49 	uint64_t	bpo_comp;
50 	uint64_t	bpo_uncomp;
51 	uint64_t	bpo_subobjs;
52 	uint64_t	bpo_num_subobjs;
53 	uint64_t	bpo_num_freed;
54 } bpobj_phys_t;
55 
56 #define	BPOBJ_SIZE_V0	(2 * sizeof (uint64_t))
57 #define	BPOBJ_SIZE_V1	(4 * sizeof (uint64_t))
58 #define	BPOBJ_SIZE_V2	(6 * sizeof (uint64_t))
59 
60 typedef struct bpobj {
61 	kmutex_t	bpo_lock;
62 	objset_t	*bpo_os;
63 	uint64_t	bpo_object;
64 	uint32_t	bpo_epb;
65 	uint8_t		bpo_havecomp;
66 	uint8_t		bpo_havesubobj;
67 	uint8_t		bpo_havefreed;
68 	bpobj_phys_t	*bpo_phys;
69 	dmu_buf_t	*bpo_dbuf;
70 	dmu_buf_t	*bpo_cached_dbuf;
71 } bpobj_t;
72 
73 typedef int bpobj_itor_t(void *arg, const blkptr_t *bp, boolean_t bp_freed,
74     dmu_tx_t *tx);
75 
76 uint64_t bpobj_alloc(objset_t *mos, int blocksize, dmu_tx_t *tx);
77 uint64_t bpobj_alloc_empty(objset_t *os, int blocksize, dmu_tx_t *tx);
78 void bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx);
79 void bpobj_decr_empty(objset_t *os, dmu_tx_t *tx);
80 
81 int bpobj_open(bpobj_t *bpo, objset_t *mos, uint64_t object);
82 void bpobj_close(bpobj_t *bpo);
83 boolean_t bpobj_is_open(const bpobj_t *bpo);
84 
85 int bpobj_iterate(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx);
86 int bpobj_iterate_nofree(bpobj_t *bpo, bpobj_itor_t func, void *, uint64_t *);
87 int livelist_bpobj_iterate_from_nofree(bpobj_t *bpo, bpobj_itor_t func,
88     void *arg, int64_t start);
89 
90 void bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx);
91 void bpobj_prefetch_subobj(bpobj_t *bpo, uint64_t subobj);
92 void bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, boolean_t bp_freed,
93     dmu_tx_t *tx);
94 
95 int bpobj_space(bpobj_t *bpo,
96     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
97 int bpobj_space_range(bpobj_t *bpo, uint64_t mintxg, uint64_t maxtxg,
98     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
99 boolean_t bpobj_is_empty(bpobj_t *bpo);
100 
101 int bplist_append_cb(void *arg, const blkptr_t *bp, boolean_t bp_freed,
102     dmu_tx_t *tx);
103 
104 #ifdef	__cplusplus
105 }
106 #endif
107 
108 #endif /* _SYS_BPOBJ_H */
109