dnode.c revision 56d55a5391b4507b679f3d8e08cc28fbe2be62b9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2008 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 kmem_cache_t *dnode_cache;
static dnode_phys_t dnode_phys_zero;
int zfs_default_bs = SPA_MINBLOCKSHIFT;
/* ARGSUSED */
static int
{
int i;
for (i = 0; i < TXG_SIZE; i++) {
sizeof (free_range_t),
sizeof (dbuf_dirty_record_t),
}
return (0);
}
/* ARGSUSED */
static void
{
int i;
for (i = 0; i < TXG_SIZE; i++) {
}
}
void
dnode_init(void)
{
sizeof (dnode_t),
}
void
dnode_fini(void)
{
}
#ifdef ZFS_DEBUG
void
{
int drop_struct_lock = FALSE;
if (!(zfs_flags & ZFS_DEBUG_DNODE_VERIFY))
return;
}
int i;
if (dn->dn_datablkshift) {
}
for (i = 0; i < TXG_SIZE; i++) {
}
}
}
if (drop_struct_lock)
}
#endif
void
{
int i;
return;
}
/*
* dn_nblkptr is only one byte, so it's OK to read it in either
* byte order. We can't read dn_bouslen.
*/
/*
* OK to check dn_bonuslen for zero, because it won't matter if
* we have the wrong byte order. This is necessary because the
* dnode dnode is smaller than a regular dnode.
*/
if (dnp->dn_bonuslen != 0) {
/*
* Note that the bonus length calculated here may be
* longer than the actual bonus buffer. This is because
* we always put the bonus buffer after the last block
* pointer (instead of packing it against the end of the
* dnode buffer).
*/
}
}
void
{
int i;
size >>= DNODE_SHIFT;
for (i = 0; i < size; i++) {
buf++;
}
}
static int
{
return (-1);
return (1);
else return (0);
}
void
{
if (newsize == 0)
else
}
static void
{
}
static dnode_t *
{
if (dnp->dn_datablkszsec)
arc_space_consume(sizeof (dnode_t));
return (dn);
}
static void
{
#ifdef ZFS_DEBUG
int i;
for (i = 0; i < TXG_SIZE; i++) {
}
#endif
if (dn->dn_dirtyctx_firstset) {
}
}
arc_space_return(sizeof (dnode_t));
}
void
{
int i;
if (blocksize == 0)
else if (blocksize > SPA_MAXBLOCKSIZE)
else
if (ibs == 0)
for (i = 0; i < TXG_SIZE; i++) {
}
dn->dn_dirtyctx = 0;
dn->dn_free_txg = 0;
if (dn->dn_dirtyctx_firstset) {
}
}
void
{
int i, old_nblkptr;
for (i = 0; i < TXG_SIZE; i++)
/* clean up any unreferenced dbufs */
/*
* XXX I should really have a generation number to tell if we
* need to do this...
*/
/* free all old data */
}
/* change blocksize */
}
if (db)
/* change type */
/* change bonus size and type */
/* XXX - for now, we can't make nblkptr smaller */
/* fix up the bonus db_size if dn_nblkptr has changed */
}
}
void
{
/*
* Wait for final references to the dnode to clear. This can
* only happen if the arc is asyncronously evicting state that
* has a hold on this dnode while we are trying to evict this
* dnode.
*/
delay(1);
}
dnode_t *
{
return (dn);
}
static void
{
int i;
for (i = 0; i < epb; i++) {
int n;
continue;
#ifdef ZFS_DEBUG
/*
* If there are holds on this dnode, then there should
* be holds on the dnode's containing dbuf as well; thus
* it wouldn't be eligable for eviction and this function
* would not have been called.
*/
for (n = 0; n < TXG_SIZE; n++)
#endif
children_dnodes[i] = NULL;
}
}
/*
* errors:
* EINVAL - invalid object number.
* EIO - i/o error.
* succeeds even for free dnodes.
*/
int
{
int drop_struct_lock = FALSE;
int type;
return (EINVAL);
}
if (drop_struct_lock)
return (EIO);
if (err) {
return (err);
}
if (children_dnodes == NULL) {
KM_SLEEP);
}
}
}
}
if (dn->dn_free_txg ||
}
return (0);
}
/*
* Return held dnode if the object is allocated, NULL if not.
*/
int
{
}
/*
* Can only add a reference if there is already at least one
* reference on the dnode. Returns FALSE if unable to add a
* new reference.
*/
{
return (FALSE);
}
return (TRUE);
}
void
{
/* NOTE: the DNODE_DNODE does not have a dn_dbuf */
}
void
{
return;
#ifdef ZFS_DEBUG
/* ASSERT(dn->dn_free_txg == 0 || dn->dn_free_txg >= txg); */
#endif
/*
* If we are already marked dirty, we're done.
*/
return;
}
} else {
}
/*
* The dnode maintains a hold on its containing dbuf as
* long as there are holds on it. Each instantiated child
* dbuf maintaines a hold on the dnode. When the last child
* drops its hold, the dnode will drop its hold on the
* containing dbuf. We add a "dirty hold" here so that the
* dnode will hang around after we finish processing its
* children.
*/
}
void
{
/* we should be the only holder... hopefully */
/* ASSERT3U(refcount_count(&dn->dn_holds), ==, 1); */
return;
}
/*
* If the dnode is already dirty, it needs to be moved from
* the dirty list to the free list.
*/
} else {
}
}
/*
* Try to change the block size for the indicated dnode. This can only
* succeed if there are no blocks allocated or dirty beyond first block
*/
int
{
int err;
if (size == 0)
if (size > SPA_MAXBLOCKSIZE)
else
ibs = 0;
return (0);
/* Check for any allocated blocks beyond the first */
goto fail;
goto fail;
}
}
goto fail;
/* resize the old block */
if (err == 0)
goto fail;
if (ibs) {
}
/* rele after we have fixed the blocksize in the dnode */
if (db)
return (0);
fail:
return (ENOTSUP);
}
void
{
int drop_struct_lock = FALSE;
int epbs, new_nlevels;
}
goto out;
/*
* Compute the number of levels necessary to support the new maxblkid.
*/
new_nlevels = 1;
new_nlevels++;
/* dirty the left indirects */
/* transfer the dirty records to the new indirect */
}
}
}
out:
if (drop_struct_lock)
}
void
{
/* clear this entire range */
/* clear the beginning of this range */
/* clear the end of this range */
/* clear a chunk out of this range */
}
/* there may be no overlap */
}
}
void
{
int epbs;
if (len == -1ULL) {
}
/*
* First, block align the region to free:
*/
goto out;
} else {
/* Freeing the whole block; fast-track this request */
blkid = 0;
nblks = 1;
goto done;
/* Freeing past end-of-data */
goto out;
} else {
/* Freeing part of the block. */
}
}
/* zero out any partial block data at the start of the range */
if (head) {
/* don't dirty if it isn't on disk and isn't dirty */
if (db->db_last_dirty ||
}
}
}
/* If the range was less than one block, we're done */
if (len == 0)
goto out;
/* If the remaining range is past end of file, we're done */
goto out;
if (trunc)
tail = 0;
else
/* zero out any partial block data at the end of the range */
if (tail) {
/* don't dirty if not on disk and not dirty */
if (db->db_last_dirty ||
}
}
}
/* If the range did not include a full block, we are done */
if (len == 0)
goto out;
if (trunc)
nblks += 1;
/*
* Read in and mark all the level-1 indirects dirty,
* so that they will stay in memory until syncing phase.
* Always dirty the first and last indirect to make sure
* we dirty all the partial indirects.
*/
}
if (trunc)
else
}
int err;
break;
if (db) {
}
}
}
done:
/*
* Add this range to the dnode range list.
* We will finish up this free operation in the syncing phase.
*/
{
/* Add new range to dn_ranges */
}
out:
}
/* return TRUE if this blkid was freed in a recent txg, or FALSE if it wasn't */
{
int i;
if (blkid == DB_BONUS_BLKID)
return (FALSE);
/*
* If we're in the process of opening the pool, dp will not be
* set yet, but there shouldn't be anything dirty.
*/
return (FALSE);
if (dn->dn_free_txg)
return (TRUE);
/*
* If dn_datablkshift is not set, then there's only a single
* block, in which case there will never be a free range so it
* won't matter.
*/
for (i = 0; i < TXG_SIZE; i++) {
if (range_found) {
break;
}
if (range_found &&
break;
}
return (i < TXG_SIZE);
}
void
{
(longlong_t)delta);
if (delta > 0) {
} else {
}
} else {
}
}
/*
* Be conservative (ie. OK to write less than this or free more than
* this, but don't write more or free less).
*/
void
{
if (space > 0)
if (ds)
}
static int
{
dprintf("probing object %llu offset %llx level %d of %u\n",
error = 0;
} else {
if (error) {
return (error);
}
if (error) {
return (error);
}
}
} else if (lvl == 0) {
span = DNODE_SHIFT;
if (txg) {
int j;
for (j = 0; j < dnp[i].dn_nblkptr; j++) {
}
}
break;
}
if (i < 0 || i == blkfill)
} else {
minfill = 0;
if (hole)
maxfill--;
else
minfill++;
break;
}
if (i < 0 || i == epb)
}
if (db)
return (error);
}
/*
* Find the next hole, data, or sparse region at or after *offset.
* The value 'blkfill' tells us how many items we expect to find
* in an L0 data block; this value is 1 for normal objects,
* DNODES_PER_BLOCK for the meta dnode, and some fraction of
* DNODES_PER_BLOCK when searching for sparse regions thereof.
*
* Examples:
*
* dnode_next_offset(dn, flags, offset, 1, 1, 0);
* Used in dmu_offset_next().
*
* dnode_next_offset(mdn, flags, offset, 0, DNODES_PER_BLOCK, txg);
* Only finds objects that have new contents since txg (ie.
* bonus buffer changes and content removal are ignored).
* Used in dmu_object_next().
*
* dnode_next_offset(mdn, DNODE_FIND_HOLE, offset, 2, DNODES_PER_BLOCK >> 2, 0);
* Finds the next L2 meta-dnode bp that's at most 1/4 full.
* Used in dmu_object_alloc().
*/
int
{
int error = 0;
if (!(flags & DNODE_FIND_HAVELOCK))
goto out;
}
if (dn->dn_datablkshift == 0) {
if (flags & DNODE_FIND_HOLE)
} else {
}
goto out;
}
break;
}
}
out:
if (!(flags & DNODE_FIND_HAVELOCK))
return (error);
}