]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu_impl.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
25  * Copyright (c) 2012, Martin Matuska <mm@FreeBSD.org>. All rights reserved.
26  */
27
28 #ifndef _SYS_DMU_IMPL_H
29 #define _SYS_DMU_IMPL_H
30
31 #include <sys/txg_impl.h>
32 #include <sys/zio.h>
33 #include <sys/dnode.h>
34 #include <sys/kstat.h>
35 #include <sys/zfs_context.h>
36 #include <sys/zfs_ioctl.h>
37
38 #ifdef  __cplusplus
39 extern "C" {
40 #endif
41
42 /*
43  * This is the locking strategy for the DMU.  Numbers in parenthesis are
44  * cases that use that lock order, referenced below:
45  *
46  * ARC is self-contained
47  * bplist is self-contained
48  * refcount is self-contained
49  * txg is self-contained (hopefully!)
50  * zst_lock
51  * zf_rwlock
52  *
53  * XXX try to improve evicting path?
54  *
55  * dp_config_rwlock > os_obj_lock > dn_struct_rwlock >
56  *      dn_dbufs_mtx > hash_mutexes > db_mtx > dd_lock > leafs
57  *
58  * dp_config_rwlock
59  *    must be held before: everything
60  *    protects dd namespace changes
61  *    protects property changes globally
62  *    held from:
63  *      dsl_dir_open/r:
64  *      dsl_dir_create_sync/w:
65  *      dsl_dir_sync_destroy/w:
66  *      dsl_dir_rename_sync/w:
67  *      dsl_prop_changed_notify/r:
68  *
69  * os_obj_lock
70  *   must be held before:
71  *      everything except dp_config_rwlock
72  *   protects os_obj_next
73  *   held from:
74  *      dmu_object_alloc: dn_dbufs_mtx, db_mtx, hash_mutexes, dn_struct_rwlock
75  *
76  * dn_struct_rwlock
77  *   must be held before:
78  *      everything except dp_config_rwlock and os_obj_lock
79  *   protects structure of dnode (eg. nlevels)
80  *      db_blkptr can change when syncing out change to nlevels
81  *      dn_maxblkid
82  *      dn_nlevels
83  *      dn_*blksz*
84  *      phys nlevels, maxblkid, physical blkptr_t's (?)
85  *   held from:
86  *      callers of dbuf_read_impl, dbuf_hold[_impl], dbuf_prefetch
87  *      dmu_object_info_from_dnode: dn_dirty_mtx (dn_datablksz)
88  *      dmu_tx_count_free:
89  *      dbuf_read_impl: db_mtx, dmu_zfetch()
90  *      dmu_zfetch: zf_rwlock/r, zst_lock, dbuf_prefetch()
91  *      dbuf_new_size: db_mtx
92  *      dbuf_dirty: db_mtx
93  *      dbuf_findbp: (callers, phys? - the real need)
94  *      dbuf_create: dn_dbufs_mtx, hash_mutexes, db_mtx (phys?)
95  *      dbuf_prefetch: dn_dirty_mtx, hash_mutexes, db_mtx, dn_dbufs_mtx
96  *      dbuf_hold_impl: hash_mutexes, db_mtx, dn_dbufs_mtx, dbuf_findbp()
97  *      dnode_sync/w (increase_indirection): db_mtx (phys)
98  *      dnode_set_blksz/w: dn_dbufs_mtx (dn_*blksz*)
99  *      dnode_new_blkid/w: (dn_maxblkid)
100  *      dnode_free_range/w: dn_dirty_mtx (dn_maxblkid)
101  *      dnode_next_offset: (phys)
102  *
103  * dn_dbufs_mtx
104  *    must be held before:
105  *      db_mtx, hash_mutexes
106  *    protects:
107  *      dn_dbufs
108  *      dn_evicted
109  *    held from:
110  *      dmu_evict_user: db_mtx (dn_dbufs)
111  *      dbuf_free_range: db_mtx (dn_dbufs)
112  *      dbuf_remove_ref: db_mtx, callees:
113  *              dbuf_hash_remove: hash_mutexes, db_mtx
114  *      dbuf_create: hash_mutexes, db_mtx (dn_dbufs)
115  *      dnode_set_blksz: (dn_dbufs)
116  *
117  * hash_mutexes (global)
118  *   must be held before:
119  *      db_mtx
120  *   protects dbuf_hash_table (global) and db_hash_next
121  *   held from:
122  *      dbuf_find: db_mtx
123  *      dbuf_hash_insert: db_mtx
124  *      dbuf_hash_remove: db_mtx
125  *
126  * db_mtx (meta-leaf)
127  *   must be held before:
128  *      dn_mtx, dn_dirty_mtx, dd_lock (leaf mutexes)
129  *   protects:
130  *      db_state
131  *      db_holds
132  *      db_buf
133  *      db_changed
134  *      db_data_pending
135  *      db_dirtied
136  *      db_link
137  *      db_dirty_node (??)
138  *      db_dirtycnt
139  *      db_d.*
140  *      db.*
141  *   held from:
142  *      dbuf_dirty: dn_mtx, dn_dirty_mtx
143  *      dbuf_dirty->dsl_dir_willuse_space: dd_lock
144  *      dbuf_dirty->dbuf_new_block->dsl_dataset_block_freeable: dd_lock
145  *      dbuf_undirty: dn_dirty_mtx (db_d)
146  *      dbuf_write_done: dn_dirty_mtx (db_state)
147  *      dbuf_*
148  *      dmu_buf_update_user: none (db_d)
149  *      dmu_evict_user: none (db_d) (maybe can eliminate)
150  *      dbuf_find: none (db_holds)
151  *      dbuf_hash_insert: none (db_holds)
152  *      dmu_buf_read_array_impl: none (db_state, db_changed)
153  *      dmu_sync: none (db_dirty_node, db_d)
154  *      dnode_reallocate: none (db)
155  *
156  * dn_mtx (leaf)
157  *   protects:
158  *      dn_dirty_dbufs
159  *      dn_ranges
160  *      phys accounting
161  *      dn_allocated_txg
162  *      dn_free_txg
163  *      dn_assigned_txg
164  *      dd_assigned_tx
165  *      dn_notxholds
166  *      dn_dirtyctx
167  *      dn_dirtyctx_firstset
168  *      (dn_phys copy fields?)
169  *      (dn_phys contents?)
170  *   held from:
171  *      dnode_*
172  *      dbuf_dirty: none
173  *      dbuf_sync: none (phys accounting)
174  *      dbuf_undirty: none (dn_ranges, dn_dirty_dbufs)
175  *      dbuf_write_done: none (phys accounting)
176  *      dmu_object_info_from_dnode: none (accounting)
177  *      dmu_tx_commit: none
178  *      dmu_tx_hold_object_impl: none
179  *      dmu_tx_try_assign: dn_notxholds(cv)
180  *      dmu_tx_unassign: none
181  *
182  * dd_lock
183  *    must be held before:
184  *      ds_lock
185  *      ancestors' dd_lock
186  *    protects:
187  *      dd_prop_cbs
188  *      dd_sync_*
189  *      dd_used_bytes
190  *      dd_tempreserved
191  *      dd_space_towrite
192  *      dd_myname
193  *      dd_phys accounting?
194  *    held from:
195  *      dsl_dir_*
196  *      dsl_prop_changed_notify: none (dd_prop_cbs)
197  *      dsl_prop_register: none (dd_prop_cbs)
198  *      dsl_prop_unregister: none (dd_prop_cbs)
199  *      dsl_dataset_block_freeable: none (dd_sync_*)
200  *
201  * os_lock (leaf)
202  *   protects:
203  *      os_dirty_dnodes
204  *      os_free_dnodes
205  *      os_dnodes
206  *      os_downgraded_dbufs
207  *      dn_dirtyblksz
208  *      dn_dirty_link
209  *   held from:
210  *      dnode_create: none (os_dnodes)
211  *      dnode_destroy: none (os_dnodes)
212  *      dnode_setdirty: none (dn_dirtyblksz, os_*_dnodes)
213  *      dnode_free: none (dn_dirtyblksz, os_*_dnodes)
214  *
215  * ds_lock
216  *    protects:
217  *      ds_objset
218  *      ds_open_refcount
219  *      ds_snapname
220  *      ds_phys accounting
221  *      ds_phys userrefs zapobj
222  *      ds_reserved
223  *    held from:
224  *      dsl_dataset_*
225  *
226  * dr_mtx (leaf)
227  *    protects:
228  *      dr_children
229  *    held from:
230  *      dbuf_dirty
231  *      dbuf_undirty
232  *      dbuf_sync_indirect
233  *      dnode_new_blkid
234  */
235
236 struct objset;
237 struct dmu_pool;
238
239 typedef struct dmu_xuio {
240         int next;
241         int cnt;
242         struct arc_buf **bufs;
243         iovec_t *iovp;
244 } dmu_xuio_t;
245
246 typedef struct xuio_stats {
247         /* loaned yet not returned arc_buf */
248         kstat_named_t xuiostat_onloan_rbuf;
249         kstat_named_t xuiostat_onloan_wbuf;
250         /* whether a copy is made when loaning out a read buffer */
251         kstat_named_t xuiostat_rbuf_copied;
252         kstat_named_t xuiostat_rbuf_nocopy;
253         /* whether a copy is made when assigning a write buffer */
254         kstat_named_t xuiostat_wbuf_copied;
255         kstat_named_t xuiostat_wbuf_nocopy;
256 } xuio_stats_t;
257
258 static xuio_stats_t xuio_stats = {
259         { "onloan_read_buf",    KSTAT_DATA_UINT64 },
260         { "onloan_write_buf",   KSTAT_DATA_UINT64 },
261         { "read_buf_copied",    KSTAT_DATA_UINT64 },
262         { "read_buf_nocopy",    KSTAT_DATA_UINT64 },
263         { "write_buf_copied",   KSTAT_DATA_UINT64 },
264         { "write_buf_nocopy",   KSTAT_DATA_UINT64 }
265 };
266
267 #define XUIOSTAT_INCR(stat, val)        \
268         atomic_add_64(&xuio_stats.stat.value.ui64, (val))
269 #define XUIOSTAT_BUMP(stat)     XUIOSTAT_INCR(stat, 1)
270
271 /*
272  * The list of data whose inclusion in a send stream can be pending from
273  * one call to backup_cb to another.  Multiple calls to dump_free() and
274  * dump_freeobjects() can be aggregated into a single DRR_FREE or
275  * DRR_FREEOBJECTS replay record.
276  */
277 typedef enum {
278         PENDING_NONE,
279         PENDING_FREE,
280         PENDING_FREEOBJECTS
281 } dmu_pendop_t;
282
283 typedef struct dmu_sendarg {
284         list_node_t dsa_link;
285         dmu_replay_record_t *dsa_drr;
286         kthread_t *dsa_td;
287         struct file *dsa_fp;
288         int dsa_outfd;
289         struct proc *dsa_proc;
290         offset_t *dsa_off;
291         objset_t *dsa_os;
292         zio_cksum_t dsa_zc;
293         uint64_t dsa_toguid;
294         int dsa_err;
295         dmu_pendop_t dsa_pending_op;
296 } dmu_sendarg_t;
297
298
299 #ifdef  __cplusplus
300 }
301 #endif
302
303 #endif  /* _SYS_DMU_IMPL_H */