]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
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 | /* | |
428870ff | 22 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
34dc7c2f BB |
23 | * Use is subject to license terms. |
24 | */ | |
13fe0198 | 25 | /* |
3ec3bc21 | 26 | * Copyright (c) 2012, 2016 by Delphix. All rights reserved. |
13fe0198 | 27 | */ |
34dc7c2f BB |
28 | |
29 | #ifndef _SYS_DMU_TX_H | |
30 | #define _SYS_DMU_TX_H | |
31 | ||
34dc7c2f BB |
32 | #include <sys/inttypes.h> |
33 | #include <sys/dmu.h> | |
34 | #include <sys/txg.h> | |
35 | #include <sys/refcount.h> | |
36 | ||
37 | #ifdef __cplusplus | |
38 | extern "C" { | |
39 | #endif | |
40 | ||
41 | struct dmu_buf_impl; | |
42 | struct dmu_tx_hold; | |
43 | struct dnode_link; | |
44 | struct dsl_pool; | |
45 | struct dnode; | |
46 | struct dsl_dir; | |
47 | ||
48 | struct dmu_tx { | |
49 | /* | |
50 | * No synchronization is needed because a tx can only be handled | |
51 | * by one thread. | |
52 | */ | |
53 | list_t tx_holds; /* list of dmu_tx_hold_t */ | |
54 | objset_t *tx_objset; | |
55 | struct dsl_dir *tx_dir; | |
56 | struct dsl_pool *tx_pool; | |
57 | uint64_t tx_txg; | |
58 | uint64_t tx_lastsnap_txg; | |
59 | uint64_t tx_lasttried_txg; | |
60 | txg_handle_t tx_txgh; | |
61 | void *tx_tempreserve_cookie; | |
62 | struct dmu_tx_hold *tx_needassign_txh; | |
e8b96c60 MA |
63 | |
64 | /* list of dmu_tx_callback_t on this dmu_tx */ | |
65 | list_t tx_callbacks; | |
66 | ||
67 | /* placeholder for syncing context, doesn't need specific holds */ | |
68 | boolean_t tx_anyobj; | |
69 | ||
70 | /* has this transaction already been delayed? */ | |
71 | boolean_t tx_waited; | |
72 | ||
3ec3bc21 BB |
73 | /* transaction is marked as being a "net free" of space */ |
74 | boolean_t tx_netfree; | |
75 | ||
e8b96c60 MA |
76 | /* time this transaction was created */ |
77 | hrtime_t tx_start; | |
78 | ||
79 | /* need to wait for sufficient dirty space */ | |
80 | boolean_t tx_wait_dirty; | |
81 | ||
34dc7c2f | 82 | int tx_err; |
34dc7c2f BB |
83 | }; |
84 | ||
85 | enum dmu_tx_hold_type { | |
86 | THT_NEWOBJECT, | |
87 | THT_WRITE, | |
88 | THT_BONUS, | |
89 | THT_FREE, | |
90 | THT_ZAP, | |
91 | THT_SPACE, | |
428870ff | 92 | THT_SPILL, |
34dc7c2f BB |
93 | THT_NUMTYPES |
94 | }; | |
95 | ||
96 | typedef struct dmu_tx_hold { | |
97 | dmu_tx_t *txh_tx; | |
98 | list_node_t txh_node; | |
99 | struct dnode *txh_dnode; | |
f85c06be | 100 | refcount_t txh_space_towrite; |
f85c06be | 101 | refcount_t txh_memory_tohold; |
34dc7c2f BB |
102 | enum dmu_tx_hold_type txh_type; |
103 | uint64_t txh_arg1; | |
104 | uint64_t txh_arg2; | |
34dc7c2f BB |
105 | } dmu_tx_hold_t; |
106 | ||
428870ff BB |
107 | typedef struct dmu_tx_callback { |
108 | list_node_t dcb_node; /* linked to tx_callbacks list */ | |
109 | dmu_tx_callback_func_t *dcb_func; /* caller function pointer */ | |
110 | void *dcb_data; /* caller private data */ | |
111 | } dmu_tx_callback_t; | |
34dc7c2f | 112 | |
570827e1 BB |
113 | /* |
114 | * Used for dmu tx kstat. | |
115 | */ | |
116 | typedef struct dmu_tx_stats { | |
117 | kstat_named_t dmu_tx_assigned; | |
118 | kstat_named_t dmu_tx_delay; | |
119 | kstat_named_t dmu_tx_error; | |
120 | kstat_named_t dmu_tx_suspended; | |
121 | kstat_named_t dmu_tx_group; | |
570827e1 BB |
122 | kstat_named_t dmu_tx_memory_reserve; |
123 | kstat_named_t dmu_tx_memory_reclaim; | |
570827e1 | 124 | kstat_named_t dmu_tx_dirty_throttle; |
e8b96c60 MA |
125 | kstat_named_t dmu_tx_dirty_delay; |
126 | kstat_named_t dmu_tx_dirty_over_max; | |
570827e1 BB |
127 | kstat_named_t dmu_tx_quota; |
128 | } dmu_tx_stats_t; | |
129 | ||
130 | extern dmu_tx_stats_t dmu_tx_stats; | |
131 | ||
d1d7e268 | 132 | #define DMU_TX_STAT_INCR(stat, val) \ |
570827e1 | 133 | atomic_add_64(&dmu_tx_stats.stat.value.ui64, (val)); |
d1d7e268 | 134 | #define DMU_TX_STAT_BUMP(stat) \ |
570827e1 BB |
135 | DMU_TX_STAT_INCR(stat, 1); |
136 | ||
34dc7c2f BB |
137 | /* |
138 | * These routines are defined in dmu.h, and are called by the user. | |
139 | */ | |
140 | dmu_tx_t *dmu_tx_create(objset_t *dd); | |
13fe0198 | 141 | int dmu_tx_assign(dmu_tx_t *tx, txg_how_t txg_how); |
34dc7c2f BB |
142 | void dmu_tx_commit(dmu_tx_t *tx); |
143 | void dmu_tx_abort(dmu_tx_t *tx); | |
144 | uint64_t dmu_tx_get_txg(dmu_tx_t *tx); | |
13fe0198 | 145 | struct dsl_pool *dmu_tx_pool(dmu_tx_t *tx); |
34dc7c2f BB |
146 | void dmu_tx_wait(dmu_tx_t *tx); |
147 | ||
148 | /* | |
149 | * These routines are defined in dmu_spa.h, and are called by the SPA. | |
150 | */ | |
151 | extern dmu_tx_t *dmu_tx_create_assigned(struct dsl_pool *dp, uint64_t txg); | |
152 | ||
153 | /* | |
154 | * These routines are only called by the DMU. | |
155 | */ | |
156 | dmu_tx_t *dmu_tx_create_dd(dsl_dir_t *dd); | |
157 | int dmu_tx_is_syncing(dmu_tx_t *tx); | |
158 | int dmu_tx_private_ok(dmu_tx_t *tx); | |
66eead53 | 159 | void dmu_tx_add_new_object(dmu_tx_t *tx, dnode_t *dn); |
34dc7c2f | 160 | void dmu_tx_dirty_buf(dmu_tx_t *tx, struct dmu_buf_impl *db); |
34dc7c2f BB |
161 | void dmu_tx_hold_space(dmu_tx_t *tx, uint64_t space); |
162 | ||
3ec3bc21 | 163 | #ifdef ZFS_DEBUG |
34dc7c2f BB |
164 | #define DMU_TX_DIRTY_BUF(tx, db) dmu_tx_dirty_buf(tx, db) |
165 | #else | |
166 | #define DMU_TX_DIRTY_BUF(tx, db) | |
167 | #endif | |
168 | ||
570827e1 BB |
169 | void dmu_tx_init(void); |
170 | void dmu_tx_fini(void); | |
171 | ||
34dc7c2f BB |
172 | #ifdef __cplusplus |
173 | } | |
174 | #endif | |
175 | ||
176 | #endif /* _SYS_DMU_TX_H */ |