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 2009 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.
104 * If you must call VN_RELE() within a tx then use VN_RELE_ASYNC().
106 * (3) All range locks must be grabbed before calling dmu_tx_assign(),
107 * as they can span dmu_tx_assign() calls.
109 * (4) Always pass TXG_NOWAIT as the second argument to dmu_tx_assign().
110 * This is critical because we don't want to block while holding locks.
111 * Note, in particular, that if a lock is sometimes acquired before
112 * the tx assigns, and sometimes after (e.g. z_lock), then failing to
113 * use a non-blocking assign can deadlock the system. The scenario:
115 * Thread A has grabbed a lock before calling dmu_tx_assign().
116 * Thread B is in an already-assigned tx, and blocks for this lock.
117 * Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
118 * forever, because the previous txg can't quiesce until B's tx commits.
120 * If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
121 * then drop all locks, call dmu_tx_wait(), and try again.
123 * (5) If the operation succeeded, generate the intent log entry for it
124 * before dropping locks. This ensures that the ordering of events
125 * in the intent log matches the order in which they actually occurred.
126 * During ZIL replay the zfs_log_* functions will update the sequence
127 * number to indicate the zil transaction has replayed.
129 * (6) At the end of each vnode op, the DMU tx must always commit,
130 * regardless of whether there were any errors.
132 * (7) After dropping all locks, invoke zil_commit(zilog, seq, foid)
133 * to ensure that synchronous semantics are provided when necessary.
135 * In general, this is how things should be ordered in each vnode op:
137 * ZFS_ENTER(zfsvfs); // exit if unmounted
139 * zfs_dirent_lock(&dl, ...) // lock directory entry (may VN_HOLD())
140 * rw_enter(...); // grab any other locks you need
141 * tx = dmu_tx_create(...); // get DMU tx
142 * dmu_tx_hold_*(); // hold each object you might modify
143 * error = dmu_tx_assign(tx, TXG_NOWAIT); // try to assign
145 * rw_exit(...); // drop locks
146 * zfs_dirent_unlock(dl); // unlock directory entry
147 * VN_RELE(...); // release held vnodes
148 * if (error == ERESTART) {
153 * dmu_tx_abort(tx); // abort DMU tx
154 * ZFS_EXIT(zfsvfs); // finished in zfs
155 * return (error); // really out of space
157 * error = do_real_work(); // do whatever this VOP does
159 * zfs_log_*(...); // on success, make ZIL entry
160 * dmu_tx_commit(tx); // commit DMU tx -- error or not
161 * rw_exit(...); // drop locks
162 * zfs_dirent_unlock(dl); // unlock directory entry
163 * VN_RELE(...); // release held vnodes
164 * zil_commit(zilog, seq, foid); // synchronous when necessary
165 * ZFS_EXIT(zfsvfs); // finished in zfs
166 * return (error); // done, report error
171 zfs_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
173 znode_t *zp = VTOZ(*vpp);
174 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
179 if ((flag & FWRITE) && (zp->z_phys->zp_flags & ZFS_APPENDONLY) &&
180 ((flag & FAPPEND) == 0)) {
185 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
186 ZTOV(zp)->v_type == VREG &&
187 !(zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) &&
188 zp->z_phys->zp_size > 0) {
189 if (fs_vscan(*vpp, cr, 0) != 0) {
195 /* Keep a count of the synchronous opens in the znode */
196 if (flag & (FSYNC | FDSYNC))
197 atomic_inc_32(&zp->z_sync_cnt);
205 zfs_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr,
206 caller_context_t *ct)
208 znode_t *zp = VTOZ(vp);
209 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
214 /* Decrement the synchronous opens in the znode */
215 if ((flag & (FSYNC | FDSYNC)) && (count == 1))
216 atomic_dec_32(&zp->z_sync_cnt);
219 * Clean up any locks held by this process on the vp.
221 cleanlocks(vp, ddi_get_pid(), 0);
222 cleanshares(vp, ddi_get_pid());
224 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
225 ZTOV(zp)->v_type == VREG &&
226 !(zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) &&
227 zp->z_phys->zp_size > 0)
228 VERIFY(fs_vscan(vp, cr, 1) == 0);
235 * Lseek support for finding holes (cmd == _FIO_SEEK_HOLE) and
236 * data (cmd == _FIO_SEEK_DATA). "off" is an in/out parameter.
239 zfs_holey(vnode_t *vp, int cmd, offset_t *off)
241 znode_t *zp = VTOZ(vp);
242 uint64_t noff = (uint64_t)*off; /* new offset */
247 file_sz = zp->z_phys->zp_size;
248 if (noff >= file_sz) {
252 if (cmd == _FIO_SEEK_HOLE)
257 error = dmu_offset_next(zp->z_zfsvfs->z_os, zp->z_id, hole, &noff);
260 if ((error == ESRCH) || (noff > file_sz)) {
262 * Handle the virtual hole at the end of file.
279 zfs_ioctl(vnode_t *vp, int com, intptr_t data, int flag, cred_t *cred,
280 int *rvalp, caller_context_t *ct)
289 return (zfs_sync(vp->v_vfsp, 0, cred));
292 * The following two ioctls are used by bfu. Faking out,
293 * necessary to avoid bfu errors.
301 if (ddi_copyin((void *)data, &off, sizeof (off), flag))
305 zfsvfs = zp->z_zfsvfs;
309 /* offset parameter is in/out */
310 error = zfs_holey(vp, com, &off);
314 if (ddi_copyout(&off, (void *)data, sizeof (off), flag))
322 * Utility functions to map and unmap a single physical page. These
323 * are used to manage the mappable copies of ZFS file data, and therefore
324 * do not update ref/mod bits.
327 zfs_map_page(page_t *pp, enum seg_rw rw)
330 return (hat_kpm_mapin(pp, 0));
331 ASSERT(rw == S_READ || rw == S_WRITE);
332 return (ppmapin(pp, PROT_READ | ((rw == S_WRITE) ? PROT_WRITE : 0),
337 zfs_unmap_page(page_t *pp, caddr_t addr)
340 hat_kpm_mapout(pp, 0, addr);
347 * When a file is memory mapped, we must keep the IO data synchronized
348 * between the DMU cache and the memory mapped pages. What this means:
350 * On Write: If we find a memory mapped page, we write to *both*
351 * the page and the dmu buffer.
354 update_pages(vnode_t *vp, int64_t start, int len, objset_t *os, uint64_t oid)
358 off = start & PAGEOFFSET;
359 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
361 uint64_t nbytes = MIN(PAGESIZE - off, len);
363 if (pp = page_lookup(vp, start, SE_SHARED)) {
366 va = zfs_map_page(pp, S_WRITE);
367 (void) dmu_read(os, oid, start+off, nbytes, va+off,
369 zfs_unmap_page(pp, va);
378 * When a file is memory mapped, we must keep the IO data synchronized
379 * between the DMU cache and the memory mapped pages. What this means:
381 * On Read: We "read" preferentially from memory mapped pages,
382 * else we default from the dmu buffer.
384 * NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
385 * the file is memory mapped.
388 mappedread(vnode_t *vp, int nbytes, uio_t *uio)
390 znode_t *zp = VTOZ(vp);
391 objset_t *os = zp->z_zfsvfs->z_os;
396 start = uio->uio_loffset;
397 off = start & PAGEOFFSET;
398 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
400 uint64_t bytes = MIN(PAGESIZE - off, len);
402 if (pp = page_lookup(vp, start, SE_SHARED)) {
405 va = zfs_map_page(pp, S_READ);
406 error = uiomove(va + off, bytes, UIO_READ, uio);
407 zfs_unmap_page(pp, va);
410 error = dmu_read_uio(os, zp->z_id, uio, bytes);
420 offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */
423 * Read bytes from specified file into supplied buffer.
425 * IN: vp - vnode of file to be read from.
426 * uio - structure supplying read location, range info,
428 * ioflag - SYNC flags; used to provide FRSYNC semantics.
429 * cr - credentials of caller.
430 * ct - caller context
432 * OUT: uio - updated offset and range, buffer filled.
434 * RETURN: 0 if success
435 * error code if failure
438 * vp - atime updated if byte count > 0
442 zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
444 znode_t *zp = VTOZ(vp);
445 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
455 if (zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) {
461 * Validate file offset
463 if (uio->uio_loffset < (offset_t)0) {
469 * Fasttrack empty reads
471 if (uio->uio_resid == 0) {
477 * Check for mandatory locks
479 if (MANDMODE((mode_t)zp->z_phys->zp_mode)) {
480 if (error = chklock(vp, FREAD,
481 uio->uio_loffset, uio->uio_resid, uio->uio_fmode, ct)) {
488 * If we're in FRSYNC mode, sync out this znode before reading it.
491 zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
494 * Lock the range against changes.
496 rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER);
499 * If we are reading past end-of-file we can skip
500 * to the end; but we might still need to set atime.
502 if (uio->uio_loffset >= zp->z_phys->zp_size) {
507 ASSERT(uio->uio_loffset < zp->z_phys->zp_size);
508 n = MIN(uio->uio_resid, zp->z_phys->zp_size - uio->uio_loffset);
511 nbytes = MIN(n, zfs_read_chunk_size -
512 P2PHASE(uio->uio_loffset, zfs_read_chunk_size));
514 if (vn_has_cached_data(vp))
515 error = mappedread(vp, nbytes, uio);
517 error = dmu_read_uio(os, zp->z_id, uio, nbytes);
519 /* convert checksum errors into IO errors */
529 zfs_range_unlock(rl);
531 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
537 * Write the bytes to a file.
539 * IN: vp - vnode of file to be written to.
540 * uio - structure supplying write location, range info,
542 * ioflag - FAPPEND flag set if in append mode.
543 * cr - credentials of caller.
544 * ct - caller context (NFS/CIFS fem monitor only)
546 * OUT: uio - updated offset and range.
548 * RETURN: 0 if success
549 * error code if failure
552 * vp - ctime|mtime updated if byte count > 0
556 zfs_write(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
558 znode_t *zp = VTOZ(vp);
559 rlim64_t limit = uio->uio_llimit;
560 ssize_t start_resid = uio->uio_resid;
564 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
569 int max_blksz = zfsvfs->z_max_blksz;
575 * Fasttrack empty write
581 if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
588 * If immutable or not appending then return EPERM
590 pflags = zp->z_phys->zp_flags;
591 if ((pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) ||
592 ((pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) &&
593 (uio->uio_loffset < zp->z_phys->zp_size))) {
598 zilog = zfsvfs->z_log;
601 * Pre-fault the pages to ensure slow (eg NFS) pages
604 uio_prefaultpages(n, uio);
607 * If in append mode, set the io offset pointer to eof.
609 if (ioflag & FAPPEND) {
611 * Range lock for a file append:
612 * The value for the start of range will be determined by
613 * zfs_range_lock() (to guarantee append semantics).
614 * If this write will cause the block size to increase,
615 * zfs_range_lock() will lock the entire file, so we must
616 * later reduce the range after we grow the block size.
618 rl = zfs_range_lock(zp, 0, n, RL_APPEND);
619 if (rl->r_len == UINT64_MAX) {
620 /* overlocked, zp_size can't change */
621 woff = uio->uio_loffset = zp->z_phys->zp_size;
623 woff = uio->uio_loffset = rl->r_off;
626 woff = uio->uio_loffset;
628 * Validate file offset
636 * If we need to grow the block size then zfs_range_lock()
637 * will lock a wider range than we request here.
638 * Later after growing the block size we reduce the range.
640 rl = zfs_range_lock(zp, woff, n, RL_WRITER);
644 zfs_range_unlock(rl);
649 if ((woff + n) > limit || woff > (limit - n))
653 * Check for mandatory locks
655 if (MANDMODE((mode_t)zp->z_phys->zp_mode) &&
656 (error = chklock(vp, FWRITE, woff, n, uio->uio_fmode, ct)) != 0) {
657 zfs_range_unlock(rl);
661 end_size = MAX(zp->z_phys->zp_size, woff + n);
664 * Write the file in reasonable size chunks. Each chunk is written
665 * in a separate transaction; this keeps the intent log records small
666 * and allows us to do more fine-grained space accounting.
670 woff = uio->uio_loffset;
673 if (zfs_usergroup_overquota(zfsvfs,
674 B_FALSE, zp->z_phys->zp_uid) ||
675 zfs_usergroup_overquota(zfsvfs,
676 B_TRUE, zp->z_phys->zp_gid)) {
678 dmu_return_arcbuf(abuf);
684 * If dmu_assign_arcbuf() is expected to execute with minimum
685 * overhead loan an arc buffer and copy user data to it before
686 * we enter a txg. This avoids holding a txg forever while we
687 * pagefault on a hanging NFS server mapping.
689 if (abuf == NULL && n >= max_blksz &&
690 woff >= zp->z_phys->zp_size &&
691 P2PHASE(woff, max_blksz) == 0 &&
692 zp->z_blksz == max_blksz) {
695 abuf = dmu_request_arcbuf(zp->z_dbuf, max_blksz);
696 ASSERT(abuf != NULL);
697 ASSERT(arc_buf_size(abuf) == max_blksz);
698 if (error = uiocopy(abuf->b_data, max_blksz,
699 UIO_WRITE, uio, &cbytes)) {
700 dmu_return_arcbuf(abuf);
703 ASSERT(cbytes == max_blksz);
707 * Start a transaction.
709 tx = dmu_tx_create(zfsvfs->z_os);
710 dmu_tx_hold_bonus(tx, zp->z_id);
711 dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
712 error = dmu_tx_assign(tx, TXG_NOWAIT);
714 if (error == ERESTART) {
721 dmu_return_arcbuf(abuf);
726 * If zfs_range_lock() over-locked we grow the blocksize
727 * and then reduce the lock range. This will only happen
728 * on the first iteration since zfs_range_reduce() will
729 * shrink down r_len to the appropriate size.
731 if (rl->r_len == UINT64_MAX) {
734 if (zp->z_blksz > max_blksz) {
735 ASSERT(!ISP2(zp->z_blksz));
736 new_blksz = MIN(end_size, SPA_MAXBLOCKSIZE);
738 new_blksz = MIN(end_size, max_blksz);
740 zfs_grow_blocksize(zp, new_blksz, tx);
741 zfs_range_reduce(rl, woff, n);
745 * XXX - should we really limit each write to z_max_blksz?
746 * Perhaps we should use SPA_MAXBLOCKSIZE chunks?
748 nbytes = MIN(n, max_blksz - P2PHASE(woff, max_blksz));
751 tx_bytes = uio->uio_resid;
752 error = dmu_write_uio(zfsvfs->z_os, zp->z_id, uio,
754 tx_bytes -= uio->uio_resid;
757 ASSERT(tx_bytes == max_blksz);
758 dmu_assign_arcbuf(zp->z_dbuf, woff, abuf, tx);
759 ASSERT(tx_bytes <= uio->uio_resid);
760 uioskip(uio, tx_bytes);
762 if (tx_bytes && vn_has_cached_data(vp)) {
763 update_pages(vp, woff,
764 tx_bytes, zfsvfs->z_os, zp->z_id);
768 * If we made no progress, we're done. If we made even
769 * partial progress, update the znode and ZIL accordingly.
778 * Clear Set-UID/Set-GID bits on successful write if not
779 * privileged and at least one of the excute bits is set.
781 * It would be nice to to this after all writes have
782 * been done, but that would still expose the ISUID/ISGID
783 * to another app after the partial write is committed.
785 * Note: we don't call zfs_fuid_map_id() here because
786 * user 0 is not an ephemeral uid.
788 mutex_enter(&zp->z_acl_lock);
789 if ((zp->z_phys->zp_mode & (S_IXUSR | (S_IXUSR >> 3) |
790 (S_IXUSR >> 6))) != 0 &&
791 (zp->z_phys->zp_mode & (S_ISUID | S_ISGID)) != 0 &&
792 secpolicy_vnode_setid_retain(cr,
793 (zp->z_phys->zp_mode & S_ISUID) != 0 &&
794 zp->z_phys->zp_uid == 0) != 0) {
795 zp->z_phys->zp_mode &= ~(S_ISUID | S_ISGID);
797 mutex_exit(&zp->z_acl_lock);
800 * Update time stamp. NOTE: This marks the bonus buffer as
801 * dirty, so we don't have to do it again for zp_size.
803 zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
806 * Update the file size (zp_size) if it has changed;
807 * account for possible concurrent updates.
809 while ((end_size = zp->z_phys->zp_size) < uio->uio_loffset)
810 (void) atomic_cas_64(&zp->z_phys->zp_size, end_size,
812 zfs_log_write(zilog, tx, TX_WRITE, zp, woff, tx_bytes, ioflag);
817 ASSERT(tx_bytes == nbytes);
821 zfs_range_unlock(rl);
824 * If we're in replay mode, or we made no progress, return error.
825 * Otherwise, it's at least a partial write, so it's successful.
827 if (zfsvfs->z_replay || uio->uio_resid == start_resid) {
832 if (ioflag & (FSYNC | FDSYNC))
833 zil_commit(zilog, zp->z_last_itx, zp->z_id);
840 zfs_get_done(dmu_buf_t *db, void *vzgd)
842 zgd_t *zgd = (zgd_t *)vzgd;
843 rl_t *rl = zgd->zgd_rl;
844 vnode_t *vp = ZTOV(rl->r_zp);
845 objset_t *os = rl->r_zp->z_zfsvfs->z_os;
847 dmu_buf_rele(db, vzgd);
848 zfs_range_unlock(rl);
850 * Release the vnode asynchronously as we currently have the
851 * txg stopped from syncing.
853 VN_RELE_ASYNC(vp, dsl_pool_vnrele_taskq(dmu_objset_pool(os)));
854 zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
855 kmem_free(zgd, sizeof (zgd_t));
859 * Get data to generate a TX_WRITE intent log record.
862 zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
864 zfsvfs_t *zfsvfs = arg;
865 objset_t *os = zfsvfs->z_os;
867 uint64_t off = lr->lr_offset;
871 int dlen = lr->lr_length; /* length of user data */
878 * Nothing to do if the file has been removed
880 if (zfs_zget(zfsvfs, lr->lr_foid, &zp) != 0)
882 if (zp->z_unlinked) {
884 * Release the vnode asynchronously as we currently have the
885 * txg stopped from syncing.
887 VN_RELE_ASYNC(ZTOV(zp),
888 dsl_pool_vnrele_taskq(dmu_objset_pool(os)));
893 * Write records come in two flavors: immediate and indirect.
894 * For small writes it's cheaper to store the data with the
895 * log record (immediate); for large writes it's cheaper to
896 * sync the data and get a pointer to it (indirect) so that
897 * we don't have to write the data twice.
899 if (buf != NULL) { /* immediate write */
900 rl = zfs_range_lock(zp, off, dlen, RL_READER);
901 /* test for truncation needs to be done while range locked */
902 if (off >= zp->z_phys->zp_size) {
906 VERIFY(0 == dmu_read(os, lr->lr_foid, off, dlen, buf,
907 DMU_READ_NO_PREFETCH));
908 } else { /* indirect write */
909 uint64_t boff; /* block starting offset */
912 * Have to lock the whole block to ensure when it's
913 * written out and it's checksum is being calculated
914 * that no one can change the data. We need to re-check
915 * blocksize after we get the lock in case it's changed!
918 if (ISP2(zp->z_blksz)) {
919 boff = P2ALIGN_TYPED(off, zp->z_blksz,
925 rl = zfs_range_lock(zp, boff, dlen, RL_READER);
926 if (zp->z_blksz == dlen)
928 zfs_range_unlock(rl);
930 /* test for truncation needs to be done while range locked */
931 if (off >= zp->z_phys->zp_size) {
935 zgd = (zgd_t *)kmem_alloc(sizeof (zgd_t), KM_SLEEP);
937 zgd->zgd_zilog = zfsvfs->z_log;
938 zgd->zgd_bp = &lr->lr_blkptr;
939 VERIFY(0 == dmu_buf_hold(os, lr->lr_foid, boff, zgd, &db));
940 ASSERT(boff == db->db_offset);
941 lr->lr_blkoff = off - boff;
942 error = dmu_sync(zio, db, &lr->lr_blkptr,
943 lr->lr_common.lrc_txg, zfs_get_done, zgd);
944 ASSERT((error && error != EINPROGRESS) ||
945 lr->lr_length <= zp->z_blksz);
947 zil_add_block(zfsvfs->z_log, &lr->lr_blkptr);
949 * If we get EINPROGRESS, then we need to wait for a
950 * write IO initiated by dmu_sync() to complete before
951 * we can release this dbuf. We will finish everything
952 * up in the zfs_get_done() callback.
954 if (error == EINPROGRESS)
956 dmu_buf_rele(db, zgd);
957 kmem_free(zgd, sizeof (zgd_t));
960 zfs_range_unlock(rl);
962 * Release the vnode asynchronously as we currently have the
963 * txg stopped from syncing.
965 VN_RELE_ASYNC(ZTOV(zp), dsl_pool_vnrele_taskq(dmu_objset_pool(os)));
971 zfs_access(vnode_t *vp, int mode, int flag, cred_t *cr,
972 caller_context_t *ct)
974 znode_t *zp = VTOZ(vp);
975 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
981 if (flag & V_ACE_MASK)
982 error = zfs_zaccess(zp, mode, flag, B_FALSE, cr);
984 error = zfs_zaccess_rwx(zp, mode, flag, cr);
991 * Lookup an entry in a directory, or an extended attribute directory.
992 * If it exists, return a held vnode reference for it.
994 * IN: dvp - vnode of directory to search.
995 * nm - name of entry to lookup.
996 * pnp - full pathname to lookup [UNUSED].
997 * flags - LOOKUP_XATTR set if looking for an attribute.
998 * rdir - root directory vnode [UNUSED].
999 * cr - credentials of caller.
1000 * ct - caller context
1001 * direntflags - directory lookup flags
1002 * realpnp - returned pathname.
1004 * OUT: vpp - vnode of located entry, NULL if not found.
1006 * RETURN: 0 if success
1007 * error code if failure
1014 zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp,
1015 int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct,
1016 int *direntflags, pathname_t *realpnp)
1018 znode_t *zdp = VTOZ(dvp);
1019 zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
1027 if (flags & LOOKUP_XATTR) {
1029 * If the xattr property is off, refuse the lookup request.
1031 if (!(zfsvfs->z_vfs->vfs_flag & VFS_XATTR)) {
1037 * We don't allow recursive attributes..
1038 * Maybe someday we will.
1040 if (zdp->z_phys->zp_flags & ZFS_XATTR) {
1045 if (error = zfs_get_xattrdir(VTOZ(dvp), vpp, cr, flags)) {
1051 * Do we have permission to get into attribute directory?
1054 if (error = zfs_zaccess(VTOZ(*vpp), ACE_EXECUTE, 0,
1064 if (dvp->v_type != VDIR) {
1070 * Check accessibility of directory.
1073 if (error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr)) {
1078 if (zfsvfs->z_utf8 && u8_validate(nm, strlen(nm),
1079 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1084 error = zfs_dirlook(zdp, nm, vpp, flags, direntflags, realpnp);
1087 * Convert device special files
1089 if (IS_DEVVP(*vpp)) {
1092 svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
1106 * Attempt to create a new entry in a directory. If the entry
1107 * already exists, truncate the file if permissible, else return
1108 * an error. Return the vp of the created or trunc'd file.
1110 * IN: dvp - vnode of directory to put new file entry in.
1111 * name - name of new file entry.
1112 * vap - attributes of new file.
1113 * excl - flag indicating exclusive or non-exclusive mode.
1114 * mode - mode to open file with.
1115 * cr - credentials of caller.
1116 * flag - large file flag [UNUSED].
1117 * ct - caller context
1118 * vsecp - ACL to be set
1120 * OUT: vpp - vnode of created or trunc'd entry.
1122 * RETURN: 0 if success
1123 * error code if failure
1126 * dvp - ctime|mtime updated if new entry created
1127 * vp - ctime|mtime always, atime if new
1132 zfs_create(vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl,
1133 int mode, vnode_t **vpp, cred_t *cr, int flag, caller_context_t *ct,
1136 znode_t *zp, *dzp = VTOZ(dvp);
1137 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1145 gid_t gid = crgetgid(cr);
1146 zfs_acl_ids_t acl_ids;
1147 boolean_t fuid_dirtied;
1150 * If we have an ephemeral id, ACL, or XVATTR then
1151 * make sure file system is at proper version
1154 ksid = crgetsid(cr, KSID_OWNER);
1156 uid = ksid_getid(ksid);
1160 if (zfsvfs->z_use_fuids == B_FALSE &&
1161 (vsecp || (vap->va_mask & AT_XVATTR) ||
1162 IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
1168 zilog = zfsvfs->z_log;
1170 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
1171 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1176 if (vap->va_mask & AT_XVATTR) {
1177 if ((error = secpolicy_xvattr((xvattr_t *)vap,
1178 crgetuid(cr), cr, vap->va_type)) != 0) {
1186 if ((vap->va_mode & VSVTX) && secpolicy_vnode_stky_modify(cr))
1187 vap->va_mode &= ~VSVTX;
1189 if (*name == '\0') {
1191 * Null component name refers to the directory itself.
1198 /* possible VN_HOLD(zp) */
1201 if (flag & FIGNORECASE)
1204 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1207 if (strcmp(name, "..") == 0)
1217 * Create a new file object and update the directory
1220 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
1225 * We only support the creation of regular files in
1226 * extended attribute directories.
1228 if ((dzp->z_phys->zp_flags & ZFS_XATTR) &&
1229 (vap->va_type != VREG)) {
1234 if ((error = zfs_acl_ids_create(dzp, 0, vap, cr, vsecp,
1237 if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
1242 tx = dmu_tx_create(os);
1243 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1244 fuid_dirtied = zfsvfs->z_fuid_dirty;
1246 zfs_fuid_txhold(zfsvfs, tx);
1247 dmu_tx_hold_bonus(tx, dzp->z_id);
1248 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
1249 if (acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
1250 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
1251 0, SPA_MAXBLOCKSIZE);
1253 error = dmu_tx_assign(tx, TXG_NOWAIT);
1255 zfs_acl_ids_free(&acl_ids);
1256 zfs_dirent_unlock(dl);
1257 if (error == ERESTART) {
1266 zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, &acl_ids);
1269 zfs_fuid_sync(zfsvfs, tx);
1271 (void) zfs_link_create(dl, zp, tx, ZNEW);
1273 txtype = zfs_log_create_txtype(Z_FILE, vsecp, vap);
1274 if (flag & FIGNORECASE)
1276 zfs_log_create(zilog, tx, txtype, dzp, zp, name,
1277 vsecp, acl_ids.z_fuidp, vap);
1278 zfs_acl_ids_free(&acl_ids);
1281 int aflags = (flag & FAPPEND) ? V_APPEND : 0;
1284 * A directory entry already exists for this name.
1287 * Can't truncate an existing file if in exclusive mode.
1294 * Can't open a directory for writing.
1296 if ((ZTOV(zp)->v_type == VDIR) && (mode & S_IWRITE)) {
1301 * Verify requested access to file.
1303 if (mode && (error = zfs_zaccess_rwx(zp, mode, aflags, cr))) {
1307 mutex_enter(&dzp->z_lock);
1309 mutex_exit(&dzp->z_lock);
1312 * Truncate regular files if requested.
1314 if ((ZTOV(zp)->v_type == VREG) &&
1315 (vap->va_mask & AT_SIZE) && (vap->va_size == 0)) {
1316 /* we can't hold any locks when calling zfs_freesp() */
1317 zfs_dirent_unlock(dl);
1319 error = zfs_freesp(zp, 0, 0, mode, TRUE);
1321 vnevent_create(ZTOV(zp), ct);
1328 zfs_dirent_unlock(dl);
1336 * If vnode is for a device return a specfs vnode instead.
1338 if (IS_DEVVP(*vpp)) {
1341 svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
1355 * Remove an entry from a directory.
1357 * IN: dvp - vnode of directory to remove entry from.
1358 * name - name of entry to remove.
1359 * cr - credentials of caller.
1360 * ct - caller context
1361 * flags - case flags
1363 * RETURN: 0 if success
1364 * error code if failure
1368 * vp - ctime (if nlink > 0)
1372 zfs_remove(vnode_t *dvp, char *name, cred_t *cr, caller_context_t *ct,
1375 znode_t *zp, *dzp = VTOZ(dvp);
1376 znode_t *xzp = NULL;
1378 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1380 uint64_t acl_obj, xattr_obj;
1383 boolean_t may_delete_now, delete_now = FALSE;
1384 boolean_t unlinked, toobig = FALSE;
1386 pathname_t *realnmp = NULL;
1393 zilog = zfsvfs->z_log;
1395 if (flags & FIGNORECASE) {
1403 * Attempt to lock directory; fail if entry doesn't exist.
1405 if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1415 if (error = zfs_zaccess_delete(dzp, zp, cr)) {
1420 * Need to use rmdir for removing directories.
1422 if (vp->v_type == VDIR) {
1427 vnevent_remove(vp, dvp, name, ct);
1430 dnlc_remove(dvp, realnmp->pn_buf);
1432 dnlc_remove(dvp, name);
1434 mutex_enter(&vp->v_lock);
1435 may_delete_now = vp->v_count == 1 && !vn_has_cached_data(vp);
1436 mutex_exit(&vp->v_lock);
1439 * We may delete the znode now, or we may put it in the unlinked set;
1440 * it depends on whether we're the last link, and on whether there are
1441 * other holds on the vnode. So we dmu_tx_hold() the right things to
1442 * allow for either case.
1444 tx = dmu_tx_create(zfsvfs->z_os);
1445 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1446 dmu_tx_hold_bonus(tx, zp->z_id);
1447 if (may_delete_now) {
1449 zp->z_phys->zp_size > zp->z_blksz * DMU_MAX_DELETEBLKCNT;
1450 /* if the file is too big, only hold_free a token amount */
1451 dmu_tx_hold_free(tx, zp->z_id, 0,
1452 (toobig ? DMU_MAX_ACCESS : DMU_OBJECT_END));
1455 /* are there any extended attributes? */
1456 if ((xattr_obj = zp->z_phys->zp_xattr) != 0) {
1457 /* XXX - do we need this if we are deleting? */
1458 dmu_tx_hold_bonus(tx, xattr_obj);
1461 /* are there any additional acls */
1462 if ((acl_obj = zp->z_phys->zp_acl.z_acl_extern_obj) != 0 &&
1464 dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END);
1466 /* charge as an update -- would be nice not to charge at all */
1467 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1469 error = dmu_tx_assign(tx, TXG_NOWAIT);
1471 zfs_dirent_unlock(dl);
1473 if (error == ERESTART) {
1486 * Remove the directory entry.
1488 error = zfs_link_destroy(dl, zp, tx, zflg, &unlinked);
1496 mutex_enter(&vp->v_lock);
1497 delete_now = may_delete_now && !toobig &&
1498 vp->v_count == 1 && !vn_has_cached_data(vp) &&
1499 zp->z_phys->zp_xattr == xattr_obj &&
1500 zp->z_phys->zp_acl.z_acl_extern_obj == acl_obj;
1501 mutex_exit(&vp->v_lock);
1505 if (zp->z_phys->zp_xattr) {
1506 error = zfs_zget(zfsvfs, zp->z_phys->zp_xattr, &xzp);
1507 ASSERT3U(error, ==, 0);
1508 ASSERT3U(xzp->z_phys->zp_links, ==, 2);
1509 dmu_buf_will_dirty(xzp->z_dbuf, tx);
1510 mutex_enter(&xzp->z_lock);
1511 xzp->z_unlinked = 1;
1512 xzp->z_phys->zp_links = 0;
1513 mutex_exit(&xzp->z_lock);
1514 zfs_unlinked_add(xzp, tx);
1515 zp->z_phys->zp_xattr = 0; /* probably unnecessary */
1517 mutex_enter(&zp->z_lock);
1518 mutex_enter(&vp->v_lock);
1520 ASSERT3U(vp->v_count, ==, 0);
1521 mutex_exit(&vp->v_lock);
1522 mutex_exit(&zp->z_lock);
1523 zfs_znode_delete(zp, tx);
1524 } else if (unlinked) {
1525 zfs_unlinked_add(zp, tx);
1529 if (flags & FIGNORECASE)
1531 zfs_log_remove(zilog, tx, txtype, dzp, name);
1538 zfs_dirent_unlock(dl);
1543 /* this rele is delayed to prevent nesting transactions */
1552 * Create a new directory and insert it into dvp using the name
1553 * provided. Return a pointer to the inserted directory.
1555 * IN: dvp - vnode of directory to add subdir to.
1556 * dirname - name of new directory.
1557 * vap - attributes of new directory.
1558 * cr - credentials of caller.
1559 * ct - caller context
1560 * vsecp - ACL to be set
1562 * OUT: vpp - vnode of created directory.
1564 * RETURN: 0 if success
1565 * error code if failure
1568 * dvp - ctime|mtime updated
1569 * vp - ctime|mtime|atime updated
1573 zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr,
1574 caller_context_t *ct, int flags, vsecattr_t *vsecp)
1576 znode_t *zp, *dzp = VTOZ(dvp);
1577 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1586 gid_t gid = crgetgid(cr);
1587 zfs_acl_ids_t acl_ids;
1588 boolean_t fuid_dirtied;
1590 ASSERT(vap->va_type == VDIR);
1593 * If we have an ephemeral id, ACL, or XVATTR then
1594 * make sure file system is at proper version
1597 ksid = crgetsid(cr, KSID_OWNER);
1599 uid = ksid_getid(ksid);
1602 if (zfsvfs->z_use_fuids == B_FALSE &&
1603 (vsecp || (vap->va_mask & AT_XVATTR) ||
1604 IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
1609 zilog = zfsvfs->z_log;
1611 if (dzp->z_phys->zp_flags & ZFS_XATTR) {
1616 if (zfsvfs->z_utf8 && u8_validate(dirname,
1617 strlen(dirname), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1621 if (flags & FIGNORECASE)
1624 if (vap->va_mask & AT_XVATTR)
1625 if ((error = secpolicy_xvattr((xvattr_t *)vap,
1626 crgetuid(cr), cr, vap->va_type)) != 0) {
1632 * First make sure the new directory doesn't exist.
1637 if (error = zfs_dirent_lock(&dl, dzp, dirname, &zp, zf,
1643 if (error = zfs_zaccess(dzp, ACE_ADD_SUBDIRECTORY, 0, B_FALSE, cr)) {
1644 zfs_dirent_unlock(dl);
1649 if ((error = zfs_acl_ids_create(dzp, 0, vap, cr, vsecp,
1651 zfs_dirent_unlock(dl);
1655 if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
1656 zfs_dirent_unlock(dl);
1662 * Add a new entry to the directory.
1664 tx = dmu_tx_create(zfsvfs->z_os);
1665 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, dirname);
1666 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
1667 fuid_dirtied = zfsvfs->z_fuid_dirty;
1669 zfs_fuid_txhold(zfsvfs, tx);
1670 if (acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE)
1671 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
1672 0, SPA_MAXBLOCKSIZE);
1673 error = dmu_tx_assign(tx, TXG_NOWAIT);
1675 zfs_acl_ids_free(&acl_ids);
1676 zfs_dirent_unlock(dl);
1677 if (error == ERESTART) {
1690 zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, &acl_ids);
1693 zfs_fuid_sync(zfsvfs, tx);
1695 * Now put new name in parent dir.
1697 (void) zfs_link_create(dl, zp, tx, ZNEW);
1701 txtype = zfs_log_create_txtype(Z_DIR, vsecp, vap);
1702 if (flags & FIGNORECASE)
1704 zfs_log_create(zilog, tx, txtype, dzp, zp, dirname, vsecp,
1705 acl_ids.z_fuidp, vap);
1707 zfs_acl_ids_free(&acl_ids);
1710 zfs_dirent_unlock(dl);
1717 * Remove a directory subdir entry. If the current working
1718 * directory is the same as the subdir to be removed, the
1721 * IN: dvp - vnode of directory to remove from.
1722 * name - name of directory to be removed.
1723 * cwd - vnode of current working directory.
1724 * cr - credentials of caller.
1725 * ct - caller context
1726 * flags - case flags
1728 * RETURN: 0 if success
1729 * error code if failure
1732 * dvp - ctime|mtime updated
1736 zfs_rmdir(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr,
1737 caller_context_t *ct, int flags)
1739 znode_t *dzp = VTOZ(dvp);
1742 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1751 zilog = zfsvfs->z_log;
1753 if (flags & FIGNORECASE)
1759 * Attempt to lock directory; fail if entry doesn't exist.
1761 if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1769 if (error = zfs_zaccess_delete(dzp, zp, cr)) {
1773 if (vp->v_type != VDIR) {
1783 vnevent_rmdir(vp, dvp, name, ct);
1786 * Grab a lock on the directory to make sure that noone is
1787 * trying to add (or lookup) entries while we are removing it.
1789 rw_enter(&zp->z_name_lock, RW_WRITER);
1792 * Grab a lock on the parent pointer to make sure we play well
1793 * with the treewalk and directory rename code.
1795 rw_enter(&zp->z_parent_lock, RW_WRITER);
1797 tx = dmu_tx_create(zfsvfs->z_os);
1798 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1799 dmu_tx_hold_bonus(tx, zp->z_id);
1800 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1801 error = dmu_tx_assign(tx, TXG_NOWAIT);
1803 rw_exit(&zp->z_parent_lock);
1804 rw_exit(&zp->z_name_lock);
1805 zfs_dirent_unlock(dl);
1807 if (error == ERESTART) {
1817 error = zfs_link_destroy(dl, zp, tx, zflg, NULL);
1820 uint64_t txtype = TX_RMDIR;
1821 if (flags & FIGNORECASE)
1823 zfs_log_remove(zilog, tx, txtype, dzp, name);
1828 rw_exit(&zp->z_parent_lock);
1829 rw_exit(&zp->z_name_lock);
1831 zfs_dirent_unlock(dl);
1840 * Read as many directory entries as will fit into the provided
1841 * buffer from the given directory cursor position (specified in
1842 * the uio structure.
1844 * IN: vp - vnode of directory to read.
1845 * uio - structure supplying read location, range info,
1846 * and return buffer.
1847 * cr - credentials of caller.
1848 * ct - caller context
1849 * flags - case flags
1851 * OUT: uio - updated offset and range, buffer filled.
1852 * eofp - set to true if end-of-file detected.
1854 * RETURN: 0 if success
1855 * error code if failure
1858 * vp - atime updated
1860 * Note that the low 4 bits of the cookie returned by zap is always zero.
1861 * This allows us to use the low range for "special" directory entries:
1862 * We use 0 for '.', and 1 for '..'. If this is the root of the filesystem,
1863 * we use the offset 2 for the '.zfs' directory.
1867 zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp,
1868 caller_context_t *ct, int flags)
1870 znode_t *zp = VTOZ(vp);
1874 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1879 zap_attribute_t zap;
1880 uint_t bytes_wanted;
1881 uint64_t offset; /* must be unsigned; checks for < 1 */
1886 boolean_t check_sysattrs;
1892 * If we are not given an eof variable,
1899 * Check for valid iov_len.
1901 if (uio->uio_iov->iov_len <= 0) {
1907 * Quit if directory has been removed (posix)
1909 if ((*eofp = zp->z_unlinked) != 0) {
1916 offset = uio->uio_loffset;
1917 prefetch = zp->z_zn_prefetch;
1920 * Initialize the iterator cursor.
1924 * Start iteration from the beginning of the directory.
1926 zap_cursor_init(&zc, os, zp->z_id);
1929 * The offset is a serialized cursor.
1931 zap_cursor_init_serialized(&zc, os, zp->z_id, offset);
1935 * Get space to change directory entries into fs independent format.
1937 iovp = uio->uio_iov;
1938 bytes_wanted = iovp->iov_len;
1939 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) {
1940 bufsize = bytes_wanted;
1941 outbuf = kmem_alloc(bufsize, KM_SLEEP);
1942 odp = (struct dirent64 *)outbuf;
1944 bufsize = bytes_wanted;
1945 odp = (struct dirent64 *)iovp->iov_base;
1947 eodp = (struct edirent *)odp;
1950 * If this VFS supports the system attribute view interface; and
1951 * we're looking at an extended attribute directory; and we care
1952 * about normalization conflicts on this vfs; then we must check
1953 * for normalization conflicts with the sysattr name space.
1955 check_sysattrs = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
1956 (vp->v_flag & V_XATTRDIR) && zfsvfs->z_norm &&
1957 (flags & V_RDDIR_ENTFLAGS);
1960 * Transform to file-system independent format
1963 while (outcount < bytes_wanted) {
1969 * Special case `.', `..', and `.zfs'.
1972 (void) strcpy(zap.za_name, ".");
1973 zap.za_normalization_conflict = 0;
1975 } else if (offset == 1) {
1976 (void) strcpy(zap.za_name, "..");
1977 zap.za_normalization_conflict = 0;
1978 objnum = zp->z_phys->zp_parent;
1979 } else if (offset == 2 && zfs_show_ctldir(zp)) {
1980 (void) strcpy(zap.za_name, ZFS_CTLDIR_NAME);
1981 zap.za_normalization_conflict = 0;
1982 objnum = ZFSCTL_INO_ROOT;
1987 if (error = zap_cursor_retrieve(&zc, &zap)) {
1988 if ((*eofp = (error == ENOENT)) != 0)
1994 if (zap.za_integer_length != 8 ||
1995 zap.za_num_integers != 1) {
1996 cmn_err(CE_WARN, "zap_readdir: bad directory "
1997 "entry, obj = %lld, offset = %lld\n",
1998 (u_longlong_t)zp->z_id,
1999 (u_longlong_t)offset);
2004 objnum = ZFS_DIRENT_OBJ(zap.za_first_integer);
2006 * MacOS X can extract the object type here such as:
2007 * uint8_t type = ZFS_DIRENT_TYPE(zap.za_first_integer);
2010 if (check_sysattrs && !zap.za_normalization_conflict) {
2011 zap.za_normalization_conflict =
2012 xattr_sysattr_casechk(zap.za_name);
2016 if (flags & V_RDDIR_ACCFILTER) {
2018 * If we have no access at all, don't include
2019 * this entry in the returned information
2022 if (zfs_zget(zp->z_zfsvfs, objnum, &ezp) != 0)
2024 if (!zfs_has_access(ezp, cr)) {
2031 if (flags & V_RDDIR_ENTFLAGS)
2032 reclen = EDIRENT_RECLEN(strlen(zap.za_name));
2034 reclen = DIRENT64_RECLEN(strlen(zap.za_name));
2037 * Will this entry fit in the buffer?
2039 if (outcount + reclen > bufsize) {
2041 * Did we manage to fit anything in the buffer?
2049 if (flags & V_RDDIR_ENTFLAGS) {
2051 * Add extended flag entry:
2053 eodp->ed_ino = objnum;
2054 eodp->ed_reclen = reclen;
2055 /* NOTE: ed_off is the offset for the *next* entry */
2056 next = &(eodp->ed_off);
2057 eodp->ed_eflags = zap.za_normalization_conflict ?
2058 ED_CASE_CONFLICT : 0;
2059 (void) strncpy(eodp->ed_name, zap.za_name,
2060 EDIRENT_NAMELEN(reclen));
2061 eodp = (edirent_t *)((intptr_t)eodp + reclen);
2066 odp->d_ino = objnum;
2067 odp->d_reclen = reclen;
2068 /* NOTE: d_off is the offset for the *next* entry */
2069 next = &(odp->d_off);
2070 (void) strncpy(odp->d_name, zap.za_name,
2071 DIRENT64_NAMELEN(reclen));
2072 odp = (dirent64_t *)((intptr_t)odp + reclen);
2076 ASSERT(outcount <= bufsize);
2078 /* Prefetch znode */
2080 dmu_prefetch(os, objnum, 0, 0);
2084 * Move to the next entry, fill in the previous offset.
2086 if (offset > 2 || (offset == 2 && !zfs_show_ctldir(zp))) {
2087 zap_cursor_advance(&zc);
2088 offset = zap_cursor_serialize(&zc);
2094 zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */
2096 if (uio->uio_segflg == UIO_SYSSPACE && uio->uio_iovcnt == 1) {
2097 iovp->iov_base += outcount;
2098 iovp->iov_len -= outcount;
2099 uio->uio_resid -= outcount;
2100 } else if (error = uiomove(outbuf, (long)outcount, UIO_READ, uio)) {
2102 * Reset the pointer.
2104 offset = uio->uio_loffset;
2108 zap_cursor_fini(&zc);
2109 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
2110 kmem_free(outbuf, bufsize);
2112 if (error == ENOENT)
2115 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
2117 uio->uio_loffset = offset;
2122 ulong_t zfs_fsync_sync_cnt = 4;
2125 zfs_fsync(vnode_t *vp, int syncflag, cred_t *cr, caller_context_t *ct)
2127 znode_t *zp = VTOZ(vp);
2128 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2131 * Regardless of whether this is required for standards conformance,
2132 * this is the logical behavior when fsync() is called on a file with
2133 * dirty pages. We use B_ASYNC since the ZIL transactions are already
2134 * going to be pushed out as part of the zil_commit().
2136 if (vn_has_cached_data(vp) && !(syncflag & FNODSYNC) &&
2137 (vp->v_type == VREG) && !(IS_SWAPVP(vp)))
2138 (void) VOP_PUTPAGE(vp, (offset_t)0, (size_t)0, B_ASYNC, cr, ct);
2140 (void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt);
2144 zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
2151 * Get the requested file attributes and place them in the provided
2154 * IN: vp - vnode of file.
2155 * vap - va_mask identifies requested attributes.
2156 * If AT_XVATTR set, then optional attrs are requested
2157 * flags - ATTR_NOACLCHECK (CIFS server context)
2158 * cr - credentials of caller.
2159 * ct - caller context
2161 * OUT: vap - attribute values.
2163 * RETURN: 0 (always succeeds)
2167 zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2168 caller_context_t *ct)
2170 znode_t *zp = VTOZ(vp);
2171 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2175 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2176 xoptattr_t *xoap = NULL;
2177 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2184 * If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES.
2185 * Also, if we are the owner don't bother, since owner should
2186 * always be allowed to read basic attributes of file.
2188 if (!(pzp->zp_flags & ZFS_ACL_TRIVIAL) &&
2189 (pzp->zp_uid != crgetuid(cr))) {
2190 if (error = zfs_zaccess(zp, ACE_READ_ATTRIBUTES, 0,
2198 * Return all attributes. It's cheaper to provide the answer
2199 * than to determine whether we were asked the question.
2202 mutex_enter(&zp->z_lock);
2203 vap->va_type = vp->v_type;
2204 vap->va_mode = pzp->zp_mode & MODEMASK;
2205 zfs_fuid_map_ids(zp, cr, &vap->va_uid, &vap->va_gid);
2206 vap->va_fsid = zp->z_zfsvfs->z_vfs->vfs_dev;
2207 vap->va_nodeid = zp->z_id;
2208 if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp))
2209 links = pzp->zp_links + 1;
2211 links = pzp->zp_links;
2212 vap->va_nlink = MIN(links, UINT32_MAX); /* nlink_t limit! */
2213 vap->va_size = pzp->zp_size;
2214 vap->va_rdev = vp->v_rdev;
2215 vap->va_seq = zp->z_seq;
2218 * Add in any requested optional attributes and the create time.
2219 * Also set the corresponding bits in the returned attribute bitmap.
2221 if ((xoap = xva_getxoptattr(xvap)) != NULL && zfsvfs->z_use_fuids) {
2222 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
2224 ((pzp->zp_flags & ZFS_ARCHIVE) != 0);
2225 XVA_SET_RTN(xvap, XAT_ARCHIVE);
2228 if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
2229 xoap->xoa_readonly =
2230 ((pzp->zp_flags & ZFS_READONLY) != 0);
2231 XVA_SET_RTN(xvap, XAT_READONLY);
2234 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
2236 ((pzp->zp_flags & ZFS_SYSTEM) != 0);
2237 XVA_SET_RTN(xvap, XAT_SYSTEM);
2240 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
2242 ((pzp->zp_flags & ZFS_HIDDEN) != 0);
2243 XVA_SET_RTN(xvap, XAT_HIDDEN);
2246 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
2247 xoap->xoa_nounlink =
2248 ((pzp->zp_flags & ZFS_NOUNLINK) != 0);
2249 XVA_SET_RTN(xvap, XAT_NOUNLINK);
2252 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
2253 xoap->xoa_immutable =
2254 ((pzp->zp_flags & ZFS_IMMUTABLE) != 0);
2255 XVA_SET_RTN(xvap, XAT_IMMUTABLE);
2258 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
2259 xoap->xoa_appendonly =
2260 ((pzp->zp_flags & ZFS_APPENDONLY) != 0);
2261 XVA_SET_RTN(xvap, XAT_APPENDONLY);
2264 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
2266 ((pzp->zp_flags & ZFS_NODUMP) != 0);
2267 XVA_SET_RTN(xvap, XAT_NODUMP);
2270 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
2272 ((pzp->zp_flags & ZFS_OPAQUE) != 0);
2273 XVA_SET_RTN(xvap, XAT_OPAQUE);
2276 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
2277 xoap->xoa_av_quarantined =
2278 ((pzp->zp_flags & ZFS_AV_QUARANTINED) != 0);
2279 XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
2282 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
2283 xoap->xoa_av_modified =
2284 ((pzp->zp_flags & ZFS_AV_MODIFIED) != 0);
2285 XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
2288 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) &&
2289 vp->v_type == VREG &&
2290 (pzp->zp_flags & ZFS_BONUS_SCANSTAMP)) {
2292 dmu_object_info_t doi;
2295 * Only VREG files have anti-virus scanstamps, so we
2296 * won't conflict with symlinks in the bonus buffer.
2298 dmu_object_info_from_db(zp->z_dbuf, &doi);
2299 len = sizeof (xoap->xoa_av_scanstamp) +
2300 sizeof (znode_phys_t);
2301 if (len <= doi.doi_bonus_size) {
2303 * pzp points to the start of the
2304 * znode_phys_t. pzp + 1 points to the
2305 * first byte after the znode_phys_t.
2307 (void) memcpy(xoap->xoa_av_scanstamp,
2309 sizeof (xoap->xoa_av_scanstamp));
2310 XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
2314 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
2315 ZFS_TIME_DECODE(&xoap->xoa_createtime, pzp->zp_crtime);
2316 XVA_SET_RTN(xvap, XAT_CREATETIME);
2320 ZFS_TIME_DECODE(&vap->va_atime, pzp->zp_atime);
2321 ZFS_TIME_DECODE(&vap->va_mtime, pzp->zp_mtime);
2322 ZFS_TIME_DECODE(&vap->va_ctime, pzp->zp_ctime);
2324 mutex_exit(&zp->z_lock);
2326 dmu_object_size_from_db(zp->z_dbuf, &vap->va_blksize, &vap->va_nblocks);
2328 if (zp->z_blksz == 0) {
2330 * Block size hasn't been set; suggest maximal I/O transfers.
2332 vap->va_blksize = zfsvfs->z_max_blksz;
2340 * Set the file attributes to the values contained in the
2343 * IN: vp - vnode of file to be modified.
2344 * vap - new attribute values.
2345 * If AT_XVATTR set, then optional attrs are being set
2346 * flags - ATTR_UTIME set if non-default time values provided.
2347 * - ATTR_NOACLCHECK (CIFS context only).
2348 * cr - credentials of caller.
2349 * ct - caller context
2351 * RETURN: 0 if success
2352 * error code if failure
2355 * vp - ctime updated, mtime updated if size changed.
2359 zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2360 caller_context_t *ct)
2362 znode_t *zp = VTOZ(vp);
2364 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2369 uint_t mask = vap->va_mask;
2373 uint64_t new_uid, new_gid;
2375 int need_policy = FALSE;
2377 zfs_fuid_info_t *fuidp = NULL;
2378 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2380 zfs_acl_t *aclp = NULL;
2381 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2382 boolean_t fuid_dirtied = B_FALSE;
2387 if (mask & AT_NOSET)
2394 zilog = zfsvfs->z_log;
2397 * Make sure that if we have ephemeral uid/gid or xvattr specified
2398 * that file system is at proper version level
2401 if (zfsvfs->z_use_fuids == B_FALSE &&
2402 (((mask & AT_UID) && IS_EPHEMERAL(vap->va_uid)) ||
2403 ((mask & AT_GID) && IS_EPHEMERAL(vap->va_gid)) ||
2404 (mask & AT_XVATTR))) {
2409 if (mask & AT_SIZE && vp->v_type == VDIR) {
2414 if (mask & AT_SIZE && vp->v_type != VREG && vp->v_type != VFIFO) {
2420 * If this is an xvattr_t, then get a pointer to the structure of
2421 * optional attributes. If this is NULL, then we have a vattr_t.
2423 xoap = xva_getxoptattr(xvap);
2425 xva_init(&tmpxvattr);
2428 * Immutable files can only alter immutable bit and atime
2430 if ((pzp->zp_flags & ZFS_IMMUTABLE) &&
2431 ((mask & (AT_SIZE|AT_UID|AT_GID|AT_MTIME|AT_MODE)) ||
2432 ((mask & AT_XVATTR) && XVA_ISSET_REQ(xvap, XAT_CREATETIME)))) {
2437 if ((mask & AT_SIZE) && (pzp->zp_flags & ZFS_READONLY)) {
2443 * Verify timestamps doesn't overflow 32 bits.
2444 * ZFS can handle large timestamps, but 32bit syscalls can't
2445 * handle times greater than 2039. This check should be removed
2446 * once large timestamps are fully supported.
2448 if (mask & (AT_ATIME | AT_MTIME)) {
2449 if (((mask & AT_ATIME) && TIMESPEC_OVERFLOW(&vap->va_atime)) ||
2450 ((mask & AT_MTIME) && TIMESPEC_OVERFLOW(&vap->va_mtime))) {
2459 if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) {
2465 * First validate permissions
2468 if (mask & AT_SIZE) {
2469 err = zfs_zaccess(zp, ACE_WRITE_DATA, 0, skipaclchk, cr);
2475 * XXX - Note, we are not providing any open
2476 * mode flags here (like FNDELAY), so we may
2477 * block if there are locks present... this
2478 * should be addressed in openat().
2480 /* XXX - would it be OK to generate a log record here? */
2481 err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE);
2488 if (mask & (AT_ATIME|AT_MTIME) ||
2489 ((mask & AT_XVATTR) && (XVA_ISSET_REQ(xvap, XAT_HIDDEN) ||
2490 XVA_ISSET_REQ(xvap, XAT_READONLY) ||
2491 XVA_ISSET_REQ(xvap, XAT_ARCHIVE) ||
2492 XVA_ISSET_REQ(xvap, XAT_CREATETIME) ||
2493 XVA_ISSET_REQ(xvap, XAT_SYSTEM))))
2494 need_policy = zfs_zaccess(zp, ACE_WRITE_ATTRIBUTES, 0,
2497 if (mask & (AT_UID|AT_GID)) {
2498 int idmask = (mask & (AT_UID|AT_GID));
2503 * NOTE: even if a new mode is being set,
2504 * we may clear S_ISUID/S_ISGID bits.
2507 if (!(mask & AT_MODE))
2508 vap->va_mode = pzp->zp_mode;
2511 * Take ownership or chgrp to group we are a member of
2514 take_owner = (mask & AT_UID) && (vap->va_uid == crgetuid(cr));
2515 take_group = (mask & AT_GID) &&
2516 zfs_groupmember(zfsvfs, vap->va_gid, cr);
2519 * If both AT_UID and AT_GID are set then take_owner and
2520 * take_group must both be set in order to allow taking
2523 * Otherwise, send the check through secpolicy_vnode_setattr()
2527 if (((idmask == (AT_UID|AT_GID)) && take_owner && take_group) ||
2528 ((idmask == AT_UID) && take_owner) ||
2529 ((idmask == AT_GID) && take_group)) {
2530 if (zfs_zaccess(zp, ACE_WRITE_OWNER, 0,
2531 skipaclchk, cr) == 0) {
2533 * Remove setuid/setgid for non-privileged users
2535 secpolicy_setid_clear(vap, cr);
2536 trim_mask = (mask & (AT_UID|AT_GID));
2545 mutex_enter(&zp->z_lock);
2546 oldva.va_mode = pzp->zp_mode;
2547 zfs_fuid_map_ids(zp, cr, &oldva.va_uid, &oldva.va_gid);
2548 if (mask & AT_XVATTR) {
2550 * Update xvattr mask to include only those attributes
2551 * that are actually changing.
2553 * the bits will be restored prior to actually setting
2554 * the attributes so the caller thinks they were set.
2556 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
2557 if (xoap->xoa_appendonly !=
2558 ((pzp->zp_flags & ZFS_APPENDONLY) != 0)) {
2561 XVA_CLR_REQ(xvap, XAT_APPENDONLY);
2562 XVA_SET_REQ(&tmpxvattr, XAT_APPENDONLY);
2566 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
2567 if (xoap->xoa_nounlink !=
2568 ((pzp->zp_flags & ZFS_NOUNLINK) != 0)) {
2571 XVA_CLR_REQ(xvap, XAT_NOUNLINK);
2572 XVA_SET_REQ(&tmpxvattr, XAT_NOUNLINK);
2576 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
2577 if (xoap->xoa_immutable !=
2578 ((pzp->zp_flags & ZFS_IMMUTABLE) != 0)) {
2581 XVA_CLR_REQ(xvap, XAT_IMMUTABLE);
2582 XVA_SET_REQ(&tmpxvattr, XAT_IMMUTABLE);
2586 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
2587 if (xoap->xoa_nodump !=
2588 ((pzp->zp_flags & ZFS_NODUMP) != 0)) {
2591 XVA_CLR_REQ(xvap, XAT_NODUMP);
2592 XVA_SET_REQ(&tmpxvattr, XAT_NODUMP);
2596 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
2597 if (xoap->xoa_av_modified !=
2598 ((pzp->zp_flags & ZFS_AV_MODIFIED) != 0)) {
2601 XVA_CLR_REQ(xvap, XAT_AV_MODIFIED);
2602 XVA_SET_REQ(&tmpxvattr, XAT_AV_MODIFIED);
2606 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
2607 if ((vp->v_type != VREG &&
2608 xoap->xoa_av_quarantined) ||
2609 xoap->xoa_av_quarantined !=
2610 ((pzp->zp_flags & ZFS_AV_QUARANTINED) != 0)) {
2613 XVA_CLR_REQ(xvap, XAT_AV_QUARANTINED);
2614 XVA_SET_REQ(&tmpxvattr, XAT_AV_QUARANTINED);
2618 if (need_policy == FALSE &&
2619 (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) ||
2620 XVA_ISSET_REQ(xvap, XAT_OPAQUE))) {
2625 mutex_exit(&zp->z_lock);
2627 if (mask & AT_MODE) {
2628 if (zfs_zaccess(zp, ACE_WRITE_ACL, 0, skipaclchk, cr) == 0) {
2629 err = secpolicy_setid_setsticky_clear(vp, vap,
2635 trim_mask |= AT_MODE;
2643 * If trim_mask is set then take ownership
2644 * has been granted or write_acl is present and user
2645 * has the ability to modify mode. In that case remove
2646 * UID|GID and or MODE from mask so that
2647 * secpolicy_vnode_setattr() doesn't revoke it.
2651 saved_mask = vap->va_mask;
2652 vap->va_mask &= ~trim_mask;
2654 err = secpolicy_vnode_setattr(cr, vp, vap, &oldva, flags,
2655 (int (*)(void *, int, cred_t *))zfs_zaccess_unix, zp);
2662 vap->va_mask |= saved_mask;
2666 * secpolicy_vnode_setattr, or take ownership may have
2669 mask = vap->va_mask;
2671 tx = dmu_tx_create(zfsvfs->z_os);
2672 dmu_tx_hold_bonus(tx, zp->z_id);
2674 if (mask & AT_MODE) {
2675 uint64_t pmode = pzp->zp_mode;
2677 new_mode = (pmode & S_IFMT) | (vap->va_mode & ~S_IFMT);
2679 if (err = zfs_acl_chmod_setattr(zp, &aclp, new_mode))
2681 if (pzp->zp_acl.z_acl_extern_obj) {
2682 /* Are we upgrading ACL from old V0 format to new V1 */
2683 if (zfsvfs->z_version <= ZPL_VERSION_FUID &&
2684 pzp->zp_acl.z_acl_version ==
2685 ZFS_ACL_VERSION_INITIAL) {
2686 dmu_tx_hold_free(tx,
2687 pzp->zp_acl.z_acl_extern_obj, 0,
2689 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
2690 0, aclp->z_acl_bytes);
2692 dmu_tx_hold_write(tx,
2693 pzp->zp_acl.z_acl_extern_obj, 0,
2696 } else if (aclp->z_acl_bytes > ZFS_ACE_SPACE) {
2697 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
2698 0, aclp->z_acl_bytes);
2702 if (mask & (AT_UID | AT_GID)) {
2703 if (pzp->zp_xattr) {
2704 err = zfs_zget(zp->z_zfsvfs, pzp->zp_xattr, &attrzp);
2707 dmu_tx_hold_bonus(tx, attrzp->z_id);
2709 if (mask & AT_UID) {
2710 new_uid = zfs_fuid_create(zfsvfs,
2711 (uint64_t)vap->va_uid, cr, ZFS_OWNER, &fuidp);
2712 if (new_uid != pzp->zp_uid &&
2713 zfs_usergroup_overquota(zfsvfs, B_FALSE, new_uid)) {
2719 if (mask & AT_GID) {
2720 new_gid = zfs_fuid_create(zfsvfs, (uint64_t)vap->va_gid,
2721 cr, ZFS_GROUP, &fuidp);
2722 if (new_gid != pzp->zp_gid &&
2723 zfs_usergroup_overquota(zfsvfs, B_TRUE, new_gid)) {
2728 fuid_dirtied = zfsvfs->z_fuid_dirty;
2730 if (zfsvfs->z_fuid_obj == 0) {
2731 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
2732 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
2733 FUID_SIZE_ESTIMATE(zfsvfs));
2734 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ,
2737 dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj);
2738 dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0,
2739 FUID_SIZE_ESTIMATE(zfsvfs));
2744 err = dmu_tx_assign(tx, TXG_NOWAIT);
2746 if (err == ERESTART)
2751 dmu_buf_will_dirty(zp->z_dbuf, tx);
2754 * Set each attribute requested.
2755 * We group settings according to the locks they need to acquire.
2757 * Note: you cannot set ctime directly, although it will be
2758 * updated as a side-effect of calling this function.
2761 mutex_enter(&zp->z_lock);
2763 if (mask & AT_MODE) {
2764 mutex_enter(&zp->z_acl_lock);
2765 zp->z_phys->zp_mode = new_mode;
2766 err = zfs_aclset_common(zp, aclp, cr, tx);
2767 ASSERT3U(err, ==, 0);
2768 mutex_exit(&zp->z_acl_lock);
2772 mutex_enter(&attrzp->z_lock);
2774 if (mask & AT_UID) {
2775 pzp->zp_uid = new_uid;
2777 attrzp->z_phys->zp_uid = new_uid;
2780 if (mask & AT_GID) {
2781 pzp->zp_gid = new_gid;
2783 attrzp->z_phys->zp_gid = new_gid;
2787 mutex_exit(&attrzp->z_lock);
2789 if (mask & AT_ATIME)
2790 ZFS_TIME_ENCODE(&vap->va_atime, pzp->zp_atime);
2792 if (mask & AT_MTIME)
2793 ZFS_TIME_ENCODE(&vap->va_mtime, pzp->zp_mtime);
2795 /* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
2797 zfs_time_stamper_locked(zp, CONTENT_MODIFIED, tx);
2799 zfs_time_stamper_locked(zp, STATE_CHANGED, tx);
2801 * Do this after setting timestamps to prevent timestamp
2802 * update from toggling bit
2805 if (xoap && (mask & AT_XVATTR)) {
2808 * restore trimmed off masks
2809 * so that return masks can be set for caller.
2812 if (XVA_ISSET_REQ(&tmpxvattr, XAT_APPENDONLY)) {
2813 XVA_SET_REQ(xvap, XAT_APPENDONLY);
2815 if (XVA_ISSET_REQ(&tmpxvattr, XAT_NOUNLINK)) {
2816 XVA_SET_REQ(xvap, XAT_NOUNLINK);
2818 if (XVA_ISSET_REQ(&tmpxvattr, XAT_IMMUTABLE)) {
2819 XVA_SET_REQ(xvap, XAT_IMMUTABLE);
2821 if (XVA_ISSET_REQ(&tmpxvattr, XAT_NODUMP)) {
2822 XVA_SET_REQ(xvap, XAT_NODUMP);
2824 if (XVA_ISSET_REQ(&tmpxvattr, XAT_AV_MODIFIED)) {
2825 XVA_SET_REQ(xvap, XAT_AV_MODIFIED);
2827 if (XVA_ISSET_REQ(&tmpxvattr, XAT_AV_QUARANTINED)) {
2828 XVA_SET_REQ(xvap, XAT_AV_QUARANTINED);
2831 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
2833 dmu_object_info_t doi;
2835 ASSERT(vp->v_type == VREG);
2837 /* Grow the bonus buffer if necessary. */
2838 dmu_object_info_from_db(zp->z_dbuf, &doi);
2839 len = sizeof (xoap->xoa_av_scanstamp) +
2840 sizeof (znode_phys_t);
2841 if (len > doi.doi_bonus_size)
2842 VERIFY(dmu_set_bonus(zp->z_dbuf, len, tx) == 0);
2844 zfs_xvattr_set(zp, xvap);
2848 zfs_fuid_sync(zfsvfs, tx);
2851 zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp);
2853 mutex_exit(&zp->z_lock);
2857 VN_RELE(ZTOV(attrzp));
2865 zfs_fuid_info_free(fuidp);
2874 if (err == ERESTART)
2881 typedef struct zfs_zlock {
2882 krwlock_t *zl_rwlock; /* lock we acquired */
2883 znode_t *zl_znode; /* znode we held */
2884 struct zfs_zlock *zl_next; /* next in list */
2888 * Drop locks and release vnodes that were held by zfs_rename_lock().
2891 zfs_rename_unlock(zfs_zlock_t **zlpp)
2895 while ((zl = *zlpp) != NULL) {
2896 if (zl->zl_znode != NULL)
2897 VN_RELE(ZTOV(zl->zl_znode));
2898 rw_exit(zl->zl_rwlock);
2899 *zlpp = zl->zl_next;
2900 kmem_free(zl, sizeof (*zl));
2905 * Search back through the directory tree, using the ".." entries.
2906 * Lock each directory in the chain to prevent concurrent renames.
2907 * Fail any attempt to move a directory into one of its own descendants.
2908 * XXX - z_parent_lock can overlap with map or grow locks
2911 zfs_rename_lock(znode_t *szp, znode_t *tdzp, znode_t *sdzp, zfs_zlock_t **zlpp)
2915 uint64_t rootid = zp->z_zfsvfs->z_root;
2916 uint64_t *oidp = &zp->z_id;
2917 krwlock_t *rwlp = &szp->z_parent_lock;
2918 krw_t rw = RW_WRITER;
2921 * First pass write-locks szp and compares to zp->z_id.
2922 * Later passes read-lock zp and compare to zp->z_parent.
2925 if (!rw_tryenter(rwlp, rw)) {
2927 * Another thread is renaming in this path.
2928 * Note that if we are a WRITER, we don't have any
2929 * parent_locks held yet.
2931 if (rw == RW_READER && zp->z_id > szp->z_id) {
2933 * Drop our locks and restart
2935 zfs_rename_unlock(&zl);
2939 rwlp = &szp->z_parent_lock;
2944 * Wait for other thread to drop its locks
2950 zl = kmem_alloc(sizeof (*zl), KM_SLEEP);
2951 zl->zl_rwlock = rwlp;
2952 zl->zl_znode = NULL;
2953 zl->zl_next = *zlpp;
2956 if (*oidp == szp->z_id) /* We're a descendant of szp */
2959 if (*oidp == rootid) /* We've hit the top */
2962 if (rw == RW_READER) { /* i.e. not the first pass */
2963 int error = zfs_zget(zp->z_zfsvfs, *oidp, &zp);
2968 oidp = &zp->z_phys->zp_parent;
2969 rwlp = &zp->z_parent_lock;
2972 } while (zp->z_id != sdzp->z_id);
2978 * Move an entry from the provided source directory to the target
2979 * directory. Change the entry name as indicated.
2981 * IN: sdvp - Source directory containing the "old entry".
2982 * snm - Old entry name.
2983 * tdvp - Target directory to contain the "new entry".
2984 * tnm - New entry name.
2985 * cr - credentials of caller.
2986 * ct - caller context
2987 * flags - case flags
2989 * RETURN: 0 if success
2990 * error code if failure
2993 * sdvp,tdvp - ctime|mtime updated
2997 zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr,
2998 caller_context_t *ct, int flags)
3000 znode_t *tdzp, *szp, *tzp;
3001 znode_t *sdzp = VTOZ(sdvp);
3002 zfsvfs_t *zfsvfs = sdzp->z_zfsvfs;
3005 zfs_dirlock_t *sdl, *tdl;
3008 int cmp, serr, terr;
3013 ZFS_VERIFY_ZP(sdzp);
3014 zilog = zfsvfs->z_log;
3017 * Make sure we have the real vp for the target directory.
3019 if (VOP_REALVP(tdvp, &realvp, ct) == 0)
3022 if (tdvp->v_vfsp != sdvp->v_vfsp) {
3028 ZFS_VERIFY_ZP(tdzp);
3029 if (zfsvfs->z_utf8 && u8_validate(tnm,
3030 strlen(tnm), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3035 if (flags & FIGNORECASE)
3044 * This is to prevent the creation of links into attribute space
3045 * by renaming a linked file into/outof an attribute directory.
3046 * See the comment in zfs_link() for why this is considered bad.
3048 if ((tdzp->z_phys->zp_flags & ZFS_XATTR) !=
3049 (sdzp->z_phys->zp_flags & ZFS_XATTR)) {
3055 * Lock source and target directory entries. To prevent deadlock,
3056 * a lock ordering must be defined. We lock the directory with
3057 * the smallest object id first, or if it's a tie, the one with
3058 * the lexically first name.
3060 if (sdzp->z_id < tdzp->z_id) {
3062 } else if (sdzp->z_id > tdzp->z_id) {
3066 * First compare the two name arguments without
3067 * considering any case folding.
3069 int nofold = (zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER);
3071 cmp = u8_strcmp(snm, tnm, 0, nofold, U8_UNICODE_LATEST, &error);
3072 ASSERT(error == 0 || !zfsvfs->z_utf8);
3075 * POSIX: "If the old argument and the new argument
3076 * both refer to links to the same existing file,
3077 * the rename() function shall return successfully
3078 * and perform no other action."
3084 * If the file system is case-folding, then we may
3085 * have some more checking to do. A case-folding file
3086 * system is either supporting mixed case sensitivity
3087 * access or is completely case-insensitive. Note
3088 * that the file system is always case preserving.
3090 * In mixed sensitivity mode case sensitive behavior
3091 * is the default. FIGNORECASE must be used to
3092 * explicitly request case insensitive behavior.
3094 * If the source and target names provided differ only
3095 * by case (e.g., a request to rename 'tim' to 'Tim'),
3096 * we will treat this as a special case in the
3097 * case-insensitive mode: as long as the source name
3098 * is an exact match, we will allow this to proceed as
3099 * a name-change request.
3101 if ((zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
3102 (zfsvfs->z_case == ZFS_CASE_MIXED &&
3103 flags & FIGNORECASE)) &&
3104 u8_strcmp(snm, tnm, 0, zfsvfs->z_norm, U8_UNICODE_LATEST,
3107 * case preserving rename request, require exact
3116 serr = zfs_dirent_lock(&sdl, sdzp, snm, &szp,
3117 ZEXISTS | zflg, NULL, NULL);
3118 terr = zfs_dirent_lock(&tdl,
3119 tdzp, tnm, &tzp, ZRENAMING | zflg, NULL, NULL);
3121 terr = zfs_dirent_lock(&tdl,
3122 tdzp, tnm, &tzp, zflg, NULL, NULL);
3123 serr = zfs_dirent_lock(&sdl,
3124 sdzp, snm, &szp, ZEXISTS | ZRENAMING | zflg,
3130 * Source entry invalid or not there.
3133 zfs_dirent_unlock(tdl);
3137 if (strcmp(snm, "..") == 0)
3143 zfs_dirent_unlock(sdl);
3145 if (strcmp(tnm, "..") == 0)
3152 * Must have write access at the source to remove the old entry
3153 * and write access at the target to create the new entry.
3154 * Note that if target and source are the same, this can be
3155 * done in a single check.
3158 if (error = zfs_zaccess_rename(sdzp, szp, tdzp, tzp, cr))
3161 if (ZTOV(szp)->v_type == VDIR) {
3163 * Check to make sure rename is valid.
3164 * Can't do a move like this: /usr/a/b to /usr/a/b/c/d
3166 if (error = zfs_rename_lock(szp, tdzp, sdzp, &zl))
3171 * Does target exist?
3175 * Source and target must be the same type.
3177 if (ZTOV(szp)->v_type == VDIR) {
3178 if (ZTOV(tzp)->v_type != VDIR) {
3183 if (ZTOV(tzp)->v_type == VDIR) {
3189 * POSIX dictates that when the source and target
3190 * entries refer to the same file object, rename
3191 * must do nothing and exit without error.
3193 if (szp->z_id == tzp->z_id) {
3199 vnevent_rename_src(ZTOV(szp), sdvp, snm, ct);
3201 vnevent_rename_dest(ZTOV(tzp), tdvp, tnm, ct);
3204 * notify the target directory if it is not the same
3205 * as source directory.
3208 vnevent_rename_dest_dir(tdvp, ct);
3211 tx = dmu_tx_create(zfsvfs->z_os);
3212 dmu_tx_hold_bonus(tx, szp->z_id); /* nlink changes */
3213 dmu_tx_hold_bonus(tx, sdzp->z_id); /* nlink changes */
3214 dmu_tx_hold_zap(tx, sdzp->z_id, FALSE, snm);
3215 dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, tnm);
3217 dmu_tx_hold_bonus(tx, tdzp->z_id); /* nlink changes */
3219 dmu_tx_hold_bonus(tx, tzp->z_id); /* parent changes */
3220 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
3221 error = dmu_tx_assign(tx, TXG_NOWAIT);
3224 zfs_rename_unlock(&zl);
3225 zfs_dirent_unlock(sdl);
3226 zfs_dirent_unlock(tdl);
3230 if (error == ERESTART) {
3240 if (tzp) /* Attempt to remove the existing target */
3241 error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL);
3244 error = zfs_link_create(tdl, szp, tx, ZRENAMING);
3246 szp->z_phys->zp_flags |= ZFS_AV_MODIFIED;
3248 error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL);
3251 zfs_log_rename(zilog, tx,
3252 TX_RENAME | (flags & FIGNORECASE ? TX_CI : 0),
3253 sdzp, sdl->dl_name, tdzp, tdl->dl_name, szp);
3255 /* Update path information for the target vnode */
3256 vn_renamepath(tdvp, ZTOV(szp), tnm, strlen(tnm));
3263 zfs_rename_unlock(&zl);
3265 zfs_dirent_unlock(sdl);
3266 zfs_dirent_unlock(tdl);
3277 * Insert the indicated symbolic reference entry into the directory.
3279 * IN: dvp - Directory to contain new symbolic link.
3280 * link - Name for new symlink entry.
3281 * vap - Attributes of new entry.
3282 * target - Target path of new symlink.
3283 * cr - credentials of caller.
3284 * ct - caller context
3285 * flags - case flags
3287 * RETURN: 0 if success
3288 * error code if failure
3291 * dvp - ctime|mtime updated
3295 zfs_symlink(vnode_t *dvp, char *name, vattr_t *vap, char *link, cred_t *cr,
3296 caller_context_t *ct, int flags)
3298 znode_t *zp, *dzp = VTOZ(dvp);
3301 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3303 int len = strlen(link);
3306 zfs_acl_ids_t acl_ids;
3307 boolean_t fuid_dirtied;
3309 ASSERT(vap->va_type == VLNK);
3313 zilog = zfsvfs->z_log;
3315 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
3316 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3320 if (flags & FIGNORECASE)
3323 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
3328 if (len > MAXPATHLEN) {
3330 return (ENAMETOOLONG);
3334 * Attempt to lock directory; fail if entry already exists.
3336 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, NULL, NULL);
3342 VERIFY(0 == zfs_acl_ids_create(dzp, 0, vap, cr, NULL, &acl_ids));
3343 if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
3344 zfs_acl_ids_free(&acl_ids);
3345 zfs_dirent_unlock(dl);
3349 tx = dmu_tx_create(zfsvfs->z_os);
3350 fuid_dirtied = zfsvfs->z_fuid_dirty;
3351 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, MAX(1, len));
3352 dmu_tx_hold_bonus(tx, dzp->z_id);
3353 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
3354 if (acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE)
3355 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, SPA_MAXBLOCKSIZE);
3357 zfs_fuid_txhold(zfsvfs, tx);
3358 error = dmu_tx_assign(tx, TXG_NOWAIT);
3360 zfs_acl_ids_free(&acl_ids);
3361 zfs_dirent_unlock(dl);
3362 if (error == ERESTART) {
3372 dmu_buf_will_dirty(dzp->z_dbuf, tx);
3375 * Create a new object for the symlink.
3376 * Put the link content into bonus buffer if it will fit;
3377 * otherwise, store it just like any other file data.
3379 if (sizeof (znode_phys_t) + len <= dmu_bonus_max()) {
3380 zfs_mknode(dzp, vap, tx, cr, 0, &zp, len, &acl_ids);
3382 bcopy(link, zp->z_phys + 1, len);
3386 zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, &acl_ids);
3389 zfs_fuid_sync(zfsvfs, tx);
3391 * Nothing can access the znode yet so no locking needed
3392 * for growing the znode's blocksize.
3394 zfs_grow_blocksize(zp, len, tx);
3396 VERIFY(0 == dmu_buf_hold(zfsvfs->z_os,
3397 zp->z_id, 0, FTAG, &dbp));
3398 dmu_buf_will_dirty(dbp, tx);
3400 ASSERT3U(len, <=, dbp->db_size);
3401 bcopy(link, dbp->db_data, len);
3402 dmu_buf_rele(dbp, FTAG);
3404 zp->z_phys->zp_size = len;
3407 * Insert the new object into the directory.
3409 (void) zfs_link_create(dl, zp, tx, ZNEW);
3411 uint64_t txtype = TX_SYMLINK;
3412 if (flags & FIGNORECASE)
3414 zfs_log_symlink(zilog, tx, txtype, dzp, zp, name, link);
3417 zfs_acl_ids_free(&acl_ids);
3421 zfs_dirent_unlock(dl);
3430 * Return, in the buffer contained in the provided uio structure,
3431 * the symbolic path referred to by vp.
3433 * IN: vp - vnode of symbolic link.
3434 * uoip - structure to contain the link path.
3435 * cr - credentials of caller.
3436 * ct - caller context
3438 * OUT: uio - structure to contain the link path.
3440 * RETURN: 0 if success
3441 * error code if failure
3444 * vp - atime updated
3448 zfs_readlink(vnode_t *vp, uio_t *uio, cred_t *cr, caller_context_t *ct)
3450 znode_t *zp = VTOZ(vp);
3451 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3458 bufsz = (size_t)zp->z_phys->zp_size;
3459 if (bufsz + sizeof (znode_phys_t) <= zp->z_dbuf->db_size) {
3460 error = uiomove(zp->z_phys + 1,
3461 MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
3464 error = dmu_buf_hold(zfsvfs->z_os, zp->z_id, 0, FTAG, &dbp);
3469 error = uiomove(dbp->db_data,
3470 MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
3471 dmu_buf_rele(dbp, FTAG);
3474 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
3480 * Insert a new entry into directory tdvp referencing svp.
3482 * IN: tdvp - Directory to contain new entry.
3483 * svp - vnode of new entry.
3484 * name - name of new entry.
3485 * cr - credentials of caller.
3486 * ct - caller context
3488 * RETURN: 0 if success
3489 * error code if failure
3492 * tdvp - ctime|mtime updated
3493 * svp - ctime updated
3497 zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr,
3498 caller_context_t *ct, int flags)
3500 znode_t *dzp = VTOZ(tdvp);
3502 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3511 ASSERT(tdvp->v_type == VDIR);
3515 zilog = zfsvfs->z_log;
3517 if (VOP_REALVP(svp, &realvp, ct) == 0)
3520 if (svp->v_vfsp != tdvp->v_vfsp) {
3527 if (zfsvfs->z_utf8 && u8_validate(name,
3528 strlen(name), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3532 if (flags & FIGNORECASE)
3537 * We do not support links between attributes and non-attributes
3538 * because of the potential security risk of creating links
3539 * into "normal" file space in order to circumvent restrictions
3540 * imposed in attribute space.
3542 if ((szp->z_phys->zp_flags & ZFS_XATTR) !=
3543 (dzp->z_phys->zp_flags & ZFS_XATTR)) {
3549 * POSIX dictates that we return EPERM here.
3550 * Better choices include ENOTSUP or EISDIR.
3552 if (svp->v_type == VDIR) {
3557 owner = zfs_fuid_map_id(zfsvfs, szp->z_phys->zp_uid, cr, ZFS_OWNER);
3558 if (owner != crgetuid(cr) &&
3559 secpolicy_basic_link(cr) != 0) {
3564 if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
3570 * Attempt to lock directory; fail if entry already exists.
3572 error = zfs_dirent_lock(&dl, dzp, name, &tzp, zf, NULL, NULL);
3578 tx = dmu_tx_create(zfsvfs->z_os);
3579 dmu_tx_hold_bonus(tx, szp->z_id);
3580 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
3581 error = dmu_tx_assign(tx, TXG_NOWAIT);
3583 zfs_dirent_unlock(dl);
3584 if (error == ERESTART) {
3594 error = zfs_link_create(dl, szp, tx, 0);
3597 uint64_t txtype = TX_LINK;
3598 if (flags & FIGNORECASE)
3600 zfs_log_link(zilog, tx, txtype, dzp, szp, name);
3605 zfs_dirent_unlock(dl);
3608 vnevent_link(svp, ct);
3616 * zfs_null_putapage() is used when the file system has been force
3617 * unmounted. It just drops the pages.
3621 zfs_null_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
3622 size_t *lenp, int flags, cred_t *cr)
3624 pvn_write_done(pp, B_INVAL|B_FORCE|B_ERROR);
3629 * Push a page out to disk, klustering if possible.
3631 * IN: vp - file to push page to.
3632 * pp - page to push.
3633 * flags - additional flags.
3634 * cr - credentials of caller.
3636 * OUT: offp - start of range pushed.
3637 * lenp - len of range pushed.
3639 * RETURN: 0 if success
3640 * error code if failure
3642 * NOTE: callers must have locked the page to be pushed. On
3643 * exit, the page (and all other pages in the kluster) must be
3648 zfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
3649 size_t *lenp, int flags, cred_t *cr)
3651 znode_t *zp = VTOZ(vp);
3652 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3654 u_offset_t off, koff;
3659 filesz = zp->z_phys->zp_size;
3663 * If our blocksize is bigger than the page size, try to kluster
3664 * multiple pages so that we write a full block (thus avoiding
3665 * a read-modify-write).
3667 if (off < filesz && zp->z_blksz > PAGESIZE) {
3668 klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE);
3669 koff = ISP2(klen) ? P2ALIGN(off, (u_offset_t)klen) : 0;
3670 ASSERT(koff <= filesz);
3671 if (koff + klen > filesz)
3672 klen = P2ROUNDUP(filesz - koff, (uint64_t)PAGESIZE);
3673 pp = pvn_write_kluster(vp, pp, &off, &len, koff, klen, flags);
3675 ASSERT3U(btop(len), ==, btopr(len));
3678 * Can't push pages past end-of-file.
3680 if (off >= filesz) {
3681 /* ignore all pages */
3684 } else if (off + len > filesz) {
3685 int npages = btopr(filesz - off);
3688 page_list_break(&pp, &trunc, npages);
3689 /* ignore pages past end of file */
3691 pvn_write_done(trunc, flags);
3695 if (zfs_usergroup_overquota(zfsvfs, B_FALSE, zp->z_phys->zp_uid) ||
3696 zfs_usergroup_overquota(zfsvfs, B_TRUE, zp->z_phys->zp_gid)) {
3701 tx = dmu_tx_create(zfsvfs->z_os);
3702 dmu_tx_hold_write(tx, zp->z_id, off, len);
3703 dmu_tx_hold_bonus(tx, zp->z_id);
3704 err = dmu_tx_assign(tx, TXG_NOWAIT);
3706 if (err == ERESTART) {
3715 if (zp->z_blksz <= PAGESIZE) {
3716 caddr_t va = zfs_map_page(pp, S_READ);
3717 ASSERT3U(len, <=, PAGESIZE);
3718 dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx);
3719 zfs_unmap_page(pp, va);
3721 err = dmu_write_pages(zfsvfs->z_os, zp->z_id, off, len, pp, tx);
3725 zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
3726 zfs_log_write(zfsvfs->z_log, tx, TX_WRITE, zp, off, len, 0);
3731 pvn_write_done(pp, (err ? B_ERROR : 0) | flags);
3741 * Copy the portion of the file indicated from pages into the file.
3742 * The pages are stored in a page list attached to the files vnode.
3744 * IN: vp - vnode of file to push page data to.
3745 * off - position in file to put data.
3746 * len - amount of data to write.
3747 * flags - flags to control the operation.
3748 * cr - credentials of caller.
3749 * ct - caller context.
3751 * RETURN: 0 if success
3752 * error code if failure
3755 * vp - ctime|mtime updated
3759 zfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
3760 caller_context_t *ct)
3762 znode_t *zp = VTOZ(vp);
3763 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3775 * Align this request to the file block size in case we kluster.
3776 * XXX - this can result in pretty aggresive locking, which can
3777 * impact simultanious read/write access. One option might be
3778 * to break up long requests (len == 0) into block-by-block
3779 * operations to get narrower locking.
3781 blksz = zp->z_blksz;
3783 io_off = P2ALIGN_TYPED(off, blksz, u_offset_t);
3786 if (len > 0 && ISP2(blksz))
3787 io_len = P2ROUNDUP_TYPED(len + (off - io_off), blksz, size_t);
3793 * Search the entire vp list for pages >= io_off.
3795 rl = zfs_range_lock(zp, io_off, UINT64_MAX, RL_WRITER);
3796 error = pvn_vplist_dirty(vp, io_off, zfs_putapage, flags, cr);
3799 rl = zfs_range_lock(zp, io_off, io_len, RL_WRITER);
3801 if (off > zp->z_phys->zp_size) {
3802 /* past end of file */
3803 zfs_range_unlock(rl);
3808 len = MIN(io_len, P2ROUNDUP(zp->z_phys->zp_size, PAGESIZE) - io_off);
3810 for (off = io_off; io_off < off + len; io_off += io_len) {
3811 if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) {
3812 pp = page_lookup(vp, io_off,
3813 (flags & (B_INVAL | B_FREE)) ? SE_EXCL : SE_SHARED);
3815 pp = page_lookup_nowait(vp, io_off,
3816 (flags & B_FREE) ? SE_EXCL : SE_SHARED);
3819 if (pp != NULL && pvn_getdirty(pp, flags)) {
3823 * Found a dirty page to push
3825 err = zfs_putapage(vp, pp, &io_off, &io_len, flags, cr);
3833 zfs_range_unlock(rl);
3834 if ((flags & B_ASYNC) == 0)
3835 zil_commit(zfsvfs->z_log, UINT64_MAX, zp->z_id);
3842 zfs_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
3844 znode_t *zp = VTOZ(vp);
3845 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3848 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER);
3849 if (zp->z_dbuf == NULL) {
3851 * The fs has been unmounted, or we did a
3852 * suspend/resume and this file no longer exists.
3854 if (vn_has_cached_data(vp)) {
3855 (void) pvn_vplist_dirty(vp, 0, zfs_null_putapage,
3859 mutex_enter(&zp->z_lock);
3860 vp->v_count = 0; /* count arrives as 1 */
3861 mutex_exit(&zp->z_lock);
3862 rw_exit(&zfsvfs->z_teardown_inactive_lock);
3868 * Attempt to push any data in the page cache. If this fails
3869 * we will get kicked out later in zfs_zinactive().
3871 if (vn_has_cached_data(vp)) {
3872 (void) pvn_vplist_dirty(vp, 0, zfs_putapage, B_INVAL|B_ASYNC,
3876 if (zp->z_atime_dirty && zp->z_unlinked == 0) {
3877 dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
3879 dmu_tx_hold_bonus(tx, zp->z_id);
3880 error = dmu_tx_assign(tx, TXG_WAIT);
3884 dmu_buf_will_dirty(zp->z_dbuf, tx);
3885 mutex_enter(&zp->z_lock);
3886 zp->z_atime_dirty = 0;
3887 mutex_exit(&zp->z_lock);
3893 rw_exit(&zfsvfs->z_teardown_inactive_lock);
3897 * Bounds-check the seek operation.
3899 * IN: vp - vnode seeking within
3900 * ooff - old file offset
3901 * noffp - pointer to new file offset
3902 * ct - caller context
3904 * RETURN: 0 if success
3905 * EINVAL if new offset invalid
3909 zfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp,
3910 caller_context_t *ct)
3912 if (vp->v_type == VDIR)
3914 return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
3918 * Pre-filter the generic locking function to trap attempts to place
3919 * a mandatory lock on a memory mapped file.
3922 zfs_frlock(vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset,
3923 flk_callback_t *flk_cbp, cred_t *cr, caller_context_t *ct)
3925 znode_t *zp = VTOZ(vp);
3926 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3933 * We are following the UFS semantics with respect to mapcnt
3934 * here: If we see that the file is mapped already, then we will
3935 * return an error, but we don't worry about races between this
3936 * function and zfs_map().
3938 if (zp->z_mapcnt > 0 && MANDMODE((mode_t)zp->z_phys->zp_mode)) {
3942 error = fs_frlock(vp, cmd, bfp, flag, offset, flk_cbp, cr, ct);
3948 * If we can't find a page in the cache, we will create a new page
3949 * and fill it with file data. For efficiency, we may try to fill
3950 * multiple pages at once (klustering) to fill up the supplied page
3951 * list. Note that the pages to be filled are held with an exclusive
3952 * lock to prevent access by other threads while they are being filled.
3955 zfs_fillpage(vnode_t *vp, u_offset_t off, struct seg *seg,
3956 caddr_t addr, page_t *pl[], size_t plsz, enum seg_rw rw)
3958 znode_t *zp = VTOZ(vp);
3959 page_t *pp, *cur_pp;
3960 objset_t *os = zp->z_zfsvfs->z_os;
3961 u_offset_t io_off, total;
3965 if (plsz == PAGESIZE || zp->z_blksz <= PAGESIZE) {
3967 * We only have a single page, don't bother klustering
3971 pp = page_create_va(vp, io_off, io_len,
3972 PG_EXCL | PG_WAIT, seg, addr);
3975 * Try to find enough pages to fill the page list
3977 pp = pvn_read_kluster(vp, off, seg, addr, &io_off,
3978 &io_len, off, plsz, 0);
3982 * The page already exists, nothing to do here.
3989 * Fill the pages in the kluster.
3992 for (total = io_off + io_len; io_off < total; io_off += PAGESIZE) {
3995 ASSERT3U(io_off, ==, cur_pp->p_offset);
3996 va = zfs_map_page(cur_pp, S_WRITE);
3997 err = dmu_read(os, zp->z_id, io_off, PAGESIZE, va,
3999 zfs_unmap_page(cur_pp, va);
4001 /* On error, toss the entire kluster */
4002 pvn_read_done(pp, B_ERROR);
4003 /* convert checksum errors into IO errors */
4008 cur_pp = cur_pp->p_next;
4012 * Fill in the page list array from the kluster starting
4013 * from the desired offset `off'.
4014 * NOTE: the page list will always be null terminated.
4016 pvn_plist_init(pp, pl, plsz, off, io_len, rw);
4017 ASSERT(pl == NULL || (*pl)->p_offset == off);
4023 * Return pointers to the pages for the file region [off, off + len]
4024 * in the pl array. If plsz is greater than len, this function may
4025 * also return page pointers from after the specified region
4026 * (i.e. the region [off, off + plsz]). These additional pages are
4027 * only returned if they are already in the cache, or were created as
4028 * part of a klustered read.
4030 * IN: vp - vnode of file to get data from.
4031 * off - position in file to get data from.
4032 * len - amount of data to retrieve.
4033 * plsz - length of provided page list.
4034 * seg - segment to obtain pages for.
4035 * addr - virtual address of fault.
4036 * rw - mode of created pages.
4037 * cr - credentials of caller.
4038 * ct - caller context.
4040 * OUT: protp - protection mode of created pages.
4041 * pl - list of pages created.
4043 * RETURN: 0 if success
4044 * error code if failure
4047 * vp - atime updated
4051 zfs_getpage(vnode_t *vp, offset_t off, size_t len, uint_t *protp,
4052 page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
4053 enum seg_rw rw, cred_t *cr, caller_context_t *ct)
4055 znode_t *zp = VTOZ(vp);
4056 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4060 /* we do our own caching, faultahead is unnecessary */
4063 else if (len > plsz)
4066 len = P2ROUNDUP(len, PAGESIZE);
4067 ASSERT(plsz >= len);
4076 * Loop through the requested range [off, off + len) looking
4077 * for pages. If we don't find a page, we will need to create
4078 * a new page and fill it with data from the file.
4081 if (*pl = page_lookup(vp, off, SE_SHARED))
4083 else if (err = zfs_fillpage(vp, off, seg, addr, pl, plsz, rw))
4086 ASSERT3U((*pl)->p_offset, ==, off);
4090 ASSERT3U(len, >=, PAGESIZE);
4093 ASSERT3U(plsz, >=, PAGESIZE);
4100 * Fill out the page array with any pages already in the cache.
4103 (*pl++ = page_lookup_nowait(vp, off, SE_SHARED))) {
4110 * Release any pages we have previously locked.
4115 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
4125 * Request a memory map for a section of a file. This code interacts
4126 * with common code and the VM system as follows:
4128 * common code calls mmap(), which ends up in smmap_common()
4130 * this calls VOP_MAP(), which takes you into (say) zfs
4132 * zfs_map() calls as_map(), passing segvn_create() as the callback
4134 * segvn_create() creates the new segment and calls VOP_ADDMAP()
4136 * zfs_addmap() updates z_mapcnt
4140 zfs_map(vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp,
4141 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4142 caller_context_t *ct)
4144 znode_t *zp = VTOZ(vp);
4145 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4146 segvn_crargs_t vn_a;
4152 if ((prot & PROT_WRITE) &&
4153 (zp->z_phys->zp_flags & (ZFS_IMMUTABLE | ZFS_READONLY |
4159 if ((prot & (PROT_READ | PROT_EXEC)) &&
4160 (zp->z_phys->zp_flags & ZFS_AV_QUARANTINED)) {
4165 if (vp->v_flag & VNOMAP) {
4170 if (off < 0 || len > MAXOFFSET_T - off) {
4175 if (vp->v_type != VREG) {
4181 * If file is locked, disallow mapping.
4183 if (MANDMODE((mode_t)zp->z_phys->zp_mode) && vn_has_flocks(vp)) {
4189 error = choose_addr(as, addrp, len, off, ADDR_VACALIGN, flags);
4197 vn_a.offset = (u_offset_t)off;
4198 vn_a.type = flags & MAP_TYPE;
4200 vn_a.maxprot = maxprot;
4203 vn_a.flags = flags & ~MAP_TYPE;
4205 vn_a.lgrp_mem_policy_flags = 0;
4207 error = as_map(as, *addrp, len, segvn_create, &vn_a);
4216 zfs_addmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
4217 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4218 caller_context_t *ct)
4220 uint64_t pages = btopr(len);
4222 atomic_add_64(&VTOZ(vp)->z_mapcnt, pages);
4227 * The reason we push dirty pages as part of zfs_delmap() is so that we get a
4228 * more accurate mtime for the associated file. Since we don't have a way of
4229 * detecting when the data was actually modified, we have to resort to
4230 * heuristics. If an explicit msync() is done, then we mark the mtime when the
4231 * last page is pushed. The problem occurs when the msync() call is omitted,
4232 * which by far the most common case:
4240 * putpage() via fsflush
4242 * If we wait until fsflush to come along, we can have a modification time that
4243 * is some arbitrary point in the future. In order to prevent this in the
4244 * common case, we flush pages whenever a (MAP_SHARED, PROT_WRITE) mapping is
4249 zfs_delmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
4250 size_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cr,
4251 caller_context_t *ct)
4253 uint64_t pages = btopr(len);
4255 ASSERT3U(VTOZ(vp)->z_mapcnt, >=, pages);
4256 atomic_add_64(&VTOZ(vp)->z_mapcnt, -pages);
4258 if ((flags & MAP_SHARED) && (prot & PROT_WRITE) &&
4259 vn_has_cached_data(vp))
4260 (void) VOP_PUTPAGE(vp, off, len, B_ASYNC, cr, ct);
4266 * Free or allocate space in a file. Currently, this function only
4267 * supports the `F_FREESP' command. However, this command is somewhat
4268 * misnamed, as its functionality includes the ability to allocate as
4269 * well as free space.
4271 * IN: vp - vnode of file to free data in.
4272 * cmd - action to take (only F_FREESP supported).
4273 * bfp - section of file to free/alloc.
4274 * flag - current file open mode flags.
4275 * offset - current file offset.
4276 * cr - credentials of caller [UNUSED].
4277 * ct - caller context.
4279 * RETURN: 0 if success
4280 * error code if failure
4283 * vp - ctime|mtime updated
4287 zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag,
4288 offset_t offset, cred_t *cr, caller_context_t *ct)
4290 znode_t *zp = VTOZ(vp);
4291 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4298 if (cmd != F_FREESP) {
4303 if (error = convoff(vp, bfp, 0, offset)) {
4308 if (bfp->l_len < 0) {
4314 len = bfp->l_len; /* 0 means from off to end of file */
4316 error = zfs_freesp(zp, off, len, flag, TRUE);
4324 zfs_fid(vnode_t *vp, fid_t *fidp, caller_context_t *ct)
4326 znode_t *zp = VTOZ(vp);
4327 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4329 uint64_t object = zp->z_id;
4335 gen = (uint32_t)zp->z_gen;
4337 size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN;
4338 if (fidp->fid_len < size) {
4339 fidp->fid_len = size;
4344 zfid = (zfid_short_t *)fidp;
4346 zfid->zf_len = size;
4348 for (i = 0; i < sizeof (zfid->zf_object); i++)
4349 zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
4351 /* Must have a non-zero generation number to distinguish from .zfs */
4354 for (i = 0; i < sizeof (zfid->zf_gen); i++)
4355 zfid->zf_gen[i] = (uint8_t)(gen >> (8 * i));
4357 if (size == LONG_FID_LEN) {
4358 uint64_t objsetid = dmu_objset_id(zfsvfs->z_os);
4361 zlfid = (zfid_long_t *)fidp;
4363 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
4364 zlfid->zf_setid[i] = (uint8_t)(objsetid >> (8 * i));
4366 /* XXX - this should be the generation number for the objset */
4367 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
4368 zlfid->zf_setgen[i] = 0;
4376 zfs_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr,
4377 caller_context_t *ct)
4389 case _PC_FILESIZEBITS:
4393 case _PC_XATTR_EXISTS:
4395 zfsvfs = zp->z_zfsvfs;
4399 error = zfs_dirent_lock(&dl, zp, "", &xzp,
4400 ZXATTR | ZEXISTS | ZSHARED, NULL, NULL);
4402 zfs_dirent_unlock(dl);
4403 if (!zfs_dirempty(xzp))
4406 } else if (error == ENOENT) {
4408 * If there aren't extended attributes, it's the
4409 * same as having zero of them.
4416 case _PC_SATTR_ENABLED:
4417 case _PC_SATTR_EXISTS:
4418 *valp = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
4419 (vp->v_type == VREG || vp->v_type == VDIR);
4422 case _PC_ACCESS_FILTERING:
4423 *valp = vfs_has_feature(vp->v_vfsp, VFSFT_ACCESS_FILTER) &&
4427 case _PC_ACL_ENABLED:
4428 *valp = _ACL_ACE_ENABLED;
4431 case _PC_MIN_HOLE_SIZE:
4432 *valp = (ulong_t)SPA_MINBLOCKSIZE;
4436 return (fs_pathconf(vp, cmd, valp, cr, ct));
4442 zfs_getsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
4443 caller_context_t *ct)
4445 znode_t *zp = VTOZ(vp);
4446 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4448 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4452 error = zfs_getacl(zp, vsecp, skipaclchk, cr);
4460 zfs_setsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
4461 caller_context_t *ct)
4463 znode_t *zp = VTOZ(vp);
4464 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4466 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4470 error = zfs_setacl(zp, vsecp, skipaclchk, cr);
4476 * Predeclare these here so that the compiler assumes that
4477 * this is an "old style" function declaration that does
4478 * not include arguments => we won't get type mismatch errors
4479 * in the initializations that follow.
4481 static int zfs_inval();
4482 static int zfs_isdir();
4496 * Directory vnode operations template
4498 vnodeops_t *zfs_dvnodeops;
4499 const fs_operation_def_t zfs_dvnodeops_template[] = {
4500 VOPNAME_OPEN, { .vop_open = zfs_open },
4501 VOPNAME_CLOSE, { .vop_close = zfs_close },
4502 VOPNAME_READ, { .error = zfs_isdir },
4503 VOPNAME_WRITE, { .error = zfs_isdir },
4504 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
4505 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4506 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4507 VOPNAME_ACCESS, { .vop_access = zfs_access },
4508 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
4509 VOPNAME_CREATE, { .vop_create = zfs_create },
4510 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
4511 VOPNAME_LINK, { .vop_link = zfs_link },
4512 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4513 VOPNAME_MKDIR, { .vop_mkdir = zfs_mkdir },
4514 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
4515 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
4516 VOPNAME_SYMLINK, { .vop_symlink = zfs_symlink },
4517 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
4518 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4519 VOPNAME_FID, { .vop_fid = zfs_fid },
4520 VOPNAME_SEEK, { .vop_seek = zfs_seek },
4521 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4522 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4523 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4524 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4529 * Regular file vnode operations template
4531 vnodeops_t *zfs_fvnodeops;
4532 const fs_operation_def_t zfs_fvnodeops_template[] = {
4533 VOPNAME_OPEN, { .vop_open = zfs_open },
4534 VOPNAME_CLOSE, { .vop_close = zfs_close },
4535 VOPNAME_READ, { .vop_read = zfs_read },
4536 VOPNAME_WRITE, { .vop_write = zfs_write },
4537 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
4538 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4539 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4540 VOPNAME_ACCESS, { .vop_access = zfs_access },
4541 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
4542 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4543 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
4544 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4545 VOPNAME_FID, { .vop_fid = zfs_fid },
4546 VOPNAME_SEEK, { .vop_seek = zfs_seek },
4547 VOPNAME_FRLOCK, { .vop_frlock = zfs_frlock },
4548 VOPNAME_SPACE, { .vop_space = zfs_space },
4549 VOPNAME_GETPAGE, { .vop_getpage = zfs_getpage },
4550 VOPNAME_PUTPAGE, { .vop_putpage = zfs_putpage },
4551 VOPNAME_MAP, { .vop_map = zfs_map },
4552 VOPNAME_ADDMAP, { .vop_addmap = zfs_addmap },
4553 VOPNAME_DELMAP, { .vop_delmap = zfs_delmap },
4554 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4555 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4556 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4557 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4562 * Symbolic link vnode operations template
4564 vnodeops_t *zfs_symvnodeops;
4565 const fs_operation_def_t zfs_symvnodeops_template[] = {
4566 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4567 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4568 VOPNAME_ACCESS, { .vop_access = zfs_access },
4569 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4570 VOPNAME_READLINK, { .vop_readlink = zfs_readlink },
4571 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4572 VOPNAME_FID, { .vop_fid = zfs_fid },
4573 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4574 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4579 * special share hidden files vnode operations template
4581 vnodeops_t *zfs_sharevnodeops;
4582 const fs_operation_def_t zfs_sharevnodeops_template[] = {
4583 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4584 VOPNAME_ACCESS, { .vop_access = zfs_access },
4585 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4586 VOPNAME_FID, { .vop_fid = zfs_fid },
4587 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4588 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4589 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4590 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4595 * Extended attribute directory vnode operations template
4596 * This template is identical to the directory vnodes
4597 * operation template except for restricted operations:
4600 * Note that there are other restrictions embedded in:
4601 * zfs_create() - restrict type to VREG
4602 * zfs_link() - no links into/out of attribute space
4603 * zfs_rename() - no moves into/out of attribute space
4605 vnodeops_t *zfs_xdvnodeops;
4606 const fs_operation_def_t zfs_xdvnodeops_template[] = {
4607 VOPNAME_OPEN, { .vop_open = zfs_open },
4608 VOPNAME_CLOSE, { .vop_close = zfs_close },
4609 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
4610 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
4611 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
4612 VOPNAME_ACCESS, { .vop_access = zfs_access },
4613 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
4614 VOPNAME_CREATE, { .vop_create = zfs_create },
4615 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
4616 VOPNAME_LINK, { .vop_link = zfs_link },
4617 VOPNAME_RENAME, { .vop_rename = zfs_rename },
4618 VOPNAME_MKDIR, { .error = zfs_inval },
4619 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
4620 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
4621 VOPNAME_SYMLINK, { .error = zfs_inval },
4622 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
4623 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4624 VOPNAME_FID, { .vop_fid = zfs_fid },
4625 VOPNAME_SEEK, { .vop_seek = zfs_seek },
4626 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
4627 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
4628 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
4629 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
4634 * Error vnode operations template
4636 vnodeops_t *zfs_evnodeops;
4637 const fs_operation_def_t zfs_evnodeops_template[] = {
4638 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
4639 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },