4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
27 /* Portions Copyright 2007 Jeremy Teo */
28 /* Portions Copyright 2010 Robert Milkowski */
30 #include <sys/types.h>
31 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/sysmacros.h>
35 #include <sys/resource.h>
38 #include <sys/vnode.h>
42 #include <sys/taskq.h>
44 #include <sys/atomic.h>
45 #include <sys/namei.h>
47 #include <sys/cmn_err.h>
48 #include <sys/errno.h>
49 #include <sys/unistd.h>
50 #include <sys/zfs_dir.h>
51 #include <sys/zfs_ioctl.h>
52 #include <sys/fs/zfs.h>
54 #include <sys/dmu_objset.h>
60 #include <sys/dirent.h>
61 #include <sys/policy.h>
62 #include <sys/sunddi.h>
63 #include <sys/filio.h>
65 #include <sys/zfs_ctldir.h>
66 #include <sys/zfs_fuid.h>
67 #include <sys/zfs_sa.h>
69 #include <sys/zfs_rlock.h>
70 #include <sys/extdirent.h>
71 #include <sys/kidmap.h>
74 #include <sys/sf_buf.h>
75 #include <sys/sched.h>
77 #include <vm/vm_param.h>
78 #include <vm/vm_pageout.h>
83 * Each vnode op performs some logical unit of work. To do this, the ZPL must
84 * properly lock its in-core state, create a DMU transaction, do the work,
85 * record this work in the intent log (ZIL), commit the DMU transaction,
86 * and wait for the intent log to commit if it is a synchronous operation.
87 * Moreover, the vnode ops must work in both normal and log replay context.
88 * The ordering of events is important to avoid deadlocks and references
89 * to freed memory. The example below illustrates the following Big Rules:
91 * (1) A check must be made in each zfs thread for a mounted file system.
92 * This is done avoiding races using ZFS_ENTER(zfsvfs).
93 * A ZFS_EXIT(zfsvfs) is needed before all returns. Any znodes
94 * must be checked with ZFS_VERIFY_ZP(zp). Both of these macros
95 * can return EIO from the calling function.
97 * (2) VN_RELE() should always be the last thing except for zil_commit()
98 * (if necessary) and ZFS_EXIT(). This is for 3 reasons:
99 * First, if it's the last reference, the vnode/znode
100 * can be freed, so the zp may point to freed memory. Second, the last
101 * reference will call zfs_zinactive(), which may induce a lot of work --
102 * pushing cached pages (which acquires range locks) and syncing out
103 * cached atime changes. Third, zfs_zinactive() may require a new tx,
104 * which could deadlock the system if you were already holding one.
105 * If you must call VN_RELE() within a tx then use VN_RELE_ASYNC().
107 * (3) All range locks must be grabbed before calling dmu_tx_assign(),
108 * as they can span dmu_tx_assign() calls.
110 * (4) Always pass TXG_NOWAIT as the second argument to dmu_tx_assign().
111 * This is critical because we don't want to block while holding locks.
112 * Note, in particular, that if a lock is sometimes acquired before
113 * the tx assigns, and sometimes after (e.g. z_lock), then failing to
114 * use a non-blocking assign can deadlock the system. The scenario:
116 * Thread A has grabbed a lock before calling dmu_tx_assign().
117 * Thread B is in an already-assigned tx, and blocks for this lock.
118 * Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
119 * forever, because the previous txg can't quiesce until B's tx commits.
121 * If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
122 * then drop all locks, call dmu_tx_wait(), and try again.
124 * (5) If the operation succeeded, generate the intent log entry for it
125 * before dropping locks. This ensures that the ordering of events
126 * in the intent log matches the order in which they actually occurred.
127 * During ZIL replay the zfs_log_* functions will update the sequence
128 * number to indicate the zil transaction has replayed.
130 * (6) At the end of each vnode op, the DMU tx must always commit,
131 * regardless of whether there were any errors.
133 * (7) After dropping all locks, invoke zil_commit(zilog, foid)
134 * to ensure that synchronous semantics are provided when necessary.
136 * In general, this is how things should be ordered in each vnode op:
138 * ZFS_ENTER(zfsvfs); // exit if unmounted
140 * zfs_dirent_lock(&dl, ...) // lock directory entry (may VN_HOLD())
141 * rw_enter(...); // grab any other locks you need
142 * tx = dmu_tx_create(...); // get DMU tx
143 * dmu_tx_hold_*(); // hold each object you might modify
144 * error = dmu_tx_assign(tx, TXG_NOWAIT); // try to assign
146 * rw_exit(...); // drop locks
147 * zfs_dirent_unlock(dl); // unlock directory entry
148 * VN_RELE(...); // release held vnodes
149 * if (error == ERESTART) {
154 * dmu_tx_abort(tx); // abort DMU tx
155 * ZFS_EXIT(zfsvfs); // finished in zfs
156 * return (error); // really out of space
158 * error = do_real_work(); // do whatever this VOP does
160 * zfs_log_*(...); // on success, make ZIL entry
161 * dmu_tx_commit(tx); // commit DMU tx -- error or not
162 * rw_exit(...); // drop locks
163 * zfs_dirent_unlock(dl); // unlock directory entry
164 * VN_RELE(...); // release held vnodes
165 * zil_commit(zilog, foid); // synchronous when necessary
166 * ZFS_EXIT(zfsvfs); // finished in zfs
167 * return (error); // done, report error
172 zfs_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
174 znode_t *zp = VTOZ(*vpp);
175 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
180 if ((flag & FWRITE) && (zp->z_pflags & ZFS_APPENDONLY) &&
181 ((flag & FAPPEND) == 0)) {
183 return (SET_ERROR(EPERM));
186 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
187 ZTOV(zp)->v_type == VREG &&
188 !(zp->z_pflags & ZFS_AV_QUARANTINED) && zp->z_size > 0) {
189 if (fs_vscan(*vpp, cr, 0) != 0) {
191 return (SET_ERROR(EACCES));
195 /* Keep a count of the synchronous opens in the znode */
196 if (flag & (FSYNC | FDSYNC))
197 atomic_inc_32(&zp->z_sync_cnt);
205 zfs_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr,
206 caller_context_t *ct)
208 znode_t *zp = VTOZ(vp);
209 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
212 * Clean up any locks held by this process on the vp.
214 cleanlocks(vp, ddi_get_pid(), 0);
215 cleanshares(vp, ddi_get_pid());
220 /* Decrement the synchronous opens in the znode */
221 if ((flag & (FSYNC | FDSYNC)) && (count == 1))
222 atomic_dec_32(&zp->z_sync_cnt);
224 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
225 ZTOV(zp)->v_type == VREG &&
226 !(zp->z_pflags & ZFS_AV_QUARANTINED) && zp->z_size > 0)
227 VERIFY(fs_vscan(vp, cr, 1) == 0);
234 * Lseek support for finding holes (cmd == _FIO_SEEK_HOLE) and
235 * data (cmd == _FIO_SEEK_DATA). "off" is an in/out parameter.
238 zfs_holey(vnode_t *vp, u_long cmd, offset_t *off)
240 znode_t *zp = VTOZ(vp);
241 uint64_t noff = (uint64_t)*off; /* new offset */
246 file_sz = zp->z_size;
247 if (noff >= file_sz) {
248 return (SET_ERROR(ENXIO));
251 if (cmd == _FIO_SEEK_HOLE)
256 error = dmu_offset_next(zp->z_zfsvfs->z_os, zp->z_id, hole, &noff);
259 if ((error == ESRCH) || (noff > file_sz)) {
261 * Handle the virtual hole at the end of file.
267 return (SET_ERROR(ENXIO));
278 zfs_ioctl(vnode_t *vp, u_long com, intptr_t data, int flag, cred_t *cred,
279 int *rvalp, caller_context_t *ct)
291 * The following two ioctls are used by bfu. Faking out,
292 * necessary to avoid bfu errors.
301 if (ddi_copyin((void *)data, &off, sizeof (off), flag))
302 return (SET_ERROR(EFAULT));
304 off = *(offset_t *)data;
307 zfsvfs = zp->z_zfsvfs;
311 /* offset parameter is in/out */
312 error = zfs_holey(vp, com, &off);
317 if (ddi_copyout(&off, (void *)data, sizeof (off), flag))
318 return (SET_ERROR(EFAULT));
320 *(offset_t *)data = off;
324 return (SET_ERROR(ENOTTY));
328 page_busy(vnode_t *vp, int64_t start, int64_t off, int64_t nbytes)
334 zfs_vmobject_assert_wlocked(obj);
337 if ((pp = vm_page_lookup(obj, OFF_TO_IDX(start))) != NULL &&
339 if (vm_page_xbusied(pp)) {
341 * Reference the page before unlocking and
342 * sleeping so that the page daemon is less
343 * likely to reclaim it.
345 vm_page_reference(pp);
347 zfs_vmobject_wunlock(obj);
348 vm_page_busy_sleep(pp, "zfsmwb");
349 zfs_vmobject_wlock(obj);
353 } else if (pp == NULL) {
354 pp = vm_page_alloc(obj, OFF_TO_IDX(start),
355 VM_ALLOC_SYSTEM | VM_ALLOC_IFCACHED |
358 ASSERT(pp != NULL && !pp->valid);
363 ASSERT3U(pp->valid, ==, VM_PAGE_BITS_ALL);
364 vm_object_pip_add(obj, 1);
365 pmap_remove_write(pp);
366 vm_page_clear_dirty(pp, off, nbytes);
374 page_unbusy(vm_page_t pp)
378 vm_object_pip_subtract(pp->object, 1);
382 page_hold(vnode_t *vp, int64_t start)
388 zfs_vmobject_assert_wlocked(obj);
391 if ((pp = vm_page_lookup(obj, OFF_TO_IDX(start))) != NULL &&
393 if (vm_page_xbusied(pp)) {
395 * Reference the page before unlocking and
396 * sleeping so that the page daemon is less
397 * likely to reclaim it.
399 vm_page_reference(pp);
401 zfs_vmobject_wunlock(obj);
402 vm_page_busy_sleep(pp, "zfsmwb");
403 zfs_vmobject_wlock(obj);
407 ASSERT3U(pp->valid, ==, VM_PAGE_BITS_ALL);
420 page_unhold(vm_page_t pp)
429 zfs_map_page(vm_page_t pp, struct sf_buf **sfp)
432 *sfp = sf_buf_alloc(pp, 0);
433 return ((caddr_t)sf_buf_kva(*sfp));
437 zfs_unmap_page(struct sf_buf *sf)
444 * When a file is memory mapped, we must keep the IO data synchronized
445 * between the DMU cache and the memory mapped pages. What this means:
447 * On Write: If we find a memory mapped page, we write to *both*
448 * the page and the dmu buffer.
451 update_pages(vnode_t *vp, int64_t start, int len, objset_t *os, uint64_t oid,
452 int segflg, dmu_tx_t *tx)
459 ASSERT(vp->v_mount != NULL);
463 off = start & PAGEOFFSET;
464 zfs_vmobject_wlock(obj);
465 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
467 int nbytes = imin(PAGESIZE - off, len);
469 if (segflg == UIO_NOCOPY) {
470 pp = vm_page_lookup(obj, OFF_TO_IDX(start));
472 ("zfs update_pages: NULL page in putpages case"));
474 ("zfs update_pages: unaligned data in putpages case"));
475 KASSERT(pp->valid == VM_PAGE_BITS_ALL,
476 ("zfs update_pages: invalid page in putpages case"));
477 KASSERT(vm_page_sbusied(pp),
478 ("zfs update_pages: unbusy page in putpages case"));
479 KASSERT(!pmap_page_is_write_mapped(pp),
480 ("zfs update_pages: writable page in putpages case"));
481 zfs_vmobject_wunlock(obj);
483 va = zfs_map_page(pp, &sf);
484 (void) dmu_write(os, oid, start, nbytes, va, tx);
487 zfs_vmobject_wlock(obj);
489 } else if ((pp = page_busy(vp, start, off, nbytes)) != NULL) {
490 zfs_vmobject_wunlock(obj);
492 va = zfs_map_page(pp, &sf);
493 (void) dmu_read(os, oid, start+off, nbytes,
494 va+off, DMU_READ_PREFETCH);;
497 zfs_vmobject_wlock(obj);
503 if (segflg != UIO_NOCOPY)
504 vm_object_pip_wakeupn(obj, 0);
505 zfs_vmobject_wunlock(obj);
509 * Read with UIO_NOCOPY flag means that sendfile(2) requests
510 * ZFS to populate a range of page cache pages with data.
512 * NOTE: this function could be optimized to pre-allocate
513 * all pages in advance, drain exclusive busy on all of them,
514 * map them into contiguous KVA region and populate them
515 * in one single dmu_read() call.
518 mappedread_sf(vnode_t *vp, int nbytes, uio_t *uio)
520 znode_t *zp = VTOZ(vp);
521 objset_t *os = zp->z_zfsvfs->z_os;
531 ASSERT(uio->uio_segflg == UIO_NOCOPY);
532 ASSERT(vp->v_mount != NULL);
535 ASSERT((uio->uio_loffset & PAGEOFFSET) == 0);
537 zfs_vmobject_wlock(obj);
538 for (start = uio->uio_loffset; len > 0; start += PAGESIZE) {
539 int bytes = MIN(PAGESIZE, len);
541 pp = vm_page_grab(obj, OFF_TO_IDX(start), VM_ALLOC_SBUSY |
542 VM_ALLOC_NORMAL | VM_ALLOC_IGN_SBUSY);
543 if (pp->valid == 0) {
544 zfs_vmobject_wunlock(obj);
545 va = zfs_map_page(pp, &sf);
546 error = dmu_read(os, zp->z_id, start, bytes, va,
548 if (bytes != PAGESIZE && error == 0)
549 bzero(va + bytes, PAGESIZE - bytes);
551 zfs_vmobject_wlock(obj);
555 if (pp->wire_count == 0 && pp->valid == 0 &&
559 pp->valid = VM_PAGE_BITS_ALL;
560 vm_page_activate(pp);
567 uio->uio_resid -= bytes;
568 uio->uio_offset += bytes;
571 zfs_vmobject_wunlock(obj);
576 * When a file is memory mapped, we must keep the IO data synchronized
577 * between the DMU cache and the memory mapped pages. What this means:
579 * On Read: We "read" preferentially from memory mapped pages,
580 * else we default from the dmu buffer.
582 * NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
583 * the file is memory mapped.
586 mappedread(vnode_t *vp, int nbytes, uio_t *uio)
588 znode_t *zp = VTOZ(vp);
589 objset_t *os = zp->z_zfsvfs->z_os;
597 ASSERT(vp->v_mount != NULL);
601 start = uio->uio_loffset;
602 off = start & PAGEOFFSET;
603 zfs_vmobject_wlock(obj);
604 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
606 uint64_t bytes = MIN(PAGESIZE - off, len);
608 if (pp = page_hold(vp, start)) {
612 zfs_vmobject_wunlock(obj);
613 va = zfs_map_page(pp, &sf);
614 error = uiomove(va + off, bytes, UIO_READ, uio);
616 zfs_vmobject_wlock(obj);
619 zfs_vmobject_wunlock(obj);
620 error = dmu_read_uio(os, zp->z_id, uio, bytes);
621 zfs_vmobject_wlock(obj);
628 zfs_vmobject_wunlock(obj);
632 offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */
635 * Read bytes from specified file into supplied buffer.
637 * IN: vp - vnode of file to be read from.
638 * uio - structure supplying read location, range info,
640 * ioflag - SYNC flags; used to provide FRSYNC semantics.
641 * cr - credentials of caller.
642 * ct - caller context
644 * OUT: uio - updated offset and range, buffer filled.
646 * RETURN: 0 on success, error code on failure.
649 * vp - atime updated if byte count > 0
653 zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
655 znode_t *zp = VTOZ(vp);
656 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
667 if (zp->z_pflags & ZFS_AV_QUARANTINED) {
669 return (SET_ERROR(EACCES));
673 * Validate file offset
675 if (uio->uio_loffset < (offset_t)0) {
677 return (SET_ERROR(EINVAL));
681 * Fasttrack empty reads
683 if (uio->uio_resid == 0) {
689 * Check for mandatory locks
691 if (MANDMODE(zp->z_mode)) {
692 if (error = chklock(vp, FREAD,
693 uio->uio_loffset, uio->uio_resid, uio->uio_fmode, ct)) {
700 * If we're in FRSYNC mode, sync out this znode before reading it.
703 (ioflag & FRSYNC || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS))
704 zil_commit(zfsvfs->z_log, zp->z_id);
707 * Lock the range against changes.
709 rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER);
712 * If we are reading past end-of-file we can skip
713 * to the end; but we might still need to set atime.
715 if (uio->uio_loffset >= zp->z_size) {
720 ASSERT(uio->uio_loffset < zp->z_size);
721 n = MIN(uio->uio_resid, zp->z_size - uio->uio_loffset);
724 if ((uio->uio_extflg == UIO_XUIO) &&
725 (((xuio_t *)uio)->xu_type == UIOTYPE_ZEROCOPY)) {
727 int blksz = zp->z_blksz;
728 uint64_t offset = uio->uio_loffset;
730 xuio = (xuio_t *)uio;
732 nblk = (P2ROUNDUP(offset + n, blksz) - P2ALIGN(offset,
735 ASSERT(offset + n <= blksz);
738 (void) dmu_xuio_init(xuio, nblk);
740 if (vn_has_cached_data(vp)) {
742 * For simplicity, we always allocate a full buffer
743 * even if we only expect to read a portion of a block.
745 while (--nblk >= 0) {
746 (void) dmu_xuio_add(xuio,
747 dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
755 nbytes = MIN(n, zfs_read_chunk_size -
756 P2PHASE(uio->uio_loffset, zfs_read_chunk_size));
759 if (uio->uio_segflg == UIO_NOCOPY)
760 error = mappedread_sf(vp, nbytes, uio);
762 #endif /* __FreeBSD__ */
763 if (vn_has_cached_data(vp))
764 error = mappedread(vp, nbytes, uio);
766 error = dmu_read_uio(os, zp->z_id, uio, nbytes);
768 /* convert checksum errors into IO errors */
770 error = SET_ERROR(EIO);
777 zfs_range_unlock(rl);
779 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
785 * Write the bytes to a file.
787 * IN: vp - vnode of file to be written to.
788 * uio - structure supplying write location, range info,
790 * ioflag - FAPPEND, FSYNC, and/or FDSYNC. FAPPEND is
791 * set if in append mode.
792 * cr - credentials of caller.
793 * ct - caller context (NFS/CIFS fem monitor only)
795 * OUT: uio - updated offset and range.
797 * RETURN: 0 on success, error code on failure.
800 * vp - ctime|mtime updated if byte count > 0
805 zfs_write(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
807 znode_t *zp = VTOZ(vp);
808 rlim64_t limit = MAXOFFSET_T;
809 ssize_t start_resid = uio->uio_resid;
813 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
818 int max_blksz = zfsvfs->z_max_blksz;
821 iovec_t *aiov = NULL;
824 int iovcnt = uio->uio_iovcnt;
825 iovec_t *iovp = uio->uio_iov;
828 sa_bulk_attr_t bulk[4];
829 uint64_t mtime[2], ctime[2];
832 * Fasttrack empty write
838 if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
844 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
845 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
846 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
848 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
852 * If immutable or not appending then return EPERM
854 if ((zp->z_pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) ||
855 ((zp->z_pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) &&
856 (uio->uio_loffset < zp->z_size))) {
858 return (SET_ERROR(EPERM));
861 zilog = zfsvfs->z_log;
864 * Validate file offset
866 woff = ioflag & FAPPEND ? zp->z_size : uio->uio_loffset;
869 return (SET_ERROR(EINVAL));
873 * Check for mandatory locks before calling zfs_range_lock()
874 * in order to prevent a deadlock with locks set via fcntl().
876 if (MANDMODE((mode_t)zp->z_mode) &&
877 (error = chklock(vp, FWRITE, woff, n, uio->uio_fmode, ct)) != 0) {
884 * Pre-fault the pages to ensure slow (eg NFS) pages
886 * Skip this if uio contains loaned arc_buf.
888 if ((uio->uio_extflg == UIO_XUIO) &&
889 (((xuio_t *)uio)->xu_type == UIOTYPE_ZEROCOPY))
890 xuio = (xuio_t *)uio;
892 uio_prefaultpages(MIN(n, max_blksz), uio);
896 * If in append mode, set the io offset pointer to eof.
898 if (ioflag & FAPPEND) {
900 * Obtain an appending range lock to guarantee file append
901 * semantics. We reset the write offset once we have the lock.
903 rl = zfs_range_lock(zp, 0, n, RL_APPEND);
905 if (rl->r_len == UINT64_MAX) {
907 * We overlocked the file because this write will cause
908 * the file block size to increase.
909 * Note that zp_size cannot change with this lock held.
913 uio->uio_loffset = woff;
916 * Note that if the file block size will change as a result of
917 * this write, then this range lock will lock the entire file
918 * so that we can re-write the block safely.
920 rl = zfs_range_lock(zp, woff, n, RL_WRITER);
923 if (vn_rlimit_fsize(vp, uio, uio->uio_td)) {
924 zfs_range_unlock(rl);
930 zfs_range_unlock(rl);
932 return (SET_ERROR(EFBIG));
935 if ((woff + n) > limit || woff > (limit - n))
938 /* Will this write extend the file length? */
939 write_eof = (woff + n > zp->z_size);
941 end_size = MAX(zp->z_size, woff + n);
944 * Write the file in reasonable size chunks. Each chunk is written
945 * in a separate transaction; this keeps the intent log records small
946 * and allows us to do more fine-grained space accounting.
950 woff = uio->uio_loffset;
952 if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
953 zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
955 dmu_return_arcbuf(abuf);
956 error = SET_ERROR(EDQUOT);
960 if (xuio && abuf == NULL) {
961 ASSERT(i_iov < iovcnt);
963 abuf = dmu_xuio_arcbuf(xuio, i_iov);
964 dmu_xuio_clear(xuio, i_iov);
965 DTRACE_PROBE3(zfs_cp_write, int, i_iov,
966 iovec_t *, aiov, arc_buf_t *, abuf);
967 ASSERT((aiov->iov_base == abuf->b_data) ||
968 ((char *)aiov->iov_base - (char *)abuf->b_data +
969 aiov->iov_len == arc_buf_size(abuf)));
971 } else if (abuf == NULL && n >= max_blksz &&
972 woff >= zp->z_size &&
973 P2PHASE(woff, max_blksz) == 0 &&
974 zp->z_blksz == max_blksz) {
976 * This write covers a full block. "Borrow" a buffer
977 * from the dmu so that we can fill it before we enter
978 * a transaction. This avoids the possibility of
979 * holding up the transaction if the data copy hangs
980 * up on a pagefault (e.g., from an NFS server mapping).
984 abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
986 ASSERT(abuf != NULL);
987 ASSERT(arc_buf_size(abuf) == max_blksz);
988 if (error = uiocopy(abuf->b_data, max_blksz,
989 UIO_WRITE, uio, &cbytes)) {
990 dmu_return_arcbuf(abuf);
993 ASSERT(cbytes == max_blksz);
997 * Start a transaction.
999 tx = dmu_tx_create(zfsvfs->z_os);
1000 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1001 dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
1002 zfs_sa_upgrade_txholds(tx, zp);
1003 error = dmu_tx_assign(tx, TXG_NOWAIT);
1005 if (error == ERESTART) {
1012 dmu_return_arcbuf(abuf);
1017 * If zfs_range_lock() over-locked we grow the blocksize
1018 * and then reduce the lock range. This will only happen
1019 * on the first iteration since zfs_range_reduce() will
1020 * shrink down r_len to the appropriate size.
1022 if (rl->r_len == UINT64_MAX) {
1025 if (zp->z_blksz > max_blksz) {
1026 ASSERT(!ISP2(zp->z_blksz));
1027 new_blksz = MIN(end_size, SPA_MAXBLOCKSIZE);
1029 new_blksz = MIN(end_size, max_blksz);
1031 zfs_grow_blocksize(zp, new_blksz, tx);
1032 zfs_range_reduce(rl, woff, n);
1036 * XXX - should we really limit each write to z_max_blksz?
1037 * Perhaps we should use SPA_MAXBLOCKSIZE chunks?
1039 nbytes = MIN(n, max_blksz - P2PHASE(woff, max_blksz));
1041 if (woff + nbytes > zp->z_size)
1042 vnode_pager_setsize(vp, woff + nbytes);
1045 tx_bytes = uio->uio_resid;
1046 error = dmu_write_uio_dbuf(sa_get_db(zp->z_sa_hdl),
1048 tx_bytes -= uio->uio_resid;
1051 ASSERT(xuio == NULL || tx_bytes == aiov->iov_len);
1053 * If this is not a full block write, but we are
1054 * extending the file past EOF and this data starts
1055 * block-aligned, use assign_arcbuf(). Otherwise,
1056 * write via dmu_write().
1058 if (tx_bytes < max_blksz && (!write_eof ||
1059 aiov->iov_base != abuf->b_data)) {
1061 dmu_write(zfsvfs->z_os, zp->z_id, woff,
1062 aiov->iov_len, aiov->iov_base, tx);
1063 dmu_return_arcbuf(abuf);
1064 xuio_stat_wbuf_copied();
1066 ASSERT(xuio || tx_bytes == max_blksz);
1067 dmu_assign_arcbuf(sa_get_db(zp->z_sa_hdl),
1070 ASSERT(tx_bytes <= uio->uio_resid);
1071 uioskip(uio, tx_bytes);
1073 if (tx_bytes && vn_has_cached_data(vp)) {
1074 update_pages(vp, woff, tx_bytes, zfsvfs->z_os,
1075 zp->z_id, uio->uio_segflg, tx);
1079 * If we made no progress, we're done. If we made even
1080 * partial progress, update the znode and ZIL accordingly.
1082 if (tx_bytes == 0) {
1083 (void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zfsvfs),
1084 (void *)&zp->z_size, sizeof (uint64_t), tx);
1091 * Clear Set-UID/Set-GID bits on successful write if not
1092 * privileged and at least one of the excute bits is set.
1094 * It would be nice to to this after all writes have
1095 * been done, but that would still expose the ISUID/ISGID
1096 * to another app after the partial write is committed.
1098 * Note: we don't call zfs_fuid_map_id() here because
1099 * user 0 is not an ephemeral uid.
1101 mutex_enter(&zp->z_acl_lock);
1102 if ((zp->z_mode & (S_IXUSR | (S_IXUSR >> 3) |
1103 (S_IXUSR >> 6))) != 0 &&
1104 (zp->z_mode & (S_ISUID | S_ISGID)) != 0 &&
1105 secpolicy_vnode_setid_retain(vp, cr,
1106 (zp->z_mode & S_ISUID) != 0 && zp->z_uid == 0) != 0) {
1108 zp->z_mode &= ~(S_ISUID | S_ISGID);
1109 newmode = zp->z_mode;
1110 (void) sa_update(zp->z_sa_hdl, SA_ZPL_MODE(zfsvfs),
1111 (void *)&newmode, sizeof (uint64_t), tx);
1113 mutex_exit(&zp->z_acl_lock);
1115 zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
1119 * Update the file size (zp_size) if it has changed;
1120 * account for possible concurrent updates.
1122 while ((end_size = zp->z_size) < uio->uio_loffset) {
1123 (void) atomic_cas_64(&zp->z_size, end_size,
1128 * If we are replaying and eof is non zero then force
1129 * the file size to the specified eof. Note, there's no
1130 * concurrency during replay.
1132 if (zfsvfs->z_replay && zfsvfs->z_replay_eof != 0)
1133 zp->z_size = zfsvfs->z_replay_eof;
1135 error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
1137 zfs_log_write(zilog, tx, TX_WRITE, zp, woff, tx_bytes, ioflag);
1142 ASSERT(tx_bytes == nbytes);
1147 uio_prefaultpages(MIN(n, max_blksz), uio);
1151 zfs_range_unlock(rl);
1154 * If we're in replay mode, or we made no progress, return error.
1155 * Otherwise, it's at least a partial write, so it's successful.
1157 if (zfsvfs->z_replay || uio->uio_resid == start_resid) {
1162 if (ioflag & (FSYNC | FDSYNC) ||
1163 zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1164 zil_commit(zilog, zp->z_id);
1171 zfs_get_done(zgd_t *zgd, int error)
1173 znode_t *zp = zgd->zgd_private;
1174 objset_t *os = zp->z_zfsvfs->z_os;
1177 dmu_buf_rele(zgd->zgd_db, zgd);
1179 zfs_range_unlock(zgd->zgd_rl);
1182 * Release the vnode asynchronously as we currently have the
1183 * txg stopped from syncing.
1185 VN_RELE_ASYNC(ZTOV(zp), dsl_pool_vnrele_taskq(dmu_objset_pool(os)));
1187 if (error == 0 && zgd->zgd_bp)
1188 zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
1190 kmem_free(zgd, sizeof (zgd_t));
1194 static int zil_fault_io = 0;
1198 * Get data to generate a TX_WRITE intent log record.
1201 zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
1203 zfsvfs_t *zfsvfs = arg;
1204 objset_t *os = zfsvfs->z_os;
1206 uint64_t object = lr->lr_foid;
1207 uint64_t offset = lr->lr_offset;
1208 uint64_t size = lr->lr_length;
1209 blkptr_t *bp = &lr->lr_blkptr;
1214 ASSERT(zio != NULL);
1218 * Nothing to do if the file has been removed
1220 if (zfs_zget(zfsvfs, object, &zp) != 0)
1221 return (SET_ERROR(ENOENT));
1222 if (zp->z_unlinked) {
1224 * Release the vnode asynchronously as we currently have the
1225 * txg stopped from syncing.
1227 VN_RELE_ASYNC(ZTOV(zp),
1228 dsl_pool_vnrele_taskq(dmu_objset_pool(os)));
1229 return (SET_ERROR(ENOENT));
1232 zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
1233 zgd->zgd_zilog = zfsvfs->z_log;
1234 zgd->zgd_private = zp;
1237 * Write records come in two flavors: immediate and indirect.
1238 * For small writes it's cheaper to store the data with the
1239 * log record (immediate); for large writes it's cheaper to
1240 * sync the data and get a pointer to it (indirect) so that
1241 * we don't have to write the data twice.
1243 if (buf != NULL) { /* immediate write */
1244 zgd->zgd_rl = zfs_range_lock(zp, offset, size, RL_READER);
1245 /* test for truncation needs to be done while range locked */
1246 if (offset >= zp->z_size) {
1247 error = SET_ERROR(ENOENT);
1249 error = dmu_read(os, object, offset, size, buf,
1250 DMU_READ_NO_PREFETCH);
1252 ASSERT(error == 0 || error == ENOENT);
1253 } else { /* indirect write */
1255 * Have to lock the whole block to ensure when it's
1256 * written out and it's checksum is being calculated
1257 * that no one can change the data. We need to re-check
1258 * blocksize after we get the lock in case it's changed!
1263 blkoff = ISP2(size) ? P2PHASE(offset, size) : offset;
1265 zgd->zgd_rl = zfs_range_lock(zp, offset, size,
1267 if (zp->z_blksz == size)
1270 zfs_range_unlock(zgd->zgd_rl);
1272 /* test for truncation needs to be done while range locked */
1273 if (lr->lr_offset >= zp->z_size)
1274 error = SET_ERROR(ENOENT);
1277 error = SET_ERROR(EIO);
1282 error = dmu_buf_hold(os, object, offset, zgd, &db,
1283 DMU_READ_NO_PREFETCH);
1286 blkptr_t *obp = dmu_buf_get_blkptr(db);
1288 ASSERT(BP_IS_HOLE(bp));
1295 ASSERT(db->db_offset == offset);
1296 ASSERT(db->db_size == size);
1298 error = dmu_sync(zio, lr->lr_common.lrc_txg,
1300 ASSERT(error || lr->lr_length <= zp->z_blksz);
1303 * On success, we need to wait for the write I/O
1304 * initiated by dmu_sync() to complete before we can
1305 * release this dbuf. We will finish everything up
1306 * in the zfs_get_done() callback.
1311 if (error == EALREADY) {
1312 lr->lr_common.lrc_txtype = TX_WRITE2;
1318 zfs_get_done(zgd, error);
1325 zfs_access(vnode_t *vp, int mode, int flag, cred_t *cr,
1326 caller_context_t *ct)
1328 znode_t *zp = VTOZ(vp);
1329 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1335 if (flag & V_ACE_MASK)
1336 error = zfs_zaccess(zp, mode, flag, B_FALSE, cr);
1338 error = zfs_zaccess_rwx(zp, mode, flag, cr);
1345 * If vnode is for a device return a specfs vnode instead.
1348 specvp_check(vnode_t **vpp, cred_t *cr)
1352 if (IS_DEVVP(*vpp)) {
1355 svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
1358 error = SET_ERROR(ENOSYS);
1366 * Lookup an entry in a directory, or an extended attribute directory.
1367 * If it exists, return a held vnode reference for it.
1369 * IN: dvp - vnode of directory to search.
1370 * nm - name of entry to lookup.
1371 * pnp - full pathname to lookup [UNUSED].
1372 * flags - LOOKUP_XATTR set if looking for an attribute.
1373 * rdir - root directory vnode [UNUSED].
1374 * cr - credentials of caller.
1375 * ct - caller context
1376 * direntflags - directory lookup flags
1377 * realpnp - returned pathname.
1379 * OUT: vpp - vnode of located entry, NULL if not found.
1381 * RETURN: 0 on success, error code on failure.
1388 zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct componentname *cnp,
1389 int nameiop, cred_t *cr, kthread_t *td, int flags)
1391 znode_t *zdp = VTOZ(dvp);
1392 zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
1394 int *direntflags = NULL;
1395 void *realpnp = NULL;
1398 if (!(flags & (LOOKUP_XATTR | FIGNORECASE))) {
1400 if (dvp->v_type != VDIR) {
1401 return (SET_ERROR(ENOTDIR));
1402 } else if (zdp->z_sa_hdl == NULL) {
1403 return (SET_ERROR(EIO));
1406 if (nm[0] == 0 || (nm[0] == '.' && nm[1] == '\0')) {
1407 error = zfs_fastaccesschk_execute(zdp, cr);
1415 vnode_t *tvp = dnlc_lookup(dvp, nm);
1418 error = zfs_fastaccesschk_execute(zdp, cr);
1423 if (tvp == DNLC_NO_VNODE) {
1425 return (SET_ERROR(ENOENT));
1428 return (specvp_check(vpp, cr));
1434 DTRACE_PROBE2(zfs__fastpath__lookup__miss, vnode_t *, dvp, char *, nm);
1441 if (flags & LOOKUP_XATTR) {
1444 * If the xattr property is off, refuse the lookup request.
1446 if (!(zfsvfs->z_vfs->vfs_flag & VFS_XATTR)) {
1448 return (SET_ERROR(EINVAL));
1453 * We don't allow recursive attributes..
1454 * Maybe someday we will.
1456 if (zdp->z_pflags & ZFS_XATTR) {
1458 return (SET_ERROR(EINVAL));
1461 if (error = zfs_get_xattrdir(VTOZ(dvp), vpp, cr, flags)) {
1467 * Do we have permission to get into attribute directory?
1470 if (error = zfs_zaccess(VTOZ(*vpp), ACE_EXECUTE, 0,
1480 if (dvp->v_type != VDIR) {
1482 return (SET_ERROR(ENOTDIR));
1486 * Check accessibility of directory.
1489 if (error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr)) {
1494 if (zfsvfs->z_utf8 && u8_validate(nm, strlen(nm),
1495 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1497 return (SET_ERROR(EILSEQ));
1500 error = zfs_dirlook(zdp, nm, vpp, flags, direntflags, realpnp);
1502 error = specvp_check(vpp, cr);
1504 /* Translate errors and add SAVENAME when needed. */
1505 if (cnp->cn_flags & ISLASTCN) {
1509 if (error == ENOENT) {
1510 error = EJUSTRETURN;
1511 cnp->cn_flags |= SAVENAME;
1517 cnp->cn_flags |= SAVENAME;
1521 if (error == 0 && (nm[0] != '.' || nm[1] != '\0')) {
1524 if (cnp->cn_flags & ISDOTDOT) {
1525 ltype = VOP_ISLOCKED(dvp);
1529 error = vn_lock(*vpp, cnp->cn_lkflags);
1530 if (cnp->cn_flags & ISDOTDOT)
1531 vn_lock(dvp, ltype | LK_RETRY);
1541 #ifdef FREEBSD_NAMECACHE
1543 * Insert name into cache (as non-existent) if appropriate.
1545 if (error == ENOENT && (cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
1546 cache_enter(dvp, *vpp, cnp);
1548 * Insert name into cache if appropriate.
1550 if (error == 0 && (cnp->cn_flags & MAKEENTRY)) {
1551 if (!(cnp->cn_flags & ISLASTCN) ||
1552 (nameiop != DELETE && nameiop != RENAME)) {
1553 cache_enter(dvp, *vpp, cnp);
1562 * Attempt to create a new entry in a directory. If the entry
1563 * already exists, truncate the file if permissible, else return
1564 * an error. Return the vp of the created or trunc'd file.
1566 * IN: dvp - vnode of directory to put new file entry in.
1567 * name - name of new file entry.
1568 * vap - attributes of new file.
1569 * excl - flag indicating exclusive or non-exclusive mode.
1570 * mode - mode to open file with.
1571 * cr - credentials of caller.
1572 * flag - large file flag [UNUSED].
1573 * ct - caller context
1574 * vsecp - ACL to be set
1576 * OUT: vpp - vnode of created or trunc'd entry.
1578 * RETURN: 0 on success, error code on failure.
1581 * dvp - ctime|mtime updated if new entry created
1582 * vp - ctime|mtime always, atime if new
1587 zfs_create(vnode_t *dvp, char *name, vattr_t *vap, int excl, int mode,
1588 vnode_t **vpp, cred_t *cr, kthread_t *td)
1590 znode_t *zp, *dzp = VTOZ(dvp);
1591 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1599 gid_t gid = crgetgid(cr);
1600 zfs_acl_ids_t acl_ids;
1601 boolean_t fuid_dirtied;
1602 boolean_t have_acl = B_FALSE;
1607 * If we have an ephemeral id, ACL, or XVATTR then
1608 * make sure file system is at proper version
1611 ksid = crgetsid(cr, KSID_OWNER);
1613 uid = ksid_getid(ksid);
1617 if (zfsvfs->z_use_fuids == B_FALSE &&
1618 (vsecp || (vap->va_mask & AT_XVATTR) ||
1619 IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
1620 return (SET_ERROR(EINVAL));
1625 zilog = zfsvfs->z_log;
1627 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
1628 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1630 return (SET_ERROR(EILSEQ));
1633 if (vap->va_mask & AT_XVATTR) {
1634 if ((error = secpolicy_xvattr(dvp, (xvattr_t *)vap,
1635 crgetuid(cr), cr, vap->va_type)) != 0) {
1643 if ((vap->va_mode & S_ISVTX) && secpolicy_vnode_stky_modify(cr))
1644 vap->va_mode &= ~S_ISVTX;
1646 if (*name == '\0') {
1648 * Null component name refers to the directory itself.
1655 /* possible VN_HOLD(zp) */
1658 if (flag & FIGNORECASE)
1661 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1665 zfs_acl_ids_free(&acl_ids);
1666 if (strcmp(name, "..") == 0)
1667 error = SET_ERROR(EISDIR);
1677 * Create a new file object and update the directory
1680 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
1682 zfs_acl_ids_free(&acl_ids);
1687 * We only support the creation of regular files in
1688 * extended attribute directories.
1691 if ((dzp->z_pflags & ZFS_XATTR) &&
1692 (vap->va_type != VREG)) {
1694 zfs_acl_ids_free(&acl_ids);
1695 error = SET_ERROR(EINVAL);
1699 if (!have_acl && (error = zfs_acl_ids_create(dzp, 0, vap,
1700 cr, vsecp, &acl_ids)) != 0)
1704 if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
1705 zfs_acl_ids_free(&acl_ids);
1706 error = SET_ERROR(EDQUOT);
1710 tx = dmu_tx_create(os);
1712 dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
1713 ZFS_SA_BASE_ATTR_SIZE);
1715 fuid_dirtied = zfsvfs->z_fuid_dirty;
1717 zfs_fuid_txhold(zfsvfs, tx);
1718 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
1719 dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
1720 if (!zfsvfs->z_use_sa &&
1721 acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
1722 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
1723 0, acl_ids.z_aclp->z_acl_bytes);
1725 error = dmu_tx_assign(tx, TXG_NOWAIT);
1727 zfs_dirent_unlock(dl);
1728 if (error == ERESTART) {
1733 zfs_acl_ids_free(&acl_ids);
1738 zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
1741 zfs_fuid_sync(zfsvfs, tx);
1743 (void) zfs_link_create(dl, zp, tx, ZNEW);
1744 txtype = zfs_log_create_txtype(Z_FILE, vsecp, vap);
1745 if (flag & FIGNORECASE)
1747 zfs_log_create(zilog, tx, txtype, dzp, zp, name,
1748 vsecp, acl_ids.z_fuidp, vap);
1749 zfs_acl_ids_free(&acl_ids);
1752 int aflags = (flag & FAPPEND) ? V_APPEND : 0;
1755 zfs_acl_ids_free(&acl_ids);
1759 * A directory entry already exists for this name.
1762 * Can't truncate an existing file if in exclusive mode.
1765 error = SET_ERROR(EEXIST);
1769 * Can't open a directory for writing.
1771 if ((ZTOV(zp)->v_type == VDIR) && (mode & S_IWRITE)) {
1772 error = SET_ERROR(EISDIR);
1776 * Verify requested access to file.
1778 if (mode && (error = zfs_zaccess_rwx(zp, mode, aflags, cr))) {
1782 mutex_enter(&dzp->z_lock);
1784 mutex_exit(&dzp->z_lock);
1787 * Truncate regular files if requested.
1789 if ((ZTOV(zp)->v_type == VREG) &&
1790 (vap->va_mask & AT_SIZE) && (vap->va_size == 0)) {
1791 /* we can't hold any locks when calling zfs_freesp() */
1792 zfs_dirent_unlock(dl);
1794 error = zfs_freesp(zp, 0, 0, mode, TRUE);
1796 vnevent_create(ZTOV(zp), ct);
1802 zfs_dirent_unlock(dl);
1809 error = specvp_check(vpp, cr);
1812 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1813 zil_commit(zilog, 0);
1820 * Remove an entry from a directory.
1822 * IN: dvp - vnode of directory to remove entry from.
1823 * name - name of entry to remove.
1824 * cr - credentials of caller.
1825 * ct - caller context
1826 * flags - case flags
1828 * RETURN: 0 on success, error code on failure.
1832 * vp - ctime (if nlink > 0)
1835 uint64_t null_xattr = 0;
1839 zfs_remove(vnode_t *dvp, char *name, cred_t *cr, caller_context_t *ct,
1842 znode_t *zp, *dzp = VTOZ(dvp);
1845 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1847 uint64_t acl_obj, xattr_obj;
1848 uint64_t xattr_obj_unlinked = 0;
1852 boolean_t may_delete_now, delete_now = FALSE;
1853 boolean_t unlinked, toobig = FALSE;
1855 pathname_t *realnmp = NULL;
1862 zilog = zfsvfs->z_log;
1864 if (flags & FIGNORECASE) {
1874 * Attempt to lock directory; fail if entry doesn't exist.
1876 if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1886 if (error = zfs_zaccess_delete(dzp, zp, cr)) {
1891 * Need to use rmdir for removing directories.
1893 if (vp->v_type == VDIR) {
1894 error = SET_ERROR(EPERM);
1898 vnevent_remove(vp, dvp, name, ct);
1901 dnlc_remove(dvp, realnmp->pn_buf);
1903 dnlc_remove(dvp, name);
1906 may_delete_now = vp->v_count == 1 && !vn_has_cached_data(vp);
1910 * We may delete the znode now, or we may put it in the unlinked set;
1911 * it depends on whether we're the last link, and on whether there are
1912 * other holds on the vnode. So we dmu_tx_hold() the right things to
1913 * allow for either case.
1916 tx = dmu_tx_create(zfsvfs->z_os);
1917 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1918 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1919 zfs_sa_upgrade_txholds(tx, zp);
1920 zfs_sa_upgrade_txholds(tx, dzp);
1921 if (may_delete_now) {
1923 zp->z_size > zp->z_blksz * DMU_MAX_DELETEBLKCNT;
1924 /* if the file is too big, only hold_free a token amount */
1925 dmu_tx_hold_free(tx, zp->z_id, 0,
1926 (toobig ? DMU_MAX_ACCESS : DMU_OBJECT_END));
1929 /* are there any extended attributes? */
1930 error = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
1931 &xattr_obj, sizeof (xattr_obj));
1932 if (error == 0 && xattr_obj) {
1933 error = zfs_zget(zfsvfs, xattr_obj, &xzp);
1935 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
1936 dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE);
1939 mutex_enter(&zp->z_lock);
1940 if ((acl_obj = zfs_external_acl(zp)) != 0 && may_delete_now)
1941 dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END);
1942 mutex_exit(&zp->z_lock);
1944 /* charge as an update -- would be nice not to charge at all */
1945 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1947 error = dmu_tx_assign(tx, TXG_NOWAIT);
1949 zfs_dirent_unlock(dl);
1953 if (error == ERESTART) {
1966 * Remove the directory entry.
1968 error = zfs_link_destroy(dl, zp, tx, zflg, &unlinked);
1978 * Hold z_lock so that we can make sure that the ACL obj
1979 * hasn't changed. Could have been deleted due to
1982 mutex_enter(&zp->z_lock);
1984 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
1985 &xattr_obj_unlinked, sizeof (xattr_obj_unlinked));
1986 delete_now = may_delete_now && !toobig &&
1987 vp->v_count == 1 && !vn_has_cached_data(vp) &&
1988 xattr_obj == xattr_obj_unlinked && zfs_external_acl(zp) ==
1995 panic("zfs_remove: delete_now branch taken");
1997 if (xattr_obj_unlinked) {
1998 ASSERT3U(xzp->z_links, ==, 2);
1999 mutex_enter(&xzp->z_lock);
2000 xzp->z_unlinked = 1;
2002 error = sa_update(xzp->z_sa_hdl, SA_ZPL_LINKS(zfsvfs),
2003 &xzp->z_links, sizeof (xzp->z_links), tx);
2004 ASSERT3U(error, ==, 0);
2005 mutex_exit(&xzp->z_lock);
2006 zfs_unlinked_add(xzp, tx);
2009 error = sa_remove(zp->z_sa_hdl,
2010 SA_ZPL_XATTR(zfsvfs), tx);
2012 error = sa_update(zp->z_sa_hdl,
2013 SA_ZPL_XATTR(zfsvfs), &null_xattr,
2014 sizeof (uint64_t), tx);
2019 ASSERT0(vp->v_count);
2021 mutex_exit(&zp->z_lock);
2022 zfs_znode_delete(zp, tx);
2023 } else if (unlinked) {
2024 mutex_exit(&zp->z_lock);
2025 zfs_unlinked_add(zp, tx);
2027 vp->v_vflag |= VV_NOSYNC;
2032 if (flags & FIGNORECASE)
2034 zfs_log_remove(zilog, tx, txtype, dzp, name, obj);
2041 zfs_dirent_unlock(dl);
2048 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2049 zil_commit(zilog, 0);
2056 * Create a new directory and insert it into dvp using the name
2057 * provided. Return a pointer to the inserted directory.
2059 * IN: dvp - vnode of directory to add subdir to.
2060 * dirname - name of new directory.
2061 * vap - attributes of new directory.
2062 * cr - credentials of caller.
2063 * ct - caller context
2064 * flags - case flags
2065 * vsecp - ACL to be set
2067 * OUT: vpp - vnode of created directory.
2069 * RETURN: 0 on success, error code on failure.
2072 * dvp - ctime|mtime updated
2073 * vp - ctime|mtime|atime updated
2077 zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr,
2078 caller_context_t *ct, int flags, vsecattr_t *vsecp)
2080 znode_t *zp, *dzp = VTOZ(dvp);
2081 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
2090 gid_t gid = crgetgid(cr);
2091 zfs_acl_ids_t acl_ids;
2092 boolean_t fuid_dirtied;
2094 ASSERT(vap->va_type == VDIR);
2097 * If we have an ephemeral id, ACL, or XVATTR then
2098 * make sure file system is at proper version
2101 ksid = crgetsid(cr, KSID_OWNER);
2103 uid = ksid_getid(ksid);
2106 if (zfsvfs->z_use_fuids == B_FALSE &&
2107 (vsecp || (vap->va_mask & AT_XVATTR) ||
2108 IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
2109 return (SET_ERROR(EINVAL));
2113 zilog = zfsvfs->z_log;
2115 if (dzp->z_pflags & ZFS_XATTR) {
2117 return (SET_ERROR(EINVAL));
2120 if (zfsvfs->z_utf8 && u8_validate(dirname,
2121 strlen(dirname), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
2123 return (SET_ERROR(EILSEQ));
2125 if (flags & FIGNORECASE)
2128 if (vap->va_mask & AT_XVATTR) {
2129 if ((error = secpolicy_xvattr(dvp, (xvattr_t *)vap,
2130 crgetuid(cr), cr, vap->va_type)) != 0) {
2136 if ((error = zfs_acl_ids_create(dzp, 0, vap, cr,
2137 vsecp, &acl_ids)) != 0) {
2142 * First make sure the new directory doesn't exist.
2144 * Existence is checked first to make sure we don't return
2145 * EACCES instead of EEXIST which can cause some applications
2151 if (error = zfs_dirent_lock(&dl, dzp, dirname, &zp, zf,
2153 zfs_acl_ids_free(&acl_ids);
2158 if (error = zfs_zaccess(dzp, ACE_ADD_SUBDIRECTORY, 0, B_FALSE, cr)) {
2159 zfs_acl_ids_free(&acl_ids);
2160 zfs_dirent_unlock(dl);
2165 if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
2166 zfs_acl_ids_free(&acl_ids);
2167 zfs_dirent_unlock(dl);
2169 return (SET_ERROR(EDQUOT));
2173 * Add a new entry to the directory.
2175 tx = dmu_tx_create(zfsvfs->z_os);
2176 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, dirname);
2177 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
2178 fuid_dirtied = zfsvfs->z_fuid_dirty;
2180 zfs_fuid_txhold(zfsvfs, tx);
2181 if (!zfsvfs->z_use_sa && acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
2182 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
2183 acl_ids.z_aclp->z_acl_bytes);
2186 dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
2187 ZFS_SA_BASE_ATTR_SIZE);
2189 error = dmu_tx_assign(tx, TXG_NOWAIT);
2191 zfs_dirent_unlock(dl);
2192 if (error == ERESTART) {
2197 zfs_acl_ids_free(&acl_ids);
2206 zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
2209 zfs_fuid_sync(zfsvfs, tx);
2212 * Now put new name in parent dir.
2214 (void) zfs_link_create(dl, zp, tx, ZNEW);
2218 txtype = zfs_log_create_txtype(Z_DIR, vsecp, vap);
2219 if (flags & FIGNORECASE)
2221 zfs_log_create(zilog, tx, txtype, dzp, zp, dirname, vsecp,
2222 acl_ids.z_fuidp, vap);
2224 zfs_acl_ids_free(&acl_ids);
2228 zfs_dirent_unlock(dl);
2230 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2231 zil_commit(zilog, 0);
2238 * Remove a directory subdir entry. If the current working
2239 * directory is the same as the subdir to be removed, the
2242 * IN: dvp - vnode of directory to remove from.
2243 * name - name of directory to be removed.
2244 * cwd - vnode of current working directory.
2245 * cr - credentials of caller.
2246 * ct - caller context
2247 * flags - case flags
2249 * RETURN: 0 on success, error code on failure.
2252 * dvp - ctime|mtime updated
2256 zfs_rmdir(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr,
2257 caller_context_t *ct, int flags)
2259 znode_t *dzp = VTOZ(dvp);
2262 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
2271 zilog = zfsvfs->z_log;
2273 if (flags & FIGNORECASE)
2279 * Attempt to lock directory; fail if entry doesn't exist.
2281 if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
2289 if (error = zfs_zaccess_delete(dzp, zp, cr)) {
2293 if (vp->v_type != VDIR) {
2294 error = SET_ERROR(ENOTDIR);
2299 error = SET_ERROR(EINVAL);
2303 vnevent_rmdir(vp, dvp, name, ct);
2306 * Grab a lock on the directory to make sure that noone is
2307 * trying to add (or lookup) entries while we are removing it.
2309 rw_enter(&zp->z_name_lock, RW_WRITER);
2312 * Grab a lock on the parent pointer to make sure we play well
2313 * with the treewalk and directory rename code.
2315 rw_enter(&zp->z_parent_lock, RW_WRITER);
2317 tx = dmu_tx_create(zfsvfs->z_os);
2318 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
2319 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
2320 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
2321 zfs_sa_upgrade_txholds(tx, zp);
2322 zfs_sa_upgrade_txholds(tx, dzp);
2323 error = dmu_tx_assign(tx, TXG_NOWAIT);
2325 rw_exit(&zp->z_parent_lock);
2326 rw_exit(&zp->z_name_lock);
2327 zfs_dirent_unlock(dl);
2329 if (error == ERESTART) {
2339 #ifdef FREEBSD_NAMECACHE
2343 error = zfs_link_destroy(dl, zp, tx, zflg, NULL);
2346 uint64_t txtype = TX_RMDIR;
2347 if (flags & FIGNORECASE)
2349 zfs_log_remove(zilog, tx, txtype, dzp, name, ZFS_NO_OBJECT);
2354 rw_exit(&zp->z_parent_lock);
2355 rw_exit(&zp->z_name_lock);
2356 #ifdef FREEBSD_NAMECACHE
2360 zfs_dirent_unlock(dl);
2364 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2365 zil_commit(zilog, 0);
2372 * Read as many directory entries as will fit into the provided
2373 * buffer from the given directory cursor position (specified in
2374 * the uio structure).
2376 * IN: vp - vnode of directory to read.
2377 * uio - structure supplying read location, range info,
2378 * and return buffer.
2379 * cr - credentials of caller.
2380 * ct - caller context
2381 * flags - case flags
2383 * OUT: uio - updated offset and range, buffer filled.
2384 * eofp - set to true if end-of-file detected.
2386 * RETURN: 0 on success, error code on failure.
2389 * vp - atime updated
2391 * Note that the low 4 bits of the cookie returned by zap is always zero.
2392 * This allows us to use the low range for "special" directory entries:
2393 * We use 0 for '.', and 1 for '..'. If this is the root of the filesystem,
2394 * we use the offset 2 for the '.zfs' directory.
2398 zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp, int *ncookies, u_long **cookies)
2400 znode_t *zp = VTOZ(vp);
2404 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2409 zap_attribute_t zap;
2410 uint_t bytes_wanted;
2411 uint64_t offset; /* must be unsigned; checks for < 1 */
2417 boolean_t check_sysattrs;
2420 u_long *cooks = NULL;
2426 if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs),
2427 &parent, sizeof (parent))) != 0) {
2433 * If we are not given an eof variable,
2440 * Check for valid iov_len.
2442 if (uio->uio_iov->iov_len <= 0) {
2444 return (SET_ERROR(EINVAL));
2448 * Quit if directory has been removed (posix)
2450 if ((*eofp = zp->z_unlinked) != 0) {
2457 offset = uio->uio_loffset;
2458 prefetch = zp->z_zn_prefetch;
2461 * Initialize the iterator cursor.
2465 * Start iteration from the beginning of the directory.
2467 zap_cursor_init(&zc, os, zp->z_id);
2470 * The offset is a serialized cursor.
2472 zap_cursor_init_serialized(&zc, os, zp->z_id, offset);
2476 * Get space to change directory entries into fs independent format.
2478 iovp = uio->uio_iov;
2479 bytes_wanted = iovp->iov_len;
2480 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) {
2481 bufsize = bytes_wanted;
2482 outbuf = kmem_alloc(bufsize, KM_SLEEP);
2483 odp = (struct dirent64 *)outbuf;
2485 bufsize = bytes_wanted;
2487 odp = (struct dirent64 *)iovp->iov_base;
2489 eodp = (struct edirent *)odp;
2491 if (ncookies != NULL) {
2493 * Minimum entry size is dirent size and 1 byte for a file name.
2495 ncooks = uio->uio_resid / (sizeof(struct dirent) - sizeof(((struct dirent *)NULL)->d_name) + 1);
2496 cooks = malloc(ncooks * sizeof(u_long), M_TEMP, M_WAITOK);
2501 * If this VFS supports the system attribute view interface; and
2502 * we're looking at an extended attribute directory; and we care
2503 * about normalization conflicts on this vfs; then we must check
2504 * for normalization conflicts with the sysattr name space.
2507 check_sysattrs = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
2508 (vp->v_flag & V_XATTRDIR) && zfsvfs->z_norm &&
2509 (flags & V_RDDIR_ENTFLAGS);
2515 * Transform to file-system independent format
2518 while (outcount < bytes_wanted) {
2521 off64_t *next = NULL;
2524 * Special case `.', `..', and `.zfs'.
2527 (void) strcpy(zap.za_name, ".");
2528 zap.za_normalization_conflict = 0;
2531 } else if (offset == 1) {
2532 (void) strcpy(zap.za_name, "..");
2533 zap.za_normalization_conflict = 0;
2536 } else if (offset == 2 && zfs_show_ctldir(zp)) {
2537 (void) strcpy(zap.za_name, ZFS_CTLDIR_NAME);
2538 zap.za_normalization_conflict = 0;
2539 objnum = ZFSCTL_INO_ROOT;
2545 if (error = zap_cursor_retrieve(&zc, &zap)) {
2546 if ((*eofp = (error == ENOENT)) != 0)
2552 if (zap.za_integer_length != 8 ||
2553 zap.za_num_integers != 1) {
2554 cmn_err(CE_WARN, "zap_readdir: bad directory "
2555 "entry, obj = %lld, offset = %lld\n",
2556 (u_longlong_t)zp->z_id,
2557 (u_longlong_t)offset);
2558 error = SET_ERROR(ENXIO);
2562 objnum = ZFS_DIRENT_OBJ(zap.za_first_integer);
2564 * MacOS X can extract the object type here such as:
2565 * uint8_t type = ZFS_DIRENT_TYPE(zap.za_first_integer);
2567 type = ZFS_DIRENT_TYPE(zap.za_first_integer);
2569 if (check_sysattrs && !zap.za_normalization_conflict) {
2571 zap.za_normalization_conflict =
2572 xattr_sysattr_casechk(zap.za_name);
2574 panic("%s:%u: TODO", __func__, __LINE__);
2579 if (flags & V_RDDIR_ACCFILTER) {
2581 * If we have no access at all, don't include
2582 * this entry in the returned information
2585 if (zfs_zget(zp->z_zfsvfs, objnum, &ezp) != 0)
2587 if (!zfs_has_access(ezp, cr)) {
2594 if (flags & V_RDDIR_ENTFLAGS)
2595 reclen = EDIRENT_RECLEN(strlen(zap.za_name));
2597 reclen = DIRENT64_RECLEN(strlen(zap.za_name));
2600 * Will this entry fit in the buffer?
2602 if (outcount + reclen > bufsize) {
2604 * Did we manage to fit anything in the buffer?
2607 error = SET_ERROR(EINVAL);
2612 if (flags & V_RDDIR_ENTFLAGS) {
2614 * Add extended flag entry:
2616 eodp->ed_ino = objnum;
2617 eodp->ed_reclen = reclen;
2618 /* NOTE: ed_off is the offset for the *next* entry */
2619 next = &(eodp->ed_off);
2620 eodp->ed_eflags = zap.za_normalization_conflict ?
2621 ED_CASE_CONFLICT : 0;
2622 (void) strncpy(eodp->ed_name, zap.za_name,
2623 EDIRENT_NAMELEN(reclen));
2624 eodp = (edirent_t *)((intptr_t)eodp + reclen);
2629 odp->d_ino = objnum;
2630 odp->d_reclen = reclen;
2631 odp->d_namlen = strlen(zap.za_name);
2632 (void) strlcpy(odp->d_name, zap.za_name, odp->d_namlen + 1);
2634 odp = (dirent64_t *)((intptr_t)odp + reclen);
2638 ASSERT(outcount <= bufsize);
2640 /* Prefetch znode */
2642 dmu_prefetch(os, objnum, 0, 0);
2646 * Move to the next entry, fill in the previous offset.
2648 if (offset > 2 || (offset == 2 && !zfs_show_ctldir(zp))) {
2649 zap_cursor_advance(&zc);
2650 offset = zap_cursor_serialize(&zc);
2655 if (cooks != NULL) {
2658 KASSERT(ncooks >= 0, ("ncookies=%d", ncooks));
2661 zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */
2663 /* Subtract unused cookies */
2664 if (ncookies != NULL)
2665 *ncookies -= ncooks;
2667 if (uio->uio_segflg == UIO_SYSSPACE && uio->uio_iovcnt == 1) {
2668 iovp->iov_base += outcount;
2669 iovp->iov_len -= outcount;
2670 uio->uio_resid -= outcount;
2671 } else if (error = uiomove(outbuf, (long)outcount, UIO_READ, uio)) {
2673 * Reset the pointer.
2675 offset = uio->uio_loffset;
2679 zap_cursor_fini(&zc);
2680 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
2681 kmem_free(outbuf, bufsize);
2683 if (error == ENOENT)
2686 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
2688 uio->uio_loffset = offset;
2690 if (error != 0 && cookies != NULL) {
2691 free(*cookies, M_TEMP);
2698 ulong_t zfs_fsync_sync_cnt = 4;
2701 zfs_fsync(vnode_t *vp, int syncflag, cred_t *cr, caller_context_t *ct)
2703 znode_t *zp = VTOZ(vp);
2704 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2706 (void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt);
2708 if (zfsvfs->z_os->os_sync != ZFS_SYNC_DISABLED) {
2711 zil_commit(zfsvfs->z_log, zp->z_id);
2719 * Get the requested file attributes and place them in the provided
2722 * IN: vp - vnode of file.
2723 * vap - va_mask identifies requested attributes.
2724 * If AT_XVATTR set, then optional attrs are requested
2725 * flags - ATTR_NOACLCHECK (CIFS server context)
2726 * cr - credentials of caller.
2727 * ct - caller context
2729 * OUT: vap - attribute values.
2731 * RETURN: 0 (always succeeds).
2735 zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2736 caller_context_t *ct)
2738 znode_t *zp = VTOZ(vp);
2739 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2742 u_longlong_t nblocks;
2744 uint64_t mtime[2], ctime[2], crtime[2], rdev;
2745 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2746 xoptattr_t *xoap = NULL;
2747 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2748 sa_bulk_attr_t bulk[4];
2754 zfs_fuid_map_ids(zp, cr, &vap->va_uid, &vap->va_gid);
2756 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
2757 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
2758 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CRTIME(zfsvfs), NULL, &crtime, 16);
2759 if (vp->v_type == VBLK || vp->v_type == VCHR)
2760 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_RDEV(zfsvfs), NULL,
2763 if ((error = sa_bulk_lookup(zp->z_sa_hdl, bulk, count)) != 0) {
2769 * If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES.
2770 * Also, if we are the owner don't bother, since owner should
2771 * always be allowed to read basic attributes of file.
2773 if (!(zp->z_pflags & ZFS_ACL_TRIVIAL) &&
2774 (vap->va_uid != crgetuid(cr))) {
2775 if (error = zfs_zaccess(zp, ACE_READ_ATTRIBUTES, 0,
2783 * Return all attributes. It's cheaper to provide the answer
2784 * than to determine whether we were asked the question.
2787 mutex_enter(&zp->z_lock);
2788 vap->va_type = IFTOVT(zp->z_mode);
2789 vap->va_mode = zp->z_mode & ~S_IFMT;
2791 vap->va_fsid = zp->z_zfsvfs->z_vfs->vfs_dev;
2793 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
2795 vap->va_nodeid = zp->z_id;
2796 if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp))
2797 links = zp->z_links + 1;
2799 links = zp->z_links;
2800 vap->va_nlink = MIN(links, LINK_MAX); /* nlink_t limit! */
2801 vap->va_size = zp->z_size;
2803 vap->va_rdev = vp->v_rdev;
2805 if (vp->v_type == VBLK || vp->v_type == VCHR)
2806 vap->va_rdev = zfs_cmpldev(rdev);
2808 vap->va_seq = zp->z_seq;
2809 vap->va_flags = 0; /* FreeBSD: Reset chflags(2) flags. */
2812 * Add in any requested optional attributes and the create time.
2813 * Also set the corresponding bits in the returned attribute bitmap.
2815 if ((xoap = xva_getxoptattr(xvap)) != NULL && zfsvfs->z_use_fuids) {
2816 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
2818 ((zp->z_pflags & ZFS_ARCHIVE) != 0);
2819 XVA_SET_RTN(xvap, XAT_ARCHIVE);
2822 if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
2823 xoap->xoa_readonly =
2824 ((zp->z_pflags & ZFS_READONLY) != 0);
2825 XVA_SET_RTN(xvap, XAT_READONLY);
2828 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
2830 ((zp->z_pflags & ZFS_SYSTEM) != 0);
2831 XVA_SET_RTN(xvap, XAT_SYSTEM);
2834 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
2836 ((zp->z_pflags & ZFS_HIDDEN) != 0);
2837 XVA_SET_RTN(xvap, XAT_HIDDEN);
2840 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
2841 xoap->xoa_nounlink =
2842 ((zp->z_pflags & ZFS_NOUNLINK) != 0);
2843 XVA_SET_RTN(xvap, XAT_NOUNLINK);
2846 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
2847 xoap->xoa_immutable =
2848 ((zp->z_pflags & ZFS_IMMUTABLE) != 0);
2849 XVA_SET_RTN(xvap, XAT_IMMUTABLE);
2852 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
2853 xoap->xoa_appendonly =
2854 ((zp->z_pflags & ZFS_APPENDONLY) != 0);
2855 XVA_SET_RTN(xvap, XAT_APPENDONLY);
2858 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
2860 ((zp->z_pflags & ZFS_NODUMP) != 0);
2861 XVA_SET_RTN(xvap, XAT_NODUMP);
2864 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
2866 ((zp->z_pflags & ZFS_OPAQUE) != 0);
2867 XVA_SET_RTN(xvap, XAT_OPAQUE);
2870 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
2871 xoap->xoa_av_quarantined =
2872 ((zp->z_pflags & ZFS_AV_QUARANTINED) != 0);
2873 XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
2876 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
2877 xoap->xoa_av_modified =
2878 ((zp->z_pflags & ZFS_AV_MODIFIED) != 0);
2879 XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
2882 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) &&
2883 vp->v_type == VREG) {
2884 zfs_sa_get_scanstamp(zp, xvap);
2887 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
2890 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zfsvfs),
2891 times, sizeof (times));
2892 ZFS_TIME_DECODE(&xoap->xoa_createtime, times);
2893 XVA_SET_RTN(xvap, XAT_CREATETIME);
2896 if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
2897 xoap->xoa_reparse = ((zp->z_pflags & ZFS_REPARSE) != 0);
2898 XVA_SET_RTN(xvap, XAT_REPARSE);
2900 if (XVA_ISSET_REQ(xvap, XAT_GEN)) {
2901 xoap->xoa_generation = zp->z_gen;
2902 XVA_SET_RTN(xvap, XAT_GEN);
2905 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE)) {
2907 ((zp->z_pflags & ZFS_OFFLINE) != 0);
2908 XVA_SET_RTN(xvap, XAT_OFFLINE);
2911 if (XVA_ISSET_REQ(xvap, XAT_SPARSE)) {
2913 ((zp->z_pflags & ZFS_SPARSE) != 0);
2914 XVA_SET_RTN(xvap, XAT_SPARSE);
2918 ZFS_TIME_DECODE(&vap->va_atime, zp->z_atime);
2919 ZFS_TIME_DECODE(&vap->va_mtime, mtime);
2920 ZFS_TIME_DECODE(&vap->va_ctime, ctime);
2921 ZFS_TIME_DECODE(&vap->va_birthtime, crtime);
2923 mutex_exit(&zp->z_lock);
2925 sa_object_size(zp->z_sa_hdl, &blksize, &nblocks);
2926 vap->va_blksize = blksize;
2927 vap->va_bytes = nblocks << 9; /* nblocks * 512 */
2929 if (zp->z_blksz == 0) {
2931 * Block size hasn't been set; suggest maximal I/O transfers.
2933 vap->va_blksize = zfsvfs->z_max_blksz;
2941 * Set the file attributes to the values contained in the
2944 * IN: vp - vnode of file to be modified.
2945 * vap - new attribute values.
2946 * If AT_XVATTR set, then optional attrs are being set
2947 * flags - ATTR_UTIME set if non-default time values provided.
2948 * - ATTR_NOACLCHECK (CIFS context only).
2949 * cr - credentials of caller.
2950 * ct - caller context
2952 * RETURN: 0 on success, error code on failure.
2955 * vp - ctime updated, mtime updated if size changed.
2959 zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2960 caller_context_t *ct)
2962 znode_t *zp = VTOZ(vp);
2963 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2968 uint_t mask = vap->va_mask;
2969 uint_t saved_mask = 0;
2970 uint64_t saved_mode;
2973 uint64_t new_uid, new_gid;
2975 uint64_t mtime[2], ctime[2];
2977 int need_policy = FALSE;
2979 zfs_fuid_info_t *fuidp = NULL;
2980 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2983 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2984 boolean_t fuid_dirtied = B_FALSE;
2985 sa_bulk_attr_t bulk[7], xattr_bulk[7];
2986 int count = 0, xattr_count = 0;
2991 if (mask & AT_NOSET)
2992 return (SET_ERROR(EINVAL));
2997 zilog = zfsvfs->z_log;
3000 * Make sure that if we have ephemeral uid/gid or xvattr specified
3001 * that file system is at proper version level
3004 if (zfsvfs->z_use_fuids == B_FALSE &&
3005 (((mask & AT_UID) && IS_EPHEMERAL(vap->va_uid)) ||
3006 ((mask & AT_GID) && IS_EPHEMERAL(vap->va_gid)) ||
3007 (mask & AT_XVATTR))) {
3009 return (SET_ERROR(EINVAL));
3012 if (mask & AT_SIZE && vp->v_type == VDIR) {
3014 return (SET_ERROR(EISDIR));
3017 if (mask & AT_SIZE && vp->v_type != VREG && vp->v_type != VFIFO) {
3019 return (SET_ERROR(EINVAL));
3023 * If this is an xvattr_t, then get a pointer to the structure of
3024 * optional attributes. If this is NULL, then we have a vattr_t.
3026 xoap = xva_getxoptattr(xvap);
3028 xva_init(&tmpxvattr);
3031 * Immutable files can only alter immutable bit and atime
3033 if ((zp->z_pflags & ZFS_IMMUTABLE) &&
3034 ((mask & (AT_SIZE|AT_UID|AT_GID|AT_MTIME|AT_MODE)) ||
3035 ((mask & AT_XVATTR) && XVA_ISSET_REQ(xvap, XAT_CREATETIME)))) {
3037 return (SET_ERROR(EPERM));
3040 if ((mask & AT_SIZE) && (zp->z_pflags & ZFS_READONLY)) {
3042 return (SET_ERROR(EPERM));
3046 * Verify timestamps doesn't overflow 32 bits.
3047 * ZFS can handle large timestamps, but 32bit syscalls can't
3048 * handle times greater than 2039. This check should be removed
3049 * once large timestamps are fully supported.
3051 if (mask & (AT_ATIME | AT_MTIME)) {
3052 if (((mask & AT_ATIME) && TIMESPEC_OVERFLOW(&vap->va_atime)) ||
3053 ((mask & AT_MTIME) && TIMESPEC_OVERFLOW(&vap->va_mtime))) {
3055 return (SET_ERROR(EOVERFLOW));
3063 /* Can this be moved to before the top label? */
3064 if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) {
3066 return (SET_ERROR(EROFS));
3070 * First validate permissions
3073 if (mask & AT_SIZE) {
3075 * XXX - Note, we are not providing any open
3076 * mode flags here (like FNDELAY), so we may
3077 * block if there are locks present... this
3078 * should be addressed in openat().
3080 /* XXX - would it be OK to generate a log record here? */
3081 err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE);
3088 if (mask & (AT_ATIME|AT_MTIME) ||
3089 ((mask & AT_XVATTR) && (XVA_ISSET_REQ(xvap, XAT_HIDDEN) ||
3090 XVA_ISSET_REQ(xvap, XAT_READONLY) ||
3091 XVA_ISSET_REQ(xvap, XAT_ARCHIVE) ||
3092 XVA_ISSET_REQ(xvap, XAT_OFFLINE) ||
3093 XVA_ISSET_REQ(xvap, XAT_SPARSE) ||
3094 XVA_ISSET_REQ(xvap, XAT_CREATETIME) ||
3095 XVA_ISSET_REQ(xvap, XAT_SYSTEM)))) {
3096 need_policy = zfs_zaccess(zp, ACE_WRITE_ATTRIBUTES, 0,
3100 if (mask & (AT_UID|AT_GID)) {
3101 int idmask = (mask & (AT_UID|AT_GID));
3106 * NOTE: even if a new mode is being set,
3107 * we may clear S_ISUID/S_ISGID bits.
3110 if (!(mask & AT_MODE))
3111 vap->va_mode = zp->z_mode;
3114 * Take ownership or chgrp to group we are a member of
3117 take_owner = (mask & AT_UID) && (vap->va_uid == crgetuid(cr));
3118 take_group = (mask & AT_GID) &&
3119 zfs_groupmember(zfsvfs, vap->va_gid, cr);
3122 * If both AT_UID and AT_GID are set then take_owner and
3123 * take_group must both be set in order to allow taking
3126 * Otherwise, send the check through secpolicy_vnode_setattr()
3130 if (((idmask == (AT_UID|AT_GID)) && take_owner && take_group) ||
3131 ((idmask == AT_UID) && take_owner) ||
3132 ((idmask == AT_GID) && take_group)) {
3133 if (zfs_zaccess(zp, ACE_WRITE_OWNER, 0,
3134 skipaclchk, cr) == 0) {
3136 * Remove setuid/setgid for non-privileged users
3138 secpolicy_setid_clear(vap, vp, cr);
3139 trim_mask = (mask & (AT_UID|AT_GID));
3148 mutex_enter(&zp->z_lock);
3149 oldva.va_mode = zp->z_mode;
3150 zfs_fuid_map_ids(zp, cr, &oldva.va_uid, &oldva.va_gid);
3151 if (mask & AT_XVATTR) {
3153 * Update xvattr mask to include only those attributes
3154 * that are actually changing.
3156 * the bits will be restored prior to actually setting
3157 * the attributes so the caller thinks they were set.
3159 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
3160 if (xoap->xoa_appendonly !=
3161 ((zp->z_pflags & ZFS_APPENDONLY) != 0)) {
3164 XVA_CLR_REQ(xvap, XAT_APPENDONLY);
3165 XVA_SET_REQ(&tmpxvattr, XAT_APPENDONLY);
3169 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
3170 if (xoap->xoa_nounlink !=
3171 ((zp->z_pflags & ZFS_NOUNLINK) != 0)) {
3174 XVA_CLR_REQ(xvap, XAT_NOUNLINK);
3175 XVA_SET_REQ(&tmpxvattr, XAT_NOUNLINK);
3179 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
3180 if (xoap->xoa_immutable !=
3181 ((zp->z_pflags & ZFS_IMMUTABLE) != 0)) {
3184 XVA_CLR_REQ(xvap, XAT_IMMUTABLE);
3185 XVA_SET_REQ(&tmpxvattr, XAT_IMMUTABLE);
3189 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
3190 if (xoap->xoa_nodump !=
3191 ((zp->z_pflags & ZFS_NODUMP) != 0)) {
3194 XVA_CLR_REQ(xvap, XAT_NODUMP);
3195 XVA_SET_REQ(&tmpxvattr, XAT_NODUMP);
3199 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
3200 if (xoap->xoa_av_modified !=
3201 ((zp->z_pflags & ZFS_AV_MODIFIED) != 0)) {
3204 XVA_CLR_REQ(xvap, XAT_AV_MODIFIED);
3205 XVA_SET_REQ(&tmpxvattr, XAT_AV_MODIFIED);
3209 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
3210 if ((vp->v_type != VREG &&
3211 xoap->xoa_av_quarantined) ||
3212 xoap->xoa_av_quarantined !=
3213 ((zp->z_pflags & ZFS_AV_QUARANTINED) != 0)) {
3216 XVA_CLR_REQ(xvap, XAT_AV_QUARANTINED);
3217 XVA_SET_REQ(&tmpxvattr, XAT_AV_QUARANTINED);
3221 if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
3222 mutex_exit(&zp->z_lock);
3224 return (SET_ERROR(EPERM));
3227 if (need_policy == FALSE &&
3228 (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) ||
3229 XVA_ISSET_REQ(xvap, XAT_OPAQUE))) {
3234 mutex_exit(&zp->z_lock);
3236 if (mask & AT_MODE) {
3237 if (zfs_zaccess(zp, ACE_WRITE_ACL, 0, skipaclchk, cr) == 0) {
3238 err = secpolicy_setid_setsticky_clear(vp, vap,
3244 trim_mask |= AT_MODE;
3252 * If trim_mask is set then take ownership
3253 * has been granted or write_acl is present and user
3254 * has the ability to modify mode. In that case remove
3255 * UID|GID and or MODE from mask so that
3256 * secpolicy_vnode_setattr() doesn't revoke it.
3260 saved_mask = vap->va_mask;
3261 vap->va_mask &= ~trim_mask;
3262 if (trim_mask & AT_MODE) {
3264 * Save the mode, as secpolicy_vnode_setattr()
3265 * will overwrite it with ova.va_mode.
3267 saved_mode = vap->va_mode;
3270 err = secpolicy_vnode_setattr(cr, vp, vap, &oldva, flags,
3271 (int (*)(void *, int, cred_t *))zfs_zaccess_unix, zp);
3278 vap->va_mask |= saved_mask;
3279 if (trim_mask & AT_MODE) {
3281 * Recover the mode after
3282 * secpolicy_vnode_setattr().
3284 vap->va_mode = saved_mode;
3290 * secpolicy_vnode_setattr, or take ownership may have
3293 mask = vap->va_mask;
3295 if ((mask & (AT_UID | AT_GID))) {
3296 err = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
3297 &xattr_obj, sizeof (xattr_obj));
3299 if (err == 0 && xattr_obj) {
3300 err = zfs_zget(zp->z_zfsvfs, xattr_obj, &attrzp);
3304 if (mask & AT_UID) {
3305 new_uid = zfs_fuid_create(zfsvfs,
3306 (uint64_t)vap->va_uid, cr, ZFS_OWNER, &fuidp);
3307 if (new_uid != zp->z_uid &&
3308 zfs_fuid_overquota(zfsvfs, B_FALSE, new_uid)) {
3310 VN_RELE(ZTOV(attrzp));
3311 err = SET_ERROR(EDQUOT);
3316 if (mask & AT_GID) {
3317 new_gid = zfs_fuid_create(zfsvfs, (uint64_t)vap->va_gid,
3318 cr, ZFS_GROUP, &fuidp);
3319 if (new_gid != zp->z_gid &&
3320 zfs_fuid_overquota(zfsvfs, B_TRUE, new_gid)) {
3322 VN_RELE(ZTOV(attrzp));
3323 err = SET_ERROR(EDQUOT);
3328 tx = dmu_tx_create(zfsvfs->z_os);
3330 if (mask & AT_MODE) {
3331 uint64_t pmode = zp->z_mode;
3333 new_mode = (pmode & S_IFMT) | (vap->va_mode & ~S_IFMT);
3335 if (zp->z_zfsvfs->z_acl_mode == ZFS_ACL_RESTRICTED &&
3336 !(zp->z_pflags & ZFS_ACL_TRIVIAL)) {
3337 err = SET_ERROR(EPERM);
3341 if (err = zfs_acl_chmod_setattr(zp, &aclp, new_mode))
3344 mutex_enter(&zp->z_lock);
3345 if (!zp->z_is_sa && ((acl_obj = zfs_external_acl(zp)) != 0)) {
3347 * Are we upgrading ACL from old V0 format
3350 if (zfsvfs->z_version >= ZPL_VERSION_FUID &&
3351 zfs_znode_acl_version(zp) ==
3352 ZFS_ACL_VERSION_INITIAL) {
3353 dmu_tx_hold_free(tx, acl_obj, 0,
3355 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
3356 0, aclp->z_acl_bytes);
3358 dmu_tx_hold_write(tx, acl_obj, 0,
3361 } else if (!zp->z_is_sa && aclp->z_acl_bytes > ZFS_ACE_SPACE) {
3362 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
3363 0, aclp->z_acl_bytes);
3365 mutex_exit(&zp->z_lock);
3366 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
3368 if ((mask & AT_XVATTR) &&
3369 XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
3370 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
3372 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
3376 dmu_tx_hold_sa(tx, attrzp->z_sa_hdl, B_FALSE);
3379 fuid_dirtied = zfsvfs->z_fuid_dirty;
3381 zfs_fuid_txhold(zfsvfs, tx);
3383 zfs_sa_upgrade_txholds(tx, zp);
3385 err = dmu_tx_assign(tx, TXG_NOWAIT);
3387 if (err == ERESTART)
3394 * Set each attribute requested.
3395 * We group settings according to the locks they need to acquire.
3397 * Note: you cannot set ctime directly, although it will be
3398 * updated as a side-effect of calling this function.
3402 if (mask & (AT_UID|AT_GID|AT_MODE))
3403 mutex_enter(&zp->z_acl_lock);
3404 mutex_enter(&zp->z_lock);
3406 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
3407 &zp->z_pflags, sizeof (zp->z_pflags));
3410 if (mask & (AT_UID|AT_GID|AT_MODE))
3411 mutex_enter(&attrzp->z_acl_lock);
3412 mutex_enter(&attrzp->z_lock);
3413 SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
3414 SA_ZPL_FLAGS(zfsvfs), NULL, &attrzp->z_pflags,
3415 sizeof (attrzp->z_pflags));
3418 if (mask & (AT_UID|AT_GID)) {
3420 if (mask & AT_UID) {
3421 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL,
3422 &new_uid, sizeof (new_uid));
3423 zp->z_uid = new_uid;
3425 SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
3426 SA_ZPL_UID(zfsvfs), NULL, &new_uid,
3428 attrzp->z_uid = new_uid;
3432 if (mask & AT_GID) {
3433 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs),
3434 NULL, &new_gid, sizeof (new_gid));
3435 zp->z_gid = new_gid;
3437 SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
3438 SA_ZPL_GID(zfsvfs), NULL, &new_gid,
3440 attrzp->z_gid = new_gid;
3443 if (!(mask & AT_MODE)) {
3444 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs),
3445 NULL, &new_mode, sizeof (new_mode));
3446 new_mode = zp->z_mode;
3448 err = zfs_acl_chown_setattr(zp);
3451 err = zfs_acl_chown_setattr(attrzp);
3456 if (mask & AT_MODE) {
3457 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
3458 &new_mode, sizeof (new_mode));
3459 zp->z_mode = new_mode;
3460 ASSERT3U((uintptr_t)aclp, !=, 0);
3461 err = zfs_aclset_common(zp, aclp, cr, tx);
3463 if (zp->z_acl_cached)
3464 zfs_acl_free(zp->z_acl_cached);
3465 zp->z_acl_cached = aclp;
3470 if (mask & AT_ATIME) {
3471 ZFS_TIME_ENCODE(&vap->va_atime, zp->z_atime);
3472 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
3473 &zp->z_atime, sizeof (zp->z_atime));
3476 if (mask & AT_MTIME) {
3477 ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
3478 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
3479 mtime, sizeof (mtime));
3482 /* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
3483 if (mask & AT_SIZE && !(mask & AT_MTIME)) {
3484 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs),
3485 NULL, mtime, sizeof (mtime));
3486 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
3487 &ctime, sizeof (ctime));
3488 zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
3490 } else if (mask != 0) {
3491 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
3492 &ctime, sizeof (ctime));
3493 zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime, ctime,
3496 SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
3497 SA_ZPL_CTIME(zfsvfs), NULL,
3498 &ctime, sizeof (ctime));
3499 zfs_tstamp_update_setup(attrzp, STATE_CHANGED,
3500 mtime, ctime, B_TRUE);
3504 * Do this after setting timestamps to prevent timestamp
3505 * update from toggling bit
3508 if (xoap && (mask & AT_XVATTR)) {
3511 * restore trimmed off masks
3512 * so that return masks can be set for caller.
3515 if (XVA_ISSET_REQ(&tmpxvattr, XAT_APPENDONLY)) {
3516 XVA_SET_REQ(xvap, XAT_APPENDONLY);
3518 if (XVA_ISSET_REQ(&tmpxvattr, XAT_NOUNLINK)) {
3519 XVA_SET_REQ(xvap, XAT_NOUNLINK);
3521 if (XVA_ISSET_REQ(&tmpxvattr, XAT_IMMUTABLE)) {
3522 XVA_SET_REQ(xvap, XAT_IMMUTABLE);
3524 if (XVA_ISSET_REQ(&tmpxvattr, XAT_NODUMP)) {
3525 XVA_SET_REQ(xvap, XAT_NODUMP);
3527 if (XVA_ISSET_REQ(&tmpxvattr, XAT_AV_MODIFIED)) {
3528 XVA_SET_REQ(xvap, XAT_AV_MODIFIED);
3530 if (XVA_ISSET_REQ(&tmpxvattr, XAT_AV_QUARANTINED)) {
3531 XVA_SET_REQ(xvap, XAT_AV_QUARANTINED);
3534 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
3535 ASSERT(vp->v_type == VREG);
3537 zfs_xvattr_set(zp, xvap, tx);
3541 zfs_fuid_sync(zfsvfs, tx);
3544 zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp);
3546 mutex_exit(&zp->z_lock);
3547 if (mask & (AT_UID|AT_GID|AT_MODE))
3548 mutex_exit(&zp->z_acl_lock);
3551 if (mask & (AT_UID|AT_GID|AT_MODE))
3552 mutex_exit(&attrzp->z_acl_lock);
3553 mutex_exit(&attrzp->z_lock);
3556 if (err == 0 && attrzp) {
3557 err2 = sa_bulk_update(attrzp->z_sa_hdl, xattr_bulk,
3563 VN_RELE(ZTOV(attrzp));
3569 zfs_fuid_info_free(fuidp);
3575 if (err == ERESTART)
3578 err2 = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
3583 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3584 zil_commit(zilog, 0);
3590 typedef struct zfs_zlock {
3591 krwlock_t *zl_rwlock; /* lock we acquired */
3592 znode_t *zl_znode; /* znode we held */
3593 struct zfs_zlock *zl_next; /* next in list */
3597 * Drop locks and release vnodes that were held by zfs_rename_lock().
3600 zfs_rename_unlock(zfs_zlock_t **zlpp)
3604 while ((zl = *zlpp) != NULL) {
3605 if (zl->zl_znode != NULL)
3606 VN_RELE(ZTOV(zl->zl_znode));
3607 rw_exit(zl->zl_rwlock);
3608 *zlpp = zl->zl_next;
3609 kmem_free(zl, sizeof (*zl));
3614 * Search back through the directory tree, using the ".." entries.
3615 * Lock each directory in the chain to prevent concurrent renames.
3616 * Fail any attempt to move a directory into one of its own descendants.
3617 * XXX - z_parent_lock can overlap with map or grow locks
3620 zfs_rename_lock(znode_t *szp, znode_t *tdzp, znode_t *sdzp, zfs_zlock_t **zlpp)
3624 uint64_t rootid = zp->z_zfsvfs->z_root;
3625 uint64_t oidp = zp->z_id;
3626 krwlock_t *rwlp = &szp->z_parent_lock;
3627 krw_t rw = RW_WRITER;
3630 * First pass write-locks szp and compares to zp->z_id.
3631 * Later passes read-lock zp and compare to zp->z_parent.
3634 if (!rw_tryenter(rwlp, rw)) {
3636 * Another thread is renaming in this path.
3637 * Note that if we are a WRITER, we don't have any
3638 * parent_locks held yet.
3640 if (rw == RW_READER && zp->z_id > szp->z_id) {
3642 * Drop our locks and restart
3644 zfs_rename_unlock(&zl);
3648 rwlp = &szp->z_parent_lock;
3653 * Wait for other thread to drop its locks
3659 zl = kmem_alloc(sizeof (*zl), KM_SLEEP);
3660 zl->zl_rwlock = rwlp;
3661 zl->zl_znode = NULL;
3662 zl->zl_next = *zlpp;
3665 if (oidp == szp->z_id) /* We're a descendant of szp */
3666 return (SET_ERROR(EINVAL));
3668 if (oidp == rootid) /* We've hit the top */
3671 if (rw == RW_READER) { /* i.e. not the first pass */
3672 int error = zfs_zget(zp->z_zfsvfs, oidp, &zp);
3677 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(zp->z_zfsvfs),
3678 &oidp, sizeof (oidp));
3679 rwlp = &zp->z_parent_lock;
3682 } while (zp->z_id != sdzp->z_id);
3688 * Move an entry from the provided source directory to the target
3689 * directory. Change the entry name as indicated.
3691 * IN: sdvp - Source directory containing the "old entry".
3692 * snm - Old entry name.
3693 * tdvp - Target directory to contain the "new entry".
3694 * tnm - New entry name.
3695 * cr - credentials of caller.
3696 * ct - caller context
3697 * flags - case flags
3699 * RETURN: 0 on success, error code on failure.
3702 * sdvp,tdvp - ctime|mtime updated
3706 zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr,
3707 caller_context_t *ct, int flags)
3709 znode_t *tdzp, *szp, *tzp;
3710 znode_t *sdzp = VTOZ(sdvp);
3711 zfsvfs_t *zfsvfs = sdzp->z_zfsvfs;
3714 zfs_dirlock_t *sdl, *tdl;
3717 int cmp, serr, terr;
3722 ZFS_VERIFY_ZP(sdzp);
3723 zilog = zfsvfs->z_log;
3726 * Make sure we have the real vp for the target directory.
3728 if (VOP_REALVP(tdvp, &realvp, ct) == 0)
3732 ZFS_VERIFY_ZP(tdzp);
3735 * We check z_zfsvfs rather than v_vfsp here, because snapshots and the
3736 * ctldir appear to have the same v_vfsp.
3738 if (tdzp->z_zfsvfs != zfsvfs || zfsctl_is_node(tdvp)) {
3740 return (SET_ERROR(EXDEV));
3743 if (zfsvfs->z_utf8 && u8_validate(tnm,
3744 strlen(tnm), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3746 return (SET_ERROR(EILSEQ));
3749 if (flags & FIGNORECASE)
3758 * This is to prevent the creation of links into attribute space
3759 * by renaming a linked file into/outof an attribute directory.
3760 * See the comment in zfs_link() for why this is considered bad.
3762 if ((tdzp->z_pflags & ZFS_XATTR) != (sdzp->z_pflags & ZFS_XATTR)) {
3764 return (SET_ERROR(EINVAL));
3768 * Lock source and target directory entries. To prevent deadlock,
3769 * a lock ordering must be defined. We lock the directory with
3770 * the smallest object id first, or if it's a tie, the one with
3771 * the lexically first name.
3773 if (sdzp->z_id < tdzp->z_id) {
3775 } else if (sdzp->z_id > tdzp->z_id) {
3779 * First compare the two name arguments without
3780 * considering any case folding.
3782 int nofold = (zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER);
3784 cmp = u8_strcmp(snm, tnm, 0, nofold, U8_UNICODE_LATEST, &error);
3785 ASSERT(error == 0 || !zfsvfs->z_utf8);
3788 * POSIX: "If the old argument and the new argument
3789 * both refer to links to the same existing file,
3790 * the rename() function shall return successfully
3791 * and perform no other action."
3797 * If the file system is case-folding, then we may
3798 * have some more checking to do. A case-folding file
3799 * system is either supporting mixed case sensitivity
3800 * access or is completely case-insensitive. Note
3801 * that the file system is always case preserving.
3803 * In mixed sensitivity mode case sensitive behavior
3804 * is the default. FIGNORECASE must be used to
3805 * explicitly request case insensitive behavior.
3807 * If the source and target names provided differ only
3808 * by case (e.g., a request to rename 'tim' to 'Tim'),
3809 * we will treat this as a special case in the
3810 * case-insensitive mode: as long as the source name
3811 * is an exact match, we will allow this to proceed as
3812 * a name-change request.
3814 if ((zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
3815 (zfsvfs->z_case == ZFS_CASE_MIXED &&
3816 flags & FIGNORECASE)) &&
3817 u8_strcmp(snm, tnm, 0, zfsvfs->z_norm, U8_UNICODE_LATEST,
3820 * case preserving rename request, require exact
3829 * If the source and destination directories are the same, we should
3830 * grab the z_name_lock of that directory only once.
3834 rw_enter(&sdzp->z_name_lock, RW_READER);
3838 serr = zfs_dirent_lock(&sdl, sdzp, snm, &szp,
3839 ZEXISTS | zflg, NULL, NULL);
3840 terr = zfs_dirent_lock(&tdl,
3841 tdzp, tnm, &tzp, ZRENAMING | zflg, NULL, NULL);
3843 terr = zfs_dirent_lock(&tdl,
3844 tdzp, tnm, &tzp, zflg, NULL, NULL);
3845 serr = zfs_dirent_lock(&sdl,
3846 sdzp, snm, &szp, ZEXISTS | ZRENAMING | zflg,
3852 * Source entry invalid or not there.
3855 zfs_dirent_unlock(tdl);
3861 rw_exit(&sdzp->z_name_lock);
3864 * FreeBSD: In OpenSolaris they only check if rename source is
3865 * ".." here, because "." is handled in their lookup. This is
3866 * not the case for FreeBSD, so we check for "." explicitly.
3868 if (strcmp(snm, ".") == 0 || strcmp(snm, "..") == 0)
3869 serr = SET_ERROR(EINVAL);
3874 zfs_dirent_unlock(sdl);
3878 rw_exit(&sdzp->z_name_lock);
3880 if (strcmp(tnm, "..") == 0)
3881 terr = SET_ERROR(EINVAL);
3887 * Must have write access at the source to remove the old entry
3888 * and write access at the target to create the new entry.
3889 * Note that if target and source are the same, this can be
3890 * done in a single check.
3893 if (error = zfs_zaccess_rename(sdzp, szp, tdzp, tzp, cr))
3896 if (ZTOV(szp)->v_type == VDIR) {
3898 * Check to make sure rename is valid.
3899 * Can't do a move like this: /usr/a/b to /usr/a/b/c/d
3901 if (error = zfs_rename_lock(szp, tdzp, sdzp, &zl))
3906 * Does target exist?
3910 * Source and target must be the same type.
3912 if (ZTOV(szp)->v_type == VDIR) {
3913 if (ZTOV(tzp)->v_type != VDIR) {
3914 error = SET_ERROR(ENOTDIR);
3918 if (ZTOV(tzp)->v_type == VDIR) {
3919 error = SET_ERROR(EISDIR);
3924 * POSIX dictates that when the source and target
3925 * entries refer to the same file object, rename
3926 * must do nothing and exit without error.
3928 if (szp->z_id == tzp->z_id) {
3934 vnevent_rename_src(ZTOV(szp), sdvp, snm, ct);
3936 vnevent_rename_dest(ZTOV(tzp), tdvp, tnm, ct);
3939 * notify the target directory if it is not the same
3940 * as source directory.
3943 vnevent_rename_dest_dir(tdvp, ct);
3946 tx = dmu_tx_create(zfsvfs->z_os);
3947 dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
3948 dmu_tx_hold_sa(tx, sdzp->z_sa_hdl, B_FALSE);
3949 dmu_tx_hold_zap(tx, sdzp->z_id, FALSE, snm);
3950 dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, tnm);
3952 dmu_tx_hold_sa(tx, tdzp->z_sa_hdl, B_FALSE);
3953 zfs_sa_upgrade_txholds(tx, tdzp);
3956 dmu_tx_hold_sa(tx, tzp->z_sa_hdl, B_FALSE);
3957 zfs_sa_upgrade_txholds(tx, tzp);
3960 zfs_sa_upgrade_txholds(tx, szp);
3961 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
3962 error = dmu_tx_assign(tx, TXG_NOWAIT);
3965 zfs_rename_unlock(&zl);
3966 zfs_dirent_unlock(sdl);
3967 zfs_dirent_unlock(tdl);
3970 rw_exit(&sdzp->z_name_lock);
3975 if (error == ERESTART) {
3985 if (tzp) /* Attempt to remove the existing target */
3986 error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL);
3989 error = zfs_link_create(tdl, szp, tx, ZRENAMING);
3991 szp->z_pflags |= ZFS_AV_MODIFIED;
3993 error = sa_update(szp->z_sa_hdl, SA_ZPL_FLAGS(zfsvfs),
3994 (void *)&szp->z_pflags, sizeof (uint64_t), tx);
3997 error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL);
3999 zfs_log_rename(zilog, tx, TX_RENAME |
4000 (flags & FIGNORECASE ? TX_CI : 0), sdzp,
4001 sdl->dl_name, tdzp, tdl->dl_name, szp);
4004 * Update path information for the target vnode
4006 vn_renamepath(tdvp, ZTOV(szp), tnm,
4010 * At this point, we have successfully created
4011 * the target name, but have failed to remove
4012 * the source name. Since the create was done
4013 * with the ZRENAMING flag, there are
4014 * complications; for one, the link count is
4015 * wrong. The easiest way to deal with this
4016 * is to remove the newly created target, and
4017 * return the original error. This must
4018 * succeed; fortunately, it is very unlikely to
4019 * fail, since we just created it.
4021 VERIFY3U(zfs_link_destroy(tdl, szp, tx,
4022 ZRENAMING, NULL), ==, 0);
4025 #ifdef FREEBSD_NAMECACHE
4029 cache_purge(ZTOV(szp));
4031 cache_purge(ZTOV(tzp));
4039 zfs_rename_unlock(&zl);
4041 zfs_dirent_unlock(sdl);
4042 zfs_dirent_unlock(tdl);
4045 rw_exit(&sdzp->z_name_lock);
4052 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
4053 zil_commit(zilog, 0);
4061 * Insert the indicated symbolic reference entry into the directory.
4063 * IN: dvp - Directory to contain new symbolic link.
4064 * link - Name for new symlink entry.
4065 * vap - Attributes of new entry.
4066 * cr - credentials of caller.
4067 * ct - caller context
4068 * flags - case flags
4070 * RETURN: 0 on success, error code on failure.
4073 * dvp - ctime|mtime updated
4077 zfs_symlink(vnode_t *dvp, vnode_t **vpp, char *name, vattr_t *vap, char *link,
4078 cred_t *cr, kthread_t *td)
4080 znode_t *zp, *dzp = VTOZ(dvp);
4083 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
4085 uint64_t len = strlen(link);
4088 zfs_acl_ids_t acl_ids;
4089 boolean_t fuid_dirtied;
4090 uint64_t txtype = TX_SYMLINK;
4093 ASSERT(vap->va_type == VLNK);
4097 zilog = zfsvfs->z_log;
4099 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
4100 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
4102 return (SET_ERROR(EILSEQ));
4104 if (flags & FIGNORECASE)
4107 if (len > MAXPATHLEN) {
4109 return (SET_ERROR(ENAMETOOLONG));
4112 if ((error = zfs_acl_ids_create(dzp, 0,
4113 vap, cr, NULL, &acl_ids)) != 0) {
4119 * Attempt to lock directory; fail if entry already exists.
4121 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, NULL, NULL);
4123 zfs_acl_ids_free(&acl_ids);
4128 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
4129 zfs_acl_ids_free(&acl_ids);
4130 zfs_dirent_unlock(dl);
4135 if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
4136 zfs_acl_ids_free(&acl_ids);
4137 zfs_dirent_unlock(dl);
4139 return (SET_ERROR(EDQUOT));
4141 tx = dmu_tx_create(zfsvfs->z_os);
4142 fuid_dirtied = zfsvfs->z_fuid_dirty;
4143 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, MAX(1, len));
4144 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
4145 dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
4146 ZFS_SA_BASE_ATTR_SIZE + len);
4147 dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
4148 if (!zfsvfs->z_use_sa && acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
4149 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
4150 acl_ids.z_aclp->z_acl_bytes);
4153 zfs_fuid_txhold(zfsvfs, tx);
4154 error = dmu_tx_assign(tx, TXG_NOWAIT);
4156 zfs_dirent_unlock(dl);
4157 if (error == ERESTART) {
4162 zfs_acl_ids_free(&acl_ids);
4169 * Create a new object for the symlink.
4170 * for version 4 ZPL datsets the symlink will be an SA attribute
4172 zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
4175 zfs_fuid_sync(zfsvfs, tx);
4177 mutex_enter(&zp->z_lock);
4179 error = sa_update(zp->z_sa_hdl, SA_ZPL_SYMLINK(zfsvfs),
4182 zfs_sa_symlink(zp, link, len, tx);
4183 mutex_exit(&zp->z_lock);
4186 (void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zfsvfs),
4187 &zp->z_size, sizeof (zp->z_size), tx);
4189 * Insert the new object into the directory.
4191 (void) zfs_link_create(dl, zp, tx, ZNEW);
4193 if (flags & FIGNORECASE)
4195 zfs_log_symlink(zilog, tx, txtype, dzp, zp, name, link);
4198 zfs_acl_ids_free(&acl_ids);
4202 zfs_dirent_unlock(dl);
4204 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
4205 zil_commit(zilog, 0);
4212 * Return, in the buffer contained in the provided uio structure,
4213 * the symbolic path referred to by vp.
4215 * IN: vp - vnode of symbolic link.
4216 * uio - structure to contain the link path.
4217 * cr - credentials of caller.
4218 * ct - caller context
4220 * OUT: uio - structure containing the link path.
4222 * RETURN: 0 on success, error code on failure.
4225 * vp - atime updated
4229 zfs_readlink(vnode_t *vp, uio_t *uio, cred_t *cr, caller_context_t *ct)
4231 znode_t *zp = VTOZ(vp);
4232 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4238 mutex_enter(&zp->z_lock);
4240 error = sa_lookup_uio(zp->z_sa_hdl,
4241 SA_ZPL_SYMLINK(zfsvfs), uio);
4243 error = zfs_sa_readlink(zp, uio);
4244 mutex_exit(&zp->z_lock);
4246 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
4253 * Insert a new entry into directory tdvp referencing svp.
4255 * IN: tdvp - Directory to contain new entry.
4256 * svp - vnode of new entry.
4257 * name - name of new entry.
4258 * cr - credentials of caller.
4259 * ct - caller context
4261 * RETURN: 0 on success, error code on failure.
4264 * tdvp - ctime|mtime updated
4265 * svp - ctime updated
4269 zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr,
4270 caller_context_t *ct, int flags)
4272 znode_t *dzp = VTOZ(tdvp);
4274 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
4284 ASSERT(tdvp->v_type == VDIR);
4288 zilog = zfsvfs->z_log;
4290 if (VOP_REALVP(svp, &realvp, ct) == 0)
4294 * POSIX dictates that we return EPERM here.
4295 * Better choices include ENOTSUP or EISDIR.
4297 if (svp->v_type == VDIR) {
4299 return (SET_ERROR(EPERM));
4306 * We check z_zfsvfs rather than v_vfsp here, because snapshots and the
4307 * ctldir appear to have the same v_vfsp.
4309 if (szp->z_zfsvfs != zfsvfs || zfsctl_is_node(svp)) {
4311 return (SET_ERROR(EXDEV));
4314 /* Prevent links to .zfs/shares files */
4316 if ((error = sa_lookup(szp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs),
4317 &parent, sizeof (uint64_t))) != 0) {
4321 if (parent == zfsvfs->z_shares_dir) {
4323 return (SET_ERROR(EPERM));
4326 if (zfsvfs->z_utf8 && u8_validate(name,
4327 strlen(name), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
4329 return (SET_ERROR(EILSEQ));
4331 if (flags & FIGNORECASE)
4335 * We do not support links between attributes and non-attributes
4336 * because of the potential security risk of creating links
4337 * into "normal" file space in order to circumvent restrictions
4338 * imposed in attribute space.
4340 if ((szp->z_pflags & ZFS_XATTR) != (dzp->z_pflags & ZFS_XATTR)) {
4342 return (SET_ERROR(EINVAL));
4346 owner = zfs_fuid_map_id(zfsvfs, szp->z_uid, cr, ZFS_OWNER);
4347 if (owner != crgetuid(cr) && secpolicy_basic_link(svp, cr) != 0) {
4349 return (SET_ERROR(EPERM));
4352 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
4359 * Attempt to lock directory; fail if entry already exists.
4361 error = zfs_dirent_lock(&dl, dzp, name, &tzp, zf, NULL, NULL);
4367 tx = dmu_tx_create(zfsvfs->z_os);
4368 dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
4369 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
4370 zfs_sa_upgrade_txholds(tx, szp);
4371 zfs_sa_upgrade_txholds(tx, dzp);
4372 error = dmu_tx_assign(tx, TXG_NOWAIT);
4374 zfs_dirent_unlock(dl);
4375 if (error == ERESTART) {
4385 error = zfs_link_create(dl, szp, tx, 0);
4388 uint64_t txtype = TX_LINK;
4389 if (flags & FIGNORECASE)
4391 zfs_log_link(zilog, tx, txtype, dzp, szp, name);
4396 zfs_dirent_unlock(dl);
4399 vnevent_link(svp, ct);
4402 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
4403 zil_commit(zilog, 0);
4411 * zfs_null_putapage() is used when the file system has been force
4412 * unmounted. It just drops the pages.
4416 zfs_null_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
4417 size_t *lenp, int flags, cred_t *cr)
4419 pvn_write_done(pp, B_INVAL|B_FORCE|B_ERROR);
4424 * Push a page out to disk, klustering if possible.
4426 * IN: vp - file to push page to.
4427 * pp - page to push.
4428 * flags - additional flags.
4429 * cr - credentials of caller.
4431 * OUT: offp - start of range pushed.
4432 * lenp - len of range pushed.
4434 * RETURN: 0 on success, error code on failure.
4436 * NOTE: callers must have locked the page to be pushed. On
4437 * exit, the page (and all other pages in the kluster) must be
4442 zfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
4443 size_t *lenp, int flags, cred_t *cr)
4445 znode_t *zp = VTOZ(vp);
4446 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4448 u_offset_t off, koff;
4455 * If our blocksize is bigger than the page size, try to kluster
4456 * multiple pages so that we write a full block (thus avoiding
4457 * a read-modify-write).
4459 if (off < zp->z_size && zp->z_blksz > PAGESIZE) {
4460 klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE);
4461 koff = ISP2(klen) ? P2ALIGN(off, (u_offset_t)klen) : 0;
4462 ASSERT(koff <= zp->z_size);
4463 if (koff + klen > zp->z_size)
4464 klen = P2ROUNDUP(zp->z_size - koff, (uint64_t)PAGESIZE);
4465 pp = pvn_write_kluster(vp, pp, &off, &len, koff, klen, flags);
4467 ASSERT3U(btop(len), ==, btopr(len));
4470 * Can't push pages past end-of-file.
4472 if (off >= zp->z_size) {
4473 /* ignore all pages */
4476 } else if (off + len > zp->z_size) {
4477 int npages = btopr(zp->z_size - off);
4480 page_list_break(&pp, &trunc, npages);
4481 /* ignore pages past end of file */
4483 pvn_write_done(trunc, flags);
4484 len = zp->z_size - off;
4487 if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
4488 zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
4489 err = SET_ERROR(EDQUOT);
4493 tx = dmu_tx_create(zfsvfs->z_os);
4494 dmu_tx_hold_write(tx, zp->z_id, off, len);
4496 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
4497 zfs_sa_upgrade_txholds(tx, zp);
4498 err = dmu_tx_assign(tx, TXG_NOWAIT);
4500 if (err == ERESTART) {
4509 if (zp->z_blksz <= PAGESIZE) {
4510 caddr_t va = zfs_map_page(pp, S_READ);
4511 ASSERT3U(len, <=, PAGESIZE);
4512 dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx);
4513 zfs_unmap_page(pp, va);
4515 err = dmu_write_pages(zfsvfs->z_os, zp->z_id, off, len, pp, tx);
4519 uint64_t mtime[2], ctime[2];
4520 sa_bulk_attr_t bulk[3];
4523 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
4525 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
4527 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
4529 zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
4531 zfs_log_write(zfsvfs->z_log, tx, TX_WRITE, zp, off, len, 0);
4536 pvn_write_done(pp, (err ? B_ERROR : 0) | flags);
4546 * Copy the portion of the file indicated from pages into the file.
4547 * The pages are stored in a page list attached to the files vnode.
4549 * IN: vp - vnode of file to push page data to.
4550 * off - position in file to put data.
4551 * len - amount of data to write.
4552 * flags - flags to control the operation.
4553 * cr - credentials of caller.
4554 * ct - caller context.
4556 * RETURN: 0 on success, error code on failure.
4559 * vp - ctime|mtime updated
4563 zfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
4564 caller_context_t *ct)
4566 znode_t *zp = VTOZ(vp);
4567 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4579 * Align this request to the file block size in case we kluster.
4580 * XXX - this can result in pretty aggresive locking, which can
4581 * impact simultanious read/write access. One option might be
4582 * to break up long requests (len == 0) into block-by-block
4583 * operations to get narrower locking.
4585 blksz = zp->z_blksz;
4587 io_off = P2ALIGN_TYPED(off, blksz, u_offset_t);
4590 if (len > 0 && ISP2(blksz))
4591 io_len = P2ROUNDUP_TYPED(len + (off - io_off), blksz, size_t);
4597 * Search the entire vp list for pages >= io_off.
4599 rl = zfs_range_lock(zp, io_off, UINT64_MAX, RL_WRITER);
4600 error = pvn_vplist_dirty(vp, io_off, zfs_putapage, flags, cr);
4603 rl = zfs_range_lock(zp, io_off, io_len, RL_WRITER);
4605 if (off > zp->z_size) {
4606 /* past end of file */
4607 zfs_range_unlock(rl);
4612 len = MIN(io_len, P2ROUNDUP(zp->z_size, PAGESIZE) - io_off);
4614 for (off = io_off; io_off < off + len; io_off += io_len) {
4615 if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) {
4616 pp = page_lookup(vp, io_off,
4617 (flags & (B_INVAL | B_FREE)) ? SE_EXCL : SE_SHARED);
4619 pp = page_lookup_nowait(vp, io_off,
4620 (flags & B_FREE) ? SE_EXCL : SE_SHARED);
4623 if (pp != NULL && pvn_getdirty(pp, flags)) {
4627 * Found a dirty page to push
4629 err = zfs_putapage(vp, pp, &io_off, &io_len, flags, cr);
4637 zfs_range_unlock(rl);
4638 if ((flags & B_ASYNC) == 0 || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
4639 zil_commit(zfsvfs->z_log, zp->z_id);
4647 zfs_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
4649 znode_t *zp = VTOZ(vp);
4650 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4653 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER);
4654 if (zp->z_sa_hdl == NULL) {
4656 * The fs has been unmounted, or we did a
4657 * suspend/resume and this file no longer exists.
4659 rw_exit(&zfsvfs->z_teardown_inactive_lock);
4664 mutex_enter(&zp->z_lock);
4665 if (zp->z_unlinked) {
4667 * Fast path to recycle a vnode of a removed file.
4669 mutex_exit(&zp->z_lock);
4670 rw_exit(&zfsvfs->z_teardown_inactive_lock);
4674 mutex_exit(&zp->z_lock);
4676 if (zp->z_atime_dirty && zp->z_unlinked == 0) {
4677 dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
4679 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
4680 zfs_sa_upgrade_txholds(tx, zp);
4681 error = dmu_tx_assign(tx, TXG_WAIT);
4685 mutex_enter(&zp->z_lock);
4686 (void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs),
4687 (void *)&zp->z_atime, sizeof (zp->z_atime), tx);
4688 zp->z_atime_dirty = 0;
4689 mutex_exit(&zp->z_lock);
4693 rw_exit(&zfsvfs->z_teardown_inactive_lock);
4698 * Bounds-check the seek operation.
4700 * IN: vp - vnode seeking within
4701 * ooff - old file offset
4702 * noffp - pointer to new file offset
4703 * ct - caller context
4705 * RETURN: 0 on success, EINVAL if new offset invalid.
4709 zfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp,
4710 caller_context_t *ct)
4712 if (vp->v_type == VDIR)
4714 return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
4718 * Pre-filter the generic locking function to trap attempts to place
4719 * a mandatory lock on a memory mapped file.
4722 zfs_frlock(vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset,
4723 flk_callback_t *flk_cbp, cred_t *cr, caller_context_t *ct)
4725 znode_t *zp = VTOZ(vp);
4726 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4732 * We are following the UFS semantics with respect to mapcnt
4733 * here: If we see that the file is mapped already, then we will
4734 * return an error, but we don't worry about races between this
4735 * function and zfs_map().
4737 if (zp->z_mapcnt > 0 && MANDMODE(zp->z_mode)) {
4739 return (SET_ERROR(EAGAIN));
4742 return (fs_frlock(vp, cmd, bfp, flag, offset, flk_cbp, cr, ct));
4746 * If we can't find a page in the cache, we will create a new page
4747 * and fill it with file data. For efficiency, we may try to fill
4748 * multiple pages at once (klustering) to fill up the supplied page
4749 * list. Note that the pages to be filled are held with an exclusive
4750 * lock to prevent access by other threads while they are being filled.
4753 zfs_fillpage(vnode_t *vp, u_offset_t off, struct seg *seg,
4754 caddr_t addr, page_t *pl[], size_t plsz, enum seg_rw rw)
4756 znode_t *zp = VTOZ(vp);
4757 page_t *pp, *cur_pp;
4758 objset_t *os = zp->z_zfsvfs->z_os;
4759 u_offset_t io_off, total;
4763 if (plsz == PAGESIZE || zp->z_blksz <= PAGESIZE) {
4765 * We only have a single page, don't bother klustering
4769 pp = page_create_va(vp, io_off, io_len,
4770 PG_EXCL | PG_WAIT, seg, addr);
4773 * Try to find enough pages to fill the page list
4775 pp = pvn_read_kluster(vp, off, seg, addr, &io_off,
4776 &io_len, off, plsz, 0);
4780 * The page already exists, nothing to do here.
4787 * Fill the pages in the kluster.
4790 for (total = io_off + io_len; io_off < total; io_off += PAGESIZE) {
4793 ASSERT3U(io_off, ==, cur_pp->p_offset);
4794 va = zfs_map_page(cur_pp, S_WRITE);
4795 err = dmu_read(os, zp->z_id, io_off, PAGESIZE, va,
4797 zfs_unmap_page(cur_pp, va);
4799 /* On error, toss the entire kluster */
4800 pvn_read_done(pp, B_ERROR);
4801 /* convert checksum errors into IO errors */
4803 err = SET_ERROR(EIO);
4806 cur_pp = cur_pp->p_next;
4810 * Fill in the page list array from the kluster starting
4811 * from the desired offset `off'.
4812 * NOTE: the page list will always be null terminated.
4814 pvn_plist_init(pp, pl, plsz, off, io_len, rw);
4815 ASSERT(pl == NULL || (*pl)->p_offset == off);
4821 * Return pointers to the pages for the file region [off, off + len]
4822 * in the pl array. If plsz is greater than len, this function may
4823 * also return page pointers from after the specified region
4824 * (i.e. the region [off, off + plsz]). These additional pages are
4825 * only returned if they are already in the cache, or were created as
4826 * part of a klustered read.
4828 * IN: vp - vnode of file to get data from.
4829 * off - position in file to get data from.
4830 * len - amount of data to retrieve.
4831 * plsz - length of provided page list.
4832 * seg - segment to obtain pages for.
4833 * addr - virtual address of fault.
4834 * rw - mode of created pages.
4835 * cr - credentials of caller.
4836 * ct - caller context.
4838 * OUT: protp - protection mode of created pages.
4839 * pl - list of pages created.
4841 * RETURN: 0 on success, error code on failure.
4844 * vp - atime updated
4848 zfs_getpage(vnode_t *vp, offset_t off, size_t len, uint_t *protp,
4849 page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
4850 enum seg_rw rw, cred_t *cr, caller_context_t *ct)
4852 znode_t *zp = VTOZ(vp);
4853 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4857 /* we do our own caching, faultahead is unnecessary */
4860 else if (len > plsz)
4863 len = P2ROUNDUP(len, PAGESIZE);
4864 ASSERT(plsz >= len);
4873 * Loop through the requested range [off, off + len) looking
4874 * for pages. If we don't find a page, we will need to create
4875 * a new page and fill it with data from the file.
4878 if (*pl = page_lookup(vp, off, SE_SHARED))
4880 else if (err = zfs_fillpage(vp, off, seg, addr, pl, plsz, rw))
4883 ASSERT3U((*pl)->p_offset, ==, off);
4887 ASSERT3U(len, >=, PAGESIZE);
4890 ASSERT3U(plsz, >=, PAGESIZE);
4897 * Fill out the page array with any pages already in the cache.
4900 (*pl++ = page_lookup_nowait(vp, off, SE_SHARED))) {
4907 * Release any pages we have previously locked.
4912 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
4922 * Request a memory map for a section of a file. This code interacts
4923 * with common code and the VM system as follows:
4925 * - common code calls mmap(), which ends up in smmap_common()
4926 * - this calls VOP_MAP(), which takes you into (say) zfs
4927 * - zfs_map() calls as_map(), passing segvn_create() as the callback
4928 * - segvn_create() creates the new segment and calls VOP_ADDMAP()
4929 * - zfs_addmap() updates z_mapcnt
4933 zfs_map(vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp,
4934 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4935 caller_context_t *ct)
4937 znode_t *zp = VTOZ(vp);
4938 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4939 segvn_crargs_t vn_a;
4945 if ((prot & PROT_WRITE) && (zp->z_pflags &
4946 (ZFS_IMMUTABLE | ZFS_READONLY | ZFS_APPENDONLY))) {
4948 return (SET_ERROR(EPERM));
4951 if ((prot & (PROT_READ | PROT_EXEC)) &&
4952 (zp->z_pflags & ZFS_AV_QUARANTINED)) {
4954 return (SET_ERROR(EACCES));
4957 if (vp->v_flag & VNOMAP) {
4959 return (SET_ERROR(ENOSYS));
4962 if (off < 0 || len > MAXOFFSET_T - off) {
4964 return (SET_ERROR(ENXIO));
4967 if (vp->v_type != VREG) {
4969 return (SET_ERROR(ENODEV));
4973 * If file is locked, disallow mapping.
4975 if (MANDMODE(zp->z_mode) && vn_has_flocks(vp)) {
4977 return (SET_ERROR(EAGAIN));
4981 error = choose_addr(as, addrp, len, off, ADDR_VACALIGN, flags);
4989 vn_a.offset = (u_offset_t)off;
4990 vn_a.type = flags & MAP_TYPE;
4992 vn_a.maxprot = maxprot;
4995 vn_a.flags = flags & ~MAP_TYPE;
4997 vn_a.lgrp_mem_policy_flags = 0;
4999 error = as_map(as, *addrp, len, segvn_create, &vn_a);
5008 zfs_addmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
5009 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
5010 caller_context_t *ct)
5012 uint64_t pages = btopr(len);
5014 atomic_add_64(&VTOZ(vp)->z_mapcnt, pages);
5019 * The reason we push dirty pages as part of zfs_delmap() is so that we get a
5020 * more accurate mtime for the associated file. Since we don't have a way of
5021 * detecting when the data was actually modified, we have to resort to
5022 * heuristics. If an explicit msync() is done, then we mark the mtime when the
5023 * last page is pushed. The problem occurs when the msync() call is omitted,
5024 * which by far the most common case:
5032 * putpage() via fsflush
5034 * If we wait until fsflush to come along, we can have a modification time that
5035 * is some arbitrary point in the future. In order to prevent this in the
5036 * common case, we flush pages whenever a (MAP_SHARED, PROT_WRITE) mapping is
5041 zfs_delmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
5042 size_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cr,
5043 caller_context_t *ct)
5045 uint64_t pages = btopr(len);
5047 ASSERT3U(VTOZ(vp)->z_mapcnt, >=, pages);
5048 atomic_add_64(&VTOZ(vp)->z_mapcnt, -pages);
5050 if ((flags & MAP_SHARED) && (prot & PROT_WRITE) &&
5051 vn_has_cached_data(vp))
5052 (void) VOP_PUTPAGE(vp, off, len, B_ASYNC, cr, ct);
5058 * Free or allocate space in a file. Currently, this function only
5059 * supports the `F_FREESP' command. However, this command is somewhat
5060 * misnamed, as its functionality includes the ability to allocate as
5061 * well as free space.
5063 * IN: vp - vnode of file to free data in.
5064 * cmd - action to take (only F_FREESP supported).
5065 * bfp - section of file to free/alloc.
5066 * flag - current file open mode flags.
5067 * offset - current file offset.
5068 * cr - credentials of caller [UNUSED].
5069 * ct - caller context.
5071 * RETURN: 0 on success, error code on failure.
5074 * vp - ctime|mtime updated
5078 zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag,
5079 offset_t offset, cred_t *cr, caller_context_t *ct)
5081 znode_t *zp = VTOZ(vp);
5082 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
5089 if (cmd != F_FREESP) {
5091 return (SET_ERROR(EINVAL));
5094 if (error = convoff(vp, bfp, 0, offset)) {
5099 if (bfp->l_len < 0) {
5101 return (SET_ERROR(EINVAL));
5105 len = bfp->l_len; /* 0 means from off to end of file */
5107 error = zfs_freesp(zp, off, len, flag, TRUE);
5114 CTASSERT(sizeof(struct zfid_short) <= sizeof(struct fid));
5115 CTASSERT(sizeof(struct zfid_long) <= sizeof(struct fid));
5119 zfs_fid(vnode_t *vp, fid_t *fidp, caller_context_t *ct)
5121 znode_t *zp = VTOZ(vp);
5122 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
5125 uint64_t object = zp->z_id;
5132 if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs),
5133 &gen64, sizeof (uint64_t))) != 0) {
5138 gen = (uint32_t)gen64;
5140 size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN;
5143 if (fidp->fid_len < size) {
5144 fidp->fid_len = size;
5146 return (SET_ERROR(ENOSPC));
5149 fidp->fid_len = size;
5152 zfid = (zfid_short_t *)fidp;
5154 zfid->zf_len = size;
5156 for (i = 0; i < sizeof (zfid->zf_object); i++)
5157 zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
5159 /* Must have a non-zero generation number to distinguish from .zfs */
5162 for (i = 0; i < sizeof (zfid->zf_gen); i++)
5163 zfid->zf_gen[i] = (uint8_t)(gen >> (8 * i));
5165 if (size == LONG_FID_LEN) {
5166 uint64_t objsetid = dmu_objset_id(zfsvfs->z_os);
5169 zlfid = (zfid_long_t *)fidp;
5171 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
5172 zlfid->zf_setid[i] = (uint8_t)(objsetid >> (8 * i));
5174 /* XXX - this should be the generation number for the objset */
5175 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
5176 zlfid->zf_setgen[i] = 0;
5184 zfs_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr,
5185 caller_context_t *ct)
5197 case _PC_FILESIZEBITS:
5201 case _PC_XATTR_EXISTS:
5203 zfsvfs = zp->z_zfsvfs;
5207 error = zfs_dirent_lock(&dl, zp, "", &xzp,
5208 ZXATTR | ZEXISTS | ZSHARED, NULL, NULL);
5210 zfs_dirent_unlock(dl);
5211 if (!zfs_dirempty(xzp))
5214 } else if (error == ENOENT) {
5216 * If there aren't extended attributes, it's the
5217 * same as having zero of them.
5224 case _PC_SATTR_ENABLED:
5225 case _PC_SATTR_EXISTS:
5226 *valp = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
5227 (vp->v_type == VREG || vp->v_type == VDIR);
5230 case _PC_ACCESS_FILTERING:
5231 *valp = vfs_has_feature(vp->v_vfsp, VFSFT_ACCESS_FILTER) &&
5235 case _PC_ACL_ENABLED:
5236 *valp = _ACL_ACE_ENABLED;
5239 case _PC_MIN_HOLE_SIZE:
5240 *valp = (int)SPA_MINBLOCKSIZE;
5243 case _PC_TIMESTAMP_RESOLUTION:
5244 /* nanosecond timestamp resolution */
5248 case _PC_ACL_EXTENDED:
5256 case _PC_ACL_PATH_MAX:
5257 *valp = ACL_MAX_ENTRIES;
5261 return (EOPNOTSUPP);
5267 zfs_getsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
5268 caller_context_t *ct)
5270 znode_t *zp = VTOZ(vp);
5271 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
5273 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
5277 error = zfs_getacl(zp, vsecp, skipaclchk, cr);
5285 zfs_setsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
5286 caller_context_t *ct)
5288 znode_t *zp = VTOZ(vp);
5289 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
5291 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
5292 zilog_t *zilog = zfsvfs->z_log;
5297 error = zfs_setacl(zp, vsecp, skipaclchk, cr);
5299 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
5300 zil_commit(zilog, 0);
5308 * The smallest read we may consider to loan out an arcbuf.
5309 * This must be a power of 2.
5311 int zcr_blksz_min = (1 << 10); /* 1K */
5313 * If set to less than the file block size, allow loaning out of an
5314 * arcbuf for a partial block read. This must be a power of 2.
5316 int zcr_blksz_max = (1 << 17); /* 128K */
5320 zfs_reqzcbuf(vnode_t *vp, enum uio_rw ioflag, xuio_t *xuio, cred_t *cr,
5321 caller_context_t *ct)
5323 znode_t *zp = VTOZ(vp);
5324 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
5325 int max_blksz = zfsvfs->z_max_blksz;
5326 uio_t *uio = &xuio->xu_uio;
5327 ssize_t size = uio->uio_resid;
5328 offset_t offset = uio->uio_loffset;
5333 int preamble, postamble;
5335 if (xuio->xu_type != UIOTYPE_ZEROCOPY)
5336 return (SET_ERROR(EINVAL));
5343 * Loan out an arc_buf for write if write size is bigger than
5344 * max_blksz, and the file's block size is also max_blksz.
5347 if (size < blksz || zp->z_blksz != blksz) {
5349 return (SET_ERROR(EINVAL));
5352 * Caller requests buffers for write before knowing where the
5353 * write offset might be (e.g. NFS TCP write).
5358 preamble = P2PHASE(offset, blksz);
5360 preamble = blksz - preamble;
5365 postamble = P2PHASE(size, blksz);
5368 fullblk = size / blksz;
5369 (void) dmu_xuio_init(xuio,
5370 (preamble != 0) + fullblk + (postamble != 0));
5371 DTRACE_PROBE3(zfs_reqzcbuf_align, int, preamble,
5372 int, postamble, int,
5373 (preamble != 0) + fullblk + (postamble != 0));
5376 * Have to fix iov base/len for partial buffers. They
5377 * currently represent full arc_buf's.
5380 /* data begins in the middle of the arc_buf */
5381 abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
5384 (void) dmu_xuio_add(xuio, abuf,
5385 blksz - preamble, preamble);
5388 for (i = 0; i < fullblk; i++) {
5389 abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
5392 (void) dmu_xuio_add(xuio, abuf, 0, blksz);
5396 /* data ends in the middle of the arc_buf */
5397 abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
5400 (void) dmu_xuio_add(xuio, abuf, 0, postamble);
5405 * Loan out an arc_buf for read if the read size is larger than
5406 * the current file block size. Block alignment is not
5407 * considered. Partial arc_buf will be loaned out for read.
5409 blksz = zp->z_blksz;
5410 if (blksz < zcr_blksz_min)
5411 blksz = zcr_blksz_min;
5412 if (blksz > zcr_blksz_max)
5413 blksz = zcr_blksz_max;
5414 /* avoid potential complexity of dealing with it */
5415 if (blksz > max_blksz) {
5417 return (SET_ERROR(EINVAL));
5420 maxsize = zp->z_size - uio->uio_loffset;
5424 if (size < blksz || vn_has_cached_data(vp)) {
5426 return (SET_ERROR(EINVAL));
5431 return (SET_ERROR(EINVAL));
5434 uio->uio_extflg = UIO_XUIO;
5435 XUIO_XUZC_RW(xuio) = ioflag;
5442 zfs_retzcbuf(vnode_t *vp, xuio_t *xuio, cred_t *cr, caller_context_t *ct)
5446 int ioflag = XUIO_XUZC_RW(xuio);
5448 ASSERT(xuio->xu_type == UIOTYPE_ZEROCOPY);
5450 i = dmu_xuio_cnt(xuio);
5452 abuf = dmu_xuio_arcbuf(xuio, i);
5454 * if abuf == NULL, it must be a write buffer
5455 * that has been returned in zfs_write().
5458 dmu_return_arcbuf(abuf);
5459 ASSERT(abuf || ioflag == UIO_WRITE);
5462 dmu_xuio_fini(xuio);
5467 * Predeclare these here so that the compiler assumes that
5468 * this is an "old style" function declaration that does
5469 * not include arguments => we won't get type mismatch errors
5470 * in the initializations that follow.
5472 static int zfs_inval();
5473 static int zfs_isdir();
5478 return (SET_ERROR(EINVAL));
5484 return (SET_ERROR(EISDIR));
5487 * Directory vnode operations template
5489 vnodeops_t *zfs_dvnodeops;
5490 const fs_operation_def_t zfs_dvnodeops_template[] = {
5491 VOPNAME_OPEN, { .vop_open = zfs_open },
5492 VOPNAME_CLOSE, { .vop_close = zfs_close },
5493 VOPNAME_READ, { .error = zfs_isdir },
5494 VOPNAME_WRITE, { .error = zfs_isdir },
5495 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
5496 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5497 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5498 VOPNAME_ACCESS, { .vop_access = zfs_access },
5499 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
5500 VOPNAME_CREATE, { .vop_create = zfs_create },
5501 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
5502 VOPNAME_LINK, { .vop_link = zfs_link },
5503 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5504 VOPNAME_MKDIR, { .vop_mkdir = zfs_mkdir },
5505 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
5506 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
5507 VOPNAME_SYMLINK, { .vop_symlink = zfs_symlink },
5508 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
5509 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5510 VOPNAME_FID, { .vop_fid = zfs_fid },
5511 VOPNAME_SEEK, { .vop_seek = zfs_seek },
5512 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5513 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5514 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5515 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5520 * Regular file vnode operations template
5522 vnodeops_t *zfs_fvnodeops;
5523 const fs_operation_def_t zfs_fvnodeops_template[] = {
5524 VOPNAME_OPEN, { .vop_open = zfs_open },
5525 VOPNAME_CLOSE, { .vop_close = zfs_close },
5526 VOPNAME_READ, { .vop_read = zfs_read },
5527 VOPNAME_WRITE, { .vop_write = zfs_write },
5528 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
5529 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5530 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5531 VOPNAME_ACCESS, { .vop_access = zfs_access },
5532 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
5533 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5534 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
5535 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5536 VOPNAME_FID, { .vop_fid = zfs_fid },
5537 VOPNAME_SEEK, { .vop_seek = zfs_seek },
5538 VOPNAME_FRLOCK, { .vop_frlock = zfs_frlock },
5539 VOPNAME_SPACE, { .vop_space = zfs_space },
5540 VOPNAME_GETPAGE, { .vop_getpage = zfs_getpage },
5541 VOPNAME_PUTPAGE, { .vop_putpage = zfs_putpage },
5542 VOPNAME_MAP, { .vop_map = zfs_map },
5543 VOPNAME_ADDMAP, { .vop_addmap = zfs_addmap },
5544 VOPNAME_DELMAP, { .vop_delmap = zfs_delmap },
5545 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5546 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5547 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5548 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5549 VOPNAME_REQZCBUF, { .vop_reqzcbuf = zfs_reqzcbuf },
5550 VOPNAME_RETZCBUF, { .vop_retzcbuf = zfs_retzcbuf },
5555 * Symbolic link vnode operations template
5557 vnodeops_t *zfs_symvnodeops;
5558 const fs_operation_def_t zfs_symvnodeops_template[] = {
5559 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5560 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5561 VOPNAME_ACCESS, { .vop_access = zfs_access },
5562 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5563 VOPNAME_READLINK, { .vop_readlink = zfs_readlink },
5564 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5565 VOPNAME_FID, { .vop_fid = zfs_fid },
5566 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5567 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5572 * special share hidden files vnode operations template
5574 vnodeops_t *zfs_sharevnodeops;
5575 const fs_operation_def_t zfs_sharevnodeops_template[] = {
5576 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5577 VOPNAME_ACCESS, { .vop_access = zfs_access },
5578 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5579 VOPNAME_FID, { .vop_fid = zfs_fid },
5580 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5581 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5582 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5583 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5588 * Extended attribute directory vnode operations template
5590 * This template is identical to the directory vnodes
5591 * operation template except for restricted operations:
5595 * Note that there are other restrictions embedded in:
5596 * zfs_create() - restrict type to VREG
5597 * zfs_link() - no links into/out of attribute space
5598 * zfs_rename() - no moves into/out of attribute space
5600 vnodeops_t *zfs_xdvnodeops;
5601 const fs_operation_def_t zfs_xdvnodeops_template[] = {
5602 VOPNAME_OPEN, { .vop_open = zfs_open },
5603 VOPNAME_CLOSE, { .vop_close = zfs_close },
5604 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
5605 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5606 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5607 VOPNAME_ACCESS, { .vop_access = zfs_access },
5608 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
5609 VOPNAME_CREATE, { .vop_create = zfs_create },
5610 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
5611 VOPNAME_LINK, { .vop_link = zfs_link },
5612 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5613 VOPNAME_MKDIR, { .error = zfs_inval },
5614 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
5615 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
5616 VOPNAME_SYMLINK, { .error = zfs_inval },
5617 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
5618 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5619 VOPNAME_FID, { .vop_fid = zfs_fid },
5620 VOPNAME_SEEK, { .vop_seek = zfs_seek },
5621 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5622 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5623 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5624 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5629 * Error vnode operations template
5631 vnodeops_t *zfs_evnodeops;
5632 const fs_operation_def_t zfs_evnodeops_template[] = {
5633 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5634 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5640 ioflags(int ioflags)
5644 if (ioflags & IO_APPEND)
5646 if (ioflags & IO_NDELAY)
5648 if (ioflags & IO_SYNC)
5649 flags |= (FSYNC | FDSYNC | FRSYNC);
5655 zfs_getpages(struct vnode *vp, vm_page_t *m, int count, int reqpage)
5657 znode_t *zp = VTOZ(vp);
5658 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
5659 objset_t *os = zp->z_zfsvfs->z_os;
5660 vm_page_t mfirst, mlast, mreq;
5664 off_t startoff, endoff;
5666 vm_pindex_t reqstart, reqend;
5667 int pcount, lsize, reqsize, size;
5672 pcount = OFF_TO_IDX(round_page(count));
5674 object = mreq->object;
5677 KASSERT(vp->v_object == object, ("mismatching object"));
5679 if (pcount > 1 && zp->z_blksz > PAGESIZE) {
5680 startoff = rounddown(IDX_TO_OFF(mreq->pindex), zp->z_blksz);
5681 reqstart = OFF_TO_IDX(round_page(startoff));
5682 if (reqstart < m[0]->pindex)
5685 reqstart = reqstart - m[0]->pindex;
5686 endoff = roundup(IDX_TO_OFF(mreq->pindex) + PAGE_SIZE,
5688 reqend = OFF_TO_IDX(trunc_page(endoff)) - 1;
5689 if (reqend > m[pcount - 1]->pindex)
5690 reqend = m[pcount - 1]->pindex;
5691 reqsize = reqend - m[reqstart]->pindex + 1;
5692 KASSERT(reqstart <= reqpage && reqpage < reqstart + reqsize,
5693 ("reqpage beyond [reqstart, reqstart + reqsize[ bounds"));
5698 mfirst = m[reqstart];
5699 mlast = m[reqstart + reqsize - 1];
5701 zfs_vmobject_wlock(object);
5703 for (i = 0; i < reqstart; i++) {
5706 vm_page_unlock(m[i]);
5708 for (i = reqstart + reqsize; i < pcount; i++) {
5711 vm_page_unlock(m[i]);
5714 if (mreq->valid && reqsize == 1) {
5715 if (mreq->valid != VM_PAGE_BITS_ALL)
5716 vm_page_zero_invalid(mreq, TRUE);
5717 zfs_vmobject_wunlock(object);
5719 return (zfs_vm_pagerret_ok);
5722 PCPU_INC(cnt.v_vnodein);
5723 PCPU_ADD(cnt.v_vnodepgsin, reqsize);
5725 if (IDX_TO_OFF(mreq->pindex) >= object->un_pager.vnp.vnp_size) {
5726 for (i = reqstart; i < reqstart + reqsize; i++) {
5730 vm_page_unlock(m[i]);
5733 zfs_vmobject_wunlock(object);
5735 return (zfs_vm_pagerret_bad);
5739 if (IDX_TO_OFF(mlast->pindex) + lsize > object->un_pager.vnp.vnp_size)
5740 lsize = object->un_pager.vnp.vnp_size - IDX_TO_OFF(mlast->pindex);
5742 zfs_vmobject_wunlock(object);
5744 for (i = reqstart; i < reqstart + reqsize; i++) {
5746 if (i == (reqstart + reqsize - 1))
5748 va = zfs_map_page(m[i], &sf);
5749 error = dmu_read(os, zp->z_id, IDX_TO_OFF(m[i]->pindex),
5750 size, va, DMU_READ_PREFETCH);
5751 if (size != PAGE_SIZE)
5752 bzero(va + size, PAGE_SIZE - size);
5758 zfs_vmobject_wlock(object);
5760 for (i = reqstart; i < reqstart + reqsize; i++) {
5762 m[i]->valid = VM_PAGE_BITS_ALL;
5763 KASSERT(m[i]->dirty == 0, ("zfs_getpages: page %p is dirty", m[i]));
5765 vm_page_readahead_finish(m[i]);
5768 zfs_vmobject_wunlock(object);
5770 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
5772 return (error ? zfs_vm_pagerret_error : zfs_vm_pagerret_ok);
5776 zfs_freebsd_getpages(ap)
5777 struct vop_getpages_args /* {
5782 vm_ooffset_t a_offset;
5786 return (zfs_getpages(ap->a_vp, ap->a_m, ap->a_count, ap->a_reqpage));
5790 zfs_freebsd_bmap(ap)
5791 struct vop_bmap_args /* {
5794 struct bufobj **a_bop;
5801 if (ap->a_bop != NULL)
5802 *ap->a_bop = &ap->a_vp->v_bufobj;
5803 if (ap->a_bnp != NULL)
5804 *ap->a_bnp = ap->a_bn;
5805 if (ap->a_runp != NULL)
5807 if (ap->a_runb != NULL)
5814 zfs_freebsd_open(ap)
5815 struct vop_open_args /* {
5818 struct ucred *a_cred;
5819 struct thread *a_td;
5822 vnode_t *vp = ap->a_vp;
5823 znode_t *zp = VTOZ(vp);
5826 error = zfs_open(&vp, ap->a_mode, ap->a_cred, NULL);
5828 vnode_create_vobject(vp, zp->z_size, ap->a_td);
5833 zfs_freebsd_close(ap)
5834 struct vop_close_args /* {
5837 struct ucred *a_cred;
5838 struct thread *a_td;
5842 return (zfs_close(ap->a_vp, ap->a_fflag, 1, 0, ap->a_cred, NULL));
5846 zfs_freebsd_ioctl(ap)
5847 struct vop_ioctl_args /* {
5857 return (zfs_ioctl(ap->a_vp, ap->a_command, (intptr_t)ap->a_data,
5858 ap->a_fflag, ap->a_cred, NULL, NULL));
5862 zfs_freebsd_read(ap)
5863 struct vop_read_args /* {
5867 struct ucred *a_cred;
5871 return (zfs_read(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag),
5876 zfs_freebsd_write(ap)
5877 struct vop_write_args /* {
5881 struct ucred *a_cred;
5885 return (zfs_write(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag),
5890 zfs_freebsd_access(ap)
5891 struct vop_access_args /* {
5893 accmode_t a_accmode;
5894 struct ucred *a_cred;
5895 struct thread *a_td;
5898 vnode_t *vp = ap->a_vp;
5899 znode_t *zp = VTOZ(vp);
5904 * ZFS itself only knowns about VREAD, VWRITE, VEXEC and VAPPEND,
5906 accmode = ap->a_accmode & (VREAD|VWRITE|VEXEC|VAPPEND);
5908 error = zfs_access(ap->a_vp, accmode, 0, ap->a_cred, NULL);
5911 * VADMIN has to be handled by vaccess().
5914 accmode = ap->a_accmode & ~(VREAD|VWRITE|VEXEC|VAPPEND);
5916 error = vaccess(vp->v_type, zp->z_mode, zp->z_uid,
5917 zp->z_gid, accmode, ap->a_cred, NULL);
5922 * For VEXEC, ensure that at least one execute bit is set for
5925 if (error == 0 && (ap->a_accmode & VEXEC) != 0 && vp->v_type != VDIR &&
5926 (zp->z_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) {
5934 zfs_freebsd_lookup(ap)
5935 struct vop_lookup_args /* {
5936 struct vnode *a_dvp;
5937 struct vnode **a_vpp;
5938 struct componentname *a_cnp;
5941 struct componentname *cnp = ap->a_cnp;
5942 char nm[NAME_MAX + 1];
5944 ASSERT(cnp->cn_namelen < sizeof(nm));
5945 strlcpy(nm, cnp->cn_nameptr, MIN(cnp->cn_namelen + 1, sizeof(nm)));
5947 return (zfs_lookup(ap->a_dvp, nm, ap->a_vpp, cnp, cnp->cn_nameiop,
5948 cnp->cn_cred, cnp->cn_thread, 0));
5952 zfs_freebsd_create(ap)
5953 struct vop_create_args /* {
5954 struct vnode *a_dvp;
5955 struct vnode **a_vpp;
5956 struct componentname *a_cnp;
5957 struct vattr *a_vap;
5960 struct componentname *cnp = ap->a_cnp;
5961 vattr_t *vap = ap->a_vap;
5964 ASSERT(cnp->cn_flags & SAVENAME);
5966 vattr_init_mask(vap);
5967 mode = vap->va_mode & ALLPERMS;
5969 return (zfs_create(ap->a_dvp, cnp->cn_nameptr, vap, !EXCL, mode,
5970 ap->a_vpp, cnp->cn_cred, cnp->cn_thread));
5974 zfs_freebsd_remove(ap)
5975 struct vop_remove_args /* {
5976 struct vnode *a_dvp;
5978 struct componentname *a_cnp;
5982 ASSERT(ap->a_cnp->cn_flags & SAVENAME);
5984 return (zfs_remove(ap->a_dvp, ap->a_cnp->cn_nameptr,
5985 ap->a_cnp->cn_cred, NULL, 0));
5989 zfs_freebsd_mkdir(ap)
5990 struct vop_mkdir_args /* {
5991 struct vnode *a_dvp;
5992 struct vnode **a_vpp;
5993 struct componentname *a_cnp;
5994 struct vattr *a_vap;
5997 vattr_t *vap = ap->a_vap;
5999 ASSERT(ap->a_cnp->cn_flags & SAVENAME);
6001 vattr_init_mask(vap);
6003 return (zfs_mkdir(ap->a_dvp, ap->a_cnp->cn_nameptr, vap, ap->a_vpp,
6004 ap->a_cnp->cn_cred, NULL, 0, NULL));
6008 zfs_freebsd_rmdir(ap)
6009 struct vop_rmdir_args /* {
6010 struct vnode *a_dvp;
6012 struct componentname *a_cnp;
6015 struct componentname *cnp = ap->a_cnp;
6017 ASSERT(cnp->cn_flags & SAVENAME);
6019 return (zfs_rmdir(ap->a_dvp, cnp->cn_nameptr, NULL, cnp->cn_cred, NULL, 0));
6023 zfs_freebsd_readdir(ap)
6024 struct vop_readdir_args /* {
6027 struct ucred *a_cred;
6034 return (zfs_readdir(ap->a_vp, ap->a_uio, ap->a_cred, ap->a_eofflag,
6035 ap->a_ncookies, ap->a_cookies));
6039 zfs_freebsd_fsync(ap)
6040 struct vop_fsync_args /* {
6043 struct thread *a_td;
6048 return (zfs_fsync(ap->a_vp, 0, ap->a_td->td_ucred, NULL));
6052 zfs_freebsd_getattr(ap)
6053 struct vop_getattr_args /* {
6055 struct vattr *a_vap;
6056 struct ucred *a_cred;
6059 vattr_t *vap = ap->a_vap;
6065 xvap.xva_vattr = *vap;
6066 xvap.xva_vattr.va_mask |= AT_XVATTR;
6068 /* Convert chflags into ZFS-type flags. */
6069 /* XXX: what about SF_SETTABLE?. */
6070 XVA_SET_REQ(&xvap, XAT_IMMUTABLE);
6071 XVA_SET_REQ(&xvap, XAT_APPENDONLY);
6072 XVA_SET_REQ(&xvap, XAT_NOUNLINK);
6073 XVA_SET_REQ(&xvap, XAT_NODUMP);
6074 XVA_SET_REQ(&xvap, XAT_READONLY);
6075 XVA_SET_REQ(&xvap, XAT_ARCHIVE);
6076 XVA_SET_REQ(&xvap, XAT_SYSTEM);
6077 XVA_SET_REQ(&xvap, XAT_HIDDEN);
6078 XVA_SET_REQ(&xvap, XAT_REPARSE);
6079 XVA_SET_REQ(&xvap, XAT_OFFLINE);
6080 XVA_SET_REQ(&xvap, XAT_SPARSE);
6082 error = zfs_getattr(ap->a_vp, (vattr_t *)&xvap, 0, ap->a_cred, NULL);
6086 /* Convert ZFS xattr into chflags. */
6087 #define FLAG_CHECK(fflag, xflag, xfield) do { \
6088 if (XVA_ISSET_RTN(&xvap, (xflag)) && (xfield) != 0) \
6089 fflags |= (fflag); \
6091 FLAG_CHECK(SF_IMMUTABLE, XAT_IMMUTABLE,
6092 xvap.xva_xoptattrs.xoa_immutable);
6093 FLAG_CHECK(SF_APPEND, XAT_APPENDONLY,
6094 xvap.xva_xoptattrs.xoa_appendonly);
6095 FLAG_CHECK(SF_NOUNLINK, XAT_NOUNLINK,
6096 xvap.xva_xoptattrs.xoa_nounlink);
6097 FLAG_CHECK(UF_ARCHIVE, XAT_ARCHIVE,
6098 xvap.xva_xoptattrs.xoa_archive);
6099 FLAG_CHECK(UF_NODUMP, XAT_NODUMP,
6100 xvap.xva_xoptattrs.xoa_nodump);
6101 FLAG_CHECK(UF_READONLY, XAT_READONLY,
6102 xvap.xva_xoptattrs.xoa_readonly);
6103 FLAG_CHECK(UF_SYSTEM, XAT_SYSTEM,
6104 xvap.xva_xoptattrs.xoa_system);
6105 FLAG_CHECK(UF_HIDDEN, XAT_HIDDEN,
6106 xvap.xva_xoptattrs.xoa_hidden);
6107 FLAG_CHECK(UF_REPARSE, XAT_REPARSE,
6108 xvap.xva_xoptattrs.xoa_reparse);
6109 FLAG_CHECK(UF_OFFLINE, XAT_OFFLINE,
6110 xvap.xva_xoptattrs.xoa_offline);
6111 FLAG_CHECK(UF_SPARSE, XAT_SPARSE,
6112 xvap.xva_xoptattrs.xoa_sparse);
6115 *vap = xvap.xva_vattr;
6116 vap->va_flags = fflags;
6121 zfs_freebsd_setattr(ap)
6122 struct vop_setattr_args /* {
6124 struct vattr *a_vap;
6125 struct ucred *a_cred;
6128 vnode_t *vp = ap->a_vp;
6129 vattr_t *vap = ap->a_vap;
6130 cred_t *cred = ap->a_cred;
6135 vattr_init_mask(vap);
6136 vap->va_mask &= ~AT_NOSET;
6139 xvap.xva_vattr = *vap;
6141 zflags = VTOZ(vp)->z_pflags;
6143 if (vap->va_flags != VNOVAL) {
6144 zfsvfs_t *zfsvfs = VTOZ(vp)->z_zfsvfs;
6147 if (zfsvfs->z_use_fuids == B_FALSE)
6148 return (EOPNOTSUPP);
6150 fflags = vap->va_flags;
6153 * We need to figure out whether it makes sense to allow
6154 * UF_REPARSE through, since we don't really have other
6155 * facilities to handle reparse points and zfs_setattr()
6156 * doesn't currently allow setting that attribute anyway.
6158 if ((fflags & ~(SF_IMMUTABLE|SF_APPEND|SF_NOUNLINK|UF_ARCHIVE|
6159 UF_NODUMP|UF_SYSTEM|UF_HIDDEN|UF_READONLY|UF_REPARSE|
6160 UF_OFFLINE|UF_SPARSE)) != 0)
6161 return (EOPNOTSUPP);
6163 * Unprivileged processes are not permitted to unset system
6164 * flags, or modify flags if any system flags are set.
6165 * Privileged non-jail processes may not modify system flags
6166 * if securelevel > 0 and any existing system flags are set.
6167 * Privileged jail processes behave like privileged non-jail
6168 * processes if the security.jail.chflags_allowed sysctl is
6169 * is non-zero; otherwise, they behave like unprivileged
6172 if (secpolicy_fs_owner(vp->v_mount, cred) == 0 ||
6173 priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0) == 0) {
6175 (ZFS_IMMUTABLE | ZFS_APPENDONLY | ZFS_NOUNLINK)) {
6176 error = securelevel_gt(cred, 0);
6182 * Callers may only modify the file flags on objects they
6183 * have VADMIN rights for.
6185 if ((error = VOP_ACCESS(vp, VADMIN, cred, curthread)) != 0)
6188 (ZFS_IMMUTABLE | ZFS_APPENDONLY | ZFS_NOUNLINK)) {
6192 (SF_IMMUTABLE | SF_APPEND | SF_NOUNLINK)) {
6197 #define FLAG_CHANGE(fflag, zflag, xflag, xfield) do { \
6198 if (((fflags & (fflag)) && !(zflags & (zflag))) || \
6199 ((zflags & (zflag)) && !(fflags & (fflag)))) { \
6200 XVA_SET_REQ(&xvap, (xflag)); \
6201 (xfield) = ((fflags & (fflag)) != 0); \
6204 /* Convert chflags into ZFS-type flags. */
6205 /* XXX: what about SF_SETTABLE?. */
6206 FLAG_CHANGE(SF_IMMUTABLE, ZFS_IMMUTABLE, XAT_IMMUTABLE,
6207 xvap.xva_xoptattrs.xoa_immutable);
6208 FLAG_CHANGE(SF_APPEND, ZFS_APPENDONLY, XAT_APPENDONLY,
6209 xvap.xva_xoptattrs.xoa_appendonly);
6210 FLAG_CHANGE(SF_NOUNLINK, ZFS_NOUNLINK, XAT_NOUNLINK,
6211 xvap.xva_xoptattrs.xoa_nounlink);
6212 FLAG_CHANGE(UF_ARCHIVE, ZFS_ARCHIVE, XAT_ARCHIVE,
6213 xvap.xva_xoptattrs.xoa_archive);
6214 FLAG_CHANGE(UF_NODUMP, ZFS_NODUMP, XAT_NODUMP,
6215 xvap.xva_xoptattrs.xoa_nodump);
6216 FLAG_CHANGE(UF_READONLY, ZFS_READONLY, XAT_READONLY,
6217 xvap.xva_xoptattrs.xoa_readonly);
6218 FLAG_CHANGE(UF_SYSTEM, ZFS_SYSTEM, XAT_SYSTEM,
6219 xvap.xva_xoptattrs.xoa_system);
6220 FLAG_CHANGE(UF_HIDDEN, ZFS_HIDDEN, XAT_HIDDEN,
6221 xvap.xva_xoptattrs.xoa_hidden);
6222 FLAG_CHANGE(UF_REPARSE, ZFS_REPARSE, XAT_REPARSE,
6223 xvap.xva_xoptattrs.xoa_hidden);
6224 FLAG_CHANGE(UF_OFFLINE, ZFS_OFFLINE, XAT_OFFLINE,
6225 xvap.xva_xoptattrs.xoa_offline);
6226 FLAG_CHANGE(UF_SPARSE, ZFS_SPARSE, XAT_SPARSE,
6227 xvap.xva_xoptattrs.xoa_sparse);
6230 return (zfs_setattr(vp, (vattr_t *)&xvap, 0, cred, NULL));
6234 zfs_freebsd_rename(ap)
6235 struct vop_rename_args /* {
6236 struct vnode *a_fdvp;
6237 struct vnode *a_fvp;
6238 struct componentname *a_fcnp;
6239 struct vnode *a_tdvp;
6240 struct vnode *a_tvp;
6241 struct componentname *a_tcnp;
6244 vnode_t *fdvp = ap->a_fdvp;
6245 vnode_t *fvp = ap->a_fvp;
6246 vnode_t *tdvp = ap->a_tdvp;
6247 vnode_t *tvp = ap->a_tvp;
6250 ASSERT(ap->a_fcnp->cn_flags & (SAVENAME|SAVESTART));
6251 ASSERT(ap->a_tcnp->cn_flags & (SAVENAME|SAVESTART));
6254 * Check for cross-device rename.
6256 if ((fdvp->v_mount != tdvp->v_mount) ||
6257 (tvp && (fdvp->v_mount != tvp->v_mount)))
6260 error = zfs_rename(fdvp, ap->a_fcnp->cn_nameptr, tdvp,
6261 ap->a_tcnp->cn_nameptr, ap->a_fcnp->cn_cred, NULL, 0);
6275 zfs_freebsd_symlink(ap)
6276 struct vop_symlink_args /* {
6277 struct vnode *a_dvp;
6278 struct vnode **a_vpp;
6279 struct componentname *a_cnp;
6280 struct vattr *a_vap;
6284 struct componentname *cnp = ap->a_cnp;
6285 vattr_t *vap = ap->a_vap;
6287 ASSERT(cnp->cn_flags & SAVENAME);
6289 vap->va_type = VLNK; /* FreeBSD: Syscall only sets va_mode. */
6290 vattr_init_mask(vap);
6292 return (zfs_symlink(ap->a_dvp, ap->a_vpp, cnp->cn_nameptr, vap,
6293 ap->a_target, cnp->cn_cred, cnp->cn_thread));
6297 zfs_freebsd_readlink(ap)
6298 struct vop_readlink_args /* {
6301 struct ucred *a_cred;
6305 return (zfs_readlink(ap->a_vp, ap->a_uio, ap->a_cred, NULL));
6309 zfs_freebsd_link(ap)
6310 struct vop_link_args /* {
6311 struct vnode *a_tdvp;
6313 struct componentname *a_cnp;
6316 struct componentname *cnp = ap->a_cnp;
6317 vnode_t *vp = ap->a_vp;
6318 vnode_t *tdvp = ap->a_tdvp;
6320 if (tdvp->v_mount != vp->v_mount)
6323 ASSERT(cnp->cn_flags & SAVENAME);
6325 return (zfs_link(tdvp, vp, cnp->cn_nameptr, cnp->cn_cred, NULL, 0));
6329 zfs_freebsd_inactive(ap)
6330 struct vop_inactive_args /* {
6332 struct thread *a_td;
6335 vnode_t *vp = ap->a_vp;
6337 zfs_inactive(vp, ap->a_td->td_ucred, NULL);
6342 zfs_freebsd_reclaim(ap)
6343 struct vop_reclaim_args /* {
6345 struct thread *a_td;
6348 vnode_t *vp = ap->a_vp;
6349 znode_t *zp = VTOZ(vp);
6350 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
6354 /* Destroy the vm object and flush associated pages. */
6355 vnode_destroy_vobject(vp);
6358 * z_teardown_inactive_lock protects from a race with
6359 * zfs_znode_dmu_fini in zfsvfs_teardown during
6362 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER);
6363 if (zp->z_sa_hdl == NULL)
6367 rw_exit(&zfsvfs->z_teardown_inactive_lock);
6375 struct vop_fid_args /* {
6381 return (zfs_fid(ap->a_vp, (void *)ap->a_fid, NULL));
6385 zfs_freebsd_pathconf(ap)
6386 struct vop_pathconf_args /* {
6389 register_t *a_retval;
6395 error = zfs_pathconf(ap->a_vp, ap->a_name, &val, curthread->td_ucred, NULL);
6397 *ap->a_retval = val;
6398 else if (error == EOPNOTSUPP)
6399 error = vop_stdpathconf(ap);
6404 zfs_freebsd_fifo_pathconf(ap)
6405 struct vop_pathconf_args /* {
6408 register_t *a_retval;
6412 switch (ap->a_name) {
6413 case _PC_ACL_EXTENDED:
6415 case _PC_ACL_PATH_MAX:
6416 case _PC_MAC_PRESENT:
6417 return (zfs_freebsd_pathconf(ap));
6419 return (fifo_specops.vop_pathconf(ap));
6424 * FreeBSD's extended attributes namespace defines file name prefix for ZFS'
6425 * extended attribute name:
6428 * system freebsd:system:
6429 * user (none, can be used to access ZFS fsattr(5) attributes
6430 * created on Solaris)
6433 zfs_create_attrname(int attrnamespace, const char *name, char *attrname,
6436 const char *namespace, *prefix, *suffix;
6438 /* We don't allow '/' character in attribute name. */
6439 if (strchr(name, '/') != NULL)
6441 /* We don't allow attribute names that start with "freebsd:" string. */
6442 if (strncmp(name, "freebsd:", 8) == 0)
6445 bzero(attrname, size);
6447 switch (attrnamespace) {
6448 case EXTATTR_NAMESPACE_USER:
6450 prefix = "freebsd:";
6451 namespace = EXTATTR_NAMESPACE_USER_STRING;
6455 * This is the default namespace by which we can access all
6456 * attributes created on Solaris.
6458 prefix = namespace = suffix = "";
6461 case EXTATTR_NAMESPACE_SYSTEM:
6462 prefix = "freebsd:";
6463 namespace = EXTATTR_NAMESPACE_SYSTEM_STRING;
6466 case EXTATTR_NAMESPACE_EMPTY:
6470 if (snprintf(attrname, size, "%s%s%s%s", prefix, namespace, suffix,
6472 return (ENAMETOOLONG);
6478 * Vnode operating to retrieve a named extended attribute.
6481 zfs_getextattr(struct vop_getextattr_args *ap)
6484 IN struct vnode *a_vp;
6485 IN int a_attrnamespace;
6486 IN const char *a_name;
6487 INOUT struct uio *a_uio;
6489 IN struct ucred *a_cred;
6490 IN struct thread *a_td;
6494 zfsvfs_t *zfsvfs = VTOZ(ap->a_vp)->z_zfsvfs;
6495 struct thread *td = ap->a_td;
6496 struct nameidata nd;
6499 vnode_t *xvp = NULL, *vp;
6502 error = extattr_check_cred(ap->a_vp, ap->a_attrnamespace,
6503 ap->a_cred, ap->a_td, VREAD);
6507 error = zfs_create_attrname(ap->a_attrnamespace, ap->a_name, attrname,
6514 error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td,
6522 NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, attrname,
6524 error = vn_open_cred(&nd, &flags, 0, 0, ap->a_cred, NULL);
6526 NDFREE(&nd, NDF_ONLY_PNBUF);
6529 if (error == ENOENT)
6534 if (ap->a_size != NULL) {
6535 error = VOP_GETATTR(vp, &va, ap->a_cred);
6537 *ap->a_size = (size_t)va.va_size;
6538 } else if (ap->a_uio != NULL)
6539 error = VOP_READ(vp, ap->a_uio, IO_UNIT, ap->a_cred);
6542 vn_close(vp, flags, ap->a_cred, td);
6549 * Vnode operation to remove a named attribute.
6552 zfs_deleteextattr(struct vop_deleteextattr_args *ap)
6555 IN struct vnode *a_vp;
6556 IN int a_attrnamespace;
6557 IN const char *a_name;
6558 IN struct ucred *a_cred;
6559 IN struct thread *a_td;
6563 zfsvfs_t *zfsvfs = VTOZ(ap->a_vp)->z_zfsvfs;
6564 struct thread *td = ap->a_td;
6565 struct nameidata nd;
6568 vnode_t *xvp = NULL, *vp;
6571 error = extattr_check_cred(ap->a_vp, ap->a_attrnamespace,
6572 ap->a_cred, ap->a_td, VWRITE);
6576 error = zfs_create_attrname(ap->a_attrnamespace, ap->a_name, attrname,
6583 error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td,
6590 NDINIT_ATVP(&nd, DELETE, NOFOLLOW | LOCKPARENT | LOCKLEAF,
6591 UIO_SYSSPACE, attrname, xvp, td);
6594 NDFREE(&nd, NDF_ONLY_PNBUF);
6597 if (error == ENOENT)
6601 error = VOP_REMOVE(nd.ni_dvp, vp, &nd.ni_cnd);
6604 if (vp == nd.ni_dvp)
6614 * Vnode operation to set a named attribute.
6617 zfs_setextattr(struct vop_setextattr_args *ap)
6620 IN struct vnode *a_vp;
6621 IN int a_attrnamespace;
6622 IN const char *a_name;
6623 INOUT struct uio *a_uio;
6624 IN struct ucred *a_cred;
6625 IN struct thread *a_td;
6629 zfsvfs_t *zfsvfs = VTOZ(ap->a_vp)->z_zfsvfs;
6630 struct thread *td = ap->a_td;
6631 struct nameidata nd;
6634 vnode_t *xvp = NULL, *vp;
6637 error = extattr_check_cred(ap->a_vp, ap->a_attrnamespace,
6638 ap->a_cred, ap->a_td, VWRITE);
6642 error = zfs_create_attrname(ap->a_attrnamespace, ap->a_name, attrname,
6649 error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td,
6650 LOOKUP_XATTR | CREATE_XATTR_DIR);
6656 flags = FFLAGS(O_WRONLY | O_CREAT);
6657 NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, attrname,
6659 error = vn_open_cred(&nd, &flags, 0600, 0, ap->a_cred, NULL);
6661 NDFREE(&nd, NDF_ONLY_PNBUF);
6669 error = VOP_SETATTR(vp, &va, ap->a_cred);
6671 VOP_WRITE(vp, ap->a_uio, IO_UNIT | IO_SYNC, ap->a_cred);
6674 vn_close(vp, flags, ap->a_cred, td);
6681 * Vnode operation to retrieve extended attributes on a vnode.
6684 zfs_listextattr(struct vop_listextattr_args *ap)
6687 IN struct vnode *a_vp;
6688 IN int a_attrnamespace;
6689 INOUT struct uio *a_uio;
6691 IN struct ucred *a_cred;
6692 IN struct thread *a_td;
6696 zfsvfs_t *zfsvfs = VTOZ(ap->a_vp)->z_zfsvfs;
6697 struct thread *td = ap->a_td;
6698 struct nameidata nd;
6699 char attrprefix[16];
6700 u_char dirbuf[sizeof(struct dirent)];
6703 struct uio auio, *uio = ap->a_uio;
6704 size_t *sizep = ap->a_size;
6706 vnode_t *xvp = NULL, *vp;
6707 int done, error, eof, pos;
6709 error = extattr_check_cred(ap->a_vp, ap->a_attrnamespace,
6710 ap->a_cred, ap->a_td, VREAD);
6714 error = zfs_create_attrname(ap->a_attrnamespace, "", attrprefix,
6715 sizeof(attrprefix));
6718 plen = strlen(attrprefix);
6725 error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td,
6730 * ENOATTR means that the EA directory does not yet exist,
6731 * i.e. there are no extended attributes there.
6733 if (error == ENOATTR)
6738 NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | LOCKSHARED,
6739 UIO_SYSSPACE, ".", xvp, td);
6742 NDFREE(&nd, NDF_ONLY_PNBUF);
6748 auio.uio_iov = &aiov;
6749 auio.uio_iovcnt = 1;
6750 auio.uio_segflg = UIO_SYSSPACE;
6752 auio.uio_rw = UIO_READ;
6753 auio.uio_offset = 0;
6758 aiov.iov_base = (void *)dirbuf;
6759 aiov.iov_len = sizeof(dirbuf);
6760 auio.uio_resid = sizeof(dirbuf);
6761 error = VOP_READDIR(vp, &auio, ap->a_cred, &eof, NULL, NULL);
6762 done = sizeof(dirbuf) - auio.uio_resid;
6765 for (pos = 0; pos < done;) {
6766 dp = (struct dirent *)(dirbuf + pos);
6767 pos += dp->d_reclen;
6769 * XXX: Temporarily we also accept DT_UNKNOWN, as this
6770 * is what we get when attribute was created on Solaris.
6772 if (dp->d_type != DT_REG && dp->d_type != DT_UNKNOWN)
6774 if (plen == 0 && strncmp(dp->d_name, "freebsd:", 8) == 0)
6776 else if (strncmp(dp->d_name, attrprefix, plen) != 0)
6778 nlen = dp->d_namlen - plen;
6781 else if (uio != NULL) {
6783 * Format of extattr name entry is one byte for
6784 * length and the rest for name.
6786 error = uiomove(&nlen, 1, uio->uio_rw, uio);
6788 error = uiomove(dp->d_name + plen, nlen,
6795 } while (!eof && error == 0);
6804 zfs_freebsd_getacl(ap)
6805 struct vop_getacl_args /* {
6814 vsecattr_t vsecattr;
6816 if (ap->a_type != ACL_TYPE_NFS4)
6819 vsecattr.vsa_mask = VSA_ACE | VSA_ACECNT;
6820 if (error = zfs_getsecattr(ap->a_vp, &vsecattr, 0, ap->a_cred, NULL))
6823 error = acl_from_aces(ap->a_aclp, vsecattr.vsa_aclentp, vsecattr.vsa_aclcnt);
6824 if (vsecattr.vsa_aclentp != NULL)
6825 kmem_free(vsecattr.vsa_aclentp, vsecattr.vsa_aclentsz);
6831 zfs_freebsd_setacl(ap)
6832 struct vop_setacl_args /* {
6841 vsecattr_t vsecattr;
6842 int aclbsize; /* size of acl list in bytes */
6845 if (ap->a_type != ACL_TYPE_NFS4)
6848 if (ap->a_aclp->acl_cnt < 1 || ap->a_aclp->acl_cnt > MAX_ACL_ENTRIES)
6852 * With NFSv4 ACLs, chmod(2) may need to add additional entries,
6853 * splitting every entry into two and appending "canonical six"
6854 * entries at the end. Don't allow for setting an ACL that would
6855 * cause chmod(2) to run out of ACL entries.
6857 if (ap->a_aclp->acl_cnt * 2 + 6 > ACL_MAX_ENTRIES)
6860 error = acl_nfs4_check(ap->a_aclp, ap->a_vp->v_type == VDIR);
6864 vsecattr.vsa_mask = VSA_ACE;
6865 aclbsize = ap->a_aclp->acl_cnt * sizeof(ace_t);
6866 vsecattr.vsa_aclentp = kmem_alloc(aclbsize, KM_SLEEP);
6867 aaclp = vsecattr.vsa_aclentp;
6868 vsecattr.vsa_aclentsz = aclbsize;
6870 aces_from_acl(vsecattr.vsa_aclentp, &vsecattr.vsa_aclcnt, ap->a_aclp);
6871 error = zfs_setsecattr(ap->a_vp, &vsecattr, 0, ap->a_cred, NULL);
6872 kmem_free(aaclp, aclbsize);
6878 zfs_freebsd_aclcheck(ap)
6879 struct vop_aclcheck_args /* {
6888 return (EOPNOTSUPP);
6891 struct vop_vector zfs_vnodeops;
6892 struct vop_vector zfs_fifoops;
6893 struct vop_vector zfs_shareops;
6895 struct vop_vector zfs_vnodeops = {
6896 .vop_default = &default_vnodeops,
6897 .vop_inactive = zfs_freebsd_inactive,
6898 .vop_reclaim = zfs_freebsd_reclaim,
6899 .vop_access = zfs_freebsd_access,
6900 #ifdef FREEBSD_NAMECACHE
6901 .vop_lookup = vfs_cache_lookup,
6902 .vop_cachedlookup = zfs_freebsd_lookup,
6904 .vop_lookup = zfs_freebsd_lookup,
6906 .vop_getattr = zfs_freebsd_getattr,
6907 .vop_setattr = zfs_freebsd_setattr,
6908 .vop_create = zfs_freebsd_create,
6909 .vop_mknod = zfs_freebsd_create,
6910 .vop_mkdir = zfs_freebsd_mkdir,
6911 .vop_readdir = zfs_freebsd_readdir,
6912 .vop_fsync = zfs_freebsd_fsync,
6913 .vop_open = zfs_freebsd_open,
6914 .vop_close = zfs_freebsd_close,
6915 .vop_rmdir = zfs_freebsd_rmdir,
6916 .vop_ioctl = zfs_freebsd_ioctl,
6917 .vop_link = zfs_freebsd_link,
6918 .vop_symlink = zfs_freebsd_symlink,
6919 .vop_readlink = zfs_freebsd_readlink,
6920 .vop_read = zfs_freebsd_read,
6921 .vop_write = zfs_freebsd_write,
6922 .vop_remove = zfs_freebsd_remove,
6923 .vop_rename = zfs_freebsd_rename,
6924 .vop_pathconf = zfs_freebsd_pathconf,
6925 .vop_bmap = zfs_freebsd_bmap,
6926 .vop_fid = zfs_freebsd_fid,
6927 .vop_getextattr = zfs_getextattr,
6928 .vop_deleteextattr = zfs_deleteextattr,
6929 .vop_setextattr = zfs_setextattr,
6930 .vop_listextattr = zfs_listextattr,
6931 .vop_getacl = zfs_freebsd_getacl,
6932 .vop_setacl = zfs_freebsd_setacl,
6933 .vop_aclcheck = zfs_freebsd_aclcheck,
6934 .vop_getpages = zfs_freebsd_getpages,
6937 struct vop_vector zfs_fifoops = {
6938 .vop_default = &fifo_specops,
6939 .vop_fsync = zfs_freebsd_fsync,
6940 .vop_access = zfs_freebsd_access,
6941 .vop_getattr = zfs_freebsd_getattr,
6942 .vop_inactive = zfs_freebsd_inactive,
6943 .vop_read = VOP_PANIC,
6944 .vop_reclaim = zfs_freebsd_reclaim,
6945 .vop_setattr = zfs_freebsd_setattr,
6946 .vop_write = VOP_PANIC,
6947 .vop_pathconf = zfs_freebsd_fifo_pathconf,
6948 .vop_fid = zfs_freebsd_fid,
6949 .vop_getacl = zfs_freebsd_getacl,
6950 .vop_setacl = zfs_freebsd_setacl,
6951 .vop_aclcheck = zfs_freebsd_aclcheck,
6955 * special share hidden files vnode operations template
6957 struct vop_vector zfs_shareops = {
6958 .vop_default = &default_vnodeops,
6959 .vop_access = zfs_freebsd_access,
6960 .vop_inactive = zfs_freebsd_inactive,
6961 .vop_reclaim = zfs_freebsd_reclaim,
6962 .vop_fid = zfs_freebsd_fid,
6963 .vop_pathconf = zfs_freebsd_pathconf,