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 /* 22893a6d32Sahrens * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23fa9e4066Sahrens * Use is subject to license terms. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #ifndef _SYS_ZIL_H 27fa9e4066Sahrens #define _SYS_ZIL_H 28fa9e4066Sahrens 29fa9e4066Sahrens #pragma ident "%Z%%M% %I% %E% SMI" 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 40fa9e4066Sahrens /* 41fa9e4066Sahrens * Intent log format: 42fa9e4066Sahrens * 43fa9e4066Sahrens * Each objset has its own intent log. The log header (zil_header_t) 44fa9e4066Sahrens * for objset N's intent log is kept in the Nth object of the SPA's 45fa9e4066Sahrens * intent_log objset. The log header points to a chain of log blocks, 46fa9e4066Sahrens * each of which contains log records (i.e., transactions) followed by 47fa9e4066Sahrens * a log block trailer (zil_trailer_t). The format of a log record 48fa9e4066Sahrens * depends on the record (or transaction) type, but all records begin 49fa9e4066Sahrens * with a common structure that defines the type, length, and txg. 50fa9e4066Sahrens */ 51fa9e4066Sahrens 52fa9e4066Sahrens /* 53fa9e4066Sahrens * Intent log header - this on disk structure holds fields to manage 54fa9e4066Sahrens * the log. All fields are 64 bit to easily handle cross architectures. 55fa9e4066Sahrens */ 56fa9e4066Sahrens typedef struct zil_header { 57fa9e4066Sahrens uint64_t zh_claim_txg; /* txg in which log blocks were claimed */ 58fa9e4066Sahrens uint64_t zh_replay_seq; /* highest replayed sequence number */ 59fa9e4066Sahrens blkptr_t zh_log; /* log chain */ 60d80c45e0Sbonwick uint64_t zh_claim_seq; /* highest claimed sequence number */ 61d80c45e0Sbonwick uint64_t zh_pad[5]; 62fa9e4066Sahrens } zil_header_t; 63fa9e4066Sahrens 64fa9e4066Sahrens /* 65fa9e4066Sahrens * Log block trailer - structure at the end of the header and each log block 66fa9e4066Sahrens * 67fa9e4066Sahrens * The zit_bt contains a zbt_cksum which for the intent log is 68fa9e4066Sahrens * the sequence number of this log block. A seq of 0 is invalid. 69fa9e4066Sahrens * The zbt_cksum is checked by the SPA against the sequence 70fa9e4066Sahrens * number passed in the blk_cksum field of the blkptr_t 71fa9e4066Sahrens */ 72fa9e4066Sahrens typedef struct zil_trailer { 73fa9e4066Sahrens uint64_t zit_pad; 74fa9e4066Sahrens blkptr_t zit_next_blk; /* next block in chain */ 75fa9e4066Sahrens uint64_t zit_nused; /* bytes in log block used */ 76fa9e4066Sahrens zio_block_tail_t zit_bt; /* block trailer */ 77fa9e4066Sahrens } zil_trailer_t; 78fa9e4066Sahrens 79b4d654b0Sperrin #define ZIL_MIN_BLKSZ 4096ULL 80fa9e4066Sahrens #define ZIL_MAX_BLKSZ SPA_MAXBLOCKSIZE 81fa9e4066Sahrens #define ZIL_BLK_DATA_SZ(lwb) ((lwb)->lwb_sz - sizeof (zil_trailer_t)) 82fa9e4066Sahrens 83d80c45e0Sbonwick /* 84d80c45e0Sbonwick * The words of a log block checksum. 85d80c45e0Sbonwick */ 86d80c45e0Sbonwick #define ZIL_ZC_GUID_0 0 87d80c45e0Sbonwick #define ZIL_ZC_GUID_1 1 88d80c45e0Sbonwick #define ZIL_ZC_OBJSET 2 89d80c45e0Sbonwick #define ZIL_ZC_SEQ 3 90d80c45e0Sbonwick 91fa9e4066Sahrens /* 92fa9e4066Sahrens * Intent log transaction types and record structures 93fa9e4066Sahrens */ 94fa9e4066Sahrens #define TX_CREATE 1 /* Create file */ 95fa9e4066Sahrens #define TX_MKDIR 2 /* Make directory */ 96fa9e4066Sahrens #define TX_MKXATTR 3 /* Make XATTR directory */ 97fa9e4066Sahrens #define TX_SYMLINK 4 /* Create symbolic link to a file */ 98fa9e4066Sahrens #define TX_REMOVE 5 /* Remove file */ 99fa9e4066Sahrens #define TX_RMDIR 6 /* Remove directory */ 100fa9e4066Sahrens #define TX_LINK 7 /* Create hard link to a file */ 101fa9e4066Sahrens #define TX_RENAME 8 /* Rename a file */ 102fa9e4066Sahrens #define TX_WRITE 9 /* File write */ 103fa9e4066Sahrens #define TX_TRUNCATE 10 /* Truncate a file */ 104fa9e4066Sahrens #define TX_SETATTR 11 /* Set file attributes */ 105fa9e4066Sahrens #define TX_ACL 12 /* Set acl */ 106fa9e4066Sahrens #define TX_MAX_TYPE 13 /* Max transaction type */ 107fa9e4066Sahrens 108fa9e4066Sahrens /* 109fa9e4066Sahrens * Format of log records. 110fa9e4066Sahrens * The fields are carefully defined to allow them to be aligned 111fa9e4066Sahrens * and sized the same on sparc & intel architectures. 112fa9e4066Sahrens * Each log record has a common structure at the beginning. 113b19a79ecSperrin * 114b19a79ecSperrin * Note, lrc_seq holds two different sequence numbers. Whilst in memory 115b19a79ecSperrin * it contains the transaction sequence number. The log record on 116b19a79ecSperrin * disk holds the sequence number of all log records which is used to 117b19a79ecSperrin * ensure we don't replay the same record. The two sequence numbers are 118b19a79ecSperrin * different because the transactions can now be pushed out of order. 119fa9e4066Sahrens */ 120fa9e4066Sahrens typedef struct { /* common log record header */ 121fa9e4066Sahrens uint64_t lrc_txtype; /* intent log transaction type */ 122fa9e4066Sahrens uint64_t lrc_reclen; /* transaction record length */ 123fa9e4066Sahrens uint64_t lrc_txg; /* dmu transaction group number */ 124b19a79ecSperrin uint64_t lrc_seq; /* see comment above */ 125fa9e4066Sahrens } lr_t; 126fa9e4066Sahrens 127fa9e4066Sahrens typedef struct { 128fa9e4066Sahrens lr_t lr_common; /* common portion of log record */ 129fa9e4066Sahrens uint64_t lr_doid; /* object id of directory */ 130fa9e4066Sahrens uint64_t lr_foid; /* object id of created file object */ 131fa9e4066Sahrens uint64_t lr_mode; /* mode of object */ 132fa9e4066Sahrens uint64_t lr_uid; /* uid of object */ 133fa9e4066Sahrens uint64_t lr_gid; /* gid of object */ 134fa9e4066Sahrens uint64_t lr_gen; /* generation (txg of creation) */ 135fa9e4066Sahrens uint64_t lr_crtime[2]; /* creation time */ 136fa9e4066Sahrens uint64_t lr_rdev; /* rdev of object to create */ 137fa9e4066Sahrens /* name of object to create follows this */ 138fa9e4066Sahrens /* for symlinks, link content follows name */ 139fa9e4066Sahrens } lr_create_t; 140fa9e4066Sahrens 141fa9e4066Sahrens typedef struct { 142fa9e4066Sahrens lr_t lr_common; /* common portion of log record */ 143fa9e4066Sahrens uint64_t lr_doid; /* obj id of directory */ 144fa9e4066Sahrens /* name of object to remove follows this */ 145fa9e4066Sahrens } lr_remove_t; 146fa9e4066Sahrens 147fa9e4066Sahrens typedef struct { 148fa9e4066Sahrens lr_t lr_common; /* common portion of log record */ 149fa9e4066Sahrens uint64_t lr_doid; /* obj id of directory */ 150fa9e4066Sahrens uint64_t lr_link_obj; /* obj id of link */ 151fa9e4066Sahrens /* name of object to link follows this */ 152fa9e4066Sahrens } lr_link_t; 153fa9e4066Sahrens 154fa9e4066Sahrens typedef struct { 155fa9e4066Sahrens lr_t lr_common; /* common portion of log record */ 156fa9e4066Sahrens uint64_t lr_sdoid; /* obj id of source directory */ 157fa9e4066Sahrens uint64_t lr_tdoid; /* obj id of target directory */ 158fa9e4066Sahrens /* 2 strings: names of source and destination follow this */ 159fa9e4066Sahrens } lr_rename_t; 160fa9e4066Sahrens 161fa9e4066Sahrens typedef struct { 162fa9e4066Sahrens lr_t lr_common; /* common portion of log record */ 163fa9e4066Sahrens uint64_t lr_foid; /* file object to write */ 164fa9e4066Sahrens uint64_t lr_offset; /* offset to write to */ 165fa9e4066Sahrens uint64_t lr_length; /* user data length to write */ 166fa9e4066Sahrens uint64_t lr_blkoff; /* offset represented by lr_blkptr */ 167fa9e4066Sahrens blkptr_t lr_blkptr; /* spa block pointer for replay */ 168fa9e4066Sahrens /* write data will follow for small writes */ 169fa9e4066Sahrens } lr_write_t; 170fa9e4066Sahrens 171fa9e4066Sahrens typedef struct { 172fa9e4066Sahrens lr_t lr_common; /* common portion of log record */ 173fa9e4066Sahrens uint64_t lr_foid; /* object id of file to truncate */ 174fa9e4066Sahrens uint64_t lr_offset; /* offset to truncate from */ 175fa9e4066Sahrens uint64_t lr_length; /* length to truncate */ 176fa9e4066Sahrens } lr_truncate_t; 177fa9e4066Sahrens 178fa9e4066Sahrens typedef struct { 179fa9e4066Sahrens lr_t lr_common; /* common portion of log record */ 180fa9e4066Sahrens uint64_t lr_foid; /* file object to change attributes */ 181fa9e4066Sahrens uint64_t lr_mask; /* mask of attributes to set */ 182fa9e4066Sahrens uint64_t lr_mode; /* mode to set */ 183fa9e4066Sahrens uint64_t lr_uid; /* uid to set */ 184fa9e4066Sahrens uint64_t lr_gid; /* gid to set */ 185fa9e4066Sahrens uint64_t lr_size; /* size to set */ 186fa9e4066Sahrens uint64_t lr_atime[2]; /* access time */ 187fa9e4066Sahrens uint64_t lr_mtime[2]; /* modification time */ 188fa9e4066Sahrens } lr_setattr_t; 189fa9e4066Sahrens 190fa9e4066Sahrens typedef struct { 191fa9e4066Sahrens lr_t lr_common; /* common portion of log record */ 192fa9e4066Sahrens uint64_t lr_foid; /* obj id of file */ 193fa9e4066Sahrens uint64_t lr_aclcnt; /* number of acl entries */ 194fa9e4066Sahrens /* lr_aclcnt number of ace_t entries follow this */ 195fa9e4066Sahrens } lr_acl_t; 196fa9e4066Sahrens 197fa9e4066Sahrens /* 198fa9e4066Sahrens * ZIL structure definitions, interface function prototype and globals. 199fa9e4066Sahrens */ 200fa9e4066Sahrens 201fa9e4066Sahrens /* 202fa9e4066Sahrens * ZFS intent log transaction structure 203fa9e4066Sahrens */ 204104e2ed7Sperrin typedef enum { 205104e2ed7Sperrin WR_INDIRECT, /* indirect - a large write (dmu_sync() data */ 206104e2ed7Sperrin /* and put blkptr in log, rather than actual data) */ 207104e2ed7Sperrin WR_COPIED, /* immediate - data is copied into lr_write_t */ 208104e2ed7Sperrin WR_NEED_COPY, /* immediate - data needs to be copied if pushed */ 209104e2ed7Sperrin } itx_wr_state_t; 210104e2ed7Sperrin 211fa9e4066Sahrens typedef struct itx { 212fa9e4066Sahrens list_node_t itx_node; /* linkage on zl_itx_list */ 213fa9e4066Sahrens void *itx_private; /* type-specific opaque data */ 214104e2ed7Sperrin itx_wr_state_t itx_wr_state; /* write state */ 21567bd71c6Sperrin uint8_t itx_sync; /* synchronous transaction */ 216fa9e4066Sahrens lr_t itx_lr; /* common part of log record */ 217fa9e4066Sahrens /* followed by type-specific part of lr_xx_t and its immediate data */ 218fa9e4066Sahrens } itx_t; 219fa9e4066Sahrens 22067bd71c6Sperrin 22167bd71c6Sperrin /* 22267bd71c6Sperrin * zgd_t is passed through dmu_sync() to the callback routine zfs_get_done() 22367bd71c6Sperrin * to handle the cleanup of the dmu_sync() buffer write 22467bd71c6Sperrin */ 22567bd71c6Sperrin typedef struct { 22667bd71c6Sperrin zilog_t *zgd_zilog; /* zilog */ 22767bd71c6Sperrin blkptr_t *zgd_bp; /* block pointer */ 22867bd71c6Sperrin struct rl *zgd_rl; /* range lock */ 22967bd71c6Sperrin } zgd_t; 23067bd71c6Sperrin 23167bd71c6Sperrin 232fa9e4066Sahrens typedef void zil_parse_blk_func_t(zilog_t *zilog, blkptr_t *bp, void *arg, 233fa9e4066Sahrens uint64_t txg); 234fa9e4066Sahrens typedef void zil_parse_lr_func_t(zilog_t *zilog, lr_t *lr, void *arg, 235fa9e4066Sahrens uint64_t txg); 236fa9e4066Sahrens typedef int zil_replay_func_t(); 237c5c6ffa0Smaybee typedef int zil_get_data_t(void *arg, lr_write_t *lr, char *dbuf, zio_t *zio); 238fa9e4066Sahrens 239d80c45e0Sbonwick extern uint64_t zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func, 240fa9e4066Sahrens zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg); 241fa9e4066Sahrens 242fa9e4066Sahrens extern void zil_init(void); 243fa9e4066Sahrens extern void zil_fini(void); 244fa9e4066Sahrens 245fa9e4066Sahrens extern zilog_t *zil_alloc(objset_t *os, zil_header_t *zh_phys); 246fa9e4066Sahrens extern void zil_free(zilog_t *zilog); 247fa9e4066Sahrens 248fa9e4066Sahrens extern zilog_t *zil_open(objset_t *os, zil_get_data_t *get_data); 249fa9e4066Sahrens extern void zil_close(zilog_t *zilog); 250fa9e4066Sahrens 251fa9e4066Sahrens extern void zil_replay(objset_t *os, void *arg, uint64_t *txgp, 252893a6d32Sahrens zil_replay_func_t *replay_func[TX_MAX_TYPE]); 253d80c45e0Sbonwick extern void zil_destroy(zilog_t *zilog, boolean_t keep_first); 254*3a8a1de4Sperrin extern void zil_rollback_destroy(zilog_t *zilog, dmu_tx_t *tx); 255fa9e4066Sahrens 256fa9e4066Sahrens extern itx_t *zil_itx_create(int txtype, size_t lrsize); 257fa9e4066Sahrens extern uint64_t zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx); 258fa9e4066Sahrens 259b19a79ecSperrin extern void zil_commit(zilog_t *zilog, uint64_t seq, uint64_t oid); 260fa9e4066Sahrens 2611d452cf5Sahrens extern int zil_claim(char *osname, void *txarg); 262fa9e4066Sahrens extern void zil_sync(zilog_t *zilog, dmu_tx_t *tx); 263fa9e4066Sahrens extern void zil_clean(zilog_t *zilog); 264436b2950Sperrin extern int zil_is_committed(zilog_t *zilog); 265fa9e4066Sahrens 266fa9e4066Sahrens extern int zil_suspend(zilog_t *zilog); 267fa9e4066Sahrens extern void zil_resume(zilog_t *zilog); 268fa9e4066Sahrens 26967bd71c6Sperrin extern void zil_add_vdev(zilog_t *zilog, uint64_t vdev); 27067bd71c6Sperrin 271fa9e4066Sahrens extern int zil_disable; 272fa9e4066Sahrens 273fa9e4066Sahrens #ifdef __cplusplus 274fa9e4066Sahrens } 275fa9e4066Sahrens #endif 276fa9e4066Sahrens 277fa9e4066Sahrens #endif /* _SYS_ZIL_H */ 278