zfs_znode.c revision d47621a49c68c359358f6630aa45cc320762f51f
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance 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
ac05c741c43aa3e2f9b2f35878d03c299ff80d99Mark Maybee * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
75c7619736838143dd41b3c5c9d7adec4683488fpeteh/* Portions Copyright 2007 Jeremy Teo */
55434c770c89aa1b84474f2559a106803511aba0ek#endif /* _KERNEL */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * Define ZNODE_STATS to turn on statistic gathering. By default, it is only
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * turned on when DEBUG is also defined.
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee#endif /* DEBUG */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee#endif /* ZNODE_STATS */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee#define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1))
55434c770c89aa1b84474f2559a106803511aba0ek * Functions needed for userland (ie: libzpool) are not put under
55434c770c89aa1b84474f2559a106803511aba0ek * #ifdef_KERNEL; the rest of the functions have dependencies
55434c770c89aa1b84474f2559a106803511aba0ek * (such as VFS logic) that will not compile easily in userland.
4e9583b23260dab68308b306795694143381ab0fTom Erickson * Needed to close a small window in zfs_znode_move() that allows the zfsvfs to
4e9583b23260dab68308b306795694143381ab0fTom Erickson * be freed before it can be safely accessed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * We should never drop all dbuf refs without first clearing
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * the eviction callback.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
b5fca8f855054d167d04d3b4de5210c83ed2083ctomeezfs_znode_cache_constructor(void *buf, void *arg, int kmflags)
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin mutex_init(&zp->z_range_lock, NULL, MUTEX_DEFAULT, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
b5fca8f855054d167d04d3b4de5210c83ed2083ctomeestatic struct {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee#endif /* ZNODE_STATS */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* Copy fields. */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* Swap vnodes. */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ozp->z_vnode = vp; /* let destructor free the overwritten vnode */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ASSERT(ozp->z_dirlocks == NULL); /* znode not in use */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* Update back pointers. */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee (void) dmu_buf_update_user(nzp->z_dbuf, ozp, nzp, &nzp->z_phys,
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * Invalidate the original znode by clearing fields that provide a
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * pointer back to the znode. Set the low bit of the vfs pointer to
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * ensure that zfs_znode_move() recognizes the znode as invalid in any
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * subsequent callback.
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee/*ARGSUSED*/
b5fca8f855054d167d04d3b4de5210c83ed2083ctomeezfs_znode_move(void *buf, void *newbuf, size_t size, void *arg)
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * The znode is on the file system's list of known znodes if the vfs
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * pointer is valid. We set the low bit of the vfs pointer when freeing
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * the znode to invalidate it, and the memory patterns written by kmem
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * (baddcafe and deadbeef) set at least one of the two low bits. A newly
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * created znode sets the vfs pointer last of all to indicate that the
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * znode is known and in a valid state to be moved by this function.
4e9583b23260dab68308b306795694143381ab0fTom Erickson * Close a small window in which it's possible that the filesystem could
4e9583b23260dab68308b306795694143381ab0fTom Erickson * be unmounted and freed, and zfsvfs, though valid in the previous
4e9583b23260dab68308b306795694143381ab0fTom Erickson * statement, could point to unrelated memory by the time we try to
4e9583b23260dab68308b306795694143381ab0fTom Erickson * prevent the filesystem from being unmounted.
4e9583b23260dab68308b306795694143381ab0fTom Erickson ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck1);
4e9583b23260dab68308b306795694143381ab0fTom Erickson * If the znode is still valid, then so is the file system. We know that
4e9583b23260dab68308b306795694143381ab0fTom Erickson * no valid file system can be freed while we hold zfsvfs_lock, so we
4e9583b23260dab68308b306795694143381ab0fTom Erickson * can safely ensure that the filesystem is not and will not be
4e9583b23260dab68308b306795694143381ab0fTom Erickson * unmounted. The next statement is equivalent to ZFS_ENTER().
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens rrw_enter(&zfsvfs->z_teardown_lock, RW_READER, FTAG);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_unmounted);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * Recheck the vfs pointer in case the znode was removed just before
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * acquiring the lock.
4e9583b23260dab68308b306795694143381ab0fTom Erickson ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck2);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * At this point we know that as long as we hold z_znodes_lock, the
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * znode cannot be freed and fields within the znode can be safely
a66b2b3504619207b55d222c87bdd9df52832f15Tom Erickson * accessed. Now, prevent a race with zfs_zget().
a66b2b3504619207b55d222c87bdd9df52832f15Tom Erickson if (ZFS_OBJ_HOLD_TRYENTER(zfsvfs, ozp->z_id) == 0) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* Only move znodes that are referenced _only_ by the DNLC. */
a66b2b3504619207b55d222c87bdd9df52832f15Tom Erickson ZNODE_STAT_ADD(znode_move_stats.zms_not_only_dnlc);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * The znode is known and in a valid state to move. We're holding the
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * locks needed to execute the critical section.
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee list_link_replace(&ozp->z_link_node, &nzp->z_link_node);
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[];
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wrightextern const fs_operation_def_t zfs_sharevnodeops_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,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright error = vn_make_ops(MNTTYPE_ZFS, zfs_sharevnodeops_template,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wrightzfs_create_share_dir(zfsvfs_t *zfsvfs, dmu_tx_t *tx)
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright sharezp = kmem_cache_alloc(znode_cache, KM_SLEEP);
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaum VERIFY(0 == zfs_acl_ids_create(sharezp, IS_ROOT_NODE, &vattr,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright zfs_mknode(sharezp, &vattr, tx, kcred, IS_ROOT_NODE,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright ASSERT(!vn_in_dnlc(ZTOV(sharezp))); /* not valid to move */
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * define a couple of values we need available
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * for both 64 and 32 bit environments.
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * Create special expldev for ZFS private use.
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * Can't use standard expldev since it doesn't do
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * what we want. The standard expldev() takes a
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * dev32_t in LP64 and expands it to a long dev_t.
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * We need an interface that takes a dev32_t in ILP32
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * and expands it to a long dev_t.
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks major_t major = (major_t)dev >> NBITSMINOR32 & MAXMAJ32;
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * Special cmpldev for ZFS private use.
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * Can't use standard cmpldev since it takes
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * a long dev_t and compresses it to dev32_t in
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * LP64. We need to do a compaction of a long dev_t
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * to a dev32_t in ILP32.
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks major_t major = (major_t)(dev >> NBITSMINOR64) & MAXMAJ64;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomeezfs_znode_dmu_init(zfsvfs_t *zfsvfs, znode_t *zp, dmu_buf_t *db)
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs) || (zfsvfs == zp->z_zfsvfs));
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee nzp = dmu_buf_set_user_ie(db, zp, &zp->z_phys, znode_evict_error);
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * there should be no
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * concurrent zgets on this object.
903a11ebdc8df157c4700150f41f1f262f4a8ae8rh panic("existing znode %p for dbuf %p", (void *)nzp, (void *)db);
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * Slap on VROOT if we are the root znode
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp->z_zfsvfs, zp->z_id)) ||
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee RW_WRITE_HELD(&zp->z_zfsvfs->z_teardown_inactive_lock));
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee VERIFY(zp == dmu_buf_update_user(db, zp, NULL, NULL, NULL));
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
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrenszfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz)
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * Defer setting z_zfsvfs until the znode is ready to be a candidate for
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * the zfs_znode_move() callback.
7f6e3e7d4ebf3d6d45073854bef004ca26f8e918perrin zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*FALLTHROUGH*/
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if (zp->z_phys->zp_parent == zfsvfs->z_shares_dir)
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * Everything else must be valid before assigning z_zfsvfs makes the
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * znode eligible for zfs_znode_move().
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
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * bonuslen - length of bonus buffer
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * setaclp - File/Dir initial ACL
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fuidp - Tracks fuid allocation.
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * OUT: zpp - allocated znode
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrenszfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaum uint_t flag, znode_t **zpp, int bonuslen, zfs_acl_ids_t *acl_ids)
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(vap && (vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create a new DMU object.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * There's currently no mechanism for pre-reading the blocks that will
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * be to needed allocate a new object, so we accept the small chance
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * that there will be an i/o error and we will fail one of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * assertions below.
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens VERIFY(0 == dmu_bonus_hold(zfsvfs->z_os, obj, NULL, &db));
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);
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * If we are creating the root node, the "parent" we
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * passed in is the znode for the root.
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaum VERIFY(0 == zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ZFS_TIME_ENCODE(&xoap->xoa_createtime, zp->z_phys->zp_crtime);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ZFS_ATTR_SET(zp, ZFS_AV_MODIFIED, xoap->xoa_av_modified);
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * Since we do immediate eviction of the z_dbuf, we
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * should never find a dbuf with a znode that doesn't
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * know about the dbuf.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Not found create new znode/vnode
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens zp = zfs_znode_alloc(zfsvfs, db, doi.doi_data_block_size);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
f18faf3f3e5def85fdfff681617d227703ace2adek if (((znode_phys_t *)db->db_data)->zp_gen != zp->z_gen) {
f18faf3f3e5def85fdfff681617d227703ace2adek return (0);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee uint64_t acl_obj = zp->z_phys->zp_acl.z_acl_extern_obj;
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.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_time_stamper_locked(znode_t *zp, uint_t flag, dmu_tx_t *tx)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw zp->z_phys->zp_flags |= (ZFS_ARCHIVE | ZFS_AV_MODIFIED);
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)
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * Grow the block size for a file.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * IN: zp - znode of file to free data in.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * size - requested block size
fa9e4066f08beec538e775443c5be79dd423fcabahrens * tx - open transaction.
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 * 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 error = dmu_object_set_blocksize(zp->z_zfsvfs->z_os, zp->z_id,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* What blocksize did we actually get? */
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_object_size_from_db(zp->z_dbuf, &zp->z_blksz, &dummy);
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);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Increase the file length
fa9e4066f08beec538e775443c5be79dd423fcabahrens * IN: zp - znode of file to free data in.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * end - new end-of-file
fa9e4066f08beec538e775443c5be79dd423fcabahrens * RETURN: 0 if success
fa9e4066f08beec538e775443c5be79dd423fcabahrens * error code if failure
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * We will change zp_size, lock the whole file.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Nothing to do if file already at desired length.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We are growing the file past the current block size.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee return (0);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Free space in a file.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * IN: zp - znode of file to free data in.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * off - start of section to free.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * len - length of section to free.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * RETURN: 0 if success
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * error code if failure
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybeezfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Lock the range being freed.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Nothing to do if file already at desired length.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee return (0);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, off, len);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Truncate a file
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * IN: zp - znode of file to free data in.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * end - new end-of-file.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * RETURN: 0 if success
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * error code if failure
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * We will change zp_size, lock the whole file.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Nothing to do if file already at desired length.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee return (0);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, end, -1);
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * Clear any mapped pages in the truncated region. This has to
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * happen outside of the transaction to avoid the possibility of
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * a deadlock with someone trying to push a page that we are
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * about to invalidate.
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee if (poff != 0 && (pp = page_lookup(vp, start, SE_SHARED))) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We need to zero a partial page.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Free space in a file
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * IN: zp - znode of file to free data in.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * off - start of range
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * len - end of range (0 => EOF)
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * flag - current file open mode flags.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * log - TRUE if this action should be logged
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * RETURN: 0 if success
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * error code if failure
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybeezfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Check for any locks in the region to be freed.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee uint64_t length = (len ? len : zp->z_phys->zp_size - off);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee if (error = chklock(vp, FWRITE, off, length, flag, NULL))
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee if (len == 0) {
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee zfs_log_truncate(zilog, tx, TX_TRUNCATE, zp, off, len);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee return (0);
de8267e0f723ed2c38ea9def92d465f69a300f56timhzfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * First attempt to create master node.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * In an empty objset, there are no blocks to read and thus
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * there can be no i/o errors (which we assert below).
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = zap_create_claim(os, moid, DMU_OT_MASTER_NODE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Set starting attributes.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_USERSPACE)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens else if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_FUID)
de8267e0f723ed2c38ea9def92d465f69a300f56timh while ((elem = nvlist_next_nvpair(zplprops, elem)) != NULL) {
de8267e0f723ed2c38ea9def92d465f69a300f56timh /* For the moment we expect all zpl props to be uint64_ts */
de8267e0f723ed2c38ea9def92d465f69a300f56timh if (strcmp(name, zfs_prop_to_name(ZFS_PROP_VERSION)) == 0) {
de8267e0f723ed2c38ea9def92d465f69a300f56timh if (strcmp(name, zfs_prop_to_name(ZFS_PROP_NORMALIZE)) == 0)
de8267e0f723ed2c38ea9def92d465f69a300f56timh else if (strcmp(name, zfs_prop_to_name(ZFS_PROP_CASE)) == 0)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens error = zap_update(os, moid, ZPL_VERSION_STR, 8, 1, &version, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create a delete queue.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens obj = zap_create(os, DMU_OT_UNLINKED_SET, DMU_OT_NONE, 0, tx);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens error = zap_add(os, moid, ZFS_UNLINKED_SET, 8, 1, &obj, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create root znode. Create minimal znode/vnode/zfsvfs
fa9e4066f08beec538e775443c5be79dd423fcabahrens * to allow zfs_mknode to work.
de8267e0f723ed2c38ea9def92d465f69a300f56timh * Fold case on file systems that are always or sometimes case
de8267e0f723ed2c38ea9def92d465f69a300f56timh * insensitive.
de8267e0f723ed2c38ea9def92d465f69a300f56timh if (sense == ZFS_CASE_INSENSITIVE || sense == ZFS_CASE_MIXED)
fa9e4066f08beec538e775443c5be79dd423fcabahrens mutex_init(&zfsvfs.z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaum VERIFY(0 == zfs_acl_ids_create(rootzp, IS_ROOT_NODE, &vattr,
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaum zfs_mknode(rootzp, &vattr, tx, cr, IS_ROOT_NODE, &zp, 0, &acl_ids);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ASSERT(!vn_in_dnlc(ZTOV(rootzp))); /* not valid to move */
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens error = zap_add(os, moid, ZFS_ROOT_OBJ, 8, 1, &rootzp->z_id, tx);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright * Create shares directory
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif /* _KERNEL */
55434c770c89aa1b84474f2559a106803511aba0ek * Given an object number, return its parent object number and whether
55434c770c89aa1b84474f2559a106803511aba0ek * or not the object is an extended attribute directory.
55434c770c89aa1b84474f2559a106803511aba0ekzfs_obj_to_pobj(objset_t *osp, uint64_t obj, uint64_t *pobjp, int *is_xattrdir)
55434c770c89aa1b84474f2559a106803511aba0ek return (0);
55434c770c89aa1b84474f2559a106803511aba0ekzfs_obj_to_path(objset_t *osp, uint64_t obj, char *buf, int len)
55434c770c89aa1b84474f2559a106803511aba0ek for (;;) {