4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25 /* Portions Copyright 2007 Jeremy Teo */
26 /* Portions Copyright 2010 Robert Milkowski */
30 #include <sys/types.h>
31 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/sysmacros.h>
35 #include <sys/resource.h>
37 #include <sys/vfs_opreg.h>
38 #include <sys/vnode.h>
42 #include <sys/taskq.h>
44 #include <sys/vmsystm.h>
45 #include <sys/atomic.h>
47 #include <vm/seg_vn.h>
51 #include <vm/seg_kpm.h>
53 #include <sys/pathname.h>
54 #include <sys/cmn_err.h>
55 #include <sys/errno.h>
56 #include <sys/unistd.h>
57 #include <sys/zfs_dir.h>
58 #include <sys/zfs_acl.h>
59 #include <sys/zfs_ioctl.h>
60 #include <sys/fs/zfs.h>
62 #include <sys/dmu_objset.h>
68 #include <sys/dirent.h>
69 #include <sys/policy.h>
70 #include <sys/sunddi.h>
71 #include <sys/filio.h>
73 #include "fs/fs_subr.h"
74 #include <sys/zfs_ctldir.h>
75 #include <sys/zfs_fuid.h>
76 #include <sys/zfs_sa.h>
77 #include <sys/zfs_vnops.h>
79 #include <sys/zfs_rlock.h>
80 #include <sys/extdirent.h>
81 #include <sys/kidmap.h>
88 * Each vnode op performs some logical unit of work. To do this, the ZPL must
89 * properly lock its in-core state, create a DMU transaction, do the work,
90 * record this work in the intent log (ZIL), commit the DMU transaction,
91 * and wait for the intent log to commit if it is a synchronous operation.
92 * Moreover, the vnode ops must work in both normal and log replay context.
93 * The ordering of events is important to avoid deadlocks and references
94 * to freed memory. The example below illustrates the following Big Rules:
96 * (1) A check must be made in each zfs thread for a mounted file system.
97 * This is done avoiding races using ZFS_ENTER(zfsvfs).
98 * A ZFS_EXIT(zfsvfs) is needed before all returns. Any znodes
99 * must be checked with ZFS_VERIFY_ZP(zp). Both of these macros
100 * can return EIO from the calling function.
102 * (2) VN_RELE() should always be the last thing except for zil_commit()
103 * (if necessary) and ZFS_EXIT(). This is for 3 reasons:
104 * First, if it's the last reference, the vnode/znode
105 * can be freed, so the zp may point to freed memory. Second, the last
106 * reference will call zfs_zinactive(), which may induce a lot of work --
107 * pushing cached pages (which acquires range locks) and syncing out
108 * cached atime changes. Third, zfs_zinactive() may require a new tx,
109 * which could deadlock the system if you were already holding one.
110 * If you must call VN_RELE() within a tx then use VN_RELE_ASYNC().
112 * (3) All range locks must be grabbed before calling dmu_tx_assign(),
113 * as they can span dmu_tx_assign() calls.
115 * (4) Always pass TXG_NOWAIT as the second argument to dmu_tx_assign().
116 * This is critical because we don't want to block while holding locks.
117 * Note, in particular, that if a lock is sometimes acquired before
118 * the tx assigns, and sometimes after (e.g. z_lock), then failing to
119 * use a non-blocking assign can deadlock the system. The scenario:
121 * Thread A has grabbed a lock before calling dmu_tx_assign().
122 * Thread B is in an already-assigned tx, and blocks for this lock.
123 * Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
124 * forever, because the previous txg can't quiesce until B's tx commits.
126 * If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
127 * then drop all locks, call dmu_tx_wait(), and try again.
129 * (5) If the operation succeeded, generate the intent log entry for it
130 * before dropping locks. This ensures that the ordering of events
131 * in the intent log matches the order in which they actually occurred.
132 * During ZIL replay the zfs_log_* functions will update the sequence
133 * number to indicate the zil transaction has replayed.
135 * (6) At the end of each vnode op, the DMU tx must always commit,
136 * regardless of whether there were any errors.
138 * (7) After dropping all locks, invoke zil_commit(zilog, foid)
139 * to ensure that synchronous semantics are provided when necessary.
141 * In general, this is how things should be ordered in each vnode op:
143 * ZFS_ENTER(zfsvfs); // exit if unmounted
145 * zfs_dirent_lock(&dl, ...) // lock directory entry (may VN_HOLD())
146 * rw_enter(...); // grab any other locks you need
147 * tx = dmu_tx_create(...); // get DMU tx
148 * dmu_tx_hold_*(); // hold each object you might modify
149 * error = dmu_tx_assign(tx, TXG_NOWAIT); // try to assign
151 * rw_exit(...); // drop locks
152 * zfs_dirent_unlock(dl); // unlock directory entry
153 * VN_RELE(...); // release held vnodes
154 * if (error == ERESTART) {
159 * dmu_tx_abort(tx); // abort DMU tx
160 * ZFS_EXIT(zfsvfs); // finished in zfs
161 * return (error); // really out of space
163 * error = do_real_work(); // do whatever this VOP does
165 * zfs_log_*(...); // on success, make ZIL entry
166 * dmu_tx_commit(tx); // commit DMU tx -- error or not
167 * rw_exit(...); // drop locks
168 * zfs_dirent_unlock(dl); // unlock directory entry
169 * VN_RELE(...); // release held vnodes
170 * zil_commit(zilog, foid); // synchronous when necessary
171 * ZFS_EXIT(zfsvfs); // finished in zfs
172 * return (error); // done, report error
177 zfs_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
179 znode_t *zp = VTOZ(*vpp);
180 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
185 if ((flag & FWRITE) && (zp->z_pflags & ZFS_APPENDONLY) &&
186 ((flag & FAPPEND) == 0)) {
191 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
192 ZTOV(zp)->v_type == VREG &&
193 !(zp->z_pflags & ZFS_AV_QUARANTINED) && zp->z_size > 0) {
194 if (fs_vscan(*vpp, cr, 0) != 0) {
200 /* Keep a count of the synchronous opens in the znode */
201 if (flag & (FSYNC | FDSYNC))
202 atomic_inc_32(&zp->z_sync_cnt);
210 zfs_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr,
211 caller_context_t *ct)
213 znode_t *zp = VTOZ(vp);
214 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
217 * Clean up any locks held by this process on the vp.
219 cleanlocks(vp, ddi_get_pid(), 0);
220 cleanshares(vp, ddi_get_pid());
225 /* Decrement the synchronous opens in the znode */
226 if ((flag & (FSYNC | FDSYNC)) && (count == 1))
227 atomic_dec_32(&zp->z_sync_cnt);
229 if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
230 ZTOV(zp)->v_type == VREG &&
231 !(zp->z_pflags & ZFS_AV_QUARANTINED) && zp->z_size > 0)
232 VERIFY(fs_vscan(vp, cr, 1) == 0);
239 * Lseek support for finding holes (cmd == _FIO_SEEK_HOLE) and
240 * data (cmd == _FIO_SEEK_DATA). "off" is an in/out parameter.
243 zfs_holey(vnode_t *vp, int cmd, offset_t *off)
245 znode_t *zp = VTOZ(vp);
246 uint64_t noff = (uint64_t)*off; /* new offset */
251 file_sz = zp->z_size;
252 if (noff >= file_sz) {
256 if (cmd == _FIO_SEEK_HOLE)
261 error = dmu_offset_next(zp->z_zfsvfs->z_os, zp->z_id, hole, &noff);
264 if ((error == ESRCH) || (noff > file_sz)) {
266 * Handle the virtual hole at the end of file.
283 zfs_ioctl(vnode_t *vp, int com, intptr_t data, int flag, cred_t *cred,
284 int *rvalp, caller_context_t *ct)
293 return (zfs_sync(vp->v_vfsp, 0, cred));
296 * The following two ioctls are used by bfu. Faking out,
297 * necessary to avoid bfu errors.
305 if (ddi_copyin((void *)data, &off, sizeof (off), flag))
309 zfsvfs = zp->z_zfsvfs;
313 /* offset parameter is in/out */
314 error = zfs_holey(vp, com, &off);
318 if (ddi_copyout(&off, (void *)data, sizeof (off), flag))
325 #if defined(_KERNEL) && defined(HAVE_UIO_RW)
327 * Utility functions to map and unmap a single physical page. These
328 * are used to manage the mappable copies of ZFS file data, and therefore
329 * do not update ref/mod bits.
332 zfs_map_page(page_t *pp, enum seg_rw rw)
335 return (hat_kpm_mapin(pp, 0));
336 ASSERT(rw == S_READ || rw == S_WRITE);
337 return (ppmapin(pp, PROT_READ | ((rw == S_WRITE) ? PROT_WRITE : 0),
342 zfs_unmap_page(page_t *pp, caddr_t addr)
345 hat_kpm_mapout(pp, 0, addr);
350 #endif /* _KERNEL && HAVE_UIO_RW */
353 * When a file is memory mapped, we must keep the IO data synchronized
354 * between the DMU cache and the memory mapped pages. What this means:
356 * On Write: If we find a memory mapped page, we write to *both*
357 * the page and the dmu buffer.
360 update_pages(vnode_t *vp, int64_t start, int len, objset_t *os, uint64_t oid)
364 off = start & PAGEOFFSET;
365 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
367 uint64_t nbytes = MIN(PAGESIZE - off, len);
369 if (pp = page_lookup(vp, start, SE_SHARED)) {
372 va = zfs_map_page(pp, S_WRITE);
373 (void) dmu_read(os, oid, start+off, nbytes, va+off,
375 zfs_unmap_page(pp, va);
384 * When a file is memory mapped, we must keep the IO data synchronized
385 * between the DMU cache and the memory mapped pages. What this means:
387 * On Read: We "read" preferentially from memory mapped pages,
388 * else we default from the dmu buffer.
390 * NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
391 * the file is memory mapped.
394 mappedread(vnode_t *vp, int nbytes, uio_t *uio)
396 znode_t *zp = VTOZ(vp);
397 objset_t *os = zp->z_zfsvfs->z_os;
402 start = uio->uio_loffset;
403 off = start & PAGEOFFSET;
404 for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
406 uint64_t bytes = MIN(PAGESIZE - off, len);
408 if (pp = page_lookup(vp, start, SE_SHARED)) {
411 va = zfs_map_page(pp, S_READ);
412 error = uiomove(va + off, bytes, UIO_READ, uio);
413 zfs_unmap_page(pp, va);
416 error = dmu_read_uio(os, zp->z_id, uio, bytes);
426 offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */
429 * Read bytes from specified file into supplied buffer.
431 * IN: vp - vnode of file to be read from.
432 * uio - structure supplying read location, range info,
434 * ioflag - SYNC flags; used to provide FRSYNC semantics.
435 * cr - credentials of caller.
436 * ct - caller context
438 * OUT: uio - updated offset and range, buffer filled.
440 * RETURN: 0 if success
441 * error code if failure
444 * vp - atime updated if byte count > 0
448 zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
450 znode_t *zp = VTOZ(vp);
451 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
462 if (zp->z_pflags & ZFS_AV_QUARANTINED) {
468 * Validate file offset
470 if (uio->uio_loffset < (offset_t)0) {
476 * Fasttrack empty reads
478 if (uio->uio_resid == 0) {
484 * Check for mandatory locks
486 if (MANDMODE(zp->z_mode)) {
487 if (error = chklock(vp, FREAD,
488 uio->uio_loffset, uio->uio_resid, uio->uio_fmode, ct)) {
495 * If we're in FRSYNC mode, sync out this znode before reading it.
497 if (ioflag & FRSYNC || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
498 zil_commit(zfsvfs->z_log, zp->z_id);
501 * Lock the range against changes.
503 rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER);
506 * If we are reading past end-of-file we can skip
507 * to the end; but we might still need to set atime.
509 if (uio->uio_loffset >= zp->z_size) {
514 ASSERT(uio->uio_loffset < zp->z_size);
515 n = MIN(uio->uio_resid, zp->z_size - uio->uio_loffset);
517 if ((uio->uio_extflg == UIO_XUIO) &&
518 (((xuio_t *)uio)->xu_type == UIOTYPE_ZEROCOPY)) {
520 int blksz = zp->z_blksz;
521 uint64_t offset = uio->uio_loffset;
523 xuio = (xuio_t *)uio;
525 nblk = (P2ROUNDUP(offset + n, blksz) - P2ALIGN(offset,
528 ASSERT(offset + n <= blksz);
531 (void) dmu_xuio_init(xuio, nblk);
533 if (vn_has_cached_data(vp)) {
535 * For simplicity, we always allocate a full buffer
536 * even if we only expect to read a portion of a block.
538 while (--nblk >= 0) {
539 (void) dmu_xuio_add(xuio,
540 dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
547 nbytes = MIN(n, zfs_read_chunk_size -
548 P2PHASE(uio->uio_loffset, zfs_read_chunk_size));
550 if (vn_has_cached_data(vp))
551 error = mappedread(vp, nbytes, uio);
553 error = dmu_read_uio(os, zp->z_id, uio, nbytes);
555 /* convert checksum errors into IO errors */
564 zfs_range_unlock(rl);
566 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
567 zfs_inode_update(zp);
571 EXPORT_SYMBOL(zfs_read);
574 * Write the bytes to a file.
576 * IN: vp - vnode of file to be written to.
577 * uio - structure supplying write location, range info,
579 * ioflag - FAPPEND flag set if in append mode.
580 * cr - credentials of caller.
581 * ct - caller context (NFS/CIFS fem monitor only)
583 * OUT: uio - updated offset and range.
585 * RETURN: 0 if success
586 * error code if failure
589 * vp - ctime|mtime updated if byte count > 0
594 zfs_write(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
596 znode_t *zp = VTOZ(vp);
597 rlim64_t limit = uio->uio_llimit;
598 ssize_t start_resid = uio->uio_resid;
602 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
607 int max_blksz = zfsvfs->z_max_blksz;
613 int iovcnt = uio->uio_iovcnt;
614 iovec_t *iovp = uio->uio_iov;
617 sa_bulk_attr_t bulk[4];
618 uint64_t mtime[2], ctime[2];
621 * Fasttrack empty write
627 if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
633 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
634 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
635 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
637 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
641 * If immutable or not appending then return EPERM
643 if ((zp->z_pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) ||
644 ((zp->z_pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) &&
645 (uio->uio_loffset < zp->z_size))) {
650 zilog = zfsvfs->z_log;
653 * Validate file offset
655 woff = ioflag & FAPPEND ? zp->z_size : uio->uio_loffset;
662 * Check for mandatory locks before calling zfs_range_lock()
663 * in order to prevent a deadlock with locks set via fcntl().
665 if (MANDMODE((mode_t)zp->z_mode) &&
666 (error = chklock(vp, FWRITE, woff, n, uio->uio_fmode, ct)) != 0) {
672 * Pre-fault the pages to ensure slow (eg NFS) pages
674 * Skip this if uio contains loaned arc_buf.
676 if ((uio->uio_extflg == UIO_XUIO) &&
677 (((xuio_t *)uio)->xu_type == UIOTYPE_ZEROCOPY))
678 xuio = (xuio_t *)uio;
680 uio_prefaultpages(MIN(n, max_blksz), uio);
683 * If in append mode, set the io offset pointer to eof.
685 if (ioflag & FAPPEND) {
687 * Obtain an appending range lock to guarantee file append
688 * semantics. We reset the write offset once we have the lock.
690 rl = zfs_range_lock(zp, 0, n, RL_APPEND);
692 if (rl->r_len == UINT64_MAX) {
694 * We overlocked the file because this write will cause
695 * the file block size to increase.
696 * Note that zp_size cannot change with this lock held.
700 uio->uio_loffset = woff;
703 * Note that if the file block size will change as a result of
704 * this write, then this range lock will lock the entire file
705 * so that we can re-write the block safely.
707 rl = zfs_range_lock(zp, woff, n, RL_WRITER);
711 zfs_range_unlock(rl);
716 if ((woff + n) > limit || woff > (limit - n))
719 /* Will this write extend the file length? */
720 write_eof = (woff + n > zp->z_size);
722 end_size = MAX(zp->z_size, woff + n);
725 * Write the file in reasonable size chunks. Each chunk is written
726 * in a separate transaction; this keeps the intent log records small
727 * and allows us to do more fine-grained space accounting.
731 woff = uio->uio_loffset;
733 if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
734 zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
736 dmu_return_arcbuf(abuf);
741 if (xuio && abuf == NULL) {
742 ASSERT(i_iov < iovcnt);
744 abuf = dmu_xuio_arcbuf(xuio, i_iov);
745 dmu_xuio_clear(xuio, i_iov);
746 DTRACE_PROBE3(zfs_cp_write, int, i_iov,
747 iovec_t *, aiov, arc_buf_t *, abuf);
748 ASSERT((aiov->iov_base == abuf->b_data) ||
749 ((char *)aiov->iov_base - (char *)abuf->b_data +
750 aiov->iov_len == arc_buf_size(abuf)));
752 } else if (abuf == NULL && n >= max_blksz &&
753 woff >= zp->z_size &&
754 P2PHASE(woff, max_blksz) == 0 &&
755 zp->z_blksz == max_blksz) {
757 * This write covers a full block. "Borrow" a buffer
758 * from the dmu so that we can fill it before we enter
759 * a transaction. This avoids the possibility of
760 * holding up the transaction if the data copy hangs
761 * up on a pagefault (e.g., from an NFS server mapping).
765 abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
767 ASSERT(abuf != NULL);
768 ASSERT(arc_buf_size(abuf) == max_blksz);
769 if ((error = uiocopy(abuf->b_data, max_blksz,
770 UIO_WRITE, uio, &cbytes))) {
771 dmu_return_arcbuf(abuf);
774 ASSERT(cbytes == max_blksz);
778 * Start a transaction.
780 tx = dmu_tx_create(zfsvfs->z_os);
781 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
782 dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
783 zfs_sa_upgrade_txholds(tx, zp);
784 error = dmu_tx_assign(tx, TXG_NOWAIT);
786 if (error == ERESTART) {
793 dmu_return_arcbuf(abuf);
798 * If zfs_range_lock() over-locked we grow the blocksize
799 * and then reduce the lock range. This will only happen
800 * on the first iteration since zfs_range_reduce() will
801 * shrink down r_len to the appropriate size.
803 if (rl->r_len == UINT64_MAX) {
806 if (zp->z_blksz > max_blksz) {
807 ASSERT(!ISP2(zp->z_blksz));
808 new_blksz = MIN(end_size, SPA_MAXBLOCKSIZE);
810 new_blksz = MIN(end_size, max_blksz);
812 zfs_grow_blocksize(zp, new_blksz, tx);
813 zfs_range_reduce(rl, woff, n);
817 * XXX - should we really limit each write to z_max_blksz?
818 * Perhaps we should use SPA_MAXBLOCKSIZE chunks?
820 nbytes = MIN(n, max_blksz - P2PHASE(woff, max_blksz));
823 tx_bytes = uio->uio_resid;
824 error = dmu_write_uio_dbuf(sa_get_db(zp->z_sa_hdl),
826 tx_bytes -= uio->uio_resid;
829 ASSERT(xuio == NULL || tx_bytes == aiov->iov_len);
831 * If this is not a full block write, but we are
832 * extending the file past EOF and this data starts
833 * block-aligned, use assign_arcbuf(). Otherwise,
834 * write via dmu_write().
836 if (tx_bytes < max_blksz && (!write_eof ||
837 aiov->iov_base != abuf->b_data)) {
839 dmu_write(zfsvfs->z_os, zp->z_id, woff,
840 aiov->iov_len, aiov->iov_base, tx);
841 dmu_return_arcbuf(abuf);
842 xuio_stat_wbuf_copied();
844 ASSERT(xuio || tx_bytes == max_blksz);
845 dmu_assign_arcbuf(sa_get_db(zp->z_sa_hdl),
848 ASSERT(tx_bytes <= uio->uio_resid);
849 uioskip(uio, tx_bytes);
851 if (tx_bytes && vn_has_cached_data(vp)) {
852 update_pages(vp, woff,
853 tx_bytes, zfsvfs->z_os, zp->z_id);
857 * If we made no progress, we're done. If we made even
858 * partial progress, update the znode and ZIL accordingly.
861 (void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zfsvfs),
862 (void *)&zp->z_size, sizeof (uint64_t), tx);
869 * Clear Set-UID/Set-GID bits on successful write if not
870 * privileged and at least one of the excute bits is set.
872 * It would be nice to to this after all writes have
873 * been done, but that would still expose the ISUID/ISGID
874 * to another app after the partial write is committed.
876 * Note: we don't call zfs_fuid_map_id() here because
877 * user 0 is not an ephemeral uid.
879 mutex_enter(&zp->z_acl_lock);
880 if ((zp->z_mode & (S_IXUSR | (S_IXUSR >> 3) |
881 (S_IXUSR >> 6))) != 0 &&
882 (zp->z_mode & (S_ISUID | S_ISGID)) != 0 &&
883 secpolicy_vnode_setid_retain(cr,
884 (zp->z_mode & S_ISUID) != 0 && zp->z_uid == 0) != 0) {
886 zp->z_mode &= ~(S_ISUID | S_ISGID);
887 newmode = zp->z_mode;
888 (void) sa_update(zp->z_sa_hdl, SA_ZPL_MODE(zfsvfs),
889 (void *)&newmode, sizeof (uint64_t), tx);
891 mutex_exit(&zp->z_acl_lock);
893 zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
897 * Update the file size (zp_size) if it has changed;
898 * account for possible concurrent updates.
900 while ((end_size = zp->z_size) < uio->uio_loffset) {
901 (void) atomic_cas_64(&zp->z_size, end_size,
906 * If we are replaying and eof is non zero then force
907 * the file size to the specified eof. Note, there's no
908 * concurrency during replay.
910 if (zfsvfs->z_replay && zfsvfs->z_replay_eof != 0)
911 zp->z_size = zfsvfs->z_replay_eof;
913 error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
915 zfs_log_write(zilog, tx, TX_WRITE, zp, woff, tx_bytes, ioflag);
920 ASSERT(tx_bytes == nbytes);
924 uio_prefaultpages(MIN(n, max_blksz), uio);
927 zfs_range_unlock(rl);
930 * If we're in replay mode, or we made no progress, return error.
931 * Otherwise, it's at least a partial write, so it's successful.
933 if (zfsvfs->z_replay || uio->uio_resid == start_resid) {
938 if (ioflag & (FSYNC | FDSYNC) ||
939 zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
940 zil_commit(zilog, zp->z_id);
942 zfs_inode_update(zp);
946 EXPORT_SYMBOL(zfs_write);
949 zfs_get_done(zgd_t *zgd, int error)
951 znode_t *zp = zgd->zgd_private;
952 objset_t *os = zp->z_zfsvfs->z_os;
955 dmu_buf_rele(zgd->zgd_db, zgd);
957 zfs_range_unlock(zgd->zgd_rl);
960 * Release the vnode asynchronously as we currently have the
961 * txg stopped from syncing.
963 VN_RELE_ASYNC(ZTOV(zp), dsl_pool_vnrele_taskq(dmu_objset_pool(os)));
965 if (error == 0 && zgd->zgd_bp)
966 zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
968 kmem_free(zgd, sizeof (zgd_t));
972 static int zil_fault_io = 0;
976 * Get data to generate a TX_WRITE intent log record.
979 zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
981 zfsvfs_t *zfsvfs = arg;
982 objset_t *os = zfsvfs->z_os;
984 uint64_t object = lr->lr_foid;
985 uint64_t offset = lr->lr_offset;
986 uint64_t size = lr->lr_length;
987 blkptr_t *bp = &lr->lr_blkptr;
996 * Nothing to do if the file has been removed
998 if (zfs_zget(zfsvfs, object, &zp) != 0)
1000 if (zp->z_unlinked) {
1002 * Release the vnode asynchronously as we currently have the
1003 * txg stopped from syncing.
1005 VN_RELE_ASYNC(ZTOV(zp),
1006 dsl_pool_vnrele_taskq(dmu_objset_pool(os)));
1010 zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
1011 zgd->zgd_zilog = zfsvfs->z_log;
1012 zgd->zgd_private = zp;
1015 * Write records come in two flavors: immediate and indirect.
1016 * For small writes it's cheaper to store the data with the
1017 * log record (immediate); for large writes it's cheaper to
1018 * sync the data and get a pointer to it (indirect) so that
1019 * we don't have to write the data twice.
1021 if (buf != NULL) { /* immediate write */
1022 zgd->zgd_rl = zfs_range_lock(zp, offset, size, RL_READER);
1023 /* test for truncation needs to be done while range locked */
1024 if (offset >= zp->z_size) {
1027 error = dmu_read(os, object, offset, size, buf,
1028 DMU_READ_NO_PREFETCH);
1030 ASSERT(error == 0 || error == ENOENT);
1031 } else { /* indirect write */
1033 * Have to lock the whole block to ensure when it's
1034 * written out and it's checksum is being calculated
1035 * that no one can change the data. We need to re-check
1036 * blocksize after we get the lock in case it's changed!
1041 blkoff = ISP2(size) ? P2PHASE(offset, size) : offset;
1043 zgd->zgd_rl = zfs_range_lock(zp, offset, size,
1045 if (zp->z_blksz == size)
1048 zfs_range_unlock(zgd->zgd_rl);
1050 /* test for truncation needs to be done while range locked */
1051 if (lr->lr_offset >= zp->z_size)
1060 error = dmu_buf_hold(os, object, offset, zgd, &db,
1061 DMU_READ_NO_PREFETCH);
1067 ASSERT(db->db_offset == offset);
1068 ASSERT(db->db_size == size);
1070 error = dmu_sync(zio, lr->lr_common.lrc_txg,
1072 ASSERT(error || lr->lr_length <= zp->z_blksz);
1075 * On success, we need to wait for the write I/O
1076 * initiated by dmu_sync() to complete before we can
1077 * release this dbuf. We will finish everything up
1078 * in the zfs_get_done() callback.
1083 if (error == EALREADY) {
1084 lr->lr_common.lrc_txtype = TX_WRITE2;
1090 zfs_get_done(zgd, error);
1097 zfs_access(vnode_t *vp, int mode, int flag, cred_t *cr,
1098 caller_context_t *ct)
1100 znode_t *zp = VTOZ(vp);
1101 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1107 if (flag & V_ACE_MASK)
1108 error = zfs_zaccess(zp, mode, flag, B_FALSE, cr);
1110 error = zfs_zaccess_rwx(zp, mode, flag, cr);
1117 * If vnode is for a device return a specfs vnode instead.
1120 specvp_check(vnode_t **vpp, cred_t *cr)
1124 if (IS_DEVVP(*vpp)) {
1127 svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
1138 * Lookup an entry in a directory, or an extended attribute directory.
1139 * If it exists, return a held vnode reference for it.
1141 * IN: dvp - vnode of directory to search.
1142 * nm - name of entry to lookup.
1143 * pnp - full pathname to lookup [UNUSED].
1144 * flags - LOOKUP_XATTR set if looking for an attribute.
1145 * rdir - root directory vnode [UNUSED].
1146 * cr - credentials of caller.
1147 * ct - caller context
1148 * direntflags - directory lookup flags
1149 * realpnp - returned pathname.
1151 * OUT: vpp - vnode of located entry, NULL if not found.
1153 * RETURN: 0 if success
1154 * error code if failure
1161 zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp,
1162 int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct,
1163 int *direntflags, pathname_t *realpnp)
1165 znode_t *zdp = VTOZ(dvp);
1166 zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
1170 if (!(flags & (LOOKUP_XATTR | FIGNORECASE))) {
1172 if (dvp->v_type != VDIR) {
1174 } else if (zdp->z_sa_hdl == NULL) {
1178 if (nm[0] == 0 || (nm[0] == '.' && nm[1] == '\0')) {
1179 error = zfs_fastaccesschk_execute(zdp, cr);
1187 vnode_t *tvp = dnlc_lookup(dvp, nm);
1190 error = zfs_fastaccesschk_execute(zdp, cr);
1195 if (tvp == DNLC_NO_VNODE) {
1200 return (specvp_check(vpp, cr));
1206 DTRACE_PROBE2(zfs__fastpath__lookup__miss, vnode_t *, dvp, char *, nm);
1213 if (flags & LOOKUP_XATTR) {
1215 * If the xattr property is off, refuse the lookup request.
1217 if (!(zfsvfs->z_vfs->vfs_flag & VFS_XATTR)) {
1223 * We don't allow recursive attributes..
1224 * Maybe someday we will.
1226 if (zdp->z_pflags & ZFS_XATTR) {
1231 if ((error = zfs_get_xattrdir(VTOZ(dvp), vpp, cr, flags))) {
1237 * Do we have permission to get into attribute directory?
1240 if ((error = zfs_zaccess(VTOZ(*vpp), ACE_EXECUTE, 0,
1250 if (dvp->v_type != VDIR) {
1256 * Check accessibility of directory.
1259 if ((error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr))) {
1264 if (zfsvfs->z_utf8 && u8_validate(nm, strlen(nm),
1265 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1270 error = zfs_dirlook(zdp, nm, vpp, flags, direntflags, realpnp);
1273 zfs_inode_update(VTOZ(*vpp));
1275 error = specvp_check(vpp, cr);
1281 EXPORT_SYMBOL(zfs_lookup);
1284 * Attempt to create a new entry in a directory. If the entry
1285 * already exists, truncate the file if permissible, else return
1286 * an error. Return the vp of the created or trunc'd file.
1288 * IN: dvp - vnode of directory to put new file entry in.
1289 * name - name of new file entry.
1290 * vap - attributes of new file.
1291 * excl - flag indicating exclusive or non-exclusive mode.
1292 * mode - mode to open file with.
1293 * cr - credentials of caller.
1294 * flag - large file flag [UNUSED].
1295 * ct - caller context
1296 * vsecp - ACL to be set
1298 * OUT: vpp - vnode of created or trunc'd entry.
1300 * RETURN: 0 if success
1301 * error code if failure
1304 * dvp - ctime|mtime updated if new entry created
1305 * vp - ctime|mtime always, atime if new
1310 zfs_create(vnode_t *dvp, char *name, vattr_t *vap, int excl,
1311 int mode, vnode_t **vpp, cred_t *cr, int flag, caller_context_t *ct,
1314 znode_t *zp, *dzp = VTOZ(dvp);
1315 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1324 zfs_acl_ids_t acl_ids;
1325 boolean_t fuid_dirtied;
1326 boolean_t have_acl = B_FALSE;
1329 * If we have an ephemeral id, ACL, or XVATTR then
1330 * make sure file system is at proper version
1334 ksid = crgetsid(cr, KSID_OWNER);
1336 uid = ksid_getid(ksid);
1340 if (zfsvfs->z_use_fuids == B_FALSE &&
1341 (vsecp || (vap->va_mask & AT_XVATTR) ||
1342 IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
1348 zilog = zfsvfs->z_log;
1350 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
1351 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1356 if (vap->va_mask & AT_XVATTR) {
1357 if ((error = secpolicy_xvattr((xvattr_t *)vap,
1358 crgetuid(cr), cr, vap->va_type)) != 0) {
1366 if ((vap->va_mode & VSVTX) && secpolicy_vnode_stky_modify(cr))
1367 vap->va_mode &= ~VSVTX;
1369 if (*name == '\0') {
1371 * Null component name refers to the directory itself.
1378 /* possible VN_HOLD(zp) */
1381 if (flag & FIGNORECASE)
1384 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1388 zfs_acl_ids_free(&acl_ids);
1389 if (strcmp(name, "..") == 0)
1400 * Create a new file object and update the directory
1403 if ((error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr))) {
1405 zfs_acl_ids_free(&acl_ids);
1410 * We only support the creation of regular files in
1411 * extended attribute directories.
1414 if ((dzp->z_pflags & ZFS_XATTR) &&
1415 (vap->va_type != VREG)) {
1417 zfs_acl_ids_free(&acl_ids);
1422 if (!have_acl && (error = zfs_acl_ids_create(dzp, 0, vap,
1423 cr, vsecp, &acl_ids)) != 0)
1427 if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
1428 zfs_acl_ids_free(&acl_ids);
1433 tx = dmu_tx_create(os);
1435 dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
1436 ZFS_SA_BASE_ATTR_SIZE);
1438 fuid_dirtied = zfsvfs->z_fuid_dirty;
1440 zfs_fuid_txhold(zfsvfs, tx);
1441 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
1442 dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
1443 if (!zfsvfs->z_use_sa &&
1444 acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
1445 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
1446 0, acl_ids.z_aclp->z_acl_bytes);
1448 error = dmu_tx_assign(tx, TXG_NOWAIT);
1450 zfs_dirent_unlock(dl);
1451 if (error == ERESTART) {
1456 zfs_acl_ids_free(&acl_ids);
1461 zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
1464 zfs_fuid_sync(zfsvfs, tx);
1466 (void) zfs_link_create(dl, zp, tx, ZNEW);
1467 txtype = zfs_log_create_txtype(Z_FILE, vsecp, vap);
1468 if (flag & FIGNORECASE)
1470 zfs_log_create(zilog, tx, txtype, dzp, zp, name,
1471 vsecp, acl_ids.z_fuidp, vap);
1472 zfs_acl_ids_free(&acl_ids);
1475 int aflags = (flag & FAPPEND) ? V_APPEND : 0;
1478 zfs_acl_ids_free(&acl_ids);
1482 * A directory entry already exists for this name.
1485 * Can't truncate an existing file if in exclusive mode.
1492 * Can't open a directory for writing.
1494 if ((ZTOV(zp)->v_type == VDIR) && (mode & S_IWRITE)) {
1499 * Verify requested access to file.
1501 if (mode && (error = zfs_zaccess_rwx(zp, mode, aflags, cr))) {
1505 mutex_enter(&dzp->z_lock);
1507 mutex_exit(&dzp->z_lock);
1510 * Truncate regular files if requested.
1512 if ((ZTOV(zp)->v_type == VREG) &&
1513 (vap->va_mask & AT_SIZE) && (vap->va_size == 0)) {
1514 /* we can't hold any locks when calling zfs_freesp() */
1515 zfs_dirent_unlock(dl);
1517 error = zfs_freesp(zp, 0, 0, mode, TRUE);
1519 vnevent_create(ZTOV(zp), ct);
1526 zfs_dirent_unlock(dl);
1532 zfs_inode_update(dzp);
1533 zfs_inode_update(zp);
1535 error = specvp_check(vpp, cr);
1538 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1539 zil_commit(zilog, 0);
1544 EXPORT_SYMBOL(zfs_create);
1547 * Remove an entry from a directory.
1549 * IN: dvp - vnode of directory to remove entry from.
1550 * name - name of entry to remove.
1551 * cr - credentials of caller.
1552 * ct - caller context
1553 * flags - case flags
1555 * RETURN: 0 if success
1556 * error code if failure
1560 * vp - ctime (if nlink > 0)
1563 uint64_t null_xattr = 0;
1567 zfs_remove(vnode_t *dvp, char *name, cred_t *cr, caller_context_t *ct,
1570 znode_t *zp, *dzp = VTOZ(dvp);
1573 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1575 uint64_t acl_obj, xattr_obj;
1576 uint64_t xattr_obj_unlinked = 0;
1580 boolean_t may_delete_now, delete_now = FALSE;
1581 boolean_t unlinked, toobig = FALSE;
1583 pathname_t *realnmp = NULL;
1590 zilog = zfsvfs->z_log;
1592 if (flags & FIGNORECASE) {
1602 * Attempt to lock directory; fail if entry doesn't exist.
1604 if ((error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
1614 if ((error = zfs_zaccess_delete(dzp, zp, cr))) {
1619 * Need to use rmdir for removing directories.
1621 if (vp->v_type == VDIR) {
1626 vnevent_remove(vp, dvp, name, ct);
1629 dnlc_remove(dvp, realnmp->pn_buf);
1631 dnlc_remove(dvp, name);
1633 mutex_enter(&vp->v_lock);
1634 may_delete_now = ((vp->v_count == 1) && (!vn_has_cached_data(vp)));
1635 mutex_exit(&vp->v_lock);
1638 * We may delete the znode now, or we may put it in the unlinked set;
1639 * it depends on whether we're the last link, and on whether there are
1640 * other holds on the vnode. So we dmu_tx_hold() the right things to
1641 * allow for either case.
1644 tx = dmu_tx_create(zfsvfs->z_os);
1645 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1646 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1647 zfs_sa_upgrade_txholds(tx, zp);
1648 zfs_sa_upgrade_txholds(tx, dzp);
1649 if (may_delete_now) {
1651 zp->z_size > zp->z_blksz * DMU_MAX_DELETEBLKCNT;
1652 /* if the file is too big, only hold_free a token amount */
1653 dmu_tx_hold_free(tx, zp->z_id, 0,
1654 (toobig ? DMU_MAX_ACCESS : DMU_OBJECT_END));
1657 /* are there any extended attributes? */
1658 error = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
1659 &xattr_obj, sizeof (xattr_obj));
1660 if (error == 0 && xattr_obj) {
1661 error = zfs_zget(zfsvfs, xattr_obj, &xzp);
1662 ASSERT3U(error, ==, 0);
1663 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
1664 dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE);
1667 mutex_enter(&zp->z_lock);
1668 if ((acl_obj = zfs_external_acl(zp)) != 0 && may_delete_now)
1669 dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END);
1670 mutex_exit(&zp->z_lock);
1672 /* charge as an update -- would be nice not to charge at all */
1673 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1675 error = dmu_tx_assign(tx, TXG_NOWAIT);
1677 zfs_dirent_unlock(dl);
1681 if (error == ERESTART) {
1694 * Remove the directory entry.
1696 error = zfs_link_destroy(dl, zp, tx, zflg, &unlinked);
1706 * Hold z_lock so that we can make sure that the ACL obj
1707 * hasn't changed. Could have been deleted due to
1710 mutex_enter(&zp->z_lock);
1711 mutex_enter(&vp->v_lock);
1712 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
1713 &xattr_obj_unlinked, sizeof (xattr_obj_unlinked));
1714 delete_now = may_delete_now && !toobig &&
1715 vp->v_count == 1 && !vn_has_cached_data(vp) &&
1716 xattr_obj == xattr_obj_unlinked && zfs_external_acl(zp) ==
1718 mutex_exit(&vp->v_lock);
1722 if (xattr_obj_unlinked) {
1723 ASSERT3U(xzp->z_links, ==, 2);
1724 mutex_enter(&xzp->z_lock);
1725 xzp->z_unlinked = 1;
1727 error = sa_update(xzp->z_sa_hdl, SA_ZPL_LINKS(zfsvfs),
1728 &xzp->z_links, sizeof (xzp->z_links), tx);
1729 ASSERT3U(error, ==, 0);
1730 mutex_exit(&xzp->z_lock);
1731 zfs_unlinked_add(xzp, tx);
1734 error = sa_remove(zp->z_sa_hdl,
1735 SA_ZPL_XATTR(zfsvfs), tx);
1737 error = sa_update(zp->z_sa_hdl,
1738 SA_ZPL_XATTR(zfsvfs), &null_xattr,
1739 sizeof (uint64_t), tx);
1740 ASSERT3U(error, ==, 0);
1742 mutex_enter(&vp->v_lock);
1744 ASSERT3U(vp->v_count, ==, 0);
1745 mutex_exit(&vp->v_lock);
1746 mutex_exit(&zp->z_lock);
1747 zfs_znode_delete(zp, tx);
1748 } else if (unlinked) {
1749 mutex_exit(&zp->z_lock);
1750 zfs_unlinked_add(zp, tx);
1754 if (flags & FIGNORECASE)
1756 zfs_log_remove(zilog, tx, txtype, dzp, name, obj);
1763 zfs_dirent_unlock(dl);
1764 zfs_inode_update(dzp);
1765 zfs_inode_update(zp);
1767 zfs_inode_update(xzp);
1774 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1775 zil_commit(zilog, 0);
1780 EXPORT_SYMBOL(zfs_remove);
1783 * Create a new directory and insert it into dvp using the name
1784 * provided. Return a pointer to the inserted directory.
1786 * IN: dvp - vnode of directory to add subdir to.
1787 * dirname - name of new directory.
1788 * vap - attributes of new directory.
1789 * cr - credentials of caller.
1790 * ct - caller context
1791 * vsecp - ACL to be set
1793 * OUT: vpp - vnode of created directory.
1795 * RETURN: 0 if success
1796 * error code if failure
1799 * dvp - ctime|mtime updated
1800 * vp - ctime|mtime|atime updated
1804 zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr,
1805 caller_context_t *ct, int flags, vsecattr_t *vsecp)
1807 znode_t *zp, *dzp = VTOZ(dvp);
1808 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1817 gid_t gid = crgetgid(cr);
1818 zfs_acl_ids_t acl_ids;
1819 boolean_t fuid_dirtied;
1821 ASSERT(vap->va_type == VDIR);
1824 * If we have an ephemeral id, ACL, or XVATTR then
1825 * make sure file system is at proper version
1828 ksid = crgetsid(cr, KSID_OWNER);
1830 uid = ksid_getid(ksid);
1833 if (zfsvfs->z_use_fuids == B_FALSE &&
1834 (vsecp || (vap->va_mask & AT_XVATTR) ||
1835 IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
1840 zilog = zfsvfs->z_log;
1842 if (dzp->z_pflags & ZFS_XATTR) {
1847 if (zfsvfs->z_utf8 && u8_validate(dirname,
1848 strlen(dirname), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
1852 if (flags & FIGNORECASE)
1855 if (vap->va_mask & AT_XVATTR) {
1856 if ((error = secpolicy_xvattr((xvattr_t *)vap,
1857 crgetuid(cr), cr, vap->va_type)) != 0) {
1863 if ((error = zfs_acl_ids_create(dzp, 0, vap, cr,
1864 vsecp, &acl_ids)) != 0) {
1869 * First make sure the new directory doesn't exist.
1871 * Existence is checked first to make sure we don't return
1872 * EACCES instead of EEXIST which can cause some applications
1878 if ((error = zfs_dirent_lock(&dl, dzp, dirname, &zp, zf,
1880 zfs_acl_ids_free(&acl_ids);
1885 if ((error = zfs_zaccess(dzp, ACE_ADD_SUBDIRECTORY, 0, B_FALSE, cr))) {
1886 zfs_acl_ids_free(&acl_ids);
1887 zfs_dirent_unlock(dl);
1892 if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
1893 zfs_acl_ids_free(&acl_ids);
1894 zfs_dirent_unlock(dl);
1900 * Add a new entry to the directory.
1902 tx = dmu_tx_create(zfsvfs->z_os);
1903 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, dirname);
1904 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
1905 fuid_dirtied = zfsvfs->z_fuid_dirty;
1907 zfs_fuid_txhold(zfsvfs, tx);
1908 if (!zfsvfs->z_use_sa && acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
1909 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
1910 acl_ids.z_aclp->z_acl_bytes);
1913 dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
1914 ZFS_SA_BASE_ATTR_SIZE);
1916 error = dmu_tx_assign(tx, TXG_NOWAIT);
1918 zfs_dirent_unlock(dl);
1919 if (error == ERESTART) {
1924 zfs_acl_ids_free(&acl_ids);
1933 zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
1936 zfs_fuid_sync(zfsvfs, tx);
1939 * Now put new name in parent dir.
1941 (void) zfs_link_create(dl, zp, tx, ZNEW);
1945 txtype = zfs_log_create_txtype(Z_DIR, vsecp, vap);
1946 if (flags & FIGNORECASE)
1948 zfs_log_create(zilog, tx, txtype, dzp, zp, dirname, vsecp,
1949 acl_ids.z_fuidp, vap);
1951 zfs_acl_ids_free(&acl_ids);
1955 zfs_dirent_unlock(dl);
1957 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1958 zil_commit(zilog, 0);
1960 zfs_inode_update(dzp);
1961 zfs_inode_update(zp);
1965 EXPORT_SYMBOL(zfs_mkdir);
1968 * Remove a directory subdir entry. If the current working
1969 * directory is the same as the subdir to be removed, the
1972 * IN: dvp - vnode of directory to remove from.
1973 * name - name of directory to be removed.
1974 * cwd - vnode of current working directory.
1975 * cr - credentials of caller.
1976 * ct - caller context
1977 * flags - case flags
1979 * RETURN: 0 if success
1980 * error code if failure
1983 * dvp - ctime|mtime updated
1987 zfs_rmdir(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr,
1988 caller_context_t *ct, int flags)
1990 znode_t *dzp = VTOZ(dvp);
1993 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
2002 zilog = zfsvfs->z_log;
2004 if (flags & FIGNORECASE)
2010 * Attempt to lock directory; fail if entry doesn't exist.
2012 if ((error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
2020 if ((error = zfs_zaccess_delete(dzp, zp, cr))) {
2024 if (vp->v_type != VDIR) {
2034 vnevent_rmdir(vp, dvp, name, ct);
2037 * Grab a lock on the directory to make sure that noone is
2038 * trying to add (or lookup) entries while we are removing it.
2040 rw_enter(&zp->z_name_lock, RW_WRITER);
2043 * Grab a lock on the parent pointer to make sure we play well
2044 * with the treewalk and directory rename code.
2046 rw_enter(&zp->z_parent_lock, RW_WRITER);
2048 tx = dmu_tx_create(zfsvfs->z_os);
2049 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
2050 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
2051 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
2052 zfs_sa_upgrade_txholds(tx, zp);
2053 zfs_sa_upgrade_txholds(tx, dzp);
2054 error = dmu_tx_assign(tx, TXG_NOWAIT);
2056 rw_exit(&zp->z_parent_lock);
2057 rw_exit(&zp->z_name_lock);
2058 zfs_dirent_unlock(dl);
2060 if (error == ERESTART) {
2070 error = zfs_link_destroy(dl, zp, tx, zflg, NULL);
2073 uint64_t txtype = TX_RMDIR;
2074 if (flags & FIGNORECASE)
2076 zfs_log_remove(zilog, tx, txtype, dzp, name, ZFS_NO_OBJECT);
2081 rw_exit(&zp->z_parent_lock);
2082 rw_exit(&zp->z_name_lock);
2084 zfs_dirent_unlock(dl);
2088 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2089 zil_commit(zilog, 0);
2091 zfs_inode_update(dzp);
2092 zfs_inode_update(zp);
2096 EXPORT_SYMBOL(zfs_rmdir);
2099 * Read as many directory entries as will fit into the provided
2100 * buffer from the given directory cursor position (specified in
2101 * the uio structure.
2103 * IN: vp - vnode of directory to read.
2104 * uio - structure supplying read location, range info,
2105 * and return buffer.
2106 * cr - credentials of caller.
2107 * ct - caller context
2108 * flags - case flags
2110 * OUT: uio - updated offset and range, buffer filled.
2111 * eofp - set to true if end-of-file detected.
2113 * RETURN: 0 if success
2114 * error code if failure
2117 * vp - atime updated
2119 * Note that the low 4 bits of the cookie returned by zap is always zero.
2120 * This allows us to use the low range for "special" directory entries:
2121 * We use 0 for '.', and 1 for '..'. If this is the root of the filesystem,
2122 * we use the offset 2 for the '.zfs' directory.
2126 zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp,
2127 caller_context_t *ct, int flags)
2129 znode_t *zp = VTOZ(vp);
2133 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2138 zap_attribute_t zap;
2139 uint_t bytes_wanted;
2140 uint64_t offset; /* must be unsigned; checks for < 1 */
2146 boolean_t check_sysattrs;
2151 if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs),
2152 &parent, sizeof (parent))) != 0) {
2158 * If we are not given an eof variable,
2165 * Check for valid iov_len.
2167 if (uio->uio_iov->iov_len <= 0) {
2173 * Quit if directory has been removed (posix)
2175 if ((*eofp = zp->z_unlinked) != 0) {
2182 offset = uio->uio_loffset;
2183 prefetch = zp->z_zn_prefetch;
2186 * Initialize the iterator cursor.
2190 * Start iteration from the beginning of the directory.
2192 zap_cursor_init(&zc, os, zp->z_id);
2195 * The offset is a serialized cursor.
2197 zap_cursor_init_serialized(&zc, os, zp->z_id, offset);
2201 * Get space to change directory entries into fs independent format.
2203 iovp = uio->uio_iov;
2204 bytes_wanted = iovp->iov_len;
2205 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) {
2206 bufsize = bytes_wanted;
2207 outbuf = kmem_alloc(bufsize, KM_SLEEP);
2208 odp = (struct dirent64 *)outbuf;
2210 bufsize = bytes_wanted;
2211 odp = (struct dirent64 *)iovp->iov_base;
2213 eodp = (struct edirent *)odp;
2216 * If this VFS supports the system attribute view interface; and
2217 * we're looking at an extended attribute directory; and we care
2218 * about normalization conflicts on this vfs; then we must check
2219 * for normalization conflicts with the sysattr name space.
2221 check_sysattrs = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
2222 (vp->v_flag & V_XATTRDIR) && zfsvfs->z_norm &&
2223 (flags & V_RDDIR_ENTFLAGS);
2226 * Transform to file-system independent format
2229 while (outcount < bytes_wanted) {
2232 off64_t *next = NULL;
2235 * Special case `.', `..', and `.zfs'.
2238 (void) strcpy(zap.za_name, ".");
2239 zap.za_normalization_conflict = 0;
2241 } else if (offset == 1) {
2242 (void) strcpy(zap.za_name, "..");
2243 zap.za_normalization_conflict = 0;
2245 } else if (offset == 2 && zfs_show_ctldir(zp)) {
2246 (void) strcpy(zap.za_name, ZFS_CTLDIR_NAME);
2247 zap.za_normalization_conflict = 0;
2248 objnum = ZFSCTL_INO_ROOT;
2253 if (error = zap_cursor_retrieve(&zc, &zap)) {
2254 if ((*eofp = (error == ENOENT)) != 0)
2260 if (zap.za_integer_length != 8 ||
2261 zap.za_num_integers != 1) {
2262 cmn_err(CE_WARN, "zap_readdir: bad directory "
2263 "entry, obj = %lld, offset = %lld\n",
2264 (u_longlong_t)zp->z_id,
2265 (u_longlong_t)offset);
2270 objnum = ZFS_DIRENT_OBJ(zap.za_first_integer);
2272 * MacOS X can extract the object type here such as:
2273 * uint8_t type = ZFS_DIRENT_TYPE(zap.za_first_integer);
2276 if (check_sysattrs && !zap.za_normalization_conflict) {
2277 zap.za_normalization_conflict =
2278 xattr_sysattr_casechk(zap.za_name);
2282 if (flags & V_RDDIR_ACCFILTER) {
2284 * If we have no access at all, don't include
2285 * this entry in the returned information
2288 if (zfs_zget(zp->z_zfsvfs, objnum, &ezp) != 0)
2290 if (!zfs_has_access(ezp, cr)) {
2297 if (flags & V_RDDIR_ENTFLAGS)
2298 reclen = EDIRENT_RECLEN(strlen(zap.za_name));
2300 reclen = DIRENT64_RECLEN(strlen(zap.za_name));
2303 * Will this entry fit in the buffer?
2305 if (outcount + reclen > bufsize) {
2307 * Did we manage to fit anything in the buffer?
2315 if (flags & V_RDDIR_ENTFLAGS) {
2317 * Add extended flag entry:
2319 eodp->ed_ino = objnum;
2320 eodp->ed_reclen = reclen;
2321 /* NOTE: ed_off is the offset for the *next* entry */
2322 next = &(eodp->ed_off);
2323 eodp->ed_eflags = zap.za_normalization_conflict ?
2324 ED_CASE_CONFLICT : 0;
2325 (void) strncpy(eodp->ed_name, zap.za_name,
2326 EDIRENT_NAMELEN(reclen));
2327 eodp = (edirent_t *)((intptr_t)eodp + reclen);
2332 odp->d_ino = objnum;
2333 odp->d_reclen = reclen;
2334 /* NOTE: d_off is the offset for the *next* entry */
2335 next = &(odp->d_off);
2336 (void) strncpy(odp->d_name, zap.za_name,
2337 DIRENT64_NAMELEN(reclen));
2338 odp = (dirent64_t *)((intptr_t)odp + reclen);
2342 ASSERT(outcount <= bufsize);
2344 /* Prefetch znode */
2346 dmu_prefetch(os, objnum, 0, 0);
2350 * Move to the next entry, fill in the previous offset.
2352 if (offset > 2 || (offset == 2 && !zfs_show_ctldir(zp))) {
2353 zap_cursor_advance(&zc);
2354 offset = zap_cursor_serialize(&zc);
2361 zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */
2363 if (uio->uio_segflg == UIO_SYSSPACE && uio->uio_iovcnt == 1) {
2364 iovp->iov_base += outcount;
2365 iovp->iov_len -= outcount;
2366 uio->uio_resid -= outcount;
2367 } else if (error = uiomove(outbuf, (long)outcount, UIO_READ, uio)) {
2369 * Reset the pointer.
2371 offset = uio->uio_loffset;
2375 zap_cursor_fini(&zc);
2376 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
2377 kmem_free(outbuf, bufsize);
2379 if (error == ENOENT)
2382 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
2384 uio->uio_loffset = offset;
2389 ulong_t zfs_fsync_sync_cnt = 4;
2392 zfs_fsync(vnode_t *vp, int syncflag, cred_t *cr, caller_context_t *ct)
2394 znode_t *zp = VTOZ(vp);
2395 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2398 * Regardless of whether this is required for standards conformance,
2399 * this is the logical behavior when fsync() is called on a file with
2400 * dirty pages. We use B_ASYNC since the ZIL transactions are already
2401 * going to be pushed out as part of the zil_commit().
2403 if (vn_has_cached_data(vp) && !(syncflag & FNODSYNC) &&
2404 (vp->v_type == VREG) && !(IS_SWAPVP(vp)))
2405 (void) VOP_PUTPAGE(vp, (offset_t)0, (size_t)0, B_ASYNC, cr, ct);
2407 (void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt);
2409 if (zfsvfs->z_os->os_sync != ZFS_SYNC_DISABLED) {
2412 zil_commit(zfsvfs->z_log, zp->z_id);
2417 EXPORT_SYMBOL(zfs_fsync);
2421 * Get the requested file attributes and place them in the provided
2424 * IN: vp - vnode of file.
2425 * vap - va_mask identifies requested attributes.
2426 * If AT_XVATTR set, then optional attrs are requested
2427 * flags - ATTR_NOACLCHECK (CIFS server context)
2428 * cr - credentials of caller.
2429 * ct - caller context
2431 * OUT: vap - attribute values.
2433 * RETURN: 0 (always succeeds)
2437 zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2438 caller_context_t *ct)
2440 znode_t *zp = VTOZ(vp);
2441 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2444 uint64_t mtime[2], ctime[2];
2445 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2446 xoptattr_t *xoap = NULL;
2447 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2448 sa_bulk_attr_t bulk[2];
2454 zfs_fuid_map_ids(zp, cr, &vap->va_uid, &vap->va_gid);
2456 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
2457 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
2459 if ((error = sa_bulk_lookup(zp->z_sa_hdl, bulk, count)) != 0) {
2465 * If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES.
2466 * Also, if we are the owner don't bother, since owner should
2467 * always be allowed to read basic attributes of file.
2469 if (!(zp->z_pflags & ZFS_ACL_TRIVIAL) &&
2470 (vap->va_uid != crgetuid(cr))) {
2471 if ((error = zfs_zaccess(zp, ACE_READ_ATTRIBUTES, 0,
2479 * Return all attributes. It's cheaper to provide the answer
2480 * than to determine whether we were asked the question.
2483 mutex_enter(&zp->z_lock);
2484 vap->va_type = vp->v_type;
2485 vap->va_mode = zp->z_mode & MODEMASK;
2486 vap->va_fsid = zp->z_zfsvfs->z_vfs->vfs_dev;
2487 vap->va_nodeid = zp->z_id;
2488 if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp))
2489 links = zp->z_links + 1;
2491 links = zp->z_links;
2492 vap->va_nlink = MIN(links, UINT32_MAX); /* nlink_t limit! */
2493 vap->va_size = zp->z_size;
2494 vap->va_rdev = vp->v_rdev;
2495 vap->va_seq = zp->z_seq;
2498 * Add in any requested optional attributes and the create time.
2499 * Also set the corresponding bits in the returned attribute bitmap.
2501 if ((xoap = xva_getxoptattr(xvap)) != NULL && zfsvfs->z_use_fuids) {
2502 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
2504 ((zp->z_pflags & ZFS_ARCHIVE) != 0);
2505 XVA_SET_RTN(xvap, XAT_ARCHIVE);
2508 if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
2509 xoap->xoa_readonly =
2510 ((zp->z_pflags & ZFS_READONLY) != 0);
2511 XVA_SET_RTN(xvap, XAT_READONLY);
2514 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
2516 ((zp->z_pflags & ZFS_SYSTEM) != 0);
2517 XVA_SET_RTN(xvap, XAT_SYSTEM);
2520 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
2522 ((zp->z_pflags & ZFS_HIDDEN) != 0);
2523 XVA_SET_RTN(xvap, XAT_HIDDEN);
2526 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
2527 xoap->xoa_nounlink =
2528 ((zp->z_pflags & ZFS_NOUNLINK) != 0);
2529 XVA_SET_RTN(xvap, XAT_NOUNLINK);
2532 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
2533 xoap->xoa_immutable =
2534 ((zp->z_pflags & ZFS_IMMUTABLE) != 0);
2535 XVA_SET_RTN(xvap, XAT_IMMUTABLE);
2538 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
2539 xoap->xoa_appendonly =
2540 ((zp->z_pflags & ZFS_APPENDONLY) != 0);
2541 XVA_SET_RTN(xvap, XAT_APPENDONLY);
2544 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
2546 ((zp->z_pflags & ZFS_NODUMP) != 0);
2547 XVA_SET_RTN(xvap, XAT_NODUMP);
2550 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
2552 ((zp->z_pflags & ZFS_OPAQUE) != 0);
2553 XVA_SET_RTN(xvap, XAT_OPAQUE);
2556 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
2557 xoap->xoa_av_quarantined =
2558 ((zp->z_pflags & ZFS_AV_QUARANTINED) != 0);
2559 XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
2562 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
2563 xoap->xoa_av_modified =
2564 ((zp->z_pflags & ZFS_AV_MODIFIED) != 0);
2565 XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
2568 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) &&
2569 vp->v_type == VREG) {
2570 zfs_sa_get_scanstamp(zp, xvap);
2573 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
2576 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zfsvfs),
2577 times, sizeof (times));
2578 ZFS_TIME_DECODE(&xoap->xoa_createtime, times);
2579 XVA_SET_RTN(xvap, XAT_CREATETIME);
2582 if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
2583 xoap->xoa_reparse = ((zp->z_pflags & ZFS_REPARSE) != 0);
2584 XVA_SET_RTN(xvap, XAT_REPARSE);
2586 if (XVA_ISSET_REQ(xvap, XAT_GEN)) {
2587 xoap->xoa_generation = zp->z_gen;
2588 XVA_SET_RTN(xvap, XAT_GEN);
2591 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE)) {
2593 ((zp->z_pflags & ZFS_OFFLINE) != 0);
2594 XVA_SET_RTN(xvap, XAT_OFFLINE);
2597 if (XVA_ISSET_REQ(xvap, XAT_SPARSE)) {
2599 ((zp->z_pflags & ZFS_SPARSE) != 0);
2600 XVA_SET_RTN(xvap, XAT_SPARSE);
2604 ZFS_TIME_DECODE(&vap->va_atime, zp->z_atime);
2605 ZFS_TIME_DECODE(&vap->va_mtime, mtime);
2606 ZFS_TIME_DECODE(&vap->va_ctime, ctime);
2608 mutex_exit(&zp->z_lock);
2610 sa_object_size(zp->z_sa_hdl, &vap->va_blksize, &vap->va_nblocks);
2612 if (zp->z_blksz == 0) {
2614 * Block size hasn't been set; suggest maximal I/O transfers.
2616 vap->va_blksize = zfsvfs->z_max_blksz;
2622 EXPORT_SYMBOL(zfs_getattr);
2625 * Set the file attributes to the values contained in the
2628 * IN: vp - vnode of file to be modified.
2629 * vap - new attribute values.
2630 * If AT_XVATTR set, then optional attrs are being set
2631 * flags - ATTR_UTIME set if non-default time values provided.
2632 * - ATTR_NOACLCHECK (CIFS context only).
2633 * cr - credentials of caller.
2634 * ct - caller context
2636 * RETURN: 0 if success
2637 * error code if failure
2640 * vp - ctime updated, mtime updated if size changed.
2644 zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2645 caller_context_t *ct)
2647 znode_t *zp = VTOZ(vp);
2648 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2653 uint_t mask = vap->va_mask;
2657 uint64_t new_uid, new_gid;
2659 uint64_t mtime[2], ctime[2];
2661 int need_policy = FALSE;
2663 zfs_fuid_info_t *fuidp = NULL;
2664 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2667 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2668 boolean_t fuid_dirtied = B_FALSE;
2669 sa_bulk_attr_t bulk[7], xattr_bulk[7];
2670 int count = 0, xattr_count = 0;
2675 if (mask & AT_NOSET)
2681 zilog = zfsvfs->z_log;
2684 * Make sure that if we have ephemeral uid/gid or xvattr specified
2685 * that file system is at proper version level
2688 if (zfsvfs->z_use_fuids == B_FALSE &&
2689 (((mask & AT_UID) && IS_EPHEMERAL(vap->va_uid)) ||
2690 ((mask & AT_GID) && IS_EPHEMERAL(vap->va_gid)) ||
2691 (mask & AT_XVATTR))) {
2696 if (mask & AT_SIZE && vp->v_type == VDIR) {
2701 if (mask & AT_SIZE && vp->v_type != VREG && vp->v_type != VFIFO) {
2707 * If this is an xvattr_t, then get a pointer to the structure of
2708 * optional attributes. If this is NULL, then we have a vattr_t.
2710 xoap = xva_getxoptattr(xvap);
2712 xva_init(&tmpxvattr);
2715 * Immutable files can only alter immutable bit and atime
2717 if ((zp->z_pflags & ZFS_IMMUTABLE) &&
2718 ((mask & (AT_SIZE|AT_UID|AT_GID|AT_MTIME|AT_MODE)) ||
2719 ((mask & AT_XVATTR) && XVA_ISSET_REQ(xvap, XAT_CREATETIME)))) {
2724 if ((mask & AT_SIZE) && (zp->z_pflags & ZFS_READONLY)) {
2730 * Verify timestamps doesn't overflow 32 bits.
2731 * ZFS can handle large timestamps, but 32bit syscalls can't
2732 * handle times greater than 2039. This check should be removed
2733 * once large timestamps are fully supported.
2735 if (mask & (AT_ATIME | AT_MTIME)) {
2736 if (((mask & AT_ATIME) && TIMESPEC_OVERFLOW(&vap->va_atime)) ||
2737 ((mask & AT_MTIME) && TIMESPEC_OVERFLOW(&vap->va_mtime))) {
2747 /* Can this be moved to before the top label? */
2748 if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) {
2754 * First validate permissions
2757 if (mask & AT_SIZE) {
2758 err = zfs_zaccess(zp, ACE_WRITE_DATA, 0, skipaclchk, cr);
2764 * XXX - Note, we are not providing any open
2765 * mode flags here (like FNDELAY), so we may
2766 * block if there are locks present... this
2767 * should be addressed in openat().
2769 /* XXX - would it be OK to generate a log record here? */
2770 err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE);
2777 if (mask & (AT_ATIME|AT_MTIME) ||
2778 ((mask & AT_XVATTR) && (XVA_ISSET_REQ(xvap, XAT_HIDDEN) ||
2779 XVA_ISSET_REQ(xvap, XAT_READONLY) ||
2780 XVA_ISSET_REQ(xvap, XAT_ARCHIVE) ||
2781 XVA_ISSET_REQ(xvap, XAT_OFFLINE) ||
2782 XVA_ISSET_REQ(xvap, XAT_SPARSE) ||
2783 XVA_ISSET_REQ(xvap, XAT_CREATETIME) ||
2784 XVA_ISSET_REQ(xvap, XAT_SYSTEM)))) {
2785 need_policy = zfs_zaccess(zp, ACE_WRITE_ATTRIBUTES, 0,
2789 if (mask & (AT_UID|AT_GID)) {
2790 int idmask = (mask & (AT_UID|AT_GID));
2795 * NOTE: even if a new mode is being set,
2796 * we may clear S_ISUID/S_ISGID bits.
2799 if (!(mask & AT_MODE))
2800 vap->va_mode = zp->z_mode;
2803 * Take ownership or chgrp to group we are a member of
2806 take_owner = (mask & AT_UID) && (vap->va_uid == crgetuid(cr));
2807 take_group = (mask & AT_GID) &&
2808 zfs_groupmember(zfsvfs, vap->va_gid, cr);
2811 * If both AT_UID and AT_GID are set then take_owner and
2812 * take_group must both be set in order to allow taking
2815 * Otherwise, send the check through secpolicy_vnode_setattr()
2819 if (((idmask == (AT_UID|AT_GID)) && take_owner && take_group) ||
2820 ((idmask == AT_UID) && take_owner) ||
2821 ((idmask == AT_GID) && take_group)) {
2822 if (zfs_zaccess(zp, ACE_WRITE_OWNER, 0,
2823 skipaclchk, cr) == 0) {
2825 * Remove setuid/setgid for non-privileged users
2827 secpolicy_setid_clear(vap, cr);
2828 trim_mask = (mask & (AT_UID|AT_GID));
2837 mutex_enter(&zp->z_lock);
2838 oldva.va_mode = zp->z_mode;
2839 zfs_fuid_map_ids(zp, cr, &oldva.va_uid, &oldva.va_gid);
2840 if (mask & AT_XVATTR) {
2842 * Update xvattr mask to include only those attributes
2843 * that are actually changing.
2845 * the bits will be restored prior to actually setting
2846 * the attributes so the caller thinks they were set.
2848 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
2849 if (xoap->xoa_appendonly !=
2850 ((zp->z_pflags & ZFS_APPENDONLY) != 0)) {
2853 XVA_CLR_REQ(xvap, XAT_APPENDONLY);
2854 XVA_SET_REQ(&tmpxvattr, XAT_APPENDONLY);
2858 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
2859 if (xoap->xoa_nounlink !=
2860 ((zp->z_pflags & ZFS_NOUNLINK) != 0)) {
2863 XVA_CLR_REQ(xvap, XAT_NOUNLINK);
2864 XVA_SET_REQ(&tmpxvattr, XAT_NOUNLINK);
2868 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
2869 if (xoap->xoa_immutable !=
2870 ((zp->z_pflags & ZFS_IMMUTABLE) != 0)) {
2873 XVA_CLR_REQ(xvap, XAT_IMMUTABLE);
2874 XVA_SET_REQ(&tmpxvattr, XAT_IMMUTABLE);
2878 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
2879 if (xoap->xoa_nodump !=
2880 ((zp->z_pflags & ZFS_NODUMP) != 0)) {
2883 XVA_CLR_REQ(xvap, XAT_NODUMP);
2884 XVA_SET_REQ(&tmpxvattr, XAT_NODUMP);
2888 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
2889 if (xoap->xoa_av_modified !=
2890 ((zp->z_pflags & ZFS_AV_MODIFIED) != 0)) {
2893 XVA_CLR_REQ(xvap, XAT_AV_MODIFIED);
2894 XVA_SET_REQ(&tmpxvattr, XAT_AV_MODIFIED);
2898 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
2899 if ((vp->v_type != VREG &&
2900 xoap->xoa_av_quarantined) ||
2901 xoap->xoa_av_quarantined !=
2902 ((zp->z_pflags & ZFS_AV_QUARANTINED) != 0)) {
2905 XVA_CLR_REQ(xvap, XAT_AV_QUARANTINED);
2906 XVA_SET_REQ(&tmpxvattr, XAT_AV_QUARANTINED);
2910 if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
2911 mutex_exit(&zp->z_lock);
2916 if (need_policy == FALSE &&
2917 (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) ||
2918 XVA_ISSET_REQ(xvap, XAT_OPAQUE))) {
2923 mutex_exit(&zp->z_lock);
2925 if (mask & AT_MODE) {
2926 if (zfs_zaccess(zp, ACE_WRITE_ACL, 0, skipaclchk, cr) == 0) {
2927 err = secpolicy_setid_setsticky_clear(vp, vap,
2933 trim_mask |= AT_MODE;
2941 * If trim_mask is set then take ownership
2942 * has been granted or write_acl is present and user
2943 * has the ability to modify mode. In that case remove
2944 * UID|GID and or MODE from mask so that
2945 * secpolicy_vnode_setattr() doesn't revoke it.
2949 saved_mask = vap->va_mask;
2950 vap->va_mask &= ~trim_mask;
2952 err = secpolicy_vnode_setattr(cr, vp, vap, &oldva, flags,
2953 (int (*)(void *, int, cred_t *))zfs_zaccess_unix, zp);
2960 vap->va_mask |= saved_mask;
2964 * secpolicy_vnode_setattr, or take ownership may have
2967 mask = vap->va_mask;
2969 if ((mask & (AT_UID | AT_GID))) {
2970 err = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
2971 &xattr_obj, sizeof (xattr_obj));
2973 if (err == 0 && xattr_obj) {
2974 err = zfs_zget(zp->z_zfsvfs, xattr_obj, &attrzp);
2978 if (mask & AT_UID) {
2979 new_uid = zfs_fuid_create(zfsvfs,
2980 (uint64_t)vap->va_uid, cr, ZFS_OWNER, &fuidp);
2981 if (new_uid != zp->z_uid &&
2982 zfs_fuid_overquota(zfsvfs, B_FALSE, new_uid)) {
2984 VN_RELE(ZTOV(attrzp));
2990 if (mask & AT_GID) {
2991 new_gid = zfs_fuid_create(zfsvfs, (uint64_t)vap->va_gid,
2992 cr, ZFS_GROUP, &fuidp);
2993 if (new_gid != zp->z_gid &&
2994 zfs_fuid_overquota(zfsvfs, B_TRUE, new_gid)) {
2996 VN_RELE(ZTOV(attrzp));
3002 tx = dmu_tx_create(zfsvfs->z_os);
3004 if (mask & AT_MODE) {
3005 uint64_t pmode = zp->z_mode;
3007 new_mode = (pmode & S_IFMT) | (vap->va_mode & ~S_IFMT);
3009 zfs_acl_chmod_setattr(zp, &aclp, new_mode);
3011 mutex_enter(&zp->z_lock);
3012 if (!zp->z_is_sa && ((acl_obj = zfs_external_acl(zp)) != 0)) {
3014 * Are we upgrading ACL from old V0 format
3017 if (zfsvfs->z_version >= ZPL_VERSION_FUID &&
3018 zfs_znode_acl_version(zp) ==
3019 ZFS_ACL_VERSION_INITIAL) {
3020 dmu_tx_hold_free(tx, acl_obj, 0,
3022 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
3023 0, aclp->z_acl_bytes);
3025 dmu_tx_hold_write(tx, acl_obj, 0,
3028 } else if (!zp->z_is_sa && aclp->z_acl_bytes > ZFS_ACE_SPACE) {
3029 dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
3030 0, aclp->z_acl_bytes);
3032 mutex_exit(&zp->z_lock);
3033 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
3035 if ((mask & AT_XVATTR) &&
3036 XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
3037 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
3039 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
3043 dmu_tx_hold_sa(tx, attrzp->z_sa_hdl, B_FALSE);
3046 fuid_dirtied = zfsvfs->z_fuid_dirty;
3048 zfs_fuid_txhold(zfsvfs, tx);
3050 zfs_sa_upgrade_txholds(tx, zp);
3052 err = dmu_tx_assign(tx, TXG_NOWAIT);
3054 if (err == ERESTART)
3061 * Set each attribute requested.
3062 * We group settings according to the locks they need to acquire.
3064 * Note: you cannot set ctime directly, although it will be
3065 * updated as a side-effect of calling this function.
3069 if (mask & (AT_UID|AT_GID|AT_MODE))
3070 mutex_enter(&zp->z_acl_lock);
3071 mutex_enter(&zp->z_lock);
3073 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
3074 &zp->z_pflags, sizeof (zp->z_pflags));
3077 if (mask & (AT_UID|AT_GID|AT_MODE))
3078 mutex_enter(&attrzp->z_acl_lock);
3079 mutex_enter(&attrzp->z_lock);
3080 SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
3081 SA_ZPL_FLAGS(zfsvfs), NULL, &attrzp->z_pflags,
3082 sizeof (attrzp->z_pflags));
3085 if (mask & (AT_UID|AT_GID)) {
3087 if (mask & AT_UID) {
3088 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL,
3089 &new_uid, sizeof (new_uid));
3090 zp->z_uid = new_uid;
3092 SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
3093 SA_ZPL_UID(zfsvfs), NULL, &new_uid,
3095 attrzp->z_uid = new_uid;
3099 if (mask & AT_GID) {
3100 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs),
3101 NULL, &new_gid, sizeof (new_gid));
3102 zp->z_gid = new_gid;
3104 SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
3105 SA_ZPL_GID(zfsvfs), NULL, &new_gid,
3107 attrzp->z_gid = new_gid;
3110 if (!(mask & AT_MODE)) {
3111 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs),
3112 NULL, &new_mode, sizeof (new_mode));
3113 new_mode = zp->z_mode;
3115 err = zfs_acl_chown_setattr(zp);
3118 err = zfs_acl_chown_setattr(attrzp);
3123 if (mask & AT_MODE) {
3124 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
3125 &new_mode, sizeof (new_mode));
3126 zp->z_mode = new_mode;
3127 ASSERT3U((uintptr_t)aclp, !=, NULL);
3128 err = zfs_aclset_common(zp, aclp, cr, tx);
3129 ASSERT3U(err, ==, 0);
3130 if (zp->z_acl_cached)
3131 zfs_acl_free(zp->z_acl_cached);
3132 zp->z_acl_cached = aclp;
3137 if (mask & AT_ATIME) {
3138 ZFS_TIME_ENCODE(&vap->va_atime, zp->z_atime);
3139 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
3140 &zp->z_atime, sizeof (zp->z_atime));
3143 if (mask & AT_MTIME) {
3144 ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
3145 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
3146 mtime, sizeof (mtime));
3149 /* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
3150 if (mask & AT_SIZE && !(mask & AT_MTIME)) {
3151 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs),
3152 NULL, mtime, sizeof (mtime));
3153 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
3154 &ctime, sizeof (ctime));
3155 zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
3157 } else if (mask != 0) {
3158 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
3159 &ctime, sizeof (ctime));
3160 zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime, ctime,
3163 SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
3164 SA_ZPL_CTIME(zfsvfs), NULL,
3165 &ctime, sizeof (ctime));
3166 zfs_tstamp_update_setup(attrzp, STATE_CHANGED,
3167 mtime, ctime, B_TRUE);
3171 * Do this after setting timestamps to prevent timestamp
3172 * update from toggling bit
3175 if (xoap && (mask & AT_XVATTR)) {
3178 * restore trimmed off masks
3179 * so that return masks can be set for caller.
3182 if (XVA_ISSET_REQ(&tmpxvattr, XAT_APPENDONLY)) {
3183 XVA_SET_REQ(xvap, XAT_APPENDONLY);
3185 if (XVA_ISSET_REQ(&tmpxvattr, XAT_NOUNLINK)) {
3186 XVA_SET_REQ(xvap, XAT_NOUNLINK);
3188 if (XVA_ISSET_REQ(&tmpxvattr, XAT_IMMUTABLE)) {
3189 XVA_SET_REQ(xvap, XAT_IMMUTABLE);
3191 if (XVA_ISSET_REQ(&tmpxvattr, XAT_NODUMP)) {
3192 XVA_SET_REQ(xvap, XAT_NODUMP);
3194 if (XVA_ISSET_REQ(&tmpxvattr, XAT_AV_MODIFIED)) {
3195 XVA_SET_REQ(xvap, XAT_AV_MODIFIED);
3197 if (XVA_ISSET_REQ(&tmpxvattr, XAT_AV_QUARANTINED)) {
3198 XVA_SET_REQ(xvap, XAT_AV_QUARANTINED);
3201 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
3202 ASSERT(vp->v_type == VREG);
3204 zfs_xvattr_set(zp, xvap, tx);
3208 zfs_fuid_sync(zfsvfs, tx);
3211 zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp);
3213 mutex_exit(&zp->z_lock);
3214 if (mask & (AT_UID|AT_GID|AT_MODE))
3215 mutex_exit(&zp->z_acl_lock);
3218 if (mask & (AT_UID|AT_GID|AT_MODE))
3219 mutex_exit(&attrzp->z_acl_lock);
3220 mutex_exit(&attrzp->z_lock);
3223 if (err == 0 && attrzp) {
3224 err2 = sa_bulk_update(attrzp->z_sa_hdl, xattr_bulk,
3230 VN_RELE(ZTOV(attrzp));
3235 zfs_fuid_info_free(fuidp);
3241 if (err == ERESTART)
3244 err2 = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
3246 zfs_inode_update(zp);
3250 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3251 zil_commit(zilog, 0);
3256 EXPORT_SYMBOL(zfs_setattr);
3258 typedef struct zfs_zlock {
3259 krwlock_t *zl_rwlock; /* lock we acquired */
3260 znode_t *zl_znode; /* znode we held */
3261 struct zfs_zlock *zl_next; /* next in list */
3265 * Drop locks and release vnodes that were held by zfs_rename_lock().
3268 zfs_rename_unlock(zfs_zlock_t **zlpp)
3272 while ((zl = *zlpp) != NULL) {
3273 if (zl->zl_znode != NULL)
3274 VN_RELE(ZTOV(zl->zl_znode));
3275 rw_exit(zl->zl_rwlock);
3276 *zlpp = zl->zl_next;
3277 kmem_free(zl, sizeof (*zl));
3282 * Search back through the directory tree, using the ".." entries.
3283 * Lock each directory in the chain to prevent concurrent renames.
3284 * Fail any attempt to move a directory into one of its own descendants.
3285 * XXX - z_parent_lock can overlap with map or grow locks
3288 zfs_rename_lock(znode_t *szp, znode_t *tdzp, znode_t *sdzp, zfs_zlock_t **zlpp)
3292 uint64_t rootid = zp->z_zfsvfs->z_root;
3293 uint64_t oidp = zp->z_id;
3294 krwlock_t *rwlp = &szp->z_parent_lock;
3295 krw_t rw = RW_WRITER;
3298 * First pass write-locks szp and compares to zp->z_id.
3299 * Later passes read-lock zp and compare to zp->z_parent.
3302 if (!rw_tryenter(rwlp, rw)) {
3304 * Another thread is renaming in this path.
3305 * Note that if we are a WRITER, we don't have any
3306 * parent_locks held yet.
3308 if (rw == RW_READER && zp->z_id > szp->z_id) {
3310 * Drop our locks and restart
3312 zfs_rename_unlock(&zl);
3316 rwlp = &szp->z_parent_lock;
3321 * Wait for other thread to drop its locks
3327 zl = kmem_alloc(sizeof (*zl), KM_SLEEP);
3328 zl->zl_rwlock = rwlp;
3329 zl->zl_znode = NULL;
3330 zl->zl_next = *zlpp;
3333 if (oidp == szp->z_id) /* We're a descendant of szp */
3336 if (oidp == rootid) /* We've hit the top */
3339 if (rw == RW_READER) { /* i.e. not the first pass */
3340 int error = zfs_zget(zp->z_zfsvfs, oidp, &zp);
3345 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(zp->z_zfsvfs),
3346 &oidp, sizeof (oidp));
3347 rwlp = &zp->z_parent_lock;
3350 } while (zp->z_id != sdzp->z_id);
3356 * Move an entry from the provided source directory to the target
3357 * directory. Change the entry name as indicated.
3359 * IN: sdvp - Source directory containing the "old entry".
3360 * snm - Old entry name.
3361 * tdvp - Target directory to contain the "new entry".
3362 * tnm - New entry name.
3363 * cr - credentials of caller.
3364 * ct - caller context
3365 * flags - case flags
3367 * RETURN: 0 if success
3368 * error code if failure
3371 * sdvp,tdvp - ctime|mtime updated
3375 zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr,
3376 caller_context_t *ct, int flags)
3378 znode_t *tdzp, *szp, *tzp;
3379 znode_t *sdzp = VTOZ(sdvp);
3380 zfsvfs_t *zfsvfs = sdzp->z_zfsvfs;
3383 zfs_dirlock_t *sdl, *tdl;
3386 int cmp, serr, terr;
3391 ZFS_VERIFY_ZP(sdzp);
3392 zilog = zfsvfs->z_log;
3395 * Make sure we have the real vp for the target directory.
3397 if (VOP_REALVP(tdvp, &realvp, ct) == 0)
3400 if (tdvp->v_vfsp != sdvp->v_vfsp || zfsctl_is_node(tdvp)) {
3406 ZFS_VERIFY_ZP(tdzp);
3407 if (zfsvfs->z_utf8 && u8_validate(tnm,
3408 strlen(tnm), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3413 if (flags & FIGNORECASE)
3422 * This is to prevent the creation of links into attribute space
3423 * by renaming a linked file into/outof an attribute directory.
3424 * See the comment in zfs_link() for why this is considered bad.
3426 if ((tdzp->z_pflags & ZFS_XATTR) != (sdzp->z_pflags & ZFS_XATTR)) {
3432 * Lock source and target directory entries. To prevent deadlock,
3433 * a lock ordering must be defined. We lock the directory with
3434 * the smallest object id first, or if it's a tie, the one with
3435 * the lexically first name.
3437 if (sdzp->z_id < tdzp->z_id) {
3439 } else if (sdzp->z_id > tdzp->z_id) {
3443 * First compare the two name arguments without
3444 * considering any case folding.
3446 int nofold = (zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER);
3448 cmp = u8_strcmp(snm, tnm, 0, nofold, U8_UNICODE_LATEST, &error);
3449 ASSERT(error == 0 || !zfsvfs->z_utf8);
3452 * POSIX: "If the old argument and the new argument
3453 * both refer to links to the same existing file,
3454 * the rename() function shall return successfully
3455 * and perform no other action."
3461 * If the file system is case-folding, then we may
3462 * have some more checking to do. A case-folding file
3463 * system is either supporting mixed case sensitivity
3464 * access or is completely case-insensitive. Note
3465 * that the file system is always case preserving.
3467 * In mixed sensitivity mode case sensitive behavior
3468 * is the default. FIGNORECASE must be used to
3469 * explicitly request case insensitive behavior.
3471 * If the source and target names provided differ only
3472 * by case (e.g., a request to rename 'tim' to 'Tim'),
3473 * we will treat this as a special case in the
3474 * case-insensitive mode: as long as the source name
3475 * is an exact match, we will allow this to proceed as
3476 * a name-change request.
3478 if ((zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
3479 (zfsvfs->z_case == ZFS_CASE_MIXED &&
3480 flags & FIGNORECASE)) &&
3481 u8_strcmp(snm, tnm, 0, zfsvfs->z_norm, U8_UNICODE_LATEST,
3484 * case preserving rename request, require exact
3493 * If the source and destination directories are the same, we should
3494 * grab the z_name_lock of that directory only once.
3498 rw_enter(&sdzp->z_name_lock, RW_READER);
3502 serr = zfs_dirent_lock(&sdl, sdzp, snm, &szp,
3503 ZEXISTS | zflg, NULL, NULL);
3504 terr = zfs_dirent_lock(&tdl,
3505 tdzp, tnm, &tzp, ZRENAMING | zflg, NULL, NULL);
3507 terr = zfs_dirent_lock(&tdl,
3508 tdzp, tnm, &tzp, zflg, NULL, NULL);
3509 serr = zfs_dirent_lock(&sdl,
3510 sdzp, snm, &szp, ZEXISTS | ZRENAMING | zflg,
3516 * Source entry invalid or not there.
3519 zfs_dirent_unlock(tdl);
3525 rw_exit(&sdzp->z_name_lock);
3527 if (strcmp(snm, "..") == 0)
3533 zfs_dirent_unlock(sdl);
3537 rw_exit(&sdzp->z_name_lock);
3539 if (strcmp(tnm, "..") == 0)
3546 * Must have write access at the source to remove the old entry
3547 * and write access at the target to create the new entry.
3548 * Note that if target and source are the same, this can be
3549 * done in a single check.
3552 if ((error = zfs_zaccess_rename(sdzp, szp, tdzp, tzp, cr)))
3555 if (ZTOV(szp)->v_type == VDIR) {
3557 * Check to make sure rename is valid.
3558 * Can't do a move like this: /usr/a/b to /usr/a/b/c/d
3560 if ((error = zfs_rename_lock(szp, tdzp, sdzp, &zl)))
3565 * Does target exist?
3569 * Source and target must be the same type.
3571 if (ZTOV(szp)->v_type == VDIR) {
3572 if (ZTOV(tzp)->v_type != VDIR) {
3577 if (ZTOV(tzp)->v_type == VDIR) {
3583 * POSIX dictates that when the source and target
3584 * entries refer to the same file object, rename
3585 * must do nothing and exit without error.
3587 if (szp->z_id == tzp->z_id) {
3593 vnevent_rename_src(ZTOV(szp), sdvp, snm, ct);
3595 vnevent_rename_dest(ZTOV(tzp), tdvp, tnm, ct);
3598 * notify the target directory if it is not the same
3599 * as source directory.
3602 vnevent_rename_dest_dir(tdvp, ct);
3605 tx = dmu_tx_create(zfsvfs->z_os);
3606 dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
3607 dmu_tx_hold_sa(tx, sdzp->z_sa_hdl, B_FALSE);
3608 dmu_tx_hold_zap(tx, sdzp->z_id, FALSE, snm);
3609 dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, tnm);
3611 dmu_tx_hold_sa(tx, tdzp->z_sa_hdl, B_FALSE);
3612 zfs_sa_upgrade_txholds(tx, tdzp);
3615 dmu_tx_hold_sa(tx, tzp->z_sa_hdl, B_FALSE);
3616 zfs_sa_upgrade_txholds(tx, tzp);
3619 zfs_sa_upgrade_txholds(tx, szp);
3620 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
3621 error = dmu_tx_assign(tx, TXG_NOWAIT);
3624 zfs_rename_unlock(&zl);
3625 zfs_dirent_unlock(sdl);
3626 zfs_dirent_unlock(tdl);
3629 rw_exit(&sdzp->z_name_lock);
3634 if (error == ERESTART) {
3644 if (tzp) /* Attempt to remove the existing target */
3645 error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL);
3648 error = zfs_link_create(tdl, szp, tx, ZRENAMING);
3650 szp->z_pflags |= ZFS_AV_MODIFIED;
3652 error = sa_update(szp->z_sa_hdl, SA_ZPL_FLAGS(zfsvfs),
3653 (void *)&szp->z_pflags, sizeof (uint64_t), tx);
3654 ASSERT3U(error, ==, 0);
3656 error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL);
3658 zfs_log_rename(zilog, tx, TX_RENAME |
3659 (flags & FIGNORECASE ? TX_CI : 0), sdzp,
3660 sdl->dl_name, tdzp, tdl->dl_name, szp);
3663 * Update path information for the target vnode
3665 vn_renamepath(tdvp, ZTOV(szp), tnm,
3669 * At this point, we have successfully created
3670 * the target name, but have failed to remove
3671 * the source name. Since the create was done
3672 * with the ZRENAMING flag, there are
3673 * complications; for one, the link count is
3674 * wrong. The easiest way to deal with this
3675 * is to remove the newly created target, and
3676 * return the original error. This must
3677 * succeed; fortunately, it is very unlikely to
3678 * fail, since we just created it.
3680 VERIFY3U(zfs_link_destroy(tdl, szp, tx,
3681 ZRENAMING, NULL), ==, 0);
3689 zfs_rename_unlock(&zl);
3691 zfs_dirent_unlock(sdl);
3692 zfs_dirent_unlock(tdl);
3694 zfs_inode_update(sdzp);
3696 rw_exit(&sdzp->z_name_lock);
3699 zfs_inode_update(tdzp);
3701 zfs_inode_update(szp);
3704 zfs_inode_update(tzp);
3708 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3709 zil_commit(zilog, 0);
3714 EXPORT_SYMBOL(zfs_rename);
3717 * Insert the indicated symbolic reference entry into the directory.
3719 * IN: dvp - Directory to contain new symbolic link.
3720 * link - Name for new symlink entry.
3721 * vap - Attributes of new entry.
3722 * target - Target path of new symlink.
3723 * cr - credentials of caller.
3724 * ct - caller context
3725 * flags - case flags
3727 * RETURN: 0 if success
3728 * error code if failure
3731 * dvp - ctime|mtime updated
3735 zfs_symlink(vnode_t *dvp, char *name, vattr_t *vap, char *link, cred_t *cr,
3736 caller_context_t *ct, int flags)
3738 znode_t *zp, *dzp = VTOZ(dvp);
3741 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3743 uint64_t len = strlen(link);
3746 zfs_acl_ids_t acl_ids;
3747 boolean_t fuid_dirtied;
3748 uint64_t txtype = TX_SYMLINK;
3750 ASSERT(vap->va_type == VLNK);
3754 zilog = zfsvfs->z_log;
3756 if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
3757 NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3761 if (flags & FIGNORECASE)
3764 if (len > MAXPATHLEN) {
3766 return (ENAMETOOLONG);
3769 if ((error = zfs_acl_ids_create(dzp, 0,
3770 vap, cr, NULL, &acl_ids)) != 0) {
3776 * Attempt to lock directory; fail if entry already exists.
3778 error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, NULL, NULL);
3780 zfs_acl_ids_free(&acl_ids);
3785 if ((error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr))) {
3786 zfs_acl_ids_free(&acl_ids);
3787 zfs_dirent_unlock(dl);
3792 if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
3793 zfs_acl_ids_free(&acl_ids);
3794 zfs_dirent_unlock(dl);
3798 tx = dmu_tx_create(zfsvfs->z_os);
3799 fuid_dirtied = zfsvfs->z_fuid_dirty;
3800 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, MAX(1, len));
3801 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
3802 dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
3803 ZFS_SA_BASE_ATTR_SIZE + len);
3804 dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
3805 if (!zfsvfs->z_use_sa && acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
3806 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
3807 acl_ids.z_aclp->z_acl_bytes);
3810 zfs_fuid_txhold(zfsvfs, tx);
3811 error = dmu_tx_assign(tx, TXG_NOWAIT);
3813 zfs_dirent_unlock(dl);
3814 if (error == ERESTART) {
3819 zfs_acl_ids_free(&acl_ids);
3826 * Create a new object for the symlink.
3827 * for version 4 ZPL datsets the symlink will be an SA attribute
3829 zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
3832 zfs_fuid_sync(zfsvfs, tx);
3834 mutex_enter(&zp->z_lock);
3836 error = sa_update(zp->z_sa_hdl, SA_ZPL_SYMLINK(zfsvfs),
3839 zfs_sa_symlink(zp, link, len, tx);
3840 mutex_exit(&zp->z_lock);
3843 (void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zfsvfs),
3844 &zp->z_size, sizeof (zp->z_size), tx);
3846 * Insert the new object into the directory.
3848 (void) zfs_link_create(dl, zp, tx, ZNEW);
3850 if (flags & FIGNORECASE)
3852 zfs_log_symlink(zilog, tx, txtype, dzp, zp, name, link);
3854 zfs_inode_update(dzp);
3855 zfs_inode_update(zp);
3857 zfs_acl_ids_free(&acl_ids);
3861 zfs_dirent_unlock(dl);
3865 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3866 zil_commit(zilog, 0);
3871 EXPORT_SYMBOL(zfs_symlink);
3874 * Return, in the buffer contained in the provided uio structure,
3875 * the symbolic path referred to by vp.
3877 * IN: vp - vnode of symbolic link.
3878 * uoip - structure to contain the link path.
3879 * cr - credentials of caller.
3880 * ct - caller context
3882 * OUT: uio - structure to contain the link path.
3884 * RETURN: 0 if success
3885 * error code if failure
3888 * vp - atime updated
3892 zfs_readlink(vnode_t *vp, uio_t *uio, cred_t *cr, caller_context_t *ct)
3894 znode_t *zp = VTOZ(vp);
3895 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3901 mutex_enter(&zp->z_lock);
3903 error = sa_lookup_uio(zp->z_sa_hdl,
3904 SA_ZPL_SYMLINK(zfsvfs), uio);
3906 error = zfs_sa_readlink(zp, uio);
3907 mutex_exit(&zp->z_lock);
3909 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
3911 zfs_inode_update(zp);
3915 EXPORT_SYMBOL(zfs_readlink);
3918 * Insert a new entry into directory tdvp referencing svp.
3920 * IN: tdvp - Directory to contain new entry.
3921 * svp - vnode of new entry.
3922 * name - name of new entry.
3923 * cr - credentials of caller.
3924 * ct - caller context
3926 * RETURN: 0 if success
3927 * error code if failure
3930 * tdvp - ctime|mtime updated
3931 * svp - ctime updated
3935 zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr,
3936 caller_context_t *ct, int flags)
3938 znode_t *dzp = VTOZ(tdvp);
3940 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3950 ASSERT(tdvp->v_type == VDIR);
3954 zilog = zfsvfs->z_log;
3956 if (VOP_REALVP(svp, &realvp, ct) == 0)
3960 * POSIX dictates that we return EPERM here.
3961 * Better choices include ENOTSUP or EISDIR.
3963 if (svp->v_type == VDIR) {
3968 if (svp->v_vfsp != tdvp->v_vfsp || zfsctl_is_node(svp)) {
3976 /* Prevent links to .zfs/shares files */
3978 if ((error = sa_lookup(szp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs),
3979 &parent, sizeof (uint64_t))) != 0) {
3983 if (parent == zfsvfs->z_shares_dir) {
3988 if (zfsvfs->z_utf8 && u8_validate(name,
3989 strlen(name), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3993 if (flags & FIGNORECASE)
3997 * We do not support links between attributes and non-attributes
3998 * because of the potential security risk of creating links
3999 * into "normal" file space in order to circumvent restrictions
4000 * imposed in attribute space.
4002 if ((szp->z_pflags & ZFS_XATTR) != (dzp->z_pflags & ZFS_XATTR)) {
4008 owner = zfs_fuid_map_id(zfsvfs, szp->z_uid, cr, ZFS_OWNER);
4009 if (owner != crgetuid(cr) && secpolicy_basic_link(cr) != 0) {
4014 if ((error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr))) {
4021 * Attempt to lock directory; fail if entry already exists.
4023 error = zfs_dirent_lock(&dl, dzp, name, &tzp, zf, NULL, NULL);
4029 tx = dmu_tx_create(zfsvfs->z_os);
4030 dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
4031 dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
4032 zfs_sa_upgrade_txholds(tx, szp);
4033 zfs_sa_upgrade_txholds(tx, dzp);
4034 error = dmu_tx_assign(tx, TXG_NOWAIT);
4036 zfs_dirent_unlock(dl);
4037 if (error == ERESTART) {
4047 error = zfs_link_create(dl, szp, tx, 0);
4050 uint64_t txtype = TX_LINK;
4051 if (flags & FIGNORECASE)
4053 zfs_log_link(zilog, tx, txtype, dzp, szp, name);
4058 zfs_dirent_unlock(dl);
4061 vnevent_link(svp, ct);
4064 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
4065 zil_commit(zilog, 0);
4067 zfs_inode_update(dzp);
4068 zfs_inode_update(szp);
4072 EXPORT_SYMBOL(zfs_link);
4075 * zfs_null_putapage() is used when the file system has been force
4076 * unmounted. It just drops the pages.
4080 zfs_null_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
4081 size_t *lenp, int flags, cred_t *cr)
4083 pvn_write_done(pp, B_INVAL|B_FORCE|B_ERROR);
4088 * Push a page out to disk, klustering if possible.
4090 * IN: vp - file to push page to.
4091 * pp - page to push.
4092 * flags - additional flags.
4093 * cr - credentials of caller.
4095 * OUT: offp - start of range pushed.
4096 * lenp - len of range pushed.
4098 * RETURN: 0 if success
4099 * error code if failure
4101 * NOTE: callers must have locked the page to be pushed. On
4102 * exit, the page (and all other pages in the kluster) must be
4107 zfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
4108 size_t *lenp, int flags, cred_t *cr)
4110 znode_t *zp = VTOZ(vp);
4111 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4113 u_offset_t off, koff;
4120 * If our blocksize is bigger than the page size, try to kluster
4121 * multiple pages so that we write a full block (thus avoiding
4122 * a read-modify-write).
4124 if (off < zp->z_size && zp->z_blksz > PAGESIZE) {
4125 klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE);
4126 koff = ISP2(klen) ? P2ALIGN(off, (u_offset_t)klen) : 0;
4127 ASSERT(koff <= zp->z_size);
4128 if (koff + klen > zp->z_size)
4129 klen = P2ROUNDUP(zp->z_size - koff, (uint64_t)PAGESIZE);
4130 pp = pvn_write_kluster(vp, pp, &off, &len, koff, klen, flags);
4132 ASSERT3U(btop(len), ==, btopr(len));
4135 * Can't push pages past end-of-file.
4137 if (off >= zp->z_size) {
4138 /* ignore all pages */
4141 } else if (off + len > zp->z_size) {
4142 int npages = btopr(zp->z_size - off);
4145 page_list_break(&pp, &trunc, npages);
4146 /* ignore pages past end of file */
4148 pvn_write_done(trunc, flags);
4149 len = zp->z_size - off;
4152 if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
4153 zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
4158 tx = dmu_tx_create(zfsvfs->z_os);
4159 dmu_tx_hold_write(tx, zp->z_id, off, len);
4161 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
4162 zfs_sa_upgrade_txholds(tx, zp);
4163 err = dmu_tx_assign(tx, TXG_NOWAIT);
4165 if (err == ERESTART) {
4174 if (zp->z_blksz <= PAGESIZE) {
4175 caddr_t va = zfs_map_page(pp, S_READ);
4176 ASSERT3U(len, <=, PAGESIZE);
4177 dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx);
4178 zfs_unmap_page(pp, va);
4180 err = dmu_write_pages(zfsvfs->z_os, zp->z_id, off, len, pp, tx);
4184 uint64_t mtime[2], ctime[2];
4185 sa_bulk_attr_t bulk[3];
4188 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
4190 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
4192 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
4194 zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
4196 zfs_log_write(zfsvfs->z_log, tx, TX_WRITE, zp, off, len, 0);
4201 pvn_write_done(pp, (err ? B_ERROR : 0) | flags);
4211 * Copy the portion of the file indicated from pages into the file.
4212 * The pages are stored in a page list attached to the files vnode.
4214 * IN: vp - vnode of file to push page data to.
4215 * off - position in file to put data.
4216 * len - amount of data to write.
4217 * flags - flags to control the operation.
4218 * cr - credentials of caller.
4219 * ct - caller context.
4221 * RETURN: 0 if success
4222 * error code if failure
4225 * vp - ctime|mtime updated
4229 zfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
4230 caller_context_t *ct)
4232 znode_t *zp = VTOZ(vp);
4233 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4245 * Align this request to the file block size in case we kluster.
4246 * XXX - this can result in pretty aggresive locking, which can
4247 * impact simultanious read/write access. One option might be
4248 * to break up long requests (len == 0) into block-by-block
4249 * operations to get narrower locking.
4251 blksz = zp->z_blksz;
4253 io_off = P2ALIGN_TYPED(off, blksz, u_offset_t);
4256 if (len > 0 && ISP2(blksz))
4257 io_len = P2ROUNDUP_TYPED(len + (off - io_off), blksz, size_t);
4263 * Search the entire vp list for pages >= io_off.
4265 rl = zfs_range_lock(zp, io_off, UINT64_MAX, RL_WRITER);
4266 error = pvn_vplist_dirty(vp, io_off, zfs_putapage, flags, cr);
4269 rl = zfs_range_lock(zp, io_off, io_len, RL_WRITER);
4271 if (off > zp->z_size) {
4272 /* past end of file */
4273 zfs_range_unlock(rl);
4278 len = MIN(io_len, P2ROUNDUP(zp->z_size, PAGESIZE) - io_off);
4280 for (off = io_off; io_off < off + len; io_off += io_len) {
4281 if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) {
4282 pp = page_lookup(vp, io_off,
4283 (flags & (B_INVAL | B_FREE)) ? SE_EXCL : SE_SHARED);
4285 pp = page_lookup_nowait(vp, io_off,
4286 (flags & B_FREE) ? SE_EXCL : SE_SHARED);
4289 if (pp != NULL && pvn_getdirty(pp, flags)) {
4293 * Found a dirty page to push
4295 err = zfs_putapage(vp, pp, &io_off, &io_len, flags, cr);
4303 zfs_range_unlock(rl);
4304 if ((flags & B_ASYNC) == 0 || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
4305 zil_commit(zfsvfs->z_log, zp->z_id);
4312 zfs_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
4314 znode_t *zp = VTOZ(vp);
4315 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4318 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER);
4319 if (zp->z_sa_hdl == NULL) {
4321 * The fs has been unmounted, or we did a
4322 * suspend/resume and this file no longer exists.
4324 if (vn_has_cached_data(vp)) {
4325 (void) pvn_vplist_dirty(vp, 0, zfs_null_putapage,
4329 mutex_enter(&zp->z_lock);
4330 mutex_enter(&vp->v_lock);
4331 ASSERT(vp->v_count == 1);
4333 mutex_exit(&vp->v_lock);
4334 mutex_exit(&zp->z_lock);
4335 rw_exit(&zfsvfs->z_teardown_inactive_lock);
4341 * Attempt to push any data in the page cache. If this fails
4342 * we will get kicked out later in zfs_zinactive().
4344 if (vn_has_cached_data(vp)) {
4345 (void) pvn_vplist_dirty(vp, 0, zfs_putapage, B_INVAL|B_ASYNC,
4349 if (zp->z_atime_dirty && zp->z_unlinked == 0) {
4350 dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
4352 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
4353 zfs_sa_upgrade_txholds(tx, zp);
4354 error = dmu_tx_assign(tx, TXG_WAIT);
4358 mutex_enter(&zp->z_lock);
4359 (void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs),
4360 (void *)&zp->z_atime, sizeof (zp->z_atime), tx);
4361 zp->z_atime_dirty = 0;
4362 mutex_exit(&zp->z_lock);
4368 rw_exit(&zfsvfs->z_teardown_inactive_lock);
4370 EXPORT_SYMBOL(zfs_inactive);
4373 * Bounds-check the seek operation.
4375 * IN: vp - vnode seeking within
4376 * ooff - old file offset
4377 * noffp - pointer to new file offset
4378 * ct - caller context
4380 * RETURN: 0 if success
4381 * EINVAL if new offset invalid
4385 zfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp,
4386 caller_context_t *ct)
4388 if (vp->v_type == VDIR)
4390 return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
4394 * Pre-filter the generic locking function to trap attempts to place
4395 * a mandatory lock on a memory mapped file.
4398 zfs_frlock(vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset,
4399 flk_callback_t *flk_cbp, cred_t *cr, caller_context_t *ct)
4401 znode_t *zp = VTOZ(vp);
4402 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4408 * We are following the UFS semantics with respect to mapcnt
4409 * here: If we see that the file is mapped already, then we will
4410 * return an error, but we don't worry about races between this
4411 * function and zfs_map().
4413 if (zp->z_mapcnt > 0 && MANDMODE(zp->z_mode)) {
4418 return (fs_frlock(vp, cmd, bfp, flag, offset, flk_cbp, cr, ct));
4422 * If we can't find a page in the cache, we will create a new page
4423 * and fill it with file data. For efficiency, we may try to fill
4424 * multiple pages at once (klustering) to fill up the supplied page
4425 * list. Note that the pages to be filled are held with an exclusive
4426 * lock to prevent access by other threads while they are being filled.
4429 zfs_fillpage(vnode_t *vp, u_offset_t off, struct seg *seg,
4430 caddr_t addr, page_t *pl[], size_t plsz, enum seg_rw rw)
4432 znode_t *zp = VTOZ(vp);
4433 page_t *pp, *cur_pp;
4434 objset_t *os = zp->z_zfsvfs->z_os;
4435 u_offset_t io_off, total;
4439 if (plsz == PAGESIZE || zp->z_blksz <= PAGESIZE) {
4441 * We only have a single page, don't bother klustering
4445 pp = page_create_va(vp, io_off, io_len,
4446 PG_EXCL | PG_WAIT, seg, addr);
4449 * Try to find enough pages to fill the page list
4451 pp = pvn_read_kluster(vp, off, seg, addr, &io_off,
4452 &io_len, off, plsz, 0);
4456 * The page already exists, nothing to do here.
4463 * Fill the pages in the kluster.
4466 for (total = io_off + io_len; io_off < total; io_off += PAGESIZE) {
4469 ASSERT3U(io_off, ==, cur_pp->p_offset);
4470 va = zfs_map_page(cur_pp, S_WRITE);
4471 err = dmu_read(os, zp->z_id, io_off, PAGESIZE, va,
4473 zfs_unmap_page(cur_pp, va);
4475 /* On error, toss the entire kluster */
4476 pvn_read_done(pp, B_ERROR);
4477 /* convert checksum errors into IO errors */
4482 cur_pp = cur_pp->p_next;
4486 * Fill in the page list array from the kluster starting
4487 * from the desired offset `off'.
4488 * NOTE: the page list will always be null terminated.
4490 pvn_plist_init(pp, pl, plsz, off, io_len, rw);
4491 ASSERT(pl == NULL || (*pl)->p_offset == off);
4497 * Return pointers to the pages for the file region [off, off + len]
4498 * in the pl array. If plsz is greater than len, this function may
4499 * also return page pointers from after the specified region
4500 * (i.e. the region [off, off + plsz]). These additional pages are
4501 * only returned if they are already in the cache, or were created as
4502 * part of a klustered read.
4504 * IN: vp - vnode of file to get data from.
4505 * off - position in file to get data from.
4506 * len - amount of data to retrieve.
4507 * plsz - length of provided page list.
4508 * seg - segment to obtain pages for.
4509 * addr - virtual address of fault.
4510 * rw - mode of created pages.
4511 * cr - credentials of caller.
4512 * ct - caller context.
4514 * OUT: protp - protection mode of created pages.
4515 * pl - list of pages created.
4517 * RETURN: 0 if success
4518 * error code if failure
4521 * vp - atime updated
4525 zfs_getpage(vnode_t *vp, offset_t off, size_t len, uint_t *protp,
4526 page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
4527 enum seg_rw rw, cred_t *cr, caller_context_t *ct)
4529 znode_t *zp = VTOZ(vp);
4530 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4534 /* we do our own caching, faultahead is unnecessary */
4537 else if (len > plsz)
4540 len = P2ROUNDUP(len, PAGESIZE);
4541 ASSERT(plsz >= len);
4550 * Loop through the requested range [off, off + len) looking
4551 * for pages. If we don't find a page, we will need to create
4552 * a new page and fill it with data from the file.
4555 if (*pl = page_lookup(vp, off, SE_SHARED))
4557 else if (err = zfs_fillpage(vp, off, seg, addr, pl, plsz, rw))
4560 ASSERT3U((*pl)->p_offset, ==, off);
4564 ASSERT3U(len, >=, PAGESIZE);
4567 ASSERT3U(plsz, >=, PAGESIZE);
4574 * Fill out the page array with any pages already in the cache.
4577 (*pl++ = page_lookup_nowait(vp, off, SE_SHARED))) {
4584 * Release any pages we have previously locked.
4589 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
4599 * Request a memory map for a section of a file. This code interacts
4600 * with common code and the VM system as follows:
4602 * common code calls mmap(), which ends up in smmap_common()
4604 * this calls VOP_MAP(), which takes you into (say) zfs
4606 * zfs_map() calls as_map(), passing segvn_create() as the callback
4608 * segvn_create() creates the new segment and calls VOP_ADDMAP()
4610 * zfs_addmap() updates z_mapcnt
4614 zfs_map(vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp,
4615 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4616 caller_context_t *ct)
4618 znode_t *zp = VTOZ(vp);
4619 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4620 segvn_crargs_t vn_a;
4626 if ((prot & PROT_WRITE) && (zp->z_pflags &
4627 (ZFS_IMMUTABLE | ZFS_READONLY | ZFS_APPENDONLY))) {
4632 if ((prot & (PROT_READ | PROT_EXEC)) &&
4633 (zp->z_pflags & ZFS_AV_QUARANTINED)) {
4638 if (vp->v_flag & VNOMAP) {
4643 if (off < 0 || len > MAXOFFSET_T - off) {
4648 if (vp->v_type != VREG) {
4654 * If file is locked, disallow mapping.
4656 if (MANDMODE(zp->z_mode) && vn_has_flocks(vp)) {
4662 error = choose_addr(as, addrp, len, off, ADDR_VACALIGN, flags);
4670 vn_a.offset = (u_offset_t)off;
4671 vn_a.type = flags & MAP_TYPE;
4673 vn_a.maxprot = maxprot;
4676 vn_a.flags = flags & ~MAP_TYPE;
4678 vn_a.lgrp_mem_policy_flags = 0;
4680 error = as_map(as, *addrp, len, segvn_create, &vn_a);
4689 zfs_addmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
4690 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4691 caller_context_t *ct)
4693 uint64_t pages = btopr(len);
4695 atomic_add_64(&VTOZ(vp)->z_mapcnt, pages);
4700 * The reason we push dirty pages as part of zfs_delmap() is so that we get a
4701 * more accurate mtime for the associated file. Since we don't have a way of
4702 * detecting when the data was actually modified, we have to resort to
4703 * heuristics. If an explicit msync() is done, then we mark the mtime when the
4704 * last page is pushed. The problem occurs when the msync() call is omitted,
4705 * which by far the most common case:
4713 * putpage() via fsflush
4715 * If we wait until fsflush to come along, we can have a modification time that
4716 * is some arbitrary point in the future. In order to prevent this in the
4717 * common case, we flush pages whenever a (MAP_SHARED, PROT_WRITE) mapping is
4722 zfs_delmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
4723 size_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cr,
4724 caller_context_t *ct)
4726 uint64_t pages = btopr(len);
4728 ASSERT3U(VTOZ(vp)->z_mapcnt, >=, pages);
4729 atomic_add_64(&VTOZ(vp)->z_mapcnt, -pages);
4731 if ((flags & MAP_SHARED) && (prot & PROT_WRITE) &&
4732 vn_has_cached_data(vp))
4733 (void) VOP_PUTPAGE(vp, off, len, B_ASYNC, cr, ct);
4739 * Free or allocate space in a file. Currently, this function only
4740 * supports the `F_FREESP' command. However, this command is somewhat
4741 * misnamed, as its functionality includes the ability to allocate as
4742 * well as free space.
4744 * IN: vp - vnode of file to free data in.
4745 * cmd - action to take (only F_FREESP supported).
4746 * bfp - section of file to free/alloc.
4747 * flag - current file open mode flags.
4748 * offset - current file offset.
4749 * cr - credentials of caller [UNUSED].
4750 * ct - caller context.
4752 * RETURN: 0 if success
4753 * error code if failure
4756 * vp - ctime|mtime updated
4760 zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag,
4761 offset_t offset, cred_t *cr, caller_context_t *ct)
4763 znode_t *zp = VTOZ(vp);
4764 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4771 if (cmd != F_FREESP) {
4776 if ((error = convoff(vp, bfp, 0, offset))) {
4781 if (bfp->l_len < 0) {
4787 len = bfp->l_len; /* 0 means from off to end of file */
4789 error = zfs_freesp(zp, off, len, flag, TRUE);
4794 EXPORT_SYMBOL(zfs_space);
4798 zfs_fid(vnode_t *vp, fid_t *fidp, caller_context_t *ct)
4800 znode_t *zp = VTOZ(vp);
4801 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4804 uint64_t object = zp->z_id;
4811 if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs),
4812 &gen64, sizeof (uint64_t))) != 0) {
4817 gen = (uint32_t)gen64;
4819 size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN;
4820 if (fidp->fid_len < size) {
4821 fidp->fid_len = size;
4826 zfid = (zfid_short_t *)fidp;
4828 zfid->zf_len = size;
4830 for (i = 0; i < sizeof (zfid->zf_object); i++)
4831 zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
4833 /* Must have a non-zero generation number to distinguish from .zfs */
4836 for (i = 0; i < sizeof (zfid->zf_gen); i++)
4837 zfid->zf_gen[i] = (uint8_t)(gen >> (8 * i));
4839 if (size == LONG_FID_LEN) {
4840 uint64_t objsetid = dmu_objset_id(zfsvfs->z_os);
4843 zlfid = (zfid_long_t *)fidp;
4845 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
4846 zlfid->zf_setid[i] = (uint8_t)(objsetid >> (8 * i));
4848 /* XXX - this should be the generation number for the objset */
4849 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
4850 zlfid->zf_setgen[i] = 0;
4856 EXPORT_SYMBOL(zfs_fid);
4859 zfs_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr,
4860 caller_context_t *ct)
4872 case _PC_FILESIZEBITS:
4876 case _PC_XATTR_EXISTS:
4878 zfsvfs = zp->z_zfsvfs;
4882 error = zfs_dirent_lock(&dl, zp, "", &xzp,
4883 ZXATTR | ZEXISTS | ZSHARED, NULL, NULL);
4885 zfs_dirent_unlock(dl);
4886 if (!zfs_dirempty(xzp))
4889 } else if (error == ENOENT) {
4891 * If there aren't extended attributes, it's the
4892 * same as having zero of them.
4899 case _PC_SATTR_ENABLED:
4900 case _PC_SATTR_EXISTS:
4901 *valp = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
4902 (vp->v_type == VREG || vp->v_type == VDIR);
4905 case _PC_ACCESS_FILTERING:
4906 *valp = vfs_has_feature(vp->v_vfsp, VFSFT_ACCESS_FILTER) &&
4910 case _PC_ACL_ENABLED:
4911 *valp = _ACL_ACE_ENABLED;
4914 case _PC_MIN_HOLE_SIZE:
4915 *valp = (ulong_t)SPA_MINBLOCKSIZE;
4918 case _PC_TIMESTAMP_RESOLUTION:
4919 /* nanosecond timestamp resolution */
4924 return (fs_pathconf(vp, cmd, valp, cr, ct));
4930 zfs_getsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
4931 caller_context_t *ct)
4933 znode_t *zp = VTOZ(vp);
4934 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4936 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4940 error = zfs_getacl(zp, vsecp, skipaclchk, cr);
4945 EXPORT_SYMBOL(zfs_getsecattr);
4949 zfs_setsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
4950 caller_context_t *ct)
4952 znode_t *zp = VTOZ(vp);
4953 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4955 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4956 zilog_t *zilog = zfsvfs->z_log;
4961 error = zfs_setacl(zp, vsecp, skipaclchk, cr);
4963 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
4964 zil_commit(zilog, 0);
4969 EXPORT_SYMBOL(zfs_setsecattr);
4972 * Tunable, both must be a power of 2.
4974 * zcr_blksz_min: the smallest read we may consider to loan out an arcbuf
4975 * zcr_blksz_max: if set to less than the file block size, allow loaning out of
4976 * an arcbuf for a partial block read
4978 int zcr_blksz_min = (1 << 10); /* 1K */
4979 int zcr_blksz_max = (1 << 17); /* 128K */
4983 zfs_reqzcbuf(vnode_t *vp, enum uio_rw ioflag, xuio_t *xuio, cred_t *cr,
4984 caller_context_t *ct)
4986 znode_t *zp = VTOZ(vp);
4987 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4988 int max_blksz = zfsvfs->z_max_blksz;
4989 uio_t *uio = &xuio->xu_uio;
4990 ssize_t size = uio->uio_resid;
4991 offset_t offset = uio->uio_loffset;
4996 int preamble, postamble;
4998 if (xuio->xu_type != UIOTYPE_ZEROCOPY)
5006 * Loan out an arc_buf for write if write size is bigger than
5007 * max_blksz, and the file's block size is also max_blksz.
5010 if (size < blksz || zp->z_blksz != blksz) {
5015 * Caller requests buffers for write before knowing where the
5016 * write offset might be (e.g. NFS TCP write).
5021 preamble = P2PHASE(offset, blksz);
5023 preamble = blksz - preamble;
5028 postamble = P2PHASE(size, blksz);
5031 fullblk = size / blksz;
5032 (void) dmu_xuio_init(xuio,
5033 (preamble != 0) + fullblk + (postamble != 0));
5034 DTRACE_PROBE3(zfs_reqzcbuf_align, int, preamble,
5035 int, postamble, int,
5036 (preamble != 0) + fullblk + (postamble != 0));
5039 * Have to fix iov base/len for partial buffers. They
5040 * currently represent full arc_buf's.
5043 /* data begins in the middle of the arc_buf */
5044 abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
5047 (void) dmu_xuio_add(xuio, abuf,
5048 blksz - preamble, preamble);
5051 for (i = 0; i < fullblk; i++) {
5052 abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
5055 (void) dmu_xuio_add(xuio, abuf, 0, blksz);
5059 /* data ends in the middle of the arc_buf */
5060 abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
5063 (void) dmu_xuio_add(xuio, abuf, 0, postamble);
5068 * Loan out an arc_buf for read if the read size is larger than
5069 * the current file block size. Block alignment is not
5070 * considered. Partial arc_buf will be loaned out for read.
5072 blksz = zp->z_blksz;
5073 if (blksz < zcr_blksz_min)
5074 blksz = zcr_blksz_min;
5075 if (blksz > zcr_blksz_max)
5076 blksz = zcr_blksz_max;
5077 /* avoid potential complexity of dealing with it */
5078 if (blksz > max_blksz) {
5083 maxsize = zp->z_size - uio->uio_loffset;
5087 if (size < blksz || vn_has_cached_data(vp)) {
5097 uio->uio_extflg = UIO_XUIO;
5098 XUIO_XUZC_RW(xuio) = ioflag;
5105 zfs_retzcbuf(vnode_t *vp, xuio_t *xuio, cred_t *cr, caller_context_t *ct)
5109 int ioflag = XUIO_XUZC_RW(xuio);
5111 ASSERT(xuio->xu_type == UIOTYPE_ZEROCOPY);
5113 i = dmu_xuio_cnt(xuio);
5115 abuf = dmu_xuio_arcbuf(xuio, i);
5117 * if abuf == NULL, it must be a write buffer
5118 * that has been returned in zfs_write().
5121 dmu_return_arcbuf(abuf);
5122 ASSERT(abuf || ioflag == UIO_WRITE);
5125 dmu_xuio_fini(xuio);
5130 * Predeclare these here so that the compiler assumes that
5131 * this is an "old style" function declaration that does
5132 * not include arguments => we won't get type mismatch errors
5133 * in the initializations that follow.
5135 static int zfs_inval();
5136 static int zfs_isdir();
5150 * Directory vnode operations template
5152 vnodeops_t *zfs_dvnodeops;
5153 const fs_operation_def_t zfs_dvnodeops_template[] = {
5154 VOPNAME_OPEN, { .vop_open = zfs_open },
5155 VOPNAME_CLOSE, { .vop_close = zfs_close },
5156 VOPNAME_READ, { .error = zfs_isdir },
5157 VOPNAME_WRITE, { .error = zfs_isdir },
5158 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
5159 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5160 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5161 VOPNAME_ACCESS, { .vop_access = zfs_access },
5162 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
5163 VOPNAME_CREATE, { .vop_create = zfs_create },
5164 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
5165 VOPNAME_LINK, { .vop_link = zfs_link },
5166 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5167 VOPNAME_MKDIR, { .vop_mkdir = zfs_mkdir },
5168 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
5169 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
5170 VOPNAME_SYMLINK, { .vop_symlink = zfs_symlink },
5171 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
5172 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5173 VOPNAME_FID, { .vop_fid = zfs_fid },
5174 VOPNAME_SEEK, { .vop_seek = zfs_seek },
5175 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5176 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5177 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5178 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5183 * Regular file vnode operations template
5185 vnodeops_t *zfs_fvnodeops;
5186 const fs_operation_def_t zfs_fvnodeops_template[] = {
5187 VOPNAME_OPEN, { .vop_open = zfs_open },
5188 VOPNAME_CLOSE, { .vop_close = zfs_close },
5189 VOPNAME_READ, { .vop_read = zfs_read },
5190 VOPNAME_WRITE, { .vop_write = zfs_write },
5191 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
5192 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5193 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5194 VOPNAME_ACCESS, { .vop_access = zfs_access },
5195 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
5196 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5197 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
5198 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5199 VOPNAME_FID, { .vop_fid = zfs_fid },
5200 VOPNAME_SEEK, { .vop_seek = zfs_seek },
5201 VOPNAME_FRLOCK, { .vop_frlock = zfs_frlock },
5202 VOPNAME_SPACE, { .vop_space = zfs_space },
5203 VOPNAME_GETPAGE, { .vop_getpage = zfs_getpage },
5204 VOPNAME_PUTPAGE, { .vop_putpage = zfs_putpage },
5205 VOPNAME_MAP, { .vop_map = zfs_map },
5206 VOPNAME_ADDMAP, { .vop_addmap = zfs_addmap },
5207 VOPNAME_DELMAP, { .vop_delmap = zfs_delmap },
5208 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5209 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5210 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5211 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5212 VOPNAME_REQZCBUF, { .vop_reqzcbuf = zfs_reqzcbuf },
5213 VOPNAME_RETZCBUF, { .vop_retzcbuf = zfs_retzcbuf },
5218 * Symbolic link vnode operations template
5220 vnodeops_t *zfs_symvnodeops;
5221 const fs_operation_def_t zfs_symvnodeops_template[] = {
5222 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5223 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5224 VOPNAME_ACCESS, { .vop_access = zfs_access },
5225 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5226 VOPNAME_READLINK, { .vop_readlink = zfs_readlink },
5227 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5228 VOPNAME_FID, { .vop_fid = zfs_fid },
5229 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5230 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5235 * special share hidden files vnode operations template
5237 vnodeops_t *zfs_sharevnodeops;
5238 const fs_operation_def_t zfs_sharevnodeops_template[] = {
5239 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5240 VOPNAME_ACCESS, { .vop_access = zfs_access },
5241 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5242 VOPNAME_FID, { .vop_fid = zfs_fid },
5243 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5244 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5245 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5246 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5251 * Extended attribute directory vnode operations template
5252 * This template is identical to the directory vnodes
5253 * operation template except for restricted operations:
5256 * Note that there are other restrictions embedded in:
5257 * zfs_create() - restrict type to VREG
5258 * zfs_link() - no links into/out of attribute space
5259 * zfs_rename() - no moves into/out of attribute space
5261 vnodeops_t *zfs_xdvnodeops;
5262 const fs_operation_def_t zfs_xdvnodeops_template[] = {
5263 VOPNAME_OPEN, { .vop_open = zfs_open },
5264 VOPNAME_CLOSE, { .vop_close = zfs_close },
5265 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
5266 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5267 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5268 VOPNAME_ACCESS, { .vop_access = zfs_access },
5269 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
5270 VOPNAME_CREATE, { .vop_create = zfs_create },
5271 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
5272 VOPNAME_LINK, { .vop_link = zfs_link },
5273 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5274 VOPNAME_MKDIR, { .error = zfs_inval },
5275 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
5276 VOPNAME_READDIR, { .vop_readdir = zfs_readdir },
5277 VOPNAME_SYMLINK, { .error = zfs_inval },
5278 VOPNAME_FSYNC, { .vop_fsync = zfs_fsync },
5279 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5280 VOPNAME_FID, { .vop_fid = zfs_fid },
5281 VOPNAME_SEEK, { .vop_seek = zfs_seek },
5282 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5283 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5284 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5285 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5290 * Error vnode operations template
5292 vnodeops_t *zfs_evnodeops;
5293 const fs_operation_def_t zfs_evnodeops_template[] = {
5294 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5295 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5298 #endif /* HAVE_ZPL */