1789Sahrens /* 2789Sahrens * CDDL HEADER START 3789Sahrens * 4789Sahrens * The contents of this file are subject to the terms of the 51544Seschrock * Common Development and Distribution License (the "License"). 61544Seschrock * 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 /* 22*11935SMark.Shellenbaum@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23789Sahrens * Use is subject to license terms. 24789Sahrens */ 25789Sahrens 26789Sahrens #ifndef _SYS_DMU_TX_H 27789Sahrens #define _SYS_DMU_TX_H 28789Sahrens 29789Sahrens #include <sys/inttypes.h> 30789Sahrens #include <sys/dmu.h> 31789Sahrens #include <sys/txg.h> 32789Sahrens #include <sys/refcount.h> 33789Sahrens 34789Sahrens #ifdef __cplusplus 35789Sahrens extern "C" { 36789Sahrens #endif 37789Sahrens 38789Sahrens struct dmu_buf_impl; 392113Sahrens struct dmu_tx_hold; 40789Sahrens struct dnode_link; 41789Sahrens struct dsl_pool; 42789Sahrens struct dnode; 43789Sahrens struct dsl_dir; 44789Sahrens 45789Sahrens struct dmu_tx { 46789Sahrens /* 47789Sahrens * No synchronization is needed because a tx can only be handled 48789Sahrens * by one thread. 49789Sahrens */ 50789Sahrens list_t tx_holds; /* list of dmu_tx_hold_t */ 51789Sahrens objset_t *tx_objset; 52789Sahrens struct dsl_dir *tx_dir; 53789Sahrens struct dsl_pool *tx_pool; 54789Sahrens uint64_t tx_txg; 551544Seschrock uint64_t tx_lastsnap_txg; 562113Sahrens uint64_t tx_lasttried_txg; 57789Sahrens txg_handle_t tx_txgh; 58789Sahrens void *tx_tempreserve_cookie; 592113Sahrens struct dmu_tx_hold *tx_needassign_txh; 6010612SRicardo.M.Correia@Sun.COM list_t tx_callbacks; /* list of dmu_tx_callback_t on this dmu_tx */ 61789Sahrens uint8_t tx_anyobj; 621544Seschrock int tx_err; 63789Sahrens #ifdef ZFS_DEBUG 642113Sahrens uint64_t tx_space_towrite; 652113Sahrens uint64_t tx_space_tofree; 662113Sahrens uint64_t tx_space_tooverwrite; 675378Sck153898 uint64_t tx_space_tounref; 682113Sahrens refcount_t tx_space_written; 692113Sahrens refcount_t tx_space_freed; 70789Sahrens #endif 71789Sahrens }; 72789Sahrens 73789Sahrens enum dmu_tx_hold_type { 74789Sahrens THT_NEWOBJECT, 75789Sahrens THT_WRITE, 76789Sahrens THT_BONUS, 77789Sahrens THT_FREE, 78789Sahrens THT_ZAP, 79789Sahrens THT_SPACE, 80*11935SMark.Shellenbaum@Sun.COM THT_SPILL, 81789Sahrens THT_NUMTYPES 82789Sahrens }; 83789Sahrens 84789Sahrens typedef struct dmu_tx_hold { 852113Sahrens dmu_tx_t *txh_tx; 862113Sahrens list_node_t txh_node; 872113Sahrens struct dnode *txh_dnode; 882113Sahrens uint64_t txh_space_towrite; 892113Sahrens uint64_t txh_space_tofree; 902113Sahrens uint64_t txh_space_tooverwrite; 915378Sck153898 uint64_t txh_space_tounref; 926992Smaybee uint64_t txh_memory_tohold; 937016Smaybee uint64_t txh_fudge; 942113Sahrens #ifdef ZFS_DEBUG 952113Sahrens enum dmu_tx_hold_type txh_type; 962113Sahrens uint64_t txh_arg1; 972113Sahrens uint64_t txh_arg2; 982113Sahrens #endif 99789Sahrens } dmu_tx_hold_t; 100789Sahrens 10110612SRicardo.M.Correia@Sun.COM typedef struct dmu_tx_callback { 10210612SRicardo.M.Correia@Sun.COM list_node_t dcb_node; /* linked to tx_callbacks list */ 10310612SRicardo.M.Correia@Sun.COM dmu_tx_callback_func_t *dcb_func; /* caller function pointer */ 10410612SRicardo.M.Correia@Sun.COM void *dcb_data; /* caller private data */ 10510612SRicardo.M.Correia@Sun.COM } dmu_tx_callback_t; 106789Sahrens 107789Sahrens /* 108789Sahrens * These routines are defined in dmu.h, and are called by the user. 109789Sahrens */ 110789Sahrens dmu_tx_t *dmu_tx_create(objset_t *dd); 111789Sahrens int dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how); 112789Sahrens void dmu_tx_commit(dmu_tx_t *tx); 113789Sahrens void dmu_tx_abort(dmu_tx_t *tx); 114789Sahrens uint64_t dmu_tx_get_txg(dmu_tx_t *tx); 1152113Sahrens void dmu_tx_wait(dmu_tx_t *tx); 116789Sahrens 11710612SRicardo.M.Correia@Sun.COM void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func, 11810612SRicardo.M.Correia@Sun.COM void *dcb_data); 11910612SRicardo.M.Correia@Sun.COM void dmu_tx_do_callbacks(list_t *cb_list, int error); 12010612SRicardo.M.Correia@Sun.COM 121789Sahrens /* 122789Sahrens * These routines are defined in dmu_spa.h, and are called by the SPA. 123789Sahrens */ 124789Sahrens extern dmu_tx_t *dmu_tx_create_assigned(struct dsl_pool *dp, uint64_t txg); 125789Sahrens 126789Sahrens /* 127789Sahrens * These routines are only called by the DMU. 128789Sahrens */ 1292199Sahrens dmu_tx_t *dmu_tx_create_dd(dsl_dir_t *dd); 130789Sahrens int dmu_tx_is_syncing(dmu_tx_t *tx); 131789Sahrens int dmu_tx_private_ok(dmu_tx_t *tx); 132789Sahrens void dmu_tx_add_new_object(dmu_tx_t *tx, objset_t *os, uint64_t object); 133789Sahrens void dmu_tx_willuse_space(dmu_tx_t *tx, int64_t delta); 134789Sahrens void dmu_tx_dirty_buf(dmu_tx_t *tx, struct dmu_buf_impl *db); 135789Sahrens int dmu_tx_holds(dmu_tx_t *tx, uint64_t object); 136789Sahrens void dmu_tx_hold_space(dmu_tx_t *tx, uint64_t space); 137789Sahrens 138789Sahrens #ifdef ZFS_DEBUG 139873Sek110237 #define DMU_TX_DIRTY_BUF(tx, db) dmu_tx_dirty_buf(tx, db) 140789Sahrens #else 141873Sek110237 #define DMU_TX_DIRTY_BUF(tx, db) 142789Sahrens #endif 143789Sahrens 144789Sahrens #ifdef __cplusplus 145789Sahrens } 146789Sahrens #endif 147789Sahrens 148789Sahrens #endif /* _SYS_DMU_TX_H */ 149