dbuf.h revision fbabab8faf7439009737ccefe9d50152b38c26d1
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_DBUF_H
#define _SYS_DBUF_H
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/zfs_context.h>
#include <sys/refcount.h>
#ifdef __cplusplus
extern "C" {
#endif
#define DB_BONUS_BLKID (-1ULL)
/*
* define flags for dbuf_read and friends
*/
#define DB_RF_MUST_SUCCEED 0
/*
* The state transition diagram for dbufs looks like:
*
* +----> READ ----+
* | |
* | V
* (alloc)-->UNCACHED CACHED-->(free)
* | ^
* | |
* +----> FILL ----+
*/
typedef enum dbuf_states {
struct objset_impl;
struct dnode;
struct dmu_tx;
/*
* level = 0 means the user data
* level = 1 means the single indirect block
* etc.
*/
#define LIST_LINK_INACTIVE(link) \
typedef struct dmu_buf_impl {
/*
* The following members are immutable, with the exception of
* db.db_data, which is protected by db_mtx.
*/
/* the publicly visible structure */
/* the objset we belong to */
struct objset_impl *db_objset;
/*
* the dnode we belong to (NULL when evicted)
*/
/*
* our parent buffer; if the dnode points to us directly,
* db_parent == db_dnode->dn_dbuf
* only accessed by sync thread ???
* (NULL when evicted)
*/
struct dmu_buf_impl *db_parent;
/*
* link for hash table of all dmu_buf_impl_t's
*/
struct dmu_buf_impl *db_hash_next;
/* our block number */
/*
* Pointer to the blkptr_t which points to us. May be NULL if we
* don't have one yet. (NULL when evicted)
*/
/*
* Our indirection level. Data buffers have db_level==0.
* Indirect buffers which point to data buffers have
* db_level==1. etc. Buffers which contain dnodes have
* db_level==0, since the dnodes are stored in a file.
*/
/* db_mtx protects the members below */
/*
* Current state of the buffer
*/
/*
* Refcount accessed by dmu_buf_{hold,rele}.
* If nonzero, the buffer can't be destroyed.
* Protected by db_mtx.
*/
/* buffer holding our data */
/*
* Last time (transaction group) this buffer was dirtied.
*/
/*
* If dd_dnode != NULL, our link on the owner dnodes's dn_dbufs list.
* Protected by its dn_mtx.
*/
/* Our link on dn_dirty_dbufs[txg] */
/*
* Data which is unique to data (leaf) blocks:
*/
struct {
/* stuff we store for the user (see dmu_buf_set_user) */
void *db_user_ptr;
void **db_user_data_ptr_ptr;
/*
* db_data_old[txg&TXG_MASK] is set when we
* dirty the buffer, so that we can retain the
* pointer even if it gets COW'd in a subsequent
* transaction group.
*
* If the buffer is dirty in any txg, it can't
* be destroyed.
*/
/*
* XXX Protected by db_mtx and dn_dirty_mtx.
* db_mtx must be held to read db_dirty[], and
* both db_mtx and dn_dirty_mtx must be held to
* modify (dirty or clean). db_mtx must be held
* before dn_dirty_mtx.
*/
} db_d;
/* Note: the dbuf hash table is exposed only for the mdb module */
#define DBUF_MUTEXES 256
typedef struct dbuf_hash_table {
void *tag);
struct dmu_tx *);
void dbuf_init(void);
void dbuf_fini(void);
#ifdef ZFS_DEBUG
/*
* There should be a ## between the string literal and fmt, to make it
* clear that we're joining two strings together, but gcc does not
* support that preprocessor token.
*/
if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
char __db_buf[32]; \
if (__db_obj == DMU_META_DNODE_OBJECT) \
else \
(u_longlong_t)__db_obj); \
"obj=%s lvl=%u blkid=%lld " fmt, \
} \
if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
char __blkbuf[BP_SPRINTF_LEN]; \
} \
#else
#define DBUF_VERIFY(db)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _SYS_DBUF_H */