xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zil.h (revision 54811da5ac6b517992fdc173df5d605e4e61fdc0)
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.
23b7b2590dSMatthew Ahrens  * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
24c3d26abcSMatthew Ahrens  * Copyright (c) 2014 Integros [integros.com]
25fa9e4066Sahrens  */
26fa9e4066Sahrens 
2755da60b9SMark J Musante /* Portions Copyright 2010 Robert Milkowski */
2855da60b9SMark J Musante 
29fa9e4066Sahrens #ifndef	_SYS_ZIL_H
30fa9e4066Sahrens #define	_SYS_ZIL_H
31fa9e4066Sahrens 
32fa9e4066Sahrens #include <sys/types.h>
33fa9e4066Sahrens #include <sys/spa.h>
34fa9e4066Sahrens #include <sys/zio.h>
35fa9e4066Sahrens #include <sys/dmu.h>
36fa9e4066Sahrens 
37fa9e4066Sahrens #ifdef	__cplusplus
38fa9e4066Sahrens extern "C" {
39fa9e4066Sahrens #endif
40fa9e4066Sahrens 
4112380e1eSArne Jansen struct dsl_pool;
4212380e1eSArne Jansen struct dsl_dataset;
431271e4b1SPrakash Surya struct lwb;
4412380e1eSArne Jansen 
45fa9e4066Sahrens /*
46fa9e4066Sahrens  * Intent log format:
47fa9e4066Sahrens  *
48fa9e4066Sahrens  * Each objset has its own intent log.  The log header (zil_header_t)
49fa9e4066Sahrens  * for objset N's intent log is kept in the Nth object of the SPA's
50fa9e4066Sahrens  * intent_log objset.  The log header points to a chain of log blocks,
51fa9e4066Sahrens  * each of which contains log records (i.e., transactions) followed by
52fa9e4066Sahrens  * a log block trailer (zil_trailer_t).  The format of a log record
53fa9e4066Sahrens  * depends on the record (or transaction) type, but all records begin
54fa9e4066Sahrens  * with a common structure that defines the type, length, and txg.
55fa9e4066Sahrens  */
56fa9e4066Sahrens 
57fa9e4066Sahrens /*
58fa9e4066Sahrens  * Intent log header - this on disk structure holds fields to manage
59fa9e4066Sahrens  * the log.  All fields are 64 bit to easily handle cross architectures.
60fa9e4066Sahrens  */
61fa9e4066Sahrens typedef struct zil_header {
62fa9e4066Sahrens 	uint64_t zh_claim_txg;	/* txg in which log blocks were claimed */
63fa9e4066Sahrens 	uint64_t zh_replay_seq;	/* highest replayed sequence number */
64fa9e4066Sahrens 	blkptr_t zh_log;	/* log chain */
65b24ab676SJeff Bonwick 	uint64_t zh_claim_blk_seq; /* highest claimed block sequence number */
663589c4f0SNeil Perrin 	uint64_t zh_flags;	/* header flags */
67b24ab676SJeff Bonwick 	uint64_t zh_claim_lr_seq; /* highest claimed lr sequence number */
68b24ab676SJeff Bonwick 	uint64_t zh_pad[3];
69fa9e4066Sahrens } zil_header_t;
70fa9e4066Sahrens 
713589c4f0SNeil Perrin /*
723589c4f0SNeil Perrin  * zh_flags bit settings
733589c4f0SNeil Perrin  */
74b24ab676SJeff Bonwick #define	ZIL_REPLAY_NEEDED	0x1	/* replay needed - internal only */
75b24ab676SJeff Bonwick #define	ZIL_CLAIM_LR_SEQ_VALID	0x2	/* zh_claim_lr_seq field is valid */
763589c4f0SNeil Perrin 
77fa9e4066Sahrens /*
786e1f5caaSNeil Perrin  * Log block chaining.
79fa9e4066Sahrens  *
806e1f5caaSNeil Perrin  * Log blocks are chained together. Originally they were chained at the
816e1f5caaSNeil Perrin  * end of the block. For performance reasons the chain was moved to the
826e1f5caaSNeil Perrin  * beginning of the block which allows writes for only the data being used.
836e1f5caaSNeil Perrin  * The older position is supported for backwards compatability.
846e1f5caaSNeil Perrin  *
856e1f5caaSNeil Perrin  * The zio_eck_t contains a zec_cksum which for the intent log is
86fa9e4066Sahrens  * the sequence number of this log block. A seq of 0 is invalid.
876e1f5caaSNeil Perrin  * The zec_cksum is checked by the SPA against the sequence
88fa9e4066Sahrens  * number passed in the blk_cksum field of the blkptr_t
89fa9e4066Sahrens  */
906e1f5caaSNeil Perrin typedef struct zil_chain {
916e1f5caaSNeil Perrin 	uint64_t zc_pad;
926e1f5caaSNeil Perrin 	blkptr_t zc_next_blk;	/* next block in chain */
936e1f5caaSNeil Perrin 	uint64_t zc_nused;	/* bytes in log block used */
946e1f5caaSNeil Perrin 	zio_eck_t zc_eck;	/* block trailer */
956e1f5caaSNeil Perrin } zil_chain_t;
96fa9e4066Sahrens 
97b4d654b0Sperrin #define	ZIL_MIN_BLKSZ	4096ULL
98fa9e4066Sahrens 
99b7b2590dSMatthew Ahrens /*
100b7b2590dSMatthew Ahrens  * ziltest is by and large an ugly hack, but very useful in
101b7b2590dSMatthew Ahrens  * checking replay without tedious work.
102b7b2590dSMatthew Ahrens  * When running ziltest we want to keep all itx's and so maintain
103b7b2590dSMatthew Ahrens  * a single list in the zl_itxg[] that uses a high txg: ZILTEST_TXG
104b7b2590dSMatthew Ahrens  * We subtract TXG_CONCURRENT_STATES to allow for common code.
105b7b2590dSMatthew Ahrens  */
106b7b2590dSMatthew Ahrens #define	ZILTEST_TXG (UINT64_MAX - TXG_CONCURRENT_STATES)
107b7b2590dSMatthew Ahrens 
108d80c45e0Sbonwick /*
109d80c45e0Sbonwick  * The words of a log block checksum.
110d80c45e0Sbonwick  */
111d80c45e0Sbonwick #define	ZIL_ZC_GUID_0	0
112d80c45e0Sbonwick #define	ZIL_ZC_GUID_1	1
113d80c45e0Sbonwick #define	ZIL_ZC_OBJSET	2
114d80c45e0Sbonwick #define	ZIL_ZC_SEQ	3
115d80c45e0Sbonwick 
116da6c28aaSamw typedef enum zil_create {
117da6c28aaSamw 	Z_FILE,
118da6c28aaSamw 	Z_DIR,
119da6c28aaSamw 	Z_XATTRDIR,
120da6c28aaSamw } zil_create_t;
121da6c28aaSamw 
122da6c28aaSamw /*
123da6c28aaSamw  * size of xvattr log section.
124da6c28aaSamw  * its composed of lr_attr_t + xvattr bitmap + 2 64 bit timestamps
125da6c28aaSamw  * for create time and a single 64 bit integer for all of the attributes,
126da6c28aaSamw  * and 4 64 bit integers (32 bytes) for the scanstamp.
127da6c28aaSamw  *
128da6c28aaSamw  */
129da6c28aaSamw 
130da6c28aaSamw #define	ZIL_XVAT_SIZE(mapsize) \
131da6c28aaSamw 	sizeof (lr_attr_t) + (sizeof (uint32_t) * (mapsize - 1)) + \
132da6c28aaSamw 	(sizeof (uint64_t) * 7)
133569e6c63Smarks 
134569e6c63Smarks /*
135569e6c63Smarks  * Size of ACL in log.  The ACE data is padded out to properly align
136569e6c63Smarks  * on 8 byte boundary.
137569e6c63Smarks  */
138569e6c63Smarks 
139569e6c63Smarks #define	ZIL_ACE_LENGTH(x)	(roundup(x, sizeof (uint64_t)))
140569e6c63Smarks 
141fa9e4066Sahrens /*
142fa9e4066Sahrens  * Intent log transaction types and record structures
143fa9e4066Sahrens  */
1441271e4b1SPrakash Surya #define	TX_COMMIT		0	/* Commit marker (no on-disk state) */
145da6c28aaSamw #define	TX_CREATE		1	/* Create file */
146da6c28aaSamw #define	TX_MKDIR		2	/* Make directory */
147da6c28aaSamw #define	TX_MKXATTR		3	/* Make XATTR directory */
148da6c28aaSamw #define	TX_SYMLINK		4	/* Create symbolic link to a file */
149da6c28aaSamw #define	TX_REMOVE		5	/* Remove file */
150da6c28aaSamw #define	TX_RMDIR		6	/* Remove directory */
151da6c28aaSamw #define	TX_LINK			7	/* Create hard link to a file */
152da6c28aaSamw #define	TX_RENAME		8	/* Rename a file */
153da6c28aaSamw #define	TX_WRITE		9	/* File write */
154da6c28aaSamw #define	TX_TRUNCATE		10	/* Truncate a file */
155da6c28aaSamw #define	TX_SETATTR		11	/* Set file attributes */
156da6c28aaSamw #define	TX_ACL_V0		12	/* Set old formatted ACL */
157da6c28aaSamw #define	TX_ACL			13	/* Set ACL */
158da6c28aaSamw #define	TX_CREATE_ACL		14	/* create with ACL */
159da6c28aaSamw #define	TX_CREATE_ATTR		15	/* create + attrs */
160*54811da5SToomas Soome #define	TX_CREATE_ACL_ATTR	16	/* create with ACL + attrs */
161da6c28aaSamw #define	TX_MKDIR_ACL		17	/* mkdir with ACL */
162da6c28aaSamw #define	TX_MKDIR_ATTR		18	/* mkdir with attr */
163da6c28aaSamw #define	TX_MKDIR_ACL_ATTR	19	/* mkdir with ACL + attrs */
164975c32a0SNeil Perrin #define	TX_WRITE2		20	/* dmu_sync EALREADY write */
165975c32a0SNeil Perrin #define	TX_MAX_TYPE		21	/* Max transaction type */
166da6c28aaSamw 
167da6c28aaSamw /*
168da6c28aaSamw  * The transactions for mkdir, symlink, remove, rmdir, link, and rename
169da6c28aaSamw  * may have the following bit set, indicating the original request
170da6c28aaSamw  * specified case-insensitive handling of names.
171da6c28aaSamw  */
172da6c28aaSamw #define	TX_CI	((uint64_t)0x1 << 63) /* case-insensitive behavior requested */
173fa9e4066Sahrens 
174b24ab676SJeff Bonwick /*
175b24ab676SJeff Bonwick  * Transactions for write, truncate, setattr, acl_v0, and acl can be logged
176b24ab676SJeff Bonwick  * out of order.  For convenience in the code, all such records must have
177b24ab676SJeff Bonwick  * lr_foid at the same offset.
178b24ab676SJeff Bonwick  */
179b24ab676SJeff Bonwick #define	TX_OOO(txtype)			\
180b24ab676SJeff Bonwick 	((txtype) == TX_WRITE ||	\
181b24ab676SJeff Bonwick 	(txtype) == TX_TRUNCATE ||	\
182b24ab676SJeff Bonwick 	(txtype) == TX_SETATTR ||	\
183b24ab676SJeff Bonwick 	(txtype) == TX_ACL_V0 ||	\
184b24ab676SJeff Bonwick 	(txtype) == TX_ACL ||		\
185b24ab676SJeff Bonwick 	(txtype) == TX_WRITE2)
186b24ab676SJeff Bonwick 
187*54811da5SToomas Soome /*
188*54811da5SToomas Soome  * The number of dnode slots consumed by the object is stored in the 8
189*54811da5SToomas Soome  * unused upper bits of the object ID. We subtract 1 from the value
190*54811da5SToomas Soome  * stored on disk for compatibility with implementations that don't
191*54811da5SToomas Soome  * support large dnodes. The slot count for a single-slot dnode will
192*54811da5SToomas Soome  * contain 0 for those bits to preserve the log record format for
193*54811da5SToomas Soome  * "small" dnodes.
194*54811da5SToomas Soome  */
195*54811da5SToomas Soome #define	LR_FOID_GET_SLOTS(oid) (BF64_GET((oid), 56, 8) + 1)
196*54811da5SToomas Soome #define	LR_FOID_SET_SLOTS(oid, x) BF64_SET((oid), 56, 8, (x) - 1)
197*54811da5SToomas Soome #define	LR_FOID_GET_OBJ(oid) BF64_GET((oid), 0, DN_MAX_OBJECT_SHIFT)
198*54811da5SToomas Soome #define	LR_FOID_SET_OBJ(oid, x) BF64_SET((oid), 0, DN_MAX_OBJECT_SHIFT, (x))
199*54811da5SToomas Soome 
200fa9e4066Sahrens /*
201fa9e4066Sahrens  * Format of log records.
202fa9e4066Sahrens  * The fields are carefully defined to allow them to be aligned
203fa9e4066Sahrens  * and sized the same on sparc & intel architectures.
204fa9e4066Sahrens  * Each log record has a common structure at the beginning.
205b19a79ecSperrin  *
2065002558fSNeil Perrin  * The log record on disk (lrc_seq) holds the sequence number of all log
2075002558fSNeil Perrin  * records which is used to ensure we don't replay the same record.
208fa9e4066Sahrens  */
209fa9e4066Sahrens typedef struct {			/* common log record header */
210fa9e4066Sahrens 	uint64_t	lrc_txtype;	/* intent log transaction type */
211fa9e4066Sahrens 	uint64_t	lrc_reclen;	/* transaction record length */
212fa9e4066Sahrens 	uint64_t	lrc_txg;	/* dmu transaction group number */
213b19a79ecSperrin 	uint64_t	lrc_seq;	/* see comment above */
214fa9e4066Sahrens } lr_t;
215fa9e4066Sahrens 
216b24ab676SJeff Bonwick /*
217b24ab676SJeff Bonwick  * Common start of all out-of-order record types (TX_OOO() above).
218b24ab676SJeff Bonwick  */
219b24ab676SJeff Bonwick typedef struct {
220b24ab676SJeff Bonwick 	lr_t		lr_common;	/* common portion of log record */
221b24ab676SJeff Bonwick 	uint64_t	lr_foid;	/* object id */
222b24ab676SJeff Bonwick } lr_ooo_t;
223b24ab676SJeff Bonwick 
224da6c28aaSamw /*
225da6c28aaSamw  * Handle option extended vattr attributes.
226da6c28aaSamw  *
227da6c28aaSamw  * Whenever new attributes are added the version number
228da6c28aaSamw  * will need to be updated as will code in
229da6c28aaSamw  * zfs_log.c and zfs_replay.c
230da6c28aaSamw  */
231da6c28aaSamw typedef struct {
232da6c28aaSamw 	uint32_t	lr_attr_masksize; /* number of elements in array */
233da6c28aaSamw 	uint32_t	lr_attr_bitmap; /* First entry of array */
234da6c28aaSamw 	/* remainder of array and any additional fields */
235da6c28aaSamw } lr_attr_t;
236da6c28aaSamw 
237da6c28aaSamw /*
238da6c28aaSamw  * log record for creates without optional ACL.
239da6c28aaSamw  * This log record does support optional xvattr_t attributes.
240da6c28aaSamw  */
241fa9e4066Sahrens typedef struct {
242fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
243fa9e4066Sahrens 	uint64_t	lr_doid;	/* object id of directory */
244fa9e4066Sahrens 	uint64_t	lr_foid;	/* object id of created file object */
245fa9e4066Sahrens 	uint64_t	lr_mode;	/* mode of object */
246fa9e4066Sahrens 	uint64_t	lr_uid;		/* uid of object */
247fa9e4066Sahrens 	uint64_t	lr_gid;		/* gid of object */
248fa9e4066Sahrens 	uint64_t	lr_gen;		/* generation (txg of creation) */
249fa9e4066Sahrens 	uint64_t	lr_crtime[2];	/* creation time */
250fa9e4066Sahrens 	uint64_t	lr_rdev;	/* rdev of object to create */
251fa9e4066Sahrens 	/* name of object to create follows this */
252fa9e4066Sahrens 	/* for symlinks, link content follows name */
253da6c28aaSamw 	/* for creates with xvattr data, the name follows the xvattr info */
254fa9e4066Sahrens } lr_create_t;
255fa9e4066Sahrens 
256da6c28aaSamw /*
257da6c28aaSamw  * FUID ACL record will be an array of ACEs from the original ACL.
258da6c28aaSamw  * If this array includes ephemeral IDs, the record will also include
259da6c28aaSamw  * an array of log-specific FUIDs to replace the ephemeral IDs.
260da6c28aaSamw  * Only one copy of each unique domain will be present, so the log-specific
261da6c28aaSamw  * FUIDs will use an index into a compressed domain table.  On replay this
262da6c28aaSamw  * information will be used to construct real FUIDs (and bypass idmap,
263da6c28aaSamw  * since it may not be available).
264da6c28aaSamw  */
265da6c28aaSamw 
266da6c28aaSamw /*
267da6c28aaSamw  * Log record for creates with optional ACL
268da6c28aaSamw  * This log record is also used for recording any FUID
269da6c28aaSamw  * information needed for replaying the create.  If the
270da6c28aaSamw  * file doesn't have any actual ACEs then the lr_aclcnt
271da6c28aaSamw  * would be zero.
272f7170741SWill Andrews  *
273f7170741SWill Andrews  * After lr_acl_flags, there are a lr_acl_bytes number of variable sized ace's.
274f7170741SWill Andrews  * If create is also setting xvattr's, then acl data follows xvattr.
275f7170741SWill Andrews  * If ACE FUIDs are needed then they will follow the xvattr_t.  Following
276f7170741SWill Andrews  * the FUIDs will be the domain table information.  The FUIDs for the owner
277f7170741SWill Andrews  * and group will be in lr_create.  Name follows ACL data.
278da6c28aaSamw  */
279da6c28aaSamw typedef struct {
280da6c28aaSamw 	lr_create_t	lr_create;	/* common create portion */
281da6c28aaSamw 	uint64_t	lr_aclcnt;	/* number of ACEs in ACL */
282da6c28aaSamw 	uint64_t	lr_domcnt;	/* number of unique domains */
283da6c28aaSamw 	uint64_t	lr_fuidcnt;	/* number of real fuids */
284da6c28aaSamw 	uint64_t	lr_acl_bytes;	/* number of bytes in ACL */
285da6c28aaSamw 	uint64_t	lr_acl_flags;	/* ACL flags */
286da6c28aaSamw } lr_acl_create_t;
287da6c28aaSamw 
288fa9e4066Sahrens typedef struct {
289fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
290fa9e4066Sahrens 	uint64_t	lr_doid;	/* obj id of directory */
291fa9e4066Sahrens 	/* name of object to remove follows this */
292fa9e4066Sahrens } lr_remove_t;
293fa9e4066Sahrens 
294fa9e4066Sahrens typedef struct {
295fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
296fa9e4066Sahrens 	uint64_t	lr_doid;	/* obj id of directory */
297fa9e4066Sahrens 	uint64_t	lr_link_obj;	/* obj id of link */
298fa9e4066Sahrens 	/* name of object to link follows this */
299fa9e4066Sahrens } lr_link_t;
300fa9e4066Sahrens 
301fa9e4066Sahrens typedef struct {
302fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
303fa9e4066Sahrens 	uint64_t	lr_sdoid;	/* obj id of source directory */
304fa9e4066Sahrens 	uint64_t	lr_tdoid;	/* obj id of target directory */
305fa9e4066Sahrens 	/* 2 strings: names of source and destination follow this */
306fa9e4066Sahrens } lr_rename_t;
307fa9e4066Sahrens 
308fa9e4066Sahrens typedef struct {
309fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
310fa9e4066Sahrens 	uint64_t	lr_foid;	/* file object to write */
311fa9e4066Sahrens 	uint64_t	lr_offset;	/* offset to write to */
312fa9e4066Sahrens 	uint64_t	lr_length;	/* user data length to write */
313b24ab676SJeff Bonwick 	uint64_t	lr_blkoff;	/* no longer used */
314fa9e4066Sahrens 	blkptr_t	lr_blkptr;	/* spa block pointer for replay */
315fa9e4066Sahrens 	/* write data will follow for small writes */
316fa9e4066Sahrens } lr_write_t;
317fa9e4066Sahrens 
318fa9e4066Sahrens typedef struct {
319fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
320fa9e4066Sahrens 	uint64_t	lr_foid;	/* object id of file to truncate */
321fa9e4066Sahrens 	uint64_t	lr_offset;	/* offset to truncate from */
322fa9e4066Sahrens 	uint64_t	lr_length;	/* length to truncate */
323fa9e4066Sahrens } lr_truncate_t;
324fa9e4066Sahrens 
325fa9e4066Sahrens typedef struct {
326fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
327fa9e4066Sahrens 	uint64_t	lr_foid;	/* file object to change attributes */
328fa9e4066Sahrens 	uint64_t	lr_mask;	/* mask of attributes to set */
329fa9e4066Sahrens 	uint64_t	lr_mode;	/* mode to set */
330fa9e4066Sahrens 	uint64_t	lr_uid;		/* uid to set */
331fa9e4066Sahrens 	uint64_t	lr_gid;		/* gid to set */
332fa9e4066Sahrens 	uint64_t	lr_size;	/* size to set */
333fa9e4066Sahrens 	uint64_t	lr_atime[2];	/* access time */
334fa9e4066Sahrens 	uint64_t	lr_mtime[2];	/* modification time */
335da6c28aaSamw 	/* optional attribute lr_attr_t may be here */
336fa9e4066Sahrens } lr_setattr_t;
337fa9e4066Sahrens 
338fa9e4066Sahrens typedef struct {
339fa9e4066Sahrens 	lr_t		lr_common;	/* common portion of log record */
340fa9e4066Sahrens 	uint64_t	lr_foid;	/* obj id of file */
341fa9e4066Sahrens 	uint64_t	lr_aclcnt;	/* number of acl entries */
342fa9e4066Sahrens 	/* lr_aclcnt number of ace_t entries follow this */
343da6c28aaSamw } lr_acl_v0_t;
344da6c28aaSamw 
345da6c28aaSamw typedef struct {
346da6c28aaSamw 	lr_t		lr_common;	/* common portion of log record */
347da6c28aaSamw 	uint64_t	lr_foid;	/* obj id of file */
348da6c28aaSamw 	uint64_t	lr_aclcnt;	/* number of ACEs in ACL */
349da6c28aaSamw 	uint64_t	lr_domcnt;	/* number of unique domains */
350da6c28aaSamw 	uint64_t	lr_fuidcnt;	/* number of real fuids */
351da6c28aaSamw 	uint64_t	lr_acl_bytes;	/* number of bytes in ACL */
352da6c28aaSamw 	uint64_t	lr_acl_flags;	/* ACL flags */
353da6c28aaSamw 	/* lr_acl_bytes number of variable sized ace's follows */
354fa9e4066Sahrens } lr_acl_t;
355fa9e4066Sahrens 
356fa9e4066Sahrens /*
357fa9e4066Sahrens  * ZIL structure definitions, interface function prototype and globals.
358fa9e4066Sahrens  */
359fa9e4066Sahrens 
360fa9e4066Sahrens /*
361510b6c0eSNeil Perrin  * Writes are handled in three different ways:
362510b6c0eSNeil Perrin  *
363510b6c0eSNeil Perrin  * WR_INDIRECT:
364510b6c0eSNeil Perrin  *    In this mode, if we need to commit the write later, then the block
365510b6c0eSNeil Perrin  *    is immediately written into the file system (using dmu_sync),
366510b6c0eSNeil Perrin  *    and a pointer to the block is put into the log record.
367510b6c0eSNeil Perrin  *    When the txg commits the block is linked in.
368510b6c0eSNeil Perrin  *    This saves additionally writing the data into the log record.
369510b6c0eSNeil Perrin  *    There are a few requirements for this to occur:
370510b6c0eSNeil Perrin  *	- write is greater than zfs/zvol_immediate_write_sz
371510b6c0eSNeil Perrin  *	- not using slogs (as slogs are assumed to always be faster
372510b6c0eSNeil Perrin  *	  than writing into the main pool)
373510b6c0eSNeil Perrin  *	- the write occupies only one block
374510b6c0eSNeil Perrin  * WR_COPIED:
375510b6c0eSNeil Perrin  *    If we know we'll immediately be committing the
376510b6c0eSNeil Perrin  *    transaction (FSYNC or FDSYNC), the we allocate a larger
377510b6c0eSNeil Perrin  *    log record here for the data and copy the data in.
378510b6c0eSNeil Perrin  * WR_NEED_COPY:
379510b6c0eSNeil Perrin  *    Otherwise we don't allocate a buffer, and *if* we need to
380510b6c0eSNeil Perrin  *    flush the write later then a buffer is allocated and
381510b6c0eSNeil Perrin  *    we retrieve the data using the dmu.
382fa9e4066Sahrens  */
383104e2ed7Sperrin typedef enum {
384104e2ed7Sperrin 	WR_INDIRECT,	/* indirect - a large write (dmu_sync() data */
385104e2ed7Sperrin 			/* and put blkptr in log, rather than actual data) */
386104e2ed7Sperrin 	WR_COPIED,	/* immediate - data is copied into lr_write_t */
387104e2ed7Sperrin 	WR_NEED_COPY,	/* immediate - data needs to be copied if pushed */
388b24ab676SJeff Bonwick 	WR_NUM_STATES	/* number of states */
389104e2ed7Sperrin } itx_wr_state_t;
390104e2ed7Sperrin 
391fa9e4066Sahrens typedef struct itx {
392fa9e4066Sahrens 	list_node_t	itx_node;	/* linkage on zl_itx_list */
393fa9e4066Sahrens 	void		*itx_private;	/* type-specific opaque data */
394104e2ed7Sperrin 	itx_wr_state_t	itx_wr_state;	/* write state */
39567bd71c6Sperrin 	uint8_t		itx_sync;	/* synchronous transaction */
39651bd2f97SNeil Perrin 	uint64_t	itx_oid;	/* object id */
397fa9e4066Sahrens 	lr_t		itx_lr;		/* common part of log record */
398fa9e4066Sahrens 	/* followed by type-specific part of lr_xx_t and its immediate data */
399fa9e4066Sahrens } itx_t;
400fa9e4066Sahrens 
401b24ab676SJeff Bonwick typedef int zil_parse_blk_func_t(zilog_t *zilog, blkptr_t *bp, void *arg,
402fa9e4066Sahrens     uint64_t txg);
403b24ab676SJeff Bonwick typedef int zil_parse_lr_func_t(zilog_t *zilog, lr_t *lr, void *arg,
404fa9e4066Sahrens     uint64_t txg);
4053f7978d0SAlan Somers typedef int zil_replay_func_t(void *arg1, void *arg2, boolean_t byteswap);
4061271e4b1SPrakash Surya typedef int zil_get_data_t(void *arg, lr_write_t *lr, char *dbuf,
4071271e4b1SPrakash Surya     struct lwb *lwb, zio_t *zio);
408fa9e4066Sahrens 
409b24ab676SJeff Bonwick extern int zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
410fa9e4066Sahrens     zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg);
411fa9e4066Sahrens 
412fa9e4066Sahrens extern void	zil_init(void);
413fa9e4066Sahrens extern void	zil_fini(void);
414fa9e4066Sahrens 
415fa9e4066Sahrens extern zilog_t	*zil_alloc(objset_t *os, zil_header_t *zh_phys);
416fa9e4066Sahrens extern void	zil_free(zilog_t *zilog);
417fa9e4066Sahrens 
418fa9e4066Sahrens extern zilog_t	*zil_open(objset_t *os, zil_get_data_t *get_data);
419fa9e4066Sahrens extern void	zil_close(zilog_t *zilog);
420fa9e4066Sahrens 
4211209a471SNeil Perrin extern void	zil_replay(objset_t *os, void *arg,
4221209a471SNeil Perrin     zil_replay_func_t *replay_func[TX_MAX_TYPE]);
423b24ab676SJeff Bonwick extern boolean_t zil_replaying(zilog_t *zilog, dmu_tx_t *tx);
424d80c45e0Sbonwick extern void	zil_destroy(zilog_t *zilog, boolean_t keep_first);
425ce636f8bSMatthew Ahrens extern void	zil_destroy_sync(zilog_t *zilog, dmu_tx_t *tx);
4263a8a1de4Sperrin extern void	zil_rollback_destroy(zilog_t *zilog, dmu_tx_t *tx);
427fa9e4066Sahrens 
428da6c28aaSamw extern itx_t	*zil_itx_create(uint64_t txtype, size_t lrsize);
429b24ab676SJeff Bonwick extern void	zil_itx_destroy(itx_t *itx);
4305002558fSNeil Perrin extern void	zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx);
431fa9e4066Sahrens 
4325002558fSNeil Perrin extern void	zil_commit(zilog_t *zilog, uint64_t oid);
43394ddd090SPrakash Surya extern void	zil_commit_impl(zilog_t *zilog, uint64_t oid);
434fa9e4066Sahrens 
4355cabbc6bSPrashanth Sreenivasa extern int	zil_reset(const char *osname, void *txarg);
43612380e1eSArne Jansen extern int	zil_claim(struct dsl_pool *dp,
43712380e1eSArne Jansen     struct dsl_dataset *ds, void *txarg);
438*54811da5SToomas Soome extern int	zil_check_log_chain(struct dsl_pool *dp,
43912380e1eSArne Jansen     struct dsl_dataset *ds, void *tx);
440fa9e4066Sahrens extern void	zil_sync(zilog_t *zilog, dmu_tx_t *tx);
4415002558fSNeil Perrin extern void	zil_clean(zilog_t *zilog, uint64_t synced_txg);
442fa9e4066Sahrens 
4433b2aab18SMatthew Ahrens extern int	zil_suspend(const char *osname, void **cookiep);
4443b2aab18SMatthew Ahrens extern void	zil_resume(void *cookie);
445fa9e4066Sahrens 
4461271e4b1SPrakash Surya extern void	zil_lwb_add_block(struct lwb *lwb, const blkptr_t *bp);
4471271e4b1SPrakash Surya extern void	zil_lwb_add_txg(struct lwb *lwb, uint64_t txg);
448b24ab676SJeff Bonwick extern int	zil_bp_tree_add(zilog_t *zilog, const blkptr_t *bp);
449b24ab676SJeff Bonwick 
45055da60b9SMark J Musante extern void	zil_set_sync(zilog_t *zilog, uint64_t syncval);
45155da60b9SMark J Musante 
452e09fa4daSNeil Perrin extern void	zil_set_logbias(zilog_t *zilog, uint64_t slogval);
453e09fa4daSNeil Perrin 
45455da60b9SMark J Musante extern int zil_replay_disable;
455fa9e4066Sahrens 
456fa9e4066Sahrens #ifdef	__cplusplus
457fa9e4066Sahrens }
458fa9e4066Sahrens #endif
459fa9e4066Sahrens 
460fa9e4066Sahrens #endif	/* _SYS_ZIL_H */
461