xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zil_impl.h (revision 7f848965aa84f3ffafe9b934c813f94048ea42f8)
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_ZIL_IMPL_H
27 #define	_SYS_ZIL_IMPL_H
28 
29 #include <sys/zil.h>
30 #include <sys/dmu_objset.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Log write buffer.
38  */
39 typedef struct lwb {
40 	zilog_t		*lwb_zilog;	/* back pointer to log struct */
41 	blkptr_t	lwb_blk;	/* on disk address of this log blk */
42 	int		lwb_nused;	/* # used bytes in buffer */
43 	int		lwb_sz;		/* size of block and buffer */
44 	char		*lwb_buf;	/* log write buffer */
45 	zio_t		*lwb_zio;	/* zio for this buffer */
46 	uint64_t	lwb_max_txg;	/* highest txg in this lwb */
47 	txg_handle_t	lwb_txgh;	/* txg handle for txg_exit() */
48 	list_node_t	lwb_node;	/* zilog->zl_lwb_list linkage */
49 } lwb_t;
50 
51 /*
52  * Vdev flushing: during a zil_commit(), we build up an AVL tree of the vdevs
53  * we've touched so we know which ones need a write cache flush at the end.
54  */
55 typedef struct zil_vdev_node {
56 	uint64_t	zv_vdev;	/* vdev to be flushed */
57 	avl_node_t	zv_node;	/* AVL tree linkage */
58 } zil_vdev_node_t;
59 
60 /*
61  * Stable storage intent log management structure.  One per dataset.
62  */
63 struct zilog {
64 	kmutex_t	zl_lock;	/* protects most zilog_t fields */
65 	struct dsl_pool	*zl_dmu_pool;	/* DSL pool */
66 	spa_t		*zl_spa;	/* handle for read/write log */
67 	const zil_header_t *zl_header;	/* log header buffer */
68 	objset_t	*zl_os;		/* object set we're logging */
69 	zil_get_data_t	*zl_get_data;	/* callback to get object content */
70 	zio_t		*zl_root_zio;	/* log writer root zio */
71 	uint64_t	zl_itx_seq;	/* next itx sequence number */
72 	uint64_t	zl_commit_seq;	/* committed upto this number */
73 	uint64_t	zl_lr_seq;	/* log record sequence number */
74 	uint64_t	zl_destroy_txg;	/* txg of last zil_destroy() */
75 	uint64_t	zl_replayed_seq[TXG_SIZE]; /* last replayed rec seq */
76 	uint64_t	zl_replaying_seq; /* current replay seq number */
77 	uint32_t	zl_suspend;	/* log suspend count */
78 	kcondvar_t	zl_cv_writer;	/* log writer thread completion */
79 	kcondvar_t	zl_cv_suspend;	/* log suspend completion */
80 	uint8_t		zl_suspending;	/* log is currently suspending */
81 	uint8_t		zl_keep_first;	/* keep first log block in destroy */
82 	uint8_t		zl_replay;	/* replaying records while set */
83 	uint8_t		zl_stop_sync;	/* for debugging */
84 	uint8_t		zl_writer;	/* boolean: write setup in progress */
85 	uint8_t		zl_log_error;	/* boolean: log write error */
86 	list_t		zl_itx_list;	/* in-memory itx list */
87 	uint64_t	zl_itx_list_sz;	/* total size of records on list */
88 	uint64_t	zl_cur_used;	/* current commit log size used */
89 	uint64_t	zl_prev_used;	/* previous commit log size used */
90 	list_t		zl_lwb_list;	/* in-flight log write list */
91 	kmutex_t	zl_vdev_lock;	/* protects zl_vdev_tree */
92 	avl_tree_t	zl_vdev_tree;	/* vdevs to flush in zil_commit() */
93 	taskq_t		*zl_clean_taskq; /* runs lwb and itx clean tasks */
94 	avl_tree_t	zl_dva_tree;	/* track DVAs during log parse */
95 	clock_t		zl_replay_time;	/* lbolt of when replay started */
96 	uint64_t	zl_replay_blks;	/* number of log blocks replayed */
97 };
98 
99 typedef struct zil_dva_node {
100 	dva_t		zn_dva;
101 	avl_node_t	zn_node;
102 } zil_dva_node_t;
103 
104 #ifdef	__cplusplus
105 }
106 #endif
107 
108 #endif	/* _SYS_ZIL_IMPL_H */
109