zfs_znode.c revision 0e276a64239609b11bfaa358da373a942beb8f45
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Portions Copyright 2007 Jeremy Teo */
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef _KERNEL
#include <sys/sysmacros.h>
#include <sys/resource.h>
#include <sys/u8_textprep.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 "zfs_prop.h"
/*
* 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
/*ARGSUSED*/
static void
{
/*
* We should never drop all dbuf refs without first clearing
* the eviction callback.
*/
}
/*ARGSUSED*/
static int
{
zp->z_dirlocks = 0;
return (0);
}
/*ARGSUSED*/
static void
{
}
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;
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.
*/
else
}
if (error) {
return (error);
(void) printf("Mismatched versions: File system "
"is version %llu on-disk format, which is "
"incompatible with this software version %lld!",
return (ENOTSUP);
}
return (error);
return (error);
return (error);
/*
* Fold case on file systems that are always or sometimes case
* insensitive.
*/
/*
* 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;
if (error)
return (error);
&zfsvfs->z_unlinkedobj);
if (error)
return (error);
/*
* Initialize zget mutex's
*/
for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
if (error) {
/*
* On error, we destroy the mutexes here since it's not
* possible for the caller to determine if the mutexes were
* initialized properly.
*/
for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
return (error);
}
&zfsvfs->z_fuid_obj);
error = 0;
return (0);
}
/*
* 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
{
/*
* there should be no
* concurrent zgets on this object.
*/
/*
* Slap on VROOT if we are the root znode
*/
}
void
{
}
/*
*
* 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 *
{
zp->z_unlinked = 0;
zp->z_atime_dirty = 0;
zp->z_last_itx = 0;
zp->z_sync_cnt = 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);
}
/*
* 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
* bonuslen - length of bonus buffer
* fuidp - Tracks fuid allocation.
*
* OUT: zpp - allocated znode
*
*/
void
{
int err;
} else {
obj = 0;
gethrestime(&now);
}
/*
* Create a new DMU object.
*/
/*
* There's currently no mechanism for pre-reading the blocks that will
* be to needed 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 {
}
}
/*
* 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.
*/
}
if (zfsvfs->z_use_fuids)
}
} else {
}
} else {
}
if (!(flag & IS_ROOT_NODE)) {
} else {
/*
* If we are creating the root node, the "parent" we
* passed in is the znode for the root.
*/
}
}
void
{
}
}
}
}
}
}
}
}
}
}
}
}
sizeof (xoap->xoa_av_scanstamp));
}
}
int
{
int err;
if (err) {
return (err);
}
return (EINVAL);
}
/*
* Since we do immediate eviction of the z_dbuf, we
* should never find a dbuf with a znode that doesn't
* know about the dbuf.
*/
if (zp->z_unlinked) {
} else {
err = 0;
}
return (err);
}
/*
*/
return (0);
}
int
{
int err;
if (err) {
return (err);
}
return (EINVAL);
}
return (EIO);
}
return (0);
}
void
{
}
}
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
{
}
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.
*
* 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);
}
/*
* 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 (0 => to EOF).
* flag - current file open mode flags.
*
* RETURN: 0 if success
* error code if failure
*/
int
{
int error;
return (EPERM);
return (0);
/*
* If we will change zp_size then lock the whole file,
* otherwise just lock the range being freed.
*/
} else {
/* recheck, in case zp_size changed */
/* lost race: file size changed, lock whole file */
}
}
/*
* Nothing to do if file already at desired length.
*/
return (0);
}
/*
* Check for any locks in the region to be freed.
*/
} else if (len == 0) {
}
return (error);
}
}
new_blksz = 0;
/*
* We are growing the file past the current block size.
*/
} else {
}
/*
* If len == 0, we are truncating the file.
*/
}
if (error) {
return (error);
}
if (new_blksz)
if (len == 0)
rlen = -1;
}
if (log) {
}
/*
* 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.
*/
/*
* We need to zero a partial page.
*/
}
}
return (0);
}
void
{
int error;
/*
* 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 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.
*/
}
#endif /* _KERNEL */
/*
* Given an object number, return its parent object number and whether
* or not the object is an extended attribute directory.
*/
static int
{
int error;
return (error);
return (EINVAL);
}
return (0);
}
int
{
int error;
*path = '\0';
for (;;) {
int is_xattrdir;
&is_xattrdir)) != 0)
break;
if (path[0] != '/')
*--path = '/';
break;
}
component[0] = '/';
if (is_xattrdir) {
} else {
if (error != 0)
break;
}
}
if (error == 0)
return (error);
}