zfs_znode.c revision 4a1f0cc97e50e029e40b6055fa68f89c9ae6bb38
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
6166ad1cf6916c6ae280ad0d6d157b6024b89611ek * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
75c7619736838143dd41b3c5c9d7adec4683488fpeteh/* Portions Copyright 2007 Jeremy Teo */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif /* _KERNEL */
55434c770c89aa1b84474f2559a106803511aba0ek * Define ZNODE_STATS to turn on statistic gathering. By default, it is only
55434c770c89aa1b84474f2559a106803511aba0ek * turned on when DEBUG is also defined.
55434c770c89aa1b84474f2559a106803511aba0ek#endif /* DEBUG */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif /* ZNODE_STATS */
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee#define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1))
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Functions needed for userland (ie: libzpool) are not put under
fa9e4066f08beec538e775443c5be79dd423fcabahrens * #ifdef_KERNEL; the rest of the functions have dependencies
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (such as VFS logic) that will not compile easily in userland.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Needed to close a small window in zfs_znode_move() that allows the zfsvfs to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * be freed before it can be safely accessed.
af2c4821c0a23e873f2a63bca4145080aa2183e3maybee/*ARGSUSED*/
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * We should never drop all dbuf refs without first clearing
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * the eviction callback.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_znode_cache_constructor(void *buf, void *arg, int kmflags)
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens mutex_init(&zp->z_range_lock, NULL, MUTEX_DEFAULT, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic struct {
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif /* ZNODE_STATS */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Copy fields. */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Swap vnodes. */
fa9e4066f08beec538e775443c5be79dd423fcabahrens ozp->z_vnode = vp; /* let destructor free the overwritten vnode */
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(ozp->z_dirlocks == NULL); /* znode not in use */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Since this is just an idle znode and kmem is already dealing with
fa9e4066f08beec538e775443c5be79dd423fcabahrens * memory pressure, release any cached ACL.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Update back pointers. */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) dmu_buf_update_user(nzp->z_dbuf, ozp, nzp, &nzp->z_phys,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Invalidate the original znode by clearing fields that provide a
fa9e4066f08beec538e775443c5be79dd423fcabahrens * pointer back to the znode. Set the low bit of the vfs pointer to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ensure that zfs_znode_move() recognizes the znode as invalid in any
fa9e4066f08beec538e775443c5be79dd423fcabahrens * subsequent callback.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_znode_move(void *buf, void *newbuf, size_t size, void *arg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The znode is on the file system's list of known znodes if the vfs
fa9e4066f08beec538e775443c5be79dd423fcabahrens * pointer is valid. We set the low bit of the vfs pointer when freeing
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the znode to invalidate it, and the memory patterns written by kmem
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (baddcafe and deadbeef) set at least one of the two low bits. A newly
fa9e4066f08beec538e775443c5be79dd423fcabahrens * created znode sets the vfs pointer last of all to indicate that the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * znode is known and in a valid state to be moved by this function.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Close a small window in which it's possible that the filesystem could
fa9e4066f08beec538e775443c5be79dd423fcabahrens * be unmounted and freed, and zfsvfs, though valid in the previous
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * statement, could point to unrelated memory by the time we try to
de8267e0f723ed2c38ea9def92d465f69a300f56timh * prevent the filesystem from being unmounted.
fa9e4066f08beec538e775443c5be79dd423fcabahrens ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the znode is still valid, then so is the file system. We know that
de8267e0f723ed2c38ea9def92d465f69a300f56timh * no valid file system can be freed while we hold zfsvfs_lock, so we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * can safely ensure that the filesystem is not and will not be
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * unmounted. The next statement is equivalent to ZFS_ENTER().
fa9e4066f08beec538e775443c5be79dd423fcabahrens rrw_enter(&zfsvfs->z_teardown_lock, RW_READER, FTAG);
de8267e0f723ed2c38ea9def92d465f69a300f56timh * Recheck the vfs pointer in case the znode was removed just before
de8267e0f723ed2c38ea9def92d465f69a300f56timh * acquiring the lock.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck2);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * At this point we know that as long as we hold z_znodes_lock, the
e7437265dc2a4920c197ed4337665539d358b22cahrens * znode cannot be freed and fields within the znode can be safely
fa9e4066f08beec538e775443c5be79dd423fcabahrens * accessed. Now, prevent a race with zfs_zget().
de8267e0f723ed2c38ea9def92d465f69a300f56timh /* Only move znodes that are referenced _only_ by the DNLC. */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * The znode is known and in a valid state to move. We're holding the
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens * locks needed to execute the critical section.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock list_link_replace(&ozp->z_link_node, &nzp->z_link_node);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Initialize zcache
c25056de36a33f2a76f79dcf64593f731d258013gw * Cleanup vfs & vnode ops
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Cleanup zcache
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * Remove vfs ops
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * Remove vnode ops
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarksextern const fs_operation_def_t zfs_dvnodeops_template[];
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarksextern const fs_operation_def_t zfs_fvnodeops_template[];
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarksextern const fs_operation_def_t zfs_xdvnodeops_template[];
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarksextern const fs_operation_def_t zfs_symvnodeops_template[];
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarksextern const fs_operation_def_t zfs_evnodeops_template[];
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarksextern const fs_operation_def_t zfs_sharevnodeops_template[];
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * zfs_dvnodeops can be set if mod_remove() calls mod_installfs()
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * due to a failure to remove the the 2nd modlinkage (zfs_modldrv).
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * In this case we just return as the ops vectors are already set up.
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens return (0);
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_dvnodeops_template,
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee error = vn_make_ops(MNTTYPE_ZFS, zfs_fvnodeops_template,
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_symvnodeops_template,
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_xdvnodeops_template,
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_evnodeops_template,
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens error = vn_make_ops(MNTTYPE_ZFS, zfs_sharevnodeops_template,
893a6d32980d24be1349478f44169009d4801c25ahrens VERIFY(0 == zfs_acl_ids_create(sharezp, IS_ROOT_NODE, &vattr,
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(!vn_in_dnlc(ZTOV(sharezp))); /* not valid to move */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * define a couple of values we need available
fa9e4066f08beec538e775443c5be79dd423fcabahrens * for both 64 and 32 bit environments.
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * Create special expldev for ZFS private use.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Can't use standard expldev since it doesn't do
fa9e4066f08beec538e775443c5be79dd423fcabahrens * what we want. The standard expldev() takes a
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dev32_t in LP64 and expands it to a long dev_t.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We need an interface that takes a dev32_t in ILP32
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and expands it to a long dev_t.
fa9e4066f08beec538e775443c5be79dd423fcabahrens major_t major = (major_t)dev >> NBITSMINOR32 & MAXMAJ32;
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Special cmpldev for ZFS private use.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Can't use standard cmpldev since it takes
fa9e4066f08beec538e775443c5be79dd423fcabahrens * a long dev_t and compresses it to dev32_t in
fa9e4066f08beec538e775443c5be79dd423fcabahrens * LP64. We need to do a compaction of a long dev_t
fa9e4066f08beec538e775443c5be79dd423fcabahrens * to a dev32_t in ILP32.
fa9e4066f08beec538e775443c5be79dd423fcabahrens major_t major = (major_t)(dev >> NBITSMINOR64) & MAXMAJ64;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwzfs_znode_dmu_init(zfsvfs_t *zfsvfs, znode_t *zp, dmu_buf_t *db)
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs) || (zfsvfs == zp->z_zfsvfs));
fa9e4066f08beec538e775443c5be79dd423fcabahrens nzp = dmu_buf_set_user_ie(db, zp, &zp->z_phys, znode_evict_error);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * there should be no
fa9e4066f08beec538e775443c5be79dd423fcabahrens * concurrent zgets on this object.
fa9e4066f08beec538e775443c5be79dd423fcabahrens panic("existing znode %p for dbuf %p", (void *)nzp, (void *)db);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Slap on VROOT if we are the root znode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp->z_zfsvfs, zp->z_id)) ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens RW_WRITE_HELD(&zp->z_zfsvfs->z_teardown_inactive_lock));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw VERIFY(zp == dmu_buf_update_user(db, zp, NULL, NULL, NULL));
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * 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, int blksz)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Defer setting z_zfsvfs until the znode is ready to be a candidate for
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the zfs_znode_move() callback.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*FALLTHROUGH*/
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * Everything else must be valid before assigning z_zfsvfs makes the
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * znode eligible for zfs_znode_move().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Create a new DMU object to hold a zfs znode.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * IN: dzp - parent directory for new znode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * vap - file attributes for new znode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * tx - dmu transaction id for zap operations
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * cr - credentials of caller
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * flag - flags:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * IS_ROOT_NODE - new object will be root
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * IS_XATTR - new object is an attribute
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * bonuslen - length of bonus buffer
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * setaclp - File/Dir initial ACL
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fuidp - Tracks fuid allocation.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * OUT: zpp - allocated znode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwzfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint_t flag, znode_t **zpp, int bonuslen, zfs_acl_ids_t *acl_ids)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ASSERT(vap && (vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Create a new DMU object.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * There's currently no mechanism for pre-reading the blocks that will
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * be to needed allocate a new object, so we accept the small chance
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * that there will be an i/o error and we will fail one of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * assertions below.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock 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;
f18faf3f3e5def85fdfff681617d227703ace2adek * If we are creating the root node, the "parent" we
f18faf3f3e5def85fdfff681617d227703ace2adek * passed in is the znode for the root.
f18faf3f3e5def85fdfff681617d227703ace2adek VERIFY(0 == zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx));
fa9e4066f08beec538e775443c5be79dd423fcabahrens ZFS_TIME_ENCODE(&xoap->xoa_createtime, zp->z_phys->zp_crtime);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ZFS_ATTR_SET(zp, ZFS_IMMUTABLE, xoap->xoa_immutable);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ZFS_ATTR_SET(zp, ZFS_APPENDONLY, xoap->xoa_appendonly);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ZFS_ATTR_SET(zp, ZFS_AV_MODIFIED, xoap->xoa_av_modified);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) memcpy(zp->z_phys + 1, xoap->xoa_av_scanstamp,
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Since we do immediate eviction of the z_dbuf, we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * should never find a dbuf with a znode that doesn't
fa9e4066f08beec538e775443c5be79dd423fcabahrens * know about the dbuf.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Not found create new znode/vnode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * but only if file exists.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * There is a small window where zfs_vget() could
fa9e4066f08beec538e775443c5be79dd423fcabahrens * find this object while a file create is still in
fa9e4066f08beec538e775443c5be79dd423fcabahrens * progress. Since a gen number can never be zero
fa9e4066f08beec538e775443c5be79dd423fcabahrens * we will check that to determine if its an allocated
fa9e4066f08beec538e775443c5be79dd423fcabahrens zp = zfs_znode_alloc(zfsvfs, db, doi.doi_data_block_size);
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (((znode_phys_t *)db->db_data)->zp_gen != zp->z_gen) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin uint64_t acl_obj = zp->z_phys->zp_acl.z_acl_extern_obj;
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * Don't allow a zfs_zget() while were trying to release this znode
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * If the hold count is greater than zero, somebody has
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * obtained a new reference on this znode while we were
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * processing it here, so we are done. If we still have
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * mapped pages then we are also done, since we don't
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * want to inactivate the znode until the pages get pushed.
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * XXX - if vn_has_cached_data(vp) is true, but count == 0,
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * this seems like it would leave the znode hanging with
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * no chance to go inactive...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this was the last reference to a file with no links,
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * remove the file from the file system.
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybeezfs_time_stamper_locked(znode_t *zp, uint_t flag, dmu_tx_t *tx)
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee zp->z_phys->zp_flags |= (ZFS_ARCHIVE | ZFS_AV_MODIFIED);
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * Update the requested znode timestamps with the current time.
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * If we are in a transaction, then go ahead and mark the znode
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * dirty in the transaction so the timestamps will go to disk.
b19a79ec1a527828a60c4d325ccd8dcbeb2b2e8bperrin * Otherwise, we will get pushed next time the znode is updated
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * in a transaction, or when this znode eventually goes inactive.
c5c6ffa0498b9c8555798756141b4a3061a138c1maybee * Why is this OK?
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * 1 - Only the ACCESS time is ever updated outside of a transaction.
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * 2 - Multiple consecutive updates will be collapsed into a single
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * znode update by the transaction grouping semantics of the DMU.
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybeezfs_time_stamper(znode_t *zp, uint_t flag, dmu_tx_t *tx)
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * Grow the block size for a file.
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * IN: zp - znode of file to free data in.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * size - requested block size
fa9e4066f08beec538e775443c5be79dd423fcabahrens * tx - open transaction.
5730cc9a43c5f11a472d7536ed81facfd10f1e2emaybee * 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)
de8267e0f723ed2c38ea9def92d465f69a300f56timh 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
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * a file, the pages being "thrown away* don't need to be written out.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock/* ARGSUSED */
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_no_putpage(vnode_t *vp, page_t *pp, u_offset_t *offp, size_t *lenp,
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
de8267e0f723ed2c38ea9def92d465f69a300f56timh * Increase the file length
de8267e0f723ed2c38ea9def92d465f69a300f56timh * IN: zp - znode of file to free data in.
de8267e0f723ed2c38ea9def92d465f69a300f56timh * end - new end-of-file
de8267e0f723ed2c38ea9def92d465f69a300f56timh * RETURN: 0 if success
de8267e0f723ed2c38ea9def92d465f69a300f56timh * error code if failure
de8267e0f723ed2c38ea9def92d465f69a300f56timh * We will change zp_size, lock the whole file.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Nothing to do if file already at desired length.
893a6d32980d24be1349478f44169009d4801c25ahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We are growing the file past the current block size.
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Free space in a file.
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * IN: zp - znode of file to free data in.
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * off - start of section to free.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * len - length of section to free.
55434c770c89aa1b84474f2559a106803511aba0ek * RETURN: 0 if success
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * error code if failure
55434c770c89aa1b84474f2559a106803511aba0ek * Lock the range being freed.
55434c770c89aa1b84474f2559a106803511aba0ek * Nothing to do if file already at desired length.
55434c770c89aa1b84474f2559a106803511aba0ek return (0);
55434c770c89aa1b84474f2559a106803511aba0ek error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, off, len);
55434c770c89aa1b84474f2559a106803511aba0ek * Truncate a file
55434c770c89aa1b84474f2559a106803511aba0ek * IN: zp - znode of file to free data in.
55434c770c89aa1b84474f2559a106803511aba0ek * end - new end-of-file.
55434c770c89aa1b84474f2559a106803511aba0ek * RETURN: 0 if success
55434c770c89aa1b84474f2559a106803511aba0ek * error code if failure
55434c770c89aa1b84474f2559a106803511aba0ek * We will change zp_size, lock the whole file.
55434c770c89aa1b84474f2559a106803511aba0ek * Nothing to do if file already at desired length.
e7437265dc2a4920c197ed4337665539d358b22cahrens return (0);
55434c770c89aa1b84474f2559a106803511aba0ek error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, end, -1);
return (error);
int error;
goto log;
return (error);
return (error);
if (len == 0) {
return (error);
log:
if (error) {
goto log;
return (error);
int error;
char *name;
for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
int error;
return (error);
return (EINVAL);
int error;
int is_xattrdir;
&is_xattrdir)) != 0)
if (is_xattrdir) {
if (error != 0)
if (error == 0)
return (error);