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) 2013 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/refcount.h>
68 #include <sys/zfs_znode.h>
70 #include <sys/zfs_sa.h>
71 #include <sys/zfs_stat.h>
74 #include "zfs_comutil.h"
77 * Define ZNODE_STATS to turn on statistic gathering. By default, it is only
78 * turned on when DEBUG is also defined.
85 #define ZNODE_STAT_ADD(stat) ((stat)++)
87 #define ZNODE_STAT_ADD(stat) /* nothing */
88 #endif /* ZNODE_STATS */
91 * Functions needed for userland (ie: libzpool) are not put under
92 * #ifdef_KERNEL; the rest of the functions have dependencies
93 * (such as VFS logic) that will not compile easily in userland.
97 static kmem_cache_t
*znode_cache
= NULL
;
98 static kmem_cache_t
*znode_hold_cache
= NULL
;
99 unsigned int zfs_object_mutex_size
= ZFS_OBJ_MTX_SZ
;
103 zfs_znode_cache_constructor(void *buf
, void *arg
, int kmflags
)
107 inode_init_once(ZTOI(zp
));
108 list_link_init(&zp
->z_link_node
);
110 mutex_init(&zp
->z_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
111 rw_init(&zp
->z_parent_lock
, NULL
, RW_DEFAULT
, NULL
);
112 rw_init(&zp
->z_name_lock
, NULL
, RW_DEFAULT
, NULL
);
113 mutex_init(&zp
->z_acl_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
114 rw_init(&zp
->z_xattr_lock
, NULL
, RW_DEFAULT
, NULL
);
116 zfs_rlock_init(&zp
->z_range_lock
);
118 zp
->z_dirlocks
= NULL
;
119 zp
->z_acl_cached
= NULL
;
120 zp
->z_xattr_cached
= NULL
;
127 zfs_znode_cache_destructor(void *buf
, void *arg
)
131 ASSERT(!list_link_active(&zp
->z_link_node
));
132 mutex_destroy(&zp
->z_lock
);
133 rw_destroy(&zp
->z_parent_lock
);
134 rw_destroy(&zp
->z_name_lock
);
135 mutex_destroy(&zp
->z_acl_lock
);
136 rw_destroy(&zp
->z_xattr_lock
);
137 zfs_rlock_destroy(&zp
->z_range_lock
);
139 ASSERT(zp
->z_dirlocks
== NULL
);
140 ASSERT(zp
->z_acl_cached
== NULL
);
141 ASSERT(zp
->z_xattr_cached
== NULL
);
145 zfs_znode_hold_cache_constructor(void *buf
, void *arg
, int kmflags
)
147 znode_hold_t
*zh
= buf
;
149 mutex_init(&zh
->zh_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
150 refcount_create(&zh
->zh_refcount
);
151 zh
->zh_obj
= ZFS_NO_OBJECT
;
157 zfs_znode_hold_cache_destructor(void *buf
, void *arg
)
159 znode_hold_t
*zh
= buf
;
161 mutex_destroy(&zh
->zh_lock
);
162 refcount_destroy(&zh
->zh_refcount
);
169 * Initialize zcache. The KMC_SLAB hint is used in order that it be
170 * backed by kmalloc() when on the Linux slab in order that any
171 * wait_on_bit() operations on the related inode operate properly.
173 ASSERT(znode_cache
== NULL
);
174 znode_cache
= kmem_cache_create("zfs_znode_cache",
175 sizeof (znode_t
), 0, zfs_znode_cache_constructor
,
176 zfs_znode_cache_destructor
, NULL
, NULL
, NULL
, KMC_SLAB
);
178 ASSERT(znode_hold_cache
== NULL
);
179 znode_hold_cache
= kmem_cache_create("zfs_znode_hold_cache",
180 sizeof (znode_hold_t
), 0, zfs_znode_hold_cache_constructor
,
181 zfs_znode_hold_cache_destructor
, NULL
, NULL
, NULL
, 0);
191 kmem_cache_destroy(znode_cache
);
194 if (znode_hold_cache
)
195 kmem_cache_destroy(znode_hold_cache
);
196 znode_hold_cache
= NULL
;
200 * The zfs_znode_hold_enter() / zfs_znode_hold_exit() functions are used to
201 * serialize access to a znode and its SA buffer while the object is being
202 * created or destroyed. This kind of locking would normally reside in the
203 * znode itself but in this case that's impossible because the znode and SA
204 * buffer may not yet exist. Therefore the locking is handled externally
205 * with an array of mutexs and AVLs trees which contain per-object locks.
207 * In zfs_znode_hold_enter() a per-object lock is created as needed, inserted
208 * in to the correct AVL tree and finally the per-object lock is held. In
209 * zfs_znode_hold_exit() the process is reversed. The per-object lock is
210 * released, removed from the AVL tree and destroyed if there are no waiters.
212 * This scheme has two important properties:
214 * 1) No memory allocations are performed while holding one of the z_hold_locks.
215 * This ensures evict(), which can be called from direct memory reclaim, will
216 * never block waiting on a z_hold_locks which just happens to have hashed
219 * 2) All locks used to serialize access to an object are per-object and never
220 * shared. This minimizes lock contention without creating a large number
221 * of dedicated locks.
223 * On the downside it does require znode_lock_t structures to be frequently
224 * allocated and freed. However, because these are backed by a kmem cache
225 * and very short lived this cost is minimal.
228 zfs_znode_hold_compare(const void *a
, const void *b
)
230 const znode_hold_t
*zh_a
= a
;
231 const znode_hold_t
*zh_b
= b
;
233 if (zh_a
->zh_obj
< zh_b
->zh_obj
)
235 else if (zh_a
->zh_obj
> zh_b
->zh_obj
)
242 zfs_znode_held(zfs_sb_t
*zsb
, uint64_t obj
)
244 znode_hold_t
*zh
, search
;
245 int i
= ZFS_OBJ_HASH(zsb
, obj
);
250 mutex_enter(&zsb
->z_hold_locks
[i
]);
251 zh
= avl_find(&zsb
->z_hold_trees
[i
], &search
, NULL
);
252 held
= (zh
&& MUTEX_HELD(&zh
->zh_lock
)) ? B_TRUE
: B_FALSE
;
253 mutex_exit(&zsb
->z_hold_locks
[i
]);
258 static znode_hold_t
*
259 zfs_znode_hold_enter(zfs_sb_t
*zsb
, uint64_t obj
)
261 znode_hold_t
*zh
, *zh_new
, search
;
262 int i
= ZFS_OBJ_HASH(zsb
, obj
);
263 boolean_t found
= B_FALSE
;
265 zh_new
= kmem_cache_alloc(znode_hold_cache
, KM_SLEEP
);
266 zh_new
->zh_obj
= obj
;
269 mutex_enter(&zsb
->z_hold_locks
[i
]);
270 zh
= avl_find(&zsb
->z_hold_trees
[i
], &search
, NULL
);
271 if (likely(zh
== NULL
)) {
273 avl_add(&zsb
->z_hold_trees
[i
], zh
);
275 ASSERT3U(zh
->zh_obj
, ==, obj
);
278 refcount_add(&zh
->zh_refcount
, NULL
);
279 mutex_exit(&zsb
->z_hold_locks
[i
]);
282 kmem_cache_free(znode_hold_cache
, zh_new
);
284 ASSERT(MUTEX_NOT_HELD(&zh
->zh_lock
));
285 ASSERT3S(refcount_count(&zh
->zh_refcount
), >, 0);
286 mutex_enter(&zh
->zh_lock
);
292 zfs_znode_hold_exit(zfs_sb_t
*zsb
, znode_hold_t
*zh
)
294 int i
= ZFS_OBJ_HASH(zsb
, zh
->zh_obj
);
295 boolean_t remove
= B_FALSE
;
297 ASSERT(zfs_znode_held(zsb
, zh
->zh_obj
));
298 ASSERT3S(refcount_count(&zh
->zh_refcount
), >, 0);
299 mutex_exit(&zh
->zh_lock
);
301 mutex_enter(&zsb
->z_hold_locks
[i
]);
302 if (refcount_remove(&zh
->zh_refcount
, NULL
) == 0) {
303 avl_remove(&zsb
->z_hold_trees
[i
], zh
);
306 mutex_exit(&zsb
->z_hold_locks
[i
]);
308 if (remove
== B_TRUE
)
309 kmem_cache_free(znode_hold_cache
, zh
);
313 zfs_create_share_dir(zfs_sb_t
*zsb
, dmu_tx_t
*tx
)
315 #ifdef HAVE_SMB_SHARE
316 zfs_acl_ids_t acl_ids
;
323 vattr
.va_mask
= AT_MODE
|AT_UID
|AT_GID
|AT_TYPE
;
324 vattr
.va_mode
= S_IFDIR
| 0555;
325 vattr
.va_uid
= crgetuid(kcred
);
326 vattr
.va_gid
= crgetgid(kcred
);
328 sharezp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
329 sharezp
->z_moved
= 0;
330 sharezp
->z_unlinked
= 0;
331 sharezp
->z_atime_dirty
= 0;
332 sharezp
->z_zfsvfs
= zfsvfs
;
333 sharezp
->z_is_sa
= zfsvfs
->z_use_sa
;
339 VERIFY(0 == zfs_acl_ids_create(sharezp
, IS_ROOT_NODE
, &vattr
,
340 kcred
, NULL
, &acl_ids
));
341 zfs_mknode(sharezp
, &vattr
, tx
, kcred
, IS_ROOT_NODE
, &zp
, &acl_ids
);
342 ASSERT3P(zp
, ==, sharezp
);
343 ASSERT(!vn_in_dnlc(ZTOV(sharezp
))); /* not valid to move */
344 POINTER_INVALIDATE(&sharezp
->z_zfsvfs
);
345 error
= zap_add(zfsvfs
->z_os
, MASTER_NODE_OBJ
,
346 ZFS_SHARES_DIR
, 8, 1, &sharezp
->z_id
, tx
);
347 zfsvfs
->z_shares_dir
= sharezp
->z_id
;
349 zfs_acl_ids_free(&acl_ids
);
350 // ZTOV(sharezp)->v_count = 0;
351 sa_handle_destroy(sharezp
->z_sa_hdl
);
352 kmem_cache_free(znode_cache
, sharezp
);
357 #endif /* HAVE_SMB_SHARE */
361 zfs_znode_sa_init(zfs_sb_t
*zsb
, znode_t
*zp
,
362 dmu_buf_t
*db
, dmu_object_type_t obj_type
, sa_handle_t
*sa_hdl
)
364 ASSERT(zfs_znode_held(zsb
, zp
->z_id
));
366 mutex_enter(&zp
->z_lock
);
368 ASSERT(zp
->z_sa_hdl
== NULL
);
369 ASSERT(zp
->z_acl_cached
== NULL
);
370 if (sa_hdl
== NULL
) {
371 VERIFY(0 == sa_handle_get_from_db(zsb
->z_os
, db
, zp
,
372 SA_HDL_SHARED
, &zp
->z_sa_hdl
));
374 zp
->z_sa_hdl
= sa_hdl
;
375 sa_set_userp(sa_hdl
, zp
);
378 zp
->z_is_sa
= (obj_type
== DMU_OT_SA
) ? B_TRUE
: B_FALSE
;
380 mutex_exit(&zp
->z_lock
);
384 zfs_znode_dmu_fini(znode_t
*zp
)
386 ASSERT(zfs_znode_held(ZTOZSB(zp
), zp
->z_id
) || zp
->z_unlinked
||
387 RW_WRITE_HELD(&ZTOZSB(zp
)->z_teardown_inactive_lock
));
389 sa_handle_destroy(zp
->z_sa_hdl
);
394 * Called by new_inode() to allocate a new inode.
397 zfs_inode_alloc(struct super_block
*sb
, struct inode
**ip
)
401 zp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
408 * Called in multiple places when an inode should be destroyed.
411 zfs_inode_destroy(struct inode
*ip
)
413 znode_t
*zp
= ITOZ(ip
);
414 zfs_sb_t
*zsb
= ZTOZSB(zp
);
416 mutex_enter(&zsb
->z_znodes_lock
);
417 if (list_link_active(&zp
->z_link_node
)) {
418 list_remove(&zsb
->z_all_znodes
, zp
);
421 mutex_exit(&zsb
->z_znodes_lock
);
423 if (zp
->z_acl_cached
) {
424 zfs_acl_free(zp
->z_acl_cached
);
425 zp
->z_acl_cached
= NULL
;
428 if (zp
->z_xattr_cached
) {
429 nvlist_free(zp
->z_xattr_cached
);
430 zp
->z_xattr_cached
= NULL
;
433 kmem_cache_free(znode_cache
, zp
);
437 zfs_inode_set_ops(zfs_sb_t
*zsb
, struct inode
*ip
)
441 switch (ip
->i_mode
& S_IFMT
) {
443 ip
->i_op
= &zpl_inode_operations
;
444 ip
->i_fop
= &zpl_file_operations
;
445 ip
->i_mapping
->a_ops
= &zpl_address_space_operations
;
449 ip
->i_op
= &zpl_dir_inode_operations
;
450 ip
->i_fop
= &zpl_dir_file_operations
;
451 ITOZ(ip
)->z_zn_prefetch
= B_TRUE
;
455 ip
->i_op
= &zpl_symlink_inode_operations
;
459 * rdev is only stored in a SA only for device files.
463 sa_lookup(ITOZ(ip
)->z_sa_hdl
, SA_ZPL_RDEV(zsb
), &rdev
,
468 init_special_inode(ip
, ip
->i_mode
, rdev
);
469 ip
->i_op
= &zpl_special_inode_operations
;
473 zfs_panic_recover("inode %llu has invalid mode: 0x%x\n",
474 (u_longlong_t
)ip
->i_ino
, ip
->i_mode
);
476 /* Assume the inode is a file and attempt to continue */
477 ip
->i_mode
= S_IFREG
| 0644;
478 ip
->i_op
= &zpl_inode_operations
;
479 ip
->i_fop
= &zpl_file_operations
;
480 ip
->i_mapping
->a_ops
= &zpl_address_space_operations
;
486 * Construct a znode+inode and initialize.
488 * This does not do a call to dmu_set_user() that is
489 * up to the caller to do, in case you don't want to
493 zfs_znode_alloc(zfs_sb_t
*zsb
, dmu_buf_t
*db
, int blksz
,
494 dmu_object_type_t obj_type
, uint64_t obj
, sa_handle_t
*hdl
)
500 sa_bulk_attr_t bulk
[9];
505 ip
= new_inode(zsb
->z_sb
);
510 ASSERT(zp
->z_dirlocks
== NULL
);
511 ASSERT3P(zp
->z_acl_cached
, ==, NULL
);
512 ASSERT3P(zp
->z_xattr_cached
, ==, NULL
);
516 zp
->z_atime_dirty
= 0;
518 zp
->z_id
= db
->db_object
;
520 zp
->z_seq
= 0x7A4653;
522 zp
->z_is_mapped
= B_FALSE
;
523 zp
->z_is_ctldir
= B_FALSE
;
524 zp
->z_is_stale
= B_FALSE
;
525 zp
->z_range_lock
.zr_size
= &zp
->z_size
;
526 zp
->z_range_lock
.zr_blksz
= &zp
->z_blksz
;
527 zp
->z_range_lock
.zr_max_blksz
= &ZTOZSB(zp
)->z_max_blksz
;
529 zfs_znode_sa_init(zsb
, zp
, db
, obj_type
, hdl
);
531 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zsb
), NULL
, &mode
, 8);
532 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GEN(zsb
), NULL
, &zp
->z_gen
, 8);
533 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zsb
), NULL
, &zp
->z_size
, 8);
534 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_LINKS(zsb
), NULL
, &zp
->z_links
, 8);
535 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
), NULL
,
537 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_PARENT(zsb
), NULL
,
539 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_ATIME(zsb
), NULL
,
541 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_UID(zsb
), NULL
, &zp
->z_uid
, 8);
542 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GID(zsb
), NULL
, &zp
->z_gid
, 8);
544 if (sa_bulk_lookup(zp
->z_sa_hdl
, bulk
, count
) != 0 || zp
->z_gen
== 0) {
546 sa_handle_destroy(zp
->z_sa_hdl
);
554 zfs_inode_update(zp
);
555 zfs_inode_set_ops(zsb
, ip
);
558 * The only way insert_inode_locked() can fail is if the ip->i_ino
559 * number is already hashed for this super block. This can never
560 * happen because the inode numbers map 1:1 with the object numbers.
562 * The one exception is rolling back a mounted file system, but in
563 * this case all the active inode are unhashed during the rollback.
565 VERIFY3S(insert_inode_locked(ip
), ==, 0);
567 mutex_enter(&zsb
->z_znodes_lock
);
568 list_insert_tail(&zsb
->z_all_znodes
, zp
);
571 mutex_exit(&zsb
->z_znodes_lock
);
573 unlock_new_inode(ip
);
582 zfs_set_inode_flags(znode_t
*zp
, struct inode
*ip
)
585 * Linux and Solaris have different sets of file attributes, so we
586 * restrict this conversion to the intersection of the two.
589 if (zp
->z_pflags
& ZFS_IMMUTABLE
)
590 ip
->i_flags
|= S_IMMUTABLE
;
592 ip
->i_flags
&= ~S_IMMUTABLE
;
594 if (zp
->z_pflags
& ZFS_APPENDONLY
)
595 ip
->i_flags
|= S_APPEND
;
597 ip
->i_flags
&= ~S_APPEND
;
601 * Update the embedded inode given the znode. We should work toward
602 * eliminating this function as soon as possible by removing values
603 * which are duplicated between the znode and inode. If the generic
604 * inode has the correct field it should be used, and the ZFS code
605 * updated to access the inode. This can be done incrementally.
608 zfs_inode_update(znode_t
*zp
)
613 uint64_t atime
[2], mtime
[2], ctime
[2];
619 /* Skip .zfs control nodes which do not exist on disk. */
620 if (zfsctl_is_node(ip
))
623 sa_lookup(zp
->z_sa_hdl
, SA_ZPL_ATIME(zsb
), &atime
, 16);
624 sa_lookup(zp
->z_sa_hdl
, SA_ZPL_MTIME(zsb
), &mtime
, 16);
625 sa_lookup(zp
->z_sa_hdl
, SA_ZPL_CTIME(zsb
), &ctime
, 16);
627 spin_lock(&ip
->i_lock
);
628 ip
->i_generation
= zp
->z_gen
;
629 ip
->i_uid
= SUID_TO_KUID(zp
->z_uid
);
630 ip
->i_gid
= SGID_TO_KGID(zp
->z_gid
);
631 set_nlink(ip
, zp
->z_links
);
632 ip
->i_mode
= zp
->z_mode
;
633 zfs_set_inode_flags(zp
, ip
);
634 ip
->i_blkbits
= SPA_MINBLOCKSHIFT
;
635 dmu_object_size_from_db(sa_get_db(zp
->z_sa_hdl
), &blksize
,
636 (u_longlong_t
*)&ip
->i_blocks
);
638 ZFS_TIME_DECODE(&ip
->i_atime
, atime
);
639 ZFS_TIME_DECODE(&ip
->i_mtime
, mtime
);
640 ZFS_TIME_DECODE(&ip
->i_ctime
, ctime
);
642 i_size_write(ip
, zp
->z_size
);
643 spin_unlock(&ip
->i_lock
);
647 * Safely mark an inode dirty. Inodes which are part of a read-only
648 * file system or snapshot may not be dirtied.
651 zfs_mark_inode_dirty(struct inode
*ip
)
653 zfs_sb_t
*zsb
= ITOZSB(ip
);
655 if (zfs_is_readonly(zsb
) || dmu_objset_is_snapshot(zsb
->z_os
))
658 mark_inode_dirty(ip
);
661 static uint64_t empty_xattr
;
662 static uint64_t pad
[4];
663 static zfs_acl_phys_t acl_phys
;
665 * Create a new DMU object to hold a zfs znode.
667 * IN: dzp - parent directory for new znode
668 * vap - file attributes for new znode
669 * tx - dmu transaction id for zap operations
670 * cr - credentials of caller
672 * IS_ROOT_NODE - new object will be root
673 * IS_XATTR - new object is an attribute
674 * bonuslen - length of bonus buffer
675 * setaclp - File/Dir initial ACL
676 * fuidp - Tracks fuid allocation.
678 * OUT: zpp - allocated znode
682 zfs_mknode(znode_t
*dzp
, vattr_t
*vap
, dmu_tx_t
*tx
, cred_t
*cr
,
683 uint_t flag
, znode_t
**zpp
, zfs_acl_ids_t
*acl_ids
)
685 uint64_t crtime
[2], atime
[2], mtime
[2], ctime
[2];
686 uint64_t mode
, size
, links
, parent
, pflags
;
687 uint64_t dzp_pflags
= 0;
689 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 */
708 gen
= dmu_tx_get_txg(tx
);
711 obj_type
= zsb
->z_use_sa
? DMU_OT_SA
: DMU_OT_ZNODE
;
712 bonuslen
= (obj_type
== DMU_OT_SA
) ?
713 DN_MAX_BONUSLEN
: ZFS_OLD_ZNODE_PHYS_SIZE
;
716 * Create a new DMU object.
719 * There's currently no mechanism for pre-reading the blocks that will
720 * be needed to allocate a new object, so we accept the small chance
721 * that there will be an i/o error and we will fail one of the
724 if (S_ISDIR(vap
->va_mode
)) {
726 VERIFY0(zap_create_claim_norm(zsb
->z_os
, obj
,
727 zsb
->z_norm
, DMU_OT_DIRECTORY_CONTENTS
,
728 obj_type
, bonuslen
, tx
));
730 obj
= zap_create_norm(zsb
->z_os
,
731 zsb
->z_norm
, DMU_OT_DIRECTORY_CONTENTS
,
732 obj_type
, bonuslen
, tx
);
736 VERIFY0(dmu_object_claim(zsb
->z_os
, obj
,
737 DMU_OT_PLAIN_FILE_CONTENTS
, 0,
738 obj_type
, bonuslen
, tx
));
740 obj
= dmu_object_alloc(zsb
->z_os
,
741 DMU_OT_PLAIN_FILE_CONTENTS
, 0,
742 obj_type
, bonuslen
, tx
);
746 zh
= zfs_znode_hold_enter(zsb
, obj
);
747 VERIFY(0 == sa_buf_hold(zsb
->z_os
, obj
, NULL
, &db
));
750 * If this is the root, fix up the half-initialized parent pointer
751 * to reference the just-allocated physical data area.
753 if (flag
& IS_ROOT_NODE
) {
756 dzp_pflags
= dzp
->z_pflags
;
760 * If parent is an xattr, so am I.
762 if (dzp_pflags
& ZFS_XATTR
) {
766 if (zsb
->z_use_fuids
)
767 pflags
= ZFS_ARCHIVE
| ZFS_AV_MODIFIED
;
771 if (S_ISDIR(vap
->va_mode
)) {
772 size
= 2; /* contents ("." and "..") */
773 links
= (flag
& (IS_ROOT_NODE
| IS_XATTR
)) ? 2 : 1;
778 if (S_ISBLK(vap
->va_mode
) || S_ISCHR(vap
->va_mode
))
782 mode
= acl_ids
->z_mode
;
787 * No execs denied will be deterimed when zfs_mode_compute() is called.
789 pflags
|= acl_ids
->z_aclp
->z_hints
&
790 (ZFS_ACL_TRIVIAL
|ZFS_INHERIT_ACE
|ZFS_ACL_AUTO_INHERIT
|
791 ZFS_ACL_DEFAULTED
|ZFS_ACL_PROTECTED
);
793 ZFS_TIME_ENCODE(&now
, crtime
);
794 ZFS_TIME_ENCODE(&now
, ctime
);
796 if (vap
->va_mask
& ATTR_ATIME
) {
797 ZFS_TIME_ENCODE(&vap
->va_atime
, atime
);
799 ZFS_TIME_ENCODE(&now
, atime
);
802 if (vap
->va_mask
& ATTR_MTIME
) {
803 ZFS_TIME_ENCODE(&vap
->va_mtime
, mtime
);
805 ZFS_TIME_ENCODE(&now
, mtime
);
808 /* Now add in all of the "SA" attributes */
809 VERIFY(0 == sa_handle_get_from_db(zsb
->z_os
, db
, NULL
, SA_HDL_SHARED
,
813 * Setup the array of attributes to be replaced/set on the new file
815 * order for DMU_OT_ZNODE is critical since it needs to be constructed
816 * in the old znode_phys_t format. Don't change this ordering
818 sa_attrs
= kmem_alloc(sizeof (sa_bulk_attr_t
) * ZPL_END
, KM_SLEEP
);
820 if (obj_type
== DMU_OT_ZNODE
) {
821 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ATIME(zsb
),
823 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MTIME(zsb
),
825 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CTIME(zsb
),
827 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CRTIME(zsb
),
829 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GEN(zsb
),
831 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MODE(zsb
),
833 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_SIZE(zsb
),
835 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PARENT(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_GEN(zsb
),
844 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_UID(zsb
),
845 NULL
, &acl_ids
->z_fuid
, 8);
846 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GID(zsb
),
847 NULL
, &acl_ids
->z_fgid
, 8);
848 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PARENT(zsb
),
850 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_FLAGS(zsb
),
852 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ATIME(zsb
),
854 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MTIME(zsb
),
856 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CTIME(zsb
),
858 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CRTIME(zsb
),
862 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_LINKS(zsb
), NULL
, &links
, 8);
864 if (obj_type
== DMU_OT_ZNODE
) {
865 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_XATTR(zsb
), NULL
,
868 if (obj_type
== DMU_OT_ZNODE
||
869 (S_ISBLK(vap
->va_mode
) || S_ISCHR(vap
->va_mode
))) {
870 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_RDEV(zsb
),
873 if (obj_type
== DMU_OT_ZNODE
) {
874 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_FLAGS(zsb
),
876 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_UID(zsb
), NULL
,
877 &acl_ids
->z_fuid
, 8);
878 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GID(zsb
), NULL
,
879 &acl_ids
->z_fgid
, 8);
880 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PAD(zsb
), NULL
, pad
,
881 sizeof (uint64_t) * 4);
882 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ZNODE_ACL(zsb
), NULL
,
883 &acl_phys
, sizeof (zfs_acl_phys_t
));
884 } else if (acl_ids
->z_aclp
->z_version
>= ZFS_ACL_VERSION_FUID
) {
885 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_DACL_COUNT(zsb
), NULL
,
886 &acl_ids
->z_aclp
->z_acl_count
, 8);
887 locate
.cb_aclp
= acl_ids
->z_aclp
;
888 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_DACL_ACES(zsb
),
889 zfs_acl_data_locator
, &locate
,
890 acl_ids
->z_aclp
->z_acl_bytes
);
891 mode
= zfs_mode_compute(mode
, acl_ids
->z_aclp
, &pflags
,
892 acl_ids
->z_fuid
, acl_ids
->z_fgid
);
895 VERIFY(sa_replace_all_by_template(sa_hdl
, sa_attrs
, cnt
, tx
) == 0);
897 if (!(flag
& IS_ROOT_NODE
)) {
898 *zpp
= zfs_znode_alloc(zsb
, db
, 0, obj_type
, obj
, sa_hdl
);
899 VERIFY(*zpp
!= NULL
);
903 * If we are creating the root node, the "parent" we
904 * passed in is the znode for the root.
908 (*zpp
)->z_sa_hdl
= sa_hdl
;
911 (*zpp
)->z_pflags
= pflags
;
912 (*zpp
)->z_mode
= mode
;
914 if (obj_type
== DMU_OT_ZNODE
||
915 acl_ids
->z_aclp
->z_version
< ZFS_ACL_VERSION_FUID
) {
916 VERIFY0(zfs_aclset_common(*zpp
, acl_ids
->z_aclp
, cr
, tx
));
918 kmem_free(sa_attrs
, sizeof (sa_bulk_attr_t
) * ZPL_END
);
919 zfs_znode_hold_exit(zsb
, zh
);
923 * Update in-core attributes. It is assumed the caller will be doing an
924 * sa_bulk_update to push the changes out.
927 zfs_xvattr_set(znode_t
*zp
, xvattr_t
*xvap
, dmu_tx_t
*tx
)
931 xoap
= xva_getxoptattr(xvap
);
934 if (XVA_ISSET_REQ(xvap
, XAT_CREATETIME
)) {
936 ZFS_TIME_ENCODE(&xoap
->xoa_createtime
, times
);
937 (void) sa_update(zp
->z_sa_hdl
, SA_ZPL_CRTIME(ZTOZSB(zp
)),
938 ×
, sizeof (times
), tx
);
939 XVA_SET_RTN(xvap
, XAT_CREATETIME
);
941 if (XVA_ISSET_REQ(xvap
, XAT_READONLY
)) {
942 ZFS_ATTR_SET(zp
, ZFS_READONLY
, xoap
->xoa_readonly
,
944 XVA_SET_RTN(xvap
, XAT_READONLY
);
946 if (XVA_ISSET_REQ(xvap
, XAT_HIDDEN
)) {
947 ZFS_ATTR_SET(zp
, ZFS_HIDDEN
, xoap
->xoa_hidden
,
949 XVA_SET_RTN(xvap
, XAT_HIDDEN
);
951 if (XVA_ISSET_REQ(xvap
, XAT_SYSTEM
)) {
952 ZFS_ATTR_SET(zp
, ZFS_SYSTEM
, xoap
->xoa_system
,
954 XVA_SET_RTN(xvap
, XAT_SYSTEM
);
956 if (XVA_ISSET_REQ(xvap
, XAT_ARCHIVE
)) {
957 ZFS_ATTR_SET(zp
, ZFS_ARCHIVE
, xoap
->xoa_archive
,
959 XVA_SET_RTN(xvap
, XAT_ARCHIVE
);
961 if (XVA_ISSET_REQ(xvap
, XAT_IMMUTABLE
)) {
962 ZFS_ATTR_SET(zp
, ZFS_IMMUTABLE
, xoap
->xoa_immutable
,
964 XVA_SET_RTN(xvap
, XAT_IMMUTABLE
);
966 if (XVA_ISSET_REQ(xvap
, XAT_NOUNLINK
)) {
967 ZFS_ATTR_SET(zp
, ZFS_NOUNLINK
, xoap
->xoa_nounlink
,
969 XVA_SET_RTN(xvap
, XAT_NOUNLINK
);
971 if (XVA_ISSET_REQ(xvap
, XAT_APPENDONLY
)) {
972 ZFS_ATTR_SET(zp
, ZFS_APPENDONLY
, xoap
->xoa_appendonly
,
974 XVA_SET_RTN(xvap
, XAT_APPENDONLY
);
976 if (XVA_ISSET_REQ(xvap
, XAT_NODUMP
)) {
977 ZFS_ATTR_SET(zp
, ZFS_NODUMP
, xoap
->xoa_nodump
,
979 XVA_SET_RTN(xvap
, XAT_NODUMP
);
981 if (XVA_ISSET_REQ(xvap
, XAT_OPAQUE
)) {
982 ZFS_ATTR_SET(zp
, ZFS_OPAQUE
, xoap
->xoa_opaque
,
984 XVA_SET_RTN(xvap
, XAT_OPAQUE
);
986 if (XVA_ISSET_REQ(xvap
, XAT_AV_QUARANTINED
)) {
987 ZFS_ATTR_SET(zp
, ZFS_AV_QUARANTINED
,
988 xoap
->xoa_av_quarantined
, zp
->z_pflags
, tx
);
989 XVA_SET_RTN(xvap
, XAT_AV_QUARANTINED
);
991 if (XVA_ISSET_REQ(xvap
, XAT_AV_MODIFIED
)) {
992 ZFS_ATTR_SET(zp
, ZFS_AV_MODIFIED
, xoap
->xoa_av_modified
,
994 XVA_SET_RTN(xvap
, XAT_AV_MODIFIED
);
996 if (XVA_ISSET_REQ(xvap
, XAT_AV_SCANSTAMP
)) {
997 zfs_sa_set_scanstamp(zp
, xvap
, tx
);
998 XVA_SET_RTN(xvap
, XAT_AV_SCANSTAMP
);
1000 if (XVA_ISSET_REQ(xvap
, XAT_REPARSE
)) {
1001 ZFS_ATTR_SET(zp
, ZFS_REPARSE
, xoap
->xoa_reparse
,
1003 XVA_SET_RTN(xvap
, XAT_REPARSE
);
1005 if (XVA_ISSET_REQ(xvap
, XAT_OFFLINE
)) {
1006 ZFS_ATTR_SET(zp
, ZFS_OFFLINE
, xoap
->xoa_offline
,
1008 XVA_SET_RTN(xvap
, XAT_OFFLINE
);
1010 if (XVA_ISSET_REQ(xvap
, XAT_SPARSE
)) {
1011 ZFS_ATTR_SET(zp
, ZFS_SPARSE
, xoap
->xoa_sparse
,
1013 XVA_SET_RTN(xvap
, XAT_SPARSE
);
1018 zfs_zget(zfs_sb_t
*zsb
, uint64_t obj_num
, znode_t
**zpp
)
1020 dmu_object_info_t doi
;
1030 zh
= zfs_znode_hold_enter(zsb
, obj_num
);
1032 err
= sa_buf_hold(zsb
->z_os
, obj_num
, NULL
, &db
);
1034 zfs_znode_hold_exit(zsb
, zh
);
1038 dmu_object_info_from_db(db
, &doi
);
1039 if (doi
.doi_bonus_type
!= DMU_OT_SA
&&
1040 (doi
.doi_bonus_type
!= DMU_OT_ZNODE
||
1041 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1042 doi
.doi_bonus_size
< sizeof (znode_phys_t
)))) {
1043 sa_buf_rele(db
, NULL
);
1044 zfs_znode_hold_exit(zsb
, zh
);
1045 return (SET_ERROR(EINVAL
));
1048 hdl
= dmu_buf_get_user(db
);
1050 zp
= sa_get_userdata(hdl
);
1054 * Since "SA" does immediate eviction we
1055 * should never find a sa handle that doesn't
1056 * know about the znode.
1059 ASSERT3P(zp
, !=, NULL
);
1061 mutex_enter(&zp
->z_lock
);
1062 ASSERT3U(zp
->z_id
, ==, obj_num
);
1063 if (zp
->z_unlinked
) {
1064 err
= SET_ERROR(ENOENT
);
1067 * If igrab() returns NULL the VFS has independently
1068 * determined the inode should be evicted and has
1069 * called iput_final() to start the eviction process.
1070 * The SA handle is still valid but because the VFS
1071 * requires that the eviction succeed we must drop
1072 * our locks and references to allow the eviction to
1073 * complete. The zfs_zget() may then be retried.
1075 * This unlikely case could be optimized by registering
1076 * a sops->drop_inode() callback. The callback would
1077 * need to detect the active SA hold thereby informing
1078 * the VFS that this inode should not be evicted.
1080 if (igrab(ZTOI(zp
)) == NULL
) {
1081 mutex_exit(&zp
->z_lock
);
1082 sa_buf_rele(db
, NULL
);
1083 zfs_znode_hold_exit(zsb
, zh
);
1084 /* inode might need this to finish evict */
1091 mutex_exit(&zp
->z_lock
);
1092 sa_buf_rele(db
, NULL
);
1093 zfs_znode_hold_exit(zsb
, zh
);
1098 * Not found create new znode/vnode but only if file exists.
1100 * There is a small window where zfs_vget() could
1101 * find this object while a file create is still in
1102 * progress. This is checked for in zfs_znode_alloc()
1104 * if zfs_znode_alloc() fails it will drop the hold on the
1107 zp
= zfs_znode_alloc(zsb
, db
, doi
.doi_data_block_size
,
1108 doi
.doi_bonus_type
, obj_num
, NULL
);
1110 err
= SET_ERROR(ENOENT
);
1114 zfs_znode_hold_exit(zsb
, zh
);
1119 zfs_rezget(znode_t
*zp
)
1121 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1122 dmu_object_info_t doi
;
1124 uint64_t obj_num
= zp
->z_id
;
1126 sa_bulk_attr_t bulk
[8];
1133 * skip ctldir, otherwise they will always get invalidated. This will
1134 * cause funny behaviour for the mounted snapdirs. Especially for
1135 * Linux >= 3.18, d_invalidate will detach the mountpoint and prevent
1136 * anyone automount it again as long as someone is still using the
1139 if (zp
->z_is_ctldir
)
1142 zh
= zfs_znode_hold_enter(zsb
, obj_num
);
1144 mutex_enter(&zp
->z_acl_lock
);
1145 if (zp
->z_acl_cached
) {
1146 zfs_acl_free(zp
->z_acl_cached
);
1147 zp
->z_acl_cached
= NULL
;
1149 mutex_exit(&zp
->z_acl_lock
);
1151 rw_enter(&zp
->z_xattr_lock
, RW_WRITER
);
1152 if (zp
->z_xattr_cached
) {
1153 nvlist_free(zp
->z_xattr_cached
);
1154 zp
->z_xattr_cached
= NULL
;
1156 rw_exit(&zp
->z_xattr_lock
);
1158 ASSERT(zp
->z_sa_hdl
== NULL
);
1159 err
= sa_buf_hold(zsb
->z_os
, obj_num
, NULL
, &db
);
1161 zfs_znode_hold_exit(zsb
, zh
);
1165 dmu_object_info_from_db(db
, &doi
);
1166 if (doi
.doi_bonus_type
!= DMU_OT_SA
&&
1167 (doi
.doi_bonus_type
!= DMU_OT_ZNODE
||
1168 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1169 doi
.doi_bonus_size
< sizeof (znode_phys_t
)))) {
1170 sa_buf_rele(db
, NULL
);
1171 zfs_znode_hold_exit(zsb
, zh
);
1172 return (SET_ERROR(EINVAL
));
1175 zfs_znode_sa_init(zsb
, zp
, db
, doi
.doi_bonus_type
, NULL
);
1177 /* reload cached values */
1178 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GEN(zsb
), NULL
,
1179 &gen
, sizeof (gen
));
1180 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zsb
), NULL
,
1181 &zp
->z_size
, sizeof (zp
->z_size
));
1182 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_LINKS(zsb
), NULL
,
1183 &zp
->z_links
, sizeof (zp
->z_links
));
1184 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
), NULL
,
1185 &zp
->z_pflags
, sizeof (zp
->z_pflags
));
1186 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_ATIME(zsb
), NULL
,
1187 &zp
->z_atime
, sizeof (zp
->z_atime
));
1188 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_UID(zsb
), NULL
,
1189 &zp
->z_uid
, sizeof (zp
->z_uid
));
1190 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GID(zsb
), NULL
,
1191 &zp
->z_gid
, sizeof (zp
->z_gid
));
1192 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zsb
), NULL
,
1193 &mode
, sizeof (mode
));
1195 if (sa_bulk_lookup(zp
->z_sa_hdl
, bulk
, count
)) {
1196 zfs_znode_dmu_fini(zp
);
1197 zfs_znode_hold_exit(zsb
, zh
);
1198 return (SET_ERROR(EIO
));
1203 if (gen
!= zp
->z_gen
) {
1204 zfs_znode_dmu_fini(zp
);
1205 zfs_znode_hold_exit(zsb
, zh
);
1206 return (SET_ERROR(EIO
));
1209 zp
->z_unlinked
= (zp
->z_links
== 0);
1210 zp
->z_blksz
= doi
.doi_data_block_size
;
1211 zfs_inode_update(zp
);
1213 zfs_znode_hold_exit(zsb
, zh
);
1219 zfs_znode_delete(znode_t
*zp
, dmu_tx_t
*tx
)
1221 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1222 objset_t
*os
= zsb
->z_os
;
1223 uint64_t obj
= zp
->z_id
;
1224 uint64_t acl_obj
= zfs_external_acl(zp
);
1227 zh
= zfs_znode_hold_enter(zsb
, obj
);
1229 VERIFY(!zp
->z_is_sa
);
1230 VERIFY(0 == dmu_object_free(os
, acl_obj
, tx
));
1232 VERIFY(0 == dmu_object_free(os
, obj
, tx
));
1233 zfs_znode_dmu_fini(zp
);
1234 zfs_znode_hold_exit(zsb
, zh
);
1238 zfs_zinactive(znode_t
*zp
)
1240 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1241 uint64_t z_id
= zp
->z_id
;
1244 ASSERT(zp
->z_sa_hdl
);
1247 * Don't allow a zfs_zget() while were trying to release this znode.
1249 zh
= zfs_znode_hold_enter(zsb
, z_id
);
1251 mutex_enter(&zp
->z_lock
);
1254 * If this was the last reference to a file with no links,
1255 * remove the file from the file system.
1257 if (zp
->z_unlinked
) {
1258 mutex_exit(&zp
->z_lock
);
1259 zfs_znode_hold_exit(zsb
, zh
);
1264 mutex_exit(&zp
->z_lock
);
1265 zfs_znode_dmu_fini(zp
);
1267 zfs_znode_hold_exit(zsb
, zh
);
1271 zfs_compare_timespec(struct timespec
*t1
, struct timespec
*t2
)
1273 if (t1
->tv_sec
< t2
->tv_sec
)
1276 if (t1
->tv_sec
> t2
->tv_sec
)
1279 return (t1
->tv_nsec
- t2
->tv_nsec
);
1283 * Determine whether the znode's atime must be updated. The logic mostly
1284 * duplicates the Linux kernel's relatime_need_update() functionality.
1285 * This function is only called if the underlying filesystem actually has
1286 * atime updates enabled.
1288 static inline boolean_t
1289 zfs_atime_need_update(znode_t
*zp
, timestruc_t
*now
)
1291 if (!ZTOZSB(zp
)->z_relatime
)
1295 * In relatime mode, only update the atime if the previous atime
1296 * is earlier than either the ctime or mtime or if at least a day
1297 * has passed since the last update of atime.
1299 if (zfs_compare_timespec(&ZTOI(zp
)->i_mtime
, &ZTOI(zp
)->i_atime
) >= 0)
1302 if (zfs_compare_timespec(&ZTOI(zp
)->i_ctime
, &ZTOI(zp
)->i_atime
) >= 0)
1305 if ((long)now
->tv_sec
- ZTOI(zp
)->i_atime
.tv_sec
>= 24*60*60)
1312 * Prepare to update znode time stamps.
1314 * IN: zp - znode requiring timestamp update
1315 * flag - ATTR_MTIME, ATTR_CTIME, ATTR_ATIME flags
1316 * have_tx - true of caller is creating a new txg
1318 * OUT: zp - new atime (via underlying inode's i_atime)
1322 * NOTE: The arguments are somewhat redundant. The following condition
1325 * have_tx == !(flag & ATTR_ATIME)
1328 zfs_tstamp_update_setup(znode_t
*zp
, uint_t flag
, uint64_t mtime
[2],
1329 uint64_t ctime
[2], boolean_t have_tx
)
1333 ASSERT(have_tx
== !(flag
& ATTR_ATIME
));
1337 * NOTE: The following test intentionally does not update z_atime_dirty
1338 * in the case where an ATIME update has been requested but for which
1339 * the update is omitted due to relatime logic. The rationale being
1340 * that if the flag was set somewhere else, we should leave it alone
1343 if (flag
& ATTR_ATIME
) {
1344 if (zfs_atime_need_update(zp
, &now
)) {
1345 ZFS_TIME_ENCODE(&now
, zp
->z_atime
);
1346 ZTOI(zp
)->i_atime
.tv_sec
= zp
->z_atime
[0];
1347 ZTOI(zp
)->i_atime
.tv_nsec
= zp
->z_atime
[1];
1348 zp
->z_atime_dirty
= 1;
1351 zp
->z_atime_dirty
= 0;
1355 if (flag
& ATTR_MTIME
) {
1356 ZFS_TIME_ENCODE(&now
, mtime
);
1357 if (ZTOZSB(zp
)->z_use_fuids
) {
1358 zp
->z_pflags
|= (ZFS_ARCHIVE
|
1363 if (flag
& ATTR_CTIME
) {
1364 ZFS_TIME_ENCODE(&now
, ctime
);
1365 if (ZTOZSB(zp
)->z_use_fuids
)
1366 zp
->z_pflags
|= ZFS_ARCHIVE
;
1371 * Grow the block size for a file.
1373 * IN: zp - znode of file to free data in.
1374 * size - requested block size
1375 * tx - open transaction.
1377 * NOTE: this function assumes that the znode is write locked.
1380 zfs_grow_blocksize(znode_t
*zp
, uint64_t size
, dmu_tx_t
*tx
)
1385 if (size
<= zp
->z_blksz
)
1388 * If the file size is already greater than the current blocksize,
1389 * we will not grow. If there is more than one block in a file,
1390 * the blocksize cannot change.
1392 if (zp
->z_blksz
&& zp
->z_size
> zp
->z_blksz
)
1395 error
= dmu_object_set_blocksize(ZTOZSB(zp
)->z_os
, zp
->z_id
,
1398 if (error
== ENOTSUP
)
1402 /* What blocksize did we actually get? */
1403 dmu_object_size_from_db(sa_get_db(zp
->z_sa_hdl
), &zp
->z_blksz
, &dummy
);
1407 * Increase the file length
1409 * IN: zp - znode of file to free data in.
1410 * end - new end-of-file
1412 * RETURN: 0 on success, error code on failure
1415 zfs_extend(znode_t
*zp
, uint64_t end
)
1417 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1424 * We will change zp_size, lock the whole file.
1426 rl
= zfs_range_lock(&zp
->z_range_lock
, 0, UINT64_MAX
, RL_WRITER
);
1429 * Nothing to do if file already at desired length.
1431 if (end
<= zp
->z_size
) {
1432 zfs_range_unlock(rl
);
1435 tx
= dmu_tx_create(zsb
->z_os
);
1436 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1437 zfs_sa_upgrade_txholds(tx
, zp
);
1438 if (end
> zp
->z_blksz
&&
1439 (!ISP2(zp
->z_blksz
) || zp
->z_blksz
< zsb
->z_max_blksz
)) {
1441 * We are growing the file past the current block size.
1443 if (zp
->z_blksz
> ZTOZSB(zp
)->z_max_blksz
) {
1445 * File's blocksize is already larger than the
1446 * "recordsize" property. Only let it grow to
1447 * the next power of 2.
1449 ASSERT(!ISP2(zp
->z_blksz
));
1450 newblksz
= MIN(end
, 1 << highbit64(zp
->z_blksz
));
1452 newblksz
= MIN(end
, ZTOZSB(zp
)->z_max_blksz
);
1454 dmu_tx_hold_write(tx
, zp
->z_id
, 0, newblksz
);
1459 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1462 zfs_range_unlock(rl
);
1467 zfs_grow_blocksize(zp
, newblksz
, tx
);
1471 VERIFY(0 == sa_update(zp
->z_sa_hdl
, SA_ZPL_SIZE(ZTOZSB(zp
)),
1472 &zp
->z_size
, sizeof (zp
->z_size
), tx
));
1474 zfs_range_unlock(rl
);
1482 * zfs_zero_partial_page - Modeled after update_pages() but
1483 * with different arguments and semantics for use by zfs_freesp().
1485 * Zeroes a piece of a single page cache entry for zp at offset
1486 * start and length len.
1488 * Caller must acquire a range lock on the file for the region
1489 * being zeroed in order that the ARC and page cache stay in sync.
1492 zfs_zero_partial_page(znode_t
*zp
, uint64_t start
, uint64_t len
)
1494 struct address_space
*mp
= ZTOI(zp
)->i_mapping
;
1499 ASSERT((start
& PAGE_MASK
) == ((start
+ len
- 1) & PAGE_MASK
));
1501 off
= start
& (PAGE_SIZE
- 1);
1504 pp
= find_lock_page(mp
, start
>> PAGE_SHIFT
);
1506 if (mapping_writably_mapped(mp
))
1507 flush_dcache_page(pp
);
1510 bzero(pb
+ off
, len
);
1513 if (mapping_writably_mapped(mp
))
1514 flush_dcache_page(pp
);
1516 mark_page_accessed(pp
);
1517 SetPageUptodate(pp
);
1525 * Free space in a file.
1527 * IN: zp - znode of file to free data in.
1528 * off - start of section to free.
1529 * len - length of section to free.
1531 * RETURN: 0 on success, error code on failure
1534 zfs_free_range(znode_t
*zp
, uint64_t off
, uint64_t len
)
1536 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1541 * Lock the range being freed.
1543 rl
= zfs_range_lock(&zp
->z_range_lock
, off
, len
, RL_WRITER
);
1546 * Nothing to do if file already at desired length.
1548 if (off
>= zp
->z_size
) {
1549 zfs_range_unlock(rl
);
1553 if (off
+ len
> zp
->z_size
)
1554 len
= zp
->z_size
- off
;
1556 error
= dmu_free_long_range(zsb
->z_os
, zp
->z_id
, off
, len
);
1559 * Zero partial page cache entries. This must be done under a
1560 * range lock in order to keep the ARC and page cache in sync.
1562 if (zp
->z_is_mapped
) {
1563 loff_t first_page
, last_page
, page_len
;
1564 loff_t first_page_offset
, last_page_offset
;
1566 /* first possible full page in hole */
1567 first_page
= (off
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
1568 /* last page of hole */
1569 last_page
= (off
+ len
) >> PAGE_SHIFT
;
1571 /* offset of first_page */
1572 first_page_offset
= first_page
<< PAGE_SHIFT
;
1573 /* offset of last_page */
1574 last_page_offset
= last_page
<< PAGE_SHIFT
;
1576 /* truncate whole pages */
1577 if (last_page_offset
> first_page_offset
) {
1578 truncate_inode_pages_range(ZTOI(zp
)->i_mapping
,
1579 first_page_offset
, last_page_offset
- 1);
1582 /* truncate sub-page ranges */
1583 if (first_page
> last_page
) {
1584 /* entire punched area within a single page */
1585 zfs_zero_partial_page(zp
, off
, len
);
1587 /* beginning of punched area at the end of a page */
1588 page_len
= first_page_offset
- off
;
1590 zfs_zero_partial_page(zp
, off
, page_len
);
1592 /* end of punched area at the beginning of a page */
1593 page_len
= off
+ len
- last_page_offset
;
1595 zfs_zero_partial_page(zp
, last_page_offset
,
1599 zfs_range_unlock(rl
);
1607 * IN: zp - znode of file to free data in.
1608 * end - new end-of-file.
1610 * RETURN: 0 on success, error code on failure
1613 zfs_trunc(znode_t
*zp
, uint64_t end
)
1615 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1619 sa_bulk_attr_t bulk
[2];
1623 * We will change zp_size, lock the whole file.
1625 rl
= zfs_range_lock(&zp
->z_range_lock
, 0, UINT64_MAX
, RL_WRITER
);
1628 * Nothing to do if file already at desired length.
1630 if (end
>= zp
->z_size
) {
1631 zfs_range_unlock(rl
);
1635 error
= dmu_free_long_range(zsb
->z_os
, zp
->z_id
, end
, -1);
1637 zfs_range_unlock(rl
);
1640 tx
= dmu_tx_create(zsb
->z_os
);
1641 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1642 zfs_sa_upgrade_txholds(tx
, zp
);
1643 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1646 zfs_range_unlock(rl
);
1651 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zsb
),
1652 NULL
, &zp
->z_size
, sizeof (zp
->z_size
));
1655 zp
->z_pflags
&= ~ZFS_SPARSE
;
1656 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
),
1657 NULL
, &zp
->z_pflags
, 8);
1659 VERIFY(sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
) == 0);
1663 zfs_range_unlock(rl
);
1669 * Free space in a file
1671 * IN: zp - znode of file to free data in.
1672 * off - start of range
1673 * len - end of range (0 => EOF)
1674 * flag - current file open mode flags.
1675 * log - TRUE if this action should be logged
1677 * RETURN: 0 on success, error code on failure
1680 zfs_freesp(znode_t
*zp
, uint64_t off
, uint64_t len
, int flag
, boolean_t log
)
1683 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1684 zilog_t
*zilog
= zsb
->z_log
;
1686 uint64_t mtime
[2], ctime
[2];
1687 sa_bulk_attr_t bulk
[3];
1691 if ((error
= sa_lookup(zp
->z_sa_hdl
, SA_ZPL_MODE(zsb
), &mode
,
1692 sizeof (mode
))) != 0)
1695 if (off
> zp
->z_size
) {
1696 error
= zfs_extend(zp
, off
+len
);
1697 if (error
== 0 && log
)
1703 error
= zfs_trunc(zp
, off
);
1705 if ((error
= zfs_free_range(zp
, off
, len
)) == 0 &&
1706 off
+ len
> zp
->z_size
)
1707 error
= zfs_extend(zp
, off
+len
);
1712 tx
= dmu_tx_create(zsb
->z_os
);
1713 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1714 zfs_sa_upgrade_txholds(tx
, zp
);
1715 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1721 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zsb
), NULL
, mtime
, 16);
1722 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zsb
), NULL
, ctime
, 16);
1723 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
),
1724 NULL
, &zp
->z_pflags
, 8);
1725 zfs_tstamp_update_setup(zp
, CONTENT_MODIFIED
, mtime
, ctime
, B_TRUE
);
1726 error
= sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
);
1729 zfs_log_truncate(zilog
, tx
, TX_TRUNCATE
, zp
, off
, len
);
1733 zfs_inode_update(zp
);
1738 * Truncate the page cache - for file truncate operations, use
1739 * the purpose-built API for truncations. For punching operations,
1740 * the truncation is handled under a range lock in zfs_free_range.
1743 truncate_setsize(ZTOI(zp
), off
);
1748 zfs_create_fs(objset_t
*os
, cred_t
*cr
, nvlist_t
*zplprops
, dmu_tx_t
*tx
)
1750 struct super_block
*sb
;
1752 uint64_t moid
, obj
, sa_obj
, version
;
1753 uint64_t sense
= ZFS_CASE_SENSITIVE
;
1759 znode_t
*rootzp
= NULL
;
1762 zfs_acl_ids_t acl_ids
;
1765 * First attempt to create master node.
1768 * In an empty objset, there are no blocks to read and thus
1769 * there can be no i/o errors (which we assert below).
1771 moid
= MASTER_NODE_OBJ
;
1772 error
= zap_create_claim(os
, moid
, DMU_OT_MASTER_NODE
,
1773 DMU_OT_NONE
, 0, tx
);
1777 * Set starting attributes.
1779 version
= zfs_zpl_version_map(spa_version(dmu_objset_spa(os
)));
1781 while ((elem
= nvlist_next_nvpair(zplprops
, elem
)) != NULL
) {
1782 /* For the moment we expect all zpl props to be uint64_ts */
1786 ASSERT(nvpair_type(elem
) == DATA_TYPE_UINT64
);
1787 VERIFY(nvpair_value_uint64(elem
, &val
) == 0);
1788 name
= nvpair_name(elem
);
1789 if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_VERSION
)) == 0) {
1793 error
= zap_update(os
, moid
, name
, 8, 1, &val
, tx
);
1796 if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_NORMALIZE
)) == 0)
1798 else if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_CASE
)) == 0)
1801 ASSERT(version
!= 0);
1802 error
= zap_update(os
, moid
, ZPL_VERSION_STR
, 8, 1, &version
, tx
);
1805 * Create zap object used for SA attribute registration
1808 if (version
>= ZPL_VERSION_SA
) {
1809 sa_obj
= zap_create(os
, DMU_OT_SA_MASTER_NODE
,
1810 DMU_OT_NONE
, 0, tx
);
1811 error
= zap_add(os
, moid
, ZFS_SA_ATTRS
, 8, 1, &sa_obj
, tx
);
1817 * Create a delete queue.
1819 obj
= zap_create(os
, DMU_OT_UNLINKED_SET
, DMU_OT_NONE
, 0, tx
);
1821 error
= zap_add(os
, moid
, ZFS_UNLINKED_SET
, 8, 1, &obj
, tx
);
1825 * Create root znode. Create minimal znode/inode/zsb/sb
1826 * to allow zfs_mknode to work.
1828 vattr
.va_mask
= ATTR_MODE
|ATTR_UID
|ATTR_GID
;
1829 vattr
.va_mode
= S_IFDIR
|0755;
1830 vattr
.va_uid
= crgetuid(cr
);
1831 vattr
.va_gid
= crgetgid(cr
);
1833 rootzp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
1834 rootzp
->z_moved
= 0;
1835 rootzp
->z_unlinked
= 0;
1836 rootzp
->z_atime_dirty
= 0;
1837 rootzp
->z_is_sa
= USE_SA(version
, os
);
1839 zsb
= kmem_zalloc(sizeof (zfs_sb_t
), KM_SLEEP
);
1841 zsb
->z_parent
= zsb
;
1842 zsb
->z_version
= version
;
1843 zsb
->z_use_fuids
= USE_FUIDS(version
, os
);
1844 zsb
->z_use_sa
= USE_SA(version
, os
);
1847 sb
= kmem_zalloc(sizeof (struct super_block
), KM_SLEEP
);
1848 sb
->s_fs_info
= zsb
;
1850 ZTOI(rootzp
)->i_sb
= sb
;
1852 error
= sa_setup(os
, sa_obj
, zfs_attr_table
, ZPL_END
,
1853 &zsb
->z_attr_table
);
1858 * Fold case on file systems that are always or sometimes case
1861 if (sense
== ZFS_CASE_INSENSITIVE
|| sense
== ZFS_CASE_MIXED
)
1862 zsb
->z_norm
|= U8_TEXTPREP_TOUPPER
;
1864 mutex_init(&zsb
->z_znodes_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
1865 list_create(&zsb
->z_all_znodes
, sizeof (znode_t
),
1866 offsetof(znode_t
, z_link_node
));
1868 size
= MIN(1 << (highbit64(zfs_object_mutex_size
)-1), ZFS_OBJ_MTX_MAX
);
1869 zsb
->z_hold_size
= size
;
1870 zsb
->z_hold_trees
= vmem_zalloc(sizeof (avl_tree_t
) * size
, KM_SLEEP
);
1871 zsb
->z_hold_locks
= vmem_zalloc(sizeof (kmutex_t
) * size
, KM_SLEEP
);
1872 for (i
= 0; i
!= size
; i
++) {
1873 avl_create(&zsb
->z_hold_trees
[i
], zfs_znode_hold_compare
,
1874 sizeof (znode_hold_t
), offsetof(znode_hold_t
, zh_node
));
1875 mutex_init(&zsb
->z_hold_locks
[i
], NULL
, MUTEX_DEFAULT
, NULL
);
1878 VERIFY(0 == zfs_acl_ids_create(rootzp
, IS_ROOT_NODE
, &vattr
,
1879 cr
, NULL
, &acl_ids
));
1880 zfs_mknode(rootzp
, &vattr
, tx
, cr
, IS_ROOT_NODE
, &zp
, &acl_ids
);
1881 ASSERT3P(zp
, ==, rootzp
);
1882 error
= zap_add(os
, moid
, ZFS_ROOT_OBJ
, 8, 1, &rootzp
->z_id
, tx
);
1884 zfs_acl_ids_free(&acl_ids
);
1886 atomic_set(&ZTOI(rootzp
)->i_count
, 0);
1887 sa_handle_destroy(rootzp
->z_sa_hdl
);
1888 kmem_cache_free(znode_cache
, rootzp
);
1891 * Create shares directory
1893 error
= zfs_create_share_dir(zsb
, tx
);
1896 for (i
= 0; i
!= size
; i
++) {
1897 avl_destroy(&zsb
->z_hold_trees
[i
]);
1898 mutex_destroy(&zsb
->z_hold_locks
[i
]);
1901 vmem_free(zsb
->z_hold_trees
, sizeof (avl_tree_t
) * size
);
1902 vmem_free(zsb
->z_hold_locks
, sizeof (kmutex_t
) * size
);
1903 kmem_free(sb
, sizeof (struct super_block
));
1904 kmem_free(zsb
, sizeof (zfs_sb_t
));
1906 #endif /* _KERNEL */
1909 zfs_sa_setup(objset_t
*osp
, sa_attr_type_t
**sa_table
)
1911 uint64_t sa_obj
= 0;
1914 error
= zap_lookup(osp
, MASTER_NODE_OBJ
, ZFS_SA_ATTRS
, 8, 1, &sa_obj
);
1915 if (error
!= 0 && error
!= ENOENT
)
1918 error
= sa_setup(osp
, sa_obj
, zfs_attr_table
, ZPL_END
, sa_table
);
1923 zfs_grab_sa_handle(objset_t
*osp
, uint64_t obj
, sa_handle_t
**hdlp
,
1924 dmu_buf_t
**db
, void *tag
)
1926 dmu_object_info_t doi
;
1929 if ((error
= sa_buf_hold(osp
, obj
, tag
, db
)) != 0)
1932 dmu_object_info_from_db(*db
, &doi
);
1933 if ((doi
.doi_bonus_type
!= DMU_OT_SA
&&
1934 doi
.doi_bonus_type
!= DMU_OT_ZNODE
) ||
1935 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1936 doi
.doi_bonus_size
< sizeof (znode_phys_t
))) {
1937 sa_buf_rele(*db
, tag
);
1938 return (SET_ERROR(ENOTSUP
));
1941 error
= sa_handle_get(osp
, obj
, NULL
, SA_HDL_PRIVATE
, hdlp
);
1943 sa_buf_rele(*db
, tag
);
1951 zfs_release_sa_handle(sa_handle_t
*hdl
, dmu_buf_t
*db
, void *tag
)
1953 sa_handle_destroy(hdl
);
1954 sa_buf_rele(db
, tag
);
1958 * Given an object number, return its parent object number and whether
1959 * or not the object is an extended attribute directory.
1962 zfs_obj_to_pobj(sa_handle_t
*hdl
, sa_attr_type_t
*sa_table
, uint64_t *pobjp
,
1968 sa_bulk_attr_t bulk
[3];
1972 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_PARENT
], NULL
,
1973 &parent
, sizeof (parent
));
1974 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_FLAGS
], NULL
,
1975 &pflags
, sizeof (pflags
));
1976 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_MODE
], NULL
,
1977 &mode
, sizeof (mode
));
1979 if ((error
= sa_bulk_lookup(hdl
, bulk
, count
)) != 0)
1983 *is_xattrdir
= ((pflags
& ZFS_XATTR
) != 0) && S_ISDIR(mode
);
1989 * Given an object number, return some zpl level statistics
1992 zfs_obj_to_stats_impl(sa_handle_t
*hdl
, sa_attr_type_t
*sa_table
,
1995 sa_bulk_attr_t bulk
[4];
1998 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_MODE
], NULL
,
1999 &sb
->zs_mode
, sizeof (sb
->zs_mode
));
2000 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_GEN
], NULL
,
2001 &sb
->zs_gen
, sizeof (sb
->zs_gen
));
2002 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_LINKS
], NULL
,
2003 &sb
->zs_links
, sizeof (sb
->zs_links
));
2004 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_CTIME
], NULL
,
2005 &sb
->zs_ctime
, sizeof (sb
->zs_ctime
));
2007 return (sa_bulk_lookup(hdl
, bulk
, count
));
2011 zfs_obj_to_path_impl(objset_t
*osp
, uint64_t obj
, sa_handle_t
*hdl
,
2012 sa_attr_type_t
*sa_table
, char *buf
, int len
)
2014 sa_handle_t
*sa_hdl
;
2015 sa_handle_t
*prevhdl
= NULL
;
2016 dmu_buf_t
*prevdb
= NULL
;
2017 dmu_buf_t
*sa_db
= NULL
;
2018 char *path
= buf
+ len
- 1;
2026 char component
[MAXNAMELEN
+ 2];
2028 int is_xattrdir
= 0;
2031 zfs_release_sa_handle(prevhdl
, prevdb
, FTAG
);
2033 if ((error
= zfs_obj_to_pobj(sa_hdl
, sa_table
, &pobj
,
2034 &is_xattrdir
)) != 0)
2045 (void) sprintf(component
+ 1, "<xattrdir>");
2047 error
= zap_value_search(osp
, pobj
, obj
,
2048 ZFS_DIRENT_OBJ(-1ULL), component
+ 1);
2053 complen
= strlen(component
);
2055 ASSERT(path
>= buf
);
2056 bcopy(component
, path
, complen
);
2059 if (sa_hdl
!= hdl
) {
2063 error
= zfs_grab_sa_handle(osp
, obj
, &sa_hdl
, &sa_db
, FTAG
);
2071 if (sa_hdl
!= NULL
&& sa_hdl
!= hdl
) {
2072 ASSERT(sa_db
!= NULL
);
2073 zfs_release_sa_handle(sa_hdl
, sa_db
, FTAG
);
2077 (void) memmove(buf
, path
, buf
+ len
- path
);
2083 zfs_obj_to_path(objset_t
*osp
, uint64_t obj
, char *buf
, int len
)
2085 sa_attr_type_t
*sa_table
;
2090 error
= zfs_sa_setup(osp
, &sa_table
);
2094 error
= zfs_grab_sa_handle(osp
, obj
, &hdl
, &db
, FTAG
);
2098 error
= zfs_obj_to_path_impl(osp
, obj
, hdl
, sa_table
, buf
, len
);
2100 zfs_release_sa_handle(hdl
, db
, FTAG
);
2105 zfs_obj_to_stats(objset_t
*osp
, uint64_t obj
, zfs_stat_t
*sb
,
2108 char *path
= buf
+ len
- 1;
2109 sa_attr_type_t
*sa_table
;
2116 error
= zfs_sa_setup(osp
, &sa_table
);
2120 error
= zfs_grab_sa_handle(osp
, obj
, &hdl
, &db
, FTAG
);
2124 error
= zfs_obj_to_stats_impl(hdl
, sa_table
, sb
);
2126 zfs_release_sa_handle(hdl
, db
, FTAG
);
2130 error
= zfs_obj_to_path_impl(osp
, obj
, hdl
, sa_table
, buf
, len
);
2132 zfs_release_sa_handle(hdl
, db
, FTAG
);
2136 #if defined(_KERNEL) && defined(HAVE_SPL)
2137 EXPORT_SYMBOL(zfs_create_fs
);
2138 EXPORT_SYMBOL(zfs_obj_to_path
);
2140 module_param(zfs_object_mutex_size
, uint
, 0644);
2141 MODULE_PARM_DESC(zfs_object_mutex_size
, "Size of znode hold array");