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