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]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
25 * Copyright (c) 2014 Integros [integros.com]
26 * Copyright 2017 Nexenta Systems, Inc.
29 /* Portions Copyright 2007 Jeremy Teo */
30 /* Portions Copyright 2010 Robert Milkowski */
33 #include <sys/types.h>
34 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/sysmacros.h>
38 #include <sys/resource.h>
40 #include <sys/endian.h>
42 #include <sys/vnode.h>
43 #if __FreeBSD_version >= 1300102
46 #include <sys/dirent.h>
50 #include <sys/taskq.h>
52 #include <sys/atomic.h>
53 #include <sys/namei.h>
55 #include <sys/cmn_err.h>
57 #include <sys/sysproto.h>
58 #include <sys/errno.h>
59 #include <sys/unistd.h>
60 #include <sys/zfs_dir.h>
61 #include <sys/zfs_ioctl.h>
62 #include <sys/fs/zfs.h>
64 #include <sys/dmu_objset.h>
70 #include <sys/policy.h>
71 #include <sys/sunddi.h>
72 #include <sys/filio.h>
74 #include <sys/zfs_ctldir.h>
75 #include <sys/zfs_fuid.h>
76 #include <sys/zfs_quota.h>
77 #include <sys/zfs_sa.h>
78 #include <sys/zfs_rlock.h>
79 #include <sys/extdirent.h>
82 #include <sys/sched.h>
84 #include <sys/vmmeter.h>
85 #include <vm/vm_param.h>
87 #include <sys/zfs_vnops.h>
89 #include <vm/vm_object.h>
91 #include <sys/extattr.h>
95 #define VN_OPEN_INVFS 0x0
100 #if __FreeBSD_version < 1300103
101 #define NDFREE_PNBUF(ndp) NDFREE((ndp), NDF_ONLY_PNBUF)
104 #if __FreeBSD_version >= 1300047
105 #define vm_page_wire_lock(pp)
106 #define vm_page_wire_unlock(pp)
108 #define vm_page_wire_lock(pp) vm_page_lock(pp)
109 #define vm_page_wire_unlock(pp) vm_page_unlock(pp)
112 #ifdef DEBUG_VFS_LOCKS
113 #define VNCHECKREF(vp) \
114 VNASSERT((vp)->v_holdcnt > 0 && (vp)->v_usecount > 0, vp, \
115 ("%s: wrong ref counts", __func__));
117 #define VNCHECKREF(vp)
120 #if __FreeBSD_version >= 1400045
121 typedef uint64_t cookie_t
;
123 typedef ulong_t cookie_t
;
129 * Each vnode op performs some logical unit of work. To do this, the ZPL must
130 * properly lock its in-core state, create a DMU transaction, do the work,
131 * record this work in the intent log (ZIL), commit the DMU transaction,
132 * and wait for the intent log to commit if it is a synchronous operation.
133 * Moreover, the vnode ops must work in both normal and log replay context.
134 * The ordering of events is important to avoid deadlocks and references
135 * to freed memory. The example below illustrates the following Big Rules:
137 * (1) A check must be made in each zfs thread for a mounted file system.
138 * This is done avoiding races using ZFS_ENTER(zfsvfs).
139 * A ZFS_EXIT(zfsvfs) is needed before all returns. Any znodes
140 * must be checked with ZFS_VERIFY_ZP(zp). Both of these macros
141 * can return EIO from the calling function.
143 * (2) VN_RELE() should always be the last thing except for zil_commit()
144 * (if necessary) and ZFS_EXIT(). This is for 3 reasons:
145 * First, if it's the last reference, the vnode/znode
146 * can be freed, so the zp may point to freed memory. Second, the last
147 * reference will call zfs_zinactive(), which may induce a lot of work --
148 * pushing cached pages (which acquires range locks) and syncing out
149 * cached atime changes. Third, zfs_zinactive() may require a new tx,
150 * which could deadlock the system if you were already holding one.
151 * If you must call VN_RELE() within a tx then use VN_RELE_ASYNC().
153 * (3) All range locks must be grabbed before calling dmu_tx_assign(),
154 * as they can span dmu_tx_assign() calls.
156 * (4) If ZPL locks are held, pass TXG_NOWAIT as the second argument to
157 * dmu_tx_assign(). This is critical because we don't want to block
158 * while holding locks.
160 * If no ZPL locks are held (aside from ZFS_ENTER()), use TXG_WAIT. This
161 * reduces lock contention and CPU usage when we must wait (note that if
162 * throughput is constrained by the storage, nearly every transaction
165 * Note, in particular, that if a lock is sometimes acquired before
166 * the tx assigns, and sometimes after (e.g. z_lock), then failing
167 * to use a non-blocking assign can deadlock the system. The scenario:
169 * Thread A has grabbed a lock before calling dmu_tx_assign().
170 * Thread B is in an already-assigned tx, and blocks for this lock.
171 * Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
172 * forever, because the previous txg can't quiesce until B's tx commits.
174 * If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
175 * then drop all locks, call dmu_tx_wait(), and try again. On subsequent
176 * calls to dmu_tx_assign(), pass TXG_NOTHROTTLE in addition to TXG_NOWAIT,
177 * to indicate that this operation has already called dmu_tx_wait().
178 * This will ensure that we don't retry forever, waiting a short bit
181 * (5) If the operation succeeded, generate the intent log entry for it
182 * before dropping locks. This ensures that the ordering of events
183 * in the intent log matches the order in which they actually occurred.
184 * During ZIL replay the zfs_log_* functions will update the sequence
185 * number to indicate the zil transaction has replayed.
187 * (6) At the end of each vnode op, the DMU tx must always commit,
188 * regardless of whether there were any errors.
190 * (7) After dropping all locks, invoke zil_commit(zilog, foid)
191 * to ensure that synchronous semantics are provided when necessary.
193 * In general, this is how things should be ordered in each vnode op:
195 * ZFS_ENTER(zfsvfs); // exit if unmounted
197 * zfs_dirent_lookup(&dl, ...) // lock directory entry (may VN_HOLD())
198 * rw_enter(...); // grab any other locks you need
199 * tx = dmu_tx_create(...); // get DMU tx
200 * dmu_tx_hold_*(); // hold each object you might modify
201 * error = dmu_tx_assign(tx, (waited ? TXG_NOTHROTTLE : 0) | TXG_NOWAIT);
203 * rw_exit(...); // drop locks
204 * zfs_dirent_unlock(dl); // unlock directory entry
205 * VN_RELE(...); // release held vnodes
206 * if (error == ERESTART) {
212 * dmu_tx_abort(tx); // abort DMU tx
213 * ZFS_EXIT(zfsvfs); // finished in zfs
214 * return (error); // really out of space
216 * error = do_real_work(); // do whatever this VOP does
218 * zfs_log_*(...); // on success, make ZIL entry
219 * dmu_tx_commit(tx); // commit DMU tx -- error or not
220 * rw_exit(...); // drop locks
221 * zfs_dirent_unlock(dl); // unlock directory entry
222 * VN_RELE(...); // release held vnodes
223 * zil_commit(zilog, foid); // synchronous when necessary
224 * ZFS_EXIT(zfsvfs); // finished in zfs
225 * return (error); // done, report error
228 zfs_open(vnode_t
**vpp
, int flag
, cred_t
*cr
)
231 znode_t
*zp
= VTOZ(*vpp
);
232 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
237 if ((flag
& FWRITE
) && (zp
->z_pflags
& ZFS_APPENDONLY
) &&
238 ((flag
& FAPPEND
) == 0)) {
240 return (SET_ERROR(EPERM
));
243 /* Keep a count of the synchronous opens in the znode */
244 if (flag
& (FSYNC
| FDSYNC
))
245 atomic_inc_32(&zp
->z_sync_cnt
);
252 zfs_close(vnode_t
*vp
, int flag
, int count
, offset_t offset
, cred_t
*cr
)
254 (void) offset
, (void) cr
;
255 znode_t
*zp
= VTOZ(vp
);
256 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
261 /* Decrement the synchronous opens in the znode */
262 if ((flag
& (FSYNC
| FDSYNC
)) && (count
== 1))
263 atomic_dec_32(&zp
->z_sync_cnt
);
270 zfs_ioctl(vnode_t
*vp
, ulong_t com
, intptr_t data
, int flag
, cred_t
*cred
,
273 (void) flag
, (void) cred
, (void) rvalp
;
283 * The following two ioctls are used by bfu. Faking out,
284 * necessary to avoid bfu errors.
296 off
= *(offset_t
*)data
;
297 /* offset parameter is in/out */
298 error
= zfs_holey(VTOZ(vp
), com
, &off
);
301 *(offset_t
*)data
= off
;
305 return (SET_ERROR(ENOTTY
));
309 page_busy(vnode_t
*vp
, int64_t start
, int64_t off
, int64_t nbytes
)
316 * At present vm_page_clear_dirty extends the cleared range to DEV_BSIZE
317 * aligned boundaries, if the range is not aligned. As a result a
318 * DEV_BSIZE subrange with partially dirty data may get marked as clean.
319 * It may happen that all DEV_BSIZE subranges are marked clean and thus
320 * the whole page would be considered clean despite have some
322 * For this reason we should shrink the range to DEV_BSIZE aligned
323 * boundaries before calling vm_page_clear_dirty.
325 end
= rounddown2(off
+ nbytes
, DEV_BSIZE
);
326 off
= roundup2(off
, DEV_BSIZE
);
330 zfs_vmobject_assert_wlocked_12(obj
);
331 #if __FreeBSD_version < 1300050
333 if ((pp
= vm_page_lookup(obj
, OFF_TO_IDX(start
))) != NULL
&&
335 if (vm_page_xbusied(pp
)) {
337 * Reference the page before unlocking and
338 * sleeping so that the page daemon is less
339 * likely to reclaim it.
341 vm_page_reference(pp
);
343 zfs_vmobject_wunlock(obj
);
344 vm_page_busy_sleep(pp
, "zfsmwb", true);
345 zfs_vmobject_wlock(obj
);
349 } else if (pp
!= NULL
) {
354 ASSERT3U(pp
->valid
, ==, VM_PAGE_BITS_ALL
);
355 vm_object_pip_add(obj
, 1);
356 pmap_remove_write(pp
);
358 vm_page_clear_dirty(pp
, off
, nbytes
);
363 vm_page_grab_valid_unlocked(&pp
, obj
, OFF_TO_IDX(start
),
364 VM_ALLOC_NOCREAT
| VM_ALLOC_SBUSY
| VM_ALLOC_NORMAL
|
367 ASSERT3U(pp
->valid
, ==, VM_PAGE_BITS_ALL
);
368 vm_object_pip_add(obj
, 1);
369 pmap_remove_write(pp
);
371 vm_page_clear_dirty(pp
, off
, nbytes
);
378 page_unbusy(vm_page_t pp
)
382 #if __FreeBSD_version >= 1300041
383 vm_object_pip_wakeup(pp
->object
);
385 vm_object_pip_subtract(pp
->object
, 1);
389 #if __FreeBSD_version > 1300051
391 page_hold(vnode_t
*vp
, int64_t start
)
397 vm_page_grab_valid_unlocked(&m
, obj
, OFF_TO_IDX(start
),
398 VM_ALLOC_NOCREAT
| VM_ALLOC_WIRED
| VM_ALLOC_IGN_SBUSY
|
404 page_hold(vnode_t
*vp
, int64_t start
)
410 zfs_vmobject_assert_wlocked(obj
);
413 if ((pp
= vm_page_lookup(obj
, OFF_TO_IDX(start
))) != NULL
&&
415 if (vm_page_xbusied(pp
)) {
417 * Reference the page before unlocking and
418 * sleeping so that the page daemon is less
419 * likely to reclaim it.
421 vm_page_reference(pp
);
423 zfs_vmobject_wunlock(obj
);
424 vm_page_busy_sleep(pp
, "zfsmwb", true);
425 zfs_vmobject_wlock(obj
);
429 ASSERT3U(pp
->valid
, ==, VM_PAGE_BITS_ALL
);
430 vm_page_wire_lock(pp
);
432 vm_page_wire_unlock(pp
);
443 page_unhold(vm_page_t pp
)
446 vm_page_wire_lock(pp
);
447 #if __FreeBSD_version >= 1300035
448 vm_page_unwire(pp
, PQ_ACTIVE
);
452 vm_page_wire_unlock(pp
);
456 * When a file is memory mapped, we must keep the IO data synchronized
457 * between the DMU cache and the memory mapped pages. What this means:
459 * On Write: If we find a memory mapped page, we write to *both*
460 * the page and the dmu buffer.
463 update_pages(znode_t
*zp
, int64_t start
, int len
, objset_t
*os
)
467 vnode_t
*vp
= ZTOV(zp
);
471 ASSERT3P(vp
->v_mount
, !=, NULL
);
473 ASSERT3P(obj
, !=, NULL
);
475 off
= start
& PAGEOFFSET
;
476 zfs_vmobject_wlock_12(obj
);
477 #if __FreeBSD_version >= 1300041
478 vm_object_pip_add(obj
, 1);
480 for (start
&= PAGEMASK
; len
> 0; start
+= PAGESIZE
) {
482 int nbytes
= imin(PAGESIZE
- off
, len
);
484 if ((pp
= page_busy(vp
, start
, off
, nbytes
)) != NULL
) {
485 zfs_vmobject_wunlock_12(obj
);
487 va
= zfs_map_page(pp
, &sf
);
488 (void) dmu_read(os
, zp
->z_id
, start
+ off
, nbytes
,
489 va
+ off
, DMU_READ_PREFETCH
);
492 zfs_vmobject_wlock_12(obj
);
498 #if __FreeBSD_version >= 1300041
499 vm_object_pip_wakeup(obj
);
501 vm_object_pip_wakeupn(obj
, 0);
503 zfs_vmobject_wunlock_12(obj
);
507 * Read with UIO_NOCOPY flag means that sendfile(2) requests
508 * ZFS to populate a range of page cache pages with data.
510 * NOTE: this function could be optimized to pre-allocate
511 * all pages in advance, drain exclusive busy on all of them,
512 * map them into contiguous KVA region and populate them
513 * in one single dmu_read() call.
516 mappedread_sf(znode_t
*zp
, int nbytes
, zfs_uio_t
*uio
)
518 vnode_t
*vp
= ZTOV(zp
);
519 objset_t
*os
= zp
->z_zfsvfs
->z_os
;
528 ASSERT3U(zfs_uio_segflg(uio
), ==, UIO_NOCOPY
);
529 ASSERT3P(vp
->v_mount
, !=, NULL
);
531 ASSERT3P(obj
, !=, NULL
);
532 ASSERT0(zfs_uio_offset(uio
) & PAGEOFFSET
);
534 zfs_vmobject_wlock_12(obj
);
535 for (start
= zfs_uio_offset(uio
); len
> 0; start
+= PAGESIZE
) {
536 int bytes
= MIN(PAGESIZE
, len
);
538 pp
= vm_page_grab_unlocked(obj
, OFF_TO_IDX(start
),
539 VM_ALLOC_SBUSY
| VM_ALLOC_NORMAL
| VM_ALLOC_IGN_SBUSY
);
540 if (vm_page_none_valid(pp
)) {
541 zfs_vmobject_wunlock_12(obj
);
542 va
= zfs_map_page(pp
, &sf
);
543 error
= dmu_read(os
, zp
->z_id
, start
, bytes
, va
,
545 if (bytes
!= PAGESIZE
&& error
== 0)
546 memset(va
+ bytes
, 0, PAGESIZE
- bytes
);
548 zfs_vmobject_wlock_12(obj
);
549 #if __FreeBSD_version >= 1300081
552 vm_page_activate(pp
);
553 vm_page_do_sunbusy(pp
);
555 zfs_vmobject_wlock(obj
);
556 if (!vm_page_wired(pp
) && pp
->valid
== 0 &&
557 vm_page_busy_tryupgrade(pp
))
561 zfs_vmobject_wunlock(obj
);
564 vm_page_do_sunbusy(pp
);
567 if (pp
->wire_count
== 0 && pp
->valid
== 0 &&
571 pp
->valid
= VM_PAGE_BITS_ALL
;
572 vm_page_activate(pp
);
577 ASSERT3U(pp
->valid
, ==, VM_PAGE_BITS_ALL
);
578 vm_page_do_sunbusy(pp
);
582 zfs_uio_advance(uio
, bytes
);
585 zfs_vmobject_wunlock_12(obj
);
590 * When a file is memory mapped, we must keep the IO data synchronized
591 * between the DMU cache and the memory mapped pages. What this means:
593 * On Read: We "read" preferentially from memory mapped pages,
594 * else we default from the dmu buffer.
596 * NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
597 * the file is memory mapped.
600 mappedread(znode_t
*zp
, int nbytes
, zfs_uio_t
*uio
)
602 vnode_t
*vp
= ZTOV(zp
);
609 ASSERT3P(vp
->v_mount
, !=, NULL
);
611 ASSERT3P(obj
, !=, NULL
);
613 start
= zfs_uio_offset(uio
);
614 off
= start
& PAGEOFFSET
;
615 zfs_vmobject_wlock_12(obj
);
616 for (start
&= PAGEMASK
; len
> 0; start
+= PAGESIZE
) {
618 uint64_t bytes
= MIN(PAGESIZE
- off
, len
);
620 if ((pp
= page_hold(vp
, start
))) {
624 zfs_vmobject_wunlock_12(obj
);
625 va
= zfs_map_page(pp
, &sf
);
626 error
= vn_io_fault_uiomove(va
+ off
, bytes
,
627 GET_UIO_STRUCT(uio
));
629 zfs_vmobject_wlock_12(obj
);
632 zfs_vmobject_wunlock_12(obj
);
633 error
= dmu_read_uio_dbuf(sa_get_db(zp
->z_sa_hdl
),
635 zfs_vmobject_wlock_12(obj
);
642 zfs_vmobject_wunlock_12(obj
);
647 zfs_write_simple(znode_t
*zp
, const void *data
, size_t len
,
648 loff_t pos
, size_t *presid
)
653 error
= vn_rdwr(UIO_WRITE
, ZTOV(zp
), __DECONST(void *, data
), len
, pos
,
654 UIO_SYSSPACE
, IO_SYNC
, kcred
, NOCRED
, &resid
, curthread
);
657 return (SET_ERROR(error
));
658 } else if (presid
== NULL
) {
660 error
= SET_ERROR(EIO
);
669 zfs_zrele_async(znode_t
*zp
)
671 vnode_t
*vp
= ZTOV(zp
);
672 objset_t
*os
= ITOZSB(vp
)->z_os
;
674 VN_RELE_ASYNC(vp
, dsl_pool_zrele_taskq(dmu_objset_pool(os
)));
678 zfs_dd_callback(struct mount
*mp
, void *arg
, int lkflags
, struct vnode
**vpp
)
683 error
= vn_lock(*vpp
, lkflags
);
690 zfs_lookup_lock(vnode_t
*dvp
, vnode_t
*vp
, const char *name
, int lkflags
)
692 znode_t
*zdp
= VTOZ(dvp
);
693 zfsvfs_t
*zfsvfs __unused
= zdp
->z_zfsvfs
;
697 if (zfsvfs
->z_replay
== B_FALSE
)
698 ASSERT_VOP_LOCKED(dvp
, __func__
);
700 if (name
[0] == 0 || (name
[0] == '.' && name
[1] == 0)) {
701 ASSERT3P(dvp
, ==, vp
);
703 ltype
= lkflags
& LK_TYPE_MASK
;
704 if (ltype
!= VOP_ISLOCKED(dvp
)) {
705 if (ltype
== LK_EXCLUSIVE
)
706 vn_lock(dvp
, LK_UPGRADE
| LK_RETRY
);
707 else /* if (ltype == LK_SHARED) */
708 vn_lock(dvp
, LK_DOWNGRADE
| LK_RETRY
);
711 * Relock for the "." case could leave us with
714 if (VN_IS_DOOMED(dvp
)) {
716 return (SET_ERROR(ENOENT
));
720 } else if (name
[0] == '.' && name
[1] == '.' && name
[2] == 0) {
722 * Note that in this case, dvp is the child vnode, and we
723 * are looking up the parent vnode - exactly reverse from
724 * normal operation. Unlocking dvp requires some rather
725 * tricky unlock/relock dance to prevent mp from being freed;
726 * use vn_vget_ino_gen() which takes care of all that.
728 * XXX Note that there is a time window when both vnodes are
729 * unlocked. It is possible, although highly unlikely, that
730 * during that window the parent-child relationship between
731 * the vnodes may change, for example, get reversed.
732 * In that case we would have a wrong lock order for the vnodes.
733 * All other filesystems seem to ignore this problem, so we
735 * A potential solution could be implemented as follows:
736 * - using LK_NOWAIT when locking the second vnode and retrying
738 * - checking that the parent-child relationship still holds
739 * after locking both vnodes and retrying if it doesn't
741 error
= vn_vget_ino_gen(dvp
, zfs_dd_callback
, vp
, lkflags
, &vp
);
744 error
= vn_lock(vp
, lkflags
);
752 * Lookup an entry in a directory, or an extended attribute directory.
753 * If it exists, return a held vnode reference for it.
755 * IN: dvp - vnode of directory to search.
756 * nm - name of entry to lookup.
757 * pnp - full pathname to lookup [UNUSED].
758 * flags - LOOKUP_XATTR set if looking for an attribute.
759 * rdir - root directory vnode [UNUSED].
760 * cr - credentials of caller.
761 * ct - caller context
763 * OUT: vpp - vnode of located entry, NULL if not found.
765 * RETURN: 0 on success, error code on failure.
771 zfs_lookup(vnode_t
*dvp
, const char *nm
, vnode_t
**vpp
,
772 struct componentname
*cnp
, int nameiop
, cred_t
*cr
, int flags
,
775 znode_t
*zdp
= VTOZ(dvp
);
777 zfsvfs_t
*zfsvfs
= zdp
->z_zfsvfs
;
778 #if __FreeBSD_version > 1300124
784 * Fast path lookup, however we must skip DNLC lookup
785 * for case folding or normalizing lookups because the
786 * DNLC code only stores the passed in name. This means
787 * creating 'a' and removing 'A' on a case insensitive
788 * file system would work, but DNLC still thinks 'a'
789 * exists and won't let you create it again on the next
790 * pass through fast path.
792 if (!(flags
& LOOKUP_XATTR
)) {
793 if (dvp
->v_type
!= VDIR
) {
794 return (SET_ERROR(ENOTDIR
));
795 } else if (zdp
->z_sa_hdl
== NULL
) {
796 return (SET_ERROR(EIO
));
800 DTRACE_PROBE2(zfs__fastpath__lookup__miss
, vnode_t
*, dvp
,
806 #if __FreeBSD_version > 1300124
807 dvp_seqc
= vn_seqc_read_notmodify(dvp
);
812 if (flags
& LOOKUP_XATTR
) {
814 * If the xattr property is off, refuse the lookup request.
816 if (!(zfsvfs
->z_flags
& ZSB_XATTR
)) {
818 return (SET_ERROR(EOPNOTSUPP
));
822 * We don't allow recursive attributes..
823 * Maybe someday we will.
825 if (zdp
->z_pflags
& ZFS_XATTR
) {
827 return (SET_ERROR(EINVAL
));
830 if ((error
= zfs_get_xattrdir(VTOZ(dvp
), &zp
, cr
, flags
))) {
837 * Do we have permission to get into attribute directory?
839 error
= zfs_zaccess(zp
, ACE_EXECUTE
, 0, B_FALSE
, cr
);
849 * Check accessibility of directory if we're not coming in via
854 if ((cnp
->cn_flags
& NOEXECCHECK
) != 0) {
855 cnp
->cn_flags
&= ~NOEXECCHECK
;
858 if ((error
= zfs_zaccess(zdp
, ACE_EXECUTE
, 0, B_FALSE
, cr
))) {
864 if (zfsvfs
->z_utf8
&& u8_validate(nm
, strlen(nm
),
865 NULL
, U8_VALIDATE_ENTIRE
, &error
) < 0) {
867 return (SET_ERROR(EILSEQ
));
872 * First handle the special cases.
874 if ((cnp
->cn_flags
& ISDOTDOT
) != 0) {
876 * If we are a snapshot mounted under .zfs, return
877 * the vp for the snapshot directory.
879 if (zdp
->z_id
== zfsvfs
->z_root
&& zfsvfs
->z_parent
!= zfsvfs
) {
880 struct componentname cn
;
885 ltype
= VOP_ISLOCKED(dvp
);
887 error
= zfsctl_root(zfsvfs
->z_parent
, LK_SHARED
,
890 cn
.cn_nameptr
= "snapshot";
891 cn
.cn_namelen
= strlen(cn
.cn_nameptr
);
892 cn
.cn_nameiop
= cnp
->cn_nameiop
;
893 cn
.cn_flags
= cnp
->cn_flags
& ~ISDOTDOT
;
894 cn
.cn_lkflags
= cnp
->cn_lkflags
;
895 error
= VOP_LOOKUP(zfsctl_vp
, vpp
, &cn
);
898 vn_lock(dvp
, ltype
| LK_RETRY
);
902 if (zfs_has_ctldir(zdp
) && strcmp(nm
, ZFS_CTLDIR_NAME
) == 0) {
904 if ((cnp
->cn_flags
& ISLASTCN
) != 0 && nameiop
!= LOOKUP
)
905 return (SET_ERROR(ENOTSUP
));
906 error
= zfsctl_root(zfsvfs
, cnp
->cn_lkflags
, vpp
);
911 * The loop is retry the lookup if the parent-child relationship
912 * changes during the dot-dot locking complexities.
917 error
= zfs_dirlook(zdp
, nm
, &zp
);
925 error
= zfs_lookup_lock(dvp
, *vpp
, nm
, cnp
->cn_lkflags
);
928 * If we've got a locking error, then the vnode
929 * got reclaimed because of a force unmount.
930 * We never enter doomed vnodes into the name cache.
936 if ((cnp
->cn_flags
& ISDOTDOT
) == 0)
940 if (zdp
->z_sa_hdl
== NULL
) {
941 error
= SET_ERROR(EIO
);
943 error
= sa_lookup(zdp
->z_sa_hdl
, SA_ZPL_PARENT(zfsvfs
),
944 &parent
, sizeof (parent
));
951 if (zp
->z_id
== parent
) {
961 /* Translate errors and add SAVENAME when needed. */
962 if (cnp
->cn_flags
& ISLASTCN
) {
966 if (error
== ENOENT
) {
968 cnp
->cn_flags
|= SAVENAME
;
974 cnp
->cn_flags
|= SAVENAME
;
979 #if __FreeBSD_version > 1300124
980 if ((cnp
->cn_flags
& ISDOTDOT
) != 0) {
982 * FIXME: zfs_lookup_lock relocks vnodes and does nothing to
983 * handle races. In particular different callers may end up
984 * with different vnodes and will try to add conflicting
985 * entries to the namecache.
987 * While finding different result may be acceptable in face
988 * of concurrent modification, adding conflicting entries
989 * trips over an assert in the namecache.
991 * Ultimately let an entry through once everything settles.
993 if (!vn_seqc_consistent(dvp
, dvp_seqc
)) {
994 cnp
->cn_flags
&= ~MAKEENTRY
;
999 /* Insert name into cache (as non-existent) if appropriate. */
1000 if (zfsvfs
->z_use_namecache
&& !zfsvfs
->z_replay
&&
1001 error
== ENOENT
&& (cnp
->cn_flags
& MAKEENTRY
) != 0)
1002 cache_enter(dvp
, NULL
, cnp
);
1004 /* Insert name into cache if appropriate. */
1005 if (zfsvfs
->z_use_namecache
&& !zfsvfs
->z_replay
&&
1006 error
== 0 && (cnp
->cn_flags
& MAKEENTRY
)) {
1007 if (!(cnp
->cn_flags
& ISLASTCN
) ||
1008 (nameiop
!= DELETE
&& nameiop
!= RENAME
)) {
1009 cache_enter(dvp
, *vpp
, cnp
);
1017 * Attempt to create a new entry in a directory. If the entry
1018 * already exists, truncate the file if permissible, else return
1019 * an error. Return the vp of the created or trunc'd file.
1021 * IN: dvp - vnode of directory to put new file entry in.
1022 * name - name of new file entry.
1023 * vap - attributes of new file.
1024 * excl - flag indicating exclusive or non-exclusive mode.
1025 * mode - mode to open file with.
1026 * cr - credentials of caller.
1027 * flag - large file flag [UNUSED].
1028 * ct - caller context
1029 * vsecp - ACL to be set
1031 * OUT: vpp - vnode of created or trunc'd entry.
1033 * RETURN: 0 on success, error code on failure.
1036 * dvp - ctime|mtime updated if new entry created
1037 * vp - ctime|mtime always, atime if new
1040 zfs_create(znode_t
*dzp
, const char *name
, vattr_t
*vap
, int excl
, int mode
,
1041 znode_t
**zpp
, cred_t
*cr
, int flag
, vsecattr_t
*vsecp
)
1043 (void) excl
, (void) mode
, (void) flag
;
1045 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
1050 uid_t uid
= crgetuid(cr
);
1051 gid_t gid
= crgetgid(cr
);
1052 uint64_t projid
= ZFS_DEFAULT_PROJID
;
1053 zfs_acl_ids_t acl_ids
;
1054 boolean_t fuid_dirtied
;
1056 #ifdef DEBUG_VFS_LOCKS
1057 vnode_t
*dvp
= ZTOV(dzp
);
1061 * If we have an ephemeral id, ACL, or XVATTR then
1062 * make sure file system is at proper version
1064 if (zfsvfs
->z_use_fuids
== B_FALSE
&&
1065 (vsecp
|| (vap
->va_mask
& AT_XVATTR
) ||
1066 IS_EPHEMERAL(uid
) || IS_EPHEMERAL(gid
)))
1067 return (SET_ERROR(EINVAL
));
1072 zilog
= zfsvfs
->z_log
;
1074 if (zfsvfs
->z_utf8
&& u8_validate(name
, strlen(name
),
1075 NULL
, U8_VALIDATE_ENTIRE
, &error
) < 0) {
1077 return (SET_ERROR(EILSEQ
));
1080 if (vap
->va_mask
& AT_XVATTR
) {
1081 if ((error
= secpolicy_xvattr(ZTOV(dzp
), (xvattr_t
*)vap
,
1082 crgetuid(cr
), cr
, vap
->va_type
)) != 0) {
1090 if ((vap
->va_mode
& S_ISVTX
) && secpolicy_vnode_stky_modify(cr
))
1091 vap
->va_mode
&= ~S_ISVTX
;
1093 error
= zfs_dirent_lookup(dzp
, name
, &zp
, ZNEW
);
1098 ASSERT3P(zp
, ==, NULL
);
1101 * Create a new file object and update the directory
1104 if ((error
= zfs_zaccess(dzp
, ACE_ADD_FILE
, 0, B_FALSE
, cr
))) {
1109 * We only support the creation of regular files in
1110 * extended attribute directories.
1113 if ((dzp
->z_pflags
& ZFS_XATTR
) &&
1114 (vap
->va_type
!= VREG
)) {
1115 error
= SET_ERROR(EINVAL
);
1119 if ((error
= zfs_acl_ids_create(dzp
, 0, vap
,
1120 cr
, vsecp
, &acl_ids
)) != 0)
1123 if (S_ISREG(vap
->va_mode
) || S_ISDIR(vap
->va_mode
))
1124 projid
= zfs_inherit_projid(dzp
);
1125 if (zfs_acl_ids_overquota(zfsvfs
, &acl_ids
, projid
)) {
1126 zfs_acl_ids_free(&acl_ids
);
1127 error
= SET_ERROR(EDQUOT
);
1131 getnewvnode_reserve_();
1133 tx
= dmu_tx_create(os
);
1135 dmu_tx_hold_sa_create(tx
, acl_ids
.z_aclp
->z_acl_bytes
+
1136 ZFS_SA_BASE_ATTR_SIZE
);
1138 fuid_dirtied
= zfsvfs
->z_fuid_dirty
;
1140 zfs_fuid_txhold(zfsvfs
, tx
);
1141 dmu_tx_hold_zap(tx
, dzp
->z_id
, TRUE
, name
);
1142 dmu_tx_hold_sa(tx
, dzp
->z_sa_hdl
, B_FALSE
);
1143 if (!zfsvfs
->z_use_sa
&&
1144 acl_ids
.z_aclp
->z_acl_bytes
> ZFS_ACE_SPACE
) {
1145 dmu_tx_hold_write(tx
, DMU_NEW_OBJECT
,
1146 0, acl_ids
.z_aclp
->z_acl_bytes
);
1148 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1150 zfs_acl_ids_free(&acl_ids
);
1152 getnewvnode_drop_reserve();
1156 zfs_mknode(dzp
, vap
, tx
, cr
, 0, &zp
, &acl_ids
);
1158 zfs_fuid_sync(zfsvfs
, tx
);
1160 (void) zfs_link_create(dzp
, name
, zp
, tx
, ZNEW
);
1161 txtype
= zfs_log_create_txtype(Z_FILE
, vsecp
, vap
);
1162 zfs_log_create(zilog
, tx
, txtype
, dzp
, zp
, name
,
1163 vsecp
, acl_ids
.z_fuidp
, vap
);
1164 zfs_acl_ids_free(&acl_ids
);
1167 getnewvnode_drop_reserve();
1175 if (zfsvfs
->z_os
->os_sync
== ZFS_SYNC_ALWAYS
)
1176 zil_commit(zilog
, 0);
1183 * Remove an entry from a directory.
1185 * IN: dvp - vnode of directory to remove entry from.
1186 * name - name of entry to remove.
1187 * cr - credentials of caller.
1188 * ct - caller context
1189 * flags - case flags
1191 * RETURN: 0 on success, error code on failure.
1195 * vp - ctime (if nlink > 0)
1198 zfs_remove_(vnode_t
*dvp
, vnode_t
*vp
, const char *name
, cred_t
*cr
)
1200 znode_t
*dzp
= VTOZ(dvp
);
1203 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
1217 zilog
= zfsvfs
->z_log
;
1222 if ((error
= zfs_zaccess_delete(dzp
, zp
, cr
))) {
1227 * Need to use rmdir for removing directories.
1229 if (vp
->v_type
== VDIR
) {
1230 error
= SET_ERROR(EPERM
);
1234 vnevent_remove(vp
, dvp
, name
, ct
);
1238 /* are there any extended attributes? */
1239 error
= sa_lookup(zp
->z_sa_hdl
, SA_ZPL_XATTR(zfsvfs
),
1240 &xattr_obj
, sizeof (xattr_obj
));
1241 if (error
== 0 && xattr_obj
) {
1242 error
= zfs_zget(zfsvfs
, xattr_obj
, &xzp
);
1247 * We may delete the znode now, or we may put it in the unlinked set;
1248 * it depends on whether we're the last link, and on whether there are
1249 * other holds on the vnode. So we dmu_tx_hold() the right things to
1250 * allow for either case.
1252 tx
= dmu_tx_create(zfsvfs
->z_os
);
1253 dmu_tx_hold_zap(tx
, dzp
->z_id
, FALSE
, name
);
1254 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1255 zfs_sa_upgrade_txholds(tx
, zp
);
1256 zfs_sa_upgrade_txholds(tx
, dzp
);
1259 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_TRUE
);
1260 dmu_tx_hold_sa(tx
, xzp
->z_sa_hdl
, B_FALSE
);
1263 /* charge as an update -- would be nice not to charge at all */
1264 dmu_tx_hold_zap(tx
, zfsvfs
->z_unlinkedobj
, FALSE
, NULL
);
1267 * Mark this transaction as typically resulting in a net free of space
1269 dmu_tx_mark_netfree(tx
);
1271 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1279 * Remove the directory entry.
1281 error
= zfs_link_destroy(dzp
, name
, zp
, tx
, ZEXISTS
, &unlinked
);
1289 zfs_unlinked_add(zp
, tx
);
1290 vp
->v_vflag
|= VV_NOSYNC
;
1292 /* XXX check changes to linux vnops */
1294 zfs_log_remove(zilog
, tx
, txtype
, dzp
, name
, obj
, unlinked
);
1302 if (zfsvfs
->z_os
->os_sync
== ZFS_SYNC_ALWAYS
)
1303 zil_commit(zilog
, 0);
1312 zfs_lookup_internal(znode_t
*dzp
, const char *name
, vnode_t
**vpp
,
1313 struct componentname
*cnp
, int nameiop
)
1315 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
1318 cnp
->cn_nameptr
= __DECONST(char *, name
);
1319 cnp
->cn_namelen
= strlen(name
);
1320 cnp
->cn_nameiop
= nameiop
;
1321 cnp
->cn_flags
= ISLASTCN
| SAVENAME
;
1322 cnp
->cn_lkflags
= LK_EXCLUSIVE
| LK_RETRY
;
1323 cnp
->cn_cred
= kcred
;
1324 #if __FreeBSD_version < 1400037
1325 cnp
->cn_thread
= curthread
;
1328 if (zfsvfs
->z_use_namecache
&& !zfsvfs
->z_replay
) {
1329 struct vop_lookup_args a
;
1331 a
.a_gen
.a_desc
= &vop_lookup_desc
;
1332 a
.a_dvp
= ZTOV(dzp
);
1335 error
= vfs_cache_lookup(&a
);
1337 error
= zfs_lookup(ZTOV(dzp
), name
, vpp
, cnp
, nameiop
, kcred
, 0,
1342 printf("got error %d on name %s on op %d\n", error
, name
,
1351 zfs_remove(znode_t
*dzp
, const char *name
, cred_t
*cr
, int flags
)
1355 struct componentname cn
;
1357 if ((error
= zfs_lookup_internal(dzp
, name
, &vp
, &cn
, DELETE
)))
1360 error
= zfs_remove_(ZTOV(dzp
), vp
, name
, cr
);
1365 * Create a new directory and insert it into dvp using the name
1366 * provided. Return a pointer to the inserted directory.
1368 * IN: dvp - vnode of directory to add subdir to.
1369 * dirname - name of new directory.
1370 * vap - attributes of new directory.
1371 * cr - credentials of caller.
1372 * ct - caller context
1373 * flags - case flags
1374 * vsecp - ACL to be set
1376 * OUT: vpp - vnode of created directory.
1378 * RETURN: 0 on success, error code on failure.
1381 * dvp - ctime|mtime updated
1382 * vp - ctime|mtime|atime updated
1385 zfs_mkdir(znode_t
*dzp
, const char *dirname
, vattr_t
*vap
, znode_t
**zpp
,
1386 cred_t
*cr
, int flags
, vsecattr_t
*vsecp
)
1388 (void) flags
, (void) vsecp
;
1390 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
1395 uid_t uid
= crgetuid(cr
);
1396 gid_t gid
= crgetgid(cr
);
1397 zfs_acl_ids_t acl_ids
;
1398 boolean_t fuid_dirtied
;
1400 ASSERT3U(vap
->va_type
, ==, VDIR
);
1403 * If we have an ephemeral id, ACL, or XVATTR then
1404 * make sure file system is at proper version
1406 if (zfsvfs
->z_use_fuids
== B_FALSE
&&
1407 ((vap
->va_mask
& AT_XVATTR
) ||
1408 IS_EPHEMERAL(uid
) || IS_EPHEMERAL(gid
)))
1409 return (SET_ERROR(EINVAL
));
1413 zilog
= zfsvfs
->z_log
;
1415 if (dzp
->z_pflags
& ZFS_XATTR
) {
1417 return (SET_ERROR(EINVAL
));
1420 if (zfsvfs
->z_utf8
&& u8_validate(dirname
,
1421 strlen(dirname
), NULL
, U8_VALIDATE_ENTIRE
, &error
) < 0) {
1423 return (SET_ERROR(EILSEQ
));
1426 if (vap
->va_mask
& AT_XVATTR
) {
1427 if ((error
= secpolicy_xvattr(ZTOV(dzp
), (xvattr_t
*)vap
,
1428 crgetuid(cr
), cr
, vap
->va_type
)) != 0) {
1434 if ((error
= zfs_acl_ids_create(dzp
, 0, vap
, cr
,
1435 NULL
, &acl_ids
)) != 0) {
1441 * First make sure the new directory doesn't exist.
1443 * Existence is checked first to make sure we don't return
1444 * EACCES instead of EEXIST which can cause some applications
1449 if ((error
= zfs_dirent_lookup(dzp
, dirname
, &zp
, ZNEW
))) {
1450 zfs_acl_ids_free(&acl_ids
);
1454 ASSERT3P(zp
, ==, NULL
);
1456 if ((error
= zfs_zaccess(dzp
, ACE_ADD_SUBDIRECTORY
, 0, B_FALSE
, cr
))) {
1457 zfs_acl_ids_free(&acl_ids
);
1462 if (zfs_acl_ids_overquota(zfsvfs
, &acl_ids
, zfs_inherit_projid(dzp
))) {
1463 zfs_acl_ids_free(&acl_ids
);
1465 return (SET_ERROR(EDQUOT
));
1469 * Add a new entry to the directory.
1471 getnewvnode_reserve_();
1472 tx
= dmu_tx_create(zfsvfs
->z_os
);
1473 dmu_tx_hold_zap(tx
, dzp
->z_id
, TRUE
, dirname
);
1474 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
1475 fuid_dirtied
= zfsvfs
->z_fuid_dirty
;
1477 zfs_fuid_txhold(zfsvfs
, tx
);
1478 if (!zfsvfs
->z_use_sa
&& acl_ids
.z_aclp
->z_acl_bytes
> ZFS_ACE_SPACE
) {
1479 dmu_tx_hold_write(tx
, DMU_NEW_OBJECT
, 0,
1480 acl_ids
.z_aclp
->z_acl_bytes
);
1483 dmu_tx_hold_sa_create(tx
, acl_ids
.z_aclp
->z_acl_bytes
+
1484 ZFS_SA_BASE_ATTR_SIZE
);
1486 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1488 zfs_acl_ids_free(&acl_ids
);
1490 getnewvnode_drop_reserve();
1498 zfs_mknode(dzp
, vap
, tx
, cr
, 0, &zp
, &acl_ids
);
1501 zfs_fuid_sync(zfsvfs
, tx
);
1504 * Now put new name in parent dir.
1506 (void) zfs_link_create(dzp
, dirname
, zp
, tx
, ZNEW
);
1510 txtype
= zfs_log_create_txtype(Z_DIR
, NULL
, vap
);
1511 zfs_log_create(zilog
, tx
, txtype
, dzp
, zp
, dirname
, NULL
,
1512 acl_ids
.z_fuidp
, vap
);
1514 zfs_acl_ids_free(&acl_ids
);
1518 getnewvnode_drop_reserve();
1520 if (zfsvfs
->z_os
->os_sync
== ZFS_SYNC_ALWAYS
)
1521 zil_commit(zilog
, 0);
1527 #if __FreeBSD_version < 1300124
1529 cache_vop_rmdir(struct vnode
*dvp
, struct vnode
*vp
)
1538 * Remove a directory subdir entry. If the current working
1539 * directory is the same as the subdir to be removed, the
1542 * IN: dvp - vnode of directory to remove from.
1543 * name - name of directory to be removed.
1544 * cwd - vnode of current working directory.
1545 * cr - credentials of caller.
1546 * ct - caller context
1547 * flags - case flags
1549 * RETURN: 0 on success, error code on failure.
1552 * dvp - ctime|mtime updated
1555 zfs_rmdir_(vnode_t
*dvp
, vnode_t
*vp
, const char *name
, cred_t
*cr
)
1557 znode_t
*dzp
= VTOZ(dvp
);
1558 znode_t
*zp
= VTOZ(vp
);
1559 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
1567 zilog
= zfsvfs
->z_log
;
1570 if ((error
= zfs_zaccess_delete(dzp
, zp
, cr
))) {
1574 if (vp
->v_type
!= VDIR
) {
1575 error
= SET_ERROR(ENOTDIR
);
1579 vnevent_rmdir(vp
, dvp
, name
, ct
);
1581 tx
= dmu_tx_create(zfsvfs
->z_os
);
1582 dmu_tx_hold_zap(tx
, dzp
->z_id
, FALSE
, name
);
1583 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
1584 dmu_tx_hold_zap(tx
, zfsvfs
->z_unlinkedobj
, FALSE
, NULL
);
1585 zfs_sa_upgrade_txholds(tx
, zp
);
1586 zfs_sa_upgrade_txholds(tx
, dzp
);
1587 dmu_tx_mark_netfree(tx
);
1588 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1595 error
= zfs_link_destroy(dzp
, name
, zp
, tx
, ZEXISTS
, NULL
);
1598 uint64_t txtype
= TX_RMDIR
;
1599 zfs_log_remove(zilog
, tx
, txtype
, dzp
, name
,
1600 ZFS_NO_OBJECT
, B_FALSE
);
1605 cache_vop_rmdir(dvp
, vp
);
1607 if (zfsvfs
->z_os
->os_sync
== ZFS_SYNC_ALWAYS
)
1608 zil_commit(zilog
, 0);
1615 zfs_rmdir(znode_t
*dzp
, const char *name
, znode_t
*cwd
, cred_t
*cr
, int flags
)
1617 struct componentname cn
;
1621 if ((error
= zfs_lookup_internal(dzp
, name
, &vp
, &cn
, DELETE
)))
1624 error
= zfs_rmdir_(ZTOV(dzp
), vp
, name
, cr
);
1630 * Read as many directory entries as will fit into the provided
1631 * buffer from the given directory cursor position (specified in
1632 * the uio structure).
1634 * IN: vp - vnode of directory to read.
1635 * uio - structure supplying read location, range info,
1636 * and return buffer.
1637 * cr - credentials of caller.
1638 * ct - caller context
1639 * flags - case flags
1641 * OUT: uio - updated offset and range, buffer filled.
1642 * eofp - set to true if end-of-file detected.
1644 * RETURN: 0 on success, error code on failure.
1647 * vp - atime updated
1649 * Note that the low 4 bits of the cookie returned by zap is always zero.
1650 * This allows us to use the low range for "special" directory entries:
1651 * We use 0 for '.', and 1 for '..'. If this is the root of the filesystem,
1652 * we use the offset 2 for the '.zfs' directory.
1655 zfs_readdir(vnode_t
*vp
, zfs_uio_t
*uio
, cred_t
*cr
, int *eofp
,
1656 int *ncookies
, cookie_t
**cookies
)
1658 znode_t
*zp
= VTOZ(vp
);
1662 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1667 zap_attribute_t zap
;
1668 uint_t bytes_wanted
;
1669 uint64_t offset
; /* must be unsigned; checks for < 1 */
1675 boolean_t check_sysattrs
;
1678 cookie_t
*cooks
= NULL
;
1684 if ((error
= sa_lookup(zp
->z_sa_hdl
, SA_ZPL_PARENT(zfsvfs
),
1685 &parent
, sizeof (parent
))) != 0) {
1691 * If we are not given an eof variable,
1698 * Check for valid iov_len.
1700 if (GET_UIO_STRUCT(uio
)->uio_iov
->iov_len
<= 0) {
1702 return (SET_ERROR(EINVAL
));
1706 * Quit if directory has been removed (posix)
1708 if ((*eofp
= zp
->z_unlinked
) != 0) {
1715 offset
= zfs_uio_offset(uio
);
1716 prefetch
= zp
->z_zn_prefetch
;
1719 * Initialize the iterator cursor.
1723 * Start iteration from the beginning of the directory.
1725 zap_cursor_init(&zc
, os
, zp
->z_id
);
1728 * The offset is a serialized cursor.
1730 zap_cursor_init_serialized(&zc
, os
, zp
->z_id
, offset
);
1734 * Get space to change directory entries into fs independent format.
1736 iovp
= GET_UIO_STRUCT(uio
)->uio_iov
;
1737 bytes_wanted
= iovp
->iov_len
;
1738 if (zfs_uio_segflg(uio
) != UIO_SYSSPACE
|| zfs_uio_iovcnt(uio
) != 1) {
1739 bufsize
= bytes_wanted
;
1740 outbuf
= kmem_alloc(bufsize
, KM_SLEEP
);
1741 odp
= (struct dirent64
*)outbuf
;
1743 bufsize
= bytes_wanted
;
1745 odp
= (struct dirent64
*)iovp
->iov_base
;
1747 eodp
= (struct edirent
*)odp
;
1749 if (ncookies
!= NULL
) {
1751 * Minimum entry size is dirent size and 1 byte for a file name.
1753 ncooks
= zfs_uio_resid(uio
) / (sizeof (struct dirent
) -
1754 sizeof (((struct dirent
*)NULL
)->d_name
) + 1);
1755 cooks
= malloc(ncooks
* sizeof (*cooks
), M_TEMP
, M_WAITOK
);
1760 * If this VFS supports the system attribute view interface; and
1761 * we're looking at an extended attribute directory; and we care
1762 * about normalization conflicts on this vfs; then we must check
1763 * for normalization conflicts with the sysattr name space.
1766 check_sysattrs
= vfs_has_feature(vp
->v_vfsp
, VFSFT_SYSATTR_VIEWS
) &&
1767 (vp
->v_flag
& V_XATTRDIR
) && zfsvfs
->z_norm
&&
1768 (flags
& V_RDDIR_ENTFLAGS
);
1774 * Transform to file-system independent format
1777 while (outcount
< bytes_wanted
) {
1780 off64_t
*next
= NULL
;
1783 * Special case `.', `..', and `.zfs'.
1786 (void) strcpy(zap
.za_name
, ".");
1787 zap
.za_normalization_conflict
= 0;
1790 } else if (offset
== 1) {
1791 (void) strcpy(zap
.za_name
, "..");
1792 zap
.za_normalization_conflict
= 0;
1795 } else if (offset
== 2 && zfs_show_ctldir(zp
)) {
1796 (void) strcpy(zap
.za_name
, ZFS_CTLDIR_NAME
);
1797 zap
.za_normalization_conflict
= 0;
1798 objnum
= ZFSCTL_INO_ROOT
;
1804 if ((error
= zap_cursor_retrieve(&zc
, &zap
))) {
1805 if ((*eofp
= (error
== ENOENT
)) != 0)
1811 if (zap
.za_integer_length
!= 8 ||
1812 zap
.za_num_integers
!= 1) {
1813 cmn_err(CE_WARN
, "zap_readdir: bad directory "
1814 "entry, obj = %lld, offset = %lld\n",
1815 (u_longlong_t
)zp
->z_id
,
1816 (u_longlong_t
)offset
);
1817 error
= SET_ERROR(ENXIO
);
1821 objnum
= ZFS_DIRENT_OBJ(zap
.za_first_integer
);
1823 * MacOS X can extract the object type here such as:
1824 * uint8_t type = ZFS_DIRENT_TYPE(zap.za_first_integer);
1826 type
= ZFS_DIRENT_TYPE(zap
.za_first_integer
);
1828 if (check_sysattrs
&& !zap
.za_normalization_conflict
) {
1830 zap
.za_normalization_conflict
=
1831 xattr_sysattr_casechk(zap
.za_name
);
1833 panic("%s:%u: TODO", __func__
, __LINE__
);
1838 if (flags
& V_RDDIR_ACCFILTER
) {
1840 * If we have no access at all, don't include
1841 * this entry in the returned information
1844 if (zfs_zget(zp
->z_zfsvfs
, objnum
, &ezp
) != 0)
1846 if (!zfs_has_access(ezp
, cr
)) {
1853 if (flags
& V_RDDIR_ENTFLAGS
)
1854 reclen
= EDIRENT_RECLEN(strlen(zap
.za_name
));
1856 reclen
= DIRENT64_RECLEN(strlen(zap
.za_name
));
1859 * Will this entry fit in the buffer?
1861 if (outcount
+ reclen
> bufsize
) {
1863 * Did we manage to fit anything in the buffer?
1866 error
= SET_ERROR(EINVAL
);
1871 if (flags
& V_RDDIR_ENTFLAGS
) {
1873 * Add extended flag entry:
1875 eodp
->ed_ino
= objnum
;
1876 eodp
->ed_reclen
= reclen
;
1877 /* NOTE: ed_off is the offset for the *next* entry */
1878 next
= &(eodp
->ed_off
);
1879 eodp
->ed_eflags
= zap
.za_normalization_conflict
?
1880 ED_CASE_CONFLICT
: 0;
1881 (void) strncpy(eodp
->ed_name
, zap
.za_name
,
1882 EDIRENT_NAMELEN(reclen
));
1883 eodp
= (edirent_t
*)((intptr_t)eodp
+ reclen
);
1888 odp
->d_ino
= objnum
;
1889 odp
->d_reclen
= reclen
;
1890 odp
->d_namlen
= strlen(zap
.za_name
);
1891 /* NOTE: d_off is the offset for the *next* entry. */
1893 strlcpy(odp
->d_name
, zap
.za_name
, odp
->d_namlen
+ 1);
1895 dirent_terminate(odp
);
1896 odp
= (dirent64_t
*)((intptr_t)odp
+ reclen
);
1900 ASSERT3S(outcount
, <=, bufsize
);
1902 /* Prefetch znode */
1904 dmu_prefetch(os
, objnum
, 0, 0, 0,
1905 ZIO_PRIORITY_SYNC_READ
);
1909 * Move to the next entry, fill in the previous offset.
1911 if (offset
> 2 || (offset
== 2 && !zfs_show_ctldir(zp
))) {
1912 zap_cursor_advance(&zc
);
1913 offset
= zap_cursor_serialize(&zc
);
1918 /* Fill the offset right after advancing the cursor. */
1921 if (cooks
!= NULL
) {
1924 KASSERT(ncooks
>= 0, ("ncookies=%d", ncooks
));
1927 zp
->z_zn_prefetch
= B_FALSE
; /* a lookup will re-enable pre-fetching */
1929 /* Subtract unused cookies */
1930 if (ncookies
!= NULL
)
1931 *ncookies
-= ncooks
;
1933 if (zfs_uio_segflg(uio
) == UIO_SYSSPACE
&& zfs_uio_iovcnt(uio
) == 1) {
1934 iovp
->iov_base
+= outcount
;
1935 iovp
->iov_len
-= outcount
;
1936 zfs_uio_resid(uio
) -= outcount
;
1938 zfs_uiomove(outbuf
, (long)outcount
, UIO_READ
, uio
))) {
1940 * Reset the pointer.
1942 offset
= zfs_uio_offset(uio
);
1946 zap_cursor_fini(&zc
);
1947 if (zfs_uio_segflg(uio
) != UIO_SYSSPACE
|| zfs_uio_iovcnt(uio
) != 1)
1948 kmem_free(outbuf
, bufsize
);
1950 if (error
== ENOENT
)
1953 ZFS_ACCESSTIME_STAMP(zfsvfs
, zp
);
1955 zfs_uio_setoffset(uio
, offset
);
1957 if (error
!= 0 && cookies
!= NULL
) {
1958 free(*cookies
, M_TEMP
);
1966 * Get the requested file attributes and place them in the provided
1969 * IN: vp - vnode of file.
1970 * vap - va_mask identifies requested attributes.
1971 * If AT_XVATTR set, then optional attrs are requested
1972 * flags - ATTR_NOACLCHECK (CIFS server context)
1973 * cr - credentials of caller.
1975 * OUT: vap - attribute values.
1977 * RETURN: 0 (always succeeds).
1980 zfs_getattr(vnode_t
*vp
, vattr_t
*vap
, int flags
, cred_t
*cr
)
1982 znode_t
*zp
= VTOZ(vp
);
1983 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
1986 u_longlong_t nblocks
;
1987 uint64_t mtime
[2], ctime
[2], crtime
[2], rdev
;
1988 xvattr_t
*xvap
= (xvattr_t
*)vap
; /* vap may be an xvattr_t * */
1989 xoptattr_t
*xoap
= NULL
;
1990 boolean_t skipaclchk
= (flags
& ATTR_NOACLCHECK
) ? B_TRUE
: B_FALSE
;
1991 sa_bulk_attr_t bulk
[4];
1997 zfs_fuid_map_ids(zp
, cr
, &vap
->va_uid
, &vap
->va_gid
);
1999 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zfsvfs
), NULL
, &mtime
, 16);
2000 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zfsvfs
), NULL
, &ctime
, 16);
2001 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CRTIME(zfsvfs
), NULL
, &crtime
, 16);
2002 if (vp
->v_type
== VBLK
|| vp
->v_type
== VCHR
)
2003 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_RDEV(zfsvfs
), NULL
,
2006 if ((error
= sa_bulk_lookup(zp
->z_sa_hdl
, bulk
, count
)) != 0) {
2012 * If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES.
2013 * Also, if we are the owner don't bother, since owner should
2014 * always be allowed to read basic attributes of file.
2016 if (!(zp
->z_pflags
& ZFS_ACL_TRIVIAL
) &&
2017 (vap
->va_uid
!= crgetuid(cr
))) {
2018 if ((error
= zfs_zaccess(zp
, ACE_READ_ATTRIBUTES
, 0,
2026 * Return all attributes. It's cheaper to provide the answer
2027 * than to determine whether we were asked the question.
2030 vap
->va_type
= IFTOVT(zp
->z_mode
);
2031 vap
->va_mode
= zp
->z_mode
& ~S_IFMT
;
2033 vap
->va_nodeid
= zp
->z_id
;
2034 vap
->va_nlink
= zp
->z_links
;
2035 if ((vp
->v_flag
& VROOT
) && zfs_show_ctldir(zp
) &&
2036 zp
->z_links
< ZFS_LINK_MAX
)
2038 vap
->va_size
= zp
->z_size
;
2039 if (vp
->v_type
== VBLK
|| vp
->v_type
== VCHR
)
2040 vap
->va_rdev
= zfs_cmpldev(rdev
);
2041 vap
->va_gen
= zp
->z_gen
;
2042 vap
->va_flags
= 0; /* FreeBSD: Reset chflags(2) flags. */
2043 vap
->va_filerev
= zp
->z_seq
;
2046 * Add in any requested optional attributes and the create time.
2047 * Also set the corresponding bits in the returned attribute bitmap.
2049 if ((xoap
= xva_getxoptattr(xvap
)) != NULL
&& zfsvfs
->z_use_fuids
) {
2050 if (XVA_ISSET_REQ(xvap
, XAT_ARCHIVE
)) {
2052 ((zp
->z_pflags
& ZFS_ARCHIVE
) != 0);
2053 XVA_SET_RTN(xvap
, XAT_ARCHIVE
);
2056 if (XVA_ISSET_REQ(xvap
, XAT_READONLY
)) {
2057 xoap
->xoa_readonly
=
2058 ((zp
->z_pflags
& ZFS_READONLY
) != 0);
2059 XVA_SET_RTN(xvap
, XAT_READONLY
);
2062 if (XVA_ISSET_REQ(xvap
, XAT_SYSTEM
)) {
2064 ((zp
->z_pflags
& ZFS_SYSTEM
) != 0);
2065 XVA_SET_RTN(xvap
, XAT_SYSTEM
);
2068 if (XVA_ISSET_REQ(xvap
, XAT_HIDDEN
)) {
2070 ((zp
->z_pflags
& ZFS_HIDDEN
) != 0);
2071 XVA_SET_RTN(xvap
, XAT_HIDDEN
);
2074 if (XVA_ISSET_REQ(xvap
, XAT_NOUNLINK
)) {
2075 xoap
->xoa_nounlink
=
2076 ((zp
->z_pflags
& ZFS_NOUNLINK
) != 0);
2077 XVA_SET_RTN(xvap
, XAT_NOUNLINK
);
2080 if (XVA_ISSET_REQ(xvap
, XAT_IMMUTABLE
)) {
2081 xoap
->xoa_immutable
=
2082 ((zp
->z_pflags
& ZFS_IMMUTABLE
) != 0);
2083 XVA_SET_RTN(xvap
, XAT_IMMUTABLE
);
2086 if (XVA_ISSET_REQ(xvap
, XAT_APPENDONLY
)) {
2087 xoap
->xoa_appendonly
=
2088 ((zp
->z_pflags
& ZFS_APPENDONLY
) != 0);
2089 XVA_SET_RTN(xvap
, XAT_APPENDONLY
);
2092 if (XVA_ISSET_REQ(xvap
, XAT_NODUMP
)) {
2094 ((zp
->z_pflags
& ZFS_NODUMP
) != 0);
2095 XVA_SET_RTN(xvap
, XAT_NODUMP
);
2098 if (XVA_ISSET_REQ(xvap
, XAT_OPAQUE
)) {
2100 ((zp
->z_pflags
& ZFS_OPAQUE
) != 0);
2101 XVA_SET_RTN(xvap
, XAT_OPAQUE
);
2104 if (XVA_ISSET_REQ(xvap
, XAT_AV_QUARANTINED
)) {
2105 xoap
->xoa_av_quarantined
=
2106 ((zp
->z_pflags
& ZFS_AV_QUARANTINED
) != 0);
2107 XVA_SET_RTN(xvap
, XAT_AV_QUARANTINED
);
2110 if (XVA_ISSET_REQ(xvap
, XAT_AV_MODIFIED
)) {
2111 xoap
->xoa_av_modified
=
2112 ((zp
->z_pflags
& ZFS_AV_MODIFIED
) != 0);
2113 XVA_SET_RTN(xvap
, XAT_AV_MODIFIED
);
2116 if (XVA_ISSET_REQ(xvap
, XAT_AV_SCANSTAMP
) &&
2117 vp
->v_type
== VREG
) {
2118 zfs_sa_get_scanstamp(zp
, xvap
);
2121 if (XVA_ISSET_REQ(xvap
, XAT_REPARSE
)) {
2122 xoap
->xoa_reparse
= ((zp
->z_pflags
& ZFS_REPARSE
) != 0);
2123 XVA_SET_RTN(xvap
, XAT_REPARSE
);
2125 if (XVA_ISSET_REQ(xvap
, XAT_GEN
)) {
2126 xoap
->xoa_generation
= zp
->z_gen
;
2127 XVA_SET_RTN(xvap
, XAT_GEN
);
2130 if (XVA_ISSET_REQ(xvap
, XAT_OFFLINE
)) {
2132 ((zp
->z_pflags
& ZFS_OFFLINE
) != 0);
2133 XVA_SET_RTN(xvap
, XAT_OFFLINE
);
2136 if (XVA_ISSET_REQ(xvap
, XAT_SPARSE
)) {
2138 ((zp
->z_pflags
& ZFS_SPARSE
) != 0);
2139 XVA_SET_RTN(xvap
, XAT_SPARSE
);
2142 if (XVA_ISSET_REQ(xvap
, XAT_PROJINHERIT
)) {
2143 xoap
->xoa_projinherit
=
2144 ((zp
->z_pflags
& ZFS_PROJINHERIT
) != 0);
2145 XVA_SET_RTN(xvap
, XAT_PROJINHERIT
);
2148 if (XVA_ISSET_REQ(xvap
, XAT_PROJID
)) {
2149 xoap
->xoa_projid
= zp
->z_projid
;
2150 XVA_SET_RTN(xvap
, XAT_PROJID
);
2154 ZFS_TIME_DECODE(&vap
->va_atime
, zp
->z_atime
);
2155 ZFS_TIME_DECODE(&vap
->va_mtime
, mtime
);
2156 ZFS_TIME_DECODE(&vap
->va_ctime
, ctime
);
2157 ZFS_TIME_DECODE(&vap
->va_birthtime
, crtime
);
2160 sa_object_size(zp
->z_sa_hdl
, &blksize
, &nblocks
);
2161 vap
->va_blksize
= blksize
;
2162 vap
->va_bytes
= nblocks
<< 9; /* nblocks * 512 */
2164 if (zp
->z_blksz
== 0) {
2166 * Block size hasn't been set; suggest maximal I/O transfers.
2168 vap
->va_blksize
= zfsvfs
->z_max_blksz
;
2176 * Set the file attributes to the values contained in the
2179 * IN: zp - znode of file to be modified.
2180 * vap - new attribute values.
2181 * If AT_XVATTR set, then optional attrs are being set
2182 * flags - ATTR_UTIME set if non-default time values provided.
2183 * - ATTR_NOACLCHECK (CIFS context only).
2184 * cr - credentials of caller.
2185 * ct - caller context
2187 * RETURN: 0 on success, error code on failure.
2190 * vp - ctime updated, mtime updated if size changed.
2193 zfs_setattr(znode_t
*zp
, vattr_t
*vap
, int flags
, cred_t
*cr
)
2195 vnode_t
*vp
= ZTOV(zp
);
2196 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
2202 uint_t mask
= vap
->va_mask
;
2203 uint_t saved_mask
= 0;
2204 uint64_t saved_mode
;
2207 uint64_t new_uid
, new_gid
;
2209 uint64_t mtime
[2], ctime
[2];
2210 uint64_t projid
= ZFS_INVALID_PROJID
;
2212 int need_policy
= FALSE
;
2214 zfs_fuid_info_t
*fuidp
= NULL
;
2215 xvattr_t
*xvap
= (xvattr_t
*)vap
; /* vap may be an xvattr_t * */
2218 boolean_t skipaclchk
= (flags
& ATTR_NOACLCHECK
) ? B_TRUE
: B_FALSE
;
2219 boolean_t fuid_dirtied
= B_FALSE
;
2220 sa_bulk_attr_t bulk
[7], xattr_bulk
[7];
2221 int count
= 0, xattr_count
= 0;
2226 if (mask
& AT_NOSET
)
2227 return (SET_ERROR(EINVAL
));
2233 zilog
= zfsvfs
->z_log
;
2236 * Make sure that if we have ephemeral uid/gid or xvattr specified
2237 * that file system is at proper version level
2240 if (zfsvfs
->z_use_fuids
== B_FALSE
&&
2241 (((mask
& AT_UID
) && IS_EPHEMERAL(vap
->va_uid
)) ||
2242 ((mask
& AT_GID
) && IS_EPHEMERAL(vap
->va_gid
)) ||
2243 (mask
& AT_XVATTR
))) {
2245 return (SET_ERROR(EINVAL
));
2248 if (mask
& AT_SIZE
&& vp
->v_type
== VDIR
) {
2250 return (SET_ERROR(EISDIR
));
2253 if (mask
& AT_SIZE
&& vp
->v_type
!= VREG
&& vp
->v_type
!= VFIFO
) {
2255 return (SET_ERROR(EINVAL
));
2259 * If this is an xvattr_t, then get a pointer to the structure of
2260 * optional attributes. If this is NULL, then we have a vattr_t.
2262 xoap
= xva_getxoptattr(xvap
);
2264 xva_init(&tmpxvattr
);
2267 * Immutable files can only alter immutable bit and atime
2269 if ((zp
->z_pflags
& ZFS_IMMUTABLE
) &&
2270 ((mask
& (AT_SIZE
|AT_UID
|AT_GID
|AT_MTIME
|AT_MODE
)) ||
2271 ((mask
& AT_XVATTR
) && XVA_ISSET_REQ(xvap
, XAT_CREATETIME
)))) {
2273 return (SET_ERROR(EPERM
));
2277 * Note: ZFS_READONLY is handled in zfs_zaccess_common.
2281 * Verify timestamps doesn't overflow 32 bits.
2282 * ZFS can handle large timestamps, but 32bit syscalls can't
2283 * handle times greater than 2039. This check should be removed
2284 * once large timestamps are fully supported.
2286 if (mask
& (AT_ATIME
| AT_MTIME
)) {
2287 if (((mask
& AT_ATIME
) && TIMESPEC_OVERFLOW(&vap
->va_atime
)) ||
2288 ((mask
& AT_MTIME
) && TIMESPEC_OVERFLOW(&vap
->va_mtime
))) {
2290 return (SET_ERROR(EOVERFLOW
));
2293 if (xoap
!= NULL
&& (mask
& AT_XVATTR
)) {
2294 if (XVA_ISSET_REQ(xvap
, XAT_CREATETIME
) &&
2295 TIMESPEC_OVERFLOW(&vap
->va_birthtime
)) {
2297 return (SET_ERROR(EOVERFLOW
));
2300 if (XVA_ISSET_REQ(xvap
, XAT_PROJID
)) {
2301 if (!dmu_objset_projectquota_enabled(os
) ||
2302 (!S_ISREG(zp
->z_mode
) && !S_ISDIR(zp
->z_mode
))) {
2304 return (SET_ERROR(EOPNOTSUPP
));
2307 projid
= xoap
->xoa_projid
;
2308 if (unlikely(projid
== ZFS_INVALID_PROJID
)) {
2310 return (SET_ERROR(EINVAL
));
2313 if (projid
== zp
->z_projid
&& zp
->z_pflags
& ZFS_PROJID
)
2314 projid
= ZFS_INVALID_PROJID
;
2319 if (XVA_ISSET_REQ(xvap
, XAT_PROJINHERIT
) &&
2320 (xoap
->xoa_projinherit
!=
2321 ((zp
->z_pflags
& ZFS_PROJINHERIT
) != 0)) &&
2322 (!dmu_objset_projectquota_enabled(os
) ||
2323 (!S_ISREG(zp
->z_mode
) && !S_ISDIR(zp
->z_mode
)))) {
2325 return (SET_ERROR(EOPNOTSUPP
));
2332 if (zfsvfs
->z_vfs
->vfs_flag
& VFS_RDONLY
) {
2334 return (SET_ERROR(EROFS
));
2338 * First validate permissions
2341 if (mask
& AT_SIZE
) {
2343 * XXX - Note, we are not providing any open
2344 * mode flags here (like FNDELAY), so we may
2345 * block if there are locks present... this
2346 * should be addressed in openat().
2348 /* XXX - would it be OK to generate a log record here? */
2349 err
= zfs_freesp(zp
, vap
->va_size
, 0, 0, FALSE
);
2356 if (mask
& (AT_ATIME
|AT_MTIME
) ||
2357 ((mask
& AT_XVATTR
) && (XVA_ISSET_REQ(xvap
, XAT_HIDDEN
) ||
2358 XVA_ISSET_REQ(xvap
, XAT_READONLY
) ||
2359 XVA_ISSET_REQ(xvap
, XAT_ARCHIVE
) ||
2360 XVA_ISSET_REQ(xvap
, XAT_OFFLINE
) ||
2361 XVA_ISSET_REQ(xvap
, XAT_SPARSE
) ||
2362 XVA_ISSET_REQ(xvap
, XAT_CREATETIME
) ||
2363 XVA_ISSET_REQ(xvap
, XAT_SYSTEM
)))) {
2364 need_policy
= zfs_zaccess(zp
, ACE_WRITE_ATTRIBUTES
, 0,
2368 if (mask
& (AT_UID
|AT_GID
)) {
2369 int idmask
= (mask
& (AT_UID
|AT_GID
));
2374 * NOTE: even if a new mode is being set,
2375 * we may clear S_ISUID/S_ISGID bits.
2378 if (!(mask
& AT_MODE
))
2379 vap
->va_mode
= zp
->z_mode
;
2382 * Take ownership or chgrp to group we are a member of
2385 take_owner
= (mask
& AT_UID
) && (vap
->va_uid
== crgetuid(cr
));
2386 take_group
= (mask
& AT_GID
) &&
2387 zfs_groupmember(zfsvfs
, vap
->va_gid
, cr
);
2390 * If both AT_UID and AT_GID are set then take_owner and
2391 * take_group must both be set in order to allow taking
2394 * Otherwise, send the check through secpolicy_vnode_setattr()
2398 if (((idmask
== (AT_UID
|AT_GID
)) && take_owner
&& take_group
) ||
2399 ((idmask
== AT_UID
) && take_owner
) ||
2400 ((idmask
== AT_GID
) && take_group
)) {
2401 if (zfs_zaccess(zp
, ACE_WRITE_OWNER
, 0,
2402 skipaclchk
, cr
) == 0) {
2404 * Remove setuid/setgid for non-privileged users
2406 secpolicy_setid_clear(vap
, vp
, cr
);
2407 trim_mask
= (mask
& (AT_UID
|AT_GID
));
2416 oldva
.va_mode
= zp
->z_mode
;
2417 zfs_fuid_map_ids(zp
, cr
, &oldva
.va_uid
, &oldva
.va_gid
);
2418 if (mask
& AT_XVATTR
) {
2420 * Update xvattr mask to include only those attributes
2421 * that are actually changing.
2423 * the bits will be restored prior to actually setting
2424 * the attributes so the caller thinks they were set.
2426 if (XVA_ISSET_REQ(xvap
, XAT_APPENDONLY
)) {
2427 if (xoap
->xoa_appendonly
!=
2428 ((zp
->z_pflags
& ZFS_APPENDONLY
) != 0)) {
2431 XVA_CLR_REQ(xvap
, XAT_APPENDONLY
);
2432 XVA_SET_REQ(&tmpxvattr
, XAT_APPENDONLY
);
2436 if (XVA_ISSET_REQ(xvap
, XAT_PROJINHERIT
)) {
2437 if (xoap
->xoa_projinherit
!=
2438 ((zp
->z_pflags
& ZFS_PROJINHERIT
) != 0)) {
2441 XVA_CLR_REQ(xvap
, XAT_PROJINHERIT
);
2442 XVA_SET_REQ(&tmpxvattr
, XAT_PROJINHERIT
);
2446 if (XVA_ISSET_REQ(xvap
, XAT_NOUNLINK
)) {
2447 if (xoap
->xoa_nounlink
!=
2448 ((zp
->z_pflags
& ZFS_NOUNLINK
) != 0)) {
2451 XVA_CLR_REQ(xvap
, XAT_NOUNLINK
);
2452 XVA_SET_REQ(&tmpxvattr
, XAT_NOUNLINK
);
2456 if (XVA_ISSET_REQ(xvap
, XAT_IMMUTABLE
)) {
2457 if (xoap
->xoa_immutable
!=
2458 ((zp
->z_pflags
& ZFS_IMMUTABLE
) != 0)) {
2461 XVA_CLR_REQ(xvap
, XAT_IMMUTABLE
);
2462 XVA_SET_REQ(&tmpxvattr
, XAT_IMMUTABLE
);
2466 if (XVA_ISSET_REQ(xvap
, XAT_NODUMP
)) {
2467 if (xoap
->xoa_nodump
!=
2468 ((zp
->z_pflags
& ZFS_NODUMP
) != 0)) {
2471 XVA_CLR_REQ(xvap
, XAT_NODUMP
);
2472 XVA_SET_REQ(&tmpxvattr
, XAT_NODUMP
);
2476 if (XVA_ISSET_REQ(xvap
, XAT_AV_MODIFIED
)) {
2477 if (xoap
->xoa_av_modified
!=
2478 ((zp
->z_pflags
& ZFS_AV_MODIFIED
) != 0)) {
2481 XVA_CLR_REQ(xvap
, XAT_AV_MODIFIED
);
2482 XVA_SET_REQ(&tmpxvattr
, XAT_AV_MODIFIED
);
2486 if (XVA_ISSET_REQ(xvap
, XAT_AV_QUARANTINED
)) {
2487 if ((vp
->v_type
!= VREG
&&
2488 xoap
->xoa_av_quarantined
) ||
2489 xoap
->xoa_av_quarantined
!=
2490 ((zp
->z_pflags
& ZFS_AV_QUARANTINED
) != 0)) {
2493 XVA_CLR_REQ(xvap
, XAT_AV_QUARANTINED
);
2494 XVA_SET_REQ(&tmpxvattr
, XAT_AV_QUARANTINED
);
2498 if (XVA_ISSET_REQ(xvap
, XAT_REPARSE
)) {
2500 return (SET_ERROR(EPERM
));
2503 if (need_policy
== FALSE
&&
2504 (XVA_ISSET_REQ(xvap
, XAT_AV_SCANSTAMP
) ||
2505 XVA_ISSET_REQ(xvap
, XAT_OPAQUE
))) {
2510 if (mask
& AT_MODE
) {
2511 if (zfs_zaccess(zp
, ACE_WRITE_ACL
, 0, skipaclchk
, cr
) == 0) {
2512 err
= secpolicy_setid_setsticky_clear(vp
, vap
,
2518 trim_mask
|= AT_MODE
;
2526 * If trim_mask is set then take ownership
2527 * has been granted or write_acl is present and user
2528 * has the ability to modify mode. In that case remove
2529 * UID|GID and or MODE from mask so that
2530 * secpolicy_vnode_setattr() doesn't revoke it.
2534 saved_mask
= vap
->va_mask
;
2535 vap
->va_mask
&= ~trim_mask
;
2536 if (trim_mask
& AT_MODE
) {
2538 * Save the mode, as secpolicy_vnode_setattr()
2539 * will overwrite it with ova.va_mode.
2541 saved_mode
= vap
->va_mode
;
2544 err
= secpolicy_vnode_setattr(cr
, vp
, vap
, &oldva
, flags
,
2545 (int (*)(void *, int, cred_t
*))zfs_zaccess_unix
, zp
);
2552 vap
->va_mask
|= saved_mask
;
2553 if (trim_mask
& AT_MODE
) {
2555 * Recover the mode after
2556 * secpolicy_vnode_setattr().
2558 vap
->va_mode
= saved_mode
;
2564 * secpolicy_vnode_setattr, or take ownership may have
2567 mask
= vap
->va_mask
;
2569 if ((mask
& (AT_UID
| AT_GID
)) || projid
!= ZFS_INVALID_PROJID
) {
2570 err
= sa_lookup(zp
->z_sa_hdl
, SA_ZPL_XATTR(zfsvfs
),
2571 &xattr_obj
, sizeof (xattr_obj
));
2573 if (err
== 0 && xattr_obj
) {
2574 err
= zfs_zget(zp
->z_zfsvfs
, xattr_obj
, &attrzp
);
2576 err
= vn_lock(ZTOV(attrzp
), LK_EXCLUSIVE
);
2578 vrele(ZTOV(attrzp
));
2583 if (mask
& AT_UID
) {
2584 new_uid
= zfs_fuid_create(zfsvfs
,
2585 (uint64_t)vap
->va_uid
, cr
, ZFS_OWNER
, &fuidp
);
2586 if (new_uid
!= zp
->z_uid
&&
2587 zfs_id_overquota(zfsvfs
, DMU_USERUSED_OBJECT
,
2591 err
= SET_ERROR(EDQUOT
);
2596 if (mask
& AT_GID
) {
2597 new_gid
= zfs_fuid_create(zfsvfs
, (uint64_t)vap
->va_gid
,
2598 cr
, ZFS_GROUP
, &fuidp
);
2599 if (new_gid
!= zp
->z_gid
&&
2600 zfs_id_overquota(zfsvfs
, DMU_GROUPUSED_OBJECT
,
2604 err
= SET_ERROR(EDQUOT
);
2609 if (projid
!= ZFS_INVALID_PROJID
&&
2610 zfs_id_overquota(zfsvfs
, DMU_PROJECTUSED_OBJECT
, projid
)) {
2613 err
= SET_ERROR(EDQUOT
);
2617 tx
= dmu_tx_create(os
);
2619 if (mask
& AT_MODE
) {
2620 uint64_t pmode
= zp
->z_mode
;
2622 new_mode
= (pmode
& S_IFMT
) | (vap
->va_mode
& ~S_IFMT
);
2624 if (zp
->z_zfsvfs
->z_acl_mode
== ZFS_ACL_RESTRICTED
&&
2625 !(zp
->z_pflags
& ZFS_ACL_TRIVIAL
)) {
2626 err
= SET_ERROR(EPERM
);
2630 if ((err
= zfs_acl_chmod_setattr(zp
, &aclp
, new_mode
)))
2633 if (!zp
->z_is_sa
&& ((acl_obj
= zfs_external_acl(zp
)) != 0)) {
2635 * Are we upgrading ACL from old V0 format
2638 if (zfsvfs
->z_version
>= ZPL_VERSION_FUID
&&
2639 zfs_znode_acl_version(zp
) ==
2640 ZFS_ACL_VERSION_INITIAL
) {
2641 dmu_tx_hold_free(tx
, acl_obj
, 0,
2643 dmu_tx_hold_write(tx
, DMU_NEW_OBJECT
,
2644 0, aclp
->z_acl_bytes
);
2646 dmu_tx_hold_write(tx
, acl_obj
, 0,
2649 } else if (!zp
->z_is_sa
&& aclp
->z_acl_bytes
> ZFS_ACE_SPACE
) {
2650 dmu_tx_hold_write(tx
, DMU_NEW_OBJECT
,
2651 0, aclp
->z_acl_bytes
);
2653 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_TRUE
);
2655 if (((mask
& AT_XVATTR
) &&
2656 XVA_ISSET_REQ(xvap
, XAT_AV_SCANSTAMP
)) ||
2657 (projid
!= ZFS_INVALID_PROJID
&&
2658 !(zp
->z_pflags
& ZFS_PROJID
)))
2659 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_TRUE
);
2661 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
2665 dmu_tx_hold_sa(tx
, attrzp
->z_sa_hdl
, B_FALSE
);
2668 fuid_dirtied
= zfsvfs
->z_fuid_dirty
;
2670 zfs_fuid_txhold(zfsvfs
, tx
);
2672 zfs_sa_upgrade_txholds(tx
, zp
);
2674 err
= dmu_tx_assign(tx
, TXG_WAIT
);
2680 * Set each attribute requested.
2681 * We group settings according to the locks they need to acquire.
2683 * Note: you cannot set ctime directly, although it will be
2684 * updated as a side-effect of calling this function.
2687 if (projid
!= ZFS_INVALID_PROJID
&& !(zp
->z_pflags
& ZFS_PROJID
)) {
2689 * For the existed object that is upgraded from old system,
2690 * its on-disk layout has no slot for the project ID attribute.
2691 * But quota accounting logic needs to access related slots by
2692 * offset directly. So we need to adjust old objects' layout
2693 * to make the project ID to some unified and fixed offset.
2696 err
= sa_add_projid(attrzp
->z_sa_hdl
, tx
, projid
);
2698 err
= sa_add_projid(zp
->z_sa_hdl
, tx
, projid
);
2700 if (unlikely(err
== EEXIST
))
2705 projid
= ZFS_INVALID_PROJID
;
2708 if (mask
& (AT_UID
|AT_GID
|AT_MODE
))
2709 mutex_enter(&zp
->z_acl_lock
);
2711 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zfsvfs
), NULL
,
2712 &zp
->z_pflags
, sizeof (zp
->z_pflags
));
2715 if (mask
& (AT_UID
|AT_GID
|AT_MODE
))
2716 mutex_enter(&attrzp
->z_acl_lock
);
2717 SA_ADD_BULK_ATTR(xattr_bulk
, xattr_count
,
2718 SA_ZPL_FLAGS(zfsvfs
), NULL
, &attrzp
->z_pflags
,
2719 sizeof (attrzp
->z_pflags
));
2720 if (projid
!= ZFS_INVALID_PROJID
) {
2721 attrzp
->z_projid
= projid
;
2722 SA_ADD_BULK_ATTR(xattr_bulk
, xattr_count
,
2723 SA_ZPL_PROJID(zfsvfs
), NULL
, &attrzp
->z_projid
,
2724 sizeof (attrzp
->z_projid
));
2728 if (mask
& (AT_UID
|AT_GID
)) {
2730 if (mask
& AT_UID
) {
2731 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_UID(zfsvfs
), NULL
,
2732 &new_uid
, sizeof (new_uid
));
2733 zp
->z_uid
= new_uid
;
2735 SA_ADD_BULK_ATTR(xattr_bulk
, xattr_count
,
2736 SA_ZPL_UID(zfsvfs
), NULL
, &new_uid
,
2738 attrzp
->z_uid
= new_uid
;
2742 if (mask
& AT_GID
) {
2743 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_GID(zfsvfs
),
2744 NULL
, &new_gid
, sizeof (new_gid
));
2745 zp
->z_gid
= new_gid
;
2747 SA_ADD_BULK_ATTR(xattr_bulk
, xattr_count
,
2748 SA_ZPL_GID(zfsvfs
), NULL
, &new_gid
,
2750 attrzp
->z_gid
= new_gid
;
2753 if (!(mask
& AT_MODE
)) {
2754 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zfsvfs
),
2755 NULL
, &new_mode
, sizeof (new_mode
));
2756 new_mode
= zp
->z_mode
;
2758 err
= zfs_acl_chown_setattr(zp
);
2761 vn_seqc_write_begin(ZTOV(attrzp
));
2762 err
= zfs_acl_chown_setattr(attrzp
);
2763 vn_seqc_write_end(ZTOV(attrzp
));
2768 if (mask
& AT_MODE
) {
2769 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MODE(zfsvfs
), NULL
,
2770 &new_mode
, sizeof (new_mode
));
2771 zp
->z_mode
= new_mode
;
2772 ASSERT3P(aclp
, !=, NULL
);
2773 err
= zfs_aclset_common(zp
, aclp
, cr
, tx
);
2775 if (zp
->z_acl_cached
)
2776 zfs_acl_free(zp
->z_acl_cached
);
2777 zp
->z_acl_cached
= aclp
;
2782 if (mask
& AT_ATIME
) {
2783 ZFS_TIME_ENCODE(&vap
->va_atime
, zp
->z_atime
);
2784 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_ATIME(zfsvfs
), NULL
,
2785 &zp
->z_atime
, sizeof (zp
->z_atime
));
2788 if (mask
& AT_MTIME
) {
2789 ZFS_TIME_ENCODE(&vap
->va_mtime
, mtime
);
2790 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zfsvfs
), NULL
,
2791 mtime
, sizeof (mtime
));
2794 if (projid
!= ZFS_INVALID_PROJID
) {
2795 zp
->z_projid
= projid
;
2796 SA_ADD_BULK_ATTR(bulk
, count
,
2797 SA_ZPL_PROJID(zfsvfs
), NULL
, &zp
->z_projid
,
2798 sizeof (zp
->z_projid
));
2801 /* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
2802 if (mask
& AT_SIZE
&& !(mask
& AT_MTIME
)) {
2803 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zfsvfs
),
2804 NULL
, mtime
, sizeof (mtime
));
2805 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zfsvfs
), NULL
,
2806 &ctime
, sizeof (ctime
));
2807 zfs_tstamp_update_setup(zp
, CONTENT_MODIFIED
, mtime
, ctime
);
2808 } else if (mask
!= 0) {
2809 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zfsvfs
), NULL
,
2810 &ctime
, sizeof (ctime
));
2811 zfs_tstamp_update_setup(zp
, STATE_CHANGED
, mtime
, ctime
);
2813 SA_ADD_BULK_ATTR(xattr_bulk
, xattr_count
,
2814 SA_ZPL_CTIME(zfsvfs
), NULL
,
2815 &ctime
, sizeof (ctime
));
2816 zfs_tstamp_update_setup(attrzp
, STATE_CHANGED
,
2822 * Do this after setting timestamps to prevent timestamp
2823 * update from toggling bit
2826 if (xoap
&& (mask
& AT_XVATTR
)) {
2828 if (XVA_ISSET_REQ(xvap
, XAT_CREATETIME
))
2829 xoap
->xoa_createtime
= vap
->va_birthtime
;
2831 * restore trimmed off masks
2832 * so that return masks can be set for caller.
2835 if (XVA_ISSET_REQ(&tmpxvattr
, XAT_APPENDONLY
)) {
2836 XVA_SET_REQ(xvap
, XAT_APPENDONLY
);
2838 if (XVA_ISSET_REQ(&tmpxvattr
, XAT_NOUNLINK
)) {
2839 XVA_SET_REQ(xvap
, XAT_NOUNLINK
);
2841 if (XVA_ISSET_REQ(&tmpxvattr
, XAT_IMMUTABLE
)) {
2842 XVA_SET_REQ(xvap
, XAT_IMMUTABLE
);
2844 if (XVA_ISSET_REQ(&tmpxvattr
, XAT_NODUMP
)) {
2845 XVA_SET_REQ(xvap
, XAT_NODUMP
);
2847 if (XVA_ISSET_REQ(&tmpxvattr
, XAT_AV_MODIFIED
)) {
2848 XVA_SET_REQ(xvap
, XAT_AV_MODIFIED
);
2850 if (XVA_ISSET_REQ(&tmpxvattr
, XAT_AV_QUARANTINED
)) {
2851 XVA_SET_REQ(xvap
, XAT_AV_QUARANTINED
);
2853 if (XVA_ISSET_REQ(&tmpxvattr
, XAT_PROJINHERIT
)) {
2854 XVA_SET_REQ(xvap
, XAT_PROJINHERIT
);
2857 if (XVA_ISSET_REQ(xvap
, XAT_AV_SCANSTAMP
))
2858 ASSERT3S(vp
->v_type
, ==, VREG
);
2860 zfs_xvattr_set(zp
, xvap
, tx
);
2864 zfs_fuid_sync(zfsvfs
, tx
);
2867 zfs_log_setattr(zilog
, tx
, TX_SETATTR
, zp
, vap
, mask
, fuidp
);
2869 if (mask
& (AT_UID
|AT_GID
|AT_MODE
))
2870 mutex_exit(&zp
->z_acl_lock
);
2873 if (mask
& (AT_UID
|AT_GID
|AT_MODE
))
2874 mutex_exit(&attrzp
->z_acl_lock
);
2877 if (err
== 0 && attrzp
) {
2878 err2
= sa_bulk_update(attrzp
->z_sa_hdl
, xattr_bulk
,
2890 zfs_fuid_info_free(fuidp
);
2897 err2
= sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
);
2902 if (os
->os_sync
== ZFS_SYNC_ALWAYS
)
2903 zil_commit(zilog
, 0);
2910 * Look up the directory entries corresponding to the source and target
2911 * directory/name pairs.
2914 zfs_rename_relock_lookup(znode_t
*sdzp
, const struct componentname
*scnp
,
2915 znode_t
**szpp
, znode_t
*tdzp
, const struct componentname
*tcnp
,
2923 * Before using sdzp and tdzp we must ensure that they are live.
2924 * As a porting legacy from illumos we have two things to worry
2925 * about. One is typical for FreeBSD and it is that the vnode is
2926 * not reclaimed (doomed). The other is that the znode is live.
2927 * The current code can invalidate the znode without acquiring the
2928 * corresponding vnode lock if the object represented by the znode
2929 * and vnode is no longer valid after a rollback or receive operation.
2930 * z_teardown_lock hidden behind ZFS_ENTER and ZFS_EXIT is the lock
2931 * that protects the znodes from the invalidation.
2933 zfsvfs
= sdzp
->z_zfsvfs
;
2934 ASSERT3P(zfsvfs
, ==, tdzp
->z_zfsvfs
);
2936 ZFS_VERIFY_ZP(sdzp
);
2937 ZFS_VERIFY_ZP(tdzp
);
2940 * Re-resolve svp to be certain it still exists and fetch the
2943 error
= zfs_dirent_lookup(sdzp
, scnp
->cn_nameptr
, &szp
, ZEXISTS
);
2945 /* Source entry invalid or not there. */
2946 if ((scnp
->cn_flags
& ISDOTDOT
) != 0 ||
2947 (scnp
->cn_namelen
== 1 && scnp
->cn_nameptr
[0] == '.'))
2948 error
= SET_ERROR(EINVAL
);
2954 * Re-resolve tvp, if it disappeared we just carry on.
2956 error
= zfs_dirent_lookup(tdzp
, tcnp
->cn_nameptr
, &tzp
, 0);
2959 if ((tcnp
->cn_flags
& ISDOTDOT
) != 0)
2960 error
= SET_ERROR(EINVAL
);
2970 * We acquire all but fdvp locks using non-blocking acquisitions. If we
2971 * fail to acquire any lock in the path we will drop all held locks,
2972 * acquire the new lock in a blocking fashion, and then release it and
2973 * restart the rename. This acquire/release step ensures that we do not
2974 * spin on a lock waiting for release. On error release all vnode locks
2975 * and decrement references the way tmpfs_rename() would do.
2978 zfs_rename_relock(struct vnode
*sdvp
, struct vnode
**svpp
,
2979 struct vnode
*tdvp
, struct vnode
**tvpp
,
2980 const struct componentname
*scnp
, const struct componentname
*tcnp
)
2982 struct vnode
*nvp
, *svp
, *tvp
;
2983 znode_t
*sdzp
, *tdzp
, *szp
, *tzp
;
2987 if (*tvpp
!= NULL
&& *tvpp
!= tdvp
)
2991 error
= vn_lock(sdvp
, LK_EXCLUSIVE
);
2994 error
= vn_lock(tdvp
, LK_EXCLUSIVE
| LK_NOWAIT
);
2999 error
= vn_lock(tdvp
, LK_EXCLUSIVE
);
3008 error
= zfs_rename_relock_lookup(sdzp
, scnp
, &szp
, tdzp
, tcnp
, &tzp
);
3015 tvp
= tzp
!= NULL
? ZTOV(tzp
) : NULL
;
3018 * Now try acquire locks on svp and tvp.
3021 error
= vn_lock(nvp
, LK_EXCLUSIVE
| LK_NOWAIT
);
3027 if (error
!= EBUSY
) {
3031 error
= vn_lock(nvp
, LK_EXCLUSIVE
);
3038 * Concurrent rename race.
3043 error
= SET_ERROR(EINVAL
);
3058 error
= vn_lock(nvp
, LK_EXCLUSIVE
| LK_NOWAIT
);
3063 if (error
!= EBUSY
) {
3067 error
= vn_lock(nvp
, LK_EXCLUSIVE
);
3085 * Note that we must use VRELE_ASYNC in this function as it walks
3086 * up the directory tree and vrele may need to acquire an exclusive
3087 * lock if a last reference to a vnode is dropped.
3090 zfs_rename_check(znode_t
*szp
, znode_t
*sdzp
, znode_t
*tdzp
)
3097 zfsvfs
= tdzp
->z_zfsvfs
;
3099 return (SET_ERROR(EINVAL
));
3102 if (tdzp
->z_id
== zfsvfs
->z_root
)
3106 ASSERT(!zp
->z_unlinked
);
3107 if ((error
= sa_lookup(zp
->z_sa_hdl
,
3108 SA_ZPL_PARENT(zfsvfs
), &parent
, sizeof (parent
))) != 0)
3111 if (parent
== szp
->z_id
) {
3112 error
= SET_ERROR(EINVAL
);
3115 if (parent
== zfsvfs
->z_root
)
3117 if (parent
== sdzp
->z_id
)
3120 error
= zfs_zget(zfsvfs
, parent
, &zp1
);
3125 VN_RELE_ASYNC(ZTOV(zp
),
3126 dsl_pool_zrele_taskq(
3127 dmu_objset_pool(zfsvfs
->z_os
)));
3131 if (error
== ENOTDIR
)
3132 panic("checkpath: .. not a directory\n");
3134 VN_RELE_ASYNC(ZTOV(zp
),
3135 dsl_pool_zrele_taskq(dmu_objset_pool(zfsvfs
->z_os
)));
3139 #if __FreeBSD_version < 1300124
3141 cache_vop_rename(struct vnode
*fdvp
, struct vnode
*fvp
, struct vnode
*tdvp
,
3142 struct vnode
*tvp
, struct componentname
*fcnp
, struct componentname
*tcnp
)
3148 cache_purge_negative(tdvp
);
3153 zfs_do_rename_impl(vnode_t
*sdvp
, vnode_t
**svpp
, struct componentname
*scnp
,
3154 vnode_t
*tdvp
, vnode_t
**tvpp
, struct componentname
*tcnp
,
3158 * Move an entry from the provided source directory to the target
3159 * directory. Change the entry name as indicated.
3161 * IN: sdvp - Source directory containing the "old entry".
3162 * scnp - Old entry name.
3163 * tdvp - Target directory to contain the "new entry".
3164 * tcnp - New entry name.
3165 * cr - credentials of caller.
3166 * INOUT: svpp - Source file
3167 * tvpp - Target file, may point to NULL initially
3169 * RETURN: 0 on success, error code on failure.
3172 * sdvp,tdvp - ctime|mtime updated
3175 zfs_do_rename(vnode_t
*sdvp
, vnode_t
**svpp
, struct componentname
*scnp
,
3176 vnode_t
*tdvp
, vnode_t
**tvpp
, struct componentname
*tcnp
,
3181 ASSERT_VOP_ELOCKED(tdvp
, __func__
);
3183 ASSERT_VOP_ELOCKED(*tvpp
, __func__
);
3185 /* Reject renames across filesystems. */
3186 if ((*svpp
)->v_mount
!= tdvp
->v_mount
||
3187 ((*tvpp
) != NULL
&& (*svpp
)->v_mount
!= (*tvpp
)->v_mount
)) {
3188 error
= SET_ERROR(EXDEV
);
3192 if (zfsctl_is_node(tdvp
)) {
3193 error
= SET_ERROR(EXDEV
);
3198 * Lock all four vnodes to ensure safety and semantics of renaming.
3200 error
= zfs_rename_relock(sdvp
, svpp
, tdvp
, tvpp
, scnp
, tcnp
);
3202 /* no vnodes are locked in the case of error here */
3206 error
= zfs_do_rename_impl(sdvp
, svpp
, scnp
, tdvp
, tvpp
, tcnp
, cr
);
3219 zfs_do_rename_impl(vnode_t
*sdvp
, vnode_t
**svpp
, struct componentname
*scnp
,
3220 vnode_t
*tdvp
, vnode_t
**tvpp
, struct componentname
*tcnp
,
3226 znode_t
*tdzp
, *sdzp
, *tzp
, *szp
;
3227 const char *snm
= scnp
->cn_nameptr
;
3228 const char *tnm
= tcnp
->cn_nameptr
;
3233 zfsvfs
= tdzp
->z_zfsvfs
;
3236 ZFS_VERIFY_ZP(tdzp
);
3237 ZFS_VERIFY_ZP(sdzp
);
3238 zilog
= zfsvfs
->z_log
;
3240 if (zfsvfs
->z_utf8
&& u8_validate(tnm
,
3241 strlen(tnm
), NULL
, U8_VALIDATE_ENTIRE
, &error
) < 0) {
3242 error
= SET_ERROR(EILSEQ
);
3246 /* If source and target are the same file, there is nothing to do. */
3247 if ((*svpp
) == (*tvpp
)) {
3252 if (((*svpp
)->v_type
== VDIR
&& (*svpp
)->v_mountedhere
!= NULL
) ||
3253 ((*tvpp
) != NULL
&& (*tvpp
)->v_type
== VDIR
&&
3254 (*tvpp
)->v_mountedhere
!= NULL
)) {
3255 error
= SET_ERROR(EXDEV
);
3261 tzp
= *tvpp
== NULL
? NULL
: VTOZ(*tvpp
);
3266 * This is to prevent the creation of links into attribute space
3267 * by renaming a linked file into/outof an attribute directory.
3268 * See the comment in zfs_link() for why this is considered bad.
3270 if ((tdzp
->z_pflags
& ZFS_XATTR
) != (sdzp
->z_pflags
& ZFS_XATTR
)) {
3271 error
= SET_ERROR(EINVAL
);
3276 * If we are using project inheritance, means if the directory has
3277 * ZFS_PROJINHERIT set, then its descendant directories will inherit
3278 * not only the project ID, but also the ZFS_PROJINHERIT flag. Under
3279 * such case, we only allow renames into our tree when the project
3282 if (tdzp
->z_pflags
& ZFS_PROJINHERIT
&&
3283 tdzp
->z_projid
!= szp
->z_projid
) {
3284 error
= SET_ERROR(EXDEV
);
3289 * Must have write access at the source to remove the old entry
3290 * and write access at the target to create the new entry.
3291 * Note that if target and source are the same, this can be
3292 * done in a single check.
3294 if ((error
= zfs_zaccess_rename(sdzp
, szp
, tdzp
, tzp
, cr
)))
3297 if ((*svpp
)->v_type
== VDIR
) {
3299 * Avoid ".", "..", and aliases of "." for obvious reasons.
3301 if ((scnp
->cn_namelen
== 1 && scnp
->cn_nameptr
[0] == '.') ||
3303 (scnp
->cn_flags
| tcnp
->cn_flags
) & ISDOTDOT
) {
3309 * Check to make sure rename is valid.
3310 * Can't do a move like this: /usr/a/b to /usr/a/b/c/d
3312 if ((error
= zfs_rename_check(szp
, sdzp
, tdzp
)))
3317 * Does target exist?
3321 * Source and target must be the same type.
3323 if ((*svpp
)->v_type
== VDIR
) {
3324 if ((*tvpp
)->v_type
!= VDIR
) {
3325 error
= SET_ERROR(ENOTDIR
);
3333 if ((*tvpp
)->v_type
== VDIR
) {
3334 error
= SET_ERROR(EISDIR
);
3340 vn_seqc_write_begin(*svpp
);
3341 vn_seqc_write_begin(sdvp
);
3343 vn_seqc_write_begin(*tvpp
);
3345 vn_seqc_write_begin(tdvp
);
3347 vnevent_rename_src(*svpp
, sdvp
, scnp
->cn_nameptr
, ct
);
3349 vnevent_rename_dest(*tvpp
, tdvp
, tnm
, ct
);
3352 * notify the target directory if it is not the same
3353 * as source directory.
3356 vnevent_rename_dest_dir(tdvp
, ct
);
3359 tx
= dmu_tx_create(zfsvfs
->z_os
);
3360 dmu_tx_hold_sa(tx
, szp
->z_sa_hdl
, B_FALSE
);
3361 dmu_tx_hold_sa(tx
, sdzp
->z_sa_hdl
, B_FALSE
);
3362 dmu_tx_hold_zap(tx
, sdzp
->z_id
, FALSE
, snm
);
3363 dmu_tx_hold_zap(tx
, tdzp
->z_id
, TRUE
, tnm
);
3365 dmu_tx_hold_sa(tx
, tdzp
->z_sa_hdl
, B_FALSE
);
3366 zfs_sa_upgrade_txholds(tx
, tdzp
);
3369 dmu_tx_hold_sa(tx
, tzp
->z_sa_hdl
, B_FALSE
);
3370 zfs_sa_upgrade_txholds(tx
, tzp
);
3373 zfs_sa_upgrade_txholds(tx
, szp
);
3374 dmu_tx_hold_zap(tx
, zfsvfs
->z_unlinkedobj
, FALSE
, NULL
);
3375 error
= dmu_tx_assign(tx
, TXG_WAIT
);
3381 if (tzp
) /* Attempt to remove the existing target */
3382 error
= zfs_link_destroy(tdzp
, tnm
, tzp
, tx
, 0, NULL
);
3385 error
= zfs_link_create(tdzp
, tnm
, szp
, tx
, ZRENAMING
);
3387 szp
->z_pflags
|= ZFS_AV_MODIFIED
;
3389 error
= sa_update(szp
->z_sa_hdl
, SA_ZPL_FLAGS(zfsvfs
),
3390 (void *)&szp
->z_pflags
, sizeof (uint64_t), tx
);
3393 error
= zfs_link_destroy(sdzp
, snm
, szp
, tx
, ZRENAMING
,
3396 zfs_log_rename(zilog
, tx
, TX_RENAME
, sdzp
,
3397 snm
, tdzp
, tnm
, szp
);
3400 * Update path information for the target vnode
3402 vn_renamepath(tdvp
, *svpp
, tnm
, strlen(tnm
));
3405 * At this point, we have successfully created
3406 * the target name, but have failed to remove
3407 * the source name. Since the create was done
3408 * with the ZRENAMING flag, there are
3409 * complications; for one, the link count is
3410 * wrong. The easiest way to deal with this
3411 * is to remove the newly created target, and
3412 * return the original error. This must
3413 * succeed; fortunately, it is very unlikely to
3414 * fail, since we just created it.
3416 VERIFY0(zfs_link_destroy(tdzp
, tnm
, szp
, tx
,
3421 cache_vop_rename(sdvp
, *svpp
, tdvp
, *tvpp
, scnp
, tcnp
);
3428 vn_seqc_write_end(*svpp
);
3429 vn_seqc_write_end(sdvp
);
3431 vn_seqc_write_end(*tvpp
);
3433 vn_seqc_write_end(tdvp
);
3436 if (error
== 0 && zfsvfs
->z_os
->os_sync
== ZFS_SYNC_ALWAYS
)
3437 zil_commit(zilog
, 0);
3444 zfs_rename(znode_t
*sdzp
, const char *sname
, znode_t
*tdzp
, const char *tname
,
3445 cred_t
*cr
, int flags
)
3447 struct componentname scn
, tcn
;
3448 vnode_t
*sdvp
, *tdvp
;
3455 error
= zfs_lookup_internal(sdzp
, sname
, &svp
, &scn
, DELETE
);
3456 if (sdzp
->z_zfsvfs
->z_replay
== B_FALSE
)
3462 vn_lock(tdvp
, LK_EXCLUSIVE
| LK_RETRY
);
3463 error
= zfs_lookup_internal(tdzp
, tname
, &tvp
, &tcn
, RENAME
);
3464 if (error
== EJUSTRETURN
)
3466 else if (error
!= 0) {
3471 error
= zfs_do_rename(sdvp
, &svp
, &scn
, tdvp
, &tvp
, &tcn
, cr
);
3482 * Insert the indicated symbolic reference entry into the directory.
3484 * IN: dvp - Directory to contain new symbolic link.
3485 * link - Name for new symlink entry.
3486 * vap - Attributes of new entry.
3487 * cr - credentials of caller.
3488 * ct - caller context
3489 * flags - case flags
3491 * RETURN: 0 on success, error code on failure.
3494 * dvp - ctime|mtime updated
3497 zfs_symlink(znode_t
*dzp
, const char *name
, vattr_t
*vap
,
3498 const char *link
, znode_t
**zpp
, cred_t
*cr
, int flags
)
3503 zfsvfs_t
*zfsvfs
= dzp
->z_zfsvfs
;
3505 uint64_t len
= strlen(link
);
3507 zfs_acl_ids_t acl_ids
;
3508 boolean_t fuid_dirtied
;
3509 uint64_t txtype
= TX_SYMLINK
;
3511 ASSERT3S(vap
->va_type
, ==, VLNK
);
3515 zilog
= zfsvfs
->z_log
;
3517 if (zfsvfs
->z_utf8
&& u8_validate(name
, strlen(name
),
3518 NULL
, U8_VALIDATE_ENTIRE
, &error
) < 0) {
3520 return (SET_ERROR(EILSEQ
));
3523 if (len
> MAXPATHLEN
) {
3525 return (SET_ERROR(ENAMETOOLONG
));
3528 if ((error
= zfs_acl_ids_create(dzp
, 0,
3529 vap
, cr
, NULL
, &acl_ids
)) != 0) {
3535 * Attempt to lock directory; fail if entry already exists.
3537 error
= zfs_dirent_lookup(dzp
, name
, &zp
, ZNEW
);
3539 zfs_acl_ids_free(&acl_ids
);
3544 if ((error
= zfs_zaccess(dzp
, ACE_ADD_FILE
, 0, B_FALSE
, cr
))) {
3545 zfs_acl_ids_free(&acl_ids
);
3550 if (zfs_acl_ids_overquota(zfsvfs
, &acl_ids
,
3552 zfs_acl_ids_free(&acl_ids
);
3554 return (SET_ERROR(EDQUOT
));
3557 getnewvnode_reserve_();
3558 tx
= dmu_tx_create(zfsvfs
->z_os
);
3559 fuid_dirtied
= zfsvfs
->z_fuid_dirty
;
3560 dmu_tx_hold_write(tx
, DMU_NEW_OBJECT
, 0, MAX(1, len
));
3561 dmu_tx_hold_zap(tx
, dzp
->z_id
, TRUE
, name
);
3562 dmu_tx_hold_sa_create(tx
, acl_ids
.z_aclp
->z_acl_bytes
+
3563 ZFS_SA_BASE_ATTR_SIZE
+ len
);
3564 dmu_tx_hold_sa(tx
, dzp
->z_sa_hdl
, B_FALSE
);
3565 if (!zfsvfs
->z_use_sa
&& acl_ids
.z_aclp
->z_acl_bytes
> ZFS_ACE_SPACE
) {
3566 dmu_tx_hold_write(tx
, DMU_NEW_OBJECT
, 0,
3567 acl_ids
.z_aclp
->z_acl_bytes
);
3570 zfs_fuid_txhold(zfsvfs
, tx
);
3571 error
= dmu_tx_assign(tx
, TXG_WAIT
);
3573 zfs_acl_ids_free(&acl_ids
);
3575 getnewvnode_drop_reserve();
3581 * Create a new object for the symlink.
3582 * for version 4 ZPL datasets the symlink will be an SA attribute
3584 zfs_mknode(dzp
, vap
, tx
, cr
, 0, &zp
, &acl_ids
);
3587 zfs_fuid_sync(zfsvfs
, tx
);
3590 error
= sa_update(zp
->z_sa_hdl
, SA_ZPL_SYMLINK(zfsvfs
),
3591 __DECONST(void *, link
), len
, tx
);
3593 zfs_sa_symlink(zp
, __DECONST(char *, link
), len
, tx
);
3596 (void) sa_update(zp
->z_sa_hdl
, SA_ZPL_SIZE(zfsvfs
),
3597 &zp
->z_size
, sizeof (zp
->z_size
), tx
);
3599 * Insert the new object into the directory.
3601 (void) zfs_link_create(dzp
, name
, zp
, tx
, ZNEW
);
3603 zfs_log_symlink(zilog
, tx
, txtype
, dzp
, zp
, name
, link
);
3606 zfs_acl_ids_free(&acl_ids
);
3610 getnewvnode_drop_reserve();
3612 if (zfsvfs
->z_os
->os_sync
== ZFS_SYNC_ALWAYS
)
3613 zil_commit(zilog
, 0);
3620 * Return, in the buffer contained in the provided uio structure,
3621 * the symbolic path referred to by vp.
3623 * IN: vp - vnode of symbolic link.
3624 * uio - structure to contain the link path.
3625 * cr - credentials of caller.
3626 * ct - caller context
3628 * OUT: uio - structure containing the link path.
3630 * RETURN: 0 on success, error code on failure.
3633 * vp - atime updated
3636 zfs_readlink(vnode_t
*vp
, zfs_uio_t
*uio
, cred_t
*cr
, caller_context_t
*ct
)
3638 (void) cr
, (void) ct
;
3639 znode_t
*zp
= VTOZ(vp
);
3640 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
3647 error
= sa_lookup_uio(zp
->z_sa_hdl
,
3648 SA_ZPL_SYMLINK(zfsvfs
), uio
);
3650 error
= zfs_sa_readlink(zp
, uio
);
3652 ZFS_ACCESSTIME_STAMP(zfsvfs
, zp
);
3659 * Insert a new entry into directory tdvp referencing svp.
3661 * IN: tdvp - Directory to contain new entry.
3662 * svp - vnode of new entry.
3663 * name - name of new entry.
3664 * cr - credentials of caller.
3666 * RETURN: 0 on success, error code on failure.
3669 * tdvp - ctime|mtime updated
3670 * svp - ctime updated
3673 zfs_link(znode_t
*tdzp
, znode_t
*szp
, const char *name
, cred_t
*cr
,
3678 zfsvfs_t
*zfsvfs
= tdzp
->z_zfsvfs
;
3685 ASSERT3S(ZTOV(tdzp
)->v_type
, ==, VDIR
);
3688 ZFS_VERIFY_ZP(tdzp
);
3689 zilog
= zfsvfs
->z_log
;
3692 * POSIX dictates that we return EPERM here.
3693 * Better choices include ENOTSUP or EISDIR.
3695 if (ZTOV(szp
)->v_type
== VDIR
) {
3697 return (SET_ERROR(EPERM
));
3703 * If we are using project inheritance, means if the directory has
3704 * ZFS_PROJINHERIT set, then its descendant directories will inherit
3705 * not only the project ID, but also the ZFS_PROJINHERIT flag. Under
3706 * such case, we only allow hard link creation in our tree when the
3707 * project IDs are the same.
3709 if (tdzp
->z_pflags
& ZFS_PROJINHERIT
&&
3710 tdzp
->z_projid
!= szp
->z_projid
) {
3712 return (SET_ERROR(EXDEV
));
3715 if (szp
->z_pflags
& (ZFS_APPENDONLY
|
3716 ZFS_IMMUTABLE
| ZFS_READONLY
)) {
3718 return (SET_ERROR(EPERM
));
3721 /* Prevent links to .zfs/shares files */
3723 if ((error
= sa_lookup(szp
->z_sa_hdl
, SA_ZPL_PARENT(zfsvfs
),
3724 &parent
, sizeof (uint64_t))) != 0) {
3728 if (parent
== zfsvfs
->z_shares_dir
) {
3730 return (SET_ERROR(EPERM
));
3733 if (zfsvfs
->z_utf8
&& u8_validate(name
,
3734 strlen(name
), NULL
, U8_VALIDATE_ENTIRE
, &error
) < 0) {
3736 return (SET_ERROR(EILSEQ
));
3740 * We do not support links between attributes and non-attributes
3741 * because of the potential security risk of creating links
3742 * into "normal" file space in order to circumvent restrictions
3743 * imposed in attribute space.
3745 if ((szp
->z_pflags
& ZFS_XATTR
) != (tdzp
->z_pflags
& ZFS_XATTR
)) {
3747 return (SET_ERROR(EINVAL
));
3751 owner
= zfs_fuid_map_id(zfsvfs
, szp
->z_uid
, cr
, ZFS_OWNER
);
3752 if (owner
!= crgetuid(cr
) && secpolicy_basic_link(ZTOV(szp
), cr
) != 0) {
3754 return (SET_ERROR(EPERM
));
3757 if ((error
= zfs_zaccess(tdzp
, ACE_ADD_FILE
, 0, B_FALSE
, cr
))) {
3763 * Attempt to lock directory; fail if entry already exists.
3765 error
= zfs_dirent_lookup(tdzp
, name
, &tzp
, ZNEW
);
3771 tx
= dmu_tx_create(zfsvfs
->z_os
);
3772 dmu_tx_hold_sa(tx
, szp
->z_sa_hdl
, B_FALSE
);
3773 dmu_tx_hold_zap(tx
, tdzp
->z_id
, TRUE
, name
);
3774 zfs_sa_upgrade_txholds(tx
, szp
);
3775 zfs_sa_upgrade_txholds(tx
, tdzp
);
3776 error
= dmu_tx_assign(tx
, TXG_WAIT
);
3783 error
= zfs_link_create(tdzp
, name
, szp
, tx
, 0);
3786 uint64_t txtype
= TX_LINK
;
3787 zfs_log_link(zilog
, tx
, txtype
, tdzp
, szp
, name
);
3793 vnevent_link(ZTOV(szp
), ct
);
3796 if (zfsvfs
->z_os
->os_sync
== ZFS_SYNC_ALWAYS
)
3797 zil_commit(zilog
, 0);
3804 * Free or allocate space in a file. Currently, this function only
3805 * supports the `F_FREESP' command. However, this command is somewhat
3806 * misnamed, as its functionality includes the ability to allocate as
3807 * well as free space.
3809 * IN: ip - inode of file to free data in.
3810 * cmd - action to take (only F_FREESP supported).
3811 * bfp - section of file to free/alloc.
3812 * flag - current file open mode flags.
3813 * offset - current file offset.
3814 * cr - credentials of caller.
3816 * RETURN: 0 on success, error code on failure.
3819 * ip - ctime|mtime updated
3822 zfs_space(znode_t
*zp
, int cmd
, flock64_t
*bfp
, int flag
,
3823 offset_t offset
, cred_t
*cr
)
3826 zfsvfs_t
*zfsvfs
= ZTOZSB(zp
);
3833 if (cmd
!= F_FREESP
) {
3835 return (SET_ERROR(EINVAL
));
3839 * Callers might not be able to detect properly that we are read-only,
3840 * so check it explicitly here.
3842 if (zfs_is_readonly(zfsvfs
)) {
3844 return (SET_ERROR(EROFS
));
3847 if (bfp
->l_len
< 0) {
3849 return (SET_ERROR(EINVAL
));
3853 * Permissions aren't checked on Solaris because on this OS
3854 * zfs_space() can only be called with an opened file handle.
3855 * On Linux we can get here through truncate_range() which
3856 * operates directly on inodes, so we need to check access rights.
3858 if ((error
= zfs_zaccess(zp
, ACE_WRITE_DATA
, 0, B_FALSE
, cr
))) {
3864 len
= bfp
->l_len
; /* 0 means from off to end of file */
3866 error
= zfs_freesp(zp
, off
, len
, flag
, TRUE
);
3873 zfs_inactive(vnode_t
*vp
, cred_t
*cr
, caller_context_t
*ct
)
3875 (void) cr
, (void) ct
;
3876 znode_t
*zp
= VTOZ(vp
);
3877 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
3880 ZFS_TEARDOWN_INACTIVE_ENTER_READ(zfsvfs
);
3881 if (zp
->z_sa_hdl
== NULL
) {
3883 * The fs has been unmounted, or we did a
3884 * suspend/resume and this file no longer exists.
3886 ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs
);
3891 if (zp
->z_unlinked
) {
3893 * Fast path to recycle a vnode of a removed file.
3895 ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs
);
3900 if (zp
->z_atime_dirty
&& zp
->z_unlinked
== 0) {
3901 dmu_tx_t
*tx
= dmu_tx_create(zfsvfs
->z_os
);
3903 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
3904 zfs_sa_upgrade_txholds(tx
, zp
);
3905 error
= dmu_tx_assign(tx
, TXG_WAIT
);
3909 (void) sa_update(zp
->z_sa_hdl
, SA_ZPL_ATIME(zfsvfs
),
3910 (void *)&zp
->z_atime
, sizeof (zp
->z_atime
), tx
);
3911 zp
->z_atime_dirty
= 0;
3915 ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs
);
3919 _Static_assert(sizeof (struct zfid_short
) <= sizeof (struct fid
),
3920 "struct zfid_short bigger than struct fid");
3921 _Static_assert(sizeof (struct zfid_long
) <= sizeof (struct fid
),
3922 "struct zfid_long bigger than struct fid");
3925 zfs_fid(vnode_t
*vp
, fid_t
*fidp
, caller_context_t
*ct
)
3928 znode_t
*zp
= VTOZ(vp
);
3929 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
3932 uint64_t object
= zp
->z_id
;
3939 if ((error
= sa_lookup(zp
->z_sa_hdl
, SA_ZPL_GEN(zfsvfs
),
3940 &gen64
, sizeof (uint64_t))) != 0) {
3945 gen
= (uint32_t)gen64
;
3947 size
= (zfsvfs
->z_parent
!= zfsvfs
) ? LONG_FID_LEN
: SHORT_FID_LEN
;
3948 fidp
->fid_len
= size
;
3950 zfid
= (zfid_short_t
*)fidp
;
3952 zfid
->zf_len
= size
;
3954 for (i
= 0; i
< sizeof (zfid
->zf_object
); i
++)
3955 zfid
->zf_object
[i
] = (uint8_t)(object
>> (8 * i
));
3957 /* Must have a non-zero generation number to distinguish from .zfs */
3960 for (i
= 0; i
< sizeof (zfid
->zf_gen
); i
++)
3961 zfid
->zf_gen
[i
] = (uint8_t)(gen
>> (8 * i
));
3963 if (size
== LONG_FID_LEN
) {
3964 uint64_t objsetid
= dmu_objset_id(zfsvfs
->z_os
);
3967 zlfid
= (zfid_long_t
*)fidp
;
3969 for (i
= 0; i
< sizeof (zlfid
->zf_setid
); i
++)
3970 zlfid
->zf_setid
[i
] = (uint8_t)(objsetid
>> (8 * i
));
3972 /* XXX - this should be the generation number for the objset */
3973 for (i
= 0; i
< sizeof (zlfid
->zf_setgen
); i
++)
3974 zlfid
->zf_setgen
[i
] = 0;
3982 zfs_pathconf(vnode_t
*vp
, int cmd
, ulong_t
*valp
, cred_t
*cr
,
3983 caller_context_t
*ct
)
3990 *valp
= MIN(LONG_MAX
, ZFS_LINK_MAX
);
3993 case _PC_FILESIZEBITS
:
3996 case _PC_MIN_HOLE_SIZE
:
3997 *valp
= (int)SPA_MINBLOCKSIZE
;
3999 case _PC_ACL_EXTENDED
:
4000 #if 0 /* POSIX ACLs are not implemented for ZFS on FreeBSD yet. */
4002 zfsvfs
= zp
->z_zfsvfs
;
4005 *valp
= zfsvfs
->z_acl_type
== ZFSACLTYPE_POSIX
? 1 : 0;
4014 zfsvfs
= zp
->z_zfsvfs
;
4017 *valp
= zfsvfs
->z_acl_type
== ZFS_ACLTYPE_NFSV4
? 1 : 0;
4021 case _PC_ACL_PATH_MAX
:
4022 *valp
= ACL_MAX_ENTRIES
;
4026 return (EOPNOTSUPP
);
4031 zfs_getpages(struct vnode
*vp
, vm_page_t
*ma
, int count
, int *rbehind
,
4034 znode_t
*zp
= VTOZ(vp
);
4035 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
4036 zfs_locked_range_t
*lr
;
4038 off_t start
, end
, obj_size
;
4040 int pgsin_b
, pgsin_a
;
4046 start
= IDX_TO_OFF(ma
[0]->pindex
);
4047 end
= IDX_TO_OFF(ma
[count
- 1]->pindex
+ 1);
4050 * Lock a range covering all required and optional pages.
4051 * Note that we need to handle the case of the block size growing.
4054 blksz
= zp
->z_blksz
;
4055 lr
= zfs_rangelock_tryenter(&zp
->z_rangelock
,
4056 rounddown(start
, blksz
),
4057 roundup(end
, blksz
) - rounddown(start
, blksz
), RL_READER
);
4059 if (rahead
!= NULL
) {
4063 if (rbehind
!= NULL
) {
4069 if (blksz
== zp
->z_blksz
)
4071 zfs_rangelock_exit(lr
);
4074 object
= ma
[0]->object
;
4075 zfs_vmobject_wlock(object
);
4076 obj_size
= object
->un_pager
.vnp
.vnp_size
;
4077 zfs_vmobject_wunlock(object
);
4078 if (IDX_TO_OFF(ma
[count
- 1]->pindex
) >= obj_size
) {
4080 zfs_rangelock_exit(lr
);
4082 return (zfs_vm_pagerret_bad
);
4086 if (rbehind
!= NULL
) {
4087 pgsin_b
= OFF_TO_IDX(start
- rounddown(start
, blksz
));
4088 pgsin_b
= MIN(*rbehind
, pgsin_b
);
4092 if (rahead
!= NULL
) {
4093 pgsin_a
= OFF_TO_IDX(roundup(end
, blksz
) - end
);
4094 if (end
+ IDX_TO_OFF(pgsin_a
) >= obj_size
)
4095 pgsin_a
= OFF_TO_IDX(round_page(obj_size
) - end
);
4096 pgsin_a
= MIN(*rahead
, pgsin_a
);
4100 * NB: we need to pass the exact byte size of the data that we expect
4101 * to read after accounting for the file size. This is required because
4102 * ZFS will panic if we request DMU to read beyond the end of the last
4105 error
= dmu_read_pages(zfsvfs
->z_os
, zp
->z_id
, ma
, count
, &pgsin_b
,
4106 &pgsin_a
, MIN(end
, obj_size
) - (end
- PAGE_SIZE
));
4109 zfs_rangelock_exit(lr
);
4110 ZFS_ACCESSTIME_STAMP(zfsvfs
, zp
);
4112 dataset_kstats_update_read_kstats(&zfsvfs
->z_kstat
, count
*PAGE_SIZE
);
4117 return (zfs_vm_pagerret_error
);
4119 VM_CNT_INC(v_vnodein
);
4120 VM_CNT_ADD(v_vnodepgsin
, count
+ pgsin_b
+ pgsin_a
);
4121 if (rbehind
!= NULL
)
4125 return (zfs_vm_pagerret_ok
);
4128 #ifndef _SYS_SYSPROTO_H_
4129 struct vop_getpages_args
{
4139 zfs_freebsd_getpages(struct vop_getpages_args
*ap
)
4142 return (zfs_getpages(ap
->a_vp
, ap
->a_m
, ap
->a_count
, ap
->a_rbehind
,
4147 zfs_putpages(struct vnode
*vp
, vm_page_t
*ma
, size_t len
, int flags
,
4150 znode_t
*zp
= VTOZ(vp
);
4151 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
4152 zfs_locked_range_t
*lr
;
4160 vm_ooffset_t lo_off
;
4171 object
= vp
->v_object
;
4175 KASSERT(ma
[0]->object
== object
, ("mismatching object"));
4176 KASSERT(len
> 0 && (len
& PAGE_MASK
) == 0, ("unexpected length"));
4178 for (i
= 0; i
< pcount
; i
++)
4179 rtvals
[i
] = zfs_vm_pagerret_error
;
4181 off
= IDX_TO_OFF(ma
[0]->pindex
);
4182 blksz
= zp
->z_blksz
;
4183 lo_off
= rounddown(off
, blksz
);
4184 lo_len
= roundup(len
+ (off
- lo_off
), blksz
);
4185 lr
= zfs_rangelock_enter(&zp
->z_rangelock
, lo_off
, lo_len
, RL_WRITER
);
4187 zfs_vmobject_wlock(object
);
4188 if (len
+ off
> object
->un_pager
.vnp
.vnp_size
) {
4189 if (object
->un_pager
.vnp
.vnp_size
> off
) {
4192 len
= object
->un_pager
.vnp
.vnp_size
- off
;
4194 if ((pgoff
= (int)len
& PAGE_MASK
) != 0) {
4196 * If the object is locked and the following
4197 * conditions hold, then the page's dirty
4198 * field cannot be concurrently changed by a
4202 vm_page_assert_sbusied(m
);
4203 KASSERT(!pmap_page_is_write_mapped(m
),
4204 ("zfs_putpages: page %p is not read-only",
4206 vm_page_clear_dirty(m
, pgoff
, PAGE_SIZE
-
4213 if (ncount
< pcount
) {
4214 for (i
= ncount
; i
< pcount
; i
++) {
4215 rtvals
[i
] = zfs_vm_pagerret_bad
;
4219 zfs_vmobject_wunlock(object
);
4224 if (zfs_id_overblockquota(zfsvfs
, DMU_USERUSED_OBJECT
, zp
->z_uid
) ||
4225 zfs_id_overblockquota(zfsvfs
, DMU_GROUPUSED_OBJECT
, zp
->z_gid
) ||
4226 (zp
->z_projid
!= ZFS_DEFAULT_PROJID
&&
4227 zfs_id_overblockquota(zfsvfs
, DMU_PROJECTUSED_OBJECT
,
4232 tx
= dmu_tx_create(zfsvfs
->z_os
);
4233 dmu_tx_hold_write(tx
, zp
->z_id
, off
, len
);
4235 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
4236 zfs_sa_upgrade_txholds(tx
, zp
);
4237 err
= dmu_tx_assign(tx
, TXG_WAIT
);
4243 if (zp
->z_blksz
< PAGE_SIZE
) {
4244 for (i
= 0; len
> 0; off
+= tocopy
, len
-= tocopy
, i
++) {
4245 tocopy
= len
> PAGE_SIZE
? PAGE_SIZE
: len
;
4246 va
= zfs_map_page(ma
[i
], &sf
);
4247 dmu_write(zfsvfs
->z_os
, zp
->z_id
, off
, tocopy
, va
, tx
);
4251 err
= dmu_write_pages(zfsvfs
->z_os
, zp
->z_id
, off
, len
, ma
, tx
);
4255 uint64_t mtime
[2], ctime
[2];
4256 sa_bulk_attr_t bulk
[3];
4259 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_MTIME(zfsvfs
), NULL
,
4261 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_CTIME(zfsvfs
), NULL
,
4263 SA_ADD_BULK_ATTR(bulk
, count
, SA_ZPL_FLAGS(zfsvfs
), NULL
,
4265 zfs_tstamp_update_setup(zp
, CONTENT_MODIFIED
, mtime
, ctime
);
4266 err
= sa_bulk_update(zp
->z_sa_hdl
, bulk
, count
, tx
);
4269 * XXX we should be passing a callback to undirty
4270 * but that would make the locking messier
4272 zfs_log_write(zfsvfs
->z_log
, tx
, TX_WRITE
, zp
, off
,
4273 len
, 0, NULL
, NULL
);
4275 zfs_vmobject_wlock(object
);
4276 for (i
= 0; i
< ncount
; i
++) {
4277 rtvals
[i
] = zfs_vm_pagerret_ok
;
4278 vm_page_undirty(ma
[i
]);
4280 zfs_vmobject_wunlock(object
);
4281 VM_CNT_INC(v_vnodeout
);
4282 VM_CNT_ADD(v_vnodepgsout
, ncount
);
4287 zfs_rangelock_exit(lr
);
4288 if ((flags
& (zfs_vm_pagerput_sync
| zfs_vm_pagerput_inval
)) != 0 ||
4289 zfsvfs
->z_os
->os_sync
== ZFS_SYNC_ALWAYS
)
4290 zil_commit(zfsvfs
->z_log
, zp
->z_id
);
4292 dataset_kstats_update_write_kstats(&zfsvfs
->z_kstat
, len
);
4298 #ifndef _SYS_SYSPROTO_H_
4299 struct vop_putpages_args
{
4309 zfs_freebsd_putpages(struct vop_putpages_args
*ap
)
4312 return (zfs_putpages(ap
->a_vp
, ap
->a_m
, ap
->a_count
, ap
->a_sync
,
4316 #ifndef _SYS_SYSPROTO_H_
4317 struct vop_bmap_args
{
4320 struct bufobj
**a_bop
;
4328 zfs_freebsd_bmap(struct vop_bmap_args
*ap
)
4331 if (ap
->a_bop
!= NULL
)
4332 *ap
->a_bop
= &ap
->a_vp
->v_bufobj
;
4333 if (ap
->a_bnp
!= NULL
)
4334 *ap
->a_bnp
= ap
->a_bn
;
4335 if (ap
->a_runp
!= NULL
)
4337 if (ap
->a_runb
!= NULL
)
4343 #ifndef _SYS_SYSPROTO_H_
4344 struct vop_open_args
{
4347 struct ucred
*a_cred
;
4348 struct thread
*a_td
;
4353 zfs_freebsd_open(struct vop_open_args
*ap
)
4355 vnode_t
*vp
= ap
->a_vp
;
4356 znode_t
*zp
= VTOZ(vp
);
4359 error
= zfs_open(&vp
, ap
->a_mode
, ap
->a_cred
);
4361 vnode_create_vobject(vp
, zp
->z_size
, ap
->a_td
);
4365 #ifndef _SYS_SYSPROTO_H_
4366 struct vop_close_args
{
4369 struct ucred
*a_cred
;
4370 struct thread
*a_td
;
4375 zfs_freebsd_close(struct vop_close_args
*ap
)
4378 return (zfs_close(ap
->a_vp
, ap
->a_fflag
, 1, 0, ap
->a_cred
));
4381 #ifndef _SYS_SYSPROTO_H_
4382 struct vop_ioctl_args
{
4393 zfs_freebsd_ioctl(struct vop_ioctl_args
*ap
)
4396 return (zfs_ioctl(ap
->a_vp
, ap
->a_command
, (intptr_t)ap
->a_data
,
4397 ap
->a_fflag
, ap
->a_cred
, NULL
));
4401 ioflags(int ioflags
)
4405 if (ioflags
& IO_APPEND
)
4407 if (ioflags
& IO_NDELAY
)
4409 if (ioflags
& IO_SYNC
)
4410 flags
|= (FSYNC
| FDSYNC
| FRSYNC
);
4415 #ifndef _SYS_SYSPROTO_H_
4416 struct vop_read_args
{
4420 struct ucred
*a_cred
;
4425 zfs_freebsd_read(struct vop_read_args
*ap
)
4428 zfs_uio_init(&uio
, ap
->a_uio
);
4429 return (zfs_read(VTOZ(ap
->a_vp
), &uio
, ioflags(ap
->a_ioflag
),
4433 #ifndef _SYS_SYSPROTO_H_
4434 struct vop_write_args
{
4438 struct ucred
*a_cred
;
4443 zfs_freebsd_write(struct vop_write_args
*ap
)
4446 zfs_uio_init(&uio
, ap
->a_uio
);
4447 return (zfs_write(VTOZ(ap
->a_vp
), &uio
, ioflags(ap
->a_ioflag
),
4451 #if __FreeBSD_version >= 1300102
4453 * VOP_FPLOOKUP_VEXEC routines are subject to special circumstances, see
4454 * the comment above cache_fplookup for details.
4457 zfs_freebsd_fplookup_vexec(struct vop_fplookup_vexec_args
*v
)
4465 if (__predict_false(zp
== NULL
))
4467 pflags
= atomic_load_64(&zp
->z_pflags
);
4468 if (pflags
& ZFS_AV_QUARANTINED
)
4470 if (pflags
& ZFS_XATTR
)
4472 if ((pflags
& ZFS_NO_EXECS_DENIED
) == 0)
4478 #if __FreeBSD_version >= 1300139
4480 zfs_freebsd_fplookup_symlink(struct vop_fplookup_symlink_args
*v
)
4488 if (__predict_false(zp
== NULL
)) {
4492 target
= atomic_load_consume_ptr(&zp
->z_cached_symlink
);
4493 if (target
== NULL
) {
4496 return (cache_symlink_resolve(v
->a_fpl
, target
, strlen(target
)));
4500 #ifndef _SYS_SYSPROTO_H_
4501 struct vop_access_args
{
4503 accmode_t a_accmode
;
4504 struct ucred
*a_cred
;
4505 struct thread
*a_td
;
4510 zfs_freebsd_access(struct vop_access_args
*ap
)
4512 vnode_t
*vp
= ap
->a_vp
;
4513 znode_t
*zp
= VTOZ(vp
);
4518 if (ap
->a_accmode
== VEXEC
) {
4519 if (zfs_fastaccesschk_execute(zp
, ap
->a_cred
) == 0)
4524 * ZFS itself only knowns about VREAD, VWRITE, VEXEC and VAPPEND,
4526 accmode
= ap
->a_accmode
& (VREAD
|VWRITE
|VEXEC
|VAPPEND
);
4528 error
= zfs_access(zp
, accmode
, 0, ap
->a_cred
);
4531 * VADMIN has to be handled by vaccess().
4534 accmode
= ap
->a_accmode
& ~(VREAD
|VWRITE
|VEXEC
|VAPPEND
);
4536 #if __FreeBSD_version >= 1300105
4537 error
= vaccess(vp
->v_type
, zp
->z_mode
, zp
->z_uid
,
4538 zp
->z_gid
, accmode
, ap
->a_cred
);
4540 error
= vaccess(vp
->v_type
, zp
->z_mode
, zp
->z_uid
,
4541 zp
->z_gid
, accmode
, ap
->a_cred
, NULL
);
4547 * For VEXEC, ensure that at least one execute bit is set for
4550 if (error
== 0 && (ap
->a_accmode
& VEXEC
) != 0 && vp
->v_type
!= VDIR
&&
4551 (zp
->z_mode
& (S_IXUSR
| S_IXGRP
| S_IXOTH
)) == 0) {
4558 #ifndef _SYS_SYSPROTO_H_
4559 struct vop_lookup_args
{
4560 struct vnode
*a_dvp
;
4561 struct vnode
**a_vpp
;
4562 struct componentname
*a_cnp
;
4567 zfs_freebsd_lookup(struct vop_lookup_args
*ap
, boolean_t cached
)
4569 struct componentname
*cnp
= ap
->a_cnp
;
4570 char nm
[NAME_MAX
+ 1];
4572 ASSERT3U(cnp
->cn_namelen
, <, sizeof (nm
));
4573 strlcpy(nm
, cnp
->cn_nameptr
, MIN(cnp
->cn_namelen
+ 1, sizeof (nm
)));
4575 return (zfs_lookup(ap
->a_dvp
, nm
, ap
->a_vpp
, cnp
, cnp
->cn_nameiop
,
4576 cnp
->cn_cred
, 0, cached
));
4580 zfs_freebsd_cachedlookup(struct vop_cachedlookup_args
*ap
)
4583 return (zfs_freebsd_lookup((struct vop_lookup_args
*)ap
, B_TRUE
));
4586 #ifndef _SYS_SYSPROTO_H_
4587 struct vop_lookup_args
{
4588 struct vnode
*a_dvp
;
4589 struct vnode
**a_vpp
;
4590 struct componentname
*a_cnp
;
4595 zfs_cache_lookup(struct vop_lookup_args
*ap
)
4599 zfsvfs
= ap
->a_dvp
->v_mount
->mnt_data
;
4600 if (zfsvfs
->z_use_namecache
)
4601 return (vfs_cache_lookup(ap
));
4603 return (zfs_freebsd_lookup(ap
, B_FALSE
));
4606 #ifndef _SYS_SYSPROTO_H_
4607 struct vop_create_args
{
4608 struct vnode
*a_dvp
;
4609 struct vnode
**a_vpp
;
4610 struct componentname
*a_cnp
;
4611 struct vattr
*a_vap
;
4616 zfs_freebsd_create(struct vop_create_args
*ap
)
4619 struct componentname
*cnp
= ap
->a_cnp
;
4620 vattr_t
*vap
= ap
->a_vap
;
4624 ASSERT(cnp
->cn_flags
& SAVENAME
);
4626 vattr_init_mask(vap
);
4627 mode
= vap
->va_mode
& ALLPERMS
;
4628 zfsvfs
= ap
->a_dvp
->v_mount
->mnt_data
;
4631 rc
= zfs_create(VTOZ(ap
->a_dvp
), cnp
->cn_nameptr
, vap
, !EXCL
, mode
,
4632 &zp
, cnp
->cn_cred
, 0 /* flag */, NULL
/* vsecattr */);
4634 *ap
->a_vpp
= ZTOV(zp
);
4635 if (zfsvfs
->z_use_namecache
&&
4636 rc
== 0 && (cnp
->cn_flags
& MAKEENTRY
) != 0)
4637 cache_enter(ap
->a_dvp
, *ap
->a_vpp
, cnp
);
4642 #ifndef _SYS_SYSPROTO_H_
4643 struct vop_remove_args
{
4644 struct vnode
*a_dvp
;
4646 struct componentname
*a_cnp
;
4651 zfs_freebsd_remove(struct vop_remove_args
*ap
)
4654 ASSERT(ap
->a_cnp
->cn_flags
& SAVENAME
);
4656 return (zfs_remove_(ap
->a_dvp
, ap
->a_vp
, ap
->a_cnp
->cn_nameptr
,
4657 ap
->a_cnp
->cn_cred
));
4660 #ifndef _SYS_SYSPROTO_H_
4661 struct vop_mkdir_args
{
4662 struct vnode
*a_dvp
;
4663 struct vnode
**a_vpp
;
4664 struct componentname
*a_cnp
;
4665 struct vattr
*a_vap
;
4670 zfs_freebsd_mkdir(struct vop_mkdir_args
*ap
)
4672 vattr_t
*vap
= ap
->a_vap
;
4676 ASSERT(ap
->a_cnp
->cn_flags
& SAVENAME
);
4678 vattr_init_mask(vap
);
4681 rc
= zfs_mkdir(VTOZ(ap
->a_dvp
), ap
->a_cnp
->cn_nameptr
, vap
, &zp
,
4682 ap
->a_cnp
->cn_cred
, 0, NULL
);
4685 *ap
->a_vpp
= ZTOV(zp
);
4689 #ifndef _SYS_SYSPROTO_H_
4690 struct vop_rmdir_args
{
4691 struct vnode
*a_dvp
;
4693 struct componentname
*a_cnp
;
4698 zfs_freebsd_rmdir(struct vop_rmdir_args
*ap
)
4700 struct componentname
*cnp
= ap
->a_cnp
;
4702 ASSERT(cnp
->cn_flags
& SAVENAME
);
4704 return (zfs_rmdir_(ap
->a_dvp
, ap
->a_vp
, cnp
->cn_nameptr
, cnp
->cn_cred
));
4707 #ifndef _SYS_SYSPROTO_H_
4708 struct vop_readdir_args
{
4711 struct ucred
*a_cred
;
4714 cookie_t
**a_cookies
;
4719 zfs_freebsd_readdir(struct vop_readdir_args
*ap
)
4722 zfs_uio_init(&uio
, ap
->a_uio
);
4723 return (zfs_readdir(ap
->a_vp
, &uio
, ap
->a_cred
, ap
->a_eofflag
,
4724 ap
->a_ncookies
, ap
->a_cookies
));
4727 #ifndef _SYS_SYSPROTO_H_
4728 struct vop_fsync_args
{
4731 struct thread
*a_td
;
4736 zfs_freebsd_fsync(struct vop_fsync_args
*ap
)
4740 return (zfs_fsync(VTOZ(ap
->a_vp
), 0, ap
->a_td
->td_ucred
));
4743 #ifndef _SYS_SYSPROTO_H_
4744 struct vop_getattr_args
{
4746 struct vattr
*a_vap
;
4747 struct ucred
*a_cred
;
4752 zfs_freebsd_getattr(struct vop_getattr_args
*ap
)
4754 vattr_t
*vap
= ap
->a_vap
;
4760 xvap
.xva_vattr
= *vap
;
4761 xvap
.xva_vattr
.va_mask
|= AT_XVATTR
;
4763 /* Convert chflags into ZFS-type flags. */
4764 /* XXX: what about SF_SETTABLE?. */
4765 XVA_SET_REQ(&xvap
, XAT_IMMUTABLE
);
4766 XVA_SET_REQ(&xvap
, XAT_APPENDONLY
);
4767 XVA_SET_REQ(&xvap
, XAT_NOUNLINK
);
4768 XVA_SET_REQ(&xvap
, XAT_NODUMP
);
4769 XVA_SET_REQ(&xvap
, XAT_READONLY
);
4770 XVA_SET_REQ(&xvap
, XAT_ARCHIVE
);
4771 XVA_SET_REQ(&xvap
, XAT_SYSTEM
);
4772 XVA_SET_REQ(&xvap
, XAT_HIDDEN
);
4773 XVA_SET_REQ(&xvap
, XAT_REPARSE
);
4774 XVA_SET_REQ(&xvap
, XAT_OFFLINE
);
4775 XVA_SET_REQ(&xvap
, XAT_SPARSE
);
4777 error
= zfs_getattr(ap
->a_vp
, (vattr_t
*)&xvap
, 0, ap
->a_cred
);
4781 /* Convert ZFS xattr into chflags. */
4782 #define FLAG_CHECK(fflag, xflag, xfield) do { \
4783 if (XVA_ISSET_RTN(&xvap, (xflag)) && (xfield) != 0) \
4784 fflags |= (fflag); \
4786 FLAG_CHECK(SF_IMMUTABLE
, XAT_IMMUTABLE
,
4787 xvap
.xva_xoptattrs
.xoa_immutable
);
4788 FLAG_CHECK(SF_APPEND
, XAT_APPENDONLY
,
4789 xvap
.xva_xoptattrs
.xoa_appendonly
);
4790 FLAG_CHECK(SF_NOUNLINK
, XAT_NOUNLINK
,
4791 xvap
.xva_xoptattrs
.xoa_nounlink
);
4792 FLAG_CHECK(UF_ARCHIVE
, XAT_ARCHIVE
,
4793 xvap
.xva_xoptattrs
.xoa_archive
);
4794 FLAG_CHECK(UF_NODUMP
, XAT_NODUMP
,
4795 xvap
.xva_xoptattrs
.xoa_nodump
);
4796 FLAG_CHECK(UF_READONLY
, XAT_READONLY
,
4797 xvap
.xva_xoptattrs
.xoa_readonly
);
4798 FLAG_CHECK(UF_SYSTEM
, XAT_SYSTEM
,
4799 xvap
.xva_xoptattrs
.xoa_system
);
4800 FLAG_CHECK(UF_HIDDEN
, XAT_HIDDEN
,
4801 xvap
.xva_xoptattrs
.xoa_hidden
);
4802 FLAG_CHECK(UF_REPARSE
, XAT_REPARSE
,
4803 xvap
.xva_xoptattrs
.xoa_reparse
);
4804 FLAG_CHECK(UF_OFFLINE
, XAT_OFFLINE
,
4805 xvap
.xva_xoptattrs
.xoa_offline
);
4806 FLAG_CHECK(UF_SPARSE
, XAT_SPARSE
,
4807 xvap
.xva_xoptattrs
.xoa_sparse
);
4810 *vap
= xvap
.xva_vattr
;
4811 vap
->va_flags
= fflags
;
4815 #ifndef _SYS_SYSPROTO_H_
4816 struct vop_setattr_args
{
4818 struct vattr
*a_vap
;
4819 struct ucred
*a_cred
;
4824 zfs_freebsd_setattr(struct vop_setattr_args
*ap
)
4826 vnode_t
*vp
= ap
->a_vp
;
4827 vattr_t
*vap
= ap
->a_vap
;
4828 cred_t
*cred
= ap
->a_cred
;
4833 vattr_init_mask(vap
);
4834 vap
->va_mask
&= ~AT_NOSET
;
4837 xvap
.xva_vattr
= *vap
;
4839 zflags
= VTOZ(vp
)->z_pflags
;
4841 if (vap
->va_flags
!= VNOVAL
) {
4842 zfsvfs_t
*zfsvfs
= VTOZ(vp
)->z_zfsvfs
;
4845 if (zfsvfs
->z_use_fuids
== B_FALSE
)
4846 return (EOPNOTSUPP
);
4848 fflags
= vap
->va_flags
;
4851 * We need to figure out whether it makes sense to allow
4852 * UF_REPARSE through, since we don't really have other
4853 * facilities to handle reparse points and zfs_setattr()
4854 * doesn't currently allow setting that attribute anyway.
4856 if ((fflags
& ~(SF_IMMUTABLE
|SF_APPEND
|SF_NOUNLINK
|UF_ARCHIVE
|
4857 UF_NODUMP
|UF_SYSTEM
|UF_HIDDEN
|UF_READONLY
|UF_REPARSE
|
4858 UF_OFFLINE
|UF_SPARSE
)) != 0)
4859 return (EOPNOTSUPP
);
4861 * Unprivileged processes are not permitted to unset system
4862 * flags, or modify flags if any system flags are set.
4863 * Privileged non-jail processes may not modify system flags
4864 * if securelevel > 0 and any existing system flags are set.
4865 * Privileged jail processes behave like privileged non-jail
4866 * processes if the PR_ALLOW_CHFLAGS permission bit is set;
4867 * otherwise, they behave like unprivileged processes.
4869 if (secpolicy_fs_owner(vp
->v_mount
, cred
) == 0 ||
4870 spl_priv_check_cred(cred
, PRIV_VFS_SYSFLAGS
) == 0) {
4872 (ZFS_IMMUTABLE
| ZFS_APPENDONLY
| ZFS_NOUNLINK
)) {
4873 error
= securelevel_gt(cred
, 0);
4879 * Callers may only modify the file flags on
4880 * objects they have VADMIN rights for.
4882 if ((error
= VOP_ACCESS(vp
, VADMIN
, cred
,
4886 (ZFS_IMMUTABLE
| ZFS_APPENDONLY
|
4891 (SF_IMMUTABLE
| SF_APPEND
| SF_NOUNLINK
)) {
4896 #define FLAG_CHANGE(fflag, zflag, xflag, xfield) do { \
4897 if (((fflags & (fflag)) && !(zflags & (zflag))) || \
4898 ((zflags & (zflag)) && !(fflags & (fflag)))) { \
4899 XVA_SET_REQ(&xvap, (xflag)); \
4900 (xfield) = ((fflags & (fflag)) != 0); \
4903 /* Convert chflags into ZFS-type flags. */
4904 /* XXX: what about SF_SETTABLE?. */
4905 FLAG_CHANGE(SF_IMMUTABLE
, ZFS_IMMUTABLE
, XAT_IMMUTABLE
,
4906 xvap
.xva_xoptattrs
.xoa_immutable
);
4907 FLAG_CHANGE(SF_APPEND
, ZFS_APPENDONLY
, XAT_APPENDONLY
,
4908 xvap
.xva_xoptattrs
.xoa_appendonly
);
4909 FLAG_CHANGE(SF_NOUNLINK
, ZFS_NOUNLINK
, XAT_NOUNLINK
,
4910 xvap
.xva_xoptattrs
.xoa_nounlink
);
4911 FLAG_CHANGE(UF_ARCHIVE
, ZFS_ARCHIVE
, XAT_ARCHIVE
,
4912 xvap
.xva_xoptattrs
.xoa_archive
);
4913 FLAG_CHANGE(UF_NODUMP
, ZFS_NODUMP
, XAT_NODUMP
,
4914 xvap
.xva_xoptattrs
.xoa_nodump
);
4915 FLAG_CHANGE(UF_READONLY
, ZFS_READONLY
, XAT_READONLY
,
4916 xvap
.xva_xoptattrs
.xoa_readonly
);
4917 FLAG_CHANGE(UF_SYSTEM
, ZFS_SYSTEM
, XAT_SYSTEM
,
4918 xvap
.xva_xoptattrs
.xoa_system
);
4919 FLAG_CHANGE(UF_HIDDEN
, ZFS_HIDDEN
, XAT_HIDDEN
,
4920 xvap
.xva_xoptattrs
.xoa_hidden
);
4921 FLAG_CHANGE(UF_REPARSE
, ZFS_REPARSE
, XAT_REPARSE
,
4922 xvap
.xva_xoptattrs
.xoa_reparse
);
4923 FLAG_CHANGE(UF_OFFLINE
, ZFS_OFFLINE
, XAT_OFFLINE
,
4924 xvap
.xva_xoptattrs
.xoa_offline
);
4925 FLAG_CHANGE(UF_SPARSE
, ZFS_SPARSE
, XAT_SPARSE
,
4926 xvap
.xva_xoptattrs
.xoa_sparse
);
4929 if (vap
->va_birthtime
.tv_sec
!= VNOVAL
) {
4930 xvap
.xva_vattr
.va_mask
|= AT_XVATTR
;
4931 XVA_SET_REQ(&xvap
, XAT_CREATETIME
);
4933 return (zfs_setattr(VTOZ(vp
), (vattr_t
*)&xvap
, 0, cred
));
4936 #ifndef _SYS_SYSPROTO_H_
4937 struct vop_rename_args
{
4938 struct vnode
*a_fdvp
;
4939 struct vnode
*a_fvp
;
4940 struct componentname
*a_fcnp
;
4941 struct vnode
*a_tdvp
;
4942 struct vnode
*a_tvp
;
4943 struct componentname
*a_tcnp
;
4948 zfs_freebsd_rename(struct vop_rename_args
*ap
)
4950 vnode_t
*fdvp
= ap
->a_fdvp
;
4951 vnode_t
*fvp
= ap
->a_fvp
;
4952 vnode_t
*tdvp
= ap
->a_tdvp
;
4953 vnode_t
*tvp
= ap
->a_tvp
;
4956 ASSERT(ap
->a_fcnp
->cn_flags
& (SAVENAME
|SAVESTART
));
4957 ASSERT(ap
->a_tcnp
->cn_flags
& (SAVENAME
|SAVESTART
));
4959 error
= zfs_do_rename(fdvp
, &fvp
, ap
->a_fcnp
, tdvp
, &tvp
,
4960 ap
->a_tcnp
, ap
->a_fcnp
->cn_cred
);
4971 #ifndef _SYS_SYSPROTO_H_
4972 struct vop_symlink_args
{
4973 struct vnode
*a_dvp
;
4974 struct vnode
**a_vpp
;
4975 struct componentname
*a_cnp
;
4976 struct vattr
*a_vap
;
4982 zfs_freebsd_symlink(struct vop_symlink_args
*ap
)
4984 struct componentname
*cnp
= ap
->a_cnp
;
4985 vattr_t
*vap
= ap
->a_vap
;
4987 #if __FreeBSD_version >= 1300139
4993 ASSERT(cnp
->cn_flags
& SAVENAME
);
4995 vap
->va_type
= VLNK
; /* FreeBSD: Syscall only sets va_mode. */
4996 vattr_init_mask(vap
);
4999 rc
= zfs_symlink(VTOZ(ap
->a_dvp
), cnp
->cn_nameptr
, vap
,
5000 ap
->a_target
, &zp
, cnp
->cn_cred
, 0 /* flags */);
5002 *ap
->a_vpp
= ZTOV(zp
);
5003 ASSERT_VOP_ELOCKED(ZTOV(zp
), __func__
);
5004 #if __FreeBSD_version >= 1300139
5005 MPASS(zp
->z_cached_symlink
== NULL
);
5006 symlink_len
= strlen(ap
->a_target
);
5007 symlink
= cache_symlink_alloc(symlink_len
+ 1, M_WAITOK
);
5008 if (symlink
!= NULL
) {
5009 memcpy(symlink
, ap
->a_target
, symlink_len
);
5010 symlink
[symlink_len
] = '\0';
5011 atomic_store_rel_ptr((uintptr_t *)&zp
->z_cached_symlink
,
5012 (uintptr_t)symlink
);
5019 #ifndef _SYS_SYSPROTO_H_
5020 struct vop_readlink_args
{
5023 struct ucred
*a_cred
;
5028 zfs_freebsd_readlink(struct vop_readlink_args
*ap
)
5032 #if __FreeBSD_version >= 1300139
5033 znode_t
*zp
= VTOZ(ap
->a_vp
);
5034 char *symlink
, *base
;
5039 zfs_uio_init(&uio
, ap
->a_uio
);
5040 #if __FreeBSD_version >= 1300139
5042 if (zfs_uio_segflg(&uio
) == UIO_SYSSPACE
&&
5043 zfs_uio_iovcnt(&uio
) == 1) {
5044 base
= zfs_uio_iovbase(&uio
, 0);
5045 symlink_len
= zfs_uio_iovlen(&uio
, 0);
5049 error
= zfs_readlink(ap
->a_vp
, &uio
, ap
->a_cred
, NULL
);
5050 #if __FreeBSD_version >= 1300139
5051 if (atomic_load_ptr(&zp
->z_cached_symlink
) != NULL
||
5052 error
!= 0 || !trycache
) {
5055 symlink_len
-= zfs_uio_resid(&uio
);
5056 symlink
= cache_symlink_alloc(symlink_len
+ 1, M_WAITOK
);
5057 if (symlink
!= NULL
) {
5058 memcpy(symlink
, base
, symlink_len
);
5059 symlink
[symlink_len
] = '\0';
5060 if (!atomic_cmpset_rel_ptr((uintptr_t *)&zp
->z_cached_symlink
,
5061 (uintptr_t)NULL
, (uintptr_t)symlink
)) {
5062 cache_symlink_free(symlink
, symlink_len
+ 1);
5069 #ifndef _SYS_SYSPROTO_H_
5070 struct vop_link_args
{
5071 struct vnode
*a_tdvp
;
5073 struct componentname
*a_cnp
;
5078 zfs_freebsd_link(struct vop_link_args
*ap
)
5080 struct componentname
*cnp
= ap
->a_cnp
;
5081 vnode_t
*vp
= ap
->a_vp
;
5082 vnode_t
*tdvp
= ap
->a_tdvp
;
5084 if (tdvp
->v_mount
!= vp
->v_mount
)
5087 ASSERT(cnp
->cn_flags
& SAVENAME
);
5089 return (zfs_link(VTOZ(tdvp
), VTOZ(vp
),
5090 cnp
->cn_nameptr
, cnp
->cn_cred
, 0));
5093 #ifndef _SYS_SYSPROTO_H_
5094 struct vop_inactive_args
{
5096 struct thread
*a_td
;
5101 zfs_freebsd_inactive(struct vop_inactive_args
*ap
)
5103 vnode_t
*vp
= ap
->a_vp
;
5105 #if __FreeBSD_version >= 1300123
5106 zfs_inactive(vp
, curthread
->td_ucred
, NULL
);
5108 zfs_inactive(vp
, ap
->a_td
->td_ucred
, NULL
);
5113 #if __FreeBSD_version >= 1300042
5114 #ifndef _SYS_SYSPROTO_H_
5115 struct vop_need_inactive_args
{
5117 struct thread
*a_td
;
5122 zfs_freebsd_need_inactive(struct vop_need_inactive_args
*ap
)
5124 vnode_t
*vp
= ap
->a_vp
;
5125 znode_t
*zp
= VTOZ(vp
);
5126 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
5129 if (vn_need_pageq_flush(vp
))
5132 if (!ZFS_TEARDOWN_INACTIVE_TRY_ENTER_READ(zfsvfs
))
5134 need
= (zp
->z_sa_hdl
== NULL
|| zp
->z_unlinked
|| zp
->z_atime_dirty
);
5135 ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs
);
5141 #ifndef _SYS_SYSPROTO_H_
5142 struct vop_reclaim_args
{
5144 struct thread
*a_td
;
5149 zfs_freebsd_reclaim(struct vop_reclaim_args
*ap
)
5151 vnode_t
*vp
= ap
->a_vp
;
5152 znode_t
*zp
= VTOZ(vp
);
5153 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
5155 ASSERT3P(zp
, !=, NULL
);
5157 #if __FreeBSD_version < 1300042
5158 /* Destroy the vm object and flush associated pages. */
5159 vnode_destroy_vobject(vp
);
5162 * z_teardown_inactive_lock protects from a race with
5163 * zfs_znode_dmu_fini in zfsvfs_teardown during
5166 ZFS_TEARDOWN_INACTIVE_ENTER_READ(zfsvfs
);
5167 if (zp
->z_sa_hdl
== NULL
)
5171 ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs
);
5177 #ifndef _SYS_SYSPROTO_H_
5178 struct vop_fid_args
{
5185 zfs_freebsd_fid(struct vop_fid_args
*ap
)
5188 return (zfs_fid(ap
->a_vp
, (void *)ap
->a_fid
, NULL
));
5192 #ifndef _SYS_SYSPROTO_H_
5193 struct vop_pathconf_args
{
5196 register_t
*a_retval
;
5201 zfs_freebsd_pathconf(struct vop_pathconf_args
*ap
)
5206 error
= zfs_pathconf(ap
->a_vp
, ap
->a_name
, &val
,
5207 curthread
->td_ucred
, NULL
);
5209 *ap
->a_retval
= val
;
5212 if (error
!= EOPNOTSUPP
)
5215 switch (ap
->a_name
) {
5217 *ap
->a_retval
= NAME_MAX
;
5219 #if __FreeBSD_version >= 1400032
5220 case _PC_DEALLOC_PRESENT
:
5225 if (ap
->a_vp
->v_type
== VDIR
|| ap
->a_vp
->v_type
== VFIFO
) {
5226 *ap
->a_retval
= PIPE_BUF
;
5231 return (vop_stdpathconf(ap
));
5235 static int zfs_xattr_compat
= 1;
5238 zfs_check_attrname(const char *name
)
5240 /* We don't allow '/' character in attribute name. */
5241 if (strchr(name
, '/') != NULL
)
5242 return (SET_ERROR(EINVAL
));
5243 /* We don't allow attribute names that start with a namespace prefix. */
5244 if (ZFS_XA_NS_PREFIX_FORBIDDEN(name
))
5245 return (SET_ERROR(EINVAL
));
5250 * FreeBSD's extended attributes namespace defines file name prefix for ZFS'
5251 * extended attribute name:
5253 * NAMESPACE XATTR_COMPAT PREFIX
5254 * system * freebsd:system:
5255 * user 1 (none, can be used to access ZFS
5256 * fsattr(5) attributes created on Solaris)
5260 zfs_create_attrname(int attrnamespace
, const char *name
, char *attrname
,
5261 size_t size
, boolean_t compat
)
5263 const char *namespace, *prefix
, *suffix
;
5265 memset(attrname
, 0, size
);
5267 switch (attrnamespace
) {
5268 case EXTATTR_NAMESPACE_USER
:
5271 * This is the default namespace by which we can access
5272 * all attributes created on Solaris.
5274 prefix
= namespace = suffix
= "";
5277 * This is compatible with the user namespace encoding
5278 * on Linux prior to xattr_compat, but nothing
5286 case EXTATTR_NAMESPACE_SYSTEM
:
5287 prefix
= "freebsd:";
5288 namespace = EXTATTR_NAMESPACE_SYSTEM_STRING
;
5291 case EXTATTR_NAMESPACE_EMPTY
:
5293 return (SET_ERROR(EINVAL
));
5295 if (snprintf(attrname
, size
, "%s%s%s%s", prefix
, namespace, suffix
,
5297 return (SET_ERROR(ENAMETOOLONG
));
5303 zfs_ensure_xattr_cached(znode_t
*zp
)
5307 ASSERT(RW_LOCK_HELD(&zp
->z_xattr_lock
));
5309 if (zp
->z_xattr_cached
!= NULL
)
5312 if (rw_write_held(&zp
->z_xattr_lock
))
5313 return (zfs_sa_get_xattr(zp
));
5315 if (!rw_tryupgrade(&zp
->z_xattr_lock
)) {
5316 rw_exit(&zp
->z_xattr_lock
);
5317 rw_enter(&zp
->z_xattr_lock
, RW_WRITER
);
5319 if (zp
->z_xattr_cached
== NULL
)
5320 error
= zfs_sa_get_xattr(zp
);
5321 rw_downgrade(&zp
->z_xattr_lock
);
5325 #ifndef _SYS_SYSPROTO_H_
5326 struct vop_getextattr
{
5327 IN
struct vnode
*a_vp
;
5328 IN
int a_attrnamespace
;
5329 IN
const char *a_name
;
5330 INOUT
struct uio
*a_uio
;
5332 IN
struct ucred
*a_cred
;
5333 IN
struct thread
*a_td
;
5338 zfs_getextattr_dir(struct vop_getextattr_args
*ap
, const char *attrname
)
5340 struct thread
*td
= ap
->a_td
;
5341 struct nameidata nd
;
5343 vnode_t
*xvp
= NULL
, *vp
;
5346 error
= zfs_lookup(ap
->a_vp
, NULL
, &xvp
, NULL
, 0, ap
->a_cred
,
5347 LOOKUP_XATTR
, B_FALSE
);
5352 #if __FreeBSD_version < 1400043
5353 NDINIT_ATVP(&nd
, LOOKUP
, NOFOLLOW
, UIO_SYSSPACE
, attrname
,
5356 NDINIT_ATVP(&nd
, LOOKUP
, NOFOLLOW
, UIO_SYSSPACE
, attrname
, xvp
);
5358 error
= vn_open_cred(&nd
, &flags
, 0, VN_OPEN_INVFS
, ap
->a_cred
, NULL
);
5362 return (SET_ERROR(error
));
5364 if (ap
->a_size
!= NULL
) {
5365 error
= VOP_GETATTR(vp
, &va
, ap
->a_cred
);
5367 *ap
->a_size
= (size_t)va
.va_size
;
5368 } else if (ap
->a_uio
!= NULL
)
5369 error
= VOP_READ(vp
, ap
->a_uio
, IO_UNIT
, ap
->a_cred
);
5372 vn_close(vp
, flags
, ap
->a_cred
, td
);
5377 zfs_getextattr_sa(struct vop_getextattr_args
*ap
, const char *attrname
)
5379 znode_t
*zp
= VTOZ(ap
->a_vp
);
5384 error
= zfs_ensure_xattr_cached(zp
);
5388 ASSERT(RW_LOCK_HELD(&zp
->z_xattr_lock
));
5389 ASSERT3P(zp
->z_xattr_cached
, !=, NULL
);
5391 error
= nvlist_lookup_byte_array(zp
->z_xattr_cached
, attrname
,
5392 &nv_value
, &nv_size
);
5394 return (SET_ERROR(error
));
5396 if (ap
->a_size
!= NULL
)
5397 *ap
->a_size
= nv_size
;
5398 else if (ap
->a_uio
!= NULL
)
5399 error
= uiomove(nv_value
, nv_size
, ap
->a_uio
);
5401 return (SET_ERROR(error
));
5407 zfs_getextattr_impl(struct vop_getextattr_args
*ap
, boolean_t compat
)
5409 znode_t
*zp
= VTOZ(ap
->a_vp
);
5410 zfsvfs_t
*zfsvfs
= ZTOZSB(zp
);
5411 char attrname
[EXTATTR_MAXNAMELEN
+1];
5414 error
= zfs_create_attrname(ap
->a_attrnamespace
, ap
->a_name
, attrname
,
5415 sizeof (attrname
), compat
);
5420 if (zfsvfs
->z_use_sa
&& zp
->z_is_sa
)
5421 error
= zfs_getextattr_sa(ap
, attrname
);
5422 if (error
== ENOENT
)
5423 error
= zfs_getextattr_dir(ap
, attrname
);
5428 * Vnode operation to retrieve a named extended attribute.
5431 zfs_getextattr(struct vop_getextattr_args
*ap
)
5433 znode_t
*zp
= VTOZ(ap
->a_vp
);
5434 zfsvfs_t
*zfsvfs
= ZTOZSB(zp
);
5438 * If the xattr property is off, refuse the request.
5440 if (!(zfsvfs
->z_flags
& ZSB_XATTR
))
5441 return (SET_ERROR(EOPNOTSUPP
));
5443 error
= extattr_check_cred(ap
->a_vp
, ap
->a_attrnamespace
,
5444 ap
->a_cred
, ap
->a_td
, VREAD
);
5446 return (SET_ERROR(error
));
5448 error
= zfs_check_attrname(ap
->a_name
);
5455 rw_enter(&zp
->z_xattr_lock
, RW_READER
);
5457 error
= zfs_getextattr_impl(ap
, zfs_xattr_compat
);
5458 if ((error
== ENOENT
|| error
== ENOATTR
) &&
5459 ap
->a_attrnamespace
== EXTATTR_NAMESPACE_USER
) {
5461 * Fall back to the alternate namespace format if we failed to
5462 * find a user xattr.
5464 error
= zfs_getextattr_impl(ap
, !zfs_xattr_compat
);
5467 rw_exit(&zp
->z_xattr_lock
);
5469 if (error
== ENOENT
)
5470 error
= SET_ERROR(ENOATTR
);
5474 #ifndef _SYS_SYSPROTO_H_
5475 struct vop_deleteextattr
{
5476 IN
struct vnode
*a_vp
;
5477 IN
int a_attrnamespace
;
5478 IN
const char *a_name
;
5479 IN
struct ucred
*a_cred
;
5480 IN
struct thread
*a_td
;
5485 zfs_deleteextattr_dir(struct vop_deleteextattr_args
*ap
, const char *attrname
)
5487 struct nameidata nd
;
5488 vnode_t
*xvp
= NULL
, *vp
;
5491 error
= zfs_lookup(ap
->a_vp
, NULL
, &xvp
, NULL
, 0, ap
->a_cred
,
5492 LOOKUP_XATTR
, B_FALSE
);
5496 #if __FreeBSD_version < 1400043
5497 NDINIT_ATVP(&nd
, DELETE
, NOFOLLOW
| LOCKPARENT
| LOCKLEAF
,
5498 UIO_SYSSPACE
, attrname
, xvp
, ap
->a_td
);
5500 NDINIT_ATVP(&nd
, DELETE
, NOFOLLOW
| LOCKPARENT
| LOCKLEAF
,
5501 UIO_SYSSPACE
, attrname
, xvp
);
5507 return (SET_ERROR(error
));
5510 error
= VOP_REMOVE(nd
.ni_dvp
, vp
, &nd
.ni_cnd
);
5514 if (vp
== nd
.ni_dvp
)
5523 zfs_deleteextattr_sa(struct vop_deleteextattr_args
*ap
, const char *attrname
)
5525 znode_t
*zp
= VTOZ(ap
->a_vp
);
5529 error
= zfs_ensure_xattr_cached(zp
);
5533 ASSERT(RW_WRITE_HELD(&zp
->z_xattr_lock
));
5534 ASSERT3P(zp
->z_xattr_cached
, !=, NULL
);
5536 nvl
= zp
->z_xattr_cached
;
5537 error
= nvlist_remove(nvl
, attrname
, DATA_TYPE_BYTE_ARRAY
);
5539 error
= SET_ERROR(error
);
5541 error
= zfs_sa_set_xattr(zp
, attrname
, NULL
, 0);
5543 zp
->z_xattr_cached
= NULL
;
5550 zfs_deleteextattr_impl(struct vop_deleteextattr_args
*ap
, boolean_t compat
)
5552 znode_t
*zp
= VTOZ(ap
->a_vp
);
5553 zfsvfs_t
*zfsvfs
= ZTOZSB(zp
);
5554 char attrname
[EXTATTR_MAXNAMELEN
+1];
5557 error
= zfs_create_attrname(ap
->a_attrnamespace
, ap
->a_name
, attrname
,
5558 sizeof (attrname
), compat
);
5563 if (zfsvfs
->z_use_sa
&& zp
->z_is_sa
)
5564 error
= zfs_deleteextattr_sa(ap
, attrname
);
5565 if (error
== ENOENT
)
5566 error
= zfs_deleteextattr_dir(ap
, attrname
);
5571 * Vnode operation to remove a named attribute.
5574 zfs_deleteextattr(struct vop_deleteextattr_args
*ap
)
5576 znode_t
*zp
= VTOZ(ap
->a_vp
);
5577 zfsvfs_t
*zfsvfs
= ZTOZSB(zp
);
5581 * If the xattr property is off, refuse the request.
5583 if (!(zfsvfs
->z_flags
& ZSB_XATTR
))
5584 return (SET_ERROR(EOPNOTSUPP
));
5586 error
= extattr_check_cred(ap
->a_vp
, ap
->a_attrnamespace
,
5587 ap
->a_cred
, ap
->a_td
, VWRITE
);
5589 return (SET_ERROR(error
));
5591 error
= zfs_check_attrname(ap
->a_name
);
5597 rw_enter(&zp
->z_xattr_lock
, RW_WRITER
);
5599 error
= zfs_deleteextattr_impl(ap
, zfs_xattr_compat
);
5600 if ((error
== ENOENT
|| error
== ENOATTR
) &&
5601 ap
->a_attrnamespace
== EXTATTR_NAMESPACE_USER
) {
5603 * Fall back to the alternate namespace format if we failed to
5604 * find a user xattr.
5606 error
= zfs_deleteextattr_impl(ap
, !zfs_xattr_compat
);
5609 rw_exit(&zp
->z_xattr_lock
);
5611 if (error
== ENOENT
)
5612 error
= SET_ERROR(ENOATTR
);
5616 #ifndef _SYS_SYSPROTO_H_
5617 struct vop_setextattr
{
5618 IN
struct vnode
*a_vp
;
5619 IN
int a_attrnamespace
;
5620 IN
const char *a_name
;
5621 INOUT
struct uio
*a_uio
;
5622 IN
struct ucred
*a_cred
;
5623 IN
struct thread
*a_td
;
5628 zfs_setextattr_dir(struct vop_setextattr_args
*ap
, const char *attrname
)
5630 struct thread
*td
= ap
->a_td
;
5631 struct nameidata nd
;
5633 vnode_t
*xvp
= NULL
, *vp
;
5636 error
= zfs_lookup(ap
->a_vp
, NULL
, &xvp
, NULL
, 0, ap
->a_cred
,
5637 LOOKUP_XATTR
| CREATE_XATTR_DIR
, B_FALSE
);
5641 flags
= FFLAGS(O_WRONLY
| O_CREAT
);
5642 #if __FreeBSD_version < 1400043
5643 NDINIT_ATVP(&nd
, LOOKUP
, NOFOLLOW
, UIO_SYSSPACE
, attrname
, xvp
, td
);
5645 NDINIT_ATVP(&nd
, LOOKUP
, NOFOLLOW
, UIO_SYSSPACE
, attrname
, xvp
);
5647 error
= vn_open_cred(&nd
, &flags
, 0600, VN_OPEN_INVFS
, ap
->a_cred
,
5652 return (SET_ERROR(error
));
5656 error
= VOP_SETATTR(vp
, &va
, ap
->a_cred
);
5658 VOP_WRITE(vp
, ap
->a_uio
, IO_UNIT
, ap
->a_cred
);
5661 vn_close(vp
, flags
, ap
->a_cred
, td
);
5666 zfs_setextattr_sa(struct vop_setextattr_args
*ap
, const char *attrname
)
5668 znode_t
*zp
= VTOZ(ap
->a_vp
);
5673 error
= zfs_ensure_xattr_cached(zp
);
5677 ASSERT(RW_WRITE_HELD(&zp
->z_xattr_lock
));
5678 ASSERT3P(zp
->z_xattr_cached
, !=, NULL
);
5680 nvl
= zp
->z_xattr_cached
;
5681 size_t entry_size
= ap
->a_uio
->uio_resid
;
5682 if (entry_size
> DXATTR_MAX_ENTRY_SIZE
)
5683 return (SET_ERROR(EFBIG
));
5684 error
= nvlist_size(nvl
, &sa_size
, NV_ENCODE_XDR
);
5686 return (SET_ERROR(error
));
5687 if (sa_size
> DXATTR_MAX_SA_SIZE
)
5688 return (SET_ERROR(EFBIG
));
5689 uchar_t
*buf
= kmem_alloc(entry_size
, KM_SLEEP
);
5690 error
= uiomove(buf
, entry_size
, ap
->a_uio
);
5692 error
= SET_ERROR(error
);
5694 error
= nvlist_add_byte_array(nvl
, attrname
, buf
, entry_size
);
5696 error
= SET_ERROR(error
);
5699 error
= zfs_sa_set_xattr(zp
, attrname
, buf
, entry_size
);
5700 kmem_free(buf
, entry_size
);
5702 zp
->z_xattr_cached
= NULL
;
5709 zfs_setextattr_impl(struct vop_setextattr_args
*ap
, boolean_t compat
)
5711 znode_t
*zp
= VTOZ(ap
->a_vp
);
5712 zfsvfs_t
*zfsvfs
= ZTOZSB(zp
);
5713 char attrname
[EXTATTR_MAXNAMELEN
+1];
5716 error
= zfs_create_attrname(ap
->a_attrnamespace
, ap
->a_name
, attrname
,
5717 sizeof (attrname
), compat
);
5721 struct vop_deleteextattr_args vda
= {
5723 .a_attrnamespace
= ap
->a_attrnamespace
,
5724 .a_name
= ap
->a_name
,
5725 .a_cred
= ap
->a_cred
,
5729 if (zfsvfs
->z_use_sa
&& zp
->z_is_sa
&& zfsvfs
->z_xattr_sa
) {
5730 error
= zfs_setextattr_sa(ap
, attrname
);
5733 * Successfully put into SA, we need to clear the one
5734 * in dir if present.
5736 zfs_deleteextattr_dir(&vda
, attrname
);
5740 error
= zfs_setextattr_dir(ap
, attrname
);
5741 if (error
== 0 && zp
->z_is_sa
) {
5743 * Successfully put into dir, we need to clear the one
5746 zfs_deleteextattr_sa(&vda
, attrname
);
5749 if (error
== 0 && ap
->a_attrnamespace
== EXTATTR_NAMESPACE_USER
) {
5751 * Also clear all versions of the alternate compat name.
5753 zfs_deleteextattr_impl(&vda
, !compat
);
5759 * Vnode operation to set a named attribute.
5762 zfs_setextattr(struct vop_setextattr_args
*ap
)
5764 znode_t
*zp
= VTOZ(ap
->a_vp
);
5765 zfsvfs_t
*zfsvfs
= ZTOZSB(zp
);
5769 * If the xattr property is off, refuse the request.
5771 if (!(zfsvfs
->z_flags
& ZSB_XATTR
))
5772 return (SET_ERROR(EOPNOTSUPP
));
5774 error
= extattr_check_cred(ap
->a_vp
, ap
->a_attrnamespace
,
5775 ap
->a_cred
, ap
->a_td
, VWRITE
);
5777 return (SET_ERROR(error
));
5779 error
= zfs_check_attrname(ap
->a_name
);
5785 rw_enter(&zp
->z_xattr_lock
, RW_WRITER
);
5787 error
= zfs_setextattr_impl(ap
, zfs_xattr_compat
);
5789 rw_exit(&zp
->z_xattr_lock
);
5794 #ifndef _SYS_SYSPROTO_H_
5795 struct vop_listextattr
{
5796 IN
struct vnode
*a_vp
;
5797 IN
int a_attrnamespace
;
5798 INOUT
struct uio
*a_uio
;
5800 IN
struct ucred
*a_cred
;
5801 IN
struct thread
*a_td
;
5806 zfs_listextattr_dir(struct vop_listextattr_args
*ap
, const char *attrprefix
)
5808 struct thread
*td
= ap
->a_td
;
5809 struct nameidata nd
;
5810 uint8_t dirbuf
[sizeof (struct dirent
)];
5813 vnode_t
*xvp
= NULL
, *vp
;
5816 error
= zfs_lookup(ap
->a_vp
, NULL
, &xvp
, NULL
, 0, ap
->a_cred
,
5817 LOOKUP_XATTR
, B_FALSE
);
5820 * ENOATTR means that the EA directory does not yet exist,
5821 * i.e. there are no extended attributes there.
5823 if (error
== ENOATTR
)
5828 #if __FreeBSD_version < 1400043
5829 NDINIT_ATVP(&nd
, LOOKUP
, NOFOLLOW
| LOCKLEAF
| LOCKSHARED
,
5830 UIO_SYSSPACE
, ".", xvp
, td
);
5832 NDINIT_ATVP(&nd
, LOOKUP
, NOFOLLOW
| LOCKLEAF
| LOCKSHARED
,
5833 UIO_SYSSPACE
, ".", xvp
);
5839 return (SET_ERROR(error
));
5841 auio
.uio_iov
= &aiov
;
5842 auio
.uio_iovcnt
= 1;
5843 auio
.uio_segflg
= UIO_SYSSPACE
;
5845 auio
.uio_rw
= UIO_READ
;
5846 auio
.uio_offset
= 0;
5848 size_t plen
= strlen(attrprefix
);
5851 aiov
.iov_base
= (void *)dirbuf
;
5852 aiov
.iov_len
= sizeof (dirbuf
);
5853 auio
.uio_resid
= sizeof (dirbuf
);
5854 error
= VOP_READDIR(vp
, &auio
, ap
->a_cred
, &eof
, NULL
, NULL
);
5857 int done
= sizeof (dirbuf
) - auio
.uio_resid
;
5858 for (int pos
= 0; pos
< done
; ) {
5859 struct dirent
*dp
= (struct dirent
*)(dirbuf
+ pos
);
5860 pos
+= dp
->d_reclen
;
5862 * XXX: Temporarily we also accept DT_UNKNOWN, as this
5863 * is what we get when attribute was created on Solaris.
5865 if (dp
->d_type
!= DT_REG
&& dp
->d_type
!= DT_UNKNOWN
)
5867 else if (plen
== 0 &&
5868 ZFS_XA_NS_PREFIX_FORBIDDEN(dp
->d_name
))
5870 else if (strncmp(dp
->d_name
, attrprefix
, plen
) != 0)
5872 uint8_t nlen
= dp
->d_namlen
- plen
;
5873 if (ap
->a_size
!= NULL
) {
5874 *ap
->a_size
+= 1 + nlen
;
5875 } else if (ap
->a_uio
!= NULL
) {
5877 * Format of extattr name entry is one byte for
5878 * length and the rest for name.
5880 error
= uiomove(&nlen
, 1, ap
->a_uio
);
5882 char *namep
= dp
->d_name
+ plen
;
5883 error
= uiomove(namep
, nlen
, ap
->a_uio
);
5886 error
= SET_ERROR(error
);
5891 } while (!eof
&& error
== 0);
5898 zfs_listextattr_sa(struct vop_listextattr_args
*ap
, const char *attrprefix
)
5900 znode_t
*zp
= VTOZ(ap
->a_vp
);
5903 error
= zfs_ensure_xattr_cached(zp
);
5907 ASSERT(RW_LOCK_HELD(&zp
->z_xattr_lock
));
5908 ASSERT3P(zp
->z_xattr_cached
, !=, NULL
);
5910 size_t plen
= strlen(attrprefix
);
5911 nvpair_t
*nvp
= NULL
;
5912 while ((nvp
= nvlist_next_nvpair(zp
->z_xattr_cached
, nvp
)) != NULL
) {
5913 ASSERT3U(nvpair_type(nvp
), ==, DATA_TYPE_BYTE_ARRAY
);
5915 const char *name
= nvpair_name(nvp
);
5916 if (plen
== 0 && ZFS_XA_NS_PREFIX_FORBIDDEN(name
))
5918 else if (strncmp(name
, attrprefix
, plen
) != 0)
5920 uint8_t nlen
= strlen(name
) - plen
;
5921 if (ap
->a_size
!= NULL
) {
5922 *ap
->a_size
+= 1 + nlen
;
5923 } else if (ap
->a_uio
!= NULL
) {
5925 * Format of extattr name entry is one byte for
5926 * length and the rest for name.
5928 error
= uiomove(&nlen
, 1, ap
->a_uio
);
5930 char *namep
= __DECONST(char *, name
) + plen
;
5931 error
= uiomove(namep
, nlen
, ap
->a_uio
);
5934 error
= SET_ERROR(error
);
5944 zfs_listextattr_impl(struct vop_listextattr_args
*ap
, boolean_t compat
)
5946 znode_t
*zp
= VTOZ(ap
->a_vp
);
5947 zfsvfs_t
*zfsvfs
= ZTOZSB(zp
);
5948 char attrprefix
[16];
5951 error
= zfs_create_attrname(ap
->a_attrnamespace
, "", attrprefix
,
5952 sizeof (attrprefix
), compat
);
5956 if (zfsvfs
->z_use_sa
&& zp
->z_is_sa
)
5957 error
= zfs_listextattr_sa(ap
, attrprefix
);
5959 error
= zfs_listextattr_dir(ap
, attrprefix
);
5964 * Vnode operation to retrieve extended attributes on a vnode.
5967 zfs_listextattr(struct vop_listextattr_args
*ap
)
5969 znode_t
*zp
= VTOZ(ap
->a_vp
);
5970 zfsvfs_t
*zfsvfs
= ZTOZSB(zp
);
5973 if (ap
->a_size
!= NULL
)
5977 * If the xattr property is off, refuse the request.
5979 if (!(zfsvfs
->z_flags
& ZSB_XATTR
))
5980 return (SET_ERROR(EOPNOTSUPP
));
5982 error
= extattr_check_cred(ap
->a_vp
, ap
->a_attrnamespace
,
5983 ap
->a_cred
, ap
->a_td
, VREAD
);
5985 return (SET_ERROR(error
));
5989 rw_enter(&zp
->z_xattr_lock
, RW_READER
);
5991 error
= zfs_listextattr_impl(ap
, zfs_xattr_compat
);
5992 if (error
== 0 && ap
->a_attrnamespace
== EXTATTR_NAMESPACE_USER
) {
5993 /* Also list user xattrs with the alternate format. */
5994 error
= zfs_listextattr_impl(ap
, !zfs_xattr_compat
);
5997 rw_exit(&zp
->z_xattr_lock
);
6002 #ifndef _SYS_SYSPROTO_H_
6003 struct vop_getacl_args
{
6013 zfs_freebsd_getacl(struct vop_getacl_args
*ap
)
6016 vsecattr_t vsecattr
;
6018 if (ap
->a_type
!= ACL_TYPE_NFS4
)
6021 vsecattr
.vsa_mask
= VSA_ACE
| VSA_ACECNT
;
6022 if ((error
= zfs_getsecattr(VTOZ(ap
->a_vp
),
6023 &vsecattr
, 0, ap
->a_cred
)))
6026 error
= acl_from_aces(ap
->a_aclp
, vsecattr
.vsa_aclentp
,
6027 vsecattr
.vsa_aclcnt
);
6028 if (vsecattr
.vsa_aclentp
!= NULL
)
6029 kmem_free(vsecattr
.vsa_aclentp
, vsecattr
.vsa_aclentsz
);
6034 #ifndef _SYS_SYSPROTO_H_
6035 struct vop_setacl_args
{
6045 zfs_freebsd_setacl(struct vop_setacl_args
*ap
)
6048 vsecattr_t vsecattr
;
6049 int aclbsize
; /* size of acl list in bytes */
6052 if (ap
->a_type
!= ACL_TYPE_NFS4
)
6055 if (ap
->a_aclp
== NULL
)
6058 if (ap
->a_aclp
->acl_cnt
< 1 || ap
->a_aclp
->acl_cnt
> MAX_ACL_ENTRIES
)
6062 * With NFSv4 ACLs, chmod(2) may need to add additional entries,
6063 * splitting every entry into two and appending "canonical six"
6064 * entries at the end. Don't allow for setting an ACL that would
6065 * cause chmod(2) to run out of ACL entries.
6067 if (ap
->a_aclp
->acl_cnt
* 2 + 6 > ACL_MAX_ENTRIES
)
6070 error
= acl_nfs4_check(ap
->a_aclp
, ap
->a_vp
->v_type
== VDIR
);
6074 vsecattr
.vsa_mask
= VSA_ACE
;
6075 aclbsize
= ap
->a_aclp
->acl_cnt
* sizeof (ace_t
);
6076 vsecattr
.vsa_aclentp
= kmem_alloc(aclbsize
, KM_SLEEP
);
6077 aaclp
= vsecattr
.vsa_aclentp
;
6078 vsecattr
.vsa_aclentsz
= aclbsize
;
6080 aces_from_acl(vsecattr
.vsa_aclentp
, &vsecattr
.vsa_aclcnt
, ap
->a_aclp
);
6081 error
= zfs_setsecattr(VTOZ(ap
->a_vp
), &vsecattr
, 0, ap
->a_cred
);
6082 kmem_free(aaclp
, aclbsize
);
6087 #ifndef _SYS_SYSPROTO_H_
6088 struct vop_aclcheck_args
{
6098 zfs_freebsd_aclcheck(struct vop_aclcheck_args
*ap
)
6101 return (EOPNOTSUPP
);
6105 zfs_vptocnp(struct vop_vptocnp_args
*ap
)
6107 vnode_t
*covered_vp
;
6108 vnode_t
*vp
= ap
->a_vp
;
6109 zfsvfs_t
*zfsvfs
= vp
->v_vfsp
->vfs_data
;
6110 znode_t
*zp
= VTOZ(vp
);
6118 * If we are a snapshot mounted under .zfs, run the operation
6119 * on the covered vnode.
6121 if (zp
->z_id
!= zfsvfs
->z_root
|| zfsvfs
->z_parent
== zfsvfs
) {
6122 char name
[MAXNAMLEN
+ 1];
6126 error
= zfs_znode_parent_and_name(zp
, &dzp
, name
);
6129 if (*ap
->a_buflen
< len
)
6130 error
= SET_ERROR(ENOMEM
);
6133 *ap
->a_buflen
-= len
;
6134 memcpy(ap
->a_buf
+ *ap
->a_buflen
, name
, len
);
6135 *ap
->a_vpp
= ZTOV(dzp
);
6142 covered_vp
= vp
->v_mount
->mnt_vnodecovered
;
6143 #if __FreeBSD_version >= 1300045
6144 enum vgetstate vs
= vget_prep(covered_vp
);
6148 ltype
= VOP_ISLOCKED(vp
);
6150 #if __FreeBSD_version >= 1300045
6151 error
= vget_finish(covered_vp
, LK_SHARED
, vs
);
6153 error
= vget(covered_vp
, LK_SHARED
| LK_VNHELD
, curthread
);
6156 #if __FreeBSD_version >= 1300123
6157 error
= VOP_VPTOCNP(covered_vp
, ap
->a_vpp
, ap
->a_buf
,
6160 error
= VOP_VPTOCNP(covered_vp
, ap
->a_vpp
, ap
->a_cred
,
6161 ap
->a_buf
, ap
->a_buflen
);
6165 vn_lock(vp
, ltype
| LK_RETRY
);
6166 if (VN_IS_DOOMED(vp
))
6167 error
= SET_ERROR(ENOENT
);
6171 #if __FreeBSD_version >= 1400032
6173 zfs_deallocate(struct vop_deallocate_args
*ap
)
6175 znode_t
*zp
= VTOZ(ap
->a_vp
);
6176 zfsvfs_t
*zfsvfs
= zp
->z_zfsvfs
;
6178 off_t off
, len
, file_sz
;
6185 * Callers might not be able to detect properly that we are read-only,
6186 * so check it explicitly here.
6188 if (zfs_is_readonly(zfsvfs
)) {
6190 return (SET_ERROR(EROFS
));
6193 zilog
= zfsvfs
->z_log
;
6194 off
= *ap
->a_offset
;
6196 file_sz
= zp
->z_size
;
6197 if (off
+ len
> file_sz
)
6198 len
= file_sz
- off
;
6199 /* Fast path for out-of-range request. */
6206 error
= zfs_freesp(zp
, off
, len
, O_RDWR
, TRUE
);
6208 if (zfsvfs
->z_os
->os_sync
== ZFS_SYNC_ALWAYS
||
6209 (ap
->a_ioflag
& IO_SYNC
) != 0)
6210 zil_commit(zilog
, zp
->z_id
);
6211 *ap
->a_offset
= off
+ len
;
6220 struct vop_vector zfs_vnodeops
;
6221 struct vop_vector zfs_fifoops
;
6222 struct vop_vector zfs_shareops
;
6224 struct vop_vector zfs_vnodeops
= {
6225 .vop_default
= &default_vnodeops
,
6226 .vop_inactive
= zfs_freebsd_inactive
,
6227 #if __FreeBSD_version >= 1300042
6228 .vop_need_inactive
= zfs_freebsd_need_inactive
,
6230 .vop_reclaim
= zfs_freebsd_reclaim
,
6231 #if __FreeBSD_version >= 1300102
6232 .vop_fplookup_vexec
= zfs_freebsd_fplookup_vexec
,
6234 #if __FreeBSD_version >= 1300139
6235 .vop_fplookup_symlink
= zfs_freebsd_fplookup_symlink
,
6237 .vop_access
= zfs_freebsd_access
,
6238 .vop_allocate
= VOP_EINVAL
,
6239 #if __FreeBSD_version >= 1400032
6240 .vop_deallocate
= zfs_deallocate
,
6242 .vop_lookup
= zfs_cache_lookup
,
6243 .vop_cachedlookup
= zfs_freebsd_cachedlookup
,
6244 .vop_getattr
= zfs_freebsd_getattr
,
6245 .vop_setattr
= zfs_freebsd_setattr
,
6246 .vop_create
= zfs_freebsd_create
,
6247 .vop_mknod
= (vop_mknod_t
*)zfs_freebsd_create
,
6248 .vop_mkdir
= zfs_freebsd_mkdir
,
6249 .vop_readdir
= zfs_freebsd_readdir
,
6250 .vop_fsync
= zfs_freebsd_fsync
,
6251 .vop_open
= zfs_freebsd_open
,
6252 .vop_close
= zfs_freebsd_close
,
6253 .vop_rmdir
= zfs_freebsd_rmdir
,
6254 .vop_ioctl
= zfs_freebsd_ioctl
,
6255 .vop_link
= zfs_freebsd_link
,
6256 .vop_symlink
= zfs_freebsd_symlink
,
6257 .vop_readlink
= zfs_freebsd_readlink
,
6258 .vop_read
= zfs_freebsd_read
,
6259 .vop_write
= zfs_freebsd_write
,
6260 .vop_remove
= zfs_freebsd_remove
,
6261 .vop_rename
= zfs_freebsd_rename
,
6262 .vop_pathconf
= zfs_freebsd_pathconf
,
6263 .vop_bmap
= zfs_freebsd_bmap
,
6264 .vop_fid
= zfs_freebsd_fid
,
6265 .vop_getextattr
= zfs_getextattr
,
6266 .vop_deleteextattr
= zfs_deleteextattr
,
6267 .vop_setextattr
= zfs_setextattr
,
6268 .vop_listextattr
= zfs_listextattr
,
6269 .vop_getacl
= zfs_freebsd_getacl
,
6270 .vop_setacl
= zfs_freebsd_setacl
,
6271 .vop_aclcheck
= zfs_freebsd_aclcheck
,
6272 .vop_getpages
= zfs_freebsd_getpages
,
6273 .vop_putpages
= zfs_freebsd_putpages
,
6274 .vop_vptocnp
= zfs_vptocnp
,
6275 #if __FreeBSD_version >= 1300064
6276 .vop_lock1
= vop_lock
,
6277 .vop_unlock
= vop_unlock
,
6278 .vop_islocked
= vop_islocked
,
6280 #if __FreeBSD_version >= 1400043
6281 .vop_add_writecount
= vop_stdadd_writecount_nomsync
,
6284 VFS_VOP_VECTOR_REGISTER(zfs_vnodeops
);
6286 struct vop_vector zfs_fifoops
= {
6287 .vop_default
= &fifo_specops
,
6288 .vop_fsync
= zfs_freebsd_fsync
,
6289 #if __FreeBSD_version >= 1300102
6290 .vop_fplookup_vexec
= zfs_freebsd_fplookup_vexec
,
6292 #if __FreeBSD_version >= 1300139
6293 .vop_fplookup_symlink
= zfs_freebsd_fplookup_symlink
,
6295 .vop_access
= zfs_freebsd_access
,
6296 .vop_getattr
= zfs_freebsd_getattr
,
6297 .vop_inactive
= zfs_freebsd_inactive
,
6298 .vop_read
= VOP_PANIC
,
6299 .vop_reclaim
= zfs_freebsd_reclaim
,
6300 .vop_setattr
= zfs_freebsd_setattr
,
6301 .vop_write
= VOP_PANIC
,
6302 .vop_pathconf
= zfs_freebsd_pathconf
,
6303 .vop_fid
= zfs_freebsd_fid
,
6304 .vop_getacl
= zfs_freebsd_getacl
,
6305 .vop_setacl
= zfs_freebsd_setacl
,
6306 .vop_aclcheck
= zfs_freebsd_aclcheck
,
6307 #if __FreeBSD_version >= 1400043
6308 .vop_add_writecount
= vop_stdadd_writecount_nomsync
,
6311 VFS_VOP_VECTOR_REGISTER(zfs_fifoops
);
6314 * special share hidden files vnode operations template
6316 struct vop_vector zfs_shareops
= {
6317 .vop_default
= &default_vnodeops
,
6318 #if __FreeBSD_version >= 1300121
6319 .vop_fplookup_vexec
= VOP_EAGAIN
,
6321 #if __FreeBSD_version >= 1300139
6322 .vop_fplookup_symlink
= VOP_EAGAIN
,
6324 .vop_access
= zfs_freebsd_access
,
6325 .vop_inactive
= zfs_freebsd_inactive
,
6326 .vop_reclaim
= zfs_freebsd_reclaim
,
6327 .vop_fid
= zfs_freebsd_fid
,
6328 .vop_pathconf
= zfs_freebsd_pathconf
,
6329 #if __FreeBSD_version >= 1400043
6330 .vop_add_writecount
= vop_stdadd_writecount_nomsync
,
6333 VFS_VOP_VECTOR_REGISTER(zfs_shareops
);
6335 ZFS_MODULE_PARAM(zfs
, zfs_
, xattr_compat
, INT
, ZMOD_RW
,
6336 "Use legacy ZFS xattr naming for writing new user namespace xattrs");