zfs_znode.c revision e722410c49fe67cbf0f639cbcc288bd6cbcf7dd1
/*
* 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 (c) 2013 by Delphix. All rights reserved.
*/
/* Portions Copyright 2007 Jeremy Teo */
#ifdef _KERNEL
#include <sys/sysmacros.h>
#include <sys/resource.h>
#include <sys/u8_textprep.h>
#include <sys/dsl_dataset.h>
#include <sys/vfs_opreg.h>
#include <sys/zfs_ioctl.h>
#include <sys/zfs_rlock.h>
#include <sys/zfs_fuid.h>
#endif /* _KERNEL */
#include <sys/refcount.h>
#include <sys/zfs_znode.h>
#include <sys/zfs_stat.h>
#include "zfs_prop.h"
#include "zfs_comutil.h"
/*
* Define ZNODE_STATS to turn on statistic gathering. By default, it is only
* turned on when DEBUG is also defined.
*/
#ifdef DEBUG
#define ZNODE_STATS
#endif /* DEBUG */
#ifdef ZNODE_STATS
#else
#endif /* ZNODE_STATS */
/*
* Functions needed for userland (ie: libzpool) are not put under
* #ifdef_KERNEL; the rest of the functions have dependencies
* (such as VFS logic) that will not compile easily in userland.
*/
#ifdef _KERNEL
/*
* Needed to close a small window in zfs_znode_move() that allows the zfsvfs to
* be freed before it can be safely accessed.
*/
/*ARGSUSED*/
static void
{
/*
* We should never drop all dbuf refs without first clearing
* the eviction callback.
*/
}
/*ARGSUSED*/
static int
{
return (-1);
}
return (0);
}
/*ARGSUSED*/
static void
{
}
#ifdef ZNODE_STATS
static struct {
#endif /* ZNODE_STATS */
static void
{
/* Copy fields. */
/* Swap vnodes. */
/*
* Since this is just an idle znode and kmem is already dealing with
* memory pressure, release any cached ACL.
*/
if (ozp->z_acl_cached) {
}
/*
* Invalidate the original znode by clearing fields that provide a
* pointer back to the znode. Set the low bit of the vfs pointer to
* ensure that zfs_znode_move() recognizes the znode as invalid in any
* subsequent callback.
*/
/*
* Mark the znode.
*/
}
/*ARGSUSED*/
static kmem_cbrc_t
{
/*
* The znode is on the file system's list of known znodes if the vfs
* pointer is valid. We set the low bit of the vfs pointer when freeing
* the znode to invalidate it, and the memory patterns written by kmem
* (baddcafe and deadbeef) set at least one of the two low bits. A newly
* created znode sets the vfs pointer last of all to indicate that the
* znode is known and in a valid state to be moved by this function.
*/
if (!POINTER_IS_VALID(zfsvfs)) {
return (KMEM_CBRC_DONT_KNOW);
}
/*
* Close a small window in which it's possible that the filesystem could
* be unmounted and freed, and zfsvfs, though valid in the previous
* statement, could point to unrelated memory by the time we try to
* prevent the filesystem from being unmounted.
*/
return (KMEM_CBRC_DONT_KNOW);
}
/*
* If the znode is still valid, then so is the file system. We know that
* no valid file system can be freed while we hold zfsvfs_lock, so we
* can safely ensure that the filesystem is not and will not be
* unmounted. The next statement is equivalent to ZFS_ENTER().
*/
if (zfsvfs->z_unmounted) {
return (KMEM_CBRC_DONT_KNOW);
}
/*
* Recheck the vfs pointer in case the znode was removed just before
* acquiring the lock.
*/
return (KMEM_CBRC_DONT_KNOW);
}
/*
* At this point we know that as long as we hold z_znodes_lock, the
* znode cannot be freed and fields within the znode can be safely
* accessed. Now, prevent a race with zfs_zget().
*/
return (KMEM_CBRC_LATER);
}
return (KMEM_CBRC_LATER);
}
/* Only move znodes that are referenced _only_ by the DNLC. */
return (KMEM_CBRC_LATER);
}
/*
* The znode is known and in a valid state to move. We're holding the
* locks needed to execute the critical section.
*/
return (KMEM_CBRC_YES);
}
void
zfs_znode_init(void)
{
/*
* Initialize zcache
*/
sizeof (znode_t), 0, zfs_znode_cache_constructor,
}
void
zfs_znode_fini(void)
{
/*
* 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;
struct vnodeops *zfs_sharevnodeops;
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)
if (zfs_sharevnodeops)
}
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[];
extern const fs_operation_def_t zfs_sharevnodeops_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);
if (error)
return (error);
return (error);
}
int
{
int error;
sharezp->z_unlinked = 0;
sharezp->z_atime_dirty = 0;
return (error);
}
/*
* define a couple of values we need available
* for both 64 and 32 bit environments.
*/
#ifndef NBITSMINOR64
#define NBITSMINOR64 32
#endif
#ifndef MAXMAJ64
#define MAXMAJ64 0xffffffffUL
#endif
#ifndef MAXMIN64
#define MAXMIN64 0xffffffffUL
#endif
/*
* Create special expldev for ZFS private use.
* Can't use standard expldev since it doesn't do
* what we want. The standard expldev() takes a
* dev32_t in LP64 and expands it to a long dev_t.
* We need an interface that takes a dev32_t in ILP32
* and expands it to a long dev_t.
*/
static uint64_t
{
#ifndef _LP64
#else
return (dev);
#endif
}
/*
* Special cmpldev for ZFS private use.
* Can't use standard cmpldev since it takes
* a long dev_t and compresses it to dev32_t in
* LP64. We need to do a compaction of a long dev_t
* to a dev32_t in ILP32.
*/
{
#ifndef _LP64
return (NODEV32);
#else
return (dev);
#endif
}
static void
{
} else {
}
/*
* Slap on VROOT if we are the root znode
*/
}
void
{
zp->z_unlinked ||
}
/*
*
* 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
*/
static znode_t *
{
int count = 0;
/*
* Defer setting z_zfsvfs until the znode is ready to be a candidate for
* the zfs_znode_move() callback.
*/
zp->z_unlinked = 0;
zp->z_atime_dirty = 0;
zp->z_sync_cnt = 0;
return (NULL);
}
case VDIR:
} else {
}
break;
case VBLK:
case VCHR:
{
}
/*FALLTHROUGH*/
case VFIFO:
case VSOCK:
case VDOOR:
break;
case VREG:
} else {
}
break;
case VLNK:
break;
default:
break;
}
/*
* Everything else must be valid before assigning z_zfsvfs makes the
* znode eligible for zfs_znode_move().
*/
return (zp);
}
static uint64_t empty_xattr;
static zfs_acl_phys_t acl_phys;
/*
* 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
* bonuslen - length of bonus buffer
* fuidp - Tracks fuid allocation.
*
* OUT: zpp - allocated znode
*
*/
void
{
uint64_t dzp_pflags = 0;
int err;
int bonuslen;
int cnt = 0;
zfs_acl_locator_cb_t locate = { 0 };
} else {
obj = 0;
gethrestime(&now);
}
/*
* Create a new DMU object.
*/
/*
* There's currently no mechanism for pre-reading the blocks that will
* be needed to allocate a new object, so we accept the small chance
* that there will be an i/o error and we will fail one of the
* assertions below.
*/
} else {
}
} else {
} else {
}
}
/*
* 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) {
} else {
}
/*
* If parent is an xattr, so am I.
*/
if (dzp_pflags & ZFS_XATTR) {
}
if (zfsvfs->z_use_fuids)
else
pflags = 0;
} else {
}
}
/*
* No execs denied will be deterimed when zfs_mode_compute() is called.
*/
} else {
}
} else {
}
/* Now add in all of the "SA" attributes */
&sa_hdl));
/*
*
* order for DMU_OT_ZNODE is critical since it needs to be constructed
* in the old znode_phys_t format. Don't change this ordering
*/
if (obj_type == DMU_OT_ZNODE) {
} else {
}
if (obj_type == DMU_OT_ZNODE) {
&empty_xattr, 8);
}
if (obj_type == DMU_OT_ZNODE ||
}
if (obj_type == DMU_OT_ZNODE) {
sizeof (uint64_t) * 4);
&acl_phys, sizeof (zfs_acl_phys_t));
}
if (!(flag & IS_ROOT_NODE)) {
} else {
/*
* If we are creating the root node, the "parent" we
* passed in is the znode for the root.
*/
}
if (obj_type == DMU_OT_ZNODE ||
}
}
/*
* Update in-core attributes. It is assumed the caller will be doing an
* sa_bulk_update to push the changes out.
*/
void
{
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
int
{
int err;
if (err) {
return (err);
}
}
/*
* Since "SA" does immediate eviction we
* should never find a sa handle that doesn't
* know about the znode.
*/
if (zp->z_unlinked) {
} else {
err = 0;
}
return (err);
}
/*
* but only if file exists.
*
* There is a small window where zfs_vget() could
* find this object while a file create is still in
* progress. This is checked for in zfs_znode_alloc()
*
* if zfs_znode_alloc() fails it will drop the hold on the
* bonus buffer.
*/
} else {
}
return (err);
}
int
{
int err;
int count = 0;
if (zp->z_acl_cached) {
}
if (err) {
return (err);
}
}
/* reload cached values */
}
}
return (0);
}
void
{
if (acl_obj) {
}
}
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.
*/
if (zp->z_unlinked) {
zfs_rmnode(zp);
return;
}
}
void
{
if (zp->z_acl_cached) {
}
}
void
{
gethrestime(&now);
if (have_tx) { /* will sa_bulk_update happen really soon? */
zp->z_atime_dirty = 0;
} else {
}
}
}
}
}
}
/*
* Grow the block size for a file.
*
* IN: zp - znode of file to free data in.
* size - requested block size
* tx - open transaction.
*
* NOTE: this function assumes that the znode is write locked.
*/
void
{
int error;
return;
/*
* 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;
return;
/* What blocksize did we actually get? */
}
/*
* 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);
}
/*
* Increase the file length
*
* IN: zp - znode of file to free data in.
* end - new end-of-file
*
* RETURN: 0 on success, error code on failure
*/
static int
{
int error;
/*
* We will change zp_size, lock the whole file.
*/
/*
* Nothing to do if file already at desired length.
*/
return (0);
}
/*
* We are growing the file past the current block size.
*/
} else {
}
} else {
newblksz = 0;
}
if (error) {
return (error);
}
if (newblksz)
return (0);
}
/*
* Free space in a file.
*
* IN: zp - znode of file to free data in.
* off - start of section to free.
* len - length of section to free.
*
* RETURN: 0 on success, error code on failure
*/
static int
{
int error;
/*
* Lock the range being freed.
*/
/*
* Nothing to do if file already at desired length.
*/
return (0);
}
return (error);
}
/*
* Truncate a file
*
* IN: zp - znode of file to free data in.
* end - new end-of-file.
*
* RETURN: 0 on success, error code on failure
*/
static int
{
int error;
int count = 0;
/*
* We will change zp_size, lock the whole file.
*/
/*
* Nothing to do if file already at desired length.
*/
return (0);
}
if (error) {
return (error);
}
if (error) {
return (error);
}
if (end == 0) {
}
/*
* Clear any mapped pages in the truncated region. This has to
* happen outside of the transaction to avoid the possibility of
* a deadlock with someone trying to push a page that we are
* about to invalidate.
*/
if (vn_has_cached_data(vp)) {
/*
* We need to zero a partial page.
*/
}
}
return (0);
}
/*
* Free space in a file
*
* IN: zp - znode of file to free data in.
* off - start of range
* len - end of range (0 => EOF)
* flag - current file open mode flags.
* log - TRUE if this action should be logged
*
* RETURN: 0 on success, error code on failure
*/
int
{
int count = 0;
int error;
sizeof (mode))) != 0)
return (error);
goto log;
else
return (error);
}
/*
* Check for any locks in the region to be freed.
*/
return (error);
}
if (len == 0) {
} else {
}
return (error);
log:
if (error) {
return (error);
}
return (0);
}
void
{
int error;
int i;
/*
* First attempt to create master node.
*/
/*
* In an empty objset, there are no blocks to read and thus
* there can be no i/o errors (which we assert below).
*/
DMU_OT_NONE, 0, tx);
/*
* Set starting attributes.
*/
/* For the moment we expect all zpl props to be uint64_ts */
char *name;
} else {
}
}
/*
* Create zap object used for SA attribute registration
*/
if (version >= ZPL_VERSION_SA) {
DMU_OT_NONE, 0, tx);
} else {
sa_obj = 0;
}
/*
* Create a delete queue.
*/
/*
* to allow zfs_mknode to work.
*/
rootzp->z_unlinked = 0;
rootzp->z_atime_dirty = 0;
/*
* Fold case on file systems that are always or sometimes case
* insensitive.
*/
for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
/*
* Create shares directory
*/
for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
}
#endif /* _KERNEL */
static int
{
int error;
return (error);
return (error);
}
static int
{
int error;
return (error);
}
if (error != 0) {
return (error);
}
return (0);
}
void
{
}
/*
* Given an object number, return its parent object number and whether
* or not the object is an extended attribute directory.
*/
static int
{
int count = 0;
int error;
return (error);
/*
* When a link is removed its parent pointer is not changed and will
* be invalid. There are two cases where a link is removed but the
* file stays around, when it goes to the delete queue and when there
* are additional links.
*/
if (error != 0)
return (error);
if (error != 0)
return (error);
/*
* Extended attributes can be applied to files, directories, etc.
* Otherwise the parent must be a directory.
*/
return (0);
}
/*
* Given an object number, return some zpl level statistics
*/
static int
zfs_stat_t *sb)
{
int count = 0;
}
static int
{
int error;
*path = '\0';
for (;;) {
int is_xattrdir;
if (prevdb)
&is_xattrdir)) != 0)
break;
if (path[0] != '/')
*--path = '/';
break;
}
component[0] = '/';
if (is_xattrdir) {
} else {
if (error != 0)
break;
}
}
if (error != 0) {
break;
}
}
}
if (error == 0)
return (error);
}
int
{
int error;
if (error != 0)
return (error);
if (error != 0)
return (error);
return (error);
}
int
{
int error;
*path = '\0';
if (error != 0)
return (error);
if (error != 0)
return (error);
if (error != 0) {
return (error);
}
return (error);
}