Print this page
3742 zfs comments need cleaner, more consistent style
Submitted by: Will Andrews <willa@spectralogic.com>
Submitted by: Alan Somers <alans@spectralogic.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/zil.h
+++ new/usr/src/uts/common/fs/zfs/sys/zil.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 */
25 25
26 26 /* Portions Copyright 2010 Robert Milkowski */
27 27
28 28 #ifndef _SYS_ZIL_H
29 29 #define _SYS_ZIL_H
30 30
31 31 #include <sys/types.h>
32 32 #include <sys/spa.h>
33 33 #include <sys/zio.h>
34 34 #include <sys/dmu.h>
35 35
36 36 #ifdef __cplusplus
37 37 extern "C" {
38 38 #endif
39 39
40 40 /*
41 41 * Intent log format:
42 42 *
43 43 * Each objset has its own intent log. The log header (zil_header_t)
44 44 * for objset N's intent log is kept in the Nth object of the SPA's
45 45 * intent_log objset. The log header points to a chain of log blocks,
46 46 * each of which contains log records (i.e., transactions) followed by
47 47 * a log block trailer (zil_trailer_t). The format of a log record
48 48 * depends on the record (or transaction) type, but all records begin
49 49 * with a common structure that defines the type, length, and txg.
50 50 */
51 51
52 52 /*
53 53 * Intent log header - this on disk structure holds fields to manage
54 54 * the log. All fields are 64 bit to easily handle cross architectures.
55 55 */
56 56 typedef struct zil_header {
57 57 uint64_t zh_claim_txg; /* txg in which log blocks were claimed */
58 58 uint64_t zh_replay_seq; /* highest replayed sequence number */
59 59 blkptr_t zh_log; /* log chain */
60 60 uint64_t zh_claim_blk_seq; /* highest claimed block sequence number */
61 61 uint64_t zh_flags; /* header flags */
62 62 uint64_t zh_claim_lr_seq; /* highest claimed lr sequence number */
63 63 uint64_t zh_pad[3];
64 64 } zil_header_t;
65 65
66 66 /*
67 67 * zh_flags bit settings
68 68 */
69 69 #define ZIL_REPLAY_NEEDED 0x1 /* replay needed - internal only */
70 70 #define ZIL_CLAIM_LR_SEQ_VALID 0x2 /* zh_claim_lr_seq field is valid */
71 71
72 72 /*
73 73 * Log block chaining.
74 74 *
75 75 * Log blocks are chained together. Originally they were chained at the
76 76 * end of the block. For performance reasons the chain was moved to the
77 77 * beginning of the block which allows writes for only the data being used.
78 78 * The older position is supported for backwards compatability.
79 79 *
80 80 * The zio_eck_t contains a zec_cksum which for the intent log is
81 81 * the sequence number of this log block. A seq of 0 is invalid.
82 82 * The zec_cksum is checked by the SPA against the sequence
83 83 * number passed in the blk_cksum field of the blkptr_t
84 84 */
85 85 typedef struct zil_chain {
86 86 uint64_t zc_pad;
87 87 blkptr_t zc_next_blk; /* next block in chain */
88 88 uint64_t zc_nused; /* bytes in log block used */
89 89 zio_eck_t zc_eck; /* block trailer */
90 90 } zil_chain_t;
91 91
92 92 #define ZIL_MIN_BLKSZ 4096ULL
93 93 #define ZIL_MAX_BLKSZ SPA_MAXBLOCKSIZE
94 94
95 95 /*
96 96 * The words of a log block checksum.
97 97 */
98 98 #define ZIL_ZC_GUID_0 0
99 99 #define ZIL_ZC_GUID_1 1
100 100 #define ZIL_ZC_OBJSET 2
101 101 #define ZIL_ZC_SEQ 3
102 102
103 103 typedef enum zil_create {
104 104 Z_FILE,
105 105 Z_DIR,
106 106 Z_XATTRDIR,
107 107 } zil_create_t;
108 108
109 109 /*
110 110 * size of xvattr log section.
111 111 * its composed of lr_attr_t + xvattr bitmap + 2 64 bit timestamps
112 112 * for create time and a single 64 bit integer for all of the attributes,
113 113 * and 4 64 bit integers (32 bytes) for the scanstamp.
114 114 *
115 115 */
116 116
117 117 #define ZIL_XVAT_SIZE(mapsize) \
118 118 sizeof (lr_attr_t) + (sizeof (uint32_t) * (mapsize - 1)) + \
119 119 (sizeof (uint64_t) * 7)
120 120
121 121 /*
122 122 * Size of ACL in log. The ACE data is padded out to properly align
123 123 * on 8 byte boundary.
124 124 */
125 125
126 126 #define ZIL_ACE_LENGTH(x) (roundup(x, sizeof (uint64_t)))
127 127
128 128 /*
129 129 * Intent log transaction types and record structures
130 130 */
131 131 #define TX_CREATE 1 /* Create file */
132 132 #define TX_MKDIR 2 /* Make directory */
133 133 #define TX_MKXATTR 3 /* Make XATTR directory */
134 134 #define TX_SYMLINK 4 /* Create symbolic link to a file */
135 135 #define TX_REMOVE 5 /* Remove file */
136 136 #define TX_RMDIR 6 /* Remove directory */
137 137 #define TX_LINK 7 /* Create hard link to a file */
138 138 #define TX_RENAME 8 /* Rename a file */
139 139 #define TX_WRITE 9 /* File write */
140 140 #define TX_TRUNCATE 10 /* Truncate a file */
141 141 #define TX_SETATTR 11 /* Set file attributes */
142 142 #define TX_ACL_V0 12 /* Set old formatted ACL */
143 143 #define TX_ACL 13 /* Set ACL */
144 144 #define TX_CREATE_ACL 14 /* create with ACL */
145 145 #define TX_CREATE_ATTR 15 /* create + attrs */
146 146 #define TX_CREATE_ACL_ATTR 16 /* create with ACL + attrs */
147 147 #define TX_MKDIR_ACL 17 /* mkdir with ACL */
148 148 #define TX_MKDIR_ATTR 18 /* mkdir with attr */
149 149 #define TX_MKDIR_ACL_ATTR 19 /* mkdir with ACL + attrs */
150 150 #define TX_WRITE2 20 /* dmu_sync EALREADY write */
151 151 #define TX_MAX_TYPE 21 /* Max transaction type */
152 152
153 153 /*
154 154 * The transactions for mkdir, symlink, remove, rmdir, link, and rename
155 155 * may have the following bit set, indicating the original request
156 156 * specified case-insensitive handling of names.
157 157 */
158 158 #define TX_CI ((uint64_t)0x1 << 63) /* case-insensitive behavior requested */
159 159
160 160 /*
161 161 * Transactions for write, truncate, setattr, acl_v0, and acl can be logged
162 162 * out of order. For convenience in the code, all such records must have
163 163 * lr_foid at the same offset.
164 164 */
165 165 #define TX_OOO(txtype) \
166 166 ((txtype) == TX_WRITE || \
167 167 (txtype) == TX_TRUNCATE || \
168 168 (txtype) == TX_SETATTR || \
169 169 (txtype) == TX_ACL_V0 || \
170 170 (txtype) == TX_ACL || \
171 171 (txtype) == TX_WRITE2)
172 172
173 173 /*
174 174 * Format of log records.
175 175 * The fields are carefully defined to allow them to be aligned
176 176 * and sized the same on sparc & intel architectures.
177 177 * Each log record has a common structure at the beginning.
178 178 *
179 179 * The log record on disk (lrc_seq) holds the sequence number of all log
180 180 * records which is used to ensure we don't replay the same record.
181 181 */
182 182 typedef struct { /* common log record header */
183 183 uint64_t lrc_txtype; /* intent log transaction type */
184 184 uint64_t lrc_reclen; /* transaction record length */
185 185 uint64_t lrc_txg; /* dmu transaction group number */
186 186 uint64_t lrc_seq; /* see comment above */
187 187 } lr_t;
188 188
189 189 /*
190 190 * Common start of all out-of-order record types (TX_OOO() above).
191 191 */
192 192 typedef struct {
193 193 lr_t lr_common; /* common portion of log record */
194 194 uint64_t lr_foid; /* object id */
195 195 } lr_ooo_t;
196 196
197 197 /*
198 198 * Handle option extended vattr attributes.
199 199 *
200 200 * Whenever new attributes are added the version number
201 201 * will need to be updated as will code in
202 202 * zfs_log.c and zfs_replay.c
203 203 */
204 204 typedef struct {
205 205 uint32_t lr_attr_masksize; /* number of elements in array */
206 206 uint32_t lr_attr_bitmap; /* First entry of array */
207 207 /* remainder of array and any additional fields */
208 208 } lr_attr_t;
209 209
210 210 /*
211 211 * log record for creates without optional ACL.
212 212 * This log record does support optional xvattr_t attributes.
213 213 */
214 214 typedef struct {
215 215 lr_t lr_common; /* common portion of log record */
216 216 uint64_t lr_doid; /* object id of directory */
217 217 uint64_t lr_foid; /* object id of created file object */
218 218 uint64_t lr_mode; /* mode of object */
219 219 uint64_t lr_uid; /* uid of object */
220 220 uint64_t lr_gid; /* gid of object */
221 221 uint64_t lr_gen; /* generation (txg of creation) */
222 222 uint64_t lr_crtime[2]; /* creation time */
223 223 uint64_t lr_rdev; /* rdev of object to create */
224 224 /* name of object to create follows this */
225 225 /* for symlinks, link content follows name */
226 226 /* for creates with xvattr data, the name follows the xvattr info */
227 227 } lr_create_t;
228 228
229 229 /*
230 230 * FUID ACL record will be an array of ACEs from the original ACL.
231 231 * If this array includes ephemeral IDs, the record will also include
232 232 * an array of log-specific FUIDs to replace the ephemeral IDs.
233 233 * Only one copy of each unique domain will be present, so the log-specific
234 234 * FUIDs will use an index into a compressed domain table. On replay this
↓ open down ↓ |
234 lines elided |
↑ open up ↑ |
235 235 * information will be used to construct real FUIDs (and bypass idmap,
236 236 * since it may not be available).
237 237 */
238 238
239 239 /*
240 240 * Log record for creates with optional ACL
241 241 * This log record is also used for recording any FUID
242 242 * information needed for replaying the create. If the
243 243 * file doesn't have any actual ACEs then the lr_aclcnt
244 244 * would be zero.
245 + *
246 + * After lr_acl_flags, there are a lr_acl_bytes number of variable sized ace's.
247 + * If create is also setting xvattr's, then acl data follows xvattr.
248 + * If ACE FUIDs are needed then they will follow the xvattr_t. Following
249 + * the FUIDs will be the domain table information. The FUIDs for the owner
250 + * and group will be in lr_create. Name follows ACL data.
245 251 */
246 252 typedef struct {
247 253 lr_create_t lr_create; /* common create portion */
248 254 uint64_t lr_aclcnt; /* number of ACEs in ACL */
249 255 uint64_t lr_domcnt; /* number of unique domains */
250 256 uint64_t lr_fuidcnt; /* number of real fuids */
251 257 uint64_t lr_acl_bytes; /* number of bytes in ACL */
252 258 uint64_t lr_acl_flags; /* ACL flags */
253 - /* lr_acl_bytes number of variable sized ace's follows */
254 - /* if create is also setting xvattr's, then acl data follows xvattr */
255 - /* if ACE FUIDs are needed then they will follow the xvattr_t */
256 - /* Following the FUIDs will be the domain table information. */
257 - /* The FUIDs for the owner and group will be in the lr_create */
258 - /* portion of the record. */
259 - /* name follows ACL data */
260 259 } lr_acl_create_t;
261 260
262 261 typedef struct {
263 262 lr_t lr_common; /* common portion of log record */
264 263 uint64_t lr_doid; /* obj id of directory */
265 264 /* name of object to remove follows this */
266 265 } lr_remove_t;
267 266
268 267 typedef struct {
269 268 lr_t lr_common; /* common portion of log record */
270 269 uint64_t lr_doid; /* obj id of directory */
271 270 uint64_t lr_link_obj; /* obj id of link */
272 271 /* name of object to link follows this */
273 272 } lr_link_t;
274 273
275 274 typedef struct {
276 275 lr_t lr_common; /* common portion of log record */
277 276 uint64_t lr_sdoid; /* obj id of source directory */
278 277 uint64_t lr_tdoid; /* obj id of target directory */
279 278 /* 2 strings: names of source and destination follow this */
280 279 } lr_rename_t;
281 280
282 281 typedef struct {
283 282 lr_t lr_common; /* common portion of log record */
284 283 uint64_t lr_foid; /* file object to write */
285 284 uint64_t lr_offset; /* offset to write to */
286 285 uint64_t lr_length; /* user data length to write */
287 286 uint64_t lr_blkoff; /* no longer used */
288 287 blkptr_t lr_blkptr; /* spa block pointer for replay */
289 288 /* write data will follow for small writes */
290 289 } lr_write_t;
291 290
292 291 typedef struct {
293 292 lr_t lr_common; /* common portion of log record */
294 293 uint64_t lr_foid; /* object id of file to truncate */
295 294 uint64_t lr_offset; /* offset to truncate from */
296 295 uint64_t lr_length; /* length to truncate */
297 296 } lr_truncate_t;
298 297
299 298 typedef struct {
300 299 lr_t lr_common; /* common portion of log record */
301 300 uint64_t lr_foid; /* file object to change attributes */
302 301 uint64_t lr_mask; /* mask of attributes to set */
303 302 uint64_t lr_mode; /* mode to set */
304 303 uint64_t lr_uid; /* uid to set */
305 304 uint64_t lr_gid; /* gid to set */
306 305 uint64_t lr_size; /* size to set */
307 306 uint64_t lr_atime[2]; /* access time */
308 307 uint64_t lr_mtime[2]; /* modification time */
309 308 /* optional attribute lr_attr_t may be here */
310 309 } lr_setattr_t;
311 310
312 311 typedef struct {
313 312 lr_t lr_common; /* common portion of log record */
314 313 uint64_t lr_foid; /* obj id of file */
315 314 uint64_t lr_aclcnt; /* number of acl entries */
316 315 /* lr_aclcnt number of ace_t entries follow this */
317 316 } lr_acl_v0_t;
318 317
319 318 typedef struct {
320 319 lr_t lr_common; /* common portion of log record */
321 320 uint64_t lr_foid; /* obj id of file */
322 321 uint64_t lr_aclcnt; /* number of ACEs in ACL */
323 322 uint64_t lr_domcnt; /* number of unique domains */
324 323 uint64_t lr_fuidcnt; /* number of real fuids */
325 324 uint64_t lr_acl_bytes; /* number of bytes in ACL */
326 325 uint64_t lr_acl_flags; /* ACL flags */
327 326 /* lr_acl_bytes number of variable sized ace's follows */
328 327 } lr_acl_t;
329 328
330 329 /*
331 330 * ZIL structure definitions, interface function prototype and globals.
332 331 */
333 332
334 333 /*
335 334 * Writes are handled in three different ways:
336 335 *
337 336 * WR_INDIRECT:
338 337 * In this mode, if we need to commit the write later, then the block
339 338 * is immediately written into the file system (using dmu_sync),
340 339 * and a pointer to the block is put into the log record.
341 340 * When the txg commits the block is linked in.
342 341 * This saves additionally writing the data into the log record.
343 342 * There are a few requirements for this to occur:
344 343 * - write is greater than zfs/zvol_immediate_write_sz
345 344 * - not using slogs (as slogs are assumed to always be faster
346 345 * than writing into the main pool)
347 346 * - the write occupies only one block
348 347 * WR_COPIED:
349 348 * If we know we'll immediately be committing the
350 349 * transaction (FSYNC or FDSYNC), the we allocate a larger
351 350 * log record here for the data and copy the data in.
352 351 * WR_NEED_COPY:
353 352 * Otherwise we don't allocate a buffer, and *if* we need to
354 353 * flush the write later then a buffer is allocated and
355 354 * we retrieve the data using the dmu.
356 355 */
357 356 typedef enum {
358 357 WR_INDIRECT, /* indirect - a large write (dmu_sync() data */
359 358 /* and put blkptr in log, rather than actual data) */
360 359 WR_COPIED, /* immediate - data is copied into lr_write_t */
361 360 WR_NEED_COPY, /* immediate - data needs to be copied if pushed */
362 361 WR_NUM_STATES /* number of states */
363 362 } itx_wr_state_t;
364 363
365 364 typedef struct itx {
366 365 list_node_t itx_node; /* linkage on zl_itx_list */
367 366 void *itx_private; /* type-specific opaque data */
368 367 itx_wr_state_t itx_wr_state; /* write state */
369 368 uint8_t itx_sync; /* synchronous transaction */
370 369 uint64_t itx_sod; /* record size on disk */
371 370 uint64_t itx_oid; /* object id */
372 371 lr_t itx_lr; /* common part of log record */
373 372 /* followed by type-specific part of lr_xx_t and its immediate data */
374 373 } itx_t;
375 374
376 375 typedef int zil_parse_blk_func_t(zilog_t *zilog, blkptr_t *bp, void *arg,
377 376 uint64_t txg);
378 377 typedef int zil_parse_lr_func_t(zilog_t *zilog, lr_t *lr, void *arg,
379 378 uint64_t txg);
380 379 typedef int zil_replay_func_t();
381 380 typedef int zil_get_data_t(void *arg, lr_write_t *lr, char *dbuf, zio_t *zio);
382 381
383 382 extern int zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
384 383 zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg);
385 384
386 385 extern void zil_init(void);
387 386 extern void zil_fini(void);
388 387
389 388 extern zilog_t *zil_alloc(objset_t *os, zil_header_t *zh_phys);
390 389 extern void zil_free(zilog_t *zilog);
391 390
392 391 extern zilog_t *zil_open(objset_t *os, zil_get_data_t *get_data);
393 392 extern void zil_close(zilog_t *zilog);
394 393
395 394 extern void zil_replay(objset_t *os, void *arg,
396 395 zil_replay_func_t *replay_func[TX_MAX_TYPE]);
397 396 extern boolean_t zil_replaying(zilog_t *zilog, dmu_tx_t *tx);
398 397 extern void zil_destroy(zilog_t *zilog, boolean_t keep_first);
399 398 extern void zil_destroy_sync(zilog_t *zilog, dmu_tx_t *tx);
400 399 extern void zil_rollback_destroy(zilog_t *zilog, dmu_tx_t *tx);
401 400
402 401 extern itx_t *zil_itx_create(uint64_t txtype, size_t lrsize);
403 402 extern void zil_itx_destroy(itx_t *itx);
404 403 extern void zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx);
405 404
406 405 extern void zil_commit(zilog_t *zilog, uint64_t oid);
407 406
408 407 extern int zil_vdev_offline(const char *osname, void *txarg);
409 408 extern int zil_claim(const char *osname, void *txarg);
410 409 extern int zil_check_log_chain(const char *osname, void *txarg);
411 410 extern void zil_sync(zilog_t *zilog, dmu_tx_t *tx);
412 411 extern void zil_clean(zilog_t *zilog, uint64_t synced_txg);
413 412
414 413 extern int zil_suspend(const char *osname, void **cookiep);
415 414 extern void zil_resume(void *cookie);
416 415
417 416 extern void zil_add_block(zilog_t *zilog, const blkptr_t *bp);
418 417 extern int zil_bp_tree_add(zilog_t *zilog, const blkptr_t *bp);
419 418
420 419 extern void zil_set_sync(zilog_t *zilog, uint64_t syncval);
421 420
422 421 extern void zil_set_logbias(zilog_t *zilog, uint64_t slogval);
423 422
424 423 extern int zil_replay_disable;
425 424
426 425 #ifdef __cplusplus
427 426 }
428 427 #endif
429 428
430 429 #endif /* _SYS_ZIL_H */
↓ open down ↓ |
161 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX