xref: /titanic_44/usr/src/uts/common/fs/zfs/sys/zil.h (revision 6927f468b0af7710df000f6b16f6ee413e1e3007)
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_H
28 #define	_SYS_ZIL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/spa.h>
34 #include <sys/zio.h>
35 #include <sys/dmu.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * Intent log format:
43  *
44  * Each objset has its own intent log.  The log header (zil_header_t)
45  * for objset N's intent log is kept in the Nth object of the SPA's
46  * intent_log objset.  The log header points to a chain of log blocks,
47  * each of which contains log records (i.e., transactions) followed by
48  * a log block trailer (zil_trailer_t).  The format of a log record
49  * depends on the record (or transaction) type, but all records begin
50  * with a common structure that defines the type, length, and txg.
51  */
52 
53 /*
54  * Intent log header - this on disk structure holds fields to manage
55  * the log.  All fields are 64 bit to easily handle cross architectures.
56  */
57 typedef struct zil_header {
58 	uint64_t zh_claim_txg;	/* txg in which log blocks were claimed */
59 	uint64_t zh_replay_seq;	/* highest replayed sequence number */
60 	blkptr_t zh_log;	/* log chain */
61 	uint64_t zit_pad[6];
62 } zil_header_t;
63 
64 /*
65  * Log block trailer - structure at the end of the header and each log block
66  *
67  * The zit_bt contains a zbt_cksum which for the intent log is
68  * the sequence number of this log block. A seq of 0 is invalid.
69  * The zbt_cksum is checked by the SPA against the sequence
70  * number passed in the blk_cksum field of the blkptr_t
71  */
72 typedef struct zil_trailer {
73 	uint64_t zit_pad;
74 	blkptr_t zit_next_blk;	/* next block in chain */
75 	uint64_t zit_nused;	/* bytes in log block used */
76 	zio_block_tail_t zit_bt; /* block trailer */
77 } zil_trailer_t;
78 
79 #define	ZIL_MIN_BLKSZ	4096
80 #define	ZIL_MAX_BLKSZ	SPA_MAXBLOCKSIZE
81 #define	ZIL_BLK_DATA_SZ(lwb)	((lwb)->lwb_sz - sizeof (zil_trailer_t))
82 
83 /*
84  * Intent log transaction types and record structures
85  */
86 #define	TX_CREATE	1		/* Create file */
87 #define	TX_MKDIR	2		/* Make directory */
88 #define	TX_MKXATTR	3		/* Make XATTR directory */
89 #define	TX_SYMLINK	4		/* Create symbolic link to a file */
90 #define	TX_REMOVE	5		/* Remove file */
91 #define	TX_RMDIR	6		/* Remove directory */
92 #define	TX_LINK		7		/* Create hard link to a file */
93 #define	TX_RENAME	8		/* Rename a file */
94 #define	TX_WRITE	9		/* File write */
95 #define	TX_TRUNCATE	10		/* Truncate a file */
96 #define	TX_SETATTR	11		/* Set file attributes */
97 #define	TX_ACL		12		/* Set acl */
98 #define	TX_MAX_TYPE	13		/* Max transaction type */
99 
100 /*
101  * Format of log records.
102  * The fields are carefully defined to allow them to be aligned
103  * and sized the same on sparc & intel architectures.
104  * Each log record has a common structure at the beginning.
105  */
106 typedef struct {			/* common log record header */
107 	uint64_t	lrc_txtype;	/* intent log transaction type */
108 	uint64_t	lrc_reclen;	/* transaction record length */
109 	uint64_t	lrc_txg;	/* dmu transaction group number */
110 	uint64_t	lrc_seq;	/* intent log sequence number */
111 } lr_t;
112 
113 typedef struct {
114 	lr_t		lr_common;	/* common portion of log record */
115 	uint64_t	lr_doid;	/* object id of directory */
116 	uint64_t	lr_foid;	/* object id of created file object */
117 	uint64_t	lr_mode;	/* mode of object */
118 	uint64_t	lr_uid;		/* uid of object */
119 	uint64_t	lr_gid;		/* gid of object */
120 	uint64_t	lr_gen;		/* generation (txg of creation) */
121 	uint64_t	lr_crtime[2];	/* creation time */
122 	uint64_t	lr_rdev;	/* rdev of object to create */
123 	/* name of object to create follows this */
124 	/* for symlinks, link content follows name */
125 } lr_create_t;
126 
127 typedef struct {
128 	lr_t		lr_common;	/* common portion of log record */
129 	uint64_t	lr_doid;	/* obj id of directory */
130 	/* name of object to remove follows this */
131 } lr_remove_t;
132 
133 typedef struct {
134 	lr_t		lr_common;	/* common portion of log record */
135 	uint64_t	lr_doid;	/* obj id of directory */
136 	uint64_t	lr_link_obj;	/* obj id of link */
137 	/* name of object to link follows this */
138 } lr_link_t;
139 
140 typedef struct {
141 	lr_t		lr_common;	/* common portion of log record */
142 	uint64_t	lr_sdoid;	/* obj id of source directory */
143 	uint64_t	lr_tdoid;	/* obj id of target directory */
144 	/* 2 strings: names of source and destination follow this */
145 } lr_rename_t;
146 
147 typedef struct {
148 	lr_t		lr_common;	/* common portion of log record */
149 	uint64_t	lr_foid;	/* file object to write */
150 	uint64_t	lr_offset;	/* offset to write to */
151 	uint64_t	lr_length;	/* user data length to write */
152 	uint64_t	lr_blkoff;	/* offset represented by lr_blkptr */
153 	blkptr_t	lr_blkptr;	/* spa block pointer for replay */
154 	/* write data will follow for small writes */
155 } lr_write_t;
156 
157 typedef struct {
158 	lr_t		lr_common;	/* common portion of log record */
159 	uint64_t	lr_foid;	/* object id of file to truncate */
160 	uint64_t	lr_offset;	/* offset to truncate from */
161 	uint64_t	lr_length;	/* length to truncate */
162 } lr_truncate_t;
163 
164 typedef struct {
165 	lr_t		lr_common;	/* common portion of log record */
166 	uint64_t	lr_foid;	/* file object to change attributes */
167 	uint64_t	lr_mask;	/* mask of attributes to set */
168 	uint64_t	lr_mode;	/* mode to set */
169 	uint64_t	lr_uid;		/* uid to set */
170 	uint64_t	lr_gid;		/* gid to set */
171 	uint64_t	lr_size;	/* size to set */
172 	uint64_t	lr_atime[2];	/* access time */
173 	uint64_t	lr_mtime[2];	/* modification time */
174 } lr_setattr_t;
175 
176 typedef struct {
177 	lr_t		lr_common;	/* common portion of log record */
178 	uint64_t	lr_foid;	/* obj id of file */
179 	uint64_t	lr_aclcnt;	/* number of acl entries */
180 	/* lr_aclcnt number of ace_t entries follow this */
181 } lr_acl_t;
182 
183 /*
184  * ZIL structure definitions, interface function prototype and globals.
185  */
186 
187 /*
188  * ZFS intent log transaction structure
189  */
190 typedef struct itx {
191 	list_node_t	itx_node;	/* linkage on zl_itx_list */
192 	void		*itx_private;	/* type-specific opaque data */
193 	uint8_t		itx_data_copied; /* TX_WRITE only: write data already */
194 					/* copied into itx data buffer */
195 	lr_t		itx_lr;		/* common part of log record */
196 	/* followed by type-specific part of lr_xx_t and its immediate data */
197 } itx_t;
198 
199 typedef void zil_parse_blk_func_t(zilog_t *zilog, blkptr_t *bp, void *arg,
200     uint64_t txg);
201 typedef void zil_parse_lr_func_t(zilog_t *zilog, lr_t *lr, void *arg,
202     uint64_t txg);
203 typedef int zil_replay_func_t();
204 typedef int zil_get_data_t(void *arg, lr_write_t *lr);
205 
206 extern void	zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
207     zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg);
208 
209 extern void	zil_init(void);
210 extern void	zil_fini(void);
211 
212 extern zilog_t	*zil_alloc(objset_t *os, zil_header_t *zh_phys);
213 extern void	zil_free(zilog_t *zilog);
214 
215 extern zilog_t	*zil_open(objset_t *os, zil_get_data_t *get_data);
216 extern void	zil_close(zilog_t *zilog);
217 
218 extern void	zil_replay(objset_t *os, void *arg, uint64_t *txgp,
219     zil_replay_func_t *replay_func[TX_MAX_TYPE], void (*rm_wait)(void *));
220 extern void	zil_destroy(zilog_t *zilog);
221 
222 extern itx_t	*zil_itx_create(int txtype, size_t lrsize);
223 extern uint64_t zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx);
224 
225 extern void	zil_commit(zilog_t *zilog, uint64_t seq, int ioflag);
226 
227 extern void	zil_claim(char *osname, void *txarg);
228 extern void	zil_sync(zilog_t *zilog, dmu_tx_t *tx);
229 extern void	zil_clean(zilog_t *zilog);
230 
231 extern int	zil_suspend(zilog_t *zilog);
232 extern void	zil_resume(zilog_t *zilog);
233 
234 extern int zil_disable;
235 extern int zil_always;
236 extern int zil_purge;
237 
238 #ifdef	__cplusplus
239 }
240 #endif
241 
242 #endif	/* _SYS_ZIL_H */
243