usr/src/uts/common/fs/zfs/sys/dbuf.h
author eschrock
Fri, 03 Mar 2006 20:08:16 -0800
changeset 1544 938876158511
parent 896 f5270e6bd04d
child 2391 2fa3fd1db808
permissions -rw-r--r--
PSARC 2006/077 zpool clear PSARC 2006/139 FMA for ZFS 6284889 arc should replace the znode cache 6333006 DMU & DSL should not panic upon I/O error 6333092 concurrent reads to a file not scaling with number of readers 6338081 ZFS/FMA phase 1 6338386 need persistent error log 6341326 i/o error causes arc buf hash table corruption 6341639 zfs backup/restore should compute/verify checksum of backup stream 6348002 out of space due to changing properties 6354724 inaccurate error message from zfs restore 6354872 dmu_sync() blows predictive accounting 6355416 zpool scrubbing consumes all memory, system hung 6363995 df should only load libzfs when it encounters a ZFS filesystem 6366320 zfs backup/restore doesn't like signals 6368892 mount -m support needed for legacy mounts 6368902 boot archive fstat support needed for ZFS Mountroot 6369424 BFU complains when bfu'ing a ZFS root filesystem 6374062 mountroot support needed for ZFS 6376356 dirtying dbuf obj=43 lvl=0 blkid=0 but not tx_held 6378391 unused members of dmu_objset_stats_t 6378392 clean up zfs_cmd_t structure 6378685 buf_init should allocate its hash table more carefully 6378976 ziltest should be a first class citizen 6381086 zdb segfaults if there is a spa deferred-free bplist 6381203 deadlock due to i/o while assigning (tc_lock held) 6381209 freed space is not immediately available 6381344 'zpool clear' 6381345 FAULTED devices should really be UNAVAIL 6381346 import should mark devices as persistently unavailable 6383272 recursive mutex_enter() during log replay with zfs root 6386326 origin property is not displayed 6386354 libzfs does too much in its _init section, calls exit(1) 6386624 zpool should not complain about non-existent devices from libdiskmgt 6386910 spa needs to be i/o error hardened 6387735 need a mechanism to inject faults into ZFS 6387736 internal ZFS utilities should be placed in an ON-private package 6389928 libzfs should ship a lint library 6390609 malformed vdev config panics on zpool_create() 6390677 version number checking makes upgrades challenging 6390713 ztest hangs in zil_suspend() 6391873 metadata compression should be turned back on 6392113 ztest sometimes reports leaked blocks because ZIL isn't resilvered 6393004 minor memory leak in unique_insert()
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: 896
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
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
/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    22
 * Copyright 2006 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_DBUF_H
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#define	_SYS_DBUF_H
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/txg.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/zio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/arc.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/refcount.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#ifdef	__cplusplus
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
extern "C" {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#define	DB_BONUS_BLKID (-1ULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#define	IN_DMU_SYNC ((blkptr_t *)-1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    47
 * define flags for dbuf_read
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#define	DB_RF_MUST_SUCCEED	0
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
#define	DB_RF_CANFAIL		(1 << 1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#define	DB_RF_HAVESTRUCT	(1 << 2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
#define	DB_RF_NOPREFETCH	(1 << 3)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    54
#define	DB_RF_NEVERWAIT		(1 << 4)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
 * The state transition diagram for dbufs looks like:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 *		+----> READ ----+
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 *		|		|
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 *		|		V
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    62
 *  (alloc)-->UNCACHED	     CACHED-->EVICTING-->(free)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
 *		|		^
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
 *		|		|
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
 *		+----> FILL ----+
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
typedef enum dbuf_states {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
	DB_UNCACHED,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	DB_FILL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
	DB_READ,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    71
	DB_CACHED,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    72
	DB_EVICTING
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
} dbuf_states_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
struct objset_impl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
struct dnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
struct dmu_tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
 * level = 0 means the user data
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
 * level = 1 means the single indirect block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
 * etc.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
#define	LIST_LINK_INACTIVE(link) \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
	((link)->list_next == NULL && (link)->list_prev == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
typedef struct dmu_buf_impl {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	 * The following members are immutable, with the exception of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
	 * db.db_data, which is protected by db_mtx.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
	/* the publicly visible structure */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
	dmu_buf_t db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
	/* the objset we belong to */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	struct objset_impl *db_objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	 * the dnode we belong to (NULL when evicted)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	struct dnode *db_dnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	 * our parent buffer; if the dnode points to us directly,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
	 * db_parent == db_dnode->dn_dbuf
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	 * only accessed by sync thread ???
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
	 * (NULL when evicted)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	struct dmu_buf_impl *db_parent;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
	 * link for hash table of all dmu_buf_impl_t's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
	struct dmu_buf_impl *db_hash_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
	/* our block number */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
	uint64_t db_blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	 * Pointer to the blkptr_t which points to us. May be NULL if we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	 * don't have one yet. (NULL when evicted)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
	blkptr_t *db_blkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	 * Our indirection level.  Data buffers have db_level==0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	 * Indirect buffers which point to data buffers have
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	 * db_level==1. etc.  Buffers which contain dnodes have
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
	 * db_level==0, since the dnodes are stored in a file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	uint8_t db_level;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
	/* db_mtx protects the members below */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	kmutex_t db_mtx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
	 * Current state of the buffer
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	dbuf_states_t db_state;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
	 * Refcount accessed by dmu_buf_{hold,rele}.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	 * If nonzero, the buffer can't be destroyed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
	 * Protected by db_mtx.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
	refcount_t db_holds;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
	/* buffer holding our data */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
	arc_buf_t *db_buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
	kcondvar_t db_changed;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
	arc_buf_t *db_data_pending;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
	 * Last time (transaction group) this buffer was dirtied.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
	uint64_t db_dirtied;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   162
	 * If db_dnode != NULL, our link on the owner dnodes's dn_dbufs list.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   163
	 * Protected by its dn_dbufs_mtx.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
	list_node_t db_link;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
	/* Our link on dn_dirty_dbufs[txg] */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
	list_node_t db_dirty_node[TXG_SIZE];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
	uint8_t db_dirtycnt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
	 * Data which is unique to data (leaf) blocks:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
	struct {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
		/* stuff we store for the user (see dmu_buf_set_user) */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
		void *db_user_ptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
		void **db_user_data_ptr_ptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
		dmu_buf_evict_func_t *db_evict_func;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
		uint8_t db_immediate_evict;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
		uint8_t db_freed_in_flight;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
		 * db_data_old[txg&TXG_MASK] is set when we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
		 * dirty the buffer, so that we can retain the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
		 * pointer even if it gets COW'd in a subsequent
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
		 * transaction group.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
		 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
		 * If the buffer is dirty in any txg, it can't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
		 * be destroyed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
		 * XXX Protected by db_mtx and dn_dirty_mtx.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
		 * db_mtx must be held to read db_dirty[], and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
		 * both db_mtx and dn_dirty_mtx must be held to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
		 * modify (dirty or clean). db_mtx must be held
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
		 * before dn_dirty_mtx.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
		 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   198
		void *db_data_old[TXG_SIZE];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
		blkptr_t *db_overridden_by[TXG_SIZE];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
	} db_d;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
} dmu_buf_impl_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
/* Note: the dbuf hash table is exposed only for the mdb module */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
#define	DBUF_MUTEXES 256
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
#define	DBUF_HASH_MUTEX(h, idx) (&(h)->hash_mutexes[(idx) & (DBUF_MUTEXES-1)])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
typedef struct dbuf_hash_table {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
	uint64_t hash_table_mask;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
	dmu_buf_impl_t **hash_table;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
	kmutex_t hash_mutexes[DBUF_MUTEXES];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
} dbuf_hash_table_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
uint64_t dbuf_whichblock(struct dnode *di, uint64_t offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
dmu_buf_impl_t *dbuf_create_tlib(struct dnode *dn, char *data);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   216
dmu_buf_impl_t *dbuf_create_bonus(struct dnode *dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   218
dmu_buf_impl_t *dbuf_hold(struct dnode *dn, uint64_t blkid, void *tag);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
dmu_buf_impl_t *dbuf_hold_level(struct dnode *dn, int level, uint64_t blkid,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
    void *tag);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
int dbuf_hold_impl(struct dnode *dn, uint8_t level, uint64_t blkid, int create,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
    void *tag, dmu_buf_impl_t **dbp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
void dbuf_prefetch(struct dnode *dn, uint64_t blkid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
void dbuf_add_ref(dmu_buf_impl_t *db, void *tag);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
uint64_t dbuf_refcount(dmu_buf_impl_t *db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   229
void dbuf_rele(dmu_buf_impl_t *db, void *tag);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
dmu_buf_impl_t *dbuf_find(struct dnode *dn, uint8_t level, uint64_t blkid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   233
int dbuf_read(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
void dbuf_will_dirty(dmu_buf_impl_t *db, dmu_tx_t *tx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   235
void dmu_buf_will_fill(dmu_buf_t *db, dmu_tx_t *tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
void dbuf_fill_done(dmu_buf_impl_t *db, dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
void dmu_buf_will_fill(dmu_buf_t *db, dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
void dmu_buf_fill_done(dmu_buf_t *db, dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
void dbuf_dirty(dmu_buf_impl_t *db, dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   241
void dbuf_clear(dmu_buf_impl_t *db);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
void dbuf_evict(dmu_buf_impl_t *db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
void dbuf_setdirty(dmu_buf_impl_t *db, dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
void dbuf_sync(dmu_buf_impl_t *db, zio_t *zio, dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
void dbuf_unoverride(dmu_buf_impl_t *db, uint64_t txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
void dbuf_free_range(struct dnode *dn, uint64_t blkid, uint64_t nblks,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
    struct dmu_tx *);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
void dbuf_new_size(dmu_buf_impl_t *db, int size, dmu_tx_t *tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
void dbuf_init(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
void dbuf_fini(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
#ifdef ZFS_DEBUG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
 * There should be a ## between the string literal and fmt, to make it
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 873
diff changeset
   260
 * clear that we're joining two strings together, but gcc does not
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 873
diff changeset
   261
 * support that preprocessor token.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
#define	dprintf_dbuf(dbuf, fmt, ...) do { \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
	char __db_buf[32]; \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
	uint64_t __db_obj = (dbuf)->db.db_object; \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
	if (__db_obj == DMU_META_DNODE_OBJECT) \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
		(void) strcpy(__db_buf, "mdn"); \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
	else \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
		(void) snprintf(__db_buf, sizeof (__db_buf), "%lld", \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
		    (u_longlong_t)__db_obj); \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
	dprintf_ds((dbuf)->db_objset->os_dsl_dataset, \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	    "obj=%s lvl=%u blkid=%lld " fmt, \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	    __db_buf, (dbuf)->db_level, \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	    (u_longlong_t)(dbuf)->db_blkid, __VA_ARGS__); \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
	} \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
_NOTE(CONSTCOND) } while (0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
#define	dprintf_dbuf_bp(db, bp, fmt, ...) do {			\
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 873
diff changeset
   280
	if (zfs_flags & ZFS_DEBUG_DPRINTF) {			\
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 873
diff changeset
   281
	char __blkbuf[BP_SPRINTF_LEN];				\
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 873
diff changeset
   282
	sprintf_blkptr(__blkbuf, BP_SPRINTF_LEN, bp);		\
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
	dprintf_dbuf(db, fmt " %s\n", __VA_ARGS__, __blkbuf);	\
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
	} \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
_NOTE(CONSTCOND) } while (0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
   287
#define	DBUF_VERIFY(db)	dbuf_verify(db)
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
   288
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
#else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
#define	dprintf_dbuf(db, fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
#define	dprintf_dbuf_bp(db, bp, fmt, ...)
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
   293
#define	DBUF_VERIFY(db)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
#ifdef	__cplusplus
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
#endif /* _SYS_DBUF_H */