]> git.proxmox.com Git - mirror_zfs.git/blame - include/sys/txg.h
Cleanup: Specify unsignedness on things that should not be signed
[mirror_zfs.git] / include / sys / txg.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
1d3ba0bf 9 * or https://opensource.org/licenses/CDDL-1.0.
34dc7c2f
BB
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 */
29809a6c 25/*
4747a7d3 26 * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
29809a6c 27 */
34dc7c2f
BB
28
29#ifndef _SYS_TXG_H
30#define _SYS_TXG_H
31
34dc7c2f
BB
32#include <sys/spa.h>
33#include <sys/zfs_context.h>
34
35#ifdef __cplusplus
36extern "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)
b2255edc 44#define TXG_UNKNOWN 0
34dc7c2f 45
428870ff
BB
46/* Number of txgs worth of frees we defer adding to in-core spacemaps */
47#define TXG_DEFER_SIZE 2
48
34dc7c2f
BB
49typedef struct tx_cpu tx_cpu_t;
50
51typedef struct txg_handle {
52 tx_cpu_t *th_cpu;
53 uint64_t th_txg;
54} txg_handle_t;
55
56typedef struct txg_node {
57 struct txg_node *tn_next[TXG_SIZE];
58 uint8_t tn_member[TXG_SIZE];
59} txg_node_t;
60
61typedef struct txg_list {
62 kmutex_t tl_lock;
63 size_t tl_offset;
4747a7d3 64 spa_t *tl_spa;
34dc7c2f
BB
65 txg_node_t *tl_head[TXG_SIZE];
66} txg_list_t;
67
68struct dsl_pool;
69
70extern void txg_init(struct dsl_pool *dp, uint64_t txg);
71extern void txg_fini(struct dsl_pool *dp);
72extern void txg_sync_start(struct dsl_pool *dp);
73extern void txg_sync_stop(struct dsl_pool *dp);
74extern uint64_t txg_hold_open(struct dsl_pool *dp, txg_handle_t *txghp);
75extern void txg_rele_to_quiesce(txg_handle_t *txghp);
76extern void txg_rele_to_sync(txg_handle_t *txghp);
428870ff 77extern void txg_register_callbacks(txg_handle_t *txghp, list_t *tx_callbacks);
34dc7c2f 78
63fd3c6c
AL
79extern void txg_delay(struct dsl_pool *dp, uint64_t txg, hrtime_t delta,
80 hrtime_t resolution);
50e09edd 81extern void txg_kick(struct dsl_pool *dp, uint64_t txg);
34dc7c2f
BB
82
83/*
84 * Wait until the given transaction group has finished syncing.
85 * Try to make this happen as soon as possible (eg. kick off any
86 * necessary syncs immediately). If txg==0, wait for the currently open
87 * txg to finish syncing.
88 */
89extern void txg_wait_synced(struct dsl_pool *dp, uint64_t txg);
90
186898bb
DB
91/*
92 * Wait as above. Returns true if the thread was signaled while waiting.
93 */
94extern boolean_t txg_wait_synced_sig(struct dsl_pool *dp, uint64_t txg);
95
34dc7c2f
BB
96/*
97 * Wait until the given transaction group, or one after it, is
98 * the open transaction group. Try to make this happen as soon
1b939560
BB
99 * as possible (eg. kick off any necessary syncs immediately) when
100 * should_quiesce is set. If txg == 0, wait for the next open txg.
34dc7c2f 101 */
1b939560
BB
102extern void txg_wait_open(struct dsl_pool *dp, uint64_t txg,
103 boolean_t should_quiesce);
34dc7c2f
BB
104
105/*
106 * Returns TRUE if we are "backed up" waiting for the syncing
107 * transaction to complete; otherwise returns FALSE.
108 */
b128c09f
BB
109extern boolean_t txg_stalled(struct dsl_pool *dp);
110
111/* returns TRUE if someone is waiting for the next txg to sync */
112extern boolean_t txg_sync_waiting(struct dsl_pool *dp);
34dc7c2f 113
4747a7d3
MA
114extern void txg_verify(spa_t *spa, uint64_t txg);
115
54a179e7
RC
116/*
117 * Wait for pending commit callbacks of already-synced transactions to finish
118 * processing.
119 */
120extern void txg_wait_callbacks(struct dsl_pool *dp);
121
34dc7c2f
BB
122/*
123 * Per-txg object lists.
124 */
125
126#define TXG_CLEAN(txg) ((txg) - 1)
127
4747a7d3 128extern void txg_list_create(txg_list_t *tl, spa_t *spa, size_t offset);
34dc7c2f 129extern void txg_list_destroy(txg_list_t *tl);
29809a6c 130extern boolean_t txg_list_empty(txg_list_t *tl, uint64_t txg);
acbad6ff 131extern boolean_t txg_all_lists_empty(txg_list_t *tl);
13fe0198
MA
132extern boolean_t txg_list_add(txg_list_t *tl, void *p, uint64_t txg);
133extern boolean_t txg_list_add_tail(txg_list_t *tl, void *p, uint64_t txg);
34dc7c2f
BB
134extern void *txg_list_remove(txg_list_t *tl, uint64_t txg);
135extern void *txg_list_remove_this(txg_list_t *tl, void *p, uint64_t txg);
13fe0198 136extern boolean_t txg_list_member(txg_list_t *tl, void *p, uint64_t txg);
34dc7c2f
BB
137extern void *txg_list_head(txg_list_t *tl, uint64_t txg);
138extern void *txg_list_next(txg_list_t *tl, void *p, uint64_t txg);
139
87d98efe 140/* Global tuning */
fdc2d303 141extern uint_t zfs_txg_timeout;
87d98efe 142
8c4fb36a
TC
143
144#ifdef ZFS_DEBUG
145#define TXG_VERIFY(spa, txg) txg_verify(spa, txg)
146#else
147#define TXG_VERIFY(spa, txg)
148#endif
149
34dc7c2f
BB
150#ifdef __cplusplus
151}
152#endif
153
154#endif /* _SYS_TXG_H */