xref: /titanic_44/usr/src/uts/common/fs/zfs/sys/txg.h (revision 67e3a03ed4a2813074d36330f062ed6e593a4937)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_TXG_H
27 #define	_SYS_TXG_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/spa.h>
32 #include <sys/zfs_context.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #define	TXG_CONCURRENT_STATES	3	/* open, quiescing, syncing	*/
39 #define	TXG_SIZE		4		/* next power of 2	*/
40 #define	TXG_MASK		(TXG_SIZE - 1)	/* mask for size	*/
41 #define	TXG_INITIAL		TXG_SIZE	/* initial txg 		*/
42 #define	TXG_IDX			(txg & TXG_MASK)
43 
44 #define	TXG_WAIT		1ULL
45 #define	TXG_NOWAIT		2ULL
46 
47 typedef struct tx_cpu tx_cpu_t;
48 
49 typedef struct txg_handle {
50 	tx_cpu_t	*th_cpu;
51 	uint64_t	th_txg;
52 } txg_handle_t;
53 
54 typedef struct txg_node {
55 	struct txg_node	*tn_next[TXG_SIZE];
56 	uint8_t		tn_member[TXG_SIZE];
57 } txg_node_t;
58 
59 typedef struct txg_list {
60 	kmutex_t	tl_lock;
61 	size_t		tl_offset;
62 	txg_node_t	*tl_head[TXG_SIZE];
63 } txg_list_t;
64 
65 struct dsl_pool;
66 
67 extern void txg_init(struct dsl_pool *dp, uint64_t txg);
68 extern void txg_fini(struct dsl_pool *dp);
69 extern void txg_sync_start(struct dsl_pool *dp);
70 extern void txg_sync_stop(struct dsl_pool *dp);
71 extern uint64_t txg_hold_open(struct dsl_pool *dp, txg_handle_t *txghp);
72 extern void txg_rele_to_quiesce(txg_handle_t *txghp);
73 extern void txg_rele_to_sync(txg_handle_t *txghp);
74 extern void txg_suspend(struct dsl_pool *dp);
75 extern void txg_resume(struct dsl_pool *dp);
76 
77 /*
78  * Delay the caller by the specified number of ticks or until
79  * the txg closes (whichever comes first).  This is intended
80  * to be used to throttle writers when the system nears its
81  * capacity.
82  */
83 extern void txg_delay(struct dsl_pool *dp, uint64_t txg, int ticks);
84 
85 /*
86  * Wait until the given transaction group has finished syncing.
87  * Try to make this happen as soon as possible (eg. kick off any
88  * necessary syncs immediately).  If txg==0, wait for the currently open
89  * txg to finish syncing.
90  */
91 extern void txg_wait_synced(struct dsl_pool *dp, uint64_t txg);
92 
93 /*
94  * Wait until the given transaction group, or one after it, is
95  * the open transaction group.  Try to make this happen as soon
96  * as possible (eg. kick off any necessary syncs immediately).
97  * If txg == 0, wait for the next open txg.
98  */
99 extern void txg_wait_open(struct dsl_pool *dp, uint64_t txg);
100 
101 /*
102  * Returns TRUE if we are "backed up" waiting for the syncing
103  * transaction to complete; otherwise returns FALSE.
104  */
105 extern int txg_stalled(struct dsl_pool *dp);
106 
107 /*
108  * Per-txg object lists.
109  */
110 
111 #define	TXG_CLEAN(txg)	((txg) - 1)
112 
113 extern void txg_list_create(txg_list_t *tl, size_t offset);
114 extern void txg_list_destroy(txg_list_t *tl);
115 extern int txg_list_empty(txg_list_t *tl, uint64_t txg);
116 extern int txg_list_add(txg_list_t *tl, void *p, uint64_t txg);
117 extern void *txg_list_remove(txg_list_t *tl, uint64_t txg);
118 extern void *txg_list_remove_this(txg_list_t *tl, void *p, uint64_t txg);
119 extern int txg_list_member(txg_list_t *tl, void *p, uint64_t txg);
120 extern void *txg_list_head(txg_list_t *tl, uint64_t txg);
121 extern void *txg_list_next(txg_list_t *tl, void *p, uint64_t txg);
122 
123 #ifdef	__cplusplus
124 }
125 #endif
126 
127 #endif	/* _SYS_TXG_H */
128