dbuf.c revision 34f1851290e1fe5f53e9f4175aa8264618e9125e
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/zfs_context.h>
#include <sys/dmu_impl.h>
#include <sys/dmu_objset.h>
#include <sys/dsl_dataset.h>
#include <sys/dmu_zfetch.h>
static arc_done_func_t dbuf_write_done;
/*
* Global data structures and functions for the dbuf cache.
*/
static kmem_cache_t *dbuf_cache;
/* ARGSUSED */
static int
{
return (0);
}
/* ARGSUSED */
static void
{
}
/*
* dbuf hash table routines
*/
static dbuf_hash_table_t dbuf_hash_table;
static uint64_t dbuf_hash_count;
static uint64_t
{
return (crc);
}
{
dbuf_hash_table_t *h = &dbuf_hash_table;
return (db);
}
}
}
return (NULL);
}
/*
* Insert an entry into the hash table. If there is already an element
* equal to elem in the hash table, then the already existing element
* will be returned and the new element will not be inserted.
* Otherwise returns NULL.
*/
static dmu_buf_impl_t *
{
dbuf_hash_table_t *h = &dbuf_hash_table;
return (dbf);
}
}
}
return (NULL);
}
/*
* Remove an entry from the hash table. This operation will
* fail if there are any existing holds on the db.
*/
static void
{
dbuf_hash_table_t *h = &dbuf_hash_table;
/*
* We musn't hold db_mtx to maintin lock ordering:
* DBUF_HASH_MUTEX > db_mtx.
*/
}
}
void
{
int err;
dbuf_clear(db);
}
static void
{
return;
}
void
dbuf_init(void)
{
dbuf_hash_table_t *h = &dbuf_hash_table;
int i;
/*
* The hash table is big enough to fill all of physical memory
* with an average 64k block size. The table will take up
* pointers).
*/
hsize <<= 1;
sizeof (dmu_buf_impl_t),
for (i = 0; i < DBUF_MUTEXES; i++)
}
void
dbuf_fini(void)
{
dbuf_hash_table_t *h = &dbuf_hash_table;
int i;
for (i = 0; i < DBUF_MUTEXES; i++)
mutex_destroy(&h->hash_mutexes[i]);
}
/*
* Other stuff.
*/
#ifdef ZFS_DEBUG
static void
{
int i;
if (!(zfs_flags & ZFS_DEBUG_DBUF_VERIFY))
return;
} else {
}
} else {
}
/* we can be momentarily larger in dnode_set_blksz() */
}
if (udpp) {
}
for (i = 0; i < TXG_SIZE; i++) {
/*
* it should only be modified in syncing
* context, so make sure we only have
* one copy of the data.
*/
}
}
}
/* verify db->db_blkptr */
/* db is pointed to by the dnode */
/* ASSERT3U(db->db_blkid, <, dn->dn_nblkptr); */
else
} else {
/* db is pointed to by an indirect block */
/*
* dnode_grow_indblksz() can make this fail if we don't
* have the struct_rwlock. XXX indblksz no longer
* grows. safe to do this now?
*/
}
}
}
/*
* If the blkptr isn't set but they have nonzero data,
* it had better be dirty, otherwise we'll lose that
* data when we evict this buffer.
*/
if (db->db_dirtycnt == 0) {
int i;
}
}
}
}
#endif
static void
{
}
}
static void
{
}
{
if (dn->dn_datablkshift) {
} else {
return (0);
}
}
static void
{
/*
* All reads are synchronous, so we must have a hold on the dbuf
*/
/* we were freed in flight; disregard any error */
} else {
}
}
void
{
/* We need the struct_rwlock to prevent db_blkptr from changing. */
/*
* prefetch only data blocks (level 0) -- don't prefetch indirect
* blocks
*/
}
}
return;
}
return;
}
return;
}
else
else
return;
}
/* ZIO_FLAG_CANFAIL callers have to check the parent zio's error */
}
static int
{
int err;
/*
* We don't have to hold the mutex to check db_state because it
* can't be freed while we have a hold on the buffer.
*/
return (0);
if ((flags & DB_RF_HAVESTRUCT) == 0)
if ((flags & DB_RF_HAVESTRUCT) == 0)
if (err)
return (err);
}
(flags & DB_RF_HAVESTRUCT) == 0);
}
return (0);
}
void
{
int err;
}
int
{
}
void
{
int err;
}
static void
{
} else {
}
}
/*
* This is our just-in-time copy function. It makes a copy of
* buffers, that have been modified in a previous transaction
* group, before we modify them in the current active group.
*
* This function is used in two places: when we are dirtying a
* buffer for the first time in a txg, and when we are freeing
* a range in a dnode that includes this buffer.
*
* Note that when we are called from dbuf_free_range() we do
* not put a hold on the buffer, we just traverse the active
* dbuf list for the dnode.
*/
static void
{
/*
* If this buffer is referenced from the current quiescing
* transaction group: either make a copy and reset the reference
* to point to the copy, or (if there a no active holders) just
* null out the current db_data pointer.
*/
/*
* If the quiescing txg is "dirty", then we better not
* be referencing the same buffer from the syncing txg.
*/
} else {
}
return;
}
/*
* If this buffer is referenced from the current syncing
* transaction group: either
* 1 - make a copy and reset the reference, or
* 2 - if there are no holders, just null the current db_data.
*/
/* we can't copy if we have already started a write */
*syncing = arc_buf_alloc(
} else {
}
}
}
void
{
/* free this block */
/* XXX can get silent EIO here */
}
sizeof (blkptr_t));
/* release the already-written buffer */
}
}
void
{
continue;
continue;
/* found a level 0 buffer in the range */
continue;
continue;
}
/* this will be handled in dbuf_read_done() */
continue;
}
/* this will be handled in dbuf_rele() */
continue;
}
/* make a copy of the data if necessary */
/* fill in with appropriate data */
}
}
}
static int
{
/* Don't count meta-objects */
return (FALSE);
/*
* We don't need any locking to protect db_blkptr:
* If it's syncing, then db_dirtied will be set so we'll
* ignore db_blkptr.
*/
/* If we have been dirtied since the last snapshot, its not new */
if (db->db_dirtied)
if (birth_txg)
else
return (TRUE);
}
void
{
/* XXX does *this* func really need the lock? */
return;
/*
* This call to dbuf_will_dirty() with the dn_struct_rwlock held
* is OK, because there can be no other references to the db
* when we are changing its size, so no concurrent DB_FILL can
* be happening.
*/
/* Make a copy of the data if necessary */
/* create the data buffer for the new block */
/* copy old block data to the new block */
/* zero the remainder */
/* ASSERT3U(refcount_count(&db->db_holds), ==, 1); */
/* fix up the dirty info */
}
void
{
int drop_struct_lock = FALSE;
/*
* Shouldn't dirty a regular buffer in syncing context. Private
* objects may be dirtied in syncing context, but only if they
* were already pre-dirtied in open context.
* XXX We may want to prohibit dirtying in syncing context even
* if they did pre-dirty.
*/
/*
* We make this assert for private objects as well, but after we
* check if we're already dirty. They are allowed to re-dirty
* in syncing context.
*/
dn->dn_dirtyctx ==
/* XXX make this true for indirects too? */
/*
* If this buffer is currently part of an "overridden" region,
* we now need to remove it from that region.
*/
}
/*
* Don't set dirtyctx to SYNC if we're just modifying this as we
* initialize the objset.
*/
dn->dn_dirtyctx =
}
/*
* If this buffer is already dirty, we're done.
*/
return;
}
/*
* Only valid if not already dirty.
*/
/*
* We should only be dirtying in syncing context if it's the
* mos, a spa os, or we're initializing the os. However, we are
* allowed to dirty in syncing context provided we already
* dirtied it in open context. Hence we must make this
* assertion only if we're not already dirty.
*/
/*
* Release the data buffer from the cache so that we
* can modify it without impacting possible other users
* of this cached data block. Note that indirect blocks
* and private objects are not released until the syncing
* state (since they are only modified then).
*
* If this buffer is dirty in an old transaction group we need
* to make a copy of it so that the changes we make in this
* transaction group won't leak out when we sync the older txg.
*/
}
}
/*
* We could have been freed_in_flight between the dbuf_noread
* and dbuf_dirty. We win, as though the dbuf_noread() had
* happened after the free.
*/
}
/*
* If writting this buffer will consume a new block on disk,
* then update the accounting.
*/
/*
* This is only a guess -- if the dbuf is dirty
* in a previous txg, we don't know how much
* space it will use on disk yet. We should
* really have the struct_rwlock to access
* db_blkptr, but since this is just a guess,
* it's OK if we get an odd answer.
*/
}
}
/*
* This buffer is now part of this txg
*/
return;
}
}
if (drop_struct_lock)
} else {
if (drop_struct_lock)
}
}
static int
{
/*
* If this buffer is not dirty, we're done.
*/
return (0);
}
/*
* If this buffer is currently held, we cannot undirty
* it, since one of the current holders may be in the
* middle of an update. Note that users of dbuf_undirty()
* should not place a hold on the dbuf before the call.
* XXX - this check assumes we are being called from
* dbuf_free_range(), perhaps we should move it there?
*/
return (0);
}
}
/* XXX would be nice to fix up dn_towrite_space[] */
/* XXX undo db_dirtied? but how? */
/* db->db_dirtied = tx->tx_txg; */
/* make duf_verify() happy */
dbuf_evict(db);
return (1);
}
return (0);
}
void
{
int rf = DB_RF_MUST_SUCCEED;
rf |= DB_RF_HAVESTRUCT;
}
void
{
}
/* ARGSUSED */
void
{
/* we were freed while filling */
/* XXX dbuf_undirty? */
}
}
}
static void
{
}
/*
* If this dbuf is referened from an indirect dbuf,
* decrement the ref count on the indirect dbuf.
*/
/* remove from dn_dbufs */
}
static int
{
nlevels = 1;
else
if (blkid == DB_BONUS_BLKID) {
/* this is the bonus buffer */
return (0);
/* the buffer has no parent yet */
return (ENOENT);
/* this block is referenced from an indirect block */
if (err)
return (err);
return (0);
} else {
/* the block is referenced from the dnode */
return (0);
}
}
static dmu_buf_impl_t *
{
} else {
int blocksize =
}
db->db_dirtied = 0;
db->db_dirtycnt = 0;
/*
* Hold the dn_dbufs_mtx while we get the new dbuf
* in the hash table *and* added to the dbufs list.
* This prevents a possible deadlock with someone
* trying to look up this dbuf before its added to the
* dn_dbufs list.
*/
/* someone else inserted it first */
return (odb);
}
return (db);
}
static int
{
int i;
return (FALSE);
return (FALSE);
#ifdef ZFS_DEBUG
for (i = 0; i < TXG_SIZE; i++) {
}
#endif
/*
* Now we know we want to free it.
* This call must be done last, since it has side effects -
* calling the db_evict_func().
*/
return (TRUE);
}
static void
{
}
void
{
return;
/* dbuf_find() returns with db_mtx held */
/*
* This dbuf is already in the cache. We assume that
* it is already CACHED, or else about to be either
* read or filled.
*/
return;
}
(ARC_NOWAIT | ARC_PREFETCH));
}
}
}
/*
* Returns with db_holds incremented, and db_mtx not held.
* Note: dn_struct_rwlock must be held.
*/
int
{
/* dbuf_find() returns with db_mtx held */
int err;
if (fail_sparse) {
if (err) {
return (err);
}
}
}
/*
* If this buffer is currently syncing out, and we are
* are still referencing it from db_data, we need to make
* a copy of it in case we decide we want to dirty it
* again in this txg.
*/
}
/* NOTE: we can't rele the parent until after we drop the db_mtx */
return (0);
}
{
return (db);
}
{
return (db);
}
{
return (db);
}
void
{
/* dprintf_dbuf(db, "adding ref %p; holds up to %lld\n", tag, holds); */
}
void
{
int need_mutex;
if (need_mutex) {
}
if (holds == 0) {
dbuf_evict(db);
} else {
}
if (need_mutex) {
}
}
void
{
}
{
}
void *
{
}
void *
{
}
void *
{
} else {
}
return (old_user_ptr);
}
void *
{
}
void
{
int blksz;
/*
* To be synced, we must be dirtied. But we
* might have been freed after the dirty.
*/
/* This buffer has been freed since it was dirtied */
/* This buffer was freed and is now being re-filled */
} else {
}
/*
* Don't need a lock on db_dirty (dn_mtx), because it can't
* be modified yet.
*/
/*
* If this buffer is currently "in use" (i.e., there are
* active holds and db_data still references it), then make
* a copy before we start the write so that any modifications
* from the open txg will not leak into this write.
*
* NOTE: this copy does not need to be made for objects only
* modified in the syncing context (e.g. DNONE_DNODE blocks)
* or if there is no actual write involved (bonus blocks).
*/
*data = arc_buf_alloc(
}
/*
* Private object buffers are released here rather
* than in dbuf_dirty() since they are only modified
* in the syncing context and we don't want the
* overhead of making multiple copies of the data.
*/
}
} else {
/*
* This can happen if we dirty and then free
* the level-0 data blocks in the same txg. So
* this indirect remains unchanged.
*/
db->db_dirtied = 0;
return;
}
}
/*
* Simply copy the bonus data into the dnode. It will
* be written out when the dnode is synced (and it will
* be synced, since it must have been dirty for dbuf_sync
* to be called). The bonus data will be byte swapped
* in dnode_byteswap.
*/
/*
* Use dn_phys->dn_bonuslen since db.db_size is the length
* of the bonus buffer in the open transaction rather than
* the syncing transaction.
*/
db->db_dirtied = 0;
return;
/*
* This indirect buffer was marked dirty, but
* never modified (if it had been modified, then
* we would have released the buffer). There is
* no reason to write anything.
*/
db->db_dirtied = 0;
return;
/*
* This buffer was allocated at a time when there was
* no available blkptrs from the dnode, or it was
* inappropriate to hook it in (i.e., nlevels mis-match).
*/
}
} else {
}
/*
* Don't write indirect blocks past EOF.
* We get these when we truncate a file *after* dirtying
* blocks in the truncate range (we undirty the level 0
* blocks in dbuf_free_range(), but not the indirects).
*/
#ifdef ZFS_DEBUG
/*
* Verify that this indirect block is empty.
*/
int i;
for (i = 0; i < (1 << epbs); i++) {
if (!BP_IS_HOLE(&bplist[i])) {
panic("data past EOF: "
"db=%p level=%d id=%llu i=%d\n",
}
}
#endif
return;
}
/*
* We may have read this block after we dirtied it,
* so never released it from the cache.
*/
}
#ifdef ZFS_DEBUG
/*
* We don't need to dnode_setdirty(dn) because if we got
* here then the parent is already dirty.
*/
}
#endif
} else {
/*
* XXX -- we should design a compression algorithm
* that specializes in arrays of bps.
*/
/* XXX - disable compresssion for now */
} else {
/*
* Allow dnode settings to override objset settings,
* except for metadata checksums.
*/
os->os_md_compress);
} else {
os->os_checksum);
os->os_compress);
}
}
#ifdef ZFS_DEBUG
}
#endif
/*
* We can't access db after arc_write, since it could finish
* and be freed, and we have no locks on it.
*/
}
}
struct dbuf_arg {
};
static void
dbuf_do_born(void *arg)
{
}
static void
dbuf_do_kill(void *arg)
{
}
/* ARGSUSED */
static void
{
int i;
db->db_dirtied = 0;
i--, dnp++) {
fill++;
}
} else {
fill = 1;
}
} else {
int epbs =
}
if (BP_IS_HOLE(bp))
continue;
}
}
} else {
}
/* We must do this after we've set the bp's type and level */
}
}
}