xref: /titanic_52/usr/src/uts/common/fs/zfs/sys/txg.h (revision c2580b931007758eab8cb5ae8726ebe1588e259b)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_TXG_H
28 #define	_SYS_TXG_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/spa.h>
33 #include <sys/zfs_context.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #define	TXG_CONCURRENT_STATES	3	/* open, quiescing, syncing	*/
40 #define	TXG_SIZE		4		/* next power of 2	*/
41 #define	TXG_MASK		(TXG_SIZE - 1)	/* mask for size	*/
42 #define	TXG_INITIAL		TXG_SIZE	/* initial txg 		*/
43 #define	TXG_IDX			(txg & TXG_MASK)
44 
45 #define	TXG_WAIT		1ULL
46 #define	TXG_NOWAIT		2ULL
47 
48 typedef struct tx_cpu tx_cpu_t;
49 
50 typedef struct txg_handle {
51 	tx_cpu_t	*th_cpu;
52 	uint64_t	th_txg;
53 } txg_handle_t;
54 
55 typedef struct txg_node {
56 	struct txg_node	*tn_next[TXG_SIZE];
57 	uint8_t		tn_member[TXG_SIZE];
58 } txg_node_t;
59 
60 typedef struct txg_list {
61 	kmutex_t	tl_lock;
62 	size_t		tl_offset;
63 	txg_node_t	*tl_head[TXG_SIZE];
64 } txg_list_t;
65 
66 struct dsl_pool;
67 
68 extern void txg_init(struct dsl_pool *dp, uint64_t txg);
69 extern void txg_fini(struct dsl_pool *dp);
70 extern void txg_sync_start(struct dsl_pool *dp);
71 extern void txg_sync_stop(struct dsl_pool *dp);
72 extern uint64_t txg_hold_open(struct dsl_pool *dp, txg_handle_t *txghp);
73 extern void txg_rele_to_quiesce(txg_handle_t *txghp);
74 extern void txg_rele_to_sync(txg_handle_t *txghp);
75 extern void txg_suspend(struct dsl_pool *dp);
76 extern void txg_resume(struct dsl_pool *dp);
77 
78 /*
79  * Wait until the given transaction group has finished syncing.
80  * Try to make this happen as soon as possible (eg. kick off any
81  * necessary syncs immediately).  If txg==0, wait for the currently open
82  * txg to finish syncing.
83  */
84 extern void txg_wait_synced(struct dsl_pool *dp, uint64_t txg);
85 
86 /*
87  * Wait until the given transaction group, or one after it, is
88  * the open transaction group.  Try to make this happen as soon
89  * as possible (eg. kick off any necessary syncs immediately).
90  * If txg == 0, wait for the next open txg.
91  */
92 extern void txg_wait_open(struct dsl_pool *dp, uint64_t txg);
93 
94 /*
95  * Returns TRUE if we are "backed up" waiting for the syncing
96  * transaction to complete; otherwise returns FALSE.
97  */
98 extern int txg_stalled(struct dsl_pool *dp);
99 
100 /*
101  * Per-txg object lists.
102  */
103 
104 #define	TXG_CLEAN(txg)	((txg) - 1)
105 
106 extern void txg_list_create(txg_list_t *tl, size_t offset);
107 extern void txg_list_destroy(txg_list_t *tl);
108 extern int txg_list_empty(txg_list_t *tl, uint64_t txg);
109 extern int txg_list_add(txg_list_t *tl, void *p, uint64_t txg);
110 extern void *txg_list_remove(txg_list_t *tl, uint64_t txg);
111 extern void *txg_list_remove_this(txg_list_t *tl, void *p, uint64_t txg);
112 extern int txg_list_member(txg_list_t *tl, void *p, uint64_t txg);
113 extern void *txg_list_head(txg_list_t *tl, uint64_t txg);
114 extern void *txg_list_next(txg_list_t *tl, void *p, uint64_t txg);
115 
116 #ifdef	__cplusplus
117 }
118 #endif
119 
120 #endif	/* _SYS_TXG_H */
121