zfs_znode.c revision 6638ae1dc32acc370fecf2c4ce2e588f1183dd6e
0N/A * The contents of this file are subject to the terms of the 0N/A * Common Development and Distribution License (the "License"). 0N/A * You may not use this file except in compliance with the License. 0N/A * See the License for the specific language governing permissions 0N/A * and limitations under the License. 0N/A * When distributing Covered Code, include this CDDL HEADER in each 0N/A * If applicable, add the following below this CDDL HEADER, with the 0N/A * fields enclosed by brackets "[]" replaced with your own identifying 0N/A * information: Portions Copyright [yyyy] [name of copyright owner] 0N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 0N/A * Use is subject to license terms. 1879N/A/* Portions Copyright 2007 Jeremy Teo */ 3888N/A * Define ZNODE_STATS to turn on statistic gathering. By default, it is only 3888N/A * turned on when DEBUG is also defined. 3888N/A * Functions needed for userland (ie: libzpool) are not put under 3888N/A * #ifdef_KERNEL; the rest of the functions have dependencies 3888N/A * (such as VFS logic) that will not compile easily in userland. 3888N/A * Needed to close a small window in zfs_znode_move() that allows the zfsvfs to 3888N/A * be freed before it can be safely accessed. 3888N/A * We should never drop all dbuf refs without first clearing 0N/A#
endif /* ZNODE_STATS */ 3638N/A * Since this is just an idle znode and kmem is already dealing with 3638N/A * memory pressure, release any cached ACL. 3888N/A /* Update back pointers. */ 0N/A * Invalidate the original znode by clearing fields that provide a 0N/A * pointer back to the znode. Set the low bit of the vfs pointer to 0N/A * ensure that zfs_znode_move() recognizes the znode as invalid in any 0N/A * subsequent callback. 939N/A * The znode is on the file system's list of known znodes if the vfs 0N/A * pointer is valid. We set the low bit of the vfs pointer when freeing 0N/A * the znode to invalidate it, and the memory patterns written by kmem 0N/A * (baddcafe and deadbeef) set at least one of the two low bits. A newly 0N/A * created znode sets the vfs pointer last of all to indicate that the 0N/A * znode is known and in a valid state to be moved by this function. 0N/A * Close a small window in which it's possible that the filesystem could 0N/A * be unmounted and freed, and zfsvfs, though valid in the previous 0N/A * statement, could point to unrelated memory by the time we try to 0N/A * prevent the filesystem from being unmounted. 0N/A * If the znode is still valid, then so is the file system. We know that 0N/A * no valid file system can be freed while we hold zfsvfs_lock, so we 0N/A * can safely ensure that the filesystem is not and will not be 0N/A * unmounted. The next statement is equivalent to ZFS_ENTER(). 0N/A * Recheck the vfs pointer in case the znode was removed just before 0N/A * acquiring the lock. 2062N/A * At this point we know that as long as we hold z_znodes_lock, the 2062N/A * znode cannot be freed and fields within the znode can be safely 2062N/A * accessed. Now, prevent a race with zfs_zget(). 431N/A /* Only move znodes that are referenced _only_ by the DNLC. */ 431N/A * The znode is known and in a valid state to move. We're holding the 431N/A * locks needed to execute the critical section. 973N/A * Cleanup vfs & vnode ops * 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. * define a couple of values we need available * for both 64 and 32 bit environments. * 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. * 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 * concurrent zgets on this object. panic(
"existing znode %p for dbuf %p", (
void *)
nzp, (
void *)
db);
* Slap on VROOT if we are the root znode * 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 * Defer setting z_zfsvfs until the znode is ready to be a candidate for * the zfs_znode_move() callback. * Everything else must be valid before assigning z_zfsvfs makes the * znode eligible for zfs_znode_move(). * 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 * 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 * 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 * 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 parent is an xattr, so am I. * If we are creating the root node, the "parent" we * passed in is the znode for the root. * Since we do immediate eviction of the z_dbuf, we * should never find a dbuf with a znode that doesn't * 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... * If this was the last reference to a file with no links, * remove the file from the file system. * 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. * 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. * Grow the block size for a file. * IN: zp - znode of file to free data in. * size - requested block size * NOTE: this function assumes that the znode is write locked. * 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. /* 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. * Increase the file length * IN: zp - znode of file to free data in. * We will change zp_size, lock the whole file. * Nothing to do if file already at desired length. * We are growing the file past the current block size. * IN: zp - znode of file to free data in. * off - start of section to free. * len - length of section to free. * Lock the range being freed. * Nothing to do if file already at desired length. * IN: zp - znode of file to free data in. * We will change zp_size, lock the whole file. * Nothing to do if file already at desired length. * 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 * We need to zero a partial page. * IN: zp - znode of file to free data in. * len - end of range (0 => EOF) * flag - current file open mode flags. * log - TRUE if this action should be logged * Check for any locks in the region to be freed. * 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). * Set starting attributes. /* For the moment we expect all zpl props to be uint64_ts */ * to allow zfs_mknode to work. * Fold case on file systems that are always or sometimes case * Create shares directory * Given an object number, return its parent object number and whether * or not the object is an extended attribute directory.