zfs_znode.c revision 7f6e3e7d4ebf3d6d45073854bef004ca26f8e918
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Common Development and Distribution License, Version 1.0 only
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (the "License"). You may not use this file except in compliance
fa9e4066f08beec538e775443c5be79dd423fcabahrens * with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Note that znodes can be on one of 2 states:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ZCACHE_mru - recently used, currently cached
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ZCACHE_mfu - frequently used, currently cached
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When there are no active references to the znode, they
fa9e4066f08beec538e775443c5be79dd423fcabahrens * are linked onto one of the lists in zcache. These are the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * only znodes that can be evicted.
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct zcache_state {
fa9e4066f08beec538e775443c5be79dd423fcabahrens list_t list; /* linked list of evictable znodes in state */
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t lcnt; /* total number of znodes in the linked list */
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t cnt; /* total number of all znodes in this state */
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* The 2 states: */
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic struct zcache {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* performance stats */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Move the supplied znode to the indicated state. The mutex
fa9e4066f08beec538e775443c5be79dd423fcabahrens * for the znode must be held by the caller.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszcache_change_state(zcache_state_t *new_state, znode_t *zp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* ASSERT(MUTEX_HELD(hash_mtx)); */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Evict znodes from list until we've removed the specified number
fa9e4066f08beec538e775443c5be79dd423fcabahrenszcache_evict_state(zcache_state_t *state, int64_t cnt, zfsvfs_t *zfsvfs)
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (zp = list_tail(&state->list); zp; zp = zp_prev) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* drops z_lock and hash_mtx */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Flush all *evictable* data from the cache.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * NOTE: this will not touch "active" (i.e. referenced) data.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zcache_evict_state(zcache.mru, zcache.mru->lcnt, zfsvfs);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zcache_evict_state(zcache.mfu, zcache.mfu->lcnt, zfsvfs);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we're almost to the current target cache size,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * increment the target cache size
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This routine is called whenever a znode is accessed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This znode is not in the cache.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Add the new znode to the MRU state.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we are using less than 2/3 of our total target
fa9e4066f08beec538e775443c5be79dd423fcabahrens * cache size, bump up the target size for the MRU
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zcache.mru->lcnt + zcache.mfu->lcnt < zcache.c*2/3) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This znode has been "accessed" only once so far,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Move it to the MFU state.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * More than 125ms have passed since we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * instantiated this buffer. Move it to the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * most frequently used state.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This buffer has been accessed more than once.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Keep it in the MFU state.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_znode_cache_constructor(void *buf, void *cdrarg, int kmflags)
fa9e4066f08beec538e775443c5be79dd423fcabahrens mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Initialize zcache
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Cleanup vfs & vnode ops
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Cleanup zcache
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove vfs ops
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove vnode ops
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern const fs_operation_def_t zfs_dvnodeops_template[];
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern const fs_operation_def_t zfs_fvnodeops_template[];
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern const fs_operation_def_t zfs_xdvnodeops_template[];
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern const fs_operation_def_t zfs_symvnodeops_template[];
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern const fs_operation_def_t zfs_evnodeops_template[];
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_dvnodeops can be set if mod_remove() calls mod_installfs()
fa9e4066f08beec538e775443c5be79dd423fcabahrens * due to a failure to remove the the 2nd modlinkage (zfs_modldrv).
fa9e4066f08beec538e775443c5be79dd423fcabahrens * In this case we just return as the ops vectors are already set up.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_dvnodeops_template,
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_fvnodeops_template,
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_symvnodeops_template,
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_xdvnodeops_template,
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_evnodeops_template,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_init_fs - Initialize the zfsvfs struct and the file system
fa9e4066f08beec538e775443c5be79dd423fcabahrens * incore "master" object. Verify version compatibility.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_init_fs(zfsvfs_t *zfsvfs, znode_t **zpp, cred_t *cr)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * XXX - hack to auto-create the pool root filesystem at
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the first attempted mount.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (dmu_object_info(os, MASTER_NODE_OBJ, &doi) == ENOENT) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, 3); /* master node */
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, 1); /* delete queue */
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); /* root node */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zap_lookup(os, MASTER_NODE_OBJ, ZFS_VERSION_OBJ, 8, 1, &version)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens "is version %lld on-disk format, which is "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "incompatible with this software version %lld!",
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The fsid is 64 bits, composed of an 8-bit fs type, which
fa9e4066f08beec538e775443c5be79dd423fcabahrens * separates our fsid from any other filesystem types, and a
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 56-bit objset unique ID. The objset unique ID is unique to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * all objsets open on this system, provided by unique_create().
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The 8-bit fs type must be put in the low bits of fsid[1]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * because that's where other Solaris filesystems put it.
fa9e4066f08beec538e775443c5be79dd423fcabahrens stats = kmem_alloc(sizeof (dmu_objset_stats_t), KM_SLEEP);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT((stats->dds_fsid_guid & ~((1ULL<<56)-1)) == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfsvfs->z_vfs->vfs_fsid.val[0] = stats->dds_fsid_guid;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfsvfs->z_vfs->vfs_fsid.val[1] = ((stats->dds_fsid_guid>>32) << 8) |
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1, &zoid)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create the per mount vop tables.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Initialize zget mutex's
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zap_lookup(os, MASTER_NODE_OBJ, ZFS_DELETE_QUEUE, 8, 1, &zoid)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Initialize delete head structure
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Thread(s) will be started/stopped via
fa9e4066f08beec538e775443c5be79dd423fcabahrens * readonly_changed_cb() depending
fa9e4066f08beec538e775443c5be79dd423fcabahrens * on whether this is rw/ro mount.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Construct a new znode/vnode and intialize.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This does not do a call to dmu_set_user() that is
fa9e4066f08beec538e775443c5be79dd423fcabahrens * up to the caller to do, in case you don't want to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * return the znode
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, uint64_t obj_num, int blksz)
7f6e3e7d4ebf3d6d45073854bef004ca26f8e918perrin zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*FALLTHROUGH*/
fa9e4066f08beec538e775443c5be79dd423fcabahrens nzp = dmu_buf_set_user(db, zp, &zp->z_phys, znode_pageout_func);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * there should be no
fa9e4066f08beec538e775443c5be79dd423fcabahrens * concurrent zgets on this object.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Slap on VROOT if we are the root znode
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create a new DMU object to hold a zfs znode.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * IN: dzp - parent directory for new znode
fa9e4066f08beec538e775443c5be79dd423fcabahrens * vap - file attributes for new znode
fa9e4066f08beec538e775443c5be79dd423fcabahrens * tx - dmu transaction id for zap operations
fa9e4066f08beec538e775443c5be79dd423fcabahrens * cr - credentials of caller
fa9e4066f08beec538e775443c5be79dd423fcabahrens * flag - flags:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * IS_ROOT_NODE - new object will be root
fa9e4066f08beec538e775443c5be79dd423fcabahrens * IS_XATTR - new object is an attribute
fa9e4066f08beec538e775443c5be79dd423fcabahrens * IS_REPLAY - intent log replay
fa9e4066f08beec538e775443c5be79dd423fcabahrens * OUT: oid - ID of created object
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_mknode(znode_t *dzp, vattr_t *vap, uint64_t *oid, dmu_tx_t *tx, cred_t *cr,
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(vap && (vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zfsvfs->z_assign >= TXG_INITIAL) { /* ZIL replay */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create a new DMU object.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Initialize the znode physical data to zero.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this is the root, fix up the half-initialized parent pointer
fa9e4066f08beec538e775443c5be79dd423fcabahrens * to reference the just-allocated physical data area.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If parent is an xattr, so am I.
fa9e4066f08beec538e775443c5be79dd423fcabahrens pzp->zp_links = (flag & (IS_ROOT_NODE | IS_XATTR)) ? 2 : 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens pzp->zp_mode = MAKEIMODE(vap->va_type, vap->va_mode);
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Not found create new znode/vnode
fa9e4066f08beec538e775443c5be79dd423fcabahrens zp = zfs_znode_alloc(zfsvfs, db, obj_num, doi.doi_data_block_size);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Don't allow a zfs_zget() while were trying to release this znode
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the hold count is greater than zero, somebody has
fa9e4066f08beec538e775443c5be79dd423fcabahrens * obtained a new reference on this znode while we were
fa9e4066f08beec538e775443c5be79dd423fcabahrens * processing it here, so we are done. If we still have
fa9e4066f08beec538e775443c5be79dd423fcabahrens * mapped pages then we are also done, since we don't
fa9e4066f08beec538e775443c5be79dd423fcabahrens * want to inactivate the znode until the pages get pushed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * XXX - if vn_has_cached_data(vp) is true, but count == 0,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * this seems like it would leave the znode hanging with
fa9e4066f08beec538e775443c5be79dd423fcabahrens * no chance to go inactive...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this was the last reference to a file with no links,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * remove the file from the file system.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XATTR files are not put on the delete queue */
fa9e4066f08beec538e775443c5be79dd423fcabahrens list_insert_tail(&zfsvfs->z_delete_head.z_znodes, zp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the file system for this znode is no longer mounted,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * evict the znode now, don't put it in the cache.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* put znode on evictable list */
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_time_stamper_locked(znode_t *zp, uint_t flag, dmu_tx_t *tx)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Update the requested znode timestamps with the current time.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we are in a transaction, then go ahead and mark the znode
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dirty in the transaction so the timestamps will go to disk.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Otherwise, we will get pushed next time the znode is updated
fa9e4066f08beec538e775443c5be79dd423fcabahrens * in a transaction, or when this znode eventually goes inactive.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Why is this OK?
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 1 - Only the ACCESS time is ever updated outside of a transaction.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 2 - Multiple consecutive updates will be collapsed into a single
fa9e4066f08beec538e775443c5be79dd423fcabahrens * znode update by the transaction grouping semantics of the DMU.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_time_stamper(znode_t *zp, uint_t flag, dmu_tx_t *tx)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Grow the block size for a file. This may involve migrating data
fa9e4066f08beec538e775443c5be79dd423fcabahrens * from the bonus buffer into a data block (when we grow beyond the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * bonus buffer data area).
fa9e4066f08beec538e775443c5be79dd423fcabahrens * IN: zp - znode of file to free data in.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * size - requested block size
fa9e4066f08beec538e775443c5be79dd423fcabahrens * tx - open transaction.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * RETURN: 0 if success
fa9e4066f08beec538e775443c5be79dd423fcabahrens * error code if failure
fa9e4066f08beec538e775443c5be79dd423fcabahrens * NOTE: this function assumes that the znode is write locked.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the file size is already greater than the current blocksize,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * we will not grow. If there is more than one block in a file,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the blocksize cannot change.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zp->z_blksz && zp->z_phys->zp_size > zp->z_blksz)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = dmu_object_set_blocksize(zp->z_zfsvfs->z_os, zp->z_id,
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* What blocksize did we actually get? */
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_object_size_from_db(zp->z_dbuf, &zp->z_blksz, &dummy);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This is a dummy interface used when pvn_vplist_dirty() should *not*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * be calling back into the fs for a putpage(). E.g.: when truncating
fa9e4066f08beec538e775443c5be79dd423fcabahrens * a file, the pages being "thrown away* don't need to be written out.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_no_putpage(vnode_t *vp, page_t *pp, u_offset_t *offp, size_t *lenp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Free space in a file. Currently, this function only
fa9e4066f08beec538e775443c5be79dd423fcabahrens * supports freeing space at the end of the file.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * IN: zp - znode of file to free data in.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * from - start of section to free.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * len - length of section to free (0 => to EOF).
fa9e4066f08beec538e775443c5be79dd423fcabahrens * flag - current file open mode flags.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * tx - open transaction.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * RETURN: 0 if success
fa9e4066f08beec538e775443c5be79dd423fcabahrens * error code if failure
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_freesp(znode_t *zp, uint64_t from, uint64_t len, int flag, dmu_tx_t *tx,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Nothing to do if file already at desired length.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check for any locks in the region to be freed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (error = chklock(vp, FWRITE, start, 0, flag, NULL))
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We are growing the file past the current block size.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Clear any mapped pages in the truncated region.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (off != 0 && (pp = page_lookup(vp, start, SE_SHARED))) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We need to zero a partial page.
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_free_range(zp->z_zfsvfs->z_os, zp->z_id, from, len, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * First attempt to create master node.
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = zap_create_claim(os, moid, DMU_OT_MASTER_NODE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Set starting attributes.
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = zap_update(os, moid, ZFS_VERSION_OBJ, 8, 1, &version, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create a delete queue.
fa9e4066f08beec538e775443c5be79dd423fcabahrens doid = zap_create(os, DMU_OT_DELETE_QUEUE, DMU_OT_NONE, 0, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = zap_add(os, moid, ZFS_DELETE_QUEUE, 8, 1, &doid, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create root znode. Create minimal znode/vnode/zfsvfs
fa9e4066f08beec538e775443c5be79dd423fcabahrens * to allow zfs_mknode to work.
fa9e4066f08beec538e775443c5be79dd423fcabahrens mutex_init(&zfsvfs.z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_mknode(rootzp, &vattr, &roid, tx, cr, IS_ROOT_NODE, NULL, 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = zap_add(os, moid, ZFS_ROOT_OBJ, 8, 1, &roid, tx);