xref: /freebsd/sys/contrib/openzfs/include/sys/dsl_deadlist.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) 2018, 2019 by Delphix. All rights reserved.
25  */
26 
27 #ifndef	_SYS_DSL_DEADLIST_H
28 #define	_SYS_DSL_DEADLIST_H
29 
30 #include <sys/bpobj.h>
31 #include <sys/zfs_context.h>
32 #include <sys/zthr.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 struct dmu_buf;
39 struct dsl_pool;
40 struct dsl_dataset;
41 
42 typedef struct dsl_deadlist_phys {
43 	uint64_t dl_used;
44 	uint64_t dl_comp;
45 	uint64_t dl_uncomp;
46 	uint64_t dl_pad[37]; /* pad out to 320b for future expansion */
47 } dsl_deadlist_phys_t;
48 
49 typedef struct dsl_deadlist {
50 	objset_t *dl_os;
51 	uint64_t dl_object;
52 	avl_tree_t dl_tree; /* contains dsl_deadlist_entry_t */
53 	avl_tree_t dl_cache; /* contains dsl_deadlist_cache_entry_t */
54 	boolean_t dl_havetree;
55 	boolean_t dl_havecache;
56 	struct dmu_buf *dl_dbuf;
57 	dsl_deadlist_phys_t *dl_phys;
58 	kmutex_t dl_lock;
59 
60 	/* if it's the old on-disk format: */
61 	bpobj_t dl_bpobj;
62 	boolean_t dl_oldfmt;
63 } dsl_deadlist_t;
64 
65 typedef struct dsl_deadlist_cache_entry {
66 	avl_node_t dlce_node;
67 	uint64_t dlce_mintxg;
68 	uint64_t dlce_bpobj;
69 	uint64_t dlce_bytes;
70 	uint64_t dlce_comp;
71 	uint64_t dlce_uncomp;
72 } dsl_deadlist_cache_entry_t;
73 
74 typedef struct dsl_deadlist_entry {
75 	avl_node_t dle_node;
76 	uint64_t dle_mintxg;
77 	bpobj_t dle_bpobj;
78 } dsl_deadlist_entry_t;
79 
80 typedef struct livelist_condense_entry {
81 	struct dsl_dataset *ds;
82 	dsl_deadlist_entry_t *first;
83 	dsl_deadlist_entry_t *next;
84 	boolean_t syncing;
85 	boolean_t cancelled;
86 } livelist_condense_entry_t;
87 
88 extern uint64_t zfs_livelist_max_entries;
89 extern int zfs_livelist_min_percent_shared;
90 
91 typedef int deadlist_iter_t(void *args, dsl_deadlist_entry_t *dle);
92 
93 int dsl_deadlist_open(dsl_deadlist_t *dl, objset_t *os, uint64_t object);
94 void dsl_deadlist_close(dsl_deadlist_t *dl);
95 void dsl_deadlist_iterate(dsl_deadlist_t *dl, deadlist_iter_t func, void *arg);
96 uint64_t dsl_deadlist_alloc(objset_t *os, dmu_tx_t *tx);
97 void dsl_deadlist_free(objset_t *os, uint64_t dlobj, dmu_tx_t *tx);
98 void dsl_deadlist_insert(dsl_deadlist_t *dl, const blkptr_t *bp,
99     boolean_t free, dmu_tx_t *tx);
100 int dsl_deadlist_insert_alloc_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx);
101 int dsl_deadlist_insert_free_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx);
102 void dsl_deadlist_add_key(dsl_deadlist_t *dl, uint64_t mintxg, dmu_tx_t *tx);
103 void dsl_deadlist_remove_key(dsl_deadlist_t *dl, uint64_t mintxg, dmu_tx_t *tx);
104 void dsl_deadlist_remove_entry(dsl_deadlist_t *dl, uint64_t mintxg,
105 dmu_tx_t *tx);
106 dsl_deadlist_entry_t *dsl_deadlist_first(dsl_deadlist_t *dl);
107 dsl_deadlist_entry_t *dsl_deadlist_last(dsl_deadlist_t *dl);
108 uint64_t dsl_deadlist_clone(dsl_deadlist_t *dl, uint64_t maxtxg,
109     uint64_t mrs_obj, dmu_tx_t *tx);
110 void dsl_deadlist_space(dsl_deadlist_t *dl,
111     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
112 void dsl_deadlist_space_range(dsl_deadlist_t *dl,
113     uint64_t mintxg, uint64_t maxtxg,
114     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
115 void dsl_deadlist_merge(dsl_deadlist_t *dl, uint64_t obj, dmu_tx_t *tx);
116 void dsl_deadlist_move_bpobj(dsl_deadlist_t *dl, bpobj_t *bpo, uint64_t mintxg,
117     dmu_tx_t *tx);
118 boolean_t dsl_deadlist_is_open(dsl_deadlist_t *dl);
119 int dsl_process_sub_livelist(bpobj_t *bpobj, struct bplist *to_free,
120     zthr_t *t, uint64_t *size);
121 void dsl_deadlist_clear_entry(dsl_deadlist_entry_t *dle, dsl_deadlist_t *dl,
122     dmu_tx_t *tx);
123 void dsl_deadlist_discard_tree(dsl_deadlist_t *dl);
124 
125 #ifdef	__cplusplus
126 }
127 #endif
128 
129 #endif /* _SYS_DSL_DEADLIST_H */
130