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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Portions Copyright 2007 Jeremy Teo */
28 #pragma ident "@(#)zfs_vnops.c 1.73 08/04/27 SMI"
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>
37 #include <sys/vfs_opreg.h>
38 #include <sys/vnode.h>
42 #include <sys/taskq.h>
44 #include <sys/vmsystm.h>
45 #include <sys/atomic.h>
47 #include <vm/seg_vn.h>
51 #include <sys/pathname.h>
52 #include <sys/cmn_err.h>
53 #include <sys/errno.h>
54 #include <sys/unistd.h>
55 #include <sys/zfs_dir.h>
56 #include <sys/zfs_acl.h>
57 #include <sys/zfs_ioctl.h>
58 #include <sys/fs/zfs.h>
64 #include <sys/dirent.h>
65 #include <sys/policy.h>
66 #include <sys/sunddi.h>
67 #include <sys/filio.h>
68 #include "fs/fs_subr.h"
69 #include <sys/zfs_ctldir.h>
70 #include <sys/zfs_fuid.h>
72 #include <sys/zfs_rlock.h>
73 #include <sys/extdirent.h>
74 #include <sys/kidmap.h>
75 #include <sys/cred_impl.h>
81 * Each vnode op performs some logical unit of work. To do this, the ZPL must
82 * properly lock its in-core state, create a DMU transaction, do the work,
83 * record this work in the intent log (ZIL), commit the DMU transaction,
84 * and wait for the intent log to commit if it is a synchronous operation.
85 * Moreover, the vnode ops must work in both normal and log replay context.
86 * The ordering of events is important to avoid deadlocks and references
87 * to freed memory. The example below illustrates the following Big Rules:
89 * (1) A check must be made in each zfs thread for a mounted file system.
90 * This is done avoiding races using ZFS_ENTER(zfsvfs).
91 * A ZFS_EXIT(zfsvfs) is needed before all returns. Any znodes
92 * must be checked with ZFS_VERIFY_ZP(zp). Both of these macros
93 * can return EIO from the calling function.
95 * (2) VN_RELE() should always be the last thing except for zil_commit()
96 * (if necessary) and ZFS_EXIT(). This is for 3 reasons:
97 * First, if it's the last reference, the vnode/znode
98 * can be freed, so the zp may point to freed memory. Second, the last
99 * reference will call zfs_zinactive(), which may induce a lot of work --
100 * pushing cached pages (which acquires range locks) and syncing out
101 * cached atime changes. Third, zfs_zinactive() may require a new tx,
102 * which could deadlock the system if you were already holding one.
104 * (3) All range locks must be grabbed before calling dmu_tx_assign(),
105 * as they can span dmu_tx_assign() calls.
107 * (4) Always pass zfsvfs->z_assign as the second argument to dmu_tx_assign().
108 * In normal operation, this will be TXG_NOWAIT. During ZIL replay,
109 * it will be a specific txg. Either way, dmu_tx_assign() never blocks.
110 * This is critical because we don't want to block while holding locks.
111 * Note, in particular, that if a lock is sometimes acquired before
112 * the tx assigns, and sometimes after (e.g. z_lock), then failing to
113 * use a non-blocking assign can deadlock the system. The scenario:
115 * Thread A has grabbed a lock before calling dmu_tx_assign().
116 * Thread B is in an already-assigned tx, and blocks for this lock.
117 * Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
118 * forever, because the previous txg can't quiesce until B's tx commits.
120 * If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
121 * then drop all locks, call dmu_tx_wait(), and try again.
123 * (5) If the operation succeeded, generate the intent log entry for it
124 * before dropping locks. This ensures that the ordering of events
125 * in the intent log matches the order in which they actually occurred.
127 * (6) At the end of each vnode op, the DMU tx must always commit,
128 * regardless of whether there were any errors.
130 * (7) After dropping all locks, invoke zil_commit(zilog, seq, foid)
131 * to ensure that synchronous semantics are provided when necessary.
133 * In general, this is how things should be ordered in each vnode op:
135 * ZFS_ENTER(zfsvfs); // exit if unmounted
137 * zfs_dirent_lock(&dl, ...) // lock directory entry (may VN_HOLD())
138 * rw_enter(...); // grab any other locks you need
139 * tx = dmu_tx_create(...); // get DMU tx
140 * dmu_tx_hold_*(); // hold each object you might modify
141 * error = dmu_tx_assign(tx, zfsvfs->z_assign); // try to assign
143 * rw_exit(...); // drop locks
144 * zfs_dirent_unlock(dl); // unlock directory entry
145 * VN_RELE(...); // release held vnodes
146 * if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
151 * dmu_tx_abort(tx); // abort DMU tx
152 * ZFS_EXIT(zfsvfs); // finished in zfs
153 * return (error); // really out of space
155 * error = do_real_work(); // do whatever this VOP does
157 * zfs_log_*(...); // on success, make ZIL entry
158 * dmu_tx_commit(tx); // commit DMU tx -- error or not
159 * rw_exit(...); // drop locks
160 * zfs_dirent_unlock(dl); // unlock directory entry
161 * VN_RELE(...); // release held vnodes
162 * zil_commit(zilog, seq, foid); // synchronous when necessary
163 * ZFS_EXIT(zfsvfs); // finished in zfs
164 * return (error); // done, report error
169 zfs_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
171 znode_t *zp = VTOZ(*vpp);
173 if ((flag & FWRITE) && (zp->z_phys->zp_flags & ZFS_APPENDONLY) &&
174 ((flag & FAPPEND) == 0)) {
178 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
179 ZTOV(zp)->v_type == VREG &&
180 !(zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) &&
181 zp->z_phys->zp_size > 0)
182 if (fs_vscan(*vpp, cr, 0) != 0)
185 /* Keep a count of the synchronous opens in the znode */
186 if (flag & (FSYNC | FDSYNC))
187 atomic_inc_32(&zp->z_sync_cnt);
194 zfs_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr,
195 caller_context_t *ct)
197 znode_t *zp = VTOZ(vp);
199 /* Decrement the synchronous opens in the znode */
200 if ((flag & (FSYNC | FDSYNC)) && (count == 1))
201 atomic_dec_32(&zp->z_sync_cnt);
204 * Clean up any locks held by this process on the vp.
206 cleanlocks(vp, ddi_get_pid(), 0);
207 cleanshares(vp, ddi_get_pid());
209 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
210 ZTOV(zp)->v_type == VREG &&
211 !(zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) &&
212 zp->z_phys->zp_size > 0)
213 VERIFY(fs_vscan(vp, cr, 1) == 0);
219 * Lseek support for finding holes (cmd == _FIO_SEEK_HOLE) and
220 * data (cmd == _FIO_SEEK_DATA). "off" is an in/out parameter.
223 zfs_holey(vnode_t *vp, int cmd, offset_t *off)
225 znode_t *zp = VTOZ(vp);
226 uint64_t noff = (uint64_t)*off; /* new offset */
231 file_sz = zp->z_phys->zp_size;
232 if (noff >= file_sz) {
236 if (cmd == _FIO_SEEK_HOLE)
241 error = dmu_offset_next(zp->z_zfsvfs->z_os, zp->z_id, hole, &noff);
244 if ((error == ESRCH) || (noff > file_sz)) {
246 * Handle the virtual hole at the end of file.
263 zfs_ioctl(vnode_t *vp, int com, intptr_t data, int flag, cred_t *cred,
264 int *rvalp, caller_context_t *ct)
273 return (zfs_sync(vp->v_vfsp, 0, cred));
276 * The following two ioctls are used by bfu. Faking out,
277 * necessary to avoid bfu errors.
285 if (ddi_copyin((void *)data, &off, sizeof (off), flag))
289 zfsvfs = zp->z_zfsvfs;
293 /* offset parameter is in/out */
294 error = zfs_holey(vp, com, &off);
298 if (ddi_copyout(&off, (void *)data, sizeof (off), flag))
306 * When a file is memory mapped, we must keep the IO data synchronized
307 * between the DMU cache and the memory mapped pages. What this means:
309 * On Write: If we find a memory mapped page, we write to *both*
310 * the page and the dmu buffer.
312 * NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
313 * the file is memory mapped.
316 mappedwrite(vnode_t *vp, int nbytes, uio_t *uio, dmu_tx_t *tx)
318 znode_t *zp = VTOZ(vp);
319 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
324 start = uio->uio_loffset;
325 off = start & PAGEOFFSET;
326 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
328 uint64_t bytes = MIN(PAGESIZE - off, len);
329 uint64_t woff = uio->uio_loffset;
332 * We don't want a new page to "appear" in the middle of
333 * the file update (because it may not get the write
334 * update data), so we grab a lock to block
337 rw_enter(&zp->z_map_lock, RW_WRITER);
338 if (pp = page_lookup(vp, start, SE_SHARED)) {
341 rw_exit(&zp->z_map_lock);
342 va = ppmapin(pp, PROT_READ | PROT_WRITE, (caddr_t)-1L);
343 error = uiomove(va+off, bytes, UIO_WRITE, uio);
345 dmu_write(zfsvfs->z_os, zp->z_id,
346 woff, bytes, va+off, tx);
351 error = dmu_write_uio(zfsvfs->z_os, zp->z_id,
353 rw_exit(&zp->z_map_lock);
364 * When a file is memory mapped, we must keep the IO data synchronized
365 * between the DMU cache and the memory mapped pages. What this means:
367 * On Read: We "read" preferentially from memory mapped pages,
368 * else we default from the dmu buffer.
370 * NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
371 * the file is memory mapped.
374 mappedread(vnode_t *vp, int nbytes, uio_t *uio)
376 znode_t *zp = VTOZ(vp);
377 objset_t *os = zp->z_zfsvfs->z_os;
382 start = uio->uio_loffset;
383 off = start & PAGEOFFSET;
384 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
386 uint64_t bytes = MIN(PAGESIZE - off, len);
388 if (pp = page_lookup(vp, start, SE_SHARED)) {
391 va = ppmapin(pp, PROT_READ, (caddr_t)-1L);
392 error = uiomove(va + off, bytes, UIO_READ, uio);
396 error = dmu_read_uio(os, zp->z_id, uio, bytes);
406 offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */
409 * Read bytes from specified file into supplied buffer.
411 * IN: vp - vnode of file to be read from.
412 * uio - structure supplying read location, range info,
414 * ioflag - SYNC flags; used to provide FRSYNC semantics.
415 * cr - credentials of caller.
416 * ct - caller context
418 * OUT: uio - updated offset and range, buffer filled.
420 * RETURN: 0 if success
421 * error code if failure
424 * vp - atime updated if byte count > 0
428 zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
430 znode_t *zp = VTOZ(vp);
431 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
441 if (zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) {
447 * Validate file offset
449 if (uio->uio_loffset < (offset_t)0) {
455 * Fasttrack empty reads
457 if (uio->uio_resid == 0) {
463 * Check for mandatory locks
465 if (MANDMODE((mode_t)zp->z_phys->zp_mode)) {
466 if (error = chklock(vp, FREAD,
467 uio->uio_loffset, uio->uio_resid, uio->uio_fmode, ct)) {
474 * If we're in FRSYNC mode, sync out this znode before reading it.
477 zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
480 * Lock the range against changes.
482 rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER);
485 * If we are reading past end-of-file we can skip
486 * to the end; but we might still need to set atime.
488 if (uio->uio_loffset >= zp->z_phys->zp_size) {
493 ASSERT(uio->uio_loffset < zp->z_phys->zp_size);
494 n = MIN(uio->uio_resid, zp->z_phys->zp_size - uio->uio_loffset);
497 nbytes = MIN(n, zfs_read_chunk_size -
498 P2PHASE(uio->uio_loffset, zfs_read_chunk_size));
500 if (vn_has_cached_data(vp))
501 error = mappedread(vp, nbytes, uio);
503 error = dmu_read_uio(os, zp->z_id, uio, nbytes);
511 zfs_range_unlock(rl);
513 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
519 * Fault in the pages of the first n bytes specified by the uio structure.
520 * 1 byte in each page is touched and the uio struct is unmodified.
521 * Any error will exit this routine as this is only a best
522 * attempt to get the pages resident. This is a copy of ufs_trans_touch().
525 zfs_prefault_write(ssize_t n, struct uio *uio)
535 cnt = MIN(iov->iov_len, n);
537 /* empty iov entry */
543 * touch each page in this segment.
547 switch (uio->uio_segflg) {
550 if (fuword8(p, &tmp))
554 if (kcopy(p, &tmp, 1))
558 incr = MIN(cnt, PAGESIZE);
563 * touch the last byte in case it straddles a page.
566 switch (uio->uio_segflg) {
569 if (fuword8(p, &tmp))
573 if (kcopy(p, &tmp, 1))
582 * Write the bytes to a file.
584 * IN: vp - vnode of file to be written to.
585 * uio - structure supplying write location, range info,
587 * ioflag - FAPPEND flag set if in append mode.
588 * cr - credentials of caller.
589 * ct - caller context (NFS/CIFS fem monitor only)
591 * OUT: uio - updated offset and range.
593 * RETURN: 0 if success
594 * error code if failure
597 * vp - ctime|mtime updated if byte count > 0
601 zfs_write(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
603 znode_t *zp = VTOZ(vp);
604 rlim64_t limit = uio->uio_llimit;
605 ssize_t start_resid = uio->uio_resid;
609 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
614 int max_blksz = zfsvfs->z_max_blksz;
615 uint64_t pflags = zp->z_phys->zp_flags;
619 * If immutable or not appending then return EPERM
621 if ((pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) ||
622 ((pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) &&
623 (uio->uio_loffset < zp->z_phys->zp_size)))
627 * Fasttrack empty write
633 if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
638 zilog = zfsvfs->z_log;
641 * Pre-fault the pages to ensure slow (eg NFS) pages
644 zfs_prefault_write(n, uio);
647 * If in append mode, set the io offset pointer to eof.
649 if (ioflag & FAPPEND) {
651 * Range lock for a file append:
652 * The value for the start of range will be determined by
653 * zfs_range_lock() (to guarantee append semantics).
654 * If this write will cause the block size to increase,
655 * zfs_range_lock() will lock the entire file, so we must
656 * later reduce the range after we grow the block size.
658 rl = zfs_range_lock(zp, 0, n, RL_APPEND);
659 if (rl->r_len == UINT64_MAX) {
660 /* overlocked, zp_size can't change */
661 woff = uio->uio_loffset = zp->z_phys->zp_size;
663 woff = uio->uio_loffset = rl->r_off;
666 woff = uio->uio_loffset;
668 * Validate file offset
676 * If we need to grow the block size then zfs_range_lock()
677 * will lock a wider range than we request here.
678 * Later after growing the block size we reduce the range.
680 rl = zfs_range_lock(zp, woff, n, RL_WRITER);
684 zfs_range_unlock(rl);
689 if ((woff + n) > limit || woff > (limit - n))
693 * Check for mandatory locks
695 if (MANDMODE((mode_t)zp->z_phys->zp_mode) &&
696 (error = chklock(vp, FWRITE, woff, n, uio->uio_fmode, ct)) != 0) {
697 zfs_range_unlock(rl);
701 end_size = MAX(zp->z_phys->zp_size, woff + n);
704 * Write the file in reasonable size chunks. Each chunk is written
705 * in a separate transaction; this keeps the intent log records small
706 * and allows us to do more fine-grained space accounting.
710 * Start a transaction.
712 woff = uio->uio_loffset;
713 tx = dmu_tx_create(zfsvfs->z_os);
714 dmu_tx_hold_bonus(tx, zp->z_id);
715 dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
716 error = dmu_tx_assign(tx, zfsvfs->z_assign);
718 if (error == ERESTART &&
719 zfsvfs->z_assign == TXG_NOWAIT) {
729 * If zfs_range_lock() over-locked we grow the blocksize
730 * and then reduce the lock range. This will only happen
731 * on the first iteration since zfs_range_reduce() will
732 * shrink down r_len to the appropriate size.
734 if (rl->r_len == UINT64_MAX) {
737 if (zp->z_blksz > max_blksz) {
738 ASSERT(!ISP2(zp->z_blksz));
739 new_blksz = MIN(end_size, SPA_MAXBLOCKSIZE);
741 new_blksz = MIN(end_size, max_blksz);
743 zfs_grow_blocksize(zp, new_blksz, tx);
744 zfs_range_reduce(rl, woff, n);
748 * XXX - should we really limit each write to z_max_blksz?
749 * Perhaps we should use SPA_MAXBLOCKSIZE chunks?
751 nbytes = MIN(n, max_blksz - P2PHASE(woff, max_blksz));
752 rw_enter(&zp->z_map_lock, RW_READER);
754 tx_bytes = uio->uio_resid;
755 if (vn_has_cached_data(vp)) {
756 rw_exit(&zp->z_map_lock);
757 error = mappedwrite(vp, nbytes, uio, tx);
759 error = dmu_write_uio(zfsvfs->z_os, zp->z_id,
761 rw_exit(&zp->z_map_lock);
763 tx_bytes -= uio->uio_resid;
766 * If we made no progress, we're done. If we made even
767 * partial progress, update the znode and ZIL accordingly.
776 * Clear Set-UID/Set-GID bits on successful write if not
777 * privileged and at least one of the excute bits is set.
779 * It would be nice to to this after all writes have
780 * been done, but that would still expose the ISUID/ISGID
781 * to another app after the partial write is committed.
783 * Note: we don't call zfs_fuid_map_id() here because
784 * user 0 is not an ephemeral uid.
786 mutex_enter(&zp->z_acl_lock);
787 if ((zp->z_phys->zp_mode & (S_IXUSR | (S_IXUSR >> 3) |
788 (S_IXUSR >> 6))) != 0 &&
789 (zp->z_phys->zp_mode & (S_ISUID | S_ISGID)) != 0 &&
790 secpolicy_vnode_setid_retain(cr,
791 (zp->z_phys->zp_mode & S_ISUID) != 0 &&
792 zp->z_phys->zp_uid == 0) != 0) {
793 zp->z_phys->zp_mode &= ~(S_ISUID | S_ISGID);
795 mutex_exit(&zp->z_acl_lock);
798 * Update time stamp. NOTE: This marks the bonus buffer as
799 * dirty, so we don't have to do it again for zp_size.
801 zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
804 * Update the file size (zp_size) if it has changed;
805 * account for possible concurrent updates.
807 while ((end_size = zp->z_phys->zp_size) < uio->uio_loffset)
808 (void) atomic_cas_64(&zp->z_phys->zp_size, end_size,
810 zfs_log_write(zilog, tx, TX_WRITE, zp, woff, tx_bytes, ioflag);
815 ASSERT(tx_bytes == nbytes);
819 zfs_range_unlock(rl);
822 * If we're in replay mode, or we made no progress, return error.
823 * Otherwise, it's at least a partial write, so it's successful.
825 if (zfsvfs->z_assign >= TXG_INITIAL || uio->uio_resid == start_resid) {
830 if (ioflag & (FSYNC | FDSYNC))
831 zil_commit(zilog, zp->z_last_itx, zp->z_id);
838 zfs_get_done(dmu_buf_t *db, void *vzgd)
840 zgd_t *zgd = (zgd_t *)vzgd;
841 rl_t *rl = zgd->zgd_rl;
842 vnode_t *vp = ZTOV(rl->r_zp);
844 dmu_buf_rele(db, vzgd);
845 zfs_range_unlock(rl);
847 zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
848 kmem_free(zgd, sizeof (zgd_t));
852 * Get data to generate a TX_WRITE intent log record.
855 zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
857 zfsvfs_t *zfsvfs = arg;
858 objset_t *os = zfsvfs->z_os;
860 uint64_t off = lr->lr_offset;
864 int dlen = lr->lr_length; /* length of user data */
871 * Nothing to do if the file has been removed
873 if (zfs_zget(zfsvfs, lr->lr_foid, &zp) != 0)
875 if (zp->z_unlinked) {
881 * Write records come in two flavors: immediate and indirect.
882 * For small writes it's cheaper to store the data with the
883 * log record (immediate); for large writes it's cheaper to
884 * sync the data and get a pointer to it (indirect) so that
885 * we don't have to write the data twice.
887 if (buf != NULL) { /* immediate write */
888 rl = zfs_range_lock(zp, off, dlen, RL_READER);
889 /* test for truncation needs to be done while range locked */
890 if (off >= zp->z_phys->zp_size) {
894 VERIFY(0 == dmu_read(os, lr->lr_foid, off, dlen, buf));
895 } else { /* indirect write */
896 uint64_t boff; /* block starting offset */
899 * Have to lock the whole block to ensure when it's
900 * written out and it's checksum is being calculated
901 * that no one can change the data. We need to re-check
902 * blocksize after we get the lock in case it's changed!
905 if (ISP2(zp->z_blksz)) {
906 boff = P2ALIGN_TYPED(off, zp->z_blksz,
912 rl = zfs_range_lock(zp, boff, dlen, RL_READER);
913 if (zp->z_blksz == dlen)
915 zfs_range_unlock(rl);
917 /* test for truncation needs to be done while range locked */
918 if (off >= zp->z_phys->zp_size) {
922 zgd = (zgd_t *)kmem_alloc(sizeof (zgd_t), KM_SLEEP);
924 zgd->zgd_zilog = zfsvfs->z_log;
925 zgd->zgd_bp = &lr->lr_blkptr;
926 VERIFY(0 == dmu_buf_hold(os, lr->lr_foid, boff, zgd, &db));
927 ASSERT(boff == db->db_offset);
928 lr->lr_blkoff = off - boff;
929 error = dmu_sync(zio, db, &lr->lr_blkptr,
930 lr->lr_common.lrc_txg, zfs_get_done, zgd);
931 ASSERT((error && error != EINPROGRESS) ||
932 lr->lr_length <= zp->z_blksz);
934 zil_add_block(zfsvfs->z_log, &lr->lr_blkptr);
936 * If we get EINPROGRESS, then we need to wait for a
937 * write IO initiated by dmu_sync() to complete before
938 * we can release this dbuf. We will finish everything
939 * up in the zfs_get_done() callback.
941 if (error == EINPROGRESS)
943 dmu_buf_rele(db, zgd);
944 kmem_free(zgd, sizeof (zgd_t));
947 zfs_range_unlock(rl);
954 zfs_access(vnode_t *vp, int mode, int flag, cred_t *cr,
955 caller_context_t *ct)
957 znode_t *zp = VTOZ(vp);
958 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
964 if (flag & V_ACE_MASK)
965 error = zfs_zaccess(zp, mode, flag, B_FALSE, cr);
967 error = zfs_zaccess_rwx(zp, mode, flag, cr);
974 * Lookup an entry in a directory, or an extended attribute directory.
975 * If it exists, return a held vnode reference for it.
977 * IN: dvp - vnode of directory to search.
978 * nm - name of entry to lookup.
979 * pnp - full pathname to lookup [UNUSED].
980 * flags - LOOKUP_XATTR set if looking for an attribute.
981 * rdir - root directory vnode [UNUSED].
982 * cr - credentials of caller.
983 * ct - caller context
984 * direntflags - directory lookup flags
985 * realpnp - returned pathname.
987 * OUT: vpp - vnode of located entry, NULL if not found.
989 * RETURN: 0 if success
990 * error code if failure
997 zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp,
998 int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct,
999 int *direntflags, pathname_t *realpnp)
1001 znode_t *zdp = VTOZ(dvp);
1002 zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
1010 if (flags & LOOKUP_XATTR) {
1012 * If the xattr property is off, refuse the lookup request.
1014 if (!(zfsvfs->z_vfs->vfs_flag & VFS_XATTR)) {
1020 * We don't allow recursive attributes..
1021 * Maybe someday we will.
1023 if (zdp->z_phys->zp_flags & ZFS_XATTR) {
1028 if (error = zfs_get_xattrdir(VTOZ(dvp), vpp, cr, flags)) {
1034 * Do we have permission to get into attribute directory?
1037 if (error = zfs_zaccess(VTOZ(*vpp), ACE_EXECUTE, 0,
1047 if (dvp->v_type != VDIR) {
1053 * Check accessibility of directory.
1056 if (error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr)) {
1061 if (zfsvfs->z_utf8 && u8_validate(nm, strlen(nm),
1062 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1067 error = zfs_dirlook(zdp, nm, vpp, flags, direntflags, realpnp);
1070 * Convert device special files
1072 if (IS_DEVVP(*vpp)) {
1075 svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
1089 * Attempt to create a new entry in a directory. If the entry
1090 * already exists, truncate the file if permissible, else return
1091 * an error. Return the vp of the created or trunc'd file.
1093 * IN: dvp - vnode of directory to put new file entry in.
1094 * name - name of new file entry.
1095 * vap - attributes of new file.
1096 * excl - flag indicating exclusive or non-exclusive mode.
1097 * mode - mode to open file with.
1098 * cr - credentials of caller.
1099 * flag - large file flag [UNUSED].
1100 * ct - caller context
1101 * vsecp - ACL to be set
1103 * OUT: vpp - vnode of created or trunc'd entry.
1105 * RETURN: 0 if success
1106 * error code if failure
1109 * dvp - ctime|mtime updated if new entry created
1110 * vp - ctime|mtime always, atime if new
1115 zfs_create(vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl,
1116 int mode, vnode_t **vpp, cred_t *cr, int flag, caller_context_t *ct,
1119 znode_t *zp, *dzp = VTOZ(dvp);
1120 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1126 zfs_acl_t *aclp = NULL;
1127 zfs_fuid_info_t *fuidp = NULL;
1130 * If we have an ephemeral id, ACL, or XVATTR then
1131 * make sure file system is at proper version
1134 if (zfsvfs->z_use_fuids == B_FALSE &&
1135 (vsecp || (vap->va_mask & AT_XVATTR) ||
1136 IS_EPHEMERAL(crgetuid(cr)) || IS_EPHEMERAL(crgetgid(cr))))
1142 zilog = zfsvfs->z_log;
1144 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
1145 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1150 if (vap->va_mask & AT_XVATTR) {
1151 if ((error = secpolicy_xvattr((xvattr_t *)vap,
1152 crgetuid(cr), cr, vap->va_type)) != 0) {
1160 if ((vap->va_mode & VSVTX) && secpolicy_vnode_stky_modify(cr))
1161 vap->va_mode &= ~VSVTX;
1163 if (*name == '\0') {
1165 * Null component name refers to the directory itself.
1172 /* possible VN_HOLD(zp) */
1175 if (flag & FIGNORECASE)
1178 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1181 if (strcmp(name, "..") == 0)
1189 if (vsecp && aclp == NULL) {
1190 error = zfs_vsec_2_aclp(zfsvfs, vap->va_type, vsecp, &aclp);
1194 zfs_dirent_unlock(dl);
1203 * Create a new file object and update the directory
1206 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
1211 * We only support the creation of regular files in
1212 * extended attribute directories.
1214 if ((dzp->z_phys->zp_flags & ZFS_XATTR) &&
1215 (vap->va_type != VREG)) {
1220 tx = dmu_tx_create(os);
1221 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1222 if ((aclp && aclp->z_has_fuids) || IS_EPHEMERAL(crgetuid(cr)) ||
1223 IS_EPHEMERAL(crgetgid(cr))) {
1224 if (zfsvfs->z_fuid_obj == 0) {
1225 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1226 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
1227 FUID_SIZE_ESTIMATE(zfsvfs));
1228 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ,
1231 dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj);
1232 dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0,
1233 FUID_SIZE_ESTIMATE(zfsvfs));
1236 dmu_tx_hold_bonus(tx, dzp->z_id);
1237 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
1238 if ((dzp->z_phys->zp_flags & ZFS_INHERIT_ACE) || aclp) {
1239 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
1240 0, SPA_MAXBLOCKSIZE);
1242 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1244 zfs_dirent_unlock(dl);
1245 if (error == ERESTART &&
1246 zfsvfs->z_assign == TXG_NOWAIT) {
1257 zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, aclp, &fuidp);
1258 (void) zfs_link_create(dl, zp, tx, ZNEW);
1259 txtype = zfs_log_create_txtype(Z_FILE, vsecp, vap);
1260 if (flag & FIGNORECASE)
1262 zfs_log_create(zilog, tx, txtype, dzp, zp, name,
1265 zfs_fuid_info_free(fuidp);
1268 int aflags = (flag & FAPPEND) ? V_APPEND : 0;
1271 * A directory entry already exists for this name.
1274 * Can't truncate an existing file if in exclusive mode.
1281 * Can't open a directory for writing.
1283 if ((ZTOV(zp)->v_type == VDIR) && (mode & S_IWRITE)) {
1288 * Verify requested access to file.
1290 if (mode && (error = zfs_zaccess_rwx(zp, mode, aflags, cr))) {
1294 mutex_enter(&dzp->z_lock);
1296 mutex_exit(&dzp->z_lock);
1299 * Truncate regular files if requested.
1301 if ((ZTOV(zp)->v_type == VREG) &&
1302 (vap->va_mask & AT_SIZE) && (vap->va_size == 0)) {
1303 error = zfs_freesp(zp, 0, 0, mode, TRUE);
1304 if (error == ERESTART &&
1305 zfsvfs->z_assign == TXG_NOWAIT) {
1306 /* NB: we already did dmu_tx_wait() */
1307 zfs_dirent_unlock(dl);
1313 vnevent_create(ZTOV(zp), ct);
1320 zfs_dirent_unlock(dl);
1328 * If vnode is for a device return a specfs vnode instead.
1330 if (IS_DEVVP(*vpp)) {
1333 svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
1349 * Remove an entry from a directory.
1351 * IN: dvp - vnode of directory to remove entry from.
1352 * name - name of entry to remove.
1353 * cr - credentials of caller.
1354 * ct - caller context
1355 * flags - case flags
1357 * RETURN: 0 if success
1358 * error code if failure
1362 * vp - ctime (if nlink > 0)
1366 zfs_remove(vnode_t *dvp, char *name, cred_t *cr, caller_context_t *ct,
1369 znode_t *zp, *dzp = VTOZ(dvp);
1370 znode_t *xzp = NULL;
1372 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1374 uint64_t acl_obj, xattr_obj;
1377 boolean_t may_delete_now, delete_now = FALSE;
1380 pathname_t *realnmp = NULL;
1387 zilog = zfsvfs->z_log;
1389 if (flags & FIGNORECASE) {
1397 * Attempt to lock directory; fail if entry doesn't exist.
1399 if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1409 if (error = zfs_zaccess_delete(dzp, zp, cr)) {
1414 * Need to use rmdir for removing directories.
1416 if (vp->v_type == VDIR) {
1421 vnevent_remove(vp, dvp, name, ct);
1424 dnlc_remove(dvp, realnmp->pn_buf);
1426 dnlc_remove(dvp, name);
1428 mutex_enter(&vp->v_lock);
1429 may_delete_now = vp->v_count == 1 && !vn_has_cached_data(vp);
1430 mutex_exit(&vp->v_lock);
1433 * We may delete the znode now, or we may put it in the unlinked set;
1434 * it depends on whether we're the last link, and on whether there are
1435 * other holds on the vnode. So we dmu_tx_hold() the right things to
1436 * allow for either case.
1438 tx = dmu_tx_create(zfsvfs->z_os);
1439 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1440 dmu_tx_hold_bonus(tx, zp->z_id);
1442 dmu_tx_hold_free(tx, zp->z_id, 0, DMU_OBJECT_END);
1444 /* are there any extended attributes? */
1445 if ((xattr_obj = zp->z_phys->zp_xattr) != 0) {
1446 /* XXX - do we need this if we are deleting? */
1447 dmu_tx_hold_bonus(tx, xattr_obj);
1450 /* are there any additional acls */
1451 if ((acl_obj = zp->z_phys->zp_acl.z_acl_extern_obj) != 0 &&
1453 dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END);
1455 /* charge as an update -- would be nice not to charge at all */
1456 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1458 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1460 zfs_dirent_unlock(dl);
1462 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
1475 * Remove the directory entry.
1477 error = zfs_link_destroy(dl, zp, tx, zflg, &unlinked);
1485 mutex_enter(&vp->v_lock);
1486 delete_now = may_delete_now &&
1487 vp->v_count == 1 && !vn_has_cached_data(vp) &&
1488 zp->z_phys->zp_xattr == xattr_obj &&
1489 zp->z_phys->zp_acl.z_acl_extern_obj == acl_obj;
1490 mutex_exit(&vp->v_lock);
1494 if (zp->z_phys->zp_xattr) {
1495 error = zfs_zget(zfsvfs, zp->z_phys->zp_xattr, &xzp);
1496 ASSERT3U(error, ==, 0);
1497 ASSERT3U(xzp->z_phys->zp_links, ==, 2);
1498 dmu_buf_will_dirty(xzp->z_dbuf, tx);
1499 mutex_enter(&xzp->z_lock);
1500 xzp->z_unlinked = 1;
1501 xzp->z_phys->zp_links = 0;
1502 mutex_exit(&xzp->z_lock);
1503 zfs_unlinked_add(xzp, tx);
1504 zp->z_phys->zp_xattr = 0; /* probably unnecessary */
1506 mutex_enter(&zp->z_lock);
1507 mutex_enter(&vp->v_lock);
1509 ASSERT3U(vp->v_count, ==, 0);
1510 mutex_exit(&vp->v_lock);
1511 mutex_exit(&zp->z_lock);
1512 zfs_znode_delete(zp, tx);
1513 } else if (unlinked) {
1514 zfs_unlinked_add(zp, tx);
1518 if (flags & FIGNORECASE)
1520 zfs_log_remove(zilog, tx, txtype, dzp, name);
1527 zfs_dirent_unlock(dl);
1532 /* this rele delayed to prevent nesting transactions */
1541 * Create a new directory and insert it into dvp using the name
1542 * provided. Return a pointer to the inserted directory.
1544 * IN: dvp - vnode of directory to add subdir to.
1545 * dirname - name of new directory.
1546 * vap - attributes of new directory.
1547 * cr - credentials of caller.
1548 * ct - caller context
1549 * vsecp - ACL to be set
1551 * OUT: vpp - vnode of created directory.
1553 * RETURN: 0 if success
1554 * error code if failure
1557 * dvp - ctime|mtime updated
1558 * vp - ctime|mtime|atime updated
1562 zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr,
1563 caller_context_t *ct, int flags, vsecattr_t *vsecp)
1565 znode_t *zp, *dzp = VTOZ(dvp);
1566 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1572 zfs_acl_t *aclp = NULL;
1573 zfs_fuid_info_t *fuidp = NULL;
1576 ASSERT(vap->va_type == VDIR);
1579 * If we have an ephemeral id, ACL, or XVATTR then
1580 * make sure file system is at proper version
1583 if (zfsvfs->z_use_fuids == B_FALSE &&
1584 (vsecp || (vap->va_mask & AT_XVATTR) || IS_EPHEMERAL(crgetuid(cr))||
1585 IS_EPHEMERAL(crgetgid(cr))))
1590 zilog = zfsvfs->z_log;
1592 if (dzp->z_phys->zp_flags & ZFS_XATTR) {
1597 if (zfsvfs->z_utf8 && u8_validate(dirname,
1598 strlen(dirname), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1602 if (flags & FIGNORECASE)
1605 if (vap->va_mask & AT_XVATTR)
1606 if ((error = secpolicy_xvattr((xvattr_t *)vap,
1607 crgetuid(cr), cr, vap->va_type)) != 0) {
1613 * First make sure the new directory doesn't exist.
1618 if (error = zfs_dirent_lock(&dl, dzp, dirname, &zp, zf,
1624 if (error = zfs_zaccess(dzp, ACE_ADD_SUBDIRECTORY, 0, B_FALSE, cr)) {
1625 zfs_dirent_unlock(dl);
1630 if (vsecp && aclp == NULL) {
1631 error = zfs_vsec_2_aclp(zfsvfs, vap->va_type, vsecp, &aclp);
1633 zfs_dirent_unlock(dl);
1639 * Add a new entry to the directory.
1641 tx = dmu_tx_create(zfsvfs->z_os);
1642 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, dirname);
1643 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
1644 if ((aclp && aclp->z_has_fuids) || IS_EPHEMERAL(crgetuid(cr)) ||
1645 IS_EPHEMERAL(crgetgid(cr))) {
1646 if (zfsvfs->z_fuid_obj == 0) {
1647 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1648 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
1649 FUID_SIZE_ESTIMATE(zfsvfs));
1650 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, FALSE, NULL);
1652 dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj);
1653 dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0,
1654 FUID_SIZE_ESTIMATE(zfsvfs));
1657 if ((dzp->z_phys->zp_flags & ZFS_INHERIT_ACE) || aclp)
1658 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
1659 0, SPA_MAXBLOCKSIZE);
1660 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1662 zfs_dirent_unlock(dl);
1663 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
1678 zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, aclp, &fuidp);
1684 * Now put new name in parent dir.
1686 (void) zfs_link_create(dl, zp, tx, ZNEW);
1690 txtype = zfs_log_create_txtype(Z_DIR, vsecp, vap);
1691 if (flags & FIGNORECASE)
1693 zfs_log_create(zilog, tx, txtype, dzp, zp, dirname, vsecp, fuidp, vap);
1696 zfs_fuid_info_free(fuidp);
1699 zfs_dirent_unlock(dl);
1706 * Remove a directory subdir entry. If the current working
1707 * directory is the same as the subdir to be removed, the
1710 * IN: dvp - vnode of directory to remove from.
1711 * name - name of directory to be removed.
1712 * cwd - vnode of current working directory.
1713 * cr - credentials of caller.
1714 * ct - caller context
1715 * flags - case flags
1717 * RETURN: 0 if success
1718 * error code if failure
1721 * dvp - ctime|mtime updated
1725 zfs_rmdir(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr,
1726 caller_context_t *ct, int flags)
1728 znode_t *dzp = VTOZ(dvp);
1731 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1740 zilog = zfsvfs->z_log;
1742 if (flags & FIGNORECASE)
1748 * Attempt to lock directory; fail if entry doesn't exist.
1750 if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1758 if (error = zfs_zaccess_delete(dzp, zp, cr)) {
1762 if (vp->v_type != VDIR) {
1772 vnevent_rmdir(vp, dvp, name, ct);
1775 * Grab a lock on the directory to make sure that noone is
1776 * trying to add (or lookup) entries while we are removing it.
1778 rw_enter(&zp->z_name_lock, RW_WRITER);
1781 * Grab a lock on the parent pointer to make sure we play well
1782 * with the treewalk and directory rename code.
1784 rw_enter(&zp->z_parent_lock, RW_WRITER);
1786 tx = dmu_tx_create(zfsvfs->z_os);
1787 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1788 dmu_tx_hold_bonus(tx, zp->z_id);
1789 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1790 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1792 rw_exit(&zp->z_parent_lock);
1793 rw_exit(&zp->z_name_lock);
1794 zfs_dirent_unlock(dl);
1796 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
1806 error = zfs_link_destroy(dl, zp, tx, zflg, NULL);
1809 uint64_t txtype = TX_RMDIR;
1810 if (flags & FIGNORECASE)
1812 zfs_log_remove(zilog, tx, txtype, dzp, name);
1817 rw_exit(&zp->z_parent_lock);
1818 rw_exit(&zp->z_name_lock);
1820 zfs_dirent_unlock(dl);
1829 * Read as many directory entries as will fit into the provided
1830 * buffer from the given directory cursor position (specified in
1831 * the uio structure.
1833 * IN: vp - vnode of directory to read.
1834 * uio - structure supplying read location, range info,
1835 * and return buffer.
1836 * cr - credentials of caller.
1837 * ct - caller context
1838 * flags - case flags
1840 * OUT: uio - updated offset and range, buffer filled.
1841 * eofp - set to true if end-of-file detected.
1843 * RETURN: 0 if success
1844 * error code if failure
1847 * vp - atime updated
1849 * Note that the low 4 bits of the cookie returned by zap is always zero.
1850 * This allows us to use the low range for "special" directory entries:
1851 * We use 0 for '.', and 1 for '..'. If this is the root of the filesystem,
1852 * we use the offset 2 for the '.zfs' directory.
1856 zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp,
1857 caller_context_t *ct, int flags)
1859 znode_t *zp = VTOZ(vp);
1863 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1868 zap_attribute_t zap;
1869 uint_t bytes_wanted;
1870 uint64_t offset; /* must be unsigned; checks for < 1 */
1875 boolean_t check_sysattrs;
1881 * If we are not given an eof variable,
1888 * Check for valid iov_len.
1890 if (uio->uio_iov->iov_len <= 0) {
1896 * Quit if directory has been removed (posix)
1898 if ((*eofp = zp->z_unlinked) != 0) {
1905 offset = uio->uio_loffset;
1906 prefetch = zp->z_zn_prefetch;
1909 * Initialize the iterator cursor.
1913 * Start iteration from the beginning of the directory.
1915 zap_cursor_init(&zc, os, zp->z_id);
1918 * The offset is a serialized cursor.
1920 zap_cursor_init_serialized(&zc, os, zp->z_id, offset);
1924 * Get space to change directory entries into fs independent format.
1926 iovp = uio->uio_iov;
1927 bytes_wanted = iovp->iov_len;
1928 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) {
1929 bufsize = bytes_wanted;
1930 outbuf = kmem_alloc(bufsize, KM_SLEEP);
1931 odp = (struct dirent64 *)outbuf;
1933 bufsize = bytes_wanted;
1934 odp = (struct dirent64 *)iovp->iov_base;
1936 eodp = (struct edirent *)odp;
1939 * If this VFS supports system attributes; and we're looking at an
1940 * extended attribute directory; and we care about normalization
1941 * conflicts on this vfs; then we must check for normalization
1942 * conflicts with the sysattr name space.
1944 check_sysattrs = vfs_has_feature(vp->v_vfsp, VFSFT_XVATTR) &&
1945 (vp->v_flag & V_XATTRDIR) && zfsvfs->z_norm &&
1946 (flags & V_RDDIR_ENTFLAGS);
1949 * Transform to file-system independent format
1952 while (outcount < bytes_wanted) {
1958 * Special case `.', `..', and `.zfs'.
1961 (void) strcpy(zap.za_name, ".");
1962 zap.za_normalization_conflict = 0;
1964 } else if (offset == 1) {
1965 (void) strcpy(zap.za_name, "..");
1966 zap.za_normalization_conflict = 0;
1967 objnum = zp->z_phys->zp_parent;
1968 } else if (offset == 2 && zfs_show_ctldir(zp)) {
1969 (void) strcpy(zap.za_name, ZFS_CTLDIR_NAME);
1970 zap.za_normalization_conflict = 0;
1971 objnum = ZFSCTL_INO_ROOT;
1976 if (error = zap_cursor_retrieve(&zc, &zap)) {
1977 if ((*eofp = (error == ENOENT)) != 0)
1983 if (zap.za_integer_length != 8 ||
1984 zap.za_num_integers != 1) {
1985 cmn_err(CE_WARN, "zap_readdir: bad directory "
1986 "entry, obj = %lld, offset = %lld\n",
1987 (u_longlong_t)zp->z_id,
1988 (u_longlong_t)offset);
1993 objnum = ZFS_DIRENT_OBJ(zap.za_first_integer);
1995 * MacOS X can extract the object type here such as:
1996 * uint8_t type = ZFS_DIRENT_TYPE(zap.za_first_integer);
1999 if (check_sysattrs && !zap.za_normalization_conflict) {
2000 zap.za_normalization_conflict =
2001 xattr_sysattr_casechk(zap.za_name);
2005 if (flags & V_RDDIR_ENTFLAGS)
2006 reclen = EDIRENT_RECLEN(strlen(zap.za_name));
2008 reclen = DIRENT64_RECLEN(strlen(zap.za_name));
2011 * Will this entry fit in the buffer?
2013 if (outcount + reclen > bufsize) {
2015 * Did we manage to fit anything in the buffer?
2023 if (flags & V_RDDIR_ENTFLAGS) {
2025 * Add extended flag entry:
2027 eodp->ed_ino = objnum;
2028 eodp->ed_reclen = reclen;
2029 /* NOTE: ed_off is the offset for the *next* entry */
2030 next = &(eodp->ed_off);
2031 eodp->ed_eflags = zap.za_normalization_conflict ?
2032 ED_CASE_CONFLICT : 0;
2033 (void) strncpy(eodp->ed_name, zap.za_name,
2034 EDIRENT_NAMELEN(reclen));
2035 eodp = (edirent_t *)((intptr_t)eodp + reclen);
2040 odp->d_ino = objnum;
2041 odp->d_reclen = reclen;
2042 /* NOTE: d_off is the offset for the *next* entry */
2043 next = &(odp->d_off);
2044 (void) strncpy(odp->d_name, zap.za_name,
2045 DIRENT64_NAMELEN(reclen));
2046 odp = (dirent64_t *)((intptr_t)odp + reclen);
2050 ASSERT(outcount <= bufsize);
2052 /* Prefetch znode */
2054 dmu_prefetch(os, objnum, 0, 0);
2057 * Move to the next entry, fill in the previous offset.
2059 if (offset > 2 || (offset == 2 && !zfs_show_ctldir(zp))) {
2060 zap_cursor_advance(&zc);
2061 offset = zap_cursor_serialize(&zc);
2067 zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */
2069 if (uio->uio_segflg == UIO_SYSSPACE && uio->uio_iovcnt == 1) {
2070 iovp->iov_base += outcount;
2071 iovp->iov_len -= outcount;
2072 uio->uio_resid -= outcount;
2073 } else if (error = uiomove(outbuf, (long)outcount, UIO_READ, uio)) {
2075 * Reset the pointer.
2077 offset = uio->uio_loffset;
2081 zap_cursor_fini(&zc);
2082 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
2083 kmem_free(outbuf, bufsize);
2085 if (error == ENOENT)
2088 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
2090 uio->uio_loffset = offset;
2095 ulong_t zfs_fsync_sync_cnt = 4;
2098 zfs_fsync(vnode_t *vp, int syncflag, cred_t *cr, caller_context_t *ct)
2100 znode_t *zp = VTOZ(vp);
2101 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2104 * Regardless of whether this is required for standards conformance,
2105 * this is the logical behavior when fsync() is called on a file with
2106 * dirty pages. We use B_ASYNC since the ZIL transactions are already
2107 * going to be pushed out as part of the zil_commit().
2109 if (vn_has_cached_data(vp) && !(syncflag & FNODSYNC) &&
2110 (vp->v_type == VREG) && !(IS_SWAPVP(vp)))
2111 (void) VOP_PUTPAGE(vp, (offset_t)0, (size_t)0, B_ASYNC, cr, ct);
2113 (void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt);
2117 zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
2124 * Get the requested file attributes and place them in the provided
2127 * IN: vp - vnode of file.
2128 * vap - va_mask identifies requested attributes.
2129 * If AT_XVATTR set, then optional attrs are requested
2130 * flags - ATTR_NOACLCHECK (CIFS server context)
2131 * cr - credentials of caller.
2132 * ct - caller context
2134 * OUT: vap - attribute values.
2136 * RETURN: 0 (always succeeds)
2140 zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2141 caller_context_t *ct)
2143 znode_t *zp = VTOZ(vp);
2144 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2148 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2149 xoptattr_t *xoap = NULL;
2150 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2156 mutex_enter(&zp->z_lock);
2159 * If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES.
2160 * Also, if we are the owner don't bother, since owner should
2161 * always be allowed to read basic attributes of file.
2163 if (!(pzp->zp_flags & ZFS_ACL_TRIVIAL) &&
2164 (pzp->zp_uid != crgetuid(cr))) {
2165 if (error = zfs_zaccess(zp, ACE_READ_ATTRIBUTES, 0,
2167 mutex_exit(&zp->z_lock);
2174 * Return all attributes. It's cheaper to provide the answer
2175 * than to determine whether we were asked the question.
2178 vap->va_type = vp->v_type;
2179 vap->va_mode = pzp->zp_mode & MODEMASK;
2180 zfs_fuid_map_ids(zp, cr, &vap->va_uid, &vap->va_gid);
2181 vap->va_fsid = zp->z_zfsvfs->z_vfs->vfs_dev;
2182 vap->va_nodeid = zp->z_id;
2183 if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp))
2184 links = pzp->zp_links + 1;
2186 links = pzp->zp_links;
2187 vap->va_nlink = MIN(links, UINT32_MAX); /* nlink_t limit! */
2188 vap->va_size = pzp->zp_size;
2189 vap->va_rdev = vp->v_rdev;
2190 vap->va_seq = zp->z_seq;
2193 * Add in any requested optional attributes and the create time.
2194 * Also set the corresponding bits in the returned attribute bitmap.
2196 if ((xoap = xva_getxoptattr(xvap)) != NULL && zfsvfs->z_use_fuids) {
2197 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
2199 ((pzp->zp_flags & ZFS_ARCHIVE) != 0);
2200 XVA_SET_RTN(xvap, XAT_ARCHIVE);
2203 if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
2204 xoap->xoa_readonly =
2205 ((pzp->zp_flags & ZFS_READONLY) != 0);
2206 XVA_SET_RTN(xvap, XAT_READONLY);
2209 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
2211 ((pzp->zp_flags & ZFS_SYSTEM) != 0);
2212 XVA_SET_RTN(xvap, XAT_SYSTEM);
2215 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
2217 ((pzp->zp_flags & ZFS_HIDDEN) != 0);
2218 XVA_SET_RTN(xvap, XAT_HIDDEN);
2221 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
2222 xoap->xoa_nounlink =
2223 ((pzp->zp_flags & ZFS_NOUNLINK) != 0);
2224 XVA_SET_RTN(xvap, XAT_NOUNLINK);
2227 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
2228 xoap->xoa_immutable =
2229 ((pzp->zp_flags & ZFS_IMMUTABLE) != 0);
2230 XVA_SET_RTN(xvap, XAT_IMMUTABLE);
2233 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
2234 xoap->xoa_appendonly =
2235 ((pzp->zp_flags & ZFS_APPENDONLY) != 0);
2236 XVA_SET_RTN(xvap, XAT_APPENDONLY);
2239 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
2241 ((pzp->zp_flags & ZFS_NODUMP) != 0);
2242 XVA_SET_RTN(xvap, XAT_NODUMP);
2245 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
2247 ((pzp->zp_flags & ZFS_OPAQUE) != 0);
2248 XVA_SET_RTN(xvap, XAT_OPAQUE);
2251 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
2252 xoap->xoa_av_quarantined =
2253 ((pzp->zp_flags & ZFS_AV_QUARANTINED) != 0);
2254 XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
2257 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
2258 xoap->xoa_av_modified =
2259 ((pzp->zp_flags & ZFS_AV_MODIFIED) != 0);
2260 XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
2263 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) &&
2264 vp->v_type == VREG &&
2265 (pzp->zp_flags & ZFS_BONUS_SCANSTAMP)) {
2267 dmu_object_info_t doi;
2270 * Only VREG files have anti-virus scanstamps, so we
2271 * won't conflict with symlinks in the bonus buffer.
2273 dmu_object_info_from_db(zp->z_dbuf, &doi);
2274 len = sizeof (xoap->xoa_av_scanstamp) +
2275 sizeof (znode_phys_t);
2276 if (len <= doi.doi_bonus_size) {
2278 * pzp points to the start of the
2279 * znode_phys_t. pzp + 1 points to the
2280 * first byte after the znode_phys_t.
2282 (void) memcpy(xoap->xoa_av_scanstamp,
2284 sizeof (xoap->xoa_av_scanstamp));
2285 XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
2289 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
2290 ZFS_TIME_DECODE(&xoap->xoa_createtime, pzp->zp_crtime);
2291 XVA_SET_RTN(xvap, XAT_CREATETIME);
2295 ZFS_TIME_DECODE(&vap->va_atime, pzp->zp_atime);
2296 ZFS_TIME_DECODE(&vap->va_mtime, pzp->zp_mtime);
2297 ZFS_TIME_DECODE(&vap->va_ctime, pzp->zp_ctime);
2299 mutex_exit(&zp->z_lock);
2301 dmu_object_size_from_db(zp->z_dbuf, &vap->va_blksize, &vap->va_nblocks);
2303 if (zp->z_blksz == 0) {
2305 * Block size hasn't been set; suggest maximal I/O transfers.
2307 vap->va_blksize = zfsvfs->z_max_blksz;
2315 * Set the file attributes to the values contained in the
2318 * IN: vp - vnode of file to be modified.
2319 * vap - new attribute values.
2320 * If AT_XVATTR set, then optional attrs are being set
2321 * flags - ATTR_UTIME set if non-default time values provided.
2322 * - ATTR_NOACLCHECK (CIFS context only).
2323 * cr - credentials of caller.
2324 * ct - caller context
2326 * RETURN: 0 if success
2327 * error code if failure
2330 * vp - ctime updated, mtime updated if size changed.
2334 zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2335 caller_context_t *ct)
2337 znode_t *zp = VTOZ(vp);
2339 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2343 uint_t mask = vap->va_mask;
2348 int need_policy = FALSE;
2350 zfs_fuid_info_t *fuidp = NULL;
2351 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2353 zfs_acl_t *aclp = NULL;
2354 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2359 if (mask & AT_NOSET)
2366 zilog = zfsvfs->z_log;
2369 * Make sure that if we have ephemeral uid/gid or xvattr specified
2370 * that file system is at proper version level
2373 if (zfsvfs->z_use_fuids == B_FALSE &&
2374 (((mask & AT_UID) && IS_EPHEMERAL(vap->va_uid)) ||
2375 ((mask & AT_GID) && IS_EPHEMERAL(vap->va_gid)) ||
2376 (mask & AT_XVATTR))) {
2381 if (mask & AT_SIZE && vp->v_type == VDIR) {
2386 if (mask & AT_SIZE && vp->v_type != VREG && vp->v_type != VFIFO) {
2392 * If this is an xvattr_t, then get a pointer to the structure of
2393 * optional attributes. If this is NULL, then we have a vattr_t.
2395 xoap = xva_getxoptattr(xvap);
2398 * Immutable files can only alter immutable bit and atime
2400 if ((pzp->zp_flags & ZFS_IMMUTABLE) &&
2401 ((mask & (AT_SIZE|AT_UID|AT_GID|AT_MTIME|AT_MODE)) ||
2402 ((mask & AT_XVATTR) && XVA_ISSET_REQ(xvap, XAT_CREATETIME)))) {
2407 if ((mask & AT_SIZE) && (pzp->zp_flags & ZFS_READONLY)) {
2413 * Verify timestamps doesn't overflow 32 bits.
2414 * ZFS can handle large timestamps, but 32bit syscalls can't
2415 * handle times greater than 2039. This check should be removed
2416 * once large timestamps are fully supported.
2418 if (mask & (AT_ATIME | AT_MTIME)) {
2419 if (((mask & AT_ATIME) && TIMESPEC_OVERFLOW(&vap->va_atime)) ||
2420 ((mask & AT_MTIME) && TIMESPEC_OVERFLOW(&vap->va_mtime))) {
2429 if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) {
2435 * First validate permissions
2438 if (mask & AT_SIZE) {
2439 err = zfs_zaccess(zp, ACE_WRITE_DATA, 0, skipaclchk, cr);
2445 * XXX - Note, we are not providing any open
2446 * mode flags here (like FNDELAY), so we may
2447 * block if there are locks present... this
2448 * should be addressed in openat().
2451 err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE);
2452 /* NB: we already did dmu_tx_wait() if necessary */
2453 } while (err == ERESTART && zfsvfs->z_assign == TXG_NOWAIT);
2460 if (mask & (AT_ATIME|AT_MTIME) ||
2461 ((mask & AT_XVATTR) && (XVA_ISSET_REQ(xvap, XAT_HIDDEN) ||
2462 XVA_ISSET_REQ(xvap, XAT_READONLY) ||
2463 XVA_ISSET_REQ(xvap, XAT_ARCHIVE) ||
2464 XVA_ISSET_REQ(xvap, XAT_CREATETIME) ||
2465 XVA_ISSET_REQ(xvap, XAT_SYSTEM))))
2466 need_policy = zfs_zaccess(zp, ACE_WRITE_ATTRIBUTES, 0,
2469 if (mask & (AT_UID|AT_GID)) {
2470 int idmask = (mask & (AT_UID|AT_GID));
2475 * NOTE: even if a new mode is being set,
2476 * we may clear S_ISUID/S_ISGID bits.
2479 if (!(mask & AT_MODE))
2480 vap->va_mode = pzp->zp_mode;
2483 * Take ownership or chgrp to group we are a member of
2486 take_owner = (mask & AT_UID) && (vap->va_uid == crgetuid(cr));
2487 take_group = (mask & AT_GID) &&
2488 zfs_groupmember(zfsvfs, vap->va_gid, cr);
2491 * If both AT_UID and AT_GID are set then take_owner and
2492 * take_group must both be set in order to allow taking
2495 * Otherwise, send the check through secpolicy_vnode_setattr()
2499 if (((idmask == (AT_UID|AT_GID)) && take_owner && take_group) ||
2500 ((idmask == AT_UID) && take_owner) ||
2501 ((idmask == AT_GID) && take_group)) {
2502 if (zfs_zaccess(zp, ACE_WRITE_OWNER, 0,
2503 skipaclchk, cr) == 0) {
2505 * Remove setuid/setgid for non-privileged users
2507 secpolicy_setid_clear(vap, cr);
2508 trim_mask = (mask & (AT_UID|AT_GID));
2517 mutex_enter(&zp->z_lock);
2518 oldva.va_mode = pzp->zp_mode;
2519 zfs_fuid_map_ids(zp, cr, &oldva.va_uid, &oldva.va_gid);
2520 if (mask & AT_XVATTR) {
2521 if ((need_policy == FALSE) &&
2522 (XVA_ISSET_REQ(xvap, XAT_APPENDONLY) &&
2523 xoap->xoa_appendonly !=
2524 ((pzp->zp_flags & ZFS_APPENDONLY) != 0)) ||
2525 (XVA_ISSET_REQ(xvap, XAT_NOUNLINK) &&
2526 xoap->xoa_nounlink !=
2527 ((pzp->zp_flags & ZFS_NOUNLINK) != 0)) ||
2528 (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE) &&
2529 xoap->xoa_immutable !=
2530 ((pzp->zp_flags & ZFS_IMMUTABLE) != 0)) ||
2531 (XVA_ISSET_REQ(xvap, XAT_NODUMP) &&
2533 ((pzp->zp_flags & ZFS_NODUMP) != 0)) ||
2534 (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED) &&
2535 xoap->xoa_av_modified !=
2536 ((pzp->zp_flags & ZFS_AV_MODIFIED) != 0)) ||
2537 ((XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED) &&
2538 ((vp->v_type != VREG && xoap->xoa_av_quarantined) ||
2539 xoap->xoa_av_quarantined !=
2540 ((pzp->zp_flags & ZFS_AV_QUARANTINED) != 0)))) ||
2541 (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) ||
2542 (XVA_ISSET_REQ(xvap, XAT_OPAQUE))) {
2547 mutex_exit(&zp->z_lock);
2549 if (mask & AT_MODE) {
2550 if (zfs_zaccess(zp, ACE_WRITE_ACL, 0, skipaclchk, cr) == 0) {
2551 err = secpolicy_setid_setsticky_clear(vp, vap,
2557 trim_mask |= AT_MODE;
2565 * If trim_mask is set then take ownership
2566 * has been granted or write_acl is present and user
2567 * has the ability to modify mode. In that case remove
2568 * UID|GID and or MODE from mask so that
2569 * secpolicy_vnode_setattr() doesn't revoke it.
2573 saved_mask = vap->va_mask;
2574 vap->va_mask &= ~trim_mask;
2576 err = secpolicy_vnode_setattr(cr, vp, vap, &oldva, flags,
2577 (int (*)(void *, int, cred_t *))zfs_zaccess_unix, zp);
2584 vap->va_mask |= saved_mask;
2588 * secpolicy_vnode_setattr, or take ownership may have
2591 mask = vap->va_mask;
2593 tx = dmu_tx_create(zfsvfs->z_os);
2594 dmu_tx_hold_bonus(tx, zp->z_id);
2595 if (((mask & AT_UID) && IS_EPHEMERAL(vap->va_uid)) ||
2596 ((mask & AT_GID) && IS_EPHEMERAL(vap->va_gid))) {
2597 if (zfsvfs->z_fuid_obj == 0) {
2598 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
2599 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
2600 FUID_SIZE_ESTIMATE(zfsvfs));
2601 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, FALSE, NULL);
2603 dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj);
2604 dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0,
2605 FUID_SIZE_ESTIMATE(zfsvfs));
2609 if (mask & AT_MODE) {
2610 uint64_t pmode = pzp->zp_mode;
2612 new_mode = (pmode & S_IFMT) | (vap->va_mode & ~S_IFMT);
2614 if (err = zfs_acl_chmod_setattr(zp, &aclp, new_mode)) {
2619 if (pzp->zp_acl.z_acl_extern_obj) {
2620 /* Are we upgrading ACL from old V0 format to new V1 */
2621 if (zfsvfs->z_version <= ZPL_VERSION_FUID &&
2622 pzp->zp_acl.z_acl_version ==
2623 ZFS_ACL_VERSION_INITIAL) {
2624 dmu_tx_hold_free(tx,
2625 pzp->zp_acl.z_acl_extern_obj, 0,
2627 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
2628 0, aclp->z_acl_bytes);
2630 dmu_tx_hold_write(tx,
2631 pzp->zp_acl.z_acl_extern_obj, 0,
2634 } else if (aclp->z_acl_bytes > ZFS_ACE_SPACE) {
2635 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
2636 0, aclp->z_acl_bytes);
2640 if ((mask & (AT_UID | AT_GID)) && pzp->zp_xattr != 0) {
2641 err = zfs_zget(zp->z_zfsvfs, pzp->zp_xattr, &attrzp);
2649 dmu_tx_hold_bonus(tx, attrzp->z_id);
2652 err = dmu_tx_assign(tx, zfsvfs->z_assign);
2655 VN_RELE(ZTOV(attrzp));
2662 if (err == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
2672 dmu_buf_will_dirty(zp->z_dbuf, tx);
2675 * Set each attribute requested.
2676 * We group settings according to the locks they need to acquire.
2678 * Note: you cannot set ctime directly, although it will be
2679 * updated as a side-effect of calling this function.
2682 mutex_enter(&zp->z_lock);
2684 if (mask & AT_MODE) {
2685 mutex_enter(&zp->z_acl_lock);
2686 zp->z_phys->zp_mode = new_mode;
2687 err = zfs_aclset_common(zp, aclp, cr, &fuidp, tx);
2688 ASSERT3U(err, ==, 0);
2689 mutex_exit(&zp->z_acl_lock);
2693 mutex_enter(&attrzp->z_lock);
2695 if (mask & AT_UID) {
2696 pzp->zp_uid = zfs_fuid_create(zfsvfs,
2697 vap->va_uid, cr, ZFS_OWNER, tx, &fuidp);
2699 attrzp->z_phys->zp_uid = zfs_fuid_create(zfsvfs,
2700 vap->va_uid, cr, ZFS_OWNER, tx, &fuidp);
2704 if (mask & AT_GID) {
2705 pzp->zp_gid = zfs_fuid_create(zfsvfs, vap->va_gid,
2706 cr, ZFS_GROUP, tx, &fuidp);
2708 attrzp->z_phys->zp_gid = zfs_fuid_create(zfsvfs,
2709 vap->va_gid, cr, ZFS_GROUP, tx, &fuidp);
2716 mutex_exit(&attrzp->z_lock);
2718 if (mask & AT_ATIME)
2719 ZFS_TIME_ENCODE(&vap->va_atime, pzp->zp_atime);
2721 if (mask & AT_MTIME)
2722 ZFS_TIME_ENCODE(&vap->va_mtime, pzp->zp_mtime);
2725 zfs_time_stamper_locked(zp, CONTENT_MODIFIED, tx);
2727 zfs_time_stamper_locked(zp, STATE_CHANGED, tx);
2729 * Do this after setting timestamps to prevent timestamp
2730 * update from toggling bit
2733 if (xoap && (mask & AT_XVATTR)) {
2734 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
2736 dmu_object_info_t doi;
2738 ASSERT(vp->v_type == VREG);
2740 /* Grow the bonus buffer if necessary. */
2741 dmu_object_info_from_db(zp->z_dbuf, &doi);
2742 len = sizeof (xoap->xoa_av_scanstamp) +
2743 sizeof (znode_phys_t);
2744 if (len > doi.doi_bonus_size)
2745 VERIFY(dmu_set_bonus(zp->z_dbuf, len, tx) == 0);
2747 zfs_xvattr_set(zp, xvap);
2751 zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp);
2754 zfs_fuid_info_free(fuidp);
2755 mutex_exit(&zp->z_lock);
2758 VN_RELE(ZTOV(attrzp));
2766 typedef struct zfs_zlock {
2767 krwlock_t *zl_rwlock; /* lock we acquired */
2768 znode_t *zl_znode; /* znode we held */
2769 struct zfs_zlock *zl_next; /* next in list */
2773 * Drop locks and release vnodes that were held by zfs_rename_lock().
2776 zfs_rename_unlock(zfs_zlock_t **zlpp)
2780 while ((zl = *zlpp) != NULL) {
2781 if (zl->zl_znode != NULL)
2782 VN_RELE(ZTOV(zl->zl_znode));
2783 rw_exit(zl->zl_rwlock);
2784 *zlpp = zl->zl_next;
2785 kmem_free(zl, sizeof (*zl));
2790 * Search back through the directory tree, using the ".." entries.
2791 * Lock each directory in the chain to prevent concurrent renames.
2792 * Fail any attempt to move a directory into one of its own descendants.
2793 * XXX - z_parent_lock can overlap with map or grow locks
2796 zfs_rename_lock(znode_t *szp, znode_t *tdzp, znode_t *sdzp, zfs_zlock_t **zlpp)
2800 uint64_t rootid = zp->z_zfsvfs->z_root;
2801 uint64_t *oidp = &zp->z_id;
2802 krwlock_t *rwlp = &szp->z_parent_lock;
2803 krw_t rw = RW_WRITER;
2806 * First pass write-locks szp and compares to zp->z_id.
2807 * Later passes read-lock zp and compare to zp->z_parent.
2810 if (!rw_tryenter(rwlp, rw)) {
2812 * Another thread is renaming in this path.
2813 * Note that if we are a WRITER, we don't have any
2814 * parent_locks held yet.
2816 if (rw == RW_READER && zp->z_id > szp->z_id) {
2818 * Drop our locks and restart
2820 zfs_rename_unlock(&zl);
2824 rwlp = &szp->z_parent_lock;
2829 * Wait for other thread to drop its locks
2835 zl = kmem_alloc(sizeof (*zl), KM_SLEEP);
2836 zl->zl_rwlock = rwlp;
2837 zl->zl_znode = NULL;
2838 zl->zl_next = *zlpp;
2841 if (*oidp == szp->z_id) /* We're a descendant of szp */
2844 if (*oidp == rootid) /* We've hit the top */
2847 if (rw == RW_READER) { /* i.e. not the first pass */
2848 int error = zfs_zget(zp->z_zfsvfs, *oidp, &zp);
2853 oidp = &zp->z_phys->zp_parent;
2854 rwlp = &zp->z_parent_lock;
2857 } while (zp->z_id != sdzp->z_id);
2863 * Move an entry from the provided source directory to the target
2864 * directory. Change the entry name as indicated.
2866 * IN: sdvp - Source directory containing the "old entry".
2867 * snm - Old entry name.
2868 * tdvp - Target directory to contain the "new entry".
2869 * tnm - New entry name.
2870 * cr - credentials of caller.
2871 * ct - caller context
2872 * flags - case flags
2874 * RETURN: 0 if success
2875 * error code if failure
2878 * sdvp,tdvp - ctime|mtime updated
2882 zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr,
2883 caller_context_t *ct, int flags)
2885 znode_t *tdzp, *szp, *tzp;
2886 znode_t *sdzp = VTOZ(sdvp);
2887 zfsvfs_t *zfsvfs = sdzp->z_zfsvfs;
2890 zfs_dirlock_t *sdl, *tdl;
2893 int cmp, serr, terr;
2898 ZFS_VERIFY_ZP(sdzp);
2899 zilog = zfsvfs->z_log;
2902 * Make sure we have the real vp for the target directory.
2904 if (VOP_REALVP(tdvp, &realvp, ct) == 0)
2907 if (tdvp->v_vfsp != sdvp->v_vfsp) {
2913 ZFS_VERIFY_ZP(tdzp);
2914 if (zfsvfs->z_utf8 && u8_validate(tnm,
2915 strlen(tnm), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
2920 if (flags & FIGNORECASE)
2929 * This is to prevent the creation of links into attribute space
2930 * by renaming a linked file into/outof an attribute directory.
2931 * See the comment in zfs_link() for why this is considered bad.
2933 if ((tdzp->z_phys->zp_flags & ZFS_XATTR) !=
2934 (sdzp->z_phys->zp_flags & ZFS_XATTR)) {
2940 * Lock source and target directory entries. To prevent deadlock,
2941 * a lock ordering must be defined. We lock the directory with
2942 * the smallest object id first, or if it's a tie, the one with
2943 * the lexically first name.
2945 if (sdzp->z_id < tdzp->z_id) {
2947 } else if (sdzp->z_id > tdzp->z_id) {
2951 * First compare the two name arguments without
2952 * considering any case folding.
2954 int nofold = (zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER);
2956 cmp = u8_strcmp(snm, tnm, 0, nofold, U8_UNICODE_LATEST, &error);
2957 ASSERT(error == 0 || !zfsvfs->z_utf8);
2960 * POSIX: "If the old argument and the new argument
2961 * both refer to links to the same existing file,
2962 * the rename() function shall return successfully
2963 * and perform no other action."
2969 * If the file system is case-folding, then we may
2970 * have some more checking to do. A case-folding file
2971 * system is either supporting mixed case sensitivity
2972 * access or is completely case-insensitive. Note
2973 * that the file system is always case preserving.
2975 * In mixed sensitivity mode case sensitive behavior
2976 * is the default. FIGNORECASE must be used to
2977 * explicitly request case insensitive behavior.
2979 * If the source and target names provided differ only
2980 * by case (e.g., a request to rename 'tim' to 'Tim'),
2981 * we will treat this as a special case in the
2982 * case-insensitive mode: as long as the source name
2983 * is an exact match, we will allow this to proceed as
2984 * a name-change request.
2986 if ((zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
2987 (zfsvfs->z_case == ZFS_CASE_MIXED &&
2988 flags & FIGNORECASE)) &&
2989 u8_strcmp(snm, tnm, 0, zfsvfs->z_norm, U8_UNICODE_LATEST,
2992 * case preserving rename request, require exact
3001 serr = zfs_dirent_lock(&sdl, sdzp, snm, &szp,
3002 ZEXISTS | zflg, NULL, NULL);
3003 terr = zfs_dirent_lock(&tdl,
3004 tdzp, tnm, &tzp, ZRENAMING | zflg, NULL, NULL);
3006 terr = zfs_dirent_lock(&tdl,
3007 tdzp, tnm, &tzp, zflg, NULL, NULL);
3008 serr = zfs_dirent_lock(&sdl,
3009 sdzp, snm, &szp, ZEXISTS | ZRENAMING | zflg,
3015 * Source entry invalid or not there.
3018 zfs_dirent_unlock(tdl);
3022 if (strcmp(snm, "..") == 0)
3028 zfs_dirent_unlock(sdl);
3030 if (strcmp(tnm, "..") == 0)
3037 * Must have write access at the source to remove the old entry
3038 * and write access at the target to create the new entry.
3039 * Note that if target and source are the same, this can be
3040 * done in a single check.
3043 if (error = zfs_zaccess_rename(sdzp, szp, tdzp, tzp, cr))
3046 if (ZTOV(szp)->v_type == VDIR) {
3048 * Check to make sure rename is valid.
3049 * Can't do a move like this: /usr/a/b to /usr/a/b/c/d
3051 if (error = zfs_rename_lock(szp, tdzp, sdzp, &zl))
3056 * Does target exist?
3060 * Source and target must be the same type.
3062 if (ZTOV(szp)->v_type == VDIR) {
3063 if (ZTOV(tzp)->v_type != VDIR) {
3068 if (ZTOV(tzp)->v_type == VDIR) {
3074 * POSIX dictates that when the source and target
3075 * entries refer to the same file object, rename
3076 * must do nothing and exit without error.
3078 if (szp->z_id == tzp->z_id) {
3084 vnevent_rename_src(ZTOV(szp), sdvp, snm, ct);
3086 vnevent_rename_dest(ZTOV(tzp), tdvp, tnm, ct);
3089 * notify the target directory if it is not the same
3090 * as source directory.
3093 vnevent_rename_dest_dir(tdvp, ct);
3096 tx = dmu_tx_create(zfsvfs->z_os);
3097 dmu_tx_hold_bonus(tx, szp->z_id); /* nlink changes */
3098 dmu_tx_hold_bonus(tx, sdzp->z_id); /* nlink changes */
3099 dmu_tx_hold_zap(tx, sdzp->z_id, FALSE, snm);
3100 dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, tnm);
3102 dmu_tx_hold_bonus(tx, tdzp->z_id); /* nlink changes */
3104 dmu_tx_hold_bonus(tx, tzp->z_id); /* parent changes */
3105 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
3106 error = dmu_tx_assign(tx, zfsvfs->z_assign);
3109 zfs_rename_unlock(&zl);
3110 zfs_dirent_unlock(sdl);
3111 zfs_dirent_unlock(tdl);
3115 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
3125 if (tzp) /* Attempt to remove the existing target */
3126 error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL);
3129 error = zfs_link_create(tdl, szp, tx, ZRENAMING);
3131 szp->z_phys->zp_flags |= ZFS_AV_MODIFIED;
3133 error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL);
3136 zfs_log_rename(zilog, tx,
3137 TX_RENAME | (flags & FIGNORECASE ? TX_CI : 0),
3138 sdzp, sdl->dl_name, tdzp, tdl->dl_name, szp);
3145 zfs_rename_unlock(&zl);
3147 zfs_dirent_unlock(sdl);
3148 zfs_dirent_unlock(tdl);
3159 * Insert the indicated symbolic reference entry into the directory.
3161 * IN: dvp - Directory to contain new symbolic link.
3162 * link - Name for new symlink entry.
3163 * vap - Attributes of new entry.
3164 * target - Target path of new symlink.
3165 * cr - credentials of caller.
3166 * ct - caller context
3167 * flags - case flags
3169 * RETURN: 0 if success
3170 * error code if failure
3173 * dvp - ctime|mtime updated
3177 zfs_symlink(vnode_t *dvp, char *name, vattr_t *vap, char *link, cred_t *cr,
3178 caller_context_t *ct, int flags)
3180 znode_t *zp, *dzp = VTOZ(dvp);
3183 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3185 int len = strlen(link);
3188 zfs_fuid_info_t *fuidp = NULL;
3190 ASSERT(vap->va_type == VLNK);
3194 zilog = zfsvfs->z_log;
3196 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
3197 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3201 if (flags & FIGNORECASE)
3204 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
3209 if (len > MAXPATHLEN) {
3211 return (ENAMETOOLONG);
3215 * Attempt to lock directory; fail if entry already exists.
3217 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, NULL, NULL);
3223 tx = dmu_tx_create(zfsvfs->z_os);
3224 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, MAX(1, len));
3225 dmu_tx_hold_bonus(tx, dzp->z_id);
3226 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
3227 if (dzp->z_phys->zp_flags & ZFS_INHERIT_ACE)
3228 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, SPA_MAXBLOCKSIZE);
3229 if (IS_EPHEMERAL(crgetuid(cr)) || IS_EPHEMERAL(crgetgid(cr))) {
3230 if (zfsvfs->z_fuid_obj == 0) {
3231 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
3232 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
3233 FUID_SIZE_ESTIMATE(zfsvfs));
3234 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, FALSE, NULL);
3236 dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj);
3237 dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0,
3238 FUID_SIZE_ESTIMATE(zfsvfs));
3241 error = dmu_tx_assign(tx, zfsvfs->z_assign);
3243 zfs_dirent_unlock(dl);
3244 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
3254 dmu_buf_will_dirty(dzp->z_dbuf, tx);
3257 * Create a new object for the symlink.
3258 * Put the link content into bonus buffer if it will fit;
3259 * otherwise, store it just like any other file data.
3261 if (sizeof (znode_phys_t) + len <= dmu_bonus_max()) {
3262 zfs_mknode(dzp, vap, tx, cr, 0, &zp, len, NULL, &fuidp);
3264 bcopy(link, zp->z_phys + 1, len);
3268 zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, NULL, &fuidp);
3270 * Nothing can access the znode yet so no locking needed
3271 * for growing the znode's blocksize.
3273 zfs_grow_blocksize(zp, len, tx);
3275 VERIFY(0 == dmu_buf_hold(zfsvfs->z_os,
3276 zp->z_id, 0, FTAG, &dbp));
3277 dmu_buf_will_dirty(dbp, tx);
3279 ASSERT3U(len, <=, dbp->db_size);
3280 bcopy(link, dbp->db_data, len);
3281 dmu_buf_rele(dbp, FTAG);
3283 zp->z_phys->zp_size = len;
3286 * Insert the new object into the directory.
3288 (void) zfs_link_create(dl, zp, tx, ZNEW);
3291 uint64_t txtype = TX_SYMLINK;
3292 if (flags & FIGNORECASE)
3294 zfs_log_symlink(zilog, tx, txtype, dzp, zp, name, link);
3297 zfs_fuid_info_free(fuidp);
3301 zfs_dirent_unlock(dl);
3310 * Return, in the buffer contained in the provided uio structure,
3311 * the symbolic path referred to by vp.
3313 * IN: vp - vnode of symbolic link.
3314 * uoip - structure to contain the link path.
3315 * cr - credentials of caller.
3316 * ct - caller context
3318 * OUT: uio - structure to contain the link path.
3320 * RETURN: 0 if success
3321 * error code if failure
3324 * vp - atime updated
3328 zfs_readlink(vnode_t *vp, uio_t *uio, cred_t *cr, caller_context_t *ct)
3330 znode_t *zp = VTOZ(vp);
3331 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3338 bufsz = (size_t)zp->z_phys->zp_size;
3339 if (bufsz + sizeof (znode_phys_t) <= zp->z_dbuf->db_size) {
3340 error = uiomove(zp->z_phys + 1,
3341 MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
3344 error = dmu_buf_hold(zfsvfs->z_os, zp->z_id, 0, FTAG, &dbp);
3349 error = uiomove(dbp->db_data,
3350 MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
3351 dmu_buf_rele(dbp, FTAG);
3354 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
3360 * Insert a new entry into directory tdvp referencing svp.
3362 * IN: tdvp - Directory to contain new entry.
3363 * svp - vnode of new entry.
3364 * name - name of new entry.
3365 * cr - credentials of caller.
3366 * ct - caller context
3368 * RETURN: 0 if success
3369 * error code if failure
3372 * tdvp - ctime|mtime updated
3373 * svp - ctime updated
3377 zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr,
3378 caller_context_t *ct, int flags)
3380 znode_t *dzp = VTOZ(tdvp);
3382 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3391 ASSERT(tdvp->v_type == VDIR);
3395 zilog = zfsvfs->z_log;
3397 if (VOP_REALVP(svp, &realvp, ct) == 0)
3400 if (svp->v_vfsp != tdvp->v_vfsp) {
3407 if (zfsvfs->z_utf8 && u8_validate(name,
3408 strlen(name), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3412 if (flags & FIGNORECASE)
3417 * We do not support links between attributes and non-attributes
3418 * because of the potential security risk of creating links
3419 * into "normal" file space in order to circumvent restrictions
3420 * imposed in attribute space.
3422 if ((szp->z_phys->zp_flags & ZFS_XATTR) !=
3423 (dzp->z_phys->zp_flags & ZFS_XATTR)) {
3429 * POSIX dictates that we return EPERM here.
3430 * Better choices include ENOTSUP or EISDIR.
3432 if (svp->v_type == VDIR) {
3437 owner = zfs_fuid_map_id(zfsvfs, szp->z_phys->zp_uid, cr, ZFS_OWNER);
3438 if (owner != crgetuid(cr) &&
3439 secpolicy_basic_link(cr) != 0) {
3444 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
3450 * Attempt to lock directory; fail if entry already exists.
3452 error = zfs_dirent_lock(&dl, dzp, name, &tzp, zf, NULL, NULL);
3458 tx = dmu_tx_create(zfsvfs->z_os);
3459 dmu_tx_hold_bonus(tx, szp->z_id);
3460 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
3461 error = dmu_tx_assign(tx, zfsvfs->z_assign);
3463 zfs_dirent_unlock(dl);
3464 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
3474 error = zfs_link_create(dl, szp, tx, 0);
3477 uint64_t txtype = TX_LINK;
3478 if (flags & FIGNORECASE)
3480 zfs_log_link(zilog, tx, txtype, dzp, szp, name);
3485 zfs_dirent_unlock(dl);
3488 vnevent_link(svp, ct);
3496 * zfs_null_putapage() is used when the file system has been force
3497 * unmounted. It just drops the pages.
3501 zfs_null_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
3502 size_t *lenp, int flags, cred_t *cr)
3504 pvn_write_done(pp, B_INVAL|B_FORCE|B_ERROR);
3509 * Push a page out to disk, klustering if possible.
3511 * IN: vp - file to push page to.
3512 * pp - page to push.
3513 * flags - additional flags.
3514 * cr - credentials of caller.
3516 * OUT: offp - start of range pushed.
3517 * lenp - len of range pushed.
3519 * RETURN: 0 if success
3520 * error code if failure
3522 * NOTE: callers must have locked the page to be pushed. On
3523 * exit, the page (and all other pages in the kluster) must be
3528 zfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
3529 size_t *lenp, int flags, cred_t *cr)
3531 znode_t *zp = VTOZ(vp);
3532 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3533 zilog_t *zilog = zfsvfs->z_log;
3536 u_offset_t off, koff;
3541 filesz = zp->z_phys->zp_size;
3545 * If our blocksize is bigger than the page size, try to kluster
3546 * muiltiple pages so that we write a full block (thus avoiding
3547 * a read-modify-write).
3549 if (off < filesz && zp->z_blksz > PAGESIZE) {
3550 if (!ISP2(zp->z_blksz)) {
3551 /* Only one block in the file. */
3552 klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE);
3556 koff = P2ALIGN(off, (u_offset_t)klen);
3558 ASSERT(koff <= filesz);
3559 if (koff + klen > filesz)
3560 klen = P2ROUNDUP(filesz - koff, (uint64_t)PAGESIZE);
3561 pp = pvn_write_kluster(vp, pp, &off, &len, koff, klen, flags);
3563 ASSERT3U(btop(len), ==, btopr(len));
3565 rl = zfs_range_lock(zp, off, len, RL_WRITER);
3567 * Can't push pages past end-of-file.
3569 filesz = zp->z_phys->zp_size;
3570 if (off >= filesz) {
3571 /* ignore all pages */
3574 } else if (off + len > filesz) {
3575 int npages = btopr(filesz - off);
3578 page_list_break(&pp, &trunc, npages);
3579 /* ignore pages past end of file */
3581 pvn_write_done(trunc, flags);
3585 tx = dmu_tx_create(zfsvfs->z_os);
3586 dmu_tx_hold_write(tx, zp->z_id, off, len);
3587 dmu_tx_hold_bonus(tx, zp->z_id);
3588 err = dmu_tx_assign(tx, zfsvfs->z_assign);
3590 if (err == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
3591 zfs_range_unlock(rl);
3601 if (zp->z_blksz <= PAGESIZE) {
3602 caddr_t va = ppmapin(pp, PROT_READ, (caddr_t)-1);
3603 ASSERT3U(len, <=, PAGESIZE);
3604 dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx);
3607 err = dmu_write_pages(zfsvfs->z_os, zp->z_id, off, len, pp, tx);
3611 zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
3612 zfs_log_write(zilog, tx, TX_WRITE, zp, off, len, 0);
3617 zfs_range_unlock(rl);
3618 pvn_write_done(pp, (err ? B_ERROR : 0) | flags);
3628 * Copy the portion of the file indicated from pages into the file.
3629 * The pages are stored in a page list attached to the files vnode.
3631 * IN: vp - vnode of file to push page data to.
3632 * off - position in file to put data.
3633 * len - amount of data to write.
3634 * flags - flags to control the operation.
3635 * cr - credentials of caller.
3636 * ct - caller context.
3638 * RETURN: 0 if success
3639 * error code if failure
3642 * vp - ctime|mtime updated
3646 zfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
3647 caller_context_t *ct)
3649 znode_t *zp = VTOZ(vp);
3650 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3662 * Search the entire vp list for pages >= off.
3664 error = pvn_vplist_dirty(vp, (u_offset_t)off, zfs_putapage,
3669 filesz = zp->z_phys->zp_size; /* get consistent copy of zp_size */
3671 /* past end of file */
3676 len = MIN(len, filesz - off);
3678 for (io_off = off; io_off < off + len; io_off += io_len) {
3679 if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) {
3680 pp = page_lookup(vp, io_off,
3681 (flags & (B_INVAL | B_FREE)) ? SE_EXCL : SE_SHARED);
3683 pp = page_lookup_nowait(vp, io_off,
3684 (flags & B_FREE) ? SE_EXCL : SE_SHARED);
3687 if (pp != NULL && pvn_getdirty(pp, flags)) {
3691 * Found a dirty page to push
3693 err = zfs_putapage(vp, pp, &io_off, &io_len, flags, cr);
3701 if ((flags & B_ASYNC) == 0)
3702 zil_commit(zfsvfs->z_log, UINT64_MAX, zp->z_id);
3709 zfs_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
3711 znode_t *zp = VTOZ(vp);
3712 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3715 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER);
3716 if (zp->z_dbuf == NULL) {
3718 * The fs has been unmounted, or we did a
3719 * suspend/resume and this file no longer exists.
3721 if (vn_has_cached_data(vp)) {
3722 (void) pvn_vplist_dirty(vp, 0, zfs_null_putapage,
3726 mutex_enter(&zp->z_lock);
3727 vp->v_count = 0; /* count arrives as 1 */
3728 mutex_exit(&zp->z_lock);
3729 rw_exit(&zfsvfs->z_teardown_inactive_lock);
3735 * Attempt to push any data in the page cache. If this fails
3736 * we will get kicked out later in zfs_zinactive().
3738 if (vn_has_cached_data(vp)) {
3739 (void) pvn_vplist_dirty(vp, 0, zfs_putapage, B_INVAL|B_ASYNC,
3743 if (zp->z_atime_dirty && zp->z_unlinked == 0) {
3744 dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
3746 dmu_tx_hold_bonus(tx, zp->z_id);
3747 error = dmu_tx_assign(tx, TXG_WAIT);
3751 dmu_buf_will_dirty(zp->z_dbuf, tx);
3752 mutex_enter(&zp->z_lock);
3753 zp->z_atime_dirty = 0;
3754 mutex_exit(&zp->z_lock);
3760 rw_exit(&zfsvfs->z_teardown_inactive_lock);
3764 * Bounds-check the seek operation.
3766 * IN: vp - vnode seeking within
3767 * ooff - old file offset
3768 * noffp - pointer to new file offset
3769 * ct - caller context
3771 * RETURN: 0 if success
3772 * EINVAL if new offset invalid
3776 zfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp,
3777 caller_context_t *ct)
3779 if (vp->v_type == VDIR)
3781 return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
3785 * Pre-filter the generic locking function to trap attempts to place
3786 * a mandatory lock on a memory mapped file.
3789 zfs_frlock(vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset,
3790 flk_callback_t *flk_cbp, cred_t *cr, caller_context_t *ct)
3792 znode_t *zp = VTOZ(vp);
3793 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3800 * We are following the UFS semantics with respect to mapcnt
3801 * here: If we see that the file is mapped already, then we will
3802 * return an error, but we don't worry about races between this
3803 * function and zfs_map().
3805 if (zp->z_mapcnt > 0 && MANDMODE((mode_t)zp->z_phys->zp_mode)) {
3809 error = fs_frlock(vp, cmd, bfp, flag, offset, flk_cbp, cr, ct);
3815 * If we can't find a page in the cache, we will create a new page
3816 * and fill it with file data. For efficiency, we may try to fill
3817 * multiple pages at once (klustering).
3820 zfs_fillpage(vnode_t *vp, u_offset_t off, struct seg *seg,
3821 caddr_t addr, page_t *pl[], size_t plsz, enum seg_rw rw)
3823 znode_t *zp = VTOZ(vp);
3824 page_t *pp, *cur_pp;
3825 objset_t *os = zp->z_zfsvfs->z_os;
3827 u_offset_t io_off, total;
3828 uint64_t oid = zp->z_id;
3834 * If we are only asking for a single page don't bother klustering.
3836 filesz = zp->z_phys->zp_size; /* get consistent copy of zp_size */
3839 if (plsz == PAGESIZE || zp->z_blksz <= PAGESIZE) {
3842 pp = page_create_va(vp, io_off, io_len, PG_WAIT, seg, addr);
3845 * Try to fill a kluster of pages (a blocks worth).
3850 if (!ISP2(zp->z_blksz)) {
3851 /* Only one block in the file. */
3852 klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE);
3856 * It would be ideal to align our offset to the
3857 * blocksize but doing so has resulted in some
3858 * strange application crashes. For now, we
3859 * leave the offset as is and only adjust the
3860 * length if we are off the end of the file.
3865 ASSERT(koff <= filesz);
3866 if (koff + klen > filesz)
3867 klen = P2ROUNDUP(filesz, (uint64_t)PAGESIZE) - koff;
3868 ASSERT3U(off, >=, koff);
3869 ASSERT3U(off, <, koff + klen);
3870 pp = pvn_read_kluster(vp, off, seg, addr, &io_off,
3871 &io_len, koff, klen, 0);
3875 * Some other thread entered the page before us.
3876 * Return to zfs_getpage to retry the lookup.
3883 * Fill the pages in the kluster.
3886 for (total = io_off + io_len; io_off < total; io_off += PAGESIZE) {
3887 ASSERT3U(io_off, ==, cur_pp->p_offset);
3888 va = ppmapin(cur_pp, PROT_READ | PROT_WRITE, (caddr_t)-1);
3889 err = dmu_read(os, oid, io_off, PAGESIZE, va);
3892 /* On error, toss the entire kluster */
3893 pvn_read_done(pp, B_ERROR);
3896 cur_pp = cur_pp->p_next;
3900 * Fill in the page list array from the kluster. If
3901 * there are too many pages in the kluster, return
3902 * as many pages as possible starting from the desired
3904 * NOTE: the page list will always be null terminated.
3906 pvn_plist_init(pp, pl, plsz, off, io_len, rw);
3912 * Return pointers to the pages for the file region [off, off + len]
3913 * in the pl array. If plsz is greater than len, this function may
3914 * also return page pointers from before or after the specified
3915 * region (i.e. some region [off', off' + plsz]). These additional
3916 * pages are only returned if they are already in the cache, or were
3917 * created as part of a klustered read.
3919 * IN: vp - vnode of file to get data from.
3920 * off - position in file to get data from.
3921 * len - amount of data to retrieve.
3922 * plsz - length of provided page list.
3923 * seg - segment to obtain pages for.
3924 * addr - virtual address of fault.
3925 * rw - mode of created pages.
3926 * cr - credentials of caller.
3927 * ct - caller context.
3929 * OUT: protp - protection mode of created pages.
3930 * pl - list of pages created.
3932 * RETURN: 0 if success
3933 * error code if failure
3936 * vp - atime updated
3940 zfs_getpage(vnode_t *vp, offset_t off, size_t len, uint_t *protp,
3941 page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
3942 enum seg_rw rw, cred_t *cr, caller_context_t *ct)
3944 znode_t *zp = VTOZ(vp);
3945 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3946 page_t *pp, **pl0 = pl;
3947 int need_unlock = 0, err = 0;
3956 /* no faultahead (for now) */
3962 /* can't fault past EOF */
3963 if (off >= zp->z_phys->zp_size) {
3970 * If we already own the lock, then we must be page faulting
3971 * in the middle of a write to this file (i.e., we are writing
3972 * to this file using data from a mapped region of the file).
3974 if (rw_owner(&zp->z_map_lock) != curthread) {
3975 rw_enter(&zp->z_map_lock, RW_WRITER);
3980 * Loop through the requested range [off, off + len] looking
3981 * for pages. If we don't find a page, we will need to create
3982 * a new page and fill it with data from the file.
3985 if (plsz < PAGESIZE)
3987 if (pp = page_lookup(vp, off, SE_SHARED)) {
3994 err = zfs_fillpage(vp, off, seg, addr, pl, plsz, rw);
3998 * klustering may have changed our region
3999 * to be block aligned.
4001 if (((pp = *pl) != 0) && (off != pp->p_offset)) {
4002 int delta = off - pp->p_offset;
4021 * Fill out the page array with any pages already in the cache.
4024 pp = page_lookup_nowait(vp, off, SE_SHARED);
4032 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
4035 * We can't grab the range lock for the page as reader which would
4036 * stop truncation as this leads to deadlock. So we need to recheck
4039 if (orig_off >= zp->z_phys->zp_size)
4043 * Release any pages we have previously locked.
4052 rw_exit(&zp->z_map_lock);
4059 * Request a memory map for a section of a file. This code interacts
4060 * with common code and the VM system as follows:
4062 * common code calls mmap(), which ends up in smmap_common()
4064 * this calls VOP_MAP(), which takes you into (say) zfs
4066 * zfs_map() calls as_map(), passing segvn_create() as the callback
4068 * segvn_create() creates the new segment and calls VOP_ADDMAP()
4070 * zfs_addmap() updates z_mapcnt
4074 zfs_map(vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp,
4075 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4076 caller_context_t *ct)
4078 znode_t *zp = VTOZ(vp);
4079 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4080 segvn_crargs_t vn_a;
4086 if ((prot & PROT_WRITE) &&
4087 (zp->z_phys->zp_flags & (ZFS_IMMUTABLE | ZFS_READONLY |
4093 if ((prot & (PROT_READ | PROT_EXEC)) &&
4094 (zp->z_phys->zp_flags & ZFS_AV_QUARANTINED)) {
4099 if (vp->v_flag & VNOMAP) {
4104 if (off < 0 || len > MAXOFFSET_T - off) {
4109 if (vp->v_type != VREG) {
4115 * If file is locked, disallow mapping.
4117 if (MANDMODE((mode_t)zp->z_phys->zp_mode) && vn_has_flocks(vp)) {
4123 error = choose_addr(as, addrp, len, off, ADDR_VACALIGN, flags);
4131 vn_a.offset = (u_offset_t)off;
4132 vn_a.type = flags & MAP_TYPE;
4134 vn_a.maxprot = maxprot;
4137 vn_a.flags = flags & ~MAP_TYPE;
4139 vn_a.lgrp_mem_policy_flags = 0;
4141 error = as_map(as, *addrp, len, segvn_create, &vn_a);
4150 zfs_addmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
4151 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4152 caller_context_t *ct)
4154 uint64_t pages = btopr(len);
4156 atomic_add_64(&VTOZ(vp)->z_mapcnt, pages);
4161 * The reason we push dirty pages as part of zfs_delmap() is so that we get a
4162 * more accurate mtime for the associated file. Since we don't have a way of
4163 * detecting when the data was actually modified, we have to resort to
4164 * heuristics. If an explicit msync() is done, then we mark the mtime when the
4165 * last page is pushed. The problem occurs when the msync() call is omitted,
4166 * which by far the most common case:
4174 * putpage() via fsflush
4176 * If we wait until fsflush to come along, we can have a modification time that
4177 * is some arbitrary point in the future. In order to prevent this in the
4178 * common case, we flush pages whenever a (MAP_SHARED, PROT_WRITE) mapping is
4183 zfs_delmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
4184 size_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cr,
4185 caller_context_t *ct)
4187 uint64_t pages = btopr(len);
4189 ASSERT3U(VTOZ(vp)->z_mapcnt, >=, pages);
4190 atomic_add_64(&VTOZ(vp)->z_mapcnt, -pages);
4192 if ((flags & MAP_SHARED) && (prot & PROT_WRITE) &&
4193 vn_has_cached_data(vp))
4194 (void) VOP_PUTPAGE(vp, off, len, B_ASYNC, cr, ct);
4200 * Free or allocate space in a file. Currently, this function only
4201 * supports the `F_FREESP' command. However, this command is somewhat
4202 * misnamed, as its functionality includes the ability to allocate as
4203 * well as free space.
4205 * IN: vp - vnode of file to free data in.
4206 * cmd - action to take (only F_FREESP supported).
4207 * bfp - section of file to free/alloc.
4208 * flag - current file open mode flags.
4209 * offset - current file offset.
4210 * cr - credentials of caller [UNUSED].
4211 * ct - caller context.
4213 * RETURN: 0 if success
4214 * error code if failure
4217 * vp - ctime|mtime updated
4221 zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag,
4222 offset_t offset, cred_t *cr, caller_context_t *ct)
4224 znode_t *zp = VTOZ(vp);
4225 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4233 if (cmd != F_FREESP) {
4238 if (error = convoff(vp, bfp, 0, offset)) {
4243 if (bfp->l_len < 0) {
4249 len = bfp->l_len; /* 0 means from off to end of file */
4252 error = zfs_freesp(zp, off, len, flag, TRUE);
4253 /* NB: we already did dmu_tx_wait() if necessary */
4254 } while (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT);
4262 zfs_fid(vnode_t *vp, fid_t *fidp, caller_context_t *ct)
4264 znode_t *zp = VTOZ(vp);
4265 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4267 uint64_t object = zp->z_id;
4273 gen = (uint32_t)zp->z_gen;
4275 size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN;
4276 if (fidp->fid_len < size) {
4277 fidp->fid_len = size;
4282 zfid = (zfid_short_t *)fidp;
4284 zfid->zf_len = size;
4286 for (i = 0; i < sizeof (zfid->zf_object); i++)
4287 zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
4289 /* Must have a non-zero generation number to distinguish from .zfs */
4292 for (i = 0; i < sizeof (zfid->zf_gen); i++)
4293 zfid->zf_gen[i] = (uint8_t)(gen >> (8 * i));
4295 if (size == LONG_FID_LEN) {
4296 uint64_t objsetid = dmu_objset_id(zfsvfs->z_os);
4299 zlfid = (zfid_long_t *)fidp;
4301 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
4302 zlfid->zf_setid[i] = (uint8_t)(objsetid >> (8 * i));
4304 /* XXX - this should be the generation number for the objset */
4305 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
4306 zlfid->zf_setgen[i] = 0;
4314 zfs_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr,
4315 caller_context_t *ct)
4327 case _PC_FILESIZEBITS:
4331 case _PC_XATTR_EXISTS:
4333 zfsvfs = zp->z_zfsvfs;
4337 error = zfs_dirent_lock(&dl, zp, "", &xzp,
4338 ZXATTR | ZEXISTS | ZSHARED, NULL, NULL);
4340 zfs_dirent_unlock(dl);
4341 if (!zfs_dirempty(xzp))
4344 } else if (error == ENOENT) {
4346 * If there aren't extended attributes, it's the
4347 * same as having zero of them.
4354 case _PC_SATTR_ENABLED:
4355 case _PC_SATTR_EXISTS:
4356 *valp = vfs_has_feature(vp->v_vfsp, VFSFT_XVATTR) &&
4357 (vp->v_type == VREG || vp->v_type == VDIR);
4360 case _PC_ACL_ENABLED:
4361 *valp = _ACL_ACE_ENABLED;
4364 case _PC_MIN_HOLE_SIZE:
4365 *valp = (ulong_t)SPA_MINBLOCKSIZE;
4369 return (fs_pathconf(vp, cmd, valp, cr, ct));
4375 zfs_getsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
4376 caller_context_t *ct)
4378 znode_t *zp = VTOZ(vp);
4379 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4381 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4385 error = zfs_getacl(zp, vsecp, skipaclchk, cr);
4393 zfs_setsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
4394 caller_context_t *ct)
4396 znode_t *zp = VTOZ(vp);
4397 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4399 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4403 error = zfs_setacl(zp, vsecp, skipaclchk, cr);
4409 * Predeclare these here so that the compiler assumes that
4410 * this is an "old style" function declaration that does
4411 * not include arguments => we won't get type mismatch errors
4412 * in the initializations that follow.
4414 static int zfs_inval();
4415 static int zfs_isdir();
4429 * Directory vnode operations template
4431 vnodeops_t *zfs_dvnodeops;
4432 const fs_operation_def_t zfs_dvnodeops_template[] = {
4433 VOPNAME_OPEN, { .vop_open = zfs_open },
4434 VOPNAME_CLOSE, { .vop_close = zfs_close },
4435 VOPNAME_READ, { .error = zfs_isdir },
4436 VOPNAME_WRITE, { .error = zfs_isdir },
4437 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
4438 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4439 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4440 VOPNAME_ACCESS, { .vop_access = zfs_access },
4441 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
4442 VOPNAME_CREATE, { .vop_create = zfs_create },
4443 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
4444 VOPNAME_LINK, { .vop_link = zfs_link },
4445 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4446 VOPNAME_MKDIR, { .vop_mkdir = zfs_mkdir },
4447 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
4448 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
4449 VOPNAME_SYMLINK, { .vop_symlink = zfs_symlink },
4450 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
4451 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4452 VOPNAME_FID, { .vop_fid = zfs_fid },
4453 VOPNAME_SEEK, { .vop_seek = zfs_seek },
4454 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4455 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4456 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4457 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4462 * Regular file vnode operations template
4464 vnodeops_t *zfs_fvnodeops;
4465 const fs_operation_def_t zfs_fvnodeops_template[] = {
4466 VOPNAME_OPEN, { .vop_open = zfs_open },
4467 VOPNAME_CLOSE, { .vop_close = zfs_close },
4468 VOPNAME_READ, { .vop_read = zfs_read },
4469 VOPNAME_WRITE, { .vop_write = zfs_write },
4470 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
4471 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4472 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4473 VOPNAME_ACCESS, { .vop_access = zfs_access },
4474 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
4475 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4476 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
4477 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4478 VOPNAME_FID, { .vop_fid = zfs_fid },
4479 VOPNAME_SEEK, { .vop_seek = zfs_seek },
4480 VOPNAME_FRLOCK, { .vop_frlock = zfs_frlock },
4481 VOPNAME_SPACE, { .vop_space = zfs_space },
4482 VOPNAME_GETPAGE, { .vop_getpage = zfs_getpage },
4483 VOPNAME_PUTPAGE, { .vop_putpage = zfs_putpage },
4484 VOPNAME_MAP, { .vop_map = zfs_map },
4485 VOPNAME_ADDMAP, { .vop_addmap = zfs_addmap },
4486 VOPNAME_DELMAP, { .vop_delmap = zfs_delmap },
4487 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4488 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4489 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4490 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4495 * Symbolic link vnode operations template
4497 vnodeops_t *zfs_symvnodeops;
4498 const fs_operation_def_t zfs_symvnodeops_template[] = {
4499 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4500 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4501 VOPNAME_ACCESS, { .vop_access = zfs_access },
4502 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4503 VOPNAME_READLINK, { .vop_readlink = zfs_readlink },
4504 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4505 VOPNAME_FID, { .vop_fid = zfs_fid },
4506 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4507 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4512 * Extended attribute directory vnode operations template
4513 * This template is identical to the directory vnodes
4514 * operation template except for restricted operations:
4517 * Note that there are other restrictions embedded in:
4518 * zfs_create() - restrict type to VREG
4519 * zfs_link() - no links into/out of attribute space
4520 * zfs_rename() - no moves into/out of attribute space
4522 vnodeops_t *zfs_xdvnodeops;
4523 const fs_operation_def_t zfs_xdvnodeops_template[] = {
4524 VOPNAME_OPEN, { .vop_open = zfs_open },
4525 VOPNAME_CLOSE, { .vop_close = zfs_close },
4526 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
4527 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4528 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4529 VOPNAME_ACCESS, { .vop_access = zfs_access },
4530 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
4531 VOPNAME_CREATE, { .vop_create = zfs_create },
4532 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
4533 VOPNAME_LINK, { .vop_link = zfs_link },
4534 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4535 VOPNAME_MKDIR, { .error = zfs_inval },
4536 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
4537 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
4538 VOPNAME_SYMLINK, { .error = zfs_inval },
4539 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
4540 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4541 VOPNAME_FID, { .vop_fid = zfs_fid },
4542 VOPNAME_SEEK, { .vop_seek = zfs_seek },
4543 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4544 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4545 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4546 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4551 * Error vnode operations template
4553 vnodeops_t *zfs_evnodeops;
4554 const fs_operation_def_t zfs_evnodeops_template[] = {
4555 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4556 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },