4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24 * Copyright (c) 2014 Integros [integros.com]
27 /* Portions Copyright 2007 Jeremy Teo */
28 /* Portions Copyright 2011 Martin Matuska <mm@FreeBSD.org> */
31 #include <sys/types.h>
32 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/sysmacros.h>
36 #include <sys/resource.h>
37 #include <sys/mntent.h>
38 #include <sys/u8_textprep.h>
39 #include <sys/dsl_dataset.h>
41 #include <sys/vnode.h>
44 #include <sys/errno.h>
45 #include <sys/unistd.h>
46 #include <sys/atomic.h>
47 #include <sys/zfs_dir.h>
48 #include <sys/zfs_acl.h>
49 #include <sys/zfs_ioctl.h>
50 #include <sys/zfs_rlock.h>
51 #include <sys/zfs_fuid.h>
52 #include <sys/dnode.h>
53 #include <sys/fs/zfs.h>
54 #include <sys/kidmap.h>
58 #include <sys/dmu_objset.h>
59 #include <sys/dmu_tx.h>
60 #include <sys/refcount.h>
63 #include <sys/zfs_znode.h>
65 #include <sys/zfs_sa.h>
66 #include <sys/zfs_stat.h>
67 #include <sys/refcount.h>
70 #include "zfs_comutil.h"
72 /* Used by fstat(1). */
73 SYSCTL_INT(_debug_sizeof, OID_AUTO, znode, CTLFLAG_RD,
74 SYSCTL_NULL_INT_PTR, sizeof(znode_t), "sizeof(znode_t)");
77 * Define ZNODE_STATS to turn on statistic gathering. By default, it is only
78 * turned on when DEBUG is also defined.
85 #define ZNODE_STAT_ADD(stat) ((stat)++)
87 #define ZNODE_STAT_ADD(stat) /* nothing */
88 #endif /* ZNODE_STATS */
91 * Functions needed for userland (ie: libzpool) are not put under
92 * #ifdef_KERNEL; the rest of the functions have dependencies
93 * (such as VFS logic) that will not compile easily in userland.
97 * Needed to close a small window in zfs_znode_move() that allows the zfsvfs to
98 * be freed before it can be safely accessed.
100 krwlock_t zfsvfs_lock;
102 static kmem_cache_t *znode_cache = NULL;
106 znode_evict_error(dmu_buf_t *dbuf, void *user_ptr)
109 * We should never drop all dbuf refs without first clearing
110 * the eviction callback.
112 panic("evicting znode %p\n", user_ptr);
115 extern struct vop_vector zfs_vnodeops;
116 extern struct vop_vector zfs_fifoops;
117 extern struct vop_vector zfs_shareops;
120 zfs_znode_cache_constructor(void *buf, void *arg, int kmflags)
124 POINTER_INVALIDATE(&zp->z_zfsvfs);
126 list_link_init(&zp->z_link_node);
128 mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
130 mutex_init(&zp->z_range_lock, NULL, MUTEX_DEFAULT, NULL);
131 avl_create(&zp->z_range_avl, zfs_range_compare,
132 sizeof (rl_t), offsetof(rl_t, r_node));
134 zp->z_acl_cached = NULL;
142 zfs_znode_cache_destructor(void *buf, void *arg)
146 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
147 ASSERT3P(zp->z_vnode, ==, NULL);
148 ASSERT(!list_link_active(&zp->z_link_node));
149 mutex_destroy(&zp->z_acl_lock);
150 avl_destroy(&zp->z_range_avl);
151 mutex_destroy(&zp->z_range_lock);
153 ASSERT(zp->z_acl_cached == NULL);
158 uint64_t zms_zfsvfs_invalid;
159 uint64_t zms_zfsvfs_recheck1;
160 uint64_t zms_zfsvfs_unmounted;
161 uint64_t zms_zfsvfs_recheck2;
162 uint64_t zms_obj_held;
163 uint64_t zms_vnode_locked;
164 uint64_t zms_not_only_dnlc;
166 #endif /* ZNODE_STATS */
170 zfs_znode_move_impl(znode_t *ozp, znode_t *nzp)
175 nzp->z_zfsvfs = ozp->z_zfsvfs;
179 nzp->z_vnode = ozp->z_vnode;
180 ozp->z_vnode = vp; /* let destructor free the overwritten vnode */
181 ZTOV(ozp)->v_data = ozp;
182 ZTOV(nzp)->v_data = nzp;
184 nzp->z_id = ozp->z_id;
185 ASSERT(ozp->z_dirlocks == NULL); /* znode not in use */
186 ASSERT(avl_numnodes(&ozp->z_range_avl) == 0);
187 nzp->z_unlinked = ozp->z_unlinked;
188 nzp->z_atime_dirty = ozp->z_atime_dirty;
189 nzp->z_zn_prefetch = ozp->z_zn_prefetch;
190 nzp->z_blksz = ozp->z_blksz;
191 nzp->z_seq = ozp->z_seq;
192 nzp->z_mapcnt = ozp->z_mapcnt;
193 nzp->z_gen = ozp->z_gen;
194 nzp->z_sync_cnt = ozp->z_sync_cnt;
195 nzp->z_is_sa = ozp->z_is_sa;
196 nzp->z_sa_hdl = ozp->z_sa_hdl;
197 bcopy(ozp->z_atime, nzp->z_atime, sizeof (uint64_t) * 2);
198 nzp->z_links = ozp->z_links;
199 nzp->z_size = ozp->z_size;
200 nzp->z_pflags = ozp->z_pflags;
201 nzp->z_uid = ozp->z_uid;
202 nzp->z_gid = ozp->z_gid;
203 nzp->z_mode = ozp->z_mode;
206 * Since this is just an idle znode and kmem is already dealing with
207 * memory pressure, release any cached ACL.
209 if (ozp->z_acl_cached) {
210 zfs_acl_free(ozp->z_acl_cached);
211 ozp->z_acl_cached = NULL;
214 sa_set_userp(nzp->z_sa_hdl, nzp);
217 * Invalidate the original znode by clearing fields that provide a
218 * pointer back to the znode. Set the low bit of the vfs pointer to
219 * ensure that zfs_znode_move() recognizes the znode as invalid in any
220 * subsequent callback.
222 ozp->z_sa_hdl = NULL;
223 POINTER_INVALIDATE(&ozp->z_zfsvfs);
229 ozp->z_moved = (uint8_t)-1;
234 zfs_znode_move(void *buf, void *newbuf, size_t size, void *arg)
236 znode_t *ozp = buf, *nzp = newbuf;
241 * The znode is on the file system's list of known znodes if the vfs
242 * pointer is valid. We set the low bit of the vfs pointer when freeing
243 * the znode to invalidate it, and the memory patterns written by kmem
244 * (baddcafe and deadbeef) set at least one of the two low bits. A newly
245 * created znode sets the vfs pointer last of all to indicate that the
246 * znode is known and in a valid state to be moved by this function.
248 zfsvfs = ozp->z_zfsvfs;
249 if (!POINTER_IS_VALID(zfsvfs)) {
250 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_invalid);
251 return (KMEM_CBRC_DONT_KNOW);
255 * Close a small window in which it's possible that the filesystem could
256 * be unmounted and freed, and zfsvfs, though valid in the previous
257 * statement, could point to unrelated memory by the time we try to
258 * prevent the filesystem from being unmounted.
260 rw_enter(&zfsvfs_lock, RW_WRITER);
261 if (zfsvfs != ozp->z_zfsvfs) {
262 rw_exit(&zfsvfs_lock);
263 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck1);
264 return (KMEM_CBRC_DONT_KNOW);
268 * If the znode is still valid, then so is the file system. We know that
269 * no valid file system can be freed while we hold zfsvfs_lock, so we
270 * can safely ensure that the filesystem is not and will not be
271 * unmounted. The next statement is equivalent to ZFS_ENTER().
273 rrm_enter(&zfsvfs->z_teardown_lock, RW_READER, FTAG);
274 if (zfsvfs->z_unmounted) {
276 rw_exit(&zfsvfs_lock);
277 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_unmounted);
278 return (KMEM_CBRC_DONT_KNOW);
280 rw_exit(&zfsvfs_lock);
282 mutex_enter(&zfsvfs->z_znodes_lock);
284 * Recheck the vfs pointer in case the znode was removed just before
285 * acquiring the lock.
287 if (zfsvfs != ozp->z_zfsvfs) {
288 mutex_exit(&zfsvfs->z_znodes_lock);
290 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck2);
291 return (KMEM_CBRC_DONT_KNOW);
295 * At this point we know that as long as we hold z_znodes_lock, the
296 * znode cannot be freed and fields within the znode can be safely
297 * accessed. Now, prevent a race with zfs_zget().
299 if (ZFS_OBJ_HOLD_TRYENTER(zfsvfs, ozp->z_id) == 0) {
300 mutex_exit(&zfsvfs->z_znodes_lock);
302 ZNODE_STAT_ADD(znode_move_stats.zms_obj_held);
303 return (KMEM_CBRC_LATER);
307 if (mutex_tryenter(&vp->v_lock) == 0) {
308 ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
309 mutex_exit(&zfsvfs->z_znodes_lock);
311 ZNODE_STAT_ADD(znode_move_stats.zms_vnode_locked);
312 return (KMEM_CBRC_LATER);
315 /* Only move znodes that are referenced _only_ by the DNLC. */
316 if (vp->v_count != 1 || !vn_in_dnlc(vp)) {
317 mutex_exit(&vp->v_lock);
318 ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
319 mutex_exit(&zfsvfs->z_znodes_lock);
321 ZNODE_STAT_ADD(znode_move_stats.zms_not_only_dnlc);
322 return (KMEM_CBRC_LATER);
326 * The znode is known and in a valid state to move. We're holding the
327 * locks needed to execute the critical section.
329 zfs_znode_move_impl(ozp, nzp);
330 mutex_exit(&vp->v_lock);
331 ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
333 list_link_replace(&ozp->z_link_node, &nzp->z_link_node);
334 mutex_exit(&zfsvfs->z_znodes_lock);
337 return (KMEM_CBRC_YES);
347 rw_init(&zfsvfs_lock, NULL, RW_DEFAULT, NULL);
348 ASSERT(znode_cache == NULL);
349 znode_cache = kmem_cache_create("zfs_znode_cache",
350 sizeof (znode_t), 0, zfs_znode_cache_constructor,
351 zfs_znode_cache_destructor, NULL, NULL, NULL, 0);
352 kmem_cache_set_move(znode_cache, zfs_znode_move);
360 * Cleanup vfs & vnode ops
362 zfs_remove_op_tables();
369 kmem_cache_destroy(znode_cache);
371 rw_destroy(&zfsvfs_lock);
375 struct vnodeops *zfs_dvnodeops;
376 struct vnodeops *zfs_fvnodeops;
377 struct vnodeops *zfs_symvnodeops;
378 struct vnodeops *zfs_xdvnodeops;
379 struct vnodeops *zfs_evnodeops;
380 struct vnodeops *zfs_sharevnodeops;
383 zfs_remove_op_tables()
389 (void) vfs_freevfsops_by_type(zfsfstype);
396 vn_freevnodeops(zfs_dvnodeops);
398 vn_freevnodeops(zfs_fvnodeops);
400 vn_freevnodeops(zfs_symvnodeops);
402 vn_freevnodeops(zfs_xdvnodeops);
404 vn_freevnodeops(zfs_evnodeops);
405 if (zfs_sharevnodeops)
406 vn_freevnodeops(zfs_sharevnodeops);
408 zfs_dvnodeops = NULL;
409 zfs_fvnodeops = NULL;
410 zfs_symvnodeops = NULL;
411 zfs_xdvnodeops = NULL;
412 zfs_evnodeops = NULL;
413 zfs_sharevnodeops = NULL;
416 extern const fs_operation_def_t zfs_dvnodeops_template[];
417 extern const fs_operation_def_t zfs_fvnodeops_template[];
418 extern const fs_operation_def_t zfs_xdvnodeops_template[];
419 extern const fs_operation_def_t zfs_symvnodeops_template[];
420 extern const fs_operation_def_t zfs_evnodeops_template[];
421 extern const fs_operation_def_t zfs_sharevnodeops_template[];
424 zfs_create_op_tables()
429 * zfs_dvnodeops can be set if mod_remove() calls mod_installfs()
430 * due to a failure to remove the the 2nd modlinkage (zfs_modldrv).
431 * In this case we just return as the ops vectors are already set up.
436 error = vn_make_ops(MNTTYPE_ZFS, zfs_dvnodeops_template,
441 error = vn_make_ops(MNTTYPE_ZFS, zfs_fvnodeops_template,
446 error = vn_make_ops(MNTTYPE_ZFS, zfs_symvnodeops_template,
451 error = vn_make_ops(MNTTYPE_ZFS, zfs_xdvnodeops_template,
456 error = vn_make_ops(MNTTYPE_ZFS, zfs_evnodeops_template,
461 error = vn_make_ops(MNTTYPE_ZFS, zfs_sharevnodeops_template,
469 zfs_create_share_dir(zfsvfs_t *zfsvfs, dmu_tx_t *tx)
471 zfs_acl_ids_t acl_ids;
477 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
478 vattr.va_type = VDIR;
479 vattr.va_mode = S_IFDIR|0555;
480 vattr.va_uid = crgetuid(kcred);
481 vattr.va_gid = crgetgid(kcred);
483 sharezp = kmem_cache_alloc(znode_cache, KM_SLEEP);
484 ASSERT(!POINTER_IS_VALID(sharezp->z_zfsvfs));
485 sharezp->z_moved = 0;
486 sharezp->z_unlinked = 0;
487 sharezp->z_atime_dirty = 0;
488 sharezp->z_zfsvfs = zfsvfs;
489 sharezp->z_is_sa = zfsvfs->z_use_sa;
491 VERIFY(0 == zfs_acl_ids_create(sharezp, IS_ROOT_NODE, &vattr,
492 kcred, NULL, &acl_ids));
493 zfs_mknode(sharezp, &vattr, tx, kcred, IS_ROOT_NODE, &zp, &acl_ids);
494 ASSERT3P(zp, ==, sharezp);
495 POINTER_INVALIDATE(&sharezp->z_zfsvfs);
496 error = zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
497 ZFS_SHARES_DIR, 8, 1, &sharezp->z_id, tx);
498 zfsvfs->z_shares_dir = sharezp->z_id;
500 zfs_acl_ids_free(&acl_ids);
501 sa_handle_destroy(sharezp->z_sa_hdl);
502 kmem_cache_free(znode_cache, sharezp);
508 * define a couple of values we need available
509 * for both 64 and 32 bit environments.
512 #define NBITSMINOR64 32
515 #define MAXMAJ64 0xffffffffUL
518 #define MAXMIN64 0xffffffffUL
522 * Create special expldev for ZFS private use.
523 * Can't use standard expldev since it doesn't do
524 * what we want. The standard expldev() takes a
525 * dev32_t in LP64 and expands it to a long dev_t.
526 * We need an interface that takes a dev32_t in ILP32
527 * and expands it to a long dev_t.
530 zfs_expldev(dev_t dev)
532 return (((uint64_t)major(dev) << NBITSMINOR64) | minor(dev));
535 * Special cmpldev for ZFS private use.
536 * Can't use standard cmpldev since it takes
537 * a long dev_t and compresses it to dev32_t in
538 * LP64. We need to do a compaction of a long dev_t
539 * to a dev32_t in ILP32.
542 zfs_cmpldev(uint64_t dev)
544 return (makedev((dev >> NBITSMINOR64), (dev & MAXMIN64)));
548 zfs_znode_sa_init(zfsvfs_t *zfsvfs, znode_t *zp,
549 dmu_buf_t *db, dmu_object_type_t obj_type, sa_handle_t *sa_hdl)
551 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs) || (zfsvfs == zp->z_zfsvfs));
552 ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zfsvfs, zp->z_id)));
554 ASSERT(zp->z_sa_hdl == NULL);
555 ASSERT(zp->z_acl_cached == NULL);
556 if (sa_hdl == NULL) {
557 VERIFY(0 == sa_handle_get_from_db(zfsvfs->z_os, db, zp,
558 SA_HDL_SHARED, &zp->z_sa_hdl));
560 zp->z_sa_hdl = sa_hdl;
561 sa_set_userp(sa_hdl, zp);
564 zp->z_is_sa = (obj_type == DMU_OT_SA) ? B_TRUE : B_FALSE;
567 * Slap on VROOT if we are the root znode unless we are the root
568 * node of a snapshot mounted under .zfs.
570 if (zp->z_id == zfsvfs->z_root && zfsvfs->z_parent == zfsvfs)
571 ZTOV(zp)->v_flag |= VROOT;
577 zfs_znode_dmu_fini(znode_t *zp)
579 ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp->z_zfsvfs, zp->z_id)) ||
581 RW_WRITE_HELD(&zp->z_zfsvfs->z_teardown_inactive_lock));
583 sa_handle_destroy(zp->z_sa_hdl);
588 zfs_vnode_forget(vnode_t *vp)
591 /* copied from insmntque_stddtr */
593 vp->v_op = &dead_vnodeops;
599 * Construct a new znode/vnode and intialize.
601 * This does not do a call to dmu_set_user() that is
602 * up to the caller to do, in case you don't want to
606 zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz,
607 dmu_object_type_t obj_type, sa_handle_t *hdl)
613 sa_bulk_attr_t bulk[9];
617 zp = kmem_cache_alloc(znode_cache, KM_SLEEP);
619 KASSERT(curthread->td_vp_reserv > 0,
620 ("zfs_znode_alloc: getnewvnode without any vnodes reserved"));
621 error = getnewvnode("zfs", zfsvfs->z_parent->z_vfs, &zfs_vnodeops, &vp);
623 kmem_cache_free(znode_cache, zp);
629 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
633 * Defer setting z_zfsvfs until the znode is ready to be a candidate for
634 * the zfs_znode_move() callback.
638 zp->z_atime_dirty = 0;
640 zp->z_id = db->db_object;
642 zp->z_seq = 0x7A4653;
647 zfs_znode_sa_init(zfsvfs, zp, db, obj_type, hdl);
649 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL, &mode, 8);
650 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GEN(zfsvfs), NULL, &zp->z_gen, 8);
651 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
653 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL,
655 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
657 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zfsvfs), NULL, &parent, 8);
658 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
660 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL,
662 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs), NULL,
665 if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count) != 0 || zp->z_gen == 0) {
667 sa_handle_destroy(zp->z_sa_hdl);
668 zfs_vnode_forget(vp);
670 kmem_cache_free(znode_cache, zp);
676 vp->v_type = IFTOVT((mode_t)mode);
678 switch (vp->v_type) {
680 zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */
687 VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(zfsvfs),
688 &rdev, sizeof (rdev)) == 0);
690 vp->v_rdev = zfs_cmpldev(rdev);
699 vp->v_op = &zfs_fifoops;
702 if (parent == zfsvfs->z_shares_dir) {
703 ASSERT(zp->z_uid == 0 && zp->z_gid == 0);
704 vp->v_op = &zfs_shareops;
709 vn_setops(vp, zfs_symvnodeops);
712 vn_setops(vp, zfs_evnodeops);
717 mutex_enter(&zfsvfs->z_znodes_lock);
718 list_insert_tail(&zfsvfs->z_all_znodes, zp);
721 * Everything else must be valid before assigning z_zfsvfs makes the
722 * znode eligible for zfs_znode_move().
724 zp->z_zfsvfs = zfsvfs;
725 mutex_exit(&zfsvfs->z_znodes_lock);
728 * Acquire vnode lock before making it available to the world.
730 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
732 if (vp->v_type != VFIFO)
736 VFS_HOLD(zfsvfs->z_vfs);
741 static uint64_t empty_xattr;
742 static uint64_t pad[4];
743 static zfs_acl_phys_t acl_phys;
745 * Create a new DMU object to hold a zfs znode.
747 * IN: dzp - parent directory for new znode
748 * vap - file attributes for new znode
749 * tx - dmu transaction id for zap operations
750 * cr - credentials of caller
752 * IS_ROOT_NODE - new object will be root
753 * IS_XATTR - new object is an attribute
754 * bonuslen - length of bonus buffer
755 * setaclp - File/Dir initial ACL
756 * fuidp - Tracks fuid allocation.
758 * OUT: zpp - allocated znode
762 zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
763 uint_t flag, znode_t **zpp, zfs_acl_ids_t *acl_ids)
765 uint64_t crtime[2], atime[2], mtime[2], ctime[2];
766 uint64_t mode, size, links, parent, pflags;
767 uint64_t dzp_pflags = 0;
769 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
777 dmu_object_type_t obj_type;
778 sa_bulk_attr_t *sa_attrs;
780 zfs_acl_locator_cb_t locate = { 0 };
782 ASSERT(vap && (vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
784 if (zfsvfs->z_replay) {
785 obj = vap->va_nodeid;
786 now = vap->va_ctime; /* see zfs_replay_create() */
787 gen = vap->va_nblocks; /* ditto */
788 dnodesize = vap->va_fsid; /* ditto */
792 gen = dmu_tx_get_txg(tx);
793 dnodesize = dmu_objset_dnodesize(zfsvfs->z_os);
797 dnodesize = DNODE_MIN_SIZE;
799 obj_type = zfsvfs->z_use_sa ? DMU_OT_SA : DMU_OT_ZNODE;
800 bonuslen = (obj_type == DMU_OT_SA) ?
801 DN_BONUS_SIZE(dnodesize) : ZFS_OLD_ZNODE_PHYS_SIZE;
804 * Create a new DMU object.
807 * There's currently no mechanism for pre-reading the blocks that will
808 * be needed to allocate a new object, so we accept the small chance
809 * that there will be an i/o error and we will fail one of the
812 if (vap->va_type == VDIR) {
813 if (zfsvfs->z_replay) {
814 VERIFY0(zap_create_claim_norm_dnsize(zfsvfs->z_os, obj,
815 zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
816 obj_type, bonuslen, dnodesize, tx));
818 obj = zap_create_norm_dnsize(zfsvfs->z_os,
819 zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
820 obj_type, bonuslen, dnodesize, tx);
823 if (zfsvfs->z_replay) {
824 VERIFY0(dmu_object_claim_dnsize(zfsvfs->z_os, obj,
825 DMU_OT_PLAIN_FILE_CONTENTS, 0,
826 obj_type, bonuslen, dnodesize, tx));
828 obj = dmu_object_alloc_dnsize(zfsvfs->z_os,
829 DMU_OT_PLAIN_FILE_CONTENTS, 0,
830 obj_type, bonuslen, dnodesize, tx);
834 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
835 VERIFY0(sa_buf_hold(zfsvfs->z_os, obj, NULL, &db));
838 * If this is the root, fix up the half-initialized parent pointer
839 * to reference the just-allocated physical data area.
841 if (flag & IS_ROOT_NODE) {
844 dzp_pflags = dzp->z_pflags;
848 * If parent is an xattr, so am I.
850 if (dzp_pflags & ZFS_XATTR) {
854 if (zfsvfs->z_use_fuids)
855 pflags = ZFS_ARCHIVE | ZFS_AV_MODIFIED;
859 if (vap->va_type == VDIR) {
860 size = 2; /* contents ("." and "..") */
861 links = (flag & (IS_ROOT_NODE | IS_XATTR)) ? 2 : 1;
866 if (vap->va_type == VBLK || vap->va_type == VCHR) {
867 rdev = zfs_expldev(vap->va_rdev);
871 mode = acl_ids->z_mode;
876 * No execs denied will be deterimed when zfs_mode_compute() is called.
878 pflags |= acl_ids->z_aclp->z_hints &
879 (ZFS_ACL_TRIVIAL|ZFS_INHERIT_ACE|ZFS_ACL_AUTO_INHERIT|
880 ZFS_ACL_DEFAULTED|ZFS_ACL_PROTECTED);
882 ZFS_TIME_ENCODE(&now, crtime);
883 ZFS_TIME_ENCODE(&now, ctime);
885 if (vap->va_mask & AT_ATIME) {
886 ZFS_TIME_ENCODE(&vap->va_atime, atime);
888 ZFS_TIME_ENCODE(&now, atime);
891 if (vap->va_mask & AT_MTIME) {
892 ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
894 ZFS_TIME_ENCODE(&now, mtime);
897 /* Now add in all of the "SA" attributes */
898 VERIFY(0 == sa_handle_get_from_db(zfsvfs->z_os, db, NULL, SA_HDL_SHARED,
902 * Setup the array of attributes to be replaced/set on the new file
904 * order for DMU_OT_ZNODE is critical since it needs to be constructed
905 * in the old znode_phys_t format. Don't change this ordering
907 sa_attrs = kmem_alloc(sizeof (sa_bulk_attr_t) * ZPL_END, KM_SLEEP);
909 if (obj_type == DMU_OT_ZNODE) {
910 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ATIME(zfsvfs),
912 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MTIME(zfsvfs),
914 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CTIME(zfsvfs),
916 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CRTIME(zfsvfs),
918 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GEN(zfsvfs),
920 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MODE(zfsvfs),
922 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_SIZE(zfsvfs),
924 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PARENT(zfsvfs),
927 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MODE(zfsvfs),
929 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_SIZE(zfsvfs),
931 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GEN(zfsvfs),
933 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_UID(zfsvfs),
934 NULL, &acl_ids->z_fuid, 8);
935 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GID(zfsvfs),
936 NULL, &acl_ids->z_fgid, 8);
937 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PARENT(zfsvfs),
939 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_FLAGS(zfsvfs),
941 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ATIME(zfsvfs),
943 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MTIME(zfsvfs),
945 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CTIME(zfsvfs),
947 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CRTIME(zfsvfs),
951 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_LINKS(zfsvfs), NULL, &links, 8);
953 if (obj_type == DMU_OT_ZNODE) {
954 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_XATTR(zfsvfs), NULL,
957 if (obj_type == DMU_OT_ZNODE ||
958 (vap->va_type == VBLK || vap->va_type == VCHR)) {
959 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_RDEV(zfsvfs),
963 if (obj_type == DMU_OT_ZNODE) {
964 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_FLAGS(zfsvfs),
966 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_UID(zfsvfs), NULL,
967 &acl_ids->z_fuid, 8);
968 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GID(zfsvfs), NULL,
969 &acl_ids->z_fgid, 8);
970 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PAD(zfsvfs), NULL, pad,
971 sizeof (uint64_t) * 4);
972 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ZNODE_ACL(zfsvfs), NULL,
973 &acl_phys, sizeof (zfs_acl_phys_t));
974 } else if (acl_ids->z_aclp->z_version >= ZFS_ACL_VERSION_FUID) {
975 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_DACL_COUNT(zfsvfs), NULL,
976 &acl_ids->z_aclp->z_acl_count, 8);
977 locate.cb_aclp = acl_ids->z_aclp;
978 SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_DACL_ACES(zfsvfs),
979 zfs_acl_data_locator, &locate,
980 acl_ids->z_aclp->z_acl_bytes);
981 mode = zfs_mode_compute(mode, acl_ids->z_aclp, &pflags,
982 acl_ids->z_fuid, acl_ids->z_fgid);
985 VERIFY(sa_replace_all_by_template(sa_hdl, sa_attrs, cnt, tx) == 0);
987 if (!(flag & IS_ROOT_NODE)) {
988 *zpp = zfs_znode_alloc(zfsvfs, db, 0, obj_type, sa_hdl);
989 ASSERT(*zpp != NULL);
992 * If we are creating the root node, the "parent" we
993 * passed in is the znode for the root.
997 (*zpp)->z_sa_hdl = sa_hdl;
1000 (*zpp)->z_pflags = pflags;
1001 (*zpp)->z_mode = mode;
1002 (*zpp)->z_dnodesize = dnodesize;
1004 if (vap->va_mask & AT_XVATTR)
1005 zfs_xvattr_set(*zpp, (xvattr_t *)vap, tx);
1007 if (obj_type == DMU_OT_ZNODE ||
1008 acl_ids->z_aclp->z_version < ZFS_ACL_VERSION_FUID) {
1009 VERIFY0(zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx));
1011 if (!(flag & IS_ROOT_NODE)) {
1015 vp->v_vflag |= VV_FORCEINSMQ;
1016 err = insmntque(vp, zfsvfs->z_vfs);
1017 vp->v_vflag &= ~VV_FORCEINSMQ;
1018 KASSERT(err == 0, ("insmntque() failed: error %d", err));
1020 kmem_free(sa_attrs, sizeof (sa_bulk_attr_t) * ZPL_END);
1021 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
1025 * Update in-core attributes. It is assumed the caller will be doing an
1026 * sa_bulk_update to push the changes out.
1029 zfs_xvattr_set(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
1033 xoap = xva_getxoptattr(xvap);
1036 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
1038 ZFS_TIME_ENCODE(&xoap->xoa_createtime, times);
1039 (void) sa_update(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
1040 ×, sizeof (times), tx);
1041 XVA_SET_RTN(xvap, XAT_CREATETIME);
1043 if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
1044 ZFS_ATTR_SET(zp, ZFS_READONLY, xoap->xoa_readonly,
1046 XVA_SET_RTN(xvap, XAT_READONLY);
1048 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
1049 ZFS_ATTR_SET(zp, ZFS_HIDDEN, xoap->xoa_hidden,
1051 XVA_SET_RTN(xvap, XAT_HIDDEN);
1053 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
1054 ZFS_ATTR_SET(zp, ZFS_SYSTEM, xoap->xoa_system,
1056 XVA_SET_RTN(xvap, XAT_SYSTEM);
1058 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
1059 ZFS_ATTR_SET(zp, ZFS_ARCHIVE, xoap->xoa_archive,
1061 XVA_SET_RTN(xvap, XAT_ARCHIVE);
1063 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
1064 ZFS_ATTR_SET(zp, ZFS_IMMUTABLE, xoap->xoa_immutable,
1066 XVA_SET_RTN(xvap, XAT_IMMUTABLE);
1068 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
1069 ZFS_ATTR_SET(zp, ZFS_NOUNLINK, xoap->xoa_nounlink,
1071 XVA_SET_RTN(xvap, XAT_NOUNLINK);
1073 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
1074 ZFS_ATTR_SET(zp, ZFS_APPENDONLY, xoap->xoa_appendonly,
1076 XVA_SET_RTN(xvap, XAT_APPENDONLY);
1078 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
1079 ZFS_ATTR_SET(zp, ZFS_NODUMP, xoap->xoa_nodump,
1081 XVA_SET_RTN(xvap, XAT_NODUMP);
1083 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
1084 ZFS_ATTR_SET(zp, ZFS_OPAQUE, xoap->xoa_opaque,
1086 XVA_SET_RTN(xvap, XAT_OPAQUE);
1088 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
1089 ZFS_ATTR_SET(zp, ZFS_AV_QUARANTINED,
1090 xoap->xoa_av_quarantined, zp->z_pflags, tx);
1091 XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
1093 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
1094 ZFS_ATTR_SET(zp, ZFS_AV_MODIFIED, xoap->xoa_av_modified,
1096 XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
1098 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
1099 zfs_sa_set_scanstamp(zp, xvap, tx);
1100 XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
1102 if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
1103 ZFS_ATTR_SET(zp, ZFS_REPARSE, xoap->xoa_reparse,
1105 XVA_SET_RTN(xvap, XAT_REPARSE);
1107 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE)) {
1108 ZFS_ATTR_SET(zp, ZFS_OFFLINE, xoap->xoa_offline,
1110 XVA_SET_RTN(xvap, XAT_OFFLINE);
1112 if (XVA_ISSET_REQ(xvap, XAT_SPARSE)) {
1113 ZFS_ATTR_SET(zp, ZFS_SPARSE, xoap->xoa_sparse,
1115 XVA_SET_RTN(xvap, XAT_SPARSE);
1120 zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
1122 dmu_object_info_t doi;
1132 getnewvnode_reserve(1);
1135 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
1137 err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, &db);
1139 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1140 getnewvnode_drop_reserve();
1144 dmu_object_info_from_db(db, &doi);
1145 if (doi.doi_bonus_type != DMU_OT_SA &&
1146 (doi.doi_bonus_type != DMU_OT_ZNODE ||
1147 (doi.doi_bonus_type == DMU_OT_ZNODE &&
1148 doi.doi_bonus_size < sizeof (znode_phys_t)))) {
1149 sa_buf_rele(db, NULL);
1150 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1152 getnewvnode_drop_reserve();
1154 return (SET_ERROR(EINVAL));
1157 hdl = dmu_buf_get_user(db);
1159 zp = sa_get_userdata(hdl);
1162 * Since "SA" does immediate eviction we
1163 * should never find a sa handle that doesn't
1164 * know about the znode.
1166 ASSERT3P(zp, !=, NULL);
1167 ASSERT3U(zp->z_id, ==, obj_num);
1168 if (zp->z_unlinked) {
1169 err = SET_ERROR(ENOENT);
1173 * Don't let the vnode disappear after
1174 * ZFS_OBJ_HOLD_EXIT.
1181 sa_buf_rele(db, NULL);
1182 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1185 getnewvnode_drop_reserve();
1189 locked = VOP_ISLOCKED(vp);
1191 if ((vp->v_iflag & VI_DOOMED) != 0 &&
1192 locked != LK_EXCLUSIVE) {
1194 * The vnode is doomed and this thread doesn't
1195 * hold the exclusive lock on it, so the vnode
1196 * must be being reclaimed by another thread.
1197 * Otherwise the doomed vnode is being reclaimed
1198 * by this thread and zfs_zget is called from
1204 * XXX vrele() locks the vnode when the last reference
1205 * is dropped. Although in this case the vnode is
1206 * doomed / dead and so no inactivation is required,
1207 * the vnode lock is still acquired. That could result
1208 * in a LOR with z_teardown_lock if another thread holds
1209 * the vnode's lock and tries to take z_teardown_lock.
1210 * But that is only possible if the other thread peforms
1211 * a ZFS vnode operation on the vnode. That either
1212 * should not happen if the vnode is dead or the thread
1213 * should also have a refrence to the vnode and thus
1214 * our reference is not last.
1220 getnewvnode_drop_reserve();
1225 * Not found create new znode/vnode
1226 * but only if file exists.
1228 * There is a small window where zfs_vget() could
1229 * find this object while a file create is still in
1230 * progress. This is checked for in zfs_znode_alloc()
1232 * if zfs_znode_alloc() fails it will drop the hold on the
1235 zp = zfs_znode_alloc(zfsvfs, db, doi.doi_data_block_size,
1236 doi.doi_bonus_type, NULL);
1238 err = SET_ERROR(ENOENT);
1243 vnode_t *vp = ZTOV(zp);
1245 err = insmntque(vp, zfsvfs->z_vfs);
1247 vp->v_hash = obj_num;
1251 zfs_znode_dmu_fini(zp);
1256 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1257 getnewvnode_drop_reserve();
1262 zfs_rezget(znode_t *zp)
1264 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1265 dmu_object_info_t doi;
1268 uint64_t obj_num = zp->z_id;
1269 uint64_t mode, size;
1270 sa_bulk_attr_t bulk[8];
1276 * Remove cached pages before reloading the znode, so that they are not
1277 * lingering after we run into any error. Ideally, we should vgone()
1278 * the vnode in case of error, but currently we cannot do that
1279 * because of the LOR between the vnode lock and z_teardown_lock.
1280 * So, instead, we have to "doom" the znode in the illumos style.
1283 vn_pages_remove(vp, 0, 0);
1285 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
1287 mutex_enter(&zp->z_acl_lock);
1288 if (zp->z_acl_cached) {
1289 zfs_acl_free(zp->z_acl_cached);
1290 zp->z_acl_cached = NULL;
1293 mutex_exit(&zp->z_acl_lock);
1294 ASSERT(zp->z_sa_hdl == NULL);
1295 err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, &db);
1297 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1301 dmu_object_info_from_db(db, &doi);
1302 if (doi.doi_bonus_type != DMU_OT_SA &&
1303 (doi.doi_bonus_type != DMU_OT_ZNODE ||
1304 (doi.doi_bonus_type == DMU_OT_ZNODE &&
1305 doi.doi_bonus_size < sizeof (znode_phys_t)))) {
1306 sa_buf_rele(db, NULL);
1307 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1308 return (SET_ERROR(EINVAL));
1311 zfs_znode_sa_init(zfsvfs, zp, db, doi.doi_bonus_type, NULL);
1314 /* reload cached values */
1315 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GEN(zfsvfs), NULL,
1316 &gen, sizeof (gen));
1317 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
1318 &zp->z_size, sizeof (zp->z_size));
1319 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL,
1320 &zp->z_links, sizeof (zp->z_links));
1321 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
1322 &zp->z_pflags, sizeof (zp->z_pflags));
1323 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
1324 &zp->z_atime, sizeof (zp->z_atime));
1325 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL,
1326 &zp->z_uid, sizeof (zp->z_uid));
1327 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs), NULL,
1328 &zp->z_gid, sizeof (zp->z_gid));
1329 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
1330 &mode, sizeof (mode));
1332 if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count)) {
1333 zfs_znode_dmu_fini(zp);
1334 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1335 return (SET_ERROR(EIO));
1340 if (gen != zp->z_gen) {
1341 zfs_znode_dmu_fini(zp);
1342 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1343 return (SET_ERROR(EIO));
1347 * It is highly improbable but still quite possible that two
1348 * objects in different datasets are created with the same
1349 * object numbers and in transaction groups with the same
1350 * numbers. znodes corresponding to those objects would
1351 * have the same z_id and z_gen, but their other attributes
1353 * zfs recv -F may replace one of such objects with the other.
1354 * As a result file properties recorded in the replaced
1355 * object's vnode may no longer match the received object's
1356 * properties. At present the only cached property is the
1357 * files type recorded in v_type.
1358 * So, handle this case by leaving the old vnode and znode
1359 * disassociated from the actual object. A new vnode and a
1360 * znode will be created if the object is accessed
1361 * (e.g. via a look-up). The old vnode and znode will be
1362 * recycled when the last vnode reference is dropped.
1364 if (vp->v_type != IFTOVT((mode_t)zp->z_mode)) {
1365 zfs_znode_dmu_fini(zp);
1366 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1367 return (SET_ERROR(EIO));
1371 * If the file has zero links, then it has been unlinked on the send
1372 * side and it must be in the received unlinked set.
1373 * We call zfs_znode_dmu_fini() now to prevent any accesses to the
1374 * stale data and to prevent automatical removal of the file in
1375 * zfs_zinactive(). The file will be removed either when it is removed
1376 * on the send side and the next incremental stream is received or
1377 * when the unlinked set gets processed.
1379 zp->z_unlinked = (zp->z_links == 0);
1380 if (zp->z_unlinked) {
1381 zfs_znode_dmu_fini(zp);
1382 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1386 zp->z_blksz = doi.doi_data_block_size;
1387 if (zp->z_size != size)
1388 vnode_pager_setsize(vp, zp->z_size);
1390 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1396 zfs_znode_delete(znode_t *zp, dmu_tx_t *tx)
1398 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1399 objset_t *os = zfsvfs->z_os;
1400 uint64_t obj = zp->z_id;
1401 uint64_t acl_obj = zfs_external_acl(zp);
1403 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
1405 VERIFY(!zp->z_is_sa);
1406 VERIFY(0 == dmu_object_free(os, acl_obj, tx));
1408 VERIFY(0 == dmu_object_free(os, obj, tx));
1409 zfs_znode_dmu_fini(zp);
1410 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
1415 zfs_zinactive(znode_t *zp)
1417 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1418 uint64_t z_id = zp->z_id;
1420 ASSERT(zp->z_sa_hdl);
1423 * Don't allow a zfs_zget() while were trying to release this znode
1425 ZFS_OBJ_HOLD_ENTER(zfsvfs, z_id);
1428 * If this was the last reference to a file with no links, remove
1429 * the file from the file system unless the file system is mounted
1430 * read-only. That can happen, for example, if the file system was
1431 * originally read-write, the file was opened, then unlinked and
1432 * the file system was made read-only before the file was finally
1433 * closed. The file will remain in the unlinked set.
1435 if (zp->z_unlinked) {
1436 ASSERT(!zfsvfs->z_issnap);
1437 if ((zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) == 0) {
1438 ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
1444 zfs_znode_dmu_fini(zp);
1445 ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
1450 zfs_znode_free(znode_t *zp)
1452 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1454 ASSERT(zp->z_sa_hdl == NULL);
1456 mutex_enter(&zfsvfs->z_znodes_lock);
1457 POINTER_INVALIDATE(&zp->z_zfsvfs);
1458 list_remove(&zfsvfs->z_all_znodes, zp);
1459 mutex_exit(&zfsvfs->z_znodes_lock);
1461 if (zp->z_acl_cached) {
1462 zfs_acl_free(zp->z_acl_cached);
1463 zp->z_acl_cached = NULL;
1466 kmem_cache_free(znode_cache, zp);
1469 VFS_RELE(zfsvfs->z_vfs);
1474 zfs_tstamp_update_setup(znode_t *zp, uint_t flag, uint64_t mtime[2],
1475 uint64_t ctime[2], boolean_t have_tx)
1479 vfs_timestamp(&now);
1481 if (have_tx) { /* will sa_bulk_update happen really soon? */
1482 zp->z_atime_dirty = 0;
1485 zp->z_atime_dirty = 1;
1488 if (flag & AT_ATIME) {
1489 ZFS_TIME_ENCODE(&now, zp->z_atime);
1492 if (flag & AT_MTIME) {
1493 ZFS_TIME_ENCODE(&now, mtime);
1494 if (zp->z_zfsvfs->z_use_fuids) {
1495 zp->z_pflags |= (ZFS_ARCHIVE |
1500 if (flag & AT_CTIME) {
1501 ZFS_TIME_ENCODE(&now, ctime);
1502 if (zp->z_zfsvfs->z_use_fuids)
1503 zp->z_pflags |= ZFS_ARCHIVE;
1508 * Grow the block size for a file.
1510 * IN: zp - znode of file to free data in.
1511 * size - requested block size
1512 * tx - open transaction.
1514 * NOTE: this function assumes that the znode is write locked.
1517 zfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
1522 if (size <= zp->z_blksz)
1525 * If the file size is already greater than the current blocksize,
1526 * we will not grow. If there is more than one block in a file,
1527 * the blocksize cannot change.
1529 if (zp->z_blksz && zp->z_size > zp->z_blksz)
1532 error = dmu_object_set_blocksize(zp->z_zfsvfs->z_os, zp->z_id,
1535 if (error == ENOTSUP)
1539 /* What blocksize did we actually get? */
1540 dmu_object_size_from_db(sa_get_db(zp->z_sa_hdl), &zp->z_blksz, &dummy);
1545 * This is a dummy interface used when pvn_vplist_dirty() should *not*
1546 * be calling back into the fs for a putpage(). E.g.: when truncating
1547 * a file, the pages being "thrown away* don't need to be written out.
1551 zfs_no_putpage(vnode_t *vp, page_t *pp, u_offset_t *offp, size_t *lenp,
1552 int flags, cred_t *cr)
1560 * Increase the file length
1562 * IN: zp - znode of file to free data in.
1563 * end - new end-of-file
1565 * RETURN: 0 on success, error code on failure
1568 zfs_extend(znode_t *zp, uint64_t end)
1570 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1577 * We will change zp_size, lock the whole file.
1579 rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
1582 * Nothing to do if file already at desired length.
1584 if (end <= zp->z_size) {
1585 zfs_range_unlock(rl);
1588 tx = dmu_tx_create(zfsvfs->z_os);
1589 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1590 zfs_sa_upgrade_txholds(tx, zp);
1591 if (end > zp->z_blksz &&
1592 (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
1594 * We are growing the file past the current block size.
1596 if (zp->z_blksz > zp->z_zfsvfs->z_max_blksz) {
1598 * File's blocksize is already larger than the
1599 * "recordsize" property. Only let it grow to
1600 * the next power of 2.
1602 ASSERT(!ISP2(zp->z_blksz));
1603 newblksz = MIN(end, 1 << highbit64(zp->z_blksz));
1605 newblksz = MIN(end, zp->z_zfsvfs->z_max_blksz);
1607 dmu_tx_hold_write(tx, zp->z_id, 0, newblksz);
1612 error = dmu_tx_assign(tx, TXG_WAIT);
1615 zfs_range_unlock(rl);
1620 zfs_grow_blocksize(zp, newblksz, tx);
1624 VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zp->z_zfsvfs),
1625 &zp->z_size, sizeof (zp->z_size), tx));
1627 vnode_pager_setsize(ZTOV(zp), end);
1629 zfs_range_unlock(rl);
1637 * Free space in a file.
1639 * IN: zp - znode of file to free data in.
1640 * off - start of section to free.
1641 * len - length of section to free.
1643 * RETURN: 0 on success, error code on failure
1646 zfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
1648 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1653 * Lock the range being freed.
1655 rl = zfs_range_lock(zp, off, len, RL_WRITER);
1658 * Nothing to do if file already at desired length.
1660 if (off >= zp->z_size) {
1661 zfs_range_unlock(rl);
1665 if (off + len > zp->z_size)
1666 len = zp->z_size - off;
1668 error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, off, len);
1672 * In FreeBSD we cannot free block in the middle of a file,
1673 * but only at the end of a file, so this code path should
1676 vnode_pager_setsize(ZTOV(zp), off);
1679 zfs_range_unlock(rl);
1687 * IN: zp - znode of file to free data in.
1688 * end - new end-of-file.
1690 * RETURN: 0 on success, error code on failure
1693 zfs_trunc(znode_t *zp, uint64_t end)
1695 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1696 vnode_t *vp = ZTOV(zp);
1700 sa_bulk_attr_t bulk[2];
1704 * We will change zp_size, lock the whole file.
1706 rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
1709 * Nothing to do if file already at desired length.
1711 if (end >= zp->z_size) {
1712 zfs_range_unlock(rl);
1716 error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, end,
1719 zfs_range_unlock(rl);
1722 tx = dmu_tx_create(zfsvfs->z_os);
1723 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1724 zfs_sa_upgrade_txholds(tx, zp);
1725 dmu_tx_mark_netfree(tx);
1726 error = dmu_tx_assign(tx, TXG_WAIT);
1729 zfs_range_unlock(rl);
1734 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs),
1735 NULL, &zp->z_size, sizeof (zp->z_size));
1738 zp->z_pflags &= ~ZFS_SPARSE;
1739 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs),
1740 NULL, &zp->z_pflags, 8);
1742 VERIFY(sa_bulk_update(zp->z_sa_hdl, bulk, count, tx) == 0);
1747 * Clear any mapped pages in the truncated region. This has to
1748 * happen outside of the transaction to avoid the possibility of
1749 * a deadlock with someone trying to push a page that we are
1750 * about to invalidate.
1752 vnode_pager_setsize(vp, end);
1754 zfs_range_unlock(rl);
1760 * Free space in a file
1762 * IN: zp - znode of file to free data in.
1763 * off - start of range
1764 * len - end of range (0 => EOF)
1765 * flag - current file open mode flags.
1766 * log - TRUE if this action should be logged
1768 * RETURN: 0 on success, error code on failure
1771 zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
1773 vnode_t *vp = ZTOV(zp);
1775 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1776 zilog_t *zilog = zfsvfs->z_log;
1778 uint64_t mtime[2], ctime[2];
1779 sa_bulk_attr_t bulk[3];
1783 if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_MODE(zfsvfs), &mode,
1784 sizeof (mode))) != 0)
1787 if (off > zp->z_size) {
1788 error = zfs_extend(zp, off+len);
1789 if (error == 0 && log)
1796 * Check for any locks in the region to be freed.
1799 if (MANDLOCK(vp, (mode_t)mode)) {
1800 uint64_t length = (len ? len : zp->z_size - off);
1801 if (error = chklock(vp, FWRITE, off, length, flag, NULL))
1806 error = zfs_trunc(zp, off);
1808 if ((error = zfs_free_range(zp, off, len)) == 0 &&
1809 off + len > zp->z_size)
1810 error = zfs_extend(zp, off+len);
1815 tx = dmu_tx_create(zfsvfs->z_os);
1816 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1817 zfs_sa_upgrade_txholds(tx, zp);
1818 error = dmu_tx_assign(tx, TXG_WAIT);
1824 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, mtime, 16);
1825 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, ctime, 16);
1826 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs),
1827 NULL, &zp->z_pflags, 8);
1828 zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime, B_TRUE);
1829 error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
1832 zfs_log_truncate(zilog, tx, TX_TRUNCATE, zp, off, len);
1839 zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
1841 uint64_t moid, obj, sa_obj, version;
1842 uint64_t sense = ZFS_CASE_SENSITIVE;
1847 znode_t *rootzp = NULL;
1851 zfs_acl_ids_t acl_ids;
1854 * First attempt to create master node.
1857 * In an empty objset, there are no blocks to read and thus
1858 * there can be no i/o errors (which we assert below).
1860 moid = MASTER_NODE_OBJ;
1861 error = zap_create_claim(os, moid, DMU_OT_MASTER_NODE,
1862 DMU_OT_NONE, 0, tx);
1866 * Set starting attributes.
1868 version = zfs_zpl_version_map(spa_version(dmu_objset_spa(os)));
1870 while ((elem = nvlist_next_nvpair(zplprops, elem)) != NULL) {
1871 /* For the moment we expect all zpl props to be uint64_ts */
1875 ASSERT(nvpair_type(elem) == DATA_TYPE_UINT64);
1876 VERIFY(nvpair_value_uint64(elem, &val) == 0);
1877 name = nvpair_name(elem);
1878 if (strcmp(name, zfs_prop_to_name(ZFS_PROP_VERSION)) == 0) {
1882 error = zap_update(os, moid, name, 8, 1, &val, tx);
1885 if (strcmp(name, zfs_prop_to_name(ZFS_PROP_NORMALIZE)) == 0)
1887 else if (strcmp(name, zfs_prop_to_name(ZFS_PROP_CASE)) == 0)
1890 ASSERT(version != 0);
1891 error = zap_update(os, moid, ZPL_VERSION_STR, 8, 1, &version, tx);
1894 * Create zap object used for SA attribute registration
1897 if (version >= ZPL_VERSION_SA) {
1898 sa_obj = zap_create(os, DMU_OT_SA_MASTER_NODE,
1899 DMU_OT_NONE, 0, tx);
1900 error = zap_add(os, moid, ZFS_SA_ATTRS, 8, 1, &sa_obj, tx);
1906 * Create a delete queue.
1908 obj = zap_create(os, DMU_OT_UNLINKED_SET, DMU_OT_NONE, 0, tx);
1910 error = zap_add(os, moid, ZFS_UNLINKED_SET, 8, 1, &obj, tx);
1914 * Create root znode. Create minimal znode/vnode/zfsvfs
1915 * to allow zfs_mknode to work.
1918 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
1919 vattr.va_type = VDIR;
1920 vattr.va_mode = S_IFDIR|0755;
1921 vattr.va_uid = crgetuid(cr);
1922 vattr.va_gid = crgetgid(cr);
1924 zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
1926 rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP);
1927 ASSERT(!POINTER_IS_VALID(rootzp->z_zfsvfs));
1928 rootzp->z_moved = 0;
1929 rootzp->z_unlinked = 0;
1930 rootzp->z_atime_dirty = 0;
1931 rootzp->z_is_sa = USE_SA(version, os);
1934 zfsvfs->z_parent = zfsvfs;
1935 zfsvfs->z_version = version;
1936 zfsvfs->z_use_fuids = USE_FUIDS(version, os);
1937 zfsvfs->z_use_sa = USE_SA(version, os);
1938 zfsvfs->z_norm = norm;
1940 error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
1941 &zfsvfs->z_attr_table);
1946 * Fold case on file systems that are always or sometimes case
1949 if (sense == ZFS_CASE_INSENSITIVE || sense == ZFS_CASE_MIXED)
1950 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
1952 mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
1953 list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
1954 offsetof(znode_t, z_link_node));
1956 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
1957 mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
1959 rootzp->z_zfsvfs = zfsvfs;
1960 VERIFY(0 == zfs_acl_ids_create(rootzp, IS_ROOT_NODE, &vattr,
1961 cr, NULL, &acl_ids));
1962 zfs_mknode(rootzp, &vattr, tx, cr, IS_ROOT_NODE, &zp, &acl_ids);
1963 ASSERT3P(zp, ==, rootzp);
1964 error = zap_add(os, moid, ZFS_ROOT_OBJ, 8, 1, &rootzp->z_id, tx);
1966 zfs_acl_ids_free(&acl_ids);
1967 POINTER_INVALIDATE(&rootzp->z_zfsvfs);
1969 sa_handle_destroy(rootzp->z_sa_hdl);
1970 kmem_cache_free(znode_cache, rootzp);
1973 * Create shares directory
1976 error = zfs_create_share_dir(zfsvfs, tx);
1980 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
1981 mutex_destroy(&zfsvfs->z_hold_mtx[i]);
1982 kmem_free(zfsvfs, sizeof (zfsvfs_t));
1984 #endif /* _KERNEL */
1987 zfs_sa_setup(objset_t *osp, sa_attr_type_t **sa_table)
1989 uint64_t sa_obj = 0;
1992 error = zap_lookup(osp, MASTER_NODE_OBJ, ZFS_SA_ATTRS, 8, 1, &sa_obj);
1993 if (error != 0 && error != ENOENT)
1996 error = sa_setup(osp, sa_obj, zfs_attr_table, ZPL_END, sa_table);
2001 zfs_grab_sa_handle(objset_t *osp, uint64_t obj, sa_handle_t **hdlp,
2002 dmu_buf_t **db, void *tag)
2004 dmu_object_info_t doi;
2007 if ((error = sa_buf_hold(osp, obj, tag, db)) != 0)
2010 dmu_object_info_from_db(*db, &doi);
2011 if ((doi.doi_bonus_type != DMU_OT_SA &&
2012 doi.doi_bonus_type != DMU_OT_ZNODE) ||
2013 doi.doi_bonus_type == DMU_OT_ZNODE &&
2014 doi.doi_bonus_size < sizeof (znode_phys_t)) {
2015 sa_buf_rele(*db, tag);
2016 return (SET_ERROR(ENOTSUP));
2019 error = sa_handle_get(osp, obj, NULL, SA_HDL_PRIVATE, hdlp);
2021 sa_buf_rele(*db, tag);
2029 zfs_release_sa_handle(sa_handle_t *hdl, dmu_buf_t *db, void *tag)
2031 sa_handle_destroy(hdl);
2032 sa_buf_rele(db, tag);
2036 * Given an object number, return its parent object number and whether
2037 * or not the object is an extended attribute directory.
2040 zfs_obj_to_pobj(objset_t *osp, sa_handle_t *hdl, sa_attr_type_t *sa_table,
2041 uint64_t *pobjp, int *is_xattrdir)
2046 uint64_t parent_mode;
2047 sa_bulk_attr_t bulk[3];
2048 sa_handle_t *sa_hdl;
2053 SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_PARENT], NULL,
2054 &parent, sizeof (parent));
2055 SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_FLAGS], NULL,
2056 &pflags, sizeof (pflags));
2057 SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_MODE], NULL,
2058 &mode, sizeof (mode));
2060 if ((error = sa_bulk_lookup(hdl, bulk, count)) != 0)
2064 * When a link is removed its parent pointer is not changed and will
2065 * be invalid. There are two cases where a link is removed but the
2066 * file stays around, when it goes to the delete queue and when there
2067 * are additional links.
2069 error = zfs_grab_sa_handle(osp, parent, &sa_hdl, &sa_db, FTAG);
2073 error = sa_lookup(sa_hdl, ZPL_MODE, &parent_mode, sizeof (parent_mode));
2074 zfs_release_sa_handle(sa_hdl, sa_db, FTAG);
2078 *is_xattrdir = ((pflags & ZFS_XATTR) != 0) && S_ISDIR(mode);
2081 * Extended attributes can be applied to files, directories, etc.
2082 * Otherwise the parent must be a directory.
2084 if (!*is_xattrdir && !S_ISDIR(parent_mode))
2085 return (SET_ERROR(EINVAL));
2093 * Given an object number, return some zpl level statistics
2096 zfs_obj_to_stats_impl(sa_handle_t *hdl, sa_attr_type_t *sa_table,
2099 sa_bulk_attr_t bulk[4];
2102 SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_MODE], NULL,
2103 &sb->zs_mode, sizeof (sb->zs_mode));
2104 SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_GEN], NULL,
2105 &sb->zs_gen, sizeof (sb->zs_gen));
2106 SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_LINKS], NULL,
2107 &sb->zs_links, sizeof (sb->zs_links));
2108 SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_CTIME], NULL,
2109 &sb->zs_ctime, sizeof (sb->zs_ctime));
2111 return (sa_bulk_lookup(hdl, bulk, count));
2115 zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
2116 sa_attr_type_t *sa_table, char *buf, int len)
2118 sa_handle_t *sa_hdl;
2119 sa_handle_t *prevhdl = NULL;
2120 dmu_buf_t *prevdb = NULL;
2121 dmu_buf_t *sa_db = NULL;
2122 char *path = buf + len - 1;
2128 uint64_t deleteq_obj;
2129 VERIFY0(zap_lookup(osp, MASTER_NODE_OBJ,
2130 ZFS_UNLINKED_SET, sizeof (uint64_t), 1, &deleteq_obj));
2131 error = zap_lookup_int(osp, deleteq_obj, obj);
2134 } else if (error != ENOENT) {
2141 char component[MAXNAMELEN + 2];
2146 zfs_release_sa_handle(prevhdl, prevdb, FTAG);
2148 if ((error = zfs_obj_to_pobj(osp, sa_hdl, sa_table, &pobj,
2149 &is_xattrdir)) != 0)
2160 (void) sprintf(component + 1, "<xattrdir>");
2162 error = zap_value_search(osp, pobj, obj,
2163 ZFS_DIRENT_OBJ(-1ULL), component + 1);
2168 complen = strlen(component);
2170 ASSERT(path >= buf);
2171 bcopy(component, path, complen);
2174 if (sa_hdl != hdl) {
2178 error = zfs_grab_sa_handle(osp, obj, &sa_hdl, &sa_db, FTAG);
2186 if (sa_hdl != NULL && sa_hdl != hdl) {
2187 ASSERT(sa_db != NULL);
2188 zfs_release_sa_handle(sa_hdl, sa_db, FTAG);
2192 (void) memmove(buf, path, buf + len - path);
2198 zfs_obj_to_path(objset_t *osp, uint64_t obj, char *buf, int len)
2200 sa_attr_type_t *sa_table;
2205 error = zfs_sa_setup(osp, &sa_table);
2209 error = zfs_grab_sa_handle(osp, obj, &hdl, &db, FTAG);
2213 error = zfs_obj_to_path_impl(osp, obj, hdl, sa_table, buf, len);
2215 zfs_release_sa_handle(hdl, db, FTAG);
2220 zfs_obj_to_stats(objset_t *osp, uint64_t obj, zfs_stat_t *sb,
2223 char *path = buf + len - 1;
2224 sa_attr_type_t *sa_table;
2231 error = zfs_sa_setup(osp, &sa_table);
2235 error = zfs_grab_sa_handle(osp, obj, &hdl, &db, FTAG);
2239 error = zfs_obj_to_stats_impl(hdl, sa_table, sb);
2241 zfs_release_sa_handle(hdl, db, FTAG);
2245 error = zfs_obj_to_path_impl(osp, obj, hdl, sa_table, buf, len);
2247 zfs_release_sa_handle(hdl, db, FTAG);
2253 zfs_znode_parent_and_name(znode_t *zp, znode_t **dzpp, char *buf)
2255 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2260 /* Extended attributes should not be visible as regular files. */
2261 if ((zp->z_pflags & ZFS_XATTR) != 0)
2262 return (SET_ERROR(EINVAL));
2264 err = zfs_obj_to_pobj(zfsvfs->z_os, zp->z_sa_hdl, zfsvfs->z_attr_table,
2265 &parent, &is_xattrdir);
2268 ASSERT0(is_xattrdir);
2270 /* No name as this is a root object. */
2271 if (parent == zp->z_id)
2272 return (SET_ERROR(EINVAL));
2274 err = zap_value_search(zfsvfs->z_os, parent, zp->z_id,
2275 ZFS_DIRENT_OBJ(-1ULL), buf);
2278 err = zfs_zget(zfsvfs, parent, dzpp);
2281 #endif /* _KERNEL */