xref: /titanic_44/usr/src/uts/common/fs/zfs/sys/zil.h (revision 12380e1e701fda28c9e9f32d01cafb54af279eb5)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5436b2950Sperrin  * Common Development and Distribution License (the "License").
6436b2950Sperrin  * 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 /*
2255da60b9SMark J Musante  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23ce636f8bSMatthew Ahrens  * Copyright (c) 2012 by Delphix. All rights reserved.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
2655da60b9SMark J Musante /* Portions Copyright 2010 Robert Milkowski */
2755da60b9SMark J Musante 
28fa9e4066Sahrens #ifndef	_SYS_ZIL_H
29fa9e4066Sahrens #define	_SYS_ZIL_H
30fa9e4066Sahrens 
31fa9e4066Sahrens #include <sys/types.h>
32fa9e4066Sahrens #include <sys/spa.h>
33fa9e4066Sahrens #include <sys/zio.h>
34fa9e4066Sahrens #include <sys/dmu.h>
35fa9e4066Sahrens 
36fa9e4066Sahrens #ifdef	__cplusplus
37fa9e4066Sahrens extern "C" {
38fa9e4066Sahrens #endif
39fa9e4066Sahrens 
40*12380e1eSArne Jansen struct dsl_pool;
41*12380e1eSArne Jansen struct dsl_dataset;
42*12380e1eSArne Jansen 
43fa9e4066Sahrens /*
44fa9e4066Sahrens  * Intent log format:
45fa9e4066Sahrens  *
46fa9e4066Sahrens  * Each objset has its own intent log.  The log header (zil_header_t)
47fa9e4066Sahrens  * for objset N's intent log is kept in the Nth object of the SPA's
48fa9e4066Sahrens  * intent_log objset.  The log header points to a chain of log blocks,
49fa9e4066Sahrens  * each of which contains log records (i.e., transactions) followed by
50fa9e4066Sahrens  * a log block trailer (zil_trailer_t).  The format of a log record
51fa9e4066Sahrens  * depends on the record (or transaction) type, but all records begin
52fa9e4066Sahrens  * with a common structure that defines the type, length, and txg.
53fa9e4066Sahrens  */
54fa9e4066Sahrens 
55fa9e4066Sahrens /*
56fa9e4066Sahrens  * Intent log header - this on disk structure holds fields to manage
57fa9e4066Sahrens  * the log.  All fields are 64 bit to easily handle cross architectures.
58fa9e4066Sahrens  */
59fa9e4066Sahrens typedef struct zil_header {
60fa9e4066Sahrens 	uint64_t zh_claim_txg;	/* txg in which log blocks were claimed */
61fa9e4066Sahrens 	uint64_t zh_replay_seq;	/* highest replayed sequence number */
62fa9e4066Sahrens 	blkptr_t zh_log;	/* log chain */
63b24ab676SJeff Bonwick 	uint64_t zh_claim_blk_seq; /* highest claimed block sequence number */
643589c4f0SNeil Perrin 	uint64_t zh_flags;	/* header flags */
65b24ab676SJeff Bonwick 	uint64_t zh_claim_lr_seq; /* highest claimed lr sequence number */
66b24ab676SJeff Bonwick 	uint64_t zh_pad[3];
67fa9e4066Sahrens } zil_header_t;
68fa9e4066Sahrens 
69fa9e4066Sahrens /*
703589c4f0SNeil Perrin  * zh_flags bit settings
713589c4f0SNeil Perrin  */
723589c4f0SNeil Perrin #define	ZIL_REPLAY_NEEDED	0x1	/* replay needed - internal only */
73b24ab676SJeff Bonwick #define	ZIL_CLAIM_LR_SEQ_VALID	0x2	/* zh_claim_lr_seq field is valid */
743589c4f0SNeil Perrin 
753589c4f0SNeil Perrin /*
766e1f5caaSNeil Perrin  * Log block chaining.
77fa9e4066Sahrens  *
786e1f5caaSNeil Perrin  * Log blocks are chained together. Originally they were chained at the
796e1f5caaSNeil Perrin  * end of the block. For performance reasons the chain was moved to the
806e1f5caaSNeil Perrin  * beginning of the block which allows writes for only the data being used.
816e1f5caaSNeil Perrin  * The older position is supported for backwards compatability.
826e1f5caaSNeil Perrin  *
836e1f5caaSNeil Perrin  * The zio_eck_t contains a zec_cksum which for the intent log is
84fa9e4066Sahrens  * the sequence number of this log block. A seq of 0 is invalid.
856e1f5caaSNeil Perrin  * The zec_cksum is checked by the SPA against the sequence
86fa9e4066Sahrens  * number passed in the blk_cksum field of the blkptr_t
87fa9e4066Sahrens  */
886e1f5caaSNeil Perrin typedef struct zil_chain {
896e1f5caaSNeil Perrin 	uint64_t zc_pad;
906e1f5caaSNeil Perrin 	blkptr_t zc_next_blk;	/* next block in chain */
916e1f5caaSNeil Perrin 	uint64_t zc_nused;	/* bytes in log block used */
926e1f5caaSNeil Perrin 	zio_eck_t zc_eck;	/* block trailer */
936e1f5caaSNeil Perrin } zil_chain_t;
94fa9e4066Sahrens 
95b4d654b0Sperrin #define	ZIL_MIN_BLKSZ	4096ULL
96fa9e4066Sahrens 
97fa9e4066Sahrens /*
98d80c45e0Sbonwick  * The words of a log block checksum.
99d80c45e0Sbonwick  */
100d80c45e0Sbonwick #define	ZIL_ZC_GUID_0	0
101d80c45e0Sbonwick #define	ZIL_ZC_GUID_1	1
102d80c45e0Sbonwick #define	ZIL_ZC_OBJSET	2
103d80c45e0Sbonwick #define	ZIL_ZC_SEQ	3
104d80c45e0Sbonwick 
105da6c28aaSamw typedef enum zil_create {
106da6c28aaSamw 	Z_FILE,
107da6c28aaSamw 	Z_DIR,
108da6c28aaSamw 	Z_XATTRDIR,
109da6c28aaSamw } zil_create_t;
110da6c28aaSamw 
111da6c28aaSamw /*
112da6c28aaSamw  * size of xvattr log section.
113da6c28aaSamw  * its composed of lr_attr_t + xvattr bitmap + 2 64 bit timestamps
114da6c28aaSamw  * for create time and a single 64 bit integer for all of the attributes,
115da6c28aaSamw  * and 4 64 bit integers (32 bytes) for the scanstamp.
116da6c28aaSamw  *
117da6c28aaSamw  */
118da6c28aaSamw 
119da6c28aaSamw #define	ZIL_XVAT_SIZE(mapsize) \
120da6c28aaSamw 	sizeof (lr_attr_t) + (sizeof (uint32_t) * (mapsize - 1)) + \
121da6c28aaSamw 	(sizeof (uint64_t) * 7)
122569e6c63Smarks 
123569e6c63Smarks /*
124569e6c63Smarks  * Size of ACL in log.  The ACE data is padded out to properly align
125569e6c63Smarks  * on 8 byte boundary.
126569e6c63Smarks  */
127569e6c63Smarks 
128569e6c63Smarks #define	ZIL_ACE_LENGTH(x)	(roundup(x, sizeof (uint64_t)))
129569e6c63Smarks 
130d80c45e0Sbonwick /*
131fa9e4066Sahrens  * Intent log transaction types and record structures
132fa9e4066Sahrens  */
133fa9e4066Sahrens #define	TX_CREATE		1	/* Create file */
134fa9e4066Sahrens #define	TX_MKDIR		2	/* Make directory */
135fa9e4066Sahrens #define	TX_MKXATTR		3	/* Make XATTR directory */
136fa9e4066Sahrens #define	TX_SYMLINK		4	/* Create symbolic link to a file */
137fa9e4066Sahrens #define	TX_REMOVE		5	/* Remove file */
138fa9e4066Sahrens #define	TX_RMDIR		6	/* Remove directory */
139fa9e4066Sahrens #define	TX_LINK			7	/* Create hard link to a file */
140fa9e4066Sahrens #define	TX_RENAME		8	/* Rename a file */
141fa9e4066Sahrens #define	TX_WRITE		9	/* File write */
142fa9e4066Sahrens #define	TX_TRUNCATE		10	/* Truncate a file */
143fa9e4066Sahrens #define	TX_SETATTR		11	/* Set file attributes */
144da6c28aaSamw #define	TX_ACL_V0		12	/* Set old formatted ACL */
145da6c28aaSamw #define	TX_ACL			13	/* Set ACL */
146da6c28aaSamw #define	TX_CREATE_ACL		14	/* create with ACL */
147da6c28aaSamw #define	TX_CREATE_ATTR		15	/* create + attrs */
148da6c28aaSamw #define	TX_CREATE_ACL_ATTR 	16	/* create with ACL + attrs */
149da6c28aaSamw #define	TX_MKDIR_ACL		17	/* mkdir with ACL */
150da6c28aaSamw #define	TX_MKDIR_ATTR		18	/* mkdir with attr */
151da6c28aaSamw #define	TX_MKDIR_ACL_ATTR	19	/* mkdir with ACL + attrs */
152975c32a0SNeil Perrin #define	TX_WRITE2		20	/* dmu_sync EALREADY write */
153975c32a0SNeil Perrin #define	TX_MAX_TYPE		21	/* Max transaction type */
154da6c28aaSamw 
155da6c28aaSamw /*
156da6c28aaSamw  * The transactions for mkdir, symlink, remove, rmdir, link, and rename
157da6c28aaSamw  * may have the following bit set, indicating the original request
158da6c28aaSamw  * specified case-insensitive handling of names.
159da6c28aaSamw  */
160da6c28aaSamw #define	TX_CI	((uint64_t)0x1 << 63) /* case-insensitive behavior requested */
161fa9e4066Sahrens 
162fa9e4066Sahrens /*
163b24ab676SJeff Bonwick  * Transactions for write, truncate, setattr, acl_v0, and acl can be logged
164b24ab676SJeff Bonwick  * out of order.  For convenience in the code, all such records must have
165b24ab676SJeff Bonwick  * lr_foid at the same offset.
166b24ab676SJeff Bonwick  */
167b24ab676SJeff Bonwick #define	TX_OOO(txtype)			\
168b24ab676SJeff Bonwick 	((txtype) == TX_WRITE ||	\
169b24ab676SJeff Bonwick 	(txtype) == TX_TRUNCATE ||	\
170b24ab676SJeff Bonwick 	(txtype) == TX_SETATTR ||	\
171b24ab676SJeff Bonwick 	(txtype) == TX_ACL_V0 ||	\
172b24ab676SJeff Bonwick 	(txtype) == TX_ACL ||		\
173b24ab676SJeff Bonwick 	(txtype) == TX_WRITE2)
174b24ab676SJeff Bonwick 
175b24ab676SJeff Bonwick /*
176fa9e4066Sahrens  * Format of log records.
177fa9e4066Sahrens  * The fields are carefully defined to allow them to be aligned
178fa9e4066Sahrens  * and sized the same on sparc & intel architectures.
179fa9e4066Sahrens  * Each log record has a common structure at the beginning.
180b19a79ecSperrin  *
1815002558fSNeil Perrin  * The log record on disk (lrc_seq) holds the sequence number of all log
1825002558fSNeil Perrin  * records which is used to ensure we don't replay the same record.
183fa9e4066Sahrens  */
184fa9e4066Sahrens typedef struct {			/* common log record header */
185fa9e4066Sahrens 	uint64_t	lrc_txtype;	/* intent log transaction type */
186fa9e4066Sahrens 	uint64_t	lrc_reclen;	/* transaction record length */
187fa9e4066Sahrens 	uint64_t	lrc_txg;	/* dmu transaction group number */
188b19a79ecSperrin 	uint64_t	lrc_seq;	/* see comment above */
189fa9e4066Sahrens } lr_t;
190fa9e4066Sahrens 
191da6c28aaSamw /*
192b24ab676SJeff Bonwick  * Common start of all out-of-order record types (TX_OOO() above).
193b24ab676SJeff Bonwick  */
194b24ab676SJeff Bonwick typedef struct {
195b24ab676SJeff Bonwick 	lr_t		lr_common;	/* common portion of log record */
196b24ab676SJeff Bonwick 	uint64_t	lr_foid;	/* object id */
197b24ab676SJeff Bonwick } lr_ooo_t;
198b24ab676SJeff Bonwick 
199b24ab676SJeff Bonwick /*
200da6c28aaSamw  * Handle option extended vattr attributes.
201da6c28aaSamw  *
202da6c28aaSamw  * Whenever new attributes are added the version number
203da6c28aaSamw  * will need to be updated as will code in
204da6c28aaSamw  * zfs_log.c and zfs_replay.c
205da6c28aaSamw  */
206da6c28aaSamw typedef struct {
207da6c28aaSamw 	uint32_t	lr_attr_masksize; /* number of elements in array */
208da6c28aaSamw 	uint32_t	lr_attr_bitmap; /* First entry of array */
209da6c28aaSamw 	/* remainder of array and any additional fields */
210da6c28aaSamw } lr_attr_t;
211da6c28aaSamw 
212da6c28aaSamw /*
213da6c28aaSamw  * log record for creates without optional ACL.
214da6c28aaSamw  * This log record does support optional xvattr_t attributes.
215da6c28aaSamw  */
216fa9e4066Sahrens typedef struct {
217fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
218fa9e4066Sahrens 	uint64_t	lr_doid;	/* object id of directory */
219fa9e4066Sahrens 	uint64_t	lr_foid;	/* object id of created file object */
220fa9e4066Sahrens 	uint64_t	lr_mode;	/* mode of object */
221fa9e4066Sahrens 	uint64_t	lr_uid;		/* uid of object */
222fa9e4066Sahrens 	uint64_t	lr_gid;		/* gid of object */
223fa9e4066Sahrens 	uint64_t	lr_gen;		/* generation (txg of creation) */
224fa9e4066Sahrens 	uint64_t	lr_crtime[2];	/* creation time */
225fa9e4066Sahrens 	uint64_t	lr_rdev;	/* rdev of object to create */
226fa9e4066Sahrens 	/* name of object to create follows this */
227fa9e4066Sahrens 	/* for symlinks, link content follows name */
228da6c28aaSamw 	/* for creates with xvattr data, the name follows the xvattr info */
229fa9e4066Sahrens } lr_create_t;
230fa9e4066Sahrens 
231da6c28aaSamw /*
232da6c28aaSamw  * FUID ACL record will be an array of ACEs from the original ACL.
233da6c28aaSamw  * If this array includes ephemeral IDs, the record will also include
234da6c28aaSamw  * an array of log-specific FUIDs to replace the ephemeral IDs.
235da6c28aaSamw  * Only one copy of each unique domain will be present, so the log-specific
236da6c28aaSamw  * FUIDs will use an index into a compressed domain table.  On replay this
237da6c28aaSamw  * information will be used to construct real FUIDs (and bypass idmap,
238da6c28aaSamw  * since it may not be available).
239da6c28aaSamw  */
240da6c28aaSamw 
241da6c28aaSamw /*
242da6c28aaSamw  * Log record for creates with optional ACL
243da6c28aaSamw  * This log record is also used for recording any FUID
244da6c28aaSamw  * information needed for replaying the create.  If the
245da6c28aaSamw  * file doesn't have any actual ACEs then the lr_aclcnt
246da6c28aaSamw  * would be zero.
247f7170741SWill Andrews  *
248f7170741SWill Andrews  * After lr_acl_flags, there are a lr_acl_bytes number of variable sized ace's.
249f7170741SWill Andrews  * If create is also setting xvattr's, then acl data follows xvattr.
250f7170741SWill Andrews  * If ACE FUIDs are needed then they will follow the xvattr_t.  Following
251f7170741SWill Andrews  * the FUIDs will be the domain table information.  The FUIDs for the owner
252f7170741SWill Andrews  * and group will be in lr_create.  Name follows ACL data.
253da6c28aaSamw  */
254da6c28aaSamw typedef struct {
255da6c28aaSamw 	lr_create_t	lr_create;	/* common create portion */
256da6c28aaSamw 	uint64_t	lr_aclcnt;	/* number of ACEs in ACL */
257da6c28aaSamw 	uint64_t	lr_domcnt;	/* number of unique domains */
258da6c28aaSamw 	uint64_t	lr_fuidcnt;	/* number of real fuids */
259da6c28aaSamw 	uint64_t	lr_acl_bytes;	/* number of bytes in ACL */
260da6c28aaSamw 	uint64_t	lr_acl_flags;	/* ACL flags */
261da6c28aaSamw } lr_acl_create_t;
262da6c28aaSamw 
263fa9e4066Sahrens typedef struct {
264fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
265fa9e4066Sahrens 	uint64_t	lr_doid;	/* obj id of directory */
266fa9e4066Sahrens 	/* name of object to remove follows this */
267fa9e4066Sahrens } lr_remove_t;
268fa9e4066Sahrens 
269fa9e4066Sahrens typedef struct {
270fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
271fa9e4066Sahrens 	uint64_t	lr_doid;	/* obj id of directory */
272fa9e4066Sahrens 	uint64_t	lr_link_obj;	/* obj id of link */
273fa9e4066Sahrens 	/* name of object to link follows this */
274fa9e4066Sahrens } lr_link_t;
275fa9e4066Sahrens 
276fa9e4066Sahrens typedef struct {
277fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
278fa9e4066Sahrens 	uint64_t	lr_sdoid;	/* obj id of source directory */
279fa9e4066Sahrens 	uint64_t	lr_tdoid;	/* obj id of target directory */
280fa9e4066Sahrens 	/* 2 strings: names of source and destination follow this */
281fa9e4066Sahrens } lr_rename_t;
282fa9e4066Sahrens 
283fa9e4066Sahrens typedef struct {
284fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
285fa9e4066Sahrens 	uint64_t	lr_foid;	/* file object to write */
286fa9e4066Sahrens 	uint64_t	lr_offset;	/* offset to write to */
287fa9e4066Sahrens 	uint64_t	lr_length;	/* user data length to write */
288b24ab676SJeff Bonwick 	uint64_t	lr_blkoff;	/* no longer used */
289fa9e4066Sahrens 	blkptr_t	lr_blkptr;	/* spa block pointer for replay */
290fa9e4066Sahrens 	/* write data will follow for small writes */
291fa9e4066Sahrens } lr_write_t;
292fa9e4066Sahrens 
293fa9e4066Sahrens typedef struct {
294fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
295fa9e4066Sahrens 	uint64_t	lr_foid;	/* object id of file to truncate */
296fa9e4066Sahrens 	uint64_t	lr_offset;	/* offset to truncate from */
297fa9e4066Sahrens 	uint64_t	lr_length;	/* length to truncate */
298fa9e4066Sahrens } lr_truncate_t;
299fa9e4066Sahrens 
300fa9e4066Sahrens typedef struct {
301fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
302fa9e4066Sahrens 	uint64_t	lr_foid;	/* file object to change attributes */
303fa9e4066Sahrens 	uint64_t	lr_mask;	/* mask of attributes to set */
304fa9e4066Sahrens 	uint64_t	lr_mode;	/* mode to set */
305fa9e4066Sahrens 	uint64_t	lr_uid;		/* uid to set */
306fa9e4066Sahrens 	uint64_t	lr_gid;		/* gid to set */
307fa9e4066Sahrens 	uint64_t	lr_size;	/* size to set */
308fa9e4066Sahrens 	uint64_t	lr_atime[2];	/* access time */
309fa9e4066Sahrens 	uint64_t	lr_mtime[2];	/* modification time */
310da6c28aaSamw 	/* optional attribute lr_attr_t may be here */
311fa9e4066Sahrens } lr_setattr_t;
312fa9e4066Sahrens 
313fa9e4066Sahrens typedef struct {
314fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
315fa9e4066Sahrens 	uint64_t	lr_foid;	/* obj id of file */
316fa9e4066Sahrens 	uint64_t	lr_aclcnt;	/* number of acl entries */
317fa9e4066Sahrens 	/* lr_aclcnt number of ace_t entries follow this */
318da6c28aaSamw } lr_acl_v0_t;
319da6c28aaSamw 
320da6c28aaSamw typedef struct {
321da6c28aaSamw 	lr_t		lr_common;	/* common portion of log record */
322da6c28aaSamw 	uint64_t	lr_foid;	/* obj id of file */
323da6c28aaSamw 	uint64_t	lr_aclcnt;	/* number of ACEs in ACL */
324da6c28aaSamw 	uint64_t	lr_domcnt;	/* number of unique domains */
325da6c28aaSamw 	uint64_t	lr_fuidcnt;	/* number of real fuids */
326da6c28aaSamw 	uint64_t	lr_acl_bytes;	/* number of bytes in ACL */
327da6c28aaSamw 	uint64_t	lr_acl_flags;	/* ACL flags */
328da6c28aaSamw 	/* lr_acl_bytes number of variable sized ace's follows */
329fa9e4066Sahrens } lr_acl_t;
330fa9e4066Sahrens 
331fa9e4066Sahrens /*
332fa9e4066Sahrens  * ZIL structure definitions, interface function prototype and globals.
333fa9e4066Sahrens  */
334fa9e4066Sahrens 
335fa9e4066Sahrens /*
336510b6c0eSNeil Perrin  * Writes are handled in three different ways:
337510b6c0eSNeil Perrin  *
338510b6c0eSNeil Perrin  * WR_INDIRECT:
339510b6c0eSNeil Perrin  *    In this mode, if we need to commit the write later, then the block
340510b6c0eSNeil Perrin  *    is immediately written into the file system (using dmu_sync),
341510b6c0eSNeil Perrin  *    and a pointer to the block is put into the log record.
342510b6c0eSNeil Perrin  *    When the txg commits the block is linked in.
343510b6c0eSNeil Perrin  *    This saves additionally writing the data into the log record.
344510b6c0eSNeil Perrin  *    There are a few requirements for this to occur:
345510b6c0eSNeil Perrin  *	- write is greater than zfs/zvol_immediate_write_sz
346510b6c0eSNeil Perrin  *	- not using slogs (as slogs are assumed to always be faster
347510b6c0eSNeil Perrin  *	  than writing into the main pool)
348510b6c0eSNeil Perrin  *	- the write occupies only one block
349510b6c0eSNeil Perrin  * WR_COPIED:
350510b6c0eSNeil Perrin  *    If we know we'll immediately be committing the
351510b6c0eSNeil Perrin  *    transaction (FSYNC or FDSYNC), the we allocate a larger
352510b6c0eSNeil Perrin  *    log record here for the data and copy the data in.
353510b6c0eSNeil Perrin  * WR_NEED_COPY:
354510b6c0eSNeil Perrin  *    Otherwise we don't allocate a buffer, and *if* we need to
355510b6c0eSNeil Perrin  *    flush the write later then a buffer is allocated and
356510b6c0eSNeil Perrin  *    we retrieve the data using the dmu.
357fa9e4066Sahrens  */
358104e2ed7Sperrin typedef enum {
359104e2ed7Sperrin 	WR_INDIRECT,	/* indirect - a large write (dmu_sync() data */
360104e2ed7Sperrin 			/* and put blkptr in log, rather than actual data) */
361104e2ed7Sperrin 	WR_COPIED,	/* immediate - data is copied into lr_write_t */
362104e2ed7Sperrin 	WR_NEED_COPY,	/* immediate - data needs to be copied if pushed */
363b24ab676SJeff Bonwick 	WR_NUM_STATES	/* number of states */
364104e2ed7Sperrin } itx_wr_state_t;
365104e2ed7Sperrin 
366fa9e4066Sahrens typedef struct itx {
367fa9e4066Sahrens 	list_node_t	itx_node;	/* linkage on zl_itx_list */
368fa9e4066Sahrens 	void		*itx_private;	/* type-specific opaque data */
369104e2ed7Sperrin 	itx_wr_state_t	itx_wr_state;	/* write state */
37067bd71c6Sperrin 	uint8_t		itx_sync;	/* synchronous transaction */
371abf76b6eSperrin 	uint64_t	itx_sod;	/* record size on disk */
37251bd2f97SNeil Perrin 	uint64_t	itx_oid;	/* object id */
373fa9e4066Sahrens 	lr_t		itx_lr;		/* common part of log record */
374fa9e4066Sahrens 	/* followed by type-specific part of lr_xx_t and its immediate data */
375fa9e4066Sahrens } itx_t;
376fa9e4066Sahrens 
377b24ab676SJeff Bonwick typedef int zil_parse_blk_func_t(zilog_t *zilog, blkptr_t *bp, void *arg,
378fa9e4066Sahrens     uint64_t txg);
379b24ab676SJeff Bonwick typedef int zil_parse_lr_func_t(zilog_t *zilog, lr_t *lr, void *arg,
380fa9e4066Sahrens     uint64_t txg);
381fa9e4066Sahrens typedef int zil_replay_func_t();
382c5c6ffa0Smaybee typedef int zil_get_data_t(void *arg, lr_write_t *lr, char *dbuf, zio_t *zio);
383fa9e4066Sahrens 
384b24ab676SJeff Bonwick extern int zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
385fa9e4066Sahrens     zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg);
386fa9e4066Sahrens 
387fa9e4066Sahrens extern void	zil_init(void);
388fa9e4066Sahrens extern void	zil_fini(void);
389fa9e4066Sahrens 
390fa9e4066Sahrens extern zilog_t	*zil_alloc(objset_t *os, zil_header_t *zh_phys);
391fa9e4066Sahrens extern void	zil_free(zilog_t *zilog);
392fa9e4066Sahrens 
393fa9e4066Sahrens extern zilog_t	*zil_open(objset_t *os, zil_get_data_t *get_data);
394fa9e4066Sahrens extern void	zil_close(zilog_t *zilog);
395fa9e4066Sahrens 
3961209a471SNeil Perrin extern void	zil_replay(objset_t *os, void *arg,
3971209a471SNeil Perrin     zil_replay_func_t *replay_func[TX_MAX_TYPE]);
398b24ab676SJeff Bonwick extern boolean_t zil_replaying(zilog_t *zilog, dmu_tx_t *tx);
399d80c45e0Sbonwick extern void	zil_destroy(zilog_t *zilog, boolean_t keep_first);
400ce636f8bSMatthew Ahrens extern void	zil_destroy_sync(zilog_t *zilog, dmu_tx_t *tx);
4013a8a1de4Sperrin extern void	zil_rollback_destroy(zilog_t *zilog, dmu_tx_t *tx);
402fa9e4066Sahrens 
403da6c28aaSamw extern itx_t	*zil_itx_create(uint64_t txtype, size_t lrsize);
404b24ab676SJeff Bonwick extern void	zil_itx_destroy(itx_t *itx);
4055002558fSNeil Perrin extern void	zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx);
406fa9e4066Sahrens 
4075002558fSNeil Perrin extern void	zil_commit(zilog_t *zilog, uint64_t oid);
408fa9e4066Sahrens 
409fd136879SMatthew Ahrens extern int	zil_vdev_offline(const char *osname, void *txarg);
410*12380e1eSArne Jansen extern int	zil_claim(struct dsl_pool *dp,
411*12380e1eSArne Jansen     struct dsl_dataset *ds, void *txarg);
412*12380e1eSArne Jansen extern int 	zil_check_log_chain(struct dsl_pool *dp,
413*12380e1eSArne Jansen     struct dsl_dataset *ds, void *tx);
414fa9e4066Sahrens extern void	zil_sync(zilog_t *zilog, dmu_tx_t *tx);
4155002558fSNeil Perrin extern void	zil_clean(zilog_t *zilog, uint64_t synced_txg);
416fa9e4066Sahrens 
4173b2aab18SMatthew Ahrens extern int	zil_suspend(const char *osname, void **cookiep);
4183b2aab18SMatthew Ahrens extern void	zil_resume(void *cookie);
419fa9e4066Sahrens 
420b24ab676SJeff Bonwick extern void	zil_add_block(zilog_t *zilog, const blkptr_t *bp);
421b24ab676SJeff Bonwick extern int	zil_bp_tree_add(zilog_t *zilog, const blkptr_t *bp);
422b24ab676SJeff Bonwick 
42355da60b9SMark J Musante extern void	zil_set_sync(zilog_t *zilog, uint64_t syncval);
42455da60b9SMark J Musante 
425e09fa4daSNeil Perrin extern void	zil_set_logbias(zilog_t *zilog, uint64_t slogval);
426e09fa4daSNeil Perrin 
42755da60b9SMark J Musante extern int zil_replay_disable;
428fa9e4066Sahrens 
429fa9e4066Sahrens #ifdef	__cplusplus
430fa9e4066Sahrens }
431fa9e4066Sahrens #endif
432fa9e4066Sahrens 
433fa9e4066Sahrens #endif	/* _SYS_ZIL_H */
434