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