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 2009 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.
91 * Needed to close a small window in zfs_znode_move() that allows the zfsvfs to
92 * be freed before it can be safely accessed.
94 krwlock_t zfsvfs_lock;
96 static kmem_cache_t *znode_cache = NULL;
100 znode_evict_error(dmu_buf_t *dbuf, void *user_ptr)
102 #if 1 /* XXXPJD: From OpenSolaris. */
104 * We should never drop all dbuf refs without first clearing
105 * the eviction callback.
107 panic("evicting znode %p\n", user_ptr);
109 znode_t *zp = user_ptr;
112 mutex_enter(&zp->z_lock);
116 mutex_exit(&zp->z_lock);
118 } else if (vp->v_count == 0) {
121 mutex_exit(&zp->z_lock);
122 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
123 vrecycle(vp, curthread);
128 mutex_exit(&zp->z_lock);
133 extern struct vop_vector zfs_vnodeops;
134 extern struct vop_vector zfs_fifoops;
135 extern struct vop_vector zfs_shareops;
138 * XXX: We cannot use this function as a cache constructor, because
139 * there is one global cache for all file systems and we need
140 * to pass vfsp here, which is not possible, because argument
141 * 'cdrarg' is defined at kmem_cache_create() time.
144 zfs_znode_cache_constructor(void *buf, void *arg, int kmflags)
151 POINTER_INVALIDATE(&zp->z_zfsvfs);
152 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
155 error = getnewvnode("zfs", vfsp, &zfs_vnodeops, &vp);
156 if (error != 0 && (kmflags & KM_NOSLEEP))
159 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
161 vp->v_data = (caddr_t)zp;
167 list_link_init(&zp->z_link_node);
169 mutex_init(&zp->z_lock, NULL, MUTEX_DEFAULT, NULL);
170 rw_init(&zp->z_parent_lock, NULL, RW_DEFAULT, NULL);
171 rw_init(&zp->z_name_lock, NULL, RW_DEFAULT, NULL);
172 mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
174 mutex_init(&zp->z_range_lock, NULL, MUTEX_DEFAULT, NULL);
175 avl_create(&zp->z_range_avl, zfs_range_compare,
176 sizeof (rl_t), offsetof(rl_t, r_node));
179 zp->z_dirlocks = NULL;
180 zp->z_acl_cached = NULL;
186 zfs_znode_cache_destructor(void *buf, void *arg)
190 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
191 ASSERT(ZTOV(zp) == NULL);
193 ASSERT(!list_link_active(&zp->z_link_node));
194 mutex_destroy(&zp->z_lock);
195 rw_destroy(&zp->z_parent_lock);
196 rw_destroy(&zp->z_name_lock);
197 mutex_destroy(&zp->z_acl_lock);
198 avl_destroy(&zp->z_range_avl);
199 mutex_destroy(&zp->z_range_lock);
201 ASSERT(zp->z_dbuf == NULL);
202 ASSERT(zp->z_dirlocks == NULL);
203 ASSERT(zp->z_acl_cached == NULL);
208 uint64_t zms_zfsvfs_invalid;
209 uint64_t zms_zfsvfs_recheck1;
210 uint64_t zms_zfsvfs_unmounted;
211 uint64_t zms_zfsvfs_recheck2;
212 uint64_t zms_obj_held;
213 uint64_t zms_vnode_locked;
214 uint64_t zms_not_only_dnlc;
216 #endif /* ZNODE_STATS */
220 zfs_znode_move_impl(znode_t *ozp, znode_t *nzp)
225 nzp->z_zfsvfs = ozp->z_zfsvfs;
229 nzp->z_vnode = ozp->z_vnode;
230 ozp->z_vnode = vp; /* let destructor free the overwritten vnode */
231 ZTOV(ozp)->v_data = ozp;
232 ZTOV(nzp)->v_data = nzp;
234 nzp->z_id = ozp->z_id;
235 ASSERT(ozp->z_dirlocks == NULL); /* znode not in use */
236 ASSERT(avl_numnodes(&ozp->z_range_avl) == 0);
237 nzp->z_unlinked = ozp->z_unlinked;
238 nzp->z_atime_dirty = ozp->z_atime_dirty;
239 nzp->z_zn_prefetch = ozp->z_zn_prefetch;
240 nzp->z_blksz = ozp->z_blksz;
241 nzp->z_seq = ozp->z_seq;
242 nzp->z_mapcnt = ozp->z_mapcnt;
243 nzp->z_last_itx = ozp->z_last_itx;
244 nzp->z_gen = ozp->z_gen;
245 nzp->z_sync_cnt = ozp->z_sync_cnt;
246 nzp->z_phys = ozp->z_phys;
247 nzp->z_dbuf = ozp->z_dbuf;
250 * Since this is just an idle znode and kmem is already dealing with
251 * memory pressure, release any cached ACL.
253 if (ozp->z_acl_cached) {
254 zfs_acl_free(ozp->z_acl_cached);
255 ozp->z_acl_cached = NULL;
258 /* Update back pointers. */
259 (void) dmu_buf_update_user(nzp->z_dbuf, ozp, nzp, &nzp->z_phys,
263 * Invalidate the original znode by clearing fields that provide a
264 * pointer back to the znode. Set the low bit of the vfs pointer to
265 * ensure that zfs_znode_move() recognizes the znode as invalid in any
266 * subsequent callback.
269 POINTER_INVALIDATE(&ozp->z_zfsvfs);
274 zfs_znode_move(void *buf, void *newbuf, size_t size, void *arg)
276 znode_t *ozp = buf, *nzp = newbuf;
281 * The znode is on the file system's list of known znodes if the vfs
282 * pointer is valid. We set the low bit of the vfs pointer when freeing
283 * the znode to invalidate it, and the memory patterns written by kmem
284 * (baddcafe and deadbeef) set at least one of the two low bits. A newly
285 * created znode sets the vfs pointer last of all to indicate that the
286 * znode is known and in a valid state to be moved by this function.
288 zfsvfs = ozp->z_zfsvfs;
289 if (!POINTER_IS_VALID(zfsvfs)) {
290 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_invalid);
291 return (KMEM_CBRC_DONT_KNOW);
295 * Close a small window in which it's possible that the filesystem could
296 * be unmounted and freed, and zfsvfs, though valid in the previous
297 * statement, could point to unrelated memory by the time we try to
298 * prevent the filesystem from being unmounted.
300 rw_enter(&zfsvfs_lock, RW_WRITER);
301 if (zfsvfs != ozp->z_zfsvfs) {
302 rw_exit(&zfsvfs_lock);
303 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck1);
304 return (KMEM_CBRC_DONT_KNOW);
308 * If the znode is still valid, then so is the file system. We know that
309 * no valid file system can be freed while we hold zfsvfs_lock, so we
310 * can safely ensure that the filesystem is not and will not be
311 * unmounted. The next statement is equivalent to ZFS_ENTER().
313 rrw_enter(&zfsvfs->z_teardown_lock, RW_READER, FTAG);
314 if (zfsvfs->z_unmounted) {
316 rw_exit(&zfsvfs_lock);
317 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_unmounted);
318 return (KMEM_CBRC_DONT_KNOW);
320 rw_exit(&zfsvfs_lock);
322 mutex_enter(&zfsvfs->z_znodes_lock);
324 * Recheck the vfs pointer in case the znode was removed just before
325 * acquiring the lock.
327 if (zfsvfs != ozp->z_zfsvfs) {
328 mutex_exit(&zfsvfs->z_znodes_lock);
330 ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck2);
331 return (KMEM_CBRC_DONT_KNOW);
335 * At this point we know that as long as we hold z_znodes_lock, the
336 * znode cannot be freed and fields within the znode can be safely
337 * accessed. Now, prevent a race with zfs_zget().
339 if (ZFS_OBJ_HOLD_TRYENTER(zfsvfs, ozp->z_id) == 0) {
340 mutex_exit(&zfsvfs->z_znodes_lock);
342 ZNODE_STAT_ADD(znode_move_stats.zms_obj_held);
343 return (KMEM_CBRC_LATER);
347 if (mutex_tryenter(&vp->v_lock) == 0) {
348 ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
349 mutex_exit(&zfsvfs->z_znodes_lock);
351 ZNODE_STAT_ADD(znode_move_stats.zms_vnode_locked);
352 return (KMEM_CBRC_LATER);
355 /* Only move znodes that are referenced _only_ by the DNLC. */
356 if (vp->v_count != 1 || !vn_in_dnlc(vp)) {
357 mutex_exit(&vp->v_lock);
358 ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
359 mutex_exit(&zfsvfs->z_znodes_lock);
361 ZNODE_STAT_ADD(znode_move_stats.zms_not_only_dnlc);
362 return (KMEM_CBRC_LATER);
366 * The znode is known and in a valid state to move. We're holding the
367 * locks needed to execute the critical section.
369 zfs_znode_move_impl(ozp, nzp);
370 mutex_exit(&vp->v_lock);
371 ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
373 list_link_replace(&ozp->z_link_node, &nzp->z_link_node);
374 mutex_exit(&zfsvfs->z_znodes_lock);
377 return (KMEM_CBRC_YES);
387 rw_init(&zfsvfs_lock, NULL, RW_DEFAULT, NULL);
388 ASSERT(znode_cache == NULL);
389 znode_cache = kmem_cache_create("zfs_znode_cache",
390 sizeof (znode_t), 0, /* zfs_znode_cache_constructor */ NULL,
391 zfs_znode_cache_destructor, NULL, NULL, NULL, 0);
393 kmem_cache_set_move(znode_cache, zfs_znode_move);
404 kmem_cache_destroy(znode_cache);
406 rw_destroy(&zfsvfs_lock);
410 zfs_create_share_dir(zfsvfs_t *zfsvfs, dmu_tx_t *tx)
412 zfs_acl_ids_t acl_ids;
419 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
420 vattr.va_type = VDIR;
421 vattr.va_mode = S_IFDIR|0555;
422 vattr.va_uid = crgetuid(kcred);
423 vattr.va_gid = crgetgid(kcred);
425 sharezp = kmem_cache_alloc(znode_cache, KM_SLEEP);
426 zfs_znode_cache_constructor(sharezp, zfsvfs->z_parent->z_vfs, 0);
427 sharezp->z_unlinked = 0;
428 sharezp->z_atime_dirty = 0;
429 sharezp->z_zfsvfs = zfsvfs;
431 sharezp->z_vnode = &vnode;
432 vnode.v_data = sharezp;
437 VERIFY(0 == zfs_acl_ids_create(sharezp, IS_ROOT_NODE, &vattr,
438 kcred, NULL, &acl_ids));
439 zfs_mknode(sharezp, &vattr, tx, kcred, IS_ROOT_NODE,
441 ASSERT3P(zp, ==, sharezp);
442 POINTER_INVALIDATE(&sharezp->z_zfsvfs);
443 error = zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
444 ZFS_SHARES_DIR, 8, 1, &sharezp->z_id, tx);
445 zfsvfs->z_shares_dir = sharezp->z_id;
447 zfs_acl_ids_free(&acl_ids);
448 ZTOV(sharezp)->v_data = NULL;
449 ZTOV(sharezp)->v_count = 0;
450 ZTOV(sharezp)->v_holdcnt = 0;
452 sharezp->z_vnode = NULL;
453 dmu_buf_rele(sharezp->z_dbuf, NULL);
454 sharezp->z_dbuf = NULL;
455 kmem_cache_free(znode_cache, sharezp);
461 * define a couple of values we need available
462 * for both 64 and 32 bit environments.
465 #define NBITSMINOR64 32
468 #define MAXMAJ64 0xffffffffUL
471 #define MAXMIN64 0xffffffffUL
475 * Create special expldev for ZFS private use.
476 * Can't use standard expldev since it doesn't do
477 * what we want. The standard expldev() takes a
478 * dev32_t in LP64 and expands it to a long dev_t.
479 * We need an interface that takes a dev32_t in ILP32
480 * and expands it to a long dev_t.
483 zfs_expldev(dev_t dev)
485 return (((uint64_t)major(dev) << NBITSMINOR64) | minor(dev));
488 * Special cmpldev for ZFS private use.
489 * Can't use standard cmpldev since it takes
490 * a long dev_t and compresses it to dev32_t in
491 * LP64. We need to do a compaction of a long dev_t
492 * to a dev32_t in ILP32.
495 zfs_cmpldev(uint64_t dev)
497 return (makedev((dev >> NBITSMINOR64), (dev & MAXMIN64)));
501 zfs_znode_dmu_init(zfsvfs_t *zfsvfs, znode_t *zp, dmu_buf_t *db)
505 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs) || (zfsvfs == zp->z_zfsvfs));
506 ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zfsvfs, zp->z_id)));
508 mutex_enter(&zp->z_lock);
510 ASSERT(zp->z_dbuf == NULL);
511 ASSERT(zp->z_acl_cached == NULL);
513 nzp = dmu_buf_set_user_ie(db, zp, &zp->z_phys, znode_evict_error);
517 * concurrent zgets on this object.
520 panic("existing znode %p for dbuf %p", (void *)nzp, (void *)db);
523 * Slap on VROOT if we are the root znode
525 if (zp->z_id == zfsvfs->z_root)
526 ZTOV(zp)->v_flag |= VROOT;
528 mutex_exit(&zp->z_lock);
533 zfs_znode_dmu_fini(znode_t *zp)
535 dmu_buf_t *db = zp->z_dbuf;
536 ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp->z_zfsvfs, zp->z_id)) ||
538 RW_WRITE_HELD(&zp->z_zfsvfs->z_teardown_inactive_lock));
539 ASSERT(zp->z_dbuf != NULL);
541 VERIFY(zp == dmu_buf_update_user(db, zp, NULL, NULL, NULL));
542 dmu_buf_rele(db, NULL);
546 * Construct a new znode/vnode and intialize.
548 * This does not do a call to dmu_set_user() that is
549 * up to the caller to do, in case you don't want to
553 zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz)
558 zp = kmem_cache_alloc(znode_cache, KM_SLEEP);
559 zfs_znode_cache_constructor(zp, zfsvfs->z_parent->z_vfs, 0);
561 ASSERT(zp->z_dirlocks == NULL);
562 ASSERT(zp->z_dbuf == NULL);
563 ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
566 * Defer setting z_zfsvfs until the znode is ready to be a candidate for
567 * the zfs_znode_move() callback.
571 zp->z_atime_dirty = 0;
574 zp->z_id = db->db_object;
576 zp->z_seq = 0x7A4653;
584 zfs_znode_dmu_init(zfsvfs, zp, db);
586 zp->z_gen = zp->z_phys->zp_gen;
593 vp->v_type = IFTOVT((mode_t)zp->z_phys->zp_mode);
594 switch (vp->v_type) {
596 zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */
599 vp->v_op = &zfs_fifoops;
602 if (zp->z_phys->zp_parent == zfsvfs->z_shares_dir) {
603 vp->v_op = &zfs_shareops;
607 if (vp->v_type != VFIFO)
610 mutex_enter(&zfsvfs->z_znodes_lock);
611 list_insert_tail(&zfsvfs->z_all_znodes, zp);
614 * Everything else must be valid before assigning z_zfsvfs makes the
615 * znode eligible for zfs_znode_move().
617 zp->z_zfsvfs = zfsvfs;
618 mutex_exit(&zfsvfs->z_znodes_lock);
620 VFS_HOLD(zfsvfs->z_vfs);
625 * Create a new DMU object to hold a zfs znode.
627 * IN: dzp - parent directory for new znode
628 * vap - file attributes for new znode
629 * tx - dmu transaction id for zap operations
630 * cr - credentials of caller
632 * IS_ROOT_NODE - new object will be root
633 * IS_XATTR - new object is an attribute
634 * bonuslen - length of bonus buffer
635 * setaclp - File/Dir initial ACL
636 * fuidp - Tracks fuid allocation.
638 * OUT: zpp - allocated znode
642 zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
643 uint_t flag, znode_t **zpp, int bonuslen, zfs_acl_ids_t *acl_ids)
647 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
652 ASSERT(vap && (vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
654 if (zfsvfs->z_replay) {
655 obj = vap->va_nodeid;
656 now = vap->va_ctime; /* see zfs_replay_create() */
657 gen = vap->va_nblocks; /* ditto */
661 gen = dmu_tx_get_txg(tx);
665 * Create a new DMU object.
668 * There's currently no mechanism for pre-reading the blocks that will
669 * be to needed allocate a new object, so we accept the small chance
670 * that there will be an i/o error and we will fail one of the
673 if (vap->va_type == VDIR) {
674 if (zfsvfs->z_replay) {
675 err = zap_create_claim_norm(zfsvfs->z_os, obj,
676 zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
677 DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
678 ASSERT3U(err, ==, 0);
680 obj = zap_create_norm(zfsvfs->z_os,
681 zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
682 DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
685 if (zfsvfs->z_replay) {
686 err = dmu_object_claim(zfsvfs->z_os, obj,
687 DMU_OT_PLAIN_FILE_CONTENTS, 0,
688 DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
689 ASSERT3U(err, ==, 0);
691 obj = dmu_object_alloc(zfsvfs->z_os,
692 DMU_OT_PLAIN_FILE_CONTENTS, 0,
693 DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
697 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
698 VERIFY(0 == dmu_bonus_hold(zfsvfs->z_os, obj, NULL, &db));
699 dmu_buf_will_dirty(db, tx);
702 * Initialize the znode physical data to zero.
704 ASSERT(db->db_size >= sizeof (znode_phys_t));
705 bzero(db->db_data, db->db_size);
709 * If this is the root, fix up the half-initialized parent pointer
710 * to reference the just-allocated physical data area.
712 if (flag & IS_ROOT_NODE) {
719 * If parent is an xattr, so am I.
721 if (dzp->z_phys->zp_flags & ZFS_XATTR)
724 if (vap->va_type == VBLK || vap->va_type == VCHR) {
725 pzp->zp_rdev = zfs_expldev(vap->va_rdev);
728 if (zfsvfs->z_use_fuids)
729 pzp->zp_flags = ZFS_ARCHIVE | ZFS_AV_MODIFIED;
731 if (vap->va_type == VDIR) {
732 pzp->zp_size = 2; /* contents ("." and "..") */
733 pzp->zp_links = (flag & (IS_ROOT_NODE | IS_XATTR)) ? 2 : 1;
736 pzp->zp_parent = dzp->z_id;
738 pzp->zp_flags |= ZFS_XATTR;
742 ZFS_TIME_ENCODE(&now, pzp->zp_crtime);
743 ZFS_TIME_ENCODE(&now, pzp->zp_ctime);
745 if (vap->va_mask & AT_ATIME) {
746 ZFS_TIME_ENCODE(&vap->va_atime, pzp->zp_atime);
748 ZFS_TIME_ENCODE(&now, pzp->zp_atime);
751 if (vap->va_mask & AT_MTIME) {
752 ZFS_TIME_ENCODE(&vap->va_mtime, pzp->zp_mtime);
754 ZFS_TIME_ENCODE(&now, pzp->zp_mtime);
757 pzp->zp_mode = MAKEIMODE(vap->va_type, vap->va_mode);
758 if (!(flag & IS_ROOT_NODE)) {
759 *zpp = zfs_znode_alloc(zfsvfs, db, 0);
762 * If we are creating the root node, the "parent" we
763 * passed in is the znode for the root.
767 pzp->zp_uid = acl_ids->z_fuid;
768 pzp->zp_gid = acl_ids->z_fgid;
769 pzp->zp_mode = acl_ids->z_mode;
770 VERIFY(0 == zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx));
771 if (vap->va_mask & AT_XVATTR)
772 zfs_xvattr_set(*zpp, (xvattr_t *)vap);
773 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
774 if (!(flag & IS_ROOT_NODE)) {
778 vp->v_vflag |= VV_FORCEINSMQ;
779 err = insmntque(vp, zfsvfs->z_vfs);
780 vp->v_vflag &= ~VV_FORCEINSMQ;
781 KASSERT(err == 0, ("insmntque() failed: error %d", err));
786 zfs_xvattr_set(znode_t *zp, xvattr_t *xvap)
790 xoap = xva_getxoptattr(xvap);
793 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
794 ZFS_TIME_ENCODE(&xoap->xoa_createtime, zp->z_phys->zp_crtime);
795 XVA_SET_RTN(xvap, XAT_CREATETIME);
797 if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
798 ZFS_ATTR_SET(zp, ZFS_READONLY, xoap->xoa_readonly);
799 XVA_SET_RTN(xvap, XAT_READONLY);
801 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
802 ZFS_ATTR_SET(zp, ZFS_HIDDEN, xoap->xoa_hidden);
803 XVA_SET_RTN(xvap, XAT_HIDDEN);
805 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
806 ZFS_ATTR_SET(zp, ZFS_SYSTEM, xoap->xoa_system);
807 XVA_SET_RTN(xvap, XAT_SYSTEM);
809 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
810 ZFS_ATTR_SET(zp, ZFS_ARCHIVE, xoap->xoa_archive);
811 XVA_SET_RTN(xvap, XAT_ARCHIVE);
813 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
814 ZFS_ATTR_SET(zp, ZFS_IMMUTABLE, xoap->xoa_immutable);
815 XVA_SET_RTN(xvap, XAT_IMMUTABLE);
817 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
818 ZFS_ATTR_SET(zp, ZFS_NOUNLINK, xoap->xoa_nounlink);
819 XVA_SET_RTN(xvap, XAT_NOUNLINK);
821 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
822 ZFS_ATTR_SET(zp, ZFS_APPENDONLY, xoap->xoa_appendonly);
823 XVA_SET_RTN(xvap, XAT_APPENDONLY);
825 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
826 ZFS_ATTR_SET(zp, ZFS_NODUMP, xoap->xoa_nodump);
827 XVA_SET_RTN(xvap, XAT_NODUMP);
829 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
830 ZFS_ATTR_SET(zp, ZFS_OPAQUE, xoap->xoa_opaque);
831 XVA_SET_RTN(xvap, XAT_OPAQUE);
833 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
834 ZFS_ATTR_SET(zp, ZFS_AV_QUARANTINED,
835 xoap->xoa_av_quarantined);
836 XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
838 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
839 ZFS_ATTR_SET(zp, ZFS_AV_MODIFIED, xoap->xoa_av_modified);
840 XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
842 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
843 (void) memcpy(zp->z_phys + 1, xoap->xoa_av_scanstamp,
844 sizeof (xoap->xoa_av_scanstamp));
845 zp->z_phys->zp_flags |= ZFS_BONUS_SCANSTAMP;
846 XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
851 zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
853 dmu_object_info_t doi;
861 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
863 err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
865 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
869 dmu_object_info_from_db(db, &doi);
870 if (doi.doi_bonus_type != DMU_OT_ZNODE ||
871 doi.doi_bonus_size < sizeof (znode_phys_t)) {
872 dmu_buf_rele(db, NULL);
873 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
877 zp = dmu_buf_get_user(db);
879 mutex_enter(&zp->z_lock);
882 * Since we do immediate eviction of the z_dbuf, we
883 * should never find a dbuf with a znode that doesn't
884 * know about the dbuf.
886 ASSERT3P(zp->z_dbuf, ==, db);
887 ASSERT3U(zp->z_id, ==, obj_num);
888 if (zp->z_unlinked) {
898 if ((vp->v_iflag & VI_DOOMED) != 0) {
901 * Don't VN_RELE() vnode here, because
902 * it can call vn_lock() which creates
903 * LOR between vnode lock and znode
904 * lock. We will VN_RELE() the vnode
905 * after droping znode lock.
911 ZFS_LOG(1, "dying znode detected (zp=%p)", zp);
915 * znode is dying so we can't reuse it, we must
916 * wait until destruction is completed.
918 dmu_buf_rele(db, NULL);
919 mutex_exit(&zp->z_lock);
920 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
923 tsleep(zp, 0, "zcollide", 1);
929 dmu_buf_rele(db, NULL);
930 mutex_exit(&zp->z_lock);
931 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
936 * Not found create new znode/vnode
937 * but only if file exists.
939 * There is a small window where zfs_vget() could
940 * find this object while a file create is still in
941 * progress. Since a gen number can never be zero
942 * we will check that to determine if its an allocated
946 if (((znode_phys_t *)db->db_data)->zp_gen != 0) {
947 zp = zfs_znode_alloc(zfsvfs, db, doi.doi_data_block_size);
950 vp->v_vflag |= VV_FORCEINSMQ;
951 err = insmntque(vp, zfsvfs->z_vfs);
952 vp->v_vflag &= ~VV_FORCEINSMQ;
953 KASSERT(err == 0, ("insmntque() failed: error %d", err));
957 dmu_buf_rele(db, NULL);
960 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
965 zfs_rezget(znode_t *zp)
967 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
968 dmu_object_info_t doi;
970 uint64_t obj_num = zp->z_id;
973 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
975 err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
977 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
981 dmu_object_info_from_db(db, &doi);
982 if (doi.doi_bonus_type != DMU_OT_ZNODE ||
983 doi.doi_bonus_size < sizeof (znode_phys_t)) {
984 dmu_buf_rele(db, NULL);
985 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
989 if (((znode_phys_t *)db->db_data)->zp_gen != zp->z_gen) {
990 dmu_buf_rele(db, NULL);
991 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
995 mutex_enter(&zp->z_acl_lock);
996 if (zp->z_acl_cached) {
997 zfs_acl_free(zp->z_acl_cached);
998 zp->z_acl_cached = NULL;
1000 mutex_exit(&zp->z_acl_lock);
1002 zfs_znode_dmu_init(zfsvfs, zp, db);
1003 zp->z_unlinked = (zp->z_phys->zp_links == 0);
1004 zp->z_blksz = doi.doi_data_block_size;
1006 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1012 zfs_znode_delete(znode_t *zp, dmu_tx_t *tx)
1014 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1015 objset_t *os = zfsvfs->z_os;
1016 uint64_t obj = zp->z_id;
1017 uint64_t acl_obj = zp->z_phys->zp_acl.z_acl_extern_obj;
1019 ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
1021 VERIFY(0 == dmu_object_free(os, acl_obj, tx));
1022 VERIFY(0 == dmu_object_free(os, obj, tx));
1023 zfs_znode_dmu_fini(zp);
1024 ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
1029 zfs_zinactive(znode_t *zp)
1031 vnode_t *vp = ZTOV(zp);
1032 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1033 uint64_t z_id = zp->z_id;
1036 ASSERT(zp->z_dbuf && zp->z_phys);
1039 * Don't allow a zfs_zget() while were trying to release this znode
1041 ZFS_OBJ_HOLD_ENTER(zfsvfs, z_id);
1043 mutex_enter(&zp->z_lock);
1045 if (vp->v_count > 0) {
1047 * If the hold count is greater than zero, somebody has
1048 * obtained a new reference on this znode while we were
1049 * processing it here, so we are done.
1052 mutex_exit(&zp->z_lock);
1053 ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
1059 * If this was the last reference to a file with no links,
1060 * remove the file from the file system.
1062 if (zp->z_unlinked) {
1063 mutex_exit(&zp->z_lock);
1064 ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
1065 ASSERT(vp->v_count == 0);
1066 vrecycle(vp, curthread);
1067 vfslocked = VFS_LOCK_GIANT(zfsvfs->z_vfs);
1069 VFS_UNLOCK_GIANT(vfslocked);
1072 mutex_exit(&zp->z_lock);
1073 ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
1077 zfs_znode_free(znode_t *zp)
1079 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1081 ASSERT(ZTOV(zp) == NULL);
1082 mutex_enter(&zfsvfs->z_znodes_lock);
1083 POINTER_INVALIDATE(&zp->z_zfsvfs);
1084 list_remove(&zfsvfs->z_all_znodes, zp);
1085 mutex_exit(&zfsvfs->z_znodes_lock);
1087 if (zp->z_acl_cached) {
1088 zfs_acl_free(zp->z_acl_cached);
1089 zp->z_acl_cached = NULL;
1092 kmem_cache_free(znode_cache, zp);
1094 VFS_RELE(zfsvfs->z_vfs);
1098 zfs_time_stamper_locked(znode_t *zp, uint_t flag, dmu_tx_t *tx)
1102 ASSERT(MUTEX_HELD(&zp->z_lock));
1107 dmu_buf_will_dirty(zp->z_dbuf, tx);
1108 zp->z_atime_dirty = 0;
1111 zp->z_atime_dirty = 1;
1114 if (flag & AT_ATIME)
1115 ZFS_TIME_ENCODE(&now, zp->z_phys->zp_atime);
1117 if (flag & AT_MTIME) {
1118 ZFS_TIME_ENCODE(&now, zp->z_phys->zp_mtime);
1119 if (zp->z_zfsvfs->z_use_fuids)
1120 zp->z_phys->zp_flags |= (ZFS_ARCHIVE | ZFS_AV_MODIFIED);
1123 if (flag & AT_CTIME) {
1124 ZFS_TIME_ENCODE(&now, zp->z_phys->zp_ctime);
1125 if (zp->z_zfsvfs->z_use_fuids)
1126 zp->z_phys->zp_flags |= ZFS_ARCHIVE;
1131 * Update the requested znode timestamps with the current time.
1132 * If we are in a transaction, then go ahead and mark the znode
1133 * dirty in the transaction so the timestamps will go to disk.
1134 * Otherwise, we will get pushed next time the znode is updated
1135 * in a transaction, or when this znode eventually goes inactive.
1138 * 1 - Only the ACCESS time is ever updated outside of a transaction.
1139 * 2 - Multiple consecutive updates will be collapsed into a single
1140 * znode update by the transaction grouping semantics of the DMU.
1143 zfs_time_stamper(znode_t *zp, uint_t flag, dmu_tx_t *tx)
1145 mutex_enter(&zp->z_lock);
1146 zfs_time_stamper_locked(zp, flag, tx);
1147 mutex_exit(&zp->z_lock);
1151 * Grow the block size for a file.
1153 * IN: zp - znode of file to free data in.
1154 * size - requested block size
1155 * tx - open transaction.
1157 * NOTE: this function assumes that the znode is write locked.
1160 zfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
1165 if (size <= zp->z_blksz)
1168 * If the file size is already greater than the current blocksize,
1169 * we will not grow. If there is more than one block in a file,
1170 * the blocksize cannot change.
1172 if (zp->z_blksz && zp->z_phys->zp_size > zp->z_blksz)
1175 error = dmu_object_set_blocksize(zp->z_zfsvfs->z_os, zp->z_id,
1177 if (error == ENOTSUP)
1179 ASSERT3U(error, ==, 0);
1181 /* What blocksize did we actually get? */
1182 dmu_object_size_from_db(zp->z_dbuf, &zp->z_blksz, &dummy);
1186 * Increase the file length
1188 * IN: zp - znode of file to free data in.
1189 * end - new end-of-file
1191 * RETURN: 0 if success
1192 * error code if failure
1195 zfs_extend(znode_t *zp, uint64_t end)
1197 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1204 * We will change zp_size, lock the whole file.
1206 rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
1209 * Nothing to do if file already at desired length.
1211 if (end <= zp->z_phys->zp_size) {
1212 zfs_range_unlock(rl);
1216 tx = dmu_tx_create(zfsvfs->z_os);
1217 dmu_tx_hold_bonus(tx, zp->z_id);
1218 if (end > zp->z_blksz &&
1219 (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
1221 * We are growing the file past the current block size.
1223 if (zp->z_blksz > zp->z_zfsvfs->z_max_blksz) {
1224 ASSERT(!ISP2(zp->z_blksz));
1225 newblksz = MIN(end, SPA_MAXBLOCKSIZE);
1227 newblksz = MIN(end, zp->z_zfsvfs->z_max_blksz);
1229 dmu_tx_hold_write(tx, zp->z_id, 0, newblksz);
1234 error = dmu_tx_assign(tx, TXG_NOWAIT);
1236 if (error == ERESTART) {
1242 zfs_range_unlock(rl);
1245 dmu_buf_will_dirty(zp->z_dbuf, tx);
1248 zfs_grow_blocksize(zp, newblksz, tx);
1250 zp->z_phys->zp_size = end;
1252 zfs_range_unlock(rl);
1256 vnode_pager_setsize(ZTOV(zp), end);
1262 * Free space in a file.
1264 * IN: zp - znode of file to free data in.
1265 * off - start of section to free.
1266 * len - length of section to free.
1268 * RETURN: 0 if success
1269 * error code if failure
1272 zfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
1274 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1279 * Lock the range being freed.
1281 rl = zfs_range_lock(zp, off, len, RL_WRITER);
1284 * Nothing to do if file already at desired length.
1286 if (off >= zp->z_phys->zp_size) {
1287 zfs_range_unlock(rl);
1291 if (off + len > zp->z_phys->zp_size)
1292 len = zp->z_phys->zp_size - off;
1294 error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, off, len);
1298 * In FreeBSD we cannot free block in the middle of a file,
1299 * but only at the end of a file.
1301 vnode_pager_setsize(ZTOV(zp), off);
1304 zfs_range_unlock(rl);
1312 * IN: zp - znode of file to free data in.
1313 * end - new end-of-file.
1315 * RETURN: 0 if success
1316 * error code if failure
1319 zfs_trunc(znode_t *zp, uint64_t end)
1321 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1322 vnode_t *vp = ZTOV(zp);
1328 * We will change zp_size, lock the whole file.
1330 rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
1333 * Nothing to do if file already at desired length.
1335 if (end >= zp->z_phys->zp_size) {
1336 zfs_range_unlock(rl);
1340 error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, end, -1);
1342 zfs_range_unlock(rl);
1346 tx = dmu_tx_create(zfsvfs->z_os);
1347 dmu_tx_hold_bonus(tx, zp->z_id);
1348 error = dmu_tx_assign(tx, TXG_NOWAIT);
1350 if (error == ERESTART) {
1356 zfs_range_unlock(rl);
1359 dmu_buf_will_dirty(zp->z_dbuf, tx);
1361 zp->z_phys->zp_size = end;
1366 * Clear any mapped pages in the truncated region. This has to
1367 * happen outside of the transaction to avoid the possibility of
1368 * a deadlock with someone trying to push a page that we are
1369 * about to invalidate.
1371 vnode_pager_setsize(vp, end);
1373 zfs_range_unlock(rl);
1379 * Free space in a file
1381 * IN: zp - znode of file to free data in.
1382 * off - start of range
1383 * len - end of range (0 => EOF)
1384 * flag - current file open mode flags.
1385 * log - TRUE if this action should be logged
1387 * RETURN: 0 if success
1388 * error code if failure
1391 zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
1393 vnode_t *vp = ZTOV(zp);
1395 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1396 zilog_t *zilog = zfsvfs->z_log;
1399 if (off > zp->z_phys->zp_size) {
1400 error = zfs_extend(zp, off+len);
1401 if (error == 0 && log)
1408 error = zfs_trunc(zp, off);
1410 if ((error = zfs_free_range(zp, off, len)) == 0 &&
1411 off + len > zp->z_phys->zp_size)
1412 error = zfs_extend(zp, off+len);
1417 tx = dmu_tx_create(zfsvfs->z_os);
1418 dmu_tx_hold_bonus(tx, zp->z_id);
1419 error = dmu_tx_assign(tx, TXG_NOWAIT);
1421 if (error == ERESTART) {
1430 zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
1431 zfs_log_truncate(zilog, tx, TX_TRUNCATE, zp, off, len);
1438 zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
1441 uint64_t moid, obj, version;
1442 uint64_t sense = ZFS_CASE_SENSITIVE;
1447 znode_t *rootzp = NULL;
1451 zfs_acl_ids_t acl_ids;
1454 * First attempt to create master node.
1457 * In an empty objset, there are no blocks to read and thus
1458 * there can be no i/o errors (which we assert below).
1460 moid = MASTER_NODE_OBJ;
1461 error = zap_create_claim(os, moid, DMU_OT_MASTER_NODE,
1462 DMU_OT_NONE, 0, tx);
1466 * Set starting attributes.
1468 if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_USERSPACE)
1469 version = ZPL_VERSION;
1470 else if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_FUID)
1471 version = ZPL_VERSION_USERSPACE - 1;
1473 version = ZPL_VERSION_FUID - 1;
1475 while ((elem = nvlist_next_nvpair(zplprops, elem)) != NULL) {
1476 /* For the moment we expect all zpl props to be uint64_ts */
1480 ASSERT(nvpair_type(elem) == DATA_TYPE_UINT64);
1481 VERIFY(nvpair_value_uint64(elem, &val) == 0);
1482 name = nvpair_name(elem);
1483 if (strcmp(name, zfs_prop_to_name(ZFS_PROP_VERSION)) == 0) {
1487 error = zap_update(os, moid, name, 8, 1, &val, tx);
1490 if (strcmp(name, zfs_prop_to_name(ZFS_PROP_NORMALIZE)) == 0)
1492 else if (strcmp(name, zfs_prop_to_name(ZFS_PROP_CASE)) == 0)
1495 ASSERT(version != 0);
1496 error = zap_update(os, moid, ZPL_VERSION_STR, 8, 1, &version, tx);
1499 * Create a delete queue.
1501 obj = zap_create(os, DMU_OT_UNLINKED_SET, DMU_OT_NONE, 0, tx);
1503 error = zap_add(os, moid, ZFS_UNLINKED_SET, 8, 1, &obj, tx);
1507 * Create root znode. Create minimal znode/vnode/zfsvfs
1508 * to allow zfs_mknode to work.
1511 vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
1512 vattr.va_type = VDIR;
1513 vattr.va_mode = S_IFDIR|0755;
1514 vattr.va_uid = crgetuid(cr);
1515 vattr.va_gid = crgetgid(cr);
1517 rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP);
1518 zfs_znode_cache_constructor(rootzp, NULL, 0);
1519 rootzp->z_unlinked = 0;
1520 rootzp->z_atime_dirty = 0;
1522 vnode.v_type = VDIR;
1523 vnode.v_data = rootzp;
1524 rootzp->z_vnode = &vnode;
1526 bzero(&zfsvfs, sizeof (zfsvfs_t));
1529 zfsvfs.z_parent = &zfsvfs;
1530 zfsvfs.z_version = version;
1531 zfsvfs.z_use_fuids = USE_FUIDS(version, os);
1532 zfsvfs.z_norm = norm;
1534 * Fold case on file systems that are always or sometimes case
1537 if (sense == ZFS_CASE_INSENSITIVE || sense == ZFS_CASE_MIXED)
1538 zfsvfs.z_norm |= U8_TEXTPREP_TOUPPER;
1540 mutex_init(&zfsvfs.z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
1541 list_create(&zfsvfs.z_all_znodes, sizeof (znode_t),
1542 offsetof(znode_t, z_link_node));
1544 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
1545 mutex_init(&zfsvfs.z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
1547 ASSERT(!POINTER_IS_VALID(rootzp->z_zfsvfs));
1548 rootzp->z_zfsvfs = &zfsvfs;
1549 VERIFY(0 == zfs_acl_ids_create(rootzp, IS_ROOT_NODE, &vattr,
1550 cr, NULL, &acl_ids));
1551 zfs_mknode(rootzp, &vattr, tx, cr, IS_ROOT_NODE, &zp, 0, &acl_ids);
1552 ASSERT3P(zp, ==, rootzp);
1553 error = zap_add(os, moid, ZFS_ROOT_OBJ, 8, 1, &rootzp->z_id, tx);
1555 zfs_acl_ids_free(&acl_ids);
1556 POINTER_INVALIDATE(&rootzp->z_zfsvfs);
1558 dmu_buf_rele(rootzp->z_dbuf, NULL);
1559 rootzp->z_dbuf = NULL;
1560 rootzp->z_vnode = NULL;
1561 kmem_cache_free(znode_cache, rootzp);
1564 * Create shares directory
1567 error = zfs_create_share_dir(&zfsvfs, tx);
1571 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
1572 mutex_destroy(&zfsvfs.z_hold_mtx[i]);
1575 #endif /* _KERNEL */
1577 * Given an object number, return its parent object number and whether
1578 * or not the object is an extended attribute directory.
1581 zfs_obj_to_pobj(objset_t *osp, uint64_t obj, uint64_t *pobjp, int *is_xattrdir)
1584 dmu_object_info_t doi;
1588 if ((error = dmu_bonus_hold(osp, obj, FTAG, &db)) != 0)
1591 dmu_object_info_from_db(db, &doi);
1592 if (doi.doi_bonus_type != DMU_OT_ZNODE ||
1593 doi.doi_bonus_size < sizeof (znode_phys_t)) {
1594 dmu_buf_rele(db, FTAG);
1599 *pobjp = zp->zp_parent;
1600 *is_xattrdir = ((zp->zp_flags & ZFS_XATTR) != 0) &&
1601 S_ISDIR(zp->zp_mode);
1602 dmu_buf_rele(db, FTAG);
1608 zfs_obj_to_path(objset_t *osp, uint64_t obj, char *buf, int len)
1610 char *path = buf + len - 1;
1617 char component[MAXNAMELEN + 2];
1621 if ((error = zfs_obj_to_pobj(osp, obj, &pobj,
1622 &is_xattrdir)) != 0)
1633 (void) sprintf(component + 1, "<xattrdir>");
1635 error = zap_value_search(osp, pobj, obj,
1636 ZFS_DIRENT_OBJ(-1ULL), component + 1);
1641 complen = strlen(component);
1643 ASSERT(path >= buf);
1644 bcopy(component, path, complen);
1649 (void) memmove(buf, path, buf + len - path);