dnode.c revision 44ecc5327ab4ce0750dcca2a17e05566bf2812e2
/*
* 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
*/
/*
*/
#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).
*/
}
/* Swap SPILL block if we have one */
}
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
}
void
{
}
void
{
}
static void
{
}
static dnode_t *
{
if (dnp->dn_datablkszsec)
dn->dn_id_flags = 0;
return (dn);
}
static void
{
#ifdef ZFS_DEBUG
int i;
for (i = 0; i < TXG_SIZE; i++) {
}
#endif
if (dn->dn_dirtyctx_firstset) {
}
}
}
void
{
int i;
if (blocksize == 0)
else if (blocksize > SPA_MAXBLOCKSIZE)
else
if (ibs == 0)
for (i = 0; i < TXG_SIZE; i++) {
}
else
dn->dn_dirtyctx = 0;
dn->dn_free_txg = 0;
if (dn->dn_dirtyctx_firstset) {
}
dn->dn_id_flags = 0;
}
void
{
int nblkptr;
/* clean up any unreferenced dbufs */
dn->dn_id_flags = 0;
/* change blocksize */
dnode_block_freed(dn, 0)));
}
nblkptr = 1;
else
}
/* change type */
/* change bonus size and type */
/* fix up the bonus db_size */
}
}
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;
/*
* If you are holding the spa config lock as writer, you shouldn't
* be asking the DMU to do *anything* unless it's the root pool
* which may require us to read from the root filesystem while
* holding some (not all) of the locks as writer.
*/
return (ENOENT);
return (ENOENT);
return (EEXIST);
return (0);
}
return (EINVAL);
}
if (drop_struct_lock)
return (EIO);
if (err) {
return (err);
}
if (children_dnodes == NULL) {
KM_SLEEP);
}
}
}
}
if (dn->dn_free_txg ||
((flag & DNODE_MUST_BE_FREE) &&
}
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);
}
/* read-holding callers must not rely on the lock being continuously held */
void
{
int epbs, new_nlevels;
/*
* if we have a read-lock, check to see if we need to do any work
* before upgrading to a write-lock.
*/
if (have_read) {
return;
}
}
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 (have_read)
}
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:
}
static boolean_t
{
int i;
for (i = 0; i < TXG_SIZE; i++) {
break;
}
return (i < TXG_SIZE);
}
/* return TRUE if this blkid was freed in a recent txg, or FALSE if it wasn't */
{
int i;
if (blkid == DMU_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 (blkid == DMU_SPILL_BLKID)
return (dnode_spill_freed(dn));
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)
}
/*
* This function scans a block at the indicated "level" looking for
* a hole or data (depending on 'flags'). If level > 0, then we are
* scanning an indirect block looking at its pointers. If level == 0,
* then we are looking at a block of dnodes. If we don't find what we
* are looking for in the block, we return ESRCH. Otherwise, return
* with *offset pointing to the beginning (if searching forwards) or
* end (if searching backwards) of the range covered by the block
* pointer we matched on (or dnode).
*
* The basic search algorithm used below by dnode_next_offset() is to
* use this function to search up the block tree (widen the search) until
* we find something (i.e., we don't return ESRCH) and then search back
* down the tree (narrow the search) until we reach our original search
* level.
*/
static int
{
dprintf("probing object %llu offset %llx level %d of %u\n",
error = 0;
} else {
if (error) {
return (error);
if (hole)
return (0);
/*
* This can only happen when we are searching up
* the block tree for data. We don't really need to
* adjust the offset, as we will just end up looking
* at the pointer to this block in its parent, and its
* going to be unallocated, so we will skip over it.
*/
return (ESRCH);
}
if (error) {
return (error);
}
}
/*
* This can only happen when we are searching up the tree
* and these conditions mean that we need to keep climbing.
*/
} else if (lvl == 0) {
span = DNODE_SHIFT;
break;
}
if (i < 0 || i == blkfill)
} else {
minfill = 0;
if (hole)
maxfill--;
else
minfill++;
break;
}
if (inc < 0) {
/* traversing backwards; position offset at the end */
}
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);
}