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 #include <sys/types.h>
29 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/sysmacros.h>
33 #include <sys/resource.h>
35 #include <sys/vfs_opreg.h>
36 #include <sys/vnode.h>
40 #include <sys/taskq.h>
42 #include <sys/vmsystm.h>
43 #include <sys/atomic.h>
45 #include <vm/seg_vn.h>
49 #include <vm/seg_kpm.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>
69 #include "fs/fs_subr.h"
70 #include <sys/zfs_ctldir.h>
71 #include <sys/zfs_fuid.h>
73 #include <sys/zfs_rlock.h>
74 #include <sys/extdirent.h>
75 #include <sys/kidmap.h>
76 #include <sys/cred_impl.h>
82 * Each vnode op performs some logical unit of work. To do this, the ZPL must
83 * properly lock its in-core state, create a DMU transaction, do the work,
84 * record this work in the intent log (ZIL), commit the DMU transaction,
85 * and wait for the intent log to commit if it is a synchronous operation.
86 * Moreover, the vnode ops must work in both normal and log replay context.
87 * The ordering of events is important to avoid deadlocks and references
88 * to freed memory. The example below illustrates the following Big Rules:
90 * (1) A check must be made in each zfs thread for a mounted file system.
91 * This is done avoiding races using ZFS_ENTER(zfsvfs).
92 * A ZFS_EXIT(zfsvfs) is needed before all returns. Any znodes
93 * must be checked with ZFS_VERIFY_ZP(zp). Both of these macros
94 * can return EIO from the calling function.
96 * (2) VN_RELE() should always be the last thing except for zil_commit()
97 * (if necessary) and ZFS_EXIT(). This is for 3 reasons:
98 * First, if it's the last reference, the vnode/znode
99 * can be freed, so the zp may point to freed memory. Second, the last
100 * reference will call zfs_zinactive(), which may induce a lot of work --
101 * pushing cached pages (which acquires range locks) and syncing out
102 * cached atime changes. Third, zfs_zinactive() may require a new tx,
103 * which could deadlock the system if you were already holding one.
105 * (3) All range locks must be grabbed before calling dmu_tx_assign(),
106 * as they can span dmu_tx_assign() calls.
108 * (4) Always pass zfsvfs->z_assign as the second argument to dmu_tx_assign().
109 * In normal operation, this will be TXG_NOWAIT. During ZIL replay,
110 * it will be a specific txg. Either way, dmu_tx_assign() never blocks.
111 * This is critical because we don't want to block while holding locks.
112 * Note, in particular, that if a lock is sometimes acquired before
113 * the tx assigns, and sometimes after (e.g. z_lock), then failing to
114 * use a non-blocking assign can deadlock the system. The scenario:
116 * Thread A has grabbed a lock before calling dmu_tx_assign().
117 * Thread B is in an already-assigned tx, and blocks for this lock.
118 * Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
119 * forever, because the previous txg can't quiesce until B's tx commits.
121 * If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
122 * then drop all locks, call dmu_tx_wait(), and try again.
124 * (5) If the operation succeeded, generate the intent log entry for it
125 * before dropping locks. This ensures that the ordering of events
126 * in the intent log matches the order in which they actually occurred.
128 * (6) At the end of each vnode op, the DMU tx must always commit,
129 * regardless of whether there were any errors.
131 * (7) After dropping all locks, invoke zil_commit(zilog, seq, foid)
132 * to ensure that synchronous semantics are provided when necessary.
134 * In general, this is how things should be ordered in each vnode op:
136 * ZFS_ENTER(zfsvfs); // exit if unmounted
138 * zfs_dirent_lock(&dl, ...) // lock directory entry (may VN_HOLD())
139 * rw_enter(...); // grab any other locks you need
140 * tx = dmu_tx_create(...); // get DMU tx
141 * dmu_tx_hold_*(); // hold each object you might modify
142 * error = dmu_tx_assign(tx, zfsvfs->z_assign); // try to assign
144 * rw_exit(...); // drop locks
145 * zfs_dirent_unlock(dl); // unlock directory entry
146 * VN_RELE(...); // release held vnodes
147 * if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
152 * dmu_tx_abort(tx); // abort DMU tx
153 * ZFS_EXIT(zfsvfs); // finished in zfs
154 * return (error); // really out of space
156 * error = do_real_work(); // do whatever this VOP does
158 * zfs_log_*(...); // on success, make ZIL entry
159 * dmu_tx_commit(tx); // commit DMU tx -- error or not
160 * rw_exit(...); // drop locks
161 * zfs_dirent_unlock(dl); // unlock directory entry
162 * VN_RELE(...); // release held vnodes
163 * zil_commit(zilog, seq, foid); // synchronous when necessary
164 * ZFS_EXIT(zfsvfs); // finished in zfs
165 * return (error); // done, report error
170 zfs_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
172 znode_t *zp = VTOZ(*vpp);
173 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
178 if ((flag & FWRITE) && (zp->z_phys->zp_flags & ZFS_APPENDONLY) &&
179 ((flag & FAPPEND) == 0)) {
184 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
185 ZTOV(zp)->v_type == VREG &&
186 !(zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) &&
187 zp->z_phys->zp_size > 0) {
188 if (fs_vscan(*vpp, cr, 0) != 0) {
194 /* Keep a count of the synchronous opens in the znode */
195 if (flag & (FSYNC | FDSYNC))
196 atomic_inc_32(&zp->z_sync_cnt);
204 zfs_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr,
205 caller_context_t *ct)
207 znode_t *zp = VTOZ(vp);
208 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
213 /* Decrement the synchronous opens in the znode */
214 if ((flag & (FSYNC | FDSYNC)) && (count == 1))
215 atomic_dec_32(&zp->z_sync_cnt);
218 * Clean up any locks held by this process on the vp.
220 cleanlocks(vp, ddi_get_pid(), 0);
221 cleanshares(vp, ddi_get_pid());
223 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
224 ZTOV(zp)->v_type == VREG &&
225 !(zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) &&
226 zp->z_phys->zp_size > 0)
227 VERIFY(fs_vscan(vp, cr, 1) == 0);
234 * Lseek support for finding holes (cmd == _FIO_SEEK_HOLE) and
235 * data (cmd == _FIO_SEEK_DATA). "off" is an in/out parameter.
238 zfs_holey(vnode_t *vp, int cmd, offset_t *off)
240 znode_t *zp = VTOZ(vp);
241 uint64_t noff = (uint64_t)*off; /* new offset */
246 file_sz = zp->z_phys->zp_size;
247 if (noff >= file_sz) {
251 if (cmd == _FIO_SEEK_HOLE)
256 error = dmu_offset_next(zp->z_zfsvfs->z_os, zp->z_id, hole, &noff);
259 if ((error == ESRCH) || (noff > file_sz)) {
261 * Handle the virtual hole at the end of file.
278 zfs_ioctl(vnode_t *vp, int com, intptr_t data, int flag, cred_t *cred,
279 int *rvalp, caller_context_t *ct)
288 return (zfs_sync(vp->v_vfsp, 0, cred));
291 * The following two ioctls are used by bfu. Faking out,
292 * necessary to avoid bfu errors.
300 if (ddi_copyin((void *)data, &off, sizeof (off), flag))
304 zfsvfs = zp->z_zfsvfs;
308 /* offset parameter is in/out */
309 error = zfs_holey(vp, com, &off);
313 if (ddi_copyout(&off, (void *)data, sizeof (off), flag))
321 * Utility functions to map and unmap a single physical page. These
322 * are used to manage the mappable copies of ZFS file data, and therefore
323 * do not update ref/mod bits.
326 zfs_map_page(page_t *pp, enum seg_rw rw)
329 return (hat_kpm_mapin(pp, 0));
330 ASSERT(rw == S_READ || rw == S_WRITE);
331 return (ppmapin(pp, PROT_READ | ((rw == S_WRITE) ? PROT_WRITE : 0),
336 zfs_unmap_page(page_t *pp, caddr_t addr)
339 hat_kpm_mapout(pp, 0, addr);
346 * When a file is memory mapped, we must keep the IO data synchronized
347 * between the DMU cache and the memory mapped pages. What this means:
349 * On Write: If we find a memory mapped page, we write to *both*
350 * the page and the dmu buffer.
352 * NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
353 * the file is memory mapped.
356 mappedwrite(vnode_t *vp, int nbytes, uio_t *uio, dmu_tx_t *tx)
358 znode_t *zp = VTOZ(vp);
359 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
364 start = uio->uio_loffset;
365 off = start & PAGEOFFSET;
366 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
368 uint64_t bytes = MIN(PAGESIZE - off, len);
369 uint64_t woff = uio->uio_loffset;
372 * We don't want a new page to "appear" in the middle of
373 * the file update (because it may not get the write
374 * update data), so we grab a lock to block
377 rw_enter(&zp->z_map_lock, RW_WRITER);
378 if (pp = page_lookup(vp, start, SE_SHARED)) {
381 rw_exit(&zp->z_map_lock);
382 va = zfs_map_page(pp, S_WRITE);
383 error = uiomove(va+off, bytes, UIO_WRITE, uio);
385 dmu_write(zfsvfs->z_os, zp->z_id,
386 woff, bytes, va+off, tx);
388 zfs_unmap_page(pp, va);
391 error = dmu_write_uio(zfsvfs->z_os, zp->z_id,
393 rw_exit(&zp->z_map_lock);
404 * When a file is memory mapped, we must keep the IO data synchronized
405 * between the DMU cache and the memory mapped pages. What this means:
407 * On Read: We "read" preferentially from memory mapped pages,
408 * else we default from the dmu buffer.
410 * NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
411 * the file is memory mapped.
414 mappedread(vnode_t *vp, int nbytes, uio_t *uio)
416 znode_t *zp = VTOZ(vp);
417 objset_t *os = zp->z_zfsvfs->z_os;
422 start = uio->uio_loffset;
423 off = start & PAGEOFFSET;
424 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
426 uint64_t bytes = MIN(PAGESIZE - off, len);
428 if (pp = page_lookup(vp, start, SE_SHARED)) {
431 va = zfs_map_page(pp, S_READ);
432 error = uiomove(va + off, bytes, UIO_READ, uio);
433 zfs_unmap_page(pp, va);
436 error = dmu_read_uio(os, zp->z_id, uio, bytes);
446 offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */
449 * Read bytes from specified file into supplied buffer.
451 * IN: vp - vnode of file to be read from.
452 * uio - structure supplying read location, range info,
454 * ioflag - SYNC flags; used to provide FRSYNC semantics.
455 * cr - credentials of caller.
456 * ct - caller context
458 * OUT: uio - updated offset and range, buffer filled.
460 * RETURN: 0 if success
461 * error code if failure
464 * vp - atime updated if byte count > 0
468 zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
470 znode_t *zp = VTOZ(vp);
471 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
481 if (zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) {
487 * Validate file offset
489 if (uio->uio_loffset < (offset_t)0) {
495 * Fasttrack empty reads
497 if (uio->uio_resid == 0) {
503 * Check for mandatory locks
505 if (MANDMODE((mode_t)zp->z_phys->zp_mode)) {
506 if (error = chklock(vp, FREAD,
507 uio->uio_loffset, uio->uio_resid, uio->uio_fmode, ct)) {
514 * If we're in FRSYNC mode, sync out this znode before reading it.
517 zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
520 * Lock the range against changes.
522 rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER);
525 * If we are reading past end-of-file we can skip
526 * to the end; but we might still need to set atime.
528 if (uio->uio_loffset >= zp->z_phys->zp_size) {
533 ASSERT(uio->uio_loffset < zp->z_phys->zp_size);
534 n = MIN(uio->uio_resid, zp->z_phys->zp_size - uio->uio_loffset);
537 nbytes = MIN(n, zfs_read_chunk_size -
538 P2PHASE(uio->uio_loffset, zfs_read_chunk_size));
540 if (vn_has_cached_data(vp))
541 error = mappedread(vp, nbytes, uio);
543 error = dmu_read_uio(os, zp->z_id, uio, nbytes);
545 /* convert checksum errors into IO errors */
555 zfs_range_unlock(rl);
557 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
563 * Write the bytes to a file.
565 * IN: vp - vnode of file to be written to.
566 * uio - structure supplying write location, range info,
568 * ioflag - FAPPEND flag set if in append mode.
569 * cr - credentials of caller.
570 * ct - caller context (NFS/CIFS fem monitor only)
572 * OUT: uio - updated offset and range.
574 * RETURN: 0 if success
575 * error code if failure
578 * vp - ctime|mtime updated if byte count > 0
582 zfs_write(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
584 znode_t *zp = VTOZ(vp);
585 rlim64_t limit = uio->uio_llimit;
586 ssize_t start_resid = uio->uio_resid;
590 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
595 int max_blksz = zfsvfs->z_max_blksz;
600 * Fasttrack empty write
606 if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
613 * If immutable or not appending then return EPERM
615 pflags = zp->z_phys->zp_flags;
616 if ((pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) ||
617 ((pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) &&
618 (uio->uio_loffset < zp->z_phys->zp_size))) {
623 zilog = zfsvfs->z_log;
626 * Pre-fault the pages to ensure slow (eg NFS) pages
629 uio_prefaultpages(n, uio);
632 * If in append mode, set the io offset pointer to eof.
634 if (ioflag & FAPPEND) {
636 * Range lock for a file append:
637 * The value for the start of range will be determined by
638 * zfs_range_lock() (to guarantee append semantics).
639 * If this write will cause the block size to increase,
640 * zfs_range_lock() will lock the entire file, so we must
641 * later reduce the range after we grow the block size.
643 rl = zfs_range_lock(zp, 0, n, RL_APPEND);
644 if (rl->r_len == UINT64_MAX) {
645 /* overlocked, zp_size can't change */
646 woff = uio->uio_loffset = zp->z_phys->zp_size;
648 woff = uio->uio_loffset = rl->r_off;
651 woff = uio->uio_loffset;
653 * Validate file offset
661 * If we need to grow the block size then zfs_range_lock()
662 * will lock a wider range than we request here.
663 * Later after growing the block size we reduce the range.
665 rl = zfs_range_lock(zp, woff, n, RL_WRITER);
669 zfs_range_unlock(rl);
674 if ((woff + n) > limit || woff > (limit - n))
678 * Check for mandatory locks
680 if (MANDMODE((mode_t)zp->z_phys->zp_mode) &&
681 (error = chklock(vp, FWRITE, woff, n, uio->uio_fmode, ct)) != 0) {
682 zfs_range_unlock(rl);
686 end_size = MAX(zp->z_phys->zp_size, woff + n);
689 * Write the file in reasonable size chunks. Each chunk is written
690 * in a separate transaction; this keeps the intent log records small
691 * and allows us to do more fine-grained space accounting.
695 * Start a transaction.
697 woff = uio->uio_loffset;
698 tx = dmu_tx_create(zfsvfs->z_os);
699 dmu_tx_hold_bonus(tx, zp->z_id);
700 dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
701 error = dmu_tx_assign(tx, zfsvfs->z_assign);
703 if (error == ERESTART &&
704 zfsvfs->z_assign == TXG_NOWAIT) {
714 * If zfs_range_lock() over-locked we grow the blocksize
715 * and then reduce the lock range. This will only happen
716 * on the first iteration since zfs_range_reduce() will
717 * shrink down r_len to the appropriate size.
719 if (rl->r_len == UINT64_MAX) {
722 if (zp->z_blksz > max_blksz) {
723 ASSERT(!ISP2(zp->z_blksz));
724 new_blksz = MIN(end_size, SPA_MAXBLOCKSIZE);
726 new_blksz = MIN(end_size, max_blksz);
728 zfs_grow_blocksize(zp, new_blksz, tx);
729 zfs_range_reduce(rl, woff, n);
733 * XXX - should we really limit each write to z_max_blksz?
734 * Perhaps we should use SPA_MAXBLOCKSIZE chunks?
736 nbytes = MIN(n, max_blksz - P2PHASE(woff, max_blksz));
737 rw_enter(&zp->z_map_lock, RW_READER);
739 tx_bytes = uio->uio_resid;
740 if (vn_has_cached_data(vp)) {
741 rw_exit(&zp->z_map_lock);
742 error = mappedwrite(vp, nbytes, uio, tx);
744 error = dmu_write_uio(zfsvfs->z_os, zp->z_id,
746 rw_exit(&zp->z_map_lock);
748 tx_bytes -= uio->uio_resid;
751 * If we made no progress, we're done. If we made even
752 * partial progress, update the znode and ZIL accordingly.
761 * Clear Set-UID/Set-GID bits on successful write if not
762 * privileged and at least one of the excute bits is set.
764 * It would be nice to to this after all writes have
765 * been done, but that would still expose the ISUID/ISGID
766 * to another app after the partial write is committed.
768 * Note: we don't call zfs_fuid_map_id() here because
769 * user 0 is not an ephemeral uid.
771 mutex_enter(&zp->z_acl_lock);
772 if ((zp->z_phys->zp_mode & (S_IXUSR | (S_IXUSR >> 3) |
773 (S_IXUSR >> 6))) != 0 &&
774 (zp->z_phys->zp_mode & (S_ISUID | S_ISGID)) != 0 &&
775 secpolicy_vnode_setid_retain(cr,
776 (zp->z_phys->zp_mode & S_ISUID) != 0 &&
777 zp->z_phys->zp_uid == 0) != 0) {
778 zp->z_phys->zp_mode &= ~(S_ISUID | S_ISGID);
780 mutex_exit(&zp->z_acl_lock);
783 * Update time stamp. NOTE: This marks the bonus buffer as
784 * dirty, so we don't have to do it again for zp_size.
786 zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
789 * Update the file size (zp_size) if it has changed;
790 * account for possible concurrent updates.
792 while ((end_size = zp->z_phys->zp_size) < uio->uio_loffset)
793 (void) atomic_cas_64(&zp->z_phys->zp_size, end_size,
795 zfs_log_write(zilog, tx, TX_WRITE, zp, woff, tx_bytes, ioflag);
800 ASSERT(tx_bytes == nbytes);
804 zfs_range_unlock(rl);
807 * If we're in replay mode, or we made no progress, return error.
808 * Otherwise, it's at least a partial write, so it's successful.
810 if (zfsvfs->z_assign >= TXG_INITIAL || uio->uio_resid == start_resid) {
815 if (ioflag & (FSYNC | FDSYNC))
816 zil_commit(zilog, zp->z_last_itx, zp->z_id);
823 zfs_get_done(dmu_buf_t *db, void *vzgd)
825 zgd_t *zgd = (zgd_t *)vzgd;
826 rl_t *rl = zgd->zgd_rl;
827 vnode_t *vp = ZTOV(rl->r_zp);
829 dmu_buf_rele(db, vzgd);
830 zfs_range_unlock(rl);
832 zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
833 kmem_free(zgd, sizeof (zgd_t));
837 * Get data to generate a TX_WRITE intent log record.
840 zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
842 zfsvfs_t *zfsvfs = arg;
843 objset_t *os = zfsvfs->z_os;
845 uint64_t off = lr->lr_offset;
849 int dlen = lr->lr_length; /* length of user data */
856 * Nothing to do if the file has been removed
858 if (zfs_zget(zfsvfs, lr->lr_foid, &zp) != 0)
860 if (zp->z_unlinked) {
866 * Write records come in two flavors: immediate and indirect.
867 * For small writes it's cheaper to store the data with the
868 * log record (immediate); for large writes it's cheaper to
869 * sync the data and get a pointer to it (indirect) so that
870 * we don't have to write the data twice.
872 if (buf != NULL) { /* immediate write */
873 rl = zfs_range_lock(zp, off, dlen, RL_READER);
874 /* test for truncation needs to be done while range locked */
875 if (off >= zp->z_phys->zp_size) {
879 VERIFY(0 == dmu_read(os, lr->lr_foid, off, dlen, buf));
880 } else { /* indirect write */
881 uint64_t boff; /* block starting offset */
884 * Have to lock the whole block to ensure when it's
885 * written out and it's checksum is being calculated
886 * that no one can change the data. We need to re-check
887 * blocksize after we get the lock in case it's changed!
890 if (ISP2(zp->z_blksz)) {
891 boff = P2ALIGN_TYPED(off, zp->z_blksz,
897 rl = zfs_range_lock(zp, boff, dlen, RL_READER);
898 if (zp->z_blksz == dlen)
900 zfs_range_unlock(rl);
902 /* test for truncation needs to be done while range locked */
903 if (off >= zp->z_phys->zp_size) {
907 zgd = (zgd_t *)kmem_alloc(sizeof (zgd_t), KM_SLEEP);
909 zgd->zgd_zilog = zfsvfs->z_log;
910 zgd->zgd_bp = &lr->lr_blkptr;
911 VERIFY(0 == dmu_buf_hold(os, lr->lr_foid, boff, zgd, &db));
912 ASSERT(boff == db->db_offset);
913 lr->lr_blkoff = off - boff;
914 error = dmu_sync(zio, db, &lr->lr_blkptr,
915 lr->lr_common.lrc_txg, zfs_get_done, zgd);
916 ASSERT((error && error != EINPROGRESS) ||
917 lr->lr_length <= zp->z_blksz);
919 zil_add_block(zfsvfs->z_log, &lr->lr_blkptr);
921 * If we get EINPROGRESS, then we need to wait for a
922 * write IO initiated by dmu_sync() to complete before
923 * we can release this dbuf. We will finish everything
924 * up in the zfs_get_done() callback.
926 if (error == EINPROGRESS)
928 dmu_buf_rele(db, zgd);
929 kmem_free(zgd, sizeof (zgd_t));
932 zfs_range_unlock(rl);
939 zfs_access(vnode_t *vp, int mode, int flag, cred_t *cr,
940 caller_context_t *ct)
942 znode_t *zp = VTOZ(vp);
943 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
949 if (flag & V_ACE_MASK)
950 error = zfs_zaccess(zp, mode, flag, B_FALSE, cr);
952 error = zfs_zaccess_rwx(zp, mode, flag, cr);
959 * Lookup an entry in a directory, or an extended attribute directory.
960 * If it exists, return a held vnode reference for it.
962 * IN: dvp - vnode of directory to search.
963 * nm - name of entry to lookup.
964 * pnp - full pathname to lookup [UNUSED].
965 * flags - LOOKUP_XATTR set if looking for an attribute.
966 * rdir - root directory vnode [UNUSED].
967 * cr - credentials of caller.
968 * ct - caller context
969 * direntflags - directory lookup flags
970 * realpnp - returned pathname.
972 * OUT: vpp - vnode of located entry, NULL if not found.
974 * RETURN: 0 if success
975 * error code if failure
982 zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp,
983 int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct,
984 int *direntflags, pathname_t *realpnp)
986 znode_t *zdp = VTOZ(dvp);
987 zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
995 if (flags & LOOKUP_XATTR) {
997 * If the xattr property is off, refuse the lookup request.
999 if (!(zfsvfs->z_vfs->vfs_flag & VFS_XATTR)) {
1005 * We don't allow recursive attributes..
1006 * Maybe someday we will.
1008 if (zdp->z_phys->zp_flags & ZFS_XATTR) {
1013 if (error = zfs_get_xattrdir(VTOZ(dvp), vpp, cr, flags)) {
1019 * Do we have permission to get into attribute directory?
1022 if (error = zfs_zaccess(VTOZ(*vpp), ACE_EXECUTE, 0,
1032 if (dvp->v_type != VDIR) {
1038 * Check accessibility of directory.
1041 if (error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr)) {
1046 if (zfsvfs->z_utf8 && u8_validate(nm, strlen(nm),
1047 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1052 error = zfs_dirlook(zdp, nm, vpp, flags, direntflags, realpnp);
1055 * Convert device special files
1057 if (IS_DEVVP(*vpp)) {
1060 svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
1074 * Attempt to create a new entry in a directory. If the entry
1075 * already exists, truncate the file if permissible, else return
1076 * an error. Return the vp of the created or trunc'd file.
1078 * IN: dvp - vnode of directory to put new file entry in.
1079 * name - name of new file entry.
1080 * vap - attributes of new file.
1081 * excl - flag indicating exclusive or non-exclusive mode.
1082 * mode - mode to open file with.
1083 * cr - credentials of caller.
1084 * flag - large file flag [UNUSED].
1085 * ct - caller context
1086 * vsecp - ACL to be set
1088 * OUT: vpp - vnode of created or trunc'd entry.
1090 * RETURN: 0 if success
1091 * error code if failure
1094 * dvp - ctime|mtime updated if new entry created
1095 * vp - ctime|mtime always, atime if new
1100 zfs_create(vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl,
1101 int mode, vnode_t **vpp, cred_t *cr, int flag, caller_context_t *ct,
1104 znode_t *zp, *dzp = VTOZ(dvp);
1105 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1111 zfs_acl_t *aclp = NULL;
1112 zfs_fuid_info_t *fuidp = NULL;
1115 gid_t gid = crgetgid(cr);
1118 * If we have an ephemeral id, ACL, or XVATTR then
1119 * make sure file system is at proper version
1122 ksid = crgetsid(cr, KSID_OWNER);
1124 uid = ksid_getid(ksid);
1128 if (zfsvfs->z_use_fuids == B_FALSE &&
1129 (vsecp || (vap->va_mask & AT_XVATTR) ||
1130 IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
1136 zilog = zfsvfs->z_log;
1138 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
1139 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1144 if (vap->va_mask & AT_XVATTR) {
1145 if ((error = secpolicy_xvattr((xvattr_t *)vap,
1146 crgetuid(cr), cr, vap->va_type)) != 0) {
1154 if ((vap->va_mode & VSVTX) && secpolicy_vnode_stky_modify(cr))
1155 vap->va_mode &= ~VSVTX;
1157 if (*name == '\0') {
1159 * Null component name refers to the directory itself.
1166 /* possible VN_HOLD(zp) */
1169 if (flag & FIGNORECASE)
1172 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1175 if (strcmp(name, "..") == 0)
1183 if (vsecp && aclp == NULL) {
1184 error = zfs_vsec_2_aclp(zfsvfs, vap->va_type, vsecp, &aclp);
1188 zfs_dirent_unlock(dl);
1197 * Create a new file object and update the directory
1200 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
1205 * We only support the creation of regular files in
1206 * extended attribute directories.
1208 if ((dzp->z_phys->zp_flags & ZFS_XATTR) &&
1209 (vap->va_type != VREG)) {
1214 tx = dmu_tx_create(os);
1215 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1216 if ((aclp && aclp->z_has_fuids) || IS_EPHEMERAL(uid) ||
1217 IS_EPHEMERAL(gid)) {
1218 if (zfsvfs->z_fuid_obj == 0) {
1219 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1220 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
1221 FUID_SIZE_ESTIMATE(zfsvfs));
1222 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ,
1225 dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj);
1226 dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0,
1227 FUID_SIZE_ESTIMATE(zfsvfs));
1230 dmu_tx_hold_bonus(tx, dzp->z_id);
1231 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
1232 if ((dzp->z_phys->zp_flags & ZFS_INHERIT_ACE) || aclp) {
1233 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
1234 0, SPA_MAXBLOCKSIZE);
1236 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1238 zfs_dirent_unlock(dl);
1239 if (error == ERESTART &&
1240 zfsvfs->z_assign == TXG_NOWAIT) {
1251 zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, aclp, &fuidp);
1252 (void) zfs_link_create(dl, zp, tx, ZNEW);
1253 txtype = zfs_log_create_txtype(Z_FILE, vsecp, vap);
1254 if (flag & FIGNORECASE)
1256 zfs_log_create(zilog, tx, txtype, dzp, zp, name,
1259 zfs_fuid_info_free(fuidp);
1262 int aflags = (flag & FAPPEND) ? V_APPEND : 0;
1265 * A directory entry already exists for this name.
1268 * Can't truncate an existing file if in exclusive mode.
1275 * Can't open a directory for writing.
1277 if ((ZTOV(zp)->v_type == VDIR) && (mode & S_IWRITE)) {
1282 * Verify requested access to file.
1284 if (mode && (error = zfs_zaccess_rwx(zp, mode, aflags, cr))) {
1288 mutex_enter(&dzp->z_lock);
1290 mutex_exit(&dzp->z_lock);
1293 * Truncate regular files if requested.
1295 if ((ZTOV(zp)->v_type == VREG) &&
1296 (vap->va_mask & AT_SIZE) && (vap->va_size == 0)) {
1297 /* we can't hold any locks when calling zfs_freesp() */
1298 zfs_dirent_unlock(dl);
1300 error = zfs_freesp(zp, 0, 0, mode, TRUE);
1302 vnevent_create(ZTOV(zp), ct);
1309 zfs_dirent_unlock(dl);
1317 * If vnode is for a device return a specfs vnode instead.
1319 if (IS_DEVVP(*vpp)) {
1322 svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
1338 * Remove an entry from a directory.
1340 * IN: dvp - vnode of directory to remove entry from.
1341 * name - name of entry to remove.
1342 * cr - credentials of caller.
1343 * ct - caller context
1344 * flags - case flags
1346 * RETURN: 0 if success
1347 * error code if failure
1351 * vp - ctime (if nlink > 0)
1355 zfs_remove(vnode_t *dvp, char *name, cred_t *cr, caller_context_t *ct,
1358 znode_t *zp, *dzp = VTOZ(dvp);
1359 znode_t *xzp = NULL;
1361 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1363 uint64_t acl_obj, xattr_obj;
1366 boolean_t may_delete_now, delete_now = FALSE;
1367 boolean_t unlinked, toobig = FALSE;
1369 pathname_t *realnmp = NULL;
1376 zilog = zfsvfs->z_log;
1378 if (flags & FIGNORECASE) {
1386 * Attempt to lock directory; fail if entry doesn't exist.
1388 if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1398 if (error = zfs_zaccess_delete(dzp, zp, cr)) {
1403 * Need to use rmdir for removing directories.
1405 if (vp->v_type == VDIR) {
1410 vnevent_remove(vp, dvp, name, ct);
1413 dnlc_remove(dvp, realnmp->pn_buf);
1415 dnlc_remove(dvp, name);
1417 mutex_enter(&vp->v_lock);
1418 may_delete_now = vp->v_count == 1 && !vn_has_cached_data(vp);
1419 mutex_exit(&vp->v_lock);
1422 * We may delete the znode now, or we may put it in the unlinked set;
1423 * it depends on whether we're the last link, and on whether there are
1424 * other holds on the vnode. So we dmu_tx_hold() the right things to
1425 * allow for either case.
1427 tx = dmu_tx_create(zfsvfs->z_os);
1428 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1429 dmu_tx_hold_bonus(tx, zp->z_id);
1430 if (may_delete_now) {
1432 zp->z_phys->zp_size > zp->z_blksz * DMU_MAX_DELETEBLKCNT;
1433 /* if the file is too big, only hold_free a token amount */
1434 dmu_tx_hold_free(tx, zp->z_id, 0,
1435 (toobig ? DMU_MAX_ACCESS : DMU_OBJECT_END));
1438 /* are there any extended attributes? */
1439 if ((xattr_obj = zp->z_phys->zp_xattr) != 0) {
1440 /* XXX - do we need this if we are deleting? */
1441 dmu_tx_hold_bonus(tx, xattr_obj);
1444 /* are there any additional acls */
1445 if ((acl_obj = zp->z_phys->zp_acl.z_acl_extern_obj) != 0 &&
1447 dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END);
1449 /* charge as an update -- would be nice not to charge at all */
1450 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1452 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1454 zfs_dirent_unlock(dl);
1456 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
1469 * Remove the directory entry.
1471 error = zfs_link_destroy(dl, zp, tx, zflg, &unlinked);
1479 mutex_enter(&vp->v_lock);
1480 delete_now = may_delete_now && !toobig &&
1481 vp->v_count == 1 && !vn_has_cached_data(vp) &&
1482 zp->z_phys->zp_xattr == xattr_obj &&
1483 zp->z_phys->zp_acl.z_acl_extern_obj == acl_obj;
1484 mutex_exit(&vp->v_lock);
1488 if (zp->z_phys->zp_xattr) {
1489 error = zfs_zget(zfsvfs, zp->z_phys->zp_xattr, &xzp);
1490 ASSERT3U(error, ==, 0);
1491 ASSERT3U(xzp->z_phys->zp_links, ==, 2);
1492 dmu_buf_will_dirty(xzp->z_dbuf, tx);
1493 mutex_enter(&xzp->z_lock);
1494 xzp->z_unlinked = 1;
1495 xzp->z_phys->zp_links = 0;
1496 mutex_exit(&xzp->z_lock);
1497 zfs_unlinked_add(xzp, tx);
1498 zp->z_phys->zp_xattr = 0; /* probably unnecessary */
1500 mutex_enter(&zp->z_lock);
1501 mutex_enter(&vp->v_lock);
1503 ASSERT3U(vp->v_count, ==, 0);
1504 mutex_exit(&vp->v_lock);
1505 mutex_exit(&zp->z_lock);
1506 zfs_znode_delete(zp, tx);
1507 } else if (unlinked) {
1508 zfs_unlinked_add(zp, tx);
1512 if (flags & FIGNORECASE)
1514 zfs_log_remove(zilog, tx, txtype, dzp, name);
1521 zfs_dirent_unlock(dl);
1526 /* this rele is delayed to prevent nesting transactions */
1535 * Create a new directory and insert it into dvp using the name
1536 * provided. Return a pointer to the inserted directory.
1538 * IN: dvp - vnode of directory to add subdir to.
1539 * dirname - name of new directory.
1540 * vap - attributes of new directory.
1541 * cr - credentials of caller.
1542 * ct - caller context
1543 * vsecp - ACL to be set
1545 * OUT: vpp - vnode of created directory.
1547 * RETURN: 0 if success
1548 * error code if failure
1551 * dvp - ctime|mtime updated
1552 * vp - ctime|mtime|atime updated
1556 zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr,
1557 caller_context_t *ct, int flags, vsecattr_t *vsecp)
1559 znode_t *zp, *dzp = VTOZ(dvp);
1560 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1566 zfs_acl_t *aclp = NULL;
1567 zfs_fuid_info_t *fuidp = NULL;
1571 gid_t gid = crgetgid(cr);
1573 ASSERT(vap->va_type == VDIR);
1576 * If we have an ephemeral id, ACL, or XVATTR then
1577 * make sure file system is at proper version
1580 ksid = crgetsid(cr, KSID_OWNER);
1582 uid = ksid_getid(ksid);
1585 if (zfsvfs->z_use_fuids == B_FALSE &&
1586 (vsecp || (vap->va_mask & AT_XVATTR) ||
1587 IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
1592 zilog = zfsvfs->z_log;
1594 if (dzp->z_phys->zp_flags & ZFS_XATTR) {
1599 if (zfsvfs->z_utf8 && u8_validate(dirname,
1600 strlen(dirname), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1604 if (flags & FIGNORECASE)
1607 if (vap->va_mask & AT_XVATTR)
1608 if ((error = secpolicy_xvattr((xvattr_t *)vap,
1609 crgetuid(cr), cr, vap->va_type)) != 0) {
1615 * First make sure the new directory doesn't exist.
1620 if (error = zfs_dirent_lock(&dl, dzp, dirname, &zp, zf,
1626 if (error = zfs_zaccess(dzp, ACE_ADD_SUBDIRECTORY, 0, B_FALSE, cr)) {
1627 zfs_dirent_unlock(dl);
1632 if (vsecp && aclp == NULL) {
1633 error = zfs_vsec_2_aclp(zfsvfs, vap->va_type, vsecp, &aclp);
1635 zfs_dirent_unlock(dl);
1641 * Add a new entry to the directory.
1643 tx = dmu_tx_create(zfsvfs->z_os);
1644 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, dirname);
1645 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
1646 if ((aclp && aclp->z_has_fuids) || IS_EPHEMERAL(uid) ||
1647 IS_EPHEMERAL(gid)) {
1648 if (zfsvfs->z_fuid_obj == 0) {
1649 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1650 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
1651 FUID_SIZE_ESTIMATE(zfsvfs));
1652 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, FALSE, NULL);
1654 dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj);
1655 dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0,
1656 FUID_SIZE_ESTIMATE(zfsvfs));
1659 if ((dzp->z_phys->zp_flags & ZFS_INHERIT_ACE) || aclp)
1660 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
1661 0, SPA_MAXBLOCKSIZE);
1662 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1664 zfs_dirent_unlock(dl);
1665 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
1680 zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, aclp, &fuidp);
1686 * Now put new name in parent dir.
1688 (void) zfs_link_create(dl, zp, tx, ZNEW);
1692 txtype = zfs_log_create_txtype(Z_DIR, vsecp, vap);
1693 if (flags & FIGNORECASE)
1695 zfs_log_create(zilog, tx, txtype, dzp, zp, dirname, vsecp, fuidp, vap);
1698 zfs_fuid_info_free(fuidp);
1701 zfs_dirent_unlock(dl);
1708 * Remove a directory subdir entry. If the current working
1709 * directory is the same as the subdir to be removed, the
1712 * IN: dvp - vnode of directory to remove from.
1713 * name - name of directory to be removed.
1714 * cwd - vnode of current working directory.
1715 * cr - credentials of caller.
1716 * ct - caller context
1717 * flags - case flags
1719 * RETURN: 0 if success
1720 * error code if failure
1723 * dvp - ctime|mtime updated
1727 zfs_rmdir(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr,
1728 caller_context_t *ct, int flags)
1730 znode_t *dzp = VTOZ(dvp);
1733 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1742 zilog = zfsvfs->z_log;
1744 if (flags & FIGNORECASE)
1750 * Attempt to lock directory; fail if entry doesn't exist.
1752 if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1760 if (error = zfs_zaccess_delete(dzp, zp, cr)) {
1764 if (vp->v_type != VDIR) {
1774 vnevent_rmdir(vp, dvp, name, ct);
1777 * Grab a lock on the directory to make sure that noone is
1778 * trying to add (or lookup) entries while we are removing it.
1780 rw_enter(&zp->z_name_lock, RW_WRITER);
1783 * Grab a lock on the parent pointer to make sure we play well
1784 * with the treewalk and directory rename code.
1786 rw_enter(&zp->z_parent_lock, RW_WRITER);
1788 tx = dmu_tx_create(zfsvfs->z_os);
1789 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1790 dmu_tx_hold_bonus(tx, zp->z_id);
1791 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1792 error = dmu_tx_assign(tx, zfsvfs->z_assign);
1794 rw_exit(&zp->z_parent_lock);
1795 rw_exit(&zp->z_name_lock);
1796 zfs_dirent_unlock(dl);
1798 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
1808 error = zfs_link_destroy(dl, zp, tx, zflg, NULL);
1811 uint64_t txtype = TX_RMDIR;
1812 if (flags & FIGNORECASE)
1814 zfs_log_remove(zilog, tx, txtype, dzp, name);
1819 rw_exit(&zp->z_parent_lock);
1820 rw_exit(&zp->z_name_lock);
1822 zfs_dirent_unlock(dl);
1831 * Read as many directory entries as will fit into the provided
1832 * buffer from the given directory cursor position (specified in
1833 * the uio structure.
1835 * IN: vp - vnode of directory to read.
1836 * uio - structure supplying read location, range info,
1837 * and return buffer.
1838 * cr - credentials of caller.
1839 * ct - caller context
1840 * flags - case flags
1842 * OUT: uio - updated offset and range, buffer filled.
1843 * eofp - set to true if end-of-file detected.
1845 * RETURN: 0 if success
1846 * error code if failure
1849 * vp - atime updated
1851 * Note that the low 4 bits of the cookie returned by zap is always zero.
1852 * This allows us to use the low range for "special" directory entries:
1853 * We use 0 for '.', and 1 for '..'. If this is the root of the filesystem,
1854 * we use the offset 2 for the '.zfs' directory.
1858 zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp,
1859 caller_context_t *ct, int flags)
1861 znode_t *zp = VTOZ(vp);
1865 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1870 zap_attribute_t zap;
1871 uint_t bytes_wanted;
1872 uint64_t offset; /* must be unsigned; checks for < 1 */
1877 boolean_t check_sysattrs;
1883 * If we are not given an eof variable,
1890 * Check for valid iov_len.
1892 if (uio->uio_iov->iov_len <= 0) {
1898 * Quit if directory has been removed (posix)
1900 if ((*eofp = zp->z_unlinked) != 0) {
1907 offset = uio->uio_loffset;
1908 prefetch = zp->z_zn_prefetch;
1911 * Initialize the iterator cursor.
1915 * Start iteration from the beginning of the directory.
1917 zap_cursor_init(&zc, os, zp->z_id);
1920 * The offset is a serialized cursor.
1922 zap_cursor_init_serialized(&zc, os, zp->z_id, offset);
1926 * Get space to change directory entries into fs independent format.
1928 iovp = uio->uio_iov;
1929 bytes_wanted = iovp->iov_len;
1930 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) {
1931 bufsize = bytes_wanted;
1932 outbuf = kmem_alloc(bufsize, KM_SLEEP);
1933 odp = (struct dirent64 *)outbuf;
1935 bufsize = bytes_wanted;
1936 odp = (struct dirent64 *)iovp->iov_base;
1938 eodp = (struct edirent *)odp;
1941 * If this VFS supports the system attribute view interface; and
1942 * we're looking at an extended attribute directory; and we care
1943 * about normalization conflicts on this vfs; then we must check
1944 * for normalization conflicts with the sysattr name space.
1946 check_sysattrs = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
1947 (vp->v_flag & V_XATTRDIR) && zfsvfs->z_norm &&
1948 (flags & V_RDDIR_ENTFLAGS);
1951 * Transform to file-system independent format
1954 while (outcount < bytes_wanted) {
1960 * Special case `.', `..', and `.zfs'.
1963 (void) strcpy(zap.za_name, ".");
1964 zap.za_normalization_conflict = 0;
1966 } else if (offset == 1) {
1967 (void) strcpy(zap.za_name, "..");
1968 zap.za_normalization_conflict = 0;
1969 objnum = zp->z_phys->zp_parent;
1970 } else if (offset == 2 && zfs_show_ctldir(zp)) {
1971 (void) strcpy(zap.za_name, ZFS_CTLDIR_NAME);
1972 zap.za_normalization_conflict = 0;
1973 objnum = ZFSCTL_INO_ROOT;
1978 if (error = zap_cursor_retrieve(&zc, &zap)) {
1979 if ((*eofp = (error == ENOENT)) != 0)
1985 if (zap.za_integer_length != 8 ||
1986 zap.za_num_integers != 1) {
1987 cmn_err(CE_WARN, "zap_readdir: bad directory "
1988 "entry, obj = %lld, offset = %lld\n",
1989 (u_longlong_t)zp->z_id,
1990 (u_longlong_t)offset);
1995 objnum = ZFS_DIRENT_OBJ(zap.za_first_integer);
1997 * MacOS X can extract the object type here such as:
1998 * uint8_t type = ZFS_DIRENT_TYPE(zap.za_first_integer);
2001 if (check_sysattrs && !zap.za_normalization_conflict) {
2002 zap.za_normalization_conflict =
2003 xattr_sysattr_casechk(zap.za_name);
2007 if (flags & V_RDDIR_ENTFLAGS)
2008 reclen = EDIRENT_RECLEN(strlen(zap.za_name));
2010 reclen = DIRENT64_RECLEN(strlen(zap.za_name));
2013 * Will this entry fit in the buffer?
2015 if (outcount + reclen > bufsize) {
2017 * Did we manage to fit anything in the buffer?
2025 if (flags & V_RDDIR_ENTFLAGS) {
2027 * Add extended flag entry:
2029 eodp->ed_ino = objnum;
2030 eodp->ed_reclen = reclen;
2031 /* NOTE: ed_off is the offset for the *next* entry */
2032 next = &(eodp->ed_off);
2033 eodp->ed_eflags = zap.za_normalization_conflict ?
2034 ED_CASE_CONFLICT : 0;
2035 (void) strncpy(eodp->ed_name, zap.za_name,
2036 EDIRENT_NAMELEN(reclen));
2037 eodp = (edirent_t *)((intptr_t)eodp + reclen);
2042 odp->d_ino = objnum;
2043 odp->d_reclen = reclen;
2044 /* NOTE: d_off is the offset for the *next* entry */
2045 next = &(odp->d_off);
2046 (void) strncpy(odp->d_name, zap.za_name,
2047 DIRENT64_NAMELEN(reclen));
2048 odp = (dirent64_t *)((intptr_t)odp + reclen);
2052 ASSERT(outcount <= bufsize);
2054 /* Prefetch znode */
2056 dmu_prefetch(os, objnum, 0, 0);
2059 * Move to the next entry, fill in the previous offset.
2061 if (offset > 2 || (offset == 2 && !zfs_show_ctldir(zp))) {
2062 zap_cursor_advance(&zc);
2063 offset = zap_cursor_serialize(&zc);
2069 zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */
2071 if (uio->uio_segflg == UIO_SYSSPACE && uio->uio_iovcnt == 1) {
2072 iovp->iov_base += outcount;
2073 iovp->iov_len -= outcount;
2074 uio->uio_resid -= outcount;
2075 } else if (error = uiomove(outbuf, (long)outcount, UIO_READ, uio)) {
2077 * Reset the pointer.
2079 offset = uio->uio_loffset;
2083 zap_cursor_fini(&zc);
2084 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
2085 kmem_free(outbuf, bufsize);
2087 if (error == ENOENT)
2090 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
2092 uio->uio_loffset = offset;
2097 ulong_t zfs_fsync_sync_cnt = 4;
2100 zfs_fsync(vnode_t *vp, int syncflag, cred_t *cr, caller_context_t *ct)
2102 znode_t *zp = VTOZ(vp);
2103 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2106 * Regardless of whether this is required for standards conformance,
2107 * this is the logical behavior when fsync() is called on a file with
2108 * dirty pages. We use B_ASYNC since the ZIL transactions are already
2109 * going to be pushed out as part of the zil_commit().
2111 if (vn_has_cached_data(vp) && !(syncflag & FNODSYNC) &&
2112 (vp->v_type == VREG) && !(IS_SWAPVP(vp)))
2113 (void) VOP_PUTPAGE(vp, (offset_t)0, (size_t)0, B_ASYNC, cr, ct);
2115 (void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt);
2119 zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
2126 * Get the requested file attributes and place them in the provided
2129 * IN: vp - vnode of file.
2130 * vap - va_mask identifies requested attributes.
2131 * If AT_XVATTR set, then optional attrs are requested
2132 * flags - ATTR_NOACLCHECK (CIFS server context)
2133 * cr - credentials of caller.
2134 * ct - caller context
2136 * OUT: vap - attribute values.
2138 * RETURN: 0 (always succeeds)
2142 zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2143 caller_context_t *ct)
2145 znode_t *zp = VTOZ(vp);
2146 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2150 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2151 xoptattr_t *xoap = NULL;
2152 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2158 mutex_enter(&zp->z_lock);
2161 * If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES.
2162 * Also, if we are the owner don't bother, since owner should
2163 * always be allowed to read basic attributes of file.
2165 if (!(pzp->zp_flags & ZFS_ACL_TRIVIAL) &&
2166 (pzp->zp_uid != crgetuid(cr))) {
2167 if (error = zfs_zaccess(zp, ACE_READ_ATTRIBUTES, 0,
2169 mutex_exit(&zp->z_lock);
2176 * Return all attributes. It's cheaper to provide the answer
2177 * than to determine whether we were asked the question.
2180 vap->va_type = vp->v_type;
2181 vap->va_mode = pzp->zp_mode & MODEMASK;
2182 zfs_fuid_map_ids(zp, cr, &vap->va_uid, &vap->va_gid);
2183 vap->va_fsid = zp->z_zfsvfs->z_vfs->vfs_dev;
2184 vap->va_nodeid = zp->z_id;
2185 if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp))
2186 links = pzp->zp_links + 1;
2188 links = pzp->zp_links;
2189 vap->va_nlink = MIN(links, UINT32_MAX); /* nlink_t limit! */
2190 vap->va_size = pzp->zp_size;
2191 vap->va_rdev = vp->v_rdev;
2192 vap->va_seq = zp->z_seq;
2195 * Add in any requested optional attributes and the create time.
2196 * Also set the corresponding bits in the returned attribute bitmap.
2198 if ((xoap = xva_getxoptattr(xvap)) != NULL && zfsvfs->z_use_fuids) {
2199 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
2201 ((pzp->zp_flags & ZFS_ARCHIVE) != 0);
2202 XVA_SET_RTN(xvap, XAT_ARCHIVE);
2205 if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
2206 xoap->xoa_readonly =
2207 ((pzp->zp_flags & ZFS_READONLY) != 0);
2208 XVA_SET_RTN(xvap, XAT_READONLY);
2211 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
2213 ((pzp->zp_flags & ZFS_SYSTEM) != 0);
2214 XVA_SET_RTN(xvap, XAT_SYSTEM);
2217 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
2219 ((pzp->zp_flags & ZFS_HIDDEN) != 0);
2220 XVA_SET_RTN(xvap, XAT_HIDDEN);
2223 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
2224 xoap->xoa_nounlink =
2225 ((pzp->zp_flags & ZFS_NOUNLINK) != 0);
2226 XVA_SET_RTN(xvap, XAT_NOUNLINK);
2229 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
2230 xoap->xoa_immutable =
2231 ((pzp->zp_flags & ZFS_IMMUTABLE) != 0);
2232 XVA_SET_RTN(xvap, XAT_IMMUTABLE);
2235 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
2236 xoap->xoa_appendonly =
2237 ((pzp->zp_flags & ZFS_APPENDONLY) != 0);
2238 XVA_SET_RTN(xvap, XAT_APPENDONLY);
2241 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
2243 ((pzp->zp_flags & ZFS_NODUMP) != 0);
2244 XVA_SET_RTN(xvap, XAT_NODUMP);
2247 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
2249 ((pzp->zp_flags & ZFS_OPAQUE) != 0);
2250 XVA_SET_RTN(xvap, XAT_OPAQUE);
2253 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
2254 xoap->xoa_av_quarantined =
2255 ((pzp->zp_flags & ZFS_AV_QUARANTINED) != 0);
2256 XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
2259 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
2260 xoap->xoa_av_modified =
2261 ((pzp->zp_flags & ZFS_AV_MODIFIED) != 0);
2262 XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
2265 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) &&
2266 vp->v_type == VREG &&
2267 (pzp->zp_flags & ZFS_BONUS_SCANSTAMP)) {
2269 dmu_object_info_t doi;
2272 * Only VREG files have anti-virus scanstamps, so we
2273 * won't conflict with symlinks in the bonus buffer.
2275 dmu_object_info_from_db(zp->z_dbuf, &doi);
2276 len = sizeof (xoap->xoa_av_scanstamp) +
2277 sizeof (znode_phys_t);
2278 if (len <= doi.doi_bonus_size) {
2280 * pzp points to the start of the
2281 * znode_phys_t. pzp + 1 points to the
2282 * first byte after the znode_phys_t.
2284 (void) memcpy(xoap->xoa_av_scanstamp,
2286 sizeof (xoap->xoa_av_scanstamp));
2287 XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
2291 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
2292 ZFS_TIME_DECODE(&xoap->xoa_createtime, pzp->zp_crtime);
2293 XVA_SET_RTN(xvap, XAT_CREATETIME);
2297 ZFS_TIME_DECODE(&vap->va_atime, pzp->zp_atime);
2298 ZFS_TIME_DECODE(&vap->va_mtime, pzp->zp_mtime);
2299 ZFS_TIME_DECODE(&vap->va_ctime, pzp->zp_ctime);
2301 mutex_exit(&zp->z_lock);
2303 dmu_object_size_from_db(zp->z_dbuf, &vap->va_blksize, &vap->va_nblocks);
2305 if (zp->z_blksz == 0) {
2307 * Block size hasn't been set; suggest maximal I/O transfers.
2309 vap->va_blksize = zfsvfs->z_max_blksz;
2317 * Set the file attributes to the values contained in the
2320 * IN: vp - vnode of file to be modified.
2321 * vap - new attribute values.
2322 * If AT_XVATTR set, then optional attrs are being set
2323 * flags - ATTR_UTIME set if non-default time values provided.
2324 * - ATTR_NOACLCHECK (CIFS context only).
2325 * cr - credentials of caller.
2326 * ct - caller context
2328 * RETURN: 0 if success
2329 * error code if failure
2332 * vp - ctime updated, mtime updated if size changed.
2336 zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2337 caller_context_t *ct)
2339 znode_t *zp = VTOZ(vp);
2341 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2345 uint_t mask = vap->va_mask;
2350 int need_policy = FALSE;
2352 zfs_fuid_info_t *fuidp = NULL;
2353 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2355 zfs_acl_t *aclp = NULL;
2356 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2361 if (mask & AT_NOSET)
2368 zilog = zfsvfs->z_log;
2371 * Make sure that if we have ephemeral uid/gid or xvattr specified
2372 * that file system is at proper version level
2375 if (zfsvfs->z_use_fuids == B_FALSE &&
2376 (((mask & AT_UID) && IS_EPHEMERAL(vap->va_uid)) ||
2377 ((mask & AT_GID) && IS_EPHEMERAL(vap->va_gid)) ||
2378 (mask & AT_XVATTR))) {
2383 if (mask & AT_SIZE && vp->v_type == VDIR) {
2388 if (mask & AT_SIZE && vp->v_type != VREG && vp->v_type != VFIFO) {
2394 * If this is an xvattr_t, then get a pointer to the structure of
2395 * optional attributes. If this is NULL, then we have a vattr_t.
2397 xoap = xva_getxoptattr(xvap);
2400 * Immutable files can only alter immutable bit and atime
2402 if ((pzp->zp_flags & ZFS_IMMUTABLE) &&
2403 ((mask & (AT_SIZE|AT_UID|AT_GID|AT_MTIME|AT_MODE)) ||
2404 ((mask & AT_XVATTR) && XVA_ISSET_REQ(xvap, XAT_CREATETIME)))) {
2409 if ((mask & AT_SIZE) && (pzp->zp_flags & ZFS_READONLY)) {
2415 * Verify timestamps doesn't overflow 32 bits.
2416 * ZFS can handle large timestamps, but 32bit syscalls can't
2417 * handle times greater than 2039. This check should be removed
2418 * once large timestamps are fully supported.
2420 if (mask & (AT_ATIME | AT_MTIME)) {
2421 if (((mask & AT_ATIME) && TIMESPEC_OVERFLOW(&vap->va_atime)) ||
2422 ((mask & AT_MTIME) && TIMESPEC_OVERFLOW(&vap->va_mtime))) {
2431 if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) {
2437 * First validate permissions
2440 if (mask & AT_SIZE) {
2441 err = zfs_zaccess(zp, ACE_WRITE_DATA, 0, skipaclchk, cr);
2447 * XXX - Note, we are not providing any open
2448 * mode flags here (like FNDELAY), so we may
2449 * block if there are locks present... this
2450 * should be addressed in openat().
2452 /* XXX - would it be OK to generate a log record here? */
2453 err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE);
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);
2724 /* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
2726 zfs_time_stamper_locked(zp, CONTENT_MODIFIED, tx);
2728 zfs_time_stamper_locked(zp, STATE_CHANGED, tx);
2730 * Do this after setting timestamps to prevent timestamp
2731 * update from toggling bit
2734 if (xoap && (mask & AT_XVATTR)) {
2735 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
2737 dmu_object_info_t doi;
2739 ASSERT(vp->v_type == VREG);
2741 /* Grow the bonus buffer if necessary. */
2742 dmu_object_info_from_db(zp->z_dbuf, &doi);
2743 len = sizeof (xoap->xoa_av_scanstamp) +
2744 sizeof (znode_phys_t);
2745 if (len > doi.doi_bonus_size)
2746 VERIFY(dmu_set_bonus(zp->z_dbuf, len, tx) == 0);
2748 zfs_xvattr_set(zp, xvap);
2752 zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp);
2755 zfs_fuid_info_free(fuidp);
2756 mutex_exit(&zp->z_lock);
2759 VN_RELE(ZTOV(attrzp));
2767 typedef struct zfs_zlock {
2768 krwlock_t *zl_rwlock; /* lock we acquired */
2769 znode_t *zl_znode; /* znode we held */
2770 struct zfs_zlock *zl_next; /* next in list */
2774 * Drop locks and release vnodes that were held by zfs_rename_lock().
2777 zfs_rename_unlock(zfs_zlock_t **zlpp)
2781 while ((zl = *zlpp) != NULL) {
2782 if (zl->zl_znode != NULL)
2783 VN_RELE(ZTOV(zl->zl_znode));
2784 rw_exit(zl->zl_rwlock);
2785 *zlpp = zl->zl_next;
2786 kmem_free(zl, sizeof (*zl));
2791 * Search back through the directory tree, using the ".." entries.
2792 * Lock each directory in the chain to prevent concurrent renames.
2793 * Fail any attempt to move a directory into one of its own descendants.
2794 * XXX - z_parent_lock can overlap with map or grow locks
2797 zfs_rename_lock(znode_t *szp, znode_t *tdzp, znode_t *sdzp, zfs_zlock_t **zlpp)
2801 uint64_t rootid = zp->z_zfsvfs->z_root;
2802 uint64_t *oidp = &zp->z_id;
2803 krwlock_t *rwlp = &szp->z_parent_lock;
2804 krw_t rw = RW_WRITER;
2807 * First pass write-locks szp and compares to zp->z_id.
2808 * Later passes read-lock zp and compare to zp->z_parent.
2811 if (!rw_tryenter(rwlp, rw)) {
2813 * Another thread is renaming in this path.
2814 * Note that if we are a WRITER, we don't have any
2815 * parent_locks held yet.
2817 if (rw == RW_READER && zp->z_id > szp->z_id) {
2819 * Drop our locks and restart
2821 zfs_rename_unlock(&zl);
2825 rwlp = &szp->z_parent_lock;
2830 * Wait for other thread to drop its locks
2836 zl = kmem_alloc(sizeof (*zl), KM_SLEEP);
2837 zl->zl_rwlock = rwlp;
2838 zl->zl_znode = NULL;
2839 zl->zl_next = *zlpp;
2842 if (*oidp == szp->z_id) /* We're a descendant of szp */
2845 if (*oidp == rootid) /* We've hit the top */
2848 if (rw == RW_READER) { /* i.e. not the first pass */
2849 int error = zfs_zget(zp->z_zfsvfs, *oidp, &zp);
2854 oidp = &zp->z_phys->zp_parent;
2855 rwlp = &zp->z_parent_lock;
2858 } while (zp->z_id != sdzp->z_id);
2864 * Move an entry from the provided source directory to the target
2865 * directory. Change the entry name as indicated.
2867 * IN: sdvp - Source directory containing the "old entry".
2868 * snm - Old entry name.
2869 * tdvp - Target directory to contain the "new entry".
2870 * tnm - New entry name.
2871 * cr - credentials of caller.
2872 * ct - caller context
2873 * flags - case flags
2875 * RETURN: 0 if success
2876 * error code if failure
2879 * sdvp,tdvp - ctime|mtime updated
2883 zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr,
2884 caller_context_t *ct, int flags)
2886 znode_t *tdzp, *szp, *tzp;
2887 znode_t *sdzp = VTOZ(sdvp);
2888 zfsvfs_t *zfsvfs = sdzp->z_zfsvfs;
2891 zfs_dirlock_t *sdl, *tdl;
2894 int cmp, serr, terr;
2899 ZFS_VERIFY_ZP(sdzp);
2900 zilog = zfsvfs->z_log;
2903 * Make sure we have the real vp for the target directory.
2905 if (VOP_REALVP(tdvp, &realvp, ct) == 0)
2908 if (tdvp->v_vfsp != sdvp->v_vfsp) {
2914 ZFS_VERIFY_ZP(tdzp);
2915 if (zfsvfs->z_utf8 && u8_validate(tnm,
2916 strlen(tnm), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
2921 if (flags & FIGNORECASE)
2930 * This is to prevent the creation of links into attribute space
2931 * by renaming a linked file into/outof an attribute directory.
2932 * See the comment in zfs_link() for why this is considered bad.
2934 if ((tdzp->z_phys->zp_flags & ZFS_XATTR) !=
2935 (sdzp->z_phys->zp_flags & ZFS_XATTR)) {
2941 * Lock source and target directory entries. To prevent deadlock,
2942 * a lock ordering must be defined. We lock the directory with
2943 * the smallest object id first, or if it's a tie, the one with
2944 * the lexically first name.
2946 if (sdzp->z_id < tdzp->z_id) {
2948 } else if (sdzp->z_id > tdzp->z_id) {
2952 * First compare the two name arguments without
2953 * considering any case folding.
2955 int nofold = (zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER);
2957 cmp = u8_strcmp(snm, tnm, 0, nofold, U8_UNICODE_LATEST, &error);
2958 ASSERT(error == 0 || !zfsvfs->z_utf8);
2961 * POSIX: "If the old argument and the new argument
2962 * both refer to links to the same existing file,
2963 * the rename() function shall return successfully
2964 * and perform no other action."
2970 * If the file system is case-folding, then we may
2971 * have some more checking to do. A case-folding file
2972 * system is either supporting mixed case sensitivity
2973 * access or is completely case-insensitive. Note
2974 * that the file system is always case preserving.
2976 * In mixed sensitivity mode case sensitive behavior
2977 * is the default. FIGNORECASE must be used to
2978 * explicitly request case insensitive behavior.
2980 * If the source and target names provided differ only
2981 * by case (e.g., a request to rename 'tim' to 'Tim'),
2982 * we will treat this as a special case in the
2983 * case-insensitive mode: as long as the source name
2984 * is an exact match, we will allow this to proceed as
2985 * a name-change request.
2987 if ((zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
2988 (zfsvfs->z_case == ZFS_CASE_MIXED &&
2989 flags & FIGNORECASE)) &&
2990 u8_strcmp(snm, tnm, 0, zfsvfs->z_norm, U8_UNICODE_LATEST,
2993 * case preserving rename request, require exact
3002 serr = zfs_dirent_lock(&sdl, sdzp, snm, &szp,
3003 ZEXISTS | zflg, NULL, NULL);
3004 terr = zfs_dirent_lock(&tdl,
3005 tdzp, tnm, &tzp, ZRENAMING | zflg, NULL, NULL);
3007 terr = zfs_dirent_lock(&tdl,
3008 tdzp, tnm, &tzp, zflg, NULL, NULL);
3009 serr = zfs_dirent_lock(&sdl,
3010 sdzp, snm, &szp, ZEXISTS | ZRENAMING | zflg,
3016 * Source entry invalid or not there.
3019 zfs_dirent_unlock(tdl);
3023 if (strcmp(snm, "..") == 0)
3029 zfs_dirent_unlock(sdl);
3031 if (strcmp(tnm, "..") == 0)
3038 * Must have write access at the source to remove the old entry
3039 * and write access at the target to create the new entry.
3040 * Note that if target and source are the same, this can be
3041 * done in a single check.
3044 if (error = zfs_zaccess_rename(sdzp, szp, tdzp, tzp, cr))
3047 if (ZTOV(szp)->v_type == VDIR) {
3049 * Check to make sure rename is valid.
3050 * Can't do a move like this: /usr/a/b to /usr/a/b/c/d
3052 if (error = zfs_rename_lock(szp, tdzp, sdzp, &zl))
3057 * Does target exist?
3061 * Source and target must be the same type.
3063 if (ZTOV(szp)->v_type == VDIR) {
3064 if (ZTOV(tzp)->v_type != VDIR) {
3069 if (ZTOV(tzp)->v_type == VDIR) {
3075 * POSIX dictates that when the source and target
3076 * entries refer to the same file object, rename
3077 * must do nothing and exit without error.
3079 if (szp->z_id == tzp->z_id) {
3085 vnevent_rename_src(ZTOV(szp), sdvp, snm, ct);
3087 vnevent_rename_dest(ZTOV(tzp), tdvp, tnm, ct);
3090 * notify the target directory if it is not the same
3091 * as source directory.
3094 vnevent_rename_dest_dir(tdvp, ct);
3097 tx = dmu_tx_create(zfsvfs->z_os);
3098 dmu_tx_hold_bonus(tx, szp->z_id); /* nlink changes */
3099 dmu_tx_hold_bonus(tx, sdzp->z_id); /* nlink changes */
3100 dmu_tx_hold_zap(tx, sdzp->z_id, FALSE, snm);
3101 dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, tnm);
3103 dmu_tx_hold_bonus(tx, tdzp->z_id); /* nlink changes */
3105 dmu_tx_hold_bonus(tx, tzp->z_id); /* parent changes */
3106 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
3107 error = dmu_tx_assign(tx, zfsvfs->z_assign);
3110 zfs_rename_unlock(&zl);
3111 zfs_dirent_unlock(sdl);
3112 zfs_dirent_unlock(tdl);
3116 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
3126 if (tzp) /* Attempt to remove the existing target */
3127 error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL);
3130 error = zfs_link_create(tdl, szp, tx, ZRENAMING);
3132 szp->z_phys->zp_flags |= ZFS_AV_MODIFIED;
3134 error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL);
3137 zfs_log_rename(zilog, tx,
3138 TX_RENAME | (flags & FIGNORECASE ? TX_CI : 0),
3139 sdzp, sdl->dl_name, tdzp, tdl->dl_name, szp);
3141 /* Update path information for the target vnode */
3142 vn_renamepath(tdvp, ZTOV(szp), tnm, strlen(tnm));
3149 zfs_rename_unlock(&zl);
3151 zfs_dirent_unlock(sdl);
3152 zfs_dirent_unlock(tdl);
3163 * Insert the indicated symbolic reference entry into the directory.
3165 * IN: dvp - Directory to contain new symbolic link.
3166 * link - Name for new symlink entry.
3167 * vap - Attributes of new entry.
3168 * target - Target path of new symlink.
3169 * cr - credentials of caller.
3170 * ct - caller context
3171 * flags - case flags
3173 * RETURN: 0 if success
3174 * error code if failure
3177 * dvp - ctime|mtime updated
3181 zfs_symlink(vnode_t *dvp, char *name, vattr_t *vap, char *link, cred_t *cr,
3182 caller_context_t *ct, int flags)
3184 znode_t *zp, *dzp = VTOZ(dvp);
3187 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3189 int len = strlen(link);
3192 zfs_fuid_info_t *fuidp = NULL;
3194 ASSERT(vap->va_type == VLNK);
3198 zilog = zfsvfs->z_log;
3200 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
3201 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3205 if (flags & FIGNORECASE)
3208 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
3213 if (len > MAXPATHLEN) {
3215 return (ENAMETOOLONG);
3219 * Attempt to lock directory; fail if entry already exists.
3221 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, NULL, NULL);
3227 tx = dmu_tx_create(zfsvfs->z_os);
3228 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, MAX(1, len));
3229 dmu_tx_hold_bonus(tx, dzp->z_id);
3230 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
3231 if (dzp->z_phys->zp_flags & ZFS_INHERIT_ACE)
3232 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, SPA_MAXBLOCKSIZE);
3233 if (IS_EPHEMERAL(crgetuid(cr)) || IS_EPHEMERAL(crgetgid(cr))) {
3234 if (zfsvfs->z_fuid_obj == 0) {
3235 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
3236 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
3237 FUID_SIZE_ESTIMATE(zfsvfs));
3238 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, FALSE, NULL);
3240 dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj);
3241 dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0,
3242 FUID_SIZE_ESTIMATE(zfsvfs));
3245 error = dmu_tx_assign(tx, zfsvfs->z_assign);
3247 zfs_dirent_unlock(dl);
3248 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
3258 dmu_buf_will_dirty(dzp->z_dbuf, tx);
3261 * Create a new object for the symlink.
3262 * Put the link content into bonus buffer if it will fit;
3263 * otherwise, store it just like any other file data.
3265 if (sizeof (znode_phys_t) + len <= dmu_bonus_max()) {
3266 zfs_mknode(dzp, vap, tx, cr, 0, &zp, len, NULL, &fuidp);
3268 bcopy(link, zp->z_phys + 1, len);
3272 zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, NULL, &fuidp);
3274 * Nothing can access the znode yet so no locking needed
3275 * for growing the znode's blocksize.
3277 zfs_grow_blocksize(zp, len, tx);
3279 VERIFY(0 == dmu_buf_hold(zfsvfs->z_os,
3280 zp->z_id, 0, FTAG, &dbp));
3281 dmu_buf_will_dirty(dbp, tx);
3283 ASSERT3U(len, <=, dbp->db_size);
3284 bcopy(link, dbp->db_data, len);
3285 dmu_buf_rele(dbp, FTAG);
3287 zp->z_phys->zp_size = len;
3290 * Insert the new object into the directory.
3292 (void) zfs_link_create(dl, zp, tx, ZNEW);
3295 uint64_t txtype = TX_SYMLINK;
3296 if (flags & FIGNORECASE)
3298 zfs_log_symlink(zilog, tx, txtype, dzp, zp, name, link);
3301 zfs_fuid_info_free(fuidp);
3305 zfs_dirent_unlock(dl);
3314 * Return, in the buffer contained in the provided uio structure,
3315 * the symbolic path referred to by vp.
3317 * IN: vp - vnode of symbolic link.
3318 * uoip - structure to contain the link path.
3319 * cr - credentials of caller.
3320 * ct - caller context
3322 * OUT: uio - structure to contain the link path.
3324 * RETURN: 0 if success
3325 * error code if failure
3328 * vp - atime updated
3332 zfs_readlink(vnode_t *vp, uio_t *uio, cred_t *cr, caller_context_t *ct)
3334 znode_t *zp = VTOZ(vp);
3335 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3342 bufsz = (size_t)zp->z_phys->zp_size;
3343 if (bufsz + sizeof (znode_phys_t) <= zp->z_dbuf->db_size) {
3344 error = uiomove(zp->z_phys + 1,
3345 MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
3348 error = dmu_buf_hold(zfsvfs->z_os, zp->z_id, 0, FTAG, &dbp);
3353 error = uiomove(dbp->db_data,
3354 MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
3355 dmu_buf_rele(dbp, FTAG);
3358 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
3364 * Insert a new entry into directory tdvp referencing svp.
3366 * IN: tdvp - Directory to contain new entry.
3367 * svp - vnode of new entry.
3368 * name - name of new entry.
3369 * cr - credentials of caller.
3370 * ct - caller context
3372 * RETURN: 0 if success
3373 * error code if failure
3376 * tdvp - ctime|mtime updated
3377 * svp - ctime updated
3381 zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr,
3382 caller_context_t *ct, int flags)
3384 znode_t *dzp = VTOZ(tdvp);
3386 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3395 ASSERT(tdvp->v_type == VDIR);
3399 zilog = zfsvfs->z_log;
3401 if (VOP_REALVP(svp, &realvp, ct) == 0)
3404 if (svp->v_vfsp != tdvp->v_vfsp) {
3411 if (zfsvfs->z_utf8 && u8_validate(name,
3412 strlen(name), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3416 if (flags & FIGNORECASE)
3421 * We do not support links between attributes and non-attributes
3422 * because of the potential security risk of creating links
3423 * into "normal" file space in order to circumvent restrictions
3424 * imposed in attribute space.
3426 if ((szp->z_phys->zp_flags & ZFS_XATTR) !=
3427 (dzp->z_phys->zp_flags & ZFS_XATTR)) {
3433 * POSIX dictates that we return EPERM here.
3434 * Better choices include ENOTSUP or EISDIR.
3436 if (svp->v_type == VDIR) {
3441 owner = zfs_fuid_map_id(zfsvfs, szp->z_phys->zp_uid, cr, ZFS_OWNER);
3442 if (owner != crgetuid(cr) &&
3443 secpolicy_basic_link(cr) != 0) {
3448 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
3454 * Attempt to lock directory; fail if entry already exists.
3456 error = zfs_dirent_lock(&dl, dzp, name, &tzp, zf, NULL, NULL);
3462 tx = dmu_tx_create(zfsvfs->z_os);
3463 dmu_tx_hold_bonus(tx, szp->z_id);
3464 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
3465 error = dmu_tx_assign(tx, zfsvfs->z_assign);
3467 zfs_dirent_unlock(dl);
3468 if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
3478 error = zfs_link_create(dl, szp, tx, 0);
3481 uint64_t txtype = TX_LINK;
3482 if (flags & FIGNORECASE)
3484 zfs_log_link(zilog, tx, txtype, dzp, szp, name);
3489 zfs_dirent_unlock(dl);
3492 vnevent_link(svp, ct);
3500 * zfs_null_putapage() is used when the file system has been force
3501 * unmounted. It just drops the pages.
3505 zfs_null_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
3506 size_t *lenp, int flags, cred_t *cr)
3508 pvn_write_done(pp, B_INVAL|B_FORCE|B_ERROR);
3513 * Push a page out to disk, klustering if possible.
3515 * IN: vp - file to push page to.
3516 * pp - page to push.
3517 * flags - additional flags.
3518 * cr - credentials of caller.
3520 * OUT: offp - start of range pushed.
3521 * lenp - len of range pushed.
3523 * RETURN: 0 if success
3524 * error code if failure
3526 * NOTE: callers must have locked the page to be pushed. On
3527 * exit, the page (and all other pages in the kluster) must be
3532 zfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
3533 size_t *lenp, int flags, cred_t *cr)
3535 znode_t *zp = VTOZ(vp);
3536 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3537 zilog_t *zilog = zfsvfs->z_log;
3540 u_offset_t off, koff;
3545 filesz = zp->z_phys->zp_size;
3549 * If our blocksize is bigger than the page size, try to kluster
3550 * muiltiple pages so that we write a full block (thus avoiding
3551 * a read-modify-write).
3553 if (off < filesz && zp->z_blksz > PAGESIZE) {
3554 if (!ISP2(zp->z_blksz)) {
3555 /* Only one block in the file. */
3556 klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE);
3560 koff = P2ALIGN(off, (u_offset_t)klen);
3562 ASSERT(koff <= filesz);
3563 if (koff + klen > filesz)
3564 klen = P2ROUNDUP(filesz - koff, (uint64_t)PAGESIZE);
3565 pp = pvn_write_kluster(vp, pp, &off, &len, koff, klen, flags);
3567 ASSERT3U(btop(len), ==, btopr(len));
3569 rl = zfs_range_lock(zp, off, len, RL_WRITER);
3571 * Can't push pages past end-of-file.
3573 filesz = zp->z_phys->zp_size;
3574 if (off >= filesz) {
3575 /* ignore all pages */
3578 } else if (off + len > filesz) {
3579 int npages = btopr(filesz - off);
3582 page_list_break(&pp, &trunc, npages);
3583 /* ignore pages past end of file */
3585 pvn_write_done(trunc, flags);
3589 tx = dmu_tx_create(zfsvfs->z_os);
3590 dmu_tx_hold_write(tx, zp->z_id, off, len);
3591 dmu_tx_hold_bonus(tx, zp->z_id);
3592 err = dmu_tx_assign(tx, zfsvfs->z_assign);
3594 if (err == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) {
3595 zfs_range_unlock(rl);
3605 if (zp->z_blksz <= PAGESIZE) {
3606 caddr_t va = zfs_map_page(pp, S_READ);
3607 ASSERT3U(len, <=, PAGESIZE);
3608 dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx);
3609 zfs_unmap_page(pp, va);
3611 err = dmu_write_pages(zfsvfs->z_os, zp->z_id, off, len, pp, tx);
3615 zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
3616 zfs_log_write(zilog, tx, TX_WRITE, zp, off, len, 0);
3621 zfs_range_unlock(rl);
3622 pvn_write_done(pp, (err ? B_ERROR : 0) | flags);
3632 * Copy the portion of the file indicated from pages into the file.
3633 * The pages are stored in a page list attached to the files vnode.
3635 * IN: vp - vnode of file to push page data to.
3636 * off - position in file to put data.
3637 * len - amount of data to write.
3638 * flags - flags to control the operation.
3639 * cr - credentials of caller.
3640 * ct - caller context.
3642 * RETURN: 0 if success
3643 * error code if failure
3646 * vp - ctime|mtime updated
3650 zfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
3651 caller_context_t *ct)
3653 znode_t *zp = VTOZ(vp);
3654 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3666 * Search the entire vp list for pages >= off.
3668 error = pvn_vplist_dirty(vp, (u_offset_t)off, zfs_putapage,
3673 filesz = zp->z_phys->zp_size; /* get consistent copy of zp_size */
3675 /* past end of file */
3680 len = MIN(len, filesz - off);
3682 for (io_off = off; io_off < off + len; io_off += io_len) {
3683 if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) {
3684 pp = page_lookup(vp, io_off,
3685 (flags & (B_INVAL | B_FREE)) ? SE_EXCL : SE_SHARED);
3687 pp = page_lookup_nowait(vp, io_off,
3688 (flags & B_FREE) ? SE_EXCL : SE_SHARED);
3691 if (pp != NULL && pvn_getdirty(pp, flags)) {
3695 * Found a dirty page to push
3697 err = zfs_putapage(vp, pp, &io_off, &io_len, flags, cr);
3705 if ((flags & B_ASYNC) == 0)
3706 zil_commit(zfsvfs->z_log, UINT64_MAX, zp->z_id);
3713 zfs_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
3715 znode_t *zp = VTOZ(vp);
3716 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3719 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER);
3720 if (zp->z_dbuf == NULL) {
3722 * The fs has been unmounted, or we did a
3723 * suspend/resume and this file no longer exists.
3725 if (vn_has_cached_data(vp)) {
3726 (void) pvn_vplist_dirty(vp, 0, zfs_null_putapage,
3730 mutex_enter(&zp->z_lock);
3731 vp->v_count = 0; /* count arrives as 1 */
3732 mutex_exit(&zp->z_lock);
3733 rw_exit(&zfsvfs->z_teardown_inactive_lock);
3739 * Attempt to push any data in the page cache. If this fails
3740 * we will get kicked out later in zfs_zinactive().
3742 if (vn_has_cached_data(vp)) {
3743 (void) pvn_vplist_dirty(vp, 0, zfs_putapage, B_INVAL|B_ASYNC,
3747 if (zp->z_atime_dirty && zp->z_unlinked == 0) {
3748 dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
3750 dmu_tx_hold_bonus(tx, zp->z_id);
3751 error = dmu_tx_assign(tx, TXG_WAIT);
3755 dmu_buf_will_dirty(zp->z_dbuf, tx);
3756 mutex_enter(&zp->z_lock);
3757 zp->z_atime_dirty = 0;
3758 mutex_exit(&zp->z_lock);
3764 rw_exit(&zfsvfs->z_teardown_inactive_lock);
3768 * Bounds-check the seek operation.
3770 * IN: vp - vnode seeking within
3771 * ooff - old file offset
3772 * noffp - pointer to new file offset
3773 * ct - caller context
3775 * RETURN: 0 if success
3776 * EINVAL if new offset invalid
3780 zfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp,
3781 caller_context_t *ct)
3783 if (vp->v_type == VDIR)
3785 return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
3789 * Pre-filter the generic locking function to trap attempts to place
3790 * a mandatory lock on a memory mapped file.
3793 zfs_frlock(vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset,
3794 flk_callback_t *flk_cbp, cred_t *cr, caller_context_t *ct)
3796 znode_t *zp = VTOZ(vp);
3797 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3804 * We are following the UFS semantics with respect to mapcnt
3805 * here: If we see that the file is mapped already, then we will
3806 * return an error, but we don't worry about races between this
3807 * function and zfs_map().
3809 if (zp->z_mapcnt > 0 && MANDMODE((mode_t)zp->z_phys->zp_mode)) {
3813 error = fs_frlock(vp, cmd, bfp, flag, offset, flk_cbp, cr, ct);
3819 * If we can't find a page in the cache, we will create a new page
3820 * and fill it with file data. For efficiency, we may try to fill
3821 * multiple pages at once (klustering).
3824 zfs_fillpage(vnode_t *vp, u_offset_t off, struct seg *seg,
3825 caddr_t addr, page_t *pl[], size_t plsz, enum seg_rw rw)
3827 znode_t *zp = VTOZ(vp);
3828 page_t *pp, *cur_pp;
3829 objset_t *os = zp->z_zfsvfs->z_os;
3831 u_offset_t io_off, total;
3832 uint64_t oid = zp->z_id;
3838 * If we are only asking for a single page don't bother klustering.
3840 filesz = zp->z_phys->zp_size; /* get consistent copy of zp_size */
3843 if (plsz == PAGESIZE || zp->z_blksz <= PAGESIZE) {
3846 pp = page_create_va(vp, io_off, io_len, PG_WAIT, seg, addr);
3849 * Try to fill a kluster of pages (a blocks worth).
3854 if (!ISP2(zp->z_blksz)) {
3855 /* Only one block in the file. */
3856 klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE);
3860 * It would be ideal to align our offset to the
3861 * blocksize but doing so has resulted in some
3862 * strange application crashes. For now, we
3863 * leave the offset as is and only adjust the
3864 * length if we are off the end of the file.
3869 ASSERT(koff <= filesz);
3870 if (koff + klen > filesz)
3871 klen = P2ROUNDUP(filesz, (uint64_t)PAGESIZE) - koff;
3872 ASSERT3U(off, >=, koff);
3873 ASSERT3U(off, <, koff + klen);
3874 pp = pvn_read_kluster(vp, off, seg, addr, &io_off,
3875 &io_len, koff, klen, 0);
3879 * Some other thread entered the page before us.
3880 * Return to zfs_getpage to retry the lookup.
3887 * Fill the pages in the kluster.
3890 for (total = io_off + io_len; io_off < total; io_off += PAGESIZE) {
3891 ASSERT3U(io_off, ==, cur_pp->p_offset);
3892 va = zfs_map_page(cur_pp, S_WRITE);
3893 err = dmu_read(os, oid, io_off, PAGESIZE, va);
3894 zfs_unmap_page(cur_pp, va);
3896 /* On error, toss the entire kluster */
3897 pvn_read_done(pp, B_ERROR);
3898 /* convert checksum errors into IO errors */
3903 cur_pp = cur_pp->p_next;
3907 * Fill in the page list array from the kluster. If
3908 * there are too many pages in the kluster, return
3909 * as many pages as possible starting from the desired
3911 * NOTE: the page list will always be null terminated.
3913 pvn_plist_init(pp, pl, plsz, off, io_len, rw);
3919 * Return pointers to the pages for the file region [off, off + len]
3920 * in the pl array. If plsz is greater than len, this function may
3921 * also return page pointers from before or after the specified
3922 * region (i.e. some region [off', off' + plsz]). These additional
3923 * pages are only returned if they are already in the cache, or were
3924 * created as part of a klustered read.
3926 * IN: vp - vnode of file to get data from.
3927 * off - position in file to get data from.
3928 * len - amount of data to retrieve.
3929 * plsz - length of provided page list.
3930 * seg - segment to obtain pages for.
3931 * addr - virtual address of fault.
3932 * rw - mode of created pages.
3933 * cr - credentials of caller.
3934 * ct - caller context.
3936 * OUT: protp - protection mode of created pages.
3937 * pl - list of pages created.
3939 * RETURN: 0 if success
3940 * error code if failure
3943 * vp - atime updated
3947 zfs_getpage(vnode_t *vp, offset_t off, size_t len, uint_t *protp,
3948 page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
3949 enum seg_rw rw, cred_t *cr, caller_context_t *ct)
3951 znode_t *zp = VTOZ(vp);
3952 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3953 page_t *pp, **pl0 = pl;
3954 int need_unlock = 0, err = 0;
3963 /* no faultahead (for now) */
3969 /* can't fault past EOF */
3970 if (off >= zp->z_phys->zp_size) {
3977 * If we already own the lock, then we must be page faulting
3978 * in the middle of a write to this file (i.e., we are writing
3979 * to this file using data from a mapped region of the file).
3981 if (rw_owner(&zp->z_map_lock) != curthread) {
3982 rw_enter(&zp->z_map_lock, RW_WRITER);
3987 * Loop through the requested range [off, off + len] looking
3988 * for pages. If we don't find a page, we will need to create
3989 * a new page and fill it with data from the file.
3992 if (plsz < PAGESIZE)
3994 if (pp = page_lookup(vp, off, SE_SHARED)) {
4001 err = zfs_fillpage(vp, off, seg, addr, pl, plsz, rw);
4005 * klustering may have changed our region
4006 * to be block aligned.
4008 if (((pp = *pl) != 0) && (off != pp->p_offset)) {
4009 int delta = off - pp->p_offset;
4028 * Fill out the page array with any pages already in the cache.
4031 pp = page_lookup_nowait(vp, off, SE_SHARED);
4039 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
4042 * We can't grab the range lock for the page as reader which would
4043 * stop truncation as this leads to deadlock. So we need to recheck
4046 if (orig_off >= zp->z_phys->zp_size)
4050 * Release any pages we have previously locked.
4059 rw_exit(&zp->z_map_lock);
4066 * Request a memory map for a section of a file. This code interacts
4067 * with common code and the VM system as follows:
4069 * common code calls mmap(), which ends up in smmap_common()
4071 * this calls VOP_MAP(), which takes you into (say) zfs
4073 * zfs_map() calls as_map(), passing segvn_create() as the callback
4075 * segvn_create() creates the new segment and calls VOP_ADDMAP()
4077 * zfs_addmap() updates z_mapcnt
4081 zfs_map(vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp,
4082 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4083 caller_context_t *ct)
4085 znode_t *zp = VTOZ(vp);
4086 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4087 segvn_crargs_t vn_a;
4093 if ((prot & PROT_WRITE) &&
4094 (zp->z_phys->zp_flags & (ZFS_IMMUTABLE | ZFS_READONLY |
4100 if ((prot & (PROT_READ | PROT_EXEC)) &&
4101 (zp->z_phys->zp_flags & ZFS_AV_QUARANTINED)) {
4106 if (vp->v_flag & VNOMAP) {
4111 if (off < 0 || len > MAXOFFSET_T - off) {
4116 if (vp->v_type != VREG) {
4122 * If file is locked, disallow mapping.
4124 if (MANDMODE((mode_t)zp->z_phys->zp_mode) && vn_has_flocks(vp)) {
4130 error = choose_addr(as, addrp, len, off, ADDR_VACALIGN, flags);
4138 vn_a.offset = (u_offset_t)off;
4139 vn_a.type = flags & MAP_TYPE;
4141 vn_a.maxprot = maxprot;
4144 vn_a.flags = flags & ~MAP_TYPE;
4146 vn_a.lgrp_mem_policy_flags = 0;
4148 error = as_map(as, *addrp, len, segvn_create, &vn_a);
4157 zfs_addmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
4158 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4159 caller_context_t *ct)
4161 uint64_t pages = btopr(len);
4163 atomic_add_64(&VTOZ(vp)->z_mapcnt, pages);
4168 * The reason we push dirty pages as part of zfs_delmap() is so that we get a
4169 * more accurate mtime for the associated file. Since we don't have a way of
4170 * detecting when the data was actually modified, we have to resort to
4171 * heuristics. If an explicit msync() is done, then we mark the mtime when the
4172 * last page is pushed. The problem occurs when the msync() call is omitted,
4173 * which by far the most common case:
4181 * putpage() via fsflush
4183 * If we wait until fsflush to come along, we can have a modification time that
4184 * is some arbitrary point in the future. In order to prevent this in the
4185 * common case, we flush pages whenever a (MAP_SHARED, PROT_WRITE) mapping is
4190 zfs_delmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
4191 size_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cr,
4192 caller_context_t *ct)
4194 uint64_t pages = btopr(len);
4196 ASSERT3U(VTOZ(vp)->z_mapcnt, >=, pages);
4197 atomic_add_64(&VTOZ(vp)->z_mapcnt, -pages);
4199 if ((flags & MAP_SHARED) && (prot & PROT_WRITE) &&
4200 vn_has_cached_data(vp))
4201 (void) VOP_PUTPAGE(vp, off, len, B_ASYNC, cr, ct);
4207 * Free or allocate space in a file. Currently, this function only
4208 * supports the `F_FREESP' command. However, this command is somewhat
4209 * misnamed, as its functionality includes the ability to allocate as
4210 * well as free space.
4212 * IN: vp - vnode of file to free data in.
4213 * cmd - action to take (only F_FREESP supported).
4214 * bfp - section of file to free/alloc.
4215 * flag - current file open mode flags.
4216 * offset - current file offset.
4217 * cr - credentials of caller [UNUSED].
4218 * ct - caller context.
4220 * RETURN: 0 if success
4221 * error code if failure
4224 * vp - ctime|mtime updated
4228 zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag,
4229 offset_t offset, cred_t *cr, caller_context_t *ct)
4231 znode_t *zp = VTOZ(vp);
4232 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4239 if (cmd != F_FREESP) {
4244 if (error = convoff(vp, bfp, 0, offset)) {
4249 if (bfp->l_len < 0) {
4255 len = bfp->l_len; /* 0 means from off to end of file */
4257 error = zfs_freesp(zp, off, len, flag, TRUE);
4265 zfs_fid(vnode_t *vp, fid_t *fidp, caller_context_t *ct)
4267 znode_t *zp = VTOZ(vp);
4268 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4270 uint64_t object = zp->z_id;
4276 gen = (uint32_t)zp->z_gen;
4278 size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN;
4279 if (fidp->fid_len < size) {
4280 fidp->fid_len = size;
4285 zfid = (zfid_short_t *)fidp;
4287 zfid->zf_len = size;
4289 for (i = 0; i < sizeof (zfid->zf_object); i++)
4290 zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
4292 /* Must have a non-zero generation number to distinguish from .zfs */
4295 for (i = 0; i < sizeof (zfid->zf_gen); i++)
4296 zfid->zf_gen[i] = (uint8_t)(gen >> (8 * i));
4298 if (size == LONG_FID_LEN) {
4299 uint64_t objsetid = dmu_objset_id(zfsvfs->z_os);
4302 zlfid = (zfid_long_t *)fidp;
4304 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
4305 zlfid->zf_setid[i] = (uint8_t)(objsetid >> (8 * i));
4307 /* XXX - this should be the generation number for the objset */
4308 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
4309 zlfid->zf_setgen[i] = 0;
4317 zfs_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr,
4318 caller_context_t *ct)
4330 case _PC_FILESIZEBITS:
4334 case _PC_XATTR_EXISTS:
4336 zfsvfs = zp->z_zfsvfs;
4340 error = zfs_dirent_lock(&dl, zp, "", &xzp,
4341 ZXATTR | ZEXISTS | ZSHARED, NULL, NULL);
4343 zfs_dirent_unlock(dl);
4344 if (!zfs_dirempty(xzp))
4347 } else if (error == ENOENT) {
4349 * If there aren't extended attributes, it's the
4350 * same as having zero of them.
4357 case _PC_SATTR_ENABLED:
4358 case _PC_SATTR_EXISTS:
4359 *valp = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
4360 (vp->v_type == VREG || vp->v_type == VDIR);
4363 case _PC_ACL_ENABLED:
4364 *valp = _ACL_ACE_ENABLED;
4367 case _PC_MIN_HOLE_SIZE:
4368 *valp = (ulong_t)SPA_MINBLOCKSIZE;
4372 return (fs_pathconf(vp, cmd, valp, cr, ct));
4378 zfs_getsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
4379 caller_context_t *ct)
4381 znode_t *zp = VTOZ(vp);
4382 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4384 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4388 error = zfs_getacl(zp, vsecp, skipaclchk, cr);
4396 zfs_setsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
4397 caller_context_t *ct)
4399 znode_t *zp = VTOZ(vp);
4400 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4402 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4406 error = zfs_setacl(zp, vsecp, skipaclchk, cr);
4412 * Predeclare these here so that the compiler assumes that
4413 * this is an "old style" function declaration that does
4414 * not include arguments => we won't get type mismatch errors
4415 * in the initializations that follow.
4417 static int zfs_inval();
4418 static int zfs_isdir();
4432 * Directory vnode operations template
4434 vnodeops_t *zfs_dvnodeops;
4435 const fs_operation_def_t zfs_dvnodeops_template[] = {
4436 VOPNAME_OPEN, { .vop_open = zfs_open },
4437 VOPNAME_CLOSE, { .vop_close = zfs_close },
4438 VOPNAME_READ, { .error = zfs_isdir },
4439 VOPNAME_WRITE, { .error = zfs_isdir },
4440 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
4441 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4442 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4443 VOPNAME_ACCESS, { .vop_access = zfs_access },
4444 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
4445 VOPNAME_CREATE, { .vop_create = zfs_create },
4446 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
4447 VOPNAME_LINK, { .vop_link = zfs_link },
4448 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4449 VOPNAME_MKDIR, { .vop_mkdir = zfs_mkdir },
4450 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
4451 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
4452 VOPNAME_SYMLINK, { .vop_symlink = zfs_symlink },
4453 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
4454 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4455 VOPNAME_FID, { .vop_fid = zfs_fid },
4456 VOPNAME_SEEK, { .vop_seek = zfs_seek },
4457 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4458 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4459 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4460 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4465 * Regular file vnode operations template
4467 vnodeops_t *zfs_fvnodeops;
4468 const fs_operation_def_t zfs_fvnodeops_template[] = {
4469 VOPNAME_OPEN, { .vop_open = zfs_open },
4470 VOPNAME_CLOSE, { .vop_close = zfs_close },
4471 VOPNAME_READ, { .vop_read = zfs_read },
4472 VOPNAME_WRITE, { .vop_write = zfs_write },
4473 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
4474 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4475 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4476 VOPNAME_ACCESS, { .vop_access = zfs_access },
4477 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
4478 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4479 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
4480 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4481 VOPNAME_FID, { .vop_fid = zfs_fid },
4482 VOPNAME_SEEK, { .vop_seek = zfs_seek },
4483 VOPNAME_FRLOCK, { .vop_frlock = zfs_frlock },
4484 VOPNAME_SPACE, { .vop_space = zfs_space },
4485 VOPNAME_GETPAGE, { .vop_getpage = zfs_getpage },
4486 VOPNAME_PUTPAGE, { .vop_putpage = zfs_putpage },
4487 VOPNAME_MAP, { .vop_map = zfs_map },
4488 VOPNAME_ADDMAP, { .vop_addmap = zfs_addmap },
4489 VOPNAME_DELMAP, { .vop_delmap = zfs_delmap },
4490 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4491 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4492 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4493 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4498 * Symbolic link vnode operations template
4500 vnodeops_t *zfs_symvnodeops;
4501 const fs_operation_def_t zfs_symvnodeops_template[] = {
4502 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4503 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4504 VOPNAME_ACCESS, { .vop_access = zfs_access },
4505 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4506 VOPNAME_READLINK, { .vop_readlink = zfs_readlink },
4507 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4508 VOPNAME_FID, { .vop_fid = zfs_fid },
4509 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4510 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4515 * Extended attribute directory vnode operations template
4516 * This template is identical to the directory vnodes
4517 * operation template except for restricted operations:
4520 * Note that there are other restrictions embedded in:
4521 * zfs_create() - restrict type to VREG
4522 * zfs_link() - no links into/out of attribute space
4523 * zfs_rename() - no moves into/out of attribute space
4525 vnodeops_t *zfs_xdvnodeops;
4526 const fs_operation_def_t zfs_xdvnodeops_template[] = {
4527 VOPNAME_OPEN, { .vop_open = zfs_open },
4528 VOPNAME_CLOSE, { .vop_close = zfs_close },
4529 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
4530 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4531 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4532 VOPNAME_ACCESS, { .vop_access = zfs_access },
4533 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
4534 VOPNAME_CREATE, { .vop_create = zfs_create },
4535 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
4536 VOPNAME_LINK, { .vop_link = zfs_link },
4537 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4538 VOPNAME_MKDIR, { .error = zfs_inval },
4539 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
4540 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
4541 VOPNAME_SYMLINK, { .error = zfs_inval },
4542 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
4543 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4544 VOPNAME_FID, { .vop_fid = zfs_fid },
4545 VOPNAME_SEEK, { .vop_seek = zfs_seek },
4546 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4547 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4548 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4549 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4554 * Error vnode operations template
4556 vnodeops_t *zfs_evnodeops;
4557 const fs_operation_def_t zfs_evnodeops_template[] = {
4558 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4559 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },