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 * Update the embedded inode given the znode. We should work toward
483 * eliminating this function as soon as possible by removing values
484 * which are duplicated between the znode and inode. If the generic
485 * inode has the correct field it should be used, and the ZFS code
486 * updated to access the inode. This can be done incrementally.
489 zfs_inode_update(znode_t
*zp
)
494 u_longlong_t i_blocks
;
500 /* Skip .zfs control nodes which do not exist on disk. */
501 if (zfsctl_is_node(ip
))
504 dmu_object_size_from_db(sa_get_db(zp
->z_sa_hdl
), &blksize
, &i_blocks
);
506 spin_lock(&ip
->i_lock
);
507 ip
->i_blocks
= i_blocks
;
508 i_size_write(ip
, zp
->z_size
);
509 spin_unlock(&ip
->i_lock
);
514 * Construct a znode+inode and initialize.
516 * This does not do a call to dmu_set_user() that is
517 * up to the caller to do, in case you don't want to
521 zfs_znode_alloc(zfs_sb_t
*zsb
, dmu_buf_t
*db
, int blksz
,
522 dmu_object_type_t obj_type
, uint64_t obj
, sa_handle_t
*hdl
)
530 uint64_t z_uid
, z_gid
;
531 uint64_t atime
[2], mtime
[2], ctime
[2];
532 sa_bulk_attr_t bulk
[11];
537 ip
= new_inode(zsb
->z_sb
);
542 ASSERT(zp
->z_dirlocks
== NULL
);
543 ASSERT3P(zp
->z_acl_cached
, ==, NULL
);
544 ASSERT3P(zp
->z_xattr_cached
, ==, NULL
);
548 zp
->z_atime_dirty
= 0;
550 zp
->z_id
= db
->db_object
;
552 zp
->z_seq
= 0x7A4653;
554 zp
->z_is_mapped
= B_FALSE
;
555 zp
->z_is_ctldir
= B_FALSE
;
556 zp
->z_is_stale
= B_FALSE
;
557 zp
->z_range_lock
.zr_size
= &zp
->z_size
;
558 zp
->z_range_lock
.zr_blksz
= &zp
->z_blksz
;
559 zp
->z_range_lock
.zr_max_blksz
= &ZTOZSB(zp
)->z_max_blksz
;
561 zfs_znode_sa_init(zsb
, zp
, db
, obj_type
, hdl
);
563 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zsb
), NULL
, &mode
, 8);
564 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GEN(zsb
), NULL
, &tmp_gen
, 8);
565 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zsb
), NULL
, &zp
->z_size
, 8);
566 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_LINKS(zsb
), NULL
, &links
, 8);
567 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
), NULL
,
569 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_PARENT(zsb
), NULL
,
571 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_UID(zsb
), NULL
, &z_uid
, 8);
572 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GID(zsb
), NULL
, &z_gid
, 8);
573 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_ATIME(zsb
), NULL
, &atime
, 16);
574 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zsb
), NULL
, &mtime
, 16);
575 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zsb
), NULL
, &ctime
, 16);
577 if (sa_bulk_lookup(zp
->z_sa_hdl
, bulk
, count
) != 0 ||
581 sa_handle_destroy(zp
->z_sa_hdl
);
586 zp
->z_mode
= ip
->i_mode
= mode
;
587 ip
->i_generation
= (uint32_t)tmp_gen
;
588 ip
->i_blkbits
= SPA_MINBLOCKSHIFT
;
589 set_nlink(ip
, (uint32_t)links
);
590 zfs_uid_write(ip
, z_uid
);
591 zfs_gid_write(ip
, z_gid
);
593 ZFS_TIME_DECODE(&ip
->i_atime
, atime
);
594 ZFS_TIME_DECODE(&ip
->i_mtime
, mtime
);
595 ZFS_TIME_DECODE(&ip
->i_ctime
, ctime
);
598 zfs_inode_update(zp
);
599 zfs_inode_set_ops(zsb
, ip
);
602 * The only way insert_inode_locked() can fail is if the ip->i_ino
603 * number is already hashed for this super block. This can never
604 * happen because the inode numbers map 1:1 with the object numbers.
606 * The one exception is rolling back a mounted file system, but in
607 * this case all the active inode are unhashed during the rollback.
609 VERIFY3S(insert_inode_locked(ip
), ==, 0);
611 mutex_enter(&zsb
->z_znodes_lock
);
612 list_insert_tail(&zsb
->z_all_znodes
, zp
);
615 mutex_exit(&zsb
->z_znodes_lock
);
617 unlock_new_inode(ip
);
626 * Safely mark an inode dirty. Inodes which are part of a read-only
627 * file system or snapshot may not be dirtied.
630 zfs_mark_inode_dirty(struct inode
*ip
)
632 zfs_sb_t
*zsb
= ITOZSB(ip
);
634 if (zfs_is_readonly(zsb
) || dmu_objset_is_snapshot(zsb
->z_os
))
637 mark_inode_dirty(ip
);
640 static uint64_t empty_xattr
;
641 static uint64_t pad
[4];
642 static zfs_acl_phys_t acl_phys
;
644 * Create a new DMU object to hold a zfs znode.
646 * IN: dzp - parent directory for new znode
647 * vap - file attributes for new znode
648 * tx - dmu transaction id for zap operations
649 * cr - credentials of caller
651 * IS_ROOT_NODE - new object will be root
652 * IS_XATTR - new object is an attribute
653 * bonuslen - length of bonus buffer
654 * setaclp - File/Dir initial ACL
655 * fuidp - Tracks fuid allocation.
657 * OUT: zpp - allocated znode
661 zfs_mknode(znode_t
*dzp
, vattr_t
*vap
, dmu_tx_t
*tx
, cred_t
*cr
,
662 uint_t flag
, znode_t
**zpp
, zfs_acl_ids_t
*acl_ids
)
664 uint64_t crtime
[2], atime
[2], mtime
[2], ctime
[2];
665 uint64_t mode
, size
, links
, parent
, pflags
;
666 uint64_t dzp_pflags
= 0;
668 zfs_sb_t
*zsb
= ZTOZSB(dzp
);
675 dmu_object_type_t obj_type
;
676 sa_bulk_attr_t
*sa_attrs
;
678 zfs_acl_locator_cb_t locate
= { 0 };
682 obj
= vap
->va_nodeid
;
683 now
= vap
->va_ctime
; /* see zfs_replay_create() */
684 gen
= vap
->va_nblocks
; /* ditto */
685 dnodesize
= vap
->va_fsid
; /* ditto */
689 gen
= dmu_tx_get_txg(tx
);
690 dnodesize
= dmu_objset_dnodesize(zsb
->z_os
);
694 dnodesize
= DNODE_MIN_SIZE
;
696 obj_type
= zsb
->z_use_sa
? DMU_OT_SA
: DMU_OT_ZNODE
;
698 bonuslen
= (obj_type
== DMU_OT_SA
) ?
699 DN_BONUS_SIZE(dnodesize
) : ZFS_OLD_ZNODE_PHYS_SIZE
;
702 * Create a new DMU object.
705 * There's currently no mechanism for pre-reading the blocks that will
706 * be needed to allocate a new object, so we accept the small chance
707 * that there will be an i/o error and we will fail one of the
710 if (S_ISDIR(vap
->va_mode
)) {
712 VERIFY0(zap_create_claim_norm_dnsize(zsb
->z_os
, obj
,
713 zsb
->z_norm
, DMU_OT_DIRECTORY_CONTENTS
,
714 obj_type
, bonuslen
, dnodesize
, tx
));
716 obj
= zap_create_norm_dnsize(zsb
->z_os
,
717 zsb
->z_norm
, DMU_OT_DIRECTORY_CONTENTS
,
718 obj_type
, bonuslen
, dnodesize
, tx
);
722 VERIFY0(dmu_object_claim_dnsize(zsb
->z_os
, obj
,
723 DMU_OT_PLAIN_FILE_CONTENTS
, 0,
724 obj_type
, bonuslen
, dnodesize
, tx
));
726 obj
= dmu_object_alloc_dnsize(zsb
->z_os
,
727 DMU_OT_PLAIN_FILE_CONTENTS
, 0,
728 obj_type
, bonuslen
, dnodesize
, tx
);
732 zh
= zfs_znode_hold_enter(zsb
, obj
);
733 VERIFY(0 == sa_buf_hold(zsb
->z_os
, obj
, NULL
, &db
));
736 * If this is the root, fix up the half-initialized parent pointer
737 * to reference the just-allocated physical data area.
739 if (flag
& IS_ROOT_NODE
) {
742 dzp_pflags
= dzp
->z_pflags
;
746 * If parent is an xattr, so am I.
748 if (dzp_pflags
& ZFS_XATTR
) {
752 if (zsb
->z_use_fuids
)
753 pflags
= ZFS_ARCHIVE
| ZFS_AV_MODIFIED
;
757 if (S_ISDIR(vap
->va_mode
)) {
758 size
= 2; /* contents ("." and "..") */
765 if (S_ISBLK(vap
->va_mode
) || S_ISCHR(vap
->va_mode
))
769 mode
= acl_ids
->z_mode
;
774 * No execs denied will be deterimed when zfs_mode_compute() is called.
776 pflags
|= acl_ids
->z_aclp
->z_hints
&
777 (ZFS_ACL_TRIVIAL
|ZFS_INHERIT_ACE
|ZFS_ACL_AUTO_INHERIT
|
778 ZFS_ACL_DEFAULTED
|ZFS_ACL_PROTECTED
);
780 ZFS_TIME_ENCODE(&now
, crtime
);
781 ZFS_TIME_ENCODE(&now
, ctime
);
783 if (vap
->va_mask
& ATTR_ATIME
) {
784 ZFS_TIME_ENCODE(&vap
->va_atime
, atime
);
786 ZFS_TIME_ENCODE(&now
, atime
);
789 if (vap
->va_mask
& ATTR_MTIME
) {
790 ZFS_TIME_ENCODE(&vap
->va_mtime
, mtime
);
792 ZFS_TIME_ENCODE(&now
, mtime
);
795 /* Now add in all of the "SA" attributes */
796 VERIFY(0 == sa_handle_get_from_db(zsb
->z_os
, db
, NULL
, SA_HDL_SHARED
,
800 * Setup the array of attributes to be replaced/set on the new file
802 * order for DMU_OT_ZNODE is critical since it needs to be constructed
803 * in the old znode_phys_t format. Don't change this ordering
805 sa_attrs
= kmem_alloc(sizeof (sa_bulk_attr_t
) * ZPL_END
, KM_SLEEP
);
807 if (obj_type
== DMU_OT_ZNODE
) {
808 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ATIME(zsb
),
810 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MTIME(zsb
),
812 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CTIME(zsb
),
814 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CRTIME(zsb
),
816 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GEN(zsb
),
818 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MODE(zsb
),
820 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_SIZE(zsb
),
822 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PARENT(zsb
),
825 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MODE(zsb
),
827 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_SIZE(zsb
),
829 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GEN(zsb
),
831 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_UID(zsb
),
832 NULL
, &acl_ids
->z_fuid
, 8);
833 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GID(zsb
),
834 NULL
, &acl_ids
->z_fgid
, 8);
835 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PARENT(zsb
),
837 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_FLAGS(zsb
),
839 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ATIME(zsb
),
841 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_MTIME(zsb
),
843 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CTIME(zsb
),
845 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_CRTIME(zsb
),
849 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_LINKS(zsb
), NULL
, &links
, 8);
851 if (obj_type
== DMU_OT_ZNODE
) {
852 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_XATTR(zsb
), NULL
,
855 if (obj_type
== DMU_OT_ZNODE
||
856 (S_ISBLK(vap
->va_mode
) || S_ISCHR(vap
->va_mode
))) {
857 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_RDEV(zsb
),
860 if (obj_type
== DMU_OT_ZNODE
) {
861 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_FLAGS(zsb
),
863 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_UID(zsb
), NULL
,
864 &acl_ids
->z_fuid
, 8);
865 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_GID(zsb
), NULL
,
866 &acl_ids
->z_fgid
, 8);
867 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_PAD(zsb
), NULL
, pad
,
868 sizeof (uint64_t) * 4);
869 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_ZNODE_ACL(zsb
), NULL
,
870 &acl_phys
, sizeof (zfs_acl_phys_t
));
871 } else if (acl_ids
->z_aclp
->z_version
>= ZFS_ACL_VERSION_FUID
) {
872 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_DACL_COUNT(zsb
), NULL
,
873 &acl_ids
->z_aclp
->z_acl_count
, 8);
874 locate
.cb_aclp
= acl_ids
->z_aclp
;
875 SA_ADD_BULK_ATTR(sa_attrs
, cnt
, SA_ZPL_DACL_ACES(zsb
),
876 zfs_acl_data_locator
, &locate
,
877 acl_ids
->z_aclp
->z_acl_bytes
);
878 mode
= zfs_mode_compute(mode
, acl_ids
->z_aclp
, &pflags
,
879 acl_ids
->z_fuid
, acl_ids
->z_fgid
);
882 VERIFY(sa_replace_all_by_template(sa_hdl
, sa_attrs
, cnt
, tx
) == 0);
884 if (!(flag
& IS_ROOT_NODE
)) {
885 *zpp
= zfs_znode_alloc(zsb
, db
, 0, obj_type
, obj
, sa_hdl
);
886 VERIFY(*zpp
!= NULL
);
890 * If we are creating the root node, the "parent" we
891 * passed in is the znode for the root.
895 (*zpp
)->z_sa_hdl
= sa_hdl
;
898 (*zpp
)->z_pflags
= pflags
;
899 (*zpp
)->z_mode
= ZTOI(*zpp
)->i_mode
= mode
;
900 (*zpp
)->z_dnodesize
= dnodesize
;
902 if (obj_type
== DMU_OT_ZNODE
||
903 acl_ids
->z_aclp
->z_version
< ZFS_ACL_VERSION_FUID
) {
904 VERIFY0(zfs_aclset_common(*zpp
, acl_ids
->z_aclp
, cr
, tx
));
906 kmem_free(sa_attrs
, sizeof (sa_bulk_attr_t
) * ZPL_END
);
907 zfs_znode_hold_exit(zsb
, zh
);
911 * Update in-core attributes. It is assumed the caller will be doing an
912 * sa_bulk_update to push the changes out.
915 zfs_xvattr_set(znode_t
*zp
, xvattr_t
*xvap
, dmu_tx_t
*tx
)
919 xoap
= xva_getxoptattr(xvap
);
922 if (XVA_ISSET_REQ(xvap
, XAT_CREATETIME
)) {
924 ZFS_TIME_ENCODE(&xoap
->xoa_createtime
, times
);
925 (void) sa_update(zp
->z_sa_hdl
, SA_ZPL_CRTIME(ZTOZSB(zp
)),
926 ×
, sizeof (times
), tx
);
927 XVA_SET_RTN(xvap
, XAT_CREATETIME
);
930 if (XVA_ISSET_REQ(xvap
, XAT_READONLY
)) {
931 ZFS_ATTR_SET(zp
, ZFS_READONLY
, xoap
->xoa_readonly
,
933 XVA_SET_RTN(xvap
, XAT_READONLY
);
935 if (XVA_ISSET_REQ(xvap
, XAT_HIDDEN
)) {
936 ZFS_ATTR_SET(zp
, ZFS_HIDDEN
, xoap
->xoa_hidden
,
938 XVA_SET_RTN(xvap
, XAT_HIDDEN
);
940 if (XVA_ISSET_REQ(xvap
, XAT_SYSTEM
)) {
941 ZFS_ATTR_SET(zp
, ZFS_SYSTEM
, xoap
->xoa_system
,
943 XVA_SET_RTN(xvap
, XAT_SYSTEM
);
945 if (XVA_ISSET_REQ(xvap
, XAT_ARCHIVE
)) {
946 ZFS_ATTR_SET(zp
, ZFS_ARCHIVE
, xoap
->xoa_archive
,
948 XVA_SET_RTN(xvap
, XAT_ARCHIVE
);
950 if (XVA_ISSET_REQ(xvap
, XAT_IMMUTABLE
)) {
951 ZFS_ATTR_SET(zp
, ZFS_IMMUTABLE
, xoap
->xoa_immutable
,
953 XVA_SET_RTN(xvap
, XAT_IMMUTABLE
);
955 ZTOI(zp
)->i_flags
|= S_IMMUTABLE
;
957 ZTOI(zp
)->i_flags
&= ~S_IMMUTABLE
;
960 if (XVA_ISSET_REQ(xvap
, XAT_NOUNLINK
)) {
961 ZFS_ATTR_SET(zp
, ZFS_NOUNLINK
, xoap
->xoa_nounlink
,
963 XVA_SET_RTN(xvap
, XAT_NOUNLINK
);
965 if (XVA_ISSET_REQ(xvap
, XAT_APPENDONLY
)) {
966 ZFS_ATTR_SET(zp
, ZFS_APPENDONLY
, xoap
->xoa_appendonly
,
968 XVA_SET_RTN(xvap
, XAT_APPENDONLY
);
970 ZTOI(zp
)->i_flags
|= S_APPEND
;
973 ZTOI(zp
)->i_flags
&= ~S_APPEND
;
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
;
1127 sa_bulk_attr_t bulk
[10];
1131 uint64_t z_uid
, z_gid
;
1132 uint64_t atime
[2], mtime
[2], ctime
[2];
1136 * skip ctldir, otherwise they will always get invalidated. This will
1137 * cause funny behaviour for the mounted snapdirs. Especially for
1138 * Linux >= 3.18, d_invalidate will detach the mountpoint and prevent
1139 * anyone automount it again as long as someone is still using the
1142 if (zp
->z_is_ctldir
)
1145 zh
= zfs_znode_hold_enter(zsb
, obj_num
);
1147 mutex_enter(&zp
->z_acl_lock
);
1148 if (zp
->z_acl_cached
) {
1149 zfs_acl_free(zp
->z_acl_cached
);
1150 zp
->z_acl_cached
= NULL
;
1152 mutex_exit(&zp
->z_acl_lock
);
1154 rw_enter(&zp
->z_xattr_lock
, RW_WRITER
);
1155 if (zp
->z_xattr_cached
) {
1156 nvlist_free(zp
->z_xattr_cached
);
1157 zp
->z_xattr_cached
= NULL
;
1159 rw_exit(&zp
->z_xattr_lock
);
1161 ASSERT(zp
->z_sa_hdl
== NULL
);
1162 err
= sa_buf_hold(zsb
->z_os
, obj_num
, NULL
, &db
);
1164 zfs_znode_hold_exit(zsb
, zh
);
1168 dmu_object_info_from_db(db
, &doi
);
1169 if (doi
.doi_bonus_type
!= DMU_OT_SA
&&
1170 (doi
.doi_bonus_type
!= DMU_OT_ZNODE
||
1171 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1172 doi
.doi_bonus_size
< sizeof (znode_phys_t
)))) {
1173 sa_buf_rele(db
, NULL
);
1174 zfs_znode_hold_exit(zsb
, zh
);
1175 return (SET_ERROR(EINVAL
));
1178 zfs_znode_sa_init(zsb
, zp
, db
, doi
.doi_bonus_type
, NULL
);
1180 /* reload cached values */
1181 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GEN(zsb
), NULL
,
1182 &gen
, sizeof (gen
));
1183 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zsb
), NULL
,
1184 &zp
->z_size
, sizeof (zp
->z_size
));
1185 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_LINKS(zsb
), NULL
,
1186 &links
, sizeof (links
));
1187 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
), NULL
,
1188 &zp
->z_pflags
, sizeof (zp
->z_pflags
));
1189 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_UID(zsb
), NULL
,
1190 &z_uid
, sizeof (z_uid
));
1191 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GID(zsb
), NULL
,
1192 &z_gid
, sizeof (z_gid
));
1193 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zsb
), NULL
,
1194 &mode
, sizeof (mode
));
1195 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_ATIME(zsb
), NULL
,
1197 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zsb
), NULL
,
1199 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zsb
), NULL
,
1202 if (sa_bulk_lookup(zp
->z_sa_hdl
, bulk
, count
)) {
1203 zfs_znode_dmu_fini(zp
);
1204 zfs_znode_hold_exit(zsb
, zh
);
1205 return (SET_ERROR(EIO
));
1208 zp
->z_mode
= ZTOI(zp
)->i_mode
= mode
;
1209 zfs_uid_write(ZTOI(zp
), z_uid
);
1210 zfs_gid_write(ZTOI(zp
), z_gid
);
1212 ZFS_TIME_DECODE(&ZTOI(zp
)->i_atime
, atime
);
1213 ZFS_TIME_DECODE(&ZTOI(zp
)->i_mtime
, mtime
);
1214 ZFS_TIME_DECODE(&ZTOI(zp
)->i_ctime
, ctime
);
1216 if (gen
!= ZTOI(zp
)->i_generation
) {
1217 zfs_znode_dmu_fini(zp
);
1218 zfs_znode_hold_exit(zsb
, zh
);
1219 return (SET_ERROR(EIO
));
1222 zp
->z_unlinked
= (ZTOI(zp
)->i_nlink
== 0);
1223 set_nlink(ZTOI(zp
), (uint32_t)links
);
1225 zp
->z_blksz
= doi
.doi_data_block_size
;
1226 zp
->z_atime_dirty
= 0;
1227 zfs_inode_update(zp
);
1230 zfs_znode_hold_exit(zsb
, zh
);
1236 zfs_znode_delete(znode_t
*zp
, dmu_tx_t
*tx
)
1238 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1239 objset_t
*os
= zsb
->z_os
;
1240 uint64_t obj
= zp
->z_id
;
1241 uint64_t acl_obj
= zfs_external_acl(zp
);
1244 zh
= zfs_znode_hold_enter(zsb
, obj
);
1246 VERIFY(!zp
->z_is_sa
);
1247 VERIFY(0 == dmu_object_free(os
, acl_obj
, tx
));
1249 VERIFY(0 == dmu_object_free(os
, obj
, tx
));
1250 zfs_znode_dmu_fini(zp
);
1251 zfs_znode_hold_exit(zsb
, zh
);
1255 zfs_zinactive(znode_t
*zp
)
1257 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1258 uint64_t z_id
= zp
->z_id
;
1261 ASSERT(zp
->z_sa_hdl
);
1264 * Don't allow a zfs_zget() while were trying to release this znode.
1266 zh
= zfs_znode_hold_enter(zsb
, z_id
);
1268 mutex_enter(&zp
->z_lock
);
1271 * If this was the last reference to a file with no links,
1272 * remove the file from the file system.
1274 if (zp
->z_unlinked
) {
1275 mutex_exit(&zp
->z_lock
);
1276 zfs_znode_hold_exit(zsb
, zh
);
1281 mutex_exit(&zp
->z_lock
);
1282 zfs_znode_dmu_fini(zp
);
1284 zfs_znode_hold_exit(zsb
, zh
);
1288 zfs_compare_timespec(struct timespec
*t1
, struct timespec
*t2
)
1290 if (t1
->tv_sec
< t2
->tv_sec
)
1293 if (t1
->tv_sec
> t2
->tv_sec
)
1296 return (t1
->tv_nsec
- t2
->tv_nsec
);
1300 * Prepare to update znode time stamps.
1302 * IN: zp - znode requiring timestamp update
1303 * flag - ATTR_MTIME, ATTR_CTIME flags
1309 * Note: We don't update atime here, because we rely on Linux VFS to do
1313 zfs_tstamp_update_setup(znode_t
*zp
, uint_t flag
, uint64_t mtime
[2],
1322 if (flag
& ATTR_MTIME
) {
1323 ZFS_TIME_ENCODE(&now
, mtime
);
1324 ZFS_TIME_DECODE(&(ZTOI(zp
)->i_mtime
), mtime
);
1325 if (ZTOZSB(zp
)->z_use_fuids
) {
1326 zp
->z_pflags
|= (ZFS_ARCHIVE
|
1331 if (flag
& ATTR_CTIME
) {
1332 ZFS_TIME_ENCODE(&now
, ctime
);
1333 ZFS_TIME_DECODE(&(ZTOI(zp
)->i_ctime
), ctime
);
1334 if (ZTOZSB(zp
)->z_use_fuids
)
1335 zp
->z_pflags
|= ZFS_ARCHIVE
;
1340 * Grow the block size for a file.
1342 * IN: zp - znode of file to free data in.
1343 * size - requested block size
1344 * tx - open transaction.
1346 * NOTE: this function assumes that the znode is write locked.
1349 zfs_grow_blocksize(znode_t
*zp
, uint64_t size
, dmu_tx_t
*tx
)
1354 if (size
<= zp
->z_blksz
)
1357 * If the file size is already greater than the current blocksize,
1358 * we will not grow. If there is more than one block in a file,
1359 * the blocksize cannot change.
1361 if (zp
->z_blksz
&& zp
->z_size
> zp
->z_blksz
)
1364 error
= dmu_object_set_blocksize(ZTOZSB(zp
)->z_os
, zp
->z_id
,
1367 if (error
== ENOTSUP
)
1371 /* What blocksize did we actually get? */
1372 dmu_object_size_from_db(sa_get_db(zp
->z_sa_hdl
), &zp
->z_blksz
, &dummy
);
1376 * Increase the file length
1378 * IN: zp - znode of file to free data in.
1379 * end - new end-of-file
1381 * RETURN: 0 on success, error code on failure
1384 zfs_extend(znode_t
*zp
, uint64_t end
)
1386 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1393 * We will change zp_size, lock the whole file.
1395 rl
= zfs_range_lock(&zp
->z_range_lock
, 0, UINT64_MAX
, RL_WRITER
);
1398 * Nothing to do if file already at desired length.
1400 if (end
<= zp
->z_size
) {
1401 zfs_range_unlock(rl
);
1404 tx
= dmu_tx_create(zsb
->z_os
);
1405 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1406 zfs_sa_upgrade_txholds(tx
, zp
);
1407 if (end
> zp
->z_blksz
&&
1408 (!ISP2(zp
->z_blksz
) || zp
->z_blksz
< zsb
->z_max_blksz
)) {
1410 * We are growing the file past the current block size.
1412 if (zp
->z_blksz
> ZTOZSB(zp
)->z_max_blksz
) {
1414 * File's blocksize is already larger than the
1415 * "recordsize" property. Only let it grow to
1416 * the next power of 2.
1418 ASSERT(!ISP2(zp
->z_blksz
));
1419 newblksz
= MIN(end
, 1 << highbit64(zp
->z_blksz
));
1421 newblksz
= MIN(end
, ZTOZSB(zp
)->z_max_blksz
);
1423 dmu_tx_hold_write(tx
, zp
->z_id
, 0, newblksz
);
1428 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1431 zfs_range_unlock(rl
);
1436 zfs_grow_blocksize(zp
, newblksz
, tx
);
1440 VERIFY(0 == sa_update(zp
->z_sa_hdl
, SA_ZPL_SIZE(ZTOZSB(zp
)),
1441 &zp
->z_size
, sizeof (zp
->z_size
), tx
));
1443 zfs_range_unlock(rl
);
1451 * zfs_zero_partial_page - Modeled after update_pages() but
1452 * with different arguments and semantics for use by zfs_freesp().
1454 * Zeroes a piece of a single page cache entry for zp at offset
1455 * start and length len.
1457 * Caller must acquire a range lock on the file for the region
1458 * being zeroed in order that the ARC and page cache stay in sync.
1461 zfs_zero_partial_page(znode_t
*zp
, uint64_t start
, uint64_t len
)
1463 struct address_space
*mp
= ZTOI(zp
)->i_mapping
;
1468 ASSERT((start
& PAGE_MASK
) == ((start
+ len
- 1) & PAGE_MASK
));
1470 off
= start
& (PAGE_SIZE
- 1);
1473 pp
= find_lock_page(mp
, start
>> PAGE_SHIFT
);
1475 if (mapping_writably_mapped(mp
))
1476 flush_dcache_page(pp
);
1479 bzero(pb
+ off
, len
);
1482 if (mapping_writably_mapped(mp
))
1483 flush_dcache_page(pp
);
1485 mark_page_accessed(pp
);
1486 SetPageUptodate(pp
);
1494 * Free space in a file.
1496 * IN: zp - znode of file to free data in.
1497 * off - start of section to free.
1498 * len - length of section to free.
1500 * RETURN: 0 on success, error code on failure
1503 zfs_free_range(znode_t
*zp
, uint64_t off
, uint64_t len
)
1505 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1510 * Lock the range being freed.
1512 rl
= zfs_range_lock(&zp
->z_range_lock
, off
, len
, RL_WRITER
);
1515 * Nothing to do if file already at desired length.
1517 if (off
>= zp
->z_size
) {
1518 zfs_range_unlock(rl
);
1522 if (off
+ len
> zp
->z_size
)
1523 len
= zp
->z_size
- off
;
1525 error
= dmu_free_long_range(zsb
->z_os
, zp
->z_id
, off
, len
);
1528 * Zero partial page cache entries. This must be done under a
1529 * range lock in order to keep the ARC and page cache in sync.
1531 if (zp
->z_is_mapped
) {
1532 loff_t first_page
, last_page
, page_len
;
1533 loff_t first_page_offset
, last_page_offset
;
1535 /* first possible full page in hole */
1536 first_page
= (off
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
1537 /* last page of hole */
1538 last_page
= (off
+ len
) >> PAGE_SHIFT
;
1540 /* offset of first_page */
1541 first_page_offset
= first_page
<< PAGE_SHIFT
;
1542 /* offset of last_page */
1543 last_page_offset
= last_page
<< PAGE_SHIFT
;
1545 /* truncate whole pages */
1546 if (last_page_offset
> first_page_offset
) {
1547 truncate_inode_pages_range(ZTOI(zp
)->i_mapping
,
1548 first_page_offset
, last_page_offset
- 1);
1551 /* truncate sub-page ranges */
1552 if (first_page
> last_page
) {
1553 /* entire punched area within a single page */
1554 zfs_zero_partial_page(zp
, off
, len
);
1556 /* beginning of punched area at the end of a page */
1557 page_len
= first_page_offset
- off
;
1559 zfs_zero_partial_page(zp
, off
, page_len
);
1561 /* end of punched area at the beginning of a page */
1562 page_len
= off
+ len
- last_page_offset
;
1564 zfs_zero_partial_page(zp
, last_page_offset
,
1568 zfs_range_unlock(rl
);
1576 * IN: zp - znode of file to free data in.
1577 * end - new end-of-file.
1579 * RETURN: 0 on success, error code on failure
1582 zfs_trunc(znode_t
*zp
, uint64_t end
)
1584 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1588 sa_bulk_attr_t bulk
[2];
1592 * We will change zp_size, lock the whole file.
1594 rl
= zfs_range_lock(&zp
->z_range_lock
, 0, UINT64_MAX
, RL_WRITER
);
1597 * Nothing to do if file already at desired length.
1599 if (end
>= zp
->z_size
) {
1600 zfs_range_unlock(rl
);
1604 error
= dmu_free_long_range(zsb
->z_os
, zp
->z_id
, end
, -1);
1606 zfs_range_unlock(rl
);
1609 tx
= dmu_tx_create(zsb
->z_os
);
1610 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1611 zfs_sa_upgrade_txholds(tx
, zp
);
1612 dmu_tx_mark_netfree(tx
);
1613 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1616 zfs_range_unlock(rl
);
1621 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_SIZE(zsb
),
1622 NULL
, &zp
->z_size
, sizeof (zp
->z_size
));
1625 zp
->z_pflags
&= ~ZFS_SPARSE
;
1626 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
),
1627 NULL
, &zp
->z_pflags
, 8);
1629 VERIFY(sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
) == 0);
1633 zfs_range_unlock(rl
);
1639 * Free space in a file
1641 * IN: zp - znode of file to free data in.
1642 * off - start of range
1643 * len - end of range (0 => EOF)
1644 * flag - current file open mode flags.
1645 * log - TRUE if this action should be logged
1647 * RETURN: 0 on success, error code on failure
1650 zfs_freesp(znode_t
*zp
, uint64_t off
, uint64_t len
, int flag
, boolean_t log
)
1653 zfs_sb_t
*zsb
= ZTOZSB(zp
);
1654 zilog_t
*zilog
= zsb
->z_log
;
1656 uint64_t mtime
[2], ctime
[2];
1657 sa_bulk_attr_t bulk
[3];
1661 if ((error
= sa_lookup(zp
->z_sa_hdl
, SA_ZPL_MODE(zsb
), &mode
,
1662 sizeof (mode
))) != 0)
1665 if (off
> zp
->z_size
) {
1666 error
= zfs_extend(zp
, off
+len
);
1667 if (error
== 0 && log
)
1673 error
= zfs_trunc(zp
, off
);
1675 if ((error
= zfs_free_range(zp
, off
, len
)) == 0 &&
1676 off
+ len
> zp
->z_size
)
1677 error
= zfs_extend(zp
, off
+len
);
1682 tx
= dmu_tx_create(zsb
->z_os
);
1683 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1684 zfs_sa_upgrade_txholds(tx
, zp
);
1685 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1691 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zsb
), NULL
, mtime
, 16);
1692 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zsb
), NULL
, ctime
, 16);
1693 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zsb
),
1694 NULL
, &zp
->z_pflags
, 8);
1695 zfs_tstamp_update_setup(zp
, CONTENT_MODIFIED
, mtime
, ctime
);
1696 error
= sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
);
1699 zfs_log_truncate(zilog
, tx
, TX_TRUNCATE
, zp
, off
, len
);
1703 zfs_inode_update(zp
);
1708 * Truncate the page cache - for file truncate operations, use
1709 * the purpose-built API for truncations. For punching operations,
1710 * the truncation is handled under a range lock in zfs_free_range.
1713 truncate_setsize(ZTOI(zp
), off
);
1718 zfs_create_fs(objset_t
*os
, cred_t
*cr
, nvlist_t
*zplprops
, dmu_tx_t
*tx
)
1720 struct super_block
*sb
;
1722 uint64_t moid
, obj
, sa_obj
, version
;
1723 uint64_t sense
= ZFS_CASE_SENSITIVE
;
1729 znode_t
*rootzp
= NULL
;
1732 zfs_acl_ids_t acl_ids
;
1735 * First attempt to create master node.
1738 * In an empty objset, there are no blocks to read and thus
1739 * there can be no i/o errors (which we assert below).
1741 moid
= MASTER_NODE_OBJ
;
1742 error
= zap_create_claim(os
, moid
, DMU_OT_MASTER_NODE
,
1743 DMU_OT_NONE
, 0, tx
);
1747 * Give dmu_object_alloc() a hint about where to start
1748 * allocating new objects. Otherwise, since the metadnode's
1749 * dnode_phys_t structure isn't initialized yet, dmu_object_next()
1750 * would fail and we'd have to skip to the next dnode block.
1752 os
->os_obj_next
= moid
+ 1;
1755 * Set starting attributes.
1757 version
= zfs_zpl_version_map(spa_version(dmu_objset_spa(os
)));
1759 while ((elem
= nvlist_next_nvpair(zplprops
, elem
)) != NULL
) {
1760 /* For the moment we expect all zpl props to be uint64_ts */
1764 ASSERT(nvpair_type(elem
) == DATA_TYPE_UINT64
);
1765 VERIFY(nvpair_value_uint64(elem
, &val
) == 0);
1766 name
= nvpair_name(elem
);
1767 if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_VERSION
)) == 0) {
1771 error
= zap_update(os
, moid
, name
, 8, 1, &val
, tx
);
1774 if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_NORMALIZE
)) == 0)
1776 else if (strcmp(name
, zfs_prop_to_name(ZFS_PROP_CASE
)) == 0)
1779 ASSERT(version
!= 0);
1780 error
= zap_update(os
, moid
, ZPL_VERSION_STR
, 8, 1, &version
, tx
);
1783 * Create zap object used for SA attribute registration
1786 if (version
>= ZPL_VERSION_SA
) {
1787 sa_obj
= zap_create(os
, DMU_OT_SA_MASTER_NODE
,
1788 DMU_OT_NONE
, 0, tx
);
1789 error
= zap_add(os
, moid
, ZFS_SA_ATTRS
, 8, 1, &sa_obj
, tx
);
1795 * Create a delete queue.
1797 obj
= zap_create(os
, DMU_OT_UNLINKED_SET
, DMU_OT_NONE
, 0, tx
);
1799 error
= zap_add(os
, moid
, ZFS_UNLINKED_SET
, 8, 1, &obj
, tx
);
1803 * Create root znode. Create minimal znode/inode/zsb/sb
1804 * to allow zfs_mknode to work.
1806 vattr
.va_mask
= ATTR_MODE
|ATTR_UID
|ATTR_GID
;
1807 vattr
.va_mode
= S_IFDIR
|0755;
1808 vattr
.va_uid
= crgetuid(cr
);
1809 vattr
.va_gid
= crgetgid(cr
);
1811 rootzp
= kmem_cache_alloc(znode_cache
, KM_SLEEP
);
1812 rootzp
->z_moved
= 0;
1813 rootzp
->z_unlinked
= 0;
1814 rootzp
->z_atime_dirty
= 0;
1815 rootzp
->z_is_sa
= USE_SA(version
, os
);
1817 zsb
= kmem_zalloc(sizeof (zfs_sb_t
), KM_SLEEP
);
1819 zsb
->z_parent
= zsb
;
1820 zsb
->z_version
= version
;
1821 zsb
->z_use_fuids
= USE_FUIDS(version
, os
);
1822 zsb
->z_use_sa
= USE_SA(version
, os
);
1825 sb
= kmem_zalloc(sizeof (struct super_block
), KM_SLEEP
);
1826 sb
->s_fs_info
= zsb
;
1828 ZTOI(rootzp
)->i_sb
= sb
;
1830 error
= sa_setup(os
, sa_obj
, zfs_attr_table
, ZPL_END
,
1831 &zsb
->z_attr_table
);
1836 * Fold case on file systems that are always or sometimes case
1839 if (sense
== ZFS_CASE_INSENSITIVE
|| sense
== ZFS_CASE_MIXED
)
1840 zsb
->z_norm
|= U8_TEXTPREP_TOUPPER
;
1842 mutex_init(&zsb
->z_znodes_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
1843 list_create(&zsb
->z_all_znodes
, sizeof (znode_t
),
1844 offsetof(znode_t
, z_link_node
));
1846 size
= MIN(1 << (highbit64(zfs_object_mutex_size
)-1), ZFS_OBJ_MTX_MAX
);
1847 zsb
->z_hold_size
= size
;
1848 zsb
->z_hold_trees
= vmem_zalloc(sizeof (avl_tree_t
) * size
, KM_SLEEP
);
1849 zsb
->z_hold_locks
= vmem_zalloc(sizeof (kmutex_t
) * size
, KM_SLEEP
);
1850 for (i
= 0; i
!= size
; i
++) {
1851 avl_create(&zsb
->z_hold_trees
[i
], zfs_znode_hold_compare
,
1852 sizeof (znode_hold_t
), offsetof(znode_hold_t
, zh_node
));
1853 mutex_init(&zsb
->z_hold_locks
[i
], NULL
, MUTEX_DEFAULT
, NULL
);
1856 VERIFY(0 == zfs_acl_ids_create(rootzp
, IS_ROOT_NODE
, &vattr
,
1857 cr
, NULL
, &acl_ids
));
1858 zfs_mknode(rootzp
, &vattr
, tx
, cr
, IS_ROOT_NODE
, &zp
, &acl_ids
);
1859 ASSERT3P(zp
, ==, rootzp
);
1860 error
= zap_add(os
, moid
, ZFS_ROOT_OBJ
, 8, 1, &rootzp
->z_id
, tx
);
1862 zfs_acl_ids_free(&acl_ids
);
1864 atomic_set(&ZTOI(rootzp
)->i_count
, 0);
1865 sa_handle_destroy(rootzp
->z_sa_hdl
);
1866 kmem_cache_free(znode_cache
, rootzp
);
1869 * Create shares directory
1871 error
= zfs_create_share_dir(zsb
, tx
);
1874 for (i
= 0; i
!= size
; i
++) {
1875 avl_destroy(&zsb
->z_hold_trees
[i
]);
1876 mutex_destroy(&zsb
->z_hold_locks
[i
]);
1879 vmem_free(zsb
->z_hold_trees
, sizeof (avl_tree_t
) * size
);
1880 vmem_free(zsb
->z_hold_locks
, sizeof (kmutex_t
) * size
);
1881 kmem_free(sb
, sizeof (struct super_block
));
1882 kmem_free(zsb
, sizeof (zfs_sb_t
));
1884 #endif /* _KERNEL */
1887 zfs_sa_setup(objset_t
*osp
, sa_attr_type_t
**sa_table
)
1889 uint64_t sa_obj
= 0;
1892 error
= zap_lookup(osp
, MASTER_NODE_OBJ
, ZFS_SA_ATTRS
, 8, 1, &sa_obj
);
1893 if (error
!= 0 && error
!= ENOENT
)
1896 error
= sa_setup(osp
, sa_obj
, zfs_attr_table
, ZPL_END
, sa_table
);
1901 zfs_grab_sa_handle(objset_t
*osp
, uint64_t obj
, sa_handle_t
**hdlp
,
1902 dmu_buf_t
**db
, void *tag
)
1904 dmu_object_info_t doi
;
1907 if ((error
= sa_buf_hold(osp
, obj
, tag
, db
)) != 0)
1910 dmu_object_info_from_db(*db
, &doi
);
1911 if ((doi
.doi_bonus_type
!= DMU_OT_SA
&&
1912 doi
.doi_bonus_type
!= DMU_OT_ZNODE
) ||
1913 (doi
.doi_bonus_type
== DMU_OT_ZNODE
&&
1914 doi
.doi_bonus_size
< sizeof (znode_phys_t
))) {
1915 sa_buf_rele(*db
, tag
);
1916 return (SET_ERROR(ENOTSUP
));
1919 error
= sa_handle_get(osp
, obj
, NULL
, SA_HDL_PRIVATE
, hdlp
);
1921 sa_buf_rele(*db
, tag
);
1929 zfs_release_sa_handle(sa_handle_t
*hdl
, dmu_buf_t
*db
, void *tag
)
1931 sa_handle_destroy(hdl
);
1932 sa_buf_rele(db
, tag
);
1936 * Given an object number, return its parent object number and whether
1937 * or not the object is an extended attribute directory.
1940 zfs_obj_to_pobj(objset_t
*osp
, sa_handle_t
*hdl
, sa_attr_type_t
*sa_table
,
1941 uint64_t *pobjp
, int *is_xattrdir
)
1946 uint64_t parent_mode
;
1947 sa_bulk_attr_t bulk
[3];
1948 sa_handle_t
*sa_hdl
;
1953 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_PARENT
], NULL
,
1954 &parent
, sizeof (parent
));
1955 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_FLAGS
], NULL
,
1956 &pflags
, sizeof (pflags
));
1957 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_MODE
], NULL
,
1958 &mode
, sizeof (mode
));
1960 if ((error
= sa_bulk_lookup(hdl
, bulk
, count
)) != 0)
1964 * When a link is removed its parent pointer is not changed and will
1965 * be invalid. There are two cases where a link is removed but the
1966 * file stays around, when it goes to the delete queue and when there
1967 * are additional links.
1969 error
= zfs_grab_sa_handle(osp
, parent
, &sa_hdl
, &sa_db
, FTAG
);
1973 error
= sa_lookup(sa_hdl
, ZPL_MODE
, &parent_mode
, sizeof (parent_mode
));
1974 zfs_release_sa_handle(sa_hdl
, sa_db
, FTAG
);
1978 *is_xattrdir
= ((pflags
& ZFS_XATTR
) != 0) && S_ISDIR(mode
);
1981 * Extended attributes can be applied to files, directories, etc.
1982 * Otherwise the parent must be a directory.
1984 if (!*is_xattrdir
&& !S_ISDIR(parent_mode
))
1993 * Given an object number, return some zpl level statistics
1996 zfs_obj_to_stats_impl(sa_handle_t
*hdl
, sa_attr_type_t
*sa_table
,
1999 sa_bulk_attr_t bulk
[4];
2002 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_MODE
], NULL
,
2003 &sb
->zs_mode
, sizeof (sb
->zs_mode
));
2004 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_GEN
], NULL
,
2005 &sb
->zs_gen
, sizeof (sb
->zs_gen
));
2006 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_LINKS
], NULL
,
2007 &sb
->zs_links
, sizeof (sb
->zs_links
));
2008 SA_ADD_BULK_ATTR(bulk
, count
, sa_table
[ZPL_CTIME
], NULL
,
2009 &sb
->zs_ctime
, sizeof (sb
->zs_ctime
));
2011 return (sa_bulk_lookup(hdl
, bulk
, count
));
2015 zfs_obj_to_path_impl(objset_t
*osp
, uint64_t obj
, sa_handle_t
*hdl
,
2016 sa_attr_type_t
*sa_table
, char *buf
, int len
)
2018 sa_handle_t
*sa_hdl
;
2019 sa_handle_t
*prevhdl
= NULL
;
2020 dmu_buf_t
*prevdb
= NULL
;
2021 dmu_buf_t
*sa_db
= NULL
;
2022 char *path
= buf
+ len
- 1;
2030 char component
[MAXNAMELEN
+ 2];
2032 int is_xattrdir
= 0;
2035 zfs_release_sa_handle(prevhdl
, prevdb
, FTAG
);
2037 if ((error
= zfs_obj_to_pobj(osp
, sa_hdl
, sa_table
, &pobj
,
2038 &is_xattrdir
)) != 0)
2049 (void) sprintf(component
+ 1, "<xattrdir>");
2051 error
= zap_value_search(osp
, pobj
, obj
,
2052 ZFS_DIRENT_OBJ(-1ULL), component
+ 1);
2057 complen
= strlen(component
);
2059 ASSERT(path
>= buf
);
2060 bcopy(component
, path
, complen
);
2063 if (sa_hdl
!= hdl
) {
2067 error
= zfs_grab_sa_handle(osp
, obj
, &sa_hdl
, &sa_db
, FTAG
);
2075 if (sa_hdl
!= NULL
&& sa_hdl
!= hdl
) {
2076 ASSERT(sa_db
!= NULL
);
2077 zfs_release_sa_handle(sa_hdl
, sa_db
, FTAG
);
2081 (void) memmove(buf
, path
, buf
+ len
- path
);
2087 zfs_obj_to_path(objset_t
*osp
, uint64_t obj
, char *buf
, int len
)
2089 sa_attr_type_t
*sa_table
;
2094 error
= zfs_sa_setup(osp
, &sa_table
);
2098 error
= zfs_grab_sa_handle(osp
, obj
, &hdl
, &db
, FTAG
);
2102 error
= zfs_obj_to_path_impl(osp
, obj
, hdl
, sa_table
, buf
, len
);
2104 zfs_release_sa_handle(hdl
, db
, FTAG
);
2109 zfs_obj_to_stats(objset_t
*osp
, uint64_t obj
, zfs_stat_t
*sb
,
2112 char *path
= buf
+ len
- 1;
2113 sa_attr_type_t
*sa_table
;
2120 error
= zfs_sa_setup(osp
, &sa_table
);
2124 error
= zfs_grab_sa_handle(osp
, obj
, &hdl
, &db
, FTAG
);
2128 error
= zfs_obj_to_stats_impl(hdl
, sa_table
, sb
);
2130 zfs_release_sa_handle(hdl
, db
, FTAG
);
2134 error
= zfs_obj_to_path_impl(osp
, obj
, hdl
, sa_table
, buf
, len
);
2136 zfs_release_sa_handle(hdl
, db
, FTAG
);
2140 #if defined(_KERNEL) && defined(HAVE_SPL)
2141 EXPORT_SYMBOL(zfs_create_fs
);
2142 EXPORT_SYMBOL(zfs_obj_to_path
);
2144 module_param(zfs_object_mutex_size
, uint
, 0644);
2145 MODULE_PARM_DESC(zfs_object_mutex_size
, "Size of znode hold array");