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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Portions Copyright 2007 Jeremy Teo */
29 #include <sys/types.h>
30 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/sysmacros.h>
34 #include <sys/resource.h>
35 #include <sys/mntent.h>
36 #include <sys/u8_textprep.h>
37 #include <sys/dsl_dataset.h>
39 #include <sys/vnode.h>
42 #include <sys/errno.h>
43 #include <sys/unistd.h>
44 #include <sys/atomic.h>
45 #include <sys/zfs_dir.h>
46 #include <sys/zfs_acl.h>
47 #include <sys/zfs_ioctl.h>
48 #include <sys/zfs_rlock.h>
49 #include <sys/zfs_fuid.h>
50 #include <sys/fs/zfs.h>
51 #include <sys/kidmap.h>
55 #include <sys/refcount.h>
58 #include <sys/zfs_znode.h>
59 #include <sys/refcount.h>
63 /* Used by fstat(1). */
64 SYSCTL_INT(_debug_sizeof, OID_AUTO, znode, CTLFLAG_RD, 0, sizeof(znode_t),
68 * Define ZNODE_STATS to turn on statistic gathering. By default, it is only
69 * turned on when DEBUG is also defined.
76 #define ZNODE_STAT_ADD(stat) ((stat)++)
78 #define ZNODE_STAT_ADD(stat) /* nothing */
79 #endif /* ZNODE_STATS */
81 #define POINTER_IS_VALID(p) (!((uintptr_t)(p) & 0x3))
82 #define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1))
85 * Functions needed for userland (ie: libzpool) are not put under
86 * #ifdef_KERNEL; the rest of the functions have dependencies
87 * (such as VFS logic) that will not compile easily in userland.
90 static kmem_cache_t *znode_cache = NULL;
94 znode_evict_error(dmu_buf_t *dbuf, void *user_ptr)
96 #if 1 /* XXXPJD: From OpenSolaris. */
98 * We should never drop all dbuf refs without first clearing
99 * the eviction callback.
101 panic("evicting znode %p\n", user_ptr);
103 znode_t *zp = user_ptr;
106 mutex_enter(&zp->z_lock);
110 mutex_exit(&zp->z_lock);
112 } else if (vp->v_count == 0) {
115 mutex_exit(&zp->z_lock);
116 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
117 vrecycle(vp, curthread);
122 mutex_exit(&zp->z_lock);
127 extern struct vop_vector zfs_vnodeops;
128 extern struct vop_vector zfs_fifoops;
131 * XXX: We cannot use this function as a cache constructor, because
132 * there is one global cache for all file systems and we need
133 * to pass vfsp here, which is not possible, because argument
134 * 'cdrarg' is defined at kmem_cache_create() time.
137 zfs_znode_cache_constructor(void *buf, void *arg, int kmflags)
144 POINTER_INVALIDATE(&zp->z_zfsvfs);
145 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
146 ASSERT(vfsp != NULL);
148 error = getnewvnode("zfs", vfsp, &zfs_vnodeops, &vp);
149 if (error != 0 && (kmflags & KM_NOSLEEP))
152 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
154 vp->v_data = (caddr_t)zp;
157 list_link_init(&zp->z_link_node);
159 mutex_init(&zp->z_lock, NULL, MUTEX_DEFAULT, NULL);
160 rw_init(&zp->z_map_lock, NULL, RW_DEFAULT, NULL);
161 rw_init(&zp->z_parent_lock, NULL, RW_DEFAULT, NULL);
162 rw_init(&zp->z_name_lock, NULL, RW_DEFAULT, NULL);
163 mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
165 mutex_init(&zp->z_range_lock, NULL, MUTEX_DEFAULT, NULL);
166 avl_create(&zp->z_range_avl, zfs_range_compare,
167 sizeof (rl_t), offsetof(rl_t, r_node));
170 zp->z_dirlocks = NULL;
176 zfs_znode_cache_destructor(void *buf, void *arg)
180 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
181 ASSERT(ZTOV(zp) == NULL);
183 ASSERT(!list_link_active(&zp->z_link_node));
184 mutex_destroy(&zp->z_lock);
185 rw_destroy(&zp->z_map_lock);
186 rw_destroy(&zp->z_parent_lock);
187 rw_destroy(&zp->z_name_lock);
188 mutex_destroy(&zp->z_acl_lock);
189 avl_destroy(&zp->z_range_avl);
190 mutex_destroy(&zp->z_range_lock);
192 ASSERT(zp->z_dbuf == NULL);
193 ASSERT(zp->z_dirlocks == NULL);
198 uint64_t zms_zfsvfs_invalid;
199 uint64_t zms_zfsvfs_unmounted;
200 uint64_t zms_zfsvfs_recheck_invalid;
201 uint64_t zms_obj_held;
202 uint64_t zms_vnode_locked;
203 uint64_t zms_not_only_dnlc;
205 #endif /* ZNODE_STATS */
209 zfs_znode_move_impl(znode_t *ozp, znode_t *nzp)
214 nzp->z_zfsvfs = ozp->z_zfsvfs;
218 nzp->z_vnode = ozp->z_vnode;
219 ozp->z_vnode = vp; /* let destructor free the overwritten vnode */
220 ZTOV(ozp)->v_data = ozp;
221 ZTOV(nzp)->v_data = nzp;
223 nzp->z_id = ozp->z_id;
224 ASSERT(ozp->z_dirlocks == NULL); /* znode not in use */
225 ASSERT(avl_numnodes(&ozp->z_range_avl) == 0);
226 nzp->z_unlinked = ozp->z_unlinked;
227 nzp->z_atime_dirty = ozp->z_atime_dirty;
228 nzp->z_zn_prefetch = ozp->z_zn_prefetch;
229 nzp->z_blksz = ozp->z_blksz;
230 nzp->z_seq = ozp->z_seq;
231 nzp->z_mapcnt = ozp->z_mapcnt;
232 nzp->z_last_itx = ozp->z_last_itx;
233 nzp->z_gen = ozp->z_gen;
234 nzp->z_sync_cnt = ozp->z_sync_cnt;
235 nzp->z_phys = ozp->z_phys;
236 nzp->z_dbuf = ozp->z_dbuf;
238 /* Update back pointers. */
239 (void) dmu_buf_update_user(nzp->z_dbuf, ozp, nzp, &nzp->z_phys,
243 * Invalidate the original znode by clearing fields that provide a
244 * pointer back to the znode. Set the low bit of the vfs pointer to
245 * ensure that zfs_znode_move() recognizes the znode as invalid in any
246 * subsequent callback.
249 POINTER_INVALIDATE(&ozp->z_zfsvfs);
253 * Wrapper function for ZFS_ENTER that returns 0 if successful and otherwise
254 * returns a non-zero error code.
257 zfs_enter(zfsvfs_t *zfsvfs)
265 zfs_znode_move(void *buf, void *newbuf, size_t size, void *arg)
267 znode_t *ozp = buf, *nzp = newbuf;
272 * The znode is on the file system's list of known znodes if the vfs
273 * pointer is valid. We set the low bit of the vfs pointer when freeing
274 * the znode to invalidate it, and the memory patterns written by kmem
275 * (baddcafe and deadbeef) set at least one of the two low bits. A newly
276 * created znode sets the vfs pointer last of all to indicate that the
277 * znode is known and in a valid state to be moved by this function.
279 zfsvfs = ozp->z_zfsvfs;
280 if (!POINTER_IS_VALID(zfsvfs)) {
281 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_invalid);
282 return (KMEM_CBRC_DONT_KNOW);
286 * Ensure that the filesystem is not unmounted during the move.
288 if (zfs_enter(zfsvfs) != 0) { /* ZFS_ENTER */
289 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_unmounted);
290 return (KMEM_CBRC_DONT_KNOW);
293 mutex_enter(&zfsvfs->z_znodes_lock);
295 * Recheck the vfs pointer in case the znode was removed just before
296 * acquiring the lock.
298 if (zfsvfs != ozp->z_zfsvfs) {
299 mutex_exit(&zfsvfs->z_znodes_lock);
301 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck_invalid);
302 return (KMEM_CBRC_DONT_KNOW);
306 * At this point we know that as long as we hold z_znodes_lock, the
307 * znode cannot be freed and fields within the znode can be safely
308 * accessed. Now, prevent a race with zfs_zget().
310 if (ZFS_OBJ_HOLD_TRYENTER(zfsvfs, ozp->z_id) == 0) {
311 mutex_exit(&zfsvfs->z_znodes_lock);
313 ZNODE_STAT_ADD(znode_move_stats.zms_obj_held);
314 return (KMEM_CBRC_LATER);
318 if (mutex_tryenter(&vp->v_lock) == 0) {
319 ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
320 mutex_exit(&zfsvfs->z_znodes_lock);
322 ZNODE_STAT_ADD(znode_move_stats.zms_vnode_locked);
323 return (KMEM_CBRC_LATER);
326 /* Only move znodes that are referenced _only_ by the DNLC. */
327 if (vp->v_count != 1 || !vn_in_dnlc(vp)) {
328 mutex_exit(&vp->v_lock);
329 ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
330 mutex_exit(&zfsvfs->z_znodes_lock);
332 ZNODE_STAT_ADD(znode_move_stats.zms_not_only_dnlc);
333 return (KMEM_CBRC_LATER);
337 * The znode is known and in a valid state to move. We're holding the
338 * locks needed to execute the critical section.
340 zfs_znode_move_impl(ozp, nzp);
341 mutex_exit(&vp->v_lock);
342 ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
344 list_link_replace(&ozp->z_link_node, &nzp->z_link_node);
345 mutex_exit(&zfsvfs->z_znodes_lock);
348 return (KMEM_CBRC_YES);
358 ASSERT(znode_cache == NULL);
359 znode_cache = kmem_cache_create("zfs_znode_cache",
360 sizeof (znode_t), 0, /* zfs_znode_cache_constructor */ NULL,
361 zfs_znode_cache_destructor, NULL, NULL, NULL, 0);
363 kmem_cache_set_move(znode_cache, zfs_znode_move);
374 kmem_cache_destroy(znode_cache);
379 * zfs_init_fs - Initialize the zfsvfs struct and the file system
380 * incore "master" object. Verify version compatibility.
383 zfs_init_fs(zfsvfs_t *zfsvfs, znode_t **zpp)
385 objset_t *os = zfsvfs->z_os;
392 error = zfs_get_zplprop(os, ZFS_PROP_VERSION, &zfsvfs->z_version);
395 } else if (zfsvfs->z_version > ZPL_VERSION) {
396 (void) printf("Mismatched versions: File system "
397 "is version %llu on-disk format, which is "
398 "incompatible with this software version %lld!",
399 (u_longlong_t)zfsvfs->z_version, ZPL_VERSION);
403 if ((error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &zval)) != 0)
405 zfsvfs->z_norm = (int)zval;
406 if ((error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &zval)) != 0)
408 zfsvfs->z_utf8 = (zval != 0);
409 if ((error = zfs_get_zplprop(os, ZFS_PROP_CASE, &zval)) != 0)
411 zfsvfs->z_case = (uint_t)zval;
413 * Fold case on file systems that are always or sometimes case
416 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
417 zfsvfs->z_case == ZFS_CASE_MIXED)
418 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
421 * The fsid is 64 bits, composed of an 8-bit fs type, which
422 * separates our fsid from any other filesystem types, and a
423 * 56-bit objset unique ID. The objset unique ID is unique to
424 * all objsets open on this system, provided by unique_create().
425 * The 8-bit fs type must be put in the low bits of fsid[1]
426 * because that's where other Solaris filesystems put it.
428 fsid_guid = dmu_objset_fsid_guid(os);
429 ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0);
430 zfsvfs->z_vfs->vfs_fsid.val[0] = fsid_guid;
431 zfsvfs->z_vfs->vfs_fsid.val[1] = ((fsid_guid>>32) << 8) |
432 zfsvfs->z_vfs->mnt_vfc->vfc_typenum & 0xFF;
434 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
438 ASSERT(zfsvfs->z_root != 0);
440 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
441 &zfsvfs->z_unlinkedobj);
446 * Initialize zget mutex's
448 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
449 mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
451 error = zfs_zget(zfsvfs, zfsvfs->z_root, zpp);
454 * On error, we destroy the mutexes here since it's not
455 * possible for the caller to determine if the mutexes were
456 * initialized properly.
458 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
459 mutex_destroy(&zfsvfs->z_hold_mtx[i]);
462 ASSERT3U((*zpp)->z_id, ==, zfsvfs->z_root);
463 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1,
464 &zfsvfs->z_fuid_obj);
472 * define a couple of values we need available
473 * for both 64 and 32 bit environments.
476 #define NBITSMINOR64 32
479 #define MAXMAJ64 0xffffffffUL
482 #define MAXMIN64 0xffffffffUL
486 * Create special expldev for ZFS private use.
487 * Can't use standard expldev since it doesn't do
488 * what we want. The standard expldev() takes a
489 * dev32_t in LP64 and expands it to a long dev_t.
490 * We need an interface that takes a dev32_t in ILP32
491 * and expands it to a long dev_t.
494 zfs_expldev(dev_t dev)
496 return (((uint64_t)major(dev) << NBITSMINOR64) | minor(dev));
499 * Special cmpldev for ZFS private use.
500 * Can't use standard cmpldev since it takes
501 * a long dev_t and compresses it to dev32_t in
502 * LP64. We need to do a compaction of a long dev_t
503 * to a dev32_t in ILP32.
506 zfs_cmpldev(uint64_t dev)
508 return (makedev((dev >> NBITSMINOR64), (dev & MAXMIN64)));
512 zfs_znode_dmu_init(zfsvfs_t *zfsvfs, znode_t *zp, dmu_buf_t *db)
516 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs) || (zfsvfs == zp->z_zfsvfs));
517 ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zfsvfs, zp->z_id)));
519 mutex_enter(&zp->z_lock);
521 ASSERT(zp->z_dbuf == NULL);
523 nzp = dmu_buf_set_user_ie(db, zp, &zp->z_phys, znode_evict_error);
527 * concurrent zgets on this object.
530 panic("existing znode %p for dbuf %p", (void *)nzp, (void *)db);
533 * Slap on VROOT if we are the root znode
535 if (zp->z_id == zfsvfs->z_root)
536 ZTOV(zp)->v_flag |= VROOT;
538 mutex_exit(&zp->z_lock);
543 zfs_znode_dmu_fini(znode_t *zp)
545 dmu_buf_t *db = zp->z_dbuf;
546 ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp->z_zfsvfs, zp->z_id)) ||
548 RW_WRITE_HELD(&zp->z_zfsvfs->z_teardown_inactive_lock));
549 ASSERT(zp->z_dbuf != NULL);
551 VERIFY(zp == dmu_buf_update_user(db, zp, NULL, NULL, NULL));
552 dmu_buf_rele(db, NULL);
556 * Construct a new znode/vnode and intialize.
558 * This does not do a call to dmu_set_user() that is
559 * up to the caller to do, in case you don't want to
563 zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz)
568 zp = kmem_cache_alloc(znode_cache, KM_SLEEP);
569 zfs_znode_cache_constructor(zp, zfsvfs->z_parent->z_vfs, 0);
571 ASSERT(zp->z_dirlocks == NULL);
572 ASSERT(zp->z_dbuf == NULL);
573 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
576 * Defer setting z_zfsvfs until the znode is ready to be a candidate for
577 * the zfs_znode_move() callback.
581 zp->z_atime_dirty = 0;
584 zp->z_id = db->db_object;
586 zp->z_seq = 0x7A4653;
594 zfs_znode_dmu_init(zfsvfs, zp, db);
596 zp->z_gen = zp->z_phys->zp_gen;
603 vp->v_type = IFTOVT((mode_t)zp->z_phys->zp_mode);
604 switch (vp->v_type) {
606 zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */
609 vp->v_op = &zfs_fifoops;
612 if (vp->v_type != VFIFO)
615 mutex_enter(&zfsvfs->z_znodes_lock);
616 list_insert_tail(&zfsvfs->z_all_znodes, zp);
619 * Everything else must be valid before assigning z_zfsvfs makes the
620 * znode eligible for zfs_znode_move().
622 zp->z_zfsvfs = zfsvfs;
623 mutex_exit(&zfsvfs->z_znodes_lock);
625 VFS_HOLD(zfsvfs->z_vfs);
630 * Create a new DMU object to hold a zfs znode.
632 * IN: dzp - parent directory for new znode
633 * vap - file attributes for new znode
634 * tx - dmu transaction id for zap operations
635 * cr - credentials of caller
637 * IS_ROOT_NODE - new object will be root
638 * IS_XATTR - new object is an attribute
639 * IS_REPLAY - intent log replay
640 * bonuslen - length of bonus buffer
641 * setaclp - File/Dir initial ACL
642 * fuidp - Tracks fuid allocation.
644 * OUT: zpp - allocated znode
648 zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
649 uint_t flag, znode_t **zpp, int bonuslen, zfs_acl_t *setaclp,
650 zfs_fuid_info_t **fuidp)
654 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
659 ASSERT(vap && (vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
661 if (zfsvfs->z_assign >= TXG_INITIAL) { /* ZIL replay */
662 obj = vap->va_nodeid;
664 now = vap->va_ctime; /* see zfs_replay_create() */
665 gen = vap->va_nblocks; /* ditto */
669 gen = dmu_tx_get_txg(tx);
673 * Create a new DMU object.
676 * There's currently no mechanism for pre-reading the blocks that will
677 * be to needed allocate a new object, so we accept the small chance
678 * that there will be an i/o error and we will fail one of the
681 if (vap->va_type == VDIR) {
682 if (flag & IS_REPLAY) {
683 err = zap_create_claim_norm(zfsvfs->z_os, obj,
684 zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
685 DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
686 ASSERT3U(err, ==, 0);
688 obj = zap_create_norm(zfsvfs->z_os,
689 zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
690 DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
693 if (flag & IS_REPLAY) {
694 err = dmu_object_claim(zfsvfs->z_os, obj,
695 DMU_OT_PLAIN_FILE_CONTENTS, 0,
696 DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
697 ASSERT3U(err, ==, 0);
699 obj = dmu_object_alloc(zfsvfs->z_os,
700 DMU_OT_PLAIN_FILE_CONTENTS, 0,
701 DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
704 VERIFY(0 == dmu_bonus_hold(zfsvfs->z_os, obj, NULL, &db));
705 dmu_buf_will_dirty(db, tx);
708 * Initialize the znode physical data to zero.
710 ASSERT(db->db_size >= sizeof (znode_phys_t));
711 bzero(db->db_data, db->db_size);
715 * If this is the root, fix up the half-initialized parent pointer
716 * to reference the just-allocated physical data area.
718 if (flag & IS_ROOT_NODE) {
725 * If parent is an xattr, so am I.
727 if (dzp->z_phys->zp_flags & ZFS_XATTR)
730 if (vap->va_type == VBLK || vap->va_type == VCHR) {
731 pzp->zp_rdev = zfs_expldev(vap->va_rdev);
734 if (zfsvfs->z_use_fuids)
735 pzp->zp_flags = ZFS_ARCHIVE | ZFS_AV_MODIFIED;
737 if (vap->va_type == VDIR) {
738 pzp->zp_size = 2; /* contents ("." and "..") */
739 pzp->zp_links = (flag & (IS_ROOT_NODE | IS_XATTR)) ? 2 : 1;
742 pzp->zp_parent = dzp->z_id;
744 pzp->zp_flags |= ZFS_XATTR;
748 ZFS_TIME_ENCODE(&now, pzp->zp_crtime);
749 ZFS_TIME_ENCODE(&now, pzp->zp_ctime);
751 if (vap->va_mask & AT_ATIME) {
752 ZFS_TIME_ENCODE(&vap->va_atime, pzp->zp_atime);
754 ZFS_TIME_ENCODE(&now, pzp->zp_atime);
757 if (vap->va_mask & AT_MTIME) {
758 ZFS_TIME_ENCODE(&vap->va_mtime, pzp->zp_mtime);
760 ZFS_TIME_ENCODE(&now, pzp->zp_mtime);
763 pzp->zp_mode = MAKEIMODE(vap->va_type, vap->va_mode);
764 if (!(flag & IS_ROOT_NODE)) {
765 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
766 *zpp = zfs_znode_alloc(zfsvfs, db, 0);
767 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
770 * If we are creating the root node, the "parent" we
771 * passed in is the znode for the root.
775 zfs_perm_init(*zpp, dzp, flag, vap, tx, cr, setaclp, fuidp);
776 if (!(flag & IS_ROOT_NODE)) {
780 vp->v_vflag |= VV_FORCEINSMQ;
781 err = insmntque(vp, zfsvfs->z_vfs);
782 vp->v_vflag &= ~VV_FORCEINSMQ;
783 KASSERT(err == 0, ("insmntque() failed: error %d", err));
788 zfs_xvattr_set(znode_t *zp, xvattr_t *xvap)
792 xoap = xva_getxoptattr(xvap);
795 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
796 ZFS_TIME_ENCODE(&xoap->xoa_createtime, zp->z_phys->zp_crtime);
797 XVA_SET_RTN(xvap, XAT_CREATETIME);
799 if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
800 ZFS_ATTR_SET(zp, ZFS_READONLY, xoap->xoa_readonly);
801 XVA_SET_RTN(xvap, XAT_READONLY);
803 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
804 ZFS_ATTR_SET(zp, ZFS_HIDDEN, xoap->xoa_hidden);
805 XVA_SET_RTN(xvap, XAT_HIDDEN);
807 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
808 ZFS_ATTR_SET(zp, ZFS_SYSTEM, xoap->xoa_system);
809 XVA_SET_RTN(xvap, XAT_SYSTEM);
811 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
812 ZFS_ATTR_SET(zp, ZFS_ARCHIVE, xoap->xoa_archive);
813 XVA_SET_RTN(xvap, XAT_ARCHIVE);
815 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
816 ZFS_ATTR_SET(zp, ZFS_IMMUTABLE, xoap->xoa_immutable);
817 XVA_SET_RTN(xvap, XAT_IMMUTABLE);
819 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
820 ZFS_ATTR_SET(zp, ZFS_NOUNLINK, xoap->xoa_nounlink);
821 XVA_SET_RTN(xvap, XAT_NOUNLINK);
823 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
824 ZFS_ATTR_SET(zp, ZFS_APPENDONLY, xoap->xoa_appendonly);
825 XVA_SET_RTN(xvap, XAT_APPENDONLY);
827 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
828 ZFS_ATTR_SET(zp, ZFS_NODUMP, xoap->xoa_nodump);
829 XVA_SET_RTN(xvap, XAT_NODUMP);
831 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
832 ZFS_ATTR_SET(zp, ZFS_OPAQUE, xoap->xoa_opaque);
833 XVA_SET_RTN(xvap, XAT_OPAQUE);
835 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
836 ZFS_ATTR_SET(zp, ZFS_AV_QUARANTINED,
837 xoap->xoa_av_quarantined);
838 XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
840 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
841 ZFS_ATTR_SET(zp, ZFS_AV_MODIFIED, xoap->xoa_av_modified);
842 XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
844 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
845 (void) memcpy(zp->z_phys + 1, xoap->xoa_av_scanstamp,
846 sizeof (xoap->xoa_av_scanstamp));
847 zp->z_phys->zp_flags |= ZFS_BONUS_SCANSTAMP;
848 XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
853 zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
855 dmu_object_info_t doi;
863 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
865 err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
867 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
871 dmu_object_info_from_db(db, &doi);
872 if (doi.doi_bonus_type != DMU_OT_ZNODE ||
873 doi.doi_bonus_size < sizeof (znode_phys_t)) {
874 dmu_buf_rele(db, NULL);
875 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
879 zp = dmu_buf_get_user(db);
881 mutex_enter(&zp->z_lock);
884 * Since we do immediate eviction of the z_dbuf, we
885 * should never find a dbuf with a znode that doesn't
886 * know about the dbuf.
888 ASSERT3P(zp->z_dbuf, ==, db);
889 ASSERT3U(zp->z_id, ==, obj_num);
890 if (zp->z_unlinked) {
893 if ((vp = ZTOV(zp)) != NULL) {
895 if ((vp->v_iflag & VI_DOOMED) != 0) {
905 ZFS_LOG(1, "dying znode detected (zp=%p)", zp);
909 * znode is dying so we can't reuse it, we must
910 * wait until destruction is completed.
912 dmu_buf_rele(db, NULL);
913 mutex_exit(&zp->z_lock);
914 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
915 tsleep(zp, 0, "zcollide", 1);
921 dmu_buf_rele(db, NULL);
922 mutex_exit(&zp->z_lock);
923 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
928 * Not found create new znode/vnode
930 zp = zfs_znode_alloc(zfsvfs, db, doi.doi_data_block_size);
933 vp->v_vflag |= VV_FORCEINSMQ;
934 err = insmntque(vp, zfsvfs->z_vfs);
935 vp->v_vflag &= ~VV_FORCEINSMQ;
936 KASSERT(err == 0, ("insmntque() failed: error %d", err));
939 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
945 zfs_rezget(znode_t *zp)
947 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
948 dmu_object_info_t doi;
950 uint64_t obj_num = zp->z_id;
953 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
955 err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
957 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
961 dmu_object_info_from_db(db, &doi);
962 if (doi.doi_bonus_type != DMU_OT_ZNODE ||
963 doi.doi_bonus_size < sizeof (znode_phys_t)) {
964 dmu_buf_rele(db, NULL);
965 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
969 if (((znode_phys_t *)db->db_data)->zp_gen != zp->z_gen) {
970 dmu_buf_rele(db, NULL);
971 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
975 zfs_znode_dmu_init(zfsvfs, zp, db);
976 zp->z_unlinked = (zp->z_phys->zp_links == 0);
977 zp->z_blksz = doi.doi_data_block_size;
979 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
985 zfs_znode_delete(znode_t *zp, dmu_tx_t *tx)
987 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
988 objset_t *os = zfsvfs->z_os;
989 uint64_t obj = zp->z_id;
990 uint64_t acl_obj = zp->z_phys->zp_acl.z_acl_extern_obj;
992 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
994 VERIFY(0 == dmu_object_free(os, acl_obj, tx));
995 VERIFY(0 == dmu_object_free(os, obj, tx));
996 zfs_znode_dmu_fini(zp);
997 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
1002 zfs_zinactive(znode_t *zp)
1004 vnode_t *vp = ZTOV(zp);
1005 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1006 uint64_t z_id = zp->z_id;
1008 ASSERT(zp->z_dbuf && zp->z_phys);
1011 * Don't allow a zfs_zget() while were trying to release this znode
1013 ZFS_OBJ_HOLD_ENTER(zfsvfs, z_id);
1015 mutex_enter(&zp->z_lock);
1017 if (vp->v_count > 0) {
1019 * If the hold count is greater than zero, somebody has
1020 * obtained a new reference on this znode while we were
1021 * processing it here, so we are done.
1024 mutex_exit(&zp->z_lock);
1025 ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
1031 * If this was the last reference to a file with no links,
1032 * remove the file from the file system.
1034 if (zp->z_unlinked) {
1035 mutex_exit(&zp->z_lock);
1036 ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
1037 ASSERT(vp->v_count == 0);
1038 vrecycle(vp, curthread);
1042 mutex_exit(&zp->z_lock);
1043 ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
1047 zfs_znode_free(znode_t *zp)
1049 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1051 ASSERT(ZTOV(zp) == NULL);
1052 mutex_enter(&zfsvfs->z_znodes_lock);
1053 POINTER_INVALIDATE(&zp->z_zfsvfs);
1054 list_remove(&zfsvfs->z_all_znodes, zp);
1055 mutex_exit(&zfsvfs->z_znodes_lock);
1057 kmem_cache_free(znode_cache, zp);
1059 VFS_RELE(zfsvfs->z_vfs);
1063 zfs_time_stamper_locked(znode_t *zp, uint_t flag, dmu_tx_t *tx)
1067 ASSERT(MUTEX_HELD(&zp->z_lock));
1072 dmu_buf_will_dirty(zp->z_dbuf, tx);
1073 zp->z_atime_dirty = 0;
1076 zp->z_atime_dirty = 1;
1079 if (flag & AT_ATIME)
1080 ZFS_TIME_ENCODE(&now, zp->z_phys->zp_atime);
1082 if (flag & AT_MTIME) {
1083 ZFS_TIME_ENCODE(&now, zp->z_phys->zp_mtime);
1084 if (zp->z_zfsvfs->z_use_fuids)
1085 zp->z_phys->zp_flags |= (ZFS_ARCHIVE | ZFS_AV_MODIFIED);
1088 if (flag & AT_CTIME) {
1089 ZFS_TIME_ENCODE(&now, zp->z_phys->zp_ctime);
1090 if (zp->z_zfsvfs->z_use_fuids)
1091 zp->z_phys->zp_flags |= ZFS_ARCHIVE;
1096 * Update the requested znode timestamps with the current time.
1097 * If we are in a transaction, then go ahead and mark the znode
1098 * dirty in the transaction so the timestamps will go to disk.
1099 * Otherwise, we will get pushed next time the znode is updated
1100 * in a transaction, or when this znode eventually goes inactive.
1103 * 1 - Only the ACCESS time is ever updated outside of a transaction.
1104 * 2 - Multiple consecutive updates will be collapsed into a single
1105 * znode update by the transaction grouping semantics of the DMU.
1108 zfs_time_stamper(znode_t *zp, uint_t flag, dmu_tx_t *tx)
1110 mutex_enter(&zp->z_lock);
1111 zfs_time_stamper_locked(zp, flag, tx);
1112 mutex_exit(&zp->z_lock);
1116 * Grow the block size for a file.
1118 * IN: zp - znode of file to free data in.
1119 * size - requested block size
1120 * tx - open transaction.
1122 * NOTE: this function assumes that the znode is write locked.
1125 zfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
1130 if (size <= zp->z_blksz)
1133 * If the file size is already greater than the current blocksize,
1134 * we will not grow. If there is more than one block in a file,
1135 * the blocksize cannot change.
1137 if (zp->z_blksz && zp->z_phys->zp_size > zp->z_blksz)
1140 error = dmu_object_set_blocksize(zp->z_zfsvfs->z_os, zp->z_id,
1142 if (error == ENOTSUP)
1144 ASSERT3U(error, ==, 0);
1146 /* What blocksize did we actually get? */
1147 dmu_object_size_from_db(zp->z_dbuf, &zp->z_blksz, &dummy);
1151 * Increase the file length
1153 * IN: zp - znode of file to free data in.
1154 * end - new end-of-file
1156 * RETURN: 0 if success
1157 * error code if failure
1160 zfs_extend(znode_t *zp, uint64_t end)
1162 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1169 * We will change zp_size, lock the whole file.
1171 rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
1174 * Nothing to do if file already at desired length.
1176 if (end <= zp->z_phys->zp_size) {
1177 zfs_range_unlock(rl);
1181 tx = dmu_tx_create(zfsvfs->z_os);
1182 dmu_tx_hold_bonus(tx, zp->z_id);
1183 if (end > zp->z_blksz &&
1184 (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
1186 * We are growing the file past the current block size.
1188 if (zp->z_blksz > zp->z_zfsvfs->z_max_blksz) {
1189 ASSERT(!ISP2(zp->z_blksz));
1190 newblksz = MIN(end, SPA_MAXBLOCKSIZE);
1192 newblksz = MIN(end, zp->z_zfsvfs->z_max_blksz);
1194 dmu_tx_hold_write(tx, zp->z_id, 0, newblksz);
1199 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1201 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
1207 zfs_range_unlock(rl);
1210 dmu_buf_will_dirty(zp->z_dbuf, tx);
1213 zfs_grow_blocksize(zp, newblksz, tx);
1215 zp->z_phys->zp_size = end;
1217 zfs_range_unlock(rl);
1221 rw_enter(&zp->z_map_lock, RW_WRITER);
1222 error = vinvalbuf(ZTOV(zp), V_SAVE, 0, 0);
1224 vnode_pager_setsize(ZTOV(zp), end);
1225 rw_exit(&zp->z_map_lock);
1231 * Free space in a file.
1233 * IN: zp - znode of file to free data in.
1234 * off - start of section to free.
1235 * len - length of section to free.
1237 * RETURN: 0 if success
1238 * error code if failure
1241 zfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
1243 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1248 * Lock the range being freed.
1250 rl = zfs_range_lock(zp, off, len, RL_WRITER);
1253 * Nothing to do if file already at desired length.
1255 if (off >= zp->z_phys->zp_size) {
1256 zfs_range_unlock(rl);
1260 if (off + len > zp->z_phys->zp_size)
1261 len = zp->z_phys->zp_size - off;
1263 error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, off, len);
1267 * In FreeBSD we cannot free block in the middle of a file,
1268 * but only at the end of a file.
1270 rw_enter(&zp->z_map_lock, RW_WRITER);
1271 error = vinvalbuf(ZTOV(zp), V_SAVE, 0, 0);
1273 vnode_pager_setsize(ZTOV(zp), off);
1274 rw_exit(&zp->z_map_lock);
1277 zfs_range_unlock(rl);
1285 * IN: zp - znode of file to free data in.
1286 * end - new end-of-file.
1288 * RETURN: 0 if success
1289 * error code if failure
1292 zfs_trunc(znode_t *zp, uint64_t end)
1294 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1295 vnode_t *vp = ZTOV(zp);
1301 * We will change zp_size, lock the whole file.
1303 rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
1306 * Nothing to do if file already at desired length.
1308 if (end >= zp->z_phys->zp_size) {
1309 zfs_range_unlock(rl);
1313 error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, end, -1);
1315 zfs_range_unlock(rl);
1319 tx = dmu_tx_create(zfsvfs->z_os);
1320 dmu_tx_hold_bonus(tx, zp->z_id);
1321 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1323 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
1329 zfs_range_unlock(rl);
1332 dmu_buf_will_dirty(zp->z_dbuf, tx);
1334 zp->z_phys->zp_size = end;
1338 zfs_range_unlock(rl);
1341 * Clear any mapped pages in the truncated region. This has to
1342 * happen outside of the transaction to avoid the possibility of
1343 * a deadlock with someone trying to push a page that we are
1344 * about to invalidate.
1346 rw_enter(&zp->z_map_lock, RW_WRITER);
1348 error = vtruncbuf(vp, curthread->td_ucred, curthread, end, PAGE_SIZE);
1350 error = vinvalbuf(vp, V_SAVE, 0, 0);
1352 vnode_pager_setsize(vp, end);
1354 rw_exit(&zp->z_map_lock);
1360 * Free space in a file
1362 * IN: zp - znode of file to free data in.
1363 * off - start of range
1364 * len - end of range (0 => EOF)
1365 * flag - current file open mode flags.
1366 * log - TRUE if this action should be logged
1368 * RETURN: 0 if success
1369 * error code if failure
1372 zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
1374 vnode_t *vp = ZTOV(zp);
1376 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1377 zilog_t *zilog = zfsvfs->z_log;
1380 if (off > zp->z_phys->zp_size) {
1381 error = zfs_extend(zp, off+len);
1382 if (error == 0 && log)
1389 error = zfs_trunc(zp, off);
1391 if ((error = zfs_free_range(zp, off, len)) == 0 &&
1392 off + len > zp->z_phys->zp_size)
1393 error = zfs_extend(zp, off+len);
1398 tx = dmu_tx_create(zfsvfs->z_os);
1399 dmu_tx_hold_bonus(tx, zp->z_id);
1400 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1402 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
1411 zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
1412 zfs_log_truncate(zilog, tx, TX_TRUNCATE, zp, off, len);
1419 zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
1422 uint64_t moid, doid, version;
1423 uint64_t sense = ZFS_CASE_SENSITIVE;
1427 znode_t *rootzp = NULL;
1433 * First attempt to create master node.
1436 * In an empty objset, there are no blocks to read and thus
1437 * there can be no i/o errors (which we assert below).
1439 moid = MASTER_NODE_OBJ;
1440 error = zap_create_claim(os, moid, DMU_OT_MASTER_NODE,
1441 DMU_OT_NONE, 0, tx);
1445 * Set starting attributes.
1447 if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_FUID)
1448 version = ZPL_VERSION;
1450 version = ZPL_VERSION_FUID - 1;
1451 error = zap_update(os, moid, ZPL_VERSION_STR,
1452 8, 1, &version, tx);
1454 while ((elem = nvlist_next_nvpair(zplprops, elem)) != NULL) {
1455 /* For the moment we expect all zpl props to be uint64_ts */
1459 ASSERT(nvpair_type(elem) == DATA_TYPE_UINT64);
1460 VERIFY(nvpair_value_uint64(elem, &val) == 0);
1461 name = nvpair_name(elem);
1462 if (strcmp(name, zfs_prop_to_name(ZFS_PROP_VERSION)) == 0) {
1464 error = zap_update(os, moid, ZPL_VERSION_STR,
1465 8, 1, &version, tx);
1467 error = zap_update(os, moid, name, 8, 1, &val, tx);
1470 if (strcmp(name, zfs_prop_to_name(ZFS_PROP_NORMALIZE)) == 0)
1472 else if (strcmp(name, zfs_prop_to_name(ZFS_PROP_CASE)) == 0)
1475 ASSERT(version != 0);
1478 * Create a delete queue.
1480 doid = zap_create(os, DMU_OT_UNLINKED_SET, DMU_OT_NONE, 0, tx);
1482 error = zap_add(os, moid, ZFS_UNLINKED_SET, 8, 1, &doid, tx);
1486 * Create root znode. Create minimal znode/vnode/zfsvfs
1487 * to allow zfs_mknode to work.
1490 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
1491 vattr.va_type = VDIR;
1492 vattr.va_mode = S_IFDIR|0755;
1493 vattr.va_uid = crgetuid(cr);
1494 vattr.va_gid = crgetgid(cr);
1496 rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP);
1497 zfs_znode_cache_constructor(rootzp, &zfsvfs, 0);
1498 rootzp->z_unlinked = 0;
1499 rootzp->z_atime_dirty = 0;
1505 bzero(&zfsvfs, sizeof (zfsvfs_t));
1508 zfsvfs.z_assign = TXG_NOWAIT;
1509 zfsvfs.z_parent = &zfsvfs;
1510 zfsvfs.z_version = version;
1511 zfsvfs.z_use_fuids = USE_FUIDS(version, os);
1512 zfsvfs.z_norm = norm;
1514 * Fold case on file systems that are always or sometimes case
1517 if (sense == ZFS_CASE_INSENSITIVE || sense == ZFS_CASE_MIXED)
1518 zfsvfs.z_norm |= U8_TEXTPREP_TOUPPER;
1520 mutex_init(&zfsvfs.z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
1521 list_create(&zfsvfs.z_all_znodes, sizeof (znode_t),
1522 offsetof(znode_t, z_link_node));
1524 ASSERT(!POINTER_IS_VALID(rootzp->z_zfsvfs));
1525 rootzp->z_zfsvfs = &zfsvfs;
1526 zfs_mknode(rootzp, &vattr, tx, cr, IS_ROOT_NODE, &zp, 0, NULL, NULL);
1527 ASSERT3P(zp, ==, rootzp);
1528 error = zap_add(os, moid, ZFS_ROOT_OBJ, 8, 1, &rootzp->z_id, tx);
1530 POINTER_INVALIDATE(&rootzp->z_zfsvfs);
1533 ZTOV(rootzp)->v_data = NULL;
1534 ZTOV(rootzp)->v_count = 0;
1535 ZTOV(rootzp)->v_holdcnt = 0;
1536 rootzp->z_vnode = NULL;
1539 dmu_buf_rele(rootzp->z_dbuf, NULL);
1540 rootzp->z_dbuf = NULL;
1541 mutex_destroy(&zfsvfs.z_znodes_lock);
1542 kmem_cache_free(znode_cache, rootzp);
1545 #endif /* _KERNEL */
1547 * Given an object number, return its parent object number and whether
1548 * or not the object is an extended attribute directory.
1551 zfs_obj_to_pobj(objset_t *osp, uint64_t obj, uint64_t *pobjp, int *is_xattrdir)
1554 dmu_object_info_t doi;
1558 if ((error = dmu_bonus_hold(osp, obj, FTAG, &db)) != 0)
1561 dmu_object_info_from_db(db, &doi);
1562 if (doi.doi_bonus_type != DMU_OT_ZNODE ||
1563 doi.doi_bonus_size < sizeof (znode_phys_t)) {
1564 dmu_buf_rele(db, FTAG);
1569 *pobjp = zp->zp_parent;
1570 *is_xattrdir = ((zp->zp_flags & ZFS_XATTR) != 0) &&
1571 S_ISDIR(zp->zp_mode);
1572 dmu_buf_rele(db, FTAG);
1578 zfs_obj_to_path(objset_t *osp, uint64_t obj, char *buf, int len)
1580 char *path = buf + len - 1;
1587 char component[MAXNAMELEN + 2];
1591 if ((error = zfs_obj_to_pobj(osp, obj, &pobj,
1592 &is_xattrdir)) != 0)
1603 (void) sprintf(component + 1, "<xattrdir>");
1605 error = zap_value_search(osp, pobj, obj,
1606 ZFS_DIRENT_OBJ(-1ULL), component + 1);
1611 complen = strlen(component);
1613 ASSERT(path >= buf);
1614 bcopy(component, path, complen);
1619 (void) memmove(buf, path, buf + len - path);