FreeBSD ZFS
The Zettabyte File System

sys/zil.h

Go to the documentation of this file.
00001 /*
00002  * CDDL HEADER START
00003  *
00004  * The contents of this file are subject to the terms of the
00005  * Common Development and Distribution License (the "License").
00006  * You may not use this file except in compliance with the License.
00007  *
00008  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
00009  * or http://www.opensolaris.org/os/licensing.
00010  * See the License for the specific language governing permissions
00011  * and limitations under the License.
00012  *
00013  * When distributing Covered Code, include this CDDL HEADER in each
00014  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
00015  * If applicable, add the following below this CDDL HEADER, with the
00016  * fields enclosed by brackets "[]" replaced with your own identifying
00017  * information: Portions Copyright [yyyy] [name of copyright owner]
00018  *
00019  * CDDL HEADER END
00020  */
00021 /*
00022  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
00023  * Copyright (c) 2012 by Delphix. All rights reserved.
00024  */
00025 
00026 /* Portions Copyright 2010 Robert Milkowski */
00027 
00028 #ifndef _SYS_ZIL_H
00029 #define _SYS_ZIL_H
00030 
00031 #include <sys/types.h>
00032 #include <sys/spa.h>
00033 #include <sys/zio.h>
00034 #include <sys/dmu.h>
00035 
00036 #ifdef  __cplusplus
00037 extern "C" {
00038 #endif
00039 
00059 typedef struct zil_header {
00060         uint64_t zh_claim_txg;  
00061         uint64_t zh_replay_seq; 
00062         blkptr_t zh_log;        
00063         uint64_t zh_claim_blk_seq; 
00064         uint64_t zh_flags;      
00065         uint64_t zh_claim_lr_seq; 
00066         uint64_t zh_pad[3];
00067 } zil_header_t;
00068 
00073 #define ZIL_REPLAY_NEEDED       0x1     
00074 #define ZIL_CLAIM_LR_SEQ_VALID  0x2     
00090 typedef struct zil_chain {
00091         uint64_t zc_pad;
00092         blkptr_t zc_next_blk;   
00093         uint64_t zc_nused;      
00094         zio_eck_t zc_eck;       
00095 } zil_chain_t;
00096 
00097 #define ZIL_MIN_BLKSZ   4096ULL
00098 #define ZIL_MAX_BLKSZ   SPA_MAXBLOCKSIZE
00099 
00104 #define ZIL_ZC_GUID_0   0
00105 #define ZIL_ZC_GUID_1   1
00106 #define ZIL_ZC_OBJSET   2
00107 #define ZIL_ZC_SEQ      3
00108 
00110 typedef enum zil_create {
00111         Z_FILE,
00112         Z_DIR,
00113         Z_XATTRDIR,
00114 } zil_create_t;
00115 
00125 #define ZIL_XVAT_SIZE(mapsize) \
00126         sizeof (lr_attr_t) + (sizeof (uint32_t) * (mapsize - 1)) + \
00127         (sizeof (uint64_t) * 7)
00128 
00134 #define ZIL_ACE_LENGTH(x)       (roundup(x, sizeof (uint64_t)))
00135 
00140 #define TX_CREATE               1       
00141 #define TX_MKDIR                2       
00142 #define TX_MKXATTR              3       
00143 #define TX_SYMLINK              4       
00144 #define TX_REMOVE               5       
00145 #define TX_RMDIR                6       
00146 #define TX_LINK                 7       
00147 #define TX_RENAME               8       
00148 #define TX_WRITE                9       
00149 #define TX_TRUNCATE             10      
00150 #define TX_SETATTR              11      
00151 #define TX_ACL_V0               12      
00152 #define TX_ACL                  13      
00153 #define TX_CREATE_ACL           14      
00154 #define TX_CREATE_ATTR          15      
00155 #define TX_CREATE_ACL_ATTR      16      
00156 #define TX_MKDIR_ACL            17      
00157 #define TX_MKDIR_ATTR           18      
00158 #define TX_MKDIR_ACL_ATTR       19      
00159 #define TX_WRITE2               20      
00160 #define TX_MAX_TYPE             21      
00168 #define TX_CI   ((uint64_t)0x1 << 63) /* case-insensitive behavior requested */
00169 
00175 #define TX_OOO(txtype)                  \
00176         ((txtype) == TX_WRITE ||        \
00177         (txtype) == TX_TRUNCATE ||      \
00178         (txtype) == TX_SETATTR ||       \
00179         (txtype) == TX_ACL_V0 ||        \
00180         (txtype) == TX_ACL ||           \
00181         (txtype) == TX_WRITE2)
00182 
00192 typedef struct {                        
00193         uint64_t        lrc_txtype;     
00194         uint64_t        lrc_reclen;     
00195         uint64_t        lrc_txg;        
00196         uint64_t        lrc_seq;        
00197 } lr_t;
00198 
00202 typedef struct {
00203         lr_t            lr_common;      
00204         uint64_t        lr_foid;        
00205 } lr_ooo_t;
00206 
00214 typedef struct {
00215         uint32_t        lr_attr_masksize; 
00216         uint32_t        lr_attr_bitmap; 
00217         /* remainder of array and any additional fields */
00218 } lr_attr_t;
00219 
00224 typedef struct {
00225         lr_t            lr_common;      
00226         uint64_t        lr_doid;        
00227         uint64_t        lr_foid;        
00228         uint64_t        lr_mode;        
00229         uint64_t        lr_uid;         
00230         uint64_t        lr_gid;         
00231         uint64_t        lr_gen;         
00232         uint64_t        lr_crtime[2];   
00233         uint64_t        lr_rdev;        
00234         /* name of object to create follows this */
00235         /* for symlinks, link content follows name */
00236         /* for creates with xvattr data, the name follows the xvattr info */
00237 } lr_create_t;
00238 
00239 /*
00240  * FUID ACL record will be an array of ACEs from the original ACL.
00241  * If this array includes ephemeral IDs, the record will also include
00242  * an array of log-specific FUIDs to replace the ephemeral IDs.
00243  * Only one copy of each unique domain will be present, so the log-specific
00244  * FUIDs will use an index into a compressed domain table.  On replay this
00245  * information will be used to construct real FUIDs (and bypass idmap,
00246  * since it may not be available).
00247  */
00248 
00262 typedef struct {
00263         lr_create_t     lr_create;      
00264         uint64_t        lr_aclcnt;      
00265         uint64_t        lr_domcnt;      
00266         uint64_t        lr_fuidcnt;     
00267         uint64_t        lr_acl_bytes;   
00268         uint64_t        lr_acl_flags;   
00269 } lr_acl_create_t;
00270 
00272 typedef struct {
00273         lr_t            lr_common;      
00274         uint64_t        lr_doid;        
00275 } lr_remove_t;
00276 
00278 typedef struct {
00279         lr_t            lr_common;      
00280         uint64_t        lr_doid;        
00281         uint64_t        lr_link_obj;    
00282 } lr_link_t;
00283 
00285 typedef struct {
00286         lr_t            lr_common;      
00287         uint64_t        lr_sdoid;       
00288         uint64_t        lr_tdoid;       
00289 } lr_rename_t;
00290 
00292 typedef struct {
00293         lr_t            lr_common;      
00294         uint64_t        lr_foid;        
00295         uint64_t        lr_offset;      
00296         uint64_t        lr_length;      
00297         uint64_t        lr_blkoff;      
00298         blkptr_t        lr_blkptr;      
00299 } lr_write_t;
00300 
00301 typedef struct {
00302         lr_t            lr_common;      
00303         uint64_t        lr_foid;        
00304         uint64_t        lr_offset;      
00305         uint64_t        lr_length;      
00306 } lr_truncate_t;
00307 
00309 typedef struct {
00310         lr_t            lr_common;      
00311         uint64_t        lr_foid;        
00312         uint64_t        lr_mask;        
00313         uint64_t        lr_mode;        
00314         uint64_t        lr_uid;         
00315         uint64_t        lr_gid;         
00316         uint64_t        lr_size;        
00317         uint64_t        lr_atime[2];    
00318         uint64_t        lr_mtime[2];    
00319 } lr_setattr_t;
00320 
00322 typedef struct {
00323         lr_t            lr_common;      
00324         uint64_t        lr_foid;        
00325         uint64_t        lr_aclcnt;      
00326 } lr_acl_v0_t;
00327 
00329 typedef struct {
00330         lr_t            lr_common;      
00331         uint64_t        lr_foid;        
00332         uint64_t        lr_aclcnt;      
00333         uint64_t        lr_domcnt;      
00334         uint64_t        lr_fuidcnt;     
00335         uint64_t        lr_acl_bytes;   
00336         uint64_t        lr_acl_flags;   
00337 } lr_acl_t;
00338 
00339 /*
00340  * ZIL structure definitions, interface function prototype and globals.
00341  */
00342 
00365 typedef enum {
00366         WR_INDIRECT,    
00368         WR_COPIED,      
00369         WR_NEED_COPY,   
00370         WR_NUM_STATES   
00371 } itx_wr_state_t;
00372 
00377 typedef struct itx {
00378         list_node_t     itx_node;       
00379         void            *itx_private;   
00380         itx_wr_state_t  itx_wr_state;   
00381         uint8_t         itx_sync;       
00382         uint64_t        itx_sod;        
00383         uint64_t        itx_oid;        
00384         lr_t            itx_lr;         
00385 } itx_t;
00386 
00387 typedef int zil_parse_blk_func_t(zilog_t *zilog, blkptr_t *bp, void *arg,
00388     uint64_t txg);
00389 typedef int zil_parse_lr_func_t(zilog_t *zilog, lr_t *lr, void *arg,
00390     uint64_t txg);
00391 typedef int zil_replay_func_t();
00392 typedef int zil_get_data_t(void *arg, lr_write_t *lr, char *dbuf, zio_t *zio);
00393 
00394 extern int zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
00395     zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg);
00396 
00397 extern void     zil_init(void);
00398 extern void     zil_fini(void);
00399 
00400 extern zilog_t  *zil_alloc(objset_t *os, zil_header_t *zh_phys);
00401 extern void     zil_free(zilog_t *zilog);
00402 
00403 extern zilog_t  *zil_open(objset_t *os, zil_get_data_t *get_data);
00404 extern void     zil_close(zilog_t *zilog);
00405 
00406 extern void     zil_replay(objset_t *os, void *arg,
00407     zil_replay_func_t *replay_func[TX_MAX_TYPE]);
00408 extern boolean_t zil_replaying(zilog_t *zilog, dmu_tx_t *tx);
00409 extern void     zil_destroy(zilog_t *zilog, boolean_t keep_first);
00410 extern void     zil_destroy_sync(zilog_t *zilog, dmu_tx_t *tx);
00411 extern void     zil_rollback_destroy(zilog_t *zilog, dmu_tx_t *tx);
00412 
00413 extern itx_t    *zil_itx_create(uint64_t txtype, size_t lrsize);
00414 extern void     zil_itx_destroy(itx_t *itx);
00415 extern void     zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx);
00416 
00417 extern void     zil_commit(zilog_t *zilog, uint64_t oid);
00418 
00419 extern int      zil_vdev_offline(const char *osname, void *txarg);
00420 extern int      zil_claim(const char *osname, void *txarg);
00421 extern int      zil_check_log_chain(const char *osname, void *txarg);
00422 extern void     zil_sync(zilog_t *zilog, dmu_tx_t *tx);
00423 extern void     zil_clean(zilog_t *zilog, uint64_t synced_txg);
00424 
00425 extern int      zil_suspend(zilog_t *zilog);
00426 extern void     zil_resume(zilog_t *zilog);
00427 
00428 extern void     zil_add_block(zilog_t *zilog, const blkptr_t *bp);
00429 extern int      zil_bp_tree_add(zilog_t *zilog, const blkptr_t *bp);
00430 
00431 extern void     zil_set_sync(zilog_t *zilog, uint64_t syncval);
00432 
00433 extern void     zil_set_logbias(zilog_t *zilog, uint64_t slogval);
00434 
00435 extern int zil_replay_disable;
00436 
00437 #ifdef  __cplusplus
00438 }
00439 #endif
00440 
00441 #endif  /* _SYS_ZIL_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines