1789Sahrens /* 2789Sahrens * CDDL HEADER START 3789Sahrens * 4789Sahrens * The contents of this file are subject to the terms of the 51807Sbonwick * Common Development and Distribution License (the "License"). 61807Sbonwick * You may not use this file except in compliance with the License. 7789Sahrens * 8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9789Sahrens * or http://www.opensolaris.org/os/licensing. 10789Sahrens * See the License for the specific language governing permissions 11789Sahrens * and limitations under the License. 12789Sahrens * 13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15789Sahrens * If applicable, add the following below this CDDL HEADER, with the 16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18789Sahrens * 19789Sahrens * CDDL HEADER END 20789Sahrens */ 21789Sahrens /* 2212294SMark.Musante@Sun.COM * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23789Sahrens */ 24789Sahrens 2512294SMark.Musante@Sun.COM /* Portions Copyright 2010 Robert Milkowski */ 2612294SMark.Musante@Sun.COM 27789Sahrens #ifndef _SYS_ZIL_IMPL_H 28789Sahrens #define _SYS_ZIL_IMPL_H 29789Sahrens 30789Sahrens #include <sys/zil.h> 31789Sahrens #include <sys/dmu_objset.h> 32789Sahrens 33789Sahrens #ifdef __cplusplus 34789Sahrens extern "C" { 35789Sahrens #endif 36789Sahrens 37789Sahrens /* 38789Sahrens * Log write buffer. 39789Sahrens */ 40789Sahrens typedef struct lwb { 41789Sahrens zilog_t *lwb_zilog; /* back pointer to log struct */ 42789Sahrens blkptr_t lwb_blk; /* on disk address of this log blk */ 43789Sahrens int lwb_nused; /* # used bytes in buffer */ 44789Sahrens int lwb_sz; /* size of block and buffer */ 45789Sahrens char *lwb_buf; /* log write buffer */ 462237Smaybee zio_t *lwb_zio; /* zio for this buffer */ 4710922SJeff.Bonwick@Sun.COM dmu_tx_t *lwb_tx; /* tx for log block allocation */ 48789Sahrens uint64_t lwb_max_txg; /* highest txg in this lwb */ 49789Sahrens list_node_t lwb_node; /* zilog->zl_lwb_list linkage */ 50789Sahrens } lwb_t; 51789Sahrens 52789Sahrens /* 53*12699SNeil.Perrin@Sun.COM * Intent log transaction lists 54*12699SNeil.Perrin@Sun.COM */ 55*12699SNeil.Perrin@Sun.COM typedef struct itxs { 56*12699SNeil.Perrin@Sun.COM list_t i_sync_list; /* list of synchronous itxs */ 57*12699SNeil.Perrin@Sun.COM avl_tree_t i_async_tree; /* tree of foids for async itxs */ 58*12699SNeil.Perrin@Sun.COM } itxs_t; 59*12699SNeil.Perrin@Sun.COM 60*12699SNeil.Perrin@Sun.COM typedef struct itxg { 61*12699SNeil.Perrin@Sun.COM kmutex_t itxg_lock; /* lock for this structure */ 62*12699SNeil.Perrin@Sun.COM uint64_t itxg_txg; /* txg for this chain */ 63*12699SNeil.Perrin@Sun.COM uint64_t itxg_sod; /* total size on disk for this txg */ 64*12699SNeil.Perrin@Sun.COM itxs_t *itxg_itxs; /* sync and async itxs */ 65*12699SNeil.Perrin@Sun.COM } itxg_t; 66*12699SNeil.Perrin@Sun.COM 67*12699SNeil.Perrin@Sun.COM /* for async nodes we build up an AVL tree of lists of async itxs per file */ 68*12699SNeil.Perrin@Sun.COM typedef struct itx_async_node { 69*12699SNeil.Perrin@Sun.COM uint64_t ia_foid; /* file object id */ 70*12699SNeil.Perrin@Sun.COM list_t ia_list; /* list of async itxs for this foid */ 71*12699SNeil.Perrin@Sun.COM avl_node_t ia_node; /* AVL tree linkage */ 72*12699SNeil.Perrin@Sun.COM } itx_async_node_t; 73*12699SNeil.Perrin@Sun.COM 74*12699SNeil.Perrin@Sun.COM /* 755688Sbonwick * Vdev flushing: during a zil_commit(), we build up an AVL tree of the vdevs 765688Sbonwick * we've touched so we know which ones need a write cache flush at the end. 77789Sahrens */ 785688Sbonwick typedef struct zil_vdev_node { 795688Sbonwick uint64_t zv_vdev; /* vdev to be flushed */ 805688Sbonwick avl_node_t zv_node; /* AVL tree linkage */ 815688Sbonwick } zil_vdev_node_t; 82789Sahrens 8311670SNeil.Perrin@Sun.COM #define ZIL_PREV_BLKS 16 8411670SNeil.Perrin@Sun.COM 85789Sahrens /* 86789Sahrens * Stable storage intent log management structure. One per dataset. 87789Sahrens */ 88789Sahrens struct zilog { 89789Sahrens kmutex_t zl_lock; /* protects most zilog_t fields */ 90789Sahrens struct dsl_pool *zl_dmu_pool; /* DSL pool */ 91789Sahrens spa_t *zl_spa; /* handle for read/write log */ 921807Sbonwick const zil_header_t *zl_header; /* log header buffer */ 93789Sahrens objset_t *zl_os; /* object set we're logging */ 94789Sahrens zil_get_data_t *zl_get_data; /* callback to get object content */ 952638Sperrin zio_t *zl_root_zio; /* log writer root zio */ 9610922SJeff.Bonwick@Sun.COM uint64_t zl_lr_seq; /* on-disk log record sequence number */ 9710922SJeff.Bonwick@Sun.COM uint64_t zl_commit_lr_seq; /* last committed on-disk lr seq */ 98789Sahrens uint64_t zl_destroy_txg; /* txg of last zil_destroy() */ 998227SNeil.Perrin@Sun.COM uint64_t zl_replayed_seq[TXG_SIZE]; /* last replayed rec seq */ 1008227SNeil.Perrin@Sun.COM uint64_t zl_replaying_seq; /* current replay seq number */ 101789Sahrens uint32_t zl_suspend; /* log suspend count */ 1022638Sperrin kcondvar_t zl_cv_writer; /* log writer thread completion */ 1031807Sbonwick kcondvar_t zl_cv_suspend; /* log suspend completion */ 1041807Sbonwick uint8_t zl_suspending; /* log is currently suspending */ 1051807Sbonwick uint8_t zl_keep_first; /* keep first log block in destroy */ 1068227SNeil.Perrin@Sun.COM uint8_t zl_replay; /* replaying records while set */ 107789Sahrens uint8_t zl_stop_sync; /* for debugging */ 108789Sahrens uint8_t zl_writer; /* boolean: write setup in progress */ 10910310SNeil.Perrin@Sun.COM uint8_t zl_logbias; /* latency or throughput */ 11012294SMark.Musante@Sun.COM uint8_t zl_sync; /* synchronous or asynchronous */ 11110922SJeff.Bonwick@Sun.COM int zl_parse_error; /* last zil_parse() error */ 11210922SJeff.Bonwick@Sun.COM uint64_t zl_parse_blk_seq; /* highest blk seq on last parse */ 11310922SJeff.Bonwick@Sun.COM uint64_t zl_parse_lr_seq; /* highest lr seq on last parse */ 11410922SJeff.Bonwick@Sun.COM uint64_t zl_parse_blk_count; /* number of blocks parsed */ 11510922SJeff.Bonwick@Sun.COM uint64_t zl_parse_lr_count; /* number of log records parsed */ 116*12699SNeil.Perrin@Sun.COM uint64_t zl_next_batch; /* next batch number */ 117*12699SNeil.Perrin@Sun.COM uint64_t zl_com_batch; /* committed batch number */ 118*12699SNeil.Perrin@Sun.COM kcondvar_t zl_cv_batch[2]; /* batch condition variables */ 119*12699SNeil.Perrin@Sun.COM itxg_t zl_itxg[TXG_SIZE]; /* intent log txg chains */ 120*12699SNeil.Perrin@Sun.COM list_t zl_itx_commit_list; /* itx list to be committed */ 121789Sahrens uint64_t zl_itx_list_sz; /* total size of records on list */ 1221141Sperrin uint64_t zl_cur_used; /* current commit log size used */ 123789Sahrens list_t zl_lwb_list; /* in-flight log write list */ 1245688Sbonwick kmutex_t zl_vdev_lock; /* protects zl_vdev_tree */ 1255688Sbonwick avl_tree_t zl_vdev_tree; /* vdevs to flush in zil_commit() */ 126789Sahrens taskq_t *zl_clean_taskq; /* runs lwb and itx clean tasks */ 12710922SJeff.Bonwick@Sun.COM avl_tree_t zl_bp_tree; /* track bps during log parse */ 1283063Sperrin clock_t zl_replay_time; /* lbolt of when replay started */ 1293063Sperrin uint64_t zl_replay_blks; /* number of log blocks replayed */ 13010922SJeff.Bonwick@Sun.COM zil_header_t zl_old_header; /* debugging aid */ 13111670SNeil.Perrin@Sun.COM uint_t zl_prev_blks[ZIL_PREV_BLKS]; /* size - sector rounded */ 13211670SNeil.Perrin@Sun.COM uint_t zl_prev_rotor; /* rotor for zl_prev[] */ 133789Sahrens }; 134789Sahrens 13510922SJeff.Bonwick@Sun.COM typedef struct zil_bp_node { 136789Sahrens dva_t zn_dva; 137789Sahrens avl_node_t zn_node; 13810922SJeff.Bonwick@Sun.COM } zil_bp_node_t; 139789Sahrens 14011670SNeil.Perrin@Sun.COM #define ZIL_MAX_LOG_DATA (SPA_MAXBLOCKSIZE - sizeof (zil_chain_t) - \ 1419401SNeil.Perrin@Sun.COM sizeof (lr_write_t)) 1429401SNeil.Perrin@Sun.COM 143789Sahrens #ifdef __cplusplus 144789Sahrens } 145789Sahrens #endif 146789Sahrens 147789Sahrens #endif /* _SYS_ZIL_IMPL_H */ 148