usr/src/uts/common/fs/zfs/sys/dmu_tx.h
author Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
Tue, 16 Mar 2010 09:43:38 -0600
changeset 11935 538c866aaac6
parent 10612 89423355fa6f
child 13973 4972ab336f54
permissions -rw-r--r--
6716117 ZFS needs native system attribute infrastructure 6516171 zpl symlinks should have their own object type
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 873
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 873
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10612
diff changeset
    22
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#ifndef	_SYS_DMU_TX_H
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#define	_SYS_DMU_TX_H
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/inttypes.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/txg.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/refcount.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#ifdef	__cplusplus
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
extern "C" {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
struct dmu_buf_impl;
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    39
struct dmu_tx_hold;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
struct dnode_link;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
struct dsl_pool;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
struct dnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
struct dsl_dir;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
struct dmu_tx {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
	 * No synchronization is needed because a tx can only be handled
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
	 * by one thread.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
	list_t tx_holds; /* list of dmu_tx_hold_t */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
	objset_t *tx_objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
	struct dsl_dir *tx_dir;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
	struct dsl_pool *tx_pool;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
	uint64_t tx_txg;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 873
diff changeset
    55
	uint64_t tx_lastsnap_txg;
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    56
	uint64_t tx_lasttried_txg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
	txg_handle_t tx_txgh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
	void *tx_tempreserve_cookie;
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    59
	struct dmu_tx_hold *tx_needassign_txh;
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
    60
	list_t tx_callbacks; /* list of dmu_tx_callback_t on this dmu_tx */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
	uint8_t tx_anyobj;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 873
diff changeset
    62
	int tx_err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
#ifdef ZFS_DEBUG
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    64
	uint64_t tx_space_towrite;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    65
	uint64_t tx_space_tofree;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    66
	uint64_t tx_space_tooverwrite;
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 2199
diff changeset
    67
	uint64_t tx_space_tounref;
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    68
	refcount_t tx_space_written;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    69
	refcount_t tx_space_freed;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
enum dmu_tx_hold_type {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	THT_NEWOBJECT,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
	THT_WRITE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	THT_BONUS,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	THT_FREE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	THT_ZAP,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
	THT_SPACE,
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10612
diff changeset
    80
	THT_SPILL,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
	THT_NUMTYPES
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
typedef struct dmu_tx_hold {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    85
	dmu_tx_t *txh_tx;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    86
	list_node_t txh_node;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    87
	struct dnode *txh_dnode;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    88
	uint64_t txh_space_towrite;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    89
	uint64_t txh_space_tofree;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    90
	uint64_t txh_space_tooverwrite;
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 2199
diff changeset
    91
	uint64_t txh_space_tounref;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 5378
diff changeset
    92
	uint64_t txh_memory_tohold;
7016
8b85f8b0129c 6721941 dmu_tx_count_free() does not account for nlevels increasing
maybee
parents: 6992
diff changeset
    93
	uint64_t txh_fudge;
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    94
#ifdef ZFS_DEBUG
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    95
	enum dmu_tx_hold_type txh_type;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    96
	uint64_t txh_arg1;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    97
	uint64_t txh_arg2;
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
    98
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
} dmu_tx_hold_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
   101
typedef struct dmu_tx_callback {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
   102
	list_node_t		dcb_node;    /* linked to tx_callbacks list */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
   103
	dmu_tx_callback_func_t	*dcb_func;   /* caller function pointer */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
   104
	void			*dcb_data;   /* caller private data */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
   105
} dmu_tx_callback_t;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
 * These routines are defined in dmu.h, and are called by the user.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
dmu_tx_t *dmu_tx_create(objset_t *dd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
int dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
void dmu_tx_commit(dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
void dmu_tx_abort(dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
uint64_t dmu_tx_get_txg(dmu_tx_t *tx);
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1544
diff changeset
   115
void dmu_tx_wait(dmu_tx_t *tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
   117
void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func,
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
   118
    void *dcb_data);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
   119
void dmu_tx_do_callbacks(list_t *cb_list, int error);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7016
diff changeset
   120
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
 * These routines are defined in dmu_spa.h, and are called by the SPA.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
extern dmu_tx_t *dmu_tx_create_assigned(struct dsl_pool *dp, uint64_t txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
 * These routines are only called by the DMU.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
 */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2113
diff changeset
   129
dmu_tx_t *dmu_tx_create_dd(dsl_dir_t *dd);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
int dmu_tx_is_syncing(dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
int dmu_tx_private_ok(dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
void dmu_tx_add_new_object(dmu_tx_t *tx, objset_t *os, uint64_t object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
void dmu_tx_willuse_space(dmu_tx_t *tx, int64_t delta);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
void dmu_tx_dirty_buf(dmu_tx_t *tx, struct dmu_buf_impl *db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
int dmu_tx_holds(dmu_tx_t *tx, uint64_t object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
void dmu_tx_hold_space(dmu_tx_t *tx, uint64_t space);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
#ifdef ZFS_DEBUG
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
   139
#define	DMU_TX_DIRTY_BUF(tx, db)	dmu_tx_dirty_buf(tx, db)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
#else
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
   141
#define	DMU_TX_DIRTY_BUF(tx, db)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
#ifdef	__cplusplus
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
#endif	/* _SYS_DMU_TX_H */