]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu_impl.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / sys / cddl / contrib / opensolaris / uts / common / fs / zfs / sys / dmu_impl.h
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25
26 #ifndef _SYS_DMU_IMPL_H
27 #define _SYS_DMU_IMPL_H
28
29 #include <sys/txg_impl.h>
30 #include <sys/zio.h>
31 #include <sys/dnode.h>
32 #include <sys/kstat.h>
33 #include <sys/zfs_context.h>
34
35 #ifdef  __cplusplus
36 extern "C" {
37 #endif
38
39 /*
40  * This is the locking strategy for the DMU.  Numbers in parenthesis are
41  * cases that use that lock order, referenced below:
42  *
43  * ARC is self-contained
44  * bplist is self-contained
45  * refcount is self-contained
46  * txg is self-contained (hopefully!)
47  * zst_lock
48  * zf_rwlock
49  *
50  * XXX try to improve evicting path?
51  *
52  * dp_config_rwlock > os_obj_lock > dn_struct_rwlock >
53  *      dn_dbufs_mtx > hash_mutexes > db_mtx > dd_lock > leafs
54  *
55  * dp_config_rwlock
56  *    must be held before: everything
57  *    protects dd namespace changes
58  *    protects property changes globally
59  *    held from:
60  *      dsl_dir_open/r:
61  *      dsl_dir_create_sync/w:
62  *      dsl_dir_sync_destroy/w:
63  *      dsl_dir_rename_sync/w:
64  *      dsl_prop_changed_notify/r:
65  *
66  * os_obj_lock
67  *   must be held before:
68  *      everything except dp_config_rwlock
69  *   protects os_obj_next
70  *   held from:
71  *      dmu_object_alloc: dn_dbufs_mtx, db_mtx, hash_mutexes, dn_struct_rwlock
72  *
73  * dn_struct_rwlock
74  *   must be held before:
75  *      everything except dp_config_rwlock and os_obj_lock
76  *   protects structure of dnode (eg. nlevels)
77  *      db_blkptr can change when syncing out change to nlevels
78  *      dn_maxblkid
79  *      dn_nlevels
80  *      dn_*blksz*
81  *      phys nlevels, maxblkid, physical blkptr_t's (?)
82  *   held from:
83  *      callers of dbuf_read_impl, dbuf_hold[_impl], dbuf_prefetch
84  *      dmu_object_info_from_dnode: dn_dirty_mtx (dn_datablksz)
85  *      dmu_tx_count_free:
86  *      dbuf_read_impl: db_mtx, dmu_zfetch()
87  *      dmu_zfetch: zf_rwlock/r, zst_lock, dbuf_prefetch()
88  *      dbuf_new_size: db_mtx
89  *      dbuf_dirty: db_mtx
90  *      dbuf_findbp: (callers, phys? - the real need)
91  *      dbuf_create: dn_dbufs_mtx, hash_mutexes, db_mtx (phys?)
92  *      dbuf_prefetch: dn_dirty_mtx, hash_mutexes, db_mtx, dn_dbufs_mtx
93  *      dbuf_hold_impl: hash_mutexes, db_mtx, dn_dbufs_mtx, dbuf_findbp()
94  *      dnode_sync/w (increase_indirection): db_mtx (phys)
95  *      dnode_set_blksz/w: dn_dbufs_mtx (dn_*blksz*)
96  *      dnode_new_blkid/w: (dn_maxblkid)
97  *      dnode_free_range/w: dn_dirty_mtx (dn_maxblkid)
98  *      dnode_next_offset: (phys)
99  *
100  * dn_dbufs_mtx
101  *    must be held before:
102  *      db_mtx, hash_mutexes
103  *    protects:
104  *      dn_dbufs
105  *      dn_evicted
106  *    held from:
107  *      dmu_evict_user: db_mtx (dn_dbufs)
108  *      dbuf_free_range: db_mtx (dn_dbufs)
109  *      dbuf_remove_ref: db_mtx, callees:
110  *              dbuf_hash_remove: hash_mutexes, db_mtx
111  *      dbuf_create: hash_mutexes, db_mtx (dn_dbufs)
112  *      dnode_set_blksz: (dn_dbufs)
113  *
114  * hash_mutexes (global)
115  *   must be held before:
116  *      db_mtx
117  *   protects dbuf_hash_table (global) and db_hash_next
118  *   held from:
119  *      dbuf_find: db_mtx
120  *      dbuf_hash_insert: db_mtx
121  *      dbuf_hash_remove: db_mtx
122  *
123  * db_mtx (meta-leaf)
124  *   must be held before:
125  *      dn_mtx, dn_dirty_mtx, dd_lock (leaf mutexes)
126  *   protects:
127  *      db_state
128  *      db_holds
129  *      db_buf
130  *      db_changed
131  *      db_data_pending
132  *      db_dirtied
133  *      db_link
134  *      db_dirty_node (??)
135  *      db_dirtycnt
136  *      db_d.*
137  *      db.*
138  *   held from:
139  *      dbuf_dirty: dn_mtx, dn_dirty_mtx
140  *      dbuf_dirty->dsl_dir_willuse_space: dd_lock
141  *      dbuf_dirty->dbuf_new_block->dsl_dataset_block_freeable: dd_lock
142  *      dbuf_undirty: dn_dirty_mtx (db_d)
143  *      dbuf_write_done: dn_dirty_mtx (db_state)
144  *      dbuf_*
145  *      dmu_buf_update_user: none (db_d)
146  *      dmu_evict_user: none (db_d) (maybe can eliminate)
147  *      dbuf_find: none (db_holds)
148  *      dbuf_hash_insert: none (db_holds)
149  *      dmu_buf_read_array_impl: none (db_state, db_changed)
150  *      dmu_sync: none (db_dirty_node, db_d)
151  *      dnode_reallocate: none (db)
152  *
153  * dn_mtx (leaf)
154  *   protects:
155  *      dn_dirty_dbufs
156  *      dn_ranges
157  *      phys accounting
158  *      dn_allocated_txg
159  *      dn_free_txg
160  *      dn_assigned_txg
161  *      dd_assigned_tx
162  *      dn_notxholds
163  *      dn_dirtyctx
164  *      dn_dirtyctx_firstset
165  *      (dn_phys copy fields?)
166  *      (dn_phys contents?)
167  *   held from:
168  *      dnode_*
169  *      dbuf_dirty: none
170  *      dbuf_sync: none (phys accounting)
171  *      dbuf_undirty: none (dn_ranges, dn_dirty_dbufs)
172  *      dbuf_write_done: none (phys accounting)
173  *      dmu_object_info_from_dnode: none (accounting)
174  *      dmu_tx_commit: none
175  *      dmu_tx_hold_object_impl: none
176  *      dmu_tx_try_assign: dn_notxholds(cv)
177  *      dmu_tx_unassign: none
178  *
179  * dd_lock
180  *    must be held before:
181  *      ds_lock
182  *      ancestors' dd_lock
183  *    protects:
184  *      dd_prop_cbs
185  *      dd_sync_*
186  *      dd_used_bytes
187  *      dd_tempreserved
188  *      dd_space_towrite
189  *      dd_myname
190  *      dd_phys accounting?
191  *    held from:
192  *      dsl_dir_*
193  *      dsl_prop_changed_notify: none (dd_prop_cbs)
194  *      dsl_prop_register: none (dd_prop_cbs)
195  *      dsl_prop_unregister: none (dd_prop_cbs)
196  *      dsl_dataset_block_freeable: none (dd_sync_*)
197  *
198  * os_lock (leaf)
199  *   protects:
200  *      os_dirty_dnodes
201  *      os_free_dnodes
202  *      os_dnodes
203  *      os_downgraded_dbufs
204  *      dn_dirtyblksz
205  *      dn_dirty_link
206  *   held from:
207  *      dnode_create: none (os_dnodes)
208  *      dnode_destroy: none (os_dnodes)
209  *      dnode_setdirty: none (dn_dirtyblksz, os_*_dnodes)
210  *      dnode_free: none (dn_dirtyblksz, os_*_dnodes)
211  *
212  * ds_lock
213  *    protects:
214  *      ds_objset
215  *      ds_open_refcount
216  *      ds_snapname
217  *      ds_phys accounting
218  *      ds_phys userrefs zapobj
219  *      ds_reserved
220  *    held from:
221  *      dsl_dataset_*
222  *
223  * dr_mtx (leaf)
224  *    protects:
225  *      dr_children
226  *    held from:
227  *      dbuf_dirty
228  *      dbuf_undirty
229  *      dbuf_sync_indirect
230  *      dnode_new_blkid
231  */
232
233 struct objset;
234 struct dmu_pool;
235
236 typedef struct dmu_xuio {
237         int next;
238         int cnt;
239         struct arc_buf **bufs;
240         iovec_t *iovp;
241 } dmu_xuio_t;
242
243 typedef struct xuio_stats {
244         /* loaned yet not returned arc_buf */
245         kstat_named_t xuiostat_onloan_rbuf;
246         kstat_named_t xuiostat_onloan_wbuf;
247         /* whether a copy is made when loaning out a read buffer */
248         kstat_named_t xuiostat_rbuf_copied;
249         kstat_named_t xuiostat_rbuf_nocopy;
250         /* whether a copy is made when assigning a write buffer */
251         kstat_named_t xuiostat_wbuf_copied;
252         kstat_named_t xuiostat_wbuf_nocopy;
253 } xuio_stats_t;
254
255 static xuio_stats_t xuio_stats = {
256         { "onloan_read_buf",    KSTAT_DATA_UINT64 },
257         { "onloan_write_buf",   KSTAT_DATA_UINT64 },
258         { "read_buf_copied",    KSTAT_DATA_UINT64 },
259         { "read_buf_nocopy",    KSTAT_DATA_UINT64 },
260         { "write_buf_copied",   KSTAT_DATA_UINT64 },
261         { "write_buf_nocopy",   KSTAT_DATA_UINT64 }
262 };
263
264 #define XUIOSTAT_INCR(stat, val)        \
265         atomic_add_64(&xuio_stats.stat.value.ui64, (val))
266 #define XUIOSTAT_BUMP(stat)     XUIOSTAT_INCR(stat, 1)
267
268
269 #ifdef  __cplusplus
270 }
271 #endif
272
273 #endif  /* _SYS_DMU_IMPL_H */