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, 2017 by Delphix. All rights reserved.
24 * Copyright (c) 2014 Integros [integros.com]
27 /* Portions Copyright 2007 Jeremy Teo */
30 #include <sys/types.h>
31 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/sysmacros.h>
35 #include <sys/resource.h>
36 #include <sys/mntent.h>
37 #include <sys/mkdev.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>
47 #include <sys/atomic.h>
49 #include "sys/fs_subr.h"
50 #include <sys/zfs_dir.h>
51 #include <sys/zfs_acl.h>
52 #include <sys/zfs_ioctl.h>
53 #include <sys/zfs_rlock.h>
54 #include <sys/zfs_fuid.h>
55 #include <sys/dnode.h>
56 #include <sys/fs/zfs.h>
57 #include <sys/kidmap.h>
61 #include <sys/dmu_objset.h>
62 #include <sys/refcount.h>
65 #include <sys/zfs_znode.h>
67 #include <sys/zfs_sa.h>
68 #include <sys/zfs_stat.h>
71 #include "zfs_comutil.h"
74 * Define ZNODE_STATS to turn on statistic gathering. By default, it is only
75 * turned on when DEBUG is also defined.
82 #define ZNODE_STAT_ADD(stat) ((stat)++)
84 #define ZNODE_STAT_ADD(stat) /* nothing */
85 #endif /* ZNODE_STATS */
88 * Functions needed for userland (ie: libzpool) are not put under
89 * #ifdef_KERNEL; the rest of the functions have dependencies
90 * (such as VFS logic) that will not compile easily in userland.
94 * Needed to close a small window in zfs_znode_move() that allows the zfsvfs to
95 * be freed before it can be safely accessed.
97 krwlock_t zfsvfs_lock
;
99 static kmem_cache_t
*znode_cache
= NULL
;
103 znode_evict_error(dmu_buf_t
*dbuf
, void *user_ptr
)
106 * We should never drop all dbuf refs without first clearing
107 * the eviction callback.
109 panic("evicting znode %p\n", user_ptr
);
114 zfs_znode_cache_constructor(void *buf
, void *arg
, int kmflags
)
118 ASSERT(!POINTER_IS_VALID(zp
->z_zfsvfs
));
120 zp
->z_vnode
= vn_alloc(kmflags
);
121 if (zp
->z_vnode
== NULL
) {
124 ZTOV(zp
)->v_data
= zp
;
126 list_link_init(&zp
->z_link_node
);
128 mutex_init(&zp
->z_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
129 rw_init(&zp
->z_parent_lock
, NULL
, RW_DEFAULT
, NULL
);
130 rw_init(&zp
->z_name_lock
, NULL
, RW_DEFAULT
, NULL
);
131 mutex_init(&zp
->z_acl_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
133 mutex_init(&zp
->z_range_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
134 avl_create(&zp
->z_range_avl
, zfs_range_compare
,
135 sizeof (rl_t
), offsetof(rl_t
, r_node
));
137 zp
->z_dirlocks
= NULL
;
138 zp
->z_acl_cached
= NULL
;
145 zfs_znode_cache_destructor(void *buf
, void *arg
)
149 ASSERT(!POINTER_IS_VALID(zp
->z_zfsvfs
));
150 ASSERT(ZTOV(zp
)->v_data
== zp
);
152 ASSERT(!list_link_active(&zp
->z_link_node
));
153 mutex_destroy(&zp
->z_lock
);
154 rw_destroy(&zp
->z_parent_lock
);
155 rw_destroy(&zp
->z_name_lock
);
156 mutex_destroy(&zp
->z_acl_lock
);
157 avl_destroy(&zp
->z_range_avl
);
158 mutex_destroy(&zp
->z_range_lock
);
160 ASSERT(zp
->z_dirlocks
== NULL
);
161 ASSERT(zp
->z_acl_cached
== NULL
);
166 uint64_t zms_zfsvfs_invalid
;
167 uint64_t zms_zfsvfs_recheck1
;
168 uint64_t zms_zfsvfs_unmounted
;
169 uint64_t zms_zfsvfs_recheck2
;
170 uint64_t zms_obj_held
;
171 uint64_t zms_vnode_locked
;
172 uint64_t zms_not_only_dnlc
;
174 #endif /* ZNODE_STATS */
177 zfs_znode_move_impl(znode_t
*ozp
, znode_t
*nzp
)
182 nzp
->z_zfsvfs
= ozp
->z_zfsvfs
;
186 nzp
->z_vnode
= ozp
->z_vnode
;
187 ozp
->z_vnode
= vp
; /* let destructor free the overwritten vnode */
188 ZTOV(ozp
)->v_data
= ozp
;
189 ZTOV(nzp
)->v_data
= nzp
;
191 nzp
->z_id
= ozp
->z_id
;
192 ASSERT(ozp
->z_dirlocks
== NULL
); /* znode not in use */
193 ASSERT(avl_numnodes(&ozp
->z_range_avl
) == 0);
194 nzp
->z_unlinked
= ozp
->z_unlinked
;
195 nzp
->z_atime_dirty
= ozp
->z_atime_dirty
;
196 nzp
->z_zn_prefetch
= ozp
->z_zn_prefetch
;
197 nzp
->z_blksz
= ozp
->z_blksz
;
198 nzp
->z_seq
= ozp
->z_seq
;
199 nzp
->z_mapcnt
= ozp
->z_mapcnt
;
200 nzp
->z_gen
= ozp
->z_gen
;
201 nzp
->z_sync_cnt
= ozp
->z_sync_cnt
;
202 nzp
->z_is_sa
= ozp
->z_is_sa
;
203 nzp
->z_sa_hdl
= ozp
->z_sa_hdl
;
204 bcopy(ozp
->z_atime
, nzp
->z_atime
, sizeof (uint64_t) * 2);
205 nzp
->z_links
= ozp
->z_links
;
206 nzp
->z_size
= ozp
->z_size
;
207 nzp
->z_pflags
= ozp
->z_pflags
;
208 nzp
->z_uid
= ozp
->z_uid
;
209 nzp
->z_gid
= ozp
->z_gid
;
210 nzp
->z_mode
= ozp
->z_mode
;
213 * Since this is just an idle znode and kmem is already dealing with
214 * memory pressure, release any cached ACL.
216 if (ozp
->z_acl_cached
) {
217 zfs_acl_free(ozp
->z_acl_cached
);
218 ozp
->z_acl_cached
= NULL
;
221 sa_set_userp(nzp
->z_sa_hdl
, nzp
);
224 * Invalidate the original znode by clearing fields that provide a
225 * pointer back to the znode. Set the low bit of the vfs pointer to
226 * ensure that zfs_znode_move() recognizes the znode as invalid in any
227 * subsequent callback.
229 ozp
->z_sa_hdl
= NULL
;
230 POINTER_INVALIDATE(&ozp
->z_zfsvfs
);
236 ozp
->z_moved
= (uint8_t)-1;
241 zfs_znode_move(void *buf
, void *newbuf
, size_t size
, void *arg
)
243 znode_t
*ozp
= buf
, *nzp
= newbuf
;
248 * The znode is on the file system's list of known znodes if the vfs
249 * pointer is valid. We set the low bit of the vfs pointer when freeing
250 * the znode to invalidate it, and the memory patterns written by kmem
251 * (baddcafe and deadbeef) set at least one of the two low bits. A newly
252 * created znode sets the vfs pointer last of all to indicate that the
253 * znode is known and in a valid state to be moved by this function.
255 zfsvfs
= ozp
->z_zfsvfs
;
256 if (!POINTER_IS_VALID(zfsvfs
)) {
257 ZNODE_STAT_ADD(znode_move_stats
.zms_zfsvfs_invalid
);
258 return (KMEM_CBRC_DONT_KNOW
);
262 * Close a small window in which it's possible that the filesystem could
263 * be unmounted and freed, and zfsvfs, though valid in the previous
264 * statement, could point to unrelated memory by the time we try to
265 * prevent the filesystem from being unmounted.
267 rw_enter(&zfsvfs_lock
, RW_WRITER
);
268 if (zfsvfs
!= ozp
->z_zfsvfs
) {
269 rw_exit(&zfsvfs_lock
);
270 ZNODE_STAT_ADD(znode_move_stats
.zms_zfsvfs_recheck1
);
271 return (KMEM_CBRC_DONT_KNOW
);
275 * If the znode is still valid, then so is the file system. We know that
276 * no valid file system can be freed while we hold zfsvfs_lock, so we
277 * can safely ensure that the filesystem is not and will not be
278 * unmounted. The next statement is equivalent to ZFS_ENTER().
280 rrm_enter(&zfsvfs
->z_teardown_lock
, RW_READER
, FTAG
);
281 if (zfsvfs
->z_unmounted
) {
283 rw_exit(&zfsvfs_lock
);
284 ZNODE_STAT_ADD(znode_move_stats
.zms_zfsvfs_unmounted
);
285 return (KMEM_CBRC_DONT_KNOW
);
287 rw_exit(&zfsvfs_lock
);
289 mutex_enter(&zfsvfs
->z_znodes_lock
);
291 * Recheck the vfs pointer in case the znode was removed just before
292 * acquiring the lock.
294 if (zfsvfs
!= ozp
->z_zfsvfs
) {
295 mutex_exit(&zfsvfs
->z_znodes_lock
);
297 ZNODE_STAT_ADD(znode_move_stats
.zms_zfsvfs_recheck2
);
298 return (KMEM_CBRC_DONT_KNOW
);
302 * At this point we know that as long as we hold z_znodes_lock, the
303 * znode cannot be freed and fields within the znode can be safely
304 * accessed. Now, prevent a race with zfs_zget().
306 if (ZFS_OBJ_HOLD_TRYENTER(zfsvfs
, ozp
->z_id
) == 0) {
307 mutex_exit(&zfsvfs
->z_znodes_lock
);
309 ZNODE_STAT_ADD(znode_move_stats
.zms_obj_held
);
310 return (KMEM_CBRC_LATER
);
314 if (mutex_tryenter(&vp
->v_lock
) == 0) {
315 ZFS_OBJ_HOLD_EXIT(zfsvfs
, ozp
->z_id
);
316 mutex_exit(&zfsvfs
->z_znodes_lock
);
318 ZNODE_STAT_ADD(znode_move_stats
.zms_vnode_locked
);
319 return (KMEM_CBRC_LATER
);
322 /* Only move znodes that are referenced _only_ by the DNLC. */
323 if (vp
->v_count
!= 1 || !vn_in_dnlc(vp
)) {
324 mutex_exit(&vp
->v_lock
);
325 ZFS_OBJ_HOLD_EXIT(zfsvfs
, ozp
->z_id
);
326 mutex_exit(&zfsvfs
->z_znodes_lock
);
328 ZNODE_STAT_ADD(znode_move_stats
.zms_not_only_dnlc
);
329 return (KMEM_CBRC_LATER
);
333 * The znode is known and in a valid state to move. We're holding the
334 * locks needed to execute the critical section.
336 zfs_znode_move_impl(ozp
, nzp
);
337 mutex_exit(&vp
->v_lock
);
338 ZFS_OBJ_HOLD_EXIT(zfsvfs
, ozp
->z_id
);
340 list_link_replace(&ozp
->z_link_node
, &nzp
->z_link_node
);
341 mutex_exit(&zfsvfs
->z_znodes_lock
);
344 return (KMEM_CBRC_YES
);
353 rw_init(&zfsvfs_lock
, NULL
, RW_DEFAULT
, NULL
);
354 ASSERT(znode_cache
== NULL
);
355 znode_cache
= kmem_cache_create("zfs_znode_cache",
356 sizeof (znode_t
), 0, zfs_znode_cache_constructor
,
357 zfs_znode_cache_destructor
, NULL
, NULL
, NULL
, 0);
358 kmem_cache_set_move(znode_cache
, zfs_znode_move
);
365 * Cleanup vfs & vnode ops
367 zfs_remove_op_tables();
373 kmem_cache_destroy(znode_cache
);
375 rw_destroy(&zfsvfs_lock
);
378 extern const struct vnodeops zfs_dvnodeops
;
379 extern const struct vnodeops zfs_fvnodeops
;
380 extern const struct vnodeops zfs_symvnodeops
;
381 extern const struct vnodeops zfs_xdvnodeops
;
382 extern const struct vnodeops zfs_evnodeops
;
383 extern const struct vnodeops zfs_sharevnodeops
;
386 zfs_remove_op_tables()
392 (void) vfs_freevfsops_by_type(zfsfstype
);
397 zfs_create_op_tables()
403 zfs_create_share_dir(zfsvfs_t
*zfsvfs
, dmu_tx_t
*tx
)
405 zfs_acl_ids_t acl_ids
;
412 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
413 vattr
.va_type
= VDIR
;
414 vattr
.va_mode
= S_IFDIR
|0555;
415 vattr
.va_uid
= crgetuid(kcred
);
416 vattr
.va_gid
= crgetgid(kcred
);
418 sharezp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
419 ASSERT(!POINTER_IS_VALID(sharezp
->z_zfsvfs
));
420 sharezp
->z_moved
= 0;
421 sharezp
->z_unlinked
= 0;
422 sharezp
->z_atime_dirty
= 0;
423 sharezp
->z_zfsvfs
= zfsvfs
;
424 sharezp
->z_is_sa
= zfsvfs
->z_use_sa
;
430 VERIFY(0 == zfs_acl_ids_create(sharezp
, IS_ROOT_NODE
, &vattr
,
431 kcred
, NULL
, &acl_ids
));
432 zfs_mknode(sharezp
, &vattr
, tx
, kcred
, IS_ROOT_NODE
, &zp
, &acl_ids
);
433 ASSERT3P(zp
, ==, sharezp
);
434 ASSERT(!vn_in_dnlc(ZTOV(sharezp
))); /* not valid to move */
435 POINTER_INVALIDATE(&sharezp
->z_zfsvfs
);
436 error
= zap_add(zfsvfs
->z_os
, MASTER_NODE_OBJ
,
437 ZFS_SHARES_DIR
, 8, 1, &sharezp
->z_id
, tx
);
438 zfsvfs
->z_shares_dir
= sharezp
->z_id
;
440 zfs_acl_ids_free(&acl_ids
);
441 ZTOV(sharezp
)->v_count
= 0;
442 sa_handle_destroy(sharezp
->z_sa_hdl
);
443 kmem_cache_free(znode_cache
, sharezp
);
449 * define a couple of values we need available
450 * for both 64 and 32 bit environments.
453 #define NBITSMINOR64 32
456 #define MAXMAJ64 0xffffffffUL
459 #define MAXMIN64 0xffffffffUL
463 * Create special expldev for ZFS private use.
464 * Can't use standard expldev since it doesn't do
465 * what we want. The standard expldev() takes a
466 * dev32_t in LP64 and expands it to a long dev_t.
467 * We need an interface that takes a dev32_t in ILP32
468 * and expands it to a long dev_t.
471 zfs_expldev(dev_t dev
)
474 major_t major
= (major_t
)dev
>> NBITSMINOR32
& MAXMAJ32
;
475 return (((uint64_t)major
<< NBITSMINOR64
) |
476 ((minor_t
)dev
& MAXMIN32
));
483 * Special cmpldev for ZFS private use.
484 * Can't use standard cmpldev since it takes
485 * a long dev_t and compresses it to dev32_t in
486 * LP64. We need to do a compaction of a long dev_t
487 * to a dev32_t in ILP32.
490 zfs_cmpldev(uint64_t dev
)
493 minor_t minor
= (minor_t
)dev
& MAXMIN64
;
494 major_t major
= (major_t
)(dev
>> NBITSMINOR64
) & MAXMAJ64
;
496 if (major
> MAXMAJ32
|| minor
> MAXMIN32
)
499 return (((dev32_t
)major
<< NBITSMINOR32
) | minor
);
506 zfs_znode_sa_init(zfsvfs_t
*zfsvfs
, znode_t
*zp
,
507 dmu_buf_t
*db
, dmu_object_type_t obj_type
, sa_handle_t
*sa_hdl
)
509 ASSERT(!POINTER_IS_VALID(zp
->z_zfsvfs
) || (zfsvfs
== zp
->z_zfsvfs
));
510 ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zfsvfs
, zp
->z_id
)));
512 mutex_enter(&zp
->z_lock
);
514 ASSERT(zp
->z_sa_hdl
== NULL
);
515 ASSERT(zp
->z_acl_cached
== NULL
);
516 if (sa_hdl
== NULL
) {
517 VERIFY(0 == sa_handle_get_from_db(zfsvfs
->z_os
, db
, zp
,
518 SA_HDL_SHARED
, &zp
->z_sa_hdl
));
520 zp
->z_sa_hdl
= sa_hdl
;
521 sa_set_userp(sa_hdl
, zp
);
524 zp
->z_is_sa
= (obj_type
== DMU_OT_SA
) ? B_TRUE
: B_FALSE
;
527 * Slap on VROOT if we are the root znode
529 if (zp
->z_id
== zfsvfs
->z_root
)
530 ZTOV(zp
)->v_flag
|= VROOT
;
532 mutex_exit(&zp
->z_lock
);
537 zfs_znode_dmu_fini(znode_t
*zp
)
539 ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp
->z_zfsvfs
, zp
->z_id
)) ||
541 RW_WRITE_HELD(&zp
->z_zfsvfs
->z_teardown_inactive_lock
));
543 sa_handle_destroy(zp
->z_sa_hdl
);
548 * Construct a new znode/vnode and intialize.
550 * This does not do a call to dmu_set_user() that is
551 * up to the caller to do, in case you don't want to
555 zfs_znode_alloc(zfsvfs_t
*zfsvfs
, dmu_buf_t
*db
, int blksz
,
556 dmu_object_type_t obj_type
, sa_handle_t
*hdl
)
562 sa_bulk_attr_t bulk
[9];
565 zp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
567 ASSERT(zp
->z_dirlocks
== NULL
);
568 ASSERT(!POINTER_IS_VALID(zp
->z_zfsvfs
));
572 * Defer setting z_zfsvfs until the znode is ready to be a candidate for
573 * the zfs_znode_move() callback.
577 zp
->z_atime_dirty
= 0;
579 zp
->z_id
= db
->db_object
;
581 zp
->z_seq
= 0x7A4653;
587 zfs_znode_sa_init(zfsvfs
, zp
, db
, obj_type
, hdl
);
589 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zfsvfs
), NULL
, &mode
, 8);
590 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GEN(zfsvfs
), NULL
, &zp
->z_gen
, 8);
591 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zfsvfs
), NULL
,
593 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_LINKS(zfsvfs
), NULL
,
595 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zfsvfs
), NULL
,
597 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_PARENT(zfsvfs
), NULL
, &parent
, 8);
598 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_ATIME(zfsvfs
), NULL
,
600 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_UID(zfsvfs
), NULL
,
602 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GID(zfsvfs
), NULL
,
605 if (sa_bulk_lookup(zp
->z_sa_hdl
, bulk
, count
) != 0 || zp
->z_gen
== 0) {
607 sa_handle_destroy(zp
->z_sa_hdl
);
608 kmem_cache_free(znode_cache
, zp
);
613 vp
->v_vfsp
= zfsvfs
->z_parent
->z_vfs
;
615 vp
->v_type
= IFTOVT((mode_t
)mode
);
617 switch (vp
->v_type
) {
619 if (zp
->z_pflags
& ZFS_XATTR
) {
620 vn_setops(vp
, &zfs_xdvnodeops
);
621 vp
->v_flag
|= V_XATTRDIR
;
623 vn_setops(vp
, &zfs_dvnodeops
);
625 zp
->z_zn_prefetch
= B_TRUE
; /* z_prefetch default is enabled */
631 VERIFY(sa_lookup(zp
->z_sa_hdl
, SA_ZPL_RDEV(zfsvfs
),
632 &rdev
, sizeof (rdev
)) == 0);
634 vp
->v_rdev
= zfs_cmpldev(rdev
);
640 vn_setops(vp
, &zfs_fvnodeops
);
643 vp
->v_flag
|= VMODSORT
;
644 if (parent
== zfsvfs
->z_shares_dir
) {
645 ASSERT(zp
->z_uid
== 0 && zp
->z_gid
== 0);
646 vn_setops(vp
, &zfs_sharevnodeops
);
648 vn_setops(vp
, &zfs_fvnodeops
);
652 vn_setops(vp
, &zfs_symvnodeops
);
655 vn_setops(vp
, &zfs_evnodeops
);
659 mutex_enter(&zfsvfs
->z_znodes_lock
);
660 list_insert_tail(&zfsvfs
->z_all_znodes
, zp
);
663 * Everything else must be valid before assigning z_zfsvfs makes the
664 * znode eligible for zfs_znode_move().
666 zp
->z_zfsvfs
= zfsvfs
;
667 mutex_exit(&zfsvfs
->z_znodes_lock
);
669 VFS_HOLD(zfsvfs
->z_vfs
);
673 static uint64_t empty_xattr
;
674 static uint64_t pad
[4];
675 static zfs_acl_phys_t acl_phys
;
677 * Create a new DMU object to hold a zfs znode.
679 * IN: dzp - parent directory for new znode
680 * vap - file attributes for new znode
681 * tx - dmu transaction id for zap operations
682 * cr - credentials of caller
684 * IS_ROOT_NODE - new object will be root
685 * IS_XATTR - new object is an attribute
686 * bonuslen - length of bonus buffer
687 * setaclp - File/Dir initial ACL
688 * fuidp - Tracks fuid allocation.
690 * OUT: zpp - allocated znode
694 zfs_mknode(znode_t
*dzp
, vattr_t
*vap
, dmu_tx_t
*tx
, cred_t
*cr
,
695 uint_t flag
, znode_t
**zpp
, zfs_acl_ids_t
*acl_ids
)
697 uint64_t crtime
[2], atime
[2], mtime
[2], ctime
[2];
698 uint64_t mode
, size
, links
, parent
, pflags
;
699 uint64_t dzp_pflags
= 0;
701 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
707 dmu_object_type_t obj_type
;
708 sa_bulk_attr_t sa_attrs
[ZPL_END
];
710 zfs_acl_locator_cb_t locate
= { 0 };
712 ASSERT(vap
&& (vap
->va_mask
& (AT_TYPE
|AT_MODE
)) == (AT_TYPE
|AT_MODE
));
714 if (zfsvfs
->z_replay
) {
715 obj
= vap
->va_nodeid
;
716 now
= vap
->va_ctime
; /* see zfs_replay_create() */
717 gen
= vap
->va_nblocks
; /* ditto */
721 gen
= dmu_tx_get_txg(tx
);
724 obj_type
= zfsvfs
->z_use_sa
? DMU_OT_SA
: DMU_OT_ZNODE
;
725 bonuslen
= (obj_type
== DMU_OT_SA
) ?
726 DN_MAX_BONUSLEN
: ZFS_OLD_ZNODE_PHYS_SIZE
;
729 * Create a new DMU object.
732 * There's currently no mechanism for pre-reading the blocks that will
733 * be needed to allocate a new object, so we accept the small chance
734 * that there will be an i/o error and we will fail one of the
737 if (vap
->va_type
== VDIR
) {
738 if (zfsvfs
->z_replay
) {
739 VERIFY0(zap_create_claim_norm(zfsvfs
->z_os
, obj
,
740 zfsvfs
->z_norm
, DMU_OT_DIRECTORY_CONTENTS
,
741 obj_type
, bonuslen
, tx
));
743 obj
= zap_create_norm(zfsvfs
->z_os
,
744 zfsvfs
->z_norm
, DMU_OT_DIRECTORY_CONTENTS
,
745 obj_type
, bonuslen
, tx
);
748 if (zfsvfs
->z_replay
) {
749 VERIFY0(dmu_object_claim(zfsvfs
->z_os
, obj
,
750 DMU_OT_PLAIN_FILE_CONTENTS
, 0,
751 obj_type
, bonuslen
, tx
));
753 obj
= dmu_object_alloc(zfsvfs
->z_os
,
754 DMU_OT_PLAIN_FILE_CONTENTS
, 0,
755 obj_type
, bonuslen
, tx
);
759 ZFS_OBJ_HOLD_ENTER(zfsvfs
, obj
);
760 VERIFY(0 == sa_buf_hold(zfsvfs
->z_os
, obj
, NULL
, &db
));
763 * If this is the root, fix up the half-initialized parent pointer
764 * to reference the just-allocated physical data area.
766 if (flag
& IS_ROOT_NODE
) {
769 dzp_pflags
= dzp
->z_pflags
;
773 * If parent is an xattr, so am I.
775 if (dzp_pflags
& ZFS_XATTR
) {
779 if (zfsvfs
->z_use_fuids
)
780 pflags
= ZFS_ARCHIVE
| ZFS_AV_MODIFIED
;
784 if (vap
->va_type
== VDIR
) {
785 size
= 2; /* contents ("." and "..") */
786 links
= (flag
& (IS_ROOT_NODE
| IS_XATTR
)) ? 2 : 1;
791 if (vap
->va_type
== VBLK
|| vap
->va_type
== VCHR
) {
792 rdev
= zfs_expldev(vap
->va_rdev
);
796 mode
= acl_ids
->z_mode
;
801 * No execs denied will be deterimed when zfs_mode_compute() is called.
803 pflags
|= acl_ids
->z_aclp
->z_hints
&
804 (ZFS_ACL_TRIVIAL
|ZFS_INHERIT_ACE
|ZFS_ACL_AUTO_INHERIT
|
805 ZFS_ACL_DEFAULTED
|ZFS_ACL_PROTECTED
);
807 ZFS_TIME_ENCODE(&now
, crtime
);
808 ZFS_TIME_ENCODE(&now
, ctime
);
810 if (vap
->va_mask
& AT_ATIME
) {
811 ZFS_TIME_ENCODE(&vap
->va_atime
, atime
);
813 ZFS_TIME_ENCODE(&now
, atime
);
816 if (vap
->va_mask
& AT_MTIME
) {
817 ZFS_TIME_ENCODE(&vap
->va_mtime
, mtime
);
819 ZFS_TIME_ENCODE(&now
, mtime
);
822 /* Now add in all of the "SA" attributes */
823 VERIFY(0 == sa_handle_get_from_db(zfsvfs
->z_os
, db
, NULL
, SA_HDL_SHARED
,
827 * Setup the array of attributes to be replaced/set on the new file
829 * order for DMU_OT_ZNODE is critical since it needs to be constructed
830 * in the old znode_phys_t format. Don't change this ordering
833 if (obj_type
== DMU_OT_ZNODE
) {
834 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ATIME(zfsvfs
),
836 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MTIME(zfsvfs
),
838 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CTIME(zfsvfs
),
840 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CRTIME(zfsvfs
),
842 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GEN(zfsvfs
),
844 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MODE(zfsvfs
),
846 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_SIZE(zfsvfs
),
848 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PARENT(zfsvfs
),
851 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MODE(zfsvfs
),
853 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_SIZE(zfsvfs
),
855 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GEN(zfsvfs
),
857 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_UID(zfsvfs
), NULL
,
858 &acl_ids
->z_fuid
, 8);
859 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GID(zfsvfs
), NULL
,
860 &acl_ids
->z_fgid
, 8);
861 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PARENT(zfsvfs
),
863 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_FLAGS(zfsvfs
),
865 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ATIME(zfsvfs
),
867 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MTIME(zfsvfs
),
869 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CTIME(zfsvfs
),
871 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CRTIME(zfsvfs
),
875 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_LINKS(zfsvfs
), NULL
, &links
, 8);
877 if (obj_type
== DMU_OT_ZNODE
) {
878 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_XATTR(zfsvfs
), NULL
,
881 if (obj_type
== DMU_OT_ZNODE
||
882 (vap
->va_type
== VBLK
|| vap
->va_type
== VCHR
)) {
883 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_RDEV(zfsvfs
),
887 if (obj_type
== DMU_OT_ZNODE
) {
888 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_FLAGS(zfsvfs
),
890 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_UID(zfsvfs
), NULL
,
891 &acl_ids
->z_fuid
, 8);
892 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GID(zfsvfs
), NULL
,
893 &acl_ids
->z_fgid
, 8);
894 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PAD(zfsvfs
), NULL
, pad
,
895 sizeof (uint64_t) * 4);
896 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ZNODE_ACL(zfsvfs
), NULL
,
897 &acl_phys
, sizeof (zfs_acl_phys_t
));
898 } else if (acl_ids
->z_aclp
->z_version
>= ZFS_ACL_VERSION_FUID
) {
899 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_DACL_COUNT(zfsvfs
), NULL
,
900 &acl_ids
->z_aclp
->z_acl_count
, 8);
901 locate
.cb_aclp
= acl_ids
->z_aclp
;
902 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_DACL_ACES(zfsvfs
),
903 zfs_acl_data_locator
, &locate
,
904 acl_ids
->z_aclp
->z_acl_bytes
);
905 mode
= zfs_mode_compute(mode
, acl_ids
->z_aclp
, &pflags
,
906 acl_ids
->z_fuid
, acl_ids
->z_fgid
);
909 VERIFY(sa_replace_all_by_template(sa_hdl
, sa_attrs
, cnt
, tx
) == 0);
911 if (!(flag
& IS_ROOT_NODE
)) {
912 *zpp
= zfs_znode_alloc(zfsvfs
, db
, 0, obj_type
, sa_hdl
);
913 ASSERT(*zpp
!= NULL
);
916 * If we are creating the root node, the "parent" we
917 * passed in is the znode for the root.
921 (*zpp
)->z_sa_hdl
= sa_hdl
;
924 (*zpp
)->z_pflags
= pflags
;
925 (*zpp
)->z_mode
= mode
;
927 if (vap
->va_mask
& AT_XVATTR
)
928 zfs_xvattr_set(*zpp
, (xvattr_t
*)vap
, tx
);
930 if (obj_type
== DMU_OT_ZNODE
||
931 acl_ids
->z_aclp
->z_version
< ZFS_ACL_VERSION_FUID
) {
932 VERIFY0(zfs_aclset_common(*zpp
, acl_ids
->z_aclp
, cr
, tx
));
934 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj
);
938 * Update in-core attributes. It is assumed the caller will be doing an
939 * sa_bulk_update to push the changes out.
942 zfs_xvattr_set(znode_t
*zp
, xvattr_t
*xvap
, dmu_tx_t
*tx
)
946 xoap
= xva_getxoptattr(xvap
);
949 if (XVA_ISSET_REQ(xvap
, XAT_CREATETIME
)) {
951 ZFS_TIME_ENCODE(&xoap
->xoa_createtime
, times
);
952 (void) sa_update(zp
->z_sa_hdl
, SA_ZPL_CRTIME(zp
->z_zfsvfs
),
953 ×
, sizeof (times
), tx
);
954 XVA_SET_RTN(xvap
, XAT_CREATETIME
);
956 if (XVA_ISSET_REQ(xvap
, XAT_READONLY
)) {
957 ZFS_ATTR_SET(zp
, ZFS_READONLY
, xoap
->xoa_readonly
,
959 XVA_SET_RTN(xvap
, XAT_READONLY
);
961 if (XVA_ISSET_REQ(xvap
, XAT_HIDDEN
)) {
962 ZFS_ATTR_SET(zp
, ZFS_HIDDEN
, xoap
->xoa_hidden
,
964 XVA_SET_RTN(xvap
, XAT_HIDDEN
);
966 if (XVA_ISSET_REQ(xvap
, XAT_SYSTEM
)) {
967 ZFS_ATTR_SET(zp
, ZFS_SYSTEM
, xoap
->xoa_system
,
969 XVA_SET_RTN(xvap
, XAT_SYSTEM
);
971 if (XVA_ISSET_REQ(xvap
, XAT_ARCHIVE
)) {
972 ZFS_ATTR_SET(zp
, ZFS_ARCHIVE
, xoap
->xoa_archive
,
974 XVA_SET_RTN(xvap
, XAT_ARCHIVE
);
976 if (XVA_ISSET_REQ(xvap
, XAT_IMMUTABLE
)) {
977 ZFS_ATTR_SET(zp
, ZFS_IMMUTABLE
, xoap
->xoa_immutable
,
979 XVA_SET_RTN(xvap
, XAT_IMMUTABLE
);
981 if (XVA_ISSET_REQ(xvap
, XAT_NOUNLINK
)) {
982 ZFS_ATTR_SET(zp
, ZFS_NOUNLINK
, xoap
->xoa_nounlink
,
984 XVA_SET_RTN(xvap
, XAT_NOUNLINK
);
986 if (XVA_ISSET_REQ(xvap
, XAT_APPENDONLY
)) {
987 ZFS_ATTR_SET(zp
, ZFS_APPENDONLY
, xoap
->xoa_appendonly
,
989 XVA_SET_RTN(xvap
, XAT_APPENDONLY
);
991 if (XVA_ISSET_REQ(xvap
, XAT_NODUMP
)) {
992 ZFS_ATTR_SET(zp
, ZFS_NODUMP
, xoap
->xoa_nodump
,
994 XVA_SET_RTN(xvap
, XAT_NODUMP
);
996 if (XVA_ISSET_REQ(xvap
, XAT_OPAQUE
)) {
997 ZFS_ATTR_SET(zp
, ZFS_OPAQUE
, xoap
->xoa_opaque
,
999 XVA_SET_RTN(xvap
, XAT_OPAQUE
);
1001 if (XVA_ISSET_REQ(xvap
, XAT_AV_QUARANTINED
)) {
1002 ZFS_ATTR_SET(zp
, ZFS_AV_QUARANTINED
,
1003 xoap
->xoa_av_quarantined
, zp
->z_pflags
, tx
);
1004 XVA_SET_RTN(xvap
, XAT_AV_QUARANTINED
);
1006 if (XVA_ISSET_REQ(xvap
, XAT_AV_MODIFIED
)) {
1007 ZFS_ATTR_SET(zp
, ZFS_AV_MODIFIED
, xoap
->xoa_av_modified
,
1009 XVA_SET_RTN(xvap
, XAT_AV_MODIFIED
);
1011 if (XVA_ISSET_REQ(xvap
, XAT_AV_SCANSTAMP
)) {
1012 zfs_sa_set_scanstamp(zp
, xvap
, tx
);
1013 XVA_SET_RTN(xvap
, XAT_AV_SCANSTAMP
);
1015 if (XVA_ISSET_REQ(xvap
, XAT_REPARSE
)) {
1016 ZFS_ATTR_SET(zp
, ZFS_REPARSE
, xoap
->xoa_reparse
,
1018 XVA_SET_RTN(xvap
, XAT_REPARSE
);
1020 if (XVA_ISSET_REQ(xvap
, XAT_OFFLINE
)) {
1021 ZFS_ATTR_SET(zp
, ZFS_OFFLINE
, xoap
->xoa_offline
,
1023 XVA_SET_RTN(xvap
, XAT_OFFLINE
);
1025 if (XVA_ISSET_REQ(xvap
, XAT_SPARSE
)) {
1026 ZFS_ATTR_SET(zp
, ZFS_SPARSE
, xoap
->xoa_sparse
,
1028 XVA_SET_RTN(xvap
, XAT_SPARSE
);
1033 zfs_zget(zfsvfs_t
*zfsvfs
, uint64_t obj_num
, znode_t
**zpp
)
1035 dmu_object_info_t doi
;
1043 ZFS_OBJ_HOLD_ENTER(zfsvfs
, obj_num
);
1045 err
= sa_buf_hold(zfsvfs
->z_os
, obj_num
, NULL
, &db
);
1047 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj_num
);
1051 dmu_object_info_from_db(db
, &doi
);
1052 if (doi
.doi_bonus_type
!= DMU_OT_SA
&&
1053 (doi
.doi_bonus_type
!= DMU_OT_ZNODE
||
1054 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1055 doi
.doi_bonus_size
< sizeof (znode_phys_t
)))) {
1056 sa_buf_rele(db
, NULL
);
1057 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj_num
);
1058 return (SET_ERROR(EINVAL
));
1061 hdl
= dmu_buf_get_user(db
);
1063 zp
= sa_get_userdata(hdl
);
1067 * Since "SA" does immediate eviction we
1068 * should never find a sa handle that doesn't
1069 * know about the znode.
1072 ASSERT3P(zp
, !=, NULL
);
1074 mutex_enter(&zp
->z_lock
);
1075 ASSERT3U(zp
->z_id
, ==, obj_num
);
1076 if (zp
->z_unlinked
) {
1077 err
= SET_ERROR(ENOENT
);
1083 mutex_exit(&zp
->z_lock
);
1084 sa_buf_rele(db
, NULL
);
1085 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj_num
);
1090 * Not found create new znode/vnode
1091 * but only if file exists.
1093 * There is a small window where zfs_vget() could
1094 * find this object while a file create is still in
1095 * progress. This is checked for in zfs_znode_alloc()
1097 * if zfs_znode_alloc() fails it will drop the hold on the
1100 zp
= zfs_znode_alloc(zfsvfs
, db
, doi
.doi_data_block_size
,
1101 doi
.doi_bonus_type
, NULL
);
1103 err
= SET_ERROR(ENOENT
);
1107 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj_num
);
1112 zfs_rezget(znode_t
*zp
)
1114 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1115 dmu_object_info_t doi
;
1117 uint64_t obj_num
= zp
->z_id
;
1119 sa_bulk_attr_t bulk
[8];
1124 ZFS_OBJ_HOLD_ENTER(zfsvfs
, obj_num
);
1126 mutex_enter(&zp
->z_acl_lock
);
1127 if (zp
->z_acl_cached
) {
1128 zfs_acl_free(zp
->z_acl_cached
);
1129 zp
->z_acl_cached
= NULL
;
1132 mutex_exit(&zp
->z_acl_lock
);
1133 ASSERT(zp
->z_sa_hdl
== NULL
);
1134 err
= sa_buf_hold(zfsvfs
->z_os
, obj_num
, NULL
, &db
);
1136 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj_num
);
1140 dmu_object_info_from_db(db
, &doi
);
1141 if (doi
.doi_bonus_type
!= DMU_OT_SA
&&
1142 (doi
.doi_bonus_type
!= DMU_OT_ZNODE
||
1143 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1144 doi
.doi_bonus_size
< sizeof (znode_phys_t
)))) {
1145 sa_buf_rele(db
, NULL
);
1146 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj_num
);
1147 return (SET_ERROR(EINVAL
));
1150 zfs_znode_sa_init(zfsvfs
, zp
, db
, doi
.doi_bonus_type
, NULL
);
1152 /* reload cached values */
1153 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GEN(zfsvfs
), NULL
,
1154 &gen
, sizeof (gen
));
1155 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zfsvfs
), NULL
,
1156 &zp
->z_size
, sizeof (zp
->z_size
));
1157 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_LINKS(zfsvfs
), NULL
,
1158 &zp
->z_links
, sizeof (zp
->z_links
));
1159 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zfsvfs
), NULL
,
1160 &zp
->z_pflags
, sizeof (zp
->z_pflags
));
1161 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_ATIME(zfsvfs
), NULL
,
1162 &zp
->z_atime
, sizeof (zp
->z_atime
));
1163 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_UID(zfsvfs
), NULL
,
1164 &zp
->z_uid
, sizeof (zp
->z_uid
));
1165 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GID(zfsvfs
), NULL
,
1166 &zp
->z_gid
, sizeof (zp
->z_gid
));
1167 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zfsvfs
), NULL
,
1168 &mode
, sizeof (mode
));
1170 if (sa_bulk_lookup(zp
->z_sa_hdl
, bulk
, count
)) {
1171 zfs_znode_dmu_fini(zp
);
1172 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj_num
);
1173 return (SET_ERROR(EIO
));
1178 if (gen
!= zp
->z_gen
) {
1179 zfs_znode_dmu_fini(zp
);
1180 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj_num
);
1181 return (SET_ERROR(EIO
));
1184 zp
->z_blksz
= doi
.doi_data_block_size
;
1187 * If the file has zero links, then it has been unlinked on the send
1188 * side and it must be in the received unlinked set.
1189 * We call zfs_znode_dmu_fini() now to prevent any accesses to the
1190 * stale data and to prevent automatical removal of the file in
1191 * zfs_zinactive(). The file will be removed either when it is removed
1192 * on the send side and the next incremental stream is received or
1193 * when the unlinked set gets processed.
1195 zp
->z_unlinked
= (zp
->z_links
== 0);
1197 zfs_znode_dmu_fini(zp
);
1199 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj_num
);
1205 zfs_znode_delete(znode_t
*zp
, dmu_tx_t
*tx
)
1207 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1208 objset_t
*os
= zfsvfs
->z_os
;
1209 uint64_t obj
= zp
->z_id
;
1210 uint64_t acl_obj
= zfs_external_acl(zp
);
1212 ZFS_OBJ_HOLD_ENTER(zfsvfs
, obj
);
1214 VERIFY(!zp
->z_is_sa
);
1215 VERIFY(0 == dmu_object_free(os
, acl_obj
, tx
));
1217 VERIFY(0 == dmu_object_free(os
, obj
, tx
));
1218 zfs_znode_dmu_fini(zp
);
1219 ZFS_OBJ_HOLD_EXIT(zfsvfs
, obj
);
1224 zfs_zinactive(znode_t
*zp
)
1226 vnode_t
*vp
= ZTOV(zp
);
1227 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1228 uint64_t z_id
= zp
->z_id
;
1230 ASSERT(zp
->z_sa_hdl
);
1233 * Don't allow a zfs_zget() while were trying to release this znode
1235 ZFS_OBJ_HOLD_ENTER(zfsvfs
, z_id
);
1237 mutex_enter(&zp
->z_lock
);
1238 mutex_enter(&vp
->v_lock
);
1240 if (vp
->v_count
> 0 || vn_has_cached_data(vp
)) {
1242 * If the hold count is greater than zero, somebody has
1243 * obtained a new reference on this znode while we were
1244 * processing it here, so we are done. If we still have
1245 * mapped pages then we are also done, since we don't
1246 * want to inactivate the znode until the pages get pushed.
1248 * XXX - if vn_has_cached_data(vp) is true, but count == 0,
1249 * this seems like it would leave the znode hanging with
1250 * no chance to go inactive...
1252 mutex_exit(&vp
->v_lock
);
1253 mutex_exit(&zp
->z_lock
);
1254 ZFS_OBJ_HOLD_EXIT(zfsvfs
, z_id
);
1257 mutex_exit(&vp
->v_lock
);
1260 * If this was the last reference to a file with no links, remove
1261 * the file from the file system unless the file system is mounted
1262 * read-only. That can happen, for example, if the file system was
1263 * originally read-write, the file was opened, then unlinked and
1264 * the file system was made read-only before the file was finally
1265 * closed. The file will remain in the unlinked set.
1267 if (zp
->z_unlinked
) {
1268 ASSERT(!zfsvfs
->z_issnap
);
1269 if ((zfsvfs
->z_vfs
->vfs_flag
& VFS_RDONLY
) == 0) {
1270 mutex_exit(&zp
->z_lock
);
1271 ZFS_OBJ_HOLD_EXIT(zfsvfs
, z_id
);
1277 mutex_exit(&zp
->z_lock
);
1278 zfs_znode_dmu_fini(zp
);
1279 ZFS_OBJ_HOLD_EXIT(zfsvfs
, z_id
);
1284 zfs_znode_free(znode_t
*zp
)
1286 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1288 vn_invalid(ZTOV(zp
));
1290 ASSERT(ZTOV(zp
)->v_count
== 0);
1292 mutex_enter(&zfsvfs
->z_znodes_lock
);
1293 POINTER_INVALIDATE(&zp
->z_zfsvfs
);
1294 list_remove(&zfsvfs
->z_all_znodes
, zp
);
1295 mutex_exit(&zfsvfs
->z_znodes_lock
);
1297 if (zp
->z_acl_cached
) {
1298 zfs_acl_free(zp
->z_acl_cached
);
1299 zp
->z_acl_cached
= NULL
;
1302 kmem_cache_free(znode_cache
, zp
);
1304 VFS_RELE(zfsvfs
->z_vfs
);
1308 zfs_tstamp_update_setup(znode_t
*zp
, uint_t flag
, uint64_t mtime
[2],
1309 uint64_t ctime
[2], boolean_t have_tx
)
1315 if (have_tx
) { /* will sa_bulk_update happen really soon? */
1316 zp
->z_atime_dirty
= 0;
1319 zp
->z_atime_dirty
= 1;
1322 if (flag
& AT_ATIME
) {
1323 ZFS_TIME_ENCODE(&now
, zp
->z_atime
);
1326 if (flag
& AT_MTIME
) {
1327 ZFS_TIME_ENCODE(&now
, mtime
);
1328 if (zp
->z_zfsvfs
->z_use_fuids
) {
1329 zp
->z_pflags
|= (ZFS_ARCHIVE
|
1334 if (flag
& AT_CTIME
) {
1335 ZFS_TIME_ENCODE(&now
, ctime
);
1336 if (zp
->z_zfsvfs
->z_use_fuids
)
1337 zp
->z_pflags
|= ZFS_ARCHIVE
;
1342 * Grow the block size for a file.
1344 * IN: zp - znode of file to free data in.
1345 * size - requested block size
1346 * tx - open transaction.
1348 * NOTE: this function assumes that the znode is write locked.
1351 zfs_grow_blocksize(znode_t
*zp
, uint64_t size
, dmu_tx_t
*tx
)
1356 if (size
<= zp
->z_blksz
)
1359 * If the file size is already greater than the current blocksize,
1360 * we will not grow. If there is more than one block in a file,
1361 * the blocksize cannot change.
1363 if (zp
->z_blksz
&& zp
->z_size
> zp
->z_blksz
)
1366 error
= dmu_object_set_blocksize(zp
->z_zfsvfs
->z_os
, zp
->z_id
,
1369 if (error
== ENOTSUP
)
1373 /* What blocksize did we actually get? */
1374 dmu_object_size_from_db(sa_get_db(zp
->z_sa_hdl
), &zp
->z_blksz
, &dummy
);
1378 * This is a dummy interface used when pvn_vplist_dirty() should *not*
1379 * be calling back into the fs for a putpage(). E.g.: when truncating
1380 * a file, the pages being "thrown away* don't need to be written out.
1384 zfs_no_putpage(vnode_t
*vp
, page_t
*pp
, uoff_t
*offp
, size_t *lenp
,
1385 int flags
, cred_t
*cr
)
1392 * Increase the file length
1394 * IN: zp - znode of file to free data in.
1395 * end - new end-of-file
1397 * RETURN: 0 on success, error code on failure
1400 zfs_extend(znode_t
*zp
, uint64_t end
)
1402 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1409 * We will change zp_size, lock the whole file.
1411 rl
= zfs_range_lock(zp
, 0, UINT64_MAX
, RL_WRITER
);
1414 * Nothing to do if file already at desired length.
1416 if (end
<= zp
->z_size
) {
1417 zfs_range_unlock(rl
);
1420 tx
= dmu_tx_create(zfsvfs
->z_os
);
1421 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1422 zfs_sa_upgrade_txholds(tx
, zp
);
1423 if (end
> zp
->z_blksz
&&
1424 (!ISP2(zp
->z_blksz
) || zp
->z_blksz
< zfsvfs
->z_max_blksz
)) {
1426 * We are growing the file past the current block size.
1428 if (zp
->z_blksz
> zp
->z_zfsvfs
->z_max_blksz
) {
1430 * File's blocksize is already larger than the
1431 * "recordsize" property. Only let it grow to
1432 * the next power of 2.
1434 ASSERT(!ISP2(zp
->z_blksz
));
1435 newblksz
= MIN(end
, 1 << highbit64(zp
->z_blksz
));
1437 newblksz
= MIN(end
, zp
->z_zfsvfs
->z_max_blksz
);
1439 dmu_tx_hold_write(tx
, zp
->z_id
, 0, newblksz
);
1444 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1447 zfs_range_unlock(rl
);
1452 zfs_grow_blocksize(zp
, newblksz
, tx
);
1456 VERIFY(0 == sa_update(zp
->z_sa_hdl
, SA_ZPL_SIZE(zp
->z_zfsvfs
),
1457 &zp
->z_size
, sizeof (zp
->z_size
), tx
));
1459 zfs_range_unlock(rl
);
1467 * Free space in a file.
1469 * IN: zp - znode of file to free data in.
1470 * off - start of section to free.
1471 * len - length of section to free.
1473 * RETURN: 0 on success, error code on failure
1476 zfs_free_range(znode_t
*zp
, uint64_t off
, uint64_t len
)
1478 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1483 * Lock the range being freed.
1485 rl
= zfs_range_lock(zp
, off
, len
, RL_WRITER
);
1488 * Nothing to do if file already at desired length.
1490 if (off
>= zp
->z_size
) {
1491 zfs_range_unlock(rl
);
1495 if (off
+ len
> zp
->z_size
)
1496 len
= zp
->z_size
- off
;
1498 error
= dmu_free_long_range(zfsvfs
->z_os
, zp
->z_id
, off
, len
);
1500 zfs_range_unlock(rl
);
1508 * IN: zp - znode of file to free data in.
1509 * end - new end-of-file.
1511 * RETURN: 0 on success, error code on failure
1514 zfs_trunc(znode_t
*zp
, uint64_t end
)
1516 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1517 vnode_t
*vp
= ZTOV(zp
);
1521 sa_bulk_attr_t bulk
[2];
1525 * We will change zp_size, lock the whole file.
1527 rl
= zfs_range_lock(zp
, 0, UINT64_MAX
, RL_WRITER
);
1530 * Nothing to do if file already at desired length.
1532 if (end
>= zp
->z_size
) {
1533 zfs_range_unlock(rl
);
1537 error
= dmu_free_long_range(zfsvfs
->z_os
, zp
->z_id
, end
,
1540 zfs_range_unlock(rl
);
1543 tx
= dmu_tx_create(zfsvfs
->z_os
);
1544 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1545 zfs_sa_upgrade_txholds(tx
, zp
);
1546 dmu_tx_mark_netfree(tx
);
1547 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1550 zfs_range_unlock(rl
);
1555 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zfsvfs
),
1556 NULL
, &zp
->z_size
, sizeof (zp
->z_size
));
1559 zp
->z_pflags
&= ~ZFS_SPARSE
;
1560 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zfsvfs
),
1561 NULL
, &zp
->z_pflags
, 8);
1563 VERIFY(sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
) == 0);
1568 * Clear any mapped pages in the truncated region. This has to
1569 * happen outside of the transaction to avoid the possibility of
1570 * a deadlock with someone trying to push a page that we are
1571 * about to invalidate.
1573 if (vn_has_cached_data(vp
)) {
1575 uint64_t start
= end
& PAGEMASK
;
1576 int poff
= end
& PAGEOFFSET
;
1578 if (poff
!= 0 && (pp
= page_lookup(&vp
->v_object
, start
, SE_SHARED
))) {
1580 * We need to zero a partial page.
1582 pagezero(pp
, poff
, PAGESIZE
- poff
);
1586 error
= pvn_vplist_dirty(vp
, start
, zfs_no_putpage
,
1587 B_INVAL
| B_TRUNC
, NULL
);
1591 zfs_range_unlock(rl
);
1597 * Free space in a file
1599 * IN: zp - znode of file to free data in.
1600 * off - start of range
1601 * len - end of range (0 => EOF)
1602 * flag - current file open mode flags.
1603 * log - TRUE if this action should be logged
1605 * RETURN: 0 on success, error code on failure
1608 zfs_freesp(znode_t
*zp
, uint64_t off
, uint64_t len
, int flag
, boolean_t log
)
1610 vnode_t
*vp
= ZTOV(zp
);
1612 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1613 zilog_t
*zilog
= zfsvfs
->z_log
;
1615 uint64_t mtime
[2], ctime
[2];
1616 sa_bulk_attr_t bulk
[3];
1620 if ((error
= sa_lookup(zp
->z_sa_hdl
, SA_ZPL_MODE(zfsvfs
), &mode
,
1621 sizeof (mode
))) != 0)
1624 if (off
> zp
->z_size
) {
1625 error
= zfs_extend(zp
, off
+len
);
1626 if (error
== 0 && log
)
1633 * Check for any locks in the region to be freed.
1636 if (MANDLOCK(vp
, (mode_t
)mode
)) {
1637 uint64_t length
= (len
? len
: zp
->z_size
- off
);
1638 if (error
= chklock(vp
, FWRITE
, off
, length
, flag
, NULL
))
1643 error
= zfs_trunc(zp
, off
);
1645 if ((error
= zfs_free_range(zp
, off
, len
)) == 0 &&
1646 off
+ len
> zp
->z_size
)
1647 error
= zfs_extend(zp
, off
+len
);
1652 tx
= dmu_tx_create(zfsvfs
->z_os
);
1653 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1654 zfs_sa_upgrade_txholds(tx
, zp
);
1655 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1661 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zfsvfs
), NULL
, mtime
, 16);
1662 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zfsvfs
), NULL
, ctime
, 16);
1663 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zfsvfs
),
1664 NULL
, &zp
->z_pflags
, 8);
1665 zfs_tstamp_update_setup(zp
, CONTENT_MODIFIED
, mtime
, ctime
, B_TRUE
);
1666 error
= sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
);
1669 zfs_log_truncate(zilog
, tx
, TX_TRUNCATE
, zp
, off
, len
);
1676 zfs_create_fs(objset_t
*os
, cred_t
*cr
, nvlist_t
*zplprops
, dmu_tx_t
*tx
)
1678 uint64_t moid
, obj
, sa_obj
, version
;
1679 uint64_t sense
= ZFS_CASE_SENSITIVE
;
1684 znode_t
*rootzp
= NULL
;
1689 zfs_acl_ids_t acl_ids
;
1692 * First attempt to create master node.
1695 * In an empty objset, there are no blocks to read and thus
1696 * there can be no i/o errors (which we assert below).
1698 moid
= MASTER_NODE_OBJ
;
1699 error
= zap_create_claim(os
, moid
, DMU_OT_MASTER_NODE
,
1700 DMU_OT_NONE
, 0, tx
);
1704 * Set starting attributes.
1706 version
= zfs_zpl_version_map(spa_version(dmu_objset_spa(os
)));
1708 while ((elem
= nvlist_next_nvpair(zplprops
, elem
)) != NULL
) {
1709 /* For the moment we expect all zpl props to be uint64_ts */
1713 ASSERT(nvpair_type(elem
) == DATA_TYPE_UINT64
);
1714 VERIFY(nvpair_value_uint64(elem
, &val
) == 0);
1715 name
= nvpair_name(elem
);
1716 if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_VERSION
)) == 0) {
1720 error
= zap_update(os
, moid
, name
, 8, 1, &val
, tx
);
1723 if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_NORMALIZE
)) == 0)
1725 else if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_CASE
)) == 0)
1728 ASSERT(version
!= 0);
1729 error
= zap_update(os
, moid
, ZPL_VERSION_STR
, 8, 1, &version
, tx
);
1732 * Create zap object used for SA attribute registration
1735 if (version
>= ZPL_VERSION_SA
) {
1736 sa_obj
= zap_create(os
, DMU_OT_SA_MASTER_NODE
,
1737 DMU_OT_NONE
, 0, tx
);
1738 error
= zap_add(os
, moid
, ZFS_SA_ATTRS
, 8, 1, &sa_obj
, tx
);
1744 * Create a delete queue.
1746 obj
= zap_create(os
, DMU_OT_UNLINKED_SET
, DMU_OT_NONE
, 0, tx
);
1748 error
= zap_add(os
, moid
, ZFS_UNLINKED_SET
, 8, 1, &obj
, tx
);
1752 * Create root znode. Create minimal znode/vnode/zfsvfs
1753 * to allow zfs_mknode to work.
1755 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
1756 vattr
.va_type
= VDIR
;
1757 vattr
.va_mode
= S_IFDIR
|0755;
1758 vattr
.va_uid
= crgetuid(cr
);
1759 vattr
.va_gid
= crgetgid(cr
);
1761 rootzp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
1762 ASSERT(!POINTER_IS_VALID(rootzp
->z_zfsvfs
));
1763 rootzp
->z_moved
= 0;
1764 rootzp
->z_unlinked
= 0;
1765 rootzp
->z_atime_dirty
= 0;
1766 rootzp
->z_is_sa
= USE_SA(version
, os
);
1772 zfsvfs
= kmem_zalloc(sizeof (zfsvfs_t
), KM_SLEEP
);
1774 zfsvfs
->z_parent
= zfsvfs
;
1775 zfsvfs
->z_version
= version
;
1776 zfsvfs
->z_use_fuids
= USE_FUIDS(version
, os
);
1777 zfsvfs
->z_use_sa
= USE_SA(version
, os
);
1778 zfsvfs
->z_norm
= norm
;
1780 error
= sa_setup(os
, sa_obj
, zfs_attr_table
, ZPL_END
,
1781 &zfsvfs
->z_attr_table
);
1786 * Fold case on file systems that are always or sometimes case
1789 if (sense
== ZFS_CASE_INSENSITIVE
|| sense
== ZFS_CASE_MIXED
)
1790 zfsvfs
->z_norm
|= U8_TEXTPREP_TOUPPER
;
1792 mutex_init(&zfsvfs
->z_znodes_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
1793 list_create(&zfsvfs
->z_all_znodes
, sizeof (znode_t
),
1794 offsetof(znode_t
, z_link_node
));
1796 for (i
= 0; i
!= ZFS_OBJ_MTX_SZ
; i
++)
1797 mutex_init(&zfsvfs
->z_hold_mtx
[i
], NULL
, MUTEX_DEFAULT
, NULL
);
1799 rootzp
->z_zfsvfs
= zfsvfs
;
1800 VERIFY(0 == zfs_acl_ids_create(rootzp
, IS_ROOT_NODE
, &vattr
,
1801 cr
, NULL
, &acl_ids
));
1802 zfs_mknode(rootzp
, &vattr
, tx
, cr
, IS_ROOT_NODE
, &zp
, &acl_ids
);
1803 ASSERT3P(zp
, ==, rootzp
);
1804 ASSERT(!vn_in_dnlc(ZTOV(rootzp
))); /* not valid to move */
1805 error
= zap_add(os
, moid
, ZFS_ROOT_OBJ
, 8, 1, &rootzp
->z_id
, tx
);
1807 zfs_acl_ids_free(&acl_ids
);
1808 POINTER_INVALIDATE(&rootzp
->z_zfsvfs
);
1810 ZTOV(rootzp
)->v_count
= 0;
1811 sa_handle_destroy(rootzp
->z_sa_hdl
);
1812 kmem_cache_free(znode_cache
, rootzp
);
1815 * Create shares directory
1818 error
= zfs_create_share_dir(zfsvfs
, tx
);
1822 for (i
= 0; i
!= ZFS_OBJ_MTX_SZ
; i
++)
1823 mutex_destroy(&zfsvfs
->z_hold_mtx
[i
]);
1824 kmem_free(zfsvfs
, sizeof (zfsvfs_t
));
1827 #endif /* _KERNEL */
1830 zfs_sa_setup(objset_t
*osp
, sa_attr_type_t
**sa_table
)
1832 uint64_t sa_obj
= 0;
1835 error
= zap_lookup(osp
, MASTER_NODE_OBJ
, ZFS_SA_ATTRS
, 8, 1, &sa_obj
);
1836 if (error
!= 0 && error
!= ENOENT
)
1839 error
= sa_setup(osp
, sa_obj
, zfs_attr_table
, ZPL_END
, sa_table
);
1844 zfs_grab_sa_handle(objset_t
*osp
, uint64_t obj
, sa_handle_t
**hdlp
,
1845 dmu_buf_t
**db
, void *tag
)
1847 dmu_object_info_t doi
;
1850 if ((error
= sa_buf_hold(osp
, obj
, tag
, db
)) != 0)
1853 dmu_object_info_from_db(*db
, &doi
);
1854 if ((doi
.doi_bonus_type
!= DMU_OT_SA
&&
1855 doi
.doi_bonus_type
!= DMU_OT_ZNODE
) ||
1856 doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1857 doi
.doi_bonus_size
< sizeof (znode_phys_t
)) {
1858 sa_buf_rele(*db
, tag
);
1859 return (SET_ERROR(ENOTSUP
));
1862 error
= sa_handle_get(osp
, obj
, NULL
, SA_HDL_PRIVATE
, hdlp
);
1864 sa_buf_rele(*db
, tag
);
1872 zfs_release_sa_handle(sa_handle_t
*hdl
, dmu_buf_t
*db
, void *tag
)
1874 sa_handle_destroy(hdl
);
1875 sa_buf_rele(db
, tag
);
1879 * Given an object number, return its parent object number and whether
1880 * or not the object is an extended attribute directory.
1883 zfs_obj_to_pobj(objset_t
*osp
, sa_handle_t
*hdl
, sa_attr_type_t
*sa_table
,
1884 uint64_t *pobjp
, int *is_xattrdir
)
1889 uint64_t parent_mode
;
1890 sa_bulk_attr_t bulk
[3];
1891 sa_handle_t
*sa_hdl
;
1896 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_PARENT
], NULL
,
1897 &parent
, sizeof (parent
));
1898 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_FLAGS
], NULL
,
1899 &pflags
, sizeof (pflags
));
1900 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_MODE
], NULL
,
1901 &mode
, sizeof (mode
));
1903 if ((error
= sa_bulk_lookup(hdl
, bulk
, count
)) != 0)
1907 * When a link is removed its parent pointer is not changed and will
1908 * be invalid. There are two cases where a link is removed but the
1909 * file stays around, when it goes to the delete queue and when there
1910 * are additional links.
1912 error
= zfs_grab_sa_handle(osp
, parent
, &sa_hdl
, &sa_db
, FTAG
);
1916 error
= sa_lookup(sa_hdl
, ZPL_MODE
, &parent_mode
, sizeof (parent_mode
));
1917 zfs_release_sa_handle(sa_hdl
, sa_db
, FTAG
);
1921 *is_xattrdir
= ((pflags
& ZFS_XATTR
) != 0) && S_ISDIR(mode
);
1924 * Extended attributes can be applied to files, directories, etc.
1925 * Otherwise the parent must be a directory.
1927 if (!*is_xattrdir
&& !S_ISDIR(parent_mode
))
1928 return (SET_ERROR(EINVAL
));
1936 * Given an object number, return some zpl level statistics
1939 zfs_obj_to_stats_impl(sa_handle_t
*hdl
, sa_attr_type_t
*sa_table
,
1942 sa_bulk_attr_t bulk
[4];
1945 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_MODE
], NULL
,
1946 &sb
->zs_mode
, sizeof (sb
->zs_mode
));
1947 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_GEN
], NULL
,
1948 &sb
->zs_gen
, sizeof (sb
->zs_gen
));
1949 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_LINKS
], NULL
,
1950 &sb
->zs_links
, sizeof (sb
->zs_links
));
1951 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_CTIME
], NULL
,
1952 &sb
->zs_ctime
, sizeof (sb
->zs_ctime
));
1954 return (sa_bulk_lookup(hdl
, bulk
, count
));
1958 zfs_obj_to_path_impl(objset_t
*osp
, uint64_t obj
, sa_handle_t
*hdl
,
1959 sa_attr_type_t
*sa_table
, char *buf
, int len
)
1961 sa_handle_t
*sa_hdl
;
1962 sa_handle_t
*prevhdl
= NULL
;
1963 dmu_buf_t
*prevdb
= NULL
;
1964 dmu_buf_t
*sa_db
= NULL
;
1965 char *path
= buf
+ len
- 1;
1971 uint64_t deleteq_obj
;
1972 VERIFY0(zap_lookup(osp
, MASTER_NODE_OBJ
,
1973 ZFS_UNLINKED_SET
, sizeof (uint64_t), 1, &deleteq_obj
));
1974 error
= zap_lookup_int(osp
, deleteq_obj
, obj
);
1977 } else if (error
!= ENOENT
) {
1984 char component
[MAXNAMELEN
+ 2];
1989 zfs_release_sa_handle(prevhdl
, prevdb
, FTAG
);
1991 if ((error
= zfs_obj_to_pobj(osp
, sa_hdl
, sa_table
, &pobj
,
1992 &is_xattrdir
)) != 0)
2003 (void) sprintf(component
+ 1, "<xattrdir>");
2005 error
= zap_value_search(osp
, pobj
, obj
,
2006 ZFS_DIRENT_OBJ(-1ULL), component
+ 1);
2011 complen
= strlen(component
);
2013 ASSERT(path
>= buf
);
2014 bcopy(component
, path
, complen
);
2017 if (sa_hdl
!= hdl
) {
2021 error
= zfs_grab_sa_handle(osp
, obj
, &sa_hdl
, &sa_db
, FTAG
);
2029 if (sa_hdl
!= NULL
&& sa_hdl
!= hdl
) {
2030 ASSERT(sa_db
!= NULL
);
2031 zfs_release_sa_handle(sa_hdl
, sa_db
, FTAG
);
2035 (void) memmove(buf
, path
, buf
+ len
- path
);
2041 zfs_obj_to_path(objset_t
*osp
, uint64_t obj
, char *buf
, int len
)
2043 sa_attr_type_t
*sa_table
;
2048 error
= zfs_sa_setup(osp
, &sa_table
);
2052 error
= zfs_grab_sa_handle(osp
, obj
, &hdl
, &db
, FTAG
);
2056 error
= zfs_obj_to_path_impl(osp
, obj
, hdl
, sa_table
, buf
, len
);
2058 zfs_release_sa_handle(hdl
, db
, FTAG
);
2063 zfs_obj_to_stats(objset_t
*osp
, uint64_t obj
, zfs_stat_t
*sb
,
2066 char *path
= buf
+ len
- 1;
2067 sa_attr_type_t
*sa_table
;
2074 error
= zfs_sa_setup(osp
, &sa_table
);
2078 error
= zfs_grab_sa_handle(osp
, obj
, &hdl
, &db
, FTAG
);
2082 error
= zfs_obj_to_stats_impl(hdl
, sa_table
, sb
);
2084 zfs_release_sa_handle(hdl
, db
, FTAG
);
2088 error
= zfs_obj_to_path_impl(osp
, obj
, hdl
, sa_table
, buf
, len
);
2090 zfs_release_sa_handle(hdl
, db
, FTAG
);