Home | History | Annotate | Line # | Download | only in sys
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 /*
     26  * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
     27  */
     28 
     29 #ifndef	_SYS_DMU_TX_H
     30 #define	_SYS_DMU_TX_H
     31 
     32 #include <sys/dmu.h>
     33 #include <sys/txg.h>
     34 #include <sys/refcount.h>
     35 
     36 #ifdef	__cplusplus
     37 extern "C" {
     38 #endif
     39 
     40 struct dmu_buf_impl;
     41 struct dmu_tx_hold;
     42 struct dnode_link;
     43 struct dsl_pool;
     44 struct dnode;
     45 struct dsl_dir;
     46 
     47 struct dmu_tx {
     48 	/*
     49 	 * No synchronization is needed because a tx can only be handled
     50 	 * by one thread.
     51 	 */
     52 	list_t tx_holds; /* list of dmu_tx_hold_t */
     53 	objset_t *tx_objset;
     54 	struct dsl_dir *tx_dir;
     55 	struct dsl_pool *tx_pool;
     56 	uint64_t tx_txg;
     57 	uint64_t tx_lastsnap_txg;
     58 	uint64_t tx_lasttried_txg;
     59 	txg_handle_t tx_txgh;
     60 	void *tx_tempreserve_cookie;
     61 	struct dmu_tx_hold *tx_needassign_txh;
     62 
     63 	/* list of dmu_tx_callback_t on this dmu_tx */
     64 	list_t tx_callbacks;
     65 
     66 	/* placeholder for syncing context, doesn't need specific holds */
     67 	boolean_t tx_anyobj;
     68 
     69 	/* has this transaction already been delayed? */
     70 	boolean_t tx_waited;
     71 
     72 	/* time this transaction was created */
     73 	hrtime_t tx_start;
     74 
     75 	/* need to wait for sufficient dirty space */
     76 	boolean_t tx_wait_dirty;
     77 
     78 	int tx_err;
     79 #ifdef ZFS_DEBUG
     80 	uint64_t tx_space_towrite;
     81 	uint64_t tx_space_tofree;
     82 	uint64_t tx_space_tooverwrite;
     83 	uint64_t tx_space_tounref;
     84 	refcount_t tx_space_written;
     85 	refcount_t tx_space_freed;
     86 #endif
     87 };
     88 
     89 enum dmu_tx_hold_type {
     90 	THT_NEWOBJECT,
     91 	THT_WRITE,
     92 	THT_BONUS,
     93 	THT_FREE,
     94 	THT_ZAP,
     95 	THT_SPACE,
     96 	THT_SPILL,
     97 	THT_NUMTYPES
     98 };
     99 
    100 typedef struct dmu_tx_hold {
    101 	dmu_tx_t *txh_tx;
    102 	list_node_t txh_node;
    103 	struct dnode *txh_dnode;
    104 	refcount_t txh_space_towrite;
    105 	refcount_t txh_space_tofree;
    106 	refcount_t txh_space_tooverwrite;
    107 	refcount_t txh_space_tounref;
    108 	refcount_t txh_memory_tohold;
    109 	refcount_t txh_fudge;
    110 #ifdef ZFS_DEBUG
    111 	enum dmu_tx_hold_type txh_type;
    112 	uint64_t txh_arg1;
    113 	uint64_t txh_arg2;
    114 #endif
    115 } dmu_tx_hold_t;
    116 
    117 typedef struct dmu_tx_callback {
    118 	list_node_t		dcb_node;    /* linked to tx_callbacks list */
    119 	dmu_tx_callback_func_t	*dcb_func;   /* caller function pointer */
    120 	void			*dcb_data;   /* caller private data */
    121 } dmu_tx_callback_t;
    122 
    123 /*
    124  * These routines are defined in dmu.h, and are called by the user.
    125  */
    126 dmu_tx_t *dmu_tx_create(objset_t *dd);
    127 int dmu_tx_assign(dmu_tx_t *tx, txg_how_t txg_how);
    128 void dmu_tx_commit(dmu_tx_t *tx);
    129 void dmu_tx_abort(dmu_tx_t *tx);
    130 uint64_t dmu_tx_get_txg(dmu_tx_t *tx);
    131 struct dsl_pool *dmu_tx_pool(dmu_tx_t *tx);
    132 void dmu_tx_wait(dmu_tx_t *tx);
    133 
    134 void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func,
    135     void *dcb_data);
    136 void dmu_tx_do_callbacks(list_t *cb_list, int error);
    137 
    138 /*
    139  * These routines are defined in dmu_spa.h, and are called by the SPA.
    140  */
    141 extern dmu_tx_t *dmu_tx_create_assigned(struct dsl_pool *dp, uint64_t txg);
    142 
    143 /*
    144  * These routines are only called by the DMU.
    145  */
    146 dmu_tx_t *dmu_tx_create_dd(dsl_dir_t *dd);
    147 int dmu_tx_is_syncing(dmu_tx_t *tx);
    148 int dmu_tx_private_ok(dmu_tx_t *tx);
    149 void dmu_tx_add_new_object(dmu_tx_t *tx, objset_t *os, uint64_t object);
    150 void dmu_tx_willuse_space(dmu_tx_t *tx, int64_t delta);
    151 void dmu_tx_dirty_buf(dmu_tx_t *tx, struct dmu_buf_impl *db);
    152 int dmu_tx_holds(dmu_tx_t *tx, uint64_t object);
    153 void dmu_tx_hold_space(dmu_tx_t *tx, uint64_t space);
    154 
    155 #ifdef ZFS_DEBUG
    156 #define	DMU_TX_DIRTY_BUF(tx, db)	dmu_tx_dirty_buf(tx, db)
    157 #else
    158 #define	DMU_TX_DIRTY_BUF(tx, db)
    159 #endif
    160 
    161 #ifdef	__cplusplus
    162 }
    163 #endif
    164 
    165 #endif	/* _SYS_DMU_TX_H */
    166