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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 #include <sys/inttypes.h>
35 #include <sys/zfs_refcount.h>
50 * No synchronization is needed because a tx can only be handled
53 list_t tx_holds
; /* list of dmu_tx_hold_t */
55 struct dsl_dir
*tx_dir
;
56 struct dsl_pool
*tx_pool
;
58 uint64_t tx_lastsnap_txg
;
59 uint64_t tx_lasttried_txg
;
61 void *tx_tempreserve_cookie
;
62 struct dmu_tx_hold
*tx_needassign_txh
;
64 /* list of dmu_tx_callback_t on this dmu_tx */
67 /* placeholder for syncing context, doesn't need specific holds */
70 /* transaction is marked as being a "net free" of space */
73 /* time this transaction was created */
76 /* need to wait for sufficient dirty space */
77 boolean_t tx_wait_dirty
;
79 /* has this transaction already been delayed? */
80 boolean_t tx_dirty_delayed
;
85 enum dmu_tx_hold_type
{
98 typedef struct dmu_tx_hold
{
100 list_node_t txh_node
;
101 struct dnode
*txh_dnode
;
102 zfs_refcount_t txh_space_towrite
;
103 zfs_refcount_t txh_memory_tohold
;
104 enum dmu_tx_hold_type txh_type
;
109 typedef struct dmu_tx_callback
{
110 list_node_t dcb_node
; /* linked to tx_callbacks list */
111 dmu_tx_callback_func_t
*dcb_func
; /* caller function pointer */
112 void *dcb_data
; /* caller private data */
116 * Used for dmu tx kstat.
118 typedef struct dmu_tx_stats
{
119 kstat_named_t dmu_tx_assigned
;
120 kstat_named_t dmu_tx_delay
;
121 kstat_named_t dmu_tx_error
;
122 kstat_named_t dmu_tx_suspended
;
123 kstat_named_t dmu_tx_group
;
124 kstat_named_t dmu_tx_memory_reserve
;
125 kstat_named_t dmu_tx_memory_reclaim
;
126 kstat_named_t dmu_tx_dirty_throttle
;
127 kstat_named_t dmu_tx_dirty_delay
;
128 kstat_named_t dmu_tx_dirty_over_max
;
129 kstat_named_t dmu_tx_dirty_frees_delay
;
130 kstat_named_t dmu_tx_wrlog_delay
;
131 kstat_named_t dmu_tx_quota
;
134 extern dmu_tx_stats_t dmu_tx_stats
;
136 #define DMU_TX_STAT_INCR(stat, val) \
137 atomic_add_64(&dmu_tx_stats.stat.value.ui64, (val));
138 #define DMU_TX_STAT_BUMP(stat) \
139 DMU_TX_STAT_INCR(stat, 1);
142 * These routines are defined in dmu.h, and are called by the user.
144 dmu_tx_t
*dmu_tx_create(objset_t
*dd
);
145 int dmu_tx_assign(dmu_tx_t
*tx
, uint64_t txg_how
);
146 void dmu_tx_commit(dmu_tx_t
*tx
);
147 void dmu_tx_abort(dmu_tx_t
*tx
);
148 uint64_t dmu_tx_get_txg(dmu_tx_t
*tx
);
149 struct dsl_pool
*dmu_tx_pool(dmu_tx_t
*tx
);
150 void dmu_tx_wait(dmu_tx_t
*tx
);
153 * These routines are defined in dmu_spa.h, and are called by the SPA.
155 extern dmu_tx_t
*dmu_tx_create_assigned(struct dsl_pool
*dp
, uint64_t txg
);
158 * These routines are only called by the DMU.
160 dmu_tx_t
*dmu_tx_create_dd(dsl_dir_t
*dd
);
161 int dmu_tx_is_syncing(dmu_tx_t
*tx
);
162 int dmu_tx_private_ok(dmu_tx_t
*tx
);
163 void dmu_tx_add_new_object(dmu_tx_t
*tx
, dnode_t
*dn
);
164 void dmu_tx_dirty_buf(dmu_tx_t
*tx
, struct dmu_buf_impl
*db
);
165 void dmu_tx_hold_space(dmu_tx_t
*tx
, uint64_t space
);
168 #define DMU_TX_DIRTY_BUF(tx, db) dmu_tx_dirty_buf(tx, db)
170 #define DMU_TX_DIRTY_BUF(tx, db)
173 void dmu_tx_init(void);
174 void dmu_tx_fini(void);
180 #endif /* _SYS_DMU_TX_H */