xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dmu_impl.h (revision b390f3a9)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5c717a561Smaybee  * Common Development and Distribution License (the "License").
6c717a561Smaybee  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
22c242f9a0Schunli zhang - Sun Microsystems - Irvine United States  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
242f3d8780SMatthew Ahrens  */
252f3d8780SMatthew Ahrens /*
264e3c9f44SBill Pijewski  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
2768ecb2ecSPaul Dagnelie  * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
28857c96d2SIgor Kozhukhov  * Copyright (c) 2018 DilOS
29fa9e4066Sahrens  */
30fa9e4066Sahrens 
31fa9e4066Sahrens #ifndef _SYS_DMU_IMPL_H
32fa9e4066Sahrens #define	_SYS_DMU_IMPL_H
33fa9e4066Sahrens 
34fa9e4066Sahrens #include <sys/txg_impl.h>
35fa9e4066Sahrens #include <sys/zio.h>
36fa9e4066Sahrens #include <sys/dnode.h>
37fa9e4066Sahrens #include <sys/zfs_context.h>
384e3c9f44SBill Pijewski #include <sys/zfs_ioctl.h>
39fa9e4066Sahrens 
40fa9e4066Sahrens #ifdef	__cplusplus
41fa9e4066Sahrens extern "C" {
42fa9e4066Sahrens #endif
43fa9e4066Sahrens 
44fa9e4066Sahrens /*
45fa9e4066Sahrens  * This is the locking strategy for the DMU.  Numbers in parenthesis are
46fa9e4066Sahrens  * cases that use that lock order, referenced below:
47fa9e4066Sahrens  *
48fa9e4066Sahrens  * ARC is self-contained
49fa9e4066Sahrens  * bplist is self-contained
50fa9e4066Sahrens  * refcount is self-contained
51fa9e4066Sahrens  * txg is self-contained (hopefully!)
52fa9e4066Sahrens  * zst_lock
53fa9e4066Sahrens  * zf_rwlock
54fa9e4066Sahrens  *
55fa9e4066Sahrens  * XXX try to improve evicting path?
56fa9e4066Sahrens  *
57fa9e4066Sahrens  * dp_config_rwlock > os_obj_lock > dn_struct_rwlock >
58*b390f3a9SJohn Poduska  *	dn_dbufs_mtx > hash_mutexes > db_mtx > dd_lock > leafs
59fa9e4066Sahrens  *
60fa9e4066Sahrens  * dp_config_rwlock
61fa9e4066Sahrens  *    must be held before: everything
62fa9e4066Sahrens  *    protects dd namespace changes
63fa9e4066Sahrens  *    protects property changes globally
64fa9e4066Sahrens  *    held from:
65*b390f3a9SJohn Poduska  *	dsl_dir_open/r:
66*b390f3a9SJohn Poduska  *	dsl_dir_create_sync/w:
67*b390f3a9SJohn Poduska  *	dsl_dir_sync_destroy/w:
68*b390f3a9SJohn Poduska  *	dsl_dir_rename_sync/w:
69*b390f3a9SJohn Poduska  *	dsl_prop_changed_notify/r:
70fa9e4066Sahrens  *
71fa9e4066Sahrens  * os_obj_lock
72fa9e4066Sahrens  *   must be held before:
73*b390f3a9SJohn Poduska  *	everything except dp_config_rwlock
74fa9e4066Sahrens  *   protects os_obj_next
75fa9e4066Sahrens  *   held from:
76*b390f3a9SJohn Poduska  *	dmu_object_alloc: dn_dbufs_mtx, db_mtx, hash_mutexes, dn_struct_rwlock
77fa9e4066Sahrens  *
78fa9e4066Sahrens  * dn_struct_rwlock
79fa9e4066Sahrens  *   must be held before:
80*b390f3a9SJohn Poduska  *	everything except dp_config_rwlock and os_obj_lock
81fa9e4066Sahrens  *   protects structure of dnode (eg. nlevels)
82*b390f3a9SJohn Poduska  *	db_blkptr can change when syncing out change to nlevels
83*b390f3a9SJohn Poduska  *	dn_maxblkid
84*b390f3a9SJohn Poduska  *	dn_nlevels
85*b390f3a9SJohn Poduska  *	dn_*blksz*
86*b390f3a9SJohn Poduska  *	phys nlevels, maxblkid, physical blkptr_t's (?)
87fa9e4066Sahrens  *   held from:
88*b390f3a9SJohn Poduska  *	callers of dbuf_read_impl, dbuf_hold[_impl], dbuf_prefetch
89*b390f3a9SJohn Poduska  *	dmu_object_info_from_dnode: dn_dirty_mtx (dn_datablksz)
90*b390f3a9SJohn Poduska  *	dbuf_read_impl: db_mtx, dmu_zfetch()
91*b390f3a9SJohn Poduska  *	dmu_zfetch: zf_rwlock/r, zst_lock, dbuf_prefetch()
92*b390f3a9SJohn Poduska  *	dbuf_new_size: db_mtx
93*b390f3a9SJohn Poduska  *	dbuf_dirty: db_mtx
94fa9e4066Sahrens  *	dbuf_findbp: (callers, phys? - the real need)
95fa9e4066Sahrens  *	dbuf_create: dn_dbufs_mtx, hash_mutexes, db_mtx (phys?)
96fa9e4066Sahrens  *	dbuf_prefetch: dn_dirty_mtx, hash_mutexes, db_mtx, dn_dbufs_mtx
97fa9e4066Sahrens  *	dbuf_hold_impl: hash_mutexes, db_mtx, dn_dbufs_mtx, dbuf_findbp()
98fa9e4066Sahrens  *	dnode_sync/w (increase_indirection): db_mtx (phys)
99fa9e4066Sahrens  *	dnode_set_blksz/w: dn_dbufs_mtx (dn_*blksz*)
100fa9e4066Sahrens  *	dnode_new_blkid/w: (dn_maxblkid)
101fa9e4066Sahrens  *	dnode_free_range/w: dn_dirty_mtx (dn_maxblkid)
102fa9e4066Sahrens  *	dnode_next_offset: (phys)
103fa9e4066Sahrens  *
104fa9e4066Sahrens  * dn_dbufs_mtx
105fa9e4066Sahrens  *    must be held before:
106*b390f3a9SJohn Poduska  *	db_mtx, hash_mutexes
107fa9e4066Sahrens  *    protects:
108*b390f3a9SJohn Poduska  *	dn_dbufs
109*b390f3a9SJohn Poduska  *	dn_evicted
110fa9e4066Sahrens  *    held from:
111*b390f3a9SJohn Poduska  *	dmu_evict_user: db_mtx (dn_dbufs)
112*b390f3a9SJohn Poduska  *	dbuf_free_range: db_mtx (dn_dbufs)
113*b390f3a9SJohn Poduska  *	dbuf_remove_ref: db_mtx, callees:
114*b390f3a9SJohn Poduska  *		dbuf_hash_remove: hash_mutexes, db_mtx
115*b390f3a9SJohn Poduska  *	dbuf_create: hash_mutexes, db_mtx (dn_dbufs)
116*b390f3a9SJohn Poduska  *	dnode_set_blksz: (dn_dbufs)
117fa9e4066Sahrens  *
118fa9e4066Sahrens  * hash_mutexes (global)
119fa9e4066Sahrens  *   must be held before:
120*b390f3a9SJohn Poduska  *	db_mtx
121fa9e4066Sahrens  *   protects dbuf_hash_table (global) and db_hash_next
122fa9e4066Sahrens  *   held from:
123*b390f3a9SJohn Poduska  *	dbuf_find: db_mtx
124*b390f3a9SJohn Poduska  *	dbuf_hash_insert: db_mtx
125*b390f3a9SJohn Poduska  *	dbuf_hash_remove: db_mtx
126fa9e4066Sahrens  *
127fa9e4066Sahrens  * db_mtx (meta-leaf)
128fa9e4066Sahrens  *   must be held before:
129*b390f3a9SJohn Poduska  *	dn_mtx, dn_dirty_mtx, dd_lock (leaf mutexes)
130fa9e4066Sahrens  *   protects:
131*b390f3a9SJohn Poduska  *	db_state
132*b390f3a9SJohn Poduska  *	db_holds
133*b390f3a9SJohn Poduska  *	db_buf
134*b390f3a9SJohn Poduska  *	db_changed
135*b390f3a9SJohn Poduska  *	db_data_pending
136*b390f3a9SJohn Poduska  *	db_dirtied
137*b390f3a9SJohn Poduska  *	db_link
138*b390f3a9SJohn Poduska  *	db_dirty_node (??)
139*b390f3a9SJohn Poduska  *	db_dirtycnt
140*b390f3a9SJohn Poduska  *	db_d.*
141*b390f3a9SJohn Poduska  *	db.*
142fa9e4066Sahrens  *   held from:
143*b390f3a9SJohn Poduska  *	dbuf_dirty: dn_mtx, dn_dirty_mtx
144*b390f3a9SJohn Poduska  *	dbuf_dirty->dsl_dir_willuse_space: dd_lock
145*b390f3a9SJohn Poduska  *	dbuf_dirty->dbuf_new_block->dsl_dataset_block_freeable: dd_lock
146*b390f3a9SJohn Poduska  *	dbuf_undirty: dn_dirty_mtx (db_d)
147*b390f3a9SJohn Poduska  *	dbuf_write_done: dn_dirty_mtx (db_state)
148*b390f3a9SJohn Poduska  *	dbuf_*
149*b390f3a9SJohn Poduska  *	dmu_buf_update_user: none (db_d)
150*b390f3a9SJohn Poduska  *	dmu_evict_user: none (db_d) (maybe can eliminate)
151*b390f3a9SJohn Poduska  *	dbuf_find: none (db_holds)
152*b390f3a9SJohn Poduska  *	dbuf_hash_insert: none (db_holds)
153*b390f3a9SJohn Poduska  *	dmu_buf_read_array_impl: none (db_state, db_changed)
154*b390f3a9SJohn Poduska  *	dmu_sync: none (db_dirty_node, db_d)
155*b390f3a9SJohn Poduska  *	dnode_reallocate: none (db)
156fa9e4066Sahrens  *
157fa9e4066Sahrens  * dn_mtx (leaf)
158fa9e4066Sahrens  *   protects:
159*b390f3a9SJohn Poduska  *	dn_dirty_dbufs
160*b390f3a9SJohn Poduska  *	dn_ranges
161*b390f3a9SJohn Poduska  *	phys accounting
162*b390f3a9SJohn Poduska  *	dn_allocated_txg
163*b390f3a9SJohn Poduska  *	dn_free_txg
164*b390f3a9SJohn Poduska  *	dn_assigned_txg
165*b390f3a9SJohn Poduska  *	dn_dirty_txg
166*b390f3a9SJohn Poduska  *	dd_assigned_tx
167*b390f3a9SJohn Poduska  *	dn_notxholds
168*b390f3a9SJohn Poduska  *	dn_nodnholds
169*b390f3a9SJohn Poduska  *	dn_dirtyctx
170*b390f3a9SJohn Poduska  *	dn_dirtyctx_firstset
171*b390f3a9SJohn Poduska  *	(dn_phys copy fields?)
172*b390f3a9SJohn Poduska  *	(dn_phys contents?)
173fa9e4066Sahrens  *   held from:
174*b390f3a9SJohn Poduska  *	dnode_*
175*b390f3a9SJohn Poduska  *	dbuf_dirty: none
176*b390f3a9SJohn Poduska  *	dbuf_sync: none (phys accounting)
177*b390f3a9SJohn Poduska  *	dbuf_undirty: none (dn_ranges, dn_dirty_dbufs)
178*b390f3a9SJohn Poduska  *	dbuf_write_done: none (phys accounting)
179*b390f3a9SJohn Poduska  *	dmu_object_info_from_dnode: none (accounting)
180*b390f3a9SJohn Poduska  *	dmu_tx_commit: none
181*b390f3a9SJohn Poduska  *	dmu_tx_hold_object_impl: none
182*b390f3a9SJohn Poduska  *	dmu_tx_try_assign: dn_notxholds(cv)
183*b390f3a9SJohn Poduska  *	dmu_tx_unassign: none
184fa9e4066Sahrens  *
1850b383af7SChris Kirby  * dd_lock
18602c8f3f0SMatthew Ahrens  *    must be held before:
187*b390f3a9SJohn Poduska  *	ds_lock
188*b390f3a9SJohn Poduska  *	ancestors' dd_lock
189fa9e4066Sahrens  *    protects:
190*b390f3a9SJohn Poduska  *	dd_prop_cbs
191*b390f3a9SJohn Poduska  *	dd_sync_*
192*b390f3a9SJohn Poduska  *	dd_used_bytes
193*b390f3a9SJohn Poduska  *	dd_tempreserved
194*b390f3a9SJohn Poduska  *	dd_space_towrite
195*b390f3a9SJohn Poduska  *	dd_myname
196*b390f3a9SJohn Poduska  *	dd_phys accounting?
197fa9e4066Sahrens  *    held from:
198*b390f3a9SJohn Poduska  *	dsl_dir_*
199*b390f3a9SJohn Poduska  *	dsl_prop_changed_notify: none (dd_prop_cbs)
200*b390f3a9SJohn Poduska  *	dsl_prop_register: none (dd_prop_cbs)
201*b390f3a9SJohn Poduska  *	dsl_prop_unregister: none (dd_prop_cbs)
202fa9e4066Sahrens  *
203fa9e4066Sahrens  * os_lock (leaf)
204fa9e4066Sahrens  *   protects:
205*b390f3a9SJohn Poduska  *	os_dirty_dnodes
206*b390f3a9SJohn Poduska  *	os_free_dnodes
207*b390f3a9SJohn Poduska  *	os_dnodes
208*b390f3a9SJohn Poduska  *	os_downgraded_dbufs
209*b390f3a9SJohn Poduska  *	dn_dirtyblksz
210*b390f3a9SJohn Poduska  *	dn_dirty_link
211fa9e4066Sahrens  *   held from:
212*b390f3a9SJohn Poduska  *	dnode_create: none (os_dnodes)
213*b390f3a9SJohn Poduska  *	dnode_destroy: none (os_dnodes)
214*b390f3a9SJohn Poduska  *	dnode_setdirty: none (dn_dirtyblksz, os_*_dnodes)
215*b390f3a9SJohn Poduska  *	dnode_free: none (dn_dirtyblksz, os_*_dnodes)
216fa9e4066Sahrens  *
2170b383af7SChris Kirby  * ds_lock
218fa9e4066Sahrens  *    protects:
219*b390f3a9SJohn Poduska  *	ds_objset
220*b390f3a9SJohn Poduska  *	ds_open_refcount
221*b390f3a9SJohn Poduska  *	ds_snapname
222*b390f3a9SJohn Poduska  *	ds_phys accounting
223842727c2SChris Kirby  *	ds_phys userrefs zapobj
2240b383af7SChris Kirby  *	ds_reserved
225fa9e4066Sahrens  *    held from:
226*b390f3a9SJohn Poduska  *	dsl_dataset_*
227fa9e4066Sahrens  *
228c717a561Smaybee  * dr_mtx (leaf)
229c717a561Smaybee  *    protects:
230c717a561Smaybee  *	dr_children
231c717a561Smaybee  *    held from:
232c717a561Smaybee  *	dbuf_dirty
233c717a561Smaybee  *	dbuf_undirty
234c717a561Smaybee  *	dbuf_sync_indirect
235c717a561Smaybee  *	dnode_new_blkid
236fa9e4066Sahrens  */
237fa9e4066Sahrens 
238fa9e4066Sahrens struct objset;
239fa9e4066Sahrens struct dmu_pool;
240fa9e4066Sahrens 
241c242f9a0Schunli zhang - Sun Microsystems - Irvine United States typedef struct dmu_xuio {
242c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	int next;
243c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	int cnt;
244c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	struct arc_buf **bufs;
245c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	iovec_t *iovp;
246c242f9a0Schunli zhang - Sun Microsystems - Irvine United States } dmu_xuio_t;
247c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 
248c242f9a0Schunli zhang - Sun Microsystems - Irvine United States typedef struct xuio_stats {
249c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	/* loaned yet not returned arc_buf */
250c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	kstat_named_t xuiostat_onloan_rbuf;
251c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	kstat_named_t xuiostat_onloan_wbuf;
252c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	/* whether a copy is made when loaning out a read buffer */
253c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	kstat_named_t xuiostat_rbuf_copied;
254c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	kstat_named_t xuiostat_rbuf_nocopy;
255c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	/* whether a copy is made when assigning a write buffer */
256c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	kstat_named_t xuiostat_wbuf_copied;
257c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 	kstat_named_t xuiostat_wbuf_nocopy;
258c242f9a0Schunli zhang - Sun Microsystems - Irvine United States } xuio_stats_t;
259c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 
2604e3c9f44SBill Pijewski /*
2614e3c9f44SBill Pijewski  * The list of data whose inclusion in a send stream can be pending from
2624e3c9f44SBill Pijewski  * one call to backup_cb to another.  Multiple calls to dump_free() and
2634e3c9f44SBill Pijewski  * dump_freeobjects() can be aggregated into a single DRR_FREE or
2644e3c9f44SBill Pijewski  * DRR_FREEOBJECTS replay record.
2654e3c9f44SBill Pijewski  */
2664e3c9f44SBill Pijewski typedef enum {
2674e3c9f44SBill Pijewski 	PENDING_NONE,
2684e3c9f44SBill Pijewski 	PENDING_FREE,
2694e3c9f44SBill Pijewski 	PENDING_FREEOBJECTS
2704e3c9f44SBill Pijewski } dmu_pendop_t;
2714e3c9f44SBill Pijewski 
2724e3c9f44SBill Pijewski typedef struct dmu_sendarg {
2734e3c9f44SBill Pijewski 	list_node_t dsa_link;
2744e3c9f44SBill Pijewski 	dmu_replay_record_t *dsa_drr;
2754e3c9f44SBill Pijewski 	vnode_t *dsa_vp;
2764e3c9f44SBill Pijewski 	int dsa_outfd;
2774e3c9f44SBill Pijewski 	struct proc *dsa_proc;
2784e3c9f44SBill Pijewski 	offset_t *dsa_off;
2794e3c9f44SBill Pijewski 	objset_t *dsa_os;
2804e3c9f44SBill Pijewski 	zio_cksum_t dsa_zc;
2814e3c9f44SBill Pijewski 	uint64_t dsa_toguid;
282eb633035STom Caputi 	uint64_t dsa_fromtxg;
2834e3c9f44SBill Pijewski 	int dsa_err;
2844e3c9f44SBill Pijewski 	dmu_pendop_t dsa_pending_op;
2855d7b4d43SMatthew Ahrens 	uint64_t dsa_featureflags;
2862f3d8780SMatthew Ahrens 	uint64_t dsa_last_data_object;
2872f3d8780SMatthew Ahrens 	uint64_t dsa_last_data_offset;
2889c3fd121SMatthew Ahrens 	uint64_t dsa_resume_object;
2899c3fd121SMatthew Ahrens 	uint64_t dsa_resume_offset;
29012b90ee2SMatt Krantz 	boolean_t dsa_sent_begin;
29112b90ee2SMatt Krantz 	boolean_t dsa_sent_end;
2924e3c9f44SBill Pijewski } dmu_sendarg_t;
2934e3c9f44SBill Pijewski 
2942acef22dSMatthew Ahrens void dmu_object_zapify(objset_t *, uint64_t, dmu_object_type_t, dmu_tx_t *);
2952acef22dSMatthew Ahrens void dmu_object_free_zapified(objset_t *, uint64_t, dmu_tx_t *);
2965d7b4d43SMatthew Ahrens int dmu_buf_hold_noread(objset_t *, uint64_t, uint64_t,
2975d7b4d43SMatthew Ahrens     void *, dmu_buf_t **);
298c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 
299fa9e4066Sahrens #ifdef	__cplusplus
300fa9e4066Sahrens }
301fa9e4066Sahrens #endif
302fa9e4066Sahrens 
303fa9e4066Sahrens #endif	/* _SYS_DMU_IMPL_H */
304