xref: /freebsd/sys/contrib/openzfs/include/sys/dsl_pool.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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright (c) 2013, 2018 by Delphix. All rights reserved.
25  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
26  */
27 
28 #ifndef	_SYS_DSL_POOL_H
29 #define	_SYS_DSL_POOL_H
30 
31 #include <sys/spa.h>
32 #include <sys/txg.h>
33 #include <sys/txg_impl.h>
34 #include <sys/zfs_context.h>
35 #include <sys/zio.h>
36 #include <sys/dnode.h>
37 #include <sys/ddt.h>
38 #include <sys/arc.h>
39 #include <sys/bpobj.h>
40 #include <sys/bptree.h>
41 #include <sys/rrwlock.h>
42 #include <sys/dsl_synctask.h>
43 #include <sys/mmp.h>
44 #include <sys/aggsum.h>
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 extern int zfs_txg_synctime_ms;
51 
52 struct objset;
53 struct dsl_dir;
54 struct dsl_dataset;
55 struct dsl_pool;
56 struct dmu_tx;
57 struct dsl_scan;
58 struct dsl_crypto_params;
59 struct dsl_deadlist;
60 
61 extern uint64_t zfs_dirty_data_max;
62 extern uint64_t zfs_dirty_data_max_max;
63 extern uint64_t zfs_wrlog_data_max;
64 extern uint_t zfs_dirty_data_max_percent;
65 extern uint_t zfs_dirty_data_max_max_percent;
66 extern uint_t zfs_delay_min_dirty_percent;
67 extern uint_t zfs_vdev_async_write_active_min_dirty_percent;
68 extern uint_t zfs_vdev_async_write_active_max_dirty_percent;
69 extern uint64_t zfs_delay_scale;
70 
71 /* These macros are for indexing into the zfs_all_blkstats_t. */
72 #define	DMU_OT_DEFERRED	DMU_OT_NONE
73 #define	DMU_OT_OTHER	DMU_OT_NUMTYPES /* place holder for DMU_OT() types */
74 #define	DMU_OT_TOTAL	(DMU_OT_NUMTYPES + 1)
75 
76 typedef struct zfs_blkstat {
77 	uint64_t	zb_count;
78 	uint64_t	zb_asize;
79 	uint64_t	zb_lsize;
80 	uint64_t	zb_psize;
81 	uint64_t	zb_gangs;
82 	uint64_t	zb_ditto_2_of_2_samevdev;
83 	uint64_t	zb_ditto_2_of_3_samevdev;
84 	uint64_t	zb_ditto_3_of_3_samevdev;
85 } zfs_blkstat_t;
86 
87 typedef struct zfs_all_blkstats {
88 	zfs_blkstat_t	zab_type[DN_MAX_LEVELS + 1][DMU_OT_TOTAL + 1];
89 } zfs_all_blkstats_t;
90 
91 
92 typedef struct dsl_pool {
93 	/* Immutable */
94 	spa_t *dp_spa;
95 	struct objset *dp_meta_objset;
96 	struct dsl_dir *dp_root_dir;
97 	struct dsl_dir *dp_mos_dir;
98 	struct dsl_dir *dp_free_dir;
99 	struct dsl_dir *dp_leak_dir;
100 	struct dsl_dataset *dp_origin_snap;
101 	uint64_t dp_root_dir_obj;
102 	struct taskq *dp_zrele_taskq;
103 	struct taskq *dp_unlinked_drain_taskq;
104 
105 	/* No lock needed - sync context only */
106 	blkptr_t dp_meta_rootbp;
107 	uint64_t dp_tmp_userrefs_obj;
108 	bpobj_t dp_free_bpobj;
109 	uint64_t dp_bptree_obj;
110 	uint64_t dp_empty_bpobj;
111 	bpobj_t dp_obsolete_bpobj;
112 
113 	struct dsl_scan *dp_scan;
114 
115 	/* Uses dp_lock */
116 	kmutex_t dp_lock;
117 	kcondvar_t dp_spaceavail_cv;
118 	uint64_t dp_dirty_pertxg[TXG_SIZE];
119 	uint64_t dp_dirty_total;
120 	uint64_t dp_long_free_dirty_pertxg[TXG_SIZE];
121 	uint64_t dp_mos_used_delta;
122 	uint64_t dp_mos_compressed_delta;
123 	uint64_t dp_mos_uncompressed_delta;
124 
125 	aggsum_t dp_wrlog_pertxg[TXG_SIZE];
126 	aggsum_t dp_wrlog_total;
127 
128 	/*
129 	 * Time of most recently scheduled (furthest in the future)
130 	 * wakeup for delayed transactions.
131 	 */
132 	hrtime_t dp_last_wakeup;
133 
134 	/* Has its own locking */
135 	tx_state_t dp_tx;
136 	txg_list_t dp_dirty_datasets;
137 	txg_list_t dp_dirty_zilogs;
138 	txg_list_t dp_dirty_dirs;
139 	txg_list_t dp_sync_tasks;
140 	txg_list_t dp_early_sync_tasks;
141 	taskq_t *dp_sync_taskq;
142 	taskq_t *dp_zil_clean_taskq;
143 
144 	/*
145 	 * Protects administrative changes (properties, namespace)
146 	 *
147 	 * It is only held for write in syncing context.  Therefore
148 	 * syncing context does not need to ever have it for read, since
149 	 * nobody else could possibly have it for write.
150 	 */
151 	rrwlock_t dp_config_rwlock;
152 
153 	zfs_all_blkstats_t *dp_blkstats;
154 } dsl_pool_t;
155 
156 int dsl_pool_init(spa_t *spa, uint64_t txg, dsl_pool_t **dpp);
157 int dsl_pool_open(dsl_pool_t *dp);
158 void dsl_pool_close(dsl_pool_t *dp);
159 dsl_pool_t *dsl_pool_create(spa_t *spa, nvlist_t *zplprops,
160     struct dsl_crypto_params *dcp, uint64_t txg);
161 void dsl_pool_sync(dsl_pool_t *dp, uint64_t txg);
162 void dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg);
163 int dsl_pool_sync_context(dsl_pool_t *dp);
164 uint64_t dsl_pool_adjustedsize(dsl_pool_t *dp, zfs_space_check_t slop_policy);
165 uint64_t dsl_pool_unreserved_space(dsl_pool_t *dp,
166     zfs_space_check_t slop_policy);
167 uint64_t dsl_pool_deferred_space(dsl_pool_t *dp);
168 void dsl_pool_wrlog_count(dsl_pool_t *dp, int64_t size, uint64_t txg);
169 boolean_t dsl_pool_need_wrlog_delay(dsl_pool_t *dp);
170 void dsl_pool_dirty_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx);
171 void dsl_pool_undirty_space(dsl_pool_t *dp, int64_t space, uint64_t txg);
172 void dsl_free(dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp);
173 void dsl_free_sync(zio_t *pio, dsl_pool_t *dp, uint64_t txg,
174     const blkptr_t *bpp);
175 void dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx);
176 void dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx);
177 void dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx);
178 void dsl_pool_mos_diduse_space(dsl_pool_t *dp,
179     int64_t used, int64_t comp, int64_t uncomp);
180 void dsl_pool_ckpoint_diduse_space(dsl_pool_t *dp,
181     int64_t used, int64_t comp, int64_t uncomp);
182 boolean_t dsl_pool_need_dirty_delay(dsl_pool_t *dp);
183 void dsl_pool_config_enter(dsl_pool_t *dp, const void *tag);
184 void dsl_pool_config_enter_prio(dsl_pool_t *dp, const void *tag);
185 void dsl_pool_config_exit(dsl_pool_t *dp, const void *tag);
186 boolean_t dsl_pool_config_held(dsl_pool_t *dp);
187 boolean_t dsl_pool_config_held_writer(dsl_pool_t *dp);
188 
189 taskq_t *dsl_pool_zrele_taskq(dsl_pool_t *dp);
190 taskq_t *dsl_pool_unlinked_drain_taskq(dsl_pool_t *dp);
191 
192 int dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj,
193     const char *tag, uint64_t now, dmu_tx_t *tx);
194 int dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj,
195     const char *tag, dmu_tx_t *tx);
196 void dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp);
197 int dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **);
198 int dsl_pool_hold(const char *name, const void *tag, dsl_pool_t **dp);
199 void dsl_pool_rele(dsl_pool_t *dp, const void *tag);
200 
201 void dsl_pool_create_obsolete_bpobj(dsl_pool_t *dp, dmu_tx_t *tx);
202 void dsl_pool_destroy_obsolete_bpobj(dsl_pool_t *dp, dmu_tx_t *tx);
203 
204 #ifdef	__cplusplus
205 }
206 #endif
207 
208 #endif /* _SYS_DSL_POOL_H */
209