zfs_znode.c revision fa9e4066f08beec538e775443c5be79dd423fcab
/*
* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <sys/resource.h>
#include <sys/zfs_ioctl.h>
#include <sys/zfs_znode.h>
/*
* Note that znodes can be on one of 2 states:
* ZCACHE_mru - recently used, currently cached
* ZCACHE_mfu - frequently used, currently cached
* When there are no active references to the znode, they
* are linked onto one of the lists in zcache. These are the
* only znodes that can be evicted.
*/
typedef struct zcache_state {
/* The 2 states: */
static zcache_state_t ZCACHE_mru;
static zcache_state_t ZCACHE_mfu;
static struct zcache {
uint64_t p; /* Target size of mru */
uint64_t c; /* Target size of cache */
/* performance stats */
} zcache;
void zcache_kmem_reclaim(void);
/*
* Move the supplied znode to the indicated state. The mutex
* for the znode must be held by the caller.
*/
static void
{
/* ASSERT(MUTEX_HELD(hash_mtx)); */
if (zp->z_zcache_state) {
}
}
static void
{
zp->z_dbuf_held = 0;
}
/*
* Evict znodes from list until we've removed the specified number
*/
static void
{
int znodes_evicted = 0;
continue;
if (mutex_tryenter(hash_mtx)) {
zp->z_zcache_access = 0;
/* drops z_lock and hash_mtx */
znodes_evicted += 1;
if (znodes_evicted >= cnt)
break;
} else {
}
}
if (znodes_evicted < cnt)
dprintf("only evicted %lld znodes from %x",
}
static void
zcache_adjust(void)
{
if (mrucnt > p)
}
}
/*
* Flush all *evictable* data from the cache.
* NOTE: this will not touch "active" (i.e. referenced) data.
*/
void
{
}
static void
{
/*
* If we're almost to the current target cache size,
* increment the target cache size
*/
}
}
/*
* This routine is called whenever a znode is accessed.
*/
static void
{
/*
* This znode is not in the cache.
* Add the new znode to the MRU state.
*/
zcache_try_grow(1);
/*
* If we are using less than 2/3 of our total target
* cache size, bump up the target size for the MRU
* list.
*/
}
/*
* This znode has been "accessed" only once so far,
* Move it to the MFU state.
*/
/*
* More than 125ms have passed since we
* instantiated this buffer. Move it to the
* most frequently used state.
*/
}
} else {
/*
* This buffer has been accessed more than once.
* Keep it in the MFU state.
*/
}
}
static void
zcache_init(void)
{
zcache.c = 20;
}
static void
zcache_fini(void)
{
}
/*ARGSUSED*/
static void
{
vn_invalid(vp);
}
}
/*ARGSUSED*/
static int
{
zp->z_dbuf_held = 0;
zp->z_dirlocks = 0;
return (0);
}
/*ARGSUSED*/
static void
{
}
void
zfs_znode_init(void)
{
/*
* Initialize zcache
*/
sizeof (znode_t), 0, zfs_znode_cache_constructor,
zcache_init();
}
void
zfs_znode_fini(void)
{
zcache_fini();
/*
* Cleanup vfs & vnode ops
*/
/*
* Cleanup zcache
*/
if (znode_cache)
znode_cache = NULL;
}
struct vnodeops *zfs_dvnodeops;
struct vnodeops *zfs_fvnodeops;
struct vnodeops *zfs_symvnodeops;
struct vnodeops *zfs_xdvnodeops;
struct vnodeops *zfs_evnodeops;
void
{
/*
* Remove vfs ops
*/
(void) vfs_freevfsops_by_type(zfsfstype);
zfsfstype = 0;
/*
* Remove vnode ops
*/
if (zfs_dvnodeops)
if (zfs_fvnodeops)
if (zfs_symvnodeops)
if (zfs_xdvnodeops)
if (zfs_evnodeops)
}
extern const fs_operation_def_t zfs_dvnodeops_template[];
extern const fs_operation_def_t zfs_fvnodeops_template[];
extern const fs_operation_def_t zfs_xdvnodeops_template[];
extern const fs_operation_def_t zfs_symvnodeops_template[];
extern const fs_operation_def_t zfs_evnodeops_template[];
int
{
int error;
/*
* zfs_dvnodeops can be set if mod_remove() calls mod_installfs()
* due to a failure to remove the the 2nd modlinkage (zfs_modldrv).
* In this case we just return as the ops vectors are already set up.
*/
if (zfs_dvnodeops)
return (0);
if (error)
return (error);
if (error)
return (error);
if (error)
return (error);
if (error)
return (error);
return (error);
}
/*
* zfs_init_fs - Initialize the zfsvfs struct and the file system
* incore "master" object. Verify version compatibility.
*/
int
{
extern int zfsfstype;
int i, error;
/*
* XXX - hack to auto-create the pool root filesystem at
* the first attempted mount.
*/
}
return (EINVAL);
} else if (version != ZFS_VERSION) {
(void) printf("Mismatched versions: File system "
"is version %lld on-disk format, which is "
"incompatible with this software version %lld!",
return (ENOTSUP);
}
/*
* The fsid is 64 bits, composed of an 8-bit fs type, which
* separates our fsid from any other filesystem types, and a
* 56-bit objset unique ID. The objset unique ID is unique to
* all objsets open on this system, provided by unique_create().
* The 8-bit fs type must be put in the low bits of fsid[1]
* because that's where other Solaris filesystems put it.
*/
zfsfstype & 0xFF;
return (EINVAL);
}
/*
* Create the per mount vop tables.
*/
/*
* Initialize zget mutex's
*/
for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
if (error)
return (error);
return (EINVAL);
}
/*
* Initialize delete head structure
* readonly_changed_cb() depending
*/
return (0);
}
/*
*
* This does not do a call to dmu_set_user() that is
* up to the caller to do, in case you don't want to
* return the znode
*/
znode_t *
{
zp->z_atime_dirty = 0;
zp->z_dbuf_held = 0;
zp->z_last_itx = 0;
case VDIR:
} else
break;
case VBLK:
case VCHR:
/*FALLTHROUGH*/
case VFIFO:
case VSOCK:
case VDOOR:
break;
case VREG:
break;
case VLNK:
break;
default:
break;
}
return (zp);
}
static void
{
/*
* there should be no
* concurrent zgets on this object.
*/
/*
* Slap on VROOT if we are the root znode
*/
}
zp->z_zcache_access = 0;
}
/*
* Create a new DMU object to hold a zfs znode.
*
* IN: dzp - parent directory for new znode
* vap - file attributes for new znode
* tx - dmu transaction id for zap operations
* cr - credentials of caller
* flag - flags:
* IS_ROOT_NODE - new object will be root
* IS_XATTR - new object is an attribute
* IS_REPLAY - intent log replay
*
* OUT: oid - ID of created object
*
*/
void
{
int err;
} else {
*oid = 0;
gethrestime(&now);
}
/*
* Create a new DMU object.
*/
} else {
}
} else {
} else {
}
}
/*
* Initialize the znode physical data to zero.
*/
/*
* If this is the root, fix up the half-initialized parent pointer
* to reference the just-allocated physical data area.
*/
if (flag & IS_ROOT_NODE) {
}
/*
* If parent is an xattr, so am I.
*/
}
}
} else {
}
} else {
}
if (zpp) {
} else {
}
}
int
{
return (ENOENT);
}
return (EINVAL);
}
return (ENOENT);
} else if (zp->z_dbuf_held) {
} else {
}
}
}
return (0);
}
/*
*/
return (0);
}
void
{
int error;
}
if (zp->z_zcache_state) {
}
zp->z_dbuf_held = 0;
}
void
{
/*
* Don't allow a zfs_zget() while were trying to release this znode
*/
/*
* If the hold count is greater than zero, somebody has
* obtained a new reference on this znode while we were
* processing it here, so we are done. If we still have
* mapped pages then we are also done, since we don't
* want to inactivate the znode until the pages get pushed.
*
* XXX - if vn_has_cached_data(vp) is true, but count == 0,
* this seems like it would leave the znode hanging with
* no chance to go inactive...
*/
return;
}
/*
* If this was the last reference to a file with no links,
* remove the file from the file system.
*/
/* XATTR files are not put on the delete queue */
zfs_rmnode(zp);
} else {
}
return;
}
/*
* If the file system for this znode is no longer mounted,
* evict the znode now, don't put it in the cache.
*/
if (zfsvfs->z_unmounted1) {
return;
}
/* put znode on evictable list */
}
void
{
}
void
{
gethrestime(&now);
if (tx) {
zp->z_atime_dirty = 0;
} else {
}
}
/*
* Update the requested znode timestamps with the current time.
* If we are in a transaction, then go ahead and mark the znode
* dirty in the transaction so the timestamps will go to disk.
* Otherwise, we will get pushed next time the znode is updated
* in a transaction, or when this znode eventually goes inactive.
*
* Why is this OK?
* 1 - Only the ACCESS time is ever updated outside of a transaction.
* 2 - Multiple consecutive updates will be collapsed into a single
* znode update by the transaction grouping semantics of the DMU.
*/
void
{
}
/*
* Grow the block size for a file. This may involve migrating data
* from the bonus buffer into a data block (when we grow beyond the
* bonus buffer data area).
*
* IN: zp - znode of file to free data in.
* size - requested block size
* tx - open transaction.
*
* RETURN: 0 if success
* error code if failure
*
* NOTE: this function assumes that the znode is write locked.
*/
int
{
int error;
return (0);
/*
* If the file size is already greater than the current blocksize,
* we will not grow. If there is more than one block in a file,
* the blocksize cannot change.
*/
return (0);
return (0);
/* What blocksize did we actually get? */
return (0);
}
/*
* This is a dummy interface used when pvn_vplist_dirty() should *not*
* be calling back into the fs for a putpage(). E.g.: when truncating
* a file, the pages being "thrown away* don't need to be written out.
*/
/* ARGSUSED */
static int
{
ASSERT(0);
return (0);
}
/*
* Free space in a file. Currently, this function only
* supports freeing space at the end of the file.
*
* IN: zp - znode of file to free data in.
* from - start of section to free.
* len - length of section to free (0 => to EOF).
* flag - current file open mode flags.
* tx - open transaction.
*
* RETURN: 0 if success
* error code if failure
*/
int
{
int have_grow_lock, error;
/*
* Nothing to do if file already at desired length.
*/
return (0);
}
/*
* Check for any locks in the region to be freed.
*/
else
return (error);
}
/*
* We are growing the file past the current block size.
*/
} else {
}
}
return (0);
if (have_grow_lock)
/*
* Clear any mapped pages in the truncated region.
*/
if (vn_has_cached_data(vp)) {
/*
* We need to zero a partial page.
*/
}
}
if (!have_grow_lock)
if (len == 0)
len = -1;
if (!have_grow_lock)
return (0);
}
void
{
int error;
/*
* First attempt to create master node.
*/
DMU_OT_NONE, 0, tx);
/*
* Set starting attributes.
*/
/*
* Create a delete queue.
*/
/*
* to allow zfs_mknode to work.
*/
rootzp->z_atime_dirty = 0;
rootzp->z_dbuf_held = 0;
}