xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zil_impl.h (revision a07094369b21309434206d9b3601d162693466fc)
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_ZIL_IMPL_H
28 #define	_SYS_ZIL_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/zil.h>
33 #include <sys/dmu_objset.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 typedef enum lwb_state_type {
40 	UNWRITTEN,	/* buffer yet to be written */
41 	SEQ_INCOMPLETE,	/* buffer written, but there's an unwritten buffer in */
42 			/* the sequence before this */
43 	SEQ_COMPLETE,	/* no unwritten buffers before this */
44 } lwb_state_t;
45 
46 /*
47  * Log write buffer.
48  */
49 typedef struct lwb {
50 	zilog_t		*lwb_zilog;	/* back pointer to log struct */
51 	blkptr_t	lwb_blk;	/* on disk address of this log blk */
52 	int		lwb_nused;	/* # used bytes in buffer */
53 	int		lwb_sz;		/* size of block and buffer */
54 	char		*lwb_buf;	/* log write buffer */
55 	uint64_t	lwb_max_txg;	/* highest txg in this lwb */
56 	uint64_t	lwb_seq;	/* highest log record seq number */
57 	txg_handle_t	lwb_txgh;	/* txg handle for txg_exit() */
58 	list_node_t	lwb_node;	/* zilog->zl_lwb_list linkage */
59 	lwb_state_t	lwb_state;	/* buffer state */
60 } lwb_t;
61 
62 /*
63  * [vdev, seq] element for use in flushing device write caches
64  */
65 typedef struct zil_vdev {
66 	uint64_t	vdev;		/* device written */
67 	uint64_t	seq;		/* itx sequence */
68 	list_node_t	vdev_seq_node;	/* zilog->zl_vdev_list linkage */
69 } zil_vdev_t;
70 
71 /*
72  * Stable storage intent log management structure.  One per dataset.
73  */
74 struct zilog {
75 	kmutex_t	zl_lock;	/* protects most zilog_t fields */
76 	struct dsl_pool	*zl_dmu_pool;	/* DSL pool */
77 	spa_t		*zl_spa;	/* handle for read/write log */
78 	zil_header_t	*zl_header;	/* log header buffer */
79 	objset_t	*zl_os;		/* object set we're logging */
80 	zil_get_data_t	*zl_get_data;	/* callback to get object content */
81 	uint64_t	zl_itx_seq;	/* itx sequence number */
82 	uint64_t	zl_ss_seq;	/* last tx on stable storage */
83 	uint64_t	zl_destroy_txg;	/* txg of last zil_destroy() */
84 	uint64_t	zl_replay_seq[TXG_SIZE]; /* seq of last replayed rec */
85 	uint32_t	zl_suspend;	/* log suspend count */
86 	kcondvar_t	zl_cv_write;	/* for waiting to write to log */
87 	kcondvar_t	zl_cv_seq;	/* for committing a sequence */
88 	uint8_t		zl_stop_replay;	/* don't replay any further */
89 	uint8_t		zl_stop_sync;	/* for debugging */
90 	uint8_t		zl_writer;	/* boolean: write setup in progress */
91 	uint8_t		zl_log_error;	/* boolean: log write error */
92 	list_t		zl_itx_list;	/* in-memory itx list */
93 	uint64_t	zl_itx_list_sz;	/* total size of records on list */
94 	uint64_t	zl_cur_used;	/* current commit log size used */
95 	uint64_t	zl_prev_used;	/* previous commit log size used */
96 	list_t		zl_lwb_list;	/* in-flight log write list */
97 	list_t		zl_vdev_list;	/* list of [vdev, seq] pairs */
98 	taskq_t		*zl_clean_taskq; /* runs lwb and itx clean tasks */
99 	avl_tree_t	zl_dva_tree;	/* track DVAs during log parse */
100 	kmutex_t	zl_destroy_lock; /* serializes zil_destroy() calls */
101 };
102 
103 typedef struct zil_dva_node {
104 	dva_t		zn_dva;
105 	avl_node_t	zn_node;
106 } zil_dva_node_t;
107 
108 #ifdef	__cplusplus
109 }
110 #endif
111 
112 #endif	/* _SYS_ZIL_IMPL_H */
113