4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
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/mkdev.h>
37 #include <sys/u8_textprep.h>
38 #include <sys/dsl_dataset.h>
40 #include <sys/vfs_opreg.h>
41 #include <sys/vnode.h>
44 #include <sys/errno.h>
45 #include <sys/unistd.h>
47 #include <sys/atomic.h>
49 #include "fs/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/zfs_vnops.h>
56 #include <sys/zfs_ctldir.h>
57 #include <sys/dnode.h>
58 #include <sys/fs/zfs.h>
59 #include <sys/kidmap.h>
64 #include <sys/dmu_objset.h>
65 #include <sys/dmu_tx.h>
66 #include <sys/refcount.h>
69 #include <sys/zfs_znode.h>
71 #include <sys/zfs_sa.h>
72 #include <sys/zfs_stat.h>
75 #include "zfs_comutil.h"
78 * Define ZNODE_STATS to turn on statistic gathering. By default, it is only
79 * turned on when DEBUG is also defined.
86 #define ZNODE_STAT_ADD(stat) ((stat)++)
88 #define ZNODE_STAT_ADD(stat) /* nothing */
89 #endif /* ZNODE_STATS */
92 * Functions needed for userland (ie: libzpool) are not put under
93 * #ifdef_KERNEL; the rest of the functions have dependencies
94 * (such as VFS logic) that will not compile easily in userland.
98 static kmem_cache_t
*znode_cache
= NULL
;
99 static kmem_cache_t
*znode_hold_cache
= NULL
;
100 unsigned int zfs_object_mutex_size
= ZFS_OBJ_MTX_SZ
;
104 zfs_znode_cache_constructor(void *buf
, void *arg
, int kmflags
)
108 inode_init_once(ZTOI(zp
));
109 list_link_init(&zp
->z_link_node
);
111 mutex_init(&zp
->z_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
112 rw_init(&zp
->z_parent_lock
, NULL
, RW_DEFAULT
, NULL
);
113 rw_init(&zp
->z_name_lock
, NULL
, RW_NOLOCKDEP
, NULL
);
114 mutex_init(&zp
->z_acl_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
115 rw_init(&zp
->z_xattr_lock
, NULL
, RW_DEFAULT
, NULL
);
117 zfs_rlock_init(&zp
->z_range_lock
);
119 zp
->z_dirlocks
= NULL
;
120 zp
->z_acl_cached
= NULL
;
121 zp
->z_xattr_cached
= NULL
;
128 zfs_znode_cache_destructor(void *buf
, void *arg
)
132 ASSERT(!list_link_active(&zp
->z_link_node
));
133 mutex_destroy(&zp
->z_lock
);
134 rw_destroy(&zp
->z_parent_lock
);
135 rw_destroy(&zp
->z_name_lock
);
136 mutex_destroy(&zp
->z_acl_lock
);
137 rw_destroy(&zp
->z_xattr_lock
);
138 zfs_rlock_destroy(&zp
->z_range_lock
);
140 ASSERT(zp
->z_dirlocks
== NULL
);
141 ASSERT(zp
->z_acl_cached
== NULL
);
142 ASSERT(zp
->z_xattr_cached
== NULL
);
146 zfs_znode_hold_cache_constructor(void *buf
, void *arg
, int kmflags
)
148 znode_hold_t
*zh
= buf
;
150 mutex_init(&zh
->zh_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
151 refcount_create(&zh
->zh_refcount
);
152 zh
->zh_obj
= ZFS_NO_OBJECT
;
158 zfs_znode_hold_cache_destructor(void *buf
, void *arg
)
160 znode_hold_t
*zh
= buf
;
162 mutex_destroy(&zh
->zh_lock
);
163 refcount_destroy(&zh
->zh_refcount
);
170 * Initialize zcache. The KMC_SLAB hint is used in order that it be
171 * backed by kmalloc() when on the Linux slab in order that any
172 * wait_on_bit() operations on the related inode operate properly.
174 ASSERT(znode_cache
== NULL
);
175 znode_cache
= kmem_cache_create("zfs_znode_cache",
176 sizeof (znode_t
), 0, zfs_znode_cache_constructor
,
177 zfs_znode_cache_destructor
, NULL
, NULL
, NULL
, KMC_SLAB
);
179 ASSERT(znode_hold_cache
== NULL
);
180 znode_hold_cache
= kmem_cache_create("zfs_znode_hold_cache",
181 sizeof (znode_hold_t
), 0, zfs_znode_hold_cache_constructor
,
182 zfs_znode_hold_cache_destructor
, NULL
, NULL
, NULL
, 0);
192 kmem_cache_destroy(znode_cache
);
195 if (znode_hold_cache
)
196 kmem_cache_destroy(znode_hold_cache
);
197 znode_hold_cache
= NULL
;
201 * The zfs_znode_hold_enter() / zfs_znode_hold_exit() functions are used to
202 * serialize access to a znode and its SA buffer while the object is being
203 * created or destroyed. This kind of locking would normally reside in the
204 * znode itself but in this case that's impossible because the znode and SA
205 * buffer may not yet exist. Therefore the locking is handled externally
206 * with an array of mutexs and AVLs trees which contain per-object locks.
208 * In zfs_znode_hold_enter() a per-object lock is created as needed, inserted
209 * in to the correct AVL tree and finally the per-object lock is held. In
210 * zfs_znode_hold_exit() the process is reversed. The per-object lock is
211 * released, removed from the AVL tree and destroyed if there are no waiters.
213 * This scheme has two important properties:
215 * 1) No memory allocations are performed while holding one of the z_hold_locks.
216 * This ensures evict(), which can be called from direct memory reclaim, will
217 * never block waiting on a z_hold_locks which just happens to have hashed
220 * 2) All locks used to serialize access to an object are per-object and never
221 * shared. This minimizes lock contention without creating a large number
222 * of dedicated locks.
224 * On the downside it does require znode_lock_t structures to be frequently
225 * allocated and freed. However, because these are backed by a kmem cache
226 * and very short lived this cost is minimal.
229 zfs_znode_hold_compare(const void *a
, const void *b
)
231 const znode_hold_t
*zh_a
= (const znode_hold_t
*)a
;
232 const znode_hold_t
*zh_b
= (const znode_hold_t
*)b
;
234 return (AVL_CMP(zh_a
->zh_obj
, zh_b
->zh_obj
));
238 zfs_znode_held(zfs_sb_t
*zsb
, uint64_t obj
)
240 znode_hold_t
*zh
, search
;
241 int i
= ZFS_OBJ_HASH(zsb
, obj
);
246 mutex_enter(&zsb
->z_hold_locks
[i
]);
247 zh
= avl_find(&zsb
->z_hold_trees
[i
], &search
, NULL
);
248 held
= (zh
&& MUTEX_HELD(&zh
->zh_lock
)) ? B_TRUE
: B_FALSE
;
249 mutex_exit(&zsb
->z_hold_locks
[i
]);
254 static znode_hold_t
*
255 zfs_znode_hold_enter(zfs_sb_t
*zsb
, uint64_t obj
)
257 znode_hold_t
*zh
, *zh_new
, search
;
258 int i
= ZFS_OBJ_HASH(zsb
, obj
);
259 boolean_t found
= B_FALSE
;
261 zh_new
= kmem_cache_alloc(znode_hold_cache
, KM_SLEEP
);
262 zh_new
->zh_obj
= obj
;
265 mutex_enter(&zsb
->z_hold_locks
[i
]);
266 zh
= avl_find(&zsb
->z_hold_trees
[i
], &search
, NULL
);
267 if (likely(zh
== NULL
)) {
269 avl_add(&zsb
->z_hold_trees
[i
], zh
);
271 ASSERT3U(zh
->zh_obj
, ==, obj
);
274 refcount_add(&zh
->zh_refcount
, NULL
);
275 mutex_exit(&zsb
->z_hold_locks
[i
]);
278 kmem_cache_free(znode_hold_cache
, zh_new
);
280 ASSERT(MUTEX_NOT_HELD(&zh
->zh_lock
));
281 ASSERT3S(refcount_count(&zh
->zh_refcount
), >, 0);
282 mutex_enter(&zh
->zh_lock
);
288 zfs_znode_hold_exit(zfs_sb_t
*zsb
, znode_hold_t
*zh
)
290 int i
= ZFS_OBJ_HASH(zsb
, zh
->zh_obj
);
291 boolean_t remove
= B_FALSE
;
293 ASSERT(zfs_znode_held(zsb
, zh
->zh_obj
));
294 ASSERT3S(refcount_count(&zh
->zh_refcount
), >, 0);
295 mutex_exit(&zh
->zh_lock
);
297 mutex_enter(&zsb
->z_hold_locks
[i
]);
298 if (refcount_remove(&zh
->zh_refcount
, NULL
) == 0) {
299 avl_remove(&zsb
->z_hold_trees
[i
], zh
);
302 mutex_exit(&zsb
->z_hold_locks
[i
]);
304 if (remove
== B_TRUE
)
305 kmem_cache_free(znode_hold_cache
, zh
);
309 zfs_create_share_dir(zfs_sb_t
*zsb
, dmu_tx_t
*tx
)
311 #ifdef HAVE_SMB_SHARE
312 zfs_acl_ids_t acl_ids
;
319 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
320 vattr
.va_mode
= S_IFDIR
| 0555;
321 vattr
.va_uid
= crgetuid(kcred
);
322 vattr
.va_gid
= crgetgid(kcred
);
324 sharezp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
325 sharezp
->z_moved
= 0;
326 sharezp
->z_unlinked
= 0;
327 sharezp
->z_atime_dirty
= 0;
328 sharezp
->z_zfsvfs
= zfsvfs
;
329 sharezp
->z_is_sa
= zfsvfs
->z_use_sa
;
335 VERIFY(0 == zfs_acl_ids_create(sharezp
, IS_ROOT_NODE
, &vattr
,
336 kcred
, NULL
, &acl_ids
));
337 zfs_mknode(sharezp
, &vattr
, tx
, kcred
, IS_ROOT_NODE
, &zp
, &acl_ids
);
338 ASSERT3P(zp
, ==, sharezp
);
339 ASSERT(!vn_in_dnlc(ZTOV(sharezp
))); /* not valid to move */
340 POINTER_INVALIDATE(&sharezp
->z_zfsvfs
);
341 error
= zap_add(zfsvfs
->z_os
, MASTER_NODE_OBJ
,
342 ZFS_SHARES_DIR
, 8, 1, &sharezp
->z_id
, tx
);
343 zfsvfs
->z_shares_dir
= sharezp
->z_id
;
345 zfs_acl_ids_free(&acl_ids
);
346 // ZTOV(sharezp)->v_count = 0;
347 sa_handle_destroy(sharezp
->z_sa_hdl
);
348 kmem_cache_free(znode_cache
, sharezp
);
353 #endif /* HAVE_SMB_SHARE */
357 zfs_znode_sa_init(zfs_sb_t
*zsb
, znode_t
*zp
,
358 dmu_buf_t
*db
, dmu_object_type_t obj_type
, sa_handle_t
*sa_hdl
)
360 ASSERT(zfs_znode_held(zsb
, zp
->z_id
));
362 mutex_enter(&zp
->z_lock
);
364 ASSERT(zp
->z_sa_hdl
== NULL
);
365 ASSERT(zp
->z_acl_cached
== NULL
);
366 if (sa_hdl
== NULL
) {
367 VERIFY(0 == sa_handle_get_from_db(zsb
->z_os
, db
, zp
,
368 SA_HDL_SHARED
, &zp
->z_sa_hdl
));
370 zp
->z_sa_hdl
= sa_hdl
;
371 sa_set_userp(sa_hdl
, zp
);
374 zp
->z_is_sa
= (obj_type
== DMU_OT_SA
) ? B_TRUE
: B_FALSE
;
376 mutex_exit(&zp
->z_lock
);
380 zfs_znode_dmu_fini(znode_t
*zp
)
382 ASSERT(zfs_znode_held(ZTOZSB(zp
), zp
->z_id
) || zp
->z_unlinked
||
383 RW_WRITE_HELD(&ZTOZSB(zp
)->z_teardown_inactive_lock
));
385 sa_handle_destroy(zp
->z_sa_hdl
);
390 * Called by new_inode() to allocate a new inode.
393 zfs_inode_alloc(struct super_block
*sb
, struct inode
**ip
)
397 zp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
404 * Called in multiple places when an inode should be destroyed.
407 zfs_inode_destroy(struct inode
*ip
)
409 znode_t
*zp
= ITOZ(ip
);
410 zfs_sb_t
*zsb
= ZTOZSB(zp
);
412 mutex_enter(&zsb
->z_znodes_lock
);
413 if (list_link_active(&zp
->z_link_node
)) {
414 list_remove(&zsb
->z_all_znodes
, zp
);
417 mutex_exit(&zsb
->z_znodes_lock
);
419 if (zp
->z_acl_cached
) {
420 zfs_acl_free(zp
->z_acl_cached
);
421 zp
->z_acl_cached
= NULL
;
424 if (zp
->z_xattr_cached
) {
425 nvlist_free(zp
->z_xattr_cached
);
426 zp
->z_xattr_cached
= NULL
;
429 kmem_cache_free(znode_cache
, zp
);
433 zfs_inode_set_ops(zfs_sb_t
*zsb
, struct inode
*ip
)
437 switch (ip
->i_mode
& S_IFMT
) {
439 ip
->i_op
= &zpl_inode_operations
;
440 ip
->i_fop
= &zpl_file_operations
;
441 ip
->i_mapping
->a_ops
= &zpl_address_space_operations
;
445 ip
->i_op
= &zpl_dir_inode_operations
;
446 ip
->i_fop
= &zpl_dir_file_operations
;
447 ITOZ(ip
)->z_zn_prefetch
= B_TRUE
;
451 ip
->i_op
= &zpl_symlink_inode_operations
;
455 * rdev is only stored in a SA only for device files.
459 (void) sa_lookup(ITOZ(ip
)->z_sa_hdl
, SA_ZPL_RDEV(zsb
), &rdev
,
464 init_special_inode(ip
, ip
->i_mode
, rdev
);
465 ip
->i_op
= &zpl_special_inode_operations
;
469 zfs_panic_recover("inode %llu has invalid mode: 0x%x\n",
470 (u_longlong_t
)ip
->i_ino
, ip
->i_mode
);
472 /* Assume the inode is a file and attempt to continue */
473 ip
->i_mode
= S_IFREG
| 0644;
474 ip
->i_op
= &zpl_inode_operations
;
475 ip
->i_fop
= &zpl_file_operations
;
476 ip
->i_mapping
->a_ops
= &zpl_address_space_operations
;
482 zfs_set_inode_flags(znode_t
*zp
, struct inode
*ip
)
485 * Linux and Solaris have different sets of file attributes, so we
486 * restrict this conversion to the intersection of the two.
489 if (zp
->z_pflags
& ZFS_IMMUTABLE
)
490 ip
->i_flags
|= S_IMMUTABLE
;
492 ip
->i_flags
&= ~S_IMMUTABLE
;
494 if (zp
->z_pflags
& ZFS_APPENDONLY
)
495 ip
->i_flags
|= S_APPEND
;
497 ip
->i_flags
&= ~S_APPEND
;
501 * Update the embedded inode given the znode. We should work toward
502 * eliminating this function as soon as possible by removing values
503 * which are duplicated between the znode and inode. If the generic
504 * inode has the correct field it should be used, and the ZFS code
505 * updated to access the inode. This can be done incrementally.
508 zfs_inode_update(znode_t
*zp
)
513 u_longlong_t i_blocks
;
519 /* Skip .zfs control nodes which do not exist on disk. */
520 if (zfsctl_is_node(ip
))
523 dmu_object_size_from_db(sa_get_db(zp
->z_sa_hdl
), &blksize
, &i_blocks
);
525 spin_lock(&ip
->i_lock
);
526 zfs_set_inode_flags(zp
, ip
);
527 ip
->i_blocks
= i_blocks
;
528 i_size_write(ip
, zp
->z_size
);
529 spin_unlock(&ip
->i_lock
);
534 * Construct a znode+inode and initialize.
536 * This does not do a call to dmu_set_user() that is
537 * up to the caller to do, in case you don't want to
541 zfs_znode_alloc(zfs_sb_t
*zsb
, dmu_buf_t
*db
, int blksz
,
542 dmu_object_type_t obj_type
, uint64_t obj
, sa_handle_t
*hdl
)
550 uint64_t z_uid
, z_gid
;
551 uint64_t atime
[2], mtime
[2], ctime
[2];
552 sa_bulk_attr_t bulk
[11];
557 ip
= new_inode(zsb
->z_sb
);
562 ASSERT(zp
->z_dirlocks
== NULL
);
563 ASSERT3P(zp
->z_acl_cached
, ==, NULL
);
564 ASSERT3P(zp
->z_xattr_cached
, ==, NULL
);
568 zp
->z_atime_dirty
= 0;
570 zp
->z_id
= db
->db_object
;
572 zp
->z_seq
= 0x7A4653;
574 zp
->z_is_mapped
= B_FALSE
;
575 zp
->z_is_ctldir
= B_FALSE
;
576 zp
->z_is_stale
= B_FALSE
;
577 zp
->z_range_lock
.zr_size
= &zp
->z_size
;
578 zp
->z_range_lock
.zr_blksz
= &zp
->z_blksz
;
579 zp
->z_range_lock
.zr_max_blksz
= &ZTOZSB(zp
)->z_max_blksz
;
581 zfs_znode_sa_init(zsb
, zp
, db
, obj_type
, hdl
);
583 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zsb
), NULL
, &mode
, 8);
584 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GEN(zsb
), NULL
, &tmp_gen
, 8);
585 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zsb
), NULL
, &zp
->z_size
, 8);
586 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_LINKS(zsb
), NULL
, &links
, 8);
587 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
), NULL
,
589 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_PARENT(zsb
), NULL
,
591 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_UID(zsb
), NULL
, &z_uid
, 8);
592 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GID(zsb
), NULL
, &z_gid
, 8);
593 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_ATIME(zsb
), NULL
, &atime
, 16);
594 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zsb
), NULL
, &mtime
, 16);
595 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zsb
), NULL
, &ctime
, 16);
597 if (sa_bulk_lookup(zp
->z_sa_hdl
, bulk
, count
) != 0 ||
601 sa_handle_destroy(zp
->z_sa_hdl
);
606 zp
->z_mode
= ip
->i_mode
= mode
;
607 ip
->i_generation
= (uint32_t)tmp_gen
;
608 ip
->i_blkbits
= SPA_MINBLOCKSHIFT
;
609 set_nlink(ip
, (uint32_t)links
);
610 zfs_uid_write(ip
, z_uid
);
611 zfs_gid_write(ip
, z_gid
);
613 ZFS_TIME_DECODE(&ip
->i_atime
, atime
);
614 ZFS_TIME_DECODE(&ip
->i_mtime
, mtime
);
615 ZFS_TIME_DECODE(&ip
->i_ctime
, ctime
);
618 zfs_inode_update(zp
);
619 zfs_inode_set_ops(zsb
, ip
);
622 * The only way insert_inode_locked() can fail is if the ip->i_ino
623 * number is already hashed for this super block. This can never
624 * happen because the inode numbers map 1:1 with the object numbers.
626 * The one exception is rolling back a mounted file system, but in
627 * this case all the active inode are unhashed during the rollback.
629 VERIFY3S(insert_inode_locked(ip
), ==, 0);
631 mutex_enter(&zsb
->z_znodes_lock
);
632 list_insert_tail(&zsb
->z_all_znodes
, zp
);
635 mutex_exit(&zsb
->z_znodes_lock
);
637 unlock_new_inode(ip
);
646 * Safely mark an inode dirty. Inodes which are part of a read-only
647 * file system or snapshot may not be dirtied.
650 zfs_mark_inode_dirty(struct inode
*ip
)
652 zfs_sb_t
*zsb
= ITOZSB(ip
);
654 if (zfs_is_readonly(zsb
) || dmu_objset_is_snapshot(zsb
->z_os
))
657 mark_inode_dirty(ip
);
660 static uint64_t empty_xattr
;
661 static uint64_t pad
[4];
662 static zfs_acl_phys_t acl_phys
;
664 * Create a new DMU object to hold a zfs znode.
666 * IN: dzp - parent directory for new znode
667 * vap - file attributes for new znode
668 * tx - dmu transaction id for zap operations
669 * cr - credentials of caller
671 * IS_ROOT_NODE - new object will be root
672 * IS_XATTR - new object is an attribute
673 * bonuslen - length of bonus buffer
674 * setaclp - File/Dir initial ACL
675 * fuidp - Tracks fuid allocation.
677 * OUT: zpp - allocated znode
681 zfs_mknode(znode_t
*dzp
, vattr_t
*vap
, dmu_tx_t
*tx
, cred_t
*cr
,
682 uint_t flag
, znode_t
**zpp
, zfs_acl_ids_t
*acl_ids
)
684 uint64_t crtime
[2], atime
[2], mtime
[2], ctime
[2];
685 uint64_t mode
, size
, links
, parent
, pflags
;
686 uint64_t dzp_pflags
= 0;
688 zfs_sb_t
*zsb
= ZTOZSB(dzp
);
695 dmu_object_type_t obj_type
;
696 sa_bulk_attr_t
*sa_attrs
;
698 zfs_acl_locator_cb_t locate
= { 0 };
702 obj
= vap
->va_nodeid
;
703 now
= vap
->va_ctime
; /* see zfs_replay_create() */
704 gen
= vap
->va_nblocks
; /* ditto */
705 dnodesize
= vap
->va_fsid
; /* ditto */
709 gen
= dmu_tx_get_txg(tx
);
710 dnodesize
= dmu_objset_dnodesize(zsb
->z_os
);
714 dnodesize
= DNODE_MIN_SIZE
;
716 obj_type
= zsb
->z_use_sa
? DMU_OT_SA
: DMU_OT_ZNODE
;
718 bonuslen
= (obj_type
== DMU_OT_SA
) ?
719 DN_BONUS_SIZE(dnodesize
) : ZFS_OLD_ZNODE_PHYS_SIZE
;
722 * Create a new DMU object.
725 * There's currently no mechanism for pre-reading the blocks that will
726 * be needed to allocate a new object, so we accept the small chance
727 * that there will be an i/o error and we will fail one of the
730 if (S_ISDIR(vap
->va_mode
)) {
732 VERIFY0(zap_create_claim_norm_dnsize(zsb
->z_os
, obj
,
733 zsb
->z_norm
, DMU_OT_DIRECTORY_CONTENTS
,
734 obj_type
, bonuslen
, dnodesize
, tx
));
736 obj
= zap_create_norm_dnsize(zsb
->z_os
,
737 zsb
->z_norm
, DMU_OT_DIRECTORY_CONTENTS
,
738 obj_type
, bonuslen
, dnodesize
, tx
);
742 VERIFY0(dmu_object_claim_dnsize(zsb
->z_os
, obj
,
743 DMU_OT_PLAIN_FILE_CONTENTS
, 0,
744 obj_type
, bonuslen
, dnodesize
, tx
));
746 obj
= dmu_object_alloc_dnsize(zsb
->z_os
,
747 DMU_OT_PLAIN_FILE_CONTENTS
, 0,
748 obj_type
, bonuslen
, dnodesize
, tx
);
752 zh
= zfs_znode_hold_enter(zsb
, obj
);
753 VERIFY(0 == sa_buf_hold(zsb
->z_os
, obj
, NULL
, &db
));
756 * If this is the root, fix up the half-initialized parent pointer
757 * to reference the just-allocated physical data area.
759 if (flag
& IS_ROOT_NODE
) {
762 dzp_pflags
= dzp
->z_pflags
;
766 * If parent is an xattr, so am I.
768 if (dzp_pflags
& ZFS_XATTR
) {
772 if (zsb
->z_use_fuids
)
773 pflags
= ZFS_ARCHIVE
| ZFS_AV_MODIFIED
;
777 if (S_ISDIR(vap
->va_mode
)) {
778 size
= 2; /* contents ("." and "..") */
785 if (S_ISBLK(vap
->va_mode
) || S_ISCHR(vap
->va_mode
))
789 mode
= acl_ids
->z_mode
;
794 * No execs denied will be deterimed when zfs_mode_compute() is called.
796 pflags
|= acl_ids
->z_aclp
->z_hints
&
797 (ZFS_ACL_TRIVIAL
|ZFS_INHERIT_ACE
|ZFS_ACL_AUTO_INHERIT
|
798 ZFS_ACL_DEFAULTED
|ZFS_ACL_PROTECTED
);
800 ZFS_TIME_ENCODE(&now
, crtime
);
801 ZFS_TIME_ENCODE(&now
, ctime
);
803 if (vap
->va_mask
& ATTR_ATIME
) {
804 ZFS_TIME_ENCODE(&vap
->va_atime
, atime
);
806 ZFS_TIME_ENCODE(&now
, atime
);
809 if (vap
->va_mask
& ATTR_MTIME
) {
810 ZFS_TIME_ENCODE(&vap
->va_mtime
, mtime
);
812 ZFS_TIME_ENCODE(&now
, mtime
);
815 /* Now add in all of the "SA" attributes */
816 VERIFY(0 == sa_handle_get_from_db(zsb
->z_os
, db
, NULL
, SA_HDL_SHARED
,
820 * Setup the array of attributes to be replaced/set on the new file
822 * order for DMU_OT_ZNODE is critical since it needs to be constructed
823 * in the old znode_phys_t format. Don't change this ordering
825 sa_attrs
= kmem_alloc(sizeof (sa_bulk_attr_t
) * ZPL_END
, KM_SLEEP
);
827 if (obj_type
== DMU_OT_ZNODE
) {
828 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ATIME(zsb
),
830 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MTIME(zsb
),
832 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CTIME(zsb
),
834 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CRTIME(zsb
),
836 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GEN(zsb
),
838 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MODE(zsb
),
840 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_SIZE(zsb
),
842 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PARENT(zsb
),
845 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MODE(zsb
),
847 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_SIZE(zsb
),
849 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GEN(zsb
),
851 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_UID(zsb
),
852 NULL
, &acl_ids
->z_fuid
, 8);
853 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GID(zsb
),
854 NULL
, &acl_ids
->z_fgid
, 8);
855 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PARENT(zsb
),
857 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_FLAGS(zsb
),
859 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ATIME(zsb
),
861 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MTIME(zsb
),
863 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CTIME(zsb
),
865 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CRTIME(zsb
),
869 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_LINKS(zsb
), NULL
, &links
, 8);
871 if (obj_type
== DMU_OT_ZNODE
) {
872 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_XATTR(zsb
), NULL
,
875 if (obj_type
== DMU_OT_ZNODE
||
876 (S_ISBLK(vap
->va_mode
) || S_ISCHR(vap
->va_mode
))) {
877 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_RDEV(zsb
),
880 if (obj_type
== DMU_OT_ZNODE
) {
881 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_FLAGS(zsb
),
883 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_UID(zsb
), NULL
,
884 &acl_ids
->z_fuid
, 8);
885 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GID(zsb
), NULL
,
886 &acl_ids
->z_fgid
, 8);
887 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PAD(zsb
), NULL
, pad
,
888 sizeof (uint64_t) * 4);
889 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ZNODE_ACL(zsb
), NULL
,
890 &acl_phys
, sizeof (zfs_acl_phys_t
));
891 } else if (acl_ids
->z_aclp
->z_version
>= ZFS_ACL_VERSION_FUID
) {
892 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_DACL_COUNT(zsb
), NULL
,
893 &acl_ids
->z_aclp
->z_acl_count
, 8);
894 locate
.cb_aclp
= acl_ids
->z_aclp
;
895 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_DACL_ACES(zsb
),
896 zfs_acl_data_locator
, &locate
,
897 acl_ids
->z_aclp
->z_acl_bytes
);
898 mode
= zfs_mode_compute(mode
, acl_ids
->z_aclp
, &pflags
,
899 acl_ids
->z_fuid
, acl_ids
->z_fgid
);
902 VERIFY(sa_replace_all_by_template(sa_hdl
, sa_attrs
, cnt
, tx
) == 0);
904 if (!(flag
& IS_ROOT_NODE
)) {
905 *zpp
= zfs_znode_alloc(zsb
, db
, 0, obj_type
, obj
, sa_hdl
);
906 VERIFY(*zpp
!= NULL
);
910 * If we are creating the root node, the "parent" we
911 * passed in is the znode for the root.
915 (*zpp
)->z_sa_hdl
= sa_hdl
;
918 (*zpp
)->z_pflags
= pflags
;
919 (*zpp
)->z_mode
= ZTOI(*zpp
)->i_mode
= mode
;
920 (*zpp
)->z_dnodesize
= dnodesize
;
922 if (obj_type
== DMU_OT_ZNODE
||
923 acl_ids
->z_aclp
->z_version
< ZFS_ACL_VERSION_FUID
) {
924 VERIFY0(zfs_aclset_common(*zpp
, acl_ids
->z_aclp
, cr
, tx
));
926 kmem_free(sa_attrs
, sizeof (sa_bulk_attr_t
) * ZPL_END
);
927 zfs_znode_hold_exit(zsb
, zh
);
931 * Update in-core attributes. It is assumed the caller will be doing an
932 * sa_bulk_update to push the changes out.
935 zfs_xvattr_set(znode_t
*zp
, xvattr_t
*xvap
, dmu_tx_t
*tx
)
939 xoap
= xva_getxoptattr(xvap
);
942 if (XVA_ISSET_REQ(xvap
, XAT_CREATETIME
)) {
944 ZFS_TIME_ENCODE(&xoap
->xoa_createtime
, times
);
945 (void) sa_update(zp
->z_sa_hdl
, SA_ZPL_CRTIME(ZTOZSB(zp
)),
946 ×
, sizeof (times
), tx
);
947 XVA_SET_RTN(xvap
, XAT_CREATETIME
);
949 if (XVA_ISSET_REQ(xvap
, XAT_READONLY
)) {
950 ZFS_ATTR_SET(zp
, ZFS_READONLY
, xoap
->xoa_readonly
,
952 XVA_SET_RTN(xvap
, XAT_READONLY
);
954 if (XVA_ISSET_REQ(xvap
, XAT_HIDDEN
)) {
955 ZFS_ATTR_SET(zp
, ZFS_HIDDEN
, xoap
->xoa_hidden
,
957 XVA_SET_RTN(xvap
, XAT_HIDDEN
);
959 if (XVA_ISSET_REQ(xvap
, XAT_SYSTEM
)) {
960 ZFS_ATTR_SET(zp
, ZFS_SYSTEM
, xoap
->xoa_system
,
962 XVA_SET_RTN(xvap
, XAT_SYSTEM
);
964 if (XVA_ISSET_REQ(xvap
, XAT_ARCHIVE
)) {
965 ZFS_ATTR_SET(zp
, ZFS_ARCHIVE
, xoap
->xoa_archive
,
967 XVA_SET_RTN(xvap
, XAT_ARCHIVE
);
969 if (XVA_ISSET_REQ(xvap
, XAT_IMMUTABLE
)) {
970 ZFS_ATTR_SET(zp
, ZFS_IMMUTABLE
, xoap
->xoa_immutable
,
972 XVA_SET_RTN(xvap
, XAT_IMMUTABLE
);
974 if (XVA_ISSET_REQ(xvap
, XAT_NOUNLINK
)) {
975 ZFS_ATTR_SET(zp
, ZFS_NOUNLINK
, xoap
->xoa_nounlink
,
977 XVA_SET_RTN(xvap
, XAT_NOUNLINK
);
979 if (XVA_ISSET_REQ(xvap
, XAT_APPENDONLY
)) {
980 ZFS_ATTR_SET(zp
, ZFS_APPENDONLY
, xoap
->xoa_appendonly
,
982 XVA_SET_RTN(xvap
, XAT_APPENDONLY
);
984 if (XVA_ISSET_REQ(xvap
, XAT_NODUMP
)) {
985 ZFS_ATTR_SET(zp
, ZFS_NODUMP
, xoap
->xoa_nodump
,
987 XVA_SET_RTN(xvap
, XAT_NODUMP
);
989 if (XVA_ISSET_REQ(xvap
, XAT_OPAQUE
)) {
990 ZFS_ATTR_SET(zp
, ZFS_OPAQUE
, xoap
->xoa_opaque
,
992 XVA_SET_RTN(xvap
, XAT_OPAQUE
);
994 if (XVA_ISSET_REQ(xvap
, XAT_AV_QUARANTINED
)) {
995 ZFS_ATTR_SET(zp
, ZFS_AV_QUARANTINED
,
996 xoap
->xoa_av_quarantined
, zp
->z_pflags
, tx
);
997 XVA_SET_RTN(xvap
, XAT_AV_QUARANTINED
);
999 if (XVA_ISSET_REQ(xvap
, XAT_AV_MODIFIED
)) {
1000 ZFS_ATTR_SET(zp
, ZFS_AV_MODIFIED
, xoap
->xoa_av_modified
,
1002 XVA_SET_RTN(xvap
, XAT_AV_MODIFIED
);
1004 if (XVA_ISSET_REQ(xvap
, XAT_AV_SCANSTAMP
)) {
1005 zfs_sa_set_scanstamp(zp
, xvap
, tx
);
1006 XVA_SET_RTN(xvap
, XAT_AV_SCANSTAMP
);
1008 if (XVA_ISSET_REQ(xvap
, XAT_REPARSE
)) {
1009 ZFS_ATTR_SET(zp
, ZFS_REPARSE
, xoap
->xoa_reparse
,
1011 XVA_SET_RTN(xvap
, XAT_REPARSE
);
1013 if (XVA_ISSET_REQ(xvap
, XAT_OFFLINE
)) {
1014 ZFS_ATTR_SET(zp
, ZFS_OFFLINE
, xoap
->xoa_offline
,
1016 XVA_SET_RTN(xvap
, XAT_OFFLINE
);
1018 if (XVA_ISSET_REQ(xvap
, XAT_SPARSE
)) {
1019 ZFS_ATTR_SET(zp
, ZFS_SPARSE
, xoap
->xoa_sparse
,
1021 XVA_SET_RTN(xvap
, XAT_SPARSE
);
1026 zfs_zget(zfs_sb_t
*zsb
, uint64_t obj_num
, znode_t
**zpp
)
1028 dmu_object_info_t doi
;
1038 zh
= zfs_znode_hold_enter(zsb
, obj_num
);
1040 err
= sa_buf_hold(zsb
->z_os
, obj_num
, NULL
, &db
);
1042 zfs_znode_hold_exit(zsb
, zh
);
1046 dmu_object_info_from_db(db
, &doi
);
1047 if (doi
.doi_bonus_type
!= DMU_OT_SA
&&
1048 (doi
.doi_bonus_type
!= DMU_OT_ZNODE
||
1049 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1050 doi
.doi_bonus_size
< sizeof (znode_phys_t
)))) {
1051 sa_buf_rele(db
, NULL
);
1052 zfs_znode_hold_exit(zsb
, zh
);
1053 return (SET_ERROR(EINVAL
));
1056 hdl
= dmu_buf_get_user(db
);
1058 zp
= sa_get_userdata(hdl
);
1062 * Since "SA" does immediate eviction we
1063 * should never find a sa handle that doesn't
1064 * know about the znode.
1067 ASSERT3P(zp
, !=, NULL
);
1069 mutex_enter(&zp
->z_lock
);
1070 ASSERT3U(zp
->z_id
, ==, obj_num
);
1071 if (zp
->z_unlinked
) {
1072 err
= SET_ERROR(ENOENT
);
1075 * If igrab() returns NULL the VFS has independently
1076 * determined the inode should be evicted and has
1077 * called iput_final() to start the eviction process.
1078 * The SA handle is still valid but because the VFS
1079 * requires that the eviction succeed we must drop
1080 * our locks and references to allow the eviction to
1081 * complete. The zfs_zget() may then be retried.
1083 * This unlikely case could be optimized by registering
1084 * a sops->drop_inode() callback. The callback would
1085 * need to detect the active SA hold thereby informing
1086 * the VFS that this inode should not be evicted.
1088 if (igrab(ZTOI(zp
)) == NULL
) {
1089 mutex_exit(&zp
->z_lock
);
1090 sa_buf_rele(db
, NULL
);
1091 zfs_znode_hold_exit(zsb
, zh
);
1092 /* inode might need this to finish evict */
1099 mutex_exit(&zp
->z_lock
);
1100 sa_buf_rele(db
, NULL
);
1101 zfs_znode_hold_exit(zsb
, zh
);
1106 * Not found create new znode/vnode but only if file exists.
1108 * There is a small window where zfs_vget() could
1109 * find this object while a file create is still in
1110 * progress. This is checked for in zfs_znode_alloc()
1112 * if zfs_znode_alloc() fails it will drop the hold on the
1115 zp
= zfs_znode_alloc(zsb
, db
, doi
.doi_data_block_size
,
1116 doi
.doi_bonus_type
, obj_num
, NULL
);
1118 err
= SET_ERROR(ENOENT
);
1122 zfs_znode_hold_exit(zsb
, zh
);
1127 zfs_rezget(znode_t
*zp
)
1129 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1130 dmu_object_info_t doi
;
1132 uint64_t obj_num
= zp
->z_id
;
1135 sa_bulk_attr_t bulk
[10];
1139 uint64_t z_uid
, z_gid
;
1140 uint64_t atime
[2], mtime
[2], ctime
[2];
1144 * skip ctldir, otherwise they will always get invalidated. This will
1145 * cause funny behaviour for the mounted snapdirs. Especially for
1146 * Linux >= 3.18, d_invalidate will detach the mountpoint and prevent
1147 * anyone automount it again as long as someone is still using the
1150 if (zp
->z_is_ctldir
)
1153 zh
= zfs_znode_hold_enter(zsb
, obj_num
);
1155 mutex_enter(&zp
->z_acl_lock
);
1156 if (zp
->z_acl_cached
) {
1157 zfs_acl_free(zp
->z_acl_cached
);
1158 zp
->z_acl_cached
= NULL
;
1160 mutex_exit(&zp
->z_acl_lock
);
1162 rw_enter(&zp
->z_xattr_lock
, RW_WRITER
);
1163 if (zp
->z_xattr_cached
) {
1164 nvlist_free(zp
->z_xattr_cached
);
1165 zp
->z_xattr_cached
= NULL
;
1167 rw_exit(&zp
->z_xattr_lock
);
1169 ASSERT(zp
->z_sa_hdl
== NULL
);
1170 err
= sa_buf_hold(zsb
->z_os
, obj_num
, NULL
, &db
);
1172 zfs_znode_hold_exit(zsb
, zh
);
1176 dmu_object_info_from_db(db
, &doi
);
1177 if (doi
.doi_bonus_type
!= DMU_OT_SA
&&
1178 (doi
.doi_bonus_type
!= DMU_OT_ZNODE
||
1179 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1180 doi
.doi_bonus_size
< sizeof (znode_phys_t
)))) {
1181 sa_buf_rele(db
, NULL
);
1182 zfs_znode_hold_exit(zsb
, zh
);
1183 return (SET_ERROR(EINVAL
));
1186 zfs_znode_sa_init(zsb
, zp
, db
, doi
.doi_bonus_type
, NULL
);
1188 /* reload cached values */
1189 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GEN(zsb
), NULL
,
1190 &gen
, sizeof (gen
));
1191 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zsb
), NULL
,
1192 &zp
->z_size
, sizeof (zp
->z_size
));
1193 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_LINKS(zsb
), NULL
,
1194 &links
, sizeof (links
));
1195 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
), NULL
,
1196 &zp
->z_pflags
, sizeof (zp
->z_pflags
));
1197 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_UID(zsb
), NULL
,
1198 &z_uid
, sizeof (z_uid
));
1199 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GID(zsb
), NULL
,
1200 &z_gid
, sizeof (z_gid
));
1201 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zsb
), NULL
,
1202 &mode
, sizeof (mode
));
1203 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_ATIME(zsb
), NULL
,
1205 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zsb
), NULL
,
1207 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zsb
), NULL
,
1210 if (sa_bulk_lookup(zp
->z_sa_hdl
, bulk
, count
)) {
1211 zfs_znode_dmu_fini(zp
);
1212 zfs_znode_hold_exit(zsb
, zh
);
1213 return (SET_ERROR(EIO
));
1216 zp
->z_mode
= ZTOI(zp
)->i_mode
= mode
;
1217 zfs_uid_write(ZTOI(zp
), z_uid
);
1218 zfs_gid_write(ZTOI(zp
), z_gid
);
1220 ZFS_TIME_DECODE(&ZTOI(zp
)->i_atime
, atime
);
1221 ZFS_TIME_DECODE(&ZTOI(zp
)->i_mtime
, mtime
);
1222 ZFS_TIME_DECODE(&ZTOI(zp
)->i_ctime
, ctime
);
1224 if (gen
!= ZTOI(zp
)->i_generation
) {
1225 zfs_znode_dmu_fini(zp
);
1226 zfs_znode_hold_exit(zsb
, zh
);
1227 return (SET_ERROR(EIO
));
1230 zp
->z_unlinked
= (ZTOI(zp
)->i_nlink
== 0);
1231 set_nlink(ZTOI(zp
), (uint32_t)links
);
1233 zp
->z_blksz
= doi
.doi_data_block_size
;
1234 zp
->z_atime_dirty
= 0;
1235 zfs_inode_update(zp
);
1237 zfs_znode_hold_exit(zsb
, zh
);
1243 zfs_znode_delete(znode_t
*zp
, dmu_tx_t
*tx
)
1245 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1246 objset_t
*os
= zsb
->z_os
;
1247 uint64_t obj
= zp
->z_id
;
1248 uint64_t acl_obj
= zfs_external_acl(zp
);
1251 zh
= zfs_znode_hold_enter(zsb
, obj
);
1253 VERIFY(!zp
->z_is_sa
);
1254 VERIFY(0 == dmu_object_free(os
, acl_obj
, tx
));
1256 VERIFY(0 == dmu_object_free(os
, obj
, tx
));
1257 zfs_znode_dmu_fini(zp
);
1258 zfs_znode_hold_exit(zsb
, zh
);
1262 zfs_zinactive(znode_t
*zp
)
1264 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1265 uint64_t z_id
= zp
->z_id
;
1268 ASSERT(zp
->z_sa_hdl
);
1271 * Don't allow a zfs_zget() while were trying to release this znode.
1273 zh
= zfs_znode_hold_enter(zsb
, z_id
);
1275 mutex_enter(&zp
->z_lock
);
1278 * If this was the last reference to a file with no links,
1279 * remove the file from the file system.
1281 if (zp
->z_unlinked
) {
1282 mutex_exit(&zp
->z_lock
);
1283 zfs_znode_hold_exit(zsb
, zh
);
1288 mutex_exit(&zp
->z_lock
);
1289 zfs_znode_dmu_fini(zp
);
1291 zfs_znode_hold_exit(zsb
, zh
);
1295 zfs_compare_timespec(struct timespec
*t1
, struct timespec
*t2
)
1297 if (t1
->tv_sec
< t2
->tv_sec
)
1300 if (t1
->tv_sec
> t2
->tv_sec
)
1303 return (t1
->tv_nsec
- t2
->tv_nsec
);
1307 * Prepare to update znode time stamps.
1309 * IN: zp - znode requiring timestamp update
1310 * flag - ATTR_MTIME, ATTR_CTIME flags
1316 * Note: We don't update atime here, because we rely on Linux VFS to do
1320 zfs_tstamp_update_setup(znode_t
*zp
, uint_t flag
, uint64_t mtime
[2],
1329 if (flag
& ATTR_MTIME
) {
1330 ZFS_TIME_ENCODE(&now
, mtime
);
1331 ZFS_TIME_DECODE(&(ZTOI(zp
)->i_mtime
), mtime
);
1332 if (ZTOZSB(zp
)->z_use_fuids
) {
1333 zp
->z_pflags
|= (ZFS_ARCHIVE
|
1338 if (flag
& ATTR_CTIME
) {
1339 ZFS_TIME_ENCODE(&now
, ctime
);
1340 ZFS_TIME_DECODE(&(ZTOI(zp
)->i_ctime
), ctime
);
1341 if (ZTOZSB(zp
)->z_use_fuids
)
1342 zp
->z_pflags
|= ZFS_ARCHIVE
;
1347 * Grow the block size for a file.
1349 * IN: zp - znode of file to free data in.
1350 * size - requested block size
1351 * tx - open transaction.
1353 * NOTE: this function assumes that the znode is write locked.
1356 zfs_grow_blocksize(znode_t
*zp
, uint64_t size
, dmu_tx_t
*tx
)
1361 if (size
<= zp
->z_blksz
)
1364 * If the file size is already greater than the current blocksize,
1365 * we will not grow. If there is more than one block in a file,
1366 * the blocksize cannot change.
1368 if (zp
->z_blksz
&& zp
->z_size
> zp
->z_blksz
)
1371 error
= dmu_object_set_blocksize(ZTOZSB(zp
)->z_os
, zp
->z_id
,
1374 if (error
== ENOTSUP
)
1378 /* What blocksize did we actually get? */
1379 dmu_object_size_from_db(sa_get_db(zp
->z_sa_hdl
), &zp
->z_blksz
, &dummy
);
1383 * Increase the file length
1385 * IN: zp - znode of file to free data in.
1386 * end - new end-of-file
1388 * RETURN: 0 on success, error code on failure
1391 zfs_extend(znode_t
*zp
, uint64_t end
)
1393 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1400 * We will change zp_size, lock the whole file.
1402 rl
= zfs_range_lock(&zp
->z_range_lock
, 0, UINT64_MAX
, RL_WRITER
);
1405 * Nothing to do if file already at desired length.
1407 if (end
<= zp
->z_size
) {
1408 zfs_range_unlock(rl
);
1411 tx
= dmu_tx_create(zsb
->z_os
);
1412 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1413 zfs_sa_upgrade_txholds(tx
, zp
);
1414 if (end
> zp
->z_blksz
&&
1415 (!ISP2(zp
->z_blksz
) || zp
->z_blksz
< zsb
->z_max_blksz
)) {
1417 * We are growing the file past the current block size.
1419 if (zp
->z_blksz
> ZTOZSB(zp
)->z_max_blksz
) {
1421 * File's blocksize is already larger than the
1422 * "recordsize" property. Only let it grow to
1423 * the next power of 2.
1425 ASSERT(!ISP2(zp
->z_blksz
));
1426 newblksz
= MIN(end
, 1 << highbit64(zp
->z_blksz
));
1428 newblksz
= MIN(end
, ZTOZSB(zp
)->z_max_blksz
);
1430 dmu_tx_hold_write(tx
, zp
->z_id
, 0, newblksz
);
1435 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1438 zfs_range_unlock(rl
);
1443 zfs_grow_blocksize(zp
, newblksz
, tx
);
1447 VERIFY(0 == sa_update(zp
->z_sa_hdl
, SA_ZPL_SIZE(ZTOZSB(zp
)),
1448 &zp
->z_size
, sizeof (zp
->z_size
), tx
));
1450 zfs_range_unlock(rl
);
1458 * zfs_zero_partial_page - Modeled after update_pages() but
1459 * with different arguments and semantics for use by zfs_freesp().
1461 * Zeroes a piece of a single page cache entry for zp at offset
1462 * start and length len.
1464 * Caller must acquire a range lock on the file for the region
1465 * being zeroed in order that the ARC and page cache stay in sync.
1468 zfs_zero_partial_page(znode_t
*zp
, uint64_t start
, uint64_t len
)
1470 struct address_space
*mp
= ZTOI(zp
)->i_mapping
;
1475 ASSERT((start
& PAGE_MASK
) == ((start
+ len
- 1) & PAGE_MASK
));
1477 off
= start
& (PAGE_SIZE
- 1);
1480 pp
= find_lock_page(mp
, start
>> PAGE_SHIFT
);
1482 if (mapping_writably_mapped(mp
))
1483 flush_dcache_page(pp
);
1486 bzero(pb
+ off
, len
);
1489 if (mapping_writably_mapped(mp
))
1490 flush_dcache_page(pp
);
1492 mark_page_accessed(pp
);
1493 SetPageUptodate(pp
);
1501 * Free space in a file.
1503 * IN: zp - znode of file to free data in.
1504 * off - start of section to free.
1505 * len - length of section to free.
1507 * RETURN: 0 on success, error code on failure
1510 zfs_free_range(znode_t
*zp
, uint64_t off
, uint64_t len
)
1512 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1517 * Lock the range being freed.
1519 rl
= zfs_range_lock(&zp
->z_range_lock
, off
, len
, RL_WRITER
);
1522 * Nothing to do if file already at desired length.
1524 if (off
>= zp
->z_size
) {
1525 zfs_range_unlock(rl
);
1529 if (off
+ len
> zp
->z_size
)
1530 len
= zp
->z_size
- off
;
1532 error
= dmu_free_long_range(zsb
->z_os
, zp
->z_id
, off
, len
);
1535 * Zero partial page cache entries. This must be done under a
1536 * range lock in order to keep the ARC and page cache in sync.
1538 if (zp
->z_is_mapped
) {
1539 loff_t first_page
, last_page
, page_len
;
1540 loff_t first_page_offset
, last_page_offset
;
1542 /* first possible full page in hole */
1543 first_page
= (off
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
1544 /* last page of hole */
1545 last_page
= (off
+ len
) >> PAGE_SHIFT
;
1547 /* offset of first_page */
1548 first_page_offset
= first_page
<< PAGE_SHIFT
;
1549 /* offset of last_page */
1550 last_page_offset
= last_page
<< PAGE_SHIFT
;
1552 /* truncate whole pages */
1553 if (last_page_offset
> first_page_offset
) {
1554 truncate_inode_pages_range(ZTOI(zp
)->i_mapping
,
1555 first_page_offset
, last_page_offset
- 1);
1558 /* truncate sub-page ranges */
1559 if (first_page
> last_page
) {
1560 /* entire punched area within a single page */
1561 zfs_zero_partial_page(zp
, off
, len
);
1563 /* beginning of punched area at the end of a page */
1564 page_len
= first_page_offset
- off
;
1566 zfs_zero_partial_page(zp
, off
, page_len
);
1568 /* end of punched area at the beginning of a page */
1569 page_len
= off
+ len
- last_page_offset
;
1571 zfs_zero_partial_page(zp
, last_page_offset
,
1575 zfs_range_unlock(rl
);
1583 * IN: zp - znode of file to free data in.
1584 * end - new end-of-file.
1586 * RETURN: 0 on success, error code on failure
1589 zfs_trunc(znode_t
*zp
, uint64_t end
)
1591 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1595 sa_bulk_attr_t bulk
[2];
1599 * We will change zp_size, lock the whole file.
1601 rl
= zfs_range_lock(&zp
->z_range_lock
, 0, UINT64_MAX
, RL_WRITER
);
1604 * Nothing to do if file already at desired length.
1606 if (end
>= zp
->z_size
) {
1607 zfs_range_unlock(rl
);
1611 error
= dmu_free_long_range(zsb
->z_os
, zp
->z_id
, end
, -1);
1613 zfs_range_unlock(rl
);
1616 tx
= dmu_tx_create(zsb
->z_os
);
1617 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1618 zfs_sa_upgrade_txholds(tx
, zp
);
1619 dmu_tx_mark_netfree(tx
);
1620 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1623 zfs_range_unlock(rl
);
1628 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zsb
),
1629 NULL
, &zp
->z_size
, sizeof (zp
->z_size
));
1632 zp
->z_pflags
&= ~ZFS_SPARSE
;
1633 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
),
1634 NULL
, &zp
->z_pflags
, 8);
1636 VERIFY(sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
) == 0);
1640 zfs_range_unlock(rl
);
1646 * Free space in a file
1648 * IN: zp - znode of file to free data in.
1649 * off - start of range
1650 * len - end of range (0 => EOF)
1651 * flag - current file open mode flags.
1652 * log - TRUE if this action should be logged
1654 * RETURN: 0 on success, error code on failure
1657 zfs_freesp(znode_t
*zp
, uint64_t off
, uint64_t len
, int flag
, boolean_t log
)
1660 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1661 zilog_t
*zilog
= zsb
->z_log
;
1663 uint64_t mtime
[2], ctime
[2];
1664 sa_bulk_attr_t bulk
[3];
1668 if ((error
= sa_lookup(zp
->z_sa_hdl
, SA_ZPL_MODE(zsb
), &mode
,
1669 sizeof (mode
))) != 0)
1672 if (off
> zp
->z_size
) {
1673 error
= zfs_extend(zp
, off
+len
);
1674 if (error
== 0 && log
)
1680 error
= zfs_trunc(zp
, off
);
1682 if ((error
= zfs_free_range(zp
, off
, len
)) == 0 &&
1683 off
+ len
> zp
->z_size
)
1684 error
= zfs_extend(zp
, off
+len
);
1689 tx
= dmu_tx_create(zsb
->z_os
);
1690 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1691 zfs_sa_upgrade_txholds(tx
, zp
);
1692 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1698 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zsb
), NULL
, mtime
, 16);
1699 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zsb
), NULL
, ctime
, 16);
1700 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
),
1701 NULL
, &zp
->z_pflags
, 8);
1702 zfs_tstamp_update_setup(zp
, CONTENT_MODIFIED
, mtime
, ctime
);
1703 error
= sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
);
1706 zfs_log_truncate(zilog
, tx
, TX_TRUNCATE
, zp
, off
, len
);
1710 zfs_inode_update(zp
);
1715 * Truncate the page cache - for file truncate operations, use
1716 * the purpose-built API for truncations. For punching operations,
1717 * the truncation is handled under a range lock in zfs_free_range.
1720 truncate_setsize(ZTOI(zp
), off
);
1725 zfs_create_fs(objset_t
*os
, cred_t
*cr
, nvlist_t
*zplprops
, dmu_tx_t
*tx
)
1727 struct super_block
*sb
;
1729 uint64_t moid
, obj
, sa_obj
, version
;
1730 uint64_t sense
= ZFS_CASE_SENSITIVE
;
1736 znode_t
*rootzp
= NULL
;
1739 zfs_acl_ids_t acl_ids
;
1742 * First attempt to create master node.
1745 * In an empty objset, there are no blocks to read and thus
1746 * there can be no i/o errors (which we assert below).
1748 moid
= MASTER_NODE_OBJ
;
1749 error
= zap_create_claim(os
, moid
, DMU_OT_MASTER_NODE
,
1750 DMU_OT_NONE
, 0, tx
);
1754 * Give dmu_object_alloc() a hint about where to start
1755 * allocating new objects. Otherwise, since the metadnode's
1756 * dnode_phys_t structure isn't initialized yet, dmu_object_next()
1757 * would fail and we'd have to skip to the next dnode block.
1759 os
->os_obj_next
= moid
+ 1;
1762 * Set starting attributes.
1764 version
= zfs_zpl_version_map(spa_version(dmu_objset_spa(os
)));
1766 while ((elem
= nvlist_next_nvpair(zplprops
, elem
)) != NULL
) {
1767 /* For the moment we expect all zpl props to be uint64_ts */
1771 ASSERT(nvpair_type(elem
) == DATA_TYPE_UINT64
);
1772 VERIFY(nvpair_value_uint64(elem
, &val
) == 0);
1773 name
= nvpair_name(elem
);
1774 if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_VERSION
)) == 0) {
1778 error
= zap_update(os
, moid
, name
, 8, 1, &val
, tx
);
1781 if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_NORMALIZE
)) == 0)
1783 else if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_CASE
)) == 0)
1786 ASSERT(version
!= 0);
1787 error
= zap_update(os
, moid
, ZPL_VERSION_STR
, 8, 1, &version
, tx
);
1790 * Create zap object used for SA attribute registration
1793 if (version
>= ZPL_VERSION_SA
) {
1794 sa_obj
= zap_create(os
, DMU_OT_SA_MASTER_NODE
,
1795 DMU_OT_NONE
, 0, tx
);
1796 error
= zap_add(os
, moid
, ZFS_SA_ATTRS
, 8, 1, &sa_obj
, tx
);
1802 * Create a delete queue.
1804 obj
= zap_create(os
, DMU_OT_UNLINKED_SET
, DMU_OT_NONE
, 0, tx
);
1806 error
= zap_add(os
, moid
, ZFS_UNLINKED_SET
, 8, 1, &obj
, tx
);
1810 * Create root znode. Create minimal znode/inode/zsb/sb
1811 * to allow zfs_mknode to work.
1813 vattr
.va_mask
= ATTR_MODE
|ATTR_UID
|ATTR_GID
;
1814 vattr
.va_mode
= S_IFDIR
|0755;
1815 vattr
.va_uid
= crgetuid(cr
);
1816 vattr
.va_gid
= crgetgid(cr
);
1818 rootzp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
1819 rootzp
->z_moved
= 0;
1820 rootzp
->z_unlinked
= 0;
1821 rootzp
->z_atime_dirty
= 0;
1822 rootzp
->z_is_sa
= USE_SA(version
, os
);
1824 zsb
= kmem_zalloc(sizeof (zfs_sb_t
), KM_SLEEP
);
1826 zsb
->z_parent
= zsb
;
1827 zsb
->z_version
= version
;
1828 zsb
->z_use_fuids
= USE_FUIDS(version
, os
);
1829 zsb
->z_use_sa
= USE_SA(version
, os
);
1832 sb
= kmem_zalloc(sizeof (struct super_block
), KM_SLEEP
);
1833 sb
->s_fs_info
= zsb
;
1835 ZTOI(rootzp
)->i_sb
= sb
;
1837 error
= sa_setup(os
, sa_obj
, zfs_attr_table
, ZPL_END
,
1838 &zsb
->z_attr_table
);
1843 * Fold case on file systems that are always or sometimes case
1846 if (sense
== ZFS_CASE_INSENSITIVE
|| sense
== ZFS_CASE_MIXED
)
1847 zsb
->z_norm
|= U8_TEXTPREP_TOUPPER
;
1849 mutex_init(&zsb
->z_znodes_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
1850 list_create(&zsb
->z_all_znodes
, sizeof (znode_t
),
1851 offsetof(znode_t
, z_link_node
));
1853 size
= MIN(1 << (highbit64(zfs_object_mutex_size
)-1), ZFS_OBJ_MTX_MAX
);
1854 zsb
->z_hold_size
= size
;
1855 zsb
->z_hold_trees
= vmem_zalloc(sizeof (avl_tree_t
) * size
, KM_SLEEP
);
1856 zsb
->z_hold_locks
= vmem_zalloc(sizeof (kmutex_t
) * size
, KM_SLEEP
);
1857 for (i
= 0; i
!= size
; i
++) {
1858 avl_create(&zsb
->z_hold_trees
[i
], zfs_znode_hold_compare
,
1859 sizeof (znode_hold_t
), offsetof(znode_hold_t
, zh_node
));
1860 mutex_init(&zsb
->z_hold_locks
[i
], NULL
, MUTEX_DEFAULT
, NULL
);
1863 VERIFY(0 == zfs_acl_ids_create(rootzp
, IS_ROOT_NODE
, &vattr
,
1864 cr
, NULL
, &acl_ids
));
1865 zfs_mknode(rootzp
, &vattr
, tx
, cr
, IS_ROOT_NODE
, &zp
, &acl_ids
);
1866 ASSERT3P(zp
, ==, rootzp
);
1867 error
= zap_add(os
, moid
, ZFS_ROOT_OBJ
, 8, 1, &rootzp
->z_id
, tx
);
1869 zfs_acl_ids_free(&acl_ids
);
1871 atomic_set(&ZTOI(rootzp
)->i_count
, 0);
1872 sa_handle_destroy(rootzp
->z_sa_hdl
);
1873 kmem_cache_free(znode_cache
, rootzp
);
1876 * Create shares directory
1878 error
= zfs_create_share_dir(zsb
, tx
);
1881 for (i
= 0; i
!= size
; i
++) {
1882 avl_destroy(&zsb
->z_hold_trees
[i
]);
1883 mutex_destroy(&zsb
->z_hold_locks
[i
]);
1886 vmem_free(zsb
->z_hold_trees
, sizeof (avl_tree_t
) * size
);
1887 vmem_free(zsb
->z_hold_locks
, sizeof (kmutex_t
) * size
);
1888 kmem_free(sb
, sizeof (struct super_block
));
1889 kmem_free(zsb
, sizeof (zfs_sb_t
));
1891 #endif /* _KERNEL */
1894 zfs_sa_setup(objset_t
*osp
, sa_attr_type_t
**sa_table
)
1896 uint64_t sa_obj
= 0;
1899 error
= zap_lookup(osp
, MASTER_NODE_OBJ
, ZFS_SA_ATTRS
, 8, 1, &sa_obj
);
1900 if (error
!= 0 && error
!= ENOENT
)
1903 error
= sa_setup(osp
, sa_obj
, zfs_attr_table
, ZPL_END
, sa_table
);
1908 zfs_grab_sa_handle(objset_t
*osp
, uint64_t obj
, sa_handle_t
**hdlp
,
1909 dmu_buf_t
**db
, void *tag
)
1911 dmu_object_info_t doi
;
1914 if ((error
= sa_buf_hold(osp
, obj
, tag
, db
)) != 0)
1917 dmu_object_info_from_db(*db
, &doi
);
1918 if ((doi
.doi_bonus_type
!= DMU_OT_SA
&&
1919 doi
.doi_bonus_type
!= DMU_OT_ZNODE
) ||
1920 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1921 doi
.doi_bonus_size
< sizeof (znode_phys_t
))) {
1922 sa_buf_rele(*db
, tag
);
1923 return (SET_ERROR(ENOTSUP
));
1926 error
= sa_handle_get(osp
, obj
, NULL
, SA_HDL_PRIVATE
, hdlp
);
1928 sa_buf_rele(*db
, tag
);
1936 zfs_release_sa_handle(sa_handle_t
*hdl
, dmu_buf_t
*db
, void *tag
)
1938 sa_handle_destroy(hdl
);
1939 sa_buf_rele(db
, tag
);
1943 * Given an object number, return its parent object number and whether
1944 * or not the object is an extended attribute directory.
1947 zfs_obj_to_pobj(objset_t
*osp
, sa_handle_t
*hdl
, sa_attr_type_t
*sa_table
,
1948 uint64_t *pobjp
, int *is_xattrdir
)
1953 uint64_t parent_mode
;
1954 sa_bulk_attr_t bulk
[3];
1955 sa_handle_t
*sa_hdl
;
1960 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_PARENT
], NULL
,
1961 &parent
, sizeof (parent
));
1962 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_FLAGS
], NULL
,
1963 &pflags
, sizeof (pflags
));
1964 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_MODE
], NULL
,
1965 &mode
, sizeof (mode
));
1967 if ((error
= sa_bulk_lookup(hdl
, bulk
, count
)) != 0)
1971 * When a link is removed its parent pointer is not changed and will
1972 * be invalid. There are two cases where a link is removed but the
1973 * file stays around, when it goes to the delete queue and when there
1974 * are additional links.
1976 error
= zfs_grab_sa_handle(osp
, parent
, &sa_hdl
, &sa_db
, FTAG
);
1980 error
= sa_lookup(sa_hdl
, ZPL_MODE
, &parent_mode
, sizeof (parent_mode
));
1981 zfs_release_sa_handle(sa_hdl
, sa_db
, FTAG
);
1985 *is_xattrdir
= ((pflags
& ZFS_XATTR
) != 0) && S_ISDIR(mode
);
1988 * Extended attributes can be applied to files, directories, etc.
1989 * Otherwise the parent must be a directory.
1991 if (!*is_xattrdir
&& !S_ISDIR(parent_mode
))
2000 * Given an object number, return some zpl level statistics
2003 zfs_obj_to_stats_impl(sa_handle_t
*hdl
, sa_attr_type_t
*sa_table
,
2006 sa_bulk_attr_t bulk
[4];
2009 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_MODE
], NULL
,
2010 &sb
->zs_mode
, sizeof (sb
->zs_mode
));
2011 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_GEN
], NULL
,
2012 &sb
->zs_gen
, sizeof (sb
->zs_gen
));
2013 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_LINKS
], NULL
,
2014 &sb
->zs_links
, sizeof (sb
->zs_links
));
2015 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_CTIME
], NULL
,
2016 &sb
->zs_ctime
, sizeof (sb
->zs_ctime
));
2018 return (sa_bulk_lookup(hdl
, bulk
, count
));
2022 zfs_obj_to_path_impl(objset_t
*osp
, uint64_t obj
, sa_handle_t
*hdl
,
2023 sa_attr_type_t
*sa_table
, char *buf
, int len
)
2025 sa_handle_t
*sa_hdl
;
2026 sa_handle_t
*prevhdl
= NULL
;
2027 dmu_buf_t
*prevdb
= NULL
;
2028 dmu_buf_t
*sa_db
= NULL
;
2029 char *path
= buf
+ len
- 1;
2037 char component
[MAXNAMELEN
+ 2];
2039 int is_xattrdir
= 0;
2042 zfs_release_sa_handle(prevhdl
, prevdb
, FTAG
);
2044 if ((error
= zfs_obj_to_pobj(osp
, sa_hdl
, sa_table
, &pobj
,
2045 &is_xattrdir
)) != 0)
2056 (void) sprintf(component
+ 1, "<xattrdir>");
2058 error
= zap_value_search(osp
, pobj
, obj
,
2059 ZFS_DIRENT_OBJ(-1ULL), component
+ 1);
2064 complen
= strlen(component
);
2066 ASSERT(path
>= buf
);
2067 bcopy(component
, path
, complen
);
2070 if (sa_hdl
!= hdl
) {
2074 error
= zfs_grab_sa_handle(osp
, obj
, &sa_hdl
, &sa_db
, FTAG
);
2082 if (sa_hdl
!= NULL
&& sa_hdl
!= hdl
) {
2083 ASSERT(sa_db
!= NULL
);
2084 zfs_release_sa_handle(sa_hdl
, sa_db
, FTAG
);
2088 (void) memmove(buf
, path
, buf
+ len
- path
);
2094 zfs_obj_to_path(objset_t
*osp
, uint64_t obj
, char *buf
, int len
)
2096 sa_attr_type_t
*sa_table
;
2101 error
= zfs_sa_setup(osp
, &sa_table
);
2105 error
= zfs_grab_sa_handle(osp
, obj
, &hdl
, &db
, FTAG
);
2109 error
= zfs_obj_to_path_impl(osp
, obj
, hdl
, sa_table
, buf
, len
);
2111 zfs_release_sa_handle(hdl
, db
, FTAG
);
2116 zfs_obj_to_stats(objset_t
*osp
, uint64_t obj
, zfs_stat_t
*sb
,
2119 char *path
= buf
+ len
- 1;
2120 sa_attr_type_t
*sa_table
;
2127 error
= zfs_sa_setup(osp
, &sa_table
);
2131 error
= zfs_grab_sa_handle(osp
, obj
, &hdl
, &db
, FTAG
);
2135 error
= zfs_obj_to_stats_impl(hdl
, sa_table
, sb
);
2137 zfs_release_sa_handle(hdl
, db
, FTAG
);
2141 error
= zfs_obj_to_path_impl(osp
, obj
, hdl
, sa_table
, buf
, len
);
2143 zfs_release_sa_handle(hdl
, db
, FTAG
);
2147 #if defined(_KERNEL) && defined(HAVE_SPL)
2148 EXPORT_SYMBOL(zfs_create_fs
);
2149 EXPORT_SYMBOL(zfs_obj_to_path
);
2151 module_param(zfs_object_mutex_size
, uint
, 0644);
2152 MODULE_PARM_DESC(zfs_object_mutex_size
, "Size of znode hold array");