]> git.proxmox.com Git - mirror_zfs.git/blame - include/sys/dmu_tx.h
Illumos #3464
[mirror_zfs.git] / include / sys / dmu_tx.h
CommitLineData
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
MA
25/*
26 * Copyright (c) 2012 by Delphix. All rights reserved.
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
38extern "C" {
39#endif
40
41struct dmu_buf_impl;
42struct dmu_tx_hold;
43struct dnode_link;
44struct dsl_pool;
45struct dnode;
46struct dsl_dir;
47
48struct 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;
428870ff 63 list_t tx_callbacks; /* list of dmu_tx_callback_t on this dmu_tx */
34dc7c2f
BB
64 uint8_t tx_anyobj;
65 int tx_err;
1c5de20a 66#ifdef DEBUG_DMU_TX
34dc7c2f
BB
67 uint64_t tx_space_towrite;
68 uint64_t tx_space_tofree;
69 uint64_t tx_space_tooverwrite;
70 uint64_t tx_space_tounref;
71 refcount_t tx_space_written;
72 refcount_t tx_space_freed;
73#endif
74};
75
76enum dmu_tx_hold_type {
77 THT_NEWOBJECT,
78 THT_WRITE,
79 THT_BONUS,
80 THT_FREE,
81 THT_ZAP,
82 THT_SPACE,
428870ff 83 THT_SPILL,
34dc7c2f
BB
84 THT_NUMTYPES
85};
86
87typedef struct dmu_tx_hold {
88 dmu_tx_t *txh_tx;
89 list_node_t txh_node;
90 struct dnode *txh_dnode;
91 uint64_t txh_space_towrite;
92 uint64_t txh_space_tofree;
93 uint64_t txh_space_tooverwrite;
94 uint64_t txh_space_tounref;
b128c09f
BB
95 uint64_t txh_memory_tohold;
96 uint64_t txh_fudge;
1c5de20a 97#ifdef DEBUG_DMU_TX
34dc7c2f
BB
98 enum dmu_tx_hold_type txh_type;
99 uint64_t txh_arg1;
100 uint64_t txh_arg2;
101#endif
102} dmu_tx_hold_t;
103
428870ff
BB
104typedef struct dmu_tx_callback {
105 list_node_t dcb_node; /* linked to tx_callbacks list */
106 dmu_tx_callback_func_t *dcb_func; /* caller function pointer */
107 void *dcb_data; /* caller private data */
108} dmu_tx_callback_t;
34dc7c2f 109
570827e1
BB
110/*
111 * Used for dmu tx kstat.
112 */
113typedef struct dmu_tx_stats {
114 kstat_named_t dmu_tx_assigned;
115 kstat_named_t dmu_tx_delay;
116 kstat_named_t dmu_tx_error;
117 kstat_named_t dmu_tx_suspended;
118 kstat_named_t dmu_tx_group;
119 kstat_named_t dmu_tx_how;
120 kstat_named_t dmu_tx_memory_reserve;
121 kstat_named_t dmu_tx_memory_reclaim;
122 kstat_named_t dmu_tx_memory_inflight;
123 kstat_named_t dmu_tx_dirty_throttle;
124 kstat_named_t dmu_tx_write_limit;
125 kstat_named_t dmu_tx_quota;
126} dmu_tx_stats_t;
127
128extern dmu_tx_stats_t dmu_tx_stats;
129
130#define DMU_TX_STAT_INCR(stat, val) \
131 atomic_add_64(&dmu_tx_stats.stat.value.ui64, (val));
132#define DMU_TX_STAT_BUMP(stat) \
133 DMU_TX_STAT_INCR(stat, 1);
134
34dc7c2f
BB
135/*
136 * These routines are defined in dmu.h, and are called by the user.
137 */
138dmu_tx_t *dmu_tx_create(objset_t *dd);
13fe0198 139int dmu_tx_assign(dmu_tx_t *tx, txg_how_t txg_how);
34dc7c2f
BB
140void dmu_tx_commit(dmu_tx_t *tx);
141void dmu_tx_abort(dmu_tx_t *tx);
142uint64_t dmu_tx_get_txg(dmu_tx_t *tx);
13fe0198 143struct dsl_pool *dmu_tx_pool(dmu_tx_t *tx);
34dc7c2f
BB
144void dmu_tx_wait(dmu_tx_t *tx);
145
428870ff
BB
146void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func,
147 void *dcb_data);
148void dmu_tx_do_callbacks(list_t *cb_list, int error);
149
34dc7c2f
BB
150/*
151 * These routines are defined in dmu_spa.h, and are called by the SPA.
152 */
153extern dmu_tx_t *dmu_tx_create_assigned(struct dsl_pool *dp, uint64_t txg);
154
155/*
156 * These routines are only called by the DMU.
157 */
158dmu_tx_t *dmu_tx_create_dd(dsl_dir_t *dd);
159int dmu_tx_is_syncing(dmu_tx_t *tx);
160int dmu_tx_private_ok(dmu_tx_t *tx);
161void dmu_tx_add_new_object(dmu_tx_t *tx, objset_t *os, uint64_t object);
162void dmu_tx_willuse_space(dmu_tx_t *tx, int64_t delta);
163void dmu_tx_dirty_buf(dmu_tx_t *tx, struct dmu_buf_impl *db);
164int dmu_tx_holds(dmu_tx_t *tx, uint64_t object);
165void dmu_tx_hold_space(dmu_tx_t *tx, uint64_t space);
166
1c5de20a 167#ifdef DEBUG_DMU_TX
34dc7c2f
BB
168#define DMU_TX_DIRTY_BUF(tx, db) dmu_tx_dirty_buf(tx, db)
169#else
170#define DMU_TX_DIRTY_BUF(tx, db)
171#endif
172
570827e1
BB
173void dmu_tx_init(void);
174void dmu_tx_fini(void);
175
34dc7c2f
BB
176#ifdef __cplusplus
177}
178#endif
179
180#endif /* _SYS_DMU_TX_H */