1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5d80c45e0Sbonwick * Common Development and Distribution License (the "License"). 6d80c45e0Sbonwick * 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 /* 2255da60b9SMark J Musante * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23ce636f8bSMatthew Ahrens * Copyright (c) 2012 by Delphix. All rights reserved. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 2655da60b9SMark J Musante /* Portions Copyright 2010 Robert Milkowski */ 2755da60b9SMark J Musante 28fa9e4066Sahrens #ifndef _SYS_ZIL_IMPL_H 29fa9e4066Sahrens #define _SYS_ZIL_IMPL_H 30fa9e4066Sahrens 31fa9e4066Sahrens #include <sys/zil.h> 32fa9e4066Sahrens #include <sys/dmu_objset.h> 33fa9e4066Sahrens 34fa9e4066Sahrens #ifdef __cplusplus 35fa9e4066Sahrens extern "C" { 36fa9e4066Sahrens #endif 37fa9e4066Sahrens 38fa9e4066Sahrens /* 39fa9e4066Sahrens * Log write buffer. 40fa9e4066Sahrens */ 41fa9e4066Sahrens typedef struct lwb { 42fa9e4066Sahrens zilog_t *lwb_zilog; /* back pointer to log struct */ 43fa9e4066Sahrens blkptr_t lwb_blk; /* on disk address of this log blk */ 44fa9e4066Sahrens int lwb_nused; /* # used bytes in buffer */ 45fa9e4066Sahrens int lwb_sz; /* size of block and buffer */ 46fa9e4066Sahrens char *lwb_buf; /* log write buffer */ 47c5c6ffa0Smaybee zio_t *lwb_zio; /* zio for this buffer */ 48b24ab676SJeff Bonwick dmu_tx_t *lwb_tx; /* tx for log block allocation */ 49fa9e4066Sahrens uint64_t lwb_max_txg; /* highest txg in this lwb */ 50fa9e4066Sahrens list_node_t lwb_node; /* zilog->zl_lwb_list linkage */ 51fa9e4066Sahrens } lwb_t; 52fa9e4066Sahrens 535002558fSNeil Perrin /* 545002558fSNeil Perrin * Intent log transaction lists 555002558fSNeil Perrin */ 565002558fSNeil Perrin typedef struct itxs { 575002558fSNeil Perrin list_t i_sync_list; /* list of synchronous itxs */ 585002558fSNeil Perrin avl_tree_t i_async_tree; /* tree of foids for async itxs */ 595002558fSNeil Perrin } itxs_t; 605002558fSNeil Perrin 615002558fSNeil Perrin typedef struct itxg { 625002558fSNeil Perrin kmutex_t itxg_lock; /* lock for this structure */ 635002558fSNeil Perrin uint64_t itxg_txg; /* txg for this chain */ 645002558fSNeil Perrin uint64_t itxg_sod; /* total size on disk for this txg */ 655002558fSNeil Perrin itxs_t *itxg_itxs; /* sync and async itxs */ 665002558fSNeil Perrin } itxg_t; 675002558fSNeil Perrin 685002558fSNeil Perrin /* for async nodes we build up an AVL tree of lists of async itxs per file */ 695002558fSNeil Perrin typedef struct itx_async_node { 705002558fSNeil Perrin uint64_t ia_foid; /* file object id */ 715002558fSNeil Perrin list_t ia_list; /* list of async itxs for this foid */ 725002558fSNeil Perrin avl_node_t ia_node; /* AVL tree linkage */ 735002558fSNeil Perrin } itx_async_node_t; 745002558fSNeil Perrin 75fa9e4066Sahrens /* 7617f17c2dSbonwick * Vdev flushing: during a zil_commit(), we build up an AVL tree of the vdevs 7717f17c2dSbonwick * we've touched so we know which ones need a write cache flush at the end. 78fa9e4066Sahrens */ 7917f17c2dSbonwick typedef struct zil_vdev_node { 8017f17c2dSbonwick uint64_t zv_vdev; /* vdev to be flushed */ 8117f17c2dSbonwick avl_node_t zv_node; /* AVL tree linkage */ 8217f17c2dSbonwick } zil_vdev_node_t; 83fa9e4066Sahrens 846e1f5caaSNeil Perrin #define ZIL_PREV_BLKS 16 856e1f5caaSNeil Perrin 86fa9e4066Sahrens /* 87fa9e4066Sahrens * Stable storage intent log management structure. One per dataset. 88fa9e4066Sahrens */ 89fa9e4066Sahrens struct zilog { 90fa9e4066Sahrens kmutex_t zl_lock; /* protects most zilog_t fields */ 91fa9e4066Sahrens struct dsl_pool *zl_dmu_pool; /* DSL pool */ 92fa9e4066Sahrens spa_t *zl_spa; /* handle for read/write log */ 93d80c45e0Sbonwick const zil_header_t *zl_header; /* log header buffer */ 94fa9e4066Sahrens objset_t *zl_os; /* object set we're logging */ 95fa9e4066Sahrens zil_get_data_t *zl_get_data; /* callback to get object content */ 96b19a79ecSperrin zio_t *zl_root_zio; /* log writer root zio */ 97b24ab676SJeff Bonwick uint64_t zl_lr_seq; /* on-disk log record sequence number */ 98b24ab676SJeff Bonwick uint64_t zl_commit_lr_seq; /* last committed on-disk lr seq */ 99fa9e4066Sahrens uint64_t zl_destroy_txg; /* txg of last zil_destroy() */ 1001209a471SNeil Perrin uint64_t zl_replayed_seq[TXG_SIZE]; /* last replayed rec seq */ 1011209a471SNeil Perrin uint64_t zl_replaying_seq; /* current replay seq number */ 102fa9e4066Sahrens uint32_t zl_suspend; /* log suspend count */ 103b19a79ecSperrin kcondvar_t zl_cv_writer; /* log writer thread completion */ 104d80c45e0Sbonwick kcondvar_t zl_cv_suspend; /* log suspend completion */ 105d80c45e0Sbonwick uint8_t zl_suspending; /* log is currently suspending */ 106d80c45e0Sbonwick uint8_t zl_keep_first; /* keep first log block in destroy */ 1071209a471SNeil Perrin uint8_t zl_replay; /* replaying records while set */ 108fa9e4066Sahrens uint8_t zl_stop_sync; /* for debugging */ 109fa9e4066Sahrens uint8_t zl_writer; /* boolean: write setup in progress */ 110e09fa4daSNeil Perrin uint8_t zl_logbias; /* latency or throughput */ 11155da60b9SMark J Musante uint8_t zl_sync; /* synchronous or asynchronous */ 112b24ab676SJeff Bonwick int zl_parse_error; /* last zil_parse() error */ 113b24ab676SJeff Bonwick uint64_t zl_parse_blk_seq; /* highest blk seq on last parse */ 114b24ab676SJeff Bonwick uint64_t zl_parse_lr_seq; /* highest lr seq on last parse */ 115b24ab676SJeff Bonwick uint64_t zl_parse_blk_count; /* number of blocks parsed */ 116b24ab676SJeff Bonwick uint64_t zl_parse_lr_count; /* number of log records parsed */ 1175002558fSNeil Perrin uint64_t zl_next_batch; /* next batch number */ 1185002558fSNeil Perrin uint64_t zl_com_batch; /* committed batch number */ 1195002558fSNeil Perrin kcondvar_t zl_cv_batch[2]; /* batch condition variables */ 1205002558fSNeil Perrin itxg_t zl_itxg[TXG_SIZE]; /* intent log txg chains */ 1215002558fSNeil Perrin list_t zl_itx_commit_list; /* itx list to be committed */ 122fa9e4066Sahrens uint64_t zl_itx_list_sz; /* total size of records on list */ 12322ac5be4Sperrin uint64_t zl_cur_used; /* current commit log size used */ 124fa9e4066Sahrens list_t zl_lwb_list; /* in-flight log write list */ 12517f17c2dSbonwick kmutex_t zl_vdev_lock; /* protects zl_vdev_tree */ 12617f17c2dSbonwick avl_tree_t zl_vdev_tree; /* vdevs to flush in zil_commit() */ 127fa9e4066Sahrens taskq_t *zl_clean_taskq; /* runs lwb and itx clean tasks */ 128b24ab676SJeff Bonwick avl_tree_t zl_bp_tree; /* track bps during log parse */ 12967bd71c6Sperrin clock_t zl_replay_time; /* lbolt of when replay started */ 13067bd71c6Sperrin uint64_t zl_replay_blks; /* number of log blocks replayed */ 131b24ab676SJeff Bonwick zil_header_t zl_old_header; /* debugging aid */ 1326e1f5caaSNeil Perrin uint_t zl_prev_blks[ZIL_PREV_BLKS]; /* size - sector rounded */ 1336e1f5caaSNeil Perrin uint_t zl_prev_rotor; /* rotor for zl_prev[] */ 134ce636f8bSMatthew Ahrens txg_node_t zl_dirty_link; /* protected by dp_dirty_zilogs list */ 135fa9e4066Sahrens }; 136fa9e4066Sahrens 137b24ab676SJeff Bonwick typedef struct zil_bp_node { 138fa9e4066Sahrens dva_t zn_dva; 139fa9e4066Sahrens avl_node_t zn_node; 140b24ab676SJeff Bonwick } zil_bp_node_t; 141fa9e4066Sahrens 142*b5152584SMatthew Ahrens #define ZIL_MAX_LOG_DATA (SPA_OLD_MAXBLOCKSIZE - sizeof (zil_chain_t) - \ 143510b6c0eSNeil Perrin sizeof (lr_write_t)) 144510b6c0eSNeil Perrin 145fa9e4066Sahrens #ifdef __cplusplus 146fa9e4066Sahrens } 147fa9e4066Sahrens #endif 148fa9e4066Sahrens 149fa9e4066Sahrens #endif /* _SYS_ZIL_IMPL_H */ 150