xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zil_impl.h (revision 55da60b9)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5d80c45e0Sbonwick  * Common Development and Distribution License (the "License").
6d80c45e0Sbonwick  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
22*55da60b9SMark J Musante  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23fa9e4066Sahrens  */
24fa9e4066Sahrens 
25*55da60b9SMark J Musante /* Portions Copyright 2010 Robert Milkowski */
26*55da60b9SMark J Musante 
27fa9e4066Sahrens #ifndef	_SYS_ZIL_IMPL_H
28fa9e4066Sahrens #define	_SYS_ZIL_IMPL_H
29fa9e4066Sahrens 
30fa9e4066Sahrens #include <sys/zil.h>
31fa9e4066Sahrens #include <sys/dmu_objset.h>
32fa9e4066Sahrens 
33fa9e4066Sahrens #ifdef	__cplusplus
34fa9e4066Sahrens extern "C" {
35fa9e4066Sahrens #endif
36fa9e4066Sahrens 
37fa9e4066Sahrens /*
38fa9e4066Sahrens  * Log write buffer.
39fa9e4066Sahrens  */
40fa9e4066Sahrens typedef struct lwb {
41fa9e4066Sahrens 	zilog_t		*lwb_zilog;	/* back pointer to log struct */
42fa9e4066Sahrens 	blkptr_t	lwb_blk;	/* on disk address of this log blk */
43fa9e4066Sahrens 	int		lwb_nused;	/* # used bytes in buffer */
44fa9e4066Sahrens 	int		lwb_sz;		/* size of block and buffer */
45fa9e4066Sahrens 	char		*lwb_buf;	/* log write buffer */
46c5c6ffa0Smaybee 	zio_t		*lwb_zio;	/* zio for this buffer */
47b24ab676SJeff Bonwick 	dmu_tx_t	*lwb_tx;	/* tx for log block allocation */
48fa9e4066Sahrens 	uint64_t	lwb_max_txg;	/* highest txg in this lwb */
49fa9e4066Sahrens 	list_node_t	lwb_node;	/* zilog->zl_lwb_list linkage */
50fa9e4066Sahrens } lwb_t;
51fa9e4066Sahrens 
52fa9e4066Sahrens /*
5317f17c2dSbonwick  * Vdev flushing: during a zil_commit(), we build up an AVL tree of the vdevs
5417f17c2dSbonwick  * we've touched so we know which ones need a write cache flush at the end.
55fa9e4066Sahrens  */
5617f17c2dSbonwick typedef struct zil_vdev_node {
5717f17c2dSbonwick 	uint64_t	zv_vdev;	/* vdev to be flushed */
5817f17c2dSbonwick 	avl_node_t	zv_node;	/* AVL tree linkage */
5917f17c2dSbonwick } zil_vdev_node_t;
60fa9e4066Sahrens 
616e1f5caaSNeil Perrin #define	ZIL_PREV_BLKS 16
626e1f5caaSNeil Perrin 
63fa9e4066Sahrens /*
64fa9e4066Sahrens  * Stable storage intent log management structure.  One per dataset.
65fa9e4066Sahrens  */
66fa9e4066Sahrens struct zilog {
67fa9e4066Sahrens 	kmutex_t	zl_lock;	/* protects most zilog_t fields */
68fa9e4066Sahrens 	struct dsl_pool	*zl_dmu_pool;	/* DSL pool */
69fa9e4066Sahrens 	spa_t		*zl_spa;	/* handle for read/write log */
70d80c45e0Sbonwick 	const zil_header_t *zl_header;	/* log header buffer */
71fa9e4066Sahrens 	objset_t	*zl_os;		/* object set we're logging */
72fa9e4066Sahrens 	zil_get_data_t	*zl_get_data;	/* callback to get object content */
73b19a79ecSperrin 	zio_t		*zl_root_zio;	/* log writer root zio */
74b24ab676SJeff Bonwick 	uint64_t	zl_itx_seq;	/* next in-core itx sequence number */
75b24ab676SJeff Bonwick 	uint64_t	zl_lr_seq;	/* on-disk log record sequence number */
7667bd71c6Sperrin 	uint64_t	zl_commit_seq;	/* committed upto this number */
77b24ab676SJeff Bonwick 	uint64_t	zl_commit_lr_seq; /* last committed on-disk lr seq */
78fa9e4066Sahrens 	uint64_t	zl_destroy_txg;	/* txg of last zil_destroy() */
791209a471SNeil Perrin 	uint64_t	zl_replayed_seq[TXG_SIZE]; /* last replayed rec seq */
801209a471SNeil Perrin 	uint64_t	zl_replaying_seq; /* current replay seq number */
81fa9e4066Sahrens 	uint32_t	zl_suspend;	/* log suspend count */
82b19a79ecSperrin 	kcondvar_t	zl_cv_writer;	/* log writer thread completion */
83d80c45e0Sbonwick 	kcondvar_t	zl_cv_suspend;	/* log suspend completion */
84d80c45e0Sbonwick 	uint8_t		zl_suspending;	/* log is currently suspending */
85d80c45e0Sbonwick 	uint8_t		zl_keep_first;	/* keep first log block in destroy */
861209a471SNeil Perrin 	uint8_t		zl_replay;	/* replaying records while set */
87fa9e4066Sahrens 	uint8_t		zl_stop_sync;	/* for debugging */
88fa9e4066Sahrens 	uint8_t		zl_writer;	/* boolean: write setup in progress */
89e09fa4daSNeil Perrin 	uint8_t		zl_logbias;	/* latency or throughput */
90*55da60b9SMark J Musante 	uint8_t		zl_sync;	/* synchronous or asynchronous */
91b24ab676SJeff Bonwick 	int		zl_parse_error;	/* last zil_parse() error */
92b24ab676SJeff Bonwick 	uint64_t	zl_parse_blk_seq; /* highest blk seq on last parse */
93b24ab676SJeff Bonwick 	uint64_t	zl_parse_lr_seq; /* highest lr seq on last parse */
94b24ab676SJeff Bonwick 	uint64_t	zl_parse_blk_count; /* number of blocks parsed */
95b24ab676SJeff Bonwick 	uint64_t	zl_parse_lr_count; /* number of log records parsed */
96fa9e4066Sahrens 	list_t		zl_itx_list;	/* in-memory itx list */
97fa9e4066Sahrens 	uint64_t	zl_itx_list_sz;	/* total size of records on list */
9822ac5be4Sperrin 	uint64_t	zl_cur_used;	/* current commit log size used */
9922ac5be4Sperrin 	uint64_t	zl_prev_used;	/* previous commit log size used */
100fa9e4066Sahrens 	list_t		zl_lwb_list;	/* in-flight log write list */
10117f17c2dSbonwick 	kmutex_t	zl_vdev_lock;	/* protects zl_vdev_tree */
10217f17c2dSbonwick 	avl_tree_t	zl_vdev_tree;	/* vdevs to flush in zil_commit() */
103fa9e4066Sahrens 	taskq_t		*zl_clean_taskq; /* runs lwb and itx clean tasks */
104b24ab676SJeff Bonwick 	avl_tree_t	zl_bp_tree;	/* track bps during log parse */
10567bd71c6Sperrin 	clock_t		zl_replay_time;	/* lbolt of when replay started */
10667bd71c6Sperrin 	uint64_t	zl_replay_blks;	/* number of log blocks replayed */
107b24ab676SJeff Bonwick 	zil_header_t	zl_old_header;	/* debugging aid */
1086e1f5caaSNeil Perrin 	uint_t		zl_prev_blks[ZIL_PREV_BLKS]; /* size - sector rounded */
1096e1f5caaSNeil Perrin 	uint_t		zl_prev_rotor;	/* rotor for zl_prev[] */
110fa9e4066Sahrens };
111fa9e4066Sahrens 
112b24ab676SJeff Bonwick typedef struct zil_bp_node {
113fa9e4066Sahrens 	dva_t		zn_dva;
114fa9e4066Sahrens 	avl_node_t	zn_node;
115b24ab676SJeff Bonwick } zil_bp_node_t;
116fa9e4066Sahrens 
1176e1f5caaSNeil Perrin #define	ZIL_MAX_LOG_DATA (SPA_MAXBLOCKSIZE - sizeof (zil_chain_t) - \
118510b6c0eSNeil Perrin     sizeof (lr_write_t))
119510b6c0eSNeil Perrin 
120fa9e4066Sahrens #ifdef	__cplusplus
121fa9e4066Sahrens }
122fa9e4066Sahrens #endif
123fa9e4066Sahrens 
124fa9e4066Sahrens #endif	/* _SYS_ZIL_IMPL_H */
125