]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu_tx.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_tx.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_TX_H
27 #define _SYS_DMU_TX_H
28
29 #include <sys/dmu.h>
30 #include <sys/txg.h>
31 #include <sys/refcount.h>
32
33 #ifdef  __cplusplus
34 extern "C" {
35 #endif
36
37 struct dmu_buf_impl;
38 struct dmu_tx_hold;
39 struct dnode_link;
40 struct dsl_pool;
41 struct dnode;
42 struct dsl_dir;
43
44 struct dmu_tx {
45         /*
46          * No synchronization is needed because a tx can only be handled
47          * by one thread.
48          */
49         list_t tx_holds; /* list of dmu_tx_hold_t */
50         objset_t *tx_objset;
51         struct dsl_dir *tx_dir;
52         struct dsl_pool *tx_pool;
53         uint64_t tx_txg;
54         uint64_t tx_lastsnap_txg;
55         uint64_t tx_lasttried_txg;
56         txg_handle_t tx_txgh;
57         void *tx_tempreserve_cookie;
58         struct dmu_tx_hold *tx_needassign_txh;
59         list_t tx_callbacks; /* list of dmu_tx_callback_t on this dmu_tx */
60         uint8_t tx_anyobj;
61         int tx_err;
62 #ifdef ZFS_DEBUG
63         uint64_t tx_space_towrite;
64         uint64_t tx_space_tofree;
65         uint64_t tx_space_tooverwrite;
66         uint64_t tx_space_tounref;
67         refcount_t tx_space_written;
68         refcount_t tx_space_freed;
69 #endif
70 };
71
72 enum dmu_tx_hold_type {
73         THT_NEWOBJECT,
74         THT_WRITE,
75         THT_BONUS,
76         THT_FREE,
77         THT_ZAP,
78         THT_SPACE,
79         THT_SPILL,
80         THT_NUMTYPES
81 };
82
83 typedef struct dmu_tx_hold {
84         dmu_tx_t *txh_tx;
85         list_node_t txh_node;
86         struct dnode *txh_dnode;
87         uint64_t txh_space_towrite;
88         uint64_t txh_space_tofree;
89         uint64_t txh_space_tooverwrite;
90         uint64_t txh_space_tounref;
91         uint64_t txh_memory_tohold;
92         uint64_t txh_fudge;
93 #ifdef ZFS_DEBUG
94         enum dmu_tx_hold_type txh_type;
95         uint64_t txh_arg1;
96         uint64_t txh_arg2;
97 #endif
98 } dmu_tx_hold_t;
99
100 typedef struct dmu_tx_callback {
101         list_node_t             dcb_node;    /* linked to tx_callbacks list */
102         dmu_tx_callback_func_t  *dcb_func;   /* caller function pointer */
103         void                    *dcb_data;   /* caller private data */
104 } dmu_tx_callback_t;
105
106 /*
107  * These routines are defined in dmu.h, and are called by the user.
108  */
109 dmu_tx_t *dmu_tx_create(objset_t *dd);
110 int dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how);
111 void dmu_tx_commit(dmu_tx_t *tx);
112 void dmu_tx_abort(dmu_tx_t *tx);
113 uint64_t dmu_tx_get_txg(dmu_tx_t *tx);
114 void dmu_tx_wait(dmu_tx_t *tx);
115
116 void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func,
117     void *dcb_data);
118 void dmu_tx_do_callbacks(list_t *cb_list, int error);
119
120 /*
121  * These routines are defined in dmu_spa.h, and are called by the SPA.
122  */
123 extern dmu_tx_t *dmu_tx_create_assigned(struct dsl_pool *dp, uint64_t txg);
124
125 /*
126  * These routines are only called by the DMU.
127  */
128 dmu_tx_t *dmu_tx_create_dd(dsl_dir_t *dd);
129 int dmu_tx_is_syncing(dmu_tx_t *tx);
130 int dmu_tx_private_ok(dmu_tx_t *tx);
131 void dmu_tx_add_new_object(dmu_tx_t *tx, objset_t *os, uint64_t object);
132 void dmu_tx_willuse_space(dmu_tx_t *tx, int64_t delta);
133 void dmu_tx_dirty_buf(dmu_tx_t *tx, struct dmu_buf_impl *db);
134 int dmu_tx_holds(dmu_tx_t *tx, uint64_t object);
135 void dmu_tx_hold_space(dmu_tx_t *tx, uint64_t space);
136
137 #ifdef ZFS_DEBUG
138 #define DMU_TX_DIRTY_BUF(tx, db)        dmu_tx_dirty_buf(tx, db)
139 #else
140 #define DMU_TX_DIRTY_BUF(tx, db)
141 #endif
142
143 #ifdef  __cplusplus
144 }
145 #endif
146
147 #endif  /* _SYS_DMU_TX_H */